spirv-opt: make traversal deterministic (#5790)

Related to https://github.com/microsoft/DirectXShaderCompiler/issues/6804
This commit is contained in:
Nathan Gauër 2024-09-09 14:59:51 +02:00 committed by GitHub
parent f914d9c8a4
commit 07f49ce65d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -21,6 +21,8 @@ class RemoveUnusedInterfaceVariablesContext {
RemoveUnusedInterfaceVariablesPass& parent_;
Instruction& entry_;
std::unordered_set<uint32_t> used_variables_;
std::vector<uint32_t> operands_to_add_;
IRContext::ProcessFunction pfn_ =
std::bind(&RemoveUnusedInterfaceVariablesContext::processFunction, this,
std::placeholders::_1);
@ -38,8 +40,10 @@ class RemoveUnusedInterfaceVariablesContext {
(parent_.get_module()->version() >=
SPV_SPIRV_VERSION_WORD(1, 4) ||
storage_class == spv::StorageClass::Input ||
storage_class == spv::StorageClass::Output))
storage_class == spv::StorageClass::Output)) {
used_variables_.insert(*id);
operands_to_add_.push_back(*id);
}
});
return false;
}
@ -71,7 +75,7 @@ class RemoveUnusedInterfaceVariablesContext {
void Modify() {
for (int i = entry_.NumInOperands() - 1; i >= 3; --i)
entry_.RemoveInOperand(i);
for (auto id : used_variables_) {
for (auto id : operands_to_add_) {
entry_.AddOperand(Operand(SPV_OPERAND_TYPE_ID, {id}));
}
}