[Piglit] [PATCH 2/3] texelFetch: Add an option for this program that does texelFetchOffset().

Eric Anholt eric at anholt.net
Tue Apr 17 12:09:05 PDT 2012


---
 tests/all.tests                      |    2 +
 tests/texturing/shaders/texelFetch.c |   77 ++++++++++++++++++++++++++++++----
 2 files changed, 71 insertions(+), 8 deletions(-)

diff --git a/tests/all.tests b/tests/all.tests
index 35e92a2..9e17535 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -950,6 +950,7 @@ 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] = concurrent_test('texelFetch ' + stage + ' ' + sampler)
+		spec['glsl-1.30/execution/texelFetchOffset/' + stage + '-' + sampler] = concurrent_test('texelFetch offset ' + stage + ' ' + sampler)
 	# texelFetch() with EXT_texture_swizzle mode "b0r1":
 	for type in ['i', 'u', '']:
 		spec['glsl-1.30/execution/texelFetch/' + stage + '-texelFetch-' + type + 'sampler2DArray-swizzle'] = concurrent_test('texelFetch ' + stage + ' ' + type + 'sampler2DArray b0r1')
@@ -998,6 +999,7 @@ for stage in ['vs', 'fs']:
 	# texelFetch():
 	for sampler in ['sampler2DRect', 'usampler2DRect', 'isampler2DRect']:
 		spec['glsl-1.40/execution/texelFetch/' + stage + '-texelFetch-' + sampler] = concurrent_test('texelFetch 140 ' + stage + ' ' + sampler)
+		spec['glsl-1.40/execution/texelFetchOffset/' + stage + '-' + sampler] = concurrent_test('texelFetch offset 140 ' + stage + ' ' + sampler)
 
 # Group AMD_conservative_depth
 spec['AMD_conservative_depth'] = Group()
diff --git a/tests/texturing/shaders/texelFetch.c b/tests/texturing/shaders/texelFetch.c
index b0522e6..0d02053 100644
--- a/tests/texturing/shaders/texelFetch.c
+++ b/tests/texturing/shaders/texelFetch.c
@@ -85,6 +85,15 @@ int piglit_window_mode = GLUT_RGBA | GLUT_DOUBLE;
 const int pos_loc = 0;
 const int texcoord_loc = 1;
 
+/** Whether we're testing texelFetchOffset() instead of texelFetch(). */
+static bool test_offset = false;
+const int fetch_x_offset = 7;
+const int fetch_y_offset = -8;
+const int fetch_z_offset = 4;
+const char *fetch_1d_arg = ", int(7)";
+const char *fetch_2d_arg = ", ivec2(7, -8)";
+const char *fetch_3d_arg = ", ivec3(7, -8, 4)";
+
 /** Uniform locations */
 int divisor_loc;
 
@@ -204,6 +213,15 @@ generate_VBOs()
 					tc[1] = array_1D ? z : y;
 					tc[2] = z;
 					tc[3] = l;
+
+					if (test_offset) {
+						tc[0] -= fetch_x_offset;
+						if (sampler.target != GL_TEXTURE_1D_ARRAY)
+							tc[1] -= fetch_y_offset;
+						if (sampler.target != GL_TEXTURE_2D_ARRAY)
+							tc[2] -= fetch_z_offset;
+					}
+
 					tc += 4;
 				}
 			}
@@ -365,6 +383,28 @@ generate_GLSL(enum shader_target test_stage)
 
 	static char *vs_code;
 	static char *fs_code;
