2 # - inout with varyings, attributes, uniforms (and arrays of 'em)
3 # - inout with arrays, array elements
4 # - inout with array elements
5 # - inout by-value semantics (arrays & elements & structs)
8 # - control flow: return, return in loop, etc.
10 group datatypes "Function Parameter Data Types"
15 input float in0 = [ 0.0 | 1.0 | -2.0 | 2.5 ];
16 output float out0 = [ 0.0 | -1.0 | 2.0 | -2.5 ];
20 precision mediump float;
39 input vec2 in0 = [ vec2(0.0, 1.0) | vec2(2.0, 2.5) ];
40 output float out0 = [ -1.0 | -4.5 ];
44 precision mediump float;
63 input vec3 in0 = [ vec3(0.0, 1.0, -2.0) | vec3(2.0, 2.5, -4.0) ];
64 output float out0 = [ 1.0 | -0.5 ];
68 precision mediump float;
73 return -(a.x + a.y + a.z);
87 input vec4 in0 = [ vec4(0.0, 1.0, -2.0, 0.5) | vec4(2.0, 2.5, 4.0, -7.0) ];
88 output float out0 = [ 0.5 | -1.5 ];
92 precision mediump float;
97 return -(a.x + a.y + a.z + a.w);
111 input mat2 in0 = [ mat2(0.0, 1.0, -2.0, 0.5) | mat2(2.0, 2.5, 4.0, -7.0) ];
112 output float out0 = [ 0.5 | -1.5 ];
116 precision mediump float;
121 return -(a[0][0] + a[0][1] + a[1][0] + a[1][1]);
135 input mat3 in0 = [ mat3(0.0, 1.0, -2.0, 0.5, 1.0, -1.0, 2.0, 4.0, -1.0) | mat3(2.0, 2.5, 4.0, -7.0, 2.5, 3.0, 0.5, -3.5, 1.0) ];
136 output float out0 = [ -4.5 | -5.0 ];
140 precision mediump float;
145 return -(a[0][0] + a[0][1] + a[0][2] + a[1][0] + a[1][1] + a[1][2] + a[2][0] + a[2][1] + a[2][2]);
159 input mat4 in0 = [ mat4(0.0, 1.0, -2.0, 0.5, 1.0, -1.0, 2.0, 4.0, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, -2.0, -2.0) | mat4(2.0, 2.5, 4.0, -7.0, 2.5, 3.0, 0.5, -3.5, 1.0, 0.0, 2.0, -1.0, 1.0, 0.0, -1.0, 3.0) ];
160 output float out0 = [ -5.5 | -9.0 ];
164 precision mediump float;
169 return -(a[0][0] + a[0][1] + a[0][2] + a[0][3] + a[1][0] + a[1][1] + a[1][2] + a[1][3] + a[2][0] + a[2][1] + a[2][2] + a[2][3] + a[3][0] + a[3][1] + a[3][2] + a[3][3]);
183 input int in0 = [ -1 | 0 | 1 | 4 ];
184 output int out0 = [ 1 | 0 | -1 | -4 ];
188 precision mediump float;
189 precision mediump int;
209 input ivec2 in0 = [ ivec2(-1, 0) | ivec2(1, 4) ];
210 output int out0 = [ 1 | -5 ];
214 precision mediump float;
215 precision mediump int;
235 input ivec3 in0 = [ ivec3(-1, 0, 2) | ivec3(1, 4, -8) ];
236 output int out0 = [ -1 | 3 ];
240 precision mediump float;
241 precision mediump int;
246 return -(a.x + a.y + a.z);
261 input ivec4 in0 = [ ivec4(-1, 0, 2, 2) | ivec4(1, 4, -8, 2) ];
262 output int out0 = [ -3 | 1 ];
266 precision mediump float;
267 precision mediump int;
272 return -(a.x + a.y + a.z + a.w);
287 input bool in0 = [ true | false ];
288 output bool out0 = [ false | true ];
292 precision mediump float;
312 input bvec2 in0 = [ bvec2(true, true) | bvec2(false, true) ];
313 output bool out0 = [ false | true ];
317 precision mediump float;
322 return !(a.x == a.y);
337 input bvec3 in0 = [ bvec3(true, true, false) | bvec3(true, false, false) ];
338 output bool out0 = [ false | true ];
342 precision mediump float;
347 return (a.x == a.y) == a.z;
362 input bvec4 in0 = [ bvec4(true, true, true, false) | bvec4(false, false, true, true) | bvec4(true, false, false, true) ];
363 output bool out0 = [ false | true | true ];
367 precision mediump float;
372 return ((a.x == a.y) == (a.z == a.w));
387 input mat2 in0 = [ mat2(-2.0, 0.5, -1.0, 1.0) | mat2(1.0, -3.5, -3.5, 2.5) | mat2(-2.0, -2.0, 3.5, 0.0) ];
388 output mat2 out0 = [ mat2(4.0, -1.0, 2.0, -2.0) | mat2(-2.0, 7.0, 7.0, -5.0) | mat2(4.0, 4.0, -7.0, -0.0) ];
392 precision mediump float;
413 input mat3 in0 = [ mat3(2.5, 0.0, 1.0, -2.5, 1.0, 3.0, 0.0, 2.0, 1.5) | mat3(-3.5, 2.0, 0.5, -1.5, -3.5, 2.5, 0.0, 1.5, 3.0) | mat3(1.5, 3.0, -1.0, 2.5, -0.5, 3.5, 3.0, -3.0, -2.5) ];
414 output mat3 out0 = [ mat3(-5.0, -0.0, -2.0, 5.0, -2.0, -6.0, -0.0, -4.0, -3.0) | mat3(7.0, -4.0, -1.0, 3.0, 7.0, -5.0, -0.0, -3.0, -6.0) | mat3(-3.0, -6.0, 2.0, -5.0, 1.0, -7.0, -6.0, 6.0, 5.0) ];
418 precision mediump float;
439 input mat4 in0 = [ mat4(-2.0, 3.5, -0.5, 1.0, -1.5, 0.0, -1.0, -1.0, 0.5, 0.5, 3.0, 1.5, 3.0, 2.5, 3.5, 1.5) | mat4(-2.5, 2.5, 3.5, 3.0, 0.5, 1.5, -2.0, 2.5, 0.5, -1.5, -3.5, 2.5, 3.5, -3.0, 2.5, -0.5) | mat4(-2.5, -1.5, 2.0, 3.0, -3.5, 1.0, -3.5, 1.5, -1.5, 3.0, 3.5, 0.0, 3.5, -1.5, -3.0, 0.5) ];
440 output mat4 out0 = [ mat4(4.0, -7.0, 1.0, -2.0, 3.0, -0.0, 2.0, 2.0, -1.0, -1.0, -6.0, -3.0, -6.0, -5.0, -7.0, -3.0) | mat4(5.0, -5.0, -7.0, -6.0, -1.0, -3.0, 4.0, -5.0, -1.0, 3.0, 7.0, -5.0, -7.0, 6.0, -5.0, 1.0) | mat4(5.0, 3.0, -4.0, -6.0, 7.0, -2.0, 7.0, -3.0, 3.0, -6.0, -7.0, -0.0, -7.0, 3.0, 6.0, -1.0) ];
444 precision mediump float;
464 input vec3 in0 = [ vec3(0.0, 1.0, -2.0) | vec3(2.0, 2.5, -4.0) ];
465 output float out0 = [ 1.0 | -0.5 ];
469 precision mediump float;
472 struct Pos { float a, b, c; };
476 return -(p.a + p.b + p.c);
481 Pos p = Pos(in0.x, in0.y, in0.z);
491 input vec3 in0 = [ vec3(0.0, 1.0, -2.0) | vec3(2.0, 2.5, -4.0) ];
492 output float out0 = [ 1.0 | -0.5 ];
496 precision mediump float;
499 struct Pos { float a, b, c; };
503 return Pos(-p.a, -p.b, -p.c);
508 Pos p = Pos(in0.x, in0.y, in0.z);
510 out0 = p.a + p.b + p.c;
516 case struct_nested_struct
519 input vec3 in0 = [ vec3(0.0, 1.0, -2.0) | vec3(2.0, 2.5, -4.0) ];
520 output float out0 = [ 1.0 | -0.5 ];
524 precision mediump float;
527 struct Pos { float a, b, c; };
528 struct Line { Pos start, end; };
532 return Line(p, Pos(-p.a, -p.b, -p.c));
537 return (p.a + p.b + p.c);
542 Pos p = Pos(in0.x, in0.y, in0.z);
544 out0 = sum(line.start) + (2.0 * sum(line.end));
550 case struct_constructor_highp_in_fragment
551 desc "passing highp vector to struct constructor in fragment shader yields all zeros"
553 ${VERTEX_DECLARATIONS}
560 #ifdef GL_FRAGMENT_PRECISION_HIGH
561 #define PRECISION highp
563 #define PRECISION mediump
566 PRECISION vec3 color;
569 PRECISION vec3 color = vec3(0.2, 2.0, 0.1);
570 Test test = Test(color);
571 // Bias the color so all components are guaranteed > 1.0.
572 gl_FragColor = vec4(vec3(0.25, 0.55, 0.65) + vec3(4.0, 0.25, 4.0) * test.color, 1.0);
579 group qualifiers "Function Parameter Qualifiers"
584 input float in0 = [ 0.0 | 1.0 | -2.0 | 2.5 ];
585 output float out0 = [ 0.0 | -1.0 | 2.0 | -2.5 ];
589 precision mediump float;
590 precision mediump int;
593 float func (in float a)
613 input float in0 = [ 0.0 | 1.0 | -2.0 | 2.5 ];
614 output float out0 = [ 0.0 | -1.0 | 2.0 | -2.5 ];
618 precision mediump float;
619 precision mediump int;
622 void func (out float a)
641 input float in0 = [ 0.0 | 1.0 | -2.0 | 2.5 ];
642 output float out0 = [ 0.0 | -1.0 | 2.0 | -2.5 ];
646 precision mediump float;
647 precision mediump int;
650 void func (inout float a)
669 input float in0 = [ 0.0 | 1.0 | -2.0 | 2.5 ];
670 output float out0 = [ 0.0 | -1.0 | 2.0 | -2.5 ];
674 precision mediump float;
675 precision mediump int;
678 float func (in lowp float a)
698 input float in0 = [ 0.0 | 1.0 | -2.0 | 2.5 ];
699 output float out0 = [ 0.0 | -1.0 | 2.0 | -2.5 ];
703 precision mediump float;
704 precision mediump int;
707 void func (out lowp float a)
723 case inout_lowp_float
726 input float in0 = [ 0.0 | 1.0 | -2.0 | 2.5 ];
727 output float out0 = [ 0.0 | -1.0 | 2.0 | -2.5 ];
731 precision mediump float;
732 precision mediump int;
735 void func (inout lowp float a)
754 input float in0 = [ 0.0 | 1.0 | -2.0 | 2.5 ];
755 output float out0 = [ 0.0 | -1.0 | 2.0 | -2.5 ];
759 precision mediump float;
760 precision mediump int;
763 float func (in highp float a)
783 input float in0 = [ 0.0 | 1.0 | -2.0 | 2.5 ];
784 output float out0 = [ 0.0 | -1.0 | 2.0 | -2.5 ];
788 precision mediump float;
789 precision mediump int;
792 void func (out highp float a)
808 case inout_highp_float
811 input float in0 = [ 0.0 | 1.0 | -2.0 | 2.5 ];
812 output float out0 = [ 0.0 | -1.0 | 2.0 | -2.5 ];
816 precision mediump float;
817 precision mediump int;
820 void func (inout highp float a)
839 input float in0 = [ 0.0 | 1.0 | -2.0 | 2.5 ];
840 output float out0 = [ 0.0 | -1.0 | 2.0 | -2.5 ];
844 precision mediump float;
845 precision mediump int;
848 float func (const float a)
868 input float in0 = [ 0.0 | 1.0 | -2.0 | 2.5 ];
869 output float out0 = [ 0.0 | -1.0 | 2.0 | -2.5 ];
873 precision mediump float;
874 precision mediump int;
877 float func (const in float a)
897 input int in0 = [ 0 | 1 | -2 | 4 ];
898 output int out0 = [ 0 | -1 | 2 | -4 ];
902 precision mediump float;
903 precision mediump int;
926 input int in0 = [ 0 | 1 | -2 | 6 ];
927 output int out0 = [ 0 | -1 | 2 | -6 ];
931 precision mediump float;
932 precision mediump int;
935 void func (out int a)
954 input int in0 = [ 0 | 1 | -2 | 6 ];
955 output int out0 = [ 0 | -1 | 2 | -6 ];
959 precision mediump float;
960 precision mediump int;
963 void func (inout int a)
982 input int in0 = [ 0 | 1 | -2 | 4 ];
983 output int out0 = [ 0 | -1 | 2 | -4 ];
987 precision mediump float;
988 precision mediump int;
991 int func (in lowp int a)
1011 input int in0 = [ 0 | 1 | -2 | 6 ];
1012 output int out0 = [ 0 | -1 | 2 | -6 ];
1016 precision mediump float;
1017 precision mediump int;
1020 void func (out lowp int a)
1039 input int in0 = [ 0 | 1 | -2 | 6 ];
1040 output int out0 = [ 0 | -1 | 2 | -6 ];
1044 precision mediump float;
1045 precision mediump int;
1048 void func (inout lowp int a)
1067 input int in0 = [ 0 | 1 | -2 | 4 ];
1068 output int out0 = [ 0 | -1 | 2 | -4 ];
1072 precision mediump float;
1073 precision mediump int;
1076 int func (in highp int a)
1096 input int in0 = [ 0 | 1 | -2 | 6 ];
1097 output int out0 = [ 0 | -1 | 2 | -6 ];
1101 precision mediump float;
1102 precision mediump int;
1105 void func (out highp int a)
1121 case inout_highp_int
1124 input int in0 = [ 0 | 1 | -2 | 6 ];
1125 output int out0 = [ 0 | -1 | 2 | -6 ];
1129 precision mediump float;
1130 precision mediump int;
1133 void func (inout highp int a)
1152 input int in0 = [ 0 | 1 | -2 | 4 ];
1153 output int out0 = [ 0 | -1 | 2 | -4 ];
1157 precision mediump float;
1158 precision mediump int;
1161 int func (const int a)
1181 input int in0 = [ 0 | 1 | -2 | 4 ];
1182 output int out0 = [ 0 | -1 | 2 | -4 ];
1186 precision mediump float;
1187 precision mediump int;
1190 int func (const in int a)
1210 input bool in0 = [ true | false ];
1211 output bool out0 = [ true | true ];
1215 precision mediump float;
1218 bool func (in bool a)
1238 input bool in0 = [ true | false ];
1239 output bool out0 = [ false | true ];
1243 precision mediump float;
1246 void func (out bool a)
1265 input bool in0 = [ true | false ];
1266 output bool out0 = [ false | true ];
1270 precision mediump float;
1273 void func (inout bool a)
1291 group declarations "Function Declarations"
1293 case void_vs_no_void
1296 input float in0 = [ 0.0 | 1.0 | -2.0 | 2.5 ];
1297 output float out0 = [ 0.0 | -1.0 | 2.0 | -2.5 ];
1301 precision mediump float;
1308 out0 = func() * in0;
1322 input float in0 = [ 0.0 | 1.0 | -2.0 | 2.5 ];
1323 output float out0 = [ 0.0 | -1.0 | 2.0 | -2.5 ];
1327 precision mediump float;
1330 float func (float f);
1338 float func (in float f)
1345 case default_vs_explicit_precision
1348 input float in0 = [ 0.0 | 1.0 | -2.0 | 2.5 ];
1349 output float out0 = [ 0.0 | -1.0 | 2.0 | -2.5 ];
1353 precision mediump float;
1356 float func (float f);
1364 float func (mediump float f)
1373 group overloading "Function Overloading"
1375 case user_func_arg_type_simple
1378 input float in0 = [ 0.0 | 1.0 | -2.0 | 2.5 ];
1379 output float out0 = [ 0.0 | -1.0 | 2.0 | -2.5 ];
1383 precision mediump float;
1384 precision mediump int;
1387 float func (float a)
1399 out0 = func(in0) * float(func(-1));
1405 case user_func_arg_float_types
1408 input float in0 = [ 0.0 | 1.0 | -2.0 | 2.5 ];
1409 output float out0 = [ 0.0 | -1.0 | 2.0 | -2.5 ];
1413 precision mediump float;
1414 precision mediump int;
1417 float func (float a) { return -a; }
1418 vec2 func (vec2 a) { return a.yx; }
1419 vec3 func (vec3 a) { return a.xxx; }
1420 vec4 func (vec4 a) { return a.wwww; }
1424 out0 = func(func(func(func(vec4(in0)).xyz).xy).x);
1430 case user_func_arg_int_types
1433 input int in0 = [ 0 | 1 | -2 | 6 ];
1434 output int out0 = [ 0 | -1 | 2 | -6 ];
1438 precision mediump float;
1439 precision mediump int;
1442 int func (int a) { return -a; }
1443 ivec2 func (ivec2 a) { return a.yx; }
1444 ivec3 func (ivec3 a) { return a.xxx; }
1445 ivec4 func (ivec4 a) { return a.wwww; }
1450 out0 = func(func(func(func(ivec4(in0)).xyz).xy).x);
1456 case user_func_arg_bool_types
1459 input bool in0 = [ true | false ];
1460 output bool out0 = [ false | true ];
1464 precision mediump float;
1467 bool func (bool a) { return !a; }
1468 bvec2 func (bvec2 a) { return a.yx; }
1469 bvec3 func (bvec3 a) { return a.xxx; }
1470 bvec4 func (bvec4 a) { return a.wwww; }
1475 out0 = func(func(func(func(bvec4(in0)).xyz).xy).x);
1481 case user_func_arg_basic_types
1484 input float in0 = [ 0.0 | 1.0 | -2.0 | 2.5 ];
1485 output float out0 = [ 0.0 | -1.0 | 2.0 | -2.5 ];
1489 precision mediump float;
1490 precision mediump int;
1493 float func (float a) { return -a; }
1494 vec2 func (vec2 a) { return a.yx; }
1495 vec3 func (vec3 a) { return a.xxx; }
1496 vec4 func (vec4 a) { return a.wwww; }
1497 int func (int a) { return -a; }
1498 ivec2 func (ivec2 a) { return a.yx; }
1499 ivec3 func (ivec3 a) { return a.xxx; }
1500 ivec4 func (ivec4 a) { return a.wwww; }
1501 bool func (bool a) { return !a; }
1502 bvec2 func (bvec2 a) { return a.yx; }
1503 bvec3 func (bvec3 a) { return a.xxx; }
1504 bvec4 func (bvec4 a) { return a.wwww; }
1509 if (func(func(bvec4(false)).x))
1510 out0 = func(in0) * float(func(-1));
1512 out0 = float(func(func(ivec4(func(func(func(vec4(0.5)).xyz).xy).xxxx)).xy).x);
1518 case user_func_arg_complex_types
1521 input float in0 = [ 0.0 | 1.0 | -2.0 | 2.5 ];
1522 output float out0 = [ 0.0 | -1.0 | 2.0 | -2.5 ];
1526 precision mediump float;
1527 precision mediump int;
1530 struct Pos { float a, b, c; };
1531 struct Line { Pos start, end; };
1533 float func (float a) { return -a; }
1534 float func (float a[4]) { return a[0] + a[3]; }
1535 vec2 func (vec2 a) { return a.yx; }
1536 vec3 func (vec3 a) { return a.xxx; }
1537 vec4 func (vec4 a) { return a.wwww; }
1538 vec4 func (vec4 a[4]) { return a[1] + a[2]; }
1539 int func (int a) { return -a; }
1540 ivec2 func (ivec2 a) { return a.yx; }
1541 ivec3 func (ivec3 a) { return a.xxx; }
1542 ivec4 func (ivec4 a) { return a.wwww; }
1543 bool func (bool a) { return !a; }
1544 bvec2 func (bvec2 a) { return a.yx; }
1545 bvec3 func (bvec3 a) { return a.xxx; }
1546 bvec4 func (bvec4 a) { return a.wwww; }
1547 Pos func (Pos a) { return a; }
1548 Line func (Line a) { return Line(a.end, a.start); }
1555 out0 = func(arr) + func(arr2).x;
1556 if (func(func(bvec4(false)).x))
1557 out0 = func(in0) * float(func(-1));
1559 out0 = float(func(func(ivec4(func(func(func(vec4(0.5)).xyz).xy).xxxx)).xy).x);
1565 case user_func_arguments
1568 input float in0 = [ 0.0 | 1.0 | -2.0 | 2.5 ];
1569 output float out0 = [ 0.0 | -1.0 | 2.0 | -2.5 ];
1573 precision mediump float;
1576 float func (float a)
1581 float func (float a, float b)
1588 out0 = func(in0) * func(-0.5, -2.0);
1597 input int in0 = [ -1 | 0 | 1 | 4 ];
1598 output int out0 = [ 1 | 0 | -1 | -4 ];
1602 precision mediump float;
1603 precision mediump int;
1606 int sin(int a) { return -a; }
1620 input int in0 = [ -1 | 0 | 1 | 4 ];
1621 output int out0 = [ 1 | 0 | -1 | -4 ];
1625 precision mediump float;
1626 precision mediump int;
1629 int step (float i, float j, int a) { return -a; }
1634 out0 = step(0.0, 1.0, in0);
1643 output float out0 = [ 1.0 ];
1647 precision mediump float;
1650 float func (float f[3])
1655 float func (float f[4])
1675 group array_arguments "Arrays as Arguments"
1680 input vec4 in0 = [ vec4(0.0, 1.0, 2.0, -4.0) | vec4(-7.5, 12.125, -0.25, 16.0) ];
1681 output vec4 out0 = [ vec4(0.0, -1.0, -2.0, 4.0) | vec4(7.5, -12.125, 0.25, -16.0) ];
1685 precision mediump float;
1688 float func (in float a[4])
1703 float f = func(arr);
1704 out0 = f * vec4(arr[0], arr[1], arr[2], arr[3]);
1710 case global_in_float
1713 input vec4 in0 = [ vec4(0.0, 1.0, 2.0, -4.0) | vec4(-7.5, 12.125, -0.25, 16.0) ];
1714 output vec4 out0 = [ vec4(0.0, -1.0, -2.0, 4.0) | vec4(7.5, -12.125, 0.25, -16.0) ];
1718 precision mediump float;
1721 float func (in float a[4])
1737 float f = func(arr);
1738 out0 = f * vec4(arr[0], arr[1], arr[2], arr[3]);
1747 input ivec4 in0 = [ ivec4(0, 1, 2, -4) | ivec4(-7, -11, 13, 19) ];
1748 output ivec4 out0 = [ ivec4(0, -1, -2, 4) | ivec4(7, 11, -13, -19) ];
1752 precision mediump float;
1753 precision mediump int;
1756 int func (in int a[4])
1773 out0 = f * ivec4(arr[0], arr[1], arr[2], arr[3]);
1782 input ivec4 in0 = [ ivec4(0, 1, 2, 4) | ivec4(-7, -11, 13, 19) ];
1783 output ivec4 out0 = [ ivec4(0, -1, -2, -4) | ivec4(7, 11, -13, -19) ];
1787 precision mediump float;
1788 precision mediump int;
1791 int func (in int a[4])
1809 out0 = f * ivec4(arr[0], arr[1], arr[2], arr[3]);
1819 input bvec4 in0 = [ bvec4(true, true, false, true) | bvec4(false, false, false, false) ];
1820 output bvec4 out0 = [ bvec4(false, false, true, false) | bvec4(true, true, true, true) ];
1824 precision mediump float;
1827 bool func (in bool a[4])
1844 out0 = bvec4(arr[0], arr[1], arr[2], arr[3]);
1853 input bvec4 in0 = [ bvec4(true, true, false, true) | bvec4(false, false, false, false) ];
1854 output bvec4 out0 = [ bvec4(false, false, true, false) | bvec4(true, true, true, true) ];
1858 precision mediump float;
1861 bool func (in bool a[4])
1879 out0 = bvec4(arr[0], arr[1], arr[2], arr[3]);
1886 desc "Check that helper functions are supported properly."
1889 input vec4 in0 = [ vec4(0.0, 1.0, 2.0, -4.0) | vec4(-7.5, 12.125, -0.25, 16.0) ];
1890 output float out0 = [ 1.0 | 1.0 ];
1894 precision mediump float;
1897 vec4 get (in float arr[4]);
1898 void set (out float arr[4], vec4 val);
1899 void negate (inout float arr[4]);
1900 bool test (in float arr[4], vec4 ref);
1901 bool isEqual (in float a[4], in float b[4]);
1908 out0 = float(test(arr, -in0));
1912 float absDiff (vec4 a, vec4 b) { vec4 d = abs(a - b); return max(max(d.x, d.y), max(d.z, d.w)); }
1913 vec4 get (in float arr[4]) { return vec4(arr[0], arr[1], arr[2], arr[3]); }
1914 void set (out float arr[4], vec4 val) { arr[0] = val.x; arr[1] = val.y; arr[2] = val.z; arr[3] = val.w; }
1915 void negate (inout float arr[4]) { set(arr, -get(arr)); }
1916 bool test (in float arr[4], vec4 ref) { return (absDiff(get(arr), ref) < 0.1); }
1917 bool isEqual (in float a[4], in float b[4]) { return (absDiff(get(a), get(b)) < 0.1); }
1921 case copy_local_in_on_call
1922 desc "Check that local 'in' arguments are copied on call and don't alias."
1925 input vec4 in0 = [ vec4(0.0, 1.0, 2.0, -4.0) | vec4(-7.5, 12.125, -0.25, 16.0) ];
1926 output vec4 out0 = [ vec4(0.0, -1.0, -2.0, 4.0) | vec4(7.5, -12.125, 0.25, -16.0) ];
1930 precision mediump float;
1933 vec4 get (in float arr[4]);
1934 void set (out float arr[4], vec4 val);
1935 void negate (inout float arr[4]);
1936 bool test (in float arr[4], vec4 ref);
1937 bool isEqual (in float a[4], in float b[4]);
1939 float func (in float a[4], in float b[4])
1943 return isEqual(a, b) ? 1.0 : -1.0;
1950 out0 = in0 * func(arr, arr);
1954 float absDiff (vec4 a, vec4 b) { vec4 d = abs(a - b); return max(max(d.x, d.y), max(d.z, d.w)); }
1955 vec4 get (in float arr[4]) { return vec4(arr[0], arr[1], arr[2], arr[3]); }
1956 void set (out float arr[4], vec4 val) { arr[0] = val.x; arr[1] = val.y; arr[2] = val.z; arr[3] = val.w; }
1957 void negate (inout float arr[4]) { set(arr, -get(arr)); }
1958 bool test (in float arr[4], vec4 ref) { return (absDiff(get(arr), ref) < 0.1); }
1959 bool isEqual (in float a[4], in float b[4]) { return (absDiff(get(a), get(b)) < 0.1); }
1963 case copy_global_in_on_call
1964 desc "Check that global 'in' arguments are copied on call and don't alias."
1967 input vec4 in0 = [ vec4(0.0, 1.0, 2.0, -4.0) | vec4(-7.5, 12.125, -0.25, 16.0) ];
1968 output vec4 out0 = [ vec4(0.0, -1.0, -2.0, 4.0) | vec4(7.5, -12.125, 0.25, -16.0) ];
1972 precision mediump float;
1975 vec4 get (in float arr[4]);
1976 void set (out float arr[4], vec4 val);
1977 void negate (inout float arr[4]);
1978 bool test (in float arr[4], vec4 ref);
1979 bool isEqual (in float a[4], in float b[4]);
1981 float func (in float a[4], in float b[4])
1985 return isEqual(a, b) ? 1.0 : -1.0;
1993 out0 = in0 * func(arr, arr);
1997 float absDiff (vec4 a, vec4 b) { vec4 d = abs(a - b); return max(max(d.x, d.y), max(d.z, d.w)); }
1998 vec4 get (in float arr[4]) { return vec4(arr[0], arr[1], arr[2], arr[3]); }
1999 void set (out float arr[4], vec4 val) { arr[0] = val.x; arr[1] = val.y; arr[2] = val.z; arr[3] = val.w; }
2000 void negate (inout float arr[4]) { set(arr, -get(arr)); }
2001 bool test (in float arr[4], vec4 ref) { return (absDiff(get(arr), ref) < 0.1); }
2002 bool isEqual (in float a[4], in float b[4]) { return (absDiff(get(a), get(b)) < 0.1); }
2006 case copy_local_inout_on_call
2007 desc "Check that local 'in' arguments are copied on call and don't alias."
2010 input vec4 in0 = [ vec4(0.0, 1.0, 2.0, -4.0) | vec4(-7.5, 12.125, -0.25, 16.0) ];
2011 output vec4 out0 = [ vec4(0.0, -1.0, -2.0, 4.0) | vec4(7.5, -12.125, 0.25, -16.0) ];
2015 precision mediump float;
2018 vec4 get (in float arr[4]);
2019 void set (out float arr[4], vec4 val);
2020 void negate (inout float arr[4]);
2021 bool test (in float arr[4], vec4 ref);
2022 bool isEqual (in float a[4], in float b[4]);
2024 float func (inout float a[4], inout float b[4])
2027 return isEqual(a, b) ? 1.0 : -1.0;
2034 float m = func(arr, arr); // returns -1.0
2035 float n = float(test(arr, in0) || test(arr, -in0));
2040 float absDiff (vec4 a, vec4 b) { vec4 d = abs(a - b); return max(max(d.x, d.y), max(d.z, d.w)); }
2041 vec4 get (in float arr[4]) { return vec4(arr[0], arr[1], arr[2], arr[3]); }
2042 void set (out float arr[4], vec4 val) { arr[0] = val.x; arr[1] = val.y; arr[2] = val.z; arr[3] = val.w; }
2043 void negate (inout float arr[4]) { set(arr, -get(arr)); }
2044 bool test (in float arr[4], vec4 ref) { return (absDiff(get(arr), ref) < 0.1); }
2045 bool isEqual (in float a[4], in float b[4]) { return (absDiff(get(a), get(b)) < 0.1); }
2049 case copy_global_inout_on_call
2050 desc "Check that global 'in' arguments are copied on call and don't alias."
2053 input vec4 in0 = [ vec4(0.0, 1.0, 2.0, -4.0) | vec4(-7.5, 12.125, -0.25, 16.0) ];
2054 output vec4 out0 = [ vec4(0.0, -1.0, -2.0, 4.0) | vec4(7.5, -12.125, 0.25, -16.0) ];
2058 precision mediump float;
2061 vec4 get (in float arr[4]);
2062 void set (out float arr[4], vec4 val);
2063 void negate (inout float arr[4]);
2064 bool test (in float arr[4], vec4 ref);
2065 bool isEqual (in float a[4], in float b[4]);
2067 float func (in float a[4], in float b[4])
2070 return isEqual(a, b) ? 1.0 : -1.0;
2078 float m = func(arr, arr); // returns -1.0
2079 float n = float(test(arr, in0) || test(arr, -in0));
2084 float absDiff (vec4 a, vec4 b) { vec4 d = abs(a - b); return max(max(d.x, d.y), max(d.z, d.w)); }
2085 vec4 get (in float arr[4]) { return vec4(arr[0], arr[1], arr[2], arr[3]); }
2086 void set (out float arr[4], vec4 val) { arr[0] = val.x; arr[1] = val.y; arr[2] = val.z; arr[3] = val.w; }
2087 void negate (inout float arr[4]) { set(arr, -get(arr)); }
2088 bool test (in float arr[4], vec4 ref) { return (absDiff(get(arr), ref) < 0.1); }
2089 bool isEqual (in float a[4], in float b[4]) { return (absDiff(get(a), get(b)) < 0.1); }
2093 # vec4 get (in float arr[4]);
2094 # void set (out float arr[4], vec4 val);
2095 # void negate (inout float arr[4]);
2096 # bool test (in float arr[4], vec4 ref);
2097 # bool isEqual (in float a[4], in float b[4]);
2099 # float absDiff (vec4 a, vec4 b) { vec4 d = abs(a - b); return max(max(d.x, d.y), max(d.z, d.w)); }
2100 # vec4 get (in float arr[4]) { return vec4(arr[0], arr[1], arr[2], arr[3]); }
2101 # void set (out float arr[4], vec4 val) { arr[0] = val.x; arr[1] = val.y; arr[2] = val.z; arr[3] = val.w; }
2102 # void negate (inout float arr[4]) { set(arr, -get(arr)); }
2103 # bool test (in float arr[4], vec4 ref) { return (absDiff(get(arr), ref) < 0.1); }
2104 # bool isEqual (in float a[4], in float b[4]) { return (absDiff(get(a), get(b)) < 0.1); }
2106 end # array_arguments
2108 #group qualifiers "Function Parameter Qualifiers"
2112 group control_flow "Control Flow In Functions"
2117 input float in0 = [ -0.5 | 1.5 ];
2118 output float out0 = [ 0.5 | -1.5 ];
2122 precision mediump float;
2125 float func (float a)
2144 input float in0 = [ -0.5 | 1.5 ];
2145 output float out0 = [ 0.5 | -1.5 ];
2149 precision mediump float;
2152 float func (float a)
2171 input float in0 = [ -0.5 | 1.5 ];
2172 output float out0 = [ 0.5 | -1.5 ];
2176 precision mediump float;
2179 float func (float a)
2200 input float in0 = [ -0.5 | 1.5 ];
2201 output float out0 = [ 0.5 | -1.5 ];
2205 precision mediump float;
2208 float func (float a)
2210 for (int i = 0; i < 1; i++)
2224 case return_in_loop_if
2227 input float in0 = [ -0.5 | 1.5 ];
2228 output float out0 = [ 0.5 | -1.5 ];
2232 precision mediump float;
2235 float func (float a)
2237 for (int i = 0; i < 3; i++)
2257 case return_after_loop
2260 input float in0 = [ -0.5 | 1.5 ];
2261 output float out0 = [ 0.5 | -1.5 ];
2265 precision mediump float;
2268 float func (float a)
2270 for (int i = 0; i < 5; i++)
2284 case return_after_break
2287 input float in0 = [ -0.5 | 1.5 ];
2288 output float out0 = [ 0.5 | -1.5 ];
2292 precision mediump float;
2295 float func (float a)
2297 for (int i = 0; i < 6; i++)
2315 case return_after_continue
2318 input float in0 = [ -0.5 | 1.5 ];
2319 output float out0 = [ 0.5 | -1.5 ];
2323 precision mediump float;
2326 float func (float a)
2328 for (int i = 0; i < 6; i++)
2346 case return_in_nested_loop
2349 input float in0 = [ -0.5 | 1.5 ];
2350 output float out0 = [ 0.5 | -1.5 ];
2354 precision mediump float;
2357 float func (float a)
2359 for (int i = 0; i < 6; i++)
2362 for (int j = 0; j < 4; j++)
2383 case return_after_loop_sequence
2384 require full_glsl_es_100_support
2388 input float in0 = [ -0.5 | 1.5 ];
2389 output float out0 = [ 0.5 | -1.5 ];
2393 precision mediump float;
2396 float func (float a)
2399 for (i = 0; i < 6; i++) // negate a
2406 for (; i < 10; i++) // keep a
2427 case mixed_return_break_continue
2430 input float in0 = [ -0.5 | 1.5 ];
2431 output float out0 = [ 0.5 | -1.5 ];
2435 precision mediump float;
2438 float func (float a)
2440 for (int i = 0; i < 6; i++)
2468 group misc "Miscellaneous"
2470 case multi_arg_float
2473 input vec4 in0 = [ vec4(0.0, 1.0, -2.0, 0.5) | vec4(2.0, 2.5, 4.0, -7.0) ];
2474 output float out0 = [ 0.5 | -1.5 ]; # -sum(in0)
2478 precision mediump float;
2481 float sum(vec4 v) { return (v.x + v.y + v.z + v.w); }
2483 float func (float a, vec3 b, vec2 c, vec2 d, vec4 e)
2485 return -sum(vec4(a, b) + vec4(c, d)) + sum(e);
2491 out0 = func(in0.y, in0.xzw, in0.wz, in0.yx, in0);
2500 input ivec4 in0 = [ ivec4(-1, 0, 2, 2) | ivec4(1, 4, -8, 2) ];
2501 output int out0 = [ -3 | 1 ];
2505 precision mediump float;
2506 precision mediump int;
2509 int sum(ivec4 v) { return (v.x + v.y + v.z + v.w); }
2511 int func (int a, ivec3 b, ivec2 c, ivec2 d, ivec4 e)
2513 return -sum(ivec4(a, b) + ivec4(c, d)) + sum(e);
2519 out0 = func(in0.y, in0.xzw, in0.wz, in0.yx, in0);
2525 case argument_eval_order_1
2528 input int in0 = [ 0 | 1 | 3 | 5 ];
2529 output int out0 = [ -1 | 5 | 11 | 17 ];
2533 precision mediump float;
2536 int func (float a, int b, bool c, int d)
2539 return b + int(a) + d;
2547 float v0 = float(in0);
2549 out0 = func((v0 += 1.0), v1++, (v0 > 1.5), v1);
2555 case argument_eval_order_2
2558 input int in0 = [ 0 | -1 | 3 | 5 ];
2559 output int out0 = [ 3 | -1 | 9 | 13 ];
2563 precision mediump float;
2574 int func (float a, int b, bool c, int d)
2577 return b + int(a) + d;
2585 out0 = func(float(g = in0), modG(2), --g > 0, g);
2591 case missing_returns
2594 input float in0 = [ 1.0 | 2.0 | 3.0 ];
2595 output float out0 = [ -1.0 | -2.0 | -3.0 ];
2598 // Note specification says that returned value is undefined if no return
2599 // statement has been executed. In this case func() is called only with
2601 precision mediump float;
2604 float func (float f)
2621 group invalid "Invalid Functions"
2625 precision mediump float;
2634 ${POSITION_FRAG_COLOR} = vec4(1.0);
2639 case continue_in_body
2642 precision mediump float;
2651 ${POSITION_FRAG_COLOR} = vec4(1.0);
2656 case return_value_from_void_function
2659 precision mediump float;
2668 ${POSITION_FRAG_COLOR} = vec4(1.0);
2673 case extra_arguments
2676 precision mediump float;
2685 ${POSITION_FRAG_COLOR} = vec4(1.0);
2690 case missing_arguments
2693 precision mediump float;
2702 ${POSITION_FRAG_COLOR} = vec4(1.0);
2707 case missing_argument_type
2710 precision mediump float;
2718 ${POSITION_FRAG_COLOR} = vec4(1.0);
2723 case argument_basetype_mismatch
2726 precision mediump float;
2727 precision mediump int;
2736 ${POSITION_FRAG_COLOR} = vec4(1.0);
2741 case argument_scalar_vector_mismatch
2744 precision mediump float;
2753 ${POSITION_FRAG_COLOR} = vec4(1.0);
2758 case argument_vector_size_mismatch
2761 precision mediump float;
2770 ${POSITION_FRAG_COLOR} = vec4(1.0);
2775 case duplicate_function
2778 precision mediump float;
2792 ${POSITION_FRAG_COLOR} = vec4(1.0);
2797 case prototype_mismatch_return_type
2800 precision mediump float;
2806 ${POSITION_FRAG_COLOR} = vec4(1.0);
2816 case prototype_unspecified_array_size
2819 precision mediump float;
2821 void func (vec3 f[]);
2825 ${POSITION_FRAG_COLOR} = vec4(1.0);
2830 case call_mismatch_argument_array_size
2833 precision mediump float;
2835 void func (vec3 f[3]);
2836 void func (vec3 f[3])
2844 ${POSITION_FRAG_COLOR} = vec4(1.0);
2849 case prototype_mismatch_argument_const
2852 precision mediump float;
2855 void func (const vec3 f)
2861 ${POSITION_FRAG_COLOR} = vec4(1.0);
2866 case prototype_mismatch_argument_array_const
2869 precision mediump float;
2871 void func (vec3 f[3]);
2872 void func (const vec3 f[3])
2878 ${POSITION_FRAG_COLOR} = vec4(1.0);
2883 case prototype_mismatch_array_inout
2886 precision mediump float;
2888 void func (out vec3 f);
2889 void func (inout vec3 f)
2895 ${POSITION_FRAG_COLOR} = vec4(1.0);
2900 case missing_return_type
2903 precision mediump float;
2906 func (inout vec3 f[3])
2912 ${POSITION_FRAG_COLOR} = vec4(1.0);
2917 case call_before_definition
2920 precision mediump float;
2925 ${POSITION_FRAG_COLOR} = vec4(1.0);
2935 case return_array_in_struct
2938 precision mediump float;
2956 ${POSITION_FRAG_COLOR} = vec4(1.0);
2961 case argument_precision_overload
2964 precision mediump float;
2966 float func (lowp float f)
2971 float func (mediump float f)
2978 ${POSITION_FRAG_COLOR} = vec4(1.0);
2983 case argument_in_out_overload
2986 precision mediump float;
2988 void func (in float f)
2992 void func (out float f)
2999 ${POSITION_FRAG_COLOR} = vec4(1.0);
3004 case argument_in_inout_overload
3007 precision mediump float;
3009 void func (in float f)
3013 void func (inout float f)
3020 ${POSITION_FRAG_COLOR} = vec4(1.0);
3025 case argument_out_inout_overload
3028 precision mediump float;
3030 void func (out float f)
3035 void func (inout float f)
3042 ${POSITION_FRAG_COLOR} = vec4(1.0);
3047 case return_type_overload
3050 precision mediump float;
3052 float func (float f)
3064 ${POSITION_FRAG_COLOR} = vec4(1.0);
3069 case return_type_precision_overload
3072 precision mediump float;
3074 lowp float func (float f)
3079 mediump float func (float f)
3086 ${POSITION_FRAG_COLOR} = vec4(1.0);
3091 case return_type_const_overload
3094 precision mediump float;
3096 float func (float f)
3101 const float func (float f)
3108 ${POSITION_FRAG_COLOR} = vec4(1.0);
3113 case return_without_value
3116 precision mediump float;
3118 float func (float f)
3126 ${POSITION_FRAG_COLOR} = vec4(1.0);
3131 case local_function_prototype
3134 precision mediump float;
3138 float func (float f);
3140 ${POSITION_FRAG_COLOR} = vec4(1.0);
3145 case local_function_definition
3148 precision mediump float;
3152 float func (float f)
3157 ${POSITION_FRAG_COLOR} = vec4(1.0);
3162 case name_type_conflict
3165 precision mediump float;
3167 struct foo { float a; }
3176 ${POSITION_FRAG_COLOR} = vec4(1.0);
3184 precision mediump float;
3190 void func (const vec3 f)
3196 ${POSITION_FRAG_COLOR} = vec4(1.0);
3204 precision mediump float;
3213 ${POSITION_FRAG_COLOR} = vec4(1.0);
3221 precision mediump float;
3230 ${POSITION_FRAG_COLOR} = vec4(1.0);
3235 case attribute_local
3238 precision mediump float;
3247 ${POSITION_FRAG_COLOR} = vec4(1.0);
3252 case uniform_argument
3255 precision mediump float;
3257 void func (uniform vec3 f)
3263 ${POSITION_FRAG_COLOR} = vec4(1.0);
3268 case varying_argument
3271 precision mediump float;
3273 void func (varying vec3 f)
3279 ${POSITION_FRAG_COLOR} = vec4(1.0);
3284 case attribute_argument
3287 precision mediump float;
3289 void func (attribute vec3 f)
3295 ${POSITION_FRAG_COLOR} = vec4(1.0);
3300 case uniform_return_type
3303 precision mediump float;
3305 uniform float func (vec3 f)
3312 ${POSITION_FRAG_COLOR} = vec4(1.0);
3317 case varying_return_type
3320 precision mediump float;
3322 varying float func (vec3 f)
3329 ${POSITION_FRAG_COLOR} = vec4(1.0);
3334 case attribute_return_type
3337 precision mediump float;
3339 attribute float func (vec3 f)
3346 ${POSITION_FRAG_COLOR} = vec4(1.0);
3351 case main_invalid_return_type
3354 precision mediump float;
3358 ${POSITION_FRAG_COLOR} = vec4(1.0);
3363 case main_has_arguments
3366 precision mediump float;
3370 ${POSITION_FRAG_COLOR} = vec4(1.0);
3375 case main_missing_return_type
3378 precision mediump float;
3382 ${POSITION_FRAG_COLOR} = vec4(1.0);
3387 case write_const_arg
3390 precision mediump float;
3392 func (const float f)
3399 ${POSITION_FRAG_COLOR} = vec4(1.0);
3404 case write_const_array_arg
3407 precision mediump float;
3409 func (const float f[3])
3416 ${POSITION_FRAG_COLOR} = vec4(1.0);
3421 case modify_const_arg
3424 precision mediump float;
3425 precision mediump int;
3428 int func (const int a)
3436 ${POSITION_FRAG_COLOR} = vec4(func(3));
3441 case init_const_local_from_const_arg
3444 precision mediump float;
3445 precision mediump int;
3448 int func (const int a)
3456 ${POSITION_FRAG_COLOR} = vec4(func(3));
3461 case array_size_from_const_arg
3464 precision mediump float;
3465 precision mediump int;
3468 int func (const int a)
3477 ${POSITION_FRAG_COLOR} = vec4(func(3));
3485 precision mediump float;
3488 float func (float f);
3489 float func (float f);
3491 float func (float f)
3498 ${POSITION_FRAG_COLOR} = vec4(func(1.0));