[Piglit] [PATCH] Add test case to verify large textures are handled correctly in mesa

Anuj Phogat anuj.phogat at gmail.com
Thu Feb 23 19:27:23 PST 2012


Intel driver throws GL_OUT_OF_MEMORY and assertion failure / segmentation
fault with large textures.

Reproduces the errors reported in:
https://bugs.freedesktop.org/show_bug.cgi?id=44970
https://bugs.freedesktop.org/show_bug.cgi?id=46303

Signed-off-by: Anuj Phogat <anuj.phogat at gmail.com>
---
V3: Added the test using proxy textures, deleted redundant code,
    data array allocation based on size returned

ToDo: getMaxTarget, getProxyTarget and isValidTexSize functions can be added
      as piglit utility functions in piglit-util-gl.c
      I will do it in a separate patch.

 tests/all.tests              |    1 +
 tests/bugs/CMakeLists.gl.txt |    1 +
 tests/bugs/large-textures.c  |  352 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 354 insertions(+), 0 deletions(-)
 create mode 100644 tests/bugs/large-textures.c

diff --git a/tests/all.tests b/tests/all.tests
index e4d56b8..d006e9a 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -569,6 +569,7 @@ add_plain_test(bugs, 'fdo24066')
 add_plain_test(bugs, 'fdo25614-genmipmap')
 add_plain_test(bugs, 'fdo28551')
 add_plain_test(bugs, 'fdo31934')
+add_plain_test(bugs, 'large-textures')
 add_plain_test(bugs, 'point-sprite')
 add_plain_test(bugs, 'r300-readcache')
 add_plain_test(bugs, 'tex1d-2dborder')
diff --git a/tests/bugs/CMakeLists.gl.txt b/tests/bugs/CMakeLists.gl.txt
index 5c1864e..8cdd4d0 100644
--- a/tests/bugs/CMakeLists.gl.txt
+++ b/tests/bugs/CMakeLists.gl.txt
@@ -32,6 +32,7 @@ add_executable (fdo24066 fdo24066.c)
 add_executable (fdo25614-genmipmap fdo25614-genmipmap.c)
 add_executable (fdo28551 fdo28551.c)
 add_executable (fdo31934 fdo31934.c)
+add_executable (large-textures large-textures.c)
 add_executable (tri-tex-crash tri-tex-crash.c)
 add_executable (vbo-buffer-unmap vbo-buffer-unmap.c)
 
