On 8 June 2012 14:45, <span dir="ltr"><<a href="mailto:anuj.phogat@gmail.com" target="_blank">anuj.phogat@gmail.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
From: Anuj Phogat <<a href="mailto:anuj.phogat@gmail.com">anuj.phogat@gmail.com</a>><br>
<br>
This test varifies that with GL_SAMPLE_ALPHA_TO_COVERAGE enabled, the coverage<br>
value is set by fragment alpha value. Coverage value decides the number of<br>
samples in multisample buffer covered by an incoming fragment, which receive<br>
the fragment data.<br>
<br>
It also includes testing of sample alpha to coverage with GL_SAMPLE_ALPHA_TO_ONE<br>
enabled/disabled.<br>
<br>
Note: Test fails for depth buffer on NVIDIA's proprietary drivers. Depth buffer is<br>
not modified even if the incoming multisample fragment passes the depth test<br>
and has a coverage = 1.0.<br></blockquote><div><br>Most of my comments from the previous patch apply to this patch as well.<br> </div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
Signed-off-by: Anuj Phogat <<a href="mailto:anuj.phogat@gmail.com">anuj.phogat@gmail.com</a>><br>
---<br>
tests/all.tests | 7 +<br>
.../ext_framebuffer_multisample/CMakeLists.gl.txt | 1 +<br>
.../sample-alpha-to-coverage.cpp | 375 ++++++++++++++++++++<br>
3 files changed, 383 insertions(+), 0 deletions(-)<br>
create mode 100644 tests/spec/ext_framebuffer_multisample/sample-alpha-to-coverage.cpp<br>
<br>
diff --git a/tests/all.tests b/tests/all.tests<br>
index a52b745..0e531b8 100644<br>
--- a/tests/all.tests<br>
+++ b/tests/all.tests<br>
@@ -1393,6 +1393,13 @@ for num_samples in (2, 4, 8, 16, 32):<br>
test_name)<br>
ext_framebuffer_multisample[test_name] = PlainExecTest(executable)<br>
<br>
+for num_samples in (2, 4, 8, 16, 32):<br>
+ for buffer_type in ('color', 'depth'):<br>
+ test_name = ' '.join(['sample-alpha-to-coverage', str(num_samples), buffer_type])<br>
+ executable = 'ext_framebuffer_multisample-{0} -auto'.format(<br>
+ test_name)<br>
+ ext_framebuffer_multisample[test_name] = PlainExecTest(executable)<br>
+<br>
ext_framebuffer_object = Group()<br>
spec['EXT_framebuffer_object'] = ext_framebuffer_object<br>
add_fbo_stencil_tests(ext_framebuffer_object, 'GL_STENCIL_INDEX1')<br>
diff --git a/tests/spec/ext_framebuffer_multisample/CMakeLists.gl.txt b/tests/spec/ext_framebuffer_multisample/CMakeLists.gl.txt<br>
index 17a9571..a6595fa 100644<br>
--- a/tests/spec/ext_framebuffer_multisample/CMakeLists.gl.txt<br>
+++ b/tests/spec/ext_framebuffer_multisample/CMakeLists.gl.txt<br>
@@ -27,6 +27,7 @@ piglit_add_executable (ext_framebuffer_multisample-renderbuffer-samples renderbu<br>
piglit_add_executable (ext_framebuffer_multisample-renderbufferstorage-samples renderbufferstorage-samples.c)<br>
piglit_add_executable (ext_framebuffer_multisample-samples samples.c)<br>
piglit_add_executable (ext_framebuffer_multisample-sample-coverage common.cpp sample-coverage.cpp)<br>
+piglit_add_executable (ext_framebuffer_multisample-sample-alpha-to-coverage common.cpp sample-alpha-to-coverage.cpp)<br>
piglit_add_executable (ext_framebuffer_multisample-turn-on-off common.cpp turn-on-off.cpp)<br>
piglit_add_executable (ext_framebuffer_multisample-unaligned-blit common.cpp unaligned-blit.cpp)<br>
piglit_add_executable (ext_framebuffer_multisample-upsample common.cpp upsample.cpp)<br>
diff --git a/tests/spec/ext_framebuffer_multisample/sample-alpha-to-coverage.cpp b/tests/spec/ext_framebuffer_multisample/sample-alpha-to-coverage.cpp<br>
new file mode 100644<br>
index 0000000..59a365b<br>
--- /dev/null<br>
+++ b/tests/spec/ext_framebuffer_multisample/sample-alpha-to-coverage.cpp<br>
@@ -0,0 +1,375 @@<br>
+/*<br>
+ * Copyright © 2012 Intel Corporation<br>
+ *<br>
+ * Permission is hereby granted, free of charge, to any person obtaining a<br>
+ * copy of this software and associated documentation files (the "Software"),<br>
+ * to deal in the Software without restriction, including without limitation<br>
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,<br>
+ * and/or sell copies of the Software, and to permit persons to whom the<br>
+ * Software is furnished to do so, subject to the following conditions:<br>
+ *<br>
+ * The above copyright notice and this permission notice (including the next<br>
+ * paragraph) shall be included in all copies or substantial portions of the<br>
+ * Software.<br>
+ *<br>
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br>
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br>
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL<br>
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br>
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING<br>
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS<br>
+ * IN THE SOFTWARE.<br>
+ */<br>
+<br>
+#include "common.h"<br>
+<br>
+/**<br>
+ * \file sample-alpha-to-coverage.cpp<br>
+ *<br>
+ * Verify glSampleCoverage() with and without coverage mask invert<br>
+ *<br>
+ * This test operates by drawing test pattern in a multisample FBO with<br>
+ * GL_SAMPLE_ALPHA_TO_COVERAGE disabled.<br>
+ *<br>
+ * Blit the multisample_fbo to right half of window system framebuffer.<br>
+ * This is used as reference image to see the visual difference caused by<br>
+ * the alpha value.<br>
+ *<br>
+ * Compute the expected color values based on the coverage value used to<br>
+ * draw the test pattern.<br>
+ *<br>
+ * Clear the multisample framebuffer to a unique color/depth. Draws<br>
+ * the same test pattern for the second time in multisample buffer with<br>
+ * GL_SAMPLE_ALPHA_TO_COVERAGE enabled. Resolve the multisample FBO by<br>
+ * blitting it to a single sample FBO. Blit the resolve_fbo to left half<br>
+ * of window system framebuffer. This is the test image.<br>
+ *<br>
+ * Probe the left half of window syetem framebuffer and compare with expected<br>
+ * color values.<br>
+ *<br>
+ * Repeat the above testing with GL_SAMPLE_ALPHA_TO_ONE enabled as well.<br>
+ *<br>
+ * Author: Anuj Phogat <<a href="mailto:anuj.phogat@gmail.com">anuj.phogat@gmail.com</a>><br>
+ */<br>
+<br>
+int piglit_width = 512; int piglit_height = 256;<br>
+int piglit_window_mode =<br>
+ GLUT_DOUBLE | GLUT_RGBA | GLUT_ALPHA | GLUT_DEPTH;<br>
+const int pattern_width = 256; const int pattern_height = 256;<br>
+<br>
+static Fbo ms_fbo, resolve_fbo;<br>
+static GLint num_samples;<br>
+static float expected[4][4];<br>
+static float coverage[4];<br>
+static GLbitfield buffer_to_test;<br>
+<br>
+static const float bg_depth = 0.80;<br>
+static const float bg_color[4] =<br>
+ {0.0, 0.0, 1.0, 0.8};<br>
+<br>
+static const float depth[4] =<br>
+ {0.0, 0.25, 0.60, 0.70};<br>
+<br>
+static const float color[4][4] = {<br>
+ /* Red */<br>
+ {1.0, 0.0, 0.0, 0.0},<br>
+ /* Green */<br>
+ {0.0, 1.0, 0.0, 0.25},<br>
+ /* Yellow */<br>
+ {1.0, 1.0, 0.0, 0.75},<br>
+ /* Cyan */<br>
+ {0.0, 1.0, 1.0, 1.0} };<br>
+<br>
+static GLint prog;<br>
+static GLint color_loc;<br>
+static GLint depth_loc;<br>
+<br>
+static const char *vert =<br>
+ "#version 130\n"<br>
+ "in vec2 pos;\n"<br>
+ "uniform float depth;\n"<br>
+ "void main()\n"<br>
+ "{\n"<br>
+ " vec4 eye_pos = gl_ModelViewProjectionMatrix * vec4(pos, 0.0, 1.0);\n"<br>
+ " gl_Position = vec4(eye_pos.xy, depth, 1.0);\n"<br>
+ "}\n";<br>
+<br>
+static const char *frag =<br>
+ "#version 130\n"<br>
+ "uniform vec4 color;\n"<br>
+ "void main()\n"<br>
+ "{\n"<br>
+ " gl_FragColor = color;\n"<br>
+ "}\n";<br>
+<br>
+void<br>
+shader_compile()<br>
+{<br>
+ /* Compile program */<br>
+ GLint vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vert);<br>
+ GLint fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, frag);<br>
+ prog = piglit_link_simple_program(vs, fs);<br>
+<br>
+ if (!piglit_link_check_status(prog)) {<br>
+ piglit_report_result(PIGLIT_FAIL);<br>
+ }<br>
+<br>
+ glBindAttribLocation(prog, 0, "pos");<br>
+ glEnableVertexAttribArray(0);<br>
+<br>
+ /* Set up uniforms */<br>
+ glUseProgram(prog);<br>
+ color_loc = glGetUniformLocation(prog, "color");<br>
+ depth_loc = glGetUniformLocation(prog, "depth");<br>
+}<br>
+<br>
+void<br>
+draw_pattern(bool sample_alpha_to_coverage, bool sample_alpha_to_one)<br>
+{<br>
+ float vertex_data[10][2] = {<br>
+ { 0, 0 },<br>
+ { 0, pattern_height },<br>
+ { pattern_width / 4, pattern_height },<br>
+ { pattern_width / 4, 0 },<br>
+ { pattern_width / 2, pattern_height },<br>
+ { pattern_width / 2, 0 },<br>
+ { 3 * pattern_width / 4, pattern_height },<br>
+ { 3 * pattern_width / 4, 0 },<br>
+ { pattern_width, pattern_height },<br>
+ { pattern_width, 0 },<br>
+ };<br>
+<br>
+ unsigned int indices[24] = {0, 1, 2, 0, 2, 3,<br>
+ 3, 2, 4, 3, 4, 5,<br>
+ 5, 4, 6, 5, 6, 7,<br>
+ 7, 6, 8, 7, 8, 9};<br>
+ glUseProgram(prog);<br>
+ glClearColor(bg_color[0], bg_color[1],<br>
+ bg_color[2], bg_color[3]);<br>
+ glClear(buffer_to_test);<br>
+ if (sample_alpha_to_coverage)<br>
+ glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE);<br>
+<br>
+ if (sample_alpha_to_one)<br>
+ glEnable(GL_SAMPLE_ALPHA_TO_ONE);<br>
+<br>
+ glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(vertex_data[0]),<br>
+ (void *) vertex_data);<br>
+<br>
+ for (int i = 0; i < 4; ++i) {<br>
+ glUniform4fv(color_loc, 1, color[i]);<br>
+ glUniform1f(depth_loc, depth[i]);<br>
+ glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT,<br>
+ (void *) (indices + 6 * i));<br>
+ }<br>
+ if (sample_alpha_to_coverage)<br>
+ glDisable (GL_SAMPLE_ALPHA_TO_COVERAGE);<br>
+<br>
+ if (sample_alpha_to_one)<br>
+ glDisable (GL_SAMPLE_ALPHA_TO_ONE);<br>
+}<br>
+<br>
+void<br>
+print_usage_and_exit(char *prog_name)<br>
+{<br>
+ printf("Usage: %s <num_samples> <buffer_type>\n"<br>
+ " where <buffer_type> is one of:\n"<br>
+ " color\n"<br>
+ " depth\n",<br>
+ prog_name);<br>
+ piglit_report_result(PIGLIT_FAIL);<br>
+}<br>
+<br>
+void<br>
+compute_expected(bool sample_alpha_to_one)<br>
+{<br>
+ int i, j;<br>
+<br>
+ /* Fragment's alpha value is directly used as coverage value */<br>
+ for (i = 0; i < 4; i++)<br>
+ coverage[i] = color[i][3];<br>
+<br>
+ /* Coverage value decides the number of samples in multisample buffer<br>
+ * covered by an incoming fragment, which will then receive the fragment<br>
+ * data. When the multisample buffer is resolved it will be blended<br>
+ * with the background color which will be written to the remaining<br>
+ * samples.<br>
+ * Page 254 (page 270 of the PDF) of the OpenGL 3.0 spec says:<br>
+ * "The method of combination is not specified, though a simple average<br>
+ * computed independently for each color component is recommended."<br>
+ */<br>
+ if(buffer_to_test == GL_COLOR_BUFFER_BIT) {<br>
+ for (i = 0; i < 4; i++) {<br>
+ for (j = 0; j < 4; j++)<br>
+ expected[i][j] = color[i][j] * coverage[i] +<br>
+ bg_color[j] * (1 - coverage[i]);<br>
+<br>
+ if (sample_alpha_to_one)<br>
+ expected[i][3] = 1.0 * coverage[i] +<br>
+ bg_color[3] * (1 - coverage[i]);<br>
+ }<br>
+ }<br>
+ /* Compute the expected depth values only for coverage = 0.0 and 1.0 */<br>
+ else if(buffer_to_test == GL_DEPTH_BUFFER_BIT) {<br>
+ for (i = 0; i < 4; i++) {<br>
+ if (coverage[i] == 0.0)<br>
+ expected[0][i] = bg_depth;<br>
+ else if (coverage[i] == 1.0)<br>
+ expected[0][i] = depth[i] < bg_depth ?<br>
+ depth[i] : bg_depth;<br>
+ }<br>
+ }<br>
+}<br>
+<br>
+bool<br>
+probe_framebuffer_color(void)<br>
+{<br>
+ bool result = true;<br>
+ glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);<br>
+ for (int i = 0; i < 4; i++) {<br>
+ result = piglit_probe_rect_rgba(i * (pattern_width / 4),<br>
+ 0,<br>
+ pattern_width / 4,<br>
+ pattern_height,<br>
+ expected[i])<br>
+ && result;<br>
+ }<br>
+ return result;<br>
+}<br>
+<br>
+bool<br>
+probe_framebuffer_depth(void)<br>
+{<br>
+ bool result = true;<br>
+ glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);<br>
+ for (int i = 0; i < 4; i++) {<br>
+ if(coverage[i] == 0.0 || coverage[i] == 1.0)<br>
+ result = piglit_probe_rect_depth(i * (pattern_width / 4),<br>
+ 0,<br>
+ pattern_width / 4,<br>
+ pattern_height,<br>
+ expected[0][i])<br>
+ && result;<br>
+ else<br>
+ /*Skip probing polygons which are drawn with coverage<br>
+ * value between 0.0 and 1.0<br>
+ */<br>
+ continue;<br>
+ }<br>
+ return result;<br>
+}<br>
+<br>
+bool<br>
+test_sample_alpha_to_coverage(bool sample_alpha_to_one)<br>
+{<br>
+ bool result = true;<br>
+ compute_expected(sample_alpha_to_one);<br>
+ /* Now draw test pattern in mulisample ms_fbo with GL_SAMPLE_ALPHA_TO_COVERAGE<br>
+ * enabled<br>
+ */<br>
+ glBindFramebuffer(GL_DRAW_FRAMEBUFFER, ms_fbo.handle);<br>
+ draw_pattern(true, sample_alpha_to_one);<br>
+<br>
+ /* Blit ms_fbo to resolve_fbo to resolve multisample buffer */<br>
+ glBindFramebuffer(GL_READ_FRAMEBUFFER, ms_fbo.handle);<br>
+ glBindFramebuffer(GL_DRAW_FRAMEBUFFER, resolve_fbo.handle);<br>
+ glBlitFramebuffer(0, 0, pattern_width, pattern_height,<br>
+ 0, 0, pattern_width, pattern_height,<br>
+ buffer_to_test, GL_NEAREST);<br>
+<br>
+ /* Blit resolve_fbo to the left half of window system framebuffer.<br>
+ * This is the test image.<br>
+ */<br>
+ glBindFramebuffer(GL_READ_FRAMEBUFFER, resolve_fbo.handle);<br>
+ glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);<br>
+ glBlitFramebuffer(0, 0, pattern_width, pattern_height,<br>
+ 0, 0, pattern_width, pattern_height,<br>
+ buffer_to_test, GL_NEAREST);<br>
+<br>
+ /* Probe the left half of default framebuffer and compare to the<br>
+ * expected values */<br>
+ if (buffer_to_test == GL_COLOR_BUFFER_BIT)<br>
+ result = probe_framebuffer_color() && result;<br>
+ else if (buffer_to_test == GL_DEPTH_BUFFER_BIT)<br>
+ result = probe_framebuffer_depth() && result;<br>
+<br>
+ result = piglit_check_gl_error(GL_NO_ERROR) && result;<br>
+ return result;<br>
+}<br>
+<br>
+<br>
+void<br>
+piglit_init(int argc, char **argv)<br>
+{<br>
+ if (argc < 3)<br>
+ print_usage_and_exit(argv[0]);<br>
+ {<br>
+ char *endptr = NULL;<br>
+ num_samples = strtol(argv[1], &endptr, 0);<br>
+ if (endptr != argv[1] + strlen(argv[1]))<br>
+ print_usage_and_exit(argv[0]);<br>
+ }<br>
+<br>
+ piglit_require_gl_version(30);<br>
+ piglit_ortho_projection(pattern_width, pattern_height, GL_TRUE);<br>
+<br>
+ /* Skip the test if num_samples > GL_MAX_SAMPLES or num_samples = 0 */<br>
+ GLint max_samples;<br>
+ glGetIntegerv(GL_MAX_SAMPLES, &max_samples);<br>
+ if (num_samples > max_samples ||<br>
+ num_samples == 0)<br>
+ piglit_report_result(PIGLIT_SKIP);<br>
+<br>
+ ms_fbo.setup(FboConfig(num_samples, pattern_width, pattern_height));<br>
+ resolve_fbo.setup(FboConfig(num_samples, pattern_width, pattern_height));<br>
+<br>
+ if (strcmp(argv[2], "color") == 0) {<br>
+ buffer_to_test = GL_COLOR_BUFFER_BIT;<br>
+ } else if (strcmp(argv[2], "depth") == 0) {<br>
+ buffer_to_test = GL_DEPTH_BUFFER_BIT;<br>
+ glClearDepth(bg_depth);<br>
+ glEnable(GL_DEPTH_TEST);<br>
+ } else<br>
+ print_usage_and_exit(argv[0]);<br>
+<br>
+ shader_compile();<br>
+}<br>
+<br>
+enum piglit_result<br>
+piglit_display()<br>
+{<br>
+ bool pass = true;<br>
+ glClearColor(0.0, 0.0, 0.0, 1.0);<br>
+ glClear(GL_COLOR_BUFFER_BIT);<br>
+<br>
+ /* Draw test pattern in multisample ms_fbo with GL_POLYGON_SMOOTH<br>
+ * disabled.<br>
+ */<br>
+ glBindFramebuffer(GL_DRAW_FRAMEBUFFER, ms_fbo.handle);<br>
+ ms_fbo.set_viewport();<br>
+ draw_pattern(false, false);<br>
+<br>
+ /* Blit ms_fbo to the right half of window system framebuffer. This<br>
+ * is a reference image to test MSAA with polygon smooth.<br>
+ */<br>
+ glBindFramebuffer(GL_READ_FRAMEBUFFER, ms_fbo.handle);<br>
+ glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);<br>
+ glBlitFramebuffer(0, 0, pattern_width, pattern_height,<br>
+ pattern_width, 0, 2 * pattern_width, pattern_height,<br>
+ buffer_to_test, GL_NEAREST);<br>
+<br>
+ /* Test with GL_SAMPLE_ALPHA_TO_ONE disabled<br>
+ */<br>
+ pass = test_sample_alpha_to_coverage(false /* sample_alpha_to_one */)<br>
+ && pass;<br>
+<br>
+ /* Test with GL_SAMPLE_ALPHA_TO_ONE enabled */<br>
+ pass = test_sample_alpha_to_coverage(true /* sample_alpha_to_one */)<br>
+ && pass;<br>
+<br>
+ if (!piglit_automatic &&<br>
+ buffer_to_test != GL_DEPTH_BUFFER_BIT)<br>
+ piglit_present_results();<br>
+<br>
+ return pass ? PIGLIT_PASS : PIGLIT_FAIL;<br>
+}<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.7.7.6<br>
<br>
</font></span><br>_______________________________________________<br>
Piglit mailing list<br>
<a href="mailto:Piglit@lists.freedesktop.org">Piglit@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/piglit" target="_blank">http://lists.freedesktop.org/mailman/listinfo/piglit</a><br>
<br></blockquote></div><br>