Module: Mesa Branch: main Commit: 83278b5661224a425a0dc6d2ec49ce4aa617c83b URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=83278b5661224a425a0dc6d2ec49ce4aa617c83b
Author: Marek Olšák <[email protected]> Date: Sun Oct 31 01:02:02 2021 -0400 glx: add a workaround to glXDestroyWindow for Viewperf2020/Sw This fixes: X Error of failed request: GLXBadWindow Major opcode of failed request: 152 (GLX) Minor opcode of failed request: 32 (X_GLXDestroyWindow) Serial number of failed request: 9667 Current serial number in output stream: 9674 Acked-by: Pierre-Eric Pelloux-Prayer <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13611> --- src/gallium/auxiliary/pipe-loader/driinfo_gallium.h | 1 + src/glx/dri2_glx.c | 7 +++++++ src/glx/dri3_glx.c | 7 +++++++ src/glx/glx_pbuffer.c | 19 +++++++++++++++++++ src/glx/glxclient.h | 1 + src/glx/tests/fake_glx_screen.h | 1 + src/util/00-mesa-defaults.conf | 1 + src/util/driconf.h | 4 ++++ 8 files changed, 41 insertions(+) diff --git a/src/gallium/auxiliary/pipe-loader/driinfo_gallium.h b/src/gallium/auxiliary/pipe-loader/driinfo_gallium.h index 90dd6c714b6..29ad8e700aa 100644 --- a/src/gallium/auxiliary/pipe-loader/driinfo_gallium.h +++ b/src/gallium/auxiliary/pipe-loader/driinfo_gallium.h @@ -46,6 +46,7 @@ DRI_CONF_SECTION_DEBUG DRI_CONF_DISABLE_PROTECTED_CONTENT_CHECK(false) DRI_CONF_IGNORE_MAP_UNSYNCHRONIZED(false) DRI_CONF_FORCE_DIRECT_GLX_CONTEXT(false) + DRI_CONF_ALLOW_INVALID_GLX_DESTROY_WINDOW(false) DRI_CONF_SECTION_END DRI_CONF_SECTION_MISCELLANEOUS diff --git a/src/glx/dri2_glx.c b/src/glx/dri2_glx.c index 4092842cccd..e3eb25262e2 100644 --- a/src/glx/dri2_glx.c +++ b/src/glx/dri2_glx.c @@ -1286,6 +1286,13 @@ dri2CreateScreen(int screen, struct glx_display * priv) &force) == 0) { psc->base.force_direct_context = force; } + + uint8_t invalid_glx_destroy_window = false; + if (psc->config->configQueryb(psc->driScreen, + "allow_invalid_glx_destroy_window", + &invalid_glx_destroy_window) == 0) { + psc->base.allow_invalid_glx_destroy_window = invalid_glx_destroy_window; + } } /* DRI2 supports SubBuffer through DRI2CopyRegion, so it's always diff --git a/src/glx/dri3_glx.c b/src/glx/dri3_glx.c index 3c0d60bdf21..9d52c3b83c8 100644 --- a/src/glx/dri3_glx.c +++ b/src/glx/dri3_glx.c @@ -1020,6 +1020,13 @@ dri3_create_screen(int screen, struct glx_display * priv) &force) == 0) { psc->base.force_direct_context = force; } + + uint8_t invalid_glx_destroy_window = false; + if (psc->config->configQueryb(psc->driScreen, + "allow_invalid_glx_destroy_window", + &invalid_glx_destroy_window) == 0) { + psc->base.allow_invalid_glx_destroy_window = invalid_glx_destroy_window; + } } free(driverName); diff --git a/src/glx/glx_pbuffer.c b/src/glx/glx_pbuffer.c index c145ee92405..ff699bd1a0f 100644 --- a/src/glx/glx_pbuffer.c +++ b/src/glx/glx_pbuffer.c @@ -394,6 +394,12 @@ __glXGetDrawableAttribute(Display * dpy, GLXDrawable drawable, return found; } +static int dummyErrorHandler(Display *display, xError *err, XExtCodes *codes, + int *ret_code) +{ + return 1; /* do nothing */ +} + static void protocolDestroyDrawable(Display *dpy, GLXDrawable drawable, CARD32 glxCode) { @@ -413,6 +419,19 @@ protocolDestroyDrawable(Display *dpy, GLXDrawable drawable, CARD32 glxCode) UnlockDisplay(dpy); SyncHandle(); + + /* Viewperf2020/Sw calls XDestroyWindow(win) and then glXDestroyWindow(win), + * causing an X error and abort. This is the workaround. + */ + struct glx_display *priv = __glXInitialize(dpy); + + if (priv->screens[0] && + priv->screens[0]->allow_invalid_glx_destroy_window) { + void *old = XESetError(priv->dpy, priv->codes.extension, + dummyErrorHandler); + XSync(dpy, false); + XESetError(priv->dpy, priv->codes.extension, old); + } } /** diff --git a/src/glx/glxclient.h b/src/glx/glxclient.h index 880f4fbaefa..0bd486b8631 100644 --- a/src/glx/glxclient.h +++ b/src/glx/glxclient.h @@ -522,6 +522,7 @@ struct glx_screen Display *dpy; int scr; bool force_direct_context; + bool allow_invalid_glx_destroy_window; #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) /** diff --git a/src/glx/tests/fake_glx_screen.h b/src/glx/tests/fake_glx_screen.h index 02b212ad7ec..8e5c9cfefc6 100644 --- a/src/glx/tests/fake_glx_screen.h +++ b/src/glx/tests/fake_glx_screen.h @@ -35,6 +35,7 @@ public: this->visuals = 0; this->configs = 0; this->force_direct_context = false; + this->allow_invalid_glx_destroy_window = false; this->display = glx_dpy; this->dpy = (glx_dpy != NULL) ? glx_dpy->dpy : NULL; diff --git a/src/util/00-mesa-defaults.conf b/src/util/00-mesa-defaults.conf index 15b1ee564db..d6629f899f4 100644 --- a/src/util/00-mesa-defaults.conf +++ b/src/util/00-mesa-defaults.conf @@ -313,6 +313,7 @@ TODO: document the other workarounds. <option name="mesa_no_error" value="true" /> <!-- Creating 10-bit pbuffers fails in the X server and returns BadAlloc. --> <option name="allow_rgb10_configs" value="false" /> + <option name="allow_invalid_glx_destroy_window" value="true" /> </application> <!-- Workaround for unsynchronized VBO updates on Dead Cells android diff --git a/src/util/driconf.h b/src/util/driconf.h index 5f37f657ead..45431eb5f5b 100644 --- a/src/util/driconf.h +++ b/src/util/driconf.h @@ -238,6 +238,10 @@ DRI_CONF_OPT_B(force_direct_glx_context, def, \ "Force direct GLX context (even if indirect is requested)") +#define DRI_CONF_ALLOW_INVALID_GLX_DESTROY_WINDOW(def) \ + DRI_CONF_OPT_B(allow_invalid_glx_destroy_window, def, \ + "Allow passing an invalid window into glXDestroyWindow") + #define DRI_CONF_OVERRIDE_VRAM_SIZE() \ DRI_CONF_OPT_I(override_vram_size, -1, -1, 2147483647, \ "Override the VRAM size advertised to the application in MiB (-1 = default)")
