perf(shader): keep up to three IR operands inside the value #11820
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11820"
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-27T08:52:22Z.
What
Every IR value keeps its operands in a
std::vector<IrValue*>, which the constructor reserves to the opcode's operand count. So almost every value makes a second heap allocation, and each operand read follows a pointer away from the value itself.This change replaces the vector with
IrOperands. It holds up to three operands inside the value and moves to a heap array only when a value gets more, for example a phi with many predecessors.On 152 Crimson Desert (PPSA25286 01.000.568) shader requests:
agc_shader_replay --prepareuses 19.2 % less CPU time (8 of 8 rounds, rotating order) and 2.8 % less peak memory.main, so the gains stack.All 65 Crimson Desert and 302 MXGP 26 (PPSA30839 01.003.000) SPIR-V outputs are byte-identical.
How
IrOperands(inIrValue.hpp):IrValuegoes from 128 to 136 bytes) and needs no allocation for up to three operands.size,empty,begin/end,operator[],at,front,back,push_back,reserve,clear, and assignment from the vectorSetDetachedOperandstakes. That covers every use ofArguments(), which only iterates, indexes or copies the operands into a vector.IrValue::Arguments()now returnsconst IrOperands&. Nothing else changes: same operand order, and the same use lists, IDs and dumps.ShaderDiskCache.cppassertssizeof(IrValue)as a reminder for the plan value encoder. The encoder writes operands one at a time throughArgumentCount()andArguments(), so the disk format doesn't change; only the asserted size moves to 136.Where the time goes: one DWARF profile per side (
perf record --call-graph dwarf -F 199, same input) shows:IrValueaccessors fall from 482 to 355. For example,Argumentdrops from 28 to 6 andHasUsesfrom 169 to 115.The operands now sit next to the rest of the value.
Tested
Linux, i7-13700K, GCC 15.2, Release with
ANYPS5_ENABLE_SPIRV_TOOLS=OFF. I builtcmake --build build-rel --target agc_shader_replayatmain13926067ac, at this change, and at this change merged with #11798.ANYPS5_NO_SHADER_CACHE=1 agc_shader_replay --spvover the same 152 Crimson Desert and 305 MXGP 26 requests as #11719 (input hashes in #11719). Each binary ran in an empty directory per set, and I diffed thesha256sum * | sort -k2lists. All 65 and 302 SPIR-V outputs are byte-identical tomain's, with and without #11798.ANYPS5_NO_SHADER_CACHE=1 /usr/bin/time -f %M perf stat -x, -e task-clock agc_shader_replay --prepare <the 152 requests>in a fresh empty directory, with four binaries per round in a rotating order:main(ms)mainRSS (KB)Means over the 8 rounds:
mainmainThis PR is lower than
mainin all 8 rounds. The binaries' sha256 prefixes are50c1220f47cc(main),c78ab132d352(this PR) and576b021a843d(both). These numbers use glibc's allocator, which titles use on Linux; I haven't measured Windows' default heap.Tests: I ran the 19 AGC test targets whose sources use
IrProgram(the same set as #11798, 20 ctest entries) andagc_shader_disk_cache_tests(7 entries), because of the size assert. Each passes 3 of 3 (--repeat until-fail:3) on an RTX 4070 Ti (NVIDIA 615.71.09) at this head. This PR also extendsagc_ir_reclaim:ReplaceArgumenton heap-stored operands;SetDetachedOperandswith five operands;On Windows 11 (WinLibs GCC 15.2, Release, GT 1030 with NVIDIA R580), the same 26 ctest entries pass 3 of 3 at this head and at its base
13926067ac. Under AddressSanitizer (ANYPS5_ENABLE_ASAN=ON, RelWithDebInfo),agc_ir_reclaim, including the new grown-operand cases, andagc_validate_programpass 3 of 3 at this head with no ASan report.This is a CPU-only shader-compilation change with byte-identical SPIR-V, like #11719, #9132 and #9198. It therefore uses the paired CPU replay that oneandonlydean accepted for those (#11719) instead of title captures.
Rebased head
e339f57e4d(onmainca0e9557aa), after review:agc_shader_memory's compaction check now assertsArguments().capacity() == max(ArgumentCount(), IrOperands::InlineCapacity), meaning no spare heap operand storage.SetDetachedOperandsgives detached operands exactly the storage they need, as the vector it replaced did.Arguments(),OperandUses(), the IR value types),agc_shader_memory_testsandagc_ir_reclaim_testsincluded. All 75 of their ctest entries pass 3 of 3 (--repeat until-fail:3) on an RTX 4070 Ti, the 7 disk-cache entries among them.agc_ir_reclaim,agc_validate_programandagc_shader_memorypass 3 of 3 with no report.main'sagc_shader_replayrebuilt at the same baseca0e9557aa, all 65 Crimson Desert and 302 MXGP 26 SPIR-V outputs are byte-identical. Four alternating--preparerounds give 15.59/15.72/15.59/15.39 s formainand 12.54/12.91/12.40/12.57 s for this PR (means 15.57 and 12.61 s, −19.0 %).Merge order
IrValue's trivial accessors,Arguments()among them, into the header, so the two touch the same lines ofIrValue.cpp. #9132 lands first, and this PR gets rebased onto it so thatArguments()returnsconst IrOperands&in the header.IrResourcePlansize assert on the line above this PR'sIrValueassert, a one-line textual conflict with no behavioural dependency. MarcZX10 agreed on #7689 (comment) that whichever of the two lands second keeps both new values, so neither depends on the other.IrValuesize assert from 128 to 136, for its use-list allocator. The two edits are identical, so git merges them without a conflict, but togetherIrValueis 144 bytes. #12039 declaresDepends on: #11820, so it lands after this one and sets the assert to 144 when it's rebased (the combined layout is validated in #12039's description).Title captures: Super Meat Boy 3D,
main9af563f33d+ #11580 (608dd76843) against the same + this PR (4f3d1e1d88), 5 interleaved rounds, recompiler cache off.Shader.PrepareArtifactworker time over each run's first 400 worker artifacts is 8,696 ms → 7,335 ms (-15.6 %, lower in 5 of 5) and title-thread time over the first 350 is 5,781 ms → 5,337 ms (-7.7 %, 4 of 5); over the whole window, leaving out rounds 2 and 4 where the PR run reached a later scene, workers are 12,018 ms → 10,397 ms (-13.5 %) (table and traces). Round 3's summary lines: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)IrValue.cpp; it lands first and this PR rebases onto it)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-27T08:56:54Z.
Review: CHANGES_REQUESTED
Requesting changes: the current IR API change breaks the existing AGC shader-memory test. In core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp:759, agc_shader_memory_tests calls value.Arguments().capacity(). The new IrOperands type has no public capacity() method; its capacity field is private. I reproduced the compile error against the exact PR header with GCC 12.2: the call resolves to the private uint32_t field and cannot be invoked as a function. CMake includes ShaderMemory.cpp in agc_shader_memory_tests and registers that target for BUILD_TESTING, so this prevents the target from compiling. Please update the compaction assertion to express the intended no-spare-heap-storage invariant for inline operands, or provide a suitable public API and adjust the assertion for inline capacity, then rerun this target at the exact updated head. The hosted relinker jobs do not compile this target, and the full product jobs are skipped, so current green/pending checks do not cover the failure.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-27T09:28:29Z.
Review: DISMISSED
Follow-up review of the updated head
3c6629017d1c3ffe96b0c5c037a3cac20913075f: the earlier compile issue I found (Arguments().capacity()missing on the new type) appears addressed by the new publiccapacity()and the inline-capacity-aware assertion. The updated Windows/product and relinker CI jobs are still pending, so I cannot yet verify the fix in the project targets.Three repository requirements still block approval:
perf(shader)and carries theperf numbers missinglabel. The report contains useful replay timings and allocator data, but not the required two validaps5-summary.jsonllines from different commits or the attached traces described by the Performance report form. Please add that required evidence or have maintainers record an applicable exception.5bc84038c490a0427ff272e39e2a1cdf6fdc3c0e, while currentmainis801d5b9bc11049e6274daca09d70690bd5b8d0a9. Rebase/update to currentmainand rerun the affected tests.Depends on: none. CONTRIBUTING asks authors to agree with the overlapping PR authors on landing order and declare the dependency. Please record the agreed order and update the checklist.I did not run the full shader build or tests locally. I am requesting changes for the missing performance evidence, stale base, and unresolved overlap order; the earlier API compile finding appears fixed, but the current CI run has not completed.