Skip to content

Shaders: console flow for groups of several console waves on 32-lane hosts - #1433

Closed
anasssssssss1 wants to merge 47 commits into
Marvisak:mainfrom
anasssssssss1:fix-console-flow-multi-wave
Closed

anasssssssss1 wants to merge 47 commits into
Marvisak:mainfrom
anasssssssss1:fix-console-flow-multi-wave

Conversation

@anasssssssss1

Copy link
Copy Markdown

Stacked on #439 (and so #320 and #233): one commit on top of it, in emit/lower.rs, with tests.

What

On a host without 64-lane waves, a wave64 program that needs its whole wave runs in the console flow only in groups of one console wave. Bigger groups stop with console wave64 lanes in a group of more than 64 threads on a host without 64-lane waves. This lifts that for groups of whole console waves (64 to 1024 threads).

Why it was refused, and how it is done

The halves of a console wave meet at group barriers (the exchange). In a group of several console waves, those waves branch and loop differently, so they reach different barriers, and a group barrier that pairs them by place would hang or pair the wrong halves.

Here group barriers are paired by count, not by place:

  • Each thread counts the group barriers it has passed (group-shared, one dword per thread). The two halves of a console wave run the same instruction stream, so they reach each exchange at the same count; the exchange slots are per half.
  • The program's own s_barrier becomes a wait: the half stamps its arrival (barrier count mod 4, and the phase it arrived in), then keeps passing group barriers until every half has arrived at this barrier (or the next one) or ended.
  • A thread that ends stamps its half as ended and keeps passing group barriers until every half has ended, so the others' exchanges and waits are never left one thread short. The LOOP_LIMIT abort path does the same.
  • What has to agree across threads is decided only from stamps written before a barrier and read after it: a stamp written in phase p is stored as p + 1 and counts once a thread has passed that barrier, so every thread deciding after the same barrier sees the same thing. Each check is one wave operation (host lane i tests half i, at most 32 halves).

Groups that are not a whole number of console waves, or whose LDS plus this state (threads + 3 × halves dwords) would pass 32 KiB, keep the old refusal.

Tests

New GPU tests in split_tests.rs, run on an RTX 4050 Laptop (split, two 32-lane waves per console wave) and an AMD Radeon 680M iGPU (native wave64), all exact:

  • console_flow_runs_groups_of_several_console_waves: v_readlane lane 40 in groups of 128 and 256 (each console wave reads its own lane 40).
  • console_waves_of_a_group_branch_differently: only console wave 0 enters a branch with a lane read inside; 256 threads.
  • console_waves_of_a_group_loop_differently: lane t loops t times reading lane 40, so wave 1 loops twice as long as wave 0; 128 threads.
  • program_barriers_order_lds_between_console_waves: waves take different branches, write LDS, s_barrier, then read the other console wave's dwords; 128 threads.

The tests that expected the refusal now expect a translation (console_lanes_translate_only_for_hosts_with_that_wave_size keeps a refusal check for a 96-thread group; each_adapter_gets_what_it_runs makes the 128-thread pipeline on every adapter).

  • cargo test -p victory-shader: 163 passed, 0 failed.
  • cargo clippy -p victory-shader --all-targets -- -D warnings, with and without --all-features: clean.

In the title

RTX 4050 Laptop (6 GB), Series S, on r4tedx's integration/testers update 9 (94e0ea5) with this change: compute programs refused in the world went from 112 to 1 (against the same tree at update 8 without it, so part of the drop is update 9's own changes), and none are refused for this reason. I have not checked the four InstanceCulling hashes from #71 by name. The world picture is still black on this machine; whether this is enough for the scene is open (pipelines were still being compiled when the runs were stopped).

No game data in this PR.

r4tedx and others added 30 commits November 24, 2026 11:20
How one console wave64 runs as two 32-lane host waves under our
per-lane structurisation, what has to cross halves, why exchanges need
uniform regions, how to test on a machine with both GPU kinds, and the
order of the remaining steps.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A compute shader that reads other lanes declares the console's wave
size. NVIDIA runs waves of 32 lanes only (D3D12 reports 32..32), so a
console wave64 program of that kind was refused at pipeline creation
and its dispatches were dropped without saying why.

The host's wave range (D3D12 options 1) now goes into translation as
`emit::Target`. A shader that needs a wave size the host does not run
stops there with the reason, the shader cache keys entries by the range,
and the run logs the range once with a warning when 64-lane waves are
missing. `victory translate --host-lanes 32-32` counts these shaders
without a GPU.

This is the first step towards running these programs as two 32-lane
waves on such hosts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`emit::host::Host::on(name)` and `VICTORY_ADAPTER` choose a hardware
adapter by part of its description, and `adapters()` lists them, so a
machine with an AMD and an NVIDIA GPU can run a test on each: the
native wave64 form as the reference on the one with 64-lane waves, the
32-lane form on the other. A new test checks on every adapter that a
wave64 program reading other lanes translates exactly when the adapter
runs 64-lane waves, and that the adapter then takes it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On a host without 64-lane waves (NVIDIA), a console wave64 compute
program whose lanes read only their own 32-lane half (DPP, ds_swizzle)
now declares WaveSize(32) instead of failing to translate. It must
read no mask whole, test no bit of a mask held as a number, have no
whole-wave sections and use no LDS. Every other wave64 program that
depends on the lane layout still stops with the reason from the
previous step. Mask ballots, wave reductions and lane-bit tests refuse
the split form as a safety net.

New GPU tests run hand-assembled programs on every hardware adapter
and check each lane against the console's layout. On an RTX 5070 the
split form is exact for 1-D groups of 32, 64 and 128 threads and for
3-D groups up to 8x8x4. A Radeon iGPU runs the same programs natively
as the reference, and a read across halves (v_readlane 40) still needs
64-lane waves.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A console wave64 program that reads masks whole or lanes of the other
half now runs on a host without 64-lane waves when its group is one
console wave (64 threads or fewer, no LDS). It runs as the console
does ("console flow"):

- `structure::structure_console` never resolves mask joins from what
  the lanes arriving know (every lane arrives); `Structured::execs`
  gives each vector instruction's EXEC bit.
- Vector instructions are guarded by EXEC. Branches are the console's
  s_cbranch_*: EXEC, VCC and mask-operation SCC tests are the console
  wave's, from both halves' ballots exchanged through group-shared
  memory between group barriers, which every thread reaches since both
  halves branch alike.
- Masks read whole are the exchanged ballots. v_readlane and
  v_readfirstlane read the owning half; v_writelane, v_mbcnt and mask
  bit tests use the console lane.

The per-lane form is tried first; a program that needs the console
flow is lowered again from the console structure.

GPU tests on an RTX 5070 are exact against the console: s_bcnt1 over
both halves (64, 48 and 32 threads), v_readlane 40, an exchange inside
a branch only the lower half takes, and a loop the halves leave at
different iterations with a lane read in each. The last one shows that
the per-lane form, which hosts with 64-lane waves get, is wrong for it
(on a Radeon iGPU): noted in docs/wave64-on-wave32.md, not changed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A wave64 program split over two 32-lane waves took the DPP row index
from the host lane, so the upper half (console rows 2 and 3) read
row_mask bits 0 and 1. The row now comes from the console lane there.
New test: v_mov_b32_dpp with row_mask:0x3 writes lanes 0 to 31 only,
exact on an RTX 5070 (split) and a Radeon iGPU (native).

Found in review against Marvisak#189 and Marvisak#192, which both get this right.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
v_readfirstlane reads the console wave's first lane. A wave64 program
with DPP or ds_swizzle and a v_readfirstlane was split into two 32-lane
waves, where the upper half read its own first lane: with all 64 lanes
active, lanes 32 to 63 got lane 32's value where the console gives
lane 0's (measured on an RTX 5070).

Such programs now take the console flow, which reads the first lane in
EXEC of the whole console wave (groups of at most 64 threads, no LDS),
or stop with the reason as they did before the split existed.

New test, exact on an RTX 5070 and a Radeon iGPU. Found by running the
same program against Marvisak#192, which has the same result on both adapters.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…the console flow

