From 05973d8aeb1a4d12f59aadfb86d20decadba82d1 Mon Sep 17 00:00:00 2001 From: asawicki Date: Mon, 28 Oct 2024 17:51:10 +0100 Subject: [PATCH] Fixes in multithreading in VmaBlockVector::Free Also improved the documentation of vmaGetPoolStatistics. See #451 - thanks @danginsburg --- include/vk_mem_alloc.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/include/vk_mem_alloc.h b/include/vk_mem_alloc.h index 69bb0c1..b9317de 100644 --- a/include/vk_mem_alloc.h +++ b/include/vk_mem_alloc.h @@ -1836,6 +1836,9 @@ VMA_CALL_PRE void VMA_CALL_POST vmaDestroyPool( \param allocator Allocator object. \param pool Pool object. \param[out] pPoolStats Statistics of specified pool. + +Note that when using the pool from multiple threads, returned information may immediately +become outdated. */ VMA_CALL_PRE void VMA_CALL_POST vmaGetPoolStatistics( VmaAllocator VMA_NOT_NULL allocator, @@ -11605,6 +11608,10 @@ void VmaBlockVector::Free(const VmaAllocation hAllocation) } IncrementallySortBlocks(); + + m_hAllocator->m_Budget.RemoveAllocation(m_hAllocator->MemoryTypeIndexToHeapIndex(m_MemoryTypeIndex), hAllocation->GetSize()); + hAllocation->Destroy(m_hAllocator); + m_hAllocator->m_AllocationObjectAllocator.Free(hAllocation); } // Destruction of a free block. Deferred until this point, outside of mutex @@ -11615,10 +11622,6 @@ void VmaBlockVector::Free(const VmaAllocation hAllocation) pBlockToDelete->Destroy(m_hAllocator); vma_delete(m_hAllocator, pBlockToDelete); } - - m_hAllocator->m_Budget.RemoveAllocation(m_hAllocator->MemoryTypeIndexToHeapIndex(m_MemoryTypeIndex), hAllocation->GetSize()); - hAllocation->Destroy(m_hAllocator); - m_hAllocator->m_AllocationObjectAllocator.Free(hAllocation); } VkDeviceSize VmaBlockVector::CalcMaxBlockSize() const