perf(libSceAgcDriver): bypass the draw cache while its hit rate is under 5% #5404
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5404"
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 bcortezf on 2026-10-13T19:00:51Z.
What
The draw cache (
APS5_DRAW_CACHE_ENTRIES, 4096 entries) misses on almost every draw in scenes whose user-data words change every frame: in Red Dead Redemption gameplay it hits 0 to 6% of 120k to 130k lookups per 10 s and spends the time inserting and evicting entries (131k inserts and 300k to 730k evictions per 10 s).Count the lookups in windows of 2,048. When fewer than 5% of a window hit, draws skip the cache (no register key, no lookup, no insert, the same path as
APS5_NO_DRAW_SRT_ENTRIES) for the next 16,384 draws, then the cache is probed again. Scenes that hit (menus and cutscenes, 98 to 100%) are not bypassed.APS5_NO_DRAW_CACHE_BYPASS=1restores the previous behaviour, and[draw-cache] bypassed N drawsis printed withAPS5_PROFILE_DRAW.Related: #5345 (report), #5364 (miss breakdown; independent, may need a rebase in
Draw.cpp).Tested
Windows 11, RTX 4070 SUPER (driver 616.64), Ryzen 7 7800X3D, 3840x2160. PPSA30528, Armadillo after the intro,
APS5_TRACE_SECONDS=100:5, caches warm, same session. The base isAPS5_NO_DRAW_CACHE_BYPASS=1on the same binary.Two earlier rounds on the same machine: 2.63 / 2.61 FPS off, 2.80 / 2.83 FPS on. The queue worker stays at 98.8% busy; the gain is per-draw cost, not a different bottleneck.
trace_droppedis true in these captures (the worker buffer fills within 5 s).Summary lines (off, then on):
python3 tools/check_conventions.py --base origin/main: passed. Not built or run on Linux or macOS.Checklist
main; no other open PR implements the same functions.mdfiles or images added to the repositoryImported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T19:01:10Z.
Thank you for your contribution! Authors with no pull requests merged into
maincan have 1 open pull request at a time, authors with at least 1 merged can have 20, and from 20 merged there is no limit. This PR has been automatically closed and labeled "open PR limit" because that limit was reached. This is not a judgment of the quality of your changes: reopen it once one of your open pull requests is merged or closed.Imported from boykopovar/AnyPS5. Originally posted by bcortezf on 2026-10-17T23:23:59Z.
Need me to update this branch? @oneandonlydean
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-17T23:25:44Z.
Some 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/Draw/Draw.cppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawCache.cppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawCache.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawCacheStatistics.cppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawCache.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawCache.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawCacheStatistics.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawCache.cppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawCache.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawCacheStatistics.cppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawCache.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawCacheStatistics.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawCache.cppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawCache.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawCacheStatistics.cppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawCache.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawCacheStatistics.cppImported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-17T23:57:58Z.
Thanks for the measurements and the opt-out switch. Before this can merge it needs a rebase and a fresh measurement, because the draw cache it works around has changed a lot since this branch was cut (it is about 2,600 commits behind
main, and all four files conflict).Why the current numbers no longer carry over. Since your base,
mainhas added several changes aimed at exactly the low hit rate you measured in RDR:0adbdcf45c: a draw key is cached the second time it is seen;94ea410c9e: a key is admitted at first sight when its shape is known;58b6ddf729: draws that differ only in user data reuse their shape's decode and stages;56bb6377d2: pure data words of a cached stage are refreshed instead of recaptured;f9cacfadc9and #4943: cached draws are found across moved user-data pointers.What the rebase needs to account for.
useDrawEntriesalso gates stage caching. Onmainit gatesstageEntries(Draw.cpp,const bool stageEntries = useDrawEntries && …), and stage-level reuse now hits in cases where the whole-draw key misses. The bypass counts only whole-drawdrawHit, so a scene whose whole-draw keys miss but whose stages hit would be measured as under 5% and would lose the stage reuse that is working. Please either measure what the bypass switches off (whole-draw plus stage hits), or bypass only the whole-draw lookup and insert and keep stage entries on.Minor: the window counters (
fetch_add, thenexchangeandstore) can race between queue workers. For a heuristic that's acceptable, but a single CAS on a packed counter, or a note, would make it explicit.Measurements we need on the rebased head:
main: the[draw-cache]profile lines (lookups, hits, stage hits), showing the low hit rate still occurs.APS5_NO_DRAW_CACHE_BYPASS=1) and on, same binary and scene, several rounds as before.[draw-cache] bypassed N drawscount, ideally 0, and FPS unchanged.With those, this is a straightforward review.
Imported from boykopovar/AnyPS5. Originally posted by bcortezf on 2026-10-22T01:21:14Z.
@oneandonlydean Closing: main has since landed the draw-cache admission and reuse changes listed above, which target the same low hit rate, and on the earlier stack (#494, #1193, #1202) this bypass was already neutral (~-3%, within noise). Thanks for the review.
Pull request closed