Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 1 | // Copyright 2016 The SwiftShader Authors. All Rights Reserved. |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2 | // |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6 | // |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 8 | // |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 14 | |
| 15 | #include "ShaderCore.hpp" |
| 16 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 17 | #include "Renderer/Renderer.hpp" |
| 18 | #include "Common/Debug.hpp" |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 19 | |
Alexis Hetu | d5c31da | 2015-08-28 14:39:13 -0400 | [diff] [blame] | 20 | #include <limits.h> |
| 21 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 22 | namespace sw |
| 23 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 24 | extern TranscendentalPrecision logPrecision; |
| 25 | extern TranscendentalPrecision expPrecision; |
| 26 | extern TranscendentalPrecision rcpPrecision; |
| 27 | extern TranscendentalPrecision rsqPrecision; |
| 28 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 29 | Vector4s::Vector4s() |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 30 | { |
| 31 | } |
| 32 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 33 | Vector4s::Vector4s(unsigned short x, unsigned short y, unsigned short z, unsigned short w) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 34 | { |
| 35 | this->x = Short4(x); |
| 36 | this->y = Short4(y); |
| 37 | this->z = Short4(z); |
| 38 | this->w = Short4(w); |
| 39 | } |
| 40 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 41 | Vector4s::Vector4s(const Vector4s &rhs) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 42 | { |
| 43 | x = rhs.x; |
| 44 | y = rhs.y; |
| 45 | z = rhs.z; |
| 46 | w = rhs.w; |
| 47 | } |
| 48 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 49 | Vector4s &Vector4s::operator=(const Vector4s &rhs) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 50 | { |
| 51 | x = rhs.x; |
| 52 | y = rhs.y; |
| 53 | z = rhs.z; |
| 54 | w = rhs.w; |
| 55 | |
| 56 | return *this; |
| 57 | } |
| 58 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 59 | Short4 &Vector4s::operator[](int i) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 60 | { |
| 61 | switch(i) |
| 62 | { |
| 63 | case 0: return x; |
| 64 | case 1: return y; |
| 65 | case 2: return z; |
| 66 | case 3: return w; |
| 67 | } |
| 68 | |
| 69 | return x; |
| 70 | } |
| 71 | |
| 72 | Vector4f::Vector4f() |
| 73 | { |
| 74 | } |
| 75 | |
| 76 | Vector4f::Vector4f(float x, float y, float z, float w) |
| 77 | { |
| 78 | this->x = Float4(x); |
| 79 | this->y = Float4(y); |
| 80 | this->z = Float4(z); |
| 81 | this->w = Float4(w); |
| 82 | } |
| 83 | |
| 84 | Vector4f::Vector4f(const Vector4f &rhs) |
| 85 | { |
| 86 | x = rhs.x; |
| 87 | y = rhs.y; |
| 88 | z = rhs.z; |
| 89 | w = rhs.w; |
| 90 | } |
| 91 | |
| 92 | Vector4f &Vector4f::operator=(const Vector4f &rhs) |
| 93 | { |
| 94 | x = rhs.x; |
| 95 | y = rhs.y; |
| 96 | z = rhs.z; |
| 97 | w = rhs.w; |
| 98 | |
| 99 | return *this; |
| 100 | } |
| 101 | |
| 102 | Float4 &Vector4f::operator[](int i) |
| 103 | { |
| 104 | switch(i) |
| 105 | { |
| 106 | case 0: return x; |
| 107 | case 1: return y; |
| 108 | case 2: return z; |
| 109 | case 3: return w; |
| 110 | } |
| 111 | |
| 112 | return x; |
| 113 | } |
| 114 | |
| 115 | Float4 exponential2(RValue<Float4> x, bool pp) |
| 116 | { |
| 117 | Float4 x0; |
| 118 | Float4 x1; |
| 119 | Int4 x2; |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 120 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 121 | x0 = x; |
| 122 | |
| 123 | x0 = Min(x0, As<Float4>(Int4(0x43010000))); // 129.00000e+0f |
| 124 | x0 = Max(x0, As<Float4>(Int4(0xC2FDFFFF))); // -126.99999e+0f |
| 125 | x1 = x0; |
| 126 | x1 -= Float4(0.5f); |
| 127 | x2 = RoundInt(x1); |
| 128 | x1 = Float4(x2); |
| 129 | x2 += Int4(0x0000007F); // 127 |
| 130 | x2 = x2 << 23; |
| 131 | x0 -= x1; |
| 132 | x1 = As<Float4>(Int4(0x3AF61905)); // 1.8775767e-3f |
| 133 | x1 *= x0; |
| 134 | x1 += As<Float4>(Int4(0x3C134806)); // 8.9893397e-3f |
| 135 | x1 *= x0; |
| 136 | x1 += As<Float4>(Int4(0x3D64AA23)); // 5.5826318e-2f |
| 137 | x1 *= x0; |
| 138 | x1 += As<Float4>(Int4(0x3E75EAD4)); // 2.4015361e-1f |
| 139 | x1 *= x0; |
| 140 | x1 += As<Float4>(Int4(0x3F31727B)); // 6.9315308e-1f |
| 141 | x1 *= x0; |
| 142 | x1 += As<Float4>(Int4(0x3F7FFFFF)); // 9.9999994e-1f |
| 143 | x1 *= As<Float4>(x2); |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 144 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 145 | return x1; |
| 146 | } |
| 147 | |
| 148 | Float4 logarithm2(RValue<Float4> x, bool absolute, bool pp) |
| 149 | { |
| 150 | Float4 x0; |
| 151 | Float4 x1; |
| 152 | Float4 x2; |
| 153 | Float4 x3; |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 154 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 155 | x0 = x; |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 156 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 157 | x1 = As<Float4>(As<Int4>(x0) & Int4(0x7F800000)); |
| 158 | x1 = As<Float4>(As<UInt4>(x1) >> 8); |
| 159 | x1 = As<Float4>(As<Int4>(x1) | As<Int4>(Float4(1.0f))); |
| 160 | x1 = (x1 - Float4(1.4960938f)) * Float4(256.0f); // FIXME: (x1 - 1.4960938f) * 256.0f; |
| 161 | x0 = As<Float4>((As<Int4>(x0) & Int4(0x007FFFFF)) | As<Int4>(Float4(1.0f))); |
| 162 | |
| 163 | x2 = (Float4(9.5428179e-2f) * x0 + Float4(4.7779095e-1f)) * x0 + Float4(1.9782813e-1f); |
| 164 | x3 = ((Float4(1.6618466e-2f) * x0 + Float4(2.0350508e-1f)) * x0 + Float4(2.7382900e-1f)) * x0 + Float4(4.0496687e-2f); |
| 165 | x2 /= x3; |
| 166 | |
| 167 | x1 += (x0 - Float4(1.0f)) * x2; |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 168 | |
Alexis Hetu | 0b7003b | 2017-11-13 16:21:11 -0500 | [diff] [blame] | 169 | Int4 pos_inf_x = CmpEQ(As<Int4>(x), Int4(0x7F800000)); |
| 170 | return As<Float4>((pos_inf_x & As<Int4>(x)) | (~pos_inf_x & As<Int4>(x1))); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | Float4 exponential(RValue<Float4> x, bool pp) |
| 174 | { |
| 175 | // FIXME: Propagate the constant |
Alexis Hetu | 0b7003b | 2017-11-13 16:21:11 -0500 | [diff] [blame] | 176 | return exponential2(Float4(1.44269504f) * x, pp); // 1/ln(2) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | Float4 logarithm(RValue<Float4> x, bool absolute, bool pp) |
| 180 | { |
| 181 | // FIXME: Propagate the constant |
| 182 | return Float4(6.93147181e-1f) * logarithm2(x, absolute, pp); // ln(2) |
| 183 | } |
| 184 | |
| 185 | Float4 power(RValue<Float4> x, RValue<Float4> y, bool pp) |
| 186 | { |
| 187 | Float4 log = logarithm2(x, true, pp); |
| 188 | log *= y; |
| 189 | return exponential2(log, pp); |
| 190 | } |
| 191 | |
Nicolas Capens | 05b3d66 | 2016-02-25 23:58:33 -0500 | [diff] [blame] | 192 | Float4 reciprocal(RValue<Float4> x, bool pp, bool finite, bool exactAtPow2) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 193 | { |
| 194 | Float4 rcp; |
| 195 | |
| 196 | if(!pp && rcpPrecision >= WHQL) |
| 197 | { |
| 198 | rcp = Float4(1.0f) / x; |
| 199 | } |
| 200 | else |
| 201 | { |
Nicolas Capens | 05b3d66 | 2016-02-25 23:58:33 -0500 | [diff] [blame] | 202 | rcp = Rcp_pp(x, exactAtPow2); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 203 | |
| 204 | if(!pp) |
| 205 | { |
| 206 | rcp = (rcp + rcp) - (x * rcp * rcp); |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | if(finite) |
| 211 | { |
| 212 | int big = 0x7F7FFFFF; |
| 213 | rcp = Min(rcp, Float4((float&)big)); |
| 214 | } |
| 215 | |
| 216 | return rcp; |
| 217 | } |
| 218 | |
| 219 | Float4 reciprocalSquareRoot(RValue<Float4> x, bool absolute, bool pp) |
| 220 | { |
| 221 | Float4 abs = x; |
| 222 | |
| 223 | if(absolute) |
| 224 | { |
| 225 | abs = Abs(abs); |
| 226 | } |
| 227 | |
| 228 | Float4 rsq; |
| 229 | |
Alexis Hetu | a0ef97a | 2017-11-13 17:31:20 -0500 | [diff] [blame^] | 230 | if(!pp) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 231 | { |
| 232 | rsq = Float4(1.0f) / Sqrt(abs); |
| 233 | } |
| 234 | else |
| 235 | { |
| 236 | rsq = RcpSqrt_pp(abs); |
| 237 | |
| 238 | if(!pp) |
| 239 | { |
| 240 | rsq = rsq * (Float4(3.0f) - rsq * rsq * abs) * Float4(0.5f); |
| 241 | } |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 242 | |
Alexis Hetu | a0ef97a | 2017-11-13 17:31:20 -0500 | [diff] [blame^] | 243 | rsq = As<Float4>(CmpNEQ(As<Int4>(abs), Int4(0x7F800000)) & As<Int4>(rsq)); |
| 244 | } |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 245 | |
| 246 | return rsq; |
| 247 | } |
| 248 | |
| 249 | Float4 modulo(RValue<Float4> x, RValue<Float4> y) |
| 250 | { |
| 251 | return x - y * Floor(x / y); |
| 252 | } |
| 253 | |
| 254 | Float4 sine_pi(RValue<Float4> x, bool pp) |
| 255 | { |
| 256 | const Float4 A = Float4(-4.05284734e-1f); // -4/pi^2 |
| 257 | const Float4 B = Float4(1.27323954e+0f); // 4/pi |
| 258 | const Float4 C = Float4(7.75160950e-1f); |
| 259 | const Float4 D = Float4(2.24839049e-1f); |
| 260 | |
| 261 | // Parabola approximating sine |
| 262 | Float4 sin = x * (Abs(x) * A + B); |
| 263 | |
| 264 | // Improve precision from 0.06 to 0.001 |
| 265 | if(true) |
| 266 | { |
| 267 | sin = sin * (Abs(sin) * D + C); |
| 268 | } |
| 269 | |
| 270 | return sin; |
| 271 | } |
| 272 | |
| 273 | Float4 cosine_pi(RValue<Float4> x, bool pp) |
| 274 | { |
| 275 | // cos(x) = sin(x + pi/2) |
| 276 | Float4 y = x + Float4(1.57079632e+0f); |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 277 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 278 | // Wrap around |
| 279 | y -= As<Float4>(CmpNLT(y, Float4(3.14159265e+0f)) & As<Int4>(Float4(6.28318530e+0f))); |
| 280 | |
| 281 | return sine_pi(y, pp); |
| 282 | } |
| 283 | |
| 284 | Float4 sine(RValue<Float4> x, bool pp) |
| 285 | { |
| 286 | // Reduce to [-0.5, 0.5] range |
| 287 | Float4 y = x * Float4(1.59154943e-1f); // 1/2pi |
| 288 | y = y - Round(y); |
| 289 | |
| 290 | const Float4 A = Float4(-16.0f); |
| 291 | const Float4 B = Float4(8.0f); |
| 292 | const Float4 C = Float4(7.75160950e-1f); |
| 293 | const Float4 D = Float4(2.24839049e-1f); |
| 294 | |
| 295 | // Parabola approximating sine |
| 296 | Float4 sin = y * (Abs(y) * A + B); |
| 297 | |
| 298 | // Improve precision from 0.06 to 0.001 |
| 299 | if(true) |
| 300 | { |
| 301 | sin = sin * (Abs(sin) * D + C); |
| 302 | } |
| 303 | |
| 304 | return sin; |
| 305 | } |
| 306 | |
| 307 | Float4 cosine(RValue<Float4> x, bool pp) |
| 308 | { |
| 309 | // cos(x) = sin(x + pi/2) |
| 310 | Float4 y = x + Float4(1.57079632e+0f); |
| 311 | return sine(y, pp); |
| 312 | } |
| 313 | |
| 314 | Float4 tangent(RValue<Float4> x, bool pp) |
| 315 | { |
| 316 | return sine(x, pp) / cosine(x, pp); |
| 317 | } |
| 318 | |
| 319 | Float4 arccos(RValue<Float4> x, bool pp) |
| 320 | { |
| 321 | // pi/2 - arcsin(x) |
| 322 | return Float4(1.57079632e+0f) - arcsin(x); |
| 323 | } |
| 324 | |
| 325 | Float4 arcsin(RValue<Float4> x, bool pp) |
| 326 | { |
| 327 | // x*(pi/2-sqrt(1-x*x)*pi/5) |
| 328 | return x * (Float4(1.57079632e+0f) - Sqrt(Float4(1.0f) - x*x) * Float4(6.28318531e-1f)); |
| 329 | } |
| 330 | |
| 331 | Float4 arctan(RValue<Float4> x, bool pp) |
| 332 | { |
| 333 | Int4 O = CmpNLT(Abs(x), Float4(1.0f)); |
Tom Anderson | 69bc6e8 | 2017-03-20 11:54:29 -0700 | [diff] [blame] | 334 | Float4 y = As<Float4>((O & As<Int4>(Float4(1.0f) / x)) | (~O & As<Int4>(x))); // FIXME: Vector select |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 335 | |
| 336 | // Approximation of atan in [-1..1] |
| 337 | Float4 theta = y * (Float4(-0.27f) * Abs(y) + Float4(1.05539816f)); |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 338 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 339 | // +/-pi/2 depending on sign of x |
| 340 | Float4 sgnPi_2 = As<Float4>(As<Int4>(Float4(1.57079632e+0f)) ^ (As<Int4>(x) & Int4(0x80000000))); |
| 341 | |
Tom Anderson | 69bc6e8 | 2017-03-20 11:54:29 -0700 | [diff] [blame] | 342 | theta = As<Float4>((O & As<Int4>(sgnPi_2 - theta)) | (~O & As<Int4>(theta))); // FIXME: Vector select |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 343 | |
| 344 | return theta; |
| 345 | } |
| 346 | |
| 347 | Float4 arctan(RValue<Float4> y, RValue<Float4> x, bool pp) |
| 348 | { |
| 349 | // Rotate to upper semicircle when in lower semicircle |
| 350 | Int4 S = CmpLT(y, Float4(0.0f)); |
| 351 | Float4 theta = As<Float4>(S & As<Int4>(Float4(-3.14159265e+0f))); // -pi |
| 352 | Float4 x0 = As<Float4>((As<Int4>(y) & Int4(0x80000000)) ^ As<Int4>(x)); |
| 353 | Float4 y0 = Abs(y); |
| 354 | |
| 355 | // Rotate to right quadrant when in left quadrant |
| 356 | Int4 Q = CmpLT(x0, Float4(0.0f)); |
| 357 | theta += As<Float4>(Q & As<Int4>(Float4(1.57079632e+0f))); // pi/2 |
Tom Anderson | 69bc6e8 | 2017-03-20 11:54:29 -0700 | [diff] [blame] | 358 | Float4 x1 = As<Float4>((Q & As<Int4>(y0)) | (~Q & As<Int4>(x0))); // FIXME: Vector select |
| 359 | Float4 y1 = As<Float4>((Q & As<Int4>(-x0)) | (~Q & As<Int4>(y0))); // FIXME: Vector select |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 360 | |
| 361 | // Rotate to first octant when in second octant |
| 362 | Int4 O = CmpNLT(y1, x1); |
| 363 | theta += As<Float4>(O & As<Int4>(Float4(7.85398163e-1f))); // pi/4 |
Tom Anderson | 69bc6e8 | 2017-03-20 11:54:29 -0700 | [diff] [blame] | 364 | Float4 x2 = As<Float4>((O & As<Int4>(Float4(7.07106781e-1f) * x1 + Float4(7.07106781e-1f) * y1)) | (~O & As<Int4>(x1))); // sqrt(2)/2 // FIXME: Vector select |
| 365 | Float4 y2 = As<Float4>((O & As<Int4>(Float4(7.07106781e-1f) * y1 - Float4(7.07106781e-1f) * x1)) | (~O & As<Int4>(y1))); // FIXME: Vector select |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 366 | |
| 367 | // Approximation of atan in [0..1] |
| 368 | Float4 y_x = y2 / x2; |
| 369 | theta += y_x * (Float4(-0.27f) * y_x + Float4(1.05539816f)); |
| 370 | |
| 371 | return theta; |
| 372 | } |
| 373 | |
Alexis Hetu | 8b5f3ef | 2015-04-16 11:33:34 -0400 | [diff] [blame] | 374 | Float4 sineh(RValue<Float4> x, bool pp) |
| 375 | { |
| 376 | return (exponential(x, pp) - exponential(-x, pp)) * Float4(0.5f); |
| 377 | } |
| 378 | |
| 379 | Float4 cosineh(RValue<Float4> x, bool pp) |
| 380 | { |
| 381 | return (exponential(x, pp) + exponential(-x, pp)) * Float4(0.5f); |
| 382 | } |
| 383 | |
| 384 | Float4 tangenth(RValue<Float4> x, bool pp) |
| 385 | { |
| 386 | Float4 e_x = exponential(x, pp); |
| 387 | Float4 e_minus_x = exponential(-x, pp); |
| 388 | return (e_x - e_minus_x) / (e_x + e_minus_x); |
| 389 | } |
| 390 | |
| 391 | Float4 arccosh(RValue<Float4> x, bool pp) |
| 392 | { |
| 393 | return logarithm(x + Sqrt(x + Float4(1.0f)) * Sqrt(x - Float4(1.0f)), pp); |
| 394 | } |
| 395 | |
| 396 | Float4 arcsinh(RValue<Float4> x, bool pp) |
| 397 | { |
| 398 | return logarithm(x + Sqrt(x * x + Float4(1.0f)), pp); |
| 399 | } |
| 400 | |
| 401 | Float4 arctanh(RValue<Float4> x, bool pp) |
| 402 | { |
| 403 | return logarithm((Float4(1.0f) + x) / (Float4(1.0f) - x), pp) * Float4(0.5f); |
| 404 | } |
| 405 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 406 | Float4 dot2(const Vector4f &v0, const Vector4f &v1) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 407 | { |
| 408 | return v0.x * v1.x + v0.y * v1.y; |
| 409 | } |
| 410 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 411 | Float4 dot3(const Vector4f &v0, const Vector4f &v1) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 412 | { |
| 413 | return v0.x * v1.x + v0.y * v1.y + v0.z * v1.z; |
| 414 | } |
| 415 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 416 | Float4 dot4(const Vector4f &v0, const Vector4f &v1) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 417 | { |
| 418 | return v0.x * v1.x + v0.y * v1.y + v0.z * v1.z + v0.w * v1.w; |
| 419 | } |
| 420 | |
| 421 | void transpose4x4(Short4 &row0, Short4 &row1, Short4 &row2, Short4 &row3) |
| 422 | { |
| 423 | Int2 tmp0 = UnpackHigh(row0, row1); |
| 424 | Int2 tmp1 = UnpackHigh(row2, row3); |
| 425 | Int2 tmp2 = UnpackLow(row0, row1); |
| 426 | Int2 tmp3 = UnpackLow(row2, row3); |
| 427 | |
Nicolas Capens | 45f187a | 2016-12-02 15:30:56 -0500 | [diff] [blame] | 428 | row0 = UnpackLow(tmp2, tmp3); |
| 429 | row1 = UnpackHigh(tmp2, tmp3); |
| 430 | row2 = UnpackLow(tmp0, tmp1); |
| 431 | row3 = UnpackHigh(tmp0, tmp1); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 432 | } |
| 433 | |
| 434 | void transpose4x4(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3) |
| 435 | { |
| 436 | Float4 tmp0 = UnpackLow(row0, row1); |
| 437 | Float4 tmp1 = UnpackLow(row2, row3); |
| 438 | Float4 tmp2 = UnpackHigh(row0, row1); |
| 439 | Float4 tmp3 = UnpackHigh(row2, row3); |
| 440 | |
| 441 | row0 = Float4(tmp0.xy, tmp1.xy); |
| 442 | row1 = Float4(tmp0.zw, tmp1.zw); |
| 443 | row2 = Float4(tmp2.xy, tmp3.xy); |
| 444 | row3 = Float4(tmp2.zw, tmp3.zw); |
| 445 | } |
| 446 | |
| 447 | void transpose4x3(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3) |
| 448 | { |
| 449 | Float4 tmp0 = UnpackLow(row0, row1); |
| 450 | Float4 tmp1 = UnpackLow(row2, row3); |
| 451 | Float4 tmp2 = UnpackHigh(row0, row1); |
| 452 | Float4 tmp3 = UnpackHigh(row2, row3); |
| 453 | |
| 454 | row0 = Float4(tmp0.xy, tmp1.xy); |
| 455 | row1 = Float4(tmp0.zw, tmp1.zw); |
| 456 | row2 = Float4(tmp2.xy, tmp3.xy); |
| 457 | } |
| 458 | |
| 459 | void transpose4x2(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3) |
| 460 | { |
| 461 | Float4 tmp0 = UnpackLow(row0, row1); |
| 462 | Float4 tmp1 = UnpackLow(row2, row3); |
| 463 | |
| 464 | row0 = Float4(tmp0.xy, tmp1.xy); |
| 465 | row1 = Float4(tmp0.zw, tmp1.zw); |
| 466 | } |
| 467 | |
| 468 | void transpose4x1(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3) |
| 469 | { |
| 470 | Float4 tmp0 = UnpackLow(row0, row1); |
| 471 | Float4 tmp1 = UnpackLow(row2, row3); |
| 472 | |
| 473 | row0 = Float4(tmp0.xy, tmp1.xy); |
| 474 | } |
| 475 | |
| 476 | void transpose2x4(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3) |
| 477 | { |
Nicolas Capens | 54ac5e8 | 2016-12-09 14:07:50 -0500 | [diff] [blame] | 478 | Float4 tmp01 = UnpackLow(row0, row1); |
| 479 | Float4 tmp23 = UnpackHigh(row0, row1); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 480 | |
Nicolas Capens | 54ac5e8 | 2016-12-09 14:07:50 -0500 | [diff] [blame] | 481 | row0 = tmp01; |
| 482 | row1 = Float4(tmp01.zw, row1.zw); |
| 483 | row2 = tmp23; |
| 484 | row3 = Float4(tmp23.zw, row3.zw); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 485 | } |
| 486 | |
| 487 | void transpose4xN(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3, int N) |
| 488 | { |
| 489 | switch(N) |
| 490 | { |
| 491 | case 1: transpose4x1(row0, row1, row2, row3); break; |
| 492 | case 2: transpose4x2(row0, row1, row2, row3); break; |
| 493 | case 3: transpose4x3(row0, row1, row2, row3); break; |
| 494 | case 4: transpose4x4(row0, row1, row2, row3); break; |
| 495 | } |
| 496 | } |
| 497 | |
Alexis Hetu | 02a2bb8 | 2015-08-20 14:10:33 -0400 | [diff] [blame] | 498 | void ShaderCore::mov(Vector4f &dst, const Vector4f &src, bool integerDestination) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 499 | { |
Alexis Hetu | 02a2bb8 | 2015-08-20 14:10:33 -0400 | [diff] [blame] | 500 | if(integerDestination) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 501 | { |
Alexis Hetu | 02a2bb8 | 2015-08-20 14:10:33 -0400 | [diff] [blame] | 502 | dst.x = As<Float4>(RoundInt(src.x)); |
| 503 | dst.y = As<Float4>(RoundInt(src.y)); |
| 504 | dst.z = As<Float4>(RoundInt(src.z)); |
| 505 | dst.w = As<Float4>(RoundInt(src.w)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 506 | } |
| 507 | else |
| 508 | { |
| 509 | dst = src; |
| 510 | } |
| 511 | } |
| 512 | |
Alexis Hetu | c4f2c29 | 2015-08-18 15:43:09 -0400 | [diff] [blame] | 513 | void ShaderCore::neg(Vector4f &dst, const Vector4f &src) |
| 514 | { |
| 515 | dst.x = -src.x; |
| 516 | dst.y = -src.y; |
| 517 | dst.z = -src.z; |
| 518 | dst.w = -src.w; |
| 519 | } |
| 520 | |
| 521 | void ShaderCore::ineg(Vector4f &dst, const Vector4f &src) |
| 522 | { |
| 523 | dst.x = As<Float4>(-As<Int4>(src.x)); |
| 524 | dst.y = As<Float4>(-As<Int4>(src.y)); |
| 525 | dst.z = As<Float4>(-As<Int4>(src.z)); |
| 526 | dst.w = As<Float4>(-As<Int4>(src.w)); |
| 527 | } |
| 528 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 529 | void ShaderCore::f2b(Vector4f &dst, const Vector4f &src) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 530 | { |
| 531 | dst.x = As<Float4>(CmpNEQ(src.x, Float4(0.0f))); |
| 532 | dst.y = As<Float4>(CmpNEQ(src.y, Float4(0.0f))); |
| 533 | dst.z = As<Float4>(CmpNEQ(src.z, Float4(0.0f))); |
| 534 | dst.w = As<Float4>(CmpNEQ(src.w, Float4(0.0f))); |
| 535 | } |
| 536 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 537 | void ShaderCore::b2f(Vector4f &dst, const Vector4f &src) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 538 | { |
| 539 | dst.x = As<Float4>(As<Int4>(src.x) & As<Int4>(Float4(1.0f))); |
| 540 | dst.y = As<Float4>(As<Int4>(src.y) & As<Int4>(Float4(1.0f))); |
| 541 | dst.z = As<Float4>(As<Int4>(src.z) & As<Int4>(Float4(1.0f))); |
| 542 | dst.w = As<Float4>(As<Int4>(src.w) & As<Int4>(Float4(1.0f))); |
| 543 | } |
| 544 | |
Alexis Hetu | c4f2c29 | 2015-08-18 15:43:09 -0400 | [diff] [blame] | 545 | void ShaderCore::f2i(Vector4f &dst, const Vector4f &src) |
| 546 | { |
| 547 | dst.x = As<Float4>(Int4(src.x)); |
| 548 | dst.y = As<Float4>(Int4(src.y)); |
| 549 | dst.z = As<Float4>(Int4(src.z)); |
| 550 | dst.w = As<Float4>(Int4(src.w)); |
| 551 | } |
| 552 | |
| 553 | void ShaderCore::i2f(Vector4f &dst, const Vector4f &src) |
| 554 | { |
| 555 | dst.x = Float4(As<Int4>(src.x)); |
| 556 | dst.y = Float4(As<Int4>(src.y)); |
| 557 | dst.z = Float4(As<Int4>(src.z)); |
| 558 | dst.w = Float4(As<Int4>(src.w)); |
| 559 | } |
| 560 | |
| 561 | void ShaderCore::f2u(Vector4f &dst, const Vector4f &src) |
| 562 | { |
| 563 | dst.x = As<Float4>(UInt4(src.x)); |
| 564 | dst.y = As<Float4>(UInt4(src.y)); |
| 565 | dst.z = As<Float4>(UInt4(src.z)); |
| 566 | dst.w = As<Float4>(UInt4(src.w)); |
| 567 | } |
| 568 | |
| 569 | void ShaderCore::u2f(Vector4f &dst, const Vector4f &src) |
| 570 | { |
| 571 | dst.x = Float4(As<UInt4>(src.x)); |
| 572 | dst.y = Float4(As<UInt4>(src.y)); |
| 573 | dst.z = Float4(As<UInt4>(src.z)); |
| 574 | dst.w = Float4(As<UInt4>(src.w)); |
| 575 | } |
| 576 | |
| 577 | void ShaderCore::i2b(Vector4f &dst, const Vector4f &src) |
| 578 | { |
| 579 | dst.x = As<Float4>(CmpNEQ(As<Int4>(src.x), Int4(0))); |
| 580 | dst.y = As<Float4>(CmpNEQ(As<Int4>(src.y), Int4(0))); |
| 581 | dst.z = As<Float4>(CmpNEQ(As<Int4>(src.z), Int4(0))); |
| 582 | dst.w = As<Float4>(CmpNEQ(As<Int4>(src.w), Int4(0))); |
| 583 | } |
| 584 | |
| 585 | void ShaderCore::b2i(Vector4f &dst, const Vector4f &src) |
| 586 | { |
| 587 | dst.x = As<Float4>(As<Int4>(src.x) & Int4(1)); |
| 588 | dst.y = As<Float4>(As<Int4>(src.y) & Int4(1)); |
| 589 | dst.z = As<Float4>(As<Int4>(src.z) & Int4(1)); |
| 590 | dst.w = As<Float4>(As<Int4>(src.w) & Int4(1)); |
| 591 | } |
| 592 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 593 | void ShaderCore::add(Vector4f &dst, const Vector4f &src0, const Vector4f &src1) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 594 | { |
| 595 | dst.x = src0.x + src1.x; |
| 596 | dst.y = src0.y + src1.y; |
| 597 | dst.z = src0.z + src1.z; |
| 598 | dst.w = src0.w + src1.w; |
| 599 | } |
| 600 | |
Alexis Hetu | c4f2c29 | 2015-08-18 15:43:09 -0400 | [diff] [blame] | 601 | void ShaderCore::iadd(Vector4f &dst, const Vector4f &src0, const Vector4f &src1) |
| 602 | { |
| 603 | dst.x = As<Float4>(As<Int4>(src0.x) + As<Int4>(src1.x)); |
| 604 | dst.y = As<Float4>(As<Int4>(src0.y) + As<Int4>(src1.y)); |
| 605 | dst.z = As<Float4>(As<Int4>(src0.z) + As<Int4>(src1.z)); |
| 606 | dst.w = As<Float4>(As<Int4>(src0.w) + As<Int4>(src1.w)); |
| 607 | } |
| 608 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 609 | void ShaderCore::sub(Vector4f &dst, const Vector4f &src0, const Vector4f &src1) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 610 | { |
| 611 | dst.x = src0.x - src1.x; |
| 612 | dst.y = src0.y - src1.y; |
| 613 | dst.z = src0.z - src1.z; |
| 614 | dst.w = src0.w - src1.w; |
| 615 | } |
| 616 | |
Alexis Hetu | c4f2c29 | 2015-08-18 15:43:09 -0400 | [diff] [blame] | 617 | void ShaderCore::isub(Vector4f &dst, const Vector4f &src0, const Vector4f &src1) |
| 618 | { |
| 619 | dst.x = As<Float4>(As<Int4>(src0.x) - As<Int4>(src1.x)); |
| 620 | dst.y = As<Float4>(As<Int4>(src0.y) - As<Int4>(src1.y)); |
| 621 | dst.z = As<Float4>(As<Int4>(src0.z) - As<Int4>(src1.z)); |
| 622 | dst.w = As<Float4>(As<Int4>(src0.w) - As<Int4>(src1.w)); |
| 623 | } |
| 624 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 625 | void ShaderCore::mad(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 626 | { |
| 627 | dst.x = src0.x * src1.x + src2.x; |
| 628 | dst.y = src0.y * src1.y + src2.y; |
| 629 | dst.z = src0.z * src1.z + src2.z; |
| 630 | dst.w = src0.w * src1.w + src2.w; |
| 631 | } |
| 632 | |
Alexis Hetu | c4f2c29 | 2015-08-18 15:43:09 -0400 | [diff] [blame] | 633 | void ShaderCore::imad(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2) |
| 634 | { |
| 635 | dst.x = As<Float4>(As<Int4>(src0.x) * As<Int4>(src1.x) + As<Int4>(src2.x)); |
| 636 | dst.y = As<Float4>(As<Int4>(src0.y) * As<Int4>(src1.y) + As<Int4>(src2.y)); |
| 637 | dst.z = As<Float4>(As<Int4>(src0.z) * As<Int4>(src1.z) + As<Int4>(src2.z)); |
| 638 | dst.w = As<Float4>(As<Int4>(src0.w) * As<Int4>(src1.w) + As<Int4>(src2.w)); |
| 639 | } |
| 640 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 641 | void ShaderCore::mul(Vector4f &dst, const Vector4f &src0, const Vector4f &src1) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 642 | { |
| 643 | dst.x = src0.x * src1.x; |
| 644 | dst.y = src0.y * src1.y; |
| 645 | dst.z = src0.z * src1.z; |
| 646 | dst.w = src0.w * src1.w; |
| 647 | } |
| 648 | |
Alexis Hetu | c4f2c29 | 2015-08-18 15:43:09 -0400 | [diff] [blame] | 649 | void ShaderCore::imul(Vector4f &dst, const Vector4f &src0, const Vector4f &src1) |
| 650 | { |
| 651 | dst.x = As<Float4>(As<Int4>(src0.x) * As<Int4>(src1.x)); |
| 652 | dst.y = As<Float4>(As<Int4>(src0.y) * As<Int4>(src1.y)); |
| 653 | dst.z = As<Float4>(As<Int4>(src0.z) * As<Int4>(src1.z)); |
| 654 | dst.w = As<Float4>(As<Int4>(src0.w) * As<Int4>(src1.w)); |
| 655 | } |
| 656 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 657 | void ShaderCore::rcpx(Vector4f &dst, const Vector4f &src, bool pp) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 658 | { |
| 659 | Float4 rcp = reciprocal(src.x, pp, true); |
| 660 | |
| 661 | dst.x = rcp; |
| 662 | dst.y = rcp; |
| 663 | dst.z = rcp; |
| 664 | dst.w = rcp; |
| 665 | } |
| 666 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 667 | void ShaderCore::div(Vector4f &dst, const Vector4f &src0, const Vector4f &src1) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 668 | { |
| 669 | dst.x = src0.x / src1.x; |
| 670 | dst.y = src0.y / src1.y; |
| 671 | dst.z = src0.z / src1.z; |
| 672 | dst.w = src0.w / src1.w; |
| 673 | } |
| 674 | |
Alexis Hetu | c4f2c29 | 2015-08-18 15:43:09 -0400 | [diff] [blame] | 675 | void ShaderCore::idiv(Vector4f &dst, const Vector4f &src0, const Vector4f &src1) |
| 676 | { |
| 677 | Float4 intMax(As<Float4>(Int4(INT_MAX))); |
| 678 | cmp0i(dst.x, src1.x, intMax, src1.x); |
| 679 | dst.x = As<Float4>(As<Int4>(src0.x) / As<Int4>(dst.x)); |
| 680 | cmp0i(dst.y, src1.y, intMax, src1.y); |
| 681 | dst.y = As<Float4>(As<Int4>(src0.y) / As<Int4>(dst.y)); |
| 682 | cmp0i(dst.z, src1.z, intMax, src1.z); |
| 683 | dst.z = As<Float4>(As<Int4>(src0.z) / As<Int4>(dst.z)); |
| 684 | cmp0i(dst.w, src1.w, intMax, src1.w); |
| 685 | dst.w = As<Float4>(As<Int4>(src0.w) / As<Int4>(dst.w)); |
| 686 | } |
| 687 | |
| 688 | void ShaderCore::udiv(Vector4f &dst, const Vector4f &src0, const Vector4f &src1) |
| 689 | { |
| 690 | Float4 uintMax(As<Float4>(UInt4(UINT_MAX))); |
| 691 | cmp0i(dst.x, src1.x, uintMax, src1.x); |
| 692 | dst.x = As<Float4>(As<UInt4>(src0.x) / As<UInt4>(dst.x)); |
| 693 | cmp0i(dst.y, src1.y, uintMax, src1.y); |
| 694 | dst.y = As<Float4>(As<UInt4>(src0.y) / As<UInt4>(dst.y)); |
| 695 | cmp0i(dst.z, src1.z, uintMax, src1.z); |
| 696 | dst.z = As<Float4>(As<UInt4>(src0.z) / As<UInt4>(dst.z)); |
| 697 | cmp0i(dst.w, src1.w, uintMax, src1.w); |
| 698 | dst.w = As<Float4>(As<UInt4>(src0.w) / As<UInt4>(dst.w)); |
| 699 | } |
| 700 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 701 | void ShaderCore::mod(Vector4f &dst, const Vector4f &src0, const Vector4f &src1) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 702 | { |
| 703 | dst.x = modulo(src0.x, src1.x); |
| 704 | dst.y = modulo(src0.y, src1.y); |
| 705 | dst.z = modulo(src0.z, src1.z); |
| 706 | dst.w = modulo(src0.w, src1.w); |
| 707 | } |
| 708 | |
Alexis Hetu | c4f2c29 | 2015-08-18 15:43:09 -0400 | [diff] [blame] | 709 | void ShaderCore::imod(Vector4f &dst, const Vector4f &src0, const Vector4f &src1) |
| 710 | { |
Alexis Hetu | 2895810 | 2017-10-02 13:48:19 -0400 | [diff] [blame] | 711 | Float4 intMax(As<Float4>(Int4(INT_MAX))); |
| 712 | cmp0i(dst.x, src1.x, intMax, src1.x); |
Alexis Hetu | c4f2c29 | 2015-08-18 15:43:09 -0400 | [diff] [blame] | 713 | dst.x = As<Float4>(As<Int4>(src0.x) % As<Int4>(dst.x)); |
Alexis Hetu | 2895810 | 2017-10-02 13:48:19 -0400 | [diff] [blame] | 714 | cmp0i(dst.y, src1.y, intMax, src1.y); |
Alexis Hetu | c4f2c29 | 2015-08-18 15:43:09 -0400 | [diff] [blame] | 715 | dst.y = As<Float4>(As<Int4>(src0.y) % As<Int4>(dst.y)); |
Alexis Hetu | 2895810 | 2017-10-02 13:48:19 -0400 | [diff] [blame] | 716 | cmp0i(dst.z, src1.z, intMax, src1.z); |
Alexis Hetu | c4f2c29 | 2015-08-18 15:43:09 -0400 | [diff] [blame] | 717 | dst.z = As<Float4>(As<Int4>(src0.z) % As<Int4>(dst.z)); |
Alexis Hetu | 2895810 | 2017-10-02 13:48:19 -0400 | [diff] [blame] | 718 | cmp0i(dst.w, src1.w, intMax, src1.w); |
Alexis Hetu | c4f2c29 | 2015-08-18 15:43:09 -0400 | [diff] [blame] | 719 | dst.w = As<Float4>(As<Int4>(src0.w) % As<Int4>(dst.w)); |
| 720 | } |
Alexis Hetu | 2895810 | 2017-10-02 13:48:19 -0400 | [diff] [blame] | 721 | |
Alexis Hetu | c4f2c29 | 2015-08-18 15:43:09 -0400 | [diff] [blame] | 722 | void ShaderCore::umod(Vector4f &dst, const Vector4f &src0, const Vector4f &src1) |
| 723 | { |
Alexis Hetu | 2895810 | 2017-10-02 13:48:19 -0400 | [diff] [blame] | 724 | Float4 uintMax(As<Float4>(UInt4(UINT_MAX))); |
| 725 | cmp0i(dst.x, src1.x, uintMax, src1.x); |
Alexis Hetu | c4f2c29 | 2015-08-18 15:43:09 -0400 | [diff] [blame] | 726 | dst.x = As<Float4>(As<UInt4>(src0.x) % As<UInt4>(dst.x)); |
Alexis Hetu | 2895810 | 2017-10-02 13:48:19 -0400 | [diff] [blame] | 727 | cmp0i(dst.y, src1.y, uintMax, src1.y); |
Alexis Hetu | c4f2c29 | 2015-08-18 15:43:09 -0400 | [diff] [blame] | 728 | dst.y = As<Float4>(As<UInt4>(src0.y) % As<UInt4>(dst.y)); |
Alexis Hetu | 2895810 | 2017-10-02 13:48:19 -0400 | [diff] [blame] | 729 | cmp0i(dst.z, src1.z, uintMax, src1.z); |
Alexis Hetu | c4f2c29 | 2015-08-18 15:43:09 -0400 | [diff] [blame] | 730 | dst.z = As<Float4>(As<UInt4>(src0.z) % As<UInt4>(dst.z)); |
Alexis Hetu | 2895810 | 2017-10-02 13:48:19 -0400 | [diff] [blame] | 731 | cmp0i(dst.w, src1.w, uintMax, src1.w); |
Alexis Hetu | c4f2c29 | 2015-08-18 15:43:09 -0400 | [diff] [blame] | 732 | dst.w = As<Float4>(As<UInt4>(src0.w) % As<UInt4>(dst.w)); |
| 733 | } |
| 734 | |
| 735 | void ShaderCore::shl(Vector4f &dst, const Vector4f &src0, const Vector4f &src1) |
| 736 | { |
| 737 | dst.x = As<Float4>(As<Int4>(src0.x) << As<Int4>(src1.x)); |
| 738 | dst.y = As<Float4>(As<Int4>(src0.y) << As<Int4>(src1.y)); |
| 739 | dst.z = As<Float4>(As<Int4>(src0.z) << As<Int4>(src1.z)); |
| 740 | dst.w = As<Float4>(As<Int4>(src0.w) << As<Int4>(src1.w)); |
| 741 | } |
| 742 | |
| 743 | void ShaderCore::ishr(Vector4f &dst, const Vector4f &src0, const Vector4f &src1) |
| 744 | { |
| 745 | dst.x = As<Float4>(As<Int4>(src0.x) >> As<Int4>(src1.x)); |
| 746 | dst.y = As<Float4>(As<Int4>(src0.y) >> As<Int4>(src1.y)); |
| 747 | dst.z = As<Float4>(As<Int4>(src0.z) >> As<Int4>(src1.z)); |
| 748 | dst.w = As<Float4>(As<Int4>(src0.w) >> As<Int4>(src1.w)); |
| 749 | } |
| 750 | |
| 751 | void ShaderCore::ushr(Vector4f &dst, const Vector4f &src0, const Vector4f &src1) |
| 752 | { |
| 753 | dst.x = As<Float4>(As<UInt4>(src0.x) >> As<UInt4>(src1.x)); |
| 754 | dst.y = As<Float4>(As<UInt4>(src0.y) >> As<UInt4>(src1.y)); |
| 755 | dst.z = As<Float4>(As<UInt4>(src0.z) >> As<UInt4>(src1.z)); |
| 756 | dst.w = As<Float4>(As<UInt4>(src0.w) >> As<UInt4>(src1.w)); |
| 757 | } |
| 758 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 759 | void ShaderCore::rsqx(Vector4f &dst, const Vector4f &src, bool pp) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 760 | { |
| 761 | Float4 rsq = reciprocalSquareRoot(src.x, true, pp); |
| 762 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 763 | dst.x = rsq; |
| 764 | dst.y = rsq; |
| 765 | dst.z = rsq; |
| 766 | dst.w = rsq; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 767 | } |
| 768 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 769 | void ShaderCore::sqrt(Vector4f &dst, const Vector4f &src, bool pp) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 770 | { |
| 771 | dst.x = Sqrt(src.x); |
| 772 | dst.y = Sqrt(src.y); |
| 773 | dst.z = Sqrt(src.z); |
| 774 | dst.w = Sqrt(src.w); |
| 775 | } |
| 776 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 777 | void ShaderCore::rsq(Vector4f &dst, const Vector4f &src, bool pp) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 778 | { |
| 779 | dst.x = reciprocalSquareRoot(src.x, false, pp); |
| 780 | dst.y = reciprocalSquareRoot(src.y, false, pp); |
| 781 | dst.z = reciprocalSquareRoot(src.z, false, pp); |
| 782 | dst.w = reciprocalSquareRoot(src.w, false, pp); |
| 783 | } |
| 784 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 785 | void ShaderCore::len2(Float4 &dst, const Vector4f &src, bool pp) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 786 | { |
| 787 | dst = Sqrt(dot2(src, src)); |
| 788 | } |
| 789 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 790 | void ShaderCore::len3(Float4 &dst, const Vector4f &src, bool pp) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 791 | { |
| 792 | dst = Sqrt(dot3(src, src)); |
| 793 | } |
| 794 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 795 | void ShaderCore::len4(Float4 &dst, const Vector4f &src, bool pp) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 796 | { |
| 797 | dst = Sqrt(dot4(src, src)); |
| 798 | } |
| 799 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 800 | void ShaderCore::dist1(Float4 &dst, const Vector4f &src0, const Vector4f &src1, bool pp) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 801 | { |
| 802 | dst = Abs(src0.x - src1.x); |
| 803 | } |
| 804 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 805 | void ShaderCore::dist2(Float4 &dst, const Vector4f &src0, const Vector4f &src1, bool pp) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 806 | { |
| 807 | Float4 dx = src0.x - src1.x; |
| 808 | Float4 dy = src0.y - src1.y; |
| 809 | Float4 dot2 = dx * dx + dy * dy; |
| 810 | dst = Sqrt(dot2); |
| 811 | } |
| 812 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 813 | void ShaderCore::dist3(Float4 &dst, const Vector4f &src0, const Vector4f &src1, bool pp) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 814 | { |
| 815 | Float4 dx = src0.x - src1.x; |
| 816 | Float4 dy = src0.y - src1.y; |
| 817 | Float4 dz = src0.z - src1.z; |
| 818 | Float4 dot3 = dx * dx + dy * dy + dz * dz; |
| 819 | dst = Sqrt(dot3); |
| 820 | } |
| 821 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 822 | void ShaderCore::dist4(Float4 &dst, const Vector4f &src0, const Vector4f &src1, bool pp) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 823 | { |
| 824 | Float4 dx = src0.x - src1.x; |
| 825 | Float4 dy = src0.y - src1.y; |
| 826 | Float4 dz = src0.z - src1.z; |
| 827 | Float4 dw = src0.w - src1.w; |
| 828 | Float4 dot4 = dx * dx + dy * dy + dz * dz + dw * dw; |
| 829 | dst = Sqrt(dot4); |
| 830 | } |
| 831 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 832 | void ShaderCore::dp1(Vector4f &dst, const Vector4f &src0, const Vector4f &src1) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 833 | { |
| 834 | Float4 t = src0.x * src1.x; |
| 835 | |
| 836 | dst.x = t; |
| 837 | dst.y = t; |
| 838 | dst.z = t; |
| 839 | dst.w = t; |
| 840 | } |
| 841 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 842 | void ShaderCore::dp2(Vector4f &dst, const Vector4f &src0, const Vector4f &src1) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 843 | { |
| 844 | Float4 t = dot2(src0, src1); |
| 845 | |
| 846 | dst.x = t; |
| 847 | dst.y = t; |
| 848 | dst.z = t; |
| 849 | dst.w = t; |
| 850 | } |
| 851 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 852 | void ShaderCore::dp2add(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 853 | { |
| 854 | Float4 t = dot2(src0, src1) + src2.x; |
| 855 | |
| 856 | dst.x = t; |
| 857 | dst.y = t; |
| 858 | dst.z = t; |
| 859 | dst.w = t; |
| 860 | } |
| 861 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 862 | void ShaderCore::dp3(Vector4f &dst, const Vector4f &src0, const Vector4f &src1) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 863 | { |
| 864 | Float4 dot = dot3(src0, src1); |
| 865 | |
| 866 | dst.x = dot; |
| 867 | dst.y = dot; |
| 868 | dst.z = dot; |
| 869 | dst.w = dot; |
| 870 | } |
| 871 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 872 | void ShaderCore::dp4(Vector4f &dst, const Vector4f &src0, const Vector4f &src1) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 873 | { |
| 874 | Float4 dot = dot4(src0, src1); |
| 875 | |
| 876 | dst.x = dot; |
| 877 | dst.y = dot; |
| 878 | dst.z = dot; |
| 879 | dst.w = dot; |
| 880 | } |
| 881 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 882 | void ShaderCore::min(Vector4f &dst, const Vector4f &src0, const Vector4f &src1) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 883 | { |
| 884 | dst.x = Min(src0.x, src1.x); |
| 885 | dst.y = Min(src0.y, src1.y); |
| 886 | dst.z = Min(src0.z, src1.z); |
| 887 | dst.w = Min(src0.w, src1.w); |
| 888 | } |
| 889 | |
Alexis Hetu | c4f2c29 | 2015-08-18 15:43:09 -0400 | [diff] [blame] | 890 | void ShaderCore::imin(Vector4f &dst, const Vector4f &src0, const Vector4f &src1) |
| 891 | { |
| 892 | dst.x = As<Float4>(Min(As<Int4>(src0.x), As<Int4>(src1.x))); |
| 893 | dst.y = As<Float4>(Min(As<Int4>(src0.y), As<Int4>(src1.y))); |
| 894 | dst.z = As<Float4>(Min(As<Int4>(src0.z), As<Int4>(src1.z))); |
| 895 | dst.w = As<Float4>(Min(As<Int4>(src0.w), As<Int4>(src1.w))); |
| 896 | } |
| 897 | |
| 898 | void ShaderCore::umin(Vector4f &dst, const Vector4f &src0, const Vector4f &src1) |
| 899 | { |
| 900 | dst.x = As<Float4>(Min(As<UInt4>(src0.x), As<UInt4>(src1.x))); |
| 901 | dst.y = As<Float4>(Min(As<UInt4>(src0.y), As<UInt4>(src1.y))); |
| 902 | dst.z = As<Float4>(Min(As<UInt4>(src0.z), As<UInt4>(src1.z))); |
| 903 | dst.w = As<Float4>(Min(As<UInt4>(src0.w), As<UInt4>(src1.w))); |
| 904 | } |
| 905 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 906 | void ShaderCore::max(Vector4f &dst, const Vector4f &src0, const Vector4f &src1) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 907 | { |
| 908 | dst.x = Max(src0.x, src1.x); |
| 909 | dst.y = Max(src0.y, src1.y); |
| 910 | dst.z = Max(src0.z, src1.z); |
| 911 | dst.w = Max(src0.w, src1.w); |
| 912 | } |
| 913 | |
Alexis Hetu | c4f2c29 | 2015-08-18 15:43:09 -0400 | [diff] [blame] | 914 | void ShaderCore::imax(Vector4f &dst, const Vector4f &src0, const Vector4f &src1) |
| 915 | { |
| 916 | dst.x = As<Float4>(Max(As<Int4>(src0.x), As<Int4>(src1.x))); |
| 917 | dst.y = As<Float4>(Max(As<Int4>(src0.y), As<Int4>(src1.y))); |
| 918 | dst.z = As<Float4>(Max(As<Int4>(src0.z), As<Int4>(src1.z))); |
| 919 | dst.w = As<Float4>(Max(As<Int4>(src0.w), As<Int4>(src1.w))); |
| 920 | } |
| 921 | |
| 922 | void ShaderCore::umax(Vector4f &dst, const Vector4f &src0, const Vector4f &src1) |
| 923 | { |
| 924 | dst.x = As<Float4>(Max(As<Int4>(src0.x), As<Int4>(src1.x))); |
| 925 | dst.y = As<Float4>(Max(As<Int4>(src0.y), As<Int4>(src1.y))); |
| 926 | dst.z = As<Float4>(Max(As<Int4>(src0.z), As<Int4>(src1.z))); |
| 927 | dst.w = As<Float4>(Max(As<Int4>(src0.w), As<Int4>(src1.w))); |
| 928 | } |
| 929 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 930 | void ShaderCore::slt(Vector4f &dst, const Vector4f &src0, const Vector4f &src1) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 931 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 932 | dst.x = As<Float4>(As<Int4>(CmpLT(src0.x, src1.x)) & As<Int4>(Float4(1.0f))); |
| 933 | dst.y = As<Float4>(As<Int4>(CmpLT(src0.y, src1.y)) & As<Int4>(Float4(1.0f))); |
| 934 | dst.z = As<Float4>(As<Int4>(CmpLT(src0.z, src1.z)) & As<Int4>(Float4(1.0f))); |
| 935 | dst.w = As<Float4>(As<Int4>(CmpLT(src0.w, src1.w)) & As<Int4>(Float4(1.0f))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 936 | } |
| 937 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 938 | void ShaderCore::step(Vector4f &dst, const Vector4f &edge, const Vector4f &x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 939 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 940 | dst.x = As<Float4>(CmpNLT(x.x, edge.x) & As<Int4>(Float4(1.0f))); |
| 941 | dst.y = As<Float4>(CmpNLT(x.y, edge.y) & As<Int4>(Float4(1.0f))); |
| 942 | dst.z = As<Float4>(CmpNLT(x.z, edge.z) & As<Int4>(Float4(1.0f))); |
| 943 | dst.w = As<Float4>(CmpNLT(x.w, edge.w) & As<Int4>(Float4(1.0f))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 944 | } |
| 945 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 946 | void ShaderCore::exp2x(Vector4f &dst, const Vector4f &src, bool pp) |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 947 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 948 | Float4 exp = exponential2(src.x, pp); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 949 | |
| 950 | dst.x = exp; |
| 951 | dst.y = exp; |
| 952 | dst.z = exp; |
| 953 | dst.w = exp; |
| 954 | } |
| 955 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 956 | void ShaderCore::exp2(Vector4f &dst, const Vector4f &src, bool pp) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 957 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 958 | dst.x = exponential2(src.x, pp); |
| 959 | dst.y = exponential2(src.y, pp); |
| 960 | dst.z = exponential2(src.z, pp); |
| 961 | dst.w = exponential2(src.w, pp); |
| 962 | } |
| 963 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 964 | void ShaderCore::exp(Vector4f &dst, const Vector4f &src, bool pp) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 965 | { |
| 966 | dst.x = exponential(src.x, pp); |
| 967 | dst.y = exponential(src.y, pp); |
| 968 | dst.z = exponential(src.z, pp); |
| 969 | dst.w = exponential(src.w, pp); |
| 970 | } |
| 971 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 972 | void ShaderCore::log2x(Vector4f &dst, const Vector4f &src, bool pp) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 973 | { |
| 974 | Float4 log = logarithm2(src.x, true, pp); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 975 | |
| 976 | dst.x = log; |
| 977 | dst.y = log; |
| 978 | dst.z = log; |
| 979 | dst.w = log; |
| 980 | } |
| 981 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 982 | void ShaderCore::log2(Vector4f &dst, const Vector4f &src, bool pp) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 983 | { |
Alexis Hetu | a781af7 | 2017-07-06 17:12:47 -0400 | [diff] [blame] | 984 | dst.x = logarithm2(src.x, false, pp); |
| 985 | dst.y = logarithm2(src.y, false, pp); |
| 986 | dst.z = logarithm2(src.z, false, pp); |
| 987 | dst.w = logarithm2(src.w, false, pp); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 988 | } |
| 989 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 990 | void ShaderCore::log(Vector4f &dst, const Vector4f &src, bool pp) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 991 | { |
| 992 | dst.x = logarithm(src.x, false, pp); |
| 993 | dst.y = logarithm(src.y, false, pp); |
| 994 | dst.z = logarithm(src.z, false, pp); |
| 995 | dst.w = logarithm(src.w, false, pp); |
| 996 | } |
| 997 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 998 | void ShaderCore::lit(Vector4f &dst, const Vector4f &src) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 999 | { |
| 1000 | dst.x = Float4(1.0f); |
| 1001 | dst.y = Max(src.x, Float4(0.0f)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1002 | |
| 1003 | Float4 pow; |
| 1004 | |
| 1005 | pow = src.w; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1006 | pow = Min(pow, Float4(127.9961f)); |
| 1007 | pow = Max(pow, Float4(-127.9961f)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1008 | |
| 1009 | dst.z = power(src.y, pow); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1010 | dst.z = As<Float4>(As<Int4>(dst.z) & CmpNLT(src.x, Float4(0.0f))); |
| 1011 | dst.z = As<Float4>(As<Int4>(dst.z) & CmpNLT(src.y, Float4(0.0f))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1012 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1013 | dst.w = Float4(1.0f); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1014 | } |
| 1015 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 1016 | void ShaderCore::att(Vector4f &dst, const Vector4f &src0, const Vector4f &src1) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1017 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1018 | // Computes attenuation factors (1, d, d^2, 1/d) assuming src0 = d^2, src1 = 1/d |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1019 | dst.x = 1; |
| 1020 | dst.y = src0.y * src1.y; |
| 1021 | dst.z = src0.z; |
| 1022 | dst.w = src1.w; |
| 1023 | } |
| 1024 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 1025 | void ShaderCore::lrp(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1026 | { |
| 1027 | dst.x = src0.x * (src1.x - src2.x) + src2.x; |
| 1028 | dst.y = src0.y * (src1.y - src2.y) + src2.y; |
| 1029 | dst.z = src0.z * (src1.z - src2.z) + src2.z; |
| 1030 | dst.w = src0.w * (src1.w - src2.w) + src2.w; |
| 1031 | } |
| 1032 | |
Alexis Hetu | 8ef6d10 | 2017-11-09 15:49:09 -0500 | [diff] [blame] | 1033 | void ShaderCore::isinf(Vector4f &dst, const Vector4f &src) |
| 1034 | { |
| 1035 | dst.x = As<Float4>(IsInf(src.x)); |
| 1036 | dst.y = As<Float4>(IsInf(src.y)); |
| 1037 | dst.z = As<Float4>(IsInf(src.z)); |
| 1038 | dst.w = As<Float4>(IsInf(src.w)); |
| 1039 | } |
| 1040 | |
| 1041 | void ShaderCore::isnan(Vector4f &dst, const Vector4f &src) |
| 1042 | { |
| 1043 | dst.x = As<Float4>(IsNan(src.x)); |
| 1044 | dst.y = As<Float4>(IsNan(src.y)); |
| 1045 | dst.z = As<Float4>(IsNan(src.z)); |
| 1046 | dst.w = As<Float4>(IsNan(src.w)); |
| 1047 | } |
| 1048 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 1049 | void ShaderCore::smooth(Vector4f &dst, const Vector4f &edge0, const Vector4f &edge1, const Vector4f &x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1050 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1051 | Float4 tx = Min(Max((x.x - edge0.x) / (edge1.x - edge0.x), Float4(0.0f)), Float4(1.0f)); dst.x = tx * tx * (Float4(3.0f) - Float4(2.0f) * tx); |
| 1052 | Float4 ty = Min(Max((x.y - edge0.y) / (edge1.y - edge0.y), Float4(0.0f)), Float4(1.0f)); dst.y = ty * ty * (Float4(3.0f) - Float4(2.0f) * ty); |
| 1053 | Float4 tz = Min(Max((x.z - edge0.z) / (edge1.z - edge0.z), Float4(0.0f)), Float4(1.0f)); dst.z = tz * tz * (Float4(3.0f) - Float4(2.0f) * tz); |
| 1054 | Float4 tw = Min(Max((x.w - edge0.w) / (edge1.w - edge0.w), Float4(0.0f)), Float4(1.0f)); dst.w = tw * tw * (Float4(3.0f) - Float4(2.0f) * tw); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1055 | } |
| 1056 | |
Alexis Hetu | ffb35eb | 2016-04-06 18:05:00 -0400 | [diff] [blame] | 1057 | void ShaderCore::floatToHalfBits(Float4& dst, const Float4& floatBits, bool storeInUpperBits) |
| 1058 | { |
| 1059 | static const uint32_t mask_sign = 0x80000000u; |
| 1060 | static const uint32_t mask_round = ~0xfffu; |
| 1061 | static const uint32_t c_f32infty = 255 << 23; |
| 1062 | static const uint32_t c_magic = 15 << 23; |
| 1063 | static const uint32_t c_nanbit = 0x200; |
| 1064 | static const uint32_t c_infty_as_fp16 = 0x7c00; |
| 1065 | static const uint32_t c_clamp = (31 << 23) - 0x1000; |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 1066 | |
Alexis Hetu | ffb35eb | 2016-04-06 18:05:00 -0400 | [diff] [blame] | 1067 | UInt4 justsign = UInt4(mask_sign) & As<UInt4>(floatBits); |
| 1068 | UInt4 absf = As<UInt4>(floatBits) ^ justsign; |
| 1069 | UInt4 b_isnormal = CmpNLE(UInt4(c_f32infty), absf); |
| 1070 | |
| 1071 | // Note: this version doesn't round to the nearest even in case of a tie as defined by IEEE 754-2008, it rounds to +inf |
| 1072 | // instead of nearest even, since that's fine for GLSL ES 3.0's needs (see section 2.1.1 Floating-Point Computation) |
| 1073 | UInt4 joined = ((((As<UInt4>(Min(As<Float4>(absf & UInt4(mask_round)) * As<Float4>(UInt4(c_magic)), |
| 1074 | As<Float4>(UInt4(c_clamp))))) - UInt4(mask_round)) >> 13) & b_isnormal) | |
| 1075 | ((b_isnormal ^ UInt4(0xFFFFFFFF)) & ((CmpNLE(absf, UInt4(c_f32infty)) & UInt4(c_nanbit)) | |
| 1076 | UInt4(c_infty_as_fp16))); |
| 1077 | |
| 1078 | dst = As<Float4>(storeInUpperBits ? As<UInt4>(dst) | ((joined << 16) | justsign) : joined | (justsign >> 16)); |
| 1079 | } |
| 1080 | |
| 1081 | void ShaderCore::halfToFloatBits(Float4& dst, const Float4& halfBits) |
| 1082 | { |
| 1083 | static const uint32_t mask_nosign = 0x7FFF; |
| 1084 | static const uint32_t magic = (254 - 15) << 23; |
| 1085 | static const uint32_t was_infnan = 0x7BFF; |
| 1086 | static const uint32_t exp_infnan = 255 << 23; |
| 1087 | |
| 1088 | UInt4 expmant = As<UInt4>(halfBits) & UInt4(mask_nosign); |
| 1089 | dst = As<Float4>(As<UInt4>(As<Float4>(expmant << 13) * As<Float4>(UInt4(magic))) | |
| 1090 | ((As<UInt4>(halfBits) ^ UInt4(expmant)) << 16) | |
| 1091 | (CmpNLE(As<UInt4>(expmant), UInt4(was_infnan)) & UInt4(exp_infnan))); |
| 1092 | } |
| 1093 | |
| 1094 | void ShaderCore::packHalf2x16(Vector4f &d, const Vector4f &s0) |
| 1095 | { |
| 1096 | // half2 | half1 |
| 1097 | floatToHalfBits(d.x, s0.x, false); |
| 1098 | floatToHalfBits(d.x, s0.y, true); |
| 1099 | } |
| 1100 | |
| 1101 | void ShaderCore::unpackHalf2x16(Vector4f &dst, const Vector4f &s0) |
| 1102 | { |
| 1103 | // half2 | half1 |
| 1104 | halfToFloatBits(dst.x, As<Float4>(As<UInt4>(s0.x) & UInt4(0x0000FFFF))); |
| 1105 | halfToFloatBits(dst.y, As<Float4>((As<UInt4>(s0.x) & UInt4(0xFFFF0000)) >> 16)); |
| 1106 | } |
| 1107 | |
Alexis Hetu | 9cde974 | 2016-04-06 13:03:38 -0400 | [diff] [blame] | 1108 | void ShaderCore::packSnorm2x16(Vector4f &d, const Vector4f &s0) |
| 1109 | { |
| 1110 | // round(clamp(c, -1.0, 1.0) * 32767.0) |
| 1111 | d.x = As<Float4>((Int4(Round(Min(Max(s0.x, Float4(-1.0f)), Float4(1.0f)) * Float4(32767.0f))) & Int4(0xFFFF)) | |
| 1112 | ((Int4(Round(Min(Max(s0.y, Float4(-1.0f)), Float4(1.0f)) * Float4(32767.0f))) & Int4(0xFFFF)) << 16)); |
| 1113 | } |
| 1114 | |
| 1115 | void ShaderCore::packUnorm2x16(Vector4f &d, const Vector4f &s0) |
| 1116 | { |
| 1117 | // round(clamp(c, 0.0, 1.0) * 65535.0) |
| 1118 | d.x = As<Float4>((Int4(Round(Min(Max(s0.x, Float4(0.0f)), Float4(1.0f)) * Float4(65535.0f))) & Int4(0xFFFF)) | |
| 1119 | ((Int4(Round(Min(Max(s0.y, Float4(0.0f)), Float4(1.0f)) * Float4(65535.0f))) & Int4(0xFFFF)) << 16)); |
| 1120 | } |
| 1121 | |
| 1122 | void ShaderCore::unpackSnorm2x16(Vector4f &dst, const Vector4f &s0) |
| 1123 | { |
| 1124 | // clamp(f / 32727.0, -1.0, 1.0) |
| 1125 | dst.x = Min(Max(Float4(As<Int4>((As<UInt4>(s0.x) & UInt4(0x0000FFFF)) << 16)) * Float4(1.0f / float(0x7FFF0000)), Float4(-1.0f)), Float4(1.0f)); |
| 1126 | dst.y = Min(Max(Float4(As<Int4>(As<UInt4>(s0.x) & UInt4(0xFFFF0000))) * Float4(1.0f / float(0x7FFF0000)), Float4(-1.0f)), Float4(1.0f)); |
| 1127 | } |
| 1128 | |
| 1129 | void ShaderCore::unpackUnorm2x16(Vector4f &dst, const Vector4f &s0) |
| 1130 | { |
| 1131 | // f / 65535.0 |
| 1132 | dst.x = Float4((As<UInt4>(s0.x) & UInt4(0x0000FFFF)) << 16) * Float4(1.0f / float(0xFFFF0000)); |
| 1133 | dst.y = Float4(As<UInt4>(s0.x) & UInt4(0xFFFF0000)) * Float4(1.0f / float(0xFFFF0000)); |
| 1134 | } |
| 1135 | |
Alexis Hetu | c3d95f3 | 2015-09-23 12:27:32 -0400 | [diff] [blame] | 1136 | void ShaderCore::det2(Vector4f &dst, const Vector4f &src0, const Vector4f &src1) |
| 1137 | { |
| 1138 | dst.x = src0.x * src1.y - src0.y * src1.x; |
| 1139 | dst.y = dst.z = dst.w = dst.x; |
| 1140 | } |
| 1141 | |
| 1142 | void ShaderCore::det3(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2) |
| 1143 | { |
| 1144 | crs(dst, src1, src2); |
| 1145 | dp3(dst, dst, src0); |
| 1146 | } |
| 1147 | |
| 1148 | void ShaderCore::det4(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2, const Vector4f &src3) |
| 1149 | { |
| 1150 | dst.x = src2.z * src3.w - src2.w * src3.z; |
| 1151 | dst.y = src1.w * src3.z - src1.z * src3.w; |
| 1152 | dst.z = src1.z * src2.w - src1.w * src2.z; |
| 1153 | dst.x = src0.x * (src1.y * dst.x + src2.y * dst.y + src3.y * dst.z) - |
| 1154 | src0.y * (src1.x * dst.x + src2.x * dst.y + src3.x * dst.z) + |
| 1155 | src0.z * (src1.x * (src2.y * src3.w - src2.w * src3.y) + |
| 1156 | src2.x * (src1.w * src3.y - src1.y * src3.w) + |
| 1157 | src3.x * (src1.y * src2.w - src1.w * src2.y)) + |
| 1158 | src0.w * (src1.x * (src2.z * src3.y - src2.y * src3.z) + |
| 1159 | src2.x * (src1.y * src3.z - src1.z * src3.y) + |
| 1160 | src3.x * (src1.z * src2.y - src1.y * src2.z)); |
| 1161 | dst.y = dst.z = dst.w = dst.x; |
| 1162 | } |
| 1163 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 1164 | void ShaderCore::frc(Vector4f &dst, const Vector4f &src) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1165 | { |
| 1166 | dst.x = Frac(src.x); |
| 1167 | dst.y = Frac(src.y); |
| 1168 | dst.z = Frac(src.z); |
| 1169 | dst.w = Frac(src.w); |
| 1170 | } |
| 1171 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 1172 | void ShaderCore::trunc(Vector4f &dst, const Vector4f &src) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1173 | { |
| 1174 | dst.x = Trunc(src.x); |
| 1175 | dst.y = Trunc(src.y); |
| 1176 | dst.z = Trunc(src.z); |
| 1177 | dst.w = Trunc(src.w); |
| 1178 | } |
| 1179 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 1180 | void ShaderCore::floor(Vector4f &dst, const Vector4f &src) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1181 | { |
| 1182 | dst.x = Floor(src.x); |
| 1183 | dst.y = Floor(src.y); |
| 1184 | dst.z = Floor(src.z); |
| 1185 | dst.w = Floor(src.w); |
| 1186 | } |
| 1187 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 1188 | void ShaderCore::round(Vector4f &dst, const Vector4f &src) |
Alexis Hetu | 8b5f3ef | 2015-04-16 11:33:34 -0400 | [diff] [blame] | 1189 | { |
| 1190 | dst.x = Round(src.x); |
| 1191 | dst.y = Round(src.y); |
| 1192 | dst.z = Round(src.z); |
| 1193 | dst.w = Round(src.w); |
| 1194 | } |
| 1195 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 1196 | void ShaderCore::roundEven(Vector4f &dst, const Vector4f &src) |
Alexis Hetu | 8e851c1 | 2015-06-04 11:30:54 -0400 | [diff] [blame] | 1197 | { |
| 1198 | // dst = round(src) + ((round(src) < src) * 2 - 1) * (fract(src) == 0.5) * isOdd(round(src)); |
| 1199 | // ex.: 1.5: 2 + (0 * 2 - 1) * 1 * 0 = 2 |
| 1200 | // 2.5: 3 + (0 * 2 - 1) * 1 * 1 = 2 |
| 1201 | // -1.5: -2 + (1 * 2 - 1) * 1 * 0 = -2 |
| 1202 | // -2.5: -3 + (1 * 2 - 1) * 1 * 1 = -2 |
| 1203 | // Even if the round implementation rounds the other way: |
| 1204 | // 1.5: 1 + (1 * 2 - 1) * 1 * 1 = 2 |
| 1205 | // 2.5: 2 + (1 * 2 - 1) * 1 * 0 = 2 |
| 1206 | // -1.5: -1 + (0 * 2 - 1) * 1 * 1 = -2 |
| 1207 | // -2.5: -2 + (0 * 2 - 1) * 1 * 0 = -2 |
| 1208 | round(dst, src); |
| 1209 | dst.x += ((Float4(CmpLT(dst.x, src.x) & Int4(1)) * Float4(2.0f)) - Float4(1.0f)) * Float4(CmpEQ(Frac(src.x), Float4(0.5f)) & Int4(1)) * Float4(Int4(dst.x) & Int4(1)); |
| 1210 | dst.y += ((Float4(CmpLT(dst.y, src.y) & Int4(1)) * Float4(2.0f)) - Float4(1.0f)) * Float4(CmpEQ(Frac(src.y), Float4(0.5f)) & Int4(1)) * Float4(Int4(dst.y) & Int4(1)); |
| 1211 | dst.z += ((Float4(CmpLT(dst.z, src.z) & Int4(1)) * Float4(2.0f)) - Float4(1.0f)) * Float4(CmpEQ(Frac(src.z), Float4(0.5f)) & Int4(1)) * Float4(Int4(dst.z) & Int4(1)); |
| 1212 | dst.w += ((Float4(CmpLT(dst.w, src.w) & Int4(1)) * Float4(2.0f)) - Float4(1.0f)) * Float4(CmpEQ(Frac(src.w), Float4(0.5f)) & Int4(1)) * Float4(Int4(dst.w) & Int4(1)); |
| 1213 | } |
| 1214 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 1215 | void ShaderCore::ceil(Vector4f &dst, const Vector4f &src) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1216 | { |
| 1217 | dst.x = Ceil(src.x); |
| 1218 | dst.y = Ceil(src.y); |
| 1219 | dst.z = Ceil(src.z); |
| 1220 | dst.w = Ceil(src.w); |
| 1221 | } |
| 1222 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 1223 | void ShaderCore::powx(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, bool pp) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1224 | { |
| 1225 | Float4 pow = power(src0.x, src1.x, pp); |
| 1226 | |
| 1227 | dst.x = pow; |
| 1228 | dst.y = pow; |
| 1229 | dst.z = pow; |
| 1230 | dst.w = pow; |
| 1231 | } |
| 1232 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 1233 | void ShaderCore::pow(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, bool pp) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1234 | { |
| 1235 | dst.x = power(src0.x, src1.x, pp); |
| 1236 | dst.y = power(src0.y, src1.y, pp); |
| 1237 | dst.z = power(src0.z, src1.z, pp); |
| 1238 | dst.w = power(src0.w, src1.w, pp); |
| 1239 | } |
| 1240 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 1241 | void ShaderCore::crs(Vector4f &dst, const Vector4f &src0, const Vector4f &src1) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1242 | { |
| 1243 | dst.x = src0.y * src1.z - src0.z * src1.y; |
| 1244 | dst.y = src0.z * src1.x - src0.x * src1.z; |
| 1245 | dst.z = src0.x * src1.y - src0.y * src1.x; |
| 1246 | } |
| 1247 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 1248 | void ShaderCore::forward1(Vector4f &dst, const Vector4f &N, const Vector4f &I, const Vector4f &Nref) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1249 | { |
| 1250 | Int4 flip = CmpNLT(Nref.x * I.x, Float4(0.0f)) & Int4(0x80000000); |
| 1251 | |
| 1252 | dst.x = As<Float4>(flip ^ As<Int4>(N.x)); |
| 1253 | } |
| 1254 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 1255 | void ShaderCore::forward2(Vector4f &dst, const Vector4f &N, const Vector4f &I, const Vector4f &Nref) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1256 | { |
| 1257 | Int4 flip = CmpNLT(dot2(Nref, I), Float4(0.0f)) & Int4(0x80000000); |
| 1258 | |
| 1259 | dst.x = As<Float4>(flip ^ As<Int4>(N.x)); |
| 1260 | dst.y = As<Float4>(flip ^ As<Int4>(N.y)); |
| 1261 | } |
| 1262 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 1263 | void ShaderCore::forward3(Vector4f &dst, const Vector4f &N, const Vector4f &I, const Vector4f &Nref) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1264 | { |
| 1265 | Int4 flip = CmpNLT(dot3(Nref, I), Float4(0.0f)) & Int4(0x80000000); |
| 1266 | |
| 1267 | dst.x = As<Float4>(flip ^ As<Int4>(N.x)); |
| 1268 | dst.y = As<Float4>(flip ^ As<Int4>(N.y)); |
| 1269 | dst.z = As<Float4>(flip ^ As<Int4>(N.z)); |
| 1270 | } |
| 1271 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 1272 | void ShaderCore::forward4(Vector4f &dst, const Vector4f &N, const Vector4f &I, const Vector4f &Nref) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1273 | { |
| 1274 | Int4 flip = CmpNLT(dot4(Nref, I), Float4(0.0f)) & Int4(0x80000000); |
| 1275 | |
| 1276 | dst.x = As<Float4>(flip ^ As<Int4>(N.x)); |
| 1277 | dst.y = As<Float4>(flip ^ As<Int4>(N.y)); |
| 1278 | dst.z = As<Float4>(flip ^ As<Int4>(N.z)); |
| 1279 | dst.w = As<Float4>(flip ^ As<Int4>(N.w)); |
| 1280 | } |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 1281 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 1282 | void ShaderCore::reflect1(Vector4f &dst, const Vector4f &I, const Vector4f &N) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1283 | { |
| 1284 | Float4 d = N.x * I.x; |
| 1285 | |
| 1286 | dst.x = I.x - Float4(2.0f) * d * N.x; |
| 1287 | } |
| 1288 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 1289 | void ShaderCore::reflect2(Vector4f &dst, const Vector4f &I, const Vector4f &N) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1290 | { |
| 1291 | Float4 d = dot2(N, I); |
| 1292 | |
| 1293 | dst.x = I.x - Float4(2.0f) * d * N.x; |
| 1294 | dst.y = I.y - Float4(2.0f) * d * N.y; |
| 1295 | } |
| 1296 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 1297 | void ShaderCore::reflect3(Vector4f &dst, const Vector4f &I, const Vector4f &N) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1298 | { |
| 1299 | Float4 d = dot3(N, I); |
| 1300 | |
| 1301 | dst.x = I.x - Float4(2.0f) * d * N.x; |
| 1302 | dst.y = I.y - Float4(2.0f) * d * N.y; |
| 1303 | dst.z = I.z - Float4(2.0f) * d * N.z; |
| 1304 | } |
| 1305 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 1306 | void ShaderCore::reflect4(Vector4f &dst, const Vector4f &I, const Vector4f &N) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1307 | { |
| 1308 | Float4 d = dot4(N, I); |
| 1309 | |
| 1310 | dst.x = I.x - Float4(2.0f) * d * N.x; |
| 1311 | dst.y = I.y - Float4(2.0f) * d * N.y; |
| 1312 | dst.z = I.z - Float4(2.0f) * d * N.z; |
| 1313 | dst.w = I.w - Float4(2.0f) * d * N.w; |
| 1314 | } |
| 1315 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 1316 | void ShaderCore::refract1(Vector4f &dst, const Vector4f &I, const Vector4f &N, const Float4 &eta) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1317 | { |
| 1318 | Float4 d = N.x * I.x; |
| 1319 | Float4 k = Float4(1.0f) - eta * eta * (Float4(1.0f) - d * d); |
| 1320 | Int4 pos = CmpNLT(k, Float4(0.0f)); |
| 1321 | Float4 t = (eta * d + Sqrt(k)); |
| 1322 | |
| 1323 | dst.x = As<Float4>(pos & As<Int4>(eta * I.x - t * N.x)); |
| 1324 | } |
| 1325 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 1326 | void ShaderCore::refract2(Vector4f &dst, const Vector4f &I, const Vector4f &N, const Float4 &eta) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1327 | { |
| 1328 | Float4 d = dot2(N, I); |
| 1329 | Float4 k = Float4(1.0f) - eta * eta * (Float4(1.0f) - d * d); |
| 1330 | Int4 pos = CmpNLT(k, Float4(0.0f)); |
| 1331 | Float4 t = (eta * d + Sqrt(k)); |
| 1332 | |
| 1333 | dst.x = As<Float4>(pos & As<Int4>(eta * I.x - t * N.x)); |
| 1334 | dst.y = As<Float4>(pos & As<Int4>(eta * I.y - t * N.y)); |
| 1335 | } |
| 1336 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 1337 | void ShaderCore::refract3(Vector4f &dst, const Vector4f &I, const Vector4f &N, const Float4 &eta) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1338 | { |
| 1339 | Float4 d = dot3(N, I); |
| 1340 | Float4 k = Float4(1.0f) - eta * eta * (Float4(1.0f) - d * d); |
| 1341 | Int4 pos = CmpNLT(k, Float4(0.0f)); |
| 1342 | Float4 t = (eta * d + Sqrt(k)); |
| 1343 | |
| 1344 | dst.x = As<Float4>(pos & As<Int4>(eta * I.x - t * N.x)); |
| 1345 | dst.y = As<Float4>(pos & As<Int4>(eta * I.y - t * N.y)); |
| 1346 | dst.z = As<Float4>(pos & As<Int4>(eta * I.z - t * N.z)); |
| 1347 | } |
| 1348 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 1349 | void ShaderCore::refract4(Vector4f &dst, const Vector4f &I, const Vector4f &N, const Float4 &eta) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1350 | { |
| 1351 | Float4 d = dot4(N, I); |
| 1352 | Float4 k = Float4(1.0f) - eta * eta * (Float4(1.0f) - d * d); |
| 1353 | Int4 pos = CmpNLT(k, Float4(0.0f)); |
| 1354 | Float4 t = (eta * d + Sqrt(k)); |
| 1355 | |
| 1356 | dst.x = As<Float4>(pos & As<Int4>(eta * I.x - t * N.x)); |
| 1357 | dst.y = As<Float4>(pos & As<Int4>(eta * I.y - t * N.y)); |
| 1358 | dst.z = As<Float4>(pos & As<Int4>(eta * I.z - t * N.z)); |
| 1359 | dst.w = As<Float4>(pos & As<Int4>(eta * I.w - t * N.w)); |
| 1360 | } |
| 1361 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 1362 | void ShaderCore::sgn(Vector4f &dst, const Vector4f &src) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1363 | { |
| 1364 | sgn(dst.x, src.x); |
| 1365 | sgn(dst.y, src.y); |
| 1366 | sgn(dst.z, src.z); |
| 1367 | sgn(dst.w, src.w); |
| 1368 | } |
| 1369 | |
Alexis Hetu | 0f44807 | 2016-03-18 10:56:08 -0400 | [diff] [blame] | 1370 | void ShaderCore::isgn(Vector4f &dst, const Vector4f &src) |
| 1371 | { |
| 1372 | isgn(dst.x, src.x); |
| 1373 | isgn(dst.y, src.y); |
| 1374 | isgn(dst.z, src.z); |
| 1375 | isgn(dst.w, src.w); |
| 1376 | } |
| 1377 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 1378 | void ShaderCore::abs(Vector4f &dst, const Vector4f &src) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1379 | { |
| 1380 | dst.x = Abs(src.x); |
| 1381 | dst.y = Abs(src.y); |
| 1382 | dst.z = Abs(src.z); |
| 1383 | dst.w = Abs(src.w); |
| 1384 | } |
Alexis Hetu | 0f44807 | 2016-03-18 10:56:08 -0400 | [diff] [blame] | 1385 | |
| 1386 | void ShaderCore::iabs(Vector4f &dst, const Vector4f &src) |
| 1387 | { |
| 1388 | dst.x = As<Float4>(Abs(As<Int4>(src.x))); |
| 1389 | dst.y = As<Float4>(Abs(As<Int4>(src.y))); |
| 1390 | dst.z = As<Float4>(Abs(As<Int4>(src.z))); |
| 1391 | dst.w = As<Float4>(Abs(As<Int4>(src.w))); |
| 1392 | } |
| 1393 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 1394 | void ShaderCore::nrm2(Vector4f &dst, const Vector4f &src, bool pp) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1395 | { |
| 1396 | Float4 dot = dot2(src, src); |
| 1397 | Float4 rsq = reciprocalSquareRoot(dot, false, pp); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1398 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1399 | dst.x = src.x * rsq; |
| 1400 | dst.y = src.y * rsq; |
| 1401 | dst.z = src.z * rsq; |
| 1402 | dst.w = src.w * rsq; |
| 1403 | } |
| 1404 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 1405 | void ShaderCore::nrm3(Vector4f &dst, const Vector4f &src, bool pp) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1406 | { |
| 1407 | Float4 dot = dot3(src, src); |
| 1408 | Float4 rsq = reciprocalSquareRoot(dot, false, pp); |
| 1409 | |
| 1410 | dst.x = src.x * rsq; |
| 1411 | dst.y = src.y * rsq; |
| 1412 | dst.z = src.z * rsq; |
| 1413 | dst.w = src.w * rsq; |
| 1414 | } |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1415 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 1416 | void ShaderCore::nrm4(Vector4f &dst, const Vector4f &src, bool pp) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1417 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1418 | Float4 dot = dot4(src, src); |
| 1419 | Float4 rsq = reciprocalSquareRoot(dot, false, pp); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1420 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1421 | dst.x = src.x * rsq; |
| 1422 | dst.y = src.y * rsq; |
| 1423 | dst.z = src.z * rsq; |
| 1424 | dst.w = src.w * rsq; |
| 1425 | } |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 1426 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 1427 | void ShaderCore::sincos(Vector4f &dst, const Vector4f &src, bool pp) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1428 | { |
| 1429 | dst.x = cosine_pi(src.x, pp); |
| 1430 | dst.y = sine_pi(src.x, pp); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1431 | } |
| 1432 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 1433 | void ShaderCore::cos(Vector4f &dst, const Vector4f &src, bool pp) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1434 | { |
| 1435 | dst.x = cosine(src.x, pp); |
| 1436 | dst.y = cosine(src.y, pp); |
| 1437 | dst.z = cosine(src.z, pp); |
| 1438 | dst.w = cosine(src.w, pp); |
| 1439 | } |
| 1440 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 1441 | void ShaderCore::sin(Vector4f &dst, const Vector4f &src, bool pp) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1442 | { |
| 1443 | dst.x = sine(src.x, pp); |
| 1444 | dst.y = sine(src.y, pp); |
| 1445 | dst.z = sine(src.z, pp); |
| 1446 | dst.w = sine(src.w, pp); |
| 1447 | } |
| 1448 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 1449 | void ShaderCore::tan(Vector4f &dst, const Vector4f &src, bool pp) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1450 | { |
| 1451 | dst.x = tangent(src.x, pp); |
| 1452 | dst.y = tangent(src.y, pp); |
| 1453 | dst.z = tangent(src.z, pp); |
| 1454 | dst.w = tangent(src.w, pp); |
| 1455 | } |
| 1456 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 1457 | void ShaderCore::acos(Vector4f &dst, const Vector4f &src, bool pp) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1458 | { |
| 1459 | dst.x = arccos(src.x, pp); |
| 1460 | dst.y = arccos(src.y, pp); |
| 1461 | dst.z = arccos(src.z, pp); |
| 1462 | dst.w = arccos(src.w, pp); |
| 1463 | } |
| 1464 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 1465 | void ShaderCore::asin(Vector4f &dst, const Vector4f &src, bool pp) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1466 | { |
| 1467 | dst.x = arcsin(src.x, pp); |
| 1468 | dst.y = arcsin(src.y, pp); |
| 1469 | dst.z = arcsin(src.z, pp); |
| 1470 | dst.w = arcsin(src.w, pp); |
| 1471 | } |
| 1472 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 1473 | void ShaderCore::atan(Vector4f &dst, const Vector4f &src, bool pp) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1474 | { |
| 1475 | dst.x = arctan(src.x, pp); |
| 1476 | dst.y = arctan(src.y, pp); |
| 1477 | dst.z = arctan(src.z, pp); |
| 1478 | dst.w = arctan(src.w, pp); |
| 1479 | } |
| 1480 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 1481 | void ShaderCore::atan2(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, bool pp) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1482 | { |
| 1483 | dst.x = arctan(src0.x, src1.x, pp); |
| 1484 | dst.y = arctan(src0.y, src1.y, pp); |
| 1485 | dst.z = arctan(src0.z, src1.z, pp); |
| 1486 | dst.w = arctan(src0.w, src1.w, pp); |
| 1487 | } |
| 1488 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 1489 | void ShaderCore::cosh(Vector4f &dst, const Vector4f &src, bool pp) |
Alexis Hetu | 8b5f3ef | 2015-04-16 11:33:34 -0400 | [diff] [blame] | 1490 | { |
| 1491 | dst.x = cosineh(src.x, pp); |
| 1492 | dst.y = cosineh(src.y, pp); |
| 1493 | dst.z = cosineh(src.z, pp); |
| 1494 | dst.w = cosineh(src.w, pp); |
| 1495 | } |
| 1496 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 1497 | void ShaderCore::sinh(Vector4f &dst, const Vector4f &src, bool pp) |
Alexis Hetu | 8b5f3ef | 2015-04-16 11:33:34 -0400 | [diff] [blame] | 1498 | { |
| 1499 | dst.x = sineh(src.x, pp); |
| 1500 | dst.y = sineh(src.y, pp); |
| 1501 | dst.z = sineh(src.z, pp); |
| 1502 | dst.w = sineh(src.w, pp); |
| 1503 | } |
| 1504 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 1505 | void ShaderCore::tanh(Vector4f &dst, const Vector4f &src, bool pp) |
Alexis Hetu | 8b5f3ef | 2015-04-16 11:33:34 -0400 | [diff] [blame] | 1506 | { |
| 1507 | dst.x = tangenth(src.x, pp); |
| 1508 | dst.y = tangenth(src.y, pp); |
| 1509 | dst.z = tangenth(src.z, pp); |
| 1510 | dst.w = tangenth(src.w, pp); |
| 1511 | } |
| 1512 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 1513 | void ShaderCore::acosh(Vector4f &dst, const Vector4f &src, bool pp) |
Alexis Hetu | 8b5f3ef | 2015-04-16 11:33:34 -0400 | [diff] [blame] | 1514 | { |
| 1515 | dst.x = arccosh(src.x, pp); |
| 1516 | dst.y = arccosh(src.y, pp); |
| 1517 | dst.z = arccosh(src.z, pp); |
| 1518 | dst.w = arccosh(src.w, pp); |
| 1519 | } |
| 1520 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 1521 | void ShaderCore::asinh(Vector4f &dst, const Vector4f &src, bool pp) |
Alexis Hetu | 8b5f3ef | 2015-04-16 11:33:34 -0400 | [diff] [blame] | 1522 | { |
| 1523 | dst.x = arcsinh(src.x, pp); |
| 1524 | dst.y = arcsinh(src.y, pp); |
| 1525 | dst.z = arcsinh(src.z, pp); |
| 1526 | dst.w = arcsinh(src.w, pp); |
| 1527 | } |
| 1528 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 1529 | void ShaderCore::atanh(Vector4f &dst, const Vector4f &src, bool pp) |
Alexis Hetu | 8b5f3ef | 2015-04-16 11:33:34 -0400 | [diff] [blame] | 1530 | { |
| 1531 | dst.x = arctanh(src.x, pp); |
| 1532 | dst.y = arctanh(src.y, pp); |
| 1533 | dst.z = arctanh(src.z, pp); |
| 1534 | dst.w = arctanh(src.w, pp); |
| 1535 | } |
| 1536 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 1537 | void ShaderCore::expp(Vector4f &dst, const Vector4f &src, unsigned short version) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1538 | { |
| 1539 | if(version < 0x0200) |
| 1540 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1541 | Float4 frc = Frac(src.x); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1542 | Float4 floor = src.x - frc; |
| 1543 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1544 | dst.x = exponential2(floor, true); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1545 | dst.y = frc; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1546 | dst.z = exponential2(src.x, true); |
| 1547 | dst.w = Float4(1.0f); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1548 | } |
| 1549 | else // Version >= 2.0 |
| 1550 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1551 | exp2x(dst, src, true); // FIXME: 10-bit precision suffices |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1552 | } |
| 1553 | } |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 1554 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 1555 | void ShaderCore::logp(Vector4f &dst, const Vector4f &src, unsigned short version) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1556 | { |
| 1557 | if(version < 0x0200) |
| 1558 | { |
| 1559 | Float4 tmp0; |
| 1560 | Float4 tmp1; |
| 1561 | Float4 t; |
| 1562 | Int4 r; |
| 1563 | |
| 1564 | tmp0 = Abs(src.x); |
| 1565 | tmp1 = tmp0; |
| 1566 | |
| 1567 | // X component |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1568 | r = As<Int4>(As<UInt4>(tmp0) >> 23) - Int4(127); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1569 | dst.x = Float4(r); |
| 1570 | |
| 1571 | // Y component |
| 1572 | dst.y = As<Float4>((As<Int4>(tmp1) & Int4(0x007FFFFF)) | As<Int4>(Float4(1.0f))); |
| 1573 | |
| 1574 | // Z component |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1575 | dst.z = logarithm2(src.x, true, true); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1576 | |
| 1577 | // W component |
| 1578 | dst.w = 1.0f; |
| 1579 | } |
| 1580 | else |
| 1581 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1582 | log2x(dst, src, true); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1583 | } |
| 1584 | } |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 1585 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 1586 | void ShaderCore::cmp0(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1587 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1588 | cmp0(dst.x, src0.x, src1.x, src2.x); |
| 1589 | cmp0(dst.y, src0.y, src1.y, src2.y); |
| 1590 | cmp0(dst.z, src0.z, src1.z, src2.z); |
| 1591 | cmp0(dst.w, src0.w, src1.w, src2.w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1592 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1593 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 1594 | void ShaderCore::select(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1595 | { |
| 1596 | select(dst.x, As<Int4>(src0.x), src1.x, src2.x); |
| 1597 | select(dst.y, As<Int4>(src0.y), src1.y, src2.y); |
| 1598 | select(dst.z, As<Int4>(src0.z), src1.z, src2.z); |
| 1599 | select(dst.w, As<Int4>(src0.w), src1.w, src2.w); |
| 1600 | } |
| 1601 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 1602 | void ShaderCore::extract(Float4 &dst, const Vector4f &src0, const Float4 &src1) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1603 | { |
Alexis Hetu | c4f2c29 | 2015-08-18 15:43:09 -0400 | [diff] [blame] | 1604 | select(dst, CmpEQ(As<Int4>(src1), Int4(1)), src0.y, src0.x); |
| 1605 | select(dst, CmpEQ(As<Int4>(src1), Int4(2)), src0.z, dst); |
| 1606 | select(dst, CmpEQ(As<Int4>(src1), Int4(3)), src0.w, dst); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1607 | } |
| 1608 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 1609 | void ShaderCore::insert(Vector4f &dst, const Vector4f &src, const Float4 &element, const Float4 &index) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1610 | { |
Alexis Hetu | c4f2c29 | 2015-08-18 15:43:09 -0400 | [diff] [blame] | 1611 | select(dst.x, CmpEQ(As<Int4>(index), Int4(0)), element, src.x); |
| 1612 | select(dst.y, CmpEQ(As<Int4>(index), Int4(1)), element, src.y); |
| 1613 | select(dst.z, CmpEQ(As<Int4>(index), Int4(2)), element, src.z); |
| 1614 | select(dst.w, CmpEQ(As<Int4>(index), Int4(3)), element, src.w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1615 | } |
| 1616 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 1617 | void ShaderCore::sgn(Float4 &dst, const Float4 &src) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1618 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1619 | Int4 neg = As<Int4>(CmpLT(src, Float4(-0.0f))) & As<Int4>(Float4(-1.0f)); |
| 1620 | Int4 pos = As<Int4>(CmpNLE(src, Float4(+0.0f))) & As<Int4>(Float4(1.0f)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1621 | dst = As<Float4>(neg | pos); |
| 1622 | } |
| 1623 | |
Alexis Hetu | 0f44807 | 2016-03-18 10:56:08 -0400 | [diff] [blame] | 1624 | void ShaderCore::isgn(Float4 &dst, const Float4 &src) |
| 1625 | { |
| 1626 | Int4 neg = CmpLT(As<Int4>(src), Int4(0)) & Int4(-1); |
| 1627 | Int4 pos = CmpNLE(As<Int4>(src), Int4(0)) & Int4(1); |
| 1628 | dst = As<Float4>(neg | pos); |
| 1629 | } |
| 1630 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 1631 | void ShaderCore::cmp0(Float4 &dst, const Float4 &src0, const Float4 &src1, const Float4 &src2) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1632 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1633 | Int4 pos = CmpLE(Float4(0.0f), src0); |
| 1634 | select(dst, pos, src1, src2); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1635 | } |
| 1636 | |
Alexis Hetu | c4f2c29 | 2015-08-18 15:43:09 -0400 | [diff] [blame] | 1637 | void ShaderCore::cmp0i(Float4 &dst, const Float4 &src0, const Float4 &src1, const Float4 &src2) |
| 1638 | { |
| 1639 | Int4 pos = CmpEQ(Int4(0), As<Int4>(src0)); |
| 1640 | select(dst, pos, src1, src2); |
| 1641 | } |
| 1642 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 1643 | void ShaderCore::select(Float4 &dst, RValue<Int4> src0, const Float4 &src1, const Float4 &src2) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1644 | { |
| 1645 | // FIXME: LLVM vector select |
Tom Anderson | 69bc6e8 | 2017-03-20 11:54:29 -0700 | [diff] [blame] | 1646 | dst = As<Float4>((src0 & As<Int4>(src1)) | (~src0 & As<Int4>(src2))); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1647 | } |
| 1648 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 1649 | void ShaderCore::cmp(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, Control control) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1650 | { |
| 1651 | switch(control) |
| 1652 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1653 | case Shader::CONTROL_GT: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1654 | dst.x = As<Float4>(CmpNLE(src0.x, src1.x)); |
| 1655 | dst.y = As<Float4>(CmpNLE(src0.y, src1.y)); |
| 1656 | dst.z = As<Float4>(CmpNLE(src0.z, src1.z)); |
| 1657 | dst.w = As<Float4>(CmpNLE(src0.w, src1.w)); |
| 1658 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1659 | case Shader::CONTROL_EQ: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1660 | dst.x = As<Float4>(CmpEQ(src0.x, src1.x)); |
| 1661 | dst.y = As<Float4>(CmpEQ(src0.y, src1.y)); |
| 1662 | dst.z = As<Float4>(CmpEQ(src0.z, src1.z)); |
| 1663 | dst.w = As<Float4>(CmpEQ(src0.w, src1.w)); |
| 1664 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1665 | case Shader::CONTROL_GE: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1666 | dst.x = As<Float4>(CmpNLT(src0.x, src1.x)); |
| 1667 | dst.y = As<Float4>(CmpNLT(src0.y, src1.y)); |
| 1668 | dst.z = As<Float4>(CmpNLT(src0.z, src1.z)); |
| 1669 | dst.w = As<Float4>(CmpNLT(src0.w, src1.w)); |
| 1670 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1671 | case Shader::CONTROL_LT: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1672 | dst.x = As<Float4>(CmpLT(src0.x, src1.x)); |
| 1673 | dst.y = As<Float4>(CmpLT(src0.y, src1.y)); |
| 1674 | dst.z = As<Float4>(CmpLT(src0.z, src1.z)); |
| 1675 | dst.w = As<Float4>(CmpLT(src0.w, src1.w)); |
| 1676 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1677 | case Shader::CONTROL_NE: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1678 | dst.x = As<Float4>(CmpNEQ(src0.x, src1.x)); |
| 1679 | dst.y = As<Float4>(CmpNEQ(src0.y, src1.y)); |
| 1680 | dst.z = As<Float4>(CmpNEQ(src0.z, src1.z)); |
| 1681 | dst.w = As<Float4>(CmpNEQ(src0.w, src1.w)); |
| 1682 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1683 | case Shader::CONTROL_LE: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1684 | dst.x = As<Float4>(CmpLE(src0.x, src1.x)); |
| 1685 | dst.y = As<Float4>(CmpLE(src0.y, src1.y)); |
| 1686 | dst.z = As<Float4>(CmpLE(src0.z, src1.z)); |
| 1687 | dst.w = As<Float4>(CmpLE(src0.w, src1.w)); |
| 1688 | break; |
| 1689 | default: |
| 1690 | ASSERT(false); |
| 1691 | } |
| 1692 | } |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1693 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 1694 | void ShaderCore::icmp(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, Control control) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1695 | { |
| 1696 | switch(control) |
| 1697 | { |
| 1698 | case Shader::CONTROL_GT: |
| 1699 | dst.x = As<Float4>(CmpNLE(As<Int4>(src0.x), As<Int4>(src1.x))); |
| 1700 | dst.y = As<Float4>(CmpNLE(As<Int4>(src0.y), As<Int4>(src1.y))); |
| 1701 | dst.z = As<Float4>(CmpNLE(As<Int4>(src0.z), As<Int4>(src1.z))); |
| 1702 | dst.w = As<Float4>(CmpNLE(As<Int4>(src0.w), As<Int4>(src1.w))); |
| 1703 | break; |
| 1704 | case Shader::CONTROL_EQ: |
| 1705 | dst.x = As<Float4>(CmpEQ(As<Int4>(src0.x), As<Int4>(src1.x))); |
| 1706 | dst.y = As<Float4>(CmpEQ(As<Int4>(src0.y), As<Int4>(src1.y))); |
| 1707 | dst.z = As<Float4>(CmpEQ(As<Int4>(src0.z), As<Int4>(src1.z))); |
| 1708 | dst.w = As<Float4>(CmpEQ(As<Int4>(src0.w), As<Int4>(src1.w))); |
| 1709 | break; |
| 1710 | case Shader::CONTROL_GE: |
| 1711 | dst.x = As<Float4>(CmpNLT(As<Int4>(src0.x), As<Int4>(src1.x))); |
| 1712 | dst.y = As<Float4>(CmpNLT(As<Int4>(src0.y), As<Int4>(src1.y))); |
| 1713 | dst.z = As<Float4>(CmpNLT(As<Int4>(src0.z), As<Int4>(src1.z))); |
| 1714 | dst.w = As<Float4>(CmpNLT(As<Int4>(src0.w), As<Int4>(src1.w))); |
| 1715 | break; |
| 1716 | case Shader::CONTROL_LT: |
| 1717 | dst.x = As<Float4>(CmpLT(As<Int4>(src0.x), As<Int4>(src1.x))); |
| 1718 | dst.y = As<Float4>(CmpLT(As<Int4>(src0.y), As<Int4>(src1.y))); |
| 1719 | dst.z = As<Float4>(CmpLT(As<Int4>(src0.z), As<Int4>(src1.z))); |
| 1720 | dst.w = As<Float4>(CmpLT(As<Int4>(src0.w), As<Int4>(src1.w))); |
| 1721 | break; |
| 1722 | case Shader::CONTROL_NE: |
| 1723 | dst.x = As<Float4>(CmpNEQ(As<Int4>(src0.x), As<Int4>(src1.x))); |
| 1724 | dst.y = As<Float4>(CmpNEQ(As<Int4>(src0.y), As<Int4>(src1.y))); |
| 1725 | dst.z = As<Float4>(CmpNEQ(As<Int4>(src0.z), As<Int4>(src1.z))); |
| 1726 | dst.w = As<Float4>(CmpNEQ(As<Int4>(src0.w), As<Int4>(src1.w))); |
| 1727 | break; |
| 1728 | case Shader::CONTROL_LE: |
| 1729 | dst.x = As<Float4>(CmpLE(As<Int4>(src0.x), As<Int4>(src1.x))); |
| 1730 | dst.y = As<Float4>(CmpLE(As<Int4>(src0.y), As<Int4>(src1.y))); |
| 1731 | dst.z = As<Float4>(CmpLE(As<Int4>(src0.z), As<Int4>(src1.z))); |
| 1732 | dst.w = As<Float4>(CmpLE(As<Int4>(src0.w), As<Int4>(src1.w))); |
| 1733 | break; |
| 1734 | default: |
| 1735 | ASSERT(false); |
| 1736 | } |
| 1737 | } |
| 1738 | |
Alexis Hetu | c4f2c29 | 2015-08-18 15:43:09 -0400 | [diff] [blame] | 1739 | void ShaderCore::ucmp(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, Control control) |
| 1740 | { |
| 1741 | switch(control) |
| 1742 | { |
| 1743 | case Shader::CONTROL_GT: |
| 1744 | dst.x = As<Float4>(CmpNLE(As<UInt4>(src0.x), As<UInt4>(src1.x))); |
| 1745 | dst.y = As<Float4>(CmpNLE(As<UInt4>(src0.y), As<UInt4>(src1.y))); |
| 1746 | dst.z = As<Float4>(CmpNLE(As<UInt4>(src0.z), As<UInt4>(src1.z))); |
| 1747 | dst.w = As<Float4>(CmpNLE(As<UInt4>(src0.w), As<UInt4>(src1.w))); |
| 1748 | break; |
| 1749 | case Shader::CONTROL_EQ: |
| 1750 | dst.x = As<Float4>(CmpEQ(As<UInt4>(src0.x), As<UInt4>(src1.x))); |
| 1751 | dst.y = As<Float4>(CmpEQ(As<UInt4>(src0.y), As<UInt4>(src1.y))); |
| 1752 | dst.z = As<Float4>(CmpEQ(As<UInt4>(src0.z), As<UInt4>(src1.z))); |
| 1753 | dst.w = As<Float4>(CmpEQ(As<UInt4>(src0.w), As<UInt4>(src1.w))); |
| 1754 | break; |
| 1755 | case Shader::CONTROL_GE: |
| 1756 | dst.x = As<Float4>(CmpNLT(As<UInt4>(src0.x), As<UInt4>(src1.x))); |
| 1757 | dst.y = As<Float4>(CmpNLT(As<UInt4>(src0.y), As<UInt4>(src1.y))); |
| 1758 | dst.z = As<Float4>(CmpNLT(As<UInt4>(src0.z), As<UInt4>(src1.z))); |
| 1759 | dst.w = As<Float4>(CmpNLT(As<UInt4>(src0.w), As<UInt4>(src1.w))); |
| 1760 | break; |
| 1761 | case Shader::CONTROL_LT: |
| 1762 | dst.x = As<Float4>(CmpLT(As<UInt4>(src0.x), As<UInt4>(src1.x))); |
| 1763 | dst.y = As<Float4>(CmpLT(As<UInt4>(src0.y), As<UInt4>(src1.y))); |
| 1764 | dst.z = As<Float4>(CmpLT(As<UInt4>(src0.z), As<UInt4>(src1.z))); |
| 1765 | dst.w = As<Float4>(CmpLT(As<UInt4>(src0.w), As<UInt4>(src1.w))); |
| 1766 | break; |
| 1767 | case Shader::CONTROL_NE: |
| 1768 | dst.x = As<Float4>(CmpNEQ(As<UInt4>(src0.x), As<UInt4>(src1.x))); |
| 1769 | dst.y = As<Float4>(CmpNEQ(As<UInt4>(src0.y), As<UInt4>(src1.y))); |
| 1770 | dst.z = As<Float4>(CmpNEQ(As<UInt4>(src0.z), As<UInt4>(src1.z))); |
| 1771 | dst.w = As<Float4>(CmpNEQ(As<UInt4>(src0.w), As<UInt4>(src1.w))); |
| 1772 | break; |
| 1773 | case Shader::CONTROL_LE: |
| 1774 | dst.x = As<Float4>(CmpLE(As<UInt4>(src0.x), As<UInt4>(src1.x))); |
| 1775 | dst.y = As<Float4>(CmpLE(As<UInt4>(src0.y), As<UInt4>(src1.y))); |
| 1776 | dst.z = As<Float4>(CmpLE(As<UInt4>(src0.z), As<UInt4>(src1.z))); |
| 1777 | dst.w = As<Float4>(CmpLE(As<UInt4>(src0.w), As<UInt4>(src1.w))); |
| 1778 | break; |
| 1779 | default: |
| 1780 | ASSERT(false); |
| 1781 | } |
| 1782 | } |
| 1783 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 1784 | void ShaderCore::all(Float4 &dst, const Vector4f &src) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1785 | { |
| 1786 | dst = As<Float4>(As<Int4>(src.x) & As<Int4>(src.y) & As<Int4>(src.z) & As<Int4>(src.w)); |
| 1787 | } |
| 1788 | |
Alexis Hetu | ecad519 | 2015-06-05 13:42:05 -0400 | [diff] [blame] | 1789 | void ShaderCore::any(Float4 &dst, const Vector4f &src) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1790 | { |
| 1791 | dst = As<Float4>(As<Int4>(src.x) | As<Int4>(src.y) | As<Int4>(src.z) | As<Int4>(src.w)); |
| 1792 | } |
| 1793 | |
Alexis Hetu | 24f454e | 2016-08-31 17:22:13 -0400 | [diff] [blame] | 1794 | void ShaderCore::bitwise_not(Vector4f &dst, const Vector4f &src) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1795 | { |
| 1796 | dst.x = As<Float4>(As<Int4>(src.x) ^ Int4(0xFFFFFFFF)); |
| 1797 | dst.y = As<Float4>(As<Int4>(src.y) ^ Int4(0xFFFFFFFF)); |
| 1798 | dst.z = As<Float4>(As<Int4>(src.z) ^ Int4(0xFFFFFFFF)); |
| 1799 | dst.w = As<Float4>(As<Int4>(src.w) ^ Int4(0xFFFFFFFF)); |
| 1800 | } |
| 1801 | |
Alexis Hetu | 24f454e | 2016-08-31 17:22:13 -0400 | [diff] [blame] | 1802 | void ShaderCore::bitwise_or(Vector4f &dst, const Vector4f &src0, const Vector4f &src1) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1803 | { |
Alexis Hetu | c4f2c29 | 2015-08-18 15:43:09 -0400 | [diff] [blame] | 1804 | dst.x = As<Float4>(As<Int4>(src0.x) | As<Int4>(src1.x)); |
| 1805 | dst.y = As<Float4>(As<Int4>(src0.y) | As<Int4>(src1.y)); |
| 1806 | dst.z = As<Float4>(As<Int4>(src0.z) | As<Int4>(src1.z)); |
| 1807 | dst.w = As<Float4>(As<Int4>(src0.w) | As<Int4>(src1.w)); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1808 | } |
| 1809 | |
Alexis Hetu | 24f454e | 2016-08-31 17:22:13 -0400 | [diff] [blame] | 1810 | void ShaderCore::bitwise_xor(Vector4f &dst, const Vector4f &src0, const Vector4f &src1) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1811 | { |
Alexis Hetu | c4f2c29 | 2015-08-18 15:43:09 -0400 | [diff] [blame] | 1812 | dst.x = As<Float4>(As<Int4>(src0.x) ^ As<Int4>(src1.x)); |
| 1813 | dst.y = As<Float4>(As<Int4>(src0.y) ^ As<Int4>(src1.y)); |
| 1814 | dst.z = As<Float4>(As<Int4>(src0.z) ^ As<Int4>(src1.z)); |
| 1815 | dst.w = As<Float4>(As<Int4>(src0.w) ^ As<Int4>(src1.w)); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1816 | } |
| 1817 | |
Alexis Hetu | 24f454e | 2016-08-31 17:22:13 -0400 | [diff] [blame] | 1818 | void ShaderCore::bitwise_and(Vector4f &dst, const Vector4f &src0, const Vector4f &src1) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1819 | { |
Alexis Hetu | c4f2c29 | 2015-08-18 15:43:09 -0400 | [diff] [blame] | 1820 | dst.x = As<Float4>(As<Int4>(src0.x) & As<Int4>(src1.x)); |
| 1821 | dst.y = As<Float4>(As<Int4>(src0.y) & As<Int4>(src1.y)); |
| 1822 | dst.z = As<Float4>(As<Int4>(src0.z) & As<Int4>(src1.z)); |
| 1823 | dst.w = As<Float4>(As<Int4>(src0.w) & As<Int4>(src1.w)); |
| 1824 | } |
| 1825 | |
| 1826 | void ShaderCore::equal(Vector4f &dst, const Vector4f &src0, const Vector4f &src1) |
| 1827 | { |
| 1828 | dst.x = As<Float4>(CmpEQ(As<UInt4>(src0.x), As<UInt4>(src1.x)) & |
| 1829 | CmpEQ(As<UInt4>(src0.y), As<UInt4>(src1.y)) & |
| 1830 | CmpEQ(As<UInt4>(src0.z), As<UInt4>(src1.z)) & |
| 1831 | CmpEQ(As<UInt4>(src0.w), As<UInt4>(src1.w))); |
| 1832 | dst.y = dst.x; |
| 1833 | dst.z = dst.x; |
| 1834 | dst.w = dst.x; |
| 1835 | } |
| 1836 | |
| 1837 | void ShaderCore::notEqual(Vector4f &dst, const Vector4f &src0, const Vector4f &src1) |
| 1838 | { |
| 1839 | dst.x = As<Float4>(CmpNEQ(As<UInt4>(src0.x), As<UInt4>(src1.x)) | |
| 1840 | CmpNEQ(As<UInt4>(src0.y), As<UInt4>(src1.y)) | |
| 1841 | CmpNEQ(As<UInt4>(src0.z), As<UInt4>(src1.z)) | |
| 1842 | CmpNEQ(As<UInt4>(src0.w), As<UInt4>(src1.w))); |
| 1843 | dst.y = dst.x; |
| 1844 | dst.z = dst.x; |
| 1845 | dst.w = dst.x; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1846 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1847 | } |