perf(agc): draw cache keys on the user words a program reads, memoizes failures, serves data-only hits #291

Closed
MichonGoddijn231849 wants to merge 5 commits from upstream-pr/291 into main
MichonGoddijn231849 commented 2026-10-01 21:58:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-01T21:58:07Z.


What

Split out of #167. Three changes to the draw cache:

  • Keys on the user words a program reads. The draw key mixes only the user words each stage's RSRC2 counts, so words a program never reads no longer make every draw a miss. APS5_DRAW_KEY_ALL_USER_WORDS=1 mixes all 32.
  • A failure memo. A draw that failed is not decoded and compiled again while the memory it read is unchanged, for at most APS5_DRAW_FAILURE_RETRY_MS (500 ms).
  • Data-only hits. A draw that differs from its shape's newest entry only in user data reuses that entry's decode and the compiled stages whose reads still hold, re-reading only the user words. APS5_NO_DRAW_DATA_HITS=1 disables them, and APS5_VERIFY_DRAW_DATA_HITS=1 compiles and compares instead.

A new key of a shape replaces that shape's previous entry instead of filling the cache with keys that never repeat. The new entry starts without the previous entry's variants: those were compiled under other user words, and a variant validates only the memory it captured, not the user words that pointed there.

That inheritance caused the regression found on #167 (Dreaming Sarah's menu text invisible until clicked). Each text draw took over the previous one's variants and drew with its data.

