Fix crash in CreateDescriptorSetGroup

Signed-off-by: renderexpert <expert@renderconsulting.co.uk>
This commit is contained in:
renderexpert
2025-07-04 19:22:05 +01:00
committed by Konstantin Pastbin
parent 01c2f02c86
commit 36f123ef25

View File

@@ -202,8 +202,7 @@ VulkanObject VulkanObjectManager::CreateImage(VkImageUsageFlags usageFlags, VkFo
return result;
}
DescriptorSetGroup VulkanObjectManager::CreateDescriptorSetGroup(ref_ptr<VulkanGpuProgram> program)
{
DescriptorSetGroup VulkanObjectManager::CreateDescriptorSetGroup(ref_ptr<VulkanGpuProgram> program) {
CHECK(std::this_thread::get_id() == m_renderers[ThreadType::Frontend], ());
DescriptorSetGroup s;
@@ -212,14 +211,17 @@ DescriptorSetGroup VulkanObjectManager::CreateDescriptorSetGroup(ref_ptr<VulkanG
// Find a pool with available sets.
uint32_t poolIndex = 0;
while (poolIndex < m_descriptorPools.size() && m_descriptorPools[poolIndex].m_availableSetsCount == 0)
++poolIndex;
while (poolIndex <= m_descriptorPools.size())
{
// No such a pool, create one.
if (poolIndex == m_descriptorPools.size())
{
CreateDescriptorPool();
poolIndex = m_descriptorPools.size() - 1;
// No available sets in the pool, try next one.
if (m_descriptorPools[poolIndex].m_availableSetsCount == 0)
{
poolIndex++;
continue;
}
// Allocate a descriptor set.
@@ -232,6 +234,22 @@ DescriptorSetGroup VulkanObjectManager::CreateDescriptorSetGroup(ref_ptr<VulkanG
// Decrease the available sets count.
m_descriptorPools[poolIndex].m_availableSetsCount--;
auto const r = vkAllocateDescriptorSets(m_device, &allocInfo, &s.m_descriptorSet);
if (r == VK_ERROR_FRAGMENTED_POOL || r == VK_ERROR_OUT_OF_POOL_MEMORY)
{
poolIndex++;
m_descriptorPools[poolIndex].m_availableSetsCount++;
}
else if (r != VK_SUCCESS)
{
CHECK_VK_CALL(r);
}
else
{
break;
}
}
TRACE_COUNTER("[drape][vulkan] Descriptor pools", static_cast<int64_t>(m_descriptorPools.size()));
#ifdef ENABLE_TRACE
int64_t usedDescriptorsSets = 0;
@@ -240,7 +258,6 @@ DescriptorSetGroup VulkanObjectManager::CreateDescriptorSetGroup(ref_ptr<VulkanG
TRACE_COUNTER("[drape][vulkan] Descriptor sets", usedDescriptorsSets);
#endif
CHECK_VK_CALL(vkAllocateDescriptorSets(m_device, &allocInfo, &s.m_descriptorSet));
return s;
}