diff --git a/tests/bugs/large-textures.c b/tests/bugs/large-textures.c
new file mode 100644
index 0000000..c43f51e
--- /dev/null
+++ b/tests/bugs/large-textures.c
@@ -0,0 +1,352 @@
+/* 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 large-textures.c
+ * Verify that large textures are handled correctly in mesa driver
+ *
+ * This test works by calling glTexImage1D/2D/3D and glTexSubImage1D/2D/3D
+ * functions with different texture targets. Each texture target is tested
+ * with large texture sizes. Some of which exceeds the largest supported
+ * texture size limit. All the calls to glTexImage2D() and glTexSubImage2D()
+ * should ensure no segmentation faults/assertion failures in mesa driver.
+ *
+ * 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
+ *
+ * 2. https://bugs.freedesktop.org/show_bug.cgi?id=46303
+ *
+ * \Author Anuj Phogat <anuj.phogat at gmail.com>
+ */
+
+#include "piglit-util.h"
+#define COLOR_COMPONENTS 4 /*GL_RGBA*/
+
+int piglit_width = 100, piglit_height = 100;
+int piglit_window_mode = GLUT_RGBA | GLUT_DOUBLE;
+
+GLenum target[] = {
+	GL_TEXTURE_1D,
+	GL_TEXTURE_2D,
+	GL_TEXTURE_CUBE_MAP,
+	GL_TEXTURE_3D,
+	};
+
+GLenum internalformat[] = {
+	GL_RGBA8,
+	GL_RGBA16,
+	GL_RGBA32F,
+	};
+
+GLenum getMaxTarget(GLenum target)
+{
+	switch(target) {
+	case GL_TEXTURE_1D:
+	case GL_TEXTURE_2D:
+		return GL_MAX_TEXTURE_SIZE;
+	case GL_TEXTURE_3D:
+		return GL_MAX_3D_TEXTURE_SIZE;
+	case GL_TEXTURE_CUBE_MAP_ARB:
+		return GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB;
+	case GL_TEXTURE_RECTANGLE:
+		return GL_MAX_RECTANGLE_TEXTURE_SIZE;
+	case GL_RENDERBUFFER_EXT:
+		return GL_MAX_RENDERBUFFER_SIZE_EXT;
+	default:
+		printf ("Invalid texture target\n");
+		return 0;
+	}
+}
+
+GLenum getProxyTarget(GLenum target)
+{
+	switch(target) {
+	case GL_TEXTURE_1D:
+		return GL_PROXY_TEXTURE_1D;
+	case GL_TEXTURE_2D:
+		return GL_PROXY_TEXTURE_2D;
+	case GL_TEXTURE_3D:
+		return GL_PROXY_TEXTURE_3D;
+	case GL_TEXTURE_CUBE_MAP:
+		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;
+	}
+}
+
+bool isValidTexSize(GLenum target, GLenum internalFormat, int sideLength)
+{
+	GLint texWidth;
+	GLenum proxyTarget = getProxyTarget(target);
+
+	switch(proxyTarget) {
+	case GL_PROXY_TEXTURE_1D:
+		glTexImage1D(proxyTarget, 0, internalFormat, sideLength, 0,
+			     GL_RGBA, GL_FLOAT, 0);
+		break;
+	case GL_PROXY_TEXTURE_2D:
+	case GL_PROXY_TEXTURE_RECTANGLE:
+	case GL_PROXY_TEXTURE_CUBE_MAP_ARB:
+		glTexImage2D(proxyTarget, 0, internalFormat, sideLength,
+			     sideLength, 0, GL_RGBA, GL_FLOAT, 0);
+		break;
+	case GL_PROXY_TEXTURE_3D:
+		glTexImage3D(proxyTarget, 0, internalFormat, sideLength,
+			     sideLength, sideLength, 0, GL_RGBA, GL_FLOAT, 0);
+		break;
+	default:
+		printf ("Invalid  proxy texture target");
+	}
+
+	glGetTexLevelParameteriv(proxyTarget, 0, GL_TEXTURE_WIDTH, &texWidth);
+	return texWidth == sideLength;
+}
+
+GLfloat * initTexData (GLenum target, int sideLength)
+{
+	uint64_t nPixels;
+	if (target == GL_TEXTURE_1D)
+		nPixels = (uint64_t)(sideLength + 2);
+	else if (target == GL_TEXTURE_2D ||
+		 target == GL_TEXTURE_CUBE_MAP)
+		nPixels = (uint64_t)(sideLength + 2) *
+			  (uint64_t)(sideLength + 2);
+	else if (target == GL_TEXTURE_3D)
+		nPixels = (uint64_t)(sideLength + 2) *
+			  (uint64_t)(sideLength + 2) *
+			  (uint64_t)(sideLength + 2);
+
+	/* Allocate sufficiently large data array and initialize to zero */
+	return ((GLfloat *) calloc(nPixels * COLOR_COMPONENTS, sizeof(float)));
+}
+
+void ValidateTexSize (GLenum target,  GLenum internalformat, bool proxy)
+{
+	int maxSide, side, k;
+	GLfloat *pixels = NULL;
+
+	/* Query the largest supported texture size */
+	glGetIntegerv(getMaxTarget(target), &maxSide);
+
+	if (!proxy) {
+		printf("%s, Internal Format = %s, Largest Texture Size ="
+		       " %d\n", piglit_get_gl_enum_name(target),
+		       piglit_get_gl_enum_name(internalformat),
+		       maxSide);
+		/* Allocate and initialize texture data array */
+		pixels = initTexData(target, maxSide);
+
+		if ( pixels == NULL) {
+			printf("Error allocating texture data array\n");
+			piglit_report_result(PIGLIT_SKIP);
+			return;
+		}
+
+	}
+	else {
+		/* Compute largest supported texture size using proxy textures */
+		while(isValidTexSize(target, internalformat, maxSide))
+			maxSide *= 2;
+		/* First unsupported size */
+		while(!isValidTexSize(target, internalformat, maxSide))
+			maxSide /= 2;
+		while(isValidTexSize(target, internalformat, maxSide))
+			maxSide += 1;
+		/* Last supported texture size */
+		maxSide -= 1;
+		printf("%s, Internal Format = %s, Largest Texture Size ="
+		       " %d\n", piglit_get_gl_enum_name(getProxyTarget(target)),
+		       piglit_get_gl_enum_name(internalformat),
+		       maxSide);
+	}
+	/* Test with large sizes. Some of which are greater than max texture size */
+	for (side = maxSide - 100; side < maxSide + 2; side++) {
+		switch (target) {
+		case GL_TEXTURE_1D:
+			//printf("Width = %d, Height = 1, Depth =  1\n", side);
+			if (!proxy) {
+				glTexImage1D(target, 0, internalformat, side,
+					     0, GL_RGBA, GL_FLOAT, NULL);
+				piglit_check_gl_error(GL_NO_ERROR);
+
+				glTexSubImage1D(target, 0, 0, side/2, GL_RGBA,
+						GL_FLOAT, pixels);
+				piglit_check_gl_error(GL_NO_ERROR);
+			}
+			else {
+				glTexImage1D(GL_PROXY_TEXTURE_1D, 0,
+					     internalformat, side, 0,
+					     GL_RGBA, GL_FLOAT, NULL);
+				piglit_check_gl_error(GL_NO_ERROR);
+			}
+			break;
+
+		case GL_TEXTURE_2D:
+			//printf("Width = %d, Height = %d, Depth =  1\n", side,
+			//       side);
+			if(!proxy) {
+				glTexImage2D(target, 0, internalformat, side,
+					     side, 0, GL_RGBA, GL_FLOAT, NULL);
+				piglit_check_gl_error(GL_NO_ERROR);
+
+				glTexSubImage2D(target, 0, 0, 0, side/2, side/2,
+						GL_RGBA, GL_FLOAT, pixels);
+				piglit_check_gl_error(GL_NO_ERROR);
+			}
+
+			else {
+				glTexImage2D(GL_PROXY_TEXTURE_2D, 0,
+					     internalformat, side, side, 0,
+					     GL_RGBA, GL_FLOAT, NULL);
+				piglit_check_gl_error(GL_NO_ERROR);
+			}
+			break;
+
+		case GL_TEXTURE_3D:
+			//printf("Width = %d, Height = %d, Depth =  %d\n", side,
+			//       side, side);
+			if(!proxy) {
+				glTexImage3D(target, 0, internalformat, side,
+					     side,  side, 0, GL_RGBA, GL_FLOAT,
+					     NULL);
+				piglit_check_gl_error(GL_NO_ERROR);
+
+				glTexSubImage3D(target, 0, 0, 0, 0, side/2,
+						side/2, side/2, GL_RGBA,
+						GL_FLOAT, pixels);
+				piglit_check_gl_error(GL_NO_ERROR);
+			}
+			else {
+				glTexImage3D(GL_PROXY_TEXTURE_3D, 0,
+					     internalformat, side, side,
+					     side, 0, GL_RGBA, GL_FLOAT, NULL);
+				piglit_check_gl_error(GL_NO_ERROR);
+			}
+			break;
+
+		case GL_TEXTURE_CUBE_MAP_ARB:
+			//printf("Width = %d, Height = %d, Depth =  1\n", side,
+			//       side);
+			if (!proxy) {
+				for (k = 0; k < 6; k++) {
+					glTexImage2D(
+					GL_TEXTURE_CUBE_MAP_POSITIVE_X + k,
+					0, internalformat,
+					side, side, 0,
+					GL_RGBA, GL_FLOAT, NULL);
+
+					piglit_check_gl_error(GL_NO_ERROR);
+				}
+
+				for (k = 0; k < 6; k++) {
+					glTexSubImage2D(
+					GL_TEXTURE_CUBE_MAP_POSITIVE_X + k,
+					0, 0, 0, side/2, side/2, GL_RGBA,
+					GL_FLOAT, pixels);
+
+					piglit_check_gl_error(GL_NO_ERROR);
+				}
+
+			}
+			else {
+				glTexImage2D(
+				GL_PROXY_TEXTURE_CUBE_MAP,
+				0, internalformat,
+				side, side, 0,
+				GL_RGBA, GL_FLOAT, NULL);
+
+				piglit_check_gl_error(GL_NO_ERROR);
+			}
+			break;
+		}
+	}
+	free(pixels);
+}
+
+void piglit_init(int argc, char **argv)
+{
+	GLuint tex;
+	int i, j;
+
+	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);
+
+	for ( i = 0; i < ARRAY_SIZE(target); i++) {
+
+		glGenTextures(1, &tex);
+		glBindTexture(target[i], tex);
+		glTexParameteri(target[i], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+		glTexParameteri(target[i], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+
+		for (j = 0; j < ARRAY_SIZE(internalformat); j++) {
+
+			if (internalformat[j] == GL_RGBA16F ||
+			    internalformat[j] == GL_RGBA32F)
+				piglit_require_extension("GL_ARB_texture_float");
+
+			/* Test using proxy textures */
+			ValidateTexSize (target[i],  internalformat[j], 1);
+		}
+		glDeleteTextures(1, &tex);
+	}
+
+	printf("\n");
+
+	for ( i = 0; i < ARRAY_SIZE(target); i++) {
+
+		glGenTextures(1, &tex);
+		glBindTexture(target[i], tex);
+		glTexParameteri(target[i], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+		glTexParameteri(target[i], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+
+		for (j = 0; j < ARRAY_SIZE(internalformat); j++) {
+
+			if (internalformat[j] == GL_RGBA16F ||
+			    internalformat[j] == GL_RGBA32F)
+				piglit_require_extension("GL_ARB_texture_float");
+
+			/* Test with out proxy textures*/
+			ValidateTexSize (target[i],  internalformat[j], 0);
+		}
+	}
+
+	printf("\n");
+	/* If execution reaches this point, return PIGLIT_PASS */
+	piglit_report_result(PIGLIT_PASS);
+}
+
+enum piglit_result
+piglit_display(void)
+{
+	return PIGLIT_FAIL;
+}
-- 
1.7.7.6



More information about the Piglit mailing list