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

Function Defragment

src/Tests.cpp:1626–1677  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1624}
1625
1626static void Defragment(VmaDefragmentationInfo& defragmentationInfo,
1627 VmaDefragmentationStats* defragmentationStats = nullptr)
1628{
1629 VmaDefragmentationContext defragCtx = nullptr;
1630 VkResult res = vmaBeginDefragmentation(g_hAllocator, &defragmentationInfo, &defragCtx);
1631 TEST(res == VK_SUCCESS);
1632
1633 VmaDefragmentationPassMoveInfo pass = {};
1634 while ((res = vmaBeginDefragmentationPass(g_hAllocator, defragCtx, &pass)) == VK_INCOMPLETE)
1635 {
1636 wprintf(L" Pass: moveCount=%u\n", pass.moveCount);
1637
1638 BeginSingleTimeCommands();
1639 ProcessDefragmentationPass(pass);
1640 EndSingleTimeCommands();
1641
1642 // Destroy old buffers/images and replace them with new handles.
1643 for(size_t i = 0; i < pass.moveCount; ++i)
1644 {
1645 VmaAllocation const alloc = pass.pMoves[i].srcAllocation;
1646 VmaAllocationInfo vmaAllocInfo;
1647 vmaGetAllocationInfo(g_hAllocator, alloc, &vmaAllocInfo);
1648 AllocInfo* allocInfo = (AllocInfo*)vmaAllocInfo.pUserData;
1649 if(pass.pMoves[i].operation != VMA_DEFRAGMENTATION_MOVE_OPERATION_IGNORE)
1650 {
1651 TEST(allocInfo != nullptr && allocInfo->m_DefragmentationMovable);
1652 if (allocInfo->m_Buffer)
1653 {
1654 TEST(allocInfo->m_NewBuffer && !allocInfo->m_Image && !allocInfo->m_NewImage);
1655 vkDestroyBuffer(g_hDevice, allocInfo->m_Buffer, g_Allocs);
1656 allocInfo->m_Buffer = allocInfo->m_NewBuffer;
1657 allocInfo->m_NewBuffer = VK_NULL_HANDLE;
1658 }
1659 else if (allocInfo->m_Image)
1660 {
1661 TEST(allocInfo->m_NewImage && !allocInfo->m_Buffer && !allocInfo->m_NewBuffer);
1662 vkDestroyImage(g_hDevice, allocInfo->m_Image, g_Allocs);
1663 allocInfo->m_Image = allocInfo->m_NewImage;
1664 allocInfo->m_NewImage = VK_NULL_HANDLE;
1665 }
1666 else
1667 assert(0);
1668 }
1669 }
1670 if ((res = vmaEndDefragmentationPass(g_hAllocator, defragCtx, &pass)) == VK_SUCCESS)
1671 break;
1672 TEST(res == VK_INCOMPLETE);
1673 }
1674 TEST(res == VK_SUCCESS);
1675
1676 vmaEndDefragmentation(g_hAllocator, defragCtx, defragmentationStats);
1677}
1678
1679static void ValidateAllocationsData(const AllocInfo* allocs, size_t allocCount)
1680{

Callers 3

TestDefragmentationFullFunction · 0.85
TestDefragmentationGpuFunction · 0.85

Calls 9

vmaBeginDefragmentationFunction · 0.85
TESTEnum · 0.85
BeginSingleTimeCommandsFunction · 0.85
EndSingleTimeCommandsFunction · 0.85
vmaGetAllocationInfoFunction · 0.85
vmaEndDefragmentationFunction · 0.85

Tested by

no test coverage detected