diff --git a/wgpu-core/src/command/bundle.rs b/wgpu-core/src/command/bundle.rs index 6cf692025..b0fe21a9e 100644 --- a/wgpu-core/src/command/bundle.rs +++ b/wgpu-core/src/command/bundle.rs @@ -380,16 +380,6 @@ impl RenderBundleEncoder { .textures .write() .set_size(indices.textures.size()); - state - .trackers - .bind_groups - .write() - .set_size(indices.bind_groups.size()); - state - .trackers - .render_pipelines - .write() - .set_size(indices.render_pipelines.size()); let base = &self.base; diff --git a/wgpu-core/src/command/compute.rs b/wgpu-core/src/command/compute.rs index 1d751531a..643e5ffa6 100644 --- a/wgpu-core/src/command/compute.rs +++ b/wgpu-core/src/command/compute.rs @@ -484,15 +484,6 @@ impl Global { let indices = &state.device.tracker_indices; state.tracker.buffers.set_size(indices.buffers.size()); state.tracker.textures.set_size(indices.textures.size()); - state - .tracker - .bind_groups - .set_size(indices.bind_groups.size()); - state - .tracker - .compute_pipelines - .set_size(indices.compute_pipelines.size()); - state.tracker.query_sets.set_size(indices.query_sets.size()); let timestamp_writes = if let Some(tw) = timestamp_writes.take() { tw.query_set diff --git a/wgpu-core/src/command/render.rs b/wgpu-core/src/command/render.rs index 251daa7d1..5227d075e 100644 --- a/wgpu-core/src/command/render.rs +++ b/wgpu-core/src/command/render.rs @@ -1620,13 +1620,6 @@ impl Global { let indices = &device.tracker_indices; tracker.buffers.set_size(indices.buffers.size()); tracker.textures.set_size(indices.textures.size()); - tracker.views.set_size(indices.texture_views.size()); - tracker.bind_groups.set_size(indices.bind_groups.size()); - tracker - .render_pipelines - .set_size(indices.render_pipelines.size()); - tracker.bundles.set_size(indices.bundles.size()); - tracker.query_sets.set_size(indices.query_sets.size()); let raw = &mut encoder.raw; diff --git a/wgpu-core/src/device/resource.rs b/wgpu-core/src/device/resource.rs index 581c52009..0072dd931 100644 --- a/wgpu-core/src/device/resource.rs +++ b/wgpu-core/src/device/resource.rs @@ -2005,7 +2005,7 @@ impl Device { ) -> Result<&'a A::Sampler, binding_model::CreateBindGroupError> { use crate::binding_model::CreateBindGroupError as Error; - used.samplers.add_single(sampler); + used.samplers.insert_single(sampler.clone()); sampler.same_device(self)?; @@ -2054,7 +2054,7 @@ impl Device { used_texture_ranges: &mut Vec>, snatch_guard: &'a SnatchGuard<'a>, ) -> Result, binding_model::CreateBindGroupError> { - used.views.add_single(view); + used.views.insert_single(view.clone()); view.same_device(self)?; diff --git a/wgpu-core/src/track/mod.rs b/wgpu-core/src/track/mod.rs index cbeca973b..134d4c695 100644 --- a/wgpu-core/src/track/mod.rs +++ b/wgpu-core/src/track/mod.rs @@ -117,7 +117,7 @@ pub(crate) use buffer::{ BufferBindGroupState, BufferTracker, BufferUsageScope, DeviceBufferTracker, }; use metadata::{ResourceMetadata, ResourceMetadataProvider}; -pub(crate) use stateless::{StatelessBindGroupState, StatelessTracker}; +pub(crate) use stateless::StatelessTracker; pub(crate) use texture::{ DeviceTextureTracker, TextureBindGroupState, TextureSelector, TextureTracker, TextureTrackerSetSingle, TextureUsageScope, @@ -423,8 +423,8 @@ impl fmt::Display for InvalidUse { pub(crate) struct BindGroupStates { pub buffers: BufferBindGroupState, pub textures: TextureBindGroupState, - pub views: StatelessBindGroupState>, - pub samplers: StatelessBindGroupState>, + pub views: StatelessTracker>, + pub samplers: StatelessTracker>, } impl BindGroupStates { @@ -432,8 +432,8 @@ impl BindGroupStates { Self { buffers: BufferBindGroupState::new(), textures: TextureBindGroupState::new(), - views: StatelessBindGroupState::new(), - samplers: StatelessBindGroupState::new(), + views: StatelessTracker::new(), + samplers: StatelessTracker::new(), } } diff --git a/wgpu-core/src/track/stateless.rs b/wgpu-core/src/track/stateless.rs index 8dfe5333d..d1c2c87dd 100644 --- a/wgpu-core/src/track/stateless.rs +++ b/wgpu-core/src/track/stateless.rs @@ -1,79 +1,26 @@ -//! Stateless Trackers -//! -//! Stateless trackers don't have any state, so make no -//! distinction between a usage scope and a full tracker. - use std::sync::Arc; -use crate::{resource::Trackable, track::ResourceMetadata}; - -/// Stores all the resources that a bind group stores. +/// A tracker that holds strong references to resources. +/// +/// This is only used to keep resources alive. #[derive(Debug)] -pub(crate) struct StatelessBindGroupState { +pub(crate) struct StatelessTracker { resources: Vec>, } -impl StatelessBindGroupState { +impl StatelessTracker { pub fn new() -> Self { Self { resources: Vec::new(), } } - /// Adds the given resource. - pub fn add_single(&mut self, resource: &Arc) { - self.resources.push(resource.clone()); - } -} - -/// Stores all resource state within a command buffer or device. -#[derive(Debug)] -pub(crate) struct StatelessTracker { - metadata: ResourceMetadata>, -} - -impl StatelessTracker { - pub fn new() -> Self { - Self { - metadata: ResourceMetadata::new(), - } - } - - fn tracker_assert_in_bounds(&self, index: usize) { - self.metadata.tracker_assert_in_bounds(index); - } - - /// Sets the size of all the vectors inside the tracker. - /// - /// Must be called with the highest possible Resource ID of this type - /// before all unsafe functions are called. - pub fn set_size(&mut self, size: usize) { - self.metadata.set_size(size); - } - - /// Extend the vectors to let the given index be valid. - fn allow_index(&mut self, index: usize) { - if index >= self.metadata.size() { - self.set_size(index + 1); - } - } - /// Inserts a single resource into the resource tracker. /// - /// If the resource already exists in the tracker, it will be overwritten. - /// - /// If the ID is higher than the length of internal vectors, - /// the vectors will be extended. A call to set_size is not needed. - /// /// Returns a reference to the newly inserted resource. /// (This allows avoiding a clone/reference count increase in many cases.) pub fn insert_single(&mut self, resource: Arc) -> &Arc { - let index = resource.tracker_index().as_usize(); - - self.allow_index(index); - - self.tracker_assert_in_bounds(index); - - unsafe { self.metadata.insert(index, resource) } + self.resources.push(resource); + unsafe { self.resources.last().unwrap_unchecked() } } }