shader: guard divergent wave64 loop latches and fence flat UAV barriers #141

Manually merged
github merged 3 commits from gh-pr/141/head into gh-pr/141/base 2026-12-01 20:13:00 +00:00
Owner

@⁠Androtim on GitHub · 2026-11-29 15:20 UTC · original
Androtim:feat/iter142-shader-wave64-loop-latches-flat-uav-barriers → main · +674 −8 · 4 files · 3 commits · merged 2026-11-29 21:26 UTC

Ports two DXIL barrier-correctness fixes in victory-shader:

  1. Unconditional loop-latch region exclusion & looped LDS atomic fencing (crates/victory-shader/src/emit/lower.rs):

    • Treats loop-closing branches (b == d) as part of their own divergent region unconditionally in lane_regions_of / branches_around / all_lane_blocks_of instead of gating on PAIR_MEETINGS, preventing group-wide barriers inside divergent Wave64 loops where one 32-lane half exits early.
    • Forms lds_no_meeting (unordered | looped) for lds_meetings and emits barrier(8) for self.lds_looped before the lds_meet branch so looped LDS atomics stay Wave32 without widening.
  2. Flat global store/atomic UAV fencing (crates/victory-shader/src/emit/lower.rs):

    • Includes Fields::Flat global_* non-load operations (global_store_*, global_atomic_*) in writes_uavs so s_barrier emits UAV_FENCE_GLOBAL (mode = 11).
  3. Tests (crates/victory-shader/src/emit/bitcode/census.rs, wave64_tests.rs, intersect_tests.rs):

    • Captures dx.op.barrier modes under #[cfg(test)] in census::barrier_modes.
    • Adds 1-block and 2-block divergent Wave64 loop GPU tests and multi-wave flat store/atomic cross-wave visibility tests.

Verification

  • cargo +1.98.1-x86_64-pc-windows-gnu xtask policy (304 files ok)
  • cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-shader wave64_tests --locked -- --test-threads=1 (19 passed; 0 failed)
  • cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-shader intersect_tests --locked -- --test-threads=1 (8 passed; 0 failed)
  • Dual cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --all-targets (--locked and --features diagnostics --locked, -D warnings)
