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

Open
reeledMarek wants to merge 1 commit from upstream-pr/3189 into main
reeledMarek commented 2026-11-26 11:28:40 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by reeledMarek on 2026-11-26T11:28:40Z.


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.
<!-- greyfinch-sync:Marvisak/VIctory:issue:6625681544 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3189). Originally posted by [reeledMarek](https://github.com/reeledMarek) on 2026-11-26T11:28:40Z. --- ## 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.
Dukestar69 commented 2026-11-26 12:05:51 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T11:47:58Z.

Review: APPROVED


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).

<!-- greyfinch-sync:Marvisak/VIctory:review:6073610802 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3189#pullrequestreview-6073610802). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T11:47:58Z. **Review:** APPROVED --- 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).
oni-swr commented 2026-11-26 12:05:59 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-26T11:47:12Z.


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://github.com/Marvisak/VIctory/issues/1633#issuecomment-7190976040

<!-- greyfinch-sync:Marvisak/VIctory:comment:7191164224 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3189#issuecomment-7191164224). Originally posted by [oni-swr](https://github.com/oni-swr) on 2026-11-26T11:47:12Z. --- ## 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://github.com/Marvisak/VIctory/issues/1633#issuecomment-7190976040
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/3189:upstream-pr/3189'
git switch 'upstream-pr/3189'

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/3189'
git switch 'upstream-pr/3189'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3189'
git switch 'upstream-pr/3189'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3189'
git switch 'main'
git merge --squash 'upstream-pr/3189'
git switch 'main'
git merge --ff-only 'upstream-pr/3189'
git switch 'main'
git merge 'upstream-pr/3189'
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
Marvisak/VIctory!3187
No description provided.