fix(agc): import a native multisample D32S8 target over uneven planes once its first draw wrote every sample #16363

Merged
hugodearaujo merged 5 commits from upstream-pr/16363 into main 2026-11-10 10:42:41 +00:00
hugodearaujo commented 2026-11-06 12:04:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by hugodearaujo on 2026-11-06T12:04:15Z.


What

Assassin's Creed Mirage (PPSA13960) reuses the memory of its 4-sample D32S8 depth target (no HTILE) every frame:

  1. A compute chain writes an R11G11B10F mip chain over both planes after the depth passes.
  2. On the next frame the depth target is bound again over those results, at that frame's dynamic resolution (1872x1056, 1772x996, 1720x968...).
  3. The import (prepareUniformPlaneSampling) finds planes that do not hold one value each and records native multisample depth plane without HTILE does not hold one depth value in [0, 1]. The target is still drawn.
  4. Later, the compute that reads mip 0 of the new chain at the same address throws that refusal. It does that through the depth owner lookup in DepthSurfaceTexture.

The first draw of each frame on that target is a full-screen triangle. It has depth test ALWAYS with depth writes on, and on both faces stencil compare ALWAYS, pass op REPLACE, reference 0 and write mask 0xff. DB_RENDER_CONTROL is 0x60 and the scissor is the target extent. On the console that draw overwrites every sample, so the guest bytes under the planes no longer matter. But the registers alone cannot show that the geometry covers every sample.

