From 0cbeea97a290cc1d263a2d7ed78e9cee6117c72b Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Wed, 11 Jul 2018 17:03:00 +0200 Subject: [PATCH] Support on-demand Vulkan tracing. --- TracyVulkan.hpp | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/TracyVulkan.hpp b/TracyVulkan.hpp index 69740baa..d3595f6b 100644 --- a/TracyVulkan.hpp +++ b/TracyVulkan.hpp @@ -123,11 +123,19 @@ public: void Collect( VkCommandBuffer cmdbuf ) { -#ifndef TRACY_ON_DEMAND ZoneScopedC( Color::Red4 ); 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; if( m_oldCnt != 0 ) { @@ -164,7 +172,6 @@ public: m_tail += cnt; if( m_tail == QueryCount ) m_tail = 0; -#endif } private: @@ -198,8 +205,13 @@ class VkCtxScope public: tracy_force_inline VkCtxScope( const SourceLocation* srcloc, VkCommandBuffer 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; const auto queryId = ctx->NextQueryId(); 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.context, ctx->GetId() ); tail.store( magic + 1, std::memory_order_release ); -#endif } tracy_force_inline VkCtxScope( const SourceLocation* srcloc, VkCommandBuffer cmdbuf, int depth ) : 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(); auto ctx = s_vkCtx.ptr; @@ -241,12 +257,13 @@ public: tail.store( magic + 1, std::memory_order_release ); s_profiler.SendCallstack( depth, thread ); -#endif } tracy_force_inline ~VkCtxScope() { -#ifndef TRACY_ON_DEMAND +#ifdef TRACY_ON_DEMAND + if( !m_active ) return; +#endif auto ctx = s_vkCtx.ptr; const auto queryId = ctx->NextQueryId(); 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.context, ctx->GetId() ); tail.store( magic + 1, std::memory_order_release ); -#endif } private: VkCommandBuffer m_cmdbuf; + +#ifdef TRACY_ON_DEMAND + const bool m_active; +#endif }; }