Hi, I've been looking for this bug for a couple of months now, and I don't feel like I'm making much progress.
Attached is a piglit test that exposes the bug. Run this with software rendering: export LIBGL_ALWAYS_SOFTWARE=1 The bug is very obvious if you run Clutter programs with that, e.g. gnome-shell. The display is all messed up. So far I have a patch for Mesa, also attached, that tries to fix this. It makes the piglit test pass, but gnome-shell still displays incorrectly. As far as I can tell, the bug happens like this. glBlitFramebuffer() needs to create a "real" front buffer (whereas previously all buffer swaps happened by just doing an XPutImage() from the back buffer to the X window). However, when glBlitFramebuffer() creates the real front buffer, it does not initialize it with the previous contents of either the "fake" front buffer, nor with the contents of the back buffer. So, the real front buffer starts up black, and subsequent blits to the screen are incorrect. My patch copies the back buffer to the real front buffer once the latter gets created. This makes the piglit test pass. However, this does not solve the problem for Clutter programs. I've tried to read the code for e.g. the Intel driver, where it mentions that intel_prepare_render() "should be called anywhere that curent read/drawbuffer state is required". I think something similar needs to happen with drisw's implementation of blitting. Basically, I don't know enough about the interplay between front/back buffers or how programs with multiple drawables are supposed to function. Any help is appreciated. Thanks! Federico
commit bf30fc1d1212e9b2cc3c837271a626b556d4fefb Author: Federico Mena Quintero <[email protected]> Date: Thu Oct 17 14:52:31 2013 -0500 fbo-blit-after-swap: New test for partial blits after a buffer swap Supports a "no-swap" command-line argument; see below. The clutter/cogl libraries try to minimize the area that gets updated on every frame. They do this by doing glBlitFramebufferEXT() from the back buffer to the front buffer. However, this is buggy with software rendering if there has been a buffer swap *before* the first blit from the back buffer to the front buffer. In this case, Mesa fails to initialize the real front buffer with the contents of the back buffer before doing the blit. The test does this: 1. Clear the back buffer to blue. 2. Copy the back buffer to the front buffer, by default with a buffer swap (see below). 3. Clear the back buffer to green, and draw a red square in the middle. 4. glBlitFramebuffer() just the red square from the back to the front buffer. This test supports a "no-swap" command-line argument. With this argument, step (2) will be done via a full-frame glBlitFramebuffer(), instead of a buffer swap. This exposes another bug with hardware rendering, at least on Intel graphics. diff --git a/tests/all.tests b/tests/all.tests index 7ab841e..6c92ebf 100644 --- a/tests/all.tests +++ b/tests/all.tests @@ -1163,6 +1163,7 @@ for format in ('rgba', 'depth', 'stencil'): test_name = ' '.join(['framebuffer-blit-levels', test_mode, format]) arb_framebuffer_object[test_name] = PlainExecTest(test_name + ' -auto') add_plain_test(arb_framebuffer_object, 'fbo-alpha') +add_plain_test(arb_framebuffer_object, 'fbo-blit-after-swap') add_plain_test(arb_framebuffer_object, 'fbo-blit-stretch') add_plain_test(arb_framebuffer_object, 'fbo-blit-scaled-linear') add_plain_test(arb_framebuffer_object, 'fbo-attachments-blit-scaled-linear') diff --git a/tests/fbo/CMakeLists.gl.txt b/tests/fbo/CMakeLists.gl.txt index 588fe26..3ad9ec0 100644 --- a/tests/fbo/CMakeLists.gl.txt +++ b/tests/fbo/CMakeLists.gl.txt @@ -31,6 +31,7 @@ piglit_add_executable (fbo-alpha fbo-alpha.c) piglit_add_executable (fbo-luminance-alpha fbo-luminance-alpha.c) piglit_add_executable (fbo-bind-renderbuffer fbo-bind-renderbuffer.c) piglit_add_executable (fbo-blit fbo-blit.c) +piglit_add_executable (fbo-blit-after-swap fbo-blit-after-swap.c) piglit_add_executable (fbo-blit-d24s8 fbo-blit-d24s8.c) piglit_add_executable (fbo-blit-stretch fbo-blit-stretch.cpp) piglit_add_executable (fbo-blending-formats fbo-blending-formats.c) diff --git a/tests/fbo/fbo-blit-after-swap.c b/tests/fbo/fbo-blit-after-swap.c new file mode 100644 index 0000000..35c5455 --- /dev/null +++ b/tests/fbo/fbo-blit-after-swap.c @@ -0,0 +1,142 @@ +/* + * Copyright 2013 Suse, Inc. + * Copyright © 2011 Henri Verbeet <[email protected]> + * Copyright 2011 Red Hat, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + */ + +/** @file fbo-blit-after-swap.c + * + * Test a glBlitFrameBuffer() with a smaller-than-the-window region after doing a buffer swap + */ + +#include "piglit-util-gl-common.h" + +PIGLIT_GL_TEST_CONFIG_BEGIN + + config.supports_gl_compat_version = 10; + + config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGB; + config.requires_displayed_window = true; + +PIGLIT_GL_TEST_CONFIG_END + +static bool use_swap_buffers = true; + +static const GLfloat red[] = {1.0f, 0.0f, 0.0f, 1.0f}; +static const GLfloat green[] = {0.0f, 1.0f, 0.0f, 1.0f}; +static const GLfloat blue[] = {0.0f, 0.0f, 1.0f, 1.0f}; +static const GLfloat black[] = {0.0f, 0.0f, 0.0f, 1.0f}; + +static void +setup_front_buffer(void) +{ + glDrawBuffer(GL_BACK); + + glClearColor(blue[0], blue[1], blue[2], blue[3]); + glClear(GL_COLOR_BUFFER_BIT); + + if (use_swap_buffers) + piglit_swap_buffers(); + else { + glDrawBuffer(GL_FRONT); + glReadBuffer(GL_BACK); + glBlitFramebufferEXT(0, 0, piglit_width, piglit_height, + 0, 0, piglit_width, piglit_height, + GL_COLOR_BUFFER_BIT, GL_NEAREST); + } +} + +static void +setup_back_buffer(void) +{ + int w = piglit_width; + int h = piglit_height; + + glDrawBuffer(GL_BACK); + + /* Clear to green */ + glClearColor(green[0], green[1], green[2], green[3]); + glClear(GL_COLOR_BUFFER_BIT); + + /* Paint a red square in the middle of the back buffer */ + glColor4fv(red); + piglit_draw_rect(w / 4, h / 4, w / 2, h / 2); +} + +static void +blit_from_back_to_front(void) +{ + int w = piglit_width; + int h = piglit_height; + + /* Copy just the red square from the back buffer to the blue front buffer */ + glDrawBuffer(GL_FRONT); + glReadBuffer(GL_BACK); + glBlitFramebufferEXT(w / 4, h / 4, 3 * w / 4, 3 * h / 4, + w / 4, h / 4, 3 * w / 4, 3 * h / 4, + GL_COLOR_BUFFER_BIT, GL_NEAREST); +} + +enum piglit_result piglit_display(void) +{ + int w = piglit_width; + int h = piglit_height; + bool pass = true; + + piglit_ortho_projection(w, h, GL_FALSE); + + setup_front_buffer(); + setup_back_buffer(); + + blit_from_back_to_front(); + + glFlush(); + + /* Now see how we did... */ + + glReadBuffer(GL_FRONT); + + /* the middle should be red */ + pass = piglit_probe_pixel_rgb(w / 2, h / 2, red) && pass; + + /* the corners should be blue */ + pass = piglit_probe_pixel_rgb(0, 0, blue) && pass; + pass = piglit_probe_pixel_rgb(w - 1, 0, blue) && pass; + pass = piglit_probe_pixel_rgb(0, h - 1, blue) && pass; + pass = piglit_probe_pixel_rgb(w - 1, h - 1, blue) && pass; + + return pass ? PIGLIT_PASS : PIGLIT_FAIL; +} + +void piglit_init(int argc, char **argv) +{ + int i; + + for (i = 1; i < argc; i++) { + if (!strcmp(argv[i], "no-swap")) + use_swap_buffers = false; + } + + piglit_require_extension("GL_EXT_framebuffer_object"); + piglit_require_extension("GL_EXT_framebuffer_blit"); +}
>From 9a787911438df20f0714177335ca748bf6d9e87a Mon Sep 17 00:00:00 2001 From: Federico Mena Quintero <[email protected]> Date: Wed, 15 Jan 2014 15:29:10 -0600 Subject: [PATCH] In drisw, copy BACK_LEFT to FRONT_LEFT when allocating a real front buffer --- src/gallium/state_trackers/dri/sw/drisw.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/gallium/state_trackers/dri/sw/drisw.c b/src/gallium/state_trackers/dri/sw/drisw.c index ba77754..2bd2812 100644 --- a/src/gallium/state_trackers/dri/sw/drisw.c +++ b/src/gallium/state_trackers/dri/sw/drisw.c @@ -252,6 +252,24 @@ drisw_allocate_textures(struct dri_drawable *drawable, drawable->textures[statts[i]] = screen->base.screen->resource_create(screen->base.screen, &templ); + if (statts[i] == ST_ATTACHMENT_FRONT_LEFT && drawable->textures[ST_ATTACHMENT_BACK_LEFT]) { + struct pipe_screen *pscreen = screen->base.screen; + struct pipe_context *pipe; + + /* Up to now, there was no FRONT_LEFT, and all output has been from the + * BACK_LEFT texture. The user expects the contents of FRONT_LEFT to + * be equal to those of BACK_LEFT at some recent point, so make a copy. + */ + + pipe = pscreen->context_create(pscreen, NULL); + dri_pipe_blit(pipe, + drawable->textures[ST_ATTACHMENT_FRONT_LEFT], + drawable->textures[ST_ATTACHMENT_BACK_LEFT]); + pipe->flush(pipe, NULL, 0); + pipe->destroy(pipe); + } + + fprintf (stderr, "drisw_allocate_textures(drawable=%p): created drawable->textures[%s]=%p from screen->base.screen->resource_create()\n", drawable, string_from_st_attachment_type (statts[i]), -- 1.8.1.4
_______________________________________________ mesa-dev mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/mesa-dev
