perf(shader): check f32 NaN sources only for NaN results, narrow window reads #12548
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/12548"
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 josealissonbr on 2026-10-28T19:11:52Z.
What
The f32 add, sub, mul and fma NaN rule (
nanResultF32) selected over every source after every operation: one compare and one select per source on each of these instructions. The new IR opcodeNanPropagateF32keeps the same result bits but checks the sources in a branch taken only when the host result is NaN. That is exact because every module declares f32SignedZeroInfNanPreserve, so a NaN source always gives a NaN host result, and the tiny-product flush needs finite factors and a zero addend. Immediate sources are emitted as integer constants, since a float constant bitcast quiets a signaling NaN on NVIDIA. The SRT evaluator evaluates the opcode with the same rule, and the passes that inspect selects (masked select, redundant value, tessellation lowering, denormal flush) know it.VectorWindowIndexNarrowerlists the few values a relative read index can take (adds, shifts, masks, bit-field extracts and selects of known values, at most 16) and, when every relative access of a window is such a read and every listed value is inside the window, reads the listed constant slots and selects between them, so the window needs no indexed access. It changes nothing when any window access is a store or has an index it cannot bound.Each change alone made no difference in the measured scene; together they shorten the two particle passes of the PPSA01325 title screen. The behaviour is generic: no title, shader or address is matched.
docs/dev/debt/shader.mdrecords both, including that the SRT tape compiler does not know the new opcode and falls back to the interpreter.Tests:
ShaderMemorycovers the evaluator with NaN, signaling NaN, IEEE and non-IEEE sources and the invalid product;VectorWindowcovers the narrowed shape of a dynamic function access; the new GPU testexecution/RelativeIndexingBoundedValuesruns relative reads whose index takes a small set of values and checks every lane.Tested
Windows 11 Pro 26200, Intel Core i5-14400, NVIDIA GeForce RTX 5070 (driver 616.64), MinGW GCC 15.2 Release build.
ANYPS5_REQUIRE_VULKAN=1andANYPS5_NO_SHADER_CACHE=1: 2862 of 2862 passed on this head (4dee5b5e32,main319621ba2emerged), and 2857 of 2857 on0c620add72(maine4da19aff0merged). The 65maincommits between them change one file of the recompiler (ControlFlow/src/GraphBuilder.cpp) and add one AGC test; neither touches the code of this change.agc_tests withVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation(Khronos layer built from b2b44c0, API 1.4.366),ANYPS5_REQUIRE_VULKAN=1andANYPS5_NO_SHADER_CACHE=1,ctest -R "^agc_" -V, onmaine4da19aff0and on0c620add72, same machine and GPU: 1138 of 1138 and 1139 of 1139 passed (the extra one is the new test). Neither log reportswas not found but was requested by env var VK_INSTANCE_LAYERS; the same 20 tests log validation messages on both, with the same IDs, and this change adds no newVUID-ID.--windows --windows-gui --to-intel, from start without input to the title screen, 3840x2160.maine4da19aff0against0c620add72(this branch before the merge ofmain319621ba2e), both built in the same session on the same machine. Each capture is 20 s from 110 s after start (APS5_TRACE_SECONDS=110:20, no other switch, log not redirected), after one warm-up run of each build; captures ran alternating main 1, change 1, main 2, change 2. All four windows are on the looping title screen animation.e4da19aff00c620add72e4da19aff00c620add72Summary lines:
tools/trace_digest.pyon main 1 and change 1: GPU busy drops from 56.1 to 41.4 ms per frame and frame p50 from 70.5 to 56.7 ms (about 14.2 to 17.6 FPS). The queue worker that waits for the GPU (queue worker 0x3d) spends 54.3 ms per frame inDriver.Packet.memory_waitonmainand 50.4 ms on this change, and the presenter waits 15.4 against 4.9 ms. The 1754 ms frame in change 2 is oneVulkan.GraphicsPipelineLibrarycreation (1643 ms) for a pipeline the title first uses there: with the faster build, 110 s after start falls later in the title animation (present 2494 against 2171 onmain), and no other frame of the change captures exceeds 192 ms.Before this merge, a local GPU pass timer (not part of this change) measured the two particle passes on
maine2a511883at 16.6 and 14.7 ms of GPU time per frame, 17.7 and 16.0 ms with the NaN branch alone, and 8.6-9.0 and 6.2-6.5 ms with both changes.tools/trace_digest.py, main 1seconds 110:20 from present 2171: 283 presents, frame p50 70.5 / p90 73.8 / p99 77.1 / max 81.7 ms, GPU busy 56.2 ms per present
NVIDIA GeForce RTX 5070, NVIDIA 616.64, Windows 10.0.26200, 3840x2160, commit
e4da19aff0, dropped: noSlowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 136.7, Driver.Packet.memory_wait 56.2, batch 56.1, Driver.Packet.dispatch 26.5, Driver.Dispatch 25.9, Vulkan.Dispatch 23.9, Vulkan.Dispatch.shader_resources 23.6, Driver.Packet.draw 18.2, Driver.Draw 18.1, Driver.Packet.prepare_memory 17.9
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
tools/trace_digest.py, change 1seconds 110:20 from present 2036: 351 presents, frame p50 56.7 / p90 59.7 / p99 64.3 / max 66.5 ms, GPU busy 41.5 ms per present
NVIDIA GeForce RTX 5070, NVIDIA 616.64, Windows 10.0.26200, 3840x2160, commit
0c620add72, dropped: noSlowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 109.6, Driver.Packet.memory_wait 52.1, batch 41.4, Driver.Packet.dispatch 16.6, Driver.Dispatch 16.0, Vulkan.Dispatch 14.2, Vulkan.Dispatch.shader_resources 13.9, Graphics.Draw 13.8, Driver.Packet.prepare_memory 12.9, Driver.Packet.draw 12.4
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
Traces (slice timings only; they open in ui.perfetto.dev):
aps5-trace-0c620add72d2-22844.json.gz
aps5-trace-e4da19aff06e-35696.json.gz
aps5-trace-e4da19aff06e-40620.json.gz
aps5-trace-0c620add72d2-15132.json.gz
Overlap: this is offered in place of #4287, which reduces the same
nanResultF32select chain to one quiet and one fallback select and has been waiting for title numbers; this change keeps the NaN rule out of the common path instead and brings those numbers. #10720 changes the same lines behindAPS5_FAST_F32; #12233 touches the neighbouring line ofdocs/dev/debt/shader.mdand #12324 a line ofRecompiler.cppnext to the new pass.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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-28T19:46:27Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
The performance evidence is present, but this branch overlaps open PRs #4287 and #10720 without recording an agreed integration order; combining it with #10720 produces a source conflict.
What I ran
4dee5b5e3296c643731e19eca13ddad80d1e49abagainst base319621ba2e578bd053b0baba2877fe70520e0737; current-main merge treedb3ff82497c56456347fdd03f9822d02a37bb553is clean.git diff --check refs/review/current-main...refs/review/12548— pass, no output.nanResultF32behavior; #10720 is open and changes the same operand-access logic. Pairwise merge with #4287 is clean, but pairwise merge with #10720 reports a content conflict inOperandAccess.cpp.Results
OperandAccess.cpptrace_digest.pyoutput; captures report no dropped eventsRaw combined-merge output with #10720
Negative control
Findings
Blocking
nanResultF32NaN selection behavior; the PR says this is offered in its place, but no agreement or supersession order is recorded. #10720 also remains open, and a combined merge preview with its current head conflicts inOperandAccess.cpp. The repository requires authors of overlapping PRs to agree on landing order and record it withDepends on. Please coordinate with the affected authors and update the checklist/body to state the agreed order or replacement plan; rebase and rerun overlap checks where required. This request is about integration, not pressure to close either PR.Non-blocking
The performance report is substantially complete: paired captures use the same title, scene, machine, driver and resolution; the four trace files and digest output are attached. I did not independently validate those trace binaries or reproduce the Vulkan measurements.
Sources
Not verified
I did not run the full CTest suite, Vulkan validation tests, GPU capture, the SRT tape path, or console/title tests. Hosted product Linux is skipped and macOS relinker checks were still pending. Author-reported test runs and trace measurements are not my own runs.
To get this to a good state
Record an author-agreed integration order/replacement plan for #4287 and #10720, then rebase and rerun the overlap check. I will review the updated head and retest the affected integration paths.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-28T19:51:20Z.
Review: CHANGES_REQUESTED
Checked the diff against the existing
nanResultF32rule. The NaN branch keeps the same bits (the legacy mul/mad forms zero the factors before the call, the invalid-product guard for a NaN addend is kept, the SRT evaluator applies the same order), and the window narrower falls back whenever any access is a store or an index is unbounded. The numbers are clear. Two things block the merge:OperandAccess.cpp:345-351rewrites the samenanResultF32body that #4287 reduces (waiting for title numbers, with @oneandonlydean's ordering "#4287 first, then #10720 rebases onto it"), and #10720 changes the same lines behindAPS5_FAST_F32. Please say which of the three lands and how: either list #4287/#10720 in Depends on and rebase on the one that goes first, or state that this replaces #4287 and why the branch version is better, and show that it still merges with #10720 (it conflicts today, as MarcZX10 reported).SrtEvaluator.cpp:372turnsif (value.ArgumentCount() < *arguments) return true;intoreturn false;for every opcode inevaluatedArguments, not onlyNanPropagateF32. Drop it, or explain why it is needed and add a test where it changes the result.Smaller:
docs/dev/debt/shader.mdis accurate, but the 16-value limit of the narrower and the compare-chain cost are unmeasured; a line in Tested on a program with many listed reads would settle that.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-31T17:18:27Z.
Review: CHANGES_REQUESTED
Checked the new head against our last review. The
SrtEvaluator.cppchange is fixed in965b8775d8: the short-argument path is back toreturn trueand onlyNanPropagateF32takes the new case.One point is still open:
OperandAccess.cpp(thenanResultF32rewrite) still conflicts with #4287 and with #10720 (git merge-treeagainst current heads), and the body saysDepends on: none. Please say which of the three lands and how: either list the one that goes first in Depends on and rebase onto it, or state that this replaces #4287 and why, and show that it still merges with #10720.Smaller, optional: a line in Tested on a program with many listed reads would settle the 16-value limit of the narrower and its compare-chain cost.
Pull request closed