diff --git a/SPIRV/GlslangToSpv.cpp b/SPIRV/GlslangToSpv.cpp index 5055a8d2..2b5333ab 100755 --- a/SPIRV/GlslangToSpv.cpp +++ b/SPIRV/GlslangToSpv.cpp @@ -10036,27 +10036,32 @@ int GetSpirvGeneratorVersion() } // Write SPIR-V out to a binary file -void OutputSpvBin(const std::vector& spirv, const char* baseName) +bool OutputSpvBin(const std::vector& spirv, const char* baseName) { std::ofstream out; out.open(baseName, std::ios::binary | std::ios::out); - if (out.fail()) + if (out.fail()) { printf("ERROR: Failed to open file: %s\n", baseName); + return false; + } for (int i = 0; i < (int)spirv.size(); ++i) { unsigned int word = spirv[i]; out.write((const char*)&word, 4); } out.close(); + return true; } // Write SPIR-V out to a text file with 32-bit hexadecimal words -void OutputSpvHex(const std::vector& spirv, const char* baseName, const char* varName) +bool OutputSpvHex(const std::vector& spirv, const char* baseName, const char* varName) { #if !defined(GLSLANG_WEB) std::ofstream out; out.open(baseName, std::ios::binary | std::ios::out); - if (out.fail()) + if (out.fail()) { printf("ERROR: Failed to open file: %s\n", baseName); + return false; + } out << "\t// " << GetSpirvGeneratorVersion() << GLSLANG_VERSION_MAJOR << "." << GLSLANG_VERSION_MINOR << "." << GLSLANG_VERSION_PATCH << @@ -10083,6 +10088,7 @@ void OutputSpvHex(const std::vector& spirv, const char* baseName, } out.close(); #endif + return true; } // diff --git a/SPIRV/GlslangToSpv.h b/SPIRV/GlslangToSpv.h index 3907be43..b9736d7c 100644 --- a/SPIRV/GlslangToSpv.h +++ b/SPIRV/GlslangToSpv.h @@ -55,7 +55,7 @@ void GlslangToSpv(const glslang::TIntermediate& intermediate, std::vector& spirv, spv::SpvBuildLogger* logger, SpvOptions* options = nullptr); -void OutputSpvBin(const std::vector& spirv, const char* baseName); -void OutputSpvHex(const std::vector& spirv, const char* baseName, const char* varName); +bool OutputSpvBin(const std::vector& spirv, const char* baseName); +bool OutputSpvHex(const std::vector& spirv, const char* baseName, const char* varName); } diff --git a/StandAlone/StandAlone.cpp b/StandAlone/StandAlone.cpp index 064b2082..a4c9fec1 100644 --- a/StandAlone/StandAlone.cpp +++ b/StandAlone/StandAlone.cpp @@ -1526,9 +1526,11 @@ void CompileAndLinkShaderUnits(std::vector compUnits) if (! (Options & EOptionMemoryLeakMode)) { printf("%s", logger.getAllMessages().c_str()); if (Options & EOptionOutputHexadecimal) { - glslang::OutputSpvHex(spirv, GetBinaryName((EShLanguage)stage), variableName); + if (!glslang::OutputSpvHex(spirv, GetBinaryName((EShLanguage)stage), variableName)) + exit(EFailUsage); } else { - glslang::OutputSpvBin(spirv, GetBinaryName((EShLanguage)stage)); + if (!glslang::OutputSpvBin(spirv, GetBinaryName((EShLanguage)stage))) + exit(EFailUsage); } outputFiles.push_back(GetBinaryName((EShLanguage)stage));