perf(shader): mark live values of a reclaimed program without a hash set #7503
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7503"
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-18T09:50:30Z.
What
IrProgram::ReclaimUnusedValuesruns once for each resource program (ResourcePrograminRecompiler.cpp). It marked every live value by inserting it into anstd::unordered_set<IrValue*>, which costs one node allocation per value plus rehashes, and then looked every value of the program up in that set three more times. In a profile of a Release replay of 355 shader requests from MXGP 26 (PPSA30839), it was 7.1% of all samples (inclusive). Most of that was the set: its lookups and inserts, and themallocandfreeof its nodes.Values enter
valuesonly throughCreateValue, which numbers them withnextValueId. So an id belownextValueIdnames at most one value of the program. The marks of those values now live in an id-indexedstd::vector<bool>, after a check thatvaluesholds the same pointer under that id. This is the schemeIdIndexin the same file already uses forValidateProgram. A value the program does not own still goes into a set as before. That covers the resource plan'svalueStorage, which can reuse an id (agc_ir_reclaimdoes that on purpose). The roots, the walk over arguments, the error for a removed value with a user, and the values kept and removed are unchanged.Tested
Ubuntu 24.04 (Linux 6.8), GCC 13.3, NVIDIA RTX 4070 Ti, driver 595.99.02.
ctest -R "^agc_|^shader_ir"on9caecfd2d5: 709/709 pass (3 skipped: host import sparse, sparse dma-buf import, stencil ref export).agc_ir_reclaimpasses. It covers reclaiming detached and cyclic values, keeping values that only metadata or the resource plan holds (avalueStoragevalue with a reused id among them), the error for an untracked external user, and moves of the program.agc_shader_replay --spv(Release,ANYPS5_ENABLE_SPIRV_TOOLSoff,ANYPS5_NO_SHADER_CACHE=1) on 420 shader requests I had dumped withAPS5_DUMP_SHADERS: 355 from PPSA30839 (two dumps), 61 from PPSA31162 and 4 from another app. All 419.spvfiles that are produced have the same SHA-256 as onmain9caecfd2d5. The replay output also matchesmaincb1d6e5bd6line for line, including the one request that fails on both. (Against9caecfd2d5I only compared it with the timer below built in, and that run's output differs only by the timer's own lines.)Pass time, from a temporary timer in
ReclaimUnusedValuesthat is not part of this PR, onmain9caecfd2d5and with this PR, interleaved:mainWhole-replay
task-clockof the 355 requests was 25,153 and 25,115 ms onmainand 24,420 and 25,000 ms with this PR. That run-to-run spread is about as large as the gain, so I'm only claiming the pass time.Title level: no speed claim. This is background shader preparation. I didn't run a title for it.
This is independent of #7431, #7491 and #7494, which change other passes of the same shader preparation.
tools/check_conventions.py --base upstream/mainpasses.tools/pr_overlap.pyreports no overlap with open pull requests.Title capture
As the
perflabel asks, these are captures of one title and scene on one machine. MXGP26 (PPSA30839) ran from boot withAPS5_TRACE_SECONDS=0:60,ANYPS5_NO_SHADER_CACHE=1and a fresh run directory (cold AnyPS5 and NVIDIA caches), so the shaders compile inside the window. NVIDIA RTX 4070 Ti (595.99.02), Ubuntu 24.04, release libs, Xvfb display, no input.maindbac9fa15bwas captured five times: before the PR captures, after them, and three more times in a row after that. Each PR capture and the first twomaincaptures followed a rebuild of the release libraries; the last threemaincaptures did not, and they came out lower. The change ismainwith this PR merged on top as a local merge commit (d0211cb37d95). The time is the wall time of theShader.PrepareArtifactslices on theshader preparethreads in each trace.main1main2main3main4main5The five
maincaptures span 17.7% in total prepare time, and the 13 prepare threads run in parallel with the title, so a title capture can't resolve a recompiler change of a few percent. The replay measurement above is this change's measurement. This PR's capture is above all fivemaincaptures in total and median prepare time. With one capture of the change I can't tell that apart from noise, and the replay measurement above points the other way. I can repeat the capture if that would help.main1 trace, digest,main2 trace, digest,main3 trace, digest,main4 trace, digest,main5 trace, digest, this PR trace, digestChecklist
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 milescoviello on 2026-10-19T21:35:30Z.
The title capture the
perflabel asks for is now in the description, with both summary lines, the traces and the digests: MXGP26 from boot, a cold shader cache,maindbac9fa15bagainstmain+ this PR (d0211cb37d95). The fivemaincaptures span 17.7% in total shader prepare time, so the capture can't resolve this change, and the replay measurement in the description is still its measurement. This PR's capture is above all fivemaincaptures in total and median prepare time. With one capture of the change I can't tell that apart from noise, and the replay measurement above points the other way. I can repeat the capture if that would help.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T22:21:26Z.
Checked the diff:
valuesis only filled throughCreateValuewithnextValueId, so ids of owned values are unique and the pointer check keeps foreign values (reused ids in the resource plan) in the fallback set. Roots, argument walk, the external-user error and the removal set are unchanged;agc_ir_reclaimcovers the reused-id case. Merged.