fix(agc): take depth fast clears from HTILE written by any kernel #5627

Merged
AlxcBTW merged 4 commits from upstream-pr/5627 into main 2026-10-15 12:52:35 +00:00
AlxcBTW commented 2026-10-14 02:08:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-14T02:08:34Z.


What

Supersedes #2053, as @oneandonlydean asked there. @esatturan's commit is kept with his authorship, rebased onto current main, with three commits of ours on top: two answer the review on #2053 and one routes native-owned depth binds around the generic path (the review on this PR).

#2053 reads a depth target's HTILE at bind when it was written since it was last read. If every word marks the depth (ZMask 0) or the stencil (SMem 0) cleared, the surface takes the pending fast clear and the words are stored back as expanded. That covers clears made by kernels the fill hooks do not recognize (PPSA29141's InvokeHTileClearComputeShader), and the store-back also matters for titles that read their HTILE after drawing (Sword of the Sea, below).

Commits, bottom to top:

  1. fix(agc): take depth fast clears from HTILE written by any kernel is @esatturan's #2053 commit, rebased: the store-back fits main's DepthSurfaceView, the debt entry moved to docs/dev/debt/libSceAgcDriver.md, a duplicate GuestMemory.hpp include is gone, and agc_driver_depth_htile_write counts its tiles itself because main's harness has no HtileBytes.
  2. fix(agc): read and store back the whole pipe-aligned HTILE outside the surfaces lock
  3. fix(agc): take a slice of a depth array from its own HTILE only when its words are uniform
  4. fix(agc): route native-owned depth binds before the HTILE read and store-back

