perf(agc): learn a bound depth target's fast clear from its pending HTILE fill #6764

Closed
SP4C3B4R-8 wants to merge 1 commit from upstream-pr/6764 into main
SP4C3B4R-8 commented 2026-10-16 10:36:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by SP4C3B4R-8 on 2026-10-16T10:36:50Z.


What

When a depth target is bound while a recorded uniform fill of its HTILE is still pending, storeBackClearedHtile reads the whole HTILE on the CPU to learn the fast clear. The read goes through the flush hook, so it waits for the batch that holds the fill, inside the draw.

Astro Bot (PPSA21564) clears its shadow cascades this way every frame (2048x2048, a 256 KiB HTILE each). At -lvl hub_crashsite that was about 190 such reads per 10 s, 3.3 s of hook waits inside queue 0's draws ([draws] ... hook waits inside draws), and every one of them read the uniform word the fill had just been noted with (NoteDepthMetadataFill).

  • NoteDepthMetadataFill keeps the fill's word with the recorder note of its write (LastWriteNote, only under the GPU mutex, so a fill stored on the CPU keeps none).
  • At the bind, while that note is still the newest recorded write over the target's HTILE (NewestWriteNote) and no unit shadow covers it, the HTILE will hold that word: the clear is taken from it without reading. Same scheme as the DCC key memo (NoteKeysFillOnGpu/PendingStoreKeys).
  • The expanded words the CPU path writes after its read go in by a GPU fill ordered behind the noted one; that fill becomes the range's newest note, so the next bind takes no clear again, and once the batch is done the HTILE in memory is expanded as before.
  • Any other noted metadata write over the range (forgetHtileReads: another fill, a recognized HTILE clear kernel) drops the kept fill. Anything else, the CPU path runs as before.

