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 vec4_to_ivec4 __retVal, f;
113 int __constructor(const bool b)
118 int __constructor(const int i)
123 bool __constructor(const int i)
125 __asm vec4_sne __retVal, i, 0.0;
128 bool __constructor(const float f)
130 __asm vec4_sne __retVal, f, 0.0;
133 bool __constructor(const bool b)
138 float __constructor(const int i)
140 __asm ivec4_to_vec4 __retVal, i;
143 float __constructor(const bool b)
145 __asm ivec4_to_vec4 __retVal, b;
148 float __constructor(const float f)
154 //// vec2 constructors
156 vec2 __constructor(const float x, const float y)
162 vec2 __constructor(const float f)
164 __asm vec4_move __retVal.xy, f;
167 vec2 __constructor(const int i)
169 __asm ivec4_to_vec4 __retVal.xy, i;
172 vec2 __constructor(const bool b)
174 __asm ivec4_to_vec4 __retVal.xy, b;
177 vec2 __constructor(const bvec2 b)
180 __asm ivec4_to_vec4 __retVal.xy, b;
183 vec2 __constructor(const vec3 v)
185 __asm vec4_move __retVal.xy, v.xy;
188 vec2 __constructor(const vec4 v)
190 __asm vec4_move __retVal.xy, v.xy;
194 //// vec3 constructors
196 vec3 __constructor(const float x, const float y, const float z)
203 vec3 __constructor(const float f)
205 // Note: this could be "__retVal.xyz = f" but that's an illegal assignment
206 __asm vec4_move __retVal.xyz, f;
209 vec3 __constructor(const int i)
211 __asm ivec4_to_vec4 __retVal.xyz, i;
214 vec3 __constructor(const bool b)
216 __asm ivec4_to_vec4 __retVal.xyz, b;
219 vec3 __constructor(const bvec3 b)
221 __asm ivec4_to_vec4 __retVal.xyz, b;
224 vec3 __constructor(const vec4 v)
226 __asm vec4_move __retVal.xyz, v;
230 //// vec4 constructors
232 vec4 __constructor(const float x, const float y, const float z, const float w)
240 vec4 __constructor(const float f)
242 // Note: this could be "__retVal = f" but that's an illegal assignment
243 __asm vec4_move __retVal, f;
246 vec4 __constructor(const int i)
248 __asm ivec4_to_vec4 __retVal, i;
251 vec4 __constructor(const bool b)
253 __asm ivec4_to_vec4 __retVal, b;
256 vec4 __constructor(const bvec4 b)
258 __asm ivec4_to_vec4 __retVal, b;
261 vec4 __constructor(const ivec4 i)
263 __asm ivec4_to_vec4 __retVal, i;
266 vec4 __constructor(const vec3 v3, const float f)
268 // XXX this constructor shouldn't be needed anymore
273 vec4 __constructor(const vec2 v2, const float f1, const float f2)
275 // XXX this constructor shouldn't be needed anymore
282 //// ivec2 constructors
284 ivec2 __constructor(const int i, const int j)
290 ivec2 __constructor(const int i)
292 __asm vec4_move __retVal.xy, i;
295 ivec2 __constructor(const float f)
297 __asm vec4_to_ivec4 __retVal.xy, f;
300 ivec2 __constructor(const bool b)
302 __asm vec4_to_ivec4 __retVal.xy, b;
306 //// ivec3 constructors
308 ivec3 __constructor(const int i, const int j, const int k)
315 ivec3 __constructor(const int i)
317 __asm vec4_move __retVal.xyz, i;
320 ivec3 __constructor(const float f)
322 __asm vec4_to_ivec4 __retVal.xyz, f;
325 ivec3 __constructor(const bool b)
327 __asm vec4_move __retVal.xyz, b;
331 //// ivec4 constructors
333 ivec4 __constructor(const int x, const int y, const int z, const int w)
341 ivec4 __constructor(const int i)
343 __asm vec4_move __retVal, i;
346 ivec4 __constructor(const float f)
348 __asm vec4_to_ivec4 __retVal, f;
351 ivec4 __constructor(const bool b)
353 __asm vec4_to_ivec4 __retVal, b;
357 //// bvec2 constructors
359 bvec2 __constructor(const bool b1, const bool b2)
365 bvec2 __constructor(const int i1, const int i2)
367 __asm vec4_sne __retVal.x, i1, 0.0;
368 __asm vec4_sne __retVal.y, i2, 0.0;
372 bvec2 __constructor(const bool b)
374 __asm vec4_move __retVal.xy, b;
377 bvec2 __constructor(const float f)
379 __asm vec4_sne __retVal.xy, f, 0.0;
382 bvec2 __constructor(const int i)
384 __asm vec4_sne __retVal.xy, i, 0.0;
387 bvec2 __constructor(const vec2 v)
389 __asm vec4_sne __retVal.xy, v, 0.0;
392 bvec2 __constructor(const ivec2 v)
394 __asm vec4_sne __retVal.xy, v, 0.0;
399 //// bvec3 constructors
401 bvec3 __constructor(const bool b1, const bool b2, const bool b3)
408 bvec3 __constructor(const float f1, const float f2, const float f3)
410 __asm vec4_sne __retVal.x, f1, 0.0;
411 __asm vec4_sne __retVal.y, f2, 0.0;
412 __asm vec4_sne __retVal.z, f3, 0.0;
415 bvec3 __constructor(const bool b)
417 __asm vec4_move __retVal.xyz, b;
420 bvec3 __constructor(const float f)
422 __asm vec4_sne __retVal.xyz, f, 0.0;
425 bvec3 __constructor(const int i)
427 __asm vec4_sne __retVal.xyz, i, 0.0;
430 bvec3 __constructor(const vec3 v)
432 __asm vec4_sne __retVal.xyz, v, 0.0;
435 bvec3 __constructor(const ivec3 v)
437 __asm vec4_sne __retVal.xyz, v, 0.0;
442 //// bvec4 constructors
444 bvec4 __constructor(const bool b1, const bool b2, const bool b3, const bool b4)
452 bvec4 __constructor(const float f1, const float f2, const float f3, const float f4)
454 const float zero = 0.0;
455 __asm vec4_sne __retVal.x, f1, zero;
456 __asm vec4_sne __retVal.y, f2, zero;
457 __asm vec4_sne __retVal.z, f3, zero;
458 __asm vec4_sne __retVal.w, f4, zero;
461 bvec4 __constructor(const bool b)
463 __asm vec4_move __retVal.xyzw, b;
466 bvec4 __constructor(const float f)
468 __asm vec4_sne __retVal.xyzw, f, 0.0;
471 bvec4 __constructor(const int i)
473 __asm vec4_sne __retVal.xyzw, i, 0.0;
476 bvec4 __constructor(const vec4 v)
478 __asm vec4_sne __retVal.xyzw, v, 0.0;
481 bvec4 __constructor(const ivec4 v)
483 __asm vec4_sne __retVal.xyzw, v, 0.0;
488 //// mat2 constructors
490 mat2 __constructor(const float m00, const float m10,
491 const float m01, const float m11)
499 mat2 __constructor(const float f)
507 mat2 __constructor(const int i)
509 return mat2(float(i));
512 mat2 __constructor(const bool b)
514 return mat2(float(b));
517 mat2 __constructor(const vec2 c0, const vec2 c1)
524 //// mat3 constructors
526 mat3 __constructor(const float m00, const float m10, const float m20,
527 const float m01, const float m11, const float m21,
528 const float m02, const float m12, const float m22)
541 mat3 __constructor(const float f)
543 vec2 v = vec2(f, 0.0);
549 mat3 __constructor(const int i)
551 return mat3(float(i));
554 mat3 __constructor(const bool b)
556 return mat3(float(b));
559 mat3 __constructor(const vec3 c0, const vec3 c1, const vec3 c2)
567 //// mat4 constructors
569 mat4 __constructor(const float m00, const float m10, const float m20, const float m30,
570 const float m01, const float m11, const float m21, const float m31,
571 const float m02, const float m12, const float m22, const float m32,
572 const float m03, const float m13, const float m23, const float m33)
593 mat4 __constructor(const float f)
595 vec2 v = vec2(f, 0.0);
596 __retVal[0] = v.xyyy;
597 __retVal[1] = v.yxyy;
598 __retVal[2] = v.yyxy;
599 __retVal[3] = v.yyyx;
602 mat4 __constructor(const int i)
604 return mat4(float(i));
607 mat4 __constructor(const bool b)
609 return mat4(float(b));
612 mat4 __constructor(const vec4 c0, const vec4 c1, const vec4 c2, const vec4 c3)
622 //// Basic int operators
624 int __operator + (const int a, const int b)
626 __asm vec4_add __retVal, a, b;
629 int __operator - (const int a, const int b)
631 __asm vec4_subtract __retVal, a, b;
634 int __operator * (const int a, const int b)
636 __asm vec4_multiply __retVal, a, b;
639 int __operator / (const int a, const int b)
642 __asm float_rcp bInv, b;
643 __asm vec4_multiply x, a, bInv;
644 __asm vec4_to_ivec4 __retVal, x;
648 //// Basic ivec2 operators
650 ivec2 __operator + (const ivec2 a, const ivec2 b)
652 __asm vec4_add __retVal, a, b;
655 ivec2 __operator - (const ivec2 a, const ivec2 b)
657 __asm vec4_subtract __retVal, a, b;
660 ivec2 __operator * (const ivec2 a, const ivec2 b)
662 __asm vec4_multiply __retVal, a, b;
665 ivec2 __operator / (const ivec2 a, const ivec2 b)
668 __asm float_rcp bInv.x, b.x;
669 __asm float_rcp bInv.y, b.y;
670 __asm vec4_multiply x, a, bInv;
671 __asm vec4_to_ivec4 __retVal, x;
675 //// Basic ivec3 operators
677 ivec3 __operator + (const ivec3 a, const ivec3 b)
679 __asm vec4_add __retVal, a, b;
682 ivec3 __operator - (const ivec3 a, const ivec3 b)
684 __asm vec4_subtract __retVal, a, b;
687 ivec3 __operator * (const ivec3 a, const ivec3 b)
689 __asm vec4_multiply __retVal, a, b;
692 ivec3 __operator / (const ivec3 a, const ivec3 b)
695 __asm float_rcp bInv.x, b.x;
696 __asm float_rcp bInv.y, b.y;
697 __asm float_rcp bInv.z, b.z;
698 __asm vec4_multiply x, a, bInv;
699 __asm vec4_to_ivec4 __retVal, x;
703 //// Basic ivec4 operators
705 ivec4 __operator + (const ivec4 a, const ivec4 b)
707 __asm vec4_add __retVal, a, b;
710 ivec4 __operator - (const ivec4 a, const ivec4 b)
712 __asm vec4_subtract __retVal, a, b;
715 ivec4 __operator * (const ivec4 a, const ivec4 b)
717 __asm vec4_multiply __retVal, a, b;
720 ivec4 __operator / (const ivec4 a, const ivec4 b)
723 __asm float_rcp bInv.x, b.x;
724 __asm float_rcp bInv.y, b.y;
725 __asm float_rcp bInv.z, b.z;
726 __asm float_rcp bInv.w, b.w;
727 __asm vec4_multiply x, a, bInv;
728 __asm vec4_to_ivec4 __retVal, x;
732 //// Basic float operators
734 float __operator + (const float a, const float b)
736 __asm vec4_add __retVal, a, b;
739 float __operator - (const float a, const float b)
741 __asm vec4_subtract __retVal, a, b;
744 float __operator * (const float a, const float b)
746 __asm vec4_multiply __retVal, a, b;
749 float __operator / (const float a, const float b)
752 __asm float_rcp bInv.x, b;
753 __asm vec4_multiply __retVal, a, bInv;
757 //// Basic vec2 operators
759 vec2 __operator + (const vec2 v, const vec2 u)
761 __asm vec4_add __retVal.xy, v, u;
764 vec2 __operator - (const vec2 v, const vec2 u)
766 __asm vec4_subtract __retVal.xy, v, u;
769 vec2 __operator * (const vec2 v, const vec2 u)
771 __asm vec4_multiply __retVal.xy, v, u;
774 vec2 __operator / (const vec2 v, const vec2 u)
777 __asm float_rcp w.x, u.x;
778 __asm float_rcp w.y, u.y;
779 __asm vec4_multiply __retVal.xy, v, w;
783 //// Basic vec3 operators
785 vec3 __operator + (const vec3 v, const vec3 u)
787 __asm vec4_add __retVal.xyz, v, u;
790 vec3 __operator - (const vec3 v, const vec3 u)
792 __asm vec4_subtract __retVal.xyz, v, u;
795 vec3 __operator * (const vec3 v, const vec3 u)
797 __asm vec4_multiply __retVal.xyz, v, u;
800 vec3 __operator / (const vec3 v, const vec3 u)
803 __asm float_rcp w.x, u.x;
804 __asm float_rcp w.y, u.y;
805 __asm float_rcp w.z, u.z;
806 __asm vec4_multiply __retVal.xyz, v, w;
810 //// Basic vec4 operators
812 vec4 __operator + (const vec4 v, const vec4 u)
814 __asm vec4_add __retVal, v, u;
817 vec4 __operator - (const vec4 v, const vec4 u)
819 __asm vec4_subtract __retVal, v, u;
822 vec4 __operator * (const vec4 v, const vec4 u)
824 __asm vec4_multiply __retVal, v, u;
827 vec4 __operator / (const vec4 v, const vec4 u)
830 __asm float_rcp w.x, u.x;
831 __asm float_rcp w.y, u.y;
832 __asm float_rcp w.z, u.z;
833 __asm float_rcp w.w, u.w;
834 __asm vec4_multiply __retVal, v, w;
840 //// Basic vec2/float operators
842 vec2 __operator + (const float a, const vec2 u)
844 __asm vec4_add __retVal.xy, a, u.xy;
847 vec2 __operator + (const vec2 v, const float b)
849 __asm vec4_add __retVal.xy, v.xy, b;
852 vec2 __operator - (const float a, const vec2 u)
854 __asm vec4_subtract __retVal.xy, a, u.xy;
857 vec2 __operator - (const vec2 v, const float b)
859 __asm vec4_subtract __retVal.xy, v.xy, b;
862 vec2 __operator * (const float a, const vec2 u)
864 __asm vec4_multiply __retVal.xy, a, u.xy;
867 vec2 __operator * (const vec2 v, const float b)
869 __asm vec4_multiply __retVal.xy, v.xy, b;
872 vec2 __operator / (const float a, const vec2 u)
875 __asm float_rcp invU.x, u.x;
876 __asm float_rcp invU.y, u.y;
877 __asm vec4_multiply __retVal.xy, a, invU.xy;
880 vec2 __operator / (const vec2 v, const float b)
883 __asm float_rcp invB, b;
884 __asm vec4_multiply __retVal.xy, v.xy, invB;
888 //// Basic vec3/float operators
890 vec3 __operator + (const float a, const vec3 u)
892 __asm vec4_add __retVal.xyz, a, u.xyz;
895 vec3 __operator + (const vec3 v, const float b)
897 __asm vec4_add __retVal.xyz, v.xyz, b;
900 vec3 __operator - (const float a, const vec3 u)
902 __asm vec4_subtract __retVal.xyz, a, u.xyz;
905 vec3 __operator - (const vec3 v, const float b)
907 __asm vec4_subtract __retVal.xyz, v.xyz, b;
910 vec3 __operator * (const float a, const vec3 u)
912 __asm vec4_multiply __retVal.xyz, a, u.xyz;
915 vec3 __operator * (const vec3 v, const float b)
917 __asm vec4_multiply __retVal.xyz, v.xyz, b;
920 vec3 __operator / (const float a, const vec3 u)
923 __asm float_rcp invU.x, u.x;
924 __asm float_rcp invU.y, u.y;
925 __asm float_rcp invU.z, u.z;
926 __asm vec4_multiply __retVal.xyz, a, invU.xyz;
929 vec3 __operator / (const vec3 v, const float b)
932 __asm float_rcp invB, b;
933 __asm vec4_multiply __retVal.xyz, v.xyz, invB;
937 //// Basic vec4/float operators
939 vec4 __operator + (const float a, const vec4 u)
941 __asm vec4_add __retVal, a, u;
944 vec4 __operator + (const vec4 v, const float b)
946 __asm vec4_add __retVal, v, b;
949 vec4 __operator - (const float a, const vec4 u)
951 __asm vec4_subtract __retVal, a, u;
954 vec4 __operator - (const vec4 v, const float b)
956 __asm vec4_subtract __retVal, v, b;
959 vec4 __operator * (const float a, const vec4 u)
961 __asm vec4_multiply __retVal, a, u;
964 vec4 __operator * (const vec4 v, const float b)
966 __asm vec4_multiply __retVal, v, b;
969 vec4 __operator / (const float a, const vec4 u)
972 __asm float_rcp invU.x, u.x;
973 __asm float_rcp invU.y, u.y;
974 __asm float_rcp invU.z, u.z;
975 __asm float_rcp invU.w, u.w;
976 __asm vec4_multiply __retVal, a, invU;
979 vec4 __operator / (const vec4 v, const float b)
982 __asm float_rcp invB, b;
983 __asm vec4_multiply __retVal, v, invB;
988 //// Basic ivec2/int operators
990 ivec2 __operator + (const int a, const ivec2 u)
992 __retVal = ivec2(a) + u;
995 ivec2 __operator + (const ivec2 v, const int b)
997 __retVal = v + ivec2(b);
1000 ivec2 __operator - (const int a, const ivec2 u)
1002 __retVal = ivec2(a) - u;
1005 ivec2 __operator - (const ivec2 v, const int b)
1007 __retVal = v - ivec2(b);
1010 ivec2 __operator * (const int a, const ivec2 u)
1012 __retVal = ivec2(a) * u;
1015 ivec2 __operator * (const ivec2 v, const int b)
1017 __retVal = v * ivec2(b);
1020 ivec2 __operator / (const int a, const ivec2 u)
1022 __retVal = ivec2(a) / u;
1025 ivec2 __operator / (const ivec2 v, const int b)
1027 __retVal = v / ivec2(b);
1031 //// Basic ivec3/int operators
1033 ivec3 __operator + (const int a, const ivec3 u)
1035 __retVal = ivec3(a) + u;
1038 ivec3 __operator + (const ivec3 v, const int b)
1040 __retVal = v + ivec3(b);
1043 ivec3 __operator - (const int a, const ivec3 u)
1045 __retVal = ivec3(a) - u;
1048 ivec3 __operator - (const ivec3 v, const int b)
1050 __retVal = v - ivec3(b);
1053 ivec3 __operator * (const int a, const ivec3 u)
1055 __retVal = ivec3(a) * u;
1058 ivec3 __operator * (const ivec3 v, const int b)
1060 __retVal = v * ivec3(b);
1063 ivec3 __operator / (const int a, const ivec3 u)
1065 __retVal = ivec3(a) / u;
1068 ivec3 __operator / (const ivec3 v, const int b)
1070 __retVal = v / ivec3(b);
1074 //// Basic ivec4/int operators
1076 ivec4 __operator + (const int a, const ivec4 u)
1078 __retVal = ivec4(a) + u;
1081 ivec4 __operator + (const ivec4 v, const int b)
1083 __retVal = v + ivec4(b);
1086 ivec4 __operator - (const int a, const ivec4 u)
1088 __retVal = ivec4(a) - u;
1091 ivec4 __operator - (const ivec4 v, const int b)
1093 __retVal = v - ivec4(b);
1096 ivec4 __operator * (const int a, const ivec4 u)
1098 __retVal = ivec4(a) * u;
1101 ivec4 __operator * (const ivec4 v, const int b)
1103 __retVal = v * ivec4(b);
1106 ivec4 __operator / (const int a, const ivec4 u)
1108 __retVal = ivec4(a) / u;
1111 ivec4 __operator / (const ivec4 v, const int b)
1113 __retVal = v / ivec4(b);
1119 //// Unary negation operator
1121 int __operator - (const int a)
1123 __asm vec4_negate __retVal.x, a;
1126 ivec2 __operator - (const ivec2 v)
1128 __asm vec4_negate __retVal, v;
1131 ivec3 __operator - (const ivec3 v)
1133 __asm vec4_negate __retVal, v;
1136 ivec4 __operator - (const ivec4 v)
1138 __asm vec4_negate __retVal, v;
1141 float __operator - (const float a)
1143 __asm vec4_negate __retVal.x, a;
1146 vec2 __operator - (const vec2 v)
1148 __asm vec4_negate __retVal.xy, v.xy;
1151 vec3 __operator - (const vec3 v)
1153 __asm vec4_negate __retVal.xyz, v.xyz;
1156 vec4 __operator - (const vec4 v)
1158 __asm vec4_negate __retVal, v;
1161 mat2 __operator - (const mat2 m)
1163 __retVal[0] = -m[0];
1164 __retVal[1] = -m[1];
1167 mat3 __operator - (const mat3 m)
1169 __retVal[0] = -m[0];
1170 __retVal[1] = -m[1];
1171 __retVal[2] = -m[2];
1174 mat4 __operator - (const mat4 m)
1176 __retVal[0] = -m[0];
1177 __retVal[1] = -m[1];
1178 __retVal[2] = -m[2];
1179 __retVal[3] = -m[3];
1186 float dot(const float a, const float b)
1191 float dot(const vec2 a, const vec2 b)
1193 __retVal = a.x * b.x + a.y * b.y;
1196 float dot(const vec3 a, const vec3 b)
1198 __asm vec3_dot __retVal, a, b;
1201 float dot(const vec4 a, const vec4 b)
1203 __asm vec4_dot __retVal, a, b;
1208 //// int assignment operators
1210 int __operator += (inout int a, const int b)
1216 int __operator -= (inout int a, const int b)
1222 int __operator *= (inout int a, const int b)
1228 int __operator /= (inout int a, const int b)
1235 //// ivec2 assignment operators
1237 ivec2 __operator += (inout ivec2 v, const ivec2 u)
1243 ivec2 __operator -= (inout ivec2 v, const ivec2 u)
1249 ivec2 __operator *= (inout ivec2 v, const ivec2 u)
1255 ivec2 __operator /= (inout ivec2 v, const ivec2 u)
1262 //// ivec3 assignment operators
1264 ivec3 __operator += (inout ivec3 v, const ivec3 u)
1270 ivec3 __operator -= (inout ivec3 v, const ivec3 u)
1276 ivec3 __operator *= (inout ivec3 v, const ivec3 u)
1282 ivec3 __operator /= (inout ivec3 v, const ivec3 u)
1289 //// ivec4 assignment operators
1291 ivec4 __operator += (inout ivec4 v, const ivec4 u)
1297 ivec4 __operator -= (inout ivec4 v, const ivec4 u)
1303 ivec4 __operator *= (inout ivec4 v, const ivec4 u)
1309 ivec4 __operator /= (inout ivec4 v, const ivec4 u)
1316 //// float assignment operators
1318 float __operator += (inout float a, const float b)
1324 float __operator -= (inout float a, const float b)
1330 float __operator *= (inout float a, const float b)
1336 float __operator /= (inout float a, const float b)
1343 //// vec2 assignment operators
1345 vec2 __operator += (inout vec2 v, const vec2 u)
1351 vec2 __operator -= (inout vec2 v, const vec2 u)
1357 vec2 __operator *= (inout vec2 v, const vec2 u)
1363 vec2 __operator /= (inout vec2 v, const vec2 u)
1370 //// vec3 assignment operators
1372 vec3 __operator += (inout vec3 v, const vec3 u)
1378 vec3 __operator -= (inout vec3 v, const vec3 u)
1384 vec3 __operator *= (inout vec3 v, const vec3 u)
1390 vec3 __operator /= (inout vec3 v, const vec3 u)
1397 //// vec4 assignment operators
1399 vec4 __operator += (inout vec4 v, const vec4 u)
1405 vec4 __operator -= (inout vec4 v, const vec4 u)
1411 vec4 __operator *= (inout vec4 v, const vec4 u)
1417 vec4 __operator /= (inout vec4 v, const vec4 u)
1425 //// ivec2/int assignment operators
1427 ivec2 __operator += (inout ivec2 v, const int a)
1433 ivec2 __operator -= (inout ivec2 v, const int a)
1439 ivec2 __operator *= (inout ivec2 v, const int a)
1445 ivec2 __operator /= (inout ivec2 v, const int a)
1452 //// ivec3/int assignment operators
1454 ivec3 __operator += (inout ivec3 v, const int a)
1460 ivec3 __operator -= (inout ivec3 v, const int a)
1466 ivec3 __operator *= (inout ivec3 v, const int a)
1472 ivec4 __operator /= (inout ivec3 v, const int a)
1479 //// ivec4/int assignment operators
1481 ivec4 __operator += (inout ivec4 v, const int a)
1487 ivec4 __operator -= (inout ivec4 v, const int a)
1493 ivec4 __operator *= (inout ivec4 v, const int a)
1499 ivec4 __operator /= (inout ivec4 v, const int a)
1507 //// vec2/float assignment operators
1509 vec2 __operator += (inout vec2 v, const float a)
1515 vec2 __operator -= (inout vec2 v, const float a)
1521 vec2 __operator *= (inout vec2 v, const float a)
1527 vec2 __operator /= (inout vec2 v, const float a)
1534 //// vec3/float assignment operators
1536 vec3 __operator += (inout vec3 v, const float a)
1542 vec3 __operator -= (inout vec3 v, const float a)
1548 vec3 __operator *= (inout vec3 v, const float a)
1554 vec3 __operator /= (inout vec3 v, const float a)
1561 //// vec4/float assignment operators
1563 vec4 __operator += (inout vec4 v, const float a)
1569 vec4 __operator -= (inout vec4 v, const float a)
1575 vec4 __operator *= (inout vec4 v, const float a)
1581 vec4 __operator /= (inout vec4 v, const float a)
1591 //// Basic mat2 operations
1593 mat2 __operator + (const mat2 m, const mat2 n)
1595 __retVal[0] = m[0] + n[0];
1596 __retVal[1] = m[1] + n[1];
1599 mat2 __operator - (const mat2 m, const mat2 n)
1601 __retVal[0] = m[0] - n[0];
1602 __retVal[1] = m[1] - n[1];
1605 mat2 __operator * (const mat2 m, const mat2 n)
1607 __retVal[0] = m[0] * n[0].xx + m[1] * n[0].yy;
1608 __retVal[1] = m[0] * n[1].xx + m[1] * n[1].yy;
1611 mat2 __operator / (const mat2 m, const mat2 n)
1613 __retVal[0] = m[0] / n[0];
1614 __retVal[1] = m[1] / n[1];
1618 //// Basic mat3 operations
1620 mat3 __operator + (const mat3 m, const mat3 n)
1622 __retVal[0] = m[0] + n[0];
1623 __retVal[1] = m[1] + n[1];
1624 __retVal[2] = m[2] + n[2];
1627 mat3 __operator - (const mat3 m, const mat3 n)
1629 __retVal[0] = m[0] - n[0];
1630 __retVal[1] = m[1] - n[1];
1631 __retVal[2] = m[2] - n[2];
1634 mat3 __operator * (const mat3 m, const mat3 n)
1636 __retVal[0] = m[0] * n[0].xxx + m[1] * n[0].yyy + m[2] * n[0].zzz;
1637 __retVal[1] = m[0] * n[1].xxx + m[1] * n[1].yyy + m[2] * n[1].zzz;
1638 __retVal[2] = m[0] * n[2].xxx + m[1] * n[2].yyy + m[2] * n[2].zzz;
1641 mat3 __operator / (const mat3 m, const mat3 n)
1643 __retVal[0] = m[0] / n[0];
1644 __retVal[1] = m[1] / n[1];
1645 __retVal[2] = m[2] / n[2];
1649 //// Basic mat4 operations
1651 mat4 __operator + (const mat4 m, const mat4 n)
1653 __retVal[0] = m[0] + n[0];
1654 __retVal[1] = m[1] + n[1];
1655 __retVal[2] = m[2] + n[2];
1656 __retVal[3] = m[3] + n[3];
1659 mat4 __operator - (const mat4 m, const mat4 n)
1661 __retVal[0] = m[0] - n[0];
1662 __retVal[1] = m[1] - n[1];
1663 __retVal[2] = m[2] - n[2];
1664 __retVal[3] = m[3] - n[3];
1667 mat4 __operator * (const mat4 m, const mat4 n)
1669 __retVal[0] = m[0] * n[0].xxxx + m[1] * n[0].yyyy + m[2] * n[0].zzzz + m[3] * n[0].wwww;
1670 __retVal[1] = m[0] * n[1].xxxx + m[1] * n[1].yyyy + m[2] * n[1].zzzz + m[3] * n[1].wwww;
1671 __retVal[2] = m[0] * n[2].xxxx + m[1] * n[2].yyyy + m[2] * n[2].zzzz + m[3] * n[2].wwww;
1672 __retVal[3] = m[0] * n[3].xxxx + m[1] * n[3].yyyy + m[2] * n[3].zzzz + m[3] * n[3].wwww;
1675 mat4 __operator / (const mat4 m, const mat4 n)
1677 __retVal[0] = m[0] / n[0];
1678 __retVal[1] = m[1] / n[1];
1679 __retVal[2] = m[2] / n[2];
1680 __retVal[3] = m[3] / n[3];
1684 //// mat2/float operations
1686 mat2 __operator + (const float a, const mat2 n)
1688 __retVal[0] = a + n[0];
1689 __retVal[1] = a + n[1];
1692 mat2 __operator + (const mat2 m, const float b)
1694 __retVal[0] = m[0] + b;
1695 __retVal[1] = m[1] + b;
1698 mat2 __operator - (const float a, const mat2 n)
1700 __retVal[0] = a - n[0];
1701 __retVal[1] = a - n[1];
1704 mat2 __operator - (const mat2 m, const float b)
1706 __retVal[0] = m[0] - b;
1707 __retVal[1] = m[1] - b;
1710 mat2 __operator * (const float a, const mat2 n)
1712 __retVal[0] = a * n[0];
1713 __retVal[1] = a * n[1];
1716 mat2 __operator * (const mat2 m, const float b)
1718 __retVal[0] = m[0] * b;
1719 __retVal[1] = m[1] * b;
1722 mat2 __operator / (const float a, const mat2 n)
1724 __retVal[0] = a / n[0];
1725 __retVal[1] = a / n[1];
1728 mat2 __operator / (const mat2 m, const float b)
1730 __retVal[0] = m[0] / b;
1731 __retVal[1] = m[1] / b;
1735 //// mat3/float operations
1737 mat3 __operator + (const float a, const mat3 n)
1739 __retVal[0] = a + n[0];
1740 __retVal[1] = a + n[1];
1741 __retVal[2] = a + n[2];
1744 mat3 __operator + (const mat3 m, const float b)
1746 __retVal[0] = m[0] + b;
1747 __retVal[1] = m[1] + b;
1748 __retVal[2] = m[2] + b;
1751 mat3 __operator - (const float a, const mat3 n)
1753 __retVal[0] = a - n[0];
1754 __retVal[1] = a - n[1];
1755 __retVal[2] = a - n[2];
1758 mat3 __operator - (const mat3 m, const float b)
1760 __retVal[0] = m[0] - b;
1761 __retVal[1] = m[1] - b;
1762 __retVal[2] = m[2] - b;
1765 mat3 __operator * (const float a, const mat3 n)
1767 __retVal[0] = a * n[0];
1768 __retVal[1] = a * n[1];
1769 __retVal[2] = a * n[2];
1772 mat3 __operator * (const mat3 m, const float b)
1774 __retVal[0] = m[0] * b;
1775 __retVal[1] = m[1] * b;
1776 __retVal[2] = m[2] * b;
1779 mat3 __operator / (const float a, const mat3 n)
1781 __retVal[0] = a / n[0];
1782 __retVal[1] = a / n[1];
1783 __retVal[2] = a / n[2];
1786 mat3 __operator / (const mat3 m, const float b)
1788 __retVal[0] = m[0] / b;
1789 __retVal[1] = m[1] / b;
1790 __retVal[2] = m[2] / b;
1794 //// mat4/float operations
1796 mat4 __operator + (const float a, const mat4 n)
1798 __retVal[0] = a + n[0];
1799 __retVal[1] = a + n[1];
1800 __retVal[2] = a + n[2];
1801 __retVal[3] = a + n[3];
1804 mat4 __operator + (const mat4 m, const float b)
1806 __retVal[0] = m[0] + b;
1807 __retVal[1] = m[1] + b;
1808 __retVal[2] = m[2] + b;
1809 __retVal[3] = m[3] + b;
1812 mat4 __operator - (const float a, const mat4 n)
1814 __retVal[0] = a - n[0];
1815 __retVal[1] = a - n[1];
1816 __retVal[2] = a - n[2];
1817 __retVal[3] = a - n[3];
1820 mat4 __operator - (const mat4 m, const float b)
1822 __retVal[0] = m[0] - b;
1823 __retVal[1] = m[1] - b;
1824 __retVal[2] = m[2] - b;
1825 __retVal[3] = m[3] - b;
1828 mat4 __operator * (const float a, const mat4 n)
1830 __retVal[0] = a * n[0];
1831 __retVal[1] = a * n[1];
1832 __retVal[2] = a * n[2];
1833 __retVal[3] = a * n[3];
1836 mat4 __operator * (const mat4 m, const float b)
1838 __retVal[0] = m[0] * b;
1839 __retVal[1] = m[1] * b;
1840 __retVal[2] = m[2] * b;
1841 __retVal[3] = m[3] * b;
1844 mat4 __operator / (const float a, const mat4 n)
1846 __retVal[0] = a / n[0];
1847 __retVal[1] = a / n[1];
1848 __retVal[2] = a / n[2];
1849 __retVal[3] = a / n[3];
1852 mat4 __operator / (const mat4 m, const float b)
1854 __retVal[0] = m[0] / b;
1855 __retVal[1] = m[1] / b;
1856 __retVal[2] = m[2] / b;
1857 __retVal[3] = m[3] / b;
1862 //// matrix / vector products
1864 vec2 __operator * (const mat2 m, const vec2 v)
1866 __retVal = m[0] * v.xx
1870 vec2 __operator * (const vec2 v, const mat2 m)
1872 __retVal.x = dot(v, m[0]);
1873 __retVal.y = dot(v, m[1]);
1876 vec3 __operator * (const mat3 m, const vec3 v)
1878 __retVal = m[0] * v.xxx
1883 vec3 __operator * (const vec3 v, const mat3 m)
1885 __retVal.x = dot(v, m[0]);
1886 __retVal.y = dot(v, m[1]);
1887 __retVal.z = dot(v, m[2]);
1890 vec4 __operator * (const mat4 m, const vec4 v)
1892 __retVal = m[0] * v.xxxx
1898 vec4 __operator * (const vec4 v, const mat4 m)
1900 __retVal.x = dot(v, m[0]);
1901 __retVal.y = dot(v, m[1]);
1902 __retVal.z = dot(v, m[2]);
1903 __retVal.w = dot(v, m[3]);
1908 //// mat2 assignment operators
1910 mat2 __operator += (inout mat2 m, const mat2 n)
1917 mat2 __operator -= (inout mat2 m, const mat2 n)
1924 mat2 __operator *= (inout mat2 m, const mat2 n)
1930 mat2 __operator /= (inout mat2 m, const mat2 n)
1938 //// mat3 assignment operators
1940 mat3 __operator += (inout mat3 m, const mat3 n)
1948 mat3 __operator -= (inout mat3 m, const mat3 n)
1956 mat3 __operator *= (inout mat3 m, const mat3 n)
1962 mat3 __operator /= (inout mat3 m, const mat3 n)
1971 // mat4 assignment operators
1973 mat4 __operator += (inout mat4 m, const mat4 n)
1982 mat4 __operator -= (inout mat4 m, const mat4 n)
1991 mat4 __operator *= (inout mat4 m, const mat4 n)
1997 mat4 __operator /= (inout mat4 m, const mat4 n)
2007 //// mat2/float assignment operators
2009 mat2 __operator += (inout mat2 m, const float a)
2017 mat2 __operator -= (inout mat2 m, const float a)
2025 mat2 __operator *= (inout mat2 m, const float a)
2033 mat2 __operator /= (inout mat2 m, const float a)
2035 vec2 v = vec2(1.0 / a);
2042 //// mat3/float assignment operators
2044 mat3 __operator += (inout mat3 m, const float a)
2053 mat3 __operator -= (inout mat3 m, const float a)
2062 mat3 __operator *= (inout mat3 m, const float a)
2071 mat3 __operator /= (inout mat3 m, const float a)
2073 vec3 v = vec3(1.0 / a);
2081 //// mat4/float assignment operators
2083 mat4 __operator += (inout mat4 m, const float a)
2093 mat4 __operator -= (inout mat4 m, const float a)
2103 mat4 __operator *= (inout mat4 m, const float a)
2113 mat4 __operator /= (inout mat4 m, const float a)
2115 vec4 v = vec4(1.0 / a);
2125 //// vec/mat assignment operators
2127 vec2 __operator *= (inout vec2 v, const mat2 m)
2133 vec3 __operator *= (inout vec3 v, const mat3 m)
2139 vec4 __operator *= (inout vec4 v, const mat4 m)
2147 //// pre-decrement operators
2149 int __operator --(inout int a)
2155 ivec2 __operator --(inout ivec2 v)
2161 ivec3 __operator --(inout ivec3 v)
2167 ivec4 __operator --(inout ivec4 v)
2174 float __operator --(inout float a)
2180 vec2 __operator --(inout vec2 v)
2186 vec3 __operator --(inout vec3 v)
2192 vec4 __operator --(inout vec4 v)
2199 mat2 __operator --(inout mat2 m)
2201 m[0] = m[0] - vec2(1.0);
2202 m[1] = m[1] - vec2(1.0);
2206 mat3 __operator --(inout mat3 m)
2208 m[0] = m[0] - vec3(1.0);
2209 m[1] = m[1] - vec3(1.0);
2210 m[2] = m[2] - vec3(1.0);
2214 mat4 __operator --(inout mat4 m)
2216 m[0] = m[0] - vec4(1.0);
2217 m[1] = m[1] - vec4(1.0);
2218 m[2] = m[2] - vec4(1.0);
2219 m[3] = m[3] - vec4(1.0);
2224 //// pre-increment operators
2226 int __operator ++(inout int a)
2232 ivec2 __operator ++(inout ivec2 v)
2238 ivec3 __operator ++(inout ivec3 v)
2244 ivec4 __operator ++(inout ivec4 v)
2251 float __operator ++(inout float a)
2257 vec2 __operator ++(inout vec2 v)
2263 vec3 __operator ++(inout vec3 v)
2269 vec4 __operator ++(inout vec4 v)
2276 mat2 __operator ++(inout mat2 m)
2278 m[0] = m[0] + vec2(1.0);
2279 m[1] = m[1] + vec2(1.0);
2283 mat3 __operator ++(inout mat3 m)
2285 m[0] = m[0] + vec3(1.0);
2286 m[1] = m[1] + vec3(1.0);
2287 m[2] = m[2] + vec3(1.0);
2291 mat4 __operator ++(inout mat4 m)
2293 m[0] = m[0] + vec4(1.0);
2294 m[1] = m[1] + vec4(1.0);
2295 m[2] = m[2] + vec4(1.0);
2296 m[3] = m[3] + vec4(1.0);
2304 int __postDecr(inout int a)
2310 ivec2 __postDecr(inout ivec2 v)
2316 ivec3 __postDecr(inout ivec3 v)
2322 ivec4 __postDecr(inout ivec4 v)
2329 float __postDecr(inout float a)
2335 vec2 __postDecr(inout vec2 v)
2341 vec3 __postDecr(inout vec3 v)
2347 vec4 __postDecr(inout vec4 v)
2354 mat2 __postDecr(inout mat2 m)
2357 m[0] = m[0] - vec2(1.0);
2358 m[1] = m[1] - vec2(1.0);
2361 mat3 __postDecr(inout mat3 m)
2364 m[0] = m[0] - vec3(1.0);
2365 m[1] = m[1] - vec3(1.0);
2366 m[2] = m[2] - vec3(1.0);
2369 mat4 __postDecr(inout mat4 m)
2372 m[0] = m[0] - vec4(1.0);
2373 m[1] = m[1] - vec4(1.0);
2374 m[2] = m[2] - vec4(1.0);
2375 m[3] = m[3] - vec4(1.0);
2381 float __postIncr(inout float a)
2387 vec2 __postIncr(inout vec2 v)
2393 vec3 __postIncr(inout vec3 v)
2399 vec4 __postIncr(inout vec4 v)
2406 int __postIncr(inout int a)
2412 ivec2 __postIncr(inout ivec2 v)
2418 ivec3 __postIncr(inout ivec3 v)
2424 ivec4 __postIncr(inout ivec4 v)
2431 mat2 __postIncr(inout mat2 m)
2434 m[0] = m[0] + vec2(1.0);
2435 m[1] = m[1] + vec2(1.0);
2439 mat3 __postIncr(inout mat3 m)
2442 m[0] = m[0] + vec3(1.0);
2443 m[1] = m[1] + vec3(1.0);
2444 m[2] = m[2] + vec3(1.0);
2448 mat4 __postIncr(inout mat4 m)
2451 m[0] = m[0] + vec4(1.0);
2452 m[1] = m[1] + vec4(1.0);
2453 m[2] = m[2] + vec4(1.0);
2454 m[3] = m[3] + vec4(1.0);
2460 //// inequality operators
2463 // XXX are the inequality operators for floats/ints really needed????
2464 bool __operator < (const float a, const float b)
2466 __asm vec4_sgt __retVal.x, b, a;
2470 bool __operator < (const int a, const int b) {
2471 return float (a) < float (b);
2474 bool __operator > (const float a, const float b) {
2476 __asm float_less c, b, a;
2480 bool __operator > (const int a, const int b) {
2481 return float (a) > float (b);
2484 bool __operator >= (const float a, const float b) {
2486 __asm float_less g, b, a;
2487 __asm float_equal e, a, b;
2491 bool __operator >= (const int a, const int b) {
2492 return float (a) >= float (b);
2495 bool __operator <= (const float a, const float b) {
2497 __asm float_less g, a, b;
2498 __asm float_equal e, a, b;
2502 bool __operator <= (const int a, const int b) {
2503 return float (a) <= float (b);
2509 // MESA-specific extension functions.
2512 void printMESA (const float f) {
2513 __asm float_print f;
2516 void printMESA (const int i) {
2520 void printMESA (const bool b) {
2524 void printMESA (const vec2 v) {
2529 void printMESA (const vec3 v) {
2535 void printMESA (const vec4 v) {
2542 void printMESA (const ivec2 v) {
2547 void printMESA (const ivec3 v) {
2553 void printMESA (const ivec4 v) {
2560 void printMESA (const bvec2 v) {
2565 void printMESA (const bvec3 v) {
2571 void printMESA (const bvec4 v) {
2578 void printMESA (const mat2 m) {
2583 void printMESA (const mat3 m) {
2589 void printMESA (const mat4 m) {
2596 void printMESA (const sampler1D e) {
2600 void printMESA (const sampler2D e) {
2604 void printMESA (const sampler3D e) {
2608 void printMESA (const samplerCube e) {
2612 void printMESA (const sampler1DShadow e) {
2616 void printMESA (const sampler2DShadow e) {