mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-25 00:03:29 +00:00
Extend event and fence support
This commit is contained in:
parent
908c29ed7e
commit
e6ba80cb39
@ -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"]
|
@ -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() }
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
28
src/sync.rs
28
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<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 {
|
||||
|
Loading…
Reference in New Issue
Block a user