perf(agc): learn draw relocation shapes from data donors #26778

Open
akkadbakkad89 wants to merge 0 commits from upstream-pr/26778 into main
akkadbakkad89 commented 2026-11-24 21:14:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by akkadbakkad89 on 2026-11-24T21:14:57Z.


What

When a draw's pointers move between captures, its stored stage variants are reusable only if the draw-cache relocation machinery can patch the moved words. Two pieces of that machinery were missing:

  • learnPendingRelocation learned moved shapes only from the keyed entry's own decode results. When that entry lacks decode (data-only hits dominate in some titles), it now learns from the data-donor entry held in DrawRelocationPending.donor.
  • The learned run offset for a callee word was computed against the low dword alone, so relocatedContentKey added high << 32 twice and every relocated read landed near twice the pointer's 4 GiB region — unreachable. The offset is now based on (word.high << 32) + AlignedWord(userData[index]), so a read through a moved callee pointer resolves at its delta in the new copy.

Stages whose decode records reads (vertex fetch, resourcesNum > 0) remain non-relocatable; extending relocation to them is split into a follow-up PR per the maintainer's request in #26595.

Tested

Windows 11, NVIDIA RTX 3070 (driver 617.42). ctest -R 'agc_driver_draw_relocate_user_values|agc_driver_draw_cache_relocation' with ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LAYER_PATH=D:\VulkanSDK\Bin (layer 1.4.363.0 ≥ VK_HEADER_VERSION 335; Insert instance layer "VK_LAYER_KHRONOS_validation" present in each log, no was not found but was requested, no VUID- lines): the change passes 8/8 and main (61cce6e8) passes 8/8 on the same subset.

New test HighCalleeWordsLearnDeltaOffsets in DrawRelocateUserValues.cpp: a callee pointer and a captured run are placed in the guest arena above 4 GiB, the draw entry is fed to the real learnPendingRelocation through both the keyed path and the data-donor path, and the learned shape must record the run's offset as its delta (0x80), not the absolute address; relocatedContentKey then keys the donor, a moved copy with identical contents, and a moved copy with changed contents correctly. With the base regression reintroduced the test fails at the delta assertion ("a run through a pointer above 4 GiB learned an absolute offset instead of its delta"); with the fix it passes. MovedDataHitsTheCache and MovedForwardedWordReachesStageDataHit continue to cover the same-data reuse and pointee-changed re-read cases through real draws.

In-world (PPSA03530 GTA-VC, PPSA03524 GTA-SA, measured on the instrumented equivalent of these two fixes): every admitted donor relocates — 0 refusals across ~1.1k donors vs ~50% refused under the stock admission. GTA-SA fps A/B in the same scene: 40–54 vs 37–49 presents/10 s — no measurable regression; the ~4–5 fps ceiling there is guest-memory collect, not relocation.

