[Piglit] [PATCH] Add test case to verify texture borders are handled properly

Anuj Phogat anuj.phogat at gmail.com
Wed Feb 29 19:03:17 PST 2012


Each texture target is tested with and with out border. Test queries the
texture dimensions, border size etc. and compare against the expected
values.

This test verfies recently posted patches about texture border on mesa-dev.

Signed-off-by: Anuj Phogat <anuj.phogat at gmail.com>
---
 tests/all.tests                   |    1 +
 tests/texturing/CMakeLists.gl.txt |    1 +
 tests/texturing/texture-border.c  |  287 +++++++++++++++++++++++++++++++++++++
 3 files changed, 289 insertions(+), 0 deletions(-)
 create mode 100644 tests/texturing/texture-border.c

diff --git a/tests/all.tests b/tests/all.tests
index e4d56b8..750d994 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -705,6 +705,7 @@ add_plain_test(texturing, 'texrect-many')
 add_plain_test(texturing, 'texredefine')
 add_plain_test(texturing, 'texsubimage')
 add_plain_test(texturing, 'texture-al')
+add_plain_test(texturing, 'texture-border')
 add_plain_test(texturing, 'texture-integer')
 add_plain_test(texturing, 'texture-packed-formats')
 add_plain_test(texturing, 'texture-rg')
diff --git a/tests/texturing/CMakeLists.gl.txt b/tests/texturing/CMakeLists.gl.txt
index 6e12cc0..bf9e1ff 100644
--- a/tests/texturing/CMakeLists.gl.txt
+++ b/tests/texturing/CMakeLists.gl.txt
@@ -65,6 +65,7 @@ add_executable (texrect-many texrect-many.c)
 add_executable (texredefine texredefine.c)
 add_executable (texture-packed-formats texture-packed-formats.c)
 add_executable (texture-integer texture-integer.c)
+add_executable (texture-border texture-border.c)
 add_executable (depth-tex-modes      depth-tex-modes.c depth-tex-modes-common.c)
 add_executable (depth-tex-modes-rg   depth-tex-modes-rg.c depth-tex-modes-common.c)
 add_executable (depth-tex-modes-glsl depth-tex-modes-glsl.c)
