feat(agc): reuse a native multisample colour target and honour guest HTILE clears #6808

Open
KingDarkHN wants to merge 5 commits from upstream-pr/6808 into main
KingDarkHN commented 2026-10-16 12:53:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by KingDarkHN on 2026-10-16T12:53:36Z.


What

Sonic Superstars (PPSA06888) reaches the menu, but as soon as a level starts the emulator aborts
because it renders into a native multisampled colour target and then reuses that guest memory
for something else while the driver still guards it as a resident target (issue #5933). This branch
builds on #6297 and #6300 (its first three commits) and adds:

  • Drop a reused multisampled colour guard in RequireNoMultisampleTarget instead of throwing, via
    the new retireGuardForAddress (issue #5933).
  • Honour a guest HTILE fast clear the driver has no producer note for when the whole HTILE proves
    the surface's clear value and neither the depth nor the stencil plane changed.
  • Retire a depth surface only over the bytes its plane actually stores. The tiled footprint rounds
    the plane up to whole 128x128 blocks, so a neighbouring allocation could land in the padding and
    wrongly retire a surface it never reused.
  • Accept a stencil plane whose clear state is in the raw plane when HTILE stencil metadata is
    disabled (TILE_STENCIL_DISABLE), and accept a clear-proven HTILE without ITERATE_256 or pipe
    alignment.

A guest read over a resident native multisample depth guard is not retired: it keeps
refusing (sample-preserving guest publication of native multisample depth is not implemented),
matching the contract of #6727 for an unwritten surface, until sample-preserving publication of the
depth, stencil and HTILE planes to guest memory exists. The read-site classification, whole-fill
HTILE note and exact-plane overlap work are intended to be rebased onto #6727 once it lands;
written-owner publication will be a separate change with its own regression. With this branch Sonic
Superstars aborts on a register read over a written depth owner — the documented follow-up.

Tested

  • OS: Omarchy (Arch Linux), kernel 7.2.3.
  • GPU: NVIDIA GeForce RTX 5060 Ti, driver 610.57.04.
  • Homebrew: n/a.
  • Tests: agc_driver_native_multisample_depth (a metadata-only HTILE write with no producer note
    must be served as a fast clear; a reuse read over a resident depth guard must refuse and leave the
    owner resident), agc_driver_depth_fast_clear, agc_driver_depth_fast_clear_submit,
    agc_driver_depth_surface_last_writer and agc_driver_depth_storage_reuse pass. Full
    ctest -R agc_driver is at 98% with the same pre-existing failures as the base commit; none are
    introduced (worker_failure_log also fails identically with this branch stashed).

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: #6297, #6300
  • Related: #6727 (unwritten depth retirement), #5933 (reused colour target)
  • Unblocks: partial — PPSA06888 (Sonic Superstars) still needs sample-preserving depth publication
  • GPUs tested: NVIDIA GeForce RTX 5060 Ti, driver 610.57.04, Omarchy (Arch Linux), kernel 7.2.3
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4888651840 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6808). Originally posted by [KingDarkHN](https://github.com/KingDarkHN) on 2026-10-16T12:53:36Z. --- ### What Sonic Superstars (PPSA06888) reaches the menu, but as soon as a level starts the emulator aborts because it renders into a native multisampled **colour** target and then reuses that guest memory for something else while the driver still guards it as a resident target (issue #5933). This branch builds on #6297 and #6300 (its first three commits) and adds: - Drop a reused multisampled colour guard in `RequireNoMultisampleTarget` instead of throwing, via the new `retireGuardForAddress` (issue #5933). - Honour a guest HTILE fast clear the driver has no producer note for when the whole HTILE proves the surface's clear value and neither the depth nor the stencil plane changed. - Retire a depth surface only over the bytes its plane actually stores. The tiled footprint rounds the plane up to whole 128x128 blocks, so a neighbouring allocation could land in the padding and wrongly retire a surface it never reused. - Accept a stencil plane whose clear state is in the raw plane when HTILE stencil metadata is disabled (`TILE_STENCIL_DISABLE`), and accept a clear-proven HTILE without ITERATE_256 or pipe alignment. A guest read over a resident native multisample **depth** guard is **not** retired: it keeps refusing (`sample-preserving guest publication of native multisample depth is not implemented`), matching the contract of #6727 for an unwritten surface, until sample-preserving publication of the depth, stencil and HTILE planes to guest memory exists. The read-site classification, whole-fill HTILE note and exact-plane overlap work are intended to be rebased onto #6727 once it lands; written-owner publication will be a separate change with its own regression. With this branch Sonic Superstars aborts on a register read over a written depth owner — the documented follow-up. ### Tested - OS: Omarchy (Arch Linux), kernel 7.2.3. - GPU: NVIDIA GeForce RTX 5060 Ti, driver 610.57.04. - Homebrew: n/a. - Tests: `agc_driver_native_multisample_depth` (a metadata-only HTILE write with no producer note must be served as a fast clear; a reuse read over a resident depth guard must refuse and leave the owner resident), `agc_driver_depth_fast_clear`, `agc_driver_depth_fast_clear_submit`, `agc_driver_depth_surface_last_writer` and `agc_driver_depth_storage_reuse` pass. Full `ctest -R agc_driver` is at 98% with the same pre-existing failures as the base commit; none are introduced (`worker_failure_log` also fails identically with this branch stashed). ### 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: #6297, #6300 - [x] Related: #6727 (unwritten depth retirement), #5933 (reused colour target) - [x] Unblocks: partial — PPSA06888 (Sonic Superstars) still needs sample-preserving depth publication - [x] GPUs tested: NVIDIA GeForce RTX 5060 Ti, driver 610.57.04, Omarchy (Arch Linux), kernel 7.2.3 - [x] AI-assisted: yes
MarcZX10 commented 2026-10-16 13:04:11 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-16T13:04:11Z.


I compared this head with open #6727 because both replace RequireNoResidentDepthRead in DepthSurface.cpp. #6727 tracks host writes (NoteDepthSurfaceWrite, CopyAspectFrom, store-back) and only retires a guard on a guest read when hostWritten is false. In this PR’s replacement, a guest reuse read retires the owner when attachmentActive is false, but I don’t see an equivalent hostWritten check. Those conditions can differ for a native depth surface that was written by the host and is no longer the current attachment. Could you coordinate with #6727 and preserve that refusal (or explain why this reuse path proves the guest memory is current), with a regression covering a host-written inactive owner? The two heads touch the same guard/lifecycle code, so they should be reviewed together before either merges.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6216112684 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6808#issuecomment-6216112684). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-16T13:04:11Z. --- I compared this head with open #6727 because both replace `RequireNoResidentDepthRead` in `DepthSurface.cpp`. #6727 tracks host writes (`NoteDepthSurfaceWrite`, `CopyAspectFrom`, store-back) and only retires a guard on a guest read when `hostWritten` is false. In this PR’s replacement, a guest reuse read retires the owner when `attachmentActive` is false, but I don’t see an equivalent `hostWritten` check. Those conditions can differ for a native depth surface that was written by the host and is no longer the current attachment. Could you coordinate with #6727 and preserve that refusal (or explain why this reuse path proves the guest memory is current), with a regression covering a host-written inactive owner? The two heads touch the same guard/lifecycle code, so they should be reviewed together before either merges.
MarcZX10 commented 2026-10-16 13:14:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-16T13:14:30Z.

Review: CHANGES_REQUESTED


The updated head still has this correctness gap at RequireNoResidentDepthRead_nid_no_patch: once an overlapping guard is inactive as an attachment, it retires the owning surface without checking whether the host image contains writes that have not been published to guest memory. retire() only marks the owner inactive and erases the guards; it does not copy the host depth/HTILE contents back. An inactive owner can therefore still have newer host data, so a guest read after reuse can observe stale bytes. The related open #6727 tracks hostWritten and refuses this transition for a written owner. Please preserve the same refusal (or provide a path that publishes the written data first), and add a regression that writes the depth target on the host, makes it inactive, then attempts the guest reuse read.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5548260018 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6808#pullrequestreview-5548260018). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-16T13:14:30Z. **Review:** CHANGES_REQUESTED --- The updated head still has this correctness gap at `RequireNoResidentDepthRead_nid_no_patch`: once an overlapping guard is inactive as an attachment, it retires the owning surface without checking whether the host image contains writes that have not been published to guest memory. `retire()` only marks the owner inactive and erases the guards; it does not copy the host depth/HTILE contents back. An inactive owner can therefore still have newer host data, so a guest read after reuse can observe stale bytes. The related open #6727 tracks `hostWritten` and refuses this transition for a written owner. Please preserve the same refusal (or provide a path that publishes the written data first), and add a regression that writes the depth target on the host, makes it inactive, then attempts the guest reuse read.
KingDarkHN commented 2026-10-16 13:32:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by KingDarkHN on 2026-10-16T13:32:58Z.


You're right about the underlying gap: retire() drops the owner without copying the host depth/stencil/HTILE image back, so a guest read that means to observe the rendered samples can see stale bytes. I tried your suggestion before replying.

I added the same hostWritten notion #6727 uses — set from draws with depth writes or stencil writes on both the plain and cached-recipe draw paths, from CopyAspectFrom, and from storage write-back, with host clears after a proven guest HTILE clear not counted — and made the overlapping owner refuse. The suite stays green, but the title then aborts on a real reuse site:

[gpu] driver failure: sample-preserving guest publication of native multisample depth is not implemented (read site=registers 0x237e06380+0x10 overlaps protected depth 0x237410000+0x10e0000 for depth 0x237410000 samples=2 attachmentActive=0 hostWritten=1)
terminate called after throwing an instance of 'std::runtime_error'

So the strict refusal can't ship on top of this head without sample-preserving publication, which is not implemented for native multisample depth (the sampling debt entry already says so). I also tried letting the retirement through only once the guest has overwritten the owner's memory, the memoryOverwritten predicate the create-time path already uses; the title still aborts, because a 17 MB owner range is not fully write-watched, so WrittenSince reports no reuse even when the guest has repurposed the memory.

What this PR does instead is bounded and explicit: it retires only when the surface is not the current attachment and the read is a reuse read (context-register, texture or vertex-buffer). It is a compatibility workaround for SONIC SUPERSTARS (PPSA06888), not a correct general fix, so I have recorded the gap as a debt entry in docs/dev/debt/libSceAgcDriver.md rather than leaving it implicit. That is also why I did not add the regression you asked for: it would pin the refusal that aborts the title.

On coordination: #6727 and this head both rewrite RequireNoResidentDepthRead_nid_no_patch and touch the same guard lifecycle, so they cannot both land as they are. I am happy to rebase on #6727 once it is in and keep only the parts that don't overlap — the read-site classification, the whole-fill HTILE note and the Overlaps used-size fix — and to split publication of a written native multisample depth owner into its own task.

Would you rather I gate the retirement further in the meantime, or land the debt-documented workaround and follow up with publication?

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6216631061 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6808#issuecomment-6216631061). Originally posted by [KingDarkHN](https://github.com/KingDarkHN) on 2026-10-16T13:32:58Z. --- You're right about the underlying gap: `retire()` drops the owner without copying the host depth/stencil/HTILE image back, so a guest read that means to observe the rendered samples can see stale bytes. I tried your suggestion before replying. I added the same `hostWritten` notion #6727 uses — set from draws with depth writes or stencil writes on both the plain and cached-recipe draw paths, from `CopyAspectFrom`, and from storage write-back, with host clears after a proven guest HTILE clear not counted — and made the overlapping owner refuse. The suite stays green, but the title then aborts on a real reuse site: ``` [gpu] driver failure: sample-preserving guest publication of native multisample depth is not implemented (read site=registers 0x237e06380+0x10 overlaps protected depth 0x237410000+0x10e0000 for depth 0x237410000 samples=2 attachmentActive=0 hostWritten=1) terminate called after throwing an instance of 'std::runtime_error' ``` So the strict refusal can't ship on top of this head without sample-preserving publication, which is not implemented for native multisample depth (the sampling debt entry already says so). I also tried letting the retirement through only once the guest has overwritten the owner's memory, the `memoryOverwritten` predicate the create-time path already uses; the title still aborts, because a 17 MB owner range is not fully write-watched, so `WrittenSince` reports no reuse even when the guest has repurposed the memory. What this PR does instead is bounded and explicit: it retires only when the surface is **not** the current attachment *and* the read is a reuse read (context-register, texture or vertex-buffer). It is a compatibility workaround for SONIC SUPERSTARS (PPSA06888), not a correct general fix, so I have recorded the gap as a debt entry in `docs/dev/debt/libSceAgcDriver.md` rather than leaving it implicit. That is also why I did not add the regression you asked for: it would pin the refusal that aborts the title. On coordination: #6727 and this head both rewrite `RequireNoResidentDepthRead_nid_no_patch` and touch the same guard lifecycle, so they cannot both land as they are. I am happy to rebase on #6727 once it is in and keep only the parts that don't overlap — the read-site classification, the whole-fill HTILE note and the `Overlaps` used-size fix — and to split publication of a written native multisample depth owner into its own task. Would you rather I gate the retirement further in the meantime, or land the debt-documented workaround and follow up with publication?
MarcZX10 commented 2026-10-16 13:36:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-16T13:36:47Z.


Thanks for adding the host-write tracking and documenting the limitation. I would not merge the current compatibility retirement as a general fix: it can discard newer host depth/stencil/HTILE data, and #6727’s contract is explicitly to refuse that state until sample-preserving publication exists. The measured title failure makes this a real follow-up, but it does not make the guest bytes safe to expose. Please rebase the read-site classification, whole-fill HTILE note and exact-plane overlap work onto #6727 after it lands, and keep written-owner publication as a separate change with its own regression. If you want to pursue the bounded workaround independently, please first provide evidence that the guest read is a reuse/alias event whose contents are intentionally replacing the old surface; the current “not attached” condition alone does not establish that. I’ll keep the changes-requested review in place until the unsafe retirement is removed or a publication path is added.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6216702473 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6808#issuecomment-6216702473). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-16T13:36:47Z. --- Thanks for adding the host-write tracking and documenting the limitation. I would not merge the current compatibility retirement as a general fix: it can discard newer host depth/stencil/HTILE data, and #6727’s contract is explicitly to refuse that state until sample-preserving publication exists. The measured title failure makes this a real follow-up, but it does not make the guest bytes safe to expose. Please rebase the read-site classification, whole-fill HTILE note and exact-plane overlap work onto #6727 after it lands, and keep written-owner publication as a separate change with its own regression. If you want to pursue the bounded workaround independently, please first provide evidence that the guest read is a reuse/alias event whose contents are intentionally replacing the old surface; the current “not attached” condition alone does not establish that. I’ll keep the changes-requested review in place until the unsafe retirement is removed or a publication path is added.
KingDarkHN commented 2026-10-16 13:55:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by KingDarkHN on 2026-10-16T13:55:43Z.


Thanks for the careful review — I agree, and I've followed it. Exposing guest bytes for a written
owner is not safe, and #6727's contract is the right one until publication exists.

I've removed the unsafe retirement. A guest read over the guard of a resident native multisample
depth surface now refuses again (sample-preserving guest publication of native multisample depth is not implemented); it no longer retires the owner, so no host depth, stencil or HTILE data is
discarded on a read. RequireNoResidentDepthRead is back to a plain overlap refusal, the read-site
classification is no longer wired into a retirement path, and the hostWritten/read-site machinery
is gone.

What the branch keeps:

  • the reused multisampled colour guard drop (issue #5933);
  • the whole-fill HTILE clear honour (a metadata-only write that proves the surface's clear with the
    depth and stencil planes untouched);
  • the exact-plane overlap fix (Overlaps now compares the bytes the plane stores, not the padded
    128x128 footprint);
  • the stencil-without-HTILE-metadata (TILE_STENCIL_DISABLE) import and the clear-proven-HTILE
    acceptance without ITERATE_256/pipe alignment.

I updated the debt entry (docs/dev/debt/libSceAgcDriver.md): a written owner is refused, SONIC
SUPERSTARS (PPSA06888) aborts on a register read over one (measured on an RTX 5060 Ti, driver
610.57.04), and publishing the samples is the follow-up.

Plan, as you suggest:

  • once #6727 lands, rebase the read-site classification, the whole-fill HTILE note and the
    exact-plane overlap work onto it;
  • keep written-owner publication (copying depth/stencil/HTILE to guest memory) as a separate change
    with its own regression.

Branch updated (head 734edb5c2); title and description reflect the narrower scope. Full
agc_driver suite at its pre-existing pass rate, and agc_driver_native_multisample_depth passes
(the reuse-read cases now assert a refusal that leaves the owner resident).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6217063015 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6808#issuecomment-6217063015). Originally posted by [KingDarkHN](https://github.com/KingDarkHN) on 2026-10-16T13:55:43Z. --- Thanks for the careful review — I agree, and I've followed it. Exposing guest bytes for a written owner is not safe, and #6727's contract is the right one until publication exists. I've removed the unsafe retirement. A guest read over the guard of a resident native multisample depth surface now refuses again (`sample-preserving guest publication of native multisample depth is not implemented`); it no longer retires the owner, so no host depth, stencil or HTILE data is discarded on a read. `RequireNoResidentDepthRead` is back to a plain overlap refusal, the read-site classification is no longer wired into a retirement path, and the `hostWritten`/read-site machinery is gone. What the branch keeps: - the reused multisampled **colour** guard drop (issue #5933); - the whole-fill HTILE clear honour (a metadata-only write that proves the surface's clear with the depth and stencil planes untouched); - the exact-plane overlap fix (`Overlaps` now compares the bytes the plane stores, not the padded 128x128 footprint); - the stencil-without-HTILE-metadata (`TILE_STENCIL_DISABLE`) import and the clear-proven-HTILE acceptance without `ITERATE_256`/pipe alignment. I updated the debt entry (`docs/dev/debt/libSceAgcDriver.md`): a written owner is refused, SONIC SUPERSTARS (PPSA06888) aborts on a register read over one (measured on an RTX 5060 Ti, driver 610.57.04), and publishing the samples is the follow-up. Plan, as you suggest: - once #6727 lands, rebase the read-site classification, the whole-fill HTILE note and the exact-plane overlap work onto it; - keep written-owner publication (copying depth/stencil/HTILE to guest memory) as a separate change with its own regression. Branch updated (head `734edb5c2`); title and description reflect the narrower scope. Full `agc_driver` suite at its pre-existing pass rate, and `agc_driver_native_multisample_depth` passes (the reuse-read cases now assert a refusal that leaves the owner resident).
billythemenace2 commented 2026-10-16 15:26:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by billythemenace2 on 2026-10-16T15:26:27Z.


A Windows data point for this branch: SONIC SUPERSTARS (PPSA06888) on 734edb5c2 merged onto main 452494439. Windows 11, MinGW-w64 GCC 15, Release, AMD Radeon RX 5700 XT (driver 32.0.21045.5002). No input, no environment variables.

It now stops a few seconds after start, during the logo screens, at the depth refusal you describe:

AGC driver: SET_CONTEXT_REG_INDIRECT at DWORD 5: AGC graphics: sample-preserving guest publication of native multisample depth is not implemented

So it matches your Linux run on the RTX 5060 Ti. The native multisample stencil import requires HTILE stencil metadata stop from #6300 (eight 1920x1080 2-sample D32S8 targets with htileStencil=0, htileDepthOnly=1) did not appear before this stop. I can't tell from this run whether those targets were reached, so I'm not counting it as confirmed.

I can rerun it on this machine when the depth publication follow-up is up.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6218802903 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6808#issuecomment-6218802903). Originally posted by [billythemenace2](https://github.com/billythemenace2) on 2026-10-16T15:26:27Z. --- A Windows data point for this branch: SONIC SUPERSTARS (PPSA06888) on `734edb5c2` merged onto `main` `452494439`. Windows 11, MinGW-w64 GCC 15, Release, AMD Radeon RX 5700 XT (driver 32.0.21045.5002). No input, no environment variables. It now stops a few seconds after start, during the logo screens, at the depth refusal you describe: ``` AGC driver: SET_CONTEXT_REG_INDIRECT at DWORD 5: AGC graphics: sample-preserving guest publication of native multisample depth is not implemented ``` So it matches your Linux run on the RTX 5060 Ti. The `native multisample stencil import requires HTILE stencil metadata` stop from #6300 (eight 1920x1080 2-sample D32S8 targets with `htileStencil=0`, `htileDepthOnly=1`) did not appear before this stop. I can't tell from this run whether those targets were reached, so I'm not counting it as confirmed. I can rerun it on this machine when the depth publication follow-up is up. AI-assisted (Claude Code).
Amoenus commented 2026-10-16 19:56:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Amoenus on 2026-10-16T19:56:27Z.

Code review location: core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cpp; line 609

@@ -549,9 +605,12 @@ void RequireNoMultisampleTarget(std::uint64_t address, std::size_t bytes, const
     std::shared_lock lock(guardedMutex());
     for (const auto& range : guarded()) {
         if (address >= range.address + range.bytes || range.address >= address + bytes) continue;
+        lock.unlock();
+        retireGuardForAddress(address, bytes);

[P1] Preserve written color data before retiring its guard

This executes for every overlapping color guard. retireGuardForAddress marks the resident inactive and erases its guard without checking whether the host image has unpublished writes or copying its samples back. RequireNoMultisampleTarget then returns, allowing a guest reader to consume the old bytes. A read classified as reuse does not prove those bytes replace the rendered content; this function does not even classify the access. The same ownership concern that prompted the depth correction still applies to color. The drawn-color/guest-buffer counterexample in #6480 documents the stale-byte hazard, although I have not run that fixture against this PR. Please preserve the refusal until replacement is established or samples are published, and add a written-color/read regression.

<!-- greyfinch-sync:boykopovar/AnyPS5:review-comment:4298753739 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6808#discussion_r4298753739). Originally posted by [Amoenus](https://github.com/Amoenus) on 2026-10-16T19:56:27Z. **Code review location:** `core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cpp`; line 609 ~~~~diff @@ -549,9 +605,12 @@ void RequireNoMultisampleTarget(std::uint64_t address, std::size_t bytes, const std::shared_lock lock(guardedMutex()); for (const auto& range : guarded()) { if (address >= range.address + range.bytes || range.address >= address + bytes) continue; + lock.unlock(); + retireGuardForAddress(address, bytes); ~~~~ --- [P1] Preserve written color data before retiring its guard This executes for every overlapping color guard. retireGuardForAddress marks the resident inactive and erases its guard without checking whether the host image has unpublished writes or copying its samples back. RequireNoMultisampleTarget then returns, allowing a guest reader to consume the old bytes. A read classified as reuse does not prove those bytes replace the rendered content; this function does not even classify the access. The same ownership concern that prompted the depth correction still applies to color. The drawn-color/guest-buffer counterexample in #6480 documents the stale-byte hazard, although I have not run that fixture against this PR. Please preserve the refusal until replacement is established or samples are published, and add a written-color/read regression.
Amoenus commented 2026-10-16 19:56:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Amoenus on 2026-10-16T19:56:27Z.

Code review location: core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cpp; line 611

@@ -549,9 +605,12 @@ void RequireNoMultisampleTarget(std::uint64_t address, std::size_t bytes, const
     std::shared_lock lock(guardedMutex());
     for (const auto& range : guarded()) {
         if (address >= range.address + range.bytes || range.address >= address + bytes) continue;
+        lock.unlock();
+        retireGuardForAddress(address, bytes);
         char text[256];
-        std::snprintf(text, sizeof(text), "AGC graphics: %s of 0x%llx+0x%zx overlaps multisampled color target 0x%llx+0x%llx (%u samples), whose samples are only on the host: guest access to it is not implemented", access, static_cast<unsigned long long>(address), bytes, static_cast<unsigned long long>(range.address), static_cast<unsigned long long>(range.bytes), range.samples);
-        throw std::runtime_error(text);
+        std::snprintf(text, sizeof(text), "[gpu] %s of 0x%llx+0x%zx retired guard for reused multisampled color target 0x%llx+0x%llx (%u samples)", access, static_cast<unsigned long long>(address), bytes, static_cast<unsigned long long>(range.address), static_cast<unsigned long long>(range.bytes), range.samples);

[P2] Copy the guard before unlocking and erasing it

range is a reference to an element of guarded(). After the shared lock is released, another writer can invalidate it; retireGuardForAddress then calls std::erase_if on that same vector and removes the overlapping entry. Reading range.address, range.bytes and range.samples afterward therefore uses an invalidated reference. Copy the needed fields while the shared lock is still held and use that copy for the diagnostic. This remains necessary if the retirement semantics are corrected separately.

<!-- greyfinch-sync:boykopovar/AnyPS5:review-comment:4298753750 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6808#discussion_r4298753750). Originally posted by [Amoenus](https://github.com/Amoenus) on 2026-10-16T19:56:27Z. **Code review location:** `core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cpp`; line 611 ~~~~diff @@ -549,9 +605,12 @@ void RequireNoMultisampleTarget(std::uint64_t address, std::size_t bytes, const std::shared_lock lock(guardedMutex()); for (const auto& range : guarded()) { if (address >= range.address + range.bytes || range.address >= address + bytes) continue; + lock.unlock(); + retireGuardForAddress(address, bytes); char text[256]; - std::snprintf(text, sizeof(text), "AGC graphics: %s of 0x%llx+0x%zx overlaps multisampled color target 0x%llx+0x%llx (%u samples), whose samples are only on the host: guest access to it is not implemented", access, static_cast<unsigned long long>(address), bytes, static_cast<unsigned long long>(range.address), static_cast<unsigned long long>(range.bytes), range.samples); - throw std::runtime_error(text); + std::snprintf(text, sizeof(text), "[gpu] %s of 0x%llx+0x%zx retired guard for reused multisampled color target 0x%llx+0x%llx (%u samples)", access, static_cast<unsigned long long>(address), bytes, static_cast<unsigned long long>(range.address), static_cast<unsigned long long>(range.bytes), range.samples); ~~~~ --- [P2] Copy the guard before unlocking and erasing it range is a reference to an element of guarded(). After the shared lock is released, another writer can invalidate it; retireGuardForAddress then calls std::erase_if on that same vector and removes the overlapping entry. Reading range.address, range.bytes and range.samples afterward therefore uses an invalidated reference. Copy the needed fields while the shared lock is still held and use that copy for the diagnostic. This remains necessary if the retirement semantics are corrected separately.
Amoenus commented 2026-10-16 19:56:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Amoenus on 2026-10-16T19:56:27Z.

Review: COMMENTED


Source review of exact head 734edb5c2 while checking overlap with native color publication work. The previous depth correction is acknowledged; the remaining color retirement has the two findings below. I did not build or run this PR or its title. AI-assisted: Codex; author responsible.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5552981012 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6808#pullrequestreview-5552981012). Originally posted by [Amoenus](https://github.com/Amoenus) on 2026-10-16T19:56:27Z. **Review:** COMMENTED --- Source review of exact head 734edb5c2 while checking overlap with native color publication work. The previous depth correction is acknowledged; the remaining color retirement has the two findings below. I did not build or run this PR or its title. AI-assisted: Codex; author responsible.
Amoenus commented 2026-10-17 00:35:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Amoenus on 2026-10-17T00:35:10Z.


@KingDarkHN Updated in place: the qualified sample-preserving stack is #6973 → #6987 → #6989 → #6995 → #7002 0cdc81ae9f, retaining exact credited #6498 e15c428b4d ancestry.

#7002 has 99 focused passes (87 actual NVIDIA/AMD GPU, 12 CPU), full Windows builds, and the same nine AMD DCC assertion failures as literal main 1e774a3b22; zero VUIDs/validation errors/warnings. All writable bindings are checked before read-only publication. Historical dependency/reversed-order controls retain their original pins, without a new rerun claim. Current scope and stack evidence are maintained in #6480 and #7002.

This is our adapted composition, not validation of unchanged #6808 or SONIC SUPERSTARS. For PPSA06888 reuse in #5933, format, tile/sample count, DCC/CMASK state and the next consumer still matter; I have not tested that title. #7260 retains Sonic's ordinary-run boundary and historical gameplay; no new title/FPS claim. AI-assisted: Codex; author responsible.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6227407355 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6808#issuecomment-6227407355). Originally posted by [Amoenus](https://github.com/Amoenus) on 2026-10-17T00:35:10Z. --- @KingDarkHN Updated in place: the qualified sample-preserving stack is #6973 → #6987 → #6989 → #6995 → [#7002 `0cdc81ae9f`](https://github.com/Amoenus/AnyPS5/commit/0cdc81ae9f6e4e2e5eaa7e2289a89864c82b2d59), retaining exact credited #6498 `e15c428b4d` ancestry. #7002 has 99 focused passes (87 actual NVIDIA/AMD GPU, 12 CPU), full Windows builds, and the same nine AMD DCC assertion failures as literal main `1e774a3b22`; zero VUIDs/validation errors/warnings. All writable bindings are checked before read-only publication. Historical dependency/reversed-order controls retain their original pins, without a new rerun claim. Current scope and stack evidence are maintained in #6480 and #7002. This is our adapted composition, not validation of unchanged #6808 or SONIC SUPERSTARS. For PPSA06888 reuse in #5933, format, tile/sample count, DCC/CMASK state and the next consumer still matter; I have not tested that title. #7260 retains Sonic's ordinary-run boundary and historical gameplay; no new title/FPS claim. AI-assisted: Codex; author responsible.
MarcZX10 commented 2026-10-17 16:56:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-17T16:56:47Z.


I checked the linked #5933 report for the format/reuse details. It records a 4x, 64 KiB native target overlapping a 512x512 texture view (format 173, tile mode 2, 10 mips, size 0x56000); the view starts 0x51000 before the target. The report also has separate storage-image and CPU-read overlaps. It does not record DCC/CMASK state or establish whether the aliased texture is meant to consume the old rendered samples versus data written after reuse, so I cannot say the #7002 buffer-publication path applies. Its stated scope is read-only shader-buffer consumers; this #5933 example is a texture read and needs its own publication evidence/coverage.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6237111559 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6808#issuecomment-6237111559). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-17T16:56:47Z. --- I checked the linked #5933 report for the format/reuse details. It records a 4x, 64 KiB native target overlapping a 512x512 texture view (format 173, tile mode 2, 10 mips, size 0x56000); the view starts 0x51000 before the target. The report also has separate storage-image and CPU-read overlaps. It does not record DCC/CMASK state or establish whether the aliased texture is meant to consume the old rendered samples versus data written after reuse, so I cannot say the #7002 buffer-publication path applies. Its stated scope is read-only shader-buffer consumers; this #5933 example is a texture read and needs its own publication evidence/coverage.
hugodearaujo commented 2026-10-18 16:18:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by hugodearaujo on 2026-10-18T16:18:12Z.


Another title that stops on this refusal: Assassin's Creed Mirage (PPSA13960, 01.007.000), on main with #6343, #7532 and #7533:

AGC graphics: a storage image access of 0x10e0720000+0x870000 overlaps multisampled color target 0x10e0720000+0x870000 (4 samples), whose samples are only on the host: guest access to it is not implemented

With a local change equivalent to this PR's RequireNoMultisampleTarget (retire the guard instead of throwing), it passes that point and runs about two more minutes through its start-up screens, then stops at an unrelated guest memory is not readable error. Unlike Sonic Superstars, Mirage does not reuse the memory later: every frame it renders two 960x540 4x MSAA targets (R11G11B10F and R16F) and then accesses the same memory as 1920x1080 single-sample images (a compute storage write in SW_64KB_S and a texture read). With the guard retired, those views do not see the samples drawn on the host.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6252189768 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6808#issuecomment-6252189768). Originally posted by [hugodearaujo](https://github.com/hugodearaujo) on 2026-10-18T16:18:12Z. --- Another title that stops on this refusal: Assassin's Creed Mirage (PPSA13960, 01.007.000), on `main` with #6343, #7532 and #7533: ``` AGC graphics: a storage image access of 0x10e0720000+0x870000 overlaps multisampled color target 0x10e0720000+0x870000 (4 samples), whose samples are only on the host: guest access to it is not implemented ``` With a local change equivalent to this PR's `RequireNoMultisampleTarget` (retire the guard instead of throwing), it passes that point and runs about two more minutes through its start-up screens, then stops at an unrelated `guest memory is not readable` error. Unlike Sonic Superstars, Mirage does not reuse the memory later: every frame it renders two 960x540 4x MSAA targets (R11G11B10F and R16F) and then accesses the same memory as 1920x1080 single-sample images (a compute storage write in SW_64KB_S and a texture read). With the guard retired, those views do not see the samples drawn on the host.
oneandonlydean commented 2026-10-20 12:51:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-20T12:51:13Z.


Thanks. This branch is far behind main and conflicts in DepthSurface.cpp, MultisampleTarget.cpp, both multisample execution tests and the debt file. main has since changed the same paths (retired multisample colour targets are reclaimed, HTILE clears of later slices, the ITERATE_256 depth import). Could you rebase onto current main? It would also help to say how this relates to the sample-preserving stack in #6973 to #7002, which covers part of the same ground, so it's clear which parts are still needed here.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6291257117 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6808#issuecomment-6291257117). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-20T12:51:13Z. --- Thanks. This branch is far behind `main` and conflicts in `DepthSurface.cpp`, `MultisampleTarget.cpp`, both multisample execution tests and the debt file. `main` has since changed the same paths (retired multisample colour targets are reclaimed, HTILE clears of later slices, the ITERATE_256 depth import). Could you rebase onto current `main`? It would also help to say how this relates to the sample-preserving stack in #6973 to #7002, which covers part of the same ground, so it's clear which parts are still needed here.
oneandonlydean commented 2026-10-20 17:53:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-20T17:53:31Z.


@KingDarkHN a follow-up to my rebase ask: we're going to take the native multisample colour work forward through Amoenus's stack (#6973 → #6987 → #6989 → #6995 → #7002), which adapts this approach and is kept up to date with main.

Two questions, so nothing in this PR gets lost:

  1. Is there anything in the colour-target part of this PR that the stack doesn't cover? If so, could you point to it (a file and function is enough), and we'll make sure it's carried over.
  2. The guest HTILE clear / depth half is a separate change from the colour reuse, and it overlaps work in progress on HTILE depth clears (#7233). Would you be willing to split it into its own PR, rebased onto current main? On its own it's much easier to review and test.

Thanks for the original work. The stack builds on it.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6297481033 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6808#issuecomment-6297481033). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-20T17:53:31Z. --- @KingDarkHN a follow-up to my rebase ask: we're going to take the native multisample colour work forward through Amoenus's stack (#6973 → #6987 → #6989 → #6995 → #7002), which adapts this approach and is kept up to date with `main`. Two questions, so nothing in this PR gets lost: 1. Is there anything in the colour-target part of this PR that the stack doesn't cover? If so, could you point to it (a file and function is enough), and we'll make sure it's carried over. 2. The guest HTILE clear / depth half is a separate change from the colour reuse, and it overlaps work in progress on HTILE depth clears (#7233). Would you be willing to split it into its own PR, rebased onto current `main`? On its own it's much easier to review and test. Thanks for the original work. The stack builds on it.
XairRrR commented 2026-10-29 05:05:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-10-29T05:05:18Z.

Review: CHANGES_REQUESTED


Reviewed — changes requested

The head conflicts with main in five files and breaks an existing test (agc_driver_native_depth_retirement). I also found two defects in the depth half that the earlier reviews did not cover: a guest HTILE write clears the host stencil plane when the HTILE has no stencil metadata, and the new Overlaps bound leaves real tiled pixel data outside the retirement range.

What I ran

  • Head: 734edb5c279d2f9de101d8ecf555f55b6f40d613
  • main: 52c09d567d2fa453494dd720fcf53a98149468e4
  • Merge base of the head and main: 5d9dcc42d2ec5401aebd089028b8d4d7410a77b4 (12,344 commits behind main)
  • Machine: Arch Linux 7.2.11-zen, GCC 16.2.1, Intel Core i9-14900KF, NVIDIA GeForce RTX 4070 Ti SUPER (driver 615.78.08), Release build in a clean worktree.
git fetch -q origin main pull/6808/head:refs/review/6808
git checkout -q --detach origin/main
git merge -q --no-ff --no-edit refs/review/6808   # conflicts, aborted
git merge --abort
git checkout -q --detach refs/review/6808
git diff --check origin/main...refs/review/6808
python3 tools/check_conventions.py --base origin/main
cmake --build build -j10 --target agc_driver_native_multisample_depth_tests agc_driver_sample_multisample_target_tests \
  agc_driver_depth_fast_clear_tests agc_driver_depth_fast_clear_submit_tests agc_driver_depth_storage_reuse_tests \
  agc_driver_depth_surface_last_writer_tests agc_driver_graphics_tests
VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ANYPS5_NO_SHADER_CACHE=1 ANYPS5_REQUIRE_VULKAN=1 VK_LOADER_DEBUG=error,warn,layer \
  ctest --test-dir build -j4 -V --output-on-failure -R '^agc_driver_(depth_fast_clear|depth_fast_clear_submit|depth_storage_reuse|depth_surface_last_writer|native_multisample_depth|sample_multisample_target|native_depth_retirement|native_depth_clears|native_depth_clear_refusals|native_depth_stencil|multisample)$'
# negative control / base comparison: DepthSurface.cpp and MultisampleTarget.cpp restored from the merge base, same build and ctest

Results

Check Result
Merge into main Conflicts in Graphics/src/DepthSurface.cpp, Graphics/src/MultisampleTarget.cpp, tests/execution/NativeMultisampleDepth.cpp, tests/execution/SampleMultisampleTarget.cpp, docs/dev/debt/libSceAgcDriver.md
git diff --check clean
check_conventions.py --base origin/main All conventions checks passed.
Build of the PR head (standalone, not merged) OK
Focused tests on the PR head 9 of 10 pass; agc_driver_native_depth_retirement fails
Same tests with the production files from the merge base agc_driver_native_depth_retirement passes; the five tests the PR adds or changes fail (see Negative control)
was not found but was requested by env var VK_INSTANCE_LAYERS absent from both logs
VUID- IDs PR head: only VUID-vkBeginCommandBuffer-commandBuffer-00050 (84 lines). Merge base: the same single ID (108 lines). No new VUID ID. The count differs because different tests stop at different points
agc_driver_native_depth_retirement on the PR head
667: [gpu] a CPU read of 0x7f8838ee0000+0x1 retired guard for reused multisampled color target 0x7f8838ee0000+0x10000 (4 samples)
667: AGC graphics: multisample target refusal did not match multisampled: 
 6/10 Test #667: agc_driver_native_depth_retirement .......***Failed    0.63 sec
PR head test summary
 1/10 Test #329: agc_driver_depth_fast_clear ..............   Passed    0.48 sec
 2/10 Test #336: agc_driver_depth_storage_reuse ...........   Passed    0.55 sec
 3/10 Test #567: agc_driver_sample_multisample_target .....   Passed    0.62 sec
 4/10 Test #338: agc_driver_depth_surface_last_writer .....   Passed    0.39 sec
 5/10 Test #330: agc_driver_depth_fast_clear_submit .......   Passed    0.95 sec
 6/10 Test #667: agc_driver_native_depth_retirement .......***Failed    0.63 sec
 7/10 Test #513: agc_driver_native_multisample_depth ......   Passed    0.95 sec
 8/10 Test #669: agc_driver_native_depth_clear_refusals ...   Passed    0.63 sec
 9/10 Test #670: agc_driver_native_depth_stencil ..........   Passed    0.66 sec
10/10 Test #668: agc_driver_native_depth_clears ...........   Passed    1.44 sec
90% tests passed, 1 tests failed out of 10

Negative control

The head does not merge, so I could not restore files from origin/main against a merged tree, and main is too far ahead to build against the head's tests. Instead I restored DepthSurface.cpp and MultisampleTarget.cpp from the merge base (5d9dcc42d2), kept the head's tests, rebuilt and reran:

 1/10 Test #513: agc_driver_native_multisample_depth ......***Failed   (native multisample depth sampled metadata or XOR mismatch)
 2/10 Test #668: agc_driver_native_depth_clears ...........***Failed   (native multisample depth sampled metadata or XOR mismatch)
 4/10 Test #567: agc_driver_sample_multisample_target .....***Failed   (... tile mode 4 has no modeled multisampled color footprint, is not implemented)
 5/10 Test #667: agc_driver_native_depth_retirement .......   Passed
 6/10 Test #670: agc_driver_native_depth_stencil ..........***Failed   (native multisample stencil or depth format import is not implemented)
 7/10 Test #669: agc_driver_native_depth_clear_refusals ...***Failed   (refusal did not match CPU writes raced: ... metadata fill transition is not implemented)

So the new and changed tests do depend on the production change. agc_driver_native_depth_retirement passes on the base and fails on the head, so the PR causes that failure; it is not pre-existing. The base includes #6297, which has since merged; the head's diff also carries #6300, which is still open.

Findings

Blocking

  1. Conflicts with main. These five files conflict: DepthSurface.cpp, MultisampleTarget.cpp, both multisample execution tests and the debt file. This confirms the maintainer's comments of 20, 25 and 28 Oct. main has since rewritten RequireNoMultisampleColorTarget: it now retires a guard only when the target is not hostOnly, and refuses otherwise. Most of this PR's colour change is therefore superseded, and the colour work is going forward through #6973 to #7002.

  2. The colour guard drop breaks an existing regression. In MultisampleTarget.cpp L602-L614, any overlapping access now retires the guard and returns, without classifying the access. NativeMultisampleDepth.cpp L1327-L1332 asserts that a CPU read over a still-allocated multisampled colour target refuses, and it now fails (log above). The description reports agc_driver_native_multisample_depth passing and only pre-existing failures elsewhere, but agc_driver_native_depth_retirement passes on the base and fails here. This failure is concrete evidence for Amoenus's P1: the change removes a refusal that an existing test pins and puts no debt entry in its place. The debt entries at libSceAgcDriver.md L48 ("guest access to live multisampled data remain unsupported") and L116 ("the memory a multisampled color target throws on (CPU read, DMA copy, texture or storage image read)") are now wrong. Suggested fix: drop this hunk when rebasing, since main and the #6973–#7002 stack cover colour retirement.

  3. A guest HTILE fast clear clears the host stencil plane even when the HTILE has no stencil metadata. In DepthSurface.cpp L276-L290, the honour path only checks the stencil clear when target.htileStencil is set. It still calls RecordClear(DEPTH | STENCIL) whenever target.stencilAddress != 0. With TILE_STENCIL_DISABLE, which this PR newly accepts at import, the HTILE carries no stencil state, and the stencil plane is required to be unwritten. The guest therefore did not clear the stencil, yet RecordClear overwrites the host stencil image with clearStencil and discards any stencil the host drew. main's own metadata-fill path makes the opposite choice: written = DEPTH | (target.htileStencil ? STENCIL : 0) at L1597. Suggested fix: add VK_IMAGE_ASPECT_STENCIL_BIT only when target.htileStencil is set, and add a case with a stencil plane, htileStencil = 0, a host stencil draw and then a guest HTILE clear that checks the stencil is preserved.

  4. The new Overlaps bound misses stored pixels. DepthSurface.cpp L438-L445 now bounds each plane by width * height * bytes * samples from its base. That counts the stored bytes correctly, but they are not the first bytes of the range. Tiled blocks are stored in row-major order (TextureTiling.hpp L34-L36), so the padding is the unused rows inside each block of the last block row, not a tail.

    Take a 1920x1080 single-sample D32 surface (128x128 blocks of 64 KiB):

    • The footprint is 0x870000 bytes, and the last block row starts at 0x780000.
    • The new bound ends at 192010804 = 0x7E9000.
    • Blocks 7 to 14 of the last row (0x7F0000 to 0x870000) lie entirely past that bound. Each one still holds rows 1024 to 1079 for its 128 columns.

    A colour target or storage write over those blocks goes through RetireDepthSurfaces (Draw.cpp, ShaderResources.cpp), no longer retires the depth surface, and leaves a stale owner that later lookups can return. Suggested fix: keep the block-rounded footprint, or use CoveredMipBytes-style per-block ranges if you want to exclude padding exactly. Add a test that writes the last block of the last block row.

  5. Unchecked retirement in DepthSurfaceView. requireNoOverlap in DepthSurface.cpp L1300-L1308 retires an overlapping owner when attachmentInactive holds, without checking for unpublished host writes. This is the same concern MarcZX10 raised for RequireNoResidentDepthRead and oneandonlydean raised on 28 Oct. I have no new evidence beyond confirming that the code still does this at the head.

Non-blocking

  • The debt entry at L16 names the game. As the maintainer noted, the debt files use the title ID only.
  • Amoenus's P2 still applies: range is used after lock.unlock() and after retireGuardForAddress has erased it from the vector. I confirmed this by reading the code; it is moot if the hunk is dropped.
  • The new fprintf(stderr, ...) lines ([gpu] ... retired guard, [agc] honoured a guest fast clear ...) print on every occurrence. Once a title hits them every frame, they flood the log.

Not verified

  • No merged tree exists, so I could not build or test the change on main. All results are for the standalone head against its merge base, and the Vulkan validation comparison is against that merge base, not current main.
  • I did not run the full agc_driver suite and did not run any title.
  • I worked out findings 3 and 4 from the code and the documented tile layout. I did not write tests for them.

To get this to a good state

  • Follow the maintainer's plan: drop the colour hunk, which main and #6973–#7002 cover, and rebase the depth/HTILE half onto current main as its own PR.
  • In that PR, record a stencil clear only when htileStencil is set (finding 3), keep the block-rounded overlap or make it exact per block (finding 4), and address the inactive-owner retirement (finding 5). Add a regression for each.
  • Make sure agc_driver_native_depth_retirement passes, and use the title ID only in the debt entry.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5693093829 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6808#pullrequestreview-5693093829). Originally posted by [XairRrR](https://github.com/XairRrR) on 2026-10-29T05:05:18Z. **Review:** CHANGES_REQUESTED --- # Reviewed — changes requested The head conflicts with `main` in five files and breaks an existing test (`agc_driver_native_depth_retirement`). I also found two defects in the depth half that the earlier reviews did not cover: a guest HTILE write clears the host stencil plane when the HTILE has no stencil metadata, and the new `Overlaps` bound leaves real tiled pixel data outside the retirement range. ## What I ran - Head: `734edb5c279d2f9de101d8ecf555f55b6f40d613` - `main`: `52c09d567d2fa453494dd720fcf53a98149468e4` - Merge base of the head and `main`: `5d9dcc42d2ec5401aebd089028b8d4d7410a77b4` (12,344 commits behind `main`) - Machine: Arch Linux 7.2.11-zen, GCC 16.2.1, Intel Core i9-14900KF, NVIDIA GeForce RTX 4070 Ti SUPER (driver 615.78.08), Release build in a clean worktree. ```sh git fetch -q origin main pull/6808/head:refs/review/6808 git checkout -q --detach origin/main git merge -q --no-ff --no-edit refs/review/6808 # conflicts, aborted git merge --abort git checkout -q --detach refs/review/6808 git diff --check origin/main...refs/review/6808 python3 tools/check_conventions.py --base origin/main cmake --build build -j10 --target agc_driver_native_multisample_depth_tests agc_driver_sample_multisample_target_tests \ agc_driver_depth_fast_clear_tests agc_driver_depth_fast_clear_submit_tests agc_driver_depth_storage_reuse_tests \ agc_driver_depth_surface_last_writer_tests agc_driver_graphics_tests VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ANYPS5_NO_SHADER_CACHE=1 ANYPS5_REQUIRE_VULKAN=1 VK_LOADER_DEBUG=error,warn,layer \ ctest --test-dir build -j4 -V --output-on-failure -R '^agc_driver_(depth_fast_clear|depth_fast_clear_submit|depth_storage_reuse|depth_surface_last_writer|native_multisample_depth|sample_multisample_target|native_depth_retirement|native_depth_clears|native_depth_clear_refusals|native_depth_stencil|multisample)$' # negative control / base comparison: DepthSurface.cpp and MultisampleTarget.cpp restored from the merge base, same build and ctest ``` ## Results | Check | Result | |---|---| | Merge into `main` | **Conflicts** in `Graphics/src/DepthSurface.cpp`, `Graphics/src/MultisampleTarget.cpp`, `tests/execution/NativeMultisampleDepth.cpp`, `tests/execution/SampleMultisampleTarget.cpp`, `docs/dev/debt/libSceAgcDriver.md` | | `git diff --check` | clean | | `check_conventions.py --base origin/main` | `All conventions checks passed.` | | Build of the PR head (standalone, not merged) | OK | | Focused tests on the PR head | 9 of 10 pass; **`agc_driver_native_depth_retirement` fails** | | Same tests with the production files from the merge base | `agc_driver_native_depth_retirement` **passes**; the five tests the PR adds or changes fail (see Negative control) | | `was not found but was requested by env var VK_INSTANCE_LAYERS` | absent from both logs | | `VUID-` IDs | PR head: only `VUID-vkBeginCommandBuffer-commandBuffer-00050` (84 lines). Merge base: the same single ID (108 lines). No new VUID ID. The count differs because different tests stop at different points | <details><summary><code>agc_driver_native_depth_retirement</code> on the PR head</summary> ``` 667: [gpu] a CPU read of 0x7f8838ee0000+0x1 retired guard for reused multisampled color target 0x7f8838ee0000+0x10000 (4 samples) 667: AGC graphics: multisample target refusal did not match multisampled: 6/10 Test #667: agc_driver_native_depth_retirement .......***Failed 0.63 sec ``` </details> <details><summary>PR head test summary</summary> ``` 1/10 Test #329: agc_driver_depth_fast_clear .............. Passed 0.48 sec 2/10 Test #336: agc_driver_depth_storage_reuse ........... Passed 0.55 sec 3/10 Test #567: agc_driver_sample_multisample_target ..... Passed 0.62 sec 4/10 Test #338: agc_driver_depth_surface_last_writer ..... Passed 0.39 sec 5/10 Test #330: agc_driver_depth_fast_clear_submit ....... Passed 0.95 sec 6/10 Test #667: agc_driver_native_depth_retirement .......***Failed 0.63 sec 7/10 Test #513: agc_driver_native_multisample_depth ...... Passed 0.95 sec 8/10 Test #669: agc_driver_native_depth_clear_refusals ... Passed 0.63 sec 9/10 Test #670: agc_driver_native_depth_stencil .......... Passed 0.66 sec 10/10 Test #668: agc_driver_native_depth_clears ........... Passed 1.44 sec 90% tests passed, 1 tests failed out of 10 ``` </details> ## Negative control The head does not merge, so I could not restore files from `origin/main` against a merged tree, and `main` is too far ahead to build against the head's tests. Instead I restored `DepthSurface.cpp` and `MultisampleTarget.cpp` from the merge base (`5d9dcc42d2`), kept the head's tests, rebuilt and reran: ``` 1/10 Test #513: agc_driver_native_multisample_depth ......***Failed (native multisample depth sampled metadata or XOR mismatch) 2/10 Test #668: agc_driver_native_depth_clears ...........***Failed (native multisample depth sampled metadata or XOR mismatch) 4/10 Test #567: agc_driver_sample_multisample_target .....***Failed (... tile mode 4 has no modeled multisampled color footprint, is not implemented) 5/10 Test #667: agc_driver_native_depth_retirement ....... Passed 6/10 Test #670: agc_driver_native_depth_stencil ..........***Failed (native multisample stencil or depth format import is not implemented) 7/10 Test #669: agc_driver_native_depth_clear_refusals ...***Failed (refusal did not match CPU writes raced: ... metadata fill transition is not implemented) ``` So the new and changed tests do depend on the production change. `agc_driver_native_depth_retirement` passes on the base and fails on the head, so the PR causes that failure; it is not pre-existing. The base includes #6297, which has since merged; the head's diff also carries #6300, which is still open. ## Findings ### Blocking 1. **Conflicts with `main`.** These five files conflict: `DepthSurface.cpp`, `MultisampleTarget.cpp`, both multisample execution tests and the debt file. This confirms the maintainer's comments of 20, 25 and 28 Oct. `main` has since rewritten `RequireNoMultisampleColorTarget`: it now retires a guard only when the target is not `hostOnly`, and refuses otherwise. Most of this PR's colour change is therefore superseded, and the colour work is going forward through #6973 to #7002. 2. **The colour guard drop breaks an existing regression.** In [`MultisampleTarget.cpp` L602-L614](https://github.com/boykopovar/AnyPS5/blob/734edb5c279d2f9de101d8ecf555f55b6f40d613/core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cpp#L602-L614), any overlapping access now retires the guard and returns, without classifying the access. [`NativeMultisampleDepth.cpp` L1327-L1332](https://github.com/boykopovar/AnyPS5/blob/734edb5c279d2f9de101d8ecf555f55b6f40d613/core/libs/prx/libSceAgcDriver/tests/execution/NativeMultisampleDepth.cpp#L1327-L1332) asserts that a CPU read over a still-allocated multisampled colour target refuses, and it now fails (log above). The description reports `agc_driver_native_multisample_depth` passing and only pre-existing failures elsewhere, but `agc_driver_native_depth_retirement` passes on the base and fails here. This failure is concrete evidence for Amoenus's P1: the change removes a refusal that an existing test pins and puts no debt entry in its place. The debt entries at [`libSceAgcDriver.md` L48](https://github.com/boykopovar/AnyPS5/blob/734edb5c279d2f9de101d8ecf555f55b6f40d613/docs/dev/debt/libSceAgcDriver.md#L48) ("guest access to live multisampled data remain unsupported") and [L116](https://github.com/boykopovar/AnyPS5/blob/734edb5c279d2f9de101d8ecf555f55b6f40d613/docs/dev/debt/libSceAgcDriver.md#L116) ("the memory a multisampled color target throws on (CPU read, DMA copy, texture or storage image read)") are now wrong. Suggested fix: drop this hunk when rebasing, since `main` and the #6973–#7002 stack cover colour retirement. 3. **A guest HTILE fast clear clears the host stencil plane even when the HTILE has no stencil metadata.** In [`DepthSurface.cpp` L276-L290](https://github.com/boykopovar/AnyPS5/blob/734edb5c279d2f9de101d8ecf555f55b6f40d613/core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp#L276-L290), the honour path only checks the stencil clear when `target.htileStencil` is set. It still calls `RecordClear(DEPTH | STENCIL)` whenever `target.stencilAddress != 0`. With `TILE_STENCIL_DISABLE`, which this PR newly accepts at import, the HTILE carries no stencil state, and the stencil plane is required to be unwritten. The guest therefore did not clear the stencil, yet `RecordClear` overwrites the host stencil image with `clearStencil` and discards any stencil the host drew. `main`'s own metadata-fill path makes the opposite choice: `written = DEPTH | (target.htileStencil ? STENCIL : 0)` at [L1597](https://github.com/boykopovar/AnyPS5/blob/734edb5c279d2f9de101d8ecf555f55b6f40d613/core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp#L1597). Suggested fix: add `VK_IMAGE_ASPECT_STENCIL_BIT` only when `target.htileStencil` is set, and add a case with a stencil plane, `htileStencil = 0`, a host stencil draw and then a guest HTILE clear that checks the stencil is preserved. 4. **The new `Overlaps` bound misses stored pixels.** [`DepthSurface.cpp` L438-L445](https://github.com/boykopovar/AnyPS5/blob/734edb5c279d2f9de101d8ecf555f55b6f40d613/core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp#L438-L445) now bounds each plane by `width * height * bytes * samples` from its base. That counts the stored bytes correctly, but they are not the first bytes of the range. Tiled blocks are stored in row-major order ([`TextureTiling.hpp` L34-L36](https://github.com/boykopovar/AnyPS5/blob/734edb5c279d2f9de101d8ecf555f55b6f40d613/core/libs/prx/libSceAgcDriver/Graphics/include/TextureTiling.hpp#L34-L36)), so the padding is the unused rows inside each block of the last block row, not a tail. Take a 1920x1080 single-sample D32 surface (128x128 blocks of 64 KiB): - The footprint is 0x870000 bytes, and the last block row starts at 0x780000. - The new bound ends at 1920*1080*4 = 0x7E9000. - Blocks 7 to 14 of the last row (0x7F0000 to 0x870000) lie entirely past that bound. Each one still holds rows 1024 to 1079 for its 128 columns. A colour target or storage write over those blocks goes through `RetireDepthSurfaces` (`Draw.cpp`, `ShaderResources.cpp`), no longer retires the depth surface, and leaves a stale owner that later lookups can return. Suggested fix: keep the block-rounded footprint, or use `CoveredMipBytes`-style per-block ranges if you want to exclude padding exactly. Add a test that writes the last block of the last block row. 5. **Unchecked retirement in `DepthSurfaceView`.** `requireNoOverlap` in [`DepthSurface.cpp` L1300-L1308](https://github.com/boykopovar/AnyPS5/blob/734edb5c279d2f9de101d8ecf555f55b6f40d613/core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp#L1300-L1308) retires an overlapping owner when `attachmentInactive` holds, without checking for unpublished host writes. This is the same concern MarcZX10 raised for `RequireNoResidentDepthRead` and oneandonlydean raised on 28 Oct. I have no new evidence beyond confirming that the code still does this at the head. ### Non-blocking - The debt entry at [L16](https://github.com/boykopovar/AnyPS5/blob/734edb5c279d2f9de101d8ecf555f55b6f40d613/docs/dev/debt/libSceAgcDriver.md#L16) names the game. As the maintainer noted, the debt files use the title ID only. - Amoenus's P2 still applies: `range` is used after `lock.unlock()` and after `retireGuardForAddress` has erased it from the vector. I confirmed this by reading the code; it is moot if the hunk is dropped. - The new `fprintf(stderr, ...)` lines (`[gpu] ... retired guard`, `[agc] honoured a guest fast clear ...`) print on every occurrence. Once a title hits them every frame, they flood the log. ## Not verified - No merged tree exists, so I could not build or test the change on `main`. All results are for the standalone head against its merge base, and the Vulkan validation comparison is against that merge base, not current `main`. - I did not run the full `agc_driver` suite and did not run any title. - I worked out findings 3 and 4 from the code and the documented tile layout. I did not write tests for them. ## To get this to a good state - Follow the maintainer's plan: drop the colour hunk, which `main` and #6973–#7002 cover, and rebase the depth/HTILE half onto current `main` as its own PR. - In that PR, record a stencil clear only when `htileStencil` is set (finding 3), keep the block-rounded overlap or make it exact per block (finding 4), and address the inactive-owner retirement (finding 5). Add a regression for each. - Make sure `agc_driver_native_depth_retirement` passes, and use the title ID only in the debt entry.
MarcZX10 commented 2026-11-22 17:13:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T17:13:21Z.

Review: CHANGES_REQUESTED


Reviewed — changes requested

A guest read overlapping a guarded multisampled color target now retires the guard and proceeds, exposing stale guest bytes while the rendered samples remain only in the host image.

What I ran

Reviewed head 734edb5c279d2f9de101d8ecf555f55b6f40d613 from the prepared diff and targeted reader context. No tests or build commands were run.

Results

Check Result Note
Diff review passed Prepared change inspected
Targeted source review passed Guard callers and relevant implementation inspected
Tests and build not run No commands executed

Findings

Blocking

  • core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cpp:538 — RequireNoMultisampleTarget is called for CPU reads, texture reads, and DMA source reads as well as target reuse. On any overlap this change removes the guard and returns, allowing the read to continue against guest memory even though the color samples reside only in the host image. Preserve the refusal for read accesses; retire the guard only when the overlapping access establishes that the allocation is being reused.

Non-blocking

None.

Not verified

  • Tests and builds were not run; the test results in the PR description are author reported.
  • core/libs/prx/libSceAgcDriver/tests/Graphics.cpp was excluded from the review folder; only its changed hunk was read through the reader.
  • The complete contents of the included changed files were not read. Targeted ranges were read in DepthSurface.cpp and MultisampleTarget.cpp; the diff was inspected for the other changes.

To get this to a good state

Keep read accesses from proceeding after retiring a multisampled color guard. Add or update regression coverage for CPU, texture, and DMA source reads against a resident target, then rerun the relevant AGC tests.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6013448583 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6808#pullrequestreview-6013448583). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-22T17:13:21Z. **Review:** CHANGES_REQUESTED --- # Reviewed — changes requested A guest read overlapping a guarded multisampled color target now retires the guard and proceeds, exposing stale guest bytes while the rendered samples remain only in the host image. ## What I ran Reviewed head `734edb5c279d2f9de101d8ecf555f55b6f40d613` from the prepared diff and targeted reader context. No tests or build commands were run. ## Results | Check | Result | Note | |---|---|---| | Diff review | passed | Prepared change inspected | | Targeted source review | passed | Guard callers and relevant implementation inspected | | Tests and build | not run | No commands executed | ## Findings ### Blocking - `core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cpp:538` — `RequireNoMultisampleTarget` is called for CPU reads, texture reads, and DMA source reads as well as target reuse. On any overlap this change removes the guard and returns, allowing the read to continue against guest memory even though the color samples reside only in the host image. Preserve the refusal for read accesses; retire the guard only when the overlapping access establishes that the allocation is being reused. ### Non-blocking None. ## Not verified - Tests and builds were not run; the test results in the PR description are author reported. - `core/libs/prx/libSceAgcDriver/tests/Graphics.cpp` was excluded from the review folder; only its changed hunk was read through the reader. - The complete contents of the included changed files were not read. Targeted ranges were read in `DepthSurface.cpp` and `MultisampleTarget.cpp`; the diff was inspected for the other changes. ## To get this to a good state Keep read accesses from proceeding after retiring a multisampled color guard. Add or update regression coverage for CPU, texture, and DMA source reads against a resident target, then rerun the relevant AGC tests.
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/6808:upstream-pr/6808'
git switch 'upstream-pr/6808'

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