File: varying-struct-basic-gs-fs.shader_test

package info (click to toggle)
piglit 0~git20220119-124bca3c9-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 109,012 kB
  • sloc: ansic: 273,511; xml: 46,666; python: 33,098; lisp: 20,392; cpp: 12,480; sh: 22; makefile: 22; pascal: 5
file content (141 lines) | stat: -rw-r--r-- 3,220 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# Test that varying structs work properly.
#
# From the GLSL 1.50 specification, section 4.3.4 ("Input Variables"):
#
# "Fragment inputs can only be signed and unsigned integers and
#  integer vectors, float, floating-point vectors, matrices, or
#  arrays or structures of these."
#
# And from section 4.3.6 ("Output Variables"):
#
# "Vertex and geometry output variables output per-vertex data and are
#  declared using the out storage qualifier, the centroid out storage
#  qualifier, or the deprecated varying storage qualifier. They can only be
#  float, floating-point vectors, matrices, signed or unsigned integers or
#  integer vectors, or arrays or structures of any these."
#
# This test verifies basic functionality of varying structs using a
# varying struct containing a variety of types.

[require]
GL >= 3.2
GLSL >= 1.50

[vertex shader]
#version 150

in vec4 vertex;
out vec4 pos;

void main()
{
	gl_Position = vertex;
	pos = vertex;
}

[geometry shader]
#version 150

uniform float ref;

layout(triangles) in;
layout(triangle_strip, max_vertices=3) out;

in vec4 pos[];

struct Foo
{
	mat4 a;
	mat3 b;
	mat2 c;
	vec4 d;
	vec3 e;
	vec2 f;
	float g;
};
out Foo foo;

void main()
{
	for(int i = 0; i < 3; i++) {
		gl_Position = pos[i];
		foo.a = mat4(ref,        ref +  1.0, ref +  2.0, ref +  3.0,
			     ref +  4.0, ref +  5.0, ref +  6.0, ref +  7.0,
			     ref +  8.0, ref +  9.0, ref + 10.0, ref + 11.0,
			     ref + 12.0, ref + 13.0, ref + 14.0, ref + 15.0);

		foo.b = mat3(ref + 16.0, ref + 17.0, ref + 18.0,
			     ref + 19.0, ref + 20.0, ref + 21.0,
			     ref + 22.0, ref + 23.0, ref + 24.0);

		foo.c = mat2(ref + 25.0, ref + 26.0,
			     ref + 27.0, ref + 28.0);

		foo.d = vec4(ref + 29.0, ref + 30.0, ref + 31.0, ref + 32.0);
		foo.e = vec3(ref + 33.0, ref + 34.0, ref + 35.0);
		foo.f = vec2(ref + 36.0, ref + 37.0);
		foo.g = ref + 38.0;
		EmitVertex();
	}
}

[fragment shader]
#version 150

uniform float ref;

struct Foo
{
	mat4 a;
	mat3 b;
	mat2 c;
	vec4 d;
	vec3 e;
	vec2 f;
	float g;
};
in Foo foo;
out vec4 color;

#define CHECK(value, expected) \
	if (distance(value, expected) > 0.00001) \
		failed = true

void main()
{
	bool failed = false;

	CHECK(foo.a[0], vec4(ref,        ref +  1.0, ref +  2.0, ref +  3.0));
	CHECK(foo.a[1], vec4(ref +  4.0, ref +  5.0, ref +  6.0, ref +  7.0));
	CHECK(foo.a[2], vec4(ref +  8.0, ref +  9.0, ref + 10.0, ref + 11.0));
	CHECK(foo.a[3], vec4(ref + 12.0, ref + 13.0, ref + 14.0, ref + 15.0));

	CHECK(foo.b[0], vec3(ref + 16.0, ref + 17.0, ref + 18.0));
	CHECK(foo.b[1], vec3(ref + 19.0, ref + 20.0, ref + 21.0));
	CHECK(foo.b[2], vec3(ref + 22.0, ref + 23.0, ref + 24.0));

	CHECK(foo.c[0], vec2(ref + 25.0, ref + 26.0));
	CHECK(foo.c[1], vec2(ref + 27.0, ref + 28.0));

	CHECK(foo.d, vec4(ref + 29.0, ref + 30.0, ref + 31.0, ref + 32.0));
	CHECK(foo.e, vec3(ref + 33.0, ref + 34.0, ref + 35.0));
	CHECK(foo.f, vec2(ref + 36.0, ref + 37.0));
	CHECK(foo.g, ref + 38.0);

	if (failed)
		color = vec4(1.0, 0.0, 0.0, 1.0);
	else
		color = 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]
uniform float ref 137.035999074
draw arrays GL_TRIANGLE_FAN 0 4
probe all rgba 0.0 1.0 0.0 1.0