fix(agc): make DCC key fills clear what reads through the surface's keys #163

Merged
MichonGoddijn231849 merged 1 commit from upstream-pr/163 into main 2026-10-01 07:50:04 +00:00
MichonGoddijn231849 commented 2026-09-29 21:42:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-09-29T21:42:40Z.


What

  • A buffer fill that starts at a surface's DCC keys and covers at least its key range counts as a key fill. Titles fill the padding too: GTA V fills 0x6000 bytes for 0x3c00 keys, and the exact-size check classified that as covering nothing.
  • A uniform key fill leaves the image's texels and pending results in place, and records the fill's code:
    • a sampled read through the surface's keys binds the clear value;
    • a color target through the keys starts from the clear value at its next refresh;
    • reads that bypass the keys (a view without the DCC address, a copy) still see the texels.
  • Key scans return the fill's code until its GPU write lands, and a write-back of results drawn before the fill keeps the keys holding that code.
  • The immediate clear of the covered images is opt-in (APS5_KEYS_FILL_CLEAR=1). It fixes titles whose sampled reads reach the pending image before a refresh, but it breaks reads that bypass the keys. @oneandonlydean found that with Astro Bot's title logo. Thanks!

In GTA V the per-frame clear of the bloom buffer was missed, and the bloom fed back into the lighting until the frame turned white. GTA V currently still needs APS5_KEYS_FILL_CLEAR=1 for a stable frame: with the per-read path alone, the frame still pulses. That remaining gap is a follow-up.

Tested

Windows 11 Pro, AMD Ryzen 5 7600 (6-core), NVIDIA GeForce RTX 5080 (driver 32.0.16.1074), 32 GB DDR5-5600, MinGW-w64 GCC 15.2.0.

  • GTA V (PPSA04264): with APS5_KEYS_FILL_CLEAR=1 the frame stays stable; without it, it no longer fades fully white but still pulses.
  • The recorder test for this path is not included: it builds on test helpers that main does not have yet.

Overlaps

  • #177 changes the line before this PR's check in cachedTexture (ShaderResources.cpp, around L290). The two are compatible: #177 drops a pending image whose DCC address moved, and this PR then checks the keys filled over the image that is left. Whichever lands second keeps both; I'll update this one if #177 goes first.

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; silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes. Written with Claude (Anthropic) under my direction; I reviewed and tested it.
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4682958068 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/163). Originally posted by [MichonGoddijn231849](https://github.com/MichonGoddijn231849) on 2026-09-29T21:42:40Z. --- ### What - A buffer fill that starts at a surface's DCC keys and covers at least its key range counts as a key fill. Titles fill the padding too: GTA V fills 0x6000 bytes for 0x3c00 keys, and the exact-size check classified that as covering nothing. - A uniform key fill leaves the image's texels and pending results in place, and records the fill's code: - a sampled read **through the surface's keys** binds the clear value; - a color target through the keys starts from the clear value at its next refresh; - reads that **bypass the keys** (a view without the DCC address, a copy) still see the texels. - Key scans return the fill's code until its GPU write lands, and a write-back of results drawn before the fill keeps the keys holding that code. - The immediate clear of the covered images is **opt-in** (`APS5_KEYS_FILL_CLEAR=1`). It fixes titles whose sampled reads reach the pending image before a refresh, but it breaks reads that bypass the keys. @oneandonlydean found that with Astro Bot's title logo. Thanks! In GTA V the per-frame clear of the bloom buffer was missed, and the bloom fed back into the lighting until the frame turned white. GTA V currently still needs `APS5_KEYS_FILL_CLEAR=1` for a stable frame: with the per-read path alone, the frame still pulses. That remaining gap is a follow-up. ### Tested Windows 11 Pro, AMD Ryzen 5 7600 (6-core), NVIDIA GeForce RTX 5080 (driver 32.0.16.1074), 32 GB DDR5-5600, MinGW-w64 GCC 15.2.0. - GTA V (PPSA04264): with `APS5_KEYS_FILL_CLEAR=1` the frame stays stable; without it, it no longer fades fully white but still pulses. - The recorder test for this path is not included: it builds on test helpers that `main` does not have yet. ### Overlaps - #177 changes the line before this PR's check in `cachedTexture` (`ShaderResources.cpp`, around L290). The two are compatible: #177 drops a pending image whose DCC address moved, and this PR then checks the keys filled over the image that is left. Whichever lands second keeps both; I'll update this one if #177 goes first. ### Checklist - [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 - [x] Unimplemented paths throw; silent stubs are listed in TechnicalDebt - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes. Written with Claude (Anthropic) under my direction; I reviewed and tested it.
MichonGoddijn231849 commented 2026-09-30 11:47:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-09-30T11:47:48Z.


@oneandonlydean thanks for testing this on Astro Bot and for the analysis in 32ee4c2. You're right: a key fill only changes the metadata, so reads that bypass the keys must keep the texels. I've reworked the PR along those lines:

  • The fill no longer touches the image or its pending results; reads through the keys see the clear value, and reads without them see the texels.
  • Write-backs of results drawn before the fill no longer reset the keys.
  • The destructive immediate clear is opt-in (APS5_KEYS_FILL_CLEAR=1), as in your commit.

GTA V still needs that switch for a stable frame for now; the remaining gap on the per-read path is a follow-up.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5910561705 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/163#issuecomment-5910561705). Originally posted by [MichonGoddijn231849](https://github.com/MichonGoddijn231849) on 2026-09-30T11:47:48Z. --- @oneandonlydean thanks for testing this on Astro Bot and for the analysis in 32ee4c2. You're right: a key fill only changes the metadata, so reads that bypass the keys must keep the texels. I've reworked the PR along those lines: - The fill no longer touches the image or its pending results; reads through the keys see the clear value, and reads without them see the texels. - Write-backs of results drawn before the fill no longer reset the keys. - The destructive immediate clear is opt-in (APS5_KEYS_FILL_CLEAR=1), as in your commit. GTA V still needs that switch for a stable frame for now; the remaining gap on the per-read path is a follow-up.
boykopovar commented 2026-09-30 17:47:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by boykopovar on 2026-09-30T17:47:09Z.


As I understand it, at the moment APS5_KEYS_FILL_CLEAR=0 also enables bypass?

std::getenv("APS5_KEYS_FILL_CLEAR") != nullptr
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5916613908 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/163#issuecomment-5916613908). Originally posted by [boykopovar](https://github.com/boykopovar) on 2026-09-30T17:47:09Z. --- As I understand it, at the moment APS5_KEYS_FILL_CLEAR=0 also enables bypass? ``` std::getenv("APS5_KEYS_FILL_CLEAR") != nullptr ```
MichonGoddijn231849 commented 2026-09-30 19:58:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-09-30T19:58:02Z.


Good catch, yes: it only checked that the variable exists, so any value (including 0) turned the immediate clear on. It now turns on only with APS5_KEYS_FILL_CLEAR=1; every other value, or no variable, leaves it off. I also rebased onto current main, where the one conflict was the new MetadataMoved check in cachedTexture; both are kept.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5918631787 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/163#issuecomment-5918631787). Originally posted by [MichonGoddijn231849](https://github.com/MichonGoddijn231849) on 2026-09-30T19:58:02Z. --- Good catch, yes: it only checked that the variable exists, so any value (including 0) turned the immediate clear on. It now turns on only with `APS5_KEYS_FILL_CLEAR=1`; every other value, or no variable, leaves it off. I also rebased onto current main, where the one conflict was the new `MetadataMoved` check in `cachedTexture`; both are kept.
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!163
No description provided.