Shaderc console out (#2758)

* Add support to output compiled shader to stdout

* Whitespace formating fixes

* Updated shaderc cli stdout output option to "--stdout"
This commit is contained in:
Catalin Moldovan 2022-04-04 22:52:44 +03:00 committed by GitHub
parent cb857c3cd3
commit 11ba8de2d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 26 additions and 18 deletions

View File

@ -1007,6 +1007,7 @@ namespace bgfx
" -f <file path> Input file path.\n" " -f <file path> Input file path.\n"
" -i <include path> Include path (for multiple paths use -i multiple times).\n" " -i <include path> Include path (for multiple paths use -i multiple times).\n"
" -o <file path> Output file path.\n" " -o <file path> Output file path.\n"
" --stdout Output to console.\n"
" --bin2c [array name] Generate C header file. If array name is not specified base file name will be used as name.\n" " --bin2c [array name] Generate C header file. If array name is not specified base file name will be used as name.\n"
" --depends Generate makefile style depends file.\n" " --depends Generate makefile style depends file.\n"
" --platform <platform> Target platform.\n" " --platform <platform> Target platform.\n"
@ -1068,7 +1069,7 @@ namespace bgfx
return word; return word;
} }
bool compileShader(const char* _varying, const char* _comment, char* _shader, uint32_t _shaderLen, Options& _options, bx::FileWriter* _writer) bool compileShader(const char* _varying, const char* _comment, char* _shader, uint32_t _shaderLen, Options& _options, bx::WriterI* _writer)
{ {
uint32_t profile_id = 0; uint32_t profile_id = 0;
@ -2633,10 +2634,11 @@ namespace bgfx
return bx::kExitFailure; return bx::kExitFailure;
} }
bool consoleOut = cmdLine.hasArg("stdout");
const char* outFilePath = cmdLine.findOption('o'); const char* outFilePath = cmdLine.findOption('o');
if (NULL == outFilePath) if (NULL == outFilePath && !consoleOut)
{ {
help("Output file name must be specified."); help("Output file name must be specified or use \"--stdout\" to output to stdout.");
return bx::kExitFailure; return bx::kExitFailure;
} }
@ -2649,7 +2651,7 @@ namespace bgfx
Options options; Options options;
options.inputFilePath = filePath; options.inputFilePath = filePath;
options.outputFilePath = outFilePath; options.outputFilePath = consoleOut ? "" : outFilePath;
options.shaderType = bx::toLower(type[0]); options.shaderType = bx::toLower(type[0]);
options.disasm = cmdLine.hasArg('\0', "disasm"); options.disasm = cmdLine.hasArg('\0', "disasm");
@ -2815,25 +2817,31 @@ namespace bgfx
bx::FileWriter* writer = NULL; bx::FileWriter* writer = NULL;
if (!bin2c.isEmpty() ) if (!consoleOut)
{ {
writer = new Bin2cWriter(bin2c); if (!bin2c.isEmpty())
} {
else writer = new Bin2cWriter(bin2c);
{ }
writer = new bx::FileWriter; else
{
writer = new bx::FileWriter;
}
if (!bx::open(writer, outFilePath))
{
bx::printf("Unable to open output file '%s'.\n", outFilePath);
return bx::kExitFailure;
}
} }
if (!bx::open(writer, outFilePath) ) compiled = compileShader(varying, commandLineComment.c_str(), data, size, options, consoleOut ? bx::getStdOut() : writer);
if (!consoleOut)
{ {
bx::printf("Unable to open output file '%s'.\n", outFilePath); bx::close(writer);
return bx::kExitFailure; delete writer;
} }
compiled = compileShader(varying, commandLineComment.c_str(), data, size, options, writer);
bx::close(writer);
delete writer;
} }
if (compiled) if (compiled)