[Piglit] [PATCH] Add depth buffer testing to sample-alpha-to-coverage test

Anuj Phogat anuj.phogat at gmail.com
Tue Jun 26 17:38:34 PDT 2012


Tests the depth buffer only for coverage value equal to 0.0 and 1.0. Depth
buffer behaviour is undefined for intermediate coverage values.
This test found an issue with the current implemantation of msaa for i965
on mesa. Following patch fixes this issue on mesa:
[PATCH] i965/msaa: Set KILL_ENABLE when GL_ALPHA_TO_COVERAGE enabled
commit 6c355cca9149e43850cf27f2d0821fab1e7a69f5

Signed-off-by: Anuj Phogat <anuj.phogat at gmail.com>
---

 tests/all.tests                                    |    9 +-
 .../sample-alpha-to-coverage.cpp                   |  111 ++++++++++++++++----
 2 files changed, 96 insertions(+), 24 deletions(-)

diff --git a/tests/all.tests b/tests/all.tests
index a533a0a..215ac9c 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -1410,10 +1410,11 @@ for num_samples in MSAA_SAMPLE_COUNTS:
                 ext_framebuffer_multisample[test_name] = PlainExecTest(executable)
 
 for num_samples in MSAA_SAMPLE_COUNTS:
-        test_name = ' '.join(['sample-alpha-to-coverage', str(num_samples)])
-        executable = 'ext_framebuffer_multisample-{0} -auto'.format(
-                test_name)
-        ext_framebuffer_multisample[test_name] = PlainExecTest(executable)
+        for buffer_type in ('color', 'depth'):
+                test_name = ' '.join(['sample-alpha-to-coverage', str(num_samples), buffer_type])
+                executable = 'ext_framebuffer_multisample-{0} -auto'.format(
+                        test_name)
+                ext_framebuffer_multisample[test_name] = PlainExecTest(executable)
 
 for num_samples in MSAA_SAMPLE_COUNTS:
         test_name = ' '.join(['sample-alpha-to-one', str(num_samples)])
diff --git a/tests/spec/ext_framebuffer_multisample/sample-alpha-to-coverage.cpp b/tests/spec/ext_framebuffer_multisample/sample-alpha-to-coverage.cpp
index 28ae633..56f2cf2 100644
--- a/tests/spec/ext_framebuffer_multisample/sample-alpha-to-coverage.cpp
+++ b/tests/spec/ext_framebuffer_multisample/sample-alpha-to-coverage.cpp
@@ -35,11 +35,11 @@
  * is used as reference image to visually compare the difference caused by
  * sample alpha to coverage value.
  *
- * Compute the expected color values based on the coverage value used to
- * draw the test pattern.
+ * Compute the expected color / depth values based on the coverage value used
+ * to draw the test pattern.
  *
- * Clear the multisample framebuffer to a unique color. Draw the same test
- * pattern in multisample buffer with GL_SAMPLE_ALPHA_TO_COVERAGE enabled.
+ * Clear the multisample framebuffer to a unique color / depth. Draw the same
+ * test pattern in multisample buffer with GL_SAMPLE_ALPHA_TO_COVERAGE enabled.
  * Resolve the multisample FBO by  blitting it to a single sample FBO. Blit
  * the resolve_fbo to bottom half of window system framebuffer. This is our
  * test image.
@@ -47,28 +47,31 @@
  * Probe the rectangles in bottom half of window system framebuffer and
  * compare with expected color values. OpenGL 3.0 specification intends
  * to allow (but not require) the implementation to produce a dithering
- * effect when the coverage value is not a strict multiple of 1/num_samples.
+ * effect when the coverage value is not a strict multiple of 1 / num_samples.
  * We will skip computing expected values and probing for such rectangles.
  * They are drawn just to look for dithering by human inspection.
  *
+ * In case of depth buffer, only probe the rectangles with coverage value
+ * equal to 0.0 or 1.0.
+ *
  * Repeat the above testing with GL_SAMPLE_ALPHA_TO_ONE enabled / disabled.
  * when both GL_SAMPLE_ALPHA_TO_ONE and GL_SAMPLE_ALPHA_TO_COVERAGE are
  * enabled, GL_SAMPLE_ALPHA_TO_COVERAGE takes effect first. i.e. the
  * coverage value is computed from the alpha value before the alpha value
  * is changed to 1.
  *
