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

Open
github-bot wants to merge 1 commit from github-bot/gh-466 into main AGit
Owner

@⁠Tarraga on GitHub · 2026-11-27 21:25 UTC · original
Tarraga:vibe/rt-shadow-mask-joins-7636bf → main · +445 −0 · 2 files · 1 commits · draft

What this changes

Refs #438.

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)
**@⁠Tarraga** on GitHub · 2026-11-27 21:25 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/466) `Tarraga:vibe/rt-shadow-mask-joins-7636bf` → `main` · +445 −0 · 2 files · 1 commits · draft ## What this changes Refs #438. 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)
Three forms of a per-lane join of a lane mask 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"). Ported from VIctory-macOS 6f8fe556:

- restored_mask: an edge that brings a join of masks (a loop's back edge
  carrying what an inner region left in the register) or a mask spilled to
  VGPR lanes and read back is that join.
- no_mask_lane_through_joins: no_mask_lane_on_edge through joins of masks:
  an edge whose lanes are in none of the masks the other edges bring reads 0,
  with that arm's reasoning (the compiler merges no value for those lanes).
- In wave32 compute, data written along the edge only (a region the other
  lanes skip reused the register for a constant-buffer or descriptor-table
  dword) is no mask for that edge's lanes: the lane's 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), so a mask
  XORed with data stays refused; so does data from before the region
  (dominates_join).

Two of these are guesses, marked in the code and in docs/native-host.md: the
second (as no_mask_lane_on_edge, a reused register where the whole wave
skips) and the third (the mask was dead where its register was reused).

r81 corpus (19,127 containers), main b998bb65 against this:
tools/corpus/compare.sh gives 22 more compute programs translated (19,011 to
19,033), 0 regressions, 0 outputs changed, 2 refused later. 19 come from the
first form; 3 of the 7 ray-traced shadow traces (534b3645dd344ab2,
d50c03da6d935d87, ffd9788ba9fec033) need all three.

Tests: a_loops_mask_its_back_edge_brings_as_a_join_of_masks_lowers,
a_join_of_masks_a_region_made_is_no_mask_for_the_lanes_that_skipped_it and
a_mask_register_reused_for_data_a_region_loads_is_no_mask_for_its_lanes each
fail without their arm; a_mask_joined_with_a_reused_registers_data_lowers
(ported) checks that data from before the region stays refused.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 21:32:06 +00:00
Author
Owner

@⁠Olima34 on GitHub · 2026-11-28 02:00 UTC · original

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 #470 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 #470'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 #470 it translates (expect("refused") panics). Each of the other PRs above passes this test.

Merging:

  • #470 and #452 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 #422 #470 #424 #413 #452 #437 #499 #501 on 86cefd22 (a local integration build, plus the pass-trace fix from #513):

  • World corpus: 302 shaders newly translated and 1 regression (see #437).
  • 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.
**@⁠Olima34** on GitHub · 2026-11-28 02:00 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/466#issuecomment-7232064851) 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 #470 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 #470'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 #470 it translates (`expect("refused")` panics). Each of the other PRs above passes this test. **Merging:** - #470 and #452 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 #422 #470 #424 #413 #452 #437 #499 #501 on 86cefd22 (a local integration build, plus the pass-trace fix from #513): - **World corpus:** 302 shaders newly translated and 1 regression (see #437). - **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 has changes conflicting with the target branch.
  • docs/native-host.md
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/470/head:github-bot/gh-466'
git switch 'github-bot/gh-466'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-466'
git switch 'github-bot/gh-466'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-466'
git switch 'github-bot/gh-466'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-466'
git switch 'main'
git merge --squash 'github-bot/gh-466'
git switch 'main'
git merge --ff-only 'github-bot/gh-466'
git switch 'main'
git merge 'github-bot/gh-466'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.