Skip to content

Recompiler: a lane loop form for small split wave64 compute programs - #3561

Open
Royalflamejlh wants to merge 2 commits into
xcl-dev:mainfrom
Royalflamejlh:recompiler/wave64-lane-loop
Open

Royalflamejlh wants to merge 2 commits into
xcl-dev:mainfrom
Royalflamejlh:recompiler/wave64-lane-loop

Conversation

@Royalflamejlh

@Royalflamejlh Royalflamejlh commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

(Edited: head cab682f3e, rebased onto main 5ad98ad, after three rounds of review: the lane loop now has the split form's per-dispatch loop caps (kernel::loop_head, shared), gives each console wave a hardware wave of its own, taken by arrival at the entry (a group of one wave stays one thread, for its s_barrier), and refuses a program larger than a dispatch piece; a test for each. Before: rebased onto main 38ad22d, after #3655; head 4a6534767. The change itself: the lane loop now fills the exchange_sites field #3655 added to Kernel (the form exchanges nothing, so 0), and its cache tag sits beside #3655's XCL_WAVE64_IDIOMS=0 tag.)

A third form for wave64 compute programs on a GPU with 32-lane waves only: one host thread runs a whole console wave, all 64 lanes, in a loop. Nothing is exchanged and nothing waits, so it cannot spin. It is meant as the exact fallback for small programs that the split form runs badly: on Linux (RTX 4060 Ti) a split program of 64 threads a group stayed 16 s in one dispatch at the title's world start and the run ended in a GPU hang; #3114 measures the same exchange at 2.6x a program's GPU time.

The form is opt-in (XCL_WAVE64_LANE_LOOP=1): without the switch nothing changes. Tests on other cards (Windows, AMD, other NVIDIA) are wanted. It has not run in a title from this branch.

What is in it

  • crates/xcl/src/gpu/dxil/lane_loop.rs (new, about 430 lines of code and 200 of tests): the form. A vector instruction is a 64-pass loop around the existing per-lane lowering with the lane's EXEC bit as the guard; each VGPR is a 64-dword array; a mask is built lane by lane; lane reads (v_readlane, v_readfirstlane, DPP, swizzle, permlane, ds_bpermute) read the array. numthreads becomes [ceil(N/64) * 64, 1, 1]: at the entry the first lane of each hardware wave takes the next console wave from a count in the LDS (two group syncs) and the others return, so each console wave is a hardware wave of its own however the driver packs threads; a group of one wave is [1, 1, 1]. Loops have the split form's caps (kernel::loop_head, loop_passes over the console group's threads).
  • LDS: the lane loop keeps the console's LDS order itself (all 64 lanes of one instruction before the next), so XCL_X_LDS_ORDER does not affect it; with XCL_WAVE64_LANE_LOOP set it also takes the single-wave LDS programs that XCL_X_LDS_ORDER=0 sends to the HLSL path on main.
  • It refuses, and the split form stays: s_barrier in a group of more than one console wave, v_movrel*, scratch memory, image stores and atomics, a lane read of a computed value, a program larger than a dispatch piece (dispatch_piece_limit, which the split form cuts into a chain), and any instruction that touches per-lane state it does not track.
  • gpu/recomp/pso.rs (direct_compute): one call, lane_loop::choose, before the split translation. lanes.rs: two early returns (ballot, rla). kernel.rs: the cache tag, and the loop head taken out into loop_head. module/split.rs: Module::dispatch_cost, the sum split_compute already weighed.
  • Second commit: the switch. The form is off unless asked for: with XCL_WAVE64_LANE_LOOP=1 split programs of at most 512 code dwords (lane_loop::MAX_WORDS) take it, with =all every program the form supports. The 512 is a first guess, and GPU time against the split form is not measured, which is why it is opt-in. The switch is part of the translated cache's identity.
  • docs/wave64-on-wave32.md: a section on the form.

817 added lines and 43 removed, 709 of them the new file with its tests; the form is not useful in smaller parts.

Tested

  • RTX 4060 Ti 16 GB, NVIDIA 615.71.09, Linux, Wine 11.21 Staging, vkd3d-proton master with local patches, AMD Ryzen 9 9950X3D, Rust 1.98.0, x86_64-pc-windows-gnu, release. Head c15bcb172. (Edited: the earlier head 659efb76 did not carry the opt-in its commit describes: the edits were left uncommitted, so 659efb76 ran the form by default on programs of at most 512 code dwords. c15bcb172 has them, and XCL_WAVE64_LANE_LOOP is a warm pipeline library setting; the lane-loop and shaders:: tests there, under Wine on the CPU: 103 passed, 0 failed.)
  • cargo test -p xcl --release --lib -- gpu::dxil --test-threads=4: 311 passed, 1 failed, 3 ignored. SKIPPED: dispatch_chain_native_wave64_builds_whole (no wave64). The failure is round_tests::directed_reference_basics ("Invalid bitcode signature"), which fails the same way here on a tree without this change; not rerun on main alone.
  • The five new tests passed, three of them on the GPU: gpu_lane_loop_gives_the_console_waves_values (groups of 48, 64, 96, 256 and 8x8x4 threads; ballot, readlane, readfirstlane, mbcnt, a saveexec loop, LDS write then read; against the console's values and the split form's), gpu_lane_loop_reads_other_lanes_before_any_is_written, gpu_lane_loop_leaves_out_the_lanes_past_a_thread_limit.

Regression run
RTX 2070 SUPER 8 GB (driver 621.01), Ryzen 7 5700X3D, Windows 11 Pro 26200, release builds by scripts/smoke.ps1, the same retail title for 60 s each.

main:

xcl-smoke v1
commit: 5eaadb54c14e0fc29597b2a1689d7dbd83491303
gpu: NVIDIA GeForce RTX 2070 SUPER
title: 5330474d
seconds: 60
exit: 0x0
frames shown: 1575 (PresentX 1575)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15670 MB

this PR's head:

xcl-smoke v1
commit: 4a6534767e570ce694174901a4148f0bc2d83eb7
gpu: NVIDIA GeForce RTX 2070 SUPER
title: 5330474d
seconds: 60
exit: 0x0
frames shown: 1613 (PresentX 1613)
presents per 2 s (last 3): 60 60 61
device removals: 0
crashes: 0
peak commit: 15135 MB

Not tested

  • Native Windows, AMD, any other NVIDIA card, the whole suite, any title.
  • GPU time against the split form: not measured. One thread does up to 64 times the arithmetic, so the limit decides whether it is a gain.
  • DPP, swizzle, permlane and writelane go through the same hooks as the tested lane reads but have no test of their own.
  • Lanes past the group's threads or a thread limit never run, also where a program widens EXEC; a readlane of a lane that never started gives the register's initial value.

AI use

  • Claude Code with Claude Fable 5.2 wrote the code, the tests and this description. The tests were run on the hardware above.

@github-actions github-actions Bot added area:docs-ci Documentation, scripts, workflows, repo governance area:recompiler RDNA2 decoder, HLSL/direct-DXIL recompiler, wave64/wave32 gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) labels Dec 1, 2026
@Royalflamejlh
Royalflamejlh marked this pull request as ready for review December 1, 2026 05:59
@github-actions github-actions Bot added the needs-pr-check Failing the PR description check (CONTRIBUTING.md) label Dec 1, 2026
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Review (head 1216e70, diff read, not a merge-check: the PR description check fails, so not built or run here yet):

