diff options
Diffstat (limited to 'runtime/src/depth24_convert.comp')
| -rw-r--r-- | runtime/src/depth24_convert.comp | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/runtime/src/depth24_convert.comp b/runtime/src/depth24_convert.comp index eb4795a35..688f68d78 100644 --- a/runtime/src/depth24_convert.comp +++ b/runtime/src/depth24_convert.comp | |||
| @@ -36,10 +36,11 @@ float depth24_to_float(uint d) { | |||
| 36 | // The 24-bit UNORM of f as WARP and AMD's D3D12 drivers write it: the product with 2^24 - 1 is rounded to a float | 36 | // The 24-bit UNORM of f as WARP and AMD's D3D12 drivers write it: the product with 2^24 - 1 is rounded to a float |
| 37 | // first, then to the nearest integer with ties to even (NVIDIA's hardware breaks some ties the other way; see | 37 | // first, then to the nearest integer with ties to even (NVIDIA's hardware breaks some ties the other way; see |
| 38 | // depth24.h). NaN and negatives give 0, 1 and above the maximum. | 38 | // depth24.h). NaN and negatives give 0, 1 and above the maximum. |
| 39 | uint depth24_from_float(float f) { | 39 | uint depth24_from_bits(uint bits) { |
| 40 | if (!(f > 0.0)) return 0u; | 40 | // In unsigned order, all negative encodings and positive NaNs lie above positive infinity. |
| 41 | if (f >= 1.0) return 0xffffffu; | 41 | if (bits > 0x7f800000u) return 0u; |
| 42 | return uint(roundEven(f * 16777215.0)); | 42 | if (bits >= 0x3f800000u) return 0xffffffu; |
| 43 | return uint(roundEven(uintBitsToFloat(bits) * 16777215.0)); | ||
| 43 | } | 44 | } |
| 44 | 45 | ||
| 45 | void main() { | 46 | void main() { |
| @@ -48,5 +49,5 @@ void main() { | |||
| 48 | uint a = pc.app_base + g.z * pc.app_slice + g.y * pc.app_row + g.x; | 49 | uint a = pc.app_base + g.z * pc.app_slice + g.y * pc.app_row + g.x; |
| 49 | uint s = pc.scratch_base + (g.z * pc.height + g.y) * pc.width + g.x; | 50 | uint s = pc.scratch_base + (g.z * pc.height + g.y) * pc.width + g.x; |
| 50 | if (pc.to_float != 0u) scratch[s] = floatBitsToUint(depth24_to_float(app[a] & 0xffffffu)); | 51 | if (pc.to_float != 0u) scratch[s] = floatBitsToUint(depth24_to_float(app[a] & 0xffffffu)); |
| 51 | else app[a] = depth24_from_float(uintBitsToFloat(scratch[s])); | 52 | else app[a] = depth24_from_bits(scratch[s]); |
| 52 | } | 53 | } |