Skip to content

Commit 85a4972

Browse files
Improvements in documentation regarding defragmentation
1 parent e1879e9 commit 85a4972

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

docs/html/defragmentation.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@
186186
<p >Defragmentation is always performed in each pool separately. Allocations are never moved between different Vulkan memory types. The size of the destination memory reserved for a moved allocation is the same as the original one. Alignment of an allocation as it was determined using <code>vkGetBufferMemoryRequirements()</code> etc. is also respected after defragmentation. Buffers/images should be recreated with the same <code>VkBufferCreateInfo</code> / <code>VkImageCreateInfo</code> parameters as the original ones.</p>
187187
<p >You can perform the defragmentation incrementally to limit the number of allocations and bytes to be moved in each pass, e.g. to call it in sync with render frames and not to experience too big hitches. See members: <a class="el" href="struct_vma_defragmentation_info.html#a637ada77b02179a27fa92290000afac4" title="Maximum numbers of bytes that can be copied during single pass, while moving allocations to different...">VmaDefragmentationInfo::maxBytesPerPass</a>, <a class="el" href="struct_vma_defragmentation_info.html#ac2db29d309bebc4f7d55041416e9694b" title="Maximum number of allocations that can be moved during single pass to a different place.">VmaDefragmentationInfo::maxAllocationsPerPass</a>.</p>
188188
<p >It is also safe to perform the defragmentation asynchronously to render frames and other Vulkan and VMA usage, possibly from multiple threads, with the exception that allocations returned in <a class="el" href="struct_vma_defragmentation_pass_move_info.html#adfa7a4994afd9b940e7f1dfaf436a725" title="Array of moves to be performed by the user in the current defragmentation pass.">VmaDefragmentationPassMoveInfo::pMoves</a> shouldn't be destroyed until the defragmentation pass is ended.</p>
189+
<p ><b>Mapping</b> is preserved on allocations that are moved during defragmentation. Whether through <a class="el" href="group__group__alloc.html#ggad9889c10c798b040d59c92f257cae597a11da372cc3a82931c5e5d6146cd9dd1f" title="Set this flag to use a memory that will be persistently mapped and retrieve pointer to it.">VMA_ALLOCATION_CREATE_MAPPED_BIT</a> or <a class="el" href="group__group__alloc.html#gad5bd1243512d099706de88168992f069" title="Maps memory represented by given allocation and returns pointer to it.">vmaMapMemory()</a>, the allocations are mapped at their new place. Of course, pointer to the mapped data changes, so it needs to be queried using <a class="el" href="struct_vma_allocation_info.html#a5eeffbe2d2f30f53370ff14aefbadbe2" title="Pointer to the beginning of this allocation as mapped data.">VmaAllocationInfo::pMappedData</a>.</p>
189190
<dl class="section note"><dt>Note</dt><dd>Defragmentation is not supported in custom pools created with <a class="el" href="group__group__alloc.html#gga9a7c45f9c863695d98c83fa5ac940fe7a13c8a444197c67866be9cb05599fc726" title="Enables alternative, linear allocation algorithm in this pool.">VMA_POOL_CREATE_LINEAR_ALGORITHM_BIT</a>. </dd></dl>
190191
</div></div><!-- contents -->
191192
</div><!-- PageDoc -->

docs/html/struct_vma_allocation_info.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ <h2 class="memtitle"><span class="permalink"><a href="#ae0bfb7dfdf79a76ffefc9a94
113113

114114
<p>Handle to Vulkan memory object. </p>
115115
<p >Same memory object can be shared by multiple allocations.</p>
116-
<p >It can change after call to vmaDefragment() if this allocation is passed to the function. </p>
116+
<p >It can change after the allocation is moved during <a class="el" href="defragmentation.html">Defragmentation</a>. </p>
117117

118118
</div>
119119
</div>
@@ -148,7 +148,7 @@ <h2 class="memtitle"><span class="permalink"><a href="#a4a3c732388dbdc7a23f9365b
148148

149149
<p>Offset in <code>VkDeviceMemory</code> object to the beginning of this allocation, in bytes. <code>(deviceMemory, offset)</code> pair is unique to this allocation. </p>
150150
<p >You usually don't need to use this offset. If you create a buffer or an image together with the allocation using e.g. function <a class="el" href="group__group__alloc.html#gac72ee55598617e8eecca384e746bab51" title="Creates a new VkBuffer, allocates and binds memory for it.">vmaCreateBuffer()</a>, <a class="el" href="group__group__alloc.html#ga02a94f25679275851a53e82eacbcfc73" title="Function similar to vmaCreateBuffer().">vmaCreateImage()</a>, functions that operate on these resources refer to the beginning of the buffer or image, not entire device memory block. Functions like <a class="el" href="group__group__alloc.html#gad5bd1243512d099706de88168992f069" title="Maps memory represented by given allocation and returns pointer to it.">vmaMapMemory()</a>, <a class="el" href="group__group__alloc.html#ga6b0929b914b60cf2d45cac4bf3547470" title="Binds buffer to allocation.">vmaBindBufferMemory()</a> also refer to the beginning of the allocation and apply this offset automatically.</p>
151-
<p >It can change after call to vmaDefragment() if this allocation is passed to the function. </p>
151+
<p >It can change after the allocation is moved during <a class="el" href="defragmentation.html">Defragmentation</a>. </p>
152152

