Skip to content

fix(agc): keep CPU stores made after a deferred DCC key store was recorded - #43

Open
Thimo188 wants to merge 18 commits into
mainfrom
upstream-pr/6186
Open

Thimo188 wants to merge 18 commits into
mainfrom
upstream-pr/6186

Conversation

@Thimo188

@Thimo188 Thimo188 commented Dec 2, 2026

Copy link
Copy Markdown
Owner

Imported from boykopovar/AnyPS5#6186, originally opened by ee6aba54.

Source commit: 9a00b0c8168d67cdb62cd6e90e209f744e2c34ed. The import branch preserves this fetched upstream PR snapshot. The description and validation below are copied from upstream; no new code changes or test runs were made for this import. Original reviews, discussions, and attachments remain at the linked upstream PR.


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:

[videoout] presentation failed: compute shader 0x1641a9c200: buffer descriptor uses an unsupported type

The change:

  • The queued key store takes a snapshot of the key bytes at record time and the batch stores the 0xff pattern through the changed-copy kernel of fix(agc): copy only the dwords a shader changed back from a GPU-copied buffer boykopovar/AnyPS5#6185: a dword is stored only where the import still holds the snapshot's value, so a CPU store made after the record keeps the CPU's value. A range whose pending writers are only earlier 0xff fills of the same keys stays guarded; a pending kernel of the title writing the keys, or a range without a device address or a snapshot, is filled as before. APS5_NO_GUARDED_KEY_STORE=1 restores the fills, and the [labels] line counts the guarded stores.
  • A unit shadow publish notes its pending write with its own value, so the key store queued right behind the publish of the key range's edge units stays guarded (the publish leaves the key bytes as they are).
  • The snapshot predicts the import: a title's key clear is a recorded fill of a known value, and after perf(agc): read DCC keys from the pending GPU fills that cover them instead of waiting for the fills boykopovar/AnyPS5#5520 a third of the key stores in PPSA15304 had such a fill pending. The pending fills of known value are applied to the snapshot in note order, so the kernel stores over the clear's bytes and still keeps a later CPU store. APS5_TRACE_KEY_GUARD=1 prints the pending writers of the stores that stay unguarded.
  • The value compare cannot tell a late CPU store of the value the keys already held from no store. The queued store therefore collects the guest writes of its range before the snapshot, and when it is recorded, every 64 KiB block the CPU wrote since then is left as the CPU left it. The [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 in docs/dev/debt/libSceAgcDriver.md.
  • The kernel's target is the device address of the keys in their import, taken from the start of the import's buffer (HostImportDeviceAddress, built on fix(agc): copy only the dwords a shader changed back from a GPU-copied buffer boykopovar/AnyPS5#6185's HostImportBufferStart), 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. boykopovar#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 current main with boykopovar#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's APS5_STORE_AT_LABEL=1 did not prevent the fault in the same section.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw; no silent stubs added
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source (none added)
  • Generic behaviour, not specific to one title
  • Depends on: fix(agc): copy only the dwords a shader changed back from a GPU-copied buffer boykopovar/AnyPS5#6185
  • Fixes: none
  • Unblocks: PPSA15304 (no Game bring-up discussion yet)
  • GPUs tested: NVIDIA GeForce RTX 5080, driver 595.99.02, Ubuntu 24.04 (Linux)
  • AI-assisted: yes

ee6aba54 and others added 18 commits October 20, 2026 21:58
…was recorded

The "uncompressed" key store recorded behind a storage write-back filled the
keys' host import whenever the GPU reached it. A title that had released the
metadata block by then and reused it (a descriptor table, for one) got the fill
pattern over its own bytes; the next dispatch built from such a V# failed in
the recompiler with an unsupported format or type.

The queued key store now takes a snapshot of the key bytes at record time and
the batch stores the 0xff pattern through the changed-copy kernel, so a dword
the CPU wrote after the record keeps the CPU's value. A range whose only
pending writers are earlier 0xff fills of the same keys stays guarded (the
kernel need not repeat them); a pending kernel of the title writing the keys,
or a range without a device address or a snapshot, is filled as before. The
[labels] line counts the guarded stores; APS5_NO_GUARDED_KEY_STORE=1 restores
the fills.
…hat precedes it

The publish of the key range's edge units notes a pending write over the keys,
which made the key store queued right after it fall back to the plain fill.
The publish leaves the key bytes as they are (its slab holds the seed the
import had), so the store's snapshot stays exact: publishes note their writes
with their own value and the key store treats them like its own fills.

(cherry picked from commit a3c8286502a94b13d2fb7676a76c82e87f677d76)
…ded before it

A title's DCC key clear is a recorded fill of a known value over the keys. The
key store queued behind it saw a pending writer it did not know and fell back
to the plain fill, which was a third of the stores in PPSA15304 after boykopovar#5520
and brought the descriptor faults back.

The snapshot now predicts the import: the bytes read at queue time with every
pending fill of a known value applied in note order, so the kernel stores the
0xff pattern over the clear's bytes and still keeps a CPU store made after the
record. APS5_TRACE_KEY_GUARD=1 prints the pending writers of the stores that
stay unguarded. The test records a key clear before the store and expects the
keys stored, then a late CPU store kept.

(cherry picked from commit 3da4934731c9231976f395b8f517bd2b03578968)
…to the CPU

The guarded key store stored the 0xff pattern wherever the import still
held the snapshot's value, so a CPU store of the value the keys already
held (zeroing reused memory that was zero) read as untouched and was
overwritten.

The queued store now collects the guest writes of its range before taking
the snapshot and keeps that generation. When the store is recorded, every
64 KiB block of the range the CPU wrote since then is left as the CPU left
it, and the kernel only runs over the other blocks, so a store is kept
whatever value it wrote. Without write watching the value compare stays
the only guard. The [labels] line counts the key blocks left to the CPU.
The test places the keys across a block boundary and adds a late store of
the value the keys held.
# Conflicts:
#	core/libs/prx/libSceAgcDriver/CMakeLists.txt
#	core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
#	docs/dev/ENVIRONMENT.md
…the import is write-watched

On hosts that compare host imports instead of watching them, the guarded
key store cannot see which blocks the CPU wrote, so the value compare is
the only guard there. Key the block expectation on the import's watch
mode and note that case in the debt entry.
…pped

guardedKeyStoreTests returned without a check when host imports or buffer
device addresses were unavailable or the host import of its block was refused,
and --guarded-key-store-only returned 0 all the same, so ctest reported
agc_guarded_key_store as passed with nothing tested. The function now returns
whether a case ran, the standalone entry returns 77 when none did (ctest's
SKIP_RETURN_CODE for this test), and the full suite goes on as before. A run
whose import is not write-watched still counts as run: its first cases
complete, only the same-value late store is left out.
# Conflicts:
#	core/libs/prx/libSceAgcDriver/CMakeLists.txt
#	docs/dev/debt/libSceAgcDriver.md
# Conflicts:
#	core/libs/prx/libSceAgcDriver/CMakeLists.txt
# Conflicts:
#	core/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketFlush.cpp
#	core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
#	core/libs/prx/libSceAgcDriver/tests/cmake/agc_driver_recorder_tests.cmake
#	docs/dev/debt/libSceAgcDriver.md
@Thimo188 Thimo188 closed this Dec 2, 2026
@Thimo188 Thimo188 reopened this Dec 2, 2026
@github-actions github-actions Bot added needs rebase Conflicts with main, rebase needed unblocks title Names a title ID on the Unblocks line labels Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs rebase Conflicts with main, rebase needed unblocks title Names a title ID on the Unblocks line

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants