fix(agc): publish unit-shadow results before an address-based build maps its heaps #6682

Merged
EagleBearerYS merged 3 commits from upstream-pr/6682 into main 2026-10-23 08:34:15 +00:00
EagleBearerYS commented 2026-10-16 04:24:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-16T04:24:31Z.


What

An address-based build binds the registered heaps in place and does not store the storage results pending in them: the heaps hold every pending image, and storing them all would serialize the build. With unit shadows on, a storage write-back that retiles into a shadow ("storage refresh", "storage image creation") reaches the import only through a publish: a host-facing reader, an eviction, an idle flush. Nothing published before an address-based build, so its pointer reads saw the bytes as of the last publish. In Resident Evil Village (PPSA01556) that is the title menu's last frame, published once by the idle flush at the load and shown dimmed over gameplay.

Two paths had the gap:

  • the per-build path skipped FlushPending for the exempt in-place heaps;
  • with the address-space cache (the default), the heaps live in the cached space's base and never reach the upload loop at all, so APS5_BDA_FLUSH=1 did not reach them either.

UploadFinish now publishes the fresh units over the heaps the build maps: the space's base, and the exempt regions of the per-build path. One AnyShadowedOverlaps check over their span gates it.

  • Pending results stay pending; only results already stored into a slab are copied. Pointer reads now see what they see with shadows off.
  • The copies are recorded into the active recorder's open batch under the device lock, ahead of the build's draw or dispatch.
  • They are counted under a new publish reason, address, in the [storage] line.

A CPU store inside a completion action (6ee5a91b2a). Found by an after-the-fact completeness review, on main with or without the rest of this PR. A store a completion action makes was published with PublishScope::None, which skips the units it covers partly. Its stamp then marked those units stale, and the next publish dropped them whole: up to 65,532 bytes of results around each such store. Completion stores now publish their partly covered units first, and a store that waited for its batch publishes like any other; the completion's existing Sync() orders the copy.

Tested

Linux, Mesa lavapipe, CI's Linux job mirror:

  • configure, test registration, build and libs pass;
  • ctest at the fix commit: 1273 of 1278 pass; the 5 failures are network tests that need IPv6, which the machine lacks;
  • ^agc at the head: 607 of 608 pass (43 of them skip as expected); the one failure, agc_driver_preparation_scope_settle, is a timing flake that also fails on main under the same parallel load and passes alone;
  • the new tests pass 20 of 20 runs (--repeat until-fail:10).
  • the completion store fix on GitHub's runners (run): with its five source files at e82f9f1a52's, agc_unit_shadow_completion_store fails in all 3 runs on Linux with the same message, and with them it and 41 neighbouring tests pass 10 runs in a row; the GPU tests skip on the Windows runner.

New agc_driver_bda_reads_shadowed_results and agc_driver_bda_reads_shadowed_results_per_build (APS5_NO_ADDRESS_SPACE_CACHE=1). A storage image's write-back retiles into the unit shadow of a registered heap, then an address-based build maps the heap:

  • on main both fail with "an address-based build over a heap left the unit shadow's stored results unpublished: the import held the earlier bytes at its submission";
  • with the fix the import holds the stored results at the build's submission;
  • a build with nothing shadowed, and a second build with nothing newly retiled, record no copy;
  • results still pending are not stored by the build.

Windows 11, RTX 3070 Laptop GPU (driver 617.42), MinGW build:

  • both new tests pass 5 runs in a row, with the address-space cache on and off;
  • with the fix's GuestBufferMemory.cpp change reverted, both fail with the same message as on Linux;
  • the tests' heap is 2 MiB (the second commit), so its Windows import is settled (main settles imports of 1 MiB or more) and keeps the write watch; at 256 KiB both tests skipped on Windows;
  • this ran with the PR on top of our test tree (main with other open PRs). GitHub's Windows runner has no Vulkan device, so these tests skip there.
  • the completion store fix (6ee5a91b2a), with the fix on our test tree: agc_unit_shadow_completion_store and both tests above pass 5 runs in a row; with its five source files at the parent, only agc_unit_shadow_completion_store fails ("a CPU store inside a completion over a pending image lost 65532 bytes of the image's results around it").

