perf(shader): reserve an IR value's arguments for its opcode at creation #7518
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7518"
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-18T11:13:09Z.
What
An
IrValuegrows itsargumentsvector oneAddArgumentat a time, starting empty. A value with two arguments allocates twice (capacity 1, then 2), and one with three allocates three times (1, 2, then 4), freeing the earlier blocks each time. In a profile of a Release replay of 355 MXGP 26 (PPSA30839) shader requests onmain, the allocator (malloc,freeand their internals) was 20% of all samples. Its largest callers were the destruction of IR programs,IrProgram::CreateValueandIrValue::AddArgument.The constructor now reserves
IrOpcodeOperandCount(opcode)arguments. That is the countIrBuilder::Emitalready requires for each opcode, so a value given its opcode's arguments allocates once. Opcodes without a fixed argument list have a count of 0 and reserve nothing as before; that coversPhi, andVoid, which constants and register operands use. A laterAddArgumentpast the reserved count grows the vector as before. Nothing else changes: the IR, the order of values and the SPIR-V are the same.Tested
Ubuntu 24.04 (Linux 6.8), GCC 13.3, NVIDIA RTX 4070 Ti, driver 595.99.02.
ctest -R "^agc_|^shader_ir"on9f25d0bf5b: 709/709 pass (3 skipped: host import sparse, sparse dma-buf import, stencil ref export).agc_shader_replay --spv(Release,ANYPS5_ENABLE_SPIRV_TOOLSoff,ANYPS5_NO_SHADER_CACHE=1) on 466 shader requests I had dumped withAPS5_DUMP_SHADERS: 355 from PPSA30839, 107 from PPSA31162 and 4 from another app. All 462.spvfiles (a few names repeat across the dumps) have the same SHA-256 onmain9f25d0bf5band with this PR, and the replay output is identical.Replay CPU time (
perf stat -e task-clock), interleaved:main9f25d0bf5b0x1e401c0000(1,056,287 SPIR-V words), 15 runs each0x10f9f30000(1,130,170 words), 15 runs eachThat is about 4 to 5% on the two large shaders and about 1.7% over the whole set.
Title level: no speed claim. This is background shader preparation. I didn't run a title for it.
This is independent of #7431, #7491, #7494, #7503 and #7516, which change single 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 (3c5679c7609e). 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:26Z.
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 (3c5679c7609e). 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:39:24Z.
Checked that the reserved count is the same
IrOpcodeOperandCountthatIrBuilder::Emitalready enforces, that variable-arity opcodes (Phi, Void) reserve nothing, and thatAddArgumentpast the reserved count grows as before, so the IR is unchanged; merged.