fix(agc): apply RADV's HTILE depth fast clears to the host depth surface #2229

Merged
TheAggie merged 2 commits from upstream-pr/2229 into main 2026-10-10 06:54:11 +00:00
TheAggie commented 2026-10-09 12:30:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by TheAggie on 2026-10-09T12:30:46Z.


What

A depth surface is a host image that AnyPS5 clears once, when it creates the image, to the DB_DEPTH_CLEAR value it sees then. RADV (and real hardware) clears depth differently: it doesn't touch the depth memory, it rewrites the HTILE metadata so every tile reads as "cleared" (ZMASK = 0), and the DB returns DB_DEPTH_CLEAR for those tiles. AnyPS5 doesn't model HTILE, so after the first frame the host depth image is never cleared again.

vkQuake (PPSA99010, the homebrew Vulkan port, through RADV) shows this as a black 3D view. It uses reverse Z (GREATER_OR_EQUAL, clear to 0.0), so the depth buffer keeps the largest depth of every earlier frame, and once the camera moves nearly every world draw fails the depth test. The HUD, the 2D draws and the post-process pass are unaffected.

  • DepthTarget carries the surface's HTILE address (DB_HTILE_DATA_BASE / _HI) when DB_Z_INFO.TILE_SURFACE_ENABLE is set and the base register has been written. 0x005 and 0x01e are added to DrawKeyRegisters.
  • RADV writes HTILE with its clear_htile_mask compute kernel (17 GFX10 words: htile = (htile & user[5]) | user[4] over the buffer at user[2..3]). HtileDepthClearAddress recognizes it by its code and 64x1x1 groups, and returns the HTILE address when the update leaves ZMASK at 0. The dispatch still runs, so guest memory is unchanged.
  • DepthSurfaceView clears the depth aspect of that surface to the draw's DB_DEPTH_CLEAR the next time the surface is bound, through Recorder::Commands() (which ends any open render pass) with barriers around the clear.

HTILE initialization (ZMASK 0xf, "expanded") and the stencil-only update RADV issues alongside it are left alone.

