Recompiler: direct compute LDS is the block the program declares #3478

Open
Foniass wants to merge 2 commits from upstream-pr/3478 into main
Foniass commented 2026-11-29 23:59:58 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-11-29T23:59:58Z.


Rebased directly onto main: #3468 is closed, because main's ada50ec5 (#3497) already clamps LDS accesses whenever lds_top < 8191.

The direct DXIL translator gives every compute program that uses LDS the whole 8,192-dword groupshared block, so a one-wave group holds 32 KB and few groups stay resident at once. With this PR the block is:

  • the LDS the program's COMPUTE_PGM_RSRC2 declares;
  • then the translator's own words: the safe barrier's two words from #3264, a native 2-D / 3-D group's arrival counter, and the split form's exchange words.

A sink word sits between the program's LDS and the translator's words: a program access past the declared size goes there, so a store has no effect on the program's LDS and a read gives 0, as on RDNA2 (second commit, after thehollowedone's out-of-bounds finding). A header with no size, or one too large to leave room for the sink and those words, keeps the 8,192-dword layout. Mesh, geometry and the HLSL path are unchanged. On by default; XCL_DECLARED_LDS=0 brings back the 8,192-dword layout. The disk caches and ComputePolicyKey keep the two apart.

This combines two earlier versions:

  • Kalmarv's #2937 (opt-in there, conflicting with main now): CsInterface::lds_dwords, the declared layout, the ComputePolicyKey field, the clamp condition.
  • raylitebull's amd-dev port 5e488781 (on by default there): the safe barrier's placement and the GPU test.

The first commit credits both as co-authors.

Kalmarv's numbers on #2937:

  • RTX 5070 Ti, the retail title: the late frame's compute went from about 89 to about 78 ms per present (per-program GPU timestamps over 187–229 s).
  • 491 of the 497 compute programs that use LDS shrink below 8,192 dwords.
  • amd-dev measured offline that the title's top open-world program goes from 32,768 to 5,008 bytes of LDS (Radeon GPU Analyzer, gfx1201).

What is in it

  • crates/xcl/src/gpu/recomp/mod.rs, recomp/lower.rs: CsInterface::lds_dwords (LDS_SIZE × 128)
  • crates/xcl/src/gpu/dxil/lanes.rs (setup_storage), kernel.rs (declared_lds_enabled, the test switch), lower.rs, lower_mem.rs: the layout and the clamp
  • crates/xcl/src/gpu/recomp/pso.rs, hle/d3d12x/real/compute_build_key.rs: cache identities (xcl-declared-lds-0 when off) and ComputePolicyKey.declared_lds
  • Tests:
    • the declared sizes (native wave32 / wave64, 1 and 2 waves, split with a barrier, size 0, too big);
    • declared_lds_accesses_stop_below_the_translators_words (disassembly: block size, accesses past the end sent to the sink word 128, translator words at 129..131 / split 153..155);
    • a GPU test of a 16×8 group in native wave32, native wave64 and split wave64, on and off, writing past the declared LDS;
    • the build-key test.
  • Second commit, Recompiler: drop direct compute LDS accesses past the declared block (lanes.rs, lower.rs, lower_mem.rs, kernel.rs): the first commit clamped an access past the declared LDS onto its last dword, so an out-of-range store overwrote it. Now setup_storage puts a sink word after the declared LDS, and lds_index sends any dword index at or past the declared size to the sink (checked before the 32 KB wrap) with an in-bounds flag. Stores and atomics there leave the program's LDS alone. Reads, returning atomics and each dword of a wide or paired access give 0. Each address of a paired instruction is checked on its own. New GPU tests in core_tests.rs, one wave32 thread with 128 declared dwords:
    • thehollowedone's gpu_compute_declared_lds_drops_out_of_bounds_store;
    • gpu_compute_declared_lds_checks_each_address_of_a_pair (ds_write2_b32 / ds_read2_b32 across the end);
    • gpu_compute_declared_lds_reads_zero_past_its_end (ds_read_b64 at the last dword, an address that wraps onto it in 32 KB, a ds_add_rtn_u32 past the end).

Tested

  • On the second commit (f33cb350): NVIDIA GeForce RTX 5070 Ti (driver 621.14), AMD Ryzen 7 7800X3D, Windows 11 build 26300, Rust 1.100.0 (stable-x86_64-pc-windows-msvc), debug tests, release smoke:
    • cargo test --workspace --no-fail-fast -- --test-threads=4: 2896 passed, 0 failed, 51 ignored. SKIPPED: 27 notices (23 no wave64, 2 no heap windows, 1 no D3D12 debug layer, 1 driver cache needs Developer Mode). The two runs before it ended early when the lib test binary crashed in gpu::agility::tests::create_device_sets_dred_first, inside the NVIDIA driver. That is a known intermittent crash on this machine, and the test is unrelated to this change.
    • The three new GPU tests without the second commit's runtime change (its tests kept): [22, 22] instead of [11, 0], [22, 22, 22, 22] instead of [11, 0, 0, 11], [11, 11, 11, 11, 22] instead of [11, 0, 0, 0, 11]. With it, all three pass.
    • Retail title: the 60 s smoke runs below, of main 1c8b5514 and of f33cb350.
  • On the first commit: NVIDIA GeForce RTX 5070 Ti (driver 32.0.16.2114) and AMD Radeon RDNA2 iGPU (driver 32.0.21030, XCL_ADAPTER=radeon), AMD Ryzen 7 7800X3D, Windows 11 build 26300, Rust 1.100.0 (stable-x86_64-pc-windows-msvc), debug tests, release smoke
  • cargo test -p xcl --lib gpu::dxil: 283 passed, 0 failed, 3 ignored, on each of:
    • the 5070 Ti;
    • the iGPU;
    • the iGPU with XCL_SPLIT_WAVE64=1.
  • gpu::recomp + compute_build_key: 508 passed, 0 failed, 21 ignored on each of the same three. With XCL_DECLARED_LDS=0 (5070 Ti), gpu::dxil + declared_lds: 284 passed, 0 failed.
  • cargo test --workspace --no-fail-fast -- --test-threads=4 on 39f4df54, rebased on main 86e86fcb (5070 Ti): 2893 passed, 0 failed, 51 ignored. SKIPPED: 29 notices, almost all no wave64 (the others: no D3D12 debug layer, heap windows off, driver cache needs Developer Mode). The narrower runs listed here are from before the rebase.

Regression run

main:

xcl-smoke v1
commit: 1c8b551475e1e7bfe48f94448492a4c3544a2e0f
gpu: NVIDIA GeForce RTX 5070 Ti
title: 3cb1d8e0
seconds: 60
exit: 0x0
frames shown: 1555 (PresentX 1555)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 18293 MB

this PR:

xcl-smoke v1
commit: f33cb35037f4648dc26d6665d3804bc77bd8ff30
gpu: NVIDIA GeForce RTX 5070 Ti
title: 3cb1d8e0
seconds: 60
exit: 0x0
frames shown: 1570 (PresentX 1570)
presents per 2 s (last 3): 61 60 60
device removals: 0
crashes: 0
peak commit: 15976 MB

Not tested

  • The frame-time gain was not measured here (#2937's numbers above are Kalmarv's); RDNA3 / RDNA4
  • The first commit's GPU test cannot see a missing clamp (both drivers tolerate the stray writes); the disassembly test and the three new GPU tests fail without it
  • The second commit on AMD and with native wave64: this PC has only the RTX 5070 Ti (wave32), so the wave64 cases were skipped
  • A program that accesses more LDS than it declares now has those accesses dropped (reads give 0), as on RDNA2. Before this PR they reached the rest of the 32 KB block. How often the title does that is not known. A declaration with no room for the sink word (all 8,192 dwords) keeps the 8,192-dword block, where they wrap at 32 KB as on main. The HLSL path keeps that block too.
  • HANDOFF.md line 106 ("groupshared, 32 KB = the D3D12 limit") is no longer true for direct compute

AI use

  • Claude Code with Claude Opus 5.5: combined #2937 and 5e488781 on #3468, wrote the extra tests, ran the tests on both GPUs and the smoke runs, wrote this description.
  • Claude Code with Claude Opus 5.5 wrote the second commit (the out-of-bounds fix and its tests; the first test is thehollowedone's regression from the PR thread), ran its tests, the suite and the smoke runs, and updated this description.
  • Original code: Kalmarv's #2937 (Claude Code, Claude Opus 5.5; Antigravity, Gemini 4 Neon) and raylitebull's amd-dev 5e488781.

🤖 Generated with Claude Code

<!-- greyfinch-sync:ivall/xcl:issue:5556568922 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3478). Originally posted by [Foniass](https://github.com/Foniass) on 2026-11-29T23:59:58Z. --- Rebased directly onto main: #3468 is closed, because main's ada50ec5 (#3497) already clamps LDS accesses whenever `lds_top < 8191`. The direct DXIL translator gives every compute program that uses LDS the whole 8,192-dword groupshared block, so a one-wave group holds 32 KB and few groups stay resident at once. With this PR the block is: - the LDS the program's COMPUTE_PGM_RSRC2 declares; - then the translator's own words: the safe barrier's two words from #3264, a native 2-D / 3-D group's arrival counter, and the split form's exchange words. A sink word sits between the program's LDS and the translator's words: a program access past the declared size goes there, so a store has no effect on the program's LDS and a read gives 0, as on RDNA2 (second commit, after thehollowedone's out-of-bounds finding). A header with no size, or one too large to leave room for the sink and those words, keeps the 8,192-dword layout. Mesh, geometry and the HLSL path are unchanged. On by default; `XCL_DECLARED_LDS=0` brings back the 8,192-dword layout. The disk caches and `ComputePolicyKey` keep the two apart. This combines two earlier versions: - Kalmarv's #2937 (opt-in there, conflicting with main now): `CsInterface::lds_dwords`, the declared layout, the `ComputePolicyKey` field, the clamp condition. - raylitebull's amd-dev port `5e488781` (on by default there): the safe barrier's placement and the GPU test. The first commit credits both as co-authors. Kalmarv's numbers on #2937: - RTX 5070 Ti, the retail title: the late frame's compute went from about 89 to about 78 ms per present (per-program GPU timestamps over 187–229 s). - 491 of the 497 compute programs that use LDS shrink below 8,192 dwords. - amd-dev measured offline that the title's top open-world program goes from 32,768 to 5,008 bytes of LDS (Radeon GPU Analyzer, gfx1201). **What is in it** - `crates/xcl/src/gpu/recomp/mod.rs`, `recomp/lower.rs`: `CsInterface::lds_dwords` (LDS_SIZE × 128) - `crates/xcl/src/gpu/dxil/lanes.rs` (`setup_storage`), `kernel.rs` (`declared_lds_enabled`, the test switch), `lower.rs`, `lower_mem.rs`: the layout and the clamp - `crates/xcl/src/gpu/recomp/pso.rs`, `hle/d3d12x/real/compute_build_key.rs`: cache identities (`xcl-declared-lds-0` when off) and `ComputePolicyKey.declared_lds` - Tests: - the declared sizes (native wave32 / wave64, 1 and 2 waves, split with a barrier, size 0, too big); - `declared_lds_accesses_stop_below_the_translators_words` (disassembly: block size, accesses past the end sent to the sink word 128, translator words at 129..131 / split 153..155); - a GPU test of a 16×8 group in native wave32, native wave64 and split wave64, on and off, writing past the declared LDS; - the build-key test. - Second commit, `Recompiler: drop direct compute LDS accesses past the declared block` (`lanes.rs`, `lower.rs`, `lower_mem.rs`, `kernel.rs`): the first commit clamped an access past the declared LDS onto its last dword, so an out-of-range store overwrote it. Now `setup_storage` puts a sink word after the declared LDS, and `lds_index` sends any dword index at or past the declared size to the sink (checked before the 32 KB wrap) with an in-bounds flag. Stores and atomics there leave the program's LDS alone. Reads, returning atomics and each dword of a wide or paired access give 0. Each address of a paired instruction is checked on its own. New GPU tests in `core_tests.rs`, one wave32 thread with 128 declared dwords: - thehollowedone's `gpu_compute_declared_lds_drops_out_of_bounds_store`; - `gpu_compute_declared_lds_checks_each_address_of_a_pair` (`ds_write2_b32` / `ds_read2_b32` across the end); - `gpu_compute_declared_lds_reads_zero_past_its_end` (`ds_read_b64` at the last dword, an address that wraps onto it in 32 KB, a `ds_add_rtn_u32` past the end). **Tested** - On the second commit (f33cb350): NVIDIA GeForce RTX 5070 Ti (driver 621.14), AMD Ryzen 7 7800X3D, Windows 11 build 26300, Rust 1.100.0 (stable-x86_64-pc-windows-msvc), debug tests, release smoke: - `cargo test --workspace --no-fail-fast -- --test-threads=4`: 2896 passed, 0 failed, 51 ignored. SKIPPED: 27 notices (23 `no wave64`, 2 no heap windows, 1 no D3D12 debug layer, 1 driver cache needs Developer Mode). The two runs before it ended early when the lib test binary crashed in `gpu::agility::tests::create_device_sets_dred_first`, inside the NVIDIA driver. That is a known intermittent crash on this machine, and the test is unrelated to this change. - The three new GPU tests without the second commit's runtime change (its tests kept): `[22, 22]` instead of `[11, 0]`, `[22, 22, 22, 22]` instead of `[11, 0, 0, 11]`, `[11, 11, 11, 11, 22]` instead of `[11, 0, 0, 0, 11]`. With it, all three pass. - Retail title: the 60 s smoke runs below, of main 1c8b5514 and of f33cb350. - On the first commit: NVIDIA GeForce RTX 5070 Ti (driver 32.0.16.2114) and AMD Radeon RDNA2 iGPU (driver 32.0.21030, `XCL_ADAPTER=radeon`), AMD Ryzen 7 7800X3D, Windows 11 build 26300, Rust 1.100.0 (stable-x86_64-pc-windows-msvc), debug tests, release smoke - `cargo test -p xcl --lib gpu::dxil`: 283 passed, 0 failed, 3 ignored, on each of: - the 5070 Ti; - the iGPU; - the iGPU with `XCL_SPLIT_WAVE64=1`. - `gpu::recomp` + `compute_build_key`: 508 passed, 0 failed, 21 ignored on each of the same three. With `XCL_DECLARED_LDS=0` (5070 Ti), `gpu::dxil` + `declared_lds`: 284 passed, 0 failed. - `cargo test --workspace --no-fail-fast -- --test-threads=4` on 39f4df54, rebased on main 86e86fcb (5070 Ti): 2893 passed, 0 failed, 51 ignored. SKIPPED: 29 notices, almost all `no wave64` (the others: no D3D12 debug layer, heap windows off, driver cache needs Developer Mode). The narrower runs listed here are from before the rebase. **Regression run** main: ``` xcl-smoke v1 commit: 1c8b551475e1e7bfe48f94448492a4c3544a2e0f gpu: NVIDIA GeForce RTX 5070 Ti title: 3cb1d8e0 seconds: 60 exit: 0x0 frames shown: 1555 (PresentX 1555) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 18293 MB ``` this PR: ``` xcl-smoke v1 commit: f33cb35037f4648dc26d6665d3804bc77bd8ff30 gpu: NVIDIA GeForce RTX 5070 Ti title: 3cb1d8e0 seconds: 60 exit: 0x0 frames shown: 1570 (PresentX 1570) presents per 2 s (last 3): 61 60 60 device removals: 0 crashes: 0 peak commit: 15976 MB ``` **Not tested** - The frame-time gain was not measured here (#2937's numbers above are Kalmarv's); RDNA3 / RDNA4 - The first commit's GPU test cannot see a missing clamp (both drivers tolerate the stray writes); the disassembly test and the three new GPU tests fail without it - The second commit on AMD and with native wave64: this PC has only the RTX 5070 Ti (wave32), so the wave64 cases were skipped - A program that accesses more LDS than it declares now has those accesses dropped (reads give 0), as on RDNA2. Before this PR they reached the rest of the 32 KB block. How often the title does that is not known. A declaration with no room for the sink word (all 8,192 dwords) keeps the 8,192-dword block, where they wrap at 32 KB as on main. The HLSL path keeps that block too. - `HANDOFF.md` line 106 ("groupshared, 32 KB = the D3D12 limit") is no longer true for direct compute **AI use** - Claude Code with Claude Opus 5.5: combined #2937 and `5e488781` on #3468, wrote the extra tests, ran the tests on both GPUs and the smoke runs, wrote this description. - Claude Code with Claude Opus 5.5 wrote the second commit (the out-of-bounds fix and its tests; the first test is thehollowedone's regression from the PR thread), ran its tests, the suite and the smoke runs, and updated this description. - Original code: Kalmarv's #2937 (Claude Code, Claude Opus 5.5; Antigravity, Gemini 4 Neon) and raylitebull's amd-dev `5e488781`. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
thehollowedone commented 2026-12-01 01:45:58 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by thehollowedone on 2026-12-01T01:45:58Z.


I reran the 512-byte LDS boundary case against head 39f4df54 and its clean merge with main at d0832e6. This is now a measured blocking regression, not just a source prediction.

A native wave32 kernel declares 128 LDS dwords (512 bytes), sets M0 to 0xffff, writes 11 at byte 508 and 22 at byte 516, then reads both. AMD's RDNA2 ISA guide, §3.6.1 gives [11, 0]: the second write is out of range and discarded, and its read returns zero. On the PR head and clean merge, the GPU produced [22, 22]. On the same current main control, it produced [11, 22]: the old path already exposes an out-of-range read, while this PR additionally corrupts the final valid word. Each identical focused run failed 0 passed / 1 failed, with 0 ignored and 0 GPU skips.

The source cause is lds_index: umin(i, lds_top) maps both word 127 and word 129 to word 127. Keep the fitted guest byte limit separately from the allocated storage top. Check each original guest byte address before masking or mapping it. Out-of-range stores and atomics must have no memory effect; returning reads/atomics must yield zero while preserving inactive destination lanes and the untouched D16 half. Check both addresses of a paired DS instruction independently. Keep the existing fallback mapping when the declaration does not fit, and apply the guest bound even when the declaration fills all 8,192 words. Please add the boundary regression below and cover those other DS forms before merging; the scalar case alone does not verify wide or paired behavior.

Measured locally: Windows 11 build 26300, RTX 3080 Ti (driver 621.40), Rust 1.99.1 MSVC, DXC 1.8.2502.11. In three isolated worktrees (head, main, clean merge), cargo test --offline --locked -p xcl --lib gpu_probe_3478_last_lds_word -- --nocapture --test-threads=1 gave 0 passed / 1 failed / 0 ignored / 0 skipped in each. I did not run the full workspace suite or a title smoke on this test-only probe.

Minimal failing GPU regression (test-only candidate)
diff --git a/crates/xcl/src/gpu/dxil/core_tests.rs b/crates/xcl/src/gpu/dxil/core_tests.rs
@@
+#[test]
+fn gpu_compute_declared_lds_drops_out_of_bounds_store() {
+    use crate::gpu::recomp::{runner, CsInterface, KERNEL_SGPRS};
+    assert_eq!(runner::wave32_supported(), Ok(true));
+    let code = prog(&[
+        ("S_MOV_B32", "ENC_SOP1", &[("SDST", 124), ("SSRC0", 255)], Some(0xffff)),
+        ("V_MOV_B32", "ENC_VOP1", &[("VDST", 1), ("SRC0", 255)], Some(508)),
+        ("V_MOV_B32", "ENC_VOP1", &[("VDST", 2), ("SRC0", 255)], Some(516)),
+        ("V_MOV_B32", "ENC_VOP1", &[("VDST", 3), ("SRC0", 139)], None),
+        ("V_MOV_B32", "ENC_VOP1", &[("VDST", 4), ("SRC0", 150)], None),
+        ("DS_WRITE_B32", "ENC_DS", &[("ADDR", 1), ("DATA0", 3)], None),
+        ("DS_WRITE_B32", "ENC_DS", &[("ADDR", 2), ("DATA0", 4)], None),
+        ("S_WAITCNT", "ENC_SOPP", &[("SIMM16", 0)], None),
+        ("DS_READ_B32", "ENC_DS", &[("ADDR", 1), ("VDST", 5)], None),
+        ("DS_READ_B32", "ENC_DS", &[("ADDR", 2), ("VDST", 6)], None),
+        ("S_WAITCNT", "ENC_SOPP", &[("SIMM16", 0)], None),
+        ("V_MOV_B32", "ENC_VOP1", &[("VDST", 8), ("SRC0", 128)], None),
+        ("V_MOV_B32", "ENC_VOP1", &[("VDST", 9), ("SRC0", 128)], None),
+        ("GLOBAL_STORE_DWORD", "ENC_FLAT_GLBL", &[("ADDR", 8), ("DATA", 5), ("SADDR", 0x7d)], None),
+        ("GLOBAL_STORE_DWORD", "ENC_FLAT_GLBL", &[("ADDR", 8), ("DATA", 6), ("SADDR", 0x7d), ("OFFSET", 4)], None),
+    ]);
+    let mut descriptor = [0u8; 0x48];
+    for (i, v) in [(1u32 << 15) | (1 << 11), 1, 1, 1].into_iter().enumerate() {
+        descriptor[0x38 + 4*i..0x3c + 4*i].copy_from_slice(&v.to_le_bytes());
+    }
+    let cs = CsInterface::from_descriptor(&descriptor, 0).unwrap();
+    let opts = KernelOptions { wave64: false, split: false, mem_windows: 1, sampler_base: 0 };
+    let kernel = super::kernel::translate_compute(&code, opts, &cs).unwrap();
+    let output = runner::dispatch(&kernel.dxil, [1, 1, 1], &vec![0; KERNEL_SGPRS], &[u32::MAX; 2]).unwrap();
+    assert_eq!(&output[..2], &[11, 0]);
+}

AI use: Codex (GPT-6.2 Sol) wrote and ran the GPU regression; Codex (GPT-6.2 Astra) independently checked the boundary semantics and source paths.

<!-- greyfinch-sync:ivall/xcl:comment:7297869394 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3478#issuecomment-7297869394). Originally posted by [thehollowedone](https://github.com/thehollowedone) on 2026-12-01T01:45:58Z. --- I reran the 512-byte LDS boundary case against [head `39f4df54`](https://github.com/xcl-dev/xcl/commit/39f4df5416a4bb108ac1fb1fe708b292f590ac4d) and its clean merge with `main` at [`d0832e6`](https://github.com/xcl-dev/xcl/commit/d0832e614fa7d6ae027bb4feb27ccb9121f54a8f). This is now a measured blocking regression, not just a source prediction. A native wave32 kernel declares 128 LDS dwords (512 bytes), sets M0 to `0xffff`, writes `11` at byte 508 and `22` at byte 516, then reads both. [AMD's RDNA2 ISA guide, §3.6.1](https://www.amd.com/content/dam/amd/en/documents/radeon-tech-docs/instruction-set-architectures/rdna2-shader-instruction-set-architecture.pdf) gives `[11, 0]`: the second write is out of range and discarded, and its read returns zero. On the PR head and clean merge, the GPU produced **`[22, 22]`**. On the same current `main` control, it produced `[11, 22]`: the old path already exposes an out-of-range read, while this PR additionally corrupts the final valid word. Each identical focused run failed 0 passed / 1 failed, with 0 ignored and 0 GPU skips. The source cause is [`lds_index`](https://github.com/xcl-dev/xcl/blob/39f4df5416a4bb108ac1fb1fe708b292f590ac4d/crates/xcl/src/gpu/dxil/lower_mem.rs#L2226-L2245): `umin(i, lds_top)` maps both word 127 and word 129 to word 127. Keep the fitted **guest byte limit** separately from the allocated storage top. Check each original guest byte address before masking or mapping it. Out-of-range stores and atomics must have no memory effect; returning reads/atomics must yield zero while preserving inactive destination lanes and the untouched D16 half. Check both addresses of a paired DS instruction independently. Keep the existing fallback mapping when the declaration does not fit, and apply the guest bound even when the declaration fills all 8,192 words. Please add the boundary regression below and cover those other DS forms before merging; the scalar case alone does not verify wide or paired behavior. **Measured locally:** Windows 11 build 26300, RTX 3080 Ti (driver 621.40), Rust 1.99.1 MSVC, DXC 1.8.2502.11. In three isolated worktrees (head, `main`, clean merge), `cargo test --offline --locked -p xcl --lib gpu_probe_3478_last_lds_word -- --nocapture --test-threads=1` gave 0 passed / 1 failed / 0 ignored / 0 skipped in each. I did not run the full workspace suite or a title smoke on this test-only probe. <details> <summary>Minimal failing GPU regression (test-only candidate)</summary> ```diff diff --git a/crates/xcl/src/gpu/dxil/core_tests.rs b/crates/xcl/src/gpu/dxil/core_tests.rs @@ +#[test] +fn gpu_compute_declared_lds_drops_out_of_bounds_store() { + use crate::gpu::recomp::{runner, CsInterface, KERNEL_SGPRS}; + assert_eq!(runner::wave32_supported(), Ok(true)); + let code = prog(&[ + ("S_MOV_B32", "ENC_SOP1", &[("SDST", 124), ("SSRC0", 255)], Some(0xffff)), + ("V_MOV_B32", "ENC_VOP1", &[("VDST", 1), ("SRC0", 255)], Some(508)), + ("V_MOV_B32", "ENC_VOP1", &[("VDST", 2), ("SRC0", 255)], Some(516)), + ("V_MOV_B32", "ENC_VOP1", &[("VDST", 3), ("SRC0", 139)], None), + ("V_MOV_B32", "ENC_VOP1", &[("VDST", 4), ("SRC0", 150)], None), + ("DS_WRITE_B32", "ENC_DS", &[("ADDR", 1), ("DATA0", 3)], None), + ("DS_WRITE_B32", "ENC_DS", &[("ADDR", 2), ("DATA0", 4)], None), + ("S_WAITCNT", "ENC_SOPP", &[("SIMM16", 0)], None), + ("DS_READ_B32", "ENC_DS", &[("ADDR", 1), ("VDST", 5)], None), + ("DS_READ_B32", "ENC_DS", &[("ADDR", 2), ("VDST", 6)], None), + ("S_WAITCNT", "ENC_SOPP", &[("SIMM16", 0)], None), + ("V_MOV_B32", "ENC_VOP1", &[("VDST", 8), ("SRC0", 128)], None), + ("V_MOV_B32", "ENC_VOP1", &[("VDST", 9), ("SRC0", 128)], None), + ("GLOBAL_STORE_DWORD", "ENC_FLAT_GLBL", &[("ADDR", 8), ("DATA", 5), ("SADDR", 0x7d)], None), + ("GLOBAL_STORE_DWORD", "ENC_FLAT_GLBL", &[("ADDR", 8), ("DATA", 6), ("SADDR", 0x7d), ("OFFSET", 4)], None), + ]); + let mut descriptor = [0u8; 0x48]; + for (i, v) in [(1u32 << 15) | (1 << 11), 1, 1, 1].into_iter().enumerate() { + descriptor[0x38 + 4*i..0x3c + 4*i].copy_from_slice(&v.to_le_bytes()); + } + let cs = CsInterface::from_descriptor(&descriptor, 0).unwrap(); + let opts = KernelOptions { wave64: false, split: false, mem_windows: 1, sampler_base: 0 }; + let kernel = super::kernel::translate_compute(&code, opts, &cs).unwrap(); + let output = runner::dispatch(&kernel.dxil, [1, 1, 1], &vec![0; KERNEL_SGPRS], &[u32::MAX; 2]).unwrap(); + assert_eq!(&output[..2], &[11, 0]); +} ``` </details> AI use: Codex (GPT-6.2 Sol) wrote and ran the GPU regression; Codex (GPT-6.2 Astra) independently checked the boundary semantics and source paths.
bmjask commented 2026-12-02 07:48:24 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T07:48:24Z.

Code review location: crates/xcl/src/gpu/dxil/lanes.rs; line 57

@@ -21,28 +21,43 @@ impl Lw {
     /// the program's LDS (`lds_words` > 0), multi-wave safe-barrier counters
     /// (`safe_bar`, 2 words), and, in the split form, the halves' exchange
     /// words — in the top of the LDS block when there is one (D3D12 allows
-    /// 32 KB, the whole LDS), as the HLSL kernel lays it out.
-    pub fn setup_storage(&mut self, lds: bool, slot: u32, safe_bar: bool) {
+    /// 32 KB, the whole LDS), as the HLSL kernel lays it out. With `declared`
+    /// dwords (`XCL_DECLARED_LDS`, 0 = not known) the block is the program's
+    /// LDS followed by those words (and a native 2-D / 3-D group's arrival
+    /// counter, `native_counter`), when they fit in 8,192.
+    pub fn setup_storage(&mut self, lds: bool, slot: u32, safe_bar: bool, declared: u32, native_counter: bool) {
         let i32 = self.s.m.i32();
         self.xslot = slot.max(1);
         if lds {
-            let g = self.s.groupshared("xcl_lds", i32, 8192);
+            // the translator's words at the top: [exchange slots, counters (split)],
+            // [XCL_BAR_ALIVE, XCL_BAR_STATE (safe_bar)], XCL_XW / XCL_WT
+            let bar_words = if safe_bar { 2 } else { 0 };
+            let slots = 4 * self.xslot * self.waves;
+            let control = if self.split { slots + 2 * self.waves + 1 + bar_words } else { bar_words + u32::from(native_counter) };
+            let fits = declared != 0 && declared <= 8192u32.saturating_sub(control);
+            let words = if fits { declared + control } else { 8192 };
+            let g = self.s.groupshared("xcl_lds", i32, words as u64);
             self.lds = Some(g);
             if safe_bar {
                 // Words 8189 = XCL_BAR_ALIVE, 8190 = XCL_BAR_STATE (8191 = XCL_XW / XCL_WT),
-                // matching `recomp::emit::safe_barrier_prelude`.
-                self.safe_bar = Some((g, 8189));
+                // matching `recomp::emit::safe_barrier_prelude`; with the declared LDS of a
+                // native group right after the program's
+                self.safe_bar = Some((g, if fits && !self.split { declared } else { words - 3 }));
             }
             if self.split {
                 // HLSL: exchange base = 8192 - slots - counters - 1 (- 2 if safe_bar)
                 // (slots = 4 · slot per console wave, 2 counters each); program LDS stops below it.
-                let bar_words = if safe_bar { 2 } else { 0 };
-                let slots = 4 * self.xslot * self.waves;
-                let base = 8192 - slots - 2 * self.waves - 1 - bar_words;
+                let base = words - control;
                 self.lds_top = base - 1;
                 self.xs = Some((g, base));
                 self.xc = Some((g, base + slots));
-                self.xw = Some((g, 8191));
+                self.xw = Some((g, words - 1));
+            } else if fits {
+                // `lds_index` clamps below the translator's words (`lds_top` < 8191)
+                self.lds_top = declared - 1;

In the native (non-split) declared layout, lds_top = declared - 1 makes lds_index clamp any out-of-range LDS access onto the program's last declared dword. Out-of-range writes now overwrite real data there and out-of-range reads return it. On RDNA such writes are dropped and reads return 0, and on main they landed in unused space of the 8,192-dword block. Take a wave32 program that declares 1 granule (128 dwords) and keeps a live value in dword 127. A lane writing past the end at dword 256 is clamped to 127 and replaces it, and a ds_read_b64 at dword 127 returns d127 twice instead of (d127, 0). Guarding the access (skip the store, return 0) instead of clamping would match the hardware. The PR lists this under Not tested.

<!-- greyfinch-sync:ivall/xcl:review-comment:4766287652 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3478#discussion_r4766287652). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T07:48:24Z. **Code review location:** `crates/xcl/src/gpu/dxil/lanes.rs`; line 57 ~~~~diff @@ -21,28 +21,43 @@ impl Lw { /// the program's LDS (`lds_words` > 0), multi-wave safe-barrier counters /// (`safe_bar`, 2 words), and, in the split form, the halves' exchange /// words — in the top of the LDS block when there is one (D3D12 allows - /// 32 KB, the whole LDS), as the HLSL kernel lays it out. - pub fn setup_storage(&mut self, lds: bool, slot: u32, safe_bar: bool) { + /// 32 KB, the whole LDS), as the HLSL kernel lays it out. With `declared` + /// dwords (`XCL_DECLARED_LDS`, 0 = not known) the block is the program's + /// LDS followed by those words (and a native 2-D / 3-D group's arrival + /// counter, `native_counter`), when they fit in 8,192. + pub fn setup_storage(&mut self, lds: bool, slot: u32, safe_bar: bool, declared: u32, native_counter: bool) { let i32 = self.s.m.i32(); self.xslot = slot.max(1); if lds { - let g = self.s.groupshared("xcl_lds", i32, 8192); + // the translator's words at the top: [exchange slots, counters (split)], + // [XCL_BAR_ALIVE, XCL_BAR_STATE (safe_bar)], XCL_XW / XCL_WT + let bar_words = if safe_bar { 2 } else { 0 }; + let slots = 4 * self.xslot * self.waves; + let control = if self.split { slots + 2 * self.waves + 1 + bar_words } else { bar_words + u32::from(native_counter) }; + let fits = declared != 0 && declared <= 8192u32.saturating_sub(control); + let words = if fits { declared + control } else { 8192 }; + let g = self.s.groupshared("xcl_lds", i32, words as u64); self.lds = Some(g); if safe_bar { // Words 8189 = XCL_BAR_ALIVE, 8190 = XCL_BAR_STATE (8191 = XCL_XW / XCL_WT), - // matching `recomp::emit::safe_barrier_prelude`. - self.safe_bar = Some((g, 8189)); + // matching `recomp::emit::safe_barrier_prelude`; with the declared LDS of a + // native group right after the program's + self.safe_bar = Some((g, if fits && !self.split { declared } else { words - 3 })); } if self.split { // HLSL: exchange base = 8192 - slots - counters - 1 (- 2 if safe_bar) // (slots = 4 · slot per console wave, 2 counters each); program LDS stops below it. - let bar_words = if safe_bar { 2 } else { 0 }; - let slots = 4 * self.xslot * self.waves; - let base = 8192 - slots - 2 * self.waves - 1 - bar_words; + let base = words - control; self.lds_top = base - 1; self.xs = Some((g, base)); self.xc = Some((g, base + slots)); - self.xw = Some((g, 8191)); + self.xw = Some((g, words - 1)); + } else if fits { + // `lds_index` clamps below the translator's words (`lds_top` < 8191) + self.lds_top = declared - 1; ~~~~ --- In the native (non-split) declared layout, `lds_top = declared - 1` makes `lds_index` clamp any out-of-range LDS access onto the program's last declared dword. Out-of-range writes now overwrite real data there and out-of-range reads return it. On RDNA such writes are dropped and reads return 0, and on main they landed in unused space of the 8,192-dword block. Take a wave32 program that declares 1 granule (128 dwords) and keeps a live value in dword 127. A lane writing past the end at dword 256 is clamped to 127 and replaces it, and a `ds_read_b64` at dword 127 returns d127 twice instead of (d127, 0). Guarding the access (skip the store, return 0) instead of clamping would match the hardware. The PR lists this under Not tested.
bmjask commented 2026-12-02 07:48:24 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T07:48:24Z.

Code review location: crates/xcl/src/gpu/dxil/lanes.rs; line 62

@@ -21,28 +21,43 @@ impl Lw {
     /// the program's LDS (`lds_words` > 0), multi-wave safe-barrier counters
     /// (`safe_bar`, 2 words), and, in the split form, the halves' exchange
     /// words — in the top of the LDS block when there is one (D3D12 allows
-    /// 32 KB, the whole LDS), as the HLSL kernel lays it out.
-    pub fn setup_storage(&mut self, lds: bool, slot: u32, safe_bar: bool) {
+    /// 32 KB, the whole LDS), as the HLSL kernel lays it out. With `declared`
+    /// dwords (`XCL_DECLARED_LDS`, 0 = not known) the block is the program's
+    /// LDS followed by those words (and a native 2-D / 3-D group's arrival
+    /// counter, `native_counter`), when they fit in 8,192.
+    pub fn setup_storage(&mut self, lds: bool, slot: u32, safe_bar: bool, declared: u32, native_counter: bool) {
         let i32 = self.s.m.i32();
         self.xslot = slot.max(1);
         if lds {
-            let g = self.s.groupshared("xcl_lds", i32, 8192);
+            // the translator's words at the top: [exchange slots, counters (split)],
+            // [XCL_BAR_ALIVE, XCL_BAR_STATE (safe_bar)], XCL_XW / XCL_WT
+            let bar_words = if safe_bar { 2 } else { 0 };
+            let slots = 4 * self.xslot * self.waves;
+            let control = if self.split { slots + 2 * self.waves + 1 + bar_words } else { bar_words + u32::from(native_counter) };
+            let fits = declared != 0 && declared <= 8192u32.saturating_sub(control);
+            let words = if fits { declared + control } else { 8192 };
+            let g = self.s.groupshared("xcl_lds", i32, words as u64);
             self.lds = Some(g);
             if safe_bar {
                 // Words 8189 = XCL_BAR_ALIVE, 8190 = XCL_BAR_STATE (8191 = XCL_XW / XCL_WT),
-                // matching `recomp::emit::safe_barrier_prelude`.
-                self.safe_bar = Some((g, 8189));
+                // matching `recomp::emit::safe_barrier_prelude`; with the declared LDS of a
+                // native group right after the program's
+                self.safe_bar = Some((g, if fits && !self.split { declared } else { words - 3 }));
             }
             if self.split {
                 // HLSL: exchange base = 8192 - slots - counters - 1 (- 2 if safe_bar)
                 // (slots = 4 · slot per console wave, 2 counters each); program LDS stops below it.
-                let bar_words = if safe_bar { 2 } else { 0 };
-                let slots = 4 * self.xslot * self.waves;
-                let base = 8192 - slots - 2 * self.waves - 1 - bar_words;
+                let base = words - control;
                 self.lds_top = base - 1;
                 self.xs = Some((g, base));
                 self.xc = Some((g, base + slots));
-                self.xw = Some((g, 8191));
+                self.xw = Some((g, words - 1));
+            } else if fits {
+                // `lds_index` clamps below the translator's words (`lds_top` < 8191)
+                self.lds_top = declared - 1;
+                if native_counter {
+                    self.xw = Some((g, words - 1));
+                }
             } else {
                 self.lds_top = if safe_bar { 8188 } else { 8191 };

When the declared LDS plus the translator's words don't fit (e.g. a full 64-granule / 8,192-dword declaration), the code falls back to 8,192 dwords with lds_top = 8188 (safe barrier) or the split base, so the program's own top declared dwords clamp onto one shared index or overlap XCL_WT. A native wave32 group of 256 threads with s_barrier and LDS_SIZE=64 gets fits false and lds_top = 8188. Its writes to dwords 8189/8190/8191 all go to 8188, and a later read of 8190 returns whichever was written last. These lines are older, but the new fits logic detects the condition and keeps the aliasing layout. Moving the translator's words to a separate small groupshared array, rather than the program's own LDS, would avoid it.

<!-- greyfinch-sync:ivall/xcl:review-comment:4766287661 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3478#discussion_r4766287661). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T07:48:24Z. **Code review location:** `crates/xcl/src/gpu/dxil/lanes.rs`; line 62 ~~~~diff @@ -21,28 +21,43 @@ impl Lw { /// the program's LDS (`lds_words` > 0), multi-wave safe-barrier counters /// (`safe_bar`, 2 words), and, in the split form, the halves' exchange /// words — in the top of the LDS block when there is one (D3D12 allows - /// 32 KB, the whole LDS), as the HLSL kernel lays it out. - pub fn setup_storage(&mut self, lds: bool, slot: u32, safe_bar: bool) { + /// 32 KB, the whole LDS), as the HLSL kernel lays it out. With `declared` + /// dwords (`XCL_DECLARED_LDS`, 0 = not known) the block is the program's + /// LDS followed by those words (and a native 2-D / 3-D group's arrival + /// counter, `native_counter`), when they fit in 8,192. + pub fn setup_storage(&mut self, lds: bool, slot: u32, safe_bar: bool, declared: u32, native_counter: bool) { let i32 = self.s.m.i32(); self.xslot = slot.max(1); if lds { - let g = self.s.groupshared("xcl_lds", i32, 8192); + // the translator's words at the top: [exchange slots, counters (split)], + // [XCL_BAR_ALIVE, XCL_BAR_STATE (safe_bar)], XCL_XW / XCL_WT + let bar_words = if safe_bar { 2 } else { 0 }; + let slots = 4 * self.xslot * self.waves; + let control = if self.split { slots + 2 * self.waves + 1 + bar_words } else { bar_words + u32::from(native_counter) }; + let fits = declared != 0 && declared <= 8192u32.saturating_sub(control); + let words = if fits { declared + control } else { 8192 }; + let g = self.s.groupshared("xcl_lds", i32, words as u64); self.lds = Some(g); if safe_bar { // Words 8189 = XCL_BAR_ALIVE, 8190 = XCL_BAR_STATE (8191 = XCL_XW / XCL_WT), - // matching `recomp::emit::safe_barrier_prelude`. - self.safe_bar = Some((g, 8189)); + // matching `recomp::emit::safe_barrier_prelude`; with the declared LDS of a + // native group right after the program's + self.safe_bar = Some((g, if fits && !self.split { declared } else { words - 3 })); } if self.split { // HLSL: exchange base = 8192 - slots - counters - 1 (- 2 if safe_bar) // (slots = 4 · slot per console wave, 2 counters each); program LDS stops below it. - let bar_words = if safe_bar { 2 } else { 0 }; - let slots = 4 * self.xslot * self.waves; - let base = 8192 - slots - 2 * self.waves - 1 - bar_words; + let base = words - control; self.lds_top = base - 1; self.xs = Some((g, base)); self.xc = Some((g, base + slots)); - self.xw = Some((g, 8191)); + self.xw = Some((g, words - 1)); + } else if fits { + // `lds_index` clamps below the translator's words (`lds_top` < 8191) + self.lds_top = declared - 1; + if native_counter { + self.xw = Some((g, words - 1)); + } } else { self.lds_top = if safe_bar { 8188 } else { 8191 }; ~~~~ --- When the declared LDS plus the translator's words don't fit (e.g. a full 64-granule / 8,192-dword declaration), the code falls back to 8,192 dwords with `lds_top = 8188` (safe barrier) or the split base, so the program's own top declared dwords clamp onto one shared index or overlap XCL_WT. A native wave32 group of 256 threads with `s_barrier` and LDS_SIZE=64 gets `fits` false and `lds_top = 8188`. Its writes to dwords 8189/8190/8191 all go to 8188, and a later read of 8190 returns whichever was written last. These lines are older, but the new `fits` logic detects the condition and keeps the aliasing layout. Moving the translator's words to a separate small groupshared array, rather than the program's own LDS, would avoid it.
bmjask commented 2026-12-02 07:48:24 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T07:48:24Z.

Review: COMMENTED


Review of 39f4df54: 2 finding(s). 2 are inline.


These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it.

<!-- greyfinch-sync:ivall/xcl:review:6146626429 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3478#pullrequestreview-6146626429). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T07:48:24Z. **Review:** COMMENTED --- Review of `39f4df54`: 2 finding(s). 2 are inline. --- _These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it._
Foniass commented 2026-12-02 09:38:50 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T09:38:50Z.


Fixed in f33cb350, for the out-of-bounds finding above.

The declared layout now has a sink word right after the program's LDS, and the translator's words move up by one. lds_index compares each dword index with the declared size before any 32 KB wrap. An index at or past it goes to the sink, so stores and atomics leave the program's LDS alone, and reads, returning atomics and each dword of a wide or paired access give 0. Each address of a paired instruction is checked on its own. A declaration with no room for the sink (all 8,192 dwords) keeps main's 8,192-dword layout. The HLSL path is unchanged.

New tests in core_tests.rs (one wave32 thread, 128 declared dwords), RTX 5070 Ti:

  • your gpu_compute_declared_lds_drops_out_of_bounds_store: [11, 0], and [22, 22] without the fix;
  • ds_write2_b32 / ds_read2_b32 across the end: [11, 0, 0, 11], and [22, 22, 22, 22] without the fix;
  • the second dword of a ds_read_b64 at the last dword, an address that wraps onto it in 32 KB, a ds_add_rtn_u32 past the end, then the last dword again: [11, 0, 0, 0, 11], and [11, 11, 11, 11, 22] without the fix.

Full suite: 2896 passed, 0 failed, 51 ignored, 27 SKIPPED (23 of them no wave64). The smoke pair is in the description. The D16 and sub-dword forms use the same index check but have no test of their own. Not run on AMD or with native wave64.

AI-assisted: Claude Code (Claude Opus 5.5), posted by Foniass.

<!-- greyfinch-sync:ivall/xcl:comment:7341267095 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3478#issuecomment-7341267095). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-02T09:38:50Z. --- Fixed in f33cb350, for the out-of-bounds finding above. The declared layout now has a sink word right after the program's LDS, and the translator's words move up by one. `lds_index` compares each dword index with the declared size before any 32 KB wrap. An index at or past it goes to the sink, so stores and atomics leave the program's LDS alone, and reads, returning atomics and each dword of a wide or paired access give 0. Each address of a paired instruction is checked on its own. A declaration with no room for the sink (all 8,192 dwords) keeps main's 8,192-dword layout. The HLSL path is unchanged. New tests in `core_tests.rs` (one wave32 thread, 128 declared dwords), RTX 5070 Ti: - your `gpu_compute_declared_lds_drops_out_of_bounds_store`: `[11, 0]`, and `[22, 22]` without the fix; - `ds_write2_b32` / `ds_read2_b32` across the end: `[11, 0, 0, 11]`, and `[22, 22, 22, 22]` without the fix; - the second dword of a `ds_read_b64` at the last dword, an address that wraps onto it in 32 KB, a `ds_add_rtn_u32` past the end, then the last dword again: `[11, 0, 0, 0, 11]`, and `[11, 11, 11, 11, 22]` without the fix. Full suite: 2896 passed, 0 failed, 51 ignored, 27 SKIPPED (23 of them `no wave64`). The smoke pair is in the description. The D16 and sub-dword forms use the same index check but have no test of their own. Not run on AMD or with native wave64. AI-assisted: Claude Code (Claude Opus 5.5), posted by Foniass.
bmjask commented 2026-12-02 09:44:48 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T09:44:48Z.

Review: COMMENTED


Review of f33cb350: 2 finding(s).

Re-review at f33cb350. Accesses past the declared LDS now go to a sink (reads 0, writes dropped), which fixes the clamp-onto-the-last-dword problem from my earlier review. The reviewer traced the layout for split/native, with and without the safe barrier, and found it consistent. Two new points: 2 are inline.


These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it.

<!-- greyfinch-sync:ivall/xcl:review:6148327608 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3478#pullrequestreview-6148327608). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T09:44:48Z. **Review:** COMMENTED --- Review of `f33cb350`: 2 finding(s). Re-review at `f33cb350`. Accesses past the declared LDS now go to a sink (reads 0, writes dropped), which fixes the clamp-onto-the-last-dword problem from my earlier review. The reviewer traced the layout for split/native, with and without the safe barrier, and found it consistent. Two new points: 2 are inline. --- _These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it._
bmjask commented 2026-12-02 09:44:49 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T09:44:49Z.

Code review location: crates/xcl/src/gpu/dxil/lower_mem.rs; line 2230

@@ -2222,25 +2222,43 @@ impl Lw {
     // ------------------------------------------------------------ LDS / DS
 
     /// LDS dword index of byte address `at` (`(at >> 2) & 8191`, below the exchange words
-    /// in the split form).
-    fn lds_index(&mut self, at: Value) -> Value {
+    /// in the split form), and with the declared LDS (`lds_sink`) whether `at` is inside it:
+    /// an access past it goes to the sink word, a store has no effect there and a read is
+    /// 0 (`lds_in`), as on RDNA, which drops such accesses.
+    fn lds_index(&mut self, at: Value) -> (Value, Option<Value>) {
         let i = self.lshrc(at, 2);
+        if let Some(sink) = self.lds_sink {

Out-of-bounds LDS behaviour now depends on the translator. The direct path sends accesses past the declared LDS to the sink (reads give 0), while the HLSL fallback still wraps into the full 8,192-dword block and returns real data. A program that reads or writes past its declared LDS reads 0 when translated directly (the default), but reads stored data when it falls back to HLSL (an unsupported instruction, XCL_DIRECT_DXIL=0, or split real LDS with XCL_X_LDS_ORDER=0). The same shader gives different results by route, which is hard to debug. Applying the same bound in emit.rs would make them agree.

<!-- greyfinch-sync:ivall/xcl:review-comment:4767608220 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3478#discussion_r4767608220). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T09:44:49Z. **Code review location:** `crates/xcl/src/gpu/dxil/lower_mem.rs`; line 2230 ~~~~diff @@ -2222,25 +2222,43 @@ impl Lw { // ------------------------------------------------------------ LDS / DS /// LDS dword index of byte address `at` (`(at >> 2) & 8191`, below the exchange words - /// in the split form). - fn lds_index(&mut self, at: Value) -> Value { + /// in the split form), and with the declared LDS (`lds_sink`) whether `at` is inside it: + /// an access past it goes to the sink word, a store has no effect there and a read is + /// 0 (`lds_in`), as on RDNA, which drops such accesses. + fn lds_index(&mut self, at: Value) -> (Value, Option<Value>) { let i = self.lshrc(at, 2); + if let Some(sink) = self.lds_sink { ~~~~ --- Out-of-bounds LDS behaviour now depends on the translator. The direct path sends accesses past the declared LDS to the sink (reads give 0), while the HLSL fallback still wraps into the full 8,192-dword block and returns real data. A program that reads or writes past its declared LDS reads 0 when translated directly (the default), but reads stored data when it falls back to HLSL (an unsupported instruction, `XCL_DIRECT_DXIL=0`, or split real LDS with `XCL_X_LDS_ORDER=0`). The same shader gives different results by route, which is hard to debug. Applying the same bound in emit.rs would make them agree.
bmjask commented 2026-12-02 09:44:49 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T09:44:49Z.

Code review location: crates/xcl/src/gpu/recomp/mod.rs; line 494

@@ -488,6 +491,7 @@ impl CsInterface {
             tgid: [(r >> 7) & 1 == 1, (r >> 8) & 1 == 1, (r >> 9) & 1 == 1],
             tg_size: (r >> 10) & 1 == 1,
             tid_components: ((r >> 11) & 3) + 1,
+            lds_dwords: ((r >> 15) & 0x1FF) * 128,

Not certain about this one: on by default, the static LDS_SIZE from the FSSM/FSPX descriptor's COMPUTE_PGM_RSRC2 is taken as the program's whole LDS, with nothing to check that the console didn't allocate more at dispatch (dynamic LDS, or driver FSPX containers whose RSRC2 undercounts). If a title's real allocation is larger than the header value, accesses above it now silently store nothing and read 0, where before they used the 32 KB block. That gives wrong compute results with no diagnostic, and the PR says it doesn't know how often this happens. A once-per-program log when an access hits the sink would make it visible.

<!-- greyfinch-sync:ivall/xcl:review-comment:4767608231 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3478#discussion_r4767608231). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T09:44:49Z. **Code review location:** `crates/xcl/src/gpu/recomp/mod.rs`; line 494 ~~~~diff @@ -488,6 +491,7 @@ impl CsInterface { tgid: [(r >> 7) & 1 == 1, (r >> 8) & 1 == 1, (r >> 9) & 1 == 1], tg_size: (r >> 10) & 1 == 1, tid_components: ((r >> 11) & 3) + 1, + lds_dwords: ((r >> 15) & 0x1FF) * 128, ~~~~ --- Not certain about this one: on by default, the static LDS_SIZE from the FSSM/FSPX descriptor's COMPUTE_PGM_RSRC2 is taken as the program's whole LDS, with nothing to check that the console didn't allocate more at dispatch (dynamic LDS, or driver FSPX containers whose RSRC2 undercounts). If a title's real allocation is larger than the header value, accesses above it now silently store nothing and read 0, where before they used the 32 KB block. That gives wrong compute results with no diagnostic, and the PR says it doesn't know how often this happens. A once-per-program log when an access hits the sink would make it visible.
bmjask commented 2026-12-02 14:13:05 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T14:13:05Z.


@Prime1997 could you take a look at this one for review and merge? My automated review notes are above, if any.

<!-- greyfinch-sync:ivall/xcl:comment:7348180152 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3478#issuecomment-7348180152). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T14:13:05Z. --- @Prime1997 could you take a look at this one for review and merge? My automated review notes are above, if any.
BBareth commented 2026-12-03 11:51:55 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by BBareth on 2026-12-03T11:51:55Z.


Test report of f33cb350 on a retail title's open world (not a merge-check: no suite run on the merge)

In short: On NVIDIA, this PR makes the title's heaviest world compute program (a split-wave64 pass, 160×90 groups, one call a frame) 12–21 % faster: 177 ms → 156 ms a frame with a warm shader cache, 140 ms on the first run. The frame rate did not change measurably, but my gameplay runs do not show the same scene, so whole-frame numbers are not comparable between them. I saw no new visual artifact.

Why I tested it: that program was the top entry of XCL_GPU_TIMES in gameplay. Its two descriptor tables and its buffers are in VRAM (window 0). Only one small constant buffer is in system memory, read with scalar loads. So memory placement does not explain its time. Its translation declares the full 8,192-dword LDS block, but it uses only a few dwords (ds_min_u32 / ds_or_b32 reductions and the split form's exchange). That is the case this PR addresses.

Setup

  • RTX 5070 Ti, driver 32.0.16.2124; i7-12700K; Windows 11 Pro 26200; rustc 1.95.0; release build.
  • Base: main 395405e4 with #3094, #3282 and #3625 merged, which my setup needs to reach a lit world. This PR was merged onto it. There were two conflicts, in gpu/dxil/kernel.rs and core_tests.rs: test-only thread-local switches that main and this PR add side by side. I kept both.
  • Same environment for every run. 1,300 s each; XCL_GPU_TIMES=6,1000 measures 6 frames from 1,000 s on, in gameplay.

Results

run build cs b78fa10b425b8e54 (ms/frame) presents/min, 360–960 s
base base 176.6 (longest call 199.9) 76–81
first run base + #3478 140.3 (longest 147.0) 69–78 (9 cold compiles past 200 s)
warm repeat base + #3478 156.2 (longest 160.7) 67–84
  • The six frames' GPU first-to-last-stamp span was 703–785 ms on the base and 831–931 ms on the warm repeat. However, each run's top-60 program list has programs missing from the others (f607b72a… only on the base, 39f23dea… only with this PR). The runs measured different scene content, so these totals say nothing about this PR either way. Only the program above, the same dispatch in every run, compares directly.
  • No device removal and no crash in any run. The HDR target of the measured frame shows the same scene with the same existing artifacts in both builds.

Not tested

  • The suite on the merge, and a smoke run of f33cb350 on main.
  • An A/B in one build (XCL_DECLARED_LDS=0 against the default), which would give a cleaner whole-frame number.
  • AMD.

Run, measured and written by Claude Code (Claude Opus 5.5); posted with the account holder's OK.

<!-- greyfinch-sync:ivall/xcl:comment:7377280000 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3478#issuecomment-7377280000). Originally posted by [BBareth](https://github.com/BBareth) on 2026-12-03T11:51:55Z. --- **Test report** of `f33cb350` on a retail title's open world (not a merge-check: no suite run on the merge) **In short:** On NVIDIA, this PR makes the title's heaviest world compute program (a split-wave64 pass, 160×90 groups, one call a frame) 12–21 % faster: 177 ms → 156 ms a frame with a warm shader cache, 140 ms on the first run. The frame rate did not change measurably, but my gameplay runs do not show the same scene, so whole-frame numbers are not comparable between them. I saw no new visual artifact. **Why I tested it:** that program was the top entry of `XCL_GPU_TIMES` in gameplay. Its two descriptor tables and its buffers are in VRAM (window 0). Only one small constant buffer is in system memory, read with scalar loads. So memory placement does not explain its time. Its translation declares the full 8,192-dword LDS block, but it uses only a few dwords (`ds_min_u32` / `ds_or_b32` reductions and the split form's exchange). That is the case this PR addresses. **Setup** - RTX 5070 Ti, driver 32.0.16.2124; i7-12700K; Windows 11 Pro 26200; rustc 1.95.0; release build. - Base: main `395405e4` with #3094, #3282 and #3625 merged, which my setup needs to reach a lit world. This PR was merged onto it. There were two conflicts, in `gpu/dxil/kernel.rs` and `core_tests.rs`: test-only thread-local switches that main and this PR add side by side. I kept both. - Same environment for every run. 1,300 s each; `XCL_GPU_TIMES=6,1000` measures 6 frames from 1,000 s on, in gameplay. **Results** | run | build | cs `b78fa10b425b8e54` (ms/frame) | presents/min, 360–960 s | |---|---|---|---| | base | base | 176.6 (longest call 199.9) | 76–81 | | first run | base + #3478 | 140.3 (longest 147.0) | 69–78 (9 cold compiles past 200 s) | | warm repeat | base + #3478 | 156.2 (longest 160.7) | 67–84 | - The six frames' GPU first-to-last-stamp span was 703–785 ms on the base and 831–931 ms on the warm repeat. However, each run's top-60 program list has programs missing from the others (`f607b72a…` only on the base, `39f23dea…` only with this PR). The runs measured different scene content, so these totals say nothing about this PR either way. Only the program above, the same dispatch in every run, compares directly. - No device removal and no crash in any run. The HDR target of the measured frame shows the same scene with the same existing artifacts in both builds. **Not tested** - The suite on the merge, and a smoke run of `f33cb350` on main. - An A/B in one build (`XCL_DECLARED_LDS=0` against the default), which would give a cleaner whole-frame number. - AMD. <sub>Run, measured and written by Claude Code (Claude Opus 5.5); posted with the account holder's OK.</sub>
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3478:upstream-pr/3478'
git switch 'upstream-pr/3478'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3478'
git switch 'upstream-pr/3478'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3478'
git switch 'upstream-pr/3478'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3478'
git switch 'main'
git merge --squash 'upstream-pr/3478'
git switch 'main'
git merge --ff-only 'upstream-pr/3478'
git switch 'main'
git merge 'upstream-pr/3478'
git push origin 'main'
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
xcl-dev/xcl!3478
No description provided.