fix(agc): let draw relocation aliases name a cached key, not hold its entry #9396
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9396"
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 EagleBearerYS on 2026-10-21T20:33:57Z.
What
Draw relocation learns an alias for a draw whose user-data words moved, so the next draw at the moved address can reuse the cached entry.
learnPendingRelocationstored each alias as ashared_ptrto the entry it had just inserted. When the draw cache later evicted that key, or replaced its entry, the alias kept the old entry alive, and with it every stage variant's runs and words.Only
MaxAliases(16,384, four times the cache's entry cap) bounds the alias map, and the cache's byte budget (#9129) doesn't count what the map holds. #9129 lists this under its limits.The change:
drawAliasesmaps an alias to the draw key it was learned for, not to the entry.relocateDrawEntrylooks that key up indrawCacheand uses the entry found there as the donor. When the key has left the cache, it drops the alias and the draw takes the ordinary miss path.lookupDrawrefreshed only an entry cached under the draw's own key. So without this, a donor that serves only relocated draws ages out like an unused entry, which now also ends its alias.A relocation now only reuses entries the cache still holds, so everything a donor keeps alive is inside the cache's entry and byte bounds.
Why, from Resident Evil Village (PPSA01556)'s main menu. The first runs show what holds the memory; the pair after them measures this PR.
APS5_NO_DRAW_RELOCATION=1) onmain1ff5c8ac5cplus #8926 and #9129, unprofiled, warm, 16 minutes at the static menu, GPU clocks weren't held:APS5_NO_DRAW_SRT_ENTRIES=1 APS5_NO_DRAW_KEY=1) gave 68 MB/min and 0.491 fps. Both runs' menu screenshots match the first's.The pair, relocation on: that tree (
main1ff5c8ac5cplus #8926 and #9129's byte bound) against the same tree with this PR's1d2fdfb261and2b862fbb7e. Resident Evil Village (PPSA01556), NVIDIA GeForce RTX 3070 (driver 617.42), Windows 11, the same launch settings for both; unprofiled, warm shader cache, 16 minutes at the static menu each, frames measured over menu +5 to +15 min; GPU clocks weren't held.Overlap: checked with
git merge-treeonc06bd7c7e1against every open PR touching these files. The ones that merge cleanly withmainmerge cleanly with this PR too, except #9335 (frankea), whose latest tests are declared at the same place inlibSceAgcDriver/CMakeLists.txt. That's a clash of test declarations only, and whichever lands second keeps both on rebase. Of the ones that conflict withmainthemselves, this PR adds conflicts only to #5609 and #6539, which is stacked on it, both in the alias map (Driver.hppandDrawRelocate.cpp). Two PRs work on the same path:donorpointer toDrawEntry, so a relocated entry keeps its donor's recipes. It doesn't touch the alias map, and the two compose.drawStageDonorsanddrawDecodes). This PR goes first, as proposed in the note on #5609, which conflicts withmainat the moment. #5609's donor maps would take the same two rules when it rebases: hold a draw key, not the entry, and move a donor up the LRU on a relocated hit. #6539 carries #5609's maps, so the same rebase covers it. If #5609 lands first, this PR moves both rules to its donor maps instead.Tested
New ctest
agc_driver_draw_cache_relocation_evicted. It'sDrawCacheRelocation.cpp --evictedwithAPS5_DRAW_CACHE_ENTRIES=2. It teaches an alias asMovedDataHitsTheCachedoes, checks that a moved draw hits through it, then evicts both taught entries with two other keys. It requires that one more moved draw of the first identity doesn't hit.main'sDriver.hppandDrawRelocate.cppand the test unchanged: "a draw whose data moved reused a draw the cache had evicted, through its relocation alias (1 hits)".New ctest
agc_driver_draw_cache_relocation_kept, for the donor refresh. It'sDrawCacheRelocation.cpp --keptwithAPS5_DRAW_CACHE_ENTRIES=2. It teaches an alias, then runs three rounds: two draws of another vertex shader that insert an entry, then a moved draw with the taught contents. Every moved draw has to hit. Without the refresh, the second round's insert evicts the donor and its moved draw misses. On GitHub's Linux runner (run) it fails 3 of 3 without 2b862fbb7e'sDraw.cppchange and passes 10 of 10 with it.GitHub's runners (run):
main's code the new case fails 3 of 3; with this PR it passes 10 of 10. The 6 draw-cache tests pass, and so does the libkernel suite. The libc suite'sprecise_waitfailed in this run with the fix, and on both sides in an earlier run. It's a timing test this change doesn't reach.Linux (Ubuntu 24.04, GCC 13.3, lavapipe, CI's flags):
^agc_driver_draw_cache6 of 6,--repeat until-fail:10on both relocation tests,check_test_registration.pyandcheck_conventions.pypass.jotitadev's run (review): Ubuntu 26.04, GCC 15.2, Release, this PR's
1d2fdfb26onmaina6dcea927. They ran the new case withANYPS5_NO_SHADER_CACHE=1 APS5_DRAW_CACHE_ENTRIES=2, which they describe as the path without graphics pipeline libraries, on an NVIDIA GeForce RTX 3070 (driver 595.99.02) and on lavapipe (Mesa 26.0.3) on the same host.main's driver and this PR's test, it fails on both with the same message as the red above.After the merge with
mainatb27924d851(c06bd7c7e1, no conflicts, the PR's own diff unchanged; run): the six draw-cache tests pass 10 runs in a row on Linux, none skipped; on Windows all six build and skip, as the runner has no Vulkan device. The libc and libkernel suites pass on both (116 and 197 on Linux, 143 and 207 on Windows).Validation layer,
mainagainst this PR (CONTRIBUTING's AGC rule), on one GitHub Linux runner (the same run). Both runs usedVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,ANYPS5_NO_SHADER_CACHE=1,ANYPS5_REQUIRE_VULKAN=1andctest -V, withVK_LOADER_DEBUG=layerto show the layer loading. The device was llvmpipe (LLVM 20.1.2) on Mesa 25.2.8, Ubuntu 24.04.5, Khronos validation layers 1.3.275.agc_driver_draw_cache_relocation,agc_driver_draw_cache_reuse_inline,agc_driver_draw_cache_reuse_offandagc_driver_draw_cache_reuse_verifyon both trees, and this PR'sagc_driver_draw_cache_relocation_evictedand_kept, whichmaindoesn't have.main's tree ran its four once and this PR's six ten times.VK_LAYER_KHRONOS_validation8 times onmainand 120 with this PR, and neither log haswas not found but was requested by env var VK_INSTANCE_LAYERS.VUID-VkDeviceCreateInfo-pNext-pNext, for a device-creation structure newer than that layer version. This PR adds noVUID-message.Windows on a GPU, at
2b862fbb7e, the head before the merge: NVIDIA GeForce RTX 3070 Laptop GPU (driver 617.42, the only device enumerated), Windows 11, WinLibs GCC 15.2.0, Release,ANYPS5_REQUIRE_VULKAN=1. GPU clocks weren't held; these are pass/fail only.main'sDriver.hpp,DrawRelocate.cppandDraw.cpp,_evictedfails 3 of 3 with the red message above.Draw.cppchange removed,_keptfails 3 of 3: "a draw whose data moved again lost the cached draw it reused before each of 2 rounds of another vertex shader's draws (2 inserts, 2 evictions)"._evictedstill passes, so each commit's test catches its own case.Ghost of Tsushima Director's Cut (PPSA02225), by @milescoviello (comment): Linux, RTX 4070 Ti, warm cache, a 20 GiB cap, journal replay off, on a stack with #8115, #8121, #8213, #8608, #9318 and #9129 (f2c368b242), plus a 256 MiB result memo budget and a 3D view bound. One gameplay run without this PR's three commits and one with them (cherry-picked cleanly).
Driver::tagVariantRuns(fromcacheDrawStages), while the draw cache's own count stayed at ~250 MiB of its 256 MiB budget: the aliases this PR changes kept evicted and replaced entries alive.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)Related: #9129
Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-21T22:17:31Z.
Review: COMMENTED
A Linux run on NVIDIA and lavapipe, with a red control, at the current head.
Machine: Ubuntu 26.04, i7-8700, GCC 15.2, Release,
BUILD_TESTING=ON. NVIDIA GeForce RTX 3070 (driver 595.99.02) and lavapipe (Mesa 26.0.3, LLVM 21.1.8) on the same host, selected withVK_ICD_FILENAMES. Head1d2fdfb26applied ontomaina6dcea927(clean). The newagc_driver_draw_cache_relocation_evictedcase, run as--evictedwithANYPS5_NO_SHADER_CACHE=1 APS5_DRAW_CACHE_ENTRIES=2(no-GPL path).agc_driver_draw_cache_relocation--evictedmaindriver + only this PR's testThe red control fails identically on both:
So on NVIDIA as well as on software Vulkan, a
maindrawAliasesentry keeps the evicted draw's entry alive and a later moved-data draw reuses it (1 stray hit); with this PR the alias names the draw key, finds the key gone fromdrawCache, drops the alias and the draw takes the ordinary miss path (0 stray hits). The teaching/first-relocation counters (lookups 4, hits 0, inserts 2, thenhits 1) match on both devices.Not run: the graphics-pipeline-libraries path of this case, Windows, the title heap measurements in the description.
GPUs tested: NVIDIA GeForce RTX 3070 (595.99.02, Linux) and lavapipe (Mesa 26.0.3, LLVM 21.1.8), Ubuntu 26.04
Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-21T22:20:36Z.
Thanks, @jotitadev. A red control on NVIDIA as well as lavapipe is what this case needed. I've added your run to Tested and to GPUs tested.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T05:45:28Z.
Review: DISMISSED
The change removes the alias map’s strong reference to evicted draw entries, and the red/green regression directly exercises that leak. The donor-retention test also covers the LRU behavior. The report has useful Linux/lavapipe and NVIDIA runs plus title memory/frame measurements, and
git diff --checkpasses. The current head merges cleanly withmain.I’m requesting changes for the remaining repository requirements:
1ff5c8ac5c(current main is4a17c71757, 496 commits ahead). Please rebase onto currentmainand rerun the focused draw-cache tests on main and the change withVK_LAYER_KHRONOS_validation,ANYPS5_NO_SHADER_CACHE=1, andANYPS5_REQUIRE_VULKAN=1; compare and report the VUIDs and tested GPUs as required for AGC changes. The recorded Linux/NVIDIA focused runs do not show that validation-layer comparison.Depends on:to match the agreement. #7369 appears complementary and does not show a same-line conflict in the current scan.Hosted product build jobs on this PR are skipped. No local AGC test or GPU run was possible in this review environment. Please refresh the overlap scan after rebasing and manually check its uncomparable intersections before merge.
Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-22T08:36:02Z.
Thanks, @MarcZX10. On the three points:
c06bd7c7e1mergesmainatb27924d851, which contains4a17c71757. It had no conflicts and leaves the PR's own diff unchanged. It still merges cleanly withmainat7e2ba73e4c, whose 34 newer commits touch none of these files.main's tree and this PR's ran on one GitHub Linux runner withVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,ANYPS5_NO_SHADER_CACHE=1andANYPS5_REQUIRE_VULKAN=1. The device was llvmpipe (LLVM 20.1.2, Mesa 25.2.8) with Khronos validation layers 1.3.275.mainran its four draw-cache relocation and reuse tests; this PR ran those and its two new ones, ten times. Both logs report the same single message,VUID-VkDeviceCreateInfo-pNext-pNext, for a device-creation structure newer than that layer version. This PR adds no VUID. Tested and GPUs tested now list it, with a red/green of both new cases on an NVIDIA GeForce RTX 3070 Laptop GPU on Windows.Depends on:says so. If #5609 lands first, this PR moves both rules to its donor maps.Overlap, after the merge: I checked the scan's uncomparable intersections with
git merge-tree, merging each of those PRs' heads withc06bd7c7e1and withmainalone. This PR adds conflicts only to #5609 and to #6539, which is stacked on it, both in the alias map (Driver.hppandDrawRelocate.cpp). For the others, each shared file has as many conflicts with this PR as withmainalone.