perf(shader): adaptive SPIR-V, drop exact emulation where the device provably gives RDNA's bits #11183

Open
opened 2026-10-25 20:52:17 +00:00 by tibzejoker · 0 comments
tibzejoker commented 2026-10-25 20:52:17 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by tibzejoker on 2026-10-25T20:52:17Z.


Exact emulation is most of the SPIR-V we emit for float-heavy compute: up to ~400x the size of the source ISA. Part of it can go where the host GPU provably gives RDNA's bits. This issue tracks that series ("adaptive SPIR-V"), so steps don't collide and closed attempts are not repeated.

Rule for every step: a capability, a spec guarantee or a startup probe only chooses between two paths that give RDNA's bits; it never relaxes semantics. #6503 already does this for the f32 denormal flush (FloatFlushProbe runs the emulated and the hardware build on the device and keeps hardware only if they agree). Background: #4977.

Where the words are (current main)

Measured offline with agc_shader_replay on 79 compute requests from Grand Theft Auto V (open world), main e1ef22e88, RTX 4090 target (native f16 modes, no f32 denormal mode). 2,036,728 words in total; 0x25b390800 alone is 552k. Attribution: each emitted instruction traced back to the IR op and ISA instruction that produced it (88 % of words attributed; the rest is header, types, constants). The f16 sub-buckets are estimates (±25 % between them, total solid).

