Repository navigation
Description
A float wave prefix sum is lowered to wavePrefixOp kind 0 (WavePrefixSum). On an AMD Radeon driver the value a lane gets is wrong when that lane's own term is NaN, +infinity or 2^60 (the one large value tried).
Found with a synthetic test while testing #470: hand-written console programs, no game files. I have not seen it in a game and do not know whether any game shader takes a float wave prefix sum over such values. It does not come from #470: the float prefix sum already on main lowers the same way, and the same lanes are wrong on ffe310e.
Setup. One group of 32 threads, WaveSize(32), dxil.dll validation on. Each lane loads a float from a structured buffer, a whole-wave section scans it, and each lane stores its prefix to a raw UAV. Compared lane by lane with the section's instructions run on the CPU. The terms are small multiples of 0.25, so their sums are exact in any order; then a term is replaced (NaN in lanes 9 and 20, or in lane 0; the other two in lane 11).
| the lane's own term | exclusive prefix in that lane | inclusive prefix in that lane |
|---|---|---|
| NaN | NaN, want the sum of the lanes below (-3.75 in lane 9, 0 in lane 0) | NaN, as wanted |
| 2^60 | 0, want -17.75 | 2^60, as wanted |
| +infinity | NaN, want -17.75 | NaN, want +infinity |
Every other lane is as wanted, and the set with no such term is exact.
- Where: Radeon iGPU of a Ryzen 7 7700X, driver 32.0.21030.2001 (September 2025), waves of 32 to 64. One GPU and one driver version.
- Not there: an RTX 4080 (driver 621.14) is exact in every case, and the integer prefix sum is exact on both.
- Not the translator: plain HLSL
WavePrefixSumcompiled by DXC 1.8.2502.11 (Windows SDK 10.0.26100) gives the same wrong lanes and values on the Radeon (shader below). - Documentation: Microsoft defines the result as the sum over the active lanes with smaller indices, and says the lowest active lane always receives 0; with a NaN in lane 0 that lane reads NaN. The same page says the order of operations is not guaranteed. No order of the lanes below gives these values, but the 2^60 row is the one a vendor could call rounding.
- The three results fit a prefix made as the sum up to and including the lane, less the lane's own term. That reading is mine; the driver is closed.
- The exclusive prefix is the raw result of the op, so it is the exposed one. The inclusive one adds the term back, and of the cases tried only the infinite term shows there.
I have not tried a fix.
HLSL that shows it without the translator
#define RS "DescriptorTable(SRV(t0)), DescriptorTable(UAV(u0))"
StructuredBuffer<float> In : register(t0);
RWByteAddressBuffer Out : register(u0);
[RootSignature(RS)]
[WaveSize(32)]
[numthreads(32, 1, 1)]
void main()
{
uint lane = WaveGetLaneIndex();
float x = In[lane];
Out.Store(lane * 4, asuint(WavePrefixSum(x)));
}dxc -T cs_6_6 -E main, one group dispatched, In holding 32 floats. This is the exclusive form; WavePrefixSum(x) + x is the inclusive one.
Test: wave_prefix_tests.rs, from the readback posted on #470. It is not on main: added to ffe310e with its two lines in emit/mod.rs, the sum tests need no other change. On the Radeon an_exclusive_prefix_sum_of_f32_reads_back fails on the NaN, 2^60 and infinity sets and an_inclusive_prefix_sum_of_f32_reads_back on the infinity set; every set is exact on the RTX 4080.
Edit: the link now points at a commit that has the 2^60 and infinity sets (lane 11 set to 0x5D800000 and 0x7F800000). They were not pushed when this was opened.
AI-assisted (Claude Code), run on my own hardware.
Activity
pickles976 commentedon Nov 24, 2026
Divergence note from ivall/xcl, plus a possible structural exit: we do not emit
WavePrefixSumat all — our lowering has no dependency on the vendor prefix intrinsic, so this Radeon-driver defect cannot reach our users, and it suggests your fix need not be a lane-correction hack: a shift-and-add Hillis-Steele lowering (5 log-rounds ofWaveReadLaneAt(v, lane - step)guarded forlane >= step, IEEE-754 add) is bit-exact under the sequential order the ISA defines (v_peres-style prefix semantics) while touching no vendor fast path. Cost: 5 cross-lane reads vs one intrinsic — on the affected driver that is the difference between wrong and right; on healthy drivers a one-line capability switch keepsWavePrefixOp.\n\nTwo rows worth adding to your synthetic before this settles: ① integer prefix on the same driver — if the int path is correct, the defect is in the float fast path specifically and your capability table can be typed; ②WaveExclusivePrefixSumfloat on the same NaN/+inf/2^60 lanes — vendor fast paths for inclusive and exclusive variants are often different code, and if both are wrong the "replace the float path" conclusion generalizes immediately instead of needing a second bug report later. On 2^60 specifically: that looks like the driver specializing associativity-reordered sums past IEEE (any reassociation changes the exact result once saturation-like fast adds enter) — if so, plain large-but-normal pairs (2^60, 1.0, repeated) would reproduce without exotic values, which matters for judging whether a real title can hit it.Paull007 commentedon Nov 24, 2026
0001-Shaders-a-float-wave-prefix-sum-from-lane-reads-not-.patch
A possible fix (patch attached): float prefix sums are built from lane reads instead of
WavePrefixOp, so the driver's float prefix path is never used. Each lane points at the nearest active lane below it (from a ballot), and each round adds that lane's partial sum and takes its pointer, so inactive lanes are never read. Integer sums keepWavePrefixOp. The inclusive sum now comes straight from the scan, which also fixes the +infinity inclusive row.Checked: a CPU model of the emitted steps matches a sequential sum over random masks, wave sizes 32/64/128, and NaN/+inf/2^60 terms; a new lowering test goes through the new path; all shader tests pass. Not run on a GPU yet: could someone with the Radeon iGPU run
wave_prefix_tests.rswith this applied? It also touches the same match arm as PR 470.AI-assisted (Claude).
WALID1618Y commentedon Nov 24, 2026
Ran @Paull007's
0001-Shaders-a-float-wave-prefix-sum-from-lane-reads-not-.patchonmain(ffe310e) with @rouges78'swave_prefix_tests.rsplus the two extra edge-case sets from the issue (2^60=0x5D80_0000and+infinity=0x7F80_0000in lane 11).Environment: Windows 11, Rust
1.98.1,dxil.dllvalidation enabled (VICTORY_DXIL), NVIDIA GeForce RTX 3050 (Ampere, driver32.0.16.2124, waves of 32 to 32) + Microsoft WARP (10.0.26100.9818, waves of 4 to 4 — skipped forWaveSize(32)). Synthetic tests only; no game data.Checks:
git apply --check: clean onffe310ecargo clippy -p victory-shader --all-targets --locked -- -D warnings: cleana_float_wave_prefix_sum_lowers_without_wave_prefix_op: pass (dxil.dll: valid)32.0.16.2124)dxil.dllan_inclusive_prefix_sum_of_f32_reads_backfloatsNaN in lanes 9 and 20NaN in lane 02^60 in lane 11+inf in lane 11an_exclusive_prefix_sum_of_f32_reads_backfloatsNaN in lanes 9 and 20NaN in lane 02^60 in lane 11+inf in lane 11an_inclusive_prefix_sum_of_u32_reads_back0x80000000&0an_exclusive_prefix_sum_of_u32_reads_back0x80000000&0This confirms the lane-read pointer-jumping lowering validates cleanly with
dxil.dlland executes bit-exactly on NVIDIA Ampere (still needs a Radeon iGPU run to verify the AMD driver defect itself is cleared).AI-assisted; all builds, DXIL validations, and GPU dispatches were executed locally on my RTX 3050.
shader: lower float wave prefix sums via lane reads
tumbubu commentedon Nov 24, 2026
Reproduced on a discrete RDNA3 card with a newer driver, in Wave64 and pixel shaders too; #1408 fixes it there.
#1458's AMD run used RADV, where #1172 does not occur. This run uses AMD's Windows driver.
dxil.dllfrom Windows SDK 10.0.26100: the modules were validatedmain(ffe310e) with only #1408'swave_prefix_tests.rsadded (and its two lines inemit/mod.rs; no lowering change):mainwave_prefix_sum_f32_exclusive_wave32nan_lanes_9_20, lane 9: NaN, want -3.75wave_prefix_sum_f32_inclusive_wave32pos_inf_lane_11, lane 11: NaN, want +infwave_prefix_sum_f32_wave64nan_lanes_9_20, lane 9: NaN, want -3.75wave_prefix_sum_f32_pixel_quad_all_backendsnan_lane_0, lane 0: NaN, want 0wave_prefix_sum_u32_reads_backThese are the same wrong values as in #1172's table. Each test stops at its first wrong lane, so later cases in the same test are not listed. Compared with #1172:
WaveSize(32)compute: Wave64 compute and the pixel-shader form fail the same way.#1408 head
a69e324,cargo test -p victory-shader --locked -- --test-threads=1: 125 passed, 0 failed, 1 ignored. That ismain's 120 plus the 5 above, all passing on the 7900 XT. No test that passes onmainfails.shader: lower float wave prefix sums via lane reads
Marvisak commentedon Nov 25, 2026
Automated triage for the maintainers.
Confirmed by reading
main(940d32f):shapeincrates/victory-shader/src/emit/lower.rslowers a float wave prefix sum towavePrefixOp.f32and builds the inclusive form by adding the lane's own term back. So the AMD Windows driver's results reach translated shaders unchanged. The reports here show the wrong lanes on two AMD Windows drivers (a Radeon iGPU and an RX 7900 XT, also in Wave64 and pixel shaders), and exact results on NVIDIA and on RADV (#1458). The integer path is exact.The fix is open as PR #1408 (float prefix sums built from lane reads; integer sums keep
wavePrefixOp). It passed on the RX 7900 XT, so review and further runs go there. Nobody has seen this in the title yet.Generated by Claude Code
JAEdotUK commentedon Nov 26, 2026
Reproduces on RDNA4. RX 9070 XT, driver 32.0.32015.7029, Windows 11 (10.0.26200.9974), waves 32..=64. main's float wavePrefixOp path (the parent of #1408 with #1408's tests) fails in the same lanes as the table above: exclusive NaN lanes 9 and 20 give NaN in lane 9 where -3.75 is wanted (Wave32 and Wave64), inclusive +inf in lane 11 gives NaN, and the pixel-shader exclusive case with NaN in lane 0 gives NaN where 0 is wanted. The u32 test passes. Each test stops at its first wrong lane, so later sets (such as 2^60) are not listed. With #1408 at 3a4ee54 all five tests pass on the same GPU. Details are in my report on #1408.
AI use: prepared with Claude (Claude Sonnet 5.5); the test run was done by me on my own machine.