What changed against #2053:

  • Whole metadata. The read covered tiles * 4 bytes from DB_HTILE_DATA_BASE. main models the HTILE as the pipe-aligned SW_64KB_Z_X metadata (HtileMetadataBytes, the extent HtileFillCovers takes). With the HTILE equation of Sword of the Sea's Nanite export shader, 1856 of the 32400 tile words of a 1920x1080 surface lie past the first tiles * 4 bytes and would keep ZMask 0 after a store-back. The read and the store-back now cover the whole metadata. Both wait for recorded work over the range, so they run before DepthSurfaceView takes the surfaces mutex.

  • GPU-written HTILE, two frames in a row (@oneandonlydean's and @adriadam10's request, PPSA01802). A fill or clear the driver recognizes over an HTILE drops the range's last-read generation, so the next bind reads and stores back again even when the write tracker did not see the stores. A bind also reads the words whenever the recorder has a pending write over the HTILE. agc_driver_depth_fast_clear_submit gets a case where an unrecognized kernel (the fill kernel behind an s_nop, so no matcher takes it) clears the HTILE on two consecutive frames and both clears are taken.

  • Slices of a depth array (@XairRrR's data). Since #5111 a slice's HTILE is at DB_HTILE_DATA_BASE + slice × HtileMetadataBytes(extent). The HTILE word layout is only modelled for slice 0: XairRrR's fit on PPSA05684 shows slices 1 to 3 need extra Z terms (X8 and Y8 also take Z0 and Z1) that no GFX10_HTILE_SW_PATTERN entry has. So a slice of 1 or more takes the clear and the store-back only when all its HTILE words are equal, which decodes the same under any layout (PPSA05684's boat level binds slices 4 and 5 of arrays whose HTILE is a uniform 0xfffffff0). Otherwise it is refused and its words are left alone. DepthTarget::firstSlice carries DB_DEPTH_VIEW SLICE_START.

  • Tests. @esatturan's agc_driver_depth_htile_write is kept; its HTILE arrays now hold the whole metadata. New in agc_driver_depth_fast_clear_submit:

    • a draw after a DMA fast clear (depth only, then depth and stencil) leaves every HTILE word expanded (0xfffc000f / 0xfffff3ff); this fails on main, where the words stay 0;
    • two consecutive unrecognized-kernel clears are both taken;
    • slice 1 with HTILE words that are not all equal is refused (no clear, words not stored back, slice 0 untouched);
    • slice 1 with equal words takes the clear and stores it back as expanded.

    agc_driver_graphics checks the decoded slice.

  • The debt entry "HTILE written by other kernels" records what is still open: the slice layout above, and per-tile clear values of a depth-only HTILE (ZMask 0 everywhere but different Min/Max Z, as in PPSA05684's cascades), which are still taken as a whole-surface clear to DB_DEPTH_CLEAR.

  • Not in this PR: the store-back is a CPU write after the bind-time read. Recording it as a GPU fill in stream order, as @XairRrR does locally, would also remove the wait on pending HTILE writes.

Composition with #5496, #5524 and #5554. #5496 and #5524 are on main: the native multisampled depth owner guards its depth and HTILE ranges, and DepthSurfaceView takes GuestMemory::GpuMutex() before the surfaces mutex. The expanded store-back is a guest write over an owner's HTILE, which the owner refuses, so commit 4 decides before the store-back whether the bind belongs to the owner (@adriadam10's request, and the routing @Amoenus and I agreed on here):

  • DepthSurfaceView calls RoutesToNativeDepthOwner first and skips the HTILE read and store-back when it is true. It is true for every multisampled target (it is the native owner or is about to be created as one, and the owner's import validates the HTILE as the guest left it) and for any target whose HTILE overlaps a resident depth guard (a single-sample alias of an owner's metadata). Those binds go on to the existing owner and creation path with its own refusals. Single-sample targets that do not alias an owner are unchanged. This replaces the samples != 1 early return in the store-back.
  • Lock order: the HTILE read and store-back still run before GpuMutex() is taken, because the read waits for recorded work; the routing check takes only the shared depth guard mutex with no other lock held.
  • NativeMultisampleDepth binds a native-owned target twice and a single-sample alias of its HTILE, with HTILE words of 0, and checks the words are untouched and the alias is refused by the owner path.

#5554 builds on #5524 and does not need the generic store-back.

Evidence: Sword of the Sea (PPSA25344, Unreal Engine 5)

The title needs the store-back for a different reason than the clear detection: it reads its HTILE after drawing.

  • It fast-clears its depth HTILE every frame with the memory-value fill (#3816's MatchMemoryValueFill), so the clear itself is already taken on main. The guest HTILE then keeps ZMask 0 for the whole frame, because our depth draws never update it.
  • After the depth prepass, the Nanite depth export runs as compute, one wave per 8x8 tile. It loads the tile's HTILE word and branches on ZMask: 0 skips the depth read and takes the scene depth as the clear value, 15 reads the depth per pixel, and other values are decoded as planes. SMem selects the same paths for the stencil.
  • So every tile reads as cleared, and Nanite depth wins wherever Nanite has geometry, including behind closer non-Nanite meshes. The shading mask sends those pixels to the Nanite material pass, which paints the background material over what the base pass wrote. On screen, the far half of the player's sword and parts of the cloak turn black.
  • Frame journal replay of one such frame on NVIDIA. As things are, the depth along the blade at the export's output is 0.119 / 0.132 on the near half, then 0.0016 / 0.0020 / 0.0021 (the Nanite background) on the far half. The shading mask marks the far pixels as Nanite, and every Nanite sample in the viewport (159313 px) replaced the scene depth. With expanded HTILE words after the depth draws, the depth is 0.119 / 0.132 / 0.135 / 0.144 / 0.154 along the whole blade, the shading mask is 0, and the base pass survives the Nanite material pass.
  • The sword is slice 0, so it does not depend on the slice rule.

Tested

  • Fork CI on an earlier head of this stack (ci/lab/htile2053, based on main 5a81f6085, run 38497597289): Linux (lavapipe, GCC) 1092 of 1092 tests pass, including agc_driver_graphics and every agc_driver_depth_* test; Windows (WinLibs GCC 15.2) builds and 1112 of 1112 pass, the agc_driver_depth_* execution tests skipped for lack of a Vulkan device. Not rerun on this head (rebased onto main fdea36b83, with the routing commit); a new fork CI run will be linked here.
  • On an RTX 5070 Laptop (NVIDIA, Windows 11, MinGW-w64 GCC 15.2), all ten agc_driver_depth_* execution tests passed on the earlier rebase of this stack (fix/htile-store-back-rebase, without the slice commit, on the main of 2026-10-13; driver not recorded). Not rerun on this head.
  • Sword of the Sea, sword: the replay above ran on a diagnostic build, not this branch. That build writes expanded HTILE words after each depth draw, the same words this store-back leaves. Our in-game rows with the store-back have not reached the sword scene yet; they stalled before gameplay for reasons unrelated to HTILE. So the in-game sword is not confirmed on this code.
  • Sword of the Sea, menu: its black blobs were fixed by #3816's memory-value fill and its missing glow by #4268, both on main. The menu gate (no dark pixels, top luma 88 at frame 585) passed on 2026-10-12 on our lab build sots/menu-boot-m1 (21d699737), which has no store-back. That run is not evidence for this PR.
  • FPV Simulator (PPSA10698, Unity): with #2053's commit and #374 on an older main (57f96fd2), the levels rendered correctly (my comment on #2053). Not rerun on this head.
  • Not rerun on this head: PPSA29141 (the title in #2053's description), PPSA01802 and PPSA05684. @alfalfa-star and @XairRrR offered on #2053 to test it on Kena and Uncharted.

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 (#5111 is merged; supersedes #2053)
  • Unblocks: PPSA25344, PPSA29141 (no Game bring-up discussion for either yet)
  • GPUs tested: none on this head (lavapipe in the PR CI); NVIDIA RTX 5070 Laptop on the earlier rebase, see Tested
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4851946317 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5627). Originally posted by [AlxcBTW](https://github.com/AlxcBTW) on 2026-10-14T02:08:34Z. --- ### What Supersedes #2053, as @oneandonlydean asked there. @esatturan's commit is kept with his authorship, rebased onto current `main`, with three commits of ours on top: two answer the review on #2053 and one routes native-owned depth binds around the generic path (the review on this PR). #2053 reads a depth target's HTILE at bind when it was written since it was last read. If every word marks the depth (ZMask 0) or the stencil (SMem 0) cleared, the surface takes the pending fast clear and the words are stored back as expanded. That covers clears made by kernels the fill hooks do not recognize (PPSA29141's `InvokeHTileClearComputeShader`), and the store-back also matters for titles that read their HTILE after drawing (Sword of the Sea, below). Commits, bottom to top: 1. `fix(agc): take depth fast clears from HTILE written by any kernel` is @esatturan's #2053 commit, rebased: the store-back fits `main`'s `DepthSurfaceView`, the debt entry moved to `docs/dev/debt/libSceAgcDriver.md`, a duplicate `GuestMemory.hpp` include is gone, and `agc_driver_depth_htile_write` counts its tiles itself because `main`'s harness has no `HtileBytes`. 2. `fix(agc): read and store back the whole pipe-aligned HTILE outside the surfaces lock` 3. `fix(agc): take a slice of a depth array from its own HTILE only when its words are uniform` 4. `fix(agc): route native-owned depth binds before the HTILE read and store-back` What changed against #2053: - **Whole metadata.** The read covered `tiles * 4` bytes from `DB_HTILE_DATA_BASE`. `main` models the HTILE as the pipe-aligned SW_64KB_Z_X metadata (`HtileMetadataBytes`, the extent `HtileFillCovers` takes). With the HTILE equation of Sword of the Sea's Nanite export shader, 1856 of the 32400 tile words of a 1920x1080 surface lie past the first `tiles * 4` bytes and would keep ZMask 0 after a store-back. The read and the store-back now cover the whole metadata. Both wait for recorded work over the range, so they run before `DepthSurfaceView` takes the surfaces mutex. - **GPU-written HTILE, two frames in a row** (@oneandonlydean's and @adriadam10's request, PPSA01802). A fill or clear the driver recognizes over an HTILE drops the range's last-read generation, so the next bind reads and stores back again even when the write tracker did not see the stores. A bind also reads the words whenever the recorder has a pending write over the HTILE. `agc_driver_depth_fast_clear_submit` gets a case where an unrecognized kernel (the fill kernel behind an `s_nop`, so no matcher takes it) clears the HTILE on two consecutive frames and both clears are taken. - **Slices of a depth array** (@XairRrR's data). Since #5111 a slice's HTILE is at `DB_HTILE_DATA_BASE + slice × HtileMetadataBytes(extent)`. The HTILE word layout is only modelled for slice 0: XairRrR's fit on PPSA05684 shows slices 1 to 3 need extra Z terms (X8 and Y8 also take Z0 and Z1) that no `GFX10_HTILE_SW_PATTERN` entry has. So a slice of 1 or more takes the clear and the store-back only when all its HTILE words are equal, which decodes the same under any layout (PPSA05684's boat level binds slices 4 and 5 of arrays whose HTILE is a uniform `0xfffffff0`). Otherwise it is refused and its words are left alone. `DepthTarget::firstSlice` carries `DB_DEPTH_VIEW` SLICE_START. - **Tests.** @esatturan's `agc_driver_depth_htile_write` is kept; its HTILE arrays now hold the whole metadata. New in `agc_driver_depth_fast_clear_submit`: - a draw after a DMA fast clear (depth only, then depth and stencil) leaves every HTILE word expanded (`0xfffc000f` / `0xfffff3ff`); this fails on `main`, where the words stay 0; - two consecutive unrecognized-kernel clears are both taken; - slice 1 with HTILE words that are not all equal is refused (no clear, words not stored back, slice 0 untouched); - slice 1 with equal words takes the clear and stores it back as expanded. `agc_driver_graphics` checks the decoded slice. - The debt entry "HTILE written by other kernels" records what is still open: the slice layout above, and per-tile clear values of a depth-only HTILE (ZMask 0 everywhere but different Min/Max Z, as in PPSA05684's cascades), which are still taken as a whole-surface clear to `DB_DEPTH_CLEAR`. - Not in this PR: the store-back is a CPU write after the bind-time read. Recording it as a GPU fill in stream order, as @XairRrR does locally, would also remove the wait on pending HTILE writes. **Composition with #5496, #5524 and #5554.** #5496 and #5524 are on `main`: the native multisampled depth owner guards its depth and HTILE ranges, and `DepthSurfaceView` takes `GuestMemory::GpuMutex()` before the surfaces mutex. The expanded store-back is a guest write over an owner's HTILE, which the owner refuses, so commit 4 decides before the store-back whether the bind belongs to the owner (@adriadam10's request, and the routing @Amoenus and I agreed on here): - `DepthSurfaceView` calls `RoutesToNativeDepthOwner` first and skips the HTILE read and store-back when it is true. It is true for every multisampled target (it is the native owner or is about to be created as one, and the owner's import validates the HTILE as the guest left it) and for any target whose HTILE overlaps a resident depth guard (a single-sample alias of an owner's metadata). Those binds go on to the existing owner and creation path with its own refusals. Single-sample targets that do not alias an owner are unchanged. This replaces the `samples != 1` early return in the store-back. - Lock order: the HTILE read and store-back still run before `GpuMutex()` is taken, because the read waits for recorded work; the routing check takes only the shared depth guard mutex with no other lock held. - `NativeMultisampleDepth` binds a native-owned target twice and a single-sample alias of its HTILE, with HTILE words of 0, and checks the words are untouched and the alias is refused by the owner path. #5554 builds on #5524 and does not need the generic store-back. ### Evidence: Sword of the Sea (PPSA25344, Unreal Engine 5) The title needs the store-back for a different reason than the clear detection: it reads its HTILE after drawing. - It fast-clears its depth HTILE every frame with the memory-value fill (#3816's `MatchMemoryValueFill`), so the clear itself is already taken on `main`. The guest HTILE then keeps ZMask 0 for the whole frame, because our depth draws never update it. - After the depth prepass, the Nanite depth export runs as compute, one wave per 8x8 tile. It loads the tile's HTILE word and branches on ZMask: 0 skips the depth read and takes the scene depth as the clear value, 15 reads the depth per pixel, and other values are decoded as planes. SMem selects the same paths for the stencil. - So every tile reads as cleared, and Nanite depth wins wherever Nanite has geometry, including behind closer non-Nanite meshes. The shading mask sends those pixels to the Nanite material pass, which paints the background material over what the base pass wrote. On screen, the far half of the player's sword and parts of the cloak turn black. - Frame journal replay of one such frame on NVIDIA. As things are, the depth along the blade at the export's output is 0.119 / 0.132 on the near half, then 0.0016 / 0.0020 / 0.0021 (the Nanite background) on the far half. The shading mask marks the far pixels as Nanite, and every Nanite sample in the viewport (159313 px) replaced the scene depth. With expanded HTILE words after the depth draws, the depth is 0.119 / 0.132 / 0.135 / 0.144 / 0.154 along the whole blade, the shading mask is 0, and the base pass survives the Nanite material pass. - The sword is slice 0, so it does not depend on the slice rule. ### Tested - Fork CI on an earlier head of this stack (`ci/lab/htile2053`, based on `main` `5a81f6085`, [run 38497597289](https://github.com/AlxcBTW/AnyPS5/actions/runs/38497597289)): Linux (lavapipe, GCC) 1092 of 1092 tests pass, including `agc_driver_graphics` and every `agc_driver_depth_*` test; Windows (WinLibs GCC 15.2) builds and 1112 of 1112 pass, the `agc_driver_depth_*` execution tests skipped for lack of a Vulkan device. **Not rerun on this head** (rebased onto `main` `fdea36b83`, with the routing commit); a new fork CI run will be linked here. - On an RTX 5070 Laptop (NVIDIA, Windows 11, MinGW-w64 GCC 15.2), all ten `agc_driver_depth_*` execution tests passed on the earlier rebase of this stack (`fix/htile-store-back-rebase`, without the slice commit, on the `main` of 2026-10-13; driver not recorded). Not rerun on this head. - Sword of the Sea, sword: the replay above ran on a diagnostic build, not this branch. That build writes expanded HTILE words after each depth draw, the same words this store-back leaves. Our in-game rows with the store-back have not reached the sword scene yet; they stalled before gameplay for reasons unrelated to HTILE. So the in-game sword is not confirmed on this code. - Sword of the Sea, menu: its black blobs were fixed by #3816's memory-value fill and its missing glow by #4268, both on `main`. The menu gate (no dark pixels, top luma 88 at frame 585) passed on 2026-10-12 on our lab build `sots/menu-boot-m1` (`21d699737`), which has no store-back. That run is not evidence for this PR. - FPV Simulator (PPSA10698, Unity): with #2053's commit and #374 on an older `main` (`57f96fd2`), the levels rendered correctly (my comment on #2053). Not rerun on this head. - Not rerun on this head: PPSA29141 (the title in #2053's description), PPSA01802 and PPSA05684. @alfalfa-star and @XairRrR offered on #2053 to test it on Kena and Uncharted. ### 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 (#5111 is merged; supersedes #2053) - [x] Unblocks: PPSA25344, PPSA29141 (no Game bring-up discussion for either yet) - [x] GPUs tested: none on this head (lavapipe in the PR CI); NVIDIA RTX 5070 Laptop on the earlier rebase, see Tested - [x] AI-assisted: yes
Amoenus commented 2026-10-14 03:16:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Amoenus on 2026-10-14T03:16:13Z.


@AlxcBTW I agree with the composition contract you described: native-owned binds must reach the guarded owner before the generic HTILE read/store-back. If #5627 lands first, I will carry that routing and a regression in our native-depth stack; if our stack lands first, your stated follow-up here handles it. #5554 still depends on #5524/#5111, transitively #5496/#4820; it does not require the generic store-back implementation. Our refreshed dependency composition passes repeated native-depth tests on NVIDIA and AMD, but I have not tested it together with #5627 and make no combined-head compatibility claim.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6160079490 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5627#issuecomment-6160079490). Originally posted by [Amoenus](https://github.com/Amoenus) on 2026-10-14T03:16:13Z. --- @AlxcBTW I agree with the composition contract you described: native-owned binds must reach the guarded owner before the generic HTILE read/store-back. If #5627 lands first, I will carry that routing and a regression in our native-depth stack; if our stack lands first, your stated follow-up here handles it. #5554 still depends on #5524/#5111, transitively #5496/#4820; it does not require the generic store-back implementation. Our refreshed [dependency composition](https://github.com/Amoenus/AnyPS5/commit/21744b0eecc9eab72e0c43b4dcaefe5bcef9a5b4) passes repeated native-depth tests on NVIDIA and AMD, but I have not tested it together with #5627 and make no combined-head compatibility claim.
adriadam10 commented 2026-10-15 11:28:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-15T11:28:51Z.

Review: CHANGES_REQUESTED


This no longer rebases onto current main, and the part that conflicts needs a decision from you:

  • #5111 is merged, so its commit drops out. The next commit then conflicts in DepthSurface.cpp, State.cpp, Dispatch.cpp and tests/DepthSurfaceReuse.cpp, plus the debt entry.
  • main now has the native multisampled depth owner (#5496). DepthSurfaceView takes GuestMemory::GpuMutex() before surfacesMutex(), and RequireNoResidentDepthRead_nid_no_patch throws on a guest write over an owner's range (DepthSurface.cpp on main, around line 917). storeBackClearedHtile writes expanded words over the HTILE of every depth target, so a bind of a native-owned target would hit that guard. Your description says whichever PR lands second carries the routing: that is this one now. Please route a native-owned bind to the owner's path before the read and store-back, with a test that binds one.
  • The read and store-back were placed outside the surfaces lock to wait on recorded work. With the new lock order, check that they still run before GpuMutex is taken, or say why not.

After the rebase, rerun agc_driver_depth_htile_write, agc_driver_depth_fast_clear_submit, agc_driver_graphics and the native-depth tests. Happy to re-review then.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5532375645 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5627#pullrequestreview-5532375645). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-15T11:28:51Z. **Review:** CHANGES_REQUESTED --- This no longer rebases onto current `main`, and the part that conflicts needs a decision from you: - #5111 is merged, so its commit drops out. The next commit then conflicts in `DepthSurface.cpp`, `State.cpp`, `Dispatch.cpp` and `tests/DepthSurfaceReuse.cpp`, plus the debt entry. - `main` now has the native multisampled depth owner (#5496). `DepthSurfaceView` takes `GuestMemory::GpuMutex()` before `surfacesMutex()`, and `RequireNoResidentDepthRead_nid_no_patch` throws on a guest write over an owner's range (`DepthSurface.cpp` on `main`, around line 917). `storeBackClearedHtile` writes expanded words over the HTILE of every depth target, so a bind of a native-owned target would hit that guard. Your description says whichever PR lands second carries the routing: that is this one now. Please route a native-owned bind to the owner's path before the read and store-back, with a test that binds one. - The read and store-back were placed outside the surfaces lock to wait on recorded work. With the new lock order, check that they still run before `GpuMutex` is taken, or say why not. After the rebase, rerun `agc_driver_depth_htile_write`, `agc_driver_depth_fast_clear_submit`, `agc_driver_graphics` and the native-depth tests. Happy to re-review then.
AlxcBTW commented 2026-10-15 11:57:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-15T11:57:34Z.


Thanks @adriadam10. The branch is rebased onto current main (fdea36b83, after #5524) and the routing is in. Head: 139e3b86e.

  • #5111 and the conflicts. The #5111 commit is gone. Of the four files and the debt entry you listed, only the include block of DepthSurface.cpp conflicted: main now includes GuestAllocations.hpp next to GuestMemory.hpp, and @esatturan's commit drops the duplicate GuestMemory.hpp include, so both of main's lines stay and the duplicate goes. State.cpp, Dispatch.cpp, tests/DepthSurfaceReuse.cpp and the debt file merged without conflict. The slice field is firstSlice now.
  • Routing a native-owned bind. New commit fix(agc): route native-owned depth binds before the HTILE read and store-back. DepthSurfaceView (DepthSurface.cpp:1050) asks RoutesToNativeDepthOwner (:914) first and skips storeBackClearedHtile when it says yes. It says yes for every multisampled target, because that target either is the native owner or is about to be created as one, and the owner's import checks the HTILE as the guest left it (htileProvesClear, UnchangedSinceAll), so an expanded store-back before the import would change what it validates. It also says yes for any target whose HTILE overlaps a resident depth guard, which is a single-sample alias of an owner's metadata. Both go on to the existing creation and owner path, which keeps its own refusals ("layout or metadata changed", "fast-clear transition is not implemented"). This replaces the blunt samples != 1u early return inside storeBackClearedHtile; the multisampled half is kept, as the first rule above, because the not-yet-created owner has no guard to detect. Single-sample targets that do not alias an owner are unchanged.
  • Test. CheckHtileRouting in tests/execution/NativeMultisampleDepth.cpp (run for every format and sample count of agc_driver_native_multisample_depth): HTILE words of 0 (what the generic path would take as a clear), then bind the native target, rebind it, and bind a single-sample alias over its HTILE. The words in guest memory must stay 0 after each, the alias must be refused by the owner path ("layout or metadata changed"), and nothing may throw from the guard on the generic path.
  • Lock order. The read and the store-back still run before GpuMutex() is taken: DepthSurfaceView calls them at :1050, GpuMutex() is taken at :1051, and the surfaces mutex after it. They have to stay outside because the read waits for recorded work. The routing check takes only the shared depth guard mutex, with no other lock held, so it cannot invert the GpuMutex -> surfacesMutex order; the guard mutex is otherwise taken inside those two.

To rerun: agc_driver_depth_htile_write, agc_driver_depth_fast_clear_submit, agc_driver_graphics, agc_driver_native_multisample_depth, agc_driver_native_depth_retirement, and the other agc_driver_depth_* tests. I have not built or run this head locally; the PR's CI runs on this push and I'll follow up on its result.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6191487175 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5627#issuecomment-6191487175). Originally posted by [AlxcBTW](https://github.com/AlxcBTW) on 2026-10-15T11:57:34Z. --- Thanks @adriadam10. The branch is rebased onto current `main` (`fdea36b83`, after #5524) and the routing is in. Head: `139e3b86e`. - **#5111 and the conflicts.** The #5111 commit is gone. Of the four files and the debt entry you listed, only the include block of `DepthSurface.cpp` conflicted: `main` now includes `GuestAllocations.hpp` next to `GuestMemory.hpp`, and @esatturan's commit drops the duplicate `GuestMemory.hpp` include, so both of `main`'s lines stay and the duplicate goes. `State.cpp`, `Dispatch.cpp`, `tests/DepthSurfaceReuse.cpp` and the debt file merged without conflict. The slice field is `firstSlice` now. - **Routing a native-owned bind.** New commit `fix(agc): route native-owned depth binds before the HTILE read and store-back`. `DepthSurfaceView` (`DepthSurface.cpp:1050`) asks `RoutesToNativeDepthOwner` (`:914`) first and skips `storeBackClearedHtile` when it says yes. It says yes for every multisampled target, because that target either is the native owner or is about to be created as one, and the owner's import checks the HTILE as the guest left it (`htileProvesClear`, `UnchangedSinceAll`), so an expanded store-back before the import would change what it validates. It also says yes for any target whose HTILE overlaps a resident depth guard, which is a single-sample alias of an owner's metadata. Both go on to the existing creation and owner path, which keeps its own refusals ("layout or metadata changed", "fast-clear transition is not implemented"). This replaces the blunt `samples != 1u` early return inside `storeBackClearedHtile`; the multisampled half is kept, as the first rule above, because the not-yet-created owner has no guard to detect. Single-sample targets that do not alias an owner are unchanged. - **Test.** `CheckHtileRouting` in `tests/execution/NativeMultisampleDepth.cpp` (run for every format and sample count of `agc_driver_native_multisample_depth`): HTILE words of 0 (what the generic path would take as a clear), then bind the native target, rebind it, and bind a single-sample alias over its HTILE. The words in guest memory must stay 0 after each, the alias must be refused by the owner path ("layout or metadata changed"), and nothing may throw from the guard on the generic path. - **Lock order.** The read and the store-back still run before `GpuMutex()` is taken: `DepthSurfaceView` calls them at `:1050`, `GpuMutex()` is taken at `:1051`, and the surfaces mutex after it. They have to stay outside because the read waits for recorded work. The routing check takes only the shared depth guard mutex, with no other lock held, so it cannot invert the `GpuMutex` -> `surfacesMutex` order; the guard mutex is otherwise taken inside those two. To rerun: `agc_driver_depth_htile_write`, `agc_driver_depth_fast_clear_submit`, `agc_driver_graphics`, `agc_driver_native_multisample_depth`, `agc_driver_native_depth_retirement`, and the other `agc_driver_depth_*` tests. I have not built or run this head locally; the PR's CI runs on this push and I'll follow up on its result.
github-actions[bot] commented 2026-10-15 12:00:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T12:00:30Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#5372 docs/dev/debt/libSceAgcDriver.md L97-98
#6146 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp L10-11
#6292 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp L11
#6300 core/libs/prx/libSceAgcDriver/tests/execution/NativeMultisampleDepth.cpp L816

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
#1368 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
#1395 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
#4040 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
#4448 docs/dev/debt/libSceAgcDriver.md
#4650 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
docs/dev/debt/libSceAgcDriver.md
#5390 docs/dev/debt/libSceAgcDriver.md
#5499 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
docs/dev/debt/libSceAgcDriver.md
#5500 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
#5609 docs/dev/debt/libSceAgcDriver.md
#5761 docs/dev/debt/libSceAgcDriver.md
#5781 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
#5804 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
#5875 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
docs/dev/debt/libSceAgcDriver.md
#5884 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
docs/dev/debt/libSceAgcDriver.md
#5905 docs/dev/debt/libSceAgcDriver.md
#5925 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
docs/dev/debt/libSceAgcDriver.md
#6188 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
#6222 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
docs/dev/debt/libSceAgcDriver.md
#6235 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6191538559 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5627#issuecomment-6191538559). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-15T12:00:30Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #5372 | `docs/dev/debt/libSceAgcDriver.md` [L97-98](https://github.com/boykopovar/AnyPS5/blob/16af28e90ad4f6cc7fda5e4325bffcdaaa5a22bd/docs/dev/debt/libSceAgcDriver.md#L97-L98) | | | | #6146 | `core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp` [L10-11](https://github.com/boykopovar/AnyPS5/blob/16af28e90ad4f6cc7fda5e4325bffcdaaa5a22bd/core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp#L10-L11) | | | | #6292 | `core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp` [L11](https://github.com/boykopovar/AnyPS5/blob/16af28e90ad4f6cc7fda5e4325bffcdaaa5a22bd/core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp#L11) | | | | #6300 | `core/libs/prx/libSceAgcDriver/tests/execution/NativeMultisampleDepth.cpp` [L816](https://github.com/boykopovar/AnyPS5/blob/16af28e90ad4f6cc7fda5e4325bffcdaaa5a22bd/core/libs/prx/libSceAgcDriver/tests/execution/NativeMultisampleDepth.cpp#L816) | | | Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap. | Pull request | Shared files not compared | |---|---| | #1368 | `core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp` | | #1395 | `core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp`<br>`core/libs/prx/libSceAgcDriver/tests/Graphics.cpp` | | #4040 | `core/libs/prx/libSceAgcDriver/tests/Graphics.cpp` | | #4448 | `docs/dev/debt/libSceAgcDriver.md` | | #4650 | `core/libs/prx/libSceAgcDriver/tests/Graphics.cpp`<br>`docs/dev/debt/libSceAgcDriver.md` | | #5390 | `docs/dev/debt/libSceAgcDriver.md` | | #5499 | `core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp`<br>`core/libs/prx/libSceAgcDriver/tests/Graphics.cpp`<br>`docs/dev/debt/libSceAgcDriver.md` | | #5500 | `core/libs/prx/libSceAgcDriver/tests/Graphics.cpp` | | #5609 | `docs/dev/debt/libSceAgcDriver.md` | | #5761 | `docs/dev/debt/libSceAgcDriver.md` | | #5781 | `core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp` | | #5804 | `core/libs/prx/libSceAgcDriver/tests/Graphics.cpp` | | #5875 | `core/libs/prx/libSceAgcDriver/tests/Graphics.cpp`<br>`docs/dev/debt/libSceAgcDriver.md` | | #5884 | `core/libs/prx/libSceAgcDriver/tests/Graphics.cpp`<br>`docs/dev/debt/libSceAgcDriver.md` | | #5905 | `docs/dev/debt/libSceAgcDriver.md` | | #5925 | `core/libs/prx/libSceAgcDriver/tests/Graphics.cpp`<br>`docs/dev/debt/libSceAgcDriver.md` | | #6188 | `core/libs/prx/libSceAgcDriver/tests/Graphics.cpp` | | #6222 | `core/libs/prx/libSceAgcDriver/tests/Graphics.cpp`<br>`docs/dev/debt/libSceAgcDriver.md` | | #6235 | `core/libs/prx/libSceAgcDriver/tests/Graphics.cpp` |
adriadam10 commented 2026-10-15 12:02:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-15T12:02:53Z.

Review: APPROVED


Re-checked against the new head:

  • Rebase is clean, #5111 is gone.
  • RoutesToNativeDepthOwner sends multisampled targets and any target whose HTILE overlaps a resident depth guard past the generic read and store-back. NativeMultisampleDepth fails if that routing is disabled.
  • The read and store-back still run before GpuMutex(); the routing check only takes the shared guard mutex.

Ran agc_driver_graphics, agc_driver_depth_fast_clear, agc_driver_depth_fast_clear_submit, agc_driver_depth_htile_write, agc_driver_native_multisample_depth and agc_driver_native_depth_retirement on lavapipe: all pass. The new submit and htile_write cases fail without the change. Merging once the full Build is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5532773163 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5627#pullrequestreview-5532773163). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-15T12:02:53Z. **Review:** APPROVED --- Re-checked against the new head: - Rebase is clean, #5111 is gone. - `RoutesToNativeDepthOwner` sends multisampled targets and any target whose HTILE overlaps a resident depth guard past the generic read and store-back. `NativeMultisampleDepth` fails if that routing is disabled. - The read and store-back still run before `GpuMutex()`; the routing check only takes the shared guard mutex. Ran `agc_driver_graphics`, `agc_driver_depth_fast_clear`, `agc_driver_depth_fast_clear_submit`, `agc_driver_depth_htile_write`, `agc_driver_native_multisample_depth` and `agc_driver_native_depth_retirement` on lavapipe: all pass. The new submit and htile_write cases fail without the change. Merging once the full Build is green.
AlxcBTW commented 2026-10-15 12:52:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-15T12:52:59Z.


Rebased again onto main after #5554 landed (head 69b413ed8). No conflicts: #5554's strict native clear branch runs first in NoteHtileDepthClear, our routing in DepthSurfaceView keeps native-owned binds off the generic HTILE read/store-back, and CheckHtileRouting is unchanged against the merged owner API.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6192515769 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5627#issuecomment-6192515769). Originally posted by [AlxcBTW](https://github.com/AlxcBTW) on 2026-10-15T12:52:59Z. --- Rebased again onto `main` after #5554 landed (head `69b413ed8`). No conflicts: #5554's strict native clear branch runs first in `NoteHtileDepthClear`, our routing in `DepthSurfaceView` keeps native-owned binds off the generic HTILE read/store-back, and `CheckHtileRouting` is unchanged against the merged owner API.
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!5627
No description provided.