perf(agc): free a registered shader's decoded program once it is planned #5910
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5910"
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 milescoviello on 2026-10-14T15:30:12Z.
What
Borderlands 4 (PPSA01494) registers shaders in a burst about 190 s into a warm run, and its anonymous resident memory grows from about 1 GB to 8–9 GB within six seconds. A jemalloc heap profile taken in that burst shows 638 MiB held by RDNA programs that
PlanRegistereddecoded (RdnaInstructionDecoder::Decode←PlanRegistered←Driver::RegisterShader←sceAgcCreateShader).Since #2583 prepares registered shaders in the background,
PlanRegistereddecodes the program into theRegisteredPreparationit queues for the registration prepare pool. OnlyPlanRegisteredreads that decoded program, for thes_swappc_b64check;PrepareRegistereddoes not use it, and the preparation decodes the program again on its own (ShaderPreparationContext::AcquireFrontend). So every shader waiting in the pool's queue holds a decoded copy of its program until a worker has prepared it.PlanRegistereddecodes into a local again, as it did before #2583, and the queued preparation no longer carries it.Tested
Ubuntu 24.04, GCC 13.3 (CI's compiler), Release with CI's configure flags, on
main84b01f9cd, then rebased ontomaina453108cf(which changes onlylibSceVoicesince):All 541 tests in
libSceAgcDriverpass.agc_driver_stencil_ref_exportis skipped because the device lacksVK_EXT_shader_stencil_export, andagc_host_import_sparseandagc_driver_sparse_dma_buf_importbecause/dev/udmabufis not accessible here.Borderlands 4 (PPSA01494), relinked with
--to-inteland run on Linux (RTX 4070 Ti, NVIDIA 580.142) with a warm shader cache under a 15 GB memory cap, once per build under jemalloc 5.3 with sampled heap profiles (prof:true,lg_prof_interval:32,lg_prof_sample:19). The two runs differ only inlibSceAgcDriver.prx. Live heap in the last profile before the run reached the cap (about 181 s):mainPlanRegisteredAcquireFrontend(preparations in progress)Most of the rest of the heap at that point is resource plans decoded from the shader cache (1.7–1.9 GB) and SPIR-V optimization in progress, which this change does not touch.
Without jemalloc the title still reaches the 15 GB cap in that burst, at 201–209 s, with and without this change: 3 of 3 runs with this PR, and 2 of 3 on
main, where the third stopped earlier at a glibc heap check that this machine's memory produces with and without changes (see #5777). So this change alone does not let it through on that budget.tools/check_conventions.py --base upstream/mainpasses, andtools/pr_overlap.py --branchfinds no overlap.Not checked on Windows or on a console.
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
Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-10-14T19:16:57Z.
Review: COMMENTED
Checked: on
main,RegisteredPreparation::decodedis only read by theUnresolvableSwappcTargetcall inPlanRegistered, and the preparation decodes again inAcquireFrontend. So every queued shader held a decoded copy it never used, and decoding into a local keeps behaviour identical. Clean change with a clear heap profile behind it.It should also help #5872, which reports the same registration burst pushing Demon's Souls out of memory.
Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-14T21:26:01Z.
A second title: Forspoken (PPSA03984) on Linux (RTX 4070 Ti, 595.99.02, GCC 13.3, Release). The base is
mainfa539dd9bwith #5937, #5975 and #5982 merged, since Forspoken stops earlier without them. Each run used a warm shader cache under a 15 GiB cap, and jemalloc heap profiles were taken every 2 GiB allocated (prof:true,lg_prof_interval:31,lg_prof_sample:19). This compares the last profile of each run:ShaderRecompiler::DecodeRdnaProgramThe total barely moves because the run with this PR got further before the cap stopped it: its last profile came after 82 dumps instead of 61. Its resource plans (
decodePlan,IrValue::AddArgument,ownPlanValues) grew from 3.1 to 4.0 GiB in that time.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T00:41:01Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cppL727-728, L772