From 0cdad7bd8ec6d102ad7181dc839f3d97b6002c00 Mon Sep 17 00:00:00 2001 From: Jake Turner Date: Thu, 19 Dec 2024 16:51:11 +0000 Subject: [PATCH] Allocate SSA IDs for DXIL Constants --- renderdoc/driver/shaders/dxil/dxil_bytecode.h | 2 ++ .../driver/shaders/dxil/dxil_disassemble.cpp | 24 +++++++++++++++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/renderdoc/driver/shaders/dxil/dxil_bytecode.h b/renderdoc/driver/shaders/dxil/dxil_bytecode.h index 4902de555..affade05b 100644 --- a/renderdoc/driver/shaders/dxil/dxil_bytecode.h +++ b/renderdoc/driver/shaders/dxil/dxil_bytecode.h @@ -987,6 +987,8 @@ struct Constant : public ForwardReferencableValue rdcstr str; // used during encoding to sort constants by number of uses... uint32_t refCount = 0; + // unique global ID used by the debugger and disassembly similar to Instruction member variable slot + uint32_t ssaId = ~0U; bool isUndef() const { return (flags & 0x1) != 0; } bool isNULL() const { return (flags & 0x2) != 0; } diff --git a/renderdoc/driver/shaders/dxil/dxil_disassemble.cpp b/renderdoc/driver/shaders/dxil/dxil_disassemble.cpp index bc9492660..5a2ea2cff 100644 --- a/renderdoc/driver/shaders/dxil/dxil_disassemble.cpp +++ b/renderdoc/driver/shaders/dxil/dxil_disassemble.cpp @@ -135,7 +135,7 @@ bool ShouldIgnoreSourceMapping(const Instruction &inst) return false; } -// true if the Value is an SSA value i.e. from an instruction, not a constant etc. +// true if the Value has an SSA value i.e. from an instruction, global variable, a constant etc. bool IsSSA(const Value *dxilValue) { if(const Instruction *inst = cast(dxilValue)) @@ -143,7 +143,7 @@ bool IsSSA(const Value *dxilValue) if(const GlobalVar *gv = cast(dxilValue)) return true; if(const Constant *c = cast(dxilValue)) - return false; + return true; if(const Literal *lit = cast(dxilValue)) return false; if(const Block *block = cast(dxilValue)) @@ -164,9 +164,8 @@ DXILDebug::Id GetSSAId(const DXIL::Value *value) if(const GlobalVar *gv = cast(value)) return gv->ssaId; if(const Constant *c = cast(value)) - return DXILDebug::INVALID_ID; + return c->ssaId; - RDCERR("Unhandled DXIL::Value type"); return DXILDebug::INVALID_ID; } @@ -1168,6 +1167,23 @@ void Program::SettleIDs() g->ssaId = m_NextSSAId++; } + // assign SSA ID for constants + for(size_t i = 0; i < m_Functions.size(); i++) + { + Function &func = *m_Functions[i]; + for(Instruction *inst : func.instructions) + { + for(const Value *arg : inst->args) + { + if(arg && arg->kind() == Constant::Kind) + { + Constant *c = (Constant *)arg; + if(c->ssaId == ~0U) + c->ssaId = m_NextSSAId++; + } + } + } + } rdcarray &metaSlots = m_MetaSlots; uint32_t &nextMetaSlot = m_NextMetaSlot; for(size_t i = 0; i < m_Functions.size(); i++)