summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Anholt <eric@anholt.net>2010-03-22 13:16:13 -0700
committerEric Anholt <eric@anholt.net>2010-03-22 13:43:56 -0700
commit3ca7da2977828dee8abea689a67dcd6825a140ce (patch)
tree8579b5f935ce6f63f56f04dab77cdaf49f42eefc
parentfa51797b710b470401d4f2dee20e14387b7cb988 (diff)
glsl-vs-functions: New test for Mesa function calls in the VS.
-rw-r--r--tests/all.tests1
-rw-r--r--tests/shaders/CMakeLists.txt1
-rw-r--r--tests/shaders/glsl-vs-functions.c84
-rw-r--r--tests/shaders/glsl-vs-functions.vert30
4 files changed, 116 insertions, 0 deletions
diff --git a/tests/all.tests b/tests/all.tests
index 39ef218a7..4ab20222b 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -163,6 +163,7 @@ add_plain_test(shaders, 'glsl-fs-mix-constant')
add_plain_test(shaders, 'glsl-fs-sqrt-branch')
add_plain_test(shaders, 'glsl-fs-sqrt-zero')
add_plain_test(shaders, 'glsl-vs-arrays')
+add_plain_test(shaders, 'glsl-vs-functions')
add_plain_test(shaders, 'glsl-vs-if')
add_plain_test(shaders, 'glsl-vs-if-bool')
add_plain_test(shaders, 'glsl-vs-loop')
diff --git a/tests/shaders/CMakeLists.txt b/tests/shaders/CMakeLists.txt
index 83f1392ae..d049321fa 100644
--- a/tests/shaders/CMakeLists.txt
+++ b/tests/shaders/CMakeLists.txt
@@ -59,6 +59,7 @@ add_executable (glsl-fs-sqrt-branch glsl-fs-sqrt-branch.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)
+add_executable (glsl-vs-functions glsl-vs-functions.c)
add_executable (glsl-vs-if glsl-vs-if.c)
add_executable (glsl-vs-if-bool glsl-vs-if-bool.c)
add_executable (glsl-vs-loop glsl-vs-loop.c)
diff --git a/tests/shaders/glsl-vs-functions.c b/tests/shaders/glsl-vs-functions.c
new file mode 100644
index 000000000..c48958b40
--- /dev/null
+++ b/tests/shaders/glsl-vs-functions.c
@@ -0,0 +1,84 @@
+/*
+ * Copyright © 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>
+ *
+ */
+
+/** @file glsl-vs-functions.c
+ *
+ * Tests that function calls in the VS work.
+ *
+ * This was designed to catch a regression I introduced in the 965 driver
+ * with jumps to function calls being wrong.
+ */
+
+#include "piglit-util.h"
+
+int piglit_width = 100, piglit_height = 100;
+int piglit_window_mode = GLUT_RGB | GLUT_DOUBLE | GLUT_ALPHA;
+
+static GLint prog;
+static int args1_location;
+
+enum piglit_result
+piglit_display(void)
+{
+ GLboolean pass = GL_TRUE;
+ static const float args1[] = {0.0, 1.0, 1.0, 0.0};
+ static const float result[] = {0.0, 1.0, 0.0, 1.0};
+
+ glUniform4fv(args1_location, 1, args1);
+ piglit_draw_rect(0, 0, piglit_width, piglit_height);
+
+ pass &= piglit_probe_pixel_rgba(piglit_width / 2, piglit_height / 2,
+ result);
+
+ glutSwapBuffers();
+
+ return pass ? PIGLIT_SUCCESS : PIGLIT_FAILURE;
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+ GLint vs, fs;
+
+ if (!GLEW_VERSION_2_0) {
+ printf("Requires OpenGL 2.0\n");
+ piglit_report_result(PIGLIT_SKIP);
+ }
+
+ piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
+
+ vs = piglit_compile_shader(GL_VERTEX_SHADER,
+ "shaders/glsl-vs-functions.vert");
+ fs = piglit_compile_shader(GL_FRAGMENT_SHADER,
+ "shaders/glsl-color.frag");
+
+ prog = piglit_link_simple_program(vs, fs);
+
+ args1_location = glGetUniformLocation(prog, "args1");
+
+ glUseProgram(prog);
+}
diff --git a/tests/shaders/glsl-vs-functions.vert b/tests/shaders/glsl-vs-functions.vert
new file mode 100644
index 000000000..cdb023a98
--- /dev/null
+++ b/tests/shaders/glsl-vs-functions.vert
@@ -0,0 +1,30 @@
+uniform vec4 args1;
+
+/* In order to make the Mesa compiler not inline the function calls, have
+ * return statements inside of branches.
+ */
+float f1(float f)
+{
+ if (f > 0.5)
+ return 1.0;
+ else
+ return 0.0;
+}
+
+float f2(float f)
+{
+ if (f < 0.5)
+ return 1.0;
+ else
+ return 0.0;
+}
+
+void main()
+{
+ gl_FrontColor = vec4(f1(args1.x),
+ f1(args1.y),
+ f2(args1.z),
+ f2(args1.w));
+ gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
+}
+