Skip to content

Commit 6687fc4

Browse files
authored
Merge pull request #13 from aosoft/aosoft/update-interfaces-6.1.8
Aosoft/update interfaces 6.1.8
2 parents 010dce6 + 5e6c9c1 commit 6687fc4

File tree

13 files changed

+52093
-96363
lines changed

13 files changed

+52093
-96363
lines changed
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
[package]
22
name = "unity-native-plugin-sample-profiler"
3-
version = "0.7.0"
3+
version = "0.8.0"
44
authors = ["Yasuhiro Taniuchi"]
5-
edition = "2021"
5+
edition = "2024"
66
publish = false
77

88
[lib]
@@ -11,8 +11,8 @@ crate-type = ["cdylib"]
1111
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1212

1313
[dependencies]
14-
unity-native-plugin = { version = "0.7.0", path = "../unity-native-plugin", features = ["profiler_callbacks"] }
15-
unity-native-plugin-sys = { version = "0.7.0", path = "../unity-native-plugin-sys" }
14+
unity-native-plugin = { version = "0.8.0", path = "../unity-native-plugin", features = ["profiler_callbacks"] }
15+
unity-native-plugin-sys = { version = "0.8.0", path = "../unity-native-plugin-sys" }
1616
log = "0.4"
1717
env_logger = "0.8"
1818
flume = "0.10"
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
[package]
22
name = "unity-native-plugin-sample"
3-
version = "0.7.0"
3+
version = "0.8.0"
44
authors = ["Yasuhiro Taniuchi"]
5-
edition = "2021"
5+
edition = "2024"
66
publish = false
77

88
[lib]
@@ -11,10 +11,10 @@ crate-type = ["cdylib"]
1111
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1212

1313
[dependencies]
14-
unity-native-plugin = { version = "0.7.0", path = "../unity-native-plugin", features = ["d3d11", "d3d12", "profiler"] }
15-
unity-native-plugin-vulkan = { version = "0.7.0", path = "../unity-native-plugin-vulkan" }
14+
unity-native-plugin = { version = "0.8.0", path = "../unity-native-plugin", features = ["d3d11", "d3d12", "profiler"] }
15+
unity-native-plugin-vulkan = { version = "0.8.0", path = "../unity-native-plugin-vulkan" }
1616
winapi = { version = "0.3.9", features = ["winuser", "d3d11", "dxgiformat"] }
1717
wio = "0.2.2"
1818

1919
[dev-dependencies]
20-
unity-native-plugin-tester = { version = "0.7.0", path = "../unity-native-plugin-tester", features = ["d3d11"] }
20+
unity-native-plugin-tester = { version = "0.8.0", path = "../unity-native-plugin-tester", features = ["d3d11"] }

unity-native-plugin-sample/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ unity_native_plugin::unity_native_plugin_entry_point! {
99
}
1010
}
1111

