[Piglit] [PATCH 2/2] Test that shaders are not allowed to declare non-uniform samplers.

Paul Berry stereotype441 at gmail.com
Wed Jul 13 15:28:33 PDT 2011


These tests check conformance with page 17 (page 23 of the PDF) of the
GLSL 1.20 spec:

     "[Samplers] can only be declared as function parameters or
     uniform variables (see Section 4.3.5 "Uniform"). ... [Samplers]
     cannot be used as out or inout function parameters"

The GLSL 1.10 spec has a similar restriction which omits mention of
"out" and "inout" function parameters, however it's clear from context
that the 1.10 spec was not intended to be more permissive; it was
simply not stated as clearly.  Accordingly, I've placed the tests in
the glsl-1.10 directory.

8 of the new tests are "compiler" tests, which verify that shaders are
rejected when they include a sampler in a toplevel non-uniform
declaration, or in a function paramter that is "out" or "inout".  The
remaining 4 tests are "execution" tests, which verify that samplers
work properly when declared as uniforms or "in" function parameters.
---
 tests/all.tests                                    |    4 ++
 .../glsl-1.10/compiler/samplers/inout-struct.frag  |   26 +++++++++++++
 tests/spec/glsl-1.10/compiler/samplers/inout.frag  |   21 +++++++++++
 .../compiler/samplers/nonuniform-struct.frag       |   19 ++++++++++
 .../glsl-1.10/compiler/samplers/nonuniform.frag    |   12 ++++++
 .../glsl-1.10/compiler/samplers/out-struct.frag    |   26 +++++++++++++
 tests/spec/glsl-1.10/compiler/samplers/out.frag    |   21 +++++++++++
 .../glsl-1.10/compiler/samplers/return-struct.frag |   24 ++++++++++++
 tests/spec/glsl-1.10/compiler/samplers/return.frag |   21 +++++++++++
 .../samplers/in-parameter-struct.shader_test       |   38 ++++++++++++++++++++
 .../execution/samplers/in-parameter.shader_test    |   36 ++++++++++++++++++
 .../samplers/normal-parameter-struct.shader_test   |   38 ++++++++++++++++++++
 .../samplers/normal-parameter.shader_test          |   36 ++++++++++++++++++
 13 files changed, 322 insertions(+), 0 deletions(-)
 create mode 100644 tests/spec/glsl-1.10/compiler/samplers/inout-struct.frag
 create mode 100644 tests/spec/glsl-1.10/compiler/samplers/inout.frag
 create mode 100644 tests/spec/glsl-1.10/compiler/samplers/nonuniform-struct.frag
 create mode 100644 tests/spec/glsl-1.10/compiler/samplers/nonuniform.frag
 create mode 100644 tests/spec/glsl-1.10/compiler/samplers/out-struct.frag
 create mode 100644 tests/spec/glsl-1.10/compiler/samplers/out.frag
 create mode 100644 tests/spec/glsl-1.10/compiler/samplers/return-struct.frag
 create mode 100644 tests/spec/glsl-1.10/compiler/samplers/return.frag
 create mode 100644 tests/spec/glsl-1.10/execution/samplers/in-parameter-struct.shader_test
 create mode 100644 tests/spec/glsl-1.10/execution/samplers/in-parameter.shader_test
 create mode 100644 tests/spec/glsl-1.10/execution/samplers/normal-parameter-struct.shader_test
 create mode 100644 tests/spec/glsl-1.10/execution/samplers/normal-parameter.shader_test

diff --git a/tests/all.tests b/tests/all.tests
index d72507e..6d837b8 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -713,6 +713,10 @@ 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)
+spec['glsl-1.10']['execution'] = Group()
+add_shader_test_dir(spec['glsl-1.10']['execution'],
+	            os.path.join(os.path.dirname(__file__), 'spec', 'glsl-1.10', 'execution'),
+		    recursive=True)
 
 # Group spec/glsl-1.20
 spec['glsl-1.20'] = Group()
diff --git a/tests/spec/glsl-1.10/compiler/samplers/inout-struct.frag b/tests/spec/glsl-1.10/compiler/samplers/inout-struct.frag
new file mode 100644
index 0000000..a7194a5
--- /dev/null
+++ b/tests/spec/glsl-1.10/compiler/samplers/inout-struct.frag
@@ -0,0 +1,26 @@
+/* [config]
+ * expect_result: fail
+ * glsl_version: 1.10
+ * [end config]
+ *
+ * From page 17 (page 23 of the PDF) of the GLSL 1.20 spec:
+ *
+ *     "Samplers cannot be treated as l-values; hence cannot be used
+ *     as out or inout function parameters..."
+ *
+ * The GLSL 1.10 spec does not state this rule specifically, but it is
+ * clear from context that it is intended.
+ */
+struct foo {
+	float x;
+	sampler2D tex;
+};
+
+void f(inout foo p)
+{
+}
+
+void main()
+{
+	gl_FragColor = vec4(1.0);
+}
diff --git a/tests/spec/glsl-1.10/compiler/samplers/inout.frag b/tests/spec/glsl-1.10/compiler/samplers/inout.frag
new file mode 100644
index 0000000..a3249d2
--- /dev/null
+++ b/tests/spec/glsl-1.10/compiler/samplers/inout.frag
@@ -0,0 +1,21 @@
+/* [config]
+ * expect_result: fail
+ * glsl_version: 1.10
+ * [end config]
+ *
+ * From page 17 (page 23 of the PDF) of the GLSL 1.20 spec:
+ *
+ *     "Samplers cannot be treated as l-values; hence cannot be used
+ *     as out or inout function parameters..."
+ *
+ * The GLSL 1.10 spec does not state this rule specifically, but it is
+ * clear from context that it is intended.
+ */
+void f(inout sampler2D p)
+{
+}
+
+void main()
+{
+	gl_FragColor = vec4(1.0);
+}
diff --git a/tests/spec/glsl-1.10/compiler/samplers/nonuniform-struct.frag b/tests/spec/glsl-1.10/compiler/samplers/nonuniform-struct.frag
new file mode 100644
index 0000000..009e8dc
--- /dev/null
+++ b/tests/spec/glsl-1.10/compiler/samplers/nonuniform-struct.frag
@@ -0,0 +1,19 @@
+/* [config]
+ * expect_result: fail
+ * glsl_version: 1.10
+ * [end config]
+ *
+ * From page 19 (page 25 of the PDF) of the GLSL 1.10 spec:
+ *
+ *     "[Samplers] can only be declared as function parameters or uniforms
+ *     (see Section 4.3.5 "Uniform")."
+ */
+struct foo {
+	float x;
+	sampler2D tex;
+} g;
+
+void main()
+{
+	gl_FragColor = vec4(1.0);
+}
diff --git a/tests/spec/glsl-1.10/compiler/samplers/nonuniform.frag b/tests/spec/glsl-1.10/compiler/samplers/nonuniform.frag
new file mode 100644
index 0000000..38bd7f9
--- /dev/null
+++ b/tests/spec/glsl-1.10/compiler/samplers/nonuniform.frag
@@ -0,0 +1,12 @@
+/* [config]
+ * expect_result: fail
+ * glsl_version: 1.10
+ * [end config]
+ *
+ * From page 19 (page 25 of the PDF) of the GLSL 1.10 spec:
+ *
+ *     "[Samplers] can only be declared as function parameters or uniforms
+ *     (see Section 4.3.5 "Uniform")."
+ */
+sampler2D tex;
+void main() { gl_FragColor = vec4(1.0); }
diff --git a/tests/spec/glsl-1.10/compiler/samplers/out-struct.frag b/tests/spec/glsl-1.10/compiler/samplers/out-struct.frag
new file mode 100644
index 0000000..c5338f7
--- /dev/null
+++ b/tests/spec/glsl-1.10/compiler/samplers/out-struct.frag
@@ -0,0 +1,26 @@
+/* [config]
+ * expect_result: fail
+ * glsl_version: 1.10
+ * [end config]
+ *
+ * From page 17 (page 23 of the PDF) of the GLSL 1.20 spec:
+ *
+ *     "Samplers cannot be treated as l-values; hence cannot be used
+ *     as out or inout function parameters..."
+ *
+ * The GLSL 1.10 spec does not state this rule specifically, but it is
+ * clear from context that it is intended.
+ */
+struct foo {
+	float x;
+	sampler2D tex;
+};
+
+void f(out foo p)
+{
+}
+
+void main()
+{
+	gl_FragColor = vec4(1.0);
+}
diff --git a/tests/spec/glsl-1.10/compiler/samplers/out.frag b/tests/spec/glsl-1.10/compiler/samplers/out.frag
new file mode 100644
index 0000000..d205665
--- /dev/null
+++ b/tests/spec/glsl-1.10/compiler/samplers/out.frag
@@ -0,0 +1,21 @@
+/* [config]
+ * expect_result: fail
+ * glsl_version: 1.10
+ * [end config]
+ *
+ * From page 17 (page 23 of the PDF) of the GLSL 1.20 spec:
+ *
+ *     "Samplers cannot be treated as l-values; hence cannot be used
+ *     as out or inout function parameters..."
+ *
+ * The GLSL 1.10 spec does not state this rule specifically, but it is
+ * clear from context that it is intended.
+ */
+void f(out sampler2D p)
+{
+}
+
+void main()
+{
+	gl_FragColor = vec4(1.0);
+}
diff --git a/tests/spec/glsl-1.10/compiler/samplers/return-struct.frag b/tests/spec/glsl-1.10/compiler/samplers/return-struct.frag
new file mode 100644
index 0000000..16d92aa
--- /dev/null
+++ b/tests/spec/glsl-1.10/compiler/samplers/return-struct.frag
@@ -0,0 +1,24 @@
+/* [config]
+ * expect_result: fail
+ * glsl_version: 1.10
+ * [end config]
+ *
+ * From page 19 (page 25 of the PDF) of the GLSL 1.10 spec:
+ *
+ *     "[Samplers] can only be declared as function parameters or uniforms
+ *     (see Section 4.3.5 "Uniform")."
+ */
+uniform struct foo {
+	float x;
+	sampler2D tex;
+} u;
+
+foo f()
+{
+	return u;
+}
+
+void main()
+{
+	gl_FragColor = vec4(1.0);
+}
diff --git a/tests/spec/glsl-1.10/compiler/samplers/return.frag b/tests/spec/glsl-1.10/compiler/samplers/return.frag
new file mode 100644
index 0000000..4c25fbc
--- /dev/null
+++ b/tests/spec/glsl-1.10/compiler/samplers/return.frag
@@ -0,0 +1,21 @@
+/* [config]
+ * expect_result: fail
+ * glsl_version: 1.10
+ * [end config]
+ *
+ * From page 19 (page 25 of the PDF) of the GLSL 1.10 spec:
+ *
+ *     "[Samplers] can only be declared as function parameters or uniforms
+ *     (see Section 4.3.5 "Uniform")."
+ */
+sampler2D u;
+
+sampler2D f()
+{
+	return u;
+}
+
+void main()
+{
+	gl_FragColor = vec4(1.0);
+}
diff --git a/tests/spec/glsl-1.10/execution/samplers/in-parameter-struct.shader_test b/tests/spec/glsl-1.10/execution/samplers/in-parameter-struct.shader_test
new file mode 100644
index 0000000..23b352c
--- /dev/null
+++ b/tests/spec/glsl-1.10/execution/samplers/in-parameter-struct.shader_test
@@ -0,0 +1,38 @@
+[require]
+GLSL >= 1.10
+
+[vertex shader]
+varying vec4 texcoords;
+
+void main()
+{
+	gl_Position = gl_Vertex;
+	texcoords = (gl_Vertex + 1.0) / 2.0;
+}
+
+[fragment shader]
+varying vec4 texcoords;
+uniform struct S {
+	float f;
+	sampler2D tex;
+} s;
+
+vec4 foo(in S foo_s, vec4 foo_texcoords)
+{
+	return texture2D(foo_s.tex, foo_texcoords.xy) * foo_s.f;
+}
+
+void main()
+{
+	gl_FragColor = foo(s, texcoords);
+}
+
+[test]
+uniform int s.tex 1
+uniform float s.f 1.0
+texture rgbw 1 (8, 8)
+draw rect -1 -1 2 2
+relative probe rgb (0.25, 0.25) (1.0, 0.0, 0.0)
+relative probe rgb (0.75, 0.25) (0.0, 1.0, 0.0)
+relative probe rgb (0.25, 0.75) (0.0, 0.0, 1.0)
+relative probe rgb (0.75, 0.75) (1.0, 1.0, 1.0)
diff --git a/tests/spec/glsl-1.10/execution/samplers/in-parameter.shader_test b/tests/spec/glsl-1.10/execution/samplers/in-parameter.shader_test
new file mode 100644
index 0000000..c8962ed
--- /dev/null
+++ b/tests/spec/glsl-1.10/execution/samplers/in-parameter.shader_test
@@ -0,0 +1,36 @@
+[require]
+GLSL >= 1.10
+
+[vertex shader]
+varying vec4 texcoords;
+
+void main()
+{
+	gl_Position = gl_Vertex;
+	texcoords = (gl_Vertex + 1.0) / 2.0;
+}
+
+[fragment shader]
+varying vec4 texcoords;
+uniform float f;
+uniform sampler2D tex;
+
+vec4 foo(float foo_f, in sampler2D foo_tex, vec4 foo_texcoords)
+{
+	return texture2D(foo_tex, foo_texcoords.xy) * foo_f;
+}
+
+void main()
+{
+	gl_FragColor = foo(f, tex, texcoords);
+}
+
+[test]
+uniform int tex 1
+uniform float f 1.0
+texture rgbw 1 (8, 8)
+draw rect -1 -1 2 2
+relative probe rgb (0.25, 0.25) (1.0, 0.0, 0.0)
+relative probe rgb (0.75, 0.25) (0.0, 1.0, 0.0)
+relative probe rgb (0.25, 0.75) (0.0, 0.0, 1.0)
+relative probe rgb (0.75, 0.75) (1.0, 1.0, 1.0)
diff --git a/tests/spec/glsl-1.10/execution/samplers/normal-parameter-struct.shader_test b/tests/spec/glsl-1.10/execution/samplers/normal-parameter-struct.shader_test
new file mode 100644
index 0000000..4d06aaa
--- /dev/null
+++ b/tests/spec/glsl-1.10/execution/samplers/normal-parameter-struct.shader_test
@@ -0,0 +1,38 @@
+[require]
+GLSL >= 1.10
+
+[vertex shader]
+varying vec4 texcoords;
+
+void main()
+{
+	gl_Position = gl_Vertex;
+	texcoords = (gl_Vertex + 1.0) / 2.0;
+}
+
+[fragment shader]
+varying vec4 texcoords;
+uniform struct S {
+	float f;
+	sampler2D tex;
+} s;
+
+vec4 foo(S foo_s, vec4 foo_texcoords)
+{
+	return texture2D(foo_s.tex, foo_texcoords.xy) * foo_s.f;
+}
+
+void main()
+{
+	gl_FragColor = foo(s, texcoords);
+}
+
+[test]
+uniform int s.tex 1
+uniform float s.f 1.0
+texture rgbw 1 (8, 8)
+draw rect -1 -1 2 2
+relative probe rgb (0.25, 0.25) (1.0, 0.0, 0.0)
+relative probe rgb (0.75, 0.25) (0.0, 1.0, 0.0)
+relative probe rgb (0.25, 0.75) (0.0, 0.0, 1.0)
+relative probe rgb (0.75, 0.75) (1.0, 1.0, 1.0)
diff --git a/tests/spec/glsl-1.10/execution/samplers/normal-parameter.shader_test b/tests/spec/glsl-1.10/execution/samplers/normal-parameter.shader_test
new file mode 100644
index 0000000..428fdc7
--- /dev/null
+++ b/tests/spec/glsl-1.10/execution/samplers/normal-parameter.shader_test
@@ -0,0 +1,36 @@
+[require]
+GLSL >= 1.10
+
+[vertex shader]
+varying vec4 texcoords;
+
+void main()
+{
+	gl_Position = gl_Vertex;
+	texcoords = (gl_Vertex + 1.0) / 2.0;
+}
+
+[fragment shader]
+varying vec4 texcoords;
+uniform float f;
+uniform sampler2D tex;
+
+vec4 foo(float foo_f, sampler2D foo_tex, vec4 foo_texcoords)
+{
+	return texture2D(foo_tex, foo_texcoords.xy) * foo_f;
+}
+
+void main()
+{
+	gl_FragColor = foo(f, tex, texcoords);
+}
+
+[test]
+uniform int tex 1
+uniform float f 1.0
+texture rgbw 1 (8, 8)
+draw rect -1 -1 2 2
+relative probe rgb (0.25, 0.25) (1.0, 0.0, 0.0)
+relative probe rgb (0.75, 0.25) (0.0, 1.0, 0.0)
+relative probe rgb (0.25, 0.75) (0.0, 0.0, 1.0)
+relative probe rgb (0.75, 0.75) (1.0, 1.0, 1.0)
-- 
1.7.6



More information about the Piglit mailing list