Skip to content

Shaders: wave64 compute programs on hosts of 32-lane waves - #1960

Open
RaghavVijayanand wants to merge 2 commits into
Marvisak:mainfrom
RaghavVijayanand:shader/wave64-on-wave32
Open

RaghavVijayanand wants to merge 2 commits into
Marvisak:mainfrom
RaghavVijayanand:shader/wave64-on-wave32

Conversation

@RaghavVijayanand

@RaghavVijayanand RaghavVijayanand commented Nov 25, 2026 •

Copy link
Copy Markdown

Wave64 compute programs that read other lanes declare WaveSize(64), so pipeline creation fails on GPUs with only 32-lane waves (all NVIDIA GPUs, for example). The README listed this as "some compute programs need a GPU with 64-lane waves". Two commits.

Shaders (emit/lower/wave64.rs): on a 32-lane host, the program declares WaveSize(32) and each console wave becomes two host waves, with thread ids kept in the console's lane order.

  • Operations within one half are unchanged and exact: DPP, ds_swizzle, v_writelane, v_mbcnt, and a lane's mask bit.
  • Operations that span both halves exchange through group-shared scratch (store, sync, load, sync). This covers 64-bit ballots, v_readlane at any lane, v_readfirstlane, whole-wave reductions, and prefix sums.
  • Partial last waves are handled. Groups of 32 threads or fewer need no exchange.
  • Still refused, each with its own reason:
    • a cross-half operation in a block not every thread runs exactly once (in a loop, or not on every path), where a group sync could hang
    • a 33-64-thread group that uses LDS, where the console compiler omits barriers within one wave
    • LDS plus scratch above 32 KiB
  • Main's newer cross-lane operations in the split:
    • ds_bpermute_b32 (reads any of the 64 lanes) now reads through the exchange. It has a new test, permutes_read_lanes_of_the_other_half, with 128, 96 and 64 threads and full and partial EXEC.
    • 16-bit whole-wave sums are refused in a split, marked as a shortcut.
    • Main's WAVE_OPS flag for waveGetLaneIndex (1e923ad) is kept, in the one place that now makes host lane indices.
  • Pre-existing bug fixed, for any wave size: a guarded v_readfirstlane read the host's first active lane, which can be outside EXEC. It now reads the first lane of the guard's ballot. Main's own fix for pixel helper lanes is applied on top.

GPU: host creation reads OPTIONS1 WaveLaneCountMin/Max and tells the translator whether the host has 64-lane waves. The shader cache key differs for 32-lane hosts. The README entry is updated.

Tests: the new emit/wave64_tests.rs (9 tests) hand-assembles wave64 programs and checks every lane against a CPU model of the console wave. One test checks the in-file assembler against the repo's decoder.

  • Programs cover ballots with s_bcnt1/s_ff1/v_mbcnt, v_readlane at fixed and SGPR lanes, v_readfirstlane under narrowed EXEC, v_writelane, DPP/permlane prefix sums, reductions, and a ballot after divergence.
  • Group sizes are 128, 96, 64 and 32 threads.
  • Adapters: an RTX 5060 Laptop (32 lanes) ran the split path, and a Radeon 780M (32-64 lanes) ran both the split and the native WaveSize(64) path. WARP (4 lanes) is skipped. Each test asserts that the 32-lane path ran on at least one device.
  • Liveness: making the exchange read its own half failed 4 GPU tests on the 32-lane path. Disabling the every-thread check failed both refusal tests. The guarded-readfirstlane test failed on the 780M before the fix.
  • The victory-gpu wiring has not run against the title, since there is no game data.

Rebased onto current main (940d32f). On this machine, 5 tests fail on main itself, with or without this change: descriptor::host::tests::dynamic_slots_are_held_until_released, memory::tests::lists_share_a_table_and_copies_keep_their_views, the two stride_tests::a_heap_buffer_read_* tests, and synthetic_tests::gathers_at_a_level_match_the_hardware. Everything else passes, and clippy passes with -D warnings, with and without --all-features.

Copilot AI balanced review requested due to automatic review settings November 25, 2026 01:45

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@upipibi

upipibi commented Nov 25, 2026

Copy link
Copy Markdown

Overlap note, from reading, not a run: #1890 (opened earlier) runs wave64 compute programs on 32-lane hosts the same way: WaveSize(32), each console wave as two host waves, cross-lane reads combined through group-shared memory. I verified it on an RTX 3070 (32-lane only) there. #1929 is a rebase of the earlier #233 with the same aim. This branch is based on ffe310e and conflicts with main. Three versions of one change would be hard to review, so it may be worth comparing against #1890 before rebasing.

