fix(agc): publish unit shadows before address-space reuse #19351

Merged
lgqdaxia merged 2 commits from upstream-pr/19351 into main 2026-12-04 00:09:25 +00:00
lgqdaxia commented 2026-11-13 05:05:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by lgqdaxia on 2026-11-13T05:05:09Z.


What

A cached address-draw space can read old imported bytes after a GPU write leaves newer data in a UnitShadow. RetakeSpace skips the shadow publication performed by a fresh UploadFinish, and space-only reuse bypasses ordinary direct-region revalidation.

Publish shadows over the reused space's bounds before refreshing its mirrors, using the existing fresh-build operation. Add a regression that verifies an actual cache hit, a later CPU-overwrite control, and a fresh-build control.

Tested

Windows 11 Pro 10.0.26300, MinGW UCRT64 GCC 15.2.0, NVIDIA GeForce RTX 3080 Laptop GPU / 621.14; validation layer 1.4.366.

  • Same fixture and GPU on main a6fbf9ce9632 and the fix: 6/8 → 8/8 passed, zero skips. Main reads 40 instead of 210 in the shadow-publish case and default suite; both pass with the fix. The later CPU write remains 90 on both sides.
  • Both runs used ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation and VK_LOADER_DEBUG=error,warn,layer. Layer insertion confirmed; zero VUIDs on either side.
  • Full-project test-registration audit and conventions check pass.
Exact comparison and overlap check

2026-11-13: tested candidate 62cd42a97356. The control restored only GuestBufferMemory.cpp to main a6fbf9ce9632, retaining the same regression executable. Test command: ctest --test-dir build -R '^agc_driver_address_draw_space_reuse($|_)' -V.

Rebased onto 441fa651195e on 2026-11-23, including the AudioOut2 revert in #25143. The AGC fix and its regression tests carry over unchanged from the previous PR revision.

