diff --git a/wgpu-core/src/binding_model.rs b/wgpu-core/src/binding_model.rs index 857628a72d..92b6254b7c 100644 --- a/wgpu-core/src/binding_model.rs +++ b/wgpu-core/src/binding_model.rs @@ -81,8 +81,6 @@ pub enum CreateBindGroupError { Device(#[from] DeviceError), #[error("Bind group layout is invalid")] InvalidLayout, - #[error("SamplerId {0:?} is invalid")] - InvalidSamplerId(SamplerId), #[error(transparent)] DestroyedResource(#[from] DestroyedResourceError), #[error( diff --git a/wgpu-core/src/device/global.rs b/wgpu-core/src/device/global.rs index f7dcc71a8d..5e49b24c3a 100644 --- a/wgpu-core/src/device/global.rs +++ b/wgpu-core/src/device/global.rs @@ -537,13 +537,13 @@ impl Global { Err(e) => break 'error e, }; - let id = fid.assign(sampler); + let id = fid.assign(Fallible::Valid(sampler)); api_log!("Device::create_sampler -> {id:?}"); return (id, None); }; - let id = fid.assign_error(); + let id = fid.assign(Fallible::Invalid(Arc::new(desc.label.to_string()))); (id, Some(error)) } @@ -553,9 +553,11 @@ impl Global { let hub = &self.hub; - if let Some(_sampler) = hub.samplers.unregister(sampler_id) { - #[cfg(feature = "trace")] - if let Some(t) = _sampler.device.trace.lock().as_mut() { + let _sampler = hub.samplers.strict_unregister(sampler_id); + + #[cfg(feature = "trace")] + if let Ok(sampler) = _sampler.get() { + if let Some(t) = sampler.device.trace.lock().as_mut() { t.add(trace::Action::DestroySampler(sampler_id)); } } @@ -733,7 +735,7 @@ impl Global { fn resolve_entry<'a>( e: &BindGroupEntry<'a>, buffer_storage: &Storage>, - sampler_storage: &Storage>, + sampler_storage: &Storage>, texture_view_storage: &Storage>, ) -> Result, binding_model::CreateBindGroupError> { @@ -750,8 +752,9 @@ impl Global { }; let resolve_sampler = |id: &id::SamplerId| { sampler_storage - .get_owned(*id) - .map_err(|_| binding_model::CreateBindGroupError::InvalidSamplerId(*id)) + .strict_get(*id) + .get() + .map_err(binding_model::CreateBindGroupError::from) }; let resolve_view = |id: &id::TextureViewId| { texture_view_storage diff --git a/wgpu-core/src/hub.rs b/wgpu-core/src/hub.rs index 2ca207438a..6fc3bb0882 100644 --- a/wgpu-core/src/hub.rs +++ b/wgpu-core/src/hub.rs @@ -179,7 +179,7 @@ pub struct Hub { pub(crate) staging_buffers: Registry>, pub(crate) textures: Registry>, pub(crate) texture_views: Registry>, - pub(crate) samplers: Registry>, + pub(crate) samplers: Registry>, } impl Hub {