mirror of
https://github.com/KhronosGroup/SPIRV-Tools
synced 2024-10-18 11:10:05 +00:00
spirv-opt: make traversal deterministic (#5790)
Related to https://github.com/microsoft/DirectXShaderCompiler/issues/6804
This commit is contained in:
parent
f914d9c8a4
commit
07f49ce65d
@ -21,6 +21,8 @@ class RemoveUnusedInterfaceVariablesContext {
|
|||||||
RemoveUnusedInterfaceVariablesPass& parent_;
|
RemoveUnusedInterfaceVariablesPass& parent_;
|
||||||
Instruction& entry_;
|
Instruction& entry_;
|
||||||
std::unordered_set<uint32_t> used_variables_;
|
std::unordered_set<uint32_t> used_variables_;
|
||||||
|
std::vector<uint32_t> operands_to_add_;
|
||||||
|
|
||||||
IRContext::ProcessFunction pfn_ =
|
IRContext::ProcessFunction pfn_ =
|
||||||
std::bind(&RemoveUnusedInterfaceVariablesContext::processFunction, this,
|
std::bind(&RemoveUnusedInterfaceVariablesContext::processFunction, this,
|
||||||
std::placeholders::_1);
|
std::placeholders::_1);
|
||||||
@ -38,8 +40,10 @@ class RemoveUnusedInterfaceVariablesContext {
|
|||||||
(parent_.get_module()->version() >=
|
(parent_.get_module()->version() >=
|
||||||
SPV_SPIRV_VERSION_WORD(1, 4) ||
|
SPV_SPIRV_VERSION_WORD(1, 4) ||
|
||||||
storage_class == spv::StorageClass::Input ||
|
storage_class == spv::StorageClass::Input ||
|
||||||
storage_class == spv::StorageClass::Output))
|
storage_class == spv::StorageClass::Output)) {
|
||||||
used_variables_.insert(*id);
|
used_variables_.insert(*id);
|
||||||
|
operands_to_add_.push_back(*id);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -71,7 +75,7 @@ class RemoveUnusedInterfaceVariablesContext {
|
|||||||
void Modify() {
|
void Modify() {
|
||||||
for (int i = entry_.NumInOperands() - 1; i >= 3; --i)
|
for (int i = entry_.NumInOperands() - 1; i >= 3; --i)
|
||||||
entry_.RemoveInOperand(i);
|
entry_.RemoveInOperand(i);
|
||||||
for (auto id : used_variables_) {
|
for (auto id : operands_to_add_) {
|
||||||
entry_.AddOperand(Operand(SPV_OPERAND_TYPE_ID, {id}));
|
entry_.AddOperand(Operand(SPV_OPERAND_TYPE_ID, {id}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user