fix(agc): skip an HTILE Hi-Z patch dispatch that writes no byte over native depth #25870

Merged
birdmarty merged 1 commit from upstream-pr/25870 into main 2026-11-23 08:28:25 +00:00
birdmarty commented 2026-11-22 19:38:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by birdmarty on 2026-11-22T19:38:30Z.


What

A 51-dword compute kernel patches the depth bounds of cleared HTILE tiles: for every word whose ZMask is 0 it replaces bits 12–31 with those of user data 4. A lane stores its 16-byte record only if one of its words changed (v_cmp_ne_u32 ×4, s_mov exec, vcc, s_cbranch_execz over the buffer_store_dwordx4). Over the HTILE of a native multisampled depth owner, the store counted as an external GPU write. The next use of the depth target threw external GPU writes over native multisample depth are not implemented, even when the kernel stored nothing.

The kernel is now recognized: all 51 dwords, 32 threads with the group id, a direct dispatch, and a raw V# with a 16-byte stride. When a native depth owner with sampling covers its HTILE, has no unapplied clear and no sampling refusal, the dispatch is skipped if the HTILE bytes prove that no lane stores. Pending GPU writes over the range are synced first, so these are the bytes the kernel would read. Host draws to a native depth target only take tiles out of the cleared state, so a dispatch that changes nothing in the guest HTILE also changes nothing on the GPU. A dispatch that would change a cleared tile still runs and still refuses.

Changes

  • core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp, Graphics/include/DepthSurface.hpp: MatchHtileClearedHiZPatch and SkipNoOpHtileHiZPatch.
  • core/libs/prx/libSceAgcDriver/Execution/src/Driver/Dispatch/Dispatch.cpp: a recognized patch that can be skipped ends the dispatch like the other recognized fills.
  • core/libs/prx/libSceAgcDriver/tests/execution/SampleMultisampleTarget.cpp, tests/cmake/agc_driver_sample_multisample_target_tests.cmake: agc_driver_htile_hiz_patch.
    • The real kernel runs on the GPU over 64 records of mixed words (cleared with other bounds, cleared with the same bounds, ZMask 15, ZMask 5) and writes exactly the decoded result.
    • The matcher accepts it and refuses another mask or an 8-byte stride.
    • Over a native 2x D32S8 owner whose HTILE is cleared at 1.0, a patch to the same bounds is skipped and one that lowers them is not; the HTILE stays untouched. No owner means no skip.

Tested

Windows 11 Pro (build 26300), Intel Core i9-9900K, AMD Radeon RX 6800 (AMD driver 26.10.1, Windows driver 32.0.21045.16010, Vulkan 1.4.315), MinGW-w64 GCC 15.3.0, Release, main 66668ebb8b.

Focused set (agc_driver_graphics, agc_shader_memory, agc_driver_sample_multisample_target, agc_driver_recorder, agc_driver_cached_image_multisample_guard, agc_driver_cmask_fast_clear, agc_driver_pipelined_metadata_pass*, agc_driver_native_fmask_*, agc_driver_fmask_*, agc_driver_msaa_*, agc_driver_multisample*, agc_driver_native_*, agc_driver_sampled_cache*, image_msaa*, agc_driver_depth*, agc_driver_htile*, agc_driver_stencil*, agc_driver_dispatch*, agc_driver_*fill*) with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation (1.4.363) and VK_LOADER_DEBUG=layer:

main 66668ebb8b this change
Passed / failed 153 / 0 154 / 0 (adds agc_driver_htile_hiz_patch)
Validation layer inserted 184 185
VUID- lines 0 0

With the skip disabled (the dispatch always runs, as on main), the new test fails with an HTILE Hi-Z patch that writes no byte over a native depth owner was not skipped. The test was then moved to other lines of the file, so it doesn't collide with other open PRs; its program's 46 tests passed again on this commit, with the validation layer and 0 VUIDs.

