perf(agc): reuse user-data callee links and check a cached raw shader's range once #9899
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9899"
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 savvaniss on 2026-10-22T20:50:00Z.
What
Get-fix/AnyPS5#13 and #15, moved upstream as one pull request. Both cut the shader preparation a draw or dispatch repeats when its draw cache entry misses. Neither is PS4-only, so it goes straight on
main. Each is its own commit.1. A program's user-data callee link is reused while its callees are unchanged (Get-fix/AnyPS5#13)
InvocationForlinks the user-data callees of a compute shader, and of a GCN vertex shader (its fetch subroutine), before it looks up the prepared artifact. Until now it did that from scratch on every draw and dispatch:RdnaInstructionDecoder::Decode, which for a GCN program re-encodes and decodes each instruction);s_swappccalls through user data and table calls (FindUserDataCalls,FindTableCalls);ReadUserDataCallee,UserDataCalleeLength);LinkCalls).The registered code never changes, and the callees rarely do. On Monopoly Plus's language screen, after #12, the queue worker is the bottleneck: draws there change their user data on almost every draw, so the draw cache rarely holds them and each draw prepares its stages again. A sampling profile of the worker put 28.8% of its time in
InvocationFor, 17.4% of all its time in decoding the vertex programs again, and about 5% in reading and measuring their fetch subroutines.This commit keeps the result with the program's prepared state (
PreparedShaderState::userDataLinks):Accessiblecheck andReadas the first read). Anything else reads and links the callees as before, so a callee rewritten in place, a callee moved or an unreadable callee behave as today, with the same errors.Nothing depends on the title: any registered compute shader or GCN vertex shader with user-data callees takes this path.
On
main,LinkUserDataCalleeslinks compute programs only, so here the memo serves compute dispatches. With #9431 it also links GCN vertex programs, and the memo covers those the same way.2. A raw shader's address range is checked only when its snapshot is read again (Get-fix/AnyPS5#15)
ReadRawShader(a PS4 program with no header, read from guest memory by its address) began withGuestMemory::CheckRangeon its first four bytes, then looked the address up in its snapshot cache. A cached snapshot is then compared with guest memory byGuestMemory::CompareMapped, which walks the same page states and returnsUnmappedfor a page that is no longer readable. So on a cache hit the range check was a second page walk whose answer the compare gives anyway.DecodeProgramsCurrentcallsReadRawShaderfor each raw program of every draw that reuses a kept decode. On Monopoly Plus's language screen, after #14, a sampling profile of the queue worker put 8.2% of its time inReadRawShader;CheckRangewas about half of that.This commit runs the range check only when the snapshot is read again from guest memory: on a cache miss, or when the compare found the bytes changed or unmapped. Nothing else changes:
Unmapped, reaches the check and throws as before.Get-fix/AnyPS5#14 (bypassing an unhit result memo) is not here: #6733 replaced that memo with a set-associative table on
main, and its eviction cost, which #14 avoided, would have to be measured again.Tested
Windows 11 Pro 26300, WinLibs GCC 15.2.0, Release, on
main3bbd2321de, AMD Radeon RX 9070 XT (driver 32.0.31041.1004),ANYPS5_GPU=AMD.agc_driver_user_data_link_reuse(new, Vulkan) runs a compute program that calls two user-data callees three times in a loop. It is invoked throughInvocationForand dispatched each time, and every lane must hold the sum of the callees' constants.With
ShaderRegistry.cppas onmainit fails with "the first invocation did not keep exactly one user-data link with both callees".The raw shader commit moves one existing check, so it has no test of its own.
agc_driver_scalar_swappc,agc_driver_scalar_swappc_fetch, bothagc_driver_compute_user_data_callsmodes and the user-data tail tests pass.Merge of
mainb7488e1ff5(30 Oct, merge commit009fc42f03): the only conflict wasLinkUserDataCallees. #9431 made it link GCN vertex shaders too, and the merge keeps that rule with this branch's memo. On the merge, 11 of 11 pass on the RX 9070 XT under the validation layer, with noVUID-line:agc_driver,agc_shader_memory, bothagc_driver_compute_user_data_callsmodes,agc_driver_scalar_swappc,agc_driver_scalar_swappc_fetch,agc_driver_queued_raw_shader,agc_driver_user_data_link_reuse,agc_driver_user_data_call_after_branch, and the fragment and vertex user-data tail tests. The focused 100-test set and the per-case failures below are from before this merge and were not rerun. Linux was not compiled here;PreparedShaderStatehas no size guard.Merge of
maincc26ab4438(1 Nov, merge commit89f30e45f0): the only conflict waslibSceAgcDriver/CMakeLists.txt:mainmoved the AGC test registrations intotests/cmake, andtools/agc_test_split.py resolvemoved this branch's include line to theagc_driver_user_data_link_reuse_testsfragment.agc_driver,agc_shader_memory, bothagc_driver_compute_user_data_callsmodes,agc_driver_scalar_swappc,agc_driver_scalar_swappc_fetch,agc_driver_queued_raw_shader,agc_driver_user_data_link_reuseandagc_driver_user_data_call_after_branchpass, 3 of 3 on the RX 9070 XT under the validation layer, noVUID-line. Not rerun: the other tests, Linux, games.Validation layer: 100 focused tests on
mainand the same 100 plus the new one on this branch, withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1andVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation. The set is the same as for the store pull request. All pass: 100 of 100 and 101 of 101. Both logs have the same fourVUID-VkImageViewCreateInfo-usage-02275lines fromagc_sampled_storage_base_level_usage, whichmainalready logs; the change adds none. Neither log containswas not found but was requested by env var VK_INSTANCE_LAYERS, and every device line names the RX 9070 XT.What the performance numbers below can and cannot show.
main/change pair from this title. CUSA03312 does not start onmain(it needs #9430 to #9432), so both pairs below come from the unpublished local stack onps4/limbo-gpudescribed next, and cannot be rebuilt from published commits. The traces named in their summary lines are not attached.mainthe memo serves only compute programs with user-data callees, becauseLinkUserDataCalleeslinks only those; GCN vertex programs reach it with #9431. EdouardSence's alternated A/B on ASTRO BOT (PPSA21567, Sky Garden, RX 9070 XT, RADV), onmainplus #9852 with and without this head, is level: frame p50 207.1 ms against 209.4 ms, inside that scene's ±1.5 % run-to-run spread (comment). Neithermainnor this change counts reused links, so that run cannot show how often the memo was hit there.main. It stands as an optimisation with identical output:agc_driver_user_data_link_reusechecks the dispatch results with a reused link, after a rewrite and after the cap of eight links. The CUSA03312 numbers show what it does on the title stack it was written for.totals_fullisfalsein every line. The summary fields (frame_ms,gpu_busy_ms_per_present,worker_busy_pct,top_phases_ms_per_frame) are built from the complete totals and hold. Only the per-slice parts oftools/trace_digest.py(slowest frames, the threads table, longest waits) miss the queue worker's slices after the buffer filled.Monopoly Plus (CUSA03312). The title doesn't run on
main: it needs #9430 to #9432. As agreed on #6977, these numbers come fromps4/limbo-gpuat93eeee0141(#6977's head then), with and without the change, on the local stack the title needs to start: the Get-fix pull requests named with each pair, and local stand-ins forsceGnmDrawInitDefaultHardwareState200andsceGnmUpdate*Shader. The base and change commits named with each pair are commits of that local stack, which isn't published. Base and change alternated on the same machine and scene.3fe75b613c, change60aac9783f, both with Get-fix/AnyPS5#1, #2, #5, #8 and #10 to #12:Driver.Packetms/frameshader_compile_and_linkms/frameprepared_invocationms/framematerializems/framecapture_resourcesms/frameSummary lines; the two traces they name will be attached by hand:
Base (
3fe75b613c):Change (
60aac9783f):tools/trace_digest.pyof the two tracesBase,
aps5-trace-3fe75b613c46-35740:seconds 120:15 from present 2876: 278 presents, frame p50 54.1 / p90 55.3 / p99 56.9 / max 58.2 ms, GPU busy 14.5 ms per present
AMD Radeon RX 9070 XT, AMD proprietary driver 26.8.1 (LLPC), Windows 10.0.26300, 1920x1080, commit 3fe75b613c46, dropped: yes
Slowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): batch 14.5, Driver.Packet 10.0, Driver.Packet.draw 8.7, Driver.Draw 8.6, Driver.Draw.shader_compile_and_link 6.8, Shader.DrawStage 4.3, Shader.DrawStage.prepared_invocation 1.7, Driver.Packet.device_lock 1.0
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
Change,
aps5-trace-60aac9783f36-9108:seconds 120:15 from present 3535: 374 presents, frame p50 40.1 / p90 41.1 / p99 42.5 / max 46.2 ms, GPU busy 13.6 ms per present
AMD Radeon RX 9070 XT, AMD proprietary driver 26.8.1 (LLPC), Windows 10.0.26300, 1920x1080, commit 60aac9783f36, dropped: yes
Slowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): batch 13.6, Driver.Packet 7.4, Driver.Packet.draw 5.9, Driver.Draw 5.8, Driver.Draw.shader_compile_and_link 3.6, Driver.Packet.device_lock 1.2, Shader.DrawStage 1.0, Driver.Present 0.4
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
In each trace the queue worker's event buffer filled 3.1 to 3.4 s into the 15 s window (
trace_dropped_threads). Its later slices are missing from the trace, so the thread, slice and wait lists cover only that part of the queue worker's time.819cd3db26, changecb626a70e8, both with Get-fix/AnyPS5#1, #2, #5, #8 and #10 to #14: the queue worker's profile share of the check fell from 8.2% to 5.1%, and fps stayed within noise (26.3 vs 26.7).Summary lines; the two traces they name will be attached by hand:
Base (
819cd3db26):Change (
cb626a70e8):tools/trace_digest.pyof the two tracesBase,
aps5-trace-819cd3db2630-35708:seconds 120:15 from present 3744: 395 presents, frame p50 37.9 / p90 39.2 / p99 41.5 / max 57.2 ms, GPU busy 13.2 ms per present
AMD Radeon RX 9070 XT, AMD proprietary driver 26.8.1 (LLPC), Windows 10.0.26300, 1920x1080, commit 819cd3db2630, dropped: yes
Slowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): batch 13.2, Driver.Packet 7.1, Driver.Packet.draw 5.3, Driver.Draw 5.2, Driver.Draw.shader_compile_and_link 2.6, Driver.Packet.device_lock 1.4, Shader.DrawStage 0.6, Driver.Present 0.4
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
Change,
aps5-trace-cb626a70e8ae-27232:seconds 120:15 from present 3828: 419 presents, frame p50 35.6 / p90 37.7 / p99 39.4 / max 50.1 ms, GPU busy 13.9 ms per present
AMD Radeon RX 9070 XT, AMD proprietary driver 26.8.1 (LLPC), Windows 10.0.26300, 1920x1080, commit cb626a70e8ae, dropped: yes
Slowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): batch 13.9, Driver.Packet 6.6, Driver.Packet.draw 4.8, Driver.Draw 4.8, Driver.Draw.shader_compile_and_link 2.5, Driver.Packet.device_lock 1.4, Shader.DrawStage 0.6, Driver.Present 0.4
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
In each trace the queue worker's event buffer filled 3.6 to 3.7 s into the 15 s window (
trace_dropped_threads). Its later slices are missing from the trace, so the thread, slice and wait lists cover only that part of the queue worker's time.tools/check_conventions.py --base origin/mainpasses.tools/pr_overlap.pylists #8658 (macOS host), which changes neighbouring lines ofShaderRegistry.cpp, and #9842. #9431 and the pull requests stacked on it, #9842 among them, change the first lines ofLinkUserDataCalleesto link GCN vertex programs as well. With both in, that line returnsnullptrfor a program that is neither compute nor a GCN vertex program, and the memo covers both. None implements the same thing.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