On 24 July 2012 15:14, Paul Berry <span dir="ltr"><<a href="mailto:stereotype441@gmail.com" target="_blank">stereotype441@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">
Some hardware platforms (e.g. i965 gen6+) are capable of processing<br>
the fragments corresponding to multiple primitives in parallel, even<br>
if those primitives overlap on the screen.  This test verifies that in<br>
such situations, the fragment shader outputs are written to the<br>
framebuffer in the correct order.<br></blockquote><div><br>Argh, I forgot to add this to all.tests.  I'll fix that before pushing.<br> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">

---<br>
 tests/spec/glsl-1.30/execution/CMakeLists.gl.txt   |    1 +<br>
 .../glsl-1.30/execution/fs-execution-ordering.c    |  178 ++++++++++++++++++++<br>
 2 files changed, 179 insertions(+), 0 deletions(-)<br>
 create mode 100644 tests/spec/glsl-1.30/execution/fs-execution-ordering.c<br>
<br>
diff --git a/tests/spec/glsl-1.30/execution/CMakeLists.gl.txt b/tests/spec/glsl-1.30/execution/CMakeLists.gl.txt<br>
index a582c3f..6737bb1 100644<br>
--- a/tests/spec/glsl-1.30/execution/CMakeLists.gl.txt<br>
+++ b/tests/spec/glsl-1.30/execution/CMakeLists.gl.txt<br>
@@ -19,3 +19,4 @@ ENDIF (NOT MSVC)<br>
 piglit_add_executable (vertexid-beginend vertexid-beginend.c)<br>
 piglit_add_executable (vertexid-drawarrays vertexid-drawarrays.c)<br>
 piglit_add_executable (vertexid-drawelements vertexid-drawelements.c)<br>
