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