- * Note: glSampleCoverage() takes effect in the graphics pipeline before
- * the point where the output of the fragment shader is split into the
- * various buffers. So it's very likely that if glSampleCoverage() works
- * properly for color buffers, it will work properly for depth and stencil
- * buffers too.
+ * The test accepts following command line options:
+ * <num_samples>
+ * <test_type> :  color or depth
+ *
+ * TODO : Add stencil buffer testing.
  *
  * Author: Anuj Phogat <anuj.phogat at gmail.com>
  */
 
 PIGLIT_GL_TEST_MAIN(512 /*window_width*/,
 		    256 /*window_height*/,
-		    GLUT_DOUBLE | GLUT_RGBA | GLUT_ALPHA)
+		    GLUT_DOUBLE | GLUT_RGBA | GLUT_ALPHA | GLUT_DEPTH)
 
 const int pattern_width = 512; const int pattern_height = 128;
 static Fbo ms_fbo, resolve_fbo;
@@ -76,6 +79,7 @@ static GLbitfield buffer_to_test;
 
 static float *coverage = NULL;
 static float *color = NULL;
+static float *depth = NULL;
 static float *expected = NULL;
 
 static int num_samples;
@@ -84,8 +88,12 @@ static int prog;
 static int color_loc;
 static int depth_loc;
 
+static const float bg_depth = 0.8;
 static const float bg_color[4] = { 0.4, 0.6, 0.0, 0.8 };
 
+/* Offset the viewport transformation on depth value passed to the
+ * vertex shader by setting it to 2 * depth - 1.0.
+ */
 static const char *vert =
 	"#version 130\n"
 	"in vec2 pos;\n"
@@ -93,7 +101,7 @@ static const char *vert =
 	"void main()\n"
 	"{\n"
 	"  vec4 eye_pos = gl_ModelViewProjectionMatrix * vec4(pos, 0.0, 1.0);\n"
-	"  gl_Position = vec4(eye_pos.xy, depth, 1.0);\n"
+	"  gl_Position = vec4(eye_pos.xy, 2 * depth - 1.0, 1.0);\n"
 	"}\n";
 
 static const char *frag =
@@ -154,7 +162,7 @@ draw_pattern(bool sample_alpha_to_coverage, bool sample_alpha_to_one)
 				      (void *) vertex_data);
 
 		glUniform4fv(color_loc, 1, (color + i * 4));
-		glUniform1f(depth_loc, 0.0f);
+		glUniform1f(depth_loc, depth[i]);
 		glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT,
 			       (void *) indices);
 	}
@@ -168,7 +176,11 @@ draw_pattern(bool sample_alpha_to_coverage, bool sample_alpha_to_one)
 void
 print_usage_and_exit(char *prog_name)
 {
-	printf("Usage: %s <num_samples>\n", prog_name);
+	printf("Usage: %s <num_samples> <test_type>\n"
+	       "  where <test_type> is one of:\n"
+	       "    color\n"
+	       "    depth\n",
+	       prog_name);
 	piglit_report_result(PIGLIT_FAIL);
 }
 
@@ -185,8 +197,10 @@ compute_expected(bool sample_alpha_to_one)
 	}
 
 	/* Fragment's alpha value is directly used as coverage value */
-	for (i = 0; i < num_rects; i++)
-		coverage[i] = color[i * 4 + 3];
+	for (i = 0; i < num_rects; i++) {
+		float alpha = color[i * 4 + 3];
+		coverage[i] = (alpha < 1.0) ? alpha : 1.0;
+	}
 
 	/* Coverage value decides the number of samples in multisample buffer
 	 * covered by an incoming fragment, which will then receive the fragment
@@ -218,6 +232,16 @@ compute_expected(bool sample_alpha_to_one)
 			}
 		}
 	}
+	/* Compute the expected depth values only for coverage = 0.0 and 1.0 */
+	else if(buffer_to_test == GL_DEPTH_BUFFER_BIT) {
+		for (i = 0; i < num_rects; i++) {
+			if (coverage[i] == 0.0)
+				expected[i] = bg_depth;
+			else if (coverage[i] == 1.0)
+				expected[i] = (depth[i] < 1.0) ? depth[i] : 1.0;
+		}
+	}
+
 }
 
 bool
