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