Skip to content

Commit 072d660

Browse files
Merge branch 'development'
# Conflicts: # src/vk_mem_alloc.h
2 parents f95e85e + 3951aa5 commit 072d660

14 files changed

Lines changed: 1856 additions & 524 deletions

docs/gfx/Buddy_allocator.png

3.83 KB
Loading

docs/html/custom_memory_pools.html

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,23 @@ <h2><a class="anchor" id="linear_algorithm_ring_buffer"></a>
141141
<div class="image">
142142
<img src="../gfx/Linear_allocator_6_ring_buffer_lost.png" alt="Ring buffer with lost allocations"/>
143143
</div>
144-
<p>Ring buffer is available only in pools with one memory block - <a class="el" href="struct_vma_pool_create_info.html#ae41142f2834fcdc82baa4883c187b75c" title="Maximum number of blocks that can be allocated in this pool. Optional. ">VmaPoolCreateInfo::maxBlockCount</a> must be 1. Otherwise behavior is undefined. </p>
144+
<p>Ring buffer is available only in pools with one memory block - <a class="el" href="struct_vma_pool_create_info.html#ae41142f2834fcdc82baa4883c187b75c" title="Maximum number of blocks that can be allocated in this pool. Optional. ">VmaPoolCreateInfo::maxBlockCount</a> must be 1. Otherwise behavior is undefined.</p>
145+
<h1><a class="anchor" id="buddy_algorithm"></a>
146+
Buddy allocation algorithm</h1>
147+
<p>There is another allocation algorithm that can be used with custom pools, called "buddy". Its internal data structure is based on a tree of blocks, each having size that is a power of two and a half of its parent's size. When you want to allocate memory of certain size, a free node in the tree is located. If it's too large, it is recursively split into two halves (called "buddies"). However, if requested allocation size is not a power of two, the size of a tree node is aligned up to the nearest power of two and the remaining space is wasted. When two buddy nodes become free, they are merged back into one larger node.</p>
148+
<div class="image">
149+
<img src="../gfx/Buddy_allocator.png" alt="Buddy allocator"/>
150+
</div>
151+
<p>The advantage of buddy allocation algorithm over default algorithm is faster allocation and deallocation, as well as smaller external fragmentation. The disadvantage is more wasted space (internal fragmentation).</p>
152+
<p>For more information, please read <a href="https://en.wikipedia.org/wiki/Buddy_memory_allocation">"Buddy memory allocation" on Wikipedia</a> or other sources that describe this concept in general.</p>
153+
<p>To use buddy allocation algorithm with a custom pool, add flag <a class="el" href="vk__mem__alloc_8h.html#a9a7c45f9c863695d98c83fa5ac940fe7a97a0dc38e5161b780594d998d313d35e" title="Enables alternative, buddy allocation algorithm in this pool. ">VMA_POOL_CREATE_BUDDY_ALGORITHM_BIT</a> to <a class="el" href="struct_vma_pool_create_info.html#a8405139f63d078340ae74513a59f5446" title="Use combination of VmaPoolCreateFlagBits. ">VmaPoolCreateInfo::flags</a> while creating <a class="el" href="struct_vma_pool.html" title="Represents custom memory pool. ">VmaPool</a> object.</p>
154+
<p>Several limitations apply to pools that use buddy algorithm:</p>
155+
<ul>
156+
<li>It is recommended to use <a class="el" href="struct_vma_pool_create_info.html#aa4265160536cdb9be821b7686c16c676" title="Size of a single VkDeviceMemory block to be allocated as part of this pool, in bytes. Optional. ">VmaPoolCreateInfo::blockSize</a> that is a power of two. Otherwise, only largest power of two smaller than the size is used for allocations. The remaining space always stays unused.</li>
157+
<li><a class="el" href="debugging_memory_usage.html#debugging_memory_usage_margins">Margins</a> and <a class="el" href="debugging_memory_usage.html#debugging_memory_usage_corruption_detection">corruption detection</a> don't work in such pools.</li>
158+
<li><a class="el" href="lost_allocations.html">Lost allocations</a> don't work in such pools. You can use them, but they never become lost. Support may be added in the future.</li>
159+
<li><a class="el" href="defragmentation.html">Defragmentation</a> doesn't work with allocations made from such pool. </li>
160+
</ul>
145161
</div></div><!-- contents -->
146162
<!-- start footer part -->
147163
<hr class="footer"/><address class="footer"><small>