diff --git a/tests/texturing/texture-border.c b/tests/texturing/texture-border.c
new file mode 100644
index 0000000..a566699
--- /dev/null
+++ b/tests/texturing/texture-border.c
@@ -0,0 +1,287 @@
+/* Copyright © 2012 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 texture-border.c
+ * Verify that large textures are handled correctly in mesa driver
+ *
+ * This test works by calling glTexImage1D/2D/3D  functions with all possible
+ * texture targets. Each texture target is tested with and with out border.
+ * Test queries the dimensions and border size and compare against the expected
+ * values.
+ *
+ * This test case reproduces the errors reported in:
+ * 1. https://bugs.freedesktop.org/show_bug.cgi?id=44970
+ *    Use GL_TEXTURE_2D and GL_RGBA16
+ *
+ * \Author Anuj Phogat <anuj.phogat at gmail.com>
+ */
+
+#include "piglit-util.h"
+#define STRIP_TEXTURE_BORDER_HACK
+
+int piglit_width = 100, piglit_height = 100;
+int piglit_window_mode = GLUT_RGBA | GLUT_DOUBLE;
+
+static const struct {
+	GLenum target;
+	GLint width;
+	GLint height;
+	GLint depth;
+	GLint border;
+} test_vectors[] = {
+	/* Texture target			width, height, depth, border */
+	{ GL_TEXTURE_1D,			512,	1,	1,	0 },
+	{ GL_TEXTURE_1D_ARRAY,			512,	128,	1,	0 },
+	{ GL_TEXTURE_2D,			256,	130,	1,	0 },
+	{ GL_TEXTURE_RECTANGLE,			256,	128,	1,	0 },
+	{ GL_TEXTURE_CUBE_MAP_POSITIVE_X,	64,	64,	1,	0 },
+	{ GL_TEXTURE_CUBE_MAP_NEGATIVE_X,	64,	64,	1,	0 },
+	{ GL_TEXTURE_CUBE_MAP_POSITIVE_Y,	64,	64,	1,	0 },
+	{ GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,	64,	64,	1,	0 },
+	{ GL_TEXTURE_CUBE_MAP_POSITIVE_Z,	64,	64,	1,	0 },
+	{ GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,	64,	64,	1,	0 },
+	{ GL_TEXTURE_2D_ARRAY,			45,	60,	64,	0 },
+	{ GL_TEXTURE_3D,			64,	32,	16,	0 },
+
+	{ GL_TEXTURE_1D,			256,	1,	1,	1 },
+	{ GL_TEXTURE_1D_ARRAY,			512,	512,	1,	1 },
+	{ GL_TEXTURE_2D,			120,	250,	1,	1 },
+	{ GL_TEXTURE_CUBE_MAP_POSITIVE_X,	64,	64,	1,	1 },
+	{ GL_TEXTURE_CUBE_MAP_NEGATIVE_X,	64,	64,	1,	1 },
+	{ GL_TEXTURE_CUBE_MAP_POSITIVE_Y,	64,	64,	1,	1 },
+	{ GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,	64,	64,	1,	1 },
+	{ GL_TEXTURE_CUBE_MAP_POSITIVE_Z,	64,	64,	1,	1 },
+	{ GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,	64,	64,	1,	1 },
+	{ GL_TEXTURE_2D_ARRAY,			46,	64,	14,	1 },
+	{ GL_TEXTURE_3D,			64,	46,	4,	1 },
+};
+
+static GLenum
+getProxyTarget(GLenum target)
+{
+	switch(target) {
+	case GL_TEXTURE_1D:
+		return GL_PROXY_TEXTURE_1D;
+	case GL_TEXTURE_1D_ARRAY:
+		return GL_PROXY_TEXTURE_1D_ARRAY;
+	case GL_TEXTURE_2D:
+		return GL_PROXY_TEXTURE_2D;
+	case GL_TEXTURE_2D_ARRAY:
+		return GL_PROXY_TEXTURE_2D_ARRAY;
+	case GL_TEXTURE_3D:
+		return GL_PROXY_TEXTURE_3D;
+	case GL_TEXTURE_CUBE_MAP:
+	case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
+	case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
+	case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
+	case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
+	case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
+	case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
+		return GL_PROXY_TEXTURE_CUBE_MAP;
+	case GL_TEXTURE_RECTANGLE:
+		return GL_PROXY_TEXTURE_RECTANGLE;
+	default:
+		printf ("No proxy target for this texture target\n");
+		return 0;
+	}
+}
+static GLboolean
+validateTexBorder(GLenum target,  GLint width, GLint height, GLint depth,
+		  GLint border)
+{
+	int  texWidth, texHeight, texDepth, texBorder;
+
+	switch (target) {
+	case GL_TEXTURE_1D:
+	case GL_PROXY_TEXTURE_1D:
+		glTexImage1D(target, 0,
+			     GL_RGBA, width, border,
+			     GL_RGBA, GL_FLOAT, NULL);
+		break;
+
+	case GL_TEXTURE_1D_ARRAY:
+	case GL_TEXTURE_RECTANGLE:
+	case GL_TEXTURE_2D:
+	case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
+	case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
+	case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
+	case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
+	case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
+	case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
+	case GL_PROXY_TEXTURE_1D_ARRAY:
+	case GL_PROXY_TEXTURE_RECTANGLE:
+	case GL_PROXY_TEXTURE_2D:
+	case GL_PROXY_TEXTURE_CUBE_MAP:
+		glTexImage2D(target, 0,
+			     GL_RGBA, width, height, border,
+			     GL_RGBA, GL_FLOAT, NULL);
+		break;
+
+	case GL_TEXTURE_2D_ARRAY:
+	case GL_TEXTURE_3D:
+	case GL_PROXY_TEXTURE_2D_ARRAY:
+	case GL_PROXY_TEXTURE_3D:
+		glTexImage3D(target, 0,
+			     GL_RGBA, width, height,
+			     depth, border, GL_RGBA, GL_FLOAT, NULL);
+		break;
+	}
+	if(!piglit_check_gl_error(GL_NO_ERROR))
+		return false;
+
+	glGetTexLevelParameteriv(target, 0, GL_TEXTURE_WIDTH, &texWidth);
+	glGetTexLevelParameteriv(target, 0, GL_TEXTURE_HEIGHT, &texHeight);
+	glGetTexLevelParameteriv(target, 0, GL_TEXTURE_DEPTH, &texDepth);
+	glGetTexLevelParameteriv(target, 0, GL_TEXTURE_BORDER, &texBorder);
+
+	if(!piglit_check_gl_error(GL_NO_ERROR))
+		return false;
+
+#ifdef STRIP_TEXTURE_BORDER_HACK
+	/* Intel and Gallium drivers don't support texture borders. Border
+	 * is stripped before texture is used inside the driver. Below hack
+	 * allows texture-border test case to pass with these drivers.
+	 */
+	switch(target) {
+	case GL_TEXTURE_1D:
+	case GL_PROXY_TEXTURE_1D:
+	case GL_TEXTURE_1D_ARRAY:
+	case GL_PROXY_TEXTURE_1D_ARRAY:
+		if (texWidth == width - 2 * border && texHeight == height &&
+		    texDepth == depth && texBorder == 0)
+			return true;
+		 break;
+	case GL_TEXTURE_2D:
+	case GL_TEXTURE_RECTANGLE:
+	case GL_TEXTURE_CUBE_MAP:
+	case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
+	case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
+	case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
+	case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
+	case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
+	case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
+	case GL_PROXY_TEXTURE_2D:
+	case GL_PROXY_TEXTURE_RECTANGLE:
+	case GL_PROXY_TEXTURE_CUBE_MAP:
+	case GL_TEXTURE_2D_ARRAY:
+	case GL_PROXY_TEXTURE_2D_ARRAY:
+		if (texWidth == width - 2 * border &&
+		    texHeight == height - 2 * border &&
+		    texDepth == depth && texBorder == 0)
+			return true;
+		break;
+	case GL_TEXTURE_3D:
+	case GL_PROXY_TEXTURE_3D:
+		if (texWidth == (width - 2 * border) &&
+		    texHeight == (height - 2 * border) &&
+		    texDepth == (depth - 2 * border) &&
+		    texBorder == 0)
+			return true;
+		break;
+	default:
+		printf("Invalid texture target\n");
+	}
+#else
+	/* For the drivers which support texture border */
+	if (texWidth == width && texHeight == height &&
+		texDepth == depth && texBorder == border)
+		return true;
+#endif
+	/* If execution reaches here, print debug information for failed case
+	 * and return false
+	 */
+	printf("%s\nwidth = %d,\ttexWidth= %d,\theight = %d,"
+	       "\ttexHeight = %d\tdepth = %d,\ttexDepth= %d,"
+	       "\tborder= %d,\ttexBorder = %d\n",
+	       piglit_get_gl_enum_name(target), width, texWidth,
+	       height, texHeight, depth, texDepth, border, texBorder);
+	return false;
+}
+
+void piglit_init(int argc, char **argv)
+{
+	GLuint tex;
+	int i;
+	GLboolean pass = true;
+
+	glMatrixMode(GL_PROJECTION);
+	glPushMatrix();
+	glLoadIdentity();
+	glOrtho(0, piglit_width, 0, piglit_height, -1, 1);
+	glMatrixMode(GL_MODELVIEW);
+	glPushMatrix();
+	glLoadIdentity();
+	glClearColor(0.2, 0.2, 0.2, 1.0);
+	glClear(GL_COLOR_BUFFER_BIT);
+
+	/* Test with all the texture targets listed in test_vectors */
+	for ( i = 0; i < ARRAY_SIZE(test_vectors); i++) {
+		glGenTextures(1, &tex);
+		if(test_vectors[i].target == GL_TEXTURE_CUBE_MAP_POSITIVE_X ||
+		   test_vectors[i].target == GL_TEXTURE_CUBE_MAP_NEGATIVE_X ||
+		   test_vectors[i].target == GL_TEXTURE_CUBE_MAP_POSITIVE_Y ||
+		   test_vectors[i].target == GL_TEXTURE_CUBE_MAP_NEGATIVE_Y ||
+		   test_vectors[i].target == GL_TEXTURE_CUBE_MAP_POSITIVE_Z ||
+		   test_vectors[i].target == GL_TEXTURE_CUBE_MAP_NEGATIVE_Z)
+			glBindTexture(GL_TEXTURE_CUBE_MAP, tex);
+		else
+			glBindTexture(test_vectors[i].target, tex);
+
+		pass = validateTexBorder (test_vectors[i].target,
+					  test_vectors[i].width,
+					  test_vectors[i].height,
+					  test_vectors[i].depth,
+					  test_vectors[i].border)
+		       && pass;
+		glDeleteTextures(1, &tex);
+	}
+	/* Test with proxy texture targets */
+	for ( i = 0; i < ARRAY_SIZE(test_vectors); i++) {
+		glGenTextures(1, &tex);
+		if(test_vectors[i].target == GL_TEXTURE_CUBE_MAP_POSITIVE_X ||
+		   test_vectors[i].target == GL_TEXTURE_CUBE_MAP_NEGATIVE_X ||
+		   test_vectors[i].target == GL_TEXTURE_CUBE_MAP_POSITIVE_Y ||
+		   test_vectors[i].target == GL_TEXTURE_CUBE_MAP_NEGATIVE_Y ||
+		   test_vectors[i].target == GL_TEXTURE_CUBE_MAP_POSITIVE_Z ||
+		   test_vectors[i].target == GL_TEXTURE_CUBE_MAP_NEGATIVE_Z)
+			glBindTexture(GL_TEXTURE_CUBE_MAP, tex);
+		else
+			glBindTexture(test_vectors[i].target, tex);
+
+		pass = validateTexBorder(getProxyTarget(test_vectors[i].target),
+					 test_vectors[i].width,
+					 test_vectors[i].height,
+					 test_vectors[i].depth,
+					 test_vectors[i].border)
+		       && pass;
+		glDeleteTextures(1, &tex);
+	}
+
+	piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
+}
+
+enum piglit_result
+piglit_display(void)
+{
+	return PIGLIT_FAIL;
+}
-- 
1.7.7.6



More information about the Piglit mailing list