perf(shader): discard helper functions unreachable after specialization #5064
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5064"
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 Scramblrrrr on 2026-10-13T10:17:10Z.
What
Specialization can remove a call in a folded-away branch while leaving the callee and its helper chain in the emitted SPIR-V. Remove whole function bodies that are no longer reachable after folding and dead-computation cleanup.
The pass starts from every entry point and module-level function reference, then follows function references transitively. It preserves exported/imported linkage declarations and functions whose local results are referenced by global group/ID/string annotations. Modules without entry points are left alone. Removed result IDs use the existing name/decoration cleanup. The existing ID-operand visitor distinguishes literal words from IDs, including 64-bit switch literals; unknown operands conservatively retain references.
This changes function reachability cleanup, not shader instruction semantics or the structurizer. It is independent of the larger 007 cross-test stack. No title stop, rendering fix, compile-time reduction or FPS improvement is claimed.
Tested
Windows 11, MinGW GCC 15.2 Release, Ryzen 7 7800X3D, RTX 5070 Ti, SPIRV-Tools OFF. Head
c94673ecd086cc4f9d98692200194e0189710e09, based on main77b9f7270c25518d26052671311f43497328fdc7.agc_spirv_module,agc_spirv_branch_targets,agc_shader_memory,agc_shader_disk_cache,agc_driver_bda_device,agc_pipeline_cache,agc_storage_baseline_settled,agc_storage_upload_lifetime.removeUnusedFunctions(), keeping the fixtures. The module test fails its dead-helper and dangling-name checks; the other three CPU controls pass. Restore the pass and disable only the linkage/string annotation guard: the module fixture fails because the exported function is lost. Restoring the source and rebuilding passes the eight checks above.An exploratory 007 run on a separate combined branch did not establish a performance gain: the largest startup modules retained the same word counts, and cold area pipelines were still compiling when that test ended. That is not an isolated-main title benchmark. No title code, captures, assets or raw title logs are uploaded.
Checklist
main; searches found no equivalent open helper-function reachability changeImported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T10:31:03Z.
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/tests/SpirvModule.cppL287-289core/shader/recompiler/SpirvBackend/src/SpirvSpecialization.cppL732-734Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-13T12:34:13Z.
Reviewed the overlap report against #4772 head007721d43e0511e446cd59d2854fe6ff80ff9a69. The behaviors are complementary: #4772 replaces specialization id maps/sets with bound-indexed containers, while this PR adds function reachability after specialization and removes helpers unreachable from entry/export/annotation roots. Neither implementation is a prerequisite for the other.
There is an integration adjustment beyond the adjacent test insertions: removeUnusedFunctions uses the existing map-style resultTypes.find iterator for OpSwitch literal width; #4772 changes find to a pointer. If #4772 lands first I will rebase and adapt that lookup, retain both fixture sets, and rerun CPU/native controls. Combined build/tests have not been run yet. No title benefit claimed. AI-assisted (Codex).
Imported from boykopovar/AnyPS5. Originally posted by coltken95 on 2026-10-13T18:52:26Z.
Tested on Linux x86-64 (Release build), with
c94673ecdmerged into main9d0a41d5a:agc_spirv_modulepasses.agc_spirv_modulefails.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-13T19:25:17Z.
Thanks for the independent Linux cross-test and production-negative with the PR fixture retained. That complements the Windows native and reachability-negative controls in the description. No source revision is needed for this result; current head remains
c94673ecd0. AI-assisted: yes (Codex).Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-10-14T00:59:10Z.
Review: COMMENTED
The reachability logic looks careful. Roots are entry points, module-level references, linkage exports and annotated local results; unknown operands stay conservative; 64-bit switch literals are handled. The mutation tests are good.
My concern is cost against benefit, since this runs inside
SpecializeSpirvfor every pipeline variant:std::map<id, std::set<id>>/std::setstructures over the whole module, with a log-n lookup (functions.contains) per ID operand. For the 1M+ word compute modules mentioned in other PRs (Yōtei, GTA V RT), that is a noticeable amount of allocation and pointer chasing on the path that creates a variant, which may run on a queue worker when a variant is first used.Before merging, I'd suggest:
SpecializeSpirvon a large captured module (agc_compute_pipeline_replaycaptures work) with and without the pass. Flatstd::vector<uint32_t>tables indexed by ID (the module'sboundis known), as #4772 does for the specialization maps, would make it close to free.If neither shows a gain, a cheap early-out (skip the pass when the module has one function, or when specialization removed no
OpFunctionCall) would at least keep the common case at zero cost.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T02:33:39Z.
Closing: no measured gain in a title yet; the only run is
agc_spirv_module. Reopen with before/after numbers from one title scene showing the specialized helpers matter.Pull request closed