Forza Horizon 5 (PPSA22327 01.685.672), local stack of open PRs without this change:

  • What the game does: it runs this kernel over the HTILE of its native 4x depth target, with every cleared word already holding the patch bounds.
  • Without this change: the refusal stopped 5 of 6 runs that got that far.
  • With this exact change added: 21 runs, none with it.

py -3 tools/check_conventions.py --base origin/main and py -3 tools/debt_fold.py --check pass. py -3 tools/pr_overlap.py --branch fix/agc-skip-no-op-htile-hiz-patch (2,356 open PRs) found only test-file positions, which were then moved. Twenty-eight PRs that conflict with main were searched by hand for the kernel and any HTILE Hi-Z handling; none has it.

Not tested: a patch that changes cleared tiles of a native owner (it still refuses; applying new clear depths to the host image is not implemented), other GPUs, Linux, console behaviour.

Rebased onto main f220c22162 (394 commits, none touching the files this PR changes, no conflicts). On the rebased commit check_conventions and debt_fold --check pass. All eight PRs merged together on f220c22162, the focused tests of all eight with the same environment: main 182 passed / 0 failed, validation layer inserted 242 times, 0 VUID- lines; the eight together 188 passed / 0 failed (the six new tests added), inserted 250 times, 0 VUID- lines.

