librashader/librashader-reflect/src/error.rs

106 lines
3.8 KiB
Rust
Raw Normal View History

use crate::reflect::semantics::{MemberOffset, 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.
#[cfg(feature = "unstable-naga")]
2022-10-23 17:36:41 +11:00
#[error("shader")]
NagaCompileError(Vec<naga::front::glsl::Error>),
/// Compilation error from shaderc (glslang).
2022-10-23 17:36:41 +11:00
#[error("shaderc")]
ShaderCCompileError(#[from] shaderc::Error),
/// Error when initializing the shaderc compiler.
2022-10-23 17:36:41 +11:00
#[error("shaderc init")]
ShaderCInitError,
2022-11-07 16:25:11 +11:00
/// Error when transpiling from spirv-cross.
2022-11-07 16:25:11 +11:00
#[error("cross")]
SpirvCrossCompileError(#[from] spirv_cross::ErrorCode),
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.
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),
/// 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 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 {
/// Compile error from naga.
#[cfg(feature = "unstable-naga")]
2022-10-23 17:36:41 +11:00
#[error("shader")]
NagaCompileError(#[from] naga::front::spv::Error),
/// Reflection error from spirv-cross.
2022-11-22 08:21:50 +11:00
#[error("spirv")]
SpirvCrossError(#[from] spirv_cross::ErrorCode),
/// Error when validating vertex shader semantics.
#[error("error when verifying vertex semantics")]
VertexSemanticError(SemanticsErrorKind),
/// Error when validating fragment shader semantics.
#[error("error when verifying texture semantics")]
FragmentSemanticError(SemanticsErrorKind),
/// The vertex and fragment shader must have the same UBO binding location.
#[error("vertex and fragment shader must have same binding")]
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.
#[error("filter chain is non causal")]
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.
#[error("mismatched offset")]
2022-10-27 17:22:44 +11:00
MismatchedOffset {
semantic: String,
expected: usize,
received: usize,
ty: UniformMemberBlock,
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.
#[error("mismatched component")]
MismatchedSize {
2022-10-27 17:22:44 +11:00
semantic: String,
vertex: u32,
fragment: u32,
pass: usize
2022-10-27 17:22:44 +11:00
},
/// The binding number is already in use.
2022-10-27 17:22:44 +11:00
#[error("the binding is already in use")]
BindingInUse(u32),
2022-10-23 17:36:41 +11:00
}
#[cfg(feature = "unstable-naga")]
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)
}
}