tombox-xshader: size tb_lds from COMPUTE_PGM_RSRC2 in every compute shader (follow-up to #257, #350) #384

Open
github-bot wants to merge 1 commit from github-bot/gh-384 into main AGit
Owner

@⁠SchmashinPrunes on GitHub · 2026-11-25 16:04 UTC · original
SchmashinPrunes:lds-size-all-compute → main · +60 −12 · 4 files · 1 commits · open

Follow-up to #257, as announced on #350. @⁠omonkeyz

Why

tb_lds was sized from COMPUTE_PGM_RSRC2.LDS_SIZE only in compute shaders with a 64-bit LDS atomic. Every other compute shader declared groupshared uint tb_lds[8192] (32 KiB), whatever the program allocates. That has two effects:

  • Occupancy. On an RX 9060 XT, a 64-thread group with 32 KiB of groupshared memory fits about 2 groups per CU: 57 groups at once on 32 CUs. With 16 KiB it fits about 4 per CU, and with none, all 1,024 that were dispatched (measured on #350). A persistent kernel sized for the console's occupancy can stall when far fewer of its groups are resident. That is the low-occupancy suspect for the PersistentClusterCull hang in #350.
  • ds_permute / ds_bpermute next to LDS. These were always refused in a compute shader that also uses LDS, because the fixed 32 KiB left no room for the exchange arrays (BLOCKERS, Trackmania 15ae33bc / 18f7efba).

Change

plan_lds64 now plans the LDS size for every compute shader that has a non-GDS DS instruction. Mesh and amplification shaders keep their own sizing.

  • With a 64-bit LDS atomic: unchanged. The declared size is required, as in #257, and the lock word sits after it.
  • Without one: the size comes from the same reader (declared_dwords, with #257's location per FSSM sub-version and its validity checks). It is used only when it fits the 32 KiB groupshared limit and every static DS offset reaches inside it. Otherwise the shader silently keeps today's tb_lds[8192]. Nothing that translates today is refused by this change.
  • Wrap: the address wrap follows the planned size: & (n − 1) for a power of two, % n otherwise, & 8191 for the fallback.
  • xlane_header: it now accepts ds_permute/ds_bpermute together with LDS when the planned LDS plus the three exchange arrays fit in 32 KiB.

Past the declared size this keeps #257's wrap. On gfx1036 an out-of-range LDS read returns 0 and the write is dropped (measured for #245). With a known size that could be reproduced exactly, at the cost of one compare per access. Tell me if you want it.

Tests

tests/exec_mem/ds.rs:

  • ds_lds_compute_in_the_declared_lds:
    • The existing ds_lds case list (70 cases, 32 mnemonics, with runtime-input reruns) runs again with 16 granules declared. The HLSL is checked for tb_lds[2048] / & 2047u] and no lock word.
    • Fallback cases keep tb_lds[8192] / & 8191u: a static offset past the declared size (1 granule), a declared size over 32 KiB (80 granules), and no container.
    • A non-power-of-two size gives tb_lds[1152] / % 1152u.
  • ds_permute_with_lds_is_refused:
    • The permute-plus-LDS program is still refused without a container, and with 63 granules declared (no room for the exchange).
    • With 1 granule declared it now runs, and ds_bpermute_b32 returns the right lanes.
  • ds_lds_atomic64_sizing: its last check pinned the old behaviour (a plain 32-bit LDS shader stays at 8192 even with a declared size). It now expects tb_lds[640] / % 640u from 5 granules, and still 8192 without a container.

Results (Windows 11, DXC from TOMBOX_DXC_DIR):

run result
WARP, exec ds_* 34/34; ds_lds_declared 70 cases ok, ds_permute_with_declared_lds ok
Radeon RX 9060 XT (TOMBOX_EXEC_HW=1), exec ds_* 34/34, same groups
WARP, full tombox-xshader suite every target ok; tests/exec.rs 190/190 (2 ignored), lib 149/149
RX 9060 XT, full tests/exec.rs 190/190 (2 ignored)

The PR gate is clean. Occupancy itself can't be measured in CI. The #350 numbers came from a separate probe.

🤖 Generated with Claude Code

**@⁠SchmashinPrunes** on GitHub · 2026-11-25 16:04 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/384) `SchmashinPrunes:lds-size-all-compute` → `main` · +60 −12 · 4 files · 1 commits · open Follow-up to #257, as announced on #350. @⁠omonkeyz ### Why `tb_lds` was sized from `COMPUTE_PGM_RSRC2.LDS_SIZE` only in compute shaders with a 64-bit LDS atomic. Every other compute shader declared `groupshared uint tb_lds[8192]` (32 KiB), whatever the program allocates. That has two effects: - **Occupancy.** On an RX 9060 XT, a 64-thread group with 32 KiB of groupshared memory fits about 2 groups per CU: 57 groups at once on 32 CUs. With 16 KiB it fits about 4 per CU, and with none, all 1,024 that were dispatched (measured on #350). A persistent kernel sized for the console's occupancy can stall when far fewer of its groups are resident. That is the low-occupancy suspect for the PersistentClusterCull hang in #350. - **`ds_permute` / `ds_bpermute` next to LDS.** These were always refused in a compute shader that also uses LDS, because the fixed 32 KiB left no room for the exchange arrays (BLOCKERS, Trackmania 15ae33bc / 18f7efba). ### Change `plan_lds64` now plans the LDS size for every compute shader that has a non-GDS DS instruction. Mesh and amplification shaders keep their own sizing. - **With a 64-bit LDS atomic:** unchanged. The declared size is required, as in #257, and the lock word sits after it. - **Without one:** the size comes from the same reader (`declared_dwords`, with #257's location per FSSM sub-version and its validity checks). It is used only when it fits the 32 KiB groupshared limit and every static DS offset reaches inside it. Otherwise the shader silently keeps today's `tb_lds[8192]`. Nothing that translates today is refused by this change. - **Wrap:** the address wrap follows the planned size: `& (n − 1)` for a power of two, `% n` otherwise, `& 8191` for the fallback. - **`xlane_header`:** it now accepts `ds_permute`/`ds_bpermute` together with LDS when the planned LDS plus the three exchange arrays fit in 32 KiB. Past the declared size this keeps #257's wrap. On gfx1036 an out-of-range LDS read returns 0 and the write is dropped (measured for #245). With a known size that could be reproduced exactly, at the cost of one compare per access. Tell me if you want it. ### Tests `tests/exec_mem/ds.rs`: - `ds_lds_compute_in_the_declared_lds`: - The existing `ds_lds` case list (70 cases, 32 mnemonics, with runtime-input reruns) runs again with 16 granules declared. The HLSL is checked for `tb_lds[2048]` / `& 2047u]` and no lock word. - Fallback cases keep `tb_lds[8192]` / `& 8191u`: a static offset past the declared size (1 granule), a declared size over 32 KiB (80 granules), and no container. - A non-power-of-two size gives `tb_lds[1152]` / `% 1152u`. - `ds_permute_with_lds_is_refused`: - The permute-plus-LDS program is still refused without a container, and with 63 granules declared (no room for the exchange). - With 1 granule declared it now runs, and `ds_bpermute_b32` returns the right lanes. - `ds_lds_atomic64_sizing`: its last check pinned the old behaviour (a plain 32-bit LDS shader stays at 8192 even with a declared size). It now expects `tb_lds[640]` / `% 640u` from 5 granules, and still 8192 without a container. **Results** (Windows 11, DXC from `TOMBOX_DXC_DIR`): | run | result | |---|---| | WARP, `exec` `ds_*` | 34/34; `ds_lds_declared` 70 cases ok, `ds_permute_with_declared_lds` ok | | Radeon RX 9060 XT (`TOMBOX_EXEC_HW=1`), `exec` `ds_*` | 34/34, same groups | | WARP, full `tombox-xshader` suite | every target ok; `tests/exec.rs` 190/190 (2 ignored), lib 149/149 | | RX 9060 XT, full `tests/exec.rs` | 190/190 (2 ignored) | The PR gate is clean. Occupancy itself can't be measured in CI. The #350 numbers came from a separate probe. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Only compute shaders with a 64-bit LDS atomic took the LDS size from
COMPUTE_PGM_RSRC2 (#257); the rest declared a fixed 32 KiB tb_lds, which
caps a 64-thread group at about 2 per CU on AMD hosts (measured on #350)
and left no room for the ds_permute exchange arrays.

Plan the size for every compute shader with a non-GDS DS instruction:
the RSRC2 dword at the FSSM sub-version's proven location, when it fits
32 KiB and every static DS offset reaches inside it. Otherwise keep
tb_lds[8192] silently, so nothing that translates today is refused. The
wrap follows the size (& (n - 1) or % n), and ds_permute/ds_bpermute
with LDS is accepted when LDS plus the exchange arrays fit 32 KiB.
Mesh and amplification shaders are unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:21:03 +00:00
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/384/head:github-bot/gh-384'
git switch 'github-bot/gh-384'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-384'
git switch 'github-bot/gh-384'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-384'
git switch 'github-bot/gh-384'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-384'
git switch 'main'
git merge --squash 'github-bot/gh-384'
git switch 'main'
git merge --ff-only 'github-bot/gh-384'
git switch 'main'
git merge 'github-bot/gh-384'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.