perf(agc): scope an image table's write stamp to mapping changes of its own range #18390

Closed
simnJS wants to merge 9 commits from upstream-pr/18390 into main
simnJS commented 2026-11-11 13:17:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by simnJS on 2026-11-11T13:17:07Z.


What

The stamp that lets a captured image table be reused without reading its words again (ShaderMemory::stampWrites / Vouched) recorded the registry generation. That generation moves on every guest allocation, release, map and protection change. A title that allocates every frame therefore lost the unwritten reuse every frame, and compared or rebuilt each table instead.

The stamp now records the forget serial, and a vouch asks whether the table's own range was forgotten since. This is what #16879 does for draw input snapshots; this PR uses its unconditional invalidator and its range reports for image registration.

  • A range registered or removed elsewhere keeps the stamp.
  • A mapping change over the table still ends it.

Not changed: the image-view identity (normalizeImageView) and CurrentTableState still follow the registry generation. It is recorded in the debt file.

Three existing tests encoded the old contract and were updated:

  • table snapshot reuse and table vouch expected a range registered elsewhere to end the reuse. They now expect it to be kept, and an invalidation of the table's own first page to end it.
  • agc_driver_image_table_vouch_queued_draws built its stamp by hand from the registry generation; it now uses the forget serial.

Tested

  • Linux, lavapipe (Mesa 25.2.8, llvmpipe), GCC 13, Release. No hardware GPU and no title: not measured on a game.
  • Base (main a57e435a53 merged with #16879) and this branch, with ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, 23 tests (agc_shader_* from agc_shader_memory_tests, agc_driver_image_table*, agc_driver_recorder):
    • Both runs: 21 pass and the same 2 fail, agc_driver_image_table and agc_driver_image_table_packed. Those two fail on any VUID- in their output, and lavapipe reports VUID-VkDeviceCreateInfo-pNext-pNext at device creation on both sides.
    • The validation layer was found in both runs. Both logs hold that same VUID 27 times and no other.
  • Negative control: with the old stamp, the updated table snapshot reuse test fails with the table after a range was registered elsewhere: an unwritten table was read again.
  • One case I could not explain: in the table edge store setup (a table with an unwatched tail), a range registered and removed elsewhere still ended the vouch on this branch, although the mapping check passed. I did not find which other check refuses it, so that configuration may not gain.
  • To measure on a title: compare the unwritten and compared counts of the image table reuse line under APS5_PROFILE_DRAW, and the trace_digest summaries, between the base and this branch.

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: #16879
  • Fixes: none
  • Unblocks: none
  • GPUs tested: lavapipe only (llvmpipe, Mesa 25.2.8, Ubuntu 24.04); no hardware GPU
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5260167636 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18390). Originally posted by [simnJS](https://github.com/simnJS) on 2026-11-11T13:17:07Z. --- ### What The stamp that lets a captured image table be reused without reading its words again (`ShaderMemory::stampWrites` / `Vouched`) recorded the registry generation. That generation moves on every guest allocation, release, map and protection change. A title that allocates every frame therefore lost the unwritten reuse every frame, and compared or rebuilt each table instead. The stamp now records the forget serial, and a vouch asks whether the table's own range was forgotten since. This is what #16879 does for draw input snapshots; this PR uses its unconditional invalidator and its range reports for image registration. - A range registered or removed elsewhere keeps the stamp. - A mapping change over the table still ends it. Not changed: the image-view identity (`normalizeImageView`) and `CurrentTableState` still follow the registry generation. It is recorded in the debt file. Three existing tests encoded the old contract and were updated: - `table snapshot reuse` and `table vouch` expected a range registered elsewhere to end the reuse. They now expect it to be kept, and an invalidation of the table's own first page to end it. - `agc_driver_image_table_vouch_queued_draws` built its stamp by hand from the registry generation; it now uses the forget serial. ### Tested - Linux, lavapipe (Mesa 25.2.8, llvmpipe), GCC 13, Release. No hardware GPU and no title: **not measured on a game**. - Base (`main` a57e435a53 merged with #16879) and this branch, with `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`, 23 tests (`agc_shader_*` from `agc_shader_memory_tests`, `agc_driver_image_table*`, `agc_driver_recorder`): - Both runs: 21 pass and the same 2 fail, `agc_driver_image_table` and `agc_driver_image_table_packed`. Those two fail on any `VUID-` in their output, and lavapipe reports `VUID-VkDeviceCreateInfo-pNext-pNext` at device creation on both sides. - The validation layer was found in both runs. Both logs hold that same VUID 27 times and no other. - Negative control: with the old stamp, the updated `table snapshot reuse` test fails with `the table after a range was registered elsewhere: an unwritten table was read again`. - One case I could not explain: in the `table edge store` setup (a table with an unwatched tail), a range registered and removed elsewhere still ended the vouch on this branch, although the mapping check passed. I did not find which other check refuses it, so that configuration may not gain. - To measure on a title: compare the unwritten and compared counts of the image table reuse line under `APS5_PROFILE_DRAW`, and the `trace_digest` summaries, between the base and this branch. ### 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](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: #16879 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: lavapipe only (llvmpipe, Mesa 25.2.8, Ubuntu 24.04); no hardware GPU - [x] AI-assisted: yes
MarcZX10 commented 2026-11-12 14:25:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-12T14:25:15Z.

Review: COMMENTED


Reviewed — no blocking findings

Nothing blocks this; the points below are optional.

What I ran

  • Head: 1536b2d6d5 (base main). No merged-preview check was run.
  • Read-only review: the changed hunks in the review folder and the diff, plus repository reads at the head through repo_read.py (cat and search).
  • No build and no test run in this review.

Results

Check Result Note
Changed hunks read passed 14 of 14 reviewed files; 3 only in part (see Not verified)
Build not run No build in this review
Lavapipe tests not run Author-reported 21 of 23 pass, same 2 failing on both sides; not re-run here
Windows forget-stamp test not run Windows only
Comments in added code passed No comment lines added in the diff
Description claims vs code passed Stamp, invalidator and "not changed" list match the code read

Findings

Blocking

None.

Non-blocking

  • Reuse checks now loop over every 64 KiB block of the requested range. The check at core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp:3272 and the probe at core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp:3353 call ForgetStamp, which walks the blocks of the range (core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp:1177). A 256 MiB range is 4096 atomic loads per candidate, where the old check was one generation compare. Not measured.
  • The invalidator is now installed unconditionally (core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp:892). Every guest allocation, release and protection change now runs ForgetPages, even with no arena, image or write-index cache. This is needed for the stamp to be correct, but its cost is not measured.
  • Linux image registration is not covered by a new test. core/libs/prx/libc/src/GuestAllocations.cpp:396 and :416 now record changes on Linux, but the new --forget-stamps test is registered only under WIN32 (core/libs/prx/libSceAgcDriver/tests/cmake/agc_page_state_tests.cmake:9). A Linux regression in these two calls would not be caught by this diff.
  • docs/dev/debt/libSceAgcDriver.md:361 inserts a blank line inside a list, which splits it into two lists. Cosmetic.

Sources

Not verified

  • Build and tests were not run here. The lavapipe results are the author's, not re-run.
  • Three files were excluded for size and read only in part, through the reader: core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp (lines 6836–6884), core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp (lines 4209–4226 and 4604–4622) and core/libs/prx/libSceAgcDriver/tests/Recorder.cpp (lines 5204–5218). Their other changed hunks were checked in diff.patch only.
  • The unwritten draw snapshot stamp at core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp:6849 still records the registry generation. UnwrittenDrawSnapshot was not read, so whether that reuse still ends on any allocation is not verified.
  • The owned draw input proof at core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp:3474 still compares the registry generation. That line is not in this diff, and the description's "not changed" list does not mention it.
  • The "table edge store" case that the author could not explain was not investigated.
  • The Apple registration branch in core/libs/prx/libc/src/GuestAllocations.cpp was not read.

To get this to a good state

Nothing is required.

Optional: a Linux test for image registration, and a measurement of the range walk in ForgetStamp on a large range, as the description already asks for on a title.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5876084046 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18390#pullrequestreview-5876084046). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-12T14:25:15Z. **Review:** COMMENTED --- # Reviewed — no blocking findings Nothing blocks this; the points below are optional. ## What I ran - Head: 1536b2d6d59e0a68be866209e1b37fd9a7c6fc42 (base main). No merged-preview check was run. - Read-only review: the changed hunks in the review folder and the diff, plus repository reads at the head through `repo_read.py` (`cat` and `search`). - No build and no test run in this review. ## Results | Check | Result | Note | | --- | --- | --- | | Changed hunks read | passed | 14 of 14 reviewed files; 3 only in part (see Not verified) | | Build | not run | No build in this review | | Lavapipe tests | not run | Author-reported 21 of 23 pass, same 2 failing on both sides; not re-run here | | Windows forget-stamp test | not run | Windows only | | Comments in added code | passed | No comment lines added in the diff | | Description claims vs code | passed | Stamp, invalidator and "not changed" list match the code read | ## Findings **Blocking** None. **Non-blocking** - Reuse checks now loop over every 64 KiB block of the requested range. The check at core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp:3272 and the probe at core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp:3353 call `ForgetStamp`, which walks the blocks of the range (core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp:1177). A 256 MiB range is 4096 atomic loads per candidate, where the old check was one generation compare. Not measured. - The invalidator is now installed unconditionally (core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp:892). Every guest allocation, release and protection change now runs `ForgetPages`, even with no arena, image or write-index cache. This is needed for the stamp to be correct, but its cost is not measured. - Linux image registration is not covered by a new test. core/libs/prx/libc/src/GuestAllocations.cpp:396 and :416 now record changes on Linux, but the new `--forget-stamps` test is registered only under WIN32 (core/libs/prx/libSceAgcDriver/tests/cmake/agc_page_state_tests.cmake:9). A Linux regression in these two calls would not be caught by this diff. - docs/dev/debt/libSceAgcDriver.md:361 inserts a blank line inside a list, which splits it into two lists. Cosmetic. ## Sources - [ForgetSerial and ForgetStamp](https://github.com/boykopovar/AnyPS5/blob/1536b2d6d59e0a68be866209e1b37fd9a7c6fc42/core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp#L1167-L1180) - [MappingUnchanged](https://github.com/boykopovar/AnyPS5/blob/1536b2d6d59e0a68be866209e1b37fd9a7c6fc42/core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp#L3271-L3273) - [Invalidator calls at the end of a mutation](https://github.com/boykopovar/AnyPS5/blob/1536b2d6d59e0a68be866209e1b37fd9a7c6fc42/core/libs/prx/libc/src/GuestAllocations.cpp#L185-L190) ## Not verified - Build and tests were not run here. The lavapipe results are the author's, not re-run. - Three files were excluded for size and read only in part, through the reader: core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp (lines 6836–6884), core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp (lines 4209–4226 and 4604–4622) and core/libs/prx/libSceAgcDriver/tests/Recorder.cpp (lines 5204–5218). Their other changed hunks were checked in diff.patch only. - The unwritten draw snapshot stamp at core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp:6849 still records the registry generation. `UnwrittenDrawSnapshot` was not read, so whether that reuse still ends on any allocation is not verified. - The owned draw input proof at core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp:3474 still compares the registry generation. That line is not in this diff, and the description's "not changed" list does not mention it. - The "table edge store" case that the author could not explain was not investigated. - The Apple registration branch in core/libs/prx/libc/src/GuestAllocations.cpp was not read. ## To get this to a good state Nothing is required. Optional: a Linux test for image registration, and a measurement of the range walk in `ForgetStamp` on a large range, as the description already asks for on a title.
MarcZX10 commented 2026-11-21 04:39:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T04:39:40Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change; the reviewed code supports the range-scoped invalidation described in the PR, and no verified blocking defect was found.

What I ran

  • Reviewed head 390bd3d2c2b9dcb6236cb2afec7951eede5afafd; no commands or tests were run. The author reports lavapipe tests and a negative control in the PR description.
  • Read description.md, commits.md, manifest.json, and diff.patch. Read the changed source and test files listed below through repo_read.py; three changed files were excluded as too large for the review folder and read only at the relevant diff hunks.

Results

Check Result Note
Diff and code review passed No blocking defect verified
Automated tests not run Results in the description are author-reported
Negative control not run The reported negative control was not run by me

Findings

Blocking

None.

Non-blocking

None.

Not verified

  • Full text of core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp, core/libs/prx/libSceAgcDriver/tests/Recorder.cpp, and core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp was excluded by the review-folder size rule; I inspected their changed hunks in diff.patch.
  • Tests, compiler/build checks, and runtime behavior were not independently verified. The PR description reports an unexplained edge-store configuration that may not benefit from the change.
  • No commit-pinned permalinks are included because repository web access was not used.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6002874996 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18390#pullrequestreview-6002874996). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-21T04:39:40Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change; the reviewed code supports the range-scoped invalidation described in the PR, and no verified blocking defect was found. ## What I ran - Reviewed head `390bd3d2c2b9dcb6236cb2afec7951eede5afafd`; no commands or tests were run. The author reports lavapipe tests and a negative control in the PR description. - Read `description.md`, `commits.md`, `manifest.json`, and `diff.patch`. Read the changed source and test files listed below through `repo_read.py`; three changed files were excluded as too large for the review folder and read only at the relevant diff hunks. ## Results | Check | Result | Note | |---|---|---| | Diff and code review | passed | No blocking defect verified | | Automated tests | not run | Results in the description are author-reported | | Negative control | not run | The reported negative control was not run by me | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified - Full text of `core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp`, `core/libs/prx/libSceAgcDriver/tests/Recorder.cpp`, and `core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp` was excluded by the review-folder size rule; I inspected their changed hunks in `diff.patch`. - Tests, compiler/build checks, and runtime behavior were not independently verified. The PR description reports an unexplained edge-store configuration that may not benefit from the change. - No commit-pinned permalinks are included because repository web access was not used. ## To get this to a good state Nothing is required.

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