From 88d66ba24a6d484fd90609a3a7031a781974e266 Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Fri, 28 Sep 2018 09:00:28 -0700 Subject: Some minor updates to resource lifetime management in Vk backend + comments --- .../GraphicsEngineNextGenBase/include/DynamicHeap.h | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'Graphics/GraphicsEngineNextGenBase') diff --git a/Graphics/GraphicsEngineNextGenBase/include/DynamicHeap.h b/Graphics/GraphicsEngineNextGenBase/include/DynamicHeap.h index ddd33d09..6707296a 100644 --- a/Graphics/GraphicsEngineNextGenBase/include/DynamicHeap.h +++ b/Graphics/GraphicsEngineNextGenBase/include/DynamicHeap.h @@ -29,6 +29,7 @@ #include #include #include +#include #include "VariableSizeAllocationsManager.h" #include "RingBuffer.h" @@ -105,16 +106,20 @@ public: MasterBlockListBasedManager& operator= (const MasterBlockListBasedManager&) = delete; MasterBlockListBasedManager& operator= ( MasterBlockListBasedManager&&) = delete; + ~MasterBlockListBasedManager() + { + DEV_CHECK_ERR(m_MasterBlockCounter == 0, m_MasterBlockCounter, " master block(s) have not been returned to the manager"); + } + template void ReleaseMasterBlocks(std::vector& Blocks, RenderDeviceImplType& Device, Uint64 CmdQueueMask) { struct StaleMasterBlock { - MasterBlock Block; MasterBlockListBasedManager* Mgr; - StaleMasterBlock(MasterBlock&& _Block, MasterBlockListBasedManager* _Mgr) : + StaleMasterBlock(MasterBlock&& _Block, MasterBlockListBasedManager* _Mgr)noexcept : Block (std::move(_Block)), Mgr (_Mgr) { @@ -137,6 +142,9 @@ public: if (Mgr != nullptr) { std::lock_guard Lock(Mgr->m_AllocationsMgrMtx); +#ifdef DEVELOPMENT + --Mgr->m_MasterBlockCounter; +#endif Mgr->m_AllocationsMgr.Free(std::move(Block)); } } @@ -154,12 +162,19 @@ protected: MasterBlock AllocateMasterBlock(OffsetType SizeInBytes, OffsetType Alignment) { std::lock_guard Lock(m_AllocationsMgrMtx); +#ifdef DEVELOPMENT + ++m_MasterBlockCounter; +#endif return m_AllocationsMgr.Allocate(SizeInBytes, Alignment); } private: std::mutex m_AllocationsMgrMtx; VariableSizeAllocationsManager m_AllocationsMgr; + +#ifdef DEVELOPMENT + std::atomic_int32_t m_MasterBlockCounter = 0; +#endif }; } // namespace DynamicHeap -- cgit v1.2.3