Merge pull request #720 from flaviobortot/master
Added --vn option to generate a C header file containing a variable a…
This commit is contained in:
commit
b0561d934c
3 changed files with 25 additions and 4 deletions
|
|
@ -5327,11 +5327,15 @@ void OutputSpvBin(const std::vector<unsigned int>& spirv, const char* baseName)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write SPIR-V out to a text file with 32-bit hexadecimal words
|
// Write SPIR-V out to a text file with 32-bit hexadecimal words
|
||||||
void OutputSpvHex(const std::vector<unsigned int>& spirv, const char* baseName)
|
void OutputSpvHex(const std::vector<unsigned int>& spirv, const char* baseName, const char* varName)
|
||||||
{
|
{
|
||||||
std::ofstream out;
|
std::ofstream out;
|
||||||
out.open(baseName, std::ios::binary | std::ios::out);
|
out.open(baseName, std::ios::binary | std::ios::out);
|
||||||
out << "\t// " GLSLANG_REVISION " " GLSLANG_DATE << std::endl;
|
out << "\t// " GLSLANG_REVISION " " GLSLANG_DATE << std::endl;
|
||||||
|
if (varName != nullptr) {
|
||||||
|
out << "\t #pragma once" << std::endl;
|
||||||
|
out << "const uint32_t " << varName << "[] = {" << std::endl;
|
||||||
|
}
|
||||||
const int WORDS_PER_LINE = 8;
|
const int WORDS_PER_LINE = 8;
|
||||||
for (int i = 0; i < (int)spirv.size(); i += WORDS_PER_LINE) {
|
for (int i = 0; i < (int)spirv.size(); i += WORDS_PER_LINE) {
|
||||||
out << "\t";
|
out << "\t";
|
||||||
|
|
@ -5344,6 +5348,9 @@ void OutputSpvHex(const std::vector<unsigned int>& spirv, const char* baseName)
|
||||||
}
|
}
|
||||||
out << std::endl;
|
out << std::endl;
|
||||||
}
|
}
|
||||||
|
if (varName != nullptr) {
|
||||||
|
out << "};";
|
||||||
|
}
|
||||||
out.close();
|
out.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,6 @@ 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);
|
||||||
void GlslangToSpv(const glslang::TIntermediate& intermediate, std::vector<unsigned int>& spirv, spv::SpvBuildLogger* logger);
|
void GlslangToSpv(const glslang::TIntermediate& intermediate, std::vector<unsigned int>& spirv, spv::SpvBuildLogger* logger);
|
||||||
void OutputSpvBin(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);
|
void OutputSpvHex(const std::vector<unsigned int>& spirv, const char* baseName, const char* varName);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -163,6 +163,7 @@ const char* binaryFileName = nullptr;
|
||||||
const char* entryPointName = nullptr;
|
const char* entryPointName = nullptr;
|
||||||
const char* sourceEntryPointName = nullptr;
|
const char* sourceEntryPointName = nullptr;
|
||||||
const char* shaderStageName = nullptr;
|
const char* shaderStageName = nullptr;
|
||||||
|
const char* variableName = nullptr;
|
||||||
|
|
||||||
std::array<unsigned int, EShLangCount> baseSamplerBinding;
|
std::array<unsigned int, EShLangCount> baseSamplerBinding;
|
||||||
std::array<unsigned int, EShLangCount> baseTextureBinding;
|
std::array<unsigned int, EShLangCount> baseTextureBinding;
|
||||||
|
|
@ -302,7 +303,18 @@ void ProcessArguments(int argc, char* argv[])
|
||||||
} else if (lowerword == "no-storage-format" || // synonyms
|
} else if (lowerword == "no-storage-format" || // synonyms
|
||||||
lowerword == "nsf") {
|
lowerword == "nsf") {
|
||||||
Options |= EOptionNoStorageFormat;
|
Options |= EOptionNoStorageFormat;
|
||||||
} else if (lowerword == "source-entrypoint" || // synonyms
|
} else if (lowerword == "variable-name" || // synonyms
|
||||||
|
lowerword == "vn") {
|
||||||
|
Options |= EOptionOutputHexadecimal;
|
||||||
|
variableName = argv[1];
|
||||||
|
if (argc > 0) {
|
||||||
|
argc--;
|
||||||
|
argv++;
|
||||||
|
} else
|
||||||
|
Error("no <C-variable-name> provided for --variable-name");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if (lowerword == "source-entrypoint" || // synonyms
|
||||||
lowerword == "sep") {
|
lowerword == "sep") {
|
||||||
sourceEntryPointName = argv[1];
|
sourceEntryPointName = argv[1];
|
||||||
if (argc > 0) {
|
if (argc > 0) {
|
||||||
|
|
@ -650,7 +662,7 @@ void CompileAndLinkShaderUnits(std::vector<ShaderCompUnit> compUnits)
|
||||||
if (! (Options & EOptionMemoryLeakMode)) {
|
if (! (Options & EOptionMemoryLeakMode)) {
|
||||||
printf("%s", logger.getAllMessages().c_str());
|
printf("%s", logger.getAllMessages().c_str());
|
||||||
if (Options & EOptionOutputHexadecimal) {
|
if (Options & EOptionOutputHexadecimal) {
|
||||||
glslang::OutputSpvHex(spirv, GetBinaryName((EShLanguage)stage));
|
glslang::OutputSpvHex(spirv, GetBinaryName((EShLanguage)stage), variableName);
|
||||||
} else {
|
} else {
|
||||||
glslang::OutputSpvBin(spirv, GetBinaryName((EShLanguage)stage));
|
glslang::OutputSpvBin(spirv, GetBinaryName((EShLanguage)stage));
|
||||||
}
|
}
|
||||||
|
|
@ -987,6 +999,8 @@ void usage()
|
||||||
"\n"
|
"\n"
|
||||||
" --keep-uncalled don't eliminate uncalled functions when linking\n"
|
" --keep-uncalled don't eliminate uncalled functions when linking\n"
|
||||||
" --ku synonym for --keep-uncalled\n"
|
" --ku synonym for --keep-uncalled\n"
|
||||||
|
" --variable-name <name> Creates a C header file that contains a uint32_t array named <name> initialized with the shader binary code.\n"
|
||||||
|
" --vn <name> synonym for --variable-name <name>.\n"
|
||||||
);
|
);
|
||||||
|
|
||||||
exit(EFailUsage);
|
exit(EFailUsage);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue