[Piglit] [PATCH] Add GL_EXT_texture_swizzle support to texelFetch.

Kenneth Graunke kenneth at whitecape.org
Tue Dec 6 15:55:16 PST 2011


texelFetch now takes an optional command line parameter representing the
EXT_texture_swizzle mode.  Examples include: "rgba", "b1gr", "r0rr".

Making the test support arbitrary swizzling was easy enough, and seemed
like it could be useful.  However, we probably don't want to test all
combinations of this by default, as there are far too many.  So, I only
added [iu ]sampler2DArray tests with "b0r1" swizzling to all.tests.

Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
---
 tests/all.tests                      |    3 +
 tests/texturing/shaders/common.c     |   83 ++++++++++++++++++++++++++++++++++
 tests/texturing/shaders/common.h     |   10 ++++-
 tests/texturing/shaders/texelFetch.c |    8 +++
 4 files changed, 103 insertions(+), 1 deletions(-)

Thanks Brian!

You're right, I was using it unconditionally without checking.  Whoops!

v2: Actually check/require EXT_texture_swizzle when the user requested
    swizzling, and avoid using it otherwise.

    Also use GLenum for the swizzle and cast to GLint* for TexParameteriv.

diff --git a/tests/all.tests b/tests/all.tests
index eb6725b..3c87550 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -890,6 +890,9 @@ for stage in ['vs', 'fs']:
 	# texelFetch():
 	for sampler in ['sampler1D', 'sampler2D', 'sampler3D', 'sampler1DArray', 'sampler2DArray', 'isampler1D', 'isampler2D', 'isampler3D', 'isampler1DArray', 'isampler2DArray', 'usampler1D', 'usampler2D', 'usampler3D', 'usampler1DArray', 'usampler2DArray']:
 		spec['glsl-1.30']['execution']['texelFetch'][stage + '-texelFetch-' + sampler] = PlainExecTest(['texelFetch', stage, sampler, '-auto', '-fbo'])
+	# texelFetch() with EXT_texture_swizzle mode "b0r1":
+	for type in ['i', 'u', '']:
+		spec['glsl-1.30']['execution']['texelFetch'][stage + '-texelFetch-' + type + 'sampler2DArray-swizzle'] = PlainExecTest(['texelFetch', stage, type + 'sampler2DArray', 'b0r1', '-auto', '-fbo'])
 
 add_plain_test(spec['glsl-1.30']['execution'], 'fs-texelFetch-2D')
 add_plain_test(spec['glsl-1.30']['execution'], 'fs-texelFetchOffset-2D')
diff --git a/tests/texturing/shaders/common.c b/tests/texturing/shaders/common.c
index 57ccc9b..1bdb37c 100644
--- a/tests/texturing/shaders/common.c
+++ b/tests/texturing/shaders/common.c
@@ -254,6 +254,9 @@ require_GL_features(enum shader_target test_stage)
 
 	piglit_require_GLSL_version(130);
 
+	if (swizzling)
+		piglit_require_extension("GL_EXT_texture_swizzle");
+
 	switch (sampler.internal_format) {
 	case GL_RGBA32I:
 	case GL_RGBA32UI:
@@ -286,3 +289,83 @@ require_GL_features(enum shader_target test_stage)
 	if (test_stage == VS && tex_units <= 0)
 		piglit_report_result(PIGLIT_SKIP);
 }
