From 8afb441ca7987a976b579e67bb0e46ae0d24a66a Mon Sep 17 00:00:00 2001 From: andristarr Date: Mon, 29 Jan 2024 20:50:35 +0100 Subject: [PATCH] adding internal error filter (#5160) Co-authored-by: Erich Gubler --- deno_webgpu/01_webgpu.js | 1 + deno_webgpu/webgpu.idl | 1 + wgpu/src/backend/webgpu.rs | 1 + wgpu/src/backend/wgpu_core.rs | 1 + wgpu/src/lib.rs | 19 +++++++++++++++++++ 5 files changed, 23 insertions(+) diff --git a/deno_webgpu/01_webgpu.js b/deno_webgpu/01_webgpu.js index 3f7b1ed57..9904f4d24 100644 --- a/deno_webgpu/01_webgpu.js +++ b/deno_webgpu/01_webgpu.js @@ -6915,6 +6915,7 @@ webidl.converters["GPUErrorFilter"] = webidl.createEnumConverter( [ "out-of-memory", "validation", + "internal" ], ); diff --git a/deno_webgpu/webgpu.idl b/deno_webgpu/webgpu.idl index bf4da0124..46d587874 100644 --- a/deno_webgpu/webgpu.idl +++ b/deno_webgpu/webgpu.idl @@ -1176,6 +1176,7 @@ interface GPUOutOfMemoryError enum GPUErrorFilter { "validation", "out-of-memory", + "internal" }; partial interface GPUDevice { diff --git a/wgpu/src/backend/webgpu.rs b/wgpu/src/backend/webgpu.rs index 91115c3e0..4f758845b 100644 --- a/wgpu/src/backend/webgpu.rs +++ b/wgpu/src/backend/webgpu.rs @@ -2009,6 +2009,7 @@ impl crate::context::Context for ContextWebGpu { device_data.0.push_error_scope(match filter { crate::ErrorFilter::OutOfMemory => web_sys::GpuErrorFilter::OutOfMemory, crate::ErrorFilter::Validation => web_sys::GpuErrorFilter::Validation, + crate::ErrorFilter::Internal => web_sys::GpuErrorFilter::Internal, }); } diff --git a/wgpu/src/backend/wgpu_core.rs b/wgpu/src/backend/wgpu_core.rs index 6a9d9fa4f..3901e7d44 100644 --- a/wgpu/src/backend/wgpu_core.rs +++ b/wgpu/src/backend/wgpu_core.rs @@ -2959,6 +2959,7 @@ impl ErrorSinkRaw { let filter = match err { crate::Error::OutOfMemory { .. } => crate::ErrorFilter::OutOfMemory, crate::Error::Validation { .. } => crate::ErrorFilter::Validation, + crate::Error::Internal { .. } => crate::ErrorFilter::Internal, }; match self .scopes diff --git a/wgpu/src/lib.rs b/wgpu/src/lib.rs index b963fa695..6becc7cde 100644 --- a/wgpu/src/lib.rs +++ b/wgpu/src/lib.rs @@ -163,6 +163,8 @@ pub enum ErrorFilter { OutOfMemory, /// Catch only validation errors. Validation, + /// Catch only internal errors. + Internal, } static_assertions::assert_impl_all!(ErrorFilter: Send, Sync); @@ -5143,6 +5145,21 @@ pub enum Error { /// Description of the validation error. description: String, }, + /// Internal error. Used for signalling any failures not explicitly expected by WebGPU. + /// + /// These could be due to internal implementation or system limits being reached. + Internal { + /// Lower level source of the error. + #[cfg(send_sync)] + #[cfg_attr(docsrs, doc(cfg(all())))] + source: Box, + /// Lower level source of the error. + #[cfg(not(send_sync))] + #[cfg_attr(docsrs, doc(cfg(all())))] + source: Box, + /// Description of the internal GPU error. + description: String, + }, } #[cfg(send_sync)] static_assertions::assert_impl_all!(Error: Send); @@ -5152,6 +5169,7 @@ impl error::Error for Error { match self { Error::OutOfMemory { source } => Some(source.as_ref()), Error::Validation { source, .. } => Some(source.as_ref()), + Error::Internal { source, .. } => Some(source.as_ref()), } } } @@ -5161,6 +5179,7 @@ impl fmt::Display for Error { match self { Error::OutOfMemory { .. } => f.write_str("Out of Memory"), Error::Validation { description, .. } => f.write_str(description), + Error::Internal { description, .. } => f.write_str(description), } } }