Skip to content

Use GL_QUERY_RESULT_NO_WAIT#1380

Open
sacereda wants to merge 2 commits into
wolfpld:masterfrom
sacereda:perf/opengl-no-wait
Open

Use GL_QUERY_RESULT_NO_WAIT#1380
sacereda wants to merge 2 commits into
wolfpld:masterfrom
sacereda:perf/opengl-no-wait

Conversation

@sacereda
Copy link
Copy Markdown
Contributor

@sacereda sacereda commented Jun 2, 2026

This should be a little bit faster than the current implementation with GL_QUERY_RESULT_AVAILABLE and GL_QUERY_RESULT.

This should be a little bit faster than the current implementation with GL_QUERY_RESULT_AVAILABLE and GL_QUERY_RESULT.
@sacereda sacereda force-pushed the perf/opengl-no-wait branch from bb3a194 to eca16be Compare June 2, 2026 11:28
@slomp
Copy link
Copy Markdown
Collaborator

slomp commented Jun 2, 2026

We may need to check whether OpenGL 4.4 is available in the context:

https://registry.khronos.org/OpenGL-Refpages/gl4/html/glGetQueryObject.xhtml

GL_QUERY_RESULT_NO_WAIT is accepted for pname only if the GL version is 4.4 or greater.

@sacereda sacereda changed the title use GL_QUERY_RESULT_NO_WAIT for non-blocking GPU queries Use GL_QUERY_RESULT_NO_WAIT Jun 3, 2026
Copy link
Copy Markdown
Collaborator

@slomp slomp left a comment

Choose a reason for hiding this comment

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

I haven't used much OpenGL over the past years, so maybe it's just the "shell shock" of having to deal with OpenGL extensions in the past that is making me pedantic and overzealous here.


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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants