[Piglit] [PATCH 6/8] arb_texture_multisample: add new sampler targets to textureSize

Chris Forbes chrisf at ijw.co.nz
Sat Jan 5 01:07:37 PST 2013


Covers use of the textureSize() glsl builtin with multisample samplers

Signed-off-by: Chris Forbes <chrisf at ijw.co.nz>
---
 tests/all.tests                       |  6 +++++
 tests/texturing/shaders/common.c      | 41 ++++++++++++++++++++++++++---
 tests/texturing/shaders/textureSize.c | 49 ++++++++++++++++++++++++-----------
 3 files changed, 78 insertions(+), 18 deletions(-)

diff --git a/tests/all.tests b/tests/all.tests
index 6c455c4..19d7cf9 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -850,6 +850,12 @@ add_concurrent_test(arb_texture_multisample, 'arb_texture_multisample-sample-mas
 add_concurrent_test(arb_texture_multisample, 'arb_texture_multisample-sample-mask-value')
 add_concurrent_test(arb_texture_multisample, 'arb_texture_multisample-sample-mask-execution')
 add_concurrent_test(arb_texture_multisample, 'arb_texture_multisample-sample-mask-execution -tex')
+textureSize_samplers_atm = ['sampler2DMS', 'isampler2DMS', 'usampler2DMS',
+							'sampler2DMSArray', 'isampler2DMSArray', 'usampler2DMSArray']
+for stage in ['vs', 'fs']:
+	# textureSize():
+	for sampler in textureSize_samplers_atm:
+		spec['ARB_texture_multisample/textureSize/' + stage + '-textureSize-' + sampler] = concurrent_test('textureSize ' + stage + ' ' + sampler)
 
 # Group AMD_shader_stencil_export
 spec['AMD_shader_stencil_export'] = Group()
diff --git a/tests/texturing/shaders/common.c b/tests/texturing/shaders/common.c
index aa69a5d..cf9c2b1 100644
--- a/tests/texturing/shaders/common.c
+++ b/tests/texturing/shaders/common.c
@@ -88,6 +88,27 @@ upload_miplevel_data(GLenum target, int level, void *level_image)
 		glTexBuffer(GL_TEXTURE_BUFFER, internal_format, bo);
 		break;
 
+	/* TODO: reconsider hardwired sample count */
+	/* TODO: perhaps render some initial content to the texture?
+	 *     (direct uploads of multisample texture images are not allowed,
+	 *     but we could render something) */
+	case GL_TEXTURE_2D_MULTISAMPLE:
+		glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 4,
+				internal_format,
+				level_size[level][0],
+				level_size[level][1],
+				GL_TRUE);
+		break;
+	
+	case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:
+		glTexImage3DMultisample(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, 4,
+				internal_format,
+				level_size[level][0],
+				level_size[level][1],
+				level_size[level][2],
+				GL_TRUE);
+		break;
+
 	default:
 		assert(!"Not implemented yet.");
 		break;
@@ -134,7 +155,9 @@ compute_miplevel_info()
 	miplevels = (int) log2f(max_dimension) + 1;
 
 	if (sampler.target == GL_TEXTURE_RECTANGLE ||
-	    sampler.target == GL_TEXTURE_BUFFER)
+	    sampler.target == GL_TEXTURE_BUFFER ||
+		sampler.target == GL_TEXTURE_2D_MULTISAMPLE ||
+		sampler.target == GL_TEXTURE_2D_MULTISAMPLE_ARRAY)
 		miplevels = 1;
 
 	/* Compute the size of each miplevel */
@@ -159,7 +182,9 @@ has_height()
 	return sampler.target == GL_TEXTURE_2D ||
 	       sampler.target == GL_TEXTURE_3D ||
 	       sampler.target == GL_TEXTURE_2D_ARRAY ||
-	       sampler.target == GL_TEXTURE_RECTANGLE;
+	       sampler.target == GL_TEXTURE_RECTANGLE ||
+	       sampler.target == GL_TEXTURE_2D_MULTISAMPLE ||
+	       sampler.target == GL_TEXTURE_2D_MULTISAMPLE_ARRAY;
 }
 
 bool
@@ -173,7 +198,8 @@ is_array_sampler()
 {
 	return sampler.target == GL_TEXTURE_1D_ARRAY ||
 	       sampler.target == GL_TEXTURE_2D_ARRAY ||
-	       sampler.target == GL_TEXTURE_CUBE_MAP_ARRAY;
+	       sampler.target == GL_TEXTURE_CUBE_MAP_ARRAY ||
+	       sampler.target == GL_TEXTURE_2D_MULTISAMPLE_ARRAY;
 }
 
 bool
@@ -207,6 +233,8 @@ select_sampler(const char *name)
 		{ "sampler2DArray",         GL_SAMPLER_2D_ARRAY,                    GL_TEXTURE_2D_ARRAY       },
 		{ "samplerCubeArray",       GL_SAMPLER_CUBE_MAP_ARRAY,              GL_TEXTURE_CUBE_MAP_ARRAY },
 		{ "samplerBuffer",          GL_SAMPLER_BUFFER,                      GL_TEXTURE_BUFFER },
+		{ "sampler2DMS",            GL_SAMPLER_2D_MULTISAMPLE,              GL_TEXTURE_2D_MULTISAMPLE },
+		{ "sampler2DMSArray",       GL_SAMPLER_2D_MULTISAMPLE_ARRAY,        GL_TEXTURE_2D_MULTISAMPLE_ARRAY },
 
 		{ "sampler1DShadow",        GL_SAMPLER_1D_SHADOW,                   GL_TEXTURE_1D             },
 		{ "sampler2DShadow",        GL_SAMPLER_2D_SHADOW,                   GL_TEXTURE_2D             },
@@ -225,6 +253,8 @@ select_sampler(const char *name)
 		{ "isampler2DArray",        GL_INT_SAMPLER_2D_ARRAY,                GL_TEXTURE_2D_ARRAY       },
 		{ "isamplerCubeArray",      GL_INT_SAMPLER_CUBE_MAP_ARRAY,          GL_TEXTURE_CUBE_MAP_ARRAY },
 		{ "isamplerBuffer",         GL_INT_SAMPLER_BUFFER,                  GL_TEXTURE_BUFFER },
+		{ "isampler2DMS",           GL_INT_SAMPLER_2D_MULTISAMPLE,          GL_TEXTURE_2D_MULTISAMPLE },
+		{ "isampler2DMSArray",      GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAY,    GL_TEXTURE_2D_MULTISAMPLE_ARRAY },
 
 		{ "usampler1D",             GL_UNSIGNED_INT_SAMPLER_1D,             GL_TEXTURE_1D             },
 		{ "usampler2D",             GL_UNSIGNED_INT_SAMPLER_2D,             GL_TEXTURE_2D             },
@@ -235,6 +265,8 @@ select_sampler(const char *name)
 		{ "usampler2DArray",        GL_UNSIGNED_INT_SAMPLER_2D_ARRAY,       GL_TEXTURE_2D_ARRAY       },
 		{ "usamplerCubeArray",      GL_UNSIGNED_INT_SAMPLER_CUBE_MAP_ARRAY, GL_TEXTURE_CUBE_MAP_ARRAY },
 		{ "usamplerBuffer",         GL_UNSIGNED_INT_SAMPLER_BUFFER,         GL_TEXTURE_BUFFER },
+		{ "usampler2DMS",           GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE, GL_TEXTURE_2D_MULTISAMPLE },
+		{ "usampler2DMSArray",      GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY, GL_TEXTURE_2D_MULTISAMPLE_ARRAY },
 	};
 
 	for (i = 0; i < ARRAY_SIZE(samplers); i++) {
@@ -321,6 +353,9 @@ require_GL_features(enum shader_target test_stage)
 	case GL_TEXTURE_BUFFER:
 		piglit_require_extension("GL_ARB_texture_buffer_object");
 		break;
+	case GL_TEXTURE_2D_MULTISAMPLE:
+	case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:
+		piglit_require_extension("GL_ARB_texture_multisample");
 	}
 
 	/* If testing in the VS, check for VS texture units */
diff --git a/tests/texturing/shaders/textureSize.c b/tests/texturing/shaders/textureSize.c
index 6adca7f..eef3855 100644
--- a/tests/texturing/shaders/textureSize.c
+++ b/tests/texturing/shaders/textureSize.c
@@ -60,7 +60,7 @@ PIGLIT_GL_TEST_CONFIG_END
 static int lod_location;
 static int vertex_location;
 