+	const char *offset_func, *offset_arg;
+
+	if (test_offset) {
+		offset_func = "Offset";
+		switch (sampler.target) {
+		case GL_TEXTURE_1D:
+		case GL_TEXTURE_1D_ARRAY:
+			offset_arg = fetch_1d_arg;
+			break;
+		case GL_TEXTURE_2D:
+		case GL_TEXTURE_2D_ARRAY:
+		case GL_TEXTURE_RECTANGLE:
+			offset_arg = fetch_2d_arg;
+			break;
+		case GL_TEXTURE_3D:
+			offset_arg = fetch_3d_arg;
+			break;
+		}
+	} else {
+		offset_func = "";
+		offset_arg = "";
+	}
 
 	switch (test_stage) {
 	case VS:
@@ -377,13 +417,16 @@ generate_GLSL(enum shader_target test_stage)
 			 "uniform %s tex;\n"
 			 "void main()\n"
 			 "{\n"
-			 "    color = texelFetch(tex, ivec%d(texcoord)%s);\n"
+			 "    color = texelFetch%s(tex, ivec%d(texcoord)%s%s);\n"
 			 "    gl_Position = pos;\n"
 			 "}\n",
 			 shader_version,
-			 sampler.return_type, sampler.name, coordinate_size(),
+			 sampler.return_type, sampler.name,
+			 offset_func,
+			 coordinate_size(),
 			 ((sampler.target == GL_TEXTURE_RECTANGLE) ?
-			  "" : ", texcoord.w"));
+			  "" : ", texcoord.w"),
+			 offset_arg);
 		asprintf(&fs_code,
 			 "#version %d\n"
 			 "flat in %s color;\n"
@@ -416,13 +459,16 @@ generate_GLSL(enum shader_target test_stage)
 			 "uniform %s tex;\n"
 			 "void main()\n"
 			 "{\n"
-			 "    vec4 color = texelFetch(tex, ivec%d(tc)%s);\n"
+			 "    vec4 color = texelFetch%s(tex, ivec%d(tc)%s%s);\n"
 			 "    gl_FragColor = color/divisor;\n"
 			 "}\n",
 			 shader_version,
-			 sampler.name, coordinate_size(),
+			 sampler.name,
+			 offset_func,
+			 coordinate_size(),
 			 (sampler.target == GL_TEXTURE_RECTANGLE ?
-			  "" : ", tc.w"));
+			  "" : ", tc.w"),
+			 offset_arg);
 		break;
 	default:
 		assert(!"Should not get here.");
@@ -430,7 +476,15 @@ generate_GLSL(enum shader_target test_stage)
 	}
 
 	vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vs_code);
+	if (!vs) {
+		printf("VS code:\n%s", vs_code);
+		piglit_report_result(PIGLIT_FAIL);
+	}
 	fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fs_code);
+	if (!fs) {
+		printf("FS code:\n%s", fs_code);
+		piglit_report_result(PIGLIT_FAIL);
+	}
 	prog = piglit_CreateProgram();
 	piglit_AttachShader(prog, vs);
 	piglit_AttachShader(prog, fs);
@@ -439,7 +493,8 @@ generate_GLSL(enum shader_target test_stage)
 	glBindAttribLocation(prog, texcoord_loc, "texcoord");
 
 	piglit_LinkProgram(prog);
-	piglit_link_check_status(prog);
+	if (!piglit_link_check_status(prog))
+		piglit_report_result(PIGLIT_FAIL);
 
 	return prog;
 }
@@ -476,7 +531,8 @@ supported_sampler()
 void
 fail_and_show_usage()
 {
-	printf("Usage: texelFetch <vs|fs> <sampler type> [piglit args...]\n");
+	printf("Usage: texelFetch [140] [offset] <vs|fs> <sampler type> "
+	       "[piglit args...]\n");
 	piglit_report_result(PIGLIT_FAIL);
 }
 
@@ -506,6 +562,11 @@ piglit_init(int argc, char **argv)
 			continue;
 		}
 
+		if (strcmp(argv[i], "offset") == 0) {
+			test_offset = true;
+			continue;
+		}
+
 		/* Maybe it's the sampler type? */
 		if (!sampler_found && (sampler_found = select_sampler(argv[i])))
 			continue;
-- 
1.7.10



More information about the Piglit mailing list