Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion public/tracy/TracyOpenGL.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,18 @@ class GpuCtx

while( m_tail != m_head )
{
#ifdef GL_QUERY_RESULT_NO_WAIT
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose this solution would work for the most part.
The problem is that it's quite possible to use a GL header/loader that defines this macro, but be operating in a GL context that does not recognize the underlying value of it.

I think the ideal solution would be to query the GL context for support when the context is created, store that in a boolean, and then test the boolean value here instead of testing the macro.

I asked Gemini and it recommended something like this:

bool SupportsQueryResultNoWait() {
    // 1. Check if the core version is 4.4 or higher
    GLint major, minor;
    glGetIntegerv(GL_MAJOR_VERSION, &major);
    glGetIntegerv(GL_MINOR_VERSION, &minor);
    
    if (major > 4 || (major == 4 && minor >= 4)) {
        return true;
    }

    // 2. Fallback: Check if the extension is supported on an older context (e.g., OpenGL 4.3)
    GLint numExtensions = 0;
    glGetIntegerv(GL_NUM_EXTENSIONS, &numExtensions);

    for (GLint i = 0; i < numExtensions; ++i) {
        const char* ext = (const char*)glGetStringi(GL_EXTENSIONS, i);
        if (ext && std::string(ext) == "GL_ARB_query_buffer_object") {
            return true;
        }
    }

    return false;
}

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the minspec required for this kind of extensions check?

Copy link
Copy Markdown
Collaborator

@slomp slomp Jun 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the docs, glGetStringi et al. was introduced to core in OpenGL 3.0:
https://registry.khronos.org/OpenGL-Refpages/gl4/html/glGetString.xhtml
There's also the old way of doing things (glGetString, OpenGL 2) where you get a gigantic string with all extensions on it and split/parse it manually.

uint64_t time = ~0ull;
glGetQueryObjectui64v( m_query[m_tail], GL_QUERY_RESULT_NO_WAIT, &time );
if (time == ~0ull) return;
#else
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 );

#endif
TracyLfqPrepare( QueueType::GpuTime );
MemWrite( &item->gpuTime.gpuTime, (int64_t)time );
MemWrite( &item->gpuTime.queryId, (uint16_t)m_tail );
Expand Down
Loading