1
0
mirror of https://github.com/wolfpld/tracy synced 2025-04-29 04:23:51 +00:00

Make vulkan query count variable.

This commit is contained in:
Bartosz Taudul 2019-06-26 16:42:51 +02:00
parent bc7f2c49c8
commit 659631fc06

View File

@ -49,6 +49,7 @@ public:
, m_head( 0 ) , m_head( 0 )
, m_tail( 0 ) , m_tail( 0 )
, m_oldCnt( 0 ) , m_oldCnt( 0 )
, m_queryCount( QueryCount )
{ {
assert( m_context != 255 ); assert( m_context != 255 );
@ -58,7 +59,7 @@ public:
VkQueryPoolCreateInfo poolInfo = {}; VkQueryPoolCreateInfo poolInfo = {};
poolInfo.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO; poolInfo.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
poolInfo.queryCount = QueryCount; poolInfo.queryCount = m_queryCount;
poolInfo.queryType = VK_QUERY_TYPE_TIMESTAMP; poolInfo.queryType = VK_QUERY_TYPE_TIMESTAMP;
vkCreateQueryPool( device, &poolInfo, nullptr, &m_query ); vkCreateQueryPool( device, &poolInfo, nullptr, &m_query );
@ -72,7 +73,7 @@ public:
submitInfo.pCommandBuffers = &cmdbuf; submitInfo.pCommandBuffers = &cmdbuf;
vkBeginCommandBuffer( cmdbuf, &beginInfo ); vkBeginCommandBuffer( cmdbuf, &beginInfo );
vkCmdResetQueryPool( cmdbuf, m_query, 0, QueryCount ); vkCmdResetQueryPool( cmdbuf, m_query, 0, m_queryCount );
vkEndCommandBuffer( cmdbuf ); vkEndCommandBuffer( cmdbuf );
vkQueueSubmit( queue, 1, &submitInfo, VK_NULL_HANDLE ); vkQueueSubmit( queue, 1, &submitInfo, VK_NULL_HANDLE );
vkQueueWaitIdle( queue ); vkQueueWaitIdle( queue );
@ -110,10 +111,13 @@ public:
#endif #endif
tail.store( magic + 1, std::memory_order_release ); tail.store( magic + 1, std::memory_order_release );
m_res = (int64_t*)tracy_malloc( sizeof( int64_t ) * m_queryCount );
} }
~VkCtx() ~VkCtx()
{ {
tracy_free( m_res );
vkDestroyQueryPool( m_device, m_query, nullptr ); vkDestroyQueryPool( m_device, m_query, nullptr );
} }
@ -126,7 +130,7 @@ public:
#ifdef TRACY_ON_DEMAND #ifdef TRACY_ON_DEMAND
if( !GetProfiler().IsConnected() ) if( !GetProfiler().IsConnected() )
{ {
vkCmdResetQueryPool( cmdbuf, m_query, 0, QueryCount ); vkCmdResetQueryPool( cmdbuf, m_query, 0, m_queryCount );
m_head = m_tail = 0; m_head = m_tail = 0;
return; return;
} }
@ -140,11 +144,10 @@ public:
} }
else else
{ {
cnt = m_head < m_tail ? QueryCount - m_tail : m_head - m_tail; cnt = m_head < m_tail ? m_queryCount - m_tail : m_head - m_tail;
} }
int64_t res[QueryCount]; if( vkGetQueryPoolResults( m_device, m_query, m_tail, cnt, sizeof( int64_t ) * m_queryCount, m_res, sizeof( int64_t ), VK_QUERY_RESULT_64_BIT ) == VK_NOT_READY )
if( vkGetQueryPoolResults( m_device, m_query, m_tail, cnt, sizeof( res ), res, sizeof( *res ), VK_QUERY_RESULT_64_BIT ) == VK_NOT_READY )
{ {
m_oldCnt = cnt; m_oldCnt = cnt;
return; return;
@ -158,7 +161,7 @@ public:
{ {
auto item = token->enqueue_begin<tracy::moodycamel::CanAlloc>( magic ); auto item = token->enqueue_begin<tracy::moodycamel::CanAlloc>( magic );
MemWrite( &item->hdr.type, QueueType::GpuTime ); MemWrite( &item->hdr.type, QueueType::GpuTime );
MemWrite( &item->gpuTime.gpuTime, res[idx] ); MemWrite( &item->gpuTime.gpuTime, m_res[idx] );
MemWrite( &item->gpuTime.queryId, uint16_t( m_tail + idx ) ); MemWrite( &item->gpuTime.queryId, uint16_t( m_tail + idx ) );
MemWrite( &item->gpuTime.context, m_context ); MemWrite( &item->gpuTime.context, m_context );
tail.store( magic + 1, std::memory_order_release ); tail.store( magic + 1, std::memory_order_release );
@ -167,14 +170,14 @@ public:
vkCmdResetQueryPool( cmdbuf, m_query, m_tail, cnt ); vkCmdResetQueryPool( cmdbuf, m_query, m_tail, cnt );
m_tail += cnt; m_tail += cnt;
if( m_tail == QueryCount ) m_tail = 0; if( m_tail == m_queryCount ) m_tail = 0;
} }
private: private:
tracy_force_inline unsigned int NextQueryId() tracy_force_inline unsigned int NextQueryId()
{ {
const auto id = m_head; const auto id = m_head;
m_head = ( m_head + 1 ) % QueryCount; m_head = ( m_head + 1 ) % m_queryCount;
assert( m_head != m_tail ); assert( m_head != m_tail );
return id; return id;
} }
@ -192,6 +195,9 @@ private:
unsigned int m_head; unsigned int m_head;
unsigned int m_tail; unsigned int m_tail;
unsigned int m_oldCnt; unsigned int m_oldCnt;
unsigned int m_queryCount;
int64_t* m_res;
}; };
class VkCtxScope class VkCtxScope