perf(agc): draw cache rebuilds shader stages when only per-draw buffer bases in user SGPRs move (Vampire Survivors late game) #9755
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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 krishalivaibhav on 2026-10-22T12:47:16Z.
Summary
In Vampire Survivors (PPSA21703), the late game makes about 10,500 draws per second. Most of them differ from a cached draw only in buffer descriptor base addresses held directly in user SGPRs: Unity's per-draw constants advance through a ring buffer. The draw cache misses these draws, and the data-only path cannot reuse their stages, so every draw rebuilds its shader stages. Each draw costs about 39 us of driver CPU, and the draw submission thread runs at 98% busy. FPS falls from 60 to 38-53 once the screen fills with enemies, while the GPU stays about half idle at 6-12 ms per frame.
Environment
macOS, Apple M2 (MacBook Air, fanless), MoltenVK 1.4.2, x86_64 build under Rosetta. The driver code paths cited below are the same on current
main.Measurements
These are from the last 10 s of a 10-minute play run, with
APS5_TRACE_DRAW_CACHE=1andAPS5_PROFILE_DRAW=1.[draw-cache]: 104,846 lookups and 21,872 hits (20.9%). 78,427 lookups found no entry: 69,602 were user words/pointers only and 8,238 were evictions (4096-entry table). Data-only hits: 78,409; 153,326 stages compiled and 3,492 reused.[draw-cache] register-key miss component changes: 78,427 in user data, 1,938 in stable registers.[draw-cache] stage data hits: 0. Stage inserts with data positions: 0.[draw-relocate]output.[draw] driver phases(microseconds per packet): decode 9.7, key/lookup/validate 7.3, capture 5.6, recompile 5.6, lock wait 5.5; total 39.3. Graphics::Draw recording adds about 31 us per draw.[rescache]: 100% hits, so resource validation is not the cost.A sampled diagnostic of the user words that change between a data-only hit and its entry is a local print, not proposed for merging. It shows the same 6 programs each time. Only the first dword of 4-dword buffer descriptors in the vertex stage's user SGPRs changes (words 0/4/8/12/16, for example
43e56ce8 -> 40ec7b00), along with pointer words in the second stage (0x0222xxxx,0x40ecxxxx).Why the cache cannot reuse these stages
DrawLookup.cppaccepts a candidate only when every changed user word is outsidevariant->userDataMask. The mask includesuserDataUse.asBasewords (DrawCapture.cpp, wherestageCapture.userDataMaskis set), so a moved base always rejects the candidate.validateVariantcompares them at the old addresses.recordStageDataPositionsrecords words only from aFlattenedSrtbinding's memory runs, so constants reached through user-SGPR descriptors never become data positions.DrawRelocate.cpphandles movedasBase & ~asValuewords. ButrelocatedContentKeyhashes the content behind the pointer, which changes on every draw here, so relocation never finds a donor.Possible direction
asBase & ~asValueuser words differ from a shape-matched entry, rebase the variant's runs by each base's delta. Validate the rebased runs at the new addresses. Reuse the stage if the remaining differences fall only on words the compiled shader reads as data, and refresh those words asstageDataHitsalready does.APS5_VERIFY_DRAW_DATA_HITSshould cover the new path, with a test where a V# base moves between draws and its contents change only in data words.The expected gain is up to about 20 us of decode, capture and recompile per draw. At about 200 draws per frame, that is roughly 4 ms per frame, enough to keep this title near 60 FPS in the late game on M2.
The cheaper partial fix is to raise
APS5_DRAW_CACHE_ENTRIES, which covers only the evicted 8%.AI-assisted: yes (Claude). The measurements are from local runs on the reporter's machine.