shader: follow constant s_bfm and s_bitreplicate EXEC writes in whole-wave sections (#361) #362

Merged
tiagonogueiraa-bit merged 2 commits from upstream-pr/362 into main 2026-11-27 16:04:48 +00:00
tiagonogueiraa-bit commented 2026-11-27 14:09:49 +00:00 (Migrated from github.com)

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


Refs #361

Shape. The title's prefix sums run in whole-wave sections and select rows with constant EXEC writes:

  • wave32: an inclusive sum in each row of 16 lanes (DPP row_shr 1, 2, 4, 8), then s_bfm_b32 exec_lo, 16, 16 and v_permlanex16_b32 add lane 15 into the upper row;
  • wave64: the same rows, then s_bitreplicate_b64_b32 exec, 0xff00ff00 (the upper row of each half) with v_permlanex16_b32, then s_bfm_b64 exec, 32, 32 adds lane 31 into the upper half.

The simulator followed only s_mov EXEC writes, and wave::register_only took neither instruction. So Lower::section_inst stopped at the opcode ("s_bfm_b32 is not supported"), or the section's values were left unknown and a later read was refused instead.

Change.

  • wave::exec_constant gives the lane set of a constant s_mov, of an s_bfm_b32 or s_bfm_b64 of two constant counts (((1 << S0) - 1) << S1, counts of 5 or 6 bits; SOP2 opcodes 36 and 37), or of an s_bitreplicate_b64_b32 of a constant (bit i to bits 2i and 2i + 1; SOP1 opcode 59).
  • simulate uses it for EXEC writes, and register_only takes those instructions when they write EXEC with constant operands.
  • Anything with a non-constant operand is still refused, and nothing outside sections changes.

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 17 0 0 1
pixel 0 0 0 0
vertex 0 0 0 0
  • Gained, was s_bfm_b32 (9): 1ba04ed0bdb9d8f7, 34046961ba5a083e, 6eb2cad0734f0844, 71ffd0d7b57f5413, 8c9f69d0d905ffe3, b8c3843f71fb4eaa, c38c7bd6ba697164, cbd298c95c519202, d9be592e55ce3180.
  • Gained, was s_bitreplicate_b64_b32 (2): 2f27e7c39c63e598, 57112cf780dbfc5c.
  • Gained, was "a lane mask holding lanes elsewhere read as data: written by a scalar instruction of the other width" (6): 13e7b57cfa9850df, 383a3512203c500b, 816f5a360245eb94, 9628f6ff142e1799, a733768e1c646908, fb2cbdf4ee7d984e. Each has the wave64 section above. Its values were unknown, so the refusal surfaced later, at a lane index read from the section's result (v_readlane_b32 sN, vM, sN before an atomic).
  • Other reason now: 6c7f547fee86539d goes from s_bfm_b32 to "a lane-mask join of an untracked mask: data, at a join of several edges", its next refusal.

Tests. The GPU and lowering tests fail on main and pass here.

  • emit::wave::tests::s_bfm_gives_exec_its_field_of_constant_counts: s_bfm inline and literal counts, the 5-bit wrap, the 64-bit form, s_bitreplicate of 0xff00ff00 and of an inline constant, and SGPR operands giving None.
  • emit::lower::tests::a_wave32_prefix_sum_may_set_its_upper_row_with_s_bfm: one dx.op.wavePrefixOp.i32.
  • split_wave_tests::a_wave32_prefix_sum_whose_upper_row_s_bfm_selects_runs (victory-gpu, on Metal): lane i stores sum(1..=i+1), also with lanes 20 and up off before the section.
  • split_wave_tests::a_wave64_prefix_sum_whose_rows_s_bitreplicate_and_s_bfm_select_runs (victory-gpu, on Metal): 64 lanes across the two host waves of a console wave, lane i stores sum(1..=i+1).

Checks.

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

docs/native-host.md ("Whole-wave sections the simulation does not follow") describes the change. I haven't checked it in a game run. @Olima34, for the board.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:5528023166 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/362). Originally posted by [tiagonogueiraa-bit](https://github.com/tiagonogueiraa-bit) on 2026-11-27T14:09:49Z. --- Refs #361 **Shape.** The title's prefix sums run in whole-wave sections and select rows with constant EXEC writes: - **wave32:** an inclusive sum in each row of 16 lanes (DPP `row_shr` 1, 2, 4, 8), then `s_bfm_b32 exec_lo, 16, 16` and `v_permlanex16_b32` add lane 15 into the upper row; - **wave64:** the same rows, then `s_bitreplicate_b64_b32 exec, 0xff00ff00` (the upper row of each half) with `v_permlanex16_b32`, then `s_bfm_b64 exec, 32, 32` adds lane 31 into the upper half. The simulator followed only `s_mov` EXEC writes, and `wave::register_only` took neither instruction. So `Lower::section_inst` stopped at the opcode ("s_bfm_b32 is not supported"), or the section's values were left unknown and a later read was refused instead. **Change.** - `wave::exec_constant` gives the lane set of a constant `s_mov`, of an `s_bfm_b32` or `s_bfm_b64` of two constant counts (`((1 << S0) - 1) << S1`, counts of 5 or 6 bits; SOP2 opcodes 36 and 37), or of an `s_bitreplicate_b64_b32` of a constant (bit `i` to bits `2i` and `2i + 1`; SOP1 opcode 59). - `simulate` uses it for EXEC writes, and `register_only` takes those instructions when they write EXEC with constant operands. - Anything with a non-constant operand is still refused, and nothing outside sections changes. **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 | 17 | 0 | 0 | 1 | | pixel | 0 | 0 | 0 | 0 | | vertex | 0 | 0 | 0 | 0 | - **Gained, was `s_bfm_b32` (9):** `1ba04ed0bdb9d8f7`, `34046961ba5a083e`, `6eb2cad0734f0844`, `71ffd0d7b57f5413`, `8c9f69d0d905ffe3`, `b8c3843f71fb4eaa`, `c38c7bd6ba697164`, `cbd298c95c519202`, `d9be592e55ce3180`. - **Gained, was `s_bitreplicate_b64_b32` (2):** `2f27e7c39c63e598`, `57112cf780dbfc5c`. - **Gained, was "a lane mask holding lanes elsewhere read as data: written by a scalar instruction of the other width" (6):** `13e7b57cfa9850df`, `383a3512203c500b`, `816f5a360245eb94`, `9628f6ff142e1799`, `a733768e1c646908`, `fb2cbdf4ee7d984e`. Each has the wave64 section above. Its values were unknown, so the refusal surfaced later, at a lane index read from the section's result (`v_readlane_b32 sN, vM, sN` before an atomic). - **Other reason now:** `6c7f547fee86539d` goes from `s_bfm_b32` to "a lane-mask join of an untracked mask: data, at a join of several edges", its next refusal. **Tests.** The GPU and lowering tests fail on main and pass here. - `emit::wave::tests::s_bfm_gives_exec_its_field_of_constant_counts`: `s_bfm` inline and literal counts, the 5-bit wrap, the 64-bit form, `s_bitreplicate` of `0xff00ff00` and of an inline constant, and SGPR operands giving `None`. - `emit::lower::tests::a_wave32_prefix_sum_may_set_its_upper_row_with_s_bfm`: one `dx.op.wavePrefixOp.i32`. - `split_wave_tests::a_wave32_prefix_sum_whose_upper_row_s_bfm_selects_runs` (`victory-gpu`, on Metal): lane `i` stores `sum(1..=i+1)`, also with lanes 20 and up off before the section. - `split_wave_tests::a_wave64_prefix_sum_whose_rows_s_bitreplicate_and_s_bfm_select_runs` (`victory-gpu`, on Metal): 64 lanes across the two host waves of a console wave, lane `i` stores `sum(1..=i+1)`. **Checks.** - `cargo test -p victory-shader -p victory-hle -p victory -p victory-gpu -p victory-metal -p xtask`: 958 passed, 0 failed, 10 ignored. - Windows clippy `-D warnings`: clean. - `cargo xtask policy`: ok. `docs/native-host.md` ("Whole-wave sections the simulation does not follow") describes the change. I haven't checked it in a game run. @Olima34, for the board.
LakshanSivakumar commented 2026-11-27 16:05:09 +00:00 (Migrated from github.com)

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


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