From 6a1f1e2d8d04d801ac20fdee1c5e7aad01685fac Mon Sep 17 00:00:00 2001 From: Adam Sawicki Date: Tue, 14 Nov 2017 16:21:12 +0100 Subject: [PATCH] Fixed bug with mapping of non-dedicated allocations. --- src/vk_mem_alloc.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/vk_mem_alloc.h b/src/vk_mem_alloc.h index e6b0161..8501e0b 100644 --- a/src/vk_mem_alloc.h +++ b/src/vk_mem_alloc.h @@ -3191,6 +3191,8 @@ public: outInfo.unusedRangeSizeMax = 0; } + void BlockAllocMap(); + void BlockAllocUnmap(); VkResult DedicatedAllocMap(VmaAllocator hAllocator, void** ppData); void DedicatedAllocUnmap(VmaAllocator hAllocator); @@ -4383,6 +4385,34 @@ void VmaAllocation_T::FreeUserDataString(VmaAllocator hAllocator) } } +void VmaAllocation_T::BlockAllocMap() +{ + VMA_ASSERT(GetType() == ALLOCATION_TYPE_BLOCK); + + if((m_MapCount & ~MAP_COUNT_FLAG_PERSISTENT_MAP) < 0x7F) + { + ++m_MapCount; + } + else + { + VMA_ASSERT(0 && "Allocation mapped too many times simultaneously."); + } +} + +void VmaAllocation_T::BlockAllocUnmap() +{ + VMA_ASSERT(GetType() == ALLOCATION_TYPE_BLOCK); + + if((m_MapCount & ~MAP_COUNT_FLAG_PERSISTENT_MAP) != 0) + { + --m_MapCount; + } + else + { + VMA_ASSERT(0 && "Unmapping allocation not previously mapped."); + } +} + VkResult VmaAllocation_T::DedicatedAllocMap(VmaAllocator hAllocator, void** ppData) { VMA_ASSERT(GetType() == ALLOCATION_TYPE_DEDICATED); @@ -7454,6 +7484,7 @@ VkResult VmaAllocator_T::Map(VmaAllocation hAllocation, void** ppData) if(res == VK_SUCCESS) { *ppData = pBytes + (ptrdiff_t)hAllocation->GetOffset(); + hAllocation->BlockAllocMap(); } return res; } @@ -7472,6 +7503,7 @@ void VmaAllocator_T::Unmap(VmaAllocation hAllocation) case VmaAllocation_T::ALLOCATION_TYPE_BLOCK: { VmaDeviceMemoryBlock* const pBlock = hAllocation->GetBlock(); + hAllocation->BlockAllocUnmap(); pBlock->Unmap(this); } break;