Ratchet & Clank: Rift Apart (PPSA01474): the compute shader whose s_swappc_b64 calls a computed target becomes a 2.5M-word SPIR-V module that RADV cannot compile (nir_opt_copy_prop_vars grows past 16 GB; Mesa 25.2.8 and 26.2.6) #13538

Open
opened 2026-10-30 17:48:22 +00:00 by Tamalero · 0 comments
Tamalero commented 2026-10-30 17:48:22 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by Tamalero on 2026-10-30T17:48:22Z.


On AMD (RADV) Ratchet & Clank is OOM-killed about 4 minutes in, every time. It is not a leak in AnyPS5: the pipeline for one generated compute shader never finishes compiling, and Mesa's nir_opt_copy_prop_vars pass allocates about 330 MB/s until the process is killed. The module is 2,516,220 SPIR-V words and makes 7,279 helper calls, which Mesa inlines. Compiled on its own, outside the title, it reaches 16 GB in 44–47 s on both Mesa 25.2.8 and 26.2.6. The same build plays past this point on an RTX 4090 (NVIDIA proprietary driver). Related: #3274 (the s_swappc_b64 through a per-lane function table in Ratchet, most likely this shader), #12089 (Mafia, an 873k-word compute pipeline that takes 37 s on AMD).

What happens

The frame counter stops at about frame 600 and the process's anonymous memory grows about 330 MB/s from then on (guest direct memory stays flat at about 9.8 GB) until the cgroup limit kills it: 244–252 s at a 52 GB limit, 187 s at 36 GB. dmesg shows only the cgroup OOM kill: no ring timeout, no GPU reset. The shader is the compute program whose s_swappc_b64 calls a computed target (its address changes from run to run; 0x116bb5a200 in this run, with APS5_PROFILE_DRAW=1):

[Shaders/ShaderRegistry.cpp:1249 operator()] Shader 0x116bb5a200 could not be prepared at registration (its s_swappc_b64 at program counter 0x1ac4 calls a computed target); preparing it when it is used
[gpu] compute shader 0x116bb5a200 recompile took 980 ms (2516220 SPIR-V words, 357455 captured regions, total 1.8 s)
[dispatch] creating a pipeline for 2516220 SPIR-V words (program 0x116bb5a200)

No created a pipeline line follows. The registration line (with program counter 0x1ac4) appears in all 9 runs that reached the memory growth (7 OOM-killed, 2 stopped under gdb). It does not appear in the 3 runs that survived (APS5_NO_HOST_IMPORT=1, or APS5_HOST_IMPORT_MIB=2048): in those, stores fail with deferred write-back failed: BDA access failed … read-only in the BDA table and the title never reaches that dispatch, so they say nothing about the shader.

Title, test or build step

Ratchet & Clank: Rift Apart (PPSA01474) 01.005.003, cold shader cache.

AnyPS5 commit

main bb04a4f1ea with #9749, #10906 and #10000 merged (needed to get this far), plus local, environment-gated audio and dispatch-skip changes that are not pushed. The emitter files involved (SpirvRuntimeBuffer.cpp, SpirvBdaRead.cpp, SpirvBdaFault.cpp) and ResourceTracker.cpp's TakeGpuDescriptor are unchanged by those PRs and on current main (223b19ba0a). I have not rerun the title on current main.

System

Ubuntu 24.04.5, kernel 7.0.0-38, AMD Radeon Pro V620 (NAVI21, RDNA2, passed through to a VM), AMD EPYC 7452 (24 vCPUs). RADV from Ubuntu's Mesa 25.2.8, and Mesa 26.2.6 built from the release tarball (RADV only, no LLVM).

What was checked

Where the time goes. gdb on the running title with Ubuntu's debug symbols (debuginfod), and again on the standalone compile with Mesa 26.2.6, shows the same pass, already in the first nir_opt_copy_prop_vars call of radv_shader_spirv_to_nir:

Mesa 25.2.8, in the title:
nir_compare_deref_paths ← lookup_entry_and_kill_aliases(_copy_array) ← invalidate_copies_for_cf_node ← copy_prop_vars_cf_node (recursive)

Mesa 26.2.6, standalone, 10 s (4.6 GB):
_mesa_hash_table_insert_pre_hashed ← gather_vars_written ×116 ← nir_copy_prop_vars_impl ← nir_opt_copy_prop_vars ← radv_shader_spirv_to_nir ← radv_compile_cs
Mesa 26.2.6, standalone, 32 s (11.2 GB):
reralloc_size ← … ← copy_prop_vars_cf_node ×157 ← nir_copy_prop_vars_impl ← nir_opt_copy_prop_vars ← radv_shader_spirv_to_nir ← radv_compile_cs

The module. Caught with MESA_SPIRV_DUMP_PATH as memory started to grow: GLCompute, 2,516,220 words. main alone has 45,152 blocks (16k selection merges, 340 loops, 18k phis) and makes 7,279 calls into 25 helpers:

