[Mesa-dev] [PATCH 0/2] First attempt at asynchronous SwapBuffers

Marek Olšák maraeo at gmail.com
Thu Nov 15 09:48:00 PST 2012


On Thu, Nov 15, 2012 at 3:30 PM, Michel Dänzer <michel at daenzer.net> wrote:
> On Don, 2012-11-15 at 04:43 +0100, Marek Olšák wrote:
>>
>> For the asynchronous SwapBuffers to work, there must be a separate X
>> connection, because Xlib isn't thread-safe at all.
>>
>> Now the bad news. The DRI invalidate events may be received too late.
>> We can't wait for the events in glXSwapBuffers, because that would
>> defeat the whole purpose of thread offloading.
>
> Why would it? Couldn't you e.g. have the main thread wait for the
> SwapBuffers thread to get the events when it needs the buffer
> information for the next frame?

The problem is I have to flush the context first, which calls the CS
ioctl and sysprof shows it usually takes about 20% of all CPU time if
that is the only context flush in the whole frame. If I flush the
context in the driver thread and at the same time I swap the buffers
in the main thread, the buffers may be swapped before the context is
fully flushed and an incomplete frame is displayed. So the context
must be flushed *before* the swapping.

Then we can swap the buffers, process all the events (XSync) and get
the swap-buffers reply. This all must be done in the driver thread for
it to work. If I can't offload the swapping, I can't offload the
context flush either (unless the kernel can somehow synchronize the
two, even though they are parallel in userspace).


>
>
>> For normal apps, that only happens when the window is resized, so only
>> the next rendered frame is likely to contain garbage.
>
> DRI2SwapBuffers also generates invalidate events, and those can be
> crucial e.g. with page flipping.

DRI2SwapBuffers is gone, see:
http://www.mail-archive.com/mesa-dev@lists.freedesktop.org/msg27459.html

All I am talking about is offloading the dri2SwapBuffers call
(flush+swap) in glx/dri2_glx.c.

>
>
>> Compositors don't work very well with this. I think it's because of
>> the invalidate events not being received in time. As a temporary
>> solution, I turn off asynchronous SwapBuffers if dri2_bind_tex_image
>> is called, which should cover all compositors that either directly or
>> indirectly use GLX.
>
> I fail to see the connection. Maybe the compositors break because they
> use page flipping, per above?

I have SwapBuffersWait turned off, which also turns off page flipping AFAIK.

I guess I could try to invalidate all drawables before SwapBuffers if
that's even possible.

Marek


More information about the mesa-dev mailing list