perf(agc): read DCC keys behind a pattern fill kernel's fast clear without a wait #5497
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5497"
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 gjonn on 2026-10-13T21:13:59Z.
What
PPSA01317 fast-clears its render-target DCC keys every frame with a 64-thread compute kernel (23 code words) that stores
pattern[i % 4], the pattern in the user SGPRs s4..s7, to dwordiof the stride-4 V# in s0..s3 for everyi < min(groups * 64, s8, num_records), with the group id in s9:On current
mainit runs as a plain dispatch, so its store is a pending write of unknown value. The next key read of those targets (currentDccKeys/WaitForKeyWritersinGraphics/src/DccMetadata.cpp) findsPendingWriteOverlapstrue andPendingStoreKeysempty, and callsRecorder::SyncThrough, waiting for the GPU while holding the GPU mutex (#3505).This PR leaves the dispatch as it is.
MatchSgprPatternFillrecognises the kernel (exact code, 9 user SGPRs with the group id enabled, 64x1x1 threads, one group row, no partial or indirect dispatch, a 32-bit format, stride 4, not swizzled, no add-tid, index-bounded OOB mode). When the pattern is one repeated DCC key code (KeysFillMemofrom #4603, taken as for its memory-value fill kernel),Driver::dispatchcallsGraphics::NoteKeysFillOnGpuunder the GPU mutex right after the dispatch is recorded. It does this only if the dispatch's own write note is the newest note and covers exactly the filled range.PendingStoreKeysanswers from that note only while it is still the newest over the range, so any later writer makes the read wait as before. The kernel needs no 16-byte multiple or alignment and is not taken as a buffer fill.Related:
s_buffer_load.This PR covers the 23-word kernel that takes its pattern from user SGPRs.
Tested
Windows 11 Pro, MinGW GCC, Release, NVIDIA GeForce RTX 5090 Laptop GPU (driver 616.92).
New test
agc_driver_sgpr_pattern_fill_keys(tests/execution/SgprPatternFillKeys.cpp):Submit:The test fails on
main(a pending key code fill by the kernel: the keys read 0000 and the read waited for the GPU) and passes with this change, 15 of 15 repeated runs.These also pass:
dword_pattern_fill,zero_dword_fill,pattern_buffer_filldcc_keys_first_write,fill_cover_keyscmask_fast_clear,depth_fast_clear,depth_fast_clear_submitdepth_storage_dispatch,gated_dispatch_capture,oversized_dispatchstore_over_untracked,store_idle_results,compute_user_data_calls,resource_cache_storage_clearRunning
agc_driver_recorder_testswithout arguments fails with(9) a scan under a pending write was kepton unmodifiedmainas well.tools/check_conventions.pypasses.PPSA01317: the same note in a local tree raised race heavy-phase FPS from 1.395 to 1.833 (+31%, 3 of 3 A/B blocks) and halved the GPU waits made under the GPU mutex. The image was unchanged. That measurement was taken on a local branch, not on this exact
maincommit.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-13T23:06:06Z.
Two things before this can go in:
IsByteFillandKeysFillMemoover the same key switch inBufferFill.cpp. Please rebase on it once it's in and use those instead ofFilledKeys(BufferFill.cpp:101).mainand of this change from the same scene, with the traces, as the Performance report form describes.Imported from boykopovar/AnyPS5. Originally posted by gjonn on 2026-10-14T13:14:10Z.
Rebased onto
main63fb0cd92, which has #4603 (force-push, one commit, e095ee4c1).FilledKeysis gone.Driver::dispatchtakes the key code fromKeysFillMemo(pattern, false, true), the same way #4603's memory-value fill kernel does: a recognised fill kernel's keys are noted whether or not the range is a storage image's keys. That is what this PR did before.FilledKeysunit cases are dropped, because #4603'sMemoryValueFill.cppalready covers the key codes. The end-to-end cases throughSubmitstay unchanged.agc_driver_sgpr_pattern_fill_keyspasses 3 of 3 runs.memory_value_fill,dword_pattern_fill,dcc_keys_first_writeandfill_cover_keysalso pass, andtools/check_conventions.pypasses.The PPSA01317 before/after from the same scene is still to come. On stock
mainthe title does not reach the race, so the comparison will be one local tree with and without this commit, run in alternating blocks with traces. I'll post the summary lines here and say exactly what the tree contains.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T12:07:51Z.
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)core/libs/prx/libSceAgcDriver/Execution/src/Driver/Dispatch/Dispatch.cppL12core/libs/prx/libSceAgcDriver/Execution/src/Driver/Dispatch/Dispatch.cppL12Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
core/libs/prx/libSceAgcDriver/Execution/src/Driver/Dispatch/Dispatch.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Memory/BufferFill.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Memory/BufferFill.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Memory/BufferFill.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Dispatch/Dispatch.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Memory/BufferFill.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Dispatch/Dispatch.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Dispatch/Dispatch.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Dispatch/Dispatch.cppImported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-16T23:44:48Z.
Still open from 10-13: the PPSA01317 summary lines of
mainand of this change from the same scene, with the traces, in alternating blocks as you described. The branch also conflicts with main again, so please rebase. If you can't run the title now, say so and I'll leave it waiting.Imported from boykopovar/AnyPS5. Originally posted by gjonn on 2026-10-17T18:41:37Z.
Rebased onto
mainf219248f0(force-push, still one commit,448ccee76). The only conflict was an include list inDispatch.cpp; the change itself is unchanged. The PR test and the other fill and key tests pass, andtools/check_conventions.pypasses.On the measurement: I can't give you
mainagainst this change from the same scene right now. Onmainthe title still stops before the title screen, so it never gets to the race where this kernel runs every frame. The blockers are tracked in discussion #4697 and in #7137, #7207, #5958 and #7175, with more to come.The only numbers I have are from our local tree, which isn't
main, so I won't count them as the comparison you asked for. Oncemainreaches the race, I'll post the summary lines ofmainand of this change from the same scene, run in alternating blocks, with the traces.Do you want to leave this waiting until then?
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-17T21:40:32Z.
@gjonn thanks for the rebase, and for being straight about the numbers.
Yes, let's leave this waiting. On main, PPSA01317 still stops before the title screen, so it never reaches the race where this fill kernel runs every frame, and a main-vs-PR comparison from the same scene isn't possible yet. We're parking this PR until main can get there (the blockers in #4697, #7137, #7207, #5958 and #7175).
Once main reaches the race, please post the summary lines of main and of this change from the same scene, in alternating blocks with the traces, as you described, and we'll pick it back up from there. A rebase at that point is fine; no need to keep it current in the meantime.
Imported from boykopovar/AnyPS5. Originally posted by Amoenus on 2026-10-19T21:34:36Z.
Independent fixture check on literal main
bf2c63f853, Windows11 Enterprise26200, GCC15.2 Release. Runtime libraries/relinker andagc_driver_sgpr_pattern_fill_keys_testswere rebuilt together.agc_driver_sgpr_pattern_fill_keysintermittently stops at:Three fresh processes per GPU with the normal implicit host layers plus explicit Khronos validation: RTX5080 2 pass /1 fail, AMD Radeon(TM) Graphics 2 pass /1 fail. Repeating three fresh processes per GPU with
VK_LOADER_LAYERS_DISABLE=~implicit~gives 3/3 pass on each. This small sample does not establish implicit-layer causality or a fix. Each fixture's two device selections and loaded Khronos layer were verified; zero VUID/errors/warnings or CTest timeouts in all12 processes. Shader cache and pipeline journal were disabled throughout; driver caches were not isolated.Reproduce serially with
ANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1,APS5_NO_PIPELINE_JOURNAL=1,VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, the installed SDK layer path, and each requestedANYPS5_GPU:Invoke it in three separate processes per device. RTX5080
10de:2c02, driver610.62 /32.0.16.1062; AMD1002:13c0, driver32.0.21036.18. This is a current-main fixture observation, not a claim that this PR introduced it, a title regression or a performance comparison. The failing observation needs investigation before treating the fixture as a reliable integration gate. AI-assisted: yes (Codex).Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-20T02:21:59Z.
Hi @gjonn,
agc_driver_sgpr_pattern_fill_keysfrom #5497 has failed 4 times on Linux CI in the last day on unrelated PRs, each time at ~10.4 s with "the submitted dispatch never became a pending write over the keys" (CI 39341103236, 39351840152, 39352635933, 39353294932; reruns pass). It looks like a race in the test:ReadAfterWrite()waits forRecorder::NewestWriteNoteover the keys, but that only scans the open and in-flight batches. If the dispatch's batch is submitted, completes and is reaped before the polling thread gets a turn (llvmpipe finishes the tiny fill almost immediately and ctest runs 4 tests in parallel), the note is gone and the loop waits out its 10 s deadline. Could you make the test hold the batch in flight until it has read the keys, or resubmit when the batch retired unseen? Naming the failing case in that message would also help.Imported from boykopovar/AnyPS5. Originally posted by simonbbby on 2026-10-20T04:32:37Z.
Native Linux reproduction of the retired-before-observation case in Dean's request, on pinned main
11ee778434dacf31f2ce0ecff8229e0839e36b34.The unmodified registered test passed 10/10 serial lavapipe runs. Adding only a 100 ms delay at entry to
ReadAfterWritereproduced the original timeout 3/3. Immediately after that delay, the probe printed:The batch was already retired; there was no pending write note left for the loop to find. This is a controlled scheduling reproduction, not a measured natural CI failure rate.
I tested the resubmission option below. When no new note is observed for 10 ms, it first drains the previously submitted work, then resubmits the same case's idempotent fill. Draining before resubmission prevents queued duplicates from leaking into the next case. The existing 10-second deadline, key classification, pending/waited expectations and stored-dword assertions remain; timeout messages now identify the case.
uniform key 0in the same timeout.git diff --checkpass.Ubuntu 24.04, kernel 7.0.0-38, Ryzen 9950X, GCC 13.3, Release; NVIDIA 595.99.02, Mesa 25.2.8. ICD restricted separately and actual devices verified; required Vulkan, shader cache and pipeline journal disabled. No Khronos validation layer is installed. Windows/macOS, loaded validation and parallel-CI failure rates are not verified. No production files are changed. Raw logs are retained.
Test-only candidate against that main pin