From 56ed5cf1bba0304d258a56d0f9c2e767705cec01 Mon Sep 17 00:00:00 2001 From: Faith Ekstrand Date: Mon, 14 Jul 2025 16:43:42 -0400 Subject: [PATCH] dri: Get rid of __DRIbackgroundCallableExtension MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This was originally needed to bind the context to the background thread for DRI2 because it needs to be able to get buffers from the X server. With DRI3 and Wayland, however, it's not needed. All the DRI3 code gets everything it needs from the drawable and only uses the context for flushes and blits, which always come from GLX itself, not the render thread. Now that we've deleted all the DRI2 code, let's delete this, too. Acked-by: Mike Blumenkrantz Reviewed-by: Adam Jackson Reviewed-by: Marek Olšák Reviewed-by: Eric Engestrom Part-of: --- src/egl/drivers/dri2/egl_dri2.c | 29 ------------ src/egl/drivers/dri2/egl_dri2.h | 1 - src/egl/drivers/dri2/platform_surfaceless.c | 1 - src/egl/drivers/dri2/platform_x11.c | 1 - src/gallium/frontends/dri/dri_context.c | 17 +------ src/gallium/frontends/dri/dri_screen.c | 5 --- src/gallium/frontends/dri/dri_screen.h | 1 - src/gallium/frontends/dri/dri_util.c | 1 - src/gallium/include/mesa_interface.h | 50 --------------------- src/glx/dri3_glx.c | 23 ---------- src/glx/dri_common.c | 19 -------- src/glx/dri_common.h | 2 - src/glx/drisw_glx.c | 1 - 13 files changed, 2 insertions(+), 149 deletions(-) diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c index 9ceac33fb63..32944890495 100644 --- a/src/egl/drivers/dri2/egl_dri2.c +++ b/src/egl/drivers/dri2/egl_dri2.c @@ -91,41 +91,12 @@ static const enum pipe_format dri2_pbuffer_visuals[] = { PIPE_FORMAT_B5G6R5_UNORM, }; -static void -dri_set_background_context(void *loaderPrivate) -{ - _EGLContext *ctx = _eglGetCurrentContext(); - _EGLThreadInfo *t = _eglGetCurrentThread(); - - _eglBindContextToThread(ctx, t); -} - static void dri2_gl_flush() { CALL_Flush(GET_DISPATCH(), ()); } -static GLboolean -dri_is_thread_safe(UNUSED void *loaderPrivate) -{ - /* loader_dri3_blit_context_get creates a context with - * loaderPrivate being NULL. Enabling glthread for a blitting - * context isn't useful so return false. - */ - if (!loaderPrivate) - return false; - - return true; -} - -const __DRIbackgroundCallableExtension background_callable_extension = { - .base = {__DRI_BACKGROUND_CALLABLE, 2}, - - .setBackgroundContext = dri_set_background_context, - .isThreadSafe = dri_is_thread_safe, -}; - static void dri2_get_pbuffer_drawable_info(struct dri_drawable *draw, int *x, int *y, int *w, int *h, void *loaderPrivate) diff --git a/src/egl/drivers/dri2/egl_dri2.h b/src/egl/drivers/dri2/egl_dri2.h index 2436ffb872b..15da921421a 100644 --- a/src/egl/drivers/dri2/egl_dri2.h +++ b/src/egl/drivers/dri2/egl_dri2.h @@ -436,7 +436,6 @@ dri2_egl_error_unlock(struct dri2_egl_display *dri2_dpy, EGLint err, } extern const __DRIimageLookupExtension image_lookup_extension; -extern const __DRIbackgroundCallableExtension background_callable_extension; extern const __DRIswrastLoaderExtension swrast_pbuffer_loader_extension; extern const __DRIkopperLoaderExtension kopper_pbuffer_loader_extension; diff --git a/src/egl/drivers/dri2/platform_surfaceless.c b/src/egl/drivers/dri2/platform_surfaceless.c index 87b6888ee24..03560836614 100644 --- a/src/egl/drivers/dri2/platform_surfaceless.c +++ b/src/egl/drivers/dri2/platform_surfaceless.c @@ -208,7 +208,6 @@ static const __DRIimageLoaderExtension image_loader_extension = { static const __DRIextension *image_loader_extensions[] = { &image_loader_extension.base, &image_lookup_extension.base, - &background_callable_extension.base, NULL, }; static const __DRIextension *swrast_loader_extensions[] = { diff --git a/src/egl/drivers/dri2/platform_x11.c b/src/egl/drivers/dri2/platform_x11.c index 738e3062c0c..6d2d442a74b 100644 --- a/src/egl/drivers/dri2/platform_x11.c +++ b/src/egl/drivers/dri2/platform_x11.c @@ -1240,7 +1240,6 @@ dri2_initialize_x11_swrast(_EGLDisplay *disp) static const __DRIextension *dri3_image_loader_extensions[] = { &dri3_image_loader_extension.base, &image_lookup_extension.base, - &background_callable_extension.base, NULL, }; diff --git a/src/gallium/frontends/dri/dri_context.c b/src/gallium/frontends/dri/dri_context.c index fe32d5c518f..27496e445da 100644 --- a/src/gallium/frontends/dri/dri_context.c +++ b/src/gallium/frontends/dri/dri_context.c @@ -60,8 +60,6 @@ dri_create_context(struct dri_screen *screen, __DRIVER_CONTEXT_ATTRIB_PRIORITY | __DRIVER_CONTEXT_ATTRIB_RELEASE_BEHAVIOR | __DRIVER_CONTEXT_ATTRIB_NO_ERROR; - const __DRIbackgroundCallableExtension *backgroundCallable = - screen->dri2.backgroundCallable; const struct driOptionCache *optionCache = &screen->dev->option_cache; /* This is effectively doing error checking for GLX context creation (by both @@ -231,19 +229,8 @@ dri_create_context(struct dri_screen *screen, enable_glthread = user_enable_glthread; } /* Do this last. */ - if (enable_glthread) { - bool safe = true; - - /* This is only needed by X11/DRI2, which can be unsafe. */ - if (backgroundCallable && - backgroundCallable->base.version >= 2 && - backgroundCallable->isThreadSafe && - !backgroundCallable->isThreadSafe(loaderPrivate)) - safe = false; - - if (safe) - _mesa_glthread_init(ctx->st->ctx); - } + if (enable_glthread) + _mesa_glthread_init(ctx->st->ctx); *error = __DRI_CTX_ERROR_SUCCESS; return ctx; diff --git a/src/gallium/frontends/dri/dri_screen.c b/src/gallium/frontends/dri/dri_screen.c index b11e3dca7e4..fed8c6b5ac1 100644 --- a/src/gallium/frontends/dri/dri_screen.c +++ b/src/gallium/frontends/dri/dri_screen.c @@ -601,11 +601,6 @@ dri_set_background_context(struct st_context *st, struct util_queue_monitoring *queue_info) { struct dri_context *ctx = (struct dri_context *)st->frontend_context; - const __DRIbackgroundCallableExtension *backgroundCallable = - ctx->screen->dri2.backgroundCallable; - - if (backgroundCallable) - backgroundCallable->setBackgroundContext(ctx->loaderPrivate); if (ctx->hud) hud_add_queue_for_monitoring(ctx->hud, queue_info); diff --git a/src/gallium/frontends/dri/dri_screen.h b/src/gallium/frontends/dri/dri_screen.h index 89fbe8f7f52..acdd624cd21 100644 --- a/src/gallium/frontends/dri/dri_screen.h +++ b/src/gallium/frontends/dri/dri_screen.h @@ -70,7 +70,6 @@ struct dri_screen struct { const __DRIimageLookupExtension *image; - const __DRIbackgroundCallableExtension *backgroundCallable; } dri2; struct { diff --git a/src/gallium/frontends/dri/dri_util.c b/src/gallium/frontends/dri/dri_util.c index a9c4f9fde9f..21f17ef9065 100644 --- a/src/gallium/frontends/dri/dri_util.c +++ b/src/gallium/frontends/dri/dri_util.c @@ -80,7 +80,6 @@ setupLoaderExtensions(struct dri_screen *screen, { static const struct dri_extension_match matches[] = { {__DRI_IMAGE_LOOKUP, 1, offsetof(struct dri_screen, dri2.image), true}, - {__DRI_BACKGROUND_CALLABLE, 1, offsetof(struct dri_screen, dri2.backgroundCallable), true}, {__DRI_SWRAST_LOADER, 1, offsetof(struct dri_screen, swrast_loader), true}, {__DRI_IMAGE_LOADER, 1, offsetof(struct dri_screen, image.loader), true}, {__DRI_MUTABLE_RENDER_BUFFER_LOADER, 1, offsetof(struct dri_screen, mutableRenderBuffer.loader), true}, diff --git a/src/gallium/include/mesa_interface.h b/src/gallium/include/mesa_interface.h index cd97dd93374..562e5437a61 100644 --- a/src/gallium/include/mesa_interface.h +++ b/src/gallium/include/mesa_interface.h @@ -895,56 +895,6 @@ typedef struct { void (*destroyLoaderImageState)(void *loaderPrivate); } __DRIimageLoaderExtension; -/** - * Background callable loader extension. - * - * Loaders expose this extension to indicate to drivers that they are capable - * of handling callbacks from the driver's background drawing threads. - */ -#define __DRI_BACKGROUND_CALLABLE "DRI_BackgroundCallable" - -typedef struct { - __DRIextension base; - - /** - * Indicate that this thread is being used by the driver as a background - * drawing thread which may make callbacks to the loader. - * - * \param loaderPrivate is the value that was passed to to the driver when - * the context was created. This can be used by the loader to identify - * which context any callbacks are associated with. - * - * If this function is called more than once from any given thread, each - * subsequent call overrides the loaderPrivate data that was passed in the - * previous call. The driver can take advantage of this to re-use a - * background thread to perform drawing on behalf of multiple contexts. - * - * It is permissible for the driver to call this function from a - * non-background thread (i.e. a thread that has already been bound to a - * context using __DRIcoreExtension::bindContext()); when this happens, - * the \c loaderPrivate pointer must be equal to the pointer that was - * passed to the driver when the currently bound context was created. - * - * This call should execute quickly enough that the driver can call it with - * impunity whenever a background thread starts performing drawing - * operations (e.g. it should just set a thread-local variable). - */ - void (*setBackgroundContext)(void *loaderPrivate); - - /** - * Indicate that it is multithread safe to use glthread. For GLX/EGL - * platforms using Xlib, that involves calling XInitThreads, before - * opening an X display. - * - * Note: only supported if extension version is at least 2. - * - * \param loaderPrivate is the value that was passed to to the driver when - * the context was created. This can be used by the loader to identify - * which context any callbacks are associated with. - */ - unsigned char (*isThreadSafe)(void *loaderPrivate); -} __DRIbackgroundCallableExtension; - /** * The loader portion of EGL_KHR_mutable_render_buffer. * diff --git a/src/glx/dri3_glx.c b/src/glx/dri3_glx.c index ee56a9e9fda..109bc3dc922 100644 --- a/src/glx/dri3_glx.c +++ b/src/glx/dri3_glx.c @@ -339,21 +339,6 @@ dri3_flush_swap_buffers(struct dri_drawable *driDrawable, void *loaderPrivate) loader_dri3_swapbuffer_barrier(draw); } -static void -dri_set_background_context(void *loaderPrivate) -{ - __glXSetCurrentContext(loaderPrivate); -} - -static GLboolean -dri_is_thread_safe(void *loaderPrivate) -{ - /* Unlike DRI2, DRI3 doesn't call GetBuffers/GetBuffersWithFormat - * during draw so we're safe here. - */ - return true; -} - /* The image loader extension record for DRI3 */ static const __DRIimageLoaderExtension imageLoaderExtension = { @@ -364,16 +349,8 @@ static const __DRIimageLoaderExtension imageLoaderExtension = { .flushSwapBuffers = dri3_flush_swap_buffers, }; -static const __DRIbackgroundCallableExtension dri3BackgroundCallable = { - .base = { __DRI_BACKGROUND_CALLABLE, 2 }, - - .setBackgroundContext = dri_set_background_context, - .isThreadSafe = dri_is_thread_safe, -}; - static const __DRIextension *loader_extensions[] = { &imageLoaderExtension.base, - &dri3BackgroundCallable.base, NULL }; diff --git a/src/glx/dri_common.c b/src/glx/dri_common.c index 58dfaae0f4c..904ba60df2d 100644 --- a/src/glx/dri_common.c +++ b/src/glx/dri_common.c @@ -737,25 +737,6 @@ out: return e ? e->config : NULL; } -static void -driSetBackgroundContext(void *loaderPrivate) -{ - __glXSetCurrentContext(loaderPrivate); -} - -static GLboolean -driIsThreadSafe(void *loaderPrivate) -{ - return true; -} - -const __DRIbackgroundCallableExtension driBackgroundCallable = { - .base = { __DRI_BACKGROUND_CALLABLE, 2 }, - - .setBackgroundContext = driSetBackgroundContext, - .isThreadSafe = driIsThreadSafe, -}; - Bool dri_bind_context(struct glx_context *context, GLXDrawable draw, GLXDrawable read) { diff --git a/src/glx/dri_common.h b/src/glx/dri_common.h index ef001be0de6..e2645547e8e 100644 --- a/src/glx/dri_common.h +++ b/src/glx/dri_common.h @@ -88,8 +88,6 @@ dri_common_create_context(struct glx_screen *base, struct glx_context *shareList, int renderType); -extern const __DRIbackgroundCallableExtension driBackgroundCallable; - Bool dri_bind_context(struct glx_context *context, GLXDrawable draw, GLXDrawable read); void diff --git a/src/glx/drisw_glx.c b/src/glx/drisw_glx.c index 2529d38b34c..5f9b674c1c8 100644 --- a/src/glx/drisw_glx.c +++ b/src/glx/drisw_glx.c @@ -430,7 +430,6 @@ static const __DRIextension *loader_extensions_noshm[] = { static const __DRIextension *kopper_extensions_noshm[] = { &swrastLoaderExtension.base, &kopperLoaderExtension.base, - &driBackgroundCallable.base, NULL };