Skip to content

Direct DXIL: size a compute program's LDS block from its LDS_SIZE - #2158

Open
grahamster2 wants to merge 2 commits into
xcl-dev:mainfrom
grahamster2:lds-size-direct-dxil
Open

grahamster2 wants to merge 2 commits into
xcl-dev:mainfrom
grahamster2:lds-size-direct-dxil

Conversation

@grahamster2

Copy link
Copy Markdown
Collaborator

Stacked on #2146; only the last commit (55d06c1) belongs here, please review that one.

The direct DXIL backend (XCL_DIRECT_DXIL) declares its xcl_lds with 8192 words for every program, as the HLSL kernel did before #2146. This sizes it by the same rule: a compute program's COMPUTE_PGM_RSRC2.LDS_SIZE plus the same reserved top words, rounded up to a power of two. The exchange words, XCL_WT and the address mask in lds_index move to the new block's top. LDS_SIZE 0 and the other stages keep 8192 words.

Part of #675.

What is in it

  • Lw::lds_words, set in setup_storage from the entry's lds_bytes (gpu/dxil/lanes.rs, kernel.rs, lower.rs), and used by the mask in lds_index (lower_mem.rs).
  • gpu_compute_lds_ring_in_a_block_of_the_programs_size also runs the direct translation. It covers the kernels direct_or runs (wave32, and wave64 in the split form) and checks that @xcl_lds has the HLSL block's size. With the old 8192-word block, the test fails.
  • bench_compute_lds_block (ignored, next to bench_split_wave64): the 32 KB block against the LDS_SIZE block, in a loop with an LDS store and load and an exchange per iteration.

Tested

  • RTX 3080 10 GB (driver 610.88), Ryzen 5 7600X, Windows 11 Pro 26200, rustc 1.94.0.
  • cargo test --workspace -- --test-threads=4 at 55d06c1: 1156 passed, 0 failed, 47 ignored. The SKIPPED tests are the same as in Recompiler: size a compute program's LDS block from its LDS_SIZE #2146 (no wave64).
  • XCL_DIRECT_DXIL=1 cargo test -p xcl --lib -- --test-threads=4: 1099 passed, 1 failed, 27 ignored. The failure, gpu_image_get_resinfo_1d_array, also fails with XCL_DIRECT_DXIL=1 at 52577f9, so it is not from this change.
  • bench_compute_lds_block, 2^18 threads x 8192 iterations, 64-thread groups, 32 KB block -> LDS_SIZE block:
backend wave32 wave64, split form
HLSL (#2146) 7.8 -> 3.5 ms 39.4 -> 12.4 ms
direct DXIL (this PR) 10.3 -> 2.3 ms 16.5 -> 5.5 ms

256-thread groups: 1.0x to 1.27x.

Regression run
Both runs with XCL_DIRECT_DXIL=1 (the path this changes).

main (cbc296a):

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

this PR (55d06c1):

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

Not tested

  • AMD (native wave64).
  • Each backend picks its own exchange slot size: HLSL from what it emits, direct DXIL from a scan of the program. A program with a ds_bpermute, a coherent s_load or a two-word reduction tail can get a different slot size, and then a different block in the two backends. Each layout still fits its own block, and the test covers the one-word slot.
  • Out-of-range LDS addresses wrap within the smaller block, as in Recompiler: size a compute program's LDS block from its LDS_SIZE #2146.

AI use

  • Claude Code with Claude Opus 5.5: the code, the tests and this description. A separate Claude Sonnet review of the diff led to gating the direct half of the test to the kernels direct_or runs, and to matching @xcl_lds exactly.

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)
The direct DXIL backend (XCL_DIRECT_DXIL) declared its `xcl_lds` with
8192 words for every program, as the HLSL kernel did. It now sizes it by
the same rule: a compute program's COMPUTE_PGM_RSRC2.LDS_SIZE plus the
same reserved top words, rounded up to a power of two (the exchange slot
size each backend picks can still differ for a program), with the exchange,
`XCL_WT` and the address mask moved to that block's top. LDS_SIZE 0 and
the other stages keep 8192 words.

