reflect: improve error messages

This commit is contained in:
chyyran 2024-02-22 19:43:30 -05:00 committed by Ronny Chan
parent b5bc3c11e1
commit 7a3a690166
4 changed files with 21 additions and 21 deletions

View file

@ -11,40 +11,40 @@ pub enum ShaderCompileError {
NagaCompileError(Vec<naga::front::glsl::Error>), NagaCompileError(Vec<naga::front::glsl::Error>),
/// Compilation error from glslang. /// Compilation error from glslang.
#[error("glslang")] #[error("error when compiling with glslang: {0}")]
GlslangError(#[from] glslang::error::GlslangError), GlslangError(#[from] glslang::error::GlslangError),
/// Error when initializing the glslang compiler. /// Error when initializing the glslang compiler.
#[error("glslang init")] #[error("error when initializing glslang")]
CompilerInitError, CompilerInitError,
/// Error when transpiling from spirv-cross. /// Error when transpiling from spirv-cross.
#[error("cross")] #[error("spirv-cross error: {0:?}")]
SpirvCrossCompileError(#[from] spirv_cross::ErrorCode), SpirvCrossCompileError(#[from] spirv_cross::ErrorCode),
/// Error when transpiling from spirv-to-dxil /// Error when transpiling from spirv-to-dxil
#[cfg(all(target_os = "windows", feature = "dxil"))] #[cfg(all(target_os = "windows", feature = "dxil"))]
#[error("spirv-to-dxil")] #[error("spirv-to-dxil error: {0:?}")]
SpirvToDxilCompileError(#[from] spirv_to_dxil::SpirvToDxilError), SpirvToDxilCompileError(#[from] spirv_to_dxil::SpirvToDxilError),
/// Error when transpiling from naga /// Error when transpiling from naga
#[cfg(all(feature = "wgsl", feature = "naga"))] #[cfg(all(feature = "wgsl", feature = "naga"))]
#[error("naga-wgsl")] #[error("naga error when compiling wgsl: {0:?}")]
NagaWgslError(#[from] naga::back::wgsl::Error), NagaWgslError(#[from] naga::back::wgsl::Error),
/// Error when transpiling from naga /// Error when transpiling from naga
#[cfg(feature = "naga")] #[cfg(feature = "naga")]
#[error("naga-spv")] #[error("naga error when compiling spirv: {0:?}")]
NagaSpvError(#[from] naga::back::spv::Error), NagaSpvError(#[from] naga::back::spv::Error),
/// Error when transpiling from naga /// Error when transpiling from naga
#[cfg(all(feature = "naga", feature = "msl"))] #[cfg(all(feature = "naga", feature = "msl"))]
#[error("naga-spv")] #[error("naga error when compiling msl: {0:?}")]
NagaMslError(#[from] naga::back::msl::Error), NagaMslError(#[from] naga::back::msl::Error),
/// Error when transpiling from naga /// Error when transpiling from naga
#[cfg(any(feature = "naga", feature = "wgsl"))] #[cfg(any(feature = "naga", feature = "wgsl"))]
#[error("naga-wgsl")] #[error("naga validation error: {0}")]
NagaValidationError(#[from] naga::WithSpan<naga::valid::ValidationError>), NagaValidationError(#[from] naga::WithSpan<naga::valid::ValidationError>),
} }
@ -86,23 +86,23 @@ pub enum SemanticsErrorKind {
#[derive(Error, Debug)] #[derive(Error, Debug)]
pub enum ShaderReflectError { pub enum ShaderReflectError {
/// Reflection error from spirv-cross. /// Reflection error from spirv-cross.
#[error("spirv")] #[error("spirv cross error: {0}")]
SpirvCrossError(#[from] spirv_cross::ErrorCode), SpirvCrossError(#[from] spirv_cross::ErrorCode),
/// Error when validating vertex shader semantics. /// Error when validating vertex shader semantics.
#[error("error when verifying vertex semantics")] #[error("error when verifying vertex semantics: {0:?}")]
VertexSemanticError(SemanticsErrorKind), VertexSemanticError(SemanticsErrorKind),
/// Error when validating fragment shader semantics. /// Error when validating fragment shader semantics.
#[error("error when verifying texture semantics")] #[error("error when verifying texture semantics {0:?}")]
FragmentSemanticError(SemanticsErrorKind), FragmentSemanticError(SemanticsErrorKind),
/// The vertex and fragment shader must have the same UBO binding location. /// The vertex and fragment shader must have the same UBO binding location.
#[error("vertex and fragment shader must have same binding")] #[error("vertex and fragment shader must have same UBO binding. declared {vertex} in vertex, got {fragment} in fragment")]
MismatchedUniformBuffer { vertex: u32, fragment: u32 }, MismatchedUniformBuffer { vertex: u32, fragment: u32 },
/// The filter chain was found to be non causal. A pass tried to access the target output /// The filter chain was found to be non causal. A pass tried to access the target output
/// in the future. /// in the future.
#[error("filter chain is non causal")] #[error("filter chain is non causal: tried to access target {target} in pass {pass}")]
NonCausalFilterChain { pass: usize, target: usize }, NonCausalFilterChain { pass: usize, target: usize },
/// The offset of the given uniform did not match up in both the vertex and fragment shader. /// The offset of the given uniform did not match up in both the vertex and fragment shader.
#[error("mismatched offset")] #[error("the offset of {semantic} was declared as {expected} but found as {received} in pass {pass}")]
MismatchedOffset { MismatchedOffset {
semantic: String, semantic: String,
expected: usize, expected: usize,
@ -111,7 +111,7 @@ pub enum ShaderReflectError {
pass: usize, pass: usize,
}, },
/// The size of the given uniform did not match up in both the vertex and fragment shader. /// The size of the given uniform did not match up in both the vertex and fragment shader.
#[error("mismatched component")] #[error("the size of {semantic} was found declared as {vertex} in vertex shader but found as {fragment} in fragment in pass {pass}")]
MismatchedSize { MismatchedSize {
semantic: String, semantic: String,
vertex: u32, vertex: u32,
@ -119,15 +119,15 @@ pub enum ShaderReflectError {
pass: usize, pass: usize,
}, },
/// The binding number is already in use. /// The binding number is already in use.
#[error("the binding is already in use")] #[error("binding {0} is already in use")]
BindingInUse(u32), BindingInUse(u32),
/// Error when transpiling from naga /// Error when transpiling from naga
#[cfg(feature = "naga")] #[cfg(feature = "naga")]
#[error("naga-spv")] #[error("naga spirv error: {0}")]
NagaInputError(#[from] naga::front::spv::Error), NagaInputError(#[from] naga::front::spv::Error),
/// Error when transpiling from naga /// Error when transpiling from naga
#[cfg(feature = "naga")] #[cfg(feature = "naga")]
#[error("naga-spv")] #[error("naga validation error: {0}")]
NagaReflectError(#[from] naga::WithSpan<naga::valid::ValidationError>), NagaReflectError(#[from] naga::WithSpan<naga::valid::ValidationError>),
} }

View file

@ -11,7 +11,7 @@ use crate::reflect::semantics::{
MAX_BINDINGS_COUNT, MAX_PUSH_BUFFER_SIZE, MAX_BINDINGS_COUNT, MAX_PUSH_BUFFER_SIZE,
}; };
use crate::reflect::{align_uniform_size, ReflectShader}; use crate::reflect::{align_uniform_size, ReflectShader};
use std::fmt::{Debug}; use std::fmt::Debug;
use std::ops::Deref; use std::ops::Deref;
use spirv_cross::spirv::{Ast, Decoration, Module, Resource, ShaderResources, Type}; use spirv_cross::spirv::{Ast, Decoration, Module, Resource, ShaderResources, Type};

View file

@ -3,7 +3,7 @@ pub mod spirv;
pub mod wgsl; pub mod wgsl;
use crate::error::{SemanticsErrorKind, ShaderReflectError}; use crate::error::{SemanticsErrorKind, ShaderReflectError};
use std::fmt::{Debug}; use std::fmt::Debug;
use crate::front::SpirvCompilation; use crate::front::SpirvCompilation;
use naga::{ use naga::{

View file

@ -140,7 +140,7 @@ where
#[cfg(feature = "github-ci")] #[cfg(feature = "github-ci")]
println!( println!(
"::warning file={},title=Failed to reflect {} with {}::{e}", "::warning file={},title=Failed to reflect {} with {}::{e:?}",
path.display(), path.display(),
O::DEBUG, O::DEBUG,
R::DEBUG R::DEBUG