Helper Calls Blocks each
record_bda_fault 4,670 5
read_bda_span_stop 1,917 29
load_formatted_gpu_buffer_x1…x4 597 108 (about 11.4k words each)
get_bda_pointer 20

Mesa inlines every SPIR-V function before this pass (the FunctionControlDontInlineMask that formattedGpuCall sets does not survive into NIR), so RADV works on roughly 190k blocks. The formatted loads come from formattedDispatch → formattedGpuCall: the V# is chosen at run time (TakeGpuDescriptor sets gpuDescriptor) and its format word is not an immediate, so every load goes through the full formatSwitch. The other module captured in the same run (70 KB) compiles in 0.1–0.2 s.

Standalone repro, with the dumped module in a small vkCreateComputePipelines harness (reflected layout, MESA_SHADER_CACHE_DISABLE=true, 16 GB cgroup limit):

Mesa Result
25.2.8 (Ubuntu) RSS 7 GB at 21 s, 14 GB at 41 s, killed at 16 GB at 47 s
26.2.6 RSS 4.7 GB at 10 s, 10.6 GB at 30 s, killed at 16 GB at 44 s

In the title on Mesa 26.2.6 (same build, cold cache, 52 GB limit): the same course. The program counter 0x1ac4 shader is prepared at use, the frame counter stops at 600 about 106 s in, anonymous memory grows about 295 MB/s, and the cgroup kills the process at 249 s (25.2.8: 244–252 s).

Settings that do not move it (one per run, 52 GB limit): APS5_NO_PIPELINE_LTO=1 (OOM 252 s), APS5_NO_GPL=1 (252 s), APS5_TEXTURE_CACHE_MIB=2048 (251 s), a warm shader cache (222 s). APS5_NO_TEXTURE_CACHE=1 only delays it (542 s, reaching the same point later).

What I don't know

I don't know whether this is mainly a Mesa problem (the pass scaling badly with nesting depth and inlined call count) or one AnyPS5 should avoid by emitting less for this shader; with 26.2.6 behaving the same, a Mesa fix would not help current distributions anyway. Shrinking the module seems the practical side: fewer formatSwitch copies per dispatch (for example one call site per distinct V#, or a format resolved once per descriptor), or fewer inlined fault sites, as discussed in #2972. Factoring into more DontInline functions, as suggested in #12089, would not help on RADV, because Mesa inlines them. I have not tried any of these.

The SPIR-V module and the dumped request are game-derived, so I can't attach them; I can run any build or diagnostic patch against them on this machine and report numbers.

