feat(recompiler): bindless image tables up to the device's sampled-image limit #1184

Closed
MichonGoddijn231849 wants to merge 5 commits from upstream-pr/1184 into main
MichonGoddijn231849 commented 2026-10-07 16:44:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-07T16:44:43Z.


What

A whole-table bindless image table binds its entries as one descriptor array, sized by the table (the next power of two, at least APS5_BINDLESS_SLOTS) up to the device's per-stage sampled-image limit, at most 65536. Before, tables wider than 48 slots were refused. The key indexes the array directly. GTA V's fidelity mode reads a 65536-entry T# heap from a compute pass.

  • A table binds the shape (numeric class, dimension, cube) of the access's group, not of its first entry. A 2D access whose table started with a cube or 3D texture sampled zeros for its 2D entries.
  • A table entry whose reads build more than one T# is planned for each of them. A heap offset (key * 32) & mask, with a contiguous mask keeping at least 16 key bits, matches like key * 32.
  • A table whose keys select nothing binds null descriptors and an empty mapping, so every key samples zeros, as on hardware.
  • A T# in a depth-comparison binding whose format no comparison can read binds a zero texture, as a null T# does.
  • SetBindlessTableLimit is reviewed for the shader disk cache key (it reaches the key through the specialization's table slots). The disk cache format version is 8.

tests/ShaderMemory.cpp covers the table planning cases.

Tested

Windows 11 Pro, AMD Ryzen 5 7600, NVIDIA GeForce RTX 5080 (driver 32.0.16.1074), 32 GB, MinGW-w64 GCC 15.2.0.

  • GTA V PPSA04264 (01.005) runs with this change on the combined gta-v/testing branch (Performance mode, the prologue).
  • On this branch: builds, and ctest passes. Not run here: the relinker's Python tests (my local Python does not find their helper modules) and guest_gameupdate.

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 in TechnicalDebt
  • 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: #293 (null texture descriptors, which the padded and empty tables bind)
  • AI-assisted: yes. Written with Claude (Anthropic) under my direction; I reviewed and tested it.

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4775679223 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1184). Originally posted by [MichonGoddijn231849](https://github.com/MichonGoddijn231849) on 2026-10-07T16:44:43Z. --- ### What A whole-table bindless image table binds its entries as one descriptor array, sized by the table (the next power of two, at least `APS5_BINDLESS_SLOTS`) up to the device's per-stage sampled-image limit, at most 65536. Before, tables wider than 48 slots were refused. The key indexes the array directly. GTA V's fidelity mode reads a 65536-entry T# heap from a compute pass. - A table binds the shape (numeric class, dimension, cube) of the access's group, not of its first entry. A 2D access whose table started with a cube or 3D texture sampled zeros for its 2D entries. - A table entry whose reads build more than one T# is planned for each of them. A heap offset `(key * 32) & mask`, with a contiguous mask keeping at least 16 key bits, matches like `key * 32`. - A table whose keys select nothing binds null descriptors and an empty mapping, so every key samples zeros, as on hardware. - A T# in a depth-comparison binding whose format no comparison can read binds a zero texture, as a null T# does. - `SetBindlessTableLimit` is reviewed for the shader disk cache key (it reaches the key through the specialization's table slots). The disk cache format version is 8. `tests/ShaderMemory.cpp` covers the table planning cases. ### Tested Windows 11 Pro, AMD Ryzen 5 7600, NVIDIA GeForce RTX 5080 (driver 32.0.16.1074), 32 GB, MinGW-w64 GCC 15.2.0. - GTA V PPSA04264 (01.005) runs with this change on the combined [`gta-v/testing`](https://github.com/MichonGoddijn231849/AnyPS5-fork/tree/gta-v/testing) branch (Performance mode, the prologue). - On this branch: builds, and `ctest` passes. Not run here: the relinker's Python tests (my local Python does not find their helper modules) and `guest_gameupdate`. ### 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](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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: #293 (null texture descriptors, which the padded and empty tables bind) - [x] AI-assisted: yes. Written with Claude (Anthropic) under my direction; I reviewed and tested it. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
fisherjoey commented 2026-10-08 08:41:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-08T08:41:47Z.


Test result: Demon's Souls on Linux/NVIDIA. Direct-index tables work; the material-selected table in this title still runs out of slots

Setup: Nobara 44 x86-64, RTX 5070 Ti, NVIDIA 595.91.07. Demon's Souls (PPSA01341 v1.07). Base is upstream main df16c4c2 plus #861, #864, #157, #1202 and our local fixes. This PR merged with conflicts in ResourceMaterializer.cpp/.hpp and the recompiler CMakeLists, all against our own bindless change, which this PR replaces. Driver ctest -j1: 413/414. The one failure (guest_force_tls_destructor) also fails on main.

Tutorial level with APS5_BINDLESS_SLOTS=48 (single run, cache format change, so the boot recompiled about 170 shaders): 2.20 fps against 2.10 and 1.70 without the PR. No new error signatures, and the picture is unchanged. So no regression on this title, but one run can't show a speedup.

Without APS5_BINDLESS_SLOTS, booting straight into the tutorial (FROM's debug start menu with a one-entry map list) still aborts:

compute shader 0x248946900: bindless image table: 60 distinct keys exceed the 16 slots

On our tree without the PR, the same boot with APS5_BINDLESS_SLOTS=48 fails on the same shader with 93 keys. As far as I can read the code, that table takes the material path (table.hasMaterial, material buffer small enough to scan). There the distinct keys are still capped by APS5_BINDLESS_SLOTS (default 16, clamped to 48), and only the direct-index path goes up to BindlessTableLimit(). Raising the material path's cap to the same device limit, or sizing it from keys.size(), would cover this shader. Through the normal menu route, 48 slots are enough for the tutorial level.

AI-assisted: yes (an agent ran the builds, the game runs and the measurements, and read the code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6056117532 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1184#issuecomment-6056117532). Originally posted by [fisherjoey](https://github.com/fisherjoey) on 2026-10-08T08:41:47Z. --- Test result: Demon's Souls on Linux/NVIDIA. Direct-index tables work; the material-selected table in this title still runs out of slots Setup: Nobara 44 x86-64, RTX 5070 Ti, NVIDIA 595.91.07. Demon's Souls (PPSA01341 v1.07). Base is upstream main df16c4c2 plus #861, #864, #157, #1202 and our local fixes. This PR merged with conflicts in ResourceMaterializer.cpp/.hpp and the recompiler CMakeLists, all against our own bindless change, which this PR replaces. Driver ctest -j1: 413/414. The one failure (guest_force_tls_destructor) also fails on main. Tutorial level with APS5_BINDLESS_SLOTS=48 (single run, cache format change, so the boot recompiled about 170 shaders): 2.20 fps against 2.10 and 1.70 without the PR. No new error signatures, and the picture is unchanged. So no regression on this title, but one run can't show a speedup. Without APS5_BINDLESS_SLOTS, booting straight into the tutorial (FROM's debug start menu with a one-entry map list) still aborts: ``` compute shader 0x248946900: bindless image table: 60 distinct keys exceed the 16 slots ``` On our tree without the PR, the same boot with APS5_BINDLESS_SLOTS=48 fails on the same shader with 93 keys. As far as I can read the code, that table takes the material path (`table.hasMaterial`, material buffer small enough to scan). There the distinct keys are still capped by `APS5_BINDLESS_SLOTS` (default 16, clamped to 48), and only the direct-index path goes up to `BindlessTableLimit()`. Raising the material path's cap to the same device limit, or sizing it from `keys.size()`, would cover this shader. Through the normal menu route, 48 slots are enough for the tutorial level. AI-assisted: yes (an agent ran the builds, the game runs and the measurements, and read the code).
MichonGoddijn231849 commented 2026-10-08 16:28:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-08T16:28:06Z.


Rebased onto main and onto the updated #293 (its own changes are now one commit). Adapting to what changed underneath:

  • nullTexture keeps #293's rule: without nullDescriptor, a comparison binding of a T# no comparison can read (all zero, or a format no comparison reads) throws instead of binding a zero texture. resourceTests in agc_driver_graphics checks the refusal names nullDescriptor and carries the dwords.
  • Descriptor pools: main now checks SetDescriptorLimit and gives a set that does not fit the chain pool a dedicated pool, so the chain-pool growth this PR had is gone; a large table set gets a dedicated pool sized for it.
  • The shader disk cache format is version 10 (main is at 9), and the Linux layout checks match the current structs.

@fisherjoey thanks for the Demon's Souls run. You read it right: the material-selected path (table.hasMaterial) still caps the distinct keys at APS5_BINDLESS_SLOTS (16, at most 48); only the direct-index path goes up to the device limit. Raising the material path changes how its slots are materialized, so I'll do it in a follow-up PR rather than grow this one.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6064389220 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1184#issuecomment-6064389220). Originally posted by [MichonGoddijn231849](https://github.com/MichonGoddijn231849) on 2026-10-08T16:28:06Z. --- Rebased onto main and onto the updated #293 (its own changes are now one commit). Adapting to what changed underneath: - `nullTexture` keeps #293's rule: without `nullDescriptor`, a comparison binding of a T# no comparison can read (all zero, or a format no comparison reads) throws instead of binding a zero texture. `resourceTests` in `agc_driver_graphics` checks the refusal names `nullDescriptor` and carries the dwords. - Descriptor pools: main now checks `SetDescriptorLimit` and gives a set that does not fit the chain pool a dedicated pool, so the chain-pool growth this PR had is gone; a large table set gets a dedicated pool sized for it. - The shader disk cache format is version 10 (main is at 9), and the Linux layout checks match the current structs. @fisherjoey thanks for the Demon's Souls run. You read it right: the material-selected path (`table.hasMaterial`) still caps the distinct keys at `APS5_BINDLESS_SLOTS` (16, at most 48); only the direct-index path goes up to the device limit. Raising the material path changes how its slots are materialized, so I'll do it in a follow-up PR rather than grow this one.
fisherjoey commented 2026-10-08 19:50:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-08T19:50:53Z.


Data from Demon's Souls (PPSA01341 v1.07, Linux, RTX 5070 Ti) on a stack with this PR, for the table paths it doesn't cover.

Compute shader 0x248946900 selects its images through a material table (resolveTableImage), and that path still sizes the table from APS5_BINDLESS_SLOTS (default 16, clamped to 48) rather than the device limit. The number of distinct keys it needs depends on the scene:

where distinct keys
opening cinematic 17, and 37 in another run (32 slots crashed)
tutorial level, loaded through the title's debug start menu 60 to 93

With this PR and no APS5_BINDLESS_SLOTS, the debug-start route ends with exit -6: compute shader 0x248946900: bindless image table: 60 distinct keys exceed the 16 slots. With APS5_BINDLESS_SLOTS=128 on a local build it reaches the level. Through the normal menus the same shader stayed under 48 in our runs, so this only shows up with the larger material sets.

The other failure we saw on this shader, bindless image table selects no entry when every material key is past the heap's entry count (2 of 4 runs in the character creator), is the case bindNullTable here covers; we had the same fix locally.

Is the material-selected path meant to move to the device limit too, here or in #757?

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6067837942 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1184#issuecomment-6067837942). Originally posted by [fisherjoey](https://github.com/fisherjoey) on 2026-10-08T19:50:53Z. --- Data from Demon's Souls (PPSA01341 v1.07, Linux, RTX 5070 Ti) on a stack with this PR, for the table paths it doesn't cover. Compute shader `0x248946900` selects its images through a material table (`resolveTableImage`), and that path still sizes the table from `APS5_BINDLESS_SLOTS` (default 16, clamped to 48) rather than the device limit. The number of distinct keys it needs depends on the scene: | where | distinct keys | |---|---| | opening cinematic | 17, and 37 in another run (32 slots crashed) | | tutorial level, loaded through the title's debug start menu | 60 to 93 | With this PR and no `APS5_BINDLESS_SLOTS`, the debug-start route ends with `exit -6`: `compute shader 0x248946900: bindless image table: 60 distinct keys exceed the 16 slots`. With `APS5_BINDLESS_SLOTS=128` on a local build it reaches the level. Through the normal menus the same shader stayed under 48 in our runs, so this only shows up with the larger material sets. The other failure we saw on this shader, `bindless image table selects no entry` when every material key is past the heap's entry count (2 of 4 runs in the character creator), is the case `bindNullTable` here covers; we had the same fix locally. Is the material-selected path meant to move to the device limit too, here or in #757?
MichonGoddijn231849 commented 2026-10-09 08:32:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-09T08:32:58Z.


Parked as a draft: with #639 a bindless table expands statically into the runtime ABI's sampled heap, so binding tables larger than 16 slots needs a new design rather than a rebase. @fisherjoey thanks for the Demon's Souls data on the material-table path; I'll use it when I redo this on the runtime ABI.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6077390489 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1184#issuecomment-6077390489). Originally posted by [MichonGoddijn231849](https://github.com/MichonGoddijn231849) on 2026-10-09T08:32:58Z. --- Parked as a draft: with #639 a bindless table expands statically into the runtime ABI's sampled heap, so binding tables larger than 16 slots needs a new design rather than a rebase. @fisherjoey thanks for the Demon's Souls data on the material-table path; I'll use it when I redo this on the runtime ABI.
simonbronk commented 2026-10-14 12:06:33 +00:00 (Migrated from github.com)

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


@MichonGoddijn231849 are you already redoing this on the runtime ABI? Onimusha: Way of the Sword (PPSA27836) needs it too: after #5620 and #5550 it stops at static bindless image capacity exceeded (#5720), and with MaxImages and SampledHeapCapacity raised locally to 128, at a compute program that reads a whole 32768-entry table with no material records (bindless image table has 32768 entries (0 materials), limit 16). Details in #5769.

If you have not started, I would like to try the redesign and would build on this PR's approach, crediting you. If you have, I will test your branch on this title instead of writing a second version. Either way is fine.

AI-assisted: yes (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6167946072 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1184#issuecomment-6167946072). Originally posted by [simonbronk](https://github.com/simonbronk) on 2026-10-14T12:06:33Z. --- @MichonGoddijn231849 are you already redoing this on the runtime ABI? Onimusha: Way of the Sword (PPSA27836) needs it too: after #5620 and #5550 it stops at `static bindless image capacity exceeded` (#5720), and with `MaxImages` and `SampledHeapCapacity` raised locally to 128, at a compute program that reads a whole 32768-entry table with no material records (`bindless image table has 32768 entries (0 materials), limit 16`). Details in #5769. If you have not started, I would like to try the redesign and would build on this PR's approach, crediting you. If you have, I will test your branch on this title instead of writing a second version. Either way is fine. AI-assisted: yes (Claude Code).
adriadam10 commented 2026-10-15 11:02:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-15T11:02:22Z.


Closing: the author said on 2026-10-09 that after #639 a bindless table expands statically into the runtime ABI's sampled heap, so this needs a new design rather than a rebase. The branch has had no push since 2026-10-08, conflicts with main in the resource materializer/tracker, binding allocator, ShaderResources.cpp and the disk cache, and depends on #293, which was closed as superseded by #639.

The measurements here (Demon's Souls material-table counts from @fisherjoey, GTA V's 65536-entry heap, Onimusha's 32768-entry table in #5769) are useful input for the redesign. @simonbronk has offered to redo it on the runtime ABI; feel free to coordinate there or reopen if you push a version rebased on the runtime ABI.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6190515172 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1184#issuecomment-6190515172). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-15T11:02:22Z. --- Closing: the author said on 2026-10-09 that after #639 a bindless table expands statically into the runtime ABI's sampled heap, so this needs a new design rather than a rebase. The branch has had no push since 2026-10-08, conflicts with `main` in the resource materializer/tracker, binding allocator, `ShaderResources.cpp` and the disk cache, and depends on #293, which was closed as superseded by #639. The measurements here (Demon's Souls material-table counts from @fisherjoey, GTA V's 65536-entry heap, Onimusha's 32768-entry table in #5769) are useful input for the redesign. @simonbronk has offered to redo it on the runtime ABI; feel free to coordinate there or reopen if you push a version rebased on the runtime ABI.
MichonGoddijn231849 commented 2026-10-15 15:19:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-15T15:19:49Z.


@simonbronk I haven't started the redesign, so please go ahead and build on this PR's approach. @adriadam10 closing this is fine.

What I'd keep from it: the table sized from the device's sampled-image limit instead of a slot count. The data in this thread gives the sizes to design for: Demon's Souls' material-selected table needs 60-93 distinct keys in the tutorial level, GTA V binds a 65536-entry heap, and Onimusha reads a whole 32768-entry table with no material records. Since #639 the table expands statically into the runtime ABI's sampled heap, which is where SampledHeapCapacity and MaxImages stop it, so the redesign has to start there. Link your PR here and I'll test it on Wolverine and GTA V.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6195606045 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1184#issuecomment-6195606045). Originally posted by [MichonGoddijn231849](https://github.com/MichonGoddijn231849) on 2026-10-15T15:19:49Z. --- @simonbronk I haven't started the redesign, so please go ahead and build on this PR's approach. @adriadam10 closing this is fine. What I'd keep from it: the table sized from the device's sampled-image limit instead of a slot count. The data in this thread gives the sizes to design for: Demon's Souls' material-selected table needs 60-93 distinct keys in the tutorial level, GTA V binds a 65536-entry heap, and Onimusha reads a whole 32768-entry table with no material records. Since #639 the table expands statically into the runtime ABI's sampled heap, which is where `SampledHeapCapacity` and `MaxImages` stop it, so the redesign has to start there. Link your PR here and I'll test it on Wolverine and GTA V.

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