fix shader compilation error reporting for non-wgsl shaders (#3441)

in #3289 I accidentally only logged errors for wgsl shaders, this PR expands the error reporting the the other supported shader types.
This commit is contained in:
Jakob Hellermann 2021-12-29 21:04:27 +00:00
parent d07c8a8fa7
commit 66b517ef81

View file

@ -407,46 +407,86 @@ impl RenderPipelineCache {
} }
} }
fn log_shader_error(source: &ProcessedShader, err: &AsModuleDescriptorError) { fn log_shader_error(source: &ProcessedShader, error: &AsModuleDescriptorError) {
use codespan_reporting::{ use codespan_reporting::{
diagnostic::{Diagnostic, Label}, diagnostic::{Diagnostic, Label},
files::SimpleFile, files::SimpleFile,
term, term,
}; };
if let ProcessedShader::Wgsl(source) = source { match error {
if let AsModuleDescriptorError::ShaderReflectError(err) = err { AsModuleDescriptorError::ShaderReflectError(error) => match error {
match err { ShaderReflectError::WgslParse(error) => {
ShaderReflectError::WgslParse(parse) => { let source = source
let msg = parse.emit_to_string(source); .get_wgsl_source()
error!("failed to process shader:\n{}", msg); .expect("non-wgsl source for wgsl error");
} let msg = error.emit_to_string(source);
ShaderReflectError::Validation(error) => { error!("failed to process shader:\n{}", msg);
let files = SimpleFile::new("wgsl", &source); }
let config = term::Config::default(); ShaderReflectError::GlslParse(errors) => {
let mut writer = term::termcolor::Ansi::new(Vec::new()); let source = source
.get_glsl_source()
.expect("non-glsl source for glsl error");
let files = SimpleFile::new("glsl", source);
let config = codespan_reporting::term::Config::default();
let mut writer = term::termcolor::Ansi::new(Vec::new());
let diagnostic = Diagnostic::error().with_labels( for err in errors {
error let mut diagnostic = Diagnostic::error().with_message(err.kind.to_string());
.spans()
.map(|(span, desc)| { if let Some(range) = err.meta.to_range() {
Label::primary((), span.to_range().unwrap()) diagnostic = diagnostic.with_labels(vec![Label::primary((), range)]);
.with_message(desc.to_owned()) }
})
.collect(),
);
term::emit(&mut writer, &config, &files, &diagnostic) term::emit(&mut writer, &config, &files, &diagnostic)
.expect("cannot write error"); .expect("cannot write error");
let msg = writer.into_inner();
let msg = String::from_utf8_lossy(&msg);
error!("failed to process shader: \n{}", msg);
} }
ShaderReflectError::GlslParse(_) => {}
ShaderReflectError::SpirVParse(_) => {} let msg = writer.into_inner();
let msg = String::from_utf8_lossy(&msg);
error!("failed to process shader: \n{}", msg);
} }
ShaderReflectError::SpirVParse(error) => {
error!("failed to process shader:\n{}", error);
}
ShaderReflectError::Validation(error) => {
let (filename, source) = match source {
ProcessedShader::Wgsl(source) => ("wgsl", source.as_ref()),
ProcessedShader::Glsl(source, _) => ("glsl", source.as_ref()),
ProcessedShader::SpirV(_) => {
error!("failed to process shader:\n{}", error);
return;
}
};
let files = SimpleFile::new(filename, source);
let config = term::Config::default();
let mut writer = term::termcolor::Ansi::new(Vec::new());
let diagnostic = Diagnostic::error().with_labels(
error
.spans()
.map(|(span, desc)| {
Label::primary((), span.to_range().unwrap())
.with_message(desc.to_owned())
})
.collect(),
);
term::emit(&mut writer, &config, &files, &diagnostic).expect("cannot write error");
let msg = writer.into_inner();
let msg = String::from_utf8_lossy(&msg);
error!("failed to process shader: \n{}", msg);
}
},
AsModuleDescriptorError::WgslConversion(error) => {
error!("failed to convert shader to wgsl: \n{}", error);
}
AsModuleDescriptorError::SpirVConversion(error) => {
error!("failed to convert shader to spirv: \n{}", error);
} }
} }
} }