mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-22 23:04:07 +00:00
hal/dx12: fences
This commit is contained in:
parent
c7519432ee
commit
855689462c
@ -60,13 +60,13 @@ impl crate::CommandEncoder<super::Api> for super::CommandEncoder {
|
||||
) {
|
||||
}
|
||||
|
||||
unsafe fn begin_query(&mut self, set: &Resource, index: u32) {}
|
||||
unsafe fn end_query(&mut self, set: &Resource, index: u32) {}
|
||||
unsafe fn write_timestamp(&mut self, set: &Resource, index: u32) {}
|
||||
unsafe fn reset_queries(&mut self, set: &Resource, range: Range<u32>) {}
|
||||
unsafe fn begin_query(&mut self, set: &super::QuerySet, index: u32) {}
|
||||
unsafe fn end_query(&mut self, set: &super::QuerySet, index: u32) {}
|
||||
unsafe fn write_timestamp(&mut self, set: &super::QuerySet, index: u32) {}
|
||||
unsafe fn reset_queries(&mut self, set: &super::QuerySet, range: Range<u32>) {}
|
||||
unsafe fn copy_query_results(
|
||||
&mut self,
|
||||
set: &Resource,
|
||||
set: &super::QuerySet,
|
||||
range: Range<u32>,
|
||||
buffer: &super::Buffer,
|
||||
offset: wgt::BufferAddress,
|
||||
|
@ -2,7 +2,7 @@ use super::{conv, descriptor, HResult as _};
|
||||
use parking_lot::Mutex;
|
||||
use std::{iter, mem, ptr};
|
||||
use winapi::{
|
||||
shared::{dxgiformat, dxgitype},
|
||||
shared::{dxgiformat, dxgitype, winerror},
|
||||
um::{d3d12, d3d12sdklayers, synchapi, winbase},
|
||||
Interface,
|
||||
};
|
||||
@ -10,8 +10,6 @@ use winapi::{
|
||||
//TODO: remove this
|
||||
use super::Resource;
|
||||
|
||||
type DeviceResult<T> = Result<T, crate::DeviceError>;
|
||||
|
||||
const D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING: u32 = 0x1688;
|
||||
|
||||
fn wide_cstr(name: &str) -> Vec<u16> {
|
||||
@ -649,10 +647,13 @@ impl crate::Device<super::Api> for super::Device {
|
||||
}
|
||||
}
|
||||
|
||||
unsafe fn create_sampler(&self, desc: &crate::SamplerDescriptor) -> DeviceResult<Resource> {
|
||||
Ok(Resource)
|
||||
unsafe fn create_sampler(
|
||||
&self,
|
||||
desc: &crate::SamplerDescriptor,
|
||||
) -> Result<super::Sampler, crate::DeviceError> {
|
||||
Ok(super::Sampler {})
|
||||
}
|
||||
unsafe fn destroy_sampler(&self, sampler: Resource) {}
|
||||
unsafe fn destroy_sampler(&self, sampler: super::Sampler) {}
|
||||
|
||||
unsafe fn create_command_encoder(
|
||||
&self,
|
||||
@ -665,21 +666,21 @@ impl crate::Device<super::Api> for super::Device {
|
||||
unsafe fn create_bind_group_layout(
|
||||
&self,
|
||||
desc: &crate::BindGroupLayoutDescriptor,
|
||||
) -> DeviceResult<Resource> {
|
||||
) -> Result<Resource, crate::DeviceError> {
|
||||
Ok(Resource)
|
||||
}
|
||||
unsafe fn destroy_bind_group_layout(&self, bg_layout: Resource) {}
|
||||
unsafe fn create_pipeline_layout(
|
||||
&self,
|
||||
desc: &crate::PipelineLayoutDescriptor<super::Api>,
|
||||
) -> DeviceResult<Resource> {
|
||||
) -> Result<Resource, crate::DeviceError> {
|
||||
Ok(Resource)
|
||||
}
|
||||
unsafe fn destroy_pipeline_layout(&self, pipeline_layout: Resource) {}
|
||||
unsafe fn create_bind_group(
|
||||
&self,
|
||||
desc: &crate::BindGroupDescriptor<super::Api>,
|
||||
) -> DeviceResult<Resource> {
|
||||
) -> Result<Resource, crate::DeviceError> {
|
||||
Ok(Resource)
|
||||
}
|
||||
unsafe fn destroy_bind_group(&self, group: Resource) {}
|
||||
@ -710,24 +711,52 @@ impl crate::Device<super::Api> for super::Device {
|
||||
unsafe fn create_query_set(
|
||||
&self,
|
||||
desc: &wgt::QuerySetDescriptor<crate::Label>,
|
||||
) -> DeviceResult<Resource> {
|
||||
Ok(Resource)
|
||||
) -> Result<super::QuerySet, crate::DeviceError> {
|
||||
Ok(super::QuerySet {})
|
||||
}
|
||||
unsafe fn destroy_query_set(&self, set: Resource) {}
|
||||
unsafe fn create_fence(&self) -> DeviceResult<Resource> {
|
||||
Ok(Resource)
|
||||
unsafe fn destroy_query_set(&self, set: super::QuerySet) {}
|
||||
|
||||
unsafe fn create_fence(&self) -> Result<super::Fence, crate::DeviceError> {
|
||||
let mut raw = native::Fence::null();
|
||||
let hr = self.raw.CreateFence(
|
||||
0,
|
||||
d3d12::D3D12_FENCE_FLAG_NONE,
|
||||
&d3d12::ID3D12Fence::uuidof(),
|
||||
raw.mut_void(),
|
||||
);
|
||||
hr.to_device_result("Fence creation")?;
|
||||
Ok(super::Fence { raw })
|
||||
}
|
||||
unsafe fn destroy_fence(&self, fence: Resource) {}
|
||||
unsafe fn get_fence_value(&self, fence: &Resource) -> DeviceResult<crate::FenceValue> {
|
||||
Ok(0)
|
||||
unsafe fn destroy_fence(&self, fence: super::Fence) {
|
||||
fence.raw.destroy();
|
||||
}
|
||||
unsafe fn get_fence_value(
|
||||
&self,
|
||||
fence: &super::Fence,
|
||||
) -> Result<crate::FenceValue, crate::DeviceError> {
|
||||
Ok(fence.raw.GetCompletedValue())
|
||||
}
|
||||
unsafe fn wait(
|
||||
&self,
|
||||
fence: &Resource,
|
||||
fence: &super::Fence,
|
||||
value: crate::FenceValue,
|
||||
timeout_ms: u32,
|
||||
) -> DeviceResult<bool> {
|
||||
Ok(true)
|
||||
) -> Result<bool, crate::DeviceError> {
|
||||
if fence.raw.GetCompletedValue() >= value {
|
||||
return Ok(true);
|
||||
}
|
||||
let hr = fence.raw.set_event_on_completion(self.idler.event, value);
|
||||
hr.to_device_result("Set event")?;
|
||||
|
||||
match synchapi::WaitForSingleObject(self.idler.event.0, timeout_ms) {
|
||||
winbase::WAIT_ABANDONED | winbase::WAIT_FAILED => Err(crate::DeviceError::Lost),
|
||||
winbase::WAIT_OBJECT_0 => Ok(true),
|
||||
winerror::WAIT_TIMEOUT => Ok(false),
|
||||
other => {
|
||||
log::error!("Unexpected wait status: 0x{:x}", other);
|
||||
Err(crate::DeviceError::Lost)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unsafe fn start_capture(&self) -> bool {
|
||||
|
@ -41,9 +41,9 @@ impl crate::Api for Api {
|
||||
type Texture = Texture;
|
||||
type SurfaceTexture = Texture;
|
||||
type TextureView = TextureView;
|
||||
type Sampler = Resource;
|
||||
type QuerySet = Resource;
|
||||
type Fence = Resource;
|
||||
type Sampler = Sampler;
|
||||
type QuerySet = QuerySet;
|
||||
type Fence = Fence;
|
||||
|
||||
type BindGroupLayout = Resource;
|
||||
type BindGroup = Resource;
|
||||
@ -216,6 +216,23 @@ pub struct TextureView {
|
||||
unsafe impl Send for TextureView {}
|
||||
unsafe impl Sync for TextureView {}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Sampler {}
|
||||
|
||||
unsafe impl Send for Sampler {}
|
||||
unsafe impl Sync for Sampler {}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct QuerySet {}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Fence {
|
||||
raw: native::Fence,
|
||||
}
|
||||
|
||||
unsafe impl Send for Fence {}
|
||||
unsafe impl Sync for Fence {}
|
||||
|
||||
impl crate::Instance<Api> for Instance {
|
||||
unsafe fn init(desc: &crate::InstanceDescriptor) -> Result<Self, crate::InstanceError> {
|
||||
let lib_main = native::D3D12Lib::new().map_err(|_| crate::InstanceError)?;
|
||||
@ -525,7 +542,7 @@ impl crate::Queue<Api> for Queue {
|
||||
unsafe fn submit(
|
||||
&mut self,
|
||||
command_buffers: &[&Resource],
|
||||
signal_fence: Option<(&mut Resource, crate::FenceValue)>,
|
||||
signal_fence: Option<(&mut Fence, crate::FenceValue)>,
|
||||
) -> Result<(), crate::DeviceError> {
|
||||
Ok(())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user