Skip to content

Commit 638f42d

Browse files
Rewritten documentation chapter about defragmentation.
1 parent ae39703 commit 638f42d

35 files changed

Lines changed: 569 additions & 383 deletions

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Additional features:
4545
- Custom memory pools: Create a pool with desired parameters (e.g. fixed or limited maximum size) and allocate memory out of it.
4646
- Linear allocator: Create a pool with linear algorithm and use it for much faster allocations and deallocations in free-at-once, stack, double stack, or ring buffer fashion.
4747
- Support for VK_KHR_dedicated_allocation extension: Just enable it and it will be used automatically by the library.
48-
- Defragmentation: Call one function and let the library move data around to free some memory blocks and make your allocations better compacted.
48+
- Defragmentation of GPU and CPU memory: Let the library move data around to free some memory blocks and make your allocations better compacted.
4949
- Lost allocations: Allocate memory with appropriate flags and let the library remove allocations that are not used for many frames to make room for new ones.
5050
- Statistics: Obtain detailed statistics about the amount of memory used, unused, number of allocated blocks, number of allocations etc. - globally, per memory heap, and per memory type.
5151
- Debug annotations: Associate string with name or opaque pointer to your own data with every allocation.

docs/html/defragmentation.html

Lines changed: 36 additions & 6 deletions
Large diffs are not rendered by default.

docs/html/functions.html

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565

6666
<h3><a id="index_a"></a>- a -</h3><ul>
6767
<li>allocationCount
68-
: <a class="el" href="struct_vma_defragmentation_info2.html#ae41a36871f23fdd34df9c72149204c57">VmaDefragmentationInfo2</a>
68+
: <a class="el" href="struct_vma_defragmentation_info2.html#a3cf86ab32c1da779b4923d301a3056ba">VmaDefragmentationInfo2</a>
6969
, <a class="el" href="struct_vma_pool_stats.html#ad1924eb54fffa45e9e0e65670c8fe5eb">VmaPoolStats</a>
7070
, <a class="el" href="struct_vma_stat_info.html#a537741e4d5cdddc1c0ab95ec650afaff">VmaStatInfo</a>
7171
</li>
@@ -78,9 +78,6 @@ <h3><a id="index_a"></a>- a -</h3><ul>
7878
<li>allocationSizeMin
7979
: <a class="el" href="struct_vma_stat_info.html#ade8b40bd3139c04aabd2fc538a356fea">VmaStatInfo</a>
8080
</li>
81-
<li>allocationsLost
82-
: <a class="el" href="struct_vma_defragmentation_stats.html#a87f0adc9588757b1e3ac1815597ace03">VmaDefragmentationStats</a>
83-
</li>
8481
<li>allocationsMoved
8582
: <a class="el" href="struct_vma_defragmentation_stats.html#aefeabf130022008eadd75999478af3f9">VmaDefragmentationStats</a>
8683
</li>
@@ -104,6 +101,13 @@ <h3><a id="index_b"></a>- b -</h3><ul>
104101
</ul>
105102

106103

104+
<h3><a id="index_c"></a>- c -</h3><ul>
105+
<li>commandBuffer
106+
: <a class="el" href="struct_vma_defragmentation_info2.html#a7f71f39590c5316771493d2333f9c1bd">VmaDefragmentationInfo2</a>
107+
</li>
108+
</ul>
109+
110+
107111
<h3><a id="index_d"></a>- d -</h3><ul>
108112
<li>device
109113
: <a class="el" href="struct_vma_allocator_create_info.html#ad924ddd77b04039c88d0c09b0ffcd500">VmaAllocatorCreateInfo</a>
@@ -214,6 +218,12 @@ <h3><a id="index_p"></a>- p -</h3><ul>
214218
<li>pool
215219
: <a class="el" href="struct_vma_allocation_create_info.html#a6272c0555cfd1fe28bff1afeb6190150">VmaAllocationCreateInfo</a>
216220
</li>
221+
<li>poolCount
222+
: <a class="el" href="struct_vma_defragmentation_info2.html#a7e70aa2a1081d849dcc7829b19d3ec9d">VmaDefragmentationInfo2</a>
223+
</li>
224+
<li>pPools
225+
: <a class="el" href="struct_vma_defragmentation_info2.html#a0b3effd57f3fcdeb2ed62210b4ef20e1">VmaDefragmentationInfo2</a>
226+
</li>
217227
<li>pRecordSettings
218228
: <a class="el" href="struct_vma_allocator_create_info.html#ace2aa4877b16a42b0b7673d4e26000ee">VmaAllocatorCreateInfo</a>
219229
</li>
@@ -295,6 +305,9 @@ <h3><a id="index_v"></a>- v -</h3><ul>
295305
<li>vkBindImageMemory
296306
: <a class="el" href="struct_vma_vulkan_functions.html#a1338d96a128a5ade648b8d934907c637">VmaVulkanFunctions</a>
297307
</li>
308+
<li>vkCmdCopyBuffer
309+
: <a class="el" href="struct_vma_vulkan_functions.html#ae5c0db8c89a3b82593dc16aa6a49fa3a">VmaVulkanFunctions</a>
310+
</li>
298311
<li>vkCreateBuffer
299312
: <a class="el" href="struct_vma_vulkan_functions.html#ae8084315a25006271a2edfc3a447519f">VmaVulkanFunctions</a>
300313
</li>

