Repository navigation
Recompiler: size a compute program's LDS block from its LDS_SIZE - #2146
grahamster2 wants to merge 1 commit into
Conversation
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)
|
Tested:
Head |
|
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
Not tested
AI use
|
|
Verification on RTX 3060 Ti (Windows 11), branch merged with current
Thanks! |
|
Tested Independent run at clean PR head Prebuilt with 1 passed, 0 failed, 0 ignored and 0 GPU skips (1.76 s) with 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. |
…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.
|
Independent desktop NVIDIA verification of PR #2146 at head Environment
Targeted release tests & build (
|
| 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; 1125 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; 1125 filtered out × 3 (0.61s, 0.58s, 0.53s, 0 skipped; 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, 0 skipped) |
cargo build --release -p xcl |
Clean build (1m 27s, exit 0, 0 new warnings) |
Paired quiet 60 s retail smoke (title: 29640639)
Exact parent & merge-base (cbc296ab65a2661a61e3e2da109134bcd5319f60, 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 #2146 (52577f993895afe1cc3e492a063b6f73821ee57c):
xcl-smoke v1
commit: 52577f993895afe1cc3e492a063b6f73821ee57c
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1581 (PresentX 1581)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14502 MB
Limits of coverage
- Sizing HLSL compute
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). - The 60 s retail smoke confirms zero runtime regression on
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).
`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]>
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: #675 (comment).
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
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