From d5fb1cfe4b48c3e75b43b540e6bbf24f00a86df6 Mon Sep 17 00:00:00 2001 From: baldurk Date: Mon, 25 Jan 2021 11:20:21 +0000 Subject: [PATCH] Work around driver issues creating shared contexts on EGL. Closes #2162 * Some drivers seem to fail when trying to share between GLES2 and GLES3 though the spec seems to suggest this should work fine. As a workaround if the context fails to create, try creating with the same context client version as the existing context. --- renderdoc/driver/gl/egl_dispatch_table.h | 5 ++++- renderdoc/driver/gl/egl_platform.cpp | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/renderdoc/driver/gl/egl_dispatch_table.h b/renderdoc/driver/gl/egl_dispatch_table.h index 0132e7437..c516eee6f 100644 --- a/renderdoc/driver/gl/egl_dispatch_table.h +++ b/renderdoc/driver/gl/egl_dispatch_table.h @@ -62,6 +62,8 @@ typedef EGLint(EGLAPIENTRY *PFN_eglGetError)(void); typedef EGLBoolean(EGLAPIENTRY *PFN_eglGetConfigAttrib)(EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint *value); typedef const char *(EGLAPIENTRY *PFN_eglQueryString)(EGLDisplay dpy, EGLint name); +typedef EGLBoolean(EGLAPIENTRY *PFN_eglQueryContext)(EGLDisplay dpy, EGLContext ctx, + EGLint attribute, EGLint *value); typedef PFNEGLPOSTSUBBUFFERNVPROC PFN_eglPostSubBufferNV; typedef PFNEGLSWAPBUFFERSWITHDAMAGEEXTPROC PFN_eglSwapBuffersWithDamageEXT; typedef PFNEGLSWAPBUFFERSWITHDAMAGEKHRPROC PFN_eglSwapBuffersWithDamageKHR; @@ -93,7 +95,8 @@ typedef PFNEGLSWAPBUFFERSWITHDAMAGEKHRPROC PFN_eglSwapBuffersWithDamageKHR; FUNC(Initialize, false, true); \ FUNC(QueryAPI, false, true); \ FUNC(QueryString, false, true); \ - FUNC(QuerySurface, false, true); + FUNC(QuerySurface, false, true); \ + FUNC(QueryContext, false, true); struct EGLDispatchTable { diff --git a/renderdoc/driver/gl/egl_platform.cpp b/renderdoc/driver/gl/egl_platform.cpp index 2a297e322..0f4e5cdf3 100644 --- a/renderdoc/driver/gl/egl_platform.cpp +++ b/renderdoc/driver/gl/egl_platform.cpp @@ -79,6 +79,20 @@ class EGLPlatform : public GLPlatform EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR, EGL_NONE}; ret.egl_ctx = EGL.CreateContext(share.egl_dpy, share.egl_cfg, share.egl_ctx, baseAttribs); + + if(ret.egl_ctx == EGL_NO_CONTEXT) + { + EGL.QueryContext(share.egl_dpy, share.egl_ctx, eEGL_CONTEXT_CLIENT_VERSION, &baseAttribs[1]); + + RDCWARN( + "Creating cloned context failed. Trying again with queried old EGL client version: %d", + baseAttribs[1]); + + ret.egl_ctx = EGL.CreateContext(share.egl_dpy, share.egl_cfg, share.egl_ctx, baseAttribs); + + if(ret.egl_ctx == EGL_NO_CONTEXT) + RDCERR("Cloned context failed again. Capture will likely fail"); + } } return ret;