Skip to content

fix(shader): count a meet's lanes by their own path where predication runs others too - #688

Merged
pragyaangaur merged 4 commits into
pragyaangaur:mainfrom
earpjonathan:shader/meet-predicated-lanes
Nov 28, 2026
Merged

pragyaangaur merged 4 commits into
pragyaangaur:mainfrom
earpjonathan:shader/meet-predicated-lanes

Conversation

@earpjonathan

Copy link
Copy Markdown
Contributor

Fixes a miscount in the halves meet from #511 where selective predication runs a block of a meet region. Two captured compute programs, 65de113e and 804b342c, are lowered wrong on main: each has lane-mask sites in a meet region whose leaving edges (10 of them) sit in predicated blocks.

The bug

Selective predication (lower/predicate.rs) runs some blocks in every lane of the host wave, with a predicate saying which lanes the block's code is really for: an early out's lanes run on as nothing, and a one-sided guard's body runs in every lane. The meet's bookkeeping in lower/meet.rs didn't look at that predicate. In a predicated block:

  • meet_leave added to a site's resolved word for every lane that ran the block, also for lanes whose real path is elsewhere. Those lanes then counted again on their own path.
  • The add after a site's wait counted every lane running the block.
  • The mask ballot at a site, and the lane count at the region's branch block, took every lane running the block.

A half's resolved could then pass its count, so the other half waited at a site this one had left until the spin fuse ran out. Or it could reach count while some of its lanes were still on their way to the site, so the other half took them as absent and read their ballot bits as 0. Both give a wrong ballot without any report.

The fix

The meet's counts and ballots now take only the lanes whose path goes through the block: they AND with the block's predicate where it has one (lanes_here), as the predicated in-step ballot already does. That covers the leaving-edge adds, the add after the wait, the site ballot in meet_masks, and the count published in meet_start. Unpredicated blocks lower as before.

Tests

In lower/tests.rs there is a synthetic program in the shape of the two programs. The lanes from 56 leave through an early out, so predication runs every block after it in all lanes. The lanes below 40 then go through a guard that predication leaves divergent: its body holds an end of the program (lanes from 63 end; none of the guard's lanes do), so it is neither a skip guard nor a flat diamond. There the lanes put an even-lane compare in VCC, then move both dwords into VGPRs (a lane-mask site). Before the site, the upper half's lanes there (32 to 39) run a long dependent ALU chain (multiply and xor with the thread id, 15000 steps, result stored), so the host compiler can neither fold it nor drop it. Since #655, main lays out flat the nested-guard shape the two programs have, so the test uses one it doesn't.

On main, the upper half counts its lanes done as follows. The 8 lanes leaving at the early out count. The guard's block runs in all 32 lanes and adds 24 for the lanes skipping it, of which 8 (the lanes that already left) are bogus. That makes 32, the half's whole count, before its 8 late lanes reach the site. With the fix it counts 24. I confirmed this with a temporary dump of the lowering of the program, on main before and after #655, since removed.

  • a_mask_behind_predicated_guards_meets (native): with the rendezvous it translates for 64, 128 and 256 threads on a 32-lane host. Without it, it is refused as before.
  • a_mask_behind_predicated_guards_matches_the_console_on_every_gpu (halves_tests.rs, Windows): every lane matches the console's ballot in groups of one, two and four console waves.

Results

The test fails on main and passes with the fix, on main both before and after #655. Under Wine on an M5 Pro, each tree rebuilt from scratch:

  • On main before fix(shader): keep lanes that break out of a counted loop in it, in halves #655 (4396e31) with only the test added (local, not for merging): the native test passes and the GPU test fails. 128 lanes are wrong, exactly the lower half of each of the 4 console waves (lanes 0-31, 64-95, 128-159, 192-223). Each gives 0x55555555, 0, 0 where the console gives 0x55555555, 0x55, 0: the upper half's ballot bits read as 0, as the count above predicts.
  • On 4396e31 with fix(shader): keep lanes that break out of a counted loop in it, in halves #655 merged and only the test added (local, not for merging): it fails the same way, on the same 128 lanes with the same values.
  • With the fix on 4396e31: both tests pass, and the whole victory-shader suite passes: lib 535 passed, 0 failed, 5 ignored; resource_tracking 3 passed, 1 ignored.
  • With the fix merged with current main (cade9e0): lib 544 passed, 0 failed, 5 ignored; resource_tracking 3 passed, 1 ignored.

Checks

  • cargo test -p xtask (10 passed) and cargo xtask policy (352 files) pass.
  • Clippy with -D warnings is clean on x86_64-pc-windows-gnullvm, for the whole workspace and all targets, with and without --all-features.
  • Native cargo test -p victory-shader: 279 passed, 2 ignored. a_mask_behind_predicated_guards_meets passes on main with the test added, before and after fix(shader): keep lanes that break out of a counted loop in it, in halves #655: without the rendezvous the program is refused there too.
  • Over 39 compute programs captured in game, only 65de113e and 804b342c change against main (cade9e0); the other 37 give identical output.

🤖 Generated with Claude Code

earpjonathan and others added 4 commits November 28, 2026 05:55
… others too

Where selective predication runs a block in a meet region (an early out
whose lanes run on as nothing, a one-sided guard run in every lane),
every lane of the host wave runs it, also those whose path is elsewhere.
They added to a site's `resolved` count by their own branch there, and
again on their real path; they were counted done after a site's wait,
and in the lanes at the region's branch block. A half's count then
passed its `count` (the other half waited to the fuse at a site this one
had left) or reached it while its lanes were still on their way (the
other half read its ballot as 0). Now the meet's counts and ballots take
only the lanes whose path is through the block (its predicate), as the
predicated in-step ballot already does.

A test program in the shape of the compute programs this changes: an
early out, then a guard predication leaves divergent (its body holds an
end of the program, so it is neither a skip guard nor a flat diamond)
around a lane mask read as data, the upper half's lanes there late
behind a long dependent chain the host compiler cannot fold. It meets
with predication on and is refused without the rendezvous (native), and
gives the console's ballot on every GPU (Windows). Its upper half would
have counted 32 done, its lane count, with 8 lanes still on their way.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…d-lanes

# Conflicts:
#	crates/victory-shader/src/emit/halves_tests.rs
…r#680)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@pragyaangaur
pragyaangaur merged commit 3d66de5 into pragyaangaur:main Nov 28, 2026
1 check passed
ZebeastSantaCruz83142069 added a commit to ZebeastSantaCruz83142069/VIctory-macOS831 that referenced this pull request Nov 28, 2026
Upstream took pragyaangaur#688, pragyaangaur#689, pragyaangaur#694-pragyaangaur#697, pragyaangaur#700, pragyaangaur#701 and new loader and HLE
switches overnight. Conflicts:

- bindless.rs: our slot vector, net range counting and timing stay;
  upstream's pragyaangaur#701 fix lives in CopySpans and merged cleanly; its heap
  walk cache (VICTORY_HEAP_WALK_CACHE) joins our uploads walk.
- host.rs: list steps timed upstream's way (refreshes and slots one in
  16); prep phases counted in nanoseconds, the flight trace's per-thread
  phases too; the frame report keeps our uploads-by-step line and gains
  upstream's evicting line.
- Our runs of table slots now ask VICTORY_SLOT_ONCE first, so upstream's
  switch reaches the batched path.
- run.rs: VICTORY_PROFILE and VICTORY_GUARD_LOOKUP both start.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants