perf(agc): take the memory-value dword fill kernel as a buffer fill #4603
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4603"
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 AlxcBTW on 2026-10-12T16:39:30Z.
What
Refs #3505. Builds on #3816, whose
MatchMemoryValueFillrecognizes 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 withs_buffer_load_dwordthrough the V# inuser[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 inWaitForKeyWriters(#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.fillBuffernow takes it as a uniform buffer fill (MatchMemoryValueBufferFill) when all of these hold. Otherwise the recompiler runs it as before.32_UINT,32_SINTor32_FLOAT(20-22), sobuffer_store_format_xstores the dword unchanged.num_recordstimes the stride, ornum_recordsalone 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 itsnum_recordscounts elements and is below 4.s8is the group id. The dispatch is not partial.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 whenClassifyFilldoes not report the fill as a keys fill.ClassifyFillreports 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
6ffc99bedonmain18c438b10(#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 headb0c8e4478; the only change since is the rebase and the removed header comment.agc_driver_memory_value_fill:RELEASE_MEMlabel earlier in the same submission is the one the next fill stores.agc_driver_memory_value_fill,depth_fast_clearanddcc_keys_first_writeincluded. Windows passes 974 of 974, with the GPU tests skipped for lack of a device.agc_driver_memory_value_fill,dword_pattern_fill,depth_fast_clear,depth_fast_clear_submit,dcc_keys_first_write,fill_cover_keysandpattern_buffer_fillpass. On that machine the non-GPU tests pass 618 of 619.log_macrosfails there on every branch and passes in CI.tools/check_conventions.py --base origin/mainpasses.mainfrom 2026-10-11 with other local changes, including a buffer fill for #4012's inline-zero kernel. TheWaitForKeyWriterssyncs were counted with a local counter, per 10 s. While the value V#'s range was read asnum_recordsalone, this kernel never took the fill path, because the title's value V# has a stride, and about 600-640 syncs remained. Countingnum_recordstimes 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
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 johnmaia on 2026-10-12T20:21:38Z.
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:
num_records1, the same shape as Sword of the Sea's. A range check that readsnum_recordsas bytes refuses it, so countingnum_recordstimes 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:[fill-clear]reports 2,443 fills cleared on resident images after one minute in the level.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.
Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-12T20:49:57Z.
@johnmaia thanks for testing it on Epic Mickey with RenderDoc. A second title with the same V# shape (stride 16,
num_records1) is exactly the evidence this PR needed.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-12T23:52:38Z.
#3816 is merged with both of its commits, so this needs a rebase onto
mainthat keeps only b0c8e4478: the branch carries the first #3816 commit (69a67ca8a) without the guard commit, and it now conflicts inDepthSurface.cpp,tests/Graphics.cpp,tests/execution/DepthFastClear.cppand the debt file. That commit applies cleanly to the code by itself; the debt sentence goes intodocs/dev/debt/libSceAgcDriver.mdby hand.Two things while you are there:
MatchMemoryValueBufferFillnow repeat whatMatchMemoryValueFilldoes onmain; share them.NoteKeysFillOnGpuis called for any byte-uniform memory-value fill, also whenClassifyFilldoes 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
mainplus this would make it aperfchange, otherwisefixfits what johnmaia's run shows.Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-13T06:57:01Z.
@oneandonlydean merged current
maininto this branch. Since @alfalfa-star'sfd98327baalready 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.cppand its test. CI is green on Linux and Windows: https://github.com/AlxcBTW/AnyPS5/actions/runs/38357633188AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by TideOPL on 2026-10-13T10:14:57Z.
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 oneandonlydean on 2026-10-13T10:32:08Z.
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 thatMatchMemoryValueFilldoes on main; share them.memoryFill && byteFillpath intoNoteKeysFillOnGpuhas no test. Is it needed?Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-13T11:46:42Z.
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:
MatchMemoryValueBufferFillare removed. It now callsMatchMemoryValueFill, 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.memoryFill && byteFillpath intoNoteKeysFillOnGpuis 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, whichfillBuffercalls, 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
MatchZeroDwordFillkeeps 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.Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-13T18:24:35Z.
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.
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T18:36:56Z.
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)docs/dev/debt/libSceAgcDriver.mdL76-77docs/dev/debt/libSceAgcDriver.mdL77-78core/libs/prx/libSceAgcDriver/Execution/src/Driver/Memory/BufferFill.cppL276-287docs/dev/debt/libSceAgcDriver.mdL77-78core/libs/prx/libSceAgcDriver/Execution/include/Driver/Memory/DwordPatternFill.hppL4, L21core/libs/prx/libSceAgcDriver/Execution/src/Driver/Memory/BufferFill.cppL89, L276-287Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-13T22:38:03Z.
Please drop the comment at
DwordPatternFill.hpp:26-28; comments in code are only for technical debt. The Tested section still describes head b0c8e4478 with #3816's depth side, so please update it for this commit.Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-13T22:45:21Z.
@oneandonlydean done: the comment is gone (
6ffc99bed, amended), and Tested now names this head on18c438b10. A fork CI run for it is going; I'll put its result in Tested when it finishes.