Shaders: model 64-bit carry sums and f16 reductions in whole-wave sections #1568
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!1568
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1568"
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?
@MartinIndra02 on GitHub · 2026-11-24 19:15 UTC · original
MartinIndra02:feat/shader-whole-wave-i64-f16→main· +533 −8 · 3 files · 1 commits · openSummary
Models two remaining whole-wave reduction patterns in
crates/victory-shader/src/emit/wave.rsand lowers them incrates/victory-shader/src/emit/lower.rs:64-bit unsigned wave sums (
v_add_co_u32+v_add_co_ci_u32)v_add_co_u32keyed by the carry register SSA value(s) (v.carry) when both operands are disjointOp::AddUreductions (identity0) over the same(lo, mask)(or zero-carry identity0 + x).v_add_co_ci_u32consumes that exact carry SSA value and combines the matching disjoint lane sets over(hi, mask), recordsSym::Red64Hi { lo, hi, mask, lanes }, which resolves toShape::Active64Hi(lo, hi, mask)when all lanes are combined.Shape::Active64Hitodx.op.waveActiveOp.i64(opcode 119, unsigned sum) withflags::WAVE_OPS | flags::INT64and returns the high 32 bits (trunc(sum >> 32)). The low 32 bits already resolve toShape::Active(Op::AddU, lo, mask, 0).16-bit floating-point wave reductions (
v_add_f16,v_min_f16,v_max_f16)Op::AddF16,Op::MinF16,Op::MaxF16with IEEE binary16 identities (±0.0,+Inf,-Inf) and rejects non-zerov.opsel(high-half ops).dx.op.legacyF16ToF32(opcode 131) →dx.op.waveActiveOp.f32/dx.op.wavePrefixOp.f32→dx.op.legacyF32ToF16(opcode 130).Verification
cargo test -p victory-shader --lib: 123/123 passed (including new testswhole_wave_u64_sum_carries_across_lanes,whole_wave_f16_sum_matches_rdna2,f16_op_identities_match_ieee_binary16, andActive64Hicoverage inprefixes_are_recognised).cargo clippy --workspace -- -D warnings: clean (0 warnings).cargo clippy --workspace --features diagnostics -- -D warnings: clean (0 warnings).cargo clippy -p victory-shader --all-targets -- -D warnings: clean (0 warnings).cargo xtask policy: 154 files ok.main(ffe310e): eliminates all 64-bit carry-sum andf16whole-wave refusals (emit: a whole-wave section step the simulation does not follow:51 → 46,+5compute shaders emitted).#1198+#308: takes the remaining19whole-wave refusals (17ray-tracing compute shaders using 64-bit wave sums and2compute shaders usingf16wave sums) to0(19 → 0).AI-assisted contribution (Antigravity); all code, tests, and hardware verification run and reviewed locally. Strictly adheres to
docs/asset-policy.md.@geiyiliyabumo on GitHub · 2026-11-24 19:36 UTC · original
Verified commit
dde4577on Windows 11 / AMD Radeon RX 9060 XT (RDNA4,gfx1200, SM 6.6) + WARP:cargo test -p victory-shader --lib: 123 passed, 0 failed, 1 ignored (including the new whole-wave 64-bit carry sum and f16 reduction GPU tests).AI-assisted; synthetic tests only, no game files.
@pablogonz12 on GitHub · 2026-11-24 23:32 UTC · original
Linux/AMD test report on the current main. Your branch no longer merges cleanly:
git merge feat/shader-whole-wave-i64-f16onto70564ae0conflicts incrates/victory-shader/src/emit/wave.rs(5 hunks:identity,counts, theSymenum, thev_add_f16/v_add_co_u32arms, andsingle()). I resolved them by keeping both sides and measured what came out.Setup: CachyOS, Ryzen 9 9900X, AMD RX 9070 XT (RADV GFX1201, Mesa 26.3.1), Rust 1.98.1,
cargo xwin(x86_64-pc-windows-msvc). Corpus: the 768 world/mesh programs I keep offline, translate → dxil-spirv master →spirv-val→ real pipeline on RADV.70564ae0Per stage on
main: compute 440 ok / 14 translate, mesh 82, pixel 138 ok / 1 translate / 11 val, vertex 77. With this branch the only change is compute: 415 ok / 39 translate. All 25 extra refusals area whole-wave section step the simulation does not follow, a class main translates today; the other refusal classes (a select on an untracked mask8, lane-mask ones, descriptors) are identical to main.I can't compare that with your
ffe310enumbers without measuring there, and since I merged by hand it may well be my resolution: the("v_add_co_u32", Some(a))arm is tried before main's generic reduce arm, so lanes it cannot track become unknown instead of staying the plain reduction main lowers. A rebase and a re-run would settle it — I can repeat this measurement on the rebased branch, and on the 768 set any gain or loss is visible per stage.Not tested: a game run, and native Windows (RTX 3080) where your own tests ran.
AI-assisted (Claude).
@Marvisak on GitHub · 2026-11-25 01:30 UTC · original
Automated triage for the maintainers.
Needs rebase. This pull request conflicts with
main(conflicting:crates/victory-shader/src/emit/valu_tests.rs,crates/victory-shader/src/emit/wave.rs). It will be reviewed once it is rebased onto the currentmain.Generated by Claude Code
@loftymocha on GitHub · 2026-11-25 03:34 UTC · original
I tested the
f16whole-wave sum at this PR's head,dde4577abe4e12a5f6d8e818e8196e2048577bad, with a synthetic shader on an RTX 5070 (Windows 11, driver 32.0.16.1742). Inside a lane branch, the card's result equals one f32 sum converted to f16 once. The compiled pattern rounds after everyv_add_f16, so the last bit can differ.s0)v_add_f16(computed in software)0x51350x51340x5135/0x51350x4b310x4b300x4b31/0x4b31Question: does this PR intend to keep the intermediate f16 rounding for this pattern, so that the result matches the compiled
v_add_f16tree bit for bit? Or is one rounded sum acceptable here?whole_wave_f16_sum_matches_rdna2sums four equal values (4 × 1.5 and 4 × −1.0), which are exact, so it can't tell the two apart.The test
A wave32 compute program with 32 threads. Thread
tholds the f160x3c00 + 37·t(1.0 att = 0up to0x407batt = 31). Insideif (t < s0), the threads compute the wave sum with the compiler's idiom and store it:The reference follows that tree: lanes
2kand2k+1, then pairs of pairs, and so on. Each addition rounds to nearest, ties to even. It is computed in software, not measured on a console.0x4d15(20.328125) and0x4d54(21.3125). Their sum, 41.640625, lies exactly halfway between0x5134and0x5135, and ties to even gives0x5134. The exact sum of the 28 terms is 41.658203, which rounds to0x5135in either direction. The card returned0x5135.0x4b30(14.375). The exact sum is 14.384766, which gives0x4b31in either direction. The card returned0x4b31.For these inputs, the f32 sum is exact whatever the order of addition. In both cases the card matches one rounded sum and not the per-addition tree.
A separate observation: the final conversion (32 active lanes)
This case says nothing about intermediate rounding: the reference and one sum rounded to nearest agree. The reference's last addition,
0x4d15 + 0x4f76= 50.171875, is halfway between0x5245and0x5246, and ties to even gives0x5246. The exact sum, 50.185547, also rounds to0x5246. The card returned0x5245, which matches the one sum converted toward zero.0x52450x52460x5246/0x5245A wider run of the same program (31, 17, 16, 10 and 1 active lanes) had one more input where the two directions differ: at 16 lanes the card gave
0x4d15(toward zero), against0x4d16to nearest. That's two inputs on one driver. I didn't isolate which instruction rounds this way.Reproduce
Apply the patch below on
dde4577. It only adds tests tocrates/victory-shader/src/emit/valu_tests.rs. Then run:The test prints one line per
s0(32, 28, 12) with the card value, the reference and the two one-sum conversions, then fails on the differences.pr1568_compare_f16_sum_inside_a_lane_branchonly reports results: it runs more branch sizes and the 64-lane case below.Patch (tests only, applies on
dde4577)64-lane form (hardware compatibility)
The same sum compiled for 64-lane waves (wave64, 64 threads, with
v_readlane_b32 s7, v1, 32and one morev_add_f16for the two halves) translates atdde4577(2,636 bytes of DXIL). On the RTX 5070, creating its compute pipeline fails withThe parameter is incorrect., as the test harness reports it. The HRESULT itself wasn't printed.Hypothesis, not checked: the shader declares
WaveSize(64), which this card doesn't offer. I haven't run it on a card with 64-lane waves, so there's no numerical result for this form.All inputs are synthetic: hand-encoded GFX10 words and software-computed reference values, with no game data.
AI-assisted: the tests and this write-up were prepared with Claude Code, and run and reviewed locally on the hardware described.
View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.