Repository navigation
Shaders: wave64 compute programs on hosts of 32-lane waves - #1960
RaghavVijayanand wants to merge 2 commits into
Conversation
|
Overlap note, from reading, not a run: #1890 (opened earlier) runs wave64 compute programs on 32-lane hosts the same way: AI-assisted (Claude Code). |
|
Tested on Linux (Arch, kernel 7.3.5, 3× RTX 4090 driver 620.73.04), Rust 1.98.1 (pinned). PR head
Not tested: Windows MSVC build, the title itself. AI-assisted. |
|
Automated triage for the maintainers. Needs work. CI fails. Six 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 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).
e852943 to
fc61f2e
Compare
catminou4
left a comment
There was a problem hiding this comment.
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.
|
Test report: this PR on Windows with an NVIDIA GPU (RTX 4070, 32-lane waves only). Head Setup: RTX 4070 12 GB, driver 617.14, i7-13700F, 32 GB RAM, Windows 11 build 26300, Rust 1.98.1 (pinned). Tests (
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. |
|
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 One thing first, because it made my first run read "no change": the
The chain I was looking at is
The two other wave64 approaches I measured the same way stop at the same program: #1929 (on its base Edit: for comparison, the fork Not tested: a game run with this PR (Creaa's RTX 4070 run above already shows the world the same as without it); the AI use: Claude Code built, ran and wrote this; checked by mrejecutor. No game data attached. |
|
Tested this on an RTX 5070 Ti (driver 621.24, 32-lane waves only). It runs wave64 compute there, and all ten 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 (
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.
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 ( 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 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. |
|
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,
The most frequent new refusal reasons at run time:
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. |
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 declaresWaveSize(32)and each console wave becomes two host waves, with thread ids kept in the console's lane order.ds_swizzle,v_writelane,v_mbcnt, and a lane's mask bit.v_readlaneat any lane,v_readfirstlane, whole-wave reductions, and prefix sums.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.waveGetLaneIndex(1e923ad) is kept, in the one place that now makes host lane indices.v_readfirstlaneread 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/Maxand 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.s_bcnt1/s_ff1/v_mbcnt,v_readlaneat fixed and SGPR lanes,v_readfirstlaneunder narrowed EXEC,v_writelane, DPP/permlane prefix sums, reductions, and a ballot after divergence.WaveSize(64)path. WARP (4 lanes) is skipped. Each test asserts that the 32-lane path ran on at least one device.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 twostride_tests::a_heap_buffer_read_*tests, andsynthetic_tests::gathers_at_a_level_match_the_hardware. Everything else passes, and clippy passes with-D warnings, with and without--all-features.