[Piglit] [PATCH] Test that there are 8 clip planes/distances in GLSL 1.30.

Paul Berry stereotype441 at gmail.com
Tue Sep 13 14:54:09 PDT 2011


The clipping tests previously in Piglit only tested the first 6
clipping planes, since prior to GLSL 1.30, a conforming implementation
was allowed to only support 6 clipping planes.  However, in GLSL 1.30,
the minimum value of gl_MaxClipDistances and gl_MaxClipPlanes was
increased to 8.

This patch adds tests to verify that if the implementation reports a
GLSL version of at least 1.30, gl_MaxClipDistances and
gl_MaxClipPlanes are both at least 8.  It also modifies
vs-clip-distance-all-planes-enabled.shader_test to exercise all 8
clipping planes.

The previous implementation of
vs-clip-distance-all-planes-enabled.shader_test used to also verify,
as a side effect, that gl_ClipDistance could be implicitly sized.  The
new version does not (it requires gl_ClipDistance to be explicitly
sized, since it indexes into it using a loop variable).  So I've added
a new test, vs-clip-distance-implicitly-sized.shader_test, to verify
this.

Tested using the nVidia proprietary Linux driver.
---
 tests/shaders/shader_runner.c                      |    2 +
 .../clipping/max-clip-distances.shader_test        |   54 ++++++++++++++
 .../execution/clipping/max-clip-planes.shader_test |   54 ++++++++++++++
 ...vs-clip-distance-all-planes-enabled.shader_test |   76 ++++++++++----------
 .../vs-clip-distance-implicitly-sized.shader_test  |   67 +++++++++++++++++
 tests/util/glew.h                                  |    2 +
 6 files changed, 218 insertions(+), 37 deletions(-)
 create mode 100644 tests/spec/glsl-1.30/execution/clipping/max-clip-distances.shader_test
 create mode 100644 tests/spec/glsl-1.30/execution/clipping/max-clip-planes.shader_test
 create mode 100644 tests/spec/glsl-1.30/execution/clipping/vs-clip-distance-implicitly-sized.shader_test

diff --git a/tests/shaders/shader_runner.c b/tests/shaders/shader_runner.c
index cde5ae3..a46ea4d 100644
--- a/tests/shaders/shader_runner.c
+++ b/tests/shaders/shader_runner.c
@@ -819,6 +819,8 @@ struct enable_table {
 	{ "GL_CLIP_PLANE3", GL_CLIP_PLANE3 },
 	{ "GL_CLIP_PLANE4", GL_CLIP_PLANE4 },
 	{ "GL_CLIP_PLANE5", GL_CLIP_PLANE5 },
+	{ "GL_CLIP_PLANE6", GL_CLIP_PLANE6 },
+	{ "GL_CLIP_PLANE7", GL_CLIP_PLANE7 },
 	{ NULL, 0 }
 };
 
