fix(agc): publish multisample depth over pages only an import window touched #22062

Open
ycbuzi wants to merge 2 commits from upstream-pr/22062 into main
ycbuzi commented 2026-11-17 03:53:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ycbuzi on 2026-11-17T03:53:45Z.


What

Native multisample depth publication threw native multisample depth publication cannot distinguish an unwritten byte from a same-value guest store on pages whose only CPU-side mark came from an import window.

When a host import runs over watched memory, the write tracker re-walks the pages the write watch reports dirty. Pages whose bytes did not change across the import get an ImportWindow stamp: a possible CPU touch, not a store (CheckImportWindow covers this). The block's stored stamp stays put and StoredOver answers false. The tracker still noted those pages in cpuPages, though, and UnchangedSinceLastCollect (the publication's last per-byte check) reads cpuPages. So a host-changed byte that still equalled its snapshot on such a page counted as a possible same-value CPU store, and the read threw.

Main already settles this for pending GPU results: under an import window, a page counts as stored only when its bytes change (see the "Pages under an import window" debt entry). This PR applies the same rule to depth publication:

  • WriteTracker keeps cpuStoredPages, the pages noted as real CPU stores. The pages an import window resolved without a change (and runs walked as ImportWindow) are noted as touches only (noteCpuTouch). cpuPages and every existing query behave as before.
  • StoreUnchangedSinceLastCollect works like UnchangedSinceLastCollect but ignores those touches. PublishToGuest uses it for its last per-byte check. A touched page takes the host result. A real same-value CPU store, before or after the window, still throws.
  • Debt entries for D32S8 publication and import-window pages are updated. A same-value CPU store that lands inside the window itself is overwritten, as it already is for pending results.

Evidence from the title: a temporary diagnostic build (not in this PR) printed the failing byte for PPSA06866 on the Radeon iGPU:

plane 0 of 3 base 0x380480000 bytes 0x1fe0000 htile=1 samples=2 extent 1920x2160 addr 0x382200000 cur 00 snap 00 res ee
page: differs 0 equalResult 0 ambiguous 4096 cpuWrote=1 storedOver=0
gen=110513 stamp=110497 cpuStamp=112281 cpuPage=112281 walkPage=0 noDriverPieces

Every byte of the page was unchanged. The block's stored stamp was older than the capture, and only the CPU stamp was newer, which is the ImportWindow signature.

Tested

