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

Merged
tiagonogueiraa-bit merged 1 commit from upstream-pr/368 into main 2026-11-27 16:04:48 +00:00
tiagonogueiraa-bit commented 2026-11-27 14:25:05 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by tiagonogueiraa-bit on 2026-11-27T14:25:05Z.


Refs #367

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.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:5528238464 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/368). Originally posted by [tiagonogueiraa-bit](https://github.com/tiagonogueiraa-bit) on 2026-11-27T14:25:05Z. --- Refs #367 **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.
LakshanSivakumar commented 2026-11-27 16:05:15 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T16:05:15Z.


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.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7222839732 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/368#issuecomment-7222839732). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-27T16:05:15Z. --- 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.
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
LakshanSivakumar/Native-Victory-macOS!368
No description provided.