diff --git a/tests/spec/glsl-1.30/execution/clipping/max-clip-distances.shader_test b/tests/spec/glsl-1.30/execution/clipping/max-clip-distances.shader_test
new file mode 100644
index 0000000..d593fbf
--- /dev/null
+++ b/tests/spec/glsl-1.30/execution/clipping/max-clip-distances.shader_test
@@ -0,0 +1,54 @@
+# [description]
+# Verify correct behavior of gl_MaxClipDistances.
+#
+# From section the GLSL 1.30 spec, section 7.4 (Built-In Constants):
+#
+#   "The following built-in constants are provided to vertex and
+#   fragment shaders. The actual values used are implementation
+#   dependent, but must be at least the value shown.
+#
+#   ...
+#
+#   const int gl_MaxClipDistances = 8;"
+#
+# This test verifies that gl_MaxClipDistances has the same value in
+# both the vertex and fragment shader, and that this value is at least
+# 8.
+
+[require]
+GLSL >= 1.30
+
+[vertex shader]
+#version 130
+
+out float maxClipDistances;
+
+void main()
+{
+	gl_Position = gl_Vertex;
+
+	maxClipDistances = gl_MaxClipDistances;
+}
+
+[fragment shader]
+#version 130
+
+in float maxClipDistances;
+
+void main()
+{
+	if (maxClipDistances != gl_MaxClipDistances) {
+		// Red: gl_MaxClipDistances values don't match
+		gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
+	} else if (gl_MaxClipDistances < 8) {
+		// Yellow: gl_MaxClipDistances is too small
+		gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0);
+	} else {
+		// Green: ok
+		gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);
+	}
+}
+
+[test]
+draw rect -1 -1 2 2
+probe all rgba 0.0 1.0 0.0 1.0
diff --git a/tests/spec/glsl-1.30/execution/clipping/max-clip-planes.shader_test b/tests/spec/glsl-1.30/execution/clipping/max-clip-planes.shader_test
new file mode 100644
index 0000000..2d7c987
--- /dev/null
+++ b/tests/spec/glsl-1.30/execution/clipping/max-clip-planes.shader_test
@@ -0,0 +1,54 @@
+# [description]
+# Verify correct behavior of gl_MaxClipPlanes.
+#
+# From section the GLSL 1.30 spec, section 7.4 (Built-In Constants):
+#
+#   "The following built-in constants are provided to vertex and
+#   fragment shaders. The actual values used are implementation
+#   dependent, but must be at least the value shown.
+#
+#   ...
+#
+#   const int gl_MaxClipPlanes = 8; // deprecated"
+#
+# This test verifies that gl_MaxClipPlanes has the same value in
+# both the vertex and fragment shader, and that this value is at least
+# 8.
+
+[require]
+GLSL >= 1.30
+
+[vertex shader]
+#version 130
+
+out float maxClipPlanes;
+
+void main()
+{
+	gl_Position = gl_Vertex;
+
+	maxClipPlanes = gl_MaxClipPlanes;
+}
+
+[fragment shader]
+#version 130
+
+in float maxClipPlanes;
+
+void main()
+{
+	if (maxClipPlanes != gl_MaxClipPlanes) {
+		// Red: gl_MaxClipPlanes values don't match
+		gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
+	} else if (gl_MaxClipPlanes < 8) {
+		// Yellow: gl_MaxClipPlanes is too small
+		gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0);
+	} else {
+		// Green: ok
+		gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);
+	}
+}
+
+[test]
+draw rect -1 -1 2 2
+probe all rgba 0.0 1.0 0.0 1.0
diff --git a/tests/spec/glsl-1.30/execution/clipping/vs-clip-distance-all-planes-enabled.shader_test b/tests/spec/glsl-1.30/execution/clipping/vs-clip-distance-all-planes-enabled.shader_test
index db294d5..88f37ec 100644
--- a/tests/spec/glsl-1.30/execution/clipping/vs-clip-distance-all-planes-enabled.shader_test
+++ b/tests/spec/glsl-1.30/execution/clipping/vs-clip-distance-all-planes-enabled.shader_test
@@ -1,39 +1,35 @@
 # [description]
-# Use all 6 gl_ClipDistance values to clip a rectangle to a hexagon shape.
+# Use all 8 gl_ClipDistance values to clip a rectangle to an octagon shape.
 #
-# This also serves as a test that gl_ClipDistance may be implicitly
-# sized, as specified in section 7.1 (Vertex Shader Special Variables)
-# of the GLSL 1.30 spec:
-#
-#   The gl_ClipDistance array is predeclared as unsized and must be
-#   sized by the shader either redeclaring it with a size or indexing
-#   it only with integral constant expressions. This needs to size the
-#   array to include all the clip planes that are enabled via the
-#   OpenGL API; if the size does not include all enabled planes,
-#   results are undefined. The size can be at most
-#   gl_MaxClipDistances. The number of varying components (see
-#   gl_MaxVaryingComponents) consumed by gl_ClipDistance will match
-#   the size of the array, no matter how many planes are enabled. The
-#   shader must also set all values in gl_ClipDistance that have been
-#   enabled via the OpenGL API, or results are undefined. Values
-#   written into gl_ClipDistance for planes that are not enabled have
-#   no effect.
+# The octagon is centered at (0.5, 0.5), and has a small radius
+# (distance from center to perpendicular edge) of 0.4.
 
 [require]
 GLSL >= 1.30
 
 [vertex shader]
 #version 130
+
+out float gl_ClipDistance[8];
+
 void main(void)
 {
 	gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
 
-	gl_ClipDistance[0] = gl_Vertex.y - 0.25;
-	gl_ClipDistance[1] = gl_Vertex.y - gl_Vertex.x + 0.4;
-	gl_ClipDistance[2] = 1.4 - gl_Vertex.x - gl_Vertex.y;
-	gl_ClipDistance[3] = 0.75 - gl_Vertex.y;
-	gl_ClipDistance[4] = gl_Vertex.x - gl_Vertex.y + 0.4;
-	gl_ClipDistance[5] = gl_Vertex.x + gl_Vertex.y - 0.6;
+	// Compute 2D cordinates relative to a center point of (0.5,
+	// 0.5).
+	vec2 coord = gl_Vertex.xy - vec2(0.5, 0.5);
+
+	for (int i = 0; i < 8; ++i) {
+		// Compute a unit vector in the direction i*45deg from
+		// the x axis.
+		float angle = i*(3.141592653589793/4);
+		vec2 u = vec2(cos(angle), sin(angle));
+
+		// Reject points whose 2D coordinate, projected onto
+		// that unit vector, is greater than 0.4.
+		gl_ClipDistance[i] = 0.4 - dot(u, coord);
+	}
 }
 
 [fragment shader]
@@ -51,20 +47,26 @@ enable GL_CLIP_PLANE2
 enable GL_CLIP_PLANE3
 enable GL_CLIP_PLANE4
 enable GL_CLIP_PLANE5
-draw rect 0.1 0.1 0.8 0.8
+enable GL_CLIP_PLANE6
+enable GL_CLIP_PLANE7
+draw rect 0.0 0.0 1.0 1.0
 
 # Test points inside each hexagon edge
-relative probe rgba (0.3, 0.4) (1.0, 1.0, 1.0, 1.0)
-relative probe rgba (0.5, 0.3) (1.0, 1.0, 1.0, 1.0)
-relative probe rgba (0.7, 0.4) (1.0, 1.0, 1.0, 1.0)
-relative probe rgba (0.7, 0.6) (1.0, 1.0, 1.0, 1.0)
-relative probe rgba (0.5, 0.7) (1.0, 1.0, 1.0, 1.0)
-relative probe rgba (0.3, 0.6) (1.0, 1.0, 1.0, 1.0)
+relative probe rgba (0.850, 0.500) (1.0, 1.0, 1.0, 1.0)
+relative probe rgba (0.747, 0.747) (1.0, 1.0, 1.0, 1.0)
+relative probe rgba (0.500, 0.850) (1.0, 1.0, 1.0, 1.0)
+relative probe rgba (0.253, 0.747) (1.0, 1.0, 1.0, 1.0)
+relative probe rgba (0.150, 0.500) (1.0, 1.0, 1.0, 1.0)
+relative probe rgba (0.253, 0.253) (1.0, 1.0, 1.0, 1.0)
+relative probe rgba (0.500, 0.150) (1.0, 1.0, 1.0, 1.0)
+relative probe rgba (0.747, 0.253) (1.0, 1.0, 1.0, 1.0)
 
 # Test points outside each hexagon edge
