<div dir="ltr">On 23 January 2014 15:56, 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"><div class="im">Here is what it tests:<br>
Enable sample shading for the whole fragment shader using OpenGL API<br>
glEnable(GL_SAMPLE_SHADING);<br>
glMinSampleShading(1.0);<br>
<br>
fragment shader:<br>
</div><div class="im">centroid in vec4 b;<br>
main()<br>
{<br>
  ...<br>
}<br>
<br>
</div>Variable 'b' should be interpolated at sample's location.<br>
<br>
V2: Use just one 'in' variable with the 'centroid' qualifier.<br>
Another test already covers the interpolation of 'in' variable<br>
without any 'qualifier'. This change also captures the mesa bug<br>
reported on i965 driver:<br>
Bugzilla: <a href="https://bugs.freedesktop.org/show_bug.cgi?id=73915" target="_blank">https://bugs.freedesktop.org/show_bug.cgi?id=73915</a><br>
<div class="im"><br>
Signed-off-by: Anuj Phogat <<a href="mailto:anuj.phogat@gmail.com">anuj.phogat@gmail.com</a>><br>
Cc: Chris Forbes <<a href="mailto:chrisf@ijw.co.nz">chrisf@ijw.co.nz</a>><br>
---<br>
 tests/all.py                                       |   5 +<br>
 .../arb_sample_shading/execution/CMakeLists.gl.txt |   1 +<br>
</div> .../execution/ignore-centroid-qualifier.cpp        | 193 +++++++++++++++++++++<br>
 3 files changed, 199 insertions(+)<br>
<div><div class="h5"> create mode 100644 tests/spec/arb_sample_shading/execution/ignore-centroid-qualifier.cpp<br>
<br>
diff --git a/tests/all.py b/tests/all.py<br>
index 459bcca..5fceff9 100644<br>
--- a/tests/all.py<br>
+++ b/tests/all.py<br>
@@ -1789,6 +1789,11 @@ for num_samples in MSAA_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 MSAA_SAMPLE_COUNTS:<br>
+    test_name = 'ignore-centroid-qualifier {0}'.format(num_samples)<br>
+    executable = 'arb_sample_shading-{0} -auto'.format(test_name)<br>
+    arb_sample_shading[test_name] = PlainExecTest(executable)<br>
+<br>
 import_glsl_parser_tests(spec['ARB_sample_shading'],<br>
                          os.path.join(testsDir, 'spec', 'arb_sample_shading'),<br>
                          ['compiler'])<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 9a72439..c3690e9 100644<br>