The LDS ring GPU test runs the direct translation too (the kernels
`direct_or` runs), and checks that its block has the HLSL block's size. `bench_compute_lds_block` (ignored,
next to `bench_split_wave64`) times a loop with an LDS store and load and
an exchange per iteration with both blocks. RTX 3080, 2^18 threads x 8192
iterations, 64-thread groups, 32 KB block -> LDS_SIZE block:
  HLSL:   wave32 7.8 -> 3.5 ms, split wave64 39.4 -> 12.4 ms
  direct: wave32 10.3 -> 2.3 ms, split wave64 16.5 -> 5.5 ms

Assisted-by: Claude Code (Claude Opus 5.5)
@JJAutoCompare

Copy link
Copy Markdown

Tested

PR #2158, stacked on #2146, was open at 55d06c1e02831b09a931d383b7f6ea4bb6793b9e before and after testing. The assigned checkout was clean and detached at that SHA. The initial GitHub API response and final public PR page agreed with the live Git pull ref. The PR describes same-head RTX 3080 coverage. The discussion contained no equivalent Arc A770 coverage.

STOR-WINLAB ran Windows 11 Enterprise Evaluation 26200.9974 on a Ryzen 7 3800X with an Intel Arc A770, driver 32.0.101.9175. Rust and Cargo were 1.100.0 on x86_64-pc-windows-msvc (rustc 0ef1bc386). Both runs loaded DXC and DXIL 1.9.2609.5 from %LOCALAPPDATA%/XclTooling/dxc-1.9.2609/bin/x64.

Cargo used the unoptimized test profile with CARGO_BUILD_JOBS=2, CARGO_INCREMENTAL=0, CARGO_PROFILE_DEV_DEBUG=0, CARGO_PROFILE_TEST_DEBUG=0 and the exclusive target L:/XclTooling/pr1947-1831ec4-t3-97236edf/target. TEMP and TMP both used L:/XclTooling/pr2158/temp. The build finished outside the Arc mutex in 59.47 s. The invocation used -NoProfile -ExecutionPolicy RemoteSigned for that PowerShell process.

cargo test --locked -p xcl --lib -j 2 --no-run --message-format=json
$fixtureExe = 'L:/XclTooling/pr1947-1831ec4-t3-97236edf/target/debug/build/xcl/97fdf2b9ff8e1482/out/xcl-97fdf2b9ff8e1482.exe'
$env:XCL_ADAPTER = 'A770'
$env:XCL_DXC_DIR = Join-Path $env:LOCALAPPDATA 'XclTooling/dxc-1.9.2609/bin/x64'
& 'L:/XclTooling/Invoke-ArcTest.ps1' -Test {
    $env:XCL_DIRECT_DXIL = '1'
    & $fixtureExe --exact gpu::recomp::tests::gpu_compute_lds_ring_in_a_block_of_the_programs_size --nocapture --test-threads=1
    $env:XCL_DIRECT_DXIL = '0'
    & $fixtureExe --exact gpu::recomp::tests::gpu_compute_lds_ring_in_a_block_of_the_programs_size --nocapture --test-threads=1
}
XCL_DIRECT_DXIL Passed Failed Ignored Skipped Filtered out Fixture time Exit
1 1 0 0 0 1126 1.60 s 0
0 1 0 0 0 1126 1.01 s 0

The fixture explicitly compiles HLSL through DXC and translates direct DXIL under both environment settings. The two invocations therefore repeat the same assertions. The existing STOR-WINLAB A770 capability log records a D3D12 wave-lane range of 8 to 32, so the fixture exercised wave32 and split wave64 for 64×1×1, 256×1×1 and 8×8×1 thread groups. For each of the six configurations, the fixture checked the direct DXIL @xcl_lds declaration against the HLSL block size and compared each backend’s per-thread ring and first-lane exchange result to the expected integer arithmetic. This exercises the fixture’s one-word exchange slot.

The executable SHA-256 was 896E8C588C18A5363FF54AD4B25C76842C9B260409AA28D89C9772E0825B74D9 before waiting for the Arc mutex, after acquiring it and after both runs. The Arc mutex and target were released after testing.

Combined: 2 passed, 0 failed, 0 ignored, 0 skipped.

Not tested

Native wave64, other adapters, other exchange layouts, negative cases, runtime backend selection, broader test suites, benchmarks, retail titles and smoke/regression runs.

AI use

T3 Code / Codex (gpt-6.2-sol) ran the checked-in fixture, verified its assertion coverage and prepared this report.

@DavidM1911

