Skip to content

Commit 58face4

Browse files
Changed macro in defragmentation test to more readable lambda.
Code by @medranSolus
1 parent c317c7b commit 58face4

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

src/Tests.cpp

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2716,18 +2716,20 @@ void TestDefragmentationIncrementalComplex()
27162716
std::vector<AllocInfo> additionalAllocations;
27172717
additionalAllocations.reserve(maxAdditionalAllocations);
27182718

2719-
#define MakeAdditionalAllocation() \
2720-
if (additionalAllocations.size() < maxAdditionalAllocations) \
2721-
{ \
2722-
bufCreateInfo.size = align_up<VkDeviceSize>(bufSizeMin + rand.Generate() % (bufSizeMax - bufSizeMin), 16); \
2723-
bufCreateInfo.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_TRANSFER_SRC_BIT; \
2724-
\
2725-
AllocInfo alloc; \
2726-
alloc.CreateBuffer(bufCreateInfo, allocCreateInfo); \
2727-
\
2728-
additionalAllocations.push_back(alloc); \
2729-
vmaSetAllocationUserData(g_hAllocator, alloc.m_Allocation, &additionalAllocations.back()); \
2730-
}
2719+
const auto makeAdditionalAllocation = [&]()
2720+
{
2721+
if (additionalAllocations.size() < maxAdditionalAllocations)
2722+
{
2723+
bufCreateInfo.size = align_up<VkDeviceSize>(bufSizeMin + rand.Generate() % (bufSizeMax - bufSizeMin), 16);
2724+
bufCreateInfo.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
2725+
2726+
AllocInfo alloc;
2727+
alloc.CreateBuffer(bufCreateInfo, allocCreateInfo);
2728+
2729+
additionalAllocations.push_back(alloc);
2730+
vmaSetAllocationUserData(g_hAllocator, alloc.m_Allocation, &additionalAllocations.back());
2731+
}
2732+
};
27312733

27322734
// Defragment using GPU only.
27332735
{
@@ -2738,12 +2740,12 @@ void TestDefragmentationIncrementalComplex()
27382740
VkResult res = vmaBeginDefragmentation(g_hAllocator, &defragInfo, &ctx);
27392741
TEST(res == VK_SUCCESS);
27402742

2741-
MakeAdditionalAllocation();
2743+
makeAdditionalAllocation();
27422744

27432745
VmaDefragmentationPassMoveInfo pass = {};
27442746
while((res = vmaBeginDefragmentationPass(g_hAllocator, ctx, &pass)) == VK_INCOMPLETE)
27452747
{
2746-
MakeAdditionalAllocation();
2748+
makeAdditionalAllocation();
27472749

27482750
// Ignore data outside of test
27492751
for (uint32_t i = 0; i < pass.moveCount; ++i)
@@ -2761,7 +2763,7 @@ void TestDefragmentationIncrementalComplex()
27612763
ProcessDefragmentationPass(pass);
27622764
EndSingleTimeCommands();
27632765

2764-
MakeAdditionalAllocation();
2766+
makeAdditionalAllocation();
27652767

27662768
// Destroy old buffers/images and replace them with new handles.
27672769
for (size_t i = 0; i < pass.moveCount; ++i)
@@ -2796,7 +2798,7 @@ void TestDefragmentationIncrementalComplex()
27962798
break;
27972799
TEST(res == VK_INCOMPLETE);
27982800

2799-
MakeAdditionalAllocation();
2801+
makeAdditionalAllocation();
28002802
}
28012803

28022804
TEST(res == VK_SUCCESS);

0 commit comments

Comments
 (0)