fix(agc): patch a relocated hit's decode when the finisher restarts it #19267

Merged
chitters2004 merged 6 commits from upstream-pr/19267 into main 2026-11-16 21:16:57 +00:00
chitters2004 commented 2026-11-13 01:03:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by chitters2004 on 2026-11-13T01:03:18Z.


What

Follow-up to #15455, which merged before these review commits reached it.

The bug (on main since #15455, with APS5_DRAW_PIPELINE=1). A draw served from another draw's cache entry through an alias keeps the donor's unpatched decode, because draw() patches it only on a miss. When the finisher restarts such a draw after its captured memory changed, the restart clears drawHit and caches that decode under the draw's own key. A later draw relocated from that entry then shifts the captured runs by the distance from the donor's user word instead of its own, so it misses the cache. The output is still correct, but each of those draws pays for a full miss. Now the user patches live in the draw's tail, and the restart applies them to a copy of the decode when the worker hit. With APS5_VERIFY_DRAW_RECIPE on, resolveDrawDecode already rebuilds the decode from the guest registers, so the restart copy is skipped there and counted (restartPatchSkipped).

Commits

  • 19c30f8ac9 test: registers #15455's finisher-restart tests under the pipeline environment, so the restart path runs in CI.
  • 24944c04ba fix, plus a check in DrawCacheRelocation.cpp: it restarts a relocated stage-data hit on the finisher, then requires a draw through a second moved table to be a relocated hit.
  • 032adc92c4 test: requires the finisher recapture only when draws are pipelined, so the inline run of the same test stays valid.
  • 3891c1e048 review: <atomic> include order; _skip_refused_draw_pipeline moved into the WIN32 libc PATH block.
  • ff4096498b review: skip the restart copy under APS5_VERIFY_DRAW_RECIPE; new agc_driver_draw_cache_relocation_recipe_verify_draw_pipeline asserts exactly one skip.

Tested

Fork CI, lavapipe, validation layer on:

tree Linux Windows
main a445e0f0f7 + this PR (032adc92c4) 9/9, 0 VUID- 9/9, 0 VUID-
main + the tests without the fix (ab1cacbdd8) 7/9: draw_cache_relocation_draw_pipeline and draw_cache_relocation_plan_verify fail same 2 fail
head ff4096498b (run 43349134560) all pass all pass
head with the restart patch removed (run 43349147825) relocation draw_pipeline and plan_verify fail; recipe_verify_draw_pipeline fails (skip count 0, expected 1) same

Independent runs: @tablefrogpillow on three AMD generations under Linux (Vega, RDNA2, RDNA3), and @JJenkx on Windows 11 with an RX 6700 XT (10 covered tests, 3 of 3 runs, 30/30 on 032adc92c4).

python -I tools/check_conventions.py passes.

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 under Silent stubs in their library's technical debt file
  • 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
  • Fixes: none
  • Unblocks: none
  • GPUs tested: lavapipe (fork CI, Linux and Windows); AMD Vega, RDNA2, RDNA3 on Linux (tablefrogpillow); AMD RX 6700 XT on Windows 11 (JJenkx)
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5288051435 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19267). Originally posted by [chitters2004](https://github.com/chitters2004) on 2026-11-13T01:03:18Z. --- ### What Follow-up to #15455, which merged before these review commits reached it. **The bug (on `main` since #15455, with `APS5_DRAW_PIPELINE=1`).** A draw served from another draw's cache entry through an alias keeps the donor's unpatched decode, because `draw()` patches it only on a miss. When the finisher restarts such a draw after its captured memory changed, the restart clears `drawHit` and caches that decode under the draw's own key. A later draw relocated from that entry then shifts the captured runs by the distance from the donor's user word instead of its own, so it misses the cache. The output is still correct, but each of those draws pays for a full miss. Now the user patches live in the draw's tail, and the restart applies them to a copy of the decode when the worker hit. With `APS5_VERIFY_DRAW_RECIPE` on, `resolveDrawDecode` already rebuilds the decode from the guest registers, so the restart copy is skipped there and counted (`restartPatchSkipped`). **Commits** - `19c30f8ac9` test: registers #15455's finisher-restart tests under the pipeline environment, so the restart path runs in CI. - `24944c04ba` fix, plus a check in `DrawCacheRelocation.cpp`: it restarts a relocated stage-data hit on the finisher, then requires a draw through a second moved table to be a relocated hit. - `032adc92c4` test: requires the finisher recapture only when draws are pipelined, so the inline run of the same test stays valid. - `3891c1e048` review: `<atomic>` include order; `_skip_refused_draw_pipeline` moved into the WIN32 `libc` PATH block. - `ff4096498b` review: skip the restart copy under `APS5_VERIFY_DRAW_RECIPE`; new `agc_driver_draw_cache_relocation_recipe_verify_draw_pipeline` asserts exactly one skip. ### Tested Fork CI, lavapipe, validation layer on: | tree | Linux | Windows | |---|---|---| | `main` `a445e0f0f7` + this PR (`032adc92c4`) | 9/9, 0 `VUID-` | 9/9, 0 `VUID-` | | `main` + the tests without the fix (`ab1cacbdd8`) | 7/9: `draw_cache_relocation_draw_pipeline` and `draw_cache_relocation_plan_verify` fail | same 2 fail | | head `ff4096498b` (run 43349134560) | all pass | all pass | | head with the restart patch removed (run 43349147825) | relocation `draw_pipeline` and `plan_verify` fail; `recipe_verify_draw_pipeline` fails (skip count 0, expected 1) | same | Independent runs: @tablefrogpillow on three AMD generations under Linux (Vega, RDNA2, RDNA3), and @JJenkx on Windows 11 with an RX 6700 XT (10 covered tests, 3 of 3 runs, 30/30 on `032adc92c4`). `python -I tools/check_conventions.py` passes. ### 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 under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [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] Fixes: none - [x] Unblocks: none - [x] GPUs tested: lavapipe (fork CI, Linux and Windows); AMD Vega, RDNA2, RDNA3 on Linux (tablefrogpillow); AMD RX 6700 XT on Windows 11 (JJenkx) - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-11-13 01:22:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-13T01:22:31Z.

Review: COMMENTED


Reviewed the relocated-hit restart fix — no blocking findings

Nothing blocks this; the points below are optional.

What I ran

  • Head: 032adc92c4f8f696196b592e5d168ba0070cf753. Base: main. No merged-preview check.
  • Read-only inspection of the head through repo_read.py, plus the review folder. No build, no test run.
Commands
python3 repo_read.py search userPatches core/libs/prx/libSceAgcDriver
python3 repo_read.py search SetCaptureCheckHook
python3 repo_read.py search OnFinisherThread
python3 repo_read.py search DrawPipeline.hpp core/libs/prx/libSceAgcDriver/tests/execution/DrawRecaptureOnChange.cpp
python3 repo_read.py search "tail.decode" core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw
python3 repo_read.py search DrawTail core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cpp
python3 repo_read.py cat core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cpp 400 530
python3 repo_read.py cat core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cpp 660 720
python3 repo_read.py cat core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cpp 1400 1460
python3 repo_read.py cat core/libs/prx/libSceAgcDriver/tests/execution/DrawCacheRelocation.cpp 350 380
python3 repo_read.py cat core/libs/prx/libSceAgcDriver/tests/cmake/agc_driver_draw_unsupported_buffer_type_tests.cmake 1 16
python3 repo_read.py cat core/libs/prx/libSceAgcDriver/CMakeLists.txt 741 762

Results

Check Result Note
Diff against the description passed Restart patch matches the stated bug
Changed hunks and their context read passed 4 of 4 files, hunks only
Build and unit tests not run No build in this pass
Author's CI table (Linux, Windows) not run Author-reported, not fetched
check_conventions.py not run Author-reported
Negative control (fix removed) not run Author-reported: 7/9 fail

Findings

Blocking

None.

Non-blocking

  1. core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cpp:1436: when verifyDrawRecipe() already passed, the decode was patched at line 512, so this restart copy patches it again. Harmless, one extra copy on the restart path only. Skipping the copy when the patch is already in place would avoid it.
  2. core/libs/prx/libSceAgcDriver/tests/execution/DrawCacheRelocation.cpp:24: <atomic> sits between <cstdint> and <cstdio>, out of alphabetical order with the rest of the include block.
  3. core/libs/prx/libSceAgcDriver/tests/cmake/agc_driver_draw_unsupported_buffer_type_tests.cmake:12: the new _skip_refused_draw_pipeline test is outside the WIN32 block (lines 8–11) that sets the libc PATH for the other two skip-refused tests. The author reports 9/9 on Windows, so it may not be needed. Worth confirming.

The restart patch condition at line 1436 (drawHit) and the miss-path patch at line 688 (!drawHit) are complementary, so a relocated hit's decode is patched on one path or the other.

Sources

Not verified

  • Build, the Linux and Windows test runs, and the 9/9 and 7/9 counts: author-reported, not run here.
  • The negative control (fix removed): not run.
  • Hosted CI for head 032adc92c4f8: not fetched. Approval would need it, so none is given.
  • check_conventions.py: author-reported, not run.
  • Runtime behaviour of the restart copy: read from the code, not executed.
  • Full text of the four files: only the changed hunks and the code they call were read. DrawRecaptureOnChange.cpp was read only at its changed hunk.

To get this to a good state

Nothing is required. The non-blocking points above are optional.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5884667354 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19267#pullrequestreview-5884667354). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-13T01:22:31Z. **Review:** COMMENTED --- # Reviewed the relocated-hit restart fix — no blocking findings Nothing blocks this; the points below are optional. ## What I ran - Head: `032adc92c4f8f696196b592e5d168ba0070cf753`. Base: `main`. No merged-preview check. - Read-only inspection of the head through `repo_read.py`, plus the review folder. No build, no test run. <details> <summary>Commands</summary> ``` python3 repo_read.py search userPatches core/libs/prx/libSceAgcDriver python3 repo_read.py search SetCaptureCheckHook python3 repo_read.py search OnFinisherThread python3 repo_read.py search DrawPipeline.hpp core/libs/prx/libSceAgcDriver/tests/execution/DrawRecaptureOnChange.cpp python3 repo_read.py search "tail.decode" core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw python3 repo_read.py search DrawTail core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cpp python3 repo_read.py cat core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cpp 400 530 python3 repo_read.py cat core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cpp 660 720 python3 repo_read.py cat core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cpp 1400 1460 python3 repo_read.py cat core/libs/prx/libSceAgcDriver/tests/execution/DrawCacheRelocation.cpp 350 380 python3 repo_read.py cat core/libs/prx/libSceAgcDriver/tests/cmake/agc_driver_draw_unsupported_buffer_type_tests.cmake 1 16 python3 repo_read.py cat core/libs/prx/libSceAgcDriver/CMakeLists.txt 741 762 ``` </details> ## Results | Check | Result | Note | |---|---|---| | Diff against the description | passed | Restart patch matches the stated bug | | Changed hunks and their context read | passed | 4 of 4 files, hunks only | | Build and unit tests | not run | No build in this pass | | Author's CI table (Linux, Windows) | not run | Author-reported, not fetched | | `check_conventions.py` | not run | Author-reported | | Negative control (fix removed) | not run | Author-reported: 7/9 fail | ## Findings **Blocking** None. **Non-blocking** 1. `core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cpp:1436`: when `verifyDrawRecipe()` already passed, the decode was patched at line 512, so this restart copy patches it again. Harmless, one extra copy on the restart path only. Skipping the copy when the patch is already in place would avoid it. 2. `core/libs/prx/libSceAgcDriver/tests/execution/DrawCacheRelocation.cpp:24`: `<atomic>` sits between `<cstdint>` and `<cstdio>`, out of alphabetical order with the rest of the include block. 3. `core/libs/prx/libSceAgcDriver/tests/cmake/agc_driver_draw_unsupported_buffer_type_tests.cmake:12`: the new `_skip_refused_draw_pipeline` test is outside the `WIN32` block (lines 8–11) that sets the `libc` PATH for the other two skip-refused tests. The author reports 9/9 on Windows, so it may not be needed. Worth confirming. The restart patch condition at line 1436 (`drawHit`) and the miss-path patch at line 688 (`!drawHit`) are complementary, so a relocated hit's decode is patched on one path or the other. ## Sources - [Draw.cpp, restart patch](https://github.com/boykopovar/AnyPS5/blob/032adc92c4f8f696196b592e5d168ba0070cf753/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cpp#L1436-L1440) - [Draw.cpp, miss-path patch](https://github.com/boykopovar/AnyPS5/blob/032adc92c4f8f696196b592e5d168ba0070cf753/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cpp#L688-L692) - [DrawPipeline.hpp, Depth and OnFinisherThread](https://github.com/boykopovar/AnyPS5/blob/032adc92c4f8f696196b592e5d168ba0070cf753/core/libs/prx/libSceAgcDriver/Execution/include/Driver/Draw/DrawPipeline.hpp#L37) - [Driver.hpp, SetCaptureCheckHook](https://github.com/boykopovar/AnyPS5/blob/032adc92c4f8f696196b592e5d168ba0070cf753/core/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hpp#L131) ## Not verified - Build, the Linux and Windows test runs, and the 9/9 and 7/9 counts: author-reported, not run here. - The negative control (fix removed): not run. - Hosted CI for head `032adc92c4f8`: not fetched. Approval would need it, so none is given. - `check_conventions.py`: author-reported, not run. - Runtime behaviour of the restart copy: read from the code, not executed. - Full text of the four files: only the changed hunks and the code they call were read. `DrawRecaptureOnChange.cpp` was read only at its changed hunk. ## To get this to a good state Nothing is required. The non-blocking points above are optional.
MarcZX10 commented 2026-11-14 05:09:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-14T05:09:28Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change; the review was limited to the changed code and targeted restart path.

What I ran

Reviewed head ff4096498b709e8d271b7bff238fdf3e673f7ed4. No commands or tests were run; no precheck output was supplied as a run performed by me.

Results

Check Result Note
Changed-code review passed Restart patch path inspected
Tests not run Author-reported CI only

Findings

Blocking

None.

Non-blocking

None.

Not verified

I read all six changed files marked reviewed in the manifest and the prepared description, commits, manifest, and diff. files.json was not available through the reader. I inspected the new restart patch logic in Draw.cpp; I did not read the remaining full contents of the changed files or execute tests. CI and hardware results in the description are author-reported, not independently verified.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5901817890 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19267#pullrequestreview-5901817890). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-14T05:09:28Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change; the review was limited to the changed code and targeted restart path. ## What I ran Reviewed head `ff4096498b709e8d271b7bff238fdf3e673f7ed4`. No commands or tests were run; no precheck output was supplied as a run performed by me. ## Results | Check | Result | Note | |---|---|---| | Changed-code review | passed | Restart patch path inspected | | Tests | not run | Author-reported CI only | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified I read all six changed files marked `reviewed` in the manifest and the prepared description, commits, manifest, and diff. `files.json` was not available through the reader. I inspected the new restart patch logic in `Draw.cpp`; I did not read the remaining full contents of the changed files or execute tests. CI and hardware results in the description are author-reported, not independently verified. ## To get this to a good state Nothing is required.
MarcZX10 commented 2026-11-15 02:52:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-15T02:52:38Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change; the reviewed code and reported checks support merging.

What I ran

Reviewed head 7c28798169000cf69f898627aec894591ce68ef6. I read all six changed files listed in manifest.json, plus description.md, commits.md, and diff.patch. I did not run commands or tests. The author reports Fork CI, hardware runs, and python -I tools/check_conventions.py passing.

Results

Check Result Note
Code review passed All changed files read
Tests in this review not run Author-reported results only
Reported CI and convention check passed As described by the author

Findings

Blocking

None.

Non-blocking

None.

Not verified

I did not run the test suite, convention check, or physical-console tests. The reported Fork CI, hardware results, and convention check were not independently verified.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5908745487 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19267#pullrequestreview-5908745487). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-15T02:52:38Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change; the reviewed code and reported checks support merging. ## What I ran Reviewed head `7c28798169000cf69f898627aec894591ce68ef6`. I read all six changed files listed in `manifest.json`, plus `description.md`, `commits.md`, and `diff.patch`. I did not run commands or tests. The author reports Fork CI, hardware runs, and `python -I tools/check_conventions.py` passing. ## Results | Check | Result | Note | |---|---|---| | Code review | passed | All changed files read | | Tests in this review | not run | Author-reported results only | | Reported CI and convention check | passed | As described by the author | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified I did not run the test suite, convention check, or physical-console tests. The reported Fork CI, hardware results, and convention check were not independently verified. ## To get this to a good state Nothing is required.
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!19267
No description provided.