12-
#[no_mangle]
12+
#[unsafe(no_mangle)]
1313
#[allow(non_snake_case)]
1414
extern "system" fn FillTexture(unity_texture: *mut IUnknown, x: f32, y: f32, z: f32, w: f32) {
1515
unsafe {

unity-native-plugin-sys/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
[package]
22
name = "unity-native-plugin-sys"
3-
version = "0.7.0"
3+
version = "0.8.0"
44
authors = ["Yasuhiro Taniuchi"]
5-
edition = "2021"
5+
edition = "2024"
66
license = "MIT"
77
description = "unity-native-plugin-sys"
88
homepage = "https://github.com/aosoft/unity-native-plugin-rs"

unity-native-plugin-sys/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
unity-native-plugin-rs
22
====
33

4-
* based on Unity 6000.0.10f1
5-
* Vulkan SDK 1.3.283.0
6-
* bindgen 0.69.4
4+
* based on Unity 6000.1.8f1
5+
* Vulkan SDK 1.4.309.0
6+
* bindgen 0.72.0
77
* clang version 14.0.0-1ubuntu1.1

unity-native-plugin-sys/bindgen.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ bindgen \
44
--output ./src/plugin_api.rs \
55
--with-derive-default \
66
--no-derive-debug \
7-
wrapper.hpp -- -I ./include -I $VULKAN_SDK/Include
7+
wrapper.hpp -- -I ./include -I $VULKAN_SDK/include
88
sed -i -e "s/extern \""C\""/extern \""system\""/g" ./src/plugin_api.rs

unity-native-plugin-sys/src/plugin_api.rs

Lines changed: 51994 additions & 96284 deletions
Large diffs are not rendered by default.

unity-native-plugin-tester/Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
[package]
22
name = "unity-native-plugin-tester"
3-
version = "0.7.0"
3+
version = "0.8.0"
44
authors = ["Yasuhiro Taniuchi"]
5-
edition = "2021"
5+
edition = "2024"
66
license = "MIT"
77
description = "Unity Native Plugin API Tester Library"
88
homepage = "https://github.com/aosoft/unity-native-plugin-rs"
9-
repository = "https://github.com/aosoft/unity-native-plugin-tester"
9+
repository = "https://github.com/aosoft/unity-native-plugin-rs"
1010
readme = "README.md"
1111
categories = ["api-bindings", "game-engines"]
1212
keywords = ["unity", "ffi"]
@@ -25,8 +25,8 @@ d3d11 = []
2525
d3d12 = []
2626

2727
[dependencies]
28-
unity-native-plugin-sys = { version = "0.7.0", path = "../unity-native-plugin-sys" }
29-
unity-native-plugin = { version = "0.7.0", path = "../unity-native-plugin", features = ["d3d11", "d3d12"] }
28+
unity-native-plugin-sys = { version = "0.8.0", path = "../unity-native-plugin-sys" }
29+
unity-native-plugin = { version = "0.8.0", path = "../unity-native-plugin", features = ["d3d11", "d3d12"] }
3030
winapi = { version = "0.3.9", features = ["winuser", "dxgi", "d3d11", "dxgiformat", "dxgitype", "d3dcommon"] }
3131
winit = "0.23.0"
3232
wio = "0.2.2"
Lines changed: 58 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
use std::any::Any;
22
use std::collections::HashMap;
3+
use std::fmt::Debug;
34
use std::os::raw::c_ulonglong;
45
use std::rc::Rc;
6+
use std::sync::{Mutex, OnceLock};
57
use unity_native_plugin_sys::*;
68

79
#[derive(Default, Copy, Clone, Eq, PartialEq, Hash)]
@@ -20,14 +22,25 @@ pub trait UnityInterfaceID {
2022
}
2123

2224
pub struct TesterContextInterfaces {
23-
map: HashMap<InfKey, Rc<dyn UnityInterfaceBase>>,
25+
map: Mutex<HashMap<InfKey, Rc<dyn UnityInterfaceBase>>>,
2426
interfaces: IUnityInterfaces,
2527
}
2628

29+
impl Debug for TesterContextInterfaces {
30+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
31+
f.debug_struct("TesterContextInterfaces").finish()
32+
}
33+
}
34+
35+
36+
// maybe thread safety
37+
unsafe impl Send for TesterContextInterfaces {}
38+
unsafe impl Sync for TesterContextInterfaces {}
39+
2740
impl TesterContextInterfaces {
2841
pub fn new() -> Self {
2942
TesterContextInterfaces {
30-
map: HashMap::<InfKey, Rc<dyn UnityInterfaceBase>>::new(),
43+
map: Mutex::new(HashMap::<InfKey, Rc<dyn UnityInterfaceBase>>::new()),
3144
interfaces: IUnityInterfaces {
3245
GetInterface: Some(get_interface),
3346
RegisterInterface: Some(register_interface),
@@ -41,49 +54,47 @@ impl TesterContextInterfaces {
4154
unsafe { std::mem::transmute::<_, _>(&self.interfaces) }
4255
}
4356

44-
pub fn get_interface(&self, guid: UnityInterfaceGUID) -> Option<&Rc<dyn UnityInterfaceBase>> {
57+
pub fn get_interface(&self, guid: UnityInterfaceGUID) -> Option<Rc<dyn UnityInterfaceBase>> {
4558
self.get_interface_split(guid.m_GUIDHigh, guid.m_GUIDLow)
4659
}
4760

4861
pub fn get_interface_split(
4962
&self,
5063
high: ::std::os::raw::c_ulonglong,
5164
low: ::std::os::raw::c_ulonglong,
52-
) -> Option<&Rc<dyn UnityInterfaceBase>> {
53-
self.map.get(&InfKey { high, low })
65+
) -> Option<Rc<dyn UnityInterfaceBase>> {
66+
self.map.lock().unwrap().get(&InfKey { high, low }).cloned()
5467
}
5568

5669
pub fn register_interface<T: UnityInterfaceBase + UnityInterfaceID>(
57-
&mut self,
70+
&self,
5871
interface: Option<Rc<dyn UnityInterfaceBase>>,
5972
) {
6073
let guid = T::get_interface_guid();
6174
self.register_interface_split(guid.m_GUIDHigh, guid.m_GUIDLow, interface);
6275
}
6376

6477
pub fn register_interface_split(
65-
&mut self,
78+
&self,
6679
high: ::std::os::raw::c_ulonglong,
6780
low: ::std::os::raw::c_ulonglong,
6881
interface: Option<Rc<dyn UnityInterfaceBase>>,
6982
) {
7083
if let Some(i) = interface {
71-
self.map.insert(InfKey { high, low }, i);
84+
self.map.lock().unwrap().insert(InfKey { high, low }, i);
7285
} else {
73-
self.map.remove(&InfKey { high, low });
86+
self.map.lock().unwrap().remove(&InfKey { high, low });
7487
}
7588
}
7689
}
7790

78-
static mut UNITY_INTERFACES: Option<TesterContextInterfaces> = None;
91+
static UNITY_INTERFACES: OnceLock<TesterContextInterfaces> = OnceLock::new();
7992

8093
extern "system" fn get_interface(guid: UnityInterfaceGUID) -> *mut IUnityInterface {
81-
unsafe {
82-
if let Some(i) = UNITY_INTERFACES.as_ref().unwrap().get_interface(guid) {
83-
i.as_ref().get_unity_interface()
84-
} else {
85-
std::ptr::null_mut()
86-
}
94+
if let Some(i) = UNITY_INTERFACES.get().unwrap().get_interface(guid) {
95+
i.as_ref().get_unity_interface()
96+
} else {
97+
std::ptr::null_mut()
8798
}
8899
}
89100

@@ -93,16 +104,14 @@ extern "system" fn get_interface_split(
93104
high: ::std::os::raw::c_ulonglong,
94105
low: ::std::os::raw::c_ulonglong,
95106
) -> *mut IUnityInterface {
96-
unsafe {
97-
if let Some(i) = UNITY_INTERFACES
98-
.as_ref()
99-
.unwrap()
100-
.get_interface_split(high, low)
101-
{
102-
i.as_ref().get_unity_interface()
103-
} else {
104-
std::ptr::null_mut()
105-
}
107+
if let Some(i) = UNITY_INTERFACES
108+
.get()
109+
.unwrap()
110+
.get_interface_split(high, low)
111+
{
112+
i.as_ref().get_unity_interface()
113+
} else {
114+
std::ptr::null_mut()
106115
}
107116
}
108117

@@ -113,34 +122,42 @@ extern "system" fn register_interface_split(
113122
) {
114123
}
115124

116-
pub unsafe fn get_unity_interfaces() -> &'static mut TesterContextInterfaces {
117-
unsafe {
118-
UNITY_INTERFACES.as_mut().unwrap()
119-
}
125+
pub unsafe fn get_unity_interfaces() -> &'static TesterContextInterfaces {
126+
UNITY_INTERFACES.get().unwrap()
120127
}
121128

122-
pub unsafe fn get_unity_interface<T: UnityInterfaceBase + UnityInterfaceID>() -> &'static T {
129+
pub unsafe fn get_unity_interface<T: UnityInterfaceBase + UnityInterfaceID + 'static>() -> Rc<T>
130+
{
123131
unsafe {
124-
get_unity_interfaces()
125-
.get_interface(T::get_interface_guid())
126-
.unwrap()
127-
.as_any()
128-
.downcast_ref::<T>()
129-
.unwrap()
132+
let interface_rc = get_unity_interfaces()
133+
.get_interface(T::get_interface_guid()).unwrap();
134+
135+
// Rcの中身をダウンキャストして新しいRcを作成
136+
let any_ref = interface_rc.as_any();
137+
if let Some(_) = any_ref.downcast_ref::<T>() {
138+
// Use Rc::clone to safely create an Rc<T>
139+
// First, get a raw pointer from the original Rc
140+
let ptr = Rc::as_ptr(&interface_rc);
141+
// Successfully downcasted, so cast it safely as type T
142+
let concrete_ptr = ptr as *const T;
143+
// Create a new Rc<T> (clone the original Rc to increase the reference count)
144+
std::mem::forget(interface_rc.clone()); // Increase reference count
145+
Rc::from_raw(concrete_ptr)
146+
} else {
147+
panic!("interface is not T");
148+
}
130149
}
131150
}
132151

133152
pub fn initialize_unity_interfaces() {
134153
unsafe {
135-
UNITY_INTERFACES = Some(TesterContextInterfaces::new());
154+
UNITY_INTERFACES.set(TesterContextInterfaces::new()).unwrap();
136155
unity_native_plugin::interface::UnityInterfaces::set_native_unity_interfaces(
137156
crate::interface::get_unity_interfaces().interfaces(),
138157
);
139158
}
140159
}
141160

142161
pub fn finalize_unity_interfaces() {
143-
unsafe {
144-
UNITY_INTERFACES = None;
145-
}
162+
UNITY_INTERFACES.get().unwrap().map.lock().unwrap().clear();
146163
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "unity-native-plugin-vulkan"
3-
version = "0.7.0"
3+
version = "0.8.0"
44
authors = ["Yasuhiro Taniuchi"]
55
license = "MIT"
66
description = "Unity Native Plugin API (Vulkan) for Rust"
@@ -9,7 +9,7 @@ repository = "https://github.com/aosoft/unity-native-plugin-rs"
99
readme = "README.md"
1010
categories = ["api-bindings", "game-engines"]
1111
keywords = ["unity"]
12-
edition = "2021"
12+
edition = "2024"
1313
include = [
1414
"**/*.rs",
1515
"Cargo.toml",
@@ -19,6 +19,6 @@ include = [
1919
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
2020

2121
[dependencies]
22-
unity-native-plugin = { version = "0.7.0", path = "../unity-native-plugin" }
23-
unity-native-plugin-sys = { version = "0.7.0", path = "../unity-native-plugin-sys" }
22+
unity-native-plugin = { version = "0.8.0", path = "../unity-native-plugin" }
23+
unity-native-plugin-sys = { version = "0.8.0", path = "../unity-native-plugin-sys" }
2424
ash = "0.38.0+1.3.281.1"

0 commit comments

Comments
 (0)