Skip to content

fix(shader): first-lane reads in divergent code meet between halves (VICTORY_HALVES_FIRST_MEET) - #719

Open
Nick233x wants to merge 2 commits into
pragyaangaur:mainfrom
Nick233x:fix/halves-first-meet
Open

Nick233x wants to merge 2 commits into
pragyaangaur:mainfrom
Nick233x:fix/halves-first-meet

Conversation

@Nick233x

Copy link
Copy Markdown
Contributor

What

VICTORY_HALVES_FIRST_MEET=1 (off by default) lets a v_readfirstlane_b32 in divergent code of a wave64 compute program, run as two 32-lane halves, meet the other half through group-shared memory (lower::meet), where it was refused with "a first-lane read of a value that may differ between 32-lane halves". Each half puts whether it has an active lane there and its first active lane's value; the console's first active lane is the lower half's if it has one, else the upper half's.

With the switch, a meet region may also contain cycles: sites count only in the acyclic part before every cycle, so the order of sites stays the one topological order the deadlock argument needs (see meet_regions' doc).

Off, nothing changes: the read keeps its refusal and the reason it gave before (the second commit makes sure of that; a_cndmask_with_vccz_as_its_mask_keeps_the_first_lane_refusal caught it). The translation differs with the switch, so the shader cache keys on it.

Lanes are counted as #688 counts them: first_meet gets the read's guard, which guard() already ANDs with pred_active, so only lanes whose path is through the block ballot "this half has lanes here", and the "done with the site" count goes through meet_halves, which #688 fixed.

Why

Run K-A dropped 300–450 draws/dispatches a frame for lack of a host pipeline (permanent, "0 being made"). 19 of the compute shaders that don't translate were refused on first-lane reads or next to them.

Measured

probe_translate_folder over those 19 shaders (Wine, D3DMetal):

translate
main 7 / 19
VICTORY_HALVES_FIRST_MEET=1 12 / 19

Of the other 7: 4 still refuse a first-lane read (outside a meet region or in a loop), 2 now stop at "a lane mask read as data", 1 at "a wave reduction over both halves".

How many draws this brings back a frame is for a game run with VICTORY_DROP_WHY=1 (#696) and this switch.

Tests

  • tools/macos/test-wine.sh -p victory-shader: 546 passed, 0 failed (includes first_lane_reads_in_divergent_code_meet_between_halves, which runs the met reads on the GPU against the console's result for each arm and group size).
  • cargo test -p victory-shader --lib (native): 280 passed.
  • cargo test -p xtask, cargo xtask policy: ok.
  • rustfmt: no new differences against main in the touched files.

🤖 Generated with Claude Code

Nikola Milenkovic and others added 2 commits November 28, 2026 20:12
…VICTORY_HALVES_FIRST_MEET)

A v_readfirstlane_b32 of a lane-varying value in divergent code of a
wave64 program run in 32-lane halves was refused (FIRST_ACROSS) and its
pipelines' draws dropped. Behind VICTORY_HALVES_FIRST_MEET=1 it meets the
other half through the rendezvous words (lower::meet): two words per read
(whether the half has lanes there, its first lane's value); the lower
half's value wins when it has lanes. Regions with a cycle also meet, sites
only in the acyclic part before it.

Tests: first_lane_reads_in_divergent_code_meet_between_halves (refused
without, the console's value on every adapter with; mutation-checked), and
an ignored probe that translates a folder of cached containers.

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

The read's operand was lowered before the switch was asked, so with it off
a refusal there could carry the operand's reason instead of the first-lane
one (a_cndmask_with_vccz_as_its_mask_keeps_the_first_lane_refusal). Also:
first_meet's doc was joined to meet_halves', the pragyaangaur#688 test built Parts
without the new field, and the new lines are formatted.

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.

1 participant