AI-assisted (Claude Code).

@Headache3318

Copy link
Copy Markdown

Tested on Linux (Arch, kernel 7.3.5, 3× RTX 4090 driver 620.73.04), Rust 1.98.1 (pinned). PR head e852943 applied cleanly onto current main ccfb029.

  • cargo test -p victory-shader --locked: 96 passed, 0 failed, 1 ignored. All tests pass.
  • cargo clippy -p victory-shader --all-targets -- -D warnings: 3 errors (vs 4 on main). The PR net-reduces clippy errors by fixing unused imports.

Not tested: Windows MSVC build, the title itself. AI-assisted.

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Needs work. CI fails. Six emit::wave64_tests tests panic at wave64_tests.rs:334 with "no SM 6.6 device ran the program" on the WARP-only runner, because each test requires at least one device to run the 32-lane path. They need to skip when no hardware adapter can run it, as other GPU tests do.

This also overlaps #1890, which splits wave64 programs into two 32-lane host waves the same way and reports a run of the title on an RTX 3070, and #1929 has the same aim. Please compare against #1890 so the maintainer can pick one. The victory-gpu wiring (the OPTIONS1 query in host.rs, the shader_cache.rs key) looks fine.


Generated by Claude Code

A compute program that reads other lanes declares the console's wave size
(WaveSize), so a wave64 one could only be created on a GPU with 64-lane
waves: NVIDIA's run 32 lanes only, and pipeline creation failed there.

The translation now knows whether the host has 64-lane waves
(emit::set_host_wave64, default yes). Without, such a program declares
WaveSize(32) and each console wave becomes two host waves (lower/wave64.rs).
Thread ids keep the console's lane order, the console lane is the host
lane plus 32 in the second half, and what stays within a half is exact as
it was: DPP, ds_swizzle, v_writelane, v_mbcnt, a lane's bit of a mask.
What spans both halves goes through group-shared scratch (store, group
sync, load, group sync): 64-bit ballots of lane masks read as data,
v_readlane at any lane, v_readfirstlane, ds_bpermute (the lane read and
its bit of EXEC's ballot), and whole-wave reductions and prefix sums
(each half's, combined with the other half's). A group sync is made only
in blocks every thread of the group runs once (no loop contains them,
every path to an end passes them); elsewhere the program is refused, as
it is for a group of 33 to 64 threads with LDS (one console wave, which
the console compiler leaves without barriers), for scratch beyond 32 KiB
of group-shared memory, and for 16-bit whole-wave sums (shortcut: not
joined over the halves). A group of at most 32 threads is one host wave
and needs no exchange. Every waveGetLaneIndex the translation makes sets
the wave-operations feature flag.

v_readfirstlane under a lane guard (an EXEC the structurisation could not
prove) read the host's first active lane, which can be outside EXEC; it
now reads the first lane of the guard's ballot, on any wave size (a pixel
helper lane still takes its own value).

The test host can now enumerate hardware adapters (Host::hardware: GPUs
as the default adapter is chosen, not software and with video memory of
their own) and read their wave sizes (Host::wave_lanes).

Tests (emit/wave64_tests.rs): hand-assembled wave64 programs of 128, 96,
64 and 32 threads with ballots (s_bcnt1, s_ff1, v_mbcnt), lane reads at
lanes of both halves, v_readfirstlane with full and partial EXEC, a
ballot under a narrowed EXEC, v_writelane, whole-wave sum, prefix sums
and maximum sections, a ballot after a divergent branch, and ds_bpermute
across the halves with full and partial EXEC, each lane checked against
a model of the console's wave. Each runs on every hardware adapter and
WARP for the wave sizes it supports: the RTX 5060 (32 lanes) ran the
split programs, the Radeon 780M (32-64) both the split and the
WaveSize(64) ones, WARP (4 lanes) neither. Refusals are tested for a
ballot in divergent code, a lane read in a loop and LDS in one console
wave. The tests fail when the exchange reads its own half instead of the
other, when the every-thread check is dropped (the 2 refusal tests), and
the permute test when ds_bpermute reads within its half; the guarded
v_readfirstlane test failed on the 780M's 64-lane waves before the fix.
The translation can split wave64 compute programs into host waves of 32
lanes, but only when told the host lacks 64-lane waves. The host device
now reads WaveLaneCountMin and WaveLaneCountMax (D3D12 OPTIONS1) when it
is created, logs them and passes whether 64 lies between them to
emit::set_host_wave64. Translation (at first use and `translate --cache`
alike) creates the device first, so the setting is in place before any
program is translated, and the shader cache keys translations for hosts
without 64-lane waves apart from the others. README: what is still
missing on such hosts.