Tested

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

  • Dreaming Sarah (PPSA02929), title menu:
    • With #167's version of this change: no menu text, whether data-only hits, the user-word keys or the failure memo are on or off. With the draw-entry cache off (APS5_NO_DRAW_SRT_ENTRIES=1), the text shows.
    • With this version: the menu text shows with every part on.
  • GTA V (PPSA04264): the Story Mode world renders with the other parts of #167 on top.
  • ctest: all tests pass.

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
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: #290 (the failure memo records the GPU out-of-memory count it adds)
  • AI-assisted: yes. Written with Claude (Anthropic) under my direction; I reviewed and tested it.

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4710118978 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/291). Originally posted by [MichonGoddijn231849](https://github.com/MichonGoddijn231849) on 2026-10-01T21:58:07Z. --- ### What Split out of #167. Three changes to the draw cache: - **Keys on the user words a program reads.** The draw key mixes only the user words each stage's RSRC2 counts, so words a program never reads no longer make every draw a miss. `APS5_DRAW_KEY_ALL_USER_WORDS=1` mixes all 32. - **A failure memo.** A draw that failed is not decoded and compiled again while the memory it read is unchanged, for at most `APS5_DRAW_FAILURE_RETRY_MS` (500 ms). - **Data-only hits.** A draw that differs from its shape's newest entry only in user data reuses that entry's decode and the compiled stages whose reads still hold, re-reading only the user words. `APS5_NO_DRAW_DATA_HITS=1` disables them, and `APS5_VERIFY_DRAW_DATA_HITS=1` compiles and compares instead. A new key of a shape replaces that shape's previous entry instead of filling the cache with keys that never repeat. The new entry starts without the previous entry's variants: those were compiled under other user words, and a variant validates only the memory it captured, not the user words that pointed there. That inheritance caused the regression found on #167 (Dreaming Sarah's menu text invisible until clicked). Each text draw took over the previous one's variants and drew with its data. ### Tested Windows 11 Pro, AMD Ryzen 5 7600, NVIDIA GeForce RTX 5080 (driver 32.0.16.1074), 32 GB DDR5-5600, MinGW-w64 GCC 15.2.0. - Dreaming Sarah (PPSA02929), title menu: - With #167's version of this change: no menu text, whether data-only hits, the user-word keys or the failure memo are on or off. With the draw-entry cache off (`APS5_NO_DRAW_SRT_ENTRIES=1`), the text shows. - With this version: the menu text shows with every part on. - GTA V (PPSA04264): the Story Mode world renders with the other parts of #167 on top. - `ctest`: all tests pass. ### 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 (`NotImplemented_nid_no_patch`); 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: #290 (the failure memo records the GPU out-of-memory count it adds) - [x] AI-assisted: yes. Written with Claude (Anthropic) under my direction; I reviewed and tested it. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
oneandonlydean commented 2026-10-04 07:09:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T07:09:57Z.


@boykopovar this one needs your call before Michon rebases it: should a draw that failed be skipped on a timer? This PR keeps a failed draw rejected until the memory it read changes or 500 ms pass (APS5_DRAW_FAILURE_RETRY_MS). Failures in the decode step are stored without any memory runs (recordDrawFailure(failureKey, error, memoryFailures, {}, {}) in Draw.cpp), so for those only the clock ends the skip, and which draws get skipped then depends on timing. That is a project policy question more than a plain bug.

It also bundles two other mechanisms (draw keys on the user words a program reads, and data-only hits), and #422, merged today, already memoizes source failures one layer down. My read: I'd take the user-word keys and the data-only hits as separate PRs, and a failure memo only if it ends on memory changes alone. It needs a rebase after #290 and #422 either way.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5977585510 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/291#issuecomment-5977585510). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-04T07:09:57Z. --- @boykopovar this one needs your call before Michon rebases it: should a draw that failed be skipped on a timer? This PR keeps a failed draw rejected until the memory it read changes or 500 ms pass (`APS5_DRAW_FAILURE_RETRY_MS`). Failures in the decode step are stored without any memory runs (`recordDrawFailure(failureKey, error, memoryFailures, {}, {})` in `Draw.cpp`), so for those only the clock ends the skip, and which draws get skipped then depends on timing. That is a project policy question more than a plain bug. It also bundles two other mechanisms (draw keys on the user words a program reads, and data-only hits), and #422, merged today, already memoizes source failures one layer down. My read: I'd take the user-word keys and the data-only hits as separate PRs, and a failure memo only if it ends on memory changes alone. It needs a rebase after #290 and #422 either way.
MichonGoddijn231849 commented 2026-10-04 08:13:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-04T08:13:37Z.


That split makes sense to me, and I'd rather not have a time-based skip in the driver either. My plan, unless @boykopovar prefers otherwise:

  1. A separate PR: draw cache keys on the user words a program reads.
  2. A separate PR: data-only hits.
  3. The failure memo only if it can end on memory changes alone. Decode-step failures carry no memory runs, so for those I'd drop the memo rather than keep the 500 ms timer. With #422 already memoizing source failures, it may not be worth a PR at all; I'll check what's left after rebasing on #290 and #422.

I'll close this one when the split PRs are up.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5978008214 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/291#issuecomment-5978008214). Originally posted by [MichonGoddijn231849](https://github.com/MichonGoddijn231849) on 2026-10-04T08:13:37Z. --- That split makes sense to me, and I'd rather not have a time-based skip in the driver either. My plan, unless @boykopovar prefers otherwise: 1. A separate PR: draw cache keys on the user words a program reads. 2. A separate PR: data-only hits. 3. The failure memo only if it can end on memory changes alone. Decode-step failures carry no memory runs, so for those I'd drop the memo rather than keep the 500 ms timer. With #422 already memoizing source failures, it may not be worth a PR at all; I'll check what's left after rebasing on #290 and #422. I'll close this one when the split PRs are up.
MichonGoddijn231849 commented 2026-10-04 09:11:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-04T09:11:35Z.


Split as discussed: #493 keys draws on the user words each stage reads, and #494 (on top of it) adds the data-only hits. The time-based failure memo is dropped: #422 already memoizes source failures, and a skip that ends on a clock isn't exact. Both are rebased on current main and no longer stack on #290.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5978404955 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/291#issuecomment-5978404955). Originally posted by [MichonGoddijn231849](https://github.com/MichonGoddijn231849) on 2026-10-04T09:11:35Z. --- Split as discussed: #493 keys draws on the user words each stage reads, and #494 (on top of it) adds the data-only hits. The time-based failure memo is dropped: #422 already memoizes source failures, and a skip that ends on a clock isn't exact. Both are rebased on current `main` and no longer stack on #290.

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!291
No description provided.