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:
Lei Zhang
2016-05-02 18:11:54 -04:00
parent 97f4e0fe19
commit 09caf12bec
6 changed files with 50 additions and 27 deletions

View File

@@ -671,11 +671,13 @@ void CompileAndLinkShaderUnits(std::vector<ShaderCompUnit> compUnits)
for (int stage = 0; stage < EShLangCount; ++stage) {
if (program.getIntermediate((EShLanguage)stage)) {
std::vector<unsigned int> spirv;
glslang::GlslangToSpv(*program.getIntermediate((EShLanguage)stage), spirv);
std::string warningsErrors;
glslang::GlslangToSpv(*program.getIntermediate((EShLanguage)stage), spirv, &warningsErrors);
// Dump the spv to a file or stdout, etc., but only if not doing
// memory/perf testing, as it's not internal to programmatic use.
if (! (Options & EOptionMemoryLeakMode)) {
printf("%s", warningsErrors.c_str());
glslang::OutputSpv(spirv, GetBinaryName((EShLanguage)stage));
if (Options & EOptionHumanReadableSpv) {
spv::Disassemble(std::cout, spirv);