[Piglit] [PATCH 1/2] Geometry shaders: Test gl_ClipDistance input (GLSL 1.50)

Paul Berry stereotype441 at gmail.com
Tue Jun 11 16:50:43 PDT 2013


This patch adds piglit tests to ensure that gl_ClipDistance works
properly as a geometry shader input.
---
 .../clip-distance-in-explicit-access-2.geom        | 26 ++++++
 .../clip-distance-in-explicit-access-max.geom      | 26 ++++++
 ...distance-in-explicit-too-large-with-access.geom | 25 ++++++
 .../clip-distance-in-explicit-too-large.geom       | 24 ++++++
 .../clip-distance-in-implicit-access-max.geom      | 22 +++++
 .../geometry/clip-distance-in-implicit-length.geom | 21 +++++
 .../clip-distance-in-implicit-nonconst-access.geom | 22 +++++
 .../geometry/clip-distance-bulk-copy.shader_test   | 93 ++++++++++++++++++++++
 .../clip-distance-in-bulk-read.shader_test         | 83 +++++++++++++++++++
 .../clip-distance-in-explicitly-sized.shader_test  | 67 ++++++++++++++++
 .../geometry/clip-distance-in-param.shader_test    | 86 ++++++++++++++++++++
 .../geometry/clip-distance-in-values.shader_test   | 76 ++++++++++++++++++
 12 files changed, 571 insertions(+)
 create mode 100644 tests/spec/glsl-1.50/compiler/geometry/clip-distance-in-explicit-access-2.geom
 create mode 100644 tests/spec/glsl-1.50/compiler/geometry/clip-distance-in-explicit-access-max.geom
 create mode 100644 tests/spec/glsl-1.50/compiler/geometry/clip-distance-in-explicit-too-large-with-access.geom
 create mode 100644 tests/spec/glsl-1.50/compiler/geometry/clip-distance-in-explicit-too-large.geom
 create mode 100644 tests/spec/glsl-1.50/compiler/geometry/clip-distance-in-implicit-access-max.geom
 create mode 100644 tests/spec/glsl-1.50/compiler/geometry/clip-distance-in-implicit-length.geom
 create mode 100644 tests/spec/glsl-1.50/compiler/geometry/clip-distance-in-implicit-nonconst-access.geom
 create mode 100644 tests/spec/glsl-1.50/execution/geometry/clip-distance-bulk-copy.shader_test
 create mode 100644 tests/spec/glsl-1.50/execution/geometry/clip-distance-in-bulk-read.shader_test
 create mode 100644 tests/spec/glsl-1.50/execution/geometry/clip-distance-in-explicitly-sized.shader_test
 create mode 100644 tests/spec/glsl-1.50/execution/geometry/clip-distance-in-param.shader_test
 create mode 100644 tests/spec/glsl-1.50/execution/geometry/clip-distance-in-values.shader_test

diff --git a/tests/spec/glsl-1.50/compiler/geometry/clip-distance-in-explicit-access-2.geom b/tests/spec/glsl-1.50/compiler/geometry/clip-distance-in-explicit-access-2.geom
new file mode 100644
index 0000000..4d615d4
--- /dev/null
+++ b/tests/spec/glsl-1.50/compiler/geometry/clip-distance-in-explicit-access-2.geom
@@ -0,0 +1,26 @@
+/* [config]
+ * expect_result: fail
+ * glsl_version: 1.50
+ * check_link: true
+ * [end config]
+ *
+ * This test checks that an error occurs when explicitly setting the
+ * size of the gl_ClipDistance input to 2 (which should be ok) and
+ * trying to access a non-existent element
+ * (gl_in[0].gl_ClipDistance[2]) using an integral constant
+ * expression, which should generate an error.
+ */
+#version 150
+
+layout(triangles) in;
+layout(triangle_strip, max_vertices = 3) out;
+
+in gl_PerVertex {
+  float gl_ClipDistance[2];
+} gl_in[];
+
+void main()
+{
+  gl_Position = vec4(gl_in[0].gl_ClipDistance[2]);
+  EmitVertex();
+}
diff --git a/tests/spec/glsl-1.50/compiler/geometry/clip-distance-in-explicit-access-max.geom b/tests/spec/glsl-1.50/compiler/geometry/clip-distance-in-explicit-access-max.geom
new file mode 100644
index 0000000..c418ece
--- /dev/null
+++ b/tests/spec/glsl-1.50/compiler/geometry/clip-distance-in-explicit-access-max.geom
@@ -0,0 +1,26 @@
+/* [config]
+ * expect_result: fail
+ * glsl_version: 1.50
+ * check_link: true
+ * [end config]
+ *
+ * This test checks that an error occurs when explicitly setting the
+ * size of the gl_ClipDistance input to gl_MaxClipDistances (which
+ * should be ok) and trying to access a non-existent element
+ * (gl_in[0].gl_ClipDistance[gl_MaxClipDistances]) using an integral
+ * constant expression, which should generate an error.
+ */
+#version 150
+
+layout(triangles) in;
+layout(triangle_strip, max_vertices = 3) out;
+
+in gl_PerVertex {
+  float gl_ClipDistance[gl_MaxClipDistances];
+} gl_in[];
+
+void main()
+{
+  gl_Position = vec4(gl_in[0].gl_ClipDistance[gl_MaxClipDistances]);
+  EmitVertex();
+}
diff --git a/tests/spec/glsl-1.50/compiler/geometry/clip-distance-in-explicit-too-large-with-access.geom b/tests/spec/glsl-1.50/compiler/geometry/clip-distance-in-explicit-too-large-with-access.geom
new file mode 100644
index 0000000..54f29be
--- /dev/null
+++ b/tests/spec/glsl-1.50/compiler/geometry/clip-distance-in-explicit-too-large-with-access.geom
@@ -0,0 +1,25 @@
+/* [config]
+ * expect_result: fail
+ * glsl_version: 1.50
+ * check_link: true
+ * [end config]
+ *
+ * This test checks that an error occurs when explicitly setting the
+ * size of the gl_ClipDistance input to gl_MaxClipDistances+1 (which
+ * should generate an error) and accessing gl_in[0].gl_ClipDistance[0]
+ * (which would otherwise be ok).
+ */
+#version 150
+
+layout(triangles) in;
+layout(triangle_strip, max_vertices = 3) out;
+
+in gl_PerVertex {
+  float gl_ClipDistance[gl_MaxClipDistances+1];
+} gl_in[];
+
+void main()
+{
+  gl_Position = vec4(gl_in[0].gl_ClipDistance[0]);
+  EmitVertex();
+}
diff --git a/tests/spec/glsl-1.50/compiler/geometry/clip-distance-in-explicit-too-large.geom b/tests/spec/glsl-1.50/compiler/geometry/clip-distance-in-explicit-too-large.geom
new file mode 100644
index 0000000..c69b60a
--- /dev/null
+++ b/tests/spec/glsl-1.50/compiler/geometry/clip-distance-in-explicit-too-large.geom
@@ -0,0 +1,24 @@
+/* [config]
+ * expect_result: fail
+ * glsl_version: 1.50
+ * check_link: true
+ * [end config]
+ *
+ * This test checks that an error occurs when explicitly setting the
+ * size of the gl_ClipDistance input to gl_MaxClipDistances+1, which
+ * should generate an error.
+ */
+#version 150
+
+layout(triangles) in;
+layout(triangle_strip, max_vertices = 3) out;
+
+in gl_PerVertex {
+  float gl_ClipDistance[gl_MaxClipDistances+1];
+} gl_in[];
+
+void main()
+{
+  gl_Position = vec4(0.0);
+  EmitVertex();
+}
diff --git a/tests/spec/glsl-1.50/compiler/geometry/clip-distance-in-implicit-access-max.geom b/tests/spec/glsl-1.50/compiler/geometry/clip-distance-in-implicit-access-max.geom
new file mode 100644
index 0000000..a0d7652
--- /dev/null
+++ b/tests/spec/glsl-1.50/compiler/geometry/clip-distance-in-implicit-access-max.geom
@@ -0,0 +1,22 @@
+/* [config]
+ * expect_result: fail
+ * glsl_version: 1.50
+ * check_link: true
+ * [end config]
+ *
+ * This test checks that an error occurs when the size of the
+ * gl_ClipDistance input is implicit, and we try to access a
+ * non-existent element
+ * (gl_in[0].gl_ClipDistance[gl_MaxClipDistances]) using an integral
+ * constant expression.
+ */
+#version 150
+
+layout(triangles) in;
+layout(triangle_strip, max_vertices = 3) out;
+
+void main()
+{
+  gl_Position = vec4(gl_in[0].gl_ClipDistance[gl_MaxClipDistances]);
+  EmitVertex();
+}
diff --git a/tests/spec/glsl-1.50/compiler/geometry/clip-distance-in-implicit-length.geom b/tests/spec/glsl-1.50/compiler/geometry/clip-distance-in-implicit-length.geom
new file mode 100644
index 0000000..b942b6b
--- /dev/null
+++ b/tests/spec/glsl-1.50/compiler/geometry/clip-distance-in-implicit-length.geom
@@ -0,0 +1,21 @@
+/* [config]
+ * expect_result: fail
+ * glsl_version: 1.50
+ * check_link: true
+ * [end config]
+ *
+ * This test verifies that the gl_ClipDistance input is predeclared as
+ * unsized by attempting to take the length of
+ * gl_in[0].gl_ClipDistanceIn, an operation that is not allowed on
+ * unsized arrays.
+ */
+#version 150
+
+layout(triangles) in;
+layout(triangle_strip, max_vertices = 3) out;
+
+void main()
+{
+  gl_Position = vec4(gl_in[0].gl_ClipDistance.length());
+  EmitVertex();
+}
diff --git a/tests/spec/glsl-1.50/compiler/geometry/clip-distance-in-implicit-nonconst-access.geom b/tests/spec/glsl-1.50/compiler/geometry/clip-distance-in-implicit-nonconst-access.geom
new file mode 100644
index 0000000..451e11d
--- /dev/null
+++ b/tests/spec/glsl-1.50/compiler/geometry/clip-distance-in-implicit-nonconst-access.geom
@@ -0,0 +1,22 @@
+/* [config]
+ * expect_result: fail
+ * glsl_version: 1.50
+ * check_link: true
+ * [end config]
+ *
+ * This test verifies that the gl_ClipDistance input is predeclared as
+ * unsized by attempting to access it using a non-constant index, an
+ * operation that is not allowed on unsized arrays.
+ */
+#version 150
+
+layout(triangles) in;
+layout(triangle_strip, max_vertices = 3) out;
+
+uniform int index;
+
+void main()
+{
+  gl_Position = vec4(gl_in[0].gl_ClipDistance[index]);
+  EmitVertex();
+}
diff --git a/tests/spec/glsl-1.50/execution/geometry/clip-distance-bulk-copy.shader_test b/tests/spec/glsl-1.50/execution/geometry/clip-distance-bulk-copy.shader_test
new file mode 100644
index 0000000..fbdee46
--- /dev/null
+++ b/tests/spec/glsl-1.50/execution/geometry/clip-distance-bulk-copy.shader_test
@@ -0,0 +1,93 @@
+# This test checks that the geometry shader can perform a bulk copy of
+# the entire gl_ClipDistance array from input to output.
+
+[require]
+GL >= 2.0
+GLSL >= 1.50
+
+[vertex shader]
+#version 150
+
+in vec4 vertex;
+in float offset;
+out float offset_to_gs;
+out float gl_ClipDistance[8];
+
+void main()
+{
+  gl_Position = vertex;
+  offset_to_gs = offset;
+  for (int i = 0; i < 8; i++) {
+    gl_ClipDistance[i] = offset + float(i);
+  }
+}
+
+[geometry shader]
+#version 150
+
+layout(triangles) in;
+layout(triangle_strip, max_vertices = 3) out;
+
+in float offset_to_gs[3];
+in gl_PerVertex {
+  vec4 gl_Position;
+  float gl_ClipDistance[8];
+} gl_in[];
+out float offset_to_fs;
+out gl_PerVertex {
+  vec4 gl_Position;
+  float gl_ClipDistance[8];
+};
+
+void main()
+{
+  bool ok = true;
+  for (int i = 0; i < 3; i++) {
+    gl_Position = gl_in[i].gl_Position;
+    gl_ClipDistance = gl_in[i].gl_ClipDistance;
+    offset_to_fs = offset_to_gs[i];
+    EmitVertex();
+  }
+}
+
+[fragment shader]
+#version 150
+
+in float gl_ClipDistance[8];
+in float offset_to_fs;
+
+void main()
+{
+  bool ok = true;
+  for (int i = 0; i < 8; i++) {
+    if (distance(gl_ClipDistance[i], offset_to_fs + float(i)) > 1e-6)
+      ok = false;
+  }
+  if (ok)
+    gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);
+  else
+    gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
+}
+
+[vertex data]
+vertex/float/2  offset/float/1
+-1.0 -1.0       1.0
+ 1.0 -1.0       2.0
+ 1.0  1.0       3.0
+-1.0  1.0       4.0
+
+[test]
+# Since the fragment shader's gl_ClipDistance array is only defined
+# for elements that have clipping enabled, we need to enable all 8
+# clip planes.  Fortunately the values we use for gl_ClipDistance are
+# always positive, so no pixels are actually clipped.
+enable GL_CLIP_PLANE0
+enable GL_CLIP_PLANE1
+enable GL_CLIP_PLANE2
+enable GL_CLIP_PLANE3
+enable GL_CLIP_PLANE4
+enable GL_CLIP_PLANE5
+enable GL_CLIP_PLANE6
+enable GL_CLIP_PLANE7
+draw arrays GL_TRIANGLE_FAN 0 4
+probe all rgba 0.0 1.0 0.0 1.0
diff --git a/tests/spec/glsl-1.50/execution/geometry/clip-distance-in-bulk-read.shader_test b/tests/spec/glsl-1.50/execution/geometry/clip-distance-in-bulk-read.shader_test
new file mode 100644
index 0000000..8124e59
--- /dev/null
+++ b/tests/spec/glsl-1.50/execution/geometry/clip-distance-in-bulk-read.shader_test
@@ -0,0 +1,83 @@
+# This test checks that the geometry shader can read one vertex's
+# worth the gl_ClipDistance input array using a single bulk assignment.
+
+[require]
+GL >= 2.0
+GLSL >= 1.50
+
+[vertex shader]
+#version 150
+
+in vec4 vertex;
+in float offset;
+out float offset_to_gs;
+out float gl_ClipDistance[gl_MaxClipDistances];
+
+void main()
+{
+  gl_Position = vertex;
+  offset_to_gs = offset;
+  for (int i = 0; i < gl_MaxClipDistances; i++) {
+    gl_ClipDistance[i] = offset + float(i);
+  }
+}
+
+[geometry shader]
+#version 150
+
+layout(triangles) in;
+layout(triangle_strip, max_vertices = 3) out;
+
+in float offset_to_gs[3];
+in gl_PerVertex {
+  vec4 gl_Position;
+  float gl_ClipDistance[gl_MaxClipDistances];
+} gl_in[];
+flat out int ok_to_fs;
+uniform float foo;
+
+void main()
+{
+  bool ok = true;
+  for (int i = 0; i < 3; i++) {
+    float clip_distance_copy[gl_MaxClipDistances] = gl_in[i].gl_ClipDistance;
+
+    /* Make sure the copy doesn't get optimized out */
+    clip_distance_copy[0] += foo;
+
+    for (int j = 0; j < gl_MaxClipDistances; j++) {
+      if (clip_distance_copy[j] != offset_to_gs[i] + float(j))
+        ok = false;
+    }
+  }
+  for (int i = 0; i < 3; i++) {
+    gl_Position = gl_in[i].gl_Position;
+    ok_to_fs = int(ok);
+    EmitVertex();
+  }
+}
+
+[fragment shader]
+#version 150
+
+flat in int ok_to_fs;
+
+void main()
+{
+  if (ok_to_fs != 0)
+    gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);
+  else
+    gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
+}
+
+[vertex data]
+vertex/float/2  offset/float/1
+-1.0 -1.0       1.0
+ 1.0 -1.0       2.0
+ 1.0  1.0       3.0
+-1.0  1.0       4.0
+
+[test]
+uniform float foo 0.0
+draw arrays GL_TRIANGLE_FAN 0 4
+probe all rgba 0.0 1.0 0.0 1.0
diff --git a/tests/spec/glsl-1.50/execution/geometry/clip-distance-in-explicitly-sized.shader_test b/tests/spec/glsl-1.50/execution/geometry/clip-distance-in-explicitly-sized.shader_test
new file mode 100644
index 0000000..ecd8e74
--- /dev/null
+++ b/tests/spec/glsl-1.50/execution/geometry/clip-distance-in-explicitly-sized.shader_test
@@ -0,0 +1,67 @@
+# This test checks that the GLSL compiler respects the size of the
+# gl_ClipDistance input when it is explicitly declared in the geometry
+# shader.
+
+[require]
+GL >= 2.0
+GLSL >= 1.50
+
+[vertex shader]
+#version 150
+out float gl_ClipDistance[2];
+in vec4 vertex;
+
+void main()
+{
+  gl_Position = vertex;
+}
+
+[geometry shader]
+#version 150
+
+layout(triangles) in;
+layout(triangle_strip, max_vertices = 3) out;
+
+in gl_PerVertex {
+  vec4 gl_Position;
+  float gl_ClipDistance[2];
+} gl_in[];
+flat out int outer_size;
+flat out int inner_size;
+
+void main()
+{
+  for (int i = 0; i < 3; i++) {
+    gl_Position = gl_in[i].gl_Position;
+    outer_size = gl_in.length();
+    inner_size = gl_in[0].gl_ClipDistance.length();
+    EmitVertex();
+  }
+}
+
+[fragment shader]
+#version 150
+
+flat in int outer_size;
+flat in int inner_size;
+
+void main()
+{
+  if (outer_size != 3)
+    gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
+  else if (inner_size != 2)
+    gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
+  else
+    gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);
+}
+
+[vertex data]
+vertex/float/2
+-1.0 -1.0
+ 1.0 -1.0
+ 1.0  1.0
+-1.0  1.0
+
+[test]
+draw arrays GL_TRIANGLE_FAN 0 4
+probe all rgba 0.0 1.0 0.0 1.0
diff --git a/tests/spec/glsl-1.50/execution/geometry/clip-distance-in-param.shader_test b/tests/spec/glsl-1.50/execution/geometry/clip-distance-in-param.shader_test
new file mode 100644
index 0000000..ad8b3f0
--- /dev/null
+++ b/tests/spec/glsl-1.50/execution/geometry/clip-distance-in-param.shader_test
@@ -0,0 +1,86 @@
+# This test checks that the geometry shader can pass one vertex's
+# worth of the gl_ClipDistance input array to a function.
+
+[require]
+GL >= 2.0
+GLSL >= 1.50
+
+[vertex shader]
+#version 150
+
+in vec4 vertex;
+in float offset;
+out float offset_to_gs;
+out float gl_ClipDistance[gl_MaxClipDistances];
+
+void main()
+{
+  gl_Position = vertex;
+  offset_to_gs = offset;
+  for (int i = 0; i < gl_MaxClipDistances; i++) {
+    gl_ClipDistance[i] = offset + float(i);
+  }
+}
+
+[geometry shader]
+#version 150
+
+layout(triangles) in;
+layout(triangle_strip, max_vertices = 3) out;
+
+in float offset_to_gs[3];
+in gl_PerVertex {
+  vec4 gl_Position;
+  float gl_ClipDistance[gl_MaxClipDistances];
+} gl_in[];
+flat out int ok_to_fs;
+
+bool test(float clip_distance_copy[gl_MaxClipDistances], float offset)
+{
+  bool ok = true;
+
+  for (int j = 0; j < gl_MaxClipDistances; j++) {
+    if (clip_distance_copy[j] != offset + float(j))
+      ok = false;
+  }
+
+  return ok;
+}
+
+void main()
+{
+  bool ok = true;
+  for (int i = 0; i < 3; i++) {
+    if (!test(gl_in[i].gl_ClipDistance, offset_to_gs[i]))
+      ok = false;
+  }
+  for (int i = 0; i < 3; i++) {
+    gl_Position = gl_in[i].gl_Position;
+    ok_to_fs = int(ok);
+    EmitVertex();
+  }
+}
+
+[fragment shader]
+#version 150
+
+flat in int ok_to_fs;
+
+void main()
+{
+  if (ok_to_fs != 0)
+    gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);
+  else
+    gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
+}
+
+[vertex data]
+vertex/float/2  offset/float/1
+-1.0 -1.0       1.0
+ 1.0 -1.0       2.0
+ 1.0  1.0       3.0
+-1.0  1.0       4.0
+
+[test]
+draw arrays GL_TRIANGLE_FAN 0 4
+probe all rgba 0.0 1.0 0.0 1.0
diff --git a/tests/spec/glsl-1.50/execution/geometry/clip-distance-in-values.shader_test b/tests/spec/glsl-1.50/execution/geometry/clip-distance-in-values.shader_test
new file mode 100644
index 0000000..8f7615c
--- /dev/null
+++ b/tests/spec/glsl-1.50/execution/geometry/clip-distance-in-values.shader_test
@@ -0,0 +1,76 @@
+# This test checks that values sent to gl_ClipDistance by the vertex
+# shader are correctly received by the geometry shader.
+
+[require]
+GL >= 2.0
+GLSL >= 1.50
+
+[vertex shader]
+#version 150
+
+in vec4 vertex;
+in float offset;
+out float offset_to_gs;
+out float gl_ClipDistance[gl_MaxClipDistances];
+
+void main()
+{
+  gl_Position = vertex;
+  offset_to_gs = offset;
+  for (int i = 0; i < gl_MaxClipDistances; i++) {
+    gl_ClipDistance[i] = offset + float(i);
+  }
+}
+
+[geometry shader]
+#version 150
+
+layout(triangles) in;
+layout(triangle_strip, max_vertices = 3) out;
+
+in float offset_to_gs[3];
+in gl_PerVertex {
+  vec4 gl_Position;
+  float gl_ClipDistance[gl_MaxClipDistances];
+} gl_in[];
+flat out int ok_to_fs;
+
+void main()
+{
+  bool ok = true;
+  for (int i = 0; i < 3; i++) {
+    for (int j = 0; j < gl_MaxClipDistances; j++) {
+      if (gl_in[i].gl_ClipDistance[j] != offset_to_gs[i] + float(j))
+        ok = false;
+    }
+  }
+  for (int i = 0; i < 3; i++) {
+    gl_Position = gl_in[i].gl_Position;
+    ok_to_fs = int(ok);
+    EmitVertex();
+  }
+}
+
+[fragment shader]
+#version 150
+
+flat in int ok_to_fs;
+
+void main()
+{
+  if (ok_to_fs != 0)
+    gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);
+  else
+    gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
+}
+
+[vertex data]
+vertex/float/2  offset/float/1
+-1.0 -1.0       1.0
+ 1.0 -1.0       2.0
+ 1.0  1.0       3.0
+-1.0  1.0       4.0
+
+[test]
+draw arrays GL_TRIANGLE_FAN 0 4
+probe all rgba 0.0 1.0 0.0 1.0
-- 
1.8.3.1



More information about the Piglit mailing list