Repository navigation
Shaders: wave32 lane masks on 64-lane host waves take their half's dword - #3556
kilolimaVI wants to merge 5 commits into
Conversation
On a host that runs pixel waves of 64 lanes (AMD; a Radeon 780M here), a wave32 pixel or vertex program's 32-bit lane masks were the ballot's low dword in every lane: lanes 32-63 tested the bits of lanes 0-31, so a loop that serves one value per pass (s_ff1 of EXEC, v_readlane, v_cmpx) never served them. Each 32-lane half now takes its own dword, as two console waves would, and lane numbers from masks (v_readlane at a computed lane, v_mbcnt) count within the half. Hosts running 32 lanes (NVIDIA, WARP) are unchanged; wave64 programs emit the same DXIL. Test: lane_mask_tests draws such a loop over a 16x16 target in wave32 and wave64. Before, the 780M served 88 of 256 pixels a wrong key in wave32 (0 in wave64, 0 on WARP); now 0 everywhere. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
I checked the merge order for the Wave32 mask fix alongside #3421. The exact heads of #3556 ( Adding the barycentric lowering split from #3335 (
These are local software-rendering results. The Radeon 780M measurement above is the hardware evidence for #3556. Its Windows workflow is still awaiting approval. The next step is for the maintainers to choose a merge order that puts the split in place before both wave changes are in |
|
RDNA1 run, and an overlap with #125 / #145. RX 5700 XT (RDNA1), driver 32.0.21045.29003, Windows 11 26200, no game files. All trees are merged onto
So RDNA1 shows the same 88/256 as your 780M, and this PR fixes it. Full Overlap: this is the bug #125 tracks: a wave32 pixel/vertex program's lane masks only use the low ballot dword on a 64-lane host wave, which I confirmed on this card earlier today. #145 (TheHoracio's) fixes it a different way: a 64-bit host ballot for mask ops ( Not run: #145's test on this PR. Windows Application Control on this machine blocked that test binary on every rebuild. AI use: Claude Code (Claude Opus 5.5). |
host_half and host_lane move to lower/lanes.rs, as lower/bvh.rs, so lower.rs stays under the asset policy's 512 KiB with Marvisak#3421 merged beside this. No change in behaviour. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks for checking the merge order. Rather than depend on #3335 landing first, I moved the two helpers ( AI-assisted (Claude). |
|
Thanks for the RDNA1 run and for spotting #125 / #145. That overlap is my miss: my check of open PRs didn't go back that far, and #145 was first. The two fixes differ in shape. #145 widens a wave32 program's masks to the host's 64-bit ballot (lane numbers, counts and compares over the whole host wave). This PR treats a 64-lane host wave as two console waves: each lane reads its own half's dword, and lane numbers from masks count within the half ( I'm happy for the maintainers to take whichever they prefer. If it's #145, I'll close this one, and the hardware test ( AI-assisted (Claude). |
|
I retested the split on the exact new #3556 head The combined commit keeps both exact parents. App-local WARP gave the expected keys for all 256 pixels at each guest wave width, and the DPP row-mask and quad-swizzle/first-lane readbacks passed. All nine wave lowering tests and both strict shader Clippy configurations passed. The author reported the same pixel result on the Radeon 780M after the split. The earlier RX 5700 XT result is for The merge-order question is resolved for these two changes. The maintainers can now choose between the approaches in #3556 and #145. If reusing my merge resolution, please retain Git authorship, or add |
|
RX 5700 XT at the new head
So the two agree on the bug, but disagree on what a wave32 program sees on a 64-lane host wave:
A wave32 program on the console never sees a lane number above 31, so where its code depends on that (a lane number used as an index or a shift, a count compared with 32), this PR's form keeps the console's values. That could help the maintainers choose between the two. AI use: Claude Code (Claude Opus 5.5). |
…64-lane host wave A wave32 pixel or vertex program on a host that runs 64 lanes per wave has two console waves in each host wave (MaskData::Host). Lane masks are already taken per half; v_readfirstlane still went to waveReadLaneFirst over the whole host wave, so lanes 32-63 read the value of the first active lane in 0-31, another console wave's. A value the console keeps uniform per wave (a flat attribute, a scalarised index) then came from the wrong primitive in the upper half. With masks split by halves, v_readfirstlane now reads the first active lane of this lane's half: FirstbitLo of the half's ballot dword, offset by 32 in the upper half, through waveReadLaneAt. Elsewhere it is waveReadLaneFirst as before. The helper lives in lower/lanes.rs. lane_mask_tests: the draw loop is shared, and a new test checks that the pixels reading one value are at most a console wave and include the pixel whose value it is. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Added one commit ( A wave32 pixel program on a 64-lane host wave has two console waves in it. Lane masks were already taken per half; With masks split, it now reads the first active lane of its own half (FirstbitLo of the half's ballot dword, +32 in the upper half, New test
WARP runs 4-lane waves, so only a 64-lane hardware wave shows it. The lane-mask loop test is unchanged (88/256 wrong on main, 0 here). 5 of 5 runs, full suite 553 passed, clippy clean. AI-assisted (Claude). |
…64-lane host wave A whole-wave section (the compiler's expansion of a wave sum, minimum, bit operation or prefix sum) lowers to DXIL's waveActiveOp, waveActiveBit or wavePrefixOp over the host's active lanes. For a wave32 pixel or vertex program on a host running 64 lanes per wave (MaskData::Host), that reduced both console waves of the host wave together: each lane got the sum over 64 lanes, not over its own wave's 32. With masks split by halves, the operation now runs twice, each half's lanes giving the identity in the other run, and each lane takes its own half's result. A prefix sum works the same way: the other half adds the identity. Elsewhere one operation as before. The DXIL emission moves to lower/lanes.rs (wave_reduce), so lower.rs shrinks to 519,957 bytes. lane_mask_tests: a wave32 wave sum of (2^20 + key): the lane count read is at most a console wave, and the pixels reading one (count, sum) have keys adding up to it. draws takes the wave sizes to draw. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Added a third commit ( A whole-wave section (the compiler's expansion of a wave sum, min/max, bit operation or prefix sum) lowers to With masks split, the operation now runs twice, each half's lanes giving the identity in the other run, and each lane takes its own half's result (a prefix the same way). Elsewhere it is one operation as before. The DXIL emission moved to New test
The other two lane-mask tests are unchanged and pass. 5 of 5 runs, full suite 554 passed, clippy clean. So the PR now covers the three ways a wave32 program read the other console wave in a 64-lane host wave: lane-mask loops, AI-assisted (Claude). |
|
Merge note for whoever lands these: all five of my open PRs together (#3556
The only conflicts are module-order lines: the test modules in AI-assisted (Claude). |
A whole-wave section summing f16 halves (Shape::Half: the sum in the low
half, console lane `hi`'s high half on top) was refused outside compute
("a 16-bit wave reduction outside compute"), because the high half names
a console lane. With host lanes that lane is known too: lane `hi` of a
wave64 program, or of a wave32 program in its own half of a 64-lane host
wave (lane hi + 32 in the upper half). Mesh programs still refuse it.
The f16 sum goes through wave_reduce_halves, so each console wave sums
its own lanes there; console_lane gives the ballot dword and host lane
of a console lane. The general reductions use the same helper, and
lower.rs shrinks to 519,102 bytes.
lane_mask_tests: a wave32 pixel program sums 1.0 per lane in f16 with
each lane's key in the high half; the sum read is at most a console
wave's lane count and lane 31's key is a pixel among those reading it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Added a fourth commit ( A whole-wave section summing f16 halves ( The f16 sum goes through the same per-half split as the other reductions ( New test
Full suite 555 passed, clippy clean. AI-assisted (Claude). |
|
@kilolimaVI RDNA1 row for
The other two tests at
Full The same counts as the 780M, so the reduction fix covers RDNA1 as well as RDNA3. AI use: Claude Code (Claude Opus 5.5). |
On hosts that run pixel waves of 64 lanes (AMD: RDNA pixel shaders run wave64; measured on a Radeon 780M, RDNA3), a wave32 pixel or vertex program's 32-bit lane masks were the ballot's low dword in every lane. Lanes 32-63 tested the bits of lanes 0-31, so the console compiler's loop that serves one value per pass (
s_ff1of EXEC,v_readlaneat that lane,v_cmpx_eq) never served them: those pixels kept whatever they held before the loop.NVIDIA (32-lane pixel waves) and WARP never show it, which is likely why it went unnoticed.
Fix (
emit/lower.rs)With
MaskData::Hostand a wave32 program, a 64-lane host wave is treated as two console waves:mask_dword: each lane takes its own half's dword of the ballot (Lower::host_half,waveGetLaneIndex >= 32).v_readlaneat a computed (host) lane adds the half's base (Lower::host_lane).v_mbcntcounts within the half (lane & 31).On a 32-lane host the upper half never exists, so nothing changes there; wave64 programs and compute (
MaskData::Console) are untouched (wave64 DXIL is byte-identical).Test (
emit/lane_mask_tests.rs)wave32_lane_mask_loops_serve_every_lane_of_a_64_lane_host_wave: a hand-assembled pixel program runs that loop over a per-pixel key, drawn over a 16x16 target (no helper lanes), wave32 and wave64, on the hardware adapter and WARP. Pixels served a wrong key:0/5 failures over 5 runs.
cargo test -p victory-shaderon the 780M: 303 passed, 0 failed.cargo clippy -p victory-shader --all-targets [--all-features] -- -D warningsclean.cargo fmt --checkreports no new sites (main already has 33 inlower.rsand 2 inmod.rs).Related: helper lanes at triangle edges are a separate issue (#2373); this test draws a full-coverage triangle so it measures only the mask width.
AI-assisted (Claude).