Shaders: ballot divergent-loop masks at reconverged reads (#1498) #1587

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

@⁠Ctrl-Alt-Haze on GitHub · 2026-11-24 19:29 UTC · original
Ctrl-Alt-Haze:fix/shader-1498-divergent-loop-mask → main · +1215 −19 · 3 files · 1 commits · open

Fixes #1498.

Summary

When a lane mask (such as a divergent-loop exit mask s[10:11] or a partial-bit mask updated across loop iterations) is initialized before a loop, updated inside divergent control flow, and later read as data (e.g. s_bcnt1_i32_b64) after the loop reconverges, mask_dword previously always emitted waveActiveBallot at the mask's def_block inside the loop — capturing only the lanes still active on that iteration rather than the full reconverged wave.

This PR adds structured ballot-site placement and sound mask-origin analysis across crates/victory-shader:

  • structure.rs:
    • Structured::ballot_site / covers (compute_ipdom, compute_loops, compute_wave_reach, bounded-monotone compute_writers with a 32-block widening cap) selects BallotSite::Def, BallotSite::Read (reconverged post-loop read site), or None when a mask may hold 1 bits in lanes not active/reconverged at either block ("a lane mask holding lanes elsewhere read as data").
    • same_iter tracking identifies masks provably holding 1 bits only in lanes active in EXEC at their definition block on the same iteration (v_cmp*/v_cmpx*, entry/phi EXEC, and same-block EXEC-bounded SOP ops):
      • When def == read_block, ballot_site returns Some(BallotSite::Read).
      • When def != read_block, ballot_site returns Some(BallotSite::Def) only when !div_loops[def], and explicitly refuses (None) when def is inside a divergent loop (refusing post-loop reads of per-iteration v_cmp masks).
    • promote_phi_masks and phi_mask promote loop-carried phis that receive a derived mask on any edge (including back edges).
  • emit/lower.rs:
    • Marks mask phis in masks/highs as Val::Missing("a lane mask") so mask reads resolve to per-lane i1 phis or wave ballots rather than raw SGPR dwords, and keys cached ballots by (lo, at) (DXIL block) rather than lo alone.
  • Tests (emit/lower.rs, emit/valu_tests.rs, structure.rs):
    • Wave64 + Wave32 #1498 tests, inner-if loop-accumulated mask test, partial-bit subset and earlier-iteration loop-phi GPU tests, refusal tests for reads inside a divergent loop / narrowed branch / outer-initialized mask / post-loop read of a divergent-loop v_cmp, and fresh_vcmp_inside_divergent_loop_counts_active_lanes_per_iteration (verified on both RTX 5070 Ti and WARP).

Clean-room corpus check (victory translate --validate, 26,503 containers / 26,084 programs)

Comparing upstream/main (940d32f) vs #1587 (a8b22d9):

Stage 940d32f emitted / validated a8b22d9 emitted / validated Delta
VP 14,205 / 13,338 14,205 / 13,338 0 / 0
Ms 8,765 / 8,694 8,765 / 8,694 0 / 0
Cs 2,621 / 1,886 2,601 / 1,865 -20 / -21
Total 25,591 / 23,918 25,571 / 23,897 -20 / -21

Pre-emission emit: a lane mask holding lanes elsewhere read as data catches 26 programs cleanly (-21 formerly-validated Cs plus the former lane-mask join of an untracked mask entries, reduced from -138 on 8d1d537), and 1 previously refused Cs now lowers to an existing dxil.dll validation failure.

Tested (a8b22d9, Windows 11 x64, NVIDIA GeForce RTX 5070 Ti + WARP)

  • cargo xtask policy -> asset policy: 182 files ok
  • cargo clippy --workspace --all-targets --locked -- -D warnings -> passed (0 warnings)
  • cargo clippy -p victory-shader --features host --all-targets --locked -- -D warnings -> passed (0 warnings)
  • cargo test --workspace --locked --exclude victory-shader --exclude victory-gpu -> 311 passed, 0 failed, 5 ignored
  • cargo test -p victory-shader --features host --locked -- divergent_loop --test-threads=1 -> 7 passed, 0 failed
  • cargo test -p victory-shader --features host --locked -- --test-threads=1 (RTX 5070 Ti) -> 250 passed, 3 failed, 3 ignored (only pre-existing 940d32f failures: stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride, stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros, synthetic_tests::gathers_at_a_level_match_the_hardware)
  • $env:VICTORY_D3D12_WARP='1'; cargo test -p victory-shader --features host --locked -- --test-threads=1 (WARP) -> 250 passed, 3 failed, 3 ignored (same 3 pre-existing 940d32f failures)
  • cargo test -p victory-gpu --locked -- --test-threads=1 (RTX 5070 Ti) -> 141 passed, 2 failed, 2 ignored (only pre-existing 940d32f failures: descriptor::host::tests::dynamic_slots_are_held_until_released, memory::tests::lists_share_a_table_and_copies_keep_their_views)

AI use: Antigravity (Google DeepMind) implemented, verified on RTX 5070 Ti + WARP, and wrote this PR description.

**@⁠Ctrl-Alt-Haze** on GitHub · 2026-11-24 19:29 UTC · [original](https://github.com/Marvisak/VIctory/pull/1587) `Ctrl-Alt-Haze:fix/shader-1498-divergent-loop-mask` → `main` · +1215 −19 · 3 files · 1 commits · open Fixes #1498. ### Summary When a lane mask (such as a divergent-loop exit mask `s[10:11]` or a partial-bit mask updated across loop iterations) is initialized before a loop, updated inside divergent control flow, and later read as data (e.g. `s_bcnt1_i32_b64`) after the loop reconverges, `mask_dword` previously always emitted `waveActiveBallot` at the mask's `def_block` inside the loop — capturing only the lanes still active on that iteration rather than the full reconverged wave. This PR adds structured ballot-site placement and sound mask-origin analysis across `crates/victory-shader`: - **`structure.rs`**: - `Structured::ballot_site` / `covers` (`compute_ipdom`, `compute_loops`, `compute_wave_reach`, bounded-monotone `compute_writers` with a 32-block widening cap) selects `BallotSite::Def`, `BallotSite::Read` (reconverged post-loop read site), or `None` when a mask may hold `1` bits in lanes not active/reconverged at either block (`"a lane mask holding lanes elsewhere read as data"`). - `same_iter` tracking identifies masks provably holding `1` bits only in lanes active in `EXEC` at their definition block on the same iteration (`v_cmp*`/`v_cmpx*`, entry/`phi` `EXEC`, and same-block `EXEC`-bounded `SOP` ops): - When `def == read_block`, `ballot_site` returns `Some(BallotSite::Read)`. - When `def != read_block`, `ballot_site` returns `Some(BallotSite::Def)` only when `!div_loops[def]`, and explicitly refuses (`None`) when `def` is inside a divergent loop (refusing post-loop reads of per-iteration `v_cmp` masks). - `promote_phi_masks` and `phi_mask` promote loop-carried phis that receive a derived mask on any edge (including back edges). - **`emit/lower.rs`**: - Marks mask phis in `masks`/`highs` as `Val::Missing("a lane mask")` so mask reads resolve to per-lane `i1` phis or wave ballots rather than raw SGPR dwords, and keys cached ballots by `(lo, at)` (DXIL block) rather than `lo` alone. - **Tests (`emit/lower.rs`, `emit/valu_tests.rs`, `structure.rs`)**: - Wave64 + Wave32 `#1498` tests, inner-`if` loop-accumulated mask test, partial-bit subset and earlier-iteration loop-phi GPU tests, refusal tests for reads inside a divergent loop / narrowed branch / outer-initialized mask / post-loop read of a divergent-loop `v_cmp`, and `fresh_vcmp_inside_divergent_loop_counts_active_lanes_per_iteration` (verified on both RTX 5070 Ti and WARP). ### Clean-room corpus check (`victory translate --validate`, 26,503 containers / 26,084 programs) Comparing `upstream/main` (`940d32f`) vs `#1587` (`a8b22d9`): | Stage | `940d32f` emitted / validated | `a8b22d9` emitted / validated | Delta | |---|---:|---:|---:| | VP | 14,205 / 13,338 | 14,205 / 13,338 | 0 / 0 | | Ms | 8,765 / 8,694 | 8,765 / 8,694 | 0 / 0 | | Cs | 2,621 / 1,886 | 2,601 / 1,865 | -20 / -21 | | **Total** | **25,591 / 23,918** | **25,571 / 23,897** | **-20 / -21** | Pre-emission `emit: a lane mask holding lanes elsewhere read as data` catches 26 programs cleanly (`-21` formerly-validated `Cs` plus the former `lane-mask join of an untracked mask` entries, reduced from `-138` on `8d1d537`), and 1 previously refused `Cs` now lowers to an existing `dxil.dll` validation failure. ### Tested (`a8b22d9`, Windows 11 x64, NVIDIA GeForce RTX 5070 Ti + WARP) - `cargo xtask policy` -> `asset policy: 182 files ok` - `cargo clippy --workspace --all-targets --locked -- -D warnings` -> passed (0 warnings) - `cargo clippy -p victory-shader --features host --all-targets --locked -- -D warnings` -> passed (0 warnings) - `cargo test --workspace --locked --exclude victory-shader --exclude victory-gpu` -> **311 passed, 0 failed, 5 ignored** - `cargo test -p victory-shader --features host --locked -- divergent_loop --test-threads=1` -> **7 passed, 0 failed** - `cargo test -p victory-shader --features host --locked -- --test-threads=1` (RTX 5070 Ti) -> **250 passed, 3 failed, 3 ignored** (only pre-existing `940d32f` failures: `stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride`, `stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros`, `synthetic_tests::gathers_at_a_level_match_the_hardware`) - `$env:VICTORY_D3D12_WARP='1'; cargo test -p victory-shader --features host --locked -- --test-threads=1` (WARP) -> **250 passed, 3 failed, 3 ignored** (same 3 pre-existing `940d32f` failures) - `cargo test -p victory-gpu --locked -- --test-threads=1` (RTX 5070 Ti) -> **141 passed, 2 failed, 2 ignored** (only pre-existing `940d32f` failures: `descriptor::host::tests::dynamic_slots_are_held_until_released`, `memory::tests::lists_share_a_table_and_copies_keep_their_views`) **AI use:** Antigravity (Google DeepMind) implemented, verified on RTX 5070 Ti + WARP, and wrote this PR description.
Closes #1498.

Place waveActiveBallot at Def, Read, or None via Structured::ballot_site/covers, compute_ipdom, compute_loops, compute_wave_reach, bounded-monotone compute_writers, and strictly sound same_iter tracking; promote loop-carried phi masks via promote_phi_masks/phi_mask; cache ballots by (lo, at) in Lower; and verify with Wave64/Wave32 unit + GPU tests (including resh_vcmp_inside_divergent_loop_counts_active_lanes_per_iteration).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:37:16 +00:00
Author
Owner

@⁠upipibi on GitHub · 2026-11-24 20:01 UTC · original

Ampere check at ba565a8 (on current main): RTX 3070, driver 616.56, Windows 11.

  • The six #1498 tests pass, including the GPU ones on the hardware adapter: issue_1498_wave32_divergent_loop_mask_counts_all_32_lanes and partial_bit_divergent_loop_mask_counts_exact_subset. They skip only WARP, which has no WaveSize(32).
  • cargo test -p victory-shader: 125 passed, 0 failed, 1 ignored, 2 of 2 runs.

Synthetic tests only, no game files. AI-assisted (Claude Code).

**@⁠upipibi** on GitHub · 2026-11-24 20:01 UTC · [original](https://github.com/Marvisak/VIctory/pull/1587#issuecomment-7142927698) Ampere check at `ba565a8` (on current `main`): RTX 3070, driver 616.56, Windows 11. - The six #1498 tests pass, including the GPU ones on the hardware adapter: `issue_1498_wave32_divergent_loop_mask_counts_all_32_lanes` and `partial_bit_divergent_loop_mask_counts_exact_subset`. They skip only WARP, which has no `WaveSize(32)`. - `cargo test -p victory-shader`: 125 passed, 0 failed, 1 ignored, 2 of 2 runs. Synthetic tests only, no game files. AI-assisted (Claude Code).
Author
Owner

@⁠Ctrl-Alt-Haze on GitHub · 2026-11-24 20:12 UTC · original

@⁠upipibi Thanks for verifying ba565a8 on RTX 3070 (Ampere) across all 6 #1498 tests!

**@⁠Ctrl-Alt-Haze** on GitHub · 2026-11-24 20:12 UTC · [original](https://github.com/Marvisak/VIctory/pull/1587#issuecomment-7143190726) @⁠upipibi Thanks for verifying `ba565a8` on RTX 3070 (Ampere) across all 6 `#1498` tests!
Author
Owner

@⁠Ctrl-Alt-Haze on GitHub · 2026-11-24 22:06 UTC · original

Rebased onto upstream main (70564ae) at 4c8eb15:

  • Merged ballot_site into mask_dword while preserving 8af0472's mask_number fallback for non-active masks.
  • Updated case 3 of divergent_loop_mask_read_inside_loop_or_narrowed_branch_is_refused so the non-loop s_not_b32 narrowed-branch case asserts the upstream 8af0472 whole-wave lowering (while keeping the divergent-loop inside-loop, narrowed-EXEC, and nonzero pre-if refusal cases).
  • Added 70564ae's new HostShader fields to build_wave32_uav_cs.

Verified locally on Windows 11 x64 / NVIDIA GeForce RTX 5070 Ti + WARP:

  • cargo xtask policy: passed (174 files ok)
  • cargo clippy --workspace --all-targets --locked -- -D warnings (default & --all-features): passed
  • Targeted divergent_loop tests: 6 passed; 0 failed
  • Workspace non-gpu/non-shader crates (--locked -- --test-threads=1): victory 1 passed, victory-core 11 passed, victory-formats 23 passed / 4 ignored, victory-game 15 passed, victory-hle 99 passed (97 unit + 1 fidelityfx + 1 no_dll_planting), victory-loader 25 passed (22 unit + 2 load_probe + 1 title_dlls), victory-pe 7 passed, victory-pipeline 4 passed, xtask 4 passed
  • cargo test -p victory-gpu --locked -- --test-threads=1: 76 passed; 2 failed; 1 ignored (pre-existing on clean 70564ae: dynamic_slots_are_held_until_released, lists_share_a_table_and_copies_keep_their_views)
  • cargo test -p victory-shader --features host --locked (hardware): 211 passed; 3 failed; 2 ignored (pre-existing on clean 70564ae on RTX 5070 Ti: stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride, stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros, synthetic_tests::gathers_at_a_level_match_the_hardware)
  • VICTORY_WARP=1 cargo test -p victory-shader --features host --locked: 212 passed; 2 failed; 2 ignored (pre-existing gathers_at_a_level_match_the_hardware + permutes_read_the_lane_named_and_zero_from_lanes_left_out which skips under VICTORY_WARP=1 and passed on RTX hardware)
**@⁠Ctrl-Alt-Haze** on GitHub · 2026-11-24 22:06 UTC · [original](https://github.com/Marvisak/VIctory/pull/1587#issuecomment-7145811984) Rebased onto upstream `main` (`70564ae`) at `4c8eb15`: - Merged `ballot_site` into `mask_dword` while preserving `8af0472`'s `mask_number` fallback for non-active masks. - Updated case 3 of `divergent_loop_mask_read_inside_loop_or_narrowed_branch_is_refused` so the non-loop `s_not_b32` narrowed-branch case asserts the upstream `8af0472` whole-wave lowering (while keeping the divergent-loop inside-loop, narrowed-EXEC, and nonzero pre-`if` refusal cases). - Added `70564ae`'s new `HostShader` fields to `build_wave32_uav_cs`. Verified locally on Windows 11 x64 / NVIDIA GeForce RTX 5070 Ti + WARP: - `cargo xtask policy`: passed (174 files ok) - `cargo clippy --workspace --all-targets --locked -- -D warnings` (default & `--all-features`): passed - Targeted `divergent_loop` tests: `6 passed; 0 failed` - Workspace non-gpu/non-shader crates (`--locked -- --test-threads=1`): `victory` 1 passed, `victory-core` 11 passed, `victory-formats` 23 passed / 4 ignored, `victory-game` 15 passed, `victory-hle` 99 passed (97 unit + 1 `fidelityfx` + 1 `no_dll_planting`), `victory-loader` 25 passed (22 unit + 2 `load_probe` + 1 `title_dlls`), `victory-pe` 7 passed, `victory-pipeline` 4 passed, `xtask` 4 passed - `cargo test -p victory-gpu --locked -- --test-threads=1`: `76 passed; 2 failed; 1 ignored` (pre-existing on clean `70564ae`: `dynamic_slots_are_held_until_released`, `lists_share_a_table_and_copies_keep_their_views`) - `cargo test -p victory-shader --features host --locked` (hardware): `211 passed; 3 failed; 2 ignored` (pre-existing on clean `70564ae` on RTX 5070 Ti: `stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride`, `stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros`, `synthetic_tests::gathers_at_a_level_match_the_hardware`) - `VICTORY_WARP=1 cargo test -p victory-shader --features host --locked`: `212 passed; 2 failed; 2 ignored` (pre-existing `gathers_at_a_level_match_the_hardware` + `permutes_read_the_lane_named_and_zero_from_lanes_left_out` which skips under `VICTORY_WARP=1` and passed on RTX hardware)
Author
Owner

@⁠upipibi on GitHub · 2026-11-24 22:15 UTC · original

At 4c8eb15 (on main 70564ae) the victory-shader tests don't build:

error[E0063]: missing fields `heap`, `heap_writes`, `memory` and 3 other fields in initializer of `emit::HostShader`
    --> crates\victory-shader\src\emit\valu_tests.rs:1521:18

That is build_wave32_uav_cs: main's HostShader gained fields since the first version. main's build_valu_cs (line 145) sets them. Adding the same six lines after root_srvs fixes it:

        root_uavs: lowered.root_uavs,
        memory: lowered.memory,
        memory_writes: lowered.memory_writes,
        view_addresses: lowered.view_addresses,
        heap: lowered.heap,
        heap_writes: lowered.heap_writes,

With that applied locally (RTX 3070, driver 616.56, Windows 11):

  • issue_1498_wave64_divergent_loop_mask_ballots_after_loop, issue_1498_wave32_divergent_loop_mask_counts_all_32_lanes and partial_bit_divergent_loop_mask_counts_exact_subset pass.
  • cargo test -p victory-shader --locked: 211 passed, 3 failed, 2 ignored, 2 of 2 runs. The 3 are the NVIDIA heap-size failures #1744 reports on main (a_heap_buffer_read_where_no_buffer_view_is_reads_zeros, a_heap_buffer_read_by_element_takes_the_views_stride, gathers_at_a_level_match_the_hardware), not this PR.

AI-assisted (Claude Code). Synthetic tests only.

**@⁠upipibi** on GitHub · 2026-11-24 22:15 UTC · [original](https://github.com/Marvisak/VIctory/pull/1587#issuecomment-7146002539) At `4c8eb15` (on `main` `70564ae`) the `victory-shader` tests don't build: ``` error[E0063]: missing fields `heap`, `heap_writes`, `memory` and 3 other fields in initializer of `emit::HostShader` --> crates\victory-shader\src\emit\valu_tests.rs:1521:18 ``` That is `build_wave32_uav_cs`: `main`'s `HostShader` gained fields since the first version. `main`'s `build_valu_cs` (line 145) sets them. Adding the same six lines after `root_srvs` fixes it: ```rust root_uavs: lowered.root_uavs, memory: lowered.memory, memory_writes: lowered.memory_writes, view_addresses: lowered.view_addresses, heap: lowered.heap, heap_writes: lowered.heap_writes, ``` With that applied locally (RTX 3070, driver 616.56, Windows 11): - `issue_1498_wave64_divergent_loop_mask_ballots_after_loop`, `issue_1498_wave32_divergent_loop_mask_counts_all_32_lanes` and `partial_bit_divergent_loop_mask_counts_exact_subset` pass. - `cargo test -p victory-shader --locked`: 211 passed, 3 failed, 2 ignored, 2 of 2 runs. The 3 are the NVIDIA heap-size failures #1744 reports on `main` (`a_heap_buffer_read_where_no_buffer_view_is_reads_zeros`, `a_heap_buffer_read_by_element_takes_the_views_stride`, `gathers_at_a_level_match_the_hardware`), not this PR. AI-assisted (Claude Code). Synthetic tests only.
Author
Owner

@⁠Ctrl-Alt-Haze on GitHub · 2026-11-25 00:05 UTC · original

@⁠upipibi Good catch — thank you! The six HostShader fields in crates/victory-shader/src/emit/valu_tests.rs (build_wave32_uav_cs) had been left uncommitted in the worktree when 4c8eb15 was pushed.

Committed and force-pushed as 0b0a670 on 70564ae.

Re-verified locally on 0b0a670 (Windows 11 x64 / NVIDIA GeForce RTX 5070 Ti + WARP):

  • cargo xtask policy: passed (174 files ok)
  • cargo clippy --workspace --all-targets --locked -- -D warnings (default & --all-features): passed
  • cargo test -p victory-shader --features host --locked -- divergent_loop --test-threads=1: 6 passed; 0 failed
  • cargo test -p victory-shader --locked -- --test-threads=1: 211 passed; 3 failed; 2 ignored (only the 3 pre-existing 70564ae RTX 5070 Ti failures: stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride, stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros, synthetic_tests::gathers_at_a_level_match_the_hardware)
  • cargo test -p victory-shader --features host --locked -- --test-threads=1: 211 passed; 3 failed; 2 ignored (same 3 pre-existing failures)
  • VICTORY_WARP=1 cargo test -p victory-shader --features host --locked -- --test-threads=1: 212 passed; 2 failed; 2 ignored (pre-existing gathers_at_a_level_match_the_hardware + permutes_read_the_lane_named_and_zero_from_lanes_left_out)
  • Workspace non-gpu/non-shader crates (--locked -- --test-threads=1): victory 1 passed, victory-core 11 passed, victory-formats 23 passed / 4 ignored, victory-game 15 passed, victory-hle 99 passed (97 unit + 1 fidelityfx + 1 no_dll_planting), victory-loader 25 passed (22 unit + 2 load_probe + 1 title_dlls), victory-pe 7 passed, victory-pipeline 4 passed, xtask 4 passed
  • cargo test -p victory-gpu --locked -- --test-threads=1: 76 passed; 2 failed; 1 ignored (pre-existing on clean 70564ae: dynamic_slots_are_held_until_released, lists_share_a_table_and_copies_keep_their_views)
**@⁠Ctrl-Alt-Haze** on GitHub · 2026-11-25 00:05 UTC · [original](https://github.com/Marvisak/VIctory/pull/1587#issuecomment-7148136321) @⁠upipibi Good catch — thank you! The six `HostShader` fields in `crates/victory-shader/src/emit/valu_tests.rs` (`build_wave32_uav_cs`) had been left uncommitted in the worktree when `4c8eb15` was pushed. Committed and force-pushed as `0b0a670` on `70564ae`. Re-verified locally on `0b0a670` (Windows 11 x64 / NVIDIA GeForce RTX 5070 Ti + WARP): - `cargo xtask policy`: passed (`174 files ok`) - `cargo clippy --workspace --all-targets --locked -- -D warnings` (default & `--all-features`): passed - `cargo test -p victory-shader --features host --locked -- divergent_loop --test-threads=1`: `6 passed; 0 failed` - `cargo test -p victory-shader --locked -- --test-threads=1`: `211 passed; 3 failed; 2 ignored` (only the 3 pre-existing `70564ae` RTX 5070 Ti failures: `stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride`, `stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros`, `synthetic_tests::gathers_at_a_level_match_the_hardware`) - `cargo test -p victory-shader --features host --locked -- --test-threads=1`: `211 passed; 3 failed; 2 ignored` (same 3 pre-existing failures) - `VICTORY_WARP=1 cargo test -p victory-shader --features host --locked -- --test-threads=1`: `212 passed; 2 failed; 2 ignored` (pre-existing `gathers_at_a_level_match_the_hardware` + `permutes_read_the_lane_named_and_zero_from_lanes_left_out`) - Workspace non-gpu/non-shader crates (`--locked -- --test-threads=1`): `victory` 1 passed, `victory-core` 11 passed, `victory-formats` 23 passed / 4 ignored, `victory-game` 15 passed, `victory-hle` 99 passed (97 unit + 1 `fidelityfx` + 1 `no_dll_planting`), `victory-loader` 25 passed (22 unit + 2 `load_probe` + 1 `title_dlls`), `victory-pe` 7 passed, `victory-pipeline` 4 passed, `xtask` 4 passed - `cargo test -p victory-gpu --locked -- --test-threads=1`: `76 passed; 2 failed; 1 ignored` (pre-existing on clean `70564ae`: `dynamic_slots_are_held_until_released`, `lists_share_a_table_and_copies_keep_their_views`)
Author
Owner

@⁠upipibi on GitHub · 2026-11-25 00:25 UTC · original

Re-checked 0b0a670 on the RTX 3070 (driver 616.56, Windows 11, debug). cargo test -p victory-shader --locked gives 211 passed, 3 failed, 2 ignored. The 3 are #1744's NVIDIA failures on main (the two stride_tests heap-buffer reads and gathers_at_a_level_match_the_hardware). The build_wave32_uav_cs fields are in, and the six #1498 divergent-loop tests pass on Ampere's 32-lane waves.

AI-assisted (Claude Code).

**@⁠upipibi** on GitHub · 2026-11-25 00:25 UTC · [original](https://github.com/Marvisak/VIctory/pull/1587#issuecomment-7148495731) Re-checked `0b0a670` on the RTX 3070 (driver 616.56, Windows 11, debug). `cargo test -p victory-shader --locked` gives 211 passed, 3 failed, 2 ignored. The 3 are #1744's NVIDIA failures on `main` (the two `stride_tests` heap-buffer reads and `gathers_at_a_level_match_the_hardware`). The `build_wave32_uav_cs` fields are in, and the six `#1498` divergent-loop tests pass on Ampere's 32-lane waves. AI-assisted (Claude Code).
Author
Owner

@⁠Ctrl-Alt-Haze on GitHub · 2026-11-25 00:41 UTC · original

@⁠upipibi Thanks for re-checking 0b0a670 on RTX 3070 and confirming all 6 #1498 tests pass on Ampere!

Rebased onto upstream main (4118f33) at 8d1d537 (switched Structured::phi_mask to use upstream #1221's exposed Structured::other map in crates/victory-shader/src/structure.rs and preserved all 4118f33 additions).

Re-verified locally on 8d1d537 (Windows 11 x64 / NVIDIA GeForce RTX 5070 Ti + WARP):

  • cargo xtask policy: passed (182 files ok)
  • cargo clippy --workspace --all-targets --locked -- -D warnings (default & --all-features): passed
  • cargo test -p victory-shader --features host --locked -- divergent_loop --test-threads=1: 6 passed; 0 failed
  • cargo test -p victory-shader --locked -- --test-threads=1: 248 passed; 3 failed; 3 ignored (pre-existing 4118f33 RTX 5070 Ti failures: stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride, stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros, synthetic_tests::gathers_at_a_level_match_the_hardware)
  • cargo test -p victory-shader --features host --locked -- --test-threads=1: 248 passed; 3 failed; 3 ignored (same 3 pre-existing failures)
  • VICTORY_WARP=1 cargo test -p victory-shader --features host --locked -- --test-threads=1: 249 passed; 2 failed; 3 ignored (pre-existing gathers_at_a_level_match_the_hardware + permutes_read_the_lane_named_and_zero_from_lanes_left_out)
  • Workspace non-gpu/non-shader crates (--locked -- --test-threads=1): all passed (victory 12 [10 unit + 2 census], victory-core 13, victory-formats 38 / 5 ignored, victory-game 15, victory-hle 145 [143 unit + 1 fidelityfx + 1 no_dll_planting], victory-loader 38 [34 unit + 1 crash_log + 2 load_probe + 1 title_dlls], victory-pe 36, victory-pipeline 7, xtask 6)
  • cargo test -p victory-gpu --locked -- --test-threads=1: 139 passed; 2 failed; 2 ignored (pre-existing 4118f33 failures: descriptor::host::tests::dynamic_slots_are_held_until_released, memory::tests::lists_share_a_table_and_copies_keep_their_views)
**@⁠Ctrl-Alt-Haze** on GitHub · 2026-11-25 00:41 UTC · [original](https://github.com/Marvisak/VIctory/pull/1587#issuecomment-7148773278) @⁠upipibi Thanks for re-checking `0b0a670` on RTX 3070 and confirming all 6 `#1498` tests pass on Ampere! Rebased onto upstream `main` (`4118f33`) at `8d1d537` (switched `Structured::phi_mask` to use upstream `#1221`'s exposed `Structured::other` map in `crates/victory-shader/src/structure.rs` and preserved all `4118f33` additions). Re-verified locally on `8d1d537` (Windows 11 x64 / NVIDIA GeForce RTX 5070 Ti + WARP): - `cargo xtask policy`: passed (`182 files ok`) - `cargo clippy --workspace --all-targets --locked -- -D warnings` (default & `--all-features`): passed - `cargo test -p victory-shader --features host --locked -- divergent_loop --test-threads=1`: `6 passed; 0 failed` - `cargo test -p victory-shader --locked -- --test-threads=1`: `248 passed; 3 failed; 3 ignored` (pre-existing `4118f33` RTX 5070 Ti failures: `stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride`, `stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros`, `synthetic_tests::gathers_at_a_level_match_the_hardware`) - `cargo test -p victory-shader --features host --locked -- --test-threads=1`: `248 passed; 3 failed; 3 ignored` (same 3 pre-existing failures) - `VICTORY_WARP=1 cargo test -p victory-shader --features host --locked -- --test-threads=1`: `249 passed; 2 failed; 3 ignored` (pre-existing `gathers_at_a_level_match_the_hardware` + `permutes_read_the_lane_named_and_zero_from_lanes_left_out`) - Workspace non-gpu/non-shader crates (`--locked -- --test-threads=1`): all passed (`victory` 12 [10 unit + 2 `census`], `victory-core` 13, `victory-formats` 38 / 5 ignored, `victory-game` 15, `victory-hle` 145 [143 unit + 1 `fidelityfx` + 1 `no_dll_planting`], `victory-loader` 38 [34 unit + 1 `crash_log` + 2 `load_probe` + 1 `title_dlls`], `victory-pe` 36, `victory-pipeline` 7, `xtask` 6) - `cargo test -p victory-gpu --locked -- --test-threads=1`: `139 passed; 2 failed; 2 ignored` (pre-existing `4118f33` failures: `descriptor::host::tests::dynamic_slots_are_held_until_released`, `memory::tests::lists_share_a_table_and_copies_keep_their_views`)
Author
Owner

@⁠sinan-cmyk on GitHub · 2026-11-25 02:55 UTC · original

Offline measurement on a retail dump (head 8d1d537 on main 940d32f)

Result: 0 gained, 138 lost. Every changed program now stops at "a lane mask holding lanes elsewhere read as data". That matches the PR's stated intent: refuse a mask read inside a divergent loop, or at a point that does not cover all its writers, instead of counting it wrongly (#1498).

Build Validated Change
main 940d32f 23,918
this PR (8d1d537, clean merge) 23,780 −138

What changes:

  • 138 programs that validate on main are refused. If the analysis is right, these are programs whose lane-mask reads main translates but may count wrongly. This is the cost of the soundness check on this data.
  • 691 programs that main emits but the validator rejects ("Entry function performs some operation that is incompatible with the shader stage") are now refused before emission, with the lane-mask reason. That replaces invalid DXIL with an explicit refusal.
  • 7 more programs move to the same reason from other lane-mask reasons.

The counts can't tell whether the 138 really count wrongly on main. A hardware test on one of those patterns (as in your [32; 32] repro) would confirm it. For reference, the older head ba565a8 on main ffe310e lost 230 programs, all to the same reason.

Method: victory translate --validate --list on shaders.rpf (1.0.2.1), dxil.dll 1.8.2502.11, compared program by program (25,889 programs). AI-assisted (Claude Code). No shader names or data are included, per the asset policy.

**@⁠sinan-cmyk** on GitHub · 2026-11-25 02:55 UTC · [original](https://github.com/Marvisak/VIctory/pull/1587#issuecomment-7151365693) ### Offline measurement on a retail dump (head 8d1d537 on `main` 940d32f) **Result: 0 gained, 138 lost.** Every changed program now stops at "a lane mask holding lanes elsewhere read as data". That matches the PR's stated intent: refuse a mask read inside a divergent loop, or at a point that does not cover all its writers, instead of counting it wrongly (#1498). | Build | Validated | Change | |---|---|---| | `main` 940d32f | 23,918 | | | this PR (8d1d537, clean merge) | 23,780 | **−138** | What changes: - **138 programs that validate on `main` are refused.** If the analysis is right, these are programs whose lane-mask reads `main` translates but may count wrongly. This is the cost of the soundness check on this data. - **691 programs that `main` emits but the validator rejects** ("Entry function performs some operation that is incompatible with the shader stage") are now refused before emission, with the lane-mask reason. That replaces invalid DXIL with an explicit refusal. - 7 more programs move to the same reason from other lane-mask reasons. The counts can't tell whether the 138 really count wrongly on `main`. A hardware test on one of those patterns (as in your `[32; 32]` repro) would confirm it. For reference, the older head ba565a8 on `main` ffe310e lost 230 programs, all to the same reason. Method: `victory translate --validate --list` on `shaders.rpf` (1.0.2.1), dxil.dll 1.8.2502.11, compared program by program (25,889 programs). AI-assisted (Claude Code). No shader names or data are included, per the asset policy.
Author
Owner

@⁠Ctrl-Alt-Haze on GitHub · 2026-11-25 03:07 UTC · original

@⁠sinan-cmyk Thank you for running the program-by-program 940d32f vs 8d1d537 census on shaders.rpf (25,889 programs) and confirming zero false gains alongside the 691 invalid-DXIL programs moved to explicit pre-emission refusal and the 138 potentially miscounted lane-mask reads refused under #1498.

**@⁠Ctrl-Alt-Haze** on GitHub · 2026-11-25 03:07 UTC · [original](https://github.com/Marvisak/VIctory/pull/1587#issuecomment-7151620306) @⁠sinan-cmyk Thank you for running the program-by-program `940d32f` vs `8d1d537` census on `shaders.rpf` (`25,889` programs) and confirming zero false gains alongside the `691` invalid-DXIL programs moved to explicit pre-emission refusal and the `138` potentially miscounted lane-mask reads refused under `#1498`.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 03:30 UTC · original · edited 2026-11-25 15:53 UTC

Automated triage for the maintainers.

This pull request no longer merges cleanly into main (conflicts in crates/victory-shader/src/emit/lower.rs). It will be reviewed once it is rebased onto the current main. The earlier verdict (merge candidate) was for an older state of main.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 03:30 UTC · [original](https://github.com/Marvisak/VIctory/pull/1587#issuecomment-7151983092) · edited 2026-11-25 15:53 UTC <!-- victory-triage v1 head=a8b22d95e3ac4d3593d505460b4860d46108ea22 verdict=needs-rebase at=2026-11-25T15:53:30Z --> Automated triage for the maintainers. This pull request no longer merges cleanly into `main` (conflicts in `crates/victory-shader/src/emit/lower.rs`). It will be reviewed once it is rebased onto the current `main`. The earlier verdict (merge candidate) was for an older state of `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠Ctrl-Alt-Haze on GitHub · 2026-11-25 05:58 UTC · original

Thanks Marvisak, @catminou4, and @sinan-cmyk for the reviews and census feedback! Rebased cleanly onto upstream/main (940d32f) and force-pushed 6e35c2e addressing every point:

  1. Compile fix on 940d32f (@catminou4 E0063): Added view_marks: false to lower::Parts and view_marks: lowered.view_marks to HostShader in crates/victory-shader/src/emit/valu_tests.rs, changed build_wave32_uav_cs to return HostShader, and included the 42363ab/ccfb029 headless-WARP test skips via the 940d32f rebase.
  2. Test-only API & cleanup (Marvisak): Removed ballot_ir_blocks from Lowered / Lower / mask_dword (the #1498 lowering tests now assert st.ballot_site(...) directly on s_bcnt1 mask operands), removed the stray parenthetical comment in lower.rs, and restored single-line paired_masks formatting in structure.rs.
  3. compute_writers monotonicity & compute_wave_reach (Marvisak): Replaced non-monotone Writers::and cycling (max_iters = dynamic * blocks) with bounded monotone widening (EXACT_ROUNDS = 16, MAX_WRITER_ROUNDS = 64, 32-block cap -> Writers::Wave) so large cyclic phis converge deterministically, and precomputed post_loop_headers outside the compute_wave_reach loop.
  4. False refusals & same_iter (@sinan-cmyk census): Root-caused the -138 (74 Ps + 64 Cs) delta to non-loop active masks (whose Atom::Quad / narrowed-EXEC reach isn't implied by wave_reach) and same-iteration v_cmp reads inside divergent loops. Added strictly sound same_iter tracking (only v_cmp*/v_cmpx*, entry/phi EXEC, and same-block EXEC-bounded SOP ops) plus fresh_vcmp_inside_divergent_loop_counts_active_lanes_per_iteration (verified on RTX 5070 Ti + WARP).
    • Clean-room victory translate --validate corpus delta (940d32f -> 6e35c2e) dropped from -138 to -16 Cs (0 VP / 0 Ms lost; pre_if_nonzero_init still strictly refused).

Verified on 6e35c2e (Windows 11 x64, RTX 5070 Ti + WARP):

  • cargo xtask policy: 182 files ok
  • Both cargo clippy gates (--workspace and -p victory-shader --features host) with --all-targets --locked -- -D warnings: 0 warnings
  • cargo test --workspace --locked --exclude victory-shader --exclude victory-gpu: 311 passed, 0 failed, 5 ignored
  • divergent_loop tests (victory-shader --features host): 7 passed, 0 failed
  • Full victory-shader (RTX 5070 Ti & WARP): 250 passed, 3 failed, 3 ignored (only the 3 pre-existing 940d32f stride_tests / synthetic_tests::gathers failures)
  • Full victory-gpu (RTX 5070 Ti): 141 passed, 2 failed, 2 ignored (only the 2 pre-existing 940d32f dynamic_slots / lists_share_a_table failures)
**@⁠Ctrl-Alt-Haze** on GitHub · 2026-11-25 05:58 UTC · [original](https://github.com/Marvisak/VIctory/pull/1587#issuecomment-7154316554) Thanks `Marvisak`, `@catminou4`, and `@sinan-cmyk` for the reviews and census feedback! Rebased cleanly onto `upstream/main` (`940d32f`) and force-pushed `6e35c2e` addressing every point: 1. **Compile fix on `940d32f` (`@catminou4` `E0063`)**: Added `view_marks: false` to `lower::Parts` and `view_marks: lowered.view_marks` to `HostShader` in `crates/victory-shader/src/emit/valu_tests.rs`, changed `build_wave32_uav_cs` to return `HostShader`, and included the `42363ab`/`ccfb029` headless-WARP test skips via the `940d32f` rebase. 2. **Test-only API & cleanup (`Marvisak`)**: Removed `ballot_ir_blocks` from `Lowered` / `Lower` / `mask_dword` (the `#1498` lowering tests now assert `st.ballot_site(...)` directly on `s_bcnt1` mask operands), removed the stray parenthetical comment in `lower.rs`, and restored single-line `paired_masks` formatting in `structure.rs`. 3. **`compute_writers` monotonicity & `compute_wave_reach` (`Marvisak`)**: Replaced non-monotone `Writers::and` cycling (`max_iters = dynamic * blocks`) with bounded monotone widening (`EXACT_ROUNDS = 16`, `MAX_WRITER_ROUNDS = 64`, 32-block cap -> `Writers::Wave`) so large cyclic phis converge deterministically, and precomputed `post_loop_headers` outside the `compute_wave_reach` loop. 4. **False refusals & `same_iter` (`@sinan-cmyk` census)**: Root-caused the `-138` (`74 Ps + 64 Cs`) delta to non-loop `active` masks (whose `Atom::Quad` / narrowed-`EXEC` reach isn't implied by `wave_reach`) and same-iteration `v_cmp` reads inside divergent loops. Added strictly sound `same_iter` tracking (only `v_cmp*`/`v_cmpx*`, entry/`phi` `EXEC`, and same-block `EXEC`-bounded `SOP` ops) plus `fresh_vcmp_inside_divergent_loop_counts_active_lanes_per_iteration` (verified on RTX 5070 Ti + WARP). - Clean-room `victory translate --validate` corpus delta (`940d32f` -> `6e35c2e`) dropped from `-138` to **`-16` Cs** (`0` VP / `0` Ms lost; `pre_if_nonzero_init` still strictly refused). **Verified on `6e35c2e` (Windows 11 x64, RTX 5070 Ti + WARP):** - `cargo xtask policy`: `182 files ok` - Both `cargo clippy` gates (`--workspace` and `-p victory-shader --features host`) with `--all-targets --locked -- -D warnings`: 0 warnings - `cargo test --workspace --locked --exclude victory-shader --exclude victory-gpu`: `311 passed, 0 failed, 5 ignored` - `divergent_loop` tests (`victory-shader --features host`): `7 passed, 0 failed` - Full `victory-shader` (`RTX 5070 Ti` & `WARP`): `250 passed, 3 failed, 3 ignored` (only the 3 pre-existing `940d32f` `stride_tests` / `synthetic_tests::gathers` failures) - Full `victory-gpu` (`RTX 5070 Ti`): `141 passed, 2 failed, 2 ignored` (only the 2 pre-existing `940d32f` `dynamic_slots` / `lists_share_a_table` failures)
Author
Owner

@⁠nathanbzrr on GitHub · 2026-11-25 06:44 UTC · original

AMD RDNA3 + DXIL 1.8.2502 verification on 6e35c2e8, empirical Wave32 counterexample reproduction, and a verified fix for Structured::ballot_site (#1498):

Environment

  • Windows 11 10.0.26340 x64, rustc 1.98.1 (x86_64-pc-windows-msvc)
  • GPU: AMD Radeon RX 7600 (RDNA3, driver 32.0.32029.2010, Wave32 supported; D3D12 WARP is Wave 4..=4 so Wave32 valu_tests skip on WARP)
  • DXIL validator: Windows SDK dxil.dll 1.8.2502.11
  • Scope: synthetic victory-shader tests only (no game files / title not run)

Baseline on 6e35c2e8

  • cargo test -p victory-shader --locked: 253 passed, 0 failed, 3 ignored
  • cargo clippy -p victory-shader --all-targets --locked -- -D warnings: 0 warnings

Empirical Wave32 counterexample (reproducing the same_iter + div_loops[def] bug)
In crates/victory-shader/src/structure.rs:571-577, when self.same_iter.contains(&lo) and def != read_block, ballot_site returns Some(BallotSite::Def) without checking !self.div_loops[def].

Running a synthetic Wave32 compute kernel where lanes 0..7 exit a divergent loop on iteration 0 and lanes 8..31 exit on iteration 1 (v_cmp_eq_u32 vcc_lo, 0, v1 inside the loop body, then s_bcnt1_i32_b32 s9, vcc_lo after reconvergence) on unmodified 6e35c2e8 produces on AMD Radeon RX 7600:

[8, 8, 8, 8, 8, 8, 8, 8, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24]

Lanes 0..7 retain iteration 0's ballot (8) and lanes 8..31 see iteration 1's (24), whereas console SGPR semantics overwrite vcc_lo on the final iteration so every lane reads uniform 24.

Note also why returning None inside the same_iter branch (rather than falling through to covers(lo, m, read_block)) matters: every lane exited with its own bit set in vcc_lo, so falling through to BallotSite::Read via covers would count all 32 lanes instead of refusing the overwrite.

Minimal fix & regression test (nathanbzrr/VIctory@a58e4f4, branch review/pr-1587-div-loop-def-refusal)

--- a/crates/victory-shader/src/structure.rs
+++ b/crates/victory-shader/src/structure.rs
@@ -569,11 +569,13 @@ impl Structured {
         let &m = self.masks.get(&lo)?;
         let def = def_block.unwrap_or(self.entry);
         if self.same_iter.contains(&lo) {
-            return Some(if def == read_block {
-                BallotSite::Read
+            return if def == read_block {
+                Some(BallotSite::Read)
+            } else if !self.div_loops.get(def).copied().unwrap_or(true) {
+                Some(BallotSite::Def)
             } else {
-                BallotSite::Def
-            });
+                None
+            };
         }

Plus regression test divergent_loop_vcmp_read_after_reconvergence_is_refused in crates/victory-shader/src/emit/lower.rs.

Verified after the fix:

  • cargo test -p victory-shader --locked: 254 passed, 0 failed, 3 ignored
  • cargo clippy -p victory-shader --all-targets --locked -- -D warnings: 0 warnings
  • cargo xtask policy: asset policy: 182 files ok

AI-assisted review/testing; all builds and GPU runs executed locally on my own machine. No game files used.

**@⁠nathanbzrr** on GitHub · 2026-11-25 06:44 UTC · [original](https://github.com/Marvisak/VIctory/pull/1587#issuecomment-7155114340) AMD RDNA3 + DXIL 1.8.2502 verification on `6e35c2e8`, empirical Wave32 counterexample reproduction, and a verified fix for `Structured::ballot_site` (#1498): **Environment** - Windows 11 `10.0.26340` x64, `rustc 1.98.1` (`x86_64-pc-windows-msvc`) - GPU: **AMD Radeon RX 7600** (RDNA3, driver `32.0.32029.2010`, Wave32 supported; D3D12 WARP is Wave 4..=4 so Wave32 `valu_tests` skip on WARP) - DXIL validator: Windows SDK `dxil.dll 1.8.2502.11` - Scope: synthetic `victory-shader` tests only (no game files / title not run) **Baseline on `6e35c2e8`** - `cargo test -p victory-shader --locked`: **253 passed, 0 failed, 3 ignored** - `cargo clippy -p victory-shader --all-targets --locked -- -D warnings`: **0 warnings** **Empirical Wave32 counterexample (reproducing the `same_iter` + `div_loops[def]` bug)** In `crates/victory-shader/src/structure.rs:571-577`, when `self.same_iter.contains(&lo)` and `def != read_block`, `ballot_site` returns `Some(BallotSite::Def)` without checking `!self.div_loops[def]`. Running a synthetic Wave32 compute kernel where lanes `0..7` exit a divergent loop on iteration 0 and lanes `8..31` exit on iteration 1 (`v_cmp_eq_u32 vcc_lo, 0, v1` inside the loop body, then `s_bcnt1_i32_b32 s9, vcc_lo` after reconvergence) on unmodified `6e35c2e8` produces on **AMD Radeon RX 7600**: ```text [8, 8, 8, 8, 8, 8, 8, 8, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24] ``` Lanes `0..7` retain iteration 0's ballot (`8`) and lanes `8..31` see iteration 1's (`24`), whereas console SGPR semantics overwrite `vcc_lo` on the final iteration so every lane reads uniform `24`. Note also why returning `None` inside the `same_iter` branch (rather than falling through to `covers(lo, m, read_block)`) matters: every lane exited with its own bit set in `vcc_lo`, so falling through to `BallotSite::Read` via `covers` would count all `32` lanes instead of refusing the overwrite. **Minimal fix & regression test (`nathanbzrr/VIctory@a58e4f4`, branch `review/pr-1587-div-loop-def-refusal`)** ```diff --- a/crates/victory-shader/src/structure.rs +++ b/crates/victory-shader/src/structure.rs @@ -569,11 +569,13 @@ impl Structured { let &m = self.masks.get(&lo)?; let def = def_block.unwrap_or(self.entry); if self.same_iter.contains(&lo) { - return Some(if def == read_block { - BallotSite::Read + return if def == read_block { + Some(BallotSite::Read) + } else if !self.div_loops.get(def).copied().unwrap_or(true) { + Some(BallotSite::Def) } else { - BallotSite::Def - }); + None + }; } ``` Plus regression test `divergent_loop_vcmp_read_after_reconvergence_is_refused` in `crates/victory-shader/src/emit/lower.rs`. Verified after the fix: - `cargo test -p victory-shader --locked`: **254 passed, 0 failed, 3 ignored** - `cargo clippy -p victory-shader --all-targets --locked -- -D warnings`: **0 warnings** - `cargo xtask policy`: `asset policy: 182 files ok` *AI-assisted review/testing; all builds and GPU runs executed locally on my own machine. No game files used.*
Author
Owner

@⁠Ctrl-Alt-Haze on GitHub · 2026-11-25 06:47 UTC · original

Thanks Marvisak for catching that remaining cross-block same_iter case! Updated and force-pushed a8b22d9 on top of 940d32f:

  1. Structured::ballot_site (crates/victory-shader/src/structure.rs): For same_iter masks read in another block (def != read_block), now returns Some(BallotSite::Def) only when !self.div_loops[def] and explicitly returns None (refusing) when div_loops[def] is true, rather than falling through to covers(read_block).
  2. Regression test (crates/victory-shader/src/emit/lower.rs): Added vcmp_in_div_loop_read_after inside divergent_loop_mask_read_inside_loop_or_narrowed_branch_is_refused asserting that reading a divergent-loop v_cmp mask (vcc_lo) via s_bcnt1 after the loop reconverges refuses with "a lane mask holding lanes elsewhere read as data".
  3. Fresh clean-room victory translate --validate (940d32f -> a8b22d9, 26,503 containers / 26,084 programs):
    • VP: 14,205 / 13,338 -> 14,205 / 13,338 (0 / 0)
    • Ms: 8,765 / 8,694 -> 8,765 / 8,694 (0 / 0)
    • Cs: 2,621 / 1,886 -> 2,601 / 1,865 (-20 / -21; 26 refused pre-emission with a lane mask holding lanes elsewhere read as data)
  4. Verified on a8b22d9 (Windows 11 x64, RTX 5070 Ti + WARP):
    • cargo xtask policy: 182 files ok, both cargo clippy --all-targets --locked -- -D warnings gates: 0 warnings
    • Non-GPU workspace (--exclude victory-shader --exclude victory-gpu): 311 passed, 0 failed, 5 ignored
    • divergent_loop tests (victory-shader --features host): 7 passed, 0 failed
    • victory-shader --features host (RTX 5070 Ti & WARP): 250 passed, 3 failed, 3 ignored (only the 3 pre-existing 940d32f stride_tests / synthetic_tests::gathers failures)
    • victory-gpu (RTX 5070 Ti): 141 passed, 2 failed, 2 ignored (only the 2 pre-existing 940d32f dynamic_slots / lists_share_a_table failures)
**@⁠Ctrl-Alt-Haze** on GitHub · 2026-11-25 06:47 UTC · [original](https://github.com/Marvisak/VIctory/pull/1587#issuecomment-7155152836) Thanks `Marvisak` for catching that remaining cross-block `same_iter` case! Updated and force-pushed `a8b22d9` on top of `940d32f`: 1. **`Structured::ballot_site` (`crates/victory-shader/src/structure.rs`)**: For `same_iter` masks read in another block (`def != read_block`), now returns `Some(BallotSite::Def)` only when `!self.div_loops[def]` and explicitly returns `None` (refusing) when `div_loops[def]` is true, rather than falling through to `covers(read_block)`. 2. **Regression test (`crates/victory-shader/src/emit/lower.rs`)**: Added `vcmp_in_div_loop_read_after` inside `divergent_loop_mask_read_inside_loop_or_narrowed_branch_is_refused` asserting that reading a divergent-loop `v_cmp` mask (`vcc_lo`) via `s_bcnt1` after the loop reconverges refuses with `"a lane mask holding lanes elsewhere read as data"`. 3. **Fresh clean-room `victory translate --validate` (`940d32f` -> `a8b22d9`, 26,503 containers / 26,084 programs)**: - **VP**: `14,205 / 13,338` -> `14,205 / 13,338` (`0 / 0`) - **Ms**: `8,765 / 8,694` -> `8,765 / 8,694` (`0 / 0`) - **Cs**: `2,621 / 1,886` -> `2,601 / 1,865` (`-20 / -21`; `26` refused pre-emission with `a lane mask holding lanes elsewhere read as data`) 4. **Verified on `a8b22d9` (Windows 11 x64, RTX 5070 Ti + WARP)**: - `cargo xtask policy`: `182 files ok`, both `cargo clippy --all-targets --locked -- -D warnings` gates: 0 warnings - Non-GPU workspace (`--exclude victory-shader --exclude victory-gpu`): `311 passed, 0 failed, 5 ignored` - `divergent_loop` tests (`victory-shader --features host`): `7 passed, 0 failed` - `victory-shader --features host` (RTX 5070 Ti & WARP): `250 passed, 3 failed, 3 ignored` (only the 3 pre-existing `940d32f` `stride_tests` / `synthetic_tests::gathers` failures) - `victory-gpu` (RTX 5070 Ti): `141 passed, 2 failed, 2 ignored` (only the 2 pre-existing `940d32f` `dynamic_slots` / `lists_share_a_table` failures)
Author
Owner

@⁠Ctrl-Alt-Haze on GitHub · 2026-11-25 06:56 UTC · original

@⁠nathanbzrr Thank you for running the AMD Radeon RX 7600 (RDNA3) verification and capturing that exact [8..8, 24..24] Wave32 counterexample! Commit a8b22d9 (pushed just after your comment) applies that exact explicit None return in Structured::ballot_site when same_iter && def != read_block && div_loops[def] alongside the vcmp_in_div_loop_read_after refusal test, and GitHub Actions check is green on a8b22d9.

**@⁠Ctrl-Alt-Haze** on GitHub · 2026-11-25 06:56 UTC · [original](https://github.com/Marvisak/VIctory/pull/1587#issuecomment-7155315143) @⁠nathanbzrr Thank you for running the AMD Radeon RX 7600 (RDNA3) verification and capturing that exact `[8..8, 24..24]` Wave32 counterexample! Commit `a8b22d9` (pushed just after your comment) applies that exact explicit `None` return in `Structured::ballot_site` when `same_iter && def != read_block && div_loops[def]` alongside the `vcmp_in_div_loop_read_after` refusal test, and GitHub Actions `check` is green on `a8b22d9`.
Author
Owner

@⁠Dathinel on GitHub · 2026-11-25 13:31 UTC · original

Hardware data point for a8b22d9 on wave32, with the D3D12 debug layer on (local probe patch enabling ID3D12Debug, InfoQueue checked after each dispatch: 0 errors in every run). RTX 3050 Laptop, driver 610.62, Windows 11 26200. WARP here does not support WaveSize(32), so only hardware ran.

I added one case to your build_wave32_uav_cs helpers: lane l runs min(l/8, 2) iterations, and each iteration overwrites the mask (s_mov_b32 s21, vcc_lo) before s_andn2 exec drops the leaving lanes. After the loop, s21 is read as data (v_mov v2, s21 and s_bcnt1 s9, s21). On the console every lane reads the last iteration's compare, 0xFFFF0000 / 16.

940d32f sources a8b22d9
s21 as data lanes 0-7 0xFF, 8-15 0xFF00, 16-31 0xFFFF0000, no error refused: "a lane mask holding lanes elsewhere read as data"
s_bcnt1 of s21 8 / 8 / 16, no error refused
your #1498 case 1 in all lanes 32 in all lanes

So the PR turns this silent wrong result into an explicit refusal, and fixes #1498 on real wave32 hardware. The same silent result occurs in the JMAN730/project-flamingo fork (JMAN730/project-flamingo#92), which has the same mask_dword placement.

AI-assisted; synthetic shaders only. Probe diff available on request.

**@⁠Dathinel** on GitHub · 2026-11-25 13:31 UTC · [original](https://github.com/Marvisak/VIctory/pull/1587#issuecomment-7163910815) Hardware data point for `a8b22d9` on wave32, with the D3D12 debug layer on (local probe patch enabling `ID3D12Debug`, InfoQueue checked after each dispatch: 0 errors in every run). RTX 3050 Laptop, driver 610.62, Windows 11 26200. WARP here does not support `WaveSize(32)`, so only hardware ran. I added one case to your `build_wave32_uav_cs` helpers: lane `l` runs `min(l/8, 2)` iterations, and each iteration *overwrites* the mask (`s_mov_b32 s21, vcc_lo`) before `s_andn2 exec` drops the leaving lanes. After the loop, s21 is read as data (`v_mov v2, s21` and `s_bcnt1 s9, s21`). On the console every lane reads the last iteration's compare, `0xFFFF0000` / 16. | | `940d32f` sources | `a8b22d9` | |---|---|---| | s21 as data | lanes 0-7 `0xFF`, 8-15 `0xFF00`, 16-31 `0xFFFF0000`, no error | refused: "a lane mask holding lanes elsewhere read as data" | | `s_bcnt1` of s21 | 8 / 8 / 16, no error | refused | | your #1498 case | 1 in all lanes | 32 in all lanes | So the PR turns this silent wrong result into an explicit refusal, and fixes #1498 on real wave32 hardware. The same silent result occurs in the JMAN730/project-flamingo fork (JMAN730/project-flamingo#92), which has the same `mask_dword` placement. AI-assisted; synthetic shaders only. Probe diff available on request.
Author
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-11-26 13:10 UTC · original

I resolved the current lower.rs and valu_tests.rs conflicts on 48bf778. Your exact a8b22d9 is the first parent and upstream 63bcca4 is the second. The merge combines phi_mask with main's BVH number/edge fallbacks. The PR’s lowerer tests are in a test submodule so lower.rs stays within the file-size limit. The upstream ds_bpermute and legacy-multiply tests are included.

The #1498 Wave32 readback and the partial-bit/earlier-iteration cases passed on WARP 1.0.22 with Agility 1.620.2. The integrated tree also passed 36 lowerer tests, 13 structure tests (1 ignored), 14 BVH tests, strict shader Clippy and policy.

There is one WARP result worth carrying forward. On both the untouched a8b22d9 and the merge, fresh_vcmp_inside_divergent_loop_counts_active_lanes_per_iteration produced the same error. The first four lanes were correct. Zero-based lanes 4, 8 and 31 gave 29, 26 and 8, where the test expects 28, 24 and 1. The full VALU group went from 30 passing + 1 failing on your head to 37 passing + the same 1 failing on the merge. VICTORY_WARP=1 was set and I verified the app-local DLLs loaded in both processes.

cargo test --locked -p victory-shader --lib emit::valu_tests::fresh_vcmp_inside_divergent_loop_counts_active_lanes_per_iteration -- --exact --nocapture --test-threads=1

You can take the integration branch as a fast-forward from a8b22d9. If you reuse the integration work, please retain its Git author, or add Co-authored-by: andrewpozdnakov7-jpg <[email protected]> if folding it into another commit.

AI-assisted with Codex.

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-11-26 13:10 UTC · [original](https://github.com/Marvisak/VIctory/pull/1587#issuecomment-7192968833) I resolved the current `lower.rs` and `valu_tests.rs` conflicts on [48bf778](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/48bf7786740afbb533ab296669facb7619f33306). Your exact `a8b22d9` is the first parent and upstream `63bcca4` is the second. The merge combines `phi_mask` with main's BVH number/edge fallbacks. The PR’s lowerer tests are in a test submodule so `lower.rs` stays within the file-size limit. The upstream `ds_bpermute` and legacy-multiply tests are included. The #1498 Wave32 readback and the partial-bit/earlier-iteration cases passed on WARP 1.0.22 with Agility 1.620.2. The integrated tree also passed 36 lowerer tests, 13 structure tests (1 ignored), 14 BVH tests, strict shader Clippy and policy. There is one WARP result worth carrying forward. On **both** the untouched `a8b22d9` and the merge, `fresh_vcmp_inside_divergent_loop_counts_active_lanes_per_iteration` produced the same error. The first four lanes were correct. Zero-based lanes 4, 8 and 31 gave 29, 26 and 8, where the test expects 28, 24 and 1. The full VALU group went from 30 passing + 1 failing on your head to 37 passing + the same 1 failing on the merge. `VICTORY_WARP=1` was set and I verified the app-local DLLs loaded in both processes. ```text cargo test --locked -p victory-shader --lib emit::valu_tests::fresh_vcmp_inside_divergent_loop_counts_active_lanes_per_iteration -- --exact --nocapture --test-threads=1 ``` You can take the integration branch as a fast-forward from `a8b22d9`. If you reuse the integration work, please retain its Git author, or add `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>` if folding it into another commit. AI-assisted with Codex.
This pull request has changes conflicting with the target branch.
  • crates/victory-shader/src/emit/lower.rs
  • crates/victory-shader/src/emit/valu_tests.rs
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/1587/head:github-bot/gh-1587'
git switch 'github-bot/gh-1587'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1587'
git switch 'github-bot/gh-1587'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1587'
git switch 'github-bot/gh-1587'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1587'
git switch 'main'
git merge --squash 'github-bot/gh-1587'
git switch 'main'
git merge --ff-only 'github-bot/gh-1587'
git switch 'main'
git merge 'github-bot/gh-1587'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!1587
No description provided.