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

Closed
anasssssssss1 wants to merge 47 commits from upstream-pr/1433 into main
anasssssssss1 commented 2026-11-24 17:58:11 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by anasssssssss1 on 2026-11-24T17:58:11Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6588132848 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1433). Originally posted by [anasssssssss1](https://github.com/anasssssssss1) on 2026-11-24T17:58:11Z. --- 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.
matheusfermiano-source commented 2026-11-24 19:04:11 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by matheusfermiano-source on 2026-11-24T18:21:34Z.


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

  • With vkd3d-proton 3.2.0 (GE-Proton11-14, cae8353): the whole victory-shader suite gives 162 passed, 1 failed, 1 ignored. Both lane_read_loop_tests are exact in wave32 and wave64. The failure is emit::tests::stub_pipeline_is_created, which fails on main here too: vkd3d-proton accepts a zeroed DXIL hash (see #1218).
  • With Proton Experimental's current vkd3d-proton 3.1.0 (cae2e003): lane_read_loop_with_a_joined_exec_back_edge kills the test process with no test result. dxil-spirv logs Failed to find a common merge point, then vkCreateComputePipelines faults inside RADV (0xc0000005). #439's head 28aca3b, which has the same test, does the same. With 3.2.0 both pass, so this is the vkd3d-proton structurizer problem discussed in #144, not this PR. For anyone testing these branches on Linux: use vkd3d-proton 3.2, or the run stops at this test.
  • RTX 3050 Laptop (NVIDIA 620.73.04, waves 32..32), with 3.1.0: both lane-read loop tests are exact, and dxil-spirv logs no warning.

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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7140532331 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1433#issuecomment-7140532331). Originally posted by [matheusfermiano-source](https://github.com/matheusfermiano-source) on 2026-11-24T18:21:34Z. --- An AMD run under Proton on Linux: Radeon 660M (RDNA2, RADV Mesa 26.3.1, waves 32..64), head `b3efa1c`. - **With vkd3d-proton 3.2.0** (GE-Proton11-14, `cae8353`): the whole `victory-shader` suite gives 162 passed, 1 failed, 1 ignored. Both `lane_read_loop_tests` are exact in wave32 and wave64. The failure is `emit::tests::stub_pipeline_is_created`, which fails on `main` here too: vkd3d-proton accepts a zeroed DXIL hash (see #1218). - **With Proton Experimental's current vkd3d-proton 3.1.0** (`cae2e003`): `lane_read_loop_with_a_joined_exec_back_edge` kills the test process with no test result. dxil-spirv logs `Failed to find a common merge point`, then `vkCreateComputePipelines` faults inside RADV (0xc0000005). #439's head `28aca3b`, which has the same test, does the same. With 3.2.0 both pass, so this is the vkd3d-proton structurizer problem discussed in #144, not this PR. For anyone testing these branches on Linux: use vkd3d-proton 3.2, or the run stops at this test. - **RTX 3050 Laptop** (NVIDIA 620.73.04, waves 32..32), with 3.1.0: both lane-read loop tests are exact, and dxil-spirv logs no warning. 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 commented 2026-11-24 20:03:16 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Zmirzz on 2026-11-24T19:41:09Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7142445623 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1433#issuecomment-7142445623). Originally posted by [Zmirzz](https://github.com/Zmirzz) on 2026-11-24T19:41:09Z. --- 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 commented 2026-11-24 21:03:38 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by sinan-cmyk on 2026-11-24T20:43:58Z.


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).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7143982406 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1433#issuecomment-7143982406). Originally posted by [sinan-cmyk](https://github.com/sinan-cmyk) on 2026-11-24T20:43:58Z. --- ### 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).
Marvisak commented 2026-11-25 02:06:05 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T01:27:59Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7149577064 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1433#issuecomment-7149577064). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T01:27:59Z. --- <!-- victory-triage v1 head=b3efa1c0e3b7848cdc45d071972c4bfde83627aa verdict=needs-rebase at=2026-11-25T01:27:57Z --> 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](https://claude.ai/code)_
r4tedx commented 2026-11-25 06:02:50 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by r4tedx on 2026-11-25T05:45:09Z.


@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).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7154104516 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1433#issuecomment-7154104516). Originally posted by [r4tedx](https://github.com/r4tedx) on 2026-11-25T05:45:09Z. --- @anasssssssss1, I read this against the multi-wave branch on our fork ([`shader/wave-per-group`](https://github.com/r4tedx/VIctory/tree/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).
upstream-sync closed this pull request 2026-11-25 08:05:29 +00:00
anasssssssss1 commented 2026-11-25 08:06:43 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by anasssssssss1 on 2026-11-25T07:51:31Z.


@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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7156330778 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1433#issuecomment-7156330778). Originally posted by [anasssssssss1](https://github.com/anasssssssss1) on 2026-11-25T07:51:31Z. --- @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 commented 2026-11-25 08:06:45 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by anasssssssss1 on 2026-11-25T08:04:31Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7156576423 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1433#issuecomment-7156576423). Originally posted by [anasssssssss1](https://github.com/anasssssssss1) on 2026-11-25T08:04:31Z. --- 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.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
Marvisak/VIctory!1432
No description provided.