Part of the Forza Horizon 5 (PPSA22327) bring-up, #25152. The game hits these stops one after another, so these PRs were found and tested together on one stack: the other open PRs the game needs (#24960, #24994, #25151, #23688, #23545, #21479, #11825, #23778, #21155, #22306, #21199) plus the PRs below. Each one stands alone: it applies to main by itself, needs none of the others to build or pass its tests, and merges cleanly with every other one.

  • #25867 fix/agc-materialize-cold-native-fmask: cold native FMASK pages read as stored after a first touch
  • #25868 fix/agc-multisample-read-single-sample-depth: multisampled read over a single-sample depth surface
  • #25869 fix/agc-claim-retires-memory-backed-msaa-copy: memory-backed multisampled copy treated as a host-only alias
  • #25871 fix/agc-sample-htile-stencil-after-expand: stencil kept in HTILE read without metadata after an expand
  • #25872 fix/agc-expanded-after-whole-depth-publication: a whole native depth publication taken as an expand
  • #25873 fix/agc-htile-clear-supersedes-plane-writes: plane writes before a whole HTILE clear
  • #25874 fix/agc-read-unwritten-htile-stencil-from-memory: stencil plane read from memory for an unwritten native target

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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
  • Fixes: none
  • Unblocks: PPSA22327 #25152
  • GPUs tested: AMD Radeon RX 6800 (vendor=0x1002, device=0x73bf), AMD proprietary driver 26.10.1 (Windows driver 32.0.21045.16010, Vulkan 1.4.315), Windows 11 Pro (build 26300); Khronos validation layer 1.4.363.0 on main and this change, 0 VUIDs
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5442603624 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/25870). Originally posted by [birdmarty](https://github.com/birdmarty) on 2026-11-22T19:38:30Z. --- ### What A 51-dword compute kernel patches the depth bounds of cleared HTILE tiles: for every word whose ZMask is 0 it replaces bits 12–31 with those of user data 4. A lane stores its 16-byte record only if one of its words changed (`v_cmp_ne_u32` ×4, `s_mov exec, vcc`, `s_cbranch_execz` over the `buffer_store_dwordx4`). Over the HTILE of a native multisampled depth owner, the store counted as an external GPU write. The next use of the depth target threw `external GPU writes over native multisample depth are not implemented`, even when the kernel stored nothing. The kernel is now recognized: all 51 dwords, 32 threads with the group id, a direct dispatch, and a raw V# with a 16-byte stride. When a native depth owner with sampling covers its HTILE, has no unapplied clear and no sampling refusal, the dispatch is skipped if the HTILE bytes prove that no lane stores. Pending GPU writes over the range are synced first, so these are the bytes the kernel would read. Host draws to a native depth target only take tiles out of the cleared state, so a dispatch that changes nothing in the guest HTILE also changes nothing on the GPU. A dispatch that would change a cleared tile still runs and still refuses. #### Changes - `core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp`, `Graphics/include/DepthSurface.hpp`: `MatchHtileClearedHiZPatch` and `SkipNoOpHtileHiZPatch`. - `core/libs/prx/libSceAgcDriver/Execution/src/Driver/Dispatch/Dispatch.cpp`: a recognized patch that can be skipped ends the dispatch like the other recognized fills. - `core/libs/prx/libSceAgcDriver/tests/execution/SampleMultisampleTarget.cpp`, `tests/cmake/agc_driver_sample_multisample_target_tests.cmake`: `agc_driver_htile_hiz_patch`. - The real kernel runs on the GPU over 64 records of mixed words (cleared with other bounds, cleared with the same bounds, ZMask 15, ZMask 5) and writes exactly the decoded result. - The matcher accepts it and refuses another mask or an 8-byte stride. - Over a native 2x D32S8 owner whose HTILE is cleared at 1.0, a patch to the same bounds is skipped and one that lowers them is not; the HTILE stays untouched. No owner means no skip. ### Tested Windows 11 Pro (build 26300), Intel Core i9-9900K, AMD Radeon RX 6800 (AMD driver 26.10.1, Windows driver 32.0.21045.16010, Vulkan 1.4.315), MinGW-w64 GCC 15.3.0, Release, `main` 66668ebb8b. Focused set (`agc_driver_graphics`, `agc_shader_memory`, `agc_driver_sample_multisample_target`, `agc_driver_recorder`, `agc_driver_cached_image_multisample_guard`, `agc_driver_cmask_fast_clear`, `agc_driver_pipelined_metadata_pass*`, `agc_driver_native_fmask_*`, `agc_driver_fmask_*`, `agc_driver_msaa_*`, `agc_driver_multisample*`, `agc_driver_native_*`, `agc_driver_sampled_cache*`, `image_msaa*`, `agc_driver_depth*`, `agc_driver_htile*`, `agc_driver_stencil*`, `agc_driver_dispatch*`, `agc_driver_*fill*`) with `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1`, `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation` (1.4.363) and `VK_LOADER_DEBUG=layer`: | | `main` 66668ebb8b | this change | |---|---|---| | Passed / failed | 153 / 0 | 154 / 0 (adds `agc_driver_htile_hiz_patch`) | | Validation layer inserted | 184 | 185 | | `VUID-` lines | 0 | 0 | With the skip disabled (the dispatch always runs, as on `main`), the new test fails with `an HTILE Hi-Z patch that writes no byte over a native depth owner was not skipped`. The test was then moved to other lines of the file, so it doesn't collide with other open PRs; its program's 46 tests passed again on this commit, with the validation layer and 0 VUIDs. Forza Horizon 5 (PPSA22327 01.685.672), local stack of open PRs without this change: - **What the game does:** it runs this kernel over the HTILE of its native 4x depth target, with every cleared word already holding the patch bounds. - **Without this change:** the refusal stopped 5 of 6 runs that got that far. - **With this exact change added:** 21 runs, none with it. `py -3 tools/check_conventions.py --base origin/main` and `py -3 tools/debt_fold.py --check` pass. `py -3 tools/pr_overlap.py --branch fix/agc-skip-no-op-htile-hiz-patch` (2,356 open PRs) found only test-file positions, which were then moved. Twenty-eight PRs that conflict with `main` were searched by hand for the kernel and any HTILE Hi-Z handling; none has it. Not tested: a patch that changes cleared tiles of a native owner (it still refuses; applying new clear depths to the host image is not implemented), other GPUs, Linux, console behaviour. Rebased onto `main` f220c22162 (394 commits, none touching the files this PR changes, no conflicts). On the rebased commit `check_conventions` and `debt_fold --check` pass. All eight PRs merged together on f220c22162, the focused tests of all eight with the same environment: `main` 182 passed / 0 failed, validation layer inserted 242 times, 0 `VUID-` lines; the eight together 188 passed / 0 failed (the six new tests added), inserted 250 times, 0 `VUID-` lines. ### Related Part of the Forza Horizon 5 (PPSA22327) bring-up, #25152. The game hits these stops one after another, so these PRs were found and tested together on one stack: the other open PRs the game needs (#24960, #24994, #25151, #23688, #23545, #21479, #11825, #23778, #21155, #22306, #21199) plus the PRs below. Each one stands alone: it applies to `main` by itself, needs none of the others to build or pass its tests, and merges cleanly with every other one. - #25867 `fix/agc-materialize-cold-native-fmask`: cold native FMASK pages read as stored after a first touch - #25868 `fix/agc-multisample-read-single-sample-depth`: multisampled read over a single-sample depth surface - #25869 `fix/agc-claim-retires-memory-backed-msaa-copy`: memory-backed multisampled copy treated as a host-only alias - #25871 `fix/agc-sample-htile-stencil-after-expand`: stencil kept in HTILE read without metadata after an expand - #25872 `fix/agc-expanded-after-whole-depth-publication`: a whole native depth publication taken as an expand - #25873 `fix/agc-htile-clear-supersedes-plane-writes`: plane writes before a whole HTILE clear - #25874 `fix/agc-read-unwritten-htile-stencil-from-memory`: stencil plane read from memory for an unwritten native target ### 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) and the licence notice of code adapted from upstream (see AGENTS.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 - [x] Fixes: none - [x] Unblocks: PPSA22327 #25152 - [x] GPUs tested: AMD Radeon RX 6800 (vendor=0x1002, device=0x73bf), AMD proprietary driver 26.10.1 (Windows driver 32.0.21045.16010, Vulkan 1.4.315), Windows 11 Pro (build 26300); Khronos validation layer 1.4.363.0 on `main` and this change, 0 VUIDs - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-11-22 19:58:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T19:58:10Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change; the implementation and focused test support the stated no-op skip behavior.

What I ran

Reviewed head ee3ebc381d8b9863b63e35d66598a9e48738de18 using the prepared diff and pinned reader. I did not run tests or a build. The description reports Windows 11, AMD Radeon RX 6800, and MinGW-w64 GCC 15.3.0 results; those were not run by me.

Results

Check Result Note
Diff and targeted code review passed Five changed files read
Build and tests not run Author-reported results only
Other platforms and console not run Not verified here

Findings

Blocking

None.

Non-blocking

None.

Not verified

I read all five changed files listed as reviewed in the manifest. No changed files were excluded. I did not independently verify the reported test runs, run a build, or inspect behavior on other GPUs, Linux, or console hardware.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6014180180 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/25870#pullrequestreview-6014180180). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-22T19:58:10Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change; the implementation and focused test support the stated no-op skip behavior. ## What I ran Reviewed head `ee3ebc381d8b9863b63e35d66598a9e48738de18` using the prepared diff and pinned reader. I did not run tests or a build. The description reports Windows 11, AMD Radeon RX 6800, and MinGW-w64 GCC 15.3.0 results; those were not run by me. ## Results | Check | Result | Note | |---|---|---| | Diff and targeted code review | passed | Five changed files read | | Build and tests | not run | Author-reported results only | | Other platforms and console | not run | Not verified here | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified I read all five changed files listed as reviewed in the manifest. No changed files were excluded. I did not independently verify the reported test runs, run a build, or inspect behavior on other GPUs, Linux, or console hardware. ## To get this to a good state Nothing is required.
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!25870
No description provided.