[Piglit] [PATCH 1/7] stencil_texturing: Allow testing of texelFetch also

Topi Pohjolainen topi.pohjolainen at intel.com
Thu Apr 28 19:17:04 UTC 2016


CC: Kenneth Graunke <kenneth at whitecape.org>
Signed-off-by: Topi Pohjolainen <topi.pohjolainen at intel.com>
---
 tests/all.py                            |  3 +-
 tests/spec/arb_stencil_texturing/draw.c | 49 +++++++++++++++++++++++++++------
 2 files changed, 43 insertions(+), 9 deletions(-)

diff --git a/tests/all.py b/tests/all.py
index 93d64e6..dd6f9eb 100644
--- a/tests/all.py
+++ b/tests/all.py
@@ -1845,7 +1845,8 @@ with profile.group_manager(
 with profile.group_manager(
         PiglitGLTest,
         grouptools.join('spec', 'ARB_stencil_texturing')) as g:
-    g(['arb_stencil_texturing-draw'], 'draw')
+    g(['arb_stencil_texturing-draw', 'texture'], 'draw-texture')
+    g(['arb_stencil_texturing-draw', 'texelFetch'], 'draw-texelFetch')
 
 with profile.group_manager(
         PiglitGLTest,
diff --git a/tests/spec/arb_stencil_texturing/draw.c b/tests/spec/arb_stencil_texturing/draw.c
index fa6ea42..9353240 100644
--- a/tests/spec/arb_stencil_texturing/draw.c
+++ b/tests/spec/arb_stencil_texturing/draw.c
@@ -223,8 +223,9 @@ setup_textures(void)
  * separate shaders.
  */
 static void
-setup_shaders(void)
+setup_shaders(const char *tex_func)
 {
+	char *fs;
 	int loc;
 
 	const char *vs =
@@ -236,42 +237,74 @@ setup_shaders(void)
 	"    texcoords = (gl_Vertex.xy + 1.0) / 2.0;\n"
 	"}\n";
 
-	const char *fs_stencil =
+	const char *fs_stencil_tmpl =
 	"#version 130\n"
 	"in vec2 texcoords;\n"
+	"ivec2 texelcoords;\n"
 	"uniform usampler2D tex;\n"
 	"void main()\n"
 	"{\n"
-	"    uint stencil = texture(tex, texcoords).x;\n"
+	"    texelcoords[0] = int(texcoords[0] * 256);\n"
+	"    texelcoords[1] = int(texcoords[1] * 256);\n"
+	"    uint stencil = %s.x;\n"
 	"    gl_FragColor = vec4(float(stencil) / 255.0, 0, 0, 1);\n"
 	"}\n";
 
-	const char *fs_depth =
+	const char *fs_depth_tmpl =
 	"#version 130\n"
 	"in vec2 texcoords;\n"
+	"ivec2 texelcoords;\n"
 	"uniform sampler2D tex;\n"
 	"void main()\n"
 	"{\n"
-	"    float depth = texture(tex, texcoords).x;\n"
+	"    texelcoords[0] = int(texcoords[0] * 256);\n"
+	"    texelcoords[1] = int(texcoords[1] * 256);\n"
+	"    float depth = %s.x;\n"
 	"    gl_FragColor = vec4(0, depth, 0, 1);\n"
 	"}\n";
 
-	stencil_prog = piglit_build_simple_program(vs, fs_stencil);
+	asprintf(&fs, fs_stencil_tmpl, tex_func);
+	stencil_prog = piglit_build_simple_program(vs, fs);
+	free(fs);
 	loc = glGetUniformLocation(stencil_prog, "tex");
 	glUseProgram(stencil_prog);
 	glUniform1i(loc, 0);
 
-	depth_prog = piglit_build_simple_program(vs, fs_depth);
+	asprintf(&fs, fs_depth_tmpl, tex_func);
+	depth_prog = piglit_build_simple_program(vs, fs);
+	free(fs);
 	loc = glGetUniformLocation(depth_prog, "tex");
 	glUseProgram(depth_prog);
 	glUniform1i(loc, 0);
 }
 
+static const char *
+parse_args(int argc, char **argv)
+{
+	if (argc != 2) {
+		printf("Usage: %s <tex_func>\n"
+		       "  where <tex_func> is a glsl texture function:\n"
+		       "    texture\n"
+		       "    texelFetch\n",
+		       argv[0]);
+		piglit_report_result(PIGLIT_FAIL);
+	}
+
+	if (strcmp(argv[1], "texture") == 0)
+		return "texture(tex, texcoords)";
+
+	if (strcmp(argv[1], "texelFetch") == 0)
+		return "texelFetch(tex, texelcoords, 0)";
+
+	printf("%s is not supported\n", argv[1]);
+	piglit_report_result(PIGLIT_FAIL);
+}
+
 void
 piglit_init(int argc, char **argv)
 {
 	piglit_require_extension("GL_ARB_stencil_texturing");
 
 	setup_textures();
-	setup_shaders();
+	setup_shaders(parse_args(argc, argv));
 }
-- 
2.5.5



More information about the Piglit mailing list