Mesa (main): glthread: change when glFlush flushes asynchronously

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Jun 17 02:54:22 UTC 2021


Module: Mesa
Branch: main
Commit: 3da170faaec2a57d76e668ab56781621c23c6703
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=3da170faaec2a57d76e668ab56781621c23c6703

Author: Marek Olšák <marek.olsak at amd.com>
Date:   Sat Jun 12 12:31:28 2021 -0400

glthread: change when glFlush flushes asynchronously

This fixes the flushing with external textures.

We don't know if we need to flush synchronously with multiple contexts,
so I removed that.

Acked-By: Mike Blumenkrantz <michael.blumenkrantz at gmail.com>
Reviewed-by: Adam Jackson <ajax at redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11341>

---

 src/gallium/frontends/dri/dri_helpers.c | 2 ++
 src/mapi/glapi/gen/gl_API.xml           | 8 +-------
 src/mesa/main/mtypes.h                  | 8 ++++++++
 src/mesa/state_tracker/st_cb_eglimage.c | 1 +
 4 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/src/gallium/frontends/dri/dri_helpers.c b/src/gallium/frontends/dri/dri_helpers.c
index 4170a4c9533..583ce67978d 100644
--- a/src/gallium/frontends/dri/dri_helpers.c
+++ b/src/gallium/frontends/dri/dri_helpers.c
@@ -309,6 +309,7 @@ dri2_create_image_from_renderbuffer2(__DRIcontext *context,
    if (dri2_get_mapping_by_format(img->dri_format))
       p_ctx->flush_resource(p_ctx, tex);
 
+   ctx->Shared->HasExternallySharedImages = true;
    *error = __DRI_IMAGE_ERROR_SUCCESS;
    return img;
 }
@@ -407,6 +408,7 @@ dri2_create_from_texture(__DRIcontext *context, int target, unsigned texture,
    if (dri2_get_mapping_by_format(img->dri_format))
       p_ctx->flush_resource(p_ctx, tex);
 
+   ctx->Shared->HasExternallySharedImages = true;
    *error = __DRI_IMAGE_ERROR_SUCCESS;
    return img;
 }
diff --git a/src/mapi/glapi/gen/gl_API.xml b/src/mapi/glapi/gen/gl_API.xml
index f0496a14285..1d5575f296a 100644
--- a/src/mapi/glapi/gen/gl_API.xml
+++ b/src/mapi/glapi/gen/gl_API.xml
@@ -2399,14 +2399,8 @@
         <glx sop="108" handcode="true"/>
     </function>
 
-    <!-- Shared contexts have to wait for glthread to finish execution after glFlush,
-         so that other contexts can see the effect of previous GL calls when glFlush returns.
-         This is harmless if the contexts run on different threads, because we only stall
-         1 thread that's asynchronous anyway. It's worse when the contexts run on the same
-         thread, but that's not a good use of multiple contexts.
-    -->
     <function name="Flush" es1="1.0" es2="2.0"
-              marshal_call_after="_mesa_glthread_flush_batch(ctx); if (ctx->Shared->RefCount > 1) _mesa_glthread_finish(ctx);">
+              marshal_call_after="_mesa_glthread_flush_batch(ctx); if (ctx->Shared->HasExternallySharedImages) _mesa_glthread_finish(ctx);">
         <glx sop="142" handcode="true"/>
     </function>
 
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index ee1c19df9a2..e7474ad0262 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -3474,6 +3474,14 @@ struct gl_shared_state
     * frequency changes.
     */
    bool DisjointOperation;
+
+   /**
+    * Whether at least one image has been imported or exported, excluding
+    * the default framebuffer. If this is false, glFlush can be executed
+    * asynchronously because there is no invisible dependency on external
+    * users.
+    */
+   bool HasExternallySharedImages;
 };
 
 
diff --git a/src/mesa/state_tracker/st_cb_eglimage.c b/src/mesa/state_tracker/st_cb_eglimage.c
index 0c487d01021..9bd53148aa7 100644
--- a/src/mesa/state_tracker/st_cb_eglimage.c
+++ b/src/mesa/state_tracker/st_cb_eglimage.c
@@ -192,6 +192,7 @@ st_get_egl_image(struct gl_context *ctx, GLeglImageOES image_handle,
       return false;
    }
 
+   ctx->Shared->HasExternallySharedImages = true;
    return true;
 }
 



More information about the mesa-commit mailing list