Implemented VmaBlockMetadata_Linear::GetSumFreeSize.

This commit is contained in:
Adam Sawicki 2018-08-23 11:20:09 +02:00
parent 1f6c388348
commit 51b0e82e60

View File

@ -4629,7 +4629,7 @@ public:
virtual bool Validate() const; virtual bool Validate() const;
virtual size_t GetAllocationCount() const; virtual size_t GetAllocationCount() const;
virtual VkDeviceSize GetSumFreeSize() const; virtual VkDeviceSize GetSumFreeSize() const { return m_SumFreeSize; }
virtual VkDeviceSize GetUnusedRangeSizeMax() const; virtual VkDeviceSize GetUnusedRangeSizeMax() const;
virtual bool IsEmpty() const { return GetAllocationCount() == 0; } virtual bool IsEmpty() const { return GetAllocationCount() == 0; }
@ -4696,6 +4696,7 @@ private:
SECOND_VECTOR_DOUBLE_STACK, SECOND_VECTOR_DOUBLE_STACK,
}; };
VkDeviceSize m_SumFreeSize;
SuballocationVectorType m_Suballocations0, m_Suballocations1; SuballocationVectorType m_Suballocations0, m_Suballocations1;
uint32_t m_1stVectorIndex; uint32_t m_1stVectorIndex;
SECOND_VECTOR_MODE m_2ndVectorMode; SECOND_VECTOR_MODE m_2ndVectorMode;
@ -7179,6 +7180,7 @@ void VmaBlockMetadata_Generic::UnregisterFreeSuballocation(VmaSuballocationList:
// class VmaBlockMetadata_Linear // class VmaBlockMetadata_Linear
VmaBlockMetadata_Linear::VmaBlockMetadata_Linear(VmaAllocator hAllocator) : VmaBlockMetadata_Linear::VmaBlockMetadata_Linear(VmaAllocator hAllocator) :
m_SumFreeSize(0),
m_Suballocations0(VmaStlAllocator<VmaSuballocation>(hAllocator->GetAllocationCallbacks())), m_Suballocations0(VmaStlAllocator<VmaSuballocation>(hAllocator->GetAllocationCallbacks())),
m_Suballocations1(VmaStlAllocator<VmaSuballocation>(hAllocator->GetAllocationCallbacks())), m_Suballocations1(VmaStlAllocator<VmaSuballocation>(hAllocator->GetAllocationCallbacks())),
m_1stVectorIndex(0), m_1stVectorIndex(0),
@ -7196,6 +7198,7 @@ VmaBlockMetadata_Linear::~VmaBlockMetadata_Linear()
void VmaBlockMetadata_Linear::Init(VkDeviceSize size) void VmaBlockMetadata_Linear::Init(VkDeviceSize size)
{ {
VmaBlockMetadata::Init(size); VmaBlockMetadata::Init(size);
m_SumFreeSize = size;
} }
bool VmaBlockMetadata_Linear::Validate() const bool VmaBlockMetadata_Linear::Validate() const
@ -7234,6 +7237,7 @@ bool VmaBlockMetadata_Linear::Validate() const
} }
} }
VkDeviceSize sumUsedSize = 0;
const size_t suballoc1stCount = suballocations1st.size(); const size_t suballoc1stCount = suballocations1st.size();
VkDeviceSize offset = VMA_DEBUG_MARGIN; VkDeviceSize offset = VMA_DEBUG_MARGIN;
@ -7265,9 +7269,9 @@ bool VmaBlockMetadata_Linear::Validate() const
{ {
return false; return false;
} }
sumUsedSize += suballoc.size;
} }
else
if(currFree)
{ {
++nullItem2ndCount; ++nullItem2ndCount;
} }
@ -7321,9 +7325,9 @@ bool VmaBlockMetadata_Linear::Validate() const
{ {
return false; return false;
} }
sumUsedSize += suballoc.size;
} }
else
if(currFree)
{ {
++nullItem1stCount; ++nullItem1stCount;
} }
@ -7363,9 +7367,9 @@ bool VmaBlockMetadata_Linear::Validate() const
{ {
return false; return false;
} }
sumUsedSize += suballoc.size;
} }
else
if(currFree)
{ {
++nullItem2ndCount; ++nullItem2ndCount;
} }
@ -7383,6 +7387,10 @@ bool VmaBlockMetadata_Linear::Validate() const
{ {
return false; return false;
} }
if(m_SumFreeSize != GetSize() - sumUsedSize)
{
return false;
}
return true; return true;
} }
@ -7393,12 +7401,6 @@ size_t VmaBlockMetadata_Linear::GetAllocationCount() const
AccessSuballocations2nd().size() - m_2ndNullItemsCount; AccessSuballocations2nd().size() - m_2ndNullItemsCount;
} }
VkDeviceSize VmaBlockMetadata_Linear::GetSumFreeSize() const
{
// TODO
return GetSize();
}
VkDeviceSize VmaBlockMetadata_Linear::GetUnusedRangeSizeMax() const VkDeviceSize VmaBlockMetadata_Linear::GetUnusedRangeSizeMax() const
{ {
// TODO // TODO
@ -8486,6 +8488,7 @@ bool VmaBlockMetadata_Linear::MakeRequestedAllocationsLost(
{ {
suballoc.type = VMA_SUBALLOCATION_TYPE_FREE; suballoc.type = VMA_SUBALLOCATION_TYPE_FREE;
suballoc.hAllocation = VK_NULL_HANDLE; suballoc.hAllocation = VK_NULL_HANDLE;
m_SumFreeSize += suballoc.size;
++m_1stNullItemsMiddleCount; ++m_1stNullItemsMiddleCount;
++madeLostCount; ++madeLostCount;
} }
@ -8518,6 +8521,7 @@ uint32_t VmaBlockMetadata_Linear::MakeAllocationsLost(uint32_t currentFrameIndex
suballoc.type = VMA_SUBALLOCATION_TYPE_FREE; suballoc.type = VMA_SUBALLOCATION_TYPE_FREE;
suballoc.hAllocation = VK_NULL_HANDLE; suballoc.hAllocation = VK_NULL_HANDLE;
++m_1stNullItemsMiddleCount; ++m_1stNullItemsMiddleCount;
m_SumFreeSize += suballoc.size;
++lostAllocationCount; ++lostAllocationCount;
} }
} }
@ -8617,6 +8621,8 @@ void VmaBlockMetadata_Linear::Alloc(
} }
} }
} }
m_SumFreeSize -= newSuballoc.size;
} }
void VmaBlockMetadata_Linear::Free(const VmaAllocation allocation) void VmaBlockMetadata_Linear::Free(const VmaAllocation allocation)
@ -8637,6 +8643,7 @@ void VmaBlockMetadata_Linear::FreeAtOffset(VkDeviceSize offset)
{ {
firstSuballoc.type = VMA_SUBALLOCATION_TYPE_FREE; firstSuballoc.type = VMA_SUBALLOCATION_TYPE_FREE;
firstSuballoc.hAllocation = VK_NULL_HANDLE; firstSuballoc.hAllocation = VK_NULL_HANDLE;
m_SumFreeSize += firstSuballoc.size;
++m_1stNullItemsBeginCount; ++m_1stNullItemsBeginCount;
CleanupAfterFree(); CleanupAfterFree();
return; return;
@ -8650,6 +8657,7 @@ void VmaBlockMetadata_Linear::FreeAtOffset(VkDeviceSize offset)
VmaSuballocation& lastSuballoc = suballocations2nd.back(); VmaSuballocation& lastSuballoc = suballocations2nd.back();
if(lastSuballoc.offset == offset) if(lastSuballoc.offset == offset)
{ {
m_SumFreeSize += lastSuballoc.size;
suballocations2nd.pop_back(); suballocations2nd.pop_back();
CleanupAfterFree(); CleanupAfterFree();
return; return;
@ -8661,6 +8669,7 @@ void VmaBlockMetadata_Linear::FreeAtOffset(VkDeviceSize offset)
VmaSuballocation& lastSuballoc = suballocations1st.back(); VmaSuballocation& lastSuballoc = suballocations1st.back();
if(lastSuballoc.offset == offset) if(lastSuballoc.offset == offset)
{ {
m_SumFreeSize += lastSuballoc.size;
suballocations1st.pop_back(); suballocations1st.pop_back();
CleanupAfterFree(); CleanupAfterFree();
return; return;
@ -8677,6 +8686,7 @@ void VmaBlockMetadata_Linear::FreeAtOffset(VkDeviceSize offset)
currSuballoc.type = VMA_SUBALLOCATION_TYPE_FREE; currSuballoc.type = VMA_SUBALLOCATION_TYPE_FREE;
currSuballoc.hAllocation = VK_NULL_HANDLE; currSuballoc.hAllocation = VK_NULL_HANDLE;
++m_1stNullItemsMiddleCount; ++m_1stNullItemsMiddleCount;
m_SumFreeSize += currSuballoc.size;
CleanupAfterFree(); CleanupAfterFree();
return; return;
} }
@ -8694,6 +8704,7 @@ void VmaBlockMetadata_Linear::FreeAtOffset(VkDeviceSize offset)
currSuballoc.type = VMA_SUBALLOCATION_TYPE_FREE; currSuballoc.type = VMA_SUBALLOCATION_TYPE_FREE;
currSuballoc.hAllocation = VK_NULL_HANDLE; currSuballoc.hAllocation = VK_NULL_HANDLE;
++m_2ndNullItemsCount; ++m_2ndNullItemsCount;
m_SumFreeSize += currSuballoc.size;
CleanupAfterFree(); CleanupAfterFree();
return; return;
} }