[Piglit] [PATCH] fbo-readpixels-oob: Add a glReadPixels out-of-bounds test

Nanley Chery nanleychery at gmail.com
Fri Feb 12 22:24:43 UTC 2016


From: Nanley Chery <nanley.g.chery at intel.com>

Test that glReadPixels for an area which reaches out of bounds
behaves like a glReadPixels into a subrectangle for the valid area.
This behaviour reduces the number of corner cases associated with
this function.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=92193

Signed-off-by: Nanley Chery <nanley.g.chery at intel.com>
---
 tests/all.py                   |   1 +
 tests/fbo/CMakeLists.gl.txt    |   1 +
 tests/fbo/fbo-readpixels-oob.c | 122 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 124 insertions(+)
 create mode 100644 tests/fbo/fbo-readpixels-oob.c

diff --git a/tests/all.py b/tests/all.py
index 89288a2..71addfc 100644
--- a/tests/all.py
+++ b/tests/all.py
@@ -2987,6 +2987,7 @@ with profile.group_manager(
     g(['fbo-nodepth-test'])
     g(['fbo-nostencil-test'])
     g(['fbo-readpixels'])
+    g(['fbo-readpixels-oob'])
     g(['fbo-readpixels-depth-formats'])
     g(['fbo-scissor-bitmap'])
     g(['fbo-storage-completeness'])
diff --git a/tests/fbo/CMakeLists.gl.txt b/tests/fbo/CMakeLists.gl.txt
index 0476b10..6a33af8 100644
--- a/tests/fbo/CMakeLists.gl.txt
+++ b/tests/fbo/CMakeLists.gl.txt
@@ -77,6 +77,7 @@ piglit_add_executable (fbo-mrt-new-bind fbo-mrt-new-bind.c)
 piglit_add_executable (fbo-nodepth-test fbo-nodepth-test.c)
 piglit_add_executable (fbo-nostencil-test fbo-nostencil-test.c)
 piglit_add_executable (fbo-readpixels fbo-readpixels.c)
+piglit_add_executable (fbo-readpixels-oob fbo-readpixels-oob.c)
 piglit_add_executable (fbo-readpixels-depth-formats fbo-readpixels-depth-formats.c)
 piglit_add_executable (fbo-rg fbo-rg.c)
 piglit_add_executable (fbo-scissor-blit fbo-scissor-blit.c)
diff --git a/tests/fbo/fbo-readpixels-oob.c b/tests/fbo/fbo-readpixels-oob.c
new file mode 100644
index 0000000..19d4dd4
--- /dev/null
+++ b/tests/fbo/fbo-readpixels-oob.c
@@ -0,0 +1,122 @@
+/*
+ * Copyright © 2016 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-readpixels-oob.c
+ *
+ * Test that requesting an area larger than the readbuffer (with
+ * glReadPixels) will only modify the valid area in the user's buffer.
+ * This is equivalent to a user requesting to read into a sub-rectangle
+ * of the larger rectangle contained in the provided buffer (via
+ * PACK_ROW_LENGTH, PACK_SKIP_ROWS, PACK_SKIP_PIXELS).
+ *
+ * This behaviour ensures that Mesa does as little work as possible in
+ * this imprecise usage of glReadpixels. It also reduces the bugs that
+ * may occur with this special case by converting it to an analogous
+ * common case.
+ *
+ */
+
+#include "piglit-util-gl.h"
+
+#define BUF_WIDTH 64
+#define BUF_HEIGHT 64
+#define BIG_MULT 4
+#define BIG_BUF_WIDTH (BIG_MULT * BUF_WIDTH)
+#define BIG_BUF_HEIGHT (BIG_MULT * BUF_HEIGHT)
+
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+	config.supports_gl_compat_version = 10;
+	config.window_width = BUF_WIDTH;
+	config.window_height = BUF_HEIGHT;
+	config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGBA;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+static GLboolean
+test_with_format(GLenum internal_format, GLenum format,
+		 float results_x, float results_y)
+{
+	GLboolean pass = GL_TRUE;
+	int x, y;
+	int i;
+
+	/* Allocate into an oversized buffer. We'll check that the contents
+	 * are still 0 after the glReadPixels.
+	 */
+	const size_t num_chan = 4;
+	const size_t tot_elements = BIG_BUF_HEIGHT * BIG_BUF_WIDTH * num_chan;
+	GLubyte * black_img = (GLubyte*)calloc(tot_elements, sizeof(GLubyte));
+	GLfloat * black_imgf = (GLfloat*)malloc(tot_elements *sizeof(GLfloat));
+
+	/* Clear background to purple */
+	glClearColor(1.0, 0.0, 1.0, 0.0);
+	glClear(GL_COLOR_BUFFER_BIT);
+
+	/* Perform over-sized glReadPixels. Read the readbuffer as
+	 * GLubytes in order to hit most HW fast-paths.
+	 */
+	glReadPixels(0, 0, BIG_BUF_WIDTH, BIG_BUF_HEIGHT, GL_RGBA,
+			GL_UNSIGNED_BYTE, black_img);
+
+	/* Convert values to float in order to use utility comparison function.
+	 */
+	for (i = 0; i < tot_elements; i++)
+		black_imgf[i] = black_img[i] / 255.0;
+
+	/* Confirm the result */
+	for (y = 0; y < BIG_BUF_HEIGHT; y++) {
+		for (x = 0; x < BIG_BUF_WIDTH; x++) {
+			static const GLfloat valid_pixel[4] = {1.0, 0, 1.0, 0};
+			static const GLfloat invalid_pixel[4] = {0};
+			const unsigned index = y * BIG_BUF_WIDTH * num_chan +
+						x * num_chan;
+			const GLfloat * expected_pixel =
+					(x < BUF_WIDTH && y < BUF_HEIGHT) ?
+						valid_pixel : invalid_pixel;
+
+			pass &= piglit_compare_pixels(x, y, expected_pixel,
+						      black_imgf + index,
+						      piglit_tolerance,
+						      num_chan);
+			if (!pass)
+				return GL_FALSE;
+		}
+	}
+
+	return pass;
+}
+
+enum piglit_result
+piglit_display(void)
+{
+	GLboolean pass = test_with_format(GL_RGBA8, GL_BGRA, 0, 0);
+	piglit_present_results();
+	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
+}
+
+void piglit_init(int argc, char **argv)
+{
+}
-- 
2.7.1



More information about the Piglit mailing list