<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                                    |   6 +<br>
 .../arb_sample_shading/execution/CMakeLists.gl.txt |   1 +<br>
 .../execution/builtin-gl-num-samples.cpp           | 220 +++++++++++++++++++++<br>
 3 files changed, 227 insertions(+)<br>
 create mode 100644 tests/spec/arb_sample_shading/execution/builtin-gl-num-samples.cpp<br>
<br>
diff --git a/tests/all.tests b/tests/all.tests<br>
index e30eb3b..1fcd08a 100644<br>
--- a/tests/all.tests<br>
+++ b/tests/all.tests<br>
@@ -1336,6 +1336,12 @@ arb_sample_shading = Group()<br>
 spec['ARB_sample_shading'] = arb_sample_shading<br>
 add_plain_test(arb_sample_shading, 'arb_sample_shading-api')<br>
<br>
+TEST_SAMPLE_COUNTS = (0, 2, 4, 6, 8, 16, 32)<br></blockquote><div><br></div><div>Let's do:<br><br></div><div>TEST_SAMPLE_COUNTS = (0,) + MSAA_SAMPLE_COUNTS<br><br>so that if we wind up changing MSAA_SAMPLE_COUNTS in the future, TEST_SAMPLE_COUNTS will automatically get updated too.<br>
</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+for num_samples in TEST_SAMPLE_COUNTS:<br>
+    test_name = 'builtin-gl-num-samples {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 36289e0..56fa0da 100644<br>
--- a/tests/spec/arb_sample_shading/execution/CMakeLists.gl.txt<br>
+++ b/tests/spec/arb_sample_shading/execution/CMakeLists.gl.txt<br>
@@ -11,4 +11,5 @@ link_libraries (<br>
 )<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>
 # vim: ft=cmake:<br>
diff --git a/tests/spec/arb_sample_shading/execution/builtin-gl-num-samples.cpp b/tests/spec/arb_sample_shading/execution/builtin-gl-num-samples.cpp<br>
new file mode 100644<br>
index 0000000..585fb75<br>
--- /dev/null<br>
+++ b/tests/spec/arb_sample_shading/execution/builtin-gl-num-samples.cpp<br>
@@ -0,0 +1,220 @@<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-num-samples.cpp<br>
+ *  This test verifies that using gl_NumSamples in fragment shader<br>
+ *  program 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>
+               "uniform mat4 proj;\n"<br></blockquote><div><br></div><div>"proj" is now unused, and can be eliminated.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

+               "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 : require\n"<br>
+               "uniform int samples;\n"<br>
+               "out vec4 out_color;\n"<br>
+               "void main()\n"<br>
+               "{\n"<br>
+               "  if (gl_NumSamples == samples)\n"<br>
+               "    out_color = vec4(0.0, 1.0, 0.0, 1.0);\n"<br>
+               "  else\n"<br>
+               "    out_color = vec4(1.0, 0.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_glsl(const Fbo *src_fbo, 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_ms_blit_scaled(Fbo ms_fbo)<br>
+{<br>
+       GLint samples;<br>
+        GLfloat expected[4] = {0.0, 1.0, 0.0, 1.0};<br>
+       bool pass = true;<br>
+<br>
+       /* Draw the test pattern into the framebuffer with texture<br>
+        * attachment.<br>
+        */<br>
+       glBindFramebuffer(GL_DRAW_FRAMEBUFFER, ms_fbo.handle);<br>
+       glGetIntegerv(GL_SAMPLES, &samples);<br>
+<br>
+       glClear(GL_COLOR_BUFFER_BIT);<br>
+       draw_pattern_glsl(&ms_fbo, 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, pattern_width,<br>
+                                       expected)  && pass;<br></blockquote><div><br></div><div>Extra indentation here.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

+       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_ms_blit_scaled(multisampled_fbo)<br>
+               && pass;<br>
+       return pass ? PIGLIT_PASS : PIGLIT_FAIL;<br>
+}<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.8.1.4<br></font></span></blockquote><div><br></div><div>With those minor changes, and Chris's comments addressed, this patch is:<br><br>Reviewed-by: Paul Berry <<a href="mailto:stereotype441@gmail.com">stereotype441@gmail.com</a>><br>
</div></div></div></div>