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-26 04:14:08 +00:00 by github-bot · 2 comments
Owner

@⁠Vaximous on GitHub · 2026-11-24 13:55 UTC · original

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: #307), 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.

**@⁠Vaximous** on GitHub · 2026-11-24 13:55 UTC · [original](https://github.com/Marvisak/VIctory/issues/908) ## 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://git.gtahub.st/github/Marvisak--VIctory/pulls/307), 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:14:08 +00:00
Author
Owner

@⁠LAKSHYA-cmd-tech on GitHub · 2026-11-24 14:01 UTC · original

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

**@⁠LAKSHYA-cmd-tech** on GitHub · 2026-11-24 14:01 UTC · [original](https://github.com/Marvisak/VIctory/issues/908#issuecomment-7133712998) Verified and merged downstream in PR #29. select(isHelperLane(), own, waveReadLaneFirst(own)) successfully stops helper lanes from spinning in waterfall loops.
Author
Owner

@⁠MichaelSmithAI on GitHub · 2026-11-24 14:29 UTC · original

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.

**@⁠MichaelSmithAI** on GitHub · 2026-11-24 14:29 UTC · [original](https://github.com/Marvisak/VIctory/issues/908#issuecomment-7134471034) 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.
This discussion has been locked. Commenting is limited to contributors.
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory#908
No description provided.