Shaders: handle dead mask dwords at data joins and wave-uniform s_bcnt1 SCC #1269

Closed
Sakura-Byte wants to merge 1 commit from upstream-pr/1269 into main
Sakura-Byte commented 2026-11-24 16:58:23 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Sakura-Byte on 2026-11-24T16:58:23Z.


Fixes #878.

Summary

  • Dead lane-mask dwords at data joins (fill_phis): When a scalar register previously held a lane-mask dword before being overwritten on the live data path, the dead mask dword incoming edge at a phi that has at least one live scalar data (Val::I32) predecessor now lowers to undef on the mask edge rather than failing the whole join as a mask read, while mask-only joins continue to be rejected.
  • Wave-uniform SCC from s_bcnt1 and mask SOP ops (mask_sccs, mask_any, mask_any_in):
    • Tracks SCC values produced by exact-width s_bcnt1_i32_b32 (Wave32) / s_bcnt1_i32_b64 (Wave64) on tracked lane masks, saveexec forms, and mask-writing SOP ops.
    • Lowers those SCC uses (directly via get or across Reg::Scc phis in fill_phis) as dx.op.waveActiveBallot(...) != 0 so SCC stays wave-uniform on Wave32 and Wave64 without per-lane divergence (avoiding the Wave32 scc_lane regression noted on the earlier attempt).
    • Keeps numeric popcount reads of s_bcnt1's scalar destination rejected in MaskData::None and rejects mismatched-width s_bcnt1_i32_b32 in Wave64 programs.

Files Changed

  • crates/victory-shader/src/emit/lower.rs: mask_sccs, is_mask_value, mask_scc_source, mask_any, mask_any_in, updated get / fill_phis, and synthetic DXIL/WARP tests (mask_dword_at_data_join_emits_undef_and_rejects_mask_only_joins, s_bcnt1_scc_only_translates_while_numeric_popcount_still_fails, s_bcnt1_scc_branch_stays_wave_uniform_on_warp).
  • crates/victory-shader/src/emit/bitcode.rs: #[cfg(test)] inspection helpers Module::func_names and Module::inst_lines.

Verification

Ran cleanly on clean origin/main (ffe310e):

  • cargo xtask policy: asset policy: 154 files ok
  • cargo clippy --workspace --all-targets --locked -- -D warnings: passed (0 warnings)
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: passed (0 warnings)
  • VICTORY_D3D12_WARP=1 VICTORY_WARP=1 cargo test -p victory-shader --locked -- --test-threads=1: 123 passed; 0 failed; 1 ignored (only the existing release-only benchmark emit::bitcode::tests::bench_write is ignored; dxil.dll validation ran; in s_bcnt1_scc_branch_stays_wave_uniform_on_warp, the Wave32 Mesh shader executes end-to-end on WARP checking [0.75, 0.75, 0.75, 1.0], and the Wave32 Compute shader verifies dx.op.waveActiveBallot, cmp:33 ... k0 (!= 0), and dxil.dll validation while skipping fixed [WaveSize(32)] PSO creation on WARP which returns E_INVALIDARG).

