Skip to content

Commit fed0295

Browse files
committed
Implement d3d12.rs
1 parent 77f7726 commit fed0295

File tree

2 files changed

+62
-2
lines changed

2 files changed

+62
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Unity Native Plugin API for Rust
66
## Notice
77

88
* WIP
9-
* Currently only D3D11 is supported
9+
* Currently supports D3D11 and D3D12
1010
* API is not stable.
1111

1212
## How to use

unity-native-plugin/src/d3d12.rs

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::define_unity_interface;
2+
use crate::interface;
23
use std::ffi::c_void;
34
use unity_native_plugin_sys::*;
45

@@ -160,7 +161,6 @@ define_unity_interface!(
160161
0xB18F8B0FF67778C8_u64
161162
);
162163

163-
164164
impl UnityGraphicsD3D12v4 {
165165
pub unsafe fn get_device(&self) -> *mut c_void {
166166
self.get_interface().GetDevice.expect("GetDevice")() as *mut c_void
@@ -218,3 +218,63 @@ define_unity_interface!(
218218
0xF5C8D8A37D37BC42_u64,
219219
0xB02DFE93B5064A27_u64
220220
);
221+
222+
impl UnityGraphicsD3D12v5 {
223+
pub unsafe fn get_device(&self) -> *mut c_void {
224+
self.get_interface().GetDevice.expect("GetDevice")() as *mut c_void
225+
}
226+
227+
pub unsafe fn get_frame_fence(&self) -> *mut c_void {
228+
self.get_interface().GetFrameFence.expect("GetFrameFence")() as *mut c_void
229+
}
230+
231+
pub fn get_next_frame_fence_value(&self) -> u64 {
232+
unsafe {
233+
self.get_interface()
234+
.GetNextFrameFenceValue
235+
.expect("GetNextFrameFenceValue")()
236+
}
237+
}
238+
239+
pub unsafe fn execute_command_list(
240+
&self,
241+
command_list: *mut c_void,
242+
states: &[ResourceState],
243+
) -> u64 {
244+
self.get_interface()
245+
.ExecuteCommandList
246+
.expect("ExecuteCommandList")(
247+
command_list as *mut ID3D12GraphicsCommandList,
248+
states.len() as ::std::os::raw::c_int,
249+
states.as_ptr() as *mut UnityGraphicsD3D12ResourceState,
250+
)
251+
}
252+
253+
pub fn set_physical_video_memory_control_values(
254+
&self,
255+
mem_info: &PhysicalVideoMemoryControlValues,
256+
) {
257+
unsafe {
258+
self.get_interface()
259+
.SetPhysicalVideoMemoryControlValues
260+
.expect("SetPhysicalVideoMemoryControlValues")(
261+
mem_info as *const UnityGraphicsD3D12PhysicalVideoMemoryControlValues,
262+
)
263+
}
264+
}
265+
266+
pub unsafe fn get_command_queue(&self) -> *mut c_void {
267+
self.get_interface()
268+
.GetCommandQueue
269+
.expect("GetCommandQueue")() as *mut c_void
270+
}
271+
272+
pub unsafe fn texture_from_render_buffer(
273+
&self,
274+
buffer: *mut interface::RenderBuffer,
275+
) -> *mut c_void {
276+
self.get_interface()
277+
.TextureFromRenderBuffer
278+
.expect("TextureFromRenderBuffer")(buffer) as *mut c_void
279+
}
280+
}

0 commit comments

Comments
 (0)