[Piglit] [PATCH 1/4] glsl-1.30: New tests for discard exiting the shader.
Eric Anholt
eric at anholt.net
Mon Mar 26 12:27:08 PDT 2012
Thes will infinite loop and hang the GPU on failure to implement the
correct behavior. This is the result of a clarification in revision 9
of the 1.30 spec, which I noticed while working on GLSL 1.40 (which
also got this clarification). The change was not backported to 1.20.
---
tests/all.tests | 1 +
tests/spec/glsl-1.30/execution/CMakeLists.gl.txt | 1 +
.../execution/fs-discard-exit-1.shader_test | 49 ++++++
tests/spec/glsl-1.30/execution/fs-discard-exit-2.c | 155 ++++++++++++++++++++
4 files changed, 206 insertions(+), 0 deletions(-)
create mode 100644 tests/spec/glsl-1.30/execution/fs-discard-exit-1.shader_test
create mode 100644 tests/spec/glsl-1.30/execution/fs-discard-exit-2.c
diff --git a/tests/all.tests b/tests/all.tests
index 0cf81da..cacc7aa 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -972,6 +972,7 @@ for arg in ['vs_basic', 'vs_xfb', 'vs_fbo', 'fs_basic', 'fs_fbo']:
spec['glsl-1.30']['execution']['clipping']['clip-plane-transformation pos'] = \
concurrent_test('clip-plane-transformation pos')
spec['glsl-1.30']['texel-offset-limits'] = concurrent_test('glsl-1.30-texel-offset-limits')
+add_concurrent_test(spec['glsl-1.30']['execution'], 'fs-discard-exit-2')
add_concurrent_test(spec['glsl-1.30']['execution'], 'vertexid-beginend')
add_concurrent_test(spec['glsl-1.30']['execution'], 'vertexid-drawarrays')
add_concurrent_test(spec['glsl-1.30']['execution'], 'vertexid-drawelements')
diff --git a/tests/spec/glsl-1.30/execution/CMakeLists.gl.txt b/tests/spec/glsl-1.30/execution/CMakeLists.gl.txt
index 4e2351d..8c64778 100644
--- a/tests/spec/glsl-1.30/execution/CMakeLists.gl.txt
+++ b/tests/spec/glsl-1.30/execution/CMakeLists.gl.txt
@@ -12,6 +12,7 @@ link_libraries (
${GLUT_glut_LIBRARY}
)
+piglit_add_executable (fs-discard-exit-2 fs-discard-exit-2.c)
piglit_add_executable (fs-texelFetch-2D fs-texelFetch-2D.c)
piglit_add_executable (fs-texelFetchOffset-2D fs-texelFetchOffset-2D.c)
IF (NOT MSVC)
diff --git a/tests/spec/glsl-1.30/execution/fs-discard-exit-1.shader_test b/tests/spec/glsl-1.30/execution/fs-discard-exit-1.shader_test
new file mode 100644
index 0000000..337a528
--- /dev/null
+++ b/tests/spec/glsl-1.30/execution/fs-discard-exit-1.shader_test
@@ -0,0 +1,49 @@
+# This is a simple test for exiting the shader on discard. See
+# fs-discard-exit-2.c for a more complete test.
+
+[require]
+GLSL >= 1.30
+
+[vertex shader]
+#version 130
+
+in vec4 vertex;
+void main()
+{
+ gl_Position = vertex;
+}
+
+[fragment shader]
+#version 130
+uniform int inc;
+uniform bool disc;
+
+void main()
+{
+ if (disc)
+ discard;
+
+ gl_FragColor = vec4(0.0);
+
+ /* Should not execute, but would infinite loop if it did. */
+ for (int i = 0; i < 10; i += inc) {
+ gl_FragColor += 0.1;
+ }
+}
+
+[vertex data]
+vertex/float/2
+-1.0 -1.0
+ 1.0 -1.0
+ 1.0 1.0
+-1.0 1.0
+
+[test]
+clear color 0.0 1.0 0.0 0.0
+clear
+
+uniform int inc 0
+uniform int disc 1
+
+draw arrays GL_TRIANGLE_FAN 0 4
+probe all rgba 0.0 1.0 0.0 0.0
diff --git a/tests/spec/glsl-1.30/execution/fs-discard-exit-2.c b/tests/spec/glsl-1.30/execution/fs-discard-exit-2.c
new file mode 100644
index 0000000..a24a922
--- /dev/null
+++ b/tests/spec/glsl-1.30/execution/fs-discard-exit-2.c
@@ -0,0 +1,155 @@
+/*
+ * Copyright © 2012 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+/**
+ * @file fs-discard-exit-2.c
+ *
+ * Tests that the discard keyword stops all further execution on that channel.
+ *
+ * From the GLSL 1.30 spec revision 9:
+ *
+ * "Control flow exits the shader, and subsequent implicit or
+ * explicit derivatives are undefined when this control flow is
+ * non-uniform (meaning different fragments within the primitive
+ * take different control paths)."
+ *
+ * Here's the testing plan: Divide the 64x64 window into an 8x8 grid.
+ * For each grid entry, choose a unique pixel to discard, and then run
+ * a loop that would infinite loop on that pixel. This should get at
+ * the intent of the spec and a bug in my first implementation of the
+ * fix on i965, while also improving our coverage of pixel discard
+ * (which previously tended to discard big regions that were at least
+ * 2x2 subspan aligned).
+ */
+
+#include "piglit-util.h"
+
+int piglit_width = 64, piglit_height = 64;
+int piglit_window_mode = GLUT_RGB | GLUT_ALPHA | GLUT_DOUBLE;
+
+static int coord1_location, coord2_location;
+
+static const char *vs_source =
+ "#version 130\n"
+ "in vec4 vertex;\n"
+ ""
+ "void main()\n"
+ "{\n"
+ " gl_Position = gl_Vertex;\n"
+ "}\n";
+
+/* This shader will discard one pixel coordinate, and do an infinite
+ * loop on another pixel. We set the two coordinates to the same, to
+ * test whether discard on a channel avoids execution on that channel.
+ */
+static const char *fs_source =
+ "#version 130\n"
+ "uniform ivec2 coord1, coord2;\n"
+ "void main()\n"
+ "{\n"
+ " ivec2 fc = ivec2(gl_FragCoord);\n"
+ " int inc = abs(fc.x - coord2.x) + abs(fc.y - coord2.y);\n"
+ "\n"
+ " if (fc == coord1)\n"
+ " discard;\n"
+ "\n"
+ " gl_FragColor = vec4(0);\n"
+ " for (int i = 0; i < 10; i += inc)\n"
+ " gl_FragColor.b += 0.1;\n"
+ "}\n";
+
+enum piglit_result
+piglit_display(void)
+{
+ int x, y;
+ bool pass = true;
+ float expected[64 * 64 * 4];
+
+ glClearColor(0.0, 1.0, 0.0, 0.0);
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ for (x = 0; x < 8; x++) {
+ for (y = 0; y < 8; y++) {
+ piglit_Uniform2i(coord1_location, x * 9, y * 9);
+ piglit_Uniform2i(coord2_location, x * 9, y * 9);
+ piglit_draw_rect(-1.0 + 0.25 * x,
+ -1.0 + 0.25 * y,
+ 0.25,
+ 0.25);
+ }
+ }
+
+ for (x = 0; x < 64; x++) {
+ for (y = 0; y < 64; y++) {
+ int sx = x % 8;
+ int sy = y % 8;
+ int dx = fabs(sx - x / 8);
+ int dy = fabs(sy - y / 8);
+ float pixel[4];
+
+ if (dx == 0 && dy == 0) {
+ pixel[0] = 0.0;
+ pixel[1] = 1.0;
+ pixel[2] = 0.0;
+ pixel[3] = 0.0;
+ } else {
+ int i;
+
+ pixel[0] = 0.0;
+ pixel[1] = 0.0;
+ pixel[2] = 0.0;
+ pixel[3] = 0.0;
+
+ for (i = 0; i < 10; i += (dx + dy))
+ pixel[2] += 0.1;
+ }
+
+ memcpy(expected + (y * 64 + x) * 4, pixel, 4 * 4);
+ }
+ }
+
+ pass = piglit_probe_image_rgba(0, 0, 64, 64, expected);
+
+ piglit_present_results();
+
+ return pass ? PIGLIT_PASS : PIGLIT_FAIL;
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+ int vs, fs, prog;
+
+ piglit_require_GLSL_version(130);
+
+ vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vs_source);
+ fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fs_source);
+ prog = piglit_link_simple_program(vs, fs);
+ if (!vs || !fs || !prog)
+ piglit_report_result(PIGLIT_FAIL);
+
+ coord1_location = piglit_GetUniformLocation(prog, "coord1");
+ coord2_location = piglit_GetUniformLocation(prog, "coord2");
+
+ piglit_UseProgram(prog);
+}
--
1.7.9.1
More information about the Piglit
mailing list