-static char *cube_map_array_extension = "";
+static char *extension = "";
 
 /**
  * Returns the number of components expected from textureSize().
@@ -76,10 +76,12 @@ sampler_size()
 	case GL_TEXTURE_1D_ARRAY:
 	case GL_TEXTURE_CUBE_MAP:
 	case GL_TEXTURE_RECTANGLE:
+	case GL_TEXTURE_2D_MULTISAMPLE:
 		return 2;
 	case GL_TEXTURE_3D:
 	case GL_TEXTURE_2D_ARRAY:
 	case GL_TEXTURE_CUBE_MAP_ARRAY:
+	case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:
 		return 3;
 	default:
 		assert(!"Should not get here.");
@@ -181,10 +183,12 @@ generate_texture()
 
 	glGenTextures(1, &tex);
 	glBindTexture(target, tex);
-	if (target == GL_TEXTURE_BUFFER) {
-		/* Texture buffers only use texelFetch() and
-		 * textureSize(), so setting the filter parameters on
-		 * them is invalid.
+	if (target == GL_TEXTURE_BUFFER ||
+		target == GL_TEXTURE_2D_MULTISAMPLE ||
+		target == GL_TEXTURE_2D_MULTISAMPLE_ARRAY) {
+		/* Texture buffers, multisample textures and multisample
+		 * texture arrays only use texelFetch() and textureSize(),
+		 * so setting the filter parameters on them is invalid.
 		 */
 	} else if (target == GL_TEXTURE_RECTANGLE) {
 		glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
@@ -195,7 +199,9 @@ generate_texture()
 		glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
 	}
 
-	if (target != GL_TEXTURE_BUFFER) {
+	if (target != GL_TEXTURE_BUFFER &&
+		target != GL_TEXTURE_2D_MULTISAMPLE &&
+		target != GL_TEXTURE_2D_MULTISAMPLE_ARRAY) {
 		glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
 		glTexParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
 	}
@@ -212,6 +218,19 @@ generate_texture()
 	}
 }
 
+bool
+has_lod(void)
+{
+	switch (sampler.target) {
+		case GL_TEXTURE_RECTANGLE:
+		case GL_TEXTURE_BUFFER:
+		case GL_TEXTURE_2D_MULTISAMPLE:
+		case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:
+			return false;
+		default:
+			return true;
+	}
+}
 
 int
 generate_GLSL(enum shader_target test_stage)
@@ -226,13 +245,10 @@ generate_GLSL(enum shader_target test_stage)
 	const int size = sampler_size();
 
 	/* The GLSL 1.40 sampler2DRect/samplerBuffer samplers don't
-	 * take a lod argument.
+	 * take a lod argument. Neither do ARB_texture_multisample's
+	 * sampler2DMS/sampler2DMSArray samplers.
 	 */
-	if (sampler.target == GL_TEXTURE_RECTANGLE ||
-	    sampler.target == GL_TEXTURE_BUFFER)
-		lod_arg = "";
-	else
-		lod_arg = ", lod";
+	lod_arg = has_lod() ? ", lod" : "";
 
 	switch (test_stage) {
 	case VS:
@@ -248,7 +264,7 @@ generate_GLSL(enum shader_target test_stage)
 			 "    size = textureSize(tex%s);\n"
 			 "    gl_Position = vertex;\n"
 			 "}\n",
-			 shader_version, cube_map_array_extension, sampler.name, size, lod_arg);
+			 shader_version, extension, sampler.name, size, lod_arg);
 		asprintf(&fs_code,
 			 "#version %d\n"
 			 "#define ivec1 int\n"
@@ -279,7 +295,7 @@ generate_GLSL(enum shader_target test_stage)
 			 "    ivec%d size = textureSize(tex%s);\n"
 			 "    gl_FragColor = vec4(0.01 * size,%s 1);\n"
 			 "}\n",
-			 shader_version, cube_map_array_extension, sampler.name, size, lod_arg,
+			 shader_version, extension, sampler.name, size, lod_arg,
 			 zeroes[3 - size]);
 		break;
 	default:
@@ -342,7 +358,10 @@ piglit_init(int argc, char **argv)
 	require_GL_features(test_stage);
 
 	if (sampler.target == GL_TEXTURE_CUBE_MAP_ARRAY)
-		cube_map_array_extension = "#extension GL_ARB_texture_cube_map_array : enable\n";
+		extension = "#extension GL_ARB_texture_cube_map_array : enable\n";
+	if (sampler.target == GL_TEXTURE_2D_MULTISAMPLE
+		|| sampler.target == GL_TEXTURE_2D_MULTISAMPLE_ARRAY)
+		extension = "#extension GL_ARB_texture_multisample : enable\n";
 
 	prog = generate_GLSL(test_stage);
 	if (!prog)
-- 
1.8.1



More information about the Piglit mailing list