Skip to content

Shaders: half-local cross-lane operations run for wave64 on 32-lane hosts (FIND-7) - #3115

Open
Creaa wants to merge 4 commits into
Marvisak:mainfrom
Creaa:shaders/wave64-half-local-cross-lane
Open

Creaa wants to merge 4 commits into
Marvisak:mainfrom
Creaa:shaders/wave64-half-local-cross-lane

Conversation

@Creaa

@Creaa Creaa commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #2176; only the top commit (be8c887) belongs here. Claimed as FIND-7 in #1633.

On a host of 32-lane waves, #2176 refuses every cross-lane operation that is not quad-local as "a cross-half operation on a 32-lane host". DPP rows (16 lanes), DPP8 (8 lanes), ds_swizzle_b32 in its group-of-32 mode and ds_bpermute_b32 (each 32-lane half on its own, RDNA2 ISA 10.4.4, as the code's own comment says) only read lanes of their own half, which one host wave holds whole. They now run.

What is in it

  • crates/victory-shader/src/emit/lower.rs: cross_lane gets cross_lanes_within(quad, lanes), the size of the group an operation reads in; refused only when the host wave is smaller than that group, quad operations included (their DPP row mask still numbers the wave's rows; found by @fuzeofficlal in review). Swizzle and bpermute pass 32, DPP8 8, DPP rows 16 when the row write mask has the same bits for both halves (0xF, 0x5, 0xA, 0x0), else the wave: the mask numbers the wave's four rows, and a 32-lane host wave sees only rows 0 and 1 of its half. v_readlane/v_writelane/v_mbcnt and other cross-lane paths are unchanged.
  • crates/victory-shader/src/emit/crosslane_tests.rs: half_local_cross_lane_ops_of_wave64_match_rdna2_on_a_wave32_host runs a wave64 program of 64 threads, translated for a 32-lane host, on a hardware device and checks all 64 lanes against RDNA2 for row_ror:4, row_mirror, row_share:3, DPP8, ds_swizzle_b32 SWAP(16) and ds_bpermute_b32, and with only the even lanes active (v_cmpx) for row_ror:4 with fi:0 and ds_bpermute_b32 (inactive sources read 0). The wave32 builder and dispatch were split into shader_of and dispatch_lanes::<N> for it; the existing wave32 tests use them unchanged.
  • crates/victory-shader/src/emit/mod.rs: wave64_dpp_row_is_refused_on_wave32_host_only_with_a_mask_naming_one_half: row_shr:1 with row masks 0xF and 0x5 emits, 0x1 is refused as cross-half; quad_perm with 0xF emits, with 0x1 is refused.

Tested

Not tested

  • AMD and Intel cards (their hosts take wave64, so the path is not used there), WARP's 32-lane mode.
  • The 51 programs still refused cross the halves for real (v_readlane of another half and the like); not changed here.

AI use

  • Claude Code (Claude Opus 5.5) found the cases, wrote the change and the tests, ran the measurements and drafted this description; I checked it.

🤖 Generated with Claude Code

@fuzeofficlal fuzeofficlal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified on a 32-lane NVIDIA GPU (RTX 5090, Windows 11):

  • emit::crosslane_tests::half_local_cross_lane_ops_of_wave64_match_rdna2_on_a_wave32_host: all 6 cases (dpp16 row_ror:4, row_mirror, row_share:3, dpp8, ds_swizzle_b32 bitmode SWAP(16), ds_bpermute_b32) passed on hardware.
  • Full emit::crosslane_tests:: (6/6), the three wave32-host refusal tests, and victory-gpu shader_cache:: (4/4) all passed; cargo clippy -p victory-shader -p victory-gpu -p victory --all-targets -- -D warnings (default and --all-features) and cargo xtask policy are clean.

One correctness edge case in crates/victory-shader/src/emit/lower.rs:

Asymmetric row_mask on a DPP quad_perm (ctrl: 0..=0xFF) bypasses the cross-half refusal

In dpp():

let quad = matches!(dpp, Dpp::Row { ctrl: 0..=0xFF, .. });
let reach = match dpp {
    Dpp::Lanes { .. } => 8,
    Dpp::Row { row_mask, .. } if row_mask & 3 == row_mask >> 2 => 16,
    Dpp::Row { .. } => self.wave(),
};
...
self.cross_lanes_within(quad, reach)?;

And in cross_lanes_within():

if !quad && self.host_wave() < lanes.min(self.wave()) {
    return Err("a cross-half operation on a 32-lane host");
}

When a wave64 compute shader uses a DPP quad permutation (ctrl: 0..=0xFF) with an asymmetric row_mask (e.g., row_mask = 0x1 or 0x4), reach is 64, but quad is true, so !quad && skips the cross-half check. On a 32-lane host, lane_index() (waveGetLaneIndex) is 0..31 in both halves, so ri = (lane >> 4) & 3 evaluates to {0, 1} in both halves — silently writing to row 2 (lanes 32-47) under row_mask = 0x1, or disabling writes for all 64 lanes under row_mask = 0x4.

Checking all cross_lanes_within call sites, every truly quad-local op already passes lanes <= 32 (ds_swizzle_b32 passes 32, symmetric Dpp::Row passes 16), so dropping !quad && from the condition (if self.host_wave() < lanes.min(self.wave())) fixes this cleanly without affecting valid quad operations. Adding a quad_perm + row_mask = 0x1 case to wave64_dpp_row_is_refused_on_wave32_host_only_with_a_mask_naming_one_half would lock it down.

(Optional non-blocking note: all 6 hardware cases in half_local_cross_lane_ops_of_wave64_match_rdna2_on_a_wave32_host run with all 64 lanes active and fi = true. Code inspection confirms src_lane_active / ds_bpermute_b32 work with waveGetLaneIndex() (0..31) + waveActiveBallot lo, and adding one divergent-EXEC / fi = false case would cover that path on 32-lane hardware too.)

@Dukestar69 Dukestar69 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified on RTX 5090 (native wave32 host) & WARP against origin/main (63bcca4):

  • cargo test -p victory-shader --lib emit::crosslane_tests:: -- --test-threads=1: 6/6 passed on RTX 5090 and WARP (including half_local_cross_lane_ops_of_wave64_match_rdna2_on_a_wave32_host).
  • cargo test -p victory-gpu --lib shader_cache:: -- --test-threads=1: 4/4 passed.
  • cargo clippy -p victory-shader -p victory-gpu -p victory --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Great NVIDIA/wave32 win: cleanly enables half-local cross-lane wave64 operations on 32-lane hosts and keys the shader cache accordingly.

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

@Aniseto

Aniseto commented Nov 26, 2026

Copy link
Copy Markdown

Ran the half-local cross-lane tests at 6f8cb55:

Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only, 16 GB) driver 32.0.16.2124, Intel Core i5-12400F, 64 GB RAM, Rust 1.98.1 (pinned by rust-toolchain.toml), MSVC 14.44.35207, debug build. No dxil.dll on this host, so the test reports validation as skipped; the GPU comparisons still ran.

cargo test --locked -p victory-shader --lib half_local_cross_lane_ops_of_wave64 -- --test-threads=1 --nocapture
1 passed; 0 failed; 0 ignored; 308 filtered out      (exit 0)

The GPU test reports [PASS] for all six forms: DPP16 row_ror:4, row_mirror, row_share:3, DPP8, ds_swizzle_b32 SWAP(16) and ds_bpermute_b32 within the half, with all 64 logical lanes matching RDNA2. The negative test wave64_dpp_row_is_refused_on_wave32_host_only_with_a_mask_naming_one_half also passes (1/1).

What this adds: the author measured on an RTX 4070 12 GB (Ada). This is a Blackwell wave32 part, exercising exactly the host configuration the PR targets, and the thread has no report from another machine.

Not tested: the full victory-shader suite, DXIL validation (no dxil.dll), a title run, AMD and Intel GPUs, WARP, release profile.

AI-assisted (OpenCode), model: DeepSeek V4.1 Flash Free - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; the worktree was not modified; no game data was used.

…osts

On a host of 32-lane waves (Marvisak#2176) every cross-lane operation that is not
quad-local was refused as "a cross-half operation", but DPP rows (16 lanes),
DPP8 (8 lanes), ds_swizzle_b32 in its group-of-32 mode and ds_bpermute_b32
(each 32-lane half on its own, RDNA2 ISA 10.4.4) only read lanes of their
own half, which one host wave holds whole (FIND-7 in Marvisak#1633).

cross_lane now takes how far an operation reaches. A DPP row write mask
numbers the wave's four rows, so a row operation stays in its half only
when the mask has the same bits for both halves (0xF, 0x5, 0xA, 0x0).

Offline `translate --list` of the title's shader pack as a 32-lane host:
"a cross-half operation on a 32-lane host" 69 -> 51 programs; compute
programs emitted 2291 -> 2309 (the 2D and array mip-chain programs of
levels 2-3, a cascade-shadow min/max and a trail-map mip program).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Creaa
Creaa force-pushed the shaders/wave64-half-local-cross-lane branch from 6f8cb55 to be8c887 Compare November 26, 2026 09:06
@Creaa

Creaa commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

@fuzeofficlal thanks, right: a quad_perm with a row mask naming one half skipped the check, since the condition only applied to non-quad operations. Fixed in be8c887 (squashed into the PR's commit) as you suggested: cross_lanes_within now refuses whenever the host wave is smaller than the reach the caller gives, quad operations included; every quad-local caller passes 32 or less, so valid quad operations are unaffected.

  • wave64_dpp_row_is_refused_on_wave32_host_only_with_a_mask_naming_one_half now also checks quad_perm with row masks 0xF (emits) and 0x1 (refused); with the old condition the 0x1 case emits and the test fails.
  • I also took the optional note: two hardware cases with only the even lanes active (v_cmpx), row_ror:4 with fi:0 and ds_bpermute_b32 (odd, inactive sources read 0). All 8 cases pass on an RTX 4070.
  • victory-shader lib: 302 passed, the same 3 hardware failures as GPU+shader: translate wave64 programs for 32-lane host waves when WaveLaneCountMax < 64 #2176 alone; clippy (default and --all-features) clean; policy ok. The offline count is unchanged (51 programs still refused as cross-half).

AI use: Claude Code (Claude Opus 5.5) made the change, ran the tests and drafted this reply.

@Aniseto

Aniseto commented Nov 26, 2026

Copy link
Copy Markdown

Re-ran the half-local cross-lane tests at be8c887 after the head moved (66 lines added to the cross-lane test, plus changes in lower.rs and emit/mod.rs).

Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only, 16 GB) driver 32.0.16.2124, Intel Core i5-12400F, 64 GB RAM, Rust 1.98.1 (pinned), MSVC 14.44.35207, debug build. No dxil.dll here, so validation is skipped; the GPU comparisons ran.

cargo test --locked -p victory-shader --lib half_local_cross_lane_ops_of_wave64 -- --test-threads=1 --nocapture
1 passed; 0 failed; 0 ignored; 308 filtered out      (exit 0)

The test now reports eight [PASS] cases: DPP16 row_ror:4, row_mirror, row_share:3, DPP8, ds_swizzle_b32 SWAP(16), ds_bpermute_b32 within the half, plus the new dpp16 row_ror:4 fi:0, even lanes active and ds_bpermute_b32 lane + 1, even lanes active (odd sources read 0). The negative test wave64_dpp_row_is_refused_on_wave32_host_only_with_a_mask_naming_one_half also passes (1/1). This is a new report following mine at 6f8cb55, not an edit.

Not tested: the full victory-shader suite, DXIL validation, a title run, AMD and Intel GPUs, WARP, release profile.

AI-assisted (OpenCode), model: DeepSeek V4.1 Flash Free - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; the worktree was not modified; no game data was used.

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Needs work: stacked on #2176. The top commit be8c887 looks right. Lower::cross_lanes_within (crates/victory-shader/src/emit/lower.rs) gives each operation the size of the group it reads: 32 for ds_swizzle_b32/ds_bpermute_b32, 8 for DPP8, 16 for DPP rows. None of the accepted DPP row controls (0x101–0x12F, 0x140/0x141, 0x150–0x16F) or swizzle modes reaches outside its row or 32-lane half. Refusing row masks that differ between the halves is the right conservative choice, and wave64_dpp_row_is_refused_on_wave32_host_only_with_a_mask_naming_one_half covers it. The blocker is that the branch also carries #2176's three commits (host_wave32, emit::Options, the shader_cache and host changes), and none of them is in main. Once #2176 lands, please rebase so that only this commit's changes to lower.rs, crosslane_tests.rs and emit/mod.rs remain. It can be reconsidered then.

CI: check passing.


Generated by Claude Code

clquwu added a commit to clquwu/leonida-ultimate that referenced this pull request Nov 26, 2026
…ata reads & #2142 fma_mix literal

- Port ubiquitarianism/leonida#2142 (SHADER-FMA-MIX-TEXT-CUT-LITERAL, GPL-3.0):
  restore_text_cut_mix_literal recovers full 32-bit v_fma_mix* literals from printed
  encodings when llvm-mc 21.1.8 truncates text literals to 16 bits on clean and
  re-anchored listings.
- Port ubiquitarianism/leonida#1397 (mask-regs-data-read, GPL-3.0):
  VALU data reads of exec_lo/exec_hi/vcc/vcc_lo/vcc_hi and mask-tracked SGPRs
  materialize the wave's 32-bit mask word (src_u/lane_mask_word), keep word readers
  out of lane-local runs and wave64-emulate folds, and fix v_readfirstlane_b32 /
  mask_src extraction on mask-holding VGPRs (_vgpr_mask_lane_bit).
- Port PastiiJay/klbf-lab#50 (GPL-3.0) static Wave32 LDS alias & hazard proof
  (Refinement A disjoint constant byte ranges + Refinement B injective per-lane
  private slots with adversarial hardening) into tools/wave64_emulate_opt.py,
  enabling multi-op/cyclic LDS inline EXECZ folding and sync-free multi-wave
  inlining under --wave64-emulate (suppressing redundant intra-region LDS
  x_order_barrier splits).
- Add opt-in --wave64-promote-wave32 compute promotion (can_promote_wave64_cs_to_wave32)
  combining FIND-7 half-local ops (Marvisak/VIctory#3115, GPL-3.0), static Wave32
  LDS hazard proof (klbf-lab#50, GPL-3.0), and strict refusal of wave-wide
  counts/sums used as data (Rubenpannen/VIctory-RTX5070@b696f73, GPL-3.0).
- Add synthetic hand-written tests in tests/semantic/test_wave30_wave32_rules.py
  (spirv-val + spirv_mini_interp + workgroup interpreter) and update docs/design.md.

@fuzeofficlal fuzeofficlal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed at be8c887c. Dropping !quad && in cross_lanes_within (crates/victory-shader/src/emit/lower.rs:2935) cleanly closes the asymmetric row_mask bypass for quad_perm while keeping symmetric quad_perm (row_mask = 0xF / 0x5 / 0xA, reach = 16) and ds_swizzle_b32 (lanes = 32) accepted — verified all cross_lane / cross_lanes_within call sites in lower.rs. The new quad_perm refusal checks in emit/mod.rs and the two active-mask (even lanes active) wave64-on-wave32 GPU tests in crosslane_tests.rs are great additions.

Verified locally on Windows 11 with a 32-lane RTX 5090 and WARP:

  • cargo clippy --workspace --all-targets -- -D warnings: clean
  • cargo clippy --workspace --all-targets --all-features -- -D warnings: clean
  • cargo xtask policy: 190 files ok
  • RTX 5090 (32-lane): cargo test -p victory-shader --lib -- crosslane_tests:: wave64 — 14/14 passed (all 8 wave64-on-wave32 subtests including the new even lanes active cases, plus 18 DPP16, 5 DPP8, and 6 ds_swizzle_b32 GPU checks)
  • WARP (VICTORY_D3D12_WARP=1): cargo test -p victory-shader --lib -- crosslane_tests:: wave64 — 14/14 passed
  • RTX 5090 victory-gpu: shader_cache:: 4/4 passed, host::tests:: 12/12 passed

LGTM.

Bebrik229 pushed a commit to Bebrik229/VIctory that referenced this pull request Nov 26, 2026
…IRE_LEAN, lock-free compiler VEH, small-mip guard, wide_refresh >=2, shaders Marvisak#3008/Marvisak#3117/Marvisak#3115
ka1qux added a commit to ka1qux/BRVIctory-ka1qux that referenced this pull request Nov 26, 2026
…4 count its lanes (VICTORY_HALF_LOCAL=0 goes back)

On a host of 32-lane waves a console wave64 program is run as two host
waves, each one half of a console wave, so DPP rows (16 lanes), DPP8 and
`ds_swizzle_b32` in its group-of-32 mode already run without the halves
meeting (upstream's version of this had to refuse them as cross-half).
Two things were still wrong, found by a test that checks all 64 lanes of
a wave64 program against RDNA2 on the hardware device:

- A DPP row write mask names the four rows of the console wave, but the
  host lane only numbers the rows of its half: a mask with different bits
  for rows 0-1 and 2-3 (0x3, 0xC) wrote the wrong rows in the upper half
  (30 of 64 lanes). The row is now counted from the console lane
  (`console_lane_in_wave`) where the host waves are halves.
- `ds_bpermute_b32` in wave64 permutes lanes 0..31 and 32..63 each on
  their own (RDNA2 ISA 10.4.4): the address modulo 32 in the lane's own
  half. It was refused ("a lane permute across two host waves") on a
  32-lane host, and on a 64-lane host it read across the halves (2 of 64
  lanes wrong where the address wraps). It is now a read inside the half,
  which a host wave of 32 holds whole, and it no longer makes the program
  need the halves to exchange.

The saved set has no such program (its bpermutes are in console wave32
programs, its row masks all full), so no translation changes there.

After Marvisak/VIctory#3115 (Creaa), whose cheap part this is; what it
mainly does (let these operations run) this translation already did.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants