Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement missing PrettyError impls #3066

Merged
merged 2 commits into from Oct 5, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions wgpu-core/src/command/query.rs
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions wgpu-core/src/device/mod.rs
Expand Up @@ -4759,6 +4759,10 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
.push(id::Valid(query_set_id));
}

pub fn query_set_label<A: HalApi>(&self, id: id::QuerySetId) -> String {
A::hub(self).query_sets.label_for_resource(id)
}

pub fn device_create_render_pipeline<A: HalApi>(
&self,
device_id: id::DeviceId,
Expand Down
15 changes: 15 additions & 0 deletions wgpu-core/src/error.rs
Expand Up @@ -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 {
Expand Down Expand Up @@ -142,6 +148,15 @@ pub fn format_pretty_any(
if let Some(pretty_err) = error.downcast_ref::<crate::command::TransferError>() {
return pretty_err.fmt_pretty(&mut fmt);
}
if let Some(pretty_err) = error.downcast_ref::<crate::command::PassErrorScope>() {
return pretty_err.fmt_pretty(&mut fmt);
}
if let Some(pretty_err) = error.downcast_ref::<crate::track::UsageConflict>() {
return pretty_err.fmt_pretty(&mut fmt);
}
if let Some(pretty_err) = error.downcast_ref::<crate::command::QueryError>() {
return pretty_err.fmt_pretty(&mut fmt);
}

// default
fmt.error(error)
Expand Down
29 changes: 25 additions & 4 deletions wgpu-core/src/track/mod.rs
Expand Up @@ -240,23 +240,24 @@ fn iterate_bitvec_indices(ownership: &BitVec<usize>) -> impl Iterator<Item = usi

#[derive(Clone, Debug, Error, Eq, PartialEq)]
pub enum UsageConflict {
#[error("Attempted to use buffer {id:?} which is invalid.")]
#[error("Attempted to use invalid buffer")]
BufferInvalid { id: id::BufferId },
#[error("Attempted to use texture {id:?} which is invalid.")]
#[error("Attempted to use invalid texture")]
TextureInvalid { id: id::TextureId },
#[error("Attempted to use buffer {id:?} with {invalid_use}.")]
#[error("Attempted to use buffer with {invalid_use}.")]
Buffer {
id: id::BufferId,
invalid_use: InvalidUse<hal::BufferUses>,
},
#[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<u32>,
array_layers: ops::Range<u32>,
invalid_use: InvalidUse<hal::TextureUses>,
},
}

impl UsageConflict {
fn from_buffer(
id: id::BufferId,
Expand Down Expand Up @@ -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<T> {
Expand Down