[Piglit] [PATCH] glsl-1.10: Add some tests for over-riding built-in functions

Vinson Lee vlee at vmware.com
Sat Jul 9 00:08:35 PDT 2011


Mac OS X 10.6.8

override-builtin-const-0[1-8]: all pass
override-builtin-uniform-0[1-8]: all pass

________________________________________
From: Ian Romanick [idr at freedesktop.org]
Sent: Friday, July 08, 2011 12:57 PM
To: piglit at lists.freedesktop.org
Cc: Vinson Lee
Subject: [PATCH] glsl-1.10: Add some tests for over-riding built-in functions

From: Ian Romanick <ian.d.romanick at intel.com>

These are somewhat justified by the GLSL spec:

    "A shader can redefine built-in functions. If a built-in function
    is redeclared in a shader (i.e. a prototype is visible) before a
    call to it, then the linker will only attempt to resolve that call
    within the set shaders that are linked with it."

This also matches the behavior that the OpenGL Shading Language (the
"orange" book) tells people to expect:

    "If the definition is in a different shader, just make sure a
    prototype is visible before calling the function. Otherwise, the
    built-in version is used."

All of these tests pass on NVIDIA's closed-source driver.

All of these tests pass on AMD's closed-source driver except
override-builtin-*-07.

Many of these tests fail on Mesa: override-builtin-const-0[57] and
override-builtin-uniform-0[13567].

I have not tested Apple's driver or Intel's Windows driver.

v2: Adds two more tests (override-builtin-0[56]) suggested by Ken and
Chad.  It also adds versions of all six tests that use uniforms as
parameters to the built-in instead of constants.

v3: Add several more tests (override-builtin-1[3456]) that are
variations of the existing glsl-override-builtin-2 test.  Renamed the
tests so that the constant tests have 'const' in the name and the
non-constant tests have 'uniform' in the name.  The tests with the
same number should be essentially identical.

This is related to Mesa bug #31744.

Cc: Vinson Lee <vlee at vmware.com>
---
 tests/all.tests                                    |    4 ++
 .../linker/override-builtin-const-01.shader_test   |   27 ++++++++++++
 .../linker/override-builtin-const-02.shader_test   |   27 ++++++++++++
 .../linker/override-builtin-const-03.shader_test   |   28 ++++++++++++
 .../linker/override-builtin-const-04.shader_test   |   30 +++++++++++++
 .../linker/override-builtin-const-05.shader_test   |   37 ++++++++++++++++
 .../linker/override-builtin-const-06.shader_test   |   30 +++++++++++++
 .../linker/override-builtin-const-07.shader_test   |   40 +++++++++++++++++
 .../linker/override-builtin-const-08.shader_test   |   42 ++++++++++++++++++
 .../linker/override-builtin-uniform-01.shader_test |   30 +++++++++++++
 .../linker/override-builtin-uniform-02.shader_test |   35 +++++++++++++++
 .../linker/override-builtin-uniform-03.shader_test |   31 +++++++++++++
 .../linker/override-builtin-uniform-04.shader_test |   37 ++++++++++++++++
 .../linker/override-builtin-uniform-05.shader_test |   40 +++++++++++++++++
 .../linker/override-builtin-uniform-06.shader_test |   33 ++++++++++++++
 .../linker/override-builtin-uniform-07.shader_test |   43 +++++++++++++++++++
 .../linker/override-builtin-uniform-08.shader_test |   45 ++++++++++++++++++++
 17 files changed, 559 insertions(+), 0 deletions(-)
 create mode 100644 tests/spec/glsl-1.10/linker/override-builtin-const-01.shader_test
 create mode 100644 tests/spec/glsl-1.10/linker/override-builtin-const-02.shader_test
 create mode 100644 tests/spec/glsl-1.10/linker/override-builtin-const-03.shader_test
 create mode 100644 tests/spec/glsl-1.10/linker/override-builtin-const-04.shader_test
 create mode 100644 tests/spec/glsl-1.10/linker/override-builtin-const-05.shader_test
 create mode 100644 tests/spec/glsl-1.10/linker/override-builtin-const-06.shader_test
 create mode 100644 tests/spec/glsl-1.10/linker/override-builtin-const-07.shader_test
 create mode 100644 tests/spec/glsl-1.10/linker/override-builtin-const-08.shader_test
 create mode 100644 tests/spec/glsl-1.10/linker/override-builtin-uniform-01.shader_test
 create mode 100644 tests/spec/glsl-1.10/linker/override-builtin-uniform-02.shader_test
 create mode 100644 tests/spec/glsl-1.10/linker/override-builtin-uniform-03.shader_test
 create mode 100644 tests/spec/glsl-1.10/linker/override-builtin-uniform-04.shader_test
 create mode 100644 tests/spec/glsl-1.10/linker/override-builtin-uniform-05.shader_test
 create mode 100644 tests/spec/glsl-1.10/linker/override-builtin-uniform-06.shader_test
 create mode 100644 tests/spec/glsl-1.10/linker/override-builtin-uniform-07.shader_test
 create mode 100644 tests/spec/glsl-1.10/linker/override-builtin-uniform-08.shader_test

diff --git a/tests/all.tests b/tests/all.tests
index 7754e17..1c71a0d 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -691,6 +691,10 @@ spec['glsl-1.10'] = Group()
 import_glsl_parser_tests(spec['glsl-1.10'],
                         os.path.join(os.path.dirname(__file__), 'spec', 'glsl-1.10'),
                         ['preprocessor', 'compiler'])
+spec['glsl-1.10']['linker'] = Group()
+add_shader_test_dir(spec['glsl-1.10']['linker'],
+                   os.path.join(os.path.dirname(__file__), 'spec', 'glsl-1.10', 'linker'),
+                   recursive=True)

 # Group spec/glsl-1.20
 spec['glsl-1.20'] = Group()
diff --git a/tests/spec/glsl-1.10/linker/override-builtin-const-01.shader_test b/tests/spec/glsl-1.10/linker/override-builtin-const-01.shader_test
new file mode 100644
index 0000000..148ea98
--- /dev/null
+++ b/tests/spec/glsl-1.10/linker/override-builtin-const-01.shader_test
@@ -0,0 +1,27 @@
+[require]
+GLSL >= 1.10
+
+[vertex shader]
+void main() { gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; }
+
+[fragment shader]
+/* From page 38 (page 44 of the PDF) of the GLSL 1.10 spec:
+ *
+ *     "A shader can redefine built-in functions. If a built-in function is
+ *     redeclared in a shader (i.e. a prototype is visible) before a call to
+ *     it, then the linker will only attempt to resolve that call within the
+ *     set shaders that are linked with it."
+ */
+void main()
+{
+  gl_FragColor = abs(vec4(0.0, -1.0, 0.0, 1.0));
+}
+
+vec4 abs(vec4 unused)
+{
+  return vec4(1.0, 0.0, 0.0, 1.0);
+}
+
+[test]
+draw rect -1 -1 2 2
+probe all rgb 0.0 1.0 0.0
diff --git a/tests/spec/glsl-1.10/linker/override-builtin-const-02.shader_test b/tests/spec/glsl-1.10/linker/override-builtin-const-02.shader_test
new file mode 100644
index 0000000..f941959
--- /dev/null
+++ b/tests/spec/glsl-1.10/linker/override-builtin-const-02.shader_test
@@ -0,0 +1,27 @@
+[require]
+GLSL >= 1.10
+
+[vertex shader]
+void main() { gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; }
+
+[fragment shader]
+/* From page 38 (page 44 of the PDF) of the GLSL 1.10 spec:
+ *
+ *     "A shader can redefine built-in functions. If a built-in function is
+ *     redeclared in a shader (i.e. a prototype is visible) before a call to
+ *     it, then the linker will only attempt to resolve that call within the
+ *     set shaders that are linked with it."
+ */
+vec4 abs(vec4 unused)
+{
+  return vec4(0.0, 1.0, 0.0, 1.0);
+}
+
+void main()
+{
+  gl_FragColor = abs(vec4(1.0, 0.0, 0.0, 1.0));
+}
+
+[test]
+draw rect -1 -1 2 2
+probe all rgb 0.0 1.0 0.0
diff --git a/tests/spec/glsl-1.10/linker/override-builtin-const-03.shader_test b/tests/spec/glsl-1.10/linker/override-builtin-const-03.shader_test
new file mode 100644
index 0000000..f3c6c01
--- /dev/null
+++ b/tests/spec/glsl-1.10/linker/override-builtin-const-03.shader_test
@@ -0,0 +1,28 @@
+[require]
+GLSL >= 1.10
+
+[vertex shader]
+void main() { gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; }
+
+[fragment shader]
+/* From page 38 (page 44 of the PDF) of the GLSL 1.10 spec:
+ *
+ *     "A shader can redefine built-in functions. If a built-in function is
+ *     redeclared in a shader (i.e. a prototype is visible) before a call to
+ *     it, then the linker will only attempt to resolve that call within the
+ *     set shaders that are linked with it."
+ */
+void main()
+{
+  gl_FragColor = abs(vec4(0.0, -1.0, 0.0, 1.0));
+}
+
+[fragment shader]
+vec4 abs(vec4 unused)
+{
+  return vec4(1.0, 0.0, 0.0, 1.0);
+}
+
+[test]
+draw rect -1 -1 2 2
+probe all rgb 0.0 1.0 0.0
diff --git a/tests/spec/glsl-1.10/linker/override-builtin-const-04.shader_test b/tests/spec/glsl-1.10/linker/override-builtin-const-04.shader_test
new file mode 100644
index 0000000..ed85b50
--- /dev/null
+++ b/tests/spec/glsl-1.10/linker/override-builtin-const-04.shader_test
@@ -0,0 +1,30 @@
+[require]
+GLSL >= 1.10
+
+[vertex shader]
+void main() { gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; }
+
+[fragment shader]
+/* From page 38 (page 44 of the PDF) of the GLSL 1.10 spec:
+ *
+ *     "A shader can redefine built-in functions. If a built-in function is
+ *     redeclared in a shader (i.e. a prototype is visible) before a call to
+ *     it, then the linker will only attempt to resolve that call within the
+ *     set shaders that are linked with it."
+ */
+vec4 abs(vec4 unused);
+
+void main()
+{
+  gl_FragColor = abs(vec4(1.0, 0.0, 0.0, 1.0));
+}
+
+[fragment shader]
+vec4 abs(vec4 unused)
+{
+  return vec4(0.0, 1.0, 0.0, 1.0);
+}
+
+[test]
+draw rect -1 -1 2 2
+probe all rgb 0.0 1.0 0.0
diff --git a/tests/spec/glsl-1.10/linker/override-builtin-const-05.shader_test b/tests/spec/glsl-1.10/linker/override-builtin-const-05.shader_test
new file mode 100644
index 0000000..a8c95ed
--- /dev/null
+++ b/tests/spec/glsl-1.10/linker/override-builtin-const-05.shader_test
@@ -0,0 +1,37 @@
+[require]
+GLSL >= 1.10
+
+[vertex shader]
+void main() { gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; }
+
+[fragment shader]
+/* From page 38 (page 44 of the PDF) of the GLSL 1.10 spec:
+ *
+ *     "A shader can redefine built-in functions. If a built-in function is
+ *     redeclared in a shader (i.e. a prototype is visible) before a call to
+ *     it, then the linker will only attempt to resolve that call within the
+ *     set shaders that are linked with it."
+ */
+float func(float x)
+{
+  return abs(x);
+}
+
+float abs(float x)
+{
+  return x;
+}
+
+void main()
+{
+  /* The call to abs in func should bind to the built-in version, but
+   * the call to abs here, which follows the override, should not.
+   */
+  gl_FragColor = (func(-1.0) == abs(-1.0))
+                 ? vec4(1.0, 0.0, 0.0, 1.0)
+                 : vec4(0.0, 1.0, 0.0, 1.0);
+}
+
+[test]
+draw rect -1 -1 2 2
+probe all rgb 0.0 1.0 0.0
diff --git a/tests/spec/glsl-1.10/linker/override-builtin-const-06.shader_test b/tests/spec/glsl-1.10/linker/override-builtin-const-06.shader_test
new file mode 100644
index 0000000..ca0b717
--- /dev/null
+++ b/tests/spec/glsl-1.10/linker/override-builtin-const-06.shader_test
@@ -0,0 +1,30 @@
+[require]
+GLSL >= 1.10
+
+[vertex shader]
+void main() { gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; }
+
+[fragment shader]
+/* From page 38 (page 44 of the PDF) of the GLSL 1.10 spec:
+ *
+ *     "A shader can redefine built-in functions. If a built-in function is
+ *     redeclared in a shader (i.e. a prototype is visible) before a call to
+ *     it, then the linker will only attempt to resolve that call within the
+ *     set shaders that are linked with it."
+ */
+void main()
+{
+  gl_FragColor = abs(vec4(0.0, -1.0, 0.0, 1.0));
+}
+
+vec4 abs(vec4 unused);
+
+[fragment shader]
+vec4 abs(vec4 unused)
+{
+  return vec4(1.0, 0.0, 0.0, 1.0);
+}
+
+[test]
+draw rect -1 -1 2 2
+probe all rgb 0.0 1.0 0.0
diff --git a/tests/spec/glsl-1.10/linker/override-builtin-const-07.shader_test b/tests/spec/glsl-1.10/linker/override-builtin-const-07.shader_test
new file mode 100644
index 0000000..17a6391
--- /dev/null
+++ b/tests/spec/glsl-1.10/linker/override-builtin-const-07.shader_test
@@ -0,0 +1,40 @@
+[require]
+GLSL >= 1.10
+
+[vertex shader]
+void main() { gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; }
+
+[fragment shader]
+/* From page 38 (page 44 of the PDF) of the GLSL 1.10 spec:
+ *
+ *     "A shader can redefine built-in functions. If a built-in function is
+ *     redeclared in a shader (i.e. a prototype is visible) before a call to
+ *     it, then the linker will only attempt to resolve that call within the
+ *     set shaders that are linked with it."
+ */
+float func(float);
+
+float abs(float x)
+{
+  return x;
+}
+
+void main()
+{
+  /* The call to abs in func should bind to the built-in version, but
+   * the call to abs here, which follows the override, should not.
+   */
+  gl_FragColor = (func(-1.0) == abs(-1.0))
+                 ? vec4(1.0, 0.0, 0.0, 1.0)
+                 : vec4(0.0, 1.0, 0.0, 1.0);
+}
+
+[fragment shader]
+float func(float x)
+{
+  return abs(x);
+}
+
+[test]
+draw rect -1 -1 2 2
+probe all rgb 0.0 1.0 0.0
diff --git a/tests/spec/glsl-1.10/linker/override-builtin-const-08.shader_test b/tests/spec/glsl-1.10/linker/override-builtin-const-08.shader_test
new file mode 100644
index 0000000..fedfa53
--- /dev/null
+++ b/tests/spec/glsl-1.10/linker/override-builtin-const-08.shader_test
@@ -0,0 +1,42 @@
+[require]
+GLSL >= 1.10
+
+[vertex shader]
+void main() { gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; }
+
+[fragment shader]
+/* From page 38 (page 44 of the PDF) of the GLSL 1.10 spec:
+ *
+ *     "A shader can redefine built-in functions. If a built-in function is
+ *     redeclared in a shader (i.e. a prototype is visible) before a call to
+ *     it, then the linker will only attempt to resolve that call within the
+ *     set shaders that are linked with it."
+ */
+float func(float);
+
+float abs(float x)
+{
+  return x;
+}
+
+void main()
+{
+  /* The call to abs in func should bind to the built-in version, but
+   * the call to abs here, which follows the override, should not.
+   */
+  gl_FragColor = (func(-1.0) != abs(-1.0))
+                 ? vec4(1.0, 0.0, 0.0, 1.0)
+                 : vec4(0.0, 1.0, 0.0, 1.0);
+}
+
+[fragment shader]
+float abs(float);
+
+float func(float x)
+{
+  return abs(x);
+}
+
+[test]
+draw rect -1 -1 2 2
+probe all rgb 0.0 1.0 0.0
diff --git a/tests/spec/glsl-1.10/linker/override-builtin-uniform-01.shader_test b/tests/spec/glsl-1.10/linker/override-builtin-uniform-01.shader_test
new file mode 100644
index 0000000..3e05b7a
--- /dev/null
+++ b/tests/spec/glsl-1.10/linker/override-builtin-uniform-01.shader_test
@@ -0,0 +1,30 @@
+[require]
+GLSL >= 1.10
+
+[vertex shader]
+void main() { gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; }
+
+[fragment shader]
+/* From page 38 (page 44 of the PDF) of the GLSL 1.10 spec:
+ *
+ *     "A shader can redefine built-in functions. If a built-in function is
+ *     redeclared in a shader (i.e. a prototype is visible) before a call to
+ *     it, then the linker will only attempt to resolve that call within the
+ *     set shaders that are linked with it."
+ */
+uniform vec4 v;
+
+void main()
+{
+  gl_FragColor = abs(v);
+}
+
+vec4 abs(vec4 unused)
+{
+  return vec4(1.0, 0.0, 0.0, 1.0);
+}
+
+[test]
+uniform vec4 v 0.0 -1.0 0.0 1.0
+draw rect -1 -1 2 2
+probe all rgb 0.0 1.0 0.0
diff --git a/tests/spec/glsl-1.10/linker/override-builtin-uniform-02.shader_test b/tests/spec/glsl-1.10/linker/override-builtin-uniform-02.shader_test
new file mode 100644
index 0000000..c309ae7
--- /dev/null
+++ b/tests/spec/glsl-1.10/linker/override-builtin-uniform-02.shader_test
@@ -0,0 +1,35 @@
+[require]
+GLSL >= 1.10
+
+[vertex shader]
+void main() { gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; }
+
+[fragment shader]
+/* From page 38 (page 44 of the PDF) of the GLSL 1.10 spec:
+ *
+ *     "A shader can redefine built-in functions. If a built-in function is
+ *     redeclared in a shader (i.e. a prototype is visible) before a call to
+ *     it, then the linker will only attempt to resolve that call within the
+ *     set shaders that are linked with it."
+ */
+uniform vec4 v;
+
+vec4 abs(vec4 x)
+{
+  /* Return a swizzle of x instead of a constant value because we don't want
+   * the compiler to optimize away all uses of the uniform.  This will make
+   * the test fail because shader_runner won't be able to glGetUnformLocation
+   * on the uniform.
+   */
+  return x.yxzw;
+}
+
+void main()
+{
+  gl_FragColor = abs(v);
+}
+
+[test]
+uniform vec4 v 1.0 0.0 0.0 1.0
+draw rect -1 -1 2 2
+probe all rgb 0.0 1.0 0.0
diff --git a/tests/spec/glsl-1.10/linker/override-builtin-uniform-03.shader_test b/tests/spec/glsl-1.10/linker/override-builtin-uniform-03.shader_test
new file mode 100644
index 0000000..5c91829
--- /dev/null
+++ b/tests/spec/glsl-1.10/linker/override-builtin-uniform-03.shader_test
@@ -0,0 +1,31 @@
+[require]
+GLSL >= 1.10
+
+[vertex shader]
+void main() { gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; }
+
+[fragment shader]
+/* From page 38 (page 44 of the PDF) of the GLSL 1.10 spec:
+ *
+ *     "A shader can redefine built-in functions. If a built-in function is
+ *     redeclared in a shader (i.e. a prototype is visible) before a call to
+ *     it, then the linker will only attempt to resolve that call within the
+ *     set shaders that are linked with it."
+ */
+uniform vec4 v;
+
+void main()
+{
+  gl_FragColor = abs(v);
+}
+
+[fragment shader]
+vec4 abs(vec4 unused)
+{
+  return vec4(1.0, 0.0, 0.0, 1.0);
+}
+
+[test]
+uniform vec4 v 0.0 -1.0 0.0 1.0
+draw rect -1 -1 2 2
+probe all rgb 0.0 1.0 0.0
diff --git a/tests/spec/glsl-1.10/linker/override-builtin-uniform-04.shader_test b/tests/spec/glsl-1.10/linker/override-builtin-uniform-04.shader_test
new file mode 100644
index 0000000..7337b2f
--- /dev/null
+++ b/tests/spec/glsl-1.10/linker/override-builtin-uniform-04.shader_test
@@ -0,0 +1,37 @@
+[require]
+GLSL >= 1.10
+
+[vertex shader]
+void main() { gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; }
+
+[fragment shader]
+/* From page 38 (page 44 of the PDF) of the GLSL 1.10 spec:
+ *
+ *     "A shader can redefine built-in functions. If a built-in function is
+ *     redeclared in a shader (i.e. a prototype is visible) before a call to
+ *     it, then the linker will only attempt to resolve that call within the
+ *     set shaders that are linked with it."
+ */
+uniform vec4 v;
+vec4 abs(vec4 x);
+
+void main()
+{
+  gl_FragColor = abs(v);
+}
+
+[fragment shader]
+vec4 abs(vec4 x)
+{
+  /* Return a swizzle of x instead of a constant value because we don't want
+   * the compiler to optimize away all uses of the uniform.  This will make
+   * the test fail because shader_runner won't be able to glGetUnformLocation
+   * on the uniform.
+   */
+  return x.yxzw;
+}
+
+[test]
+uniform vec4 v 1.0 0.0 0.0 1.0
+draw rect -1 -1 2 2
+probe all rgb 0.0 1.0 0.0
diff --git a/tests/spec/glsl-1.10/linker/override-builtin-uniform-05.shader_test b/tests/spec/glsl-1.10/linker/override-builtin-uniform-05.shader_test
new file mode 100644
index 0000000..67dd5e3
--- /dev/null
+++ b/tests/spec/glsl-1.10/linker/override-builtin-uniform-05.shader_test
@@ -0,0 +1,40 @@
+[require]
+GLSL >= 1.10
+
+[vertex shader]
+void main() { gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; }
+
+[fragment shader]
+/* From page 38 (page 44 of the PDF) of the GLSL 1.10 spec:
+ *
+ *     "A shader can redefine built-in functions. If a built-in function is
+ *     redeclared in a shader (i.e. a prototype is visible) before a call to
+ *     it, then the linker will only attempt to resolve that call within the
+ *     set shaders that are linked with it."
+ */
+uniform float f;
+
+float func(float x)
+{
+  return abs(x);
+}
+
+float abs(float x)
+{
+  return x;
+}
+
+void main()
+{
+  /* The call to abs in func should bind to the built-in version, but
+   * the call to abs here, which follows the override, should not.
+   */
+  gl_FragColor = (func(f) == abs(f))
+                 ? vec4(1.0, 0.0, 0.0, 1.0)
+                 : vec4(0.0, 1.0, 0.0, 1.0);
+}
+
+[test]
+uniform float f -1.0
+draw rect -1 -1 2 2
+probe all rgb 0.0 1.0 0.0
diff --git a/tests/spec/glsl-1.10/linker/override-builtin-uniform-06.shader_test b/tests/spec/glsl-1.10/linker/override-builtin-uniform-06.shader_test
new file mode 100644
index 0000000..b2d8cf4
--- /dev/null
+++ b/tests/spec/glsl-1.10/linker/override-builtin-uniform-06.shader_test
@@ -0,0 +1,33 @@
+[require]
+GLSL >= 1.10
+
+[vertex shader]
+void main() { gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; }
+
+[fragment shader]
+/* From page 38 (page 44 of the PDF) of the GLSL 1.10 spec:
+ *
+ *     "A shader can redefine built-in functions. If a built-in function is
+ *     redeclared in a shader (i.e. a prototype is visible) before a call to
+ *     it, then the linker will only attempt to resolve that call within the
+ *     set shaders that are linked with it."
+ */
+uniform vec4 v;
+
+void main()
+{
+  gl_FragColor = abs(v);
+}
+
+vec4 abs(vec4 unused);
+
+[fragment shader]
+vec4 abs(vec4 unused)
+{
+  return vec4(1.0, 0.0, 0.0, 1.0);
+}
+
+[test]
+uniform vec4 v 0.0 -1.0 0.0 1.0
+draw rect -1 -1 2 2
+probe all rgb 0.0 1.0 0.0
diff --git a/tests/spec/glsl-1.10/linker/override-builtin-uniform-07.shader_test b/tests/spec/glsl-1.10/linker/override-builtin-uniform-07.shader_test
new file mode 100644
index 0000000..b2f9af3
--- /dev/null
+++ b/tests/spec/glsl-1.10/linker/override-builtin-uniform-07.shader_test
@@ -0,0 +1,43 @@
+[require]
+GLSL >= 1.10
+
+[vertex shader]
+void main() { gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; }
+
+[fragment shader]
+/* From page 38 (page 44 of the PDF) of the GLSL 1.10 spec:
+ *
+ *     "A shader can redefine built-in functions. If a built-in function is
+ *     redeclared in a shader (i.e. a prototype is visible) before a call to
+ *     it, then the linker will only attempt to resolve that call within the
+ *     set shaders that are linked with it."
+ */
+uniform float f;
+
+float func(float);
+
+float abs(float x)
+{
+  return x;
+}
+
+void main()
+{
+  /* The call to abs in func should bind to the built-in version, but
+   * the call to abs here, which follows the override, should not.
+   */
+  gl_FragColor = (func(f) == abs(f))
+                 ? vec4(1.0, 0.0, 0.0, 1.0)
+                 : vec4(0.0, 1.0, 0.0, 1.0);
+}
+
+[fragment shader]
+float func(float x)
+{
+  return abs(x);
+}
+
+[test]
+uniform float f -1.0
+draw rect -1 -1 2 2
+probe all rgb 0.0 1.0 0.0
diff --git a/tests/spec/glsl-1.10/linker/override-builtin-uniform-08.shader_test b/tests/spec/glsl-1.10/linker/override-builtin-uniform-08.shader_test
new file mode 100644
index 0000000..6e290ca
--- /dev/null
+++ b/tests/spec/glsl-1.10/linker/override-builtin-uniform-08.shader_test
@@ -0,0 +1,45 @@
+[require]
+GLSL >= 1.10
+
+[vertex shader]
+void main() { gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; }
+
+[fragment shader]
+/* From page 38 (page 44 of the PDF) of the GLSL 1.10 spec:
+ *
+ *     "A shader can redefine built-in functions. If a built-in function is
+ *     redeclared in a shader (i.e. a prototype is visible) before a call to
+ *     it, then the linker will only attempt to resolve that call within the
+ *     set shaders that are linked with it."
+ */
+uniform float f;
+
+float func(float);
+
+float abs(float x)
+{
+  return x;
+}
+
+void main()
+{
+  /* The call to abs in func should bind to the built-in version, but
+   * the call to abs here, which follows the override, should not.
+   */
+  gl_FragColor = (func(f) != abs(f))
+                 ? vec4(1.0, 0.0, 0.0, 1.0)
+                 : vec4(0.0, 1.0, 0.0, 1.0);
+}
+
+[fragment shader]
+float abs(float);
+
+float func(float x)
+{
+  return abs(x);
+}
+
+[test]
+uniform float f -1.0
+draw rect -1 -1 2 2
+probe all rgb 0.0 1.0 0.0
--
1.7.4.4



More information about the Piglit mailing list