Copy link
Copy Markdown
Contributor

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

Thanks!

@DarkPanda69

Copy link
Copy Markdown

Tested: gpu_compute_lds_ring_in_a_block_of_the_programs_size passes on AMD with native 64-lane waves (the case the PR lists as untested), and on an RTX 3060.

Head 55d06c1 applied on main 568e7db, debug, cargo test -p xcl --lib -- gpu:: --test-threads=4 with XCL_ADAPTER set to each card. The HLSL half (#2146) passed the same way on this card earlier.
Not tested: occupancy or speed on AMD (correctness only), a title.
AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.

@emirduran707

Copy link
Copy Markdown
Contributor

Independent AMD RDNA4 (native wave64) test report on exact head 55d06c1e02831b09a931d383b7f6ea4bb6793b9e (clean detached checkout, no local changes).

Tested

  • AMD Radeon RX 9060 XT 16 GB (RDNA4, native wave64, driver 32.0.31044.16), Ryzen 5 5600, 32 GB RAM, Windows 11 Pro 26300, Rust 1.100.0 (stable-x86_64-pc-windows-msvc), DXC 1.9.2602.17; tests debug, smoke release.
  • cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4: 1154 passed, 2 failed, 47 ignored; 8 SKIPPED (6 in lower_dxil::tests::{f16,f32}_programs_on_the_gpu refused by per-lane form; heap_window_out_of_memory_falls_back_to_the_switch_form; pso_measurement_compiles_an_exact_synthetic_record). All native wave64 GPU tests ran and passed.
    • The PR's test passed: gpu::recomp::tests::compute_lds_block_takes_the_programs_lds_size.
    • The 2 failures (gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1 seed 722 and fuzz_validate_and_gpu_3 seed 1599) are pre-existing on unmodified main on this GPU.

Regression run (60 s retail-title smoke, XCL_NETWORK=0, release)

xcl-smoke v1
commit: 55d06c1e02831b09a931d383b7f6ea4bb6793b9e
gpu: AMD Radeon RX 9060 XT
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1562 (PresentX 1562)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16794 MB

(Matched main 68a284a baseline on the same machine today: 1573 frames, 14420 MB peak, 0 device removals, 0 crashes.)

Not tested

  • D3D12 debug layer; Intel GPUs.

AI use

  • Antigravity with Gemini 4 Neon ran the build, test suite, and smoke run and drafted this report.

grahamster2 added a commit to grahamster2/xcl that referenced this pull request Nov 27, 2026
…LDS_SIZE

Merges xcl-dev#2146 (fork/lds-size-from-rsrc2, 52577f9: the HLSL
path declares xcl_lds from COMPUTE_PGM_RSRC2.LDS_SIZE plus the runtime
words at its top) and xcl-dev#2158 (fork/lds-size-direct-dxil,
55d06c1: the direct DXIL translator sizes its block the same way).

Conflicts:
- dxil/kernel.rs: HEAD calls setup_storage after the partner is chosen;
  kept that order and passed the compute program's lds_bytes to it.
- recomp/tests.rs: kept HEAD's tests and added the PRs' LDS tests after
  gpu_compute_tg_size_counts_a_partial_last_wave.

Follow-ups for HEAD:
- CsInterface literals added since the PR base get lds_bytes: 0.
- gpu_compute_lds_ring_in_a_block_of_the_programs_size: the direct
  translator now refuses an s_barrier in a group of several hardware
  waves (safe barrier on by default), so that refusal skips the direct
  form, and a 32-thread wave32 case keeps direct DXIL covered.
grahamster2 added a commit to grahamster2/xcl that referenced this pull request Nov 27, 2026
…ck from LDS_SIZE"

This reverts commit bcd5fb8, reversing
changes made to d6a4621.

Series S runs hang (DEVICE_HUNG) with it during world load; no measured speedup on the retail title (027daf6e 238→229 ms on Series X).
@Decodere

Copy link
Copy Markdown
Contributor

Independent desktop NVIDIA verification of PR #2158 at head 55d06c1e02831b09a931d383b7f6ea4bb6793b9e (2 commits stacked on PR #2146: 52577f993895afe1cc3e492a063b6f73821ee57c -> 55d06c1e02831b09a931d383b7f6ea4bb6793b9e; exact parent & merge-base: cbc296ab65a2661a61e3e2da109134bcd5319f60, pre-#2555 ancestor of main).