153153
</div>
154154
</div>
@@ -166,7 +166,7 @@ <h2 class="memtitle"><span class="permalink"><a href="#a5eeffbe2d2f30f53370ff14a
166166

167167
<p>Pointer to the beginning of this allocation as mapped data. </p>
168168
<p >If the allocation hasn't been mapped using <a class="el" href="group__group__alloc.html#gad5bd1243512d099706de88168992f069" title="Maps memory represented by given allocation and returns pointer to it.">vmaMapMemory()</a> and hasn't been created with <a class="el" href="group__group__alloc.html#ggad9889c10c798b040d59c92f257cae597a11da372cc3a82931c5e5d6146cd9dd1f" title="Set this flag to use a memory that will be persistently mapped and retrieve pointer to it.">VMA_ALLOCATION_CREATE_MAPPED_BIT</a> flag, this value is null.</p>
169-
<p >It can change after call to <a class="el" href="group__group__alloc.html#gad5bd1243512d099706de88168992f069" title="Maps memory represented by given allocation and returns pointer to it.">vmaMapMemory()</a>, <a class="el" href="group__group__alloc.html#ga9bc268595cb33f6ec4d519cfce81ff45" title="Unmaps memory represented by given allocation, mapped previously using vmaMapMemory().">vmaUnmapMemory()</a>. It can also change after call to vmaDefragment() if this allocation is passed to the function. </p>
169+
<p >It can change after call to <a class="el" href="group__group__alloc.html#gad5bd1243512d099706de88168992f069" title="Maps memory represented by given allocation and returns pointer to it.">vmaMapMemory()</a>, <a class="el" href="group__group__alloc.html#ga9bc268595cb33f6ec4d519cfce81ff45" title="Unmaps memory represented by given allocation, mapped previously using vmaMapMemory().">vmaUnmapMemory()</a>. It can also change after the allocation is moved during <a class="el" href="defragmentation.html">Defragmentation</a>. </p>
170170

171171
</div>
172172
</div>

include/vk_mem_alloc.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,7 +1344,7 @@ typedef struct VmaAllocationInfo
13441344

13451345
Same memory object can be shared by multiple allocations.
13461346

1347-
It can change after call to vmaDefragment() if this allocation is passed to the function.
1347+
It can change after the allocation is moved during \ref defragmentation.
13481348
*/
13491349
VkDeviceMemory VMA_NULLABLE_NON_DISPATCHABLE deviceMemory;
13501350
/** \brief Offset in `VkDeviceMemory` object to the beginning of this allocation, in bytes. `(deviceMemory, offset)` pair is unique to this allocation.
@@ -1354,7 +1354,7 @@ typedef struct VmaAllocationInfo
13541354
not entire device memory block. Functions like vmaMapMemory(), vmaBindBufferMemory() also refer to the beginning of the allocation
13551355
and apply this offset automatically.
13561356

1357-
It can change after call to vmaDefragment() if this allocation is passed to the function.
1357+
It can change after the allocation is moved during \ref defragmentation.
13581358
*/
13591359
VkDeviceSize offset;
13601360
/** \brief Size of this allocation, in bytes.
@@ -1374,7 +1374,7 @@ typedef struct VmaAllocationInfo
13741374
created with #VMA_ALLOCATION_CREATE_MAPPED_BIT flag, this value is null.
13751375

13761376
It can change after call to vmaMapMemory(), vmaUnmapMemory().
1377-
It can also change after call to vmaDefragment() if this allocation is passed to the function.
1377+
It can also change after the allocation is moved during \ref defragmentation.
13781378
*/
13791379
void* VMA_NULLABLE pMappedData;
13801380
/** \brief Custom general-purpose pointer that was passed as VmaAllocationCreateInfo::pUserData or set using vmaSetAllocationUserData().
@@ -18357,6 +18357,11 @@ It is also safe to perform the defragmentation asynchronously to render frames a
1835718357
usage, possibly from multiple threads, with the exception that allocations
1835818358
returned in VmaDefragmentationPassMoveInfo::pMoves shouldn't be destroyed until the defragmentation pass is ended.
1835918359

18360+
<b>Mapping</b> is preserved on allocations that are moved during defragmentation.
18361+
Whether through #VMA_ALLOCATION_CREATE_MAPPED_BIT or vmaMapMemory(), the allocations
18362+
are mapped at their new place. Of course, pointer to the mapped data changes, so it needs to be queried
18363+
using VmaAllocationInfo::pMappedData.
18364+
1836018365
\note Defragmentation is not supported in custom pools created with #VMA_POOL_CREATE_LINEAR_ALGORITHM_BIT.
1836118366

1836218367

0 commit comments

Comments
 (0)