+
+/**
+ * Performs an in-place swizzle of a vec4 based on the EXT_texture_swizzle mode.
+ */
+void
+swizzle(float vec[])
+{
+	int i;
+	float temp[4];
+
+	if (!swizzling)
+		return;
+
+	memcpy(temp, vec, 4*sizeof(float));
+
+	for (i = 0; i < 4; i++) {
+		switch (sampler.swizzle[i]) {
+		case GL_RED:
+			vec[i] = temp[0];
+			break;
+		case GL_GREEN:
+			vec[i] = temp[1];
+			break;
+		case GL_BLUE:
+			vec[i] = temp[2];
+			break;
+		case GL_ALPHA:
+			vec[i] = temp[3];
+			break;
+		case GL_ZERO:
+			vec[i] = 0.0;
+			break;
+		case GL_ONE:
+			vec[i] = 1.0;
+			break;
+		default:
+			assert(!"Should not get here.");
+		}
+	}
+}
+
+/**
+ * Parse the command line argument for the EXT_texture_swizzle mode.
+ * It should be a string of length 4 consisting of r, g, b, a, 0, or 1.
+ * For example, "bgr1".
+ */
+bool
+parse_swizzle(const char *swiz)
+{
+	int i;
+	if (strlen(swiz) != 4 || strspn(swiz, "rgba01") != 4)
+		return false;
+
+	for (i = 0; i < 4; i++) {
+		switch (swiz[i]) {
+		case 'r':
+			sampler.swizzle[i] = GL_RED;
+			break;
+		case 'g':
+			sampler.swizzle[i] = GL_GREEN;
+			break;
+		case 'b':
+			sampler.swizzle[i] = GL_BLUE;
+			break;
+		case 'a':
+			sampler.swizzle[i] = GL_ALPHA;
+			break;
+		case '0':
+			sampler.swizzle[i] = GL_ZERO;
+			break;
+		case '1':
+			sampler.swizzle[i] = GL_ONE;
+			break;
+		default:
+			assert(!"Should not get here.");
+		}
+	}
+
+	return true;
+}
diff --git a/tests/texturing/shaders/common.h b/tests/texturing/shaders/common.h
index c25bf2c..32cf8da 100644
--- a/tests/texturing/shaders/common.h
+++ b/tests/texturing/shaders/common.h
@@ -74,8 +74,14 @@ struct sampler_info
 	 * GL_DEPTH_COMPONENT.
 	 */
 	GLenum internal_format;
+
+	/** GL_EXT_texture_swizzle setting: GL_RED/GREEN/BLUE/ALPHA/ZERO/ONE */
+	GLenum swizzle[4];
 } sampler;
 
+/** Whether or not we're using GL_EXT_texture_swizzle */
+bool swizzling;
+
 /**
  * Which shader stage to test
  */
@@ -94,8 +100,10 @@ bool has_slices();
 bool is_array_sampler();
 bool is_shadow_sampler();
 
+void swizzle(float vec4[]);
+
 void upload_miplevel_data(GLenum target, int level, void *level_image);
 void compute_miplevel_info();
 void require_GL_features(enum shader_target test_stage);
 bool select_sampler(const char *name);
-
+bool parse_swizzle(const char *swiz);
diff --git a/tests/texturing/shaders/texelFetch.c b/tests/texturing/shaders/texelFetch.c
index 94356c4..285f9a2 100644
--- a/tests/texturing/shaders/texelFetch.c
+++ b/tests/texturing/shaders/texelFetch.c
@@ -131,6 +131,7 @@ piglit_display()
 			float divisors[4];
 
 			compute_divisors(l, divisors);
+			swizzle(divisors);
 			glUniform4fv(divisor_loc, 1, divisors);
 
 			glDrawArrays(GL_POINTS, i, points);
@@ -248,6 +249,9 @@ generate_texture()
 	glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
 	glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
 	glTexParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+	if (swizzling)
+		glTexParameteriv(target, GL_TEXTURE_SWIZZLE_RGBA,
+				 (GLint *) sampler.swizzle);
 
 	expected_colors = calloc(miplevels, sizeof(float **));
 
@@ -294,6 +298,7 @@ generate_texture()
 					expected_ptr[1] = f_ptr[1]/divisors[1];
 					expected_ptr[2] = f_ptr[2]/divisors[2];
 					expected_ptr[3] = 1.0;
+					swizzle(expected_ptr);
 
 					f_ptr += 4;
 					i_ptr += 4;
@@ -484,6 +489,9 @@ piglit_init(int argc, char **argv)
 		if (!sampler_found && (sampler_found = select_sampler(argv[i])))
 			continue;
 
+		if (!swizzling && (swizzling = parse_swizzle(argv[i])))
+			continue;
+
 		fail_and_show_usage();
 	}
 
-- 
1.7.7.3



More information about the Piglit mailing list