From 6a181fa63422afbbc4d1e394374a0e95014149c5 Mon Sep 17 00:00:00 2001 From: teoxoy <28601907+teoxoy@users.noreply.github.com> Date: Thu, 20 Jun 2024 00:35:09 +0200 Subject: [PATCH] remove IDs from `StatelessBindGroupState` --- wgpu-core/src/device/resource.rs | 14 +++++--------- wgpu-core/src/track/stateless.rs | 27 ++++++--------------------- 2 files changed, 11 insertions(+), 30 deletions(-) diff --git a/wgpu-core/src/device/resource.rs b/wgpu-core/src/device/resource.rs index c00964a249..333316122c 100644 --- a/wgpu-core/src/device/resource.rs +++ b/wgpu-core/src/device/resource.rs @@ -2016,10 +2016,8 @@ impl Device { ) -> Result<&'a Sampler, binding_model::CreateBindGroupError> { use crate::binding_model::CreateBindGroupError as Error; - let sampler = used - .samplers - .add_single(storage, id) - .ok_or(Error::InvalidSampler(id))?; + let sampler = storage.get(id).map_err(|_| Error::InvalidSampler(id))?; + used.samplers.add_single(sampler); sampler.same_device(self)?; @@ -2038,10 +2036,8 @@ impl Device { ) -> Result, binding_model::CreateBindGroupError> { use crate::binding_model::CreateBindGroupError as Error; - let view = used - .views - .add_single(storage, id) - .ok_or(Error::InvalidTextureView(id))?; + let view = storage.get(id).map_err(|_| Error::InvalidTextureView(id))?; + used.views.add_single(view); view.same_device(self)?; @@ -2057,7 +2053,7 @@ impl Device { used.textures .add_single(texture, Some(view.selector.clone()), internal_use); - texture.same_device_as(view)?; + texture.same_device_as(view.as_ref())?; texture.check_usage(pub_usage)?; diff --git a/wgpu-core/src/track/stateless.rs b/wgpu-core/src/track/stateless.rs index b74d960e63..fd4bec9113 100644 --- a/wgpu-core/src/track/stateless.rs +++ b/wgpu-core/src/track/stateless.rs @@ -17,13 +17,10 @@ use crate::{ use super::{ResourceTracker, TrackerIndex}; -/// Satisfy clippy. -type Pair = (Id<::Marker>, Arc); - /// Stores all the resources that a bind group stores. #[derive(Debug)] pub(crate) struct StatelessBindGroupState { - resources: Mutex>>, + resources: Mutex>>, } impl StatelessBindGroupState { @@ -39,37 +36,25 @@ impl StatelessBindGroupState { /// accesses will be in a constant ascending order. pub(crate) fn optimize(&self) { let mut resources = self.resources.lock(); - resources.sort_unstable_by_key(|&(id, _)| id.unzip().0); + resources.sort_unstable_by_key(|resource| resource.as_info().tracker_index()); } /// Returns a list of all resources tracked. May contain duplicates. pub fn used_resources(&self) -> impl Iterator> + '_ { let resources = self.resources.lock(); - resources - .iter() - .map(|(_, resource)| resource.clone()) - .collect::>() - .into_iter() + resources.iter().cloned().collect::>().into_iter() } /// Returns a list of all resources tracked. May contain duplicates. pub fn drain_resources(&self) -> impl Iterator> + '_ { let mut resources = self.resources.lock(); - resources - .drain(..) - .map(|(_, r)| r) - .collect::>() - .into_iter() + resources.drain(..).collect::>().into_iter() } /// Adds the given resource. - pub fn add_single<'a>(&self, storage: &'a Storage, id: Id) -> Option<&'a T> { - let resource = storage.get(id).ok()?; - + pub fn add_single(&self, resource: &Arc) { let mut resources = self.resources.lock(); - resources.push((id, resource.clone())); - - Some(resource) + resources.push(resource.clone()); } }