diff --git a/CHANGELOG.md b/CHANGELOG.md index 3eef977e2..fa9562d90 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -135,6 +135,7 @@ By @beholdnec in [#8505](https://github.com/gfx-rs/wgpu/pull/8505). - Extend `copy_texture_to_texture` to allow copying a single plane of a multi-planar source (NV12, P010) into a single-plane destination of the matching format (e.g. NV12 `Plane0` → `R8Unorm`, NV12 `Plane1` → `Rg8Unorm`). `copy_size` is interpreted in plane texels, not luma texels. By @AdrianEddy in [#9551](https://github.com/gfx-rs/wgpu/pull/9551). - Added `InstanceFlags::STRICT_WEBGPU_COMPLIANCE` flag, which restricts the available feature set to the one defined by the WebGPU specification. By @teoxoy in [#9586](https://github.com/gfx-rs/wgpu/pull/9586). - Implemented `QuerySet::destroy` by @sagudev in [#9671](https://github.com/gfx-rs/wgpu/pull/9671) +- Implemented query set initialization tracking, ensuring unwritten query slots resolve to 0; avoiding UB. By @teoxoy in [#9664](https://github.com/gfx-rs/wgpu/pull/9664). #### Metal diff --git a/examples/features/src/timestamp_queries/mod.rs b/examples/features/src/timestamp_queries/mod.rs index 0e1f673dd..527e9d87d 100644 --- a/examples/features/src/timestamp_queries/mod.rs +++ b/examples/features/src/timestamp_queries/mod.rs @@ -143,7 +143,6 @@ impl Queries { fn resolve(&self, encoder: &mut wgpu::CommandEncoder) { encoder.resolve_query_set( &self.set, - // TODO(https://github.com/gfx-rs/wgpu/issues/3993): Musn't be larger than the number valid queries in the set. 0..self.next_unused_query, &self.resolve_buffer, 0, diff --git a/wgpu-core/src/command/compute.rs b/wgpu-core/src/command/compute.rs index 75b4875bb..871bca98d 100644 --- a/wgpu-core/src/command/compute.rs +++ b/wgpu-core/src/command/compute.rs @@ -17,7 +17,10 @@ use crate::{ memory_init::{fixup_discarded_surfaces, SurfacesInDiscardState}, pass::{self, flush_bindings_helper}, pass_base, pass_try, - query::{end_pipeline_statistics_query, validate_and_begin_pipeline_statistics_query}, + query::{ + end_pipeline_statistics_query, record_pass_timestamp_writes, + validate_and_begin_pipeline_statistics_query, + }, ArcCommand, ArcPassTimestampWrites, BasePass, BindGroupStateChange, CommandEncoder, CommandEncoderError, DebugGroupError, EncoderStateError, InnerCommandEncoder, MapPassErr, PassErrorScope, PassStateError, PassTimestampWrites, QueryUseError, StateChange, @@ -632,6 +635,8 @@ pub(super) fn encode_compute_pass( indirect_draw_validation_resources: parent_state.indirect_draw_validation_resources, snatch_guard: parent_state.snatch_guard, debug_scope_depth: &mut debug_scope_depth, + query_set_writes: parent_state.query_set_writes, + deferred_query_set_resolves: parent_state.deferred_query_set_resolves, }, binder: Binder::new(), temp_offsets: Vec::new(), @@ -670,6 +675,8 @@ pub(super) fn encode_compute_pass( if let Some(tw) = timestamp_writes.take() { tw.query_set.same_device(device).map_pass_err(pass_scope)?; + record_pass_timestamp_writes(&tw, state.pass.base.query_set_writes); + let query_set = state .pass .base @@ -825,6 +832,7 @@ pub(super) fn encode_compute_pass( state.pass.base.raw_encoder, &mut state.active_query, state.pass.base.snatch_guard, + state.pass.base.query_set_writes, ) .map_pass_err(scope)?; } diff --git a/wgpu-core/src/command/encoder.rs b/wgpu-core/src/command/encoder.rs index 19222c6e3..a0cf3655a 100644 --- a/wgpu-core/src/command/encoder.rs +++ b/wgpu-core/src/command/encoder.rs @@ -1,7 +1,10 @@ use alloc::{sync::Arc, vec::Vec}; use crate::{ - command::memory_init::CommandBufferTextureMemoryActions, + command::{ + memory_init::CommandBufferTextureMemoryActions, + query::{DeferredQuerySetResolve, QuerySetWrites}, + }, device::{queue::TempResource, Device}, init_tracker::BufferInitTrackerAction, ray_tracing::AsAction, @@ -50,4 +53,7 @@ pub(crate) struct EncodingState<'snatch_guard, 'cmd_enc, E: ?Sized = dyn hal::Dy /// When encoding a compute or render pass, this is the depth of debug /// scopes in the pass, not the depth of debug scopes in the parent encoder. pub(crate) debug_scope_depth: &'cmd_enc mut u32, + + pub(crate) query_set_writes: &'cmd_enc mut QuerySetWrites, + pub(crate) deferred_query_set_resolves: &'cmd_enc mut Vec, } diff --git a/wgpu-core/src/command/memory_init.rs b/wgpu-core/src/command/memory_init.rs index faca41704..6ee1ebc4e 100644 --- a/wgpu-core/src/command/memory_init.rs +++ b/wgpu-core/src/command/memory_init.rs @@ -7,7 +7,7 @@ use core::ops::Range; use hashbrown::hash_map::Entry; use crate::{ - device::Device, + device::{Device, DeviceError}, init_tracker::*, resource::{DestroyedResourceError, ParentDevice, RawResourceAccess, Texture, Trackable}, snatch::SnatchGuard, @@ -335,4 +335,74 @@ impl BakedCommands { Ok(()) } + + pub(crate) fn process_deferred_query_set_resolves( + &mut self, + device: &Device, + snatch_guard: &SnatchGuard<'_>, + ) -> Result<(), DeviceError> { + profiling::scope!("process_deferred_query_set_resolves"); + + for mut resolve in self.deferred_query_set_resolves.drain(..).rev() { + let raw_dst = resolve.dst_buffer.try_raw(snatch_guard).unwrap(); + let raw_query_set = resolve.query_set.try_raw(snatch_guard).unwrap(); + + let raw_encoder = self.encoder.open_pass(crate::hal_label( + Some("(wgpu internal) Deferred query set resolve"), + device.instance_flags, + ))?; + + let initialized_slots_guard = resolve.query_set.initialized_slots.lock(); + let initialized_slots = + if let Some(query_set_writes) = resolve.query_set_writes.as_mut() { + query_set_writes.or(&initialized_slots_guard); + &*query_set_writes + } else { + &*initialized_slots_guard + }; + + let mut start = resolve.start_query; + while start < resolve.end_query { + let is_initialized = initialized_slots[start as usize]; + let end = (start + 1..resolve.end_query) + .find(|&i| initialized_slots[i as usize] != is_initialized) + .unwrap_or(resolve.end_query); + + let byte_offset = resolve.destination_offset + + (start - resolve.start_query) as u64 * resolve.stride; + let byte_len = (end - start) as u64 * resolve.stride; + + if is_initialized { + unsafe { + raw_encoder.copy_query_results( + raw_query_set, + start..end, + raw_dst, + byte_offset, + wgt::BufferSize::new_unchecked(resolve.stride), + ); + } + } else { + unsafe { + raw_encoder.clear_buffer(raw_dst, byte_offset..byte_offset + byte_len); + } + } + + start = end; + } + drop(initialized_slots_guard); + + self.encoder.close_and_insert_at(resolve.insertion_point)?; + } + + // Update query set initialization state. + for query_set in &self.trackers.query_sets { + if let Some(slots) = self.query_set_writes.get(&query_set.tracker_index()) { + let mut initialized = query_set.initialized_slots.lock(); + initialized.or(slots); + } + } + + Ok(()) + } } diff --git a/wgpu-core/src/command/mod.rs b/wgpu-core/src/command/mod.rs index c9c4c016a..b9c9a6f4d 100644 --- a/wgpu-core/src/command/mod.rs +++ b/wgpu-core/src/command/mod.rs @@ -653,9 +653,15 @@ impl InnerCommandEncoder { /// /// - If the encoder is not open. /// + /// # Warning + /// + /// Any [`DeferredQuerySetResolve::insertion_point`] pointing to the + /// last element will be invalidated. + /// /// [l]: InnerCommandEncoder::list /// [`transition_buffers`]: hal::CommandEncoder::transition_buffers /// [`transition_textures`]: hal::CommandEncoder::transition_textures + /// [`DeferredQuerySetResolve::insertion_point`]: query::DeferredQuerySetResolve::insertion_point fn close_and_swap(&mut self) -> Result<(), DeviceError> { self.close_and_insert_at(self.list.len() - 1) } @@ -669,7 +675,13 @@ impl InnerCommandEncoder { /// /// - If the encoder is not open. /// + /// # Warning + /// + /// All existing [`DeferredQuerySetResolve::insertion_point`] values + /// will be invalidated. + /// /// [l]: InnerCommandEncoder::list + /// [`DeferredQuerySetResolve::insertion_point`]: query::DeferredQuerySetResolve::insertion_point pub(crate) fn close_and_push_front(&mut self) -> Result<(), DeviceError> { self.close_and_insert_at(0) } @@ -683,7 +695,13 @@ impl InnerCommandEncoder { /// /// - If the encoder is not open. /// + /// # Warning + /// + /// Any [`DeferredQuerySetResolve::insertion_point`] value that is + /// >= `index` will be invalidated. + /// /// [l]: InnerCommandEncoder::list + /// [`DeferredQuerySetResolve::insertion_point`]: query::DeferredQuerySetResolve::insertion_point pub(crate) fn close_and_insert_at(&mut self, index: usize) -> Result<(), DeviceError> { assert!(self.is_open); self.is_open = false; @@ -813,6 +831,8 @@ pub(crate) struct BakedCommands { pub(crate) indirect_draw_validation_resources: crate::indirect_validation::DrawResources, buffer_memory_init_actions: Vec, texture_memory_actions: CommandBufferTextureMemoryActions, + pub(crate) query_set_writes: query::QuerySetWrites, + pub(crate) deferred_query_set_resolves: Vec, } /// The mutable state of a [`CommandBuffer`]. @@ -846,6 +866,11 @@ pub struct CommandBufferMutable { /// with integer pointers, and moves them into `trace_commands`. #[cfg(feature = "trace")] pub(crate) trace_commands: Option>>, + + /// Tracks which query slots have been written by commands in this encoder. + pub(crate) query_set_writes: query::QuerySetWrites, + /// Query set resolves that had to be deferred to submit time. + pub(crate) deferred_query_set_resolves: Vec, } impl CommandBufferMutable { @@ -857,6 +882,8 @@ impl CommandBufferMutable { indirect_draw_validation_resources: self.indirect_draw_validation_resources, buffer_memory_init_actions: self.buffer_memory_init_actions, texture_memory_actions: self.texture_memory_actions, + query_set_writes: self.query_set_writes, + deferred_query_set_resolves: self.deferred_query_set_resolves, } } } @@ -912,6 +939,8 @@ impl CommandEncoder { indirect_draw_validation_resources: crate::indirect_validation::DrawResources::new(device.clone()), commands: Vec::new(), + query_set_writes: Default::default(), + deferred_query_set_resolves: Default::default(), #[cfg(feature = "trace")] trace_commands: if device.trace.lock().is_some() { Some(Vec::new()) @@ -1040,12 +1069,15 @@ impl CommandEncoder { for command in commands { if matches!( command, - ArcCommand::RunRenderPass { .. } | ArcCommand::RunComputePass { .. } + ArcCommand::RunRenderPass { .. } + | ArcCommand::RunComputePass { .. } + | ArcCommand::ResolveQuerySet { .. } ) { // Compute passes and render passes can accept either an - // open or closed encoder. This state object holds an - // `InnerCommandEncoder`. See the documentation of - // [`EncodingState`]. + // open or closed encoder. Resolving query sets needs to + // potentially close and open the encoder. This state + // object holds an `InnerCommandEncoder`. See the + // documentation of [`EncodingState`]. let mut state = EncodingState { device, raw_encoder: &mut cmd_buf_data.encoder, @@ -1058,6 +1090,8 @@ impl CommandEncoder { .indirect_draw_validation_resources, snatch_guard: &snatch_guard, debug_scope_depth: &mut debug_scope_depth, + query_set_writes: &mut cmd_buf_data.query_set_writes, + deferred_query_set_resolves: &mut cmd_buf_data.deferred_query_set_resolves, }; match command { @@ -1111,6 +1145,22 @@ impl CommandEncoder { } res?; } + ArcCommand::ResolveQuerySet { + query_set, + start_query, + query_count, + destination, + destination_offset, + } => { + query::resolve_query_set( + &mut state, + query_set, + start_query, + query_count, + destination, + destination_offset, + )?; + } _ => unreachable!(), } } else { @@ -1132,6 +1182,8 @@ impl CommandEncoder { .indirect_draw_validation_resources, snatch_guard: &snatch_guard, debug_scope_depth: &mut debug_scope_depth, + query_set_writes: &mut cmd_buf_data.query_set_writes, + deferred_query_set_resolves: &mut cmd_buf_data.deferred_query_set_resolves, }; match command { ArcCommand::CopyBufferToBuffer { @@ -1169,22 +1221,6 @@ impl CommandEncoder { } => { query::write_timestamp(&mut state, query_set, query_index)?; } - ArcCommand::ResolveQuerySet { - query_set, - start_query, - query_count, - destination, - destination_offset, - } => { - query::resolve_query_set( - &mut state, - query_set, - start_query, - query_count, - destination, - destination_offset, - )?; - } ArcCommand::PushDebugGroup(label) => { push_debug_group(&mut state, &label)?; } @@ -1207,7 +1243,9 @@ impl CommandEncoder { texture_transitions, )?; } - ArcCommand::RunComputePass { .. } | ArcCommand::RunRenderPass { .. } => { + ArcCommand::RunComputePass { .. } + | ArcCommand::RunRenderPass { .. } + | ArcCommand::ResolveQuerySet { .. } => { unreachable!() } } diff --git a/wgpu-core/src/command/pass.rs b/wgpu-core/src/command/pass.rs index 99af9f889..22b52568e 100644 --- a/wgpu-core/src/command/pass.rs +++ b/wgpu-core/src/command/pass.rs @@ -307,6 +307,7 @@ where query_index, pending_query_resets, state.base.snatch_guard, + state.base.query_set_writes, )?; Ok(()) } diff --git a/wgpu-core/src/command/query.rs b/wgpu-core/src/command/query.rs index 254461f2c..6d054fef0 100644 --- a/wgpu-core/src/command/query.rs +++ b/wgpu-core/src/command/query.rs @@ -1,8 +1,9 @@ use alloc::{sync::Arc, vec, vec::Vec}; +use bit_vec::BitVec; use core::{iter, mem}; use crate::{ - command::{encoder::EncodingState, ArcCommand, EncoderStateError}, + command::{encoder::EncodingState, ArcCommand, EncoderStateError, InnerCommandEncoder}, device::{Device, DeviceError, MissingFeatures}, global::Global, id, @@ -21,6 +22,48 @@ use wgt::{ BufferAddress, }; +pub(crate) struct DeferredQuerySetResolve { + pub(crate) query_set: Arc, + pub(crate) query_set_writes: Option, + pub(crate) start_query: u32, + pub(crate) end_query: u32, + pub(crate) dst_buffer: Arc, + pub(crate) destination_offset: BufferAddress, + /// Bytes per query slot in the destination buffer + /// (accounts for pipeline-statistics element count * `QUERY_SIZE`). + pub(crate) stride: u64, + /// Index into [`InnerCommandEncoder::list`] at which a new command buffer + /// for the resolve operation must be inserted at submit time so that it + /// executes at exactly the position it was recorded. + pub(crate) insertion_point: usize, +} + +pub(crate) type QuerySetWrites = FastHashMap; + +pub(super) fn record_pass_timestamp_writes( + tw: &crate::command::ArcPassTimestampWrites, + query_set_writes: &mut QuerySetWrites, +) { + for index in tw + .beginning_of_pass_write_index + .into_iter() + .chain(tw.end_of_pass_write_index) + { + record_query_write(query_set_writes, &tw.query_set, index); + } +} + +pub(crate) fn record_query_write( + query_set_writes: &mut QuerySetWrites, + query_set: &Arc, + slot_index: u32, +) { + query_set_writes + .entry(query_set.tracker_index()) + .or_insert_with(|| BitVec::from_elem(query_set.desc.count as usize, false)) + .set(slot_index as usize, true); +} + #[derive(Debug)] pub(crate) struct QueryResetMap { map: FastHashMap, Arc)>, @@ -256,6 +299,7 @@ impl QuerySet { query_index: u32, reset_state: Option<&mut QueryResetMap>, snatch_guard: &SnatchGuard<'_>, + query_set_writes: &mut QuerySetWrites, ) -> Result<(), QueryUseError> { let needs_reset = reset_state.is_none(); self.validate_query(SimplifiedQueryType::Timestamp, query_index, reset_state)?; @@ -269,6 +313,7 @@ impl QuerySet { raw_encoder.write_timestamp(self.try_raw(snatch_guard)?, query_index); } + record_query_write(query_set_writes, self, query_index); Ok(()) } } @@ -313,9 +358,11 @@ pub(super) fn end_occlusion_query( raw_encoder: &mut dyn hal::DynCommandEncoder, active_query: &mut Option<(Arc, u32)>, snatch_guard: &SnatchGuard<'_>, + query_set_writes: &mut QuerySetWrites, ) -> Result<(), QueryUseError> { if let Some((query_set, query_index)) = active_query.take() { unsafe { raw_encoder.end_query(query_set.try_raw(snatch_guard)?, query_index) }; + record_query_write(query_set_writes, &query_set, query_index); Ok(()) } else { Err(QueryUseError::AlreadyStopped) @@ -369,9 +416,11 @@ pub(super) fn end_pipeline_statistics_query( raw_encoder: &mut dyn hal::DynCommandEncoder, active_query: &mut Option<(Arc, u32)>, snatch_guard: &SnatchGuard<'_>, + query_set_writes: &mut QuerySetWrites, ) -> Result<(), QueryUseError> { if let Some((query_set, query_index)) = active_query.take() { unsafe { raw_encoder.end_query(query_set.try_raw(snatch_guard)?, query_index) }; + record_query_write(query_set_writes, &query_set, query_index); Ok(()) } else { Err(QueryUseError::AlreadyStopped) @@ -440,6 +489,7 @@ pub(super) fn write_timestamp( query_index, None, state.snatch_guard, + state.query_set_writes, )?; state.tracker.query_sets.insert_single(query_set); @@ -448,7 +498,7 @@ pub(super) fn write_timestamp( } pub(super) fn resolve_query_set( - state: &mut EncodingState, + state: &mut EncodingState<'_, '_, InnerCommandEncoder>, query_set: Arc, start_query: u32, query_count: u32, @@ -511,7 +561,8 @@ pub(super) fn resolve_query_set( bytes_used, })?; - // TODO(https://github.com/gfx-rs/wgpu/issues/3993): Need to track initialization state. + let query_set = state.tracker.query_sets.insert_single(query_set); + state .buffer_memory_init_actions .extend(dst_buffer.initialization_status.read().create_action( @@ -520,23 +571,55 @@ pub(super) fn resolve_query_set( MemoryInitKind::ImplicitlyInitialized, )); + let raw_encoder = state.raw_encoder.open_if_closed()?; let raw_dst_buffer = dst_buffer.try_raw(state.snatch_guard)?; unsafe { - state.raw_encoder.transition_buffers(dst_barrier.as_slice()); - state.raw_encoder.copy_query_results( - query_set.try_raw(state.snatch_guard)?, - start_query..end_query, - raw_dst_buffer, - destination_offset, - wgt::BufferSize::new_unchecked(stride as u64), - ); + raw_encoder.transition_buffers(dst_barrier.as_slice()); + } + + // Check if all slots in the range have been written within this encoder. + // If so we can emit `copy_query_results` directly. + // Otherwise defer to submit time where we have knowledge of + // the query set initialization state. + let query_set_writes = state.query_set_writes.get(&query_set.tracker_index()); + let all_written = + query_set_writes.is_some_and(|slots| (start_query..end_query).all(|i| slots[i as usize])); + + if all_written { + unsafe { + raw_encoder.copy_query_results( + query_set.try_raw(state.snatch_guard)?, + start_query..end_query, + raw_dst_buffer, + destination_offset, + wgt::BufferSize::new_unchecked(stride as u64), + ); + } + } else { + state.raw_encoder.close_if_open()?; + let insertion_point = state.raw_encoder.list.len(); + + state + .deferred_query_set_resolves + .push(DeferredQuerySetResolve { + query_set: query_set.clone(), + query_set_writes: query_set_writes.cloned(), + start_query, + end_query, + dst_buffer: dst_buffer.clone(), + destination_offset, + stride: stride as u64, + insertion_point, + }); } if matches!(query_set.desc.ty, wgt::QueryType::Timestamp) { + let raw_encoder = state.raw_encoder.open_if_closed()?; + // Timestamp normalization is only needed for timestamps. state.device.timestamp_normalizer.get().unwrap().normalize( state.snatch_guard, - state.raw_encoder, + raw_encoder, &mut state.tracker.buffers, dst_buffer .timestamp_normalization_bind_group @@ -548,7 +631,5 @@ pub(super) fn resolve_query_set( ); } - state.tracker.query_sets.insert_single(query_set); - Ok(()) } diff --git a/wgpu-core/src/command/render.rs b/wgpu-core/src/command/render.rs index 86bc24e72..19b06244b 100644 --- a/wgpu-core/src/command/render.rs +++ b/wgpu-core/src/command/render.rs @@ -19,8 +19,9 @@ use crate::{ pass::{self, flush_bindings_helper}, pass_base, pass_try, query::{ - end_occlusion_query, end_pipeline_statistics_query, validate_and_begin_occlusion_query, - validate_and_begin_pipeline_statistics_query, QueryResetMap, + end_occlusion_query, end_pipeline_statistics_query, record_pass_timestamp_writes, + validate_and_begin_occlusion_query, validate_and_begin_pipeline_statistics_query, + QueryResetMap, QuerySetWrites, }, render_command::ArcRenderCommand, ArcCommand, ArcPassTimestampWrites, BasePass, BindGroupStateChange, @@ -1166,6 +1167,7 @@ impl RenderPassInfo { pending_query_resets: &mut QueryResetMap, pending_discard_init_fixups: &mut SurfacesInDiscardState, snatch_guard: &SnatchGuard<'_>, + query_set_writes: &mut QuerySetWrites, multiview_mask: Option, ) -> Result { profiling::scope!("RenderPassInfo::start"); @@ -1632,6 +1634,8 @@ impl RenderPassInfo { pending_query_resets.use_query_set(query_set, index); } + record_pass_timestamp_writes(tw, query_set_writes); + Some(hal::PassTimestampWrites { query_set: query_set.try_raw(snatch_guard)?, beginning_of_pass_write_index: tw.beginning_of_pass_write_index, @@ -2109,6 +2113,7 @@ pub(super) fn encode_render_pass( &mut pending_query_resets, &mut pending_discard_init_fixups, parent_state.snatch_guard, + parent_state.query_set_writes, multiview_mask, ) .map_pass_err(pass_scope)?; @@ -2148,6 +2153,8 @@ pub(super) fn encode_render_pass( .indirect_draw_validation_resources, snatch_guard: parent_state.snatch_guard, debug_scope_depth: &mut debug_scope_depth, + query_set_writes: parent_state.query_set_writes, + deferred_query_set_resolves: parent_state.deferred_query_set_resolves, }, pending_discard_init_fixups, scope: device.new_usage_scope(), @@ -2401,6 +2408,7 @@ pub(super) fn encode_render_pass( state.pass.base.raw_encoder, &mut state.active_occlusion_query, state.pass.base.snatch_guard, + state.pass.base.query_set_writes, ) .map_pass_err(scope)?; } @@ -2434,6 +2442,7 @@ pub(super) fn encode_render_pass( state.pass.base.raw_encoder, &mut state.active_pipeline_statistics_query, state.pass.base.snatch_guard, + state.pass.base.query_set_writes, ) .map_pass_err(scope)?; } diff --git a/wgpu-core/src/device/queue.rs b/wgpu-core/src/device/queue.rs index a363a8032..592f5f3d8 100644 --- a/wgpu-core/src/device/queue.rs +++ b/wgpu-core/src/device/queue.rs @@ -1416,6 +1416,13 @@ impl Queue { } }; + if let Err(e) = baked.process_deferred_query_set_resolves( + &self.device, + &submission.snatch_guard, + ) { + break 'error Err(e.into()); + } + // execute resource transitions if let Err(e) = baked.encoder.open_pass(hal_label( Some("(wgpu internal) Transit"), diff --git a/wgpu-core/src/device/resource.rs b/wgpu-core/src/device/resource.rs index 2ff337255..b89bc4c36 100644 --- a/wgpu-core/src/device/resource.rs +++ b/wgpu-core/src/device/resource.rs @@ -5030,6 +5030,10 @@ impl Device { label: desc.label.to_string(), tracking_data: TrackingData::new(self.tracker_indices.query_sets.clone()), desc: desc.map_label(|_| ()), + initialized_slots: Mutex::new( + rank::QUERY_SET_INITIALIZED_SLOTS, + bit_vec::BitVec::from_elem(desc.count as usize, false), + ), }; let query_set = Arc::new(query_set); diff --git a/wgpu-core/src/lock/rank.rs b/wgpu-core/src/lock/rank.rs index 401fb9c7b..2ce4025bc 100644 --- a/wgpu-core/src/lock/rank.rs +++ b/wgpu-core/src/lock/rank.rs @@ -133,6 +133,7 @@ define_lock_ranks! { TEXTURE_BIND_GROUPS, TEXTURE_CLEAR_MODE, TEXTURE_VIEWS, + QUERY_SET_INITIALIZED_SLOTS, // Uncomment this to see an interesting cycle. // COMMAND_BUFFER_DATA, } @@ -185,6 +186,7 @@ define_lock_ranks! { rank DEVICE_USAGE_SCOPES "Device::usage_scopes" followed by { } rank REGISTRY_STORAGE "Registry::storage" followed by { } rank SHARED_TRACKER_INDEX_ALLOCATOR_INNER "SharedTrackerIndexAllocator::inner" followed by { } + rank QUERY_SET_INITIALIZED_SLOTS "QuerySet::initialized_slots" followed by { } rank TEXTURE_BIND_GROUPS "Texture::bind_groups" followed by { } rank TEXTURE_CLEAR_MODE "Texture::clear_mode" followed by { } rank TEXTURE_VIEWS "Texture::views" followed by { } diff --git a/wgpu-core/src/resource.rs b/wgpu-core/src/resource.rs index 6c710c74f..e1e4da029 100644 --- a/wgpu-core/src/resource.rs +++ b/wgpu-core/src/resource.rs @@ -2246,6 +2246,7 @@ pub struct QuerySet { pub(crate) label: String, pub(crate) tracking_data: TrackingData, pub(crate) desc: wgt::QuerySetDescriptor<()>, + pub(crate) initialized_slots: Mutex, } impl RawResourceAccess for QuerySet {