pr_overlap.py and manual comparison of its 27 shared-file candidates found no equivalent fix. #9508 shares a test-header insertion; its production change only factors mirror refresh into a helper. #17796 publishes storage images into resident heap mirrors, a different path from existing UnitShadow publication into host imports. Neither is a dependency.

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: Fixes #19350
  • Unblocks: none
  • GPUs tested: NVIDIA GeForce RTX 3080 Laptop GPU, driver 621.14, Windows 11 Pro 10.0.26300
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5290384181 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19351). Originally posted by [lgqdaxia](https://github.com/lgqdaxia) on 2026-11-13T05:05:09Z. --- ### What A cached address-draw space can read old imported bytes after a GPU write leaves newer data in a UnitShadow. `RetakeSpace` skips the shadow publication performed by a fresh `UploadFinish`, and space-only reuse bypasses ordinary direct-region revalidation. Publish shadows over the reused space's bounds before refreshing its mirrors, using the existing fresh-build operation. Add a regression that verifies an actual cache hit, a later CPU-overwrite control, and a fresh-build control. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Windows 11 Pro 10.0.26300, MinGW UCRT64 GCC 15.2.0, NVIDIA GeForce RTX 3080 Laptop GPU / 621.14; validation layer 1.4.366. - Same fixture and GPU on main `a6fbf9ce9632` and the fix: **6/8 → 8/8 passed**, zero skips. Main reads **40 instead of 210** in the shadow-publish case and default suite; both pass with the fix. The later CPU write remains **90** on both sides. - Both runs used `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1`, `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation` and `VK_LOADER_DEBUG=error,warn,layer`. Layer insertion confirmed; **zero VUIDs on either side**. - Full-project test-registration audit and conventions check pass. <details> <summary>Exact comparison and overlap check</summary> 2026-11-13: tested candidate `62cd42a97356`. The control restored only `GuestBufferMemory.cpp` to main `a6fbf9ce9632`, retaining the same regression executable. Test command: `ctest --test-dir build -R '^agc_driver_address_draw_space_reuse($|_)' -V`. Rebased onto `441fa651195e` on 2026-11-23, including the AudioOut2 revert in #25143. The AGC fix and its regression tests carry over unchanged from the previous PR revision. `pr_overlap.py` and manual comparison of its 27 shared-file candidates found no equivalent fix. #9508 shares a test-header insertion; its production change only factors mirror refresh into a helper. #17796 publishes storage images into resident heap mirrors, a different path from existing UnitShadow publication into host imports. Neither is a dependency. </details> ### 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: Fixes #19350 - [x] Unblocks: none - [x] GPUs tested: NVIDIA GeForce RTX 3080 Laptop GPU, driver 621.14, Windows 11 Pro 10.0.26300 - [x] AI-assisted: yes
MarcZX10 commented 2026-11-23 02:28:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-23T02:28:59Z.

Review: COMMENTED


Reviewed — no blocking findings

The inspected changes address the stale-shadow reuse path, but I could not run the checks or inspect the full production source file, so a formal approval is not justified.

What I ran

Reviewed head 4068918813d7767fcb8c6f7a2c2a947a000f1d69 using the pinned repo_read.py reader. No tests or build commands were run. The author reports GPU regression and convention checks in the PR description; these were not independently run.

Results

Check Result Note
Production path review passed Relevant reuse and publication code inspected
Regression review passed Added cases and CMake registration inspected
Tests and build not run Author-reported results only

Findings

Blocking

None found in the inspected code.

Non-blocking

None.

Not verified

The remainder of GuestBufferMemory.cpp was not read; the manifest marks its full text as excluded for size. No build, test, or GPU validation was run in this review. The PR description reports successful GPU tests and conventions checks, but those results are author-reported.

Files read: GuestBufferMemory.cpp relevant ranges around RetakeSpace and UploadFinish; Texture.cpp relevant publication ranges; the complete changed CMake test-registration file; and the relevant changed and test-dispatch ranges in AddressDrawSpaceReuse.cpp. Excluded from the review bundle: full text of GuestBufferMemory.cpp.

To get this to a good state

Nothing is required. Optional: independently run the focused regression suite and build on the pinned head.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6015924567 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19351#pullrequestreview-6015924567). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-23T02:28:59Z. **Review:** COMMENTED --- # Reviewed — no blocking findings The inspected changes address the stale-shadow reuse path, but I could not run the checks or inspect the full production source file, so a formal approval is not justified. ## What I ran Reviewed head `4068918813d7767fcb8c6f7a2c2a947a000f1d69` using the pinned `repo_read.py` reader. No tests or build commands were run. The author reports GPU regression and convention checks in the PR description; these were not independently run. ## Results | Check | Result | Note | |---|---|---| | Production path review | passed | Relevant reuse and publication code inspected | | Regression review | passed | Added cases and CMake registration inspected | | Tests and build | not run | Author-reported results only | ## Findings ### Blocking None found in the inspected code. ### Non-blocking None. ## Not verified The remainder of `GuestBufferMemory.cpp` was not read; the manifest marks its full text as excluded for size. No build, test, or GPU validation was run in this review. The PR description reports successful GPU tests and conventions checks, but those results are author-reported. Files read: `GuestBufferMemory.cpp` relevant ranges around `RetakeSpace` and `UploadFinish`; `Texture.cpp` relevant publication ranges; the complete changed CMake test-registration file; and the relevant changed and test-dispatch ranges in `AddressDrawSpaceReuse.cpp`. Excluded from the review bundle: full text of `GuestBufferMemory.cpp`. ## To get this to a good state Nothing is required. Optional: independently run the focused regression suite and build on the pinned head.
MarcZX10 commented 2026-11-23 02:45:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-23T02:45:35Z.

Review: APPROVED


Reviewed — looks good

The changed code and all files marked reviewed were inspected at head cdc376ea15fc34ce3f59705d4b6b56139940b5b5; no verified defect blocks merging.

What I ran

No test commands were run. Review was based on the prepared diff and targeted reads through repo_read.py.

Results

Check Result Note
Diff and changed code passed Inspected the changed logic and test cases
Tests not run Author-reported test results were not independently run

Negative control

Not run; no test environment was available in this review session.

Findings

Blocking

None.

Non-blocking

None.

Sources

Behavior claims were checked against the prepared change and the implementation of PublishShadowsOnly at the reviewed head.

Not verified

Tests and runtime behavior were not independently verified. The full text for GuestBufferMemory.cpp was excluded from the review folder because it was too large; the changed function and adjacent relevant code were read through repo_read.py. All three changed files listed in the manifest were reviewed, including the two test files in full and the changed production hunk with surrounding code.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6016005861 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19351#pullrequestreview-6016005861). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-23T02:45:35Z. **Review:** APPROVED --- # Reviewed — looks good The changed code and all files marked reviewed were inspected at head `cdc376ea15fc34ce3f59705d4b6b56139940b5b5`; no verified defect blocks merging. ## What I ran No test commands were run. Review was based on the prepared diff and targeted reads through `repo_read.py`. ## Results | Check | Result | Note | |---|---|---| | Diff and changed code | passed | Inspected the changed logic and test cases | | Tests | not run | Author-reported test results were not independently run | ## Negative control Not run; no test environment was available in this review session. ## Findings ### Blocking None. ### Non-blocking None. ## Sources Behavior claims were checked against the prepared change and the implementation of `PublishShadowsOnly` at the reviewed head. ## Not verified Tests and runtime behavior were not independently verified. The full text for `GuestBufferMemory.cpp` was excluded from the review folder because it was too large; the changed function and adjacent relevant code were read through `repo_read.py`. All three changed files listed in the manifest were reviewed, including the two test files in full and the changed production hunk with surrounding code. ## To get this to a good state Nothing is required.
malekaifa commented 2026-11-23 03:15:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by malekaifa on 2026-11-23T03:15:54Z.

Review: APPROVED


Reviewed exact head cdc376ea15fc34ce3f59705d4b6b56139940b5b5. I verified all three PR-file blobs are byte-identical to the prior head 4068918813d7767fcb8c6f7a2c2a947a000f1d69 that I independently tested on Windows/NVIDIA, where the address-space-reuse regressions passed 8/8 with validation enabled and failed on main with the PR fixtures. This rebase brings in the unrelated AudioOut2 revert I requested; its Windows job now fails only guest_sleep_wake, outside the three changed AGC files. MarcZX10 also approved this exact head. No blocking AGC finding from me. AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6016176294 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19351#pullrequestreview-6016176294). Originally posted by [malekaifa](https://github.com/malekaifa) on 2026-11-23T03:15:54Z. **Review:** APPROVED --- Reviewed exact head `cdc376ea15fc34ce3f59705d4b6b56139940b5b5`. I verified all three PR-file blobs are byte-identical to the prior head `4068918813d7767fcb8c6f7a2c2a947a000f1d69` that I independently tested on Windows/NVIDIA, where the address-space-reuse regressions passed 8/8 with validation enabled and failed on main with the PR fixtures. This rebase brings in the unrelated AudioOut2 revert I requested; its Windows job now fails only `guest_sleep_wake`, outside the three changed AGC files. MarcZX10 also approved this exact head. No blocking AGC finding from me. AI-assisted: yes
Plyxen commented 2026-12-03 10:41:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Plyxen on 2026-12-03T10:41:05Z.

Review: APPROVED


I read the diff at cdc376ea15. Windows 11, GCC 15.2, merged into main at b97867d3ce6 together with other open PRs (so not an isolated build), with ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 and VK_LAYER_KHRONOS_validation on an RTX 5080 (621.24) and a Radeon iGPU (26.11.2).

  • the 10 agc_driver_address_draw_space_reuse tests: pass on both GPUs. The loader log shows the layer inserted and no "was not found" line, and neither run has a VUID- or SYNC-HAZARD line.
  • Control (same tree and tests, the changed files of those PRs put back to main's): agc_driver_address_draw_space_reuse and _shadow_publish fail on both GPUs: "a draw after a unit-shadow write read 40 instead of 210". The other eight pass.

The red check is guest_sleep_wake, which this PR does not touch; it passes here.

Not checked: a title.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6168160233 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19351#pullrequestreview-6168160233). Originally posted by [Plyxen](https://github.com/Plyxen) on 2026-12-03T10:41:05Z. **Review:** APPROVED --- I read the diff at `cdc376ea15`. Windows 11, GCC 15.2, merged into `main` at `b97867d3ce6` together with other open PRs (so not an isolated build), with `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1` and `VK_LAYER_KHRONOS_validation` on an RTX 5080 (621.24) and a Radeon iGPU (26.11.2). - the 10 `agc_driver_address_draw_space_reuse` tests: pass on both GPUs. The loader log shows the layer inserted and no "was not found" line, and neither run has a `VUID-` or `SYNC-HAZARD` line. - Control (same tree and tests, the changed files of those PRs put back to `main`'s): `agc_driver_address_draw_space_reuse` and `_shadow_publish` fail on both GPUs: "a draw after a unit-shadow write read 40 instead of 210". The other eight pass. The red check is `guest_sleep_wake`, which this PR does not touch; it passes here. Not checked: a title. AI-assisted: yes (Claude Code)
ligmaSec commented 2026-12-03 22:17:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T22:17:08Z.

Review: COMMENTED


I trial-merged this head cleanly onto a1b75b0947. RetakeSpace now publishes shadows before reading the epoch and proof used to refresh the mirrors, which matches the fresh-build ordering. The regression explicitly checks a cache hit and covers the CPU-overwrite and fresh-build controls. Please retain the cache-hit assertion if the fixture changes, since a forced rebuild would otherwise let an old reuse path pass. Local paired validation is pending.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6179572685 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19351#pullrequestreview-6179572685). Originally posted by [ligmaSec](https://github.com/ligmaSec) on 2026-12-03T22:17:08Z. **Review:** COMMENTED --- I trial-merged this head cleanly onto `a1b75b0947`. `RetakeSpace` now publishes shadows before reading the epoch and proof used to refresh the mirrors, which matches the fresh-build ordering. The regression explicitly checks a cache hit and covers the CPU-overwrite and fresh-build controls. Please retain the cache-hit assertion if the fixture changes, since a forced rebuild would otherwise let an old reuse path pass. Local paired validation is pending. AI-assisted: yes.
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!19351
No description provided.