Avoid printing to stdout directly in library functions.
Previously GlslangToSpv() reported missing/TBD functionalities by directly writing to stdout using printf. That could cause problems to callers of GlslangToSpv(). This patch cleans up the error reporting logic in GlslangToSpv(), TGlslangToSpvTraverser, and spv::Builder a little bit to use ostringstream. Also fixed the usage of GlslangToSpv() in GTest fixtures to capture warnings/errors reported when translating AST to SPIR-V.
This commit is contained in:
@@ -156,6 +156,7 @@ public:
|
||||
const std::string compilationError;
|
||||
const std::string linkingOutput;
|
||||
const std::string linkingError;
|
||||
const std::string spirvWarningsErrors;
|
||||
const std::string spirv; // Optional SPIR-V disassembly text.
|
||||
};
|
||||
|
||||
@@ -187,20 +188,23 @@ public:
|
||||
program.addShader(&shader);
|
||||
success &= program.link(messages);
|
||||
|
||||
std::string spirvWarningsErrors;
|
||||
|
||||
if (success && target == Target::Spirv) {
|
||||
std::vector<uint32_t> spirv_binary;
|
||||
glslang::GlslangToSpv(*program.getIntermediate(language),
|
||||
spirv_binary);
|
||||
spirv_binary, &spirvWarningsErrors);
|
||||
|
||||
std::ostringstream disassembly_stream;
|
||||
spv::Parameterize();
|
||||
spv::Disassemble(disassembly_stream, spirv_binary);
|
||||
return {shader.getInfoLog(), shader.getInfoDebugLog(),
|
||||
program.getInfoLog(), program.getInfoDebugLog(),
|
||||
disassembly_stream.str()};
|
||||
spirvWarningsErrors, disassembly_stream.str()};
|
||||
} else {
|
||||
return {shader.getInfoLog(), shader.getInfoDebugLog(),
|
||||
program.getInfoLog(), program.getInfoDebugLog(), ""};
|
||||
program.getInfoLog(), program.getInfoDebugLog(),
|
||||
"", ""};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -231,6 +235,7 @@ public:
|
||||
outputIfNotEmpty(result.compilationError);
|
||||
outputIfNotEmpty(result.linkingOutput);
|
||||
outputIfNotEmpty(result.linkingError);
|
||||
stream << result.spirvWarningsErrors;
|
||||
if (target == Target::Spirv) {
|
||||
stream
|
||||
<< (result.spirv.empty()
|
||||
|
||||
Reference in New Issue
Block a user