Resident Evil Village (PPSA01556), Windows 11, RTX 3070 Laptop GPU (driver 617.42), unit shadows on (the default):

  • Before: on our earlier test tree, at control in the first scene after loading a save, the title menu's foreground (stakes and branches) is drawn dimmed over the room, densest over the lower left, and does not fade.
  • After: on our current test tree (main with this PR and other open PRs), the same save and view at control show no trace of it over ~8 minutes.
  • The earlier tree is not this PR's base: the same tree without this PR stops earlier in the save load for an unrelated reason (fixed in #6366), so the before is from the tree that reached the scene.

Linux, NVIDIA GeForce RTX 3070 (driver 595.99.02), Ubuntu 26.04, run by jotitadev on this head merged onto main 0615cd2b8 (review):

  • With main's sources and this PR's tests, agc_driver_bda_reads_shadowed_results and _per_build fail with "an address-based build over a heap left the unit shadow's stored results unpublished: the import held the earlier bytes at its submission", and agc_unit_shadow_completion_store with "a CPU store inside a completion over a pending image lost 65532 bytes of the image's results around it".
  • With the change, all four tests pass 3 of 3. That driver keeps imported ranges in the write watch, and lavapipe on the same machine compares them, so the tests ran under both import modes.

Merged with main 0d078f75d3 (c320f283d7, the head, no conflicts), on GitHub's runners (run): the ^agc tests pass on Linux (712, 0 failed), and the suites' only failure is libc's precise_wait timing test. On Windows the only failures are agc_driver_pm4_replay_tool and agc_shader_replay_tool, which fail the same way on that runner for an unrelated branch (run).

Cost in the title: follows as an edit.

