mirror of
https://github.com/GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator.git
synced 2025-05-22 04:38:38 +00:00
Improvements in documentation formatting.
This commit is contained in:
parent
c005a84e37
commit
07a7deb09d
8 changed files with 276 additions and 388 deletions
|
@ -1290,32 +1290,7 @@ Functions</h2></td></tr>
|
|||
<p>The function also frees empty <code>VkDeviceMemory</code> blocks.</p>
|
||||
<p>After allocation has been moved, its <a class="el" href="struct_vma_allocation_info.html#ae0bfb7dfdf79a76ffefc9a94677a2f67" title="Handle to Vulkan memory object. ">VmaAllocationInfo::deviceMemory</a> and/or <a class="el" href="struct_vma_allocation_info.html#a4a3c732388dbdc7a23f9365b00825268" title="Offset into deviceMemory object to the beginning of this allocation, in bytes. (deviceMemory, offset) pair is unique to this allocation. ">VmaAllocationInfo::offset</a> changes. You must query them again using <a class="el" href="vk__mem__alloc_8h.html#a86dd08aba8633bfa4ad0df2e76481d8b" title="Returns current information about specified allocation. ">vmaGetAllocationInfo()</a> if you need them.</p>
|
||||
<p>If an allocation has been moved, data in memory is copied to new place automatically, but if it was bound to a buffer or an image, you must destroy that object yourself, create new one and bind it to the new memory pointed by the allocation. You must use <code>vkDestroyBuffer()</code>, <code>vkDestroyImage()</code>, <code>vkCreateBuffer()</code>, <code>vkCreateImage()</code> for that purpose and NOT <a class="el" href="vk__mem__alloc_8h.html#a0d9f4e4ba5bf9aab1f1c746387753d77" title="Destroys Vulkan buffer and frees allocated memory. ">vmaDestroyBuffer()</a>, <a class="el" href="vk__mem__alloc_8h.html#ae50d2cb3b4a3bfd4dd40987234e50e7e" title="Destroys Vulkan image and frees allocated memory. ">vmaDestroyImage()</a>, <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>! Example:</p>
|
||||
<pre class="fragment">VkDevice device = ...;
|
||||
VmaAllocator allocator = ...;
|
||||
std::vector<VkBuffer> buffers = ...;
|
||||
std::vector<VmaAllocation> allocations = ...;
|
||||
|
||||
std::vector<VkBool32> allocationsChanged(allocations.size());
|
||||
vmaDefragment(allocator, allocations.data(), allocations.size(), allocationsChanged.data(), nullptr, nullptr);
|
||||
|
||||
for(size_t i = 0; i < allocations.size(); ++i)
|
||||
{
|
||||
if(allocationsChanged[i])
|
||||
{
|
||||
VmaAllocationInfo allocInfo;
|
||||
vmaGetAllocationInfo(allocator, allocations[i], &allocInfo);
|
||||
|
||||
vkDestroyBuffer(device, buffers[i], nullptr);
|
||||
|
||||
VkBufferCreateInfo bufferInfo = ...;
|
||||
vkCreateBuffer(device, &bufferInfo, nullptr, &buffers[i]);
|
||||
|
||||
.// You can make dummy call to vkGetBufferMemoryRequirements here to silence validation layer warning.
|
||||
|
||||
vkBindBufferMemory(device, buffers[i], allocInfo.deviceMemory, allocInfo.offset);
|
||||
}
|
||||
}
|
||||
</pre><p>This function may be time-consuming, so you shouldn't call it too often (like every frame or after every resource creation/destruction), but rater you can call it on special occasions (like when reloading a game level, when you just destroyed a lot of objects). </p>
|
||||
<div class="fragment"><div class="line">VkDevice device = ...;</div><div class="line">VmaAllocator allocator = ...;</div><div class="line">std::vector<VkBuffer> buffers = ...;</div><div class="line">std::vector<VmaAllocation> allocations = ...;</div><div class="line"></div><div class="line">std::vector<VkBool32> allocationsChanged(allocations.size());</div><div class="line"><a class="code" href="vk__mem__alloc_8h.html#a6aced90fcc7b39882b6654a740a0b9bb">vmaDefragment</a>(allocator, allocations.data(), allocations.size(), allocationsChanged.data(), <span class="keyword">nullptr</span>, <span class="keyword">nullptr</span>);</div><div class="line"></div><div class="line"><span class="keywordflow">for</span>(<span class="keywordtype">size_t</span> i = 0; i < allocations.size(); ++i)</div><div class="line">{</div><div class="line"> <span class="keywordflow">if</span>(allocationsChanged[i])</div><div class="line"> {</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], &allocInfo);</div><div class="line"></div><div class="line"> vkDestroyBuffer(device, buffers[i], <span class="keyword">nullptr</span>);</div><div class="line"></div><div class="line"> VkBufferCreateInfo bufferInfo = ...;</div><div class="line"> vkCreateBuffer(device, &bufferInfo, <span class="keyword">nullptr</span>, &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"> 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>This function may be time-consuming, so you shouldn't call it too often (like every frame or after every resource creation/destruction), but rater you can call it on special occasions (like when reloading a game level, when you just destroyed a lot of objects). </p>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
@ -1373,8 +1348,7 @@ for(size_t i = 0; i < allocations.size(); ++i)
|
|||
|
||||
<p>Destroys Vulkan buffer and frees allocated memory. </p>
|
||||
<p>This is just a convenience function equivalent to:</p>
|
||||
<pre class="fragment">vkDestroyBuffer(device, buffer, allocationCallbacks);
|
||||
vmaFreeMemory(allocator, allocation);</pre>
|
||||
<div class="fragment"><div class="line">vkDestroyBuffer(device, buffer, allocationCallbacks);</div><div class="line"><a class="code" href="vk__mem__alloc_8h.html#a11f0fbc034fa81a4efedd73d61ce7568">vmaFreeMemory</a>(allocator, allocation);</div></div><!-- fragment -->
|
||||
</div>
|
||||
</div>
|
||||
<a id="ae50d2cb3b4a3bfd4dd40987234e50e7e"></a>
|
||||
|
@ -1411,8 +1385,7 @@ vmaFreeMemory(allocator, allocation);</pre>
|
|||
|
||||
<p>Destroys Vulkan image and frees allocated memory. </p>
|
||||
<p>This is just a convenience function equivalent to:</p>
|
||||
<pre class="fragment">vkDestroyImage(device, image, allocationCallbacks);
|
||||
vmaFreeMemory(allocator, allocation);</pre>
|
||||
<div class="fragment"><div class="line">vkDestroyImage(device, image, allocationCallbacks);</div><div class="line"><a class="code" href="vk__mem__alloc_8h.html#a11f0fbc034fa81a4efedd73d61ce7568">vmaFreeMemory</a>(allocator, allocation);</div></div><!-- fragment -->
|
||||
</div>
|
||||
</div>
|
||||
<a id="a5485779c8f1948238fc4e92232fa65e1"></a>
|
||||
|
@ -1941,10 +1914,7 @@ vmaFreeMemory(allocator, allocation);</pre>
|
|||
|
||||
<p>Unmaps persistently mapped memory of types that are <code>HOST_COHERENT</code> and <code>DEVICE_LOCAL</code>. </p>
|
||||
<p>This is optional performance optimization. On AMD GPUs on Windows, Vulkan memory from the type that has both <code>DEVICE_LOCAL</code> and <code>HOST_VISIBLE</code> flags should not be mapped for the time of any call to <code>vkQueueSubmit()</code> or <code>vkQueuePresent()</code>. Although legal, that would cause performance degradation because WDDM migrates such memory to system RAM. To ensure this, you can unmap all persistently mapped memory using this function. Example:</p>
|
||||
<pre class="fragment">vmaUnmapPersistentlyMappedMemory(allocator);
|
||||
vkQueueSubmit(...)
|
||||
vmaMapPersistentlyMappedMemory(allocator);
|
||||
</pre><p>After this call <a class="el" href="struct_vma_allocation_info.html#a5eeffbe2d2f30f53370ff14aefbadbe2" title="Pointer to the beginning of this allocation as mapped data. Null if this alloaction is not persistent...">VmaAllocationInfo::pMappedData</a> of some allocations may become null.</p>
|
||||
<div class="fragment"><div class="line"><a class="code" href="vk__mem__alloc_8h.html#a26b87244491c1fe77f11fe9ab5779c27">vmaUnmapPersistentlyMappedMemory</a>(allocator);</div><div class="line">vkQueueSubmit(...)</div><div class="line"><a class="code" href="vk__mem__alloc_8h.html#a03366170bb8e186605518d2f5d65b85a">vmaMapPersistentlyMappedMemory</a>(allocator);</div></div><!-- fragment --><p>After this call <a class="el" href="struct_vma_allocation_info.html#a5eeffbe2d2f30f53370ff14aefbadbe2" title="Pointer to the beginning of this allocation as mapped data. Null if this alloaction is not persistent...">VmaAllocationInfo::pMappedData</a> of some allocations may become null.</p>
|
||||
<p>This call is reference-counted. Memory is mapped again after you call <a class="el" href="vk__mem__alloc_8h.html#a03366170bb8e186605518d2f5d65b85a" title="Maps back persistently mapped memory of types that are HOST_COHERENT and DEVICE_LOCAL. ">vmaMapPersistentlyMappedMemory()</a> same number of times that you called <a class="el" href="vk__mem__alloc_8h.html#a26b87244491c1fe77f11fe9ab5779c27" title="Unmaps persistently mapped memory of types that are HOST_COHERENT and DEVICE_LOCAL. ">vmaUnmapPersistentlyMappedMemory()</a>. </p>
|
||||
|
||||
</div>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue