xshader: find the first active lane with a ballot, not a lane minimum #347
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/347"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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 forv_readfirstlane_b32and other scalar writes from a vector, fors_ff1_i32_b64of EXEC, and fortb_first_active_lane. It now takes the lowest set bit ofWaveActiveBallot((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, v1with readback. A bisect on the 5090, one guest run per variant, gave:WaveReadLaneAtreplaced byWaveReadLaneFirst, leaving the minimum's result unusedWaveReadLaneAt(v0, 0u)instead of the elected laneWaveActiveMinreplaced byfirstbitlow(WaveActiveBallot(...).x)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,
WaveActiveBitOrandWaveActiveSumin 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 onmain.host_profiles.txtis re-recorded because four fixture programs' translations (saveexec, waterfall, lanes, empty) change on four host profiles. In thecs_5_0profiles the change is inside#if __SHADER_TARGET_MAJOR >= 6, so only the text differs.python tuxbox.py check --no-gpu: passed.Shader harness
--no-gpuagainstmain(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:
main, so the ballot elects the same lanes.On
main, the RTX 5090 loses the device atcompare02w32_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:v0;tb_float_relationhelper) on the value read;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, one6b68c54):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