Recompiler: batch consecutive v_readfirstlane/v_readlane exchanges in… #944
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!944
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-944"
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?
@zondy1i on GitHub · 2026-11-24 09:11 UTC · original
zondy1i:recomp/x64-readlane-batch→main· +307 −1 · 2 files · 1 commits · openIn split-wave64 mode (two hardware wave32 halves per console wave64), consecutive independent
v_readfirstlane_b32andv_readlane_b32instructions (for example, 4-dword V# or 8-dword T# descriptor waterfalls in wave64 mesh and compute shaders) previously each emitted a separatexcl_x_rla_uniformcall — inlining a full cross-halfxcl_x_meet()barrier/spin-wait exchange per instruction.PRELUDE_X64already supports multi-word exchanges (xcl_x_put(i, ...)/xcl_x_meet()/xcl_x_get(i), as used by coherents_load_dwordx4andds_bpermute). This batches consecutive dependency-freev_readfirstlane_b32/v_readlane_b32instructions inside each basic block into a single multi-wordxcl_x_meet()(sharing onefirst_lane(exec_lo, exec_hi)call across the batch), reducing DXIL size, DXC compile time, and NVIDIA driver (nvgpucomp64.dll) pipeline compile time. Native wave64 and wave32 HLSL are unchanged, and this is orthogonal to #917 (v_writelane_b32spill shadows).What is in it
crates/xcl/src/gpu/recomp/emit.rs:Em::emit_instsfor consecutive plainv_readfirstlane_b32/v_readlane_b32instructions within a basic block. Splits on any SGPR/EXEC read-after-write dependency, skips reads already resolved byupper_lanes, and caps batch width at(64 / waves).clamp(2, 8)so per-wave exchange storage stays<= 256dwords (1 KiB).Em::configure_round_modes(may_use_lds) for guest LDS use (Mode::Geometry(_)or anyENC_DSinstruction other thands_swizzle_b32/ds_bpermute_b32withGDS == 0), and keep lane-read batching at the existing 1-word slot (XCL_X_SLOT 1u) for those programs at every group size soXCL_X_LDS_TOPis never shrunk into guest LDS space.crates/xcl/src/gpu/recomp/tests.rs:split_wave64_readlane_batching_rules: covers 4-word batching, SGPR andEXECdependency splits, jump-target splits, 64- and 1024-thread slot caps, and native wave64 invariance.split_wave64_readlane_batch_preserves_guest_lds_top: 512-thread regression verifying that 8v_readfirstlane_b32beforeDS_WRITE_B32keepXCL_X_SLOT 1uandXCL_X_LDS_TOP 8142u, whileDS_SWIZZLE_B32still batches (XCL_X_SLOT 8u).gpu_split_wave64_batched_readlanes: GPU test verifying upper-half active lanes, mixed lower/upper lane batches, SGPR dependency split, andEXEC-modifying split.Across 10,447 wave64 CS/MS programs in a retail shader pack (measured pre-rebase), this removed 19,334
xcl_x_meet()exchanges (18,049 from consecutivev_readfirstlane_b32and 1,281 from consecutivev_readlane_b32).Measured on four retail wave64 shaders on
origin/main(09940bb) -> pre-rebase commit (e7199ca) (RTX 3060 Ti, DXC 1.9.2609.5):75 -> 25(-66.7%), DXIL345.6 -> 332.2 KB(-3.9%), DXC4549 -> 3853 ms(-15.3%), cold PSO7149 -> 6191 ms(-13.4%)258 -> 101(-60.9%), DXIL328.4 -> 279.7 KB(-14.8%), DXC7865 -> 5366 ms(-31.8%), PSO5551 -> 5409 ms(4481 ms first cold run)310 -> 131(-57.7%), DXIL426.7 -> 382.3 KB(-10.4%), DXC10468 -> 8867 ms(-15.3%), PSO9406 -> 8077 ms(-14.1%)505 -> 361(-28.5%), DXIL1028.9 -> 994.8 KB(-3.3%), DXC25564 -> 22523 ms(-11.9%), PSO24487 -> 21444 ms(-12.4%)Tested
x86_64-pc-windows-msvc), debug + release.origin/main(b49be183).cargo test --workspace -- --test-threads=4one22a0a6: 1438 passed, 0 failed, 47 ignored across 37 test binaries (29 runtimeSKIPPEDnotices from adapter-gated tests); all three tests (split_wave64_readlane_batching_rules,split_wave64_readlane_batch_preserves_guest_lds_top,gpu_split_wave64_batched_readlanes) ran and passed.Regression run
main:
PR:
Not tested
split_wave64is false there so emitted HLSL is unchanged).e7199ca; shaders without guest LDS are unaffected).AI use
@Xeltax on GitHub · 2026-11-24 09:32 UTC · original
A first AMD run, on native Windows: the split form forced on 64-lane hardware, and the native path.
Tested
e7199camerged ontomain077ce40(clean merge).XCL_ADAPTER=radeon XCL_SPLIT_WAVE64=1 cargo test -p xcl --lib split_wave64 -- --test-threads=4.runner::split_wave64()is then true, so the HLSL batching asserts ofgpu_split_wave64_batched_readlanesrun as well:main077ce40: 6 passed, 0 failed, 1 ignored, in 5 of 5 runs.XCL_REQUIRE_GPU=wave64, noXCL_SPLIT_WAVE64):gpu::recompmodule: 190 passed, 0 failed, 18 ignored, no skips.maingives 188 / 0 / 18.Not tested
SlopTartsaw forced-split failures in #772.AI use
@eizispark on GitHub · 2026-11-24 09:37 UTC · original
Hardware check of
e7199ca3f4fd985969b73bd17d5108866c93a679(verified clean merge withmain077ce40): pass.Tested
rustc 1.100.0 (0ef1bc386 2026-11-09), release + test profilecargo test --workspace --no-fail-fast -- --test-threads=4:715 passed, 3 failed, 41 ignored(GPU tests skipped on this adapter:none); the 3 failures are the pre-existing concurrenthle::d3d12xcontention (placed_title_textures_share_vram_and_preserve_pixelsplus 2 downstreamPoisonErrors), verified clean viacargo test -p xcl --lib hle::d3d12x -- --test-threads=1:115 passed, 0 failed, 1 ignoredsplit_wave64_readlane_batching_rules,gpu_split_wave64_batched_readlanes,gpu_wave32_program_in_wave64_hardware, andgpu_geometry_wave32_prefix_count_over_a_maskall passed on native wave64; also verified forced split-wave64 execution on discrete RDNA4 viaXCL_SPLIT_WAVE64=1 cargo test -p xcl --lib gpu_split_wave64_batched_readlanes -- --nocapture:1 passed, 0 failedRegression run
main(beaa245):PR (
e7199ca):Not tested
AI use
scripts/smoke.ps1harness on this machine and formatted this report.@SlopTart on GitHub · 2026-11-24 10:37 UTC · original
Linux / AMD RDNA3 datapoint.
Merged state: head
e7199caonto main9aec53d, clean merge.Full suite,
cargo test --workspace --release --no-fail-fast --target x86_64-pc-windows-gnu -- --test-threads=4: 719 passed, 7 failed, 41 ignored; failures are the known Wine-lane set from my #42 rows. batched readfirstlane/readlane green.Not tested: retail titles (none here), Windows, RDNA4.
Counts only, no game data.
Machine: RX 7900 XT (RADV NAVI31), Mesa 26.2.5, kernel 7.2 (Arch), Proton Experimental (wine-11.0), patched vkd3d-proton v3.1, Rust cross
x86_64-pc-windows-gnu,XCL_NETWORK=0, release profile,--test-threads=4. My Linux rows: #42 / #718.AI use: Hermes agent (local Qwen-class) ran the suite and drafted this; I checked it before posting.
@DavidM1911 on GitHub · 2026-11-24 12:38 UTC · original
Independent verification, merged onto current
main384f7f7locally (clean merge).Machine: Windows 11, Ryzen 9 7900X + RTX 3060 Ti; Rust stable MSVC, debug; DXC 1.8.2502.11.
cargo test -p xcl --lib readlane: 2 passed, 0 failed —split_wave64_readlane_batching_rulesandgpu_split_wave64_batched_readlanes(GPU) both pass.AI use: test runs by Devin (Cognition, SWE-2); no code changes.
@zondy1i on GitHub · 2026-11-24 14:48 UTC · original
Thanks for the code review! Answering both questions:
XCL_X_LDS_TOPfor 1024-thread groups: We cappedXCL_X_SLOTat 4 for 1024-thread groups (768 Bextra, movingXCL_X_LDS_TOPfrom word 8094 to 7902, leaving 31,608 B of LDS) rather than 8 specifically to keep the footprint small. The corpus scan verified static exchange reductions and clean translation/compilation across all 10,490 wave64 CS/MS shaders, rather than proving dynamic runtime LDS offsets on every 1024-thread LDS-using shader. If a tighter guarantee is preferred, cappingx64_batch_capwhenself.uses_ldsis true for 1024-thread groups is straightforward — happy to add that if desired.recomp::translate(split-wave64) across all 10,490 wave64 CS/MS shaders in a retail shader corpus, and the DXC/PSO times come from a one-off local Rust harness callingrecomp::translate->dxc::compile->CreateComputePipelineStateon a cold cache (single cold build per shader on Windows 11 + RTX 3060 Ti).18,049 + 1,281 = 19,330in compute shaders plus4in mesh shaders =19,334total exchanges removed.AI use: Antigravity (Gemini 4 Neon) helped draft this reply from the code and measurement logs.
@pvfreis on GitHub · 2026-11-24 14:57 UTC · original
Thanks, that answers both (and the 4 are the mesh shaders, understood).
On the LDS top: since the scan checked translation and compilation rather than the LDS offsets programs reach at run time, the cap you describe (no batching beyond today's slot size when
uses_ldsis set for 1024-thread groups) would remove the one risk at little cost, so I'd add it.On the numbers: the harness could live in the tree as an
#[ignore]test that reads the shader pack from anXCL_SAMPLE_*variable, as the other game-data tests do (CONTRIBUTING, "Tests on game data"). Then anyone who owns the title can rerun the counts and timings on their own GPU.Reply by Claude Code (Claude Opus 5.5); checked by a person before posting.
@Mykolas009 on GitHub · 2026-11-24 15:02 UTC · original
Tested on NVIDIA Blackwell: this PR's head
e7199camerged ontomain6efdabc(clean merge, not pushed).Ryzen 5 7500F; Windows 11 Pro 26300; Rust 1.100.0 MSVC; DXC 1.9.2602.17; debug.
cargo build --workspace+cargo test --workspace --no-fail-fast -- --test-threads=4:729 passed, 0 failed, 41 ignored (
main6efdabcalone: 727 / 0 / 41, 3 of 3 runs).SKIPPED:
gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware(no wave64).split_wave64_readlane_batching_rulesandgpu_split_wave64_batched_readlanes: pass.emit.rsandmod.rsfrommainand this PR's tests kept, both tests fail(
tests.rs:5808andtests.rs:5897).main077ce40+ this PR: same result for its own tests and the negative control.Since #798 the exchange this PR removes is also the bounded-spin one in one-wave groups, which costs about
8.3x of wave32 per exchange on this card (
bench_split_wave64). I did not measure this PR's effect onframe times.
Not tested
smoke.ps1(no game files); frame times of real shaders. AMD.AI use
@Mykolas009 on GitHub · 2026-11-24 15:49 UTC · original
How much the batching saves on NVIDIA, since nobody has timed it yet. A local benchmark (not for a PR,
built like
bench_split_wave64: a 2^18-thread compute dispatch, 32,768 loop iterations, GPU timestamps,median of 9, release) on
main930e8b4with and without this PR (e7199ca), 2 runs each:mainv_readfirstlaneof lane valuesv_readfirstlane(nothing to batch)So four reads in a row run about 3x faster, and a lone read is unchanged. The wave64 output of every case
is identical with and without the PR (same hash of all stored values).
Tested
Rust 1.100.0 MSVC; DXC 1.9.2602.17.
930e8b4+ this PR (debug): full suite 753 passed, 0 failed, 41 ignored; both new tests pass andboth fail with
emit.rsandmod.rsfrommain(tests.rs:5808, 5897).Not tested
AI use
@DarkPanda69 on GitHub · 2026-11-24 09:43 UTC · original · edited 2026-11-26 08:36 UTC
Update for head
e22a0a6: paired rerun onmainb49be18, same cards,cargo test -p xcl --lib -- gpu:: --test-threads=4. On both cards, the only result changes againstmainaregpu_split_wave64_batched_readlanes,split_wave64_readlane_batch_preserves_guest_lds_topandsplit_wave64_readlane_batching_rules, all ok, with no new skips. RX 9070 XT: 708 → 711 passed, 2 failed (#2115, the same onmain), 6 SKIPPED. RTX 3060: 710 → 713 passed, 0 failed, 24 SKIPPED.AMD run with native 64-lane waves, plus NVIDIA. Updated for head
e6a94f5(first run was one7199ca, same result).Tested: pass, head
e6a94f5applied onmainaaa0936, debug, Rust 1.100.0, Windows 11 Pro 26200, Ryzen 7 5800X, DXC 1.9.2602.17.cargo test -p xcl --lib -- gpu:: --test-threads=4:gpu_split_wave64_batched_readlanesok. The 2 failures aregpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1and_3, which fail the same way onmainwithout this PR on this card.gpu_split_wave64_batched_readlanesok.Not tested: retail gameplay; performance.
Note: these runs check that the translated HLSL matches the test's reference model, in 64-lane and in 32-lane waves. They cannot show that the model matches the hardware.
AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.
@thehollowedone on GitHub · 2026-11-25 23:21 UTC · original
Follow-up on the LDS cap at head
e6a94f5: the largest extra reservation is at 512 threads, not 1024. Eight independentv_readfirstlane_b32instructions before aDS_WRITE_B32selectXCL_X_SLOT 8and moveXCL_X_LDS_TOPfrom word 8142 to 7918 (896 more bytes reserved). Guest LDS words 8000 and 8001, distinct on the previous single-word exchange, would both clamp to 7918. This address alias is a source-level prediction; I have not run a GPU readback of those two words.I added a synthetic 512-thread translation regression locally. It fails on the PR head (
0 passed, 1 failed) because the slot expands, then passes with a small guard (1 passed, 0 failed). The existingsplit_wave64_readlane_batching_rulesunit test andgpu_split_wave64_batched_readlanestest also pass with that guard (1/0each, the GPU test ran on an RTX 3080 Ti with no skip). The test reads no game data.Suggested bound: classify possible guest LDS use over the decoded program before emitting instructions, then keep lane-read batching at the existing one-word slot for that class at every group size. Exclude
DS_SWIZZLE_B32,DS_BPERMUTE_B32, and GDS accesses from that classification; geometry also has implicit LDS. Checkinguses_ldsinside the batching loop is insufficient when lane reads precede the first DS instruction. This leaves the no-LDS batching benefit intact. I have an uncommitted 27-line local diff (including the regression) if useful.AI use: Codex (GPT-6.2 Sol) reviewed the source, wrote and ran the synthetic regression and local guard, and drafted this comment.
@DavidM1911 on GitHub · 2026-11-26 03:11 UTC · original
Re-verification on RTX 3060 Ti (Windows 11), new head merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved.Thanks!
— Devin
e6a94f51f9toe22a0a6e78@pvfreis on GitHub · 2026-11-24 14:36 UTC · original · reviewed
Review of
e7199ca(merge base09940bb), by reading the code; nothing was built or run here. I checked that each batched read sees what the unbatchedxcl_x_rla_uniformsequence would (lane indices,first_lane(exec)and the reads are all computed before the first SGPR write,emit.rs:972-990; dependent reads split the batch,:890-937), and that the GPU test compares against independent values. No defect found.Questions for the author
XCL_X_SLOTmovesXCL_X_LDS_TOPdown (emit.rs:4345): for a 1024-thread group from word 8094 to 7902 (arithmetic), and LDS accesses above the top are clamped onto it. Did the shader-pack scan check that no LDS-using program reaches between the old and new top?Review by Claude Code (written by Claude Opus 5.5, second read by Claude Fable 5.2); each point checked by a person before posting.
@zondy1i on GitHub · 2026-11-26 08:24 UTC · original
Rebased onto current
main(b49be183) and addressed @thehollowedone's 512-thread guest-LDS headroom finding ine22a0a6:Em::configure_round_modes(may_use_lds) for guest LDS usage (Mode::Geometry(_)or anyENC_DSinstruction other thands_swizzle_b32/ds_bpermute_b32withGDS == 0), and keep readlane batching at the existing 1-word slot (XCL_X_SLOT 1u) for those programs at every group size soXCL_X_LDS_TOPis never shrunk.split_wave64_readlane_batch_preserves_guest_lds_top(512-thread regression confirming 8v_readfirstlane_b32beforeDS_WRITE_B32keepXCL_X_SLOT 1uandXCL_X_LDS_TOP 8142u, whileDS_SWIZZLE_B32still batches).Full workspace suite on
e22a0a6: 1438 passed, 0 failed, 47 ignored; 60 s smoke is updated in the description. Thanks @thehollowedone for catching this!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.