From d785eaeb679ef60364cc572d368f94d5f34ff418 Mon Sep 17 00:00:00 2001 From: Jake Turner Date: Wed, 13 Mar 2024 16:06:28 +0000 Subject: [PATCH] Update struct member and array element names of SPIRV constants array names and struct member names are not set when constants are created (struct decoration data is not available) --- renderdoc/driver/shaders/spirv/spirv_debug.h | 2 + .../shaders/spirv/spirv_debug_setup.cpp | 39 +++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/renderdoc/driver/shaders/spirv/spirv_debug.h b/renderdoc/driver/shaders/spirv/spirv_debug.h index 10d67a9bb..15c1d5292 100644 --- a/renderdoc/driver/shaders/spirv/spirv_debug.h +++ b/renderdoc/driver/shaders/spirv/spirv_debug.h @@ -417,6 +417,8 @@ private: std::function callback) const; + void SetStructArrayNames(ShaderVariable &c, const DataType *typeWalk, + const rdcarray &specInfo); void MakeSignatureNames(const rdcarray &sigList, rdcarray &sigNames); diff --git a/renderdoc/driver/shaders/spirv/spirv_debug_setup.cpp b/renderdoc/driver/shaders/spirv/spirv_debug_setup.cpp index c6dfed24b..2626aa9a3 100644 --- a/renderdoc/driver/shaders/spirv/spirv_debug_setup.cpp +++ b/renderdoc/driver/shaders/spirv/spirv_debug_setup.cpp @@ -796,6 +796,36 @@ void Reflector::CheckDebuggable(bool &debuggable, rdcstr &debugStatus) const debugStatus.trim(); } +void Debugger::SetStructArrayNames(ShaderVariable &c, const DataType *typeWalk, + const rdcarray &specInfo) +{ + if(typeWalk->type == DataType::StructType) + { + RDCASSERTEQUAL(c.members.size(), typeWalk->children.size()); + for(size_t i = 0; i < c.members.size(); ++i) + { + const DataType::Child &child = typeWalk->children[i]; + const DataType *childType = &dataTypes[child.type]; + if(!child.name.empty()) + c.members[i].name = child.name; + else + c.members[i].name = StringFormat::Fmt("_child%d", i); + + SetStructArrayNames(c.members[i], childType, specInfo); + } + } + else if(typeWalk->type == DataType::ArrayType) + { + uint32_t arraySize = EvaluateConstant(typeWalk->length, specInfo).value.u32v[0]; + const DataType *childType = &dataTypes[typeWalk->InnerType()]; + for(size_t i = 0; i < arraySize; ++i) + { + c.members[i].name = StringFormat::Fmt("[%u]", i); + SetStructArrayNames(c.members[i], childType, specInfo); + } + } +} + ShaderDebugTrace *Debugger::BeginDebug(DebugAPIWrapper *api, const ShaderStage shaderStage, const rdcstr &entryPoint, const rdcarray &specInfo, @@ -867,6 +897,15 @@ ShaderDebugTrace *Debugger::BeginDebug(DebugAPIWrapper *api, const ShaderStage s active.ids.resize(idOffsets.size()); + // array names and struct member names are not set when constants are created + for(auto it = constants.begin(); it != constants.end(); ++it) + { + Constant &c = it->second; + + const DataType *typeWalk = &dataTypes[c.type]; + SetStructArrayNames(c.value, typeWalk, specInfo); + } + // evaluate all constants for(auto it = constants.begin(); it != constants.end(); it++) {