summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Anholt <eric@anholt.net>2010-03-09 13:39:47 -0800
committerEric Anholt <eric@anholt.net>2010-03-09 14:24:14 -0800
commit5a1c1a9faf8394527b2a974bb6bd3d5486d620b4 (patch)
tree0d628bc0d4b200545f0e944539f89b7c18e1719a
parent4eb5b97f69fcc9dd9abb2e4b4992657c0382010b (diff)
glsl-fs-loop-nested: New test for nested loops in the fragment shader.
While it was designed to catch failure on i965, it also catches failure with Mesa software.
-rw-r--r--tests/all.tests1
-rw-r--r--tests/shaders/CMakeLists.txt1
-rw-r--r--tests/shaders/glsl-fs-loop-nested.c122
-rw-r--r--tests/shaders/glsl-fs-loop-nested.frag18
4 files changed, 142 insertions, 0 deletions
diff --git a/tests/all.tests b/tests/all.tests
index d054f7676..ea503e4d1 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -154,6 +154,7 @@ add_plain_test(shaders, 'glsl-fs-exp2')
add_plain_test(shaders, 'glsl-fs-fragcoord')
add_plain_test(shaders, 'glsl-fs-log2')
add_plain_test(shaders, 'glsl-fs-loop')
+add_plain_test(shaders, 'glsl-fs-loop-nested')
add_plain_test(shaders, 'glsl-fs-sqrt-zero')
add_plain_test(shaders, 'glsl-vs-arrays')
add_plain_test(shaders, 'glsl-vs-if')
diff --git a/tests/shaders/CMakeLists.txt b/tests/shaders/CMakeLists.txt
index 14ebfa95a..affe9f7ef 100644
--- a/tests/shaders/CMakeLists.txt
+++ b/tests/shaders/CMakeLists.txt
@@ -51,6 +51,7 @@ add_executable (glsl-fs-exp2 glsl-fs-exp2.c)
add_executable (glsl-fs-fragcoord glsl-fs-fragcoord.c)
add_executable (glsl-fs-log2 glsl-fs-log2.c)
add_executable (glsl-fs-loop glsl-fs-loop.c)
+add_executable (glsl-fs-loop-nested glsl-fs-loop-nested.c)
add_executable (glsl-fs-sqrt-zero glsl-fs-sqrt-zero.c)
add_executable (glsl-vs-arrays glsl-vs-arrays.c)
add_executable (glsl-vs-mov-after-deref glsl-vs-mov-after-deref.c)
diff --git a/tests/shaders/glsl-fs-loop-nested.c b/tests/shaders/glsl-fs-loop-nested.c
new file mode 100644
index 000000000..bf01f8e00
--- /dev/null
+++ b/tests/shaders/glsl-fs-loop-nested.c
@@ -0,0 +1,122 @@
+/*
+ * Copyright © 2009-2010 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.
+ *
+ * Authors:
+ * Eric Anholt <eric@anholt.net>
+ * Ian Romanick <idr@freedesktop.org>
+ *
+ */
+
+/** @file glsl-fs-loop-nested.c
+ *
+ * Tests that nested loops in the fragment shader work.
+ *
+ * Since a value from an attribute is used as a loop counter, the compiler
+ * cannot simply unroll the loop. This verifies that GLSL loops can be
+ * correctly generated in the fragment shader.
+ *
+ * This was conceived as a test case for freedesktop.org bug #25173.
+ */
+
+#include "piglit-util.h"
+
+int piglit_width = 100, piglit_height = 100;
+int piglit_window_mode = GLUT_RGB | GLUT_DOUBLE;
+
+static int color_location;
+static GLint prog;
+
+enum piglit_result
+piglit_display(void)
+{
+ GLboolean pass = GL_TRUE;
+
+ float color[] = {1.0, 0.0, 0.0, 0.0};
+
+ unsigned i;
+ unsigned j;
+
+ glClearColor(0.5, 0.5, 0.5, 0.5);
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ for (i = 0; i < 3; i++) {
+ float temp;
+ float line_color[4];
+ unsigned x = 5 + (25 * i);
+
+ for (j = 0; j < 3; j++) {
+ unsigned y = 5 + (25 * j);
+ int rotate;
+
+ memcpy(line_color, color, sizeof(line_color));
+ for (rotate = 0; rotate < i * j; rotate++) {
+ temp = line_color[2];
+ line_color[2] = line_color[1];
+ line_color[1] = line_color[0];
+ line_color[0] = temp;
+ }
+ line_color[3] = (float) i * 4 + j;
+
+ glUniform4fv(color_location, 1, line_color);
+ piglit_draw_rect(x, y, 20, 20);
+
+ pass &= piglit_probe_pixel_rgb(x + 5, y + 5, color);
+ }
+
+ temp = color[2];
+ color[2] = color[1];
+ color[1] = color[0];
+ color[0] = temp;
+ }
+
+
+ glutSwapBuffers();
+
+ return pass ? PIGLIT_SUCCESS : PIGLIT_FAILURE;
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+ GLint vs, fs;
+
+ /* Set up projection matrix so we can just draw using window
+ * coordinates.
+ */
+ piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
+
+ if (!GLEW_VERSION_2_0) {
+ printf("Requires OpenGL 2.0\n");
+ piglit_report_result(PIGLIT_SKIP);
+ }
+
+ vs = piglit_compile_shader(GL_VERTEX_SHADER,
+ "shaders/glsl-mvp.vert");
+ fs = piglit_compile_shader(GL_FRAGMENT_SHADER,
+ "shaders/glsl-fs-loop-nested.frag");
+
+ prog = piglit_link_simple_program(vs, fs);
+
+ glUseProgram(prog);
+
+ color_location = glGetUniformLocation(prog, "color");
+}
diff --git a/tests/shaders/glsl-fs-loop-nested.frag b/tests/shaders/glsl-fs-loop-nested.frag
new file mode 100644
index 000000000..9a8316622
--- /dev/null
+++ b/tests/shaders/glsl-fs-loop-nested.frag
@@ -0,0 +1,18 @@
+uniform vec4 color;
+
+void main()
+{
+ int count = int(color.w);
+ int count1 = int(count / 4);
+ int count2 = count - count1 * 4;
+ vec3 c = color.xyz;
+ int i, j;
+
+ for (i = 0; i < count1; i++) {
+ for (j = 0; j < count2; j++) {
+ c = c.yzx;
+ }
+ }
+
+ gl_FragColor = vec4(c, 1.0);
+}