mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-21 15:00:57 +01:00
Merge #632
632: Improve error messages r=kvark a=scoopr Improve error messages depends on gfx-rs/wgpu#1037 Co-authored-by: Mikko Lehtonen <scoopr@iki.fi>
This commit is contained in:
commit
4fb4eac485
3 files changed
+90
-6
No files matched your search
+2
-2
@@ -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"
|
||||
|
||||
+21
-3
@@ -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<E: Error + Send + Sync + 'static> 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<E: Error + Send + Sync + 'static> WithContextError for E {
|
||||
pub(crate) struct ContextError {
|
||||
pub string: String,
|
||||
pub cause: Box<dyn Error + Send + Sync + 'static>,
|
||||
pub label_key: &'static str,
|
||||
pub label: String,
|
||||
}
|
||||
|
||||
|
||||
+67
-1
@@ -37,9 +37,18 @@ fn fmt_pretty_any(error: &(dyn Error + 'static), context: &Context) -> String {
|
||||
if let Some(pretty_err) = error.downcast_ref::<wgc::command::RenderPassErrorInner>() {
|
||||
return pretty_err.fmt_pretty(context);
|
||||
}
|
||||
if let Some(pretty_err) = error.downcast_ref::<wgc::command::RenderPassError>() {
|
||||
return pretty_err.fmt_pretty(context);
|
||||
}
|
||||
if let Some(pretty_err) = error.downcast_ref::<wgc::command::ComputePassErrorInner>() {
|
||||
return pretty_err.fmt_pretty(context);
|
||||
}
|
||||
if let Some(pretty_err) = error.downcast_ref::<wgc::command::ComputePassError>() {
|
||||
return pretty_err.fmt_pretty(context);
|
||||
}
|
||||
if let Some(pretty_err) = error.downcast_ref::<wgc::command::RenderBundleError>() {
|
||||
return pretty_err.fmt_pretty(context);
|
||||
}
|
||||
if let Some(pretty_err) = error.downcast_ref::<wgc::command::TransferError>() {
|
||||
return pretty_err.fmt_pretty(context);
|
||||
}
|
||||
@@ -82,7 +91,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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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(),
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user