Tested and written by Claude (AI assistant) on a contributor's machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:6124183423 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/13538). Originally posted by [Tamalero](https://github.com/Tamalero) on 2026-10-30T17:48:22Z. --- On AMD (RADV) Ratchet & Clank is OOM-killed about 4 minutes in, every time. It is not a leak in AnyPS5: the pipeline for one generated compute shader never finishes compiling, and Mesa's `nir_opt_copy_prop_vars` pass allocates about 330 MB/s until the process is killed. The module is 2,516,220 SPIR-V words and makes 7,279 helper calls, which Mesa inlines. Compiled on its own, outside the title, it reaches 16 GB in 44–47 s on both Mesa 25.2.8 and 26.2.6. The same build plays past this point on an RTX 4090 (NVIDIA proprietary driver). Related: #3274 (the `s_swappc_b64` through a per-lane function table in Ratchet, most likely this shader), #12089 (Mafia, an 873k-word compute pipeline that takes 37 s on AMD). ### What happens The frame counter stops at about frame 600 and the process's anonymous memory grows about 330 MB/s from then on (guest direct memory stays flat at about 9.8 GB) until the cgroup limit kills it: 244–252 s at a 52 GB limit, 187 s at 36 GB. `dmesg` shows only the cgroup OOM kill: no ring timeout, no GPU reset. The shader is the compute program whose `s_swappc_b64` calls a computed target (its address changes from run to run; `0x116bb5a200` in this run, with `APS5_PROFILE_DRAW=1`): ``` [Shaders/ShaderRegistry.cpp:1249 operator()] Shader 0x116bb5a200 could not be prepared at registration (its s_swappc_b64 at program counter 0x1ac4 calls a computed target); preparing it when it is used [gpu] compute shader 0x116bb5a200 recompile took 980 ms (2516220 SPIR-V words, 357455 captured regions, total 1.8 s) [dispatch] creating a pipeline for 2516220 SPIR-V words (program 0x116bb5a200) ``` No `created a pipeline` line follows. The registration line (with program counter `0x1ac4`) appears in all 9 runs that reached the memory growth (7 OOM-killed, 2 stopped under gdb). It does not appear in the 3 runs that survived (`APS5_NO_HOST_IMPORT=1`, or `APS5_HOST_IMPORT_MIB=2048`): in those, stores fail with `deferred write-back failed: BDA access failed … read-only in the BDA table` and the title never reaches that dispatch, so they say nothing about the shader. ### Title, test or build step Ratchet & Clank: Rift Apart (PPSA01474) 01.005.003, cold shader cache. ### AnyPS5 commit `main` `bb04a4f1ea` with #9749, #10906 and #10000 merged (needed to get this far), plus local, environment-gated audio and dispatch-skip changes that are not pushed. The emitter files involved (`SpirvRuntimeBuffer.cpp`, `SpirvBdaRead.cpp`, `SpirvBdaFault.cpp`) and `ResourceTracker.cpp`'s `TakeGpuDescriptor` are unchanged by those PRs and on current `main` (`223b19ba0a`). I have not rerun the title on current `main`. ### System Ubuntu 24.04.5, kernel 7.0.0-38, AMD Radeon Pro V620 (NAVI21, RDNA2, passed through to a VM), AMD EPYC 7452 (24 vCPUs). RADV from Ubuntu's Mesa 25.2.8, and Mesa 26.2.6 built from the release tarball (RADV only, no LLVM). ### What was checked **Where the time goes.** gdb on the running title with Ubuntu's debug symbols (debuginfod), and again on the standalone compile with Mesa 26.2.6, shows the same pass, already in the first `nir_opt_copy_prop_vars` call of `radv_shader_spirv_to_nir`: ``` Mesa 25.2.8, in the title: nir_compare_deref_paths ← lookup_entry_and_kill_aliases(_copy_array) ← invalidate_copies_for_cf_node ← copy_prop_vars_cf_node (recursive) Mesa 26.2.6, standalone, 10 s (4.6 GB): _mesa_hash_table_insert_pre_hashed ← gather_vars_written ×116 ← nir_copy_prop_vars_impl ← nir_opt_copy_prop_vars ← radv_shader_spirv_to_nir ← radv_compile_cs Mesa 26.2.6, standalone, 32 s (11.2 GB): reralloc_size ← … ← copy_prop_vars_cf_node ×157 ← nir_copy_prop_vars_impl ← nir_opt_copy_prop_vars ← radv_shader_spirv_to_nir ← radv_compile_cs ``` **The module.** Caught with `MESA_SPIRV_DUMP_PATH` as memory started to grow: GLCompute, 2,516,220 words. `main` alone has 45,152 blocks (16k selection merges, 340 loops, 18k phis) and makes 7,279 calls into 25 helpers: | Helper | Calls | Blocks each | |---|---:|---:| | `record_bda_fault` | 4,670 | 5 | | `read_bda_span_stop` | 1,917 | 29 | | `load_formatted_gpu_buffer_x1…x4` | 597 | 108 (about 11.4k words each) | | `get_bda_pointer` | 20 | | Mesa inlines every SPIR-V function before this pass (the `FunctionControlDontInlineMask` that `formattedGpuCall` sets does not survive into NIR), so RADV works on roughly 190k blocks. The formatted loads come from `formattedDispatch` → `formattedGpuCall`: the V# is chosen at run time (`TakeGpuDescriptor` sets `gpuDescriptor`) and its format word is not an immediate, so every load goes through the full `formatSwitch`. The other module captured in the same run (70 KB) compiles in 0.1–0.2 s. **Standalone repro**, with the dumped module in a small `vkCreateComputePipelines` harness (reflected layout, `MESA_SHADER_CACHE_DISABLE=true`, 16 GB cgroup limit): | Mesa | Result | |---|---| | 25.2.8 (Ubuntu) | RSS 7 GB at 21 s, 14 GB at 41 s, killed at 16 GB at 47 s | | 26.2.6 | RSS 4.7 GB at 10 s, 10.6 GB at 30 s, killed at 16 GB at 44 s | **In the title on Mesa 26.2.6** (same build, cold cache, 52 GB limit): the same course. The program counter `0x1ac4` shader is prepared at use, the frame counter stops at 600 about 106 s in, anonymous memory grows about 295 MB/s, and the cgroup kills the process at 249 s (25.2.8: 244–252 s). **Settings that do not move it** (one per run, 52 GB limit): `APS5_NO_PIPELINE_LTO=1` (OOM 252 s), `APS5_NO_GPL=1` (252 s), `APS5_TEXTURE_CACHE_MIB=2048` (251 s), a warm shader cache (222 s). `APS5_NO_TEXTURE_CACHE=1` only delays it (542 s, reaching the same point later). ### What I don't know I don't know whether this is mainly a Mesa problem (the pass scaling badly with nesting depth and inlined call count) or one AnyPS5 should avoid by emitting less for this shader; with 26.2.6 behaving the same, a Mesa fix would not help current distributions anyway. Shrinking the module seems the practical side: fewer `formatSwitch` copies per dispatch (for example one call site per distinct V#, or a format resolved once per descriptor), or fewer inlined fault sites, as discussed in #2972. Factoring into more `DontInline` functions, as suggested in #12089, would not help on RADV, because Mesa inlines them. I have not tried any of these. The SPIR-V module and the dumped request are game-derived, so I can't attach them; I can run any build or diagnostic patch against them on this machine and report numbers. *Tested and written by Claude (AI assistant) on a contributor's machine.*
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5#13538
No description provided.