Added -x option to save SPIR-V as 32-bit hexadecimal numbers to a text file.

This commit is contained in:
Johannes van Waveren
2016-05-27 12:55:53 -05:00
parent 5a7f0eff69
commit ecb0f3b75b
3 changed files with 46 additions and 8 deletions

View File

@@ -49,8 +49,10 @@ namespace spv {
#include "../glslang/MachineIndependent/localintermediate.h"
#include "../glslang/MachineIndependent/SymbolTable.h"
#include "../glslang/Include/Common.h"
#include "../glslang/Include/revision.h"
#include <fstream>
#include <iomanip>
#include <list>
#include <map>
#include <stack>
@@ -4311,7 +4313,7 @@ void GetSpirvVersion(std::string& version)
}
// Write SPIR-V out to a binary file
void OutputSpv(const std::vector<unsigned int>& spirv, const char* baseName)
void OutputSpvBin(const std::vector<unsigned int>& spirv, const char* baseName)
{
std::ofstream out;
out.open(baseName, std::ios::binary | std::ios::out);
@@ -4322,6 +4324,27 @@ void OutputSpv(const std::vector<unsigned int>& spirv, const char* baseName)
out.close();
}
// Write SPIR-V out to a text file with 32-bit hexadecimal words
void OutputSpvHex(const std::vector<unsigned int>& spirv, const char* baseName)
{
std::ofstream out;
out.open(baseName, std::ios::binary | std::ios::out);
out << "\t// " GLSLANG_REVISION " " GLSLANG_DATE << std::endl;
const int WORDS_PER_LINE = 8;
for (int i = 0; i < (int)spirv.size(); i += WORDS_PER_LINE) {
out << "\t";
for (int j = 0; j < WORDS_PER_LINE && i + j < (int)spirv.size(); ++j) {
const unsigned int word = spirv[i + j];
out << "0x" << std::hex << std::setw(8) << std::setfill('0') << word;
if (i + j + 1 < (int)spirv.size()) {
out << ",";
}
}
out << std::endl;
}
out.close();
}
//
// Set up the glslang traversal
//

View File

@@ -44,6 +44,7 @@ namespace glslang {
void GetSpirvVersion(std::string&);
void GlslangToSpv(const glslang::TIntermediate& intermediate, std::vector<unsigned int>& spirv);
void GlslangToSpv(const glslang::TIntermediate& intermediate, std::vector<unsigned int>& spirv, spv::SpvBuildLogger* logger);
void OutputSpv(const std::vector<unsigned int>& spirv, const char* baseName);
void OutputSpvBin(const std::vector<unsigned int>& spirv, const char* baseName);
void OutputSpvHex(const std::vector<unsigned int>& spirv, const char* baseName);
}