Extend event and fence support

This commit is contained in:
msiglreith 2018-09-04 19:09:23 +02:00
parent 908c29ed7e
commit e6ba80cb39
4 changed files with 47 additions and 7 deletions

View File

@ -8,4 +8,4 @@ bitflags = "1"
[dependencies.winapi]
version = "0.3"
features = ["dxgi1_2","dxgi1_3","dxgi1_4","d3d12","d3d12sdklayers","d3dcommon","d3dcompiler","dxgiformat","winerror"]
features = ["dxgi1_2","dxgi1_3","dxgi1_4","d3d12","d3d12sdklayers","d3dcommon","d3dcompiler","dxgiformat","synchapi","winerror"]

View File

@ -57,9 +57,14 @@ impl IndirectArgument {
}
pub type CommandSignature = WeakPtr<d3d12::ID3D12CommandSignature>;
pub type CommandList = WeakPtr<d3d12::ID3D12CommandList>;
pub type GraphicsCommandList = WeakPtr<d3d12::ID3D12GraphicsCommandList>;
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() }
}

View File

@ -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<d3d12::ID3D12Device>;
@ -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<Fence> {
let mut fence = Fence::null();
let hr = unsafe {
self.CreateFence(
initial,
d3d12::D3D12_FENCE_FLAG_NONE,
&d3d12::ID3D12Fence::uuidof(),
fence.mut_void(),
)
};
(fence, hr)
}
}

View File

@ -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<d3d12::ID3D12Fence>;
#[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<d3d12::ID3D12Fence>;
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 {