[Mesa-dev] Bug with glBlitFramebufferEXT(), and a piglit test for it

Federico Mena Quintero federico.mena.lists at gmail.com
Tue Oct 22 00:37:06 CEST 2013


Hello, everyone,

Attached is a new test for piglit which exposes a bug in Mesa's
software rendering (and another bug in hardware rendering, but that's
not its main purpose).

The bug is as follows.  With software rendering, after doing a buffer
swap, glBlitFrameBufferEXT() appears to to copy the whole framebuffer
instead of just the specified region.  This breaks clutter and cogl,
since they keep track of a dirty region themselves, and they use blits
instead of full buffer swaps to avoid updating the whole display on
every frame unnecessarily.

What is happening is actually a bit more complicated.
glBlitFrameBufferEXT()'s basic machinery works correctly, but if there
has been a buffer swap before it, the following happens:

1. Draw some stuff (say, to GL_BACK)

2. Swap buffers.  As far as I can tell, this just causes an
XPutImage() from the GL_BACK buffer to the X window.

3. Draw some stuff to GL_BACK.

4. Do glBlitFrameBufferEXT() from GL_BACK to GL_FRONT with the area you
are interested in.

5. Internally, Mesa sees that the buffer for GL_FRONT has not been
created yet, so it creates it and does the blit.

6. Do glFlush() so that GL_FRONT actually gets sent to the screen.  This
causes an XPutImage() of the *whole* of GL_FRONT, thus giving
incorrect results - the area that should have been updated is the one
from (4), i.e. just the blit.

If you run the test program with hardware acceleration, it will work
correctly.  But if you run it with LIBGL_ALWAYS_SOFTWARE=1, it will
fail.

For a related bug, do the following:  in the test program change the
line that says

  #define SWAP_BUFFERS_BEFORE_BLIT 1

from 1 to 0.  Run the program again; this time it will work correctly
with software rendering, but at least on my box it fails with hardware
rendering (Intel).

I don't know enough about Mesa's internals to fix this quickly.  Any
help is appreciated.

Thanks,

  Federico

-------------- next part --------------
A non-text attachment was scrubbed...
Name: piglit-fbo-blit-after-swap.patch
Type: text/x-patch
Size: 6466 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20131021/55b8ca10/attachment-0001.bin>


More information about the mesa-dev mailing list