<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Oct 29, 2013 at 8:01 AM, Paul Berry <span dir="ltr"><<a href="mailto:stereotype441@gmail.com" target="_blank">stereotype441@gmail.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="im">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><div class="gmail_extra"><div class="gmail_quote"><div class="im">

<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" target="_blank">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-id.cpp             | 230 +++++++++++++++++++++<br>
 3 files changed, 236 insertions(+)<br>
 create mode 100644 tests/spec/arb_sample_shading/execution/builtin-gl-sample-id.cpp<br></blockquote><div><br></div></div><div>I'm not comfortable with this test.  It doesn't verify that gl_SampleID is correct for each sample.  It just averages together float(gl_SampleID)/float(gl_NumSamples) for all samples and verifies that is equals the expected value (which will always be near 0.5).  In particular, if there's a bug causing gl_SampleID to identify the samples in an incorrect order, that won't be caught by this test.<br>



<br></div><div>I'd recommend keeping your vertex and fragment shader, but instead of drawing to a renderbuffer, draw to a multisampled texture (using ARB_texture_multisample).  Then you can have a second shader which reads from the multisampled texture and verifies that every sample is correct at every pixel location.<br>



<br></div><div>Also, Chris's suggestion from patch 2 (about reinventing piglit_draw_rect) applies here as well.<br></div></div></div></div></blockquote><div style>I agree. This test may not catch a bug related to incorrect ordering of samples. I liked your idea of blitting to a multisample texture and then verify the expected color of each sample.</div>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div><div class="h5">

<br>
diff --git a/tests/all.tests b/tests/all.tests<br>
index 1fcd08a..d861a91 100644<br>
--- a/tests/all.tests<br>
+++ b/tests/all.tests<br>
@@ -1342,6 +1342,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-id {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 56fa0da..35f2905 100644<br>
--- a/tests/spec/arb_sample_shading/execution/CMakeLists.gl.txt<br>
+++ b/tests/spec/arb_sample_shading/execution/CMakeLists.gl.txt<br>
@@ -12,4 +12,5 @@ link_libraries (<br>
<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>
 # vim: ft=cmake:<br>
diff --git a/tests/spec/arb_sample_shading/execution/builtin-gl-sample-id.cpp b/tests/spec/arb_sample_shading/execution/builtin-gl-sample-id.cpp<br>
new file mode 100644<br>
index 0000000..143dc95<br>
--- /dev/null<br>
+++ b/tests/spec/arb_sample_shading/execution/builtin-gl-sample-id.cpp<br>
@@ -0,0 +1,230 @@<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-id.cpp<br>
+ *  This test verifies that using gl_SampleID in fragment shader program<br>
+ *  works as per ARB_sample_shading specification.<br>
+ *<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 samples;\n"<br>
+               "out vec4 out_color;\n"<br>
+               "void main()\n"<br>
+               "{\n"<br>
+               "  if(samples == 0)\n"<br>
+               "    out_color = vec4(0.0, 1.0, 0.0, 1.0);\n"<br>
+               "  else\n"<br>
+               "    out_color = vec4(0.0, float(gl_SampleID) / samples, 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)<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, "samples"), samples);<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_id(Fbo ms_fbo)<br>
+{<br>
+       bool pass = true;<br>
+       int i, samples;<br>
+        float expected[4] = {0.0, 0.0, 0.0, 1.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>
+        * ((sample_id0 + sample_id_1 + sample_id_2 + sample_id_3)<br>
+        *  / (samples * samples))<br>
+        */<br>
+        if (samples == 0)<br>
+               expected[1] = 1.0;<br>
+       else {<br>
+               for (i = 0; i < samples; i++)<br>
+                       expected[1] += (((float) i) / samples);<br>
+               expected[1] /= samples;<br>
+       }<br>
+<br>
+       glClear(GL_COLOR_BUFFER_BIT);<br>
+       draw_pattern(samples);<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>
+       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>
+       pass = test_builtin_sample_id(multisampled_fbo)<br>
+               && pass;<br>
+       return pass ? PIGLIT_PASS : PIGLIT_FAIL;<br>
+}<br>
</div></div><span class="HOEnZb"><font color="#888888"><span><font color="#888888">--<br>
1.8.1.4<br>
<br>
_______________________________________________<br>
Piglit mailing list<br>
<a href="mailto:Piglit@lists.freedesktop.org" target="_blank">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></font></span></blockquote></div><br></div></div>
</blockquote></div><br></div></div>