Support on-demand Vulkan tracing.

This commit is contained in:
Bartosz Taudul 2018-07-11 17:03:00 +02:00
parent 1f7246f6b9
commit 0cbeea97a2

View File

@ -123,11 +123,19 @@ public:
void Collect( VkCommandBuffer cmdbuf ) void Collect( VkCommandBuffer cmdbuf )
{ {
#ifndef TRACY_ON_DEMAND
ZoneScopedC( Color::Red4 ); ZoneScopedC( Color::Red4 );
if( m_tail == m_head ) return; if( m_tail == m_head ) return;
#ifdef TRACY_ON_DEMAND
if( !s_profiler.IsConnected() )
{
vkCmdResetQueryPool( cmdbuf, m_query, 0, QueryCount );
m_head = m_tail = 0;
return;
}
#endif
unsigned int cnt; unsigned int cnt;
if( m_oldCnt != 0 ) if( m_oldCnt != 0 )
{ {
@ -164,7 +172,6 @@ public:
m_tail += cnt; m_tail += cnt;
if( m_tail == QueryCount ) m_tail = 0; if( m_tail == QueryCount ) m_tail = 0;
#endif
} }
private: private:
@ -198,8 +205,13 @@ class VkCtxScope
public: public:
tracy_force_inline VkCtxScope( const SourceLocation* srcloc, VkCommandBuffer cmdbuf ) tracy_force_inline VkCtxScope( const SourceLocation* srcloc, VkCommandBuffer cmdbuf )
: m_cmdbuf( cmdbuf ) : m_cmdbuf( cmdbuf )
#ifdef TRACY_ON_DEMAND
, m_active( s_profiler.IsConnected() )
#endif
{ {
#ifndef TRACY_ON_DEMAND #ifdef TRACY_ON_DEMAND
if( !m_active ) return;
#endif
auto ctx = s_vkCtx.ptr; auto ctx = s_vkCtx.ptr;
const auto queryId = ctx->NextQueryId(); const auto queryId = ctx->NextQueryId();
vkCmdWriteTimestamp( cmdbuf, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, ctx->m_query, queryId ); vkCmdWriteTimestamp( cmdbuf, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, ctx->m_query, queryId );
@ -215,13 +227,17 @@ public:
MemWrite( &item->gpuZoneBegin.queryId, uint16_t( queryId ) ); MemWrite( &item->gpuZoneBegin.queryId, uint16_t( queryId ) );
MemWrite( &item->gpuZoneBegin.context, ctx->GetId() ); MemWrite( &item->gpuZoneBegin.context, ctx->GetId() );
tail.store( magic + 1, std::memory_order_release ); tail.store( magic + 1, std::memory_order_release );
#endif
} }
tracy_force_inline VkCtxScope( const SourceLocation* srcloc, VkCommandBuffer cmdbuf, int depth ) tracy_force_inline VkCtxScope( const SourceLocation* srcloc, VkCommandBuffer cmdbuf, int depth )
: m_cmdbuf( cmdbuf ) : m_cmdbuf( cmdbuf )
#ifdef TRACY_ON_DEMAND
, m_active( s_profiler.IsConnected() )
#endif
{ {
#ifndef TRACY_ON_DEMAND #ifdef TRACY_ON_DEMAND
if( !m_active ) return;
#endif
const auto thread = GetThreadHandle(); const auto thread = GetThreadHandle();
auto ctx = s_vkCtx.ptr; auto ctx = s_vkCtx.ptr;
@ -241,12 +257,13 @@ public:
tail.store( magic + 1, std::memory_order_release ); tail.store( magic + 1, std::memory_order_release );
s_profiler.SendCallstack( depth, thread ); s_profiler.SendCallstack( depth, thread );
#endif
} }
tracy_force_inline ~VkCtxScope() tracy_force_inline ~VkCtxScope()
{ {
#ifndef TRACY_ON_DEMAND #ifdef TRACY_ON_DEMAND
if( !m_active ) return;
#endif
auto ctx = s_vkCtx.ptr; auto ctx = s_vkCtx.ptr;
const auto queryId = ctx->NextQueryId(); const auto queryId = ctx->NextQueryId();
vkCmdWriteTimestamp( m_cmdbuf, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, ctx->m_query, queryId ); vkCmdWriteTimestamp( m_cmdbuf, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, ctx->m_query, queryId );
@ -260,11 +277,14 @@ public:
MemWrite( &item->gpuZoneEnd.queryId, uint16_t( queryId ) ); MemWrite( &item->gpuZoneEnd.queryId, uint16_t( queryId ) );
MemWrite( &item->gpuZoneEnd.context, ctx->GetId() ); MemWrite( &item->gpuZoneEnd.context, ctx->GetId() );
tail.store( magic + 1, std::memory_order_release ); tail.store( magic + 1, std::memory_order_release );
#endif
} }
private: private:
VkCommandBuffer m_cmdbuf; VkCommandBuffer m_cmdbuf;
#ifdef TRACY_ON_DEMAND
const bool m_active;
#endif
}; };
} }