Repository navigation
perf(shader): emit the f32 NaN repair without its own selection - #28820
oneandonlydean wants to merge 1 commit into
Conversation
EmitNanPropagateF32 opened one DontFlatten selection per exact f32 result: branch on a NaN host result, select the source NaN inside, phi after. A large compute program carries hundreds to thousands of these in one function, and the vendor's pipeline compiler pays for each. The repair now runs unconditionally and one more select on the same NaN test picks between the repaired bits and the host result. The value is unchanged: the instructions that left the branch are bit casts, integer compares, selects and one OR. The form without NaN sources and the grouped region path are untouched. Offline creation of the 13 compute programs over 100000 words of PPSA21564 takes 64% of the time it took (56% to 76% per program, none slower), with 96.5% of the words and 45% of the selections. A warm paired run of PPSA21564 is neutral.
|
No actionable comments were generated in the recent review. Walkthrough
Change: Refactor Merge Risk:
|
|
Paired Linux check on AMD Radeon RX 6650 XT (RADV), comparing the PR base I gave the existing CPU fixture's four shaders distinct dump addresses and validated the eight modules with AI-assisted: yes. |
|
Data for the same transform from Windows and NVIDIA, on larger modules. My local build has carried this change since Nov 29 behind an opt-in switch, Host: Windows 11, RTX 3090 24 GB, NVIDIA 617.14. Offline pipeline creation. I captured six compute modules of 0.94 to 1.67 million SPIR-V words from a title and replayed them with
All six together went from 321.9 s to 245.3 s (−24%), with 96 to 98% of the words. No module got slower. Two forms that didn't help. Moving the repair into DontInline helper functions made creation 1.8 to 7 times slower. A Flatten hint on the existing selection stayed within 1% of the base time. Run time. On an open-source homebrew title at its 60 Hz cap, GPU busy per present was 3.82 and 3.46 ms with the branch, and 3.71 and 3.42 ms with the select form. Exactness on this host. I ran AI-assisted: yes. |
|
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — looks good
The reviewed change removes the NaN repair branch while preserving the result selection, and I found no defect in the changed code.
What I ran
Reviewed head f844ec4a1767f2742a44223390eaf8babdd66f76 using the prepared diff and manifest, the changed function’s source range, and the complete changed debt note. No tests or builds were run.
Results
| Check | Result | Note |
|---|---|---|
| Changed code review | passed | Repair selection remains gated by the NaN test |
| Tests | not run | No runtime checks performed |
Negative control
Not run; no test was run to invert the expected behavior.
Findings
Blocking
None.
Non-blocking
None.
Sources
Not verified
GPU execution, console compatibility, and performance claims in the description were not independently verified. No changed files were excluded by the manifest.
To get this to a good state
Nothing is required.
jassycliq's Windows data covers six larger modules from a title it does not name. Here are your 13 PPSA21564 programs, replayed on Windows with NVIDIA (RTX 5070 Ti, driver 621.24), plus this head in the title and its GPU tests. Compile time. The 13 programs together take about 72 to 74 s per pass on The largest program gains least. It took 8.0 to 8.4 s on
Crash Site also creates 3 programs that are not in your table, and 5 of yours a second time under other identities. All 21 pipelines together: 104.1 to 105.9 s per pass on How. I captured at Crash Site with Frame time. 3 pairs (A, B, B, A, A, B), 300 s each, medians over the summary intervals that start in the last 120 s of each run's log. Frame p50 is 86.5, 88.1 and 88.0 ms on Tests. On this GPU under Setup, the driver cache and the cold runsRyzen 5 7600X, Windows 10 19045. The driver wrote a Both sides started on a new, empty shader cache folder, so each got one cold warm-up run (A first, then B). Over the logged part of those runs (to 253 s and 261 s), the Not covered: one GPU and one machine, NVIDIA only. Captures from one level. No check of the picture beyond every run reaching and holding the level. Not tested: whether this shortens the PPSA38500 boots in #27914. AI-assisted: yes. |
Plyxen
left a comment
There was a problem hiding this comment.
Verified on Windows 11 (GCC 15.2, Release) on main 484b036, with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1 and the Khronos validation layer 1.4.363. Every run log shows the loader inserting the layer and none shows "was not found". It ran on an RTX 5080 (621.24) and an AMD Radeon iGPU (26.11.2), together with #28802, #28780, #28646 and #28670.
- The f32 NaN group passed on main and on this change on both GPUs, with no
VUID-messages in any log:agc_driver_f32_arithmetic_nan,agc_driver_f32_arithmetic_nan_fast,agc_driver_fma_mix_f32_nan_sources,agc_nan_payload_elimination,agc_shader_memoryandagc_spirv_branch_targets. - Read the emitter change. The moved instructions are bitcasts, integer compares, selects and one OR, all side-effect free. The final
OpSelectonresultNangives what the old phi gave on both edges.
Not run: the pipeline creation timings and the PPSA21564 frame-time pair, and Linux.
AI-assisted: yes (Claude Code)
What
EmitNanPropagateF32opened oneDontFlattenselection per exact f32 result: branch on "the host result is a NaN", pick the source NaN inside, phi after. In large compute programs that is hundreds to thousands of small selections in one function, and the GPU vendor's pipeline compiler pays for each of them.Now the repair is emitted without its own selection: the same selects pick the source NaN, they always run, and one more
OpSelecton the same NaN test chooses between the repaired bits and the host result. The value is the same in every case: the instructions that moved out of the branch are bit casts, integer compares, selects and one OR, none with a side effect. The form without possible NaN sources was already a single select and is unchanged, and so is the grouped region path (EmitNanRegion), which keeps its one entry or exit test for a whole region.Why: on #27914 a reporter's boots spend about a minute of vendor compile per new compute program, with one function holding 90% or more of each module. I measured where that time goes on a title I hold and found this branch per result to be the largest single part I could remove without changing results.
The debt note of #17733 said the source repair branches on a NaN host result; its sentence is corrected in the pending fragment that adds the entry.
Tested
Linux (CachyOS, GCC 16, Release), NVIDIA GeForce RTX 4090, driver 610.57.04.
On this head:
agc_driver_f32_arithmetic_nan,agc_driver_f32_arithmetic_nan_fastandagc_driver_fma_mix_f32_nan_sources(they runv_add_f32,v_sub_f32,v_subrev_f32,v_mul_f32,v_fma_f32andv_fma_mix_f32forms with NaN sources on the GPU and compare the result bits, payloads included): pass.agc_nan_payload_elimination,agc_shader_memory,agc_spirv_branch_targets: pass.Measured with a build of
main7502170 that carries this same change behind a local switch (one binary, switch off and on; the switched-on path emits exactly what this PR emits):Vendor pipeline creation time, offline. The 13 compute programs over 100000 SPIR-V words that PPSA21564 creates in one level, captured once per arm and replayed with
agc_compute_pipeline_replay, one process per replay, fresh application cache, driver disk cache off, two passes. Times are the tool's fresh pipeline creation time in ms, on this host's E cores.All 13 together: pass 1 93648 ms to 60100 ms (64.2%), pass 2 96821 ms to 61391 ms (63.4%). Words 96.5%, selections 45.2%. No program got slower. The two passes of one capture differ by 3.8% in the median, 24% at most.
Frame time, PPSA21564, same scene, one perf window, warm shader caches (so this pair shows the run-time cost of always running the selects, not the compile gain): p50 over 180 to 330 s is 205.8 ms before and 208.6 ms after (+2.8 ms, +1.4%); the noise floor of this scene is 2 to 4 ms, so neutral. Presents per 10 s 49 and 48, GPU busy per present 81.8 ms and 80.8 ms. No crash, the level loaded and the frames show the same pictures in both arms.
Not claimed: that this unlocks PPSA38500 (#27914). It shortens the compile of each new large compute program there by an amount I measured only on PPSA21564's programs; whether that is enough for the reporter's boots is for a run on this head to show.
Windows: built and tested by CI only. No Windows host here.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Summary by CodeRabbit