Merge pull request #3077 from greg-lunarg/edos3

Add EliminateDeadOutputStores to API.
This commit is contained in:
Greg Fischer 2022-11-28 16:27:56 -07:00 committed by GitHub
commit 12bb8602dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 70 additions and 2 deletions

View File

@ -212,8 +212,7 @@ void SpirvToolsTransform(const glslang::TIntermediate& intermediate, std::vector
optimizer.RegisterPass(spvtools::CreateInterpolateFixupPass());
if (options->optimizeSize) {
optimizer.RegisterPass(spvtools::CreateRedundancyEliminationPass());
if (intermediate.getStage() == EShLanguage::EShLangVertex)
optimizer.RegisterPass(spvtools::CreateEliminateDeadInputComponentsPass());
optimizer.RegisterPass(spvtools::CreateEliminateDeadInputComponentsSafePass());
}
optimizer.RegisterPass(spvtools::CreateAggressiveDCEPass());
optimizer.RegisterPass(spvtools::CreateCFGCleanupPass());
@ -224,6 +223,56 @@ void SpirvToolsTransform(const glslang::TIntermediate& intermediate, std::vector
optimizer.Run(spirv.data(), spirv.size(), &spirv, spvOptOptions);
}
bool SpirvToolsAnalyzeDeadOutputStores(spv_target_env target_env, std::vector<unsigned int>& spirv,
std::unordered_set<uint32_t>* live_locs,
std::unordered_set<uint32_t>* live_builtins,
spv::SpvBuildLogger* logger)
{
spvtools::Optimizer optimizer(target_env);
optimizer.SetMessageConsumer(OptimizerMesssageConsumer);
optimizer.RegisterPass(spvtools::CreateAnalyzeLiveInputPass(live_locs, live_builtins));
spvtools::OptimizerOptions spvOptOptions;
optimizer.SetTargetEnv(target_env);
spvOptOptions.set_run_validator(false);
return optimizer.Run(spirv.data(), spirv.size(), &spirv, spvOptOptions);
}
void SpirvToolsEliminateDeadOutputStores(spv_target_env target_env, std::vector<unsigned int>& spirv,
std::unordered_set<uint32_t>* live_locs,
std::unordered_set<uint32_t>* live_builtins,
spv::SpvBuildLogger* logger)
{
spvtools::Optimizer optimizer(target_env);
optimizer.SetMessageConsumer(OptimizerMesssageConsumer);
optimizer.RegisterPass(spvtools::CreateEliminateDeadOutputStoresPass(live_locs, live_builtins));
optimizer.RegisterPass(spvtools::CreateAggressiveDCEPass(false, true));
optimizer.RegisterPass(spvtools::CreateEliminateDeadOutputComponentsPass());
optimizer.RegisterPass(spvtools::CreateAggressiveDCEPass(false, true));
spvtools::OptimizerOptions spvOptOptions;
optimizer.SetTargetEnv(target_env);
spvOptOptions.set_run_validator(false);
optimizer.Run(spirv.data(), spirv.size(), &spirv, spvOptOptions);
}
void SpirvToolsEliminateDeadInputComponents(spv_target_env target_env, std::vector<unsigned int>& spirv,
spv::SpvBuildLogger* logger)
{
spvtools::Optimizer optimizer(target_env);
optimizer.SetMessageConsumer(OptimizerMesssageConsumer);
optimizer.RegisterPass(spvtools::CreateEliminateDeadInputComponentsPass());
optimizer.RegisterPass(spvtools::CreateAggressiveDCEPass());
spvtools::OptimizerOptions spvOptOptions;
optimizer.SetTargetEnv(target_env);
spvOptOptions.set_run_validator(false);
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.

View File

@ -65,6 +65,9 @@ struct SpvOptions {
#if ENABLE_OPT
// Translate glslang's view of target versioning to what SPIRV-Tools uses.
spv_target_env MapToSpirvToolsEnv(const SpvVersion& spvVersion, spv::SpvBuildLogger* logger);
// Use the SPIRV-Tools disassembler to print SPIR-V using a SPV_ENV_UNIVERSAL_1_3 environment.
void SpirvToolsDisassemble(std::ostream& out, const std::vector<unsigned int>& spirv);
@ -80,6 +83,22 @@ void SpirvToolsValidate(const glslang::TIntermediate& intermediate, std::vector<
void SpirvToolsTransform(const glslang::TIntermediate& intermediate, std::vector<unsigned int>& spirv,
spv::SpvBuildLogger*, const SpvOptions*);
// Apply the SPIRV-Tools EliminateDeadInputComponents pass to generated SPIR-V. Put result in |spirv|.
void SpirvToolsEliminateDeadInputComponents(spv_target_env target_env, std::vector<unsigned int>& spirv,
spv::SpvBuildLogger*);
// Apply the SPIRV-Tools AnalyzeDeadOutputStores pass to generated SPIR-V. Put result in |live_locs|.
// Return true if the result is valid.
bool SpirvToolsAnalyzeDeadOutputStores(spv_target_env target_env, std::vector<unsigned int>& spirv,
std::unordered_set<uint32_t>* live_locs,
std::unordered_set<uint32_t>* live_builtins, spv::SpvBuildLogger*);
// Apply the SPIRV-Tools EliminateDeadOutputStores and AggressiveDeadCodeElimination passes to generated SPIR-V using
// |live_locs|. Put result in |spirv|.
void SpirvToolsEliminateDeadOutputStores(spv_target_env target_env, std::vector<unsigned int>& spirv,
std::unordered_set<uint32_t>* live_locs,
std::unordered_set<uint32_t>* live_builtins, spv::SpvBuildLogger*);
// 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.