Shaders: a wave64 program without lane reads loses UAV order across its 32-lane halves on AMD (main) #3766
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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 ColorMeBoom on 2026-11-28T17:22:22Z.
On
main, a console wave64 compute program whose lanes never read each other gets noWaveSizein DXIL (lower.rsL601-605 declares one only with console lanes, or for a one-wave group with LDS). The driver is then free to run it as 32-lane waves, and the AMD driver here does. When one lane writes a UAV dword and a lane in the other 32-lane half reads it later in program order, the reader gets the old value every time. On the console both lanes are in one wave and the read sees the write.Measured on
main63bcca4, RX 5700 XT (Navi 10, RDNA1, 32 and 64 lanes, driver 32.0.21045.29003), Windows 11 26200, hardware adapter. Setup:wof each console wave loads a dword only it touches, adds 1 and stores it to its wave's slot;rthen loads that slot.w5 →r6 (same half)w5 →r40w40 →r5WaveSize)row_mirrorat the top (WaveSize(64))v_readlane_b32 s9, v0, 40at the top (WaveSize(64))The store lands in every slot in every row, so a stale read means the load ran early, not that the store was lost. The same program declared
WaveSize(64)keeps the console's order on this card. So the gap comes from leaving the wave size to the driver for a program whose UAV accesses cross the 32-lane halves.Related:
neonbyte1:suggest/uav-order-all-formsalso covers this per-lane form there, but its tests skip 64-lane hardware.WaveSize(64)for programs with a cross-lane UAV conflict would be enough. A 32-lane host still needs the fence.Reproduce:
ColorMeBoom:probe/main-uav-order(d867ae7, one ignored test onmain), then:PROBE_RUNSsets the dispatch count. The same probe on #2633 is in this comment.AI use: Claude Code (Claude Opus 5.5).
Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-28T17:56:48Z.
RDNA3 hardware check for #3766. I could not reproduce the stale reads on an AMD Radeon RX 7800 XT (Navi 32). The D3D12 test device identified that adapter and reported wave sizes 32–64. Driver
32.0.31035.1003, Windows 11 Pro 25H2 build26200.9974, Ryzen 7 5700X3D, Cargo test profile, hardware D3D12.63bcca43c6a00a758510398fa43096ce7e4f7df0with ColorMeBoom’s probed867ae75db59a7edcce19e4f83673c40d49bc7af.suggest/uav-order-all-formsat0c0e85ef67c81a651b941ccc893efc7544953e2a, with the same probe cherry-picked without conflicts and adapted to call the fork’s emitter with the actual D3D12 target. Local probe diagnostics logged the adapter and declared wave size in both arms.Stale reads / checked reads for the no-lane-read program, aggregated over three runs per arm, 256 single-group dispatches per case per run.
Both
WaveSize(64)controls also had zero stale reads in every row, with the same denominators per control. Every store landed and there were zero other mismatches. The no-lane-read DXIL had noWaveSizein either arm. These readbacks leave the actual driver-selected width undetermined. I reran one B repetition after another test process appeared at its end and excluded the original.The fork’s three UAV-order tests (console flow, per-lane, split) normally skip when
Host::target()reports wave64 viaD3D12_OPTIONS1. I relaxed that test-only skip and ran all three with the real target, then added a localVICTORY_1128I_FORCE_WAVE32=1switch that passesTarget { lanes_min: 32, lanes_max: 32 }only to the emitter. All three passed in both modes, with 0/688,128 stale reads per mode over 18 cases. The forced mode emittedWaveSize(32)and a barrier in all 18 cases. The native mode emitted no fork UAV barriers, so the native A/B shows order held in both arms and gives no evidence of a benefit from the fix on the native wave64-capable target. The forced run shows the fork’s wave32 fence path preserved order on this hardware.AI-assisted (Codex gpt-6.2-sol)
Imported from Marvisak/VIctory. Originally posted by ColorMeBoom on 2026-11-28T18:14:13Z.
@oni-swr Thanks for the RDNA3 run. Your "driver-selected width undetermined" point is the missing piece, so I measured the width on the RDNA1 card. It's 32 here. That may be the whole difference from your 7800 XT.
How: I wrote an HLSL twin of the translated no-lane-read program, with the same heap UAV through root constant
b0and the same per-thread code. It adds one store at the end:WaveGetLaneCount(). I built it with the Windows SDK's dxc (cs_6_6, noWaveSizeattribute) and ran it with the translated shader's root signature on the RX 5700 XT (driver 32.0.21045.29003).Result: every thread of every row saw a lane count of 32: 64, 256 and 1024 threads, each
w/rpair, 256 dispatches each. So on this driver a wave64 program withoutWaveSizeruns as two 32-lane waves per console wave. That fits the earlier table: all stale across the halves, 0 in the same half, and 0 onceWaveSize(64)is declared.Could you run that variant on the 7800 XT? If RDNA3's driver picks 64 lanes for these programs, the two results agree and #3766 is a driver-choice issue: it hits hosts whose driver picks 32. To run it:
probe/main-uav-orderat9c68ace;.dxilfiles fromcrates/victory-shader/src/emit/uav_halves_probe.hlslwith the dxc line at its end;PROBE_HLSL_DIRto their folder and run the samecargo testline.The
RESULT hlslrows print how many threads saw 32 and how many saw 64.One caveat:
ifs on exclusive lane tests, so the compiler is free to move the reader's load above the other lane's store.WaveSize(64)alone keeps relying on that. A fence, as in neonbyte1's branch, doesn't.AI use: Claude Code (Claude Opus 5.5).
Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-28T18:45:42Z.
@ColorMeBoom I ran the probe at
9c68ace543f9f954cd0b2a902435dfa5d0168fedon an RX 7800 XT (Navi 32), driver32.0.31035.1003, Windows 11 25H2 build26200.9974. One run, 256 dispatches per row. The counts below apply separately to each of the three lane pairs (5 → 6, 5 → 40, 40 → 5).The three translated variants had 0/48,384 stale reads combined. Every store landed, with zero other mismatches across all rows. The 64-lane HLSL result here and your 32-lane result on the RX 5700 XT agree with the driver-choice explanation. The translated rows did not measure their actual wave width.
AI use: Codex (gpt-6.2-sol) ran the probe and wrote this comment.
Imported from Marvisak/VIctory. Originally posted by ColorMeBoom on 2026-11-28T19:14:59Z.
@oni-swr Thanks, that settles it. Summary for whoever picks this up:
WaveSize(HLSL twin)WaveSizeas 32-lane waves. That includes RDNA1 on this driver, and probably every 32-lane-only host (NVIDIA, where neonbyte1 measured the same pattern). RDNA3 picks 64 here and hides it. Neither of us measured the translated programs' own width, only the HLSL twin's, so "the same choice applies to the translated code" is an inference. It's consistent with every row so far, though.WaveSize(64)alone would keep relying on that layout. A fence between conflicting accesses, as in neonbyte1's branch, doesn't depend on it.AI use: Claude Code (Claude Opus 5.5).
Imported from Marvisak/VIctory. Originally posted by omarsaifuddin on 2026-11-30T06:34:43Z.
An Emulate-form data point on an RTX 3070 Ti (Windows 11, driver 32.0.16.2140,
wave 32..=32), using ColorMeBoom's probe ported to #189'sWave64Mode::Emulate(probe in #3874).Method: lane
writerof each console wave stores 1 + a dword only it loaded to its wave's slot; lanereaderthen loads the slot. One group per dispatch, 64 dispatches per row. Stale reads per reads, writer in the high half, reader in the low half:v_readlaneunwritten 0), so this is read reordering, not a lost store.v_readlanevariants declareWaveSize(64)on main and never build on this card; under Emulate they now translate and run, and are just as stale. The group-shared barrier they force isbarrier(1 | 8), which fences LDS, not device memory, so it does not help.Scope: one card, one program shape, and the write/read lanes are deliberately in different halves. The probe in #3874 is ignored and can be rerun against a fix; a fix needs to cover the Emulate form too.