Recompiler: size a compute program's LDS block from its LDS_SIZE #2146

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

@⁠grahamster2 on GitHub · 2026-11-25 06:15 UTC · original
grahamster2:lds-size-from-rsrc2 → main · +186 −33 · 5 files · 1 commits · open

Every translated program that touches LDS declares groupshared uint xcl_lds[8192] (32 KB, the D3D12 limit), whatever the console program allocated. A compute program's allocation is in COMPUTE_PGM_RSRC2.LDS_SIZE (bits 15..23, 512-byte units), which we already read from the FSSM descriptor. This sizes the HLSL block of a compute program to the next power of two that holds it plus the runtime words kept at the top: the split-wave64 exchange, the safe barrier's two words and the 2-D thread hand-out (XCL_WT). Accesses are masked with XCL_LDS_MASK instead of 8191u. LDS_SIZE 0 and the other stages keep 32 KB.

With 32 KB per group, an NVIDIA Ampere SM holds 3 groups at once, which is 6 warps for a 64-thread group. In the split form nothing hides the meets' latency. Analysis and numbers: #675.

Part of #675.

What is in it

  • CsInterface::lds_bytes from RSRC2 (gpu/recomp/mod.rs); lds_words / lds_decl and the layouts that used 8192 / 8191 / 8189 / 8190 / 8188 (gpu/recomp/emit.rs). Struct literals in tests get lds_bytes: 0.
  • Tests (gpu/recomp/tests.rs):
    • compute_lds_block_takes_the_programs_lds_size: block size and layout per LDS_SIZE, native / wave64 / split.
    • gpu_compute_lds_ring_in_a_block_of_the_programs_size: an LDS ring plus an exchange, with the largest LDS_SIZE that still gets the smallest block and the program's words at its very end. Runs 64 / 256 threads and an 8 x 8 group, split and native wave32. With one word fewer reserved at the top, it fails.

Tested

  • RTX 3080 10 GB (driver 610.88), Ryzen 5 7600X, Windows 11 Pro 26200, rustc 1.94.0, debug suite at 52577f9.
  • cargo test --workspace -- --test-threads=4: 1156 passed, 0 failed, 46 ignored.
  • SKIPPED on this adapter (no wave64, or refused by the per-lane form): the lower / lower_dxil wave64 parity tests, gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware, heap_window_out_of_memory_falls_back_to_the_switch_form.
  • Microbenchmark, scratch test (not in the PR). The bench_split_wave64 loop with an LDS store and load per iteration: 2^18 threads x 8192 iterations, 64-thread groups, GPU timestamps, median of 7.
    • split form with one exchange per iteration: 41.9 ms with 32 KB, 14.0 ms with a 1K-word block.
    • native wave32: 10.0 ms with 32 KB, 4.2 ms with a 1K-word block.
    • 256-thread groups: 16.0 -> 13.9 ms.
  • xcl shaders --export-hlsl on the retail title's pack: HBO (LDS_SIZE 512 B) now declares xcl_lds[256]. The 84 LDS-using split programs allocate 512 B to 16.9 KB.

Regression run
main (cbc296a):

xcl-smoke v1
commit: cbc296ab65a2661a61e3e2da109134bcd5319f60
gpu: NVIDIA GeForce RTX 3080
title: 5d6132ca
seconds: 60
exit: 0x0
frames shown: 1649 (PresentX 1649)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15679 MB

this PR (52577f9):

xcl-smoke v1
commit: 52577f993895afe1cc3e492a063b6f73821ee57c
gpu: NVIDIA GeForce RTX 3080
title: 5d6132ca
seconds: 60
exit: 0x0
frames shown: 1630 (PresentX 1630)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15616 MB