docs/html/functions_vars.html

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565

6666
<h3><a id="index_a"></a>- a -</h3><ul>
6767
<li>allocationCount
68-
: <a class="el" href="struct_vma_defragmentation_info2.html#ae41a36871f23fdd34df9c72149204c57">VmaDefragmentationInfo2</a>
68+
: <a class="el" href="struct_vma_defragmentation_info2.html#a3cf86ab32c1da779b4923d301a3056ba">VmaDefragmentationInfo2</a>
6969
, <a class="el" href="struct_vma_pool_stats.html#ad1924eb54fffa45e9e0e65670c8fe5eb">VmaPoolStats</a>
7070
, <a class="el" href="struct_vma_stat_info.html#a537741e4d5cdddc1c0ab95ec650afaff">VmaStatInfo</a>
7171
</li>
@@ -78,9 +78,6 @@ <h3><a id="index_a"></a>- a -</h3><ul>
7878
<li>allocationSizeMin
7979
: <a class="el" href="struct_vma_stat_info.html#ade8b40bd3139c04aabd2fc538a356fea">VmaStatInfo</a>
8080
</li>
81-
<li>allocationsLost
82-
: <a class="el" href="struct_vma_defragmentation_stats.html#a87f0adc9588757b1e3ac1815597ace03">VmaDefragmentationStats</a>
83-
</li>
8481
<li>allocationsMoved
8582
: <a class="el" href="struct_vma_defragmentation_stats.html#aefeabf130022008eadd75999478af3f9">VmaDefragmentationStats</a>
8683
</li>
@@ -104,6 +101,13 @@ <h3><a id="index_b"></a>- b -</h3><ul>
104101
</ul>
105102

106103

104+
<h3><a id="index_c"></a>- c -</h3><ul>
105+
<li>commandBuffer
106+
: <a class="el" href="struct_vma_defragmentation_info2.html#a7f71f39590c5316771493d2333f9c1bd">VmaDefragmentationInfo2</a>
107+
</li>
108+
</ul>
109+
110+
107111
<h3><a id="index_d"></a>- d -</h3><ul>
108112
<li>device
109113
: <a class="el" href="struct_vma_allocator_create_info.html#ad924ddd77b04039c88d0c09b0ffcd500">VmaAllocatorCreateInfo</a>
@@ -214,6 +218,12 @@ <h3><a id="index_p"></a>- p -</h3><ul>
214218
<li>pool
215219
: <a class="el" href="struct_vma_allocation_create_info.html#a6272c0555cfd1fe28bff1afeb6190150">VmaAllocationCreateInfo</a>
216220
</li>
221+
<li>poolCount
222+
: <a class="el" href="struct_vma_defragmentation_info2.html#a7e70aa2a1081d849dcc7829b19d3ec9d">VmaDefragmentationInfo2</a>
223+
</li>
224+
<li>pPools
225+
: <a class="el" href="struct_vma_defragmentation_info2.html#a0b3effd57f3fcdeb2ed62210b4ef20e1">VmaDefragmentationInfo2</a>
226+
</li>
217227
<li>pRecordSettings
218228
: <a class="el" href="struct_vma_allocator_create_info.html#ace2aa4877b16a42b0b7673d4e26000ee">VmaAllocatorCreateInfo</a>
219229
</li>
@@ -295,6 +305,9 @@ <h3><a id="index_v"></a>- v -</h3><ul>
295305
<li>vkBindImageMemory
296306
: <a class="el" href="struct_vma_vulkan_functions.html#a1338d96a128a5ade648b8d934907c637">VmaVulkanFunctions</a>
297307
</li>
308+
<li>vkCmdCopyBuffer
309+
: <a class="el" href="struct_vma_vulkan_functions.html#ae5c0db8c89a3b82593dc16aa6a49fa3a">VmaVulkanFunctions</a>
310+
</li>
298311
<li>vkCreateBuffer
299312
: <a class="el" href="struct_vma_vulkan_functions.html#ae8084315a25006271a2edfc3a447519f">VmaVulkanFunctions</a>
300313
</li>