-relative probe rgba (0.2, 0.3) (0.0, 0.0, 0.0, 0.0)
-relative probe rgba (0.5, 0.2) (0.0, 0.0, 0.0, 0.0)
-relative probe rgba (0.8, 0.3) (0.0, 0.0, 0.0, 0.0)
-relative probe rgba (0.8, 0.7) (0.0, 0.0, 0.0, 0.0)
-relative probe rgba (0.5, 0.8) (0.0, 0.0, 0.0, 0.0)
-relative probe rgba (0.2, 0.7) (0.0, 0.0, 0.0, 0.0)
+relative probe rgba (0.950, 0.500) (0.0, 0.0, 0.0, 0.0)
+relative probe rgba (0.818, 0.818) (0.0, 0.0, 0.0, 0.0)
+relative probe rgba (0.500, 0.950) (0.0, 0.0, 0.0, 0.0)
+relative probe rgba (0.182, 0.818) (0.0, 0.0, 0.0, 0.0)
+relative probe rgba (0.050, 0.500) (0.0, 0.0, 0.0, 0.0)
+relative probe rgba (0.182, 0.182) (0.0, 0.0, 0.0, 0.0)
+relative probe rgba (0.500, 0.050) (0.0, 0.0, 0.0, 0.0)
+relative probe rgba (0.818, 0.182) (0.0, 0.0, 0.0, 0.0)
diff --git a/tests/spec/glsl-1.30/execution/clipping/vs-clip-distance-implicitly-sized.shader_test b/tests/spec/glsl-1.30/execution/clipping/vs-clip-distance-implicitly-sized.shader_test
new file mode 100644
index 0000000..5eee867
--- /dev/null
+++ b/tests/spec/glsl-1.30/execution/clipping/vs-clip-distance-implicitly-sized.shader_test
@@ -0,0 +1,67 @@
+# [description]
+# This test verifies that gl_ClipDistance may be implicitly
+# sized, as specified in section 7.1 (Vertex Shader Special Variables)
+# of the GLSL 1.30 spec:
+#
+#   The gl_ClipDistance array is predeclared as unsized and must be
+#   sized by the shader either redeclaring it with a size or indexing
+#   it only with integral constant expressions. This needs to size the
+#   array to include all the clip planes that are enabled via the
+#   OpenGL API; if the size does not include all enabled planes,
+#   results are undefined. The size can be at most
+#   gl_MaxClipDistances. The number of varying components (see
+#   gl_MaxVaryingComponents) consumed by gl_ClipDistance will match
+#   the size of the array, no matter how many planes are enabled. The
+#   shader must also set all values in gl_ClipDistance that have been
+#   enabled via the OpenGL API, or results are undefined. Values
+#   written into gl_ClipDistance for planes that are not enabled have
+#   no effect.
+#
+# It does so by using 8 clip distances to progressively reject points
+# with x coordinate less than 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, and
+# 0.8.  (The end result of this should be to clip all values with x
+# coordinate less than 0.8).  It then verifies proper clipping
+# behavior by probing points with x coordinates 0.75 and 0.85.
+
+[require]
+GLSL >= 1.30
+
+[vertex shader]
+#version 130
+
+void main()
+{
+	gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
+
+	gl_ClipDistance[0] = gl_Vertex.x - 0.1;
+	gl_ClipDistance[1] = gl_Vertex.x - 0.2;
+	gl_ClipDistance[2] = gl_Vertex.x - 0.3;
+	gl_ClipDistance[3] = gl_Vertex.x - 0.4;
+	gl_ClipDistance[4] = gl_Vertex.x - 0.5;
+	gl_ClipDistance[5] = gl_Vertex.x - 0.6;
+	gl_ClipDistance[6] = gl_Vertex.x - 0.7;
+	gl_ClipDistance[7] = gl_Vertex.x - 0.8;
+}
+
+[fragment shader]
+#version 130
+
+void main()
+{
+	gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
+}
+
+[test]
+ortho 0 1 0 1
+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 rect 0.0 0.0 1.0 1.0
+
+relative probe rgba (0.75, 0.5) (0.0, 0.0, 0.0, 0.0)
+relative probe rgba (0.85, 0.5) (1.0, 1.0, 1.0, 1.0)
diff --git a/tests/util/glew.h b/tests/util/glew.h
index aec7ede..df4b90f 100644
--- a/tests/util/glew.h
+++ b/tests/util/glew.h
@@ -722,6 +722,8 @@ typedef char GLchar;
 #define GL_CLIP_PLANE3 0x3003
 #define GL_CLIP_PLANE4 0x3004
 #define GL_CLIP_PLANE5 0x3005
+#define GL_CLIP_PLANE6 0x3006
+#define GL_CLIP_PLANE7 0x3007
 #define GL_LIGHT0 0x4000
 #define GL_COLOR_BUFFER_BIT 0x00004000
 #define GL_LIGHT1 0x4001
-- 
1.7.6



More information about the Piglit mailing list