diff --git a/wgpu-core/src/binding_model.rs b/wgpu-core/src/binding_model.rs index 0ec07092cb..857628a72d 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("TextureViewId {0:?} is invalid")] - InvalidTextureViewId(TextureViewId), #[error("SamplerId {0:?} is invalid")] InvalidSamplerId(SamplerId), #[error(transparent)] diff --git a/wgpu-core/src/command/mod.rs b/wgpu-core/src/command/mod.rs index 56cd57e7b7..296a8725a0 100644 --- a/wgpu-core/src/command/mod.rs +++ b/wgpu-core/src/command/mod.rs @@ -31,7 +31,7 @@ use crate::lock::{rank, Mutex}; use crate::snatch::SnatchGuard; use crate::init_tracker::BufferInitTrackerAction; -use crate::resource::Labeled; +use crate::resource::{InvalidResourceError, Labeled}; use crate::track::{DeviceTracker, Tracker, UsageScope}; use crate::LabelHelpers; use crate::{api_log, global::Global, id, resource_log, Label}; @@ -599,16 +599,12 @@ pub enum CommandEncoderError { #[error("QuerySet {0:?} for pass timestamp writes is invalid.")] InvalidTimestampWritesQuerySetId(id::QuerySetId), - #[error("Attachment TextureViewId {0:?} is invalid")] - InvalidAttachmentId(id::TextureViewId), #[error(transparent)] InvalidColorAttachment(#[from] ColorAttachmentError), - #[error("Resolve attachment TextureViewId {0:?} is invalid")] - InvalidResolveTargetId(id::TextureViewId), - #[error("Depth stencil attachment TextureViewId {0:?} is invalid")] - InvalidDepthStencilAttachmentId(id::TextureViewId), #[error("Occlusion QuerySetId {0:?} is invalid")] InvalidOcclusionQuerySetId(id::QuerySetId), + #[error(transparent)] + InvalidResource(#[from] InvalidResourceError), } impl Global { diff --git a/wgpu-core/src/command/render.rs b/wgpu-core/src/command/render.rs index 4065b73be8..d341cef12d 100644 --- a/wgpu-core/src/command/render.rs +++ b/wgpu-core/src/command/render.rs @@ -1363,14 +1363,10 @@ impl Global { channel, }) = color_attachment { - let view = texture_views - .get_owned(*view_id) - .map_err(|_| CommandEncoderError::InvalidAttachmentId(*view_id))?; + let view = texture_views.strict_get(*view_id).get()?; let resolve_target = if let Some(resolve_target_id) = resolve_target { - let rt_arc = texture_views.get_owned(*resolve_target_id).map_err(|_| { - CommandEncoderError::InvalidResolveTargetId(*resolve_target_id) - })?; + let rt_arc = texture_views.strict_get(*resolve_target_id).get()?; Some(rt_arc) } else { @@ -1392,12 +1388,8 @@ impl Global { arc_desc.depth_stencil_attachment = if let Some(depth_stencil_attachment) = desc.depth_stencil_attachment { let view = texture_views - .get_owned(depth_stencil_attachment.view) - .map_err(|_| { - CommandEncoderError::InvalidDepthStencilAttachmentId( - depth_stencil_attachment.view, - ) - })?; + .strict_get(depth_stencil_attachment.view) + .get()?; Some(ArcRenderPassDepthStencilAttachment { view, diff --git a/wgpu-core/src/device/global.rs b/wgpu-core/src/device/global.rs index f2f51a09ce..f7dcc71a8d 100644 --- a/wgpu-core/src/device/global.rs +++ b/wgpu-core/src/device/global.rs @@ -481,7 +481,7 @@ impl Global { Err(e) => break 'error e, }; - let id = fid.assign(view); + let id = fid.assign(Fallible::Valid(view)); api_log!("Texture::create_view({texture_id:?}) -> {id:?}"); @@ -489,7 +489,7 @@ impl Global { }; log::error!("Texture::create_view({texture_id:?}) error: {error}"); - let id = fid.assign_error(); + let id = fid.assign(Fallible::Invalid(Arc::new(desc.label.to_string()))); (id, Some(error)) } @@ -502,9 +502,11 @@ impl Global { let hub = &self.hub; - if let Some(_view) = hub.texture_views.unregister(texture_view_id) { - #[cfg(feature = "trace")] - if let Some(t) = _view.device.trace.lock().as_mut() { + let _view = hub.texture_views.strict_unregister(texture_view_id); + + #[cfg(feature = "trace")] + if let Ok(view) = _view.get() { + if let Some(t) = view.device.trace.lock().as_mut() { t.add(trace::Action::DestroyTextureView(texture_view_id)); } } @@ -732,7 +734,7 @@ impl Global { e: &BindGroupEntry<'a>, buffer_storage: &Storage>, sampler_storage: &Storage>, - texture_view_storage: &Storage>, + texture_view_storage: &Storage>, ) -> Result, binding_model::CreateBindGroupError> { let resolve_buffer = |bb: &BufferBinding| { @@ -753,8 +755,9 @@ impl Global { }; let resolve_view = |id: &id::TextureViewId| { texture_view_storage - .get_owned(*id) - .map_err(|_| binding_model::CreateBindGroupError::InvalidTextureViewId(*id)) + .strict_get(*id) + .get() + .map_err(binding_model::CreateBindGroupError::from) }; let resource = match e.resource { BindingResource::Buffer(ref buffer) => { diff --git a/wgpu-core/src/hub.rs b/wgpu-core/src/hub.rs index d7a56f3703..2ca207438a 100644 --- a/wgpu-core/src/hub.rs +++ b/wgpu-core/src/hub.rs @@ -178,7 +178,7 @@ pub struct Hub { pub(crate) buffers: Registry>, pub(crate) staging_buffers: Registry>, pub(crate) textures: Registry>, - pub(crate) texture_views: Registry>, + pub(crate) texture_views: Registry>, pub(crate) samplers: Registry>, } diff --git a/wgpu-core/src/resource.rs b/wgpu-core/src/resource.rs index 8d6ab7b4c9..799148b04c 100644 --- a/wgpu-core/src/resource.rs +++ b/wgpu-core/src/resource.rs @@ -1290,7 +1290,7 @@ impl Global { let hub = &self.hub; - if let Ok(texture_view) = hub.texture_views.get(id) { + if let Ok(texture_view) = hub.texture_views.strict_get(id).get() { let snatch_guard = texture_view.device.snatchable_lock.read(); let hal_texture_view = texture_view.raw(&snatch_guard); let hal_texture_view = hal_texture_view