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

Function TestDefragmentationGpu

src/Tests.cpp:2539–2634  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2537}
2538
2539static void TestDefragmentationGpu()
2540{
2541 wprintf(L"Test defragmentation GPU\n");
2542
2543 // Create that many allocations to surely fill 3 new blocks of 256 MB.
2544 const VkDeviceSize bufSizeMin = 5ull * 1024 * 1024;
2545 const VkDeviceSize bufSizeMax = 10ull * 1024 * 1024;
2546 const VkDeviceSize totalSize = 3ull * 256 * 1024 * 1024;
2547 const size_t bufCount = (size_t)(totalSize / bufSizeMin);
2548 const size_t percentToLeave = 30;
2549 const size_t percentNonMovable = 3;
2550 RandomNumberGenerator rand = { 234522 };
2551
2552 std::vector<AllocInfo> allocations;
2553 allocations.reserve(bufCount);
2554
2555 VkBufferCreateInfo bufCreateInfo = { VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO };
2556
2557 VmaAllocationCreateInfo allocCreateInfo = {};
2558 allocCreateInfo.usage = VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE;
2559
2560 // Create all intended buffers.
2561 for(size_t i = 0; i < bufCount; ++i)
2562 {
2563 bufCreateInfo.size = align_up(rand.Generate() % (bufSizeMax - bufSizeMin) + bufSizeMin, 32ull);
2564
2565 AllocInfo alloc;
2566
2567 if(rand.Generate() % 100 < percentNonMovable)
2568 {
2569 bufCreateInfo.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT |
2570 VK_BUFFER_USAGE_TRANSFER_DST_BIT |
2571 VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
2572 alloc.m_DefragmentationMovable = false;
2573 }
2574 else
2575 {
2576 // Different usage just to see different color in output from VmaDumpVis.
2577 bufCreateInfo.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT |
2578 VK_BUFFER_USAGE_TRANSFER_DST_BIT |
2579 VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
2580 // And in JSON dump.
2581 }
2582
2583 alloc.CreateBuffer(bufCreateInfo, allocCreateInfo);
2584 alloc.m_StartValue = rand.Generate();
2585 allocations.push_back(alloc);
2586 }
2587
2588 // Destroy some percentage of them.
2589 {
2590 const size_t buffersToDestroy = round_div<size_t>(bufCount * (100 - percentToLeave), 100);
2591 for(size_t i = 0; i < buffersToDestroy; ++i)
2592 {
2593 const size_t index = rand.Generate() % allocations.size();
2594 allocations[index].Destroy();
2595 allocations.erase(allocations.begin() + index);
2596 }

Callers 1

TestFunction · 0.85

Calls 15

align_upFunction · 0.85
vmaSetAllocationUserDataFunction · 0.85
UploadGpuDataFunction · 0.85
SaveAllocatorStatsToFileFunction · 0.85
DefragmentFunction · 0.85
TESTEnum · 0.85
ValidateGpuDataFunction · 0.85
reserveMethod · 0.80
GenerateMethod · 0.80
eraseMethod · 0.80
CreateBufferMethod · 0.45

Tested by

no test coverage detected