Repository navigation
perf(shader): keep up to three IR operands inside the value - #11820
Conversation
|
This pull request is labeled |
MarcZX10
left a comment
There was a problem hiding this comment.
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.
|
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
|
@MarcZX10 thanks, you're right. I only built the 19 targets plus the disk-cache test, and
To catch anything else that compiles against this API, I've queued a build of every test target whose sources use AI-assisted: yes (Claude Code) |
|
@milescoviello one blocker: Could you restate that plan-compaction check for |
MarcZX10
left a comment
There was a problem hiding this comment.
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 public capacity() 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:
- This is titled
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. - The branch base is
5bc84038c490a0427ff272e39e2a1cdf6fdc3c0e, while currentmainis801d5b9bc11049e6274daca09d70690bd5b8d0a9. Rebase/update to currentmainand rerun the affected tests. - The body identifies overlap with open #9132 and #7689, but says either can land second and leaves
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.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…luded Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3c66290 to
e339f57
Compare
|
@MarcZX10 thanks, taking these in order.
AI-assisted: yes (Claude Code) |
|
@MarcZX10 @oneandonlydean results on the rebased head
The Windows VM rerun on the rebased head is queued. The perf-evidence question is still with oneandonlydean. AI-assisted: yes (Claude Code) |
|
Title captures for the perf label, with the same method as on #11967. Setup
The in-title effect is small:
That's well below the replay's −19 %. I haven't profiled where the rest of a prepared artifact's time goes in the title. Summary lines of the first pair ( {"commit":"ed3b6566a2c6","dirty":false,"env":{"APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_SECONDS":"0:150"},"gpu":"NVIDIA GeForce RTX 4070 Ti","driver":"NVIDIA 615.71.09","os":"Linux 7.0.0-38-generic","cpu":"13th Gen Intel(R) Core(TM) i7-13700K","cpu_threads":24,"memory_mib":30993,"title_id":"PPSA34502","title":"Call of Duty®: Black Ops II","content_version":"01.010.000","resolution":"1920x1080","window":{"spec":"seconds 0:150","first_present":0,"ms":150026.262},"presents":2233,"frame_ms":{"p50":16.694,"p90":190.971,"p99":240.998,"max":1554.838},"gpu_busy_ms_per_present":18.850,"worker_busy_pct":{"queue worker 0x0":77.302},"top_phases_ms_per_frame":{"Driver.Packet":51.240,"Driver.Packet.draw":32.070,"Driver.Draw":31.825,"Graphics.Draw":26.670,"Graphics.Draw.draw_and_resource_release":24.985,"VideoOut.Flip":14.507,"Driver.Draw.shader_compile_and_link":14.251,"Shader.ResolveAbi":12.980},"trace_dropped":true,"trace_dropped_threads":{"title":{"events_full_after_s":95.466,"events_lost":79253,"totals_full":false},"queue worker 0x0":{"events_full_after_s":25.447,"events_lost":2863844,"totals_full":false},"draw committer":{"events_full_after_s":65.833,"events_lost":509726,"totals_full":false}},"trace":"aps5-trace-ed3b6566a2c6-3.json.gz"}
{"commit":"789b0a598ee2","dirty":false,"env":{"APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_SECONDS":"0:150"},"gpu":"NVIDIA GeForce RTX 4070 Ti","driver":"NVIDIA 615.71.09","os":"Linux 7.0.0-38-generic","cpu":"13th Gen Intel(R) Core(TM) i7-13700K","cpu_threads":24,"memory_mib":30993,"title_id":"PPSA34502","title":"Call of Duty®: Black Ops II","content_version":"01.010.000","resolution":"1920x1080","window":{"spec":"seconds 0:150","first_present":0,"ms":150013.049},"presents":2140,"frame_ms":{"p50":16.708,"p90":189.083,"p99":245.821,"max":1454.636},"gpu_busy_ms_per_present":19.757,"worker_busy_pct":{"queue worker 0x0":76.717},"top_phases_ms_per_frame":{"Driver.Packet":53.081,"Driver.Packet.draw":34.310,"Driver.Draw":34.053,"Graphics.Draw":28.711,"Graphics.Draw.draw_and_resource_release":26.993,"Driver.Draw.shader_compile_and_link":15.306,"VideoOut.Flip":14.234,"Shader.ResolveAbi":13.636},"trace_dropped":true,"trace_dropped_threads":{"title":{"events_full_after_s":92.336,"events_lost":83588,"totals_full":false},"queue worker 0x0":{"events_full_after_s":25.917,"events_lost":2898901,"totals_full":false},"draw committer":{"events_full_after_s":64.463,"events_lost":495402,"totals_full":false}},"trace":"aps5-trace-789b0a598ee2-3.json.gz"}AI-assisted: yes (Claude Code) |
|
Title captures for this change, with the same setup as the captures on #12039. The base is Setup: Super Meat Boy 3D (PPSA31162 02.000.001), release libs, 100 s at a 12 GB cap with the same input script, recompiler cache off (
The PR runs in rounds 2 and 4 reached a later scene. They prepared 598 and 634 worker artifacts against 483 to 502 in the other eight runs, so their window totals don't measure the same work, and the mean above leaves those two rounds out. The same boot work, each run's first 400 worker artifacts and first 350 title-thread artifacts by start time, covers all 5 rounds (total ms):
Workers are lower in all 5 rounds and the title thread in 4 of 5. The summary lines of round 3: All ten traces, summary lines and AI-assisted: yes (Claude Code) |
Dismissing a stale review: the requested changes were addressed after it (new head) and the merge queue blocks on it. Please request changes again if anything is still open.
Adapt upstream PR boykopovar#11820 at 3c66290. Keep up to three operands inside each value, retain heap storage for longer lists, and reject capacities outside the 32-bit counters. Update the plan compaction check and IrValue size assertion without changing the wire format. Paired focused validation passes on the saved main and candidate; synthetic SPIR-V is byte-identical. Real Yotei request performance remains unmeasured.
|
Checked the |
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_replayatmain1392606, 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 perf(shader): reuse the evaluator's requirement list across values #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 perf(shader): allocate a program's IR values in chunks #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 perf(shader): allocate a program's IR values in chunks #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. perf(shader): define IrValue's trivial accessors in its header #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 fix(shader): defer guarded fragment V# type faults #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. perf(shader): allocate a program's use lists from an arena #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 perf(shader): allocate a program's use lists from an arena #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