shader: per-lane mask joins through joins of masks, and of data a region loads (#434) #466

Open
Tarraga wants to merge 1 commit from upstream-pr/466 into main
Tarraga commented 2026-11-27 21:25:32 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Tarraga on 2026-11-27T21:25:32Z.


What this changes

Refs #434.

Three more forms of a per-lane join of a lane mask are lowered in fill_phis. They were refused as "a lane-mask join of an untracked mask" ("a value the translation could not make", "data, at a join of several edges"). The arms are ported from VIctory-macOS 6f8fe556.

  1. A join of masks on an edge (restored_mask). A loop's back edge carries what an inner region left in the register: that region's compare for the lanes that ran it, the header's mask for the others. The edge is that join. A mask spilled to VGPR lanes and read back is followed the same way.
  2. Lanes in none of the masks the other edges bring (no_mask_lane_through_joins). This is no_mask_lane_on_edge through joins of masks a region made: those lanes read 0.
  3. Data a region loads into the mask's register, in wave32 compute. A region the other lanes skip reuses the register for a constant-buffer or descriptor-table dword. That data is no mask for the edge's lanes: they read their bit of the number with the console's lanes, else 0.
    • Only data made from no mask counts (made_without_masks: loads, inputs, and scalar work on them). A mask XORed with data stays refused.
    • So does data from before the region (dominates_join).

There is no switch. No translation that main already makes changes: the sweep below has 0 changed outputs. Only programs main refuses now translate.

Guesses, marked in the code and in docs/native-host.md ("Lane masks joined with data"):

  • Form 2 rests on no_mask_lane_on_edge's reasoning: where the whole wave skips the region, the data the skipping lanes bring is a reused register, never read as a mask.
  • Form 3 assumes the mask was dead where the compiler reused its register. On the console, the region's write is the whole wave's, so the other edges' lanes would read the data's bits. Here they read their mask. Either way, no result should depend on it.
  • Neither was checked on the GPU against the console.

How it was tested

  • Corpus. examples/sweep on my own dump of 19,127 containers (Series S), main b998bb65 against this branch, compared with tools/corpus/compare.sh:
    • 22 newly translated, all compute (19,011 to 19,033);
    • 0 regressions;
    • 0 outputs changed;
    • 2 now refused at a later join (a96bb7e19625fc8d, c2d3fdeffa839418).
  • Which forms are needed. I swept with one arm off at a time.
    • 19 of the 22 need only form 1 (0a5ecfee6b79e13b, 17af15c4015cb4b6, a53a7977fe762268 and others).
    • 3 of the 7 ray-traced shadow traces need all three (CS_RTShadowTrace32*: 534b3645dd344ab2, d50c03da6d935d87, ffd9788ba9fec033). With only form 3 they stay refused, and so they do without form 2.
    • The first version of form 3 took any data written in the region. It let split_wave_tests::a_mask_swapped_into_a_pair_by_64_bit_xors_in_a_32_lane_wave_is_that_mask_at_a_join's look-alike (a mask XORed with data) through. made_without_masks fixes that and keeps the same 22.
  • Unit tests (emit::lower::tests). Each of the first three fails on main, with "a lane-mask join of an untracked mask: data, on the host's lanes":
    • a_loops_mask_its_back_edge_brings_as_a_join_of_masks_lowers (form 1);
    • a_join_of_masks_a_region_made_is_no_mask_for_the_lanes_that_skipped_it (form 2; it also fails with only that arm off);
    • a_mask_register_reused_for_data_a_region_loads_is_no_mask_for_its_lanes (form 3, with s_buffer_load_dword and s_load_dword);
    • a_mask_joined_with_a_reused_registers_data_lowers (ported) already passes on main. It checks that data from before the region stays refused.
  • cargo test -p victory-shader --lib: 406 passed, 3 ignored.
  • cargo test --target x86_64-apple-darwin -p victory-gpu --lib, with the Metal Shader Converter from D3DMetal 4.0b3 (VICTORY_MSC_DYLIB): 412 passed, 0 failed, 6 ignored. x86_64 because that is the only converter this Mac has; the run did not crash under Rosetta.
  • cargo clippy -p victory-shader --all-targets --locked -- -D warnings (host): no warnings.
  • Windows clippy (x86_64-pc-windows-gnullvm): not run. This Mac has no target for it, so CI will be the first to run it.
  • cargo xtask policy: 398 files ok.
  • Ran the game: not with this branch on main. On our working branch, an earlier version of these arms (form 3 without made_without_masks) translated these programs. One run there (Series S, 480 s) bound 10 of the 22 in the world: the prop and tree batch culling (CS_Prop_BatchCull, CS_Tree_BatchCull), the irradiance cache's shading and the hair shadow masks. That run had 0 GPU errors. Main's own runs name these programs by other hashes, so I can't say from them which of the 22 main binds.

Checklist

  • No game files, game code, disassembly listings or SDK files are included (counts, hashes, program names and refusal messages only)
  • Guesses about undocumented console behaviour are marked in the code and in docs/native-host.md
  • New diagnostics are behind a VICTORY_* variable and documented (no new diagnostics)
<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:5533284278 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/466). Originally posted by [Tarraga](https://github.com/Tarraga) on 2026-11-27T21:25:32Z. --- ## What this changes Refs #434. Three more forms of a per-lane join of a lane mask are lowered in `fill_phis`. They were refused as "a lane-mask join of an untracked mask" ("a value the translation could not make", "data, at a join of several edges"). The arms are ported from VIctory-macOS 6f8fe556. 1. **A join of masks on an edge** (`restored_mask`). A loop's back edge carries what an inner region left in the register: that region's compare for the lanes that ran it, the header's mask for the others. The edge is that join. A mask spilled to VGPR lanes and read back is followed the same way. 2. **Lanes in none of the masks the other edges bring** (`no_mask_lane_through_joins`). This is `no_mask_lane_on_edge` through joins of masks a region made: those lanes read 0. 3. **Data a region loads into the mask's register**, in wave32 compute. A region the other lanes skip reuses the register for a constant-buffer or descriptor-table dword. That data is no mask for the edge's lanes: they read their bit of the number with the console's lanes, else 0. - Only data made from no mask counts (`made_without_masks`: loads, inputs, and scalar work on them). A mask XORed with data stays refused. - So does data from before the region (`dominates_join`). There is no switch. No translation that main already makes changes: the sweep below has 0 changed outputs. Only programs main refuses now translate. Guesses, marked in the code and in docs/native-host.md ("Lane masks joined with data"): - Form 2 rests on `no_mask_lane_on_edge`'s reasoning: where the whole wave skips the region, the data the skipping lanes bring is a reused register, never read as a mask. - Form 3 assumes the mask was dead where the compiler reused its register. On the console, the region's write is the whole wave's, so the other edges' lanes would read the data's bits. Here they read their mask. Either way, no result should depend on it. - Neither was checked on the GPU against the console. ## How it was tested - **Corpus.** `examples/sweep` on my own dump of 19,127 containers (Series S), main b998bb65 against this branch, compared with `tools/corpus/compare.sh`: - 22 newly translated, all compute (19,011 to 19,033); - 0 regressions; - 0 outputs changed; - 2 now refused at a later join (`a96bb7e19625fc8d`, `c2d3fdeffa839418`). - **Which forms are needed.** I swept with one arm off at a time. - 19 of the 22 need only form 1 (`0a5ecfee6b79e13b`, `17af15c4015cb4b6`, `a53a7977fe762268` and others). - 3 of the 7 ray-traced shadow traces need all three (`CS_RTShadowTrace32*`: `534b3645dd344ab2`, `d50c03da6d935d87`, `ffd9788ba9fec033`). With only form 3 they stay refused, and so they do without form 2. - The first version of form 3 took any data written in the region. It let `split_wave_tests::a_mask_swapped_into_a_pair_by_64_bit_xors_in_a_32_lane_wave_is_that_mask_at_a_join`'s look-alike (a mask XORed with data) through. `made_without_masks` fixes that and keeps the same 22. - **Unit tests** (`emit::lower::tests`). Each of the first three fails on main, with "a lane-mask join of an untracked mask: data, on the host's lanes": - `a_loops_mask_its_back_edge_brings_as_a_join_of_masks_lowers` (form 1); - `a_join_of_masks_a_region_made_is_no_mask_for_the_lanes_that_skipped_it` (form 2; it also fails with only that arm off); - `a_mask_register_reused_for_data_a_region_loads_is_no_mask_for_its_lanes` (form 3, with `s_buffer_load_dword` and `s_load_dword`); - `a_mask_joined_with_a_reused_registers_data_lowers` (ported) already passes on main. It checks that data from before the region stays refused. - [x] `cargo test -p victory-shader --lib`: 406 passed, 3 ignored. - [x] `cargo test --target x86_64-apple-darwin -p victory-gpu --lib`, with the Metal Shader Converter from D3DMetal 4.0b3 (`VICTORY_MSC_DYLIB`): 412 passed, 0 failed, 6 ignored. x86_64 because that is the only converter this Mac has; the run did not crash under Rosetta. - [x] `cargo clippy -p victory-shader --all-targets --locked -- -D warnings` (host): no warnings. - [ ] Windows clippy (`x86_64-pc-windows-gnullvm`): not run. This Mac has no target for it, so CI will be the first to run it. - [x] `cargo xtask policy`: 398 files ok. - [ ] Ran the game: not with this branch on main. On our working branch, an earlier version of these arms (form 3 without `made_without_masks`) translated these programs. One run there (Series S, 480 s) bound 10 of the 22 in the world: the prop and tree batch culling (`CS_Prop_BatchCull`, `CS_Tree_BatchCull`), the irradiance cache's shading and the hair shadow masks. That run had 0 GPU errors. Main's own runs name these programs by other hashes, so I can't say from them which of the 22 main binds. ## Checklist - [x] No game files, game code, disassembly listings or SDK files are included (counts, hashes, program names and refusal messages only) - [x] Guesses about undocumented console behaviour are marked in the code and in docs/native-host.md - [x] New diagnostics are behind a `VICTORY_*` variable and documented (no new diagnostics)
Olima34 commented 2026-11-28 02:00:31 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Olima34 on 2026-11-28T02:00:31Z.


Thanks for this PR! An offline check of 18c66d5b:

Measured offline on main 86cefd22 with examples/sweep + tools/corpus/compare.sh, on our 21,600-shader world corpus. The PR alone was swept over the 10,319 world shaders that the combination below changes. "Passes/frame" is an estimate from four traced world frames of an earlier preview run: the dropped passes whose only refused shader this PR translates.

#466 alone:

  • Newly translated, 27:
    • 15 compute and 2 pixel that were refused for "a lane-mask join of an untracked mask: a value the translation could not make";
    • 6 vertex that were refused for "… data, on the host's lanes";
    • 4 compute that were refused for "… data, at a join of several edges".
  • Outputs changed: 5 compute.
  • Refused for another reason now: 13.
  • Regressions: 0.
  • Passes/frame: about 7.

Needs a rebase: with #466 merged onto current main, main's test emit::mask_tests::a_merge_of_another_mask_is_no_merge_of_the_old_one fails. That test came in with db6c3bd6, after #466's base. The test expects a merge whose s_andn2_b64 reads the loop's EXEC rather than the old mask to stay refused; with #466 it translates (expect("refused") panics). Each of the other PRs above passes this test.

Merging:

  • #466 and #448 add code at the same spot in emit/lower.rs (one new function and one new let each). Keeping both sides compiles, so whichever lands second needs only a trivial rebase.
  • The two PRs overlap on 1 shader.

In combination with #418 #466 #420 #409 #448 #433 #495 #497 on 86cefd22 (a local integration build, plus the pass-trace fix from #509):

  • World corpus: 302 shaders newly translated and 1 regression (see #433).
  • Windowed run (6 min): no GPU errors, and the GPU memory drained afterwards. About 1.4 fps in the world. 351 passes dropped per world frame, against 456 in an earlier census of the preview branch; these are different runs, so not a clean A/B.
<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7232064851 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/466#issuecomment-7232064851). Originally posted by [Olima34](https://github.com/Olima34) on 2026-11-28T02:00:31Z. --- Thanks for this PR! An offline check of 18c66d5b: Measured offline on main 86cefd22 with `examples/sweep` + `tools/corpus/compare.sh`, on our 21,600-shader world corpus. The PR alone was swept over the 10,319 world shaders that the combination below changes. "Passes/frame" is an estimate from four traced world frames of an earlier preview run: the dropped passes whose only refused shader this PR translates. **#466 alone:** - **Newly translated, 27:** - 15 compute and 2 pixel that were refused for "a lane-mask join of an untracked mask: a value the translation could not make"; - 6 vertex that were refused for "… data, on the host's lanes"; - 4 compute that were refused for "… data, at a join of several edges". - **Outputs changed:** 5 compute. - **Refused for another reason now:** 13. - **Regressions:** 0. - **Passes/frame:** about 7. **Needs a rebase:** with #466 merged onto current main, main's test `emit::mask_tests::a_merge_of_another_mask_is_no_merge_of_the_old_one` fails. That test came in with db6c3bd6, after #466's base. The test expects a merge whose `s_andn2_b64` reads the loop's EXEC rather than the old mask to stay refused; with #466 it translates (`expect("refused")` panics). Each of the other PRs above passes this test. **Merging:** - #466 and #448 add code at the same spot in `emit/lower.rs` (one new function and one new `let` each). Keeping both sides compiles, so whichever lands second needs only a trivial rebase. - The two PRs overlap on 1 shader. **In combination** with #418 #466 #420 #409 #448 #433 #495 #497 on 86cefd22 (a local integration build, plus the pass-trace fix from #509): - **World corpus:** 302 shaders newly translated and 1 regression (see #433). - **Windowed run (6 min):** no GPU errors, and the GPU memory drained afterwards. About 1.4 fps in the world. 351 passes dropped per world frame, against 456 in an earlier census of the preview branch; these are different runs, so not a clean A/B.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/466:upstream-pr/466'
git switch 'upstream-pr/466'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/466'
git switch 'upstream-pr/466'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/466'
git switch 'upstream-pr/466'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/466'
git switch 'main'
git merge --squash 'upstream-pr/466'
git switch 'main'
git merge --ff-only 'upstream-pr/466'
git switch 'main'
git merge 'upstream-pr/466'
git push origin 'main'
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!466
No description provided.