mirror of
https://github.com/GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator.git
synced 2024-11-22 15:04:34 +00:00
Added "LastUseFrameIndex" to JSON dump. Changed behavior of vmaGetAllocationInfo, vmaTouchAllocation to update allocation.lastUseFrameIndex even if allocation cannot become lost. Documented it.
This commit is contained in:
parent
c22103d183
commit
d9bdd6cf78
@ -79,7 +79,9 @@ $(function() {
|
|||||||
<p>Example code:</p>
|
<p>Example code:</p>
|
||||||
<div class="fragment"><div class="line"><span class="keyword">struct </span>MyBuffer</div><div class="line">{</div><div class="line"> VkBuffer m_Buf = <span class="keyword">nullptr</span>;</div><div class="line"> <a class="code" href="struct_vma_allocation.html">VmaAllocation</a> m_Alloc = <span class="keyword">nullptr</span>;</div><div class="line"></div><div class="line"> <span class="comment">// Called when the buffer is really needed in the current frame.</span></div><div class="line"> <span class="keywordtype">void</span> EnsureBuffer();</div><div class="line">};</div><div class="line"></div><div class="line"><span class="keywordtype">void</span> MyBuffer::EnsureBuffer()</div><div class="line">{</div><div class="line"> <span class="comment">// Buffer has been created.</span></div><div class="line"> <span class="keywordflow">if</span>(m_Buf != VK_NULL_HANDLE)</div><div class="line"> {</div><div class="line"> <span class="comment">// Check if its allocation is not lost + mark it as used in current frame.</span></div><div class="line"> <span class="keywordflow">if</span>(<a class="code" href="vk__mem__alloc_8h.html#a43d8ba9673c846f049089a5029d5c73a">vmaTouchAllocation</a>(allocator, m_Alloc))</div><div class="line"> {</div><div class="line"> <span class="comment">// It's all OK - safe to use m_Buf.</span></div><div class="line"> <span class="keywordflow">return</span>;</div><div class="line"> }</div><div class="line"> }</div><div class="line"></div><div class="line"> <span class="comment">// Buffer not yet exists or lost - destroy and recreate it.</span></div><div class="line"></div><div class="line"> <a class="code" href="vk__mem__alloc_8h.html#a0d9f4e4ba5bf9aab1f1c746387753d77">vmaDestroyBuffer</a>(allocator, m_Buf, m_Alloc);</div><div class="line"></div><div class="line"> VkBufferCreateInfo bufCreateInfo = { VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO };</div><div class="line"> bufCreateInfo.size = 1024;</div><div class="line"> bufCreateInfo.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT;</div><div class="line"></div><div class="line"> <a class="code" href="struct_vma_allocation_create_info.html">VmaAllocationCreateInfo</a> allocCreateInfo = {};</div><div class="line"> allocCreateInfo.<a class="code" href="struct_vma_allocation_create_info.html#accb8b06b1f677d858cb9af20705fa910">usage</a> = <a class="code" href="vk__mem__alloc_8h.html#aa5846affa1e9da3800e3e78fae2305ccac6b5dc1432d88647aa4cd456246eadf7">VMA_MEMORY_USAGE_GPU_ONLY</a>;</div><div class="line"> allocCreateInfo.<a class="code" href="struct_vma_allocation_create_info.html#add09658ac14fe290ace25470ddd6d41b">flags</a> = <a class="code" href="vk__mem__alloc_8h.html#ad9889c10c798b040d59c92f257cae597a5f436af6c8fe8540573a6d22627a6fd2">VMA_ALLOCATION_CREATE_CAN_BECOME_LOST_BIT</a> |</div><div class="line"> <a class="code" href="vk__mem__alloc_8h.html#ad9889c10c798b040d59c92f257cae597a68686d0ce9beb0d4d1b9f2b8b1389a7e">VMA_ALLOCATION_CREATE_CAN_MAKE_OTHER_LOST_BIT</a>;</div><div class="line"></div><div class="line"> <a class="code" href="vk__mem__alloc_8h.html#ac72ee55598617e8eecca384e746bab51">vmaCreateBuffer</a>(allocator, &bufCreateInfo, &allocCreateInfo, &m_Buf, &m_Alloc, <span class="keyword">nullptr</span>);</div><div class="line">}</div></div><!-- fragment --><p>When using lost allocations, you may see some Vulkan validation layer warnings about overlapping regions of memory bound to different kinds of buffers and images. This is still valid as long as you implement proper handling of lost allocations (like in the example above) and don't use them.</p>
|
<div class="fragment"><div class="line"><span class="keyword">struct </span>MyBuffer</div><div class="line">{</div><div class="line"> VkBuffer m_Buf = <span class="keyword">nullptr</span>;</div><div class="line"> <a class="code" href="struct_vma_allocation.html">VmaAllocation</a> m_Alloc = <span class="keyword">nullptr</span>;</div><div class="line"></div><div class="line"> <span class="comment">// Called when the buffer is really needed in the current frame.</span></div><div class="line"> <span class="keywordtype">void</span> EnsureBuffer();</div><div class="line">};</div><div class="line"></div><div class="line"><span class="keywordtype">void</span> MyBuffer::EnsureBuffer()</div><div class="line">{</div><div class="line"> <span class="comment">// Buffer has been created.</span></div><div class="line"> <span class="keywordflow">if</span>(m_Buf != VK_NULL_HANDLE)</div><div class="line"> {</div><div class="line"> <span class="comment">// Check if its allocation is not lost + mark it as used in current frame.</span></div><div class="line"> <span class="keywordflow">if</span>(<a class="code" href="vk__mem__alloc_8h.html#a43d8ba9673c846f049089a5029d5c73a">vmaTouchAllocation</a>(allocator, m_Alloc))</div><div class="line"> {</div><div class="line"> <span class="comment">// It's all OK - safe to use m_Buf.</span></div><div class="line"> <span class="keywordflow">return</span>;</div><div class="line"> }</div><div class="line"> }</div><div class="line"></div><div class="line"> <span class="comment">// Buffer not yet exists or lost - destroy and recreate it.</span></div><div class="line"></div><div class="line"> <a class="code" href="vk__mem__alloc_8h.html#a0d9f4e4ba5bf9aab1f1c746387753d77">vmaDestroyBuffer</a>(allocator, m_Buf, m_Alloc);</div><div class="line"></div><div class="line"> VkBufferCreateInfo bufCreateInfo = { VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO };</div><div class="line"> bufCreateInfo.size = 1024;</div><div class="line"> bufCreateInfo.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT;</div><div class="line"></div><div class="line"> <a class="code" href="struct_vma_allocation_create_info.html">VmaAllocationCreateInfo</a> allocCreateInfo = {};</div><div class="line"> allocCreateInfo.<a class="code" href="struct_vma_allocation_create_info.html#accb8b06b1f677d858cb9af20705fa910">usage</a> = <a class="code" href="vk__mem__alloc_8h.html#aa5846affa1e9da3800e3e78fae2305ccac6b5dc1432d88647aa4cd456246eadf7">VMA_MEMORY_USAGE_GPU_ONLY</a>;</div><div class="line"> allocCreateInfo.<a class="code" href="struct_vma_allocation_create_info.html#add09658ac14fe290ace25470ddd6d41b">flags</a> = <a class="code" href="vk__mem__alloc_8h.html#ad9889c10c798b040d59c92f257cae597a5f436af6c8fe8540573a6d22627a6fd2">VMA_ALLOCATION_CREATE_CAN_BECOME_LOST_BIT</a> |</div><div class="line"> <a class="code" href="vk__mem__alloc_8h.html#ad9889c10c798b040d59c92f257cae597a68686d0ce9beb0d4d1b9f2b8b1389a7e">VMA_ALLOCATION_CREATE_CAN_MAKE_OTHER_LOST_BIT</a>;</div><div class="line"></div><div class="line"> <a class="code" href="vk__mem__alloc_8h.html#ac72ee55598617e8eecca384e746bab51">vmaCreateBuffer</a>(allocator, &bufCreateInfo, &allocCreateInfo, &m_Buf, &m_Alloc, <span class="keyword">nullptr</span>);</div><div class="line">}</div></div><!-- fragment --><p>When using lost allocations, you may see some Vulkan validation layer warnings about overlapping regions of memory bound to different kinds of buffers and images. This is still valid as long as you implement proper handling of lost allocations (like in the example above) and don't use them.</p>
|
||||||
<p>You can create an allocation that is already in lost state from the beginning using function <a class="el" href="vk__mem__alloc_8h.html#ae5c9657d9e94756269145b01c05d16f1" title="Creates new allocation that is in lost state from the beginning. ">vmaCreateLostAllocation()</a>. It may be useful if you need a "dummy" allocation that is not null.</p>
|
<p>You can create an allocation that is already in lost state from the beginning using function <a class="el" href="vk__mem__alloc_8h.html#ae5c9657d9e94756269145b01c05d16f1" title="Creates new allocation that is in lost state from the beginning. ">vmaCreateLostAllocation()</a>. It may be useful if you need a "dummy" allocation that is not null.</p>
|
||||||
<p>You can call function <a class="el" href="vk__mem__alloc_8h.html#a736bd6cbda886f36c891727e73bd4024" title="Marks all allocations in given pool as lost if they are not used in current frame or VmaPoolCreateInf...">vmaMakePoolAllocationsLost()</a> to set all eligible allocations in a specified custom pool to lost state. Allocations that have been "touched" in current frame or <a class="el" href="struct_vma_pool_create_info.html#a9437e43ffbb644dbbf7fc4e50cfad6aa" title="Maximum number of additional frames that are in use at the same time as current frame. ">VmaPoolCreateInfo::frameInUseCount</a> frames back cannot become lost. </p>
|
<p>You can call function <a class="el" href="vk__mem__alloc_8h.html#a736bd6cbda886f36c891727e73bd4024" title="Marks all allocations in given pool as lost if they are not used in current frame or VmaPoolCreateInf...">vmaMakePoolAllocationsLost()</a> to set all eligible allocations in a specified custom pool to lost state. Allocations that have been "touched" in current frame or <a class="el" href="struct_vma_pool_create_info.html#a9437e43ffbb644dbbf7fc4e50cfad6aa" title="Maximum number of additional frames that are in use at the same time as current frame. ">VmaPoolCreateInfo::frameInUseCount</a> frames back cannot become lost.</p>
|
||||||
|
<p><b>Q: Can I touch allocation that cannot become lost?</b></p>
|
||||||
|
<p>Yes, although it has no visible effect. Calls to <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> and <a class="el" href="vk__mem__alloc_8h.html#a43d8ba9673c846f049089a5029d5c73a" title="Returns VK_TRUE if allocation is not lost and atomically marks it as used in current frame...">vmaTouchAllocation()</a> update last use frame index also for allocations that cannot become lost, but the only way to observe it is to dump internal allocator state using <a class="el" href="vk__mem__alloc_8h.html#aa4fee7eb5253377599ef4fd38c93c2a0" title="Builds and returns statistics as string in JSON format. ">vmaBuildStatsString()</a>. You can use this feature for debugging purposes to explicitly mark allocations that you use in current frame and then analyze JSON dump to see for how long each allocation stays unused. </p>
|
||||||
</div></div><!-- contents -->
|
</div></div><!-- contents -->
|
||||||
<!-- start footer part -->
|
<!-- start footer part -->
|
||||||
<hr class="footer"/><address class="footer"><small>
|
<hr class="footer"/><address class="footer"><small>
|
||||||
|
File diff suppressed because one or more lines are too long
@ -686,6 +686,15 @@ in a specified custom pool to lost state.
|
|||||||
Allocations that have been "touched" in current frame or VmaPoolCreateInfo::frameInUseCount frames back
|
Allocations that have been "touched" in current frame or VmaPoolCreateInfo::frameInUseCount frames back
|
||||||
cannot become lost.
|
cannot become lost.
|
||||||
|
|
||||||
|
<b>Q: Can I touch allocation that cannot become lost?</b>
|
||||||
|
|
||||||
|
Yes, although it has no visible effect.
|
||||||
|
Calls to vmaGetAllocationInfo() and vmaTouchAllocation() update last use frame index
|
||||||
|
also for allocations that cannot become lost, but the only way to observe it is to dump
|
||||||
|
internal allocator state using vmaBuildStatsString().
|
||||||
|
You can use this feature for debugging purposes to explicitly mark allocations that you use
|
||||||
|
in current frame and then analyze JSON dump to see for how long each allocation stays unused.
|
||||||
|
|
||||||
|
|
||||||
\page statistics Statistics
|
\page statistics Statistics
|
||||||
|
|
||||||
@ -5188,6 +5197,9 @@ void VmaAllocation_T::PrintParameters(class VmaJsonWriter& json) const
|
|||||||
json.WriteString("CreationFrameIndex");
|
json.WriteString("CreationFrameIndex");
|
||||||
json.WriteNumber(m_CreationFrameIndex);
|
json.WriteNumber(m_CreationFrameIndex);
|
||||||
|
|
||||||
|
json.WriteString("LastUseFrameIndex");
|
||||||
|
json.WriteNumber(GetLastUseFrameIndex());
|
||||||
|
|
||||||
if(m_BufferImageUsage != 0)
|
if(m_BufferImageUsage != 0)
|
||||||
{
|
{
|
||||||
json.WriteString("Usage");
|
json.WriteString("Usage");
|
||||||
@ -8251,6 +8263,26 @@ void VmaAllocator_T::GetAllocationInfo(VmaAllocation hAllocation, VmaAllocationI
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
#if VMA_STATS_STRING_ENABLED
|
||||||
|
uint32_t localCurrFrameIndex = m_CurrentFrameIndex.load();
|
||||||
|
uint32_t localLastUseFrameIndex = hAllocation->GetLastUseFrameIndex();
|
||||||
|
for(;;)
|
||||||
|
{
|
||||||
|
VMA_ASSERT(localLastUseFrameIndex != VMA_FRAME_INDEX_LOST);
|
||||||
|
if(localLastUseFrameIndex == localCurrFrameIndex)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else // Last use time earlier than current time.
|
||||||
|
{
|
||||||
|
if(hAllocation->CompareExchangeLastUseFrameIndex(localLastUseFrameIndex, localCurrFrameIndex))
|
||||||
|
{
|
||||||
|
localLastUseFrameIndex = localCurrFrameIndex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
pAllocationInfo->memoryType = hAllocation->GetMemoryTypeIndex();
|
pAllocationInfo->memoryType = hAllocation->GetMemoryTypeIndex();
|
||||||
pAllocationInfo->deviceMemory = hAllocation->GetMemory();
|
pAllocationInfo->deviceMemory = hAllocation->GetMemory();
|
||||||
pAllocationInfo->offset = hAllocation->GetOffset();
|
pAllocationInfo->offset = hAllocation->GetOffset();
|
||||||
@ -8288,6 +8320,26 @@ bool VmaAllocator_T::TouchAllocation(VmaAllocation hAllocation)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
#if VMA_STATS_STRING_ENABLED
|
||||||
|
uint32_t localCurrFrameIndex = m_CurrentFrameIndex.load();
|
||||||
|
uint32_t localLastUseFrameIndex = hAllocation->GetLastUseFrameIndex();
|
||||||
|
for(;;)
|
||||||
|
{
|
||||||
|
VMA_ASSERT(localLastUseFrameIndex != VMA_FRAME_INDEX_LOST);
|
||||||
|
if(localLastUseFrameIndex == localCurrFrameIndex)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else // Last use time earlier than current time.
|
||||||
|
{
|
||||||
|
if(hAllocation->CompareExchangeLastUseFrameIndex(localLastUseFrameIndex, localCurrFrameIndex))
|
||||||
|
{
|
||||||
|
localLastUseFrameIndex = localCurrFrameIndex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user