Skip to main content

librashader_reflect/
error.rs

1use crate::reflect::semantics::UniformMemberBlock;
2use thiserror::Error;
3
4/// Error type for shader compilation.
5#[non_exhaustive]
6#[derive(Error, Debug)]
7pub enum ShaderCompileError {
8    /// Compile error from naga.
9    #[cfg(feature = "naga-in")]
10    #[error("error when parsing wgsl: {0}")]
11    NagaCompileError(#[from] naga::front::wgsl::ParseError),
12
13    /// Compilation error from glslang.
14    #[cfg(feature = "glslang-in")]
15    #[error("error when compiling with glslang: {0}")]
16    GlslangError(#[from] glslang::error::GlslangError),
17
18    /// Error when initializing the glslang compiler.
19    #[cfg(feature = "glslang-in")]
20    #[error("error when initializing glslang")]
21    CompilerInitError,
22
23    /// Error when transpiling from spirv-cross.
24    #[cfg(feature = "cross")]
25    #[error("spirv-cross error: {0:?}")]
26    SpirvCrossCompileError(#[from] spirv_cross2::SpirvCrossError),
27
28    /// Error when transpiling from spirv-to-dxil
29    #[cfg(all(target_os = "windows", feature = "dxil"))]
30    #[error("spirv-to-dxil error: {0:?}")]
31    SpirvToDxilCompileError(#[from] spirv_to_dxil::SpirvToDxilError),
32
33    /// Error when transpiling from naga
34    #[cfg(all(feature = "wgsl", feature = "naga"))]
35    #[error("naga error when compiling wgsl: {0:?}")]
36    NagaWgslError(#[from] naga::back::wgsl::Error),
37
38    /// Error when transpiling from naga
39    #[cfg(feature = "naga")]
40    #[error("naga error when compiling spirv: {0:?}")]
41    NagaSpvError(#[from] naga::back::spv::Error),
42
43    /// Error when transpiling from naga
44    #[cfg(all(feature = "naga", feature = "msl"))]
45    #[error("naga error when compiling msl: {0:?}")]
46    NagaMslError(#[from] naga::back::msl::Error),
47
48    /// Error when transpiling from naga
49    #[cfg(any(feature = "naga", feature = "wgsl"))]
50    #[error("naga validation error: {0}")]
51    NagaValidationError(#[from] naga::WithSpan<naga::valid::ValidationError>),
52}
53
54/// The error kind encountered when reflecting shader semantics.
55#[derive(Debug)]
56pub enum SemanticsErrorKind {
57    /// The number of uniform buffers was invalid. Only one UBO is permitted.
58    InvalidUniformBufferCount(usize),
59    /// The number of push constant blocks was invalid. Only one push constant block is permitted.
60    InvalidPushBufferCount(usize),
61    /// The size of the push constant block was invalid.
62    InvalidPushBufferSize(u32),
63    /// The location of a varying was invalid.
64    InvalidLocation(u32),
65    /// The requested descriptor set was invalid. Only descriptor set 0 is available.
66    InvalidDescriptorSet(u32),
67    /// The number of inputs to the shader was invalid.
68    InvalidInputCount(usize),
69    /// The number of outputs declared was invalid.
70    InvalidOutputCount(usize),
71    /// Expected a binding but there was none.
72    MissingBinding,
73    /// The declared binding point was invalid.
74    InvalidBinding(u32),
75    /// The declared resource type was invalid.
76    InvalidResourceType,
77    /// The range of a struct member was invalid.
78    InvalidRange(u32),
79    /// The number of entry points in the shader was invalid.
80    InvalidEntryPointCount(usize),
81    /// The requested uniform or texture name was not provided semantics.
82    UnknownSemantics(String),
83    /// The type of the requested uniform was not compatible with the provided semantics.
84    InvalidTypeForSemantic(String),
85}
86
87/// Error type for shader reflection.
88#[non_exhaustive]
89#[derive(Error, Debug)]
90pub enum ShaderReflectError {
91    /// Reflection error from spirv-cross.
92    #[cfg(feature = "cross")]
93    #[error("spirv cross error: {0}")]
94    SpirvCrossError(#[from] spirv_cross2::SpirvCrossError),
95    /// Error when validating vertex shader semantics.
96    #[error("error when verifying vertex semantics: {0:?}")]
97    VertexSemanticError(SemanticsErrorKind),
98    /// Error when validating fragment shader semantics.
99    #[error("error when verifying texture semantics {0:?}")]
100    FragmentSemanticError(SemanticsErrorKind),
101    /// The vertex and fragment shader must have the same UBO binding location.
102    #[error("vertex and fragment shader must have same UBO binding. declared {vertex} in vertex, got {fragment} in fragment")]
103    MismatchedUniformBuffer { vertex: u32, fragment: u32 },
104    /// The filter chain was found to be non causal. A pass tried to access the target output
105    /// in the future.
106    #[error("filter chain is non causal: tried to access target {target} in pass {pass}")]
107    NonCausalFilterChain { pass: usize, target: usize },
108    /// The offset of the given uniform did not match up in both the vertex and fragment shader.
109    #[error("the offset of {semantic} was declared as {expected} but found as {received} in pass {pass}")]
110    MismatchedOffset {
111        semantic: String,
112        expected: usize,
113        received: usize,
114        ty: UniformMemberBlock,
115        pass: usize,
116    },
117    /// The size of the given uniform did not match up in both the vertex and fragment shader.
118    #[error("the size of {semantic} was found declared as {vertex} in vertex shader but found as {fragment} in fragment in pass {pass}")]
119    MismatchedSize {
120        semantic: String,
121        vertex: u32,
122        fragment: u32,
123        pass: usize,
124    },
125    /// The binding number is already in use.
126    #[error("binding {0} is already in use")]
127    BindingInUse(u32),
128    /// Error when transpiling from naga
129    #[cfg(feature = "naga")]
130    #[error("naga spirv error: {0}")]
131    NagaInputError(#[from] naga::front::spv::Error),
132    /// Error when transpiling from naga
133    #[cfg(feature = "naga")]
134    #[error("naga validation error: {0}")]
135    NagaReflectError(#[from] naga::WithSpan<naga::valid::ValidationError>),
136}