From bcf8ef007f705e0f4f4bf95f815937a3c51558d6 Mon Sep 17 00:00:00 2001 From: Mikko Lehtonen Date: Sat, 21 Nov 2020 23:41:36 +0200 Subject: [PATCH 1/2] Add label for render pass context error Also made the label key settable --- src/backend/direct.rs | 24 +++++++++++++++++++++--- src/backend/error.rs | 2 +- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/backend/direct.rs b/src/backend/direct.rs index a8c92c63e..5f3adb1bb 100644 --- a/src/backend/direct.rs +++ b/src/backend/direct.rs @@ -1419,7 +1419,10 @@ impl crate::Context for Context { ) { let global = &self.0; wgc::gfx_select!(encoder.id => global.command_encoder_run_render_pass(encoder.id, pass)) - .map_err(|err| err.with_context("In a RenderPass", None)) + .map_err(|err| { + let name = wgc::gfx_select!(encoder.id => global.command_buffer_label(encoder.id)); + err.with_context_label_key("In a render pass", "encoder", Some(&name)) + }) .unwrap_error_sink(&encoder.error_sink, &self, || ()) } @@ -1578,15 +1581,29 @@ where } trait WithContextError: Error + Send + Sync + 'static + Sized { - fn with_context(self, string: &str, label: Option<&str>) -> ContextError; + fn with_context_label_key( + self, + string: &str, + label_key: &'static str, + label: Option<&str>, + ) -> ContextError; + fn with_context(self, string: &str, label: Option<&str>) -> ContextError { + self.with_context_label_key(string, "label", label) + } } impl WithContextError for E { - fn with_context(self, string: &str, label: Option<&str>) -> ContextError { + fn with_context_label_key( + self, + string: &str, + label_key: &'static str, + label: Option<&str>, + ) -> ContextError { ContextError { string: string.to_string(), cause: Box::new(self), label: label.unwrap_or("").to_string(), + label_key, } } } @@ -1595,6 +1612,7 @@ impl WithContextError for E { pub(crate) struct ContextError { pub string: String, pub cause: Box, + pub label_key: &'static str, pub label: String, } diff --git a/src/backend/error.rs b/src/backend/error.rs index 92bd1335a..0158964f8 100644 --- a/src/backend/error.rs +++ b/src/backend/error.rs @@ -82,7 +82,7 @@ pub trait PrettyError: Error { impl PrettyError for super::direct::ContextError { fn fmt_pretty(&self, _context: &Context) -> String { - format_error_line(self.as_display()) + &format_label_line("label", &self.label) + format_error_line(self.as_display()) + &format_label_line(self.label_key, &self.label) } } From caa33203154a6a8de3cc20245223c84b3d570112 Mon Sep 17 00:00:00 2001 From: Mikko Lehtonen Date: Sat, 21 Nov 2020 23:42:17 +0200 Subject: [PATCH 2/2] Handle PassErrorScope Ids --- Cargo.toml | 4 +-- src/backend/error.rs | 66 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 81a1b1346..f1e33eb98 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,14 +26,14 @@ vulkan-portability = ["wgc/gfx-backend-vulkan", "gfx-backend-vulkan"] package = "wgpu-core" #version = "0.6" git = "https://github.com/gfx-rs/wgpu" -rev = "9d35aea08eb5cdd5ad408e8a13838a7beab11ad3" +rev = "feac96d3151f08188bdd270fdf021117944c01b0" features = ["raw-window-handle"] [dependencies.wgt] package = "wgpu-types" #version = "0.6" git = "https://github.com/gfx-rs/wgpu" -rev = "9d35aea08eb5cdd5ad408e8a13838a7beab11ad3" +rev = "feac96d3151f08188bdd270fdf021117944c01b0" [dependencies] arrayvec = "0.5" diff --git a/src/backend/error.rs b/src/backend/error.rs index 0158964f8..bb662f3da 100644 --- a/src/backend/error.rs +++ b/src/backend/error.rs @@ -37,9 +37,18 @@ fn fmt_pretty_any(error: &(dyn Error + 'static), context: &Context) -> String { if let Some(pretty_err) = error.downcast_ref::() { return pretty_err.fmt_pretty(context); } + if let Some(pretty_err) = error.downcast_ref::() { + return pretty_err.fmt_pretty(context); + } if let Some(pretty_err) = error.downcast_ref::() { return pretty_err.fmt_pretty(context); } + if let Some(pretty_err) = error.downcast_ref::() { + return pretty_err.fmt_pretty(context); + } + if let Some(pretty_err) = error.downcast_ref::() { + return pretty_err.fmt_pretty(context); + } if let Some(pretty_err) = error.downcast_ref::() { return pretty_err.fmt_pretty(context); } @@ -175,6 +184,29 @@ impl PrettyError for wgc::command::RenderPassErrorInner { } } +impl PrettyError for wgc::command::RenderPassError { + fn fmt_pretty(&self, context: &Context) -> String { + // This error is wrapper for the inner error, + // but the scope has useful labels + format_error_line(self) + &self.scope.fmt_pretty(context) + } +} + +impl PrettyError for wgc::command::ComputePassError { + fn fmt_pretty(&self, context: &Context) -> String { + // This error is wrapper for the inner error, + // but the scope has useful labels + format_error_line(self) + &self.scope.fmt_pretty(context) + } +} +impl PrettyError for wgc::command::RenderBundleError { + fn fmt_pretty(&self, context: &Context) -> String { + // This error is wrapper for the inner error, + // but the scope has useful labels + format_error_line(self) + &self.scope.fmt_pretty(context) + } +} + impl PrettyError for wgc::command::ComputePassErrorInner { fn fmt_pretty(&self, context: &Context) -> String { let global = context.global(); @@ -236,3 +268,37 @@ impl PrettyError for wgc::command::TransferError { ret } } + +impl PrettyError for wgc::command::PassErrorScope { + fn fmt_pretty(&self, context: &Context) -> String { + // This error is not in the error chain, only notes are needed + let global = context.global(); + match *self { + Self::Pass(id) => { + let name = wgc::gfx_select!(id => global.command_buffer_label(id)); + format_label_line("command buffer", &name) + } + Self::SetBindGroup(id) => { + let name = wgc::gfx_select!(id => global.bind_group_label(id)); + format_label_line("bind group", &name) + } + Self::SetPipelineRender(id) => { + let name = wgc::gfx_select!(id => global.render_pipeline_label(id)); + format_label_line("render pipeline", &name) + } + Self::SetPipelineCompute(id) => { + let name = wgc::gfx_select!(id => global.compute_pipeline_label(id)); + format_label_line("compute pipeline", &name) + } + Self::SetVertexBuffer(id) => { + let name = wgc::gfx_select!(id => global.buffer_label(id)); + format_label_line("buffer", &name) + } + Self::SetIndexBuffer(id) => { + let name = wgc::gfx_select!(id => global.buffer_label(id)); + format_label_line("buffer", &name) + } + _ => String::new(), + } + } +}