From 6216177eb4e57f9574aa840da5d87748a0133fdf Mon Sep 17 00:00:00 2001 From: Jay Kwak <82421531+jkwak-work@users.noreply.github.com> Date: Tue, 23 Jul 2024 12:30:12 -0700 Subject: Print SPIRV validation error message (#4697) Closes #4692 This is a quick fix for the issue that SPIR-V validation error message is not printed. A more proper way is to return the error messages to the application and let the application handle it. --- source/slang-glslang/slang-glslang.cpp | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/source/slang-glslang/slang-glslang.cpp b/source/slang-glslang/slang-glslang.cpp index 8ae85b631..d29d22e89 100644 --- a/source/slang-glslang/slang-glslang.cpp +++ b/source/slang-glslang/slang-glslang.cpp @@ -145,6 +145,28 @@ struct SPIRVOptimizationDiagnostic std::string message; }; +// TODO: the actual printing should happen on the application side. +static void validationMessageConsumer(spv_message_level_t level, const char*, + const spv_position_t& position, const char* message) +{ + switch (level) + { + case SPV_MSG_FATAL: + case SPV_MSG_INTERNAL_ERROR: + case SPV_MSG_ERROR: + std::cerr << "error: line " << position.index << ": " << message << std::endl; + break; + case SPV_MSG_WARNING: + std::cout << "warning: line " << position.index << ": " << message << std::endl; + break; + case SPV_MSG_INFO: + std::cout << "info: line " << position.index << ": " << message << std::endl; + break; + default: + break; + } +} + // Validate the given SPIRV-ASM instructions. extern "C" #ifdef _MSC_VER @@ -160,7 +182,7 @@ bool glslang_validateSPIRV(const uint32_t* contents, int contentsSize) options.SetScalarBlockLayout(true); spvtools::SpirvTools tools(target_env); - //tools.SetMessageConsumer(spvtools::utils::CLIMessageConsumer); + tools.SetMessageConsumer(validationMessageConsumer); return tools.Validate(contents, contentsSize, options); } -- cgit v1.2.3