perf(shader): drop window stores no relative read can see #7560
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7560"
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 parl0v on 2026-10-18T14:02:10Z.
What
A program that uses relative VGPR addressing (
v_movrels*/v_movreld*) gets a per-invocation vector window, and every write to a register inside the window is also stored into it so relative reads see the value (IrBuilder::SetVectorReg). In Minecraft Dungeons II's hottest compute programs almost none of those stores can be read: program 0x1c00843000 has 2,196 window stores and 3 relative reads, and 2,117 of the stores are overwritten or reach the end of the program before any window load could see them. They still cost GPU time.MaskedSelectEliminatorcounts a window store as a reader of every lane, so the EXEC merge it stores stays (95 % of the merges left in that program are kept only by a window store), andDenormalFlushEliminatorthen keeps the input flushes behind those merges.VectorWindowStoreEliminatorruns after the read-lane step and beforeMaskedSelectEliminator. It is a backward liveness over the window slots: a constant-indexLoadVectorWindowreads its slot, a dynamic one reads every slot (dynamic indexes are clamped into the window), a constant-indexStoreVectorWindowoverwrites its slot, and a dynamic store overwrites nothing and is never removed. A constant-index store whose slot is not live after it is deleted. The window is per-invocation Function memory that onlyLoadVectorWindowreads, and a window store is an unconditionalOpStoreof the already merged value, so no loaded value changes in any lane. The existing passes then remove the merges and flushes those stores kept alive.agc_vector_window_testsgets a case where a window register is written twice before a relative read; it must leave as many window stores as writing it once. Without the pass it fails with "window stores: written twice 4, written once 3".Tested
Windows 10 19045, MinGW GCC, Release.
main1c523bdb4againstmainplus this commit: 8.14 / 8.10 / 8.10 / 8.08 FPS against 8.28 / 8.29 / 8.25 / 8.28 (+2.1 %). GPU time per frame of the three hottest window programs: 7.9 → 7.0 ms, 6.2 → 5.3 ms, 2.55 → 2.41 ms.agc_shader_replay --spv): program 0x1c00843000 goes from 238,094 to 212,781 SPIR-V words and from 7,509 to 5,921OpSelect; 0x1bc05c4000 from 212,409 to 190,772 words.APS5_TEXTURE_CACHE_MIB=3072, 4 rounds: the two hottest window programs go from 5.6 to 5.0 ms and from 4.5 to 4.0 ms per frame, but FPS stays within this box's noise (8.13 / 8.23 / 8.23 / 8.32 against 8.33 / 8.23 / 8.20 / 8.23): GPU busy drops from 96 to 95 ms and the idle gaps grow by about as much, so the frame there is set by more than the GPU.main385ed71f2: the 44 recompiler, window, relative-addressing, lane, DPP, denormal and masked-select tests pass, among themagc_vector_window,agc_vector_window_stage_inputs,agc_driver_relative_indexing,agc_driver_scalar_relative_indexing,agc_driver_relative_stage_inputs,agc_driver_relative_ancillary,agc_driver_vector_window_direct_access,agc_driver_vector_window_narrowing,agc_masked_select,agc_denormal_flush_elimination,agc_driver_read_lane,agc_shader_memory, theagc_structurizervariants and the DPP and denormal-mode execution tests. With the pass disabled, the new case inagc_vector_windowfails.agc_driver_vector_window_liveness(new,tests/execution/VectorWindowLiveness.cpp): a window register written before a scalar branch and overwritten on one side only, then read by a constant-indexv_movrelsafter the join (both sides run), and a register read at the top of a three-iteration loop and overwritten after the read; every lane's loaded value is checked in wave32 and wave64. WithliveOutignoring the successors it fails.tools/check_conventions.py --base origin/mainpasses.Performance capture (as the Performance report form describes): Minecraft Dungeons II (PPSA16064) title screen, RTX 3060 12 GB (i5-12400F), NVIDIA 617.42, Windows 10.0.19045, 3840x2160 output. Only
APS5_TRACE_SECONDS=120:12set, caches warm (the title ran once on the build and was restarted), stderr not redirected.main48d61f53b4against this PR's headca01351ff8:Frame and GPU times (ms):
Top phases (ms per frame):
Traces:
aps5-trace-48d61f53b46f-9720.json.gz(main) andaps5-trace-ca01351ff882-11512.json.gz(this PR), attached below.trace_digest.py, main
seconds 120:12 from present 2158: 99 presents, frame p50 117.2 / p90 145.0 / p99 158.4 / max 158.4 ms, GPU busy 100.7 ms per present
NVIDIA GeForce RTX 3060, NVIDIA 617.42, Windows 10.0.19045, 3840x2160, commit
48d61f53b4, dropped: noSlowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 235.3, batch 100.7, Driver.Packet.dispatch 86.1, Driver.Dispatch 85.2, Driver.Packet.memory_wait 68.0, Vulkan.Dispatch 39.4, Vulkan.Dispatch.shader_resources 37.1, Driver.Packet.device_lock 32.2, Driver.Packet.prepare_memory 27.8, Recorder.Sync 20.7
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
trace_digest.py, this PR
seconds 120:12 from present 2169: 101 presents, frame p50 114.7 / p90 143.2 / p99 164.2 / max 165.1 ms, GPU busy 97.5 ms per present
NVIDIA GeForce RTX 3060, NVIDIA 617.42, Windows 10.0.19045, 3840x2160, commit
ca01351ff8, dropped: noSlowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 229.8, batch 98.5, Driver.Packet.dispatch 83.0, Driver.Dispatch 82.1, Driver.Packet.memory_wait 66.2, Vulkan.Dispatch 37.9, Vulkan.Dispatch.shader_resources 35.5, Driver.Packet.device_lock 32.9, Driver.Packet.prepare_memory 26.5, Recorder.WaitSerial 19.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 github-actions[bot] on 2026-10-18T14:13:41Z.
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.
core/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/CMakeLists.txtcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/CMakeLists.txtcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/CMakeLists.txtcore/shader/recompiler/CMakeLists.txtcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/CMakeLists.txtcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/CMakeLists.txtcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/CMakeLists.txtcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/CMakeLists.txtcore/shader/recompiler/CMakeLists.txtcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.cppImported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-18T15:14:47Z.
Apple GPU / MoltenVK run, as a second vendor next to the RTX 3060/4060 runs. The pass changes the SPIR-V that SPIRV-Cross turns into Metal for every program with a vector window.
Machine: Apple M2 Max, macOS 27.2, x86-64 build under Rosetta. Head c7a652e87. Method: macos-port @ b7eb6b6b + ImportWatched + PR diff, not main. The pass, its header and the
Recompiler.cpphook applied cleanly. Two conflicts came from code the port doesn't have. InCMakeLists.txtI added onlyVectorWindowStoreEliminator.cpp. InVectorWindow.cppI added only your new "written twice" case, without main's v_readlane sampler case next to it. Drivers: MoltenVK 1.4.2 (SDK) and MoltenVK main + SPIRV-Cross #2704.Test set: the 31 tests matching
vector_window|relative|masked_select|denormal|readlane|read_lane|dpp|lane|movrel. They includeagc_vector_window,agc_vector_window_stage_inputs,agc_driver_relative_indexing,agc_driver_scalar_relative_indexing,agc_driver_relative_stage_inputs,agc_masked_select,agc_denormal_flush_eliminationand the read/write lane and DPP tests.Recompiler.cpphook removed (pass not run)agc_vector_windowalso fails withwindow stores: written twice 4, written once 3agc_driver_relative_ancillaryfails on both drivers because it needs geometry shaders (SPIR-V requires unsupported device capability 2).agc_driver_f32_denormal_flushfails on both because there is no f32 denormal preservation.agc_driver_dpp16_operandsfails only on the SDK driver, from the signed-zero issue that #2704 fixes. On the SDK driver the GPU tests in the set give the same result with and without the pass.The port doesn't have
agc_driver_vector_window_direct_accessoragc_driver_vector_window_narrowing, so those two were not run here. No timing measured on Apple.GPUs tested: Apple M2 Max (MoltenVK 1.4.2 and MoltenVK main + SPIRV-Cross #2704)
Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by parl0v on 2026-10-18T17:09:24Z.
Frame check on the RTX 3060 12 GB, MCD2 title screen, default settings, every 200th frame saved, two alternating rounds of
main1c523bdb4andmainplus this commit. Mean absolute difference per channel (0–255) at the same frame index:main(round 1)mainround 1 vs round 2main(round 2)The differences with the change match the run-to-run differences of
mainitself (the title's animation), so nothing visible changes. The same rows ran at 8.19 / 8.10 FPS onmainand 8.28 / 8.27 with this commit.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-18T19:52:01Z.
Thanks, the liveness looks right to me, and the reaching-store walks in the emitter keep their stores, because a store a load can reach is never dead.
One test gap: the new
agc_vector_windowcase compares store counts within one straight-line block. It can't catch a live store dropped across blocks, for example a slot written before a branch or loop and read by a constant-indexv_movrelsin a later block or the next iteration, which is where the fixpoint and theliveOutmerge matter. Could you add one execution case that checks a value: write a window register, branch or loop, then read it relatively in another block, and require the loaded value? The existing relative-indexing tests may already cover this, but none is aimed at this pass.Imported from boykopovar/AnyPS5. Originally posted by parl0v on 2026-10-18T20:10:01Z.
Added
agc_driver_vector_window_liveness(tests/execution/VectorWindowLiveness.cpp), which checks loaded values rather than store counts:v_movrelsin the block after the join. User data picks the side, so both paths run;Every lane's loaded value is checked, in wave32 and wave64. As a mutation check I made
liveOutignore the successors: the test then fails with "the window register written before the branch read 0x00000000, expected 0x00000001". With the pass as it is, it passes on my RTX 4060. I also rebased onto currentmain.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-18T20:10:09Z.
This pull request is labeled
perf, so it needs the summary line of a capture onmainand one with the change, from the same title, scene and machine, as the Performance report form asks. Please paste bothaps5-summary.jsonllines, attach the two traces and add the output oftools/trace_digest.py.Imported from boykopovar/AnyPS5. Originally posted by parl0v on 2026-10-18T22:09:09Z.
Traces of the performance capture in the description (they open in ui.perfetto.dev):
main48d61f53b: aps5-trace-48d61f53b46f-9720.json.gzImported from boykopovar/AnyPS5. Originally posted by savvaniss on 2026-10-19T06:36:14Z.
Intel and AMD Windows data:
agc_vector_windowfails onmainand passes with this PR, on an Intel UHD 770 and an AMD RX 9070 XT.Windows 11 Pro 26300, WinLibs GCC 15.2.0 r7, Release, every execution test built,
ANYPS5_NO_SHADER_CACHE=1, serial CTest. Intel UHD Graphics 770 (8086:a780), driver 32.0.101.7088. AMD Radeon RX 9070 XT (1002:7550), driver 32.0.31041.1004, withVkCacheemptied first. This headca01351ffmerged intomain07377573f. "Without" means this PR's test files onmain07377573f, with none of its other changes.agc_driver_vector_window_liveness,agc_vector_window,agc_vector_window_stage_inputsagc_vector_windowfailsThis is a correctness check only; I measured no speed.
I also ran full CTest with this PR and the 13 other open AGC and shader PRs I tested in the same batch merged together (#7668, #7659, #7504, #7432, #7426, #7413, #7480, #7465, #7466, #7464, #7449, #7489, #7673). Neither GPU showed a failure beyond
main's own: the five image-table tests (#6647) andagc_driver_sample_multisample_target(#6957) on the UHD 770, andagc_driver_layered_volume_vertex_no_gpl(#4768) on the RX 9070 XT.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by DavidAmsellem on 2026-10-19T16:28:00Z.
First AMD-on-Linux (RADV) run of this PR. Merged onto
main0fbfd91e5(clean merge), built in full and compared with the samemain, on the same machine.AMD Radeon RX 7900 XT (RADV NAVI31, gfx1100), Mesa 25.2.8, Linux Mint 22.3 (Ubuntu 24.04 base), kernel 7.0.0-38, GCC 13.3, Release.
Full suite (
ANYPS5_REQUIRE_VULKAN=1 ctest -j8): 1638/1640 with this PR, against 1637/1639 onmain. The failures are the same two on both, so this PR adds none:agc_driver_image_table_vouched_lookups(#7766, fixed by #7916) andagc_driver_guest_memory_lifetime(#7784). The newagc_driver_vector_window_livenessran (not skipped) and passed.GPUs tested: AMD Radeon RX 7900 XT (RADV NAVI31, gfx1100), Mesa 25.2.8, Linux Mint 22.3 / kernel 7.0.0-38
AI-assisted: yes