perf(agc): drop superseded pending units of a foreign image under APS5_TAKEOVER_DISCARD #18348
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/18348"
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 klosixgaming-arch on 2026-11-11T10:58:25Z.
What
Draft, and not safe to merge as it is. It drops GPU results without proof that they are dead. I'm posting it so the measurements are on record while I work on the sound version, described at the end. It is off by default.
Some titles reuse one guest address range as a transient pool: within a frame, images of different sizes and formats start at the same address, one pass after another. In Cyberpunk 2077 these are 3200x1800, 2560x1440, 2048x2048, 1848x1040 and 1600x900 images. Each new image is refreshed over memory where an earlier image of another shape still holds pending GPU results. The refresh writes those results back to guest memory and then uploads the memory into the new image. The old contents are usually dead, because the new pass overwrites them, but nothing in the driver can prove it.
With
APS5_TAKEOVER_DISCARD:DiscardPendingInside) instead of writing them back.ScanPendingandFindPendingcount a pending image as over a range only where one of its pending units lies. After a takeover, a larger earlier image keeps pending units only outside the smaller new one. The extent check still named it, so the fast revalidation path failed and fell back to a full walk.Why it is unsafe. The fill HLE may drop pending units because the fill writes every byte of the range before anything else is recorded. Here the drop happens at the refresh, before the new image's write is recorded, and nothing proves that the write covers the range. If a later pass reads bytes the new image leaves unwritten (blending, partial coverage, padding, other mips or layers), it gets the older guest bytes instead of the dropped results. The frames I checked look right, but that is not a proof. The debt entry says the same.
The unit-overlap half is sound on its own: an image with no pending units in a range has nothing there that guest memory lacks. On
mainalone it gains nothing, because without the takeover the overlaps it ignores do not happen (in-run A/B onmain9bce44ce3b: +0.32 +- 0.21 presents per 10 s, n 11).The series this was found on. I found the takeover while stacking open PRs for Cyberpunk 2077, and most of the numbers below come from those stacks:
APS5_SETTLE_FLOOR_KIB=64) and #11485 by QRMOE (storage image uploads over several host imports).Here is this PR measured on top of them:
mainbc94a8e423+ #17786, #18078, #18075, #18076, #18102, #10443, #11485, #16371On the second stack the takeover halved storage-refresh write-backs (about 26 to 13.5 GB per 10 s) and cut the GPU wait from 8.2 to 3.8 ms per frame. Unit overlap cut full revalidation walks by 68% (about 8,600 to 2,700 per 10 s).
Tested
Cyberpunk 2077 (PPSA03974), the intro movie, 3200x1800, warm caches; Windows 11, RTX 5090 (driver 617.42), Ryzen 9 9950X3D. 2026-11-11.
Summary lines of
mainand of this PR. Separate runs, 5 minutes apart, with only the capture switches (APS5_TRACE_SECONDS=60:10,APS5_TRACE_SUMMARY_EVERY=10,APS5_TRACE_EVENTS=1048576), plusAPS5_TAKEOVER_DISCARD=1on this PR. Traces, all summary lines and the digests: https://github.com/klosixgaming-arch/AnyPS5/releases/tag/perf-captures-2026-11-11main14bff3fc4a:this PR,
2b129e3a43, withAPS5_TAKEOVER_DISCARD=1:mainVulkan.Dispatchper frameRecorder.Syncslices per presentIn-run A/B on this commit (
APS5_AB=10:APS5_TAKEOVER_DISCARDfrom 80 s, 11 B phases inside the movie): +14.1%, 35.75 to 40.79 presents per 10 s, B vs neighbouring A +5.10 +- 0.72 (SD 2.40). An earlier A/B ran while a game was using the GPU, so I don't count it; it gave +8.8% (n 9).These two disagree. The separate runs above show about +3.5% (+1.1% without the first window), and the A/B shows +14%. The A phases ran at 35.75, well below the 42.9 of
mainalone, so switching may cost the A phases, or that run was slower overall. Later in-run A/Bs of the sound version in #18369 gave +2.5% and +3.4%. That suggests this A/B's +14% carried a switching effect. The clear effects are the GPU time per present (-13%) and the GPU syncs per present (-30%). The frame is limited by queue worker 0x0 (87% busy in both traces), so those don't turn into frames one for one.Pictures. With the switch on (every 150th frame), the logos, the legal text, six scenes of the intro movie and the title render correctly.
takeover-frames.jpgis in the release.Tests. None yet. The sound version below will come with tests that fail without it.
trace_digest.py, main
14bff3fc4aseconds 60:10 from present 357: 44 presents, frame p50 230.4 / p90 253.0 / p99 278.4 / max 278.4 ms, GPU busy 43.4 ms per present
NVIDIA GeForce RTX 5090, NVIDIA 617.42, Windows 10.0.26200, 3200x1800, commit
14bff3fc4a, dropped: noSlowest frames (largest slices inside each, inclusive)
Persistent spikes (frame time above the fastest frame that separates it from a longer frame; one entry per stall, not per frame)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 440.3, Driver.Packet.dispatch 218.0, Driver.Packet.memory_wait 198.2, Driver.Dispatch 154.4, Vulkan.Dispatch 101.9, Vulkan.Dispatch.shader_resources 96.0, Graphics.Draw 65.4, Graphics.Draw.draw_and_resource_release 64.1, batch 43.4, Recorder.Sync 37.6
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
trace_digest.py, this PR
2b129e3a43with APS5_TAKEOVER_DISCARD=1seconds 60:10 from present 358: 46 presents, frame p50 219.2 / p90 245.2 / p99 265.1 / max 265.1 ms, GPU busy 38.2 ms per present
NVIDIA GeForce RTX 5090, NVIDIA 617.42, Windows 10.0.26200, 3200x1800, commit
2b129e3a43, dropped: noSlowest frames (largest slices inside each, inclusive)
Persistent spikes (frame time above the fastest frame that separates it from a longer frame; one entry per stall, not per frame)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 423.6, Driver.Packet.dispatch 209.5, Driver.Packet.memory_wait 191.4, Driver.Dispatch 141.1, Vulkan.Dispatch 91.3, Vulkan.Dispatch.shader_resources 85.9, Graphics.Draw 63.8, Graphics.Draw.draw_and_resource_release 62.4, batch 37.5, Recorder.Sync 27.8
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
The sound version
#18369 does this with a proof instead of a guess. The recompiler proves that a compute shader stores every texel of a storage image's level and never reads it, and the driver checks the grid, the user data and the other bindings per dispatch before it drops anything. Its in-run A/B on
mainis +3.4% (n 8).A census on
mainof the takeovers this draft makes, counted without dropping anything (832,522 units of 64 KiB in 12 reports):IR dumps of the top programs show copy-rectangle, clear, A16 swizzled and plain global-id stores, which the proof covers. They also show a read-modify-write of the same image at the same texel, about 6% of the units. This draft can drop results that shader then reads, so it can change what that shader computes. The frames I checked still looked right.
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)Pull request closed