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

Closed
esatturan wants to merge 8 commits from upstream-pr/2053 into main
esatturan commented 2026-10-09 06:00:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by esatturan on 2026-10-09T06:00:25Z.


Depends on #374: this branch is built on its head 3a99fa18, and only the last commit belongs to this PR.

What

#374 takes a depth fast clear when the driver sees a DMA_DATA fill or a buffer-fill kernel it recognizes over the HTILE. PPSA29141 clears its depth every frame with its own compute kernel (InvokeHTileClearComputeShader in Unity's ClearMRT pass), which neither hook sees. Its depth kept every earlier frame, and moving objects left black trails.

  • When a depth target is bound and its HTILE was written since it was last read, the words are read. When every word marks the depth (ZMask 0) or the stencil (SMem 0, with DB_STENCIL_INFO.TILE_STENCIL_DISABLE clear) cleared, the surface takes #374's pending fast clear.
  • The words are then stored back as expanded (depth only: ZMask 15 over the full Z range; with stencil: ZMask 15, and SMem, SR1 and SR0 3). Only the title's next clear clears the surface again, with or without write tracking.
  • The word layouts are Mesa radv's for GFX10. Partly cleared metadata and the compression state draws leave in HTILE are not modelled; both are recorded in TechnicalDebt.

Tested

Windows 11, i7-13650HX, RTX 4070 Laptop, MinGW-w64 GCC 15.2.

  • New agc_driver_depth_htile_write: the HTILE is written in memory, as a kernel the driver does not recognize writes it, followed by a depth-tested or stencil-tested draw. It covers the depth-only and depth-plus-stencil layouts, an HTILE with one tile left expanded (no clear), the stored-back words, and a later draw keeping the depth or stencil written after the clear. It fails on #374's head and passes here. agc_driver_depth_fast_clear, agc_driver_depth_fast_clear_submit and agc_driver_graphics pass.
  • Full ctest on current main (c6e3aa76) merged with this branch, the other LEGO Party! PRs and #1482: 547/547 pass. On Windows, main's libs step currently fails with duplicate patched export name: LibwuIonIBw: #1714 added APS5_EXPORTs for sceVideoOutAddVrrActiveStatusEvent and sceVideoOutAddVrrStatusFlagsPrivilege, whose names the NID table already maps. Those two lines were removed locally for the run.
  • PPSA29141, with the first version of this change (the HTILE read at bind, the planes cleared directly instead of through #374's pending clear): the title scene and minigames render without trails. Title runs were on the base these PRs had before review. PPSA29141 was converted with #846's --module-dir for its plugins, and #846 no longer merges with today's main, so the title was not converted and run again on it.

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 in TechnicalDebt
  • 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: #374
  • AI-assisted: yes (Claude Code)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4796626633 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2053). Originally posted by [esatturan](https://github.com/esatturan) on 2026-10-09T06:00:25Z. --- Depends on #374: this branch is built on its head `3a99fa18`, and only the last commit belongs to this PR. ### What #374 takes a depth fast clear when the driver sees a `DMA_DATA` fill or a buffer-fill kernel it recognizes over the HTILE. PPSA29141 clears its depth every frame with its own compute kernel (`InvokeHTileClearComputeShader` in Unity's `ClearMRT` pass), which neither hook sees. Its depth kept every earlier frame, and moving objects left black trails. - When a depth target is bound and its HTILE was written since it was last read, the words are read. When every word marks the depth (ZMask 0) or the stencil (SMem 0, with `DB_STENCIL_INFO.TILE_STENCIL_DISABLE` clear) cleared, the surface takes #374's pending fast clear. - The words are then stored back as expanded (depth only: ZMask 15 over the full Z range; with stencil: ZMask 15, and SMem, SR1 and SR0 3). Only the title's next clear clears the surface again, with or without write tracking. - The word layouts are Mesa radv's for GFX10. Partly cleared metadata and the compression state draws leave in HTILE are not modelled; both are recorded in TechnicalDebt. ### Tested Windows 11, i7-13650HX, RTX 4070 Laptop, MinGW-w64 GCC 15.2. - New `agc_driver_depth_htile_write`: the HTILE is written in memory, as a kernel the driver does not recognize writes it, followed by a depth-tested or stencil-tested draw. It covers the depth-only and depth-plus-stencil layouts, an HTILE with one tile left expanded (no clear), the stored-back words, and a later draw keeping the depth or stencil written after the clear. It fails on #374's head and passes here. `agc_driver_depth_fast_clear`, `agc_driver_depth_fast_clear_submit` and `agc_driver_graphics` pass. - Full `ctest` on current `main` (`c6e3aa76`) merged with this branch, the other LEGO Party! PRs and #1482: 547/547 pass. On Windows, `main`'s `libs` step currently fails with `duplicate patched export name: LibwuIonIBw`: #1714 added `APS5_EXPORT`s for `sceVideoOutAddVrrActiveStatusEvent` and `sceVideoOutAddVrrStatusFlagsPrivilege`, whose names the NID table already maps. Those two lines were removed locally for the run. - PPSA29141, with the first version of this change (the HTILE read at bind, the planes cleared directly instead of through #374's pending clear): the title scene and minigames render without trails. Title runs were on the base these PRs had before review. PPSA29141 was converted with #846's `--module-dir` for its plugins, and #846 no longer merges with today's `main`, so the title was not converted and run again on it. ### 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 in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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: #374 - [x] AI-assisted: yes (Claude Code)
oneandonlydean commented 2026-10-09 09:23:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-09T09:23:00Z.


Please split this into one PR per change: the HTILE fast clear, depth-surface reuse, unreachable V#s read as null, and stencil clears through DB_RENDER_CONTROL, each with a test that fails on main. Leave out the debug aids (APS5_TRACE_MARKERS, APS5_DUMP_FRAMES_AFTER, APS5_SAMPLE_THREADS_AFTER) and the code comments. The HTILE clear behind PPSA29141's trails is the one to start with.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6078131252 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2053#issuecomment-6078131252). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-09T09:23:00Z. --- Please split this into one PR per change: the HTILE fast clear, depth-surface reuse, unreachable V#s read as null, and stencil clears through `DB_RENDER_CONTROL`, each with a test that fails on main. Leave out the debug aids (`APS5_TRACE_MARKERS`, `APS5_DUMP_FRAMES_AFTER`, `APS5_SAMPLE_THREADS_AFTER`) and the code comments. The HTILE clear behind PPSA29141's trails is the one to start with.
Angel21PC commented 2026-10-09 14:32:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Angel21PC on 2026-10-09T14:32:01Z.


Same pattern in Unreal Engine 5. Poppy Playtime: Chapter 4 (PPSA25063) clears its scene depth's HTILE with two back-to-back dispatches (1536 groups over 0x60000 bytes) of generic buffer-fill kernels it also uses for many other buffers, not with a fill the driver recognizes. Without a clear on the next bind, the depth prepass and base pass fail the depth test over almost the whole screen, and the lit scene comes out flat and dark (mean frame brightness 7-8 of 255; 21-24 with the clear, on a local build with #454). With LEGO Party! here and Astro's Playroom in #374, that makes three titles whose HTILE clear goes through a compute kernel the driver does not match, so reading the HTILE covers more than matching kernels.

I have the same check locally, stacked on #454 but using only #374's fast-clear path: when a depth target is bound and its HTILE, in write-watched memory, was written since the last bind and reads cleared on every tile, the surface takes the pending fast clear. It does not store the HTILE back, so it needs write-watched memory and clears again when other memory in the same 64 KiB tracking block is written; storing the words back as expanded, as this PR does, avoids that. It comes with an execution test that draws through a rewritten HTILE. Happy to share it if it helps the split.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6082999313 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2053#issuecomment-6082999313). Originally posted by [Angel21PC](https://github.com/Angel21PC) on 2026-10-09T14:32:01Z. --- Same pattern in Unreal Engine 5. Poppy Playtime: Chapter 4 (PPSA25063) clears its scene depth's HTILE with two back-to-back dispatches (1536 groups over 0x60000 bytes) of generic buffer-fill kernels it also uses for many other buffers, not with a fill the driver recognizes. Without a clear on the next bind, the depth prepass and base pass fail the depth test over almost the whole screen, and the lit scene comes out flat and dark (mean frame brightness 7-8 of 255; 21-24 with the clear, on a local build with #454). With LEGO Party! here and Astro's Playroom in #374, that makes three titles whose HTILE clear goes through a compute kernel the driver does not match, so reading the HTILE covers more than matching kernels. I have the same check locally, stacked on #454 but using only #374's fast-clear path: when a depth target is bound and its HTILE, in write-watched memory, was written since the last bind and reads cleared on every tile, the surface takes the pending fast clear. It does not store the HTILE back, so it needs write-watched memory and clears again when other memory in the same 64 KiB tracking block is written; storing the words back as expanded, as this PR does, avoids that. It comes with an execution test that draws through a rewritten HTILE. Happy to share it if it helps the split.
esatturan commented 2026-10-09 23:36:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by esatturan on 2026-10-09T23:36:07Z.


Split as asked. This PR is now only the HTILE clear; the others are their own PRs, all without the debug aids and code comments:

  • Stencil clears through DB_RENDER_CONTROL: #2504. On main with #1482, PPSA29141 stops there: depth/stencil clear, copy, resummarize or decompress draws (DB_RENDER_CONTROL) is unsupported (register 0x0 = 0x00000022).
  • Unreachable V#s read as null: #2505.
  • Depth-surface reuse: dropped in favour of #454, which retires a depth surface once a colour target or a written storage image covers it, which is the case PPSA29141 hits.

The HTILE part now builds on #374's pending fast clear instead of adding a second clear path. At bind, if the HTILE was written since it was last read and every tile reads cleared, the surface takes the clear, and the words are stored back as expanded. That covers kernels the fill hooks do not recognize, such as PPSA29141's InvokeHTileClearComputeShader; it is the same shape as the cases @Angel21PC and @orbz22 describe. Storing the words back means other writes in the same 64 KiB tracking block do not clear the surface again. The new agc_driver_depth_htile_write test fails on #374's head and passes here; #374's tests still pass.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6091090500 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2053#issuecomment-6091090500). Originally posted by [esatturan](https://github.com/esatturan) on 2026-10-09T23:36:07Z. --- Split as asked. This PR is now only the HTILE clear; the others are their own PRs, all without the debug aids and code comments: - Stencil clears through `DB_RENDER_CONTROL`: #2504. On `main` with #1482, PPSA29141 stops there: `depth/stencil clear, copy, resummarize or decompress draws (DB_RENDER_CONTROL) is unsupported (register 0x0 = 0x00000022)`. - Unreachable V#s read as null: #2505. - Depth-surface reuse: dropped in favour of #454, which retires a depth surface once a colour target or a written storage image covers it, which is the case PPSA29141 hits. The HTILE part now builds on #374's pending fast clear instead of adding a second clear path. At bind, if the HTILE was written since it was last read and every tile reads cleared, the surface takes the clear, and the words are stored back as expanded. That covers kernels the fill hooks do not recognize, such as PPSA29141's `InvokeHTileClearComputeShader`; it is the same shape as the cases @Angel21PC and @orbz22 describe. Storing the words back means other writes in the same 64 KiB tracking block do not clear the surface again. The new `agc_driver_depth_htile_write` test fails on #374's head and passes here; #374's tests still pass.
Mouhand-Kaddo commented 2026-10-10 10:09:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Mouhand-Kaddo on 2026-10-10T10:09:37Z.


Additional platform validation on standalone PR head 9a62ec7ecf57f85cb12a798a49496c9b82cc4317:

Linux: passed — Arch Linux in WSL2 (kernel 6.6.87.2), GCC 16.2.1 20260810; CMake 4.3.1 / Ninja.

Release / BUILD_TESTING=ON: built the selected test targets; 2 CTest cases, 0 failures, 0 CTest skips.

Tests: agc_driver_graphics, agc_driver_depth_htile_write.

Reproduce after building the test targets: ctest --test-dir <build> --verbose --no-tests=error --timeout 30 -R "^agc_driver_(depth_htile_write|graphics)$".

Vulkan: Mesa lavapipe 26.2.4 software Vulkan; no native Linux GPU/retail-title validation.

Internal limitation: write-watched guest-heap mirror subcases returned early because WSL userfaultfd async write protection is unavailable. The other graphics assertions ran; zero CTest skips does not include this internal early return.

Integration limitation: a local merge against main 948a526c2 has source conflicts; these results validate the standalone PR head, not a resolved merge.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6096427299 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2053#issuecomment-6096427299). Originally posted by [Mouhand-Kaddo](https://github.com/Mouhand-Kaddo) on 2026-10-10T10:09:37Z. --- <!-- anyps5-platform-validation:9a62ec7ecf57f85cb12a798a49496c9b82cc4317 --> Additional platform validation on standalone PR head `9a62ec7ecf57f85cb12a798a49496c9b82cc4317`: **Linux: passed** — Arch Linux in WSL2 (kernel 6.6.87.2), GCC 16.2.1 20260810; CMake 4.3.1 / Ninja. Release / `BUILD_TESTING=ON`: built the selected test targets; 2 CTest cases, 0 failures, 0 CTest skips. Tests: `agc_driver_graphics`, `agc_driver_depth_htile_write`. Reproduce after building the test targets: `ctest --test-dir <build> --verbose --no-tests=error --timeout 30 -R "^agc_driver_(depth_htile_write|graphics)$"`. Vulkan: Mesa lavapipe 26.2.4 software Vulkan; no native Linux GPU/retail-title validation. Internal limitation: write-watched guest-heap mirror subcases returned early because WSL userfaultfd async write protection is unavailable. The other graphics assertions ran; zero CTest skips does not include this internal early return. Integration limitation: a local merge against main `948a526c2` has source conflicts; these results validate the standalone PR head, not a resolved merge.
AlxcBTW commented 2026-10-10 18:28:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-10T18:28:43Z.


Data point from a retail Unity title, FPV Simulator (PPSA10698 v01.006.000, Unity 2021.3 URP), on Windows 11 with an RTX 5070 Laptop.

On main (57f96fd2 plus unrelated local patches) the levels render mostly black: buildings and ground are black silhouettes, and bright blobs appear where the sky should be. Per-draw target dumps showed that the depth-prepass and opaque draws write no pixels. The cause is that Unity clears each depth buffer every frame with its own compute kernel that fills HTILE. main only recognises RADV's clear kernel as a depth clear, so the depth buffers are never cleared and stale depth fails almost every draw.

With this PR and #374 merged locally (the conflicts with main's RADV path resolved, keeping both sides), the depth clears are taken from the HTILE and the levels render correctly. The game's owner compared it against the PS5 and confirmed it. The HTILE and depth fast-clear tests from both PRs pass on top of main.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6100796010 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2053#issuecomment-6100796010). Originally posted by [AlxcBTW](https://github.com/AlxcBTW) on 2026-10-10T18:28:43Z. --- Data point from a retail Unity title, FPV Simulator (PPSA10698 v01.006.000, Unity 2021.3 URP), on Windows 11 with an RTX 5070 Laptop. On `main` (57f96fd2 plus unrelated local patches) the levels render mostly black: buildings and ground are black silhouettes, and bright blobs appear where the sky should be. Per-draw target dumps showed that the depth-prepass and opaque draws write no pixels. The cause is that Unity clears each depth buffer every frame with its own compute kernel that fills HTILE. `main` only recognises RADV's clear kernel as a depth clear, so the depth buffers are never cleared and stale depth fails almost every draw. With this PR and #374 merged locally (the conflicts with `main`'s RADV path resolved, keeping both sides), the depth clears are taken from the HTILE and the levels render correctly. The game's owner compared it against the PS5 and confirmed it. The HTILE and depth fast-clear tests from both PRs pass on top of `main`. AI-assisted: yes
Mouhand-Kaddo commented 2026-10-10 21:23:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Mouhand-Kaddo on 2026-10-10T21:23:15Z.


Fresh current-main platform validation of the final commit 9a62ec7ecf57f85cb12a798a49496c9b82cc4317, on main 262c031692a0ce538707436fa1587b671ace682b plus the current #374 head 94d93e00f. The cherry-pick conflicts in DepthSurface.cpp and TechnicalDebt were resolved locally, preserving main's RADV clear-HTILE notification path and current CMASK behavior. Local integration: 4351bfe97.

  • Arch WSL2, GCC 16.2.1, lavapipe / LLVM 23.1.1, Release: graphics, depth-fast-clear, depth-fast-clear-submit, and depth-HTILE-write pass 4/4 (5.52 s). The HTILE-write fixture exercises its depth/stencil assertions; the submit fixture reports that its compute-fill case ran.
  • Windows 11 x64, MinGW-w64 GCC 15.2.0, RX 6900 XT, driver 32.0.21045.5002, Release: graphics, depth-fast-clear, and depth-fast-clear-submit pass. The HTILE-write test crashes in two default runs with 0xc0000005, reading null inside amdvlk64.dll+0x21c4c42. The captured main-thread stack is waiting in ClearPipelineLibraries during cleanup.
  • As a diagnostic comparison, the same Windows HTILE-write test passes 20 consecutive runs with the existing APS5_NO_PIPELINE_LTO=1 setting. This narrows the failure to investigate but does not establish its root cause or make the default Windows run green. No production workaround was added.

CTest selection: ^agc_driver_(depth_htile_write|depth_fast_clear|depth_fast_clear_submit|graphics)$; individual repeats use -V --repeat until-fail:20.

Arch uses software Vulkan. As in my earlier report, WSL asynchronous userfaultfd write protection is unavailable, and the graphics test reports its write-watch/import-mirror omissions. No full-suite or boot claim.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6102320610 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2053#issuecomment-6102320610). Originally posted by [Mouhand-Kaddo](https://github.com/Mouhand-Kaddo) on 2026-10-10T21:23:15Z. --- Fresh current-main platform validation of the final commit `9a62ec7ecf57f85cb12a798a49496c9b82cc4317`, on main `262c031692a0ce538707436fa1587b671ace682b` plus the current #374 head `94d93e00f`. The cherry-pick conflicts in `DepthSurface.cpp` and TechnicalDebt were resolved locally, preserving main's RADV clear-HTILE notification path and current CMASK behavior. Local integration: `4351bfe97`. - **Arch WSL2**, GCC 16.2.1, lavapipe / LLVM 23.1.1, Release: graphics, depth-fast-clear, depth-fast-clear-submit, and depth-HTILE-write pass 4/4 (5.52 s). The HTILE-write fixture exercises its depth/stencil assertions; the submit fixture reports that its compute-fill case ran. - **Windows 11 x64**, MinGW-w64 GCC 15.2.0, RX 6900 XT, driver 32.0.21045.5002, Release: graphics, depth-fast-clear, and depth-fast-clear-submit pass. The HTILE-write test crashes in two default runs with `0xc0000005`, reading null inside `amdvlk64.dll+0x21c4c42`. The captured main-thread stack is waiting in `ClearPipelineLibraries` during cleanup. - As a diagnostic comparison, the same Windows HTILE-write test passes 20 consecutive runs with the existing `APS5_NO_PIPELINE_LTO=1` setting. This narrows the failure to investigate but does not establish its root cause or make the default Windows run green. No production workaround was added. CTest selection: `^agc_driver_(depth_htile_write|depth_fast_clear|depth_fast_clear_submit|graphics)$`; individual repeats use `-V --repeat until-fail:20`. Arch uses software Vulkan. As in my earlier report, WSL asynchronous userfaultfd write protection is unavailable, and the graphics test reports its write-watch/import-mirror omissions. No full-suite or boot claim.
alfalfa-star commented 2026-10-11 17:01:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by alfalfa-star on 2026-10-11T17:01:57Z.


Data point from a UE4 title where this approach takes only the first clear: Kena: Bridge of Spirits (PPSA01802), Arch Linux, RADV (RX 9070 XT). It's on our local Kena stack (main 1e8fff68 + #425 + #454 + #1077 + #3645 + AlxcBTW/AnyPS5#39). I applied 9a62ec7ec by hand there because it conflicts with #425's DepthSurface.cpp; the logic is unchanged.

What Kena does: every frame it clears its 3200x1800 D32S8 depth HTILE (0x80000 bytes) with its own compute kernel. It's a 9-word dword fill, 2048x1x1 groups of 64, storing through the stride-4 V# in user[0..3] a value loaded through the V# in user[4..7] (disassembly corrected after #3816's review):