Environment

  • GPU: NVIDIA GeForce RTX 4060 (8 GB / 7956 MiB reported by D3D12, Wave32-only Ada), driver 32.0.16.2114 (NVIDIA 621.14, WDDM 3.2)
  • CPU / RAM / OS: Intel Core i5-11400F (6C / 12T), 32 GB RAM (31.9 GiB usable), Windows 11 Home 26200 (Developer Mode off)
  • Toolchain: rustc 1.100.0 (0ef1bc386 2026-11-09) MSVC, DXC 1.9.2609.5, --release

Targeted release tests & build (55d06c1e)

Command Result
cargo test --release -p xcl --lib compute_lds_block_takes_the_programs_lds_size -- --nocapture (3 consecutive runs) 1 passed; 0 failed; 0 ignored; 1126 filtered out × 3 (0.00s × 3, 0 skipped)
cargo test --release -p xcl --lib gpu_compute_lds_ring_in_a_block_of_the_programs_size -- --nocapture (3 consecutive runs) 1 passed; 0 failed; 0 ignored; 1126 filtered out × 3 (0.60s, 0.53s, 0.54s, 0 skipped; live RTX 4060 execution across HLSL and direct-DXIL backends)
cargo test --release -p xcl --lib gpu::dxil:: -- --test-threads=4 (3 consecutive runs) 122 passed; 0 failed; 3 ignored; 1002 filtered out × 3 (4.08s, 4.19s, 4.35s, 0 skipped)
cargo build --release -p xcl Clean build (1m 28s, exit 0, 0 new warnings)

Paired quiet 60 s retail smoke (title: 29640639)

Exact parent & merge-base (cbc296ab65a2661a61e3e2da109134bcd5319f60, cached baseline on the same machine):

xcl-smoke v1
commit: cbc296ab65a2661a61e3e2da109134bcd5319f60
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1572 (PresentX 1572)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14509 MB

PR #2158 (55d06c1e02831b09a931d383b7f6ea4bb6793b9e):

xcl-smoke v1
commit: 55d06c1e02831b09a931d383b7f6ea4bb6793b9e
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1569 (PresentX 1569)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14521 MB

