diff --git a/docs/FAST-PATHS.md b/docs/FAST-PATHS.md index 9afcfdfd7..cc2ce98b3 100644 --- a/docs/FAST-PATHS.md +++ b/docs/FAST-PATHS.md @@ -38,7 +38,7 @@ three consumer pipelines: A2X (`a2x-s4`, `a2x-s96`), Xgc14 (`xgc14-bgra8`) and X | The `half` conversion converts the value itself (no `NoContraction` barrier), so the device's compiler may fold it into the instruction computing the value, rounding once. | `half_rounding = HalfRoundingPolicy::Native` | `half_rounding = HalfRoundingPolicy::Exact` (with the rows above) | The row above's: on NVIDIA (RTX 3090), and on lavapipe for a loaded texel (Mesa 26.0.8), the pair is dropped whether or not the barrier stands, so the barrier does not restore the rounding there. `NativeHalfConversion` (`native-half-conversion`) | At its merge: A2X 0.99-1.02 s without the barrier against 1.00-1.05 s with it; Xgc within a round's spread | | A `half` texel's NaN is the rounding's own NaN, not the texel's bits (the keep's four instructions a texel are left out). | `half_rounding = HalfRoundingPolicy::Native` and `nan_and_min_max = NanMinMaxPolicy::Native` | `nan_and_min_max = NanMinMaxPolicy::Exact` (the keep under native half rounding); `half_rounding = HalfRoundingPolicy::Exact` also keeps it, at that row's cost. The same switch also gives Metal's full rule: `0x7e00` for every NaN but a one-texel read, nearest sample or gather of a 16-bit float texture, by the slot's format class read as data, a heap handle's class index and a runtime sampler's filter. A gather with a `half` result fetches its four texels where the class is a half-float one, since NVIDIA's gather hands back every NaN as `0x7fffffff`. **Not yet exact:** a cube gather, bicubic and emulated linear, fetched or compared samples; and on ANV (Iris Xe, Mesa 26.2.4) every 16-bit float texel's NaN, which its image decode answers as `0xFFC00000` (`0xFE00` as a `half`) before any keep, and on RADV (the Radeon 780M and the RX 7900 XTX, Mesa 26.2.4) a 16-bit float texel's NaN through a **sampler**, which answers `0xFFC00000` the same way where its image loads keep the texel's bits (`half-texel-nans-r16f`'s `nearest-sample` site differs, its `read` sites are exact): reading the texel's bits through an unsigned integer view would answer Metal's. Possible, not built: the runtime sampler's filter read as push data rather than specialized, which would spare the remake below. Measured on the RTX 5080: under the switch no `half` lane of the runtime lane's texel reads, samples and gathers differs from Metal's (1,469 differ by default). Under the switch `DeviceNanEncoding` is still announced; the consumer logs notes, so no device fact is built to drop it | NaN bits the device's (`0x7FFF` on the RTX 5080), where Metal hands back a 16-bit float texel's own bits on a read, nearest sample or gather, and `0x7e00` for a 32-bit or small float texel's NaN and a linear sample's. `NativeHalfConversion` (`native-half-conversion`); the read also records `DeviceNanEncoding` (`device-nan-encoding`) | Measured on top of the NaN switch's own row (a probe with the keep against one without): A2X 341,299 → 347,519 words, 1.82-1.86 → 1.81-1.87 s, GPU 0.115-0.117 → 0.115-0.116 ms, within noise; Xgc14 and Xgc15 read no `half` texel (words unchanged). The full rule (a probe with it against the same tree without it): A2X 347,519 → 372,429 words (+7.2%), creation 1.85-1.88 → 1.99-2.04 s; where a linear runtime sampler is bound at the draw the sampler word's filter is now specialized, so the first draw remakes (1.94-1.96 s) and its GPU time rises 0.115-0.117 → 0.124-0.125 ms; with a nearest sampler GPU 0.115-0.116 → 0.115-0.117 ms; Xgc14 and Xgc15 words unchanged. On the RTX 3090 the same pair: A2X creation 2.91-3.06 → 3.17-3.23 s, the first draw's remake 3.0 s and its GPU time 0.17-0.18 → 0.79-1.15 ms, with a nearest sampler 0.17-0.18 ms both | | On ANV and RADV, which round a `half` through the device's conversion under the float controls, a `half` read from its bits (a load, a reinterpretation, a texel's bits) is the device's widening of them as a 16-bit float, loops included, and a `half` texel takes that conversion's NaN (no keep): every value but a NaN is exact by the Vulkan spec. | `nan_and_min_max = NanMinMaxPolicy::Native` | `nan_and_min_max = NanMinMaxPolicy::Exact`: the integer decode and the texel's keep; a `half` widened to `float` then answers Metal's `0x7fc00000` for every NaN, read from memory, a texel or a select alike | A `half` NaN widened to `float` has the device's bits (ANV quiets a signalling NaN, RADV keeps it), where Metal answers `0x7fc00000`; a `half` stored back unchanged keeps its bits. `NativeNanEncoding` (`native-nan-encoding`); a texel's, `DeviceNanEncoding` (`device-nan-encoding`) | ANV (Iris Xe, Mesa 26.2.4), A2X: making 4.06-4.36 → 5.76-5.87 s, 269,828 → 280,070 words, peak RSS 0.35 → 0.51 GB, GPU 4.48 → 4.62 ms (warm); RADV (Radeon 780M, Mesa 26.2.4): 379-467 → 535-665 ms, GPU within its clock states' spread | -| A fragment function that states its math mode returns a `half` color to a blended attachment: the device blends in its own arithmetic and rounds once, where Metal blends a 16-bit float attachment itself -- without fast math in `half` arithmetic (each factor, product and sum rounded to `half`), and under fast math in the forms its compiler folds into the function, which round the source's product to the attachment and carry the destination's into the sum unrounded where a pair is contracted. | `half_blend = HalfBlendPolicy::Device` | `half_blend = HalfBlendPolicy::Exact`: the function computes Metal's blend in the interlocked storage form, for a `half` output of one to four lanes into `R16Float`, `RG16Float` or `RGBA16Float` where that form is exact for the pipeline (RADV, ANV, NVIDIA, MoltenVK); under fast math only where the blend state's form is measured word for word (`extended_range::blend::MEASURED_SIXTEEN`: `SourceColor` over `DestinationColor`, `DestinationAlpha` over `OneMinusDestinationAlpha`) and no lane of the output folds into the blend (`fetch::folds_into_blend`); and, under fast math, for a four-lane `half` or `float` output into `R32Float`, `RG32Float` or `RGBA32Float` at a state whose forms are Metal's (`extended_range::Blend::float32`, `Blend::fitted`: not a one-channel `SourceColor` over `DestinationColor`, nor one and zero), the attachment the function reads or the pipeline names taking it alike (the device-gap row on a fetched attachment's blend); elsewhere, and for lavapipe, 8-bit, a module naming no math mode or a blend of the second source, the device's blend and its note stay | 2.5 `half` ulps at the largest operand on NVIDIA (the blend color and one minus it), two on RADV, ANV and lavapipe (16-bit float); two `float` ulps (32-bit float, one on NVIDIA); one or two codes (8-bit, extended range); MoltenVK stores Metal's bytes, where under fast math it stores a code apart at a contracted pair (`half-output-blends-*`). Measured with and without the factors' magnitudes. `HalfOutputPrecision` (`half-output-precision`), `HalfOutputFastMathBlend` (`half-output-fast-math-blend`) | A probe (a `half4` over a 1920x1080 `RGBA16Float` target, One / OneMinusSourceAlpha): making 11.1 → 24.0 ms; GPU 25 → 82 us one draw, 506 → 2291 us 32 overlapping draws (the interlock orders them). RTX 3090 (the same draw): making 12.9 → 27.4 ms; GPU 45 → 115 us one draw, 648 → 3268 us 32 overlapping draws. The same route into `RGBA32Float`: GPU time unmeasured at this width; the fragment module grows as the 16-bit one's does (an M3 Max probe over this row's four committed profiles, a four-lane output over a blended `RGBA32Float`: 259-291 → 1382-1454 SPIR-V words, translation 0.27-0.34 → 0.31-0.36 ms a stage) | +| A fragment function that states its math mode returns a `half` color to a blended attachment: the device blends in its own arithmetic and rounds once, where Metal blends a 16-bit float attachment itself -- without fast math in `half` arithmetic (each factor, product and sum rounded to `half`), and under fast math in the forms its compiler folds into the function, which round the source's product to the attachment and carry the destination's into the sum unrounded where a pair is contracted. | `half_blend = HalfBlendPolicy::Device` | `half_blend = HalfBlendPolicy::Exact`: the function computes Metal's blend in the interlocked storage form, for a `half` output of one to four lanes into `R16Float`, `RG16Float` or `RGBA16Float` where that form is exact for the pipeline (RADV, ANV, NVIDIA, MoltenVK); under fast math only where the blend state's form is measured word for word (`extended_range::blend::MEASURED_SIXTEEN`: `SourceColor` over `DestinationColor`, `DestinationAlpha` over `OneMinusDestinationAlpha`) and no lane of the output folds into the blend (`fetch::folds_into_blend`); and, under fast math, for a four-lane `half` or `float` output into `R32Float`, `RG32Float` or `RGBA32Float` at a state whose forms are Metal's (`extended_range::Blend::float32`, `Blend::fitted`: not a one-channel `SourceColor` over `DestinationColor`, nor one and zero), the attachment the function reads or the pipeline names taking it alike (the device-gap row on a fetched attachment's blend); elsewhere, and for lavapipe, 8-bit, a module naming no math mode or a blend of the second source, the device's blend and its note stay | 2.5 `half` ulps at the largest operand on NVIDIA (the blend color and one minus it), two on RADV, ANV and lavapipe (16-bit float); two `float` ulps (32-bit float, one on NVIDIA); one or two codes (8-bit, extended range); MoltenVK stores Metal's bytes, where under fast math it stores a code apart at a contracted pair (`half-output-blends-*`). Measured with and without the factors' magnitudes. `HalfOutputPrecision` (`half-output-precision`), `HalfOutputFastMathBlend` (`half-output-fast-math-blend`) | A probe (a `half4` over a 1920x1080 `RGBA16Float` target, One / OneMinusSourceAlpha): making 11.1 → 24.0 ms; GPU 25 → 82 us one draw, 506 → 2291 us 32 overlapping draws (the interlock orders them). RTX 3090 (the same draw): making 12.9 → 27.4 ms; GPU 45 → 115 us one draw, 648 → 3268 us 32 overlapping draws. The same route into `RGBA32Float`: GPU time unmeasured at this width; the fragment module grows as the 16-bit one's does (an M3 Max probe over this row's four committed profiles, a four-lane output over a blended `RGBA32Float`: 259-291 → 1382-1454 SPIR-V words, translation 0.27-0.34 → 0.31-0.36 ms a stage; the same probe gives `RGBA16Float` 259-459 → 912-1988 words, so the wider attachment's module is the smaller of the two) | | A `half` or `float` read of a 16-bit float texture (`R16Float`, `RG16Float`, `RGBA16Float`, `RGBX16Float`) answers the device's decode of the texel, where Metal's `texture2d` never widens and hands back the texel's own code: a NaN's sign, payload and signalling bit survive on Metal and are gone once a device has decoded the texel into `f32`. | `half_texel_bits = HalfTexelBitsPolicy::Device` | `half_texel_bits = HalfTexelBitsPolicy::Exact`: a colour texture slot the function declares `access::read` takes a second sampled-image binding of the texture's unsigned-integer alias (`R16_UINT`, `R16G16_UINT`, `R16G16B16A16_UINT`; `metal::format::half_bits_read_view`, `RuntimeFact::HalfBitsTexture`), and each plain fetch branches on the bound format's class: the alias's 16 bits widened in integer arithmetic where it names 16-bit float channels, the device's texel for every other class. A slot the function may sample, gather, compare, write or update atomically keeps the device's decode, the slot having one declaration; so does a fetch with a shader-side out-of-bounds check, a sparse arm, clamp-to-edge or level views. A fetch through a snapshot takes the same arm from the snapshot's codes: the copy fetches the alias on the same branch and stores the 16 bits, so the one snapshot holds whichever arm the class selects. The alias holds codes, so a `One` in its component mapping would fill a channel with the code 1 (the `half` 2 ^ -24): a slot bound to a texture whose swizzle reads a channel as 1, one whose alpha reads 1 among them, takes both of its views unswizzled and the function swizzles the widened texel, under `VariantKey::swizzled_storage` | Every NaN texel collapses to `0x7e00`, so a signalling NaN, a payload NaN and a negative NaN all read as the one quiet positive NaN; no finite, zero, denormal or infinite texel differs. Measured on MoltenVK (Apple M3 Max, API 1.2, this chip's `f32` decode canonicalizing): 515 of 4,096 words at each of the three read sites of `half-texel-nans-r16f`, 1,026 for `-rg16f`, 2,045 for `-rgba16f`, largest difference 33,279 as unsigned words. On RADV (Radeon 780M and RX 7900 XTX, Mesa 26.2.4) the `read` and `read-through-sample` sites are exact and the sampler's `nearest-sample` answers its own negative quiet NaN `0xfe00`, which this switch does not reach (it covers the read, not the sample). ANV unaudited, expected to be MoltenVK's shape, through its image decode. Announced `device-nan-encoding` under either value: the note's clause is the bound class's, not the arm's | Unmeasured. One sampled-image descriptor and one view at each such slot, the texture's image mutable with the alias in its format list, and per plain fetch a branch on the class word, the alias fetch and about twenty integer instructions a channel. A snapshot of such a slot costs no further image, descriptor or byte: its copy carries the same branch and the same alias fetch, of the binding the slot already takes, into the snapshot its form already sizes | | A computed `half` or `float` color blended into an extended-range attachment (`BGR10_XR`, `BGRA10_XR`, `RGB10A8_2P_XR10`) rounds the blend's source as a loaded one; Metal's compiler rounds it by how it computed it. Every device. | The in-shader blend's loaded rounding (no switch) | **Not built yet:** Metal's rounding per shape is probed, not modelled | One code. `ExtendedRangeBlendSource` (`extended-range-blend-source`), `ExtendedRangeFloatBlendSource` (`extended-range-float-blend-source`) | Not measured | | A blend into a packed 16-bit attachment the device renders through its word view (`A1BGR5Unorm`, `ABGR4Unorm` on the RTX 5080; `WordAttachment`), which the function computes in the interlocked storage form, reads the attachment's codes, where Metal's tile holds the pass's clear and each earlier blend's result as a `half`, finer; under fast math it also sums a few states otherwise than Metal. Every device rendering such an attachment. | The in-shader blend over the codes (no switch) | **Not built yet:** the extended-range attachments' `half` shadow (`render/extended_shadow.rs`, `VariantKey::extended_shadows`) taken by word attachments: the runtime's shadow start and end, its load of the codes and the clear's halves, and the word's shadowed variant in `lower::fragment::fetch`, for a single-sampled pass (a multisampled one keeps the codes, as an extended-range one does). Fast math's regrouped sums have no model | One code: without fast math exact over a loaded attachment (the 2,891 states of the M3 sweep, every channel), under fast math 3,527 of 94,732,288 channels a code apart; after a clear or an earlier blend in the pass, a code apart where the two readings store different codes. `DeviceColorConversion` (`device-color-conversion`) | Not measured. Expected from the shadow's form: an `R16G16B16A16_SFLOAT` image of the pass's extent per such color (8 bytes a pixel, 16.6 MB at 1920x1080), set at the draw it starts by a fill or a load dispatch, and an 8-byte storage read and write per blended fragment inside the interlock beside the word's |