docs/html/debugging_memory_usage.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ <h1><a class="anchor" id="debugging_memory_usage_margins"></a>
8989
<p>If your bug goes away after enabling margins, it means it may be caused by memory being overwritten outside of allocation boundaries. It is not 100% certain though. Change in application behavior may also be caused by different order and distribution of allocations across memory blocks after margins are applied.</p>
9090
<p>The margin is applied also before first and after last allocation in a block. It may occur only once between two adjacent allocations.</p>
9191
<p>Margins work with all types of memory.</p>
92-
<p>Margin is applied only to allocations made out of memory blocks and not to dedicated allocations, which have their own memory block of specific size. It is thus not applied to allocations made using <a class="el" href="vk__mem__alloc_8h.html#ad9889c10c798b040d59c92f257cae597a3fc311d855c2ff53f1090ef5c722b38f" title="Set this flag if the allocation should have its own memory block. ">VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT</a> flag or those automatically decided to put into dedicated allocations, e.g. due to its large size or recommended by VK_KHR_dedicated_allocation extension.</p>
92+
<p>Margin is applied only to allocations made out of memory blocks and not to dedicated allocations, which have their own memory block of specific size. It is thus not applied to allocations made using <a class="el" href="vk__mem__alloc_8h.html#ad9889c10c798b040d59c92f257cae597a3fc311d855c2ff53f1090ef5c722b38f" title="Set this flag if the allocation should have its own memory block. ">VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT</a> flag or those automatically decided to put into dedicated allocations, e.g. due to its large size or recommended by VK_KHR_dedicated_allocation extension. Margins are also not active in custom pools created with <a class="el" href="vk__mem__alloc_8h.html#a9a7c45f9c863695d98c83fa5ac940fe7a97a0dc38e5161b780594d998d313d35e" title="Enables alternative, buddy allocation algorithm in this pool. ">VMA_POOL_CREATE_BUDDY_ALGORITHM_BIT</a> flag.</p>
9393
<p>Margins appear in <a class="el" href="statistics.html#statistics_json_dump">JSON dump</a> as part of free space.</p>
9494
<p>Note that enabling margins increases memory usage and fragmentation.</p>
9595
<h1><a class="anchor" id="debugging_memory_usage_corruption_detection"></a>

