librashader_reflect/
error.rs1use crate::reflect::semantics::UniformMemberBlock;
2use thiserror::Error;
3
4#[non_exhaustive]
6#[derive(Error, Debug)]
7pub enum ShaderCompileError {
8 #[cfg(feature = "unstable-naga-in")]
10 #[error("shader")]
11 NagaCompileError(Vec<naga::front::glsl::Error>),
12
13 #[error("error when compiling with glslang: {0}")]
15 GlslangError(#[from] glslang::error::GlslangError),
16
17 #[error("error when initializing glslang")]
19 CompilerInitError,
20
21 #[error("spirv-cross error: {0:?}")]
23 SpirvCrossCompileError(#[from] spirv_cross2::SpirvCrossError),
24
25 #[cfg(all(target_os = "windows", feature = "dxil"))]
27 #[error("spirv-to-dxil error: {0:?}")]
28 SpirvToDxilCompileError(#[from] spirv_to_dxil::SpirvToDxilError),
29
30 #[cfg(all(feature = "wgsl", feature = "naga"))]
32 #[error("naga error when compiling wgsl: {0:?}")]
33 NagaWgslError(#[from] naga::back::wgsl::Error),
34
35 #[cfg(feature = "naga")]
37 #[error("naga error when compiling spirv: {0:?}")]
38 NagaSpvError(#[from] naga::back::spv::Error),
39
40 #[cfg(all(feature = "naga", feature = "msl"))]
42 #[error("naga error when compiling msl: {0:?}")]
43 NagaMslError(#[from] naga::back::msl::Error),
44
45 #[cfg(any(feature = "naga", feature = "wgsl"))]
47 #[error("naga validation error: {0}")]
48 NagaValidationError(#[from] naga::WithSpan<naga::valid::ValidationError>),
49}
50
51#[derive(Debug)]
53pub enum SemanticsErrorKind {
54 InvalidUniformBufferCount(usize),
56 InvalidPushBufferCount(usize),
58 InvalidPushBufferSize(u32),
60 InvalidLocation(u32),
62 InvalidDescriptorSet(u32),
64 InvalidInputCount(usize),
66 InvalidOutputCount(usize),
68 MissingBinding,
70 InvalidBinding(u32),
72 InvalidResourceType,
74 InvalidRange(u32),
76 InvalidEntryPointCount(usize),
78 UnknownSemantics(String),
80 InvalidTypeForSemantic(String),
82}
83
84#[non_exhaustive]
86#[derive(Error, Debug)]
87pub enum ShaderReflectError {
88 #[error("spirv cross error: {0}")]
90 SpirvCrossError(#[from] spirv_cross2::SpirvCrossError),
91 #[error("error when verifying vertex semantics: {0:?}")]
93 VertexSemanticError(SemanticsErrorKind),
94 #[error("error when verifying texture semantics {0:?}")]
96 FragmentSemanticError(SemanticsErrorKind),
97 #[error("vertex and fragment shader must have same UBO binding. declared {vertex} in vertex, got {fragment} in fragment")]
99 MismatchedUniformBuffer { vertex: u32, fragment: u32 },
100 #[error("filter chain is non causal: tried to access target {target} in pass {pass}")]
103 NonCausalFilterChain { pass: usize, target: usize },
104 #[error("the offset of {semantic} was declared as {expected} but found as {received} in pass {pass}")]
106 MismatchedOffset {
107 semantic: String,
108 expected: usize,
109 received: usize,
110 ty: UniformMemberBlock,
111 pass: usize,
112 },
113 #[error("the size of {semantic} was found declared as {vertex} in vertex shader but found as {fragment} in fragment in pass {pass}")]
115 MismatchedSize {
116 semantic: String,
117 vertex: u32,
118 fragment: u32,
119 pass: usize,
120 },
121 #[error("binding {0} is already in use")]
123 BindingInUse(u32),
124 #[cfg(feature = "naga")]
126 #[error("naga spirv error: {0}")]
127 NagaInputError(#[from] naga::front::spv::Error),
128 #[cfg(feature = "naga")]
130 #[error("naga validation error: {0}")]
131 NagaReflectError(#[from] naga::WithSpan<naga::valid::ValidationError>),
132}
133
134#[cfg(feature = "unstable-naga-in")]
135impl From<Vec<naga::front::glsl::Error>> for ShaderCompileError {
136 fn from(err: Vec<naga::front::glsl::Error>) -> Self {
137 ShaderCompileError::NagaCompileError(err)
138 }
139}