Skip to content

perf(agc): handle the zero dword fill kernel as a buffer fill - #4012

Merged
adriadam10 merged 2 commits into
boykopovar:mainfrom
queeeef:perf/agc-zero-dword-fill
Oct 13, 2026
Merged

adriadam10 merged 2 commits into
boykopovar:mainfrom
queeeef:perf/agc-zero-dword-fill

Conversation

@queeeef

@queeeef queeeef commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

What

A wave64 compute kernel that stores dword 0 at group * 64 + thread through 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:

v_lshl_add_u32 v0, s4, 6, v0
v_mov_b32 v1, 0
buffer_store_dword v1, v0, s[0:3], 0 idxen
s_endpgm

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.

MatchZeroDwordFill takes a dispatch as this fill only when all of these hold, and otherwise leaves it to the recompiler:

  • the 6 code words match exactly;
  • 4 user SGPRs, so the group id is in s4;
  • group id X enabled, 64×1×1 threads, not a partial dispatch, 1×1 groups in Y and Z;
  • the descriptor has stride 4, no swizzle, no add_tid and out-of-bounds select 0;
  • the filled range 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), at fed11bde:

  • ctest --timeout 120 --parallel 12: 844 tests, 839 passed, 5 skipped (video_out_flip_* and guest_video_out_wqhd_detection_no_vulkan), 0 failed.
  • The new agc_driver_zero_dword_fill test:
    • Matching: the kernel matches, and these do not:
      • one bit flipped in any code word, or truncated code;
      • stride 8, add_tid, out-of-bounds select 3, an unaligned base, or 102 records;
      • an extra user SGPR, a partial dispatch, or no group id.
    • A 256-byte descriptor clamps the fill.
    • Execution: 8 dispatches through 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 with APS5_NO_FILL_HLE=1, where the recompiled shader runs instead.
    • Writing 1s instead of 0s in the fill makes it fail.
  • tools/check_test_registration.py, tools/check_conventions.py --base upstream/main and git diff --check pass.
  • Linux not tested.
  • Title: Palworld (PPSA23126, 01.102.999), main menu, with the other open PRs it needs (Palworld (PPSA23126): next start-up stop is unresolved import oiOi7vgPfAY (sceAudioOut2EnableChat) #2648):
    • the kernel runs about 15 times a frame and now goes through the fill path;
    • the main menu renders the same;
    • frame rate measured only together with other local changes, so no number is claimed for this change alone.

I don't know which compiler or engine emits this kernel. Only the exact code words above match.

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 (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes (Claude Code)

🤖 Generated with Claude Code

@github-actions github-actions Bot added the agc libSceAgc* label Oct 11, 2026
@oneandonlydean

Copy link
Copy Markdown
Collaborator

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.

@queeeef

queeeef commented Oct 12, 2026

Copy link
Copy Markdown
Contributor Author

Measured on the Palworld main menu, idle, with and without this change on the same build.

Setup

Presents / 10 s Frame time Key-refresh waits / frame GPU idle gaps / present
With #4012, run 1 202.0 49.5 ms 2.0 4.6–5.1 ms
Without, run 1 175.8 56.9 ms 15.0 10.7–11.1 ms
With #4012, run 2 199.2 50.2 ms 2.0 4.9–5.2 ms
Without, run 2 174.5 57.3 ms 15.1 10.2–10.9 ms
  • Frame time: about 7 ms (13%) lower with the change, in both pairs.
  • Waits: about 13 fewer per frame. The ones the change removes are on targets whose keys the zero dword fill kernel clears every frame. Most of the waited time was a 960x540 target: 350 waits per 10 s, about 13 ms each.
  • GPU: each wait drained the queue. With fewer of them, the GPU's idle time per present halves. The scene is GPU-bound (about 43 ms of GPU time per frame), so that idle time is what the frame rate gains.

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)

@johnmaia

Copy link
Copy Markdown
Contributor

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 fed11bde6 merged onto main e7c70a2df.

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:

without this PR with it
DISPATCH_DIRECT through the fill path 0 about 1,080
recorded-store syncs 326 (1.6 s) 181 (1.4 s)
pending-write syncs 190 (1.25 s) 444 (1.6 s)
FPS 4.5 4.8

The 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.

@AlxcBTW

AlxcBTW commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

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. MatchZeroDwordFill doesn'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's MatchDwordPatternFill has 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 ClassifyFill reports FillCover::Keys, and ClassifyFill reports that only for storage images' keys. In Sword of the Sea, ClassifyFill doesn't report this kernel's fills as Keys, so they never reach the memo and the next key read still waits in WaitForKeyWriters. 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)

@oneandonlydean

Copy link
Copy Markdown
Collaborator

MatchZeroDwordFill needs the output-format check that main's MatchDwordPatternFill has had since 4309bff (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.

@TideOPL

TideOPL commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

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 -> SyncThrough was the largest sync source on queue 0). With both PRs: queue-0 Recorder.Sync 11.7 -> 7.3 per frame (8.7 -> 6.1 ms), GpuMutex.wait.dispatch 6 -> 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).

queeeef and others added 2 commits October 13, 2026 12:27
A wave64 compute kernel that stores dword 0 at index group * 64 + thread through a 4-byte
stride buffer is run as a buffer fill. Palworld (PPSA23126) clears its DCC keys with it every
frame; as a shader dispatch its writes were unknown to the DCC key proofs, so every refresh of
those targets waited for the GPU.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The kernel stores through the V# FORMAT; with an 8- or 16-bit format it writes 1 or 2 bytes per element, which a zero fill of the whole range would also clear between. Same check as MatchDwordPatternFill (format 20-22), with test rows.
@adriadam10

Copy link
Copy Markdown
Collaborator

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 (99ebc65), rebased on current main:

  • MatchZeroDwordFill now refuses a V# FORMAT outside 20-22, same as MatchDwordPatternFill, so 8/16-bit formats are not zero-filled over the bytes between elements.
  • Test rows in MatchTests: formats 17 and 23 are refused, 21 and 22 match.

Checked: agc_driver_zero_dword_fill passes, and fails with the check removed; the rest of libSceAgcDriver's tests are green (agc_driver_tessellation crashes inside RADV pipeline linking with and without this change). Merging once the full Build is green.

@adriadam10
adriadam10 force-pushed the perf/agc-zero-dword-fill branch from fed11bd to 99ebc65 Compare October 13, 2026 10:36
@coltken95

Copy link
Copy Markdown

Tested on Linux x86-64 (Release build, lavapipe / llvmpipe LLVM 20.1.2), with 99ebc65 cherry-picked onto main 5d50886:

  • With the PR: agc_driver_zero_dword_fill passes.
  • With main's sources, the new test doesn't compile:
    'MatchZeroDwordFill' has not been declared in 'AgcDriver::DriverDetail'

@adriadam10

Copy link
Copy Markdown
Collaborator

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_fill passes, and fails to build without the change. Format check requested by @oneandonlydean is in. Merging once the full build is green.

@adriadam10
adriadam10 merged commit a252fcd into boykopovar:main Oct 13, 2026
8 checks passed
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.

7 participants