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

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), 1, 1]: thread x is console wave x.
  • 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, 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.
  • 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.

673 added lines, 635 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

  • None yet: no Windows machine was reachable. The two xcl-smoke blocks are still owed.

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
Contributor

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
Contributor

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 and others added 2 commits December 1, 2026 13:27
One thread runs a whole console wave: a group of N threads is declared as
ceil(N / 64) threads, 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.

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. XCL_WAVE64_LANE_LOOP tags the translated cache.

Not run on a GPU: the test bench has none. The expected values of the three
GPU tests were checked by interpreting the DXIL the form emits.

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 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
Contributor

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.

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 gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants