[Mesa-dev] [PATCH] dri2: Remove the extra roundtrip during SwapBuffers

Chris Wilson chris at chris-wilson.co.uk
Sun Aug 11 13:13:50 PDT 2013


On Sun, Aug 11, 2013 at 08:42:45PM +0200, Eric Anholt wrote:
> Chris Wilson <chris at chris-wilson.co.uk> writes:
> 
> > Currently we call XSync() to run the event queue to catch the invalidate
> > event before we wait for the reply from the DRI2SwapBuffers request.
> > However, the XServer sends the DRI2InvalidateNotify event before sending
> > the DRI2SwapBuffers reply and so the invalidate event is processed in
> > the normal manner by xcb before it returns the DRI2SwapBuffers reply
> > without having to add an extra round-trip.
> 
> You need Xlib to have processed the event, not just XCB.  I remember the
> XSync being required to make rendering actually work correctly when I
> wrote the code.

I thought that was all handled inside xcb, but the async handlers is an
libX11 feature, dispatched by _XEventsQueued (called by _XReply). In
order to actually called the async handlers immediately you do need the
internal function as opposed to XPending or XQLength.

diff --git a/src/glx/dri2_glx.c b/src/glx/dri2_glx.c
index c54edac..580af86 100644
--- a/src/glx/dri2_glx.c
+++ b/src/glx/dri2_glx.c
@@ -812,12 +812,7 @@ dri2XcbSwapBuffers(Display *dpy,
     * to do so some time before reusing a (non-pageflipped) backbuffer.
     * Otherwise, the new rendering could get ahead of the X Server's
     * dispatch of the swapbuffer and you'd display garbage.
-    *
-    * We use XSync() first to reap the invalidate events through the event
-    * filter, to ensure that the next drawing doesn't use an invalidated
-    * buffer.
     */
-   XSync(dpy, False);
 
    swap_buffers_reply =
       xcb_dri2_swap_buffers_reply(c, swap_buffers_cookie, NULL);
@@ -826,6 +821,11 @@ dri2XcbSwapBuffers(Display *dpy,
                           swap_buffers_reply->swap_lo);
       free(swap_buffers_reply);
    }
+
+   /* Run our async event handlers attached via libX11 to ensure that the
+    * next drawing doesn't use an invalidated buffer.
+    */
+   _XEventsQueued(dpy, QueuedAfterFlush);
    return ret;
 }

-- 
Chris Wilson, Intel Open Source Technology Centre


More information about the mesa-dev mailing list