docs/html/general_considerations.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ <h1><a class="anchor" id="general_considerations_validation_layer_warnings"></a>
9191
</li>
9292
<li><em>Non-linear image 0xebc91 is aliased with linear buffer 0xeb8e4 which may indicate a bug.</em><ul>
9393
<li>It happens when you use lost allocations, and a new image or buffer is created in place of an existing object that bacame lost.</li>
94+
<li>It may happen also when you use <a class="el" href="defragmentation.html">defragmentation</a>.</li>
9495
</ul>
9596
</li>
9697
</ul>
@@ -111,7 +112,7 @@ <h1><a class="anchor" id="general_considerations_features_not_supported"></a>
111112
<p>Features deliberately excluded from the scope of this library:</p>
112113
<ul>
113114
<li>Support for sparse binding and sparse residency. You can still use these features (when supported by the device) with VMA. You just need to do it yourself. Allocate memory pages with <a class="el" href="vk__mem__alloc_8h.html#abf28077dbf82d0908b8acbe8ee8dd9b8" title="General purpose memory allocation. ">vmaAllocateMemory()</a>. Any explicit support for sparse binding/residency would rather require another, higher-level library on top of VMA.</li>
114-
<li>Data transfer - issuing commands that transfer data between buffers or images, any usage of <code>VkCommandList</code> or <code>VkQueue</code> and related synchronization is responsibility of the user.</li>
115+
<li>Data transfer - issuing commands that transfer data between buffers or images, any usage of <code>VkCommandBuffer</code> or <code>VkQueue</code> and related synchronization is responsibility of the user.</li>
115116
<li>Allocations for imported/exported external memory. They tend to require explicit memory type index and dedicated allocation anyway, so they don't interact with main features of this library. Such special purpose allocations should be made manually, using <code>vkCreateBuffer()</code> and <code>vkAllocateMemory()</code>.</li>
116117
<li>Recreation of buffers and images. Although the library has functions for buffer and image creation (<a class="el" href="vk__mem__alloc_8h.html#ac72ee55598617e8eecca384e746bab51">vmaCreateBuffer()</a>, <a class="el" href="vk__mem__alloc_8h.html#a02a94f25679275851a53e82eacbcfc73" title="Function similar to vmaCreateBuffer(). ">vmaCreateImage()</a>), you need to recreate these objects yourself after defragmentation. That's because the big structures <code>VkBufferCreateInfo</code>, <code>VkImageCreateInfo</code> are not stored in <a class="el" href="struct_vma_allocation.html" title="Represents single memory allocation. ">VmaAllocation</a> object.</li>
117118
<li>Handling CPU memory allocation failures. When dynamically creating small C++ objects in CPU memory (not Vulkan memory), allocation failures are not checked and handled gracefully, because that would complicate code significantly and is usually not needed in desktop PC applications anyway.</li>

