Skip to content

Shaders: readfirstlane takes each program wave's lane on hardware waves holding more than four - #61

Open
guialmm wants to merge 1 commit into
ThatRecompDev:mainfrom
guialmm:fix/readfirstlane-wide-hardware-wave
Open

guialmm wants to merge 1 commit into
ThatRecompDev:mainfrom
guialmm:fix/readfirstlane-wide-hardware-wave

Conversation

@guialmm

@guialmm guialmm commented Nov 26, 2026

Copy link
Copy Markdown

On a real GPU, WaveEmulationTests.Wave_operations_see_the_console_wave fails for wave: 2 and wave: 4 with groupLanes: False: only the last column (readfirstlane(x, c)) is wrong, and every thread from the fourth program wave on reads the same value. This is the "WaveEmulation wave 2 and 4 with groupLanes False, last column wrong" item from the RTX 3070 run in #9.

Why. On a hardware wave wider than the program wave, readfirstlane in rdna_prelude.hlsli takes one WaveActiveMax over a uint4, one component per program wave, and the comment there assumes at most four program waves (128 lanes, or WARP's 4 lanes for test waves). A 32-lane NVIDIA wave holds 16 two-lane or 8 four-lane test waves, so waves 3 and up all land in .w and read the max over all of them. With two-lane waves that is thread 6's value (6·7+3 = 45), with four-lane waves thread 12's (87), which is what the test prints.

Change. The same max, four program waves per WaveActiveMax, repeated until it covers WaveGetLaneCount() / VW_WAVE waves. The loop is unrolled with a constant bound (128 / VW_WAVE) and each step is behind a wave-uniform test, so for console waves (32 or 64 lanes) only the first step runs, as one max like before. Only this function changes.

Checked on an RTX 3060 (12 GB, driver 32.0.16.1714), Windows 11:

AI-assisted (Claude Code, Claude Opus 5.5): found the cause, wrote the change and ran the tests above on my machine.

🤖 Generated with Claude Code

@guialmm
guialmm force-pushed the fix/readfirstlane-wide-hardware-wave branch from 496df04 to 8c6dd3b Compare November 26, 2026 17:44
…es holding more than four

On a hardware wave wider than the program wave, readfirstlane took one
WaveActiveMax over a uint4, one component per program wave, which covers
at most four program waves. A 32-lane NVIDIA wave holds 16 two-lane or 8
four-lane test waves, so every wave past the fourth read the same value
(WaveEmulationTests, wave 2 and 4 without group lanes, from ThatRecompDev#9). The same
max now repeats four program waves at a time up to WaveGetLaneCount() /
VW_WAVE; console waves (32 or 64 lanes) still take a single max.
@guialmm
guialmm force-pushed the fix/readfirstlane-wide-hardware-wave branch from 8c6dd3b to 598e8cb Compare November 26, 2026 18:05
@ThatRecompDev

Copy link
Copy Markdown
Owner

nice catch on the uint4 only covering four program waves, the fix reads clean. ran it here on WARP together with our next translator changes and the whole shader suite passes (583, 0 failed). since it changes translation output we'll land it together with that batch so testers only re-translate once, should be soon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants