From 44ab5e99286562698bc24a52c1103adb15b6650a Mon Sep 17 00:00:00 2001 From: baldurk Date: Fri, 5 Jun 2020 13:23:54 +0100 Subject: [PATCH] Fix crash in shader debugging with unbound (but unused) descriptor sets --- renderdoc/driver/vulkan/vk_shaderdebug.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/renderdoc/driver/vulkan/vk_shaderdebug.cpp b/renderdoc/driver/vulkan/vk_shaderdebug.cpp index 5aa62b817..0dfa06e42 100644 --- a/renderdoc/driver/vulkan/vk_shaderdebug.cpp +++ b/renderdoc/driver/vulkan/vk_shaderdebug.cpp @@ -182,22 +182,39 @@ public: { uint32_t dynamicOffset = 0; + // skip invalid descriptor set binds, we assume these aren't present because they will not be + // accessed statically + if(descSets[set].descSet == ResourceId() || descSets[set].pipeLayout == ResourceId()) + continue; + DescSetSnapshot &dstSet = m_DescSets[set]; const rdcarray &curBinds = m_pDriver->GetCurrentDescSetBindings(descSets[set].descSet); const bytebuf &curInline = m_pDriver->GetCurrentDescSetInlineData(descSets[set].descSet); - const DescSetLayout &setLayout = m_Creation.m_DescSetLayout[pipeLayout.descSetLayouts[set]]; + + // use the descriptor set layout from when it was bound. If the pipeline layout declared a + // descriptor set layout for this set, but it's statically unused, it may be complete + // garbage and doesn't match what the shader uses. However the pipeline layout at descriptor + // set bind time must have been compatible and valid so we can use it. If this set *is* used + // then the pipeline layout at bind time must be compatible with the pipeline's pipeline + // layout, so we're fine too. + const DescSetLayout &setLayout = + m_Creation + .m_DescSetLayout[m_Creation.m_PipelineLayout[descSets[set].pipeLayout].descSetLayouts[set]]; for(size_t bind = 0; bind < setLayout.bindings.size(); bind++) { const DescSetLayout::Binding &bindLayout = setLayout.bindings[bind]; + if(bindLayout.descriptorCount == 0) + continue; + if(bindLayout.stageFlags & stage) { DescriptorSetSlot *curSlots = curBinds[bind]; - dstSet.bindings.resize(bind + 1); + dstSet.bindings.resize_for_index(bind); DescSetBindingSnapshot &dstBind = dstSet.bindings[bind];