fix(agc): read the DCC keys of sampled textures after the GPU writes recorded before them #4699

Closed
Nesyth wants to merge 1 commit from upstream-pr/4699 into main
Nesyth commented 2026-10-12 19:13:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Nesyth on 2026-10-12T19:13:32Z.


What

A sampled texture's DCC keys were read straight from guest memory. That read is textureClearKeys, which sits behind TextureClearKeys, ProvedClearKeys and the sampled path of cachedTexture. Recorded work that has not run yet can still write those keys: a title's clear or decompress kernel, or a copy or fill over the key range. A texture sampled later in the same batch then decided its content (clear-code fill or "read as stored") from the keys as they were before that work.

  • textureClearKeys now reads the keys through currentDccKeys, as render targets already do through CurrentDccKeys. Under the GPU lock, a key range with a recorded writer is answered in one of two ways:
    • if the driver made that store itself, from the pending store's keys (PendingStoreKeys);
    • otherwise, the read first waits for the writer (Recorder::SyncThrough).
  • Without the GPU lock, or with no recorded writer over the range, the keys are read as before.
  • A sampled texture over keys that recorded work writes can therefore now wait for that work under the GPU lock, where it used to read the memory at once.
  • Test: pendingKeyStoreTests records a vkCmdFillBuffer that writes 0001 clear keys (0x40) over a texture's key range, and notes it as a pending write. TextureClearKeys must then answer Clear0001 and leave no pending writer. On main it answers Clear0000 from the stale bytes ("a sampled texture read its DCC keys before the recorded GPU write over them landed").
  • pendingKeyStoreTests had no ctest entry, so it now runs alone as agc_pending_key_stores (--pending-key-stores-only), like the other recorder tests.

Related: #1359 (open) makes direct consumers wait for copied writes whose CPU write-back has not happened yet, DCC metadata included. This PR covers keys that recorded GPU work writes in place, which #1359 does not wait for. The two change different functions.

Overlaps with my other open PR; whichever merges second rebases:

  • #4700 edits the line next to this one in textureClearKeys.

Tested

