perf(agc): a DCC key proof over untracked memory holds until the next ordering point #6209
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6209"
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-15T02:57:24Z.
What
Stacked on #6187; only the last two commits are this PR. Independent of #6192, except that both add a test at the same place in
CMakeLists.txtandtests/Recorder.cpp, a trivial conflict for whichever lands second.ProvedClearKeysandProvedCurrentDccKeysskip the scan of a surface's DCC keys while the key range is unchanged since the last scan, proved byCollectWritesandUnchangedSince. Over keys the write watch does not cover (on Windows, every host-pointer import of the guest mapping, #1441),CollectWritesreturns 0, so no proof is ever kept and every use scans the keys again.In RetroArch's Flycast core (PPSA99169) on Windows: 3.7 million key scans per 10 s (72 GB read, 2.2 s), with 0 proved and every one counted unstable.
NewestStamp(driver stores into the keys),ForgetStamp(#6187) and the recorder's newest pending write note over the keys. A scan that is otherwise stable becomes the proof with that stamp, and a later call with the same stamp returns the proved keys without scanning.compareUntracked,docs/dev/ARCHITECTURE.md): a CPU store into untracked memory is seen at the next ordering point. Pending GPU writes still make a scan unstable, as before.Tested
Windows 11, NVIDIA GeForce RTX 5070 Ti, MinGW-w64 GCC 15.2.0, on main
8cd937e29with #6187; rebased onto main92e50418fwith #6187 (only a CMake test list conflicted), where the full suite passes 1276 of 1296, 14 skipped, failing only the known tests below andagc_driver_multisample_fill_host_only, which passes when run alone.ctest: 1233 of 1249 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_key_proofs(agc_driver_recorder_tests --untracked-key-proofs-only): keys in an untracked allocation. In one collect epoch the secondProvedClearKeysand the secondProvedCurrentDccKeyscome from the proof; after a store into the keys and a new epoch the keys are scanned again and read as changed. Without this change the test fails with "a second key proof over untracked memory in the same collect epoch scanned the keys again".ProvedClearKeyschange alone did not move it measurably; with theProvedCurrentDccKeyschange as well, 65.3% and 66.9% of real time against 68.0% and 68.0% (that stack also had #6192). I have no measurement ofmainalone.Related: #6060 keeps Windows imports of private write-watched memory on
GetWriteWatchwhen a start-up probe allows it; key ranges it keeps watched never reach this path.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 ps54all on 2026-10-16T17:47:47Z.
Data point on Windows from a game: Metal Gear Solid 4 (PPSA18194), gameplay from a save, i9-10850K, RTX 3080 10 GB (610.74), MinGW GCC 15.2, Release. Local stack: #6188, #6187 + #6192, #6273, #6077, and this PR's code commit (
8f2c04e2b) on top; A/B is the same stack without it, 900 s each,APS5_PROFILE_DRAW=1, medians over 10 s gameplay windows. A local diagnostic splits the draw thread's render-target lookups byLookupOutcomesrow.readTargetper 10 sThe key ranges here sit in Windows host imports smaller than 1 MiB, so they were never write-watched and every target lookup scanned them twice (the refresh, then
materializeRegisterClear'sProvedCurrentDccKeys). HUD text and the rest of the picture look the same as without it (still shots at t600/t900). No errors over the run.Tested with AI assistance (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by Rajkamalcode on 2026-10-20T04:56:44Z.
SWAG (PPSA22102) check: the untracked population is small here, no hot-path reduction
Stack tested: #6187 + #6209 combined at
4cb0fd041(base448cf78c6), prx SHA-256 prefixE28ABA5A5C33DA72; baseline prx5AB0413B6D02CBFC. Same tree, only the stack differs.Measured
Setup: Squirrel with a Gun
01.000.000, stock settings (0156186E), stock scene, fixed pad schedule,APS5_SAMPLE_WORKER+APS5_PROFILE_DRAW=1, 360 s both runs. Baseline 22,952 samples (mid snapshot 17,933); stack 22,939 (17,932); worker thread 99.9% busy in both.Worker sampler, inclusive share of samples (function anywhere in the stack, all PCs aggregated, counted once per stack). Baseline final/mid2 -> stack final/mid2:
ShaderResources::CompleteShaderResources::buildCompleteresolveImageBindingcachedStorageTextureCompletePendingCpuWritesSyncThroughUploadFinishDrawPipeline::EnqueueRecorder::SyncVulkanDevice::DispatchDrawPipeline::DrainGuestMemory::GpuMutexType::lockMethod note: this aggregates every PC of a function. My earlier #7947 comment quoted only the hottest PC, which understates multi-PC functions there (e.g.
buildCompleteis 24.8% aggregate, not 13.6%).Untracked population, per 10 s window:
[textures]untracked snapshots kept/compared: 215/46 baseline vs 174/42 stack.[buffers]host imports under 1 MiB: baseline ~6235 settle reads, 6223-6226 back in the write watch, 3 kept compared under a storage image; stack ~6334, 6329-6332 back in the watch, 4 kept compared. The stack run also logs the proof work in[draw] pipelined: 2,583,788 read ranges and 6,992 stores held per 10 s; the baseline does not print these counters.Timing, same setup, steady tail medians (last 20 x 10 s windows):
readTarget134.3 -> 163.0 us/draw,resources104.9 -> 130.2,record28.7 -> 32.4,prepare6.1 -> 7.7, commit 260.4 -> 305.3 us, enqueue wait 110.1 -> 114.7. Caveat: the two runs' scene trajectories diverged (draws per 10 s window differ by up to ~2x in the first ~100 s; the two stock repeats show the same class of divergence), so these deltas are not clean PR attribution from one pair.AI-generated analysis (not measured)
The proof only pays when target key ranges are not write-watched. On SWAG nearly all sub-1 MiB host imports are back in the write watch (6223-6332 of ~6240), so there is almost nothing for the memo/proof to elide, unlike the MGS4 ranges in ps54all's comment. What changes instead is when the worker blocks: DCC path counts that do involve untracked comparisons go down (
Complete,buildComplete,cachedStorageTexture,CompletePendingCpuWrites, snapshots compared 46->42), whileRecorder::SyncandVulkanDevice::Dispatchgo up by more than that. Net: the hot path (ShaderResources::Complete22-24%, storage-texture binding work) is not reduced; on this title the change reads as correctness/coverage with a small overhead, not a perf win. I would keep MGS4 as the perf case and treat SWAG as neutral. No further A/B planned unless you want one; if useful I can run a low-settings variant (fewer dispatches, more draw/commit path) or a dedicated 4-run paired timing.Artifacts (I will drag them in):
swag-run26-baseline-symbolized.txt,swag-run27-stack-symbolized.txt,swag-stack-agg.txt,swag-stack-timing.txt,swag-run27-stack-worker.collapsed.txt.Imported from boykopovar/AnyPS5. Originally posted by Rajkamalcode on 2026-10-20T06:28:30Z.
swag-run26-baseline-symbolized.txt
swag-run27-stack-symbolized.txt
[swag-stack-agg.txt](https://github.com/u
swag-stack-timing.txt
ser-attachments/files/3370
swag-run27-stack-worker.collapsed.txt
3067/swag-stack-agg.txt)
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-23T02:56:06Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: guard the address-range arithmetic in
ForgetPagesandForgetStampagainst overflow.What I ran
Reviewed head
b00f936b31fe9ba4946ee35dd3fd9f9bc707806cfrom the prepared diff and pinned reader. I did not run tests or a build.Results
Findings
Blocking
GuestMemory::ForgetPagesandForgetStampcomputeaddress + bytes - 1without checking overflow. If a nonempty range ends pastUINT64_MAX, this wraps and computes an invalid last block;ForgetPagesmay then fail to invalidate the range stamp, andForgetStampmay report a stale stamp. This can leave a cached comparison or DCC key proof valid after memory in its range was forgotten. Validate the range before derivinglast, or use checked/saturating range arithmetic. Changed lines:core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp:487andcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp:81.Non-blocking
None.
Sources
ForgetPagesandForgetStampin the reviewed changed code atcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp.Not verified
files.jsonwas unavailable through the reader, so the exclusions list could not be checked. All seven changed paths listed inmanifest.jsonwere included; the final manifest entry,core/libs/prx/libSceAgcDriver/tests/Recorder.cpp, was not read in full, only the changed test hunks from the diff were inspected.To get this to a good state
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.