Shaders: a helper lane spins to the loop limit in a pixel shader's readfirstlane loop (DEVICE_HUNG); fix on a fork #908

Closed
opened 2026-11-24 13:55:13 +00:00 by Vaximous · 2 comments
Vaximous commented 2026-11-24 13:55:13 +00:00 (Migrated from github.com)
Contributor

Imported from Marvisak/VIctory. Originally posted by Vaximous on 2026-11-24T13:55:13Z.


Problem

A pixel shader can hang the GPU (DXGI_ERROR_DEVICE_HUNG) through a v_readfirstlane_b32 loop. In the world, draws took 0.3-1.3 s each and submissions about 1.16 s, frame after frame. About 200 s into the world, one submission passed the host's 2 s limit and the device was removed.

Cause: on the console, whole-quad mode keeps a pixel shader's helper lanes in EXEC. A waterfall loop (read the first lane's value, run the lanes that have it, drop them from EXEC) therefore serves the helper lanes as well. On the host, wave ops skip helper lanes (DXIL without WaveOpsIncludeHelperLanes). Once only helper lanes are left in the loop, WaveReadLaneFirst reads no lane and nothing matches. Each of those lanes then spins to LOOP_LIMIT (2^20).

On main, the loads that the waterfall proof from ffe310e / #307 accepts already read the lane's own value, so they are safe. Every other v_readfirstlane_b32 in a pixel shader still goes through waveReadLaneFirst and can hit this.

Fix

In a pixel shader, a helper lane's v_readfirstlane_b32 now returns the lane's own value: select(isHelperLane(), own, waveReadLaneFirst(own)). The 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.

One file, crates/victory-shader/src/emit/lower.rs, +25 lines.

Branch

https://github.com/Vaximous/VIctory/compare/main...fix/helper-lane-readfirstlane — commit 9d5ce7a, based on ffe310e.

Tested

  • cargo test -p victory-shader: 120 passed, 0 failed, 1 ignored. cargo clippy -p victory-shader --all-targets -- -D warnings is clean.
  • Runtime (RTX 4070 Ti, Windows 11): measured on our local integration build (main plus a set of open PRs), not on plain main. That build lowers waterfall loops in its own way (console-flow lane reads), and the same one-line select went on top of it. Before the change: DEVICE_HUNG about 200 s into the world. After it: three world runs of about 6 minutes each with no device removal.

#307 (waterfall lowering; earlier comment: https://github.com/Marvisak/VIctory/pull/307#issuecomment-7128461640), ffe310e. Possibly some of the world DEVICE_HUNG reports, e.g. #619 and #625 (not verified on those machines).

AI use

Written with Claude Code (Claude Opus 5.5); tested locally.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6583384025 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/issues/908). Originally posted by [Vaximous](https://github.com/Vaximous) on 2026-11-24T13:55:13Z. --- ## Problem A pixel shader can hang the GPU (DXGI_ERROR_DEVICE_HUNG) through a `v_readfirstlane_b32` loop. In the world, draws took 0.3-1.3 s each and submissions about 1.16 s, frame after frame. About 200 s into the world, one submission passed the host's 2 s limit and the device was removed. Cause: on the console, whole-quad mode keeps a pixel shader's helper lanes in EXEC. A waterfall loop (read the first lane's value, run the lanes that have it, drop them from EXEC) therefore serves the helper lanes as well. On the host, wave ops skip helper lanes (DXIL without `WaveOpsIncludeHelperLanes`). Once only helper lanes are left in the loop, `WaveReadLaneFirst` reads no lane and nothing matches. Each of those lanes then spins to `LOOP_LIMIT` (2^20). On main, the loads that the waterfall proof from ffe310e / #307 accepts already read the lane's own value, so they are safe. Every other `v_readfirstlane_b32` in a pixel shader still goes through `waveReadLaneFirst` and can hit this. ## Fix In a pixel shader, a helper lane's `v_readfirstlane_b32` now returns the lane's own value: `select(isHelperLane(), own, waveReadLaneFirst(own))`. The 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. One file, `crates/victory-shader/src/emit/lower.rs`, +25 lines. ## Branch https://github.com/Vaximous/VIctory/compare/main...fix/helper-lane-readfirstlane — commit 9d5ce7a, based on ffe310e. ## Tested - `cargo test -p victory-shader`: 120 passed, 0 failed, 1 ignored. `cargo clippy -p victory-shader --all-targets -- -D warnings` is clean. - Runtime (RTX 4070 Ti, Windows 11): measured on our local integration build (main plus a set of open PRs), not on plain main. That build lowers waterfall loops in its own way (console-flow lane reads), and the same one-line select went on top of it. Before the change: DEVICE_HUNG about 200 s into the world. After it: three world runs of about 6 minutes each with no device removal. ## Related #307 (waterfall lowering; earlier comment: https://github.com/Marvisak/VIctory/pull/307#issuecomment-7128461640), ffe310e. Possibly some of the world DEVICE_HUNG reports, e.g. #619 and #625 (not verified on those machines). ## AI use Written with Claude Code (Claude Opus 5.5); tested locally.
LAKSHYA-cmd-tech commented 2026-11-24 14:04:58 +00:00 (Migrated from github.com)
Author
Contributor

Imported from Marvisak/VIctory. Originally posted by LAKSHYA-cmd-tech on 2026-11-24T14:01:31Z.


Verified and merged downstream in PR #29. select(isHelperLane(), own, waveReadLaneFirst(own)) successfully stops helper lanes from spinning in waterfall loops.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7133712998 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/issues/908#issuecomment-7133712998). Originally posted by [LAKSHYA-cmd-tech](https://github.com/LAKSHYA-cmd-tech) on 2026-11-24T14:01:31Z. --- Verified and merged downstream in PR #29. select(isHelperLane(), own, waveReadLaneFirst(own)) successfully stops helper lanes from spinning in waterfall loops.
MichaelSmithAI commented 2026-11-24 15:04:05 +00:00 (Migrated from github.com)
Author
Contributor

Imported from Marvisak/VIctory. Originally posted by MichaelSmithAI on 2026-11-24T14:29:52Z.


Independent covered-pixel check on exact 9d5ce7a under RTX 4090 Wine/GE 3.2. Microsoft’s DXIL validator accepted the translated pixel shader. A source-built GFX1030 shader reading pixel-position X with v_readfirstlane produced [0.5, 0.5, 0.5, 0.5] at the covered pixel of a 1×1 RGBA32F target. This verifies the covered-pixel result for that input. The fixture does not observe a derivative computed from a neighboring helper lane, and it does not measure title timing.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7134471034 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/issues/908#issuecomment-7134471034). Originally posted by [MichaelSmithAI](https://github.com/MichaelSmithAI) on 2026-11-24T14:29:52Z. --- Independent covered-pixel check on exact 9d5ce7a under RTX 4090 Wine/GE 3.2. Microsoft’s DXIL validator accepted the translated pixel shader. A source-built GFX1030 shader reading pixel-position X with v_readfirstlane produced [0.5, 0.5, 0.5, 0.5] at the covered pixel of a 1×1 RGBA32F target. This verifies the covered-pixel result for that input. The fixture does not observe a derivative computed from a neighboring helper lane, and it does not measure title timing.
Sign in to join this conversation.
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#908
No description provided.