shader: lower a whole-wave f16 sum across the host's two waves (#367) #371

Manually merged
github merged 1 commit from github-bot/gh-368 into main 2026-11-27 16:13:15 +00:00 AGit
Owner

@⁠tiagonogueiraa-bit on GitHub · 2026-11-27 14:25 UTC · original
tiagonogueiraa-bit:shader-half-reduction-halves → main · +82 −3 · 3 files · 1 commits · merged 2026-11-27 16:04 UTC

Refs #370

Shape. In wave64 compute shaders the host splits into two 32-lane waves (groups of more than 64 threads), a whole-wave v_add_f16 sum read at lane 63 was refused as "a 16-bit wave reduction across the host's waves". The sum is built from row butterflies, v_permlanex16_b32 of lane 0, and lane 0 added in. Shape::Half (low halves summed, high half from one console lane hi) was lowered only when a console wave is one host wave.

Change. When self.halves is set:

  • each host wave's f32 sum (waveActiveOp.f32) is combined across the pair with halves_reduce(Op::AddF, ..), as other float sums are, then rounded to f16 once, as before;
  • lane hi's value is read with wide_read_lane.

That exchange reads 0 for a lane that wrote nothing, but a lane elsewhere must give the identity, so it carries x ^ ident and is XORed back. The single-host-wave path is unchanged.

By-output corpus sweep. 12,020 containers from my own boot-to-menus run (Series S), native host options, main 905e7aa against this head:

Stage Gained Lost Changed Other reason now
compute 2 0 0 0
pixel 0 0 0 0
vertex 0 0 0 0

Gained: c943990185ea8740, d98422fd516b6e44.

Test. split_wave_tests::a_whole_wave_half_sum_reads_across_the_host_waves (victory-gpu, on Metal with MSC 4.0 beta 3) runs the title's form in groups of 128 threads, so the fast path splits each wave. Each lane's term is i & 3 as an f16, with 0x1234 in the high half.

  • Every lane of each wave reads 0x12345600: 96.0 under lane 63's high half.
  • With lanes 40 and up off before the section, lanes 0 to 39 read 0x00005380 (60.0, and lane 63 is off, so the identity's high half), and the rest store nothing.

On main, refusal() gives the old message.

Checks.

  • cargo test -p victory-shader -p victory-hle -p victory -p victory-gpu -p victory-metal -p xtask: 955 passed, 0 failed, 10 ignored.
  • Windows clippy -D warnings: clean.
  • cargo xtask policy: ok.

docs/native-host.md (whole-wave sections) describes it. @⁠Olima34, for the board.

**@⁠tiagonogueiraa-bit** on GitHub · 2026-11-27 14:25 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/368) `tiagonogueiraa-bit:shader-half-reduction-halves` → `main` · +82 −3 · 3 files · 1 commits · merged 2026-11-27 16:04 UTC Refs #370 **Shape.** In wave64 compute shaders the host splits into two 32-lane waves (groups of more than 64 threads), a whole-wave `v_add_f16` sum read at lane 63 was refused as "a 16-bit wave reduction across the host's waves". The sum is built from row butterflies, `v_permlanex16_b32` of lane 0, and lane 0 added in. `Shape::Half` (low halves summed, high half from one console lane `hi`) was lowered only when a console wave is one host wave. **Change.** When `self.halves` is set: - each host wave's f32 sum (`waveActiveOp.f32`) is combined across the pair with `halves_reduce(Op::AddF, ..)`, as other float sums are, then rounded to f16 once, as before; - lane `hi`'s value is read with `wide_read_lane`. That exchange reads 0 for a lane that wrote nothing, but a lane elsewhere must give the identity, so it carries `x ^ ident` and is XORed back. The single-host-wave path is unchanged. **By-output corpus sweep.** 12,020 containers from my own boot-to-menus run (Series S), native host options, main `905e7aa` against this head: | Stage | Gained | Lost | Changed | Other reason now | |---|---|---|---|---| | compute | 2 | 0 | 0 | 0 | | pixel | 0 | 0 | 0 | 0 | | vertex | 0 | 0 | 0 | 0 | Gained: `c943990185ea8740`, `d98422fd516b6e44`. **Test.** `split_wave_tests::a_whole_wave_half_sum_reads_across_the_host_waves` (`victory-gpu`, on Metal with MSC 4.0 beta 3) runs the title's form in groups of 128 threads, so the fast path splits each wave. Each lane's term is `i & 3` as an f16, with `0x1234` in the high half. - Every lane of each wave reads `0x12345600`: 96.0 under lane 63's high half. - With lanes 40 and up off before the section, lanes 0 to 39 read `0x00005380` (60.0, and lane 63 is off, so the identity's high half), and the rest store nothing. On main, `refusal()` gives the old message. **Checks.** - `cargo test -p victory-shader -p victory-hle -p victory -p victory-gpu -p victory-metal -p xtask`: 955 passed, 0 failed, 10 ignored. - Windows clippy `-D warnings`: clean. - `cargo xtask policy`: ok. `docs/native-host.md` (whole-wave sections) describes it. @⁠Olima34, for the board.
A whole-wave v_add_f16 sum (Shape::Half) was lowered only where a
console wave is one host wave, and refused where the host splits it.
Now each host wave's f32 sum is combined across the pair with
halves_reduce, as other float sums are, then rounded to f16 once. The
lane giving the high half is read with wide_read_lane. That exchange
reads 0 for a lane that wrote nothing, but a lane elsewhere must give
the identity, so it carries x ^ ident.

Corpus sweep (12,020 shaders, main 905e7aa): 2 compute shaders gained,
no regressions, no changed outputs.

Refs #367
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 14:28:34 +00:00
github manually merged commit c80f5cc552 into main 2026-11-27 16:13:15 +00:00
Author
Owner

@⁠LakshanSivakumar on GitHub · 2026-11-27 16:05 UTC · original

Merged in be7dc1b5 with the other shader PRs from tonight. Ran the tests (native arm64), Windows clippy, the policy check and a release build on the merged tree, and swept my full corpus of 21,600 shaders before and after: 0 lost, 352 newly translated, every changed output accounted for. I have not run the game on it yet. Thanks.

**@⁠LakshanSivakumar** on GitHub · 2026-11-27 16:05 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/368#issuecomment-7222839732) Merged in be7dc1b5 with the other shader PRs from tonight. Ran the tests (native arm64), Windows clippy, the policy check and a release build on the merged tree, and swept my full corpus of 21,600 shaders before and after: 0 lost, 352 newly translated, every changed output accounted for. I have not run the game on it yet. Thanks.
github-bot referenced this pull request from a commit 2026-11-27 16:23:10 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.