From 6b28d140898a3639264f09313d864b49ac242671 Mon Sep 17 00:00:00 2001 From: baldurk Date: Thu, 20 Feb 2020 18:13:39 +0000 Subject: [PATCH] Add source variables for named IDs where possible --- .../driver/shaders/spirv/spirv_debug.cpp | 9 +- renderdoc/driver/shaders/spirv/spirv_debug.h | 3 + .../shaders/spirv/spirv_debug_setup.cpp | 99 +++++++++++++++++++ 3 files changed, 109 insertions(+), 2 deletions(-) diff --git a/renderdoc/driver/shaders/spirv/spirv_debug.cpp b/renderdoc/driver/shaders/spirv/spirv_debug.cpp index c38bb02aa..18d2aabe8 100644 --- a/renderdoc/driver/shaders/spirv/spirv_debug.cpp +++ b/renderdoc/driver/shaders/spirv/spirv_debug.cpp @@ -149,8 +149,9 @@ void ThreadState::EnterFunction(ShaderDebugState *state, const rdcarray &arg rdcstr sourceName = debugger.GetHumanName(decl.result); - debugger.AllocateVariable(decl.result, decl.resultType, DebugVariableType::Variable, sourceName, - stackvar); + // don't add source vars - SetDst below will do that + debugger.AllocateVariable(decl.result, decl.resultType, DebugVariableType::Undefined, + sourceName, stackvar); if(decl.HasInitializer()) AssignValue(stackvar, ids[decl.initializer]); @@ -187,6 +188,8 @@ void ThreadState::SetDst(ShaderDebugState *state, Id id, const ShaderVariable &v ids[id] = val; ids[id].name = debugger.GetRawName(id); live.push_back(id); + + debugger.AddSourceVars(id); } else { @@ -267,6 +270,8 @@ void ThreadState::SetDst(ShaderDebugState *state, Id id, const ShaderVariable &v ShaderVariableChange change; change.after = debugger.EvaluatePointerVariable(ids[id]); state->changes.push_back(change); + + debugger.AddSourceVars(id); } } diff --git a/renderdoc/driver/shaders/spirv/spirv_debug.h b/renderdoc/driver/shaders/spirv/spirv_debug.h index 0e881bef1..8e14c4754 100644 --- a/renderdoc/driver/shaders/spirv/spirv_debug.h +++ b/renderdoc/driver/shaders/spirv/spirv_debug.h @@ -133,6 +133,7 @@ public: const DataType &GetType(Id typeId); rdcstr GetRawName(Id id) const; rdcstr GetHumanName(Id id); + void AddSourceVars(Id id); void AllocateVariable(Id id, Id typeId, DebugVariableType sourceVarType, const rdcstr &sourceName, ShaderVariable &outVar); @@ -154,6 +155,8 @@ private: void AllocateVariable(const Decorations &varDecorations, const Decorations &curDecorations, DebugVariableType sourceVarType, const rdcstr &sourceName, uint32_t offset, const DataType &inType, ShaderVariable &outVar); + void AddSourceVars(const DataType &inType, const rdcstr &sourceName, const rdcstr &varName, + uint32_t &offset); ///////////////////////////////////////////////////////// // debug data diff --git a/renderdoc/driver/shaders/spirv/spirv_debug_setup.cpp b/renderdoc/driver/shaders/spirv/spirv_debug_setup.cpp index 7f7c0f265..bec9068f6 100644 --- a/renderdoc/driver/shaders/spirv/spirv_debug_setup.cpp +++ b/renderdoc/driver/shaders/spirv/spirv_debug_setup.cpp @@ -552,6 +552,102 @@ rdcstr Debugger::GetHumanName(Id id) return name; } +void Debugger::AddSourceVars(Id id) +{ + rdcstr name; + + auto it = dynamicNames.find(id); + if(it != dynamicNames.end()) + name = it->second; + else + name = strings[id]; + + if(!name.empty()) + { + Id type = idTypes[id]; + + uint32_t offset = 0; + AddSourceVars(dataTypes[type], name, GetRawName(id), offset); + } +} + +void Debugger::AddSourceVars(const DataType &inType, const rdcstr &sourceName, + const rdcstr &varName, uint32_t &offset) +{ + SourceVariableMapping sourceVar; + + switch(inType.type) + { + case DataType::UnknownType: + case DataType::ImageType: + case DataType::SamplerType: + case DataType::SampledImageType: return; + case DataType::PointerType: + { + // step silently into pointers + AddSourceVars(dataTypes[inType.InnerType()], sourceName, varName, offset); + return; + } + case DataType::ScalarType: + { + sourceVar.type = inType.scalar().Type(); + sourceVar.rows = 1; + sourceVar.columns = 1; + break; + } + case DataType::VectorType: + { + sourceVar.type = inType.scalar().Type(); + sourceVar.rows = 1; + sourceVar.columns = RDCMAX(1U, inType.vector().count); + break; + } + case DataType::MatrixType: + { + sourceVar.type = inType.scalar().Type(); + sourceVar.columns = RDCMAX(1U, inType.matrix().count); + sourceVar.rows = RDCMAX(1U, inType.vector().count); + break; + } + case DataType::StructType: + { + for(int32_t i = 0; i < inType.children.count(); i++) + { + rdcstr childVarName = StringFormat::Fmt("%s._child%d", varName.c_str(), i); + + rdcstr childSourceName; + if(inType.children[i].name.empty()) + childSourceName = StringFormat::Fmt("%s._child%d", sourceName.c_str(), i); + else + childSourceName = sourceName + "." + inType.children[i].name; + + AddSourceVars(dataTypes[inType.children[i].type], childSourceName, childVarName, offset); + } + return; + } + case DataType::ArrayType: + { + ShaderVariable len = GetActiveLane().ids[inType.length]; + for(uint32_t i = 0; i < len.value.u.x; i++) + { + rdcstr idx = StringFormat::Fmt("[%u]", i); + + AddSourceVars(dataTypes[inType.InnerType()], sourceName + idx, varName + idx, offset); + } + return; + } + } + + sourceVar.name = sourceName; + sourceVar.offset = offset; + for(uint32_t x = 0; x < sourceVar.rows * sourceVar.columns; x++) + sourceVar.variables.push_back(DebugVariableReference(DebugVariableType::Variable, varName, x)); + + sourceVars.push_back(sourceVar); + + offset++; +} + void Debugger::CalcActiveMask(rdcarray &activeMask) { // one bool per workgroup thread @@ -672,6 +768,9 @@ void Debugger::AllocateVariable(const Decorations &varDecorations, const Decorat } } + if(sourceVarType == DebugVariableType::Undefined) + return; + SourceVariableMapping sourceVar; sourceVar.name = sourceName; sourceVar.offset = offset;