Repository navigation
fix(shader): let lanes outside a loop's entry predicate leave it, in halves - #709
Open
Scarlet-Noble wants to merge 1 commit into
Open
Scarlet-Noble wants to merge 1 commit into
Scarlet-Noble wants to merge 1 commit into
Conversation
…halves A skip-guard body that halves predication runs in every lane can hold a counted per-lane loop. Lanes outside the predicate never entered that loop on the console, but they ran its exit test, which they need never meet: they spun to the iteration limit and left the program, skipping their stores. Each counted loop now records the predicate it is entered under (one entry only), and at its exit branch a lane outside that entry predicate takes the successor that leaves. A lane that left the predicate inside the loop (a break) stays in it, as pragyaangaur#655's lockstep exchanges need. Co-Authored-By: Claude Opus 5.5 <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
In halves, a skip-guard body (
if (cond) { ... }→v_cmpx+s_cbranch_execz) that has to be predicated (every lane runs it, under the predicate) can contain a counted per-lane loop:On the console, lanes outside the predicate (here, trip 0) never enter the loop. After predication they run it anyway, and they run its exit test too, which a trip-0 lane never meets. They spin to the iteration limit and leave the program, so their stores never happen: those lanes write nothing.
The fix
Each counted loop records the predicate it's entered under (
enter_loop, single entry only). At the loop's exit branch, a lane outside that entry predicate takes the successor that leaves the loop. A lane that leaves the predicate inside the loop (a break) still stays in it, as #655 needs for its lockstep exchanges.first_lane_reads_past_a_break_and_under_nested_guards_match_the_console_on_every_gpupasses.How it was found and tested
Found by differential testing: random compute shaders, each with an exact CPU model of its expected output, run through the translator on an M3 Pro. Five of 400 random shaders came out wrong on
main(a08d94b); all five are right with this change.cargo test --workspace: 279 passed (victory-shader).A hand-written regression test in
halves_tests.rsis still to come: the minimal shape above didn't reproduce on its own (main already handles it), so the test needs one of the fuzz cases reduced to GFX10 words. I'll add it to this PR.🤖 Generated with Claude Code