**@⁠Androtim** on GitHub · 2026-11-29 15:20 UTC · [original](https://github.com/Androtim/MiniVI/pull/141) `Androtim:feat/iter142-shader-wave64-loop-latches-flat-uav-barriers` → `main` · +674 −8 · 4 files · 3 commits · merged 2026-11-29 21:26 UTC Ports two DXIL barrier-correctness fixes in `victory-shader`: 1. **Unconditional loop-latch region exclusion & looped LDS atomic fencing (`crates/victory-shader/src/emit/lower.rs`)**: - Treats loop-closing branches (`b == d`) as part of their own divergent region unconditionally in `lane_regions_of` / `branches_around` / `all_lane_blocks_of` instead of gating on `PAIR_MEETINGS`, preventing group-wide barriers inside divergent Wave64 loops where one 32-lane half exits early. - Forms `lds_no_meeting` (`unordered | looped`) for `lds_meetings` and emits `barrier(8)` for `self.lds_looped` before the `lds_meet` branch so looped LDS atomics stay Wave32 without widening. 2. **Flat global store/atomic UAV fencing (`crates/victory-shader/src/emit/lower.rs`)**: - Includes `Fields::Flat` `global_*` non-load operations (`global_store_*`, `global_atomic_*`) in `writes_uavs` so `s_barrier` emits `UAV_FENCE_GLOBAL` (`mode = 11`). 3. **Tests (`crates/victory-shader/src/emit/bitcode/census.rs`, `wave64_tests.rs`, `intersect_tests.rs`)**: - Captures `dx.op.barrier` modes under `#[cfg(test)]` in `census::barrier_modes`. - Adds 1-block and 2-block divergent Wave64 loop GPU tests and multi-wave flat store/atomic cross-wave visibility tests. ### Verification - `cargo +1.98.1-x86_64-pc-windows-gnu xtask policy` (`304 files ok`) - `cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-shader wave64_tests --locked -- --test-threads=1` (`19 passed; 0 failed`) - `cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-shader intersect_tests --locked -- --test-threads=1` (`8 passed; 0 failed`) - Dual `cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --all-targets` (`--locked` and `--features diagnostics --locked`, `-D warnings`)
Two barrier-correctness fixes in victory-shader DXIL lowering:

1. Unconditionally include loop-closing branches (`b == d`) in their own
   divergent region in `lane_regions_of` instead of gating on
   `PAIR_MEETINGS`. Exempt `lds_order.looped` atomics from `lds_meetings`
   and emit their non-waiting shared-memory fence (`mode = 8`) before checking
   `lds_meet` so looped atomic loops stay Wave32 without widening.

2. Include `Fields::Flat` global stores and atomics (`global_store_*`,
   `global_atomic_*`) in `writes_uavs` so `s_barrier` emits
   `UAV_FENCE_GLOBAL` (bit 2, `mode = 11`) when compute shaders write
   memory exclusively through 64-bit global addresses.

Add GPU execution and DXIL barrier-mode unit tests for 1-block and 2-block
divergent Wave64 loops and cross-wave flat global stores/atomics.
Relax device-count assertions in the new GPU shader tests so lowering,
barrier-mode, and DXIL validation checks run unconditionally while GPU
dispatch runs on available SM 6.6 / Wave32 devices without panicking on
headless CI runners.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 20:12:58 +00:00
github manually merged commit 2bf6800d0d into gh-pr/141/base 2026-12-01 20:13:00 +00:00
Author
Owner

@⁠Androtim on GitHub · 2026-11-29 16:03 UTC · original · edited 2026-11-29 19:03 UTC

Automated triage for the maintainers (not an approval).

Verdict: needs-gpu-test · CI (check): passing

Review Summary

Logic and safety look solid, and CI is passing. Because this PR changes DXIL barrier emission (dx.op.barrier fence/sync modes) and Wave64-to-Wave32 split-LDS lowering in victory-shader, a local real-GPU test pass is recommended before merging.

Verified Changes

  • crates/victory-shader/src/emit/lower.rs (Lower::new, Lower::inst):
    • writes_uavs now includes Fields::Flat instructions starting with global_ and not global_load_ (global_store_*, global_atomic_*), so s_barrier emits UAV_FENCE_GLOBAL (mode = 11 instead of 9) for shaders that only write global memory via flat ops.
    • lds_no_meeting (lds_order.unordered ∪ lds_order.looped) is passed to the lds check and lds_meetings, and Lower::inst now checks self.lds_looped.contains(&(b, i)) before self.lds_meet.as_ref().is_none_or(|(all, _)| all[b]). This keeps looped LDS atomics in Wave32 with a TGSM-only fence (dx.op.barrier(8)) even in non-all-lane blocks.
  • crates/victory-shader/src/emit/bitcode/census.rs:
    • Adds #[cfg(test)]-only BARRIERS tracking and barrier_modes() inspection (no non-test runtime impact).
  • crates/victory-shader/src/emit/intersect_tests.rs & wave64_tests.rs:
    • Adds DXIL barrier-mode, dxil.dll validation, and hardware/WARP dispatch tests for cross-wave flat global stores/atomics (flat_global_stores_and_atomics_fence_uavs_at_group_barriers_across_waves) and 1-/2-block divergent Wave64 loops (one_console_wave_divergent_loop_lds_widens_for_one_and_two_block_loops, one_console_wave_divergent_loop_wave_ops_widen_for_one_and_two_block_loops, divergent_loop_atomics_stay_wave32_with_fence_only).

Minor Note

  • The PR description mentions changing lane_regions_of / branches_around / all_lane_blocks_of to drop the PAIR_MEETINGS gate on b == d, but those functions are not modified in the current diff (presumably already on origin/main or omitted when rebasing). Please update the PR description if that change is already on main.

Local GPU Verification Needed

  • Run the new wave64_tests and intersect_tests on a real SM 6.6 GPU (especially NVIDIA Wave32) to confirm hardware execution passes alongside WARP, and do a quick in-game smoke test covering compute/cloud passes with looped LDS atomics and flat global UAV barriers.

Generated with Antigravity CLI (agy).

**@⁠Androtim** on GitHub · 2026-11-29 16:03 UTC · [original](https://github.com/Androtim/MiniVI/pull/141#issuecomment-7258583795) · edited 2026-11-29 19:03 UTC <!-- minivi-triage v1 head=2bf6800d0d5b3452a23e40f6eeacd2f3e4e72a83 verdict=needs-gpu-test ci=passing at=2026-11-29T19:04:13Z --> Automated triage for the maintainers (not an approval). **Verdict:** `needs-gpu-test` · **CI (`check`):** `passing` ### Review Summary Logic and safety look solid, and CI is passing. Because this PR changes DXIL barrier emission (`dx.op.barrier` fence/sync modes) and Wave64-to-Wave32 split-LDS lowering in `victory-shader`, a local real-GPU test pass is recommended before merging. #### Verified Changes - **`crates/victory-shader/src/emit/lower.rs` (`Lower::new`, `Lower::inst`)**: - `writes_uavs` now includes `Fields::Flat` instructions starting with `global_` and not `global_load_` (`global_store_*`, `global_atomic_*`), so `s_barrier` emits `UAV_FENCE_GLOBAL` (`mode = 11` instead of `9`) for shaders that only write global memory via flat ops. - `lds_no_meeting` (`lds_order.unordered ∪ lds_order.looped`) is passed to the `lds` check and `lds_meetings`, and `Lower::inst` now checks `self.lds_looped.contains(&(b, i))` before `self.lds_meet.as_ref().is_none_or(|(all, _)| all[b])`. This keeps looped LDS atomics in Wave32 with a TGSM-only fence (`dx.op.barrier(8)`) even in non-all-lane blocks. - **`crates/victory-shader/src/emit/bitcode/census.rs`**: - Adds `#[cfg(test)]`-only `BARRIERS` tracking and `barrier_modes()` inspection (no non-test runtime impact). - **`crates/victory-shader/src/emit/intersect_tests.rs` & `wave64_tests.rs`**: - Adds DXIL barrier-mode, `dxil.dll` validation, and hardware/WARP dispatch tests for cross-wave flat global stores/atomics (`flat_global_stores_and_atomics_fence_uavs_at_group_barriers_across_waves`) and 1-/2-block divergent Wave64 loops (`one_console_wave_divergent_loop_lds_widens_for_one_and_two_block_loops`, `one_console_wave_divergent_loop_wave_ops_widen_for_one_and_two_block_loops`, `divergent_loop_atomics_stay_wave32_with_fence_only`). #### Minor Note - The PR description mentions changing `lane_regions_of` / `branches_around` / `all_lane_blocks_of` to drop the `PAIR_MEETINGS` gate on `b == d`, but those functions are not modified in the current diff (presumably already on `origin/main` or omitted when rebasing). Please update the PR description if that change is already on `main`. #### Local GPU Verification Needed - Run the new `wave64_tests` and `intersect_tests` on a real SM 6.6 GPU (especially NVIDIA Wave32) to confirm hardware execution passes alongside WARP, and do a quick in-game smoke test covering compute/cloud passes with looped LDS atomics and flat global UAV barriers. --- _Generated with Antigravity CLI (`agy`)._
Author
Owner

@⁠Androtim on GitHub · 2026-11-29 16:41 UTC · original

Automated RTX 4060 Ti 8 GB A/B hardware verification FAILED visual & texture regression checks (bisected across origin/main 17a2f09 vs playtest/wave4 vs playtest/wave4-no141):

  • Visual regression: With PR #141 included (verify-wave4), character skin/face and neck render severely blown-out white and semi-translucent with background geometry (bookshelf) bleeding through the face (captured frame-3478.png, frame-3502.png; median luma jumped from 39.23 baseline to 96.88).
  • Texture streaming regression: final_waiting regressed +678 (6431 vs 5753 baseline), failing the A/B non-regression gate.
  • Bisect proof: Removing PR #141 while keeping #74 + #145 + #147 (playtest/wave4-no141) immediately restored clean solid skin/lighting (frame-3923.png, frame-3955.png) and passed all 5/5 A/B gates (11.9 fps vs 11.2 fps baseline, -119 MB VRAM, -42% residency stalls).

Please investigate the divergent wave64 loop latch / flat UAV barrier changes in this PR.

**@⁠Androtim** on GitHub · 2026-11-29 16:41 UTC · [original](https://github.com/Androtim/MiniVI/pull/141#issuecomment-7259098360) Automated RTX 4060 Ti 8 GB A/B hardware verification **FAILED** visual & texture regression checks (bisected across `origin/main` `17a2f09` vs `playtest/wave4` vs `playtest/wave4-no141`): - **Visual regression:** With PR #141 included (`verify-wave4`), character skin/face and neck render severely blown-out white and semi-translucent with background geometry (bookshelf) bleeding through the face (captured `frame-3478.png`, `frame-3502.png`; median luma jumped from `39.23` baseline to `96.88`). - **Texture streaming regression:** `final_waiting` regressed `+678` (`6431` vs `5753` baseline), failing the A/B non-regression gate. - **Bisect proof:** Removing PR #141 while keeping #74 + #145 + #147 (`playtest/wave4-no141`) immediately restored clean solid skin/lighting (`frame-3923.png`, `frame-3955.png`) and passed **all 5/5** A/B gates (`11.9 fps` vs `11.2 fps` baseline, `-119 MB` VRAM, `-42%` residency stalls). Please investigate the divergent wave64 loop latch / flat UAV barrier changes in this PR.
Author
Owner

@⁠Androtim on GitHub · 2026-11-29 18:38 UTC · original

Rebased onto origin/main (9d8b3646) and restored PAIR_MEETINGS.get() gating on the loop-latch region exclusion in crates/victory-shader/src/emit/lower.rs (lane_regions_of / all_lane_blocks_of / branches_around and their *_for helpers), keeping Fields::Flat UAV barriers and lds_looped barrier(8) while leaving non-PAIR_MEETINGS translations identical to main. Also wrapped the two new tests in crates/victory-shader/src/emit/wave64_tests.rs in lower::with_pair_meetings.

Verified at 2bf6800d:

  • xtask policy: 305 files ok
  • cargo test -p victory-shader --locked -- wave64_tests: 19 passed; 0 failed
  • cargo test -p victory-shader --locked -- intersect_tests: 8 passed; 0 failed
  • cargo clippy --workspace --locked --all-targets -- -D warnings (default features and --all-features): 0 warnings
  • CI (check): COMPLETED / SUCCESS
  • Live RTX 4060 Ti 8 GB 45s in-world verification (scripts/verify-world.ps1 with --features diagnostics for VICTORY_CAPTURE): all 6 gates passed — 0 crashes, 0 host texture errors, 0 untranslated shaders, max_draws=11242, world_windows=12, VRAM max 5709 MB / budget min 6708 MB, pngs=24 (lit=15/24, median luma 106.45, edge energy 7.62, near-black 0.03%, magenta 0.0%). Visual inspection of captured PNGs confirms solid skin/face shading and lighting without the blown-out translucent visual regression seen when loop-latch exclusion applied unconditionally.
**@⁠Androtim** on GitHub · 2026-11-29 18:38 UTC · [original](https://github.com/Androtim/MiniVI/pull/141#issuecomment-7260643019) Rebased onto `origin/main` (`9d8b3646`) and restored `PAIR_MEETINGS.get()` gating on the loop-latch region exclusion in `crates/victory-shader/src/emit/lower.rs` (`lane_regions_of` / `all_lane_blocks_of` / `branches_around` and their `*_for` helpers), keeping `Fields::Flat` UAV barriers and `lds_looped` `barrier(8)` while leaving non-`PAIR_MEETINGS` translations identical to `main`. Also wrapped the two new tests in `crates/victory-shader/src/emit/wave64_tests.rs` in `lower::with_pair_meetings`. Verified at `2bf6800d`: - `xtask policy`: `305 files ok` - `cargo test -p victory-shader --locked -- wave64_tests`: `19 passed; 0 failed` - `cargo test -p victory-shader --locked -- intersect_tests`: `8 passed; 0 failed` - `cargo clippy --workspace --locked --all-targets -- -D warnings` (default features and `--all-features`): 0 warnings - CI (`check`): `COMPLETED` / `SUCCESS` - Live RTX 4060 Ti 8 GB 45s in-world verification (`scripts/verify-world.ps1` with `--features diagnostics` for `VICTORY_CAPTURE`): all 6 gates passed — 0 crashes, 0 host texture errors, 0 untranslated shaders, `max_draws=11242`, `world_windows=12`, VRAM `max 5709 MB / budget min 6708 MB`, `pngs=24` (`lit=15/24`, median luma `106.45`, edge energy `7.62`, near-black `0.03%`, magenta `0.0%`). Visual inspection of captured PNGs confirms solid skin/face shading and lighting without the blown-out translucent visual regression seen when loop-latch exclusion applied unconditionally.
Author
Owner

@⁠Androtim on GitHub · 2026-11-29 21:26 UTC · original

Automated RTX 4060 Ti 8 GB Open-World A/B hardware verification PASSED (playtest/wave5 vs origin/main b1b6dc1, VICTORY_LEVELS_ON_DEMAND=0 play-parity):

  • Hardware cargo test (RTX 4060 Ti): 645 passed, 0 failed (victory 39/39, victory-shader emit::wave64_tests 19/19 & lower 19/19, victory-gpu 568/568).
  • 45s Open-World A/B (scripts/verify-world.ps1, DLSS Quality + open-world save):
    • FPS: median 9.4 fps vs 7.5 fps (+1.90 fps / +25%), min 8.3 fps vs 0.8 fps, preparing 53.6 ms vs 60.0 ms
    • Stability: 0 crashes / 0 DRED / 0 untranslated shaders
    • VRAM / Issue #149: max 5760 MB vs 6005 MB (-245 MB, 0 MB over budget); no room for new ones halved (9,000 vs 18,000); max_waiting dropped (36,432 vs 41,431)
    • Decoration bakes / Issue #150: 0 mismatches (other_bytes=0, showed_another_view=0, failed=0 vs 5 and 2 on baseline)
    • Residency stalls: mapped_rate 1.63 ms/s vs 6.9 ms/s (-76%, max 12.9 vs 51.9 ms)
    • Visual check: Clean open-world safehouse frames (frame-5975.png, frame-5983.png), edge_energy=4.69 vs 3.88, near_black=0.02%, magenta=0.0% (and #141 2bf6800 showed zero visual artifacts).
**@⁠Androtim** on GitHub · 2026-11-29 21:26 UTC · [original](https://github.com/Androtim/MiniVI/pull/141#issuecomment-7262880443) Automated RTX 4060 Ti 8 GB **Open-World** A/B hardware verification **PASSED** (`playtest/wave5` vs `origin/main` `b1b6dc1`, `VICTORY_LEVELS_ON_DEMAND=0` play-parity): - **Hardware `cargo test` (RTX 4060 Ti):** **645 passed, 0 failed** (`victory` 39/39, `victory-shader` `emit::wave64_tests` 19/19 & `lower` 19/19, `victory-gpu` 568/568). - **45s Open-World A/B (`scripts/verify-world.ps1`, DLSS Quality + open-world save):** - **FPS:** median **`9.4 fps`** vs `7.5 fps` (**+1.90 fps / +25%**), min **`8.3 fps`** vs **`0.8 fps`**, preparing `53.6 ms` vs `60.0 ms` - **Stability:** **0** crashes / **0** DRED / **0** untranslated shaders - **VRAM / Issue #149:** max **`5760 MB`** vs `6005 MB` (**-245 MB**, `0 MB` over budget); `no room for new ones` halved (**`9,000`** vs `18,000`); `max_waiting` dropped (`36,432` vs `41,431`) - **Decoration bakes / Issue #150:** **`0` mismatches** (`other_bytes=0, showed_another_view=0, failed=0` vs `5` and `2` on baseline) - **Residency stalls:** `mapped_rate` **`1.63 ms/s`** vs `6.9 ms/s` (**-76%**, max `12.9` vs `51.9 ms`) - **Visual check:** Clean open-world safehouse frames (`frame-5975.png`, `frame-5983.png`), `edge_energy=4.69` vs `3.88`, `near_black=0.02%`, `magenta=0.0%` (and `#141` `2bf6800` showed zero visual artifacts).
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/Androtim--MiniVI!141
No description provided.