Limits of coverage

  • Sizing direct-DXIL compute xcl_lds blocks from COMPUTE_PGM_RSRC2.LDS_SIZE plus top-reserved runtime words (matching stacked HLSL PR Recompiler: size a compute program's LDS block from its LDS_SIZE #2146) was directly verified on desktop RTX 4060 via compute_lds_block_takes_the_programs_lds_size (3/3), gpu_compute_lds_ring_in_a_block_of_the_programs_size (3/3, live GPU execution), and gpu::dxil:: (122/122 × 3).
  • The ignored bench_compute_lds_block microbenchmark was not run; the 60 s retail smoke confirms zero runtime regression on title: 29640639 (single-run frame/commit delta vs. cached parent reflects normal startup variance, not this PR).

AI disclosure: test execution and report drafting assisted by Google Antigravity (Gemini 4 Neon).

voiceovarian1-max added a commit to voiceovarian1-max/xcl that referenced this pull request Nov 27, 2026
`xcl_lds` was always 32 KB. Its size now follows what the program allocates
(RSRC2 LDS_SIZE, 512-byte granules, `CsInterface::lds_bytes`) plus the words
XCL keeps above it (the split form's exchange, the safe barrier's state), in
both the direct DXIL path and HLSL. Groups that ask for little LDS then fit
many to a GPU core: a retail title's busiest program allocates 512 B, and
32 KB let ~3 of its groups onto an NVIDIA SM. Measured in-run A/B (run 186,
RTX 4070 Ti under Wine): that program -34 % GPU time per call (60.8 -> 40.2 ms
over 30 windows). `XCL_LDS_FIT=0`: 32 KB as before. GPU test included; the
test literals get `lds_bytes: 0` (size not known: 32 KB).

Upstream PRs xcl-dev#2146 and xcl-dev#2158 (grahamster2, open) size the LDS block from
LDS_SIZE too; this is our own form, made before we saw them.

Platform: all

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@voiceovarian1-max

Copy link
Copy Markdown

A retail measurement of the same idea, not of this PR's head: our tree sizes the LDS block from LDS_SIZE the same way (direct DXIL and HLSL; our commit), and we compared it with the 32 KB block inside one run of a retail title's world.

Setup: RTX 4070 Ti 12 GB (32-lane waves only), NVIDIA 620.73.04, Linux + Proton Experimental (Wine 11.0) + vkd3d-proton 3.1, XCL_DIRECT_DXIL=1, the GPU profile on (it serialises the queues). Each of 13 hot compute programs ran its fitted pipeline on odd frames and the 32 KB one on even frames; 5 of them have an LDS size that changes.

Result (30 windows of 2 s)

  • The title's busiest compute program, which allocates 512 B of LDS: 60.8 -> 40.2 ms per call, -34 % (per-window median -36 %, range -55 % to +8 %). With 32 KB, only ~3 of its groups fit on an SM.
  • The other 12: within ±5 % (medians within ±1.3 %).
  • Not measured: the world's frame rate with this alone (our frames there were not bound by shader time).

Written with Claude Code (Claude Opus 5.5) from our run records.

voiceovarian1-max added a commit to voiceovarian1-max/xcl that referenced this pull request Nov 27, 2026
…idia-dev refuses the direct form

`gpu_compute_lds_ring_in_a_block_of_the_programs_size` translates its ring
program with the direct DXIL translator too and unwrapped the result. On
nvidia-dev the direct path refuses an s_barrier in a group of several
hardware waves (`barrier_waves`), as on this wave32-only card for its larger
groups: such a program runs as HLSL, so the test now checks the HLSL form
alone then. With it, the LDS tests pass on an RTX 4070 Ti under Wine (33
passed, 0 failed), the GPU dispatches of the fitted blocks included.

Platform: carried

Co-Authored-By: Claude Opus 5.5 <[email protected]>
voiceovarian1-max added a commit to voiceovarian1-max/xcl that referenced this pull request Nov 27, 2026
Upstream PRs xcl-dev#2146 and xcl-dev#2158 by grahamster2 (size a compute program's LDS
block from its LDS_SIZE, HLSL and direct DXIL; heads 52577f9 / 55d06c1)
do what our 50876a8 did, tested on many GPUs. Their form differs: the block
is the next power of two that holds the program's LDS and the runtime words,
and accesses are masked with it (`XCL_LDS_MASK`). They are carried in place of
ours: our `XCL_LDS_FIT` switch, our sizing in `emit::lds_words`,
`Lw::setup_storage` and lower_mem, and our GPU test are taken out; their
`lds_words`, `lds_decl`, `setup_storage(.., lds_bytes)` and tests are in.
Their tests are appended at the end of recomp/tests.rs (nvidia-dev's tests
sit where they added them on main).

Ours on top: a one-pass mesh shader (`Options::mesh_one`,
`Entry::MeshOnePass`) is sized from its own LDS as well, through their
functions, and is refused when that is over 28 KB (a mesh shader's limit).

Tested here (Wine, no usable GPU at the time): compute_lds_block_takes_the_
programs_lds_size and the one-pass tests pass; the GPU tests (their
gpu_compute_lds_ring_in_a_block_of_the_programs_size among them) are not run
yet. Kept on branch linux-lds-2146 until they are.

Platform: carried

Co-Authored-By: Claude Opus 5.5 <[email protected]>
voiceovarian1-max added a commit to voiceovarian1-max/xcl that referenced this pull request Nov 27, 2026
…idia-dev refuses the direct form

`gpu_compute_lds_ring_in_a_block_of_the_programs_size` translates its ring
program with the direct DXIL translator too and unwrapped the result. On
nvidia-dev the direct path refuses an s_barrier in a group of several
hardware waves (`barrier_waves`), as on this wave32-only card for its larger
groups: such a program runs as HLSL, so the test now checks the HLSL form
alone then. With it, the LDS tests pass on an RTX 4070 Ti under Wine (33
passed, 0 failed), the GPU dispatches of the fitted blocks included.

Platform: carried

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@throny

throny commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

Two contributors checked independently and found that #2937 solves the same problem in a different way: #1607, group D149. You may want to compare them with the other author and agree on one, or say in the PR why both are needed.

This is a hint from the community triage in #1607, not a maintainer decision.

AI use: Claude Code (Claude Opus 5.5), posted by a script from the #1607 table.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants