Recompiler: size a compute program's LDS block from its LDS_SIZE #2136
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2146"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ivall/xcl. Originally posted by grahamster2 on 2026-11-25T06:15:07Z.
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 inCOMPUTE_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 withXCL_LDS_MASKinstead of8191u. 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://github.com/xcl-dev/xcl/issues/675#issuecomment-7152949831.
Part of #675.
What is in it
CsInterface::lds_bytesfrom RSRC2 (gpu/recomp/mod.rs);lds_words/lds_decland the layouts that used 8192 / 8191 / 8189 / 8190 / 8188 (gpu/recomp/emit.rs). Struct literals in tests getlds_bytes: 0.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
52577f9.cargo test --workspace -- --test-threads=4: 1156 passed, 0 failed, 46 ignored.lower/lower_dxilwave64 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.bench_split_wave64loop with an LDS store and load per iteration: 2^18 threads x 8192 iterations, 64-thread groups, GPU timestamps, median of 7.xcl shaders --export-hlslon the retail title's pack: HBO (LDS_SIZE 512 B) now declaresxcl_lds[256]. The 84 LDS-using split programs allocate 512 B to 16.9 KB.Regression run
main (
cbc296a):this PR (
52577f9):Not tested
XCL_DIRECT_DXIL,gpu/dxil/lanes.rs) still declares 8192 words. It is unchanged and would be a follow-up.ds_*offset past its size, but dynamic addresses were not checked.AI use
Imported from ivall/xcl. Originally posted by DarkPanda69 on 2026-11-25T06:28:06Z.
Tested:
gpu_compute_lds_ring_in_a_block_of_the_programs_sizepasses on AMD with native 64-lane waves, and on an RTX 3060.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 onmain.Head
52577f9applied onmain6ea813a,cargo test -p xcl --lib -- gpu:: --test-threads=4withXCL_ADAPTERset 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.
Imported from ivall/xcl. Originally posted by JoaoPauluu on 2026-11-25T06:29:09Z.
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
x86_64-pc-windows-gnu.52577f9as it is (merge base withmaincbc296a), no uncommitted changes. The lib test binary runs under Wine, one test per process.compute_lds_block_takes_the_programs_lds_size: okgpu_compute_lds_ring_in_a_block_of_the_programs_size: okNot tested
AI use
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T06:49:27Z.
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!
Imported from ivall/xcl. Originally posted by JJAutoCompare on 2026-11-26T22:49:44Z.
Tested
Independent run at clean PR head
52577f993895afe1cc3e492a063b6f73821ee57con Intel Arc A770 (driver 32.0.101.9175), Ryzen 7 3800X, Windows 11 x64 26200.9974, Rust/Cargo 1.100.0 MSVC, DXC/DXIL 1.9.2609.5, debug test profile.Prebuilt with
cargo test --locked -p xcl --lib --no-run --message-format=jsonoutside the GPU mutex. Ran<test-exe> gpu::recomp::tests::gpu_compute_lds_ring_in_a_block_of_the_programs_size --exact --nocapture --test-threads=1under the Arc mutex withXCL_ADAPTER=A770.1 passed, 0 failed, 0 ignored and 0 GPU skips (1.76 s) with
XCL_DIRECT_DXIL=0andXCL_REQUIRE_GPU=wave64. The stock HLSL/DXC fixture checked 768 outputs across three workgroup shapes in logical wave32 and split wave64.Not tested
The CPU companion fixture, direct DXIL, native wave64, occupancy and performance, the workspace suite and retail smoke.
AI use
T3 Code / Codex (gpt-6.2-sol) ran the original verification and summarized the saved results.
Imported from ivall/xcl. Originally posted by Decodere on 2026-11-27T09:04:02Z.
Independent desktop NVIDIA verification of PR #2146 at head
52577f993895afe1cc3e492a063b6f73821ee57c(1commit; exact parent & merge-base:cbc296ab65a2661a61e3e2da109134bcd5319f60, pre-#2555ancestor ofmain).Environment
7956 MiBreported by D3D12, Wave32-only Ada), driver32.0.16.2114(NVIDIA621.14, WDDM 3.2)31.9 GiBusable), Windows 11 Home26200(Developer Mode off)rustc 1.100.0 (0ef1bc386 2026-11-09)MSVC, DXC1.9.2609.5,--releaseTargeted release tests & build (
52577f99)cargo test --release -p xcl --lib compute_lds_block_takes_the_programs_lds_size -- --nocapture(3 consecutive runs)1 passed; 0 failed; 0 ignored; 1125 filtered out× 3 (0.00s× 3,0skipped)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; 1125 filtered out× 3 (0.61s,0.58s,0.53s,0skipped; live RTX 4060 execution)cargo test --release -p xcl --lib gpu::dxil:: -- --test-threads=4(3 consecutive runs)122 passed; 0 failed; 3 ignored; 1001 filtered out× 3 (4.76s,4.33s,4.46s,0skipped)cargo build --release -p xcl1m 27s, exit0,0new warnings)Paired quiet 60 s retail smoke (
title: 29640639)Exact parent & merge-base (
cbc296ab65a2661a61e3e2da109134bcd5319f60, same machine):PR #2146 (
52577f993895afe1cc3e492a063b6f73821ee57c):Limits of coverage
xcl_ldsblocks fromCOMPUTE_PGM_RSRC2.LDS_SIZEplus top-reserved runtime words was directly verified on desktop RTX 4060 viacompute_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), andgpu::dxil::(122/122× 3).title: 29640639(single-run frame/commit delta vs. parent reflects normal startup variance, not this PR); SM occupancy / compute dispatch throughput delta from smallergroupsharedallocations was not separately profiled.AI disclosure: test execution and report drafting assisted by Google Antigravity (Gemini 4 Neon).
Imported from ivall/xcl. Originally posted by thehollowedone on 2026-11-28T11:07:08Z.
merge-check
base:
e429936c10head:
52577f9938merge: clean
build: cargo build --offline --locked -j 4 --workspace -> ok (the local overlay changed test code and missing test initializers only)
tests: cargo test --offline --locked -j 4 -p xcl --lib compute_lds_block_takes_the_programs_lds_size -- --nocapture --test-threads=1 -> the unmodified merged tree fails to compile with 15 E0063 missing-field errors in newer CsInterface test initializers. After adding lds_bytes: 0 to those 15 local test initializers, the stock block-size and GPU LDS-ring tests each passed (1/0/0, no skips). A new local GPU regression below then failed (0/1/0, no skip) on the RTX 3080 Ti.
review: not yet. With LDS_SIZE=512 B, the new 256-word mask maps guest byte 1024 to word 0. The regression first stores 0x12345678 at byte 0, then stores 0xDEADBEEF at byte 1024 and reads byte 0. The unknown-size/32 KB control preserves the sentinel; the known-size case fails and the first four displayed lanes return 0xDEADBEEF. This is a new in-range corruption from an out-of-range guest write. RDNA2 specifies zero for out-of-range LDS reads and discards writes (ISA §3.6).
performance: Smaller HLSL group-shared blocks should improve occupancy for programs with small LDS_SIZE; I did not measure frame time or occupancy. Correct bounds checks should be per effective DS access, before the host mask, including paired/wide elements; constant offsets can fold at shader compile time. Benchmark the guarded path rather than restoring a 32 KB block for all programs.
verdict: not yet: rebase the 15 new test initializers and prevent known-size LDS out-of-range accesses from wrapping into valid data. Keep the in-range smaller-block behavior.
hardware / tool and model: Windows 11 build 26300, Ryzen 7 9800X3D, RTX 3080 Ti driver 621.35, DXC 1.8.2502.11; Codex (GPT-6.2 Sol) reviewed the merged diff, built it, and ran the tests; Codex (GPT-6.2 Astra) independently traced the LDS bounds.
Local failing GPU regression (test-only diff after the 15 compile accommodations)
Local candidate on the same head: guard each known-size DS access at its final byte address before applying the smaller host-block mask. An independent emitter review found no omitted DS path. With this candidate and the 15 local test-initializer accommodations,
cargo test --offline --locked -j 4 -p xcl --lib gpu_compute_lds_ -- --test-threads=1passed 2/0/0,gpu_ds_passed 4/0/0, andsplit_wave64_lds_passed 5/0/0 on the RTX 3080 Ti, with no skips. The first command includes the new sentinel regression that failed on the unchanged PR. This is a proposed fix, not a merge-ready retest: mixed-validity paired operations, subword reads, returning atomics, the full workspace suite, and paired title smoke remain to be checked on a committed revision. The effective address is evaluated before the range check, preserving 32-bit address wrap.Candidate emitter diff (local, not committed)
Imported from ivall/xcl. Originally posted by throny on 2026-11-28T14:40:42Z.
merge-check claim
head:
52577f9938Imported from ivall/xcl. Originally posted by throny on 2026-11-28T14:53:34Z.
merge-check
base:
b937fbabhead:
52577f9938merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> the test targets do not compile on the merge result: 15 times error[E0063], missing field
lds_bytesin an initializer ofCsInterface. No test ran. (cargo build --workspace of the merge result is fine.)review: two blocking points. (1) The PR adds the field
CsInterface::lds_bytes, and main has 15 fullCsInterface { .. }literals in test code that the PR does not update (robustness_tests.rs, link_tests.rs, the test module of pso.rs, and tests.rs); the same kind of break #2158 had. (2) With the block sized from LDS_SIZE, the default path masks the index with the block's size, so an access past the declared size now wraps onto the program's own low words; before, it landed in unused space of the fixed 32 KB block. The earlier checker in the thread reproduced this on a GPU and it is still open; clamping or dropping the access would answer it. Minor and fine: the geometry stage keeps its fixed mask, which is safe because the block keeps its full size there.performance: a smaller groupshared block may help compute shaders; nobody has measured it. It changes a translator source: every tester re-translates all shaders once.
verdict: not yet: rebase and add the field to the 15 test literals, and answer the out-of-range access (clamp or drop instead of wrap).
hardware / tool and model: RTX 4080 16 GB (621.40), i9-12900K, Windows 11 26300, Rust 1.100.0, debug. Claude Code; merge, build and suite run by Claude Fable 5.2, diff review by Claude Opus 5.5 (every hunk read; nothing run on the GPU beyond the suite).
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T06:17:59Z.
Review (head
52577f99, diff read, not a merge-check; it conflicts with main, so not built or run):emit.rsstill declaresxcl_lds[8192], and #3478 only changes the direct backend. Direct DXIL is now the default for compute (kernel.rs~45), so this reaches programs that fall back to HLSL or runs withXCL_DIRECT_DXIL=0. Measurements and smoke runs are fromcbc296aand need redoing.CsInterface { ... }literals added on main since (e.g.dxil/core_tests.rs~28,dxil/kernel.rs~987,robustness_tests.rs~110,link_tests.rs~165) lacklds_bytes;..Default::default()as #3478 does would avoid that.x64_slots_countersusesx64_threads()while main'sx64_preludenow usesx64_hw_threads()(4ec5d490), which oversizes the exchange arrays of remapped split programs (wasted groupshared memory, not wrong results).CsInterface::lds_dwordsand its exact-size-plus-clamp layout would also make the two backends agree on out-of-range addresses (here they wrap within the block, #3478 clamps).Fine: the reserved top words never overlap the program's words in native, wave64 or split form, with or without the safe barrier or the 2-D
XCL_WT; mesh and geometry keep 8192 words; theemit.rschange resets the translation cache by itself; and there's a GPU test of the tight layout.AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.