frontend/dri: make the backgroundCallable extension optional
authorMarek Olšák <marek.olsak@amd.com>
Tue, 23 Aug 2022 02:28:58 +0000 (22:28 -0400)
committerMarge Bot <emma+marge@anholt.net>
Wed, 21 Sep 2022 14:54:50 +0000 (14:54 +0000)
It's only needed by X11/DRI2. This allows glthread to be used by android,
drm, wayland, and device (EGL backend).

This is the only solution to allow the egl/drm backend to work with glthread
without ugly hacks between libgbm and libEGL.

Reviewed-by: Adam Jackson <ajax@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18223>

src/gallium/frontends/dri/dri_context.c
src/gallium/frontends/dri/dri_screen.c

index 3a98eb2..1d48665 100644 (file)
@@ -206,20 +206,18 @@ dri_create_context(gl_api api, const struct gl_config * visual,
 
    /* Do this last. */
    if (ctx->st->start_thread &&
-         driQueryOptionb(&screen->dev->option_cache, "mesa_glthread")) {
-
-      if (backgroundCallable && backgroundCallable->base.version >= 2 &&
-            backgroundCallable->isThreadSafe) {
-
-         if (backgroundCallable->isThreadSafe(cPriv->loaderPrivate))
-            ctx->st->start_thread(ctx->st);
-         else
-            fprintf(stderr, "dri_create_context: glthread isn't thread safe "
-                  "- missing call XInitThreads\n");
-      } else {
-         fprintf(stderr, "dri_create_context: requested glthread but driver "
-               "is missing backgroundCallable V2 extension\n");
-      }
+       driQueryOptionb(&screen->dev->option_cache, "mesa_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(cPriv->loaderPrivate))
+         safe = false;
+
+      if (safe)
+         ctx->st->start_thread(ctx->st);
    }
 
    *error = __DRI_CTX_ERROR_SUCCESS;
index fe232ba..e9f3671 100644 (file)
@@ -824,12 +824,8 @@ dri_set_background_context(struct st_context_iface *st,
    const __DRIbackgroundCallableExtension *backgroundCallable =
       ctx->sPriv->dri2.backgroundCallable;
 
-   /* Note: Mesa will only call this function if GL multithreading is enabled
-    * We only do that if the loader exposed the __DRI_BACKGROUND_CALLABLE
-    * extension. So we know that backgroundCallable is not NULL.
-    */
-   assert(backgroundCallable);
-   backgroundCallable->setBackgroundContext(ctx->cPriv->loaderPrivate);
+   if (backgroundCallable)
+      backgroundCallable->setBackgroundContext(ctx->cPriv->loaderPrivate);
 
    if (ctx->hud)
       hud_add_queue_for_monitoring(ctx->hud, queue_info);