[Piglit] [PATCH v2] Test a front buffer corner case: invalidate causes data loss.
Paul Berry
stereotype441 at gmail.com
Fri May 31 13:49:41 PDT 2013
Cc: Eric Anholt <eric at anholt.net>
v2: Move to spec/gl-1.0. Add to all.tests.
---
tests/all.tests | 1 +
tests/spec/gl-1.0/CMakeLists.gl.txt | 1 +
tests/spec/gl-1.0/front-invalidate-back.c | 105 ++++++++++++++++++++++++++++++
3 files changed, 107 insertions(+)
create mode 100644 tests/spec/gl-1.0/front-invalidate-back.c
diff --git a/tests/all.tests b/tests/all.tests
index 417ca08..f490bb2 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -575,6 +575,7 @@ add_concurrent_test(gl10, 'gl-1.0-dlist-shademodel')
add_concurrent_test(gl10, 'gl-1.0-edgeflag')
add_concurrent_test(gl10, 'gl-1.0-edgeflag-quads')
add_concurrent_test(gl10, 'gl-1.0-rendermode-feedback')
+add_plain_test(gl10, 'gl-1.0-front-invalidate-back')
gl12 = Group()
spec['!OpenGL 1.2'] = gl12
diff --git a/tests/spec/gl-1.0/CMakeLists.gl.txt b/tests/spec/gl-1.0/CMakeLists.gl.txt
index 8d3111c..d0107f0 100644
--- a/tests/spec/gl-1.0/CMakeLists.gl.txt
+++ b/tests/spec/gl-1.0/CMakeLists.gl.txt
@@ -14,6 +14,7 @@ piglit_add_executable (gl-1.0-edgeflag edgeflag.c)
piglit_add_executable (gl-1.0-edgeflag-quads edgeflag-quads.c)
piglit_add_executable (gl-1.0-dlist-beginend dlist-beginend.c)
piglit_add_executable (gl-1.0-dlist-shademodel dlist-shademodel.c)
+piglit_add_executable (gl-1.0-front-invalidate-back front-invalidate-back.c)
piglit_add_executable (gl-1.0-rendermode-feedback rendermode-feedback.c)
# vim: ft=cmake:
diff --git a/tests/spec/gl-1.0/front-invalidate-back.c b/tests/spec/gl-1.0/front-invalidate-back.c
new file mode 100644
index 0000000..ffca1c7
--- /dev/null
+++ b/tests/spec/gl-1.0/front-invalidate-back.c
@@ -0,0 +1,105 @@
+/*
+ * Copyright © 2013 Intel Corporation
+ *
+ * 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-front-invalidate-back.c
+ *
+ * This test validates a corner case in the Intel mesa driver: if GL
+ * calls that require access to the front buffer are followed by GL
+ * calls that don't require access to the front buffer, and an
+ * invalidate event is received from the server in between, then
+ * before the driver responds to the invalidate event by requesting a
+ * new back buffer, it needs to flush the pending front buffer
+ * rendering. Otherwise the front buffer rendering will be lost.
+ *
+ * Unfortunately, we can't force the server to send an invalidate
+ * event to the driver at a specific time; however, thanks to a quirk
+ * in the driver, we can simulate one using a sequence of
+ * glDrawBuffer() calls.
+ */
+
+#include "piglit-util-gl-common.h"
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+ config.supports_gl_compat_version = 10;
+
+ config.window_width = 128;
+ config.window_height = 128;
+ config.requires_displayed_window = true;
+ config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGB;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+void
+piglit_init(int argc, char **argv)
+{
+}
+
+enum piglit_result
+piglit_display(void)
+{
+ const float green[] = {0.0f, 1.0f, 0.0f};
+ bool pass;
+
+ /* Do some rendering that requires access to the front buffer
+ * (clear it to green).
+ */
+ glDrawBuffer(GL_FRONT);
+ glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ /* Simulate an invalidate event using a sequence of
+ * glDrawBuffer() calls. This takes advantage of a quirk of
+ * the Intel driver: when glDrawBuffer() is used to switch
+ * from back buffer to front buffer rendering, the driver acts
+ * as though a buffer invalidate event has occurred, so that
+ * when the next draw operation occurs, it will be sure to
+ * pick up a valid front buffer. Therefore, we can simulate
+ * an invalidate event by switching to GL_BACK and then to
+ * GL_FRONT again.
+ */
+ glDrawBuffer(GL_BACK);
+ glDrawBuffer(GL_FRONT);
+
+ /* Do some rendering that doesn't require access to the front
+ * buffer (clear the back buffer to red). Note:
+ * gl_ReadBuffer(GL_BACK) ensures that the driver doesn't try
+ * to maintain access to the front buffer.
+ */
+ glReadBuffer(GL_BACK);
+ glDrawBuffer(GL_BACK);
+ glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ /* Check that the front buffer rendering was not lost. */
+ glReadBuffer(GL_FRONT);
+ pass = piglit_probe_rect_rgb(0, 0, piglit_width, piglit_height,
+ green);
+
+ /* Since we don't do a buffer swap, flush to make sure
+ * rendering gets to the screen.
+ */
+ glFlush();
+
+ return pass ? PIGLIT_PASS : PIGLIT_FAIL;
+}
--
1.8.3
More information about the Piglit
mailing list