fix(shader): lower single-lane and SALU-combined wave64 section reductions #262

Closed
Sheffy007 wants to merge 1 commit from upstream-pr/262 into main
Sheffy007 commented 2026-11-27 06:08:50 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Sheffy007 on 2026-11-27T06:08:50Z.


What this changes

Refs #258

  • Record per-lane uniform shapes (Section::lane_shapes) for whole-wave section VGPRs whose lanes do not all agree (for example wave64 reductions that combine the two 32-lane halves into lane 63 only) and evaluate constant-lane v_readlane_b32 reads of those lanes (Lower::section_lanes) at the section site while keeping reads of incomplete or non-constant lanes refused (NO_SHAPE).
  • Follow associative SALU combinations of disjoint reduction terms (s_add_u32/s_add_i32, s_min/s_max, s_or_b32/s_and_b32/s_xor_b32), constant-lane v_writelane_b32, and v_sub_co_u32 / v_subrev_* exclusive prefix differences in emit::wave (with unshaped carry-out masks recorded in Lower::lane_fail so reading v_sub_co_u32's carry outside the section refuses with NO_SHAPE).

How it was tested

  • split_wave_tests::wave64_lane63_writelane_and_salu_or_reductions_run_on_the_gpu (on Apple Silicon Metal GPU, 64-lane and 128-lane groups): verifies lane 63 after v_writelane_b32 + s_mov_b64 exec, 1 (sum(1..=64) = 2080, sum(65..=128) = 6176) and divergent s_or_b32 of v_readlane_b32 lanes 0 and 32 (0x0000_FFFF in wave 0, 0xFFFF_0000 in wave 1).
  • emit::wave::tests::wave64_single_lane_and_salu_reductions_lower_while_partial_lanes_stay_refused and per_lane_prefix_soundness.
  • Corpus comparison by output fingerprint (@Sandile-0511, 21,608 containers): +64 newly translated (52 pixel, 9 vertex, 3 compute; 2 in the world), 0 newly refused, 17 compute changed output (8 in the world: 1-wave compute shaders that previously fell back to emit::lockstep after hitting NO_SHAPE on the fast path and now lower directly through emit::wave), and 55 advance past NO_SHAPE to a later refusal.
  • cargo test -p victory-hle -p victory -p victory-gpu -p victory-metal -p victory-shader -p xtask, both x86_64-pc-windows-gnullvm clippy targets, and cargo xtask policy.
<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:5522111441 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/262). Originally posted by [Sheffy007](https://github.com/Sheffy007) on 2026-11-27T06:08:50Z. --- ## What this changes Refs #258 - Record per-lane uniform shapes (`Section::lane_shapes`) for whole-wave section VGPRs whose lanes do not all agree (for example wave64 reductions that combine the two 32-lane halves into lane 63 only) and evaluate constant-lane `v_readlane_b32` reads of those lanes (`Lower::section_lanes`) at the section site while keeping reads of incomplete or non-constant lanes refused (`NO_SHAPE`). - Follow associative SALU combinations of disjoint reduction terms (`s_add_u32`/`s_add_i32`, `s_min`/`s_max`, `s_or_b32`/`s_and_b32`/`s_xor_b32`), constant-lane `v_writelane_b32`, and `v_sub_co_u32` / `v_subrev_*` exclusive prefix differences in `emit::wave` (with unshaped carry-out masks recorded in `Lower::lane_fail` so reading `v_sub_co_u32`'s carry outside the section refuses with `NO_SHAPE`). ## How it was tested - `split_wave_tests::wave64_lane63_writelane_and_salu_or_reductions_run_on_the_gpu` (on Apple Silicon Metal GPU, 64-lane and 128-lane groups): verifies `lane 63` after `v_writelane_b32` + `s_mov_b64 exec, 1` (`sum(1..=64) = 2080`, `sum(65..=128) = 6176`) and divergent `s_or_b32` of `v_readlane_b32` lanes 0 and 32 (`0x0000_FFFF` in wave 0, `0xFFFF_0000` in wave 1). - `emit::wave::tests::wave64_single_lane_and_salu_reductions_lower_while_partial_lanes_stay_refused` and `per_lane_prefix_soundness`. - Corpus comparison by output fingerprint (@Sandile-0511, 21,608 containers): **+64 newly translated** (52 pixel, 9 vertex, 3 compute; 2 in the world), **0 newly refused**, **17 compute changed output** (8 in the world: 1-wave compute shaders that previously fell back to `emit::lockstep` after hitting `NO_SHAPE` on the fast path and now lower directly through `emit::wave`), and 55 advance past `NO_SHAPE` to a later refusal. - `cargo test -p victory-hle -p victory -p victory-gpu -p victory-metal -p victory-shader -p xtask`, both `x86_64-pc-windows-gnullvm` clippy targets, and `cargo xtask policy`.
LakshanSivakumar commented 2026-11-27 06:48:38 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T06:48:38Z.


Thank you. Reading single-lane results of a wave64 reduction is the right narrowing, and keeping lane 0 of a half reduction refused is the right test to have. Several things need work first.

  1. emit::wave::per_lane also changes k == ident to op.identity(k) for lane 0 of an exclusive prefix. The text does not mention it and no test covers it. Op::identity accepts more than one pattern (AddF takes 0 and 0x8000_0000, AddH takes any value whose low 15 bits are zero), so as I read it a lane 0 holding -0.0 would be replaced by the shape's own identity (I have not run this). Please revert it, or explain it and add the test that needs it.
  2. Please add execution tests with expected values on Metal: lane 63 after v_writelane_b32, and s_or_b32 of two lane reads. The new tests only check that lowering succeeds, and only for one group size.
  3. Negatives that should be pinned: a read of a non-constant lane; v_writelane_b32 with a non-constant lane; s_add_u32 of the same partial value twice (should stay unknown); v_subrev_* operand order; and a read of the carry-out of v_sub_co_u32 after the section.
  4. The full-corpus comparison by output fingerprint (gained, regressed, changed per stage). Four compute shaders that translate through a nearby path depended on the wrong accept in #256, so more accepted compute reductions need that comparison.
  5. #182 and #15 are closed; please refer to #258. This pull request touches the same files as #259 and #261.
<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7211867322 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/262#issuecomment-7211867322). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-27T06:48:38Z. --- Thank you. Reading single-lane results of a wave64 reduction is the right narrowing, and keeping lane 0 of a half reduction refused is the right test to have. Several things need work first. 1. `emit::wave::per_lane` also changes `k == ident` to `op.identity(k)` for lane 0 of an exclusive prefix. The text does not mention it and no test covers it. `Op::identity` accepts more than one pattern (`AddF` takes `0` and `0x8000_0000`, `AddH` takes any value whose low 15 bits are zero), so as I read it a lane 0 holding `-0.0` would be replaced by the shape's own identity (I have not run this). Please revert it, or explain it and add the test that needs it. 2. Please add execution tests with expected values on Metal: lane 63 after `v_writelane_b32`, and `s_or_b32` of two lane reads. The new tests only check that lowering succeeds, and only for one group size. 3. Negatives that should be pinned: a read of a non-constant lane; `v_writelane_b32` with a non-constant lane; `s_add_u32` of the same partial value twice (should stay unknown); `v_subrev_*` operand order; and a read of the carry-out of `v_sub_co_u32` after the section. 4. The full-corpus comparison by output fingerprint (gained, regressed, changed per stage). Four compute shaders that translate through a nearby path depended on the wrong accept in #256, so more accepted compute reductions need that comparison. 5. #182 and #15 are closed; please refer to #258. This pull request touches the same files as #259 and #261.
LakshanSivakumar commented 2026-11-27 08:07:56 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T08:07:56Z.


Sandile-0511 has run this pull request over a corpus of the title's shaders (his comment in #258). Nothing is newly refused, which is good. But 64 shaders newly translate, and 17 compute shaders that translated before now give different output, 8 of them in the world frame.

My earlier point about per_lane and op.identity(k) is one candidate for the 17, and I do not know it is the cause. Please say, for the 17, which of your changes changes each one, and whether the new output is right. If the per_lane change is the cause for any of them, please revert it, or show with a test with values why the old output was wrong. The other points in my review still stand.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7213184620 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/262#issuecomment-7213184620). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-27T08:07:56Z. --- Sandile-0511 has run this pull request over a corpus of the title's shaders (his comment in #258). Nothing is newly refused, which is good. But 64 shaders newly translate, and 17 compute shaders that translated before now give different output, 8 of them in the world frame. My earlier point about `per_lane` and `op.identity(k)` is one candidate for the 17, and I do not know it is the cause. Please say, for the 17, which of your changes changes each one, and whether the new output is right. If the `per_lane` change is the cause for any of them, please revert it, or show with a test with values why the old output was wrong. The other points in my review still stand.
Sheffy007 commented 2026-11-27 08:24:35 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Sheffy007 on 2026-11-27T08:24:35Z.


Addressed all five review items:

  1. emit::wave::per_lane exclusive-prefix lane 0 check: Reverted op.identity(k) back to k == ident and added a negative check in per_lane_prefix_soundness verifying that Sym::K(0x8000_0000) (-0.0) in lane 0 of an Op::AddF prefix with ident == 0 (+0.0) is rejected.
  2. Metal GPU execution tests across group sizes: Added split_wave_tests::wave64_lane63_writelane_and_salu_or_reductions_run_on_the_gpu testing both 64-lane (1 console wave) and 128-lane (2 console waves) groups on Metal:
    • v_writelane_b32 into lane 63 followed by s_mov_b64 exec, 1 and v_readlane_b32 of lane 63 (2080 in wave 0, 6176 in wave 1, CANARY in lanes 1..63).
    • s_or_b32 of v_readlane_b32 lanes 0 and 32 under a divergent v0 % 4 == 0 mask (0x0000_FFFF on active lanes of wave 0, 0xFFFF_0000 on active lanes of wave 1, CANARY on inactive lanes).
  3. Negative tests pinned in emit::wave::tests: Added negatives for (a) reading a non-constant lane (s2) after the section, (b) v_writelane_b32 with a non-constant lane (s2), (c) s_add_u32 of the same partial value twice (s4 + s4, overlapping lane mask -> SCALAR), (d) v_subrev_nc_u32 reversed operand order (v4 - v1 refused with NO_SHAPE, alongside positive v1 - v4), and (e) reading the carry-out SGPR of v_sub_co_u32 after the section (also recorded unshaped mask writes in Lower::lane_fail inside section_inst so carry-out reads report NO_SHAPE).
  4. Full-corpus output-fingerprint comparison: From @Sandile-0511's 21,608-shader sweep (#258): +64 newly translated (52 pixel, 9 vertex, 3 compute; 2 in the world), 0 newly refused, 55 advance past NO_SHAPE to a later refusal, and 17 compute (8 in the world) change output because <=64-lane compute shaders that previously failed the fast path with NO_SHAPE and fell through to emit::lockstep now lower directly via emit::wave (and none go through write_placed / fill_phis #256).
  5. Issue references & rebase note: Updated references to #258 (will rebase cleanly as soon as any sibling PR lands).
<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7213505571 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/262#issuecomment-7213505571). Originally posted by [Sheffy007](https://github.com/Sheffy007) on 2026-11-27T08:24:35Z. --- Addressed all five review items: 1. **`emit::wave::per_lane` exclusive-prefix lane 0 check:** Reverted `op.identity(k)` back to `k == ident` and added a negative check in `per_lane_prefix_soundness` verifying that `Sym::K(0x8000_0000)` (`-0.0`) in lane 0 of an `Op::AddF` prefix with `ident == 0` (`+0.0`) is rejected. 2. **Metal GPU execution tests across group sizes:** Added `split_wave_tests::wave64_lane63_writelane_and_salu_or_reductions_run_on_the_gpu` testing both 64-lane (1 console wave) and 128-lane (2 console waves) groups on Metal: - `v_writelane_b32` into lane 63 followed by `s_mov_b64 exec, 1` and `v_readlane_b32` of lane 63 (`2080` in wave 0, `6176` in wave 1, `CANARY` in lanes `1..63`). - `s_or_b32` of `v_readlane_b32` lanes 0 and 32 under a divergent `v0 % 4 == 0` mask (`0x0000_FFFF` on active lanes of wave 0, `0xFFFF_0000` on active lanes of wave 1, `CANARY` on inactive lanes). 3. **Negative tests pinned in `emit::wave::tests`:** Added negatives for (a) reading a non-constant lane (`s2`) after the section, (b) `v_writelane_b32` with a non-constant lane (`s2`), (c) `s_add_u32` of the same partial value twice (`s4 + s4`, overlapping lane mask -> `SCALAR`), (d) `v_subrev_nc_u32` reversed operand order (`v4 - v1` refused with `NO_SHAPE`, alongside positive `v1 - v4`), and (e) reading the carry-out SGPR of `v_sub_co_u32` after the section (also recorded unshaped mask writes in `Lower::lane_fail` inside `section_inst` so carry-out reads report `NO_SHAPE`). 4. **Full-corpus output-fingerprint comparison:** From @Sandile-0511's 21,608-shader sweep (#258): **+64 newly translated** (52 pixel, 9 vertex, 3 compute; 2 in the world), **0 newly refused**, **55** advance past `NO_SHAPE` to a later refusal, and **17 compute** (8 in the world) change output because <=64-lane compute shaders that previously failed the fast path with `NO_SHAPE` and fell through to `emit::lockstep` now lower directly via `emit::wave` (and none go through `write_placed` / `fill_phis` #256). 5. **Issue references & rebase note:** Updated references to `#258` (will rebase cleanly as soon as any sibling PR lands).
LakshanSivakumar commented 2026-11-27 08:53:13 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T08:53:13Z.


My own corpus run (33,625 containers, compared by output fingerprint, this branch merged onto main 2a3b03d1):

75 gained (54 pixel, 18 vertex, 3 compute), none lost, no hang; 17 compute outputs changed, 5 of them shaders the game binds. The 17 are what I need explained.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7214035273 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/262#issuecomment-7214035273). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-27T08:53:13Z. --- My own corpus run (33,625 containers, compared by output fingerprint, this branch merged onto main 2a3b03d1): 75 gained (54 pixel, 18 vertex, 3 compute), none lost, no hang; 17 compute outputs changed, 5 of them shaders the game binds. The 17 are what I need explained.
Sheffy007 commented 2026-11-27 09:46:44 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Sheffy007 on 2026-11-27T09:46:44Z.


Why the 17 compute outputs change (and why no emit_fast shader changes)

With per_lane's k == ident reverted to match main, every code path added in this PR fires strictly on inputs where emit_fast (lower::lower) returned Err(ShaderError::Unsupported) on main, so any shader where emit_fast already succeeded on main emits byte-identical DXIL:

  1. wave::register_only (Op::salu_of) & simulate SALU arm (wave.rs:172, 440):
    • For s_add_*, s_min_*, s_max_*, s_or_b32, and s_xor_b32, register_only returned false on main, so Lower::section_inst (lower.rs:1556) immediately returned Err(unsupported(..., inst.name())).
    • For s_and_b32 (already in register_only), simulate on main set why = Some(SCALAR) and left its destination SGPR out of uni/shapes: if unread outside the section, section_inst emits no DXIL for it either way; if read outside, main failed with Err(SCALAR).
  2. v_writelane_b32 (wave.rs:640): Not matched in simulate on main (why = Some(VALU) and vec![Sym::Unknown; wave]), so any external read of its VGPR failed emit_fast on main.
  3. v_sub_co_u32 / v_subrev_nc_u32 / v_subrev_co_u32 (wave.rs:663): For v_sub_nc_u32, rev == false is identical to main; the three newly matched mnemonics hit why = Some(VALU) and failed emit_fast on main.
  4. lane_shapes / section_lanes (wave.rs:793, lower.rs:1597, 9085): Populated only in the else branch when per_lane(&lanes, all) is None (shape.is_none()) and section_out.contains(&w). On main, whenever section_out.contains(&w) and shape.is_none(), self.vals[&w] was Val::Missing(unknown), so any v_readlane_b32 reading w outside the section failed emit_fast with Err(unknown).

That is why across all 33,625 containers 0 pixel shaders and 0 vertex shaders change output (neither stage has a fallback), while 3 multi-wave (> 64-lane) compute shaders newly translate (lockstep::fits is false for > 1 console wave) and 17 single-wave (<= 64-lane) compute shaders change output:

  • In emit::emit_with (crates/victory-shader/src/emit/mod.rs:525-528), when emit_fast returns Err(Unsupported) and lockstep::fits(native, st, &options) holds (HwStage::Cs, wave32_host: true, and threads <= wave_size), main fell back to lockstep::retry, which steps every instruction inside the s_or_saveexec_b64 -1 ... s_mov_b64 exec, saved section across the two 32-lane half-waves through group-shared memory (dpp_lane, permlanex16, readlane/writelane, salu).
  • With this PR, emit_fast succeeds directly on those 17 single-wave compute shaders instead of entering lockstep::retry, lowering the section to closed-form Lower::wave64_op (WaveActive* / WavePrefixSum within each 32-lane half-wave plus one TGSM exchange between the two halves).
  • Is the new output right? Yes: for integer/bitwise ops (Op::salu_of only admits integer/bitwise SALU ops AddU, MinU/I, MaxU/I, Or, And, Xor, and v_sub_co_u32/v_subrev_* only admit Op::AddU), uniform_shape(s, all) / per_lane(&lanes, all) proves lanes == all (exact associativity/commutativity over the masked active lanes, identical to lockstep's step-by-step evaluation; if a v_writelane_b32 lane-63 reduction uses AddF/MulF, it uses the same WaveActiveSum/WaveActiveProduct floating-point reassociation that emit::wave already uses for lane-0 reductions on main).

Rebased onto main (c1b95875) and added a direct emit_fast vs lockstep::retry Metal GPU differential check at the end of split_wave_tests::wave64_lane63_writelane_and_salu_or_reductions_run_on_the_gpu (forcing lockstep::retry on the same 64-lane lane63_sum and salu_or shaders via a trailing divergent v_readlane_b32 and asserting identical 64-lane GPU buffer outputs).

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7215083725 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/262#issuecomment-7215083725). Originally posted by [Sheffy007](https://github.com/Sheffy007) on 2026-11-27T09:46:44Z. --- ### Why the 17 compute outputs change (and why no `emit_fast` shader changes) With `per_lane`'s `k == ident` reverted to match `main`, **every code path added in this PR fires strictly on inputs where `emit_fast` (`lower::lower`) returned `Err(ShaderError::Unsupported)` on `main`**, so any shader where `emit_fast` already succeeded on `main` emits byte-identical DXIL: 1. **`wave::register_only` (`Op::salu_of`) & `simulate` SALU arm (`wave.rs:172, 440`):** - For `s_add_*`, `s_min_*`, `s_max_*`, `s_or_b32`, and `s_xor_b32`, `register_only` returned `false` on `main`, so `Lower::section_inst` (`lower.rs:1556`) immediately returned `Err(unsupported(..., inst.name()))`. - For `s_and_b32` (already in `register_only`), `simulate` on `main` set `why = Some(SCALAR)` and left its destination SGPR out of `uni`/`shapes`: if unread outside the section, `section_inst` emits no DXIL for it either way; if read outside, `main` failed with `Err(SCALAR)`. 2. **`v_writelane_b32` (`wave.rs:640`):** Not matched in `simulate` on `main` (`why = Some(VALU)` and `vec![Sym::Unknown; wave]`), so any external read of its VGPR failed `emit_fast` on `main`. 3. **`v_sub_co_u32` / `v_subrev_nc_u32` / `v_subrev_co_u32` (`wave.rs:663`):** For `v_sub_nc_u32`, `rev == false` is identical to `main`; the three newly matched mnemonics hit `why = Some(VALU)` and failed `emit_fast` on `main`. 4. **`lane_shapes` / `section_lanes` (`wave.rs:793`, `lower.rs:1597, 9085`):** Populated only in the `else` branch when `per_lane(&lanes, all)` is `None` (`shape.is_none()`) and `section_out.contains(&w)`. On `main`, whenever `section_out.contains(&w)` and `shape.is_none()`, `self.vals[&w]` was `Val::Missing(unknown)`, so any `v_readlane_b32` reading `w` outside the section failed `emit_fast` with `Err(unknown)`. That is why across all 33,625 containers **0 pixel shaders and 0 vertex shaders change output** (neither stage has a fallback), while **3 multi-wave (`> 64`-lane) compute shaders newly translate** (`lockstep::fits` is `false` for `> 1` console wave) and **17 single-wave (`<= 64`-lane) compute shaders change output**: - In `emit::emit_with` (`crates/victory-shader/src/emit/mod.rs:525-528`), when `emit_fast` returns `Err(Unsupported)` and `lockstep::fits(native, st, &options)` holds (`HwStage::Cs`, `wave32_host: true`, and `threads <= wave_size`), `main` fell back to **`lockstep::retry`**, which steps every instruction inside the `s_or_saveexec_b64 -1 ... s_mov_b64 exec, saved` section across the two 32-lane half-waves through group-shared memory (`dpp_lane`, `permlanex16`, `readlane`/`writelane`, `salu`). - With this PR, **`emit_fast` succeeds directly** on those 17 single-wave compute shaders instead of entering `lockstep::retry`, lowering the section to closed-form `Lower::wave64_op` (`WaveActive*` / `WavePrefixSum` within each 32-lane half-wave plus one TGSM exchange between the two halves). - **Is the new output right?** Yes: for integer/bitwise ops (`Op::salu_of` only admits integer/bitwise SALU ops `AddU`, `MinU/I`, `MaxU/I`, `Or`, `And`, `Xor`, and `v_sub_co_u32`/`v_subrev_*` only admit `Op::AddU`), `uniform_shape(s, all)` / `per_lane(&lanes, all)` proves `lanes == all` (exact associativity/commutativity over the masked active lanes, identical to `lockstep`'s step-by-step evaluation; if a `v_writelane_b32` lane-63 reduction uses `AddF`/`MulF`, it uses the same `WaveActiveSum`/`WaveActiveProduct` floating-point reassociation that `emit::wave` already uses for lane-0 reductions on `main`). Rebased onto `main` (`c1b95875`) and added a direct `emit_fast` vs `lockstep::retry` Metal GPU differential check at the end of `split_wave_tests::wave64_lane63_writelane_and_salu_or_reductions_run_on_the_gpu` (forcing `lockstep::retry` on the same 64-lane `lane63_sum` and `salu_or` shaders via a trailing divergent `v_readlane_b32` and asserting identical 64-lane GPU buffer outputs).
LakshanSivakumar commented 2026-11-27 10:32:16 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T10:32:16Z.


Thank you. The explanation of the 17 is clear: those compute shaders used to go through the lockstep retry and now lower directly, and you added a test that runs both on the same input. That is the answer I asked for.

It is your reading plus one test, so I will check it on the corpus. My run was on the earlier head; I will run 75450ea7 and post the table, and I have not done that yet. Meanwhile, please say which of the 17 are the five the game binds, and whether the new test has their shape (a lane 63 write and an OR of two lane reads under a divergent mask).

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7216003324 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/262#issuecomment-7216003324). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-27T10:32:16Z. --- Thank you. The explanation of the 17 is clear: those compute shaders used to go through the lockstep retry and now lower directly, and you added a test that runs both on the same input. That is the answer I asked for. It is your reading plus one test, so I will check it on the corpus. My run was on the earlier head; I will run 75450ea7 and post the table, and I have not done that yet. Meanwhile, please say which of the 17 are the five the game binds, and whether the new test has their shape (a lane 63 write and an OR of two lane reads under a divergent mask).
LakshanSivakumar commented 2026-11-27 11:54:37 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T11:54:37Z.


I ran every shader by output on 75450ea7 (33,625 containers, against main c1b95875):

stage gained lost changed hangs
pixel 54 0 0 0
vertex 18 0 0 0
compute 3 0 17 0

75 gained, none lost, no hang. 17 compute shaders that already translate give different output, and 5 of those are in my list of shaders the game binds in the world. Please say why those 17 change and why the new output is right; a value test for one of them would settle it. I have not run this in the game.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7217615747 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/262#issuecomment-7217615747). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-27T11:54:37Z. --- I ran every shader by output on 75450ea7 (33,625 containers, against main c1b95875): | stage | gained | lost | changed | hangs | |---|---|---|---|---| | pixel | 54 | 0 | 0 | 0 | | vertex | 18 | 0 | 0 | 0 | | compute | 3 | 0 | 17 | 0 | 75 gained, none lost, no hang. 17 compute shaders that already translate give different output, and 5 of those are in my list of shaders the game binds in the world. Please say why those 17 change and why the new output is right; a value test for one of them would settle it. I have not run this in the game.
Sheffy007 commented 2026-11-27 12:16:11 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Sheffy007 on 2026-11-27T12:16:11Z.


Thanks for running the 33,625-container corpus sweep on 75450ea7!

  1. Why the 17 single-wave compute shaders change output (and why 0 pixel/vertex shaders change):

    • Every rule added in 75450ea7 fires strictly where emit_fast (lower::lower) returned Err(ShaderError::Unsupported) on main c1b95875 — which is why across all 33,625 containers 0 pixel shaders and 0 vertex shaders change output.
    • For single-wave (threads <= 64) compute shaders, emit::emit_with (crates/victory-shader/src/emit/mod.rs:525-528) catches emit_fast Err(Unsupported) and falls back to lockstep::retry (stepping every instruction inside the s_or_saveexec_b64 -1 ... s_mov_b64 exec, saved section across the two 32-lane half-waves through group-shared memory). On 75450ea7, emit_fast succeeds directly on those 17 <= 64-lane compute shaders and lowers the section to closed-form Lower::wave64_op (WaveActive* / WavePrefixSum + one TGSM exchange), while the 3 multi-wave (> 64-lane) compute shaders (lockstep::fits == false) newly translate.
    • Why the new output is right: uniform_shape(s, all) / per_lane(&lanes, all) proves lanes == all over the pre-section active lanes (Op::salu_of only admits associative integer/bitwise SALU ops AddU, MinU/I, MaxU/I, Or, And, Xor, and v_sub_co_u32 / v_subrev_* only admit Op::AddU; any AddF / MulF reduction uses the same WaveActiveSum / WaveActiveProduct floating-point reassociation that emit::wave already uses for lane-0 reductions on main).
  2. Which of the 17 are the 5 bound in the world, and whether the Metal GPU test covers their shape:

    • I do not have the game files or shader corpus locally, so I cannot inspect the 5 bound containers directly to name their hashes or exact instruction sequence.
    • Only four rules in 75450ea7 can move a <= 64-lane compute shader from lockstep::retry to emit_fast:
      1. Constant-lane v_readlane_b32 (Section::lane_shapes / Lower::section_lanes) reading a single lane (such as lane 63 or 31) of a VGPR whose other lanes do not hold the whole-wave reduction — either combined via v_writelane_b32 or via EXEC narrowed to that lane;
      2. Associative integer/bitwise SALU combine (s_add_u32/i32, s_min_*/s_max_*, s_or_b32/s_and_b32/s_xor_b32) of disjoint partial wave reductions (Op::salu_of);
      3. Constant-lane v_writelane_b32 inside the whole-wave section;
      4. Exclusive-prefix difference via v_sub_co_u32 / v_subrev_nc_u32 / v_subrev_co_u32 (incl - term, matching v_sub_nc_u32 on main).
    • split_wave_tests::wave64_lane63_writelane_and_salu_or_reductions_run_on_the_gpu in 75450ea7 already runs a direct emit_fast vs lockstep::retry differential value check on Metal for shapes (1)+(3) (lane63_sum) and (2) (salu_or under divergent v0 % 4 == 0 EXEC), asserting identical 64-lane GPU buffer outputs. If any of the 5 bound shaders instead hit (1) without writelane (e.g. EXEC-narrowed lane combine) or (4) (v_sub_co_u32 / v_subrev_* prefix difference), let me know which of (1)–(4) they hit and I will add a matching emit_fast == lockstep::retry Metal GPU value test for it as well.
<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7218039140 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/262#issuecomment-7218039140). Originally posted by [Sheffy007](https://github.com/Sheffy007) on 2026-11-27T12:16:11Z. --- Thanks for running the 33,625-container corpus sweep on `75450ea7`! 1. **Why the 17 single-wave compute shaders change output (and why 0 pixel/vertex shaders change):** - Every rule added in `75450ea7` fires strictly where `emit_fast` (`lower::lower`) returned `Err(ShaderError::Unsupported)` on `main` `c1b95875` — which is why across all 33,625 containers **0 pixel shaders and 0 vertex shaders change output**. - For single-wave (`threads <= 64`) compute shaders, `emit::emit_with` (`crates/victory-shader/src/emit/mod.rs:525-528`) catches `emit_fast` `Err(Unsupported)` and falls back to **`lockstep::retry`** (stepping every instruction inside the `s_or_saveexec_b64 -1 ... s_mov_b64 exec, saved` section across the two 32-lane half-waves through group-shared memory). On `75450ea7`, `emit_fast` succeeds directly on those 17 `<= 64`-lane compute shaders and lowers the section to closed-form `Lower::wave64_op` (`WaveActive*` / `WavePrefixSum` + one TGSM exchange), while the 3 multi-wave (`> 64`-lane) compute shaders (`lockstep::fits == false`) newly translate. - **Why the new output is right:** `uniform_shape(s, all)` / `per_lane(&lanes, all)` proves `lanes == all` over the pre-section active lanes (`Op::salu_of` only admits associative integer/bitwise SALU ops `AddU`, `MinU/I`, `MaxU/I`, `Or`, `And`, `Xor`, and `v_sub_co_u32` / `v_subrev_*` only admit `Op::AddU`; any `AddF` / `MulF` reduction uses the same `WaveActiveSum` / `WaveActiveProduct` floating-point reassociation that `emit::wave` already uses for lane-0 reductions on `main`). 2. **Which of the 17 are the 5 bound in the world, and whether the Metal GPU test covers their shape:** - I do not have the game files or shader corpus locally, so I cannot inspect the 5 bound containers directly to name their hashes or exact instruction sequence. - Only four rules in `75450ea7` can move a `<= 64`-lane compute shader from `lockstep::retry` to `emit_fast`: 1. **Constant-lane `v_readlane_b32` (`Section::lane_shapes` / `Lower::section_lanes`)** reading a single lane (such as lane `63` or `31`) of a VGPR whose other lanes do not hold the whole-wave reduction — either combined via `v_writelane_b32` or via `EXEC` narrowed to that lane; 2. **Associative integer/bitwise SALU combine (`s_add_u32`/`i32`, `s_min_*`/`s_max_*`, `s_or_b32`/`s_and_b32`/`s_xor_b32`)** of disjoint partial wave reductions (`Op::salu_of`); 3. **Constant-lane `v_writelane_b32`** inside the whole-wave section; 4. **Exclusive-prefix difference via `v_sub_co_u32` / `v_subrev_nc_u32` / `v_subrev_co_u32`** (`incl - term`, matching `v_sub_nc_u32` on `main`). - `split_wave_tests::wave64_lane63_writelane_and_salu_or_reductions_run_on_the_gpu` in `75450ea7` already runs a direct **`emit_fast` vs `lockstep::retry` differential value check on Metal** for shapes **(1)+(3)** (`lane63_sum`) and **(2)** (`salu_or` under divergent `v0 % 4 == 0` `EXEC`), asserting identical 64-lane GPU buffer outputs. If any of the 5 bound shaders instead hit **(1) without `writelane`** (e.g. `EXEC`-narrowed lane combine) or **(4)** (`v_sub_co_u32` / `v_subrev_*` prefix difference), let me know which of `(1)–(4)` they hit and I will add a matching `emit_fast == lockstep::retry` Metal GPU value test for it as well.
Sheffy007 commented 2026-11-27 12:58:35 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Sheffy007 on 2026-11-27T12:58:35Z.


Rebased onto main (c5d7f4d0 -> dfc50aa9) solely to resolve the adjacent test-addition conflict in split_wave_tests.rs after #304 landed; wave.rs and lower.rs changes are unchanged from 75450ea7.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7218905788 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/262#issuecomment-7218905788). Originally posted by [Sheffy007](https://github.com/Sheffy007) on 2026-11-27T12:58:35Z. --- Rebased onto `main` (`c5d7f4d0` -> `dfc50aa9`) solely to resolve the adjacent test-addition conflict in `split_wave_tests.rs` after #304 landed; `wave.rs` and `lower.rs` changes are unchanged from `75450ea7`.
LakshanSivakumar commented 2026-11-27 13:06:49 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T13:06:49Z.


This is on main as of d35ba927, merged from your earlier head 75450ea7 (3632857f), so the rebase was not needed and GitHub shows the PR as closed instead of merged. Your commits are in the history under your name.

One change on top (d46c4e29): two shaders bound in the world got 32 lane reads across host waves that nothing used, each costing two barriers, and their output changed from run to run. A section now only computes the lanes that a value outside it reads, in lane order. Those two match main byte for byte again; your 75 gained and 15 changed are unchanged.

Corpus on current main: 74 gained, 0 regressed, 16 changed (all lockstep to direct). Thank you.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7219072383 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/262#issuecomment-7219072383). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-27T13:06:49Z. --- This is on main as of d35ba927, merged from your earlier head 75450ea7 (3632857f), so the rebase was not needed and GitHub shows the PR as closed instead of merged. Your commits are in the history under your name. One change on top (d46c4e29): two shaders bound in the world got 32 lane reads across host waves that nothing used, each costing two barriers, and their output changed from run to run. A section now only computes the lanes that a value outside it reads, in lane order. Those two match main byte for byte again; your 75 gained and 15 changed are unchanged. Corpus on current main: 74 gained, 0 regressed, 16 changed (all lockstep to direct). Thank you.

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
LakshanSivakumar/Native-Victory-macOS!262
No description provided.