[Piglit] [PATCH] Fix fragcoord tests to check for the pixel center

Neil Roberts neil at linux.intel.com
Thu Oct 8 02:59:29 PDT 2015


Preivously the frag coord tests were effectively trying to assert that
the results for gl_FragCoord were aligned to whole numbers, ie that it
reports the bottom left edge of the pixel. However by default
gl_FragCoord actually reports the center of the pixel, so the bottom
left pixel would be reported as 0.5,0.5. The test was passing anyway
because it scales the results from gl_FragCoord to fit within
[0.0,1.0) and so the difference is within Piglit's tolerance.

This patch makes the tests more strict by creating an RGBA buffer
instead of just RGB and storing the fractional part of gl_FragCoord in
the BA components. It then verifies that these are both 0.5.
---
 tests/fbo/fbo-fragcoord.c            | 44 ++++++++++++++++++++++++-----------
 tests/shaders/glsl-fs-fragcoord.c    | 45 ++++++++++++++++++++++++------------
 tests/shaders/glsl-fs-fragcoord.frag |  2 +-
 3 files changed, 61 insertions(+), 30 deletions(-)

diff --git a/tests/fbo/fbo-fragcoord.c b/tests/fbo/fbo-fragcoord.c
index 6d1befd..b26182b 100644
--- a/tests/fbo/fbo-fragcoord.c
+++ b/tests/fbo/fbo-fragcoord.c
@@ -88,10 +88,38 @@ create_fbo(unsigned width, unsigned height, GLuint *out_tex)
 	return fb;
 }
 
+static bool
+check_results(void)
+{
+	float *expected_results =
+		malloc(sizeof *expected_results *
+		       piglit_width * piglit_height * 4);
+	float *p = expected_results;
+	int y, x;
+	bool result;
+
+	for (y = 0; y < piglit_height; y++) {
+		for (x = 0; x < piglit_width; x++) {
+			*(p++) = x / (float) piglit_width;
+			*(p++) = y / (float) piglit_height;
+			*(p++) = 0.5f;
+			*(p++) = 0.5f;
+		}
+	}
+
+	result = piglit_probe_image_color(0, 0, piglit_width, piglit_height,
+					  GL_RGBA,
+					  expected_results);
+
+	free(expected_results);
+
+	return result;
+}
+
 enum piglit_result
 piglit_display(void)
 {
-	GLboolean pass = GL_TRUE;
+	GLboolean pass;
 	int x, y;
 	GLuint fb, tex;
 
@@ -126,19 +154,7 @@ piglit_display(void)
 	if (!piglit_check_gl_error(GL_NO_ERROR))
 		piglit_report_result(PIGLIT_FAIL);
 
-	for (y = 0; y < piglit_height; y++) {
-		for (x = 0; x < piglit_width; x++) {
-			float color[3];
-
-			color[0] = x / 256.0;
-			color[1] = y / 256.0;
-			color[2] = 0;
-
-			pass &= piglit_probe_pixel_rgb(x, y, color);
-			if (!pass)
-				break;
-		}
-	}
+	pass = check_results();
 
 	piglit_present_results();
 
diff --git a/tests/shaders/glsl-fs-fragcoord.c b/tests/shaders/glsl-fs-fragcoord.c
index 29b1bca..21ad7b8 100644
--- a/tests/shaders/glsl-fs-fragcoord.c
+++ b/tests/shaders/glsl-fs-fragcoord.c
@@ -38,36 +38,51 @@ PIGLIT_GL_TEST_CONFIG_BEGIN
 
 	config.window_width = 256;
 	config.window_height = 256;
-	config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
+	config.window_visual = PIGLIT_GL_VISUAL_RGBA | PIGLIT_GL_VISUAL_DOUBLE;
 
 PIGLIT_GL_TEST_CONFIG_END
 
 static GLint prog;
 
+static bool
+check_results(void)
+{
+	float *expected_results =
+		malloc(sizeof *expected_results *
+		       piglit_width * piglit_height * 4);
+	float *p = expected_results;
+	int y, x;
+	bool result;
+
+	for (y = 0; y < piglit_height; y++) {
+		for (x = 0; x < piglit_width; x++) {
+			*(p++) = x / (float) piglit_width;
+			*(p++) = y / (float) piglit_height;
+			*(p++) = 0.5f;
+			*(p++) = 0.5f;
+		}
+	}
+
+	result = piglit_probe_image_color(0, 0, piglit_width, piglit_height,
+					  GL_RGBA,
+					  expected_results);
+
+	free(expected_results);
+
+	return result;
+}
+
 enum piglit_result
 piglit_display(void)
 {
 	GLboolean pass = GL_TRUE;
-	int x, y;
 
 	glClearColor(0.5, 0.5, 0.5, 0.5);
 	glClear(GL_COLOR_BUFFER_BIT);
 
 	piglit_draw_rect(0, 0, piglit_width, piglit_height);
 
-	for (y = 8; y < piglit_height && pass; y += 16) {
-		for (x = 8; x < piglit_width; x += 16) {
-			float color[3];
-
-			color[0] = x / 256.0;
-			color[1] = y / 256.0;
-			color[2] = 0;
-
-			pass &= piglit_probe_pixel_rgb(x, y, color);
-			if (!pass)
-				break;
-		}
-	}
+	check_results();
 
 	piglit_present_results();
 
diff --git a/tests/shaders/glsl-fs-fragcoord.frag b/tests/shaders/glsl-fs-fragcoord.frag
index 17a6c58..08f51d2 100644
--- a/tests/shaders/glsl-fs-fragcoord.frag
+++ b/tests/shaders/glsl-fs-fragcoord.frag
@@ -1,4 +1,4 @@
 void main()
 {
-	gl_FragColor = vec4(gl_FragCoord.x / 256.0, gl_FragCoord.y / 256.0, 0, 0);
+	gl_FragColor = vec4(gl_FragCoord.xy / 256.0, fract(gl_FragCoord.xy));
 }
-- 
1.9.3



More information about the Piglit mailing list