[Piglit] [PATCH] ext_texture_array-gen-mipmap: test texture array mipmap generation

Brian Paul brianp at vmware.com
Wed Jul 24 08:29:33 PDT 2013


Test compressed formats too, to check for a Mesa bug.
---
 tests/all.tests                                |    1 +
 tests/spec/ext_texture_array/CMakeLists.gl.txt |    1 +
 tests/spec/ext_texture_array/gen-mipmap.c      |  137 ++++++++++++++++++++++++
 3 files changed, 139 insertions(+)
 create mode 100644 tests/spec/ext_texture_array/gen-mipmap.c

diff --git a/tests/all.tests b/tests/all.tests
index 2a5fbd0..e4e7f31 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -1757,6 +1757,7 @@ ext_texture_array = Group()
 spec['EXT_texture_array'] = ext_texture_array
 add_plain_test(ext_texture_array, 'fbo-generatemipmap-array')
 spec['EXT_texture_array']['maxlayers'] = concurrent_test('ext_texture_array-maxlayers')
+spec['EXT_texture_array']['gen-mipmap'] = concurrent_test('ext_texture_array-gen-mipmap')
 add_shader_test_dir(ext_texture_array,
                     testsDir + '/spec/ext_texture_array',
                     recursive=True)
diff --git a/tests/spec/ext_texture_array/CMakeLists.gl.txt b/tests/spec/ext_texture_array/CMakeLists.gl.txt
index 5b10962..048e0d3 100644
--- a/tests/spec/ext_texture_array/CMakeLists.gl.txt
+++ b/tests/spec/ext_texture_array/CMakeLists.gl.txt
@@ -11,3 +11,4 @@ link_libraries (
 
 piglit_add_executable (ext_texture_array-maxlayers maxlayers.c)
 piglit_add_executable (ext_texture_array-compressed compressed.c)
+piglit_add_executable (ext_texture_array-gen-mipmap gen-mipmap.c)
diff --git a/tests/spec/ext_texture_array/gen-mipmap.c b/tests/spec/ext_texture_array/gen-mipmap.c
new file mode 100644
index 0000000..f0a306f
--- /dev/null
+++ b/tests/spec/ext_texture_array/gen-mipmap.c
@@ -0,0 +1,137 @@
+/*
+ * Copyright (c) 2013 VMware, Inc.
+ *
+ * Permission is hereby, 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.
+ */
+
+/**
+ * Test glGenerateMipmaps with a texture array.
+ * In particular, test with texture compression to expose a Mesa bug.
+ * See https://bugs.freedesktop.org/show_bug.cgi?id=66850
+ *
+ * Brian Paul
+ * 24 July 2013
+ */
+
+
+#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_RGBA;
+PIGLIT_GL_TEST_CONFIG_END
+
+
+/* texture size */
+#define WIDTH 128
+#define HEIGHT 64
+#define DEPTH 3
+#define BPP 4  /* GL_RGBA/ubyte */
+
+
+static bool
+run_test(GLenum internalFormat)
+{
+	unsigned char *buf, *buf2;
+	int level;
+	GLuint tex;
+	bool pass = true;
+
+	buf = malloc(WIDTH * HEIGHT * DEPTH * BPP);
+	buf2 = malloc(WIDTH * HEIGHT * DEPTH * BPP);
+
+	/* Create 2D array texture */
+	memset(buf, 255, WIDTH * HEIGHT * DEPTH * BPP); /* white */
+	glGenTextures(1, &tex);
+	glBindTexture(GL_TEXTURE_2D_ARRAY, tex);
+	glTexImage3D(GL_TEXTURE_2D_ARRAY, 0,
+		     internalFormat,
+		     WIDTH, HEIGHT, DEPTH, 0,
+		     GL_RGBA, GL_UNSIGNED_BYTE,
+		     buf);
+
+	glGenerateMipmap(GL_TEXTURE_2D_ARRAY);
+
+	/* now read back texture images and test */
+	for (level = 0; (WIDTH >> level) > 0; level++) {
+		int x, y, z, level_size, row_len;
+
+		memset(buf2, 0, WIDTH * HEIGHT * DEPTH * BPP);
+
+		glGetTexImage(GL_TEXTURE_2D_ARRAY, level,
+			      GL_RGBA, GL_UNSIGNED_BYTE, buf2);
+
+		/* test center texel */
+		x = (WIDTH >> level) / 2;
+		y = (HEIGHT >> level) / 2;
+
+		level_size = (WIDTH >> level) * (HEIGHT >> level) * BPP;
+		row_len = (WIDTH >> level) * BPP;
+
+		for (z = 0; z < DEPTH; z++) {
+			int pos = z * level_size + y * row_len + x * BPP;
+
+			if (buf2[pos + 0] != 255 ||
+			    buf2[pos + 1] != 255 ||
+			    buf2[pos + 2] != 255 ||
+			    buf2[pos + 3] != 255) {
+				printf("Probe at level %d, x %d, y %d, z %d = "
+				       " (%u, %u, %u, %u),"
+				       " expected (255,255,255,255)\n",
+				       level, x, y, z,
+				       buf2[pos + 0],
+				       buf2[pos + 1],
+				       buf2[pos + 2],
+				       buf2[pos + 3]);
+				printf("Internal tex format %s\n",
+				       piglit_get_gl_enum_name(internalFormat));
+				pass = false;
+				break;
+			}
+		}
+	}
+
+	free(buf);
+	free(buf2);
+
+	return pass;
+}
+
+
+enum piglit_result
+piglit_display(void)
+{
+	bool pass = true;
+
+	pass = run_test(GL_RGBA) && pass;
+	if (piglit_is_extension_supported("GL_ARB_texture_compression")) {
+		pass = run_test(GL_COMPRESSED_RGBA) && pass;
+		pass = run_test(GL_COMPRESSED_RGB) && pass;
+	}
+
+	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
+}
+
+
+void
+piglit_init(int argc, char **argv)
+{
+	piglit_require_extension("GL_EXT_texture_array");
+}
-- 
1.7.10.4



More information about the Piglit mailing list