Shaders: a lane mask counted after a loop its lanes leave at different iterations is each lane's own, not the wave's (wrong count, no error) #1498
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory#1498
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
@r4tedx on GitHub · 2026-11-24 18:31 UTC · original
A compute program that counts (or otherwise reads as a number) a lane mask after control flow its lanes took differently gets a wrong value in the per-lane form, without any error. The commonest shape is the loop compilers emit: lanes that are done are added to an exit mask, EXEC loses them, and after the loop the mask is counted.
Reproduction (hand-assembled GFX10, no game data)
A wave32 compute program, 32 threads per group,
v0= the thread's index in the group, result inv2:Words:
4A020081 BE8A0380 4E020281 7D840280 880A0A6A 8A7E0A7E BF89FFFB 887E0A7E BE890F0A 7E040209. The wave64 form is the same with_b64operations (BE8A0480,888A0A6A,8AFE0A7E,88FE0A7E,BE89100A) and 64 threads.On the console every lane ends with
v2 = 32(64 for the wave64 form): one wave, one mask.What happens
Measured with the readback harness of #233 at its head
ededb1b, where lane masks are handled as onmain(the per-lane form). Onmainffe310eitself both programs lower without a refusal (checked with a unit test throughlower); I have not run them on a GPU frommain, which has no multi-thread readback harness, so the table is #233's.A second shape, a mask grown inside a branch only some lanes take and counted after it, is refused on a 64-lane host with
a lane mask holding lanes elsewhere read as data, which is at least not silent.Why
In the per-lane form each lane knows of a mask only what its own path saw. A mask joined across paths the lanes took differently, when read as a number, is then each lane's own view of it (here: its own bit), not the wave's.
How common
Offline over the title's shader pack (local title data, CPU only, counts only): about 400 compute programs read a lane mask as a number after such a join, about 300 of them wave32. That is a count of the shape, not of programs known to misbehave, and I have no title measurement of the effect. Counts feeding compaction and culling are the obvious candidates.
A fix, and where it is
The console flow of #320 (every lane runs every block, branches are the wave's) gives the wave's mask. A rule that sends such programs there on a host that runs their wave size, keeping the per-lane form where the console flow cannot lower them, makes all three rows exact and changes no program's outcome over the pack (no program gained or lost for a 32-lane or a 32-64 host). It sits on the fork branch after #439 (r4tedx/VIctory
shader/wave-per-group), because it needs the console flow, which is not onmain. Two of the fixtures and the detection of joins lanes reach by different paths come from @mohammadallami75-ops's patch on #439.Related: #225 (named lane reads where lanes branch differently, the same family), #269.
AI-assisted (Claude Code).
@andrewpozdnakov7-jpg on GitHub · 2026-11-24 21:20 UTC · original
I ran the issue's wave32 loop on WARP 1.0.22 through the fork's normal shader emitter and dispatch/readback harness.
05c7cbb161f320e2fc25918a234c5978f86ed23areturned counts 1 through 8 in batches of four lanes. All 96 outputs across three 32-thread groups disagreed with 32.88b38e8262c4b0242d84d640990e1e10565b78f9, all 96 outputs from the 32-thread groups and all 192 outputs from three 64-thread groups were 32. DXIL validation passed and the shader suite reported 165 passed, 1 ignored.Partial-wave results on this WARP version are inconclusive. An independent bounded
[WaveSize(32)]HLSL control compiled with DXC also sometimes counts more than 16 active lanes in the trailing wave of a 48-thread group. A useful hardware check would run the translated 48-thread case beside the DXC control on a wave32 adapter and compare each lane against 32 for the first wave and 16 for the trailing wave.@mohammadallami75-ops on GitHub · 2026-11-25 09:09 UTC · original
I ran the requested 48-thread hardware check with the translated fixture and a separate DXC control on a physical RTX 2080 SUPER (driver 621.01, Wave32). Across three groups, the translator returned 1 for all 144 reads at
05c7cbb. Atc734600, all 144 were correct: 32 for every thread in the first wave and 16 for every thread in the trailing wave. The independently compiled DXC control returned the same 32/16 results at both revisions. The 32- and 64-thread cases also went from 0/288 correct to 288/288. DXIL validation passed on both revisions.I submitted the 48-thread regression with the full results in r4tedx/VIctory#17. This was a synthetic test. I did not test the game or frame rate.
AI-assisted.
@Marvisak on GitHub · 2026-11-25 10:22 UTC · original
Automated triage for the maintainers.
Confirmed by reading
main.mask_dwordincrates/victory-shader/src/emit/lower.rsturns a lane mask read as a number into awaveActiveBallottaken in the block that writes the mask. In a loop that lanes leave at different iterations, lanes that already left are not active when the last write runs. Each lane's count then holds only the lanes that left with it, and nothing is refused. The WARP and RTX 2080 SUPER readbacks in the comments match this (1 instead of 32 or 64). Same family as #225.Open PR #1587 ("ballot divergent-loop masks at reconverged reads") targets this issue on
main. The fork branchshader/wave-per-groupfixes it through the console flow instead and depends on #439. Pull requests are open to everyone. If the branch should be weighed against #1587, please open it as a pull request stacked on #439, with the 48-thread regression from the comments.Generated by Claude Code