[Piglit] [PATCH] Add tests for gl_ClipDistance and gl_ClipVertex.

Ian Romanick idr at freedesktop.org
Tue Aug 16 13:45:33 PDT 2011


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 08/09/2011 02:55 PM, Paul Berry wrote:
> This patch is a preparation for work I'm about to do to add
> gl_ClipDistance support to Mesa, and future work that I hope to do to
> fix bugs in gl_ClipVertex in Mesa.  It adds a thorough set of tests
> for the following behaviors of gl_ClipDistance and gl_ClipVertex:
> 
> For gl_ClipVertex:
> - It behaves properly when equal to gl_Position.
> - It behaves properly when not equal to gl_Position.
> - It falls back to gl_Position when it is not set.
> - Its homogeneous coordinate is respected.
> - The homogeneous coordinate is respected when falling back to gl_Position.
> 
> For gl_ClipDistance:
> - It works when all 6 clip planes are enabled.
> - Its behavior is properly affected by clip plane enable flags.
> - It can be explicitly or implicitly sized in the vertex shader.
> - It can be sized up to gl_MaxVaryingComponents but no higher.
> - In the fragment shader, it contains properly interpolated values.

There a couple of "dumb" tests missing:

 - Write a constant value to gl_ClipVertex that will never be clipped.
Verify that the whole primitive is drawn.

 - Write a constant value to gl_ClipVertex that will always be clipped.
 Verify that nothing is drawn.

 - Write a constant values to gl_ClipDistance that will never be
clipped.  Verify that the whole primitive is drawn.

 - Write a constant values to gl_ClipDistance that will always be
clipped.  Verify that nothing is drawn.

Silly tests like these are useful for bring-up.

There are comments about a couple specific tests below...

> 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..185fb22
> --- /dev/null
> +++ b/tests/spec/glsl-1.30/execution/clipping/vs-clip-distance-implicitly-sized.shader_test
> @@ -0,0 +1,52 @@
> +# From the GLSL 1.30 spec section 7.1 (Vertex Shader Special
> +# Variables):
> +#
> +#   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.
> +#
> +# This test checks that the GLSL compiler respects the size of
> +# gl_ClipDistance when it is implicitly sized in the vertex shader by
> +# indexing into it with integral constant expressions.
> +#
> +# The spec isn't clear about whether it's necessary for the GLSL
> +# compiler to size gl_ClipDistance to the minimum size possible.  In
> +# other words, if only gl_ClipDistance[2] is accessed, must the
> +# compiler infer that the size of gl_ClipDistance is 3, or is any size
> +# greater than or equal to 3 acceptable?  This test assumes any size
> +# greater than or equal to 3 is acceptable.
> +
> +[require]
> +GLSL >= 1.30
> +
> +[vertex shader]
> +#version 130
> +
> +void main()
> +{
> +  gl_Position = gl_Vertex;
> +  gl_FrontColor = (gl_ClipDistance.length() >= 3) ? vec4(0.0, 1.0, 0.0, 1.0)
> +                                                  : vec4(1.0, 0.0, 0.0, 1.0);

This should actually generate an error.  Page 26 (page 32 of the PDF) of
the GLSL 1.30 spec says:

    "The length method cannot be called on an array that has not been
    explicitly sized."

In this case gl_ClipDistance is implicitly sized after the call to
length.  We /should/ have similar tests for gl_TexCoord.  It behaves in
a similar manner.

> +  gl_ClipDistance[2] = 1.0;
> +}
> +
> +[fragment shader]
> +#version 130
> +void main()
> +{
> +  gl_FragColor = gl_Color;
> +}
> +
> +[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-sizeable-to-max.shader_test b/tests/spec/glsl-1.30/execution/clipping/vs-clip-distance-sizeable-to-max.shader_test
> new file mode 100644
> index 0000000..accd639
> --- /dev/null
> +++ b/tests/spec/glsl-1.30/execution/clipping/vs-clip-distance-sizeable-to-max.shader_test
> @@ -0,0 +1,45 @@
> +# From the GLSL 1.30 spec section 7.1 (Vertex Shader Special
> +# Variables):
> +#
> +#   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.
> +#
> +# This test checks that the size of gl_ClipDistance can be set to
> +# gl_MaxClipDistances without error, and that this actually causes the
> +# size of the array to be set properly.
> +
> +[require]
> +GLSL >= 1.30
> +
> +[vertex shader]
> +#version 130
> +out float gl_ClipDistance[gl_MaxClipDistances];

We should also test that

out float gl_ClipDistance[gl_MaxClipDistances + 1];

generates an error.  I see there's a similar test for accesses beyond
gl_MaxClipDistances when gl_ClipDistance is implicitly sized.

> +
> +void main()
> +{
> +  gl_Position = gl_Vertex;
> +  gl_FrontColor = (gl_ClipDistance.length() == gl_MaxClipDistances)
> +    ? vec4(0.0, 1.0, 0.0, 1.0) : vec4(1.0, 0.0, 0.0, 1.0);
> +}
> +
> +[fragment shader]
> +#version 130
> +void main()
> +{
> +  gl_FragColor = gl_Color;
> +}
> +
> +[test]
> +draw rect -1 -1 2 2
> +probe all rgba 0.0 1.0 0.0 1.0
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/

iEYEARECAAYFAk5K1u0ACgkQX1gOwKyEAw9P9QCgjO5p9YRQ9IoWSOhPgReemiK7
LX4AoIVoMsE5CoRl8ASIQlKbYx1Gutul
=acMr
-----END PGP SIGNATURE-----


More information about the Piglit mailing list