[Mesa-dev] [PATCH 2/4] st/mesa: implement st_server_wait_sync properly

Nicolai Hähnle nhaehnle at gmail.com
Thu Nov 9 13:45:57 UTC 2017


From: Nicolai Hähnle <nicolai.haehnle at amd.com>

Asynchronous flushes require a proper implementation of
st_server_wait_sync, because we could have the following with
threaded Gallium:

 Context 1 app     Context 1 driver         Context 2
 -------------     ----------------         ---------
 f = glFenceSync
 glFlush
 <-- app sync -->                           <-- app sync -->
                                            glWaitSync(f)
                                            .. draw calls ..
                   pipe_context::flush
                     for glFenceSync
                   pipe_context::flush
                     for glFlush
---
 src/mesa/state_tracker/st_cb_syncobj.c | 26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)

diff --git a/src/mesa/state_tracker/st_cb_syncobj.c b/src/mesa/state_tracker/st_cb_syncobj.c
index 637fbe3b73a..44323b4750a 100644
--- a/src/mesa/state_tracker/st_cb_syncobj.c
+++ b/src/mesa/state_tracker/st_cb_syncobj.c
@@ -123,22 +123,44 @@ static void st_client_wait_sync(struct gl_context *ctx,
 
 static void st_check_sync(struct gl_context *ctx, struct gl_sync_object *obj)
 {
    st_client_wait_sync(ctx, obj, 0, 0);
 }
 
 static void st_server_wait_sync(struct gl_context *ctx,
                                 struct gl_sync_object *obj,
                                 GLbitfield flags, GLuint64 timeout)
 {
-   /* NO-OP.
-    * Neither Gallium nor DRM interfaces support blocking on the GPU. */
+   struct pipe_context *pipe = st_context(ctx)->pipe;
+   struct pipe_screen *screen = pipe->screen;
+   struct st_sync_object *so = (struct st_sync_object*)obj;
+   struct pipe_fence_handle *fence = NULL;
+
+   /* Nothing needs to be done here if the driver does not support async
+    * flushes. */
+   if (!pipe->fence_server_sync)
+      return;
+
+   /* If the fence doesn't exist, assume it's signalled. */
+   mtx_lock(&so->mutex);
+   if (!so->fence) {
+      mtx_unlock(&so->mutex);
+      so->b.StatusFlag = GL_TRUE;
+      return;
+   }
+
+   /* We need a local copy of the fence pointer. */
+   screen->fence_reference(screen, &fence, so->fence);
+   mtx_unlock(&so->mutex);
+
+   pipe->fence_server_sync(pipe, fence);
+   screen->fence_reference(screen, &fence, NULL);
 }
 
 void st_init_syncobj_functions(struct dd_function_table *functions)
 {
    functions->NewSyncObject = st_new_sync_object;
    functions->FenceSync = st_fence_sync;
    functions->DeleteSyncObject = st_delete_sync_object;
    functions->CheckSync = st_check_sync;
    functions->ClientWaitSync = st_client_wait_sync;
    functions->ServerWaitSync = st_server_wait_sync;
-- 
2.11.0



More information about the mesa-dev mailing list