Shaders: retry barrier-free all-lane forms on native wave64 hosts #558

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

@⁠tulerws on GitHub · 2026-11-25 02:14 UTC · original
tulerws:fix/wave64-needs-every-lane → main · +212 −11 · 3 files · 1 commits · open

Problem

On native wave64 hosts (HOST_MAX_WAVE != 32, e.g. AMD RDNA 3/4), compute shaders that hit a needs_every_lane refusal (a wave sum of 16-bit floats where not every lane runs in Lower::half_sum, or a lane mask holding lanes elsewhere read as data in Lower::mask_dword) fail immediately:

  1. Lower::half_sum only recorded need(self.cur_ir) when halves == true (two-wave32 emulation), skipping native wave64.
  2. Lower::mask_dword only considered whole / need(...) when self.exchange.is_some(), even though a native wave64 compute shader with threads % 64 == 0 already has all 64 lanes present in every all_lane_blocks block.
  3. emit::emit() gated its early-out/skip/widen retry path on lower::host_max_wave() == 32, even though widen() already allows native wave64 (!(native.wave64 && lower::host_max_wave() == 32)) and none of these forms adds group barriers on native wave64.

As a result, b22a16a178976e1b translated cleanly on wave32 hosts (without early-outs) while failing on native wave64 hosts, and 926c46bab3b86bd6 failed on both.

Fix

  • crates/victory-shader/src/emit/lower.rs:
    • Record need(self.cur_ir) in half_sum on native wave64 as well as wave32 halves.
    • In mask_dword, treat all_lane_blocks as whole-wave when lowering native wave64 compute shaders whose thread-group size is a multiple of 64, and record need(made) when a mask holding lanes outside EXEC sits in a per-lane region.
  • crates/victory-shader/src/emit/mod.rs:
    • When emit_program fails on a native wave64 compute shader with lower::needs_every_lane(what), retry without_early_outs, without_skips(false), without_skips(true) (respecting VICTORY_WAVE_DEEP_SKIPS), and widen() (respecting VICTORY_WAVE_WIDE, no group barriers added).
  • crates/victory-shader/src/emit/wave64_tests.rs:
    • Added two clean-room hardware GPU tests (TEST_HOST_WAVE = Some(64)):
      • native_wave64_half_sum_inside_early_out_translates_and_runs_exact
      • native_wave64_mask_outside_exec_inside_branch_translates_and_runs_exact

Verification

  • cargo test -p victory-shader on AMD Radeon RX 9070 (RDNA 4): 216 passed, 0 failed (both new tests validated with dxil.dll and executed on hardware GPU).
  • cargo clippy -p victory-shader --all-targets -- -D warnings: pass (0 warnings).
  • cargo xtask policy: pass (169 files ok).
  • Full shader sweep (VICTORY_HOST_MAX_WAVE=64):
    • Compute shaders emitted: 2,672 → 2,676 / 2,682 (+4, 0 regressions).
    • a wave sum of 16-bit floats where not every lane runs: 2 → 0 (b22a16a178976e1b validates with dxil.dll and creates D3D12 pipeline).
    • a lane mask holding lanes elsewhere read as data: 2 → 0 (926c46bab3b86bd6 widens 14 branches with 0 barriers, validates with dxil.dll, and creates D3D12 pipeline).

Overlap note

  • Open PR #203 also fixes the 2 half_sum programs on native wave64 via half_sum_present (without widening early-outs). The mask_dword whole-wave fix (926c46bab3b86bd6) and the general native-wave64 needs_every_lane retry path in emit/mod.rs are not covered by #203 or other open PRs. Happy to rebase/drop the half_sum one-liner if #203 merges first.

AI-assisted (Antigravity); verified locally on AMD Radeon RX 9070. Hashes, counts, and clean-room tests only; no game data.

**@⁠tulerws** on GitHub · 2026-11-25 02:14 UTC · [original](https://github.com/fxceless/victory-fork/pull/558) `tulerws:fix/wave64-needs-every-lane` → `main` · +212 −11 · 3 files · 1 commits · open ## Problem On native wave64 hosts (`HOST_MAX_WAVE != 32`, e.g. AMD RDNA 3/4), compute shaders that hit a `needs_every_lane` refusal (`a wave sum of 16-bit floats where not every lane runs` in `Lower::half_sum`, or `a lane mask holding lanes elsewhere read as data` in `Lower::mask_dword`) fail immediately: 1. `Lower::half_sum` only recorded `need(self.cur_ir)` when `halves == true` (two-wave32 emulation), skipping native wave64. 2. `Lower::mask_dword` only considered `whole` / `need(...)` when `self.exchange.is_some()`, even though a native wave64 compute shader with `threads % 64 == 0` already has all 64 lanes present in every `all_lane_blocks` block. 3. `emit::emit()` gated its early-out/skip/widen retry path on `lower::host_max_wave() == 32`, even though `widen()` already allows native wave64 (`!(native.wave64 && lower::host_max_wave() == 32)`) and none of these forms adds group barriers on native wave64. As a result, `b22a16a178976e1b` translated cleanly on wave32 hosts (`without early-outs`) while failing on native wave64 hosts, and `926c46bab3b86bd6` failed on both. ## Fix - **`crates/victory-shader/src/emit/lower.rs`**: - Record `need(self.cur_ir)` in `half_sum` on native wave64 as well as wave32 halves. - In `mask_dword`, treat `all_lane_blocks` as whole-wave when lowering native wave64 compute shaders whose thread-group size is a multiple of 64, and record `need(made)` when a mask holding lanes outside `EXEC` sits in a per-lane region. - **`crates/victory-shader/src/emit/mod.rs`**: - When `emit_program` fails on a native wave64 compute shader with `lower::needs_every_lane(what)`, retry `without_early_outs`, `without_skips(false)`, `without_skips(true)` (respecting `VICTORY_WAVE_DEEP_SKIPS`), and `widen()` (respecting `VICTORY_WAVE_WIDE`, no group barriers added). - **`crates/victory-shader/src/emit/wave64_tests.rs`**: - Added two clean-room hardware GPU tests (`TEST_HOST_WAVE = Some(64)`): - `native_wave64_half_sum_inside_early_out_translates_and_runs_exact` - `native_wave64_mask_outside_exec_inside_branch_translates_and_runs_exact` ## Verification - `cargo test -p victory-shader` on AMD Radeon RX 9070 (RDNA 4): **216 passed, 0 failed** (both new tests validated with `dxil.dll` and executed on hardware GPU). - `cargo clippy -p victory-shader --all-targets -- -D warnings`: pass (0 warnings). - `cargo xtask policy`: pass (`169 files ok`). - Full shader sweep (`VICTORY_HOST_MAX_WAVE=64`): - Compute shaders emitted: **2,672 → 2,676 / 2,682** (+4, 0 regressions). - `a wave sum of 16-bit floats where not every lane runs`: **2 → 0** (`b22a16a178976e1b` validates with `dxil.dll` and creates D3D12 pipeline). - `a lane mask holding lanes elsewhere read as data`: **2 → 0** (`926c46bab3b86bd6` widens 14 branches with 0 barriers, validates with `dxil.dll`, and creates D3D12 pipeline). ## Overlap note - Open PR #203 also fixes the 2 `half_sum` programs on native wave64 via `half_sum_present` (without widening early-outs). The `mask_dword` whole-wave fix (`926c46bab3b86bd6`) and the general native-wave64 `needs_every_lane` retry path in `emit/mod.rs` are not covered by #203 or other open PRs. Happy to rebase/drop the `half_sum` one-liner if #203 merges first. _AI-assisted (Antigravity); verified locally on AMD Radeon RX 9070. Hashes, counts, and clean-room tests only; no game data._
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:46:19 +00:00
Author
Owner

@⁠avt0m4t48 on GitHub · 2026-11-25 02:21 UTC · original

I ran an independent synthetic translation check at base c96b4f2b8365bf43d54ab074940923ef8267f4c6 and head 973101f230a1ec7ad416270c859f296529ffaed7, with the host wave size forced to 64.

  • The base refused a guarded f16 wave sum at 64 threads and a guarded EXEC-complement popcount at 64 and 128 threads. The head translated all three with zero dx.op.barrier calls in the selected modules' DXIL census. The half sum succeeded after removing the early-out, and both popcounts required one widened branch.
  • With VICTORY_WAVE_WIDE=0, both popcounts returned to the original refusal and the guarded half-sum output stayed byte-identical. Both revisions kept the 96-thread partial-wave refusals. The unguarded native-wave64 sum and the guarded wave32-host control produced byte-identical DXIL across revisions. The wave32-host control emitted three barriers.
  • The exact head passed the Linux shader library suite (171 passed, 2 ignored) and cargo check --target x86_64-pc-windows-msvc -p victory-shader --tests from Linux. The independent probe checked translation and emitted instructions. GPU readback and DXIL validator execution remain unverified in this run.

For reproduction, use the synthetic compute setup in wave64_tests.rs::native_of and force TEST_HOST_WAVE to 64. In the guarded half-sum fixture, replace the six words that construct the lane's term with 7e0e02ff 00003e00 (a constant f16 1.5). In the mask fixture change the skip to bf840005 (s_cbranch_scc0), keeping the body and EXEC restore. Use 64 and 128 threads for the mask, and 96 threads for each partial-wave control. Set VICTORY_SHADER_CENSUS=1 and inspect the barrier count from census::take for the selected DXIL.

**@⁠avt0m4t48** on GitHub · 2026-11-25 02:21 UTC · [original](https://github.com/fxceless/victory-fork/pull/558#issuecomment-7150618634) I ran an independent synthetic translation check at base `c96b4f2b8365bf43d54ab074940923ef8267f4c6` and head `973101f230a1ec7ad416270c859f296529ffaed7`, with the host wave size forced to 64. - The base refused a guarded f16 wave sum at 64 threads and a guarded EXEC-complement popcount at 64 and 128 threads. The head translated all three with zero `dx.op.barrier` calls in the selected modules' DXIL census. The half sum succeeded after removing the early-out, and both popcounts required one widened branch. - With `VICTORY_WAVE_WIDE=0`, both popcounts returned to the original refusal and the guarded half-sum output stayed byte-identical. Both revisions kept the 96-thread partial-wave refusals. The unguarded native-wave64 sum and the guarded wave32-host control produced byte-identical DXIL across revisions. The wave32-host control emitted three barriers. - The exact head passed the Linux shader library suite (171 passed, 2 ignored) and `cargo check --target x86_64-pc-windows-msvc -p victory-shader --tests` from Linux. The independent probe checked translation and emitted instructions. GPU readback and DXIL validator execution remain unverified in this run. For reproduction, use the synthetic compute setup in `wave64_tests.rs::native_of` and force `TEST_HOST_WAVE` to 64. In the guarded half-sum fixture, replace the six words that construct the lane's term with `7e0e02ff 00003e00` (a constant f16 1.5). In the mask fixture change the skip to `bf840005` (`s_cbranch_scc0`), keeping the body and EXEC restore. Use 64 and 128 threads for the mask, and 96 threads for each partial-wave control. Set `VICTORY_SHADER_CENSUS=1` and inspect the `barrier` count from `census::take` for the selected DXIL.
Author
Owner

@⁠HAL9000RELOADED on GitHub · 2026-11-25 08:08 UTC · original

A run on a native wave64 card, to go with the synthetic check above (which forced the host wave size to 64).

Setup: Radeon RX 7900 XTX (RDNA3, waves of 32 to 64 lanes), Adrenalin 32.0.32015.7029, i7-13700KF, Windows 10 Pro 22H2 (19045), Rust 1.98.1. Windows 10's in-box D3D12 stops at SM 6.5, so the tree also carries the D3D12 Agility SDK 1.620 (the same approach as #69). The DXIL validator comes from SDK 10.0.26100 (VICTORY_DXIL). WARP stays below SM 6.6 on this machine, so the GPU cases ran on the card only. No game data used.

Base: main c96b4f2 plus the Agility patch and the stack-headroom test fix from Marvisak/VIctory#742. The PR head 973101f was merged on top of it. "Base + tests" means the base with only this PR's wave64_tests.rs.

test base + tests this PR
native_wave64_half_sum_inside_early_out_translates_and_runs_exact fails: Unsupported { offset: 132, what: "a wave sum of 16-bit floats where not every lane runs" } passes: "ran on the hardware device: native wave64 half_sum inside early-out matches console tree"
native_wave64_mask_outside_exec_inside_branch_translates_and_runs_exact fails: Unsupported { offset: 36, what: "a lane mask holding lanes elsewhere read as data" } passes: "ran on the hardware device: native wave64 mask outside EXEC matches console popcount"

The whole workspace with this PR: 507 passed, 0 failed. The base gives 505 passed.

**@⁠HAL9000RELOADED** on GitHub · 2026-11-25 08:08 UTC · [original](https://github.com/fxceless/victory-fork/pull/558#issuecomment-7156653890) A run on a native wave64 card, to go with the synthetic check above (which forced the host wave size to 64). **Setup:** Radeon RX 7900 XTX (RDNA3, waves of 32 to 64 lanes), Adrenalin 32.0.32015.7029, i7-13700KF, Windows 10 Pro 22H2 (19045), Rust 1.98.1. Windows 10's in-box D3D12 stops at SM 6.5, so the tree also carries the D3D12 Agility SDK 1.620 (the same approach as #69). The DXIL validator comes from SDK 10.0.26100 (`VICTORY_DXIL`). WARP stays below SM 6.6 on this machine, so the GPU cases ran on the card only. No game data used. **Base:** `main` `c96b4f2` plus the Agility patch and the stack-headroom test fix from Marvisak/VIctory#742. The PR head `973101f` was merged on top of it. "Base + tests" means the base with only this PR's `wave64_tests.rs`. | test | base + tests | this PR | |---|---|---| | `native_wave64_half_sum_inside_early_out_translates_and_runs_exact` | fails: `Unsupported { offset: 132, what: "a wave sum of 16-bit floats where not every lane runs" }` | passes: "ran on the hardware device: native wave64 half_sum inside early-out matches console tree" | | `native_wave64_mask_outside_exec_inside_branch_translates_and_runs_exact` | fails: `Unsupported { offset: 36, what: "a lane mask holding lanes elsewhere read as data" }` | passes: "ran on the hardware device: native wave64 mask outside EXEC matches console popcount" | The whole workspace with this PR: 507 passed, 0 failed. The base gives 505 passed.
This pull request has changes conflicting with the target branch.
  • crates/victory-shader/src/emit/lower.rs
  • crates/victory-shader/src/emit/wave64_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/558/head:github-bot/gh-558'
git switch 'github-bot/gh-558'

Merge

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