Shaders: clamp inactive source lane in ds_bpermute_b32 before WaveReadLaneAt #3189

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

@⁠reeledMarek on GitHub · 2026-11-26 11:28 UTC · original
reeledMarek:fix/shader-bpermute-safe-lane → main · +55 −5 · 2 files · 1 commits · open

Summary

  • In crates/victory-shader/src/emit/lower.rs, ds_bpermute_b32 passed the computed source lane directly to self.read_lane(x, lane) (dx.op.waveReadLaneAt.i32) before checking running via waveActiveBallot.
  • Passing an inactive lane index to WaveReadLaneAt is undefined behavior in DXIL/SM6.0+ (matching the bug fixed for DPP16/DPP8/ds_swizzle_b32 in commit b51011aa).
  • Compute me = self.lane_index() (reused for wave64 half masking) and running before read_lane, select safe_lane = select(running, lane, me), and pass safe_lane to read_lane before zeroing inactive sources.

Testing

  • Added Module::wave_read_lane_clamps_inactive in crates/victory-shader/src/emit/bitcode.rs and asserted it in ds_bpermute_wave64_preserves_32_lane_half for both wave32 and wave64 (fails on main, passes with the fix).
  • Verified cargo clippy -p victory-shader --all-targets --target x86_64-pc-windows-msvc --locked -- -D warnings and cargo test -p xtask --locked pass.
