[vello_shaders] Use thiserror::Error for the library Error type

This commit is contained in:
Arman Uguray 2023-03-29 10:12:23 -07:00
parent 14ab8d90ae
commit b52ef32c90
2 changed files with 22 additions and 25 deletions

View file

@ -5,13 +5,15 @@ edition = "2021"
[features] [features]
default = ["compile", "wgsl", "msl"] default = ["compile", "wgsl", "msl"]
compile = ["naga"] compile = ["naga", "thiserror"]
wgsl = [] wgsl = []
msl = [] msl = []
[dependencies] [dependencies]
naga = { git = "https://github.com/gfx-rs/naga", features = ["wgsl-in", "msl-out", "validate"], optional = true } 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] [build-dependencies]
naga = { git = "https://github.com/gfx-rs/naga", features = ["wgsl-in", "msl-out", "validate"] } naga = { git = "https://github.com/gfx-rs/naga", features = ["wgsl-in", "msl-out", "validate"] }
thiserror = "1.0.40"

View file

@ -1,12 +1,14 @@
use naga::{ use {
naga::{
front::wgsl, front::wgsl,
valid::{Capabilities, ModuleInfo, ValidationError, ValidationFlags}, valid::{Capabilities, ModuleInfo, ValidationError, ValidationFlags},
AddressSpace, ImageClass, Module, StorageAccess, WithSpan, AddressSpace, ImageClass, Module, StorageAccess, WithSpan,
}; },
std::{
use std::{
collections::{HashMap, HashSet}, collections::{HashMap, HashSet},
path::Path, path::Path,
},
thiserror::Error,
}; };
pub mod permutations; pub mod permutations;
@ -16,25 +18,18 @@ pub mod msl;
use crate::types::{BindType, BindingInfo}; use crate::types::{BindType, BindingInfo};
#[derive(Debug)] #[derive(Error, Debug)]
pub enum Error { pub enum Error {
Parse(wgsl::ParseError), #[error("failed to parse shader: {0}")]
Validate(WithSpan<ValidationError>), Parse(#[from] wgsl::ParseError),
#[error("failed to validate shader: {0}")]
Validate(#[from] WithSpan<ValidationError>),
#[error("missing entry point function")]
EntryPointNotFound, EntryPointNotFound,
} }
impl From<wgsl::ParseError> for Error {
fn from(e: wgsl::ParseError) -> Self {
Self::Parse(e)
}
}
impl From<WithSpan<ValidationError>> for Error {
fn from(e: WithSpan<ValidationError>) -> Self {
Self::Validate(e)
}
}
#[derive(Debug)] #[derive(Debug)]
pub struct ShaderInfo { pub struct ShaderInfo {
pub source: String, pub source: String,