Shaders: a helper lane's v_readfirstlane reads its own value (#908) #1732

Merged
moe-miau merged 1 commit from upstream-pr/1733 into main 2026-11-25 00:23:50 +00:00
moe-miau commented 2026-11-24 21:31:00 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by moe-miau on 2026-11-24T21:31:00Z.


Fixes #908.

This is Vaximous's fix from the issue (branch fix/helper-lane-readfirstlane, 9d5ce7a), cherry-picked unchanged onto main with the original author kept on the commit. It was posted as a fork branch while PRs were limited to collaborators. The only PR that carried it (#1039) was closed without being merged, so nothing open fixes #908 now.

Problem. On the console, whole-quad mode keeps a pixel shader's helper lanes in EXEC, so a v_readfirstlane_b32 waterfall loop serves them too. On the host, wave ops skip helper lanes (no WaveOpsIncludeHelperLanes). Once only helper lanes are left in such a loop, WaveReadLaneFirst matches nothing and each of them spins to LOOP_LIMIT. #908 measured draws of 0.3 to 1.3 s each, then DXGI_ERROR_DEVICE_HUNG about 200 s into the world.

Fix (crates/victory-shader/src/emit/lower.rs, +25): in a pixel shader, v_readfirstlane_b32 returns select(IsHelperLane(), own, WaveReadLaneFirst(own)). A helper lane matches on the first pass and leaves the loop. A helper lane's results only feed derivatives and its stores are already dropped. Other stages are unchanged. IsHelperLane is DXIL op 221 (shader model 6.6, which the host already requires).

Checked on Windows 11 x64, Rust 1.98.1 MSVC, main ffe310e + this commit:

  • cargo clippy --workspace --all-targets --locked -- -D warnings and the --all-features variant: clean
  • cargo test --workspace --locked: pass (victory-shader: 120 passed, including the GPU valu_tests on an RTX 4070 SUPER)
  • cargo xtask policy: ok

From #908: the DXIL validator accepts the translated pixel shader, and a covered-pixel readback on an RTX 4090 returns the lane's own value. The runtime effect was measured by the author on an integration build (RTX 4070 Ti), not on plain main.

There is no synthetic pixel-stage test here. The existing lowering tests in lower.rs only build compute programs. A test that asserts isHelperLane is emitted for a pixel v_readfirstlane_b32 would need a pixel-stage harness; I can add one if you want it in this PR.

AI-assisted (Claude Code): I reviewed the diff and reran the checks. The fix itself is Vaximous's (commit author Vax).

🤖 Generated with Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:issue:6591814630 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1733). Originally posted by [moe-miau](https://github.com/moe-miau) on 2026-11-24T21:31:00Z. --- Fixes #908. This is Vaximous's fix from the issue (branch `fix/helper-lane-readfirstlane`, `9d5ce7a`), cherry-picked unchanged onto `main` with the original author kept on the commit. It was posted as a fork branch while PRs were limited to collaborators. The only PR that carried it (#1039) was closed without being merged, so nothing open fixes #908 now. **Problem.** On the console, whole-quad mode keeps a pixel shader's helper lanes in EXEC, so a `v_readfirstlane_b32` waterfall loop serves them too. On the host, wave ops skip helper lanes (no `WaveOpsIncludeHelperLanes`). Once only helper lanes are left in such a loop, `WaveReadLaneFirst` matches nothing and each of them spins to `LOOP_LIMIT`. #908 measured draws of 0.3 to 1.3 s each, then `DXGI_ERROR_DEVICE_HUNG` about 200 s into the world. **Fix** (`crates/victory-shader/src/emit/lower.rs`, +25): in a pixel shader, `v_readfirstlane_b32` returns `select(IsHelperLane(), own, WaveReadLaneFirst(own))`. A helper lane matches on the first pass and leaves the loop. A helper lane's results only feed derivatives and its stores are already dropped. Other stages are unchanged. `IsHelperLane` is DXIL op 221 (shader model 6.6, which the host already requires). Checked on Windows 11 x64, Rust 1.98.1 MSVC, `main` `ffe310e` + this commit: - `cargo clippy --workspace --all-targets --locked -- -D warnings` and the `--all-features` variant: clean - `cargo test --workspace --locked`: pass (`victory-shader`: 120 passed, including the GPU `valu_tests` on an RTX 4070 SUPER) - `cargo xtask policy`: ok From #908: the DXIL validator accepts the translated pixel shader, and a covered-pixel readback on an RTX 4090 returns the lane's own value. The runtime effect was measured by the author on an integration build (RTX 4070 Ti), not on plain `main`. There is no synthetic pixel-stage test here. The existing lowering tests in `lower.rs` only build compute programs. A test that asserts `isHelperLane` is emitted for a pixel `v_readfirstlane_b32` would need a pixel-stage harness; I can add one if you want it in this PR. AI-assisted (Claude Code): I reviewed the diff and reran the checks. The fix itself is Vaximous's (commit author Vax). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
catminou4 commented 2026-11-24 22:02:10 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T21:41:04Z.

Review: APPROVED


Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (ffe310e), cargo test -p victory-shader --locked → 96 passed, 0 failed. Windows-gated execution/hardware tests only run on Windows.

helper_reads_own: in pixel shaders a helper lane's v_readfirstlane now reads its own value instead of the first lane's — on the host WaveReadLaneFirst excludes helper lanes (no WaveOpsIncludeHelperLanes), so a waterfall loop left with only helper lanes never matched, ran to LOOP_LIMIT per lane (0.3-1.3 s draws) and ended in DEVICE_HUNG. The select(isHelperLane, own, first) is minimal and pixel-only; what helper lanes compute only feeds derivatives and their stores are dropped. No new test, but the mechanism is precisely documented and the existing waterfall harness exercises the path on Windows.

<!-- greyfinch-sync:Marvisak/VIctory:review:6047860749 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1733#pullrequestreview-6047860749). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T21:41:04Z. **Review:** APPROVED --- Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (ffe310e), cargo test -p victory-shader --locked → 96 passed, 0 failed. Windows-gated execution/hardware tests only run on Windows. helper_reads_own: in pixel shaders a helper lane's v_readfirstlane now reads its own value instead of the first lane's — on the host WaveReadLaneFirst excludes helper lanes (no WaveOpsIncludeHelperLanes), so a waterfall loop left with only helper lanes never matched, ran to LOOP_LIMIT per lane (0.3-1.3 s draws) and ended in DEVICE_HUNG. The select(isHelperLane, own, first) is minimal and pixel-only; what helper lanes compute only feeds derivatives and their stores are dropped. No new test, but the mechanism is precisely documented and the existing waterfall harness exercises the path on Windows.
upstream-sync closed this pull request 2026-11-25 01:07:07 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
Marvisak/VIctory!1732
No description provided.