Skip to content

Commit

Permalink
better fix for calls to eglMakeCurrent
Browse files Browse the repository at this point in the history
turns out that KHR_surfaceless_context is implied for ES3.0 when 
KHR_create_context is present. However, Adreno 306 fails even if
it advertises it. So, we now reset the value of KHR_surfaceless_context
based on actually calling eglMakeCurrent(EGL_NO_SURFACE).
  • Loading branch information
pixelflinger committed Aug 17, 2023
1 parent c0389ac commit 69f78db
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions filament/backend/src/opengl/platforms/PlatformEGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,14 @@ Driver* PlatformEGL::createDriver(void* sharedContext, const Platform::DriverCon

auto extensions = GLUtils::split(eglQueryString(mEGLDisplay, EGL_EXTENSIONS));
ext.egl.ANDROID_recordable = extensions.has("EGL_ANDROID_recordable");
ext.egl.KHR_create_context = extensions.has("EGL_KHR_create_context");
ext.egl.KHR_gl_colorspace = extensions.has("EGL_KHR_gl_colorspace");
ext.egl.KHR_create_context = extensions.has("EGL_KHR_create_context");
ext.egl.KHR_no_config_context = extensions.has("EGL_KHR_no_config_context");
ext.egl.KHR_surfaceless_context = extensions.has("KHR_surfaceless_context");
if (ext.egl.KHR_create_context) {
// KHR_create_context implies KHR_surfaceless_context for ES3.x contexts
ext.egl.KHR_surfaceless_context = true;
}

eglCreateSyncKHR = (PFNEGLCREATESYNCKHRPROC) eglGetProcAddress("eglCreateSyncKHR");
eglDestroySyncKHR = (PFNEGLDESTROYSYNCKHRPROC) eglGetProcAddress("eglDestroySyncKHR");
Expand Down Expand Up @@ -182,15 +186,6 @@ Driver* PlatformEGL::createDriver(void* sharedContext, const Platform::DriverCon
eglConfig = mEGLConfig;
}

if (UTILS_UNLIKELY(!ext.egl.KHR_surfaceless_context)) {
// create the dummy surface, just for being able to make the context current.
mEGLDummySurface = eglCreatePbufferSurface(mEGLDisplay, mEGLConfig, pbufferAttribs);
if (UTILS_UNLIKELY(mEGLDummySurface == EGL_NO_SURFACE)) {
logEglError("eglCreatePbufferSurface");
goto error;
}
}

for (size_t tries = 0; tries < 3; tries++) {
mEGLContext = eglCreateContext(mEGLDisplay, eglConfig,
(EGLContext)sharedContext, contextAttribs.data());
Expand Down Expand Up @@ -223,6 +218,26 @@ Driver* PlatformEGL::createDriver(void* sharedContext, const Platform::DriverCon
goto error;
}

if (ext.egl.KHR_surfaceless_context) {
// Adreno 306 driver advertises KHR_create_context but doesn't support passing
// EGL_NO_SURFACE to eglMakeCurrent with a 3.0 context.
if (UTILS_UNLIKELY(!eglMakeCurrent(mEGLDisplay,
EGL_NO_SURFACE, EGL_NO_SURFACE, mEGLContext))) {
if (eglGetError() == EGL_BAD_MATCH) {
ext.egl.KHR_surfaceless_context = false;
}
}
}

if (UTILS_UNLIKELY(!ext.egl.KHR_surfaceless_context)) {
// create the dummy surface, just for being able to make the context current.
mEGLDummySurface = eglCreatePbufferSurface(mEGLDisplay, mEGLConfig, pbufferAttribs);
if (UTILS_UNLIKELY(mEGLDummySurface == EGL_NO_SURFACE)) {
logEglError("eglCreatePbufferSurface");
goto error;
}
}

if (UTILS_UNLIKELY(!makeCurrent(mEGLDummySurface, mEGLDummySurface))) {
// eglMakeCurrent failed
logEglError("eglMakeCurrent");
Expand Down

0 comments on commit 69f78db

Please sign in to comment.