Skip to content

Commit 663b0c9

Browse files
Minor fixes in documentation.
1 parent bdb89a9 commit 663b0c9

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

docs/html/defragmentation.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ <h1><a class="anchor" id="defragmentation_cpu"></a>
8989
<li>It temporarily maps entire memory blocks when necessary.</li>
9090
<li>It moves data using <code>memmove()</code> function.</li>
9191
</ul>
92-
<div class="fragment"><div class="line"><span class="comment">// Given following variables already initialized:</span></div><div class="line">VkDevice device;</div><div class="line"><a class="code" href="struct_vma_allocator.html">VmaAllocator</a> allocator;</div><div class="line">std::vector&lt;VkBuffer&gt; buffers;</div><div class="line">std::vector&lt;VmaAllocation&gt; allocations;</div><div class="line"></div><div class="line"></div><div class="line"><span class="keyword">const</span> uint32_t allocCount = (uint32_t)allocations.size();</div><div class="line">std::vector&lt;VkBool32&gt; allocationsChanged(allocCount);</div><div class="line"></div><div class="line"><a class="code" href="struct_vma_defragmentation_info2.html">VmaDefragmentationInfo2</a> defragInfo = {};</div><div class="line">defragInfo.<a class="code" href="struct_vma_defragmentation_info2.html#a3cf86ab32c1da779b4923d301a3056ba">allocationCount</a> = allocCount;</div><div class="line">defragInfo.<a class="code" href="struct_vma_defragmentation_info2.html#a8943f8d65969ce8e2189a1cdf3205e96">pAllocations</a> = allocations.data();</div><div class="line">defragInfo.<a class="code" href="struct_vma_defragmentation_info2.html#a76d51a644dc7f5405d0cdd0025ecd0cc">pAllocationsChanged</a> = allocationsChanged.data();</div><div class="line">defragInfo.<a class="code" href="struct_vma_defragmentation_info2.html#af78e1ea40c22d85137b65f6b384a4d0a">maxCpuBytesToMove</a> = VK_WHOLE_SIZE; <span class="comment">// No limit.</span></div><div class="line">defragInfo.<a class="code" href="struct_vma_defragmentation_info2.html#a94c2c7223d52878445a8cccce396b671">maxCpuAllocationsToMove</a> = UINT32_MAX; <span class="comment">// No limit.</span></div><div class="line"></div><div class="line"><a class="code" href="struct_vma_defragmentation_context.html">VmaDefragmentationContext</a> defragCtx;</div><div class="line"><a class="code" href="vk__mem__alloc_8h.html#a36ba776fd7fd5cb1e9359fdc0d8e6e8a">vmaDefragmentationBegin</a>(allocator, &amp;defragInfo, <span class="keyword">nullptr</span>, &amp;defragCtx);</div><div class="line"><a class="code" href="vk__mem__alloc_8h.html#a8774e20e91e245aae959ba63efa15dd2">vmaDefragmentationEnd</a>(allocator, defragCtx);</div><div class="line"></div><div class="line"><span class="keywordflow">for</span>(uint32_t i = 0; i &lt; allocCount; ++i)</div><div class="line">{</div><div class="line"> <span class="keywordflow">if</span>(allocationsChanged[i])</div><div class="line"> {</div><div class="line"> <span class="comment">// Destroy buffer that is immutably bound to memory region which is no longer valid.</span></div><div class="line"> vkDestroyBuffer(device, buffers[i], <span class="keyword">nullptr</span>);</div><div class="line"></div><div class="line"> <span class="comment">// Create new buffer with same parameters.</span></div><div class="line"> VkBufferCreateInfo bufferInfo = ...;</div><div class="line"> vkCreateBuffer(device, &amp;bufferInfo, <span class="keyword">nullptr</span>, &amp;buffers[i]);</div><div class="line"> </div><div class="line"> <span class="comment">// You can make dummy call to vkGetBufferMemoryRequirements here to silence validation layer warning.</span></div><div class="line"> </div><div class="line"> <span class="comment">// Bind new buffer to new memory region. Data contained in it is already moved.</span></div><div class="line"> <a class="code" href="struct_vma_allocation_info.html">VmaAllocationInfo</a> allocInfo;</div><div class="line"> <a class="code" href="vk__mem__alloc_8h.html#a86dd08aba8633bfa4ad0df2e76481d8b">vmaGetAllocationInfo</a>(allocator, allocations[i], &amp;allocInfo);</div><div class="line"> vkBindBufferMemory(device, buffers[i], allocInfo.<a class="code" href="struct_vma_allocation_info.html#ae0bfb7dfdf79a76ffefc9a94677a2f67">deviceMemory</a>, allocInfo.<a class="code" href="struct_vma_allocation_info.html#a4a3c732388dbdc7a23f9365b00825268">offset</a>);</div><div class="line"> }</div><div class="line">}</div></div><!-- fragment --><p>Filling <a class="el" href="struct_vma_defragmentation_info2.html#a76d51a644dc7f5405d0cdd0025ecd0cc" title="Optional, output. Pointer to array that will be filled with information whether the allocation at cer...">VmaDefragmentationInfo2::pAllocationsChanged</a> is optional. This output array tells whether particular allocation in <a class="el" href="struct_vma_defragmentation_info2.html#a8943f8d65969ce8e2189a1cdf3205e96" title="Pointer to array of allocations that can be defragmented. ">VmaDefragmentationInfo2::pAllocations</a> at the same index has been modified during defragmentation. You can pass null, but you then need to query every allocation passed to defragmentation for new parameters using <a class="el" href="vk__mem__alloc_8h.html#a86dd08aba8633bfa4ad0df2e76481d8b" title="Returns current information about specified allocation and atomically marks it as used in current fra...">vmaGetAllocationInfo()</a> if you might need to recreate and rebind a buffer or image associated with it.</p>
92+
<div class="fragment"><div class="line"><span class="comment">// Given following variables already initialized:</span></div><div class="line">VkDevice device;</div><div class="line"><a class="code" href="struct_vma_allocator.html">VmaAllocator</a> allocator;</div><div class="line">std::vector&lt;VkBuffer&gt; buffers;</div><div class="line">std::vector&lt;VmaAllocation&gt; allocations;</div><div class="line"></div><div class="line"></div><div class="line"><span class="keyword">const</span> uint32_t allocCount = (uint32_t)allocations.size();</div><div class="line">std::vector&lt;VkBool32&gt; allocationsChanged(allocCount);</div><div class="line"></div><div class="line"><a class="code" href="struct_vma_defragmentation_info2.html">VmaDefragmentationInfo2</a> defragInfo = {};</div><div class="line">defragInfo.<a class="code" href="struct_vma_defragmentation_info2.html#a3cf86ab32c1da779b4923d301a3056ba">allocationCount</a> = allocCount;</div><div class="line">defragInfo.<a class="code" href="struct_vma_defragmentation_info2.html#a8943f8d65969ce8e2189a1cdf3205e96">pAllocations</a> = allocations.data();</div><div class="line">defragInfo.<a class="code" href="struct_vma_defragmentation_info2.html#a76d51a644dc7f5405d0cdd0025ecd0cc">pAllocationsChanged</a> = allocationsChanged.data();</div><div class="line">defragInfo.<a class="code" href="struct_vma_defragmentation_info2.html#af78e1ea40c22d85137b65f6b384a4d0a">maxCpuBytesToMove</a> = VK_WHOLE_SIZE; <span class="comment">// No limit.</span></div><div class="line">defragInfo.<a class="code" href="struct_vma_defragmentation_info2.html#a94c2c7223d52878445a8cccce396b671">maxCpuAllocationsToMove</a> = UINT32_MAX; <span class="comment">// No limit.</span></div><div class="line"></div><div class="line"><a class="code" href="struct_vma_defragmentation_context.html">VmaDefragmentationContext</a> defragCtx;</div><div class="line"><a class="code" href="vk__mem__alloc_8h.html#a36ba776fd7fd5cb1e9359fdc0d8e6e8a">vmaDefragmentationBegin</a>(allocator, &amp;defragInfo, <span class="keyword">nullptr</span>, &amp;defragCtx);</div><div class="line"><a class="code" href="vk__mem__alloc_8h.html#a8774e20e91e245aae959ba63efa15dd2">vmaDefragmentationEnd</a>(allocator, defragCtx);</div><div class="line"></div><div class="line"><span class="keywordflow">for</span>(uint32_t i = 0; i &lt; allocCount; ++i)</div><div class="line">{</div><div class="line"> <span class="keywordflow">if</span>(allocationsChanged[i])</div><div class="line"> {</div><div class="line"> <span class="comment">// Destroy buffer that is immutably bound to memory region which is no longer valid.</span></div><div class="line"> vkDestroyBuffer(device, buffers[i], <span class="keyword">nullptr</span>);</div><div class="line"></div><div class="line"> <span class="comment">// Create new buffer with same parameters.</span></div><div class="line"> VkBufferCreateInfo bufferInfo = ...;</div><div class="line"> vkCreateBuffer(device, &amp;bufferInfo, <span class="keyword">nullptr</span>, &amp;buffers[i]);</div><div class="line"> </div><div class="line"> <span class="comment">// You can make dummy call to vkGetBufferMemoryRequirements here to silence validation layer warning.</span></div><div class="line"> </div><div class="line"> <span class="comment">// Bind new buffer to new memory region. Data contained in it is already moved.</span></div><div class="line"> <a class="code" href="struct_vma_allocation_info.html">VmaAllocationInfo</a> allocInfo;</div><div class="line"> <a class="code" href="vk__mem__alloc_8h.html#a86dd08aba8633bfa4ad0df2e76481d8b">vmaGetAllocationInfo</a>(allocator, allocations[i], &amp;allocInfo);</div><div class="line"> vkBindBufferMemory(device, buffers[i], allocInfo.<a class="code" href="struct_vma_allocation_info.html#ae0bfb7dfdf79a76ffefc9a94677a2f67">deviceMemory</a>, allocInfo.<a class="code" href="struct_vma_allocation_info.html#a4a3c732388dbdc7a23f9365b00825268">offset</a>);</div><div class="line"> }</div><div class="line">}</div></div><!-- fragment --><p>Setting <a class="el" href="struct_vma_defragmentation_info2.html#a76d51a644dc7f5405d0cdd0025ecd0cc" title="Optional, output. Pointer to array that will be filled with information whether the allocation at cer...">VmaDefragmentationInfo2::pAllocationsChanged</a> is optional. This output array tells whether particular allocation in <a class="el" href="struct_vma_defragmentation_info2.html#a8943f8d65969ce8e2189a1cdf3205e96" title="Pointer to array of allocations that can be defragmented. ">VmaDefragmentationInfo2::pAllocations</a> at the same index has been modified during defragmentation. You can pass null, but you then need to query every allocation passed to defragmentation for new parameters using <a class="el" href="vk__mem__alloc_8h.html#a86dd08aba8633bfa4ad0df2e76481d8b" title="Returns current information about specified allocation and atomically marks it as used in current fra...">vmaGetAllocationInfo()</a> if you might need to recreate and rebind a buffer or image associated with it.</p>
9393
<p>If you use <a class="el" href="choosing_memory_type.html#choosing_memory_type_custom_memory_pools">Custom memory pools</a>, you can fill <a class="el" href="struct_vma_defragmentation_info2.html#a7e70aa2a1081d849dcc7829b19d3ec9d" title="Numer of pools in pPools array. ">VmaDefragmentationInfo2::poolCount</a> and <a class="el" href="struct_vma_defragmentation_info2.html#a0b3effd57f3fcdeb2ed62210b4ef20e1" title="Either null or pointer to array of pools to be defragmented. ">VmaDefragmentationInfo2::pPools</a> instead of <a class="el" href="struct_vma_defragmentation_info2.html#a3cf86ab32c1da779b4923d301a3056ba" title="Number of allocations in pAllocations array. ">VmaDefragmentationInfo2::allocationCount</a> and <a class="el" href="struct_vma_defragmentation_info2.html#a8943f8d65969ce8e2189a1cdf3205e96" title="Pointer to array of allocations that can be defragmented. ">VmaDefragmentationInfo2::pAllocations</a> to defragment all allocations in given pools. You cannot use <a class="el" href="struct_vma_defragmentation_info2.html#a76d51a644dc7f5405d0cdd0025ecd0cc" title="Optional, output. Pointer to array that will be filled with information whether the allocation at cer...">VmaDefragmentationInfo2::pAllocationsChanged</a> in that case. You can also combine both methods.</p>
9494
<h1><a class="anchor" id="defragmentation_gpu"></a>
9595
Defragmenting GPU memory</h1>
@@ -111,9 +111,9 @@ <h1><a class="anchor" id="defragmentation_custom_algorithm"></a>
111111
Writing custom defragmentation algorithm</h1>
112112
<p>If you want to implement your own, custom defragmentation algorithm, there is infrastructure prepared for that, but it is not exposed through the library API - you need to hack its source code. Here are steps needed to do this:</p>
113113
<ol type="1">
114-
<li>Main thing you need to do is to define your own class derived from base abstract class <code>VmaDefragmentationAlgorithm</code> and implement your version of its pure virtual method. See definition and comments of this class for details.</li>
114+
<li>Main thing you need to do is to define your own class derived from base abstract class <code>VmaDefragmentationAlgorithm</code> and implement your version of its pure virtual methods. See definition and comments of this class for details.</li>
115115
<li>Your code needs to interact with device memory block metadata. If you need more access to its data than it's provided by its public interface, declare your new class as a friend class e.g. in class <code>VmaBlockMetadata_Generic</code>.</li>
116-
<li>If you want to create a flag that would enable your algorithm or pass some additional flags to configure it, define some enum with such flags and use them in <a class="el" href="struct_vma_defragmentation_info2.html#a53e844ee5633e229cf6daf14b2d9fff9" title="Reserved for future use. Should be 0. ">VmaDefragmentationInfo2::flags</a>.</li>
116+
<li>If you want to create a flag that would enable your algorithm or pass some additional flags to configure it, add them to <code>VmaDefragmentationFlagBits</code> and use them in <a class="el" href="struct_vma_defragmentation_info2.html#a53e844ee5633e229cf6daf14b2d9fff9" title="Reserved for future use. Should be 0. ">VmaDefragmentationInfo2::flags</a>.</li>
117117
<li>Modify function <code>VmaBlockVectorDefragmentationContext::Begin</code> to create object of your new class whenever needed. </li>
118118
</ol>
119119
</div></div><!-- contents -->