--- a/tests/spec/arb_sample_shading/execution/CMakeLists.gl.txt<br>
+++ b/tests/spec/arb_sample_shading/execution/CMakeLists.gl.txt<br>
@@ -16,4 +16,5 @@ piglit_add_executable (arb_sample_shading-builtin-gl-sample-id builtin-gl-sample<br>
 piglit_add_executable (arb_sample_shading-builtin-gl-sample-mask builtin-gl-sample-mask.cpp)<br>
 piglit_add_executable (arb_sample_shading-builtin-gl-sample-position builtin-gl-sample-position.cpp)<br>
 piglit_add_executable (arb_sample_shading-interpolate-at-sample-position interpolate-at-sample-position.cpp)<br>
+piglit_add_executable (arb_sample_shading-ignore-centroid-qualifier ignore-centroid-qualifier.cpp)<br>
 # vim: ft=cmake:<br>
diff --git a/tests/spec/arb_sample_shading/execution/ignore-centroid-qualifier.cpp b/tests/spec/arb_sample_shading/execution/ignore-centroid-qualifier.cpp<br>
new file mode 100644<br>
</div></div>index 0000000..cb54655<br>
--- /dev/null<br>
+++ b/tests/spec/arb_sample_shading/execution/ignore-centroid-qualifier.cpp<br>
@@ -0,0 +1,193 @@<br>
<div><div class="h5">+/*<br>
+ * Copyright (c) 2014 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>
+/**<br>
+ * @file ignore-centroid-qualifier.cpp<br>
+ *<br>
+ * Tests that all 'in' variables in fragment shader are interpolated at sample<br>
+ * positions when using per sample shading. Ignore the 'centroid' qualifier if<br>
+ * used with 'in' variable.<br>
+ *<br>
+ */<br>
+#include "piglit-util-gl-common.h"<br>
+#include "piglit-fbo.h"<br>
+<br>
+using namespace piglit_util_fbo;<br>
+const int pattern_width = 128; const int pattern_height = 128;<br>
+<br>
+PIGLIT_GL_TEST_CONFIG_BEGIN<br>
+       config.supports_gl_compat_version = 21;<br>
+       config.supports_gl_core_version = 31;<br>
+        config.window_width = 2 * 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 Fbo multisampled_fbo;<br>
+static int sample_pos_loc, sample_id_loc, num_samples;<br>
+static int draw_prog_left, draw_prog_right, test_prog;<br>
+<br>
+enum piglit_result<br>
+piglit_display(void)<br>
+{<br>
+       float pos[2];<br>
+       bool result = true, pass = true;<br>
+<br>
+       glBindFramebuffer(GL_DRAW_FRAMEBUFFER, multisampled_fbo.handle);<br>
+       glClear(GL_COLOR_BUFFER_BIT);<br>
+<br>
+       /* Draw test image in to left half of multisample fbo*/<br>
+       glUseProgram(draw_prog_left);<br>
+       glViewport(0, 0, pattern_width, pattern_height);<br>
+       glEnable(GL_SAMPLE_SHADING);<br>
+       glMinSampleShading(1.0);<br>
+       piglit_draw_rect(-1, -1, 2, 2);<br>
+       glDisable(GL_SAMPLE_SHADING);<br>
+<br>
+       for(int i = 0; i < num_samples; i++) {<br>
+               /* Draw reference image in to right half of multisample fbo */<br>
+               glUseProgram(draw_prog_right);<br>
+               glBindFramebuffer(GL_DRAW_FRAMEBUFFER, multisampled_fbo.handle);<br>
+               glGetMultisamplefv(GL_SAMPLE_POSITION, i, pos);<br>
+               glUniform2fv(sample_pos_loc, 1, pos);<br>
+               glEnable(GL_SCISSOR_TEST);<br>
+               glScissor(pattern_width, 0, pattern_width, pattern_height);<br>
+               glViewport(pattern_width, 0, pattern_width, pattern_height);<br>
+               glClear(GL_COLOR_BUFFER_BIT);<br>
+               piglit_draw_rect(-1, -1, 2, 2);<br>
+               glDisable(GL_SCISSOR_TEST);<br>
+<br>
+               /* Draw sample color from multisample texture in to winsys fbo */<br>
+               glUseProgram(test_prog);<br>
+               glUniform1i(sample_id_loc, i);<br>
+               glViewport(0, 0, 2 * pattern_width, pattern_height);<br>
+               glBindFramebuffer(GL_DRAW_FRAMEBUFFER, piglit_winsys_fbo);<br>
+               glClear(GL_COLOR_BUFFER_BIT);<br>
+               piglit_draw_rect(-1, -1, 2, 2);<br>
+<br>
+               result = piglit_probe_rect_halves_equal_rgba(0, 0,<br>
+                                                            piglit_width,<br>
+                                                            piglit_height);<br>
+               pass = pass && result;<br>
+               printf("sample_id = %d, result = %s\n", i,<br>
+                      result ? "pass" : "fail");<br>
+       }<br>
+       piglit_present_results();<br>
+       return pass ? PIGLIT_PASS : PIGLIT_FAIL;<br>
+}<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>
+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_extension("GL_ARB_texture_multisample");<br>
+       piglit_require_extension("GL_ARB_sample_shading");<br>
+       piglit_require_GLSL_version(130);<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 == 0 || num_samples > max_samples)<br>
+               piglit_report_result(PIGLIT_SKIP);<br>
+<br>
+       FboConfig msConfig(num_samples, piglit_width, piglit_height);<br>
+        msConfig.attach_texture = true;<br>
+       multisampled_fbo.setup(msConfig);<br>
+<br>
+       /* Reduced tolerence for stricter color matching */<br>
+       piglit_set_tolerance_for_bits(16, 16, 16, 16);<br>
+       draw_prog_left = piglit_build_simple_program(<br>
+               "#version 130\n"<br>
+               "#extension GL_ARB_sample_shading: require\n"<br>
+               "in vec4 piglit_vertex;\n"<br>
</div></div>+               "centroid out vec2 test;\n"<br>
<div class="im">+               "void main() {\n"<br>
+               "       gl_Position = piglit_vertex;\n"<br>
</div>+               "       test = piglit_vertex.xy;\n"<br>
<div class="im">+               "}\n",<br>
+<br>
+               "#version 130\n"<br>
+               "#extension GL_ARB_sample_shading: require\n"<br>
</div>+               "centroid in vec2 test;\n"<br>
+               "void main() {\n"<br>
+               "       gl_FragColor = vec4(abs(test), 0, 1);\n"<br>
<div class="im">+               "}\n");<br>
+<br>
+       draw_prog_right = piglit_build_simple_program(<br>
+               "#version 130\n"<br>
+               "uniform vec2 sample_pos;\n"<br>
+               "in vec4 piglit_vertex;\n"<br>
</div>+               "out vec2 ref;\n"<br>
<div class="im">+               "void main() {\n"<br>
+               "       gl_Position = piglit_vertex;\n"<br>
</div>+               "       ref = piglit_vertex.xy;\n"<br>
<div class="im">+                       /* Add an offset to account for interplolation<br>
+                        * at sample position.<br>
+                        */<br>
</div>+               "       ref += (sample_pos - 0.5) / 64;\n"<br></blockquote><div><br></div><div>It would be nice to have a comment here explaining the origin of the magic number 64 (it comes from the fact that pattern_width == pattern_height == 128, so the scaling factor between normalized device coordinates and pixels is 128/2 == 64).<br>
<br></div><div>With that changed, the test is:<br><br>Reviewed-by: Paul Berry <<a href="mailto:stereotype441@gmail.com">stereotype441@gmail.com</a>><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div class="im">+               "}\n",<br>
+<br>
+               "#version 130\n"<br>
</div>+               "in vec2 ref;\n"<br>
+               "void main() {\n"<br>
+               "       gl_FragColor = vec4(abs(ref), 0, 1);\n"<br>
<div class="HOEnZb"><div class="h5">+               "}\n");<br>
+       sample_pos_loc = glGetUniformLocation(draw_prog_right, "sample_pos");<br>
+<br>
+       test_prog = piglit_build_simple_program(<br>
+               "#version 130\n"<br>
+               "in vec4 piglit_vertex;\n"<br>
+               "void main() {\n"<br>
+               "       gl_Position = piglit_vertex;\n"<br>
+               "}\n",<br>
+<br>
+               "#version 130\n"<br>
+               "#extension GL_ARB_texture_multisample: require\n"<br>
+               "uniform int sample_id;\n"<br>
+               "uniform sampler2DMS tex;\n"<br>
+               "void main() {\n"<br>
+               "       gl_FragColor =  texelFetch(tex, ivec2(gl_FragCoord.xy),\n"<br>
+               "                                  sample_id);\n"<br>
+               "}\n");<br>
+<br>
+       glUseProgram(test_prog);<br>
+       glUniform1i(glGetUniformLocation(test_prog, "tex"), 0);<br>
+       sample_id_loc = glGetUniformLocation(test_prog, "sample_id");<br>
+}<br>
+<br>
--<br>
1.8.3.1<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>
</div></div></blockquote></div><br></div></div>