Skip to content

Commit c715d82

Browse files
Fixed stripping unused inputs in remove_unused_interface_variables_pass for OpenGL
Fixed stripping unused inputs in remove_unused_interface_variables_pass for OpenGL Re-added previous fix for preserve storage Fixed remove_unused_interface_variables_pass removing outputs from fragment shaders
1 parent 3e2b2bf commit c715d82

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

source/opt/aggressive_dead_code_elim_pass.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -612,11 +612,11 @@ void AggressiveDCEPass::InitializeModuleScopeLiveInstructions() {
612612
// without an associated output. Don't remove outputs unless explicitly
613613
// allowed.
614614
// UE Change Begin: Fix to override the stripping of input variables, this should be allowed in the spec, but we rely on this data for some platforms to match inputs/outputs
615-
if (!remove_outputs_) {
616-
if (spv::StorageClass(storage_class) == spv::StorageClass::Input ||
617-
spv::StorageClass(storage_class) == spv::StorageClass::Output) {
618-
AddToWorklist(var);
619-
}
615+
if ((context()->preserve_storage_input() &&
616+
spv::StorageClass(storage_class) == spv::StorageClass::Input) ||
617+
(!remove_outputs_ &&
618+
spv::StorageClass(storage_class) == spv::StorageClass::Output)) {
619+
AddToWorklist(var);
620620
}
621621
// UE Change End: Fix to override the stripping of input variables, this should be allowed in the spec, but we rely on this data for some platforms to match inputs/outputs
622622
}

source/opt/optimizer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ Optimizer& Optimizer::RegisterPerformancePasses(bool preserve_interface) {
230230
.RegisterPass(CreateLocalMultiStoreElimPass())
231231
.RegisterPass(CreateRedundancyEliminationPass())
232232
.RegisterPass(CreateSimplificationPass())
233-
.RegisterPass(CreateAggressiveDCEPass())
233+
.RegisterPass(CreateAggressiveDCEPass(preserve_interface))
234234
.RegisterPass(CreateCFGCleanupPass());
235235
// UE Change End
236236
;

source/opt/remove_unused_interface_variables_pass.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,17 @@ class RemoveUnusedInterfaceVariablesContext {
6363
std::unordered_set<uint32_t> old_variables;
6464
for (int i = entry_.NumInOperands() - 1; i >= 3; --i) {
6565
auto variable = entry_.GetInOperand(i).words[0];
66+
// UE Change Begin: Fix to override the stripping of input variables and fragement outputs, this should be allowed in the spec, but we rely on this data for some platforms to match inputs/outputs
67+
auto* var = parent_.get_def_use_mgr()->GetDef(variable);
68+
69+
bool is_fragment_model = parent_.context()->GetStage() == spv::ExecutionModel::Fragment;
70+
spv::StorageClass storage_class = spv::StorageClass(var->GetSingleWordInOperand(0));
71+
if ((storage_class == spv::StorageClass::Input && parent_.context()->preserve_storage_input()) ||
72+
(storage_class == spv::StorageClass::Output && is_fragment_model))
73+
{
74+
return false;
75+
}
76+
// UE Change End: Fix to override the stripping of input variables and fragement outputs, this should be allowed in the spec, but we rely on this data for some platforms to match inputs/outputs
6677
if (!used_variables_.count(variable)) return true; // It is unused.
6778
if (old_variables.count(variable)) return true; // It is duplicate.
6879
old_variables.insert(variable);

0 commit comments

Comments
 (0)