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

Manually merged
github merged 2 commits from github-bot/gh-362 into main 2026-11-27 16:13:16 +00:00 AGit
Owner

@⁠tiagonogueiraa-bit on GitHub · 2026-11-27 14:09 UTC · original
tiagonogueiraa-bit:shader-section-bfm-exec → main · +252 −11 · 4 files · 2 commits · merged 2026-11-27 16:04 UTC

Refs #364

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.

**@⁠tiagonogueiraa-bit** on GitHub · 2026-11-27 14:09 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/362) `tiagonogueiraa-bit:shader-section-bfm-exec` → `main` · +252 −11 · 4 files · 2 commits · merged 2026-11-27 16:04 UTC Refs #364 **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.
The title's wave32 prefix sums sum each row of 16 lanes with DPP. Then
they set EXEC to the upper row with s_bfm_b32 exec_lo, 16, 16 and add
lane 15 through v_permlanex16_b32. The section simulator followed only
s_mov EXEC writes, and register_only did not take the s_bfm, so these
were refused as "s_bfm_b32 is not supported".

wave::exec_constant gives the lane set of a constant s_mov, or of an
s_bfm_b32 or s_bfm_b64 of two constant counts. The simulator uses it for
EXEC writes, and register_only takes such an s_bfm. An s_bfm with a count
in an SGPR stays refused.

Corpus sweep (12,020 shaders, main 905e7aa): 9 compute shaders gained,
1 refused for another reason, no regressions, no changed outputs.

Refs #361
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 14:16:40 +00:00
github-bot changed title from shader: follow a constant s_bfm EXEC write in a whole-wave section (#361) to shader: follow constant s_bfm and s_bitreplicate EXEC writes in whole-wave sections (#361) 2026-11-27 14:22:16 +00:00
The wave64 form of the title's prefix sums selects the upper row of each
half with s_bitreplicate_b64_b32 exec, 0xff00ff00, then the upper half
with s_bfm_b64 exec, 32, 32. wave::exec_constant gives the lane set of
an s_bitreplicate_b64_b32 of a constant (bit i to bits 2i and 2i + 1),
and register_only takes it.

Corpus sweep against main 905e7aa, with the s_bfm commit: 17 compute
shaders gained, 1 refused for another reason, no regressions, no changed
outputs.

Refs #361
github manually merged commit 8b0d3e90a6 into main 2026-11-27 16:13:16 +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/362#issuecomment-7222838022) 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.
This discussion has been locked. Commenting is limited to contributors.
No description provided.