2 # Copyright © 2019 Google
4 # Permission is hereby granted, free of charge, to any person obtaining a copy
5 # of this software and associated documentation files (the "Software"), to deal
6 # in the Software without restriction, including without limitation the rights
7 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 # copies of the Software, and to permit persons to whom the Software is
9 # furnished to do so, subject to the following conditions:
11 # The above copyright notice and this permission notice shall be included in
12 # all copies or substantial portions of the Software.
14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 from __future__
import print_function
27 from collections
import namedtuple
30 Test
= namedtuple("Test", "name source match_re")
34 Test("f32 simple division",
36 uniform mediump float a, b;
40 gl_FragColor.rgba = vec4(a / b);
43 r
'\(expression +float16_t +/'),
44 Test("i32 simple division",
47 precision mediump float;
48 precision mediump int;
49 uniform mediump int a, b;
58 r
'\(expression +int16_t +/'),
59 Test("u32 simple division",
62 precision mediump float;
63 precision mediump int;
64 uniform mediump uint a, b;
73 r
'\(expression +uint16_t +/'),
76 uniform mediump vec2 a, b;
80 gl_FragColor.rgba = vec4(dot(a, b));
83 r
'\(expression +float16_t +dot\b'),
84 Test("f32 array with const index",
86 precision mediump float;
88 uniform float in_simple[2];
92 gl_FragColor = vec4(in_simple[0] / in_simple[1]);
95 r
'\(expression +float16_t +/'),
96 Test("i32 array with const index",
99 precision mediump float;
100 precision mediump int;
102 uniform int in_simple[2];
108 color = vec4(in_simple[0] / in_simple[1]);
111 r
'\(expression +int16_t +/'),
112 Test("u32 array with const index",
115 precision mediump float;
116 precision mediump int;
118 uniform uint in_simple[2];
124 color = vec4(in_simple[0] / in_simple[1]);
127 r
'\(expression +uint16_t +/'),
128 Test("f32 array with uniform index",
130 precision mediump float;
132 uniform float in_simple[2];
137 gl_FragColor = vec4(in_simple[i0] / in_simple[i1]);
140 r
'\(expression +float16_t +/'),
141 Test("i32 array with uniform index",
144 precision mediump float;
145 precision mediump int;
147 uniform int in_simple[2];
154 color = vec4(in_simple[i0] / in_simple[i1]);
157 r
'\(expression +int16_t +/'),
158 Test("u32 array with uniform index",
161 precision mediump float;
162 precision mediump int;
164 uniform uint in_simple[2];
171 color = vec4(in_simple[i0] / in_simple[i1]);
174 r
'\(expression +uint16_t +/'),
175 Test("f32 array-of-array with const index",
178 precision mediump float;
180 uniform float in_aoa[2][2];
182 layout(location = 0) out float out_color;
186 out_color = in_aoa[0][0] / in_aoa[1][1];
189 r
'\(expression +float16_t +/'),
190 Test("i32 array-of-array with const index",
193 precision mediump float;
194 precision mediump int;
196 uniform int in_aoa[2][2];
198 layout(location = 0) out highp int out_color;
202 out_color = in_aoa[0][0] / in_aoa[1][1];
205 r
'\(expression +int16_t +/'),
206 Test("u32 array-of-array with const index",
209 precision mediump float;
210 precision mediump int;
212 uniform uint in_aoa[2][2];
214 layout(location = 0) out highp uint out_color;
218 out_color = in_aoa[0][0] / in_aoa[1][1];
221 r
'\(expression +uint16_t +/'),
222 Test("f32 array-of-array with uniform index",
225 precision mediump float;
227 uniform float in_aoa[2][2];
230 layout(location = 0) out float out_color;
234 out_color = in_aoa[i0][i0] / in_aoa[i1][i1];
237 r
'\(expression +float16_t +/'),
238 Test("i32 array-of-array with uniform index",
241 precision mediump float;
242 precision mediump int;
244 uniform int in_aoa[2][2];
247 layout(location = 0) out highp int out_color;
251 out_color = in_aoa[i0][i0] / in_aoa[i1][i1];
254 r
'\(expression +int16_t +/'),
255 Test("u32 array-of-array with uniform index",
258 precision mediump float;
259 precision mediump int;
261 uniform uint in_aoa[2][2];
264 layout(location = 0) out highp uint out_color;
268 out_color = in_aoa[i0][i0] / in_aoa[i1][i1];
271 r
'\(expression +uint16_t +/'),
272 Test("f32 array index",
274 uniform mediump float a, b;
275 uniform mediump float values[2];
279 gl_FragColor.rgba = vec4(values[int(a / b)]);
282 r
'\(expression +float16_t +/'),
283 Test("i32 array index",
286 precision mediump float;
287 precision mediump int;
289 uniform mediump int a, b;
290 uniform mediump int values[2];
296 color = values[a / b];
299 r
'\(expression +int16_t +/'),
302 precision mediump float;
320 gl_FragColor = vec4(get_a() / get_b());
323 r
'\(expression +float16_t +/'),
327 precision mediump float;
328 precision mediump int;
348 color = get_a() / get_b();
351 r
'\(expression +int16_t +/'),
355 precision mediump float;
356 precision mediump int;
372 out highp uint color;
376 color = get_a() / get_b();
379 r
'\(expression +uint16_t +/'),
380 Test("f32 function mediump args",
382 precision mediump float;
387 do_div(float x, float y)
394 gl_FragColor = vec4(do_div(a, b));
397 r
'\(expression +float16_t +/'),
398 Test("i32 function mediump args",
401 precision mediump float;
402 precision mediump int;
416 color = do_div(a, b);
419 r
'\(expression +int16_t +/'),
420 Test("u32 function mediump args",
423 precision mediump float;
424 precision mediump int;
429 do_div(uint x, uint y)
434 out highp uint color;
438 color = do_div(a, b);
441 r
'\(expression +uint16_t +/'),
442 Test("f32 function highp args",
444 precision mediump float;
449 do_div(highp float x, highp float y)
456 gl_FragColor = vec4(do_div(a, b));
459 r
'\(expression +float +/'),
460 Test("i32 function highp args",
463 precision mediump float;
464 precision mediump int;
469 do_div(highp int x, highp int y)
478 color = do_div(a, b);
481 r
'\(expression +int +/'),
482 Test("u32 function highp args",
485 precision mediump float;
486 precision mediump int;
491 do_div(highp uint x, highp uint y)
496 out highp uint color;
500 color = do_div(a, b);
503 r
'\(expression +uint +/'),
504 Test("f32 function inout different precision highp",
506 uniform mediump float a, b;
509 do_div(inout highp float x, highp float y)
516 mediump float temp = a;
518 gl_FragColor = vec4(temp);
521 r
'\(expression +float +/'),
522 Test("i32 function inout different precision highp",
525 uniform mediump int a, b;
528 do_div(inout highp int x, highp int y)
533 out mediump int color;
537 mediump int temp = a;
542 r
'\(expression +int +/'),
543 Test("u32 function inout different precision highp",
546 uniform mediump uint a, b;
549 do_div(inout highp uint x, highp uint y)
554 out mediump uint color;
558 mediump uint temp = a;
563 r
'\(expression +uint +/'),
564 Test("f32 function inout different precision mediump",
566 uniform highp float a, b;
569 do_div(inout mediump float x, mediump float y)
576 highp float temp = a;
578 gl_FragColor = vec4(temp);
581 r
'\(expression +float16_t +/'),
582 Test("i32 function inout different precision mediump",
585 uniform highp int a, b;
590 do_div(inout mediump int x, mediump int y)
602 r
'\(expression +int16_t +/'),
603 Test("u32 function inout different precision mediump",
606 uniform highp uint a, b;
608 out highp uint color;
611 do_div(inout mediump uint x, mediump uint y)
623 r
'\(expression +uint16_t +/'),
626 precision mediump float;
634 gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);
636 gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
639 r
'\(expression +float16_t +/'),
643 precision mediump float;
644 precision mediump int;
654 color = vec4(0.0, 1.0, 0.0, 1.0);
656 color = vec4(1.0, 0.0, 0.0, 1.0);
659 r
'\(expression +int16_t +/'),
663 precision mediump float;
664 precision mediump int;
674 color = vec4(0.0, 1.0, 0.0, 1.0);
676 color = vec4(1.0, 0.0, 0.0, 1.0);
679 r
'\(expression +uint16_t +/'),
682 precision mediump float;
689 gl_FragColor = vec4(b * a, 0.0, 0.0);
692 r
'\(expression +f16vec2 \*.*\bf16mat2\b'),
693 Test("f32 simple struct deref",
695 precision mediump float;
701 uniform simple in_simple;
705 gl_FragColor = vec4(in_simple.a / in_simple.b);
708 r
'\(expression +float16_t +/'),
709 Test("i32 simple struct deref",
712 precision mediump float;
713 precision mediump int;
719 uniform simple in_simple;
725 color = in_simple.a / in_simple.b;
728 r
'\(expression +int16_t +/'),
729 Test("u32 simple struct deref",
732 precision mediump float;
733 precision mediump int;
739 uniform simple in_simple;
741 out highp uint color;
745 color = in_simple.a / in_simple.b;
748 r
'\(expression +uint16_t +/'),
749 Test("f32 embedded struct deref",
751 precision mediump float;
761 uniform embedded in_embedded;
765 gl_FragColor = vec4(in_embedded.a.a / in_embedded.b.b);
768 r
'\(expression +float16_t +/'),
769 Test("i32 embedded struct deref",
772 precision mediump float;
773 precision mediump int;
783 uniform embedded in_embedded;
789 color = in_embedded.a.a / in_embedded.b.b;
792 r
'\(expression +int16_t +/'),
793 Test("u32 embedded struct deref",
796 precision mediump float;
797 precision mediump int;
807 uniform embedded in_embedded;
809 out highp uint color;
813 color = in_embedded.a.a / in_embedded.b.b;
816 r
'\(expression +uint16_t +/'),
817 Test("f32 arrayed struct deref",
819 precision mediump float;
829 uniform arrayed in_arrayed;
833 gl_FragColor = vec4(in_arrayed.a[0].a / in_arrayed.a[1].b);
836 r
'\(expression +float16_t +/'),
837 Test("i32 arrayed struct deref",
840 precision mediump float;
841 precision mediump int;
851 uniform arrayed in_arrayed;
857 color = in_arrayed.a[0].a / in_arrayed.a[1].b;
860 r
'\(expression +int16_t +/'),
861 Test("u32 arrayed struct deref",
864 precision mediump float;
865 precision mediump int;
875 uniform arrayed in_arrayed;
877 out highp uint color;
881 color = in_arrayed.a[0].a / in_arrayed.a[1].b;
884 r
'\(expression +uint16_t +/'),
885 Test("f32 mixed precision not lowered",
887 uniform mediump float a;
888 uniform highp float b;
892 gl_FragColor = vec4(a / b);
895 r
'\(expression +float +/'),
896 Test("i32 mixed precision not lowered",
899 uniform mediump int a;
902 out mediump int color;
909 r
'\(expression +int +/'),
910 Test("u32 mixed precision not lowered",
913 uniform mediump uint a;
914 uniform highp uint b;
916 out mediump uint color;
923 r
'\(expression +uint +/'),
924 Test("f32 sampler array",
927 precision mediump float;
928 precision mediump int;
930 uniform sampler2D tex[2];
931 // highp shouldn't affect the return value of texture2D
932 uniform highp vec2 coord;
933 uniform float divisor;
936 out highp vec4 color;
940 color = texture2D(tex[index], coord) / divisor;
943 r
'\(expression +f16vec4 +/.*\(tex +f16vec4 +'),
944 Test("f32 texture sample",
946 precision mediump float;
948 uniform sampler2D tex;
949 // highp shouldn't affect the return value of texture2D
950 uniform highp vec2 coord;
951 uniform float divisor;
955 gl_FragColor = texture2D(tex, coord) / divisor;
958 r
'\(expression +f16vec4 +/.*\(tex +f16vec4 +'),
959 Test("i32 texture sample",
962 precision mediump float;
963 precision mediump int;
965 uniform mediump isampler2D tex;
966 // highp shouldn't affect the return value of texture
967 uniform highp vec2 coord;
970 out highp ivec4 color;
974 color = texture(tex, coord) / divisor;
977 r
'\(expression +i16vec4 +/.*\(tex +i16vec4 +'),
978 Test("u32 texture sample",
981 precision mediump float;
982 precision mediump int;
984 uniform mediump usampler2D tex;
985 // highp shouldn't affect the return value of texture
986 uniform highp vec2 coord;
987 uniform uint divisor;
989 out highp uvec4 color;
993 color = texture(tex, coord) / divisor;
996 r
'\(expression +u16vec4 +/.*\(tex +u16vec4 +'),
997 Test("f32 image array",
1000 precision mediump float;
1002 layout(rgba16f) readonly uniform mediump image2D img[2];
1003 // highp shouldn't affect the return value of imageLoad
1004 uniform highp ivec2 coord;
1005 uniform float divisor;
1007 out highp vec4 color;
1011 color = imageLoad(img[1], coord) / divisor;
1014 r
'\(expression +f16vec4 +/'),
1015 Test("f32 image load",
1018 precision mediump float;
1019 precision mediump int;
1021 layout(rgba16f) readonly uniform mediump image2D img;
1022 // highp shouldn't affect the return value of imageLoad
1023 uniform highp ivec2 coord;
1024 uniform float divisor;
1026 out highp vec4 color;
1030 color = imageLoad(img, coord) / divisor;
1033 r
'\(expression +f16vec4 +/'),
1034 Test("i32 image load",
1037 precision mediump float;
1038 precision mediump int;
1040 layout(rgba16i) readonly uniform mediump iimage2D img;
1041 // highp shouldn't affect the return value of imageLoad
1042 uniform highp ivec2 coord;
1043 uniform int divisor;
1045 out highp ivec4 color;
1049 color = imageLoad(img, coord) / divisor;
1052 r
'\(expression +i16vec4 +/'),
1053 Test("u32 image load",
1056 precision mediump float;
1057 precision mediump int;
1059 layout(rgba16ui) readonly uniform mediump uimage2D img;
1060 // highp shouldn't affect the return value of imageLoad
1061 uniform highp ivec2 coord;
1062 uniform uint divisor;
1064 out highp uvec4 color;
1068 color = imageLoad(img, coord) / divisor;
1071 r
'\(expression +u16vec4 +/'),
1072 Test("f32 expression in lvalue",
1074 uniform mediump float a, b;
1078 gl_FragColor = vec4(1.0);
1079 gl_FragColor[int(a / b)] = 0.5;
1082 r
'\(expression +float16_t +/'),
1083 Test("i32 expression in lvalue",
1086 precision mediump float;
1087 precision mediump int;
1089 uniform mediump int a, b;
1099 r
'\(expression +int16_t +/'),
1100 Test("f32 builtin with const arg",
1102 uniform mediump float a;
1106 gl_FragColor = vec4(min(a, 3.0));
1109 r
'\(expression +float16_t min'),
1110 Test("i32 builtin with const arg",
1113 uniform mediump int a;
1115 out highp int color;
1122 r
'\(expression +int16_t min'),
1123 Test("u32 builtin with const arg",
1126 uniform mediump uint a;
1128 out highp uint color;
1135 r
'\(expression +uint16_t min'),
1139 precision mediump float;
1149 r
'\(expression +f16vec4 +dFdx +\(expression +f16vec4'),
1153 precision mediump float;
1163 r
'\(expression +f16vec4 +dFdy +\(expression +f16vec4'),
1167 precision mediump float;
1168 precision mediump int;
1170 uniform mediump sampler2D tex;
1175 color = textureSize(tex, 0) * ivec2(2);
1178 r
'expression ivec2 \* \(txs ivec2 \(var_ref tex'),
1179 Test("floatBitsToInt",
1182 precision mediump float;
1183 precision mediump int;
1190 color = floatBitsToInt(val + 1.0) + 1;
1193 r
'expression int bitcast_f2i \(expression float'),
1194 Test("floatBitsToUint",
1197 precision mediump float;
1198 precision mediump int;
1205 color = floatBitsToUint(val + 1.0) + 1u;
1208 r
'expression uint bitcast_f2u \(expression float'),
1209 Test("intBitsToFloat",
1212 precision mediump float;
1213 precision mediump int;
1220 color = intBitsToFloat(val + 1) + 1.0;
1223 r
'expression float bitcast_i2f \(expression int'),
1224 Test("uintBitsToFloat",
1227 precision mediump float;
1228 precision mediump int;
1235 color = uintBitsToFloat(val + 1u) + 1.0;
1238 r
'expression float bitcast_u2f \(expression uint'),
1239 Test("bitfieldReverse",
1242 precision mediump float;
1243 precision mediump int;
1250 color = bitfieldReverse(val + 1) + 1;
1253 r
'expression int bitfield_reverse \(expression int'),
1257 precision mediump float;
1258 precision mediump int;
1267 float x = frexp(val + 1.0, y);
1272 r
'assign \(x\) \(var_ref x\) \(expression float f162f'),
1276 precision mediump float;
1277 precision mediump int;
1285 color = ldexp(val + 1.0, exp + 1) + 1.0;
1288 r
'expression float ldexp \(expression float'),
1292 precision mediump float;
1293 precision mediump int;
1301 color = uaddCarry(x * 2u, y * 2u, carry) * 2u;
1305 r
'expression uint \+ \(var_ref x\) \(var_ref y'),
1309 precision mediump float;
1310 precision mediump int;
1318 color = usubBorrow(x * 2u, y * 2u, borrow) * 2u;
1322 r
'expression uint \+ \(var_ref x\) \(expression uint neg'),
1323 Test("imulExtended",
1326 precision mediump float;
1327 precision mediump int;
1335 imulExtended(x + 2, y + 2, msb, lsb);
1339 r
'expression int64_t \* \(expression int'),
1340 Test("umulExtended",
1343 precision mediump float;
1344 precision mediump int;
1352 umulExtended(x + 2u, y + 2u, msb, lsb);
1356 r
'expression uint64_t \* \(expression uint'),
1357 Test("unpackUnorm2x16",
1360 precision mediump float;
1361 precision mediump int;
1368 color = unpackUnorm2x16(val + 1u) + vec2(1.0);
1371 r
'expression vec2 unpackUnorm2x16 \(expression uint'),
1372 Test("unpackSnorm2x16",
1375 precision mediump float;
1376 precision mediump int;
1383 color = unpackSnorm2x16(val + 1u) + vec2(1.0);
1386 r
'expression vec2 unpackSnorm2x16 \(expression uint'),
1387 Test("packUnorm2x16",
1390 precision mediump float;
1391 precision mediump int;
1398 color = packUnorm2x16(val + vec2(1.0)) + 1u;
1401 r
'expression uint packUnorm2x16 \(expression vec2'),
1402 Test("packSnorm2x16",
1405 precision mediump float;
1406 precision mediump int;
1413 color = packSnorm2x16(val + vec2(1.0)) + 1u;
1416 r
'expression uint packSnorm2x16 \(expression vec2'),
1417 Test("packHalf2x16",
1420 precision mediump float;
1421 precision mediump int;
1428 color = packHalf2x16(val + vec2(1.0)) + 1u;
1431 r
'expression uint packHalf2x16 \(expression vec2'),
1432 Test("packUnorm4x8",
1435 precision mediump float;
1436 precision mediump int;
1443 color = packUnorm4x8(val + vec4(1.0)) + 1u;
1446 r
'expression uint packUnorm4x8 \(expression vec4'),
1447 Test("packSnorm4x8",
1450 precision mediump float;
1451 precision mediump int;
1458 color = packSnorm4x8(val + vec4(1.0)) + 1u;
1461 r
'expression uint packSnorm4x8 \(expression vec4'),
1462 Test("interpolateAtCentroid",
1465 precision mediump float;
1466 precision mediump int;
1473 color = interpolateAtCentroid(val) + 1.0;
1476 r
'expression float16_t interpolate_at_centroid \(expression float16_t'),
1477 Test("interpolateAtOffset",
1480 precision mediump float;
1481 precision mediump int;
1483 uniform highp vec2 offset;
1489 color = interpolateAtOffset(val, offset) + 1.0;
1492 r
'expression float16_t interpolate_at_offset \(expression float16_t'),
1493 Test("interpolateAtSample",
1496 precision mediump float;
1497 precision mediump int;
1499 uniform highp int sample_index;
1505 color = interpolateAtSample(val, sample_index) + 1.0;
1508 r
'expression float16_t interpolate_at_sample \(expression float16_t'),
1509 Test("bitfieldExtract",
1512 precision mediump float;
1513 precision mediump int;
1515 uniform highp int offset, bits;
1521 color = bitfieldExtract(val, offset, bits) + 1;
1524 r
'expression int16_t bitfield_extract \(expression int16_t'),
1525 Test("bitfieldInsert",
1528 precision mediump float;
1529 precision mediump int;
1531 uniform highp int offset, bits;
1532 uniform int val, val2;
1537 color = bitfieldInsert(val, val2, offset, bits) + 1;
1540 r
'expression int16_t bitfield_insert \(expression int16_t'),
1544 precision mediump float;
1545 precision mediump int;
1547 uniform highp int val;
1552 color = bitCount(val) + 1;
1555 r
'expression int16_t \+ \(expression int16_t i2imp \(expression int bit_count \(var_ref val'),
1559 precision mediump float;
1560 precision mediump int;
1562 uniform highp int val;
1567 color = findLSB(val) + 1;
1570 r
'expression int16_t \+ \(expression int16_t i2imp \(expression int find_lsb \(var_ref val'),
1574 precision mediump float;
1575 precision mediump int;
1577 uniform highp int val;
1582 color = findMSB(val) + 1;
1585 r
'expression int16_t \+ \(expression int16_t i2imp \(expression int find_msb \(var_ref val'),
1586 Test("unpackHalf2x16",
1589 precision mediump float;
1590 precision mediump int;
1592 uniform highp uint val;
1597 color = unpackHalf2x16(val) + vec2(1.0);
1600 r
'expression f16vec2 \+ \(expression f16vec2 f2fmp \(expression vec2 unpackHalf2x16 \(var_ref val'),
1601 Test("unpackUnorm4x8",
1604 precision mediump float;
1605 precision mediump int;
1607 uniform highp uint val;
1612 color = unpackUnorm4x8(val) + vec4(1.0);
1615 r
'expression f16vec4 \+ \(expression f16vec4 f2fmp \(expression vec4 unpackUnorm4x8 \(var_ref val'),
1616 Test("unpackSnorm4x8",
1619 precision mediump float;
1620 precision mediump int;
1622 uniform highp uint val;
1627 color = unpackSnorm4x8(val) + vec4(1.0);
1630 r
'expression f16vec4 \+ \(expression f16vec4 f2fmp \(expression vec4 unpackSnorm4x8 \(var_ref val'),
1634 precision mediump float;
1641 color = (var.x > var.y) ? var : vec4(10.0);
1644 r
'\(constant +f16vec4 \(10'),
1648 precision mediump int;
1655 color = (var.x > var.y) ? var : ivec4(10);
1658 r
'\(constant +i16vec4 \(10'),
1662 precision mediump int;
1669 color = (var.x > var.y) ? var : uvec4(10);
1672 r
'\(constant +u16vec4 \(10'),
1673 Test("f32 loop counter",
1676 precision mediump float;
1678 uniform float n, incr;
1684 for (float x = 0.0; x < n; x += incr)
1688 r
'\(assign \(x\) \(var_ref x\) \(expression float16_t \+ \(var_ref x\) \(expression float16_t f2fmp \(var_ref incr'),
1689 Test("i32 loop counter",
1692 precision mediump float;
1693 precision mediump int;
1695 uniform int n, incr;
1701 for (int x = 0; x < n; x += incr)
1705 r
'\(assign \(x\) \(var_ref x\) \(expression int16_t \+ \(var_ref x\) \(expression int16_t i2imp \(var_ref incr'),
1706 Test("u32 loop counter",
1709 precision mediump float;
1710 precision mediump int;
1712 uniform uint n, incr;
1718 for (uint x = 0u; x < n; x += incr)
1722 r
'\(assign \(x\) \(var_ref x\) \(expression uint16_t \+ \(var_ref x\) \(expression uint16_t u2ump \(var_ref incr'),
1723 Test("f32 temp array",
1726 precision mediump float;
1733 float a[2] = float[2](x, y);
1736 color = a[0] + a[1];
1739 r
'\(constant float16_t \(3'),
1740 Test("i32 temp array",
1743 precision mediump int;
1750 int a[2] = int[2](x, y);
1753 color = a[0] + a[1];
1756 r
'\(constant int16_t \(3'),
1757 Test("u32 temp array",
1760 precision mediump int;
1767 uint a[2] = uint[2](x, y);
1770 color = a[0] + a[1];
1773 r
'\(constant uint16_t \(3'),
1774 Test("f32 temp array of array",
1777 precision mediump float;
1784 float a[2][2] = float[2][2](float[2](x, y), float[2](x, y));
1787 color = a[0][0] + a[1][1];
1790 r
'\(constant float16_t \(3'),
1791 Test("i32 temp array of array",
1794 precision mediump int;
1801 int a[2][2] = int[2][2](int[2](x, y), int[2](x, y));
1804 color = a[0][0] + a[1][1];
1807 r
'\(constant int16_t \(3'),
1808 Test("u32 temp array of array",
1811 precision mediump int;
1818 uint a[2][2] = uint[2][2](uint[2](x, y), uint[2](x, y));
1821 color = a[0][0] + a[1][1];
1824 r
'\(constant uint16_t \(3'),
1825 Test("f32 temp array of array assigned from highp",
1828 precision mediump float;
1835 highp float b[2][2] = float[2][2](float[2](x, y), float[2](x, y));
1840 color = a[0][0] + a[1][1];
1843 r
'\(constant float16_t \(3'),
1844 Test("i32 temp array of array assigned from highp",
1847 precision mediump int;
1854 highp int b[2][2] = int[2][2](int[2](x, y), int[2](x, y));
1859 color = a[0][0] + a[1][1];
1862 r
'\(constant int16_t \(3'),
1863 Test("u32 temp array of array assigned from highp",
1866 precision mediump int;
1873 highp uint b[2][2] = uint[2][2](uint[2](x, y), uint[2](x, y));
1878 color = a[0][0] + a[1][1];
1881 r
'\(constant uint16_t \(3'),
1882 Test("f32 temp array of array assigned to highp",
1885 precision mediump float;
1892 float a[2][2] = float[2][2](float[2](x, y), float[2](x, y));
1893 highp float b[2][2];
1898 color = a[0][0] + a[1][1];
1901 r
'\(constant float16_t \(3'),
1902 Test("i32 temp array of array assigned to highp",
1905 precision mediump int;
1912 int a[2][2] = int[2][2](int[2](x, y), int[2](x, y));
1918 color = a[0][0] + a[1][1];
1921 r
'\(constant int16_t \(3'),
1922 Test("u32 temp array of array assigned to highp",
1925 precision mediump int;
1932 uint a[2][2] = uint[2][2](uint[2](x, y), uint[2](x, y));
1938 color = a[0][0] + a[1][1];
1941 r
'\(constant uint16_t \(3'),
1942 Test("f32 temp array of array returned by function",
1945 precision mediump float;
1952 return float[2][2](float[2](x, y), float[2](x, y));
1957 float a[2][2] = f();
1960 color = a[0][0] + a[1][1];
1963 r
'\(constant float16_t \(3'),
1964 Test("i32 temp array of array returned by function",
1967 precision mediump int;
1974 return int[2][2](int[2](x, y), int[2](x, y));
1982 color = a[0][0] + a[1][1];
1985 r
'\(constant int16_t \(3'),
1986 Test("u32 temp array of array returned by function",
1989 precision mediump int;
1996 return uint[2][2](uint[2](x, y), uint[2](x, y));
2004 color = a[0][0] + a[1][1];
2007 r
'\(constant uint16_t \(3'),
2008 Test("f32 temp array of array as function out",
2011 precision mediump float;
2016 void f(out float[2][2] v)
2018 v = float[2][2](float[2](x, y), float[2](x, y));
2027 color = a[0][0] + a[1][1];
2030 r
'\(constant float16_t \(3'),
2031 Test("i32 temp array of array as function out",
2034 precision mediump int;
2039 void f(out int[2][2] v)
2041 v = int[2][2](int[2](x, y), int[2](x, y));
2050 color = a[0][0] + a[1][1];
2053 r
'\(constant int16_t \(3'),
2054 Test("u32 temp array of array as function out",
2057 precision mediump int;
2062 void f(out uint[2][2] v)
2064 v = uint[2][2](uint[2](x, y), uint[2](x, y));
2073 color = a[0][0] + a[1][1];
2076 r
'\(constant uint16_t \(3'),
2077 Test("f32 temp array of array as function in",
2080 precision mediump float;
2085 float[2][2] f(in float[2][2] v)
2097 color = a[0][0] + a[1][1];
2100 r
'\(constant float16_t \(3'),
2101 Test("i32 temp array of array as function in",
2104 precision mediump int;
2109 int[2][2] f(in int[2][2] v)
2121 color = a[0][0] + a[1][1];
2124 r
'\(constant int16_t \(3'),
2125 Test("u32 temp array of array as function in",
2128 precision mediump int;
2133 uint[2][2] f(in uint[2][2] v)
2145 color = a[0][0] + a[1][1];
2148 r
'\(constant uint16_t \(3'),
2149 Test("f32 temp array of array as function inout",
2152 precision mediump float;
2157 void f(inout float[2][2] v)
2169 color = a[0][0] + a[1][1];
2172 r
'\(constant float16_t \(3'),
2173 Test("i32 temp array of array as function inout",
2176 precision mediump int;
2181 void f(inout int[2][2] v)
2193 color = a[0][0] + a[1][1];
2196 r
'\(constant int16_t \(3'),
2197 Test("u32 temp array of array as function inout",
2200 precision mediump int;
2205 void f(inout uint[2][2] v)
2217 color = a[0][0] + a[1][1];
2220 r
'\(constant uint16_t \(3'),
2221 Test("f32 temp struct (not lowered in the presence of control flow - TODO)",
2224 precision mediump float;
2231 struct { float x,y; } s;
2239 r
'\(constant float \(3'), # should be float16_t
2240 Test("i32 temp struct (not lowered in the presence of control flow - TODO)",
2243 precision mediump int;
2250 struct { int x,y; } s;
2258 r
'\(constant int \(3'), # should be int16_t
2259 Test("u32 temp struct (not lowered in the presence of control flow - TODO)",
2262 precision mediump int;
2269 struct { uint x,y; } s;
2277 r
'\(constant uint \(3'), # should be uint16_t
2281 def compile_shader(standalone_compiler
, source
):
2282 with tempfile
.NamedTemporaryFile(mode
='wt', suffix
='.frag') as source_file
:
2283 print(source
, file=source_file
)
2285 return subprocess
.check_output([standalone_compiler
,
2287 '--lower-precision',
2290 universal_newlines
=True)
2293 def run_test(standalone_compiler
, test
):
2294 ir
= compile_shader(standalone_compiler
, test
.source
)
2296 if re
.search(test
.match_re
, ir
) is None:
2304 standalone_compiler
= sys
.argv
[1]
2308 print('Testing {} ... '.format(test
.name
), end
='')
2310 result
= run_test(standalone_compiler
, test
)
2318 print('{}/{} tests returned correct results'.format(passed
, len(TESTS
)))
2319 sys
.exit(0 if passed
== len(TESTS
) else 1)
2322 if __name__
== '__main__':