Shaders: support cross-half ds_bpermute_b32 and fix group <= 32 OOB lanes on 32-lane GPUs #615

Open
orazal12 wants to merge 1 commit from upstream-pr/615 into main
orazal12 commented 2026-11-25 03:19:28 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by orazal12 on 2026-11-25T03:19:28Z.


Fixes and extends ds_bpermute_b32 lowering for console wave64 shaders running on 32-lane GPUs (NVIDIA / wave32):

  • Fix group <= 32 OOB lane reads: previously passed src in 0..=63 directly to dx.op.waveReadLaneAt.i32 on a 32-lane host wave (UB / wraps mod 32 instead of returning 0 for lanes 32..63). Now masks lane = src & 31 and selects 0 when src >= 32.
  • Support cross-half ds_bpermute_b32 (group > 32): allocates 64-dword-per-console-wave LDS scratch (checking D3D12's 32 KiB limit with 1 dword reserved for wave_base), exchanges all 64 lanes via store -> group_sync -> load -> group_sync, selects 0 for missing lanes in partial tail waves (!group.is_multiple_of(64)), and hooks into needs_every_lane / widen when called inside a per-lane branch.
  • Local-wave modes: matches v_readlane_b32 (masks src & 31 under local && local_any; refuses cleanly under local && !local_any).

Verification:

  • cargo test -p victory-shader --offline: 218 passed, 0 failed (4 new wave64_tests validated with dxil.dll and executed on hardware GPU covering [32,1,1], [64,1,1], [128,1,1], [96,1,1], per-lane branch widening, and 32 KiB LDS overflow refusal)
  • cargo test -p xtask --offline: 4 passed (asset policy check ok)
  • cargo clippy -p victory-shader --all-targets --offline -- -D warnings: 0 warnings
<!-- greyfinch-sync:fxceless/victory-fork:issue:6596414535 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/615). Originally posted by [orazal12](https://github.com/orazal12) on 2026-11-25T03:19:28Z. --- Fixes and extends `ds_bpermute_b32` lowering for console wave64 shaders running on 32-lane GPUs (NVIDIA / wave32): - **Fix `group <= 32` OOB lane reads**: previously passed `src` in `0..=63` directly to `dx.op.waveReadLaneAt.i32` on a 32-lane host wave (UB / wraps mod 32 instead of returning `0` for lanes `32..63`). Now masks `lane = src & 31` and selects `0` when `src >= 32`. - **Support cross-half `ds_bpermute_b32` (`group > 32`)**: allocates 64-dword-per-console-wave LDS scratch (checking D3D12's 32 KiB limit with 1 dword reserved for `wave_base`), exchanges all 64 lanes via `store -> group_sync -> load -> group_sync`, selects `0` for missing lanes in partial tail waves (`!group.is_multiple_of(64)`), and hooks into `needs_every_lane` / `widen` when called inside a per-lane branch. - **Local-wave modes**: matches `v_readlane_b32` (masks `src & 31` under `local && local_any`; refuses cleanly under `local && !local_any`). **Verification:** - `cargo test -p victory-shader --offline`: 218 passed, 0 failed (4 new `wave64_tests` validated with `dxil.dll` and executed on hardware GPU covering `[32,1,1]`, `[64,1,1]`, `[128,1,1]`, `[96,1,1]`, per-lane branch widening, and 32 KiB LDS overflow refusal) - `cargo test -p xtask --offline`: 4 passed (asset policy check ok) - `cargo clippy -p victory-shader --all-targets --offline -- -D warnings`: 0 warnings
HAL9000RELOADED commented 2026-11-25 20:09:26 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by HAL9000RELOADED on 2026-11-25T19:29:39Z.


RX 7900 XTX (RDNA3), Windows 10 + #402 for SM 6.6, main d510ee4: all 4 new tests pass on the card with this PR, and all 4 fail with the tests alone on the base. No other test changed. Run table: #129 (https://github.com/fxceless/victory-fork/pull/129#issuecomment-7172358511).

<!-- greyfinch-sync:fxceless/victory-fork:comment:7172374228 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/615#issuecomment-7172374228). Originally posted by [HAL9000RELOADED](https://github.com/HAL9000RELOADED) on 2026-11-25T19:29:39Z. --- RX 7900 XTX (RDNA3), Windows 10 + #402 for SM 6.6, main `d510ee4`: all 4 new tests pass on the card with this PR, and all 4 fail with the tests alone on the base. No other test changed. Run table: #129 (https://github.com/fxceless/victory-fork/pull/129#issuecomment-7172358511).
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/615:upstream-pr/615'
git switch 'upstream-pr/615'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/615'
git switch 'upstream-pr/615'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/615'
git switch 'upstream-pr/615'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/615'
git switch 'main'
git merge --squash 'upstream-pr/615'
git switch 'main'
git merge --ff-only 'upstream-pr/615'
git switch 'main'
git merge 'upstream-pr/615'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
fxceless/victory-fork!615
No description provided.