From a4bb5dff2b6ae9a70bd6dd538c44d288dad88e0d Mon Sep 17 00:00:00 2001 From: teoxoy <28601907+teoxoy@users.noreply.github.com> Date: Thu, 27 Jun 2024 18:04:53 +0200 Subject: [PATCH] rename error variants that contain IDs --- wgpu-core/src/binding_model.rs | 25 ++++++---------------- wgpu-core/src/command/bundle.rs | 8 ++----- wgpu-core/src/command/compute.rs | 20 ++++++------------ wgpu-core/src/command/compute_command.rs | 2 +- wgpu-core/src/command/draw.rs | 20 +++--------------- wgpu-core/src/command/mod.rs | 27 ++++++++---------------- wgpu-core/src/command/query.rs | 17 +++++---------- wgpu-core/src/command/render.rs | 13 +++--------- wgpu-core/src/command/render_command.rs | 2 +- wgpu-core/src/device/resource.rs | 4 ++-- wgpu-core/src/track/mod.rs | 6 +----- 11 files changed, 40 insertions(+), 104 deletions(-) diff --git a/wgpu-core/src/binding_model.rs b/wgpu-core/src/binding_model.rs index 1958068ed..9c19d7248 100644 --- a/wgpu-core/src/binding_model.rs +++ b/wgpu-core/src/binding_model.rs @@ -78,10 +78,10 @@ pub enum CreateBindGroupError { InvalidLayout, #[error("BufferId {0:?} is invalid")] InvalidBufferId(BufferId), - #[error("Texture view Id {0:?} is invalid")] + #[error("TextureViewId {0:?} is invalid")] InvalidTextureViewId(TextureViewId), - #[error("Sampler {0:?} is invalid")] - InvalidSampler(SamplerId), + #[error("SamplerId {0:?} is invalid")] + InvalidSamplerId(SamplerId), #[error(transparent)] DestroyedResource(#[from] DestroyedResourceError), #[error( @@ -198,12 +198,6 @@ impl PrettyError for CreateBindGroupError { Self::BindingSizeTooSmall { buffer, .. } => { fmt.buffer_label(&buffer); } - Self::InvalidTextureViewId(id) => { - fmt.texture_view_label(&id); - } - Self::InvalidSampler(id) => { - fmt.sampler_label(&id); - } _ => {} }; } @@ -511,8 +505,8 @@ impl BindGroupLayout { pub enum CreatePipelineLayoutError { #[error(transparent)] Device(#[from] DeviceError), - #[error("Bind group layout {0:?} is invalid")] - InvalidBindGroupLayout(BindGroupLayoutId), + #[error("BindGroupLayoutId {0:?} is invalid")] + InvalidBindGroupLayoutId(BindGroupLayoutId), #[error( "Push constant at index {index} has range bound {bound} not aligned to {}", wgt::PUSH_CONSTANT_ALIGNMENT @@ -538,14 +532,7 @@ pub enum CreatePipelineLayoutError { TooManyGroups { actual: usize, max: usize }, } -impl PrettyError for CreatePipelineLayoutError { - fn fmt_pretty(&self, fmt: &mut ErrorFormatter) { - fmt.error(self); - if let Self::InvalidBindGroupLayout(id) = *self { - fmt.bind_group_layout_label(&id); - }; - } -} +impl PrettyError for CreatePipelineLayoutError {} #[derive(Clone, Debug, Error)] #[non_exhaustive] diff --git a/wgpu-core/src/command/bundle.rs b/wgpu-core/src/command/bundle.rs index d2bd39333..cf4fbcda7 100644 --- a/wgpu-core/src/command/bundle.rs +++ b/wgpu-core/src/command/bundle.rs @@ -661,7 +661,7 @@ fn set_pipeline( ) -> Result<(), RenderBundleErrorInner> { let pipeline = pipeline_guard .get(pipeline_id) - .map_err(|_| RenderCommandError::InvalidPipeline(pipeline_id))?; + .map_err(|_| RenderCommandError::InvalidPipelineId(pipeline_id))?; state.trackers.render_pipelines.write().add_single(pipeline); @@ -948,11 +948,7 @@ pub enum ExecutionError { #[error("Using {0} in a render bundle is not implemented")] Unimplemented(&'static str), } -impl PrettyError for ExecutionError { - fn fmt_pretty(&self, fmt: &mut ErrorFormatter) { - fmt.error(self); - } -} +impl PrettyError for ExecutionError {} pub type RenderBundleDescriptor<'a> = wgt::RenderBundleDescriptor>; diff --git a/wgpu-core/src/command/compute.rs b/wgpu-core/src/command/compute.rs index 7b8c853b4..04d5f10df 100644 --- a/wgpu-core/src/command/compute.rs +++ b/wgpu-core/src/command/compute.rs @@ -144,8 +144,8 @@ pub enum ComputePassErrorInner { InvalidBindGroupId(id::BindGroupId), #[error("Bind group index {index} is greater than the device's requested `max_bind_group` limit {max}")] BindGroupIndexOutOfRange { index: u32, max: u32 }, - #[error("Compute pipeline {0:?} is invalid")] - InvalidPipeline(id::ComputePipelineId), + #[error("ComputePipelineId {0:?} is invalid")] + InvalidPipelineId(id::ComputePipelineId), #[error("QuerySet {0:?} is invalid")] InvalidQuerySet(id::QuerySetId), #[error(transparent)] @@ -189,17 +189,11 @@ pub enum ComputePassErrorInner { impl PrettyError for ComputePassErrorInner { fn fmt_pretty(&self, fmt: &mut ErrorFormatter) { fmt.error(self); - match *self { - Self::InvalidPipeline(id) => { - fmt.compute_pipeline_label(&id); + if let Self::Dispatch(DispatchError::IncompatibleBindGroup { ref diff, .. }) = *self { + for d in diff { + fmt.note(&d); } - Self::Dispatch(DispatchError::IncompatibleBindGroup { ref diff, .. }) => { - for d in diff { - fmt.note(&d); - } - } - _ => {} - }; + } } } @@ -1073,7 +1067,7 @@ impl Global { .compute_pipelines .read() .get_owned(pipeline_id) - .map_err(|_| ComputePassErrorInner::InvalidPipeline(pipeline_id)) + .map_err(|_| ComputePassErrorInner::InvalidPipelineId(pipeline_id)) .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 4faab90da..2e762de14 100644 --- a/wgpu-core/src/command/compute_command.rs +++ b/wgpu-core/src/command/compute_command.rs @@ -106,7 +106,7 @@ impl ComputeCommand { .get_owned(pipeline_id) .map_err(|_| ComputePassError { scope: PassErrorScope::SetPipelineCompute, - inner: ComputePassErrorInner::InvalidPipeline(pipeline_id), + inner: ComputePassErrorInner::InvalidPipelineId(pipeline_id), })?, ), diff --git a/wgpu-core/src/command/draw.rs b/wgpu-core/src/command/draw.rs index d43039a89..6df9371b1 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}, - error::ErrorFormatter, id, resource::{ DestroyedResourceError, MissingBufferUsageError, MissingTextureUsageError, @@ -83,8 +82,8 @@ pub enum RenderCommandError { VertexBufferIndexOutOfRange { index: u32, max: u32 }, #[error("Dynamic buffer offset {0} does not respect device's requested `{1}` limit {2}")] UnalignedBufferOffset(u64, &'static str, u32), - #[error("Render pipeline {0:?} is invalid")] - InvalidPipeline(id::RenderPipelineId), + #[error("RenderPipelineId {0:?} is invalid")] + InvalidPipelineId(id::RenderPipelineId), #[error("QuerySet {0:?} is invalid")] InvalidQuerySet(id::QuerySetId), #[error("Render pipeline targets are incompatible with render pass")] @@ -112,20 +111,7 @@ pub enum RenderCommandError { #[error("Support for {0} is not implemented yet")] Unimplemented(&'static str), } -impl crate::error::PrettyError for RenderCommandError { - fn fmt_pretty(&self, fmt: &mut ErrorFormatter) { - fmt.error(self); - match *self { - Self::InvalidBindGroupId(id) => { - fmt.bind_group_label(&id); - } - Self::InvalidPipeline(id) => { - fmt.render_pipeline_label(&id); - } - _ => {} - }; - } -} +impl crate::error::PrettyError for RenderCommandError {} #[derive(Clone, Copy, Debug, Default)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] diff --git a/wgpu-core/src/command/mod.rs b/wgpu-core/src/command/mod.rs index a90ea789b..7ecd0e5ba 100644 --- a/wgpu-core/src/command/mod.rs +++ b/wgpu-core/src/command/mod.rs @@ -30,7 +30,7 @@ pub use timestamp_writes::PassTimestampWrites; use self::memory_init::CommandBufferTextureMemoryActions; use crate::device::{Device, DeviceError}; -use crate::error::{ErrorFormatter, PrettyError}; +use crate::error::PrettyError; use crate::hub::Hub; use crate::lock::{rank, Mutex}; use crate::snatch::SnatchGuard; @@ -598,26 +598,17 @@ pub enum CommandEncoderError { #[error("QuerySet {0:?} for pass timestamp writes is invalid.")] InvalidTimestampWritesQuerySetId(id::QuerySetId), - #[error("Attachment texture view {0:?} is invalid")] - InvalidAttachment(id::TextureViewId), - #[error("Attachment texture view {0:?} for resolve is invalid")] - InvalidResolveTarget(id::TextureViewId), - #[error("Depth stencil attachment view {0:?} is invalid")] - InvalidDepthStencilAttachment(id::TextureViewId), - #[error("Occlusion query set {0:?} is invalid")] + #[error("Attachment TextureViewId {0:?} is invalid")] + InvalidAttachmentId(id::TextureViewId), + #[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), } -impl PrettyError for CommandEncoderError { - fn fmt_pretty(&self, fmt: &mut ErrorFormatter) { - fmt.error(self); - if let Self::InvalidAttachment(id) = *self { - fmt.texture_view_label_with_key(&id, "attachment"); - } else if let Self::InvalidResolveTarget(id) = *self { - fmt.texture_view_label_with_key(&id, "resolve target"); - }; - } -} +impl PrettyError for CommandEncoderError {} impl Global { pub fn command_encoder_finish( diff --git a/wgpu-core/src/command/query.rs b/wgpu-core/src/command/query.rs index cd60cf9cb..09a062d85 100644 --- a/wgpu-core/src/command/query.rs +++ b/wgpu-core/src/command/query.rs @@ -107,18 +107,11 @@ pub enum QueryError { InvalidBufferId(id::BufferId), #[error(transparent)] DestroyedResource(#[from] DestroyedResourceError), - #[error("QuerySet {0:?} is invalid or destroyed")] - InvalidQuerySet(id::QuerySetId), + #[error("QuerySetId {0:?} is invalid or destroyed")] + InvalidQuerySetId(id::QuerySetId), } -impl crate::error::PrettyError for QueryError { - fn fmt_pretty(&self, fmt: &mut crate::error::ErrorFormatter) { - fmt.error(self); - if let Self::InvalidQuerySet(id) = *self { - fmt.query_set_label(&id) - } - } -} +impl crate::error::PrettyError for QueryError {} /// Error encountered while trying to use queries #[derive(Clone, Debug, Error)] @@ -356,7 +349,7 @@ impl Global { let query_set_guard = hub.query_sets.read(); let query_set = query_set_guard .get(query_set_id) - .map_err(|_| QueryError::InvalidQuerySet(query_set_id))?; + .map_err(|_| QueryError::InvalidQuerySetId(query_set_id))?; tracker.query_sets.add_single(query_set); @@ -403,7 +396,7 @@ impl Global { let query_set_guard = hub.query_sets.read(); let query_set = query_set_guard .get(query_set_id) - .map_err(|_| QueryError::InvalidQuerySet(query_set_id))?; + .map_err(|_| QueryError::InvalidQuerySetId(query_set_id))?; tracker.query_sets.add_single(query_set); diff --git a/wgpu-core/src/command/render.rs b/wgpu-core/src/command/render.rs index 91b6ba22d..f27972e48 100644 --- a/wgpu-core/src/command/render.rs +++ b/wgpu-core/src/command/render.rs @@ -590,10 +590,6 @@ pub enum RenderPassErrorInner { Encoder(#[from] CommandEncoderError), #[error("Parent encoder is invalid")] InvalidParentEncoder, - #[error("Attachment texture view {0:?} is invalid")] - InvalidAttachmentId(id::TextureViewId), - #[error("Attachment texture view {0:?} is invalid")] - InvalidResolveTargetId(id::TextureViewId), #[error("The format of the depth-stencil attachment ({0:?}) is not a depth-stencil format")] InvalidDepthStencilAttachmentFormat(wgt::TextureFormat), #[error("Buffer {0:?} is invalid or destroyed")] @@ -724,9 +720,6 @@ pub enum RenderPassErrorInner { impl PrettyError for RenderPassErrorInner { fn fmt_pretty(&self, fmt: &mut ErrorFormatter) { fmt.error(self); - if let Self::InvalidAttachmentId(id) = *self { - fmt.texture_view_label_with_key(&id, "attachment"); - }; if let Self::Draw(DrawError::IncompatibleBindGroup { diff, .. }) = self { for d in diff { fmt.note(&d); @@ -1381,12 +1374,12 @@ impl Global { { let view = texture_views .get_owned(*view_id) - .map_err(|_| CommandEncoderError::InvalidAttachment(*view_id))?; + .map_err(|_| CommandEncoderError::InvalidAttachmentId(*view_id))?; view.same_device(device)?; let resolve_target = if let Some(resolve_target_id) = resolve_target { let rt_arc = texture_views.get_owned(*resolve_target_id).map_err(|_| { - CommandEncoderError::InvalidResolveTarget(*resolve_target_id) + CommandEncoderError::InvalidResolveTargetId(*resolve_target_id) })?; rt_arc.same_device(device)?; @@ -1412,7 +1405,7 @@ impl Global { let view = texture_views .get_owned(depth_stencil_attachment.view) .map_err(|_| { - CommandEncoderError::InvalidDepthStencilAttachment( + CommandEncoderError::InvalidDepthStencilAttachmentId( depth_stencil_attachment.view, ) })?; diff --git a/wgpu-core/src/command/render_command.rs b/wgpu-core/src/command/render_command.rs index c86bfd12b..66b3a68ee 100644 --- a/wgpu-core/src/command/render_command.rs +++ b/wgpu-core/src/command/render_command.rs @@ -163,7 +163,7 @@ impl RenderCommand { .get_owned(pipeline_id) .map_err(|_| RenderPassError { scope: PassErrorScope::SetPipelineRender, - inner: RenderCommandError::InvalidPipeline(pipeline_id).into(), + inner: RenderCommandError::InvalidPipelineId(pipeline_id).into(), })?, ), diff --git a/wgpu-core/src/device/resource.rs b/wgpu-core/src/device/resource.rs index 36d885260..5e2c560df 100644 --- a/wgpu-core/src/device/resource.rs +++ b/wgpu-core/src/device/resource.rs @@ -1994,7 +1994,7 @@ impl Device { ) -> Result<&'a Sampler, binding_model::CreateBindGroupError> { use crate::binding_model::CreateBindGroupError as Error; - let sampler = storage.get(id).map_err(|_| Error::InvalidSampler(id))?; + let sampler = storage.get(id).map_err(|_| Error::InvalidSamplerId(id))?; used.samplers.add_single(sampler); sampler.same_device(self)?; @@ -2512,7 +2512,7 @@ impl Device { let mut bind_group_layouts = ArrayVec::new(); for &id in desc.bind_group_layouts.iter() { let Ok(bgl) = bgl_registry.get(id) else { - return Err(Error::InvalidBindGroupLayout(id)); + return Err(Error::InvalidBindGroupLayoutId(id)); }; bind_group_layouts.push(bgl); diff --git a/wgpu-core/src/track/mod.rs b/wgpu-core/src/track/mod.rs index d741abce7..208b277ec 100644 --- a/wgpu-core/src/track/mod.rs +++ b/wgpu-core/src/track/mod.rs @@ -385,11 +385,7 @@ impl ResourceUsageCompatibilityError { } } -impl crate::error::PrettyError for ResourceUsageCompatibilityError { - fn fmt_pretty(&self, fmt: &mut crate::error::ErrorFormatter) { - fmt.error(self); - } -} +impl crate::error::PrettyError for ResourceUsageCompatibilityError {} /// Pretty print helper that shows helpful descriptions of a conflicting usage. #[derive(Clone, Debug, Eq, PartialEq)]