Add -g0 command line argument
Analogous to gcc, -g0 would strip all debug info. This is done regardless of whether optimizations are enabled. Signed-off-by: Shahbaz Youssefi <ShabbyX@gmail.com>
This commit is contained in:
parent
051c6fed88
commit
d52dce5067
@ -8738,10 +8738,14 @@ void GlslangToSpv(const TIntermediate& intermediate, std::vector<unsigned int>&
|
|||||||
// If from HLSL, run spirv-opt to "legalize" the SPIR-V for Vulkan
|
// If from HLSL, run spirv-opt to "legalize" the SPIR-V for Vulkan
|
||||||
// eg. forward and remove memory writes of opaque types.
|
// eg. forward and remove memory writes of opaque types.
|
||||||
bool prelegalization = intermediate.getSource() == EShSourceHlsl;
|
bool prelegalization = intermediate.getSource() == EShSourceHlsl;
|
||||||
if ((intermediate.getSource() == EShSourceHlsl || options->optimizeSize) && !options->disableOptimizer) {
|
if ((prelegalization || options->optimizeSize) && !options->disableOptimizer) {
|
||||||
SpirvToolsLegalize(intermediate, spirv, logger, options);
|
SpirvToolsTransform(intermediate, spirv, logger, options);
|
||||||
prelegalization = false;
|
prelegalization = false;
|
||||||
}
|
}
|
||||||
|
else if (options->stripDebugInfo) {
|
||||||
|
// Strip debug info even if optimization is disabled.
|
||||||
|
SpirvToolsStripDebugInfo(intermediate, spirv, logger);
|
||||||
|
}
|
||||||
|
|
||||||
if (options->validate)
|
if (options->validate)
|
||||||
SpirvToolsValidate(intermediate, spirv, logger, prelegalization);
|
SpirvToolsValidate(intermediate, spirv, logger, prelegalization);
|
||||||
|
@ -80,6 +80,39 @@ spv_target_env MapToSpirvToolsEnv(const SpvVersion& spvVersion, spv::SpvBuildLog
|
|||||||
return spv_target_env::SPV_ENV_UNIVERSAL_1_0;
|
return spv_target_env::SPV_ENV_UNIVERSAL_1_0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Callback passed to spvtools::Optimizer::SetMessageConsumer
|
||||||
|
void OptimizerMesssageConsumer(spv_message_level_t level, const char *source,
|
||||||
|
const spv_position_t &position, const char *message)
|
||||||
|
{
|
||||||
|
auto &out = std::cerr;
|
||||||
|
switch (level)
|
||||||
|
{
|
||||||
|
case SPV_MSG_FATAL:
|
||||||
|
case SPV_MSG_INTERNAL_ERROR:
|
||||||
|
case SPV_MSG_ERROR:
|
||||||
|
out << "error: ";
|
||||||
|
break;
|
||||||
|
case SPV_MSG_WARNING:
|
||||||
|
out << "warning: ";
|
||||||
|
break;
|
||||||
|
case SPV_MSG_INFO:
|
||||||
|
case SPV_MSG_DEBUG:
|
||||||
|
out << "info: ";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (source)
|
||||||
|
{
|
||||||
|
out << source << ":";
|
||||||
|
}
|
||||||
|
out << position.line << ":" << position.column << ":" << position.index << ":";
|
||||||
|
if (message)
|
||||||
|
{
|
||||||
|
out << " " << message;
|
||||||
|
}
|
||||||
|
out << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
// Use the SPIRV-Tools disassembler to print SPIR-V.
|
// Use the SPIRV-Tools disassembler to print SPIR-V.
|
||||||
void SpirvToolsDisassemble(std::ostream& out, const std::vector<unsigned int>& spirv)
|
void SpirvToolsDisassemble(std::ostream& out, const std::vector<unsigned int>& spirv)
|
||||||
@ -128,45 +161,14 @@ void SpirvToolsValidate(const glslang::TIntermediate& intermediate, std::vector<
|
|||||||
spvContextDestroy(context);
|
spvContextDestroy(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply the SPIRV-Tools optimizer to generated SPIR-V, for the purpose of
|
// Apply the SPIRV-Tools optimizer to generated SPIR-V. HLSL SPIR-V is legalized in the process.
|
||||||
// legalizing HLSL SPIR-V.
|
void SpirvToolsTransform(const glslang::TIntermediate& intermediate, std::vector<unsigned int>& spirv,
|
||||||
void SpirvToolsLegalize(const glslang::TIntermediate& intermediate, std::vector<unsigned int>& spirv,
|
spv::SpvBuildLogger* logger, const SpvOptions* options)
|
||||||
spv::SpvBuildLogger* logger, const SpvOptions* options)
|
|
||||||
{
|
{
|
||||||
spv_target_env target_env = SPV_ENV_UNIVERSAL_1_2;
|
spv_target_env target_env = SPV_ENV_UNIVERSAL_1_2;
|
||||||
|
|
||||||
spvtools::Optimizer optimizer(target_env);
|
spvtools::Optimizer optimizer(target_env);
|
||||||
optimizer.SetMessageConsumer(
|
optimizer.SetMessageConsumer(OptimizerMesssageConsumer);
|
||||||
[](spv_message_level_t level, const char *source, const spv_position_t &position, const char *message) {
|
|
||||||
auto &out = std::cerr;
|
|
||||||
switch (level)
|
|
||||||
{
|
|
||||||
case SPV_MSG_FATAL:
|
|
||||||
case SPV_MSG_INTERNAL_ERROR:
|
|
||||||
case SPV_MSG_ERROR:
|
|
||||||
out << "error: ";
|
|
||||||
break;
|
|
||||||
case SPV_MSG_WARNING:
|
|
||||||
out << "warning: ";
|
|
||||||
break;
|
|
||||||
case SPV_MSG_INFO:
|
|
||||||
case SPV_MSG_DEBUG:
|
|
||||||
out << "info: ";
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (source)
|
|
||||||
{
|
|
||||||
out << source << ":";
|
|
||||||
}
|
|
||||||
out << position.line << ":" << position.column << ":" << position.index << ":";
|
|
||||||
if (message)
|
|
||||||
{
|
|
||||||
out << " " << message;
|
|
||||||
}
|
|
||||||
out << std::endl;
|
|
||||||
});
|
|
||||||
|
|
||||||
// If debug (specifically source line info) is being generated, propagate
|
// If debug (specifically source line info) is being generated, propagate
|
||||||
// line information into all SPIR-V instructions. This avoids loss of
|
// line information into all SPIR-V instructions. This avoids loss of
|
||||||
@ -175,6 +177,9 @@ void SpirvToolsLegalize(const glslang::TIntermediate& intermediate, std::vector<
|
|||||||
if (options->generateDebugInfo) {
|
if (options->generateDebugInfo) {
|
||||||
optimizer.RegisterPass(spvtools::CreatePropagateLineInfoPass());
|
optimizer.RegisterPass(spvtools::CreatePropagateLineInfoPass());
|
||||||
}
|
}
|
||||||
|
else if (options->stripDebugInfo) {
|
||||||
|
optimizer.RegisterPass(spvtools::CreateStripDebugInfoPass());
|
||||||
|
}
|
||||||
optimizer.RegisterPass(spvtools::CreateWrapOpKillPass());
|
optimizer.RegisterPass(spvtools::CreateWrapOpKillPass());
|
||||||
optimizer.RegisterPass(spvtools::CreateDeadBranchElimPass());
|
optimizer.RegisterPass(spvtools::CreateDeadBranchElimPass());
|
||||||
optimizer.RegisterPass(spvtools::CreateMergeReturnPass());
|
optimizer.RegisterPass(spvtools::CreateMergeReturnPass());
|
||||||
@ -212,6 +217,25 @@ void SpirvToolsLegalize(const glslang::TIntermediate& intermediate, std::vector<
|
|||||||
optimizer.Run(spirv.data(), spirv.size(), &spirv, spvOptOptions);
|
optimizer.Run(spirv.data(), spirv.size(), &spirv, spvOptOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Apply the SPIRV-Tools optimizer to strip debug info from SPIR-V. This is implicitly done by
|
||||||
|
// SpirvToolsTransform if spvOptions->stripDebugInfo is set, but can be called separately if
|
||||||
|
// optimization is disabled.
|
||||||
|
void SpirvToolsStripDebugInfo(const glslang::TIntermediate& intermediate,
|
||||||
|
std::vector<unsigned int>& spirv, spv::SpvBuildLogger* logger)
|
||||||
|
{
|
||||||
|
spv_target_env target_env = SPV_ENV_UNIVERSAL_1_2;
|
||||||
|
|
||||||
|
spvtools::Optimizer optimizer(target_env);
|
||||||
|
optimizer.SetMessageConsumer(OptimizerMesssageConsumer);
|
||||||
|
|
||||||
|
optimizer.RegisterPass(spvtools::CreateStripDebugInfoPass());
|
||||||
|
|
||||||
|
spvtools::OptimizerOptions spvOptOptions;
|
||||||
|
optimizer.SetTargetEnv(MapToSpirvToolsEnv(intermediate.getSpv(), logger));
|
||||||
|
spvOptOptions.set_run_validator(false); // The validator may run as a separate step later on
|
||||||
|
optimizer.Run(spirv.data(), spirv.size(), &spirv, spvOptOptions);
|
||||||
|
}
|
||||||
|
|
||||||
}; // end namespace glslang
|
}; // end namespace glslang
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -52,9 +52,10 @@
|
|||||||
namespace glslang {
|
namespace glslang {
|
||||||
|
|
||||||
struct SpvOptions {
|
struct SpvOptions {
|
||||||
SpvOptions() : generateDebugInfo(false), disableOptimizer(true),
|
SpvOptions() : generateDebugInfo(false), stripDebugInfo(false), disableOptimizer(true),
|
||||||
optimizeSize(false), disassemble(false), validate(false) { }
|
optimizeSize(false), disassemble(false), validate(false) { }
|
||||||
bool generateDebugInfo;
|
bool generateDebugInfo;
|
||||||
|
bool stripDebugInfo;
|
||||||
bool disableOptimizer;
|
bool disableOptimizer;
|
||||||
bool optimizeSize;
|
bool optimizeSize;
|
||||||
bool disassemble;
|
bool disassemble;
|
||||||
@ -70,10 +71,15 @@ void SpirvToolsDisassemble(std::ostream& out, const std::vector<unsigned int>& s
|
|||||||
void SpirvToolsValidate(const glslang::TIntermediate& intermediate, std::vector<unsigned int>& spirv,
|
void SpirvToolsValidate(const glslang::TIntermediate& intermediate, std::vector<unsigned int>& spirv,
|
||||||
spv::SpvBuildLogger*, bool prelegalization);
|
spv::SpvBuildLogger*, bool prelegalization);
|
||||||
|
|
||||||
// Apply the SPIRV-Tools optimizer to generated SPIR-V, for the purpose of
|
// Apply the SPIRV-Tools optimizer to generated SPIR-V. HLSL SPIR-V is legalized in the process.
|
||||||
// legalizing HLSL SPIR-V.
|
void SpirvToolsTransform(const glslang::TIntermediate& intermediate, std::vector<unsigned int>& spirv,
|
||||||
void SpirvToolsLegalize(const glslang::TIntermediate& intermediate, std::vector<unsigned int>& spirv,
|
spv::SpvBuildLogger*, const SpvOptions*);
|
||||||
spv::SpvBuildLogger*, const SpvOptions*);
|
|
||||||
|
// Apply the SPIRV-Tools optimizer to strip debug info from SPIR-V. This is implicitly done by
|
||||||
|
// SpirvToolsTransform if spvOptions->stripDebugInfo is set, but can be called separately if
|
||||||
|
// optimization is disabled.
|
||||||
|
void SpirvToolsStripDebugInfo(const glslang::TIntermediate& intermediate,
|
||||||
|
std::vector<unsigned int>& spirv, spv::SpvBuildLogger*);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -106,6 +106,7 @@ bool targetHlslFunctionality1 = false;
|
|||||||
bool SpvToolsDisassembler = false;
|
bool SpvToolsDisassembler = false;
|
||||||
bool SpvToolsValidate = false;
|
bool SpvToolsValidate = false;
|
||||||
bool NaNClamp = false;
|
bool NaNClamp = false;
|
||||||
|
bool stripDebugInfo = false;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Return codes from main/exit().
|
// Return codes from main/exit().
|
||||||
@ -750,7 +751,13 @@ void ProcessArguments(std::vector<std::unique_ptr<glslang::TWorkItem>>& workItem
|
|||||||
Error("-f: expected hlsl_functionality1");
|
Error("-f: expected hlsl_functionality1");
|
||||||
break;
|
break;
|
||||||
case 'g':
|
case 'g':
|
||||||
Options |= EOptionDebug;
|
// Override previous -g or -g0 argument
|
||||||
|
stripDebugInfo = false;
|
||||||
|
Options &= ~EOptionDebug;
|
||||||
|
if (argv[0][2] == '0')
|
||||||
|
stripDebugInfo = true;
|
||||||
|
else
|
||||||
|
Options |= EOptionDebug;
|
||||||
break;
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
usage();
|
usage();
|
||||||
@ -1150,6 +1157,8 @@ void CompileAndLinkShaderUnits(std::vector<ShaderCompUnit> compUnits)
|
|||||||
glslang::SpvOptions spvOptions;
|
glslang::SpvOptions spvOptions;
|
||||||
if (Options & EOptionDebug)
|
if (Options & EOptionDebug)
|
||||||
spvOptions.generateDebugInfo = true;
|
spvOptions.generateDebugInfo = true;
|
||||||
|
else if (stripDebugInfo)
|
||||||
|
spvOptions.stripDebugInfo = true;
|
||||||
spvOptions.disableOptimizer = (Options & EOptionOptimizeDisable) != 0;
|
spvOptions.disableOptimizer = (Options & EOptionOptimizeDisable) != 0;
|
||||||
spvOptions.optimizeSize = (Options & EOptionOptimizeSize) != 0;
|
spvOptions.optimizeSize = (Options & EOptionOptimizeSize) != 0;
|
||||||
spvOptions.disassemble = SpvToolsDisassembler;
|
spvOptions.disassemble = SpvToolsDisassembler;
|
||||||
@ -1568,6 +1577,7 @@ void usage()
|
|||||||
" 'hlsl_functionality1' enables use of the\n"
|
" 'hlsl_functionality1' enables use of the\n"
|
||||||
" SPV_GOOGLE_hlsl_functionality1 extension\n"
|
" SPV_GOOGLE_hlsl_functionality1 extension\n"
|
||||||
" -g generate debug information\n"
|
" -g generate debug information\n"
|
||||||
|
" -g0 strip debug information\n"
|
||||||
" -h print this usage message\n"
|
" -h print this usage message\n"
|
||||||
" -i intermediate tree (glslang AST) is printed out\n"
|
" -i intermediate tree (glslang AST) is printed out\n"
|
||||||
" -l link all input files together to form a single module\n"
|
" -l link all input files together to form a single module\n"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user