<div dir="ltr">On 25 October 2013 16:49, Anuj Phogat <span dir="ltr"><<a href="mailto:anuj.phogat@gmail.com" target="_blank">anuj.phogat@gmail.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">V2: Get rid of redundant projection matrix.<br>
Signed-off-by: Anuj Phogat <<a href="mailto:anuj.phogat@gmail.com">anuj.phogat@gmail.com</a>><br>
---<br>
 tests/all.tests                                    |   5 +<br>
 .../arb_sample_shading/execution/CMakeLists.gl.txt |   1 +<br>
 .../execution/builtin-gl-sample-mask.cpp           | 236 +++++++++++++++++++++<br>
 3 files changed, 242 insertions(+)<br>
 create mode 100644 tests/spec/arb_sample_shading/execution/builtin-gl-sample-mask.cpp<br></blockquote><div><br></div><div>I have similar concerns with this patch to the concerns I have with patch 3.  The test should be rewritten to use ARB_texture_multisample so that we can verify the correct mapping of gl_SampleMask bits to samples.  As it is, this test would still pass if the implementation got the bits in the wrong order.<br>
<br></div><div>Also, I notice that the loop in piglit_display() tests the following sequence of sample masks:<br><br></div><div>0x00<br></div><div>0x01<br></div><div>0x03<br></div><div>0x07<br></div><div>0x0f<br></div><div>
0x1f<br></div><div>0x3f<br></div><div>0x7f<br></div><div>0xff<br><br>That's a problem because:<br><br></div><div>(a) some implementations support >8 sample MSAA; on those implementations we only test the first 8 samples.<br>
</div><div><br>(b) all of the values tested consist of a sequence of 0 bits followed by a sequence of 1 bits.  We also need to test bit sequences which alternate between 1's and 0's.<br><br></div><div>(c) we aren't doing anything to verify that the upper bits of gl_SampleMask[0] (those beyond the first gl_NumSamples bits) are ignored.<br>
<br></div><div>(d) since we are setting gl_SampleMask[0] to a uniform value, we won't catch bugs if the implementation mixes up sample masks between one fragment and a nearby fragment.<br></div><div><br><br></div><div>
Here's a possible way to revise the test:<br><br></div><div>1. In the fragment shader, instead of setting gl_SampleMask[0] to a uniform value, set it to a value that's dynamically computed based on gl_FragCoord.  For example, a possible formula might be (int(gl_FragCoord.x) * 0x10204081) ^ (int(gl_FragCoord.y) * 0x01010101).  (The nice thing about this formula is that for your 128x128 image size, it produces a bit pattern where no two bits of gl_SampleMask[0] are correllated, so it should exercise the hardware pretty thoroughly).<br>
<br></div><div>2. Render to a multisample texture.<br><br></div><div>3. Read from the multisample texture using a second fragment shader that computes the same formula, figures out for each pixel which samples are expected to be green vs. black, and checks that all the samples have the expected color.<br>
</div><br> <blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
diff --git a/tests/all.tests b/tests/all.tests<br>
index d861a91..c5dd80c 100644<br>
--- a/tests/all.tests<br>
+++ b/tests/all.tests<br>
@@ -1347,6 +1347,11 @@ for num_samples in TEST_SAMPLE_COUNTS:<br>
     executable = 'arb_sample_shading-{0} -auto'.format(test_name)<br>
     arb_sample_shading[test_name] = PlainExecTest(executable)<br>
<br>
+for num_samples in TEST_SAMPLE_COUNTS:<br>
+    test_name = 'builtin-gl-sample-mask {0}'.format(num_samples)<br>
+    executable = 'arb_sample_shading-{0} -auto'.format(test_name)<br>
+    arb_sample_shading[test_name] = PlainExecTest(executable)<br>
+<br>
 # Group ARB_debug_output<br>
 arb_debug_output = Group()<br>
 spec['ARB_debug_output'] = arb_debug_output<br>
