• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#version 430
2
3#extension GL_3DL_array_objects : enable
4
5out Vertex {
6    vec4 Position;  // API transform/feedback will use �Vertex.Position7    vec2 Texture;
8} Coords;           // shader will use �Coords.Position9
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 transforms2[2];
24
25layout(location = 3) struct S {
26    vec3 a1;
27    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
64layout(std140) uniform Transform2 { // layout of this block is std140
65    mat4 M1;                       // row_major
66    layout(column_major) mat4 M2;  // column major
67    mat3 N1;                       // row_major
68};
69
70layout(column_major) uniform T3 {  // shared and column_major
71    mat4 M13;                      // column_major
72    layout(row_major) mat4 m14;    // row major
73    mat3 N12;                      // column_major
74};
75
76// in one compilation unit...
77layout(binding=3) uniform sampler2D s17; // s bound to unit 3
78
79// in another compilation unit...
80uniform sampler2D s17;                   // okay, s still bound at 3
81
82// in another compilation unit...
83//layout(binding=4) uniform sampler2D s; // ERROR: contradictory bindings
84
85layout (binding = 2, offset = 4) uniform atomic_uint a2;
86
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 bar23;  // 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
100//layout (binding=1, offset=0)  a; // okay
101//layout (binding=2, offset=0)  b; // okay
102//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
111out vec3 ColorInv;
112invariant ColorIvn;      // make existing Color be invariant
113
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
127buffer Block2a {
128    coherent readonly vec4 member1A;
129    coherent vec4 member2A;
130};
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, ERROR, changing formats
170    funcB(img2);              // illegal, stripping "coherent" is not, ERROR, changing formats
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    {
181        const float c[3] = float[3](5.0, 7.2, 1.1);
182        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}
197