gallium/xlib: call fence_finish() in XMesaSwapBuffers()
authorBrian Paul <brianp@vmware.com>
Fri, 17 Mar 2023 20:23:29 +0000 (14:23 -0600)
committerMarge Bot <emma+marge@anholt.net>
Mon, 20 Mar 2023 06:05:47 +0000 (06:05 +0000)
Before we can present the buffer we need to wait for the fence to
finish.  This fixes severe flickering of unfinished rendering in
many demos/tests.  This has been broken for a while, I think.

Note, this is for the non-DRI / Xlib-based GLX.

Signed-off-by: Brian Paul <brianp@vmware.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21993>

src/gallium/frontends/glx/xlib/xm_api.c

index 458c56c..9599741 100644 (file)
@@ -1343,7 +1343,16 @@ void XMesaSwapBuffers( XMesaBuffer b )
    }
 
    if (xmctx && xmctx->xm_buffer == b) {
-      st_context_flush(xmctx->st, ST_FLUSH_FRONT, NULL, NULL, NULL);
+      struct pipe_fence_handle *fence = NULL;
+      st_context_flush(xmctx->st, ST_FLUSH_FRONT, &fence, NULL, NULL);
+      /* Wait until all rendering is complete */
+      if (fence) {
+         XMesaDisplay xmdpy = xmesa_init_display(b->xm_visual->display);
+         struct pipe_screen *screen = xmdpy->screen;
+         xmdpy->screen->fence_finish(screen, NULL, fence,
+                                     PIPE_TIMEOUT_INFINITE);
+         xmdpy->screen->fence_reference(screen, &fence, NULL);
+      }
    }
 
    xmesa_swap_st_framebuffer(b->drawable);