perf(agc): an untracked comparison memo holds until memory it covers is forgotten #6187
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6187"
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 TheAggie on 2026-10-15T01:19:25Z.
What
A storage image over guest memory the write watch does not cover (on Windows, every host-pointer import of the guest mapping, #1441) is checked by comparing its saved bytes with guest memory (
StorageTexture::compareUntracked). The comparison is memoized under a stamp, and one part of that stamp isGuestMemory::ForgetSerial, a single counter that moves on everyForgetPagescall anywhere in guest memory. A title that maps and frees memory all the time therefore drops every untracked image's memo, and each refresh compares the whole surface again.In RetroArch's Flycast core (PPSA99169) on Windows, that is the 1.7 MB render target compared about 26,000 times per 10 s, about 44 GB of
memcmp, a third of the draw committer's busy time. Counting which part of the stamp changed between compares: the forget serial in about 255,000 cases, the epoch or driver-store stamp in under 4,000 each, the write note in none.ForgetPagesalso raises a per-block stamp: a fixed table of 65,536 slots, one per 64 KiB block of the forgotten range (block index modulo the table), each holding the newest forget serial that touched it. A range wider than the table raises one shared stamp instead.GuestMemory::ForgetStamp(address, bytes)is the newest of those over a range. A collision between blocks only makes it newer, so the memo is dropped too often, never too rarely.compareUntrackedstamps withForgetStampof the surface instead of the global serial. A forget in progress (oddForgetSerial) still disables the memo, as before.No runtime switch: the memo rule is the same, only the forget part of the stamp is now per range.
Tested
Windows 11, NVIDIA GeForce RTX 5070 Ti, MinGW-w64 GCC 15.2.0, on main
8cd937e29; rebased onto main92e50418f(only a CMake test list conflicted), where the full suite with #6192 on top passes 1277 of 1296, 14 skipped, failing only the known tests below.ctest: 1232 of 1248 pass, 14 skipped.guest_call_trace_abortandwindows_backtrace_reportfail, and fail the same way on plain main here.agc_driver_prepared_graphics_prebuild_0/_1andundeliverable_host_exceptionfail under my test runner because it skips their environment changes and pass pattern; run with those, they pass.agc_untracked_forget(agc_driver_recorder_tests --untracked-forget-only): an untracked surface in its own allocation and a second untracked allocation. After the first refresh, a second refresh in the same epoch does not compare; invalidating the other allocation does not make the refresh compare; invalidating the surface's own memory does. With the old stamp (globalForgetSerial) the test fails with "forgetting memory the surface does not cover made its refresh compare again".ANYPS5_PRESENT_MODE=immediate, unprofiled. Measured on a local stack:maina453108cfplus local frontend support, #4943, #5906 and #5609, a port of #1201's pipelined draw committer, and two local changes (GPU-only lease pins, DCC key proofs in unwatched memory). Same stack without and with this change, two runs each: audio produced at 52.5% and 52.9% of real time against 63.1% and 62.6%. The committer's render target phase went from 10.4 to 5.25 µs per draw. I have no measurement ofmainalone with only this change.Related: #1441 introduced the compared imports on Windows. #5906 removes another Windows cost of the same exclusion (draw snapshots). #4448 attacks the same compare cost from the other side on i915, by keeping more surfaces watched (a smaller import window, no self-import of a watched surface); this PR only changes when the memo of a surface that stays untracked is dropped, so the two complement each other. Both add a function right after
ForgetSerialinGuestMemory.hpp/.cpp, which is a trivial conflict for whichever lands second. #6060 keeps Windows imports of private write-watched memory onGetWriteWatchwhen a start-up probe allows it; memory it keeps watched never reaches this path, so this PR matters for what stays untracked (imports through views, devices whose probe fails). I have not measured how much of the Flycast workload #6060 would cover.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by nicolasfalesy on 2026-10-16T08:52:51Z.
Tested on Linux (Arch),
c++ (GCC) 16.2.1 20260810, Release,BUILD_TESTING=ON,mainat5d9dcc42d2ec5401aebd089028b8d4d7410a77b4. GPU tests ran on lavapipe (Mesa 26.2.2, llvmpipe with LLVM 22.1.8).agc_untracked_forget(this PR's test,agc_driver_recorder_tests --untracked-forget-only) crashes onmainplus this PR (2 of 2), and also in a combined build of many PRs (3 of 3):The fault is inside lavapipe on a worker thread, not in AnyPS5 code:
It is not seen on an Intel Arc GPU, where the same build passes. So the test probably leaves memory that a queued command still reads (or writes) after
forget, which real GPUs tolerate and lavapipe does not. CONTRIBUTING says CI runs the Vulkan tests on lavapipe. I did not find which access it is.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-18T19:16:52Z.
Review: CHANGES_REQUESTED
The Linux build of this head (run 39153907046, lavapipe) fails on
agc_untracked_forgetwith***Exception: SegFaultafter 2 s; it passes onmain, so it comes from the new test. It is the same crash @nicolasfalesy reported on 2026-10-16 (inside lavapipe, on a worker thread), now reproduced in CI, so it blocks the merge.core/libs/prx/libSceAgcDriver/tests/Recorder.cpp:4102(untrackedForgetTests): the test host-imports thealigned_allocblocks, runsRefresh()on aStorageTexture, then tears down (Unregisterremoves the allocations and callsHostImportForagain). Please find which step lavapipe faults in (a backtrace on lavapipe) and make the teardown safe: wait for the device/queue to be idle before destroying the image and releasing the import, and keep the blocks alive until then. If the test does not need a real Vulkan import to prove the memo rule, testingGuestMemory::ForgetStampdirectly would also avoid it.The stamp logic itself is unchanged from the last review and fine; once the test passes on lavapipe this can go back to the queue.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-20T15:38:37Z.
@TheAggie a nudge on this one, because #6192 is stacked on it and shows a solid gain in a tester's run (p50 about 9% better). What blocks it is the maintainer's 18 Oct change request: this PR's own new test,
agc_untracked_forget, segfaults on Linux CI after about 2 s on lavapipe (run 39153907046), inuntrackedForgetTestsinRecorder.cpp. It passes on main, and nicolasfalesy reproduced the crash on 16 Oct. Once that's fixed (the remaining conflict is only the CMake test list), we can run CI on both PRs.Pull request closed