[Piglit] [PATCH] texelFetch: test various texture dimensions

Marek Olšák maraeo at gmail.com
Thu Sep 19 05:56:29 PDT 2013


This is the ultimate test for validating texture allocation in the driver.
texelFetch is a perfect test for it: it supports various texture targets,
NPOT textures, and mipmapping. It's also our only test for NPOT 3D mipmapped
textures. This commit adds support for testing various texture dimensions.

There are several ways to specify the range of dimensions to test, for example:

texelFetch fs sampler3D 1x129x9-98x129x9
  This runs the test with the texture width of 1, 2, 3, ... up to 98.

texelFetch fs sampler3D 1x1x1-30x30x30
  This tests all WxHxD combinations, where W,H,D is in {1,..,30}.
  This one takes a really long time, so it's not practical for all.tests, but
  the option is there. The main difference between this and tex3d-npot is that
  this also tests mipmaps and you have the option to test bigger dimensions.

The options for the last parameter are:
  WxH - test just WxHx1 (can be non-auto)
  WxHxD - test just WxHxD (can be non-auto)
  W1-W2 - start with W1x1x1 and end with W2x1x1
  W1xH1-W2xH2 - test all combinations between and including the specified
                values, and D=1
  W1xH1xD1-W2xH2xD2 - test all combinations between and including
                      the specified values

The new items in all.tests only iterate over one dimension, the other
dimensions are fixed. It should cover most cases.

Other changes:

- the space between drawn quads is changed to 1 and the mipmaps are positioned
  next to each other for more stuff to fit on the window

- the test fails if a texture with all its layers and mipmaps doesn't fit
  on the window

- some but not all memory leaks are fixed
---
 tests/all.tests                      |  22 +++++
 tests/texturing/shaders/common.h     |   1 +
 tests/texturing/shaders/texelFetch.c | 172 ++++++++++++++++++++++++++---------
 3 files changed, 152 insertions(+), 43 deletions(-)

diff --git a/tests/all.tests b/tests/all.tests
index dc36841..720f5ae 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -876,6 +876,21 @@ for stage in ['vs', 'gs', 'fs']:
                 'texelFetch {0} {1}sampler2DArray b0r1'.format(
                         stage, type))
 
