i965: Implement threaded GL support.
authorKenneth Graunke <kenneth@whitecape.org>
Mon, 10 Jul 2017 06:03:44 +0000 (23:03 -0700)
committerKenneth Graunke <kenneth@whitecape.org>
Tue, 5 Mar 2019 08:49:05 +0000 (00:49 -0800)
Now i965 supports mesa_glthread=true like Gallium drivers do.

According to Markus (degasus), the Citra emulator now runs ~30% faster.
Emmanuel (linkmauve) also reported that the Dolphin emulator improved
by 2.8x on one game.  (Both of those still need to be added to drirc.)

An Intel Mesa CI run with mesa_glthread=true appears to be happy.

Bioshock Infinite's benchmark mode seems to be around 15-20% faster
on my Skylake GT4 at 1920x1080.

Tested-by: Markus Wick <markus@selfnet.de>
Tested-by: Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
Tested-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
src/mesa/drivers/dri/i965/brw_context.c
src/mesa/drivers/dri/i965/intel_screen.c
src/mesa/drivers/dri/i965/intel_tex_image.c

index 505da9896b369a445bec5c321a106ffa10e80086..ab637ddf7216506e6579dede85f9c5f8c18e7448 100644 (file)
@@ -36,6 +36,7 @@
 #include "main/context.h"
 #include "main/fbobject.h"
 #include "main/extensions.h"
+#include "main/glthread.h"
 #include "main/imports.h"
 #include "main/macros.h"
 #include "main/points.h"
@@ -147,6 +148,24 @@ intel_get_string(struct gl_context * ctx, GLenum name)
    }
 }
 
+static void
+brw_set_background_context(struct gl_context *ctx,
+                           struct util_queue_monitoring *queue_info)
+{
+   struct brw_context *brw = brw_context(ctx);
+   __DRIcontext *driContext = brw->driContext;
+   __DRIscreen *driScreen = driContext->driScreenPriv;
+   const __DRIbackgroundCallableExtension *backgroundCallable =
+      driScreen->dri2.backgroundCallable;
+
+   /* Note: Mesa will only call this function if we've called
+    * _mesa_enable_multithreading().  We only do that if the loader exposed
+    * the __DRI_BACKGROUND_CALLABLE extension.  So we know that
+    * backgroundCallable is not NULL.
+    */
+   backgroundCallable->setBackgroundContext(driContext->loaderPrivate);
+}
+
 static void
 intel_viewport(struct gl_context *ctx)
 {
@@ -376,6 +395,8 @@ brw_init_driver_functions(struct brw_context *brw,
    if (brw->screen->disk_cache) {
       functions->ShaderCacheSerializeDriverBlob = brw_program_serialize_nir;
    }
+
+   functions->SetBackgroundContext = brw_set_background_context;
 }
 
 static void
@@ -1126,6 +1147,12 @@ brwCreateContext(gl_api api,
 
    brw->ctx.Cache = brw->screen->disk_cache;
 
+   if (driContextPriv->driScreenPriv->dri2.backgroundCallable &&
+       driQueryOptionb(&screen->optionCache, "mesa_glthread")) {
+      /* Loader supports multithreading, and so do we. */
+      _mesa_glthread_init(ctx);
+   }
+
    return true;
 }
 
@@ -1136,6 +1163,18 @@ intelDestroyContext(__DRIcontext * driContextPriv)
       (struct brw_context *) driContextPriv->driverPrivate;
    struct gl_context *ctx = &brw->ctx;
 
+   GET_CURRENT_CONTEXT(curctx);
+
+   if (curctx == NULL) {
+      /* No current context, but we need one to release
+       * renderbuffer surface when we release framebuffer.
+       * So temporarily bind the context.
+       */
+      _mesa_make_current(ctx, NULL, NULL);
+   }
+
+   _mesa_glthread_destroy(&brw->ctx);
+
    _mesa_meta_free(&brw->ctx);
 
    if (INTEL_DEBUG & DEBUG_SHADER_TIME) {
@@ -1196,6 +1235,9 @@ intelDestroyContext(__DRIcontext * driContextPriv)
 GLboolean
 intelUnbindContext(__DRIcontext * driContextPriv)
 {
+   GET_CURRENT_CONTEXT(ctx);
+   _mesa_glthread_finish(ctx);
+
    /* Unset current context and dispath table */
    _mesa_make_current(NULL, NULL, NULL);
 
@@ -1299,6 +1341,8 @@ intelMakeCurrent(__DRIcontext * driContextPriv,
 
       _mesa_make_current(ctx, fb, readFb);
    } else {
+      GET_CURRENT_CONTEXT(ctx);
+      _mesa_glthread_finish(ctx);
       _mesa_make_current(NULL, NULL, NULL);
    }
 
index d34b161f41e71302f1fb9c631ec8b17d4709a530..76c85047240440c384844c6624d1785a1050bc6e 100644 (file)
@@ -34,6 +34,7 @@
 #include "main/hash.h"
 #include "main/fbobject.h"
 #include "main/version.h"
+#include "main/glthread.h"
 #include "swrast/s_renderbuffer.h"
 #include "util/ralloc.h"
 #include "util/disk_cache.h"
@@ -62,6 +63,7 @@ DRI_CONF_BEGIN
         DRI_CONF_DESC_END
       DRI_CONF_OPT_END
       DRI_CONF_MESA_NO_ERROR("false")
+      DRI_CONF_MESA_GLTHREAD("false")
    DRI_CONF_SECTION_END
 
    DRI_CONF_SECTION_QUALITY
@@ -148,6 +150,8 @@ intel_dri2_flush_with_flags(__DRIcontext *cPriv,
 
    struct gl_context *ctx = &brw->ctx;
 
+   _mesa_glthread_finish(ctx);
+
    FLUSH_VERTICES(ctx, 0);
 
    if (flags & __DRI2_FLUSH_DRAWABLE)
index 8d4ca7fed728c17ff8512e89e9c7daa1a66937ff..ccaa9ef7474714c10bd84ac345eea1d55ac7c11f 100644 (file)
@@ -14,6 +14,7 @@
 #include "main/texobj.h"
 #include "main/teximage.h"
 #include "main/texstore.h"
+#include "main/glthread.h"
 
 #include "drivers/common/meta.h"
 
@@ -442,6 +443,8 @@ intelSetTexBuffer2(__DRIcontext *pDRICtx, GLint target,
    mesa_format texFormat = MESA_FORMAT_NONE;
    GLenum internal_format = 0;
 
+   _mesa_glthread_finish(ctx);
+
    texObj = _mesa_get_current_tex_object(ctx, target);
 
    if (!texObj)