perf(shader): reuse an evicted memo result's bindings for the next miss #9049
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9049"
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 EdouardSence on 2026-10-21T10:52:12Z.
What
In ASTRO BOT's Sky Garden, the queue worker thread is at ~99 % and bounds the frame. The
Recompile(request, capture)result memo hits only ~6.5 % of the time there: about 35k misses per second, nearly every one evicting an entry. Every miss builds a newRecompileResult. Itsbindingsare copied from the binding plan with all of eachDescriptorBinding's vectors, and the evicted result is destroyed with all of its vectors on the same thread. In aneu-stacksample of the worker (120 samples), ~18 % of samples were in~RecompileResultundermaterializePreparedMemoized, and malloc/free showed up underMaterializeandPopulatetoo. WithLD_PRELOADof jemalloc the same build ran ~8 % faster, so allocation is a real share of the frame there.materializePreparedMemoizednow picks the set's least recently used entry before materializing. When the memo holds the only reference to it (use_count() == 1under the source mutex, which every other lookup also takes), the entry is taken out of the set and itsbindingsvector is passed tomaterializeResult.DescriptorBindingBuilder::Populatecopy-assigns each plan binding into the allocation's existing elements, then resizes to the plan's size, instead of building a new vector. The vectors in a reused element keep their storage. An empty allocation gives the same result as before.APS5_PROFILE_DRAW's[recompile] result memoline also counts these entries.Tested
-DBUILD_TESTING=ON: ctest 1786/1792 withVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ANYPS5_NO_SHADER_CACHE=1 ANYPS5_REQUIRE_VULKAN=1on the RX 9070 XT. The 6 failures (agc_driver_guest_memory_lifetime,agc_driver_image_array_window_past_layer_limit,agc_driver_tessellation(segfault),net_dontwait_blocking_send,_sendto,_sendmsg) fail the same way onmain2abfb1bebin this environment.ctest -Vand the same variables, onmainand on this branch:agc_shader_disk_cache,agc_shader_memory,agc_driver_graphics,agc_driver_testsand theagc_driver_draw*tests (17 tests) pass on both. Neither log has aVUID-line orwas not found but was requested by env var VK_INSTANCE_LAYERS.verifyBindingPlanSelection(agc_shader_disk_cache) now also populates the selected plan into an allocation that still holds the full plan's four bindings, and checks that the result equals a fresh populate.-lvl underwater_aerial_garden), headless gamescope 3840×2160, no input,APS5_TRACE_SECONDS=90:50,APS5_NO_SNAPSHOT_CHECK=1. Both builds also ran withAPS5_HOST_IMPORT_MIB=11815, becausemainwithout #7844 thrashes textures in this level on a 16 GB card. Each build had a warm-up run, then the runs were interleaved.Driver.Draw.shader_compile_and_linkms/framemain2abfb1beb, warm-up7fcf71555, warm-upmain, run 1main, run 2This PR is about 8 % faster at p50 here, and p99 drops from 380-402 ms to ~261 ms. GPU time is unchanged. In the traces,
Shader.DrawStagegoes from 123.4 to 96.8 ms per frame. The worker stays at ~99 %, so the draw cost still bounds the frame.Summary lines (run 1 of each). Traces of both run 1s: main, this PR. Both traces dropped events after a few seconds on the worker (
trace_dropped); the frame times come from the presents.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)Tested and written by Claude (AI assistant) on a contributor's machine.
AI-assisted: yes
🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by EdouardSence on 2026-10-21T12:52:23Z.
Checked the files the overlap comment could not compare, against the diffs of those 25 pull requests. No other pull request changes the result memo (
materializePreparedMemoized,ResultMemoEntry) orPopulate's binding loop.Four touch the line this PR changes in
Recompiler.cpp, thematerializeResultsignature:snapshotparameter tocaptured.UsedBindingPlan* usedPlan = nullptrparameter.Each is a one-line textual conflict. Whichever lands second keeps both changes; the parameters are independent. No
Depends onneeded.Tested and written by Claude (AI assistant) on a contributor's machine.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by ycbuzi on 2026-10-21T17:51:18Z.
Windows run of
7fcf715559merged ontomain745b394629(efc0236650, clean), the platform the description lists as not tested. Windows 11 Home 10.0.26200, MinGW-w64 GCC 15.2.0 (ucrt-posix-seh r7), Release,BUILD_TESTING=ON. RTX 4070 SUPER, NVIDIA 616.92 (ANYPS5_GPU=4070).Built
agc_shader_disk_cache_testswith no errors or warnings.ctest --repeat until-fail:2on the 15 tests these executables register on Windows: all pass on both repeats. These are theagc_shader_disk_cache,agc_shader_cache_housekeeping_*andagc_shader_prebuilt_discovery_*tests. Not run: a title.Imported from boykopovar/AnyPS5. Originally posted by teepean on 2026-10-21T19:31:03Z.
@EdouardSence a Linux/NVIDIA data point on Stray (PPSA02100). It was measured on my stack, not on plain
main, with a replacement allocator, so take it as one data point.Setup
main1ff5c8ac5c(showcase/stray-stack, 27dbc2891f).7fcf715559cherry-picks onto it cleanly.engine.ini, scripted input.FPS (mean of four runs)
[recompile] result memowithAPS5_PROFILE_DRAW=1(one run each, tcmalloc, about 100k misses per 10 s in both): Populate takes 1.9 us per miss without the PR and 2.4 us with it.Tests and output
agc_shader_disk_cache_testspasses, including the new check.Your -8 % came from
mainwith glibc, wheremallocandfreecost more, so the result may well differ there. If it helps, I can measuremain+ #9049 with glibc on Stray.AI-assisted: yes (text with Claude Code; the numbers are from my machine).
Imported from boykopovar/AnyPS5. Originally posted by EdouardSence on 2026-10-22T07:53:54Z.
@teepean thanks for the Stray runs and the reading. Your guess about the move-assigned vectors was right, so I pushed
edc95643a:GuestBuffersDescriptorandGuestSamplersDescriptornow fill the binding's existingguestDescriptorinstead of returning a new vector, so a recycled binding keeps that storage too.ShaderDatastill moves its vector in.Sky Garden A/B, ASTRO BOT PPSA21567 01.019.000, Ryzen 7 7800X3D, RX 9070 XT (RADV Mesa 26.2.4), CachyOS. Headless gamescope 3840x2160, no input,
APS5_TRACE_SECONDS=90:50,APS5_HOST_IMPORT_MIB=11815, warm shader cache, all on base2abfb1beb. Two rounds, arms interleaved. Frame p50 in ms:main7fcf71555edc95643aOn this machine and scene, the previous head was not slower with jemalloc (its round 1 is the noisy one). The new head is about 8 % faster than
mainwith glibc and about 6 % faster with jemalloc. Your Stray scene on NVIDIA may still behave differently, for example because the LRU victim is cold in the cache, as you said. If you have time, a run of the new head on your stack would show whether this change recovers the 3 %.tools/check_conventions.pypasses, and so do the 7agc_shader_disk_cache*/housekeeping/prebuilt tests. #9177 (milescoviello) adds areserveinGuestSamplersDescriptor, which this commit also touches, so whichever PR lands second needs a small rebase.Tested and written by Claude (AI assistant) on a contributor's machine.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by ycbuzi on 2026-10-22T08:34:31Z.
Windows run of
edc95643a1, the update since my earlier run, merged ontomaind6eafa54d0(0edab22f56, clean). Windows 11 Home 10.0.26200, MinGW-w64 GCC 15.2.0 (ucrt-posix-seh r7), Release,BUILD_TESTING=ON. GPU: NVIDIA GeForce RTX 4070 SUPER, driver 616.92 (ANYPS5_GPU=4070,ANYPS5_REQUIRE_VULKAN=1).Built
libSceAgcDriverandagc_shader_disk_cache_testswith no errors or warnings.ctest --repeat until-fail:2on the 15 tests that executable registers on Windows (agc_shader_disk_cache,agc_shader_cache_housekeeping_*andagc_shader_prebuilt_discovery_*): all pass on both repeats, none skipped. Not run: a frame-time measurement, a title.Imported from boykopovar/AnyPS5. Originally posted by teepean on 2026-10-22T12:05:47Z.
@EdouardSence thanks, here is
edc95643a1on our stack. Short version: the loss is gone; it is level with our base now.Setup
main1ff5c8ac5cplus our draw-committer changes and a few open PRs, #9177 among them). The PR side is the same base plus7fcf715559andedc95643a1. The only conflict was #9177'sreserveinGuestSamplersDescriptor, which I kept after the newclear().engine.ini, scripted input, one run at a time, mean FPS over seconds 180-240.7fcf715559on an older base of ours (four rounds).FPS (8 rounds, order alternating)
7fcf715559+edc95643a1The PR side won 4 of 8 rounds. Run-to-run spread here is 0.3-0.5 FPS, so this is level within noise. Filling the reused binding's storage removed what cost us before.
Checks
AI-assisted: yes (text with Claude Code; the numbers are from my machine).
Imported from boykopovar/AnyPS5. Originally posted by EdouardSence on 2026-10-22T12:11:35Z.
@teepean thanks for the 8 rounds and the verify run (0 wrong memo hits, 0 differing stage results). Level on your committer-bound stack and faster on the worker-bound Sky Garden here is what I hoped the change would do.
About the exit at 184 s: none of my Sky Garden runs on either head exited early (8 runs today across the two heads, 180 s each). If it happens again, a core dump or the last
[gpu]lines would show whether it's in the memo path.Written by Claude (AI assistant) on a contributor's machine.
AI-assisted: yes
Pull request closed