[Piglit] [PATCH 2/2] max-samplers: Add a mode that samples the border color.

Kenneth Graunke kenneth at whitecape.org
Sat Jan 18 19:54:26 PST 2014


Intel hardware has an awkward limit where the index into the sampler
state table is represented by a 4-bit value, so the only possible
indices are 0-15.  (The surface state table has no such restriction.)
However, it's possible to support more than 16 textures on Haswell via
a bit of trickery.

The existing test covers basic sampling, but doesn't do much with
sampler state (wrap modes, filter modes, border color, and such).
An implementation that got the surface information correct but which
used the wrong sampler state (say, by dropping bit 5) would pass.

This patch additionally programs each texture's unique color as the
border color, sets the wrap modes to CLAMP_TO_BORDER, and provides a
"border" command line argument which makes the test sample outside the
texture.  This mode ensures that the right sampler state is used.

Cc: Marek Olšák <maraeo at gmail.com>
Cc: Chris Forbes <chrisf at ijw.co.nz>
Cc: Ian Romanick <idr at freedesktop.org>
Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
---
 tests/all.py                   |  1 +
 tests/texturing/max-samplers.c | 20 ++++++++++++++++----
 2 files changed, 17 insertions(+), 4 deletions(-)

Thanks again for writing this test, Marek!  Saved me a lot of effort.

diff --git a/tests/all.py b/tests/all.py
index 6ed30eb..8f0e1f0 100644
--- a/tests/all.py
+++ b/tests/all.py
@@ -1022,6 +1022,7 @@ add_plain_test(gl20, 'fragment-and-vertex-texturing')
 gl20['incomplete-texture-glsl'] = concurrent_test('incomplete-texture -auto glsl')
 add_plain_test(gl20, 'tex3d-npot')
 add_concurrent_test(gl20, 'max-samplers')
+add_concurrent_test(gl20, 'max-samplers border')
 
 gl21 = Group()
 spec['!OpenGL 2.1'] = gl21
diff --git a/tests/texturing/max-samplers.c b/tests/texturing/max-samplers.c
index c8de624..3080412 100644
--- a/tests/texturing/max-samplers.c
+++ b/tests/texturing/max-samplers.c
@@ -52,7 +52,7 @@ static const char *vs_source =
 	"	vertex_tex_color = vec3(0.0); \n"
 	"	for (i = 0; i < NUM; i++) \n"
 	"		if (i == vertex_index) \n"
-	"			vertex_tex_color = texture2DLod(vertex_tex[i], vec2(0.5), 0.0).xyz; \n"
+	"			vertex_tex_color = texture2DLod(vertex_tex[i], vec2(%f), 0.0).xyz; \n"
 	"} \n";
 
 static const char *vs_source_no_textures =
@@ -74,7 +74,7 @@ static const char *fs_source =
 	"	vec3 fragment_tex_color = vec3(0.0); \n"
 	"	for (i = 0; i < NUM; i++) \n"
 	"		if (i == fragment_index) \n"
-	"			fragment_tex_color = texture2D(fragment_tex[i], vec2(0.5), 0.0).xyz; \n"
+	"			fragment_tex_color = texture2D(fragment_tex[i], vec2(%f), 0.0).xyz; \n"
 	"	gl_FragColor = vec4(fragment_tex_color + vertex_tex_color, 1.0); \n"
 	"} \n";
 
@@ -213,6 +213,9 @@ set_texture(int unit)
 		     GL_RGB, GL_FLOAT, color);
 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
+	glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, color);
 
 	piglit_check_gl_error(GL_NO_ERROR);
 }
@@ -223,6 +226,15 @@ piglit_init(int argc, char **argv)
 	GLuint vs, fs, vao;
 	int max_combined_textures, i, unit;
 	char str[2048];
+	float texcoord = 0.5;
+
+	if (argc == 2 && strcmp(argv[1], "border") == 0) {
+		/* Sample outside of the texture, testing border color. */
+		texcoord = 5.0;
+	} else if (argc != 1) {
+		printf("Usage: max-samples [border]\n");
+		piglit_report_result(PIGLIT_SKIP);
+	}
 
 	/* get limits */
 	glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &max_fs_textures);
@@ -238,14 +250,14 @@ piglit_init(int argc, char **argv)
 
 	/* compile shaders */
 	if (max_vs_textures) {
-		sprintf(str, vs_source, max_vs_textures);
+		sprintf(str, vs_source, max_vs_textures, texcoord);
 		vs = piglit_compile_shader_text(GL_VERTEX_SHADER, str);
 	}
 	else {
 		vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vs_source_no_textures);
 	}
 
-	sprintf(str, fs_source, max_fs_textures);
+	sprintf(str, fs_source, max_fs_textures, texcoord);
 	fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, str);
 
 	prog = piglit_link_simple_program(vs, fs);
-- 
1.8.5.2



More information about the Piglit mailing list