Limits: this matches one RADV kernel. Fast clears done some other way (the SDK's own paths, CP DMA fills, stencil HTILE clears) aren't covered.

Tests:

  • DepthStencilTests: the HTILE address decodes from DB_HTILE_DATA_BASE and its high byte, is 0 without the base register or without TILE_SURFACE_ENABLE, and every register the decoder reads is in DrawKeyRegisters.
  • htileDepthClearTests: the fast clear is recognized; HTILE initialization, the ZMASK-preserving stencil update, another group size, a changed kernel and a truncated kernel are not.

Other open PRs touch the same files (#1684, #2076, #2169 in DepthSurface/State, #2095 in the Graphics tests); I'll rebase onto whichever lands first.

Tested

Windows 11 Pro (26200), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, NVIDIA GeForce RTX 5070 Ti (driver 610.88).

  • Full local suite: 507 tests, 505 passed, 1 skipped; guest_sce_net timed out (also when run alone; it doesn't touch the AGC driver, likely my local network filtering). It was run from the generated CTestTestfile.cmake commands because antivirus blocks ctest.exe on this machine.
  • tools/check_conventions.py --base origin/main passes.
  • vkQuake (PPSA99010): the 3D view went from black to a correctly depth-tested, textured and lit world (E1M1 demo). That run was on my local test branch (current main plus my open RADV PRs and some local stubs), so it isn't reproducible on main alone.

Not tested on Linux or macOS.

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: none
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4800431872 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2229). Originally posted by [TheAggie](https://github.com/TheAggie) on 2026-10-09T12:30:46Z. --- ### What A depth surface is a host image that AnyPS5 clears once, when it creates the image, to the DB_DEPTH_CLEAR value it sees then. RADV (and real hardware) clears depth differently: it doesn't touch the depth memory, it rewrites the HTILE metadata so every tile reads as "cleared" (ZMASK = 0), and the DB returns DB_DEPTH_CLEAR for those tiles. AnyPS5 doesn't model HTILE, so after the first frame the host depth image is never cleared again. vkQuake (PPSA99010, the homebrew Vulkan port, through RADV) shows this as a black 3D view. It uses reverse Z (GREATER_OR_EQUAL, clear to 0.0), so the depth buffer keeps the largest depth of every earlier frame, and once the camera moves nearly every world draw fails the depth test. The HUD, the 2D draws and the post-process pass are unaffected. - `DepthTarget` carries the surface's HTILE address (DB_HTILE_DATA_BASE / _HI) when DB_Z_INFO.TILE_SURFACE_ENABLE is set and the base register has been written. 0x005 and 0x01e are added to `DrawKeyRegisters`. - RADV writes HTILE with its `clear_htile_mask` compute kernel (17 GFX10 words: `htile = (htile & user[5]) | user[4]` over the buffer at user[2..3]). `HtileDepthClearAddress` recognizes it by its code and 64x1x1 groups, and returns the HTILE address when the update leaves ZMASK at 0. The dispatch still runs, so guest memory is unchanged. - `DepthSurfaceView` clears the depth aspect of that surface to the draw's DB_DEPTH_CLEAR the next time the surface is bound, through `Recorder::Commands()` (which ends any open render pass) with barriers around the clear. HTILE initialization (ZMASK 0xf, "expanded") and the stencil-only update RADV issues alongside it are left alone. Limits: this matches one RADV kernel. Fast clears done some other way (the SDK's own paths, CP DMA fills, stencil HTILE clears) aren't covered. Tests: - `DepthStencilTests`: the HTILE address decodes from DB_HTILE_DATA_BASE and its high byte, is 0 without the base register or without TILE_SURFACE_ENABLE, and every register the decoder reads is in `DrawKeyRegisters`. - `htileDepthClearTests`: the fast clear is recognized; HTILE initialization, the ZMASK-preserving stencil update, another group size, a changed kernel and a truncated kernel are not. Other open PRs touch the same files (#1684, #2076, #2169 in DepthSurface/State, #2095 in the Graphics tests); I'll rebase onto whichever lands first. ### Tested Windows 11 Pro (26200), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, NVIDIA GeForce RTX 5070 Ti (driver 610.88). - Full local suite: 507 tests, 505 passed, 1 skipped; `guest_sce_net` timed out (also when run alone; it doesn't touch the AGC driver, likely my local network filtering). It was run from the generated `CTestTestfile.cmake` commands because antivirus blocks `ctest.exe` on this machine. - `tools/check_conventions.py --base origin/main` passes. - vkQuake (PPSA99010): the 3D view went from black to a correctly depth-tested, textured and lit world (E1M1 demo). That run was on my local test branch (current `main` plus my open RADV PRs and some local stubs), so it isn't reproducible on `main` alone. Not tested on Linux or macOS. ### 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: none - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
popcoder565 commented 2026-10-09 15:24:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by popcoder565 on 2026-10-09T15:24:52Z.


Native Windows run, since no Windows results were posted. Setup: Windows 10 (19045), RTX 3060 Laptop (NVIDIA 616.92), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. Head dd5a5117, merged onto main d70b8998 in one build with 33 other AGC/shader PRs that had no Windows run.

  • This PR's tests pass: agc_driver_graphics. None of them reported skipping a case.
  • Full ctest in that build: 514 of 515. The one failure is #2257's new test, which is registered without the Windows PATH setup.

No title was run.

🤖 Addressed by Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6083913937 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2229#issuecomment-6083913937). Originally posted by [popcoder565](https://github.com/popcoder565) on 2026-10-09T15:24:52Z. --- Native Windows run, since no Windows results were posted. Setup: Windows 10 (19045), RTX 3060 Laptop (NVIDIA 616.92), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. Head `dd5a5117`, merged onto `main` d70b8998 in one build with 33 other AGC/shader PRs that had no Windows run. - This PR's tests pass: `agc_driver_graphics`. None of them reported skipping a case. - Full ctest in that build: 514 of 515. The one failure is #2257's new test, which is registered without the Windows `PATH` setup. No title was run. _🤖 Addressed by [Claude Code](https://claude.com/claude-code)_
oneandonlydean commented 2026-10-10 05:18:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-10T05:18:16Z.


Please rebase; it conflicts with main in tests/Graphics.cpp.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6094140778 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2229#issuecomment-6094140778). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-10T05:18:16Z. --- Please rebase; it conflicts with main in `tests/Graphics.cpp`.
github-actions[bot] commented 2026-10-10 06:24:03 +00:00 (Migrated from github.com)

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


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
#1430 core/libs/prx/libSceAgcDriver/Graphics/include/DepthSurface.hpp L17
#1864 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Dispatch/Dispatch.cpp L7-8, L53-60
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6094622295 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2229#issuecomment-6094622295). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-10T06:24:03Z. --- <!-- 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 | |---|---|---|---| | #1430 | `core/libs/prx/libSceAgcDriver/Graphics/include/DepthSurface.hpp` [L17](https://github.com/boykopovar/AnyPS5/blob/653e3d04d77888927fe99b00eddd12b6d166c720/core/libs/prx/libSceAgcDriver/Graphics/include/DepthSurface.hpp#L17) | | | | #1864 | `core/libs/prx/libSceAgcDriver/Execution/src/Driver/Dispatch/Dispatch.cpp` [L7-8](https://github.com/boykopovar/AnyPS5/blob/653e3d04d77888927fe99b00eddd12b6d166c720/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Dispatch/Dispatch.cpp#L7-L8), [L53-60](https://github.com/boykopovar/AnyPS5/blob/653e3d04d77888927fe99b00eddd12b6d166c720/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Dispatch/Dispatch.cpp#L53-L60) | | |
adriadam10 commented 2026-10-10 06:48:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T06:48:54Z.


Checked on Linux (RADV host) on the rebased head: scoped build + ctest of libSceAgcDriver green, agc_driver_graphics and agc_driver_prepared_graphics pass, and agc_driver_graphics fails if the ZMASK check on user[4] is removed. I disassembled the 17-word kernel for gfx1030 and it is htile = (htile & user[5]) | user[4] as described. Windows run by @popcoder565 also passes.

Added by us on top of your rebase:

  • docs/dev/TechnicalDebt.md, "Functional": a line for the HTILE depth fast clear limits (only RADV's kernel, exact HTILE address match, no HTILE init / stencil / other fast-clear paths).

Merging once CI is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6094812150 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2229#issuecomment-6094812150). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-10T06:48:54Z. --- Checked on Linux (RADV host) on the rebased head: scoped build + ctest of libSceAgcDriver green, `agc_driver_graphics` and `agc_driver_prepared_graphics` pass, and `agc_driver_graphics` fails if the ZMASK check on `user[4]` is removed. I disassembled the 17-word kernel for gfx1030 and it is `htile = (htile & user[5]) | user[4]` as described. Windows run by @popcoder565 also passes. Added by us on top of your rebase: - `docs/dev/TechnicalDebt.md`, "Functional": a line for the HTILE depth fast clear limits (only RADV's kernel, exact HTILE address match, no HTILE init / stencil / other fast-clear paths). Merging once CI is green.
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!2229
No description provided.