perf(shader): emit the f32 NaN repair without its own selection #28820
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/28820"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-12-03T23:59:03Z.
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
main75021708bfthat 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
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-12-04T01:35:52Z.
Review: APPROVED
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
f844ec4a1767f2742a44223390eaf8babdd66f76using the prepared diff and manifest, the changed function’s source range, and the complete changed debt note. No tests or builds were run.Results
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.
Imported from boykopovar/AnyPS5. Originally posted by Plyxen on 2026-12-04T13:37:36Z.
Review: APPROVED
Verified on Windows 11 (GCC 15.2, Release) on main
484b0368d3, withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1and 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.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.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)
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.