summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Anholt <eric@anholt.net>2010-03-09 10:07:50 -0800
committerEric Anholt <eric@anholt.net>2010-03-09 13:19:20 -0800
commit4eb5b97f69fcc9dd9abb2e4b4992657c0382010b (patch)
tree07b46a5d2bca188240de4ee94ea42549d5d9d1ed
parent1c5eea9b18e7ac4d287608014dab6ce159cf06e6 (diff)
glsl-fs-loop: New test for loops in the fragment shader.
Shows off failure in the 965 driver in unaliasing registers for GLSL.
-rw-r--r--tests/all.tests1
-rw-r--r--tests/shaders/CMakeLists.txt1
-rw-r--r--tests/shaders/glsl-fs-loop.c120
-rw-r--r--tests/shaders/glsl-fs-loop.frag14
4 files changed, 136 insertions, 0 deletions
diff --git a/tests/all.tests b/tests/all.tests
index da71ebda0..d054f7676 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -153,6 +153,7 @@ add_plain_test(shaders, 'glsl-unused-varying')
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-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 a04fa6f09..14ebfa95a 100644
--- a/tests/shaders/CMakeLists.txt
+++ b/tests/shaders/CMakeLists.txt
@@ -50,6 +50,7 @@ add_executable (glsl-uniform-out-of-bounds glsl-uniform-out-of-bounds.c)
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-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.c b/tests/shaders/glsl-fs-loop.c
new file mode 100644
index 000000000..aa70e9d1e
--- /dev/null
+++ b/tests/shaders/glsl-fs-loop.c
@@ -0,0 +1,120 @@
+/*
+ * 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.c
+ *
+ * Tests that 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 vertex 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);
+
+ memcpy(line_color, color, sizeof(line_color));
+ for (j = 0; j < 3; j++) {
+ unsigned y = 5 + (25 * j);
+
+ line_color[3] = (float) 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 = line_color[2];
+ line_color[2] = line_color[1];
+ line_color[1] = line_color[0];
+ line_color[0] = temp;
+ }
+
+ 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.frag");
+
+ prog = piglit_link_simple_program(vs, fs);
+
+ glUseProgram(prog);
+
+ color_location = glGetUniformLocation(prog, "color");
+}
diff --git a/tests/shaders/glsl-fs-loop.frag b/tests/shaders/glsl-fs-loop.frag
new file mode 100644
index 000000000..b00b9580a
--- /dev/null
+++ b/tests/shaders/glsl-fs-loop.frag
@@ -0,0 +1,14 @@
+uniform vec4 color;
+
+void main()
+{
+ int count = int(color.w);
+ vec3 c = color.xyz;
+ int i;
+
+ for (i = 0; i < count; i++) {
+ c = c.yzx;
+ }
+
+ gl_FragColor = vec4(c, 1.0);
+}