fix(shader): bound SPIR-V scalar replacement #4288
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4288"
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 014-code on 2026-10-12T04:50:05Z.
What
CreateScalarReplacementPass(0)treats zero as unlimited. The default AnyPS5 SPIR-V pipeline registered that pass twice, allowing large function-scope arrays and nested composites to expand into an unbounded number of replacement variables while shaders were being optimized. This can cause excessive temporary IR growth during shader compilation.This changes both AnyPS5 registrations to a shared
ScalarReplacementLimitof 64. Smaller composites keep the existing scalar-replacement optimization; larger composites remain aggregate values instead of being expanded without a bound.64is a conservative power-of-two ceiling that preserves useful optimization for small composites while placing a predictable upper bound on per-composite expansion. It is an engineering guardrail, not a title-specific tuning result.The optimizer test now covers a valid 1,000-element function array passed through branching and a memory barrier. It validates the optimized result and bounds the resulting module size, so removing the limit regresses the test without requiring a GPU or a title dump.
This PR does not claim that scalar replacement is the root cause of #4166: no isolated title-level memory A/B measurement is available here. Accordingly, #4166 remains open.
Tested
Ubuntu 24.04 under WSL2, Release build, bundled SPIRV-Tools enabled:
cmake -S . -B build-wsl-4288 -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON -DANYPS5_ENABLE_SPIRV_TOOLS=ON.agc_spirv_optimizer_tests.ctest --test-dir build-wsl-4288 -R '^agc_spirv_optimizer$' --output-on-failure: passed (1/1).agc_spirv_optimizer_testswith the default optimizer,APS5_SPIRV_OPT=none, andAPS5_SPIRV_OPT=full: all passed.python tools/check_conventions.py --base d92a8dad390af1807cc91622b924252141816a5a --head HEAD --title 'fix(shader): bound SPIR-V scalar replacement': run against the updated PR body.git diff --check d92a8dad390af1807cc91622b924252141816a5a..HEAD: passed.No RTX 3080 or Demon’s Souls run was available here. The regression is exercised at the CPU-side optimizer boundary; no title-level memory improvement is claimed.
Checklist
main; no other open PR implements the scalar-replacement limitNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt (n/a).mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by Mouhand-Kaddo on 2026-10-12T09:34:45Z.
Tested the patch at
6589b8d1a9979514c546f4b87dbbd5b1c00538f8on Linux, rebased locally onto public mainc36fd0a0eb57c01866befd370c88329ca42df759, with SPIRV-Tools enabled.Applying only the new regression test to main gives:
After applying the production change,
agc_spirv_optimizer_testspasses with the default optimizer,APS5_SPIRV_OPT=full, andAPS5_SPIRV_OPT=none. The combined candidate build's registeredagc_spirv_optimizertest also passes.I am investigating Demon's Souls on an i7-13700K / RX 6900 XT, RADV Mesa 26.2.4. Main previously approached exhaustion of 31 GiB RAM and 8 GiB swap during startup, but I have not yet established a title-level memory improvement or main-menu success from this patch. Separate descriptor-table failures are currently being investigated before another game launch.
Testing performed with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by Mouhand-Kaddo on 2026-10-12T12:20:53Z.
Linux follow-up for the tested head
6589b8d1a9979514c546f4b87dbbd5b1c00538f8. Demon's Souls (PPSA01342) reached the main menu, with New Game and Settings visible in a native emulator frame and interaction confirmed by the user. Selecting New Game then produced a black screen; gameplay is not validated.This was a combined integration stack: public-main snapshot
c36fd0a0eb57c01866befd370c88329ca42df759, ported #757/#758, #4288, #3991, #4402, the descriptor-layout fix now in #4456, and a local split-descriptor-load correction. It is not an isolated success claim for this PR. The final menu run used GDB to investigate an earlierbuffer descriptor uses an unsupported typeabort. That earlier failure remains undiagnosed.The earlier failing-main/passing-fix scalar-replacement regression remains the isolated evidence for this PR. The title result below is a combined-stack result.
Reproduction detail: the title run temporarily raised Linux
udmabufsize_limit_mbfrom 64 to 2048 because larger GPU imports failed at the default limit. The user restored 64 afterward and readback confirmed it. Default shader optimization remained enabled. RX 6900 XT/RADV was receiving GPU work; CPU shader compilation was a major startup bottleneck. Game assets were accessed through an enforced read-only view of the Windows gaming drive, without copying the game or changing its inputs. Disposable test caches have now been removed. AI-assisted testing/report.Imported from boykopovar/AnyPS5. Originally posted by Mouhand-Kaddo on 2026-10-12T21:23:04Z.
Retest on Linux using updated #4456 head
4f5f6d671cdb0ffd3a9c43eedbdf03e433e80ebeas the integration base. Its six focused PR checks pass three times each; the previous null-shader-module mock failure is reproduced on its parent and fixed on this head.The title support stack remains #757/#758/#4288/#3991/#4402 plus the local grouped split-load correction. Five integration shader/graphics checks pass. Demon's Souls PPSA01342 rendered language/display settings and the online/offline prompt, then aborted with exit 134:
This run did not verify main menu. The earlier c36-based integration did reach it. I have not isolated which rebased-stack change causes the descriptor failure, so this is not a regression attribution to this PR. No memory guard/OOM event stopped the run. One brief debugger snapshot was taken during startup, then detached.
The temporary Linux udmabuf limit was again 2048 MiB for the title run and is now verified back at 64. Assets were read directly through an enforced read-only view of the Windows gaming drive, without copying the game. Original input hashes and timestamps are unchanged. AI-assisted testing/report.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-13T00:19:09Z.
Is there a measurement that scalar replacement is what grows memory in #4166? Mouhand-Kaddo's runs show the new test failing on main, but no title memory with and without the limit, so
Fixes #4166is still a guess. Please show the issue's memory table with and without the limit, or drop theFixesline so the issue stays open. And why 64?Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-13T05:21:12Z.
Needs a rebase: #4580 and #4600 are merged and this now conflicts with them in
core/libs/prx/libSceAgcDriver/tests/SpirvOptimizer.cpp.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T21:33:03Z.
The 10-13 questions are still open: is there a measurement that scalar replacement is what grows memory in #4166 (the issue's memory table with and without the limit), or else please drop the
Fixes #4166line; and why 64? It also still needs the rebase fortests/SpirvOptimizer.cppafter #4580 and #4600.Imported from boykopovar/AnyPS5. Originally posted by 014-code on 2026-10-15T07:01:09Z.
Pushed an updated revision at
6a880abf2866ca025ff167deb2b023e0eaf83277and rebased the PR onto currentmain(d92a8dad390af1807cc91622b924252141816a5a).Addressed the review points:
SpirvOptimizer.cpptest conflict introduced by #4580 and #4600.Fixes #4166. I do not have an isolated title-level memory A/B measurement proving that scalar replacement is the root cause of #4166, so that issue remains open.Validation on Ubuntu 24.04 under WSL2 with bundled SPIRV-Tools enabled:
agc_spirv_optimizer_testsbuilt successfully.agc_spirv_optimizer: passed (1/1).APS5_SPIRV_OPT=none, andAPS5_SPIRV_OPT=full.git diff --checkpassed.No RTX 3080 or Demon’s Souls run was performed, and no title-level memory improvement is claimed.
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T07:32:59Z.
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/SpirvOptimizer.cppL293Imported from boykopovar/AnyPS5. Originally posted by 014-code on 2026-10-15T07:54:21Z.
Thanks for flagging this. This is an insertion-point overlap in
core/libs/prx/libSceAgcDriver/tests/SpirvOptimizer.cpp, not a functional dependency or duplicate implementation.The two PRs are independent, so
Depends onremainsnone. If both are merged, the conflict can be resolved by retaining both test blocks and their respective calls; no production-code conflict is expected.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-17T00:41:24Z.
That answers 10-13 and 10-14:
Fixes #4166is gone, 64 is explained and the optimizer test conflict is resolved. The overlap with #6176 is only the test insertion point, soDepends on: nonestands. The Windowsguest_shader_linktimeout in the first CI run was the runner hang class (that test never reaches the optimizer); a rerun passed on Windows and Linux.