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.
105 //vec4 vec4(const float a1, const float b1, const float c1, const float d1)
114 //// Assorted constructors
117 int __constructor (const float f) {
119 __asm float_to_int i, f;
123 bool __constructor (const int i) {
127 bool __constructor (const float f) {
131 int __constructor (const bool b) {
135 float __constructor (const bool b) {
136 return b ? 1.0 : 0.0;
139 float __constructor (const int i) {
141 __asm int_to_float f, i;
145 bool __constructor (const bool b) {
149 int __constructor (const int i) {
153 float __constructor(const float f)
158 vec2 __constructor(const float f)
163 vec2 __constructor (const int i) {
165 __asm int_to_float x, i;
169 vec2 __constructor (const bool b) {
170 return vec2 (b ? 1.0 : 0.0);
173 vec3 __constructor(const float f)
175 __retVal.xyz = f.xxx;
178 vec3 __constructor (const int i) {
180 __asm int_to_float x, i;
184 vec3 __constructor (const bool b) {
185 return vec3 (b ? 1.0 : 0.0);
188 vec3 __constructor(const vec4 v)
190 __retVal.xyz = v.xyz;
194 vec4 __constructor(const float f)
196 __retVal.xyzw = f.xxxx;
199 vec4 __constructor (const int i) {
201 __asm int_to_float x, i;
205 vec4 __constructor (const bool b) {
206 return vec4 (b ? 1.0 : 0.0);
209 vec4 __constructor(const vec3 v3, const float f)
217 ivec2 __constructor (const int i) {
221 ivec2 __constructor (const float f) {
222 return ivec2 (int (f));
225 ivec2 __constructor (const bool b) {
226 return ivec2 (int (b));
229 ivec3 __constructor (const int i) {
230 return ivec3 (i, i, i);
233 ivec3 __constructor (const float f) {
234 return ivec3 (int (f));
237 ivec3 __constructor (const bool b) {
238 return ivec3 (int (b));
241 ivec4 __constructor (const int i) {
242 return ivec4 (i, i, i, i);
245 ivec4 __constructor (const float f) {
246 return ivec4 (int (f));
249 ivec4 __constructor (const bool b) {
250 return ivec4 (int (b));
253 bvec2 __constructor (const bool b) {
257 bvec2 __constructor (const float f) {
258 return bvec2 (bool (f));
261 bvec2 __constructor (const int i) {
262 return bvec2 (bool (i));
265 bvec3 __constructor (const bool b) {
266 return bvec3 (b, b, b);
269 bvec3 __constructor (const float f) {
270 return bvec3 (bool (f));
273 bvec3 __constructor (const int i) {
274 return bvec3 (bool (i));
277 bvec4 __constructor (const bool b) {
278 return bvec4 (b, b, b, b);
281 bvec4 __constructor (const float f) {
282 return bvec4 (bool (f));
285 bvec4 __constructor (const int i) {
286 return bvec4 (bool (i));
291 //// mat2 constructors
293 mat2 __constructor (const float f) {
294 return mat2 (f, 0.0, 0.0, f);
297 mat2 __constructor (const int i) {
299 __asm int_to_float x, i;
303 mat2 __constructor (const bool b) {
304 return mat2 (b ? 1.0 : 0.0);
308 //// mat3 constructors
310 mat3 __constructor (const float f) {
311 return mat3 (f, 0.0, 0.0, 0.0, f, 0.0, 0.0, 0.0, f);
314 mat3 __constructor (const int i) {
316 __asm int_to_float x, i;
320 mat3 __constructor (const bool b) {
321 return mat3 (b ? 1.0 : 0.0);
325 //// mat4 constructors
327 mat4 __constructor (const float f) {
328 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);
331 mat4 __constructor (const int i) {
333 __asm int_to_float x, i;
337 mat4 __constructor (const bool b) {
338 return mat4 (b ? 1.0 : 0.0);
341 mat4 __constructor (const vec4 r0, const vec4 r1, const vec4 r2, const vec4 r3)
351 //// Basic int operators
353 int __operator + (const int a, const int b)
357 __asm int_to_float x, a;
358 __asm int_to_float y, b;
359 __asm vec4_add x.x, x.x, y.x;
360 __asm float_to_int c, x;
364 int __operator - (const int a, const int b)
368 __asm int_to_float x, a;
369 __asm int_to_float y, b;
370 __asm float_negate y, y;
371 __asm vec4_add x.x, x.x, y.x;
372 __asm float_to_int c, x;
376 int __operator * (const int a, const int b)
380 __asm int_to_float x, a;
381 __asm int_to_float y, b;
382 __asm float_multiply x, x, y;
383 __asm float_to_int c, x;
387 int __operator / (const int a, const int b)
391 __asm int_to_float x, a;
392 __asm int_to_float y, b;
393 __asm float_divide x, x, y;
394 __asm float_to_int c, x;
399 //// Basic ivec2 operators
401 ivec2 __operator + (const ivec2 v, const ivec2 u)
403 return ivec2 (v.x + u.x, v.y + u.y);
406 ivec2 __operator - (const ivec2 v, const ivec2 u)
408 return ivec2 (v.x - u.x, v.y - u.y);
411 ivec2 __operator * (const ivec2 v, const ivec2 u)
413 return ivec2 (v.x * u.x, v.y * u.y);
416 ivec2 __operator / (const ivec2 v, const ivec2 u)
418 return ivec2 (v.x / u.x, v.y / u.y);
422 //// Basic ivec3 operators
424 ivec3 __operator + (const ivec3 v, const ivec3 u)
426 return ivec3 (v.x + u.x, v.y + u.y, v.z + u.z);
429 ivec3 __operator - (const ivec3 v, const ivec3 u)
431 return ivec3 (v.x - u.x, v.y - u.y, v.z - u.z);
434 ivec3 __operator * (const ivec3 v, const ivec3 u)
436 return ivec3 (v.x * u.x, v.y * u.y, v.z * u.z);
439 ivec3 __operator / (const ivec3 v, const ivec3 u)
441 return ivec3 (v.x / u.x, v.y / u.y, v.z / u.z);
445 //// Basic ivec4 operators
447 ivec4 __operator + (const ivec4 v, const ivec4 u)
449 return ivec4 (v.x + u.x, v.y + u.y, v.z + u.z, v.w + u.w);
452 ivec4 __operator - (const ivec4 v, const ivec4 u)
454 return ivec4 (v.x - u.x, v.y - u.y, v.z - u.z, v.w - u.w);
457 ivec4 __operator * (const ivec4 v, const ivec4 u)
459 return ivec4 (v.x * u.x, v.y * u.y, v.z * u.z, v.w * u.w);
462 ivec4 __operator / (const ivec4 v, const ivec4 u)
464 return ivec4 (v.x / u.x, v.y / u.y, v.z / u.z, v.w / u.w);
468 //// Basic float operators
470 float __operator + (const float a, const float b)
472 __asm vec4_add __retVal.x, a, b;
475 float __operator - (const float a, const float b)
477 __asm vec4_subtract __retVal.x, a, b;
480 float __operator * (const float a, const float b)
482 __asm float_multiply __retVal, a, b;
485 float __operator / (const float a, const float b)
487 __asm float_divide __retVal, a, b;
491 //// Basic vec2 operators
493 vec2 __operator + (const vec2 v, const vec2 u)
495 __asm vec4_add __retVal.xy, v, u;
498 vec2 __operator - (const vec2 v, const vec2 u)
500 __asm vec4_subtract __retVal.xy, v, u;
503 vec2 __operator * (const vec2 v, const vec2 u)
505 __asm vec4_multiply __retVal.xy, v, u;
508 vec2 __operator / (const vec2 v, const vec2 u)
511 __asm float_rcp w.x, u.x;
512 __asm float_rcp w.y, u.y;
513 __asm vec4_multiply __retVal.xy, v, w;
517 //// Basic vec3 operators
519 vec3 __operator + (const vec3 v, const vec3 u)
521 __asm vec4_add __retVal.xyz, v, u;
524 vec3 __operator - (const vec3 v, const vec3 u)
526 __asm vec4_subtract __retVal.xyz, v, u;
529 vec3 __operator * (const vec3 v, const vec3 u)
531 __asm vec4_multiply __retVal.xyz, v, u;
534 vec3 __operator / (const vec3 v, const vec3 u)
537 __asm float_rcp w.x, u.x;
538 __asm float_rcp w.y, u.y;
539 __asm float_rcp w.z, u.z;
540 __asm vec4_multiply __retVal.xyz, v, w;
544 //// Basic vec4 operators
546 vec4 __operator + (const vec4 v, const vec4 u)
548 __asm vec4_add __retVal, v, u;
551 vec4 __operator - (const vec4 v, const vec4 u)
553 __asm vec4_subtract __retVal, v, u;
556 vec4 __operator * (const vec4 v, const vec4 u)
558 __asm vec4_multiply __retVal, v, u;
561 vec4 __operator / (const vec4 v, const vec4 u)
564 __asm float_rcp w.x, u.x;
565 __asm float_rcp w.y, u.y;
566 __asm float_rcp w.z, u.z;
567 __asm float_rcp w.w, u.w;
568 __asm vec4_multiply __retVal, v, w;
574 //// Basic vec2/float operators
576 vec2 __operator + (const float a, const vec2 u)
578 __asm vec4_add __retVal.xy, a.xx, u.xy;
581 vec2 __operator + (const vec2 v, const float b)
583 __asm vec4_add __retVal.xy, v.xy, b.xx;
586 vec2 __operator - (const float a, const vec2 u)
588 __asm vec4_subtract __retVal.xy, a.xx, u.xy;
591 vec2 __operator - (const vec2 v, const float b)
593 __asm vec4_subtract __retVal.xy, v.xy, b.xx;
596 vec2 __operator * (const float a, const vec2 u)
598 __asm vec4_multiply __retVal.xy, a.xx, u.xy;
601 vec2 __operator * (const vec2 v, const float b)
603 __asm vec4_multiply __retVal.xy, v.xy, b.xx;
606 vec2 __operator / (const float a, const vec2 u)
609 __asm float_rcp invU.x, u.x;
610 __asm float_rcp invU.y, u.y;
611 __asm vec4_multiply __retVal.xy, a.xx, invU.xy;
614 vec2 __operator / (const vec2 v, const float b)
617 __asm float_rcp invB, b;
618 __asm vec4_multiply __retVal.xy, v.xy, invB.xx;
622 //// Basic vec3/float operators
624 vec3 __operator + (const float a, const vec3 u)
626 __asm vec4_add __retVal.xyz, a.xxx, u.xyz;
629 vec3 __operator + (const vec3 v, const float b)
631 __asm vec4_add __retVal.xyz, v.xyz, b.xxx;
634 vec3 __operator - (const float a, const vec3 u)
636 __asm vec4_subtract __retVal.xyz, a.xxx, u.xyz;
639 vec3 __operator - (const vec3 v, const float b)
641 __asm vec4_subtract __retVal.xyz, v.xyz, b.xxx;
644 vec3 __operator * (const float a, const vec3 u)
646 __asm vec4_multiply __retVal.xyz, a.xxx, u.xyz;
649 vec3 __operator * (const vec3 v, const float b)
651 __asm vec4_multiply __retVal.xyz, v.xyz, b.xxx;
654 vec3 __operator / (const float a, const vec3 u)
657 __asm float_rcp invU.x, u.x;
658 __asm float_rcp invU.y, u.y;
659 __asm float_rcp invU.z, u.z;
660 __asm vec4_multiply __retVal.xyz, a.xxx, invU.xyz;
663 vec3 __operator / (const vec3 v, const float b)
666 __asm float_rcp invB, b;
667 __asm vec4_multiply __retVal.xyz, v.xyz, invB.xxx;
671 //// Basic vec4/float operators
673 vec4 __operator + (const float a, const vec4 u)
675 __asm vec4_add __retVal, a.xxxx, u;
678 vec4 __operator + (const vec4 v, const float b)
680 __asm vec4_add __retVal, v, b.xxxx;
683 vec4 __operator - (const float a, const vec4 u)
685 __asm vec4_subtract __retVal, a.xxxx, u;
688 vec4 __operator - (const vec4 v, const float b)
690 __asm vec4_subtract __retVal, v, b.xxxx;
693 vec4 __operator * (const float a, const vec4 u)
695 __asm vec4_multiply __retVal, a.xxxx, u;
698 vec4 __operator * (const vec4 v, const float b)
700 __asm vec4_multiply __retVal, v, b.xxxx;
703 vec4 __operator / (const float a, const vec4 u)
706 __asm float_rcp invU.x, u.x;
707 __asm float_rcp invU.y, u.y;
708 __asm float_rcp invU.z, u.z;
709 __asm float_rcp invU.w, u.w;
710 __asm vec4_multiply __retVal, a.xxxx, invU;
713 vec4 __operator / (const vec4 v, const float b)
716 __asm float_rcp invB, b;
717 __asm vec4_multiply __retVal, v, invB.xxxx;
722 //// Basic ivec2/int operators
724 ivec2 __operator + (const int a, const ivec2 u) {
725 return ivec2 (a) + u;
728 ivec2 __operator + (const ivec2 v, const int b) {
729 return v + ivec2 (b);
732 ivec2 __operator - (const int a, const ivec2 u) {
733 return ivec2 (a) - u;
736 ivec2 __operator - (const ivec2 v, const int b) {
737 return v - ivec2 (b);
740 ivec2 __operator * (const int a, const ivec2 u) {
741 return ivec2 (a) * u;
744 ivec2 __operator * (const ivec2 v, const int b) {
745 return v * ivec2 (b);
748 ivec2 __operator / (const int a, const ivec2 u) {
749 return ivec2 (a) / u;
752 ivec2 __operator / (const ivec2 v, const int b) {
753 return v / ivec2 (b);
757 //// Basic ivec3/int operators
759 ivec3 __operator + (const int a, const ivec3 u) {
760 return ivec3 (a) + u;
763 ivec3 __operator + (const ivec3 v, const int b) {
764 return v + ivec3 (b);
767 ivec3 __operator - (const int a, const ivec3 u) {
768 return ivec3 (a) - u;
771 ivec3 __operator - (const ivec3 v, const int b) {
772 return v - ivec3 (b);
775 ivec3 __operator * (const int a, const ivec3 u) {
776 return ivec3 (a) * u;
779 ivec3 __operator * (const ivec3 v, const int b) {
780 return v * ivec3 (b);
783 ivec3 __operator / (const int a, const ivec3 u) {
784 return ivec3 (a) / u;
787 ivec3 __operator / (const ivec3 v, const int b) {
788 return v / ivec3 (b);
792 //// Basic ivec4/int operators
794 ivec4 __operator + (const int a, const ivec4 u) {
795 return ivec4 (a) + u;
798 ivec4 __operator + (const ivec4 v, const int b) {
799 return v + ivec4 (b);
802 ivec4 __operator - (const int a, const ivec4 u) {
803 return ivec4 (a) - u;
806 ivec4 __operator - (const ivec4 v, const int b) {
807 return v - ivec4 (b);
810 ivec4 __operator * (const int a, const ivec4 u) {
811 return ivec4 (a) * u;
814 ivec4 __operator * (const ivec4 v, const int b) {
815 return v * ivec4 (b);
818 ivec4 __operator / (const int a, const ivec4 u) {
819 return ivec4 (a) / u;
822 ivec4 __operator / (const ivec4 v, const int b) {
823 return v / ivec4 (b);
829 //// Unary negation operator
831 int __operator - (const int a)
836 __asm int_to_float x, a;
837 __asm float_negate x, x;
838 __asm float_to_int b, x;
842 ivec2 __operator - (const ivec2 v)
845 return ivec2 (-v.x, -v.y);
848 ivec3 __operator - (const ivec3 v)
851 return ivec3 (-v.x, -v.y, -v.z);
854 ivec4 __operator - (const ivec4 v)
857 return ivec4 (-v.x, -v.y, -v.z, -v.w);
860 float __operator - (const float a)
862 __asm vec4_negate __retVal.x, a;
865 vec2 __operator - (const vec2 v)
867 __asm vec4_negate __retVal.xy, v.xy;
870 vec3 __operator - (const vec3 v)
872 __asm vec4_negate __retVal.xyz, v.xyz;
875 vec4 __operator - (const vec4 v)
877 __asm vec4_negate __retVal, v;
880 mat2 __operator - (const mat2 m)
886 mat3 __operator - (const mat3 m)
893 mat4 __operator - (const mat4 m)
905 float dot(const float a, const float b)
910 float dot(const vec2 a, const vec2 b)
912 return a.x * b.x + a.y * b.y;
915 float dot(const vec3 a, const vec3 b)
917 __asm vec3_dot __retVal, a, b;
920 float dot(const vec4 a, const vec4 b)
922 __asm vec4_dot __retVal, a, b;
927 //// int assignment operators
929 void __operator += (inout int a, const int b)
931 a = int (float (a) + float (b));
934 void __operator -= (inout int a, const int b)
939 void __operator *= (inout int a, const int b)
941 a = int (float (a) * float (b));
944 void __operator /= (inout int a, const int b)
946 a = int (float (a) / float (b));
950 //// ivec2 assignment operators
952 void __operator += (inout ivec2 v, const ivec2 u)
958 void __operator -= (inout ivec2 v, const ivec2 u)
964 void __operator *= (inout ivec2 v, const ivec2 u)
970 void __operator /= (inout ivec2 v, const ivec2 u)
977 //// ivec3 assignment operators
979 void __operator += (inout ivec3 v, const ivec3 u)
986 void __operator -= (inout ivec3 v, const ivec3 u)
993 void __operator *= (inout ivec3 v, const ivec3 u)
1000 void __operator /= (inout ivec3 v, const ivec3 u)
1008 //// ivec4 assignment operators
1010 void __operator += (inout ivec4 v, const ivec4 u) {
1017 void __operator -= (inout ivec4 v, const ivec4 u) {
1024 void __operator *= (inout ivec4 v, const ivec4 u) {
1031 void __operator /= (inout ivec4 v, const ivec4 u) {
1039 //// float assignment operators
1041 void __operator += (inout float a, const float b)
1043 __asm vec4_add a.x, a.x, b;
1046 void __operator -= (inout float a, const float b)
1048 __asm vec4_subtract a.x, a, b;
1051 void __operator *= (inout float a, const float b)
1053 __asm vec4_multiply a.x, a, b;
1056 void __operator /= (inout float a, const float b)
1059 __asm float_rcp w.x, b;
1060 __asm vec4_multiply a.x, a, w;
1064 //// vec2 assignment operators
1066 void __operator += (inout vec2 v, const vec2 u)
1072 void __operator -= (inout vec2 v, const vec2 u)
1078 void __operator *= (inout vec2 v, const vec2 u)
1084 void __operator /= (inout vec2 v, const vec2 u)
1091 //// vec3 assignment operators
1093 void __operator += (inout vec3 v, const vec3 u)
1095 __asm vec4_add v.xyz, v, u;
1098 void __operator -= (inout vec3 v, const vec3 u)
1100 __asm vec4_subtract v.xyz, v, u;
1103 void __operator *= (inout vec3 v, const vec3 u)
1105 __asm vec4_multiply v.xyz, v, u;
1108 void __operator /= (inout vec3 v, const vec3 u)
1117 //// vec4 assignment operators
1119 void __operator += (inout vec4 v, const vec4 u)
1121 __asm vec4_add v, v, u;
1124 void __operator -= (inout vec4 v, const vec4 u)
1126 __asm vec4_subtract v, v, u;
1129 void __operator *= (inout vec4 v, const vec4 u)
1131 __asm vec4_multiply v, v, u;
1134 void __operator /= (inout vec4 v, const vec4 u)
1145 //// ivec2/int assignment operators
1147 void __operator += (inout ivec2 v, const int a)
1153 void __operator -= (inout ivec2 v, const int a)
1159 void __operator *= (inout ivec2 v, const int a)
1165 void __operator /= (inout ivec2 v, const int a)
1173 //// ivec3/int assignment operators
1175 void __operator += (inout ivec3 v, const int a)
1182 void __operator -= (inout ivec3 v, const int a)
1189 void __operator *= (inout ivec3 v, const int a)
1196 void __operator /= (inout ivec3 v, const int a)
1204 //// ivec4/int assignment operators
1206 void __operator += (inout ivec4 v, const int a)
1208 __asm vec4_add v, v, a.xxxx;
1211 void __operator -= (inout ivec4 v, const int a)
1213 __asm vec4_subtract v, v, a.xxxx;
1216 void __operator *= (inout ivec4 v, const int a)
1218 __asm vec4_multiply v, v, a.xxxx;
1221 void __operator /= (inout ivec4 v, const int a)
1231 //// vec2/float assignment operators
1233 void __operator += (inout vec2 v, const float a)
1235 __asm vec4_add v.xy, v, a.xx;
1238 void __operator -= (inout vec2 v, const float a)
1240 __asm vec4_subtract v.xy, v, a.xx;
1243 void __operator *= (inout vec2 v, const float a)
1245 __asm vec4_multiply v.xy, v, a.xx;
1248 void __operator /= (inout vec2 v, const float a)
1251 __asm float_rcp invA, a;
1252 __asm vec4_multiply v.xy, v.xy, a.xx;
1256 //// vec3/float assignment operators
1258 void __operator += (inout vec3 v, const float a)
1260 __asm vec4_add v.xyz, v, a.xxx;
1263 void __operator -= (inout vec3 v, const float a)
1265 __asm vec4_subtract v.xyz, v, a.xxx;
1268 void __operator *= (inout vec3 v, const float a)
1270 __asm vec4_multiply v.xyz, v, a.xxx;
1273 void __operator /= (inout vec3 v, const float a)
1276 __asm float_rcp invA, a;
1277 __asm vec4_multiply v.xyz, v.xyz, a.xxx;
1281 //// vec4/float assignment operators
1283 void __operator += (inout vec4 v, const float a)
1285 __asm vec4_add v, v, a.xxxx;
1288 void __operator -= (inout vec4 v, const float a)
1290 __asm vec4_subtract v, v, a.xxxx;
1293 void __operator *= (inout vec4 v, const float a)
1295 __asm vec4_multiply v, v, a.xxxx;
1298 void __operator /= (inout vec4 v, const float a)
1301 __asm float_rcp invA, a;
1302 __asm vec4_multiply v, v, a.xxxx;
1309 //// Basic mat2 operations
1311 mat2 __operator + (const mat2 m, const mat2 n)
1313 __retVal[0] = m[0] + n[0];
1314 __retVal[1] = m[1] + n[1];
1317 mat2 __operator - (const mat2 m, const mat2 n)
1319 __retVal[0] = m[0] - n[0];
1320 __retVal[1] = m[1] - n[1];
1323 mat2 __operator * (const mat2 m, const mat2 n)
1330 __retVal[0].x = dot(mRow0, n[0]);
1331 __retVal[1].x = dot(mRow0, n[1]);
1332 __retVal[0].y = dot(mRow1, n[0]);
1333 __retVal[1].y = dot(mRow1, n[1]);
1336 mat2 __operator / (const mat2 m, const mat2 n)
1338 __retVal[0] = m[0] / n[0];
1339 __retVal[1] = m[1] / n[1];
1343 //// Basic mat3 operations
1345 mat3 __operator + (const mat3 m, const mat3 n)
1347 __retVal[0] = m[0] + n[0];
1348 __retVal[1] = m[1] + n[1];
1349 __retVal[2] = m[2] + n[2];
1352 mat3 __operator - (const mat3 m, const mat3 n)
1354 __retVal[0] = m[0] - n[0];
1355 __retVal[1] = m[1] - n[1];
1356 __retVal[2] = m[2] - n[2];
1359 mat3 __operator * (const mat3 m, const mat3 n)
1361 vec3 mRow0, mRow1, mRow2;
1371 __retVal[0].x = dot(mRow0, n[0]);
1372 __retVal[1].x = dot(mRow0, n[1]);
1373 __retVal[2].x = dot(mRow0, n[2]);
1374 __retVal[0].y = dot(mRow1, n[0]);
1375 __retVal[1].y = dot(mRow1, n[1]);
1376 __retVal[2].y = dot(mRow1, n[2]);
1377 __retVal[0].z = dot(mRow2, n[0]);
1378 __retVal[1].z = dot(mRow2, n[1]);
1379 __retVal[2].z = dot(mRow2, n[2]);
1382 mat3 __operator / (const mat3 m, const mat3 n)
1384 __retVal[0] = m[0] / n[0];
1385 __retVal[1] = m[1] / n[1];
1386 __retVal[2] = m[2] / n[2];
1390 //// Basic mat4 operations
1392 mat4 __operator + (const mat4 m, const mat4 n)
1394 __retVal[0] = m[0] + n[0];
1395 __retVal[1] = m[1] + n[1];
1396 __retVal[2] = m[2] + n[2];
1397 __retVal[3] = m[3] + n[3];
1400 mat4 __operator - (const mat4 m, const mat4 n)
1402 __retVal[0] = m[0] - n[0];
1403 __retVal[1] = m[1] - n[1];
1404 __retVal[2] = m[2] - n[2];
1405 __retVal[3] = m[3] - n[3];
1408 mat4 __operator * (const mat4 m, const mat4 n)
1410 vec4 mRow0, mRow1, mRow2, mRow3;
1427 __retVal[0].x = dot(mRow0, n[0]);
1428 __retVal[1].x = dot(mRow0, n[1]);
1429 __retVal[2].x = dot(mRow0, n[2]);
1430 __retVal[3].x = dot(mRow0, n[3]);
1431 __retVal[0].y = dot(mRow1, n[0]);
1432 __retVal[1].y = dot(mRow1, n[1]);
1433 __retVal[2].y = dot(mRow1, n[2]);
1434 __retVal[3].y = dot(mRow1, n[3]);
1435 __retVal[0].z = dot(mRow2, n[0]);
1436 __retVal[1].z = dot(mRow2, n[1]);
1437 __retVal[2].z = dot(mRow2, n[2]);
1438 __retVal[3].z = dot(mRow2, n[3]);
1439 __retVal[0].w = dot(mRow3, n[0]);
1440 __retVal[1].w = dot(mRow3, n[1]);
1441 __retVal[2].w = dot(mRow3, n[2]);
1442 __retVal[3].w = dot(mRow3, n[3]);
1445 mat4 __operator / (const mat4 m, const mat4 n)
1447 __retVal[0] = m[0] / n[0];
1448 __retVal[1] = m[1] / n[1];
1449 __retVal[2] = m[2] / n[2];
1450 __retVal[3] = m[3] / n[3];
1454 //// mat2/float operations
1456 mat2 __operator + (const float a, const mat2 n)
1458 __retVal[0] = a + n[0];
1459 __retVal[1] = a + n[1];
1462 mat2 __operator + (const mat2 m, const float b)
1464 __retVal[0] = m[0] + b;
1465 __retVal[1] = m[1] + b;
1468 mat2 __operator - (const float a, const mat2 n)
1470 __retVal[0] = a - n[0];
1471 __retVal[1] = a - n[1];
1474 mat2 __operator - (const mat2 m, const float b)
1476 __retVal[0] = m[0] - b;
1477 __retVal[1] = m[1] - b;
1480 mat2 __operator * (const float a, const mat2 n)
1482 __retVal[0] = a * n[0];
1483 __retVal[1] = a * n[1];
1486 mat2 __operator * (const mat2 m, const float b)
1488 __retVal[0] = m[0] * b;
1489 __retVal[1] = m[1] * b;
1492 mat2 __operator / (const float a, const mat2 n)
1494 __retVal[0] = a / n[0];
1495 __retVal[1] = a / n[1];
1498 mat2 __operator / (const mat2 m, const float b)
1500 __retVal[0] = m[0] / b;
1501 __retVal[1] = m[1] / b;
1505 //// mat3/float operations
1507 mat3 __operator + (const float a, const mat3 n)
1509 __retVal[0] = a + n[0];
1510 __retVal[1] = a + n[1];
1511 __retVal[2] = a + n[2];
1514 mat3 __operator + (const mat3 m, const float b)
1516 __retVal[0] = m[0] + b;
1517 __retVal[1] = m[1] + b;
1518 __retVal[2] = m[2] + b;
1521 mat3 __operator - (const float a, const mat3 n)
1523 __retVal[0] = a - n[0];
1524 __retVal[1] = a - n[1];
1525 __retVal[2] = a - n[2];
1528 mat3 __operator - (const mat3 m, const float b)
1530 __retVal[0] = m[0] - b;
1531 __retVal[1] = m[1] - b;
1532 __retVal[2] = m[2] - b;
1535 mat3 __operator * (const float a, const mat3 n)
1537 __retVal[0] = a * n[0];
1538 __retVal[1] = a * n[1];
1539 __retVal[2] = a * n[2];
1542 mat3 __operator * (const mat3 m, const float b)
1544 __retVal[0] = m[0] * b;
1545 __retVal[1] = m[1] * b;
1546 __retVal[2] = m[2] * b;
1549 mat3 __operator / (const float a, const mat3 n)
1551 __retVal[0] = a / n[0];
1552 __retVal[1] = a / n[1];
1553 __retVal[2] = a / n[2];
1556 mat3 __operator / (const mat3 m, const float b)
1558 __retVal[0] = m[0] / b;
1559 __retVal[1] = m[1] / b;
1560 __retVal[2] = m[2] / b;
1564 //// mat4/float operations
1566 mat4 __operator + (const float a, const mat4 n)
1568 __retVal[0] = a + n[0];
1569 __retVal[1] = a + n[1];
1570 __retVal[2] = a + n[2];
1571 __retVal[3] = a + n[3];
1574 mat4 __operator + (const mat4 m, const float b)
1576 __retVal[0] = m[0] + b;
1577 __retVal[1] = m[1] + b;
1578 __retVal[2] = m[2] + b;
1579 __retVal[3] = m[3] + b;
1582 mat4 __operator - (const float a, const mat4 n)
1584 __retVal[0] = a - n[0];
1585 __retVal[1] = a - n[1];
1586 __retVal[2] = a - n[2];
1587 __retVal[3] = a - n[3];
1590 mat4 __operator - (const mat4 m, const float b)
1592 __retVal[0] = m[0] - b;
1593 __retVal[1] = m[1] - b;
1594 __retVal[2] = m[2] - b;
1595 __retVal[3] = m[3] - b;
1598 mat4 __operator * (const float a, const mat4 n)
1600 __retVal[0] = a * n[0];
1601 __retVal[1] = a * n[1];
1602 __retVal[2] = a * n[2];
1603 __retVal[3] = a * n[3];
1606 mat4 __operator * (const mat4 m, const float b)
1608 __retVal[0] = m[0] * b;
1609 __retVal[1] = m[1] * b;
1610 __retVal[2] = m[2] * b;
1611 __retVal[3] = m[3] * b;
1614 mat4 __operator / (const float a, const mat4 n)
1616 __retVal[0] = a / n[0];
1617 __retVal[1] = a / n[1];
1618 __retVal[2] = a / n[2];
1619 __retVal[3] = a / n[3];
1622 mat4 __operator / (const mat4 m, const float b)
1624 __retVal[0] = m[0] / b;
1625 __retVal[1] = m[1] / b;
1626 __retVal[2] = m[2] / b;
1627 __retVal[3] = m[3] / b;
1632 //// matrix / vector products
1634 vec2 __operator * (const mat2 m, const vec2 v)
1636 __retVal.x = dot(m[0], v);
1637 __retVal.y = dot(m[1], v);
1640 vec2 __operator * (const vec2 v, const mat2 m)
1647 __retVal.x = dot(v, r0);
1648 __retVal.y = dot(v, r1);
1651 vec3 __operator * (const mat3 m, const vec3 v)
1653 __retVal.x = dot(m[0], v);
1654 __retVal.y = dot(m[1], v);
1655 __retVal.z = dot(m[2], v);
1658 vec3 __operator * (const vec3 v, const mat3 m)
1670 __asm vec3_dot __retVal.x, v, r0;
1671 __asm vec3_dot __retVal.y, v, r1;
1672 __asm vec3_dot __retVal.z, v, r2;
1675 vec4 __operator * (const mat4 m, const vec4 v)
1677 __retVal.x = dot(m[0], v);
1678 __retVal.y = dot(m[1], v);
1679 __retVal.z = dot(m[2], v);
1680 __retVal.w = dot(m[3], v);
1683 vec4 __operator * (const vec4 v, const mat4 m)
1685 vec4 r0, r1, r2, r3;
1702 __asm vec4_dot __retVal.x, v, r0;
1703 __asm vec4_dot __retVal.y, v, r1;
1704 __asm vec4_dot __retVal.z, v, r2;
1705 __asm vec4_dot __retVal.w, v, r3;
1710 //// mat2 assignment operators
1712 void __operator += (inout mat2 m, const mat2 n)
1718 void __operator -= (inout mat2 m, const mat2 n)
1724 void __operator *= (inout mat2 m, const mat2 n)
1729 void __operator /= (inout mat2 m, const mat2 n)
1736 //// mat3 assignment operators
1738 void __operator += (inout mat3 m, const mat3 n)
1745 void __operator -= (inout mat3 m, const mat3 n)
1752 void __operator *= (inout mat3 m, const mat3 n)
1757 void __operator /= (inout mat3 m, const mat3 n)
1765 // mat4 assignment operators
1767 void __operator += (inout mat4 m, const mat4 n)
1775 void __operator -= (inout mat4 m, const mat4 n) {
1782 void __operator *= (inout mat4 m, const mat4 n)
1787 void __operator /= (inout mat4 m, const mat4 n)
1796 //// mat2/float assignment operators
1798 void __operator += (inout mat2 m, const float a) {
1803 void __operator -= (inout mat2 m, const float a) {
1808 void __operator *= (inout mat2 m, const float a) {
1813 void __operator /= (inout mat2 m, const float a) {
1819 //// mat3/float assignment operators
1821 void __operator += (inout mat3 m, const float a) {
1827 void __operator -= (inout mat3 m, const float a) {
1833 void __operator *= (inout mat3 m, const float a) {
1839 void __operator /= (inout mat3 m, const float a) {
1846 //// mat4/float assignment operators
1848 void __operator += (inout mat4 m, const float a) {
1855 void __operator -= (inout mat4 m, const float a) {
1862 void __operator *= (inout mat4 m, const float a) {
1869 void __operator /= (inout mat4 m, const float a) {
1878 //// vec/mat assignment operators
1880 void __operator *= (inout vec2 v, const mat2 m)
1885 void __operator *= (inout vec3 v, const mat3 m)
1890 void __operator *= (inout vec4 v, const mat4 m)
1897 //// pre-decrement operators
1899 int __operator --(inout int a)
1905 ivec2 __operator --(inout ivec2 v)
1911 ivec3 __operator --(inout ivec3 v)
1917 ivec4 __operator --(inout ivec4 v)
1924 float __operator --(inout float a)
1930 vec2 __operator --(inout vec2 v)
1936 vec3 __operator --(inout vec3 v)
1942 vec4 __operator --(inout vec4 v)
1949 mat2 __operator --(inout mat2 m)
1951 m[0] = m[0] - vec2(1.0);
1952 m[1] = m[1] - vec2(1.0);
1956 mat3 __operator --(inout mat3 m)
1958 m[0] = m[0] - vec3(1.0);
1959 m[1] = m[1] - vec3(1.0);
1960 m[2] = m[2] - vec3(1.0);
1964 mat4 __operator --(inout mat4 m)
1966 m[0] = m[0] - vec4(1.0);
1967 m[1] = m[1] - vec4(1.0);
1968 m[2] = m[2] - vec4(1.0);
1969 m[3] = m[3] - vec4(1.0);
1974 //// pre-increment operators
1976 int __operator ++(inout int a)
1982 ivec2 __operator ++(inout ivec2 v)
1988 ivec3 __operator ++(inout ivec3 v)
1994 ivec4 __operator ++(inout ivec4 v)
2001 float __operator ++(inout float a)
2007 vec2 __operator ++(inout vec2 v)
2013 vec3 __operator ++(inout vec3 v)
2019 vec4 __operator ++(inout vec4 v)
2026 mat2 __operator ++(inout mat2 m)
2028 m[0] = m[0] + vec2(1.0);
2029 m[1] = m[1] + vec2(1.0);
2033 mat3 __operator ++(inout mat3 m)
2035 m[0] = m[0] + vec3(1.0);
2036 m[1] = m[1] + vec3(1.0);
2037 m[2] = m[2] + vec3(1.0);
2041 mat4 __operator ++(inout mat4 m)
2043 m[0] = m[0] + vec4(1.0);
2044 m[1] = m[1] + vec4(1.0);
2045 m[2] = m[2] + vec4(1.0);
2046 m[3] = m[3] + vec4(1.0);
2054 int __postDecr(inout int a)
2060 ivec2 __postDecr(inout ivec2 v)
2066 ivec3 __postDecr(inout ivec3 v)
2072 ivec4 __postDecr(inout ivec4 v)
2079 float __postDecr(inout float a)
2085 vec2 __postDecr(inout vec2 v)
2091 vec3 __postDecr(inout vec3 v)
2097 vec4 __postDecr(inout vec4 v)
2104 mat2 __postDecr(inout mat2 m)
2107 m[0] = m[0] - vec2(1.0);
2108 m[1] = m[1] - vec2(1.0);
2111 mat3 __postDecr(inout mat3 m)
2114 m[0] = m[0] - vec3(1.0);
2115 m[1] = m[1] - vec3(1.0);
2116 m[2] = m[2] - vec3(1.0);
2119 mat4 __postDecr(inout mat4 m)
2122 m[0] = m[0] - vec4(1.0);
2123 m[1] = m[1] - vec4(1.0);
2124 m[2] = m[2] - vec4(1.0);
2125 m[3] = m[3] - vec4(1.0);
2131 float __postIncr(inout float a) {
2137 vec2 __postIncr(inout vec2 v) {
2138 return vec2 (v.x++, v.y++);
2141 vec3 __postIncr(inout vec3 v) {
2142 return vec3 (v.x++, v.y++, v.z++);
2145 vec4 __postIncr(inout vec4 v)
2152 int __postIncr(inout int a) {
2158 ivec2 __postIncr(inout ivec2 v) {
2159 return ivec2 (v.x++, v.y++);
2162 ivec3 __postIncr(inout ivec3 v) {
2163 return ivec3 (v.x++, v.y++, v.z++);
2166 ivec4 __postIncr(inout ivec4 v) {
2167 return ivec4 (v.x++, v.y++, v.z++, v.w++);
2172 mat2 __postIncr(inout mat2 m) {
2173 return mat2 (m[0]++, m[1]++);
2176 mat3 __postIncr(inout mat3 m) {
2177 return mat3 (m[0]++, m[1]++, m[2]++);
2180 mat4 __postIncr(inout mat4 m) {
2181 return mat4 (m[0]++, m[1]++, m[2]++, m[3]++);
2186 //// inequality operators
2189 // XXX are the inequality operators for floats/ints really needed????
2190 bool __operator < (const float a, const float b)
2192 __asm vec4_sgt __retVal.x, b, a;
2196 bool __operator < (const int a, const int b) {
2197 return float (a) < float (b);
2200 bool __operator > (const float a, const float b) {
2202 __asm float_less c, b, a;
2206 bool __operator > (const int a, const int b) {
2207 return float (a) > float (b);
2210 bool __operator >= (const float a, const float b) {
2212 __asm float_less g, b, a;
2213 __asm float_equal e, a, b;
2217 bool __operator >= (const int a, const int b) {
2218 return float (a) >= float (b);
2221 bool __operator <= (const float a, const float b) {
2223 __asm float_less g, a, b;
2224 __asm float_equal e, a, b;
2228 bool __operator <= (const int a, const int b) {
2229 return float (a) <= float (b);
2232 bool __operator ^^ (const bool a, const bool b) {
2239 // These operators are handled internally by the compiler:
2241 // bool __operator && (bool a, bool b) {
2242 // return a ? b : false;
2244 // bool __operator || (bool a, bool b) {
2245 // return a ? true : b;
2249 bool __operator ! (const bool a) {
2253 bool __logicalAnd(const bool a, const bool b)
2263 // MESA-specific extension functions.
2266 void printMESA (const float f) {
2267 __asm float_print f;
2270 void printMESA (const int i) {
2274 void printMESA (const bool b) {
2278 void printMESA (const vec2 v) {
2283 void printMESA (const vec3 v) {
2289 void printMESA (const vec4 v) {
2296 void printMESA (const ivec2 v) {
2301 void printMESA (const ivec3 v) {
2307 void printMESA (const ivec4 v) {
2314 void printMESA (const bvec2 v) {
2319 void printMESA (const bvec3 v) {
2325 void printMESA (const bvec4 v) {
2332 void printMESA (const mat2 m) {
2337 void printMESA (const mat3 m) {
2343 void printMESA (const mat4 m) {
2350 void printMESA (const sampler1D e) {
2354 void printMESA (const sampler2D e) {
2358 void printMESA (const sampler3D e) {
2362 void printMESA (const samplerCube e) {
2366 void printMESA (const sampler1DShadow e) {
2370 void printMESA (const sampler2DShadow e) {