Checklist

  • Based on main 7663bc63bb; merges main 0d078f75d3; no other open PR implements the same functions. Overlaps (git merge-tree with main 5d9dcc42d2):
    • #6146 (ours, out-of-place DB expands) adds if (addressable) StoreDepthExpandWrites(context); at the same line at the end of UploadFinish. Keep both, the expand store first, so expanded planes stored into a shadow are published too.
    • #6642 (MarcZX100, the full recorder suite as one CTest entry) edits the Windows test registration a few lines below these tests'. Keep both; the full suite does not run these flag-only tests.
    • #6636 (ours, reuses address-based draw builds whose inputs are unchanged) merges cleanly with this PR but needs one call when both are in. A reused build never runs UploadFinish, where this PR publishes: it takes its space back through ResumeSpace and proves itself in Revalidate. Whichever merges second publishes the space's unit shadows after proveBuild in Revalidate (a PublishSpaceShadows() call), with a test that reuses a draw over a shadowed heap.
    • #6490 (parl0v) retiles more write-backs straight into their slabs. Every slab retile still ends in MarkShadowed, so this publishes them for pointer reads the same way.
    • #6457 and #6479 (ours) change how heaps are imported. The publish covers a guest span, so it covers every import inside it.
  • 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
  • Unblocks: PPSA01556 #5169 (stop 24: the title menu drawn over gameplay)
  • GPUs tested: Mesa lavapipe (CPU Vulkan), Ubuntu 24.04; NVIDIA GeForce RTX 3070 Laptop GPU (driver 617.42), Windows 11; NVIDIA GeForce RTX 3070 (driver 595.99.02), Ubuntu 26.04 (jotitadev)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4883458398 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6682). Originally posted by [EagleBearerYS](https://github.com/EagleBearerYS) on 2026-10-16T04:24:31Z. --- ### What An address-based build binds the registered heaps in place and does not store the storage results pending in them: the heaps hold every pending image, and storing them all would serialize the build. With unit shadows on, a storage write-back that retiles into a shadow ("storage refresh", "storage image creation") reaches the import only through a publish: a host-facing reader, an eviction, an idle flush. Nothing published before an address-based build, so its pointer reads saw the bytes as of the last publish. In Resident Evil Village (PPSA01556) that is the title menu's last frame, published once by the idle flush at the load and shown dimmed over gameplay. Two paths had the gap: - the per-build path skipped `FlushPending` for the exempt in-place heaps; - with the address-space cache (the default), the heaps live in the cached space's base and never reach the upload loop at all, so `APS5_BDA_FLUSH=1` did not reach them either. `UploadFinish` now publishes the fresh units over the heaps the build maps: the space's base, and the exempt regions of the per-build path. One `AnyShadowedOverlaps` check over their span gates it. - Pending results stay pending; only results already stored into a slab are copied. Pointer reads now see what they see with shadows off. - The copies are recorded into the active recorder's open batch under the device lock, ahead of the build's draw or dispatch. - They are counted under a new publish reason, `address`, in the `[storage]` line. **A CPU store inside a completion action (6ee5a91b2a).** Found by an after-the-fact completeness review, on `main` with or without the rest of this PR. A store a completion action makes was published with `PublishScope::None`, which skips the units it covers partly. Its stamp then marked those units stale, and the next publish dropped them whole: up to 65,532 bytes of results around each such store. Completion stores now publish their partly covered units first, and a store that waited for its batch publishes like any other; the completion's existing `Sync()` orders the copy. ### Tested Linux, Mesa lavapipe, CI's Linux job mirror: - configure, test registration, build and libs pass; - ctest at the fix commit: 1273 of 1278 pass; the 5 failures are network tests that need IPv6, which the machine lacks; - `^agc` at the head: 607 of 608 pass (43 of them skip as expected); the one failure, `agc_driver_preparation_scope_settle`, is a timing flake that also fails on main under the same parallel load and passes alone; - the new tests pass 20 of 20 runs (`--repeat until-fail:10`). - the completion store fix on GitHub's runners ([run](https://github.com/EagleBearerYS/AnyPS5/actions/runs/38861117049)): with its five source files at e82f9f1a52's, `agc_unit_shadow_completion_store` fails in all 3 runs on Linux with the same message, and with them it and 41 neighbouring tests pass 10 runs in a row; the GPU tests skip on the Windows runner. New `agc_driver_bda_reads_shadowed_results` and `agc_driver_bda_reads_shadowed_results_per_build` (`APS5_NO_ADDRESS_SPACE_CACHE=1`). A storage image's write-back retiles into the unit shadow of a registered heap, then an address-based build maps the heap: - on main both fail with "an address-based build over a heap left the unit shadow's stored results unpublished: the import held the earlier bytes at its submission"; - with the fix the import holds the stored results at the build's submission; - a build with nothing shadowed, and a second build with nothing newly retiled, record no copy; - results still pending are not stored by the build. Windows 11, RTX 3070 Laptop GPU (driver 617.42), MinGW build: - both new tests pass 5 runs in a row, with the address-space cache on and off; - with the fix's `GuestBufferMemory.cpp` change reverted, both fail with the same message as on Linux; - the tests' heap is 2 MiB (the second commit), so its Windows import is settled (main settles imports of 1 MiB or more) and keeps the write watch; at 256 KiB both tests skipped on Windows; - this ran with the PR on top of our test tree (main with other open PRs). GitHub's Windows runner has no Vulkan device, so these tests skip there. - the completion store fix (6ee5a91b2a), with the fix on our test tree: `agc_unit_shadow_completion_store` and both tests above pass 5 runs in a row; with its five source files at the parent, only `agc_unit_shadow_completion_store` fails ("a CPU store inside a completion over a pending image lost 65532 bytes of the image's results around it"). Resident Evil Village (PPSA01556), Windows 11, RTX 3070 Laptop GPU (driver 617.42), unit shadows on (the default): - **Before:** on our earlier test tree, at control in the first scene after loading a save, the title menu's foreground (stakes and branches) is drawn dimmed over the room, densest over the lower left, and does not fade. - **After:** on our current test tree (main with this PR and other open PRs), the same save and view at control show no trace of it over ~8 minutes. - The earlier tree is not this PR's base: the same tree without this PR stops earlier in the save load for an unrelated reason (fixed in #6366), so the before is from the tree that reached the scene. Linux, NVIDIA GeForce RTX 3070 (driver 595.99.02), Ubuntu 26.04, run by jotitadev on this head merged onto `main` 0615cd2b8 ([review](https://github.com/boykopovar/AnyPS5/pull/6682#pullrequestreview-5549987050)): - With `main`'s sources and this PR's tests, `agc_driver_bda_reads_shadowed_results` and `_per_build` fail with "an address-based build over a heap left the unit shadow's stored results unpublished: the import held the earlier bytes at its submission", and `agc_unit_shadow_completion_store` with "a CPU store inside a completion over a pending image lost 65532 bytes of the image's results around it". - With the change, all four tests pass 3 of 3. That driver keeps imported ranges in the write watch, and lavapipe on the same machine compares them, so the tests ran under both import modes. Merged with `main` 0d078f75d3 (c320f283d7, the head, no conflicts), on GitHub's runners ([run](https://github.com/EagleBearerYS/AnyPS5/actions/runs/39126258354)): the `^agc` tests pass on Linux (712, 0 failed), and the suites' only failure is libc's `precise_wait` timing test. On Windows the only failures are `agc_driver_pm4_replay_tool` and `agc_shader_replay_tool`, which fail the same way on that runner for an unrelated branch ([run](https://github.com/EagleBearerYS/AnyPS5/actions/runs/39061670036)). Cost in the title: follows as an edit. ### Checklist - [x] Based on `main` 7663bc63bb; merges `main` 0d078f75d3; no other open PR implements the same functions. Overlaps (`git merge-tree` with `main` 5d9dcc42d2): - **#6146** (ours, out-of-place DB expands) adds `if (addressable) StoreDepthExpandWrites(context);` at the same line at the end of `UploadFinish`. Keep both, the expand store first, so expanded planes stored into a shadow are published too. - **#6642** (MarcZX100, the full recorder suite as one CTest entry) edits the Windows test registration a few lines below these tests'. Keep both; the full suite does not run these flag-only tests. - **#6636** (ours, reuses address-based draw builds whose inputs are unchanged) merges cleanly with this PR but needs one call when both are in. A reused build never runs `UploadFinish`, where this PR publishes: it takes its space back through `ResumeSpace` and proves itself in `Revalidate`. Whichever merges second publishes the space's unit shadows after `proveBuild` in `Revalidate` (a `PublishSpaceShadows()` call), with a test that reuses a draw over a shadowed heap. - **#6490** (parl0v) retiles more write-backs straight into their slabs. Every slab retile still ends in `MarkShadowed`, so this publishes them for pointer reads the same way. - **#6457 and #6479** (ours) change how heaps are imported. The publish covers a guest span, so it covers every import inside it. - [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] Unblocks: PPSA01556 #5169 (stop 24: the title menu drawn over gameplay) - [x] GPUs tested: Mesa lavapipe (CPU Vulkan), Ubuntu 24.04; NVIDIA GeForce RTX 3070 Laptop GPU (driver 617.42), Windows 11; NVIDIA GeForce RTX 3070 (driver 595.99.02), Ubuntu 26.04 (jotitadev) - [x] AI-assisted: yes
jotitadev commented 2026-10-16 15:30:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-16T15:30:12Z.

Review: COMMENTED


Linux run on a desktop NVIDIA GPU with the proprietary driver; the description covers lavapipe on Linux and an RTX 3070 Laptop on Windows.

Machine: NVIDIA GeForce RTX 3070, driver 595.99.02, Vulkan 1.4.329, plus lavapipe (Mesa 26.0.3, LLVM 21.1.8) on the same machine. Ubuntu 26.04 (kernel 7.0.0-38), i7-8700, GCC 15.2, Release, BUILD_TESTING=ON. Head 6ee5a91b2 merged onto main 0615cd2b8, clean merge (main did not build at the time, #6784).

GPUs tested: NVIDIA GeForce RTX 3070 (595.99.02), lavapipe (Mesa 26.0.3, LLVM 21.1.8), Ubuntu 26.04

RTX 3070:

  • Test only (the PR's tests and CMake, with Texture, UnitShadow, Recorder.cpp and GuestBufferMemory.cpp from main): agc_driver_bda_reads_shadowed_results and _per_build fail with an address-based build over a heap left the unit shadow's stored results unpublished: the import held the earlier bytes at its submission, and agc_unit_shadow_completion_store fails with a CPU store inside a completion over a pending image lost 65532 bytes of the image's results around it. agc_unit_shadow passes.
  • With the change: all four pass 3/3.
  • On this driver the write-watch probe reports host imports resolve write protection: no ... imported ranges stay watched, while lavapipe reports imported ranges are compared, so the new tests ran under both import modes on Linux.
  • ctest -R "^agc|shader|recompiler" -E "agc_display_buffer_dcc|agc_driver_flip|agc_driver_lds_atomics64|display|flip" -j1 --timeout 60: 616 tests, only agc_driver_store_over_untracked fails, which also fails on unchanged main here (#6347).

lavapipe: the four tests pass.

Not checked: Resident Evil Village or any title, Windows, the address-space cache toggle beyond what the _per_build test sets.

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5549987050 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6682#pullrequestreview-5549987050). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-16T15:30:12Z. **Review:** COMMENTED --- Linux run on a desktop NVIDIA GPU with the proprietary driver; the description covers lavapipe on Linux and an RTX 3070 Laptop on Windows. **Machine:** NVIDIA GeForce RTX 3070, driver 595.99.02, Vulkan 1.4.329, plus lavapipe (Mesa 26.0.3, LLVM 21.1.8) on the same machine. Ubuntu 26.04 (kernel 7.0.0-38), i7-8700, GCC 15.2, Release, `BUILD_TESTING=ON`. Head `6ee5a91b2` merged onto `main` `0615cd2b8`, clean merge (`main` did not build at the time, #6784). GPUs tested: NVIDIA GeForce RTX 3070 (595.99.02), lavapipe (Mesa 26.0.3, LLVM 21.1.8), Ubuntu 26.04 **RTX 3070:** - Test only (the PR's tests and CMake, with `Texture`, `UnitShadow`, `Recorder.cpp` and `GuestBufferMemory.cpp` from `main`): `agc_driver_bda_reads_shadowed_results` and `_per_build` fail with `an address-based build over a heap left the unit shadow's stored results unpublished: the import held the earlier bytes at its submission`, and `agc_unit_shadow_completion_store` fails with `a CPU store inside a completion over a pending image lost 65532 bytes of the image's results around it`. `agc_unit_shadow` passes. - With the change: all four pass 3/3. - On this driver the write-watch probe reports `host imports resolve write protection: no ... imported ranges stay watched`, while lavapipe reports `imported ranges are compared`, so the new tests ran under both import modes on Linux. - `ctest -R "^agc|shader|recompiler" -E "agc_display_buffer_dcc|agc_driver_flip|agc_driver_lds_atomics64|display|flip" -j1 --timeout 60`: 616 tests, only `agc_driver_store_over_untracked` fails, which also fails on unchanged `main` here (#6347). **lavapipe:** the four tests pass. Not checked: Resident Evil Village or any title, Windows, the address-space cache toggle beyond what the `_per_build` test sets. Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
EagleBearerYS commented 2026-10-16 15:34:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-16T15:34:41Z.


@jotitadev thank you for the run on a desktop RTX 3070 with NVIDIA's Linux driver. It covers a case the description didn't: that driver keeps imported ranges in the write watch, while lavapipe compares them, so the new tests now have a red and a green under both import modes. I've added your run to the description's Tested section.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6218954322 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6682#issuecomment-6218954322). Originally posted by [EagleBearerYS](https://github.com/EagleBearerYS) on 2026-10-16T15:34:41Z. --- @jotitadev thank you for the run on a desktop RTX 3070 with NVIDIA's Linux driver. It covers a case the description didn't: that driver keeps imported ranges in the write watch, while lavapipe compares them, so the new tests now have a red and a green under both import modes. I've added your run to the description's Tested section.
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!6682
No description provided.