perf(shader): eliminate redundant GetSrtResource and ReadConst in RVE #8727
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/8727"
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 hamb3r on 2026-10-20T22:36:40Z.
What
IrOpcode::GetSrtResourceandIrOpcode::ReadConstas recomputable inRedundantValueEliminatorso redundant SRT descriptor and flattened-SRT constant reads with identical arguments in the same or dominated basic blocks are eliminated before SPIR-V emission.ValueKey::memoryEpoch) across buffer/address writes, atomics, and barriers (ClobbersReadConst) via a reverse-post-order fixed-point pass soReadConstinstructions separated by a memory clobber on intra-block, branch-merge, or loop-backedge paths are not merged.RedundantValueElimination.cppcovering dominated-block merging ofGetSrtResourceandReadConst, intra-block store separation on the table address, branch-merge clobber propagation while preserving clean sibling-branch reuse, single-loop backedge store invalidation, and nested-loop fixed-point store propagation.Tested
x86_64), NVIDIA GeForce RTX 3080 (driver617.14):origin/main(0c6a5bd5938f) and this PR (f2a0dc0b746b) withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1, andVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation:ctest --test-dir build-portable -R "^agc_(redundant_value_elimination|shader_memory)$" -V:2/2 Passedon bothmainand this PR.was not found but was requested by env var VK_INSTANCE_LAYERSand0VUID-validation errors are logged.PPSA01341v01.007.000, steady-state window after the first present withAPS5_TRACE_SECONDS=10:5, 2 repeats onmainand 2 repeats on this PR):gpu_busy_ms_per_present:8.851and8.827ms onmain(mean8.839ms) vs8.562and8.411ms on this PR (mean8.487ms,-4.0%).frame_ms.p50:31.516and30.593ms onmainvs29.866and30.914ms on this PR.main(0c6a5bd5938f, run 1):aps5-trace-0c6a5bd5938f-49564.json.gzmain(0c6a5bd5938f, run 2):aps5-trace-0c6a5bd5938f-47980.json.gzf2a0dc0b746b, run 1):aps5-trace-f2a0dc0b746b-48664.json.gzf2a0dc0b746b, run 2):aps5-trace-f2a0dc0b746b-55396.json.gztools/trace_digest.py—main(0c6a5bd5938f, run 1,aps5-trace-0c6a5bd5938f-49564.json.gz)seconds 10:5 from present 43: 152 presents, frame p50 31.5 / p90 35.2 / p99 80.0 / max 97.0 ms, GPU busy 8.9 ms per present
NVIDIA GeForce RTX 3080, NVIDIA 617.14, Windows 10.0.19045, 1920x1080, commit
0c6a5bd593, dropped: noSlowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 254.2, Driver.Packet.memory_wait 217.2, Driver.Packet.dispatch 32.4, Driver.Dispatch 28.2, Vulkan.Dispatch 14.8, Vulkan.Dispatch.shader_resources 13.5, Resources.Complete 9.6, batch 8.9, Driver.WorkerWait 4.2, Driver.WorkerWait.idle_and_completion_poll 4.1
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
tools/trace_digest.py—main(0c6a5bd5938f, run 2,aps5-trace-0c6a5bd5938f-47980.json.gz)seconds 10:5 from present 68: 163 presents, frame p50 30.6 / p90 33.1 / p99 38.9 / max 43.7 ms, GPU busy 8.8 ms per present
NVIDIA GeForce RTX 3080, NVIDIA 617.14, Windows 10.0.19045, 1920x1080, commit
0c6a5bd593, dropped: noSlowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 237.3, Driver.Packet.memory_wait 204.0, Driver.Packet.dispatch 28.8, Driver.Dispatch 24.8, Vulkan.Dispatch 13.9, Vulkan.Dispatch.shader_resources 12.6, Resources.Complete 9.2, batch 8.8, Driver.WorkerWait 3.8, Driver.WorkerWait.idle_and_completion_poll 3.7
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
tools/trace_digest.py— PR (f2a0dc0b746b, run 1,aps5-trace-f2a0dc0b746b-48664.json.gz)seconds 10:5 from present 57: 165 presents, frame p50 29.9 / p90 32.8 / p99 45.9 / max 48.6 ms, GPU busy 8.6 ms per present
NVIDIA GeForce RTX 3080, NVIDIA 617.14, Windows 10.0.19045, 1920x1080, commit
f2a0dc0b74, dropped: noSlowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 234.7, Driver.Packet.memory_wait 201.2, Driver.Packet.dispatch 29.0, Driver.Dispatch 24.9, Vulkan.Dispatch 13.8, Vulkan.Dispatch.shader_resources 12.5, Resources.Complete 9.0, batch 8.5, Driver.WorkerWait 3.8, Driver.WorkerWait.idle_and_completion_poll 3.7
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
tools/trace_digest.py— PR (f2a0dc0b746b, run 2,aps5-trace-f2a0dc0b746b-55396.json.gz)seconds 10:5 from present 64: 153 presents, frame p50 30.9 / p90 39.7 / p99 56.0 / max 81.1 ms, GPU busy 8.4 ms per present
NVIDIA GeForce RTX 3080, NVIDIA 617.14, Windows 10.0.19045, 1920x1080, commit
f2a0dc0b74, dropped: noSlowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 253.4, Driver.Packet.memory_wait 217.1, Driver.Packet.dispatch 31.3, Driver.Dispatch 27.2, Vulkan.Dispatch 14.7, Vulkan.Dispatch.shader_resources 13.2, Resources.Complete 9.4, batch 8.5, Driver.WorkerWait 3.9, Driver.WorkerWait.idle_and_completion_poll 3.9
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
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)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-20T22:49:35Z.
Review: COMMENTED
The implementation and reported focused runtime/performance results look plausible, but the optimizer regression suite does not appear to exercise the two opcodes newly made recomputable. Could you add a small IR test proving duplicate
GetSrtResourceandReadConstexpressions with identical operands merge in a dominated block, while a differentReadConstslot (and a sibling-only expression) remains distinct? That would directly guard the new opcode classifications instead of relying on the general BitCast recomputation case. I have not approved pending that coverage.Imported from boykopovar/AnyPS5. Originally posted by hamb3r on 2026-10-20T23:56:18Z.
Added the requested RVE unit test in
6c57cc3631(test(shader): cover GetSrtResource and ReadConst deduplication in RVE) and mergedorigin/mainin54bd2da7e0:origin/main(54bd2da7e0):c9e38be258andc76299f217replacedRecordBdaFaultWordsinEmitReadConst(SpirvMemoryInstructions.cpp) with an inlineOpAtomicStoretoBdaAbi::SrtGuardWordinsidemain(and addedverifyGuardedNullPointersinShaderMemory.cppasserting oneOpAtomicStoreper guard inmain), so54bd2da7e0adopts upstreamSpirvMemoryInstructions.cpp/SpirvEmitterState.hppand keeps this PR scoped toRedundantValueEliminator.cpp(pr_overlap.pynow reportsNo overlap with open pull requests).GetSrtResourceandReadConstRVE regression test (6c57cc3631incore/libs/prx/libSceAgcDriver/tests/RedundantValueElimination.cpp):GetSrtResource(0)andReadConst(srt, 2)instructions in dominated blocks (thenandmerge) merge into theheaddefinitions (b.eliminate() == 4u,!srtDominated.HasUses(),!readDominated.HasUses(),!srtMerge.HasUses(),!readMerge.HasUses()).ReadConst(srt, 3)with a different constant slot in the dominated block stays distinct while reusing the deduplicatedsrtHeadoperand (srtHead.UseCount() == 4u), and that sibling-onlyGetSrtResource(1)/ReadConst(..., 4)expressions inthenandotherwiseremain distinct (AllUsed({&readOtherSlot, &srtThenOnly, &readThenOnly, &srtSibling, &readSibling})).gcovcoverage:RedundantValueEliminator.cppachieves100.00%line coverage (119 / 119executable lines):text File 'E:/AnyPS5_original/core/shader/recompiler/Optimization/src/RedundantValueEliminator.cpp' Lines executed:100.00% of 119 ... 2563 : 17 : bool Recomputable(IrOpcode opcode) { 2563 : 18 : switch (opcode) { 1697 : 19 : case IrOpcode::BitCastU16F16: ... - : 125 : case IrOpcode::GetSrtResource: - : 126 : case IrOpcode::ReadConst: 1697 : 127 : return true; 866 : 128 : default: 866 : 129 : return false;cc @MarcZX10
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-21T05:44:53Z.
Independent Windows run of this PR (data only).
Environment: Windows 10 Pro 10.0.19045, Ryzen 7 5800X3D, WinLibs GCC 15.2.0 r7 (MinGW-w64 UCRT), Release, BUILD_TESTING=ON. Merge-tree of the PR head against
mainis clean. I built onlyagc_redundant_value_elimination_tests;ctest -N -R agc_redundant_value_eliminationlists exactly one test.Results (3 runs each):
agc_redundant_value_eliminationpasses 3/3.core/shader/recompiler/Optimization/src/RedundantValueEliminator.cppwith the version from the PR's merge base (5b59fbc553), then rebuilt. The test fails 3/3 (Failed). I restored the PR's files afterwards.GPU: the run output has no
Selected GPUline; no GPU claim is made.Not run: other platforms, the other tests in the same family, the full repository CTest, and any title or console run.
AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-10-21T18:05:54Z.
Review: COMMENTED
The change is two clean ideas (treat
ReadConstandGetSrtResourcewith identical arguments as recomputable; outline the guarded SRT check into a non-inlined helper so it is not repeated at every read site), and GPU busy per present falling 51.6 to 43.2 ms is a real result. The headline number in the description is not one.frame_ms.p50decreased from 970 to 160 ms (-83.55%) andwindow.msfrom 181,523 to 8,382 ms". The base capture's first present took 178 s (present 1: 178158.2 ms, every queue worker inDriver.Packetfor 178 s), the change's did not. That is a boot-time compile or load stall that differs between the two runs, not an effect of two shader passes, and p50 over five presents is dominated by it. Please report the GPU busy figure and a window taken after the first present (a steady stretch,APS5_TRACE_SECONDS=...), with a repeat of each, and drop the -83% from the description.DontInlineputs a function call on every guardedReadConstinstead of an inline branch. It reduced code size and busy time on this GPU; the cost of a call depends on the driver's inlining and register allocation. Please run the same pair on an AMD card (and note the driver), since the NVIDIA compiler is the least likely to care.ReadConsts whose arguments are identical but separated by a store the table can see (they are not redundant), so the recomputable marking cannot become a wrong deduplication later.Imported from boykopovar/AnyPS5. Originally posted by hamb3r on 2026-10-21T21:25:33Z.
Thanks for the detailed review @CnRJay! All three points have been addressed in the rebased branch (
f2a0dc0b746bon top of0c6a5bd5938f):Steady-state performance traces (
APS5_TRACE_SECONDS=10:5)frames 0:5numbers:present 1in themaintrace included a 178 s cold shader-compilation stall while the branch trace ran with a warm cache.logs/andshader_cache/, warmed up the shader cache for each build, and captured two steady-state repeats (APS5_TRACE_SECONDS=10:5after the first present,"dirty": false) onorigin/main(0c6a5bd5938f) and two on this PR (f2a0dc0b746b) in Demon's Souls (PPSA01341v01.007.000):main(0c6a5bd5938f):gpu_busy_ms_per_present=8.851ms and8.827ms (mean8.839ms);frame_ms.p50=31.516ms and30.593ms.aps5-trace-0c6a5bd5938f-49564.json.gzaps5-trace-0c6a5bd5938f-47980.json.gzf2a0dc0b746b):gpu_busy_ms_per_present=8.562ms and8.411ms (mean8.487ms,-4.0%);frame_ms.p50=29.866ms and30.914ms.aps5-trace-f2a0dc0b746b-48664.json.gzaps5-trace-f2a0dc0b746b-55396.json.gz.json.gztrace links and the fulltools/trace_digest.pysummaries for all four runs.DontInlinehelper removal & AMD GPU checkc9e38be258landed onmain(shrinking the inline guarded SRT check inEmitReadConstto a singleOpAtomicStoretoSrtGuardWord), the out-of-lineDontInlineGuardedSrtFunctionhelper was already dropped in54bd2da7e0, leaving stale mentions in the PR title and description.origin/mainwithout the obsoleteDontInlinecommit and updated the PR title and body so they reflect the RVE-only change.DontInlinehelper is no longer part of the diff, the AMD GPU check for out-of-lineDontInlinecall overhead does not apply to the current RVE-only change.Memory-clobber invalidation for
ReadConst& unit testsValueKey::memoryEpoch, separate fromflags) inRedundantValueEliminator.cpp:ClobbersReadConst(IrOpcode)checksBufferAccessOf(Write/Atomic),AddressOpcodeInfoOf(Write/Atomic), andIrOpcode::Barrier.entryEpochandexitEpochacross CFG predecessors, assigning a stable merge epoch when predecessor epochs differ and advancing the epoch at each clobber instruction.ReadConstkeys includememoryEpoch, preventing CSE across intra-block, branch-merge, or loop-backedge writes/atomics/barriers while preserving CSE before a store and on clean sibling branches.RedundantValueElimination.cpp(withprogram.srtReadslinkingReadConstto aLoadAddressU32on the table address and storing viaStoreAddressU32to the same address and offset):GetSrtResourceandReadConstwhile another slot or sibling block stays.StoreAddressU32between twoReadConstinstructions of the same slot prevents merging (b.eliminate() == 0u).thenbranch only beforemerge: cleanotherwisesibling reuses theheadread, while the post-store read inthenand the read inmergeare not merged (b.eliminate() == 1u).body -> header) prevents reusing the pre-loopReadConstinheader(b.eliminate() == 2u).ReadConst(b.eliminate() == 2u).