docs/html/globals.html

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,27 @@ <h3><a id="index_v"></a>- v -</h3><ul>
9999
<li>VMA_ALLOCATION_CREATE_NEVER_ALLOCATE_BIT
100100
: <a class="el" href="vk__mem__alloc_8h.html#ad9889c10c798b040d59c92f257cae597a89759603401014eb325eb22a3839f2ff">vk_mem_alloc.h</a>
101101
</li>
102+
<li>VMA_ALLOCATION_CREATE_STRATEGY_BEST_FIT_BIT
103+
: <a class="el" href="vk__mem__alloc_8h.html#ad9889c10c798b040d59c92f257cae597a839826775c62319466441f86496f036d">vk_mem_alloc.h</a>
104+
</li>
105+
<li>VMA_ALLOCATION_CREATE_STRATEGY_FIRST_FIT_BIT
106+
: <a class="el" href="vk__mem__alloc_8h.html#ad9889c10c798b040d59c92f257cae597a33eb2052674f3ad92386c714a65fb777">vk_mem_alloc.h</a>
107+
</li>
108+
<li>VMA_ALLOCATION_CREATE_STRATEGY_MASK
109+
: <a class="el" href="vk__mem__alloc_8h.html#ad9889c10c798b040d59c92f257cae597a8e16845d81ae3d27c47106d4770d5c7e">vk_mem_alloc.h</a>
110+
</li>
111+
<li>VMA_ALLOCATION_CREATE_STRATEGY_MIN_FRAGMENTATION_BIT
112+
: <a class="el" href="vk__mem__alloc_8h.html#ad9889c10c798b040d59c92f257cae597a621b704103eb3360230c860acf36e706">vk_mem_alloc.h</a>
113+
</li>
114+
<li>VMA_ALLOCATION_CREATE_STRATEGY_MIN_MEMORY_BIT
115+
: <a class="el" href="vk__mem__alloc_8h.html#ad9889c10c798b040d59c92f257cae597a8af1210cf591784afa026d94998f735d">vk_mem_alloc.h</a>
116+
</li>
117+
<li>VMA_ALLOCATION_CREATE_STRATEGY_MIN_TIME_BIT
118+
: <a class="el" href="vk__mem__alloc_8h.html#ad9889c10c798b040d59c92f257cae597a0729e932b7ea170e3a128cad96c5cf6d">vk_mem_alloc.h</a>
119+
</li>
120+
<li>VMA_ALLOCATION_CREATE_STRATEGY_WORST_FIT_BIT
121+
: <a class="el" href="vk__mem__alloc_8h.html#ad9889c10c798b040d59c92f257cae597ad242a04f802e25fef0b880afe8bb0a62">vk_mem_alloc.h</a>
122+
</li>
102123
<li>VMA_ALLOCATION_CREATE_UPPER_ADDRESS_BIT
103124
: <a class="el" href="vk__mem__alloc_8h.html#ad9889c10c798b040d59c92f257cae597a42ba3a2d2c7117953210b7c3ef8da0df">vk_mem_alloc.h</a>
104125
</li>
@@ -135,6 +156,12 @@ <h3><a id="index_v"></a>- v -</h3><ul>
135156
<li>VMA_MEMORY_USAGE_UNKNOWN
136157
: <a class="el" href="vk__mem__alloc_8h.html#aa5846affa1e9da3800e3e78fae2305ccaf50d27e34e0925cf3a63db8c839121dd">vk_mem_alloc.h</a>
137158
</li>
159+
<li>VMA_POOL_CREATE_ALGORITHM_MASK
160+
: <a class="el" href="vk__mem__alloc_8h.html#a9a7c45f9c863695d98c83fa5ac940fe7af4d270f8f42517a0f70037ceb6ac1d9c">vk_mem_alloc.h</a>
161+
</li>
162+
<li>VMA_POOL_CREATE_BUDDY_ALGORITHM_BIT
163+
: <a class="el" href="vk__mem__alloc_8h.html#a9a7c45f9c863695d98c83fa5ac940fe7a97a0dc38e5161b780594d998d313d35e">vk_mem_alloc.h</a>
164+
</li>
138165
<li>VMA_POOL_CREATE_FLAG_BITS_MAX_ENUM
139166
: <a class="el" href="vk__mem__alloc_8h.html#a9a7c45f9c863695d98c83fa5ac940fe7a1c7312bea9ea246846b9054fd6bd6aec">vk_mem_alloc.h</a>
140167
</li>

docs/html/globals_eval.html

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@
6161
</div>
6262