Builds and passes clippy and the workspace tests; not run against the
title (no game data here).

@catminou4 catminou4 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.

Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main 940d32f, cargo test -p victory-shader --locked.

144 passed / 0 failed / 2 ignored. Wave64 compute programs on hosts of 32-lane waves — third PR in this cluster (#1890, #1929 flagged earlier); emulation strategy must be consistent across the three.

@Creaa

Creaa commented Nov 25, 2026

Copy link
Copy Markdown

Test report: this PR on Windows with an NVIDIA GPU (RTX 4070, 32-lane waves only). Head fc61f2e, merged locally onto main 940d32f together with #1763 and #1751 (no conflicts), so that the title boots on this card (#1952) and the view heap keeps its dynamic slots.

Setup: RTX 4070 12 GB, driver 617.14, i7-13700F, 32 GB RAM, Windows 11 build 26300, Rust 1.98.1 (pinned).

Tests (cargo test --workspace --locked --no-fail-fast, debug):

translate --cache --pipelines on the title's shader pack, same card:

main this merge
containers translated / refused 25 678 / 307 25 366 / 619
pipelines skipped: compute shader does not translate 61 368
pipelines skipped: the host refuses it 395 1

So the host no longer refuses wave64 compute pipelines; the cases this PR refuses on purpose (divergent ballots, lane reads in loops, LDS in a wave64 wave of more than 32 threads) now show up as about 300 compute programs that do not translate.

Title run: the splash and loading screens at 30 fps as before; at the first in-engine cutscene the frame rate falls to 0.1 fps with about 10 s of GPU time per frame and a black, then grey screen with no visible 3D objects, then the device hangs (246 s). That is the same as without this PR on this card, and matches #898, so it is not something this PR changes.

Not tested: other NVIDIA cards and drivers, this PR on its own (the title does not boot on this card without #1763 or another fix for #1952).

AI use: Claude Code (Claude Opus 5.5) ran the builds, tests and runs on my machine and drafted this comment; I checked it before posting.

@MrEjecutor

MrEjecutor commented Nov 25, 2026 •

Copy link
Copy Markdown

Offline data from an RTX 5060 Ti (Blackwell, 32-lane only): +90 compute pipelines, none lost; the shader-binning chain still stops at its third program

Setup: RTX 5060 Ti 16 GB, driver 621.24, Windows 11 26200, head fc61f2e on its base 940d32f, release build, victory translate --validate --pipelines --list over the title's files, compared program by program with the same run on 940d32f.

One thing first, because it made my first run read "no change": the --validate --pipelines mode builds the shader crate's own Host, not victory-gpu's, so set_host_wave64(false) is never called there and it translates as for a 64-lane host (the default). My first run gave exactly the main counts for that reason. For the numbers below I set it to false in that mode with a local switch (not part of this PR, not posted). The --cache warm-up goes another way, so it may not be affected; I did not check that.

940d32f this PR, 32-lane
compute programs with a working pipeline 2,293 2,383
lost (a pipeline before, none now) – 0
gained – 90, all of them pipeline: The parameter is incorrect before

The chain I was looking at is shader_binning_utils. On this card, with it refused, the colour targets of a world frame hold only small objects while depth holds the whole view (#1968):

program 940d32f this PR, 32-lane
CS_GenerateShaderBins pipeline refused pipeline created
CS_GenerateShaderBins_Tiled pipeline refused pipeline created
CS_GenerateShaderBinOffsets pipeline refused refused on purpose: "a wave64 cross-lane operation spanning both halves, on a host without 64-lane waves, where not every thread of the group arrives once"

The two other wave64 approaches I measured the same way stop at the same program: #1929 (on its base 42363ab) refuses all three in emit, and a port of #189 (on 70564ae) creates the first two and refuses the third ("a 64-lane wave ballot in divergent control flow"). So on 32-lane cards the third program is the one left in that chain for all three.

Edit: for comparison, the fork fxceless/victory-fork at 310c6eb (offline, translating as for a 32-lane host with its VICTORY_HOST_WAVE=32, VICTORY_WAVE_WHY=1) creates pipelines for all three, but the third only through its last-resort approximate mode: every exact retry stops (lane reads in a half-wave, a lane mask exchanged where not every lane runs, a first-lane read where not every lane runs), and the one that goes through makes each host wave of 32 take masks and lane reads over its own lanes only. So nobody has an exact form of that program for 32-lane hosts yet, as far as I can tell. A guess I have not checked: if its offsets come out wrong that way, some bins would be left unshaded, which could be why large surfaces are missing in places in the fork's picture on this card.

Not tested: a game run with this PR (Creaa's RTX 4070 run above already shows the world the same as without it); the --cache path; other cards.

AI use: Claude Code built, ran and wrote this; checked by mrejecutor. No game data attached.

@0xkn0wh3r3

Copy link
Copy Markdown

Tested this on an RTX 5070 Ti (driver 621.24, 32-lane waves only). It runs wave64 compute there, and all ten wave64_tests pass. One group layout comes out wrong, though.

What I ran. A console wave64 compute program in a 128-thread group (two console waves). Each thread stores, at its flat id, its console lane (v_mbcnt_lo/hi) and its wave's lane count (s_bcnt1_i32_b64 of exec). On the console every thread should get flat % 64 and 64. Translated with set_host_wave64(false), as the host sets it on this card:

group result on this PR (fc61f2e)
128x1 matches the console
16x8 matches the console
32x4 lanes 0-31, lane counts 32, and some threads' slots never written

Why. For some 2-D groups, NVIDIA does not fill a host wave with 32 consecutive flat ids. It fills it with a 16x2 tile of the group. I probed this with plain HLSL on the same card: a 32x2 group's first wave holds ids 0-15 and 32-47. 2-D groups 24, 32 or 64 wide, or not a power of two wide, are laid out this way. 1-D groups and 8x8, 16x16 and 16x8 groups are in order.

split_ids takes the half and the console wave's base from the host's first flat id (waveReadLaneFirst(flattenedThreadIdInGroup)), and thread_id rounds that same id down. With tiles, two host waves round to the same base: they are paired into the wrong console waves and given the same ids.

A fix. #2126 hits the same assumption for wave32 programs that read lanes. It gives every host wave its own aligned run of ids with a group-shared ticket: each full wave's first lane adds the wave size to a zeroed counter, and the one partial wave takes the last run. 1-D groups keep the rounding. With that relabelled id (console_flat), split_ids becomes:

let f = self.console_flat();
let e = self.s.entry;
let (k32, not63) = (self.s.m.i32(32), self.s.m.i32(!63));
let half = self.s.m.bin(e, Bin::And, f, k32);
let base = self.s.m.bin(e, Bin::And, f, not63);

With both PRs and this change merged, all three shapes match the console on the RTX 5070 Ti, and this PR's ten tests still pass. That combination is on 0xkn0wh3r3/VIctory branch demo, with the test above as emit::lane_order_tests::a_wave64_program_runs_as_the_console_runs_it_on_a_32_lane_host.

Whichever of the two lands second needs the change. If this one goes first, its split could take the same ticket on its own, keeping the rounding for 1-D groups.

@Machad3x

Copy link
Copy Markdown

In-title run on an RTX 3080 Ti (32-lane waves only): refused pipelines go from 157 to 0; GPU work per frame goes up

Setup: RTX 3080 Ti 12 GB, driver 621.24, Windows 11 26300, Series X profile, diag build, VICTORY_SHADER_LOOP_LIMIT=4096, scripted Enter presses, cache filled with translate --cache. main 940d32f + #1763 + #1751 + #1800 + #1906 + #2098 + #1762 (the stack from my comment on #1968), then the same plus #688 and this PR (fc61f2e). Cherry-picked without conflicts. One 7-minute run each, so run-to-run variation is not measured, and the second build differs by #688 too.

stack stack + #688 + this PR
host pipeline refused 157 (all compute, E_INVALIDARG) 0
translate --cache, containers refused 307 619
does not translate lines in the run 19 147 (143 compute)
submissions over 1 s 0 (slowest 381 ms) 15 (slowest 3,561 ms)
GPU time per frame, last samples about 460 ms about 600 ms
end no device removal at 420 s no device removal at 420 s (TdrDelay is 10 s on this machine)

The most frequent new refusal reasons at run time:

  • 72 × LDS shared without barriers by a wave64 group of 33 to 64 threads, on a host without 64-lane waves
  • 58 × a wave64 cross-lane operation spanning both halves, on a host without 64-lane waves, where not every thread of the group arrives once
  • 1 × a 16-bit wave reduction in a wave64 program, on a host without 64-lane waves

I did not identify which programs make the slow submissions. With the default 2 s TDR delay, submissions of 3.5 s could reset the driver.

AI-assisted (Claude Code); measured on my own machine.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants