potentially faster timestamp query result check

Co-authored-by: Sergio Acereda <sergio.acereda@gmail.com>
This commit is contained in:
Marcos Slomp
2026-06-15 21:35:13 -07:00
parent 1de94aa856
commit 16cfd25320

View File

@@ -102,6 +102,7 @@ public:
: 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 @@ public:
"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 @@ public:
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 @@ private:
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 @@ private:
#ifdef TRACY_OPENGL_AUTO_CALIBRATION
int64_t m_prevCalibration; // host-ns timestamp of the last emitted calibration
#endif
bool m_supportsQueryBufferObject;
};
class GpuCtxScope