From 42be6f36aa2b13c68ab6b8b59eb58b9f554f9ad9 Mon Sep 17 00:00:00 2001 From: Jinlei Li Date: Thu, 13 Oct 2022 14:10:33 +0800 Subject: [PATCH] web: call `create_query_set` and `write_timestamp` of web-sys (#3091) --- wgpu/src/backend/web.rs | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/wgpu/src/backend/web.rs b/wgpu/src/backend/web.rs index 7544e57b9..bae4080ee 100644 --- a/wgpu/src/backend/web.rs +++ b/wgpu/src/backend/web.rs @@ -144,11 +144,15 @@ impl crate::ComputePassInner for ComputePass { .dispatch_workgroups_indirect_with_f64(&indirect_buffer.0, indirect_offset as f64); } - fn write_timestamp(&mut self, _query_set: &(), _query_index: u32) { + fn write_timestamp(&mut self, _query_set: &Sendable, _query_index: u32) { panic!("WRITE_TIMESTAMP_INSIDE_PASSES feature must be enabled to call write_timestamp in a compute pass") } - fn begin_pipeline_statistics_query(&mut self, _query_set: &(), _query_index: u32) { + fn begin_pipeline_statistics_query( + &mut self, + _query_set: &Sendable, + _query_index: u32, + ) { // Not available in gecko yet } @@ -494,11 +498,15 @@ impl crate::RenderPassInner for RenderPass { self.0.execute_bundles(&mapped); } - fn write_timestamp(&mut self, _query_set: &(), _query_index: u32) { + fn write_timestamp(&mut self, _query_set: &Sendable, _query_index: u32) { panic!("WRITE_TIMESTAMP_INSIDE_PASSES feature must be enabled to call write_timestamp in a compute pass") } - fn begin_pipeline_statistics_query(&mut self, _query_set: &(), _query_index: u32) { + fn begin_pipeline_statistics_query( + &mut self, + _query_set: &Sendable, + _query_index: u32, + ) { // Not available in gecko yet } @@ -1039,7 +1047,7 @@ impl crate::Context for Context { type SamplerId = Sendable; type BufferId = Sendable; type TextureId = Sendable; - type QuerySetId = (); //TODO! + type QuerySetId = Sendable; type PipelineLayoutId = Sendable; type RenderPipelineId = Sendable; type ComputePipelineId = Sendable; @@ -1802,9 +1810,19 @@ impl crate::Context for Context { fn device_create_query_set( &self, - _device: &Self::DeviceId, - _desc: &wgt::QuerySetDescriptor, + device: &Self::DeviceId, + desc: &wgt::QuerySetDescriptor, ) -> Self::QuerySetId { + let ty = match desc.ty { + wgt::QueryType::Occlusion => web_sys::GpuQueryType::Occlusion, + wgt::QueryType::Timestamp => web_sys::GpuQueryType::Timestamp, + wgt::QueryType::PipelineStatistics(_) => unreachable!(), + }; + let mut mapped_desc = web_sys::GpuQuerySetDescriptor::new(desc.count, ty); + if let Some(label) = desc.label { + mapped_desc.label(label); + } + Sendable(device.0.create_query_set(&mapped_desc)) } fn device_create_command_encoder( @@ -2263,11 +2281,11 @@ impl crate::Context for Context { fn command_encoder_write_timestamp( &self, - _encoder: &Self::CommandEncoderId, - _query_set: &Self::QuerySetId, - _query_index: u32, + encoder: &Self::CommandEncoderId, + query_set: &Self::QuerySetId, + query_index: u32, ) { - unimplemented!(); + encoder.0.write_timestamp(&query_set.0, query_index); } fn command_encoder_resolve_query_set(