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

Function TestDefragmentationFull

src/Tests.cpp:2466–2531  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2464}
2465
2466void TestDefragmentationFull()
2467{
2468 wprintf(L"Test defragmentation full\n");
2469
2470 std::vector<AllocInfo> allocations;
2471
2472 // Create initial allocations.
2473 for(size_t i = 0; i < 400; ++i)
2474 {
2475 AllocInfo allocation;
2476 CreateAllocation(allocation);
2477 allocations.push_back(allocation);
2478 }
2479
2480 // Delete random allocations
2481 const size_t allocationsToDeletePercent = 80;
2482 size_t allocationsToDelete = allocations.size() * allocationsToDeletePercent / 100;
2483 for(size_t i = 0; i < allocationsToDelete; ++i)
2484 {
2485 size_t index = (size_t)rand() % allocations.size();
2486 DestroyAllocation(allocations[index]);
2487 allocations.erase(allocations.begin() + index);
2488 }
2489 //ValidateAllocationsData(allocations.data(), allocations.size()); // Ultra-slow
2490 //SaveAllocatorStatsToFile(L"Before.csv");
2491
2492 {
2493 std::vector<VmaAllocation> vmaAllocations(allocations.size());
2494 for(size_t i = 0; i < allocations.size(); ++i)
2495 vmaAllocations[i] = allocations[i].m_Allocation;
2496
2497 const size_t nonMovablePercent = 0;
2498 size_t nonMovableCount = vmaAllocations.size() * nonMovablePercent / 100;
2499 for(size_t i = 0; i < nonMovableCount; ++i)
2500 {
2501 size_t index = (size_t)rand() % vmaAllocations.size();
2502 vmaAllocations.erase(vmaAllocations.begin() + index);
2503 }
2504
2505 // Set data for defragmentation retrieval
2506 for (auto& alloc : allocations)
2507 vmaSetAllocationUserData(g_hAllocator, alloc.m_Allocation, &alloc);
2508
2509 VmaDefragmentationInfo defragmentationInfo = {};
2510 defragmentationInfo.flags = VMA_DEFRAGMENTATION_FLAG_ALGORITHM_FULL_BIT;
2511
2512 time_point begTime = std::chrono::high_resolution_clock::now();
2513
2514 VmaDefragmentationStats stats;
2515 Defragment(defragmentationInfo, &stats);
2516
2517 float defragmentDuration = ToFloatSeconds(std::chrono::high_resolution_clock::now() - begTime);
2518
2519 wprintf(L" Moved allocations %u, bytes %llu\n", stats.allocationsMoved, stats.bytesMoved);
2520 wprintf(L" Freed blocks %u, bytes %llu\n", stats.deviceMemoryBlocksFreed, stats.bytesFreed);
2521 wprintf(L" Time: %.2f s\n", defragmentDuration);
2522
2523 //wchar_t fileName[MAX_PATH];

Callers 1

TestFunction · 0.85

Calls 10

CreateAllocationFunction · 0.85
DestroyAllocationFunction · 0.85
vmaSetAllocationUserDataFunction · 0.85
DefragmentFunction · 0.85
ToFloatSecondsFunction · 0.85
DestroyAllAllocationsFunction · 0.85
eraseMethod · 0.80
push_backMethod · 0.45
sizeMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected