[Piglit] [PATCH 3/3] Test a front buffer corner case: invalidate causes data loss.

Paul Berry stereotype441 at gmail.com
Fri May 31 12:50:10 PDT 2013


Cc: Eric Anholt <eric at anholt.net>
---
 tests/fbo/CMakeLists.gl.txt           |   1 +
 tests/fbo/fbo-front-invalidate-back.c | 105 ++++++++++++++++++++++++++++++++++
 2 files changed, 106 insertions(+)
 create mode 100644 tests/fbo/fbo-front-invalidate-back.c

diff --git a/tests/fbo/CMakeLists.gl.txt b/tests/fbo/CMakeLists.gl.txt
index cf2a268..217715d 100644
--- a/tests/fbo/CMakeLists.gl.txt
+++ b/tests/fbo/CMakeLists.gl.txt
@@ -53,6 +53,7 @@ piglit_add_executable (fbo-flushing fbo-flushing.c)
 piglit_add_executable (fbo-flushing-2 fbo-flushing-2.c)
 piglit_add_executable (fbo-fragcoord fbo-fragcoord.c)
 piglit_add_executable (fbo-fragcoord2 fbo-fragcoord2.c)
+piglit_add_executable (fbo-front-invalidate-back fbo-front-invalidate-back.c)
 piglit_add_executable (fbo-generatemipmap fbo-generatemipmap.c)
 piglit_add_executable (fbo-generatemipmap-array fbo-generatemipmap-array.c)
 piglit_add_executable (fbo-generatemipmap-filtering fbo-generatemipmap-filtering.c)
diff --git a/tests/fbo/fbo-front-invalidate-back.c b/tests/fbo/fbo-front-invalidate-back.c
new file mode 100644
index 0000000..ffca1c7
--- /dev/null
+++ b/tests/fbo/fbo-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