From 54a029356d6c502a9397953c39615a0257ba133e Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Wed, 27 May 2020 18:16:53 +0200 Subject: [PATCH] Explicitly store GPU context type. --- TracyOpenGL.hpp | 1 + TracyVulkan.hpp | 2 ++ common/TracyProtocol.hpp | 2 +- common/TracyQueue.hpp | 9 +++++++++ server/TracyEvent.hpp | 2 ++ server/TracyVersion.hpp | 2 +- server/TracyView.cpp | 34 +++++++++++++--------------------- server/TracyWorker.cpp | 13 ++++++++++++- 8 files changed, 41 insertions(+), 24 deletions(-) diff --git a/TracyOpenGL.hpp b/TracyOpenGL.hpp index 9150b704..e4d831d3 100644 --- a/TracyOpenGL.hpp +++ b/TracyOpenGL.hpp @@ -111,6 +111,7 @@ public: MemWrite( &item->gpuNewContext.period, period ); MemWrite( &item->gpuNewContext.context, m_context ); MemWrite( &item->gpuNewContext.accuracyBits, (uint8_t)bits ); + MemWrite( &item->gpuNewContext.type, GpuContextType::OpenGl ); #ifdef TRACY_ON_DEMAND GetProfiler().DeferItem( *item ); diff --git a/TracyVulkan.hpp b/TracyVulkan.hpp index 68efea58..4482f987 100644 --- a/TracyVulkan.hpp +++ b/TracyVulkan.hpp @@ -105,6 +105,8 @@ public: MemWrite( &item->gpuNewContext.period, period ); MemWrite( &item->gpuNewContext.context, m_context ); MemWrite( &item->gpuNewContext.accuracyBits, uint8_t( 0 ) ); + MemWrite( &item->gpuNewContext.type, GpuContextType::Vulkan ); + #ifdef TRACY_ON_DEMAND GetProfiler().DeferItem( *item ); #endif diff --git a/common/TracyProtocol.hpp b/common/TracyProtocol.hpp index 6cf94c7b..d30aad0e 100644 --- a/common/TracyProtocol.hpp +++ b/common/TracyProtocol.hpp @@ -9,7 +9,7 @@ namespace tracy constexpr unsigned Lz4CompressBound( unsigned isize ) { return isize + ( isize / 255 ) + 16; } -enum : uint32_t { ProtocolVersion = 32 }; +enum : uint32_t { ProtocolVersion = 33 }; enum : uint32_t { BroadcastVersion = 1 }; using lz4sz_t = uint32_t; diff --git a/common/TracyQueue.hpp b/common/TracyQueue.hpp index 7bc34ed2..f791410b 100644 --- a/common/TracyQueue.hpp +++ b/common/TracyQueue.hpp @@ -258,6 +258,14 @@ struct QueueMessageColor : public QueueMessage uint8_t b; }; +// Don't change order, only add new entries at the end, this is also used on trace dumps! +enum class GpuContextType : uint8_t +{ + Invalid, + OpenGl, + Vulkan +}; + struct QueueGpuNewContext { int64_t cpuTime; @@ -266,6 +274,7 @@ struct QueueGpuNewContext float period; uint8_t context; uint8_t accuracyBits; + GpuContextType type; }; struct QueueGpuZoneBegin diff --git a/server/TracyEvent.hpp b/server/TracyEvent.hpp index f4ad85de..8545b867 100644 --- a/server/TracyEvent.hpp +++ b/server/TracyEvent.hpp @@ -12,6 +12,7 @@ #include "TracyVector.hpp" #include "tracy_robin_hood.h" #include "../common/TracyForceInline.hpp" +#include "../common/TracyQueue.hpp" namespace tracy { @@ -571,6 +572,7 @@ struct GpuCtxData float period; unordered_flat_map threadData; short_ptr query[64*1024]; + GpuContextType type; }; enum { GpuCtxDataSize = sizeof( GpuCtxData ) }; diff --git a/server/TracyVersion.hpp b/server/TracyVersion.hpp index 4e9d7870..d040147a 100644 --- a/server/TracyVersion.hpp +++ b/server/TracyVersion.hpp @@ -7,7 +7,7 @@ namespace Version { enum { Major = 0 }; enum { Minor = 6 }; -enum { Patch = 13 }; +enum { Patch = 14 }; } } diff --git a/server/TracyView.cpp b/server/TracyView.cpp index 01b1a7c8..87dbac88 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -54,7 +54,7 @@ namespace tracy static double s_time = 0; -static const char* s_tracyStackFrames[] = { +constexpr const char* s_tracyStackFrames[] = { "tracy::Callstack", "tracy::Callstack(int)", "tracy::GpuCtxScope::{ctor}", @@ -72,6 +72,12 @@ static const char* s_tracyStackFrames[] = { nullptr }; +constexpr const char* GpuContextNames[] = { + "Invalid", + "OpenGL", + "Vulkan" +}; + static inline uint64_t GetThreadBit( uint8_t thread ) { @@ -2464,16 +2470,10 @@ void View::DrawZones() { draw->AddTriangle( wpos + ImVec2( to/2, oldOffset + to/2 ), wpos + ImVec2( to/2, oldOffset + ty - to/2 ), wpos + ImVec2( to/2 + th, oldOffset + ty * 0.5 ), 0xFF886666, 2.0f ); } - const bool isVulkan = v->thread == 0; + + const bool isMultithreaded = v->type == GpuContextType::Vulkan; char buf[64]; - if( isVulkan ) - { - sprintf( buf, "Vulkan context %zu", i ); - } - else - { - sprintf( buf, "OpenGL context %zu", i ); - } + sprintf( buf, "%s context %zu", GpuContextNames[(int)v->type], i ); DrawTextContrast( draw, wpos + ImVec2( ty, oldOffset ), showFull ? 0xFFFFAAAA : 0xFF886666, buf ); if( hover && ImGui::IsMouseHoveringRect( wpos + ImVec2( 0, oldOffset ), wpos + ImVec2( ty + ImGui::CalcTextSize( buf ).x, oldOffset + ty ) ) ) @@ -2513,7 +2513,7 @@ void View::DrawZones() ImGui::BeginTooltip(); ImGui::TextUnformatted( buf ); ImGui::Separator(); - if( !isVulkan ) + if( !isMultithreaded ) { SmallColorBox( GetThreadColor( v->thread, 0 ) ); ImGui::SameLine(); @@ -2590,7 +2590,7 @@ void View::DrawZones() } TextFocused( "Zone count:", RealToString( v->count ) ); //TextFocused( "Top-level zones:", RealToString( v->timeline.size() ) ); - if( isVulkan ) + if( isMultithreaded ) { TextFocused( "Timestamp accuracy:", TimeToString( v->period ) ); } @@ -7878,16 +7878,8 @@ void View::DrawOptions() for( size_t i=0; ithreadData.begin()->second.timeline; - const bool isVulkan = gpuData[i]->thread == 0; char buf[1024]; - if( isVulkan ) - { - sprintf( buf, "Vulkan context %zu", i ); - } - else - { - sprintf( buf, "OpenGL context %zu", i ); - } + sprintf( buf, "%s context %zu", GpuContextNames[(int)gpuData[i]->type], i ); SmallCheckbox( buf, &Vis( gpuData[i] ).visible ); ImGui::SameLine(); if( gpuData[i]->threadData.size() == 1 ) diff --git a/server/TracyWorker.cpp b/server/TracyWorker.cpp index a4227828..5fa13af4 100644 --- a/server/TracyWorker.cpp +++ b/server/TracyWorker.cpp @@ -1082,7 +1082,15 @@ Worker::Worker( FileRead& f, EventType::Type eventMask, bool bgTasks ) for( uint64_t i=0; i(); - f.Read4( ctx->thread, ctx->accuracyBits, ctx->count, ctx->period ); + if( fileVer >= FileVersion( 0, 6, 14 ) ) + { + f.Read5( ctx->thread, ctx->accuracyBits, ctx->count, ctx->period, ctx->type ); + } + else + { + f.Read4( ctx->thread, ctx->accuracyBits, ctx->count, ctx->period ); + ctx->type = ctx->thread == 0 ? GpuContextType::Vulkan : GpuContextType::OpenGl; + } m_data.gpuCnt += ctx->count; if( fileVer >= FileVersion( 0, 5, 10 ) ) { @@ -5163,6 +5171,7 @@ void Worker::ProcessMessageAppInfo( const QueueMessage& ev ) void Worker::ProcessGpuNewContext( const QueueGpuNewContext& ev ) { assert( !m_gpuCtxMap[ev.context] ); + assert( ev.type != GpuContextType::Invalid ); int64_t gpuTime; if( ev.period == 1.f ) @@ -5181,6 +5190,7 @@ void Worker::ProcessGpuNewContext( const QueueGpuNewContext& ev ) gpu->accuracyBits = ev.accuracyBits; gpu->period = ev.period; gpu->count = 0; + gpu->type = ev.type; m_data.gpuData.push_back( gpu ); m_gpuCtxMap[ev.context] = gpu; } @@ -7081,6 +7091,7 @@ void Worker::Write( FileWrite& f ) f.Write( &ctx->accuracyBits, sizeof( ctx->accuracyBits ) ); f.Write( &ctx->count, sizeof( ctx->count ) ); f.Write( &ctx->period, sizeof( ctx->period ) ); + f.Write( &ctx->type, sizeof( ctx->type ) ); sz = ctx->threadData.size(); f.Write( &sz, sizeof( sz ) ); for( auto& td : ctx->threadData )