Windows 11 (26200), MinGW GCC 15.2.0, Release.

  • agc_write_tracking (new CheckImportWindowTouchIsNotAStore). An unchanged import-window page still fails UnchangedSinceLastCollect but passes StoreUnchangedSinceLastCollect. New bytes inside the window and a later same-value store both read as stored. Untouched pages read as unstored.
  • agc_driver_native_depth_publication: ImportSameValue must now publish the host depth over the touched page. The new ImportThenSameDepth (a same-value CPU store after the window) must keep the guest byte or refuse. SameDepth, Possible, ChangedHull and the other existing cases are unchanged.
  • Vulkan validation A/B, main 521fb7fec4 vs this branch, ctest -R '^(agc_driver_native_multisample_depth|agc_driver_native_depth_.*|agc_write_tracking)$' with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1 and VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, twice per GPU, non-elevated. The layer loaded on both sides (no was not found but was requested lines). There were 0 VUID- errors on main and 0 on the branch, on every GPU. Results were identical on both sides: 31 of 32 passed. agc_driver_native_depth_bda_clear reports Not Run because its executable is a separate target I did not build. driver_queued_fill skips on both sides. The publication test printed the new case (write=30) on all three GPUs on the branch.
  • PPSA06866 Divinity: Original Sin 2 - Definitive Edition, Radeon iGPU, run from a separate copy of the game folder with the lane's PR-stack libraries plus this libSceAgcDriver.prx. Before: abort after 114 s with the error above (reproduced with the diagnostic build). After: the error did not come back, and the game kept running and presenting until the 300 s harness limit stopped it, with no new driver failure in the log.
  • Follow-up 7a78b2aabd: StoreUnchangedSinceLastCollect also ignored import-window touches only on pages with no stored stamp in their 64 KiB block; a touched page beside a CPU-stored page still threw through StoredOver. It now reads only real CPU stores there, and publication asks once per page before the per-byte query. agc_write_tracking checks a store beside a touch. Rebuilt and ran on the same machine (RTX 4070 SUPER): agc_write_tracking* 11/11, agc_driver_native_multisample_depth and agc_driver_native_depth_* 28 passed, driver_queued_fill skipped as on main. The Vulkan validation A/B and the Divinity run above were on 4790a046b9; this change touches no Vulkan calls.

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 (composes with #15941: both change the same else branch of PublishToGuest's byte loop and the D32S8 debt entry; whichever merges second takes the resolution in EagleBearerYS's comment https://github.com/boykopovar/AnyPS5/pull/22062#issuecomment-6941196314, verified by their dry merge bd8f8b7465). Also conflicts as text with #21719 (adds DepthReadCause::Write publication in the same file and debt entry): this PR only changes how an undecided byte's page is classified, so #21719's strict Write path keeps throwing for real same-value stores either way; whichever lands second merges both
  • Fixes: none
  • Unblocks: PPSA06866 #13726
  • GPUs tested: NVIDIA GeForce RTX 4070 SUPER (driver 621.14), NVIDIA GeForce GTX 1650 SUPER (driver 621.14), AMD Radeon(TM) Graphics, Ryzen 9 7900 iGPU (driver 32.0.21030.2001); Windows 11 build 26200
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5350278056 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22062). Originally posted by [ycbuzi](https://github.com/ycbuzi) on 2026-11-17T03:53:45Z. --- ### What Native multisample depth publication threw `native multisample depth publication cannot distinguish an unwritten byte from a same-value guest store` on pages whose only CPU-side mark came from an import window. When a host import runs over watched memory, the write tracker re-walks the pages the write watch reports dirty. Pages whose bytes did not change across the import get an `ImportWindow` stamp: a possible CPU touch, not a store (`CheckImportWindow` covers this). The block's stored stamp stays put and `StoredOver` answers false. The tracker still noted those pages in `cpuPages`, though, and `UnchangedSinceLastCollect` (the publication's last per-byte check) reads `cpuPages`. So a host-changed byte that still equalled its snapshot on such a page counted as a possible same-value CPU store, and the read threw. Main already settles this for pending GPU results: under an import window, a page counts as stored only when its bytes change (see the "Pages under an import window" debt entry). This PR applies the same rule to depth publication: - `WriteTracker` keeps `cpuStoredPages`, the pages noted as real CPU stores. The pages an import window resolved without a change (and runs walked as `ImportWindow`) are noted as touches only (`noteCpuTouch`). `cpuPages` and every existing query behave as before. - `StoreUnchangedSinceLastCollect` works like `UnchangedSinceLastCollect` but ignores those touches. `PublishToGuest` uses it for its last per-byte check. A touched page takes the host result. A real same-value CPU store, before or after the window, still throws. - Debt entries for D32S8 publication and import-window pages are updated. A same-value CPU store that lands inside the window itself is overwritten, as it already is for pending results. Evidence from the title: a temporary diagnostic build (not in this PR) printed the failing byte for PPSA06866 on the Radeon iGPU: ``` plane 0 of 3 base 0x380480000 bytes 0x1fe0000 htile=1 samples=2 extent 1920x2160 addr 0x382200000 cur 00 snap 00 res ee page: differs 0 equalResult 0 ambiguous 4096 cpuWrote=1 storedOver=0 gen=110513 stamp=110497 cpuStamp=112281 cpuPage=112281 walkPage=0 noDriverPieces ``` Every byte of the page was unchanged. The block's stored stamp was older than the capture, and only the CPU stamp was newer, which is the `ImportWindow` signature. ### Tested Windows 11 (26200), MinGW GCC 15.2.0, Release. - `agc_write_tracking` (new `CheckImportWindowTouchIsNotAStore`). An unchanged import-window page still fails `UnchangedSinceLastCollect` but passes `StoreUnchangedSinceLastCollect`. New bytes inside the window and a later same-value store both read as stored. Untouched pages read as unstored. - `agc_driver_native_depth_publication`: `ImportSameValue` must now publish the host depth over the touched page. The new `ImportThenSameDepth` (a same-value CPU store after the window) must keep the guest byte or refuse. `SameDepth`, `Possible`, `ChangedHull` and the other existing cases are unchanged. - Vulkan validation A/B, main 521fb7fec40 vs this branch, `ctest -R '^(agc_driver_native_multisample_depth|agc_driver_native_depth_.*|agc_write_tracking)$'` with `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1` and `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`, twice per GPU, non-elevated. The layer loaded on both sides (no `was not found but was requested` lines). There were 0 `VUID-` errors on main and 0 on the branch, on every GPU. Results were identical on both sides: 31 of 32 passed. `agc_driver_native_depth_bda_clear` reports Not Run because its executable is a separate target I did not build. `driver_queued_fill` skips on both sides. The publication test printed the new case (`write=30`) on all three GPUs on the branch. - PPSA06866 Divinity: Original Sin 2 - Definitive Edition, Radeon iGPU, run from a separate copy of the game folder with the lane's PR-stack libraries plus this `libSceAgcDriver.prx`. Before: abort after 114 s with the error above (reproduced with the diagnostic build). After: the error did not come back, and the game kept running and presenting until the 300 s harness limit stopped it, with no new driver failure in the log. - Follow-up 7a78b2aabdd: `StoreUnchangedSinceLastCollect` also ignored import-window touches only on pages with no stored stamp in their 64 KiB block; a touched page beside a CPU-stored page still threw through `StoredOver`. It now reads only real CPU stores there, and publication asks once per page before the per-byte query. `agc_write_tracking` checks a store beside a touch. Rebuilt and ran on the same machine (RTX 4070 SUPER): `agc_write_tracking*` 11/11, `agc_driver_native_multisample_depth` and `agc_driver_native_depth_*` 28 passed, `driver_queued_fill` skipped as on main. The Vulkan validation A/B and the Divinity run above were on 4790a046b98; this change touches no Vulkan calls. ### 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 (composes with #15941: both change the same `else` branch of `PublishToGuest`'s byte loop and the D32S8 debt entry; whichever merges second takes the resolution in EagleBearerYS's comment https://github.com/boykopovar/AnyPS5/pull/22062#issuecomment-6941196314, verified by their dry merge bd8f8b7465). Also conflicts as text with #21719 (adds `DepthReadCause::Write` publication in the same file and debt entry): this PR only changes how an undecided byte's page is classified, so #21719's strict `Write` path keeps throwing for real same-value stores either way; whichever lands second merges both - [x] Fixes: none - [x] Unblocks: PPSA06866 #13726 - [x] GPUs tested: NVIDIA GeForce RTX 4070 SUPER (driver 621.14), NVIDIA GeForce GTX 1650 SUPER (driver 621.14), AMD Radeon(TM) Graphics, Ryzen 9 7900 iGPU (driver 32.0.21030.2001); Windows 11 build 26200 - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
kurexw commented 2026-11-17 09:35:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by kurexw on 2026-11-17T09:35:23Z.

Review: COMMENTED


Tested on macOS 27.2 on an Apple M4. This is an x86-64 build under Rosetta with Apple clang 21.0.0, on MoltenVK 1.4.2 from the LunarG Vulkan SDK 1.4.363.1.

Method. The base was main at a72186d3cf plus #22056 and #22074, which fix the macOS build of two other targets; both have since merged. I built the base and this PR merged onto it (a clean merge) in two separate build directories. I ran them alternately, base then PR, with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation and VK_LOADER_DEBUG=layer: three runs each:

ctest --test-dir build -R '^agc_driver_native_multisample_depth|^agc_write_tracking|^agc_driver_native_depth_' -V
base (3 runs) This PR (3 runs)
Passed 33 of 35 33 of 35, the same tests
agc_write_tracking Failed Failed, same message
agc_driver_native_depth_publication Failed Failed, same message
Layer inserts per run 64 64
was not found but was requested 0 0
VUID- lines 0 0

There's no regression, but on macOS the two tests this PR changes stop before or after its new cases, at checks the base already fails:

  • agc_write_tracking: it fails with a page only an import window stamped as a possible CPU touch was not listed. That check is in CheckImportWindowOtherThread, which this PR doesn't change. It runs after the new CheckImportWindowTouchIsNotAStore, so the new check passes on macOS.
  • agc_driver_native_depth_publication: it fails with AGC graphics: guest writes raced native multisample depth publication, in an early case right after samples=2 write=3 (the loop at NativeMultisampleDepth.cpp:4672). The ImportSameValue and ImportThenSameDepth cases at line 4693 are never reached. So on macOS this test can't confirm the publication change in either direction.

I didn't run a title.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5936016941 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22062#pullrequestreview-5936016941). Originally posted by [kurexw](https://github.com/kurexw) on 2026-11-17T09:35:23Z. **Review:** COMMENTED --- Tested on macOS 27.2 on an Apple M4. This is an x86-64 build under Rosetta with Apple clang 21.0.0, on MoltenVK 1.4.2 from the LunarG Vulkan SDK 1.4.363.1. **Method.** The base was `main` at a72186d3cf plus #22056 and #22074, which fix the macOS build of two other targets; both have since merged. I built the base and this PR merged onto it (a clean merge) in two separate build directories. I ran them alternately, base then PR, with `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1`, `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation` and `VK_LOADER_DEBUG=layer`: three runs each: ``` ctest --test-dir build -R '^agc_driver_native_multisample_depth|^agc_write_tracking|^agc_driver_native_depth_' -V ``` | | base (3 runs) | This PR (3 runs) | | --- | --- | --- | | Passed | 33 of 35 | 33 of 35, the same tests | | `agc_write_tracking` | Failed | Failed, same message | | `agc_driver_native_depth_publication` | Failed | Failed, same message | | Layer inserts per run | 64 | 64 | | `was not found but was requested` | 0 | 0 | | `VUID-` lines | 0 | 0 | There's no regression, but on macOS the two tests this PR changes stop before or after its new cases, at checks the base already fails: - **`agc_write_tracking`**: it fails with `a page only an import window stamped as a possible CPU touch was not listed`. That check is in `CheckImportWindowOtherThread`, which this PR doesn't change. It runs after the new `CheckImportWindowTouchIsNotAStore`, so the new check passes on macOS. - **`agc_driver_native_depth_publication`**: it fails with `AGC graphics: guest writes raced native multisample depth publication`, in an early case right after `samples=2 write=3` (the loop at `NativeMultisampleDepth.cpp:4672`). The `ImportSameValue` and `ImportThenSameDepth` cases at line 4693 are never reached. So on macOS this test can't confirm the publication change in either direction. I didn't run a title.
MarcZX10 commented 2026-11-19 01:17:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-19T01:17:03Z.

Review: COMMENTED


Reviewed — no blocking findings

The reviewed changes appear consistent with the stated import-window behavior; I could not independently run the reported checks, so a formal approval is not justified.

What I ran

Reviewed head 7a78b2aabdd8a22fe3eb2dde2f6b348c9bd23638 using repo_read.py to inspect the prepared diff and relevant code at that pinned head. No tests or builds were run. The author-reported results are not results from this review.

Results

Check Result Note
Diff and targeted code review passed Inspected all six changed files
Tests and build not run Author-reported results not independently verified
Negative control not run Could not modify code or run tests

Findings

Blocking

None.

Non-blocking

None.

Sources

Not verified

Tests, builds, Vulkan validation, and the reported game run were not independently verified. Reviewed files: GuestMemory.hpp, GuestMemory.cpp, DepthSurface.cpp, WriteTracking.cpp, NativeMultisampleDepth.cpp, and docs/dev/debt/libSceAgcDriver.md. All six are marked included in the manifest; targeted relevant hunks and surrounding code were read, not every line of each full file.

To get this to a good state

Nothing is required. Optional: run the reported tracker and depth-publication tests on the reviewed head and attach the results.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5967871416 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22062#pullrequestreview-5967871416). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-19T01:17:03Z. **Review:** COMMENTED --- # Reviewed — no blocking findings The reviewed changes appear consistent with the stated import-window behavior; I could not independently run the reported checks, so a formal approval is not justified. ## What I ran Reviewed head `7a78b2aabdd8a22fe3eb2dde2f6b348c9bd23638` using `repo_read.py` to inspect the prepared diff and relevant code at that pinned head. No tests or builds were run. The author-reported results are not results from this review. ## Results | Check | Result | Note | |---|---|---| | Diff and targeted code review | passed | Inspected all six changed files | | Tests and build | not run | Author-reported results not independently verified | | Negative control | not run | Could not modify code or run tests | ## Findings ### Blocking None. ### Non-blocking None. ## Sources - [GuestMemory.cpp at reviewed head](https://github.com/boykopovar/AnyPS5/blob/7a78b2aabdd8a22fe3eb2dde2f6b348c9bd23638/core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp) - [DepthSurface.cpp at reviewed head](https://github.com/boykopovar/AnyPS5/blob/7a78b2aabdd8a22fe3eb2dde2f6b348c9bd23638/core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp) ## Not verified Tests, builds, Vulkan validation, and the reported game run were not independently verified. Reviewed files: `GuestMemory.hpp`, `GuestMemory.cpp`, `DepthSurface.cpp`, `WriteTracking.cpp`, `NativeMultisampleDepth.cpp`, and `docs/dev/debt/libSceAgcDriver.md`. All six are marked included in the manifest; targeted relevant hunks and surrounding code were read, not every line of each full file. ## To get this to a good state Nothing is required. Optional: run the reported tracker and depth-publication tests on the reviewed head and attach the results.
ligmaSec commented 2026-12-03 18:41:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T18:41:42Z.

Review: COMMENTED


CheckImportWindowTouchIsNotAStore uses base + 0x2010 to place a later store on a different page from base + 0x100. The macOS write watch uses getpagesize() and reports whole host pages. On a host exposing 16 KiB pages, these addresses are on the same watch page, so the test cannot expect one range to count as stored and the other to remain a touch. The fixture runs without a platform guard. Could it use the host watch granularity for those offsets while still keeping both pages in the same tracker block?

Source review of 7a78b2aabd. The native depth and write-tracker files conflict with current main, and I have no native macOS result for the fixture.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6176169949 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22062#pullrequestreview-6176169949). Originally posted by [ligmaSec](https://github.com/ligmaSec) on 2026-12-03T18:41:42Z. **Review:** COMMENTED --- `CheckImportWindowTouchIsNotAStore` uses `base + 0x2010` to place a later store on a different page from `base + 0x100`. The macOS write watch uses `getpagesize()` and reports whole host pages. On a host exposing 16 KiB pages, these addresses are on the same watch page, so the test cannot expect one range to count as stored and the other to remain a touch. The fixture runs without a platform guard. Could it use the host watch granularity for those offsets while still keeping both pages in the same tracker block? Source review of `7a78b2aabd`. The native depth and write-tracker files conflict with current `main`, and I have no native macOS result for the fixture. AI-assisted: yes.
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/22062:upstream-pr/22062'
git switch 'upstream-pr/22062'

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