This change proves it after the draw instead:

  • Mark the candidate. DepthSurfaceViewWithStencilWriteIntent takes the stencil value that the draw writes to every sample it covers. Draw.cpp passes it only for depth ALWAYS with writes and no depth bounds, plus stencil ALWAYS/REPLACE with write mask 0xff and one reference on both faces. If such a draw creates an owner whose import was refused only because the planes are uneven, the owner starts with stencil ~reference in every sample. The refusal stays recorded.
  • Prove it after the draw. The proof runs at the owner's next use after that draw: its next attachment, a check in CheckCurrent, or a guest access over its planes in RequireNoResidentDepthRead_nid_no_patch. The driver syncs the recorder and stores pending storage results over the planes. Then it reads the stencil samples back, with the readback PublishToGuest uses (now a shared helper). If every sample holds the reference, every sample passed that draw's tests, so its depth was written too.
  • Import on success. If the planes are also unchanged since the import, the refusal is dropped. The owner gets its depth guards and its publication capture, like an owner over uniform planes (#15688). The padding keeps the guest bytes.
  • Refuse otherwise, as today. That covers a sample the draw did not reach (it still holds ~reference), another stencil value, guest writes, and storage results stored over the planes since the import.

The debt entry for D32S8 without HTILE now says which uneven planes are imported.

Cost: one proof per created owner, which is a recorder sync plus a readback of the stencil plane (7 MB at 1772x996x4).

Tested

Linux 7.2.11, AMD Radeon RX 9070 XT, RADV (Mesa 26.2.6), Release with tests.

  • New agc_driver_native_depth_overwritten_planes (--overwritten-planes), at 2, 4 and 8 samples, on a 200x130 D32S8 target without HTILE. Its planes hold mixed words (5.5e7 and NaN patterns among them) and mixed stencil bytes.
    • The first draw writes every sample with stencil 0x21. Then one of:
      • the next draw attaches and draws 193x129. Sampling returns that draw inside 193x129 and the first draw elsewhere. A guest read publishes all samples over the planes and keeps the padding bytes.
      • a sampling lookup comes first. Same result.
      • a guest access over the planes (RequireNoMultisampleTarget) comes first. It publishes the first draw's samples.
    • Each of these still refuses with the title message:
      • a first draw that covers 193x129 only;
      • a first draw that writes stencil 0x22;
      • a CPU write to the depth plane after the first draw;
      • storage results recorded over the depth plane before the proof. They are stored to the plane, and the refusal stays.
  • Negative control: the test needs the new argument of DepthSurfaceViewWithStencilWriteIntent, so it cannot build on #15688 alone. A mutation of the fix stands in for the base instead. Each was made locally and reverted, and each fails the test at the expected case:
    • never marking the candidate (the base behaviour): the first case, with the title message;
    • accepting the proof without comparing the stencil samples: the 193x129 first draw;
    • dropping the unchanged-planes check: the CPU write;
    • not storing pending results before the proof: the storage results case;
    • not proving on guest access: the guest-access case.
  • Validation layer, paired, same machine (VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, ANYPS5_NO_SHADER_CACHE=1, ANYPS5_REQUIRE_VULKAN=1, ctest -V -R "native_depth|native_multisample|depth_storage|depth_surface|agc_storage_|multisample_guest|repeat_storage_guard|cached_image|storage_flush_ordering|storage_one_slice|storage_read_during|storage_write_back|msaa_address_on_plane"):
    • #15688 (fa590e435a): 54 of 54;
    • this change: 55 of 55.
    • The loader inserted the layer in both runs. Neither log has a VUID- line or "was not found but was requested". Both have the same 20 WARNING-VkImageSubresourceRange-layerCount-compatibility lines.
  • tools/check_conventions.py --base fa590e435a: passes.
  • Title: Assassin's Creed Mirage (PPSA13960): title, New Game, Assassin, Full Synchronization Off, on main 5299939ecf + #13963 (7d548223bd) + #15707 (a8c5df4e69, with #15690 and #15688), 720 s each:
    • Without the four changes: the run stopped at 484 s on the title's compute shader 0x10b4c8ad00: AGC graphics: native multisample depth plane without HTILE does not hold one depth value in [0, 1].
    • With this change and the three others (#16364 pending units, #16365 single-sample view, and a fourth that starts a new owner under pending storage results, see below), two runs. Neither stops on the title message, and both get past the point where the run above stopped:
      • one stopped at 452 s on AGC graphics: a native multisample depth attachment over the planes of a host-written owner of another identity is not implemented, a separate stop;
      • one ran on into the intro cinematic and was killed at 482 s by the local VRAM guard (817 MiB of VRAM free).
    • With #15941 (7d377e40ba) in place of the fourth change, two runs, neither stops on the title message:
      • one stopped at 468 s on compute shader 0x10009c9600: AGC graphics: a texture read of 0x13bc1a0000+0x800000 overlaps multisampled color target 0x13bada0000+0x1860000 (4 samples), whose samples are only on the host: guest access to it is not implemented, a separate multisampled colour stop;
      • one showed a corrupted frame from about 451 s and was killed at 496 s by the VRAM guard (1244 MiB free).
    • With #15941 alone (none of the four changes): the run stopped at 456 s on the title message, as without it.
    • The fourth change is now its own PR, #17890. It had been left out because #15941 (at 7d377e40ba) retired a published owner at the storage access that leaves results pending over its planes. Since 9452ca6e35 (head d4583e9ccd), #15941 retires an owner at a Reuse access only when that access's publication took a guest byte. An owner that was already published has nothing to publish there, so #15941 keeps it, and the next bind reuses it:
      • #17890's test, with its storage access passing DepthReadCause::Reuse, now fails on #15941 without the fourth change: an overwriting draw over a published owner under storage results did not start a new owner.
      • main 6b58dfa474 + #13963 + #16364 + this PR + #16365 + #15941 (d4583e9ccd) + #16974: 5 of 5 runs stopped at 73-77 s, before the title screen, on compute shader 0x1000810a00: AGC graphics: native multisample depth publication over pending storage image writes is not implemented. With the fourth change added, 6 of 6 runs got through the title and the menu into New Game. They stopped later (448-573 s) on other messages or the local VRAM guard.
      • Without #15941 (main 6719b01bf3 + #13963 + this PR + #16364 + #16365): 3 of 3 runs stopped at 73-81 s on the same message. With #17890, 3 of 3 ran their full 300 s through New Game, Assassin and Full Synchronization Off into the opening scene.
    • These match the earlier runs of the combined change on main 5b1d381d5a: stops at 497 s and 456 s on the attachment message, the VRAM guard at 470 s, and the multisampled colour stop at 485 s. A rerun of that earlier build here stopped at 464 s on the colour stop.

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 (#15688 is merged)
  • Fixes: none
  • Unblocks: PPSA13960 together with the changes listed under Tested
  • GPUs tested: AMD Radeon RX 9070 XT, RADV Mesa 26.2.6, Linux 7.2.11
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5187539410 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16363). Originally posted by [hugodearaujo](https://github.com/hugodearaujo) on 2026-11-06T12:04:15Z. --- ### What Assassin's Creed Mirage (PPSA13960) reuses the memory of its 4-sample D32S8 depth target (no HTILE) every frame: 1. A compute chain writes an R11G11B10F mip chain over both planes after the depth passes. 2. On the next frame the depth target is bound again over those results, at that frame's dynamic resolution (1872x1056, 1772x996, 1720x968...). 3. The import (`prepareUniformPlaneSampling`) finds planes that do not hold one value each and records `native multisample depth plane without HTILE does not hold one depth value in [0, 1]`. The target is still drawn. 4. Later, the compute that reads mip 0 of the new chain at the same address throws that refusal. It does that through the depth owner lookup in `DepthSurfaceTexture`. The first draw of each frame on that target is a full-screen triangle. It has depth test ALWAYS with depth writes on, and on both faces stencil compare ALWAYS, pass op REPLACE, reference 0 and write mask 0xff. `DB_RENDER_CONTROL` is 0x60 and the scissor is the target extent. On the console that draw overwrites every sample, so the guest bytes under the planes no longer matter. But the registers alone cannot show that the geometry covers every sample. This change proves it after the draw instead: - **Mark the candidate.** `DepthSurfaceViewWithStencilWriteIntent` takes the stencil value that the draw writes to every sample it covers. `Draw.cpp` passes it only for depth ALWAYS with writes and no depth bounds, plus stencil ALWAYS/REPLACE with write mask 0xff and one reference on both faces. If such a draw creates an owner whose import was refused only because the planes are uneven, the owner starts with stencil `~reference` in every sample. The refusal stays recorded. - **Prove it after the draw.** The proof runs at the owner's next use after that draw: its next attachment, a check in `CheckCurrent`, or a guest access over its planes in `RequireNoResidentDepthRead_nid_no_patch`. The driver syncs the recorder and stores pending storage results over the planes. Then it reads the stencil samples back, with the readback `PublishToGuest` uses (now a shared helper). If every sample holds the reference, every sample passed that draw's tests, so its depth was written too. - **Import on success.** If the planes are also unchanged since the import, the refusal is dropped. The owner gets its depth guards and its publication capture, like an owner over uniform planes (#15688). The padding keeps the guest bytes. - **Refuse otherwise, as today.** That covers a sample the draw did not reach (it still holds `~reference`), another stencil value, guest writes, and storage results stored over the planes since the import. The debt entry for D32S8 without HTILE now says which uneven planes are imported. Cost: one proof per created owner, which is a recorder sync plus a readback of the stencil plane (7 MB at 1772x996x4). ### Tested Linux 7.2.11, AMD Radeon RX 9070 XT, RADV (Mesa 26.2.6), Release with tests. - New `agc_driver_native_depth_overwritten_planes` (`--overwritten-planes`), at 2, 4 and 8 samples, on a 200x130 D32S8 target without HTILE. Its planes hold mixed words (5.5e7 and NaN patterns among them) and mixed stencil bytes. - The first draw writes every sample with stencil 0x21. Then one of: - the next draw attaches and draws 193x129. Sampling returns that draw inside 193x129 and the first draw elsewhere. A guest read publishes all samples over the planes and keeps the padding bytes. - a sampling lookup comes first. Same result. - a guest access over the planes (`RequireNoMultisampleTarget`) comes first. It publishes the first draw's samples. - Each of these still refuses with the title message: - a first draw that covers 193x129 only; - a first draw that writes stencil 0x22; - a CPU write to the depth plane after the first draw; - storage results recorded over the depth plane before the proof. They are stored to the plane, and the refusal stays. - Negative control: the test needs the new argument of `DepthSurfaceViewWithStencilWriteIntent`, so it cannot build on #15688 alone. A mutation of the fix stands in for the base instead. Each was made locally and reverted, and each fails the test at the expected case: - never marking the candidate (the base behaviour): the first case, with the title message; - accepting the proof without comparing the stencil samples: the 193x129 first draw; - dropping the unchanged-planes check: the CPU write; - not storing pending results before the proof: the storage results case; - not proving on guest access: the guest-access case. - Validation layer, paired, same machine (`VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`, `ANYPS5_NO_SHADER_CACHE=1`, `ANYPS5_REQUIRE_VULKAN=1`, `ctest -V -R "native_depth|native_multisample|depth_storage|depth_surface|agc_storage_|multisample_guest|repeat_storage_guard|cached_image|storage_flush_ordering|storage_one_slice|storage_read_during|storage_write_back|msaa_address_on_plane"`): - #15688 (fa590e435a): 54 of 54; - this change: 55 of 55. - The loader inserted the layer in both runs. Neither log has a `VUID-` line or "was not found but was requested". Both have the same 20 `WARNING-VkImageSubresourceRange-layerCount-compatibility` lines. - `tools/check_conventions.py --base fa590e435a`: passes. - Title: Assassin's Creed Mirage (PPSA13960): title, New Game, Assassin, Full Synchronization Off, on `main` 5299939ecf + #13963 (7d548223bd) + #15707 (a8c5df4e69, with #15690 and #15688), 720 s each: - Without the four changes: the run stopped at 484 s on the title's `compute shader 0x10b4c8ad00: AGC graphics: native multisample depth plane without HTILE does not hold one depth value in [0, 1]`. - With this change and the three others (#16364 pending units, #16365 single-sample view, and a fourth that starts a new owner under pending storage results, see below), two runs. Neither stops on the title message, and both get past the point where the run above stopped: - one stopped at 452 s on `AGC graphics: a native multisample depth attachment over the planes of a host-written owner of another identity is not implemented`, a separate stop; - one ran on into the intro cinematic and was killed at 482 s by the local VRAM guard (817 MiB of VRAM free). - With #15941 (7d377e40ba) in place of the fourth change, two runs, neither stops on the title message: - one stopped at 468 s on `compute shader 0x10009c9600: AGC graphics: a texture read of 0x13bc1a0000+0x800000 overlaps multisampled color target 0x13bada0000+0x1860000 (4 samples), whose samples are only on the host: guest access to it is not implemented`, a separate multisampled colour stop; - one showed a corrupted frame from about 451 s and was killed at 496 s by the VRAM guard (1244 MiB free). - With #15941 alone (none of the four changes): the run stopped at 456 s on the title message, as without it. - The fourth change is now its own PR, #17890. It had been left out because #15941 (at 7d377e40ba) retired a published owner at the storage access that leaves results pending over its planes. Since 9452ca6e35 (head d4583e9ccd), #15941 retires an owner at a `Reuse` access only when that access's publication took a guest byte. An owner that was already published has nothing to publish there, so #15941 keeps it, and the next bind reuses it: - #17890's test, with its storage access passing `DepthReadCause::Reuse`, now fails on #15941 without the fourth change: `an overwriting draw over a published owner under storage results did not start a new owner`. - `main` 6b58dfa474 + #13963 + #16364 + this PR + #16365 + #15941 (d4583e9ccd) + #16974: 5 of 5 runs stopped at 73-77 s, before the title screen, on `compute shader 0x1000810a00: AGC graphics: native multisample depth publication over pending storage image writes is not implemented`. With the fourth change added, 6 of 6 runs got through the title and the menu into New Game. They stopped later (448-573 s) on other messages or the local VRAM guard. - Without #15941 (`main` 6719b01bf3 + #13963 + this PR + #16364 + #16365): 3 of 3 runs stopped at 73-81 s on the same message. With #17890, 3 of 3 ran their full 300 s through New Game, Assassin and Full Synchronization Off into the opening scene. - These match the earlier runs of the combined change on `main` 5b1d381d5a: stops at 497 s and 456 s on the attachment message, the VRAM guard at 470 s, and the multisampled colour stop at 485 s. A rerun of that earlier build here stopped at 464 s on the colour stop. ### 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 (#15688 is merged) - [x] Fixes: none - [x] Unblocks: PPSA13960 together with the changes listed under Tested - [x] GPUs tested: AMD Radeon RX 9070 XT, RADV Mesa 26.2.6, Linux 7.2.11 - [x] AI-assisted: yes
gabichuuuuu commented 2026-11-07 17:40:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by gabichuuuuu on 2026-11-07T17:40:03Z.

Review: COMMENTED


Windows check of head 92ff7c307f, merged onto main 4e44ed59b2 (clean merge), with main from the same build directory as the control.

Setup: Windows 11 x64, WinLibs GCC 15.2.0 r7, Release, full build. ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 ctest -R '^agc_driver_native_depth_', 3 runs per GPU on each side.

NVIDIA laptop GPU, driver 610 Intel iGPU, same machine
main 3 of 3 runs pass 3 of 3 runs fail stencil_view, uniform_planes and publication
this PR 3 of 3 runs pass (20 tests) the same three, plus publication_without_htile, 3 of 3
  • The new agc_driver_native_depth_overwritten_planes passes in every run on both GPUs.
  • publication_without_htile is not from this change: it comes with the #15688 commits this branch merges. On the Intel iGPU it fails with a written D32S8 owner without HTILE did not publish its stencil samples and padding, the same D32S8 stencil pattern as the three tests that already fail on main there, and it passes on the NVIDIA GPU. I'm looking into that Intel failure separately; it doesn't block this PR.
  • Not run with VK_LAYER_KHRONOS_validation.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5814054327 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16363#pullrequestreview-5814054327). Originally posted by [gabichuuuuu](https://github.com/gabichuuuuu) on 2026-11-07T17:40:03Z. **Review:** COMMENTED --- Windows check of head `92ff7c307f`, merged onto `main` `4e44ed59b2` (clean merge), with `main` from the same build directory as the control. **Setup:** Windows 11 x64, WinLibs GCC 15.2.0 r7, Release, full build. `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 ctest -R '^agc_driver_native_depth_'`, 3 runs per GPU on each side. | | NVIDIA laptop GPU, driver 610 | Intel iGPU, same machine | |---|---|---| | `main` | 3 of 3 runs pass | 3 of 3 runs fail `stencil_view`, `uniform_planes` and `publication` | | this PR | 3 of 3 runs pass (20 tests) | the same three, plus `publication_without_htile`, 3 of 3 | - The new `agc_driver_native_depth_overwritten_planes` passes in every run on both GPUs. - `publication_without_htile` is not from this change: it comes with the #15688 commits this branch merges. On the Intel iGPU it fails with `a written D32S8 owner without HTILE did not publish its stencil samples and padding`, the same D32S8 stencil pattern as the three tests that already fail on `main` there, and it passes on the NVIDIA GPU. I'm looking into that Intel failure separately; it doesn't block this PR. - Not run with `VK_LAYER_KHRONOS_validation`. 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!16363
No description provided.