Recompiler: a pixel shader of LEGO Batman: Legacy of the Dark Knight (PPSA16833) binds more than 16 samplers and is refused ("shader sampler pairs exceed runtime heap capacity"), so a new game aborts; fix branch ready #6692

Closed
opened 2026-10-16 05:03:22 +00:00 by Tamalero · 1 comment
Tamalero commented 2026-10-16 05:03:22 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by Tamalero on 2026-10-16T05:03:22Z.


When a new game starts, LEGO Batman: Legacy of the Dark Knight compiles a pixel shader that binds more than 16 samplers directly (outside the sampler tables). The recompiler refuses it and the title aborts:

what():  shader 0x1325230000 stage 5: ShaderRecompiler::Recompile: shader sampler pairs exceed runtime heap capacity

The check is in BindingAllocator. Each sampler takes two heap entries, one per descriptor variant. RuntimeAbi::SamplerHeapCapacity is 32 entries, so at most 16 samplers fit. #1789 raised the sampled image heap for a similar Unreal shader, but the sampler heap kept its size.

Title: LEGO Batman: Legacy of the Dark Knight (PPSA16833 v01.010.000)
Where it stops: choosing New Game, while the first level loads, on main 5d9dcc42d plus the two changes that get it to the menu (#6688 and the #6447 Terms of Service change). Linux, RTX 4090. 1 of 1 run. The build also carried the #6564 input change, which doesn't touch shaders.

Fix

Branch: https://github.com/Tamalero/AnyPS5/tree/fix/shader-sampler-heap-32-samplers (one commit on 5d9dcc42d).

  • SamplerHeapCapacity goes from 32 to 64 entries, so up to 32 samplers fit.
  • The sampler metadata array is part of ShaderData, so ShaderData grows from 14528 to 16064 bytes (export mappings move from dword 3624 to 4008). That still fits the 16 KiB uniform buffer range every Vulkan device supports. The two layout asserts are updated.
  • RuntimeAbi::Version goes from 12 to 13. The shader cache keys include it, so shaders cached with the old layout are rebuilt instead of reused.
  • The overflow message now names the sampler count, so the next title over the limit says by how much.
  • agc_shader_device_profile checks that 20 and 32 samplers allocate (40 and 64 entries). With RuntimeAbi.hpp and BindingAllocator.cpp from main and the new test, it fails with "shader sampler pairs exceed runtime heap capacity" (negative check).

The driver's existing per-device clamp still applies (maxPerStageDescriptorSamplers and maxDescriptorSetSamplers in ShaderResources.cpp), so a device with a lower limit is still capped there.

Result on the title

Build New Game
main + the two menu changes aborts on the shader above
the same + the capacity change (local build, fresh shader cache) the level loads, and the first area plays: movement, objects smashed, studs collected, the character menu

The title run used a local build with the same capacity and layout changes as the branch, but without the version bump and the test, which came later; I used a separate, empty shader cache for it instead. I don't know the exact sampler count of 0x1325230000, because it fits now. It's more than 16 and at most 32.

Details
  • Linux (CachyOS), GCC, Release, BUILD_TESTING=ON, RTX 4090, i9-14900K. The title was relinked with --to-intel by the relinker at 5d9dcc42d.
  • ctest -R "agc_|shader|recompiler|spirv" -j 12: 601 of 604 pass. agc_driver_flip_stores_small_results and agc_driver_store_idle_results failed under load, and pass 3 of 3 alone. agc_driver_store_over_untracked fails 3 of 3 on this branch and also 3 of 3 on main 5d9dcc42d (Linux), so it predates this change; #6347 reports it on Windows.
  • tools/check_conventions.py --base origin/main passes.
  • Not tested: AMD, Intel, Windows, macOS.
  • I have fewer than 10 merged PRs, so this is an issue with the branch rather than a PR.

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

Video of map loading and gameplay:

o7ZJNCox84E
H4Ez64cP0_8

Image
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5878638724 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/6692). Originally posted by [Tamalero](https://github.com/Tamalero) on 2026-10-16T05:03:22Z. --- When a new game starts, LEGO Batman: Legacy of the Dark Knight compiles a pixel shader that binds more than 16 samplers directly (outside the sampler tables). The recompiler refuses it and the title aborts: ``` what(): shader 0x1325230000 stage 5: ShaderRecompiler::Recompile: shader sampler pairs exceed runtime heap capacity ``` The check is in `BindingAllocator`. Each sampler takes two heap entries, one per descriptor variant. `RuntimeAbi::SamplerHeapCapacity` is 32 entries, so at most 16 samplers fit. #1789 raised the sampled image heap for a similar Unreal shader, but the sampler heap kept its size. **Title:** LEGO Batman: Legacy of the Dark Knight (PPSA16833 v01.010.000) **Where it stops:** choosing New Game, while the first level loads, on `main` `5d9dcc42d` plus the two changes that get it to the menu (#6688 and the #6447 Terms of Service change). Linux, RTX 4090. 1 of 1 run. The build also carried the #6564 input change, which doesn't touch shaders. ### Fix Branch: https://github.com/Tamalero/AnyPS5/tree/fix/shader-sampler-heap-32-samplers (one commit on `5d9dcc42d`). - `SamplerHeapCapacity` goes from 32 to 64 entries, so up to 32 samplers fit. - The sampler metadata array is part of `ShaderData`, so `ShaderData` grows from 14528 to 16064 bytes (export mappings move from dword 3624 to 4008). That still fits the 16 KiB uniform buffer range every Vulkan device supports. The two layout asserts are updated. - `RuntimeAbi::Version` goes from 12 to 13. The shader cache keys include it, so shaders cached with the old layout are rebuilt instead of reused. - The overflow message now names the sampler count, so the next title over the limit says by how much. - `agc_shader_device_profile` checks that 20 and 32 samplers allocate (40 and 64 entries). With `RuntimeAbi.hpp` and `BindingAllocator.cpp` from `main` and the new test, it fails with "shader sampler pairs exceed runtime heap capacity" (negative check). The driver's existing per-device clamp still applies (`maxPerStageDescriptorSamplers` and `maxDescriptorSetSamplers` in `ShaderResources.cpp`), so a device with a lower limit is still capped there. ### Result on the title | Build | New Game | |---|---| | `main` + the two menu changes | aborts on the shader above | | the same + the capacity change (local build, fresh shader cache) | the level loads, and the first area plays: movement, objects smashed, studs collected, the character menu | The title run used a local build with the same capacity and layout changes as the branch, but without the version bump and the test, which came later; I used a separate, empty shader cache for it instead. I don't know the exact sampler count of `0x1325230000`, because it fits now. It's more than 16 and at most 32. <details><summary>Details</summary> - Linux (CachyOS), GCC, Release, `BUILD_TESTING=ON`, RTX 4090, i9-14900K. The title was relinked with `--to-intel` by the relinker at `5d9dcc42d`. - `ctest -R "agc_|shader|recompiler|spirv" -j 12`: 601 of 604 pass. `agc_driver_flip_stores_small_results` and `agc_driver_store_idle_results` failed under load, and pass 3 of 3 alone. `agc_driver_store_over_untracked` fails 3 of 3 on this branch and also 3 of 3 on `main` `5d9dcc42d` (Linux), so it predates this change; #6347 reports it on Windows. - `tools/check_conventions.py --base origin/main` passes. - Not tested: AMD, Intel, Windows, macOS. - I have fewer than 10 merged PRs, so this is an issue with the branch rather than a PR. </details> *Tested and written by Claude (AI assistant) on a contributor's machine.* Video of map loading and gameplay: [o7ZJNCox84E](https://www.youtube.com/watch?v=o7ZJNCox84E) [H4Ez64cP0_8](https://youtu.be/H4Ez64cP0_8) <img width="3075" height="1699" alt="Image" src="https://github.com/user-attachments/assets/59bbe886-30b0-4bdf-ac7c-4027ab7534c0" />
MarcZX10 commented 2026-10-16 05:12:15 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-16T05:12:15Z.


I opened PR #6699 carrying your commit unchanged and preserving its author metadata. Intake, eligibility, conventions and progress-report checks pass. The local GCC 12 build was blocked in unchanged SrtDescriptorEvaluation.cpp before the focused CTest could run; the test and LEGO Batman gameplay results in the PR description are your reported GCC 15/RTX 4090 results.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6208588139 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/6692#issuecomment-6208588139). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-16T05:12:15Z. --- I opened [PR #6699](https://github.com/boykopovar/AnyPS5/pull/6699) carrying your commit unchanged and preserving its author metadata. Intake, eligibility, conventions and progress-report checks pass. The local GCC 12 build was blocked in unchanged `SrtDescriptorEvaluation.cpp` before the focused CTest could run; the test and LEGO Batman gameplay results in the PR description are your reported GCC 15/RTX 4090 results.
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#6692
No description provided.