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

Function TestDefragmentationSimple

src/Tests.cpp:1851–2124  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1849}
1850
1851void TestDefragmentationSimple()
1852{
1853 wprintf(L"Test defragmentation simple\n");
1854
1855 RandomNumberGenerator rand(667);
1856
1857 const VkDeviceSize BUF_SIZE = 0x10000;
1858 const VkDeviceSize BLOCK_SIZE = BUF_SIZE * 8;
1859
1860 const VkDeviceSize MIN_BUF_SIZE = 32;
1861 const VkDeviceSize MAX_BUF_SIZE = BUF_SIZE * 4;
1862 auto RandomBufSize = [&]() -> VkDeviceSize
1863 {
1864 return align_up<VkDeviceSize>(rand.Generate() % (MAX_BUF_SIZE - MIN_BUF_SIZE + 1) + MIN_BUF_SIZE, 64);
1865 };
1866
1867 VkBufferCreateInfo bufCreateInfo = { VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO };
1868 bufCreateInfo.size = BUF_SIZE;
1869 bufCreateInfo.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT;
1870
1871 VmaAllocationCreateInfo allocCreateInfo = {};
1872 allocCreateInfo.usage = VMA_MEMORY_USAGE_AUTO;
1873 allocCreateInfo.flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT;
1874
1875 uint32_t memTypeIndex = UINT32_MAX;
1876 vmaFindMemoryTypeIndexForBufferInfo(g_hAllocator, &bufCreateInfo, &allocCreateInfo, &memTypeIndex);
1877
1878 VmaPoolCreateInfo poolCreateInfo = {};
1879 poolCreateInfo.blockSize = BLOCK_SIZE;
1880 poolCreateInfo.memoryTypeIndex = memTypeIndex;
1881
1882 VmaPool pool;
1883 TEST(vmaCreatePool(g_hAllocator, &poolCreateInfo, &pool) == VK_SUCCESS);
1884 allocCreateInfo.pool = pool;
1885
1886 VmaDefragmentationInfo defragInfo = {};
1887 defragInfo.flags = VMA_DEFRAGMENTATION_FLAG_ALGORITHM_FAST_BIT;
1888 defragInfo.pool = pool;
1889
1890 // Defragmentation of empty pool.
1891 {
1892 VmaDefragmentationContext defragCtx = nullptr;
1893 VkResult res = vmaBeginDefragmentation(g_hAllocator, &defragInfo, &defragCtx);
1894 TEST(res == VK_SUCCESS);
1895
1896 VmaDefragmentationPassMoveInfo pass = {};
1897 res = vmaBeginDefragmentationPass(g_hAllocator, defragCtx, &pass);
1898 TEST(res == VK_SUCCESS);
1899
1900 VmaDefragmentationStats defragStats = {};
1901 vmaEndDefragmentation(g_hAllocator, defragCtx, &defragStats);
1902 TEST(defragStats.allocationsMoved == 0 && defragStats.bytesFreed == 0 &&
1903 defragStats.bytesMoved == 0 && defragStats.deviceMemoryBlocksFreed == 0);
1904 }
1905
1906 std::vector<AllocInfo> allocations;
1907
1908 // persistentlyMappedOption = 0 - not persistently mapped.

Callers 1

TestFunction · 0.85

Calls 15

TESTEnum · 0.85
vmaCreatePoolFunction · 0.85
vmaBeginDefragmentationFunction · 0.85
vmaEndDefragmentationFunction · 0.85
CreateBufferFunction · 0.85
DestroyAllocationFunction · 0.85
vmaSetAllocationUserDataFunction · 0.85
DefragmentFunction · 0.85
ValidateAllocationsDataFunction · 0.85
DestroyAllAllocationsFunction · 0.85

Tested by

no test coverage detected