xshader: run loops that meet the group at barriers as a group #372
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/372"
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-28T05:07:36Z.
Refs #232.
Problem
A 128-thread translated mesh group holds two 64-lane guest waves. On a 32-lane host, a vote over one guest wave reaches the other half of that wave through group barriers:
tb_page_ballotuses three,tb_page_readtwo.When such a vote sat inside a guest loop, each host thread left the loop by its own copy of its wave's condition. The two guest waves could then run the loop a different number of times, as a loop over distinct values does, and one wave met group barriers the other never reached. That is undefined behaviour.
wave_cullalso took the exit vote of ans_andn2_b64/s_cbranch_scc0/1loop inside the guest branch guard, which differs between guest waves. Only threads 0–7, all in the first guest wave, clear the vote words. So once the first wave is done, the second can keep reading stale votes and never leave its loop, which had no iteration guard.Measured on main, over the 7,990 recorded mesh requests of ProjectScarlett:
The link to #232 is still unproven. Breadcrumbs from a ProjectScarlett GPU hang on an RTX 5090 (Xid 109) put the unfinished work in a run of 39
ExecuteIndirectmesh draws. Four of the mesh programs in those draws hold such a loop. Game runs on the same machine, all on a warm driver cache, all reaching the story load:main(four runs:10b48fd4three times,70b825a7once)df4f27c3MMU Fault: ENGINE GRAPHICS HUBCLIENT_FE … FAULT_PDE ACCESS_TYPE_VIRT_WRITEThat is one run of this change, so the timeout's disappearance is suggestive, not proven. The new fault is a front-end write to an unmapped address. It followed vkd3d-proton dropping raytracing builds and postbuild-info writes whose title addresses map to no resource. That is the area #320 covers, and we are testing the two together next.
Change
A loop now iterates as a group when its instructions hold a group rendezvous, or when it encloses such a loop. This applies to the mesh programs that vote across guest waves, the hoisted wave-cull compute programs and the page-wave programs.
Group vote. The loop repeats while
tb_group_any(tb_live)is true. That is a groupshared OR, the same in every thread.Done threads change nothing. A thread whose own condition says stop puts its skip target aside and sets
tb_skippast every instruction. Every guard in the body tests that, so the thread changes no state but still meets every barrier. After the loop it takes its skip target back.Votes move before the guard. The votes
wave_culltook inside the guard are now taken before it:s_andn2_b64;s_cmp_lg_u32 exec_hi, 0;s_cselect_b32 exec_hi, exec_lo.A thread the guard skips votes false. For every thread that runs the instruction, the result is the same as before.
Iteration guards.
tb_guardother stages have. Leaving one early skips no barrier.Unchanged. Compute loops without a rendezvous, and every program outside those three kinds.
After the change, no group barrier in any recorded mesh program sits under a guard. There are 351 group loops in 244 programs, and every one of the 5,112 mesh loops is bounded.
Tests
src/tests/hlsl/group_loops.rscovers loop selection, the guarded vote, and the emitted shape of a full mesh translation. In that translation, no barrier is inside anif, and every loop around one closes ontb_group_anywith the round count.tb_guard.loop-3,loop-67andloop-128.loop-3passed.loop-67hung the GPU (the kernel loggedring gfx_0.0.0 timeoutand a successful ring reset) and then read back 0 of 64 words. The guest stops at the first mismatch, soloop-67clipped andloop-128did not run.Checks
Run at 0c08bc31, this branch before the rebase onto
7bafe6b6:tools/check_translator_gpu.py, all 59): pass on AMD (RADV, 1002:13c0) and on an RTX 5090 (10de:2b85).lanes-shader-cache,lanes-raster-tables,lanes-compute-root,lanes-compute-root-recoveryandlanes-bindless-compute(28 checks): pass on both cards.After the rebase:
cargo testfor the shader compiler: pass.python tuxbox.py check --no-gpu: pass (all seven steps).--no-gpuagainst7bafe6b6: PASS.The 1,100 changed outputs are all mesh programs (
ms_6_6): 1,004 programs and 96.linkrequests. I split them by kind in the earlier run againstdf4f27c3, which changed the same number: 244 gained group loops and the guard, and 760 only gainedtb_guardon loops without a rendezvous.🤖 Generated with Claude Code