eglGetCurrentContext returns destroyed context
Created by: Josua-SR
While prototyping a vendor implementation for the Vivante EGL binaries I noticed a difference in behaviour to both Mesa(Intel gpu) and the NVIDIA binaries:
eglCreateContext eglDestroyContext eglCreateContext
^^ The second call to eglCreateContext may return an identical address to the first call. This confuses glvnd in such a way that the following chain fails to dispatch the second call of eglMakeCurrent to the vendor library:
eglCreateContext eglMakeCurrent eglDestroyContext eglCreateContext eglMakeCurrent <-- this one actually never happens
This in turn makes OpenGL-ES (we only work on gles at this time) calls stop working.
So why this title to the issue? While writing a testcase I noticed that glvnd does not dispatch calls to eglGetCurrentContext to the vendor library. Instead it returns the last known context, even if it has already been destroyed by eglDestroyContext.
So another sample:
ctx = eglCreateContext() eglMakeCurrent(ctx) eglDestroyContext(ctx) eglGetCurrentContext()
The Vivante libEGL returns EGL_NO_CONTEXT here as one would expect, but glvnd returns the now invalid handle on the previous context. I believe this is the heart of the problem.
As a work-around I have patched the test application glmark2 to call
eglMakeCurrent(display, EGL_NO_SURFACE, EFL_NO_SURFACE, EGL_NO_CONTEXT)
right after eglDestroyContext.
And this tiny change makes all the difference between glGetString returning 0, and glmark2 running through all the way.
I believe this should be fixed by catching calls to eglDestroyContext to update the currentContext state in glvnd.