cause words share covered by
wave64 as two lanes per invocation 696k 34 % #7922, #8004
f32 NaN-result rule + software denormal flush 343k 16.9 % #6503 (needs a device f32 denormal mode: not on NVIDIA), #10720 (opt-in, not exact), #4287
f16 special-value rules (NaN pick, default NaN, FP16_OVFL, min/max) ~195k ~9.6 % issue #4042; #5057 closed
f16 ops computed in f32: conversions ~181k ~8.9 % native conversions already in main (#1252, #2411, #7698); what is left is mostly inside the f16 FMA emulation
f16 FMA in f32 with round-to-odd ~106k ~5.2 % #4072 closed
buffer bounds checks ~120k ~6 % #7484
module header 175k 8.6 % not exactness

Planned steps (one PR each, each with a test that fails on main and its own before/after numbers)

  1. Restore the SPIR-V pins (#11184). #6134 moved 3rdparty/SPIRV-Tools and 3rdparty/SPIRV-Headers back to v2025.4 / 01e057791 by accident, which undid #5319; spv::OpFmaKHR and spirv-val's SPV_KHR_fma support are gone again.
  2. Packed f16 FMA through OpFmaKHR (#11265: #4072 rebased, @queeeef's commit). Measured: GTA compute corpus -7.7 % words, 0x25b390800 NVIDIA pipeline creation 5445 -> 3743 ms. Vulkan lists OpFmaKHR as correctly rounded and subject to DenormPreserve; with RoundingModeRTE 16 that is RDNA's v_pk_fma_f16 for non-NaN inputs, and the existing NaN / FP16_OVFL / clamp rules run on the result bits. No probe needed. Devices without shaderFmaFloat16 (e.g. Intel UHD 770 on Windows) keep the f32 path.
  3. NaN payload of the remaining f16/f32 conversions, probe-gated in the #6503 style. The NaN space is small enough to probe exhaustively (2^11 f16 NaNs, 2^24 f32 NaNs).
  4. f16 special-value rules with fewer words, not more. #5057 was closed because its guard grew the module (+17 %) with no GPU gain; any step here has to shrink it.
  5. f32 NaN/denormal rules on devices without an f32 denormal mode (NVIDIA), by proof (value-class analysis: a result that cannot be denormal or NaN needs no repair, as LLVM's AMDGPU backend does with computeKnownFPClass) rather than by probe. Largest exact cause left; the most work.

Each step reports word counts and pipeline creation time on the same requests, and GPU time from a windowed trace (APS5_TRACE_SECONDS) for the affected batches.

Lessons from earlier attempts

  • Fma is not guaranteed to be fused in Vulkan (llvmpipe splits it; Intel fuses only with NoContraction on the result). Only OpFmaKHR is.
  • A probe must read its inputs from a buffer (drivers constant-fold otherwise), test the exact instruction template we emit, in the same stage and execution modes, and its result has to be in the shader cache key together with the driver version.
  • Declared float controls never promise RDNA's NaN payloads: they allow a mode, they don't prove a result.

If you are working on one of these steps, or know why one would be rejected, please say so here.

AI-assisted: yes (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:6029187010 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/11183). Originally posted by [tibzejoker](https://github.com/tibzejoker) on 2026-10-25T20:52:17Z. --- Exact emulation is most of the SPIR-V we emit for float-heavy compute: up to ~400x the size of the source ISA. Part of it can go where the host GPU provably gives RDNA's bits. This issue tracks that series ("adaptive SPIR-V"), so steps don't collide and closed attempts are not repeated. **Rule for every step:** a capability, a spec guarantee or a startup probe only chooses between two paths that give RDNA's bits; it never relaxes semantics. #6503 already does this for the f32 denormal flush (`FloatFlushProbe` runs the emulated and the hardware build on the device and keeps hardware only if they agree). Background: #4977. ### Where the words are (current `main`) Measured offline with `agc_shader_replay` on 79 compute requests from Grand Theft Auto V (open world), `main` e1ef22e88, RTX 4090 target (native f16 modes, no f32 denormal mode). 2,036,728 words in total; `0x25b390800` alone is 552k. Attribution: each emitted instruction traced back to the IR op and ISA instruction that produced it (88 % of words attributed; the rest is header, types, constants). The f16 sub-buckets are estimates (±25 % between them, total solid). | cause | words | share | covered by | |---|---|---|---| | wave64 as two lanes per invocation | 696k | 34 % | #7922, #8004 | | f32 NaN-result rule + software denormal flush | 343k | 16.9 % | #6503 (needs a device f32 denormal mode: not on NVIDIA), #10720 (opt-in, not exact), #4287 | | f16 special-value rules (NaN pick, default NaN, FP16_OVFL, min/max) | ~195k | ~9.6 % | issue #4042; #5057 closed | | f16 ops computed in f32: conversions | ~181k | ~8.9 % | native conversions already in `main` (#1252, #2411, #7698); what is left is mostly inside the f16 FMA emulation | | f16 FMA in f32 with round-to-odd | ~106k | ~5.2 % | #4072 closed | | buffer bounds checks | ~120k | ~6 % | #7484 | | module header | 175k | 8.6 % | not exactness | ### Planned steps (one PR each, each with a test that fails on `main` and its own before/after numbers) 1. **Restore the SPIR-V pins** (#11184). #6134 moved `3rdparty/SPIRV-Tools` and `3rdparty/SPIRV-Headers` back to v2025.4 / `01e057791` by accident, which undid #5319; `spv::OpFmaKHR` and spirv-val's `SPV_KHR_fma` support are gone again. 2. **Packed f16 FMA through `OpFmaKHR`** (#11265: #4072 rebased, @queeeef's commit). Measured: GTA compute corpus -7.7 % words, `0x25b390800` NVIDIA pipeline creation 5445 -> 3743 ms. Vulkan lists `OpFmaKHR` as correctly rounded and subject to `DenormPreserve`; with `RoundingModeRTE` 16 that is RDNA's `v_pk_fma_f16` for non-NaN inputs, and the existing NaN / FP16_OVFL / clamp rules run on the result bits. No probe needed. Devices without `shaderFmaFloat16` (e.g. Intel UHD 770 on Windows) keep the f32 path. 3. **NaN payload of the remaining f16/f32 conversions**, probe-gated in the #6503 style. The NaN space is small enough to probe exhaustively (2^11 f16 NaNs, 2^24 f32 NaNs). 4. **f16 special-value rules with fewer words, not more.** #5057 was closed because its guard grew the module (+17 %) with no GPU gain; any step here has to shrink it. 5. **f32 NaN/denormal rules on devices without an f32 denormal mode (NVIDIA)**, by proof (value-class analysis: a result that cannot be denormal or NaN needs no repair, as LLVM's AMDGPU backend does with `computeKnownFPClass`) rather than by probe. Largest exact cause left; the most work. Each step reports word counts and pipeline creation time on the same requests, and GPU time from a windowed trace (`APS5_TRACE_SECONDS`) for the affected batches. ### Lessons from earlier attempts - Fma is not guaranteed to be fused in Vulkan (llvmpipe splits it; Intel fuses only with `NoContraction` on the result). Only `OpFmaKHR` is. - A probe must read its inputs from a buffer (drivers constant-fold otherwise), test the exact instruction template we emit, in the same stage and execution modes, and its result has to be in the shader cache key together with the driver version. - Declared float controls never promise RDNA's NaN payloads: they allow a mode, they don't prove a result. If you are working on one of these steps, or know why one would be rejected, please say so here. AI-assisted: yes (Claude Code).
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5#11183
No description provided.