Shaders: DPP and ds_swizzle_b32 read nothing from source lanes outside EXEC (port of upstream b51011a) #232
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/232"
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 DexNom/VIctory. Originally posted by murillojndem on 2026-11-29T21:55:37Z.
On RDNA2 a cross-lane read from a source lane outside EXEC is invalid unless FI (fetch inactive) is set. DPP16 then gives 0 with bound_ctrl and otherwise leaves the destination lane unwritten. DPP8 gives 0, and so does
ds_swizzle_b32. The lowering here read the source lane's register whatever its EXEC bit:dpp()ignored FI, and both read withWaveReadLaneAt, whose result for a lane the host does not run there is undefined in DXIL. On an RX 7900 XT, an active lane reading an inactive neighbour got the neighbour's old value.This ports upstream Marvisak/VIctory b51011a (#1582, Capt-Speed). Its tests reproduce the bug here. On main, on the RX 7900 XT, 12 of 18 DPP16 cases fail: for example
row_shr:1with bound_ctrl under a 0x55555555 guard, where lane 2 got 0x10010004 and RDNA2 gives 0x00010002. The DPP8/DPP8FI andds_swizzle_b32tests fail too. With this change all pass.Change (
emit/lower.rs):src_lane_activesays whether a source lane runs the instruction under the console's EXEC.lane_bit_of. Lanes a branch took elsewhere are not in a host ballot either.dpp(): a source outside the row, or inactive without FI, is invalid. DPP8 then gives 0 (it gave the value). DPP16 gives 0 with bound_ctrl and otherwise does not write, as it already did for a source outside the row. An invalid source is not read withWaveReadLaneAt; the lane reads its own register instead, and the result is not used.ds_swizzle_b32: an inactive source gives 0, and is likewise not read.quad_picktakes the quad pattern, and the guard is read with the same pattern;use_quadincludes mesh shaders, whoselane_indexis the console's lane; andlane_bitonly gives a lane's own bit, solane_bit_ofis new.Tests:
emit::crosslane_testsis upstream's file. It holds DPP16 in 18 cases (straight-line guards, branches, and both nested), DPP8 and DPP8FI,ds_swizzle_b32, pixel quad forms validated and made into pipelines, and a CPU model of the RDNA2 rules. Only the harness'sPartsandHostShaderfields are adapted to this repository, andlib.rslists the file among the sources outside the translation. The GPU cases run on the hardware adapter (they declareWaveSize(32)).victory-shader --libon the RX 7900 XT and WARP with one test thread: 242 passed, 2 failed, 4 ignored (main: 237, 2, 4). The 2 failures (emit::rect::tests::rectangles_are_drawn_wholeandthe_rectangle_stage_is_a_geometry_shader) fail on main too.-D warnings, with and without--all-features, andcargo xtask policypass. rustfmt reports 269 differences in victory-shader on main and 272 here.Cost: outside pixel shaders, each DPP or
ds_swizzle_b32now makes a ballot even under a full EXEC: onewaveActiveBallot, one morewaveGetLaneIndexin mesh shaders, and about 8 ALU operations. DPP16 without bound_ctrl is now always a guarded write. Pixel shaders without a guard are lowered as before.Limits:
dpp()is left for a change of its own. When console wave64 code runs on 32-lane host waves, the DPP16 row mask is indexed by the host lane, so console rows 2 and 3 test mask bits 0 and 1. An independent review found it. It needs hosts whose waves have at most 32 lanes, which the RX 7900 XT's do not.Generated with Claude Code
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.