**@⁠reeledMarek** on GitHub · 2026-11-26 11:28 UTC · [original](https://github.com/Marvisak/VIctory/pull/3189) `reeledMarek:fix/shader-bpermute-safe-lane` → `main` · +55 −5 · 2 files · 1 commits · open ## Summary - In `crates/victory-shader/src/emit/lower.rs`, `ds_bpermute_b32` passed the computed source `lane` directly to `self.read_lane(x, lane)` (`dx.op.waveReadLaneAt.i32`) before checking `running` via `waveActiveBallot`. - Passing an inactive lane index to `WaveReadLaneAt` is undefined behavior in DXIL/SM6.0+ (matching the bug fixed for DPP16/DPP8/`ds_swizzle_b32` in commit `b51011aa`). - Compute `me = self.lane_index()` (reused for wave64 half masking) and `running` before `read_lane`, select `safe_lane = select(running, lane, me)`, and pass `safe_lane` to `read_lane` before zeroing inactive sources. ## Testing - Added `Module::wave_read_lane_clamps_inactive` in `crates/victory-shader/src/emit/bitcode.rs` and asserted it in `ds_bpermute_wave64_preserves_32_lane_half` for both wave32 and wave64 (fails on `main`, passes with the fix). - Verified `cargo clippy -p victory-shader --all-targets --target x86_64-pc-windows-msvc --locked -- -D warnings` and `cargo test -p xtask --locked` pass.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 11:33:21 +00:00
Author
Owner

@⁠oni-swr on GitHub · 2026-11-26 11:47 UTC · original

WARP verification of #3189 (head 707f71541c15446c3fd443ad42921059c45f970e)

Environment: Windows 11 Pro 10.0.26200; WARP D3D10Warp.dll 10.0.26100.9818 (VICTORY_D3D12_WARP=1, physical GPU not used); dxil.dll and dxc.exe 1.8.2502.11 from Windows SDK 10.0.26100.0 (VICTORY_DXIL points at that dxil.dll); rustc 1.98.1.

Commands:
cargo test -p victory-shader --lib -j 4 --locked -- --test-threads=1, on the PR head and on the merge-base with main (63bcca43c6a00a758510398fa43096ce7e4f7df0). The test builds the container and validates it with the SDK dxil.dll.

Run Result
PR head 302 passed, 0 failed, 3 ignored (includes emit::lower::tests::ds_bpermute_wave64_preserves_32_lane_half, wave32 and wave64)
merge-base (main) 302 passed, 0 failed, 3 ignored (the changed test sits in the old, weaker form)
PR head with only the fix reverted (read_lane(x, safe_lane) back to read_lane(x, lane)), test kept FAILED: "wave64=false: WaveReadLaneAt must clamp inactive lanes to waveGetLaneIndex"

Defects found: none. Reading the diff, running is still computed from the unclamped lane, so inactive sources are still zeroed. lane_index() is now emitted for wave32 as well, and the test's uses_lane_index assertion is updated to match. Note the test checks the DXIL structure (select on waveGetLaneIndex feeding waveReadLaneAt), not lane values on a device; no WARP execution test covers it.

AI use: Claude Code (Claude Sonnet 5.5), coordinated by Claude Code (Claude Opus 5.5). Test report only, no code changes. Claim: #1633

**@⁠oni-swr** on GitHub · 2026-11-26 11:47 UTC · [original](https://github.com/Marvisak/VIctory/pull/3189#issuecomment-7191164224) ## WARP verification of #3189 (head `707f71541c15446c3fd443ad42921059c45f970e`) **Environment:** Windows 11 Pro 10.0.26200; WARP `D3D10Warp.dll` 10.0.26100.9818 (`VICTORY_D3D12_WARP=1`, physical GPU not used); `dxil.dll` and `dxc.exe` 1.8.2502.11 from Windows SDK 10.0.26100.0 (`VICTORY_DXIL` points at that `dxil.dll`); rustc 1.98.1. **Commands:** `cargo test -p victory-shader --lib -j 4 --locked -- --test-threads=1`, on the PR head and on the merge-base with `main` (`63bcca43c6a00a758510398fa43096ce7e4f7df0`). The test builds the container and validates it with the SDK `dxil.dll`. | Run | Result | |---|---| | PR head | 302 passed, 0 failed, 3 ignored (includes `emit::lower::tests::ds_bpermute_wave64_preserves_32_lane_half`, wave32 and wave64) | | merge-base (main) | 302 passed, 0 failed, 3 ignored (the changed test sits in the old, weaker form) | | PR head with only the fix reverted (`read_lane(x, safe_lane)` back to `read_lane(x, lane)`), test kept | **FAILED**: "wave64=false: WaveReadLaneAt must clamp inactive lanes to waveGetLaneIndex" | **Defects found:** none. Reading the diff, `running` is still computed from the unclamped `lane`, so inactive sources are still zeroed. `lane_index()` is now emitted for wave32 as well, and the test's `uses_lane_index` assertion is updated to match. Note the test checks the DXIL structure (select on `waveGetLaneIndex` feeding `waveReadLaneAt`), not lane values on a device; no WARP execution test covers it. AI use: Claude Code (Claude Sonnet 5.5), coordinated by Claude Code (Claude Opus 5.5). Test report only, no code changes. Claim: https://git.gtahub.st/github/Marvisak--VIctory/issues/1633
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 11:47 UTC · original · approved these changes

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

  • cargo test -p victory-shader --lib ds_bpermute -- --test-threads=1: passed.
  • cargo test -p victory-shader --lib emit::crosslane_tests:: -- --test-threads=1: 5/5 passed on RTX 5090 and WARP.
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Cleanly clamps inactive source lanes before WaveReadLaneAt in ds_bpermute_b32.

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

**@⁠Dukestar69** on GitHub · 2026-11-26 11:47 UTC · [original](https://github.com/Marvisak/VIctory/pull/3189#pullrequestreview-6073610802) · **approved these changes** Verified on RTX 5090 & WARP against `origin/main` (`63bcca4`): - `cargo test -p victory-shader --lib ds_bpermute -- --test-threads=1`: passed. - `cargo test -p victory-shader --lib emit::crosslane_tests:: -- --test-threads=1`: 5/5 passed on RTX 5090 and WARP. - `cargo clippy -p victory-shader --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Cleanly clamps inactive source lanes before `WaveReadLaneAt` in `ds_bpermute_b32`. 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/3189/head:github-bot/gh-3189'
git switch 'github-bot/gh-3189'

Merge

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