AI-assisted; synthetic tests only, zero game assets.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6587066032 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1269). Originally posted by [Sakura-Byte](https://github.com/Sakura-Byte) on 2026-11-24T16:58:23Z. --- Fixes #878. ### Summary - **Dead lane-mask dwords at data joins (`fill_phis`)**: When a scalar register previously held a lane-mask dword before being overwritten on the live data path, the dead mask dword incoming edge at a `phi` that has at least one live scalar data (`Val::I32`) predecessor now lowers to `undef` on the mask edge rather than failing the whole join as a mask read, while mask-only joins continue to be rejected. - **Wave-uniform SCC from `s_bcnt1` and mask SOP ops (`mask_sccs`, `mask_any`, `mask_any_in`)**: - Tracks SCC values produced by exact-width `s_bcnt1_i32_b32` (Wave32) / `s_bcnt1_i32_b64` (Wave64) on tracked lane masks, `saveexec` forms, and mask-writing SOP ops. - Lowers those SCC uses (directly via `get` or across `Reg::Scc` phis in `fill_phis`) as `dx.op.waveActiveBallot(...) != 0` so SCC stays wave-uniform on Wave32 and Wave64 without per-lane divergence (avoiding the Wave32 `scc_lane` regression noted on the earlier attempt). - Keeps numeric popcount reads of `s_bcnt1`'s scalar destination rejected in `MaskData::None` and rejects mismatched-width `s_bcnt1_i32_b32` in Wave64 programs. ### Files Changed - `crates/victory-shader/src/emit/lower.rs`: `mask_sccs`, `is_mask_value`, `mask_scc_source`, `mask_any`, `mask_any_in`, updated `get` / `fill_phis`, and synthetic DXIL/WARP tests (`mask_dword_at_data_join_emits_undef_and_rejects_mask_only_joins`, `s_bcnt1_scc_only_translates_while_numeric_popcount_still_fails`, `s_bcnt1_scc_branch_stays_wave_uniform_on_warp`). - `crates/victory-shader/src/emit/bitcode.rs`: `#[cfg(test)]` inspection helpers `Module::func_names` and `Module::inst_lines`. ### Verification Ran cleanly on clean `origin/main` (`ffe310e`): - `cargo xtask policy`: `asset policy: 154 files ok` - `cargo clippy --workspace --all-targets --locked -- -D warnings`: passed (0 warnings) - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: passed (0 warnings) - `VICTORY_D3D12_WARP=1 VICTORY_WARP=1 cargo test -p victory-shader --locked -- --test-threads=1`: `123 passed; 0 failed; 1 ignored` (only the existing release-only benchmark `emit::bitcode::tests::bench_write` is ignored; `dxil.dll` validation ran; in `s_bcnt1_scc_branch_stays_wave_uniform_on_warp`, the Wave32 Mesh shader executes end-to-end on WARP checking `[0.75, 0.75, 0.75, 1.0]`, and the Wave32 Compute shader verifies `dx.op.waveActiveBallot`, `cmp:33 ... k0` (`!= 0`), and `dxil.dll` validation while skipping fixed `[WaveSize(32)]` PSO creation on WARP which returns `E_INVALIDARG`). *AI-assisted; synthetic tests only, zero game assets.*
pablogonz12 commented 2026-11-24 17:04:48 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by pablogonz12 on 2026-11-24T17:03:16Z.


Setup: Linux, RX 9070 XT, RADV (Mesa 26.3.1), dxil-spirv master, spirv-val 1.3. Your head folded onto a base of origin/main ffe310e plus #1017 — main's host build is broken without it (E0425 host_resource in victory-gpu), so the base is that pair. Ran the four-stage offline check (translate, dxil-spirv, spirv-val, RADV pipeline) over 768 programs: the 751-program world dump plus a 52-program BVH capture, 35 duplicate containers skipped.

translate valid SPIR-V RADV pipeline
base 666 / 768 656 656
your head 666 / 768 656 656

No program gained or lost. The only difference in the failure table: two compute programs that read a lane mask as data now report "a lane mask holding lanes elsewhere read as data" instead of "a lane mask read as data", which is the new distinction working. No new failure, same 10 SPIR-V validation failures as the base.

Not tested: in-game.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7138613652 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1269#issuecomment-7138613652). Originally posted by [pablogonz12](https://github.com/pablogonz12) on 2026-11-24T17:03:16Z. --- Setup: Linux, RX 9070 XT, RADV (Mesa 26.3.1), dxil-spirv master, spirv-val 1.3. Your head folded onto a base of origin/main `ffe310e` plus #1017 — main's host build is broken without it (`E0425 host_resource` in `victory-gpu`), so the base is that pair. Ran the four-stage offline check (translate, dxil-spirv, spirv-val, RADV pipeline) over 768 programs: the 751-program world dump plus a 52-program BVH capture, 35 duplicate containers skipped. | | translate | valid SPIR-V | RADV pipeline | |---|---|---|---| | base | 666 / 768 | 656 | 656 | | your head | 666 / 768 | 656 | 656 | No program gained or lost. The only difference in the failure table: two compute programs that read a lane mask as data now report "a lane mask holding lanes elsewhere read as data" instead of "a lane mask read as data", which is the new distinction working. No new failure, same 10 SPIR-V validation failures as the base. Not tested: in-game.
catminou4 commented 2026-11-24 18:04:27 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T17:06:56Z.

Review: APPROVED


Dead mask dwords at data joins emit undef instead of a stale ballot, scalar ops writing tracked masks (and s_bcnt1 testing them) get their SCC mapped back to the mask's low dword (saveexec forms map EXEC's new value), so wave-uniform SCC branches on masks translate. Structure tests for the join/undef and s_bcnt1 SCC cases run on macOS. Local verification: macOS arm64, rustc 1.98.1, PR head merged into main ffe310e, cargo test -p victory-shader --locked. Shader execution tests (valu_tests/host) are #[cfg(all(test, windows))], so macOS covers lowering/decode/unit tests only. 98 passed, 0 failed. Note: adds the same #[cfg(test)] op_names/insts helpers as #1275 — the second of the two to land will conflict textually.

