Skip to content

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

Closed
SP4C3B4R-8 wants to merge 1 commit into
boykopovar:mainfrom
SP4C3B4R-8:perf/htile-pending-fill
Closed

SP4C3B4R-8 wants to merge 1 commit into
boykopovar:mainfrom
SP4C3B4R-8:perf/htile-pending-fill

Conversation

@SP4C3B4R-8

Copy link
Copy Markdown
Contributor

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

…TILE fill

A depth target whose HTILE a recorded uniform fill is still writing made storeBackClearedHtile read the
whole HTILE on the CPU, so the flush hook waited for the batch holding the fill. Astro Bot clears its
shadow cascades' HTILE that way every frame (2048x2048, 256 KiB each): about 190 such reads per 10 s at
Crash Site, 3.3 s of GPU waits inside queue 0's draws, every one reading the uniform word the fill had
just been noted with.

NoteDepthMetadataFill now keeps the fill's word with the recorder note of its write. While that write is
still the newest recorded write over the target's HTILE (and no unit shadow covers it), the word is what
the range will hold: the clear is taken from it, and the expanded words the CPU path writes after its read
go in by a GPU fill ordered behind the noted one, which becomes the range's newest note. Any other noted
metadata write over the range (forgetHtileReads) drops the kept fill.

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, and depth with stencil in the HTILE) takes the clear
without a hook wait, leaves the HTILE expanded, and a later draw keeps its depth.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added the agc libSceAgc* label Oct 16, 2026
@github-actions

github-actions Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

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

@parl0v

parl0v commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

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 c842491 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 (d9621ed) 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

Copy link
Copy Markdown
Contributor

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

tibzejoker commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

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 47a266c + #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 (7918fd4) 502 138 ms 41.7
+ #6764 (d9621ed) 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

Copy link
Copy Markdown
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc*

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants