From dbcb273188b35bddd81d517b4b3f86573b89ea31 Mon Sep 17 00:00:00 2001 From: teoxoy <28601907+teoxoy@users.noreply.github.com> Date: Tue, 2 Jul 2024 18:35:23 +0200 Subject: [PATCH] remove `StatelessTracker.add_single` --- wgpu-core/src/command/bundle.rs | 17 ++++++++++------- wgpu-core/src/command/query.rs | 16 ++++++++-------- wgpu-core/src/track/stateless.rs | 16 ---------------- 3 files changed, 18 insertions(+), 31 deletions(-) diff --git a/wgpu-core/src/command/bundle.rs b/wgpu-core/src/command/bundle.rs index 65b914ceae..d2fd938776 100644 --- a/wgpu-core/src/command/bundle.rs +++ b/wgpu-core/src/command/bundle.rs @@ -618,11 +618,9 @@ fn set_bind_group( bind_group_id: id::Id, ) -> Result<(), RenderBundleErrorInner> { let bind_group = bind_group_guard - .get(bind_group_id) + .get_owned(bind_group_id) .map_err(|_| RenderCommandError::InvalidBindGroupId(bind_group_id))?; - state.trackers.bind_groups.write().add_single(bind_group); - bind_group.same_device(&state.device)?; let max_bind_groups = state.device.limits.max_bind_groups; @@ -655,6 +653,7 @@ fn set_bind_group( offsets_range, ); unsafe { state.trackers.merge_bind_group(&bind_group.used)? }; + state.trackers.bind_groups.write().insert_single(bind_group); // Note: stateless trackers are not merged: the lifetime reference // is held to the bind group itself. Ok(()) @@ -669,11 +668,9 @@ fn set_pipeline( pipeline_id: id::Id, ) -> Result<(), RenderBundleErrorInner> { let pipeline = pipeline_guard - .get(pipeline_id) + .get_owned(pipeline_id) .map_err(|_| RenderCommandError::InvalidPipelineId(pipeline_id))?; - state.trackers.render_pipelines.write().add_single(pipeline); - pipeline.same_device(&state.device)?; context @@ -687,7 +684,7 @@ fn set_pipeline( return Err(RenderCommandError::IncompatibleStencilAccess(pipeline.error_ident()).into()); } - let pipeline_state = PipelineState::new(pipeline); + let pipeline_state = PipelineState::new(&pipeline); state .commands @@ -700,6 +697,12 @@ fn set_pipeline( state.invalidate_bind_groups(&pipeline_state, &pipeline.layout); state.pipeline = Some(pipeline_state); + + state + .trackers + .render_pipelines + .write() + .insert_single(pipeline); Ok(()) } diff --git a/wgpu-core/src/command/query.rs b/wgpu-core/src/command/query.rs index 3b69475653..f01050d7f8 100644 --- a/wgpu-core/src/command/query.rs +++ b/wgpu-core/src/command/query.rs @@ -231,7 +231,7 @@ pub(super) fn validate_and_begin_occlusion_query( let needs_reset = reset_state.is_none(); query_set.validate_query(SimplifiedQueryType::Occlusion, query_index, reset_state)?; - tracker.add_single(&query_set); + tracker.insert_single(query_set.clone()); if let Some((_old, old_idx)) = active_query.take() { return Err(QueryUseError::AlreadyStarted { @@ -282,7 +282,7 @@ pub(super) fn validate_and_begin_pipeline_statistics_query( reset_state, )?; - tracker.add_single(&query_set); + tracker.insert_single(query_set.clone()); if let Some((_old, old_idx)) = active_query.take() { return Err(QueryUseError::AlreadyStarted { @@ -346,12 +346,12 @@ impl Global { let raw_encoder = encoder.open()?; - let query_set_guard = hub.query_sets.read(); - let query_set = query_set_guard + let query_set = hub + .query_sets .get(query_set_id) .map_err(|_| QueryError::InvalidQuerySetId(query_set_id))?; - tracker.query_sets.add_single(query_set); + let query_set = tracker.query_sets.insert_single(query_set); query_set.validate_and_write_timestamp(raw_encoder, query_index, None)?; @@ -393,12 +393,12 @@ impl Global { return Err(QueryError::Resolve(ResolveError::BufferOffsetAlignment)); } - let query_set_guard = hub.query_sets.read(); - let query_set = query_set_guard + let query_set = hub + .query_sets .get(query_set_id) .map_err(|_| QueryError::InvalidQuerySetId(query_set_id))?; - tracker.query_sets.add_single(query_set); + let query_set = tracker.query_sets.insert_single(query_set); query_set.same_device_as(cmd_buf.as_ref())?; diff --git a/wgpu-core/src/track/stateless.rs b/wgpu-core/src/track/stateless.rs index 2f4f297779..903dc21961 100644 --- a/wgpu-core/src/track/stateless.rs +++ b/wgpu-core/src/track/stateless.rs @@ -171,22 +171,6 @@ impl StatelessTracker { unsafe { self.metadata.insert(index, resource) } } - /// Adds the given resource to the tracker. - /// - /// If the ID is higher than the length of internal vectors, - /// the vectors will be extended. A call to set_size is not needed. - pub fn add_single(&mut self, resource: &Arc) { - let index = resource.tracker_index().as_usize(); - - self.allow_index(index); - - self.tracker_assert_in_bounds(index); - - unsafe { - self.metadata.insert(index, resource.clone()); - } - } - /// Adds the given resources from the given tracker. /// /// If the ID is higher than the length of internal vectors,