Shaders: whole-wave sections follow binary64 sums (WaveActiveSum of a double) #2978
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!2978
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2978"
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?
@Anzymanz on GitHub · 2026-11-26 02:04 UTC · original
Anzymanz:wave-f64-sums→main· +522 −5 · 6 files · 5 commits · openStacked on #2348 (
v_cvt_f32_f64): its three commits come first; the last commit is this change.Problem
WaveActiveSumof adoubleexpands, on the console, into a whole-wave section that works on dword pairs:v_cndmaskputs each lane's pair (or +0.0) in two VGPRs, each DPP step moves the two dwords with twov_mov_b32,v_add_f64adds the pairs,v_permlanex16joins the rows,v_readlanereads the result (on wave64, the two halves' results, added once more), and ans_mov_b32copies each dword to the register that leaves the section. The section simulator (emit/wave.rs) follows 32-bit operations only, so both dwords are unknown, and a program that reads them is refused:a whole-wave section step the simulation does not follow is not supportedThat's what five programs in this title hit once #2348 lowers the
v_cvt_f32_f64that reads the sum (before #2348 they stop at that instruction).Change
emit/wave.rs:Sym::Red64 { lo, hi, mask, lanes, high }is one dword of the binary64 sum overlanesofmask ? (lo, hi) : +0.0.v_add_f64reads both of its sources as (low, high) pairs: register pairs, SGPR pairs, inline 0. It joins two terms of one masked sum when their lanes are disjoint, and writes both destination dwords.v_mov_b32with DPP,v_permlanex16_b32andv_readlane_b32move these symbols a dword at a time already.s_mov_b32now keeps what its source holds, where it used to be unknown. A sum over every lane isShape::Sum64.emit/lower/sum64.rs(new, keepinglower.rsunder the 512 KiB policy):Shape::Sum64becomes onewaveActiveOp.f64(sum) overmask ? double(lo, hi) : 0.0. Both dwords share it, one per block. It setsFLOAT64,INT64andWAVE_OPS.Tests
wave::tests::a_binary64_sum_is_followed_through_its_dwords: the compiler's wave32 expansion (four DPP steps,v_permlanex16,v_readlane,s_mov_b32copies) givesSum64for both read dwords and both copies.wave::tests::a_binary64_sum_counting_a_lane_twice_is_not_a_sum: the same, with a lane added to itself first, gives no shape.valu_tests::a_whole_wave_binary64_sum_reaches_the_host(GPU): the same section run end to end on the host, thenv_cvt_f32_f64of the copied pair; five values,x as f32expected. Passes on an RX 9070 XT (RADV through vkd3d-proton, GE-Proton 11-14, DXC'sdxil.dll).Measured over the title's shader pack
All 25,889 distinct containers in
shaders.rpfwent throughemit::translate_withoffline, on main63bcca4+ #2348 and then with this commit added:5dc3b25986622949, refused before)Every other program's output is byte-identical: the
s_mov_b32change gives nothing else a new shape. The new program's DXIL converts with dxil-spirv (master). The other four (6f225b641c5b0708,6871d6e4b3ac9a10,926c46bab3b86bd6,a10179ab7eda0dc3) get past the section and stop later ata lane-mask join of an untracked mask, a separate class.Windows test binary under Proton on the RX 9070 XT: 306 passed and 2 failed. The 2 failures (
hosts_that_do_not_fuse_are_named,stub_pipeline_is_created) fail on main in the same environment too.cargo clippy -p victory-shader -- -D warningsis clean,cargo xtask policyis ok, andlower.rsis 523,410 bytes.Not run: the differential tests (no console compiler here) and NVIDIA.
🤖 Generated with Claude Code
The console compiler expands a wave sum of doubles into a whole-wave section on dword pairs: v_cndmask per dword, two v_mov_b32 per DPP step, v_add_f64 on the pairs, v_permlanex16 per dword, v_readlane, and s_mov_b32 copies out. The simulator followed 32-bit steps only, so both dwords were unknown and a program reading them was refused ("a whole-wave section step the simulation does not follow"). - wave.rs: Sym::Red64 is one dword of the binary64 sum over some lanes of mask ? (lo, hi) : +0.0; v_add_f64 joins two terms of one masked sum over disjoint lanes and writes both destination dwords; s_mov_b32 keeps what its source holds; a sum over every lane is Shape::Sum64. - lower/sum64.rs: Shape::Sum64 is one waveActiveOp.f64 per block, shared by both dwords (FLOAT64, INT64, WAVE_OPS). Tests: two simulator tests (the wave32 expansion is followed through its dwords and copies; a lane counted twice is not a sum) and a GPU test running the section end to end into v_cvt_f32_f64. Co-Authored-By: Claude Opus 5.5 <[email protected]>@oni-swr on GitHub · 2026-11-26 02:21 UTC · original
Independent Windows WARP check of head
7de694fe56020fc3d32f3ef945a829485455b5b3. The control was its exact stack parent9ead47e28fddc16979529f55588e71b2ef362eec(main63bcca4+ the three #2348 commits, as stacked here).Result: the simulator and lowering part holds up. The GPU test
a_whole_wave_binary64_sum_reaches_the_hostfails on WARP, both here and in this PR's CI at this same head.Environment
cargo test -p victory-shader --locked -j 4,--test-threads=1 --nocaptureVICTORY_WARP=1,VICTORY_D3D12_WARP=1,VICTORY_DXIL= Windows SDK 10.0.26100.0x64\dxil.dll(1.8.2502.11)d3d10warp.dll/D3D12Core.dll10.0.26100.9818. Both test labels ("hardware" and "warp") resolved to Microsoft Basic Render Driver (vendor 0x1414, device 0x008c, software flag set,WaveLaneCountMin..Max = 4..4). I printed this from inside the test process.d3d10warp.dlland the SDKdxil.dllloaded, and no vendor user-mode driver.Why the GPU test fails
With the D3D12 debug layer on, WARP gives the reason:
The lowered section asks for
WaveSize(32), and this WARP only offers 4-lane waves. CI run 45739979316 at this head fails on the same test with the same message.run_casespanics whencompute_pipelinefails.synthetic_testsinstead skips a WARP pipeline with a fixed wave size ("no pipeline for a wave of 32; skipped"). So nothing in this environment checks the end-to-end binary64 result. I make no claim either way about whether the value is correct on the host.Focused (PR tests plus my synthetic cases)
9ead47e7de694fwave::tests::a_binary64_sum_is_followed_through_its_dwordswave::tests::a_binary64_sum_counting_a_lane_twice_is_not_a_sumvalu_tests::a_whole_wave_binary64_sum_reaches_the_hostdxil.dllvalidation (3 forms)a whole-wave section step the simulation does not followv_cmpxguard,s_and_saveexecbranch)My synthetic cases use the same wave32 expansion as the PR's test:
s_or_saveexec_b32 -1,v_cndmaskper dword, four DPP steps,v_permlanex16,v_add_f64,v_readlanelane 31, thens_mov_b32copies. The section is wrapped three ways: full EXEC, a straight-linev_cmpx_ne_u32guard, and av_cmp+s_and_saveexec_b32+s_cbranch_execzbranch. Inputs are dyadic, so every partial sum is exact in any order: 1 + l·2⁻³² (low dword varies), 2^l (high dword varies), mixed-sign multiples of 0.25, and negative values plus a −0.0. All three forms lower at the head and passdxil.dllvalidation. The parent refuses them all with the message this PR addresses. These cases were local only and aren't pushed.Matched suite (
victory-shaderlib, same environment)9ead47e: 301 passed, 4 failed, 3 ignored (not counting my local tests).7de694f: 303 passed, 5 failed, 3 ignored. The two extra passes are the PR's two simulator tests. The extra failure isa_whole_wave_binary64_sum_reaches_the_host.63bcca4:synthetic_tests::{a_mask_joined_with_data_at_a_uniform_loop_is_its_number, gathers_at_a_level_match_the_hardware, permutes_mask_high_address_bits_and_divergent_branches, permutes_read_the_lane_named_and_zero_from_lanes_left_out}. They come fromVICTORY_WARP=1sending the "hardware" label to WARP, so they're environmental and not from this stack or this PR.Limitations
Suggestion: skip on WARP the way
synthetic_testsdoes (or require a 32-lane adapter ina_whole_wave_binary64_sum_reaches_the_host). That would let Windows CI pass, but WARP still wouldn't check the result.@Anzymanz on GitHub · 2026-11-26 02:32 UTC · original
Thanks both, and thanks for chasing the WARP message down.
ab08acb:run_cases_wave32, which skips WARP when it refuses the pipeline, assynthetic_testsdoes. Any other failure still panics, andrun_casesbehaves as before for every other test.a_whole_wave_binary64_sum_counts_the_active_lanes_onlyruns the section over a wave of 32 with only the lanes belows2active (v_cmp_gt_u32+s_and_saveexecbefore it). Laneladds 2^l, so the sum is 2^n − 1 in any order, and the 32 − n inactive lanes' +0.0 must not count. Cases n = 1, 5, 17, 31, 32; with n = 32 the f32 result rounds, which is checked as well. Both GPU tests pass on an RX 9070 XT (RADV via vkd3d-proton). I haven't added NaN/Inf/−0.0 cases. Those don't depend on the order, but a NaN payload's propagation through the host's sum isn't something the console fixes either, so I'd rather not assert it.v_cvt_f32_f64source modifiers. That code is #2348's (the commits this PR is stacked on), so I'll point its author at your finding there instead of changing it under their PR.Shape::Sum64arm and a cache field there; the lowering is inemit/lower/sum64.rs. If something else lands first and it no longer fits, I'll move more out.AI-assisted (Claude Code).
@zed6000 on GitHub · 2026-11-26 02:33 UTC · original
Measured offline on the title's shaders (the method in #1247), head
7de694fonmain63bcca4(a clean merge), RX 7900 XTX:mainv_cvt_f32_f64programsemit: a lane-mask join of an untracked maskSo this does what you said: with #385 and #1065 on top, all five programs translate and validate. I didn't measure #2978 + #385 without #1065. On #385 alone, the 13 join programs it unblocks on
mainthen hit the validator's stage error that #1065 fixes, so the four likely need it too. The other 761 of the +766 are #385 + #1065's own (+761 together on63bcca4).Two things for the merge order:
mod sum64;/mod phi;inlower.rs, and the new tests at the same spot at the end ofvalu_tests.rs, where your binary64 test needs its closing}before #385's helpers. #1065 then merges cleanly on top.a_whole_wave_binary64_sum_reaches_the_hostfails on the built-in WARP here. The hardware leg passes, thenrun_casespanics withwarp: compute_pipeline failed: The parameter is incorrect.(Windows 11, built-ind3d10warp.dll10.0.26100.9818, which reports waves 4..4). Every other test passes: 307/1 on #2978 alone and 326/1 on the stack, and that's the only failure. The hardware runs it, so this looks like a WARP limit (perhaps 64-bit wave ops) that the test should skip, rather than a lowering bug. I haven't checked which feature WARP is missing.Offline counts and unit tests only; no program names or data.
@zed6000 on GitHub · 2026-11-26 02:35 UTC · original
Crossed with your
ab08acb. On it, the 4 binary64 tests pass on the RX 7900 XTX hardware, and the built-in WARP (10.0.26100.9818) is skipped as intended ("no pipeline for a wave of 32"). So the WARP point in my note is handled. The census numbers above don't change, sinceab08acbonly touches tests.@steven-seagull27 on GitHub · 2026-11-26 04:05 UTC · original
Both result dwords at
ab08acbmatched an exact integer reference on an RTX 5080 and app-local WARP 1.0.22. The sparse mask0x80010041(lanes 0, 6, 16, 31) gave0x40100000_00000d60for one input. Converting that result to f32 gives exactly 4.0, so a zeroed low dword would pass the existing check.I ran 36 wave32 dispatches per adapter with positive and negative inputs and nine masks, including empty, full, alternating and lane 31 alone. Each active lane contributed ±(1 + (seed + 256 × lane) × 2⁻⁵²). The inputs are multiples of 32 units of 2⁻⁵², so every intermediate sum is exactly representable. Each dispatch read back two pairs per lane. The first pair kept both sentinel words in masked-off lanes; after restoring EXEC, all 32 lanes copied out the expected scalar pair. The empty mask gave +0. All 1,152 lane rows matched on each adapter.
1.0.22.0.20261027.110.0.26100.10068I verified the loaded WARP DLL paths and validated the shader with Windows SDK
dxil.dll(1.9.2602.17). These finite, exact cases leave the existing caveats about floating-point reassociation and NaN payload selection open. Test-only cherry-pick on this head@Marvisak on GitHub · 2026-11-26 05:36 UTC · original
Automated triage for the maintainers.
Needs work. The core of the change reads well:
Sym::Red64inemit/wave.rsfollows a binary64 wave sum through the console compiler's dword-pair expansion, andemit/lower/sum64.rslowersShape::Sum64to onewaveActiveOp.f64(sum) overmask ? double(lo, hi) : 0.0, cached per block so both dwords share it. TheFLOAT64flag (bit 2) and the0x1feature bit match DXIL's double-precision flags, and the ordering difference is marked as a// shortcut:. Independent runs in the thread check both result dwords on an RTX 5080 and app-local WARP.What is in the way:
ab08acb. Please get thecheckjob green, or say what fails if it is outside this PR.v_cvt_f32_f64). Those should be reviewed and land in #2348 first, then this PR rebased to its own commit. One point there: in thev_cvt_f32_f64arm oflower.rsthe literal and inline-constant paths skipsrc64's modifier check, soabs/negon those forms are silently ignored; they should be applied or refused.mod sum64;next tomod phi;, and tests at the end ofvalu_tests.rs); whichever lands second will need a rebase.CI: failing.
Generated by Claude Code
@kotekompotek on GitHub · 2026-11-26 02:26 UTC · original · reviewed
Verified: correct LLVM bitcode encodings (FpTrunc=7, TYPE_DOUBLE record 4, FeatureFlag doubles=0x1), inline-constant table matches GCN's f64 set including 1/(2pi), literal sources read as high-word-only per RDNA rules, and only MODE's default round-to-nearest is accepted (directed modes refused rather than mis-rounded). Sum64 is right too: masked lanes contribute +0.0 and one waveActiveOp.f64 serves both dwords via the per-block cache.
@fuzeofficlal on GitHub · 2026-11-26 02:26 UTC · original · reviewed
Reviewed and tested against
main(63bcca43) on Windows 11 (RTX 5090 + WARP +dxil.dll,VICTORY_D3D12_DEBUG=1). There is a blocking test failure on WARP plus a source-modifier bug inv_cvt_f32_f64:Blocking WARP / CI failure (
emit::valu_tests::a_whole_wave_binary64_sum_reaches_the_host):dxil.dlland RTX 5090, but fails on WARP atvalu_tests.rs:209withE_INVALIDARG(0x80070057).ID3D12InfoQueuereports:ID3D12Device::CreateComputeShader: Shader wants wave lane count of 32 but maximum wave lane count for device is 4.dx.op.waveActiveOp.f64itself, so the refusal comes from whole-wave sections emittingWaveSize=32(lower.rs:608) whilevalu_tests::run_casespanics unconditionally on WARP (unlikesynthetic_tests.rs:345-349, which skipsWaveSize=32pipelines on WARP).Silent source-modifier drop in
v_cvt_f32_f64(crates/victory-shader/src/emit/lower.rs:6405-6427):Operand::Const(240..=248)andOperand::Literal(_)arms bypassself.src64(...)and do not checkv.abs,v.neg,v.sdwa, orv.dpp. A VOP3-encodedv_cvt_f32_f64_e64 v0, -1.0(inline constant withneg/abs) silently drops the modifier instead of applying or rejecting it.Two non-blocking notes:
a_whole_wave_binary64_sum_reaches_the_hostcurrently runsthreads: [1, 1, 1](1 active lane); testing multi-lane reduction with inactive lanes (+0.0) andNaN/Inf/-0.0would exerciseWaveActiveSummuch more thoroughly.63bcca43,emit/lower.rsgrows to 523,410 B (only 878 B below the 512 KiBxtask policylimit — merging alongside #2977 or #2104 will exceed524,288 B).@Venom2054 on GitHub · 2026-11-26 16:18 UTC · original
Follow-up on the rounding and guest Wave64 cases discussed above. On an RTX 5070 Ti we tested a separate implementation built on #439 (
e2d3cfd) and the FP64 conversion from #416. It recognizes the guest addition tree and preserves operand order across two physical Wave32 waves, including when one half leaves a masked loop first.5dc3b25986622949and6f225b641c5b0708both produced SDK-validated Wave32 DXIL and D3D12 compute pipelines. In a matched title capture the control dropped both targeted commands. The candidate recorded two indirect dispatch commands for each shader. The capture did not include the indirect group counts or a visible water surface.This was a separate implementation on a different base from
ab08acb. Would the synthetic masked-loop regression or the ordered lowering be useful as a follow-up here?Implementation and testing were assisted by Codex.
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.