Skip to content

Commit bfb7a3d

Browse files
Vulkan: fixed reference invalidation issue in DescriptorSetAllocator::Allocate() (close #664)
1 parent 4c5d5db commit bfb7a3d

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

Graphics/GraphicsEngineVulkan/src/DescriptorPoolManager.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2022 Diligent Graphics LLC
2+
* Copyright 2019-2025 Diligent Graphics LLC
33
* Copyright 2015-2019 Egor Yusov
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -61,7 +61,7 @@ VulkanUtilities::DescriptorPoolWrapper DescriptorPoolManager::CreateDescriptorPo
6161

6262
static std::vector<VkDescriptorPoolSize> PrunePoolSizes(RenderDeviceVkImpl& DeviceVkImpl, std::vector<VkDescriptorPoolSize>&& PoolSizes)
6363
{
64-
const auto& Feats = DeviceVkImpl.GetLogicalDevice().GetEnabledExtFeatures();
64+
const VulkanUtilities::VulkanLogicalDevice::ExtensionFeatures& Feats = DeviceVkImpl.GetLogicalDevice().GetEnabledExtFeatures();
6565
for (auto iter = PoolSizes.begin(); iter != PoolSizes.end();)
6666
{
6767
switch (iter->type)
@@ -113,8 +113,8 @@ VulkanUtilities::DescriptorPoolWrapper DescriptorPoolManager::GetPool(const char
113113
return CreateDescriptorPool(DebugName);
114114
else
115115
{
116-
auto& LogicalDevice = m_DeviceVkImpl.GetLogicalDevice();
117-
auto Pool = std::move(m_Pools.front());
116+
const VulkanUtilities::VulkanLogicalDevice& LogicalDevice = m_DeviceVkImpl.GetLogicalDevice();
117+
VulkanUtilities::DescriptorPoolWrapper Pool = std::move(m_Pools.front());
118118
VulkanUtilities::SetDescriptorPoolName(LogicalDevice.GetVkDevice(), Pool, DebugName);
119119
m_Pools.pop_front();
120120
return Pool;
@@ -201,14 +201,14 @@ DescriptorSetAllocation DescriptorSetAllocator::Allocate(Uint64 CommandQueueMask
201201
// and/or free descriptor sets from the same pool in multiple threads simultaneously (13.2.3)
202202
std::lock_guard<std::mutex> Lock{m_Mutex};
203203

204-
const auto& LogicalDevice = m_DeviceVkImpl.GetLogicalDevice();
204+
const VulkanUtilities::VulkanLogicalDevice& LogicalDevice = m_DeviceVkImpl.GetLogicalDevice();
205205
// Try all pools starting from the frontmost
206206
for (auto it = m_Pools.begin(); it != m_Pools.end(); ++it)
207207
{
208-
auto& Pool = *it;
209-
auto Set = AllocateDescriptorSet(LogicalDevice, Pool, SetLayout, DebugName);
210-
if (Set != VK_NULL_HANDLE)
208+
VkDescriptorSet vkSet = AllocateDescriptorSet(LogicalDevice, *it, SetLayout, DebugName);
209+
if (vkSet != VK_NULL_HANDLE)
211210
{
211+
VkDescriptorPool vkPool = *it;
212212
// Move the pool to the front
213213
if (it != m_Pools.begin())
214214
{
@@ -218,23 +218,23 @@ DescriptorSetAllocation DescriptorSetAllocator::Allocate(Uint64 CommandQueueMask
218218
#ifdef DILIGENT_DEVELOPMENT
219219
++m_AllocatedSetCounter;
220220
#endif
221-
return {Set, Pool, CommandQueueMask, *this};
221+
return {vkSet, vkPool, CommandQueueMask, *this};
222222
}
223223
}
224224

225225
// Failed to allocate descriptor from existing pools -> create a new one
226226
LOG_INFO_MESSAGE("Allocated new descriptor pool");
227227
m_Pools.emplace_front(CreateDescriptorPool("Descriptor pool"));
228228

229-
auto& NewPool = m_Pools.front();
230-
auto Set = AllocateDescriptorSet(LogicalDevice, NewPool, SetLayout, DebugName);
231-
DEV_CHECK_ERR(Set != VK_NULL_HANDLE, "Failed to allocate descriptor set");
229+
VulkanUtilities::DescriptorPoolWrapper& NewPool = m_Pools.front();
230+
VkDescriptorSet vkSet = AllocateDescriptorSet(LogicalDevice, NewPool, SetLayout, DebugName);
231+
DEV_CHECK_ERR(vkSet != VK_NULL_HANDLE, "Failed to allocate descriptor set");
232232

233233
#ifdef DILIGENT_DEVELOPMENT
234234
++m_AllocatedSetCounter;
235235
#endif
236236

237-
return {Set, NewPool, CommandQueueMask, *this};
237+
return {vkSet, NewPool, CommandQueueMask, *this};
238238
}
239239

240240
void DescriptorSetAllocator::FreeDescriptorSet(VkDescriptorSet Set, VkDescriptorPool Pool, Uint64 QueueMask)
@@ -289,8 +289,8 @@ void DescriptorSetAllocator::FreeDescriptorSet(VkDescriptorSet Set, VkDescriptor
289289

290290
VkDescriptorSet DynamicDescriptorSetAllocator::Allocate(VkDescriptorSetLayout SetLayout, const char* DebugName)
291291
{
292-
VkDescriptorSet set = VK_NULL_HANDLE;
293-
const auto& LogicalDevice = m_GlobalPoolMgr.GetDeviceVkImpl().GetLogicalDevice();
292+
VkDescriptorSet set = VK_NULL_HANDLE;
293+
const VulkanUtilities::VulkanLogicalDevice& LogicalDevice = m_GlobalPoolMgr.GetDeviceVkImpl().GetLogicalDevice();
294294
if (!m_AllocatedPools.empty())
295295
{
296296
set = AllocateDescriptorSet(LogicalDevice, m_AllocatedPools.back(), SetLayout, DebugName);
@@ -307,7 +307,7 @@ VkDescriptorSet DynamicDescriptorSetAllocator::Allocate(VkDescriptorSetLayout Se
307307

308308
void DynamicDescriptorSetAllocator::ReleasePools(Uint64 QueueMask)
309309
{
310-
for (auto& Pool : m_AllocatedPools)
310+
for (VulkanUtilities::DescriptorPoolWrapper& Pool : m_AllocatedPools)
311311
{
312312
m_GlobalPoolMgr.DisposePool(std::move(Pool), QueueMask);
313313
}

0 commit comments

Comments
 (0)