Repository navigation
perf(shader): keep recently specialized SPIR-V for reuse - #25852
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — comments
The review covers head 2a16f1846720f1a90ff5f63c2036cbb2aa5aabb4; I found no verified blocking defect, but the configured byte budget has edge cases worth addressing before relying on it for a hard memory limit.
What I ran
No build or tests were run. I inspected the prepared diff and targeted source at the pinned head.
Results
| Check | Result | Note |
|---|---|---|
| Diff and context review | passed | Changed behavior inspected |
| Build and tests | not run | Author reports 16 passing tests |
Findings
Blocking
None.
Non-blocking
APS5_KEEP_SPECIALIZED_MIBis parsed withstrtoulland shifted left by 20 without validating the input or checking overflow (core/shader/recompiler/Recompiler.cpp:1128). A sufficiently large integer can wrap the byte budget to zero or a smaller value, and invalid text is silently treated as zero. Consider validating and saturating the MiB-to-byte conversion so the configured budget behaves predictably.- The eviction accounting uses
uint64_taddition and multiplication without overflow checks (core/shader/recompiler/Recompiler.cpp:1136). Extremely large SPIR-V modules or aggregate sizes could wrap the counter, causing retention beyond the stated budget. Consider overflow-safe accounting if this setting is intended to be a strict cap.
Not verified
- No commands, build, or tests were run; the reported Windows 11 test results are author-provided.
core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppwas read around the changed lines. Full text was excluded as too large. All other changed files listed in the manifest had full text available; targeted ranges were read forcore/shader/recompiler/Recompiler.cpp,core/shader/recompiler/Recompiler.hpp,core/libs/prx/libSceAgcDriver/tests/cmake/agc_shader_memory_tests.cmake, anddocs/dev/ENVIRONMENT.md.- No title performance measurements were provided; the description says performance was not measured in a title.
To get this to a good state
Nothing is required. Optional points: validate and saturate the budget parsing and make byte accounting overflow-safe.
|
NVIDIA run on Linux: the new Setup: RTX 3070 8 GB, NVIDIA 610.57.04, Ryzen 5 5600X, Debian 13 (kernel 6.12.115), GCC 13.3.0 Release, validation layer 1.4.335. Base is the merge-base 07336cc, head is 2a16f18.
Every Vulkan test's log selects the RTX 3070 and shows the layer inserted, none reports it missing, and no log has a AI-assisted: yes |
|
This pull request is labeled |
|
Head
Code.
Test gap. The PR changes
So The Probe: served words against a fresh rebuild. I made two local, uncommitted changes to the merged head:
The run covers 45 tests: all
All served words matched a fresh rebuild for the same input. The ring adds one hit each in Speed. There is no Existing runs. The author ran 16/16 on an RX 9070 (Windows, layer 1.4.363) and Doorriiaann ran on an RTX 3070. This run adds:
Negative control. I copied the PR's GPU.
The four tests marked CPU create no Vulkan instance: the change is CPU-side. Validation.
Host:
AI-assisted: yes |
… both release tests Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Speed capture: keep recently specialized SPIR-VSetup: Windows 11 (26300), AMD Radeon RX 9070, AMD proprietary driver 26.11.2 (LLPC), Ryzen 9 5950X, 32 GB. PPSA01317, Café scene, 3840x2160. Vulkan validation not loaded (speed captures).
Common environment:
Phase totals over the window (ms, from the summary line):
Result: no measurable difference in this window. The change is opt-in (default 0) and this scene did not show a gain from it. Read this with care: one run per side, no repeat, so run-to-run noise is unmeasured. The worst frame is 87 to 94 s in all four captures (cold compile of split callee parts at Café entry), so frame percentiles above p99 say nothing about this change. aps5-summary.jsonl lines
tools/trace_digest.py, `APS5_KEEP_SPECIALIZED_MIB` unset (first lines)237 frames over 13243.8 ms (no summary line found) Slowest frames (largest slices inside each, inclusive)
Persistent spikes (frame time above the fastest frame that separates it from a longer frame; one entry per stall, not per frame)
Threads (ms per frame)
tools/trace_digest.py, `APS5_KEEP_SPECIALIZED_MIB=1024` (first lines)250 frames over 14274.0 ms (no summary line found) Slowest frames (largest slices inside each, inclusive)
Persistent spikes (frame time above the fastest frame that separates it from a longer frame; one entry per stall, not per frame)
Threads (ms per frame)
AI-assisted: yes |
|
@Remi-Bon GCC on Linux stopped at the budget lambda: |
|
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.
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.
|
|
@Helldiverr @MarcZX10 Addressed in f560d7b (pushed before 845546c, thanks @oneandonlydean for the GCC return-type fix).
Not covered: the same |
|
Recheck of 845546c: the code and the new tests match the reply, but none of the shader-memory tests could run on this host, so the GPU part is not done. The budget parser, copied into a small program, rejects Remi-Bon, thanks for the update. Here is what this host could check, and what it could not. Not run on this hostWindows Defender removes
A run on another Windows host or on Linux would cover them. Read at the head
Budget parser (measured outside the tree)MarcZX10 first raised the budget edge cases. The lambda at
Inferred, not run
SpeedAs your reply says, the capture shows no measurable gain, and the PR is a memory and reuse change, not a speed claim. Speed was not measured here. Existing runs
Host
AI-assisted: yes |
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — comments
The review covers all four changed files at the pinned head; no blocking defect was verified, but the budget parser has an edge case worth fixing.
What I ran
Reviewed head 845546c98763dc3dbfcd54c6767767814c74fc2f. Read the prepared description, commits, manifest, and diff, plus the changed source files and targeted repository context using repo_read.py tools. No build or tests were run; test results in the description are author-reported.
Results
| Check | Result | Note |
|---|---|---|
| Source review | passed | Four changed files read |
| Build and tests | not run | Description reports 16/16 author-run tests |
Findings
Blocking
None.
Non-blocking
core/shader/recompiler/Recompiler.cpp:1131accepts a leading minus sign throughstrtoull; for example,-1parses as a very large unsigned value and is capped to the maximum budget. This contradicts the setting’s documented whole-number MiB budget and can unexpectedly retain a very large amount of SPIR-V. Reject a leading sign (and consider explicitly requiring decimal digits) before parsing.
Not verified
No build, tests, or physical-console measurement was performed. The author-reported test run and validation-layer output were not independently verified. core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp was read only at the changed regions; other unchanged portions were not reviewed. The full file texts for the other three changed files were present in the review bundle, but only changed regions and relevant context were read.
To get this to a good state
Nothing is required. Optional: reject signed values for APS5_KEEP_SPECIALIZED_MIB so malformed input cannot silently become the maximum budget.
What
A specialized module holds its SPIR-V words only weakly, so the words are freed with the module's last result. A variant specialized again soon after is rebuilt word for word. Split table call parts do this often, because their results are short-lived.
APS5_KEEP_SPECIALIZED_MIBsets a byte budget for a ring of the most recently specialized modules. The ring holds them strongly, so a re-materialization finds the words still alive. The default is 0, which keeps today's behaviour: unused words are released.Tested
ctest --test-dir build -R "specializ|recompiler|pipeline_cache|shader_memory|layer_specialization": 16/16 passed, withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1,VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validationandVK_LOADER_DEBUG=layer, validation layer from Vulkan SDK 1.4.363.1. The loader log showsInsert instance layer "VK_LAYER_KHRONOS_validation"and contains noVUID-.agc_shader_layer_specialization_keptruns the release test withAPS5_KEEP_SPECIALIZED_MIB=1and requires the released words to stay alive.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)🤖 Generated with Claude Code