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

Vinson Lee vlee at vmware.com
Wed Jul 6 23:08:42 PDT 2011


Mac OS X 10.6.8

All four tests display a green window.

override-builtin-01: pass
override-builtin-02: pass
override-builtin-03: pass
override-builtin-04: pass


________________________________________
From: Ian Romanick [idr at freedesktop.org]
Sent: Wednesday, July 06, 2011 4:52 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."

These tests all pass on NVIDIA's closed-source driver, but many fail
on AMD's driver.  I have not test Apple's driver or Intel's Windows driver.

This is related to Mesa bug #31744.

Cc: Vinson Lee <vlee at vmware.com>
---
 tests/all.tests                                    |    4 ++
 .../linker/override-builtin-01.shader_test         |   27 ++++++++++++++++++
 .../linker/override-builtin-02.shader_test         |   27 ++++++++++++++++++
 .../linker/override-builtin-03.shader_test         |   28 ++++++++++++++++++
 .../linker/override-builtin-04.shader_test         |   30 ++++++++++++++++++++
 5 files changed, 116 insertions(+), 0 deletions(-)
 create mode 100644 tests/spec/glsl-1.10/linker/override-builtin-01.shader_test
 create mode 100644 tests/spec/glsl-1.10/linker/override-builtin-02.shader_test
 create mode 100644 tests/spec/glsl-1.10/linker/override-builtin-03.shader_test
 create mode 100644 tests/spec/glsl-1.10/linker/override-builtin-04.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-01.shader_test b/tests/spec/glsl-1.10/linker/override-builtin-01.shader_test
new file mode 100644
index 0000000..148ea98
--- /dev/null
+++ b/tests/spec/glsl-1.10/linker/override-builtin-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-02.shader_test b/tests/spec/glsl-1.10/linker/override-builtin-02.shader_test
new file mode 100644
index 0000000..f941959
--- /dev/null
+++ b/tests/spec/glsl-1.10/linker/override-builtin-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-03.shader_test b/tests/spec/glsl-1.10/linker/override-builtin-03.shader_test
new file mode 100644
index 0000000..f3c6c01
--- /dev/null
+++ b/tests/spec/glsl-1.10/linker/override-builtin-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-04.shader_test b/tests/spec/glsl-1.10/linker/override-builtin-04.shader_test
new file mode 100644
index 0000000..ed85b50
--- /dev/null
+++ b/tests/spec/glsl-1.10/linker/override-builtin-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
--
1.7.4.4



More information about the Piglit mailing list