Shaders: lower float wave prefix sums via lane reads #1407
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1408"
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?
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-24T17:47:51Z.
Fixes #1172.
Summary
Op::AddFwave prefix sums (inclusiveandexclusive) viawaveActiveBallot+ pointer-jumpingwaveReadLaneAt(Lower::float_prefix_sum) instead ofdx.op.wavePrefixOp.f32, keepingOp::AddUonwavePrefixOp.i32.wavePrefixOp.f32corrupts lanes whose own input term isNaN,±inf, or large enough (2^60) to round away earlier terms:id, remaining active lanes start from their active predecessor).Verification
NaN/+infcorruption on live AMD Radeon(TM) Graphics in both Wave32 and Wave64, then verifiedwave_prefix_tests(Wave32 plain + narrowedEXEC+ divergents_cbranch_execz, native Wave64 64-lane compute, and 4×4 pixel shader rasterization):dxil.dllvalidation + container hash check: passedcargo clippy --workspace --all-featuresandcargo xtask policy: passed.Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-24T17:57:05Z.
Review: APPROVED
Tested head
e7ef4e3(fast-forward onmainffe310e) on Windows 11 x64 (Rust 1.98.1 MSVC) with NVIDIA GeForce RTX 5090 (Blackwell) and WARP:cargo test -p victory-shader wave_prefix_tests: 5 passed, 0 failed (wave_prefix_sum_u32_reads_back,wave_prefix_sum_f32_pixel_quad_all_backends,wave_prefix_sum_f32_exclusive_wave32,wave_prefix_sum_f32_inclusive_wave32,wave_prefix_sum_f32_wave64)cargo test -p victory-shader valu_tests: 13 passed, 0 failedcargo clippy -p victory-shader --all-targets: 0 warningscargo xtask policy: ok (156 files ok)Solid float wave prefix sum lowering via lane reads, verified end-to-end on Blackwell hardware and WARP. Approving.
AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by matheusfermiano-source on 2026-11-24T17:52:20Z.
Tested on Linux under Proton, as a second AMD driver. In short: RADV does not show the #1172 defect, so a run there cannot confirm the fix. It does show the new lowering is exact on an RDNA2 GPU in Wave32, native Wave64 and the pixel-shader case, and on NVIDIA.
Setup
cae2e003) and DXVK 3.1.1 DXGI. One GPU at a time (VK_LOADER_DRIVERS_SELECT).x86_64-pc-windows-gnullvm, Rust 1.98.1.dxil.dllfrom DXC 1.9.2609: every module valid.Results (
victory-shadertests,--test-threads=1)e7ef4e3,wave_prefixtestslower.rsfrommain(oldwavePrefixOp.f32)mainffe310e+ @rouges78'swave_prefix_tests.rs+ 2^60 and +infinity in lane 11What this means:
wavePrefixOp.f32is already exact, in Wave32 and in Wave64. So the wrong lanes in #1172 come from AMD's Windows driver (its shader compiler), not from the RDNA2 hardware. A Linux/Proton run of these tests passes with or without the fix; the AMD Windows reproduction in the PR body is the run that shows it.A note for anyone running these tests under Proton: DXVK's DXGI has no WARP adapter, so the "D3D12 WARP" rows are the same hardware GPU again (they report its wave range).
Synthetic tests only, no game files. AI-assisted (Claude Code, Opus 5.5); every run above was on this machine.
Imported from Marvisak/VIctory. Originally posted by geiyiliyabumo on 2026-11-24T17:59:38Z.
Independent verification of \
e7ef4e3\ on Windows 11 / AMD Radeon RX 9060 XT (RDNA4, \gfx1200, native wave32 + wave64) / Rust 1.98.1 MSVC:AI-assisted; synthetic tests only, no game files.
Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T19:24:57Z.
Review: APPROVED
Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (
ffe310e),cargo test -p victory-shader --locked→ 96. GPU/valu execution tests are Windows-gated and were not run here.Float wave prefix sums lower through lane reads: ballot the active lanes, find the previous set lane with
unaryBitsleading-zero counts per ballot word (wave32/64/128 all handled), then Hillis-Steeleread_lanerounds. The 988-linewave_prefix_tests.rspins f32 results against a CPU reference model across wave32/wave64, inclusive/exclusive, pixel quad and every backend — exactly the right harness for a float scan (addition is not associative, so the reference semantics matter). Windows-gated, not run here; macOS 96 green.One thing to confirm on hardware: the CPU model's summation order vs. the shuffle tree's — the tests should catch any mismatch, but please make sure CI actually runs them (WARP + hardware).
Imported from Marvisak/VIctory. Originally posted by sinan-cmyk on 2026-11-24T20:44:05Z.
Offline measurement on a retail dump, and the shader tests on Ada
Result: no count change against
main.Offline. I merged head
a69e324ontomainffe310e(clean merge) and ranvictory translate --validate --listonshaders.rpf(1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result withmainprogram by program (25,889 programs). Validated: 21,724 onmain, 21,724 with this PR.No program changes its failure reason either. That is the expected result for a fix whose instructions sit behind the earlier failures on
main. The count shows that the change rejects nothing. It does not show whether the output is right.Tests: with the same merge,
cargo test --locked -p victory-shader --libpassed 125, failed 0. The bitcode benchmark is ignored, as onmain, where 120 pass. The run was on an RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter, withVICTORY_WARPunset.No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
Imported from Marvisak/VIctory. Originally posted by Calvix2k on 2026-11-24T21:23:58Z.
Hardware run on head 69e324, Radeon RX 7800 XT (RDNA3, driver 32.0.32029.2010), Windows 10 x64, Agility SDK 1.616 locally for SM 6.6:
WARP here tops out at SM 6.2 even with the Agility runtime, so the WARP half is skipped; the pixel test still requires it, which turns an unavailable backend into a failure. The compute tests already skip gracefully after 69e324; the PS-quad one could do the same (require at least one backend, or only WARP when it is present), otherwise Windows 10 hosts always report this test red although the AMD path is correct.
Happy to re-run after the change.
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T03:26:50Z.
Automated triage for the maintainers.
Verdict: merge candidate (unchanged). Thanks for the rebase. At
3a4ee54(on63bcca43),Lower::float_prefix_sumhas moved tocrates/victory-shader/src/emit/lower/wave_prefix.rs. It is the same ballot plusreadLanepointer chain I reviewed before.wave_prefix_tests.rsnow usesHost::from_device(device), which matchesemit/host.rsonmain.emit/lower.rsstays under the 512 KiBMAX_FILE_SIZEinxtask/src/policy.rs. Integer prefix sums still go throughwavePrefixOp.i32.One small nit:
wave_prefix.rshas a stray blank line before the closing}of theimpl.rustfmtwould remove it.CI: passing (
check). Merges cleanly.Generated by Claude Code
upstream-sync referenced this pull request2026-11-25 04:06:52 +00:00
upstream-sync referenced this pull request2026-11-25 05:06:07 +00:00
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T04:37:53Z.
Rebased onto
940d32f(8254052a) and updatedwave_prefix_sum_f32_pixel_quad_all_backendsto skip WARP when no SM 6.6 WARP adapter is available (requiringran > 0instead ofassert!(warp_ran)), matching the compute tests so Windows 10 hosts with SM 6.6 hardware pass cleanly. Thanks @Calvix2k for the Windows 10 run!Imported from Marvisak/VIctory. Originally posted by nathanbzrr on 2026-11-25T06:38:45Z.
Retested the rebased head
8254052a(onmain940d32f) on AMD Radeon RX 7600 (RDNA3) + Windows 11 D3D12 SM 6.6 WARP:Environment
10.0.26340x64,rustc 1.98.1(x86_64-pc-windows-msvc)32.0.32029.2010,wave=32..=64) + D3D12 WARP (wave=4..=4)dxil.dll 1.8.2502.11Results on
8254052acargo test -p victory-shader --locked wave_prefix_tests -- --nocapture: 5 passed, 0 failedok: AMD Radeon RX 7600 [Wave32, inclusive=false, wave=32..=64]ok: AMD Radeon RX 7600 [Wave32, inclusive=true, wave=32..=64]ok: AMD Radeon RX 7600 [Wave64, inclusive=false, wave=32..=64]ok: AMD Radeon RX 7600 [Wave64, inclusive=true, wave=32..=64]ok: AMD Radeon RX 7600 [PS 4x4 target, wave=32..=64]ok: D3D12 WARP [PS 4x4 target, wave=4..=4](compute Wave32/64 skipped on WARPwave range 4..=4)cargo test -p victory-shader --locked: 252 passed, 0 failed, 3 ignoredcargo clippy -p victory-shader --all-targets --locked -- -D warnings: 0 warningscargo xtask policy:asset policy: 183 files okAI-assisted review/testing; all builds and GPU runs executed locally on my own machine. No game files used.
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T02:52:24Z.
Rebased onto
main(63bcca43) in3a4ee54c, updatedHost::from_device(device)inwave_prefix_tests.rs(fixing silent test-compilation breakage on currentmain), and movedfloat_prefix_sumintocrates/victory-shader/src/emit/lower/wave_prefix.rssoemit/lower.rsstays well under the 512 KiB policy limit (~520.7 KiB). Verifiedwave_prefix_tests+emit::lower::tests(38/38),clippy --all-targets, andxtask policy.Imported from Marvisak/VIctory. Originally posted by JAEdotUK on 2026-11-26T13:10:06Z.
Hardware test report: head
3a4ee54(RDNA4)Environment: AMD Radeon RX 9070 XT (RDNA4), driver 32.0.32015.7029, Windows 11 (10.0.26200.9974), rustc 1.98.1. WARP not forced; the test output names the adapter ("AMD Radeon RX 9070 XT", wave=32..=64).
With the PR: cargo test -p victory-shader --lib --locked wave_prefix -- --nocapture -> 5 passed, 0 failed. Wave32 inclusive and exclusive, native Wave64 inclusive and exclusive, and the pixel-shader 4x4 case all ran on the RX 9070 XT and matched. The compute cases were skipped on WARP (wave range 4..=4), as the tests intend; the pixel-shader case also ran on WARP and passed.
Control: with lower.rs taken from the PR's parent commit (rebased onto main
63bcca4) and the PR's tests kept, 4 failed and 1 passed (the u32 test). Each failing test stops at its first wrong lane:Not run: Clippy, xtask policy, any game files. Synthetic tests only.
AI use: this report was prepared with Claude (Claude Sonnet 5.5); the test run was done by me on my own machine.
Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-26T13:16:30Z.
The compute tests do run on app-local D3D12 WARP 1.0.22 (wave range 4–128). I ran the exact same
wave_prefix_tests.rsand module declaration on current upstream63bcca4, then on the exact head3a4ee54, with Agility 1.620.2, SDK DXIL validator 1.9.2609.5 andVICTORY_WARP=1. Both loaded app-local DLLs were verified.exact_quarters-4.5vs-1.5-18vs2-4.5vs-1.5The first float failure occurs in the plain input case, before the tests reach the narrowed-EXEC cases. These inputs are exact quarters, so addition grouping does not account for the difference. The lane-4 boundary is consistent with the dynamic lane-read issue seen on this WARP build in #2949. That is a hypothesis for this PR until tested in isolation. This software result sits alongside the RX 9070 XT result above, where the PR passed and the stock lowering failed.
To reproduce, place the WARP 1.0.22 x64
d3d10warp.dllbeside the test executable, use SM 6.6-capable Agility, setVICTORY_WARP=1, and runemit::wave_prefix_tests --nocapture --test-threads=1.AI-assisted with Codex.
Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-26T13:23:10Z.
I tested two follow-ups on the same WARP 1.0.22 setup.
masked_two60case still failed. For example, exclusive lane 9 read-2.25instead of-0.25in both widths.wavePrefixOp.f32for compute on the software adapter made all five tests pass, including the branched cases. The hardware path still selects your prefix scan. The pixel-quad test still uses that path and passed on WARP. I also reran both permutation tests and all 33 lowerer tests. Strict shader Clippy and policy passed.Patch
ed634dfis on a branch combining this PR's3a4ee54and #2997'sa4484f5. It uses #2997's software-adapter selection and separate cache variant. The test fixture chooses lowering per adapter, so it will exercise the hardware scan and software prefix in the same suite when both are available. This follow-up was tested on WARP. The RX 9070 XT results above are for your original hardware path.If you take the patch, please retain its Git author on cherry-pick or rebase, or add
Co-authored-by: andrewpozdnakov7-jpg <[email protected]>if folding it into a different commit.AI-assisted with Codex.
Imported from Marvisak/VIctory. Originally posted by ColorMeBoom on 2026-11-26T19:12:13Z.
RDNA1 hardware verification — RX 5700 XT (Navi 10), driver 32.0.21045.29003, Windows 11 26200. Synthetic tests only, no game data.
3a4ee54:wave_prefix_tests5/5 pass on the RX 5700 XT (Wave32, native Wave64, PS 4×4); WARP passes PS and skips Wave32/64 (wave range 4..=4).lower.rsfrom main63bcca4, PR tests kept: 4 of 5 fail on the RX 5700 XT. Wave32 exclusive[nan_lanes_9_20]lane 9 = NaN (want −3.75); Wave32 inclusive[pos_inf_lane_11]lane 11 = NaN (want +inf); Wave64 exclusive same as Wave32; PS exclusive[nan_lane_0]lane 0 = NaN (want 0). The u32 test passes.#1172 reproduces on RDNA1 on main, and this PR fixes it there.
AI use: Claude Code (Claude Opus 5.5).
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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.