mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
[naga wgsl-out] Consolidate unsupported Naga IR feature errors.
Introduce a new variant of `naga::back::wgsl::Error`, `Unsupported`, and let it subsume `UnsupportedMathFunction` and various uses of `Custom`. Introduce a helper function, `Error::unsupported`, for building these errors.
This commit is contained in:
@@ -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<T: core::fmt::Debug>(kind: &'static str, value: T) -> Error {
|
||||
Error::Unsupported {
|
||||
kind,
|
||||
value: format!("{value:?}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn write_string(
|
||||
|
||||
@@ -1765,12 +1765,12 @@ impl<W: Write> Writer<W> {
|
||||
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)),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user