Merge pull request #2908 from Biswa96/cmake-spirv-remap
[platform/upstream/glslang.git] / Test / specExamples.frag
1 #version 430\r
2 \r
3 #extension GL_3DL_array_objects : enable\r
4 \r
5 int  a = 0xffffffff;  // 32 bits, a gets the value -1\r
6 int  b = 0xffffffffU; // ERROR: can't convert uint to int\r
7 uint c = 0xffffffff;  // 32 bits, c gets the value 0xFFFFFFFF\r
8 uint d = 0xffffffffU; // 32 bits, d gets the value 0xFFFFFFFF\r
9 int  e = -1;          // the literal is "1", then negation is performed,\r
10                       //   and the resulting non-literal 32-bit signed \r
11                       //   bit pattern of 0xFFFFFFFF is assigned, giving e \r
12                       //   the value of -1.\r
13 uint f = -1u;         // the literal is "1u", then negation is performed,\r
14                       //   and the resulting non-literal 32-bit unsigned \r
15                       //   bit pattern of 0xFFFFFFFF is assigned, giving f \r
16                       //   the value of 0xFFFFFFFF.\r
17 int  g = 3000000000;  // a signed decimal literal taking 32 bits,\r
18                       //   setting the sign bit, g gets -1294967296\r
19 int  h = 0xA0000000;  // okay, 32-bit signed hexadecimal\r
20 int  i = 5000000000;  // ERROR: needs more than 32 bits\r
21 int  j = 0xFFFFFFFFF; // ERROR: needs more that 32 bits\r
22 int  k = 0x80000000;  // k gets -2147483648 == 0x80000000\r
23 int  l = 2147483648;  // l gets -2147483648 (the literal set the sign bit)\r
24 \r
25 float fa, fb = 1.5;     // single-precision floating-point\r
26 double fc, fd = 2.0LF;  // double-precision floating-point\r
27 \r
28 vec2 texcoord1, texcoord2;\r
29 vec3 position;\r
30 vec4 myRGBA;\r
31 ivec2 textureLookup;\r
32 bvec3 less;\r
33 \r
34 mat2 mat2D;\r
35 mat3 optMatrix;\r
36 mat4 view, projection;\r
37 mat4x4 view;  // an alternate way of declaring a mat4\r
38 mat3x2 m;     // a matrix with 3 columns and 2 rows\r
39 dmat4 highPrecisionMVP;\r
40 dmat2x4 dm;\r
41 \r
42 struct light {\r
43     float intensity;\r
44     vec3 position;\r
45 } lightVar;\r
46 \r
47 struct S { float f; };\r
48 \r
49 struct T {\r
50         //S;              // Error: anonymous structures disallowed\r
51         //struct { ... }; // Error: embedded structures disallowed\r
52         S s;            // Okay: nested structures with name are allowed\r
53 };\r
54 \r
55 float frequencies[3];   \r
56 uniform vec4 lightPosition[4];\r
57 light lights[];\r
58 const int numLights = 2;\r
59 light lights[numLights];\r
60 \r
61 in vec3 normal;\r
62 centroid in vec2 TexCoord;\r
63 invariant centroid in vec4 Color;\r
64 noperspective in float temperature;\r
65 flat in vec3 myColor;\r
66 noperspective centroid in vec2 myTexCoord;\r
67 \r
68 uniform vec4 lightPosition;\r
69 uniform vec3 color = vec3(0.7, 0.7, 0.2);  // value assigned at link time\r
70 \r
71 in Material {\r
72     smooth in vec4 Color1; // legal, input inside in block\r
73     smooth vec4 Color2;    // legal, 'in' inherited from 'in Material'\r
74     vec2 TexCoordA;        // legal, TexCoord is an input\r
75     uniform float Atten;   // illegal, mismatched  storage qualifier\r
76 \r
77 };\r
78 \r
79 in Light {\r
80     vec4 LightPos;\r
81     vec3 LightColor;\r
82 };\r
83 in ColoredTexture {\r
84     vec4 Color;\r
85     vec2 TexCoord;        \r
86 } Materiala;           // instance name\r
87 vec3 Color;            // different Color than Material.Color\r
88 \r
89 in vec4 gl_FragCoord;     // redeclaration that changes nothing is allowed\r
90 \r
91 // All the following are allowed redeclaration that change behavior\r
92 layout(origin_upper_left) in vec4 gl_FragCoord;\r
93 layout(pixel_center_integer) in vec4 gl_FragCoord;\r
94 layout(origin_upper_left, pixel_center_integer) in vec4 gl_FragCoord;\r
95 \r
96 layout(early_fragment_tests) in;\r
97 \r
98 // compute shader:\r
99 layout (local_size_x = 32, local_size_y = 32) in;\r
100 layout (local_size_x = 8) in;\r
101 \r
102 layout(location = 3) out vec4 color;\r
103 layout(location = 3, index = 1) out vec4 factor;\r
104 layout(location = 2) out vec4 colors[3];\r
105 \r
106 layout (depth_greater) out float gl_FragDepth;\r
107 \r
108 // redeclaration that changes nothing is allowed\r
109 out float gl_FragDepth;\r
110 \r
111 // assume it may be modified in any way\r
112 layout (depth_any) out float gl_FragDepth;\r
113 \r
114 // assume it may be modified such that its value will only increase\r
115 layout (depth_greater) out float gl_FragDepth;\r
116 \r
117 // assume it may be modified such that its value will only decrease\r
118 layout (depth_less) out float gl_FragDepth;\r
119 \r
120 // assume it will not be modified\r
121 layout (depth_unchanged) out float gl_FragDepth;\r
122 \r
123 in vec4 gl_Color;             // predeclared by the fragment language\r
124 flat  in vec4 gl_Color;       // redeclared by user to be flat\r
125 \r
126 \r
127 float[5] foo(float[5]) \r
128 {\r
129     return float[5](3.4, 4.2, 5.0, 5.2, 1.1);\r
130 }\r
131 \r
132 precision highp float;\r
133 precision highp int;\r
134 precision mediump int;\r
135 precision highp float;\r
136 \r
137 void main()\r
138 {\r
139     {\r
140                 float a[5] = float[5](3.4, 4.2, 5.0, 5.2, 1.1);\r
141         }\r
142         {\r
143                 float a[5] = float[](3.4, 4.2, 5.0, 5.2, 1.1);  // same thing\r
144         }\r
145     {\r
146             vec4 a[3][2];  // size-3 array of size-2 array of vec4\r
147                 vec4[2] a1[3];  // size-3 array of size-2 array of vec4\r
148                 vec4[3][2] a2;  // size-3 array of size-2 array of vec4\r
149                 vec4 b[2] = vec4[2](vec4(0.0), vec4(0.1));\r
150                 vec4[3][2] a3 = vec4[3][2](b, b, b);        // constructor\r
151                 void foo(vec4[3][2]);  // prototype with unnamed parameter\r
152                 vec4 a4[3][2] = {vec4[2](vec4(0.0), vec4(1.0)),   \r
153                                                  vec4[2](vec4(0.0), vec4(1.0)),   \r
154                                                  vec4[2](vec4(0.0), vec4(1.0)) };\r
155     }\r
156         {\r
157                 float a[5];\r
158                 {\r
159                         float b[] = a;  // b is explicitly size 5\r
160                 }\r
161                 {\r
162                         float b[5] = a; // means the same thing\r
163                 }\r
164                 {\r
165                         float b[] = float[](1,2,3,4,5);  // also explicitly sizes to 5\r
166                 }\r
167                 a.length();  // returns 5 \r
168         }\r
169     {\r
170                 vec4 a[3][2];\r
171                 a.length();     // this is 3\r
172                 a[x].length();  // this is 2\r
173     }\r
174         // for an array b containing a member array a:\r
175         b[++x].a.length();    // b is never dereferenced, but \93++x\94 is evaluated\r
176 \r
177         // for an array s of a shader storage object containing a member array a:\r
178         s[x].a.length();      // s is dereferenced; x needs to be a valid index\r
179         //\r
180         //All of the following declarations result in a compile-time error.\r
181         //float a[2] = { 3.4, 4.2, 5.0 };         // illegal\r
182         //vec2 b = { 1.0, 2.0, 3.0 };             // illegal\r
183         //mat3x3 c = { vec3(0.0), vec3(1.0), vec3(2.0), vec3(3.0) };    // illegal\r
184         //mat2x2 d = { 1.0, 0.0, 0.0, 1.0 };      // illegal, can't flatten nesting\r
185         //struct {\r
186         //      float a;\r
187         //      int   b;\r
188         //} e = { 1.2, 2, 3 };                    // illegal\r
189 \r
190     struct {\r
191         float a;\r
192         int   b;\r
193     } e = { 1.2, 2 };             // legal, all types match\r
194 \r
195     struct {\r
196         float a;\r
197         int   b;\r
198     } e = { 1, 3 };               // legal, first initializer is converted\r
199 \r
200     //All of the following declarations result in a compile-time error.\r
201     //int a = true;                           // illegal\r
202     //vec4 b[2] = { vec4(0.0), 1.0 };         // illegal\r
203     //mat4x2 c = { vec3(0.0), vec3(1.0) };    // illegal\r
204 \r
205     //struct S1 {\r
206     //    vec4 a;\r
207     //    vec4 b;\r
208     //};\r
209 \r
210     //struct {\r
211     //    float s;\r
212     //    float t;\r
213     //} d[] = { S1(vec4(0.0), vec4(1.1)) };   // illegal\r
214 \r
215     {\r
216         float a[] = float[](3.4, 4.2, 5.0, 5.2, 1.1);\r
217         float b[] = { 3.4, 4.2, 5.0, 5.2, 1.1 };\r
218         float c[] = a;                          // c is explicitly size 5\r
219         float d[5] = b;                         // means the same thing\r
220     }\r
221     {\r
222         const vec3 zAxis = vec3 (0.0, 0.0, 1.0);\r
223         const float ceiling = a + b; // a and b not necessarily constants\r
224     }\r
225     {\r
226         in vec4 position;\r
227         in vec3 normal;\r
228         in vec2 texCoord[4];\r
229     }\r
230     {\r
231         lowp float color;\r
232         out mediump vec2 P;\r
233         lowp ivec2 foo(lowp mat3);\r
234         highp mat4 m;\r
235     }\r
236 \r
237 }\r