Add a test for glTexImage2D + PBO + small offset

Submitted by Cody Northrop on Sept. 15, 2014, 10:04 p.m.

Details

Message ID 1410818691-17520-1-git-send-email-cody@lunarg.com
State New
Headers show

Not browsing as part of any series.

Commit Message

Cody Northrop Sept. 15, 2014, 10:04 p.m.
This test is based on pbo-teximage, but adds a small offset to
test whether a driver can handle offsets that are not naturally
aligned to pixel boundaries.

The test is inspired by a bug seen in Steam Big Picture mode.

It will fail on i965 as of submission, but will pass once the fix
is committed.

Signed-off-by: Cody Northrop <cody@lunarg.com>
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=83908
---
 tests/all.py                                 |   1 +
 tests/general/CMakeLists.gl.txt              |   1 +
 tests/general/pbo-teximage-pixel-alignment.c | 126 +++++++++++++++++++++++++++
 3 files changed, 128 insertions(+)
 create mode 100644 tests/general/pbo-teximage-pixel-alignment.c

Patch hide | download patch | download mbox

diff --git a/tests/all.py b/tests/all.py
index f7ee734..8b84d27 100644
--- a/tests/all.py
+++ b/tests/all.py
@@ -2042,6 +2042,7 @@  add_plain_test(arb_pixel_buffer_object, 'pbo-drawpixels')
 add_plain_test(arb_pixel_buffer_object, 'pbo-read-argb8888')
 add_plain_test(arb_pixel_buffer_object, 'pbo-readpixels-small')
 add_plain_test(arb_pixel_buffer_object, 'pbo-teximage')
+add_plain_test(arb_pixel_buffer_object, 'pbo-teximage-pixel-alignment')
 add_plain_test(arb_pixel_buffer_object, 'pbo-teximage-tiling')
 add_plain_test(arb_pixel_buffer_object, 'pbo-teximage-tiling-2')
 
diff --git a/tests/general/CMakeLists.gl.txt b/tests/general/CMakeLists.gl.txt
index 5917df2..3165eca 100644
--- a/tests/general/CMakeLists.gl.txt
+++ b/tests/general/CMakeLists.gl.txt
@@ -82,6 +82,7 @@  piglit_add_executable (pbo-drawpixels pbo-drawpixels.c)
 piglit_add_executable (pbo-read-argb8888 pbo-read-argb8888.c)
 piglit_add_executable (pbo-readpixels-small pbo-readpixels-small.c)
 piglit_add_executable (pbo-teximage pbo-teximage.c)
+piglit_add_executable (pbo-teximage-pixel-alignment pbo-teximage-pixel-alignment.c)
 piglit_add_executable (pbo-teximage-tiling pbo-teximage-tiling.c)
 piglit_add_executable (pbo-teximage-tiling-2 pbo-teximage-tiling-2.c)
 piglit_add_executable (point-line-no-cull point-line-no-cull.c)
diff --git a/tests/general/pbo-teximage-pixel-alignment.c b/tests/general/pbo-teximage-pixel-alignment.c
new file mode 100644
index 0000000..f710641
--- /dev/null
+++ b/tests/general/pbo-teximage-pixel-alignment.c
@@ -0,0 +1,126 @@ 
+/*
+ * Copyright © 2009 Intel Corporation
+ * Copyright © 2014 LunarG, 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.
+ *
+ * Authors:
+ *    Eric Anholt <eric@anholt.net>
+ *    Cody Northrop <cody@lunarg.com>
+ *
+ */
+
+/** @file pbo-teximage-pixel-alignment.c
+ *
+ * Tests that using a PBO as the unpack buffer for glTexImage2D works correctly
+ * if given an offset that is not pixel aligned.
+ *
+ * This test is based on pbo-teximage, with primary differences being texture
+ * format and pixel offset.
+ */
+
+#include "piglit-util-gl.h"
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+	config.supports_gl_compat_version = 10;
+
+	config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+enum piglit_result
+piglit_display(void)
+{
+	GLboolean pass = GL_TRUE;
+	static float fRed[]   = {1.0, 0.0, 0.0, 0.0};
+	static float fGreen[] = {0.0, 1.0, 0.0, 0.0};
+	static float fBlue[]  = {0.0, 0.0, 1.0, 0.0};
+	GLuint pbo, tex;
+
+	static char red[]   = {0xFF, 0x00, 0x00, 0x00};
+	static char green[] = {0x00, 0xFF, 0x00, 0x00};
+	static char blue[]  = {0x00, 0x00, 0xFF, 0x00};
+	char *pixels;
+
+	/* The following offset is not naturally aligned to pixel size */
+	const int offset = 3;
+
+	glClearColor(0.5, 0.5, 0.5, 0.0);
+	glClear(GL_COLOR_BUFFER_BIT);
+
+	glGenBuffersARB(1, &pbo);
+	glBindBufferARB(GL_PIXEL_UNPACK_BUFFER, pbo);
+	glBufferDataARB(GL_PIXEL_UNPACK_BUFFER, (4 * 4 + offset) * sizeof(char),
+			NULL, GL_STREAM_DRAW_ARB);
+	pixels = glMapBufferARB(GL_PIXEL_UNPACK_BUFFER, GL_WRITE_ONLY_ARB);
+
+	memcpy(pixels + 0 + offset,  red,   sizeof(red));
+	memcpy(pixels + 4 + offset,  green, sizeof(green));
+	memcpy(pixels + 8 + offset,  blue,  sizeof(blue));
+	memcpy(pixels + 12 + offset, red,   sizeof(red));
+
+	glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER);
+	glGenTextures(1, &tex);
+	glBindTexture(GL_TEXTURE_2D, tex);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+	glTexImage2D(GL_TEXTURE_2D, 0,
+		     GL_RGBA,
+		     2, 2, 0,
+		     GL_RGBA, GL_UNSIGNED_BYTE, (const void *)(offset * sizeof(char)));
+	glBindBufferARB(GL_PIXEL_UNPACK_BUFFER, 0);
+	glDeleteBuffersARB(1, &pbo);
+
+	glEnable(GL_TEXTURE_2D);
+	glBegin(GL_TRIANGLE_FAN);
+	glTexCoord2f(0.0, 0.0); glVertex2f(10, 10);
+	glTexCoord2f(1.0, 0.0); glVertex2f(20, 10);
+	glTexCoord2f(1.0, 1.0); glVertex2f(20, 20);
+	glTexCoord2f(0.0, 1.0); glVertex2f(10, 20);
+	glEnd();
+
+	glDeleteTextures(1, &tex);
+
+	pass &= piglit_probe_pixel_rgb(12, 12, fRed);
+	pass &= piglit_probe_pixel_rgb(18, 12, fGreen);
+	pass &= piglit_probe_pixel_rgb(12, 18, fBlue);
+	pass &= piglit_probe_pixel_rgb(18, 18, fRed);
+
+	piglit_present_results();
+
+	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
+}
+
+
+static void reshape(int width, int height)
+{
+	piglit_width = width;
+	piglit_height = height;
+
+	piglit_ortho_projection(width, height, GL_FALSE);
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+	reshape(piglit_width, piglit_height);
+	piglit_require_extension("GL_ARB_pixel_buffer_object");
+}