perf(agc): read a sampled texture's DCC keys once per lookup #8117
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/8117"
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 johandavidcm on 2026-10-19T22:29:45Z.
What
cachedTextureread the DCC keys of one range up to three times in a lookup with nothing written between the reads:ClearSinglecheck over a pending image scanned and dropped the result when no keys were held yet;observedKeys) scanned on every lookup, though only a lookup with a pending source uses it, and kept nothing;On Windows the key ranges sit in compared host imports, so
CollectWritesis 0 and no proof stands in for these scans (#6209 works on that forProvedClearKeys, which this path does not use). In PPSA31327's gameplay the scans took 12 % of the draw committer's samples, and the committer bounds the frame (#8068).The lookup now keeps the keys it read until it does something that can change them: the storage source it looks up (which may refresh), the pending source's
Refresh, orFlushPending, which can publish unit shadows over the surface even when it flushes no image. The staged-clear test reads the keys only with a pending source. Which keys a lookup acts on is unchanged; only the repeated reads go.ClearSinglekeys, storage-eligibleReads around a
Refreshor a flush are unchanged.Tested
Windows 11 Pro 26200, WinLibs GCC 15.2.0 (ucrt, posix, seh, r7), Release, NVIDIA GeForce RTX 4070 (driver 617.42), Ryzen 7 7800X3D.
Tests on this head, rebased onto
main0c6a5bd59. The rebase metmain'srefreshForViewincachedTexture, which replacedsource->Refresh(); it is kept, and the key memo is reset after it, as afterRefreshbefore.With
ANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1andVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation(Vulkan SDK 1.4.363.0; the loader log shows the layer inserted),ctest -R <the seven below> -Vpasses onmain0c6a5bd59and with this change, and neither log has aVUID-line or a missing-layer message.agc_driver_dcc_key_presyncpasses--repeat until-fail:20.DccKeyPresyncgainsRunOneKeyReadPerLookup: a dispatch's first and repeated lookup of a texture with no key writer read its keys at most once under the GPU mutex (KeyWaitCounts().calls). With this change 1 and 1; onmainthe test fails, reading them twice.Pass with the change:
agc_driver_dcc_keys_first_write,agc_driver_staged_clear_sampled_read,agc_driver_dcc_key_presync,agc_driver_graphics,agc_pending_key_stores,agc_shadowed_key_stores,agc_copied_direct_ordering. The fullagc_driver_recorder_testsrun (not a ctest entry) stops at(9) a scan under a pending write was keptwith and without this change.tools/check_conventions.py --base origin/mainpasses.PPSA31327 (Yakuza 0 Director's Cut 01.015.000), gameplay after loading the title's autosave, character still, 1920x1080, warm caches.
1c230943a=mainbf2c63f85with #6572 and #7719, which the title needs to reach gameplay and play sound; the change is this pull request's commit cherry-picked onto that base (5e81d5a85).APS5_PAD_INPUT_FILE(left and cross at the load prompt) withAPS5_NO_PAD_INPUT=1, recordedAPS5_TRACE_SECONDS=150:60with no other trace or profile switch and the log not redirected, and closed the title once the trace was written.Graphics.Drawon the draw committer drops from 273-307 to 244-268 ms per frame; the GPU stays busy 94-110 ms per present in both.Pairs 1-4 used the same code built from the uncommitted change (their summary lines say
dirty); pairs 5 and 6 used the commit. WithAPS5_PROFILE_DRAWin separate runs (16 gameplay intervals of 10 s each), the[dcc]line counts per present 7,319 scans, 1,302 MiB and 37.1 ms of scanning on the base, and 2,635 scans, 442 MiB and 12.9 ms with the change.Summary lines of pairs 5 and 6 (base, change, base, change):
The twelve traces are attached.
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 Rajkamalcode on 2026-10-20T06:36:08Z.
SWAG (PPSA22102) mechanism check - measured data
Clean pair on the heavy spawn scene, same save and pad schedule, 360 s per run, stock ini,
APS5_PROFILE_DRAW=1; baseline prx5AB0413B, PR prx3189DE77(RTX 3070 / Ryzen 5 5600X, 2026-10-20). DCC rows are medians over the last 30 x 10 s windows; resource rows are cumulative over the run.[resources] images[resources] stage BNo frame-rate claim. Scene trajectories diverged: run29 recorded 248,781 draws (+20.2%) and 680 presents (+67%) vs run28's 207,013 and 407;
guest memory uploadalso doubled. The single pair is not a frame-time comparison.readTargetmoved -3.0% cumulatively despite the extra draws, but it remains noisy and is not a claim here.Measured takeaway: the memoization is active on SWAG - the direct DCC counters fall about 20%, and the cumulative
imagesphase falls about 16% per build. That is consistent with the PR's mechanism, but a reverse-order pair or a fixed-scene capture is needed before calling it a performance win.AI-assisted interpretation (separate from the measured table): the
imagesreduction is larger than the draw-count difference and is measured per build, so it looks like a real CPU-side saving rather than only scene drift. I would not merge or claim FPS on this pair alone.Imported from boykopovar/AnyPS5. Originally posted by TheSovietWaffle on 2026-10-20T07:38:01Z.
Tested on RTX 3080 (NVIDIA 617.42) and AMD Radeon RDNA 2 iGPU (
1002:164e, 32.0.21045.5002), Windows 10 Pro 22H2, WinLibs GCC 15.2.0, Release, head8cd75d779:agc_driver_dcc_key_presyncis flaky here. It fails 4 of 10 runs on the RTX 3080 and 2 of 10 on the Radeon, each time on the second new case:The first case ("a dispatch's first lookup") never failed.
KeyWaitCounts()looks process-wide, so the delta may include key reads that another thread (or work still settling from the earlier cases inmain()) makes while the dispatch runs; I have not confirmed that. The other runs pass on both GPUs.AI-assisted: yes (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-20T20:34:31Z.
Review: CHANGES_REQUESTED
Thanks, the memoization itself reads correctly (the reset after the storage source, after
Refreshand afterFlushPendingcovers the paths that can change the keys). One blocker:core/libs/prx/libSceAgcDriver/tests/execution/DccKeyPresync.cpp:247:RunOneKeyReadPerLookupcomparesKeyWaitCounts().callsbefore and after the dispatch, but that counter is process-wide (DccMetadata.cpp,KeyWaitTotals), so key reads from any other thread (or work still settling from earlier cases) land in the delta. @TheSovietWaffle measured it failing 4/10 runs on an RTX 3080 and 2/10 on a Radeon iGPU, always on the second case ("repeated lookup read the keys ... 4 times"). A flaky ctest entry is not acceptable. Please make the count specific to the lookup under test (for example a per-thread counter, or counting only reads made by the calling thread) or quiesce the other readers before taking the baseline, and show it passes repeatedly (ctest --repeat until-fail:20).Once that is fixed this looks good to merge.
Imported from boykopovar/AnyPS5. Originally posted by johandavidcm on 2026-10-21T05:47:05Z.
@adriadam10 @TheSovietWaffle Reproduced here: 7 of 30 runs failed, always the repeated lookup with 4 reads (RTX 4070, 617.42). The extra reads were not another thread's: a temporary per-thread counter saw the same 4 reads on the test thread. Only one of them comes from
cachedTexture. The other three come from the storage image that the repeated lookup sometimes refreshes, depending on when the GPU finished:StorageTexture::upload→ProvedClearKeys, andStorageTexture::ProvedKeys→WaitForKeyWritersandProvedClearKeys. This PR does not touch them, butKeyWaitCounts().callscounts them too, so a per-thread version of it would still fail.f39d75d62 counts what the test is about.
cachedTexturecounts the key scans it makes on the calling thread (SampledLookupKeyScans(), next toImageTableReuses()), and the test compares that count around the dispatch.ctest -R ^agc_driver_dcc_key_presync$ --repeat until-fail:20passes, and so doesuntil-fail:100, withANYPS5_REQUIRE_VULKAN=1andANYPS5_NO_SHADER_CACHE=1.main'scachedTextureplus the same counter, the test still fails: the first lookup scans twice.agc_driver_dcc_key_presync,agc_driver_dcc_keys_first_write,agc_driver_staged_clear_sampled_read,agc_driver_graphics,agc_pending_key_stores,agc_shadowed_key_storesandagc_copied_direct_orderingpass through ctest.With
VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validationas well (Vulkan SDK 1.4.363.0; the loader log confirms the layer loads),ctest -R <the seven above> -Vpasses onmain0d8c51a54and with this PR, and neither log has aVUID-line or a missing-layer message.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by akkadbakkad89 on 2026-10-21T19:50:50Z.
agc_driver_dcc_key_presyncflake — RTX 3070 datapointWindows 11 Pro 26200, WinLibs GCC 15.2.0 (ucrt, posix, seh, r7), Release, NVIDIA GeForce RTX 3070 (driver 617.42),
main1698d1ea6a+ this PR's diff applied (git diff 0d8c51a54..HEAD). 30 consecutive runs ofagc_driver_dcc_key_presync_testsper arm,ANYPS5_NO_SHADER_CACHE=1,APS5_NO_PIPELINE_JOURNAL=1.8cd75d779(before the own-scan counter)a dispatch's repeated lookup read the keys of its sampled texture 4 times under the GPU mutex with nothing written between the reads, expected at most once— always the 4-read casef39d75d62f(current head)Same signature as the RTX 3080 / RTX 4070 reports (always the second case, always exactly 4 reads), and the own-scan counter fixes it here too. So on this driver generation the storage-refresh interleave happens on NVIDIA Ampere as well; 10 % observed rate is in line with the other reports.
AI-assisted: yes (Devin).
Imported from boykopovar/AnyPS5. Originally posted by johandavidcm on 2026-10-21T20:48:06Z.
Rebased onto
main0c6a5bd59. The one conflict was incachedTexture:mainnow callsrefreshForView(*source, resource)where this PR hadsource->Refresh(). I keptmain's call and the key memo's reset after it;refreshForViewstill refreshes the image (Refresh, orRefreshLayersfor an array view), which can store over the keys.On the rebased head (RTX 4070, 617.42): the seven focused tests pass,
agc_driver_dcc_key_presyncpasses--repeat until-fail:20, and with the validation layer neithermain0c6a5bd59nor this PR logs aVUID-line. The Tested section is updated.@akkadbakkad89 thanks for the RTX 3070 runs.
AI-assisted: yes