blob: 628f746e93573378041c8a0e34db6b5483afa5ad [file] [log] [blame]
John Kessenichf7922952013-02-12 06:53:13 +00001#version 430
John Kessenich9fd55bd2012-12-13 00:05:26 +00002
3#extension GL_3DL_array_objects : enable
4
5out Vertex {
6 vec4 Position; // API transform/feedback will use “Vertex.Position”
7 vec2 Texture;
8} Coords; // shader will use “Coords.Position”
9
10out Vertex2 {
11 vec4 Color; // API will use “Color”
12};
13
14uniform Transform { // API uses “Transform[2]” to refer to instance 2
15 mat4 ModelViewMatrix;
16 mat4 ModelViewProjectionMatrix;
17 vec4 a[]; // array will get implicitly sized
18 float Deformation;
19} transforms[4];
20
21layout(location = 3) in vec4 normal;
22layout(location = 6) in vec4 colors[3];
23layout(location = 9) in mat4 transforms[2];
24
25layout(location = 3) struct S {
John Kessenich8f13e132013-10-18 03:56:23 +000026 vec3 a1;
John Kessenich9fd55bd2012-12-13 00:05:26 +000027 mat2 b;
28 vec4 c[2];
29} s;
30
31layout(triangles, invocations = 6) in;
32
33layout(lines) in; // legal for Color2, input size is 2, matching Color2
34
35layout(triangle_strip, max_vertices = 60) out; // order does not matter
36layout(max_vertices = 60) out; // redeclaration okay
37layout(triangle_strip) out; // redeclaration okay
38//layout(points) out; // error, contradicts triangle_strip
39//layout(max_vertices = 30) out; // error, contradicts 60
40
41layout(stream = 1) out;
42
43layout(stream=1) out; // default is now stream 1
44out vec4 var1; // var1 gets default stream (1)
45layout(stream=2) out Block1 { // "Block1" belongs to stream 2
46 layout(stream=2) vec4 var2; // redundant block member stream decl
47 layout(stream=3) vec2 var3; // ILLEGAL (must match block stream)
48 vec3 var4; // belongs to stream 2
49};
50layout(stream=0) out; // default is now stream 0
51out vec4 var5; // var5 gets default stream (0)
52out Block2 { // "Block2" gets default stream (0)
53 vec4 var6;
54};
55layout(stream=3) out vec4 var7; // var7 belongs to stream 3
56
57layout(shared, column_major) uniform;
58layout(shared, column_major) buffer;
59
60layout(row_major, column_major)
61
62layout(shared, row_major) uniform; // default is now shared and row_major
63
John Kessenichf6648dc2013-04-10 02:06:46 +000064layout(std140) uniform Transform2 { // layout of this block is std140
John Kessenich9fd55bd2012-12-13 00:05:26 +000065 mat4 M1; // row_major
66 layout(column_major) mat4 M2; // column major
67 mat3 N1; // row_major
68};
69
John Kessenichf59bfa02013-01-10 01:47:54 +000070layout(column_major) uniform T3 { // shared and column_major
John Kessenichba042102013-04-10 20:15:16 +000071 mat4 M13; // column_major
72 layout(row_major) mat4 m14; // row major
73 mat3 N12; // column_major
John Kessenich9fd55bd2012-12-13 00:05:26 +000074};
75
76// in one compilation unit...
John Kessenichba042102013-04-10 20:15:16 +000077layout(binding=3) uniform sampler2D s17; // s bound to unit 3
John Kessenich9fd55bd2012-12-13 00:05:26 +000078
79// in another compilation unit...
John Kessenichba042102013-04-10 20:15:16 +000080uniform sampler2D s17; // okay, s still bound at 3
John Kessenich9fd55bd2012-12-13 00:05:26 +000081
82// in another compilation unit...
83//layout(binding=4) uniform sampler2D s; // ERROR: contradictory bindings
84
John Kessenich8f13e132013-10-18 03:56:23 +000085layout (binding = 2, offset = 4) uniform atomic_uint a2;
John Kessenich9fd55bd2012-12-13 00:05:26 +000086
87layout (binding = 2) uniform atomic_uint bar;
88
89layout (binding = 2, offset = 4) uniform atomic_uint;
90
91layout (binding = 2) uniform atomic_uint bar; // offset is 4
92layout (offset = 8) uniform atomic_uint bar; // error, no default binding
93
94layout (binding=3, offset=4) uniform atomic_uint a2; // offset = 4
95layout (binding=2) uniform atomic_uint b2; // offset = 0
96layout (binding=3) uniform atomic_uint c2; // offset = 8
97layout (binding=2) uniform atomic_uint d2; // offset = 4
98
99//layout (offset=4) // error, must include binding
John Kessenich60d9f7a2013-06-19 20:44:17 +0000100//layout (binding=1, offset=0) a; // okay
101//layout (binding=2, offset=0) b; // okay
John Kessenich9fd55bd2012-12-13 00:05:26 +0000102//layout (binding=1, offset=0) c; // error, offsets must not be shared
103// // between a and c
104//layout (binding=1, offset=2) d; // error, overlaps offset 0 of a
105
106flat in vec4 gl_FrontColor; // input to geometry shader, no “gl_in[]”
107flat out vec4 gl_FrontColor; // output from geometry shader
108
109invariant gl_Position; // make existing gl_Position be invariant
110
John Kessenicha4ea1312013-10-11 19:46:10 +0000111out vec3 ColorInv;
112invariant ColorIvn; // make existing Color be invariant
John Kessenich9fd55bd2012-12-13 00:05:26 +0000113
114invariant centroid out vec3 Color4;
115precise out vec4 position;
116
117out vec3 Color5;
118precise Color5; // make existing Color be precise
119in vec4 a, b, c, d;
120precise out vec4 v;
121
122coherent buffer Block {
123 readonly vec4 member1;
124 vec4 member2;
125};
126
John Kessenicha4ea1312013-10-11 19:46:10 +0000127buffer Block2a {
128 coherent readonly vec4 member1A;
129 coherent vec4 member2A;
John Kessenich9fd55bd2012-12-13 00:05:26 +0000130};
131
132shared vec4 shv;
133
134vec4 funcA(restrict image2D a) { }
135
136vec4 funcB(image2D a) { }
137layout(rgba32f) uniform image2D img1;
138layout(rgba32f) coherent uniform image2D img2;
139
140float func(float e, float f, float g, float h)
141{
142 return (e*f) + (g*h); // no constraint on order or
143 // operator consistency
144}
145
146float func2(float e, float f, float g, float h)
147{
148 precise float result = (e*f) + (g*h); // ensures same precision for
149 // the two multiplies
150 return result;
151}
152
153float func3(float i, float j, precise out float k)
154{
155 k = i * i + j; // precise, due to <k> declaration
156}
157
158void main()
159{
160 vec3 r = vec3(a * b); // precise, used to compute v.xyz
161 vec3 s = vec3(c * d); // precise, used to compute v.xyz
162 v.xyz = r + s; // precise
163 v.w = (a.w * b.w) + (c.w * d.w); // precise
164 v.x = func(a.x, b.x, c.x, d.x); // values computed in func()
165 // are NOT precise
166 v.x = func2(a.x, b.x, c.x, d.x); // precise!
167 func3(a.x * b.x, c.x * d.x, v.x); // precise!
168
169 funcA(img1); // OK, adding "restrict" is allowed
170 funcB(img2); // illegal, stripping "coherent" is not
171
172 {
173 struct light {
174 float intensity;
175 vec3 position;
176 };
177
178 light lightVar = light(3.0, vec3(1.0, 2.0, 3.0));
179 }
180 {
John Kessenichf59bfa02013-01-10 01:47:54 +0000181 const float c[3] = float[3](5.0, 7.2, 1.1);
John Kessenich9fd55bd2012-12-13 00:05:26 +0000182 const float d[3] = float[](5.0, 7.2, 1.1);
183
184 float g;
185 float a[5] = float[5](g, 1, g, 2.3, g);
186 float b[3];
187
188 b = float[3](g, g + 1.0, g + 2.0);
189 }
190 {
191 vec4 b[2] = { vec4(1.0), vec4(1.0) };
192 vec4[3][2](b, b, b); // constructor
193 vec4[][2](b, b, b); // constructor, valid, size deduced
194 vec4[3][](b, b, b); // compile-time error, invalid type constructed
195 }
196}