+add_concurrent_test(spec['glsl-1.30']['execution'], 'texelFetch fs sampler1D 1-513')
+add_concurrent_test(spec['glsl-1.30']['execution'], 'texelFetch fs sampler1DArray 1x71-501x71')
+add_concurrent_test(spec['glsl-1.30']['execution'], 'texelFetch fs sampler1DArray 1x281-501x281')
+add_concurrent_test(spec['glsl-1.30']['execution'], 'texelFetch fs sampler1DArray 71x1-71x281')
+add_concurrent_test(spec['glsl-1.30']['execution'], 'texelFetch fs sampler1DArray 281x1-281x281')
+add_concurrent_test(spec['glsl-1.30']['execution'], 'texelFetch fs sampler2D 1x71-501x71')
+add_concurrent_test(spec['glsl-1.30']['execution'], 'texelFetch fs sampler2D 1x281-501x281')
+add_concurrent_test(spec['glsl-1.30']['execution'], 'texelFetch fs sampler2D 71x1-71x281')
+add_concurrent_test(spec['glsl-1.30']['execution'], 'texelFetch fs sampler2D 281x1-281x281')
+add_concurrent_test(spec['glsl-1.30']['execution'], 'texelFetch fs sampler3D 1x129x9-98x129x9')
+add_concurrent_test(spec['glsl-1.30']['execution'], 'texelFetch fs sampler3D 98x1x9-98x129x9')
+add_concurrent_test(spec['glsl-1.30']['execution'], 'texelFetch fs sampler3D 98x129x1-98x129x9')
+add_concurrent_test(spec['glsl-1.30']['execution'], 'texelFetch fs sampler2DArray 1x129x9-98x129x9')
+add_concurrent_test(spec['glsl-1.30']['execution'], 'texelFetch fs sampler2DArray 98x1x9-98x129x9')
+add_concurrent_test(spec['glsl-1.30']['execution'], 'texelFetch fs sampler2DArray 98x129x1-98x129x9')
 add_plain_test(spec['glsl-1.30']['execution'], 'fs-texelFetch-2D')
 add_plain_test(spec['glsl-1.30']['execution'], 'fs-texelFetchOffset-2D')
 add_shader_test_dir(spec['glsl-1.30']['execution'],
@@ -1034,6 +1049,13 @@ for sample_count in MSAA_SAMPLE_COUNTS:
     # sample positions
     spec['ARB_texture_multisample/sample-position/%d' % (sample_count,)] = \
         concurrent_test('arb_texture_multisample-sample-position %d' % (sample_count,))
+add_concurrent_test(arb_texture_multisample, 'texelFetch fs sampler2DMS 4 1x71-501x71')
+add_concurrent_test(arb_texture_multisample, 'texelFetch fs sampler2DMS 4 1x130-501x130')
+add_concurrent_test(arb_texture_multisample, 'texelFetch fs sampler2DMS 4 71x1-71x130')
+add_concurrent_test(arb_texture_multisample, 'texelFetch fs sampler2DMS 4 281x1-281x130')
+add_concurrent_test(arb_texture_multisample, 'texelFetch fs sampler2DMSArray 4 1x129x9-98x129x9')
+add_concurrent_test(arb_texture_multisample, 'texelFetch fs sampler2DMSArray 4 98x1x9-98x129x9')
+add_concurrent_test(arb_texture_multisample, 'texelFetch fs sampler2DMSArray 4 98x129x1-98x129x9')
 add_concurrent_test(arb_texture_multisample, 'arb_texture_multisample-texstate')
 add_concurrent_test(arb_texture_multisample, 'arb_texture_multisample-errors')
 add_concurrent_test(arb_texture_multisample, 'arb_texture_multisample-sample-mask')
diff --git a/tests/texturing/shaders/common.h b/tests/texturing/shaders/common.h
index 7b241b9..a4d1dc0 100644
--- a/tests/texturing/shaders/common.h
+++ b/tests/texturing/shaders/common.h
@@ -80,6 +80,7 @@ struct sampler_info
 
 /** Whether or not we're using GL_EXT_texture_swizzle */
 bool swizzling;
+int minx, miny, minz, maxx, maxy, maxz;
 int sample_count;
 extern int shader_version;
 
diff --git a/tests/texturing/shaders/texelFetch.c b/tests/texturing/shaders/texelFetch.c
index badaac7..1c4c97f 100644
--- a/tests/texturing/shaders/texelFetch.c
+++ b/tests/texturing/shaders/texelFetch.c
@@ -93,13 +93,13 @@ PIGLIT_GL_TEST_CONFIG_BEGIN
 		config.supports_gl_core_version = 31;
 	}
 
-	config.window_width = 355;
-	config.window_height = 350;
+	config.window_width = 900;
+	config.window_height = 600;
 	config.window_visual = PIGLIT_GL_VISUAL_RGBA | PIGLIT_GL_VISUAL_DOUBLE;
 
 PIGLIT_GL_TEST_CONFIG_END
 
-#define MAX_LOD_OR_SAMPLES  8.0
+#define MAX_LOD_OR_SAMPLES  10.0
 
 /** Vertex shader attribute locations */
 const int pos_loc = 0;
@@ -123,6 +123,9 @@ int divisor_loc;
  */
 float ***expected_colors;
 
+int prog;
+GLuint tex;
+
 /**
  * Return the divisors necessary to scale the unnormalized texture data to
  * a floating point color value in the range [0, 1].
@@ -139,21 +142,16 @@ compute_divisors(int lod, float *divisors)
 		divisors[0] = -divisors[0];
 }
 
-enum piglit_result
-piglit_display()
+static bool test_once()
 {
-	int i, l, z;
+	int i, l, z, level_y = 0;
 	bool pass = true;
 
-   glViewport(0, 0, piglit_width, piglit_height);
-
-	glClearColor(0.1, 0.1, 0.1, 1.0);
-	glClear(GL_COLOR_BUFFER_BIT);
-
-	glPointSize(1.0);
-
 	i = 0;
 	for (l = 0; l < miplevels; ++l) {
+		if (l && !has_samples())
+			level_y += 1 + MAX2(base_size[1] >> (l-1), 1);
+
 		for (z = 0; z < level_size[l][2]; z++) {
 			/* Draw the "rectangle" for this miplevel/slice. */
 			int points = level_size[l][0] * level_size[l][1];
