feat(shader): enumerate bindless material keys behind a mask or a shifted selector #5820

Closed
simonbronk wants to merge 4 commits from upstream-pr/5820 into main
simonbronk commented 2026-10-14 12:27:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by simonbronk on 2026-10-14T12:27:20Z.


What

Onimusha: Way of the Sword (PPSA27836 01.000.001) has compute programs that read a T# from a 32768-entry table with 48-byte records, keyed through a material record:

key = M[readfirstlane(i) << 6 + offset] & 0x7fff      // s_lshl_b32, s_buffer_load_dword, s_and_b32
T#  = H[key * 0x30 + 16]                              // s_buffer_load_dwordx8

TryMakeTableImage recognised the material read only as a direct ReadConstBuffer at readfirstlane(i) * stride + offset. Here the selector is scaled by a shift and the key is masked, so the table fell back to binding every entry and the dispatch stopped:

what():  compute shader 0x21115dde00: bindless image table has 32768 entries (0 materials), limit 16

Now a ShiftLeftLogical32 selector gives the stride 1 << n, and a BitwiseAnd32 with an immediate around the material read is recorded as selectorMask, which resolveTableImage applies to each enumerated key. The shader still computes the key itself, so the masked value it searches for is the one enumerated. selectorMask is in the disk-cache plan encoding (format version 32). A debt entry lists what is still not recognised.

This carries #5620's two commits (records wider than 32 bytes), which this title also needs. Once #5620 is merged, a rebase drops them.

