From 16cfd25320ff4bc537452c35d5e5c030e4bf550f Mon Sep 17 00:00:00 2001 From: Marcos Slomp Date: Mon, 15 Jun 2026 21:35:13 -0700 Subject: [PATCH 1/6] potentially faster timestamp query result check Co-authored-by: Sergio Acereda --- public/tracy/TracyOpenGL.hpp | 38 +++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/public/tracy/TracyOpenGL.hpp b/public/tracy/TracyOpenGL.hpp index 4b7c1991e9..f80d8b35ba 100644 --- a/public/tracy/TracyOpenGL.hpp +++ b/public/tracy/TracyOpenGL.hpp @@ -102,6 +102,7 @@ class GpuCtx : m_context( GetGpuCtxCounter().fetch_add( 1, std::memory_order_relaxed ) ) , m_head( 0 ) , m_tail( 0 ) + , m_supportsQueryBufferObject( false ) { ZoneScopedC( Color::Red4 ); @@ -113,6 +114,14 @@ class GpuCtx "OpenGL context does not support GL_ARB_timer_query." ); } + // check for GL_QUERY_RESULT_NO_WAIT support + m_supportsQueryBufferObject = CheckFeature( "GL_ARB_query_buffer_object" ); + if( !m_supportsQueryBufferObject ) + { + Profiler::LogString( MessageSourceType::Tracy, MessageSeverity::Info, 0, 0, + "OpenGL context does not support GL_ARB_query_buffer_object." ); + } + GLint bits; glGetQueryiv( GL_TIMESTAMP, GL_QUERY_COUNTER_BITS, &bits ); if( bits == 0 ) @@ -197,12 +206,8 @@ class GpuCtx while( m_tail != m_head ) { - GLint available; - glGetQueryObjectiv( m_query[m_tail], GL_QUERY_RESULT_AVAILABLE, &available ); - if( !available ) return; - uint64_t time; - glGetQueryObjectui64v( m_query[m_tail], GL_QUERY_RESULT, &time ); + if( !GetTimestamp(time, m_tail) ) return; TracyLfqPrepare( QueueType::GpuTime ); MemWrite( &item->gpuTime.gpuTime, (int64_t)time ); @@ -239,6 +244,27 @@ class GpuCtx return exts && strstr( exts, feature ) != nullptr; } + bool GetTimestamp( uint64_t& timestamp, unsigned int queryId ) + { + if( m_supportsQueryBufferObject ) + { + uint64_t time = ~0ull; + glGetQueryObjectui64v( m_query[m_tail], GL_QUERY_RESULT_NO_WAIT, &time ); + if ( time == ~0ull ) return false; + timestamp = time; + } + else + { + GLint available; + glGetQueryObjectiv( m_query[m_tail], GL_QUERY_RESULT_AVAILABLE, &available ); + if( !available ) return false; + uint64_t time; + glGetQueryObjectui64v( m_query[m_tail], GL_QUERY_RESULT, &time ); + timestamp = time; + } + return true; + } + #ifdef TRACY_OPENGL_AUTO_CALIBRATION // Monotonic host ns for the inter-calibration interval (cpuDelta), kept // separate from Profiler::GetTime() as in the D3D12/Vulkan backends. @@ -298,6 +324,8 @@ class GpuCtx #ifdef TRACY_OPENGL_AUTO_CALIBRATION int64_t m_prevCalibration; // host-ns timestamp of the last emitted calibration #endif + + bool m_supportsQueryBufferObject; }; class GpuCtxScope From dd6962b42ce584cc05aef705f44d864d875433a6 Mon Sep 17 00:00:00 2001 From: Marcos Slomp Date: Tue, 16 Jun 2026 11:24:12 -0700 Subject: [PATCH 2/6] use queryId arg, not m_tail member --- public/tracy/TracyOpenGL.hpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/public/tracy/TracyOpenGL.hpp b/public/tracy/TracyOpenGL.hpp index f80d8b35ba..ff027c4900 100644 --- a/public/tracy/TracyOpenGL.hpp +++ b/public/tracy/TracyOpenGL.hpp @@ -248,18 +248,16 @@ class GpuCtx { if( m_supportsQueryBufferObject ) { - uint64_t time = ~0ull; - glGetQueryObjectui64v( m_query[m_tail], GL_QUERY_RESULT_NO_WAIT, &time ); - if ( time == ~0ull ) return false; + glGetQueryObjectui64v( m_query[queryId], GL_QUERY_RESULT_NO_WAIT, &time ); timestamp = time; } else { GLint available; - glGetQueryObjectiv( m_query[m_tail], GL_QUERY_RESULT_AVAILABLE, &available ); + glGetQueryObjectiv( m_query[queryId], GL_QUERY_RESULT_AVAILABLE, &available ); if( !available ) return false; uint64_t time; - glGetQueryObjectui64v( m_query[m_tail], GL_QUERY_RESULT, &time ); + glGetQueryObjectui64v( m_query[queryId], GL_QUERY_RESULT, &time ); timestamp = time; } return true; From 704b5c40303eba3678209b8511f5a336dabd913b Mon Sep 17 00:00:00 2001 From: Marcos Slomp Date: Tue, 16 Jun 2026 11:24:27 -0700 Subject: [PATCH 3/6] refactor sentinel value --- public/tracy/TracyOpenGL.hpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/public/tracy/TracyOpenGL.hpp b/public/tracy/TracyOpenGL.hpp index ff027c4900..dea2ec0876 100644 --- a/public/tracy/TracyOpenGL.hpp +++ b/public/tracy/TracyOpenGL.hpp @@ -248,7 +248,10 @@ class GpuCtx { if( m_supportsQueryBufferObject ) { + constexpr uint64_t sentinel = ~0ull; + uint64_t time = sentinel; glGetQueryObjectui64v( m_query[queryId], GL_QUERY_RESULT_NO_WAIT, &time ); + if ( time == sentinel ) return false; timestamp = time; } else From 32b712c1208f3c4366a179bd0bf08c2c84b257dd Mon Sep 17 00:00:00 2001 From: Marcos Slomp Date: Tue, 16 Jun 2026 11:24:47 -0700 Subject: [PATCH 4/6] force inline helper method --- public/tracy/TracyOpenGL.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/tracy/TracyOpenGL.hpp b/public/tracy/TracyOpenGL.hpp index dea2ec0876..fc32b6640d 100644 --- a/public/tracy/TracyOpenGL.hpp +++ b/public/tracy/TracyOpenGL.hpp @@ -244,7 +244,7 @@ class GpuCtx return exts && strstr( exts, feature ) != nullptr; } - bool GetTimestamp( uint64_t& timestamp, unsigned int queryId ) + tracy_force_inline bool GetTimestamp( uint64_t& timestamp, unsigned int queryId ) { if( m_supportsQueryBufferObject ) { From 22abcd272f3d076bcdc5db4525dd84b8650dee4f Mon Sep 17 00:00:00 2001 From: Marcos Slomp Date: Tue, 16 Jun 2026 11:30:21 -0700 Subject: [PATCH 5/6] cosmetic: making things a bit more idiomatic --- public/tracy/TracyOpenGL.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/public/tracy/TracyOpenGL.hpp b/public/tracy/TracyOpenGL.hpp index fc32b6640d..189a810a37 100644 --- a/public/tracy/TracyOpenGL.hpp +++ b/public/tracy/TracyOpenGL.hpp @@ -248,7 +248,7 @@ class GpuCtx { if( m_supportsQueryBufferObject ) { - constexpr uint64_t sentinel = ~0ull; + constexpr uint64_t sentinel = ~uint64_t(0); uint64_t time = sentinel; glGetQueryObjectui64v( m_query[queryId], GL_QUERY_RESULT_NO_WAIT, &time ); if ( time == sentinel ) return false; @@ -258,7 +258,7 @@ class GpuCtx { GLint available; glGetQueryObjectiv( m_query[queryId], GL_QUERY_RESULT_AVAILABLE, &available ); - if( !available ) return false; + if( available == GL_FALSE ) return false; uint64_t time; glGetQueryObjectui64v( m_query[queryId], GL_QUERY_RESULT, &time ); timestamp = time; From d1373d3f4c1270c323aa68080480ed0f50d58449 Mon Sep 17 00:00:00 2001 From: Marcos Slomp Date: Fri, 19 Jun 2026 10:39:29 -0700 Subject: [PATCH 6/6] code hardening for GLES 2.0 --- public/tracy/TracyOpenGL.hpp | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/public/tracy/TracyOpenGL.hpp b/public/tracy/TracyOpenGL.hpp index 189a810a37..e053848850 100644 --- a/public/tracy/TracyOpenGL.hpp +++ b/public/tracy/TracyOpenGL.hpp @@ -52,11 +52,26 @@ class GpuCtxScope #if !defined GL_TIMESTAMP && defined GL_TIMESTAMP_EXT # define GL_TIMESTAMP GL_TIMESTAMP_EXT # define GL_QUERY_COUNTER_BITS GL_QUERY_COUNTER_BITS_EXT +# define GL_QUERY_RESULT GL_QUERY_RESULT_EXT +# define GL_QUERY_RESULT_AVAILABLE GL_QUERY_RESULT_AVAILABLE_EXT +# define glGenQueries glGenQueriesEXT +# define glGetQueryiv glGetQueryivEXT # define glGetQueryObjectiv glGetQueryObjectivEXT # define glGetQueryObjectui64v glGetQueryObjectui64vEXT +# define glGetInteger64v glGetInteger64vEXT # define glQueryCounter glQueryCounterEXT #endif +#ifndef GL_MAJOR_VERSION +# define GL_MAJOR_VERSION 0x821B +#endif +#ifndef GL_NUM_EXTENSIONS +# define GL_NUM_EXTENSIONS 0x821D +#endif +#ifndef GL_QUERY_RESULT_NO_WAIT +# define GL_QUERY_RESULT_NO_WAIT 0x9194 +#endif + #define TracyGpuContext tracy::GetGpuCtx().ptr = (tracy::GpuCtx*)tracy::tracy_malloc( sizeof( tracy::GpuCtx ) ); new(tracy::GetGpuCtx().ptr) tracy::GpuCtx; #define TracyGpuContextName( name, size ) tracy::GetGpuCtx().ptr->Name( name, size ); #if defined TRACY_HAS_CALLSTACK && defined TRACY_CALLSTACK @@ -108,10 +123,10 @@ class GpuCtx assert( m_context != 255 ); - if( !CheckFeature( "GL_ARB_timer_query" ) ) + if( !CheckFeature( "GL_ARB_timer_query" ) && !CheckFeature( "GL_EXT_disjoint_timer_query" ) ) { Profiler::LogString( MessageSourceType::Tracy, MessageSeverity::Warning, Color::Tomato, 0, - "OpenGL context does not support GL_ARB_timer_query." ); + "OpenGL context does not support timer queries." ); } // check for GL_QUERY_RESULT_NO_WAIT support @@ -227,6 +242,8 @@ class GpuCtx glGetIntegerv( GL_MAJOR_VERSION, &major ); if( glGetError() != GL_NO_ERROR ) major = 0; // pre-3.0: enum not supported +#if defined(GL_VERSION_3_0) || defined(GL_ES_VERSION_3_0) + // GL 3 onwards: glGetStringi if( major >= 3 ) { GLint numExt = 0; @@ -238,6 +255,7 @@ class GpuCtx } return false; } +#endif // pre GL3 fallback: auto exts = (const char*)glGetString( GL_EXTENSIONS );