From 5fee776a5278bb304a43803379e90be6d4ec113f Mon Sep 17 00:00:00 2001 From: baldurk Date: Thu, 20 Feb 2020 15:00:35 +0000 Subject: [PATCH] Allocate function variables in stack frame, and copy function parameters --- .../driver/shaders/spirv/spirv_debug.cpp | 37 ++++++++++++++++++- renderdoc/driver/shaders/spirv/spirv_debug.h | 3 ++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/renderdoc/driver/shaders/spirv/spirv_debug.cpp b/renderdoc/driver/shaders/spirv/spirv_debug.cpp index 67e30705f..c451a7a5d 100644 --- a/renderdoc/driver/shaders/spirv/spirv_debug.cpp +++ b/renderdoc/driver/shaders/spirv/spirv_debug.cpp @@ -74,7 +74,14 @@ void ThreadState::EnterFunction(ShaderDebugState *state, const rdcarray &arg if(arg <= arguments.size()) { - // TODO fill in function parameter + // function parameters are copied into function calls. Thus a function parameter that is a + // pointer does not have allocated storage for itself, it gets the pointer from the call site + // copied in and points to whatever storage that is. + // That means we don't have to allocate anything here, we just set up the ID and copy the + // value from the argument + ids[param.result] = ids[arguments[arg]]; + ids[param.result].name = debugger.GetRawName(param.result); + live.push_back(param.result); } else { @@ -89,14 +96,40 @@ void ThreadState::EnterFunction(ShaderDebugState *state, const rdcarray &arg RDCASSERT(OpDecoder(it).op == Op::Label); it++; + size_t numVars = 0; + Iter varCounter = it; + while(OpDecoder(varCounter).op == Op::Variable) + { + varCounter++; + numVars++; + } + + frame->locals.resize(numVars); + + size_t i = 0; // handle any variable declarations while(OpDecoder(it).op == Op::Variable) { OpVariable decl(it); - // TODO declare variable + ShaderVariable &stackvar = frame->locals[i]; + stackvar.name = debugger.GetRawName(decl.result); + + rdcstr sourceName = debugger.GetHumanName(decl.result); + + debugger.AllocateVariable(decl.result, decl.resultType, DebugVariableType::Variable, sourceName, + stackvar); + + if(decl.HasInitializer()) + AssignValue(stackvar, ids[decl.initializer]); + + live.removeOne(decl.result); + + ids[decl.result] = debugger.MakePointerVariable(decl.result, &stackvar); + live.push_back(decl.result); it++; + i++; } // next instruction is the first actual instruction we'll execute diff --git a/renderdoc/driver/shaders/spirv/spirv_debug.h b/renderdoc/driver/shaders/spirv/spirv_debug.h index 044a37039..7c1e39ffb 100644 --- a/renderdoc/driver/shaders/spirv/spirv_debug.h +++ b/renderdoc/driver/shaders/spirv/spirv_debug.h @@ -57,6 +57,9 @@ struct StackFrame Id function; uint32_t funcCallInstruction = ~0U; + // allocated storage for locals + rdcarray locals; + private: // disallow copying to ensure the locals we allocate never move around StackFrame(const StackFrame &o) = delete;