AGC: registered shaders keep decoded programs and resource plans resident; UFC 6 (PPSA23566) exhausts host memory on a 32 GB machine #6139

Closed
opened 2026-10-14 23:08:36 +00:00 by mcsilva-dev · 2 comments
mcsilva-dev commented 2026-10-14 23:08:36 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by mcsilva-dev on 2026-10-14T23:08:36Z.


What happens

EA SPORTS UFC 6 (PPSA23566, 01.004.000) registers thousands of shaders during start-up. On a 32 GB machine the process commit grows about 8 GB per minute until it ends with

FATAL: C++ exception St9bad_alloc raised on thread 12392 cannot be delivered: libSceAgcDriver.prx+0x3375f9 has no unwind data

raised in the shader recompiler (ShaderRecompiler::ValidateProgram, MaskedSelectEliminator::Eliminate, SpirvEmitter::Emit), about 570 s in, at roughly 80 GB of commit. The window stays black until then.

How it was measured

  • Process memory sampled every 15 s: commit rose 4 → 31 GB in the first two minutes, then about 2 GB every 15 s, with no plateau.
  • VirtualQueryEx over the process: the guest direct-memory reservations stay uncommitted; the growth is host heap segments (~16 MB NT heap segments, mostly zero-filled).
  • A temporary operator new/delete override in libSceAgcDriver counted live bytes per caller (blocks of 1 KB and up exactly, smaller ones sampled 1 in 64). libSceAgcDriver held about 31 GB live of 38 GB process commit.

The two holders

  1. RegisteredPreparation::decoded: 18.7 GB in 12,882 blocks from ShaderRecompiler::DecodeRdnaProgram. Every queued registration preparation keeps its decoded RDNA program (~1.5 MB; DecodeRdnaProgram reserves one RdnaInstruction per code word) while it waits in the background queue, although only PlanRegistered reads it (UnresolvableSwappcTarget). Releasing it before PlanRegistered returns removes this holder completely; I will open a pull request for that.
  2. Resource plans of registered shaders: ~10.5 GB allocated under ShaderDiskCache::DecodePlan, plus ~3 GB under IrValue::AddArgument. Each registered shader keeps its resource plan (~3 MB of IR) resident whether or not it is ever drawn. The title registers ~8,600 shaders before its first frame; ~200 are used up to the title screen.

Workaround tested locally

With holder 1 released, commit still grew from holder 2. As a local workaround I added a switch that sends every shader down the existing deferred path (prepared->deferred = true, no registration preparation), so it is prepared at first use. With both changes the process holds ~9.9 GB, stable, the title screen appears in ~30 s with a warm shader cache, and the main menu is reachable (~11 presents/s at the title screen).

The switch trades memory for first-use stalls, so it is probably not the right default. Would you prefer bounding the resident plans (dropping plans of shaders that were prepared but never drawn and reloading them from the disk cache), or another approach? I can work on it in that direction.

Setup

Windows 11 Pro, Intel i5-14600KF, 32 GB RAM + 38 GB page file, AMD Radeon RX 9070 XT, WinLibs GCC 15.2.0, Release + libs, ANYPS5_ENABLE_SPIRV_TOOLS=ON. Base main bebff8b0e; the same code is unchanged on current main. Bring-up thread: #5996.

