John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1 | // SwiftShader Software Renderer |
| 2 | // |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3 | // Copyright(c) 2005-2012 TransGaming Inc. |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4 | // |
| 5 | // All rights reserved. No part of this software may be copied, distributed, transmitted, |
| 6 | // transcribed, stored in a retrieval system, translated into any human or computer |
| 7 | // language by any means, or disclosed to third parties without the explicit written |
| 8 | // agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express |
| 9 | // or implied, including but not limited to any patent rights, are granted to you. |
| 10 | // |
| 11 | |
| 12 | #include "ShaderCore.hpp" |
| 13 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 14 | #include "Renderer/Renderer.hpp" |
| 15 | #include "Common/Debug.hpp" |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 16 | |
| 17 | namespace sw |
| 18 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 19 | extern TranscendentalPrecision logPrecision; |
| 20 | extern TranscendentalPrecision expPrecision; |
| 21 | extern TranscendentalPrecision rcpPrecision; |
| 22 | extern TranscendentalPrecision rsqPrecision; |
| 23 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 24 | Vector4s::Vector4s() |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 25 | { |
| 26 | } |
| 27 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 28 | 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] | 29 | { |
| 30 | this->x = Short4(x); |
| 31 | this->y = Short4(y); |
| 32 | this->z = Short4(z); |
| 33 | this->w = Short4(w); |
| 34 | } |
| 35 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 36 | Vector4s::Vector4s(const Vector4s &rhs) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 37 | { |
| 38 | x = rhs.x; |
| 39 | y = rhs.y; |
| 40 | z = rhs.z; |
| 41 | w = rhs.w; |
| 42 | } |
| 43 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 44 | Vector4s &Vector4s::operator=(const Vector4s &rhs) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 45 | { |
| 46 | x = rhs.x; |
| 47 | y = rhs.y; |
| 48 | z = rhs.z; |
| 49 | w = rhs.w; |
| 50 | |
| 51 | return *this; |
| 52 | } |
| 53 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 54 | Short4 &Vector4s::operator[](int i) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 55 | { |
| 56 | switch(i) |
| 57 | { |
| 58 | case 0: return x; |
| 59 | case 1: return y; |
| 60 | case 2: return z; |
| 61 | case 3: return w; |
| 62 | } |
| 63 | |
| 64 | return x; |
| 65 | } |
| 66 | |
Alexis Hetu | 8b5f3ef | 2015-04-16 11:33:34 -0400 | [diff] [blame^] | 67 | Vector4i::Vector4i() |
| 68 | { |
| 69 | } |
| 70 | |
| 71 | Vector4i::Vector4i(int x, int y, int z, int w) |
| 72 | { |
| 73 | this->x = Int4(x); |
| 74 | this->y = Int4(y); |
| 75 | this->z = Int4(z); |
| 76 | this->w = Int4(w); |
| 77 | } |
| 78 | |
| 79 | Vector4i::Vector4i(const Vector4i &rhs) |
| 80 | { |
| 81 | x = rhs.x; |
| 82 | y = rhs.y; |
| 83 | z = rhs.z; |
| 84 | w = rhs.w; |
| 85 | } |
| 86 | |
| 87 | Vector4i &Vector4i::operator=(const Vector4i &rhs) |
| 88 | { |
| 89 | x = rhs.x; |
| 90 | y = rhs.y; |
| 91 | z = rhs.z; |
| 92 | w = rhs.w; |
| 93 | |
| 94 | return *this; |
| 95 | } |
| 96 | |
| 97 | Int4 &Vector4i::operator[](int i) |
| 98 | { |
| 99 | switch(i) |
| 100 | { |
| 101 | case 0: return x; |
| 102 | case 1: return y; |
| 103 | case 2: return z; |
| 104 | case 3: return w; |
| 105 | } |
| 106 | |
| 107 | return x; |
| 108 | } |
| 109 | |
| 110 | Vector4u::Vector4u() |
| 111 | { |
| 112 | } |
| 113 | |
| 114 | Vector4u::Vector4u(unsigned int x, unsigned int y, unsigned int z, unsigned int w) |
| 115 | { |
| 116 | this->x = UInt4(x); |
| 117 | this->y = UInt4(y); |
| 118 | this->z = UInt4(z); |
| 119 | this->w = UInt4(w); |
| 120 | } |
| 121 | |
| 122 | Vector4u::Vector4u(const Vector4u &rhs) |
| 123 | { |
| 124 | x = rhs.x; |
| 125 | y = rhs.y; |
| 126 | z = rhs.z; |
| 127 | w = rhs.w; |
| 128 | } |
| 129 | |
| 130 | Vector4u &Vector4u::operator=(const Vector4u &rhs) |
| 131 | { |
| 132 | x = rhs.x; |
| 133 | y = rhs.y; |
| 134 | z = rhs.z; |
| 135 | w = rhs.w; |
| 136 | |
| 137 | return *this; |
| 138 | } |
| 139 | |
| 140 | UInt4 &Vector4u::operator[](int i) |
| 141 | { |
| 142 | switch(i) |
| 143 | { |
| 144 | case 0: return x; |
| 145 | case 1: return y; |
| 146 | case 2: return z; |
| 147 | case 3: return w; |
| 148 | } |
| 149 | |
| 150 | return x; |
| 151 | } |
| 152 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 153 | Vector4f::Vector4f() |
| 154 | { |
| 155 | } |
| 156 | |
| 157 | Vector4f::Vector4f(float x, float y, float z, float w) |
| 158 | { |
| 159 | this->x = Float4(x); |
| 160 | this->y = Float4(y); |
| 161 | this->z = Float4(z); |
| 162 | this->w = Float4(w); |
| 163 | } |
| 164 | |
| 165 | Vector4f::Vector4f(const Vector4f &rhs) |
| 166 | { |
| 167 | x = rhs.x; |
| 168 | y = rhs.y; |
| 169 | z = rhs.z; |
| 170 | w = rhs.w; |
| 171 | } |
| 172 | |
| 173 | Vector4f &Vector4f::operator=(const Vector4f &rhs) |
| 174 | { |
| 175 | x = rhs.x; |
| 176 | y = rhs.y; |
| 177 | z = rhs.z; |
| 178 | w = rhs.w; |
| 179 | |
| 180 | return *this; |
| 181 | } |
| 182 | |
| 183 | Float4 &Vector4f::operator[](int i) |
| 184 | { |
| 185 | switch(i) |
| 186 | { |
| 187 | case 0: return x; |
| 188 | case 1: return y; |
| 189 | case 2: return z; |
| 190 | case 3: return w; |
| 191 | } |
| 192 | |
| 193 | return x; |
| 194 | } |
| 195 | |
| 196 | Float4 exponential2(RValue<Float4> x, bool pp) |
| 197 | { |
| 198 | Float4 x0; |
| 199 | Float4 x1; |
| 200 | Int4 x2; |
| 201 | |
| 202 | x0 = x; |
| 203 | |
| 204 | x0 = Min(x0, As<Float4>(Int4(0x43010000))); // 129.00000e+0f |
| 205 | x0 = Max(x0, As<Float4>(Int4(0xC2FDFFFF))); // -126.99999e+0f |
| 206 | x1 = x0; |
| 207 | x1 -= Float4(0.5f); |
| 208 | x2 = RoundInt(x1); |
| 209 | x1 = Float4(x2); |
| 210 | x2 += Int4(0x0000007F); // 127 |
| 211 | x2 = x2 << 23; |
| 212 | x0 -= x1; |
| 213 | x1 = As<Float4>(Int4(0x3AF61905)); // 1.8775767e-3f |
| 214 | x1 *= x0; |
| 215 | x1 += As<Float4>(Int4(0x3C134806)); // 8.9893397e-3f |
| 216 | x1 *= x0; |
| 217 | x1 += As<Float4>(Int4(0x3D64AA23)); // 5.5826318e-2f |
| 218 | x1 *= x0; |
| 219 | x1 += As<Float4>(Int4(0x3E75EAD4)); // 2.4015361e-1f |
| 220 | x1 *= x0; |
| 221 | x1 += As<Float4>(Int4(0x3F31727B)); // 6.9315308e-1f |
| 222 | x1 *= x0; |
| 223 | x1 += As<Float4>(Int4(0x3F7FFFFF)); // 9.9999994e-1f |
| 224 | x1 *= As<Float4>(x2); |
| 225 | |
| 226 | return x1; |
| 227 | } |
| 228 | |
| 229 | Float4 logarithm2(RValue<Float4> x, bool absolute, bool pp) |
| 230 | { |
| 231 | Float4 x0; |
| 232 | Float4 x1; |
| 233 | Float4 x2; |
| 234 | Float4 x3; |
| 235 | |
| 236 | x0 = x; |
| 237 | |
| 238 | x1 = As<Float4>(As<Int4>(x0) & Int4(0x7F800000)); |
| 239 | x1 = As<Float4>(As<UInt4>(x1) >> 8); |
| 240 | x1 = As<Float4>(As<Int4>(x1) | As<Int4>(Float4(1.0f))); |
| 241 | x1 = (x1 - Float4(1.4960938f)) * Float4(256.0f); // FIXME: (x1 - 1.4960938f) * 256.0f; |
| 242 | x0 = As<Float4>((As<Int4>(x0) & Int4(0x007FFFFF)) | As<Int4>(Float4(1.0f))); |
| 243 | |
| 244 | x2 = (Float4(9.5428179e-2f) * x0 + Float4(4.7779095e-1f)) * x0 + Float4(1.9782813e-1f); |
| 245 | x3 = ((Float4(1.6618466e-2f) * x0 + Float4(2.0350508e-1f)) * x0 + Float4(2.7382900e-1f)) * x0 + Float4(4.0496687e-2f); |
| 246 | x2 /= x3; |
| 247 | |
| 248 | x1 += (x0 - Float4(1.0f)) * x2; |
| 249 | |
| 250 | return x1; |
| 251 | } |
| 252 | |
| 253 | Float4 exponential(RValue<Float4> x, bool pp) |
| 254 | { |
| 255 | // FIXME: Propagate the constant |
| 256 | return exponential2(Float4(1.44269541f) * x, pp); // 1/ln(2) |
| 257 | } |
| 258 | |
| 259 | Float4 logarithm(RValue<Float4> x, bool absolute, bool pp) |
| 260 | { |
| 261 | // FIXME: Propagate the constant |
| 262 | return Float4(6.93147181e-1f) * logarithm2(x, absolute, pp); // ln(2) |
| 263 | } |
| 264 | |
| 265 | Float4 power(RValue<Float4> x, RValue<Float4> y, bool pp) |
| 266 | { |
| 267 | Float4 log = logarithm2(x, true, pp); |
| 268 | log *= y; |
| 269 | return exponential2(log, pp); |
| 270 | } |
| 271 | |
| 272 | Float4 reciprocal(RValue<Float4> x, bool pp, bool finite) |
| 273 | { |
| 274 | Float4 rcp; |
| 275 | |
| 276 | if(!pp && rcpPrecision >= WHQL) |
| 277 | { |
| 278 | rcp = Float4(1.0f) / x; |
| 279 | } |
| 280 | else |
| 281 | { |
| 282 | rcp = Rcp_pp(x); |
| 283 | |
| 284 | if(!pp) |
| 285 | { |
| 286 | rcp = (rcp + rcp) - (x * rcp * rcp); |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | if(finite) |
| 291 | { |
| 292 | int big = 0x7F7FFFFF; |
| 293 | rcp = Min(rcp, Float4((float&)big)); |
| 294 | } |
| 295 | |
| 296 | return rcp; |
| 297 | } |
| 298 | |
| 299 | Float4 reciprocalSquareRoot(RValue<Float4> x, bool absolute, bool pp) |
| 300 | { |
| 301 | Float4 abs = x; |
| 302 | |
| 303 | if(absolute) |
| 304 | { |
| 305 | abs = Abs(abs); |
| 306 | } |
| 307 | |
| 308 | Float4 rsq; |
| 309 | |
| 310 | if(!pp && rsqPrecision >= IEEE) |
| 311 | { |
| 312 | rsq = Float4(1.0f) / Sqrt(abs); |
| 313 | } |
| 314 | else |
| 315 | { |
| 316 | rsq = RcpSqrt_pp(abs); |
| 317 | |
| 318 | if(!pp) |
| 319 | { |
| 320 | rsq = rsq * (Float4(3.0f) - rsq * rsq * abs) * Float4(0.5f); |
| 321 | } |
| 322 | } |
| 323 | |
| 324 | int big = 0x7F7FFFFF; |
| 325 | rsq = Min(rsq, Float4((float&)big)); |
| 326 | |
| 327 | return rsq; |
| 328 | } |
| 329 | |
| 330 | Float4 modulo(RValue<Float4> x, RValue<Float4> y) |
| 331 | { |
| 332 | return x - y * Floor(x / y); |
| 333 | } |
| 334 | |
| 335 | Float4 sine_pi(RValue<Float4> x, bool pp) |
| 336 | { |
| 337 | const Float4 A = Float4(-4.05284734e-1f); // -4/pi^2 |
| 338 | const Float4 B = Float4(1.27323954e+0f); // 4/pi |
| 339 | const Float4 C = Float4(7.75160950e-1f); |
| 340 | const Float4 D = Float4(2.24839049e-1f); |
| 341 | |
| 342 | // Parabola approximating sine |
| 343 | Float4 sin = x * (Abs(x) * A + B); |
| 344 | |
| 345 | // Improve precision from 0.06 to 0.001 |
| 346 | if(true) |
| 347 | { |
| 348 | sin = sin * (Abs(sin) * D + C); |
| 349 | } |
| 350 | |
| 351 | return sin; |
| 352 | } |
| 353 | |
| 354 | Float4 cosine_pi(RValue<Float4> x, bool pp) |
| 355 | { |
| 356 | // cos(x) = sin(x + pi/2) |
| 357 | Float4 y = x + Float4(1.57079632e+0f); |
| 358 | |
| 359 | // Wrap around |
| 360 | y -= As<Float4>(CmpNLT(y, Float4(3.14159265e+0f)) & As<Int4>(Float4(6.28318530e+0f))); |
| 361 | |
| 362 | return sine_pi(y, pp); |
| 363 | } |
| 364 | |
| 365 | Float4 sine(RValue<Float4> x, bool pp) |
| 366 | { |
| 367 | // Reduce to [-0.5, 0.5] range |
| 368 | Float4 y = x * Float4(1.59154943e-1f); // 1/2pi |
| 369 | y = y - Round(y); |
| 370 | |
| 371 | const Float4 A = Float4(-16.0f); |
| 372 | const Float4 B = Float4(8.0f); |
| 373 | const Float4 C = Float4(7.75160950e-1f); |
| 374 | const Float4 D = Float4(2.24839049e-1f); |
| 375 | |
| 376 | // Parabola approximating sine |
| 377 | Float4 sin = y * (Abs(y) * A + B); |
| 378 | |
| 379 | // Improve precision from 0.06 to 0.001 |
| 380 | if(true) |
| 381 | { |
| 382 | sin = sin * (Abs(sin) * D + C); |
| 383 | } |
| 384 | |
| 385 | return sin; |
| 386 | } |
| 387 | |
| 388 | Float4 cosine(RValue<Float4> x, bool pp) |
| 389 | { |
| 390 | // cos(x) = sin(x + pi/2) |
| 391 | Float4 y = x + Float4(1.57079632e+0f); |
| 392 | return sine(y, pp); |
| 393 | } |
| 394 | |
| 395 | Float4 tangent(RValue<Float4> x, bool pp) |
| 396 | { |
| 397 | return sine(x, pp) / cosine(x, pp); |
| 398 | } |
| 399 | |
| 400 | Float4 arccos(RValue<Float4> x, bool pp) |
| 401 | { |
| 402 | // pi/2 - arcsin(x) |
| 403 | return Float4(1.57079632e+0f) - arcsin(x); |
| 404 | } |
| 405 | |
| 406 | Float4 arcsin(RValue<Float4> x, bool pp) |
| 407 | { |
| 408 | // x*(pi/2-sqrt(1-x*x)*pi/5) |
| 409 | return x * (Float4(1.57079632e+0f) - Sqrt(Float4(1.0f) - x*x) * Float4(6.28318531e-1f)); |
| 410 | } |
| 411 | |
| 412 | Float4 arctan(RValue<Float4> x, bool pp) |
| 413 | { |
| 414 | Int4 O = CmpNLT(Abs(x), Float4(1.0f)); |
| 415 | Float4 y = As<Float4>(O & As<Int4>(Float4(1.0f) / x) | ~O & As<Int4>(x)); // FIXME: Vector select |
| 416 | |
| 417 | // Approximation of atan in [-1..1] |
| 418 | Float4 theta = y * (Float4(-0.27f) * Abs(y) + Float4(1.05539816f)); |
| 419 | |
| 420 | // +/-pi/2 depending on sign of x |
| 421 | Float4 sgnPi_2 = As<Float4>(As<Int4>(Float4(1.57079632e+0f)) ^ (As<Int4>(x) & Int4(0x80000000))); |
| 422 | |
| 423 | theta = As<Float4>(O & As<Int4>(sgnPi_2 - theta) | ~O & As<Int4>(theta)); // FIXME: Vector select |
| 424 | |
| 425 | return theta; |
| 426 | } |
| 427 | |
| 428 | Float4 arctan(RValue<Float4> y, RValue<Float4> x, bool pp) |
| 429 | { |
| 430 | // Rotate to upper semicircle when in lower semicircle |
| 431 | Int4 S = CmpLT(y, Float4(0.0f)); |
| 432 | Float4 theta = As<Float4>(S & As<Int4>(Float4(-3.14159265e+0f))); // -pi |
| 433 | Float4 x0 = As<Float4>((As<Int4>(y) & Int4(0x80000000)) ^ As<Int4>(x)); |
| 434 | Float4 y0 = Abs(y); |
| 435 | |
| 436 | // Rotate to right quadrant when in left quadrant |
| 437 | Int4 Q = CmpLT(x0, Float4(0.0f)); |
| 438 | theta += As<Float4>(Q & As<Int4>(Float4(1.57079632e+0f))); // pi/2 |
| 439 | Float4 x1 = As<Float4>(Q & As<Int4>(y0) | ~Q & As<Int4>(x0)); // FIXME: Vector select |
| 440 | Float4 y1 = As<Float4>(Q & As<Int4>(-x0) | ~Q & As<Int4>(y0)); // FIXME: Vector select |
| 441 | |
| 442 | // Rotate to first octant when in second octant |
| 443 | Int4 O = CmpNLT(y1, x1); |
| 444 | theta += As<Float4>(O & As<Int4>(Float4(7.85398163e-1f))); // pi/4 |
| 445 | 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 |
| 446 | Float4 y2 = As<Float4>(O & As<Int4>(Float4(7.07106781e-1f) * y1 - Float4(7.07106781e-1f) * x1) | ~O & As<Int4>(y1)); // FIXME: Vector select |
| 447 | |
| 448 | // Approximation of atan in [0..1] |
| 449 | Float4 y_x = y2 / x2; |
| 450 | theta += y_x * (Float4(-0.27f) * y_x + Float4(1.05539816f)); |
| 451 | |
| 452 | return theta; |
| 453 | } |
| 454 | |
Alexis Hetu | 8b5f3ef | 2015-04-16 11:33:34 -0400 | [diff] [blame^] | 455 | Float4 sineh(RValue<Float4> x, bool pp) |
| 456 | { |
| 457 | return (exponential(x, pp) - exponential(-x, pp)) * Float4(0.5f); |
| 458 | } |
| 459 | |
| 460 | Float4 cosineh(RValue<Float4> x, bool pp) |
| 461 | { |
| 462 | return (exponential(x, pp) + exponential(-x, pp)) * Float4(0.5f); |
| 463 | } |
| 464 | |
| 465 | Float4 tangenth(RValue<Float4> x, bool pp) |
| 466 | { |
| 467 | Float4 e_x = exponential(x, pp); |
| 468 | Float4 e_minus_x = exponential(-x, pp); |
| 469 | return (e_x - e_minus_x) / (e_x + e_minus_x); |
| 470 | } |
| 471 | |
| 472 | Float4 arccosh(RValue<Float4> x, bool pp) |
| 473 | { |
| 474 | return logarithm(x + Sqrt(x + Float4(1.0f)) * Sqrt(x - Float4(1.0f)), pp); |
| 475 | } |
| 476 | |
| 477 | Float4 arcsinh(RValue<Float4> x, bool pp) |
| 478 | { |
| 479 | return logarithm(x + Sqrt(x * x + Float4(1.0f)), pp); |
| 480 | } |
| 481 | |
| 482 | Float4 arctanh(RValue<Float4> x, bool pp) |
| 483 | { |
| 484 | return logarithm((Float4(1.0f) + x) / (Float4(1.0f) - x), pp) * Float4(0.5f); |
| 485 | } |
| 486 | |
| 487 | Int4 floatBitsToInt(RValue<Float4> x) |
| 488 | { |
| 489 | return As<Int4>(x); |
| 490 | } |
| 491 | |
| 492 | UInt4 floatBitsToUInt(RValue<Float4> x) |
| 493 | { |
| 494 | return As<UInt4>(x); |
| 495 | } |
| 496 | |
| 497 | Float4 intBitsToFloat(RValue<Int4> x) |
| 498 | { |
| 499 | return As<Float4>(x); |
| 500 | } |
| 501 | |
| 502 | Float4 uintBitsToFloat(RValue<UInt4> x) |
| 503 | { |
| 504 | return As<Float4>(x); |
| 505 | } |
| 506 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 507 | Float4 dot2(Vector4f &v0, Vector4f &v1) |
| 508 | { |
| 509 | return v0.x * v1.x + v0.y * v1.y; |
| 510 | } |
| 511 | |
| 512 | Float4 dot3(Vector4f &v0, Vector4f &v1) |
| 513 | { |
| 514 | return v0.x * v1.x + v0.y * v1.y + v0.z * v1.z; |
| 515 | } |
| 516 | |
| 517 | Float4 dot4(Vector4f &v0, Vector4f &v1) |
| 518 | { |
| 519 | return v0.x * v1.x + v0.y * v1.y + v0.z * v1.z + v0.w * v1.w; |
| 520 | } |
| 521 | |
| 522 | void transpose4x4(Short4 &row0, Short4 &row1, Short4 &row2, Short4 &row3) |
| 523 | { |
| 524 | Int2 tmp0 = UnpackHigh(row0, row1); |
| 525 | Int2 tmp1 = UnpackHigh(row2, row3); |
| 526 | Int2 tmp2 = UnpackLow(row0, row1); |
| 527 | Int2 tmp3 = UnpackLow(row2, row3); |
| 528 | |
| 529 | row0 = As<Short4>(UnpackLow(tmp2, tmp3)); |
| 530 | row1 = As<Short4>(UnpackHigh(tmp2, tmp3)); |
| 531 | row2 = As<Short4>(UnpackLow(tmp0, tmp1)); |
| 532 | row3 = As<Short4>(UnpackHigh(tmp0, tmp1)); |
| 533 | } |
| 534 | |
| 535 | void transpose4x4(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3) |
| 536 | { |
| 537 | Float4 tmp0 = UnpackLow(row0, row1); |
| 538 | Float4 tmp1 = UnpackLow(row2, row3); |
| 539 | Float4 tmp2 = UnpackHigh(row0, row1); |
| 540 | Float4 tmp3 = UnpackHigh(row2, row3); |
| 541 | |
| 542 | row0 = Float4(tmp0.xy, tmp1.xy); |
| 543 | row1 = Float4(tmp0.zw, tmp1.zw); |
| 544 | row2 = Float4(tmp2.xy, tmp3.xy); |
| 545 | row3 = Float4(tmp2.zw, tmp3.zw); |
| 546 | } |
| 547 | |
| 548 | void transpose4x3(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3) |
| 549 | { |
| 550 | Float4 tmp0 = UnpackLow(row0, row1); |
| 551 | Float4 tmp1 = UnpackLow(row2, row3); |
| 552 | Float4 tmp2 = UnpackHigh(row0, row1); |
| 553 | Float4 tmp3 = UnpackHigh(row2, row3); |
| 554 | |
| 555 | row0 = Float4(tmp0.xy, tmp1.xy); |
| 556 | row1 = Float4(tmp0.zw, tmp1.zw); |
| 557 | row2 = Float4(tmp2.xy, tmp3.xy); |
| 558 | } |
| 559 | |
| 560 | void transpose4x2(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3) |
| 561 | { |
| 562 | Float4 tmp0 = UnpackLow(row0, row1); |
| 563 | Float4 tmp1 = UnpackLow(row2, row3); |
| 564 | |
| 565 | row0 = Float4(tmp0.xy, tmp1.xy); |
| 566 | row1 = Float4(tmp0.zw, tmp1.zw); |
| 567 | } |
| 568 | |
| 569 | void transpose4x1(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3) |
| 570 | { |
| 571 | Float4 tmp0 = UnpackLow(row0, row1); |
| 572 | Float4 tmp1 = UnpackLow(row2, row3); |
| 573 | |
| 574 | row0 = Float4(tmp0.xy, tmp1.xy); |
| 575 | } |
| 576 | |
| 577 | void transpose2x4(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3) |
| 578 | { |
| 579 | row0 = UnpackLow(row0, row1); |
| 580 | row1 = Float4(row0.zw, row1.zw); |
| 581 | row2 = UnpackHigh(row0, row1); |
| 582 | row3 = Float4(row2.zw, row3.zw); |
| 583 | } |
| 584 | |
| 585 | void transpose2x4h(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3) |
| 586 | { |
| 587 | row0 = UnpackLow(row2, row3); |
| 588 | row1 = Float4(row0.zw, row1.zw); |
| 589 | row2 = UnpackHigh(row2, row3); |
| 590 | row3 = Float4(row2.zw, row3.zw); |
| 591 | } |
| 592 | |
| 593 | void transpose4xN(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3, int N) |
| 594 | { |
| 595 | switch(N) |
| 596 | { |
| 597 | case 1: transpose4x1(row0, row1, row2, row3); break; |
| 598 | case 2: transpose4x2(row0, row1, row2, row3); break; |
| 599 | case 3: transpose4x3(row0, row1, row2, row3); break; |
| 600 | case 4: transpose4x4(row0, row1, row2, row3); break; |
| 601 | } |
| 602 | } |
| 603 | |
| 604 | void ShaderCore::mov(Vector4f &dst, Vector4f &src, bool floorToInteger) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 605 | { |
| 606 | if(floorToInteger) |
| 607 | { |
| 608 | dst.x = Floor(src.x); |
| 609 | } |
| 610 | else |
| 611 | { |
| 612 | dst = src; |
| 613 | } |
| 614 | } |
| 615 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 616 | void ShaderCore::f2b(Vector4f &dst, Vector4f &src) |
| 617 | { |
| 618 | dst.x = As<Float4>(CmpNEQ(src.x, Float4(0.0f))); |
| 619 | dst.y = As<Float4>(CmpNEQ(src.y, Float4(0.0f))); |
| 620 | dst.z = As<Float4>(CmpNEQ(src.z, Float4(0.0f))); |
| 621 | dst.w = As<Float4>(CmpNEQ(src.w, Float4(0.0f))); |
| 622 | } |
| 623 | |
| 624 | void ShaderCore::b2f(Vector4f &dst, Vector4f &src) |
| 625 | { |
| 626 | dst.x = As<Float4>(As<Int4>(src.x) & As<Int4>(Float4(1.0f))); |
| 627 | dst.y = As<Float4>(As<Int4>(src.y) & As<Int4>(Float4(1.0f))); |
| 628 | dst.z = As<Float4>(As<Int4>(src.z) & As<Int4>(Float4(1.0f))); |
| 629 | dst.w = As<Float4>(As<Int4>(src.w) & As<Int4>(Float4(1.0f))); |
| 630 | } |
| 631 | |
| 632 | void ShaderCore::add(Vector4f &dst, Vector4f &src0, Vector4f &src1) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 633 | { |
| 634 | dst.x = src0.x + src1.x; |
| 635 | dst.y = src0.y + src1.y; |
| 636 | dst.z = src0.z + src1.z; |
| 637 | dst.w = src0.w + src1.w; |
| 638 | } |
| 639 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 640 | void ShaderCore::sub(Vector4f &dst, Vector4f &src0, Vector4f &src1) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 641 | { |
| 642 | dst.x = src0.x - src1.x; |
| 643 | dst.y = src0.y - src1.y; |
| 644 | dst.z = src0.z - src1.z; |
| 645 | dst.w = src0.w - src1.w; |
| 646 | } |
| 647 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 648 | void ShaderCore::mad(Vector4f &dst, Vector4f &src0, Vector4f &src1, Vector4f &src2) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 649 | { |
| 650 | dst.x = src0.x * src1.x + src2.x; |
| 651 | dst.y = src0.y * src1.y + src2.y; |
| 652 | dst.z = src0.z * src1.z + src2.z; |
| 653 | dst.w = src0.w * src1.w + src2.w; |
| 654 | } |
| 655 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 656 | void ShaderCore::mul(Vector4f &dst, Vector4f &src0, Vector4f &src1) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 657 | { |
| 658 | dst.x = src0.x * src1.x; |
| 659 | dst.y = src0.y * src1.y; |
| 660 | dst.z = src0.z * src1.z; |
| 661 | dst.w = src0.w * src1.w; |
| 662 | } |
| 663 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 664 | void ShaderCore::rcpx(Vector4f &dst, Vector4f &src, bool pp) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 665 | { |
| 666 | Float4 rcp = reciprocal(src.x, pp, true); |
| 667 | |
| 668 | dst.x = rcp; |
| 669 | dst.y = rcp; |
| 670 | dst.z = rcp; |
| 671 | dst.w = rcp; |
| 672 | } |
| 673 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 674 | void ShaderCore::div(Vector4f &dst, Vector4f &src0, Vector4f &src1) |
| 675 | { |
| 676 | dst.x = src0.x / src1.x; |
| 677 | dst.y = src0.y / src1.y; |
| 678 | dst.z = src0.z / src1.z; |
| 679 | dst.w = src0.w / src1.w; |
| 680 | } |
| 681 | |
| 682 | void ShaderCore::mod(Vector4f &dst, Vector4f &src0, Vector4f &src1) |
| 683 | { |
| 684 | dst.x = modulo(src0.x, src1.x); |
| 685 | dst.y = modulo(src0.y, src1.y); |
| 686 | dst.z = modulo(src0.z, src1.z); |
| 687 | dst.w = modulo(src0.w, src1.w); |
| 688 | } |
| 689 | |
| 690 | void ShaderCore::rsqx(Vector4f &dst, Vector4f &src, bool pp) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 691 | { |
| 692 | Float4 rsq = reciprocalSquareRoot(src.x, true, pp); |
| 693 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 694 | dst.x = rsq; |
| 695 | dst.y = rsq; |
| 696 | dst.z = rsq; |
| 697 | dst.w = rsq; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 698 | } |
| 699 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 700 | void ShaderCore::sqrt(Vector4f &dst, Vector4f &src, bool pp) |
| 701 | { |
| 702 | dst.x = Sqrt(src.x); |
| 703 | dst.y = Sqrt(src.y); |
| 704 | dst.z = Sqrt(src.z); |
| 705 | dst.w = Sqrt(src.w); |
| 706 | } |
| 707 | |
| 708 | void ShaderCore::rsq(Vector4f &dst, Vector4f &src, bool pp) |
| 709 | { |
| 710 | dst.x = reciprocalSquareRoot(src.x, false, pp); |
| 711 | dst.y = reciprocalSquareRoot(src.y, false, pp); |
| 712 | dst.z = reciprocalSquareRoot(src.z, false, pp); |
| 713 | dst.w = reciprocalSquareRoot(src.w, false, pp); |
| 714 | } |
| 715 | |
| 716 | void ShaderCore::len2(Float4 &dst, Vector4f &src, bool pp) |
| 717 | { |
| 718 | dst = Sqrt(dot2(src, src)); |
| 719 | } |
| 720 | |
| 721 | void ShaderCore::len3(Float4 &dst, Vector4f &src, bool pp) |
| 722 | { |
| 723 | dst = Sqrt(dot3(src, src)); |
| 724 | } |
| 725 | |
| 726 | void ShaderCore::len4(Float4 &dst, Vector4f &src, bool pp) |
| 727 | { |
| 728 | dst = Sqrt(dot4(src, src)); |
| 729 | } |
| 730 | |
| 731 | void ShaderCore::dist1(Float4 &dst, Vector4f &src0, Vector4f &src1, bool pp) |
| 732 | { |
| 733 | dst = Abs(src0.x - src1.x); |
| 734 | } |
| 735 | |
| 736 | void ShaderCore::dist2(Float4 &dst, Vector4f &src0, Vector4f &src1, bool pp) |
| 737 | { |
| 738 | Float4 dx = src0.x - src1.x; |
| 739 | Float4 dy = src0.y - src1.y; |
| 740 | Float4 dot2 = dx * dx + dy * dy; |
| 741 | dst = Sqrt(dot2); |
| 742 | } |
| 743 | |
| 744 | void ShaderCore::dist3(Float4 &dst, Vector4f &src0, Vector4f &src1, bool pp) |
| 745 | { |
| 746 | Float4 dx = src0.x - src1.x; |
| 747 | Float4 dy = src0.y - src1.y; |
| 748 | Float4 dz = src0.z - src1.z; |
| 749 | Float4 dot3 = dx * dx + dy * dy + dz * dz; |
| 750 | dst = Sqrt(dot3); |
| 751 | } |
| 752 | |
| 753 | void ShaderCore::dist4(Float4 &dst, Vector4f &src0, Vector4f &src1, bool pp) |
| 754 | { |
| 755 | Float4 dx = src0.x - src1.x; |
| 756 | Float4 dy = src0.y - src1.y; |
| 757 | Float4 dz = src0.z - src1.z; |
| 758 | Float4 dw = src0.w - src1.w; |
| 759 | Float4 dot4 = dx * dx + dy * dy + dz * dz + dw * dw; |
| 760 | dst = Sqrt(dot4); |
| 761 | } |
| 762 | |
| 763 | void ShaderCore::dp1(Vector4f &dst, Vector4f &src0, Vector4f &src1) |
| 764 | { |
| 765 | Float4 t = src0.x * src1.x; |
| 766 | |
| 767 | dst.x = t; |
| 768 | dst.y = t; |
| 769 | dst.z = t; |
| 770 | dst.w = t; |
| 771 | } |
| 772 | |
| 773 | void ShaderCore::dp2(Vector4f &dst, Vector4f &src0, Vector4f &src1) |
| 774 | { |
| 775 | Float4 t = dot2(src0, src1); |
| 776 | |
| 777 | dst.x = t; |
| 778 | dst.y = t; |
| 779 | dst.z = t; |
| 780 | dst.w = t; |
| 781 | } |
| 782 | |
| 783 | void ShaderCore::dp2add(Vector4f &dst, Vector4f &src0, Vector4f &src1, Vector4f &src2) |
| 784 | { |
| 785 | Float4 t = dot2(src0, src1) + src2.x; |
| 786 | |
| 787 | dst.x = t; |
| 788 | dst.y = t; |
| 789 | dst.z = t; |
| 790 | dst.w = t; |
| 791 | } |
| 792 | |
| 793 | void ShaderCore::dp3(Vector4f &dst, Vector4f &src0, Vector4f &src1) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 794 | { |
| 795 | Float4 dot = dot3(src0, src1); |
| 796 | |
| 797 | dst.x = dot; |
| 798 | dst.y = dot; |
| 799 | dst.z = dot; |
| 800 | dst.w = dot; |
| 801 | } |
| 802 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 803 | void ShaderCore::dp4(Vector4f &dst, Vector4f &src0, Vector4f &src1) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 804 | { |
| 805 | Float4 dot = dot4(src0, src1); |
| 806 | |
| 807 | dst.x = dot; |
| 808 | dst.y = dot; |
| 809 | dst.z = dot; |
| 810 | dst.w = dot; |
| 811 | } |
| 812 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 813 | void ShaderCore::min(Vector4f &dst, Vector4f &src0, Vector4f &src1) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 814 | { |
| 815 | dst.x = Min(src0.x, src1.x); |
| 816 | dst.y = Min(src0.y, src1.y); |
| 817 | dst.z = Min(src0.z, src1.z); |
| 818 | dst.w = Min(src0.w, src1.w); |
| 819 | } |
| 820 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 821 | void ShaderCore::max(Vector4f &dst, Vector4f &src0, Vector4f &src1) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 822 | { |
| 823 | dst.x = Max(src0.x, src1.x); |
| 824 | dst.y = Max(src0.y, src1.y); |
| 825 | dst.z = Max(src0.z, src1.z); |
| 826 | dst.w = Max(src0.w, src1.w); |
| 827 | } |
| 828 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 829 | void ShaderCore::slt(Vector4f &dst, Vector4f &src0, Vector4f &src1) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 830 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 831 | dst.x = As<Float4>(As<Int4>(CmpLT(src0.x, src1.x)) & As<Int4>(Float4(1.0f))); |
| 832 | dst.y = As<Float4>(As<Int4>(CmpLT(src0.y, src1.y)) & As<Int4>(Float4(1.0f))); |
| 833 | dst.z = As<Float4>(As<Int4>(CmpLT(src0.z, src1.z)) & As<Int4>(Float4(1.0f))); |
| 834 | 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] | 835 | } |
| 836 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 837 | void ShaderCore::step(Vector4f &dst, Vector4f &edge, Vector4f &x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 838 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 839 | dst.x = As<Float4>(CmpNLT(x.x, edge.x) & As<Int4>(Float4(1.0f))); |
| 840 | dst.y = As<Float4>(CmpNLT(x.y, edge.y) & As<Int4>(Float4(1.0f))); |
| 841 | dst.z = As<Float4>(CmpNLT(x.z, edge.z) & As<Int4>(Float4(1.0f))); |
| 842 | 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] | 843 | } |
| 844 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 845 | void ShaderCore::exp2x(Vector4f &dst, Vector4f &src, bool pp) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 846 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 847 | Float4 exp = exponential2(src.x, pp); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 848 | |
| 849 | dst.x = exp; |
| 850 | dst.y = exp; |
| 851 | dst.z = exp; |
| 852 | dst.w = exp; |
| 853 | } |
| 854 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 855 | void ShaderCore::exp2(Vector4f &dst, Vector4f &src, bool pp) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 856 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 857 | dst.x = exponential2(src.x, pp); |
| 858 | dst.y = exponential2(src.y, pp); |
| 859 | dst.z = exponential2(src.z, pp); |
| 860 | dst.w = exponential2(src.w, pp); |
| 861 | } |
| 862 | |
| 863 | void ShaderCore::exp(Vector4f &dst, Vector4f &src, bool pp) |
| 864 | { |
| 865 | dst.x = exponential(src.x, pp); |
| 866 | dst.y = exponential(src.y, pp); |
| 867 | dst.z = exponential(src.z, pp); |
| 868 | dst.w = exponential(src.w, pp); |
| 869 | } |
| 870 | |
| 871 | void ShaderCore::log2x(Vector4f &dst, Vector4f &src, bool pp) |
| 872 | { |
| 873 | Float4 log = logarithm2(src.x, true, pp); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 874 | |
| 875 | dst.x = log; |
| 876 | dst.y = log; |
| 877 | dst.z = log; |
| 878 | dst.w = log; |
| 879 | } |
| 880 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 881 | void ShaderCore::log2(Vector4f &dst, Vector4f &src, bool pp) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 882 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 883 | dst.x = logarithm2(src.x, pp); |
| 884 | dst.y = logarithm2(src.y, pp); |
| 885 | dst.z = logarithm2(src.z, pp); |
| 886 | dst.w = logarithm2(src.w, pp); |
| 887 | } |
| 888 | |
| 889 | void ShaderCore::log(Vector4f &dst, Vector4f &src, bool pp) |
| 890 | { |
| 891 | dst.x = logarithm(src.x, false, pp); |
| 892 | dst.y = logarithm(src.y, false, pp); |
| 893 | dst.z = logarithm(src.z, false, pp); |
| 894 | dst.w = logarithm(src.w, false, pp); |
| 895 | } |
| 896 | |
| 897 | void ShaderCore::lit(Vector4f &dst, Vector4f &src) |
| 898 | { |
| 899 | dst.x = Float4(1.0f); |
| 900 | dst.y = Max(src.x, Float4(0.0f)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 901 | |
| 902 | Float4 pow; |
| 903 | |
| 904 | pow = src.w; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 905 | pow = Min(pow, Float4(127.9961f)); |
| 906 | pow = Max(pow, Float4(-127.9961f)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 907 | |
| 908 | dst.z = power(src.y, pow); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 909 | dst.z = As<Float4>(As<Int4>(dst.z) & CmpNLT(src.x, Float4(0.0f))); |
| 910 | 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] | 911 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 912 | dst.w = Float4(1.0f); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 913 | } |
| 914 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 915 | void ShaderCore::att(Vector4f &dst, Vector4f &src0, Vector4f &src1) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 916 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 917 | // 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] | 918 | dst.x = 1; |
| 919 | dst.y = src0.y * src1.y; |
| 920 | dst.z = src0.z; |
| 921 | dst.w = src1.w; |
| 922 | } |
| 923 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 924 | void ShaderCore::lrp(Vector4f &dst, Vector4f &src0, Vector4f &src1, Vector4f &src2) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 925 | { |
| 926 | dst.x = src0.x * (src1.x - src2.x) + src2.x; |
| 927 | dst.y = src0.y * (src1.y - src2.y) + src2.y; |
| 928 | dst.z = src0.z * (src1.z - src2.z) + src2.z; |
| 929 | dst.w = src0.w * (src1.w - src2.w) + src2.w; |
| 930 | } |
| 931 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 932 | void ShaderCore::smooth(Vector4f &dst, Vector4f &edge0, Vector4f &edge1, Vector4f &x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 933 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 934 | 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); |
| 935 | 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); |
| 936 | 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); |
| 937 | 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] | 938 | } |
| 939 | |
Alexis Hetu | 8b5f3ef | 2015-04-16 11:33:34 -0400 | [diff] [blame^] | 940 | void ShaderCore::floatBitsToInt(Vector4i &dst, Vector4f &src) |
| 941 | { |
| 942 | dst.x = sw::floatBitsToInt(src.x); |
| 943 | dst.y = sw::floatBitsToInt(src.y); |
| 944 | dst.z = sw::floatBitsToInt(src.z); |
| 945 | dst.w = sw::floatBitsToInt(src.w); |
| 946 | } |
| 947 | |
| 948 | void ShaderCore::floatBitsToUInt(Vector4u &dst, Vector4f &src) |
| 949 | { |
| 950 | dst.x = sw::floatBitsToUInt(src.x); |
| 951 | dst.y = sw::floatBitsToUInt(src.y); |
| 952 | dst.z = sw::floatBitsToUInt(src.z); |
| 953 | dst.w = sw::floatBitsToUInt(src.w); |
| 954 | } |
| 955 | |
| 956 | void ShaderCore::intBitsToFloat(Vector4f &dst, Vector4i &src) |
| 957 | { |
| 958 | dst.x = sw::intBitsToFloat(src.x); |
| 959 | dst.y = sw::intBitsToFloat(src.y); |
| 960 | dst.z = sw::intBitsToFloat(src.z); |
| 961 | dst.w = sw::intBitsToFloat(src.w); |
| 962 | } |
| 963 | |
| 964 | void ShaderCore::uintBitsToFloat(Vector4f &dst, Vector4u &src) |
| 965 | { |
| 966 | dst.x = sw::uintBitsToFloat(src.x); |
| 967 | dst.y = sw::uintBitsToFloat(src.y); |
| 968 | dst.z = sw::uintBitsToFloat(src.z); |
| 969 | dst.w = sw::uintBitsToFloat(src.w); |
| 970 | } |
| 971 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 972 | void ShaderCore::frc(Vector4f &dst, Vector4f &src) |
| 973 | { |
| 974 | dst.x = Frac(src.x); |
| 975 | dst.y = Frac(src.y); |
| 976 | dst.z = Frac(src.z); |
| 977 | dst.w = Frac(src.w); |
| 978 | } |
| 979 | |
| 980 | void ShaderCore::trunc(Vector4f &dst, Vector4f &src) |
| 981 | { |
| 982 | dst.x = Trunc(src.x); |
| 983 | dst.y = Trunc(src.y); |
| 984 | dst.z = Trunc(src.z); |
| 985 | dst.w = Trunc(src.w); |
| 986 | } |
| 987 | |
| 988 | void ShaderCore::floor(Vector4f &dst, Vector4f &src) |
| 989 | { |
| 990 | dst.x = Floor(src.x); |
| 991 | dst.y = Floor(src.y); |
| 992 | dst.z = Floor(src.z); |
| 993 | dst.w = Floor(src.w); |
| 994 | } |
| 995 | |
Alexis Hetu | 8b5f3ef | 2015-04-16 11:33:34 -0400 | [diff] [blame^] | 996 | void ShaderCore::round(Vector4f &dst, Vector4f &src) |
| 997 | { |
| 998 | dst.x = Round(src.x); |
| 999 | dst.y = Round(src.y); |
| 1000 | dst.z = Round(src.z); |
| 1001 | dst.w = Round(src.w); |
| 1002 | } |
| 1003 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1004 | void ShaderCore::ceil(Vector4f &dst, Vector4f &src) |
| 1005 | { |
| 1006 | dst.x = Ceil(src.x); |
| 1007 | dst.y = Ceil(src.y); |
| 1008 | dst.z = Ceil(src.z); |
| 1009 | dst.w = Ceil(src.w); |
| 1010 | } |
| 1011 | |
| 1012 | void ShaderCore::powx(Vector4f &dst, Vector4f &src0, Vector4f &src1, bool pp) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1013 | { |
| 1014 | Float4 pow = power(src0.x, src1.x, pp); |
| 1015 | |
| 1016 | dst.x = pow; |
| 1017 | dst.y = pow; |
| 1018 | dst.z = pow; |
| 1019 | dst.w = pow; |
| 1020 | } |
| 1021 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1022 | void ShaderCore::pow(Vector4f &dst, Vector4f &src0, Vector4f &src1, bool pp) |
| 1023 | { |
| 1024 | dst.x = power(src0.x, src1.x, pp); |
| 1025 | dst.y = power(src0.y, src1.y, pp); |
| 1026 | dst.z = power(src0.z, src1.z, pp); |
| 1027 | dst.w = power(src0.w, src1.w, pp); |
| 1028 | } |
| 1029 | |
| 1030 | void ShaderCore::crs(Vector4f &dst, Vector4f &src0, Vector4f &src1) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1031 | { |
| 1032 | dst.x = src0.y * src1.z - src0.z * src1.y; |
| 1033 | dst.y = src0.z * src1.x - src0.x * src1.z; |
| 1034 | dst.z = src0.x * src1.y - src0.y * src1.x; |
| 1035 | } |
| 1036 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1037 | void ShaderCore::forward1(Vector4f &dst, Vector4f &N, Vector4f &I, Vector4f &Nref) |
| 1038 | { |
| 1039 | Int4 flip = CmpNLT(Nref.x * I.x, Float4(0.0f)) & Int4(0x80000000); |
| 1040 | |
| 1041 | dst.x = As<Float4>(flip ^ As<Int4>(N.x)); |
| 1042 | } |
| 1043 | |
| 1044 | void ShaderCore::forward2(Vector4f &dst, Vector4f &N, Vector4f &I, Vector4f &Nref) |
| 1045 | { |
| 1046 | Int4 flip = CmpNLT(dot2(Nref, I), Float4(0.0f)) & Int4(0x80000000); |
| 1047 | |
| 1048 | dst.x = As<Float4>(flip ^ As<Int4>(N.x)); |
| 1049 | dst.y = As<Float4>(flip ^ As<Int4>(N.y)); |
| 1050 | } |
| 1051 | |
| 1052 | void ShaderCore::forward3(Vector4f &dst, Vector4f &N, Vector4f &I, Vector4f &Nref) |
| 1053 | { |
| 1054 | Int4 flip = CmpNLT(dot3(Nref, I), Float4(0.0f)) & Int4(0x80000000); |
| 1055 | |
| 1056 | dst.x = As<Float4>(flip ^ As<Int4>(N.x)); |
| 1057 | dst.y = As<Float4>(flip ^ As<Int4>(N.y)); |
| 1058 | dst.z = As<Float4>(flip ^ As<Int4>(N.z)); |
| 1059 | } |
| 1060 | |
| 1061 | void ShaderCore::forward4(Vector4f &dst, Vector4f &N, Vector4f &I, Vector4f &Nref) |
| 1062 | { |
| 1063 | Int4 flip = CmpNLT(dot4(Nref, I), Float4(0.0f)) & Int4(0x80000000); |
| 1064 | |
| 1065 | dst.x = As<Float4>(flip ^ As<Int4>(N.x)); |
| 1066 | dst.y = As<Float4>(flip ^ As<Int4>(N.y)); |
| 1067 | dst.z = As<Float4>(flip ^ As<Int4>(N.z)); |
| 1068 | dst.w = As<Float4>(flip ^ As<Int4>(N.w)); |
| 1069 | } |
| 1070 | |
| 1071 | void ShaderCore::reflect1(Vector4f &dst, Vector4f &I, Vector4f &N) |
| 1072 | { |
| 1073 | Float4 d = N.x * I.x; |
| 1074 | |
| 1075 | dst.x = I.x - Float4(2.0f) * d * N.x; |
| 1076 | } |
| 1077 | |
| 1078 | void ShaderCore::reflect2(Vector4f &dst, Vector4f &I, Vector4f &N) |
| 1079 | { |
| 1080 | Float4 d = dot2(N, I); |
| 1081 | |
| 1082 | dst.x = I.x - Float4(2.0f) * d * N.x; |
| 1083 | dst.y = I.y - Float4(2.0f) * d * N.y; |
| 1084 | } |
| 1085 | |
| 1086 | void ShaderCore::reflect3(Vector4f &dst, Vector4f &I, Vector4f &N) |
| 1087 | { |
| 1088 | Float4 d = dot3(N, I); |
| 1089 | |
| 1090 | dst.x = I.x - Float4(2.0f) * d * N.x; |
| 1091 | dst.y = I.y - Float4(2.0f) * d * N.y; |
| 1092 | dst.z = I.z - Float4(2.0f) * d * N.z; |
| 1093 | } |
| 1094 | |
| 1095 | void ShaderCore::reflect4(Vector4f &dst, Vector4f &I, Vector4f &N) |
| 1096 | { |
| 1097 | Float4 d = dot4(N, I); |
| 1098 | |
| 1099 | dst.x = I.x - Float4(2.0f) * d * N.x; |
| 1100 | dst.y = I.y - Float4(2.0f) * d * N.y; |
| 1101 | dst.z = I.z - Float4(2.0f) * d * N.z; |
| 1102 | dst.w = I.w - Float4(2.0f) * d * N.w; |
| 1103 | } |
| 1104 | |
| 1105 | void ShaderCore::refract1(Vector4f &dst, Vector4f &I, Vector4f &N, Float4 &eta) |
| 1106 | { |
| 1107 | Float4 d = N.x * I.x; |
| 1108 | Float4 k = Float4(1.0f) - eta * eta * (Float4(1.0f) - d * d); |
| 1109 | Int4 pos = CmpNLT(k, Float4(0.0f)); |
| 1110 | Float4 t = (eta * d + Sqrt(k)); |
| 1111 | |
| 1112 | dst.x = As<Float4>(pos & As<Int4>(eta * I.x - t * N.x)); |
| 1113 | } |
| 1114 | |
| 1115 | void ShaderCore::refract2(Vector4f &dst, Vector4f &I, Vector4f &N, Float4 &eta) |
| 1116 | { |
| 1117 | Float4 d = dot2(N, I); |
| 1118 | Float4 k = Float4(1.0f) - eta * eta * (Float4(1.0f) - d * d); |
| 1119 | Int4 pos = CmpNLT(k, Float4(0.0f)); |
| 1120 | Float4 t = (eta * d + Sqrt(k)); |
| 1121 | |
| 1122 | dst.x = As<Float4>(pos & As<Int4>(eta * I.x - t * N.x)); |
| 1123 | dst.y = As<Float4>(pos & As<Int4>(eta * I.y - t * N.y)); |
| 1124 | } |
| 1125 | |
| 1126 | void ShaderCore::refract3(Vector4f &dst, Vector4f &I, Vector4f &N, Float4 &eta) |
| 1127 | { |
| 1128 | Float4 d = dot3(N, I); |
| 1129 | Float4 k = Float4(1.0f) - eta * eta * (Float4(1.0f) - d * d); |
| 1130 | Int4 pos = CmpNLT(k, Float4(0.0f)); |
| 1131 | Float4 t = (eta * d + Sqrt(k)); |
| 1132 | |
| 1133 | dst.x = As<Float4>(pos & As<Int4>(eta * I.x - t * N.x)); |
| 1134 | dst.y = As<Float4>(pos & As<Int4>(eta * I.y - t * N.y)); |
| 1135 | dst.z = As<Float4>(pos & As<Int4>(eta * I.z - t * N.z)); |
| 1136 | } |
| 1137 | |
| 1138 | void ShaderCore::refract4(Vector4f &dst, Vector4f &I, Vector4f &N, Float4 &eta) |
| 1139 | { |
| 1140 | Float4 d = dot4(N, I); |
| 1141 | Float4 k = Float4(1.0f) - eta * eta * (Float4(1.0f) - d * d); |
| 1142 | Int4 pos = CmpNLT(k, Float4(0.0f)); |
| 1143 | Float4 t = (eta * d + Sqrt(k)); |
| 1144 | |
| 1145 | dst.x = As<Float4>(pos & As<Int4>(eta * I.x - t * N.x)); |
| 1146 | dst.y = As<Float4>(pos & As<Int4>(eta * I.y - t * N.y)); |
| 1147 | dst.z = As<Float4>(pos & As<Int4>(eta * I.z - t * N.z)); |
| 1148 | dst.w = As<Float4>(pos & As<Int4>(eta * I.w - t * N.w)); |
| 1149 | } |
| 1150 | |
| 1151 | void ShaderCore::sgn(Vector4f &dst, Vector4f &src) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1152 | { |
| 1153 | sgn(dst.x, src.x); |
| 1154 | sgn(dst.y, src.y); |
| 1155 | sgn(dst.z, src.z); |
| 1156 | sgn(dst.w, src.w); |
| 1157 | } |
| 1158 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1159 | void ShaderCore::abs(Vector4f &dst, Vector4f &src) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1160 | { |
| 1161 | dst.x = Abs(src.x); |
| 1162 | dst.y = Abs(src.y); |
| 1163 | dst.z = Abs(src.z); |
| 1164 | dst.w = Abs(src.w); |
| 1165 | } |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1166 | |
| 1167 | void ShaderCore::nrm2(Vector4f &dst, Vector4f &src, bool pp) |
| 1168 | { |
| 1169 | Float4 dot = dot2(src, src); |
| 1170 | Float4 rsq = reciprocalSquareRoot(dot, false, pp); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1171 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1172 | dst.x = src.x * rsq; |
| 1173 | dst.y = src.y * rsq; |
| 1174 | dst.z = src.z * rsq; |
| 1175 | dst.w = src.w * rsq; |
| 1176 | } |
| 1177 | |
| 1178 | void ShaderCore::nrm3(Vector4f &dst, Vector4f &src, bool pp) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1179 | { |
| 1180 | Float4 dot = dot3(src, src); |
| 1181 | Float4 rsq = reciprocalSquareRoot(dot, false, pp); |
| 1182 | |
| 1183 | dst.x = src.x * rsq; |
| 1184 | dst.y = src.y * rsq; |
| 1185 | dst.z = src.z * rsq; |
| 1186 | dst.w = src.w * rsq; |
| 1187 | } |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1188 | |
| 1189 | void ShaderCore::nrm4(Vector4f &dst, Vector4f &src, bool pp) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1190 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1191 | Float4 dot = dot4(src, src); |
| 1192 | Float4 rsq = reciprocalSquareRoot(dot, false, pp); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1193 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1194 | dst.x = src.x * rsq; |
| 1195 | dst.y = src.y * rsq; |
| 1196 | dst.z = src.z * rsq; |
| 1197 | dst.w = src.w * rsq; |
| 1198 | } |
| 1199 | |
| 1200 | void ShaderCore::sincos(Vector4f &dst, Vector4f &src, bool pp) |
| 1201 | { |
| 1202 | dst.x = cosine_pi(src.x, pp); |
| 1203 | dst.y = sine_pi(src.x, pp); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1204 | } |
| 1205 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1206 | void ShaderCore::cos(Vector4f &dst, Vector4f &src, bool pp) |
| 1207 | { |
| 1208 | dst.x = cosine(src.x, pp); |
| 1209 | dst.y = cosine(src.y, pp); |
| 1210 | dst.z = cosine(src.z, pp); |
| 1211 | dst.w = cosine(src.w, pp); |
| 1212 | } |
| 1213 | |
| 1214 | void ShaderCore::sin(Vector4f &dst, Vector4f &src, bool pp) |
| 1215 | { |
| 1216 | dst.x = sine(src.x, pp); |
| 1217 | dst.y = sine(src.y, pp); |
| 1218 | dst.z = sine(src.z, pp); |
| 1219 | dst.w = sine(src.w, pp); |
| 1220 | } |
| 1221 | |
| 1222 | void ShaderCore::tan(Vector4f &dst, Vector4f &src, bool pp) |
| 1223 | { |
| 1224 | dst.x = tangent(src.x, pp); |
| 1225 | dst.y = tangent(src.y, pp); |
| 1226 | dst.z = tangent(src.z, pp); |
| 1227 | dst.w = tangent(src.w, pp); |
| 1228 | } |
| 1229 | |
| 1230 | void ShaderCore::acos(Vector4f &dst, Vector4f &src, bool pp) |
| 1231 | { |
| 1232 | dst.x = arccos(src.x, pp); |
| 1233 | dst.y = arccos(src.y, pp); |
| 1234 | dst.z = arccos(src.z, pp); |
| 1235 | dst.w = arccos(src.w, pp); |
| 1236 | } |
| 1237 | |
| 1238 | void ShaderCore::asin(Vector4f &dst, Vector4f &src, bool pp) |
| 1239 | { |
| 1240 | dst.x = arcsin(src.x, pp); |
| 1241 | dst.y = arcsin(src.y, pp); |
| 1242 | dst.z = arcsin(src.z, pp); |
| 1243 | dst.w = arcsin(src.w, pp); |
| 1244 | } |
| 1245 | |
| 1246 | void ShaderCore::atan(Vector4f &dst, Vector4f &src, bool pp) |
| 1247 | { |
| 1248 | dst.x = arctan(src.x, pp); |
| 1249 | dst.y = arctan(src.y, pp); |
| 1250 | dst.z = arctan(src.z, pp); |
| 1251 | dst.w = arctan(src.w, pp); |
| 1252 | } |
| 1253 | |
| 1254 | void ShaderCore::atan2(Vector4f &dst, Vector4f &src0, Vector4f &src1, bool pp) |
| 1255 | { |
| 1256 | dst.x = arctan(src0.x, src1.x, pp); |
| 1257 | dst.y = arctan(src0.y, src1.y, pp); |
| 1258 | dst.z = arctan(src0.z, src1.z, pp); |
| 1259 | dst.w = arctan(src0.w, src1.w, pp); |
| 1260 | } |
| 1261 | |
Alexis Hetu | 8b5f3ef | 2015-04-16 11:33:34 -0400 | [diff] [blame^] | 1262 | void ShaderCore::cosh(Vector4f &dst, Vector4f &src, bool pp) |
| 1263 | { |
| 1264 | dst.x = cosineh(src.x, pp); |
| 1265 | dst.y = cosineh(src.y, pp); |
| 1266 | dst.z = cosineh(src.z, pp); |
| 1267 | dst.w = cosineh(src.w, pp); |
| 1268 | } |
| 1269 | |
| 1270 | void ShaderCore::sinh(Vector4f &dst, Vector4f &src, bool pp) |
| 1271 | { |
| 1272 | dst.x = sineh(src.x, pp); |
| 1273 | dst.y = sineh(src.y, pp); |
| 1274 | dst.z = sineh(src.z, pp); |
| 1275 | dst.w = sineh(src.w, pp); |
| 1276 | } |
| 1277 | |
| 1278 | void ShaderCore::tanh(Vector4f &dst, Vector4f &src, bool pp) |
| 1279 | { |
| 1280 | dst.x = tangenth(src.x, pp); |
| 1281 | dst.y = tangenth(src.y, pp); |
| 1282 | dst.z = tangenth(src.z, pp); |
| 1283 | dst.w = tangenth(src.w, pp); |
| 1284 | } |
| 1285 | |
| 1286 | void ShaderCore::acosh(Vector4f &dst, Vector4f &src, bool pp) |
| 1287 | { |
| 1288 | dst.x = arccosh(src.x, pp); |
| 1289 | dst.y = arccosh(src.y, pp); |
| 1290 | dst.z = arccosh(src.z, pp); |
| 1291 | dst.w = arccosh(src.w, pp); |
| 1292 | } |
| 1293 | |
| 1294 | void ShaderCore::asinh(Vector4f &dst, Vector4f &src, bool pp) |
| 1295 | { |
| 1296 | dst.x = arcsinh(src.x, pp); |
| 1297 | dst.y = arcsinh(src.y, pp); |
| 1298 | dst.z = arcsinh(src.z, pp); |
| 1299 | dst.w = arcsinh(src.w, pp); |
| 1300 | } |
| 1301 | |
| 1302 | void ShaderCore::atanh(Vector4f &dst, Vector4f &src, bool pp) |
| 1303 | { |
| 1304 | dst.x = arctanh(src.x, pp); |
| 1305 | dst.y = arctanh(src.y, pp); |
| 1306 | dst.z = arctanh(src.z, pp); |
| 1307 | dst.w = arctanh(src.w, pp); |
| 1308 | } |
| 1309 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1310 | void ShaderCore::expp(Vector4f &dst, Vector4f &src, unsigned short version) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1311 | { |
| 1312 | if(version < 0x0200) |
| 1313 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1314 | Float4 frc = Frac(src.x); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1315 | Float4 floor = src.x - frc; |
| 1316 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1317 | dst.x = exponential2(floor, true); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1318 | dst.y = frc; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1319 | dst.z = exponential2(src.x, true); |
| 1320 | dst.w = Float4(1.0f); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1321 | } |
| 1322 | else // Version >= 2.0 |
| 1323 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1324 | exp2x(dst, src, true); // FIXME: 10-bit precision suffices |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1325 | } |
| 1326 | } |
| 1327 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1328 | void ShaderCore::logp(Vector4f &dst, Vector4f &src, unsigned short version) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1329 | { |
| 1330 | if(version < 0x0200) |
| 1331 | { |
| 1332 | Float4 tmp0; |
| 1333 | Float4 tmp1; |
| 1334 | Float4 t; |
| 1335 | Int4 r; |
| 1336 | |
| 1337 | tmp0 = Abs(src.x); |
| 1338 | tmp1 = tmp0; |
| 1339 | |
| 1340 | // X component |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1341 | r = As<Int4>(As<UInt4>(tmp0) >> 23) - Int4(127); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1342 | dst.x = Float4(r); |
| 1343 | |
| 1344 | // Y component |
| 1345 | dst.y = As<Float4>((As<Int4>(tmp1) & Int4(0x007FFFFF)) | As<Int4>(Float4(1.0f))); |
| 1346 | |
| 1347 | // Z component |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1348 | dst.z = logarithm2(src.x, true, true); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1349 | |
| 1350 | // W component |
| 1351 | dst.w = 1.0f; |
| 1352 | } |
| 1353 | else |
| 1354 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1355 | log2x(dst, src, true); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1356 | } |
| 1357 | } |
| 1358 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1359 | void ShaderCore::cmp0(Vector4f &dst, Vector4f &src0, Vector4f &src1, Vector4f &src2) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1360 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1361 | cmp0(dst.x, src0.x, src1.x, src2.x); |
| 1362 | cmp0(dst.y, src0.y, src1.y, src2.y); |
| 1363 | cmp0(dst.z, src0.z, src1.z, src2.z); |
| 1364 | cmp0(dst.w, src0.w, src1.w, src2.w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1365 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1366 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1367 | void ShaderCore::select(Vector4f &dst, Vector4f &src0, Vector4f &src1, Vector4f &src2) |
| 1368 | { |
| 1369 | select(dst.x, As<Int4>(src0.x), src1.x, src2.x); |
| 1370 | select(dst.y, As<Int4>(src0.y), src1.y, src2.y); |
| 1371 | select(dst.z, As<Int4>(src0.z), src1.z, src2.z); |
| 1372 | select(dst.w, As<Int4>(src0.w), src1.w, src2.w); |
| 1373 | } |
| 1374 | |
| 1375 | void ShaderCore::extract(Float4 &dst, Vector4f &src0, Float4 &src1) |
| 1376 | { |
| 1377 | select(dst, CmpEQ(src1, Float4(1.0f)), src0.y, src0.x); |
| 1378 | select(dst, CmpEQ(src1, Float4(2.0f)), src0.z, dst); |
| 1379 | select(dst, CmpEQ(src1, Float4(3.0f)), src0.w, dst); |
| 1380 | } |
| 1381 | |
| 1382 | void ShaderCore::insert(Vector4f &dst, Vector4f &src, Float4 &element, Float4 &index) |
| 1383 | { |
| 1384 | select(dst.x, CmpEQ(index, Float4(0.0f)), element, src.x); |
| 1385 | select(dst.y, CmpEQ(index, Float4(1.0f)), element, src.y); |
| 1386 | select(dst.z, CmpEQ(index, Float4(2.0f)), element, src.z); |
| 1387 | select(dst.w, CmpEQ(index, Float4(3.0f)), element, src.w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1388 | } |
| 1389 | |
| 1390 | void ShaderCore::sgn(Float4 &dst, Float4 &src) |
| 1391 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1392 | Int4 neg = As<Int4>(CmpLT(src, Float4(-0.0f))) & As<Int4>(Float4(-1.0f)); |
| 1393 | 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] | 1394 | dst = As<Float4>(neg | pos); |
| 1395 | } |
| 1396 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1397 | void ShaderCore::cmp0(Float4 &dst, Float4 &src0, Float4 &src1, Float4 &src2) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1398 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1399 | Int4 pos = CmpLE(Float4(0.0f), src0); |
| 1400 | select(dst, pos, src1, src2); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1401 | } |
| 1402 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1403 | void ShaderCore::select(Float4 &dst, RValue<Int4> src0, Float4 &src1, Float4 &src2) |
| 1404 | { |
| 1405 | // FIXME: LLVM vector select |
| 1406 | dst = As<Float4>(src0 & As<Int4>(src1) | ~src0 & As<Int4>(src2)); |
| 1407 | } |
| 1408 | |
| 1409 | void ShaderCore::cmp(Vector4f &dst, Vector4f &src0, Vector4f &src1, Control control) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1410 | { |
| 1411 | switch(control) |
| 1412 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1413 | case Shader::CONTROL_GT: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1414 | dst.x = As<Float4>(CmpNLE(src0.x, src1.x)); |
| 1415 | dst.y = As<Float4>(CmpNLE(src0.y, src1.y)); |
| 1416 | dst.z = As<Float4>(CmpNLE(src0.z, src1.z)); |
| 1417 | dst.w = As<Float4>(CmpNLE(src0.w, src1.w)); |
| 1418 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1419 | case Shader::CONTROL_EQ: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1420 | dst.x = As<Float4>(CmpEQ(src0.x, src1.x)); |
| 1421 | dst.y = As<Float4>(CmpEQ(src0.y, src1.y)); |
| 1422 | dst.z = As<Float4>(CmpEQ(src0.z, src1.z)); |
| 1423 | dst.w = As<Float4>(CmpEQ(src0.w, src1.w)); |
| 1424 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1425 | case Shader::CONTROL_GE: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1426 | dst.x = As<Float4>(CmpNLT(src0.x, src1.x)); |
| 1427 | dst.y = As<Float4>(CmpNLT(src0.y, src1.y)); |
| 1428 | dst.z = As<Float4>(CmpNLT(src0.z, src1.z)); |
| 1429 | dst.w = As<Float4>(CmpNLT(src0.w, src1.w)); |
| 1430 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1431 | case Shader::CONTROL_LT: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1432 | dst.x = As<Float4>(CmpLT(src0.x, src1.x)); |
| 1433 | dst.y = As<Float4>(CmpLT(src0.y, src1.y)); |
| 1434 | dst.z = As<Float4>(CmpLT(src0.z, src1.z)); |
| 1435 | dst.w = As<Float4>(CmpLT(src0.w, src1.w)); |
| 1436 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1437 | case Shader::CONTROL_NE: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1438 | dst.x = As<Float4>(CmpNEQ(src0.x, src1.x)); |
| 1439 | dst.y = As<Float4>(CmpNEQ(src0.y, src1.y)); |
| 1440 | dst.z = As<Float4>(CmpNEQ(src0.z, src1.z)); |
| 1441 | dst.w = As<Float4>(CmpNEQ(src0.w, src1.w)); |
| 1442 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1443 | case Shader::CONTROL_LE: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1444 | dst.x = As<Float4>(CmpLE(src0.x, src1.x)); |
| 1445 | dst.y = As<Float4>(CmpLE(src0.y, src1.y)); |
| 1446 | dst.z = As<Float4>(CmpLE(src0.z, src1.z)); |
| 1447 | dst.w = As<Float4>(CmpLE(src0.w, src1.w)); |
| 1448 | break; |
| 1449 | default: |
| 1450 | ASSERT(false); |
| 1451 | } |
| 1452 | } |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1453 | |
| 1454 | void ShaderCore::icmp(Vector4f &dst, Vector4f &src0, Vector4f &src1, Control control) |
| 1455 | { |
| 1456 | switch(control) |
| 1457 | { |
| 1458 | case Shader::CONTROL_GT: |
| 1459 | dst.x = As<Float4>(CmpNLE(As<Int4>(src0.x), As<Int4>(src1.x))); |
| 1460 | dst.y = As<Float4>(CmpNLE(As<Int4>(src0.y), As<Int4>(src1.y))); |
| 1461 | dst.z = As<Float4>(CmpNLE(As<Int4>(src0.z), As<Int4>(src1.z))); |
| 1462 | dst.w = As<Float4>(CmpNLE(As<Int4>(src0.w), As<Int4>(src1.w))); |
| 1463 | break; |
| 1464 | case Shader::CONTROL_EQ: |
| 1465 | dst.x = As<Float4>(CmpEQ(As<Int4>(src0.x), As<Int4>(src1.x))); |
| 1466 | dst.y = As<Float4>(CmpEQ(As<Int4>(src0.y), As<Int4>(src1.y))); |
| 1467 | dst.z = As<Float4>(CmpEQ(As<Int4>(src0.z), As<Int4>(src1.z))); |
| 1468 | dst.w = As<Float4>(CmpEQ(As<Int4>(src0.w), As<Int4>(src1.w))); |
| 1469 | break; |
| 1470 | case Shader::CONTROL_GE: |
| 1471 | dst.x = As<Float4>(CmpNLT(As<Int4>(src0.x), As<Int4>(src1.x))); |
| 1472 | dst.y = As<Float4>(CmpNLT(As<Int4>(src0.y), As<Int4>(src1.y))); |
| 1473 | dst.z = As<Float4>(CmpNLT(As<Int4>(src0.z), As<Int4>(src1.z))); |
| 1474 | dst.w = As<Float4>(CmpNLT(As<Int4>(src0.w), As<Int4>(src1.w))); |
| 1475 | break; |
| 1476 | case Shader::CONTROL_LT: |
| 1477 | dst.x = As<Float4>(CmpLT(As<Int4>(src0.x), As<Int4>(src1.x))); |
| 1478 | dst.y = As<Float4>(CmpLT(As<Int4>(src0.y), As<Int4>(src1.y))); |
| 1479 | dst.z = As<Float4>(CmpLT(As<Int4>(src0.z), As<Int4>(src1.z))); |
| 1480 | dst.w = As<Float4>(CmpLT(As<Int4>(src0.w), As<Int4>(src1.w))); |
| 1481 | break; |
| 1482 | case Shader::CONTROL_NE: |
| 1483 | dst.x = As<Float4>(CmpNEQ(As<Int4>(src0.x), As<Int4>(src1.x))); |
| 1484 | dst.y = As<Float4>(CmpNEQ(As<Int4>(src0.y), As<Int4>(src1.y))); |
| 1485 | dst.z = As<Float4>(CmpNEQ(As<Int4>(src0.z), As<Int4>(src1.z))); |
| 1486 | dst.w = As<Float4>(CmpNEQ(As<Int4>(src0.w), As<Int4>(src1.w))); |
| 1487 | break; |
| 1488 | case Shader::CONTROL_LE: |
| 1489 | dst.x = As<Float4>(CmpLE(As<Int4>(src0.x), As<Int4>(src1.x))); |
| 1490 | dst.y = As<Float4>(CmpLE(As<Int4>(src0.y), As<Int4>(src1.y))); |
| 1491 | dst.z = As<Float4>(CmpLE(As<Int4>(src0.z), As<Int4>(src1.z))); |
| 1492 | dst.w = As<Float4>(CmpLE(As<Int4>(src0.w), As<Int4>(src1.w))); |
| 1493 | break; |
| 1494 | default: |
| 1495 | ASSERT(false); |
| 1496 | } |
| 1497 | } |
| 1498 | |
| 1499 | void ShaderCore::all(Float4 &dst, Vector4f &src) |
| 1500 | { |
| 1501 | dst = As<Float4>(As<Int4>(src.x) & As<Int4>(src.y) & As<Int4>(src.z) & As<Int4>(src.w)); |
| 1502 | } |
| 1503 | |
| 1504 | void ShaderCore::any(Float4 &dst, Vector4f &src) |
| 1505 | { |
| 1506 | dst = As<Float4>(As<Int4>(src.x) | As<Int4>(src.y) | As<Int4>(src.z) | As<Int4>(src.w)); |
| 1507 | } |
| 1508 | |
| 1509 | void ShaderCore::not(Vector4f &dst, Vector4f &src) |
| 1510 | { |
| 1511 | dst.x = As<Float4>(As<Int4>(src.x) ^ Int4(0xFFFFFFFF)); |
| 1512 | dst.y = As<Float4>(As<Int4>(src.y) ^ Int4(0xFFFFFFFF)); |
| 1513 | dst.z = As<Float4>(As<Int4>(src.z) ^ Int4(0xFFFFFFFF)); |
| 1514 | dst.w = As<Float4>(As<Int4>(src.w) ^ Int4(0xFFFFFFFF)); |
| 1515 | } |
| 1516 | |
| 1517 | void ShaderCore::or(Float4 &dst, Float4 &src0, Float4 &src1) |
| 1518 | { |
| 1519 | dst = As<Float4>(As<Int4>(src0) | As<Int4>(src1)); |
| 1520 | } |
| 1521 | |
| 1522 | void ShaderCore::xor(Float4 &dst, Float4 &src0, Float4 &src1) |
| 1523 | { |
| 1524 | dst = As<Float4>(As<Int4>(src0) ^ As<Int4>(src1)); |
| 1525 | } |
| 1526 | |
| 1527 | void ShaderCore::and(Float4 &dst, Float4 &src0, Float4 &src1) |
| 1528 | { |
| 1529 | dst = As<Float4>(As<Int4>(src0) & As<Int4>(src1)); |
| 1530 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1531 | } |