From 3639186e7e6ae8fb83a46b796f3ca3b896bdc5ae Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Wed, 13 Jan 2021 22:27:08 +0000 Subject: [PATCH] ShaderModule: Include extra information in shader errors If the SPIR-V fails to validate, include the SPIR-V disassembly in the error. If the shader fails to compile, include the shader source in the error. Change-Id: I05f93b5dec7985c42ddf9cd14621af2a855ee640 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/37282 Commit-Queue: Ben Clayton Reviewed-by: Austin Eng --- src/dawn_native/ShaderModule.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/dawn_native/ShaderModule.cpp b/src/dawn_native/ShaderModule.cpp index 98cdfa8ce7..90670af6c7 100644 --- a/src/dawn_native/ShaderModule.cpp +++ b/src/dawn_native/ShaderModule.cpp @@ -166,6 +166,12 @@ namespace dawn_native { }); if (!spirvTools.Validate(code, codeSize)) { + std::string disassembly; + if (spirvTools.Disassemble(std::vector(code, code + codeSize), + &disassembly)) { + errorStream << "disassembly:" << std::endl << disassembly; + } + return DAWN_VALIDATION_ERROR(errorStream.str().c_str()); } @@ -180,7 +186,9 @@ namespace dawn_native { tint::reader::wgsl::Parser parser(file); if (!parser.Parse()) { auto err = tint::diag::Formatter{}.format(parser.diagnostics()); - errorStream << "Parser: " << err << std::endl; + errorStream << "Parser: " << err << std::endl + << "Shader: " << std::endl + << file->content << std::endl; return DAWN_VALIDATION_ERROR(errorStream.str().c_str()); }