fix(shader): leave the workgroup memory set out of a compute module's bindings #11951

Merged
BunnyFl merged 2 commits from upstream-pr/11951 into main 2026-11-02 13:35:24 +00:00
BunnyFl commented 2026-10-27 13:46:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-10-27T13:46:54Z.


What

A compute shader whose LDS plus 4 bytes is larger than the device's maxWorkgroupSharedMemoryBytes keeps its LDS in a storage buffer declared in descriptor set 1, binding 0 (WorkgroupMemoryDescriptorSet). buildSpecializedModule lists the binding number of every descriptor variable that remains after specialization and left out only the pixel function LDS set (set 2), so it listed that buffer as binding 0. DescriptorBindingBuilder::Select then looks the module's binding numbers up in the prepared plan, which holds only set 0. When the shader has guest buffers, set 0's binding 0 (Buffers) is there and the lookup succeeds by number. When it has none, the recompile fails with specialized module bindings disagree with the prepared plan.

This leaves the variables of WorkgroupMemoryDescriptorSet out for a GLCompute entry point, as the pixel function LDS set already is. Set 1 is also FragmentDescriptorSet, so pixel shaders keep listing their set 1 bindings.

Tested

Windows 11 (10.0.26200), WinLibs GCC 15.2.0 r7 (MinGW-w64 UCRT), Release, BUILD_TESTING=ON, on main 75f3702aed:

  • New case in agc_lds_lock_budget: a compute program with one image load, 16 dwords of LDS stored with ds_write_b32 and no buffers, compiled for a 64-byte shared memory limit. It checks that the program compiles, that its LDS is in device memory (workgroupMemoryDwords == 18) and that it was specialized. It passes in three runs; with only Recompiler.cpp put back to main's version, it fails in all three runs with specialized module bindings disagree with the prepared plan. The 12 existing cases pass in both. The runs set ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1 and VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation; the test only recompiles and creates no Vulkan device, so neither log has a VUID- line or a missing-layer message.
  • tools/check_conventions.py --base upstream/main passes.

Planet Zoo (PPSA18026 01.009.002), AMD Radeon RX 9070 XT (maxComputeSharedMemorySize 32768, driver 32.0.32015.7029):

  • main aborts before any frame with compute shader 0xb401f08800: specialized module bindings disagree with the prepared plan: 55 and 46 s in on 3fea2a937b, 49 s in on 8ff4baf534. That shader uses 8192 dwords of LDS and no buffers. Its request, saved with APS5_DUMP_SHADERS, fails the same way in agc_shader_replay with main's Recompiler.cpp and recompiles with this change (on 62b3ba2522 too), as do the other nine requests saved in that run.
  • With this change, on 8ff4baf534, the title no longer aborts there. In one run it showed the Frontier logo and the EULA screen (288 presents before a timed APS5_HANG_DUMP_SECS dump at 60 s). In two other 300 s runs its log stopped after about 80 s and 30 s, with 3 and 0 presents; that stop is not investigated here.

Rebased onto main 08a10d2253 (head 40775bc85a). main had added MeshWindowDescriptorSet to the same condition (6f79055a00); the rebased line keeps it next to this change's compute-only WorkgroupMemoryDescriptorSet. On that head, same machine and compiler (these runs did not set the Vulkan variables above):

  • agc_lds_lock_budget passes in three runs; with only Recompiler.cpp put back to main's version it fails in all three with LDS lock budget: specialized image program without buffers: ShaderRecompiler::Recompile: specialized module bindings disagree with the prepared plan.
  • tools/check_conventions.py --base upstream/main passes.
  • Planet Zoo, freshly converted with this build (AMD driver 26.10.1, 3840x2160): one unattended 180 s run with Cross pressed every 3 s presents steadily from 40 s on (about 59 presents per 10 s) and its last saved frame shows the EULA screen, with no disagree with the prepared plan line; the run stopped at the time cap, not by itself. The same title on main 99b571f879 aborted 49 s in with that error.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: PPSA18026 #11608
  • GPUs tested: AMD Radeon RX 9070 XT, driver 32.0.32015.7029, Windows 11 (title runs; the unit test does not use the GPU)
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5034971656 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11951). Originally posted by [BunnyFl](https://github.com/BunnyFl) on 2026-10-27T13:46:54Z. --- ### What A compute shader whose LDS plus 4 bytes is larger than the device's `maxWorkgroupSharedMemoryBytes` keeps its LDS in a storage buffer declared in descriptor set 1, binding 0 (`WorkgroupMemoryDescriptorSet`). `buildSpecializedModule` lists the binding number of every descriptor variable that remains after specialization and left out only the pixel function LDS set (set 2), so it listed that buffer as binding 0. `DescriptorBindingBuilder::Select` then looks the module's binding numbers up in the prepared plan, which holds only set 0. When the shader has guest buffers, set 0's binding 0 (`Buffers`) is there and the lookup succeeds by number. When it has none, the recompile fails with `specialized module bindings disagree with the prepared plan`. This leaves the variables of `WorkgroupMemoryDescriptorSet` out for a `GLCompute` entry point, as the pixel function LDS set already is. Set 1 is also `FragmentDescriptorSet`, so pixel shaders keep listing their set 1 bindings. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Windows 11 (10.0.26200), WinLibs GCC 15.2.0 r7 (MinGW-w64 UCRT), Release, `BUILD_TESTING=ON`, on `main` `75f3702aed`: - New case in `agc_lds_lock_budget`: a compute program with one image load, 16 dwords of LDS stored with `ds_write_b32` and no buffers, compiled for a 64-byte shared memory limit. It checks that the program compiles, that its LDS is in device memory (`workgroupMemoryDwords == 18`) and that it was specialized. It passes in three runs; with only `Recompiler.cpp` put back to `main`'s version, it fails in all three runs with `specialized module bindings disagree with the prepared plan`. The 12 existing cases pass in both. The runs set `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1` and `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`; the test only recompiles and creates no Vulkan device, so neither log has a `VUID-` line or a missing-layer message. - `tools/check_conventions.py --base upstream/main` passes. Planet Zoo (PPSA18026 01.009.002), AMD Radeon RX 9070 XT (`maxComputeSharedMemorySize` 32768, driver 32.0.32015.7029): - `main` aborts before any frame with `compute shader 0xb401f08800: specialized module bindings disagree with the prepared plan`: 55 and 46 s in on `3fea2a937b`, 49 s in on `8ff4baf534`. That shader uses 8192 dwords of LDS and no buffers. Its request, saved with `APS5_DUMP_SHADERS`, fails the same way in `agc_shader_replay` with `main`'s `Recompiler.cpp` and recompiles with this change (on `62b3ba2522` too), as do the other nine requests saved in that run. - With this change, on `8ff4baf534`, the title no longer aborts there. In one run it showed the Frontier logo and the EULA screen (288 presents before a timed `APS5_HANG_DUMP_SECS` dump at 60 s). In two other 300 s runs its log stopped after about 80 s and 30 s, with 3 and 0 presents; that stop is not investigated here. Rebased onto `main` `08a10d2253` (head `40775bc85a`). `main` had added `MeshWindowDescriptorSet` to the same condition (6f79055a00); the rebased line keeps it next to this change's compute-only `WorkgroupMemoryDescriptorSet`. On that head, same machine and compiler (these runs did not set the Vulkan variables above): - `agc_lds_lock_budget` passes in three runs; with only `Recompiler.cpp` put back to `main`'s version it fails in all three with `LDS lock budget: specialized image program without buffers: ShaderRecompiler::Recompile: specialized module bindings disagree with the prepared plan`. - `tools/check_conventions.py --base upstream/main` passes. - Planet Zoo, freshly converted with this build (AMD driver 26.10.1, 3840x2160): one unattended 180 s run with Cross pressed every 3 s presents steadily from 40 s on (about 59 presents per 10 s) and its last saved frame shows the EULA screen, with no `disagree with the prepared plan` line; the run stopped at the time cap, not by itself. The same title on `main` `99b571f879` aborted 49 s in with that error. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: PPSA18026 #11608 - [x] GPUs tested: AMD Radeon RX 9070 XT, driver 32.0.32015.7029, Windows 11 (title runs; the unit test does not use the GPU) - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Sign in to join this conversation.
No reviewers
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!11951
No description provided.