6363
<div class="contents">
64-
&#160;<ul>
64+
&#160;
65+
66+
<h3><a id="index_v"></a>- v -</h3><ul>
6567
<li>VMA_ALLOCATION_CREATE_CAN_BECOME_LOST_BIT
6668
: <a class="el" href="vk__mem__alloc_8h.html#ad9889c10c798b040d59c92f257cae597a5f436af6c8fe8540573a6d22627a6fd2">vk_mem_alloc.h</a>
6769
</li>
@@ -80,6 +82,27 @@
8082
<li>VMA_ALLOCATION_CREATE_NEVER_ALLOCATE_BIT
8183
: <a class="el" href="vk__mem__alloc_8h.html#ad9889c10c798b040d59c92f257cae597a89759603401014eb325eb22a3839f2ff">vk_mem_alloc.h</a>
8284
</li>
85+
<li>VMA_ALLOCATION_CREATE_STRATEGY_BEST_FIT_BIT
86+
: <a class="el" href="vk__mem__alloc_8h.html#ad9889c10c798b040d59c92f257cae597a839826775c62319466441f86496f036d">vk_mem_alloc.h</a>
87+
</li>
88+
<li>VMA_ALLOCATION_CREATE_STRATEGY_FIRST_FIT_BIT
89+
: <a class="el" href="vk__mem__alloc_8h.html#ad9889c10c798b040d59c92f257cae597a33eb2052674f3ad92386c714a65fb777">vk_mem_alloc.h</a>
90+
</li>
91+
<li>VMA_ALLOCATION_CREATE_STRATEGY_MASK
92+
: <a class="el" href="vk__mem__alloc_8h.html#ad9889c10c798b040d59c92f257cae597a8e16845d81ae3d27c47106d4770d5c7e">vk_mem_alloc.h</a>
93+
</li>
94+
<li>VMA_ALLOCATION_CREATE_STRATEGY_MIN_FRAGMENTATION_BIT
95+
: <a class="el" href="vk__mem__alloc_8h.html#ad9889c10c798b040d59c92f257cae597a621b704103eb3360230c860acf36e706">vk_mem_alloc.h</a>
96+
</li>
97+
<li>VMA_ALLOCATION_CREATE_STRATEGY_MIN_MEMORY_BIT
98+
: <a class="el" href="vk__mem__alloc_8h.html#ad9889c10c798b040d59c92f257cae597a8af1210cf591784afa026d94998f735d">vk_mem_alloc.h</a>
99+
</li>
100+
<li>VMA_ALLOCATION_CREATE_STRATEGY_MIN_TIME_BIT
101+
: <a class="el" href="vk__mem__alloc_8h.html#ad9889c10c798b040d59c92f257cae597a0729e932b7ea170e3a128cad96c5cf6d">vk_mem_alloc.h</a>
102+
</li>
103+
<li>VMA_ALLOCATION_CREATE_STRATEGY_WORST_FIT_BIT
104+
: <a class="el" href="vk__mem__alloc_8h.html#ad9889c10c798b040d59c92f257cae597ad242a04f802e25fef0b880afe8bb0a62">vk_mem_alloc.h</a>
105+
</li>
83106
<li>VMA_ALLOCATION_CREATE_UPPER_ADDRESS_BIT
84107
: <a class="el" href="vk__mem__alloc_8h.html#ad9889c10c798b040d59c92f257cae597a42ba3a2d2c7117953210b7c3ef8da0df">vk_mem_alloc.h</a>
85108
</li>
@@ -113,6 +136,12 @@
113136
<li>VMA_MEMORY_USAGE_UNKNOWN
114137
: <a class="el" href="vk__mem__alloc_8h.html#aa5846affa1e9da3800e3e78fae2305ccaf50d27e34e0925cf3a63db8c839121dd">vk_mem_alloc.h</a>
115138
</li>
139+
<li>VMA_POOL_CREATE_ALGORITHM_MASK
140+
: <a class="el" href="vk__mem__alloc_8h.html#a9a7c45f9c863695d98c83fa5ac940fe7af4d270f8f42517a0f70037ceb6ac1d9c">vk_mem_alloc.h</a>
141+
</li>
142+
<li>VMA_POOL_CREATE_BUDDY_ALGORITHM_BIT
143+
: <a class="el" href="vk__mem__alloc_8h.html#a9a7c45f9c863695d98c83fa5ac940fe7a97a0dc38e5161b780594d998d313d35e">vk_mem_alloc.h</a>
144+
</li>
116145
<li>VMA_POOL_CREATE_FLAG_BITS_MAX_ENUM
117146
: <a class="el" href="vk__mem__alloc_8h.html#a9a7c45f9c863695d98c83fa5ac940fe7a1c7312bea9ea246846b9054fd6bd6aec">vk_mem_alloc.h</a>
118147
</li>

docs/html/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ <h1><a class="anchor" id="main_table_of_contents"></a>
102102
<li><a class="el" href="custom_memory_pools.html#linear_algorithm_ring_buffer">Ring buffer</a></li>
103103
</ul>
104104
</li>
105+
<li><a class="el" href="custom_memory_pools.html#buddy_algorithm">Buddy allocation algorithm</a></li>
105106
</ul>
106107
</li>
107108
<li><a class="el" href="defragmentation.html">Defragmentation</a></li>

docs/html/menudata.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,6 @@ var menudata={children:[
6565
{text:"v",url:"globals_func.html#index_v"}]},
6666
{text:"Typedefs",url:"globals_type.html"},
6767
{text:"Enumerations",url:"globals_enum.html"},
68-
{text:"Enumerator",url:"globals_eval.html"},
68+
{text:"Enumerator",url:"globals_eval.html",children:[
69+
{text:"v",url:"globals_eval.html#index_v"}]},
6970
{text:"Macros",url:"globals_defs.html"}]}]}]}

0 commit comments

Comments
 (0)