From 6532eb65f02a2e24c83a1d773db1e66e1d5a3cf6 Mon Sep 17 00:00:00 2001 From: Jake Turner Date: Thu, 11 Apr 2024 11:24:00 +0100 Subject: [PATCH] SPIRV debug mapping change the superseding detection Loop over the scope downwards (parent -> child) then inside that loop iterate upwards from the current scope (child -> parent) to detect mappings which might be superseded --- .../shaders/spirv/spirv_debug_setup.cpp | 54 ++++++++----------- 1 file changed, 23 insertions(+), 31 deletions(-) diff --git a/renderdoc/driver/shaders/spirv/spirv_debug_setup.cpp b/renderdoc/driver/shaders/spirv/spirv_debug_setup.cpp index bcefecf86..26de2741f 100644 --- a/renderdoc/driver/shaders/spirv/spirv_debug_setup.cpp +++ b/renderdoc/driver/shaders/spirv/spirv_debug_setup.cpp @@ -1562,8 +1562,22 @@ void Debugger::FillDebugSourceVars(rdcarray &instInfo) // we only pick the innermost. rdcarray processed; + // capture the scopes upwards (from child to parent) + rdcarray scopes; while(scope) { + scopes.push_back(scope); + // if we reach a function scope, don't go up any further. + if(scope->type == DebugScope::Function) + break; + + scope = scope->parent; + } + + // Iterate over the scopes downwards (parent->child) + for(size_t s = 0; s < scopes.size(); ++s) + { + scope = scopes[scopes.size() - 1 - s]; for(size_t m = 0; m < scope->localMappings.size(); m++) { const LocalMapping &mapping = scope->localMappings[m]; @@ -1572,50 +1586,28 @@ void Debugger::FillDebugSourceVars(rdcarray &instInfo) if(mapping.instIndex > i.instruction) break; - // see if this mapping is superceded by a later mapping that is in scope for this - // instruction. This is a bit inefficient but simple. The alternative would be to do record + // see if this mapping is superceded by a later mapping in this scope for this instruction. + // This is a bit inefficient but simple. The alternative would be to do record // start and end points for each mapping and update the end points, but this is simple and // should be limited since it's only per-scope bool supercede = false; - const ScopeData *supercedeScope = scope; - while(supercedeScope) + for(size_t n = m + 1; n < scope->localMappings.size(); n++) { - for(size_t n = m + 1; n < supercedeScope->localMappings.size(); n++) - { - const LocalMapping &laterMapping = supercedeScope->localMappings[n]; + const LocalMapping &laterMapping = scope->localMappings[n]; - // if this mapping is past the current instruction, stop here. - if(laterMapping.instIndex > i.instruction) - break; - - // if this mapping will supercede and starts later - if(laterMapping.isSourceSupersetOf(mapping) && laterMapping.instIndex > mapping.instIndex) - { - supercede = true; - break; - } - } - - if(supercede) + // if this mapping is past the current instruction, stop here. + if(laterMapping.instIndex > i.instruction) break; - // if we reach a function scope, don't go up any further. - if(supercedeScope->type == DebugScope::Function) - break; - - supercedeScope = supercedeScope->parent; - } - - for(size_t n = 0; n < processed.size(); n++) - { - if(processed[n].isSourceSupersetOf(mapping)) + // if this mapping will supercede and starts later + if(laterMapping.isSourceSupersetOf(mapping) && laterMapping.instIndex > mapping.instIndex) { supercede = true; break; } } - // don't add the current mapping if it's going to be superceded. + // don't add the current mapping if it's going to be superceded by something later if(supercede) continue;