@@ -10925,7 +10925,7 @@ class VmaBlockVector
10925
10925
size_t allocationCount,
10926
10926
VmaAllocation* pAllocations);
10927
10927
10928
- void Free(const VmaAllocation hAllocation, bool incrementalSort = true );
10928
+ void Free(const VmaAllocation hAllocation);
10929
10929
10930
10930
#if VMA_STATS_STRING_ENABLED
10931
10931
void PrintDetailedMap(class VmaJsonWriter& json);
@@ -10951,6 +10951,9 @@ class VmaBlockVector
10951
10951
// Incrementally sorted by sumFreeSize, ascending.
10952
10952
VmaVector<VmaDeviceMemoryBlock*, VmaStlAllocator<VmaDeviceMemoryBlock*>> m_Blocks;
10953
10953
uint32_t m_NextBlockId;
10954
+ bool m_IncrementalSort = true;
10955
+
10956
+ void SetIncrementalSort(bool val) { m_IncrementalSort = val; }
10954
10957
10955
10958
VkDeviceSize CalcMaxBlockSize() const;
10956
10959
// Finds and removes given block from vector.
@@ -12622,9 +12625,7 @@ VkResult VmaBlockVector::AllocatePage(
12622
12625
return VK_ERROR_OUT_OF_DEVICE_MEMORY;
12623
12626
}
12624
12627
12625
- void VmaBlockVector::Free(
12626
- const VmaAllocation hAllocation,
12627
- bool incrementalSort)
12628
+ void VmaBlockVector::Free(const VmaAllocation hAllocation)
12628
12629
{
12629
12630
VmaDeviceMemoryBlock* pBlockToDelete = VMA_NULL;
12630
12631
@@ -12684,8 +12685,7 @@ void VmaBlockVector::Free(
12684
12685
}
12685
12686
}
12686
12687
12687
- if (incrementalSort)
12688
- IncrementallySortBlocks();
12688
+ IncrementallySortBlocks();
12689
12689
}
12690
12690
12691
12691
// Destruction of a free block. Deferred until this point, outside of mutex
@@ -12730,6 +12730,8 @@ void VmaBlockVector::Remove(VmaDeviceMemoryBlock* pBlock)
12730
12730
12731
12731
void VmaBlockVector::IncrementallySortBlocks()
12732
12732
{
12733
+ if (!m_IncrementalSort)
12734
+ return;
12733
12735
if (m_Algorithm != VMA_POOL_CREATE_LINEAR_ALGORITHM_BIT)
12734
12736
{
12735
12737
// Bubble sort only until first swap.
@@ -13013,6 +13015,7 @@ VmaDefragmentationContext_T::VmaDefragmentationContext_T(
13013
13015
m_BlockVectorCount = 1;
13014
13016
m_PoolBlockVector = &info.pool->m_BlockVector;
13015
13017
m_pBlockVectors = &m_PoolBlockVector;
13018
+ m_PoolBlockVector->SetIncrementalSort(false);
13016
13019
m_PoolBlockVector->SortByFreeSize();
13017
13020
}
13018
13021
else
@@ -13024,7 +13027,10 @@ VmaDefragmentationContext_T::VmaDefragmentationContext_T(
13024
13027
{
13025
13028
VmaBlockVector* vector = m_pBlockVectors[i];
13026
13029
if (vector != VMA_NULL)
13030
+ {
13031
+ vector->SetIncrementalSort(false);
13027
13032
vector->SortByFreeSize();
13033
+ }
13028
13034
}
13029
13035
}
13030
13036
@@ -13050,6 +13056,20 @@ VmaDefragmentationContext_T::VmaDefragmentationContext_T(
13050
13056
13051
13057
VmaDefragmentationContext_T::~VmaDefragmentationContext_T()
13052
13058
{
13059
+ if (m_PoolBlockVector != VMA_NULL)
13060
+ {
13061
+ m_PoolBlockVector->SetIncrementalSort(true);
13062
+ }
13063
+ else
13064
+ {
13065
+ for (uint32_t i = 0; i < m_BlockVectorCount; ++i)
13066
+ {
13067
+ VmaBlockVector* vector = m_pBlockVectors[i];
13068
+ if (vector != VMA_NULL)
13069
+ vector->SetIncrementalSort(true);
13070
+ }
13071
+ }
13072
+
13053
13073
if (m_AlgorithmState)
13054
13074
{
13055
13075
switch (m_Algorithm)
@@ -13169,7 +13189,7 @@ VkResult VmaDefragmentationContext_T::DefragmentPassEnd(VmaDefragmentationPassMo
13169
13189
prevCount = vector->GetBlockCount();
13170
13190
freedBlockSize = move.dstTmpAllocation->GetBlock()->m_pMetadata->GetSize();
13171
13191
}
13172
- vector->Free(move.dstTmpAllocation, false );
13192
+ vector->Free(move.dstTmpAllocation);
13173
13193
{
13174
13194
VmaMutexLockRead lock(vector->GetMutex(), vector->GetAllocator()->m_UseMutex);
13175
13195
currentCount = vector->GetBlockCount();
@@ -13182,7 +13202,7 @@ VkResult VmaDefragmentationContext_T::DefragmentPassEnd(VmaDefragmentationPassMo
13182
13202
{
13183
13203
m_PassStats.bytesMoved -= move.srcAllocation->GetSize();
13184
13204
--m_PassStats.allocationsMoved;
13185
- vector->Free(move.dstTmpAllocation, false );
13205
+ vector->Free(move.dstTmpAllocation);
13186
13206
13187
13207
VmaDeviceMemoryBlock* newBlock = move.srcAllocation->GetBlock();
13188
13208
bool notPresent = true;
@@ -13208,7 +13228,7 @@ VkResult VmaDefragmentationContext_T::DefragmentPassEnd(VmaDefragmentationPassMo
13208
13228
prevCount = vector->GetBlockCount();
13209
13229
freedBlockSize = move.srcAllocation->GetBlock()->m_pMetadata->GetSize();
13210
13230
}
13211
- vector->Free(move.srcAllocation, false );
13231
+ vector->Free(move.srcAllocation);
13212
13232
{
13213
13233
VmaMutexLockRead lock(vector->GetMutex(), vector->GetAllocator()->m_UseMutex);
13214
13234
currentCount = vector->GetBlockCount();
@@ -13220,7 +13240,7 @@ VkResult VmaDefragmentationContext_T::DefragmentPassEnd(VmaDefragmentationPassMo
13220
13240
VmaMutexLockRead lock(vector->GetMutex(), vector->GetAllocator()->m_UseMutex);
13221
13241
dstBlockSize = move.dstTmpAllocation->GetBlock()->m_pMetadata->GetSize();
13222
13242
}
13223
- vector->Free(move.dstTmpAllocation, false );
13243
+ vector->Free(move.dstTmpAllocation);
13224
13244
{
13225
13245
VmaMutexLockRead lock(vector->GetMutex(), vector->GetAllocator()->m_UseMutex);
13226
13246
freedBlockSize += dstBlockSize * (currentCount - vector->GetBlockCount());
0 commit comments