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 rebase. The earlier notes still apply:
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. |
|
@RaghavVijayanand @0xkn0wh3r3, could whichever PR lands second carry the I ran the emitted DXIL through a CPU model of four 32-lane waves. In a Local checks and comment prepared with Codex on macOS arm64. |
|
Tested against the title on a 32-lane-only card: RTX 2080, driver 32.0.16.1742, Windows 10 19045. The stack is Compute pipelines,
That's 87 more working compute pipelines, and none handed to the driver that it refuses. The 307 refusals:
The 191 look like what #192 targets. One note for measuring: In the game (diag build, scripted Enter presses, DRED on):
My guess, unconfirmed: the change to 🤖 Generated with Claude Code. The measurements were made by Claude Code on my machine. |
|
Correction to my comment above: the hang isn't in That program is small, with no loops and no cross-lane operations, so it can't spin the GPU itself. DRED just listed it among the commands of the hung list. A second run with this PR (plus #192) hung the same way, about 3 minutes in. This time DRED's report says the list stopped at command 4862 of 12115, in a run of commands that starts with a Both of those are refused by the driver without this PR ( Also, for anyone looking at the |
With the lane relabelling of Marvisak#2126: thread ids come from Lower::console_flat, and split_ids too (its halves from the console flat id, so a 32x4 group on a host laying it out in 16 by 2 tiles pairs the right waves). The test host keeps one wave_lanes.
On upstream 842b0cb: the host's depth-bounds and wave-lane queries both kept; thread ids and split_ids from Lower::console_flat (Marvisak#2126); ds_bpermute stays within each 32-lane half as upstream reads the ISA (so Marvisak#1960's test of permutes across halves fails, as does its v_readfirstlane-under-a-compare test with upstream's lane masks); the test host keeps upstream's device setup, wave_lanes as a Result, and gets Host::on for Marvisak#1960's per-adapter tests.
|
@RaghavVijayanand measurements only, no code proposal: where this PR's wave64 split still refuses compute programs on a 32-lane host, and why I think none of them is a safe case for the current barrier design. Setup: this PR's head Sample: the 81 compute programs that #2176 (+ #3115) refuse first at
Why the block is not "every thread once":
So I did not find a small, provably safe subset to carve out of these 75; exact coverage would seem to need the exchange at a group-uniform point before the branch (e.g. a whole-wave ballot hoisted above the AI use: Claude Code (Claude Opus 5.5) instrumented the translator locally, ran the measurement and drafted this note; the measurement setup was prepared with OpenAI Codex (GPT-6.2 Astra). |
|
Superseded by #3147, which carries this branch rebased onto current |
…yout A compute program that reads other lanes is relabelled so that each thread's host lane is its console lane (`Lower::thread_id`): its flat id was its wave's first flat id rounded down to the wave size, plus its lane index. That is a bijection only while each host wave holds one aligned run of flat ids. Measured on an RTX 5070 Ti (driver 621.24), it does not for 2-D groups 24, 32 or 64 wide or not a power of two wide: the driver fills waves with 16 by 2 tiles (ids 0-15 and 32-47 in one wave), so two waves round to one base. A 32 by 2 group gave its 64 threads 32 ids; 32 by 8, 64 by 4, 24 by 8, 12 by 12 and 10 by 10 lost a quarter to a half of theirs, threads computing and storing for the same console thread. (XCL's public notes report 2 by 2 quads on an RX 9070, which would break 8 by 8 groups too.) 1-D groups keep the rounding: hosts put them into waves in order. Other groups take ids by ticket: every thread zeroes a group-shared counter, a barrier, then each full wave's first lane adds the wave size to it and the wave takes the old value as its base; the one partial wave (the group's last threads, its lanes from 0) takes the last run. Computed once, in the entry block. New tests (`emit::lane_order_tests`): - `relabelled_threads_each_get_their_own_id` translates a console wave32 program that reads lanes and stores 1 at its thread's flat id, in nine group shapes, and checks every id is stored once. On main six shapes fail (32 by 2: 32 of 64); with the change all pass. - `host_waves_keep_what_the_relabelling_relies_on` probes the host with a plain HLSL program (the Windows SDK's dxc), printing each shape's wave layout, and checks 1-D groups are aligned runs and each group has at most one partial wave, its lanes from 0. Skipped without dxc. ---- from Marvisak#2126, squashed with its two follow-ups: Shaders: programs whose LDS fills group-shared memory keep the rounding The ticket that gives relabelled threads in 2-D and 3-D groups their ids is one more dword of group-shared memory. A program that reads lanes and already allocates the host's whole 32 KiB would then fail validation ("Total Thread Group Shared Memory storage is 32772, exceeded 32768") where it translated before. Such programs keep the old rounding of the wave's first flat id (`Lower::ticket`), noted as a shortcut: they translate as they did, with the ids it repeats on hosts that put several rows into one wave. `programs_with_all_the_lds_keep_the_rounding` lowers the 8 by 8 program of `lane_order_tests` with 32 KiB of LDS (the rounding) and with 31.5 KiB (the ticket), and validates both where dxil.dll is found; with the ticket forced, the first fails validation. `relabelled_threads_each_get_their_own_id` now skips on a host that runs no waves of 32 (D3D12_FEATURE_D3D12_OPTIONS1's lane range, read by the new `Host::wave_lanes`) or that refuses the 1-D program, which takes no ticket, as an Intel UHD (Xe-LP, waves of 16) did with "The parameter is incorrect". Shaders: relabelled threads' ids are made in a module of their own `Lower::console_flat` and `Lower::ticket`, with the group-shared size they check against, move from `lower.rs` to `lower/thread_ids.rs`, unchanged. With them `lower.rs` grew past the 512 KiB the asset policy allows a source file. Applied on top of the wave64 split from Marvisak#1960/Marvisak#3147 as one commit (the first alone takes lower.rs past the 512 KiB limit). Conflicts: Lower::thread_id takes console_flat (as @stem23456-coder resolved it); Host::wave_lanes is this version (the split's tests unwrap it); both test-only fields kept. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A host may lay a 2-D group out in tiles: an RTX 5070 Ti puts a 32x4 group's threads in 16 by 2 tiles, so the host wave's first flat id, masked to 64, paired the wrong host waves into a console wave (64 output slots written twice, 64 none). split_ids now takes the half and the wave base from Lower::console_flat, which gives each host wave one 32-aligned run of console thread ids in any layout. lane_order_tests::a_wave64_program_runs_as_the_console_runs_it_on_a_32_lane_host runs a wave64 program in 128x1, 16x8 and 32x4 groups, translated for 32-lane waves, and checks every thread's console lane and its wave's lane count. It fails at 32x4 on an RTX 5060 Laptop without this change and passes with it. synthetic_tests::lowered_for translates for a given host wave size. Fix and regression shader by @0xkn0wh3r3 (Marvisak#1960); ported onto Marvisak#2126 by @stem23456-coder (gist 14a4788ec408364054c33f32789728ca); applied here. Co-Authored-By: stem23456-coder <stem23456-coder@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.