[Fix] (MG_Util/ShaderTranspiler): keep decomposed workgroup types before globals

This commit is contained in:
2026-07-06 03:58:26 +08:00
parent d35e452368
commit 0bee379b61
2 changed files with 46 additions and 2 deletions
@@ -13,6 +13,7 @@
#include "source/opt/instruction.h"
#include "source/opt/ir_context.h"
#include "source/opt/module.h"
#include "source/opt/reflect.h"
#include "source/opt/type_manager.h"
#include "spirv.hpp"
@@ -308,6 +309,39 @@ namespace MobileGL {
assert(false && "DecomposeWorkgroupVec3Pass: unsupported composite store type");
}
void MoveLateTypesConstantsBeforeGlobalVariables(IRContext* context) {
Instruction* firstVariable = nullptr;
for (Instruction& inst : context->module()->types_values()) {
if (inst.opcode() == spv::Op::OpVariable) {
firstVariable = &inst;
break;
}
}
if (firstVariable == nullptr) {
return;
}
bool sawFirstVariable = false;
for (auto it = context->module()->types_values_begin();
it != context->module()->types_values_end();) {
Instruction* inst = &*it;
++it;
if (inst == firstVariable) {
sawFirstVariable = true;
continue;
}
if (sawFirstVariable &&
(spvtools::opt::IsTypeInst(inst->opcode()) ||
spvtools::opt::IsConstantInst(inst->opcode()) ||
inst->opcode() == spv::Op::OpUndef)) {
inst->InsertBefore(firstVariable);
}
}
}
} // namespace
spvtools::opt::Pass::Status DecomposeWorkgroupVec3Pass::Process() {
@@ -605,6 +639,8 @@ namespace MobileGL {
}
}
MoveLateTypesConstantsBeforeGlobalVariables(ctx);
return Status::SuccessWithChange;
}