diff --git a/tests/spec/arb_sample_shading/execution/CMakeLists.gl.txt b/tests/spec/arb_sample_shading/execution/CMakeLists.gl.txt<br>
index 35f2905..d2f1f4a 100644<br>
--- a/tests/spec/arb_sample_shading/execution/CMakeLists.gl.txt<br>
+++ b/tests/spec/arb_sample_shading/execution/CMakeLists.gl.txt<br>
@@ -13,4 +13,5 @@ link_libraries (<br>
 piglit_add_executable (arb_sample_shading-api api.c)<br>
 piglit_add_executable (arb_sample_shading-builtin-gl-num-samples builtin-gl-num-samples.cpp)<br>
 piglit_add_executable (arb_sample_shading-builtin-gl-sample-id builtin-gl-sample-id.cpp)<br>
+piglit_add_executable (arb_sample_shading-builtin-gl-sample-mask builtin-gl-sample-mask.cpp)<br>
 # vim: ft=cmake:<br>
diff --git a/tests/spec/arb_sample_shading/execution/builtin-gl-sample-mask.cpp b/tests/spec/arb_sample_shading/execution/builtin-gl-sample-mask.cpp<br>
new file mode 100644<br>
index 0000000..2b4e7d7<br>
--- /dev/null<br>
+++ b/tests/spec/arb_sample_shading/execution/builtin-gl-sample-mask.cpp<br>
@@ -0,0 +1,236 @@<br>
+/*<br>
+ * Copyright © 2013 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>
+/** \file builtin-gl-sample-mask.cpp<br>
+ *  This test verifies that supplying a value to gl_SampleMask[]<br>
+ *  in fragment shader program works as per ARB_sample_shading<br>
+ *  specification.<br>
+ **/<br>
+<br>
+#include "piglit-fbo.h"<br>
+using namespace piglit_util_fbo;<br>
+<br>
+const int pattern_width = 128; const int pattern_height = 128;<br>
+<br>
+PIGLIT_GL_TEST_CONFIG_BEGIN<br>
+<br>
+       config.supports_gl_compat_version = 10;<br>
+<br>
+       config.window_width = pattern_width;<br>
+       config.window_height = pattern_height;<br>
+       config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGBA;<br>
+<br>
+PIGLIT_GL_TEST_CONFIG_END<br>
+<br>
+static int  num_samples;<br>
+static unsigned prog, vao, vertex_buf;<br>
+static Fbo multisampled_fbo, singlesampled_fbo;<br>
+<br>
+static void<br>
+print_usage_and_exit(char *prog_name)<br>
+{<br>
+       printf("Usage: %s <num_samples>\n", prog_name);<br>
+       piglit_report_result(PIGLIT_FAIL);<br>
+}<br>
+<br>
+void<br>
+compile_shader(void)<br>
+{<br>
+       static const char *vert =<br>
+               "#version 130\n"<br>
+               "in vec2 pos;\n"<br>
+               "void main()\n"<br>
+               "{\n"<br>
+               "  gl_Position = vec4(pos, 0.0, 1.0);\n"<br>
+               "}\n";<br>
+       static const char *frag =<br>
+               "#version 130\n"<br>
+               "#extension GL_ARB_sample_shading : enable\n"<br>
+               "uniform int sample_mask;\n"<br>
+               "out vec4 out_color;\n"<br>
+               "void main()\n"<br>
+               "{\n"<br>
+               "  gl_SampleMask[0] = sample_mask;\n"<br>
+               "  out_color = vec4(0.0, 1.0, 0.0, 1.0);\n"<br>
+               "}\n";<br>
+       /* Compile program */<br>
+       prog = glCreateProgram();<br>
+       GLint vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vert);<br>
+       glAttachShader(prog, vs);<br>
+       piglit_check_gl_error(GL_NO_ERROR);<br>
+       GLint fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, frag);<br>
+       glAttachShader(prog, fs);<br>
+       glBindAttribLocation(prog, 0, "pos");<br>
+       glLinkProgram(prog);<br>
+       if (!piglit_link_check_status(prog)) {<br>
+               piglit_report_result(PIGLIT_FAIL);<br>
+       }<br>
+<br>
+       /* Set up vertex array object */<br>
+       glGenVertexArrays(1, &vao);<br>
+       glBindVertexArray(vao);<br>
+<br>
+       /* Set up vertex input buffer */<br>
+       glGenBuffers(1, &vertex_buf);<br>
+       glBindBuffer(GL_ARRAY_BUFFER, vertex_buf);<br>
+       glEnableVertexAttribArray(0);<br>
+       glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4*sizeof(float),<br>
+                             (void *) 0);<br>
+<br>
+       /* Set up element input buffer to tesselate a quad into<br>
+        * triangles<br>
+        */<br>
+       unsigned int indices[6] = { 0, 1, 2, 0, 2, 3 };<br>
+       GLuint element_buf;<br>
+       glGenBuffers(1, &element_buf);<br>
+       glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, element_buf);<br>
+       glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices,<br>
+                    GL_STATIC_DRAW);<br>
+}<br>
+<br>
+void<br>
+draw_pattern(GLint samples, GLint sample_mask)<br>
+{<br>
+       float vertex_data[4][4] = {<br>
+               { -1, -1 },<br>
+               { -1,  1 },<br>
+               {  1,  1 },<br>
+               {  1, -1 }};<br>
+<br>
+       glUseProgram(prog);<br>
+       glBindVertexArray(vao);<br>
+<br>
+       /* Set up uniforms */<br>
+       glUseProgram(prog);<br>
+       glUniform1i(glGetUniformLocation(prog, "sample_mask"), sample_mask);<br>
+<br>
+       glBindBuffer(GL_ARRAY_BUFFER, vertex_buf);<br>
+       glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_data), vertex_data,<br>
+                    GL_STREAM_DRAW);<br>
+       glDrawElements(GL_TRIANGLES, 6 , GL_UNSIGNED_INT, (void *) 0);<br>
+}<br>
+<br>
+void<br>
+piglit_init(int argc, char **argv)<br>
+{<br>
+       if (argc != 2)<br>
+               print_usage_and_exit(argv[0]);<br>
+<br>
+       /* 1st arg: num_samples */<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>
+       piglit_require_gl_version(21);<br>
+       piglit_require_extension("GL_ARB_vertex_array_object");<br>
+       piglit_require_extension("GL_ARB_sample_shading");<br>
+<br>
+       /* Skip the test if num_samples > GL_MAX_SAMPLES */<br>
+       GLint max_samples;<br>
+       glGetIntegerv(GL_MAX_SAMPLES, &max_samples);<br>
+       if (num_samples > max_samples)<br>
+               piglit_report_result(PIGLIT_SKIP);<br>
+<br>
+       singlesampled_fbo.setup(FboConfig(0,<br>
+                                         pattern_width,<br>
+                                         pattern_height));<br>
+<br>
+       FboConfig msConfig(num_samples, pattern_width, pattern_height);<br>
+       multisampled_fbo.setup(msConfig);<br>
+<br>
+       compile_shader();<br>
+       if (!piglit_check_gl_error(GL_NO_ERROR)) {<br>
+               piglit_report_result(PIGLIT_FAIL);<br>
+       }<br>
+}<br>
+<br>
+bool test_builtin_sample_mask(Fbo ms_fbo, GLint sample_mask)<br>
+{<br>
+       GLint i, samples;<br>
+       bool pass = true, is_sample_enabled[8];<br>
+        GLfloat expected[4] = {0.0, 0.0, 0.0, 0.0};<br>
+<br>
+       glBindFramebuffer(GL_DRAW_FRAMEBUFFER, ms_fbo.handle);<br>
+       glGetIntegerv(GL_SAMPLES, &samples);<br>
+<br>
+       /* Expected color is computed after taking in to account the<br>
+        * multisample color resolve:<br>
+        */<br>
+       for (i = 0; i < samples; i++) {<br>
+               is_sample_enabled[i] = (sample_mask >> i) & 0x1;<br>
+               if (is_sample_enabled[i]) {<br>
+                       expected[1] += 1.0;<br>
+                       expected[3] += 1.0;<br>
+               }<br>
+       }<br>
+       expected[1] /= samples;<br>
+       expected[3] /= samples;<br>
+<br>
+       glClear(GL_COLOR_BUFFER_BIT);<br>
+       draw_pattern(samples, sample_mask);<br>
+<br>
+       glBindFramebuffer(GL_READ_FRAMEBUFFER, ms_fbo.handle);<br>
+       glBindFramebuffer(GL_DRAW_FRAMEBUFFER, singlesampled_fbo.handle);<br>
+       glClear(GL_COLOR_BUFFER_BIT);<br>
+       glBlitFramebuffer(0, 0,<br>
+                         pattern_width, pattern_height,<br>
+                         0, 0,<br>
+                         pattern_width, pattern_height,<br>
+                         GL_COLOR_BUFFER_BIT,<br>
+                         GL_NEAREST);<br>
+<br>
+       glBindFramebuffer(GL_READ_FRAMEBUFFER, singlesampled_fbo.handle);<br>
+       glBindFramebuffer(GL_DRAW_FRAMEBUFFER, piglit_winsys_fbo);<br>
+<br>
+       pass = piglit_probe_rect_rgba(0, 0, pattern_width,<br>
+                                      pattern_width, expected)<br>
+               && pass;<br>
+       printf("sample_mask = 0x%x result= %s\n",<br>
+               sample_mask, pass ? "pass": "fail");<br>
+       glClear(GL_COLOR_BUFFER_BIT);<br>
+       glBlitFramebuffer(0, 0,<br>
+                         pattern_width, pattern_height,<br>
+                         0, 0,<br>
+                         pattern_width, pattern_height,<br>
+                         GL_COLOR_BUFFER_BIT,<br>
+                         GL_NEAREST);<br>
+<br>
+       piglit_present_results();<br>
+       return pass;<br>
+}<br>
+<br>
+enum piglit_result<br>
+piglit_display()<br>
+{<br>
+       bool pass = true;<br>
+       int i, sample_mask = 0;<br>
+<br>
+       for(i = 0; i <= 8; i++) {<br>
+               pass = test_builtin_sample_mask(multisampled_fbo, sample_mask)<br>
+                       && pass;<br>
+               sample_mask |= (0x1 << i);<br>
+       }<br>
+<br>
+       return pass ? PIGLIT_PASS : PIGLIT_FAIL;<br>
+}<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.8.1.4<br>
<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>
</font></span></blockquote></div><br></div></div>