PPSA21564-class workload (Lucky's Tale, reported by JJenkx on the same two fixes): failed relocated reads 101k→0, trial idle-skip 94%→12%, relocation hit rate 2%→56–59%, stage compiles ~300k→~155k per 10 s, +4% presents, ~6 ms better p99, no FATAL. Astro Bot (PPSA21564) itself has not been run on this head — flagged for verification in #26595.

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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 — contributes to #26595; the vertex-fetch half lands in a follow-up PR
  • Unblocks: PPSA03524, PPSA03530, PPSA21564 — #26595
  • GPUs tested: NVIDIA RTX 3070, driver 617.42, Windows 11
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5480455160 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/26778). Originally posted by [akkadbakkad89](https://github.com/akkadbakkad89) on 2026-11-24T21:14:57Z. --- ### What When a draw's pointers move between captures, its stored stage variants are reusable only if the draw-cache relocation machinery can patch the moved words. Two pieces of that machinery were missing: - `learnPendingRelocation` learned moved shapes only from the keyed entry's own decode results. When that entry lacks decode (data-only hits dominate in some titles), it now learns from the data-donor entry held in `DrawRelocationPending.donor`. - The learned run offset for a callee word was computed against the low dword alone, so `relocatedContentKey` added `high << 32` twice and every relocated read landed near twice the pointer's 4 GiB region — unreachable. The offset is now based on `(word.high << 32) + AlignedWord(userData[index])`, so a read through a moved callee pointer resolves at its delta in the new copy. Stages whose decode records reads (vertex fetch, `resourcesNum > 0`) remain non-relocatable; extending relocation to them is split into a follow-up PR per the maintainer's request in #26595. ### Tested Windows 11, NVIDIA RTX 3070 (driver 617.42). `ctest -R 'agc_driver_draw_relocate_user_values|agc_driver_draw_cache_relocation'` with `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LAYER_PATH=D:\VulkanSDK\Bin` (layer 1.4.363.0 ≥ VK_HEADER_VERSION 335; `Insert instance layer "VK_LAYER_KHRONOS_validation"` present in each log, no `was not found but was requested`, no `VUID-` lines): the change passes 8/8 and `main` (`61cce6e8`) passes 8/8 on the same subset. New test `HighCalleeWordsLearnDeltaOffsets` in `DrawRelocateUserValues.cpp`: a callee pointer and a captured run are placed in the guest arena above 4 GiB, the draw entry is fed to the real `learnPendingRelocation` through both the keyed path and the data-donor path, and the learned shape must record the run's offset as its delta (`0x80`), not the absolute address; `relocatedContentKey` then keys the donor, a moved copy with identical contents, and a moved copy with changed contents correctly. With the base regression reintroduced the test fails at the delta assertion ("a run through a pointer above 4 GiB learned an absolute offset instead of its delta"); with the fix it passes. `MovedDataHitsTheCache` and `MovedForwardedWordReachesStageDataHit` continue to cover the same-data reuse and pointee-changed re-read cases through real draws. In-world (PPSA03530 GTA-VC, PPSA03524 GTA-SA, measured on the instrumented equivalent of these two fixes): every admitted donor relocates — 0 refusals across ~1.1k donors vs ~50% refused under the stock admission. GTA-SA fps A/B in the same scene: 40–54 vs 37–49 presents/10 s — no measurable regression; the ~4–5 fps ceiling there is guest-memory collect, not relocation. PPSA21564-class workload (Lucky's Tale, reported by JJenkx on the same two fixes): failed relocated reads 101k→0, trial idle-skip 94%→12%, relocation hit rate 2%→56–59%, stage compiles ~300k→~155k per 10 s, +4% presents, ~6 ms better p99, no FATAL. Astro Bot (PPSA21564) itself has not been run on this head — flagged for verification in #26595. ### 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) and the licence notice of code adapted from upstream (see AGENTS.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 — contributes to #26595; the vertex-fetch half lands in a follow-up PR - [x] Unblocks: PPSA03524, PPSA03530, PPSA21564 — #26595 - [x] GPUs tested: NVIDIA RTX 3070, driver 617.42, Windows 11 - [x] AI-assisted: yes
MarcZX10 commented 2026-11-25 01:33:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T01:33:14Z.

Review: DISMISSED


Reviewed — changes requested

Changes are required before merge: fix the decode-read attribution so each read uses the actual user-data pointer word.

What I ran

Reviewed head 79699ccee24f453ad7d0e4d9e80f9c88ec7ff34c using repo_read.py. No tests were run by me; the test and workload results in the PR description are author-reported.

Results

Check Result Note
Changed code review failed One verified pointer attribution defect
Tests not run Author-reported results only

Findings

Blocking

  • core/libs/prx/libSceAgcDriver/Graphics/src/ShaderInputState.cpp:354: the attribute-table read is tagged with attribWord, the 32-bit contents loaded from the table, instead of the user-data word index attribWord is meant to identify. The table address is formed from userData[attribWord] and userData[attribWord + 1] at lines 283–284, so this attribution can be an arbitrary value outside the 0–63 user-word domain. DrawCapture.cpp:368–374 then rejects the stage as non-relocatable when that value is out of range, or treats an unrelated word as the pointer when it happens to be in range. Pass the pointer-word index (the local attribWord identifier is shadowed by the later contents variable) to record; apply the same correction to the buffer-table read at ShaderInputState.cpp:364, which already uses bufferWord.

Non-blocking

None.

Not verified

  • No tests or runtime workloads were run in this review; Windows, GPU and console behavior are not independently confirmed.
  • Reviewed all eight changed files listed in the manifest. Their full texts were available; no changed file was excluded.
  • The PR description's reported test runs and performance measurements were not independently verified.

To get this to a good state

  • Correct the attribute-table read attribution, then rerun the relocation tests and verify that decode reads are associated with the pointer user-data words before relocation is admitted.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:6050217354 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/26778#pullrequestreview-6050217354). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-25T01:33:14Z. **Review:** DISMISSED --- # Reviewed — changes requested Changes are required before merge: fix the decode-read attribution so each read uses the actual user-data pointer word. ## What I ran Reviewed head `79699ccee24f453ad7d0e4d9e80f9c88ec7ff34c` using `repo_read.py`. No tests were run by me; the test and workload results in the PR description are author-reported. ## Results | Check | Result | Note | |---|---|---| | Changed code review | failed | One verified pointer attribution defect | | Tests | not run | Author-reported results only | ## Findings ### Blocking - `core/libs/prx/libSceAgcDriver/Graphics/src/ShaderInputState.cpp:354`: the attribute-table read is tagged with `attribWord`, the 32-bit *contents* loaded from the table, instead of the user-data word index `attribWord` is meant to identify. The table address is formed from `userData[attribWord]` and `userData[attribWord + 1]` at lines 283–284, so this attribution can be an arbitrary value outside the 0–63 user-word domain. `DrawCapture.cpp:368–374` then rejects the stage as non-relocatable when that value is out of range, or treats an unrelated word as the pointer when it happens to be in range. Pass the pointer-word index (the local `attribWord` identifier is shadowed by the later contents variable) to `record`; apply the same correction to the buffer-table read at `ShaderInputState.cpp:364`, which already uses `bufferWord`. ### Non-blocking None. ## Not verified - No tests or runtime workloads were run in this review; Windows, GPU and console behavior are not independently confirmed. - Reviewed all eight changed files listed in the manifest. Their full texts were available; no changed file was excluded. - The PR description's reported test runs and performance measurements were not independently verified. ## To get this to a good state - Correct the attribute-table read attribution, then rerun the relocation tests and verify that decode reads are associated with the pointer user-data words before relocation is admitted.
MarcZX10 commented 2026-11-25 06:53:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T06:53:40Z.

Review: COMMENTED


Reviewed — no blocking findings

The inspected changes implement the stated donor-learning and high-address offset fixes; the reported test and runtime results were not independently run here.

What I ran

Inspected head 21db7bb556b22aed99781c2f04c813f78f6535ad using repo_read.py to read the prepared review bundle and changed files. No test commands were run.

Results

Check Result Note
Changed-file review passed All five reviewed files read
Tests not run Author-reported results not independently verified
Negative control not run No test mutation performed

Findings

Blocking

None.

Non-blocking

None.

Sources

Reviewed the prepared diff and head-pinned repository files: DrawCache.hpp, Draw.cpp, DrawRelocate.cpp, DrawRelocateUserValues.cpp, and agc-draw-relocation-decode-reads.md.

Not verified

The Windows/Vulkan test results, in-world captures, performance claims, and behavior on Astro Bot were not independently verified. No files were excluded by the manifest; all five changed files listed there were read.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6053109066 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/26778#pullrequestreview-6053109066). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-25T06:53:40Z. **Review:** COMMENTED --- # Reviewed — no blocking findings The inspected changes implement the stated donor-learning and high-address offset fixes; the reported test and runtime results were not independently run here. ## What I ran Inspected head `21db7bb556b22aed99781c2f04c813f78f6535ad` using `repo_read.py` to read the prepared review bundle and changed files. No test commands were run. ## Results | Check | Result | Note | |---|---|---| | Changed-file review | passed | All five reviewed files read | | Tests | not run | Author-reported results not independently verified | | Negative control | not run | No test mutation performed | ## Findings ### Blocking None. ### Non-blocking None. ## Sources Reviewed the prepared diff and head-pinned repository files: `DrawCache.hpp`, `Draw.cpp`, `DrawRelocate.cpp`, `DrawRelocateUserValues.cpp`, and `agc-draw-relocation-decode-reads.md`. ## Not verified The Windows/Vulkan test results, in-world captures, performance claims, and behavior on Astro Bot were not independently verified. No files were excluded by the manifest; all five changed files listed there were read. ## To get this to a good state Nothing is required.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/26778:upstream-pr/26778'
git switch 'upstream-pr/26778'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/26778'
git switch 'upstream-pr/26778'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/26778'
git switch 'upstream-pr/26778'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/26778'
git switch 'main'
git merge --squash 'upstream-pr/26778'
git switch 'main'
git merge --ff-only 'upstream-pr/26778'
git switch 'main'
git merge 'upstream-pr/26778'
git push origin 'main'
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!26778
No description provided.