[Mesa-dev] Mesa + glxPixmaps problems

Kristian Høgsberg krh at bitplanet.net
Fri Aug 27 11:20:44 PDT 2010


On Thu, Aug 26, 2010 at 11:30 AM, Ian Molton <ian.molton at collabora.co.uk> wrote:
>
> Hi folks,
>
> I've been working on some code that makes extensive use of glxPixmaps for
> offscreen rendering, and I've hit a number of problems.
>
> First, My colleague and I found that the following sequence of events led to
> a crash:
>
> context1 = glXCreateNewContext()
> xPixmap = XCreatePixmap ()
> glxPixmap = glXCreatePixmap (dpy, blah, xPixmap, NULL);
>
> glXMakeCurrent (dpy, glxPixmap, context1);
> context2 = glXCreateNewContext()
> glXDestroyContext(dpy, context2);
> glXMakeCurrent (dpy, glxPixmap, context1);
> **KABOOM**
>
> It turns out that this is down to a flaw in the garbage collection code,
> where a test is made to determine if a drawable still exists, and if not, it
> is dropped from the hashtable (src/glx/glxcmd.c)
>
> The test is this:
>
> XGetWindowAttributes(dpy, draw, &xwa); /* dummy request */
>
> And if an error is caught, it is assumed the drawable is gone, however if
> draw is a glxPixmap, it appears X does not consider them drawable, and thus
> the test will ALWAYS return false, resulting in hashtable entries for
> glxPixmaps being destroyed when they should not.
>
> Changing this line to:
>
> XGetWindowAttributes(dpy, pdraw->xDrawable, &xwa); /* dummy request */
>
> Fixes the problem (by extracting the underlying X drawable from the pdraw
> struct).

Yes, the drawable garbage collection is broken; it doesn't work for
pixmaps (as Michel pointed) out, it's not thread safe and as you
found, it uses the GLX XID for testing whether the X drawable is still
live.  And even when it's working right, it'll generate a bunch of
roundtrips to the X server.  I wanted to get rid of it when I recently
chopped through GLX, but ran out of steam.  But I sat down today and
wrote a patch to implement what I had in mind, it's attached, please
give it a try.  With this patch we now only keep the client side
struct alive for as long as the X drawable is bound to a context.  It
only affects pre-glx 1.3 uses where the application binds a regular X
drawable to a context and we have track the lifetime of the underlying
client side structs transparently.

> Sadly, however, it appears that there are many more similar looking bugs in
> Mesa. Has anyone actually used Mesa to render to glxPixmaps? are there
> patches available to make this stuff work?

There has been a number of bugs recently where either the X drawable
XID or the GLX drawable XID was used in place of the other and there
may be more bugs of that kind lurking in there.  I tested simple uses
of GLX pixmaps when I added the support, but I'm sure more complicated
use patterns will trigger bugs we haven't seen yet.  As Eric said, the
best way to get these fixed is to send a piglit patch
(http://cgit.freedesktop.org/piglit/) with a new test case that
demonstrates the problem.

Kristian
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-glx-Drop-broken-drawable-garbage-collection.patch
Type: text/x-patch
Size: 8787 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20100827/5a4991fb/attachment.bin>


More information about the mesa-dev mailing list