Add a new shader-versioning infrastructure capable of handling multiple profiles...
[platform/upstream/glslang.git] / Test / specExamples.vert
1 #version 110\r
2 \r
3 #extension GL_3DL_array_objects : enable\r
4 \r
5 out Vertex {\r
6     vec4 Position;  // API transform/feedback will use \93Vertex.Position\94\r
7     vec2 Texture;\r
8 } Coords;           // shader will use \93Coords.Position\94\r
9 \r
10 out Vertex2 {\r
11     vec4 Color;     // API will use \93Color\94\r
12 };\r
13 \r
14 uniform Transform {  // API uses \93Transform[2]\94 to refer to instance 2\r
15     mat4           ModelViewMatrix;\r
16     mat4           ModelViewProjectionMatrix;\r
17     vec4           a[];  // array will get implicitly sized\r
18     float          Deformation;\r
19 } transforms[4];\r
20 \r
21 layout(location = 3) in vec4 normal;\r
22 layout(location = 6) in vec4 colors[3];\r
23 layout(location = 9) in mat4 transforms[2];\r
24 \r
25 layout(location = 3) struct S {\r
26     vec3 a;\r
27     mat2 b;\r
28     vec4 c[2];\r
29 } s;\r
30 \r
31 layout(triangles, invocations = 6) in;\r
32 \r
33 layout(lines) in;    // legal for Color2, input size is 2, matching Color2\r
34 \r
35 layout(triangle_strip, max_vertices = 60) out;  // order does not matter\r
36 layout(max_vertices = 60) out;      // redeclaration okay\r
37 layout(triangle_strip) out;         // redeclaration okay\r
38 //layout(points) out;                 // error, contradicts triangle_strip\r
39 //layout(max_vertices = 30) out;      // error, contradicts 60\r
40 \r
41 layout(stream = 1) out;\r
42 \r
43 layout(stream=1) out;             // default is now stream 1\r
44 out vec4 var1;                    // var1 gets default stream (1)\r
45 layout(stream=2) out Block1 {     // "Block1" belongs to stream 2\r
46     layout(stream=2) vec4 var2;   // redundant block member stream decl\r
47     layout(stream=3) vec2 var3;   // ILLEGAL (must match block stream)\r
48     vec3 var4;                    // belongs to stream 2\r
49 };\r
50 layout(stream=0) out;             // default is now stream 0\r
51 out vec4 var5;                    // var5 gets default stream (0)\r
52 out Block2 {                      // "Block2" gets default stream (0)\r
53     vec4 var6;\r
54 };\r
55 layout(stream=3) out vec4 var7;   // var7 belongs to stream 3\r
56 \r
57 layout(shared, column_major) uniform;\r
58 layout(shared, column_major) buffer;\r
59 \r
60 layout(row_major, column_major)\r
61 \r
62 layout(shared, row_major) uniform; // default is now shared and row_major\r
63 \r
64 layout(std140) uniform Transform { // layout of this block is std140
65     mat4 M1;                       // row_major\r
66     layout(column_major) mat4 M2;  // column major\r
67     mat3 N1;                       // row_major\r
68 };\r
69 \r
70 layout(column_major) uniform T3 {  // shared and column_major
71     mat4 M3;                       // column_major\r
72     layout(row_major) mat4 m4;     // row major\r
73     mat3 N2;                       // column_major\r
74 };\r
75 \r
76 // in one compilation unit...\r
77 layout(binding=3) uniform sampler2D s; // s bound to unit 3\r
78 \r
79 // in another compilation unit...\r
80 uniform sampler2D s;                   // okay, s still bound at 3\r
81 \r
82 // in another compilation unit...\r
83 //layout(binding=4) uniform sampler2D s; // ERROR: contradictory bindings\r
84 \r
85 layout (binding = 2, offset = 4) uniform atomic_uint a;\r
86 \r
87 layout (binding = 2) uniform atomic_uint bar;\r
88 \r
89 layout (binding = 2, offset = 4) uniform atomic_uint;\r
90 \r
91 layout (binding = 2) uniform atomic_uint bar; // offset is 4\r
92 layout (offset = 8) uniform atomic_uint bar;  // error, no default binding\r
93 \r
94 layout (binding=3, offset=4) uniform atomic_uint a2; // offset = 4\r
95 layout (binding=2) uniform atomic_uint b2;           // offset = 0\r
96 layout (binding=3) uniform atomic_uint c2;           // offset = 8\r
97 layout (binding=2) uniform atomic_uint d2;           // offset = 4\r
98 \r
99 //layout (offset=4)                // error, must include binding\r
100 layout (binding=1, offset=0)  a; // okay\r
101 layout (binding=2, offset=0)  b; // okay\r
102 //layout (binding=1, offset=0)  c; // error, offsets must not be shared\r
103 //                                 //        between a and c\r
104 //layout (binding=1, offset=2)  d; // error, overlaps offset 0 of a\r
105 \r
106 flat  in vec4 gl_FrontColor;  // input to geometry shader, no \93gl_in[]\94\r
107 flat out vec4 gl_FrontColor;  // output from geometry shader\r
108 \r
109 invariant gl_Position;   // make existing gl_Position be invariant\r
110 \r
111 out vec3 Color;\r
112 invariant Color;         // make existing Color be invariant\r
113 \r
114 invariant centroid out vec3 Color4;\r
115 precise out vec4 position;\r
116 \r
117 out vec3 Color5;\r
118 precise Color5;            // make existing Color be precise\r
119 in vec4 a, b, c, d;\r
120 precise out vec4 v;\r
121 \r
122 coherent buffer Block {\r
123     readonly vec4 member1;\r
124     vec4 member2;\r
125 };\r
126 \r
127 buffer Block {\r
128     coherent readonly vec4 member1;\r
129     coherent vec4 member2;\r
130 };\r
131 \r
132 shared vec4 shv;\r
133 \r
134 vec4 funcA(restrict image2D a)   {  }\r
135 \r
136 vec4 funcB(image2D a)            {  }\r
137 layout(rgba32f) uniform image2D img1;\r
138 layout(rgba32f) coherent uniform image2D img2;\r
139 \r
140 float func(float e, float f, float g, float h)\r
141 {\r
142     return (e*f) + (g*h);            // no constraint on order or \r
143                                      // operator consistency\r
144 }\r
145 \r
146 float func2(float e, float f, float g, float h)\r
147 {\r
148     precise float result = (e*f) + (g*h);  // ensures same precision for\r
149                                            // the two multiplies\r
150     return result;\r
151 }\r
152 \r
153 float func3(float i, float j, precise out float k)\r
154 {\r
155     k = i * i + j;                   // precise, due to <k> declaration\r
156 }\r
157 \r
158 void main()\r
159 {\r
160     vec3 r = vec3(a * b);           // precise, used to compute v.xyz\r
161     vec3 s = vec3(c * d);           // precise, used to compute v.xyz\r
162     v.xyz = r + s;                          // precise                      \r
163     v.w = (a.w * b.w) + (c.w * d.w);        // precise\r
164     v.x = func(a.x, b.x, c.x, d.x);         // values computed in func()\r
165                                             // are NOT precise\r
166     v.x = func2(a.x, b.x, c.x, d.x);        // precise!\r
167     func3(a.x * b.x, c.x * d.x, v.x);       // precise!\r
168         \r
169     funcA(img1);              // OK, adding "restrict" is allowed\r
170     funcB(img2);              // illegal, stripping "coherent" is not\r
171 \r
172     {\r
173         struct light {\r
174             float intensity;\r
175             vec3 position;\r
176         };\r
177 \r
178         light lightVar = light(3.0, vec3(1.0, 2.0, 3.0));\r
179     }\r
180     {\r
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);\r
183 \r
184         float g;\r
185         float a[5] = float[5](g, 1, g, 2.3, g);\r
186         float b[3];\r
187 \r
188         b = float[3](g, g + 1.0, g + 2.0);\r
189     }\r
190     {\r
191         vec4 b[2] = { vec4(1.0), vec4(1.0) };\r
192         vec4[3][2](b, b, b);        // constructor\r
193         vec4[][2](b, b, b);         // constructor, valid, size deduced\r
194         vec4[3][](b, b, b);         // compile-time error, invalid type constructed\r
195     }\r
196 }\r