diff --git a/naga/src/back/wgsl/mod.rs b/naga/src/back/wgsl/mod.rs index 50ae648049..029e1fff0e 100644 --- a/naga/src/back/wgsl/mod.rs +++ b/naga/src/back/wgsl/mod.rs @@ -7,6 +7,7 @@ Backend for [WGSL][wgsl] (WebGPU Shading Language). mod polyfill; mod writer; +use alloc::format; use alloc::string::String; use thiserror::Error; @@ -21,10 +22,28 @@ pub enum Error { Custom(String), #[error("{0}")] Unimplemented(String), // TODO: Error used only during development - #[error("Unsupported math function: {0:?}")] - UnsupportedMathFunction(crate::MathFunction), #[error("Unsupported relational function: {0:?}")] UnsupportedRelationalFunction(crate::RelationalFunction), + #[error("Unsupported {kind}: {value}")] + Unsupported { + /// What kind of unsupported thing this is: interpolation, builtin, etc. + kind: &'static str, + + /// The debug form of the Naga IR value that this backend can't express. + value: String, + }, +} + +impl Error { + /// Produce an [`Unsupported`] error for `value`. + /// + /// [`Unsupported`]: Error::Unsupported + fn unsupported(kind: &'static str, value: T) -> Error { + Error::Unsupported { + kind, + value: format!("{value:?}"), + } + } } pub fn write_string( diff --git a/naga/src/back/wgsl/writer.rs b/naga/src/back/wgsl/writer.rs index 4fd0493f91..5dfda9fdfb 100644 --- a/naga/src/back/wgsl/writer.rs +++ b/naga/src/back/wgsl/writer.rs @@ -1765,12 +1765,12 @@ impl Writer { let ty = func_ctx.resolve_type(arg, &module.types); let Some(overload) = InversePolyfill::find_overload(ty) else { - return Err(Error::UnsupportedMathFunction(fun)); + return Err(Error::unsupported("math function", fun)); }; Function::InversePolyfill(overload) } - Mf::Outer => return Err(Error::UnsupportedMathFunction(fun)), + Mf::Outer => return Err(Error::unsupported("math function", fun)), }; match function { @@ -1981,7 +1981,7 @@ fn builtin_str(built_in: crate::BuiltIn) -> Result<&'static str, Error> { | Bi::PointSize | Bi::PointCoord | Bi::WorkGroupSize - | Bi::DrawID => return Err(Error::Custom(format!("Unsupported builtin {built_in:?}"))), + | Bi::DrawID => return Err(Error::unsupported("builtin", built_in)), }) }