From 4d156f0904aa0a48cee66340fa921d020a446665 Mon Sep 17 00:00:00 2001 From: baldurk Date: Fri, 19 Jun 2020 17:02:59 +0100 Subject: [PATCH] Handle ret not being in last basic block --- renderdoc/driver/shaders/dxil/dxil_bytecode.cpp | 10 +++++++++- renderdoc/driver/shaders/dxil/dxil_disassemble.cpp | 10 ++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/renderdoc/driver/shaders/dxil/dxil_bytecode.cpp b/renderdoc/driver/shaders/dxil/dxil_bytecode.cpp index dc40c7ee5..5182dadc2 100644 --- a/renderdoc/driver/shaders/dxil/dxil_bytecode.cpp +++ b/renderdoc/driver/shaders/dxil/dxil_bytecode.cpp @@ -1406,6 +1406,8 @@ Program::Program(const byte *bytes, size_t length) m_Symbols.push_back({SymbolType::Instruction, f.instructions.size()}); } + curBlock++; + f.instructions.push_back(inst); } else if(op.type == FunctionRecord::INST_BINOP) @@ -2256,6 +2258,8 @@ Program::Program(const byte *bytes, size_t length) } } + RDCASSERT(curBlock == f.blocks.size()); + size_t resultID = 0; if(f.blocks[0].name.empty()) @@ -2277,9 +2281,13 @@ Program::Program(const byte *bytes, size_t length) if(f.instructions[i].op == Instruction::Branch || f.instructions[i].op == Instruction::Unreachable || - f.instructions[i].op == Instruction::Switch) + f.instructions[i].op == Instruction::Switch || f.instructions[i].op == Instruction::Ret) { curBlock++; + + if(i == f.instructions.size() - 1) + break; + if(f.blocks[curBlock].name.empty()) f.blocks[curBlock].resultID = (uint32_t)resultID++; continue; diff --git a/renderdoc/driver/shaders/dxil/dxil_disassemble.cpp b/renderdoc/driver/shaders/dxil/dxil_disassemble.cpp index 25d2bf086..eb3382da5 100644 --- a/renderdoc/driver/shaders/dxil/dxil_disassemble.cpp +++ b/renderdoc/driver/shaders/dxil/dxil_disassemble.cpp @@ -595,8 +595,10 @@ void Program::MakeDisassemblyString() instructionLine++; } - for(Instruction &inst : func.instructions) + for(size_t funcIdx = 0; funcIdx < func.instructions.size(); funcIdx++) { + Instruction &inst = func.instructions[funcIdx]; + inst.disassemblyLine = instructionLine; m_Disassembly += " "; if(!inst.name.empty()) @@ -1326,8 +1328,12 @@ void Program::MakeDisassemblyString() m_Disassembly += "\n"; instructionLine++; + // if this is the last instruction don't print the next block's label + if(funcIdx == func.instructions.size() - 1) + break; + if(inst.op == Instruction::Branch || inst.op == Instruction::Unreachable || - inst.op == Instruction::Switch) + inst.op == Instruction::Switch || inst.op == Instruction::Ret) { m_Disassembly += "\n"; instructionLine++;