diff --git a/Cargo.toml b/Cargo.toml index 451272962..1063f5d08 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,4 +8,4 @@ bitflags = "1" [dependencies.winapi] version = "0.3" -features = ["dxgi1_2","dxgi1_3","dxgi1_4","d3d12","d3d12sdklayers","d3dcommon","d3dcompiler","dxgiformat","winerror"] \ No newline at end of file +features = ["dxgi1_2","dxgi1_3","dxgi1_4","d3d12","d3d12sdklayers","d3dcommon","d3dcompiler","dxgiformat","synchapi","winerror"] \ No newline at end of file diff --git a/src/command_list.rs b/src/command_list.rs index 64fb76a4f..e3725b95b 100644 --- a/src/command_list.rs +++ b/src/command_list.rs @@ -57,9 +57,14 @@ impl IndirectArgument { } pub type CommandSignature = WeakPtr; +pub type CommandList = WeakPtr; pub type GraphicsCommandList = WeakPtr; impl GraphicsCommandList { + pub fn as_list(&self) -> CommandList { + unsafe { CommandList::from_raw(self.as_mut_ptr() as *mut _) } + } + pub fn close(&self) -> HRESULT { unsafe { self.Close() } } diff --git a/src/device.rs b/src/device.rs index 33781064a..376c30418 100644 --- a/src/device.rs +++ b/src/device.rs @@ -9,8 +9,8 @@ use winapi::Interface; use {pso, query, queue}; use { Blob, CachedPSO, CommandAllocator, CommandQueue, D3DResult, DescriptorHeap, FeatureLevel, - GraphicsCommandList, NodeMask, PipelineState, QueryHeap, Resource, RootSignature, Shader, - TextureAddressMode, + Fence, GraphicsCommandList, NodeMask, PipelineState, QueryHeap, Resource, RootSignature, + Shader, TextureAddressMode, }; pub type Device = WeakPtr; @@ -276,4 +276,19 @@ impl Device { self.CreateRenderTargetView(resource.as_mut_ptr(), &desc.0 as *const _, descriptor); } } + + // TODO: interface not complete + pub fn create_fence(&self, initial: u64) -> D3DResult { + let mut fence = Fence::null(); + let hr = unsafe { + self.CreateFence( + initial, + d3d12::D3D12_FENCE_FLAG_NONE, + &d3d12::ID3D12Fence::uuidof(), + fence.mut_void(), + ) + }; + + (fence, hr) + } } diff --git a/src/sync.rs b/src/sync.rs index c10c73519..650fa6d00 100644 --- a/src/sync.rs +++ b/src/sync.rs @@ -1,14 +1,34 @@ use com::WeakPtr; +use std::ptr; use winapi::um::d3d12; -use winapi::um::winnt; +use winapi::um::{synchapi, winnt}; use HRESULT; -pub type Event = winnt::HANDLE; -pub type Fence = WeakPtr; +#[derive(Copy, Clone)] +#[repr(transparent)] +pub struct Event(winnt::HANDLE); +impl Event { + pub fn create(manual_reset: bool, initial_state: bool) -> Self { + Event(unsafe { + synchapi::CreateEventA( + ptr::null_mut(), + manual_reset as _, + initial_state as _, + ptr::null(), + ) + }) + } + // TODO: return value + pub fn wait(&self, timeout_ms: u32) -> u32 { + unsafe { synchapi::WaitForSingleObject(self.0, timeout_ms) } + } +} + +pub type Fence = WeakPtr; impl Fence { pub fn set_event_on_completion(&self, event: Event, value: u64) -> HRESULT { - unsafe { self.SetEventOnCompletion(value, event) } + unsafe { self.SetEventOnCompletion(value, event.0) } } pub fn get_value(&self) -> u64 {