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

Closed
github-bot wants to merge 647 commits from github-bot/gh-61 into main AGit
Owner

@⁠guialmm on GitHub · 2026-11-26 17:06 UTC · original
guialmm:fix/readfirstlane-wide-hardware-wave → main · +12 −5 · 1 files · 1 commits · closed without merging

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:

  • dotnet build FiveStar.slnx: no warnings.
  • FIVESTAR_TEST_ADAPTER=hardware, WaveEmulationTests, same build with and without the change: 2 failed, 14 passed before; 16 passed after.
  • FIVESTAR_TEST_ADAPTER=hardware, whole shader project (without the three cases that hang NVIDIA in #9): 30 failures before, 28 after. The 28 left are the other open items from #9 (buffer-bounds E_OUTOFMEMORY, root-descriptor fallback, integer gathers, StageProbe); none is new.
  • WARP: dotnet test FiveStar.slnx, 0 failed (shaders: 550 passed, 14 skipped, as on main).

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** on GitHub · 2026-11-26 17:06 UTC · [original](https://github.com/ThatRecompDev/five-star-recomp/pull/61) `guialmm:fix/readfirstlane-wide-hardware-wave` → `main` · +12 −5 · 1 files · 1 commits · closed without merging 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: - `dotnet build FiveStar.slnx`: no warnings. - `FIVESTAR_TEST_ADAPTER=hardware`, `WaveEmulationTests`, same build with and without the change: 2 failed, 14 passed before; 16 passed after. - `FIVESTAR_TEST_ADAPTER=hardware`, whole shader project (without the three cases that hang NVIDIA in #9): 30 failures before, 28 after. The 28 left are the other open items from #9 (buffer-bounds E_OUTOFMEMORY, root-descriptor fallback, integer gathers, StageProbe); none is new. - WARP: `dotnet test FiveStar.slnx`, 0 failed (shaders: 550 passed, 14 skipped, as on main). 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](https://claude.com/claude-code)
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 #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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 03:16:21 +00:00
Author
Owner

@⁠ThatRecompDev on GitHub · 2026-11-26 21:32 UTC · original

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

**@⁠ThatRecompDev** on GitHub · 2026-11-26 21:32 UTC · [original](https://github.com/ThatRecompDev/five-star-recomp/pull/61#issuecomment-7203820172) 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
github-bot closed this pull request 2026-11-27 08:06:17 +00:00
Author
Owner

@⁠ThatRecompDev on GitHub · 2026-11-27 08:01 UTC · original

this one is in main too, as 496df042 with you as author (the batch was built on your commit before you rebased, so github doesn't see the PR as merged, closing it by hand). it went in with 976cc3e3 together with #62, #66 and #67. heads-up for everyone: translation output changed with this batch, so the next run translates and compiles the shaders again. thanks for the fix!

**@⁠ThatRecompDev** on GitHub · 2026-11-27 08:01 UTC · [original](https://github.com/ThatRecompDev/five-star-recomp/pull/61#issuecomment-7213056642) this one is in main too, as 496df042 with you as author (the batch was built on your commit before you rebased, so github doesn't see the PR as merged, closing it by hand). it went in with 976cc3e3 together with #62, #66 and #67. heads-up for everyone: translation output changed with this batch, so the next run translates and compiles the shaders again. thanks for the fix!

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.