fix(shader): release bundled optimizer traversal maps #4402
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4402"
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 jakezwang on 2026-10-12T09:29:45Z.
What
Related to #4166. The bundled SPIRV-Tools redundancy-elimination pass retains every processed dominator block's value map until the entire traversal finishes. A deep chain with a growing value table accumulates obsolete map copies.
Apply the fix from SPIRV-Tools #6962 during the bundled build: copy inherited maps to earlier children, move the map into the final child, then clear the processed state. Optimization order and sibling state stay intact. The generated source matches the upstream patch, with native line endings.
This follows the existing
PatchLibAtrac9.cmakeapproach. The helper writes one source file in the build directory and replaces the original target source exactly once. It leaves the submodule clean, tracks upstream source changes for reconfiguration, and refuses unexpected traversal code or target layout. The helper is included in the shader-cache source manifest. Technical debt records when to remove the patch.ANYPS5_USE_SYSTEM_DEPS=ONbuilds require the fix in their installed package. This change is independent of #4288, which bounds scalar replacement; it does not edit the optimizer pipeline.Tested
Ubuntu 24.04 Docker, linux/amd64 under emulation on an Apple Silicon host, GCC 13.3, Release,
ANYPS5_ENABLE_SPIRV_TOOLS=ON:cmake --build /tmp/anyps5-build --parallel 4.python3 tools/check_conventions.py --base origin/mainandgit diff --checkpass.Windows x64 (build 26300), WinLibs GCC 15.2.0, CMake 3.31.8, Release, NVIDIA GeForce RTX 5070 Ti Laptop GPU (12 GB), driver 617.14; tested commit
09c0fa5daf51c2284ae282b0eca84d479e0996dawith the bundled optimizer enabled:agc_spirv_optimizer_tests,agc_spirv13_image_tests,agc_spirv_narrow_constant_store_tests,agc_driver_constant_store_tests, andagc_compute_pipeline_replay_testsand their dependencies.ANYPS5_GPU=RTX 5070 Ti,ANYPS5_REQUIRE_VULKAN=1, andANYPS5_NO_SHADER_CACHE=1were set. Logs name the NVIDIA device and confirm all three readback checks plus normal/captured compute-output verification.No title or console hardware was exercised. The original Demon's Souls report remains unconfirmed; this PR fixes the reproduced optimizer allocation pattern without claiming to resolve every cause of #4166.
Checklist
main; no other open PR implements the same functions.mdfiles or images added to the repositoryImported from boykopovar/AnyPS5. Originally posted by Mouhand-Kaddo on 2026-10-12T11:13:33Z.
Tested head
09c0fa5dafon native Linux (i7-13700K, RX6900XT, RADV Mesa26.2.4), integrated with public mainc36fd0a0and the existing #757/#758/#4288/#3991 candidate stack plus two local shader fixes. This is combined integration evidence, not a clean PR-branch title run.The patch builds runtime libs and the optimizer/resource targets. Default agc_spirv_optimizer, agc_shader_memory and agc_shader_bindless all pass (3/3). Independent readback confirms the generated redundancy source is byte-identical to upstream #6962; the original pinned source remains read-only and unchanged.
A native standalone redundancy-pass diagnostic uses a valid4096-block dominator chain with duplicate additions, preserving an observable final output. Five interleaved fresh processes per version use the same compiler, input, core archive and optimizer objects; the control changes only the redundancy object back to its pre-patch build object. Median peak RSS is401.48MiB control versus20.60MiB patched (ranges401.0-401.7 and20.35-20.80MiB). All ten optimized binaries validate, retain exactly4096 additions, and are byte-identical. The pass is also faster in this synthetic case, but that is not a title-FPS result.
A separate90-second Demon's Souls diagnostic before this patch confirms actual GPU work (per-process graphics-engine counter advances10.8seconds; whole-device busy0-99%). CPU dispatch counters show substantial recompilation: one interval's seven dispatches spend10.304seconds total with1.471seconds average recompile, while debugger stacks include RedundancyEliminationPass map allocation/destruction. There is no sampled memory-pressure/OOM event in that profile. A prior longer run reached the language-selection screen; responsive main-menu success remains unverified. The post-patch title run is next, with no game-speedup claim yet.
No validation or fault handling was disabled. Testing performed with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by Mouhand-Kaddo on 2026-10-12T12:20:57Z.
Linux follow-up for the tested head
09c0fa5daf51c2284ae282b0eca84d479e0996da. 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 controlled optimizer probe retained byte-identical valid output while reducing synthetic peak RSS from about 401.5 MiB to 20.6 MiB. That is synthetic-pass evidence, not a game FPS or isolated title-memory measurement.
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:08Z.
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:20:00Z.
Does this change the growth in #4166? The 437.80 → 43.83 MiB figure is for a synthetic 4,096-operation shader; please measure peak RSS for a shader compile from a title on main and on main plus this PR alone. Without that I'd wait for SPIRV-Tools #6962 to merge and bump the submodule instead of carrying the patch.
Imported from boykopovar/AnyPS5. Originally posted by jakezwang on 2026-10-13T04:14:13Z.
Measured genuine PS5 title shaders on clean main
6124bf063f6348e4451ad0b9c67f82acec5bc1c2versus that same main with only this PR's patch (09c0fa5daf51c2284ae282b0eca84d479e0996da) applied.The title is Middle Ages Ping Pong / MedievalTennis, PPSA28319 v01.000.000, from the author's public release. Its archive SHA256 matches the catalog entry:
6426468091b42f6512a456004e47a0807ae83fc2af82a4408bef8a51103fbd48. I extracted unchanged embedded AGC code/header bytes and their compute-register metadata, then called main's actualRecompilewith the default optimizer. The zero-user-data/no-guest-memory offline protocol follows #3271.Both builds were screened on all 250 unique compute shaders: 182 validated successes and the same 68 unresolved indirect-call failures. Every successful SPIR-V output and serialized request is byte-identical across the two builds; all failure diagnostics also match.
Three cases were selected from the main screen alone: highest peak RSS, largest raw code and largest compiled output. Each had one excluded warm-up per version followed by five interleaved fresh processes per version. The table gives peak RSS in MiB, median [min–max]:
shader_01cec600(highest main RSS)shader_01cfaa00(largest raw code)shader_01d02900(largest output)All 30 measured outputs additionally passed standalone Vulkan 1.1 validation and matched byte for byte. Primary
ru_maxrssis sampled immediately afterRecompile, before the harness's additional validation and output writing; it includes process startup, input loading and request serialization. Post-validation peak is recorded separately.Build controls: Ubuntu 24.04, GCC 13.3.0, Release
-O3 -DNDEBUG, identical pinned dependencies and the exact same runner object. Archive comparison found only the redundancy-elimination optimizer object changed, plus the expected eight-byte AnyPS5 cache-version constant; caching and result memoization are disabled. No #4288 or title-support patch stack was applied. The generated redundancy source matches upstream SPIRV-Tools #6962 exactly.Raw records, complete corpus outcomes, source/input hashes, build audit, extraction scripts and reproduction files are public. The portable fresh-Ubuntu recipe is supplied separately from the measured archived-library relink procedure and is explicitly marked as not yet executed end to end. Game/shader binaries are fetched from the author release by the extraction recipe rather than redistributed in that bundle.
This is offline compilation of actual title input on Linux AMD64 under Docker emulation on macOS ARM64, with fixed Vulkan 1.1/SPIR-V 1.3 capabilities, host subgroup 32 and the title header's guest wave size. It demonstrates a title-input compile peak-memory reduction. Demon's Souls #4166's sustained application-memory growth has not been directly retested; there is no gameplay or FPS claim.
AI-assisted extraction, benchmark harness, testing and reporting.