From 25ba64a0855fd6c031b973aabedef60b67c9920c Mon Sep 17 00:00:00 2001 From: baldurk Date: Wed, 6 May 2020 11:12:28 +0100 Subject: [PATCH] Give better names to anonymous/unnamed variables * With GLSL anonymous blocks the variable doesn't get a name, but the type does get a meaningful name - use that to name the variable. --- .../driver/shaders/spirv/spirv_debug_setup.cpp | 13 +++++++++++++ .../driver/shaders/spirv/spirv_reflect.cpp | 17 +++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/renderdoc/driver/shaders/spirv/spirv_debug_setup.cpp b/renderdoc/driver/shaders/spirv/spirv_debug_setup.cpp index 7b427ad9a..b1f2d1d71 100644 --- a/renderdoc/driver/shaders/spirv/spirv_debug_setup.cpp +++ b/renderdoc/driver/shaders/spirv/spirv_debug_setup.cpp @@ -2243,6 +2243,19 @@ void Debugger::RegisterOp(Iter it) if(var.storageClass == StorageClass::Function && curFunction) curFunction->variables.push_back(var.result); + + // variables are always pointers + Id varType = dataTypes[var.resultType].InnerType(); + + // if we don't have a name for this variable but it's a pointer to a struct that is named then + // give the variable a name based on the type. This is a common pattern in GLSL for global + // blocks, and since the variable is how we access commonly we should give it a recognisable + // name. + if(strings[var.result].empty() && dataTypes[varType].type == DataType::StructType && + !strings[varType].empty()) + { + strings[var.result] = strings[varType] + "_var"; + } } else if(opdata.op == Op::Label) { diff --git a/renderdoc/driver/shaders/spirv/spirv_reflect.cpp b/renderdoc/driver/shaders/spirv/spirv_reflect.cpp index df05f1b76..664d65e5c 100644 --- a/renderdoc/driver/shaders/spirv/spirv_reflect.cpp +++ b/renderdoc/driver/shaders/spirv/spirv_reflect.cpp @@ -355,6 +355,23 @@ void Reflector::RegisterOp(Iter it) memberNames.push_back({memberName.type, memberName.member, memberName.name}); } + else if(opdata.op == Op::Variable) + { + OpVariable var(it); + + // variables are always pointers + Id varType = dataTypes[var.resultType].InnerType(); + + // if we don't have a name for this variable but it's a pointer to a struct that is named then + // give the variable a name based on the type. This is a common pattern in GLSL for global + // blocks, and since the variable is how we access commonly we should give it a recognisable + // name. + if(strings[var.result].empty() && dataTypes[varType].type == DataType::StructType && + !strings[varType].empty()) + { + strings[var.result] = strings[varType] + "_var"; + } + } else if(opdata.op == Op::ModuleProcessed) { OpModuleProcessed processed(it);