From f0fd6407aee88b3f59ed961807ed9dace881289c Mon Sep 17 00:00:00 2001 From: Swung0x48 Date: Thu, 20 Aug 2026 05:37:53 -0400 Subject: [PATCH] [Fix] (ShaderTranspiler): keep the demoted viewport-index variable after its private pointer type --- .../SpirvPasses/LowerViewportIndexPass.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/MobileGL/MG_Util/ShaderTranspiler/SpirvPasses/LowerViewportIndexPass.cpp b/MobileGL/MG_Util/ShaderTranspiler/SpirvPasses/LowerViewportIndexPass.cpp index 877ca016..e0074197 100644 --- a/MobileGL/MG_Util/ShaderTranspiler/SpirvPasses/LowerViewportIndexPass.cpp +++ b/MobileGL/MG_Util/ShaderTranspiler/SpirvPasses/LowerViewportIndexPass.cpp @@ -210,6 +210,14 @@ namespace MobileGL { variable->SetResultType(privatePointerTypeId); variable->SetInOperand(0, {static_cast(spv::StorageClass::Private)}); + // FindPointerToType APPENDS a newly minted pointer type to the end of the + // globals section - after this variable - and SPIR-V requires def before use. + // Re-anchor the variable directly after its new type, which is equally correct + // when the type already existed further up. + Instruction* privatePointerType = defUseMgr->GetDef(privatePointerTypeId); + variable->RemoveFromList(); + variable->InsertAfter(privatePointerType); + irContext->KillInst(target.decoration); RemoveFromEntryPointInterfaces(irContext, variableId); ReplaceName(irContext, variableId, kLoweredName);