diff --git a/TracyOpenGL.hpp b/TracyOpenGL.hpp index 65444857..d810596e 100644 --- a/TracyOpenGL.hpp +++ b/TracyOpenGL.hpp @@ -102,6 +102,22 @@ public: tail.store( magic + 1, std::memory_order_release ); m_tail = ( m_tail + 1 ) % QueryCount; } + + { + int64_t tgpu; + glGetInteger64v( GL_TIMESTAMP, &tgpu ); + int64_t tcpu = Profiler::GetTime(); + + Magic magic; + auto& token = s_token.ptr; + auto& tail = token->get_tail_index(); + auto item = token->enqueue_begin( magic ); + item->hdr.type = QueueType::GpuResync; + item->gpuResync.cpuTime = tcpu; + item->gpuResync.gpuTime = tgpu; + item->gpuResync.context = m_context; + tail.store( magic + 1, std::memory_order_release ); + } } private: diff --git a/common/TracyQueue.hpp b/common/TracyQueue.hpp index c7c68256..e9495301 100644 --- a/common/TracyQueue.hpp +++ b/common/TracyQueue.hpp @@ -26,6 +26,7 @@ enum class QueueType : uint8_t GpuZoneBegin, GpuZoneEnd, GpuTime, + GpuResync, StringData, ThreadName, CustomStringData, @@ -162,6 +163,13 @@ struct QueueGpuTime uint16_t context; }; +struct QueueGpuResync +{ + int64_t cpuTime; + int64_t gpuTime; + uint16_t context; +}; + struct QueueHeader { union @@ -192,6 +200,7 @@ struct QueueItem QueueGpuZoneBegin gpuZoneBegin; QueueGpuZoneEnd gpuZoneEnd; QueueGpuTime gpuTime; + QueueGpuResync gpuResync; }; }; @@ -219,6 +228,7 @@ static const size_t QueueDataSize[] = { sizeof( QueueHeader ) + sizeof( QueueGpuZoneBegin ), sizeof( QueueHeader ) + sizeof( QueueGpuZoneEnd ), sizeof( QueueHeader ) + sizeof( QueueGpuTime ), + sizeof( QueueHeader ) + sizeof( QueueGpuResync ), // keep all QueueStringTransfer below sizeof( QueueHeader ) + sizeof( QueueStringTransfer ), // string data sizeof( QueueHeader ) + sizeof( QueueStringTransfer ), // thread name diff --git a/server/TracyEvent.hpp b/server/TracyEvent.hpp index 98e9e226..c39e428c 100644 --- a/server/TracyEvent.hpp +++ b/server/TracyEvent.hpp @@ -151,6 +151,12 @@ struct ThreadData Vector messages; }; +struct GpuCtxResync +{ + int64_t timeDiff; + uint16_t events; +}; + struct GpuCtxData { int64_t timeDiff; @@ -159,6 +165,7 @@ struct GpuCtxData Vector timeline; Vector stack; Vector queue; + Vector resync; uint8_t accuracyBits; bool showFull; }; diff --git a/server/TracyView.cpp b/server/TracyView.cpp index 5048f015..e2a50d41 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -619,6 +619,9 @@ void View::Process( const QueueItem& ev ) case QueueType::GpuTime: ProcessGpuTime( ev.gpuTime ); break; + case QueueType::GpuResync: + ProcessGpuResync( ev.gpuResync ); + break; case QueueType::Terminate: m_terminate = true; break; @@ -912,6 +915,44 @@ void View::ProcessGpuTime( const QueueGpuTime& ev ) } ctx->queue.erase( ctx->queue.begin() ); + if( !ctx->resync.empty() ) + { + auto& resync = ctx->resync.front(); + assert( resync.events > 0 ); + resync.events--; + if( resync.events == 0 ) + { + ctx->timeDiff = resync.timeDiff; + ctx->resync.erase( ctx->resync.begin() ); + } + } +} + +void View::ProcessGpuResync( const QueueGpuResync& ev ) +{ + auto it = m_gpuCtxMap.find( ev.context ); + assert( it != m_gpuCtxMap.end() ); + auto ctx = it->second; + + const auto timeDiff = int64_t( ev.cpuTime * m_timerMul - ev.gpuTime ); + + if( ctx->queue.empty() ) + { + assert( ctx->resync.empty() ); + ctx->timeDiff = timeDiff; + } + else + { + if( ctx->resync.empty() ) + { + ctx->resync.push_back( { timeDiff, uint16_t( ctx->queue.size() ) } ); + } + else + { + const auto last = ctx->resync.back().events; + ctx->resync.push_back( { timeDiff, uint16_t( ctx->queue.size() - last ) } ); + } + } } void View::CheckString( uint64_t ptr ) diff --git a/server/TracyView.hpp b/server/TracyView.hpp index 40a43c49..18219127 100644 --- a/server/TracyView.hpp +++ b/server/TracyView.hpp @@ -76,6 +76,7 @@ private: tracy_force_inline void ProcessGpuZoneBegin( const QueueGpuZoneBegin& ev ); tracy_force_inline void ProcessGpuZoneEnd( const QueueGpuZoneEnd& ev ); tracy_force_inline void ProcessGpuTime( const QueueGpuTime& ev ); + tracy_force_inline void ProcessGpuResync( const QueueGpuResync& ev ); void CheckString( uint64_t ptr ); void CheckThreadString( uint64_t id );