Shaders: whole-wave sections follow binary64 sums (WaveActiveSum of a double) #2976
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/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?
Imported from Marvisak/VIctory. Originally posted by Anzymanz on 2026-11-26T02:04:33Z.
Stacked 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
Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-26T02:26:34Z.
Review: COMMENTED
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.
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T02:26:49Z.
Review: COMMENTED
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).Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-26T02:21:33Z.
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.Imported from Marvisak/VIctory. Originally posted by Anzymanz on 2026-11-26T02:32:20Z.
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).
Imported from Marvisak/VIctory. Originally posted by zed6000 on 2026-11-26T02:33:20Z.
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.
Imported from Marvisak/VIctory. Originally posted by zed6000 on 2026-11-26T02:35:52Z.
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.Imported from Marvisak/VIctory. Originally posted by steven-seagull27 on 2026-11-26T04:05:27Z.
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 headImported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T05:36:45Z.
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
Imported from Marvisak/VIctory. Originally posted by Venom2054 on 2026-11-26T16:18:46Z.
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.
Imported from Marvisak/VIctory. Originally posted by Anzymanz on 2026-11-27T01:27:59Z.
CI. The
checkfailure is the two binary64 wave tests on the runner: it has no hardware adapter, and its inbox WARP runs 4-lane waves only. Both tests skipped every device and then hitrun_cases_on's "neither hardware nor WARP SM 6.6 device available" assertion.f923b5dlets the wave-32 helper finish without a device that can run a wave of 32, assynthetic_tests' wave-32 tests already do.run_caseskeeps its assertion. It compiles; the new CI run will confirm the rest.#2348's commits. This PR stays stacked on #2348 until that one lands. Then I'll merge
maininto this branch, so the diff is this PR's own commits only, without a force-push. Theabs/negpoint on the literal and inline-constant forms ofv_cvt_f32_f64belongs to #2348. @steven-seagull27's 5b841a2 fixes it there, and it cherry-picks cleanly onto this stack (their note on #2348). If it lands with #2348, the merge brings it here too.@Venom2054, thank you, yes to both, as follow-ups:
Thanks as well to @zed6000 for the census with #385 and #1065, and the keep-both note on the conflict, and to @steven-seagull27 for the exact-reference readback on two adapters.
Written with Claude Code.
Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-27T13:03:58Z.
The two Wave32 failures in the #3501 report have a test-harness cause on
f923b5d. WithVICTORY_WARP=1,Host::new(false)already returns WARP, but the pipeline-error skip tests the original Boolean. The first iteration can panic before reaching the second iteration's skip.Test-only commit e854af8 queries the selected device before creating the pipeline. It skips when Wave32 falls outside the reported range and still surfaces pipeline failures on eligible devices. D3D12 WaveSize spec
On app-local WARP 1.0.22, the logs show lanes 4..128 and both tests dispatch successfully. All 40 VALU tests passed, along with strict shader Clippy and the asset check. The Windows 10 inbox WARP here reports only SM 6.2, so it exits at the existing SM 6.6 check before reaching the new query.
@oni-swr could you rerun filter
a_whole_wave_binary64_sumate854af8withVICTORY_WARP=1on the same Windows 11 inbox WARP? The expected log isWave32 unavailable (lanes 4..4); skippedon both iterations. The separate masked Wave64 readback in #3501 still needs a native Wave64 result.If taking the patch, please retain Git authorship or add
Co-authored-by: andrewpozdnakov7-jpg <[email protected]>if squashed.AI-assisted with Codex. Synthetic tests only.
Imported from Marvisak/VIctory. Originally posted by Anzymanz on 2026-11-27T13:05:37Z.
@andrewpozdnakov7-jpg, thank you: asking the device for its wave sizes is the right test, not inferring it from the WARP flag. I've taken
e854af8as it is, with your authorship, as a fast-forward on this branch.@oni-swr, if you have a moment, the rerun andrewpozdnakov7-jpg describes (
a_whole_wave_binary64_sumate854af8withVICTORY_WARP=1) would confirm the skip on Windows 11's inbox WARP.Written with Claude Code.
Imported from Marvisak/VIctory. Originally posted by pablogonz12 on 2026-11-27T17:29:08Z.
I checked two affected programs offline on an RX 9070 XT with RADV. With #2348 applied to main, both stopped in whole-wave simulation (0/2 pipelines). On this PR head (
e854af8d3), one translated, validated, and created a pipeline; the other progressed to an untracked lane-mask join (1/2 pipelines). The PR-head comparison may include base differences. Not tested on NVIDIA hardware.Imported from Marvisak/VIctory. Originally posted by Anzymanz on 2026-11-27T17:33:43Z.
@pablogonz12, thank you for testing on the same card and driver family we use. It's useful to have an independent check of this.
As I read it, for the first program this PR does what it claims: the whole-wave section after the binary64 sum translates, validates and makes a pipeline where it didn't before. The second program now stops at a different limit, the untracked lane-mask join, which is outside what this change covers. So I'd keep it out of this PR and look at it as a follow-up.
For that, could you post the second program's shader hash and the exact refusal line? As you say, part of the difference may come from the base, so the base commit you used for the PR-head run would help too.
Written with Claude Code.
Imported from Marvisak/VIctory. Originally posted by kilolimaVI on 2026-11-29T14:51:28Z.
Hardware finding on AMD Radeon 780M (RDNA3, driver 32.0.13022.3006) while merging this with #1262, which also lowers
v_cvt_f32_f64. With this PR'sv_cvt_f32_f64arm in place, two of #1262's tests fail on the hardware:cvt_f32_f64_applies_e64_source_and_output_modifiers: input 0 and 1 give0x3fc00002, want0x40000002(the e64 output modifier ×2 is dropped); input 2 gives0x42487eda, want0xc0400002(the neg/abs source modifiers are not applied)f64_reads_uniform_pairs_at_odd_dwords: the 64-bit source read from a uniform pair starting at an odd dword is wrongWith #1262's arm instead (and everything else from this PR), all pass. So the conversion here likely needs the VOP3 source and output modifiers and the odd-dword pair handling before it lands on its own.
The rest of this PR works on hardware: both whole-wave binary64 sum tests and the three 64-bit conversion tests pass (the wave32 cases skip on WARP, run here). Combined tree:
kilolimaVI/VIctoryintegration/shader-11(fa02e0e), main + #3097, #2999, #3617, #3717, #1315, #3716, #2398, #385, #1262, #3401 and this, withv_cvt_f32_f64taken from #1262: victory-shader lib 361 passed / 0 failed / 3 ignored, victory-gpu (diagnostics) 246 passed, both clippy configurations and the asset policy pass.lower.rs478,379 bytes.AI-assisted (Claude).
Imported from Marvisak/VIctory. Originally posted by Anzymanz on 2026-11-29T15:15:17Z.
Thanks for testing this on the 780M, @kilolimaVI. Agreed: #1262's
v_cvt_f32_f64arm, which handles the output modifier, the neg/abs source modifiers and 64-bit uniform pairs at odd dwords, is the right one and should win over ours. Glad the rest of this PR passes on hardware.Written with Claude Code.
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.