Shaders: readfirstlane reads the first active lane with WaveReadLaneFirst #21

Manually merged
github merged 1 commit from gh-pr/21/head into gh-pr/21/base 2026-11-27 03:14:08 +00:00
Owner

@⁠Sr-0w on GitHub · 2026-11-25 05:36 UTC · original
Sr-0w:shaders/readfirstlane-amd → main · +17 −1 · 2 files · 1 commits · merged 2026-11-25 08:06 UTC

What changed

The prelude's readfirstlane (no wave emulation, no group wave) reads the first active lane with WaveReadLaneFirst instead of vw_read(x, firstbitlow(ballot)), i.e. WaveReadLaneAt with a lane computed from a ballot. With EXEC empty it still reads lane 0, as before. Emulated and group-wave programs keep the old path.

Why

On an RX 7800 XT (Adrenalin 32.0.32029.2010), the old pattern made the driver's shader compiler (amdxc64) crash in a story-load pixel program. I bisected the translated HLSL down to that one pattern:

  • without readfirstlane the program compiles and runs;
  • with only vw_any removed it still crashes;
  • the WaveReadLaneFirst form runs.

The result is the same: the first lane whose EXEC bit is set.

How I checked

  • dotnet test tests/FiveStar.Shaders.Tests: 320 passed, 12 skipped (the GPU cases cover v_readfirstlane_b32 with partial EXEC).
  • In game: the story load got past that program, where it had crashed in amdxc64 before.
  • docs/shader-translation.md notes the AMD form next to readfirstlane.

🤖 Generated with Claude Code

**@⁠Sr-0w** on GitHub · 2026-11-25 05:36 UTC · [original](https://github.com/ThatRecompDev/five-star-recomp/pull/21) `Sr-0w:shaders/readfirstlane-amd` → `main` · +17 −1 · 2 files · 1 commits · merged 2026-11-25 08:06 UTC ## What changed The prelude's `readfirstlane` (no wave emulation, no group wave) reads the first active lane with `WaveReadLaneFirst` instead of `vw_read(x, firstbitlow(ballot))`, i.e. `WaveReadLaneAt` with a lane computed from a ballot. With EXEC empty it still reads lane 0, as before. Emulated and group-wave programs keep the old path. ## Why On an RX 7800 XT (Adrenalin 32.0.32029.2010), the old pattern made the driver's shader compiler (amdxc64) crash in a story-load pixel program. I bisected the translated HLSL down to that one pattern: - without `readfirstlane` the program compiles and runs; - with only `vw_any` removed it still crashes; - the `WaveReadLaneFirst` form runs. The result is the same: the first lane whose EXEC bit is set. ## How I checked - `dotnet test tests/FiveStar.Shaders.Tests`: 320 passed, 12 skipped (the GPU cases cover `v_readfirstlane_b32` with partial EXEC). - In game: the story load got past that program, where it had crashed in amdxc64 before. - `docs/shader-translation.md` notes the AMD form next to `readfirstlane`. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
When the hardware wave holds no more than the program wave, readfirstlane now reads x under if (active) with WaveReadLaneFirst and spreads it with WaveActiveMax, instead of WaveReadLaneAt at the ballot's lowest bit. The old form crashed AMD's compiler (RX 7800 XT, driver 32.0.32029.2010) inside CreatePipelineState on the decoration-baking mesh pipeline's pixel program, which reads the first lane seven times in a loop; the crash took the process at the eighth present of the story load. The group forms and a wider hardware wave keep the ballot form.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SKtJsfjasPuTLtS3mEXFru
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 03:14:06 +00:00
github manually merged commit bae37fa6d0 into gh-pr/21/base 2026-11-27 03:14:08 +00:00
Author
Owner

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

merged, thanks! checked it against the old ballot path and it picks the same lane in every case since both only see active lanes

**@⁠ThatRecompDev** on GitHub · 2026-11-25 08:08 UTC · [original](https://github.com/ThatRecompDev/five-star-recomp/pull/21#issuecomment-7156650208) merged, thanks! checked it against the old ballot path and it picks the same lane in every case since both only see active lanes
This discussion has been locked. Commenting is limited to contributors.
No description provided.