docs/html/globals.html

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -138,21 +138,9 @@ <h3><a id="index_v"></a>- v -</h3><ul>
138138
<li>VMA_DEDICATED_ALLOCATION
139139
: <a class="el" href="vk__mem__alloc_8h.html#af7b860e63b96d11e44ae8587ba06bbf4">vk_mem_alloc.h</a>
140140
</li>
141-
<li>VMA_DEFRAGMENTATION_ALGORITHM_MASK
142-
: <a class="el" href="vk__mem__alloc_8h.html#a6552a65b71d16f378c6994b3ceaef50cad5069876a2b8b45065b91e43ef906c1d">vk_mem_alloc.h</a>
143-
</li>
144-
<li>VMA_DEFRAGMENTATION_CAN_MAKE_LOST_BIT
145-
: <a class="el" href="vk__mem__alloc_8h.html#a6552a65b71d16f378c6994b3ceaef50ca4e406da317f64208d0b26eb82c8d8071">vk_mem_alloc.h</a>
146-
</li>
147-
<li>VMA_DEFRAGMENTATION_FAST_ALGORITHM_BIT
148-
: <a class="el" href="vk__mem__alloc_8h.html#a6552a65b71d16f378c6994b3ceaef50ca72611a502fd73f59c478475a3e18ca7f">vk_mem_alloc.h</a>
149-
</li>
150141
<li>VMA_DEFRAGMENTATION_FLAG_BITS_MAX_ENUM
151142
: <a class="el" href="vk__mem__alloc_8h.html#a6552a65b71d16f378c6994b3ceaef50cab87ec33154803bfeb5ac2b379f1d6a97">vk_mem_alloc.h</a>
152143
</li>
153-
<li>VMA_DEFRAGMENTATION_OPTIMAL_ALGORITHM_BIT
154-
: <a class="el" href="vk__mem__alloc_8h.html#a6552a65b71d16f378c6994b3ceaef50cacf7eb65ad6d2423ebe2ca3f56bb77a46">vk_mem_alloc.h</a>
155-
</li>
156144
<li>VMA_MEMORY_USAGE_CPU_ONLY
157145
: <a class="el" href="vk__mem__alloc_8h.html#aa5846affa1e9da3800e3e78fae2305cca40bdf4cddeffeb12f43d45ca1286e0a5">vk_mem_alloc.h</a>
158146
</li>
@@ -271,7 +259,7 @@ <h3><a id="index_v"></a>- v -</h3><ul>
271259
: <a class="el" href="vk__mem__alloc_8h.html#a8774e20e91e245aae959ba63efa15dd2">vk_mem_alloc.h</a>
272260
</li>
273261
<li>VmaDefragmentationFlagBits
274-
: <a class="el" href="vk__mem__alloc_8h.html#a6552a65b71d16f378c6994b3ceaef50c">vk_mem_alloc.h</a>
262+
: <a class="el" href="vk__mem__alloc_8h.html#a96df0eddab2e1735782fe4e7cd05ea7f">vk_mem_alloc.h</a>
275263
</li>
276264
<li>VmaDefragmentationFlags
277265
: <a class="el" href="vk__mem__alloc_8h.html#a88a77cef37e5d3c4fc9eb328885d048d">vk_mem_alloc.h</a>
@@ -358,7 +346,7 @@ <h3><a id="index_v"></a>- v -</h3><ul>
358346
: <a class="el" href="vk__mem__alloc_8h.html#a2e5612d871d64c5624087b837a338c34">vk_mem_alloc.h</a>
359347
</li>
360348
<li>VmaRecordFlagBits
361-
: <a class="el" href="vk__mem__alloc_8h.html#ade20b626a6635ce1bf30ea53dea774e4">vk_mem_alloc.h</a>
349+
: <a class="el" href="vk__mem__alloc_8h.html#a4dd2c44642312a147a4e93373a6e64d2">vk_mem_alloc.h</a>
362350
</li>
363351
<li>VmaRecordFlags
364352
: <a class="el" href="vk__mem__alloc_8h.html#af3929a1a4547c592fc0b0e55ef452828">vk_mem_alloc.h</a>

docs/html/globals_eval.html

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -118,21 +118,9 @@ <h3><a id="index_v"></a>- v -</h3><ul>
118118
<li>VMA_ALLOCATOR_CREATE_KHR_DEDICATED_ALLOCATION_BIT
119119
: <a class="el" href="vk__mem__alloc_8h.html#a4f87c9100d154a65a4ad495f7763cf7cace7da7cc6e71a625dfa763c55a597878">vk_mem_alloc.h</a>
120120
</li>
121-
<li>VMA_DEFRAGMENTATION_ALGORITHM_MASK
122-
: <a class="el" href="vk__mem__alloc_8h.html#a6552a65b71d16f378c6994b3ceaef50cad5069876a2b8b45065b91e43ef906c1d">vk_mem_alloc.h</a>
123-
</li>
124-
<li>VMA_DEFRAGMENTATION_CAN_MAKE_LOST_BIT
125-
: <a class="el" href="vk__mem__alloc_8h.html#a6552a65b71d16f378c6994b3ceaef50ca4e406da317f64208d0b26eb82c8d8071">vk_mem_alloc.h</a>
126-
</li>
127-
<li>VMA_DEFRAGMENTATION_FAST_ALGORITHM_BIT
128-
: <a class="el" href="vk__mem__alloc_8h.html#a6552a65b71d16f378c6994b3ceaef50ca72611a502fd73f59c478475a3e18ca7f">vk_mem_alloc.h</a>
129-
</li>
130121
<li>VMA_DEFRAGMENTATION_FLAG_BITS_MAX_ENUM
131122
: <a class="el" href="vk__mem__alloc_8h.html#a6552a65b71d16f378c6994b3ceaef50cab87ec33154803bfeb5ac2b379f1d6a97">vk_mem_alloc.h</a>
132123
</li>
133-
<li>VMA_DEFRAGMENTATION_OPTIMAL_ALGORITHM_BIT
134-
: <a class="el" href="vk__mem__alloc_8h.html#a6552a65b71d16f378c6994b3ceaef50cacf7eb65ad6d2423ebe2ca3f56bb77a46">vk_mem_alloc.h</a>
135-
</li>
136124
<li>VMA_MEMORY_USAGE_CPU_ONLY
137125
: <a class="el" href="vk__mem__alloc_8h.html#aa5846affa1e9da3800e3e78fae2305cca40bdf4cddeffeb12f43d45ca1286e0a5">vk_mem_alloc.h</a>
138126
</li>

