Skip to content

perf(agc): take the memory-value dword fill kernel as a buffer fill - #4603

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
AlxcBTW:perf/agc-memory-value-fill
Oct 14, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
AlxcBTW:perf/agc-memory-value-fill

Conversation

@AlxcBTW

@AlxcBTW AlxcBTW commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

What

Refs #3505. Builds on #3816, whose MatchMemoryValueFill recognizes the kernel.

The 9-word kernel from #3816 stores one dword per thread through the stride-4 V# in user[0..3]. It loads that dword with s_buffer_load_dword through the V# in user[4..7]. Run as a compute dispatch, its stores are pending writes of unknown value, so a later read of DCC keys in that range waits for the GPU in WaitForKeyWriters (#3505). Sword of the Sea (PPSA25344) clears DCC keys with this kernel every frame. Beast of Reincarnation (#3816) and Kena (PPSA01802) run it over HTILE.

fillBuffer now takes it as a uniform buffer fill (MatchMemoryValueBufferFill) when all of these hold. Otherwise the recompiler runs it as before.

  • fix(agc): take an HTILE fill from a value in memory as a depth fast clear #3816's match holds: the 9 code words, 64x1x1 threads, one group in Y and Z, and a stride-4 output V#.
  • The output V#'s FORMAT is 32_UINT, 32_SINT or 32_FLOAT (20-22), so buffer_store_format_x stores the dword unchanged.
  • The value V# covers the loaded dword. num_records times the stride, or num_records alone with stride 0, is at least 4 bytes. That is the range the recompiler gives a scalar buffer load (EmitRuntimeScalarBufferLoad). Outside that range the load returns 0, which the recompiled kernel keeps storing. Sword of the Sea's value V# has a stride, so its num_records counts elements and is below 4.
  • There are exactly 8 user SGPRs and group id X is enabled, so the kernel's s8 is the group id. The dispatch is not partial.
  • The range is 16-byte aligned and a whole number of 16-byte units.

The value is read when the fill is recorded, after the labels queued before it, the way the pattern-fill kernel reads its source. From there the fill takes the existing path: fill clears on resident images, the HTILE note and the DCC key notes.

A fill whose value is one byte repeated also goes into the GPU key-store memo (NoteKeysFillOnGpu) when that byte is a key code, even when ClassifyFill does not report the fill as a keys fill. ClassifyFill reports keys only for storage images' keys, so a fill over other keys, such as a color target's that is not also a storage image, never reached the memo. The memo answers a key read only while this fill is still the newest pending write over those keys (PendingStoreKeys).

docs/dev/TechnicalDebt.md: #3816's HTILE entry now says that the fill path reads the value again when the fill is recorded.

Tested

Head 6ffc99bed on main 18c438b10 (#3816 is merged, so only this commit is in the diff). Fork CI for this head: run 38479822027: Linux and Windows green. The results below are from the earlier head b0c8e4478; the only change since is the rebase and the removed header comment.

  • New agc_driver_memory_value_fill:
    • Match checks (no GPU): the kernel is taken for output formats 20-22 and refused for 13, 39 and 56. A value V# of 4 bytes, or one 4-byte element with stride 4 (the Sword of the Sea shape), is taken. A value V# with 0 records, 3 bytes or one 2-byte element is refused. Also refused: an unaligned destination, a record count that leaves part of a 16-byte unit, a ninth user SGPR, a partial dispatch, no group id, and a changed code word. A 64-record output V# clamps the fill to 256 bytes.
    • Execution, wave32 and wave64: every dword matches what the kernel stores, both for dispatches the fill path takes and for those it leaves to the recompiler. The cases cover an aligned fill, one shorter or longer than the records, a size that is not a multiple of 16 bytes, an unaligned start, an empty fill, a value V# without records (stores 0) and the strided value V#. A value written by a RELEASE_MEM label earlier in the same submission is the one the next fill stores.
  • Fork CI, run 38276463398: Linux passes 968 of 968 (lavapipe; 43 skipped for features lavapipe lacks), agc_driver_memory_value_fill, depth_fast_clear and dcc_keys_first_write included. Windows passes 974 of 974, with the GPU tests skipped for lack of a device.
  • Windows 11, RTX 5070 Laptop (NVIDIA; the AMD iGPU is hidden from the Vulkan loader), with test binaries built on a second Windows 11 machine (MinGW GCC 15.2.0, Release): agc_driver_memory_value_fill, dword_pattern_fill, depth_fast_clear, depth_fast_clear_submit, dcc_keys_first_write, fill_cover_keys and pattern_buffer_fill pass. On that machine the non-GPU tests pass 618 of 619. log_macros fails there on every branch and passes in CI.
  • tools/check_conventions.py --base origin/main passes.
  • Sword of the Sea (PPSA25344) main menu, Windows 11, RTX 5070 Laptop. Measured on our local branch, which carries the same change on a main from 2026-10-11 with other local changes, including a buffer fill for perf(agc): handle the zero dword fill kernel as a buffer fill #4012's inline-zero kernel. The WaitForKeyWriters syncs were counted with a local counter, per 10 s. While the value V#'s range was read as num_records alone, this kernel never took the fill path, because the title's value V# has a stride, and about 600-640 syncs remained. Counting num_records times the stride, the kernel took the fill path (16,530 fills in 120 s) and the syncs dropped to about 90. These are single runs, not alternated. Frame time was not compared for this change alone.

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: fix(agc): take an HTILE fill from a value in memory as a depth fast clear #3816
  • Unblocks: none
  • AI-assisted: yes (Claude Code)

🤖 Generated with Claude Code

@johnmaia

Copy link
Copy Markdown
Contributor

Tested on Linux, RX 7600 (RADV NAVI33, Mesa 25.2.8), with Disney Epic Mickey: Rebrushed (PPSA15657). That game clears its depth HTILE with this kernel, and this PR fixes its level rendering.

Without a fill path for this kernel, the level renders black except for the HUD:

  • The kernel runs as an ordinary dispatch, so the HTILE bytes change, but the depth surface is never treated as cleared.
  • RenderDoc shows the depth prepass and base pass failing the depth test against stale depth from an earlier pass.
  • Mickey's value V# has stride 16 and num_records 1, the same shape as Sword of the Sea's. A range check that reads num_records as bytes refuses it, so counting num_records times the stride is what matters here too.

With this PR, at head b0c8e4478 (which includes #3816), merged into my Mickey test bed, the level renders:

The level now renders with a strong green cast. That one is unrelated to this PR (it comes from the sky light's cubemap), and I'm tracking it in #2255.

@AlxcBTW

AlxcBTW commented Oct 12, 2026

Copy link
Copy Markdown
Contributor Author

@johnmaia thanks for testing it on Epic Mickey with RenderDoc. A second title with the same V# shape (stride 16, num_records 1) is exactly the evidence this PR needed.

AI-assisted: yes (Claude Code)

@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 12, 2026
@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 12, 2026
@oneandonlydean

Copy link
Copy Markdown
Collaborator

#3816 is merged with both of its commits, so this needs a rebase onto main that keeps only b0c8e44: the branch carries the first #3816 commit (69a67ca) without the guard commit, and it now conflicts in DepthSurface.cpp, tests/Graphics.cpp, tests/execution/DepthFastClear.cpp and the debt file. That commit applies cleanly to the code by itself; the debt sentence goes into docs/dev/debt/libSceAgcDriver.md by hand.

Two things while you are there:

  • The format 20-22 and value-size checks in MatchMemoryValueBufferFill now repeat what MatchMemoryValueFill does on main; share them.
  • NoteKeysFillOnGpu is called for any byte-uniform memory-value fill, also when ClassifyFill does not report keys, and nothing tests that. Is it needed for this kernel only?

The match itself reads exact to me. The numbers are sync counts from a branch with other changes; a frame time on main plus this would make it a perf change, otherwise fix fits what johnmaia's run shows.

@oneandonlydean oneandonlydean self-assigned this Oct 12, 2026
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 13, 2026
@AlxcBTW

AlxcBTW commented Oct 13, 2026

Copy link
Copy Markdown
Contributor Author

@oneandonlydean merged current main into this branch. Since @alfalfa-star's fd98327 already takes the memory value fill on the depth side (in a stricter form), I kept main's version there, so this PR is now only the buffer-fill part: DwordPatternFill.hpp, BufferFill.cpp and its test. CI is green on Linux and Windows: https://github.com/AlxcBTW/AnyPS5/actions/runs/38357633188

AI-assisted: yes (Claude Code)

@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).

@oneandonlydean

Copy link
Copy Markdown
Collaborator

Merging main brought in three merge commits, and the branch now conflicts with main in docs/dev/debt/libSceAgcDriver.md; please rebase it as one commit instead. Two points from the last round are still open:

  • MatchMemoryValueBufferFill (BufferFill.cpp) still repeats the format 20-22 and value-size checks that MatchMemoryValueFill does on main; share them.
  • The memoryFill && byteFill path into NoteKeysFillOnGpu has no test. Is it needed?

@AlxcBTW

AlxcBTW commented Oct 13, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto current main as a single commit, without merge commits. #3816's commit is on main, so it is gone from the branch.

On Dean's two points:

  • The format 20-22 and value-size checks in MatchMemoryValueBufferFill are removed. It now calls MatchMemoryValueFill, which already has both checks, and only adds the 16-byte alignment and the packet/user-data conditions of the buffer fill. The existing format and value-descriptor tests still cover them through the new entry point.
  • The memoryFill && byteFill path into NoteKeysFillOnGpu is kept, because a memory-value fill over a color target's keys is not classified as a storage image's keys fill, and the memo is what spares the later key read from waiting for the GPU. The decision is now one function, KeysFillMemo, which fillBuffer calls, and a test covers all six key codes, a non-code byte and non-uniform patterns for each combination of the two flags. The recording itself is not exercised end to end.

Aligned with #4012, which is still open: that PR's MatchZeroDwordFill keeps its own checks and nothing in this change touches it, so whichever lands second rebases over adjacent hunks in BufferFill.cpp and DwordPatternFill.hpp. Checked with check_conventions and a full Linux and Windows run on a fork branch before the push.

@github-actions github-actions Bot added needs rebase Conflicts with main, rebase needed and removed needs rebase Conflicts with main, rebase needed labels Oct 13, 2026
@AlxcBTW
AlxcBTW force-pushed the perf/agc-memory-value-fill branch from af246e0 to f6c105b Compare October 13, 2026 18:24
@AlxcBTW

AlxcBTW commented Oct 13, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto current main. In the debt file I kept main's CMASK and host-import entries and this PR's HTILE edit. The fork CI is green on Windows and Linux. #5380 stacks on this PR and extends the dword-fill match to any inline constant.

@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 13, 2026
@github-actions

github-actions Bot commented Oct 13, 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
#4965 docs/dev/debt/libSceAgcDriver.md L76-77
#5249 docs/dev/debt/libSceAgcDriver.md L77-78
#5313 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Memory/BufferFill.cpp L276-287
#5372 docs/dev/debt/libSceAgcDriver.md L77-78
#5497 core/libs/prx/libSceAgcDriver/Execution/include/Driver/Memory/DwordPatternFill.hpp L4, L21
core/libs/prx/libSceAgcDriver/Execution/src/Driver/Memory/BufferFill.cpp L89, L276-287

@oneandonlydean

Copy link
Copy Markdown
Collaborator

Please drop the comment at DwordPatternFill.hpp:26-28; comments in code are only for technical debt. The Tested section still describes head b0c8e44 with #3816's depth side, so please update it for this commit.

The 9-word kernel #3816 matches stores one dword per thread, loaded with
s_buffer_load_dword through the descriptor in user[4..7]. Run as a
compute dispatch, its stores are pending writes of unknown value, so a
later read of DCC keys in that range waits for the GPU.

fillBuffer now takes it as a uniform buffer fill when all of these hold:
- the output descriptor's format is 32_UINT, 32_SINT or 32_FLOAT (20-22),
  so buffer_store_format_x stores the loaded dword unchanged;
- the value descriptor covers the loaded dword: num_records times the
  stride (num_records alone when the stride is 0) is at least 4 bytes,
  the range the recompiler gives a scalar buffer load;
- exactly 8 user SGPRs and group id X enabled, so the group id is s8;
- a direct, non-partial dispatch, 64x1x1 threads, one group in Y and Z,
  and a 16-byte aligned range of whole 16-byte units.

The value is read when the fill is recorded, after the labels queued
before it, as the pattern-fill kernel's source is. When the value is one
byte repeated and that byte is a DCC key code, the fill goes into the GPU
key-store memo whatever ClassifyFill reports: the memo answers a key
read only while this fill is still the newest pending write over the
keys, and a fill over a color target's keys is not a storage image's
keys fill.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@AlxcBTW
AlxcBTW force-pushed the perf/agc-memory-value-fill branch from f6c105b to 6ffc99b Compare October 13, 2026 22:44
@AlxcBTW

AlxcBTW commented Oct 13, 2026

Copy link
Copy Markdown
Contributor Author

@oneandonlydean done: the comment is gone (6ffc99bed, amended), and Tested now names this head on 18c438b10. A fork CI run for it is going; I'll put its result in Tested when it finishes.

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

Labels

agc libSceAgc* docs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants