Implemented vmaMakePoolAllocationsLost for pools with linear allocator.

This commit is contained in:
Adam Sawicki 2018-08-22 17:02:44 +02:00
parent 8cfe05fad9
commit 0ebdf0c63e
2 changed files with 68 additions and 3 deletions

View File

@ -1733,7 +1733,7 @@ static void TestLinearAllocator()
}
// Allocate number of buffers until pool is full again.
// This way we make sure ring buffers wraps around.
// This way we make sure ring buffers wraps around, front in in the middle.
res = VK_SUCCESS;
for(size_t i = 0; res == VK_SUCCESS; ++i)
{
@ -1786,6 +1786,35 @@ static void TestLinearAllocator()
break;
}
// Delete buffers that are lost.
for(size_t i = bufInfo.size(); i--; )
{
vmaGetAllocationInfo(g_hAllocator, bufInfo[i].Allocation, &allocInfo);
if(allocInfo.deviceMemory == VK_NULL_HANDLE)
{
vmaDestroyBuffer(g_hAllocator, bufInfo[i].Buffer, bufInfo[i].Allocation);
bufInfo.erase(bufInfo.begin() + i);
}
}
// Test vmaMakePoolAllocationsLost
{
vmaSetCurrentFrameIndex(g_hAllocator, ++g_FrameIndex);
size_t lostAllocCount = SIZE_MAX;
vmaMakePoolAllocationsLost(g_hAllocator, pool, &lostAllocCount);
assert(lostAllocCount > 0);
size_t realLostAllocCount = 0;
for(size_t i = 0; i < bufInfo.size(); ++i)
{
vmaGetAllocationInfo(g_hAllocator, bufInfo[i].Allocation, &allocInfo);
if(allocInfo.deviceMemory == VK_NULL_HANDLE)
++realLostAllocCount;
}
assert(realLostAllocCount == lostAllocCount);
}
// Destroy all the buffers in forward order.
for(size_t i = 0; i < bufInfo.size(); ++i)
vmaDestroyBuffer(g_hAllocator, bufInfo[i].Buffer, bufInfo[i].Allocation);

View File

@ -8504,8 +8504,44 @@ bool VmaBlockMetadata_Linear::MakeRequestedAllocationsLost(
uint32_t VmaBlockMetadata_Linear::MakeAllocationsLost(uint32_t currentFrameIndex, uint32_t frameInUseCount)
{
VMA_ASSERT(0 && "TODO");
return 0;
uint32_t lostAllocationCount = 0;
SuballocationVectorType& suballocations1st = AccessSuballocations1st();
for(size_t i = m_1stNullItemsBeginCount, count = suballocations1st.size(); i < count; ++i)
{
VmaSuballocation& suballoc = suballocations1st[i];
if(suballoc.type != VMA_SUBALLOCATION_TYPE_FREE &&
suballoc.hAllocation->CanBecomeLost() &&
suballoc.hAllocation->MakeLost(currentFrameIndex, frameInUseCount))
{
suballoc.type = VMA_SUBALLOCATION_TYPE_FREE;
suballoc.hAllocation = VK_NULL_HANDLE;
++m_1stNullItemsMiddleCount;
++lostAllocationCount;
}
}
SuballocationVectorType& suballocations2nd = AccessSuballocations2nd();
for(size_t i = 0, count = suballocations2nd.size(); i < count; ++i)
{
VmaSuballocation& suballoc = suballocations2nd[i];
if(suballoc.type != VMA_SUBALLOCATION_TYPE_FREE &&
suballoc.hAllocation->CanBecomeLost() &&
suballoc.hAllocation->MakeLost(currentFrameIndex, frameInUseCount))
{
suballoc.type = VMA_SUBALLOCATION_TYPE_FREE;
suballoc.hAllocation = VK_NULL_HANDLE;
++m_2ndNullItemsCount;
++lostAllocationCount;
}
}
if(lostAllocationCount)
{
CleanupAfterFree();
}
return lostAllocationCount;
}
VkResult VmaBlockMetadata_Linear::CheckCorruption(const void* pBlockData)