docs/html/index.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,12 @@ <h1><a class="anchor" id="main_table_of_contents"></a>
105105
<li><a class="el" href="custom_memory_pools.html#buddy_algorithm">Buddy allocation algorithm</a></li>
106106
</ul>
107107
</li>
108-
<li><a class="el" href="defragmentation.html">Defragmentation</a></li>
108+
<li><a class="el" href="defragmentation.html">Defragmentation</a><ul>
109+
<li><a class="el" href="defragmentation.html#defragmentation_cpu">Defragmenting CPU memory</a></li>
110+
<li><a class="el" href="defragmentation.html#defragmentation_gpu">Defragmenting GPU memory</a></li>
111+
<li><a class="el" href="defragmentation.html#defragmentation_additional_notes">Additional notes</a></li>
112+
</ul>
113+
</li>
109114
<li><a class="el" href="lost_allocations.html">Lost allocations</a></li>
110115
<li><a class="el" href="statistics.html">Statistics</a><ul>
111116
<li><a class="el" href="statistics.html#statistics_numeric_statistics">Numeric statistics</a></li>

docs/html/menudata.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ var menudata={children:[
3131
{text:"All",url:"functions.html",children:[
3232
{text:"a",url:"functions.html#index_a"},
3333
{text:"b",url:"functions.html#index_b"},
34+
{text:"c",url:"functions.html#index_c"},
3435
{text:"d",url:"functions.html#index_d"},
3536
{text:"f",url:"functions.html#index_f"},
3637
{text:"m",url:"functions.html#index_m"},
@@ -44,6 +45,7 @@ var menudata={children:[
4445
{text:"Variables",url:"functions_vars.html",children:[
4546
{text:"a",url:"functions_vars.html#index_a"},
4647
{text:"b",url:"functions_vars.html#index_b"},
48+
{text:"c",url:"functions_vars.html#index_c"},
4749
{text:"d",url:"functions_vars.html#index_d"},
4850
{text:"f",url:"functions_vars.html#index_f"},
4951
{text:"m",url:"functions_vars.html#index_m"},

docs/html/search/all_0.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
var searchData=
22
[
33
['allocation_20names_20and_20user_20data',['Allocation names and user data',['../allocation_annotation.html',1,'index']]],
4-
['allocationcount',['allocationCount',['../struct_vma_stat_info.html#a537741e4d5cdddc1c0ab95ec650afaff',1,'VmaStatInfo::allocationCount()'],['../struct_vma_pool_stats.html#ad1924eb54fffa45e9e0e65670c8fe5eb',1,'VmaPoolStats::allocationCount()'],['../struct_vma_defragmentation_info2.html#ae41a36871f23fdd34df9c72149204c57',1,'VmaDefragmentationInfo2::allocationCount()']]],
4+
['allocationcount',['allocationCount',['../struct_vma_stat_info.html#a537741e4d5cdddc1c0ab95ec650afaff',1,'VmaStatInfo::allocationCount()'],['../struct_vma_pool_stats.html#ad1924eb54fffa45e9e0e65670c8fe5eb',1,'VmaPoolStats::allocationCount()'],['../struct_vma_defragmentation_info2.html#a3cf86ab32c1da779b4923d301a3056ba',1,'VmaDefragmentationInfo2::allocationCount()']]],
55
['allocationsizeavg',['allocationSizeAvg',['../struct_vma_stat_info.html#a1081a039964e566c672e7a2347f9e599',1,'VmaStatInfo']]],
66
['allocationsizemax',['allocationSizeMax',['../struct_vma_stat_info.html#a17e9733a5ecd76287d4db6e66f71f50c',1,'VmaStatInfo']]],
77
['allocationsizemin',['allocationSizeMin',['../struct_vma_stat_info.html#ade8b40bd3139c04aabd2fc538a356fea',1,'VmaStatInfo']]],
8-
['allocationslost',['allocationsLost',['../struct_vma_defragmentation_stats.html#a87f0adc9588757b1e3ac1815597ace03',1,'VmaDefragmentationStats']]],
98
['allocationsmoved',['allocationsMoved',['../struct_vma_defragmentation_stats.html#aefeabf130022008eadd75999478af3f9',1,'VmaDefragmentationStats']]]
109
];

0 commit comments

Comments
 (0)