perf(agc): repeat a draw shape's resident targets and pipeline instead of looking them up again #11696
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11696"
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 Astronaut10 on 2026-10-27T03:38:13Z.
What
The draw committer looks up every draw's resident color target images and its pipeline again, although consecutive draws of the same register shape almost always reuse both. This keeps a small per-thread memo (up to 4096 shapes, 4 pipeline choices each) in
prepareDraw, keyed on the shape key the driver already computes for data-only draw hits (key registers without user words, device serial and shader snapshots, the same invariant #494 relies on).decodeDrawreads only those inputs, so the shape determines the draw'sState.RepeatStorageSurfacerepeats the storage cache's hit path on the remembered image (array window, the multisample and resident-depth guard over the whole viewed surface, the depth-surface check, the depth-plane flush when stale, allocated levels, moved metadata,Refresh, LRU splice and hit counters) and finds it by image instead of rebuilding theSurfaceKey. Any refusal falls back toCachedStorageSurface.Identity()and push offset, plusPushConstantStages: everythingpipelineKeyreads that the shape does not determine. The newTouchCachedPipelinethen finds the stored pipeline by its hash under the store mutex, checks it is the same object through aweak_ptr, and splices it to the front of the LRU.AcquireFramebufferis unchanged.APS5_NO_SHAPE_MEMOturns the memo off;APS5_VERIFY_SHAPE_MEMOalso runs the ordinary lookups beside every hit, throws on a difference and prints[shape-memo]counts.Tested
CachyOS (Linux 7.3), Ryzen 7 5700X3D, RX 9070 XT (RADV, Mesa 26.2.5), 3840x2160. PPSA21564 (ASTRO BOT 01.007.000), started into
underwater_aerial_gardenwith-lvl, standing at the spawn with no input, 20 s after the level started, warm caches.Plain
mainruns this scene at 0.15 FPS (6-8 s per frame, refused host imports), so both sides carry #7844, which is unrelated to this change. Base1050ece9ca18:main09f9a63f6b+ #7844 (31342e632b). Changee1fcaed1ce50: this branch atdeec3d1824(the four commits now on the branch) + #7844. The two differ only in this PR's files. The branch headc7123a3da3is the same four commits rebased ontomainf5e3dc5e3bwithout conflicts. Switches on both:APS5_DEPTH_PLANE_COPY_MIB=512 APS5_DRAW_PIPELINE=1 APS5_PIPELINED_DRAWS=32 APS5_PIPELINE_DISPATCH=1 APS5_NO_PAD_INPUT=1.Clean runs, 120 s each, A/B/B/A then B/A/A/B, four per side, no run excluded; frame times from every frame of the steady window:
Graphics.Drawms per frameThe claim is the committer's draw preparation: 2.5 % less with the full-range guard. The FPS change is within its spread at four runs per side; on
mainthe committer also waits on labels. Earlier measurements of the same memo before the guard fix: onmain27ad7244d2+ #7844,Graphics.Draw-3.5 % and FPS +1.3 % (95 % -0.3 to +2.9 %); on a base that also had #9858, FPS +2.0 % (95 % +1.1 to +2.9 %). Those bases differ, so the gap is not attributed to the guard.APS5_VERIFY_SHAPE_MEMO=1one1fcaed1ce50from boot to the level and 60 s in it: 3,039,657 target and 1,107,060 pipeline hits checked against the ordinary lookups, no difference.Summary lines of the two traces of this pair (10 s each, captured as the Performance report form describes;
APS5_TRACE_EVENTSraised so the queue worker's buffer does not fill):Tests:
agc_pipeline_store_touch: a touch returns the stored pipeline as a hit, refuses another pipeline, an emptyweak_ptrand a cleared store, and keeps a touched pipeline from being the LRU victim; it fails when the LRU splice is removed.agc_repeat_storage_guard: remembers a surface's storage image, then checks the repeat path and the lookup agree with no guarded target (same image), with a 4x target that starts where the surface ends (same image), and with one that starts 64 KiB into the surface (the same refusal). It fails with a guard over the surface's first byte only.*_draw_pipelinetest, color and linear target tests, depth storage reuse, the two above) withANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validationandctest -Vonmainf5e3dc5e3b(74 of 74) and onc7123a3da3(76 of 76);agc_driver_linear_target_direct_write_completionskips on both. Neither log reports the layer missing. Both have the same 6VUID-VkPipelineColorBlendStateCreateInfo-pAttachments-00605fromagc_driver_srgb8_color_target; this change adds none.agcand guest memory tests pass apart from two that fail onmainas well:agc_driver_tessellation(crashes inside RADV inLinkPipelineFromLibraries) andagc_idle_publish_wait("the idle publish's bytes are wrong").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)🤖 Generated with Claude Code