xshader: find the first active lane with a ballot, not a lane minimum #347

Merged
NickStallman merged 3 commits from upstream-pr/347 into main 2026-11-28 00:42:58 +00:00
NickStallman commented 2026-11-28 00:38:12 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-11-28T00:38:12Z.


What

The translator found "the first lane whose guest EXEC bit is set" as WaveActiveMin((exec_lo & 1u) ? WaveGetLaneIndex() : 0xffffffffu). It uses that for v_readfirstlane_b32 and other scalar writes from a vector, for s_ff1_i32_b64 of EXEC, and for tb_first_active_lane. It now takes the lowest set bit of WaveActiveBallot((exec_lo & 1u) != 0u), using the second word for lanes 32–63 of a 64-lane host wave, and still gives 0xffffffff when no lane is set.

Why

On an RTX 5090 (driver 620.70.10, GE-Proton11-14), a synthetic program from the float-compares check (#348) lost the device. Every time, the kernel logged NVRM: Xid 109 … CTX SWITCH TIMEOUT. This is the same Xid that #232 reports from a game run, but this PR does not show that the in-game device loss has the same cause. That is untested.

The program is the translation of v_readfirstlane_b32 s23, v0; v_cmp_lt_f32 vcc_lo, s23, v1 with readback. A bisect on the 5090, one guest run per variant, gave:

Variant Xid 109
The program, EXEC partly set (4 different masks, and twice the same) yes
Full EXEC, or empty EXEC no
Without the readfirstlane item no
WaveReadLaneAt replaced by WaveReadLaneFirst, leaving the minimum's result unused yes
WaveReadLaneAt(v0, 0u) instead of the elected lane yes
WaveActiveMin replaced by firstbitlow(WaveActiveBallot(...).x) no

The device loss followed the minimum even when nothing used its result; DXC keeps wave operations whose results are unused. The idiom alone does not reproduce it, though. Fifteen standalone shaders all ran without a device loss. They covered the minimum in the branch-and-phi shape DXC gives the translated code, WaveActiveBitOr and WaveActiveSum in the same shape, the select form, and a lane-varying minimum. So something else in the program is needed as well, and it is still being narrowed down. The ballot gives the same lane, as the AMD results below show, and avoids the hang.

Results

  • Translator tests: 475 passed. A new test, readfirstlane_finds_its_lane_by_ballot, fails on main. host_profiles.txt is re-recorded because four fixture programs' translations (saveexec, waterfall, lanes, empty) change on four host profiles. In the cs_5_0 profiles the change is inside #if __SHADER_TARGET_MAJOR >= 6, so only the text differs.

  • python tuxbox.py check --no-gpu: passed.

  • Shader harness --no-gpu against main (e6b68c54): PASS. Translated before and after: 27,812 on the wave64 host and 4,820 on the wave32 host. 0 recovered, 0 regressed, 0 new failures. Output changed for 2,846 and 1,165 programs. 199 of 200 sampled changed programs compiled through DXC and DXV with both builds, and 0 broke.

  • float-compares (#348) on this change:

    • RTX 5090: no device loss. 874 cases read back (the native wave64 cases don't run on a 32-lane host).
    • AMD Raphael iGPU (RADV, Mesa 26.0.8): the same 559 cases differ from the model as on main, so the ballot elects the same lanes.
    • The cases that differ are two known translation faults, which that PR expects.
  • On main, the RTX 5090 loses the device at compare02w32_random0. After that, 1,180 of the 1,234 cases have no readback.

  • Trimming the hanging program to find what else is needed, on the 5090: it still hangs without the divergent if (exec_lo & 1u) blocks, the lane counts, the stores or the helpers. It stops hanging if any one of these is removed:

    • the minimum;
    • the cross-lane read of v0;
    • the float compare (the tb_float_relation helper) on the value read;
    • the ballot of the compare.

    So the device loss needs that whole chain, with the minimum present. Removing the minimum, as this change does, is enough for this program. Whether other chains of wave operations can cause the same hang is not known yet.

  • On this change with the float-compares check on top (38207ed5, on e6b68c54): tools/check_translator_gpu.py, all checks, passed 58 of 58, and the shader Lanes suites (lanes-shader-cache, lanes-raster-tables, lanes-compute-root, lanes-compute-root-recovery, lanes-bindless-compute) passed 28 of 28. Both ran on the AMD Raphael iGPU (1002:13c0, RADV) and on the RTX 5090 (10de:2b85, 620.70.10), with GE-Proton11-14.

🤖 Generated with Claude Code

<!-- greyfinch-sync:brcly/TuxBox:issue:5534999760 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/347). Originally posted by [NickStallman](https://github.com/NickStallman) on 2026-11-28T00:38:12Z. --- ## What The translator found "the first lane whose guest EXEC bit is set" as `WaveActiveMin((exec_lo & 1u) ? WaveGetLaneIndex() : 0xffffffffu)`. It uses that for `v_readfirstlane_b32` and other scalar writes from a vector, for `s_ff1_i32_b64` of EXEC, and for `tb_first_active_lane`. It now takes the lowest set bit of `WaveActiveBallot((exec_lo & 1u) != 0u)`, using the second word for lanes 32–63 of a 64-lane host wave, and still gives 0xffffffff when no lane is set. ## Why On an RTX 5090 (driver 620.70.10, GE-Proton11-14), a synthetic program from the float-compares check (#348) lost the device. Every time, the kernel logged `NVRM: Xid 109 … CTX SWITCH TIMEOUT`. This is the same Xid that #232 reports from a game run, but **this PR does not show that the in-game device loss has the same cause**. That is untested. The program is the translation of `v_readfirstlane_b32 s23, v0; v_cmp_lt_f32 vcc_lo, s23, v1` with readback. A bisect on the 5090, one guest run per variant, gave: | Variant | Xid 109 | |---|---| | The program, EXEC partly set (4 different masks, and twice the same) | yes | | Full EXEC, or empty EXEC | no | | Without the readfirstlane item | no | | `WaveReadLaneAt` replaced by `WaveReadLaneFirst`, leaving the minimum's result unused | yes | | `WaveReadLaneAt(v0, 0u)` instead of the elected lane | yes | | `WaveActiveMin` replaced by `firstbitlow(WaveActiveBallot(...).x)` | no | The device loss followed the minimum even when nothing used its result; DXC keeps wave operations whose results are unused. The idiom alone does not reproduce it, though. Fifteen standalone shaders all ran without a device loss. They covered the minimum in the branch-and-phi shape DXC gives the translated code, `WaveActiveBitOr` and `WaveActiveSum` in the same shape, the select form, and a lane-varying minimum. So something else in the program is needed as well, and it is still being narrowed down. The ballot gives the same lane, as the AMD results below show, and avoids the hang. ## Results - Translator tests: 475 passed. A new test, `readfirstlane_finds_its_lane_by_ballot`, fails on `main`. `host_profiles.txt` is re-recorded because four fixture programs' translations (saveexec, waterfall, lanes, empty) change on four host profiles. In the `cs_5_0` profiles the change is inside `#if __SHADER_TARGET_MAJOR >= 6`, so only the text differs. - `python tuxbox.py check --no-gpu`: passed. - Shader harness `--no-gpu` against `main` (e6b68c54): PASS. Translated before and after: 27,812 on the wave64 host and 4,820 on the wave32 host. 0 recovered, 0 regressed, 0 new failures. Output changed for 2,846 and 1,165 programs. 199 of 200 sampled changed programs compiled through DXC and DXV with both builds, and 0 broke. - float-compares (#348) on this change: - RTX 5090: no device loss. 874 cases read back (the native wave64 cases don't run on a 32-lane host). - AMD Raphael iGPU (RADV, Mesa 26.0.8): the same 559 cases differ from the model as on `main`, so the ballot elects the same lanes. - The cases that differ are two known translation faults, which that PR expects. - On `main`, the RTX 5090 loses the device at `compare02w32_random0`. After that, 1,180 of the 1,234 cases have no readback. - **Trimming the hanging program to find what else is needed,** on the 5090: it still hangs without the divergent `if (exec_lo & 1u)` blocks, the lane counts, the stores or the helpers. It stops hanging if any one of these is removed: - the minimum; - the cross-lane read of `v0`; - the float compare (the `tb_float_relation` helper) on the value read; - the ballot of the compare. So the device loss needs that whole chain, with the minimum present. Removing the minimum, as this change does, is enough for this program. Whether other chains of wave operations can cause the same hang is not known yet. - On this change with the float-compares check on top (`38207ed5`, on `e6b68c54`): `tools/check_translator_gpu.py`, all checks, passed 58 of 58, and the shader Lanes suites (`lanes-shader-cache`, `lanes-raster-tables`, `lanes-compute-root`, `lanes-compute-root-recovery`, `lanes-bindless-compute`) passed 28 of 28. Both ran on the AMD Raphael iGPU (1002:13c0, RADV) and on the RTX 5090 (10de:2b85, 620.70.10), with GE-Proton11-14. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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
brcly/TuxBox!347
No description provided.