@@ -168,17 +166,15 @@ piglit_display()
 			i += points;
 
 			/* Compare results against reference image. */
-			pass &= piglit_probe_image_rgba(5+(5+base_size[0]) * z,
-							5+(5+base_size[1]) * l,
+			pass &= piglit_probe_image_rgba(5+(1+base_size[0]) * z,
+							has_samples() ? 5+(1+base_size[1]) * l
+								      : 5 + level_y,
 							level_size[l][0],
 							level_size[l][1],
 							expected_colors[l][z]);
 		}
 	}
-
-	piglit_present_results();
-
-	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
+	return pass;
 }
 
 /**
@@ -198,6 +194,7 @@ generate_VBOs()
 	int *tc, *tc_data;
 	bool array_1D = sampler.target == GL_TEXTURE_1D_ARRAY;
 	int num_texels = 0;
+	int level_y = 0;
 
 	/* Calculate the # of texels a.k.a. size of the VBOs */
 	for (l = 0; l < miplevels; l++) {
@@ -208,12 +205,18 @@ generate_VBOs()
 	tc = tc_data = malloc(num_texels * 4 * sizeof(int));
 
 	for (l = 0; l < miplevels; l++) {
+		if (l && !has_samples())
+			level_y += 1 + MAX2(base_size[1] >> (l-1), 1);
+
 		for (z = 0; z < level_size[l][2]; z++) {
 			for (y = 0; y < level_size[l][1]; y++) {
 				for (x = 0; x < level_size[l][0]; x++) {
 					/* Assign pixel positions: */
-					pos[0] = 5.5 + (5 + base_size[0])*z + x;
-					pos[1] = 5.5 + (5 + base_size[1])*l + y;
+					pos[0] = 5.5 + (1 + base_size[0])*z + x;
+					if (has_samples())
+						pos[1] = 5.5 + (1 + base_size[1])*l + y;
+					else
+						pos[1] = 5.5 + level_y + y;
 					pos[2] = 0.0;
 					pos[3] = 1.0;
 
@@ -273,6 +276,9 @@ generate_VBOs()
 		     tc_data, GL_STATIC_DRAW);
 	glVertexAttribIPointer(texcoord_loc, 4, GL_INT, 0, 0);
 	glEnableVertexAttribArray(texcoord_loc);
+
+	free(pos_data);
+	free(tc_data);
 }
 
 /* like piglit_draw_rect(), but works in a core context too.
@@ -432,7 +438,6 @@ generate_texture()
 	float    *expected_ptr;
 	void *level_image;
 	float divisors[4];
-	GLuint tex;
 	GLenum target = sampler.target;
 
 	glActiveTexture(GL_TEXTURE0);
@@ -528,6 +533,10 @@ generate_texture()
 
 		if (!has_samples())
 			upload_miplevel_data(target, l, level_image);
+
+		free(f_level);
+		free(u_level);
+		free(i_level);
 	}
 
 	if (has_samples())
@@ -754,17 +763,6 @@ generate_GLSL(enum shader_target test_stage)
 }
 
 /**
- * Set the size of the texture's base level.
- */
-void
-set_base_size()
-{
-	base_size[0] = 65;
-	base_size[1] = has_height() ? 32 : 1;
-	base_size[2] = has_slices() ?  5 : 1;
-}
-
-/**
  * Is this sampler supported by texelFetch?
  */
 static bool
@@ -798,8 +796,12 @@ parse_args(int argc, char **argv)
 {
 	int i;
 	bool sampler_found = false;
+	bool dim_range_found = false;
 
 	sample_count = 0;
+	minx = maxx = 65;
+	miny = maxy = 32;
+	minz = maxz = 5;
 
 	for (i = 1; i < argc; i++) {
 		if (test_stage == UNKNOWN) {
@@ -833,13 +835,45 @@ parse_args(int argc, char **argv)
 		/* Maybe it's the sample count? */
 		if (sampler_found && has_samples() && !sample_count) {
 			sample_count = atoi(argv[i]);
-
 			continue;
 		}
 
 		if (!swizzling && (swizzling = parse_swizzle(argv[i])))
 			continue;
 
+		if (!dim_range_found) {
+			if (sscanf(argv[i], "%ux%ux%u-%ux%ux%u",
+				   &minx, &miny, &minz, &maxx, &maxy, &maxz) == 6) {
+				dim_range_found = true;
+				continue;
+			}
+			if (sscanf(argv[i], "%ux%u-%ux%u",
+				   &minx, &miny, &maxx, &maxy) == 4) {
+				minz = maxz = 1;
+				dim_range_found = true;
+				continue;
+			}
+			if (sscanf(argv[i], "%u-%u", &minx, &maxx) == 2) {
+				miny = maxy = minz = maxz = 1;
+				dim_range_found = true;
+				continue;
+			}
+			if (sscanf(argv[i], "%ux%ux%u", &minx, &miny, &minz) == 3) {
+				maxx = minx;
+				maxy = miny;
+				maxz = minz;
+				dim_range_found = true;
+				continue;
+			}
+			if (sscanf(argv[i], "%ux%u", &minx, &miny) == 2) {
+				maxx = minx;
+				maxy = miny;
+				minz = maxz = 1;
+				dim_range_found = true;
+				continue;
+			}
+		}
+
 		fail_and_show_usage();
 	}
 
@@ -848,13 +882,73 @@ parse_args(int argc, char **argv)
 
 	if (test_stage == GS && shader_version < 150)
 		shader_version = 150;
+
+	if (!has_height()) {
+		miny = maxy = 1;
+	}
+
+	if (!has_slices()) {
+		minz = maxz = 1;
+	}
+
+	if (minx < maxx || miny < maxy || minz < maxz)
+		piglit_automatic = true;
 }
 
+enum piglit_result
+piglit_display()
+{
+	int x, y, z;
+	bool pass = true;
+
+	glClearColor(0.1, 0.1, 0.1, 1.0);
+	glPointSize(1.0);
+
+	for (x = minx; x <= maxx; x++) {
+		for (y = miny; y <= maxy; y++) {
+			for (z = minz; z <= maxz; z++) {
+				printf("%ix%ix%i\n", x, y, z);
+
+				if (5 + (x+1) * z >= piglit_width) {
+					printf("Width or depth is too big.\n");
+					piglit_report_result(PIGLIT_FAIL);
+				}
+
+				if ((has_samples() && 5 + (y+1) * miplevels >= piglit_height) ||
+				    (!has_samples() && 5 + y*2 + miplevels-2 >= piglit_height)) {
+					printf("Height is too big or too many samples.\n");
+					piglit_report_result(PIGLIT_FAIL);
+				}
+
+				base_size[0] = x;
+				base_size[1] = y;
+				base_size[2] = z;
+
+				/* Create textures and set miplevel info */
+				compute_miplevel_info();
+				generate_texture();
+				generate_VBOs();
+
+				glViewport(0, 0, piglit_width, piglit_height);
+				glClear(GL_COLOR_BUFFER_BIT);
+				glUseProgram(prog);
+
+				pass &= test_once();
+
+				glUseProgram(0);
+				glDeleteTextures(1, &tex);
+			}
+		}
+	}
+
+	piglit_present_results();
+
+	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
+}
 
 void
 piglit_init(int argc, char **argv)
 {
-	int prog;
 	int tex_location;
 
 	if (!supported_sampler()) {
@@ -893,14 +987,6 @@ piglit_init(int argc, char **argv)
 	tex_location = glGetUniformLocation(prog, "tex");
 	divisor_loc = glGetUniformLocation(prog, "divisor");
 
-	/* Create textures and set miplevel info */
-	set_base_size();
-	compute_miplevel_info();
-	generate_texture();
-
-	generate_VBOs();
-
 	glUseProgram(prog);
-
 	glUniform1i(tex_location, 0);
 }
-- 
1.8.1.2



More information about the Piglit mailing list