shader: lower non-sum wave prefix operations to DXIL #2776
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!2776
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2776"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@JAEdotUK on GitHub · 2026-11-25 20:16 UTC · original
JAEdotUK:fix/wave-prefix-ops→main· +393 −1 · 2 files · 7 commits · openImplements 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.
@oni-swr on GitHub · 2026-11-25 20:36 UTC · original
Independent verification of head
0e16a724(WARP/CPU): changes requested.victory-shader --lib268 pass, 3 fail. The same 3 fail onorigin/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 warningsis clean.panic!()as the first statement of the new(op, Some(inclusive))arm inlower.rs, andwave_prefix_non_sum_ops_lower_and_validatestill passes. I also replaced the arm with the oldErr(...), 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 thevalu_testsdo.×,π,²,±,−,≤,→became strings likeÃ-sequences), for example the/// Block × 4096 + page in the block.doc comment. Please restore them.lower.rs, andorigin/mainis 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 SDKdxil.dllon PATH, so DXIL validation ran),cargo test -p <crate> --lib --lockedandcargo clippy -p <crate> --all-targets --locked -- -D warnings, compared withorigin/main13f91cae. Nothing from the game was used.AI-assisted review (Claude Code / Claude Sonnet 5.5).
@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.
@JAEdotUK on GitHub · 2026-11-25 22:48 UTC · original
Thanks for the careful review. The updated head addresses each point:
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.
@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 inLower::shape(emit/lower.rs) with a lowering for the min/max/and/or/xor prefixes thatwave.rsalready recognizes: a ballot of the host lanes, then a scan over up to 64 lanes withwaveReadLaneAt, inclusive or exclusive. The updated head drops the earlier reformatting and garbled comments, and the newwave_prefix_non_sum_ops_match_scan_across_lanestest 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; theOp::AddHbranch is anunreachable!()in the translator; and the sharedrun_casesharness 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
@fuzeofficlal on GitHub · 2026-11-26 00:30 UTC · original · reviewed
Verified head
5fa0c3f8cleanly merged ontoorigin/main(63bcca43) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + D3D12 WARP +VICTORY_D3D12_DEBUG=1+ Windows SDK 10.0.26100.0dxil.dll).Code & Semantics Review
Op::{MinU, MaxU, MinI, MaxI, MinF, MaxF, And, Or, Xor}for both inclusive and exclusive prefixes is sound:Op::AddHonly usesShape::Half(wave.rs:631-650), inactive host lanes are avoided by clampingsafe_ktoFirstbitLo(waveActiveBallot(true)), title-inactive lanes carryident, andMinF/MaxFrunftz+self.max_minpreserving RDNA2-0.0 < +0.0and non-NaN preference.63bcca43,crates/victory-shader/src/emit/lower.rsis524,209 B— only 79 bytes undercargo xtask policy's524,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 otherlower.rsPR.Local Verification (
VICTORY_D3D12_DEBUG=1,dxil.dll)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 Blower.rsheadroom).@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.dllvalidator active):cargo test -p victory-shader --lib emit::valu_tests::wave_prefix_non_sum_ops_match_scan_across_lanes -- --nocapture: reportedok, but executed 0 GPU comparisons — all 36 PSOs were skipped withE_INVALIDARGon both RTX 5090 (Wave32-only) and inbox WARP (4-lane):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 notelower.rspassesAttr::ReadOnlyforwaveGetLaneIndex(other call sites useAttr::ReadNone), and unrolls0..64unconditionally even for Wave32 programs (0..32suffices when!wave64).Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
@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.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.
@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 read0xffffffffand expected0x9236567a.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
25f40e70on native Windows withVICTORY_REQUIRE_HW=1and 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 resultsThe 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.
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
0x9236567aand the shader returned its identity,0xffffffff.Native HLSL control. Using DXC
cs_6_6and 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. YetWaveActiveBallot(true)returned zero for both mask words in every lane across three runs. With 64 threads both mask words were0xffffffffin 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
0xffffffffand high0. 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
I compiled it twice, with
THREADS=32andTHREADS=64, then dispatched one group for each.To apply and rerun from
25f40e70on WindowsFor the WARP 1.0.22 run, I put that package’s x64
d3d10warp.dllnext to the compiled test executable, setVICTORY_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.
@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::MaxFinemit/lower.rs:1287-1333): when lane 0 is active, the guest DPP prefix never runs a floating-pointmin/maxon that singleton value—inclusive lane 0 keeps its input bits directly, and exclusive lane 1 copies them viav_mov_b32. Because the new lowering unconditionally appliesself.ftzand combines the first active element with±Infviaself.max_min(DXILFMin/FMax), a singletonqNaN(0x7fc00001) turns into±Infand a singleton subnormal (0x00000001/0x80000001) flushes to±0. Please preserve singleton float results unchanged (or continue decliningMinF/MaxFuntil singleton inputs are preserved), and add NaN/subnormal plus 64-thread Wave64 coverage.Also note two maintenance points: merged onto
63bcca43,emit/lower.rssits at524,209bytes (only79bytes below the 512 KiB policy limit, so extracting a helper submodule would help), andtry_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.rsmerged onto63bcca43=524,209bytes)cargo clippy -p victory-shader --all-targets --locked -- -D warnings(default and--all-features): cleanemit::crosslane_tests -- --test-threads=1: 5 passed, 0 failedwave_prefix_non_sum_ops_match_scan_across_lanes -- --test-threads=1: passed (1,152Wave32 hardware lane comparisons on RTX 5090; Wave64 andVICTORY_WARP=1skipped withE_INVALIDARG)@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 throughv_mov_b32. On the RTX 5080, inclusive min returned0x7f800000for0x7fc00001. ReviewThe 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
AI-assisted with Codex. Synthetic shaders on native Windows.
@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: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).
@fuzeofficlal on GitHub · 2026-11-26 12:10 UTC · original · approved these changes
Verified
4b5aa622locally on RTX 5090 and WARP (cleangit merge-treeagainstmain63bcca43):Op::MinF | Op::MaxFresolves the singleton float NaN/subnormal issue from the earlier round, the incremental diff restoresdwords: 4andView::RawUav(1)in the shared VALU fixture (emit/valu_tests.rs:124,225) while keeping the dedicated prefix UAV, and the mergedcrates/victory-shader/src/emit/lower.rsis524,093bytes (195bytes below the 524,288-byte policy cap).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), andwave_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 withE_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 coverb_hiand the first-active-lane fallback on Wave64 hardware. Approving for the stated Wave32/Wave64 scope.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.