From c0c594eff21a4f7f074c5d03ff8b6178af3858a8 Mon Sep 17 00:00:00 2001 From: teoxoy <28601907+teoxoy@users.noreply.github.com> Date: Fri, 6 Sep 2024 22:11:03 +0200 Subject: [PATCH] [wgpu-core] use `Fallible` for `RenderBundle` --- wgpu-core/src/command/draw.rs | 3 --- wgpu-core/src/command/render.rs | 7 +------ wgpu-core/src/command/render_command.rs | 12 ++++++------ wgpu-core/src/device/global.rs | 19 ++++++++++--------- wgpu-core/src/hub.rs | 2 +- 5 files changed, 18 insertions(+), 25 deletions(-) diff --git a/wgpu-core/src/command/draw.rs b/wgpu-core/src/command/draw.rs index 779bbb7c9..dd54b60f2 100644 --- a/wgpu-core/src/command/draw.rs +++ b/wgpu-core/src/command/draw.rs @@ -1,6 +1,5 @@ use crate::{ binding_model::{LateMinBufferBindingSizeMismatch, PushConstantUploadError}, - id, resource::{ DestroyedResourceError, MissingBufferUsageError, MissingTextureUsageError, ResourceErrorIdent, @@ -68,8 +67,6 @@ pub enum DrawError { #[derive(Clone, Debug, Error)] #[non_exhaustive] pub enum RenderCommandError { - #[error("Render bundle {0:?} is invalid")] - InvalidRenderBundle(id::RenderBundleId), #[error("Bind group index {index} is greater than the device's requested `max_bind_group` limit {max}")] BindGroupIndexOutOfRange { index: u32, max: u32 }, #[error("Vertex buffer index {index} is greater than the device's requested `max_vertex_buffers` limit {max}")] diff --git a/wgpu-core/src/command/render.rs b/wgpu-core/src/command/render.rs index ec9867e16..832e10525 100644 --- a/wgpu-core/src/command/render.rs +++ b/wgpu-core/src/command/render.rs @@ -583,8 +583,6 @@ pub enum RenderPassErrorInner { InvalidParentEncoder, #[error("The format of the depth-stencil attachment ({0:?}) is not a depth-stencil format")] InvalidDepthStencilAttachmentFormat(wgt::TextureFormat), - #[error("Render bundle {0:?} is invalid")] - InvalidRenderBundle(id::RenderBundleId), #[error("The format of the {location} ({format:?}) is not resolvable")] UnsupportedResolveTargetFormat { location: AttachmentErrorLocation, @@ -3333,10 +3331,7 @@ impl Global { let bundles = hub.render_bundles.read(); for &bundle_id in render_bundle_ids { - let bundle = bundles - .get_owned(bundle_id) - .map_err(|_| RenderPassErrorInner::InvalidRenderBundle(bundle_id)) - .map_pass_err(scope)?; + let bundle = bundles.strict_get(bundle_id).get().map_pass_err(scope)?; base.commands.push(ArcRenderCommand::ExecuteBundle(bundle)); } diff --git a/wgpu-core/src/command/render_command.rs b/wgpu-core/src/command/render_command.rs index 0754e30a7..13e0209d0 100644 --- a/wgpu-core/src/command/render_command.rs +++ b/wgpu-core/src/command/render_command.rs @@ -129,7 +129,7 @@ impl RenderCommand { hub: &crate::hub::Hub, commands: &[RenderCommand], ) -> Result, super::RenderPassError> { - use super::{DrawKind, PassErrorScope, RenderCommandError, RenderPassError}; + use super::{DrawKind, PassErrorScope, RenderPassError}; let buffers_guard = hub.buffers.read(); let bind_group_guard = hub.bind_groups.read(); @@ -376,12 +376,12 @@ impl RenderCommand { RenderCommand::EndOcclusionQuery => ArcRenderCommand::EndOcclusionQuery, RenderCommand::ExecuteBundle(bundle) => ArcRenderCommand::ExecuteBundle( - render_bundles_guard - .get_owned(bundle) - .map_err(|_| RenderPassError { + render_bundles_guard.strict_get(bundle).get().map_err(|e| { + RenderPassError { scope: PassErrorScope::ExecuteBundle, - inner: RenderCommandError::InvalidRenderBundle(bundle).into(), - })?, + inner: e.into(), + } + })?, ), }) }) diff --git a/wgpu-core/src/device/global.rs b/wgpu-core/src/device/global.rs index 9edcf0866..965ec3b22 100644 --- a/wgpu-core/src/device/global.rs +++ b/wgpu-core/src/device/global.rs @@ -186,11 +186,10 @@ impl Global { &self, backend: wgt::Backend, id_in: Option, + desc: &command::RenderBundleDescriptor, ) { - let hub = &self.hub; - let fid = hub.render_bundles.prepare(backend, id_in); - - fid.assign_error(); + let fid = self.hub.render_bundles.prepare(backend, id_in); + fid.assign(Fallible::Invalid(Arc::new(desc.label.to_string()))); } /// Assign `id_in` an error with the given `label`. @@ -1103,13 +1102,13 @@ impl Global { Err(e) => break 'error e, }; - let id = fid.assign(render_bundle); + let id = fid.assign(Fallible::Valid(render_bundle)); api_log!("RenderBundleEncoder::finish -> {id:?}"); return (id, None); }; - let id = fid.assign_error(); + let id = fid.assign(Fallible::Invalid(Arc::new(desc.label.to_string()))); (id, Some(error)) } @@ -1119,9 +1118,11 @@ impl Global { let hub = &self.hub; - if let Some(_bundle) = hub.render_bundles.unregister(render_bundle_id) { - #[cfg(feature = "trace")] - if let Some(t) = _bundle.device.trace.lock().as_mut() { + let _bundle = hub.render_bundles.strict_unregister(render_bundle_id); + + #[cfg(feature = "trace")] + if let Ok(bundle) = _bundle.get() { + if let Some(t) = bundle.device.trace.lock().as_mut() { t.add(trace::Action::DestroyRenderBundle(render_bundle_id)); } } diff --git a/wgpu-core/src/hub.rs b/wgpu-core/src/hub.rs index d0f71f382..f4e8b9c75 100644 --- a/wgpu-core/src/hub.rs +++ b/wgpu-core/src/hub.rs @@ -170,7 +170,7 @@ pub struct Hub { pub(crate) bind_group_layouts: Registry>, pub(crate) bind_groups: Registry>, pub(crate) command_buffers: Registry>, - pub(crate) render_bundles: Registry>, + pub(crate) render_bundles: Registry>, pub(crate) render_pipelines: Registry>, pub(crate) compute_pipelines: Registry>, pub(crate) pipeline_caches: Registry>,