From cf9c56aae857803ad4d3f1d624941317ccb9f96e Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Mon, 1 Oct 2018 08:30:02 -0700 Subject: Added few extra debug checks to Vk backend --- .../GraphicsEngineVulkan/include/DescriptorPoolManager.h | 14 ++++++++++++++ .../GraphicsEngineVulkan/src/DescriptorPoolManager.cpp | 16 ++++++++++++++++ Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp | 5 ++++- 3 files changed, 34 insertions(+), 1 deletion(-) (limited to 'Graphics/GraphicsEngineVulkan') diff --git a/Graphics/GraphicsEngineVulkan/include/DescriptorPoolManager.h b/Graphics/GraphicsEngineVulkan/include/DescriptorPoolManager.h index 3ff54944..a0200ee6 100644 --- a/Graphics/GraphicsEngineVulkan/include/DescriptorPoolManager.h +++ b/Graphics/GraphicsEngineVulkan/include/DescriptorPoolManager.h @@ -149,6 +149,10 @@ public: RenderDeviceVkImpl& GetDeviceVkImpl() {return m_DeviceVkImpl;} +#ifdef DEVELOPMENT + int32_t GetAllocatedPoolCounter()const{return m_AllocatedPoolCounter;} +#endif + protected: VulkanUtilities::DescriptorPoolWrapper CreateDescriptorPool(const char* DebugName)const; @@ -186,10 +190,20 @@ public: { } + ~DescriptorSetAllocator(); + DescriptorSetAllocation Allocate(Uint64 CommandQueueMask, VkDescriptorSetLayout SetLayout); +#ifdef DEVELOPMENT + int32_t GetAllocatedDescriptorSetCounter()const{return m_AllocatedSetCounter;} +#endif + private: void FreeDescriptorSet(VkDescriptorSet Set, VkDescriptorPool Pool, Uint64 QueueMask); + +#ifdef DEVELOPMENT + std::atomic_int32_t m_AllocatedSetCounter = 0; +#endif }; diff --git a/Graphics/GraphicsEngineVulkan/src/DescriptorPoolManager.cpp b/Graphics/GraphicsEngineVulkan/src/DescriptorPoolManager.cpp index 20d9fac6..cd2cb7a1 100644 --- a/Graphics/GraphicsEngineVulkan/src/DescriptorPoolManager.cpp +++ b/Graphics/GraphicsEngineVulkan/src/DescriptorPoolManager.cpp @@ -144,6 +144,11 @@ static VkDescriptorSet AllocateDescriptorSet(const VulkanUtilities::VulkanLogica } +DescriptorSetAllocator::~DescriptorSetAllocator() +{ + DEV_CHECK_ERR(m_AllocatedSetCounter == 0, m_AllocatedSetCounter, " descriptor set(s) have not been returned to the allocator. If there are outstanding references to the sets in release queues, the app will crash when DescriptorSetAllocator::FreeDescriptorSet() is called"); +} + DescriptorSetAllocation DescriptorSetAllocator::Allocate(Uint64 CommandQueueMask, VkDescriptorSetLayout SetLayout) { // Descriptor pools are externally synchronized, meaning that the application must not allocate @@ -163,6 +168,10 @@ DescriptorSetAllocation DescriptorSetAllocator::Allocate(Uint64 CommandQueueMask { std::swap(*it, m_Pools.front()); } + +#ifdef DEVELOPMENT + ++m_AllocatedSetCounter; +#endif return {Set, Pool, CommandQueueMask, *this}; } } @@ -175,6 +184,10 @@ DescriptorSetAllocation DescriptorSetAllocator::Allocate(Uint64 CommandQueueMask auto Set = AllocateDescriptorSet(LogicalDevice, NewPool, SetLayout, ""); DEV_CHECK_ERR(Set != VK_NULL_HANDLE, "Failed to allocate descriptor set"); +#ifdef DEVELOPMENT + ++m_AllocatedSetCounter; +#endif + return {Set, NewPool, CommandQueueMask, *this }; } @@ -211,6 +224,9 @@ void DescriptorSetAllocator::FreeDescriptorSet(VkDescriptorSet Set, VkDescriptor { std::lock_guard Lock(Allocator->m_Mutex); Allocator->m_DeviceVkImpl.GetLogicalDevice().FreeDescriptorSet(Pool, Set); +#ifdef DEVELOPMENT + --Allocator->m_AllocatedSetCounter; +#endif } } diff --git a/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp index f29dfa3c..62772d92 100644 --- a/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp @@ -139,7 +139,10 @@ RenderDeviceVkImpl::~RenderDeviceVkImpl() ReleaseStaleResources(true); - VERIFY(m_TransientCmdPoolMgr.GetAllocatedPoolCount() == 0, "All allocated transient command pools must have been released now. If there are outstanding references to the pools in release queues, the app will crash when CommandPoolManager::FreeCommandPool() is called."); + DEV_CHECK_ERR(m_DescriptorSetAllocator.GetAllocatedDescriptorSetCounter() == 0, "All allocated descriptor sets must have been released now."); + DEV_CHECK_ERR(m_TransientCmdPoolMgr.GetAllocatedPoolCount() == 0, "All allocated transient command pools must have been released now. If there are outstanding references to the pools in release queues, the app will crash when CommandPoolManager::FreeCommandPool() is called."); + DEV_CHECK_ERR(m_DynamicDescriptorPool.GetAllocatedPoolCounter() == 0, "All allocated dynamic descriptor pools must have been released now."); + DEV_CHECK_ERR(m_DynamicMemoryManager.GetMasterBlockCounter() == 0, "All allocated dynamic master blocks must have been returned to the pool."); // Immediately destroys all command pools m_TransientCmdPoolMgr.DestroyPools(); -- cgit v1.2.3