Shaders: compute threads that read other lanes keep unique ids in 2-D groups (NVIDIA) #2124
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2126"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from Marvisak/VIctory. Originally posted by 0xkn0wh3r3 on 2026-11-25T05:40:30Z.
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.Rebased onto
f3578e3Lowered. Both upstream's and this branch's are kept.lower.rsgrew past the 512 KiB thatcargo xtask policyallows a source file. A new commit movesLower::console_flatandLower::ticketunchanged intolower/thread_ids.rs, next tolower/bvh.rs. The group-shared size they check against moves with them.ec653f6, a program whose LDS already takes the host's whole 32 KiB keeps the old rounding, because the ticket's extra dword would fail validation (programs_with_all_the_lds_keep_the_rounding).cargo test -p victory-shader --lib -- --skip heap_direct_texture_reads_mark_their_heap_indexon the RTX 5070 Ti: 301 passed. The same three tests fail onf3578e3itself: the twostride_testsandgathers_at_a_level_match_the_hardware. Clippy is clean with and without--features diagnostics, and so iscargo xtask policy.Imported from Marvisak/VIctory. Originally posted by DrDarkDK on 2026-11-25T06:02:06Z.
I ran the two
lane_order_testson native Windows with a Ryzen 9 7900X Radeon iGPU (32.0.11024.2) and an RTX 4070 Ti (621.01). I changed only the local test adapter selector to choose each GPU explicitly and verified the D3D12 device’s adapter LUID.Retaining the PR’s tests but using the parent
940d32flowering, both GPUs missed the same six of nine group shapes. For example,32×2marked 32/64 IDs,24×8marked 128/192, and10×10marked 68/100. Withe214ce4, both tests passed on each GPU, and all nine shapes marked every ID.Synthetic tests only. WARP refused
WaveSize(32)and was skipped.AI-assisted with Codex.
Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T06:40:58Z.
Review: APPROVED
Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main
940d32f69b,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.
Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T06:46:05Z.
Review: APPROVED
Verified locally merged onto
origin/main(940d32f, Windows 11 x64, NVIDIA GeForce RTX 5090 + WARP, Rust 1.98.1 MSVC, withdxil.dllvalidator):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).
Imported from Marvisak/VIctory. Originally posted by fiestorra on 2026-11-25T06:10:59Z.
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 (
console_flat, "compute threads that read other lanes keep unique ids in 2-D groups") changes how a thread's console flat id is derived, using a group-shared ticket, because a host may put threads of several rows into one wave; #2117 changes whether a wave size is declared at all, addingmin_lanesand aStop::Widere-lowering for programs that only read within aligned groups of 4, 8, 16 or 32.The question that decides how they land is about your premise for narrow groups. The argument for "an aligned group of
klanes never straddles a host wave" needs the host to fill its waves from consecutive flat ids in group order. #2126's description says that is not what some hosts do: an RTX 5070 Ti fills 2-D groups in 16 × 2 tiles ("24, 32 or 64 wide or not a power of two wide"), and XCL's notes report 2 × 2 quads on an RX 9070. If threads of one aligned group land in different host waves, then a narrow-group read is not within one wave after all, and #2126's ticket is what makes the ids line up again.So:
Stop::Wide) is where it goes wrong if it is.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:
translate --validatewill not show this. A declared or missingWaveSizeis refused by the host when the pipeline is created, so the number that moves is the--pipelinescount (or a boot), not the validated count. If either description has a before/after of that count on a host whose lane count differs from the console's, it would settle the review in one line; on this machine (NVIDIA, 32 lanes,32.0.16.2124) I can measure it for whichever of the two lands first, and for the pair once they agree.No game data is involved: file names, hosts and counts.
Written with an AI assistant.
upstream-sync referenced this pull request2026-11-25 07:03:14 +00:00
Imported from Marvisak/VIctory. Originally posted by 0xkn0wh3r3 on 2026-11-25T07:21:22Z.
@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
waveGetLaneIndex. So an aligned group of G ≤ host-lanes console lanes is always G lanes of one host wave, on any tiling. What breaks on a tiled host is the base. With 16×2 tiles, wave 0 starts at flat id 0 and wave 1 at flat id 16. Rounding both down to the wave width gives both the same base, so every id appears twice and half are never used. That happens for every G. It even happens with no cross-lane read beyondv_mbcnt, which is why the test here stores at its own id and reads nothing else.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
thread_idonmain, and shares the failure. On the conflict: keep the ticket, and in #2117's narrow path take the block size fromwaveGetLaneCount()instead of the console's N. Each host wave then takes one block of host-lane-count ids, and #2117's G argument holds as written. 1-D groups can keep the rounding, since every host probed fills them in order. Either order works; whichever lands second makes that change.On the evidence: #2126 doesn't change whether
WaveSizeis declared, so--pipelineswon't move for it. Its before/after is the stored-id count inrelabelled_threads_each_get_their_own_id, which you can measure on any host that tiles. So far it fails onmainand passes here on an RTX 5070 Ti, an RTX 4070 Ti and a Radeon iGPU, and it passes here on an RTX 5090.Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T10:47:30Z.
Automated triage for the maintainers.
Needs work: needs the maintainer's decision. Rebased onto current
main(63bcca4), and it merges cleanly.What it does: in
crates/victory-shader/src/emit/lower/thread_ids.rs,Lower::console_flatkeeps the round-down for 1-D groups. 2-D and 3-D groups that read other lanes instead give each full host wave a 32-id block from a group-shared ticket (zeroed by every thread before a barrier; the wave's first lane does the add andwaveReadLaneFirstshares the result). The single partial wave takes the last block. Programs whose LDS already fills 32 KiB keep the rounding (Lower::ticket), whichprograms_with_all_the_lds_keep_the_roundingcovers. Moving the code tolower/thread_ids.rskeepslower.rsunder the policy's size limit. The evidence is hardware measurements, not a guess: the stored-id test fails onmainand passes here on an RTX 5070 Ti, an RTX 4070 Ti, an RTX 5090 and a Radeon iGPU, and chippy01 measured the same tiling on an RTX 3070 Ti and RDNA2.For the maintainer:
lane_order_tests::host_waves_keep_what_the_relabelling_relies_onruns an externaldxc.exethroughstd::process::Command(VICTORY_PC_DXC, else the Windows SDK's).diff_tests.rs,flow_tests.rsandemit/mod.rsonmainalready do the same, so this is a quick call.On your reply: confirmed. The rebase keeps both sets of
Loweredtest fields, and the 16-lane skip fromec653f6is in place.CI: passing (
check).Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by KainanP on 2026-11-25T12:30:43Z.
On an Intel UHD (Xe-LP, 16-lane waves), head
e214ce40merged ontomain940d32fmakesrelabelled_threads_each_get_their_own_idpanic with[64, 1]: The parameter is incorrectinstead of skipping, because theWaveSize(32)pipeline is refused on that host. Your probe'shardwareleg ran there and shows most 2-D groups in 4×4 tiles. The layouts are in item 5 of https://github.com/Marvisak/VIctory/issues/1829#issuecomment-7162467900AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this.
amdxc64.dllwhile a translated compute pipeline is created #2515Imported from Marvisak/VIctory. Originally posted by 0xkn0wh3r3 on 2026-11-25T18:40:16Z.
Thanks both. Fixed in
ec653f6.Lower::ticket, noted as a shortcut), so they translate as they do onmain.programs_with_all_the_lds_keep_the_roundingchecks both sides of the limit (32 KiB keeps the rounding, 31.5 KiB takes the ticket) and validates the output wheredxil.dllis found.relabelled_threads_each_get_their_own_idnow reads the host's wave lane range (D3D12_OPTIONS1) and skips with a printed reason when 32 is outside it. It also skips if the host refuses the 1-D program, which takes no ticket, so a refusal there can only be about the wave size. On your UHD it should now skip instead of panicking. A rerun to confirm would be welcome, as I have no 16-lane host here. Your 4×4 tiles are one more layout the ticket handles where rounding doesn't.The
dxc.exetest is left for the maintainer's decision.Imported from Marvisak/VIctory. Originally posted by chippy01 on 2026-11-25T23:45:36Z.
Same measurement on AMD, from #2633 (wave64 in 32-lane halves, which uses the same relabelling). A program stores 1 at its own relabelled id; the table counts how many ids get stored. Hardware: RTX 3070 Ti (driver 32.0.16.2124) and the Radeon iGPU of a Ryzen 9 7900X (RDNA2, driver 32.0.21045):
So the Radeon tiles as well: waves of 32 for rows 32 threads wide or more, and waves of 64 for 64-wide rows. That means
main's own wave64 programs on AMD lose ids in a 64x4 group today. Your tickets cover that case too.#2633 now refuses those shapes in halves. Once this lands, halves can take its ids from your tickets instead (each host wave gets its own 32-aligned block, which is all halves need).
Imported from Marvisak/VIctory. Originally posted by 0xkn0wh3r3 on 2026-11-25T23:52:52Z.
@chippy01 thanks, that settles the AMD side. The Radeon iGPU tiles 2-D groups too: waves of 32 for rows 32 or more wide, and waves of 64 for 64-wide rows, so
main's own wave64 programs lose ids in a 64x4 group on AMD today. The ticket gives each host wave a block of the host wave's width, so it covers both. For #2633: yes, once this lands, halves can take their ids from the ticket (each host wave's 32-aligned block) instead of refusing those shapes. The branch is rebased onto currentmain(256079e).View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.