Shaders: write v_writelane_b32 under wave-level EXEC (#111) #119

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

@⁠adritoyalser on GitHub · 2026-11-24 21:38 UTC · original
adritoyalser:fix/writelane-outside-exec → main · +104 −3 · 2 files · 1 commits · open

Fixes #111.

Problem

On GFX10/RDNA2 hardware, v_writelane_b32 vN, sX, K writes lane K whenever any lane of the console wave is active in EXEC, ignoring lane K's own EXEC bit (and skips the write only when EXEC == 0 for the whole wave).

Previously, "v_writelane_b32" in crates/victory-shader/src/emit/lower.rs emitted select(console_lane == lane, a, old) and wrote it via int(self, r) -> write_placed(..., guard), which wrapped the write in select(guard, r, old) using the target lane's own EXEC bit. Whenever lane K was outside EXEC (or did not reach the block due to a per-lane skip), the write was dropped.

Fix

  • In "v_writelane_b32" (crates/victory-shader/src/emit/lower.rs):
    • When splitting a console wave64 across two 32-lane host waves (exchange with group > 32 and !local), require all_lanes(cur_ir) (calling need(cur_ir) and returning "a lane write where not every lane runs" so emit() retries without_skips).
    • When guard is Some(g), compute exec_any with dx.op.waveAnyTrue(g) (and exchange_halves + OR across both 32-lane host waves when split), combine with console_lane == lane, and store via write_placed(inst, Reg::V(reg), r, None) so the target lane's own EXEC bit does not mask out the write.
    • When guard is None, emit no wave ballot or exchange overhead.
  • Add regression test a_lane_write_reaches_its_lane_outside_exec in crates/victory-shader/src/emit/wave64_tests.rs matching the #111 synthetic program (validating both 32-lane and 64-lane DXIL against dxil.dll, verifying per-lane refusal -> without_skips promotion, and running the s0 = 10, 62, 63 GPU checks on SM 6.6 hardware).

Verification

  • cargo clippy -p victory-shader --all-targets --locked -- -D warnings — clean
  • cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings — clean
  • cargo test -p victory-shader --lib --locked wave64_tests — 6 passed, 0 failed (dxil.dll 10.0.26100.0 validated both 32-lane and 64-lane DXIL; SM 6.6 hardware execution skipped on this Windows 10 host)
**@⁠adritoyalser** on GitHub · 2026-11-24 21:38 UTC · [original](https://github.com/fxceless/victory-fork/pull/119) `adritoyalser:fix/writelane-outside-exec` → `main` · +104 −3 · 2 files · 1 commits · open Fixes #111. ### Problem On GFX10/RDNA2 hardware, `v_writelane_b32 vN, sX, K` writes lane `K` whenever any lane of the console wave is active in `EXEC`, ignoring lane `K`'s own `EXEC` bit (and skips the write only when `EXEC == 0` for the whole wave). Previously, `"v_writelane_b32"` in `crates/victory-shader/src/emit/lower.rs` emitted `select(console_lane == lane, a, old)` and wrote it via `int(self, r)` -> `write_placed(..., guard)`, which wrapped the write in `select(guard, r, old)` using the target lane's own `EXEC` bit. Whenever lane `K` was outside `EXEC` (or did not reach the block due to a per-lane skip), the write was dropped. ### Fix - In `"v_writelane_b32"` (`crates/victory-shader/src/emit/lower.rs`): - When splitting a console wave64 across two 32-lane host waves (`exchange` with `group > 32` and `!local`), require `all_lanes(cur_ir)` (calling `need(cur_ir)` and returning `"a lane write where not every lane runs"` so `emit()` retries `without_skips`). - When `guard` is `Some(g)`, compute `exec_any` with `dx.op.waveAnyTrue(g)` (and `exchange_halves` + OR across both 32-lane host waves when split), combine with `console_lane == lane`, and store via `write_placed(inst, Reg::V(reg), r, None)` so the target lane's own `EXEC` bit does not mask out the write. - When `guard` is `None`, emit no wave ballot or exchange overhead. - Add regression test `a_lane_write_reaches_its_lane_outside_exec` in `crates/victory-shader/src/emit/wave64_tests.rs` matching the `#111` synthetic program (validating both 32-lane and 64-lane DXIL against `dxil.dll`, verifying per-lane refusal -> `without_skips` promotion, and running the `s0 = 10, 62, 63` GPU checks on SM 6.6 hardware). ### Verification - `cargo clippy -p victory-shader --all-targets --locked -- -D warnings` — clean - `cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings` — clean - `cargo test -p victory-shader --lib --locked wave64_tests` — 6 passed, 0 failed (`dxil.dll` 10.0.26100.0 validated both 32-lane and 64-lane DXIL; SM 6.6 hardware execution skipped on this Windows 10 host)
On GFX10/RDNA2, v_writelane_b32 writes its target lane whenever any lane of the console wave is in EXEC, ignoring the target lane's own EXEC bit. Previously, lower.rs wrote the result through int(self, r) -> write_placed(..., guard), which re-masked the write by the target lane's own EXEC bit and dropped the write whenever the target lane was outside EXEC.

Check whether any lane of the console wave is in EXEC via dx.op.waveAnyTrue (and exchange_halves across the two 32-lane host waves when splitting a wave64 shader, refusing if not every lane reaches the block so emit() retries without_skips), combine that with `console_lane == lane`, and write via write_placed(..., None).

Add a wave64 regression test in wave64_tests.rs covering both 32-lane and 64-lane DXIL validation and GPU execution when SM 6.6 hardware is present.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:36:27 +00:00
Author
Owner

@⁠arminkhaleghirod on GitHub · 2026-11-24 22:23 UTC · original

Merged onto main 90228a7 and ran victory translate --validate over the full title (26,148 programs) on Windows 11 / RTX 4080.

No change: every failure count matches main, and no new reason appears. What it changes at run time isn't covered by this check.

**@⁠arminkhaleghirod** on GitHub · 2026-11-24 22:23 UTC · [original](https://github.com/fxceless/victory-fork/pull/119#issuecomment-7146179327) Merged onto main 90228a7 and ran `victory translate --validate` over the full title (26,148 programs) on Windows 11 / RTX 4080. No change: every failure count matches main, and no new reason appears. What it changes at run time isn't covered by this check.
Author
Owner

@⁠HAL9000RELOADED on GitHub · 2026-11-25 08:08 UTC · original

A run of this PR on a 64-lane card. The RTX 4080 check above covered translation only. #139 addresses the same issue and was run on an RX 9060 XT. This is the run for this PR's version.

Setup: Radeon RX 7900 XTX (RDNA3, waves of 32 to 64 lanes), Adrenalin 32.0.32015.7029, i7-13700KF, Windows 10 Pro 22H2 (19045), Rust 1.98.1. Windows 10's in-box D3D12 stops at SM 6.5, so the tree also carries the D3D12 Agility SDK 1.620 (the same approach as #69). The DXIL validator comes from SDK 10.0.26100 (VICTORY_DXIL). WARP stays below SM 6.6 on this machine, so the GPU cases ran on the card only. No game data used.

Base: main c96b4f2 plus the Agility patch and the stack-headroom test fix from Marvisak/VIctory#742. The PR head 481569b was merged on top of it.

tree a_lane_write_reaches_its_lane_outside_exec
base + only this PR's wave64_tests.rs fails: the assertion at wave64_tests.rs:488 gets None
this PR passes: "ran on the hardware device: v_writelane_b32 reaches lane 0 outside EXEC"

The whole workspace with this PR: 506 passed, 0 failed.

**@⁠HAL9000RELOADED** on GitHub · 2026-11-25 08:08 UTC · [original](https://github.com/fxceless/victory-fork/pull/119#issuecomment-7156654520) A run of this PR on a 64-lane card. The RTX 4080 check above covered translation only. #139 addresses the same issue and was run on an RX 9060 XT. This is the run for this PR's version. **Setup:** Radeon RX 7900 XTX (RDNA3, waves of 32 to 64 lanes), Adrenalin 32.0.32015.7029, i7-13700KF, Windows 10 Pro 22H2 (19045), Rust 1.98.1. Windows 10's in-box D3D12 stops at SM 6.5, so the tree also carries the D3D12 Agility SDK 1.620 (the same approach as #69). The DXIL validator comes from SDK 10.0.26100 (`VICTORY_DXIL`). WARP stays below SM 6.6 on this machine, so the GPU cases ran on the card only. No game data used. **Base:** `main` `c96b4f2` plus the Agility patch and the stack-headroom test fix from Marvisak/VIctory#742. The PR head `481569b` was merged on top of it. | tree | `a_lane_write_reaches_its_lane_outside_exec` | |---|---| | base + only this PR's `wave64_tests.rs` | fails: the assertion at `wave64_tests.rs:488` gets `None` | | this PR | passes: "ran on the hardware device: v_writelane_b32 reaches lane 0 outside EXEC" | The whole workspace with this PR: 506 passed, 0 failed.
github-bot force-pushed github-bot/gh-119 from 481569b04f to 94b95bd369 2026-11-26 18:45:27 +00:00 Compare
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/119/head:github-bot/gh-119'
git switch 'github-bot/gh-119'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-119'
git switch 'github-bot/gh-119'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-119'
git switch 'github-bot/gh-119'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-119'
git switch 'main'
git merge --squash 'github-bot/gh-119'
git switch 'main'
git merge --ff-only 'github-bot/gh-119'
git switch 'main'
git merge 'github-bot/gh-119'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.