[glslang] Refine implicit array size interfaces. (#3074)
[platform/upstream/glslang.git] / Test / 310.vert
1 #version 310 es\r
2 \r
3 shared vec4 s;   // ERROR\r
4 layout(local_size_x = 2) out;  // ERROR\r
5 buffer vec4 v;  // ERROR\r
6 in int ini;\r
7 layout(location = 2) uniform mat4 x;\r
8 layout(location = 3) uniform mat4 y;\r
9 layout(location = 2) out mat4 xi;\r
10 layout(location = 3) out mat4 yi;  // ERROR, locations conflict with xi\r
11 \r
12 void main()\r
13 {\r
14     uvec2 u2;\r
15     u2 = uaddCarry(u2, u2, u2);\r
16     uint u1;\r
17     u1 = usubBorrow(u1, u1, u1);\r
18     uvec4 u4;\r
19     umulExtended(u4, u4, u4, u4);\r
20     ivec4 i4;\r
21     imulExtended(i4, i4, i4, i4);\r
22     int i1;\r
23     i1 = bitfieldExtract(i1, 4, 5);\r
24     uvec3 u3;\r
25     u3 = bitfieldExtract(u3, 4, 5);\r
26     ivec3 i3;\r
27     i3 = bitfieldInsert(i3, i3, 4, 5);\r
28     u1 = bitfieldInsert(u1, u1, 4, 5);\r
29     ivec2 i2;\r
30     i2 = bitfieldReverse(i2);\r
31     u4 = bitfieldReverse(u4);\r
32     i1 = bitCount(i1);\r
33     i3 = bitCount(u3);\r
34     i2 = findLSB(i2);\r
35     i4 = findLSB(u4);\r
36     i1 = findMSB(i1);\r
37     i2 = findMSB(u2);\r
38 \r
39     vec3 v3;\r
40     v3 = frexp(v3, i3);\r
41     vec2 v2;\r
42     v2 = ldexp(v2, i2);\r
43 \r
44     mediump vec4 v4;\r
45     u1 = packUnorm4x8(v4);\r
46     u1 = packSnorm4x8(v4);\r
47     v4 = unpackUnorm4x8(u1);\r
48     v4 = unpackSnorm4x8(u1);\r
49 }\r
50 \r
51 precision highp sampler2DMS;\r
52 precision highp isampler2DMS;\r
53 precision highp usampler2DMS;\r
54 \r
55 uniform sampler2DMS s2dms;\r
56 uniform isampler2DMS is2dms;\r
57 uniform usampler2DMS us2dms;\r
58 uniform usampler2DMSArray us2dmsa;   // ERROR\r
59 \r
60 void foo()\r
61 {\r
62     ivec2 v2;\r
63     v2 = textureSize(s2dms);\r
64     v2 = textureSize(us2dms);\r
65     vec4 v4 = texelFetch(s2dms, v2, 2);\r
66     ivec4 iv4 = texelFetch(is2dms, v2, 2);\r
67     textureSamples(s2dms);   // ERROR\r
68     float f;\r
69     frexp(f, ini);     // ERROR, i not writable\r
70 }\r
71 \r
72 out bool outb;         // ERROR\r
73 out sampler2D outo;    // ERROR\r
74 out float outa[4];\r
75 out float outaa[4][2]; // ERROR\r
76 struct S { float f; };\r
77 out S outs;\r
78 out S[4] outasa;       // ERROR\r
79 out S outsa[4];        // ERROR\r
80 struct SA { float f[4]; };\r
81 out SA outSA;          // ERROR\r
82 struct SS { float f; S s; };\r
83 out SS outSS;          // ERROR\r
84 \r
85 layout(std430) uniform U430 { int a; } U430i;    // ERROR\r
86 layout(std430) buffer B430 { int a; } B430i;\r
87 \r
88 #ifndef GL_OES_shader_io_blocks\r
89 #error GL_OES_shader_io_blocks not defined\r
90 #endif\r
91 \r
92 #extension GL_OES_shader_io_blocks : enable\r
93 \r
94 out outbname {\r
95     int a;\r
96     out vec4 v;\r
97     highp sampler2D s;   // ERROR, opaque type\r
98 } outbinst;\r
99 \r
100 out outbname2 {\r
101     layout(location = 12) int aAnon;\r
102     layout(location = 13) vec4 vAnon;\r
103 };\r
104 \r
105 layout(location = 12) out highp int aliased;  // ERROR, aliasing location\r
106 \r
107 in inbname { int a; } inbinst;  // ERROR, no in block in vertex shader\r
108 \r
109 out gl_PerVertex {              // ERROR, has extra member\r
110     highp vec4 gl_Position;\r
111     highp vec4 t;\r
112 };\r
113 \r
114 void foo_IO()\r
115 {\r
116     int sum  = gl_VertexID +\r
117                gl_InstanceID;\r
118     gl_Position = vec4(1.0);\r
119     gl_PointSize = 2.0;         // ERROR, removed by redeclaration\r
120 }\r
121 \r
122 out gl_PerVertex {              // ERROR, already used and already redeclared\r
123     highp vec4 gl_Position;\r
124     highp vec4 t;\r
125 };\r
126 \r
127 smooth out smo {                // ERROR, no smooth on a block\r
128     int i;\r
129 } smon;\r
130 \r
131 flat out fmo {                  // ERROR, no flat on a block\r
132     int i;\r
133 } fmon;\r
134 \r
135 centroid out cmo {              // ERROR, no centroid on a block\r
136     int i;\r
137 } cmon;\r
138 \r
139 invariant out imo {             // ERROR, no invariant on a block\r
140     int i;\r
141 } imon;\r
142 \r
143 in vec2 inf, ing;\r
144 uniform ivec2 offsets[4];\r
145 uniform sampler2D sArray[4];\r
146 uniform int sIndex;\r
147 layout(binding = 0) uniform atomic_uint auArray[2];\r
148 uniform ubName { int i; } ubInst[4];\r
149 buffer bbName { int i; } bbInst[4];\r
150 highp uniform writeonly image2D iArray[5];\r
151 const ivec2 constOffsets[4] = ivec2[4](ivec2(0.1), ivec2(0.2), ivec2(0.3), ivec2(0.4));\r
152 \r
153 void pfooBad()\r
154 {\r
155     precise vec2 h;          // ERROR reserved\r
156     h = fma(inf, ing, h);    // ERROR, not available\r
157     sArray[sIndex + 1];      // ERRRO, not supported\r
158     auArray[sIndex + 1];\r
159     ubInst[1];\r
160     bbInst[2];\r
161     ubInst[sIndex + 1];      // ERROR, not supported\r
162     bbInst[sIndex];          // ERROR, not supported\r
163     iArray[2];\r
164     iArray[sIndex * 2];      // ERROR, not supported\r
165     textureGatherOffset(sArray[0], vec2(0.1), ivec2(inf));     // ERROR, offset not constant\r
166     textureGatherOffsets(sArray[0], vec2(0.1), constOffsets);  // ERROR, not available\r
167 }\r
168 \r
169 #extension GL_OES_gpu_shader5 : enable\r
170 \r
171 void pfoo()\r
172 {\r
173     precise vec2 h;\r
174     h = fma(inf, ing, h);\r
175     sArray[sIndex + 1];\r
176     ubInst[sIndex + 1];\r
177     bbInst[sIndex - 2];      // ERROR, still not supported\r
178     iArray[2];\r
179     iArray[sIndex - 2];\r
180     textureGatherOffset(sArray[0], vec2(0.1), ivec2(inf));\r
181     textureGatherOffsets(sArray[0], vec2(0.1), constOffsets);\r
182     textureGatherOffsets(sArray[0], vec2(0.1), offsets);   // ERROR, offset not constant\r
183 }\r
184 \r
185 uniform samplerBuffer  badSamp1;             // ERROR, reserved\r
186 uniform isamplerBuffer badSamp2;             // ERROR, reserved\r
187 uniform usamplerBuffer badSamp3;             // ERROR, reserved\r
188 uniform writeonly imageBuffer    badSamp4;   // ERROR, reserved\r
189 uniform writeonly iimageBuffer   badSamp5;   // ERROR, reserved\r
190 uniform writeonly uimageBuffer   badSamp6;   // ERROR, reserved\r
191 \r
192 #extension GL_OES_texture_buffer : enable\r
193 #extension GL_EXT_texture_buffer : enable\r
194 \r
195 uniform samplerBuffer  noPreSamp1;            // ERROR, no default precision\r
196 uniform isamplerBuffer noPreSamp2;            // ERROR, no default precision\r
197 uniform usamplerBuffer noPreSamp3;            // ERROR, no default precision\r
198 uniform writeonly imageBuffer    noPreSamp4;  // ERROR, no default precision\r
199 uniform writeonly iimageBuffer   noPreSamp5;  // ERROR, no default precision\r
200 uniform writeonly uimageBuffer   noPreSamp6;  // ERROR, no default precision\r
201 \r
202 precision highp samplerBuffer; \r
203 precision highp isamplerBuffer;\r
204 precision highp usamplerBuffer;\r
205 precision highp imageBuffer;   \r
206 precision highp iimageBuffer;  \r
207 precision highp uimageBuffer;  \r
208 \r
209 #ifdef GL_OES_texture_buffer\r
210 uniform samplerBuffer  bufSamp1;          \r
211 uniform isamplerBuffer bufSamp2;          \r
212 uniform usamplerBuffer bufSamp3;          \r
213 #endif\r
214 #ifdef GL_EXT_texture_buffer\r
215 uniform writeonly imageBuffer    bufSamp4;\r
216 uniform writeonly iimageBuffer   bufSamp5;\r
217 uniform writeonly uimageBuffer   bufSamp6;\r
218 #endif\r
219 \r
220 void bufferT()\r
221 {\r
222     highp int s1 = textureSize(bufSamp1);\r
223     highp int s2 = textureSize(bufSamp2);\r
224     highp int s3 = textureSize(bufSamp3);\r
225 \r
226     highp int s4 = imageSize(bufSamp4);\r
227     highp int s5 = imageSize(bufSamp5);\r
228     highp int s6 = imageSize(bufSamp6);\r
229     \r
230     highp vec4 f1 = texelFetch(bufSamp1, s1);\r
231     highp ivec4 f2 = texelFetch(bufSamp2, s2);\r
232     highp uvec4 f3 = texelFetch(bufSamp3, s3);\r
233 }\r
234 \r
235 uniform writeonly imageCubeArray  badCA1;  // ERROR, reserved\r
236 uniform writeonly iimageCubeArray badCA2;  // ERROR, reserved\r
237 uniform writeonly uimageCubeArray badCA3;  // ERROR, reserved\r
238 \r
239 uniform samplerCubeArray          badCA4;  // ERROR, reserved\r
240 uniform samplerCubeArrayShadow    badCA5;  // ERROR, reserved\r
241 uniform isamplerCubeArray         badCA6;  // ERROR, reserved\r
242 uniform usamplerCubeArray         badCA7;  // ERROR, reserved\r
243 \r
244 #extension GL_OES_texture_cube_map_array : enable\r
245 \r
246 uniform writeonly imageCubeArray  noPreCA1;   // ERROR, no default precision\r
247 uniform writeonly iimageCubeArray noPreCA2;   // ERROR, no default precision\r
248 uniform writeonly uimageCubeArray noPreCA3;   // ERROR, no default precision\r
249 \r
250 uniform samplerCubeArray          noPreCA4;   // ERROR, no default precision\r
251 uniform samplerCubeArrayShadow    noPreCA5;   // ERROR, no default precision\r
252 uniform isamplerCubeArray         noPreCA6;   // ERROR, no default precision\r
253 uniform usamplerCubeArray         noPreCA7;   // ERROR, no default precision\r
254 \r
255 precision highp imageCubeArray        ;\r
256 precision highp iimageCubeArray       ;\r
257 precision highp uimageCubeArray       ;\r
258 \r
259 precision highp samplerCubeArray      ;\r
260 precision highp samplerCubeArrayShadow;\r
261 precision highp isamplerCubeArray     ;\r
262 precision highp usamplerCubeArray     ;\r
263 \r
264 uniform writeonly imageCubeArray  CA1;\r
265 uniform writeonly iimageCubeArray CA2;\r
266 uniform writeonly uimageCubeArray CA3;\r
267 \r
268 layout(rgba16f) uniform readonly imageCubeArray  rCA1;\r
269 layout(rgba32i) uniform readonly iimageCubeArray rCA2;\r
270 layout(r32ui) uniform readonly uimageCubeArray rCA3;\r
271 \r
272 #ifdef GL_OES_texture_cube_map_array\r
273 uniform samplerCubeArray          CA4;\r
274 uniform samplerCubeArrayShadow    CA5;\r
275 uniform isamplerCubeArray         CA6;\r
276 uniform usamplerCubeArray         CA7;\r
277 #endif\r
278 \r
279 void CAT()\r
280 {\r
281     highp ivec3 s4 = textureSize(CA4, 1);\r
282     highp ivec3 s5 = textureSize(CA5, 1);\r
283     highp ivec3 s6 = textureSize(CA6, 1);\r
284     highp ivec3 s7 = textureSize(CA7, 1);\r
285     \r
286     highp vec4 t4 = texture(CA4, vec4(0.5));\r
287     highp float t5 = texture(CA5, vec4(0.5), 3.0);\r
288     highp ivec4 t6 = texture(CA6, vec4(0.5));\r
289     highp uvec4 t7 = texture(CA7, vec4(0.5));\r
290 \r
291     highp vec4 L4 = textureLod(CA4, vec4(0.5), 0.24);\r
292     highp ivec4 L6 = textureLod(CA6, vec4(0.5), 0.26);\r
293     highp uvec4 L7 = textureLod(CA7, vec4(0.5), 0.27);\r
294 \r
295     highp vec4 g4 = textureGrad(CA4, vec4(0.5), vec3(0.1), vec3(0.2));\r
296     highp ivec4 g6 = textureGrad(CA6, vec4(0.5), vec3(0.1), vec3(0.2));\r
297     highp uvec4 g7 = textureGrad(CA7, vec4(0.5), vec3(0.1), vec3(0.2));\r
298 \r
299     highp vec4 gath4 = textureGather(CA4, vec4(0.5));\r
300     highp vec4 gathC4 = textureGather(CA4, vec4(0.5), 2);\r
301     highp ivec4 gath6 = textureGather(CA6, vec4(0.5));\r
302     highp ivec4 gathC6 = textureGather(CA6, vec4(0.5), 1);\r
303     highp uvec4 gath7 = textureGather(CA7, vec4(0.5));\r
304     highp uvec4 gathC7 = textureGather(CA7, vec4(0.5), 0);\r
305 \r
306     highp vec4 gath5 = textureGather(CA5, vec4(0.5), 2.5);\r
307 \r
308     highp ivec3 s1 = imageSize(CA1);\r
309     highp ivec3 s2 = imageSize(CA2);\r
310     highp ivec3 s3 = imageSize(CA3);\r
311 \r
312     imageStore(CA1, s3, vec4(1));\r
313     imageStore(CA2, s3, ivec4(1));\r
314     imageStore(CA3, s3, uvec4(1));\r
315 \r
316     highp vec4 cl1 = imageLoad(rCA1, s3);\r
317     highp ivec4 cl2 = imageLoad(rCA2, s3);\r
318     highp uvec4 cl3 = imageLoad(rCA3, s3);\r
319 }\r
320 \r
321 uniform sampler2DMSArray  bad2DMS;    // ERROR, reserved\r
322 uniform isampler2DMSArray bad2DMSi;   // ERROR, reserved\r
323 uniform usampler2DMSArray bad2DMSu;   // ERROR, reserved\r
324 \r
325 #extension GL_OES_texture_storage_multisample_2d_array : enable\r
326 \r
327 #ifdef GL_OES_texture_storage_multisample_2d_array\r
328 \r
329 uniform sampler2DMSArray  noPrec2DMS;    // ERROR, no default\r
330 uniform isampler2DMSArray noPrec2DMSi;   // ERROR, no default\r
331 uniform usampler2DMSArray noPrec2DMSu;   // ERROR, no default\r
332 \r
333 #endif\r
334 \r
335 precision highp sampler2DMSArray;\r
336 precision highp isampler2DMSArray;\r
337 precision highp usampler2DMSArray;\r
338 \r
339 uniform sampler2DMSArray  samp2DMSA;\r
340 uniform isampler2DMSArray samp2DMSAi;\r
341 uniform usampler2DMSArray samp2DMSAu;\r
342 \r
343 void MSA()\r
344 {\r
345     vec4 tf = texelFetch(samp2DMSA, ivec3(5), 2);\r
346     ivec4 tfi = texelFetch(samp2DMSAi, ivec3(5), 2);\r
347     uvec4 tfu = texelFetch(samp2DMSAu, ivec3(5), 2);\r
348     \r
349     ivec3 tfs = textureSize(samp2DMSA);\r
350     ivec3 tfsi = textureSize(samp2DMSAi);\r
351     ivec3 tfsb = textureSize(samp2DMSAi, 4);  // ERROR, no lod\r
352     ivec3 tfsu = textureSize(samp2DMSAu);\r
353 }\r
354 \r
355 #ifdef GL_OES_shader_image_atomic \r
356 #extension GL_OES_shader_image_atomic : enable\r
357 #endif\r
358 \r
359 uniform layout(r32f)  highp  image2D im2Df;\r
360 uniform layout(r32ui) highp uimage2D im2Du;\r
361 uniform layout(r32i)  highp iimage2D im2Di;\r
362 uniform ivec2 P;\r
363 \r
364 void goodImageAtom()\r
365 {\r
366     float datf;\r
367     int dati;\r
368     uint datu;\r
369 \r
370     imageAtomicAdd(     im2Di, P, dati);
371     imageAtomicAdd(     im2Du, P, datu);
372     imageAtomicMin(     im2Di, P, dati);
373     imageAtomicMin(     im2Du, P, datu);
374     imageAtomicMax(     im2Di, P, dati);
375     imageAtomicMax(     im2Du, P, datu);
376     imageAtomicAnd(     im2Di, P, dati);
377     imageAtomicAnd(     im2Du, P, datu);
378     imageAtomicOr(      im2Di, P, dati);
379     imageAtomicOr(      im2Du, P, datu);
380     imageAtomicXor(     im2Di, P, dati);
381     imageAtomicXor(     im2Du, P, datu);
382     imageAtomicExchange(im2Di, P, dati);
383     imageAtomicExchange(im2Du, P, datu);
384     imageAtomicExchange(im2Df, P, datf);
385     imageAtomicCompSwap(im2Di, P,  3, dati);\r
386     imageAtomicCompSwap(im2Du, P, 5u, datu);\r
387 }\r
388 \r
389 sample out vec4 colorSampInBad;       // ERROR, reserved\r
390 \r
391 #extension GL_OES_shader_multisample_interpolation : enable\r
392 \r
393 sample out vec4 colorSample;\r
394 flat sample out vec4 colorfsi;\r
395 sample out vec3 sampInArray[4];\r
396 in vec4 inv4;\r
397 \r
398 void badInterp()\r
399 {\r
400     interpolateAtCentroid(inv4);             // ERROR, wrong stage\r
401     interpolateAtSample(inv4, 1);            // ERROR, need extension\r
402     interpolateAtOffset(inv4, vec2(0.2));    // ERROR, need extension\r
403 }\r