| 1 | // This file is part of the FidelityFX SDK. |
| 2 | // |
| 3 | // Copyright (c) 2022-2023 Advanced Micro Devices, Inc. All rights reserved. |
| 4 | // |
| 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy |
| 6 | // of this software and associated documentation files (the "Software"), to deal |
| 7 | // in the Software without restriction, including without limitation the rights |
| 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 9 | // copies of the Software, and to permit persons to whom the Software is |
| 10 | // furnished to do so, subject to the following conditions: |
| 11 | // The above copyright notice and this permission notice shall be included in |
| 12 | // all copies or substantial portions of the Software. |
| 13 | // |
| 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 20 | // THE SOFTWARE. |
| 21 | |
| 22 | #if FFX_HALF |
| 23 | #if FFX_HLSL_6_2 |
| 24 | /// A define value for 16bit positive infinity. |
| 25 | /// |
| 26 | /// @ingroup GPU |
| 27 | #define FFX_POSITIVE_INFINITY_HALF FFX_TO_FLOAT16((uint16_t)0x7c00u) |
| 28 | |
| 29 | /// A define value for 16bit negative infinity. |
| 30 | /// |
| 31 | /// @ingroup GPU |
| 32 | #define FFX_NEGATIVE_INFINITY_HALF FFX_TO_FLOAT16((uint16_t)0xfc00u) |
| 33 | #else |
| 34 | /// A define value for 16bit positive infinity. |
| 35 | /// |
| 36 | /// @ingroup GPU |
| 37 | #define FFX_POSITIVE_INFINITY_HALF FFX_TO_FLOAT16(0x7c00u) |
| 38 | |
| 39 | /// A define value for 16bit negative infinity. |
| 40 | /// |
| 41 | /// @ingroup GPU |
| 42 | #define FFX_NEGATIVE_INFINITY_HALF FFX_TO_FLOAT16(0xfc00u) |
| 43 | #endif // FFX_HLSL_6_2 |
| 44 | |
| 45 | /// Compute the min of two values. |
| 46 | /// |
| 47 | /// @param [in] x The first value to compute the min of. |
| 48 | /// @param [in] y The second value to compute the min of. |
| 49 | /// |
| 50 | /// @returns |
| 51 | /// The the lowest of two values. |
| 52 | /// |
| 53 | /// @ingroup GPU |
| 54 | FfxFloat16 ffxMin(FfxFloat16 x, FfxFloat16 y) |
| 55 | { |
| 56 | return min(x, y); |
| 57 | } |
| 58 | |
| 59 | /// Compute the min of two values. |
| 60 | /// |
| 61 | /// @param [in] x The first value to compute the min of. |
| 62 | /// @param [in] y The second value to compute the min of. |
| 63 | /// |
| 64 | /// @returns |
| 65 | /// The the lowest of two values. |
| 66 | /// |
| 67 | /// @ingroup GPU |
| 68 | FfxFloat16x2 ffxMin(FfxFloat16x2 x, FfxFloat16x2 y) |
| 69 | { |
| 70 | return min(x, y); |
| 71 | } |
| 72 | |
| 73 | /// Compute the min of two values. |
| 74 | /// |
| 75 | /// @param [in] x The first value to compute the min of. |
| 76 | /// @param [in] y The second value to compute the min of. |
| 77 | /// |
| 78 | /// @returns |
| 79 | /// The the lowest of two values. |
| 80 | /// |
| 81 | /// @ingroup GPU |
| 82 | FfxFloat16x3 ffxMin(FfxFloat16x3 x, FfxFloat16x3 y) |
| 83 | { |
| 84 | return min(x, y); |
| 85 | } |
| 86 | |
| 87 | /// Compute the min of two values. |
| 88 | /// |
| 89 | /// @param [in] x The first value to compute the min of. |
| 90 | /// @param [in] y The second value to compute the min of. |
| 91 | /// |
| 92 | /// @returns |
| 93 | /// The the lowest of two values. |
| 94 | /// |
| 95 | /// @ingroup GPU |
| 96 | FfxFloat16x4 ffxMin(FfxFloat16x4 x, FfxFloat16x4 y) |
| 97 | { |
| 98 | return min(x, y); |
| 99 | } |
| 100 | |
| 101 | /// Compute the min of two values. |
| 102 | /// |
| 103 | /// @param [in] x The first value to compute the min of. |
| 104 | /// @param [in] y The second value to compute the min of. |
| 105 | /// |
| 106 | /// @returns |
| 107 | /// The the lowest of two values. |
| 108 | /// |
| 109 | /// @ingroup GPU |
| 110 | FfxInt16 ffxMin(FfxInt16 x, FfxInt16 y) |
| 111 | { |
| 112 | return min(x, y); |
| 113 | } |
| 114 | |
| 115 | /// Compute the min of two values. |
| 116 | /// |
| 117 | /// @param [in] x The first value to compute the min of. |
| 118 | /// @param [in] y The second value to compute the min of. |
| 119 | /// |
| 120 | /// @returns |
| 121 | /// The the lowest of two values. |
| 122 | /// |
| 123 | /// @ingroup GPU |
| 124 | FfxInt16x2 ffxMin(FfxInt16x2 x, FfxInt16x2 y) |
| 125 | { |
| 126 | return min(x, y); |
| 127 | } |
| 128 | |
| 129 | /// Compute the min of two values. |
| 130 | /// |
| 131 | /// @param [in] x The first value to compute the min of. |
| 132 | /// @param [in] y The second value to compute the min of. |
| 133 | /// |
| 134 | /// @returns |
| 135 | /// The the lowest of two values. |
| 136 | /// |
| 137 | /// @ingroup GPU |
| 138 | FfxInt16x3 ffxMin(FfxInt16x3 x, FfxInt16x3 y) |
| 139 | { |
| 140 | return min(x, y); |
| 141 | } |
| 142 | |
| 143 | /// Compute the min of two values. |
| 144 | /// |
| 145 | /// @param [in] x The first value to compute the min of. |
| 146 | /// @param [in] y The second value to compute the min of. |
| 147 | /// |
| 148 | /// @returns |
| 149 | /// The the lowest of two values. |
| 150 | /// |
| 151 | /// @ingroup GPU |
| 152 | FfxInt16x4 ffxMin(FfxInt16x4 x, FfxInt16x4 y) |
| 153 | { |
| 154 | return min(x, y); |
| 155 | } |
| 156 | |
| 157 | /// Compute the min of two values. |
| 158 | /// |
| 159 | /// @param [in] x The first value to compute the min of. |
| 160 | /// @param [in] y The second value to compute the min of. |
| 161 | /// |
| 162 | /// @returns |
| 163 | /// The the lowest of two values. |
| 164 | /// |
| 165 | /// @ingroup GPU |
| 166 | FfxUInt16 ffxMin(FfxUInt16 x, FfxUInt16 y) |
| 167 | { |
| 168 | return min(x, y); |
| 169 | } |
| 170 | |
| 171 | /// Compute the min of two values. |
| 172 | /// |
| 173 | /// @param [in] x The first value to compute the min of. |
| 174 | /// @param [in] y The second value to compute the min of. |
| 175 | /// |
| 176 | /// @returns |
| 177 | /// The the lowest of two values. |
| 178 | /// |
| 179 | /// @ingroup GPU |
| 180 | FfxUInt16x2 ffxMin(FfxUInt16x2 x, FfxUInt16x2 y) |
| 181 | { |
| 182 | return min(x, y); |
| 183 | } |
| 184 | |
| 185 | /// Compute the min of two values. |
| 186 | /// |
| 187 | /// @param [in] x The first value to compute the min of. |
| 188 | /// @param [in] y The second value to compute the min of. |
| 189 | /// |
| 190 | /// @returns |
| 191 | /// The the lowest of two values. |
| 192 | /// |
| 193 | /// @ingroup GPU |
| 194 | FfxUInt16x3 ffxMin(FfxUInt16x3 x, FfxUInt16x3 y) |
| 195 | { |
| 196 | return min(x, y); |
| 197 | } |
| 198 | |
| 199 | /// Compute the min of two values. |
| 200 | /// |
| 201 | /// @param [in] x The first value to compute the min of. |
| 202 | /// @param [in] y The second value to compute the min of. |
| 203 | /// |
| 204 | /// @returns |
| 205 | /// The the lowest of two values. |
| 206 | /// |
| 207 | /// @ingroup GPU |
| 208 | FfxUInt16x4 ffxMin(FfxUInt16x4 x, FfxUInt16x4 y) |
| 209 | { |
| 210 | return min(x, y); |
| 211 | } |
| 212 | |
| 213 | /// Compute the max of two values. |
| 214 | /// |
| 215 | /// @param [in] x The first value to compute the max of. |
| 216 | /// @param [in] y The second value to compute the max of. |
| 217 | /// |
| 218 | /// @returns |
| 219 | /// The the lowest of two values. |
| 220 | /// |
| 221 | /// @ingroup GPU |
| 222 | FfxFloat16 ffxMax(FfxFloat16 x, FfxFloat16 y) |
| 223 | { |
| 224 | return max(x, y); |
| 225 | } |
| 226 | |
| 227 | /// Compute the max of two values. |
| 228 | /// |
| 229 | /// @param [in] x The first value to compute the max of. |
| 230 | /// @param [in] y The second value to compute the max of. |
| 231 | /// |
| 232 | /// @returns |
| 233 | /// The the lowest of two values. |
| 234 | /// |
| 235 | /// @ingroup GPU |
| 236 | FfxFloat16x2 ffxMax(FfxFloat16x2 x, FfxFloat16x2 y) |
| 237 | { |
| 238 | return max(x, y); |
| 239 | } |
| 240 | |
| 241 | /// Compute the max of two values. |
| 242 | /// |
| 243 | /// @param [in] x The first value to compute the max of. |
| 244 | /// @param [in] y The second value to compute the max of. |
| 245 | /// |
| 246 | /// @returns |
| 247 | /// The the lowest of two values. |
| 248 | /// |
| 249 | /// @ingroup GPU |
| 250 | FfxFloat16x3 ffxMax(FfxFloat16x3 x, FfxFloat16x3 y) |
| 251 | { |
| 252 | return max(x, y); |
| 253 | } |
| 254 | |
| 255 | /// Compute the max of two values. |
| 256 | /// |
| 257 | /// @param [in] x The first value to compute the max of. |
| 258 | /// @param [in] y The second value to compute the max of. |
| 259 | /// |
| 260 | /// @returns |
| 261 | /// The the lowest of two values. |
| 262 | /// |
| 263 | /// @ingroup GPU |
| 264 | FfxFloat16x4 ffxMax(FfxFloat16x4 x, FfxFloat16x4 y) |
| 265 | { |
| 266 | return max(x, y); |
| 267 | } |
| 268 | |
| 269 | /// Compute the max of two values. |
| 270 | /// |
| 271 | /// @param [in] x The first value to compute the max of. |
| 272 | /// @param [in] y The second value to compute the max of. |
| 273 | /// |
| 274 | /// @returns |
| 275 | /// The the lowest of two values. |
| 276 | /// |
| 277 | /// @ingroup GPU |
| 278 | FfxInt16 ffxMax(FfxInt16 x, FfxInt16 y) |
| 279 | { |
| 280 | return max(x, y); |
| 281 | } |
| 282 | |
| 283 | /// Compute the max of two values. |
| 284 | /// |
| 285 | /// @param [in] x The first value to compute the max of. |
| 286 | /// @param [in] y The second value to compute the max of. |
| 287 | /// |
| 288 | /// @returns |
| 289 | /// The the lowest of two values. |
| 290 | /// |
| 291 | /// @ingroup GPU |
| 292 | FfxInt16x2 ffxMax(FfxInt16x2 x, FfxInt16x2 y) |
| 293 | { |
| 294 | return max(x, y); |
| 295 | } |
| 296 | |
| 297 | /// Compute the max of two values. |
| 298 | /// |
| 299 | /// @param [in] x The first value to compute the max of. |
| 300 | /// @param [in] y The second value to compute the max of. |
| 301 | /// |
| 302 | /// @returns |
| 303 | /// The the lowest of two values. |
| 304 | /// |
| 305 | /// @ingroup GPU |
| 306 | FfxInt16x3 ffxMax(FfxInt16x3 x, FfxInt16x3 y) |
| 307 | { |
| 308 | return max(x, y); |
| 309 | } |
| 310 | |
| 311 | /// Compute the max of two values. |
| 312 | /// |
| 313 | /// @param [in] x The first value to compute the max of. |
| 314 | /// @param [in] y The second value to compute the max of. |
| 315 | /// |
| 316 | /// @returns |
| 317 | /// The the lowest of two values. |
| 318 | /// |
| 319 | /// @ingroup GPU |
| 320 | FfxInt16x4 ffxMax(FfxInt16x4 x, FfxInt16x4 y) |
| 321 | { |
| 322 | return max(x, y); |
| 323 | } |
| 324 | |
| 325 | /// Compute the max of two values. |
| 326 | /// |
| 327 | /// @param [in] x The first value to compute the max of. |
| 328 | /// @param [in] y The second value to compute the max of. |
| 329 | /// |
| 330 | /// @returns |
| 331 | /// The the lowest of two values. |
| 332 | /// |
| 333 | /// @ingroup GPU |
| 334 | FfxUInt16 ffxMax(FfxUInt16 x, FfxUInt16 y) |
| 335 | { |
| 336 | return max(x, y); |
| 337 | } |
| 338 | |
| 339 | /// Compute the max of two values. |
| 340 | /// |
| 341 | /// @param [in] x The first value to compute the max of. |
| 342 | /// @param [in] y The second value to compute the max of. |
| 343 | /// |
| 344 | /// @returns |
| 345 | /// The the lowest of two values. |
| 346 | /// |
| 347 | /// @ingroup GPU |
| 348 | FfxUInt16x2 ffxMax(FfxUInt16x2 x, FfxUInt16x2 y) |
| 349 | { |
| 350 | return max(x, y); |
| 351 | } |
| 352 | |
| 353 | /// Compute the max of two values. |
| 354 | /// |
| 355 | /// @param [in] x The first value to compute the max of. |
| 356 | /// @param [in] y The second value to compute the max of. |
| 357 | /// |
| 358 | /// @returns |
| 359 | /// The the lowest of two values. |
| 360 | /// |
| 361 | /// @ingroup GPU |
| 362 | FfxUInt16x3 ffxMax(FfxUInt16x3 x, FfxUInt16x3 y) |
| 363 | { |
| 364 | return max(x, y); |
| 365 | } |
| 366 | |
| 367 | /// Compute the max of two values. |
| 368 | /// |
| 369 | /// @param [in] x The first value to compute the max of. |
| 370 | /// @param [in] y The second value to compute the max of. |
| 371 | /// |
| 372 | /// @returns |
| 373 | /// The the lowest of two values. |
| 374 | /// |
| 375 | /// @ingroup GPU |
| 376 | FfxUInt16x4 ffxMax(FfxUInt16x4 x, FfxUInt16x4 y) |
| 377 | { |
| 378 | return max(x, y); |
| 379 | } |
| 380 | |
| 381 | /// Compute the value of the first parameter raised to the power of the second. |
| 382 | /// |
| 383 | /// @param [in] x The value to raise to the power y. |
| 384 | /// @param [in] y The power to which to raise x. |
| 385 | /// |
| 386 | /// @returns |
| 387 | /// The value of the first parameter raised to the power of the second. |
| 388 | /// |
| 389 | /// @ingroup GPU |
| 390 | FfxFloat16 ffxPow(FfxFloat16 x, FfxFloat16 y) |
| 391 | { |
| 392 | return pow(x, y); |
| 393 | } |
| 394 | |
| 395 | /// Compute the value of the first parameter raised to the power of the second. |
| 396 | /// |
| 397 | /// @param [in] x The value to raise to the power y. |
| 398 | /// @param [in] y The power to which to raise x. |
| 399 | /// |
| 400 | /// @returns |
| 401 | /// The value of the first parameter raised to the power of the second. |
| 402 | /// |
| 403 | /// @ingroup GPU |
| 404 | FfxFloat16x2 ffxPow(FfxFloat16x2 x, FfxFloat16x2 y) |
| 405 | { |
| 406 | return pow(x, y); |
| 407 | } |
| 408 | |
| 409 | /// Compute the value of the first parameter raised to the power of the second. |
| 410 | /// |
| 411 | /// @param [in] x The value to raise to the power y. |
| 412 | /// @param [in] y The power to which to raise x. |
| 413 | /// |
| 414 | /// @returns |
| 415 | /// The value of the first parameter raised to the power of the second. |
| 416 | /// |
| 417 | /// @ingroup GPU |
| 418 | FfxFloat16x3 ffxPow(FfxFloat16x3 x, FfxFloat16x3 y) |
| 419 | { |
| 420 | return pow(x, y); |
| 421 | } |
| 422 | |
| 423 | /// Compute the value of the first parameter raised to the power of the second. |
| 424 | /// |
| 425 | /// @param [in] x The value to raise to the power y. |
| 426 | /// @param [in] y The power to which to raise x. |
| 427 | /// |
| 428 | /// @returns |
| 429 | /// The value of the first parameter raised to the power of the second. |
| 430 | /// |
| 431 | /// @ingroup GPU |
| 432 | FfxFloat16x4 ffxPow(FfxFloat16x4 x, FfxFloat16x4 y) |
| 433 | { |
| 434 | return pow(x, y); |
| 435 | } |
| 436 | |
| 437 | /// Compute the square root of a value. |
| 438 | /// |
| 439 | /// @param [in] x The first value to compute the min of. |
| 440 | /// |
| 441 | /// @returns |
| 442 | /// The the square root of <c><i>x</i></c>. |
| 443 | /// |
| 444 | /// @ingroup GPU |
| 445 | FfxFloat16 ffxSqrt(FfxFloat16 x) |
| 446 | { |
| 447 | return sqrt(x); |
| 448 | } |
| 449 | |
| 450 | /// Compute the square root of a value. |
| 451 | /// |
| 452 | /// @param [in] x The first value to compute the min of. |
| 453 | /// |
| 454 | /// @returns |
| 455 | /// The the square root of <c><i>x</i></c>. |
| 456 | /// |
| 457 | /// @ingroup GPU |
| 458 | FfxFloat16x2 ffxSqrt(FfxFloat16x2 x) |
| 459 | { |
| 460 | return sqrt(x); |
| 461 | } |
| 462 | |
| 463 | /// Compute the square root of a value. |
| 464 | /// |
| 465 | /// @param [in] x The first value to compute the min of. |
| 466 | /// |
| 467 | /// @returns |
| 468 | /// The the square root of <c><i>x</i></c>. |
| 469 | /// |
| 470 | /// @ingroup GPU |
| 471 | FfxFloat16x3 ffxSqrt(FfxFloat16x3 x) |
| 472 | { |
| 473 | return sqrt(x); |
| 474 | } |
| 475 | |
| 476 | /// Compute the square root of a value. |
| 477 | /// |
| 478 | /// @param [in] x The first value to compute the min of. |
| 479 | /// |
| 480 | /// @returns |
| 481 | /// The the square root of <c><i>x</i></c>. |
| 482 | /// |
| 483 | /// @ingroup GPU |
| 484 | FfxFloat16x4 ffxSqrt(FfxFloat16x4 x) |
| 485 | { |
| 486 | return sqrt(x); |
| 487 | } |
| 488 | |
| 489 | /// Copy the sign bit from 's' to positive 'd'. |
| 490 | /// |
| 491 | /// @param [in] d The value to copy the sign bit into. |
| 492 | /// @param [in] s The value to copy the sign bit from. |
| 493 | /// |
| 494 | /// @returns |
| 495 | /// The value of <c><i>d</i></c> with the sign bit from <c><i>s</i></c>. |
| 496 | /// |
| 497 | /// @ingroup GPU |
| 498 | FfxFloat16 ffxCopySignBitHalf(FfxFloat16 d, FfxFloat16 s) |
| 499 | { |
| 500 | return FFX_TO_FLOAT16(FFX_TO_UINT16(d) | (FFX_TO_UINT16(s) & FFX_BROADCAST_UINT16(0x8000u))); |
| 501 | } |
| 502 | |
| 503 | /// Copy the sign bit from 's' to positive 'd'. |
| 504 | /// |
| 505 | /// @param [in] d The value to copy the sign bit into. |
| 506 | /// @param [in] s The value to copy the sign bit from. |
| 507 | /// |
| 508 | /// @returns |
| 509 | /// The value of <c><i>d</i></c> with the sign bit from <c><i>s</i></c>. |
| 510 | /// |
| 511 | /// @ingroup GPU |
| 512 | FfxFloat16x2 ffxCopySignBitHalf(FfxFloat16x2 d, FfxFloat16x2 s) |
| 513 | { |
| 514 | return FFX_TO_FLOAT16X2(FFX_TO_UINT16X2(d) | (FFX_TO_UINT16X2(s) & FFX_BROADCAST_UINT16X2(0x8000u))); |
| 515 | } |
| 516 | |
| 517 | /// Copy the sign bit from 's' to positive 'd'. |
| 518 | /// |
| 519 | /// @param [in] d The value to copy the sign bit into. |
| 520 | /// @param [in] s The value to copy the sign bit from. |
| 521 | /// |
| 522 | /// @returns |
| 523 | /// The value of <c><i>d</i></c> with the sign bit from <c><i>s</i></c>. |
| 524 | /// |
| 525 | /// @ingroup GPU |
| 526 | FfxFloat16x3 ffxCopySignBitHalf(FfxFloat16x3 d, FfxFloat16x3 s) |
| 527 | { |
| 528 | return FFX_TO_FLOAT16X3(FFX_TO_UINT16X3(d) | (FFX_TO_UINT16X3(s) & FFX_BROADCAST_UINT16X3(0x8000u))); |
| 529 | } |
| 530 | |
| 531 | /// Copy the sign bit from 's' to positive 'd'. |
| 532 | /// |
| 533 | /// @param [in] d The value to copy the sign bit into. |
| 534 | /// @param [in] s The value to copy the sign bit from. |
| 535 | /// |
| 536 | /// @returns |
| 537 | /// The value of <c><i>d</i></c> with the sign bit from <c><i>s</i></c>. |
| 538 | /// |
| 539 | /// @ingroup GPU |
| 540 | FfxFloat16x4 ffxCopySignBitHalf(FfxFloat16x4 d, FfxFloat16x4 s) |
| 541 | { |
| 542 | return FFX_TO_FLOAT16X4(FFX_TO_UINT16X4(d) | (FFX_TO_UINT16X4(s) & FFX_BROADCAST_UINT16X4(0x8000u))); |
| 543 | } |
| 544 | |
| 545 | /// A single operation to return the following: |
| 546 | /// m = NaN := 0 |
| 547 | /// m >= 0 := 0 |
| 548 | /// m < 0 := 1 |
| 549 | /// |
| 550 | /// Uses the following useful floating point logic, |
| 551 | /// saturate(+a*(-INF)==-INF) := 0 |
| 552 | /// saturate( 0*(-INF)== NaN) := 0 |
| 553 | /// saturate(-a*(-INF)==+INF) := 1 |
| 554 | /// |
| 555 | /// This function is useful when creating masks for branch-free logic. |
| 556 | /// |
| 557 | /// @param [in] m The value to test against 0. |
| 558 | /// |
| 559 | /// @returns |
| 560 | /// 1.0 when the value is negative, or 0.0 when the value is 0 or position. |
| 561 | /// |
| 562 | /// @ingroup GPU |
| 563 | FfxFloat16 ffxIsSignedHalf(FfxFloat16 m) |
| 564 | { |
| 565 | return ffxSaturate(m * FFX_BROADCAST_FLOAT16(FFX_NEGATIVE_INFINITY_HALF)); |
| 566 | } |
| 567 | |
| 568 | /// A single operation to return the following: |
| 569 | /// m = NaN := 0 |
| 570 | /// m >= 0 := 0 |
| 571 | /// m < 0 := 1 |
| 572 | /// |
| 573 | /// Uses the following useful floating point logic, |
| 574 | /// saturate(+a*(-INF)==-INF) := 0 |
| 575 | /// saturate( 0*(-INF)== NaN) := 0 |
| 576 | /// saturate(-a*(-INF)==+INF) := 1 |
| 577 | /// |
| 578 | /// This function is useful when creating masks for branch-free logic. |
| 579 | /// |
| 580 | /// @param [in] m The value to test against 0. |
| 581 | /// |
| 582 | /// @returns |
| 583 | /// 1.0 when the value is negative, or 0.0 when the value is 0 or position. |
| 584 | /// |
| 585 | /// @ingroup GPU |
| 586 | FfxFloat16x2 ffxIsSignedHalf(FfxFloat16x2 m) |
| 587 | { |
| 588 | return ffxSaturate(m * FFX_BROADCAST_FLOAT16X2(FFX_NEGATIVE_INFINITY_HALF)); |
| 589 | } |
| 590 | |
| 591 | /// A single operation to return the following: |
| 592 | /// m = NaN := 0 |
| 593 | /// m >= 0 := 0 |
| 594 | /// m < 0 := 1 |
| 595 | /// |
| 596 | /// Uses the following useful floating point logic, |
| 597 | /// saturate(+a*(-INF)==-INF) := 0 |
| 598 | /// saturate( 0*(-INF)== NaN) := 0 |
| 599 | /// saturate(-a*(-INF)==+INF) := 1 |
| 600 | /// |
| 601 | /// This function is useful when creating masks for branch-free logic. |
| 602 | /// |
| 603 | /// @param [in] m The value to test against 0. |
| 604 | /// |
| 605 | /// @returns |
| 606 | /// 1.0 when the value is negative, or 0.0 when the value is 0 or position. |
| 607 | /// |
| 608 | /// @ingroup GPU |
| 609 | FfxFloat16x3 ffxIsSignedHalf(FfxFloat16x3 m) |
| 610 | { |
| 611 | return ffxSaturate(m * FFX_BROADCAST_FLOAT16X3(FFX_NEGATIVE_INFINITY_HALF)); |
| 612 | } |
| 613 | |
| 614 | /// A single operation to return the following: |
| 615 | /// m = NaN := 0 |
| 616 | /// m >= 0 := 0 |
| 617 | /// m < 0 := 1 |
| 618 | /// |
| 619 | /// Uses the following useful floating point logic, |
| 620 | /// saturate(+a*(-INF)==-INF) := 0 |
| 621 | /// saturate( 0*(-INF)== NaN) := 0 |
| 622 | /// saturate(-a*(-INF)==+INF) := 1 |
| 623 | /// |
| 624 | /// This function is useful when creating masks for branch-free logic. |
| 625 | /// |
| 626 | /// @param [in] m The value to test against 0. |
| 627 | /// |
| 628 | /// @returns |
| 629 | /// 1.0 when the value is negative, or 0.0 when the value is 0 or position. |
| 630 | /// |
| 631 | /// @ingroup GPU |
| 632 | FfxFloat16x4 ffxIsSignedHalf(FfxFloat16x4 m) |
| 633 | { |
| 634 | return ffxSaturate(m * FFX_BROADCAST_FLOAT16X4(FFX_NEGATIVE_INFINITY_HALF)); |
| 635 | } |
| 636 | |
| 637 | /// A single operation to return the following: |
| 638 | /// m = NaN := 1 |
| 639 | /// m > 0 := 0 |
| 640 | /// m <= 0 := 1 |
| 641 | /// |
| 642 | /// This function is useful when creating masks for branch-free logic. |
| 643 | /// |
| 644 | /// @param [in] m The value to test against zero. |
| 645 | /// |
| 646 | /// @returns |
| 647 | /// 1.0 when the value is position, or 0.0 when the value is 0 or negative. |
| 648 | /// |
| 649 | /// @ingroup GPU |
| 650 | FfxFloat16 ffxIsGreaterThanZeroHalf(FfxFloat16 m) |
| 651 | { |
| 652 | return ffxSaturate(m * FFX_BROADCAST_FLOAT16(FFX_POSITIVE_INFINITY_HALF)); |
| 653 | } |
| 654 | |
| 655 | /// A single operation to return the following: |
| 656 | /// m = NaN := 1 |
| 657 | /// m > 0 := 0 |
| 658 | /// m <= 0 := 1 |
| 659 | /// |
| 660 | /// This function is useful when creating masks for branch-free logic. |
| 661 | /// |
| 662 | /// @param [in] m The value to test against zero. |
| 663 | /// |
| 664 | /// @returns |
| 665 | /// 1.0 when the value is position, or 0.0 when the value is 0 or negative. |
| 666 | /// |
| 667 | /// @ingroup GPU |
| 668 | FfxFloat16x2 ffxIsGreaterThanZeroHalf(FfxFloat16x2 m) |
| 669 | { |
| 670 | return ffxSaturate(m * FFX_BROADCAST_FLOAT16X2(FFX_POSITIVE_INFINITY_HALF)); |
| 671 | } |
| 672 | |
| 673 | /// A single operation to return the following: |
| 674 | /// m = NaN := 1 |
| 675 | /// m > 0 := 0 |
| 676 | /// m <= 0 := 1 |
| 677 | /// |
| 678 | /// This function is useful when creating masks for branch-free logic. |
| 679 | /// |
| 680 | /// @param [in] m The value to test against zero. |
| 681 | /// |
| 682 | /// @returns |
| 683 | /// 1.0 when the value is position, or 0.0 when the value is 0 or negative. |
| 684 | /// |
| 685 | /// @ingroup GPU |
| 686 | FfxFloat16x3 ffxIsGreaterThanZeroHalf(FfxFloat16x3 m) |
| 687 | { |
| 688 | return ffxSaturate(m * FFX_BROADCAST_FLOAT16X3(FFX_POSITIVE_INFINITY_HALF)); |
| 689 | } |
| 690 | |
| 691 | /// A single operation to return the following: |
| 692 | /// m = NaN := 1 |
| 693 | /// m > 0 := 0 |
| 694 | /// m <= 0 := 1 |
| 695 | /// |
| 696 | /// This function is useful when creating masks for branch-free logic. |
| 697 | /// |
| 698 | /// @param [in] m The value to test against zero. |
| 699 | /// |
| 700 | /// @returns |
| 701 | /// 1.0 when the value is position, or 0.0 when the value is 0 or negative. |
| 702 | /// |
| 703 | /// @ingroup GPU |
| 704 | FfxFloat16x4 ffxIsGreaterThanZeroHalf(FfxFloat16x4 m) |
| 705 | { |
| 706 | return ffxSaturate(m * FFX_BROADCAST_FLOAT16X4(FFX_POSITIVE_INFINITY_HALF)); |
| 707 | } |
| 708 | |
| 709 | /// Convert a 16bit floating point value to sortable integer. |
| 710 | /// |
| 711 | /// - If sign bit=0, flip the sign bit (positives). |
| 712 | /// - If sign bit=1, flip all bits (negatives). |
| 713 | /// |
| 714 | /// The function has the side effects that: |
| 715 | /// - Larger integers are more positive values. |
| 716 | /// - Float zero is mapped to center of integers (so clear to integer zero is a nice default for atomic max usage). |
| 717 | /// |
| 718 | /// @param [in] x The floating point value to make sortable. |
| 719 | /// |
| 720 | /// @returns |
| 721 | /// The sortable integer value. |
| 722 | /// |
| 723 | /// @ingroup GPU |
| 724 | FfxUInt16 ffxFloatToSortableIntegerHalf(FfxUInt16 x) |
| 725 | { |
| 726 | return x ^ ((ffxBitShiftRightHalf(x, FFX_BROADCAST_UINT16(15))) | FFX_BROADCAST_UINT16(0x8000)); |
| 727 | } |
| 728 | |
| 729 | /// Convert a sortable integer to a 16bit floating point value. |
| 730 | /// |
| 731 | /// The function has the side effects that: |
| 732 | /// - If sign bit=1, flip the sign bit (positives). |
| 733 | /// - If sign bit=0, flip all bits (negatives). |
| 734 | /// |
| 735 | /// @param [in] x The sortable integer value to make floating point. |
| 736 | /// |
| 737 | /// @returns |
| 738 | /// The floating point value. |
| 739 | /// |
| 740 | /// @ingroup GPU |
| 741 | FfxUInt16 ffxSortableIntegerToFloatHalf(FfxUInt16 x) |
| 742 | { |
| 743 | return x ^ ((~ffxBitShiftRightHalf(x, FFX_BROADCAST_UINT16(15))) | FFX_BROADCAST_UINT16(0x8000)); |
| 744 | } |
| 745 | |
| 746 | /// Convert a pair of 16bit floating point values to a pair of sortable integers. |
| 747 | /// |
| 748 | /// - If sign bit=0, flip the sign bit (positives). |
| 749 | /// - If sign bit=1, flip all bits (negatives). |
| 750 | /// |
| 751 | /// The function has the side effects that: |
| 752 | /// - Larger integers are more positive values. |
| 753 | /// - Float zero is mapped to center of integers (so clear to integer zero is a nice default for atomic max usage). |
| 754 | /// |
| 755 | /// @param [in] x The floating point values to make sortable. |
| 756 | /// |
| 757 | /// @returns |
| 758 | /// The sortable integer values. |
| 759 | /// |
| 760 | /// @ingroup GPU |
| 761 | FfxUInt16x2 ffxFloatToSortableIntegerHalf(FfxUInt16x2 x) |
| 762 | { |
| 763 | return x ^ ((ffxBitShiftRightHalf(x, FFX_BROADCAST_UINT16X2(15))) | FFX_BROADCAST_UINT16X2(0x8000)); |
| 764 | } |
| 765 | |
| 766 | /// Convert a pair of sortable integers to a pair of 16bit floating point values. |
| 767 | /// |
| 768 | /// The function has the side effects that: |
| 769 | /// - If sign bit=1, flip the sign bit (positives). |
| 770 | /// - If sign bit=0, flip all bits (negatives). |
| 771 | /// |
| 772 | /// @param [in] x The sortable integer values to make floating point. |
| 773 | /// |
| 774 | /// @returns |
| 775 | /// The floating point values. |
| 776 | /// |
| 777 | /// @ingroup GPU |
| 778 | FfxUInt16x2 ffxSortableIntegerToFloatHalf(FfxUInt16x2 x) |
| 779 | { |
| 780 | return x ^ ((~ffxBitShiftRightHalf(x, FFX_BROADCAST_UINT16X2(15))) | FFX_BROADCAST_UINT16X2(0x8000)); |
| 781 | } |
| 782 | |
| 783 | /// Packs the bytes from the X and Y components of a FfxUInt32x2 into a single 32-bit integer. |
| 784 | /// |
| 785 | /// The resulting integer will contain bytes in the following order, from most to least significant: |
| 786 | /// [Zero] Y0 [Zero] X0 |
| 787 | /// |
| 788 | /// @param [in] i The integer pair to pack. |
| 789 | /// |
| 790 | /// @returns |
| 791 | /// The packed integer value. |
| 792 | /// |
| 793 | /// @ingroup GPU |
| 794 | FfxUInt32 ffxPackBytesZeroY0ZeroX0(FfxUInt32x2 i) |
| 795 | { |
| 796 | return ((i.x) & 0xffu) | ((i.y << 16) & 0xff0000u); |
| 797 | } |
| 798 | |
| 799 | /// Packs the bytes from the X and Y components of a FfxUInt32x2 into a single 32-bit integer. |
| 800 | /// |
| 801 | /// The resulting integer will contain bytes in the following order, from most to least significant: |
| 802 | /// [Zero] Y1 [Zero] X1 |
| 803 | /// |
| 804 | /// @param [in] i The integer pair to pack. |
| 805 | /// |
| 806 | /// @returns |
| 807 | /// The packed integer value. |
| 808 | /// |
| 809 | /// @ingroup GPU |
| 810 | FfxUInt32 ffxPackBytesZeroY1ZeroX1(FfxUInt32x2 i) |
| 811 | { |
| 812 | return ((i.x >> 8) & 0xffu) | ((i.y << 8) & 0xff0000u); |
| 813 | } |
| 814 | |
| 815 | /// Packs the bytes from the X and Y components of a FfxUInt32x2 into a single 32-bit integer. |
| 816 | /// |
| 817 | /// The resulting integer will contain bytes in the following order, from most to least significant: |
| 818 | /// [Zero] Y2 [Zero] X2 |
| 819 | /// |
| 820 | /// @param [in] i The integer pair to pack. |
| 821 | /// |
| 822 | /// @returns |
| 823 | /// The packed integer value. |
| 824 | /// |
| 825 | /// @ingroup GPU |
| 826 | FfxUInt32 ffxPackBytesZeroY2ZeroX2(FfxUInt32x2 i) |
| 827 | { |
| 828 | return ((i.x >> 16) & 0xffu) | ((i.y) & 0xff0000u); |
| 829 | } |
| 830 | |
| 831 | /// Packs the bytes from the X and Y components of a FfxUInt32x2 into a single 32-bit integer. |
| 832 | /// |
| 833 | /// The resulting integer will contain bytes in the following order, from most to least significant: |
| 834 | /// [Zero] Y3 [Zero] X3 |
| 835 | /// |
| 836 | /// @param [in] i The integer pair to pack. |
| 837 | /// |
| 838 | /// @returns |
| 839 | /// The packed integer value. |
| 840 | /// |
| 841 | /// @ingroup GPU |
| 842 | FfxUInt32 ffxPackBytesZeroY3ZeroX3(FfxUInt32x2 i) |
| 843 | { |
| 844 | return ((i.x >> 24) & 0xffu) | ((i.y >> 8) & 0xff0000u); |
| 845 | } |
| 846 | |
| 847 | /// Packs the bytes from the X and Y components of a FfxUInt32x2 into a single 32-bit integer. |
| 848 | /// |
| 849 | /// The resulting integer will contain bytes in the following order, from most to least significant: |
| 850 | /// Y3 Y2 Y1 X0 |
| 851 | /// |
| 852 | /// @param [in] i The integer pair to pack. |
| 853 | /// |
| 854 | /// @returns |
| 855 | /// The packed integer value. |
| 856 | /// |
| 857 | /// @ingroup GPU |
| 858 | FfxUInt32 ffxPackBytesY3Y2Y1X0(FfxUInt32x2 i) |
| 859 | { |
| 860 | return ((i.x) & 0x000000ffu) | (i.y & 0xffffff00u); |
| 861 | } |
| 862 | |
| 863 | /// Packs the bytes from the X and Y components of a FfxUInt32x2 into a single 32-bit integer. |
| 864 | /// |
| 865 | /// The resulting integer will contain bytes in the following order, from most to least significant: |
| 866 | /// Y3 Y2 Y1 X2 |
| 867 | /// |
| 868 | /// @param [in] i The integer pair to pack. |
| 869 | /// |
| 870 | /// @returns |
| 871 | /// The packed integer value. |
| 872 | /// |
| 873 | /// @ingroup GPU |
| 874 | FfxUInt32 ffxPackBytesY3Y2Y1X2(FfxUInt32x2 i) |
| 875 | { |
| 876 | return ((i.x >> 16) & 0x000000ffu) | (i.y & 0xffffff00u); |
| 877 | } |
| 878 | |
| 879 | /// Packs the bytes from the X and Y components of a FfxUInt32x2 into a single 32-bit integer. |
| 880 | /// |
| 881 | /// The resulting integer will contain bytes in the following order, from most to least significant: |
| 882 | /// Y3 Y2 X0 Y0 |
| 883 | /// |
| 884 | /// @param [in] i The integer pair to pack. |
| 885 | /// |
| 886 | /// @returns |
| 887 | /// The packed integer value. |
| 888 | /// |
| 889 | /// @ingroup GPU |
| 890 | FfxUInt32 ffxPackBytesY3Y2X0Y0(FfxUInt32x2 i) |
| 891 | { |
| 892 | return ((i.x << 8) & 0x0000ff00u) | (i.y & 0xffff00ffu); |
| 893 | } |
| 894 | |
| 895 | /// Packs the bytes from the X and Y components of a FfxUInt32x2 into a single 32-bit integer. |
| 896 | /// |
| 897 | /// The resulting integer will contain bytes in the following order, from most to least significant: |
| 898 | /// Y3 Y2 X2 Y0 |
| 899 | /// |
| 900 | /// @param [in] i The integer pair to pack. |
| 901 | /// |
| 902 | /// @returns |
| 903 | /// The packed integer value. |
| 904 | /// |
| 905 | /// @ingroup GPU |
| 906 | FfxUInt32 ffxPackBytesY3Y2X2Y0(FfxUInt32x2 i) |
| 907 | { |
| 908 | return ((i.x >> 8) & 0x0000ff00u) | (i.y & 0xffff00ffu); |
| 909 | } |
| 910 | |
| 911 | /// Packs the bytes from the X and Y components of a FfxUInt32x2 into a single 32-bit integer. |
| 912 | /// |
| 913 | /// The resulting integer will contain bytes in the following order, from most to least significant: |
| 914 | /// Y3 X0 Y1 Y0 |
| 915 | /// |
| 916 | /// @param [in] i The integer pair to pack. |
| 917 | /// |
| 918 | /// @returns |
| 919 | /// The packed integer value. |
| 920 | /// |
| 921 | /// @ingroup GPU |
| 922 | FfxUInt32 ffxPackBytesY3X0Y1Y0(FfxUInt32x2 i) |
| 923 | { |
| 924 | return ((i.x << 16) & 0x00ff0000u) | (i.y & 0xff00ffffu); |
| 925 | } |
| 926 | |
| 927 | /// Packs the bytes from the X and Y components of a FfxUInt32x2 into a single 32-bit integer. |
| 928 | /// |
| 929 | /// The resulting integer will contain bytes in the following order, from most to least significant: |
| 930 | /// Y3 X2 Y1 Y0 |
| 931 | /// |
| 932 | /// @param [in] i The integer pair to pack. |
| 933 | /// |
| 934 | /// @returns |
| 935 | /// The packed integer value. |
| 936 | /// |
| 937 | /// @ingroup GPU |
| 938 | FfxUInt32 ffxPackBytesY3X2Y1Y0(FfxUInt32x2 i) |
| 939 | { |
| 940 | return ((i.x) & 0x00ff0000u) | (i.y & 0xff00ffffu); |
| 941 | } |
| 942 | |
| 943 | /// Packs the bytes from the X and Y components of a FfxUInt32x2 into a single 32-bit integer. |
| 944 | /// |
| 945 | /// The resulting integer will contain bytes in the following order, from most to least significant: |
| 946 | /// X0 Y2 Y1 Y0 |
| 947 | /// |
| 948 | /// @param [in] i The integer pair to pack. |
| 949 | /// |
| 950 | /// @returns |
| 951 | /// The packed integer value. |
| 952 | /// |
| 953 | /// @ingroup GPU |
| 954 | FfxUInt32 ffxPackBytesX0Y2Y1Y0(FfxUInt32x2 i) |
| 955 | { |
| 956 | return ((i.x << 24) & 0xff000000u) | (i.y & 0x00ffffffu); |
| 957 | } |
| 958 | |
| 959 | /// Packs the bytes from the X and Y components of a FfxUInt32x2 into a single 32-bit integer. |
| 960 | /// |
| 961 | /// The resulting integer will contain bytes in the following order, from most to least significant: |
| 962 | /// X2 Y2 Y1 Y0 |
| 963 | /// |
| 964 | /// @param [in] i The integer pair to pack. |
| 965 | /// |
| 966 | /// @returns |
| 967 | /// The packed integer value. |
| 968 | /// |
| 969 | /// @ingroup GPU |
| 970 | FfxUInt32 ffxPackBytesX2Y2Y1Y0(FfxUInt32x2 i) |
| 971 | { |
| 972 | return ((i.x << 8) & 0xff000000u) | (i.y & 0x00ffffffu); |
| 973 | } |
| 974 | |
| 975 | /// Packs the bytes from the X and Y components of a FfxUInt32x2 into a single 32-bit integer. |
| 976 | /// |
| 977 | /// The resulting integer will contain bytes in the following order, from most to least significant: |
| 978 | /// Y2 X2 Y0 X0 |
| 979 | /// |
| 980 | /// @param [in] i The integer pair to pack. |
| 981 | /// |
| 982 | /// @returns |
| 983 | /// The packed integer value. |
| 984 | /// |
| 985 | /// @ingroup GPU |
| 986 | FfxUInt32 ffxPackBytesY2X2Y0X0(FfxUInt32x2 i) |
| 987 | { |
| 988 | return ((i.x) & 0x00ff00ffu) | ((i.y << 8) & 0xff00ff00u); |
| 989 | } |
| 990 | |
| 991 | /// Packs the bytes from the X and Y components of a FfxUInt32x2 into a single 32-bit integer. |
| 992 | /// |
| 993 | /// The resulting integer will contain bytes in the following order, from most to least significant: |
| 994 | /// Y2 Y0 X2 X0 |
| 995 | /// |
| 996 | /// @param [in] i The integer pair to pack. |
| 997 | /// |
| 998 | /// @returns |
| 999 | /// The packed integer value. |
| 1000 | /// |
| 1001 | /// @ingroup GPU |
| 1002 | FfxUInt32 ffxPackBytesY2Y0X2X0(FfxUInt32x2 i) |
| 1003 | { |
| 1004 | return (((i.x) & 0xffu) | ((i.x >> 8) & 0xff00u) | ((i.y << 16) & 0xff0000u) | ((i.y << 8) & 0xff000000u)); |
| 1005 | } |
| 1006 | |
| 1007 | /// Takes two Float16x2 values x and y, normalizes them and builds a single Uint16x2 value in the format {{x0,y0},{x1,y1}}. |
| 1008 | /// |
| 1009 | /// @param [in] x The first float16x2 value to pack. |
| 1010 | /// @param [in] y The second float16x2 value to pack. |
| 1011 | /// |
| 1012 | /// @returns |
| 1013 | /// The packed FfxUInt32x2 value. |
| 1014 | /// |
| 1015 | /// @ingroup GPU |
| 1016 | FfxUInt16x2 ffxPackX0Y0X1Y1UnsignedToUint16x2(FfxFloat16x2 x, FfxFloat16x2 y) |
| 1017 | { |
| 1018 | x *= FFX_BROADCAST_FLOAT16X2(1.0 / 32768.0); |
| 1019 | y *= FFX_BROADCAST_FLOAT16X2(1.0 / 32768.0); |
| 1020 | return FFX_UINT32_TO_UINT16X2(ffxPackBytesY2X2Y0X0(FfxUInt32x2(FFX_UINT16X2_TO_UINT32(FFX_TO_UINT16X2(x)), FFX_UINT16X2_TO_UINT32(FFX_TO_UINT16X2(y))))); |
| 1021 | } |
| 1022 | |
| 1023 | /// Given a FfxUInt32x2 value d, Float16x2 value i and a resulting FfxUInt32x2 value r, this function packs d.x[0:7] into r.x[0:7], |
| 1024 | /// d.y[0:7] into r.y[0:7], i.x[8:15] into r.x[8:15], r.y[8:15] and i.y[0:15] into r.x[16:31], r.y[16:31] using 3 ops. |
| 1025 | /// |
| 1026 | /// r=ffxPermuteUByte0Float16x2ToUint2(d,i) |
| 1027 | /// Where 'k0' is an SGPR with {1.0/32768.0} packed into the lower 16-bits |
| 1028 | /// Where 'k1' is an SGPR with 0x???? |
| 1029 | /// Where 'k2' is an SGPR with 0x???? |
| 1030 | /// V_PK_FMA_F16 i,i,k0.x,0 |
| 1031 | /// V_PERM_B32 r.x,i,i,k1 |
| 1032 | /// V_PERM_B32 r.y,i,i,k2 |
| 1033 | /// |
| 1034 | /// @param [in] d The FfxUInt32x2 value to be packed. |
| 1035 | /// @param [in] i The FfxFloat16x2 value to be packed. |
| 1036 | /// |
| 1037 | /// @returns |
| 1038 | /// The packed FfxUInt32x2 value. |
| 1039 | /// |
| 1040 | /// @ingroup GPU |
| 1041 | FfxUInt32x2 ffxPermuteUByte0Float16x2ToUint2(FfxUInt32x2 d, FfxFloat16x2 i) |
| 1042 | { |
| 1043 | FfxUInt32 b = FFX_UINT16X2_TO_UINT32(FFX_TO_UINT16X2(i * FFX_BROADCAST_FLOAT16X2(1.0 / 32768.0))); |
| 1044 | return FfxUInt32x2(ffxPackBytesY3Y2Y1X0(FfxUInt32x2(d.x, b)), ffxPackBytesY3Y2Y1X2(FfxUInt32x2(d.y, b))); |
| 1045 | } |
| 1046 | |
| 1047 | /// Given a FfxUInt32x2 value d, Float16x2 value i and a resulting FfxUInt32x2 value r, this function packs d.x[0:7] into r.x[8:15], |
| 1048 | /// d.y[0:7] into r.y[8:15], i.x[0:7] into r.x[0:7], r.y[0:7] and i.y[0:15] into r.x[16:31], r.y[16:31] using 3 ops. |
| 1049 | /// |
| 1050 | /// r=ffxPermuteUByte1Float16x2ToUint2(d,i) |
| 1051 | /// Where 'k0' is an SGPR with {1.0/32768.0} packed into the lower 16-bits |
| 1052 | /// Where 'k1' is an SGPR with 0x???? |
| 1053 | /// Where 'k2' is an SGPR with 0x???? |
| 1054 | /// V_PK_FMA_F16 i,i,k0.x,0 |
| 1055 | /// V_PERM_B32 r.x,i,i,k1 |
| 1056 | /// V_PERM_B32 r.y,i,i,k2 |
| 1057 | /// |
| 1058 | /// @param [in] d The FfxUInt32x2 value to be packed. |
| 1059 | /// @param [in] i The FfxFloat16x2 value to be packed. |
| 1060 | /// |
| 1061 | /// @returns |
| 1062 | /// The packed FfxUInt32x2 value. |
| 1063 | /// |
| 1064 | /// @ingroup GPU |
| 1065 | FfxUInt32x2 ffxPermuteUByte1Float16x2ToUint2(FfxUInt32x2 d, FfxFloat16x2 i) |
| 1066 | { |
| 1067 | FfxUInt32 b = FFX_UINT16X2_TO_UINT32(FFX_TO_UINT16X2(i * FFX_BROADCAST_FLOAT16X2(1.0 / 32768.0))); |
| 1068 | return FfxUInt32x2(ffxPackBytesY3Y2X0Y0(FfxUInt32x2(d.x, b)), ffxPackBytesY3Y2X2Y0(FfxUInt32x2(d.y, b))); |
| 1069 | } |
| 1070 | |
| 1071 | /// Given a FfxUInt32x2 value d, Float16x2 value i and a resulting FfxUInt32x2 value r, this function packs d.x[0:7] into r.x[16:23], |
| 1072 | /// d.y[0:7] into r.y[16:23], i.x[0:15] into r.x[0:15], r.y[0:15] and i.y[8:15] into r.x[24:31], r.y[24:31] using 3 ops. |
| 1073 | /// |
| 1074 | /// r=ffxPermuteUByte2Float16x2ToUint2(d,i) |
| 1075 | /// Where 'k0' is an SGPR with {1.0/32768.0} packed into the lower 16-bits |
| 1076 | /// Where 'k1' is an SGPR with 0x???? |
| 1077 | /// Where 'k2' is an SGPR with 0x???? |
| 1078 | /// V_PK_FMA_F16 i,i,k0.x,0 |
| 1079 | /// V_PERM_B32 r.x,i,i,k1 |
| 1080 | /// V_PERM_B32 r.y,i,i,k2 |
| 1081 | /// |
| 1082 | /// @param [in] d The FfxUInt32x2 value to be packed. |
| 1083 | /// @param [in] i The FfxFloat16x2 value to be packed. |
| 1084 | /// |
| 1085 | /// @returns |
| 1086 | /// The packed FfxUInt32x2 value. |
| 1087 | /// |
| 1088 | /// @ingroup GPU |
| 1089 | FfxUInt32x2 ffxPermuteUByte2Float16x2ToUint2(FfxUInt32x2 d, FfxFloat16x2 i) |
| 1090 | { |
| 1091 | FfxUInt32 b = FFX_UINT16X2_TO_UINT32(FFX_TO_UINT16X2(i * FFX_BROADCAST_FLOAT16X2(1.0 / 32768.0))); |
| 1092 | return FfxUInt32x2(ffxPackBytesY3X0Y1Y0(FfxUInt32x2(d.x, b)), ffxPackBytesY3X2Y1Y0(FfxUInt32x2(d.y, b))); |
| 1093 | } |
| 1094 | |
| 1095 | /// Given a FfxUInt32x2 value d, Float16x2 value i and a resulting FfxUInt32x2 value r, this function packs d.x[0:7] into r.x[24:31], |
| 1096 | /// d.y[0:7] into r.y[24:31], i.x[0:15] into r.x[0:15], r.y[0:15] and i.y[0:7] into r.x[16:23], r.y[16:23] using 3 ops. |
| 1097 | /// |
| 1098 | /// r=ffxPermuteUByte3Float16x2ToUint2(d,i) |
| 1099 | /// Where 'k0' is an SGPR with {1.0/32768.0} packed into the lower 16-bits |
| 1100 | /// Where 'k1' is an SGPR with 0x???? |
| 1101 | /// Where 'k2' is an SGPR with 0x???? |
| 1102 | /// V_PK_FMA_F16 i,i,k0.x,0 |
| 1103 | /// V_PERM_B32 r.x,i,i,k1 |
| 1104 | /// V_PERM_B32 r.y,i,i,k2 |
| 1105 | /// |
| 1106 | /// @param [in] d The FfxUInt32x2 value to be packed. |
| 1107 | /// @param [in] i The FfxFloat16x2 value to be packed. |
| 1108 | /// |
| 1109 | /// @returns |
| 1110 | /// The packed FfxUInt32x2 value. |
| 1111 | /// |
| 1112 | /// @ingroup GPU |
| 1113 | FfxUInt32x2 ffxPermuteUByte3Float16x2ToUint2(FfxUInt32x2 d, FfxFloat16x2 i) |
| 1114 | { |
| 1115 | FfxUInt32 b = FFX_UINT16X2_TO_UINT32(FFX_TO_UINT16X2(i * FFX_BROADCAST_FLOAT16X2(1.0 / 32768.0))); |
| 1116 | return FfxUInt32x2(ffxPackBytesX0Y2Y1Y0(FfxUInt32x2(d.x, b)), ffxPackBytesX2Y2Y1Y0(FfxUInt32x2(d.y, b))); |
| 1117 | } |
| 1118 | |
| 1119 | /// Given a FfxUInt32x2 value i and a resulting Float16x2 value r, this function packs i.x[0:7] into r.x[0:7] and i.y[0:7] into r.y[0:7] using 2 ops. |
| 1120 | /// |
| 1121 | /// @param [in] i The FfxUInt32x2 value to be unpacked. |
| 1122 | /// |
| 1123 | /// @returns |
| 1124 | /// The unpacked FfxFloat16x2. |
| 1125 | /// |
| 1126 | /// @ingroup GPU |
| 1127 | FfxFloat16x2 ffxPermuteUByte0Uint2ToFloat16x2(FfxUInt32x2 i) |
| 1128 | { |
| 1129 | return FFX_TO_FLOAT16X2(FFX_UINT32_TO_UINT16X2(ffxPackBytesZeroY0ZeroX0(i))) * FFX_BROADCAST_FLOAT16X2(32768.0); |
| 1130 | } |
| 1131 | |
| 1132 | /// Given a FfxUInt32x2 value i and a resulting Float16x2 value r, this function packs i.x[8:15] into r.x[0:7] and i.y[8:15] into r.y[0:7] using 2 ops. |
| 1133 | /// |
| 1134 | /// @param [in] i The FfxUInt32x2 value to be unpacked. |
| 1135 | /// |
| 1136 | /// @returns |
| 1137 | /// The unpacked FfxFloat16x2. |
| 1138 | /// |
| 1139 | /// @ingroup GPU |
| 1140 | FfxFloat16x2 ffxPermuteUByte1Uint2ToFloat16x2(FfxUInt32x2 i) |
| 1141 | { |
| 1142 | return FFX_TO_FLOAT16X2(FFX_UINT32_TO_UINT16X2(ffxPackBytesZeroY1ZeroX1(i))) * FFX_BROADCAST_FLOAT16X2(32768.0); |
| 1143 | } |
| 1144 | |
| 1145 | /// Given a FfxUInt32x2 value i and a resulting Float16x2 value r, this function packs i.x[16:23] into r.x[0:7] and i.y[16:23] into r.y[0:7] using 2 ops. |
| 1146 | /// |
| 1147 | /// @param [in] i The FfxUInt32x2 value to be unpacked. |
| 1148 | /// |
| 1149 | /// @returns |
| 1150 | /// The unpacked FfxFloat16x2. |
| 1151 | /// |
| 1152 | /// @ingroup GPU |
| 1153 | FfxFloat16x2 ffxPermuteUByte2Uint2ToFloat16x2(FfxUInt32x2 i) |
| 1154 | { |
| 1155 | return FFX_TO_FLOAT16X2(FFX_UINT32_TO_UINT16X2(ffxPackBytesZeroY2ZeroX2(i))) * FFX_BROADCAST_FLOAT16X2(32768.0); |
| 1156 | } |
| 1157 | |
| 1158 | /// Given a FfxUInt32x2 value i and a resulting Float16x2 value r, this function packs i.x[24:31] into r.x[0:7] and i.y[24:31] into r.y[0:7] using 2 ops. |
| 1159 | /// |
| 1160 | /// @param [in] i The FfxUInt32x2 value to be unpacked. |
| 1161 | /// |
| 1162 | /// @returns |
| 1163 | /// The unpacked FfxFloat16x2. |
| 1164 | /// |
| 1165 | /// @ingroup GPU |
| 1166 | FfxFloat16x2 ffxPermuteUByte3Uint2ToFloat16x2(FfxUInt32x2 i) |
| 1167 | { |
| 1168 | return FFX_TO_FLOAT16X2(FFX_UINT32_TO_UINT16X2(ffxPackBytesZeroY3ZeroX3(i))) * FFX_BROADCAST_FLOAT16X2(32768.0); |
| 1169 | } |
| 1170 | |
| 1171 | /// Takes two Float16x2 values x and y, normalizes them and builds a single Uint16x2 value in the format {{x0,y0},{x1,y1}}. |
| 1172 | /// |
| 1173 | /// @param [in] x The first float16x2 value to pack. |
| 1174 | /// @param [in] y The second float16x2 value to pack. |
| 1175 | /// |
| 1176 | /// @returns |
| 1177 | /// The packed FfxUInt32x2 value. |
| 1178 | /// |
| 1179 | /// @ingroup GPU |
| 1180 | FfxUInt16x2 ffxPackX0Y0X1Y1SignedToUint16x2(FfxFloat16x2 x, FfxFloat16x2 y) |
| 1181 | { |
| 1182 | x = x * FFX_BROADCAST_FLOAT16X2(1.0 / 32768.0) + FFX_BROADCAST_FLOAT16X2(0.25 / 32768.0); |
| 1183 | y = y * FFX_BROADCAST_FLOAT16X2(1.0 / 32768.0) + FFX_BROADCAST_FLOAT16X2(0.25 / 32768.0); |
| 1184 | return FFX_UINT32_TO_UINT16X2(ffxPackBytesY2X2Y0X0(FfxUInt32x2(FFX_UINT16X2_TO_UINT32(FFX_TO_UINT16X2(x)), FFX_UINT16X2_TO_UINT32(FFX_TO_UINT16X2(y))))); |
| 1185 | } |
| 1186 | |
| 1187 | /// Given a FfxUInt32x2 value d, Float16x2 value i and a resulting FfxUInt32x2 value r, this function packs d.x[0:7] into r.x[0:7], |
| 1188 | /// d.y[0:7] into r.y[0:7], i.x[8:15] into r.x[8:15], r.y[8:15] and i.y[0:15] into r.x[16:31], r.y[16:31] using 3 ops. |
| 1189 | /// |
| 1190 | /// Handles signed byte values. |
| 1191 | /// |
| 1192 | /// @param [in] d The FfxUInt32x2 value to be packed. |
| 1193 | /// @param [in] i The FfxFloat16x2 value to be packed. |
| 1194 | /// |
| 1195 | /// @returns |
| 1196 | /// The packed FfxUInt32x2 value. |
| 1197 | /// |
| 1198 | /// @ingroup GPU |
| 1199 | FfxUInt32x2 ffxPermuteSByte0Float16x2ToUint2(FfxUInt32x2 d, FfxFloat16x2 i) |
| 1200 | { |
| 1201 | FfxUInt32 b = FFX_UINT16X2_TO_UINT32(FFX_TO_UINT16X2(i * FFX_BROADCAST_FLOAT16X2(1.0 / 32768.0) + FFX_BROADCAST_FLOAT16X2(0.25 / 32768.0))); |
| 1202 | return FfxUInt32x2(ffxPackBytesY3Y2Y1X0(FfxUInt32x2(d.x, b)), ffxPackBytesY3Y2Y1X2(FfxUInt32x2(d.y, b))); |
| 1203 | } |
| 1204 | |
| 1205 | /// Given a FfxUInt32x2 value d, Float16x2 value i and a resulting FfxUInt32x2 value r, this function packs d.x[0:7] into r.x[8:15], |
| 1206 | /// d.y[0:7] into r.y[8:15], i.x[0:7] into r.x[0:7], r.y[0:7] and i.y[0:15] into r.x[16:31], r.y[16:31] using 3 ops. |
| 1207 | /// |
| 1208 | /// Handles signed byte values. |
| 1209 | /// |
| 1210 | /// @param [in] d The FfxUInt32x2 value to be packed. |
| 1211 | /// @param [in] i The FfxFloat16x2 value to be packed. |
| 1212 | /// |
| 1213 | /// @returns |
| 1214 | /// The packed FfxUInt32x2 value. |
| 1215 | /// |
| 1216 | /// @ingroup GPU |
| 1217 | FfxUInt32x2 ffxPermuteSByte1Float16x2ToUint2(FfxUInt32x2 d, FfxFloat16x2 i) |
| 1218 | { |
| 1219 | FfxUInt32 b = FFX_UINT16X2_TO_UINT32(FFX_TO_UINT16X2(i * FFX_BROADCAST_FLOAT16X2(1.0 / 32768.0) + FFX_BROADCAST_FLOAT16X2(0.25 / 32768.0))); |
| 1220 | return FfxUInt32x2(ffxPackBytesY3Y2X0Y0(FfxUInt32x2(d.x, b)), ffxPackBytesY3Y2X2Y0(FfxUInt32x2(d.y, b))); |
| 1221 | } |
| 1222 | |
| 1223 | /// Given a FfxUInt32x2 value d, Float16x2 value i and a resulting FfxUInt32x2 value r, this function packs d.x[0:7] into r.x[16:23], |
| 1224 | /// d.y[0:7] into r.y[16:23], i.x[0:15] into r.x[0:15], r.y[0:15] and i.y[8:15] into r.x[24:31], r.y[24:31] using 3 ops. |
| 1225 | /// |
| 1226 | /// Handles signed byte values. |
| 1227 | /// |
| 1228 | /// @param [in] d The FfxUInt32x2 value to be packed. |
| 1229 | /// @param [in] i The FfxFloat16x2 value to be packed. |
| 1230 | /// |
| 1231 | /// @returns |
| 1232 | /// The packed FfxUInt32x2 value. |
| 1233 | /// |
| 1234 | /// @ingroup GPU |
| 1235 | FfxUInt32x2 ffxPermuteSByte2Float16x2ToUint2(FfxUInt32x2 d, FfxFloat16x2 i) |
| 1236 | { |
| 1237 | FfxUInt32 b = FFX_UINT16X2_TO_UINT32(FFX_TO_UINT16X2(i * FFX_BROADCAST_FLOAT16X2(1.0 / 32768.0) + FFX_BROADCAST_FLOAT16X2(0.25 / 32768.0))); |
| 1238 | return FfxUInt32x2(ffxPackBytesY3X0Y1Y0(FfxUInt32x2(d.x, b)), ffxPackBytesY3X2Y1Y0(FfxUInt32x2(d.y, b))); |
| 1239 | } |
| 1240 | |
| 1241 | /// Given a FfxUInt32x2 value d, Float16x2 value i and a resulting FfxUInt32x2 value r, this function packs d.x[0:7] into r.x[24:31], |
| 1242 | /// d.y[0:7] into r.y[24:31], i.x[0:15] into r.x[0:15], r.y[0:15] and i.y[0:7] into r.x[16:23], r.y[16:23] using 3 ops. |
| 1243 | /// |
| 1244 | /// Handles signed byte values. |
| 1245 | /// |
| 1246 | /// @param [in] d The FfxUInt32x2 value to be packed. |
| 1247 | /// @param [in] i The FfxFloat16x2 value to be packed. |
| 1248 | /// |
| 1249 | /// @returns |
| 1250 | /// The packed FfxUInt32x2 value. |
| 1251 | /// |
| 1252 | /// @ingroup GPU |
| 1253 | FfxUInt32x2 ffxPermuteSByte3Float16x2ToUint2(FfxUInt32x2 d, FfxFloat16x2 i) |
| 1254 | { |
| 1255 | FfxUInt32 b = FFX_UINT16X2_TO_UINT32(FFX_TO_UINT16X2(i * FFX_BROADCAST_FLOAT16X2(1.0 / 32768.0) + FFX_BROADCAST_FLOAT16X2(0.25 / 32768.0))); |
| 1256 | return FfxUInt32x2(ffxPackBytesX0Y2Y1Y0(FfxUInt32x2(d.x, b)), ffxPackBytesX2Y2Y1Y0(FfxUInt32x2(d.y, b))); |
| 1257 | } |
| 1258 | |
| 1259 | /// Given a FfxUInt32x2 value d, Float16x2 value i and a resulting FfxUInt32x2 value r, this function packs d.x[0:7] into r.x[0:7], |
| 1260 | /// d.y[0:7] into r.y[0:7], i.x[8:15] into r.x[8:15], r.y[8:15] and i.y[0:15] into r.x[16:31], r.y[16:31] using 3 ops. |
| 1261 | /// |
| 1262 | /// Zero-based flips the MSB bit of the byte (making 128 "exact zero" actually zero). |
| 1263 | /// This is useful if there is a desire for cleared values to decode as zero. |
| 1264 | /// |
| 1265 | /// Handles signed byte values. |
| 1266 | /// |
| 1267 | /// @param [in] d The FfxUInt32x2 value to be packed. |
| 1268 | /// @param [in] i The FfxFloat16x2 value to be packed. |
| 1269 | /// |
| 1270 | /// @returns |
| 1271 | /// The packed FfxUInt32x2 value. |
| 1272 | /// |
| 1273 | /// @ingroup GPU |
| 1274 | FfxUInt32x2 ffxPermuteZeroBasedSByte0Float16x2ToUint2(FfxUInt32x2 d, FfxFloat16x2 i) |
| 1275 | { |
| 1276 | FfxUInt32 b = FFX_UINT16X2_TO_UINT32(FFX_TO_UINT16X2(i * FFX_BROADCAST_FLOAT16X2(1.0 / 32768.0) + FFX_BROADCAST_FLOAT16X2(0.25 / 32768.0))) ^ 0x00800080u; |
| 1277 | return FfxUInt32x2(ffxPackBytesY3Y2Y1X0(FfxUInt32x2(d.x, b)), ffxPackBytesY3Y2Y1X2(FfxUInt32x2(d.y, b))); |
| 1278 | } |
| 1279 | |
| 1280 | /// Given a FfxUInt32x2 value d, Float16x2 value i and a resulting FfxUInt32x2 value r, this function packs d.x[0:7] into r.x[8:15], |
| 1281 | /// d.y[0:7] into r.y[8:15], i.x[0:7] into r.x[0:7], r.y[0:7] and i.y[0:15] into r.x[16:31], r.y[16:31] using 3 ops. |
| 1282 | /// |
| 1283 | /// Zero-based flips the MSB bit of the byte (making 128 "exact zero" actually zero). |
| 1284 | /// This is useful if there is a desire for cleared values to decode as zero. |
| 1285 | /// |
| 1286 | /// Handles signed byte values. |
| 1287 | /// |
| 1288 | /// @param [in] d The FfxUInt32x2 value to be packed. |
| 1289 | /// @param [in] i The FfxFloat16x2 value to be packed. |
| 1290 | /// |
| 1291 | /// @returns |
| 1292 | /// The packed FfxUInt32x2 value. |
| 1293 | /// |
| 1294 | /// @ingroup GPU |
| 1295 | FfxUInt32x2 ffxPermuteZeroBasedSByte1Float16x2ToUint2(FfxUInt32x2 d, FfxFloat16x2 i) |
| 1296 | { |
| 1297 | FfxUInt32 b = FFX_UINT16X2_TO_UINT32(FFX_TO_UINT16X2(i * FFX_BROADCAST_FLOAT16X2(1.0 / 32768.0) + FFX_BROADCAST_FLOAT16X2(0.25 / 32768.0))) ^ 0x00800080u; |
| 1298 | return FfxUInt32x2(ffxPackBytesY3Y2X0Y0(FfxUInt32x2(d.x, b)), ffxPackBytesY3Y2X2Y0(FfxUInt32x2(d.y, b))); |
| 1299 | } |
| 1300 | |
| 1301 | /// Given a FfxUInt32x2 value d, Float16x2 value i and a resulting FfxUInt32x2 value r, this function packs d.x[0:7] into r.x[16:23], |
| 1302 | /// d.y[0:7] into r.y[16:23], i.x[0:15] into r.x[0:15], r.y[0:15] and i.y[8:15] into r.x[24:31], r.y[24:31] using 3 ops. |
| 1303 | /// |
| 1304 | /// Zero-based flips the MSB bit of the byte (making 128 "exact zero" actually zero). |
| 1305 | /// This is useful if there is a desire for cleared values to decode as zero. |
| 1306 | /// |
| 1307 | /// Handles signed byte values. |
| 1308 | /// |
| 1309 | /// @param [in] d The FfxUInt32x2 value to be packed. |
| 1310 | /// @param [in] i The FfxFloat16x2 value to be packed. |
| 1311 | /// |
| 1312 | /// @returns |
| 1313 | /// The packed FfxUInt32x2 value. |
| 1314 | /// |
| 1315 | /// @ingroup GPU |
| 1316 | FfxUInt32x2 ffxPermuteZeroBasedSByte2Float16x2ToUint2(FfxUInt32x2 d, FfxFloat16x2 i) |
| 1317 | { |
| 1318 | FfxUInt32 b = FFX_UINT16X2_TO_UINT32(FFX_TO_UINT16X2(i * FFX_BROADCAST_FLOAT16X2(1.0 / 32768.0) + FFX_BROADCAST_FLOAT16X2(0.25 / 32768.0))) ^ 0x00800080u; |
| 1319 | return FfxUInt32x2(ffxPackBytesY3X0Y1Y0(FfxUInt32x2(d.x, b)), ffxPackBytesY3X2Y1Y0(FfxUInt32x2(d.y, b))); |
| 1320 | } |
| 1321 | |
| 1322 | /// Given a FfxUInt32x2 value d, Float16x2 value i and a resulting FfxUInt32x2 value r, this function packs d.x[0:7] into r.x[24:31], |
| 1323 | /// d.y[0:7] into r.y[24:31], i.x[0:15] into r.x[0:15], r.y[0:15] and i.y[0:7] into r.x[16:23], r.y[16:23] using 3 ops. |
| 1324 | /// |
| 1325 | /// Zero-based flips the MSB bit of the byte (making 128 "exact zero" actually zero). |
| 1326 | /// This is useful if there is a desire for cleared values to decode as zero. |
| 1327 | /// |
| 1328 | /// Handles signed byte values. |
| 1329 | /// |
| 1330 | /// @param [in] d The FfxUInt32x2 value to be packed. |
| 1331 | /// @param [in] i The FfxFloat16x2 value to be packed. |
| 1332 | /// |
| 1333 | /// @returns |
| 1334 | /// The packed FfxUInt32x2 value. |
| 1335 | /// |
| 1336 | /// @ingroup GPU |
| 1337 | FfxUInt32x2 ffxPermuteZeroBasedSByte3Float16x2ToUint2(FfxUInt32x2 d, FfxFloat16x2 i) |
| 1338 | { |
| 1339 | FfxUInt32 b = FFX_UINT16X2_TO_UINT32(FFX_TO_UINT16X2(i * FFX_BROADCAST_FLOAT16X2(1.0 / 32768.0) + FFX_BROADCAST_FLOAT16X2(0.25 / 32768.0))) ^ 0x00800080u; |
| 1340 | return FfxUInt32x2(ffxPackBytesX0Y2Y1Y0(FfxUInt32x2(d.x, b)), ffxPackBytesX2Y2Y1Y0(FfxUInt32x2(d.y, b))); |
| 1341 | } |
| 1342 | |
| 1343 | /// Given a FfxUInt32x2 value i and a resulting Float16x2 value r, this function packs i.x[0:7] into r.x[0:7] and i.y[0:7] into r.y[0:7] using 2 ops. |
| 1344 | /// |
| 1345 | /// Handles signed byte values. |
| 1346 | /// |
| 1347 | /// @param [in] i The FfxUInt32x2 value to be unpacked. |
| 1348 | /// |
| 1349 | /// @returns |
| 1350 | /// The unpacked FfxFloat16x2. |
| 1351 | /// |
| 1352 | /// @ingroup GPU |
| 1353 | FfxFloat16x2 ffxPermuteSByte0Uint2ToFloat16x2(FfxUInt32x2 i) |
| 1354 | { |
| 1355 | return FFX_TO_FLOAT16X2(FFX_UINT32_TO_UINT16X2(ffxPackBytesZeroY0ZeroX0(i))) * FFX_BROADCAST_FLOAT16X2(32768.0) - FFX_BROADCAST_FLOAT16X2(0.25); |
| 1356 | } |
| 1357 | |
| 1358 | /// Given a FfxUInt32x2 value i and a resulting Float16x2 value r, this function packs i.x[8:15] into r.x[0:7] and i.y[8:15] into r.y[0:7] using 2 ops. |
| 1359 | /// |
| 1360 | /// Handles signed byte values. |
| 1361 | /// |
| 1362 | /// @param [in] i The FfxUInt32x2 value to be unpacked. |
| 1363 | /// |
| 1364 | /// @returns |
| 1365 | /// The unpacked FfxFloat16x2. |
| 1366 | /// |
| 1367 | /// @ingroup GPU |
| 1368 | FfxFloat16x2 ffxPermuteSByte1Uint2ToFloat16x2(FfxUInt32x2 i) |
| 1369 | { |
| 1370 | return FFX_TO_FLOAT16X2(FFX_UINT32_TO_UINT16X2(ffxPackBytesZeroY1ZeroX1(i))) * FFX_BROADCAST_FLOAT16X2(32768.0) - FFX_BROADCAST_FLOAT16X2(0.25); |
| 1371 | } |
| 1372 | |
| 1373 | /// Given a FfxUInt32x2 value i and a resulting Float16x2 value r, this function packs i.x[16:23] into r.x[0:7] and i.y[16:23] into r.y[0:7] using 2 ops. |
| 1374 | /// |
| 1375 | /// Handles signed byte values. |
| 1376 | /// |
| 1377 | /// @param [in] i The FfxUInt32x2 value to be unpacked. |
| 1378 | /// |
| 1379 | /// @returns |
| 1380 | /// The unpacked FfxFloat16x2. |
| 1381 | /// |
| 1382 | /// @ingroup GPU |
| 1383 | FfxFloat16x2 ffxPermuteSByte2Uint2ToFloat16x2(FfxUInt32x2 i) |
| 1384 | { |
| 1385 | return FFX_TO_FLOAT16X2(FFX_UINT32_TO_UINT16X2(ffxPackBytesZeroY2ZeroX2(i))) * FFX_BROADCAST_FLOAT16X2(32768.0) - FFX_BROADCAST_FLOAT16X2(0.25); |
| 1386 | } |
| 1387 | |
| 1388 | /// Given a FfxUInt32x2 value i and a resulting Float16x2 value r, this function packs i.x[24:31] into r.x[0:7] and i.y[24:31] into r.y[0:7] using 2 ops. |
| 1389 | /// |
| 1390 | /// Handles signed byte values. |
| 1391 | /// |
| 1392 | /// @param [in] i The FfxUInt32x2 value to be unpacked. |
| 1393 | /// |
| 1394 | /// @returns |
| 1395 | /// The unpacked FfxFloat16x2. |
| 1396 | /// |
| 1397 | /// @ingroup GPU |
| 1398 | FfxFloat16x2 ffxPermuteSByte3Uint2ToFloat16x2(FfxUInt32x2 i) |
| 1399 | { |
| 1400 | return FFX_TO_FLOAT16X2(FFX_UINT32_TO_UINT16X2(ffxPackBytesZeroY3ZeroX3(i))) * FFX_BROADCAST_FLOAT16X2(32768.0) - FFX_BROADCAST_FLOAT16X2(0.25); |
| 1401 | } |
| 1402 | |
| 1403 | /// Given a FfxUInt32x2 value i and a resulting Float16x2 value r, this function packs i.x[0:7] into r.x[0:7] and i.y[0:7] into r.y[0:7] using 2 ops. |
| 1404 | /// |
| 1405 | /// Handles signed byte values. |
| 1406 | /// |
| 1407 | /// @param [in] i The FfxUInt32x2 value to be unpacked. |
| 1408 | /// |
| 1409 | /// @returns |
| 1410 | /// The unpacked FfxFloat16x2. |
| 1411 | /// |
| 1412 | /// @ingroup GPU |
| 1413 | FfxFloat16x2 ffxPermuteZeroBasedSByte0Uint2ToFloat16x2(FfxUInt32x2 i) |
| 1414 | { |
| 1415 | return FFX_TO_FLOAT16X2(FFX_UINT32_TO_UINT16X2(ffxPackBytesZeroY0ZeroX0(i) ^ 0x00800080u)) * FFX_BROADCAST_FLOAT16X2(32768.0) - FFX_BROADCAST_FLOAT16X2(0.25); |
| 1416 | } |
| 1417 | |
| 1418 | /// Given a FfxUInt32x2 value i and a resulting Float16x2 value r, this function packs i.x[8:15] into r.x[0:7] and i.y[8:15] into r.y[0:7] using 2 ops. |
| 1419 | /// |
| 1420 | /// Handles signed byte values. |
| 1421 | /// |
| 1422 | /// @param [in] i The FfxUInt32x2 value to be unpacked. |
| 1423 | /// |
| 1424 | /// @returns |
| 1425 | /// The unpacked FfxFloat16x2. |
| 1426 | /// |
| 1427 | /// @ingroup GPU |
| 1428 | FfxFloat16x2 ffxPermuteZeroBasedSByte1Uint2ToFloat16x2(FfxUInt32x2 i) |
| 1429 | { |
| 1430 | return FFX_TO_FLOAT16X2(FFX_UINT32_TO_UINT16X2(ffxPackBytesZeroY1ZeroX1(i) ^ 0x00800080u)) * FFX_BROADCAST_FLOAT16X2(32768.0) - FFX_BROADCAST_FLOAT16X2(0.25); |
| 1431 | } |
| 1432 | |
| 1433 | /// Given a FfxUInt32x2 value i and a resulting Float16x2 value r, this function packs i.x[16:23] into r.x[0:7] and i.y[16:23] into r.y[0:7] using 2 ops. |
| 1434 | /// |
| 1435 | /// Handles signed byte values. |
| 1436 | /// |
| 1437 | /// @param [in] i The FfxUInt32x2 value to be unpacked. |
| 1438 | /// |
| 1439 | /// @returns |
| 1440 | /// The unpacked FfxFloat16x2. |
| 1441 | /// |
| 1442 | /// @ingroup GPU |
| 1443 | FfxFloat16x2 ffxPermuteZeroBasedSByte2Uint2ToFloat16x2(FfxUInt32x2 i) |
| 1444 | { |
| 1445 | return FFX_TO_FLOAT16X2(FFX_UINT32_TO_UINT16X2(ffxPackBytesZeroY2ZeroX2(i) ^ 0x00800080u)) * FFX_BROADCAST_FLOAT16X2(32768.0) - FFX_BROADCAST_FLOAT16X2(0.25); |
| 1446 | } |
| 1447 | |
| 1448 | /// Given a FfxUInt32x2 value i and a resulting Float16x2 value r, this function packs i.x[24:31] into r.x[0:7] and i.y[24:31] into r.y[0:7] using 2 ops. |
| 1449 | /// |
| 1450 | /// Handles signed byte values. |
| 1451 | /// |
| 1452 | /// @param [in] i The FfxUInt32x2 value to be unpacked. |
| 1453 | /// |
| 1454 | /// @returns |
| 1455 | /// The unpacked FfxFloat16x2. |
| 1456 | /// |
| 1457 | /// @ingroup GPU |
| 1458 | FfxFloat16x2 ffxPermuteZeroBasedSByte3Uint2ToFloat16x2(FfxUInt32x2 i) |
| 1459 | { |
| 1460 | return FFX_TO_FLOAT16X2(FFX_UINT32_TO_UINT16X2(ffxPackBytesZeroY3ZeroX3(i) ^ 0x00800080u)) * FFX_BROADCAST_FLOAT16X2(32768.0) - FFX_BROADCAST_FLOAT16X2(0.25); |
| 1461 | } |
| 1462 | |
| 1463 | /// Calculate a half-precision low-quality approximation for the square root of a value. |
| 1464 | /// |
| 1465 | /// For additional information on the approximation family of functions, you can refer to Michal Drobot's excellent |
| 1466 | /// presentation materials: |
| 1467 | /// |
| 1468 | /// - https://michaldrobot.files.wordpress.com/2014/05/gcn_alu_opt_digitaldragons2014.pdf |
| 1469 | /// - https://github.com/michaldrobot/ShaderFastLibs/blob/master/ShaderFastMathLib.h |
| 1470 | /// |
| 1471 | /// @param [in] a The value to calculate an approximate to the square root for. |
| 1472 | /// |
| 1473 | /// @returns |
| 1474 | /// An approximation of the square root, estimated to low quality. |
| 1475 | /// |
| 1476 | /// @ingroup GPU |
| 1477 | FfxFloat16 ffxApproximateSqrtHalf(FfxFloat16 a) |
| 1478 | { |
| 1479 | return FFX_TO_FLOAT16((FFX_TO_UINT16(a) >> FFX_BROADCAST_UINT16(1)) + FFX_BROADCAST_UINT16(0x1de2)); |
| 1480 | } |
| 1481 | |
| 1482 | /// Calculate a half-precision low-quality approximation for the square root of a value. |
| 1483 | /// |
| 1484 | /// For additional information on the approximation family of functions, you can refer to Michal Drobot's excellent |
| 1485 | /// presentation materials: |
| 1486 | /// |
| 1487 | /// - https://michaldrobot.files.wordpress.com/2014/05/gcn_alu_opt_digitaldragons2014.pdf |
| 1488 | /// - https://github.com/michaldrobot/ShaderFastLibs/blob/master/ShaderFastMathLib.h |
| 1489 | /// |
| 1490 | /// @param [in] a The value to calculate an approximate to the square root for. |
| 1491 | /// |
| 1492 | /// @returns |
| 1493 | /// An approximation of the square root, estimated to low quality. |
| 1494 | /// |
| 1495 | /// @ingroup GPU |
| 1496 | FfxFloat16x2 ffxApproximateSqrtHalf(FfxFloat16x2 a) |
| 1497 | { |
| 1498 | return FFX_TO_FLOAT16X2((FFX_TO_UINT16X2(a) >> FFX_BROADCAST_UINT16X2(1)) + FFX_BROADCAST_UINT16X2(0x1de2)); |
| 1499 | } |
| 1500 | |
| 1501 | /// Calculate a half-precision low-quality approximation for the square root of a value. |
| 1502 | /// |
| 1503 | /// For additional information on the approximation family of functions, you can refer to Michal Drobot's excellent |
| 1504 | /// presentation materials: |
| 1505 | /// |
| 1506 | /// - https://michaldrobot.files.wordpress.com/2014/05/gcn_alu_opt_digitaldragons2014.pdf |
| 1507 | /// - https://github.com/michaldrobot/ShaderFastLibs/blob/master/ShaderFastMathLib.h |
| 1508 | /// |
| 1509 | /// @param [in] a The value to calculate an approximate to the square root for. |
| 1510 | /// |
| 1511 | /// @returns |
| 1512 | /// An approximation of the square root, estimated to low quality. |
| 1513 | /// |
| 1514 | /// @ingroup GPU |
| 1515 | FfxFloat16x3 ffxApproximateSqrtHalf(FfxFloat16x3 a) |
| 1516 | { |
| 1517 | return FFX_TO_FLOAT16X3((FFX_TO_UINT16X3(a) >> FFX_BROADCAST_UINT16X3(1)) + FFX_BROADCAST_UINT16X3(0x1de2)); |
| 1518 | } |
| 1519 | |
| 1520 | /// Calculate a half-precision low-quality approximation for the reciprocal of a value. |
| 1521 | /// |
| 1522 | /// For additional information on the approximation family of functions, you can refer to Michal Drobot's excellent |
| 1523 | /// presentation materials: |
| 1524 | /// |
| 1525 | /// - https://michaldrobot.files.wordpress.com/2014/05/gcn_alu_opt_digitaldragons2014.pdf |
| 1526 | /// - https://github.com/michaldrobot/ShaderFastLibs/blob/master/ShaderFastMathLib.h |
| 1527 | /// |
| 1528 | /// @param [in] a The value to calculate an approximate to the reciprocal for. |
| 1529 | /// |
| 1530 | /// @returns |
| 1531 | /// An approximation of the reciprocal, estimated to low quality. |
| 1532 | /// |
| 1533 | /// @ingroup GPU |
| 1534 | FfxFloat16 ffxApproximateReciprocalHalf(FfxFloat16 a) |
| 1535 | { |
| 1536 | return FFX_TO_FLOAT16(FFX_BROADCAST_UINT16(0x7784) - FFX_TO_UINT16(a)); |
| 1537 | } |
| 1538 | |
| 1539 | /// Calculate a half-precision low-quality approximation for the reciprocal of a value. |
| 1540 | /// |
| 1541 | /// For additional information on the approximation family of functions, you can refer to Michal Drobot's excellent |
| 1542 | /// presentation materials: |
| 1543 | /// |
| 1544 | /// - https://michaldrobot.files.wordpress.com/2014/05/gcn_alu_opt_digitaldragons2014.pdf |
| 1545 | /// - https://github.com/michaldrobot/ShaderFastLibs/blob/master/ShaderFastMathLib.h |
| 1546 | /// |
| 1547 | /// @param [in] a The value to calculate an approximate to the reciprocal for. |
| 1548 | /// |
| 1549 | /// @returns |
| 1550 | /// An approximation of the reciprocal, estimated to low quality. |
| 1551 | /// |
| 1552 | /// @ingroup GPU |
| 1553 | FfxFloat16x2 ffxApproximateReciprocalHalf(FfxFloat16x2 a) |
| 1554 | { |
| 1555 | return FFX_TO_FLOAT16X2(FFX_BROADCAST_UINT16X2(0x7784) - FFX_TO_UINT16X2(a)); |
| 1556 | } |
| 1557 | |
| 1558 | /// Calculate a half-precision low-quality approximation for the reciprocal of a value. |
| 1559 | /// |
| 1560 | /// For additional information on the approximation family of functions, you can refer to Michal Drobot's excellent |
| 1561 | /// presentation materials: |
| 1562 | /// |
| 1563 | /// - https://michaldrobot.files.wordpress.com/2014/05/gcn_alu_opt_digitaldragons2014.pdf |
| 1564 | /// - https://github.com/michaldrobot/ShaderFastLibs/blob/master/ShaderFastMathLib.h |
| 1565 | /// |
| 1566 | /// @param [in] a The value to calculate an approximate to the reciprocal for. |
| 1567 | /// |
| 1568 | /// @returns |
| 1569 | /// An approximation of the reciprocal, estimated to low quality. |
| 1570 | /// |
| 1571 | /// @ingroup GPU |
| 1572 | FfxFloat16x3 ffxApproximateReciprocalHalf(FfxFloat16x3 a) |
| 1573 | { |
| 1574 | return FFX_TO_FLOAT16X3(FFX_BROADCAST_UINT16X3(0x7784) - FFX_TO_UINT16X3(a)); |
| 1575 | } |
| 1576 | |
| 1577 | /// Calculate a half-precision low-quality approximation for the reciprocal of a value. |
| 1578 | /// |
| 1579 | /// For additional information on the approximation family of functions, you can refer to Michal Drobot's excellent |
| 1580 | /// presentation materials: |
| 1581 | /// |
| 1582 | /// - https://michaldrobot.files.wordpress.com/2014/05/gcn_alu_opt_digitaldragons2014.pdf |
| 1583 | /// - https://github.com/michaldrobot/ShaderFastLibs/blob/master/ShaderFastMathLib.h |
| 1584 | /// |
| 1585 | /// @param [in] a The value to calculate an approximate to the reciprocal for. |
| 1586 | /// |
| 1587 | /// @returns |
| 1588 | /// An approximation of the reciprocal, estimated to low quality. |
| 1589 | /// |
| 1590 | /// @ingroup GPU |
| 1591 | FfxFloat16x4 ffxApproximateReciprocalHalf(FfxFloat16x4 a) |
| 1592 | { |
| 1593 | return FFX_TO_FLOAT16X4(FFX_BROADCAST_UINT16X4(0x7784) - FFX_TO_UINT16X4(a)); |
| 1594 | } |
| 1595 | |
| 1596 | /// Calculate a half-precision medium-quality approximation for the reciprocal of a value. |
| 1597 | /// |
| 1598 | /// For additional information on the approximation family of functions, you can refer to Michal Drobot's excellent |
| 1599 | /// presentation materials: |
| 1600 | /// |
| 1601 | /// - https://michaldrobot.files.wordpress.com/2014/05/gcn_alu_opt_digitaldragons2014.pdf |
| 1602 | /// - https://github.com/michaldrobot/ShaderFastLibs/blob/master/ShaderFastMathLib.h |
| 1603 | /// |
| 1604 | /// @param [in] a The value to calculate an approximate to the reciprocal for. |
| 1605 | /// |
| 1606 | /// @returns |
| 1607 | /// An approximation of the reciprocal, estimated to medium quality. |
| 1608 | /// |
| 1609 | /// @ingroup GPU |
| 1610 | FfxFloat16 ffxApproximateReciprocalMediumHalf(FfxFloat16 a) |
| 1611 | { |
| 1612 | FfxFloat16 b = FFX_TO_FLOAT16(FFX_BROADCAST_UINT16(0x778d) - FFX_TO_UINT16(a)); |
| 1613 | return b * (-b * a + FFX_BROADCAST_FLOAT16(2.0)); |
| 1614 | } |
| 1615 | |
| 1616 | /// Calculate a half-precision medium-quality approximation for the reciprocal of a value. |
| 1617 | /// |
| 1618 | /// For additional information on the approximation family of functions, you can refer to Michal Drobot's excellent |
| 1619 | /// presentation materials: |
| 1620 | /// |
| 1621 | /// - https://michaldrobot.files.wordpress.com/2014/05/gcn_alu_opt_digitaldragons2014.pdf |
| 1622 | /// - https://github.com/michaldrobot/ShaderFastLibs/blob/master/ShaderFastMathLib.h |
| 1623 | /// |
| 1624 | /// @param [in] a The value to calculate an approximate to the reciprocal for. |
| 1625 | /// |
| 1626 | /// @returns |
| 1627 | /// An approximation of the reciprocal, estimated to medium quality. |
| 1628 | /// |
| 1629 | /// @ingroup GPU |
| 1630 | FfxFloat16x2 ffxApproximateReciprocalMediumHalf(FfxFloat16x2 a) |
| 1631 | { |
| 1632 | FfxFloat16x2 b = FFX_TO_FLOAT16X2(FFX_BROADCAST_UINT16X2(0x778d) - FFX_TO_UINT16X2(a)); |
| 1633 | return b * (-b * a + FFX_BROADCAST_FLOAT16X2(2.0)); |
| 1634 | } |
| 1635 | |
| 1636 | /// Calculate a half-precision medium-quality approximation for the reciprocal of a value. |
| 1637 | /// |
| 1638 | /// For additional information on the approximation family of functions, you can refer to Michal Drobot's excellent |
| 1639 | /// presentation materials: |
| 1640 | /// |
| 1641 | /// - https://michaldrobot.files.wordpress.com/2014/05/gcn_alu_opt_digitaldragons2014.pdf |
| 1642 | /// - https://github.com/michaldrobot/ShaderFastLibs/blob/master/ShaderFastMathLib.h |
| 1643 | /// |
| 1644 | /// @param [in] a The value to calculate an approximate to the reciprocal for. |
| 1645 | /// |
| 1646 | /// @returns |
| 1647 | /// An approximation of the reciprocal, estimated to medium quality. |
| 1648 | /// |
| 1649 | /// @ingroup GPU |
| 1650 | FfxFloat16x3 ffxApproximateReciprocalMediumHalf(FfxFloat16x3 a) |
| 1651 | { |
| 1652 | FfxFloat16x3 b = FFX_TO_FLOAT16X3(FFX_BROADCAST_UINT16X3(0x778d) - FFX_TO_UINT16X3(a)); |
| 1653 | return b * (-b * a + FFX_BROADCAST_FLOAT16X3(2.0)); |
| 1654 | } |
| 1655 | |
| 1656 | /// Calculate a half-precision medium-quality approximation for the reciprocal of a value. |
| 1657 | /// |
| 1658 | /// For additional information on the approximation family of functions, you can refer to Michal Drobot's excellent |
| 1659 | /// presentation materials: |
| 1660 | /// |
| 1661 | /// - https://michaldrobot.files.wordpress.com/2014/05/gcn_alu_opt_digitaldragons2014.pdf |
| 1662 | /// - https://github.com/michaldrobot/ShaderFastLibs/blob/master/ShaderFastMathLib.h |
| 1663 | /// |
| 1664 | /// @param [in] a The value to calculate an approximate to the reciprocal for. |
| 1665 | /// |
| 1666 | /// @returns |
| 1667 | /// An approximation of the reciprocal, estimated to medium quality. |
| 1668 | /// |
| 1669 | /// @ingroup GPU |
| 1670 | FfxFloat16x4 ffxApproximateReciprocalMediumHalf(FfxFloat16x4 a) |
| 1671 | { |
| 1672 | FfxFloat16x4 b = FFX_TO_FLOAT16X4(FFX_BROADCAST_UINT16X4(0x778d) - FFX_TO_UINT16X4(a)); |
| 1673 | return b * (-b * a + FFX_BROADCAST_FLOAT16X4(2.0)); |
| 1674 | } |
| 1675 | |
| 1676 | /// Calculate a half-precision low-quality approximation for the reciprocal of the square root of a value. |
| 1677 | /// |
| 1678 | /// For additional information on the approximation family of functions, you can refer to Michal Drobot's excellent |
| 1679 | /// presentation materials: |
| 1680 | /// |
| 1681 | /// - https://michaldrobot.files.wordpress.com/2014/05/gcn_alu_opt_digitaldragons2014.pdf |
| 1682 | /// - https://github.com/michaldrobot/ShaderFastLibs/blob/master/ShaderFastMathLib.h |
| 1683 | /// |
| 1684 | /// @param [in] a The value to calculate an approximate to the reciprocal of the square root for. |
| 1685 | /// |
| 1686 | /// @returns |
| 1687 | /// An approximation of the reciprocal of the square root, estimated to low quality. |
| 1688 | /// |
| 1689 | /// @ingroup GPU |
| 1690 | FfxFloat16 ffxApproximateReciprocalSquareRootHalf(FfxFloat16 a) |
| 1691 | { |
| 1692 | return FFX_TO_FLOAT16(FFX_BROADCAST_UINT16(0x59a3) - (FFX_TO_UINT16(a) >> FFX_BROADCAST_UINT16(1))); |
| 1693 | } |
| 1694 | |
| 1695 | /// Calculate a half-precision low-quality approximation for the reciprocal of the square root of a value. |
| 1696 | /// |
| 1697 | /// For additional information on the approximation family of functions, you can refer to Michal Drobot's excellent |
| 1698 | /// presentation materials: |
| 1699 | /// |
| 1700 | /// - https://michaldrobot.files.wordpress.com/2014/05/gcn_alu_opt_digitaldragons2014.pdf |
| 1701 | /// - https://github.com/michaldrobot/ShaderFastLibs/blob/master/ShaderFastMathLib.h |
| 1702 | /// |
| 1703 | /// @param [in] a The value to calculate an approximate to the reciprocal of the square root for. |
| 1704 | /// |
| 1705 | /// @returns |
| 1706 | /// An approximation of the reciprocal of the square root, estimated to low quality. |
| 1707 | /// |
| 1708 | /// @ingroup GPU |
| 1709 | FfxFloat16x2 ffxApproximateReciprocalSquareRootHalf(FfxFloat16x2 a) |
| 1710 | { |
| 1711 | return FFX_TO_FLOAT16X2(FFX_BROADCAST_UINT16X2(0x59a3) - (FFX_TO_UINT16X2(a) >> FFX_BROADCAST_UINT16X2(1))); |
| 1712 | } |
| 1713 | |
| 1714 | /// Calculate a half-precision low-quality approximation for the reciprocal of the square root of a value. |
| 1715 | /// |
| 1716 | /// For additional information on the approximation family of functions, you can refer to Michal Drobot's excellent |
| 1717 | /// presentation materials: |
| 1718 | /// |
| 1719 | /// - https://michaldrobot.files.wordpress.com/2014/05/gcn_alu_opt_digitaldragons2014.pdf |
| 1720 | /// - https://github.com/michaldrobot/ShaderFastLibs/blob/master/ShaderFastMathLib.h |
| 1721 | /// |
| 1722 | /// @param [in] a The value to calculate an approximate to the reciprocal of the square root for. |
| 1723 | /// |
| 1724 | /// @returns |
| 1725 | /// An approximation of the reciprocal of the square root, estimated to low quality. |
| 1726 | /// |
| 1727 | /// @ingroup GPU |
| 1728 | FfxFloat16x3 ffxApproximateReciprocalSquareRootHalf(FfxFloat16x3 a) |
| 1729 | { |
| 1730 | return FFX_TO_FLOAT16X3(FFX_BROADCAST_UINT16X3(0x59a3) - (FFX_TO_UINT16X3(a) >> FFX_BROADCAST_UINT16X3(1))); |
| 1731 | } |
| 1732 | |
| 1733 | /// Calculate a half-precision low-quality approximation for the reciprocal of the square root of a value. |
| 1734 | /// |
| 1735 | /// For additional information on the approximation family of functions, you can refer to Michal Drobot's excellent |
| 1736 | /// presentation materials: |
| 1737 | /// |
| 1738 | /// - https://michaldrobot.files.wordpress.com/2014/05/gcn_alu_opt_digitaldragons2014.pdf |
| 1739 | /// - https://github.com/michaldrobot/ShaderFastLibs/blob/master/ShaderFastMathLib.h |
| 1740 | /// |
| 1741 | /// @param [in] a The value to calculate an approximate to the reciprocal of the square root for. |
| 1742 | /// |
| 1743 | /// @returns |
| 1744 | /// An approximation of the reciprocal of the square root, estimated to low quality. |
| 1745 | /// |
| 1746 | /// @ingroup GPU |
| 1747 | FfxFloat16x4 ffxApproximateReciprocalSquareRootHalf(FfxFloat16x4 a) |
| 1748 | { |
| 1749 | return FFX_TO_FLOAT16X4(FFX_BROADCAST_UINT16X4(0x59a3) - (FFX_TO_UINT16X4(a) >> FFX_BROADCAST_UINT16X4(1))); |
| 1750 | } |
| 1751 | |
| 1752 | /// An approximation of sine. |
| 1753 | /// |
| 1754 | /// Valid input range is {-1 to 1} representing {0 to 2 pi}, and the output range |
| 1755 | /// is {-1/4 to 1/4} representing {-1 to 1}. |
| 1756 | /// |
| 1757 | /// @param [in] x The value to calculate approximate sine for. |
| 1758 | /// |
| 1759 | /// @returns |
| 1760 | /// The approximate sine of <c><i>value</i></c>. |
| 1761 | FfxFloat16 ffxParabolicSinHalf(FfxFloat16 x) |
| 1762 | { |
| 1763 | return x * abs(x) - x; |
| 1764 | } |
| 1765 | |
| 1766 | /// An approximation of sine. |
| 1767 | /// |
| 1768 | /// Valid input range is {-1 to 1} representing {0 to 2 pi}, and the output range |
| 1769 | /// is {-1/4 to 1/4} representing {-1 to 1}. |
| 1770 | /// |
| 1771 | /// @param [in] x The value to calculate approximate sine for. |
| 1772 | /// |
| 1773 | /// @returns |
| 1774 | /// The approximate sine of <c><i>value</i></c>. |
| 1775 | FfxFloat16x2 ffxParabolicSinHalf(FfxFloat16x2 x) |
| 1776 | { |
| 1777 | return x * abs(x) - x; |
| 1778 | } |
| 1779 | |
| 1780 | /// An approximation of cosine. |
| 1781 | /// |
| 1782 | /// Valid input range is {-1 to 1} representing {0 to 2 pi}, and the output range |
| 1783 | /// is {-1/4 to 1/4} representing {-1 to 1}. |
| 1784 | /// |
| 1785 | /// @param [in] x The value to calculate approximate cosine for. |
| 1786 | /// |
| 1787 | /// @returns |
| 1788 | /// The approximate cosine of <c><i>value</i></c>. |
| 1789 | FfxFloat16 ffxParabolicCosHalf(FfxFloat16 x) |
| 1790 | { |
| 1791 | x = ffxFract(x * FFX_BROADCAST_FLOAT16(0.5) + FFX_BROADCAST_FLOAT16(0.75)); |
| 1792 | x = x * FFX_BROADCAST_FLOAT16(2.0) - FFX_BROADCAST_FLOAT16(1.0); |
| 1793 | return ffxParabolicSinHalf(x); |
| 1794 | } |
| 1795 | |
| 1796 | /// An approximation of cosine. |
| 1797 | /// |
| 1798 | /// Valid input range is {-1 to 1} representing {0 to 2 pi}, and the output range |
| 1799 | /// is {-1/4 to 1/4} representing {-1 to 1}. |
| 1800 | /// |
| 1801 | /// @param [in] x The value to calculate approximate cosine for. |
| 1802 | /// |
| 1803 | /// @returns |
| 1804 | /// The approximate cosine of <c><i>value</i></c>. |
| 1805 | FfxFloat16x2 ffxParabolicCosHalf(FfxFloat16x2 x) |
| 1806 | { |
| 1807 | x = ffxFract(x * FFX_BROADCAST_FLOAT16X2(0.5) + FFX_BROADCAST_FLOAT16X2(0.75)); |
| 1808 | x = x * FFX_BROADCAST_FLOAT16X2(2.0) - FFX_BROADCAST_FLOAT16X2(1.0); |
| 1809 | return ffxParabolicSinHalf(x); |
| 1810 | } |
| 1811 | |
| 1812 | /// An approximation of both sine and cosine. |
| 1813 | /// |
| 1814 | /// Valid input range is {-1 to 1} representing {0 to 2 pi}, and the output range |
| 1815 | /// is {-1/4 to 1/4} representing {-1 to 1}. |
| 1816 | /// |
| 1817 | /// @param [in] x The value to calculate approximate cosine for. |
| 1818 | /// |
| 1819 | /// @returns |
| 1820 | /// A <c><i>FfxFloat32x2</i></c> containing approximations of both sine and cosine of <c><i>value</i></c>. |
| 1821 | FfxFloat16x2 ffxParabolicSinCosHalf(FfxFloat16 x) |
| 1822 | { |
| 1823 | FfxFloat16 y = ffxFract(x * FFX_BROADCAST_FLOAT16(0.5) + FFX_BROADCAST_FLOAT16(0.75)); |
| 1824 | y = y * FFX_BROADCAST_FLOAT16(2.0) - FFX_BROADCAST_FLOAT16(1.0); |
| 1825 | return ffxParabolicSinHalf(FfxFloat16x2(x, y)); |
| 1826 | } |
| 1827 | |
| 1828 | /// Conditional free logic AND operation using two half-precision values. |
| 1829 | /// |
| 1830 | /// @param [in] x The first value to be fed into the AND operator. |
| 1831 | /// @param [in] y The second value to be fed into the AND operator. |
| 1832 | /// |
| 1833 | /// @returns |
| 1834 | /// Result of the AND operation. |
| 1835 | /// |
| 1836 | /// @ingroup GPU |
| 1837 | FfxUInt16 ffxZeroOneAndHalf(FfxUInt16 x, FfxUInt16 y) |
| 1838 | { |
| 1839 | return min(x, y); |
| 1840 | } |
| 1841 | |
| 1842 | /// Conditional free logic AND operation using two half-precision values. |
| 1843 | /// |
| 1844 | /// @param [in] x The first value to be fed into the AND operator. |
| 1845 | /// @param [in] y The second value to be fed into the AND operator. |
| 1846 | /// |
| 1847 | /// @returns |
| 1848 | /// Result of the AND operation. |
| 1849 | /// |
| 1850 | /// @ingroup GPU |
| 1851 | FfxUInt16x2 ffxZeroOneAndHalf(FfxUInt16x2 x, FfxUInt16x2 y) |
| 1852 | { |
| 1853 | return min(x, y); |
| 1854 | } |
| 1855 | |
| 1856 | /// Conditional free logic AND operation using two half-precision values. |
| 1857 | /// |
| 1858 | /// @param [in] x The first value to be fed into the AND operator. |
| 1859 | /// @param [in] y The second value to be fed into the AND operator. |
| 1860 | /// |
| 1861 | /// @returns |
| 1862 | /// Result of the AND operation. |
| 1863 | /// |
| 1864 | /// @ingroup GPU |
| 1865 | FfxUInt16x3 ffxZeroOneAndHalf(FfxUInt16x3 x, FfxUInt16x3 y) |
| 1866 | { |
| 1867 | return min(x, y); |
| 1868 | } |
| 1869 | |
| 1870 | /// Conditional free logic AND operation using two half-precision values. |
| 1871 | /// |
| 1872 | /// @param [in] x The first value to be fed into the AND operator. |
| 1873 | /// @param [in] y The second value to be fed into the AND operator. |
| 1874 | /// |
| 1875 | /// @returns |
| 1876 | /// Result of the AND operation. |
| 1877 | /// |
| 1878 | /// @ingroup GPU |
| 1879 | FfxUInt16x4 ffxZeroOneAndHalf(FfxUInt16x4 x, FfxUInt16x4 y) |
| 1880 | { |
| 1881 | return min(x, y); |
| 1882 | } |
| 1883 | |
| 1884 | /// Conditional free logic NOT operation using two half-precision values. |
| 1885 | /// |
| 1886 | /// @param [in] x The first value to be fed into the NOT operator. |
| 1887 | /// @param [in] y The second value to be fed into the NOT operator. |
| 1888 | /// |
| 1889 | /// @returns |
| 1890 | /// Result of the NOT operation. |
| 1891 | /// |
| 1892 | /// @ingroup GPU |
| 1893 | FfxUInt16 ffxZeroOneNotHalf(FfxUInt16 x) |
| 1894 | { |
| 1895 | return x ^ FFX_BROADCAST_UINT16(1); |
| 1896 | } |
| 1897 | |
| 1898 | /// Conditional free logic NOT operation using two half-precision values. |
| 1899 | /// |
| 1900 | /// @param [in] x The first value to be fed into the NOT operator. |
| 1901 | /// @param [in] y The second value to be fed into the NOT operator. |
| 1902 | /// |
| 1903 | /// @returns |
| 1904 | /// Result of the NOT operation. |
| 1905 | /// |
| 1906 | /// @ingroup GPU |
| 1907 | FfxUInt16x2 ffxZeroOneNotHalf(FfxUInt16x2 x) |
| 1908 | { |
| 1909 | return x ^ FFX_BROADCAST_UINT16X2(1); |
| 1910 | } |
| 1911 | |
| 1912 | /// Conditional free logic NOT operation using two half-precision values. |
| 1913 | /// |
| 1914 | /// @param [in] x The first value to be fed into the NOT operator. |
| 1915 | /// @param [in] y The second value to be fed into the NOT operator. |
| 1916 | /// |
| 1917 | /// @returns |
| 1918 | /// Result of the NOT operation. |
| 1919 | /// |
| 1920 | /// @ingroup GPU |
| 1921 | FfxUInt16x3 ffxZeroOneNotHalf(FfxUInt16x3 x) |
| 1922 | { |
| 1923 | return x ^ FFX_BROADCAST_UINT16X3(1); |
| 1924 | } |
| 1925 | |
| 1926 | /// Conditional free logic NOT operation using two half-precision values. |
| 1927 | /// |
| 1928 | /// @param [in] x The first value to be fed into the NOT operator. |
| 1929 | /// @param [in] y The second value to be fed into the NOT operator. |
| 1930 | /// |
| 1931 | /// @returns |
| 1932 | /// Result of the NOT operation. |
| 1933 | /// |
| 1934 | /// @ingroup GPU |
| 1935 | FfxUInt16x4 ffxZeroOneNotHalf(FfxUInt16x4 x) |
| 1936 | { |
| 1937 | return x ^ FFX_BROADCAST_UINT16X4(1); |
| 1938 | } |
| 1939 | |
| 1940 | /// Conditional free logic OR operation using two half-precision values. |
| 1941 | /// |
| 1942 | /// @param [in] x The first value to be fed into the OR operator. |
| 1943 | /// @param [in] y The second value to be fed into the OR operator. |
| 1944 | /// |
| 1945 | /// @returns |
| 1946 | /// Result of the OR operation. |
| 1947 | /// |
| 1948 | /// @ingroup GPU |
| 1949 | FfxUInt16 ffxZeroOneOrHalf(FfxUInt16 x, FfxUInt16 y) |
| 1950 | { |
| 1951 | return max(x, y); |
| 1952 | } |
| 1953 | |
| 1954 | /// Conditional free logic OR operation using two half-precision values. |
| 1955 | /// |
| 1956 | /// @param [in] x The first value to be fed into the OR operator. |
| 1957 | /// @param [in] y The second value to be fed into the OR operator. |
| 1958 | /// |
| 1959 | /// @returns |
| 1960 | /// Result of the OR operation. |
| 1961 | /// |
| 1962 | /// @ingroup GPU |
| 1963 | FfxUInt16x2 ffxZeroOneOrHalf(FfxUInt16x2 x, FfxUInt16x2 y) |
| 1964 | { |
| 1965 | return max(x, y); |
| 1966 | } |
| 1967 | |
| 1968 | /// Conditional free logic OR operation using two half-precision values. |
| 1969 | /// |
| 1970 | /// @param [in] x The first value to be fed into the OR operator. |
| 1971 | /// @param [in] y The second value to be fed into the OR operator. |
| 1972 | /// |
| 1973 | /// @returns |
| 1974 | /// Result of the OR operation. |
| 1975 | /// |
| 1976 | /// @ingroup GPU |
| 1977 | FfxUInt16x3 ffxZeroOneOrHalf(FfxUInt16x3 x, FfxUInt16x3 y) |
| 1978 | { |
| 1979 | return max(x, y); |
| 1980 | } |
| 1981 | |
| 1982 | /// Conditional free logic OR operation using two half-precision values. |
| 1983 | /// |
| 1984 | /// @param [in] x The first value to be fed into the OR operator. |
| 1985 | /// @param [in] y The second value to be fed into the OR operator. |
| 1986 | /// |
| 1987 | /// @returns |
| 1988 | /// Result of the OR operation. |
| 1989 | /// |
| 1990 | /// @ingroup GPU |
| 1991 | FfxUInt16x4 ffxZeroOneOrHalf(FfxUInt16x4 x, FfxUInt16x4 y) |
| 1992 | { |
| 1993 | return max(x, y); |
| 1994 | } |
| 1995 | |
| 1996 | /// Convert a half-precision FfxFloat32 value between 0.0f and 1.0f to a half-precision Uint. |
| 1997 | /// |
| 1998 | /// @param [in] x The value to converted to a Uint. |
| 1999 | /// |
| 2000 | /// @returns |
| 2001 | /// The converted Uint value. |
| 2002 | /// |
| 2003 | /// @ingroup GPU |
| 2004 | FfxUInt16 ffxZeroOneFloat16ToUint16(FfxFloat16 x) |
| 2005 | { |
| 2006 | return FFX_TO_UINT16(x * FFX_TO_FLOAT16(FFX_TO_UINT16(1))); |
| 2007 | } |
| 2008 | |
| 2009 | /// Convert a half-precision FfxFloat32 value between 0.0f and 1.0f to a half-precision Uint. |
| 2010 | /// |
| 2011 | /// @param [in] x The value to converted to a Uint. |
| 2012 | /// |
| 2013 | /// @returns |
| 2014 | /// The converted Uint value. |
| 2015 | /// |
| 2016 | /// @ingroup GPU |
| 2017 | FfxUInt16x2 ffxZeroOneFloat16x2ToUint16x2(FfxFloat16x2 x) |
| 2018 | { |
| 2019 | return FFX_TO_UINT16X2(x * FFX_TO_FLOAT16X2(FfxUInt16x2(1, 1))); |
| 2020 | } |
| 2021 | |
| 2022 | /// Convert a half-precision FfxFloat32 value between 0.0f and 1.0f to a half-precision Uint. |
| 2023 | /// |
| 2024 | /// @param [in] x The value to converted to a Uint. |
| 2025 | /// |
| 2026 | /// @returns |
| 2027 | /// The converted Uint value. |
| 2028 | /// |
| 2029 | /// @ingroup GPU |
| 2030 | FfxUInt16x3 ffxZeroOneFloat16x3ToUint16x3(FfxFloat16x3 x) |
| 2031 | { |
| 2032 | return FFX_TO_UINT16X3(x * FFX_TO_FLOAT16X3(FfxUInt16x3(1, 1, 1))); |
| 2033 | } |
| 2034 | |
| 2035 | /// Convert a half-precision FfxFloat32 value between 0.0f and 1.0f to a half-precision Uint. |
| 2036 | /// |
| 2037 | /// @param [in] x The value to converted to a Uint. |
| 2038 | /// |
| 2039 | /// @returns |
| 2040 | /// The converted Uint value. |
| 2041 | /// |
| 2042 | /// @ingroup GPU |
| 2043 | FfxUInt16x4 ffxZeroOneFloat16x4ToUint16x4(FfxFloat16x4 x) |
| 2044 | { |
| 2045 | return FFX_TO_UINT16X4(x * FFX_TO_FLOAT16X4(FfxUInt16x4(1, 1, 1, 1))); |
| 2046 | } |
| 2047 | |
| 2048 | /// Convert a half-precision FfxUInt32 value between 0 and 1 to a half-precision FfxFloat32. |
| 2049 | /// |
| 2050 | /// @param [in] x The value to converted to a half-precision FfxFloat32. |
| 2051 | /// |
| 2052 | /// @returns |
| 2053 | /// The converted half-precision FfxFloat32 value. |
| 2054 | /// |
| 2055 | /// @ingroup GPU |
| 2056 | FfxFloat16 ffxZeroOneUint16ToFloat16(FfxUInt16 x) |
| 2057 | { |
| 2058 | return FFX_TO_FLOAT16(x * FFX_TO_UINT16(FFX_TO_FLOAT16(1.0))); |
| 2059 | } |
| 2060 | |
| 2061 | /// Convert a half-precision FfxUInt32 value between 0 and 1 to a half-precision FfxFloat32. |
| 2062 | /// |
| 2063 | /// @param [in] x The value to converted to a half-precision FfxFloat32. |
| 2064 | /// |
| 2065 | /// @returns |
| 2066 | /// The converted half-precision FfxFloat32 value. |
| 2067 | /// |
| 2068 | /// @ingroup GPU |
| 2069 | FfxFloat16x2 ffxZeroOneUint16x2ToFloat16x2(FfxUInt16x2 x) |
| 2070 | { |
| 2071 | return FFX_TO_FLOAT16X2(x * FFX_TO_UINT16X2(FfxUInt16x2(FFX_TO_FLOAT16(1.0), FFX_TO_FLOAT16(1.0)))); |
| 2072 | } |
| 2073 | |
| 2074 | /// Convert a half-precision FfxUInt32 value between 0 and 1 to a half-precision FfxFloat32. |
| 2075 | /// |
| 2076 | /// @param [in] x The value to converted to a half-precision FfxFloat32. |
| 2077 | /// |
| 2078 | /// @returns |
| 2079 | /// The converted half-precision FfxFloat32 value. |
| 2080 | /// |
| 2081 | /// @ingroup GPU |
| 2082 | FfxFloat16x3 ffxZeroOneUint16x3ToFloat16x3(FfxUInt16x3 x) |
| 2083 | { |
| 2084 | return FFX_TO_FLOAT16X3(x * FFX_TO_UINT16X3(FfxUInt16x3(FFX_TO_FLOAT16(1.0), FFX_TO_FLOAT16(1.0), FFX_TO_FLOAT16(1.0)))); |
| 2085 | } |
| 2086 | |
| 2087 | /// Convert a half-precision FfxUInt32 value between 0 and 1 to a half-precision FfxFloat32. |
| 2088 | /// |
| 2089 | /// @param [in] x The value to converted to a half-precision FfxFloat32. |
| 2090 | /// |
| 2091 | /// @returns |
| 2092 | /// The converted half-precision FfxFloat32 value. |
| 2093 | /// |
| 2094 | /// @ingroup GPU |
| 2095 | FfxFloat16x4 ffxZeroOneUint16x4ToFloat16x4(FfxUInt16x4 x) |
| 2096 | { |
| 2097 | return FFX_TO_FLOAT16X4(x * FFX_TO_UINT16X4(FfxUInt16x4(FFX_TO_FLOAT16(1.0), FFX_TO_FLOAT16(1.0), FFX_TO_FLOAT16(1.0), FFX_TO_FLOAT16(1.0)))); |
| 2098 | } |
| 2099 | |
| 2100 | /// Conditional free logic AND operation using two half-precision values. |
| 2101 | /// |
| 2102 | /// @param [in] x The first value to be fed into the AND operator. |
| 2103 | /// @param [in] y The second value to be fed into the AND operator. |
| 2104 | /// |
| 2105 | /// @returns |
| 2106 | /// Result of the AND operation. |
| 2107 | /// |
| 2108 | /// @ingroup GPU |
| 2109 | FfxFloat16 ffxZeroOneAndHalf(FfxFloat16 x, FfxFloat16 y) |
| 2110 | { |
| 2111 | return min(x, y); |
| 2112 | } |
| 2113 | |
| 2114 | /// Conditional free logic AND operation using two half-precision values. |
| 2115 | /// |
| 2116 | /// @param [in] x The first value to be fed into the AND operator. |
| 2117 | /// @param [in] y The second value to be fed into the AND operator. |
| 2118 | /// |
| 2119 | /// @returns |
| 2120 | /// Result of the AND operation. |
| 2121 | /// |
| 2122 | /// @ingroup GPU |
| 2123 | FfxFloat16x2 ffxZeroOneAndHalf(FfxFloat16x2 x, FfxFloat16x2 y) |
| 2124 | { |
| 2125 | return min(x, y); |
| 2126 | } |
| 2127 | |
| 2128 | /// Conditional free logic AND operation using two half-precision values. |
| 2129 | /// |
| 2130 | /// @param [in] x The first value to be fed into the AND operator. |
| 2131 | /// @param [in] y The second value to be fed into the AND operator. |
| 2132 | /// |
| 2133 | /// @returns |
| 2134 | /// Result of the AND operation. |
| 2135 | /// |
| 2136 | /// @ingroup GPU |
| 2137 | FfxFloat16x3 ffxZeroOneAndHalf(FfxFloat16x3 x, FfxFloat16x3 y) |
| 2138 | { |
| 2139 | return min(x, y); |
| 2140 | } |
| 2141 | |
| 2142 | /// Conditional free logic AND operation using two half-precision values. |
| 2143 | /// |
| 2144 | /// @param [in] x The first value to be fed into the AND operator. |
| 2145 | /// @param [in] y The second value to be fed into the AND operator. |
| 2146 | /// |
| 2147 | /// @returns |
| 2148 | /// Result of the AND operation. |
| 2149 | /// |
| 2150 | /// @ingroup GPU |
| 2151 | FfxFloat16x4 ffxZeroOneAndHalf(FfxFloat16x4 x, FfxFloat16x4 y) |
| 2152 | { |
| 2153 | return min(x, y); |
| 2154 | } |
| 2155 | |
| 2156 | /// Conditional free logic AND NOT operation using two half-precision values. |
| 2157 | /// |
| 2158 | /// @param [in] x The first value to be fed into the AND NOT operator. |
| 2159 | /// @param [in] y The second value to be fed into the AND NOT operator. |
| 2160 | /// |
| 2161 | /// @returns |
| 2162 | /// Result of the AND NOT operation. |
| 2163 | /// |
| 2164 | /// @ingroup GPU |
| 2165 | FfxFloat16 ffxSignedZeroOneAndOrHalf(FfxFloat16 x, FfxFloat16 y) |
| 2166 | { |
| 2167 | return (-x) * y + FFX_BROADCAST_FLOAT16(1.0); |
| 2168 | } |
| 2169 | |
| 2170 | /// Conditional free logic AND NOT operation using two half-precision values. |
| 2171 | /// |
| 2172 | /// @param [in] x The first value to be fed into the AND NOT operator. |
| 2173 | /// @param [in] y The second value to be fed into the AND NOT operator. |
| 2174 | /// |
| 2175 | /// @returns |
| 2176 | /// Result of the AND NOT operation. |
| 2177 | /// |
| 2178 | /// @ingroup GPU |
| 2179 | FfxFloat16x2 ffxSignedZeroOneAndOrHalf(FfxFloat16x2 x, FfxFloat16x2 y) |
| 2180 | { |
| 2181 | return (-x) * y + FFX_BROADCAST_FLOAT16X2(1.0); |
| 2182 | } |
| 2183 | |
| 2184 | /// Conditional free logic AND NOT operation using two half-precision values. |
| 2185 | /// |
| 2186 | /// @param [in] x The first value to be fed into the AND NOT operator. |
| 2187 | /// @param [in] y The second value to be fed into the AND NOT operator. |
| 2188 | /// |
| 2189 | /// @returns |
| 2190 | /// Result of the AND NOT operation. |
| 2191 | /// |
| 2192 | /// @ingroup GPU |
| 2193 | FfxFloat16x3 ffxSignedZeroOneAndOrHalf(FfxFloat16x3 x, FfxFloat16x3 y) |
| 2194 | { |
| 2195 | return (-x) * y + FFX_BROADCAST_FLOAT16X3(1.0); |
| 2196 | } |
| 2197 | |
| 2198 | /// Conditional free logic AND NOT operation using two half-precision values. |
| 2199 | /// |
| 2200 | /// @param [in] x The first value to be fed into the AND NOT operator. |
| 2201 | /// @param [in] y The second value to be fed into the AND NOT operator. |
| 2202 | /// |
| 2203 | /// @returns |
| 2204 | /// Result of the AND NOT operation. |
| 2205 | /// |
| 2206 | /// @ingroup GPU |
| 2207 | FfxFloat16x4 ffxSignedZeroOneAndOrHalf(FfxFloat16x4 x, FfxFloat16x4 y) |
| 2208 | { |
| 2209 | return (-x) * y + FFX_BROADCAST_FLOAT16X4(1.0); |
| 2210 | } |
| 2211 | |
| 2212 | /// Conditional free logic AND operation using two half-precision values followed by |
| 2213 | /// a NOT operation using the resulting value and a third half-precision value. |
| 2214 | /// |
| 2215 | /// @param [in] x The first value to be fed into the AND operator. |
| 2216 | /// @param [in] y The second value to be fed into the AND operator. |
| 2217 | /// @param [in] z The second value to be fed into the OR operator. |
| 2218 | /// |
| 2219 | /// @returns |
| 2220 | /// Result of the AND OR operation. |
| 2221 | /// |
| 2222 | /// @ingroup GPU |
| 2223 | FfxFloat16 ffxZeroOneAndOrHalf(FfxFloat16 x, FfxFloat16 y, FfxFloat16 z) |
| 2224 | { |
| 2225 | return ffxSaturate(x * y + z); |
| 2226 | } |
| 2227 | |
| 2228 | /// Conditional free logic AND operation using two half-precision values followed by |
| 2229 | /// a NOT operation using the resulting value and a third half-precision value. |
| 2230 | /// |
| 2231 | /// @param [in] x The first value to be fed into the AND operator. |
| 2232 | /// @param [in] y The second value to be fed into the AND operator. |
| 2233 | /// @param [in] z The second value to be fed into the OR operator. |
| 2234 | /// |
| 2235 | /// @returns |
| 2236 | /// Result of the AND OR operation. |
| 2237 | /// |
| 2238 | /// @ingroup GPU |
| 2239 | FfxFloat16x2 ffxZeroOneAndOrHalf(FfxFloat16x2 x, FfxFloat16x2 y, FfxFloat16x2 z) |
| 2240 | { |
| 2241 | return ffxSaturate(x * y + z); |
| 2242 | } |
| 2243 | |
| 2244 | /// Conditional free logic AND operation using two half-precision values followed by |
| 2245 | /// a NOT operation using the resulting value and a third half-precision value. |
| 2246 | /// |
| 2247 | /// @param [in] x The first value to be fed into the AND operator. |
| 2248 | /// @param [in] y The second value to be fed into the AND operator. |
| 2249 | /// @param [in] z The second value to be fed into the OR operator. |
| 2250 | /// |
| 2251 | /// @returns |
| 2252 | /// Result of the AND OR operation. |
| 2253 | /// |
| 2254 | /// @ingroup GPU |
| 2255 | FfxFloat16x3 ffxZeroOneAndOrHalf(FfxFloat16x3 x, FfxFloat16x3 y, FfxFloat16x3 z) |
| 2256 | { |
| 2257 | return ffxSaturate(x * y + z); |
| 2258 | } |
| 2259 | |
| 2260 | /// Conditional free logic AND operation using two half-precision values followed by |
| 2261 | /// a NOT operation using the resulting value and a third half-precision value. |
| 2262 | /// |
| 2263 | /// @param [in] x The first value to be fed into the AND operator. |
| 2264 | /// @param [in] y The second value to be fed into the AND operator. |
| 2265 | /// @param [in] z The second value to be fed into the OR operator. |
| 2266 | /// |
| 2267 | /// @returns |
| 2268 | /// Result of the AND OR operation. |
| 2269 | /// |
| 2270 | /// @ingroup GPU |
| 2271 | FfxFloat16x4 ffxZeroOneAndOrHalf(FfxFloat16x4 x, FfxFloat16x4 y, FfxFloat16x4 z) |
| 2272 | { |
| 2273 | return ffxSaturate(x * y + z); |
| 2274 | } |
| 2275 | |
| 2276 | /// Given a half-precision value, returns 1.0 if greater than zero and 0.0 if not. |
| 2277 | /// |
| 2278 | /// @param [in] x The value to be compared. |
| 2279 | /// |
| 2280 | /// @returns |
| 2281 | /// Result of the greater than zero comparison. |
| 2282 | /// |
| 2283 | /// @ingroup GPU |
| 2284 | FfxFloat16 ffxZeroOneIsGreaterThanZeroHalf(FfxFloat16 x) |
| 2285 | { |
| 2286 | return ffxSaturate(x * FFX_BROADCAST_FLOAT16(FFX_POSITIVE_INFINITY_HALF)); |
| 2287 | } |
| 2288 | |
| 2289 | /// Given a half-precision value, returns 1.0 if greater than zero and 0.0 if not. |
| 2290 | /// |
| 2291 | /// @param [in] x The value to be compared. |
| 2292 | /// |
| 2293 | /// @returns |
| 2294 | /// Result of the greater than zero comparison. |
| 2295 | /// |
| 2296 | /// @ingroup GPU |
| 2297 | FfxFloat16x2 ffxZeroOneIsGreaterThanZeroHalf(FfxFloat16x2 x) |
| 2298 | { |
| 2299 | return ffxSaturate(x * FFX_BROADCAST_FLOAT16X2(FFX_POSITIVE_INFINITY_HALF)); |
| 2300 | } |
| 2301 | |
| 2302 | /// Given a half-precision value, returns 1.0 if greater than zero and 0.0 if not. |
| 2303 | /// |
| 2304 | /// @param [in] x The value to be compared. |
| 2305 | /// |
| 2306 | /// @returns |
| 2307 | /// Result of the greater than zero comparison. |
| 2308 | /// |
| 2309 | /// @ingroup GPU |
| 2310 | FfxFloat16x3 ffxZeroOneIsGreaterThanZeroHalf(FfxFloat16x3 x) |
| 2311 | { |
| 2312 | return ffxSaturate(x * FFX_BROADCAST_FLOAT16X3(FFX_POSITIVE_INFINITY_HALF)); |
| 2313 | } |
| 2314 | |
| 2315 | /// Given a half-precision value, returns 1.0 if greater than zero and 0.0 if not. |
| 2316 | /// |
| 2317 | /// @param [in] x The value to be compared. |
| 2318 | /// |
| 2319 | /// @returns |
| 2320 | /// Result of the greater than zero comparison. |
| 2321 | /// |
| 2322 | /// @ingroup GPU |
| 2323 | FfxFloat16x4 ffxZeroOneIsGreaterThanZeroHalf(FfxFloat16x4 x) |
| 2324 | { |
| 2325 | return ffxSaturate(x * FFX_BROADCAST_FLOAT16X4(FFX_POSITIVE_INFINITY_HALF)); |
| 2326 | } |
| 2327 | |
| 2328 | /// Conditional free logic signed NOT operation using two half-precision FfxFloat32 values. |
| 2329 | /// |
| 2330 | /// @param [in] x The first value to be fed into the AND OR operator. |
| 2331 | /// |
| 2332 | /// @returns |
| 2333 | /// Result of the AND OR operation. |
| 2334 | /// |
| 2335 | /// @ingroup GPU |
| 2336 | FfxFloat16 ffxZeroOneNotHalf(FfxFloat16 x) |
| 2337 | { |
| 2338 | return FFX_BROADCAST_FLOAT16(1.0) - x; |
| 2339 | } |
| 2340 | |
| 2341 | /// Conditional free logic signed NOT operation using two half-precision FfxFloat32 values. |
| 2342 | /// |
| 2343 | /// @param [in] x The first value to be fed into the AND OR operator. |
| 2344 | /// |
| 2345 | /// @returns |
| 2346 | /// Result of the AND OR operation. |
| 2347 | /// |
| 2348 | /// @ingroup GPU |
| 2349 | FfxFloat16x2 ffxZeroOneNotHalf(FfxFloat16x2 x) |
| 2350 | { |
| 2351 | return FFX_BROADCAST_FLOAT16X2(1.0) - x; |
| 2352 | } |
| 2353 | |
| 2354 | /// Conditional free logic signed NOT operation using two half-precision FfxFloat32 values. |
| 2355 | /// |
| 2356 | /// @param [in] x The first value to be fed into the AND OR operator. |
| 2357 | /// |
| 2358 | /// @returns |
| 2359 | /// Result of the AND OR operation. |
| 2360 | /// |
| 2361 | /// @ingroup GPU |
| 2362 | FfxFloat16x3 ffxZeroOneNotHalf(FfxFloat16x3 x) |
| 2363 | { |
| 2364 | return FFX_BROADCAST_FLOAT16X3(1.0) - x; |
| 2365 | } |
| 2366 | |
| 2367 | /// Conditional free logic signed NOT operation using two half-precision FfxFloat32 values. |
| 2368 | /// |
| 2369 | /// @param [in] x The first value to be fed into the AND OR operator. |
| 2370 | /// |
| 2371 | /// @returns |
| 2372 | /// Result of the AND OR operation. |
| 2373 | /// |
| 2374 | /// @ingroup GPU |
| 2375 | FfxFloat16x4 ffxZeroOneNotHalf(FfxFloat16x4 x) |
| 2376 | { |
| 2377 | return FFX_BROADCAST_FLOAT16X4(1.0) - x; |
| 2378 | } |
| 2379 | |
| 2380 | /// Conditional free logic OR operation using two half-precision FfxFloat32 values. |
| 2381 | /// |
| 2382 | /// @param [in] x The first value to be fed into the OR operator. |
| 2383 | /// @param [in] y The second value to be fed into the OR operator. |
| 2384 | /// |
| 2385 | /// @returns |
| 2386 | /// Result of the OR operation. |
| 2387 | /// |
| 2388 | /// @ingroup GPU |
| 2389 | FfxFloat16 ffxZeroOneOrHalf(FfxFloat16 x, FfxFloat16 y) |
| 2390 | { |
| 2391 | return max(x, y); |
| 2392 | } |
| 2393 | |
| 2394 | /// Conditional free logic OR operation using two half-precision FfxFloat32 values. |
| 2395 | /// |
| 2396 | /// @param [in] x The first value to be fed into the OR operator. |
| 2397 | /// @param [in] y The second value to be fed into the OR operator. |
| 2398 | /// |
| 2399 | /// @returns |
| 2400 | /// Result of the OR operation. |
| 2401 | /// |
| 2402 | /// @ingroup GPU |
| 2403 | FfxFloat16x2 ffxZeroOneOrHalf(FfxFloat16x2 x, FfxFloat16x2 y) |
| 2404 | { |
| 2405 | return max(x, y); |
| 2406 | } |
| 2407 | |
| 2408 | /// Conditional free logic OR operation using two half-precision FfxFloat32 values. |
| 2409 | /// |
| 2410 | /// @param [in] x The first value to be fed into the OR operator. |
| 2411 | /// @param [in] y The second value to be fed into the OR operator. |
| 2412 | /// |
| 2413 | /// @returns |
| 2414 | /// Result of the OR operation. |
| 2415 | /// |
| 2416 | /// @ingroup GPU |
| 2417 | FfxFloat16x3 ffxZeroOneOrHalf(FfxFloat16x3 x, FfxFloat16x3 y) |
| 2418 | { |
| 2419 | return max(x, y); |
| 2420 | } |
| 2421 | |
| 2422 | /// Conditional free logic OR operation using two half-precision FfxFloat32 values. |
| 2423 | /// |
| 2424 | /// @param [in] x The first value to be fed into the OR operator. |
| 2425 | /// @param [in] y The second value to be fed into the OR operator. |
| 2426 | /// |
| 2427 | /// @returns |
| 2428 | /// Result of the OR operation. |
| 2429 | /// |
| 2430 | /// @ingroup GPU |
| 2431 | FfxFloat16x4 ffxZeroOneOrHalf(FfxFloat16x4 x, FfxFloat16x4 y) |
| 2432 | { |
| 2433 | return max(x, y); |
| 2434 | } |
| 2435 | |
| 2436 | /// Choose between two half-precision FfxFloat32 values if the first paramter is greater than zero. |
| 2437 | /// |
| 2438 | /// @param [in] x The value to compare against zero. |
| 2439 | /// @param [in] y The value to return if the comparision is greater than zero. |
| 2440 | /// @param [in] z The value to return if the comparision is less than or equal to zero. |
| 2441 | /// |
| 2442 | /// @returns |
| 2443 | /// The selected value. |
| 2444 | /// |
| 2445 | /// @ingroup GPU |
| 2446 | FfxFloat16 ffxZeroOneSelectHalf(FfxFloat16 x, FfxFloat16 y, FfxFloat16 z) |
| 2447 | { |
| 2448 | FfxFloat16 r = (-x) * z + z; |
| 2449 | return x * y + r; |
| 2450 | } |
| 2451 | |
| 2452 | /// Choose between two half-precision FfxFloat32 values if the first paramter is greater than zero. |
| 2453 | /// |
| 2454 | /// @param [in] x The value to compare against zero. |
| 2455 | /// @param [in] y The value to return if the comparision is greater than zero. |
| 2456 | /// @param [in] z The value to return if the comparision is less than or equal to zero. |
| 2457 | /// |
| 2458 | /// @returns |
| 2459 | /// The selected value. |
| 2460 | /// |
| 2461 | /// @ingroup GPU |
| 2462 | FfxFloat16x2 ffxZeroOneSelectHalf(FfxFloat16x2 x, FfxFloat16x2 y, FfxFloat16x2 z) |
| 2463 | { |
| 2464 | FfxFloat16x2 r = (-x) * z + z; |
| 2465 | return x * y + r; |
| 2466 | } |
| 2467 | |
| 2468 | /// Choose between two half-precision FfxFloat32 values if the first paramter is greater than zero. |
| 2469 | /// |
| 2470 | /// @param [in] x The value to compare against zero. |
| 2471 | /// @param [in] y The value to return if the comparision is greater than zero. |
| 2472 | /// @param [in] z The value to return if the comparision is less than or equal to zero. |
| 2473 | /// |
| 2474 | /// @returns |
| 2475 | /// The selected value. |
| 2476 | /// |
| 2477 | /// @ingroup GPU |
| 2478 | FfxFloat16x3 ffxZeroOneSelectHalf(FfxFloat16x3 x, FfxFloat16x3 y, FfxFloat16x3 z) |
| 2479 | { |
| 2480 | FfxFloat16x3 r = (-x) * z + z; |
| 2481 | return x * y + r; |
| 2482 | } |
| 2483 | |
| 2484 | /// Choose between two half-precision FfxFloat32 values if the first paramter is greater than zero. |
| 2485 | /// |
| 2486 | /// @param [in] x The value to compare against zero. |
| 2487 | /// @param [in] y The value to return if the comparision is greater than zero. |
| 2488 | /// @param [in] z The value to return if the comparision is less than or equal to zero. |
| 2489 | /// |
| 2490 | /// @returns |
| 2491 | /// The selected value. |
| 2492 | /// |
| 2493 | /// @ingroup GPU |
| 2494 | FfxFloat16x4 ffxZeroOneSelectHalf(FfxFloat16x4 x, FfxFloat16x4 y, FfxFloat16x4 z) |
| 2495 | { |
| 2496 | FfxFloat16x4 r = (-x) * z + z; |
| 2497 | return x * y + r; |
| 2498 | } |
| 2499 | |
| 2500 | /// Given a half-precision value, returns 1.0 if less than zero and 0.0 if not. |
| 2501 | /// |
| 2502 | /// @param [in] x The value to be compared. |
| 2503 | /// |
| 2504 | /// @returns |
| 2505 | /// Result of the sign value. |
| 2506 | /// |
| 2507 | /// @ingroup GPU |
| 2508 | FfxFloat16 ffxZeroOneIsSignedHalf(FfxFloat16 x) |
| 2509 | { |
| 2510 | return ffxSaturate(x * FFX_BROADCAST_FLOAT16(FFX_NEGATIVE_INFINITY_HALF)); |
| 2511 | } |
| 2512 | |
| 2513 | /// Given a half-precision value, returns 1.0 if less than zero and 0.0 if not. |
| 2514 | /// |
| 2515 | /// @param [in] x The value to be compared. |
| 2516 | /// |
| 2517 | /// @returns |
| 2518 | /// Result of the sign value. |
| 2519 | /// |
| 2520 | /// @ingroup GPU |
| 2521 | FfxFloat16x2 ffxZeroOneIsSignedHalf(FfxFloat16x2 x) |
| 2522 | { |
| 2523 | return ffxSaturate(x * FFX_BROADCAST_FLOAT16X2(FFX_NEGATIVE_INFINITY_HALF)); |
| 2524 | } |
| 2525 | |
| 2526 | /// Given a half-precision value, returns 1.0 if less than zero and 0.0 if not. |
| 2527 | /// |
| 2528 | /// @param [in] x The value to be compared. |
| 2529 | /// |
| 2530 | /// @returns |
| 2531 | /// Result of the sign value. |
| 2532 | /// |
| 2533 | /// @ingroup GPU |
| 2534 | FfxFloat16x3 ffxZeroOneIsSignedHalf(FfxFloat16x3 x) |
| 2535 | { |
| 2536 | return ffxSaturate(x * FFX_BROADCAST_FLOAT16X3(FFX_NEGATIVE_INFINITY_HALF)); |
| 2537 | } |
| 2538 | |
| 2539 | /// Given a half-precision value, returns 1.0 if less than zero and 0.0 if not. |
| 2540 | /// |
| 2541 | /// @param [in] x The value to be compared. |
| 2542 | /// |
| 2543 | /// @returns |
| 2544 | /// Result of the sign value. |
| 2545 | /// |
| 2546 | /// @ingroup GPU |
| 2547 | FfxFloat16x4 ffxZeroOneIsSignedHalf(FfxFloat16x4 x) |
| 2548 | { |
| 2549 | return ffxSaturate(x * FFX_BROADCAST_FLOAT16X4(FFX_NEGATIVE_INFINITY_HALF)); |
| 2550 | } |
| 2551 | |
| 2552 | /// Compute a Rec.709 color space. |
| 2553 | /// |
| 2554 | /// Rec.709 is used for some HDTVs. |
| 2555 | /// |
| 2556 | /// Both Rec.709 and sRGB have a linear segment which as spec'ed would intersect the curved segment 2 times. |
| 2557 | /// (a.) For 8-bit sRGB, steps {0 to 10.3} are in the linear region (4% of the encoding range). |
| 2558 | /// (b.) For 8-bit 709, steps {0 to 20.7} are in the linear region (8% of the encoding range). |
| 2559 | /// |
| 2560 | /// @param [in] c The color to convert to Rec. 709. |
| 2561 | /// |
| 2562 | /// @returns |
| 2563 | /// The <c><i>color</i></c> in Rec.709 space. |
| 2564 | /// |
| 2565 | /// @ingroup GPU |
| 2566 | FfxFloat16 ffxRec709FromLinearHalf(FfxFloat16 c) |
| 2567 | { |
| 2568 | FfxFloat16x3 j = FfxFloat16x3(0.018 * 4.5, 4.5, 0.45); |
| 2569 | FfxFloat16x2 k = FfxFloat16x2(1.099, -0.099); |
| 2570 | return clamp(j.x, c * j.y, pow(c, j.z) * k.x + k.y); |
| 2571 | } |
| 2572 | |
| 2573 | /// Compute a Rec.709 color space. |
| 2574 | /// |
| 2575 | /// Rec.709 is used for some HDTVs. |
| 2576 | /// |
| 2577 | /// Both Rec.709 and sRGB have a linear segment which as spec'ed would intersect the curved segment 2 times. |
| 2578 | /// (a.) For 8-bit sRGB, steps {0 to 10.3} are in the linear region (4% of the encoding range). |
| 2579 | /// (b.) For 8-bit 709, steps {0 to 20.7} are in the linear region (8% of the encoding range). |
| 2580 | /// |
| 2581 | /// @param [in] c The color to convert to Rec. 709. |
| 2582 | /// |
| 2583 | /// @returns |
| 2584 | /// The <c><i>color</i></c> in Rec.709 space. |
| 2585 | /// |
| 2586 | /// @ingroup GPU |
| 2587 | FfxFloat16x2 ffxRec709FromLinearHalf(FfxFloat16x2 c) |
| 2588 | { |
| 2589 | FfxFloat16x3 j = FfxFloat16x3(0.018 * 4.5, 4.5, 0.45); |
| 2590 | FfxFloat16x2 k = FfxFloat16x2(1.099, -0.099); |
| 2591 | return clamp(j.xx, c * j.yy, pow(c, j.zz) * k.xx + k.yy); |
| 2592 | } |
| 2593 | |
| 2594 | /// Compute a Rec.709 color space. |
| 2595 | /// |
| 2596 | /// Rec.709 is used for some HDTVs. |
| 2597 | /// |
| 2598 | /// Both Rec.709 and sRGB have a linear segment which as spec'ed would intersect the curved segment 2 times. |
| 2599 | /// (a.) For 8-bit sRGB, steps {0 to 10.3} are in the linear region (4% of the encoding range). |
| 2600 | /// (b.) For 8-bit 709, steps {0 to 20.7} are in the linear region (8% of the encoding range). |
| 2601 | /// |
| 2602 | /// @param [in] c The color to convert to Rec. 709. |
| 2603 | /// |
| 2604 | /// @returns |
| 2605 | /// The <c><i>color</i></c> in Rec.709 space. |
| 2606 | /// |
| 2607 | /// @ingroup GPU |
| 2608 | FfxFloat16x3 ffxRec709FromLinearHalf(FfxFloat16x3 c) |
| 2609 | { |
| 2610 | FfxFloat16x3 j = FfxFloat16x3(0.018 * 4.5, 4.5, 0.45); |
| 2611 | FfxFloat16x2 k = FfxFloat16x2(1.099, -0.099); |
| 2612 | return clamp(j.xxx, c * j.yyy, pow(c, j.zzz) * k.xxx + k.yyy); |
| 2613 | } |
| 2614 | |
| 2615 | /// Compute a gamma value from a linear value. |
| 2616 | /// |
| 2617 | /// Typically 2.2 for some PC displays, or 2.4-2.5 for CRTs, or 2.2 FreeSync2 native. |
| 2618 | /// |
| 2619 | /// Note: 'rcpX' is '1/x', where the 'x' is what would be used in <c><i>ffxLinearFromGammaHalf</i></c>. |
| 2620 | /// |
| 2621 | /// @param [in] c The value to convert to gamma space from linear. |
| 2622 | /// @param [in] rcpX The reciprocal of power value used for the gamma curve. |
| 2623 | /// |
| 2624 | /// @returns |
| 2625 | /// A value in gamma space. |
| 2626 | /// |
| 2627 | /// @ingroup GPU |
| 2628 | FfxFloat16 ffxGammaFromLinearHalf(FfxFloat16 c, FfxFloat16 rcpX) |
| 2629 | { |
| 2630 | return pow(c, FFX_BROADCAST_FLOAT16(rcpX)); |
| 2631 | } |
| 2632 | |
| 2633 | /// Compute a gamma value from a linear value. |
| 2634 | /// |
| 2635 | /// Typically 2.2 for some PC displays, or 2.4-2.5 for CRTs, or 2.2 FreeSync2 native. |
| 2636 | /// |
| 2637 | /// Note: 'rcpX' is '1/x', where the 'x' is what would be used in <c><i>ffxLinearFromGammaHalf</i></c>. |
| 2638 | /// |
| 2639 | /// @param [in] c The value to convert to gamma space from linear. |
| 2640 | /// @param [in] rcpX The reciprocal of power value used for the gamma curve. |
| 2641 | /// |
| 2642 | /// @returns |
| 2643 | /// A value in gamma space. |
| 2644 | /// |
| 2645 | /// @ingroup GPU |
| 2646 | FfxFloat16x2 ffxGammaFromLinearHalf(FfxFloat16x2 c, FfxFloat16 rcpX) |
| 2647 | { |
| 2648 | return pow(c, FFX_BROADCAST_FLOAT16X2(rcpX)); |
| 2649 | } |
| 2650 | |
| 2651 | /// Compute a gamma value from a linear value. |
| 2652 | /// |
| 2653 | /// Typically 2.2 for some PC displays, or 2.4-2.5 for CRTs, or 2.2 FreeSync2 native. |
| 2654 | /// |
| 2655 | /// Note: 'rcpX' is '1/x', where the 'x' is what would be used in <c><i>ffxLinearFromGammaHalf</i></c>. |
| 2656 | /// |
| 2657 | /// @param [in] c The value to convert to gamma space from linear. |
| 2658 | /// @param [in] rcpX The reciprocal of power value used for the gamma curve. |
| 2659 | /// |
| 2660 | /// @returns |
| 2661 | /// A value in gamma space. |
| 2662 | /// |
| 2663 | /// @ingroup GPU |
| 2664 | FfxFloat16x3 ffxGammaFromLinearHalf(FfxFloat16x3 c, FfxFloat16 rcpX) |
| 2665 | { |
| 2666 | return pow(c, FFX_BROADCAST_FLOAT16X3(rcpX)); |
| 2667 | } |
| 2668 | |
| 2669 | /// Compute an SRGB value from a linear value. |
| 2670 | /// |
| 2671 | /// @param [in] c The value to convert to SRGB from linear. |
| 2672 | /// |
| 2673 | /// @returns |
| 2674 | /// A value in SRGB space. |
| 2675 | /// |
| 2676 | /// @ingroup GPU |
| 2677 | FfxFloat16 ffxSrgbFromLinearHalf(FfxFloat16 c) |
| 2678 | { |
| 2679 | FfxFloat16x3 j = FfxFloat16x3(0.0031308 * 12.92, 12.92, 1.0 / 2.4); |
| 2680 | FfxFloat16x2 k = FfxFloat16x2(1.055, -0.055); |
| 2681 | return clamp(j.x, c * j.y, pow(c, j.z) * k.x + k.y); |
| 2682 | } |
| 2683 | |
| 2684 | /// Compute an SRGB value from a linear value. |
| 2685 | /// |
| 2686 | /// @param [in] c The value to convert to SRGB from linear. |
| 2687 | /// |
| 2688 | /// @returns |
| 2689 | /// A value in SRGB space. |
| 2690 | /// |
| 2691 | /// @ingroup GPU |
| 2692 | FfxFloat16x2 ffxSrgbFromLinearHalf(FfxFloat16x2 c) |
| 2693 | { |
| 2694 | FfxFloat16x3 j = FfxFloat16x3(0.0031308 * 12.92, 12.92, 1.0 / 2.4); |
| 2695 | FfxFloat16x2 k = FfxFloat16x2(1.055, -0.055); |
| 2696 | return clamp(j.xx, c * j.yy, pow(c, j.zz) * k.xx + k.yy); |
| 2697 | } |
| 2698 | |
| 2699 | /// Compute an SRGB value from a linear value. |
| 2700 | /// |
| 2701 | /// @param [in] c The value to convert to SRGB from linear. |
| 2702 | /// |
| 2703 | /// @returns |
| 2704 | /// A value in SRGB space. |
| 2705 | /// |
| 2706 | /// @ingroup GPU |
| 2707 | FfxFloat16x3 ffxSrgbFromLinearHalf(FfxFloat16x3 c) |
| 2708 | { |
| 2709 | FfxFloat16x3 j = FfxFloat16x3(0.0031308 * 12.92, 12.92, 1.0 / 2.4); |
| 2710 | FfxFloat16x2 k = FfxFloat16x2(1.055, -0.055); |
| 2711 | return clamp(j.xxx, c * j.yyy, pow(c, j.zzz) * k.xxx + k.yyy); |
| 2712 | } |
| 2713 | |
| 2714 | /// Compute the square root of a value. |
| 2715 | /// |
| 2716 | /// @param [in] c The value to compute the square root for. |
| 2717 | /// |
| 2718 | /// @returns |
| 2719 | /// A square root of the input value. |
| 2720 | /// |
| 2721 | /// @ingroup GPU |
| 2722 | FfxFloat16 ffxSquareRootHalf(FfxFloat16 c) |
| 2723 | { |
| 2724 | return sqrt(c); |
| 2725 | } |
| 2726 | |
| 2727 | /// Compute the square root of a value. |
| 2728 | /// |
| 2729 | /// @param [in] c The value to compute the square root for. |
| 2730 | /// |
| 2731 | /// @returns |
| 2732 | /// A square root of the input value. |
| 2733 | /// |
| 2734 | /// @ingroup GPU |
| 2735 | FfxFloat16x2 ffxSquareRootHalf(FfxFloat16x2 c) |
| 2736 | { |
| 2737 | return sqrt(c); |
| 2738 | } |
| 2739 | |
| 2740 | /// Compute the square root of a value. |
| 2741 | /// |
| 2742 | /// @param [in] c The value to compute the square root for. |
| 2743 | /// |
| 2744 | /// @returns |
| 2745 | /// A square root of the input value. |
| 2746 | /// |
| 2747 | /// @ingroup GPU |
| 2748 | FfxFloat16x3 ffxSquareRootHalf(FfxFloat16x3 c) |
| 2749 | { |
| 2750 | return sqrt(c); |
| 2751 | } |
| 2752 | |
| 2753 | /// Compute the cube root of a value. |
| 2754 | /// |
| 2755 | /// @param [in] c The value to compute the cube root for. |
| 2756 | /// |
| 2757 | /// @returns |
| 2758 | /// A cube root of the input value. |
| 2759 | /// |
| 2760 | /// @ingroup GPU |
| 2761 | FfxFloat16 ffxCubeRootHalf(FfxFloat16 c) |
| 2762 | { |
| 2763 | return pow(c, FFX_BROADCAST_FLOAT16(1.0 / 3.0)); |
| 2764 | } |
| 2765 | |
| 2766 | /// Compute the cube root of a value. |
| 2767 | /// |
| 2768 | /// @param [in] c The value to compute the cube root for. |
| 2769 | /// |
| 2770 | /// @returns |
| 2771 | /// A cube root of the input value. |
| 2772 | /// |
| 2773 | /// @ingroup GPU |
| 2774 | FfxFloat16x2 ffxCubeRootHalf(FfxFloat16x2 c) |
| 2775 | { |
| 2776 | return pow(c, FFX_BROADCAST_FLOAT16X2(1.0 / 3.0)); |
| 2777 | } |
| 2778 | |
| 2779 | /// Compute the cube root of a value. |
| 2780 | /// |
| 2781 | /// @param [in] c The value to compute the cube root for. |
| 2782 | /// |
| 2783 | /// @returns |
| 2784 | /// A cube root of the input value. |
| 2785 | /// |
| 2786 | /// @ingroup GPU |
| 2787 | FfxFloat16x3 ffxCubeRootHalf(FfxFloat16x3 c) |
| 2788 | { |
| 2789 | return pow(c, FFX_BROADCAST_FLOAT16X3(1.0 / 3.0)); |
| 2790 | } |
| 2791 | |
| 2792 | /// Compute a linear value from a REC.709 value. |
| 2793 | /// |
| 2794 | /// @param [in] c The value to convert to linear from REC.709. |
| 2795 | /// |
| 2796 | /// @returns |
| 2797 | /// A value in linear space. |
| 2798 | /// |
| 2799 | /// @ingroup GPU |
| 2800 | FfxFloat16 ffxLinearFromRec709Half(FfxFloat16 c) |
| 2801 | { |
| 2802 | FfxFloat16x3 j = FfxFloat16x3(0.081 / 4.5, 1.0 / 4.5, 1.0 / 0.45); |
| 2803 | FfxFloat16x2 k = FfxFloat16x2(1.0 / 1.099, 0.099 / 1.099); |
| 2804 | return ffxZeroOneSelectHalf(ffxZeroOneIsSignedHalf(c - j.x), c * j.y, pow(c * k.x + k.y, j.z)); |
| 2805 | } |
| 2806 | |
| 2807 | /// Compute a linear value from a REC.709 value. |
| 2808 | /// |
| 2809 | /// @param [in] c The value to convert to linear from REC.709. |
| 2810 | /// |
| 2811 | /// @returns |
| 2812 | /// A value in linear space. |
| 2813 | /// |
| 2814 | /// @ingroup GPU |
| 2815 | FfxFloat16x2 ffxLinearFromRec709Half(FfxFloat16x2 c) |
| 2816 | { |
| 2817 | FfxFloat16x3 j = FfxFloat16x3(0.081 / 4.5, 1.0 / 4.5, 1.0 / 0.45); |
| 2818 | FfxFloat16x2 k = FfxFloat16x2(1.0 / 1.099, 0.099 / 1.099); |
| 2819 | return ffxZeroOneSelectHalf(ffxZeroOneIsSignedHalf(c - j.xx), c * j.yy, pow(c * k.xx + k.yy, j.zz)); |
| 2820 | } |
| 2821 | |
| 2822 | /// Compute a linear value from a REC.709 value. |
| 2823 | /// |
| 2824 | /// @param [in] c The value to convert to linear from REC.709. |
| 2825 | /// |
| 2826 | /// @returns |
| 2827 | /// A value in linear space. |
| 2828 | /// |
| 2829 | /// @ingroup GPU |
| 2830 | FfxFloat16x3 ffxLinearFromRec709Half(FfxFloat16x3 c) |
| 2831 | { |
| 2832 | FfxFloat16x3 j = FfxFloat16x3(0.081 / 4.5, 1.0 / 4.5, 1.0 / 0.45); |
| 2833 | FfxFloat16x2 k = FfxFloat16x2(1.0 / 1.099, 0.099 / 1.099); |
| 2834 | return ffxZeroOneSelectHalf(ffxZeroOneIsSignedHalf(c - j.xxx), c * j.yyy, pow(c * k.xxx + k.yyy, j.zzz)); |
| 2835 | } |
| 2836 | |
| 2837 | /// Compute a linear value from a value in a gamma space. |
| 2838 | /// |
| 2839 | /// Typically 2.2 for some PC displays, or 2.4-2.5 for CRTs, or 2.2 FreeSync2 native. |
| 2840 | /// |
| 2841 | /// @param [in] c The value to convert to linear in gamma space. |
| 2842 | /// @param [in] x The power value used for the gamma curve. |
| 2843 | /// |
| 2844 | /// @returns |
| 2845 | /// A value in linear space. |
| 2846 | /// |
| 2847 | /// @ingroup GPU |
| 2848 | FfxFloat16 ffxLinearFromGammaHalf(FfxFloat16 c, FfxFloat16 x) |
| 2849 | { |
| 2850 | return pow(c, FFX_BROADCAST_FLOAT16(x)); |
| 2851 | } |
| 2852 | |
| 2853 | /// Compute a linear value from a value in a gamma space. |
| 2854 | /// |
| 2855 | /// Typically 2.2 for some PC displays, or 2.4-2.5 for CRTs, or 2.2 FreeSync2 native. |
| 2856 | /// |
| 2857 | /// @param [in] c The value to convert to linear in gamma space. |
| 2858 | /// @param [in] x The power value used for the gamma curve. |
| 2859 | /// |
| 2860 | /// @returns |
| 2861 | /// A value in linear space. |
| 2862 | /// |
| 2863 | /// @ingroup GPU |
| 2864 | FfxFloat16x2 ffxLinearFromGammaHalf(FfxFloat16x2 c, FfxFloat16 x) |
| 2865 | { |
| 2866 | return pow(c, FFX_BROADCAST_FLOAT16X2(x)); |
| 2867 | } |
| 2868 | |
| 2869 | /// Compute a linear value from a value in a gamma space. |
| 2870 | /// |
| 2871 | /// Typically 2.2 for some PC displays, or 2.4-2.5 for CRTs, or 2.2 FreeSync2 native. |
| 2872 | /// |
| 2873 | /// @param [in] c The value to convert to linear in gamma space. |
| 2874 | /// @param [in] x The power value used for the gamma curve. |
| 2875 | /// |
| 2876 | /// @returns |
| 2877 | /// A value in linear space. |
| 2878 | /// |
| 2879 | /// @ingroup GPU |
| 2880 | FfxFloat16x3 ffxLinearFromGammaHalf(FfxFloat16x3 c, FfxFloat16 x) |
| 2881 | { |
| 2882 | return pow(c, FFX_BROADCAST_FLOAT16X3(x)); |
| 2883 | } |
| 2884 | |
| 2885 | /// Compute a linear value from a value in a SRGB space. |
| 2886 | /// |
| 2887 | /// Typically 2.2 for some PC displays, or 2.4-2.5 for CRTs, or 2.2 FreeSync2 native. |
| 2888 | /// |
| 2889 | /// @param [in] c The value to convert to linear in SRGB space. |
| 2890 | /// |
| 2891 | /// @returns |
| 2892 | /// A value in linear space. |
| 2893 | /// |
| 2894 | /// @ingroup GPU |
| 2895 | FfxFloat16 ffxLinearFromSrgbHalf(FfxFloat16 c) |
| 2896 | { |
| 2897 | FfxFloat16x3 j = FfxFloat16x3(0.04045 / 12.92, 1.0 / 12.92, 2.4); |
| 2898 | FfxFloat16x2 k = FfxFloat16x2(1.0 / 1.055, 0.055 / 1.055); |
| 2899 | return ffxZeroOneSelectHalf(ffxZeroOneIsSignedHalf(c - j.x), c * j.y, pow(c * k.x + k.y, j.z)); |
| 2900 | } |
| 2901 | |
| 2902 | /// Compute a linear value from a value in a SRGB space. |
| 2903 | /// |
| 2904 | /// Typically 2.2 for some PC displays, or 2.4-2.5 for CRTs, or 2.2 FreeSync2 native. |
| 2905 | /// |
| 2906 | /// @param [in] c The value to convert to linear in SRGB space. |
| 2907 | /// |
| 2908 | /// @returns |
| 2909 | /// A value in linear space. |
| 2910 | /// |
| 2911 | /// @ingroup GPU |
| 2912 | FfxFloat16x2 ffxLinearFromSrgbHalf(FfxFloat16x2 c) |
| 2913 | { |
| 2914 | FfxFloat16x3 j = FfxFloat16x3(0.04045 / 12.92, 1.0 / 12.92, 2.4); |
| 2915 | FfxFloat16x2 k = FfxFloat16x2(1.0 / 1.055, 0.055 / 1.055); |
| 2916 | return ffxZeroOneSelectHalf(ffxZeroOneIsSignedHalf(c - j.xx), c * j.yy, pow(c * k.xx + k.yy, j.zz)); |
| 2917 | } |
| 2918 | |
| 2919 | /// Compute a linear value from a value in a SRGB space. |
| 2920 | /// |
| 2921 | /// Typically 2.2 for some PC displays, or 2.4-2.5 for CRTs, or 2.2 FreeSync2 native. |
| 2922 | /// |
| 2923 | /// @param [in] c The value to convert to linear in SRGB space. |
| 2924 | /// |
| 2925 | /// @returns |
| 2926 | /// A value in linear space. |
| 2927 | /// |
| 2928 | /// @ingroup GPU |
| 2929 | FfxFloat16x3 ffxLinearFromSrgbHalf(FfxFloat16x3 c) |
| 2930 | { |
| 2931 | FfxFloat16x3 j = FfxFloat16x3(0.04045 / 12.92, 1.0 / 12.92, 2.4); |
| 2932 | FfxFloat16x2 k = FfxFloat16x2(1.0 / 1.055, 0.055 / 1.055); |
| 2933 | return ffxZeroOneSelectHalf(ffxZeroOneIsSignedHalf(c - j.xxx), c * j.yyy, pow(c * k.xxx + k.yyy, j.zzz)); |
| 2934 | } |
| 2935 | |
| 2936 | /// A remapping of 64x1 to 8x8 imposing rotated 2x2 pixel quads in quad linear. |
| 2937 | /// |
| 2938 | /// 543210 |
| 2939 | /// ====== |
| 2940 | /// ..xxx. |
| 2941 | /// yy...y |
| 2942 | /// |
| 2943 | /// @param [in] a The input 1D coordinates to remap. |
| 2944 | /// |
| 2945 | /// @returns |
| 2946 | /// The remapped 2D coordinates. |
| 2947 | /// |
| 2948 | /// @ingroup GPU |
| 2949 | FfxUInt16x2 ffxRemapForQuadHalf(FfxUInt32 a) |
| 2950 | { |
| 2951 | return FfxUInt16x2(bitfieldExtract(a, 1u, 3u), bitfieldInsertMask(bitfieldExtract(a, 3u, 3u), a, 1u)); |
| 2952 | } |
| 2953 | |
| 2954 | /// A helper function performing a remap 64x1 to 8x8 remapping which is necessary for 2D wave reductions. |
| 2955 | /// |
| 2956 | /// The 64-wide lane indices to 8x8 remapping is performed as follows: |
| 2957 | /// |
| 2958 | /// 00 01 08 09 10 11 18 19 |
| 2959 | /// 02 03 0a 0b 12 13 1a 1b |
| 2960 | /// 04 05 0c 0d 14 15 1c 1d |
| 2961 | /// 06 07 0e 0f 16 17 1e 1f |
| 2962 | /// 20 21 28 29 30 31 38 39 |
| 2963 | /// 22 23 2a 2b 32 33 3a 3b |
| 2964 | /// 24 25 2c 2d 34 35 3c 3d |
| 2965 | /// 26 27 2e 2f 36 37 3e 3f |
| 2966 | /// |
| 2967 | /// @param [in] a The input 1D coordinate to remap. |
| 2968 | /// |
| 2969 | /// @returns |
| 2970 | /// The remapped 2D coordinates. |
| 2971 | /// |
| 2972 | /// @ingroup GPU |
| 2973 | FfxUInt16x2 ffxRemapForWaveReductionHalf(FfxUInt32 a) |
| 2974 | { |
| 2975 | return FfxUInt16x2(bitfieldInsertMask(bitfieldExtract(a, 2u, 3u), a, 1u), bitfieldInsertMask(bitfieldExtract(a, 3u, 3u), bitfieldExtract(a, 1u, 2u), 2u)); |
| 2976 | } |
| 2977 | |
| 2978 | #endif // FFX_HALF |