Merge branch 'crestline-qa', adding support for the 965GM chipset.
[mesa.git] / src / mesa / shader / slang / library / slang_builtin_120_common.gc
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.6
4 *
5 * Copyright (C) 2006 Brian Paul All Rights Reserved.
6 *
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:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
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.
23 */
24
25 //
26 // From Shader Spec, ver. 1.20, rev. 6
27 //
28
29 //
30 // 8.5 Matrix Functions
31 //
32
33 mat2x3 matrixCompMult (mat2x3 m, mat2x3 n) {
34 return mat2x3 (m[0] * n[0], m[1] * n[1]);
35 }
36
37 mat2x4 matrixCompMult (mat2x4 m, mat2x4 n) {
38 return mat2x4 (m[0] * n[0], m[1] * n[1]);
39 }
40
41 mat3x2 matrixCompMult (mat3x2 m, mat3x2 n) {
42 return mat3x2 (m[0] * n[0], m[1] * n[1], m[2] * n[2]);
43 }
44
45 mat3x4 matrixCompMult (mat3x4 m, mat3x4 n) {
46 return mat3x4 (m[0] * n[0], m[1] * n[1], m[2] * n[2]);
47 }
48
49 mat4x2 matrixCompMult (mat4x2 m, mat4x2 n) {
50 return mat4x2 (m[0] * n[0], m[1] * n[1], m[2] * n[2], m[3] * n[3]);
51 }
52
53 mat4x3 matrixCompMult (mat4x3 m, mat4x3 n) {
54 return mat4x3 (m[0] * n[0], m[1] * n[1], m[2] * n[2], m[3] * n[3]);
55 }
56
57 mat2 outerProduct (vec2 c, vec2 r) {
58 return mat2 (
59 c.x * r.x, c.y * r.x,
60 c.x * r.y, c.y * r.y
61 );
62 }
63
64 mat3 outerProduct (vec3 c, vec3 r) {
65 return mat3 (
66 c.x * r.x, c.y * r.x, c.z * r.x,
67 c.x * r.y, c.y * r.y, c.z * r.y,
68 c.x * r.z, c.y * r.z, c.z * r.z
69 );
70 }
71
72 mat4 outerProduct (vec4 c, vec4 r) {
73 return mat4 (
74 c.x * r.x, c.y * r.x, c.z * r.x, c.w * r.x,
75 c.x * r.y, c.y * r.y, c.z * r.y, c.w * r.y,
76 c.x * r.z, c.y * r.z, c.z * r.z, c.w * r.z,
77 c.x * r.w, c.y * r.w, c.z * r.w, c.w * r.w
78 );
79 }
80
81 mat2x3 outerProduct (vec3 c, vec2 r) {
82 return mat2x3 (
83 c.x * r.x, c.y * r.x, c.z * r.x,
84 c.x * r.y, c.y * r.y, c.z * r.y
85 );
86 }
87
88 mat3x2 outerProduct (vec2 c, vec3 r) {
89 return mat3x2 (
90 c.x * r.x, c.y * r.x,
91 c.x * r.y, c.y * r.y,
92 c.x * r.z, c.y * r.z
93 );
94 }
95
96 mat2x4 outerProduct (vec4 c, vec2 r) {
97 return mat2x4 (
98 c.x * r.x, c.y * r.x, c.z * r.x, c.w * r.x,
99 c.x * r.y, c.y * r.y, c.z * r.y, c.w * r.y
100 );
101 }
102
103 mat4x2 outerProduct (vec2 c, vec4 r) {
104 return mat4x2 (
105 c.x * r.x, c.y * r.x,
106 c.x * r.y, c.y * r.y,
107 c.x * r.z, c.y * r.z,
108 c.x * r.w, c.y * r.w
109 );
110 }
111
112 mat3x4 outerProduct (vec4 c, vec3 r) {
113 return mat3x4 (
114 c.x * r.x, c.y * r.x, c.z * r.x, c.w * r.x,
115 c.x * r.y, c.y * r.y, c.z * r.y, c.w * r.y,
116 c.x * r.z, c.y * r.z, c.z * r.z, c.w * r.z
117 );
118 }
119
120 mat4x3 outerProduct (vec3 c, vec4 r) {
121 return mat4x3 (
122 c.x * r.x, c.y * r.x, c.z * r.x,
123 c.x * r.y, c.y * r.y, c.z * r.y,
124 c.x * r.z, c.y * r.z, c.z * r.z,
125 c.x * r.w, c.y * r.w, c.z * r.w
126 );
127 }
128
129 mat2 transpose (mat2 m) {
130 return mat2 (
131 m[0].x, m[1].x,
132 m[0].y, m[1].y
133 );
134 }
135
136 mat3 transpose (mat3 m) {
137 return mat3 (
138 m[0].x, m[1].x, m[2].x,
139 m[0].y, m[1].y, m[2].y,
140 m[0].z, m[1].z, m[2].z
141 );
142 }
143
144 mat4 transpose (mat4 m) {
145 return mat4 (
146 m[0].x, m[1].x, m[2].x, m[3].x,
147 m[0].y, m[1].y, m[2].y, m[3].y,
148 m[0].z, m[1].z, m[2].z, m[3].z,
149 m[0].w, m[1].w, m[2].w, m[3].w
150 );
151 }
152
153 mat2x3 transpose (mat3x2 m) {
154 return mat2x3 (
155 m[0].x, m[1].x, m[2].x,
156 m[0].y, m[1].y, m[2].y
157 );
158 }
159
160 mat3x2 transpose (mat2x3 m) {
161 return mat3x2 (
162 m[0].x, m[1].x,
163 m[0].y, m[1].y,
164 m[0].z, m[1].z
165 );
166 }
167
168 mat2x4 transpose (mat4x2 m) {
169 return mat2x4 (
170 m[0].x, m[1].x, m[2].x, m[3].x,
171 m[0].y, m[1].y, m[2].y, m[3].y
172 );
173 }
174
175 mat4x2 transpose (mat2x4 m) {
176 return mat4x2 (
177 m[0].x, m[1].x,
178 m[0].y, m[1].y,
179 m[0].z, m[1].z,
180 m[0].w, m[1].w
181 );
182 }
183
184 mat3x4 transpose (mat4x3 m) {
185 return mat3x4 (
186 m[0].x, m[1].x, m[2].x, m[3].x,
187 m[0].y, m[1].y, m[2].y, m[3].y,
188 m[0].z, m[1].z, m[2].z, m[3].z
189 );
190 }
191
192 mat4x3 transpose (mat3x4 m) {
193 return mat4x3 (
194 m[0].x, m[1].x, m[2].x,
195 m[0].y, m[1].y, m[2].y,
196 m[0].z, m[1].z, m[2].z,
197 m[0].w, m[1].w, m[2].w
198 );
199 }
200