shader: paired lanes for compute groups of several console waves (#527) #545

Closed
github-bot wants to merge 2 commits from github-bot/gh-541 into main AGit
Owner

@⁠marcus-4 on GitHub · 2026-11-28 02:01 UTC · original
marcus-4:feat/paired-lanes → main · +813 −33 · 12 files · 2 commits · closed without merging

Refs #531
Refs #379

This is the paired-lanes route that #531 names as the alternative to if-conversion. It is behind VICTORY_PAIRED_WAVES=1 (Options::paired_waves, off by default, part of the shader cache key), so nothing changes with the switch unset.

What it does

A wave64 compute program that the fast path refuses, whose group is several console waves and a multiple of 64 threads (the 128 and 256 of #531), is retried in lockstep in a paired form (emit/lower/paired.rs):

  • One host wave per console wave. Each host thread holds console lanes n and n + 32, and the host group is half the console's. Thread ids, lane indices and v_mbcnt are remapped (paired_console_flat).
  • Nothing crosses host waves. A lane mask's number is the host ballot of the lower lanes (bits 0-31) and of the upper lanes (bits 32-63) (paired_ballot). v_readlane_b32 and v_readfirstlane_b32 read the lower or upper value of host lane k & 31 (paired_cross). So a whole-wave vote used as a branch, the shape of #531, is the same in every thread of that console wave. There is no exchange and no barrier of our own: the title's s_barrier is the group barrier. A barrier the waves may reach unevenly is refused, as before.
  • Two lanes, one lowering. The lowering keeps a second copy of its per-lane state (Twin), swapped per lane. Vector instructions are lowered once per lane, scalar ones once and mirrored.

The design is TaynanGT/Vice-Tay's paired lanes, lowered our own way. It replaces #442's spinning pair barrier, which hung the GPU once more groups were dispatched than could run at once.

Tests (victory-gpu, Metal, split_wave_tests)

  • The two shapes from #531, each under an EXEC skip in a group of four console waves whose halves vote differently:

    • s_bcnt1_i32_b64 s6, vcc then s_cbranch_scc0
    • s_and_b64 vcc, exec, s[4:5] then s_cbranch_vccz

    Both are refused on the fast path with "a cross-lane operation between host waves in divergent code", and both give each console wave's whole-wave result with the switch on. This is the "two-wave group where the halves vote differently" test that #531 asks for.

  • Lane reads in groups of two and four waves, each with a different EXEC.

  • A per-wave loop sharing LDS, with different trip counts.

  • Whole-wave prefix sums behind branches that each wave takes differently, including the eee76bf6 shape (#258).

  • A title barrier in a divergent loop, which is refused.

  • Guards: the fast-path ballot case is unchanged, and the switch-off refusal stays.

  • Scale: paired_lanes_at_the_scale_of_a_world_dispatch runs 4,096 groups of four waves in 5.5 ms on an M1 Pro, against 5.1 ms for one-wave groups. paired_lanes_by_group_count (ignored, a measurement) is right at every count from 1 to 1,024.

Checked locally (M1 Pro, macOS 27.2): clippy for x86_64-pc-windows-gnullvm with -D warnings, cargo xtask policy, and the arm64 tests of all 11 crates pass. The x86_64 tests of victory-hle/loader/victory also pass, apart from dsp::tests::dump_captures_the_titles_ir_blocks_and_output, which fails only under parallel load and on main too, and passes alone.

Checked by a tester

alexballvideos-netizen ran a sweep and game runs on an M3 Max, Series X, with this PR merged onto main 61f55a49 (report):

  • Corpus sweep (21,579 shaders):
    • Switch off: nothing changes against main.
    • Switch on: 10 compute programs gained, eee76bf6 among them. None lost and no other output changed.
    • With the switch on, no shader is still refused for "a cross-lane operation between host waves in divergent code".
  • Game runs (two headless 330 s runs):
    • That refusal went from 12 to 0.
    • eee76bf6, 08b62ac5 and ab95b63f ran.
    • Neither run had a GPU time-out or a page fault.

--example sweep now reads VICTORY_PAIRED_WAVES (f493ea07), so the sweep needs no local edit.

Still open

  • Whether the four ray-traced passes then dispatch real work. Neither trace window caught them.
  • The picture. It is still dark in both modes, and the two runs reached different shots.
**@⁠marcus-4** on GitHub · 2026-11-28 02:01 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/541) `marcus-4:feat/paired-lanes` → `main` · +813 −33 · 12 files · 2 commits · closed without merging Refs #531 Refs #379 This is the paired-lanes route that #531 names as the alternative to if-conversion. It is behind `VICTORY_PAIRED_WAVES=1` (`Options::paired_waves`, off by default, part of the shader cache key), so nothing changes with the switch unset. ## What it does A wave64 compute program that the fast path refuses, whose group is several console waves and a multiple of 64 threads (the 128 and 256 of #531), is retried in lockstep in a paired form (`emit/lower/paired.rs`): - **One host wave per console wave.** Each host thread holds console lanes `n` and `n + 32`, and the host group is half the console's. Thread ids, lane indices and `v_mbcnt` are remapped (`paired_console_flat`). - **Nothing crosses host waves.** A lane mask's number is the host ballot of the lower lanes (bits 0-31) and of the upper lanes (bits 32-63) (`paired_ballot`). `v_readlane_b32` and `v_readfirstlane_b32` read the lower or upper value of host lane `k & 31` (`paired_cross`). So a whole-wave vote used as a branch, the shape of #531, is the same in every thread of that console wave. There is no exchange and no barrier of our own: the title's `s_barrier` is the group barrier. A barrier the waves may reach unevenly is refused, as before. - **Two lanes, one lowering.** The lowering keeps a second copy of its per-lane state (`Twin`), swapped per lane. Vector instructions are lowered once per lane, scalar ones once and mirrored. The design is TaynanGT/Vice-Tay's paired lanes, lowered our own way. It replaces #442's spinning pair barrier, which hung the GPU once more groups were dispatched than could run at once. ## Tests (victory-gpu, Metal, `split_wave_tests`) - The two shapes from #531, each under an EXEC skip in a group of four console waves whose halves vote differently: - `s_bcnt1_i32_b64 s6, vcc` then `s_cbranch_scc0` - `s_and_b64 vcc, exec, s[4:5]` then `s_cbranch_vccz` Both are refused on the fast path with "a cross-lane operation between host waves in divergent code", and both give each console wave's whole-wave result with the switch on. This is the "two-wave group where the halves vote differently" test that #531 asks for. - Lane reads in groups of two and four waves, each with a different EXEC. - A per-wave loop sharing LDS, with different trip counts. - Whole-wave prefix sums behind branches that each wave takes differently, including the `eee76bf6` shape (#258). - A title barrier in a divergent loop, which is refused. - Guards: the fast-path ballot case is unchanged, and the switch-off refusal stays. - Scale: `paired_lanes_at_the_scale_of_a_world_dispatch` runs 4,096 groups of four waves in 5.5 ms on an M1 Pro, against 5.1 ms for one-wave groups. `paired_lanes_by_group_count` (ignored, a measurement) is right at every count from 1 to 1,024. Checked locally (M1 Pro, macOS 27.2): clippy for `x86_64-pc-windows-gnullvm` with `-D warnings`, `cargo xtask policy`, and the arm64 tests of all 11 crates pass. The x86_64 tests of victory-hle/loader/victory also pass, apart from `dsp::tests::dump_captures_the_titles_ir_blocks_and_output`, which fails only under parallel load and on main too, and passes alone. ## Checked by a tester alexballvideos-netizen ran a sweep and game runs on an M3 Max, Series X, with this PR merged onto `main` `61f55a49` ([report](https://git.gtahub.st/github/LakshanSivakumar--Native-Victory-macOS/pulls/545)): - **Corpus sweep** (21,579 shaders): - Switch off: nothing changes against `main`. - Switch on: 10 compute programs gained, `eee76bf6` among them. None lost and no other output changed. - With the switch on, no shader is still refused for "a cross-lane operation between host waves in divergent code". - **Game runs** (two headless 330 s runs): - That refusal went from 12 to 0. - `eee76bf6`, `08b62ac5` and `ab95b63f` ran. - Neither run had a GPU time-out or a page fault. `--example sweep` now reads `VICTORY_PAIRED_WAVES` (f493ea07), so the sweep needs no local edit. ## Still open - Whether the four ray-traced passes then dispatch real work. Neither trace window caught them. - The picture. It is still dark in both modes, and the two runs reached different shots.
A wave64 compute program the fast path refuses, whose group is several
console waves and a multiple of 64 threads, is retried in lockstep in a
paired form behind VICTORY_PAIRED_WAVES=1 (Options::paired_waves, off by
default): one host wave per console wave, each host thread holding
console lanes n and n + 32. Votes, lane reads and first-lane reads stay
inside one host wave, so nothing crosses host waves and no barrier of
our own is needed; the title's s_barrier is the group barrier.

The design follows TaynanGT/Vice-Tay's paired lanes, lowered our own
way in emit/lower/paired.rs (a second copy of the per-lane state,
swapped per lane). It replaces #438's spinning pair barrier, which hung
the GPU once more groups were dispatched than run at once.

Tests (victory-gpu, Metal): lane reads in groups of two and four waves,
per-wave loops sharing LDS, whole-wave prefix sums behind branches each
wave takes differently (the shape of eee76bf6), the two vote shapes of
#527 under an EXEC skip, a title barrier refused in a divergent loop,
and a world-scale run (4,096 groups of four waves, 5.5 ms on an M1 Pro).

Refs #527
Refs #376
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-28 02:04:56 +00:00
Author
Owner

@⁠alexballvideos-netizen on GitHub · 2026-11-28 03:23 UTC · original

Check report: a corpus sweep and game runs. M3 Max 36 GB, macOS 27.2, Series X. Tested as this PR merged onto main 61f55a49 (local merge 101fd2d1, no conflicts). Counts and ids only.

Corpus sweep (21,579 shaders registered by the game). The sweep example doesn't read the switch, so I passed paired_waves through from VICTORY_PAIRED_WAVES in a local, uncommitted edit:

gained lost output changed
switch off vs main 0 0 0
switch on vs main 10 (all compute) 0 0
  • Gained: eee76bf6265f33bb, 22bac47e3a8446f9, 00fc302d8e70d1b6, 08b62ac5ce40cceb, 17d6c48bac0751f3, 61a6c35cf9a06a5a, 67a13ba4cde171c6, ab95b63f73b77253, d3ada4dfc4a06127, e265a8356ad6125c.
  • With the switch on, no shader in the corpus is still refused as "a cross-lane operation between host waves in divergent code".
  • 836 refused shaders show a different number in the sweep's last column, but each has the same refusal reason at the same address, with the switch on or off.

Game runs (headless, 330 s caps, VICTORY_DEPTH_TWINS=0 VICTORY_TRACE_TARGETS=1, one run per mode):

divergent cross-lane refusals eee76bf6 GPU time-outs / page faults frames reached
switch off 12 refused, its dispatches dropped 0 / 0 2,048
switch on 0 runs 0 / 0 2,624
  • Both runs ended on the usual image+0x55e56f8 exception that main runs hit too.
  • In game, with the switch on, eee76bf6, 08b62ac5 and ab95b63f translate and run.
  • Comparing the shaders each run refused: the ones that differ do so for unrelated reasons (lane-mask joins, descriptor dwords read as data, a mesh/fragment type mismatch). That's the two runs reaching different shots, not the switch. Nothing is refused because of it.
  • The pipelines of the four ray-traced passes (0af6bb55, 52f01bcb, 67662685, caa50df7) are bound in both modes.

Not established:

  • Whether the ray-traced passes now dispatch real work. Two VICTORY_TRACE_PASSES windows (2 and 60 presents, starting at about 95–108 s) didn't catch eee76bf6 or those passes in either mode. Without the trace they're logged only rarely (the dropped eee76bf6 dispatch shows up twice in a whole switch-off run), so it seems they don't run every frame.
  • The picture. The lit scene and the final picture are still dark in both modes. The cutscene follows wall time, so the two runs reached different shots and the images can't be compared side by side.

No problem found with the switch on: the sweep shows no regressions and the game runs had no GPU errors. @⁠Olima34, this covers the sweep and game run you offered on #442, in case it saves you a run.

**@⁠alexballvideos-netizen** on GitHub · 2026-11-28 03:23 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/541#issuecomment-7233036876) Check report: a corpus sweep and game runs. M3 Max 36 GB, macOS 27.2, Series X. Tested as this PR merged onto `main` `61f55a49` (local merge `101fd2d1`, no conflicts). Counts and ids only. **Corpus sweep** (21,579 shaders registered by the game). The `sweep` example doesn't read the switch, so I passed `paired_waves` through from `VICTORY_PAIRED_WAVES` in a local, uncommitted edit: | | gained | lost | output changed | |---|---|---|---| | switch off vs `main` | 0 | 0 | 0 | | switch on vs `main` | 10 (all compute) | 0 | 0 | - **Gained:** `eee76bf6265f33bb`, `22bac47e3a8446f9`, `00fc302d8e70d1b6`, `08b62ac5ce40cceb`, `17d6c48bac0751f3`, `61a6c35cf9a06a5a`, `67a13ba4cde171c6`, `ab95b63f73b77253`, `d3ada4dfc4a06127`, `e265a8356ad6125c`. - With the switch on, **no** shader in the corpus is still refused as "a cross-lane operation between host waves in divergent code". - 836 refused shaders show a different number in the sweep's last column, but each has the same refusal reason at the same address, with the switch on or off. **Game runs** (headless, 330 s caps, `VICTORY_DEPTH_TWINS=0 VICTORY_TRACE_TARGETS=1`, one run per mode): | | divergent cross-lane refusals | `eee76bf6` | GPU time-outs / page faults | frames reached | |---|---|---|---|---| | switch off | 12 | refused, its dispatches dropped | 0 / 0 | 2,048 | | switch on | **0** | runs | 0 / 0 | 2,624 | - Both runs ended on the usual `image+0x55e56f8` exception that main runs hit too. - In game, with the switch on, `eee76bf6`, `08b62ac5` and `ab95b63f` translate and run. - Comparing the shaders each run refused: the ones that differ do so for unrelated reasons (lane-mask joins, descriptor dwords read as data, a mesh/fragment type mismatch). That's the two runs reaching different shots, not the switch. Nothing is refused because of it. - The pipelines of the four ray-traced passes (`0af6bb55`, `52f01bcb`, `67662685`, `caa50df7`) are bound in both modes. **Not established:** - **Whether the ray-traced passes now dispatch real work.** Two `VICTORY_TRACE_PASSES` windows (2 and 60 presents, starting at about 95–108 s) didn't catch `eee76bf6` or those passes in either mode. Without the trace they're logged only rarely (the dropped `eee76bf6` dispatch shows up twice in a whole switch-off run), so it seems they don't run every frame. - **The picture.** The lit scene and the final picture are still dark in both modes. The cutscene follows wall time, so the two runs reached different shots and the images can't be compared side by side. No problem found with the switch on: the sweep shows no regressions and the game runs had no GPU errors. @⁠Olima34, this covers the sweep and game run you offered on #442, in case it saves you a run.
A corpus sweep of the paired form needed a local edit to pass the switch
through. The sweep now reads it as the native host does. native-host.md
records the sweep and game runs alexballvideos-netizen reported on #541.

Refs #527
Author
Owner

@⁠marcus-4 on GitHub · 2026-11-28 03:38 UTC · original

Thank you, @⁠alexballvideos-netizen. That answers the open questions in this PR: 10 gained, none lost, no output changed, the divergent cross-lane refusal gone from the corpus and from the run, and no GPU errors with the switch on.

  • The sweep switch: fixed in f493ea07 on this branch, so the next sweep needs no local edit. --example sweep now reads VICTORY_PAIRED_WAVES the way the native host does. Your numbers are recorded in docs/native-host.md, under the paired-form section.
  • The ray-traced passes: agreed that it is open whether they now dispatch real work. If they really do not run every frame, a trace window that does not start at a fixed present might catch them, for example one opened by the first bind of eee76bf6. I have not built that.

This switch stays off by default, so merging it changes nothing until someone turns it on.

**@⁠marcus-4** on GitHub · 2026-11-28 03:38 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/541#issuecomment-7233238236) Thank you, @⁠alexballvideos-netizen. That answers the open questions in this PR: 10 gained, none lost, no output changed, the divergent cross-lane refusal gone from the corpus and from the run, and no GPU errors with the switch on. - **The sweep switch:** fixed in f493ea07 on this branch, so the next sweep needs no local edit. `--example sweep` now reads `VICTORY_PAIRED_WAVES` the way the native host does. Your numbers are recorded in `docs/native-host.md`, under the paired-form section. - **The ray-traced passes:** agreed that it is open whether they now dispatch real work. If they really do not run every frame, a trace window that does not start at a fixed present might catch them, for example one opened by the first bind of `eee76bf6`. I have not built that. This switch stays off by default, so merging it changes nothing until someone turns it on.
Author
Owner

@⁠alexballvideos-netizen on GitHub · 2026-11-28 06:52 UTC · original

Follow-up on the ray-traced passes, @⁠marcus-4. I built your first-bind window idea (#579 / #580, VICTORY_TRACE_PASSES_AFTER=<hash>,...) and used it to answer whether they run.

Headless runs, Series X, M3 Max, VICTORY_DEPTH_TWINS=0, window opened at the first dispatch of 0af6bb55 / 52f01bcb / 67662685 / caa50df7 after 20 world presents, 3 presents long:

main 2f4d81e0 main + #545, VICTORY_PAIRED_WAVES=1
eee76bf6 dropped ("a dispatch without a host compute pipeline", refused for the divergent cross-lane case) ran (2 PASS lines)
0af6bb55, 52f01bcb, 67662685, caa50df7 ran, 3 each (indirect) ran, 3 each
the R16_UINT 1280x720 target all four write (1.10) 0.0000 non-zero 0.6958 non-zero
eee76bf6's own outputs (R16_UINT 1280x720, R32_FLOAT 2560x1440) 0.0000 / 0.0050 0.8605 / 0.1156
run 0xc0000005 at image+0x55e56f8 after ~300 s full 420 s, no crash, no GPU error (one run)

So all four ray-traced passes, and the shaders that build the structures they walk, translate and run on main. Their output stays empty only because eee76bf6, which runs just before them, is dropped: it evidently produces what they trace (the passes are indirect dispatches whose counts are written on the GPU earlier in the frame). With #545 it runs and the ray-traced output fills in. That makes #545 more than a coverage gain: it is what turns the world's ray tracing on.

One more thing from the same window, not looked into: several 1280x720 and 2560x1440 R11G11B10 targets in the lit passes hold many non-finite texels (16k, 111k and 337k in three of them). Those could feed the dark, smeared lit picture.

The window, the hashes and the counts above are all I kept; no images.

**@⁠alexballvideos-netizen** on GitHub · 2026-11-28 06:52 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/541#issuecomment-7235574079) Follow-up on the ray-traced passes, @⁠marcus-4. I built your first-bind window idea (#579 / #580, `VICTORY_TRACE_PASSES_AFTER=<hash>,...`) and used it to answer whether they run. Headless runs, Series X, M3 Max, `VICTORY_DEPTH_TWINS=0`, window opened at the first dispatch of `0af6bb55` / `52f01bcb` / `67662685` / `caa50df7` after 20 world presents, 3 presents long: | | main `2f4d81e0` | main + #545, `VICTORY_PAIRED_WAVES=1` | |---|---|---| | `eee76bf6` | dropped ("a dispatch without a host compute pipeline", refused for the divergent cross-lane case) | **ran** (2 PASS lines) | | `0af6bb55`, `52f01bcb`, `67662685`, `caa50df7` | ran, 3 each (indirect) | ran, 3 each | | the R16_UINT 1280x720 target all four write (`1.10`) | **0.0000 non-zero** | **0.6958 non-zero** | | `eee76bf6`'s own outputs (R16_UINT 1280x720, R32_FLOAT 2560x1440) | 0.0000 / 0.0050 | 0.8605 / 0.1156 | | run | `0xc0000005` at `image+0x55e56f8` after ~300 s | full 420 s, no crash, no GPU error (one run) | So all four ray-traced passes, and the shaders that build the structures they walk, translate and run on main. Their output stays empty only because `eee76bf6`, which runs just before them, is dropped: it evidently produces what they trace (the passes are indirect dispatches whose counts are written on the GPU earlier in the frame). With #545 it runs and the ray-traced output fills in. That makes #545 more than a coverage gain: it is what turns the world's ray tracing on. One more thing from the same window, not looked into: several 1280x720 and 2560x1440 R11G11B10 targets in the lit passes hold many non-finite texels (16k, 111k and 337k in three of them). Those could feed the dark, smeared lit picture. The window, the hashes and the counts above are all I kept; no images.
github-bot closed this pull request 2026-11-28 08:20:38 +00:00
Author
Owner

@⁠marcus-4 on GitHub · 2026-11-28 08:13 UTC · original

Closing: this change is already in.

**@⁠marcus-4** on GitHub · 2026-11-28 08:13 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/541#issuecomment-7236445315) Closing: this change is already in.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.