Measured on Windows (where draw inputs need #6763 to leave the GPU-bound regime), Crash Site, APS5_PROFILE_DRAW=1/APS5_PROFILE_GPU=1: hook waits inside draws 3.3 s -> 0.0 s per 10 s, queue 0 worker 74.6 -> 32.1 us per draw packet; with the draw input copies, 7.52 -> 7.86 fps. Dumped frames match (shadows of the player, the tower and the foliage on the sand).

Tested

Windows 11 Pro (26300), MinGW-w64 GCC 15.2.0, Release, Ryzen 7 7800X3D, RTX 5070 Ti.

  • agc_driver_depth_fast_clear_submit gains PendingFillClearsWithoutWait: a GPU fill of the HTILE, noted and still pending, then a bind of the target (depth only, and depth with stencil in the HTILE): the clear is taken with no hook wait (Recorder::ThreadHookWaits unchanged), the HTILE ends expanded (0xfffc000f / 0xfffff3ff), and the next draw keeps its depth. With the new path disabled it fails ("the bind read the HTILE under its pending fill: it waited for the batch").
  • The 25 depth, HTILE and fill tests (ctest -R "depth|htile|fast_clear|_fill") pass. agc_driver_multisample_fill_host_only fails now and then here ("the sentinel fill did not land"), 1 of 10 runs on main without this change too.
  • tools/check_conventions.py --base origin/main passes.

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
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes (Claude). I reviewed and take responsibility for every line.

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4887112425 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6764). Originally posted by [SP4C3B4R-8](https://github.com/SP4C3B4R-8) on 2026-10-16T10:36:50Z. --- ### What When a depth target is bound while a recorded uniform fill of its HTILE is still pending, `storeBackClearedHtile` reads the whole HTILE on the CPU to learn the fast clear. The read goes through the flush hook, so it waits for the batch that holds the fill, inside the draw. Astro Bot (PPSA21564) clears its shadow cascades this way every frame (2048x2048, a 256 KiB HTILE each). At `-lvl hub_crashsite` that was about 190 such reads per 10 s, 3.3 s of hook waits inside queue 0's draws (`[draws] ... hook waits inside draws`), and every one of them read the uniform word the fill had just been noted with (`NoteDepthMetadataFill`). - `NoteDepthMetadataFill` keeps the fill's word with the recorder note of its write (`LastWriteNote`, only under the GPU mutex, so a fill stored on the CPU keeps none). - At the bind, while that note is still the newest recorded write over the target's HTILE (`NewestWriteNote`) and no unit shadow covers it, the HTILE will hold that word: the clear is taken from it without reading. Same scheme as the DCC key memo (`NoteKeysFillOnGpu`/`PendingStoreKeys`). - The expanded words the CPU path writes after its read go in by a GPU fill ordered behind the noted one; that fill becomes the range's newest note, so the next bind takes no clear again, and once the batch is done the HTILE in memory is expanded as before. - Any other noted metadata write over the range (`forgetHtileReads`: another fill, a recognized HTILE clear kernel) drops the kept fill. Anything else, the CPU path runs as before. Measured on Windows (where draw inputs need #6763 to leave the GPU-bound regime), Crash Site, `APS5_PROFILE_DRAW=1`/`APS5_PROFILE_GPU=1`: hook waits inside draws 3.3 s -> 0.0 s per 10 s, queue 0 worker 74.6 -> 32.1 us per draw packet; with the draw input copies, 7.52 -> 7.86 fps. Dumped frames match (shadows of the player, the tower and the foliage on the sand). ### Tested Windows 11 Pro (26300), MinGW-w64 GCC 15.2.0, Release, Ryzen 7 7800X3D, RTX 5070 Ti. - `agc_driver_depth_fast_clear_submit` gains `PendingFillClearsWithoutWait`: a GPU fill of the HTILE, noted and still pending, then a bind of the target (depth only, and depth with stencil in the HTILE): the clear is taken with no hook wait (`Recorder::ThreadHookWaits` unchanged), the HTILE ends expanded (0xfffc000f / 0xfffff3ff), and the next draw keeps its depth. With the new path disabled it fails ("the bind read the HTILE under its pending fill: it waited for the batch"). - The 25 depth, HTILE and fill tests (`ctest -R "depth|htile|fast_clear|_fill"`) pass. `agc_driver_multisample_fill_host_only` fails now and then here ("the sentinel fill did not land"), 1 of 10 runs on `main` without this change too. - `tools/check_conventions.py --base origin/main` passes. ### 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 - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in TechnicalDebt - [x] No notes, investigation `.md` files or images added to the repository - [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 (Claude). I reviewed and take responsibility for every line. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-16 10:51:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-16T10:51:51Z.


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
PR 5987 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp L3
PR 6146 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp L10
PR 6505 core/libs/prx/libSceAgcDriver/tests/execution/DepthFastClearSubmit.cpp L2, L258

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

Pull request Shared files not compared
PR 1368 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 1395 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 5499 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 6292 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 6300 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 6423 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 6553 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 6615 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 6727 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 6808 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 6977 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 6989 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 6995 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 7002 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 7154 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 7201 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6213886844 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6764#issuecomment-6213886844). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-16T10:51:51Z. --- <!-- 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 | |---|---|---|---| | [PR 5987](https://www.github.com/boykopovar/AnyPS5/pull/5987) | `core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp` [L3](https://github.com/boykopovar/AnyPS5/blob/1c523bdb48f724c06d0f526ddfbcd4c3a22bbea0/core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp#L3) | | | | [PR 6146](https://www.github.com/boykopovar/AnyPS5/pull/6146) | `core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp` [L10](https://github.com/boykopovar/AnyPS5/blob/1c523bdb48f724c06d0f526ddfbcd4c3a22bbea0/core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp#L10) | | | | [PR 6505](https://www.github.com/boykopovar/AnyPS5/pull/6505) | `core/libs/prx/libSceAgcDriver/tests/execution/DepthFastClearSubmit.cpp` [L2](https://github.com/boykopovar/AnyPS5/blob/1c523bdb48f724c06d0f526ddfbcd4c3a22bbea0/core/libs/prx/libSceAgcDriver/tests/execution/DepthFastClearSubmit.cpp#L2), [L258](https://github.com/boykopovar/AnyPS5/blob/1c523bdb48f724c06d0f526ddfbcd4c3a22bbea0/core/libs/prx/libSceAgcDriver/tests/execution/DepthFastClearSubmit.cpp#L258) | | | Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap. | Pull request | Shared files not compared | |---|---| | [PR 1368](https://www.github.com/boykopovar/AnyPS5/pull/1368) | `core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp` | | [PR 1395](https://www.github.com/boykopovar/AnyPS5/pull/1395) | `core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp` | | [PR 5499](https://www.github.com/boykopovar/AnyPS5/pull/5499) | `core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp` | | [PR 6292](https://www.github.com/boykopovar/AnyPS5/pull/6292) | `core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp` | | [PR 6300](https://www.github.com/boykopovar/AnyPS5/pull/6300) | `core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp` | | [PR 6423](https://www.github.com/boykopovar/AnyPS5/pull/6423) | `core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp` | | [PR 6553](https://www.github.com/boykopovar/AnyPS5/pull/6553) | `core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp` | | [PR 6615](https://www.github.com/boykopovar/AnyPS5/pull/6615) | `core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp` | | [PR 6727](https://www.github.com/boykopovar/AnyPS5/pull/6727) | `core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp` | | [PR 6808](https://www.github.com/boykopovar/AnyPS5/pull/6808) | `core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp` | | [PR 6977](https://www.github.com/boykopovar/AnyPS5/pull/6977) | `core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp` | | [PR 6989](https://www.github.com/boykopovar/AnyPS5/pull/6989) | `core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp` | | [PR 6995](https://www.github.com/boykopovar/AnyPS5/pull/6995) | `core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp` | | [PR 7002](https://www.github.com/boykopovar/AnyPS5/pull/7002) | `core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp` | | [PR 7154](https://www.github.com/boykopovar/AnyPS5/pull/7154) | `core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp` | | [PR 7201](https://www.github.com/boykopovar/AnyPS5/pull/7201) | `core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp` |
parl0v commented 2026-10-16 21:06:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by parl0v on 2026-10-16T21:06:38Z.


Data point from a CPU-bound scene on Windows: RTX 3060 12 GB (NVIDIA 617.42), i5-12400F, Windows 10 19045, MinGW GCC Release. Minecraft Dungeons II (PPSA16064 01.100.100), title screen, no input, 200 s rows, APS5_PROFILE_DRAW=1 APS5_PROFILE_GPU=1; main c84249186 vs main + this PR, interleaved with three other PRs in one batch, two rounds. FPS is the mean of the last 10 [present] windows, GPU busy and idle gaps per frame over the last 8. This scene is CPU-bound on this machine (45-48 ms of idle gaps per frame).

libs FPS GPU busy idle gaps
main 6.60 / 6.60 105 / 104 ms 46 / 48 ms
+ this PR (d9621eddb) 6.70 / 6.60 (+0.8 %) 104 / 106 ms 45 / 45 ms

Within the run-to-run spread (about ±1.5 % here), no regression, 0 fatal.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6224699744 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6764#issuecomment-6224699744). Originally posted by [parl0v](https://github.com/parl0v) on 2026-10-16T21:06:38Z. --- Data point from a CPU-bound scene on Windows: RTX 3060 12 GB (NVIDIA 617.42), i5-12400F, Windows 10 19045, MinGW GCC Release. Minecraft Dungeons II (PPSA16064 01.100.100), title screen, no input, 200 s rows, `APS5_PROFILE_DRAW=1 APS5_PROFILE_GPU=1`; `main` c84249186 vs `main` + this PR, interleaved with three other PRs in one batch, two rounds. FPS is the mean of the last 10 `[present]` windows, GPU busy and idle gaps per frame over the last 8. This scene is CPU-bound on this machine (45-48 ms of idle gaps per frame). | libs | FPS | GPU busy | idle gaps | |---|---|---|---| | `main` | 6.60 / 6.60 | 105 / 104 ms | 46 / 48 ms | | + this PR (d9621eddb) | 6.70 / 6.60 (+0.8 %) | 104 / 106 ms | 45 / 45 ms | Within the run-to-run spread (about ±1.5 % here), no regression, 0 fatal. AI-assisted: yes (Claude Code)
keravyn-ops commented 2026-10-17 08:13:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by keravyn-ops on 2026-10-17T08:13:36Z.


Hi @SP4C3B4R-8 — this looks like the same change as #6505 (opened 2026-10-15): both take a bound depth target's fast clear from a pending uniform HTILE fill and record the expanded words as a GPU fill behind it, instead of reading the HTILE in storeBackClearedHtile.

#6505 has test reports so far from ASTRO BOT hub_crashsite (Windows/AMD, 5.3 → 6.9 fps), Planet of Lana (RTX 3070 Laptop, 7.06 → 8.89 fps, pending-write syncs 263 → 0) and Hollow Knight: Silksong (Radeon 780M, 44–46 → 60–61 fps), and now also covers the depth and stencil case your PendingFillClearsWithoutWait checks.

Happy to run both PRs side by side on the 780M if that helps the maintainers pick one.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6231606201 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6764#issuecomment-6231606201). Originally posted by [keravyn-ops](https://github.com/keravyn-ops) on 2026-10-17T08:13:36Z. --- Hi @SP4C3B4R-8 — this looks like the same change as #6505 (opened 2026-10-15): both take a bound depth target's fast clear from a pending uniform HTILE fill and record the expanded words as a GPU fill behind it, instead of reading the HTILE in `storeBackClearedHtile`. #6505 has test reports so far from ASTRO BOT `hub_crashsite` (Windows/AMD, 5.3 → 6.9 fps), Planet of Lana (RTX 3070 Laptop, 7.06 → 8.89 fps, pending-write syncs 263 → 0) and Hollow Knight: Silksong (Radeon 780M, 44–46 → 60–61 fps), and now also covers the depth and stencil case your `PendingFillClearsWithoutWait` checks. Happy to run both PRs side by side on the 780M if that helps the maintainers pick one.
tibzejoker commented 2026-10-17 14:51:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by tibzejoker on 2026-10-17T14:51:28Z.


Tested on GTA V (PPSA04264) in the open world (Los Santos, a story save resumed), Windows 11, RTX 4090 (driver 616.92), i9-13900K. Both HTILE PRs were measured on the same base, one run each, in the same session: main 47a266cf9 + #6488 + #6848, which GTA needs to render. APS5_PROFILE_DRAW=1, last 12 windows of 10 s (two minutes in the world, warm shader cache).

Build [hooksync] pending-write syncs / 10 s waited / 10 s committer µs per draw
base (3 runs) 595 / 622 / 708 555 / 591 / 666 ms 41.8 / 45.5 / 36.6
+ #6505 (7918fd477) 502 138 ms 41.7
+ #6764 (d9621eddb) 617 354 ms 40.6

A committer profile of the base (sampling the DrawPipeline thread) puts DepthSurfaceView → storeBackClearedHtile → GuestMemory::Read → FlushForAccess → Recorder::Sync at about 5 % of the committer's samples, so GTA hits the case both PRs handle. In this scene #6505 removes about 75 % of the hook wait time and #6764 about 40 %. FPS and the committer cost per draw stay within run-to-run noise: the committer is ~84 % busy with other per-draw work. Neither run crashed. I checked the rendering on the #6764 run's screenshots (correct); the #6505 run's were overwritten before I looked.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6235329924 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6764#issuecomment-6235329924). Originally posted by [tibzejoker](https://github.com/tibzejoker) on 2026-10-17T14:51:28Z. --- Tested on GTA V (PPSA04264) in the open world (Los Santos, a story save resumed), Windows 11, RTX 4090 (driver 616.92), i9-13900K. Both HTILE PRs were measured on the same base, one run each, in the same session: `main` 47a266cf9 + #6488 + #6848, which GTA needs to render. `APS5_PROFILE_DRAW=1`, last 12 windows of 10 s (two minutes in the world, warm shader cache). | Build | `[hooksync]` pending-write syncs / 10 s | waited / 10 s | committer µs per draw | |---|---|---|---| | base (3 runs) | 595 / 622 / 708 | 555 / 591 / 666 ms | 41.8 / 45.5 / 36.6 | | + #6505 (7918fd477) | 502 | **138 ms** | 41.7 | | + #6764 (d9621eddb) | 617 | 354 ms | 40.6 | A committer profile of the base (sampling the `DrawPipeline` thread) puts `DepthSurfaceView` → `storeBackClearedHtile` → `GuestMemory::Read` → `FlushForAccess` → `Recorder::Sync` at about 5 % of the committer's samples, so GTA hits the case both PRs handle. In this scene #6505 removes about 75 % of the hook wait time and #6764 about 40 %. FPS and the committer cost per draw stay within run-to-run noise: the committer is ~84 % busy with other per-draw work. Neither run crashed. I checked the rendering on the #6764 run's screenshots (correct); the #6505 run's were overwritten before I looked. AI-assisted (Claude Code).
SP4C3B4R-8 commented 2026-10-18 08:28:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by SP4C3B4R-8 on 2026-10-18T08:28:02Z.


Closing in favour of #6505, which takes the same idea further (75% of the GTA V hook wait removed against 40% here, per @tibzejoker's side-by-side run) and now covers the depth and stencil case PendingFillClearsWithoutWait checked. Thanks @keravyn-ops for pointing it out.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6247634163 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6764#issuecomment-6247634163). Originally posted by [SP4C3B4R-8](https://github.com/SP4C3B4R-8) on 2026-10-18T08:28:02Z. --- Closing in favour of #6505, which takes the same idea further (75% of the GTA V hook wait removed against 40% here, per @tibzejoker's side-by-side run) and now covers the depth and stencil case `PendingFillClearsWithoutWait` checked. Thanks @keravyn-ops for pointing it out.

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