Commit ed15050c authored by Timothy Arceri's avatar Timothy Arceri

gl-3.2-compat: test gl_ClipVertex built-in with geometry shaders

These tests have been adapted from the glsl-1.20 clipping tests.

This tests both setting gl_ClipVertex in the geometry shader and
using the gs to passthrough the gl_ClipVertex value from the
vertex shader.

I tested these on NVIDIA 384.111 binary driver but some of these
get a cryptic error message:

variable "gl_ClipVertex" domain conflicts with semantics "CLPV"

However I believe the tests are correct and this is a driver bug.
Tested-by: default avatarMarek Olšák <marek.olsak@amd.com>
Acked-by: default avatarMarek Olšák <marek.olsak@amd.com>
parent 7fd22146
# From the GL 2.1 spec, section 2.17 (Clipping):
#
# All points with eye coordinates (x_e y_e z_e w_e)^T that satisfy
#
# (x_e)
# (p_1' p_2' p_3' p_4')(y_e) >= 0
# (z_e)
# (w_e)
#
# lie in the half-space defined by the plane; points that do not
# satisfy this condition do not lie in the half-space.
#
# This test checks that gl_ClipVertex works properly for the trivial
# case where gl_ClipVertex is a constant value satisfying the above
# inequality.
[require]
GL COMPAT >= 3.2
GLSL >= 1.50
[vertex shader]
#version 150 compatibility
out gl_PerVertex {
vec4 gl_Position;
vec4 gl_ClipVertex;
};
void main(void)
{
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}
[geometry shader]
#version 150 compatibility
layout(triangles) in;
layout(triangle_strip, max_vertices = 3) out;
in gl_PerVertex {
vec4 gl_Position;
vec4 gl_ClipVertex;
} gl_in[];
void main()
{
for (int i = 0; i < 3; i++) {
gl_Position = gl_in[i].gl_Position;
gl_ClipVertex = vec4(1.0, 0.0, 0.0, 0.0);
EmitVertex();
}
}
[fragment shader]
#version 120
void main(void)
{
gl_FragColor = vec4(1.0);
}
[test]
clear color 0.0 0.0 0.0 0.0
clear
clip plane 0 1.0 0.0 0.0 0.0 # accept points where gl_ClipVertex.x >= 0
enable GL_CLIP_PLANE0
draw rect -1 -1 2 2
probe all rgba 1.0 1.0 1.0 1.0
# From the GL 2.1 spec, section 2.17 (Clipping):
#
# All points with eye coordinates (x_e y_e z_e w_e)^T that satisfy
#
# (x_e)
# (p_1' p_2' p_3' p_4')(y_e) >= 0
# (z_e)
# (w_e)
#
# lie in the half-space defined by the plane; points that do not
# satisfy this condition do not lie in the half-space.
#
# This test checks that gl_ClipVertex works properly for the trivial
# case where gl_ClipVertex is a constant value not satisfying the
# above inequality.
[require]
GL COMPAT >= 3.2
GLSL >= 1.50
[vertex shader]
#version 120
void main(void)
{
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}
[geometry shader]
#version 150 compatibility
layout(triangles) in;
layout(triangle_strip, max_vertices = 3) out;
void main()
{
for (int i = 0; i < 3; i++) {
gl_Position = gl_in[i].gl_Position;
gl_ClipVertex = vec4(-1.0, 0.0, 0.0, 0.0);
EmitVertex();
}
}
[fragment shader]
#version 120
void main(void)
{
gl_FragColor = vec4(1.0);
}
[test]
clear color 0.0 0.0 0.0 0.0
clear
clip plane 0 1.0 0.0 0.0 0.0 # accept points where gl_ClipVertex.x >= 0
enable GL_CLIP_PLANE0
draw rect -1 -1 2 2
probe all rgba 0.0 0.0 0.0 0.0
# [description]
# Use all 6 clip planes to clip a rectangle to a hexagon shape.
#
# In this test, gl_Position and gl_ClipVertex are different to verify
# that gl_Position determines screen position and gl_ClipVertex
# determines clipping.
[require]
GL COMPAT >= 3.2
GLSL >= 1.50
[vertex shader]
#version 120
void main(void)
{
gl_Position = gl_Vertex;
}
[geometry shader]
#version 150 compatibility
layout(triangles) in;
layout(triangle_strip, max_vertices = 3) out;
void main()
{
for (int i = 0; i < 3; i++) {
gl_Position = gl_ModelViewProjectionMatrix * gl_in[i].gl_Position;
// Transform gl_ClipVertex in an arbitrary way so that
// we can verify it is being used for clipping instead of
// gl_Position.
gl_ClipVertex = gl_in[i].gl_Position * vec4(10.0, 10.0, 1.0, 1.0);
EmitVertex();
}
}
[fragment shader]
#version 120
void main(void)
{
gl_FragColor = vec4(1, 1, 1, 1);
}
[test]
clear color 0.0 0.0 0.0 0.0
clear
ortho 0 1 0 1
clip plane 0 0 1 0 -2.5
clip plane 1 -1 1 0 4
clip plane 2 -1 -1 0 14
clip plane 3 0 -1 0 7.5
clip plane 4 1 -1 0 4
clip plane 5 1 1 0 -6
enable GL_CLIP_PLANE0
enable GL_CLIP_PLANE1
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
# 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)
# 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)
# This test sets up 6 clipping planes using gl_ClipVertex, which clip
# a rectangle to a hexagon shape. Then it tests various combinations
# of enables for the 6 clipping planes, and verifies that they all
# create the correct shape.
#
# To verify that each enable works, the combinations of enables were
# chosen such that:
# - Every plane is enabled at least once and disbled at least once.
# - Every plane is enabled and disabled in a different pattern.
#
# Note: Some implementations have bugs related to improper coordinate
# transformations of clip planes (which are already adequately tested
# by the clip-plane-transformation test), so to avoid those bugs
# contaminating the results of this test, we don't do any coordinate
# transformation in this test.
[require]
GL COMPAT >= 3.2
GLSL >= 1.50
[vertex shader]
#version 120
void main(void)
{
gl_Position = gl_Vertex;
}
[geometry shader]
#version 150 compatibility
layout(triangles) in;
layout(triangle_strip, max_vertices = 3) out;
void main()
{
for (int i = 0; i < 3; i++) {
gl_Position = gl_in[i].gl_Position;
gl_ClipVertex = gl_in[i].gl_Position;
EmitVertex();
}
}
[fragment shader]
#version 120
void main(void)
{
gl_FragColor = vec4(1, 1, 1, 1);
}
[test]
clip plane 0 0 1 0 0.5
clip plane 1 -1 1 0 0.8
clip plane 2 -1 -1 0 0.8
clip plane 3 0 -1 0 0.5
clip plane 4 1 -1 0 0.8
clip plane 5 1 1 0 0.8
clear color 0.0 0.0 0.0 0.0
# Test with planes 0, 2, and 4 enabled.
enable GL_CLIP_PLANE0
disable GL_CLIP_PLANE1
enable GL_CLIP_PLANE2
disable GL_CLIP_PLANE3
enable GL_CLIP_PLANE4
disable GL_CLIP_PLANE5
clear
draw rect -1 -1 2 2
# 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)
# Test points outside each hexagon edge
relative probe rgba (0.5, 0.2) (0.0, 0.0, 0.0, 0.0) # clipped by plane 0
relative probe rgba (0.8, 0.3) (1.0, 1.0, 1.0, 1.0) # clipped by plane 1
relative probe rgba (0.8, 0.7) (0.0, 0.0, 0.0, 0.0) # clipped by plane 2
relative probe rgba (0.5, 0.8) (1.0, 1.0, 1.0, 1.0) # clipped by plane 3
relative probe rgba (0.2, 0.7) (0.0, 0.0, 0.0, 0.0) # clipped by plane 4
relative probe rgba (0.2, 0.3) (1.0, 1.0, 1.0, 1.0) # clipped by plane 5
# Test with planes 0, 1, 4, and 5 enabled.
enable GL_CLIP_PLANE0
enable GL_CLIP_PLANE1
disable GL_CLIP_PLANE2
disable GL_CLIP_PLANE3
enable GL_CLIP_PLANE4
enable GL_CLIP_PLANE5
clear
draw rect -1 -1 2 2
# 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)
# Test points outside each hexagon edge
relative probe rgba (0.5, 0.2) (0.0, 0.0, 0.0, 0.0) # clipped by plane 0
relative probe rgba (0.8, 0.3) (0.0, 0.0, 0.0, 0.0) # clipped by plane 1
relative probe rgba (0.8, 0.7) (1.0, 1.0, 1.0, 1.0) # clipped by plane 2
relative probe rgba (0.5, 0.8) (1.0, 1.0, 1.0, 1.0) # clipped by plane 3
relative probe rgba (0.2, 0.7) (0.0, 0.0, 0.0, 0.0) # clipped by plane 4
relative probe rgba (0.2, 0.3) (0.0, 0.0, 0.0, 0.0) # clipped by plane 5
# Test with planes 0, 1, 2, and 3 enabled.
enable GL_CLIP_PLANE0
enable GL_CLIP_PLANE1
enable GL_CLIP_PLANE2
enable GL_CLIP_PLANE3
disable GL_CLIP_PLANE4
disable GL_CLIP_PLANE5
clear
draw rect -1 -1 2 2
# 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)
# Test points outside each hexagon edge
relative probe rgba (0.5, 0.2) (0.0, 0.0, 0.0, 0.0) # clipped by plane 0
relative probe rgba (0.8, 0.3) (0.0, 0.0, 0.0, 0.0) # clipped by plane 1
relative probe rgba (0.8, 0.7) (0.0, 0.0, 0.0, 0.0) # clipped by plane 2
relative probe rgba (0.5, 0.8) (0.0, 0.0, 0.0, 0.0) # clipped by plane 3
relative probe rgba (0.2, 0.7) (1.0, 1.0, 1.0, 1.0) # clipped by plane 4
relative probe rgba (0.2, 0.3) (1.0, 1.0, 1.0, 1.0) # clipped by plane 5
# Test with planes 4 and 5 enabled.
disable GL_CLIP_PLANE0
disable GL_CLIP_PLANE1
disable GL_CLIP_PLANE2
disable GL_CLIP_PLANE3
enable GL_CLIP_PLANE4
enable GL_CLIP_PLANE5
clear
draw rect -1 -1 2 2
# 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)
# Test points outside each hexagon edge
relative probe rgba (0.5, 0.2) (1.0, 1.0, 1.0, 1.0) # clipped by plane 0
relative probe rgba (0.8, 0.3) (1.0, 1.0, 1.0, 1.0) # clipped by plane 1
relative probe rgba (0.8, 0.7) (1.0, 1.0, 1.0, 1.0) # clipped by plane 2
relative probe rgba (0.5, 0.8) (1.0, 1.0, 1.0, 1.0) # clipped by plane 3
relative probe rgba (0.2, 0.7) (0.0, 0.0, 0.0, 0.0) # clipped by plane 4
relative probe rgba (0.2, 0.3) (0.0, 0.0, 0.0, 0.0) # clipped by plane 5
# [description]
# Use all 6 clip planes to clip a rectangle to a hexagon shape.
#
# In this test, gl_Position and gl_ClipVertex are the same.
[require]
GL COMPAT >= 3.2
GLSL >= 1.50
[vertex shader]
#version 120
void main(void)
{
gl_Position = gl_Vertex;
}
[geometry shader]
#version 150 compatibility
layout(triangles) in;
layout(triangle_strip, max_vertices = 3) out;
void main()
{
for (int i = 0; i < 3; i++) {
gl_Position = gl_ModelViewProjectionMatrix * gl_in[i].gl_Position;
gl_ClipVertex = gl_Position;
EmitVertex();
}
}
[fragment shader]
#version 120
void main(void)
{
gl_FragColor = vec4(1, 1, 1, 1);
}
[test]
clear color 0.0 0.0 0.0 0.0
clear
ortho 0 1 0 1
clip plane 0 0 1 0 0.5
clip plane 1 -1 1 0 0.8
clip plane 2 -1 -1 0 0.8
clip plane 3 0 -1 0 0.5
clip plane 4 1 -1 0 0.8
clip plane 5 1 1 0 0.8
enable GL_CLIP_PLANE0
enable GL_CLIP_PLANE1
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
# 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)
# 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)
# This test verifies that the homogeneous coordinate of gl_ClipVertex
# is properly respected, by doubling all the coordinates of
# gl_ClipVertex (including the homogeneous coordinate) and verifying
# that the clipped shape is still correct.
#
# In addition, this test:
# - uses all 6 clip planes to clip a rectangle to a hexagon shape.
# - sets gl_Position and gl_ClipVertex to different values, to verify
# that gl_Position determines screen position and gl_ClipVertex
# determines clipping.
[require]
GL COMPAT >= 3.2
GLSL >= 1.50
[vertex shader]
#version 120
void main(void)
{
gl_Position = gl_Vertex;
}
[geometry shader]
#version 150 compatibility
layout(triangles) in;
layout(triangle_strip, max_vertices = 3) out;
void main()
{
for (int i = 0; i < 3; i++) {
gl_Position = gl_ModelViewProjectionMatrix * gl_in[i].gl_Position;
// Transform gl_ClipVertex in an arbitrary way so that
// we can verify it is being used for clipping instead of
// gl_Position. The x and y coordinates are multiplied by 5,
// and the homogeneous coordinate is multiplied by 0.5, so the
// net result should be that x and y are scaled by a factor of
// 10.
gl_ClipVertex = gl_in[i].gl_Position * vec4(5.0, 5.0, 1.0, 0.5);
EmitVertex();
}
}
[fragment shader]
#version 120
void main(void)
{
gl_FragColor = vec4(1, 1, 1, 1);
}
[test]
clear color 0.0 0.0 0.0 0.0
clear
ortho 0 1 0 1
clip plane 0 0 1 0 -2.5
clip plane 1 -1 1 0 4
clip plane 2 -1 -1 0 14
clip plane 3 0 -1 0 7.5
clip plane 4 1 -1 0 4
clip plane 5 1 1 0 -6
enable GL_CLIP_PLANE0
enable GL_CLIP_PLANE1
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
# 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)
# 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)
# Verify that gl_ClipVertex affects different primitive types correctly.
[require]
GL COMPAT >= 3.2
GLSL >= 1.50
[vertex shader]
#version 120
attribute vec2 in_pos;
uniform vec2 u_offset;
void main(void)
{
gl_Position = gl_ModelViewProjectionMatrix * vec4(u_offset + in_pos, 0, 1);
}
[geometry shader]
#version 150 compatibility
layout(lines) in;
layout(line_strip, max_vertices = 2) out;
uniform float u_clipdist;
void main()
{
for (int i = 0; i < 3; i++) {
gl_Position = gl_in[i].gl_Position;
gl_ClipVertex = vec4(u_clipdist, 0.0, 0.0, 0.0);
EmitVertex();
}
}
[fragment shader]
#version 120
void main(void)
{
gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
}
[vertex data]
in_pos/float/2
0 0
10 0
0 10
10 10
[test]
clear color 0.0 0.0 0.0 0.0
clear
clip plane 0 1.0 0.0 0.0 0.0 # accept points where gl_ClipVertex.x >= 0
enable GL_CLIP_PLANE0
ortho
# Test that primitives are clipped with a negative distance
uniform float u_clipdist -1
uniform vec2 u_offset 20 0.5
draw arrays GL_LINES 0 2
probe rect rgba (20, 0, 20, 20) (0, 0, 0, 0)
# Test that primitives are not clipped with zero distance
uniform float u_clipdist 0
uniform vec2 u_offset 20 20.5
draw arrays GL_LINES 0 2
probe rect rgba (20, 20, 10, 1) (1, 0, 0, 1)
# Verify that gl_ClipVertex affects different primitive types correctly.
[require]
GL COMPAT >= 3.2
GLSL >= 1.50
[vertex shader]
#version 120
attribute vec2 in_pos;
uniform vec2 u_offset;
void main(void)
{
gl_Position = gl_ModelViewProjectionMatrix * vec4(u_offset + in_pos, 0, 1);
}
[geometry shader]
#version 150 compatibility
layout(points) in;
layout(points, max_vertices = 1) out;
uniform float u_clipdist;
void main()
{
for (int i = 0; i < 3; i++) {
gl_Position = gl_in[i].gl_Position;
gl_ClipVertex = vec4(u_clipdist, 0.0, 0.0, 0.0);
EmitVertex();
}
}
[fragment shader]
#version 120
void main(void)
{
gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
}
[vertex data]
in_pos/float/2
0 0
10 0
0 10
10 10
[test]
clear color 0.0 0.0 0.0 0.0
clear
clip plane 0 1.0 0.0 0.0 0.0 # accept points where gl_ClipVertex.x >= 0
enable GL_CLIP_PLANE0
ortho
# Test that primitives are clipped with a negative distance
uniform float u_clipdist -1
uniform vec2 u_offset 0.5 0.5
draw arrays GL_POINTS 0 1
probe rect rgba ( 0, 0, 20, 20) (0, 0, 0, 0)
# Test that primitives are not clipped with zero distance
uniform float u_clipdist 0
uniform vec2 u_offset 0.5 20.5
draw arrays GL_POINTS 0 1
probe rect rgba ( 0, 20, 1, 1) (1, 0, 0, 1)
# Verify that gl_ClipVertex affects different primitive types correctly.
[require]
GL COMPAT >= 3.2
GLSL >= 1.50
[vertex shader]
#version 120
attribute vec2 in_pos;
uniform vec2 u_offset;
void main(void)
{
gl_Position = gl_ModelViewProjectionMatrix * vec4(u_offset + in_pos, 0, 1);
}
[geometry shader]
#version 150 compatibility
layout(triangles) in;
layout(triangle_strip, max_vertices = 3) out;
uniform float u_clipdist;