2 * Mesa 3-D graphics library
5 * Copyright (C) 2006 Brian Paul All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 // This file defines nearly all constructors and operators for built-in data
27 // types, using extended language syntax. In general, compiler treats
28 // constructors and operators as ordinary functions with some exceptions.
29 // For example, the language does not allow functions to be called in
30 // constant expressions - here the exception is made to allow it.
32 // Each implementation provides its own version of this file. Each
33 // implementation can define the required set of operators and constructors
34 // in its own fashion.
36 // The extended language syntax is only present when compiling this file.
37 // It is implicitly included at the very beginning of the compiled shader,
38 // so no built-in functions can be used.
40 // To communicate with the implementation, a special extended "__asm" keyword
41 // is used, followed by an instruction name (any valid identifier), a
42 // destination variable identifier and a list of zero or more source
43 // variable identifiers.
45 // A variable identifier is a variable name declared earlier in the code
46 // (as a function parameter, local or global variable).
48 // An instruction name designates an instruction that must be exported
49 // by the implementation. Each instruction receives data from source
50 // variable identifiers and returns data in the destination variable
53 // It is up to the implementation how to define a particular operator
54 // or constructor. If it is expected to being used rarely, it can be
55 // defined in terms of other operators and constructors,
58 // ivec2 __operator + (const ivec2 x, const ivec2 y) {
59 // return ivec2 (x[0] + y[0], x[1] + y[1]);
62 // If a particular operator or constructor is expected to be used very
63 // often or is an atomic operation (that is, an operation that cannot be
64 // expressed in terms of other operations or would create a dependency
65 // cycle) it must be defined using one or more __asm constructs.
67 // Each implementation must define constructors for all scalar types
68 // (bool, float, int). There are 9 scalar-to-scalar constructors
69 // (including identity constructors). However, since the language
70 // introduces special constructors (like matrix constructor with a single
71 // scalar value), implementations must also implement these cases.
72 // The compiler provides the following algorithm when resolving a constructor:
73 // - try to find a constructor with a prototype matching ours,
74 // - if no constructor is found and this is a scalar-to-scalar constructor,
76 // - if a constructor is found, execute it and return,
77 // - count the size of the constructor parameter list - if it is less than
78 // the size of our constructor's type, raise an error,
79 // - for each parameter in the list do a recursive constructor matching for
80 // appropriate scalar fields in the constructed variable,
82 // Each implementation must also define a set of operators that deal with
83 // built-in data types.
84 // There are four kinds of operators:
85 // 1) Operators that are implemented only by the compiler: "()" (function
86 // call), "," (sequence) and "?:" (selection).
87 // 2) Operators that are implemented by the compiler by expressing it in
88 // terms of other operators:
89 // - "." (field selection) - translated to subscript access,
90 // - "&&" (logical and) - translated to "<left_expr> ? <right_expr> :
92 // - "||" (logical or) - translated to "<left_expr> ? true : <right_expr>",
93 // 3) Operators that can be defined by the implementation and if the required
94 // prototype is not found, standard behaviour is used:
95 // - "==", "!=", "=" (equality, assignment) - compare or assign
96 // matching fields one-by-one;
97 // note that at least operators for scalar data types must be defined
98 // by the implementation to get it work,
99 // 4) All other operators not mentioned above. If no required prototype is
100 // found, an error is raised. An implementation must follow the language
101 // specification to provide all valid operator prototypes.
106 //// Basic, scalar constructors/casts
108 int __constructor(const float f)
110 __asm float_to_int __retVal, f;
113 bool __constructor(const int i)
115 const float zero = 0.0;
116 __asm vec4_seq __retVal, i, zero;
119 bool __constructor(const float f)
121 const float zero = 0.0;
122 __asm vec4_seq __retVal, i, zero;
125 int __constructor(const bool b)
130 float __constructor(const bool b)
135 float __constructor(const int i)
137 __asm int_to_float __retVal, i;
140 bool __constructor(const bool b)
145 int __constructor(const int i)
150 float __constructor(const float f)
156 //// vec2 constructors
158 vec2 __constructor(const float x, const float y)
164 vec2 __constructor(const float f)
169 vec2 __constructor(const int i)
174 vec2 __constructor(const bool b)
179 vec2 __constructor(const vec3 v)
184 vec2 __constructor(const vec4 v)
190 //// vec3 constructors
192 vec3 __constructor(const float x, const float y, const float z)
199 vec3 __constructor(const float f)
201 __retVal.xyz = f.xxx;
204 vec3 __constructor(const int i)
206 __asm int_to_float __retVal.xyz, i.xxx;
209 vec3 __constructor(const bool b)
211 __retVal.xyz = b.xxx;
214 vec3 __constructor(const vec4 v)
216 __retVal.xyz = v.xyz;
220 //// vec4 constructors
222 vec4 __constructor(const float x, const float y, const float z, const float w)
230 vec4 __constructor(const float f)
235 vec4 __constructor(const int i)
240 vec4 __constructor(const bool b)
245 vec4 __constructor(const vec3 v3, const float f)
247 // XXX this constructor shouldn't be needed anymore
253 //// ivec2 constructors
255 ivec2 __constructor(const int i, const int j)
261 ivec2 __constructor(const int i)
266 ivec2 __constructor(const float f)
268 __asm float_to_int __retVal.xy, f.xx;
271 ivec2 __constructor(const bool b)
273 __asm float_to_int __retVal.xy, b.xx;
277 //// ivec3 constructors
279 ivec3 __constructor(const int i, const int j, const int k)
286 ivec3 __constructor(const int i)
288 __retVal.xyz = i.xxx;
291 ivec3 __constructor(const float f)
293 __retVal.xyz = f.xxx;
296 ivec3 __constructor(const bool b)
298 __retVal.xyz = b.xxx;
302 //// ivec4 constructors
304 ivec4 __constructor(const int x, const int y, const int z, const int w)
312 ivec4 __constructor(const int i)
317 ivec4 __constructor(const float f)
319 __asm float_to_int __retVal, f.xxxx;
322 ivec4 __constructor(const bool b)
328 //// bvec2 constructors
330 bvec2 __constructor(const bool b1, const bool b2)
336 bvec2 __constructor(const bool b)
341 bvec2 __constructor(const float f)
343 const vec2 zero = vec2(0.0, 0.0);
344 __asm vec4_seq __retVal.xy, f.xx, zero;
347 bvec2 __constructor(const int i)
349 const ivec2 zero = ivec2(0, 0);
350 __asm vec4_seq __retVal.xy, i.xx, zero;
354 //// bvec3 constructors
356 bvec3 __constructor(const bool b1, const bool b2, const bool b3)
363 bvec3 __constructor(const bool b)
365 __retVal.xyz = b.xxx;
368 bvec3 __constructor(const float f)
370 const vec3 zero = vec3(0.0, 0.0, 0.0);
371 __asm vec4_seq __retVal.xyz, f.xxx, zero;
374 bvec3 __constructor(const int i)
376 const ivec3 zero = ivec3(0, 0, 0);
377 __asm vec4_seq __retVal.xyz, i.xxx, zero;
381 //// bvec4 constructors
383 bvec4 __constructor(const bool b1, const bool b2, const bool b3, const bool b4)
391 bvec4 __constructor(const bool b)
393 __retVal.xyzw = b.xxxx;
396 bvec4 __constructor(const float f)
398 const vec4 zero = vec4(0.0, 0.0, 0.0, 0.0);
399 __asm vec4_seq __retVal, f.xxxx, zero;
402 bvec4 __constructor(const int i)
404 const ivec4 zero = ivec4(0, 0, 0, 0);
405 __asm vec4_seq __retVal, i.xxxx, zero;
410 //// mat2 constructors
412 mat2 __constructor(const float m00, const float m10,
413 const float m01, const float m11)
421 mat2 __constructor(const float f)
429 mat2 __constructor(const int i)
431 return mat2(float(i));
434 mat2 __constructor(const bool b)
436 return mat2(float(b));
439 mat2 __constructor(const vec2 c0, const vec2 c1)
446 //// mat3 constructors
448 mat3 __constructor(const float m00, const float m10, const float m20,
449 const float m01, const float m11, const float m21,
450 const float m02, const float m12, const float m22)
463 mat3 __constructor(const float f)
465 vec2 v = vec2(f, 0.0);
471 mat3 __constructor(const int i)
473 return mat3(float(i));
476 mat3 __constructor(const bool b)
478 return mat3(float(b));
481 mat3 __constructor(const vec3 c0, const vec3 c1, const vec3 c2)
489 //// mat4 constructors
491 mat4 __constructor(const float m00, const float m10, const float m20, const float m30,
492 const float m01, const float m11, const float m21, const float m31,
493 const float m02, const float m12, const float m22, const float m32,
494 const float m03, const float m13, const float m23, const float m33)
515 mat4 __constructor(const float f)
517 vec2 v = vec2(f, 0.0);
518 __retVal[0] = v.xyyy;
519 __retVal[1] = v.yxyy;
520 __retVal[2] = v.yyxy;
521 __retVal[3] = v.yyyx;
524 mat4 __constructor(const int i)
526 return mat4(float(i));
529 mat4 __constructor(const bool b)
531 return mat4(float(b));
534 mat4 __constructor(const vec4 c0, const vec4 c1, const vec4 c2, const vec4 c3)
544 //// Basic int operators
546 int __operator + (const int a, const int b)
548 // XXX If we ever have int registers, we'll do something like this:
549 // XXX For now, mostly treat ints as floats.
551 // __asm int_to_float x, a;
552 // __asm int_to_float y, b;
553 // __asm vec4_add x.x, x.x, y.x;
554 // __asm float_to_int __retVal, x;
556 __asm vec4_add x, a, b;
557 __asm float_to_int __retVal, x;
560 int __operator - (const int a, const int b)
563 __asm vec4_subtract x, a, b;
564 __asm float_to_int __retVal, x;
567 int __operator * (const int a, const int b)
570 __asm vec4_multiply x, a, b;
571 __asm float_to_int __retVal, x;
574 int __operator / (const int a, const int b)
577 __asm float_rcp bInv, b;
578 __asm vec4_multiply x, a, bInv;
579 __asm float_to_int __retVal, x;
583 //// Basic ivec2 operators
585 ivec2 __operator + (const ivec2 a, const ivec2 b)
588 __asm vec4_add x, a, b;
589 __asm float_to_int __retVal, x;
592 ivec2 __operator - (const ivec2 a, const ivec2 b)
595 __asm vec4_subtract x, a, b;
596 __asm float_to_int __retVal, x;
599 ivec2 __operator * (const ivec2 a, const ivec2 b)
602 __asm vec4_multiply x, a, b;
603 __asm float_to_int __retVal, x;
606 ivec2 __operator / (const ivec2 a, const ivec2 b)
609 __asm float_rcp bInv.x, b.x;
610 __asm float_rcp bInv.y, b.y;
611 __asm vec4_multiply x, a, bInv;
612 __asm float_to_int __retVal, x;
616 //// Basic ivec3 operators
618 ivec3 __operator + (const ivec3 a, const ivec3 b)
621 __asm vec4_add x, a, b;
622 __asm float_to_int __retVal, x;
625 ivec3 __operator - (const ivec3 a, const ivec3 b)
628 __asm vec4_subtract x, a, b;
629 __asm float_to_int __retVal, x;
632 ivec3 __operator * (const ivec3 a, const ivec3 b)
635 __asm vec4_multiply x, a, b;
636 __asm float_to_int __retVal, x;
639 ivec3 __operator / (const ivec3 a, const ivec3 b)
642 __asm float_rcp bInv.x, b.x;
643 __asm float_rcp bInv.y, b.y;
644 __asm float_rcp bInv.z, b.z;
645 __asm vec4_multiply x, a, bInv;
646 __asm float_to_int __retVal, x;
650 //// Basic ivec4 operators
652 ivec4 __operator + (const ivec4 a, const ivec4 b)
655 __asm vec4_add x, a, b;
656 __asm float_to_int __retVal, x;
659 ivec4 __operator - (const ivec4 a, const ivec4 b)
662 __asm vec4_subtract x, a, b;
663 __asm float_to_int __retVal, x;
666 ivec4 __operator * (const ivec4 a, const ivec4 b)
669 __asm vec4_multiply x, a, b;
670 __asm float_to_int __retVal, x;
673 ivec4 __operator / (const ivec4 a, const ivec4 b)
676 __asm float_rcp bInv.x, b.x;
677 __asm float_rcp bInv.y, b.y;
678 __asm float_rcp bInv.z, b.z;
679 __asm float_rcp bInv.w, b.w;
680 __asm vec4_multiply x, a, bInv;
681 __asm float_to_int __retVal, x;
685 //// Basic float operators
687 float __operator + (const float a, const float b)
689 __asm vec4_add __retVal.x, a, b;
692 float __operator - (const float a, const float b)
694 __asm vec4_subtract __retVal.x, a, b;
697 float __operator * (const float a, const float b)
699 __asm vec4_multiply __retVal.x, a, b;
702 float __operator / (const float a, const float b)
705 __asm float_rcp bInv.x, b.x;
706 __asm vec4_multiply __retVal.x, a, bInv;
710 //// Basic vec2 operators
712 vec2 __operator + (const vec2 v, const vec2 u)
714 __asm vec4_add __retVal.xy, v, u;
717 vec2 __operator - (const vec2 v, const vec2 u)
719 __asm vec4_subtract __retVal.xy, v, u;
722 vec2 __operator * (const vec2 v, const vec2 u)
724 __asm vec4_multiply __retVal.xy, v, u;
727 vec2 __operator / (const vec2 v, const vec2 u)
730 __asm float_rcp w.x, u.x;
731 __asm float_rcp w.y, u.y;
732 __asm vec4_multiply __retVal.xy, v, w;
736 //// Basic vec3 operators
738 vec3 __operator + (const vec3 v, const vec3 u)
740 __asm vec4_add __retVal.xyz, v, u;
743 vec3 __operator - (const vec3 v, const vec3 u)
745 __asm vec4_subtract __retVal.xyz, v, u;
748 vec3 __operator * (const vec3 v, const vec3 u)
750 __asm vec4_multiply __retVal.xyz, v, u;
753 vec3 __operator / (const vec3 v, const vec3 u)
756 __asm float_rcp w.x, u.x;
757 __asm float_rcp w.y, u.y;
758 __asm float_rcp w.z, u.z;
759 __asm vec4_multiply __retVal.xyz, v, w;
763 //// Basic vec4 operators
765 vec4 __operator + (const vec4 v, const vec4 u)
767 __asm vec4_add __retVal, v, u;
770 vec4 __operator - (const vec4 v, const vec4 u)
772 __asm vec4_subtract __retVal, v, u;
775 vec4 __operator * (const vec4 v, const vec4 u)
777 __asm vec4_multiply __retVal, v, u;
780 vec4 __operator / (const vec4 v, const vec4 u)
783 __asm float_rcp w.x, u.x;
784 __asm float_rcp w.y, u.y;
785 __asm float_rcp w.z, u.z;
786 __asm float_rcp w.w, u.w;
787 __asm vec4_multiply __retVal, v, w;
793 //// Basic vec2/float operators
795 vec2 __operator + (const float a, const vec2 u)
797 __asm vec4_add __retVal.xy, a.xx, u.xy;
800 vec2 __operator + (const vec2 v, const float b)
802 __asm vec4_add __retVal.xy, v.xy, b.xx;
805 vec2 __operator - (const float a, const vec2 u)
807 __asm vec4_subtract __retVal.xy, a.xx, u.xy;
810 vec2 __operator - (const vec2 v, const float b)
812 __asm vec4_subtract __retVal.xy, v.xy, b.xx;
815 vec2 __operator * (const float a, const vec2 u)
817 __asm vec4_multiply __retVal.xy, a.xx, u.xy;
820 vec2 __operator * (const vec2 v, const float b)
822 __asm vec4_multiply __retVal.xy, v.xy, b.xx;
825 vec2 __operator / (const float a, const vec2 u)
828 __asm float_rcp invU.x, u.x;
829 __asm float_rcp invU.y, u.y;
830 __asm vec4_multiply __retVal.xy, a.xx, invU.xy;
833 vec2 __operator / (const vec2 v, const float b)
836 __asm float_rcp invB, b;
837 __asm vec4_multiply __retVal.xy, v.xy, invB.xx;
841 //// Basic vec3/float operators
843 vec3 __operator + (const float a, const vec3 u)
845 __asm vec4_add __retVal.xyz, a.xxx, u.xyz;
848 vec3 __operator + (const vec3 v, const float b)
850 __asm vec4_add __retVal.xyz, v.xyz, b.xxx;
853 vec3 __operator - (const float a, const vec3 u)
855 __asm vec4_subtract __retVal.xyz, a.xxx, u.xyz;
858 vec3 __operator - (const vec3 v, const float b)
860 __asm vec4_subtract __retVal.xyz, v.xyz, b.xxx;
863 vec3 __operator * (const float a, const vec3 u)
865 __asm vec4_multiply __retVal.xyz, a.xxx, u.xyz;
868 vec3 __operator * (const vec3 v, const float b)
870 __asm vec4_multiply __retVal.xyz, v.xyz, b.xxx;
873 vec3 __operator / (const float a, const vec3 u)
876 __asm float_rcp invU.x, u.x;
877 __asm float_rcp invU.y, u.y;
878 __asm float_rcp invU.z, u.z;
879 __asm vec4_multiply __retVal.xyz, a.xxx, invU.xyz;
882 vec3 __operator / (const vec3 v, const float b)
885 __asm float_rcp invB, b;
886 __asm vec4_multiply __retVal.xyz, v.xyz, invB.xxx;
890 //// Basic vec4/float operators
892 vec4 __operator + (const float a, const vec4 u)
894 __asm vec4_add __retVal, a.xxxx, u;
897 vec4 __operator + (const vec4 v, const float b)
899 __asm vec4_add __retVal, v, b.xxxx;
902 vec4 __operator - (const float a, const vec4 u)
904 __asm vec4_subtract __retVal, a.xxxx, u;
907 vec4 __operator - (const vec4 v, const float b)
909 __asm vec4_subtract __retVal, v, b.xxxx;
912 vec4 __operator * (const float a, const vec4 u)
914 __asm vec4_multiply __retVal, a.xxxx, u;
917 vec4 __operator * (const vec4 v, const float b)
919 __asm vec4_multiply __retVal, v, b.xxxx;
922 vec4 __operator / (const float a, const vec4 u)
925 __asm float_rcp invU.x, u.x;
926 __asm float_rcp invU.y, u.y;
927 __asm float_rcp invU.z, u.z;
928 __asm float_rcp invU.w, u.w;
929 __asm vec4_multiply __retVal, a.xxxx, invU;
932 vec4 __operator / (const vec4 v, const float b)
935 __asm float_rcp invB, b;
936 __asm vec4_multiply __retVal, v, invB.xxxx;
941 //// Basic ivec2/int operators
943 ivec2 __operator + (const int a, const ivec2 u)
945 __retVal = ivec2(a) + u;
948 ivec2 __operator + (const ivec2 v, const int b)
950 __retVal = v + ivec2(b);
953 ivec2 __operator - (const int a, const ivec2 u)
955 __retVal = ivec2(a) - u;
958 ivec2 __operator - (const ivec2 v, const int b)
960 __retVal = v - ivec2(b);
963 ivec2 __operator * (const int a, const ivec2 u)
965 __retVal = ivec2(a) * u;
968 ivec2 __operator * (const ivec2 v, const int b)
970 __retVal = v * ivec2(b);
973 ivec2 __operator / (const int a, const ivec2 u)
975 __retVal = ivec2(a) / u;
978 ivec2 __operator / (const ivec2 v, const int b)
980 __retVal = v / ivec2(b);
984 //// Basic ivec3/int operators
986 ivec3 __operator + (const int a, const ivec3 u)
988 __retVal = ivec3(a) + u;
991 ivec3 __operator + (const ivec3 v, const int b)
993 __retVal = v + ivec3(b);
996 ivec3 __operator - (const int a, const ivec3 u)
998 __retVal = ivec3(a) - u;
1001 ivec3 __operator - (const ivec3 v, const int b)
1003 __retVal = v - ivec3(b);
1006 ivec3 __operator * (const int a, const ivec3 u)
1008 __retVal = ivec3(a) * u;
1011 ivec3 __operator * (const ivec3 v, const int b)
1013 __retVal = v * ivec3(b);
1016 ivec3 __operator / (const int a, const ivec3 u)
1018 __retVal = ivec3(a) / u;
1021 ivec3 __operator / (const ivec3 v, const int b)
1023 __retVal = v / ivec3(b);
1027 //// Basic ivec4/int operators
1029 ivec4 __operator + (const int a, const ivec4 u)
1031 __retVal = ivec4(a) + u;
1034 ivec4 __operator + (const ivec4 v, const int b)
1036 __retVal = v + ivec4(b);
1039 ivec4 __operator - (const int a, const ivec4 u)
1041 __retVal = ivec4(a) - u;
1044 ivec4 __operator - (const ivec4 v, const int b)
1046 __retVal = v - ivec4(b);
1049 ivec4 __operator * (const int a, const ivec4 u)
1051 __retVal = ivec4(a) * u;
1054 ivec4 __operator * (const ivec4 v, const int b)
1056 __retVal = v * ivec4(b);
1059 ivec4 __operator / (const int a, const ivec4 u)
1061 __retVal = ivec4(a) / u;
1064 ivec4 __operator / (const ivec4 v, const int b)
1066 __retVal = v / ivec4(b);
1072 //// Unary negation operator
1074 int __operator - (const int a)
1076 __asm vec4_negate __retVal.x, a;
1079 ivec2 __operator - (const ivec2 v)
1081 __asm vec4_negate __retVal, v;
1084 ivec3 __operator - (const ivec3 v)
1086 __asm vec4_negate __retVal, v;
1089 ivec4 __operator - (const ivec4 v)
1091 __asm vec4_negate __retVal, v;
1094 float __operator - (const float a)
1096 __asm vec4_negate __retVal.x, a;
1099 vec2 __operator - (const vec2 v)
1101 __asm vec4_negate __retVal.xy, v.xy;
1104 vec3 __operator - (const vec3 v)
1106 __asm vec4_negate __retVal.xyz, v.xyz;
1109 vec4 __operator - (const vec4 v)
1111 __asm vec4_negate __retVal, v;
1114 mat2 __operator - (const mat2 m)
1116 __retVal[0] = -m[0];
1117 __retVal[1] = -m[1];
1120 mat3 __operator - (const mat3 m)
1122 __retVal[0] = -m[0];
1123 __retVal[1] = -m[1];
1124 __retVal[2] = -m[2];
1127 mat4 __operator - (const mat4 m)
1129 __retVal[0] = -m[0];
1130 __retVal[1] = -m[1];
1131 __retVal[2] = -m[2];
1132 __retVal[3] = -m[3];
1139 float dot(const float a, const float b)
1144 float dot(const vec2 a, const vec2 b)
1146 __retVal = a.x * b.x + a.y * b.y;
1149 float dot(const vec3 a, const vec3 b)
1151 __asm vec3_dot __retVal, a, b;
1154 float dot(const vec4 a, const vec4 b)
1156 __asm vec4_dot __retVal, a, b;
1161 //// int assignment operators
1163 void __operator += (inout int a, const int b)
1165 __asm vec4_add a, a, b;
1168 void __operator -= (inout int a, const int b)
1170 __asm vec4_subtract a, a, b;
1173 void __operator *= (inout int a, const int b)
1175 __asm vec4_multiply a, a, b;
1178 void __operator /= (inout int a, const int b)
1181 __asm float_rcp invB, b;
1182 __asm vec4_multiply a, a, invB;
1186 //// ivec2 assignment operators
1188 void __operator += (inout ivec2 v, const ivec2 u)
1190 __asm vec4_add v, v, u;
1193 void __operator -= (inout ivec2 v, const ivec2 u)
1195 __asm vec4_subtract v, v, u;
1198 void __operator *= (inout ivec2 v, const ivec2 u)
1200 __asm vec4_multiply v, v, u;
1203 void __operator /= (inout ivec2 v, const ivec2 u)
1206 __asm float_rcp inv.x, u.x;
1207 __asm float_rcp inv.y, u.y;
1208 __asm vec4_multiply z, v, inv;
1209 __asm float_to_int __retVal, z;
1213 //// ivec3 assignment operators
1215 void __operator += (inout ivec3 v, const ivec3 u)
1217 __asm vec4_add v, v, u;
1220 void __operator -= (inout ivec3 v, const ivec3 u)
1222 __asm vec4_subtract v, v, u;
1225 void __operator *= (inout ivec3 v, const ivec3 u)
1227 __asm vec4_multiply v, v, u;
1230 void __operator /= (inout ivec3 v, const ivec3 u)
1233 __asm float_rcp inv.x, u.x;
1234 __asm float_rcp inv.y, u.y;
1235 __asm vec4_multiply z, v, inv;
1236 __asm float_to_int __retVal, z;
1240 //// ivec4 assignment operators
1242 void __operator += (inout ivec4 v, const ivec4 u)
1244 __asm vec4_add v, v, u;
1247 void __operator -= (inout ivec4 v, const ivec4 u)
1249 __asm vec4_subtract v, v, u;
1252 void __operator *= (inout ivec4 v, const ivec4 u)
1254 __asm vec4_multiply v, v, u;
1257 void __operator /= (inout ivec4 v, const ivec4 u)
1260 __asm float_rcp inv.x, u.x;
1261 __asm float_rcp inv.y, u.y;
1262 __asm vec4_multiply z, v, inv;
1263 __asm float_to_int __retVal, z;
1267 //// float assignment operators
1269 void __operator += (inout float a, const float b)
1271 __asm vec4_add a.x, a.x, b;
1274 void __operator -= (inout float a, const float b)
1276 __asm vec4_subtract a.x, a, b;
1279 void __operator *= (inout float a, const float b)
1281 __asm vec4_multiply a.x, a, b;
1284 void __operator /= (inout float a, const float b)
1287 __asm float_rcp w.x, b;
1288 __asm vec4_multiply a.x, a, w;
1292 //// vec2 assignment operators
1294 void __operator += (inout vec2 v, const vec2 u)
1296 __asm vec4_add v.xy, v.xy, u.xy;
1299 void __operator -= (inout vec2 v, const vec2 u)
1301 __asm vec4_subtract v.xy, v.xy, u.xy;
1304 void __operator *= (inout vec2 v, const vec2 u)
1306 __asm vec4_multiply v.xy, v.xy, u.xy;
1309 void __operator /= (inout vec2 v, const vec2 u)
1312 __asm float_rcp w.x, u.x;
1313 __asm float_rcp w.y, u.y;
1314 __asm vec4_multiply v.xy, v.xy, w.xy;
1318 //// vec3 assignment operators
1320 void __operator += (inout vec3 v, const vec3 u)
1322 __asm vec4_add v.xyz, v, u;
1325 void __operator -= (inout vec3 v, const vec3 u)
1327 __asm vec4_subtract v.xyz, v, u;
1330 void __operator *= (inout vec3 v, const vec3 u)
1332 __asm vec4_multiply v.xyz, v, u;
1335 void __operator /= (inout vec3 v, const vec3 u)
1338 __asm float_rcp w.x, u.x;
1339 __asm float_rcp w.y, u.y;
1340 __asm float_rcp w.z, u.z;
1341 __asm vec4_multiply v.xyz, v.xyz, w.xyz;
1345 //// vec4 assignment operators
1347 void __operator += (inout vec4 v, const vec4 u)
1349 __asm vec4_add v, v, u;
1352 void __operator -= (inout vec4 v, const vec4 u)
1354 __asm vec4_subtract v, v, u;
1357 void __operator *= (inout vec4 v, const vec4 u)
1359 __asm vec4_multiply v, v, u;
1362 void __operator /= (inout vec4 v, const vec4 u)
1365 __asm float_rcp w.x, u.x;
1366 __asm float_rcp w.y, u.y;
1367 __asm float_rcp w.z, u.z;
1368 __asm float_rcp w.w, u.w;
1369 __asm vec4_multiply v, v, w;
1374 //// ivec2/int assignment operators
1376 void __operator += (inout ivec2 v, const int a)
1378 __asm vec4_add v.xy, v.xy, a.xx;
1381 void __operator -= (inout ivec2 v, const int a)
1383 __asm vec4_subtract v.xy, v.xy, a.xx;
1386 void __operator *= (inout ivec2 v, const int a)
1388 __asm vec4_multiply v.xy, v.xy, a.xx;
1393 void __operator /= (inout ivec2 v, const int a)
1401 //// ivec3/int assignment operators
1403 void __operator += (inout ivec3 v, const int a)
1405 __asm vec4_add v.xyz, v.xyz, a.xxx;
1408 void __operator -= (inout ivec3 v, const int a)
1410 __asm vec4_subtract v.xyz, v.xyz, a.xxx;
1413 void __operator *= (inout ivec3 v, const int a)
1415 __asm vec4_multiply v.xyz, v.xyz, a.xxx;
1418 void __operator /= (inout ivec3 v, const int a)
1427 //// ivec4/int assignment operators
1429 void __operator += (inout ivec4 v, const int a)
1431 __asm vec4_add v, v, a.xxxx;
1434 void __operator -= (inout ivec4 v, const int a)
1436 __asm vec4_subtract v, v, a.xxxx;
1439 void __operator *= (inout ivec4 v, const int a)
1441 __asm vec4_multiply v, v, a.xxxx;
1444 void __operator /= (inout ivec4 v, const int a)
1454 //// vec2/float assignment operators
1456 void __operator += (inout vec2 v, const float a)
1458 __asm vec4_add v.xy, v, a.xx;
1461 void __operator -= (inout vec2 v, const float a)
1463 __asm vec4_subtract v.xy, v, a.xx;
1466 void __operator *= (inout vec2 v, const float a)
1468 __asm vec4_multiply v.xy, v, a.xx;
1471 void __operator /= (inout vec2 v, const float a)
1474 __asm float_rcp invA, a;
1475 __asm vec4_multiply v.xy, v.xy, a.xx;
1479 //// vec3/float assignment operators
1481 void __operator += (inout vec3 v, const float a)
1483 __asm vec4_add v.xyz, v, a.xxx;
1486 void __operator -= (inout vec3 v, const float a)
1488 __asm vec4_subtract v.xyz, v, a.xxx;
1491 void __operator *= (inout vec3 v, const float a)
1493 __asm vec4_multiply v.xyz, v, a.xxx;
1496 void __operator /= (inout vec3 v, const float a)
1499 __asm float_rcp invA, a;
1500 __asm vec4_multiply v.xyz, v.xyz, a.xxx;
1504 //// vec4/float assignment operators
1506 void __operator += (inout vec4 v, const float a)
1508 __asm vec4_add v, v, a.xxxx;
1511 void __operator -= (inout vec4 v, const float a)
1513 __asm vec4_subtract v, v, a.xxxx;
1516 void __operator *= (inout vec4 v, const float a)
1518 __asm vec4_multiply v, v, a.xxxx;
1521 void __operator /= (inout vec4 v, const float a)
1524 __asm float_rcp invA, a;
1525 __asm vec4_multiply v, v, a.xxxx;
1532 //// Basic mat2 operations
1534 mat2 __operator + (const mat2 m, const mat2 n)
1536 __retVal[0] = m[0] + n[0];
1537 __retVal[1] = m[1] + n[1];
1540 mat2 __operator - (const mat2 m, const mat2 n)
1542 __retVal[0] = m[0] - n[0];
1543 __retVal[1] = m[1] - n[1];
1546 mat2 __operator * (const mat2 m, const mat2 n)
1548 __retVal[0] = m[0] * n[0].xx + m[1] * n[0].yy;
1549 __retVal[1] = m[0] * n[1].xx + m[1] * n[1].yy;
1552 mat2 __operator / (const mat2 m, const mat2 n)
1554 __retVal[0] = m[0] / n[0];
1555 __retVal[1] = m[1] / n[1];
1559 //// Basic mat3 operations
1561 mat3 __operator + (const mat3 m, const mat3 n)
1563 __retVal[0] = m[0] + n[0];
1564 __retVal[1] = m[1] + n[1];
1565 __retVal[2] = m[2] + n[2];
1568 mat3 __operator - (const mat3 m, const mat3 n)
1570 __retVal[0] = m[0] - n[0];
1571 __retVal[1] = m[1] - n[1];
1572 __retVal[2] = m[2] - n[2];
1575 mat3 __operator * (const mat3 m, const mat3 n)
1577 __retVal[0] = m[0] * n[0].xxx + m[1] * n[0].yyy + m[2] * n[0].zzz;
1578 __retVal[1] = m[0] * n[1].xxx + m[1] * n[1].yyy + m[2] * n[1].zzz;
1579 __retVal[2] = m[0] * n[2].xxx + m[1] * n[2].yyy + m[2] * n[2].zzz;
1582 mat3 __operator / (const mat3 m, const mat3 n)
1584 __retVal[0] = m[0] / n[0];
1585 __retVal[1] = m[1] / n[1];
1586 __retVal[2] = m[2] / n[2];
1590 //// Basic mat4 operations
1592 mat4 __operator + (const mat4 m, const mat4 n)
1594 __retVal[0] = m[0] + n[0];
1595 __retVal[1] = m[1] + n[1];
1596 __retVal[2] = m[2] + n[2];
1597 __retVal[3] = m[3] + n[3];
1600 mat4 __operator - (const mat4 m, const mat4 n)
1602 __retVal[0] = m[0] - n[0];
1603 __retVal[1] = m[1] - n[1];
1604 __retVal[2] = m[2] - n[2];
1605 __retVal[3] = m[3] - n[3];
1608 mat4 __operator * (const mat4 m, const mat4 n)
1610 __retVal[0] = m[0] * n[0].xxxx + m[1] * n[0].yyyy + m[2] * n[0].zzzz + m[3] * n[0].wwww;
1611 __retVal[1] = m[0] * n[1].xxxx + m[1] * n[1].yyyy + m[2] * n[1].zzzz + m[3] * n[1].wwww;
1612 __retVal[2] = m[0] * n[2].xxxx + m[1] * n[2].yyyy + m[2] * n[2].zzzz + m[3] * n[2].wwww;
1613 __retVal[3] = m[0] * n[3].xxxx + m[1] * n[3].yyyy + m[2] * n[3].zzzz + m[3] * n[3].wwww;
1616 mat4 __operator / (const mat4 m, const mat4 n)
1618 __retVal[0] = m[0] / n[0];
1619 __retVal[1] = m[1] / n[1];
1620 __retVal[2] = m[2] / n[2];
1621 __retVal[3] = m[3] / n[3];
1625 //// mat2/float operations
1627 mat2 __operator + (const float a, const mat2 n)
1629 __retVal[0] = a + n[0];
1630 __retVal[1] = a + n[1];
1633 mat2 __operator + (const mat2 m, const float b)
1635 __retVal[0] = m[0] + b;
1636 __retVal[1] = m[1] + b;
1639 mat2 __operator - (const float a, const mat2 n)
1641 __retVal[0] = a - n[0];
1642 __retVal[1] = a - n[1];
1645 mat2 __operator - (const mat2 m, const float b)
1647 __retVal[0] = m[0] - b;
1648 __retVal[1] = m[1] - b;
1651 mat2 __operator * (const float a, const mat2 n)
1653 __retVal[0] = a * n[0];
1654 __retVal[1] = a * n[1];
1657 mat2 __operator * (const mat2 m, const float b)
1659 __retVal[0] = m[0] * b;
1660 __retVal[1] = m[1] * b;
1663 mat2 __operator / (const float a, const mat2 n)
1665 __retVal[0] = a / n[0];
1666 __retVal[1] = a / n[1];
1669 mat2 __operator / (const mat2 m, const float b)
1671 __retVal[0] = m[0] / b;
1672 __retVal[1] = m[1] / b;
1676 //// mat3/float operations
1678 mat3 __operator + (const float a, const mat3 n)
1680 __retVal[0] = a + n[0];
1681 __retVal[1] = a + n[1];
1682 __retVal[2] = a + n[2];
1685 mat3 __operator + (const mat3 m, const float b)
1687 __retVal[0] = m[0] + b;
1688 __retVal[1] = m[1] + b;
1689 __retVal[2] = m[2] + b;
1692 mat3 __operator - (const float a, const mat3 n)
1694 __retVal[0] = a - n[0];
1695 __retVal[1] = a - n[1];
1696 __retVal[2] = a - n[2];
1699 mat3 __operator - (const mat3 m, const float b)
1701 __retVal[0] = m[0] - b;
1702 __retVal[1] = m[1] - b;
1703 __retVal[2] = m[2] - b;
1706 mat3 __operator * (const float a, const mat3 n)
1708 __retVal[0] = a * n[0];
1709 __retVal[1] = a * n[1];
1710 __retVal[2] = a * n[2];
1713 mat3 __operator * (const mat3 m, const float b)
1715 __retVal[0] = m[0] * b;
1716 __retVal[1] = m[1] * b;
1717 __retVal[2] = m[2] * b;
1720 mat3 __operator / (const float a, const mat3 n)
1722 __retVal[0] = a / n[0];
1723 __retVal[1] = a / n[1];
1724 __retVal[2] = a / n[2];
1727 mat3 __operator / (const mat3 m, const float b)
1729 __retVal[0] = m[0] / b;
1730 __retVal[1] = m[1] / b;
1731 __retVal[2] = m[2] / b;
1735 //// mat4/float operations
1737 mat4 __operator + (const float a, const mat4 n)
1739 __retVal[0] = a + n[0];
1740 __retVal[1] = a + n[1];
1741 __retVal[2] = a + n[2];
1742 __retVal[3] = a + n[3];
1745 mat4 __operator + (const mat4 m, const float b)
1747 __retVal[0] = m[0] + b;
1748 __retVal[1] = m[1] + b;
1749 __retVal[2] = m[2] + b;
1750 __retVal[3] = m[3] + b;
1753 mat4 __operator - (const float a, const mat4 n)
1755 __retVal[0] = a - n[0];
1756 __retVal[1] = a - n[1];
1757 __retVal[2] = a - n[2];
1758 __retVal[3] = a - n[3];
1761 mat4 __operator - (const mat4 m, const float b)
1763 __retVal[0] = m[0] - b;
1764 __retVal[1] = m[1] - b;
1765 __retVal[2] = m[2] - b;
1766 __retVal[3] = m[3] - b;
1769 mat4 __operator * (const float a, const mat4 n)
1771 __retVal[0] = a * n[0];
1772 __retVal[1] = a * n[1];
1773 __retVal[2] = a * n[2];
1774 __retVal[3] = a * n[3];
1777 mat4 __operator * (const mat4 m, const float b)
1779 __retVal[0] = m[0] * b;
1780 __retVal[1] = m[1] * b;
1781 __retVal[2] = m[2] * b;
1782 __retVal[3] = m[3] * b;
1785 mat4 __operator / (const float a, const mat4 n)
1787 __retVal[0] = a / n[0];
1788 __retVal[1] = a / n[1];
1789 __retVal[2] = a / n[2];
1790 __retVal[3] = a / n[3];
1793 mat4 __operator / (const mat4 m, const float b)
1795 __retVal[0] = m[0] / b;
1796 __retVal[1] = m[1] / b;
1797 __retVal[2] = m[2] / b;
1798 __retVal[3] = m[3] / b;
1803 //// matrix / vector products
1805 vec2 __operator * (const mat2 m, const vec2 v)
1807 __retVal = m[0] * v.xx
1811 vec2 __operator * (const vec2 v, const mat2 m)
1813 __retVal.x = dot(v, m[0]);
1814 __retVal.y = dot(v, m[1]);
1817 vec3 __operator * (const mat3 m, const vec3 v)
1819 __retVal = m[0] * v.xxx
1824 vec3 __operator * (const vec3 v, const mat3 m)
1826 __retVal.x = dot(v, m[0]);
1827 __retVal.y = dot(v, m[1]);
1828 __retVal.z = dot(v, m[2]);
1831 vec4 __operator * (const mat4 m, const vec4 v)
1833 __retVal = m[0] * v.xxxx
1839 vec4 __operator * (const vec4 v, const mat4 m)
1841 __retVal.x = dot(v, m[0]);
1842 __retVal.y = dot(v, m[1]);
1843 __retVal.z = dot(v, m[2]);
1844 __retVal.w = dot(v, m[3]);
1849 //// mat2 assignment operators
1851 void __operator += (inout mat2 m, const mat2 n)
1857 void __operator -= (inout mat2 m, const mat2 n)
1863 void __operator *= (inout mat2 m, const mat2 n)
1868 void __operator /= (inout mat2 m, const mat2 n)
1875 //// mat3 assignment operators
1877 void __operator += (inout mat3 m, const mat3 n)
1884 void __operator -= (inout mat3 m, const mat3 n)
1891 void __operator *= (inout mat3 m, const mat3 n)
1896 void __operator /= (inout mat3 m, const mat3 n)
1904 // mat4 assignment operators
1906 void __operator += (inout mat4 m, const mat4 n)
1914 void __operator -= (inout mat4 m, const mat4 n) {
1921 void __operator *= (inout mat4 m, const mat4 n)
1926 void __operator /= (inout mat4 m, const mat4 n)
1935 //// mat2/float assignment operators
1937 void __operator += (inout mat2 m, const float a) {
1942 void __operator -= (inout mat2 m, const float a) {
1947 void __operator *= (inout mat2 m, const float a) {
1952 void __operator /= (inout mat2 m, const float a) {
1958 //// mat3/float assignment operators
1960 void __operator += (inout mat3 m, const float a) {
1966 void __operator -= (inout mat3 m, const float a) {
1972 void __operator *= (inout mat3 m, const float a) {
1978 void __operator /= (inout mat3 m, const float a) {
1985 //// mat4/float assignment operators
1987 void __operator += (inout mat4 m, const float a) {
1994 void __operator -= (inout mat4 m, const float a) {
2001 void __operator *= (inout mat4 m, const float a) {
2008 void __operator /= (inout mat4 m, const float a) {
2017 //// vec/mat assignment operators
2019 void __operator *= (inout vec2 v, const mat2 m)
2024 void __operator *= (inout vec3 v, const mat3 m)
2029 void __operator *= (inout vec4 v, const mat4 m)
2036 //// pre-decrement operators
2038 int __operator --(inout int a)
2044 ivec2 __operator --(inout ivec2 v)
2050 ivec3 __operator --(inout ivec3 v)
2056 ivec4 __operator --(inout ivec4 v)
2063 float __operator --(inout float a)
2069 vec2 __operator --(inout vec2 v)
2075 vec3 __operator --(inout vec3 v)
2081 vec4 __operator --(inout vec4 v)
2088 mat2 __operator --(inout mat2 m)
2090 m[0] = m[0] - vec2(1.0);
2091 m[1] = m[1] - vec2(1.0);
2095 mat3 __operator --(inout mat3 m)
2097 m[0] = m[0] - vec3(1.0);
2098 m[1] = m[1] - vec3(1.0);
2099 m[2] = m[2] - vec3(1.0);
2103 mat4 __operator --(inout mat4 m)
2105 m[0] = m[0] - vec4(1.0);
2106 m[1] = m[1] - vec4(1.0);
2107 m[2] = m[2] - vec4(1.0);
2108 m[3] = m[3] - vec4(1.0);
2113 //// pre-increment operators
2115 int __operator ++(inout int a)
2121 ivec2 __operator ++(inout ivec2 v)
2127 ivec3 __operator ++(inout ivec3 v)
2133 ivec4 __operator ++(inout ivec4 v)
2140 float __operator ++(inout float a)
2146 vec2 __operator ++(inout vec2 v)
2152 vec3 __operator ++(inout vec3 v)
2158 vec4 __operator ++(inout vec4 v)
2165 mat2 __operator ++(inout mat2 m)
2167 m[0] = m[0] + vec2(1.0);
2168 m[1] = m[1] + vec2(1.0);
2172 mat3 __operator ++(inout mat3 m)
2174 m[0] = m[0] + vec3(1.0);
2175 m[1] = m[1] + vec3(1.0);
2176 m[2] = m[2] + vec3(1.0);
2180 mat4 __operator ++(inout mat4 m)
2182 m[0] = m[0] + vec4(1.0);
2183 m[1] = m[1] + vec4(1.0);
2184 m[2] = m[2] + vec4(1.0);
2185 m[3] = m[3] + vec4(1.0);
2193 int __postDecr(inout int a)
2199 ivec2 __postDecr(inout ivec2 v)
2205 ivec3 __postDecr(inout ivec3 v)
2211 ivec4 __postDecr(inout ivec4 v)
2218 float __postDecr(inout float a)
2224 vec2 __postDecr(inout vec2 v)
2230 vec3 __postDecr(inout vec3 v)
2236 vec4 __postDecr(inout vec4 v)
2243 mat2 __postDecr(inout mat2 m)
2246 m[0] = m[0] - vec2(1.0);
2247 m[1] = m[1] - vec2(1.0);
2250 mat3 __postDecr(inout mat3 m)
2253 m[0] = m[0] - vec3(1.0);
2254 m[1] = m[1] - vec3(1.0);
2255 m[2] = m[2] - vec3(1.0);
2258 mat4 __postDecr(inout mat4 m)
2261 m[0] = m[0] - vec4(1.0);
2262 m[1] = m[1] - vec4(1.0);
2263 m[2] = m[2] - vec4(1.0);
2264 m[3] = m[3] - vec4(1.0);
2270 float __postIncr(inout float a)
2276 vec2 __postIncr(inout vec2 v)
2282 vec3 __postIncr(inout vec3 v)
2288 vec4 __postIncr(inout vec4 v)
2295 int __postIncr(inout int a)
2301 ivec2 __postIncr(inout ivec2 v)
2307 ivec3 __postIncr(inout ivec3 v)
2313 ivec4 __postIncr(inout ivec4 v)
2320 mat2 __postIncr(inout mat2 m)
2323 m[0] = m[0] + vec2(1.0);
2324 m[1] = m[1] + vec2(1.0);
2328 mat3 __postIncr(inout mat3 m)
2331 m[0] = m[0] + vec3(1.0);
2332 m[1] = m[1] + vec3(1.0);
2333 m[2] = m[2] + vec3(1.0);
2337 mat4 __postIncr(inout mat4 m)
2340 m[0] = m[0] + vec4(1.0);
2341 m[1] = m[1] + vec4(1.0);
2342 m[2] = m[2] + vec4(1.0);
2343 m[3] = m[3] + vec4(1.0);
2349 //// inequality operators
2352 // XXX are the inequality operators for floats/ints really needed????
2353 bool __operator < (const float a, const float b)
2355 __asm vec4_sgt __retVal.x, b, a;
2359 bool __operator < (const int a, const int b) {
2360 return float (a) < float (b);
2363 bool __operator > (const float a, const float b) {
2365 __asm float_less c, b, a;
2369 bool __operator > (const int a, const int b) {
2370 return float (a) > float (b);
2373 bool __operator >= (const float a, const float b) {
2375 __asm float_less g, b, a;
2376 __asm float_equal e, a, b;
2380 bool __operator >= (const int a, const int b) {
2381 return float (a) >= float (b);
2384 bool __operator <= (const float a, const float b) {
2386 __asm float_less g, a, b;
2387 __asm float_equal e, a, b;
2391 bool __operator <= (const int a, const int b) {
2392 return float (a) <= float (b);
2398 // MESA-specific extension functions.
2401 void printMESA (const float f) {
2402 __asm float_print f;
2405 void printMESA (const int i) {
2409 void printMESA (const bool b) {
2413 void printMESA (const vec2 v) {
2418 void printMESA (const vec3 v) {
2424 void printMESA (const vec4 v) {
2431 void printMESA (const ivec2 v) {
2436 void printMESA (const ivec3 v) {
2442 void printMESA (const ivec4 v) {
2449 void printMESA (const bvec2 v) {
2454 void printMESA (const bvec3 v) {
2460 void printMESA (const bvec4 v) {
2467 void printMESA (const mat2 m) {
2472 void printMESA (const mat3 m) {
2478 void printMESA (const mat4 m) {
2485 void printMESA (const sampler1D e) {
2489 void printMESA (const sampler2D e) {
2493 void printMESA (const sampler3D e) {
2497 void printMESA (const samplerCube e) {
2501 void printMESA (const sampler1DShadow e) {
2505 void printMESA (const sampler2DShadow e) {