Repository navigation
Shaders: compute threads that read other lanes keep unique ids in 2-D groups (NVIDIA) - #2126
0xkn0wh3r3 wants to merge 3 commits into
Conversation
|
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. Needs work: needs the maintainer's decision. Rebased onto current What it does: in For the maintainer:
On your reply: confirmed. The rebase keeps both sets of CI: passing ( 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. |
|
Thanks both. Fixed in ec653f6.
The |
…e ids in 2-D groups) into demo # Conflicts: # crates/victory-shader/src/emit/lower.rs # crates/victory-shader/src/emit/synthetic_tests.rs
…k#2085's early_depth is
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.
ec653f6 to
fc065f2
Compare
What was wrong: the thread relabelling gives a thread the flat id of its host wave's first lane, rounded down to 32, plus its host lane. That is a bijection only while every host wave holds a 32-aligned run of flat ids. Hosts fill the waves of a group of several rows with tiles when its rows are 32 threads wide or more. A wave then holds a 16 x 2 tile, two waves round down to the same base, and two threads share every id while half the ids go unused. Measured in halves with a program that stores 1 at its own id, on an RTX 3070 Ti (driver 32.0.16.2124) and the Radeon iGPU of a Ryzen 9 7900X (RDNA2): - 32x2, 32x8, 64x4, 32x32 and 32x2x2 groups store half their ids, on both; - 8x4, 4x4, 8x8, 16x2, 16x4, 8x16, 16x16, 4x4x4, 2x2x16, 8x8x4 and one-row groups store all of them. Marvisak#2126 (0xkn0wh3r3) measured the same tiling on an RTX 5070 Ti, and for rows 24, 12 and 10 threads wide too, for main's 32-lane programs. What changed: halves refuse a group of several rows whose rows are 32 threads wide or more or not a power of two wide, with its reason (`halves::halves_tiles`). halves.rs and halves_tests.rs are rustfmt-clean. Evidence: translate --list --wave32 over shaders.rpf, the executable, XboxBvhBuilder.dll and the FidelityFX DLL, on main 842b0cb merged: no emitted program changes (2,369); with --pipelines on the RTX 3070 Ti, 2,369 compute pipelines are made, none refused by the driver. The title's programs in halves that translate are in groups of 8x8, 8x4, 4x4 or one row. Its programs in groups of 32x2, 32x32 or 6x6 were refused already; 2 of them (GpuParticleEmit's water emitters) now give this reason first, the rest the one-wave LDS reason. The exchanges planned next would otherwise have run them wrongly. Tests (emit::halves_tests): - groups_a_host_wave_may_tile_are_refused_in_halves: 32x2, 64x4, 32x2x2 and 6x6 are refused; 8x8, 16x2, 4x4x4 and 64x1 translate. - every_thread_keeps_its_own_id_in_halves_on_every_gpu: 8x8, 16x2, 4x4x4 and 64x1 store every id on both GPUs, in halves and (on the Radeon) as one wave64. Found on the way, not changed here: under main's rounding to 64, the Radeon's own wave64 stores 128 of a 64x4 group's 256 ids (32-wide groups are laid out in rows there). Marvisak#2126's per-wave tickets cover that too; once it lands, halves can take their ids from it and drop this refusal. Checks: cargo clippy --workspace --all-targets --locked -- -D warnings, and with --all-features: clean. cargo xtask policy: ok. cargo test -p victory-shader --lib -- --test-threads=1: 307 passed, 3 failed, the same 3 as on main on this NVIDIA machine; heap_direct_texture_reads_mark_their_heap_index skipped as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
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 #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). |
…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.
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".
`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.
fc065f2 to
256079e
Compare
|
@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 |
With Marvisak#2085: both test-only fields kept.
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.
…here: rebased only)
Adapt the wave ticket from Marvisak/VIctory#2126 (411ed48) to this fork’s split-wave lowering. Reserve the final logical wave for the partial hardware wave and use one initializing thread and one atomic per full wave. Co-authored-by: 0xkn0wh3r3 <360897260+0xkn0wh3r3@users.noreply.github.com>
…ounter A console program whose code reads other lanes runs in host waves of the console's size, and its threads were relabelled so that each console lane is its host lane: the flat id of the wave's first lane, rounded down to the wave size, plus the host lane. That is a bijection only while every host wave holds a run of flat ids. Hosts fill the waves of a group of several rows with tiles when its rows are 32 threads wide or more, or not a power of two wide: two waves then round to the same base, two threads share every id, and half the ids go unused. On the RTX 4070 Ti here a 32 x 2 group stored 32 of its 64 ids that way (the new card test, without the change). Such a group now takes its waves' bases from an LDS counter, as the programs run in halves and the paired form already did (wave_base): every thread zeroes it, the group meets once, each wave's first lane adds a wave. Only for groups of whole waves; a group with a part-filled wave keeps the old relabelling. Over the title's archive no program is in such a group today (counted with a temporary log line): no translation changes. The paired form was checked for upstream's two defects as well: its host group is one row and its bases come from the counter (no tiling), and its first-lane read takes the lower lane first, the upper only when no lower lane is in EXEC (the paired v_readfirstlane in lower.rs), as the console. From Marvisak/VIctory PR Marvisak#2633 (86a16dc, "in halves, a group a 32-lane host wave may tile is refused", measured on an RTX 3070 Ti and RDNA2; Marvisak#2126 for rows 24, 12 and 10 wide on an RTX 5070 Ti). Here relabelled by the counter instead of refused. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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 f3578e3
Lowered. 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.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.