[Piglit] [PATCH] fbo-blit-after-swap: New test for partial blits after a buffer swap

Federico Mena Quintero federico.mena.lists at gmail.com
Wed Feb 26 12:20:46 PST 2014


From: Federico Mena Quintero <federico at suse.com>

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,
instead of doing a full buffer swap.

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.  A
subsequent glFlush() causes the entire buffer to be copied to the
screen, giving incorrect results as only part of the buffer has valid
contents.
---
 tests/all.py                    |   1 +
 tests/fbo/CMakeLists.gl.txt     |   1 +
 tests/fbo/fbo-blit-after-swap.c | 125 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 127 insertions(+)
 create mode 100644 tests/fbo/fbo-blit-after-swap.c

diff --git a/tests/all.py b/tests/all.py
index 590c832..65814c3 100644
--- a/tests/all.py
+++ b/tests/all.py
@@ -1650,6 +1650,7 @@ for format in ('rgba', 'depth', 'stencil'):
         test_name = ' '.join(['framebuffer-blit-levels', test_mode, format])
         arb_framebuffer_object[test_name] = concurrent_test(test_name)
 add_concurrent_test(arb_framebuffer_object, 'fbo-alpha')
+add_concurrent_test(arb_framebuffer_object, 'fbo-blit-after-swap')
 add_plain_test(arb_framebuffer_object, 'fbo-blit-stretch')
 add_concurrent_test(arb_framebuffer_object, 'fbo-blit-scaled-linear')
 add_concurrent_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..a27ffbc
--- /dev/null
+++ b/tests/fbo/fbo-blit-after-swap.c
@@ -0,0 +1,125 @@
+/*
+ * Copyright 2013 Suse, Inc. 
+ * Copyright © 2011 Henri Verbeet <hverbeet at gmail.com>
+ * 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 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 void
+clear_to_color4fv(const GLfloat *color)
+{
+	glClearColor(color[0], color[1], color[2], color[3]);
+	glClear(GL_COLOR_BUFFER_BIT);
+}
+
+static void
+draw_rect_with_color4fv(const GLfloat *color, int x, int y, int w, int h)
+{
+	glColor4fv(color);
+	piglit_draw_rect(x, y, w, h);
+}
+
+static void
+blit_from_back_to_front(int x0, int y0, int x1, int y1)
+{
+	glDrawBuffer(GL_FRONT);
+	glReadBuffer(GL_BACK);
+	glBlitFramebufferEXT(x0, y0, x1, y1,
+			     x0, y0, x1, y1,
+			     GL_COLOR_BUFFER_BIT, GL_NEAREST);
+}
+
+static bool
+test_corner_and_center_colors(const GLfloat *corner, const GLfloat *center)
+{
+	int w = piglit_width;
+	int h = piglit_height;
+	bool pass = true;
+
+	glReadBuffer(GL_FRONT);
+	pass = pass && piglit_probe_pixel_rgb(0,     0,     corner);
+	pass = pass && piglit_probe_pixel_rgb(w - 1, 0,     corner);
+	pass = pass && piglit_probe_pixel_rgb(0,     h - 1, corner);
+	pass = pass && piglit_probe_pixel_rgb(w - 1, h - 1, corner);
+	pass = pass && piglit_probe_pixel_rgb(w / 2, h / 2, center);
+
+	return pass;
+}
+
+enum piglit_result piglit_display(void)
+{
+	int w = piglit_width;
+	int h = piglit_height;
+	bool pass = true;
+
+	piglit_ortho_projection(w, h, GL_FALSE);
+
+	glDrawBuffer(GL_BACK);
+
+	/* First, blue background, green square in the middle */
+
+	clear_to_color4fv(blue);
+	draw_rect_with_color4fv(green, w / 4, h /4, w / 2, h / 2);
+	piglit_swap_buffers();
+	glFlush();
+
+	pass = pass && test_corner_and_center_colors(blue, green);
+
+	/* Second, blue background, red square in the middle */
+
+	clear_to_color4fv(blue);
+	draw_rect_with_color4fv(red, w / 4, h /4, w / 2, h / 2);
+
+	/* Blit just the red square */
+	blit_from_back_to_front(w / 4, h / 4, w / 4 + w / 2, h / 4 + h / 2);
+	glFlush();
+
+	pass = pass && test_corner_and_center_colors(blue, red);
+	
+	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
+}
+
+void piglit_init(int argc, char **argv)
+{
+	piglit_require_extension("GL_EXT_framebuffer_object");
+	piglit_require_extension("GL_EXT_framebuffer_blit");
+}
-- 
1.8.4.5



More information about the Piglit mailing list