shader: lower non-sum wave prefix operations to DXIL #2776

Open
github-bot wants to merge 7 commits from github-bot/gh-2776 into main AGit
Owner

@⁠JAEdotUK on GitHub · 2026-11-25 20:16 UTC · original
JAEdotUK:fix/wave-prefix-ops → main · +393 −1 · 2 files · 7 commits · open

Implements DXIL lowering for the integer, signed and bitwise wave prefix operations that were previously rejected: min, max, and, or and xor, in inclusive and exclusive modes, across up to 64 lanes via waveActiveBallot + waveReadLaneAt.

Float min/max prefixes are deliberately not included. Reviewers found the lowering changes a lone active lane's NaN and subnormal values. They are rejected with the original error and will come in a follow-up, coordinated with #470.

Tested on an RX 9070 XT: 1,792 lane comparisons against a CPU model (896 each at Wave32 and Wave64), all matching. WARP skips these pipelines.

Code and debugging produced with Claude (Claude Sonnet 5.5), plus Gemini earlier.

**@⁠JAEdotUK** on GitHub · 2026-11-25 20:16 UTC · [original](https://github.com/Marvisak/VIctory/pull/2776) `JAEdotUK:fix/wave-prefix-ops` → `main` · +393 −1 · 2 files · 7 commits · open Implements DXIL lowering for the integer, signed and bitwise wave prefix operations that were previously rejected: min, max, and, or and xor, in inclusive and exclusive modes, across up to 64 lanes via waveActiveBallot + waveReadLaneAt. Float min/max prefixes are deliberately not included. Reviewers found the lowering changes a lone active lane's NaN and subnormal values. They are rejected with the original error and will come in a follow-up, coordinated with #470. Tested on an RX 9070 XT: 1,792 lane comparisons against a CPU model (896 each at Wave32 and Wave64), all matching. WARP skips these pipelines. Code and debugging produced with Claude (Claude Sonnet 5.5), plus Gemini earlier.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:13:57 +00:00
Author
Owner

@⁠oni-swr on GitHub · 2026-11-25 20:36 UTC · original

Independent verification of head 0e16a724 (WARP/CPU): changes requested.

  • Tests: victory-shader --lib 268 pass, 3 fail. The same 3 fail on origin/main (gathers_at_a_level_match_the_hardware, permutes_read_the_lane_named_and_zero_from_lanes_left_out, a_mask_joined_with_data_at_a_uniform_loop_is_its_number: WARP has no 32-lane pipeline), so they are baseline WARP failures, not caused by this PR. Clippy -D warnings is clean.
  • Negative control fails: the new test does not exercise the new code. I put panic!() as the first statement of the new (op, Some(inclusive)) arm in lower.rs, and wave_prefix_non_sum_ops_lower_and_validate still passes. I also replaced the arm with the old Err(...), and the test passes too. So the arm is never reached, and its lane-by-lane scan (and the exclusive-prefix computation) is unverified. The test's DPP sequence is evidently not recognized as a wave prefix. Please make it hit the arm, and ideally compare the results with a CPU model, as the valu_tests do.
  • Mojibake: 13 comment lines were double/triple-encoded (×, π, ², ±, −, ≤, → became strings like Ã-sequences), for example the /// Block × 4096 + page in the block. doc comment. Please restore them.
  • Scope: most of the diff (most of its hunks) is unrelated rustfmt reflowing of lower.rs, and origin/main is not rustfmt-clean, so this is churn that hides the actual change and will conflict with other open shader PRs. Please limit the diff to the feature.

Method: WARP/CPU only (no physical GPU; VICTORY_WARP=1, VICTORY_D3D12_WARP=1, Windows SDK dxil.dll on PATH, so DXIL validation ran), cargo test -p <crate> --lib --locked and cargo clippy -p <crate> --all-targets --locked -- -D warnings, compared with origin/main 13f91cae. Nothing from the game was used.

AI-assisted review (Claude Code / Claude Sonnet 5.5).

**@⁠oni-swr** on GitHub · 2026-11-25 20:36 UTC · [original](https://github.com/Marvisak/VIctory/pull/2776#issuecomment-7173912966) Independent verification of head `0e16a724` (WARP/CPU): **changes requested**. - Tests: `victory-shader --lib` 268 pass, 3 fail. The same 3 fail on `origin/main` (`gathers_at_a_level_match_the_hardware`, `permutes_read_the_lane_named_and_zero_from_lanes_left_out`, `a_mask_joined_with_data_at_a_uniform_loop_is_its_number`: WARP has no 32-lane pipeline), so they are baseline WARP failures, not caused by this PR. Clippy `-D warnings` is clean. - **Negative control fails: the new test does not exercise the new code.** I put `panic!()` as the first statement of the new `(op, Some(inclusive))` arm in `lower.rs`, and `wave_prefix_non_sum_ops_lower_and_validate` still passes. I also replaced the arm with the old `Err(...)`, and the test passes too. So the arm is never reached, and its lane-by-lane scan (and the exclusive-prefix computation) is unverified. The test's DPP sequence is evidently not recognized as a wave prefix. Please make it hit the arm, and ideally compare the results with a CPU model, as the `valu_tests` do. - **Mojibake**: 13 comment lines were double/triple-encoded (`×`, `π`, `²`, `±`, `−`, `≤`, `→` became strings like `Ã`-sequences), for example the `/// Block × 4096 + page in the block.` doc comment. Please restore them. - **Scope**: most of the diff (most of its hunks) is unrelated rustfmt reflowing of `lower.rs`, and `origin/main` is not rustfmt-clean, so this is churn that hides the actual change and will conflict with other open shader PRs. Please limit the diff to the feature. Method: WARP/CPU only (no physical GPU; `VICTORY_WARP=1`, `VICTORY_D3D12_WARP=1`, Windows SDK `dxil.dll` on PATH, so DXIL validation ran), `cargo test -p <crate> --lib --locked` and `cargo clippy -p <crate> --all-targets --locked -- -D warnings`, compared with `origin/main` 13f91cae. Nothing from the game was used. AI-assisted review (Claude Code / Claude Sonnet 5.5).
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-25 20:40 UTC · original

The previous code refused any wave prefix that wasn't a sum; lowering product/min/max/bitwise prefixes to DXIL removes a whole skip bucket. The exclusive-from-inclusive construction in the tests is the standard pattern. Structure looks consistent with how the sum prefix already lowers.

**@⁠kotekompotek** on GitHub · 2026-11-25 20:40 UTC · [original](https://github.com/Marvisak/VIctory/pull/2776#issuecomment-7174032133) The previous code refused any wave prefix that wasn't a sum; lowering product/min/max/bitwise prefixes to DXIL removes a whole skip bucket. The exclusive-from-inclusive construction in the tests is the standard pattern. Structure looks consistent with how the sum prefix already lowers.
Author
Owner

@⁠JAEdotUK on GitHub · 2026-11-25 22:48 UTC · original

Thanks for the careful review. The updated head addresses each point:

  • Test: replaced wave_prefix_non_sum_ops_lower_and_validate with wave_prefix_non_sum_ops_match_scan_across_lanes, which runs min/max (u32, i32, f32) and and/or/xor, inclusive and exclusive, and compares all 32 lanes against a CPU model. I repeated your negative control: with panic!() as the first statement of the (op, Some(inclusive)) arm, the test fails, so the arm is reached. The test also counts the comparisons it ran.
  • Hardware: on an RX 9070 XT (Windows 11) it runs 1152 lane comparisons and all match. On my machine the WARP PSO is skipped ("The parameter is incorrect"), so a WARP-only setup will not exercise the comparison.
  • Mojibake: restored the 13 garbled comment lines from origin/main.
  • Scope: removed the unrelated rustfmt reflow; the diff is the new arm in lower.rs plus the test.

Also merged main to resolve a conflict in valu_tests.rs, and merged the integer and float min/max cases in the new arm so lower.rs stays under the 512 KiB policy limit (it has only a few KB of headroom left on main, which other PRs may hit).

victory-shader --lib: 303 passed, 0 failed, 3 ignored. Clippy -D warnings clean.

I'm new to this and used AI help (Gemini, and Claude for review and debugging), so please flag anything that looks off.

**@⁠JAEdotUK** on GitHub · 2026-11-25 22:48 UTC · [original](https://github.com/Marvisak/VIctory/pull/2776#issuecomment-7176817592) Thanks for the careful review. The updated head addresses each point: - Test: replaced wave_prefix_non_sum_ops_lower_and_validate with wave_prefix_non_sum_ops_match_scan_across_lanes, which runs min/max (u32, i32, f32) and and/or/xor, inclusive and exclusive, and compares all 32 lanes against a CPU model. I repeated your negative control: with panic!() as the first statement of the (op, Some(inclusive)) arm, the test fails, so the arm is reached. The test also counts the comparisons it ran. - Hardware: on an RX 9070 XT (Windows 11) it runs 1152 lane comparisons and all match. On my machine the WARP PSO is skipped ("The parameter is incorrect"), so a WARP-only setup will not exercise the comparison. - Mojibake: restored the 13 garbled comment lines from origin/main. - Scope: removed the unrelated rustfmt reflow; the diff is the new arm in lower.rs plus the test. Also merged main to resolve a conflict in valu_tests.rs, and merged the integer and float min/max cases in the new arm so lower.rs stays under the 512 KiB policy limit (it has only a few KB of headroom left on main, which other PRs may hit). victory-shader --lib: 303 passed, 0 failed, 3 ignored. Clippy -D warnings clean. I'm new to this and used AI help (Gemini, and Claude for review and debugging), so please flag anything that looks off.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 23:23 UTC · original

Automated triage for the maintainers.

This replaces the Err("a wave prefix of an operation other than a sum") arm in Lower::shape (emit/lower.rs) with a lowering for the min/max/and/or/xor prefixes that wave.rs already recognizes: a ballot of the host lanes, then a scan over up to 64 lanes with waveReadLaneAt, inclusive or exclusive. The updated head drops the earlier reformatting and garbled comments, and the new wave_prefix_non_sum_ops_match_scan_across_lanes test runs a real DPP prefix sequence and compares all lanes against a CPU model; the author reports it fails when the new arm panics. Points for the maintainer: the scan emits 64 unrolled lane reads per prefix, so shaders get larger; the Op::AddH branch is an unreachable!() in the translator; and the shared run_cases harness now binds a 32-dword UAV for every VALU test. CI passes on this head.

This is a recommendation for a maintainer to look, not an approval.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 23:23 UTC · [original](https://github.com/Marvisak/VIctory/pull/2776#issuecomment-7177497840) <!-- victory-triage v1 head=5fa0c3f8ef9540395e1d0dda7659dc6908383a68 verdict=merge-candidate at=2026-11-25T23:23:28Z --> Automated triage for the maintainers. This replaces the `Err("a wave prefix of an operation other than a sum")` arm in `Lower::shape` (`emit/lower.rs`) with a lowering for the min/max/and/or/xor prefixes that `wave.rs` already recognizes: a ballot of the host lanes, then a scan over up to 64 lanes with `waveReadLaneAt`, inclusive or exclusive. The updated head drops the earlier reformatting and garbled comments, and the new `wave_prefix_non_sum_ops_match_scan_across_lanes` test runs a real DPP prefix sequence and compares all lanes against a CPU model; the author reports it fails when the new arm panics. Points for the maintainer: the scan emits 64 unrolled lane reads per prefix, so shaders get larger; the `Op::AddH` branch is an `unreachable!()` in the translator; and the shared `run_cases` harness now binds a 32-dword UAV for every VALU test. CI passes on this head. This is a recommendation for a maintainer to look, not an approval. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 00:30 UTC · original · reviewed

Verified head 5fa0c3f8 cleanly merged onto origin/main (63bcca43) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + D3D12 WARP + VICTORY_D3D12_DEBUG=1 + Windows SDK 10.0.26100.0 dxil.dll).

Code & Semantics Review

  • Lowering Op::{MinU, MaxU, MinI, MaxI, MinF, MaxF, And, Or, Xor} for both inclusive and exclusive prefixes is sound: Op::AddH only uses Shape::Half (wave.rs:631-650), inactive host lanes are avoided by clamping safe_k to FirstbitLo(waveActiveBallot(true)), title-inactive lanes carry ident, and MinF/MaxF run ftz + self.max_min preserving RDNA2 -0.0 < +0.0 and non-NaN preference.
  • File-size heads-up: Merged onto 63bcca43, crates/victory-shader/src/emit/lower.rs is 524,209 B — only 79 bytes under cargo xtask policy's 524,288 B (512 KiB) cap. Extracting this prefix scan helper into a submodule (e.g. emit/lower/wave.rs) would avoid tripping policy when combined with any other lower.rs PR.

Local Verification (VICTORY_D3D12_DEBUG=1, dxil.dll)

  • RTX 5090 & WARP: wave_prefix_non_sum_ops + emit::crosslane_tests + emit::lower::tests: 39/39 passed on both adapters (covering all 9 ops x inclusive/exclusive across 32 lanes).
  • cargo clippy --locked -p victory-shader --all-targets -- -D warnings (default and --all-features) & cargo xtask policy (191 files ok): clean.

Looks solid and ready to merge (mind the 79 B lower.rs headroom).

**@⁠fuzeofficlal** on GitHub · 2026-11-26 00:30 UTC · [original](https://github.com/Marvisak/VIctory/pull/2776#pullrequestreview-6066925721) · **reviewed** Verified head `5fa0c3f8` cleanly merged onto `origin/main` (`63bcca43`) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + D3D12 WARP + `VICTORY_D3D12_DEBUG=1` + Windows SDK 10.0.26100.0 `dxil.dll`). ### Code & Semantics Review - Lowering `Op::{MinU, MaxU, MinI, MaxI, MinF, MaxF, And, Or, Xor}` for both inclusive and exclusive prefixes is sound: `Op::AddH` only uses `Shape::Half` (`wave.rs:631-650`), inactive host lanes are avoided by clamping `safe_k` to `FirstbitLo(waveActiveBallot(true))`, title-inactive lanes carry `ident`, and `MinF`/`MaxF` run `ftz` + `self.max_min` preserving RDNA2 `-0.0 < +0.0` and non-NaN preference. - **File-size heads-up**: Merged onto `63bcca43`, `crates/victory-shader/src/emit/lower.rs` is **`524,209 B`** — only **79 bytes** under `cargo xtask policy`'s `524,288 B` (512 KiB) cap. Extracting this prefix scan helper into a submodule (e.g. `emit/lower/wave.rs`) would avoid tripping policy when combined with any other `lower.rs` PR. ### Local Verification (`VICTORY_D3D12_DEBUG=1`, `dxil.dll`) - **RTX 5090 & WARP**: `wave_prefix_non_sum_ops` + `emit::crosslane_tests` + `emit::lower::tests`: **39/39 passed** on both adapters (covering all 9 ops x inclusive/exclusive across 32 lanes). - `cargo clippy --locked -p victory-shader --all-targets -- -D warnings` (default and `--all-features`) & `cargo xtask policy` (`191 files ok`): clean. Looks solid and ready to merge (mind the `79 B` `lower.rs` headroom).
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 03:11 UTC · original · reviewed

Tested merged onto origin/main (63bcca4) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP, dxil.dll validator active):

  • cargo test -p victory-shader --lib emit::valu_tests::wave_prefix_non_sum_ops_match_scan_across_lanes -- --nocapture: reported ok, but executed 0 GPU comparisons — all 36 PSOs were skipped with E_INVALIDARG on both RTX 5090 (Wave32-only) and inbox WARP (4-lane):
    hardware (min_u32, inc=true): PSO skipped (Falscher Parameter.)
    warp (min_u32, inc=true): PSO skipped (Falscher Parameter.)
    ...
    wave prefix: 0 lane comparisons ran
    
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Adding a Wave32 (wave64: false, numthreads(32, 1, 1)) test pass alongside Wave64 would allow hardware execution and verification on NVIDIA Wave32 GPUs (and prevent the test from silently passing with 0 comparisons when Wave64 is unavailable). Also note lower.rs passes Attr::ReadOnly for waveGetLaneIndex (other call sites use Attr::ReadNone), and unrolls 0..64 unconditionally even for Wave32 programs (0..32 suffices when !wave64).

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

**@⁠Dukestar69** on GitHub · 2026-11-26 03:11 UTC · [original](https://github.com/Marvisak/VIctory/pull/2776#pullrequestreview-6068039579) · **reviewed** Tested merged onto `origin/main` (`63bcca4`) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP, `dxil.dll` validator active): - `cargo test -p victory-shader --lib emit::valu_tests::wave_prefix_non_sum_ops_match_scan_across_lanes -- --nocapture`: reported `ok`, **but executed 0 GPU comparisons** — all 36 PSOs were skipped with `E_INVALIDARG` on both RTX 5090 (Wave32-only) and inbox WARP (4-lane): ``` hardware (min_u32, inc=true): PSO skipped (Falscher Parameter.) warp (min_u32, inc=true): PSO skipped (Falscher Parameter.) ... wave prefix: 0 lane comparisons ran ``` - `cargo clippy -p victory-shader --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Adding a Wave32 (`wave64: false`, `numthreads(32, 1, 1)`) test pass alongside Wave64 would allow hardware execution and verification on NVIDIA Wave32 GPUs (and prevent the test from silently passing with 0 comparisons when Wave64 is unavailable). Also note `lower.rs` passes `Attr::ReadOnly` for `waveGetLaneIndex` (other call sites use `Attr::ReadNone`), and unrolls `0..64` unconditionally even for Wave32 programs (`0..32` suffices when `!wave64`). Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Author
Owner

@⁠JAEdotUK on GitHub · 2026-11-26 10:09 UTC · original

Pushed 25f40e7. Addresses Dukestar69's report that the test passed with 0 comparisons on Wave32 hardware.

  • valu_tests.rs only: the test now runs a Wave32 variant (32-lane lane-mask sequence) as well as Wave64, and skips whichever variant the device refuses to build a PSO for.
  • RX 9070 XT: both variants ran, 1,152 lane comparisons each (2,304 total), all matching the CPU model. WARP refuses both variants (PSO "The parameter is incorrect"), so it still compares nothing.
  • New env var VICTORY_REQUIRE_HW=1 makes the test fail if 0 lanes were compared. It is off by default so WARP-only machines and CI stay green.
  • Not verified: the Wave32 variant on an RTX 5090 (I don't have one), and DXIL validation on my machine.
  • Left unchanged in lower.rs: Attr::ReadOnly on waveGetLaneIndex (all four call sites use ReadOnly; the ReadNone calls nearby are a different op). I also left the 0..64 unroll alone: lower.rs has only 79 bytes of headroom under the 512 KiB policy, so trimming it to 0..32 for Wave32 would be better done in a follow-up, possibly with Marvisak's suggested submodule split.

Tests: victory-shader --lib 303 passed, 0 failed, 3 ignored. Clippy -D warnings and cargo xtask policy clean.

@⁠oni-swr, could you re-review?

Code and debugging produced with Claude (Claude Sonnet 5.5), plus Gemini earlier.

**@⁠JAEdotUK** on GitHub · 2026-11-26 10:09 UTC · [original](https://github.com/Marvisak/VIctory/pull/2776#issuecomment-7188986447) Pushed 25f40e7. Addresses Dukestar69's report that the test passed with 0 comparisons on Wave32 hardware. - valu_tests.rs only: the test now runs a Wave32 variant (32-lane lane-mask sequence) as well as Wave64, and skips whichever variant the device refuses to build a PSO for. - RX 9070 XT: both variants ran, 1,152 lane comparisons each (2,304 total), all matching the CPU model. WARP refuses both variants (PSO "The parameter is incorrect"), so it still compares nothing. - New env var VICTORY_REQUIRE_HW=1 makes the test fail if 0 lanes were compared. It is off by default so WARP-only machines and CI stay green. - Not verified: the Wave32 variant on an RTX 5090 (I don't have one), and DXIL validation on my machine. - Left unchanged in lower.rs: Attr::ReadOnly on waveGetLaneIndex (all four call sites use ReadOnly; the ReadNone calls nearby are a different op). I also left the 0..64 unroll alone: lower.rs has only 79 bytes of headroom under the 512 KiB policy, so trimming it to 0..32 for Wave32 would be better done in a follow-up, possibly with Marvisak's suggested submodule split. Tests: victory-shader --lib 303 passed, 0 failed, 3 ignored. Clippy -D warnings and cargo xtask policy clean. @⁠oni-swr, could you re-review? Code and debugging produced with Claude (Claude Sonnet 5.5), plus Gemini earlier.
Author
Owner

@⁠steven-seagull27 on GitHub · 2026-11-26 10:14 UTC · original · edited 2026-11-26 11:29 UTC

Update on the integer-only head 46ec91e. The RTX 5080 matched all 896 full-Wave32 comparisons on the unmodified PR test. Windows inbox WARP refused all 14 pipelines for each fixed wave width. App-local Microsoft WARP 1.0.22 accepted the pipelines and the unmodified test stopped at inclusive unsigned minimum on lane 1 of the 32-thread Wave64 group: it read 0xffffffff and expected 0x9236567a.

The existing full-vs-partial test commit cherry-picks cleanly on this head. In two fresh WARP 1.0.22 processes the complete counts were 0/896 wrong for 32 threads at Wave32, 0/1,792 wrong for 64 threads at Wave64, and 658/896 wrong for 32 threads at Wave64. All 14 pipelines ran in each case. This count covers the seven integer and bitwise operations now in the PR. The author deferred float min/max. Upstream revision


@⁠JAEdotUK I tested your Wave32 update at 25f40e70 on native Windows with VICTORY_REQUIRE_HW=1 and the Windows SDK 10.0.26100.0 DXIL validator loaded. The RTX 5080 built all 18 Wave32 pipelines and matched all 1,152 lanes in both runs. Built-in WARP skipped both widths. App-local WARP 1.0.22 accepted Wave64 and failed the first 32-thread case in both runs. Your RX 9070 XT passed that same case. Author’s Radeon results

The follow-up adds a 64-thread control for direct comparison with the PR’s original 32-thread Wave64 case. Test-only commit on your revision

Mismatches / lane comparisons per run with the follow-up patch. Each result repeated in three fresh processes. Each supported case ran nine operations, inclusive and exclusive, with two sets of inputs. The comparison includes the sentinel in inactive guest lanes.

Adapter Wave32, 32 threads Wave64, 64 threads Wave64, 32 threads
RTX 5080, 621.40 0 / 1,152 Unsupported Unsupported
Windows inbox WARP Unsupported Unsupported Unsupported
App-local WARP 1.0.22 0 / 1,152 0 / 2,304 846 / 1,152

Inbox WARP reported a fixed wave size of four and executed zero comparisons. On WARP 1.0.22, the first partial-wave mismatch was the inclusive unsigned minimum at lane 1. The reference expected 0x9236567a and the shader returned its identity, 0xffffffff.

Native HLSL control. Using DXC cs_6_6 and the same WARP 1.0.22 DLL, a [WaveSize(64)] shader with 32 threads counted 32 active lanes and mapped threads 0–31 to lanes 0–31. Yet WaveActiveBallot(true) returned zero for both mask words in every lane across three runs. With 64 threads both mask words were 0xffffffff in every lane. The neighboring-lane read and unsigned wave minimum were correct for both group sizes.

In a diagnostic build I replaced just the prefix ballot with the expected mask for this group, low 0xffffffff and high 0. The same partial-wave fixture went from 846/1,152 mismatches to 0/1,152 in each of two runs. That accounts for all the observed failures on this WARP version. The shared commit changes only tests.

Native shader used for the control
RWByteAddressBuffer output : register(u0);

[RootSignature("DescriptorTable(UAV(u0))")]
[WaveSize(64)]
[numthreads(THREADS, 1, 1)]
void main(uint id : SV_GroupIndex) {
    uint lane = WaveGetLaneIndex();
    uint4 active = WaveActiveBallot(true);
    uint value = 0x5a00u + id;
    uint neighbor = WaveReadLaneAt(value, lane ^ 1u);
    output.Store4(32 * id, uint4(id, lane, WaveGetLaneCount(), WaveActiveCountBits(true)));
    output.Store4(32 * id + 16, uint4(active.x, active.y, neighbor, WaveActiveMin(value)));
}

I compiled it twice, with THREADS=32 and THREADS=64, then dispatched one group for each.

To apply and rerun from 25f40e70 on Windows

git fetch https://github.com/steven-seagull27/VIctory.git codex/pr2776-wave-prefix-readbacks
git cherry-pick 2ed7f86a34bf91a757f036eb458d51293beaf121
$env:VICTORY_REQUIRE_HW = '1'
cargo test --locked -p victory-shader --lib emit::valu_tests::wave_prefix_non_sum_ops_match_scan_across_lanes -- --exact --test-threads=1 --nocapture

For the WARP 1.0.22 run, I put that package’s x64 d3d10warp.dll next to the compiled test executable, set VICTORY_WARP=1, and ran the executable with the same test filter. The partial Wave64 result makes that run exit with a test failure after it prints all three counts.

AI-assisted testing and write-up, using synthetic inputs on Windows.

**@⁠steven-seagull27** on GitHub · 2026-11-26 10:14 UTC · [original](https://github.com/Marvisak/VIctory/pull/2776#issuecomment-7189086585) · edited 2026-11-26 11:29 UTC **Update on the integer-only head `46ec91e`.** The RTX 5080 matched all 896 full-Wave32 comparisons on the unmodified PR test. Windows inbox WARP refused all 14 pipelines for each fixed wave width. App-local Microsoft WARP 1.0.22 accepted the pipelines and the unmodified test stopped at inclusive unsigned minimum on lane 1 of the 32-thread Wave64 group: it read `0xffffffff` and expected `0x9236567a`. The existing [full-vs-partial test commit](https://github.com/steven-seagull27/VIctory/commit/2ed7f86a34bf91a757f036eb458d51293beaf121) cherry-picks cleanly on this head. In two fresh WARP 1.0.22 processes the complete counts were **0/896 wrong** for 32 threads at Wave32, **0/1,792 wrong** for 64 threads at Wave64, and **658/896 wrong** for 32 threads at Wave64. All 14 pipelines ran in each case. This count covers the seven integer and bitwise operations now in the PR. The author deferred float min/max. [Upstream revision](https://github.com/Marvisak/VIctory/commit/46ec91e146e5f14d58ab58c6f9496cc3a4a193c2) --- @⁠JAEdotUK I tested your Wave32 update at `25f40e70` on native Windows with `VICTORY_REQUIRE_HW=1` and the Windows SDK 10.0.26100.0 DXIL validator loaded. The RTX 5080 built all 18 Wave32 pipelines and matched all 1,152 lanes in both runs. Built-in WARP skipped both widths. App-local WARP 1.0.22 accepted Wave64 and failed the first 32-thread case in both runs. Your RX 9070 XT passed that same case. [Author’s Radeon results](https://git.gtahub.st/github/Marvisak--VIctory/pulls/2776) The follow-up adds a 64-thread control for direct comparison with the PR’s original 32-thread Wave64 case. [Test-only commit on your revision](https://github.com/steven-seagull27/VIctory/commit/2ed7f86a34bf91a757f036eb458d51293beaf121) **Mismatches / lane comparisons per run with the follow-up patch**. Each result repeated in three fresh processes. Each supported case ran nine operations, inclusive and exclusive, with two sets of inputs. The comparison includes the sentinel in inactive guest lanes. | Adapter | Wave32, 32 threads | Wave64, 64 threads | Wave64, 32 threads | |---|---:|---:|---:| | RTX 5080, 621.40 | 0 / 1,152 | Unsupported | Unsupported | | Windows inbox WARP | Unsupported | Unsupported | Unsupported | | App-local WARP 1.0.22 | 0 / 1,152 | 0 / 2,304 | **846 / 1,152** | Inbox WARP reported a fixed wave size of four and executed zero comparisons. On WARP 1.0.22, the first partial-wave mismatch was the inclusive unsigned minimum at lane 1. The reference expected `0x9236567a` and the shader returned its identity, `0xffffffff`. **Native HLSL control.** Using DXC `cs_6_6` and the same WARP 1.0.22 DLL, a `[WaveSize(64)]` shader with 32 threads counted 32 active lanes and mapped threads 0–31 to lanes 0–31. Yet `WaveActiveBallot(true)` returned zero for both mask words in every lane across three runs. With 64 threads both mask words were `0xffffffff` in every lane. The neighboring-lane read and unsigned wave minimum were correct for both group sizes. In a diagnostic build I replaced just the prefix ballot with the expected mask for this group, low `0xffffffff` and high `0`. The same partial-wave fixture went from **846/1,152 mismatches to 0/1,152** in each of two runs. That accounts for all the observed failures on this WARP version. The shared commit changes only tests. <details> <summary>Native shader used for the control</summary> ```hlsl RWByteAddressBuffer output : register(u0); [RootSignature("DescriptorTable(UAV(u0))")] [WaveSize(64)] [numthreads(THREADS, 1, 1)] void main(uint id : SV_GroupIndex) { uint lane = WaveGetLaneIndex(); uint4 active = WaveActiveBallot(true); uint value = 0x5a00u + id; uint neighbor = WaveReadLaneAt(value, lane ^ 1u); output.Store4(32 * id, uint4(id, lane, WaveGetLaneCount(), WaveActiveCountBits(true))); output.Store4(32 * id + 16, uint4(active.x, active.y, neighbor, WaveActiveMin(value))); } ``` I compiled it twice, with `THREADS=32` and `THREADS=64`, then dispatched one group for each. </details> To apply and rerun from `25f40e70` on Windows ```powershell git fetch https://github.com/steven-seagull27/VIctory.git codex/pr2776-wave-prefix-readbacks git cherry-pick 2ed7f86a34bf91a757f036eb458d51293beaf121 $env:VICTORY_REQUIRE_HW = '1' cargo test --locked -p victory-shader --lib emit::valu_tests::wave_prefix_non_sum_ops_match_scan_across_lanes -- --exact --test-threads=1 --nocapture ``` For the WARP 1.0.22 run, I put that package’s x64 `d3d10warp.dll` next to the compiled test executable, set `VICTORY_WARP=1`, and ran the executable with the same test filter. The partial Wave64 result makes that run exit with a test failure after it prints all three counts. AI-assisted testing and write-up, using synthetic inputs on Windows.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 10:46 UTC · original · requested changes

The integer and bitwise prefix lowerings match wave.rs, and the Wave32 harness runs 1,152 lane comparisons on hardware.

One correctness issue blocks the floating-point path (Op::MinF / Op::MaxF in emit/lower.rs:1287-1333): when lane 0 is active, the guest DPP prefix never runs a floating-point min/max on that singleton value—inclusive lane 0 keeps its input bits directly, and exclusive lane 1 copies them via v_mov_b32. Because the new lowering unconditionally applies self.ftz and combines the first active element with ±Inf via self.max_min (DXIL FMin/FMax), a singleton qNaN (0x7fc00001) turns into ±Inf and a singleton subnormal (0x00000001/0x80000001) flushes to ±0. Please preserve singleton float results unchanged (or continue declining MinF/MaxF until singleton inputs are preserved), and add NaN/subnormal plus 64-thread Wave64 coverage.

Also note two maintenance points: merged onto 63bcca43, emit/lower.rs sits at 524,209 bytes (only 79 bytes below the 512 KiB policy limit, so extracting a helper submodule would help), and try_build_valu_cs/run_cases (dwords: 4 -> 32, RawUav(1) -> RawUav(32)) can stay unchanged since the new test uses its own harness.

Verified locally on Windows 11 x64 (25f40e70):

  • cargo run --locked -p xtask -- policy: passed (190 files ok; emit/lower.rs merged onto 63bcca43 = 524,209 bytes)
  • cargo clippy -p victory-shader --all-targets --locked -- -D warnings (default and --all-features): clean
  • emit::crosslane_tests -- --test-threads=1: 5 passed, 0 failed
  • wave_prefix_non_sum_ops_match_scan_across_lanes -- --test-threads=1: passed (1,152 Wave32 hardware lane comparisons on RTX 5090; Wave64 and VICTORY_WARP=1 skipped with E_INVALIDARG)
**@⁠fuzeofficlal** on GitHub · 2026-11-26 10:46 UTC · [original](https://github.com/Marvisak/VIctory/pull/2776#pullrequestreview-6072735752) · **requested changes** The integer and bitwise prefix lowerings match `wave.rs`, and the Wave32 harness runs 1,152 lane comparisons on hardware. One correctness issue blocks the floating-point path (`Op::MinF` / `Op::MaxF` in `emit/lower.rs:1287-1333`): when lane 0 is active, the guest DPP prefix never runs a floating-point `min`/`max` on that singleton value—inclusive lane 0 keeps its input bits directly, and exclusive lane 1 copies them via `v_mov_b32`. Because the new lowering unconditionally applies `self.ftz` and combines the first active element with `±Inf` via `self.max_min` (DXIL `FMin`/`FMax`), a singleton `qNaN` (`0x7fc00001`) turns into `±Inf` and a singleton subnormal (`0x00000001`/`0x80000001`) flushes to `±0`. Please preserve singleton float results unchanged (or continue declining `MinF`/`MaxF` until singleton inputs are preserved), and add NaN/subnormal plus 64-thread Wave64 coverage. Also note two maintenance points: merged onto `63bcca43`, `emit/lower.rs` sits at `524,209` bytes (only `79` bytes below the 512 KiB policy limit, so extracting a helper submodule would help), and `try_build_valu_cs`/`run_cases` (`dwords: 4 -> 32`, `RawUav(1) -> RawUav(32)`) can stay unchanged since the new test uses its own harness. Verified locally on Windows 11 x64 (`25f40e70`): - `cargo run --locked -p xtask -- policy`: passed (`190 files ok`; `emit/lower.rs` merged onto `63bcca43` = `524,209` bytes) - `cargo clippy -p victory-shader --all-targets --locked -- -D warnings` (default and `--all-features`): clean - `emit::crosslane_tests -- --test-threads=1`: 5 passed, 0 failed - `wave_prefix_non_sum_ops_match_scan_across_lanes -- --test-threads=1`: passed (`1,152` Wave32 hardware lane comparisons on RTX 5090; Wave64 and `VICTORY_WARP=1` skipped with `E_INVALIDARG`)
Author
Owner

@⁠steven-seagull27 on GitHub · 2026-11-26 10:59 UTC · original

@⁠JAEdotUK @⁠fuzeofficlal I reproduced the copied-singleton issue on 25f40e70. A guest DPP row shift with no source leaves lane 0 untouched. Inclusive lane 0 keeps its input bits, and exclusive lane 1 gets them through v_mov_b32. On the RTX 5080, inclusive min returned 0x7f800000 for 0x7fc00001. Review

Full-wave regression Incorrect on PR head Incorrect with fix
RTX 5080, driver 621.40, Wave32 16 / 1,024 0 / 1,024
WARP 1.0.22, Wave32 16 / 1,024 0 / 1,024
WARP 1.0.22, Wave64 16 / 2,048 0 / 2,048

The regression checks every lane of inclusive and exclusive min/max with two NaN payloads, positive and negative subnormals, both signed zeros, normal values and infinities. Windows inbox WARP skipped both fixed widths. The RTX also passed the existing 1,152 masked-pattern comparisons. WARP 1.0.22 still fails the separate 32-thread group on Wave64 in the original integer test. Earlier partial-wave report

The fix keeps lane 0's raw bits until a real pair is combined. The matcher only accepts float-prefix patterns with a copied singleton and declines cases where the guest explicitly applies min/max to it. Eight wave-recognition tests, strict all-feature shader Clippy, and asset policy passed. One-commit fix and tests

git fetch https://github.com/steven-seagull27/VIctory.git codex/pr2776-preserve-prefix-singleton
git cherry-pick ecdfcf7391413a146268ea0bd93a1bf07156f919
cargo test -p victory-shader --lib float_prefix_singletons_keep_their_bits -- --nocapture

AI-assisted with Codex. Synthetic shaders on native Windows.

**@⁠steven-seagull27** on GitHub · 2026-11-26 10:59 UTC · [original](https://github.com/Marvisak/VIctory/pull/2776#issuecomment-7190119102) @⁠JAEdotUK @⁠fuzeofficlal I reproduced the copied-singleton issue on `25f40e70`. A guest DPP row shift with no source leaves lane 0 untouched. Inclusive lane 0 keeps its input bits, and exclusive lane 1 gets them through `v_mov_b32`. On the RTX 5080, inclusive min returned `0x7f800000` for `0x7fc00001`. [Review](https://git.gtahub.st/github/Marvisak--VIctory/pulls/2776) | Full-wave regression | Incorrect on PR head | Incorrect with fix | |---|---:|---:| | RTX 5080, driver 621.40, Wave32 | 16 / 1,024 | 0 / 1,024 | | WARP 1.0.22, Wave32 | 16 / 1,024 | 0 / 1,024 | | WARP 1.0.22, Wave64 | 16 / 2,048 | 0 / 2,048 | The regression checks every lane of inclusive and exclusive min/max with two NaN payloads, positive and negative subnormals, both signed zeros, normal values and infinities. Windows inbox WARP skipped both fixed widths. The RTX also passed the existing 1,152 masked-pattern comparisons. WARP 1.0.22 still fails the separate 32-thread group on Wave64 in the original integer test. [Earlier partial-wave report](https://git.gtahub.st/github/Marvisak--VIctory/pulls/2776) The fix keeps lane 0's raw bits until a real pair is combined. The matcher only accepts float-prefix patterns with a copied singleton and declines cases where the guest explicitly applies min/max to it. Eight wave-recognition tests, strict all-feature shader Clippy, and asset policy passed. [One-commit fix and tests](https://github.com/steven-seagull27/VIctory/commit/ecdfcf7391413a146268ea0bd93a1bf07156f919) ```sh git fetch https://github.com/steven-seagull27/VIctory.git codex/pr2776-preserve-prefix-singleton git cherry-pick ecdfcf7391413a146268ea0bd93a1bf07156f919 cargo test -p victory-shader --lib float_prefix_singletons_keep_their_bits -- --nocapture ``` AI-assisted with Codex. Synthetic shaders on native Windows.
Author
Owner

@⁠JAEdotUK on GitHub · 2026-11-26 11:29 UTC · original

Thanks @⁠fuzeofficlal, @⁠steven-seagull27 and @⁠oni-swr. The float min/max prefix changed a lone active lane's value (a NaN became infinity and a subnormal flushed to zero), so I've pulled float out. Pushed 46ec91e: MinF/MaxF prefixes are rejected again with the original error. The integer, signed and bitwise prefixes are unchanged.

Float min/max will come in a follow-up. It needs to keep a lone lane's bits, add NaN/subnormal coverage, and be coordinated with #470, which covers the same ground.

victory-shader --lib 303 passed, clippy -D warnings clean, policy clean. On my RX 9070 XT the prefix test ran 1,792 lane comparisons (896 each at Wave32 and Wave64), all matching. lower.rs is now 195 bytes under the policy limit.

Code and debugging produced with Claude (Claude Sonnet 5.5).

**@⁠JAEdotUK** on GitHub · 2026-11-26 11:29 UTC · [original](https://github.com/Marvisak/VIctory/pull/2776#issuecomment-7190801947) Thanks @⁠fuzeofficlal, @⁠steven-seagull27 and @⁠oni-swr. The float min/max prefix changed a lone active lane's value (a NaN became infinity and a subnormal flushed to zero), so I've pulled float out. Pushed 46ec91e: MinF/MaxF prefixes are rejected again with the original error. The integer, signed and bitwise prefixes are unchanged. Float min/max will come in a follow-up. It needs to keep a lone lane's bits, add NaN/subnormal coverage, and be coordinated with #470, which covers the same ground. victory-shader --lib 303 passed, clippy -D warnings clean, policy clean. On my RX 9070 XT the prefix test ran 1,792 lane comparisons (896 each at Wave32 and Wave64), all matching. lower.rs is now 195 bytes under the policy limit. Code and debugging produced with Claude (Claude Sonnet 5.5).
Author
Owner

@⁠JAEdotUK on GitHub · 2026-11-26 11:50 UTC · original

Pushed 4b5aa62: reverted the shared VALU test harness change (dwords 4, RawUav(1)) to match main. valu_tests.rs only, no change to lower.rs. 1,792 lane comparisons on RX 9070 XT, all matching; tests, clippy and policy clean.

Code and debugging produced with Claude (Claude Sonnet 5.5).

**@⁠JAEdotUK** on GitHub · 2026-11-26 11:50 UTC · [original](https://github.com/Marvisak/VIctory/pull/2776#issuecomment-7191225573) Pushed 4b5aa62: reverted the shared VALU test harness change (dwords 4, RawUav(1)) to match main. valu_tests.rs only, no change to lower.rs. 1,792 lane comparisons on RX 9070 XT, all matching; tests, clippy and policy clean. Code and debugging produced with Claude (Claude Sonnet 5.5).
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 12:10 UTC · original · approved these changes

Verified 4b5aa622 locally on RTX 5090 and WARP (clean git merge-tree against main 63bcca43):

  • Declining Op::MinF | Op::MaxF resolves the singleton float NaN/subnormal issue from the earlier round, the incremental diff restores dwords: 4 and View::RawUav(1) in the shared VALU fixture (emit/valu_tests.rs:124,225) while keeping the dedicated prefix UAV, and the merged crates/victory-shader/src/emit/lower.rs is 524,093 bytes (195 bytes below the 524,288-byte policy cap).
  • Local checks: xtask policy (190 files ok), cargo clippy -p victory-shader --all-targets -- -D warnings (default and --all-features), rustfmt --edition 2024 --check, emit::lower::tests (33/33), emit::crosslane_tests (5/5 on RTX 5090 and WARP), and wave_prefix_non_sum_ops_match_scan_across_lanes (896 Wave32 lane comparisons across 14 PSOs on RTX 5090 with DXIL validation; Wave64 hardware and WARP configs skip PSO creation with E_INVALIDARG).

Non-blocking follow-up notes: the host-ballot path (emit/lower.rs:700-703,1272-1306) assumes host waves <= 64 lanes, and the Wave64 test fixture currently dispatches 32 threads (emit/valu_tests.rs:2393-2399,2516-2544) — a 64-thread upper-half-active case would cover b_hi and the first-active-lane fallback on Wave64 hardware. Approving for the stated Wave32/Wave64 scope.

**@⁠fuzeofficlal** on GitHub · 2026-11-26 12:10 UTC · [original](https://github.com/Marvisak/VIctory/pull/2776#pullrequestreview-6073903628) · **approved these changes** Verified `4b5aa622` locally on RTX 5090 and WARP (clean `git merge-tree` against `main` `63bcca43`): - Declining `Op::MinF | Op::MaxF` resolves the singleton float NaN/subnormal issue from the earlier round, the incremental diff restores `dwords: 4` and `View::RawUav(1)` in the shared VALU fixture (`emit/valu_tests.rs:124,225`) while keeping the dedicated prefix UAV, and the merged `crates/victory-shader/src/emit/lower.rs` is `524,093` bytes (`195` bytes below the 524,288-byte policy cap). - Local checks: `xtask policy` (`190 files ok`), `cargo clippy -p victory-shader --all-targets -- -D warnings` (default and `--all-features`), `rustfmt --edition 2024 --check`, `emit::lower::tests` (33/33), `emit::crosslane_tests` (5/5 on RTX 5090 and WARP), and `wave_prefix_non_sum_ops_match_scan_across_lanes` (896 Wave32 lane comparisons across 14 PSOs on RTX 5090 with DXIL validation; Wave64 hardware and WARP configs skip PSO creation with `E_INVALIDARG`). Non-blocking follow-up notes: the host-ballot path (`emit/lower.rs:700-703,1272-1306`) assumes host waves <= 64 lanes, and the Wave64 test fixture currently dispatches 32 threads (`emit/valu_tests.rs:2393-2399,2516-2544`) — a 64-thread upper-half-active case would cover `b_hi` and the first-active-lane fallback on Wave64 hardware. Approving for the stated Wave32/Wave64 scope.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
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/2776/head:github-bot/gh-2776'
git switch 'github-bot/gh-2776'

Merge

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