AI-assisted: yes (Claude Code). The measurements are from runs on this machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5857150985 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/6139). Originally posted by [mcsilva-dev](https://github.com/mcsilva-dev) on 2026-10-14T23:08:36Z. --- ## What happens EA SPORTS UFC 6 (PPSA23566, 01.004.000) registers thousands of shaders during start-up. On a 32 GB machine the process commit grows about 8 GB per minute until it ends with ``` FATAL: C++ exception St9bad_alloc raised on thread 12392 cannot be delivered: libSceAgcDriver.prx+0x3375f9 has no unwind data ``` raised in the shader recompiler (`ShaderRecompiler::ValidateProgram`, `MaskedSelectEliminator::Eliminate`, `SpirvEmitter::Emit`), about 570 s in, at roughly 80 GB of commit. The window stays black until then. ## How it was measured - Process memory sampled every 15 s: commit rose 4 → 31 GB in the first two minutes, then about 2 GB every 15 s, with no plateau. - `VirtualQueryEx` over the process: the guest direct-memory reservations stay uncommitted; the growth is host heap segments (~16 MB NT heap segments, mostly zero-filled). - A temporary `operator new`/`delete` override in libSceAgcDriver counted live bytes per caller (blocks of 1 KB and up exactly, smaller ones sampled 1 in 64). libSceAgcDriver held about 31 GB live of 38 GB process commit. ## The two holders 1. **`RegisteredPreparation::decoded`: 18.7 GB in 12,882 blocks** from `ShaderRecompiler::DecodeRdnaProgram`. Every queued registration preparation keeps its decoded RDNA program (~1.5 MB; `DecodeRdnaProgram` reserves one `RdnaInstruction` per code word) while it waits in the background queue, although only `PlanRegistered` reads it (`UnresolvableSwappcTarget`). Releasing it before `PlanRegistered` returns removes this holder completely; I will open a pull request for that. 2. **Resource plans of registered shaders: ~10.5 GB** allocated under `ShaderDiskCache::DecodePlan`, plus ~3 GB under `IrValue::AddArgument`. Each registered shader keeps its resource plan (~3 MB of IR) resident whether or not it is ever drawn. The title registers ~8,600 shaders before its first frame; ~200 are used up to the title screen. ## Workaround tested locally With holder 1 released, commit still grew from holder 2. As a local workaround I added a switch that sends every shader down the existing deferred path (`prepared->deferred = true`, no registration preparation), so it is prepared at first use. With both changes the process holds **~9.9 GB, stable**, the title screen appears in ~30 s with a warm shader cache, and the main menu is reachable (~11 presents/s at the title screen). The switch trades memory for first-use stalls, so it is probably not the right default. Would you prefer bounding the resident plans (dropping plans of shaders that were prepared but never drawn and reloading them from the disk cache), or another approach? I can work on it in that direction. ## Setup Windows 11 Pro, Intel i5-14600KF, 32 GB RAM + 38 GB page file, AMD Radeon RX 9070 XT, WinLibs GCC 15.2.0, Release + libs, `ANYPS5_ENABLE_SPIRV_TOOLS=ON`. Base `main` bebff8b0e; the same code is unchanged on current `main`. Bring-up thread: #5996. AI-assisted: yes (Claude Code). The measurements are from runs on this machine.
mcsilva-dev commented 2026-10-15 02:26:56 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by mcsilva-dev on 2026-10-15T02:26:56Z.


Update: the UFC bring-up fork in #5996 (0xcrstn/AnyPS5 ufc6/testing, c222bd2c2) already addresses both holders, independently of this report, and is probably a better shape than my local switch:

  1. Decoded program. In PlanRegistered, decoded is a local; it moves into the plan only when the plan awaits callees (awaitsCallees), which reads it later (LinkUserDataCalls, FindUserDataCalls). So releasing it unconditionally, as I first did, would be wrong on that branch; keeping it local is the right fix.
  2. Resident plans. Registration preparation is admitted up to APS5_REGISTRATION_PREPARE_LIMIT and then only while the process commits less than APS5_REGISTRATION_PREPARE_COMMIT_GB (default: half of physical memory); past that, shaders take the deferred path. On this 32 GB machine the fork holds ~10.5 GB at the title screen, stable, with no local change, versus ~80 GB and std::bad_alloc on main.

Measured on the same machine (Windows 11, i5-14600KF, 32 GB, RX 9070 XT). Frame-time work on the same title is in #6197 and the progress report in #5996.

AI-assisted: yes (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6183003634 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/6139#issuecomment-6183003634). Originally posted by [mcsilva-dev](https://github.com/mcsilva-dev) on 2026-10-15T02:26:56Z. --- Update: the UFC bring-up fork in #5996 (`0xcrstn/AnyPS5` `ufc6/testing`, c222bd2c2) already addresses both holders, independently of this report, and is probably a better shape than my local switch: 1. **Decoded program.** In `PlanRegistered`, `decoded` is a local; it moves into the plan only when the plan awaits callees (`awaitsCallees`), which reads it later (`LinkUserDataCalls`, `FindUserDataCalls`). So releasing it unconditionally, as I first did, would be wrong on that branch; keeping it local is the right fix. 2. **Resident plans.** Registration preparation is admitted up to `APS5_REGISTRATION_PREPARE_LIMIT` and then only while the process commits less than `APS5_REGISTRATION_PREPARE_COMMIT_GB` (default: half of physical memory); past that, shaders take the deferred path. On this 32 GB machine the fork holds ~10.5 GB at the title screen, stable, with no local change, versus ~80 GB and `std::bad_alloc` on `main`. Measured on the same machine (Windows 11, i5-14600KF, 32 GB, RX 9070 XT). Frame-time work on the same title is in #6197 and the progress report in #5996. AI-assisted: yes (Claude Code).
nicolasabosch commented 2026-10-21 02:05:23 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by nicolasabosch on 2026-10-21T02:05:23Z.


Another data point for the fork in #5996 (0xcrstn/AnyPS5 ufc6/testing, c222bd2c2), on Intel + NVIDIA:

  • Windows 11 (26300), Intel Core i9-14900HX, 32 GB RAM, NVIDIA GeForce RTX 4070 Laptop GPU (8 GB), driver 616.92
  • Built with WinLibs GCC 15.2.0 r7; relinked with the fork's relinker: --windows --to-intel --windows-diagnostics --registry --module-dir . (with Engine.Render.Core2.PlatformPs5.prx beside eboot.elf, see #6336)
  • APS5_PIPELINE_COMPILE_AHEAD=1, APS5_PIPELINE_COMPILE_THREADS=4, APS5_THREAD_PRIORITY=high, APS5_PREPARE_PRIORITY=normal, APS5_PREPARE_THREADS=14

Memory: stable at ~10 GB once the shader cache is warm, as reported above. The first run after new content shows up is slow for a while: about 180 compute pipelines (75k–190k SPIR-V words) compiled one at a time, ~208 s in total. The next run reads them from the pipeline cache.

Frame rate:

Scene FPS
Title / "PRESS ANY BUTTON" ~20 (queue worker 0 at ~95%)
Same, with the local change below ~34–36
Intro cinematic after the first-run dialogs ~1.5–2.5, with or without the change

Title screen at ~20 FPS. About half of queue worker 0's time went to CPU storage uploads: ~1,550 per 10 s (~6.2 GB), each with a full sync (StorageTexture::upload → GuestMemory::ReadCommitted → Recorder::SyncThrough, then CommandBatch::Wait). Their refusal reason is not registered. The title remaps a pool at 0x11c0000000 in separate 8 MiB pieces, each a registered range, the host import window is also 8 MiB, and render targets that straddle a piece's edge fail runCovers. A local experiment that falls back to importJoined in importAccess for such accesses (as buffer accesses already do) brought CPU uploads to 0 and the title screen to ~35 FPS with no import churn (27 joined imports, none retired). It doesn't change the cinematic. Not submitted; happy to open a PR if this is the right direction.

Cinematic at ~2 FPS. It's an in-engine scene, not a movie: ~3,200 draws and ~85 GPU batches per frame. Queue worker 0 is at ~97%; the GPU reports ~1.2 s of work per 10 s ([gputime]). Per frame: Packet.draw ~350 ms and Packet.memory_wait ~280 ms. The draw recipe cache almost never applies: [recipe] draw shows ~100 hits against 20,000–27,000 no recipe per 10 s, because no recipe gets built. Counting the first failing condition of the recipe build in Graphics::Draw: ~85% !resolved.moved.empty() (a template hit whose read-only buffers moved; constants in a new ring-buffer slot every frame) and ~15% not cacheable. Allowing recipes with moved buffers (repeating MovedReadOnlyBuffers after ProveCurrent on a hit and passing them as record.moved) builds recipes, but they still match only 0.5–10% of draws. The stage variants are replaced each frame (Driver::cloneVariant from relocateDrawEntry), so DrawRecipeRecord::Matches never finds the old ones. No FPS change, so I'm not proposing that yet.

Dump note in case it helps others: a null dereference in a ConcurrentExecutor_global_0 job at exe+0x3f254cd, about 10 s after the first frame, was not an emulator bug. My dump was missing Data/Ps5/superbundlelayout/ufc_installpackage_02/cas_23–27, _03, _05, _06 and _07, all listed in app0/ampr_emu.index. The title gets ENOENT for ufc_installpackage_05/cas_01.cas and derefs an unbound resource slot. With the full dump it gets past that point.

AI-assisted: yes (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6306207015 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/6139#issuecomment-6306207015). Originally posted by [nicolasabosch](https://github.com/nicolasabosch) on 2026-10-21T02:05:23Z. --- Another data point for the fork in #5996 (`0xcrstn/AnyPS5` `ufc6/testing`, c222bd2c2), on Intel + NVIDIA: - Windows 11 (26300), Intel Core i9-14900HX, 32 GB RAM, NVIDIA GeForce RTX 4070 Laptop GPU (8 GB), driver 616.92 - Built with WinLibs GCC 15.2.0 r7; relinked with the fork's relinker: `--windows --to-intel --windows-diagnostics --registry --module-dir .` (with `Engine.Render.Core2.PlatformPs5.prx` beside `eboot.elf`, see #6336) - `APS5_PIPELINE_COMPILE_AHEAD=1`, `APS5_PIPELINE_COMPILE_THREADS=4`, `APS5_THREAD_PRIORITY=high`, `APS5_PREPARE_PRIORITY=normal`, `APS5_PREPARE_THREADS=14` **Memory:** stable at ~10 GB once the shader cache is warm, as reported above. The first run after new content shows up is slow for a while: about 180 compute pipelines (75k–190k SPIR-V words) compiled one at a time, ~208 s in total. The next run reads them from the pipeline cache. **Frame rate:** | Scene | FPS | |---|---| | Title / "PRESS ANY BUTTON" | ~20 (queue worker 0 at ~95%) | | Same, with the local change below | ~34–36 | | Intro cinematic after the first-run dialogs | **~1.5–2.5**, with or without the change | **Title screen at ~20 FPS.** About half of queue worker 0's time went to CPU storage uploads: ~1,550 per 10 s (~6.2 GB), each with a full sync (`StorageTexture::upload` → `GuestMemory::ReadCommitted` → `Recorder::SyncThrough`, then `CommandBatch::Wait`). Their refusal reason is `not registered`. The title remaps a pool at 0x11c0000000 in separate 8 MiB pieces, each a registered range, the host import window is also 8 MiB, and render targets that straddle a piece's edge fail `runCovers`. A local experiment that falls back to `importJoined` in `importAccess` for such accesses (as buffer accesses already do) brought CPU uploads to 0 and the title screen to ~35 FPS with no import churn (27 joined imports, none retired). It doesn't change the cinematic. Not submitted; happy to open a PR if this is the right direction. **Cinematic at ~2 FPS.** It's an in-engine scene, not a movie: ~3,200 draws and ~85 GPU batches per frame. Queue worker 0 is at ~97%; the GPU reports ~1.2 s of work per 10 s (`[gputime]`). Per frame: `Packet.draw` ~350 ms and `Packet.memory_wait` ~280 ms. The draw recipe cache almost never applies: `[recipe] draw` shows ~100 hits against 20,000–27,000 `no recipe` per 10 s, because no recipe gets built. Counting the first failing condition of the recipe build in `Graphics::Draw`: ~85% `!resolved.moved.empty()` (a template hit whose read-only buffers moved; constants in a new ring-buffer slot every frame) and ~15% not cacheable. Allowing recipes with moved buffers (repeating `MovedReadOnlyBuffers` after `ProveCurrent` on a hit and passing them as `record.moved`) builds recipes, but they still match only 0.5–10% of draws. The stage variants are replaced each frame (`Driver::cloneVariant` from `relocateDrawEntry`), so `DrawRecipeRecord::Matches` never finds the old ones. No FPS change, so I'm not proposing that yet. **Dump note in case it helps others:** a null dereference in a `ConcurrentExecutor_global_0` job at `exe+0x3f254cd`, about 10 s after the first frame, was not an emulator bug. My dump was missing `Data/Ps5/superbundlelayout/ufc_installpackage_02/cas_23–27`, `_03`, `_05`, `_06` and `_07`, all listed in `app0/ampr_emu.index`. The title gets ENOENT for `ufc_installpackage_05/cas_01.cas` and derefs an unbound resource slot. With the full dump it gets past that point. AI-assisted: yes (Claude Code).
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#6139
No description provided.