librashader/librashader-reflect/src/error.rs

140 lines
5.6 KiB
Rust
Raw Normal View History

2023-01-29 18:30:58 +11:00
use crate::reflect::semantics::UniformMemberBlock;
2022-10-27 17:22:44 +11:00
use thiserror::Error;
2022-10-23 17:36:41 +11:00
/// Error type for shader compilation.
#[non_exhaustive]
2022-10-23 17:36:41 +11:00
#[derive(Error, Debug)]
pub enum ShaderCompileError {
/// Compile error from naga.
2024-08-09 14:55:58 +10:00
#[cfg(feature = "unstable-naga-in")]
2022-10-23 17:36:41 +11:00
#[error("shader")]
NagaCompileError(Vec<naga::front::glsl::Error>),
2024-02-08 14:26:17 +11:00
/// Compilation error from glslang.
2024-02-23 11:43:30 +11:00
#[error("error when compiling with glslang: {0}")]
2024-02-08 14:26:17 +11:00
GlslangError(#[from] glslang::error::GlslangError),
2022-10-23 17:36:41 +11:00
2024-02-08 14:26:17 +11:00
/// Error when initializing the glslang compiler.
2024-02-23 11:43:30 +11:00
#[error("error when initializing glslang")]
2024-02-08 14:26:17 +11:00
CompilerInitError,
2022-11-07 16:25:11 +11:00
/// Error when transpiling from spirv-cross.
2024-02-23 11:43:30 +11:00
#[error("spirv-cross error: {0:?}")]
2022-11-07 16:25:11 +11:00
SpirvCrossCompileError(#[from] spirv_cross::ErrorCode),
2023-02-05 09:53:51 +11:00
/// Error when transpiling from spirv-to-dxil
2023-11-29 18:06:20 +11:00
#[cfg(all(target_os = "windows", feature = "dxil"))]
2024-02-23 11:43:30 +11:00
#[error("spirv-to-dxil error: {0:?}")]
2023-02-07 11:22:53 +11:00
SpirvToDxilCompileError(#[from] spirv_to_dxil::SpirvToDxilError),
2023-12-13 11:02:49 +11:00
/// Error when transpiling from naga
#[cfg(all(feature = "wgsl", feature = "naga"))]
2024-02-23 11:43:30 +11:00
#[error("naga error when compiling wgsl: {0:?}")]
2023-12-13 11:02:49 +11:00
NagaWgslError(#[from] naga::back::wgsl::Error),
/// Error when transpiling from naga
#[cfg(feature = "naga")]
2024-02-23 11:43:30 +11:00
#[error("naga error when compiling spirv: {0:?}")]
2024-02-12 07:39:11 +11:00
NagaSpvError(#[from] naga::back::spv::Error),
2023-12-13 11:02:49 +11:00
/// Error when transpiling from naga
2024-02-12 07:39:11 +11:00
#[cfg(all(feature = "naga", feature = "msl"))]
2024-02-23 11:43:30 +11:00
#[error("naga error when compiling msl: {0:?}")]
2024-02-12 07:39:11 +11:00
NagaMslError(#[from] naga::back::msl::Error),
/// Error when transpiling from naga
#[cfg(any(feature = "naga", feature = "wgsl"))]
2024-02-23 11:43:30 +11:00
#[error("naga validation error: {0}")]
2023-12-13 11:02:49 +11:00
NagaValidationError(#[from] naga::WithSpan<naga::valid::ValidationError>),
2022-10-23 17:36:41 +11:00
}
/// The error kind encountered when reflecting shader semantics.
#[derive(Debug)]
pub enum SemanticsErrorKind {
/// The number of uniform buffers was invalid. Only one UBO is permitted.
InvalidUniformBufferCount(usize),
/// The number of push constant blocks was invalid. Only one push constant block is permitted.
InvalidPushBufferCount(usize),
/// The size of the push constant block was invalid.
InvalidPushBufferSize(u32),
/// The location of a varying was invalid.
InvalidLocation(u32),
/// The requested descriptor set was invalid. Only descriptor set 0 is available.
InvalidDescriptorSet(u32),
/// The number of inputs to the shader was invalid.
InvalidInputCount(usize),
/// The number of outputs declared was invalid.
InvalidOutputCount(usize),
/// Expected a binding but there was none.
MissingBinding,
/// The declared binding point was invalid.
InvalidBinding(u32),
/// The declared resource type was invalid.
InvalidResourceType,
/// The range of a struct member was invalid.
InvalidRange(u32),
/// The number of entry points in the shader was invalid.
InvalidEntryPointCount(usize),
/// The requested uniform or texture name was not provided semantics.
UnknownSemantics(String),
/// The type of the requested uniform was not compatible with the provided semantics.
2022-10-27 17:22:44 +11:00
InvalidTypeForSemantic(String),
}
/// Error type for shader reflection.
#[non_exhaustive]
2022-10-23 17:36:41 +11:00
#[derive(Error, Debug)]
pub enum ShaderReflectError {
/// Reflection error from spirv-cross.
2024-02-23 11:43:30 +11:00
#[error("spirv cross error: {0}")]
2022-11-22 08:21:50 +11:00
SpirvCrossError(#[from] spirv_cross::ErrorCode),
/// Error when validating vertex shader semantics.
2024-02-23 11:43:30 +11:00
#[error("error when verifying vertex semantics: {0:?}")]
VertexSemanticError(SemanticsErrorKind),
/// Error when validating fragment shader semantics.
2024-02-23 11:43:30 +11:00
#[error("error when verifying texture semantics {0:?}")]
FragmentSemanticError(SemanticsErrorKind),
/// The vertex and fragment shader must have the same UBO binding location.
2024-02-23 11:43:30 +11:00
#[error("vertex and fragment shader must have same UBO binding. declared {vertex} in vertex, got {fragment} in fragment")]
MismatchedUniformBuffer { vertex: u32, fragment: u32 },
/// The filter chain was found to be non causal. A pass tried to access the target output
/// in the future.
2024-02-23 11:43:30 +11:00
#[error("filter chain is non causal: tried to access target {target} in pass {pass}")]
2022-11-20 10:48:54 +11:00
NonCausalFilterChain { pass: usize, target: usize },
/// The offset of the given uniform did not match up in both the vertex and fragment shader.
2024-02-23 11:43:30 +11:00
#[error("the offset of {semantic} was declared as {expected} but found as {received} in pass {pass}")]
2022-10-27 17:22:44 +11:00
MismatchedOffset {
semantic: String,
expected: usize,
received: usize,
ty: UniformMemberBlock,
2023-01-29 18:30:58 +11:00
pass: usize,
2022-10-27 17:22:44 +11:00
},
/// The size of the given uniform did not match up in both the vertex and fragment shader.
2024-02-23 11:43:30 +11:00
#[error("the size of {semantic} was found declared as {vertex} in vertex shader but found as {fragment} in fragment in pass {pass}")]
MismatchedSize {
2022-10-27 17:22:44 +11:00
semantic: String,
vertex: u32,
fragment: u32,
2023-01-29 18:30:58 +11:00
pass: usize,
2022-10-27 17:22:44 +11:00
},
/// The binding number is already in use.
2024-02-23 11:43:30 +11:00
#[error("binding {0} is already in use")]
2022-10-27 17:22:44 +11:00
BindingInUse(u32),
2023-12-13 11:02:49 +11:00
/// Error when transpiling from naga
#[cfg(feature = "naga")]
2024-02-23 11:43:30 +11:00
#[error("naga spirv error: {0}")]
2023-12-13 11:02:49 +11:00
NagaInputError(#[from] naga::front::spv::Error),
/// Error when transpiling from naga
#[cfg(feature = "naga")]
2024-02-23 11:43:30 +11:00
#[error("naga validation error: {0}")]
NagaReflectError(#[from] naga::WithSpan<naga::valid::ValidationError>),
2022-10-23 17:36:41 +11:00
}
2024-08-09 14:55:58 +10:00
#[cfg(feature = "unstable-naga-in")]
2022-10-23 17:36:41 +11:00
impl From<Vec<naga::front::glsl::Error>> for ShaderCompileError {
fn from(err: Vec<naga::front::glsl::Error>) -> Self {
ShaderCompileError::NagaCompileError(err)
}
}