fix(agc): take an HTILE fill from a value in memory as a depth fast clear #3816
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3816"
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 alfalfa-star on 2026-10-11T17:04:46Z.
What
Kena: Bridge of Spirits (PPSA01802) clears its depth HTILE every frame with its own compute kernel, which the driver didn't see as a clear. The depth image kept the first frames' contents. The base pass (greater-or-equal, reversed Z) and the sky then failed their depth test almost everywhere, and the title menu showed stale memory: black, white or striped, depending on the run.
The kernel is a 9-word dword fill, run as 2048x1x1 groups of 64 over the 0x80000-byte HTILE of a 3200x1800 D32S8 target:
The value comes from memory (through the V# in
user[4..7]), not from user data, so neither the DMA_DATA hook nor the known fill kernels match it.MatchMemoryValueFill(DepthSurface.cpp) matches the kernel exactly and requires:buffer_store_format_xwrites the value unconverted;The range is groups × 64 dwords, clipped to NUM_RECORDS.
NoteMemoryValueFillreads the value from guest memory when the dispatch is decoded and passes range and value toNoteDepthMetadataFill. The whole-HTILE coverage and ZMask/SMem rules of #374 apply unchanged.Dispatch.cppcalls both next to the existingHtileDepthClearAddresshook, for direct dispatches with group counts only. The dispatch itself still runs.TechnicalDebt: the HTILE fast clear entry now names the second kernel, and notes that the value is read at decode, so a value that earlier GPU work in the same submission hasn't written back yet is not seen.
Relation to #2053
#2053 (esatturan) covers HTILE written by any kernel, by reading the words when the depth target is bound. On Kena it takes only the first clear. The first bind reads 90000 of 90000 words with ZMask 0. All 299 later binds return at
UnchangedSince, because the kernel's GPU stores don't move the write generation. Details are in https://github.com/boykopovar/AnyPS5/pull/2053#issuecomment-6111465156.This PR is narrower and catches the clear at the dispatch. The two can coexist: a CP-side note here, a memory read there. If #2053 learns to see GPU-written HTILE, this matcher is still harmless (it notes the same clear earlier), and I'm happy to drop it if the maintainers prefer one path.
Tested
Arch Linux, KDE Plasma, GCC, Release, RADV (RX 9070 XT, Mesa 26.2.4), on main
a11c8f7f7.New
memoryValueFillTestsinagc_driver_graphicscovers:The user data are Kena's own words (logged in game): output format 32_UINT, and a value V# of one 16-byte record.
agc_driver_depth_fast_cleargains memory-value fills over the harness HTILE:With
NoteMemoryValueFillstubbed out, it fails at "a memory value fill of ZMask 0 over the whole HTILE did not clear the depth to DB_DEPTH_CLEAR (1.0)".ctest: 832/832.tools/check_conventions.pypasses (both on the second commit too).Kena in game: on our local stack, since Kena doesn't reach its menu on bare main for other reasons (#2548 shaders, layered draws). The stack was main
1e8fff68+ #425 + #454 + #1077 + #3645 + AlxcBTW/AnyPS5#39, with the same change.app.elf+0x1c6a46b, which happens with and without this change.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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by GustavoGamarra95 on 2026-10-11T19:48:49Z.
Beast of Reincarnation (PPSA29343, Unreal Engine) runs the same 9-word kernel: at least 40 matches in the first minutes, mostly with value 0x40404040 over HTILE ranges of 0x1000 to 0x30000 bytes (a few with 0x10101010 and 0). Cherry-picked onto my branch for that title, it removes the stale blocks its title screen showed (Linux, RTX 3050 Laptop).
We are still analyzing the remaining rendering issues of this title and an improvement for GPUs with little VRAM.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-11T23:17:36Z.
Conventions fails on the checklist: the
AI-assisted:line is unticked and has no yes or no. Please fill it in.Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-11T23:36:11Z.
Data point from a UE5 title: Sword of the Sea (PPSA25344) runs this exact kernel every frame, and this PR alone fixes its depth.
Setup: Windows 11, RTX 5070 Laptop, MinGW GCC 15.2, Release; current
mainplus our local menu-boot patches for this title (none touch depth or HTILE), with 69a67ca8a cherry-picked cleanly on top.What the title does: before the first depth draw of each frame, it clears its 1920x1080 D32S8 depth target with two compute dispatches over the whole HTILE (0xc000 dwords, 768x1x1 groups of 64, stride-4 V# in
user[0..3]):user[4..5](0 here);v_mov_b32 v1, 0in place of thes_load_dword), which this PR does not match.Since the matched one already covers the whole HTILE with 0, that's enough here.
Result: 1:1 captures at 1920x1080, 240 s. "Dark" is the share of the sky band with luma < 22; the PS5 footage is 0.000 there.
Without the clear, the GPU depth image keeps the previous frame's depth/stencil. Particle-shaped black holes then accumulate over the title-screen sky. A frame replayed from a fresh depth surface was clean, which is how we tracked it down.
If the inline-constant variant would be useful for another title, I can send its exact words.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-12T09:53:15Z.
@alfalfa-star a small edge case we hit while testing a buffer-fill version of the same kernel on our side. The kernel reads its value with
s_buffer_loadthrough the V# inuser[4..7]. When that V# doesn't cover the dword, e.g.num_records(user[6]) is 0, the hardware load returns 0 and the kernel fills with 0.MatchMemoryValueFillonly checksuser[4..5], soNoteMemoryValueFillwould read the value from memory instead. Kena's V# is valid, so nothing changes there. A one-line guard would keep the two in step: returnnulloptunlessuser[6]covers the loaded dword, or note a 0 fill in that case.One more edge of the same kind. The kernel stores with
buffer_store_format_x, so what lands in memory depends on the output V#'s FORMAT (user[3]). With a non-32-bit format, e.g. 0x27 (10_11_11), the hardware writes a converted value or 0, whileNoteMemoryValueFillnotes the raw dword. Accepting the match only for FORMAT 20–22 (32_UINT / 32_SINT / 32_FLOAT) keeps the note and the GPU in step.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by alfalfa-star on 2026-10-12T17:10:30Z.
@AlxcBTW thanks, both are right. I had also misread the kernel:
0xf4201a82iss_buffer_load_dword vcc_lo, s[4:7]and0xe0102000isbuffer_store_format_x, not thes_load_dword/buffer_store_dwordI wrote here and on #2053. The description is corrected. f80179784 adds both guards:user[3]bits 12-18) must be 20-22 (32_UINT / 32_SINT / 32_FLOAT).user[6] >= 4, and that dropped every Kena clear: Kena's value V# has NUM_RECORDS 1 with stride 16 (user[5] = 0x00100020). So the check now uses NUM_RECORDS × stride, or NUM_RECORDS bytes when the stride is 0, which is the byte range the hardware checks a scalar buffer load against.I logged Kena's own words in game (
user[3..7]=00014204 …e70c 00100020 00000001 0004dfac): format 32_UINT, one 16-byte value record. The unit tests now use those words, plus cases for the refused formats, an empty value V#, and a raw 4-byte / 3-byte value buffer. With the corrected check, Kena still notes the whole-HTILE clears (13 in the first 60 s of the run). ctest 832/832, conventions pass.@GustavoGamarra95 and @AlxcBTW, thanks for the Beast of Reincarnation and Sword of the Sea data. Since three UE titles run this kernel, it's likely UE's own HTILE clear. The inline-constant variant would be a separate matcher; I'd leave it out of this PR unless a title needs it alone.
@oneandonlydean the AI-assisted line is filled in.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by GustavoGamarra95 on 2026-10-12T18:08:48Z.
Rechecked Beast of Reincarnation (PPSA29343) with f801797: its value V# and output format pass the new guards. In 170 s at 1080p output the driver noted 248 whole-HTILE clears (value 0), and the title screen renders without the stale blocks (Linux, RTX 3050 Laptop).
Follow-up to "still analyzing" above: the blocks that remained on that title had a separate cause, storage results still pending under memory that a later dispatch wrote as a buffer (Unreal's transient allocator reuses it for both). That fix is #4654.
Imported from boykopovar/AnyPS5. Originally posted by TideOPL on 2026-10-12T19:49:00Z.
Another UE5 data point: Minecraft Dungeons II (PPSA16064) clears its scene depth HTILE with this same 9-word kernel every frame, and this PR fixes its depth.
Without it, the host depth image never clears. The depth pre-pass (greater-or-equal, reversed Z) keeps the nearest depth of the animated foliage from earlier frames. The base pass then fails its depth test, so two-sided masked materials (grass, flowers, leaves, the campfire flame) render solid black on the title screen, and gameplay scenes are mostly dark. The black shapes are larger than the plants because they hold the union of their earlier positions. A constant depth bias of about 10⁶ units on the base pass hides the symptom, which is how the stale depth showed up.
The match: one dispatch per frame over the scene depth's HTILE, 0x60000 bytes, value 0. With 69a67ca8a and f80179784 cherry-picked, the driver notes the clear every frame and the title renders the same as our reference build. That reference build ran this kernel as a buffer fill via an older local patch, which is how I found it.
Tested by reviewer:
mainA/B: MCD2 doesn't reach its title on plainmainyet (it stops on the depth-plane sample that #425 adds). I tested onmaine7c70a2dfplus #425 and the patches MCD2 needs to boot, none of which touch HTILE or fills. A/B with and without the two commits, same capture points, title screen at +20 s and +35 s: black foliage without, correct with.NoteDepthMetadataFill.