v_lshl_add_u32 v0, s8, 6, v0
s_buffer_load_dword vcc_lo, s[4:7], 0x0
s_waitcnt lgkmcnt(0)
v_mov_b32 v1, vcc_lo
buffer_store_format_x v1, v0, s[0:3], 0 idxen
s_endpgm

Neither the DMA_DATA hook nor the fill-kernel hook sees it. Without a clear, the depth keeps the first frames' contents. The base pass (greater-or-equal, reversed Z) and the sky then fail almost everywhere, and the menu background shows stale pool memory: black, white or striped, depending on the run.

With this PR: logging in noteHtileWrites over a 150 s run:

  • First bind: the words are read, ZMask 0 in 90000 of 90000, so the clear is taken and the words are stored back expanded.
  • All 299 later binds of that HTILE return early at UnchangedSince(...). The kernel's per-frame GPU stores to the HTILE never move the write generation, so no later clear is seen. The menu stays black for 4 minutes.

With a dispatch-time match instead (recognize this kernel, read the value at decode, pass the range and value to NoteDepthMetadataFill): 158 clears over 180 s, about one per frame, and the title scene renders correctly.

So for GPU-written HTILE, the "written since it was last read" check seems to need GPU writes too, for example a pending or completed compute write overlapping the HTILE range. Unity's ClearMRT kernel probably reaches you through a path the tracking does see. I have the kernel-specific matcher with tests (agc_driver_graphics, agc_driver_depth_fast_clear) on a local branch. I'd rather not open a competing PR, so if you want to cover GPU writes in this PR, I can test it on Kena. If you'd prefer the narrow matcher as a separate fix, say so and I'll open it.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6111465156 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2053#issuecomment-6111465156). Originally posted by [alfalfa-star](https://github.com/alfalfa-star) on 2026-10-11T17:01:57Z. --- Data point from a UE4 title where this approach takes only the first clear: **Kena: Bridge of Spirits (PPSA01802)**, Arch Linux, RADV (RX 9070 XT). It's on our local Kena stack (main 1e8fff68 + #425 + #454 + #1077 + #3645 + AlxcBTW/AnyPS5#39). I applied 9a62ec7ec by hand there because it conflicts with #425's `DepthSurface.cpp`; the logic is unchanged. **What Kena does:** every frame it clears its 3200x1800 D32S8 depth HTILE (0x80000 bytes) with its own compute kernel. It's a 9-word dword fill, 2048x1x1 groups of 64, storing through the stride-4 V# in `user[0..3]` a value loaded through the V# in `user[4..7]` (disassembly corrected after #3816's review): ``` v_lshl_add_u32 v0, s8, 6, v0 s_buffer_load_dword vcc_lo, s[4:7], 0x0 s_waitcnt lgkmcnt(0) v_mov_b32 v1, vcc_lo buffer_store_format_x v1, v0, s[0:3], 0 idxen s_endpgm ``` Neither the DMA_DATA hook nor the fill-kernel hook sees it. Without a clear, the depth keeps the first frames' contents. The base pass (greater-or-equal, reversed Z) and the sky then fail almost everywhere, and the menu background shows stale pool memory: black, white or striped, depending on the run. **With this PR:** logging in `noteHtileWrites` over a 150 s run: - First bind: the words are read, ZMask 0 in 90000 of 90000, so the clear is taken and the words are stored back expanded. - All 299 later binds of that HTILE return early at `UnchangedSince(...)`. The kernel's per-frame GPU stores to the HTILE never move the write generation, so no later clear is seen. The menu stays black for 4 minutes. **With a dispatch-time match instead** (recognize this kernel, read the value at decode, pass the range and value to `NoteDepthMetadataFill`): 158 clears over 180 s, about one per frame, and the title scene renders correctly. So for GPU-written HTILE, the "written since it was last read" check seems to need GPU writes too, for example a pending or completed compute write overlapping the HTILE range. Unity's ClearMRT kernel probably reaches you through a path the tracking does see. I have the kernel-specific matcher with tests (`agc_driver_graphics`, `agc_driver_depth_fast_clear`) on a local branch. I'd rather not open a competing PR, so if you want to cover GPU writes in this PR, I can test it on Kena. If you'd prefer the narrow matcher as a separate fix, say so and I'll open it.
alfalfa-star commented 2026-10-11 17:04:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by alfalfa-star on 2026-10-11T17:04:53Z.


Opened the narrow dispatch-time matcher as #3816, so Kena's per-frame clear is covered meanwhile. It only recognizes that one kernel and doesn't conflict with this PR's bind-time read. If this PR learns to see GPU-written HTILE, I'll retest Kena on it, and #3816 can be dropped if the maintainers prefer one path.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6111492238 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2053#issuecomment-6111492238). Originally posted by [alfalfa-star](https://github.com/alfalfa-star) on 2026-10-11T17:04:53Z. --- Opened the narrow dispatch-time matcher as #3816, so Kena's per-frame clear is covered meanwhile. It only recognizes that one kernel and doesn't conflict with this PR's bind-time read. If this PR learns to see GPU-written HTILE, I'll retest Kena on it, and #3816 can be dropped if the maintainers prefer one path.
oneandonlydean commented 2026-10-11 23:14:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-11T23:14:55Z.


#374 is merged; please rebase onto main so this carries only its own commit (it conflicts in DepthSurface.cpp, State.cpp, BufferFill.cpp, PacketMemory.cpp and the fast-clear tests).

The PPSA01802 report above also needs an answer before this goes into testing: after the first clear, noteHtileWrites returns at UnchangedSince on every later bind, because a compute kernel's stores to the HTILE don't move the write generation. agc_driver_depth_htile_write writes the HTILE from the CPU; please add a case where a dispatch writes it on two frames in a row and both clears are taken.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6114985769 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2053#issuecomment-6114985769). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-11T23:14:55Z. --- #374 is merged; please rebase onto main so this carries only its own commit (it conflicts in `DepthSurface.cpp`, `State.cpp`, `BufferFill.cpp`, `PacketMemory.cpp` and the fast-clear tests). The PPSA01802 report above also needs an answer before this goes into testing: after the first clear, `noteHtileWrites` returns at `UnchangedSince` on every later bind, because a compute kernel's stores to the HTILE don't move the write generation. `agc_driver_depth_htile_write` writes the HTILE from the CPU; please add a case where a dispatch writes it on two frames in a row and both clears are taken.
adriadam10 commented 2026-10-13 09:17:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-13T09:17:38Z.

Review: CHANGES_REQUESTED


Checked the diff; #374 is merged now, so this needs a rebase before anything else.

  • Conflicts with main in DepthSurface.cpp, State.cpp, BufferFill.cpp, PacketMemory.cpp and the fast-clear tests; the branch still carries #374's commits. Rebase so only the last commit remains, and rerun agc_driver_depth_fast_clear, agc_driver_depth_fast_clear_submit, agc_driver_graphics and agc_driver_depth_htile_write afterwards.
  • DepthSurface.cpp:179: noteHtileWrites returns at UnchangedSince on every later bind, and a compute kernel's stores to the HTILE don't move the write generation, so only the first clear is taken (the PPSA01802 report). agc_driver_depth_htile_write writes the HTILE from the CPU, so it can't catch it. Please add a case where a dispatch writes the HTILE on two consecutive frames and both clears are taken (fails on the current head), and fix the check so it doesn't depend on write tracking for GPU-written metadata.
  • The PPSA29141 run in the description used the first version of the change; please re-run it (or say it wasn't) on the rebased head.

Welcome to push the rebase and I'll look again.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5501360954 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2053#pullrequestreview-5501360954). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-13T09:17:38Z. **Review:** CHANGES_REQUESTED --- Checked the diff; #374 is merged now, so this needs a rebase before anything else. - Conflicts with `main` in `DepthSurface.cpp`, `State.cpp`, `BufferFill.cpp`, `PacketMemory.cpp` and the fast-clear tests; the branch still carries #374's commits. Rebase so only the last commit remains, and rerun `agc_driver_depth_fast_clear`, `agc_driver_depth_fast_clear_submit`, `agc_driver_graphics` and `agc_driver_depth_htile_write` afterwards. - `DepthSurface.cpp:179`: `noteHtileWrites` returns at `UnchangedSince` on every later bind, and a compute kernel's stores to the HTILE don't move the write generation, so only the first clear is taken (the PPSA01802 report). `agc_driver_depth_htile_write` writes the HTILE from the CPU, so it can't catch it. Please add a case where a dispatch writes the HTILE on two consecutive frames and both clears are taken (fails on the current head), and fix the check so it doesn't depend on write tracking for GPU-written metadata. - The PPSA29141 run in the description used the first version of the change; please re-run it (or say it wasn't) on the rebased head. Welcome to push the rebase and I'll look again.
XairRrR commented 2026-10-13 11:34:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-10-13T11:34:35Z.


A data point from Uncharted: Legacy of Thieves Collection (PPSA05684), on a local stack (#425, #757/#758, #2076), on the question of GPU-written HTILE.

What the title does: every frame, the title rewrites the HTILE of its four 2048x2048 D16 sun cascades (a 2D array; each slice has its own HTILE at DB_HTILE_DATA_BASE + slice × 256 KiB). I found no DMA_DATA fill, no recognized fill kernel, and no buffer or storage binding over that HTILE, yet the HTILE changes before every frame's first cascade bind. Every tile has ZMask 0, but the tiles are not all the same value:

  • about a third have Min Z = Max Z = 0x3fff (0xfffffff0, cleared to 1.0);
  • the rest are 0x0, which masks those tiles at depth 0.

Decoded with the HTILE equation below, the 1.0 tiles form each cascade's convex footprint. A whole-surface clear to DB_DEPTH_CLEAR lights the masked tiles, and the shadowed parts of the menu came out lit. Without any clear, the cascades stayed at the near-plane casters from earlier frames, so the volumetric light shafts were missing.

What worked here (local commits, not proposed as a competing PR):

  1. Seeing GPU writes: at bind, CollectWrites over the HTILE range, then UnchangedSince(range, generation) against the generation the plane last consumed. In my stack the title's GPU writes into the host-imported HTILE do move the generation. If they don't on main, the store-back in step 4 still keeps stale words from reading as new clears. Note that UnchangedSinceCollected ignores MarkWritten stamps, so it misses GPU writes.
  2. Read order: if the recorder has pending writes over the HTILE, SyncThrough first, so the words are read in stream order.
  3. Per-tile clear values: when every tile of a depth-only HTILE has ZMask 0, each 8x8 tile takes its own Min Z (bits 17:4, the encoding radeonsi's si_get_htile_clear_value writes). I clear the surface to the most common value and copy the other tiles in from a constant buffer, one region per run of tiles. A depth-and-stencil HTILE keeps the whole-surface clear.
  4. Store-back: the expanded store-back (ZMask 15) is recorded as a GPU vkCmdFillBuffer into the HTILE's host import, in stream order, after a reset and before the first depth write. Without it, our draws never update the HTILE. A later copy of that stale HTILE (this title copies its main depth into a second plane each frame), or any write elsewhere in the same 64 KiB tracker block, then read as a fresh clear and wiped the surface.

Tile addressing: I used the pipe-aligned GFX10 HTILE equation for 16 pipes: addrlib GFX10_HTILE_SW_PATTERN entry 4 (GFX10_HTILE_PATIDX, 16 pipes 1xaa), Gfx10Lib::HwlComputeHtileAddrFromCoord. One word per 8x8 tile, in 1024x512 metablocks of 32 KiB. The word index bits are X3, Y4, X6, Y6, X7, Y7, X3^Y3^Z3, X4^Y4^Z2, Y5^X6^Z1, X5^Y6^Z0, X8, Y8, X9, where Z is the slice. With Z, each slice decodes to clean shapes; without it, the edges come out sawtoothed. It is the same table family as the CMASK equation already on main (GFX10_CMASK_SW_PATTERN entry 4).

I can test a rebased head of this PR on PPSA05684 if that helps.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6144626461 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2053#issuecomment-6144626461). Originally posted by [XairRrR](https://github.com/XairRrR) on 2026-10-13T11:34:35Z. --- A data point from Uncharted: Legacy of Thieves Collection (PPSA05684), on a local stack (#425, #757/#758, #2076), on the question of GPU-written HTILE. **What the title does:** every frame, the title rewrites the HTILE of its four 2048x2048 D16 sun cascades (a 2D array; each slice has its own HTILE at `DB_HTILE_DATA_BASE` + slice × 256 KiB). I found no DMA_DATA fill, no recognized fill kernel, and no buffer or storage binding over that HTILE, yet the HTILE changes before every frame's first cascade bind. Every tile has ZMask 0, but the tiles are not all the same value: - about a third have Min Z = Max Z = 0x3fff (`0xfffffff0`, cleared to 1.0); - the rest are `0x0`, which masks those tiles at depth 0. Decoded with the HTILE equation below, the 1.0 tiles form each cascade's convex footprint. A whole-surface clear to `DB_DEPTH_CLEAR` lights the masked tiles, and the shadowed parts of the menu came out lit. Without any clear, the cascades stayed at the near-plane casters from earlier frames, so the volumetric light shafts were missing. **What worked here (local commits, not proposed as a competing PR):** 1. **Seeing GPU writes:** at bind, `CollectWrites` over the HTILE range, then `UnchangedSince(range, generation)` against the generation the plane last consumed. In my stack the title's GPU writes into the host-imported HTILE do move the generation. If they don't on main, the store-back in step 4 still keeps stale words from reading as new clears. Note that `UnchangedSinceCollected` ignores `MarkWritten` stamps, so it misses GPU writes. 2. **Read order:** if the recorder has pending writes over the HTILE, `SyncThrough` first, so the words are read in stream order. 3. **Per-tile clear values:** when every tile of a depth-only HTILE has ZMask 0, each 8x8 tile takes its own Min Z (bits 17:4, the encoding radeonsi's `si_get_htile_clear_value` writes). I clear the surface to the most common value and copy the other tiles in from a constant buffer, one region per run of tiles. A depth-and-stencil HTILE keeps the whole-surface clear. 4. **Store-back:** the expanded store-back (ZMask 15) is recorded as a GPU `vkCmdFillBuffer` into the HTILE's host import, in stream order, after a reset and before the first depth write. Without it, our draws never update the HTILE. A later copy of that stale HTILE (this title copies its main depth into a second plane each frame), or any write elsewhere in the same 64 KiB tracker block, then read as a fresh clear and wiped the surface. **Tile addressing:** I used the pipe-aligned GFX10 HTILE equation for 16 pipes: addrlib `GFX10_HTILE_SW_PATTERN` entry 4 (`GFX10_HTILE_PATIDX`, 16 pipes 1xaa), `Gfx10Lib::HwlComputeHtileAddrFromCoord`. One word per 8x8 tile, in 1024x512 metablocks of 32 KiB. The word index bits are X3, Y4, X6, Y6, X7, Y7, X3^Y3^Z3, X4^Y4^Z2, Y5^X6^Z1, X5^Y6^Z0, X8, Y8, X9, where Z is the slice. With Z, each slice decodes to clean shapes; without it, the edges come out sawtoothed. It is the same table family as the CMASK equation already on main (`GFX10_CMASK_SW_PATTERN` entry 4). I can test a rebased head of this PR on PPSA05684 if that helps. AI-assisted: yes
AlxcBTW commented 2026-10-13 12:04:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-13T12:04:19Z.


Data point from an Unreal Engine 5 title. Sword of the Sea (PPSA25344) needs this PR's store-back, but for a different reason than the clear detection: it reads its HTILE after drawing. I also have this PR rebased onto current main with follow-ups that take in @oneandonlydean's two-frame request and @XairRrR's slice data.

What happens without the store-back

  • The title 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, its Nanite depth export runs as compute, one wave per 8x8 tile. It loads the tile's HTILE word and branches on ZMask:
    • 0: the depth read is skipped and the scene depth is taken as the clear value.
    • 15: the depth is read per pixel. 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 then 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 where Nanite background starts behind them.

Evidence (frame journal replay of one such frame, NVIDIA)

  • As things are: 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. Every Nanite sample in the viewport (159313 px) replaced the scene depth.
  • With expanded HTILE words after the depth draws: 0.119 / 0.132 / 0.135 / 0.144 / 0.154 along the whole blade, shading mask 0, and the base pass survives the Nanite material pass.

Rebased stack: https://github.com/AlxcBTW/AnyPS5/compare/main...AlxcBTW:AnyPS5:fix/htile-store-back-rebase

esatturan's commit is kept as-is apart from conflict resolution: the store-back fitted into main's rewritten DepthSurfaceView, the debt entry moved to docs/dev/debt/libSceAgcDriver.md, and the test's tile count adjusted to main's harness. Two commits of ours sit on top:

  1. Extent and lock. The read covered one word per 8x8 tile from DB_HTILE_DATA_BASE (tiles * 4 bytes). main models the HTILE as the pipe-aligned SW_64KB_Z_X metadata (HtileMetadataBytes, the extent HtileFillCovers takes). With the HTILE equation from that export shader (it matches the one @XairRrR describes for Z = 0), 1856 of the 32400 tile words of a 1920x1080 surface lie past the first tiles * 4 bytes, so they would keep ZMask 0 after a store-back. The read and the store-back now cover the whole metadata, and they run before DepthSurfaceView takes the surfaces mutex, since both wait for recorded work over the range. The test HTILE arrays hold the whole metadata.
  2. Re-reads and slices. A fill or clear the driver recognizes now 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 fill. A depth view of slice 1 or later decodes to slice 0's HTILE address (the per-slice HTILE debt entry), so its bind neither takes slice 0's clear nor stores slice 0's words back. DepthTarget::slice carries DB_DEPTH_VIEW SLICE_START for that. With @XairRrR's stride (base + slice × 256 KiB for 2048² D16, which equals HtileMetadataBytes there, while Astro's 1536² cascades are 0x40000 apart), the per-slice address can follow. I left it out rather than guess the stride for other sizes.

New cases in agc_driver_depth_fast_clear_submit:

  • A DMA fast clear (depth only, then depth and stencil) followed by a draw leaves every HTILE word expanded (0xfffc000f / 0xfffff3ff). This fails on main, where the words stay 0.
  • An unrecognized kernel (the fill kernel behind an s_nop, so no matcher takes it) clears the HTILE on two frames in a row, and both clears are taken.
  • A bind of slice 1 leaves slice 0's cleared words alone, and slice 0's own bind still stores them back.

The stack up to the extent and lock commit passes all ten agc_driver_depth_* execution tests on an RTX 5070 Laptop (Windows 11, MinGW-w64 GCC 15.2). In fork CI on Linux (lavapipe), the full stack passes agc_driver_graphics and every agc_driver_depth_* test. The only failure, guest_math, fails the same way on main.

Not covered here: per-tile clear values (a depth-only HTILE with ZMask 0 everywhere but different Min/Max Z, as in PPSA05684's cascades) are still taken as a whole-surface clear to DB_DEPTH_CLEAR. The store-back is a CPU write after the bind-time read; recording it as a GPU fill in stream order, as @XairRrR does, would also remove the wait on pending HTILE writes.

@esatturan, if you want it, take it into this PR (cherry-pick or reset onto it). Otherwise I can open it as a separate PR that keeps your commit and authorship and says it supersedes this one.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6145122271 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2053#issuecomment-6145122271). Originally posted by [AlxcBTW](https://github.com/AlxcBTW) on 2026-10-13T12:04:19Z. --- Data point from an Unreal Engine 5 title. Sword of the Sea (PPSA25344) needs this PR's store-back, but for a different reason than the clear detection: it reads its HTILE after drawing. I also have this PR rebased onto current `main` with follow-ups that take in @oneandonlydean's two-frame request and @XairRrR's slice data. **What happens without the store-back** - The title 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, its Nanite depth export runs as compute, one wave per 8x8 tile. It loads the tile's HTILE word and branches on ZMask: - 0: the depth read is skipped and the scene depth is taken as the clear value. - 15: the depth is read per pixel. 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 then 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 where Nanite background starts behind them. **Evidence** (frame journal replay of one such frame, NVIDIA) - As things are: 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. Every Nanite sample in the viewport (159313 px) replaced the scene depth. - With expanded HTILE words after the depth draws: 0.119 / 0.132 / 0.135 / 0.144 / 0.154 along the whole blade, shading mask 0, and the base pass survives the Nanite material pass. **Rebased stack:** https://github.com/AlxcBTW/AnyPS5/compare/main...AlxcBTW:AnyPS5:fix/htile-store-back-rebase esatturan's commit is kept as-is apart from conflict resolution: the store-back fitted into `main`'s rewritten `DepthSurfaceView`, the debt entry moved to `docs/dev/debt/libSceAgcDriver.md`, and the test's tile count adjusted to `main`'s harness. Two commits of ours sit on top: 1. **Extent and lock.** The read covered one word per 8x8 tile from `DB_HTILE_DATA_BASE` (`tiles * 4` bytes). `main` models the HTILE as the pipe-aligned SW_64KB_Z_X metadata (`HtileMetadataBytes`, the extent `HtileFillCovers` takes). With the HTILE equation from that export shader (it matches the one @XairRrR describes for Z = 0), 1856 of the 32400 tile words of a 1920x1080 surface lie past the first `tiles * 4` bytes, so they would keep ZMask 0 after a store-back. The read and the store-back now cover the whole metadata, and they run before `DepthSurfaceView` takes the surfaces mutex, since both wait for recorded work over the range. The test HTILE arrays hold the whole metadata. 2. **Re-reads and slices.** A fill or clear the driver recognizes now 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 fill. A depth view of slice 1 or later decodes to slice 0's HTILE address (the per-slice HTILE debt entry), so its bind neither takes slice 0's clear nor stores slice 0's words back. `DepthTarget::slice` carries `DB_DEPTH_VIEW` SLICE_START for that. With @XairRrR's stride (base + slice × 256 KiB for 2048² D16, which equals `HtileMetadataBytes` there, while Astro's 1536² cascades are 0x40000 apart), the per-slice address can follow. I left it out rather than guess the stride for other sizes. New cases in `agc_driver_depth_fast_clear_submit`: - A DMA fast clear (depth only, then depth and stencil) followed by a draw leaves every HTILE word expanded (`0xfffc000f` / `0xfffff3ff`). This fails on `main`, where the words stay 0. - An unrecognized kernel (the fill kernel behind an `s_nop`, so no matcher takes it) clears the HTILE on two frames in a row, and both clears are taken. - A bind of slice 1 leaves slice 0's cleared words alone, and slice 0's own bind still stores them back. The stack up to the extent and lock commit passes all ten `agc_driver_depth_*` execution tests on an RTX 5070 Laptop (Windows 11, MinGW-w64 GCC 15.2). In fork CI on Linux (lavapipe), the full stack passes `agc_driver_graphics` and every `agc_driver_depth_*` test. The only failure, `guest_math`, fails the same way on `main`. **Not covered here:** per-tile clear values (a depth-only HTILE with ZMask 0 everywhere but different Min/Max Z, as in PPSA05684's cascades) are still taken as a whole-surface clear to `DB_DEPTH_CLEAR`. The store-back is a CPU write after the bind-time read; recording it as a GPU fill in stream order, as @XairRrR does, would also remove the wait on pending HTILE writes. @esatturan, if you want it, take it into this PR (cherry-pick or reset onto it). Otherwise I can open it as a separate PR that keeps your commit and authorship and says it supersedes this one.
XairRrR commented 2026-10-13 17:02:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-10-13T17:02:16Z.


A correction to the HTILE equation in my earlier comment, plus slice data for @AlxcBTW's rebase.

Per-slice address: #5111 sets a slice's HTILE to DB_HTILE_DATA_BASE + slice × HtileMetadataBytes(extent). That is addrlib's sliceSize * slice in Gfx10Lib::HwlComputeHtileAddrFromCoord, not a measured stride. It gives 256 KiB for PPSA05684's 2048² D16 cascades, which the mask fit below confirms (each slice's tiles sit at slice × 256 KiB). For its 1024² D32 arrays it gives 64 KiB, which is not measured. It also lets a recognized HTILE clear take every slice whose HTILE its range covers. So the per-slice address can follow from that PR rather than be guessed per size.

Correction, slices 1 to 3: the word bits I gave (X3, Y4, X6, Y6, X7, Y7, X3^Y3^Z3, X4^Y4^Z2, Y5^X6^Z1, X5^Y6^Z0, X8, Y8, X9) are right for slice 0, but not complete for the other slices. PPSA05684 also writes each cascade's tile mask as a 256x256 R8 image (one texel per 8x8 tile). I fitted the equation's slice terms and block offsets against those four masks, by an exhaustive search over flips of word bits 6 to 12 and over every 32 KiB block offset:

  • Slice 0 decodes to the title's mask exactly.
  • Slice 1 needs word bits 9 and 10 flipped, and slice 2 needs bits 8 and 11, both at offset slice × sliceSize. Slice 3 needs bits 8 to 11 (at most 6 of 65536 tiles differ, at the mask edges).
  • So beyond addrlib's Z terms, bit 10 (X8) also takes Z0 and bit 11 (Y8) also takes Z1. No entry of GFX10_HTILE_SW_PATTERN has that shape. Slices 4 and up are unmeasured.

With only the addrlib terms, slices 1 to 3 decode to shifted strips of the right shape, which is why it looked clean to me before. Locally I now throw for a per-tile decode of slice 4 or above. One exception: a slice whose HTILE words are all equal decodes to one value under any layout. PPSA05684's boat level binds slice 4 and 5 of six-slice 1024² D32 arrays whose HTILE is a uniform 0xfffffff0.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6150843745 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2053#issuecomment-6150843745). Originally posted by [XairRrR](https://github.com/XairRrR) on 2026-10-13T17:02:16Z. --- A correction to the HTILE equation in my earlier comment, plus slice data for @AlxcBTW's rebase. **Per-slice address:** #5111 sets a slice's HTILE to `DB_HTILE_DATA_BASE + slice × HtileMetadataBytes(extent)`. That is addrlib's `sliceSize * slice` in `Gfx10Lib::HwlComputeHtileAddrFromCoord`, not a measured stride. It gives 256 KiB for PPSA05684's 2048² D16 cascades, which the mask fit below confirms (each slice's tiles sit at `slice × 256 KiB`). For its 1024² D32 arrays it gives 64 KiB, which is not measured. It also lets a recognized HTILE clear take every slice whose HTILE its range covers. So the per-slice address can follow from that PR rather than be guessed per size. **Correction, slices 1 to 3:** the word bits I gave (X3, Y4, X6, Y6, X7, Y7, X3^Y3^Z3, X4^Y4^Z2, Y5^X6^Z1, X5^Y6^Z0, X8, Y8, X9) are right for slice 0, but not complete for the other slices. PPSA05684 also writes each cascade's tile mask as a 256x256 R8 image (one texel per 8x8 tile). I fitted the equation's slice terms and block offsets against those four masks, by an exhaustive search over flips of word bits 6 to 12 and over every 32 KiB block offset: - Slice 0 decodes to the title's mask exactly. - Slice 1 needs word bits 9 **and 10** flipped, and slice 2 needs bits 8 **and 11**, both at offset `slice × sliceSize`. Slice 3 needs bits 8 to 11 (at most 6 of 65536 tiles differ, at the mask edges). - So beyond addrlib's Z terms, bit 10 (X8) also takes Z0 and bit 11 (Y8) also takes Z1. No entry of `GFX10_HTILE_SW_PATTERN` has that shape. Slices 4 and up are unmeasured. With only the addrlib terms, slices 1 to 3 decode to shifted strips of the right shape, which is why it looked clean to me before. Locally I now throw for a per-tile decode of slice 4 or above. One exception: a slice whose HTILE words are all equal decodes to one value under any layout. PPSA05684's boat level binds slice 4 and 5 of six-slice 1024² D32 arrays whose HTILE is a uniform `0xfffffff0`. AI-assisted: yes
AlxcBTW commented 2026-10-13 17:05:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-13T17:05:29Z.


@XairRrR thank you, that saves the rebase a wrong guess. I'll take the per-slice HTILE address from #5111 (DB_HTILE_DATA_BASE + slice × HtileMetadataBytes(extent)) instead of a stride of my own. I'll also keep the per-tile decode to slice 0, refusing slices ≥ 1, until the X8/Z0 and Y8/Z1 terms you fitted are in an equation with a test, except for slices whose HTILE words are all equal, as in your boat-level case. The Sword of the Sea case behind this PR is slice 0 (Nanite depth pass), so the fix doesn't depend on the higher slices.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6150902200 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2053#issuecomment-6150902200). Originally posted by [AlxcBTW](https://github.com/AlxcBTW) on 2026-10-13T17:05:29Z. --- @XairRrR thank you, that saves the rebase a wrong guess. I'll take the per-slice HTILE address from #5111 (`DB_HTILE_DATA_BASE + slice × HtileMetadataBytes(extent)`) instead of a stride of my own. I'll also keep the per-tile decode to slice 0, refusing slices ≥ 1, until the X8/Z0 and Y8/Z1 terms you fitted are in an equation with a test, except for slices whose HTILE words are all equal, as in your boat-level case. The Sword of the Sea case behind this PR is slice 0 (Nanite depth pass), so the fix doesn't depend on the higher slices.
Amoenus commented 2026-10-13 23:46:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Amoenus on 2026-10-13T23:46:54Z.


@esatturan Coordination for the protected native-MSAA subset introduced by #5496: follow-up #5554 now handles recognized completed HTILE mask clears while retaining the native depth image and its sampled views. It requires complete store coverage, no pending GPU/CPU/depth conflict, and exact zero/one metadata. Generic producers remain unsupported there.

Your HTILE polling/expansion path is distinct. When composing it with these owners, a direct GuestMemory::Read/expanded-metadata write reaches their sample-preserving publication guard; the guarded native subset needs explicit routing before generic HTILE readback. I have not tested #2053 in this new composition and do not claim that combination works. #5554 currently depends on #5524/#5111, transitively #5496/#4820; its producer/coverage validation passes on NVIDIA and AMD. This scope is also recorded in #3262. AI-assisted: Codex.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6157600247 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2053#issuecomment-6157600247). Originally posted by [Amoenus](https://github.com/Amoenus) on 2026-10-13T23:46:54Z. --- @esatturan Coordination for the protected native-MSAA subset introduced by #5496: follow-up #5554 now handles recognized completed HTILE mask clears while retaining the native depth image and its sampled views. It requires complete store coverage, no pending GPU/CPU/depth conflict, and exact zero/one metadata. Generic producers remain unsupported there. Your HTILE polling/expansion path is distinct. When composing it with these owners, a direct `GuestMemory::Read`/expanded-metadata write reaches their sample-preserving publication guard; the guarded native subset needs explicit routing before generic HTILE readback. I have not tested #2053 in this new composition and do not claim that combination works. #5554 currently depends on #5524/#5111, transitively #5496/#4820; its [producer/coverage validation](https://github.com/Amoenus/AnyPS5/commit/4dcc5ede3ddb3c87702214725504649d51413f43) passes on NVIDIA and AMD. This scope is also recorded in #3262. AI-assisted: Codex.
oneandonlydean commented 2026-10-14 01:24:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T01:24:28Z.


@AlxcBTW please open it as a separate PR that keeps esatturan's commit and says it supersedes this one; there has been nothing here from the author since 10-09.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6158785498 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2053#issuecomment-6158785498). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-14T01:24:28Z. --- @AlxcBTW please open it as a separate PR that keeps esatturan's commit and says it supersedes this one; there has been nothing here from the author since 10-09.
AlxcBTW commented 2026-10-14 02:08:44 +00:00 (Migrated from github.com)

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


@oneandonlydean @esatturan opened as #5627. It keeps esatturan's commit and authorship, adds the whole-metadata store-back, the two-frame GPU-written case and the per-slice rule from the review here, and depends on #5111.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6159306478 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2053#issuecomment-6159306478). Originally posted by [AlxcBTW](https://github.com/AlxcBTW) on 2026-10-14T02:08:44Z. --- @oneandonlydean @esatturan opened as #5627. It keeps esatturan's commit and authorship, adds the whole-metadata store-back, the two-frame GPU-written case and the per-slice rule from the review here, and depends on #5111.
github-actions[bot] commented 2026-10-14 02:24:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-14T02:24:06Z.


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
#5627 core/libs/prx/libSceAgcDriver/tests/execution/DepthHtileWrite.cpp
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6159486358 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2053#issuecomment-6159486358). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-14T02:24:06Z. --- <!-- 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 | |---|---|---|---| | #5627 | | | `core/libs/prx/libSceAgcDriver/tests/execution/DepthHtileWrite.cpp` |
oneandonlydean commented 2026-10-14 02:33:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T02:33:53Z.


Closing: the same change continues in #5627, which keeps your commit and adds the follow-ups from the review here.
Reopen if something here is still missing on current main.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6159598624 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2053#issuecomment-6159598624). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-14T02:33:53Z. --- Closing: the same change continues in #5627, which keeps your commit and adds the follow-ups from the review here. Reopen if something here is still missing on current main.

Pull request closed

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!2053
No description provided.