<!-- greyfinch-sync:Marvisak/VIctory:review:6043854150 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1269#pullrequestreview-6043854150). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T17:06:56Z. **Review:** APPROVED --- Dead mask dwords at data joins emit undef instead of a stale ballot, scalar ops writing tracked masks (and s_bcnt1 testing them) get their SCC mapped back to the mask's low dword (saveexec forms map EXEC's new value), so wave-uniform SCC branches on masks translate. Structure tests for the join/undef and s_bcnt1 SCC cases run on macOS. Local verification: macOS arm64, rustc 1.98.1, PR head merged into main ffe310e, `cargo test -p victory-shader --locked`. Shader execution tests (valu_tests/host) are `#[cfg(all(test, windows))]`, so macOS covers lowering/decode/unit tests only. 98 passed, 0 failed. Note: adds the same #[cfg(test)] op_names/insts helpers as #1275 — the second of the two to land will conflict textually.
rafaconvaitis commented 2026-11-24 18:05:35 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by rafaconvaitis on 2026-11-24T17:13:01Z.


I replayed the two mesh-shader containers reported as the largest and packed drops in the recent update-9 run on #293. Both runtime hash prefixes resolved in the local shader archive. Here is the direct comparison on Windows 11 build 26300 with the RTX 4070 selected explicitly.

Runtime shader hash main ffe310e #1269 8c3092f #1269 + #953 c42cbb0
ef5409053e14aa82 lane mask read as data scalar memory read as data descriptor address or format read as data
235e56869c1ea883 scalar memory read as data scalar memory read as data descriptor address or format read as data

#1269 gets the first program past the lane-mask refusal. Adding #953 makes both reach the remaining descriptor-data case tracked in #798. Both still stop before DXIL validation or D3D12 PSO creation in the tested builds. These are offline translation results, so the in-game dropped-draw counts remain unmeasured for the stack.

AI-assisted test harness and reporting.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7138861276 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1269#issuecomment-7138861276). Originally posted by [rafaconvaitis](https://github.com/rafaconvaitis) on 2026-11-24T17:13:01Z. --- I replayed the two mesh-shader containers reported as the largest and packed drops in the recent update-9 run on #293. Both runtime hash prefixes resolved in the local shader archive. Here is the direct comparison on Windows 11 build 26300 with the RTX 4070 selected explicitly. | Runtime shader hash | main `ffe310e` | #1269 `8c3092f` | #1269 + #953 `c42cbb0` | | --- | --- | --- | --- | | `ef5409053e14aa82` | lane mask read as data | scalar memory read as data | descriptor address or format read as data | | `235e56869c1ea883` | scalar memory read as data | scalar memory read as data | descriptor address or format read as data | #1269 gets the first program past the lane-mask refusal. Adding #953 makes both reach the remaining descriptor-data case tracked in #798. Both still stop before DXIL validation or D3D12 PSO creation in the tested builds. These are offline translation results, so the in-game dropped-draw counts remain unmeasured for the stack. AI-assisted test harness and reporting.
upstream-sync closed this pull request 2026-11-25 01:06:05 +00:00
Marvisak commented 2026-11-25 01:08:07 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:36:15Z.


Automated triage for the maintainers. Closing because this change is already in main, or main has since replaced the code it patches.

Stale mask dwords at data joins and bit counts of masks in mesh programs are both handled in main (dead_on_edge/live_edges/joins_loaded in fill_phis; host-wave bit count for mesh). This version gives the mask edge undef whenever another edge carries data, which is the unsound shortcut main moved away from.

If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148684917 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1269#issuecomment-7148684917). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:36:15Z. --- Automated triage for the maintainers. Closing because this change is already in `main`, or `main` has since replaced the code it patches. Stale mask dwords at data joins and bit counts of masks in mesh programs are both handled in main (dead_on_edge/live_edges/joins_loaded in fill_phis; host-wave bit count for mesh). This version gives the mask edge undef whenever another edge carries data, which is the unsound shortcut main moved away from. If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

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
Marvisak/VIctory!1269
No description provided.