From 58face4cffa0db693e603c9bfc61532dd21d83c6 Mon Sep 17 00:00:00 2001 From: Adam Sawicki Date: Mon, 14 Mar 2022 14:21:59 +0100 Subject: [PATCH] Changed macro in defragmentation test to more readable lambda. Code by @medranSolus --- src/Tests.cpp | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/Tests.cpp b/src/Tests.cpp index 008a530..9c96b68 100644 --- a/src/Tests.cpp +++ b/src/Tests.cpp @@ -2716,18 +2716,20 @@ void TestDefragmentationIncrementalComplex() std::vector additionalAllocations; additionalAllocations.reserve(maxAdditionalAllocations); -#define MakeAdditionalAllocation() \ - if (additionalAllocations.size() < maxAdditionalAllocations) \ - { \ - bufCreateInfo.size = align_up(bufSizeMin + rand.Generate() % (bufSizeMax - bufSizeMin), 16); \ - bufCreateInfo.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_TRANSFER_SRC_BIT; \ - \ - AllocInfo alloc; \ - alloc.CreateBuffer(bufCreateInfo, allocCreateInfo); \ - \ - additionalAllocations.push_back(alloc); \ - vmaSetAllocationUserData(g_hAllocator, alloc.m_Allocation, &additionalAllocations.back()); \ - } + const auto makeAdditionalAllocation = [&]() + { + if (additionalAllocations.size() < maxAdditionalAllocations) + { + bufCreateInfo.size = align_up(bufSizeMin + rand.Generate() % (bufSizeMax - bufSizeMin), 16); + bufCreateInfo.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_TRANSFER_SRC_BIT; + + AllocInfo alloc; + alloc.CreateBuffer(bufCreateInfo, allocCreateInfo); + + additionalAllocations.push_back(alloc); + vmaSetAllocationUserData(g_hAllocator, alloc.m_Allocation, &additionalAllocations.back()); + } + }; // Defragment using GPU only. { @@ -2738,12 +2740,12 @@ void TestDefragmentationIncrementalComplex() VkResult res = vmaBeginDefragmentation(g_hAllocator, &defragInfo, &ctx); TEST(res == VK_SUCCESS); - MakeAdditionalAllocation(); + makeAdditionalAllocation(); VmaDefragmentationPassMoveInfo pass = {}; while((res = vmaBeginDefragmentationPass(g_hAllocator, ctx, &pass)) == VK_INCOMPLETE) { - MakeAdditionalAllocation(); + makeAdditionalAllocation(); // Ignore data outside of test for (uint32_t i = 0; i < pass.moveCount; ++i) @@ -2761,7 +2763,7 @@ void TestDefragmentationIncrementalComplex() ProcessDefragmentationPass(pass); EndSingleTimeCommands(); - MakeAdditionalAllocation(); + makeAdditionalAllocation(); // Destroy old buffers/images and replace them with new handles. for (size_t i = 0; i < pass.moveCount; ++i) @@ -2796,7 +2798,7 @@ void TestDefragmentationIncrementalComplex() break; TEST(res == VK_INCOMPLETE); - MakeAdditionalAllocation(); + makeAdditionalAllocation(); } TEST(res == VK_SUCCESS);