@@ -246,6 +270,30 @@ probe_framebuffer_color(bool sample_alpha_to_one)
 }
 
 bool
+probe_framebuffer_depth(void)
+{
+	bool result = true;
+	glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
+	for (int i = 0; i < num_rects; i++) {
+		if(coverage[i] == 0.0 || coverage[i] == 1.0) {
+			result = piglit_probe_rect_depth(
+				 i * (pattern_width / num_rects),
+				 0,
+				 pattern_width / num_rects,
+				 pattern_height,
+				 expected[i])
+				 && result;
+		}
+		else {
+		/*Skip probing polygons which are drawn with fractional
+		 * coverage value (between 0.0 and 1.0)*/
+			continue;
+		}
+	}
+	return result;
+}
+
+bool
 test_sample_alpha_to_coverage(bool sample_alpha_to_one)
 {
 	bool result = true;
@@ -277,6 +325,8 @@ test_sample_alpha_to_coverage(bool sample_alpha_to_one)
 	 * expected values */
 	if (buffer_to_test == GL_COLOR_BUFFER_BIT)
 		result = probe_framebuffer_color(sample_alpha_to_one) && result;
+	else if (buffer_to_test == GL_DEPTH_BUFFER_BIT)
+		result = probe_framebuffer_depth() && result;
 
 	result = piglit_check_gl_error(GL_NO_ERROR) && result;
 	return result;
@@ -292,6 +342,7 @@ allocate_data_arrays(void)
 
 	/* Allocate data arrays based on number of samples used */
 	color = (float *) malloc(num_rects * 4 * sizeof(float));
+	depth = (float *) malloc(num_rects * sizeof(float));
 	coverage = (float *) malloc(num_rects * sizeof(float));
 	expected = (float *) malloc(num_rects * 4 * sizeof(float));
 
@@ -300,8 +351,14 @@ allocate_data_arrays(void)
 		color[i * 4 + 1] = (sin((float)(i * 4 + 1)) + 1) / 2;
 		color[i * 4 + 2] = (sin((float)(i * 4 + 2)) + 1) / 2;
 
-		/* Alpha value will be used as coverage */
-		color[i * 4 + 3] = i * (1.0 / (2 * num_samples));
+		/* Alpha value will be directly used as coverage */
+		if(buffer_to_test == GL_COLOR_BUFFER_BIT)
+			color[i * 4 + 3] = i * (1.0 / (2 * num_samples));
+
+		else if(buffer_to_test == GL_DEPTH_BUFFER_BIT)
+			color[i * 4 + 3] = i / num_samples;
+
+		depth[i] =  i * (1.0 / (4 * num_samples));
 	}
 }
 
@@ -312,6 +369,10 @@ free_data_arrays(void)
 		free(color);
 		color = NULL;
 	}
+	if(depth != NULL) {
+		free(depth);
+		depth = NULL;
+	}
 	if(coverage != NULL) {
 		free(coverage);
 		coverage = NULL;
@@ -326,7 +387,7 @@ void
 piglit_init(int argc, char **argv)
 {
 	int samples;
-	if (argc < 2)
+	if (argc < 3)
 		print_usage_and_exit(argv[0]);
 	{
 		char *endptr = NULL;
@@ -354,6 +415,17 @@ piglit_init(int argc, char **argv)
 		piglit_report_result(PIGLIT_FAIL);
         }
 
+	if (strcmp(argv[2], "color") == 0) {
+		buffer_to_test = GL_COLOR_BUFFER_BIT;
+	} else if (strcmp(argv[2], "depth") == 0) {
+		buffer_to_test = GL_DEPTH_BUFFER_BIT;
+		glClearDepth(bg_depth);
+		glEnable(GL_DEPTH_TEST);
+		glDepthFunc(GL_ALWAYS);
+	} else
+		print_usage_and_exit(argv[0]);
+
+
 	/* Query the number of samples used in ms_fbo. OpenGL implementation
 	 * may create FBO with more samples per pixel than what is requested.
 	 */
@@ -362,7 +434,6 @@ piglit_init(int argc, char **argv)
 				     GL_RENDERBUFFER_SAMPLES,
 				     &num_samples);
 
-	buffer_to_test = GL_COLOR_BUFFER_BIT;
 	shader_compile();
 }
 
-- 
1.7.7.6



More information about the Piglit mailing list