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

Open
adritoyalser wants to merge 1 commit from upstream-pr/119 into main
adritoyalser commented 2026-11-24 21:38:37 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by adritoyalser on 2026-11-24T21:38:37Z.


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)
<!-- greyfinch-sync:fxceless/victory-fork:issue:6591931532 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/119). Originally posted by [adritoyalser](https://github.com/adritoyalser) on 2026-11-24T21:38:37Z. --- 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)
arminkhaleghirod commented 2026-11-24 23:09:35 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by arminkhaleghirod on 2026-11-24T22:23:54Z.


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.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7146179327 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/119#issuecomment-7146179327). Originally posted by [arminkhaleghirod](https://github.com/arminkhaleghirod) on 2026-11-24T22:23:54Z. --- 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.
HAL9000RELOADED commented 2026-11-25 08:09:07 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by HAL9000RELOADED on 2026-11-25T08:08:26Z.


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.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7156654520 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/119#issuecomment-7156654520). Originally posted by [HAL9000RELOADED](https://github.com/HAL9000RELOADED) on 2026-11-25T08:08:26Z. --- 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.
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/119:upstream-pr/119'
git switch 'upstream-pr/119'

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