fix(agc): take depth fast clears from HTILE written by any kernel #2053
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2053"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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_DATAfill or a buffer-fill kernel it recognizes over the HTILE. PPSA29141 clears its depth every frame with its own compute kernel (InvokeHTileClearComputeShaderin Unity'sClearMRTpass), which neither hook sees. Its depth kept every earlier frame, and moving objects left black trails.DB_STENCIL_INFO.TILE_STENCIL_DISABLEclear) cleared, the surface takes #374's pending fast clear.Tested
Windows 11, i7-13650HX, RTX 4070 Laptop, MinGW-w64 GCC 15.2.
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_submitandagc_driver_graphicspass.cteston currentmain(c6e3aa76) merged with this branch, the other LEGO Party! PRs and #1482: 547/547 pass. On Windows,main'slibsstep currently fails withduplicate patched export name: LibwuIonIBw: #1714 addedAPS5_EXPORTs forsceVideoOutAddVrrActiveStatusEventandsceVideoOutAddVrrStatusFlagsPrivilege, whose names the NID table already maps. Those two lines were removed locally for the run.--module-dirfor its plugins, and #846 no longer merges with today'smain, so the title was not converted and run again on it.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)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.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.
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:
DB_RENDER_CONTROL: #2504. Onmainwith #1482, PPSA29141 stops there:depth/stencil clear, copy, resummarize or decompress draws (DB_RENDER_CONTROL) is unsupported (register 0x0 = 0x00000022).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 newagc_driver_depth_htile_writetest fails on #374's head and passes here; #374's tests still pass.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
948a526c2has source conflicts; these results validate the standalone PR head, not a resolved merge.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(57f96fd2plus 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.mainonly 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 ofmain.AI-assisted: yes
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 main262c031692a0ce538707436fa1587b671ace682bplus the current #374 head94d93e00f. The cherry-pick conflicts inDepthSurface.cppand TechnicalDebt were resolved locally, preserving main's RADV clear-HTILE notification path and current CMASK behavior. Local integration:4351bfe97.0xc0000005, reading null insideamdvlk64.dll+0x21c4c42. The captured main-thread stack is waiting inClearPipelineLibrariesduring cleanup.APS5_NO_PIPELINE_LTO=1setting. 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.
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 applied9a62ec7ecby hand there because it conflicts with #425'sDepthSurface.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# inuser[4..7](disassembly corrected after #3816's review):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
noteHtileWritesover a 150 s run: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.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.
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.cppand the fast-clear tests).The PPSA01802 report above also needs an answer before this goes into testing: after the first clear,
noteHtileWritesreturns atUnchangedSinceon every later bind, because a compute kernel's stores to the HTILE don't move the write generation.agc_driver_depth_htile_writewrites 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.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.
maininDepthSurface.cpp,State.cpp,BufferFill.cpp,PacketMemory.cppand the fast-clear tests; the branch still carries #374's commits. Rebase so only the last commit remains, and rerunagc_driver_depth_fast_clear,agc_driver_depth_fast_clear_submit,agc_driver_graphicsandagc_driver_depth_htile_writeafterwards.DepthSurface.cpp:179:noteHtileWritesreturns atUnchangedSinceon 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_writewrites 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.Welcome to push the rebase and I'll look again.
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:0xfffffff0, cleared to 1.0);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_CLEARlights 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):
CollectWritesover the HTILE range, thenUnchangedSince(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 thatUnchangedSinceCollectedignoresMarkWrittenstamps, so it misses GPU writes.SyncThroughfirst, so the words are read in stream order.si_get_htile_clear_valuewrites). 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.vkCmdFillBufferinto 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_PATTERNentry 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_PATTERNentry 4).I can test a rebased head of this PR on PPSA05684 if that helps.
AI-assisted: yes
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
mainwith follow-ups that take in @oneandonlydean's two-frame request and @XairRrR's slice data.What happens without the store-back
MatchMemoryValueFill), so the clear itself is already taken onmain. The guest HTILE then keeps ZMask 0 for the whole frame, because our depth draws never update it.Evidence (frame journal replay of one such frame, NVIDIA)
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 rewrittenDepthSurfaceView, the debt entry moved todocs/dev/debt/libSceAgcDriver.md, and the test's tile count adjusted tomain's harness. Two commits of ours sit on top:DB_HTILE_DATA_BASE(tiles * 4bytes).mainmodels the HTILE as the pipe-aligned SW_64KB_Z_X metadata (HtileMetadataBytes, the extentHtileFillCoverstakes). 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 firsttiles * 4bytes, so they would keep ZMask 0 after a store-back. The read and the store-back now cover the whole metadata, and they run beforeDepthSurfaceViewtakes the surfaces mutex, since both wait for recorded work over the range. The test HTILE arrays hold the whole metadata.DepthTarget::slicecarriesDB_DEPTH_VIEWSLICE_START for that. With @XairRrR's stride (base + slice × 256 KiB for 2048² D16, which equalsHtileMetadataBytesthere, 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:0xfffc000f/0xfffff3ff). This fails onmain, where the words stay 0.s_nop, so no matcher takes it) clears the HTILE on two frames in a row, and both clears are taken.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 passesagc_driver_graphicsand everyagc_driver_depth_*test. The only failure,guest_math, fails the same way onmain.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.
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'ssliceSize * sliceinGfx10Lib::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 atslice × 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 × sliceSize. Slice 3 needs bits 8 to 11 (at most 6 of 65536 tiles differ, at the mask edges).GFX10_HTILE_SW_PATTERNhas 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
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.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.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.
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.
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.
main)core/libs/prx/libSceAgcDriver/tests/execution/DepthHtileWrite.cppImported 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.
Pull request closed