+piglit_add_executable (fs-execution-ordering fs-execution-ordering.c)<br>
diff --git a/tests/spec/glsl-1.30/execution/fs-execution-ordering.c b/tests/spec/glsl-1.30/execution/fs-execution-ordering.c<br>
new file mode 100644<br>
index 0000000..ccb0b77<br>
--- /dev/null<br>
+++ b/tests/spec/glsl-1.30/execution/fs-execution-ordering.c<br>
@@ -0,0 +1,178 @@<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<br>
+ * DEALINGS IN THE SOFTWARE.<br>
+ */<br>
+<br>
+/**<br>
+ * fs-execution-ordering.c<br>
+ *<br>
+ * Confirm that fragment shader outputs are written to the color<br>
+ * buffer in the correct order, even if some fragments take<br>
+ * dramatically longer to execute than others.<br>
+ *<br>
+ * Since this test is looking for race conditions, it repeats 100<br>
+ * times, drawing different primitives sizes, to increase the chances<br>
+ * of a race condition occurring.<br>
+ */<br>
+<br>
+#include "piglit-util-gl-common.h"<br>
+<br>
+#define SHIFT_COUNT 64<br>
+<br>
+PIGLIT_GL_TEST_MAIN(<br>
+   100 /* window_width */,<br>
+   100 /* window_height */,<br>
+   GLUT_DOUBLE | GLUT_RGB | GLUT_ALPHA)<br>
+<br>
+#define SMALL_COMPOSITE 4<br>
+#define LARGE_PRIME 7919<br>
+<br>
+GLint prog;<br>
+GLuint vbo_handle;<br>
+<br>
+static const char *vstext =<br>
+       "#version 130\n"<br>
+       "in uint num;\n"<br>
+       "in vec4 pos;\n"<br>
+       "flat out uint number_to_classify;\n"<br>
+       "\n"<br>
+       "void main()\n"<br>
+       "{\n"<br>
+       "  gl_Position = pos;\n"<br>
+       "  number_to_classify = num;\n"<br>
+       "}\n";<br>
+<br>
+/* This fragment shader implements a simple primality test using trial<br>
+ * division.  It outputs a color of red if its input is prime, and<br>
+ * green if its input is composite.<br>
+ *<br>
+ * Note: no special effort has been made to use a very fast algorithm,<br>
+ * since the purpose of the shader is to have dramatically different<br>
+ * execution times based on the input parameter.<br>
+ */<br>
+static const char *fstext =<br>
+       "#version 130\n"<br>
+       "flat in uint number_to_classify;\n"<br>
+       "\n"<br>
+       "void main()\n"<br>
+       "{\n"<br>
+       "  bool factor_found = false;\n"<br>
+       "  for (uint i = 2u; i < number_to_classify; ++i) {\n"<br>
+       "    if (number_to_classify % i == 0u)\n"<br>
+       "      factor_found = true;\n"<br>
+       "  }\n"<br>
+       "  gl_FragColor = factor_found ?\n"<br>
+       "    vec4(0.0, 1.0, 0.0, 1.0) :\n"<br>
+       "    vec4(1.0, 0.0, 0.0, 1.0);\n"<br>
+       "}\n";<br>
+<br>
+void<br>
+piglit_init(int argc, char **argv)<br>
+{<br>
+       GLuint vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vstext);<br>
+       GLuint fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fstext);<br>
+       prog = piglit_link_simple_program(vs, fs);<br>
+       glGenBuffers(1, &vbo_handle);<br>
+<br>
+       if (!piglit_check_gl_error(GL_NO_ERROR))<br>
+               piglit_report_result(PIGLIT_FAIL);<br>
+}<br>
+<br>
+bool<br>
+do_test(unsigned size)<br>
+{<br>
+       float expected_color[4] = { 0.0, 1.0, 0.0, 1.0 };<br>
+<br>
+       /* Set up the necessary vertex array to draw two squares, each<br>
+        * size x size pixels.  The first square is drawn using a<br>
+        * large prime number for the "num" parameter, so it will be<br>
+        * drawn in red and take a long time to compute.  The second<br>
+        * square is drawn using a small composite number for the<br>
+        * "num" parameter, so it will be drawn in green and take a<br>
+        * short time to compute.<br>
+        *<br>
+        * Even though the second square takes a short time to<br>
+        * compute, it should be written to the color buffer after the<br>
+        * first square, so the result should be a green square.<br>
+        */<br>
+       GLfloat xmin = -1.0;<br>
+       GLfloat ymin = -1.0;<br>
+       GLfloat xmax = 2.0 * size / piglit_width - 1.0;<br>
+       GLfloat ymax = 2.0 * size / piglit_height - 1.0;<br>
+       struct vertex_attributes {<br>
+               GLfloat pos[2];<br>
+               GLuint num;<br>
+       } vertex_data[] = {<br>
+               { { xmin, ymin }, LARGE_PRIME },<br>
+               { { xmin, ymax }, LARGE_PRIME },<br>
+               { { xmax, ymax }, LARGE_PRIME },<br>
+               { { xmin, ymin }, LARGE_PRIME },<br>
+               { { xmax, ymax }, LARGE_PRIME },<br>
+               { { xmax, ymin }, LARGE_PRIME },<br>
+               { { xmin, ymin }, SMALL_COMPOSITE },<br>
+               { { xmax, ymax }, SMALL_COMPOSITE },<br>
+               { { xmax, ymin }, SMALL_COMPOSITE },<br>
+               { { xmin, ymin }, SMALL_COMPOSITE },<br>
+               { { xmin, ymax }, SMALL_COMPOSITE },<br>
+               { { xmax, ymax }, SMALL_COMPOSITE },<br>
+       };<br>
+<br>
+       size_t stride = sizeof(vertex_data[0]);<br>
+       GLint pos_index = glGetAttribLocation(prog, "pos");<br>
+       GLint num_index = glGetAttribLocation(prog, "num");<br>
+       glBindBuffer(GL_ARRAY_BUFFER, vbo_handle);<br>
+       glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_data), &vertex_data,<br>
+                    GL_STATIC_DRAW);<br>
+       glVertexAttribPointer(pos_index, 2, GL_FLOAT, GL_FALSE, stride,<br>
+                             (void *) offsetof(struct vertex_attributes,<br>
+                                               pos));<br>
+       glVertexAttribIPointer(num_index, 1, GL_UNSIGNED_INT, stride,<br>
+                              (void *) offsetof(struct vertex_attributes,<br>
+                                                num));<br>
+       glEnableVertexAttribArray(pos_index);<br>
+       glEnableVertexAttribArray(num_index);<br>
+<br>
+       /* Draw the squares and check their color. */<br>
+       glDrawArrays(GL_TRIANGLES, 0, ARRAY_SIZE(vertex_data));<br>
+       return piglit_probe_rect_rgba(0, 0, size, size, expected_color);<br>
+}<br>
+<br>
+enum piglit_result<br>
+piglit_display(void)<br>
+{<br>
+       enum piglit_result result = PIGLIT_PASS;<br>
+       unsigned size;<br>
+<br>
+       glUseProgram(prog);<br>
+       glClear(GL_COLOR_BUFFER_BIT);<br>
+<br>
+       for (size = 1; size <= 100; ++size) {<br>
+               if (!do_test(size)) {<br>
+                       printf("Failed at rect size %dx%d\n", size, size);<br>
+                       result = PIGLIT_FAIL;<br>
+                       break;<br>
+               }<br>
+       }<br>
+<br>
+       piglit_present_results();<br>
+<br>
+       return result;<br>
+}<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.7.7.6<br>
<br>
</font></span></blockquote></div><br>