Compare commits

...

6 Commits

Author SHA1 Message Date
Marcos Slomp
d1373d3f4c code hardening for GLES 2.0 2026-06-19 11:03:30 -07:00
Marcos Slomp
22abcd272f cosmetic: making things a bit more idiomatic 2026-06-16 11:30:21 -07:00
Marcos Slomp
32b712c120 force inline helper method 2026-06-16 11:24:47 -07:00
Marcos Slomp
704b5c4030 refactor sentinel value 2026-06-16 11:24:27 -07:00
Marcos Slomp
dd6962b42c use queryId arg, not m_tail member 2026-06-16 11:24:12 -07:00
Marcos Slomp
16cfd25320 potentially faster timestamp query result check
Co-authored-by: Sergio Acereda <sergio.acereda@gmail.com>
2026-06-16 08:36:55 -07:00

View File

@@ -52,11 +52,26 @@ public:
#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
@@ -102,15 +117,24 @@ public:
: m_context( GetGpuCtxCounter().fetch_add( 1, std::memory_order_relaxed ) )
, m_head( 0 )
, m_tail( 0 )
, m_supportsQueryBufferObject( false )
{
ZoneScopedC( Color::Red4 );
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
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;
@@ -197,12 +221,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 );
@@ -222,6 +242,8 @@ private:
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;
@@ -233,12 +255,35 @@ private:
}
return false;
}
#endif
// pre GL3 fallback:
auto exts = (const char*)glGetString( GL_EXTENSIONS );
return exts && strstr( exts, feature ) != nullptr;
}
tracy_force_inline bool GetTimestamp( uint64_t& timestamp, unsigned int queryId )
{
if( m_supportsQueryBufferObject )
{
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;
timestamp = time;
}
else
{
GLint available;
glGetQueryObjectiv( m_query[queryId], GL_QUERY_RESULT_AVAILABLE, &available );
if( available == GL_FALSE ) return false;
uint64_t time;
glGetQueryObjectui64v( m_query[queryId], 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 +343,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