diff --git a/meson.build b/meson.build index 5e2b32554aa..173c4f007d9 100644 --- a/meson.build +++ b/meson.build @@ -2058,7 +2058,7 @@ dep_glproto_version = '>= 1.4.14' dep_xcb_dri3_version = '>= 1.13' dep_xcb_glx_version = '>= 1.8.1' dep_xcb_present_version = '>= 1.13' -dep_xlib_version = '>= 1.8' +dep_xlib_version = '>= 1.6' # RHEL8 has 1.6, RHEL9 has 1.7, U22.04 has 1.7 dep_xlib_xrandr_version = '>= 1.3' dep_xshmfence_version = '>= 1.1' diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c index 81ed4a47375..eaff81c21dc 100644 --- a/src/egl/drivers/dri2/egl_dri2.c +++ b/src/egl/drivers/dri2/egl_dri2.c @@ -59,6 +59,7 @@ #ifdef HAVE_X11_PLATFORM #include "X11/Xlibint.h" #include "x11_dri3.h" +#include "x11_display.h" #endif #include "GL/mesa_glinterop.h" @@ -1235,9 +1236,16 @@ dri2_create_context(_EGLDisplay *disp, _EGLConfig *conf, &num_attribs)) goto cleanup; + bool thread_safe = true; + +#ifdef HAVE_X11_PLATFORM + if (disp->Platform == _EGL_PLATFORM_X11) + thread_safe = x11_xlib_display_is_thread_safe(disp->PlatformDisplay); +#endif + dri2_ctx->dri_context = driCreateContextAttribs( dri2_dpy->dri_screen_render_gpu, api, dri_config, shared, num_attribs / 2, - ctx_attribs, &error, dri2_ctx); + ctx_attribs, &error, dri2_ctx, thread_safe); dri2_create_context_attribs_error(error); if (!dri2_ctx->dri_context) diff --git a/src/egl/drivers/dri2/platform_x11.c b/src/egl/drivers/dri2/platform_x11.c index 296056dbd31..3854e573f29 100644 --- a/src/egl/drivers/dri2/platform_x11.c +++ b/src/egl/drivers/dri2/platform_x11.c @@ -52,7 +52,6 @@ #include #include #include "x11_dri3.h" -#include "x11_display.h" #include "kopper_interface.h" #include "loader.h" #include "platform_x11.h" @@ -1069,8 +1068,6 @@ dri2_get_xcb_connection(_EGLDisplay *disp, struct dri2_egl_display *dri2_dpy) screen = dri2_find_screen_for_display(disp, screen); } else if (disp->Platform == _EGL_PLATFORM_X11) { Display *dpy = disp->PlatformDisplay; - if (!x11_xlib_display_is_thread_safe(dpy)) - return EGL_FALSE; dri2_dpy->conn = XGetXCBConnection(dpy); screen = DefaultScreen(dpy); } else { diff --git a/src/gallium/frontends/dri/dri_context.c b/src/gallium/frontends/dri/dri_context.c index 27496e445da..467a48a1cef 100644 --- a/src/gallium/frontends/dri/dri_context.c +++ b/src/gallium/frontends/dri/dri_context.c @@ -48,7 +48,8 @@ dri_create_context(struct dri_screen *screen, const struct __DriverContextConfig *ctx_config, unsigned *error, struct dri_context *sharedContextPrivate, - void *loaderPrivate) + void *loaderPrivate, + bool thread_safe) { struct dri_context *ctx = NULL; struct st_context *st_share = NULL; @@ -228,6 +229,10 @@ dri_create_context(struct dri_screen *screen, } enable_glthread = user_enable_glthread; } + + if (!thread_safe) + enable_glthread = false; + /* Do this last. */ if (enable_glthread) _mesa_glthread_init(ctx->st->ctx); diff --git a/src/gallium/frontends/dri/dri_context.h b/src/gallium/frontends/dri/dri_context.h index f36f796e469..7bd8b847db9 100644 --- a/src/gallium/frontends/dri/dri_context.h +++ b/src/gallium/frontends/dri/dri_context.h @@ -101,7 +101,8 @@ dri_create_context(struct dri_screen *screen, const struct __DriverContextConfig *ctx_config, unsigned *error, struct dri_context *sharedContextPrivate, - void *loaderPrivate); + void *loaderPrivate, + bool thread_safe); #endif diff --git a/src/gallium/frontends/dri/dri_util.c b/src/gallium/frontends/dri/dri_util.c index 24048d57d12..bd10995602b 100644 --- a/src/gallium/frontends/dri/dri_util.c +++ b/src/gallium/frontends/dri/dri_util.c @@ -421,7 +421,8 @@ driCreateContextAttribs(struct dri_screen *screen, int api, unsigned num_attribs, const uint32_t *attribs, unsigned *error, - void *data) + void *data, + bool thread_safe) { const struct gl_config *modes = (config != NULL) ? &config->modes : NULL; gl_api mesa_api; @@ -594,27 +595,27 @@ driCreateContextAttribs(struct dri_screen *screen, int api, struct dri_context *ctx = dri_create_context(screen, mesa_api, modes, &ctx_config, error, - shared, data); + shared, data, thread_safe); return ctx; } static struct dri_context * driCreateNewContextForAPI(struct dri_screen *screen, int api, const struct dri_config *config, - struct dri_context *shared, void *data) + struct dri_context *shared, void *data, bool thread_safe) { unsigned error; return driCreateContextAttribs(screen, api, config, shared, 0, NULL, - &error, data); + &error, data, thread_safe); } struct dri_context * driCreateNewContext(struct dri_screen *screen, const struct dri_config *config, - struct dri_context *shared, void *data) + struct dri_context *shared, void *data, bool thread_safe) { return driCreateNewContextForAPI(screen, __DRI_API_OPENGL, - config, shared, data); + config, shared, data, thread_safe); } /** diff --git a/src/gallium/frontends/dri/dri_util.h b/src/gallium/frontends/dri/dri_util.h index c61178c0479..96713679a23 100644 --- a/src/gallium/frontends/dri/dri_util.h +++ b/src/gallium/frontends/dri/dri_util.h @@ -119,7 +119,8 @@ driCreateContextAttribs(struct dri_screen *psp, int api, unsigned num_attribs, const uint32_t *attribs, unsigned *error, - void *data); + void *data, + bool thread_safe); extern uint32_t driImageFormatToSizedInternalGLFormat(uint32_t image_format); @@ -140,7 +141,8 @@ driSwapBuffers(struct dri_drawable *drawable); PUBLIC void driSwapBuffersWithDamage(struct dri_drawable *drawable, int nrects, const int *rects); PUBLIC struct dri_context * -driCreateNewContext(struct dri_screen *screen, const struct dri_config *config, struct dri_context *shared, void *data); +driCreateNewContext(struct dri_screen *screen, const struct dri_config *config, + struct dri_context *shared, void *data, bool thread_safe); PUBLIC int driCopyContext(struct dri_context *dest, struct dri_context *src, unsigned long mask); PUBLIC void diff --git a/src/gallium/frontends/dri/loader_dri3_helper.c b/src/gallium/frontends/dri/loader_dri3_helper.c index c5f80000862..2c8caba08fd 100644 --- a/src/gallium/frontends/dri/loader_dri3_helper.c +++ b/src/gallium/frontends/dri/loader_dri3_helper.c @@ -184,7 +184,7 @@ loader_dri3_blit_context_get(struct loader_dri3_drawable *draw) if (!blit_context.ctx) { blit_context.ctx = driCreateNewContext(draw->dri_screen_render_gpu, - NULL, NULL, NULL); + NULL, NULL, NULL, true); blit_context.cur_screen = draw->dri_screen_render_gpu; } diff --git a/src/gbm/backends/dri/gbm_dri.c b/src/gbm/backends/dri/gbm_dri.c index 8b455bbfad1..6640f16da77 100644 --- a/src/gbm/backends/dri/gbm_dri.c +++ b/src/gbm/backends/dri/gbm_dri.c @@ -1060,7 +1060,7 @@ gbm_dri_bo_map(struct gbm_bo *_bo, dri->context = driCreateContextAttribs(dri->screen, __DRI_API_OPENGL, NULL, NULL, 0, NULL, - &error, NULL); + &error, NULL, true); } assert(dri->context); mtx_unlock(&dri->mutex); diff --git a/src/glx/dri_common.c b/src/glx/dri_common.c index 10542949cbe..02aa1371af1 100644 --- a/src/glx/dri_common.c +++ b/src/glx/dri_common.c @@ -45,6 +45,7 @@ #include #include "dri_util.h" #include "pipe-loader/pipe_loader.h" +#include "x11/x11_display.h" #define __ATTRIB(attrib, field) \ { attrib, offsetof(struct glx_config, field) } @@ -887,7 +888,8 @@ dri_create_context_attribs(struct glx_screen *base, num_ctx_attribs / 2, ctx_attribs, error, - pcp); + pcp, + x11_xlib_display_is_thread_safe(base->dpy)); *error = dri_context_error_to_glx_error(*error); diff --git a/src/glx/glxext.c b/src/glx/glxext.c index 25117407ea4..5c3dd807370 100644 --- a/src/glx/glxext.c +++ b/src/glx/glxext.c @@ -34,7 +34,6 @@ #endif #include "x11_dri3.h" -#include "x11_display.h" #ifdef HAVE_LIBDRM #include "loader_dri3_helper.h" #endif @@ -942,9 +941,6 @@ __glXInitialize(Display * dpy) struct glx_display *dpyPriv, *d; int i, majorVersion = 0; - if (!x11_xlib_display_is_thread_safe(dpy)) - return NULL; - _XLockMutex(_Xglobal_lock); for (dpyPriv = glx_displays; dpyPriv; dpyPriv = dpyPriv->next) {