fix(agc): keep CPU stores made after a deferred DCC key store was recorded #6186
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6186"
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 ee6aba54 on 2026-10-15T01:17:16Z.
What
After a storage write-back the driver records a fill of the "uncompressed" DCC keys into the keys' host import (
StoreUncompressedOnGpu,Recorder::QueueKeyStore). The fill lands whenever the GPU reaches it. A title that waited for its label, released the metadata block and reused it for something else had the 0xff pattern written over its new bytes. In PPSA15304 the reused block held a descriptor table, and the next dispatch built from it stopped the title in the recompiler:The change:
APS5_NO_GUARDED_KEY_STORE=1restores the fills, and the[labels]line counts the guarded stores.APS5_TRACE_KEY_GUARD=1prints the pending writers of the stores that stay unguarded.[labels]line counts those blocks. Without write watching, the value compare stays the only guard. Key dwords in such a block that the CPU did not write keep their old value instead of 0xff: write watching does not tell which dwords of a 64 KiB block were written, and the alternative, the value compare, overwrites a CPU store of the value the keys held. This is intended and recorded indocs/dev/debt/libSceAgcDriver.md.HostImportDeviceAddress, built on #6185'sHostImportBufferStart), so an import whose buffer starts below its range (lead) is addressed at the keys.Scope: the guard covers the deferred key stores; the unit shadow publishes (slab to import) stay unguarded, since a kernel over every published dword read the snapshot and the import over PCIe and halved the present rate of PPSA15304. #4794 stores results right behind the draw instead; on this title that mode (then
APS5_EAGER_WRITEBACK=1) ran at 0.3 presents per second against 15 to 20 per 10 s with the deferred path and this guard, so the deferred path stays the one heavy titles need, and this guard keeps it safe where it crashed.Tested
Linux, Ubuntu 24.04, NVIDIA GeForce RTX 5080 (driver 595.99.02). New test
agc_guarded_key_store(a key clear recorded before the store: the keys end up stored; CPU stores made after the record survive, including one of the value the keys held, and the keys of a block the CPU left alone are stored).ctest -R agc_passes. PPSA15304 on currentmainwith #6185 alone stopped three times after 10 to 11 minutes in the section after the first drop with the descriptor fault above; with this change two runs of 20 and 25 minutes of continuous movement showed no fault, with 99.6 percent of the key stores guarded. Upstream'sAPS5_STORE_AT_LABEL=1did not prevent the fault in the same section.Checklist
main; no other open PR implements the same functions.mdfiles or images added to the repositoryImported from boykopovar/AnyPS5. Originally posted by ee6aba54 on 2026-10-15T01:37:07Z.
The overlap with #6182 is the option list in the test binary's main (tests/Recorder.cpp), both add a
--...-onlyentry at the same spot; whichever lands second rebases in a minute, no dependency.Imported from boykopovar/AnyPS5. Originally posted by Amoenus on 2026-10-15T06:40:27Z.
Same-value late CPU store: GPU reproduction
At unchanged head
dce8f47370a69581928466e3b93029a9b6e0d913, bothagc_changed_copyandagc_guarded_key_storepass five runs each. Changing only the existing late store from0x12345678uto0uand its expected preserved value to zero fails 5/5 with:Two-line reproducer on our fork; production is unchanged. This commit intentionally fails the test, not a proposed fix. Restoring the original head, rebuilding and rerunning both groups gives five passes each again. No internal skips; each run identifies the RTX 5080. Maximum iteration: 0.69s; same-value case 0.32s.
Environment: Windows 11 Enterprise 26200, WinLibs GCC 15.2.0, Release, NVIDIA GeForce RTX 5080, driver 610.62 / 32.0.16.1062. Built the recorder target/dependencies; shader caches disabled,
APS5_NO_GUARDED_KEY_STOREandAPS5_CHANGED_COPY_ALWAYSabsent. Ranctest -R '^agc_(guarded_key_store|changed_copy)$' -V --timeout 30 --repeat until-fail:5 -j 1; for the expected-failure variant, onlyagc_guarded_key_storewith--repeat until-pass:5.The shader sees
value=0xffffffff,before=0,held=0for both a same-value late store and no late store, so equality cannot distinguish them. Could the test retain this case? If preservation includes it, ordering/write provenance is needed beyond value equality; if the intended guest ordering forbids it, please state and test that constraint.Scope: public synthetic test on this PR head, not current-main integration, AMD/Linux/console coverage, or attribution of Sonic's loading stop. AI-assisted: yes (Codex).
Imported from boykopovar/AnyPS5. Originally posted by ee6aba54 on 2026-10-15T11:20:45Z.
Thanks, the reproduction is right. A late CPU store of the value the keys already held is indistinguishable from no store at all to the value compare. That case matters: zeroing reused memory that was already zero is exactly how a freed metadata block gets taken over. So preservation has to include it.
Pushed eb65a6577, which adds write provenance on top of the value compare:
QueueKeyStorecollects the guest writes of the fill range (GuestMemory::CollectWritesUncached) right before it takes the snapshot, and keeps that generation with the store.ChangedBlocks, not the driver's ownMarkWrittenstamps) is left as the CPU left it. The kernel only runs over the other blocks, which keeps a store whatever value it wrote.[labels]line counts the key blocks left to a later CPU store.agc_guarded_key_storenow places the keys across a block boundary. Your same-value case is part of it: a late store of0umust survive, and the keys of the other block must still be stored. With the provenance check disabled, the test fails. On Linux with an RTX 5080,agc_guarded_key_storeandagc_changed_copypass five runs each, andctest -R agc_passes.Limits:
In PPSA15304, two runs on top of current main (about 160,000 guarded key stores in the longer one) left no key block to a later CPU store, and neither run had a fault. So in that section the new check never changes what is stored, and it closes the same-value case for titles that do reuse such memory.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-20T20:24:52Z.
Thanks for the rebase and the clear answers on #6185. One problem in the guarded key store's target address, the same
leadpoint #6185 just fixed for the copy source:StoreUncompressedOnGpupassestarget = import->address + first, wherefirst = HostImportOffset(*import, begin) = begin - base + leadis an offset into the import's buffer. Butimport->addressis already the device address ofbase, i.e. buffer start +lead(entry.address = address + leadin the sparse import). So whenever an import has a lead, the target isleadbytes past the keys. The kernel then compares and stores0xffup toleadbytes beyond the key range, into whatever guest memory follows, wherever that memory equals the snapshot's dword (zeros are common). The real keys aren't stored.The fix is the helper from #6185:
HostImportBufferStart(*import).device + first(orimport->address - import->lead + first).agc_guarded_key_storebuilds its buffer offset askeysAddress - import->base, which assumes no lead, so it can't see this. A case with a lead (like the 0x1000-byte lead case you added toagc_changed_copy) would pin it. Leads only come from sparse dma-buf imports, so neither an NVIDIA proprietary driver nor a machine without udmabuf access reaches this path, which is probably why your runs didn't show it.A smaller design point, for the description rather than code: after
960c01ac9, a 64 KiB block the CPU wrote after the queue keeps every byte as the CPU left it, so key dwords in that block the CPU did not write never get0xff. That trades Amoenus's same-value case for stale keys around any single CPU store in a key block. If that's intended, please say so in the description and the debt entry.Imported from boykopovar/AnyPS5. Originally posted by ee6aba54 on 2026-10-21T23:01:08Z.
@oneandonlydean Thanks, that was a real error.
StoreUncompressedOnGpunow passesHostImportDeviceAddress(*import, begin), which isHostImportBufferStart(*import).device + HostImportOffset(*import, begin), so theleadis counted once.agc_guarded_key_storefills its keys atHostImportOffset(*import, keysAddress)instead ofkeysAddress - import->base, and checksHostImportDeviceAddressfor an import with a 0x1000-byte lead (the keys' address, notleadbytes past it) and for its own import. The kernel itself does not run against an import with a lead here: those only come from sparse dma-buf imports, which this machine does not reach (/dev/udmabufis not accessible to the test user).docs/dev/debt/libSceAgcDriver.mdsay so.Both branches are merged with
maina6dcea927(keeping your merge into #6185).Tested on Linux, Release,
ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, same machine and GPU:maina6dcea927agc_changed_copy,agc_guarded_key_storemain)agc_recorder_read_list,agc_host_import_unmap,agc_parked_import_unmap,agc_host_import_retirement,agc_sparse_run_import,agc_sparse_run_import_copied,agc_draw_inputs_in_place,agc_draw_inputs_copied,agc_unit_shadow,agc_idle_publish_wait,agc_driver_graphicsVUID-linesAll 868
agctests on the #6186 head pass exceptagc_driver_sample_order,agc_driver_sample_order_grid_referenceandagc_driver_sample_order_recipe_depth_locations, which fail the same way onmaina6dcea927on this machine.check_conventions.pypasses on both branches.Ubuntu 24.04, kernel 7.0.0, NVIDIA GeForce RTX 5080, driver 595.99.02.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-22T01:30:23Z.
@ee6aba54 thanks for the lead fix, that part checks out. The full CI run on
d8c1459821failsagc_guarded_key_storeon Linux (llvmpipe) with "a guarded key store wrote into a block the CPU wrote after it was recorded". I think it's the test's expectation, not the store path.On that runner the import probe prints
host imports resolve write protection: yes ... imported ranges are compared, so host imports are compared rather than write-watched. ThenCpuWrittenBlockscan't report the CPU store atkeys + 400, the block isn't left to the CPU, and the guarded compare stores 0xff into the bytes that still equal the snapshot. That's the documented fallback. But the test decides its expectation fromGuestMemory::WriteWatched()alone, which is still true there, so it expects 0x00.I reproduced it on an NVIDIA host by forcing that mode. Your head passes by default (imports stay watched) and fails with
APS5_WRITE_WATCH_IMPORTS=unwatchwith the same message. Changing the test's flag tomakes it pass both ways, and the guarded-store checks (
late == 0x12345678, the guarded count) still run in compare mode.Could you make that change, or something equivalent that keys the block expectation on whether this import is actually watched? It may also be worth a line in the debt entry: on hosts that compare imports, the block rule doesn't apply, so a CPU store of the same value inside a key block can still be overwritten.
Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-22T11:52:27Z.
@ee6aba54 a merge-order note: #7446 and this PR both extend the
[labels]profile line inPacketFlush.cpp. #7446 adds a count of packets redone for captured memory that changed before recording, and this PR adds the guarded DCC key stores and the key blocks left to a later CPU store. That's the only conflict, and composed, the line prints both. #7446 goes after this PR and rebases over it.Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-11-01T19:59:02Z.
Review: COMMENTED
1. Carried commits. This PR targets
mainand lists "Depends on: #6185", but its history contains the whole of #6185 (the changed-copy kernel,StagingCopyBack.comp,WriteChangedKeepingGuest, the copy-back switches docs and tests) plus the key-store commits and several merge commits between the two branches. A reviewer cannot tell from the diff which part is this fix; the key-store guard (Recorder::QueueKeyStoretarget,NotePendingWriteswithShadowPublishWrite, the snapshot of known fills, and the 64 KiB CPU-written block exemption) is only a fraction of it. Please rebase onto #6185 once it merges, or state a base so the diff shows only the guard.2. The behavior is a heuristic over what the CPU wrote. Per the description, a 64 KiB block the CPU wrote since the record is "left as the CPU left it", so key dwords in that block the CPU did not write keep their old value instead of 0xff; and with no write watching "the value compare stays the only guard", which by the text cannot tell a late CPU store of the old value from no store. These are stated as limits, but the consequence (stale DCC keys read as compressed after a metadata block is reused) is not covered by a test:
agc_guarded_key_storechecks that CPU stores survive and untouched blocks are stored, not what a later reader sees for the exempted block. Is there a case for that, and what does it do on the DCC read side?3. Evidence. The result is one title (PPSA15304) on Linux NVIDIA (two runs of 20 and 25 minutes, "99.6 percent of the key stores guarded"), compared to a run with #6185 alone that faulted after 10 to 11 minutes, no pair with
tools/trace_digest.pysummaries ofmainand this change, and no validation-layer run. The copy kernel and itskeepGuestbranch inwriteChangedrun on every changed-copy write-back, so a cost comparison on the same scene is relevant. Please attach the digest formainand this head, and runagc_guarded_key_storeandagc_changed_copyon both withANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, showing no newVUID-lines.Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-03T07:16:52Z.
Review: APPROVED
Reviewed — approved
The guarded DCC key store and the host-copied
WriteChangedKeepingGuestwrite-back behave as described: the new tests pass and fail when the production change is reverted, and there are no validation errors on lavapipe. One small non-blocking gap is noted below.What I ran
Head
9a00b0c8168d67cdb62cd6e90e209f744e2c34ed,maind1ae628bc2f62459cce1e9872ba5632c938c71f2, merged with--no-ffin a clean worktree. Debian 13 VM, 2× Xeon Gold 6136 (AVX2/FMA), GCC 14.2.0, Release, Vulkan through lavapipe (Mesa 26.1.6, LLVM 19), no GPU, no/dev/udmabuf.Results
git diff --checkcheck_conventions.pylibs(script)mainVUID-linesagc_guarded_key_store,agc_changed_copy,agc_copied_write_back,agc_bda_staging,agc_driver_pm4agc_unit_shadowagc_guarded_key_storewithAPS5_NO_GUARDED_KEY_STORE=1agc_guarded_key_storewithAPS5_WRITE_WATCH_IMPORTS=watchVK_LAYER_KHRONOS_validationVUID-lines, no "was not found but was requested"Default mode on this host (imports compared)
In this mode only the value compare runs. The block rule and the same-value case run only with the forced-watch run above.
Forced watch mode
Negative control
I restored
Graphics/src/DccMetadata.cpp(no kernel target passed toQueueKeyStore) andGraphics/src/GuestBufferMemory.cpp(noWriteChangedKeepingGuestand no changed copy-back) frommain, then rebuiltagc_driver_recorder_tests:agc_changed_copydrivesRecorder::RecordChangedCopydirectly, so reverting these two files does not affect it. That is expected. After restoring the merged files and rebuilding,git status --porcelainwas empty.Findings
Blocking
None.
Non-blocking
Recorder::recordKeyStores(core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp:1812), the seed copies of the unaligned head and tail (up to 3 bytes each, 0xff from the seed made inDccMetadata.cpp:242) are recorded for every store. This happens whether the store is guarded or not, and whether the block holding those bytes is left to the CPU. A late CPU store into those bytes is overwritten. The new debt entry (docs/dev/debt/libSceAgcDriver.md:352) says a CPU-written block "is left exactly as the CPU left it", which does not hold for those bytes. The exposure is small: key ranges are normally dword-aligned, and the block skip already covers everything else. Suggested fix: skip the edge copy when its block is incpuWritten, or add one clause to the debt entry saying the unaligned head and tail are always stored.The point CnRJay raised still applies, and I have no new evidence on it: the diff still carries all of #6185 (
StagingCopyBack.comp,WriteChangedKeepingGuest, the changed copy-back). This review covers the combined diff. The author has already agreed the landing order (#8887 → #12070 → this PR).Not verified
APS5_WRITE_WATCH_IMPORTS=watch.lead(sparse dma-buf) was not reached because there is no/dev/udmabuf. Only the address arithmetic was checked, through the test'sHostImportDeviceAddressassertions.PATHregistration for the new tests.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-23T03:03:09Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this; the points below are optional.
What I ran
Reviewed head
9a00b0c8168d67cdb62cd6e90e209f744e2c34edand its prepared diff. No build or tests were run; no merged-preview check was performed.Results
ctest -R agc_passedFindings
Blocking
None.
Non-blocking
None.
Not verified
The full text for
core/libs/prx/libSceAgcDriver/tests/Recorder.cppwas excluded because it was too large for the review folder; the diff and relevant test hunks were read. Other changed files in the manifest were read through the prepared diff or their included head text. No build, test suite, or console run was performed here. The author-reported test and console results were not independently verified.To get this to a good state
Nothing is required.
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.