perf(agc): handle the zero dword fill kernel as a buffer fill #4012
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4012"
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 queeeef on 2026-10-11T21:15:27Z.
What
A wave64 compute kernel that stores dword 0 at
group * 64 + threadthrough a buffer descriptor is run as a buffer fill of zeros, next to the existing dword pattern-fill kernel (#2081). The kernel is 6 words:Palworld (PPSA23126) clears the DCC keys of its render targets with it every frame. As a shader dispatch its stores were unknown to the DCC key proofs, so each later refresh of those keys waited for the GPU to finish.
MatchZeroDwordFilltakes a dispatch as this fill only when all of these hold, and otherwise leaves it to the recompiler:s4;add_tidand out-of-bounds select 0;min(groups * 64, records)dwords is a non-zero multiple of 16 bytes at a 16-byte-aligned base.Tested
Windows 11 Pro 26300, i5-13600K, RTX 2080 Ti (NVIDIA 610.74), MinGW-w64 GCC 15.2.0 (WinLibs r7), configured like the Windows CI job (
-G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON), atfed11bde:ctest --timeout 120 --parallel 12: 844 tests, 839 passed, 5 skipped (video_out_flip_*andguest_video_out_wqhd_detection_no_vulkan), 0 failed.agc_driver_zero_dword_filltest:add_tid, out-of-bounds select 3, an unaligned base, or 102 records;Submit, comparing every dword of the buffer with what the kernel writes. Fill-shaped dispatches and ones it refuses are both included (100 and 102 records, stride 8, a 70-thread partial dispatch, 0 groups). It also passes withAPS5_NO_FILL_HLE=1, where the recompiled shader runs instead.tools/check_test_registration.py,tools/check_conventions.py --base upstream/mainandgit diff --checkpass.I don't know which compiler or engine emits this kernel. Only the exact code words above match.
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 oneandonlydean on 2026-10-11T23:20:21Z.
Could you measure the Palworld menu with and without this PR on the same base? Perf PRs need numbers for the change itself (#218); frame time, or the key-refresh waits per frame, is enough.
Imported from boykopovar/AnyPS5. Originally posted by queeeef on 2026-10-12T03:35:25Z.
Measured on the Palworld main menu, idle, with and without this change on the same build.
Setup
mainplus the open PRs the title needs (#2648), this PR, and local changes such as #4072. All runs use the same build.MatchZeroDwordFillreturnstd::nullopt, so only this change is off.APS5_NO_FILL_HLEwould also turn off the existing pattern fills.APS5_PROFILE_DRAWandAPS5_PROFILE_GPU.SyncThroughinWaitForKeyWriters.What is left. About 2 waits per frame remain. They are mostly on a 2536x1428 R8 target whose keys another shader writes, about 25 ms each. That shader is a different kernel and not part of this PR.
AI-assisted (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by johnmaia on 2026-10-12T13:35:24Z.
Tested on Linux, which the description lists as not tested: Ubuntu, kernel 7.0, RX 7600 (RADV NAVI33, Mesa 25.2.8), GCC Release, head
fed11bde6merged onto maine7c70a2df.Epic Mickey: Rebrushed (PPSA15657, Unreal Engine 4) uses the same kernel. Base: main + #3763, #2904, #425 and #4363, which it needs to reach the first level. Measured with
APS5_PROFILE_DRAW=1, per 10 s in the level:DISPATCH_DIRECTthrough the fill pathThe kernel matches about 108 times a second, and the level renders the same. Recorded-store syncs (
WaitForKeyWriters) drop by about 45%. Total GPU wait and FPS did not move beyond what differs between my runs, which aren't scripted identically. Other writers of the same DCC keys still cause syncs in this title, so that is not a limit of this PR.Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-12T16:20:18Z.
Sword of the Sea (PPSA25344, UE5) runs this exact kernel every frame to clear DCC keys, so here are two points from testing a buffer-fill version of it on our side.
Output format. The kernel stores with
buffer_store_format_x, so the bytes it writes depend on the output V#'s FORMAT (user[3]bits 12-18). With 32_UINT, 32_SINT or 32_FLOAT (20-22) the dword lands unchanged. With another format, the hardware converts the value, and an 8- or 16-bit format writes only 1 or 2 bytes per element. A zero fill of the whole range would then also clear the bytes between those elements.MatchZeroDwordFilldoesn't check FORMAT. Accepting only 20-22 would keep the fill and the kernel in step. Your test descriptors use format 20, so they would still pass. #2081'sMatchDwordPatternFillhas the same gap. We're sending a separate small fix for that one, and #3816's matcher has the same gap too (noted there).Keys outside storage images. The fill is noted in the GPU key-store memo only when
ClassifyFillreportsFillCover::Keys, andClassifyFillreports that only for storage images' keys. In Sword of the Sea,ClassifyFilldoesn't report this kernel's fills asKeys, so they never reach the memo and the next key read still waits inWaitForKeyWriters. On a local branch we took this kernel as a fill and also noted a byte-uniform fill from it in the memo, whatever its cover. The key-writer waits behind this kernel then went away: about 415 per 10 s in the menu, Windows 11, RTX 5070 Laptop. We did not measure the fill without the memo note, so we don't know how much the fill path alone removes there. If it's useful, I can send that as a follow-up once this is merged, so this PR stays as it is.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-13T02:42:30Z.
MatchZeroDwordFillneeds the output-format check that main'sMatchDwordPatternFillhas had since4309bffdb(format < 20u || format > 22u,BufferFill.cpp). The kernel stores through the V#'s FORMAT, so with an 8- or 16-bit format it writes 1 or 2 bytes per element and a zero fill of the whole range also clears the bytes between them (AlxcBTW's first point above). Please rebase, add the check and a test row with a format outside 20-22 that is refused.Imported from boykopovar/AnyPS5. Originally posted by TideOPL on 2026-10-13T10:14:56Z.
Tested #4012 and #4603 together on Minecraft Dungeons II (PPSA16064) gameplay at the Squid Coast spawn: Windows 11, RTX 5070, trace window 25-40 s after the HUD (#4526 trace,
APS5_TRACE_SECONDS=25:15). Base:main+ #4367 #4515 #4517 + #3816 + #425 + #3763 + local patches MCD2 needs.MCD2 clears DCC keys with both kernels. Run as shader dispatches, their stores made the key proofs of later render-target refreshes wait for the GPU (
StorageTexture::Refresh->ProvedKeys->WaitForKeyWriters->SyncThroughwas the largest sync source on queue 0). With both PRs: queue-0Recorder.Sync11.7 -> 7.3 per frame (8.7 -> 6.1 ms),GpuMutex.wait.dispatch6 -> 4 ms per frame.The two PRs conflict in
BufferFill.cpp/DwordPatternFill.hpp; I chained the matchers as pattern, zero, memory value.Not run: Linux, AMD, the PRs' own tests.
AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-13T10:36:02Z.
Thanks for the PR and the measurements, and to @AlxcBTW and @oneandonlydean for the review.
Added the output-format check @oneandonlydean asked for as a separate commit on top (
99ebc650c), rebased on currentmain:MatchZeroDwordFillnow refuses a V# FORMAT outside 20-22, same asMatchDwordPatternFill, so 8/16-bit formats are not zero-filled over the bytes between elements.MatchTests: formats 17 and 23 are refused, 21 and 22 match.Checked:
agc_driver_zero_dword_fillpasses, and fails with the check removed; the rest of libSceAgcDriver's tests are green (agc_driver_tessellationcrashes inside RADV pipeline linking with and without this change). Merging once the full Build is green.Imported from boykopovar/AnyPS5. Originally posted by coltken95 on 2026-10-13T12:06:01Z.
Tested on Linux x86-64 (Release build, lavapipe / llvmpipe LLVM 20.1.2), with
99ebc650ccherry-picked onto main5d50886ee:agc_driver_zero_dword_fillpasses.'MatchZeroDwordFill' has not been declared in 'AgcDriver::DriverDetail'Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-13T13:20:51Z.
Checked the zero-fill match (stride, swizzle, add_tid, OOB select, FORMAT 20-22, alignment, partial dispatch, record clamp) and its execution test against the recompiled path;
agc_driver_zero_dword_fillpasses, and fails to build without the change. Format check requested by @oneandonlydean is in. Merging once the full build is green.