Fine: the ballot / rla hooks cover the lowering's lane reads (the remaining direct hardware-wave calls are split-only or pixel-only), results of instructions that read other lanes are held until every lane has read, lanes past the thread limits never run, and the tests compare against both the console's values and the split form.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Triage (#1607) – head 1216e70

No open PR adds a lane-loop form. #3562 (same author) attacks the same problem, the split wave64 exchange on 32-lane GPUs, by folding two console lanes into one host lane. This PR instead runs a whole console wave per thread for small programs (at most 512 code dwords by default). These are different approaches. If both merge, the lane loop runs first in pso::direct_compute and the fold in kernel::translate_compute_rodata, and both add sections to docs/wave64-on-wave32.md.
No problems found in the parts read. The failing check is the PR description check: the smoke pair is still owed.
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

@Royalflamejlh
Royalflamejlh force-pushed the recompiler/wave64-lane-loop branch from 1216e70 to 659efb7 Compare December 1, 2026 14:25
@github-actions github-actions Bot removed the needs-pr-check Failing the PR description check (CONTRIBUTING.md) label Dec 1, 2026
@Royalflamejlh

Royalflamejlh commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor Author

Edited: 659efb76 did not carry the opt-in described here; c15bcb172 does (see below).

Thanks for the review. The lane loop is opt-in now (head 659efb76): with XCL_WAVE64_LANE_LOOP=1 split programs of at most 512 code dwords take it, with =all every program the form supports, and without the switch no program changes form. The 512 is still a first guess and GPU time against the split form is still not measured; the description says so.

On the other points: a lane-loop program gets no dispatch chain, as you say (one thread a wave has nothing to cut); and it does take single-wave programs with LDS when the switch is on. If both this and #3562 merge, the order between them needs one decision point; I would put the choice in kernel::translate_compute_rodata in whichever lands second.

cargo test --lib gpu::dxil on that head, RTX 4060 Ti under Wine: 311 passed, 1 failed (directed_reference_basics, as on main), 3 ignored; the five lane-loop tests passed, three of them on the GPU.

AI use: Claude Code with Claude Fable 5.2 made the change, ran the tests and wrote this.

@github-actions github-actions Bot added the needs-pr-check Failing the PR description check (CONTRIBUTING.md) label Dec 1, 2026
@Royalflamejlh
Royalflamejlh force-pushed the recompiler/wave64-lane-loop branch from 659efb7 to c15bcb1 Compare December 1, 2026 20:46
@github-actions github-actions Bot added area:shaders Shader cache, PSO compilation, pipeline libraries, precompilation and removed needs-pr-check Failing the PR description check (CONTRIBUTING.md) labels Dec 1, 2026
@Royalflamejlh

Copy link
Copy Markdown
Contributor Author

A correction to my comment above: head 659efb76 did not carry the opt-in. The edits that make the form opt-in were left uncommitted, so 659efb76 ran the lane loop by default on split programs of at most 512 code dwords. Head c15bcb172 has them: without XCL_WAVE64_LANE_LOOP no program changes form, and the switch is now also a warm pipeline library setting (it was missing there, like #3563's). Lane-loop and shaders:: tests on that head, under Wine on the CPU: 103 passed, 0 failed.

AI use: Claude Code (Claude Opus 5.5).

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Follow-up review (head c15bcb1, since 1216e70, diff read, not a merge-check; checks red):

New: none.

Fine: the 0/unset/1/all cases map to the cache tag and warm settings consistently, XCL_DIRECT_DXIL_SOURCE_ID covers the new file, and with the switch off direct_compute behaves as on main.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

@Decodere

Decodere commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

merge-check
base: 1c8b551
head: c15bcb1
merge: clean (3f227198be4bc70bd7322538f7f11bc333352360; 8 files, +684/-4; git diff --check ok)
build: cargo build --workspace ok; cargo build --release -p xcl ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 --nocapture -> 2915 passed, 0 failed, 51 ignored across 43 targets (28 SKIPPED lines matching clean base 1c8b551: 22 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 2 no heap windows, 1 cannot disable the driver cache). All 6 new tests passed on RTX 4060 with 0 skips: gpu::dxil::lane_loop::tests::{gpu_lane_loop_gives_the_console_waves_values, gpu_lane_loop_leaves_out_the_lanes_past_a_thread_limit, gpu_lane_loop_reads_other_lanes_before_any_is_written, lane_loop_has_one_thread_a_wave_and_nothing_to_wait_for, lane_loop_is_chosen_by_size_and_refusals_keep_the_split_form} and shaders::warm_settings_keep_the_wave64_lane_loop_switch_on_both_backends.
review: Full diff audited across all 8 files (+684/-4). Opt-in only (off by default; XCL_WAVE64_LANE_LOOP=1 for programs up to 512 words, =all for all eligible) and keyed into both kernel::compact_nest_tag and shaders::semantic_pipeline_setting so translated and warm caches stay separate. lane_loop::each_lane deliberately omits an SSA backedge from end to head, so scalar inputs stay at their pre-loop values across all 64 iterations (including carry-in/out instructions) while scalar writes and ballots are read at after from lane 63. VGPR outputs are double-buffered via held whenever ll.crossed is set (handling in-place cross-lane ops such as ds_bpermute), and unsupported constructs (multi-wave s_barrier, v_movrel*/v_swaprel_b32, scratch, image writes, and lane reads of computed values) fail closed and fall back to the split form. In the live XCL_WAVE64_LANE_LOOP=1 retail smoke, 67 refused shaders (51 image writes, 16 multi-wave s_barrier) fell back cleanly to the split form with zero errors. No scope creep or unintended changes.
performance: Two 60 s release smokes on title 29640639 vs clean base 1c8b551 (1462 frames, presents per 2 s last 3: 48 53 59, peak commit 16043 MB): default (switch unset) ran 1629 frames (+11.4%, steady 61 60 60, peak commit 17007 MB, +6.0%, 0 removals, 0 crashes); opt-in XCL_WAVE64_LANE_LOOP=1 ran 1649 frames (+12.8% vs base, +1.2% vs default, steady 60 60 60, peak commit 15160 MB, -5.5% vs base, 0 removals, 0 crashes).

Default (switch unset):

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

Opt-in (XCL_WAVE64_LANE_LOOP=1):

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

verdict: safe to merge
hardware / tool and model: NVIDIA GeForce RTX 4060 8 GB (driver 621.40), Intel Core i5-11400F, 32 GB RAM, Windows 11 Build 26200, Rust 1.100.1 MSVC, DXC 1.9.2602.17 / Antigravity (Gemini 4 Neon)

@github-actions github-actions Bot added needs-1st-check Passes gates; needs first independent merge-check (#3041) needs:amd-test Needs a test report or merge-check on an AMD GPU needs:nvidia-test Needs a test report or merge-check on an NVIDIA GPU needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) and removed needs-1st-check Passes gates; needs first independent merge-check (#3041) needs:nvidia-test Needs a test report or merge-check on an NVIDIA GPU labels Dec 2, 2026
@Royalflamejlh
Royalflamejlh force-pushed the recompiler/wave64-lane-loop branch from c15bcb1 to 4a65347 Compare December 2, 2026 13:43
@github-actions github-actions Bot removed needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) needs:amd-test Needs a test report or merge-check on an AMD GPU labels Dec 2, 2026
@Foniass

Foniass commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

Follow-up review (head 4a65347, since c15bcb1, diff read, not a merge-check; checks red):

  • Earlier points: unchanged. git range-diff shows the own commit changed only where main moved under it (the XCL_WAVE64_IDIOMS warm setting and cache tag now sit next to this PR's own in shaders.rs / kernel.rs); this push is a rebase.

New: none.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

@bmjask bmjask left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of 4a653476: 3 finding(s) (1 critical, 1 high, 1 medium), most severe first.

  1. Critical crates/xcl/src/gpu/dxil/lane_loop.rs:138: The lane loop's CFG walk drops the per-dispatch loop-pass cap (loop_passes / VAR_LOOP_PASSES from IO_LOOP_BUDGET) that kernel.rs applies to every plain-form compute program. (inline)
  2. High crates/xcl/src/gpu/dxil/lane_loop.rs:175: Not certain about this one, because it depends on scheduling the hardware doesn't guarantee: numthreads becomes [ceil(N/64),1,1], so all console waves of a group run as threads of one 32-lane hardware wave. (inline)
  3. Medium crates/xcl/src/gpu/dxil/lane_loop.rs:179: The lane loop always finishes with try_finish(..) and dispatch_chain: None, bypassing finish_dispatch's split_compute / dispatch_piece_limit() (12,500 instructions). (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.

for &b in &cfg.rpo {
let h = head(&mut lw, b);
lw.s.m.set_block(h);
if cfg.headers.contains(&b) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Critical: The lane loop's CFG walk drops the per-dispatch loop-pass cap (loop_passes / VAR_LOOP_PASSES from IO_LOOP_BUDGET) that kernel.rs applies to every plain-form compute program. Loop headers only decrement the 65,536-pass VAR_BUDGET. A compute program whose loop runs away (a spin on memory that never changes, or an exit condition the translation gets wrong) runs up to 65,536 passes per console wave, where the plain form stops it at the dispatch's share (DISPATCH_LOOP_PASSES / threads, min 1024). Each pass also runs every vector instruction as a 64-iteration loop in one thread, so a dispatch the split form cuts short runs ~64x longer per pass: the GPU hang / TDR the form is meant to avoid. Applying the same per-dispatch cap at the lane loop's loop headers would keep it bounded.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right: the lane loop's loop heads counted only the lane's 65,536 budget. Fixed in cab682f3e: the head now goes through kernel::loop_head (taken out of translate_on_this_thread, so both forms share it), and loop_passes divides the dispatch's share by the console group's threads, so a console lane gets the passes it gets in the split form.

Tests: lane_loop_loops_have_the_passes_of_the_console_threads (red before the fix: the program never loaded IO_LOOP_BUDGET), and the lane loop is now a third case of gpu_direct_compute_loop_passes_follow_the_dispatch, with the same expected counts as the split form.

Comment thread crates/xcl/src/gpu/dxil/lane_loop.rs Outdated
return Err(e);
}
let static_samplers = lw.static_used.iter().map(|&(w, c, _)| (w, c)).collect();
let dxil = lw.s.try_finish([waves, 1, 1], None).map_err(|e| format!("direct DXIL builder error: {e}"))?;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

High: Not certain about this one, because it depends on scheduling the hardware doesn't guarantee: numthreads becomes [ceil(N/64),1,1], so all console waves of a group run as threads of one 32-lane hardware wave. Waits between console waves that don't use s_barrier (LDS-flag or atomic spin loops) then depend on divergent threads of one hardware wave making progress, which GPUs without independent thread scheduling don't guarantee. In a 256-thread group (4 console waves) where wave 0 polls an LDS or global flag that wave 1 sets with no s_barrier (accepted, since only S_BARRIER with waves > 1 is refused), thread 0 loops while thread 1 is masked at the reconvergence point on AMD. The flag is never written, so the loop spins until VAR_BUDGET runs out and exits with wrong results, or hangs the GPU. Refusing programs with cross-wave waits other than s_barrier (e.g. LDS/global loads inside loops whose exit depends on them) would keep them on the split form.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Taken, though fixed another way than a refusal: each console wave now has a hardware wave of its own. The group is declared with 64 threads for each console wave; at the entry the first lane of each hardware wave takes the next console wave from a count in the LDS, and the other threads return (wave_by_arrival, cab682f3e; it does not assume the driver forms waves from consecutive thread indices). So on 32- and 64-lane hosts alike a wave that polls LDS or memory another wave writes is in a different hardware wave, as on the console. A group of one console wave is declared as one thread, so the s_barrier the form accepts there has nobody to wait for.

Not reproduced: we have no AMD card, and on NVIDIA the old layout may well have made progress anyway. Test: lane_loop_has_one_thread_a_wave_and_waits_only_at_its_entry expects numthreads 128 for a group of 96 (2 before the fix) and the entry's two group syncs, one waveIsFirstLane and one atomic add.

if cfg!(any(test, debug_assertions)) {
super::validate::validate(&dxil).map_err(|e| format!("lane loop DXIL failed validation: {e}"))?;
}
Ok(Kernel { dxil, static_samplers, dispatch_chain: None, exchange_sites: lw.exchange_sites })

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Medium: The lane loop always finishes with try_finish(..) and dispatch_chain: None, bypassing finish_dispatch's split_compute / dispatch_piece_limit() (12,500 instructions). With XCL_WAVE64_LANE_LOOP=all, a large split-wave64 program the split form would run as a dispatch chain becomes one monolithic shader running 64 lanes per thread, and its lane-loop module is already much bigger than the split form's. That brings back the driver compile times, size limits and GPU timeouts the chain avoids. Routing through finish_dispatch, or refusing programs over the piece limit, would keep the chain.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. A dispatch chain cannot carry the lane arrays across its cuts, so in cab682f3e the lane loop refuses a program whose module costs more than dispatch_piece_limit(), measured as split_compute measures it (Module::dispatch_cost, now shared). Such a program keeps the split form and its chain. A program of 512 code dwords (MAX_WORDS) still fits.

Test: lane_loop_refuses_a_program_larger_than_a_dispatch_piece (2,048 instructions; translated whole before the fix).

@bmjask

bmjask commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

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

@Royalflamejlh
Royalflamejlh force-pushed the recompiler/wave64-lane-loop branch from 4a65347 to 50f65e5 Compare December 2, 2026 20:49
@github-actions github-actions Bot added area:tests Unit, integration, e2e tests, or testtitle needs-pr-check Failing the PR description check (CONTRIBUTING.md) labels Dec 2, 2026
@Foniass

Foniass commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

Follow-up review of 50f65e53, since 4a653476 (code reading only, not a merge-check; PR description red) · 1 high, 3 nits

In short: Since 4a653476 the lane loop gives every console wave 64 host threads instead of one: thread 64 x runs wave x and the other 63 leave. Loops take their pass count from the dispatch's share through kernel::loop_head / loop_passes, and a program larger than a dispatch piece is refused, so the split form keeps it with its chain. The new layout breaks the one-wave s_barrier case the form still accepts. It has not run on a GPU: the tested head (c15bcb17) and the smoke head (4a653476) both predate it, and PR description is red.

High

  1. A one-wave group with s_barrier now syncs a group whose other 63 threads have left.

    • translate_on_this_thread refuses s_barrier only when waves > 1 (lane_loop.rs ~107), and the test expects the one-wave barrier program to be taken (~649).
    • Since this push the group is declared as 64 threads (~174), and only thread 0 passes the gate (~254-258).
    • With split: false, wave64: true, barrier_waves is 1 (kernel.rs ~831), so the safe barrier is off. s_barrier lowers to a plain GROUP_SYNC (lower.rs ~1187) that only 1 of 64 threads reaches.
    • D3D leaves that undefined, and emit.rs ~6749 records that bar.sync waits forever on NVIDIA when a warp exits early. Before this push the group had one thread, so it was harmless.

    Fix: lower s_barrier of a one-wave group in the lane loop without the group sync (keep the LDS fence), or declare [1, 1, 1] when waves == 1. Add a GPU test that runs the barrier program.

Nit

  1. Single-wave LDS programs with XCL_X_LDS_ORDER=0 (still open). choose still takes programs that main sends to the HLSL path with XCL_X_LDS_ORDER=0 (kernel.rs ~322). The lane loop keeps LDS order itself, so the result is right, but lds_order_wanted is not consulted and the interaction is not written down.
  2. Overlap with Recompiler: a wave64 compute program folds into one 32-lane wave #3562 (still open). Both add a tag to compact_nest_tag (kernel.rs ~113) and to semantic_pipeline_setting, and both add a section to docs/wave64-on-wave32.md. Whichever merges second resolves the conflicts. With XCL_WAVE64_FOLD=1 also set, the lane loop takes small programs first (pso.rs ~1327).
  3. The description and the first commit message describe the old layout. Both still say a group of N threads is declared as ceil(N / 64) threads with thread x being wave x, but the code now declares waves * 64. Tested refers to c15bcb17, before this change.
Checked and fine
  • Earlier finding fixed: lane-loop kernels had no dispatch chain. A program whose dispatch_cost exceeds dispatch_piece_limit() is now refused and keeps the split form (lane_loop.rs ~170), using the same measure as the split path. lane_loop_refuses_a_program_larger_than_a_dispatch_piece covers it.
  • Earlier finding fixed: the overlap with Recompiler: split wave64 halves skip the exchange at local votes and uniform first-lane reads #3563 and Recompiler/D3D12.X: rebase #2353 (multi-wave/LDS dispatch chains) and split two-pass mesh producers #3504. Both are closed.
  • loop_passes takes the console group's thread count. gpu_direct_compute_loop_passes_follow_the_dispatch now also runs on the lane loop, and lane_loop_loops_have_the_passes_of_the_console_threads checks the divisor.
  • loop_head moved out of translate_on_this_thread unchanged and is shared by both forms.
  • tg_size, the per-lane thread coordinates and the thread-limit gate all derive from tid >> 6. Lanes past the group or a limit still never run.
  • With XCL_WAVE64_LANE_LOOP unset, choose returns None, as on main.

Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.

@bmjask bmjask left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of 50f65e53: 2 finding(s) (1 high, 1 medium), most severe first.

  1. High crates/xcl/src/gpu/dxil/lane_loop.rs:107: With one console wave (waves == 1), s_barrier is let through and lowered by the scalar path (lw.inst at line 146) to a real GROUP_SYNC barrier, but only thread 0 of the 64-thread group reaches it: the other 63 have already left at th.... (inline)
  2. Medium crates/xcl/src/gpu/dxil/lane_loop.rs:364: The 'reads a VGPR it does not name' refusal only sees reads that fall through to init.load (init.touched). (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.

let waves = cs.threads.iter().product::<u32>().div_ceil(64).max(1);
for d in &cfg.insts {
let why = match d.inst.name {
"S_BARRIER" if waves > 1 => "s_barrier in a group of several waves",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

High: With one console wave (waves == 1), s_barrier is let through and lowered by the scalar path (lw.inst at line 146) to a real GROUP_SYNC barrier, but only thread 0 of the 64-thread group reaches it: the other 63 have already left at the runs && leads gate (lines 135/258). A cs([64,1,1]) program with DS_WRITE; S_BARRIER; DS_READ under XCL_WAVE64_LANE_LOOP=all gets GroupMemoryBarrierWithGroupSync in non-uniform control flow after a whole 32-lane hardware wave returned. That's undefined behaviour in D3D12 and in vkd3d-proton's SPIR-V (OpControlBarrier), and can hang on drivers that don't count exited waves. The kernel path avoids exactly this (leave = !any S_BARRIER). Since the test calls it 'one wave: nothing to wait for', dropping the barrier in the lane loop would match.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, and already fixed in f66d74c9f, the head this comment sits on: a group of one console wave is declared as one thread (lane_loop.rs ~174), so its s_barrier waits for nobody who left; groups of several waves still refuse s_barrier. Tests: lane_loop_is_chosen_by_size_and_refusals_keep_the_split_form checks numthreads 1 for the one-wave barrier program (64 at 50f65e53), and gpu_lane_loop_passes_the_barrier_of_a_group_of_one_wave runs one.

});
let touched = std::mem::replace(&mut self.init.touched, before);
r?;
if touched.iter().any(|v| (VAR_VGPR..VAR_BUDGET).contains(v) && !arrays.contains_key(&(v - VAR_VGPR))) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Medium: The 'reads a VGPR it does not name' refusal only sees reads that fall through to init.load (init.touched). Once an earlier lane loop has written VAR_VGPR+m, a read of an unnamed VGPR resolves to that SSA definition, which is lane 63's value from the earlier loop, and nothing is refused. If instruction A names and writes v7, and later instruction B's lowering reads v7 without naming it (e.g. an implicit second dword of a 64-bit or NSA operand that rdna2::vgpr_uses doesn't list), every lane of B silently reads lane 63's v7. Checking the reads themselves, or clearing the VGPR SSA definitions after each lane loop, would make the refusal reliable.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this one happens. Lw::rd puts every variable it reads into init.touched (lower.rs ~410-411), before the SSA looks for a definition, so a read that finds an earlier lane loop's VAR_VGPR + m is recorded the same as one that falls through to init.load. vreg reads through rd (lower.rs ~809). lane_loop_inst empties touched before the lanes run (lane_loop.rs ~311) and refuses after them if a VGPR outside the instruction's arrays is in it (~366). So an instruction whose lowering reads a VGPR that vgpr_uses does not list is refused, whatever wrote that VGPR before.

@Royalflamejlh
Royalflamejlh force-pushed the recompiler/wave64-lane-loop branch from 50f65e5 to f66d74c Compare December 2, 2026 21:14
@github-actions github-actions Bot added needs-pr-check Failing the PR description check (CONTRIBUTING.md) and removed needs-pr-check Failing the PR description check (CONTRIBUTING.md) labels Dec 2, 2026
@Foniass

Foniass commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

Follow-up review of f66d74c9, since 50f65e53 (code reading only, not a merge-check; PR description red) · 3 nits

In short: This push fixes the one-wave barrier problem from the last review: a group of one console wave is now declared as one thread (lane_loop.rs, threads = if waves == 1 { 1 } else { waves * 64 }), so s_barrier has no threads that left early. It adds a GPU test that runs a barrier program through LDS, and a check of the declared numthreads. The two smaller points are unchanged. The description still describes the old layout, and its smoke block names 4a653476.

Nit

  1. Single-wave LDS programs with XCL_X_LDS_ORDER=0 (still open). choose still takes programs that main sends to the HLSL path with XCL_X_LDS_ORDER=0 (kernel.rs ~322). The lane loop keeps LDS order itself, so the result is right, but lds_order_wanted is not consulted and the interaction is not written down.
  2. Overlap with Recompiler: a wave64 compute program folds into one 32-lane wave #3562 (still open). Both add a tag to compact_nest_tag and to semantic_pipeline_setting, and a section to docs/wave64-on-wave32.md. Whichever merges second resolves the conflicts.
  3. The description describes the old layout. What is in it still says "numthreads becomes [ceil(N/64), 1, 1]: thread x is console wave x". The code declares waves * 64 threads, one thread for a single wave, with thread 64 x running wave x. The commit message is already updated.
Checked and fine
  • Earlier finding fixed: a one-wave group with s_barrier synced a group whose other 63 threads had left. With one thread declared, tid is 0, lane == 0 passes the gate, and tid >> 6 gives wave 0, so tg_size and the thread coordinates are unchanged.
  • gpu_lane_loop_passes_the_barrier_of_a_group_of_one_wave writes each lane's value to LDS, meets at s_barrier, reads the neighbour's value, and checks all 64 results.
  • The choose test now asserts !{i32 1, i32 1, i32 1} in the disassembly when it can disassemble.
  • The doc comment and docs/wave64-on-wave32.md describe the one-thread case.
  • The earlier fixes (programs over a dispatch piece are refused, loop passes per console thread) are unchanged.

Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.

@bmjask bmjask left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of f66d74c9: 1 finding(s) (1 medium), most severe first.

Re-review at f66d74c9. Both findings from the 50f65e53 review look addressed: the single-wave s_barrier after the other threads exit isn't flagged any more, and unnamed VGPR reads are now refused (every read and write is recorded in touched). One new item below.

  1. Medium crates/xcl/src/gpu/dxil/lane_loop.rs:258: Not certain about this one, because it depends on how drivers form hardware waves: giving each console wave its own hardware wave assumes the driver packs consecutive flat thread ids into hardware waves, which the codebase says elsewhere.... (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.

Comment thread crates/xcl/src/gpu/dxil/lane_loop.rs Outdated
let tid = self.s.thread_id_in_group(0);
let wave = self.lshrc(tid, 6);
let lane = self.andc(tid, 63);
let leads = self.cmpc(Pred::Eq, lane, 0);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Medium: Not certain about this one, because it depends on how drivers form hardware waves: giving each console wave its own hardware wave assumes the driver packs consecutive flat thread ids into hardware waves, which the codebase says elsewhere isn't guaranteed (setup_lanes: 'the PC need not form waves from consecutive thread indices'). If a driver puts leading threads 0 and 64 in the same lockstep hardware wave, and console wave 0 spins on memory console wave 1 writes (the cross-wave polling the module docs say now 'waits as on the console'), the spinning thread starves the other and the dispatch hangs, the GPU hang this form was meant to avoid. Leading with one thread per hardware wave derived from WaveGetLaneIndex()/wave id, rather than from flat ids, would remove the assumption.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right that it was an assumption: numthreads is 1-D there, but setup_lanes already counts on no particular packing, so the lane loop now does the same. In cab682f3e the first lane of each hardware wave takes the next console wave from a count in the LDS at the entry (wave_by_arrival: zero the count, group sync, WaveIsFirstLane adds 1, group sync), and only those up to the group's console waves run; every other thread returns. Whatever the driver packs, each running thread is the only one of its hardware wave. The count is the LDS's top word (or a word of its own when the program has no LDS), which the program finds as undefined as at any start, since the second sync comes before any of its code.

Test: lane_loop_has_one_thread_a_wave_and_waits_only_at_its_entry (two syncs, one waveIsFirstLane, one atomic add; none at f66d74c9). The GPU tests run on the RTX 2070 SUPER PC; their results go into the description.

Royalflamejlh and others added 2 commits December 2, 2026 14:45
One thread runs a whole console wave: a group has 64 threads for each
console wave, the first lane of each hardware wave takes the next console
wave from a count in the LDS at the entry (a driver need not form waves
from consecutive thread indices) and the other threads leave, so each
console wave is a hardware wave of its own. A group of one wave is
declared as one thread, so an s_barrier there has nobody to wait for. Each
VGPR is 64 dwords local to the thread, and a vector instruction is a loop
over the lanes around its ordinary lowering (Lw::inst_guarded) with the
lane's EXEC bit as the guard. Masks are gathered bit by bit and lane reads
read the register's array, so nothing waits for another hardware wave. The
SSA sees each loop body once: scalars read there are their values before
the loop, and scalars written are taken from the last lane, where masks
and lane reads are whole. Loops have the split form's caps: the head goes
through kernel::loop_head, now shared, with the dispatch's share divided
by the console group's threads.

Refused (the caller keeps the split form): s_barrier in a group of several
waves, v_movrel, scratch memory, image writes, a lane read of a computed
value, and a program larger than a dispatch piece (Module::dispatch_cost
over dispatch_piece_limit), which the split form cuts into a chain.
XCL_WAVE64_LANE_LOOP tags the translated cache.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rograms the lane loop

Off unless asked for: with =1 a split program of at most 512 code dwords
(lane_loop::MAX_WORDS) takes the lane loop where the form supports it,
with =all every program it supports. The 512 is a first guess; GPU time
against the split form is not measured. The switch is part of the
translated cache's identity.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Royalflamejlh
Royalflamejlh force-pushed the recompiler/wave64-lane-loop branch from f66d74c to cab682f Compare December 2, 2026 21:46
@github-actions github-actions Bot added needs-pr-check Failing the PR description check (CONTRIBUTING.md) and removed needs-pr-check Failing the PR description check (CONTRIBUTING.md) labels Dec 2, 2026
@Foniass

Foniass commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

Follow-up review of cab682f3, since f66d74c9 (code reading only, not a merge-check; PR description red) · 3 nits

In short: This push changes how the lane loop gives out console waves: no longer thread 64 x to wave x, but by arrival (wave_by_arrival, lane_loop.rs ~305), because a driver need not form hardware waves from consecutive thread indices. Every thread zeroes a counter, the group syncs, the first lane of each hardware wave adds 1, the group syncs again, and hardware waves past waves leave. The sequence is right for 32- and 64-lane hardware waves and does not clash with the safe barrier or the program's own LDS. The three earlier nits are still open, and no run of this head is recorded (PR description is red).

Nit

  1. Single-wave LDS programs with XCL_X_LDS_ORDER=0 (still open). choose still takes programs that main sends to the HLSL path with XCL_X_LDS_ORDER=0 (kernel.rs ~339). The result is right, because the lane loop keeps LDS order itself, but the interaction is not written down.
  2. Overlap with Recompiler: a wave64 compute program folds into one 32-lane wave #3562 (still open). Both add a tag to compact_nest_tag and to semantic_pipeline_setting, and both add a section to docs/wave64-on-wave32.md. Whichever merges second resolves the conflicts.
  3. The description describes the old layout (still open). What is in it still says "numthreads becomes [ceil(N/64), 1, 1]: thread x is console wave x". Tested names c15bcb17, so the new entry sequence has no recorded run. The commit message and the doc are up to date.
Checked and fine
  • LDS word 8191 does not clash with the safe barrier:
    • The lane loop's Lw has split: false and refuses s_barrier when waves > 1 (~109), so safe_bar is never set (kernel.rs ~831, ~855).
    • Words 8189 / 8190 are never used.
    • setup_lanes_compute, the other user of 8191, is not called.
  • It does not clash with the program's LDS either. Both group syncs sit in the entry block, before the gate (~317, ~321), so every thread reaches both. The program can only write word 8191 after the count is done, and finds it undefined at its start, as on the console. Without program LDS, a one-word xcl_ll_waves is used.
  • With 32-lane hardware waves, waves * 64 threads make 2 * waves hardware waves. The first waves to arrive take 0..waves-1 and the rest leave. With 64-lane waves, each takes one.
  • leads is first && wave < waves. A one-wave group still takes (0, true) with one thread and no syncs.
  • Lanes past the group or the thread limits still never run; only the source of wave changed.
  • Tests: the entry test counts 2 barriers, 1 atomicrmw add and 1 waveIsFirstLane for a 96-thread group. The GPU tests run groups of several waves through both counters (with LDS: 96, 256 and 8x8x4 threads; without: 128) and compare per-thread results, so a wave taken twice or not at all fails.

Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.

@Royalflamejlh

Copy link
Copy Markdown
Contributor Author

Thanks for the follow-ups (to 21:51). At cab682f3e (rebased on main 5ad98ad):

  1. Right. A group of one console wave is declared as one thread again (translate_on_this_thread, lane_loop.rs ~174), so the s_barrier the form accepts there strands nobody; groups of several waves still refuse it. (And since bmjask's 21:33 point, a console wave's hardware wave is chosen at the entry by arrival rather than by thread index: wave_by_arrival.) Tests: lane_loop_is_chosen_by_size_and_refusals_keep_the_split_form now checks numthreads 1 for the one-wave barrier program (64 at 50f65e53), and gpu_lane_loop_passes_the_barrier_of_a_group_of_one_wave runs one: LDS write, s_barrier, the neighbour's dword read back.
  2. The code is left as is: the lane loop keeps the console's LDS order itself (all 64 lanes of one instruction before the next), so XCL_X_LDS_ORDER has no choice to make for it, and it is only taken with XCL_WAVE64_LANE_LOOP set. The description's What is in it now says so.
  3. Yes: whichever of Recompiler: a lane loop form for small split wave64 compute programs #3561 and Recompiler: a wave64 compute program folds into one 32-lane wave #3562 merges second takes the conflicts in compact_nest_tag, semantic_pipeline_setting and the docs. With both switches set the lane loop is tried first for the programs it takes; both are opt-in.
  4. The first commit message and now the description describe the new layout. Tested and the regression blocks are being redone at cab682f3e on the RTX 2070 SUPER PC (whole suite and smoke); the description says so once they are in.

AI use: Claude Code (Claude Opus 5.5) wrote the fixes, the tests and the replies in this round.

@github-actions github-actions Bot added needs-pr-check Failing the PR description check (CONTRIBUTING.md) and removed needs-pr-check Failing the PR description check (CONTRIBUTING.md) labels Dec 2, 2026

@bmjask bmjask left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of cab682f3: 1 finding(s) (1 medium), most severe first.

Re-review at cab682f3. The wave-packing assumption from the f66d74c9 review looks addressed: waves are now assigned by arrival (wave_by_arrival). One new item below.

  1. Medium crates/xcl/src/gpu/dxil/lane_loop.rs:172: The only time limit on the lane loop is a check of static DXIL size (dispatch_cost() > dispatch_piece_limit()), but each lane-loop body runs 64 times in one thread, so GPU time per dispatch is roughly 64x what that size suggests and is.... (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.

if let Some(e) = lw.exchange_error.take() {
return Err(e);
}
if lw.s.m.dispatch_cost() > dispatch_piece_limit() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Medium: The only time limit on the lane loop is a check of static DXIL size (dispatch_cost() > dispatch_piece_limit()), but each lane-loop body runs 64 times in one thread, so GPU time per dispatch is roughly 64x what that size suggests and isn't bounded. With XCL_WAVE64_LANE_LOOP=all, a program just under 12 500 static instructions, or one with long loops (up to 65 536 passes, each now 64 lanes run one after another in one thread), runs about 64x longer per thread than the split form and is never cut into a dispatch chain. That can cause the same TDR/device hang the PR is trying to avoid (the 16 s dispatch at the title's world start). Counting the 64x in the cost estimate, or scaling the loop budget down for the lane loop, would keep it bounded.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not changed, on purpose; here is the reasoning. The loop cap already gives a console lane the passes it gets in the split form (loop_passes over the console group's threads), so the total work of a runaway dispatch is the split form's; what the lane loop gives up is parallelism, by design (one thread per console wave), and that is why it is opt-in and its GPU time is listed under Not tested. Scaling the cap by 64 would end a working loop after 16 passes (1024 / 64, against the floor that keeps working programs whole), and counting 64x in dispatch_cost would refuse nearly every program (about 195 DXIL instructions). The 16 s dispatch in the description is the split form's exchange, not a long loop. If GPU time on real programs shows the lane loop near a timeout, the size limit (MAX_WORDS) is the place to narrow it.

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

Labels

area:docs-ci Documentation, scripts, workflows, repo governance area:recompiler RDNA2 decoder, HLSL/direct-DXIL recompiler, wave64/wave32 area:shaders Shader cache, PSO compilation, pipeline libraries, precompilation area:tests Unit, integration, e2e tests, or testtitle gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) needs-pr-check Failing the PR description check (CONTRIBUTING.md)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants