Shaders: allow half-local DPP in divergent Wave64 Emulate (FIND-7) #3200

Open
github-bot wants to merge 20 commits from github-bot/gh-3200 into main AGit
Owner

@⁠makmatvey on GitHub · 2026-11-26 12:23 UTC · original
makmatvey:cursor/shader-find7-half-local-divergent-673e → main · +5131 −611 · 19 files · 20 commits · open

Stacked on #189; only the top commit belongs here. Related but separate from #3115 (that PR is the #2176 wave64-on-32-lane cross-half refusal).

What's wrong

Under Wave64Mode::Emulate (#189), DPP source picks go through exchange_64, which refuses with "a cross-lane wave operation in divergent control flow" / "a cross-lane read in divergent control flow" whenever EXEC is narrowed. DPP row/quad/DPP8 never leave a 32-lane half (#1317 H-6.3 / FIND-7), so they need no LDS barrier and should stay legal in divergent control flow. Only v_permlanex16, 64-wide v_readlane, and 64-bit ballots really cross the halves.

What the change does

  • crates/victory-shader/src/emit/lower.rs: in Emulate (non-mesh-quad) DPP, use host lane indices and WaveReadLaneAt instead of exchange_64.
  • crates/victory-shader/src/emit/lower/wave64.rs: src_lane_active(..., half_local) uses the host waveActiveBallot for half-local DPP FI=0, skipping the 64-lane ballot/barrier path.
  • ds_swizzle / permute paths that still need console-lane exchange keep half_local: false.

Tests

  • New divergent_dpp_row_emits_under_wave64_emulate: divergent row_shr:1 emits under Emulate; a same-shape divergent 64-bit ballot still refuses.
  • cargo check -p victory-shader --locked and cargo clippy -p victory-shader --locked -- -D warnings clean on Linux.
  • cargo test -p victory-shader --lib does not compile on Linux on #189's base (validator is cfg(windows)); Windows CI is the gate.
  • cargo xtask policy: 193 files ok.

Asset policy

No game data used.

**@⁠makmatvey** on GitHub · 2026-11-26 12:23 UTC · [original](https://github.com/Marvisak/VIctory/pull/3200) `makmatvey:cursor/shader-find7-half-local-divergent-673e` → `main` · +5131 −611 · 19 files · 20 commits · open Stacked on #189; only the top commit belongs here. Related but separate from #3115 (that PR is the #2176 wave64-on-32-lane `cross-half` refusal). **What's wrong** Under `Wave64Mode::Emulate` (#189), DPP source picks go through `exchange_64`, which refuses with "a cross-lane wave operation in divergent control flow" / "a cross-lane read in divergent control flow" whenever EXEC is narrowed. DPP row/quad/DPP8 never leave a 32-lane half (#1317 H-6.3 / FIND-7), so they need no LDS barrier and should stay legal in divergent control flow. Only `v_permlanex16`, 64-wide `v_readlane`, and 64-bit ballots really cross the halves. **What the change does** - `crates/victory-shader/src/emit/lower.rs`: in Emulate (non-mesh-quad) DPP, use host lane indices and `WaveReadLaneAt` instead of `exchange_64`. - `crates/victory-shader/src/emit/lower/wave64.rs`: `src_lane_active(..., half_local)` uses the host `waveActiveBallot` for half-local DPP FI=0, skipping the 64-lane ballot/barrier path. - `ds_swizzle` / permute paths that still need console-lane exchange keep `half_local: false`. **Tests** - New `divergent_dpp_row_emits_under_wave64_emulate`: divergent `row_shr:1` emits under Emulate; a same-shape divergent 64-bit ballot still refuses. - `cargo check -p victory-shader --locked` and `cargo clippy -p victory-shader --locked -- -D warnings` clean on Linux. - `cargo test -p victory-shader --lib` does not compile on Linux on #189's base (`validator` is `cfg(windows)`); Windows CI is the gate. - `cargo xtask policy`: 193 files ok. **Asset policy** No game data used.
Add Wave64Mode (Native, Wave32, Emulate) and TranslateOptions so Wave64 compute shaders lower and run on 32-lane GPUs (NVIDIA/Intel) and narrower hosts such as WARP instead of failing CreateComputePipelineState with E_INVALIDARG on WaveSize(64).

- Add Wave64Mode, TranslateOptions, translate_with, and emit_with while keeping translate/emit defaulting to Wave64Mode::Native.
- Resolve constant-lane SGPR spills across v_writelane_b32/v_readlane_b32 via resource::spilled_sgprs.
- Implement virtual 64-lane mapping for Wave32 (two aligned 32-lane waves) and portable LDS emulation without WAVE_OPS for narrower hosts, with post-dominator uniformity checks to reject cross-half barriers in divergent control flow rather than hanging.
- Auto-detect host wave capabilities in victory-gpu::Host (with VICTORY_WAVE64_EMULATE override and mode byte in shader_cache keys) and in victory translate --pipelines.
- Add synthetic RDNA2 compute tests (PSO validation + execution on hardware GPU and WARP).
Incorporate verified follow-up fixes from PR #189 reviewers and contributors:

- Fence single-console-wave LDS accesses at group-uniform joins/exits and reject unfenceable divergent regions (fixes marquezinii's split-block stale LDS readback; from alfycs/VIctory#1 by @erickbobd).
- Allow Wave32 divergent v_readfirstlane per half without LDS barriers (fixes waterfall loops / common divergent refusals reported by @AKA0GHOST and @NuraadGit), preserve ValUniform propagation across unguarded v_mov_b32 copies for uniform v_readfirstlane in divergent branches (@marquezinii), and return lane 0 when EXEC == 0 in emulated_readfirstlane.
- Clamp DPP row_shr/row_shl lane indices using inside before read_lane/exchange_64 to avoid out-of-range waveReadLaneAt on WARP 1.0.22 (@ifBars).
- Verify DXGI_ADAPTER_FLAG_SOFTWARE in shader::emit::host::Host::new(true) for Wine/DXVK (@dpalacios69, @tanishq-dubey), base recommended_wave64_mode_matches_device_capabilities on queried capabilities (@ifBars), and serialize wave64 GPU tests under valu_tests::ONE_AT_A_TIME (@r4tedx).

Co-authored-by: erickbobd <[email protected]>
Avoid false positives in plan_lds_fences on Wave32:

- Skip need_lds_barriers in Wave32 when total_threads <= 32 (single native host wave).
- Track reads vs writes/atomics separately in plan_lds_fences so multiple pure ds_read* instructions inside a divergent region or loop are allowed while RAW/WAW/WAR hazards remain rejected.
Log every rejected adapter and WARP in Host::all_adapters(), and print SKIPPED <test>: no SM 6.6 adapter instead of panicking on an empty host list. This makes Turing/SM 6.5 machines diagnosable instead of producing identical failures.
The two 64-lane emulations refuse different programs: Wave32 those with a
cross-lane operation in divergent control flow, Emulate those with a
non-uniform v_readfirstlane there. A program the asked-for lowering refuses
now tries the other one, then the native lowering; the refusal reported is
the asked-for one's. On an RTX 4050 Laptop (32 lanes) this takes the shader
pack's pipelines the host refuses from 395 (native) to 257, with the same
307 container refusals as native.

AI-assisted (Claude Code).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
DPP row/quad/DPP8 never leave a 32-lane half (#1317 H-6.3 / FIND-7).
Under Wave64Mode::Emulate the host wave is that half, so use host
WaveReadLaneAt and host ballot instead of exchange_64 / 64-lane ballot.
Keeps real cross-half ops (64-bit ballots, exchange_64 paths) refused.

Co-authored-by: Matsvey Makushenka <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 12:25:05 +00:00
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 12:28 UTC · original · reviewed

Tested on Windows 11 (RTX 5090 + WARP) against origin/main (63bcca4):

  • cargo clippy -p victory-shader -p victory-gpu -p victory --all-targets -- -D warnings: clean.
  • cargo xtask policy: 193 files ok.
  • cargo test -p victory-shader --lib emit::crosslane_tests:: -- --test-threads=1: 5/5 passed on RTX 5090 and WARP.
  • cargo test -p victory-gpu --lib shader_cache:: -- --test-threads=1: 5/5 passed.
  • cargo test -p victory-shader --lib emit::wave64_tests:: -- --test-threads=1: 34/35 passed, 1 failed:
    • emit::wave64_tests::gpu::gpu_128_threads_ds_swizzle_and_dpp_row_mask passed on RTX 5090 (wave=(true, 32..=32), [Emulate, Wave32]), but failed on WARP (wave=(true, 4..=4), [Emulate]):
      assertion `left == right` failed: ds_swizzle_dpp_rowmask (Emulate, WARP) output mismatch
        left[16..20]:  [65554, 65555, 65552, 65553, ...]
        right[16..20]: [1048594, 2162707, 2293776, 2424849, ...]
      
    • Looks like Emulate mode assumes host wave width >= 32 (or >= 16) for half-local DPP row operations, which breaks on inbox WARP (wave=(true, 4..=4)).

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

**@⁠Dukestar69** on GitHub · 2026-11-26 12:28 UTC · [original](https://github.com/Marvisak/VIctory/pull/3200#pullrequestreview-6074125013) · **reviewed** Tested on Windows 11 (RTX 5090 + WARP) against `origin/main` (`63bcca4`): - `cargo clippy -p victory-shader -p victory-gpu -p victory --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 193 files ok. - `cargo test -p victory-shader --lib emit::crosslane_tests:: -- --test-threads=1`: 5/5 passed on RTX 5090 and WARP. - `cargo test -p victory-gpu --lib shader_cache:: -- --test-threads=1`: 5/5 passed. - `cargo test -p victory-shader --lib emit::wave64_tests:: -- --test-threads=1`: **34/35 passed, 1 failed**: - `emit::wave64_tests::gpu::gpu_128_threads_ds_swizzle_and_dpp_row_mask` **passed on RTX 5090** (`wave=(true, 32..=32)`, `[Emulate, Wave32]`), but **failed on WARP** (`wave=(true, 4..=4)`, `[Emulate]`): ``` assertion `left == right` failed: ds_swizzle_dpp_rowmask (Emulate, WARP) output mismatch left[16..20]: [65554, 65555, 65552, 65553, ...] right[16..20]: [1048594, 2162707, 2293776, 2424849, ...] ``` - Looks like `Emulate` mode assumes host wave width >= 32 (or >= 16) for half-local DPP row operations, which breaks on inbox WARP (`wave=(true, 4..=4)`). Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

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

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3200'
git switch 'github-bot/gh-3200'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3200'
git switch 'github-bot/gh-3200'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3200'
git switch 'main'
git merge --squash 'github-bot/gh-3200'
git switch 'main'
git merge --ff-only 'github-bot/gh-3200'
git switch 'main'
git merge 'github-bot/gh-3200'
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!3200
No description provided.