On the console v_readlane and v_writelane ignore EXEC, and a wave runs a
loop while any of its lanes does. The per-lane form runs branches and
loops per lane, so a lane that left a loop or skipped a branch is not
there to be read or written, and never sees the scalars set inside
(Marvisak#225):

- a loop lane t runs t times, reading lane L in each iteration: 12 of
  32 lanes wrong in waves of 32 (RTX 5070, Radeon iGPU), 24 of 64 in
  waves of 64 (Radeon);
- v_writelane to lane 40 inside a branch only lanes below 20 take: lane
  40 was never written.

A compute program with v_readlane or v_writelane, a branch that is not
uniform, no ds_(b)permute and no whole-wave sections now runs in the
console flow on every host. Where the host runs the console's wave
size, one host wave is the console wave: ballots are the wave's own and
nothing is exchanged, so any group size and LDS are fine. A program the
console flow cannot lower keeps the per-lane form
(`Parts::per_lane_only`), so nothing that translated before is refused.

Both cases are now exact on an RTX 5070 (wave32 natively, wave64 in two
halves) and on a Radeon iGPU (both natively).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The loop form compilers emit keeps the lanes that are done in an exit
mask that starts as 0 (s_mov_b64 s[2:3], 0; in the loop s_or_b64
s[2:3], vcc, s[2:3] and s_andn2_b64 exec, exec, s[2:3]). In the console
flow every mask join is a phi, and its incoming values had to be masks
derived from EXEC or a VALU result, so such a loop stopped with "a
lane-mask join of an untracked mask".

`Structured::others` gives the lane's bit of the other values read as
masks (constants, uniform selects, opaque ones), and the console flow's
mask joins take them. The per-lane form is unchanged.

New test: a loop in that form with a lane read in every iteration and
the exit mask counted afterwards. It was refused on an RTX 5070 before
and is exact there (in two halves) and on a Radeon iGPU now.

Found through the test report on Marvisak#233 that tried Marvisak#269's programs.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Drivers create pipelines from some modules the DXIL validator refuses
(D3D12 checks only the container hash we write). The hand-assembled
split and console-flow programs now go through dxil.dll's validator
before pipeline creation, where one is installed. All of them pass.

Prompted by a report on Marvisak#233 of pipelines created from modules that
fail validation.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
On the console one wave shares LDS without s_barrier, because it runs
an instruction in all 64 lanes before the next. A wave64 program of one
console wave per group that uses LDS stopped on hosts without 64-lane
waves (`a wave64 group sharing LDS without barriers`), and so did such
a program with cross-lane reads.

Both now take the console flow there. The halves reach every LDS
access together, and a group barrier before each access puts it after
every earlier one, whichever half made it.

What still stops says why: a group of more than 64 threads, ds_permute
across the halves, or a whole-wave section.

Two new tests (LDS written and read across the halves, one with the
lower half kept busy first) are exact on an RTX 5070 and a Radeon iGPU.
They also pass on the RTX 5070 with the barrier left out, so they check
the result, not that the barrier is needed.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The validator's message for an operation the stage or the entry's
properties do not allow ("Entry function performs some operation that
is incompatible with the shader stage or other entry properties") names
neither the operation nor the property, and it is the only message when
the call is in the entry function itself.

`victory translate --validate` now adds to each validator failure what
our own module declares and calls: its thread-group size, its wave size
and its dx.op operations (`emit::last_module_summary`, kept per thread
when a module is finished). Nothing of the console program is in it, so
a report of counts per reason is enough to see what the refused modules
have in common.

Prompted by a report on Marvisak#233: modules that fail validation with that
message and still create pipelines, 20 of them new with Marvisak#320, which I
cannot reproduce with hand-assembled programs.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The scan test of the previous commit goes through the carry of a prefix
sum only. These cover the other branch, where each half's reduction is
exchanged and combined: the sum of the lane ids, their maximum (in the
upper half), their minimum (in the lower half) and their bitwise or,
and a sum over a mask of lanes below 40, which straddles the halves.
A group with a partial upper half, or none, still stops with the
section's reason.

All exact on an RTX 5070 (two halves) and a Radeon iGPU (native).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
One console wave with no s_barrier whose LDS write and read sit in
different exec-masked blocks: every lane (or, after a 4096-iteration
loop, only lanes 32..63) writes dword t, then lanes 0..31 read dword
t + 32. A third case has the same masks with no branch around either
access. Hand-assembled; exact on an RTX 5070 (two 32-lane waves, console
flow) and a Radeon iGPU (one 64-lane wave).

The pattern is the one a reviewer measured stale reads for on Marvisak#189. The
console flow orders the first two cases twice: a branch on EXEC is
decided by both halves through an exchange (a group barrier), and each
LDS access has a group barrier before it, so they also pass with the
second left out. The third has no branch, and with the barrier before
each LDS access left out the lower half of the RTX 5070 reads 0 in 20 of
20 runs (exact in 20 of 20 with it): the first test here that fails
without that barrier.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The startup warning on hosts without 64-lane waves still said every
console wave64 compute program that reads other lanes is dropped, and its
literal carried a run of spaces from a lost line continuation. It now
says such programs run as two 32-lane waves where there is a form for
them, and that the rest do not translate.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Cases for the ds_bpermute_b32 lowering of the commit before, each lane
checked on an RTX 5070 (two 32-lane waves) and a Radeon iGPU (one
64-lane wave): EXEC over part of each half, two console waves per group,
groups of 48 and 32 threads (a source lane that is not there reads 0),
and beside a v_readlane across the halves, which takes the console flow
on a host without 64-lane waves.

Also formats that commit's new lines for this crate's line width, and
the plan now lists ds_bpermute as an in-half read; ds_permute stays
open.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
In the console flow on a host without 64-lane waves, a whole-wave section
that leaves a float sum, minimum or maximum stopped with "a
floating-point whole-wave operation across 32-lane halves". Each half's
result now crosses as its bits, like the integer ones: minimum and
maximum through FMin / FMax, a sum as the two halves' sums added last,
and a prefix sum in the upper half adds the lower half's total. Groups of
exactly 64 threads, as for integers.

A sum's additions are in one more order than the console's and the host
wave's own, so its last bits may differ, as they already may in one host
wave.

Tests (hand-assembled, each lane checked on an RTX 5070 and a Radeon
iGPU): the lane ids as floats, their sum, maximum (in the upper half) and
minimum (in the lower half) with identities 0.0, -inf and +inf, a sum
over a mask that straddles the halves, and an inclusive prefix sum.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The wave64 plan had per-console-wave arrival counters with a bounded wait
for groups of more than 64 threads. A wait is met only if the partner
half runs meanwhile, which D3D12 does not promise and an RTX 5070 does not
do in the LDS tests, so that plan is dropped. For programs without LDS,
each console wave becomes a host group of its own (64 threads, the
dispatch's x count multiplied), which is the console flow as it is.
Groups that share LDS stay open, with the candidates named.

The group sizes and counts come from an offline translate over a local
copy of the title's shaders; no program content is in the document.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A v_cndmask_b32 whose selector derives from neither EXEC nor a compare (a
constant, a number built from scalars) stopped with "a select on an
untracked mask". In compute the lane can test its own bit of such a mask
by its console lane, as guards on such masks already do: the select now
takes the lane's bit from the structure's other masks, and a program
with such a select declares the console's wave size like the ones that
guard on them. Other stages are unchanged.

The high dword of a wave64 mask held as a number was found only when one
instruction wrote both dwords; written by two (s_mov_b32 each), lanes 32
to 63 tested the low dword's bits. The structure pass now records the
pair a mask's reader takes, and that is used where no single writer
exists. This applied to guards on such masks too.

Test (hand-assembled, each lane checked on an RTX 5070 and a Radeon
iGPU): a select on a mask of two constants and on one with a bit that
depends on the group, as a wave64 and as a wave32 program, in groups of
64 and 32 threads.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A loop-carried EXEC phi can depend on a latch phi that is not otherwise used. Discover deferred inputs before emitting mask phis, including inputs discovered while walking the deferred worklist. Extend the authored lane-read loop fixture by adding a second predecessor of the latch.
The test of the commit before dispatched on WARP only, which has no
32-lane waves, so it checked emission alone. It now runs like the other
lane-read loop test: emitted for each hardware adapter's waves,
validated, dispatched, and every lane compared (lane t stores t + 40).
Exact on an RTX 5070 (two 32-lane waves) and a Radeon iGPU; without the
structure change it stops with "a lane-mask join of an untracked mask".

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…d masks

Two defects found with a contributor's fixture (a waterfall loop over
lane classes with a whole-wave section inside, reported on Marvisak#439).

A mask copied dword by dword (EXEC restored with two s_mov_b32) is held
as a number, and that number is known only as the mask's own dword. In
the console flow the lowering followed that in a circle until the stack
ran out, which takes the process with it. It now stops with "an opaque
lane mask".

On a host that runs the console's wave size, a program with a lane read
in a divergent branch took the console flow only if it had no whole-wave
section, so one with both stopped with "a lane mask holding lanes
elsewhere read as data" there while a 32-lane host ran it. The rule
counted the lane reads sections make themselves; it now looks for a lane
read or write outside the sections and lets sections be, which the
console flow lowers as wave operations like the per-lane form. Such
programs fall back to the per-lane form as before if the console flow
cannot lower them.

Tests (hand-assembled): a lane read in a branch beside a whole-wave sum,
each lane checked on an RTX 5070 and a Radeon iGPU; and a mask copied
dword by dword, which overflowed the stack before and stops now.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A compute program with a numeric select declared the console's wave size
whether or not anything read the select's result. On a host without
64-lane waves that refused a wave64 program in a group of more than 64
threads only for a select nothing consumes, where it translated before
selects on numeric masks were lowered.

The ordinary lowering now runs first. Only when it stops on a select
with an untracked mask is the program lowered again with numeric selects
counted among the masks held as numbers.

From r4tedx#5 (MichaelSmithAI). Picked onto shader/console-flow-lds
by r4.: the selector scan iterates every instruction here (the tester
tree's `live()` filter is another PR's), and the new lines are formatted
for this crate.
The in-half form cannot read the high word of a numeric mask. Let an unused select drop out and use the existing full-wave retry when its result is needed. Exercise both cases alongside a live swizzle and DPP read.
Keep the host wave target and console-flow lowering while bringing in per-lane waterfall resource tracking. Use the structured program for resource tracking in translation and tests, and prefer proved per-lane descriptor reads before the general console read-first-lane path.
…hosts

A wave64 program that needs its whole wave ran in the console flow only
in groups of one console wave: its halves meet at group barriers, and
console waves of a bigger group branch differently, so they reach
different barriers. Now group barriers are counted, not placed: each
thread counts the barriers it passed, the halves of a console wave reach
their exchanges at the same count, the program's s_barrier waits until
every half has arrived (or ended), and a thread that ends keeps passing
barriers until every half has ended. What must agree is decided from
stamps written before a barrier and read after it.

GPU tests (RTX 4050, split; AMD iGPU native): lane reads in groups of
128 and 256, console waves taking different branches, loops of different
lengths, and LDS ordered by s_barrier between console waves.
@matheusfermiano-source

Copy link
Copy Markdown

An AMD run under Proton on Linux: Radeon 660M (RDNA2, RADV Mesa 26.3.1, waves 32..64), head b3efa1c.

Built on Linux with llvm-mingw for x86_64-pc-windows-gnullvm (Rust 1.98.1); dxil.dll from DXC 1.9.2609 was loaded. Synthetic tests only, no game files. AI-assisted (Claude Code, Opus 5.5); every run was on this machine.

@Zmirzz

Zmirzz commented Nov 24, 2026

Copy link
Copy Markdown

Whole-corpus translate with pipeline creation on a 32-lane host, for this PR's head b3efa1c (so with #439, #320, #233 and #223 under it).

Host: NVIDIA GeForce RTX 5060, Windows 11 (host waves 32-32 lanes).
Input: all 26,503 shaders.rpf containers of my own copy (614 duplicates skipped, 2,582 compute programs), victory translate <dir> --pipelines, release build.

Build Compute emitted Compute pipelines created
main at ffe310e 1,441 1,121 (320 refused: The parameter is incorrect., i.e. WaveSize(64))
this PR, b3efa1c 1,458 1,458 (none refused)

Vertex/pixel (12,231) and mesh (8,214) pipelines are the same on both.

On main the 320 refused programs include passes that matter for the world's lighting: tiled_lighting (MaterialTiles, ShadowRevealTiles, ClusterLightsWorldSpace), shadowmask (GenerateShadowMasks*, DenoiseShadowMask*), cascadeshadows_rendering / _classify / _processing, depth_pyramid, deferred_tiled_CS_DepthProcessing*, ambient_map_CS_AmbientMapSky*, TAA resolves and the im_CS_Texture2D*Mipmap* generators. With this PR none of them fails for a wave reason. Among those families, what still fails here is not wave-related: resources: an address not from a root parameter (TraceShadowRays_*, sr_tracing_CS_RaytraceVBuffer_*), a descriptor read only as data, an LDS write of bytes or halves (DenoiseShadowMaskLDS*, TAA2_PrepareFrameStats), v_permlanex16_b32 (deferred_tiled_CS_WaterTransmittanceOpticalDepthProcessing).

Remaining wave-related failures over the whole corpus: 4 × a whole-wave section of a wave64 on a host without 64-lane waves, 2 × console wave64 lanes in a group of more than 64 threads on a host without 64-lane waves.

Not validated with dxil.dll (no --validate in this run), and no title run yet; I'll report back if I get one.

@sinan-cmyk

Copy link
Copy Markdown

Offline measurement on a retail dump, and the shader tests on Ada

Result: +12 programs over main, 0 lost.

Offline. I merged head b3efa1c onto main ffe310e (clean merge) and ran victory translate --validate --list on shaders.rpf (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with main program by program (25,889 programs). Validated: 21,724 on main, 21,736 with this PR.

Failure on main Gained
emit: an LDS operation 4
emit: a select on an untracked mask 3
emit: a lane mask holding lanes elsewhere read as data 2
emit: a lane-mask join of an untracked mask 2
emit: LDS the program does not allocate 1

Of the 12, 5 are among the programs that #1402 gains and 7 are new. It also moves 658 programs that keep failing on to later reasons: 220 from "a lane mask holding lanes elsewhere read as data" and 205 from "a select on an untracked mask" go on to "a descriptor read only as data", which #1067 (inside #1402) handles. #1423 showed the same pattern and gained +214 on top of #1402, so I'm measuring this PR stacked on #1402 too.

Tests: with the same merge, cargo test --locked -p victory-shader --lib passed 163, failed 0. The bitcode benchmark is ignored, as on main, where 120 pass. The run was on an RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter, with VICTORY_WARP unset.

No shader names or data are included, per the asset policy. AI-assisted (Claude Code).

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Needs rebase. This pull request conflicts with main (conflicting: apps/victory/src/main.rs, apps/victory/src/translate.rs, crates/victory-gpu/src/host.rs, crates/victory-gpu/src/pipeline.rs, crates/victory-gpu/src/shader_cache.rs). It will be reviewed once it is rebased onto the current main.


Generated by Claude Code

@r4tedx

r4tedx commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

@anasssssssss1, I read this against the multi-wave branch on our fork (shader/wave-per-group, stacked on #439 too), since both take the groups #439 stops with console wave64 lanes in a group of more than 64 threads. One structural problem first, then the numbers.

Group barriers in group-divergent control flow. Pairing barriers by count keeps every half of a console wave on the same branches, but the console waves of one group branch independently, and both the exchange barriers and the drain loop then sit on different paths for different threads of the same host group. A minimal case, a 128-thread wave64 group (two console waves) for a 32-lane host:

v_cmp_gt_u32   vcc, 20, v0        ; only console wave 0 has lanes below 20
s_cbranch_vccz end                ; console wave 1 ends here
v_readlane_b32 s9, v0, 40
s_barrier
s_barrier
v_mov_b32      v2, s9
...
end: s_endpgm

Words: 7D880094 BF860006 D7600009 00015100 BF8A0000 BF8A0000 7E040209 BF820001 BF810000, through emit::split_tests's program(body, 128) and Target { lanes_min: 32, lanes_max: 32 } at b3efa1c. The module validates with dxil.dll. In it, the branch on console wave 0's ballot (br i1 %45, label %175, label %46) leads one way to five dx.op.barrier(80, 11) call sites (the exchange and the two waits) and the other way to a loop around a different dx.op.barrier call (the drain). So within one thread group, threads of wave 0 and wave 1 execute barrier calls at different places in the program at the same time.

GroupMemoryBarrierWithGroupSync is defined only in control flow that is uniform across the thread group; the validator does not check that dynamically. The hardware barriers underneath count arrivals, which is what the scheme relies on, and that may well work on a given card, but nothing in D3D12 promises it, and a driver compiler is entitled to assume the barrier is reached uniformly (move it, merge it, or treat the code around it as convergent). Two more points from reading it: each wait loop exits on waveAllTrue per host wave (wait_for_halves), so different waves of one group can leave it after different numbers of barrier calls; the drain and the waits have no iteration bound of their own (the 2^20 loop guard sends a long loop into the same unbounded drain), and the arrival stamp shares bits with the count from phase 2^30. I have not run it on a GPU: the 32-lane card here is off limits for barrier-heavy tests after a hard freeze, so I can say it is undefined, not that it hangs.

The form on our branch avoids the question for groups that share no LDS and have no s_barrier: each host group is one console wave (64 threads, the dispatch's x multiplied by the waves per group, indirect dispatches through a list-owned rewrite of the records), so the console flow's barriers stay uniform within each host group. It cannot take groups whose waves meet at s_barrier or share LDS; that is the part this PR is aiming at.

Coverage, offline (local title data, CPU only, counts and hashes only; translate --host-lanes 32-32 --validate over the shader pack, against #439 at the same translator):

compute emitted / validated of the 43 stopped for group size
#439 1,420 / 1,385 43 stopped
our branch c734600 1,443 / 1,408 20 validated, 3 to a section step
this PR b3efa1c 1,458 / 1,423 38 validated, 3 to a section step, 2 left (32 KiB of LDS before the bookkeeping)

No program that validated on #439 is lost with either. So this PR takes 18 more programs, all with LDS and s_barrier, and those are exactly the ones whose barriers the problem above affects.

What I would suggest. Keep the one-host-group-per-console-wave form for groups without LDS and barriers (it needs no cross-wave synchronisation at all), and use count-paired barriers only for groups that need them, once every barrier call sits where the whole group reaches it: for example, every thread of the group running every block that any console wave of the group enters, with each wave's effects guarded by whether that wave is really there (the "group-wide form" in docs/wave64-on-wave32.md on #439), so the exchanges and waits are the same calls for all threads. Then exact readbacks against independently computed results for early ends, repeated barriers, unequal loops and LDS visibility across waves, and runs on several 32-lane drivers under occupancy pressure. I am glad to compare that on the same pack.

The counts and the module above come from an AI agent's offline run (Codex), checked by me; the disassembly is reproducible from the words above. AI-assisted (Claude Code).

@anasssssssss1

Copy link
Copy Markdown
Author

@r4tedx, thanks. The structural point is right. Count-paired barriers keep the two halves of a console wave together, but two console waves of one group can still reach dx.op.barrier from different call sites. D3D12 leaves that undefined, even if it works on the cards it was tried on (the RTX 5060 run above and my 4050). I'm marking this as a draft until it's reworked.

The rework follows what you suggest:

  • Groups without LDS and without s_barrier use the one-host-group-per-console-wave form, so no cross-wave synchronisation is needed.
  • Groups with LDS or barriers use a group-wide form. Each scalar branch, and each loop back edge, goes where any console wave of the group goes. A wave that isn't on that path runs with its exec mask cleared and its scalar writes masked off. Every dx.op.barrier then sits on a group-uniform path, and the drain loop goes away. A wave that has ended stays "absent" until s_endpgm, so the barrier count is the same for every thread by construction, not by counting.
  • Waits and stamps: the per-wave waveAllTrue exits and the arrival stamps go away with this form. That fixes the bit-sharing from phase 2^30 and the unbounded loops along with them.

For tests, I'll add readbacks checked against independently computed results for your case (words above), early ends, repeated barriers, unequal loop counts and LDS visibility across waves. I'll also rebase onto current main. Once it's up, I'll ask for the comparison on the pack.

@anasssssssss1

Copy link
Copy Markdown
Author

Moved to #2214 (same commit, now from my other account, shawshanker18). The review above is carried over there, and the rework will land on #2214.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.