Tested

  • Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, Release, on main 0b97f8b9f with #5620:
    • full ctest -j 8 on the RTX 5070: 1142/1142 pass;
    • ctest -R "agc|shader|video_out" on the AMD iGPU: all pass except the three tests of #5271, which fail the same way on main on this GPU.
  • agc_shader_memory gains a case in verifyBindlessTable: the material program with s_lshl_b32 for the selector and s_and_b32 0x7fff on the key, with material keys 0x8001 and 0xffff8003. The plan records stride 16 and mask 0x7fff, the mapping holds keys 1 and 3, and it compiles. With main's ResourceTracker.cpp and ResourceMaterializer.cpp it fails (the shifted selector and the key mask were not recorded).
  • PPSA27836 on Windows (RTX 5070), on a local branch: main plus the start-up fixes in #5769, #5620, #5550, and ShaderInfo::MaxImages and RuntimeAbi::SampledHeapCapacity raised to 128 locally (#5720's limit stops it earlier otherwise). The compute program above prepares; the title stops next at a 1D T# in the same table sampled through a 2D-array image_sample_l.
  • python tools/check_conventions.py --base upstream/main: passes.

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 — not applicable
  • 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 — not applicable
  • Generic behaviour, not specific to one title
  • Depends on: #5620
  • Unblocks: PPSA27836 #5769 (the compute stop is reached with #5720's limit raised locally)
  • GPUs tested: NVIDIA GeForce RTX 5070, driver 617.42 (32.0.16.1742); AMD Radeon(TM) Graphics, Ryzen iGPU gfx1036, driver 32.0.21036.18; both Windows 11 Pro 26200
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4857852057 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5820). Originally posted by [simonbronk](https://github.com/simonbronk) on 2026-10-14T12:27:20Z. --- ### What Onimusha: Way of the Sword (PPSA27836 01.000.001) has compute programs that read a T# from a 32768-entry table with 48-byte records, keyed through a material record: ``` key = M[readfirstlane(i) << 6 + offset] & 0x7fff // s_lshl_b32, s_buffer_load_dword, s_and_b32 T# = H[key * 0x30 + 16] // s_buffer_load_dwordx8 ``` `TryMakeTableImage` recognised the material read only as a direct `ReadConstBuffer` at `readfirstlane(i) * stride + offset`. Here the selector is scaled by a shift and the key is masked, so the table fell back to binding every entry and the dispatch stopped: ``` what(): compute shader 0x21115dde00: bindless image table has 32768 entries (0 materials), limit 16 ``` Now a `ShiftLeftLogical32` selector gives the stride `1 << n`, and a `BitwiseAnd32` with an immediate around the material read is recorded as `selectorMask`, which `resolveTableImage` applies to each enumerated key. The shader still computes the key itself, so the masked value it searches for is the one enumerated. `selectorMask` is in the disk-cache plan encoding (format version 32). A debt entry lists what is still not recognised. This carries #5620's two commits (records wider than 32 bytes), which this title also needs. Once #5620 is merged, a rebase drops them. ### Tested - Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, Release, on `main` 0b97f8b9f with #5620: - full `ctest -j 8` on the RTX 5070: 1142/1142 pass; - `ctest -R "agc|shader|video_out"` on the AMD iGPU: all pass except the three tests of #5271, which fail the same way on `main` on this GPU. - `agc_shader_memory` gains a case in `verifyBindlessTable`: the material program with `s_lshl_b32` for the selector and `s_and_b32 0x7fff` on the key, with material keys `0x8001` and `0xffff8003`. The plan records stride 16 and mask `0x7fff`, the mapping holds keys 1 and 3, and it compiles. With `main`'s `ResourceTracker.cpp` and `ResourceMaterializer.cpp` it fails (`the shifted selector and the key mask were not recorded`). - PPSA27836 on Windows (RTX 5070), on a local branch: `main` plus the start-up fixes in #5769, #5620, #5550, and `ShaderInfo::MaxImages` and `RuntimeAbi::SampledHeapCapacity` raised to 128 locally (#5720's limit stops it earlier otherwise). The compute program above prepares; the title stops next at a 1D T# in the same table sampled through a 2D-array `image_sample_l`. - `python tools/check_conventions.py --base upstream/main`: passes. ### Checklist - [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 - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's technical debt file — not applicable - [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 — not applicable - [x] Generic behaviour, not specific to one title - [x] Depends on: #5620 - [x] Unblocks: PPSA27836 #5769 (the compute stop is reached with #5720's limit raised locally) - [x] GPUs tested: NVIDIA GeForce RTX 5070, driver 617.42 (32.0.16.1742); AMD Radeon(TM) Graphics, Ryzen iGPU gfx1036, driver 32.0.21036.18; both Windows 11 Pro 26200 - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
simonbronk commented 2026-10-14 12:46:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by simonbronk on 2026-10-14T12:46:30Z.


Rebased onto main cee9841b6 (after #5089 was reverted in #5824); the disk-cache format version is 32.

Tested again on Windows 11 Pro 26200 (RTX 5070 and the AMD gfx1036 iGPU): everything passes except

  • agc_shader_memory: #5188's verifyUniformTableImage (merged since) fails with the carried #5620 commits alone too; reported on #5620. This PR's own masked-material case passes.
  • check_main_sync: a Windows code-page issue in the tool's own test, unrelated to this change.
  • on the AMD iGPU only, the three tests of #5271, as on main.

AI-assisted: yes (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6168669883 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5820#issuecomment-6168669883). Originally posted by [simonbronk](https://github.com/simonbronk) on 2026-10-14T12:46:30Z. --- Rebased onto `main` cee9841b6 (after #5089 was reverted in #5824); the disk-cache format version is 32. Tested again on Windows 11 Pro 26200 (RTX 5070 and the AMD gfx1036 iGPU): everything passes except - `agc_shader_memory`: #5188's `verifyUniformTableImage` (merged since) fails with the carried #5620 commits alone too; reported on #5620. This PR's own masked-material case passes. - `check_main_sync`: a Windows code-page issue in the tool's own test, unrelated to this change. - on the AMD iGPU only, the three tests of #5271, as on `main`. AI-assisted: yes (Claude Code).
adriadam10 commented 2026-10-14 14:19:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T14:19:21Z.

Review: CHANGES_REQUESTED


The head does not build, so the new test and the rest of the suite could not run:

  • core/shader/recompiler/ShaderDiskCache.cpp:110: static_assert(sizeof(DescriptorSource) == 104, ...) fails. selectorMask makes IndirectImage 36 bytes (that assert at line 111 is updated, this one is not), so DescriptorSource grows too; update it together with the encoder.
  • This stacks on #5620, whose head has moved (ee9506603, a third commit that changes ResourceTracker.cpp and ShaderDiskCache). The two carried commits are the old ones and the branch conflicts with main. Once #5620 is merged, rebase onto main so only your commit stays, and re-run the tests after the rebase.
  • ShaderMemory.cpp:1132-1134: the new comment block; the repo keeps code comments for technical debt only.

The approach (shift gives stride 1 << n, an immediate AND recorded as selectorMask and applied to each enumerated key) looks right to me; I'll review the rest with the build once it compiles.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5519409405 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5820#pullrequestreview-5519409405). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-14T14:19:21Z. **Review:** CHANGES_REQUESTED --- The head does not build, so the new test and the rest of the suite could not run: - `core/shader/recompiler/ShaderDiskCache.cpp:110`: `static_assert(sizeof(DescriptorSource) == 104, ...)` fails. `selectorMask` makes `IndirectImage` 36 bytes (that assert at line 111 is updated, this one is not), so `DescriptorSource` grows too; update it together with the encoder. - This stacks on #5620, whose head has moved (`ee9506603`, a third commit that changes `ResourceTracker.cpp` and `ShaderDiskCache`). The two carried commits are the old ones and the branch conflicts with `main`. Once #5620 is merged, rebase onto `main` so only your commit stays, and re-run the tests after the rebase. - `ShaderMemory.cpp:1132-1134`: the new comment block; the repo keeps code comments for technical debt only. The approach (shift gives stride `1 << n`, an immediate AND recorded as `selectorMask` and applied to each enumerated key) looks right to me; I'll review the rest with the build once it compiles.
simonbronk commented 2026-10-14 14:46:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by simonbronk on 2026-10-14T14:46:12Z.


@adriadam10 thanks, fixed in 727387252:

  • ShaderDiskCache.cpp:110: sizeof(DescriptorSource) is 112 with the 36-byte IndirectImage (the optional grows to 40 and the struct pads to 8). The encoder already wrote selectorMask, so only the assert changes. FormatVersion stays 32, which also covers #5620's entryStride.
  • Rebuilt on main f3434892b with #5620's current head: fdbd6938b, 3093460c9 and ee9506603 cherry-picked, authorship kept, then this commit. The debt entry now sits next to the MODE entry on main.

Tested on Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, Release:

  • full ctest -j 8 on the RTX 5070: all pass except check_main_sync, which fails on a Windows code page and is unrelated. agc_shader_memory, including the masked-material case and #5188's verifyUniformTableImage, now passes with #5620's third commit;
  • ctest -R "agc|shader|video_out" on the AMD gfx1036 iGPU: all pass except the three tests of #5271, as on main there;
  • tools/check_conventions.py: passes.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6171078689 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5820#issuecomment-6171078689). Originally posted by [simonbronk](https://github.com/simonbronk) on 2026-10-14T14:46:12Z. --- @adriadam10 thanks, fixed in 727387252: - `ShaderDiskCache.cpp:110`: `sizeof(DescriptorSource)` is 112 with the 36-byte `IndirectImage` (the optional grows to 40 and the struct pads to 8). The encoder already wrote `selectorMask`, so only the assert changes. `FormatVersion` stays 32, which also covers #5620's `entryStride`. - Rebuilt on `main` f3434892b with #5620's current head: fdbd6938b, 3093460c9 and ee9506603 cherry-picked, authorship kept, then this commit. The debt entry now sits next to the MODE entry on `main`. Tested on Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, Release: - full `ctest -j 8` on the RTX 5070: all pass except `check_main_sync`, which fails on a Windows code page and is unrelated. `agc_shader_memory`, including the masked-material case and #5188's `verifyUniformTableImage`, now passes with #5620's third commit; - `ctest -R "agc|shader|video_out"` on the AMD gfx1036 iGPU: all pass except the three tests of #5271, as on `main` there; - `tools/check_conventions.py`: passes. AI-assisted (Claude Code).
simonbronk commented 2026-10-14 19:12:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by simonbronk on 2026-10-14T19:12:07Z.


Closing as superseded. #5620 was closed in favour of d9e47d1e9 and 34525fdf7 (#757, #758), which this PR built on. On main ed835aa76, Onimusha (PPSA27836) runs without this PR and shows none of the bindless or material-key errors it fixed (runs on #5720). @adriadam10 thanks for the review.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6176254010 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5820#issuecomment-6176254010). Originally posted by [simonbronk](https://github.com/simonbronk) on 2026-10-14T19:12:07Z. --- Closing as superseded. #5620 was closed in favour of `d9e47d1e9` and `34525fdf7` (#757, #758), which this PR built on. On `main` ed835aa76, Onimusha (PPSA27836) runs without this PR and shows none of the bindless or material-key errors it fixed (runs on #5720). @adriadam10 thanks for the review.

Pull request closed

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!5820
No description provided.