Repository navigation
fix(shader): keep the lanes past a dispatch's thread count outside EXEC where they cannot leave - #667
Merged
pragyaangaur merged 1 commit intoNov 28, 2026
Conversation
…EC where they cannot leave
A dispatch counted in threads (DispatchX with its thread-dimensions flag)
may end in a part of a group. The console starts only the threads the
dispatch counts; the other lanes of the last wave are there with their
EXEC bit clear. Here the host runs whole groups, and the translation asked
for such a dispatch branches the lanes past the count to a return at the
entry (Lower::leave_past_the_count). That is possible only where no lane
waits for another: a program with a group barrier, with LDS barriers for
narrow waves, or in 32-lane halves that pass values needs every lane at
each barrier. Such a program had no form for the dispatch, and its last
group ran whole ("cannot leave the lanes past the count").
That is wrong for the lanes that do run, not only for stores past the
count: EXEC on entry held every lane, so a program that counts its lanes
(s_bcnt1_i32_b64 of EXEC), ballots, sums over the wave or reads the first
lane computed with the lanes the console never starts. GTA VI's
acceleration-structure builder dispatches 28918b7150a7aad5 and
caa78b8ca62bc3d6 that way (1,606 and 12 threads in groups of 64); both
add s_bcnt1 of EXEC into every lane's addresses.
Those lanes now stay, with EXEC on entry clear, as the console has them.
For the translation with thread limits the structure pass takes EXEC on
entry as a new atom, "the dispatch runs this lane"
(structure::structure_limited, Atom::Dispatched), instead of every lane;
its lane bit is thread < count (or count 0) from the same user-data word.
Every mask derived from EXEC carries it through the mask algebra that is
already there: guards of loads and stores, ballots and bit counts, sums
and prefixes over the wave, first-lane reads, and the stay conditions of
loops, so such a lane neither stores nor votes to stay. A mask the
program itself sets to all lanes still holds all of them: the compiler's
whole-wave sections run the lanes not started too and select on the
saved EXEC, as on the console.
The return at the entry stays for the programs that can use it. The new
form is tried where it cannot be (lower_limited), in one dimension, for
the per-lane form only (literal halves take EXEC as the console wave's
whole: no word there); where it is refused the program is as before.
Translations without thread limits do not change.
Of the builder's 52 programs, 37 had a form for such a dispatch; 51 have
one now (the other has one thread per group).
Tests, on hardware (M5 Pro, D3DMetal) against the console's values:
- a wave64 program in groups of 64 with LDS, a group barrier, a loop run
in lockstep with an atomic counter, s_bcnt1 of EXEC, EXEC as two
dwords, a first-lane read and the compiler's whole-wave sum, in
dispatches of 0 (all), 1, 2, 7, 12, 31, 32, 33, 40, 63, 64, 65, 74, 96,
127 and 128 threads over two groups: every lane that runs stores the
console's eight dwords, no other lane stores, and the loop's passes are
counted for the lanes that run only;
- the existing count test (each lane adds 1 to a counter) also with a
group barrier and with console lanes (v_mbcnt), in wave32 and wave64.
And natively: the limited structure guards an instruction under EXEC on
entry by the new atom and one under EXEC set to all lanes by nothing.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was wrong
A dispatch counted in threads (
DispatchXwith its thread-dimensions flag) may end in a part of a group. The console starts only the threads the dispatch counts. The other lanes of the last wave are there with their EXEC bit clear.The host runs whole groups. For such a dispatch the pipeline is translated again with
Options::thread_limits, and that form branches the lanes past the count to a return at the entry (Lower::leave_past_the_count). It exists only where no lane waits for another: a program with a group barrier, with LDS barriers for narrow waves, or in 32-lane halves that pass values needs every lane at each barrier. Such a program had no form for the dispatch, and the log said:A whole last group is wrong for the lanes that do run, not only for stores past the count. EXEC on entry held every lane, so whatever the program computes from EXEC counted lanes the console never starts. Two of the builder's programs are dispatched this way (1,606 and 12 threads in groups of 64). Both begin with
s_bcnt1_i32_b64of EXEC and add the count into every lane's addresses.The change
Those lanes stay, with EXEC on entry clear, as the console has them.
structure::structure_limited,Atom::Dispatched), instead of every lane. Every mask derived from EXEC carries it through the existing mask algebra: guards of loads and stores, ballots and bit counts, sums and prefixes over the wave, first-lane reads, the stay conditions of loops. A lane past the count neither stores nor votes to stay.s_or_saveexec_b64 ..., -1, then a select on the saved EXEC) run the lanes not started too, as on the console, and the select gives them the identity.thread < count(or count 0: every lane), from the same user-data word the return form reads (USER_DISPATCH_THREADS_X), made once in the entry block (Lower::dispatched). No lane returns, so barriers and exchanges keep every lane.lower_limited): one dimension, the per-lane form only. Literal halves take EXEC as the console wave's whole and get no word. Where the new form is refused, the program is as before.Translations without thread limits do not change: the limited structure is built only for that form.
In game
Nothing to show yet: in our runs only the structure builder dispatches counted in threads, and it is held back by default since #591 (
VICTORY_BVH_BUILDER=1runs it). No play-time program changes.Effect
The one left has one thread per group. The 14 that gain a form have console barriers or run as wave64 in halves (the three prefix sums among them).
Tests
On hardware (M5 Pro, D3DMetal), each lane against the console's value computed in the test:
lanes_past_a_count_stay_out_of_exec_in_halves_on_every_gpu: wave64, groups of 64, LDS, a group barrier, a lockstep loop with an atomic counter,s_bcnt1of EXEC, EXEC as two dwords, a first-lane read, the compiler's whole-wave sumthe_lanes_past_a_count_of_threads_do_not_run, extended: plain, withs_barrier, withv_mbcntWithout hardware:
a_program_with_barriers_keeps_the_lanes_past_a_count_out_of_exec: the program above gets the word only when asked.only_programs_whose_lanes_never_wait_leave_past_a_count_of_threads: a barrier and halves now give a word; two dimensions, one thread per group, not asked for, and literal halves give none.exec_on_entry_holds_the_dispatched_lanes_in_the_limited_form(native): an instruction under EXEC on entry is guarded by the new atom, one under EXEC set to all lanes by nothing, one under the saved EXEC by the atom again.Whole victory-shader suite under Wine: 537 passed, 0 failed, 5 ignored. Native: 278 passed. Clippy (
x86_64-pc-windows-gnullvm,--all-targets,-D warnings) for victory-shader and victory-gpu, andcargo xtask policy, pass.Not in this branch
🤖 Generated with Claude Code