From 82ce2ea7479b3994b60ef2e80e04cb613f382b67 Mon Sep 17 00:00:00 2001 From: teoxoy <28601907+teoxoy@users.noreply.github.com> Date: Fri, 6 Sep 2024 21:35:46 +0200 Subject: [PATCH] [wgpu-core] use `Fallible` for `ComputePipeline` --- tests/tests/pipeline.rs | 2 +- wgpu-core/src/binding_model.rs | 2 ++ wgpu-core/src/command/compute.rs | 6 ++---- wgpu-core/src/command/compute_command.rs | 12 ++++++------ wgpu-core/src/device/global.rs | 16 +++++++++------- wgpu-core/src/hub.rs | 2 +- 6 files changed, 21 insertions(+), 19 deletions(-) diff --git a/tests/tests/pipeline.rs b/tests/tests/pipeline.rs index 4c3888a21..f7d8d1ec7 100644 --- a/tests/tests/pipeline.rs +++ b/tests/tests/pipeline.rs @@ -8,7 +8,7 @@ static PIPELINE_DEFAULT_LAYOUT_BAD_MODULE: GpuTestConfiguration = GpuTestConfigu .parameters( TestParameters::default() // https://github.com/gfx-rs/wgpu/issues/4167 - .expect_fail(FailureCase::always().panic("Pipeline is invalid")), + .expect_fail(FailureCase::always().panic("Error reflecting bind group")), ) .run_sync(|ctx| { ctx.device.push_error_scope(wgpu::ErrorFilter::Validation); diff --git a/wgpu-core/src/binding_model.rs b/wgpu-core/src/binding_model.rs index 92b6254b7..bcf6f0e24 100644 --- a/wgpu-core/src/binding_model.rs +++ b/wgpu-core/src/binding_model.rs @@ -1003,6 +1003,8 @@ pub enum GetBindGroupLayoutError { InvalidPipeline, #[error("Invalid group index {0}")] InvalidGroupIndex(u32), + #[error(transparent)] + InvalidResource(#[from] InvalidResourceError), } #[derive(Clone, Debug, Error, Eq, PartialEq)] diff --git a/wgpu-core/src/command/compute.rs b/wgpu-core/src/command/compute.rs index 51eadc587..e9e9cf18e 100644 --- a/wgpu-core/src/command/compute.rs +++ b/wgpu-core/src/command/compute.rs @@ -134,8 +134,6 @@ pub enum ComputePassErrorInner { InvalidParentEncoder, #[error("Bind group index {index} is greater than the device's requested `max_bind_group` limit {max}")] BindGroupIndexOutOfRange { index: u32, max: u32 }, - #[error("ComputePipelineId {0:?} is invalid")] - InvalidPipelineId(id::ComputePipelineId), #[error(transparent)] DestroyedResource(#[from] DestroyedResourceError), #[error("Indirect buffer uses bytes {offset}..{end_offset} which overruns indirect buffer of size {buffer_size}")] @@ -1016,8 +1014,8 @@ impl Global { let hub = &self.hub; let pipeline = hub .compute_pipelines - .get(pipeline_id) - .map_err(|_| ComputePassErrorInner::InvalidPipelineId(pipeline_id)) + .strict_get(pipeline_id) + .get() .map_pass_err(scope)?; base.commands.push(ArcComputeCommand::SetPipeline(pipeline)); diff --git a/wgpu-core/src/command/compute_command.rs b/wgpu-core/src/command/compute_command.rs index 30d1bb74e..582702f0e 100644 --- a/wgpu-core/src/command/compute_command.rs +++ b/wgpu-core/src/command/compute_command.rs @@ -74,7 +74,7 @@ impl ComputeCommand { hub: &crate::hub::Hub, commands: &[ComputeCommand], ) -> Result, super::ComputePassError> { - use super::{ComputePassError, ComputePassErrorInner, PassErrorScope}; + use super::{ComputePassError, PassErrorScope}; let buffers_guard = hub.buffers.read(); let bind_group_guard = hub.bind_groups.read(); @@ -114,12 +114,12 @@ impl ComputeCommand { } } ComputeCommand::SetPipeline(pipeline_id) => ArcComputeCommand::SetPipeline( - pipelines_guard - .get_owned(pipeline_id) - .map_err(|_| ComputePassError { + pipelines_guard.strict_get(pipeline_id).get().map_err(|e| { + ComputePassError { scope: PassErrorScope::SetPipelineCompute, - inner: ComputePassErrorInner::InvalidPipelineId(pipeline_id), - })?, + inner: e.into(), + } + })?, ), ComputeCommand::SetPushConstant { diff --git a/wgpu-core/src/device/global.rs b/wgpu-core/src/device/global.rs index 878e98908..0a0381a92 100644 --- a/wgpu-core/src/device/global.rs +++ b/wgpu-core/src/device/global.rs @@ -1547,13 +1547,13 @@ impl Global { } } - let id = fid.assign(pipeline); + let id = fid.assign(Fallible::Valid(pipeline)); api_log!("Device::create_compute_pipeline -> {id:?}"); return (id, None); }; - let id = fid.assign_error(); + let id = fid.assign(Fallible::Invalid(Arc::new(desc.label.to_string()))); // We also need to assign errors to the implicit pipeline layout and the // implicit bind group layouts. @@ -1583,9 +1583,9 @@ impl Global { let hub = &self.hub; let error = 'error: { - let pipeline = match hub.compute_pipelines.get(pipeline_id) { + let pipeline = match hub.compute_pipelines.strict_get(pipeline_id).get() { Ok(pipeline) => pipeline, - Err(_) => break 'error binding_model::GetBindGroupLayoutError::InvalidPipeline, + Err(e) => break 'error e.into(), }; let id = match pipeline.layout.bind_group_layouts.get(index as usize) { @@ -1614,9 +1614,11 @@ impl Global { let hub = &self.hub; - if let Some(_pipeline) = hub.compute_pipelines.unregister(compute_pipeline_id) { - #[cfg(feature = "trace")] - if let Some(t) = _pipeline.device.trace.lock().as_mut() { + let _pipeline = hub.compute_pipelines.strict_unregister(compute_pipeline_id); + + #[cfg(feature = "trace")] + if let Ok(pipeline) = _pipeline.get() { + if let Some(t) = pipeline.device.trace.lock().as_mut() { t.add(trace::Action::DestroyComputePipeline(compute_pipeline_id)); } } diff --git a/wgpu-core/src/hub.rs b/wgpu-core/src/hub.rs index 1dfe285d5..0c731a05c 100644 --- a/wgpu-core/src/hub.rs +++ b/wgpu-core/src/hub.rs @@ -172,7 +172,7 @@ pub struct Hub { pub(crate) command_buffers: Registry>, pub(crate) render_bundles: Registry>, pub(crate) render_pipelines: Registry>, - pub(crate) compute_pipelines: Registry>, + pub(crate) compute_pipelines: Registry>, pub(crate) pipeline_caches: Registry>, pub(crate) query_sets: Registry>, pub(crate) buffers: Registry>,