diff --git a/vello_shaders/Cargo.toml b/vello_shaders/Cargo.toml index abd7dc0..72217a8 100644 --- a/vello_shaders/Cargo.toml +++ b/vello_shaders/Cargo.toml @@ -5,13 +5,15 @@ edition = "2021" [features] default = ["compile", "wgsl", "msl"] -compile = ["naga"] +compile = ["naga", "thiserror"] wgsl = [] msl = [] [dependencies] naga = { git = "https://github.com/gfx-rs/naga", features = ["wgsl-in", "msl-out", "validate"], optional = true } +thiserror = { version = "1.0.40", optional = true } [build-dependencies] naga = { git = "https://github.com/gfx-rs/naga", features = ["wgsl-in", "msl-out", "validate"] } +thiserror = "1.0.40" diff --git a/vello_shaders/src/compile/mod.rs b/vello_shaders/src/compile/mod.rs index c1815a4..6d88667 100644 --- a/vello_shaders/src/compile/mod.rs +++ b/vello_shaders/src/compile/mod.rs @@ -1,12 +1,14 @@ -use naga::{ - front::wgsl, - valid::{Capabilities, ModuleInfo, ValidationError, ValidationFlags}, - AddressSpace, ImageClass, Module, StorageAccess, WithSpan, -}; - -use std::{ - collections::{HashMap, HashSet}, - path::Path, +use { + naga::{ + front::wgsl, + valid::{Capabilities, ModuleInfo, ValidationError, ValidationFlags}, + AddressSpace, ImageClass, Module, StorageAccess, WithSpan, + }, + std::{ + collections::{HashMap, HashSet}, + path::Path, + }, + thiserror::Error, }; pub mod permutations; @@ -16,25 +18,18 @@ pub mod msl; use crate::types::{BindType, BindingInfo}; -#[derive(Debug)] +#[derive(Error, Debug)] pub enum Error { - Parse(wgsl::ParseError), - Validate(WithSpan), + #[error("failed to parse shader: {0}")] + Parse(#[from] wgsl::ParseError), + + #[error("failed to validate shader: {0}")] + Validate(#[from] WithSpan), + + #[error("missing entry point function")] EntryPointNotFound, } -impl From for Error { - fn from(e: wgsl::ParseError) -> Self { - Self::Parse(e) - } -} - -impl From> for Error { - fn from(e: WithSpan) -> Self { - Self::Validate(e) - } -} - #[derive(Debug)] pub struct ShaderInfo { pub source: String,