src/vk_mem_alloc.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ for(uint32_t i = 0; i < allocCount; ++i)
799799
}
800800
\endcode
801801

802-
Filling VmaDefragmentationInfo2::pAllocationsChanged is optional.
802+
Setting VmaDefragmentationInfo2::pAllocationsChanged is optional.
803803
This output array tells whether particular allocation in VmaDefragmentationInfo2::pAllocations at the same index
804804
has been modified during defragmentation.
805805
You can pass null, but you then need to query every allocation passed to defragmentation
@@ -914,13 +914,13 @@ but it is not exposed through the library API - you need to hack its source code
914914
Here are steps needed to do this:
915915

916916
-# Main thing you need to do is to define your own class derived from base abstract
917-
class `VmaDefragmentationAlgorithm` and implement your version of its pure virtual method.
917+
class `VmaDefragmentationAlgorithm` and implement your version of its pure virtual methods.
918918
See definition and comments of this class for details.
919919
-# Your code needs to interact with device memory block metadata.
920920
If you need more access to its data than it's provided by its public interface,
921921
declare your new class as a friend class e.g. in class `VmaBlockMetadata_Generic`.
922922
-# If you want to create a flag that would enable your algorithm or pass some additional
923-
flags to configure it, define some enum with such flags and use them in
923+
flags to configure it, add them to `VmaDefragmentationFlagBits` and use them in
924924
VmaDefragmentationInfo2::flags.
925925
-# Modify function `VmaBlockVectorDefragmentationContext::Begin` to create object
926926
of your new class whenever needed.

0 commit comments

Comments
 (0)