From f2f07cbc74778681fd8797bd4564abfdf811424c Mon Sep 17 00:00:00 2001 From: Jake Turner Date: Mon, 29 Jul 2024 15:47:20 +0100 Subject: [PATCH] DXIL Disassembly moved global SSA ID to be part of SettleIDs Removed it from Accumulator::processFunction() --- .../driver/shaders/dxil/dxil_bytecode.cpp | 13 ++----- renderdoc/driver/shaders/dxil/dxil_bytecode.h | 2 +- .../shaders/dxil/dxil_bytecode_editor.cpp | 12 ++----- .../driver/shaders/dxil/dxil_disassemble.cpp | 35 +++++++++++++++++-- 4 files changed, 39 insertions(+), 23 deletions(-) diff --git a/renderdoc/driver/shaders/dxil/dxil_bytecode.cpp b/renderdoc/driver/shaders/dxil/dxil_bytecode.cpp index 3b0299318..75c8694bb 100644 --- a/renderdoc/driver/shaders/dxil/dxil_bytecode.cpp +++ b/renderdoc/driver/shaders/dxil/dxil_bytecode.cpp @@ -2580,7 +2580,7 @@ void LLVMOrderAccumulator::processGlobals(Program *prog, bool doLiveChecking) } } -void LLVMOrderAccumulator::processFunction(const Function *f, uint32_t *nextSSAId) +void LLVMOrderAccumulator::processFunction(const Function *f) { const Function &func = *f; @@ -2636,11 +2636,7 @@ void LLVMOrderAccumulator::processFunction(const Function *f, uint32_t *nextSSAI { #if DISABLED(DXC_COMPATIBLE_DISASM) if(arg->slot == ~0U) - { - RDCASSERT(!nextSSAId); - arg->slot = *nextSSAId; - (*nextSSAId)++; - } + arg->slot = slot++; #else if(arg->getName().isEmpty()) arg->slot = slot++; @@ -2671,10 +2667,7 @@ void LLVMOrderAccumulator::processFunction(const Function *f, uint32_t *nextSSAI #if DISABLED(DXC_COMPATIBLE_DISASM) if(inst->slot == ~0U) - { - inst->slot = *nextSSAId; - (*nextSSAId)++; - } + inst->slot = slot++; #else if(inst->getName().isEmpty()) inst->slot = slot++; diff --git a/renderdoc/driver/shaders/dxil/dxil_bytecode.h b/renderdoc/driver/shaders/dxil/dxil_bytecode.h index face3fd96..19cf25df9 100644 --- a/renderdoc/driver/shaders/dxil/dxil_bytecode.h +++ b/renderdoc/driver/shaders/dxil/dxil_bytecode.h @@ -1387,7 +1387,7 @@ public: size_t firstFuncConst; size_t numFuncConsts; - void processFunction(const Function *f, uint32_t *nextSSAId = NULL); + void processFunction(const Function *f); void exitFunction(); private: diff --git a/renderdoc/driver/shaders/dxil/dxil_bytecode_editor.cpp b/renderdoc/driver/shaders/dxil/dxil_bytecode_editor.cpp index e8aa318c9..00e37766a 100644 --- a/renderdoc/driver/shaders/dxil/dxil_bytecode_editor.cpp +++ b/renderdoc/driver/shaders/dxil/dxil_bytecode_editor.cpp @@ -89,11 +89,9 @@ ProgramEditor::ProgramEditor(const DXBC::DXBCContainer *container, bytebuf &outB for(size_t idx = accum.firstConst; idx < accum.firstConst + accum.numConsts; idx++) m_Constants.push_back((Constant *)cast(accum.values[idx])); - uint32_t ssaID = 0; - for(Function *f : m_Functions) { - accum.processFunction(f, &ssaID); + accum.processFunction(f); for(size_t idx = accum.firstFuncConst; idx < accum.firstFuncConst + accum.numFuncConsts; idx++) m_Constants.push_back((Constant *)cast(accum.values[idx])); accum.exitFunction(); @@ -107,13 +105,11 @@ ProgramEditor::~ProgramEditor() LLVMOrderAccumulator accum; accum.processGlobals(this, true); - uint32_t ssaID = 0; - // delete any functions that aren't referenced by call instructions rdcarray keep; for(Function *f : m_Functions) { - accum.processFunction(f, &ssaID); + accum.processFunction(f); accum.exitFunction(); } @@ -1069,8 +1065,6 @@ bytebuf ProgramEditor::EncodeProgram() } \ } - uint32_t ssaID = 0; - for(Function *f : m_Functions) { if(f->external) @@ -1080,7 +1074,7 @@ bytebuf ProgramEditor::EncodeProgram() writer.Record(LLVMBC::FunctionRecord::DECLAREBLOCKS, f->blocks.size()); - accum.processFunction(f, &ssaID); + accum.processFunction(f); if(accum.numFuncConsts) { diff --git a/renderdoc/driver/shaders/dxil/dxil_disassemble.cpp b/renderdoc/driver/shaders/dxil/dxil_disassemble.cpp index d556c7851..e83826e46 100644 --- a/renderdoc/driver/shaders/dxil/dxil_disassemble.cpp +++ b/renderdoc/driver/shaders/dxil/dxil_disassemble.cpp @@ -1064,9 +1064,38 @@ void Program::SettleIDs() uint32_t &nextMetaSlot = m_NextMetaSlot; for(size_t i = 0; i < m_Functions.size(); i++) { - m_Accum.processFunction(m_Functions[i], &m_NextSSAId); - + // Generating the global SSA Id must be done before calling processFunction +#if ENABLED(DXC_COMPATIBLE_DISASM) + uint32_t slot = 0; +#endif + size_t curBlock = 0; Function &func = *m_Functions[i]; + for(Instruction *inst : func.instructions) + { + RDCASSERT(curBlock < func.blocks.size()); + for(Instruction *arg : func.args) + { +#if DISABLED(DXC_COMPATIBLE_DISASM) + if(arg->slot == ~0U) + arg->slot = m_NextSSAId++; +#else + if(arg->getName().isEmpty()) + arg->slot = slot++; +#endif + } + if(!inst->type->isVoid()) + { +#if DISABLED(DXC_COMPATIBLE_DISASM) + if(inst->slot == ~0U) + inst->slot = m_NextSSAId++; +#else + if(inst->getName().isEmpty()) + inst->slot = slot++; +#endif + } + } + + m_Accum.processFunction(m_Functions[i]); auto argMetaSlot = [this, &metaSlots, &nextMetaSlot](const Value *v) { if(const Metadata *meta = cast(v)) @@ -1095,7 +1124,7 @@ void Program::SettleIDs() if(!func.external) { - size_t curBlock = 0; + curBlock = 0; RDCASSERT(!func.blocks.empty()); func.blocks[curBlock]->startInstructionIdx = 0; RDCASSERTEQUAL(curBlock, func.blocks[curBlock]->id);