Small refactoring: Removed function VmaBlockVector::DestroyDefragmentator.

This commit is contained in:
Adam Sawicki 2018-10-10 16:49:36 +02:00
parent f863a1dbd0
commit 6826f2d768

View file

@ -5519,13 +5519,12 @@ public:
VmaAllocator hAllocator, VmaAllocator hAllocator,
uint32_t currentFrameIndex); uint32_t currentFrameIndex);
// If m_pDefragmentator is not null, uses it to defragment and destroys it.
VkResult Defragment( VkResult Defragment(
VmaDefragmentationStats* pDefragmentationStats, VmaDefragmentationStats* pDefragmentationStats,
VkDeviceSize& maxBytesToMove, VkDeviceSize& maxBytesToMove,
uint32_t& maxAllocationsToMove); uint32_t& maxAllocationsToMove);
void DestroyDefragmentator();
private: private:
friend class VmaDefragmentationAlgorithm; friend class VmaDefragmentationAlgorithm;
friend class VmaDefragmentator; friend class VmaDefragmentator;
@ -11157,41 +11156,39 @@ VkResult VmaBlockVector::Defragment(
} }
// Free empty blocks. // Free empty blocks.
m_HasEmptyBlock = false; if(result >= 0)
for(size_t blockIndex = m_Blocks.size(); blockIndex--; )
{ {
VmaDeviceMemoryBlock* pBlock = m_Blocks[blockIndex]; m_HasEmptyBlock = false;
if(pBlock->m_pMetadata->IsEmpty()) for(size_t blockIndex = m_Blocks.size(); blockIndex--; )
{ {
if(m_Blocks.size() > m_MinBlockCount) VmaDeviceMemoryBlock* pBlock = m_Blocks[blockIndex];
if(pBlock->m_pMetadata->IsEmpty())
{ {
if(pDefragmentationStats != VMA_NULL) if(m_Blocks.size() > m_MinBlockCount)
{ {
++pDefragmentationStats->deviceMemoryBlocksFreed; if(pDefragmentationStats != VMA_NULL)
pDefragmentationStats->bytesFreed += pBlock->m_pMetadata->GetSize(); {
} ++pDefragmentationStats->deviceMemoryBlocksFreed;
pDefragmentationStats->bytesFreed += pBlock->m_pMetadata->GetSize();
}
VmaVectorRemove(m_Blocks, blockIndex); VmaVectorRemove(m_Blocks, blockIndex);
pBlock->Destroy(m_hAllocator); pBlock->Destroy(m_hAllocator);
vma_delete(m_hAllocator, pBlock); vma_delete(m_hAllocator, pBlock);
} }
else else
{ {
m_HasEmptyBlock = true; m_HasEmptyBlock = true;
}
} }
} }
} }
return result; // Destroy defragmentator.
} vma_delete(m_hAllocator, m_pDefragmentator);
m_pDefragmentator = VMA_NULL;
void VmaBlockVector::DestroyDefragmentator() return result;
{
if(m_pDefragmentator != VMA_NULL)
{
vma_delete(m_hAllocator, m_pDefragmentator);
m_pDefragmentator = VMA_NULL;
}
} }
void VmaBlockVector::MakePoolAllocationsLost( void VmaBlockVector::MakePoolAllocationsLost(
@ -12898,7 +12895,7 @@ VkResult VmaAllocator_T::DefragmentationBegin(
VkResult result = VK_SUCCESS; VkResult result = VK_SUCCESS;
// ======== Main processing - call Defragment on block vectors. // Main processing: Call Defragment on block vectors.
VkDeviceSize maxBytesToMove = info.maxCpuBytesToMove; VkDeviceSize maxBytesToMove = info.maxCpuBytesToMove;
uint32_t maxAllocationsToMove = info.maxCpuAllocationsToMove; uint32_t maxAllocationsToMove = info.maxCpuAllocationsToMove;
@ -12927,23 +12924,6 @@ VkResult VmaAllocator_T::DefragmentationBegin(
maxAllocationsToMove); maxAllocationsToMove);
} }
// ======== Destroy defragmentators (regardless of result).
// Process custom pools.
for(size_t poolIndex = poolCount; poolIndex--; )
{
m_Pools[poolIndex]->m_BlockVector.DestroyDefragmentator();
}
// Process standard memory.
for(uint32_t memTypeIndex = GetMemoryTypeCount(); memTypeIndex--; )
{
if((m_MemProps.memoryTypes[memTypeIndex].propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) != 0)
{
m_pBlockVectors[memTypeIndex]->DestroyDefragmentator();
}
}
return result; return result;
} }