hal/dx12: queries

This commit is contained in:
Dzmitry Malyshau 2021-07-08 23:11:20 -04:00
parent b818157f67
commit 27b8085048
5 changed files with 48 additions and 13 deletions

View File

@ -145,7 +145,9 @@ impl super::Adapter {
| wgt::Features::MULTI_DRAW_INDIRECT_COUNT | wgt::Features::MULTI_DRAW_INDIRECT_COUNT
| wgt::Features::ADDRESS_MODE_CLAMP_TO_BORDER | wgt::Features::ADDRESS_MODE_CLAMP_TO_BORDER
| wgt::Features::NON_FILL_POLYGON_MODE | wgt::Features::NON_FILL_POLYGON_MODE
|wgt::Features::VERTEX_WRITABLE_STORAGE; | wgt::Features::VERTEX_WRITABLE_STORAGE
| wgt::Features::TIMESTAMP_QUERY
| wgt::Features::PIPELINE_STATISTICS_QUERY;
features.set( features.set(
wgt::Features::CONSERVATIVE_RASTERIZATION, wgt::Features::CONSERVATIVE_RASTERIZATION,

View File

@ -338,10 +338,26 @@ impl crate::CommandEncoder<super::Api> for super::CommandEncoder {
} }
} }
unsafe fn begin_query(&mut self, set: &super::QuerySet, index: u32) {} unsafe fn begin_query(&mut self, set: &super::QuerySet, index: u32) {
unsafe fn end_query(&mut self, set: &super::QuerySet, index: u32) {} self.list
unsafe fn write_timestamp(&mut self, set: &super::QuerySet, index: u32) {} .unwrap()
unsafe fn reset_queries(&mut self, set: &super::QuerySet, range: Range<u32>) {} .BeginQuery(set.raw.as_mut_ptr(), set.raw_ty, index);
}
unsafe fn end_query(&mut self, set: &super::QuerySet, index: u32) {
self.list
.unwrap()
.EndQuery(set.raw.as_mut_ptr(), set.raw_ty, index);
}
unsafe fn write_timestamp(&mut self, set: &super::QuerySet, index: u32) {
self.list.unwrap().EndQuery(
set.raw.as_mut_ptr(),
d3d12::D3D12_QUERY_TYPE_TIMESTAMP,
index,
);
}
unsafe fn reset_queries(&mut self, _set: &super::QuerySet, _range: Range<u32>) {
// nothing to do here
}
unsafe fn copy_query_results( unsafe fn copy_query_results(
&mut self, &mut self,
set: &super::QuerySet, set: &super::QuerySet,
@ -350,6 +366,14 @@ impl crate::CommandEncoder<super::Api> for super::CommandEncoder {
offset: wgt::BufferAddress, offset: wgt::BufferAddress,
stride: wgt::BufferSize, stride: wgt::BufferSize,
) { ) {
self.list.unwrap().ResolveQueryData(
set.raw.as_mut_ptr(),
set.raw_ty,
range.start,
range.end - range.start,
buffer.resource.as_mut_ptr(),
offset,
);
} }
// render // render

View File

@ -1059,10 +1059,19 @@ impl crate::Device<super::Api> for super::Device {
&self, &self,
desc: &wgt::QuerySetDescriptor<crate::Label>, desc: &wgt::QuerySetDescriptor<crate::Label>,
) -> Result<super::QuerySet, crate::DeviceError> { ) -> Result<super::QuerySet, crate::DeviceError> {
let heap_ty = match desc.ty { let (heap_ty, raw_ty) = match desc.ty {
wgt::QueryType::Occlusion => native::QueryHeapType::Occlusion, wgt::QueryType::Occlusion => (
wgt::QueryType::PipelineStatistics(_) => native::QueryHeapType::PipelineStatistics, native::QueryHeapType::Occlusion,
wgt::QueryType::Timestamp => native::QueryHeapType::Timestamp, d3d12::D3D12_QUERY_TYPE_BINARY_OCCLUSION,
),
wgt::QueryType::PipelineStatistics(_) => (
native::QueryHeapType::PipelineStatistics,
d3d12::D3D12_QUERY_TYPE_TIMESTAMP,
),
wgt::QueryType::Timestamp => (
native::QueryHeapType::Timestamp,
d3d12::D3D12_QUERY_TYPE_PIPELINE_STATISTICS,
),
}; };
let raw = self let raw = self
@ -1070,7 +1079,7 @@ impl crate::Device<super::Api> for super::Device {
.create_query_heap(heap_ty, desc.count, 0) .create_query_heap(heap_ty, desc.count, 0)
.into_device_result("Query heap creation")?; .into_device_result("Query heap creation")?;
Ok(super::QuerySet { raw, ty: desc.ty }) Ok(super::QuerySet { raw, raw_ty })
} }
unsafe fn destroy_query_set(&self, set: super::QuerySet) { unsafe fn destroy_query_set(&self, set: super::QuerySet) {
set.raw.destroy(); set.raw.destroy();

View File

@ -302,7 +302,7 @@ unsafe impl Sync for Sampler {}
#[derive(Debug)] #[derive(Debug)]
pub struct QuerySet { pub struct QuerySet {
raw: native::QueryHeap, raw: native::QueryHeap,
ty: wgt::QueryType, raw_ty: d3d12::D3D12_QUERY_TYPE,
} }
unsafe impl Send for QuerySet {} unsafe impl Send for QuerySet {}

View File

@ -204,7 +204,7 @@ bitflags::bitflags! {
/// ///
/// Supported Platforms: /// Supported Platforms:
/// - Vulkan (works) /// - Vulkan (works)
/// - DX12 (future) /// - DX12 (works)
/// ///
/// This is a web and native feature. /// This is a web and native feature.
const TIMESTAMP_QUERY = 0x0000_0000_0000_0004; const TIMESTAMP_QUERY = 0x0000_0000_0000_0004;
@ -219,7 +219,7 @@ bitflags::bitflags! {
/// ///
/// Supported Platforms: /// Supported Platforms:
/// - Vulkan (works) /// - Vulkan (works)
/// - DX12 (future) /// - DX12 (works)
/// ///
/// This is a web and native feature. /// This is a web and native feature.
const PIPELINE_STATISTICS_QUERY = 0x0000_0000_0000_0008; const PIPELINE_STATISTICS_QUERY = 0x0000_0000_0000_0008;