Repository navigation
Shaders: compute threads that read other lanes keep unique ids in 2-D groups (NVIDIA) - #2126
0xkn0wh3r3 wants to merge 1 commit into
Conversation
…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.
|
I ran the two Retaining the PR’s tests but using the parent Synthetic tests only. WARP refused AI-assisted with Codex. |
|
This and #2126 rewrite the same arithmetic, they conflict, and one may be a precondition of the other Two pull requests in the same window are changing how a thread's lane is arranged for cross-lane reads, and they are not independent. Measured: they conflict, in the one file where it matters: #2126 ( The question that decides how they land is about your premise for narrow groups. The argument for "an aligned group of So:
I am not asking for both to be merged together; I am asking for the sentence that says which mechanism owns the 2-D case. At the moment two of them claim it and they disagree by construction. A note on the evidence, since it decides what a reviewer can check: No game data is involved: file names, hosts and counts. Written with an AI assistant. |
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. Compute threads reading other lanes keep unique ids — lane-id uniqueness fix for cross-lane reads.
DenRakEiw
left a comment
There was a problem hiding this comment.
Verified locally merged onto origin/main (940d32f, Windows 11 x64, NVIDIA GeForce RTX 5090 + WARP, Rust 1.98.1 MSVC, with dxil.dll validator):
cargo test -p victory-shader --lib emit::lane_order_tests::— 2 passed, 0 failed on both RTX 5090 hardware andVICTORY_D3D12_WARP=1cargo clippy -p victory-shader --all-targets— 0 warningscargo xtask policy— ok (184 files ok)
Clean NVIDIA-verified fix keeping unique thread IDs in 2-D compute groups that read other lanes. Looks great.
AI-assisted (Gemini 4 Neon).
|
@DrDarkDK thanks. A Radeon iGPU missing the same six shapes as the 4070 Ti means this isn't NVIDIA-only. @fiestorra, on which mechanism owns the 2-D case: the ticket does, and it covers #2117's narrow groups too, whatever G is. The failure isn't a lane group straddling host waves. Once ids are relabelled, a console lane is a host lane: a thread's id is its wave's base plus So no size is safe without the ticket on a host that tiles 2-D groups. #2117's relabelling ("a host wave holds an aligned run of flat thread ids") makes the same assumption as On the evidence: #2126 doesn't change whether |
|
Automated triage for the maintainers. The fix looks sound. For 2-D and 3-D groups, This needs the maintainer's decision: the new test Generated by Claude Code |
|
On an Intel UHD (Xe-LP, 16-lane waves), head AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this. |
The problem
Some console compute programs read values from other lanes of their wave (
v_mbcnt,v_readlane, DPP,ds_swizzleand similar). For those to work on a PC GPU, each thread's lane on the host must be its lane on the console. VIctory arranges that by renumbering the threads of such programs (Lower::thread_id): a thread's flat id becomesThat gives every thread a different id only if each host wave holds 32 consecutive flat ids, starting at a multiple of 32, which is how the console fills its waves.
NVIDIA does not always do that. Probed on an RTX 5070 Ti (driver 621.24), for 2-D groups 24, 32 or 64 threads wide, or not a power of two wide, the driver fills a wave with a 16x2 tile of the group instead of a row:
Both waves round down to the same base (0 and 16 both round to 0), so two threads end up with every id and half the ids are never used. The program then computes and stores the same results twice and never writes the other half. Measured with a translated program that stores 1 at its own thread id:
XCL's public notes report that an AMD RX 9070 lays 2-D groups out as 2x2 quads, which would break 8x8 groups there too.
The fix
The renumbering no longer guesses from where a wave starts. It hands each wave its block of 32 ids explicitly:
[n, 1, 1]) keep the old rounding. Every host measured fills them in order, and the new test checks that it does.WaveReadLaneFirst).Each wave gets a different block, so every id is used exactly once however the GPU arranges the threads. It is computed once, at the start of the program; the cost is one barrier and one group-shared atomic per wave, and only in 2-D and 3-D programs that read other lanes.
Testing
Two new tests in
emit::lane_order_tests:relabelled_threads_each_get_their_own_id: translates a console wave32 program that reads lanes (v_mbcnt) and stores 1 at its thread id, runs it in the nine shapes above, and checks every id is stored exactly once. It fails on main (the table above) and passes with the change.host_waves_keep_what_the_relabelling_relies_on: probes the GPU itself with a plain HLSL program (built with the Windows SDK'sdxc.exe;VICTORY_PC_DXCpoints elsewhere) and prints each shape's wave layout. It checks the two things the fix relies on: 1-D groups fill waves in order, and each group has at most one partial wave, filled from lane 0. Skipped withoutdxc; WARP refusesWaveSize(32)and is skipped.cargo test -p victory-shader --libon the RTX 5070 Ti passes except the three tests that fail on main there too (twostride_testsandgathers_at_a_level_match_the_hardware, fixed by #1887 and #1777). Clippy is clean with and withoutdiagnostics.Not checked on AMD hardware or in a title run.
Related
#2117 renumbers the threads of the programs it lets drop their
WaveSizeusing the same "waves hold aligned runs" assumption, so the shapes above break there too. Whichever of the two lands second should take its ids the same way.