Skip to content

Commit b0c3636

Browse files
Added function vmaResizeAllocation.
Added tests: function TestResize. Bumped CSV recording file format version to 1.4.
1 parent 1146b45 commit b0c3636

File tree

11 files changed

+530
-17
lines changed

11 files changed

+530
-17
lines changed

docs/Recording file format.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Formats with only minor version incremented are backward compatible.
2323
VmaReplay application supports all older versions.
2424
Current version is:
2525

26-
1,3
26+
1,4
2727

2828
# Configuration
2929

@@ -204,6 +204,11 @@ No parameters.
204204

205205
- pool : pointer
206206

207+
**vmaResizeAllocation** (min format version: 1.4)
208+
209+
- allocation : pointer
210+
- newSize : uint64
211+
207212
# Data types
208213

209214
**bool**
@@ -228,7 +233,7 @@ It should not contain end-of-line characters - results are then undefined.
228233
# Example file
229234

230235
Vulkan Memory Allocator,Calls recording
231-
1,3
236+
1,4
232237
Config,Begin
233238
PhysicalDevice,apiVersion,4198477
234239
PhysicalDevice,driverVersion,8388653
@@ -284,4 +289,4 @@ It should not contain end-of-line characters - results are then undefined.
284289
12552,0.695,0,vmaDestroyImage,000001D85B8B1620
285290
12552,0.695,0,vmaDestroyBuffer,000001D85B8B16C0
286291
12552,0.695,0,vmaDestroyBuffer,000001D85B8B1A80
287-
12552,0.695,0,vmaDestroyAllocator
292+
12552,0.695,0,vmaDestroyAllocator

docs/html/globals.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ <h3><a id="index_v"></a>- v -</h3><ul>
316316
: <a class="el" href="vk__mem__alloc_8h.html#ad63b2113c0bfdbeade1cb498f5a8580d">vk_mem_alloc.h</a>
317317
</li>
318318
<li>VmaPoolCreateFlagBits
319-
: <a class="el" href="vk__mem__alloc_8h.html#a9a7c45f9c863695d98c83fa5ac940fe7">vk_mem_alloc.h</a>
319+
: <a class="el" href="vk__mem__alloc_8h.html#a8f93195158e0e2ac80ca352064e71c1f">vk_mem_alloc.h</a>
320320
</li>
321321
<li>VmaPoolCreateFlags
322322
: <a class="el" href="vk__mem__alloc_8h.html#a2770e325ea42e087c1b91fdf46d0292a">vk_mem_alloc.h</a>
@@ -336,6 +336,9 @@ <h3><a id="index_v"></a>- v -</h3><ul>
336336
<li>VmaRecordSettings
337337
: <a class="el" href="vk__mem__alloc_8h.html#a0ab61e87ff6365f1d59915eadc37a9f0">vk_mem_alloc.h</a>
338338
</li>
339+
<li>vmaResizeAllocation()
340+
: <a class="el" href="vk__mem__alloc_8h.html#a0ff488958ca72b28e545880463cb8696">vk_mem_alloc.h</a>
341+
</li>
339342
<li>vmaSetAllocationUserData()
340343
: <a class="el" href="vk__mem__alloc_8h.html#af9147d31ffc11d62fc187bde283ed14f">vk_mem_alloc.h</a>
341344
</li>

docs/html/globals_func.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,9 @@ <h3><a id="index_v"></a>- v -</h3><ul>
163163
<li>vmaMapMemory()
164164
: <a class="el" href="vk__mem__alloc_8h.html#ad5bd1243512d099706de88168992f069">vk_mem_alloc.h</a>
165165
</li>
166+
<li>vmaResizeAllocation()
167+
: <a class="el" href="vk__mem__alloc_8h.html#a0ff488958ca72b28e545880463cb8696">vk_mem_alloc.h</a>
168+
</li>
166169
<li>vmaSetAllocationUserData()
167170
: <a class="el" href="vk__mem__alloc_8h.html#af9147d31ffc11d62fc187bde283ed14f">vk_mem_alloc.h</a>
168171
</li>

docs/html/search/all_10.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/html/search/functions_0.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/html/vk__mem__alloc_8h.html

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,9 @@
310310
<tr class="memitem:a11f0fbc034fa81a4efedd73d61ce7568"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="vk__mem__alloc_8h.html#a11f0fbc034fa81a4efedd73d61ce7568">vmaFreeMemory</a> (<a class="el" href="struct_vma_allocator.html">VmaAllocator</a> allocator, <a class="el" href="struct_vma_allocation.html">VmaAllocation</a> allocation)</td></tr>
311311
<tr class="memdesc:a11f0fbc034fa81a4efedd73d61ce7568"><td class="mdescLeft">&#160;</td><td class="mdescRight">Frees memory previously allocated using <a class="el" href="vk__mem__alloc_8h.html#abf28077dbf82d0908b8acbe8ee8dd9b8" title="General purpose memory allocation. ">vmaAllocateMemory()</a>, <a class="el" href="vk__mem__alloc_8h.html#a7fdf64415b6c3d83c454f28d2c53df7b">vmaAllocateMemoryForBuffer()</a>, or <a class="el" href="vk__mem__alloc_8h.html#a0faa3f9e5fb233d29d1e00390650febb" title="Function similar to vmaAllocateMemoryForBuffer(). ">vmaAllocateMemoryForImage()</a>. <a href="#a11f0fbc034fa81a4efedd73d61ce7568">More...</a><br /></td></tr>
312312
<tr class="separator:a11f0fbc034fa81a4efedd73d61ce7568"><td class="memSeparator" colspan="2">&#160;</td></tr>
313+
<tr class="memitem:a0ff488958ca72b28e545880463cb8696"><td class="memItemLeft" align="right" valign="top">VkResult&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="vk__mem__alloc_8h.html#a0ff488958ca72b28e545880463cb8696">vmaResizeAllocation</a> (<a class="el" href="struct_vma_allocator.html">VmaAllocator</a> allocator, <a class="el" href="struct_vma_allocation.html">VmaAllocation</a> allocation, VkDeviceSize newSize)</td></tr>
314+
<tr class="memdesc:a0ff488958ca72b28e545880463cb8696"><td class="mdescLeft">&#160;</td><td class="mdescRight">Tries to resize an allocation in place, if there is enough free memory after it. <a href="#a0ff488958ca72b28e545880463cb8696">More...</a><br /></td></tr>
315+
<tr class="separator:a0ff488958ca72b28e545880463cb8696"><td class="memSeparator" colspan="2">&#160;</td></tr>
313316
<tr class="memitem:a86dd08aba8633bfa4ad0df2e76481d8b"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="vk__mem__alloc_8h.html#a86dd08aba8633bfa4ad0df2e76481d8b">vmaGetAllocationInfo</a> (<a class="el" href="struct_vma_allocator.html">VmaAllocator</a> allocator, <a class="el" href="struct_vma_allocation.html">VmaAllocation</a> allocation, <a class="el" href="struct_vma_allocation_info.html">VmaAllocationInfo</a> *pAllocationInfo)</td></tr>
314317
<tr class="memdesc:a86dd08aba8633bfa4ad0df2e76481d8b"><td class="mdescLeft">&#160;</td><td class="mdescRight">Returns current information about specified allocation and atomically marks it as used in current frame. <a href="#a86dd08aba8633bfa4ad0df2e76481d8b">More...</a><br /></td></tr>
315318
<tr class="separator:a86dd08aba8633bfa4ad0df2e76481d8b"><td class="memSeparator" colspan="2">&#160;</td></tr>
@@ -2364,6 +2367,50 @@ <h2 class="memtitle"><span class="permalink"><a href="#ad5bd1243512d099706de8816
23642367
<p>This function fails when used on allocation made in memory type that is not <code>HOST_VISIBLE</code>.</p>
23652368
<p>This function always fails when called for allocation that was created with <a class="el" href="vk__mem__alloc_8h.html#ad9889c10c798b040d59c92f257cae597a5f436af6c8fe8540573a6d22627a6fd2">VMA_ALLOCATION_CREATE_CAN_BECOME_LOST_BIT</a> flag. Such allocations cannot be mapped. </p>
23662369

2370+
</div>
2371+
</div>
2372+
<a id="a0ff488958ca72b28e545880463cb8696"></a>
2373+
<h2 class="memtitle"><span class="permalink"><a href="#a0ff488958ca72b28e545880463cb8696">&#9670;&nbsp;</a></span>vmaResizeAllocation()</h2>
2374+
2375+
<div class="memitem">
2376+
<div class="memproto">
2377+
<table class="memname">
2378+
<tr>
2379+
<td class="memname">VkResult vmaResizeAllocation </td>
2380+
<td>(</td>
2381+
<td class="paramtype"><a class="el" href="struct_vma_allocator.html">VmaAllocator</a>&#160;</td>
2382+
<td class="paramname"><em>allocator</em>, </td>
2383+
</tr>
2384+
<tr>
2385+
<td class="paramkey"></td>
2386+
<td></td>
2387+
<td class="paramtype"><a class="el" href="struct_vma_allocation.html">VmaAllocation</a>&#160;</td>
2388+
<td class="paramname"><em>allocation</em>, </td>
2389+
</tr>
2390+
<tr>
2391+
<td class="paramkey"></td>
2392+
<td></td>
2393+
<td class="paramtype">VkDeviceSize&#160;</td>
2394+
<td class="paramname"><em>newSize</em>&#160;</td>
2395+
</tr>
2396+
<tr>
2397+
<td></td>
2398+
<td>)</td>
2399+
<td></td><td></td>
2400+
</tr>
2401+
</table>
2402+
</div><div class="memdoc">
2403+
2404+
<p>Tries to resize an allocation in place, if there is enough free memory after it. </p>
2405+
<p>Tries to change allocation's size without moving or reallocating it. You can both shrink and grow allocation size. When growing, it succeeds only when the allocation belongs to a memory block with enough free space after it.</p>
2406+
<p>Returns <code>VK_SUCCESS</code> if allocation's size has been successfully changed. Returns <code>VK_ERROR_OUT_OF_POOL_MEMORY</code> if allocation's size could not be changed.</p>
2407+
<p>After successful call to this function, <a class="el" href="struct_vma_allocation_info.html#aac76d113a6a5ccbb09fea00fb25fd18f" title="Size of this allocation, in bytes. ">VmaAllocationInfo::size</a> of this allocation changes. All other parameters stay the same: memory pool and type, alignment, offset, mapped pointer.</p>
2408+
<ul>
2409+
<li>Calling this function on allocation that is in lost state fails with result <code>VK_ERROR_VALIDATION_FAILED_EXT</code>.</li>
2410+
<li>Calling this function with <code>newSize</code> same as current allocation size does nothing and returns <code>VK_SUCCESS</code>.</li>
2411+
<li>Resizing dedicated allocations, as well as allocations created in pools that use linear or buddy algorithm, is not supported. The function returns <code>VK_ERROR_FEATURE_NOT_PRESENT</code> in such cases. Support may be added in the future. </li>
2412+
</ul>
2413+
23672414
</div>
23682415
</div>
23692416
<a id="af9147d31ffc11d62fc187bde283ed14f"></a>

docs/html/vk__mem__alloc_8h_source.html

Lines changed: 10 additions & 9 deletions
Large diffs are not rendered by default.

src/Tests.cpp

Lines changed: 155 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2711,6 +2711,159 @@ static void TestPool_SameSize()
27112711
vmaDestroyPool(g_hAllocator, pool);
27122712
}
27132713

2714+
static void TestResize()
2715+
{
2716+
wprintf(L"Testing vmaResizeAllocation...\n");
2717+
2718+
const VkDeviceSize KILOBYTE = 1024ull;
2719+
const VkDeviceSize MEGABYTE = KILOBYTE * 1024;
2720+
2721+
VkBufferCreateInfo bufCreateInfo = { VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO };
2722+
bufCreateInfo.size = 2 * MEGABYTE;
2723+
bufCreateInfo.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
2724+
2725+
VmaAllocationCreateInfo allocCreateInfo = {};
2726+
allocCreateInfo.usage = VMA_MEMORY_USAGE_CPU_ONLY;
2727+
2728+
uint32_t memTypeIndex = UINT32_MAX;
2729+
TEST( vmaFindMemoryTypeIndexForBufferInfo(g_hAllocator, &bufCreateInfo, &allocCreateInfo, &memTypeIndex) == VK_SUCCESS );
2730+
2731+
VmaPoolCreateInfo poolCreateInfo = {};
2732+
poolCreateInfo.flags = VMA_POOL_CREATE_IGNORE_BUFFER_IMAGE_GRANULARITY_BIT;
2733+
poolCreateInfo.blockSize = 8 * MEGABYTE;
2734+
poolCreateInfo.minBlockCount = 1;
2735+
poolCreateInfo.maxBlockCount = 1;
2736+
poolCreateInfo.memoryTypeIndex = memTypeIndex;
2737+
2738+
VmaPool pool;
2739+
TEST( vmaCreatePool(g_hAllocator, &poolCreateInfo, &pool) == VK_SUCCESS );
2740+
2741+
allocCreateInfo.pool = pool;
2742+
2743+
// Fill 8 MB pool with 4 * 2 MB allocations.
2744+
VmaAllocation allocs[4] = {};
2745+
2746+
VkMemoryRequirements memReq = {};
2747+
memReq.memoryTypeBits = UINT32_MAX;
2748+
memReq.alignment = 4;
2749+
memReq.size = bufCreateInfo.size;
2750+
2751+
VmaAllocationInfo allocInfo = {};
2752+
2753+
for(uint32_t i = 0; i < 4; ++i)
2754+
{
2755+
TEST( vmaAllocateMemory(g_hAllocator, &memReq, &allocCreateInfo, &allocs[i], nullptr) == VK_SUCCESS );
2756+
}
2757+
2758+
// Now it's: a0 2MB, a1 2MB, a2 2MB, a3 2MB
2759+
2760+
// Case: Resize to the same size always succeeds.
2761+
{
2762+
TEST( vmaResizeAllocation(g_hAllocator, allocs[0], 2 * MEGABYTE) == VK_SUCCESS);
2763+
vmaGetAllocationInfo(g_hAllocator, allocs[3], &allocInfo);
2764+
TEST(allocInfo.size == 2ull * 1024 * 1024);
2765+
}
2766+
2767+
// Case: Shrink allocation at the end.
2768+
{
2769+
TEST( vmaResizeAllocation(g_hAllocator, allocs[3], 1 * MEGABYTE) == VK_SUCCESS );
2770+
vmaGetAllocationInfo(g_hAllocator, allocs[3], &allocInfo);
2771+
TEST(allocInfo.size == 1ull * 1024 * 1024);
2772+
}
2773+
2774+
// Now it's: a0 2MB, a1 2MB, a2 2MB, a3 1MB, free 1MB
2775+
2776+
// Case: Shrink allocation before free space.
2777+
{
2778+
TEST( vmaResizeAllocation(g_hAllocator, allocs[3], 512 * KILOBYTE) == VK_SUCCESS );
2779+
vmaGetAllocationInfo(g_hAllocator, allocs[3], &allocInfo);
2780+
TEST(allocInfo.size == 512 * KILOBYTE);
2781+
}
2782+
2783+
// Now it's: a0 2MB, a1 2MB, a2 2MB, a3 0.5MB, free 1.5MB
2784+
2785+
// Case: Shrink allocation before next allocation.
2786+
{
2787+
TEST( vmaResizeAllocation(g_hAllocator, allocs[0], 1 * MEGABYTE) == VK_SUCCESS );
2788+
vmaGetAllocationInfo(g_hAllocator, allocs[0], &allocInfo);
2789+
TEST(allocInfo.size == 1 * MEGABYTE);
2790+
}
2791+
2792+
// Now it's: a0 1MB, free 1 MB, a1 2MB, a2 2MB, a3 0.5MB, free 1.5MB
2793+
2794+
// Case: Grow allocation while there is even more space available.
2795+
{
2796+
TEST( vmaResizeAllocation(g_hAllocator, allocs[3], 1 * MEGABYTE) == VK_SUCCESS );
2797+
vmaGetAllocationInfo(g_hAllocator, allocs[3], &allocInfo);
2798+
TEST(allocInfo.size == 1 * MEGABYTE);
2799+
}
2800+
2801+
// Now it's: a0 1MB, free 1 MB, a1 2MB, a2 2MB, a3 1MB, free 1MB
2802+
2803+
// Case: Grow allocation while there is exact amount of free space available.
2804+
{
2805+
TEST( vmaResizeAllocation(g_hAllocator, allocs[0], 2 * MEGABYTE) == VK_SUCCESS );
2806+
vmaGetAllocationInfo(g_hAllocator, allocs[0], &allocInfo);
2807+
TEST(allocInfo.size == 2 * MEGABYTE);
2808+
}
2809+
2810+
// Now it's: a0 2MB, a1 2MB, a2 2MB, a3 1MB, free 1MB
2811+
2812+
// Case: Fail to grow when there is not enough free space due to next allocation.
2813+
{
2814+
TEST( vmaResizeAllocation(g_hAllocator, allocs[0], 3 * MEGABYTE) == VK_ERROR_OUT_OF_POOL_MEMORY );
2815+
vmaGetAllocationInfo(g_hAllocator, allocs[0], &allocInfo);
2816+
TEST(allocInfo.size == 2 * MEGABYTE);
2817+
}
2818+
2819+
// Case: Fail to grow when there is not enough free space due to end of memory block.
2820+
{
2821+
TEST( vmaResizeAllocation(g_hAllocator, allocs[3], 3 * MEGABYTE) == VK_ERROR_OUT_OF_POOL_MEMORY );
2822+
vmaGetAllocationInfo(g_hAllocator, allocs[3], &allocInfo);
2823+
TEST(allocInfo.size == 1 * MEGABYTE);
2824+
}
2825+
2826+
for(uint32_t i = 4; i--; )
2827+
{
2828+
vmaFreeMemory(g_hAllocator, allocs[i]);
2829+
}
2830+
2831+
vmaDestroyPool(g_hAllocator, pool);
2832+
2833+
// Test dedicated allocation
2834+
{
2835+
VmaAllocationCreateInfo dedicatedAllocCreateInfo = {};
2836+
dedicatedAllocCreateInfo.usage = VMA_MEMORY_USAGE_CPU_ONLY;
2837+
dedicatedAllocCreateInfo.flags = VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT;
2838+
2839+
VmaAllocation dedicatedAlloc = VK_NULL_HANDLE;
2840+
TEST( vmaAllocateMemory(g_hAllocator, &memReq, &dedicatedAllocCreateInfo, &dedicatedAlloc, nullptr) == VK_SUCCESS );
2841+
2842+
// Case: Resize to the same size always succeeds.
2843+
{
2844+
TEST( vmaResizeAllocation(g_hAllocator, dedicatedAlloc, 2 * MEGABYTE) == VK_SUCCESS);
2845+
vmaGetAllocationInfo(g_hAllocator, dedicatedAlloc, &allocInfo);
2846+
TEST(allocInfo.size == 2ull * 1024 * 1024);
2847+
}
2848+
2849+
// Case: Shrinking fails.
2850+
{
2851+
TEST( vmaResizeAllocation(g_hAllocator, dedicatedAlloc, 1 * MEGABYTE) < VK_SUCCESS);
2852+
vmaGetAllocationInfo(g_hAllocator, dedicatedAlloc, &allocInfo);
2853+
TEST(allocInfo.size == 2ull * 1024 * 1024);
2854+
}
2855+
2856+
// Case: Growing fails.
2857+
{
2858+
TEST( vmaResizeAllocation(g_hAllocator, dedicatedAlloc, 3 * MEGABYTE) < VK_SUCCESS);
2859+
vmaGetAllocationInfo(g_hAllocator, dedicatedAlloc, &allocInfo);
2860+
TEST(allocInfo.size == 2ull * 1024 * 1024);
2861+
}
2862+
2863+
vmaFreeMemory(g_hAllocator, dedicatedAlloc);
2864+
}
2865+
}
2866+
27142867
static bool ValidatePattern(const void* pMemory, size_t size, uint8_t pattern)
27152868
{
27162869
const uint8_t* pBytes = (const uint8_t*)pMemory;
@@ -4275,7 +4428,7 @@ void Test()
42754428
// ########################################
42764429
// ########################################
42774430

4278-
BasicTestBuddyAllocator();
4431+
TestResize();
42794432
return;
42804433
}
42814434

@@ -4287,6 +4440,7 @@ void Test()
42874440
#else
42884441
TestPool_SameSize();
42894442
TestHeapSizeLimit();
4443+
TestResize();
42904444
#endif
42914445
#if VMA_DEBUG_INITIALIZE_ALLOCATIONS
42924446
TestAllocationsInitialization();

0 commit comments

Comments
 (0)