Not tested

  • The 60 s regression run covers the title's start, not its world load, where the split programs with LDS run most. So it shows that nothing regressed, not the speed-up.
  • AMD (native wave64): there the block shrinks too, so occupancy should rise, but I have not measured it.
  • The direct DXIL backend (XCL_DIRECT_DXIL, gpu/dxil/lanes.rs) still declares 8192 words. It is unchanged and would be a follow-up.
  • A program that addresses LDS past its LDS_SIZE now wraps within the smaller block, where before it landed in unused words. On the console such reads return 0 and such writes are dropped, so neither form matches. None of the 84 has a constant ds_* offset past its size, but dynamic addresses were not checked.

AI use

  • Claude Code with Claude Opus 5.5: the analysis, the code, the tests and this description. A separate Claude Sonnet review of the diff found no overlap or size bugs. Its test-coverage points (tight layout, 2-D hand-out) are in the GPU test.
**@⁠grahamster2** on GitHub · 2026-11-25 06:15 UTC · [original](https://github.com/xcl-dev/xcl/pull/2146) `grahamster2:lds-size-from-rsrc2` → `main` · +186 −33 · 5 files · 1 commits · open Every translated program that touches LDS declares `groupshared uint xcl_lds[8192]` (32 KB, the D3D12 limit), whatever the console program allocated. A compute program's allocation is in `COMPUTE_PGM_RSRC2.LDS_SIZE` (bits 15..23, 512-byte units), which we already read from the FSSM descriptor. This sizes the HLSL block of a compute program to the next power of two that holds it plus the runtime words kept at the top: the split-wave64 exchange, the safe barrier's two words and the 2-D thread hand-out (`XCL_WT`). Accesses are masked with `XCL_LDS_MASK` instead of `8191u`. LDS_SIZE 0 and the other stages keep 32 KB. With 32 KB per group, an NVIDIA Ampere SM holds 3 groups at once, which is 6 warps for a 64-thread group. In the split form nothing hides the meets' latency. Analysis and numbers: https://git.gtahub.st/github/xcl-dev--xcl/issues/675. Part of #675. **What is in it** - `CsInterface::lds_bytes` from RSRC2 (`gpu/recomp/mod.rs`); `lds_words` / `lds_decl` and the layouts that used 8192 / 8191 / 8189 / 8190 / 8188 (`gpu/recomp/emit.rs`). Struct literals in tests get `lds_bytes: 0`. - Tests (`gpu/recomp/tests.rs`): - `compute_lds_block_takes_the_programs_lds_size`: block size and layout per LDS_SIZE, native / wave64 / split. - `gpu_compute_lds_ring_in_a_block_of_the_programs_size`: an LDS ring plus an exchange, with the largest LDS_SIZE that still gets the smallest block and the program's words at its very end. Runs 64 / 256 threads and an 8 x 8 group, split and native wave32. With one word fewer reserved at the top, it fails. **Tested** - RTX 3080 10 GB (driver 610.88), Ryzen 5 7600X, Windows 11 Pro 26200, rustc 1.94.0, debug suite at 52577f9. - `cargo test --workspace -- --test-threads=4`: 1156 passed, 0 failed, 46 ignored. - SKIPPED on this adapter (no wave64, or refused by the per-lane form): the `lower` / `lower_dxil` wave64 parity tests, `gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu_wave32_program_in_wave64_hardware`, `heap_window_out_of_memory_falls_back_to_the_switch_form`. - Microbenchmark, scratch test (not in the PR). The `bench_split_wave64` loop with an LDS store and load per iteration: 2^18 threads x 8192 iterations, 64-thread groups, GPU timestamps, median of 7. - split form with one exchange per iteration: 41.9 ms with 32 KB, 14.0 ms with a 1K-word block. - native wave32: 10.0 ms with 32 KB, 4.2 ms with a 1K-word block. - 256-thread groups: 16.0 -> 13.9 ms. - `xcl shaders --export-hlsl` on the retail title's pack: HBO (LDS_SIZE 512 B) now declares `xcl_lds[256]`. The 84 LDS-using split programs allocate 512 B to 16.9 KB. **Regression run** main (cbc296a): ``` xcl-smoke v1 commit: cbc296ab65a2661a61e3e2da109134bcd5319f60 gpu: NVIDIA GeForce RTX 3080 title: 5d6132ca seconds: 60 exit: 0x0 frames shown: 1649 (PresentX 1649) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 15679 MB ``` this PR (52577f9): ``` xcl-smoke v1 commit: 52577f993895afe1cc3e492a063b6f73821ee57c gpu: NVIDIA GeForce RTX 3080 title: 5d6132ca seconds: 60 exit: 0x0 frames shown: 1630 (PresentX 1630) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 15616 MB ``` **Not tested** - The 60 s regression run covers the title's start, not its world load, where the split programs with LDS run most. So it shows that nothing regressed, not the speed-up. - AMD (native wave64): there the block shrinks too, so occupancy should rise, but I have not measured it. - The direct DXIL backend (`XCL_DIRECT_DXIL`, `gpu/dxil/lanes.rs`) still declares 8192 words. It is unchanged and would be a follow-up. - A program that addresses LDS past its LDS_SIZE now wraps within the smaller block, where before it landed in unused words. On the console such reads return 0 and such writes are dropped, so neither form matches. None of the 84 has a constant `ds_*` offset past its size, but dynamic addresses were not checked. **AI use** - Claude Code with Claude Opus 5.5: the analysis, the code, the tests and this description. A separate Claude Sonnet review of the diff found no overlap or size bugs. Its test-coverage points (tight layout, 2-D hand-out) are in the GPU test.
Every translated program that touches LDS declared `groupshared uint
xcl_lds[8192]`, the D3D12 limit of 32 KB, whatever the console program
allocated. COMPUTE_PGM_RSRC2.LDS_SIZE (bits 15..23, 512-byte units) is in
the FSSM descriptor already: the HLSL block of a compute program is now the
next power of two that holds it and the runtime words kept at the top (the
split-wave64 exchange, the safe barrier's words, the 2-D thread hand-out),
with accesses masked by `XCL_LDS_MASK`. LDS_SIZE 0 and the other stages
keep 32 KB.

32 KB per group lets an NVIDIA Ampere SM hold 3 groups, 6 warps of a
64-thread group, so the split form's meets have nothing to hide behind.
On an RTX 3080, a loop with an LDS store and load and one exchange per
iteration (2^18 threads x 8192 iterations, 64-thread groups) takes
41.9 ms in the split form with the 32 KB block and 14.0 ms with a 1K-word
one; native wave32 10.0 -> 4.2 ms. The retail title's 84 LDS-using split
programs allocate 512 B to 16.9 KB (34 of them 512 B).

Assisted-by: Claude Code (Claude Opus 5.5)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:20:27 +00:00
Author
Owner

@⁠DarkPanda69 on GitHub · 2026-11-25 06:28 UTC · original

Tested: gpu_compute_lds_ring_in_a_block_of_the_programs_size passes on AMD with native 64-lane waves, and on an RTX 3060.

  • RX 9070 XT (RDNA4, driver 32.0.32029.2010, waves 32..64): ok, so its wave64 cases (64, 256 and 8x8 threads) ran in native 64-lane waves with the smaller LDS block. Whole gpu:: filter: 586 passed, 2 failed, 22 ignored. The 2 failures are the AMD fuzz seeds 722 and 1599 tracked in #2115, which fail the same way on main.
  • RTX 3060 (driver 32.0.16.1088, waves 32 only): ok. 588 passed, 0 failed, 22 ignored.

Head 52577f9 applied on main 6ea813a, cargo test -p xcl --lib -- gpu:: --test-threads=4 with XCL_ADAPTER set to each card.
Not tested: the occupancy or speed change on AMD (correctness only), a title.
AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.

**@⁠DarkPanda69** on GitHub · 2026-11-25 06:28 UTC · [original](https://github.com/xcl-dev/xcl/pull/2146#issuecomment-7154820214) Tested: `gpu_compute_lds_ring_in_a_block_of_the_programs_size` passes on AMD with native 64-lane waves, and on an RTX 3060. - RX 9070 XT (RDNA4, driver 32.0.32029.2010, waves 32..64): ok, so its wave64 cases (64, 256 and 8x8 threads) ran in native 64-lane waves with the smaller LDS block. Whole `gpu::` filter: 586 passed, 2 failed, 22 ignored. The 2 failures are the AMD fuzz seeds 722 and 1599 tracked in #2115, which fail the same way on `main`. - RTX 3060 (driver 32.0.16.1088, waves 32 only): ok. 588 passed, 0 failed, 22 ignored. Head `52577f9` applied on `main` `6ea813a`, `cargo test -p xcl --lib -- gpu:: --test-threads=4` with `XCL_ADAPTER` set to each card. Not tested: the occupancy or speed change on AMD (correctness only), a title. AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.
Author
Owner

@⁠JoaoPauluu on GitHub · 2026-11-25 06:29 UTC · original

A run with vkd3d-proton as the host D3D12. The DXIL goes through dxil-spirv and then the NVIDIA Vulkan driver, not the native-Windows path: this PR's 2 new tests pass, none skipped.

Tested

  • RTX 3060 12 GB (NVIDIA 620.70.06, 32-lane waves), i5-10400F, 16 GB, CachyOS (kernel 7.3.3), Proton Experimental 11.0-20261112 with the patched vkd3d-proton 3.1 from #257, DXC 1.9.2609.5. Release, cross-built for x86_64-pc-windows-gnu. 52577f9 as it is (merge base with main cbc296a), no uncommitted changes. The lib test binary runs under Wine, one test per process.
    • compute_lds_block_takes_the_programs_lds_size: ok
    • gpu_compute_lds_ring_in_a_block_of_the_programs_size: ok

Not tested

  • the whole suite on this head, a retail title, native Windows, AMD.

AI use

  • Claude Code (Claude Opus 5.5) built the commit, ran the tests and wrote this report. The account owner asked for test reports to be posted and has not reviewed this one.
**@⁠JoaoPauluu** on GitHub · 2026-11-25 06:29 UTC · [original](https://github.com/xcl-dev/xcl/pull/2146#issuecomment-7154838454) A run with vkd3d-proton as the host D3D12. The DXIL goes through dxil-spirv and then the NVIDIA Vulkan driver, not the native-Windows path: this PR's 2 new tests pass, none skipped. **Tested** - RTX 3060 12 GB (NVIDIA 620.70.06, 32-lane waves), i5-10400F, 16 GB, CachyOS (kernel 7.3.3), Proton Experimental 11.0-20261112 with the patched vkd3d-proton 3.1 from #257, DXC 1.9.2609.5. Release, cross-built for `x86_64-pc-windows-gnu`. `52577f9` as it is (merge base with `main` `cbc296a`), no uncommitted changes. The lib test binary runs under Wine, one test per process. - `compute_lds_block_takes_the_programs_lds_size`: ok - `gpu_compute_lds_ring_in_a_block_of_the_programs_size`: ok **Not tested** - the whole suite on this head, a retail title, native Windows, AMD. **AI use** - Claude Code (Claude Opus 5.5) built the commit, ran the tests and wrote this report. The account owner asked for test reports to be posted and has not reviewed this one.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-25 06:49 UTC · original

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)

Thanks!

**@⁠DavidM1911** on GitHub · 2026-11-25 06:49 UTC · [original](https://github.com/xcl-dev/xcl/pull/2146#issuecomment-7155195944) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.) Thanks!
This pull request can be merged automatically.
This branch is out-of-date with the base branch
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/2146/head:github-bot/gh-2146'
git switch 'github-bot/gh-2146'

Merge

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