Windows 11 Pro 10.0.22631, AMD Ryzen 7 7800X3D, AMD Radeon RX 7900 XTX, WinLibs GCC 15.2.0, Release, BUILD_TESTING=ON, on main ffa198407. The branch was rebased onto main d53960612 for this pull request and is not yet rebuilt or re-tested there:

  • ctest: 952/952 passed: main's 951 (8 of them skip there too) plus the new agc_pending_key_stores.
  • With DccMetadata.cpp as on main, agc_pending_key_stores fails with the message above.
  • tools/check_conventions.py --base origin/main passes.
  • Ready or Not (PPSA18605), from boot to the station: the [gpu] texture ... has mixed DCC keys ...; its texels are read as stored reports went from 11 and 14 (two runs without this change) to 2 in each of three runs with it. The 6 reported before the level load are gone.
  • The two textures left are 2612x1472 RGBA8 (format 56) surfaces whose key bytes are mixed in guest memory. They are an open lead for the colour corruption reported in #4184.
  • That was measured on an earlier state of the bring-up build: main bab7b3285 plus #4021, #4057, #1077, #425, #454, #4031, #2254 and local changes, before #3864, #3865, #4012, #4248 and #1359 were added. It was not measured on this branch alone.

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 (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4833915535 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4699). Originally posted by [Nesyth](https://github.com/Nesyth) on 2026-10-12T19:13:32Z. --- ### What A sampled texture's DCC keys were read straight from guest memory. That read is `textureClearKeys`, which sits behind `TextureClearKeys`, `ProvedClearKeys` and the sampled path of `cachedTexture`. Recorded work that has not run yet can still write those keys: a title's clear or decompress kernel, or a copy or fill over the key range. A texture sampled later in the same batch then decided its content (clear-code fill or "read as stored") from the keys as they were before that work. - `textureClearKeys` now reads the keys through `currentDccKeys`, as render targets already do through `CurrentDccKeys`. Under the GPU lock, a key range with a recorded writer is answered in one of two ways: - if the driver made that store itself, from the pending store's keys (`PendingStoreKeys`); - otherwise, the read first waits for the writer (`Recorder::SyncThrough`). - Without the GPU lock, or with no recorded writer over the range, the keys are read as before. - A sampled texture over keys that recorded work writes can therefore now wait for that work under the GPU lock, where it used to read the memory at once. - Test: `pendingKeyStoreTests` records a `vkCmdFillBuffer` that writes 0001 clear keys (0x40) over a texture's key range, and notes it as a pending write. `TextureClearKeys` must then answer `Clear0001` and leave no pending writer. On `main` it answers `Clear0000` from the stale bytes ("a sampled texture read its DCC keys before the recorded GPU write over them landed"). - `pendingKeyStoreTests` had no ctest entry, so it now runs alone as `agc_pending_key_stores` (`--pending-key-stores-only`), like the other recorder tests. Related: #1359 (open) makes direct consumers wait for copied writes whose CPU write-back has not happened yet, DCC metadata included. This PR covers keys that recorded GPU work writes in place, which #1359 does not wait for. The two change different functions. Overlaps with my other open PR; whichever merges second rebases: - #4700 edits the line next to this one in `textureClearKeys`. ### Tested Windows 11 Pro 10.0.22631, AMD Ryzen 7 7800X3D, AMD Radeon RX 7900 XTX, WinLibs GCC 15.2.0, Release, `BUILD_TESTING=ON`, on `main` ffa198407. The branch was rebased onto `main` d53960612 for this pull request and is not yet rebuilt or re-tested there: - `ctest`: 952/952 passed: `main`'s 951 (8 of them skip there too) plus the new `agc_pending_key_stores`. - With `DccMetadata.cpp` as on `main`, `agc_pending_key_stores` fails with the message above. - `tools/check_conventions.py --base origin/main` passes. - Ready or Not (PPSA18605), from boot to the station: the `[gpu] texture ... has mixed DCC keys ...; its texels are read as stored` reports went from 11 and 14 (two runs without this change) to 2 in each of three runs with it. The 6 reported before the level load are gone. - The two textures left are 2612x1472 RGBA8 (format 56) surfaces whose key bytes are mixed in guest memory. They are an open lead for the colour corruption reported in #4184. - That was measured on an earlier state of the bring-up build: `main` bab7b3285 plus #4021, #4057, #1077, #425, #454, #4031, #2254 and local changes, before #3864, #3865, #4012, #4248 and #1359 were added. It was not measured on this branch alone. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: none - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-12 19:29:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-12T19:29:12Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#4017 core/libs/prx/libSceAgcDriver/CMakeLists.txt L899
#4554 core/libs/prx/libSceAgcDriver/Graphics/src/DccMetadata.cpp L451-452
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6131167669 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4699#issuecomment-6131167669). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-12T19:29:12Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #4017 | `core/libs/prx/libSceAgcDriver/CMakeLists.txt` [L899](https://github.com/boykopovar/AnyPS5/blob/6f438a1c2e23dadf4c00284b4e797d02596f949e/core/libs/prx/libSceAgcDriver/CMakeLists.txt#L899) | | | | #4554 | `core/libs/prx/libSceAgcDriver/Graphics/src/DccMetadata.cpp` [L451-452](https://github.com/boykopovar/AnyPS5/blob/6f438a1c2e23dadf4c00284b4e797d02596f949e/core/libs/prx/libSceAgcDriver/Graphics/src/DccMetadata.cpp#L451-L452) | | |
Nesyth commented 2026-10-12 21:03:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Nesyth on 2026-10-12T21:03:51Z.


Closing in favour of #4554, see my comment there.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6132572950 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4699#issuecomment-6132572950). Originally posted by [Nesyth](https://github.com/Nesyth) on 2026-10-12T21:03:51Z. --- Closing in favour of #4554, see my comment there.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!4699
No description provided.