[Mesa-dev] [PATCH 3/4] dri2: Don't call the dri2 flush hook for swapbuffers unless we have a context.

Kristian Høgsberg krh at bitplanet.net
Tue Feb 22 12:07:45 PST 2011


On Tue, Feb 22, 2011 at 2:07 PM, Ian Romanick <idr at freedesktop.org> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On 02/21/2011 02:41 PM, Eric Anholt wrote:
>> The driver only has one reasonable place to look for its context to
>> flush anything, which is the current context.  Don't bother it with
>> having to check.
>
> There are some odd interactions here, but I don't completely recall the
> details.  Kristian implemented this function in this way for a specific
> reason.  It was either to deal with glXSwapBuffers when no context was
> current or to deal with glXSwapBuffers on a drawable that isn't bound to
> a context.  Otherwise the flush method would have been associated with
> the context (instead of with the screen).

The background is that tiling/deferred rendering architectures would
like to ignore glFlush() and only really flush when the user hits
*SwapBuffer.  Since the driver doesn't actually see the swapbuffer
call (it goes to the X server, Wayland or the pageflip ioctl), there
has to be a way for the loader to tell the driver "ok, really flush
now".  That's what this entry point is for.

It looks like there could be a problem if the drawable isn't current
for any context, and Erics patch looks like it just skips it if
there's no current context which probably fixes some crashes.  It
seems like it could still crash if there's a current context, but the
drawable passed to swapbuffers isn't current for any context.  The
spec says that the flush is only implied if the drawable is current
for the current context in the current thread, maybe we just need to
add that check before calling the dri flush entrypoint.

Kristian

>> ---
>>  src/glx/dri2_glx.c |    9 +++++++--
>>  1 files changed, 7 insertions(+), 2 deletions(-)
>>
>> diff --git a/src/glx/dri2_glx.c b/src/glx/dri2_glx.c
>> index a275ba5..2c28bc2 100644
>> --- a/src/glx/dri2_glx.c
>> +++ b/src/glx/dri2_glx.c
>> @@ -535,8 +535,13 @@ dri2SwapBuffers(__GLXDRIdrawable *pdraw, int64_t target_msc, int64_t divisor,
>>      CARD64 ret = 0;
>>
>>  #ifdef __DRI2_FLUSH
>> -    if (psc->f)
>> -     (*psc->f->flush)(priv->driDrawable);
>> +    if (psc->f) {
>> +       struct glx_context *gc = __glXGetCurrentContext();
>> +
>> +       if (gc) {
>> +       (*psc->f->flush)(priv->driDrawable);
>> +       }
>> +    }
>>  #endif
>>
>>      /* Old servers don't send invalidate events */
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.11 (GNU/Linux)
> Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/
>
> iEYEARECAAYFAk1kCYQACgkQX1gOwKyEAw+8VgCfbPmxFENw5p0pdYPA4uaTbEKA
> AogAoJV5DVlgJi4w2yPFGE0AJH4dN9WG
> =o3/e
> -----END PGP SIGNATURE-----
>


More information about the mesa-dev mailing list