Shader recompilation with SPIRV-Tools optimization grows host memory by about 0.6 GiB/s (Demon's Souls, Linux) #4166
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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 btsouth on 2026-10-12T00:21:23Z.
On Linux, with
ANYPS5_ENABLE_SPIRV_TOOLS=ONand the default optimizer, Demon's Souls PPSA01342 v1.005 (US) grows to about 16.6 GiB in its first 26 s of start-up while it compiles shaders. WithAPS5_SPIRV_OPT=noneand nothing else changed, it stays near 3 GiB.Setup: main
bab7b328, Release, GCC 16.2.1, Arch Linux kernel 7.2.8, i7-14700F, RTX 4070 SUPER on driver 615.78.08, 31 GiB RAM. The process was pinned to 16 hardware threads (taskset -c 0-15). The default run had 181 modules in its shader cache from an earlier run; the other started with an empty cache.Resident plus swapped memory, sampled from
/proc/<pid>/smapsevery 5 s (MiB):APS5_SPIRV_OPT=noneAt 26 s in the default run, 15.0 GiB was in anonymous host mappings of 64 MiB or more and 1.3 GiB in anonymous host mappings between 2 and 64 MiB. Guest mappings below 64 GiB held 44 MiB and the direct memory memfd 10 MiB, so the growth is host-side. The 64 MiB mappings have the shape of glibc malloc arenas, but I haven't confirmed which allocations they hold. Left running, an earlier default run reached about 27.3 GiB (18.2 GiB resident plus 9.0 GiB swapped) after 6.5 minutes and about 740 compiled shaders.
This lines up with the slow optimized compile noted in #2552. As noted there,
APS5_SPIRV_OPT=nonestill optimizes specialized modules, so this compares the default against that switch, not against no optimization at all.Imported from boykopovar/AnyPS5. Originally posted by 014-code on 2026-10-12T04:52:10Z.
Implemented and opened PR #4288: https://github.com/boykopovar/AnyPS5/pull/4288
What I found:
What I changed:
How I verified it:
The regression module contains a storage-only narrow type so the custom AnyPS5 pipeline is exercised consistently even when the full switch is set. The explicit SPIRV-Tools RegisterPerformancePasses(true) path for ordinary modules remains intentionally unchanged; the fix targets AnyPS5's default/custom path reported by this issue.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-13T07:38:10Z.
#4402 is on main: the bundled SPIRV-Tools releases its traversal maps as it goes. Does host memory still grow at about 0.6 GiB/s with the optimizer on?
Imported from boykopovar/AnyPS5. Originally posted by btsouth on 2026-10-14T11:51:41Z.
The offline optimizer no longer runs away on the saved Demon's Souls modules with #4402. I have not rerun the game, so I cannot confirm the exact in-game 0.6 GiB/s start-up rate.
I rebuilt the default pipeline against the same bundled SPIRV-Tools pin, comparing main
2a2a3dc650(with #4402) against #4402's merge parentebf417a51c. One fresh process per module, one worker, 16 GiB memory cap, no swap, 120 s timeout:All completed runs passed input and final output validation. OOM peaks are sampled lower bounds, and wall times are from a shared devbox. These are the same saved inputs as the earlier pass-isolation test, generated by an older local patched recompiler build, not newly emitted current-main shaders. The offline runs do not reproduce the game's start-up ordering or concurrency.
#4402 fixes the reproduced traversal-map failure without #4288. #4288 still addresses a separate scalar-replacement expansion risk. The largest module here has no function-local arrays or structs to split, so this result does not establish whether that limit is needed for other shaders.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T18:45:58Z.
Thanks, that matches: #4402 stops the runaway. Closing; please reopen if host memory still grows like this at start-up in the game on current main.