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
|
|
|
|
2022-12-01 17:50:16 +11:00
|
|
|
/// Error type for shader compilation.
|
2022-11-28 15:37:45 +11:00
|
|
|
#[non_exhaustive]
|
2022-10-23 17:36:41 +11:00
|
|
|
#[derive(Error, Debug)]
|
|
|
|
pub enum ShaderCompileError {
|
2022-12-01 17:50:16 +11:00
|
|
|
/// Compile error from naga.
|
2023-01-16 10:36:38 +11:00
|
|
|
#[cfg(feature = "unstable-naga")]
|
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
|
|
|
|
2022-12-01 17:50:16 +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
|
2024-02-11 18:23:01 +11:00
|
|
|
#[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),
|
2024-02-11 18:23:01 +11:00
|
|
|
|
|
|
|
/// 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),
|
2024-02-11 18:23:01 +11:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-12-01 17:50:16 +11:00
|
|
|
/// The error kind encountered when reflecting shader semantics.
|
2022-10-24 14:22:26 +11:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum SemanticsErrorKind {
|
2022-12-01 17:50:16 +11:00
|
|
|
/// The number of uniform buffers was invalid. Only one UBO is permitted.
|
2022-10-26 13:13:39 +11:00
|
|
|
InvalidUniformBufferCount(usize),
|
2022-12-01 17:50:16 +11:00
|
|
|
/// The number of push constant blocks was invalid. Only one push constant block is permitted.
|
2023-12-13 18:30:01 +11:00
|
|
|
InvalidPushBufferCount(usize),
|
|
|
|
/// The size of the push constant block was invalid.
|
2022-10-26 13:13:39 +11:00
|
|
|
InvalidPushBufferSize(u32),
|
2022-12-01 17:50:16 +11:00
|
|
|
/// The location of a varying was invalid.
|
2022-10-24 14:22:26 +11:00
|
|
|
InvalidLocation(u32),
|
2022-12-01 17:50:16 +11:00
|
|
|
/// The requested descriptor set was invalid. Only descriptor set 0 is available.
|
2022-10-24 14:22:26 +11:00
|
|
|
InvalidDescriptorSet(u32),
|
2022-12-01 17:50:16 +11:00
|
|
|
/// The number of inputs to the shader was invalid.
|
2022-10-24 14:22:26 +11:00
|
|
|
InvalidInputCount(usize),
|
2022-12-01 17:50:16 +11:00
|
|
|
/// The number of outputs declared was invalid.
|
2022-10-24 14:22:26 +11:00
|
|
|
InvalidOutputCount(usize),
|
2023-12-13 18:30:01 +11:00
|
|
|
/// Expected a binding but there was none.
|
|
|
|
MissingBinding,
|
2022-12-01 17:50:16 +11:00
|
|
|
/// The declared binding point was invalid.
|
2022-10-24 14:22:26 +11:00
|
|
|
InvalidBinding(u32),
|
2022-12-01 17:50:16 +11:00
|
|
|
/// The declared resource type was invalid.
|
2022-10-24 14:22:26 +11:00
|
|
|
InvalidResourceType,
|
2022-12-01 17:50:16 +11:00
|
|
|
/// The range of a struct member was invalid.
|
2022-10-26 13:13:39 +11:00
|
|
|
InvalidRange(u32),
|
2023-12-13 18:30:01 +11:00
|
|
|
/// The number of entry points in the shader was invalid.
|
|
|
|
InvalidEntryPointCount(usize),
|
2022-12-01 17:50:16 +11:00
|
|
|
/// The requested uniform or texture name was not provided semantics.
|
2022-10-26 16:19:04 +11:00
|
|
|
UnknownSemantics(String),
|
2022-12-01 17:50:16 +11:00
|
|
|
/// The type of the requested uniform was not compatible with the provided semantics.
|
2022-10-27 17:22:44 +11:00
|
|
|
InvalidTypeForSemantic(String),
|
2022-10-24 14:22:26 +11:00
|
|
|
}
|
|
|
|
|
2022-12-01 17:50:16 +11:00
|
|
|
/// Error type for shader reflection.
|
2022-11-28 15:37:45 +11:00
|
|
|
#[non_exhaustive]
|
2022-10-23 17:36:41 +11:00
|
|
|
#[derive(Error, Debug)]
|
|
|
|
pub enum ShaderReflectError {
|
2022-12-01 17:50:16 +11:00
|
|
|
/// 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),
|
2022-12-01 17:50:16 +11:00
|
|
|
/// Error when validating vertex shader semantics.
|
2024-02-23 11:43:30 +11:00
|
|
|
#[error("error when verifying vertex semantics: {0:?}")]
|
2022-10-24 14:22:26 +11:00
|
|
|
VertexSemanticError(SemanticsErrorKind),
|
2022-12-01 17:50:16 +11:00
|
|
|
/// Error when validating fragment shader semantics.
|
2024-02-23 11:43:30 +11:00
|
|
|
#[error("error when verifying texture semantics {0:?}")]
|
2022-10-24 14:22:26 +11:00
|
|
|
FragmentSemanticError(SemanticsErrorKind),
|
2022-12-01 17:50:16 +11:00
|
|
|
/// 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")]
|
2022-10-26 13:13:39 +11:00
|
|
|
MismatchedUniformBuffer { vertex: u32, fragment: u32 },
|
2022-12-01 17:50:16 +11:00
|
|
|
/// 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 },
|
2022-12-01 17:50:16 +11:00
|
|
|
/// 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,
|
2023-01-29 17:57:09 +11:00
|
|
|
expected: usize,
|
|
|
|
received: usize,
|
|
|
|
ty: UniformMemberBlock,
|
2023-01-29 18:30:58 +11:00
|
|
|
pass: usize,
|
2022-10-27 17:22:44 +11:00
|
|
|
},
|
2022-12-01 17:50:16 +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}")]
|
2022-12-01 17:50:16 +11:00
|
|
|
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
|
|
|
},
|
2022-12-01 17:50:16 +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
|
2024-02-11 13:17:58 +11:00
|
|
|
#[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),
|
2024-02-16 10:57:51 +11:00
|
|
|
/// Error when transpiling from naga
|
|
|
|
#[cfg(feature = "naga")]
|
2024-02-23 11:43:30 +11:00
|
|
|
#[error("naga validation error: {0}")]
|
2024-02-16 10:57:51 +11:00
|
|
|
NagaReflectError(#[from] naga::WithSpan<naga::valid::ValidationError>),
|
2022-10-23 17:36:41 +11:00
|
|
|
}
|
|
|
|
|
2023-01-16 10:36:38 +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)
|
|
|
|
}
|
|
|
|
}
|