3 // This file defines nearly all constructors and operators for built-in data types, using
4 // extended language syntax. In general, compiler treats constructors and operators as
5 // ordinary functions with some exceptions. For example, the language does not allow
6 // functions to be called in constant expressions - here the exception is made to allow it.
8 // Each implementation provides its own version of this file. Each implementation can define
9 // the required set of operators and constructors in its own fashion.
11 // The extended language syntax is only present when compiling this file. It is implicitly
12 // included at the very beginning of the compiled shader, so no built-in functions can be
15 // To communicate with the implementation, a special extended "__asm" keyword is used, followed
16 // by an instruction name (any valid identifier), a destination variable identifier and a
17 // a list of zero or more source variable identifiers. A variable identifier is a variable name
18 // declared earlier in the code (as a function parameter, local or global variable).
19 // An instruction name designates an instruction that must be exported by the implementation.
20 // Each instruction receives data from source variable identifiers and returns data in the
21 // destination variable identifier.
23 // It is up to the implementation how to define a particular operator or constructor. If it is
24 // expected to being used rarely, it can be defined in terms of other operators and constructors,
27 // ivec2 __operator + (const ivec2 x, const ivec2 y) {
28 // return ivec2 (x[0] + y[0], x[1] + y[1]);
31 // If a particular operator or constructor is expected to be used very often or is an atomic
32 // operation (that is, an operation that cannot be expressed in terms of other operations or
33 // would create a dependency cycle) it must be defined using one or more __asm constructs.
35 // Each implementation must define constructors for all scalar types (bool, float, int).
36 // There are 9 scalar-to-scalar constructors (including identity constructors). However,
37 // since the language introduces special constructors (like matrix constructor with a single
38 // scalar value), implementations must also implement these cases.
39 // The compiler provides the following algorithm when resolving a constructor:
40 // - try to find a constructor with a prototype matching ours,
41 // - if no constructor is found and this is a scalar-to-scalar constructor, raise an error,
42 // - if a constructor is found, execute it and return,
43 // - count the size of the constructor parameter list - if it is less than the size of
44 // our constructor's type, raise an error,
45 // - for each parameter in the list do a recursive constructor matching for appropriate
46 // scalar fields in the constructed variable,
48 // Each implementation must also define a set of operators that deal with built-in data types.
49 // There are four kinds of operators:
50 // 1) Operators that are implemented only by the compiler: "()" (function call), "," (sequence)
51 // and "?:" (selection).
52 // 2) Operators that are implemented by the compiler by expressing it in terms of other operators:
53 // - "." (field selection) - translated to subscript access,
54 // - "&&" (logical and) - translated to "<left_expr> ? <right_expr> : false",
55 // - "||" (logical or) - translated to "<left_expr> ? true : <right_expr>",
56 // 3) Operators that can be defined by the implementation and if the required prototype is not
57 // found, standard behaviour is used:
58 // - "==", "!=", "=" (equality, assignment) - compare or assign matching fields one-by-one;
59 // note that at least operators for scalar data types must be defined by the implementation
61 // 4) All other operators not mentioned above. If no required prototype is found, an error is
62 // raised. An implementation must follow the language specification to provide all valid
63 // operator prototypes.
66 int __constructor (const float f) {
68 __asm float_to_int i, f;
72 bool __constructor (const int i) {
76 bool __constructor (const float f) {
80 int __constructor (const bool b) {
84 float __constructor (const bool b) {
88 float __constructor (const int i) {
90 __asm int_to_float f, i;
94 bool __constructor (const bool b) {
98 int __constructor (const int i) {
102 float __constructor (const float f) {
106 vec2 __constructor (const float f) {
110 vec2 __constructor (const int i) {
112 __asm int_to_float x, i;
116 vec2 __constructor (const bool b) {
117 return vec2 (b ? 1.0 : 0.0);
120 vec3 __constructor (const float f) {
121 return vec3 (f, f, f);
124 vec3 __constructor (const int i) {
126 __asm int_to_float x, i;
130 vec3 __constructor (const bool b) {
131 return vec3 (b ? 1.0 : 0.0);
134 vec4 __constructor (const float f) {
135 return vec4 (f, f, f, f);
138 vec4 __constructor (const int i) {
140 __asm int_to_float x, i;
144 vec4 __constructor (const bool b) {
145 return vec4 (b ? 1.0 : 0.0);
148 ivec2 __constructor (const int i) {
152 ivec2 __constructor (const float f) {
153 return ivec2 (int (f));
156 ivec2 __constructor (const bool b) {
157 return ivec2 (int (b));
160 ivec3 __constructor (const int i) {
161 return ivec3 (i, i, i);
164 ivec3 __constructor (const float f) {
165 return ivec3 (int (f));
168 ivec3 __constructor (const bool b) {
169 return ivec3 (int (b));
172 ivec4 __constructor (const int i) {
173 return ivec4 (i, i, i, i);
176 ivec4 __constructor (const float f) {
177 return ivec4 (int (f));
180 ivec4 __constructor (const bool b) {
181 return ivec4 (int (b));
184 bvec2 __constructor (const bool b) {
188 bvec2 __constructor (const float f) {
189 return bvec2 (bool (f));
192 bvec2 __constructor (const int i) {
193 return bvec2 (bool (i));
196 bvec3 __constructor (const bool b) {
197 return bvec3 (b, b, b);
200 bvec3 __constructor (const float f) {
201 return bvec3 (bool (f));
204 bvec3 __constructor (const int i) {
205 return bvec3 (bool (i));
208 bvec4 __constructor (const bool b) {
209 return bvec4 (b, b, b, b);
212 bvec4 __constructor (const float f) {
213 return bvec4 (bool (f));
216 bvec4 __constructor (const int i) {
217 return bvec4 (bool (i));
220 mat2 __constructor (const float f) {
221 return mat2 (f, 0.0, 0.0, f);
224 mat2 __constructor (const int i) {
226 __asm int_to_float x, i;
230 mat2 __constructor (const bool b) {
231 return mat2 (b ? 1.0 : 0.0);
234 mat3 __constructor (const float f) {
235 return mat3 (f, 0.0, 0.0, 0.0, f, 0.0, 0.0, 0.0, f);
238 mat3 __constructor (const int i) {
240 __asm int_to_float x, i;
244 mat3 __constructor (const bool b) {
245 return mat3 (b ? 1.0 : 0.0);
248 mat4 __constructor (const float f) {
249 return mat4 (f, 0.0, 0.0, 0.0, 0.0, f, 0.0, 0.0, 0.0, 0.0, f, 0.0, 0.0, 0.0, 0.0, f);
252 mat4 __constructor (const int i) {
254 __asm int_to_float x, i;
258 mat4 __constructor (const bool b) {
259 return mat4 (b ? 1.0 : 0.0);
262 void __operator += (inout float a, const float b) {
263 __asm float_add a, a, b;
266 float __operator - (const float a) {
268 __asm float_negate b, a;
272 void __operator -= (inout float a, const float b) {
274 __asm float_negate c, b;
275 __asm float_add a, a, c;
278 void __operator *= (inout float a, const float b) {
279 __asm float_multiply a, a, b;
282 void __operator /= (inout float a, const float b) {
283 __asm float_divide a, a, b;
286 float __operator + (const float a, const float b) {
288 __asm float_add c, a, b;
292 void __operator += (inout int a, const int b) {
293 a = int (float (a) + float (b));
296 int __operator - (const int a) {
299 __asm int_to_float x, a;
300 __asm float_negate x, x;
301 __asm float_to_int b, x;
305 void __operator -= (inout int a, const int b) {
309 float __operator * (const float a, const float b) {
311 __asm float_multiply c, a, b;
315 void __operator *= (inout int a, const int b) {
316 a = int (float (a) * float (b));
319 float __operator / (const float a, const float b) {
321 __asm float_divide c, a, b;
325 void __operator /= (inout int a, const int b) {
326 a = int (float (a) / float (b));
329 void __operator += (inout vec2 v, const vec2 u) {
334 void __operator -= (inout vec2 v, const vec2 u) {
339 void __operator *= (inout vec2 v, const vec2 u) {
344 void __operator /= (inout vec2 v, const vec2 u) {
349 void __operator += (inout vec3 v, const vec3 u) {
355 void __operator -= (inout vec3 v, const vec3 u) {
361 void __operator *= (inout vec3 v, const vec3 u) {
367 void __operator /= (inout vec3 v, const vec3 u) {
373 void __operator += (inout vec4 v, const vec4 u) {
380 void __operator -= (inout vec4 v, const vec4 u) {
387 void __operator *= (inout vec4 v, const vec4 u) {
394 void __operator /= (inout vec4 v, const vec4 u) {
401 void __operator += (inout ivec2 v, const ivec2 u) {
406 void __operator -= (inout ivec2 v, const ivec2 u) {
411 void __operator *= (inout ivec2 v, const ivec2 u) {
416 void __operator /= (inout ivec2 v, const ivec2 u) {
421 void __operator += (inout ivec3 v, const ivec3 u) {
427 void __operator -= (inout ivec3 v, const ivec3 u) {
433 void __operator *= (inout ivec3 v, const ivec3 u) {
439 void __operator /= (inout ivec3 v, const ivec3 u) {
445 void __operator += (inout ivec4 v, const ivec4 u) {
452 void __operator -= (inout ivec4 v, const ivec4 u) {
459 void __operator *= (inout ivec4 v, const ivec4 u) {
466 void __operator /= (inout ivec4 v, const ivec4 u) {
473 void __operator += (inout mat2 m, const mat2 n) {
478 void __operator -= (inout mat2 m, const mat2 n) {
483 vec2 __operator * (const mat2 m, const vec2 v) {
485 v.x * m[0].x + v.y * m[1].x,
486 v.x * m[0].y + v.y * m[1].y
490 mat2 __operator * (const mat2 m, const mat2 n) {
491 return mat2 (m * n[0], m * n[1]);
494 void __operator *= (inout mat2 m, const mat2 n) {
498 void __operator /= (inout mat2 m, const mat2 n) {
503 void __operator += (inout mat3 m, const mat3 n) {
509 void __operator -= (inout mat3 m, const mat3 n) {
515 vec3 __operator * (const mat3 m, const vec3 v) {
517 v.x * m[0].x + v.y * m[1].x + v.z * m[2].x,
518 v.x * m[0].y + v.y * m[1].y + v.z * m[2].y,
519 v.x * m[0].z + v.y * m[1].z + v.z * m[2].z
523 mat3 __operator * (const mat3 m, const mat3 n) {
524 return mat3 (m * n[0], m * n[1], m * n[2]);
527 void __operator *= (inout mat3 m, const mat3 n) {
531 void __operator /= (inout mat3 m, const mat3 n) {
537 void __operator += (inout mat4 m, const mat4 n) {
544 void __operator -= (inout mat4 m, const mat4 n) {
551 vec4 __operator * (const mat4 m, const vec4 v) {
553 v.x * m[0].x + v.y * m[1].x + v.z * m[2].x + v.w * m[3].x,
554 v.x * m[0].y + v.y * m[1].y + v.z * m[2].y + v.w * m[3].y,
555 v.x * m[0].z + v.y * m[1].z + v.z * m[2].z + v.w * m[3].z,
556 v.x * m[0].w + v.y * m[1].w + v.z * m[2].w + v.w * m[3].w
560 mat4 __operator * (const mat4 m, const mat4 n) {
561 return mat4 (m * n[0], m * n[1], m * n[2], m * n[3]);
564 void __operator *= (inout mat4 m, const mat4 n) {
568 void __operator /= (inout mat4 m, const mat4 n) {
575 void __operator += (inout vec2 v, const float a) {
580 void __operator -= (inout vec2 v, const float a) {
585 void __operator *= (inout vec2 v, const float a) {
590 void __operator /= (inout vec2 v, const float a) {
595 void __operator += (inout vec3 v, const float a) {
601 void __operator -= (inout vec3 v, const float a) {
607 void __operator *= (inout vec3 v, const float a) {
613 void __operator /= (inout vec3 v, const float a) {
619 void __operator += (inout vec4 v, const float a) {
626 void __operator -= (inout vec4 v, const float a) {
633 void __operator *= (inout vec4 v, const float a) {
640 void __operator /= (inout vec4 v, const float a) {
647 void __operator += (inout mat2 m, const float a) {
652 void __operator -= (inout mat2 m, const float a) {
657 void __operator *= (inout mat2 m, const float a) {
662 void __operator /= (inout mat2 m, const float a) {
667 void __operator += (inout mat3 m, const float a) {
673 void __operator -= (inout mat3 m, const float a) {
679 void __operator *= (inout mat3 m, const float a) {
685 void __operator /= (inout mat3 m, const float a) {
691 void __operator += (inout mat4 m, const float a) {
698 void __operator -= (inout mat4 m, const float a) {
705 void __operator *= (inout mat4 m, const float a) {
712 void __operator /= (inout mat4 m, const float a) {
719 vec2 __operator * (const vec2 v, const mat2 m) {
721 v.x * m[0].x + v.y * m[0].y,
722 v.x * m[1].x + v.y * m[1].y
726 void __operator *= (inout vec2 v, const mat2 m) {
730 vec3 __operator * (const vec3 v, const mat3 m) {
732 v.x * m[0].x + v.y * m[0].y + v.z * m[0].z,
733 v.x * m[1].x + v.y * m[1].y + v.z * m[1].z,
734 v.x * m[2].x + v.y * m[2].y + v.z * m[2].z
738 void __operator *= (inout vec3 v, const mat3 m) {
742 vec4 __operator * (const vec4 v, const mat4 m) {
744 v.x * m[0].x + v.y * m[0].y + v.z * m[0].z + v.w * m[0].w,
745 v.x * m[1].x + v.y * m[1].y + v.z * m[1].z + v.w * m[1].w,
746 v.x * m[2].x + v.y * m[2].y + v.z * m[2].z + v.w * m[2].w,
747 v.x * m[3].x + v.y * m[3].y + v.z * m[3].z + v.w * m[3].w
751 void __operator *= (inout vec4 v, const mat4 m) {
755 float __operator - (const float a, const float b) {
757 __asm float_negate c, b;
758 __asm float_add c, a, c;
762 int __operator + (const int a, const int b) {
765 __asm int_to_float x, a;
766 __asm int_to_float y, b;
767 __asm float_add x, x, y;
768 __asm float_to_int c, x;
772 int __operator - (const int a, const int b) {
775 __asm int_to_float x, a;
776 __asm int_to_float y, b;
777 __asm float_negate y, y;
778 __asm float_add x, x, y;
779 __asm float_to_int c, x;
783 int __operator * (const int a, const int b) {
786 __asm int_to_float x, a;
787 __asm int_to_float y, b;
788 __asm float_multiply x, x, y;
789 __asm float_to_int c, x;
793 int __operator / (const int a, const int b) {
796 __asm int_to_float x, a;
797 __asm int_to_float y, b;
798 __asm float_divide x, x, y;
799 __asm float_to_int c, x;
803 vec2 __operator + (const vec2 v, const vec2 u) {
804 return vec2 (v.x + u.x, v.y + u.y);
807 vec2 __operator - (const vec2 v, const vec2 u) {
808 return vec2 (v.x - u.x, v.y - u.y);
811 vec2 __operator * (const vec2 v, const vec2 u) {
812 return vec2 (v.x * u.x, v.y * u.y);
815 vec2 __operator / (const vec2 v, const vec2 u) {
816 return vec2 (v.x / u.x, v.y / u.y);
819 vec3 __operator + (const vec3 v, const vec3 u) {
820 return vec3 (v.x + u.x, v.y + u.y, v.z + u.z);
823 vec3 __operator - (const vec3 v, const vec3 u) {
824 return vec3 (v.x - u.x, v.y - u.y, v.z - u.z);
827 vec3 __operator * (const vec3 v, const vec3 u) {
828 return vec3 (v.x * u.x, v.y * u.y, v.z * u.z);
831 vec3 __operator / (const vec3 v, const vec3 u) {
832 return vec3 (v.x / u.x, v.y / u.y, v.z / u.z);
835 vec4 __operator + (const vec4 v, const vec4 u) {
836 return vec4 (v.x + u.x, v.y + u.y, v.z + u.z, v.w + u.w);
839 vec4 __operator - (const vec4 v, const vec4 u) {
840 return vec4 (v.x - u.x, v.y - u.y, v.z - u.z, v.w - u.w);
843 vec4 __operator * (const vec4 v, const vec4 u) {
844 return vec4 (v.x * u.x, v.y * u.y, v.z * u.z, v.w * u.w);
847 vec4 __operator / (const vec4 v, const vec4 u) {
848 return vec4 (v.x / u.x, v.y / u.y, v.z / u.z, v.w / u.w);
851 ivec2 __operator + (const ivec2 v, const ivec2 u) {
852 return ivec2 (v.x + u.x, v.y + u.y);
855 ivec2 __operator - (const ivec2 v, const ivec2 u) {
856 return ivec2 (v.x - u.x, v.y - u.y);
859 ivec2 __operator * (const ivec2 v, const ivec2 u) {
860 return ivec2 (v.x * u.x, v.y * u.y);
863 ivec2 __operator / (const ivec2 v, const ivec2 u) {
864 return ivec2 (v.x / u.x, v.y / u.y);
867 ivec3 __operator + (const ivec3 v, const ivec3 u) {
868 return ivec3 (v.x + u.x, v.y + u.y, v.z + u.z);
871 ivec3 __operator - (const ivec3 v, const ivec3 u) {
872 return ivec3 (v.x - u.x, v.y - u.y, v.z - u.z);
875 ivec3 __operator * (const ivec3 v, const ivec3 u) {
876 return ivec3 (v.x * u.x, v.y * u.y, v.z * u.z);
879 ivec3 __operator / (const ivec3 v, const ivec3 u) {
880 return ivec3 (v.x / u.x, v.y / u.y, v.z / u.z);
883 ivec4 __operator + (const ivec4 v, const ivec4 u) {
884 return ivec4 (v.x + u.x, v.y + u.y, v.z + u.z, v.w + u.w);
887 ivec4 __operator - (const ivec4 v, const ivec4 u) {
888 return ivec4 (v.x - u.x, v.y - u.y, v.z - u.z, v.w - u.w);
891 ivec4 __operator * (const ivec4 v, const ivec4 u) {
892 return ivec4 (v.x * u.x, v.y * u.y, v.z * u.z, v.w * u.w);
895 ivec4 __operator / (const ivec4 v, const ivec4 u) {
896 return ivec4 (v.x / u.x, v.y / u.y, v.z / u.z, v.w / u.w);
899 mat2 __operator + (const mat2 m, const mat2 n) {
900 return mat2 (m[0] + n[0], m[1] + n[1]);
903 mat2 __operator - (const mat2 m, const mat2 n) {
904 return mat2 (m[0] - n[0], m[1] - n[1]);
907 mat2 __operator / (const mat2 m, const mat2 n) {
908 return mat2 (m[0] / n[0], m[1] / n[1]);
911 mat3 __operator + (const mat3 m, const mat3 n) {
912 return mat3 (m[0] + n[0], m[1] + n[1], m[2] + n[2]);
915 mat3 __operator - (const mat3 m, const mat3 n) {
916 return mat3 (m[0] - n[0], m[1] - n[1], m[2] - n[2]);
919 mat3 __operator / (const mat3 m, const mat3 n) {
920 return mat3 (m[0] / n[0], m[1] / n[1], m[2] / n[2]);
923 mat4 __operator + (const mat4 m, const mat4 n) {
924 return mat4 (m[0] + n[0], m[1] + n[1], m[2] + n[2], m[3] + n[3]);
927 mat4 __operator - (const mat4 m, const mat4 n) {
928 return mat4 (m[0] - n[0], m[1] - n[1], m[2] - n[2], m[3] - n[3]);
931 mat4 __operator / (const mat4 m, const mat4 n) {
932 return mat4 (m[0] / n[0], m[1] / n[1], m[2] / n[2], m[3] / n[3]);
935 vec2 __operator + (const float a, const vec2 u) {
936 return vec2 (a + u.x, a + u.y);
939 vec2 __operator + (const vec2 v, const float b) {
940 return vec2 (v.x + b, v.y + b);
943 vec2 __operator - (const float a, const vec2 u) {
944 return vec2 (a - u.x, a - u.y);
947 vec2 __operator - (const vec2 v, const float b) {
948 return vec2 (v.x - b, v.y - b);
951 vec2 __operator * (const float a, const vec2 u) {
952 return vec2 (a * u.x, a * u.y);
955 vec2 __operator * (const vec2 v, const float b) {
956 return vec2 (v.x * b, v.y * b);
959 vec2 __operator / (const float a, const vec2 u) {
960 return vec2 (a / u.x, a / u.y);
963 vec2 __operator / (const vec2 v, const float b) {
964 return vec2 (v.x / b, v.y / b);
967 vec3 __operator + (const float a, const vec3 u) {
968 return vec3 (a + u.x, a + u.y, a + u.z);
971 vec3 __operator + (const vec3 v, const float b) {
972 return vec3 (v.x + b, v.y + b, v.z + b);
975 vec3 __operator - (const float a, const vec3 u) {
976 return vec3 (a - u.x, a - u.y, a - u.z);
979 vec3 __operator - (const vec3 v, const float b) {
980 return vec3 (v.x - b, v.y - b, v.z - b);
983 vec3 __operator * (const float a, const vec3 u) {
984 return vec3 (a * u.x, a * u.y, a * u.z);
987 vec3 __operator * (const vec3 v, const float b) {
988 return vec3 (v.x * b, v.y * b, v.z * b);
991 vec3 __operator / (const float a, const vec3 u) {
992 return vec3 (a / u.x, a / u.y, a / u.z);
995 vec3 __operator / (const vec3 v, const float b) {
996 return vec3 (v.x / b, v.y / b, v.z / b);
999 vec4 __operator + (const float a, const vec4 u) {
1000 return vec4 (a + u.x, a + u.y, a + u.z, a + u.w);
1003 vec4 __operator + (const vec4 v, const float b) {
1004 return vec4 (v.x + b, v.y + b, v.z + b, v.w + b);
1007 vec4 __operator - (const float a, const vec4 u) {
1008 return vec4 (a - u.x, a - u.y, a - u.z, a - u.w);
1011 vec4 __operator - (const vec4 v, const float b) {
1012 return vec4 (v.x - b, v.y - b, v.z - b, v.w - b);
1015 vec4 __operator * (const float a, const vec4 u) {
1016 return vec4 (a * u.x, a * u.y, a * u.z, a * u.w);
1019 vec4 __operator * (const vec4 v, const float b) {
1020 return vec4 (v.x * b, v.y * b, v.z * b, v.w * b);
1023 vec4 __operator / (const float a, const vec4 u) {
1024 return vec4 (a / u.x, a / u.y, a / u.z, a / u.w);
1027 vec4 __operator / (const vec4 v, const float b) {
1028 return vec4 (v.x / b, v.y / b, v.z / b, v.w / b);
1031 mat2 __operator + (const float a, const mat2 n) {
1032 return mat2 (a + n[0], a + n[1]);
1035 mat2 __operator + (const mat2 m, const float b) {
1036 return mat2 (m[0] + b, m[1] + b);
1039 mat2 __operator - (const float a, const mat2 n) {
1040 return mat2 (a - n[0], a - n[1]);
1043 mat2 __operator - (const mat2 m, const float b) {
1044 return mat2 (m[0] - b, m[1] - b);
1047 mat2 __operator * (const float a, const mat2 n) {
1048 return mat2 (a * n[0], a * n[1]);
1051 mat2 __operator * (const mat2 m, const float b) {
1052 return mat2 (m[0] * b, m[1] * b);
1055 mat2 __operator / (const float a, const mat2 n) {
1056 return mat2 (a / n[0], a / n[1]);
1059 mat2 __operator / (const mat2 m, const float b) {
1060 return mat2 (m[0] / b, m[1] / b);
1063 mat3 __operator + (const float a, const mat3 n) {
1064 return mat3 (a + n[0], a + n[1], a + n[2]);
1067 mat3 __operator + (const mat3 m, const float b) {
1068 return mat3 (m[0] + b, m[1] + b, m[2] + b);
1071 mat3 __operator - (const float a, const mat3 n) {
1072 return mat3 (a - n[0], a - n[1], a - n[2]);
1075 mat3 __operator - (const mat3 m, const float b) {
1076 return mat3 (m[0] - b, m[1] - b, m[2] - b);
1079 mat3 __operator * (const float a, const mat3 n) {
1080 return mat3 (a * n[0], a * n[1], a * n[2]);
1083 mat3 __operator * (const mat3 m, const float b) {
1084 return mat3 (m[0] * b, m[1] * b, m[2] * b);
1087 mat3 __operator / (const float a, const mat3 n) {
1088 return mat3 (a / n[0], a / n[1], a / n[2]);
1091 mat3 __operator / (const mat3 m, const float b) {
1092 return mat3 (m[0] / b, m[1] / b, m[2] / b);
1095 mat4 __operator + (const float a, const mat4 n) {
1096 return mat4 (a + n[0], a + n[1], a + n[2], a + n[3]);
1099 mat4 __operator + (const mat4 m, const float b) {
1100 return mat4 (m[0] + b, m[1] + b, m[2] + b, m[3] + b);
1103 mat4 __operator - (const float a, const mat4 n) {
1104 return mat4 (a - n[0], a - n[1], a - n[2], a - n[3]);
1107 mat4 __operator - (const mat4 m, const float b) {
1108 return mat4 (m[0] - b, m[1] - b, m[2] - b, m[3] - b);
1111 mat4 __operator * (const float a, const mat4 n) {
1112 return mat4 (a * n[0], a * n[1], a * n[2], a * n[3]);
1115 mat4 __operator * (const mat4 m, const float b) {
1116 return mat4 (m[0] * b, m[1] * b, m[2] * b, m[3] * b);
1119 mat4 __operator / (const float a, const mat4 n) {
1120 return mat4 (a / n[0], a / n[1], a / n[2], a / n[3]);
1123 mat4 __operator / (const mat4 m, const float b) {
1124 return mat4 (m[0] / b, m[1] / b, m[2] / b, m[3] / b);
1127 ivec2 __operator + (const int a, const ivec2 u) {
1128 return ivec2 (a) + u;
1131 ivec2 __operator + (const ivec2 v, const int b) {
1132 return v + ivec2 (b);
1135 ivec2 __operator - (const int a, const ivec2 u) {
1136 return ivec2 (a) - u;
1139 ivec2 __operator - (const ivec2 v, const int b) {
1140 return v - ivec2 (b);
1143 ivec2 __operator * (const int a, const ivec2 u) {
1144 return ivec2 (a) * u;
1147 ivec2 __operator * (const ivec2 v, const int b) {
1148 return v * ivec2 (b);
1151 ivec2 __operator / (const int a, const ivec2 u) {
1152 return ivec2 (a) / u;
1155 ivec2 __operator / (const ivec2 v, const int b) {
1156 return v / ivec2 (b);
1159 ivec3 __operator + (const int a, const ivec3 u) {
1160 return ivec3 (a) + u;
1163 ivec3 __operator + (const ivec3 v, const int b) {
1164 return v + ivec3 (b);
1167 ivec3 __operator - (const int a, const ivec3 u) {
1168 return ivec3 (a) - u;
1171 ivec3 __operator - (const ivec3 v, const int b) {
1172 return v - ivec3 (b);
1175 ivec3 __operator * (const int a, const ivec3 u) {
1176 return ivec3 (a) * u;
1179 ivec3 __operator * (const ivec3 v, const int b) {
1180 return v * ivec3 (b);
1183 ivec3 __operator / (const int a, const ivec3 u) {
1184 return ivec3 (a) / u;
1187 ivec3 __operator / (const ivec3 v, const int b) {
1188 return v / ivec3 (b);
1191 ivec4 __operator + (const int a, const ivec4 u) {
1192 return ivec4 (a) + u;
1195 ivec4 __operator + (const ivec4 v, const int b) {
1196 return v + ivec4 (b);
1199 ivec4 __operator - (const int a, const ivec4 u) {
1200 return ivec4 (a) - u;
1203 ivec4 __operator - (const ivec4 v, const int b) {
1204 return v - ivec4 (b);
1207 ivec4 __operator * (const int a, const ivec4 u) {
1208 return ivec4 (a) * u;
1211 ivec4 __operator * (const ivec4 v, const int b) {
1212 return v * ivec4 (b);
1215 ivec4 __operator / (const int a, const ivec4 u) {
1216 return ivec4 (a) / u;
1219 ivec4 __operator / (const ivec4 v, const int b) {
1220 return v / ivec4 (b);
1223 vec2 __operator - (const vec2 v) {
1224 return vec2 (-v.x, -v.y);
1227 vec3 __operator - (const vec3 v) {
1228 return vec3 (-v.x, -v.y, -v.z);
1231 vec4 __operator - (const vec4 v) {
1232 return vec4 (-v.x, -v.y, -v.z, -v.w);
1235 ivec2 __operator - (const ivec2 v) {
1236 return ivec2 (-v.x, -v.y);
1239 ivec3 __operator - (const ivec3 v) {
1240 return ivec3 (-v.x, -v.y, -v.z);
1243 ivec4 __operator - (const ivec4 v) {
1244 return ivec4 (-v.x, -v.y, -v.z, -v.w);
1247 mat2 __operator - (const mat2 m) {
1248 return mat2 (-m[0], -m[1]);
1251 mat3 __operator - (const mat3 m) {
1252 return mat3 (-m[0], -m[1], -m[2]);
1255 mat4 __operator - (const mat4 m) {
1256 return mat4 (-m[0], -m[1], -m[2], -m[3]);
1259 void __operator -- (inout float a) {
1263 void __operator -- (inout int a) {
1267 void __operator -- (inout vec2 v) {
1272 void __operator -- (inout vec3 v) {
1278 void __operator -- (inout vec4 v) {
1285 void __operator -- (inout ivec2 v) {
1290 void __operator -- (inout ivec3 v) {
1296 void __operator -- (inout ivec4 v) {
1303 void __operator -- (inout mat2 m) {
1308 void __operator -- (inout mat3 m) {
1314 void __operator -- (inout mat4 m) {
1321 void __operator ++ (inout float a) {
1325 void __operator ++ (inout int a) {
1329 void __operator ++ (inout vec2 v) {
1334 void __operator ++ (inout vec3 v) {
1340 void __operator ++ (inout vec4 v) {
1347 void __operator ++ (inout ivec2 v) {
1352 void __operator ++ (inout ivec3 v) {
1358 void __operator ++ (inout ivec4 v) {
1365 void __operator ++ (inout mat2 m) {
1370 void __operator ++ (inout mat3 m) {
1376 void __operator ++ (inout mat4 m) {
1384 // NOTE: postfix increment and decrement operators take additional dummy int parameter to
1385 // distinguish their prototypes from prefix ones.
1388 float __operator -- (inout float a, const int) {
1395 int __operator -- (inout int a, const int) {
1402 vec2 __operator -- (inout vec2 v, const int) {
1403 return vec2 (v.x--, v.y--);
1406 vec3 __operator -- (inout vec3 v, const int) {
1407 return vec3 (v.x--, v.y--, v.z--);
1410 vec4 __operator -- (inout vec4 v, const int) {
1411 return vec4 (v.x--, v.y--, v.z--, v.w--);
1414 ivec2 __operator -- (inout ivec2 v, const int) {
1415 return ivec2 (v.x--, v.y--);
1418 ivec3 __operator -- (inout ivec3 v, const int) {
1419 return ivec3 (v.x--, v.y--, v.z--);
1422 ivec4 __operator -- (inout ivec4 v, const int) {
1423 return ivec4 (v.x--, v.y--, v.z--, v.w--);
1426 mat2 __operator -- (inout mat2 m, const int) {
1427 return mat2 (m[0]--, m[1]--);
1430 mat3 __operator -- (inout mat3 m, const int) {
1431 return mat3 (m[0]--, m[1]--, m[2]--);
1434 mat4 __operator -- (inout mat4 m, const int) {
1435 return mat4 (m[0]--, m[1]--, m[2]--, m[3]--);
1438 float __operator ++ (inout float a, const int) {
1445 int __operator ++ (inout int a, const int) {
1452 vec2 __operator ++ (inout vec2 v, const int) {
1453 return vec2 (v.x++, v.y++);
1456 vec3 __operator ++ (inout vec3 v, const int) {
1457 return vec3 (v.x++, v.y++, v.z++);
1460 vec4 __operator ++ (inout vec4 v, const int) {
1461 return vec4 (v.x++, v.y++, v.z++, v.w++);
1464 ivec2 __operator ++ (inout ivec2 v, const int) {
1465 return ivec2 (v.x++, v.y++);
1468 ivec3 __operator ++ (inout ivec3 v, const int) {
1469 return ivec3 (v.x++, v.y++, v.z++);
1472 ivec4 __operator ++ (inout ivec4 v, const int) {
1473 return ivec4 (v.x++, v.y++, v.z++, v.w++);
1476 mat2 __operator ++ (inout mat2 m, const int) {
1477 return mat2 (m[0]++, m[1]++);
1480 mat3 __operator ++ (inout mat3 m, const int) {
1481 return mat3 (m[0]++, m[1]++, m[2]++);
1484 mat4 __operator ++ (inout mat4 m, const int) {
1485 return mat4 (m[0]++, m[1]++, m[2]++, m[3]++);
1488 bool __operator < (const float a, const float b) {
1490 __asm float_less c, a, b;
1494 bool __operator < (const int a, const int b) {
1495 return float (a) < float (b);
1498 bool __operator > (const float a, const float b) {
1500 __asm float_less c, b, a;
1504 bool __operator > (const int a, const int b) {
1505 return float (a) > float (b);
1508 bool __operator >= (const float a, const float b) {
1510 __asm float_less g, b, a;
1511 __asm float_equal e, a, b;
1515 bool __operator >= (const int a, const int b) {
1516 return float (a) >= float (b);
1519 bool __operator <= (const float a, const float b) {
1521 __asm float_less g, a, b;
1522 __asm float_equal e, a, b;
1526 bool __operator <= (const int a, const int b) {
1527 return float (a) <= float (b);
1530 bool __operator ^^ (const bool a, const bool b) {
1535 // These operators are handled internally by the compiler:
1537 // bool __operator && (bool a, bool b) {
1538 // return a ? b : false;
1540 // bool __operator || (bool a, bool b) {
1541 // return a ? true : b;
1545 bool __operator ! (const bool a) {
1550 // mesa-specific extension functions.
1553 void print (const float f) {
1554 __asm float_print f;
1557 void print (const int i) {
1561 void print (const bool b) {
1565 void print (const vec2 v) {
1570 void print (const vec3 v) {
1576 void print (const vec4 v) {
1583 void print (const ivec2 v) {
1588 void print (const ivec3 v) {
1594 void print (const ivec4 v) {
1601 void print (const bvec2 v) {
1606 void print (const bvec3 v) {
1612 void print (const bvec4 v) {
1619 void print (const mat2 m) {
1624 void print (const mat3 m) {
1630 void print (const mat4 m) {
1637 void print (const sampler1D e) {
1641 void print (const sampler2D e) {
1645 void print (const sampler3D e) {
1649 void print (const samplerCube e) {
1653 void print (const sampler1DShadow e) {
1657 void print (const sampler2DShadow e) {