From 60fd2a32e9bbfda853c1017bfce0df96bf8cc94b Mon Sep 17 00:00:00 2001 From: Mikko Lehtonen Date: Thu, 6 Oct 2022 01:43:52 +0300 Subject: [PATCH] Implement missing PrettyError impls (#3066) --- CHANGELOG.md | 1 + wgpu-core/src/command/query.rs | 12 ++++++++++++ wgpu-core/src/device/mod.rs | 4 ++++ wgpu-core/src/error.rs | 15 +++++++++++++++ wgpu-core/src/track/mod.rs | 29 +++++++++++++++++++++++++---- 5 files changed, 57 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b1a4c260e..e4369a280f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -89,6 +89,7 @@ SurfaceConfiguration { enabled. By @imberflur in [#3023](https://github.com/gfx-rs/wgpu/pull/3023) - Fixed `CommandEncoder` not being `Send` and `Sync` on web by @i509VCB in [#3025](https://github.com/gfx-rs/wgpu/pull/3025) - Document meaning of `vendor` in `AdapterInfo` if the vendor has no PCI id. +- Fix missing resource labels from some Errors by @scoopr in [#3066](https://github.com/gfx-rs/wgpu/pull/3066) #### Metal - Add the missing `msg_send![view, retain]` call within `from_view` by @jinleili in [#2976](https://github.com/gfx-rs/wgpu/pull/2976) diff --git a/wgpu-core/src/command/query.rs b/wgpu-core/src/command/query.rs index 873a3031ac..0d6fc8a558 100644 --- a/wgpu-core/src/command/query.rs +++ b/wgpu-core/src/command/query.rs @@ -112,6 +112,18 @@ pub enum QueryError { InvalidQuerySet(id::QuerySetId), } +impl crate::error::PrettyError for QueryError { + fn fmt_pretty(&self, fmt: &mut crate::error::ErrorFormatter) { + fmt.error(self); + match *self { + Self::InvalidBuffer(id) => fmt.buffer_label(&id), + Self::InvalidQuerySet(id) => fmt.query_set_label(&id), + + _ => {} + } + } +} + /// Error encountered while trying to use queries #[derive(Clone, Debug, Error)] pub enum QueryUseError { diff --git a/wgpu-core/src/device/mod.rs b/wgpu-core/src/device/mod.rs index 072e14620a..a88d99cbca 100644 --- a/wgpu-core/src/device/mod.rs +++ b/wgpu-core/src/device/mod.rs @@ -4759,6 +4759,10 @@ impl Global { .push(id::Valid(query_set_id)); } + pub fn query_set_label(&self, id: id::QuerySetId) -> String { + A::hub(self).query_sets.label_for_resource(id) + } + pub fn device_create_render_pipeline( &self, device_id: id::DeviceId, diff --git a/wgpu-core/src/error.rs b/wgpu-core/src/error.rs index fa023a94ae..23a80064f7 100644 --- a/wgpu-core/src/error.rs +++ b/wgpu-core/src/error.rs @@ -91,6 +91,12 @@ impl<'a> ErrorFormatter<'a> { let label = gfx_select!(id => global.command_buffer_label(*id)); self.label("command buffer", &label); } + + pub fn query_set_label(&mut self, id: &crate::id::QuerySetId) { + let global = self.global; + let label = gfx_select!(id => global.query_set_label(*id)); + self.label("query set", &label); + } } pub trait PrettyError: Error + Sized { @@ -142,6 +148,15 @@ pub fn format_pretty_any( if let Some(pretty_err) = error.downcast_ref::() { return pretty_err.fmt_pretty(&mut fmt); } + if let Some(pretty_err) = error.downcast_ref::() { + return pretty_err.fmt_pretty(&mut fmt); + } + if let Some(pretty_err) = error.downcast_ref::() { + return pretty_err.fmt_pretty(&mut fmt); + } + if let Some(pretty_err) = error.downcast_ref::() { + return pretty_err.fmt_pretty(&mut fmt); + } // default fmt.error(error) diff --git a/wgpu-core/src/track/mod.rs b/wgpu-core/src/track/mod.rs index 7cf822e4cf..830244bee4 100644 --- a/wgpu-core/src/track/mod.rs +++ b/wgpu-core/src/track/mod.rs @@ -240,16 +240,16 @@ fn iterate_bitvec_indices(ownership: &BitVec) -> impl Iterator, }, - #[error("Attempted to use a texture {id:?} mips {mip_levels:?} layers {array_layers:?} with {invalid_use}.")] + #[error("Attempted to use a texture (mips {mip_levels:?} layers {array_layers:?}) with {invalid_use}.")] Texture { id: id::TextureId, mip_levels: ops::Range, @@ -257,6 +257,7 @@ pub enum UsageConflict { invalid_use: InvalidUse, }, } + impl UsageConflict { fn from_buffer( id: id::BufferId, @@ -290,6 +291,26 @@ impl UsageConflict { } } +impl crate::error::PrettyError for UsageConflict { + fn fmt_pretty(&self, fmt: &mut crate::error::ErrorFormatter) { + fmt.error(self); + match *self { + Self::BufferInvalid { id } => { + fmt.buffer_label(&id); + } + Self::TextureInvalid { id } => { + fmt.texture_label(&id); + } + Self::Buffer { id, .. } => { + fmt.buffer_label(&id); + } + Self::Texture { id, .. } => { + fmt.texture_label(&id); + } + } + } +} + /// Pretty print helper that shows helpful descriptions of a conflicting usage. #[derive(Clone, Debug, Eq, PartialEq)] pub struct InvalidUse {