MCPcopy Create free account
hub / github.com/GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator / DefragmentPassEnd

Method DefragmentPassEnd

include/vk_mem_alloc.h:12409–12645  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12407}
12408
12409VkResult VmaDefragmentationContext_T::DefragmentPassEnd(VmaDefragmentationPassMoveInfo& moveInfo)
12410{
12411 VMA_ASSERT(moveInfo.moveCount > 0 ? moveInfo.pMoves != VMA_NULL : true);
12412
12413 VkResult result = VK_SUCCESS;
12414 VmaStlAllocator<FragmentedBlock> blockAllocator(m_MoveAllocator.m_pCallbacks);
12415 VmaVector<FragmentedBlock, VmaStlAllocator<FragmentedBlock>> immovableBlocks(blockAllocator);
12416 VmaVector<FragmentedBlock, VmaStlAllocator<FragmentedBlock>> mappedBlocks(blockAllocator);
12417
12418 VmaAllocator allocator = VMA_NULL;
12419 for (uint32_t i = 0; i < moveInfo.moveCount; ++i)
12420 {
12421 VmaDefragmentationMove& move = moveInfo.pMoves[i];
12422 size_t prevCount = 0;
12423 size_t currentCount = 0;
12424 VkDeviceSize freedBlockSize = 0;
12425
12426 uint32_t vectorIndex = 0;
12427 VmaBlockVector* vector = VMA_NULL;
12428 if (m_PoolBlockVector != VMA_NULL)
12429 {
12430 vector = m_PoolBlockVector;
12431 }
12432 else
12433 {
12434 vectorIndex = move.srcAllocation->GetMemoryTypeIndex();
12435 vector = m_pBlockVectors[vectorIndex];
12436 VMA_ASSERT(vector != VMA_NULL);
12437 }
12438
12439 switch (move.operation)
12440 {
12441 case VMA_DEFRAGMENTATION_MOVE_OPERATION_COPY:
12442 {
12443 uint8_t mapCount = 0;
12444 {
12445 VmaMutexLockWrite swapLock(vector->GetMutex(), vector->GetAllocator()->m_UseMutex);
12446 mapCount = move.srcAllocation->SwapBlockAllocation(vector->m_hAllocator, move.dstTmpAllocation);
12447 }
12448 if (mapCount > 0)
12449 {
12450 allocator = vector->m_hAllocator;
12451 VmaDeviceMemoryBlock* newMapBlock = move.srcAllocation->GetBlock();
12452 bool notPresent = true;
12453 for (FragmentedBlock& block : mappedBlocks)
12454 {
12455 if (block.block == newMapBlock)
12456 {
12457 notPresent = false;
12458 block.data += mapCount;
12459 break;
12460 }
12461 }
12462 if (notPresent)
12463 mappedBlocks.push_back({ mapCount, newMapBlock });
12464 }
12465
12466 // Scope for locks, Free have it's own lock

Callers

nothing calls this directly

Calls 12

GetAllocatorMethod · 0.80
SwapBlockAllocationMethod · 0.80
GetBlockCountMethod · 0.80
MapMethod · 0.80
GetMemoryTypeIndexMethod · 0.45
GetBlockMethod · 0.45
push_backMethod · 0.45
GetSizeMethod · 0.45
FreeMethod · 0.45
IsEmptyMethod · 0.45
clearMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected