Shaders: lower v_dot2_f32_f16 and v_dot2c_f32_f16 #465
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!465
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-465"
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?
@Baconzido on GitHub · 2026-11-24 03:45 UTC · original
Baconzido:shaders/v-dot2-f32-f16→main· +324 −0 · 3 files · 4 commits · openTwo VALU instructions the translator refused (
Unsupported { what: "v_dot2_f32_f16" }), so any shader using one dropped its draws or dispatches:v_dot2_f32_f16(VOP3P):S0.f16[0] * S1.f16[0] + S0.f16[1] * S1.f16[1] + S2.f32, withop_sel/op_sel_hichoosing each source's half per product,neg_lo/neg_hinegating them (neg_lobit 2 negates the f32 addend) andclampsaturating the result;v_dot2c_f32_f16(VOP2): the same sum with the destination as the addend, read likev_fmac_f32reads its accumulator.Each f16 goes through
legacyF16ToF32aspacked16does, so the halves and their products are exact in f32 (65504 * 65504 does not overflow as it would in f16). The two products and the addend are summed with one rounding, as RDNA2 does (measured on gfx1036 in this PR's comments): Boldo and Melquiond's correctly rounded sum of three, two TwoSums whose errors are added with rounding to odd, then one rounded add. Shortcut, noted in the code: f32 denormals along the way follow the shader's denormal mode. Modifiers the lowering does not model (neg_hibit 2, SDWA, VOP3-encodedv_dot2cwith abs/neg/op_sel, omod) are refused.This complements #157, which lowers the integer dot products (
v_dot2_i32_i16…v_dot8_u32_u4); there is no overlap.Tests (new, in
emit/valu_tests.rs, all failing before this change with theUnsupportedabove):v_dot2_f32_f16_sums_f16_products_in_f32: exact cases, mixed signs, 65504², infinity;v_dot2_f32_f16_applies_op_sel_and_negation_per_half: swapped halves of src0 and negation on both halves;v_dot2_f32_f16_clamps_to_zero_one;v_dot2c_f32_f16_accumulates_into_its_destination;v_dot2_f32_f16_rounds_the_exact_sum_onceandv_dot2c_f32_f16_rounds_the_exact_sum_once: sums where rounding the products' sum first gives another f32 (these fail with a two-rounding sum).Expected values come from an independent model of the ISA definition, not from the lowering.
Run on Windows 11 (26300), both backends of
run_cases: AMD Radeon RX 5700 (RDNA1, driver 26.11.2) and WARP, withdxil.dllfrom SDK 10.0.26100 validating every shader: 6/6 pass, onmainffe310e.cargo test --workspace: 348 passed, 1 failed (victory-hledisplay::sdr_and_display_deferrals, which also fails onmainhere because the run is over SSH with no desktop).cargo clippy -p victory-shader --all-targetsis clean;cargo fmtadds nothing in the changed lines;cargo xtask policy --staged: ok.AI-assisted (Claude Code wrote the lowering and tests and ran them over SSH); every run is on my machine. No game files.
@DaviTostes on GitHub · 2026-11-24 03:51 UTC · original
Verified
aa55c55on Arch Linux x86_64 (rustc 1.98.1,cargo test -p victory-shader): 56 passed, 0 failed, 0 ignored.Not covered: the dot products executed on a real GPU (no SM 6.6 device here) and title shaders (no game data).
@marquezinii on GitHub · 2026-11-24 05:15 UTC · original
Ran
1d20123merged ontomaind2a4bae(clean) on NVIDIA.valu_testsruns each case on the hardware device and on WARP.x86_64-pc-windows-msvc, debugv_dot2_f32_f16_sums_f16_products_in_f32,…_applies_op_sel_and_negation_per_half,…_clamps_to_zero_one,v_dot2c_f32_f16_accumulates_into_its_destination): ok on bothcargo test -p victory-shader --lib -- --test-threads=1: 73 passed, 0 failedcargo test --workspace -- --test-threads=1: 268 passed, 0 failed, 4 ignored@Lyrnc on GitHub · 2026-11-24 06:22 UTC · original
RDNA2 hardware measurement of the
shortcut:: the hardware rounds once.v_dot2_f32_f16andv_dot2c_f32_f16are fused, so the two-rounding sum is not what RDNA2 does.Setup. AMD Radeon iGPU of a Ryzen 7 9800X3D, gfx1036 (RDNA2), AMD driver 32.0.21042.62, Windows 11 Pro 26200. Hand-written instructions in a HIP kernel (assembled by the AMD driver's amd_comgr). RDNA2 desktop silicon, not the console's. No game data. 404 operand sets: 400 random halves in ±4 with an f32 addend chosen close to minus the dot product (so the final rounding is sensitive), plus four built cases.
v_dot2c_f32_f16takes the addend from the destination.v_dot2_f32_f16v_dot2c_f32_f16a0*b0 + a1*b1 + c(exact)(a0*b0 + a1*b1)rounded, then+ c(this PR's order)(a0*b0 + c)rounded, then+ a1*b1a0*b0 + (a1*b1 + c)roundedFor example, halves
1.0 · 1.0 + 2^-12 · 2^-12withc = -1.0gives0x33800000(2^-24) on the hardware. Summing the products first rounds1 + 2^-24to 1.0 and gives 0.The products of two halves are exact in f32, as you note, so the hardware result is those three exact terms rounded once. Matching it needs the sum formed without an intermediate rounding before the final one, for example an error-free TwoSum on the f32 terms. A plain f64 sum is not always enough when the terms' exponents are far apart.
AI use: Claude Code (Claude Opus 5.5) wrote the probes, ran them on the GPU above and drafted this comment; the numbers come from the hardware run.
@slint6614-dev on GitHub · 2026-11-24 10:16 UTC · original
AMD hardware check, Windows 11, Adrenalin driver: RX 9070 (RDNA4) and Ryzen 9600X iGPU (RDNA2, gfx1036), each picked as the hardware device of
run_cases(local adapter-selection patch, not part of this PR);cargo test -p victory-shader --release valu_testsat the PR head. Negative control: the PR's non-test files reverted to its merge base, its new tests kept.v_dot2*tests pass on both AMD GPUs.@slint6614-dev on GitHub · 2026-11-24 10:42 UTC · original
Corpus run note: merged locally with current main (
c7a5f49), this PR no longer compiles:packed_srcgained a fourth argument on main, so this PR needs a rebase. At its own head it builds, and its GPU tests pass on AMD (see my earlier comment).@MichaelSmithAI on GitHub · 2026-11-24 10:46 UTC · original
Following up on the gfx1036 single-rounding measurement: on an RTX 4090 under Wine/vkd3d-proton, DXIL
Dot2AddHalfreturned0x00000000for the cancellation example above. It also returned0x4b800000for packed operandsa=b=0x00013c00, addend0x4b800000; rounding the exact sum once gives0x4b800001. Both results repeated on vkd3d-proton 3.1 and 3.2.We compared 1,026 deliberately rounding-sensitive finite inputs against an exact rational reference. With DXC denormal preservation enabled, the direct intrinsic matched 142. A separate compensated FP32 test shader matched all 1,026 on both backends. Without explicit denormal preservation, that same compensated shader matched 770; all 256 misses were subnormal results after cancellation.
These counts describe this constructed test set. The compensated shader is an experimental reference. Guest denormal mode, NaNs, infinities, and rendering cost remain open before adopting a lowering. No title shaders were used.
@Baconzido on GitHub · 2026-11-24 12:41 UTC · original
Thanks for the measurements. Both points are addressed, and the branch is rebased on
mainffe310e.Rounding (@Lyrnc, @MichaelSmithAI).
2b0d00bsums the two products and the addend with a single rounding, using Boldo and Melquiond's correctly rounded sum of three: two TwoSums, their errors added with rounding to odd, then one rounded add. A zero tail keeps the sign of an all-negative-zero sum, and an infinite or NaN term falls back to the plain sum. Theshortcut:comment is gone. One limit is written down instead: f32 denormals along the way follow the shader's denormal mode, which the translator doesn't set (the subnormal misses @MichaelSmithAI saw).New tests,
v_dot2_f32_f16_rounds_the_exact_sum_onceandv_dot2c_f32_f16_rounds_the_exact_sum_once:(1, 2^-12) . (1, 2^-12) - 1→0x33800000, the gfx1036 result above;(1, 2^-14) . (1, 2^-14) + 2^24→0x4b800001, the tie case (a normal-half variant of0x00013c00), which needs the round-to-odd step;(-0, -0) . (1, 1) - 0→-0.Rebase (@slint6614-dev).
packed_srcnow takesfloat = true, so inline constants read as halves, as inpacked16.Tested on Windows 11, AMD Radeon RX 5700 (RDNA1, driver 26.11.2) and WARP,
dxil.dllfrom SDK 10.0.26100, Rust 1.98.1:e1da143'slower.rs)0x00000000, want0x33800000cargo test -p victory-shader --lib dot2cargo test -p victory-shadercargo test --workspace --no-fail-fastvictory-hledisplay::sdr_and_display_deferrals, which opens a window; it failed the same way over SSH onmaind2a4baecargo clippy -p victory-shader --all-targetsI also checked the algorithm against an exact rational reference with subnormals kept: 40,000 random cases, 40% of them cancellations, all match. No game data used.
AI use: Claude Code (Claude Opus 5.5) wrote the change, the tests and this comment; I ran the tests on the hardware above.
@Lyrnc on GitHub · 2026-11-24 15:23 UTC · original
Re-checked
2b0d00bagainst the hardware, using the same encodings on both sides:v_dot2_f32_f16(VOP3P, defaultop_sel_hi) andv_dot2c_f32_f16(VOP2) on 554 inputs:0x33800000, the0x4b800001tie, and-0, which the hardware gives exactly;c ≈ -(a·b);2^24).build_valu_cs, on the RTX 5080 (610.88) and on the same Radeon iGPU (#94'sVICTORY_ADAPTER).v_dot2_f32_f16v_dot2c_f32_f16The single rounding matches the hardware on every non-NaN result. That includes the cancellations, which an earlier head got wrong. The only differences are which NaN comes back. This run used the shader's default denormal mode, so it doesn't speak to the denormal limit you wrote down. No game data.
AI use: Claude Code (Claude Opus 5.5) wrote the probe and the comparison and ran them; the numbers are from those runs.
@Baconzido on GitHub · 2026-11-24 22:16 UTC · original · edited 2026-11-24 23:29 UTC
Rebased on
main70564ae. The conflicts were only in placement: main's newnarrow16and the upscaler dot-product tests landed where this PR adds its helpers and tests, so both sides are kept. Againstmainthe diff is additions only. The one other change is the wording of the denormal limit, which now follows main's convention: f32 denormals inside the sum follow the host's mode, not the console's, which reads them as zero (ftz). No behavior change.Re-run on Windows 11, AMD Radeon RX 5700 (RDNA1, driver 26.11.2) and WARP,
dxil.dllfrom SDK 10.0.26100, Rust 1.98.1, headbdced0f:cargo test -p victory-shader --lib dot2cargo test -p victory-shadercargo test --workspace --no-fail-fastcargo clippy -p victory-shader --all-targetsNeither failure comes from this branch:
victory-hledisplay::sdr_and_display_deferralsopens a window and fails over SSH, as before.fspx_programs_run_with_the_hardwares_dot_productsfails the same way on plainmain70564ae, on the RX 5700 device only: the first case ([cc164000, 1c0e0501]) gives0x80007FF5, want0x7FFFFBF5. The RX 5700 is RDNA1, so this is likely how its driver handlesdot4AddPacked, not the lowering.@Marvisak on GitHub · 2026-11-25 00:27 UTC · original · edited 2026-11-26 01:22 UTC
Automated triage for the maintainers.
Merge candidate. Rebased cleanly onto current
main; the only new change is moving the lowering and itstwo_sum/sum3_rounded_oncehelpers intocrates/victory-shader/src/emit/lower/dot2.rs(aslower/bvh.rsdoes), with a one-line arm left invalu_op, to stay under the policy's file-size limit. The lowering itself matches the version reviewed before: single rounding of the exact three-term sum, backed by the gfx1036 hardware measurements in this thread, with unmodelled modifiers refused. The new test helpers (vop2,vop3p_mods) don't clash with anything inmain'svalu_tests.rs, and the branch merges cleanly.CI: passing (
check).Generated by Claude Code
@Baconzido on GitHub · 2026-11-25 22:31 UTC · original
Rebased on
mainf3578e3. The conflicts were only in placement: main's newfma_f16andv_mul_legacy_f32_treats_denormals_as_zerolanded where this PR adds its helpers and tests, so both sides are kept.One new commit,
693468a. With this PR,lower.rswent past the policy's 512 KiB file limit: 526,928 bytes, andrepository_passes_policyfailed. The commit moves the dot2 lowering and itstwo_sum/sum3_rounded_oncehelpers toemit/lower/dot2.rs, aslower/bvh.rsdoes.valu_opkeeps a one-line arm, andlower.rsis now 94 bytes overmain. No behavior change.Re-run on Windows 11, AMD Radeon RX 5700 (RDNA1, driver 26.11.2) and WARP,
dxil.dllfrom SDK 10.0.26100, Rust 1.98.1, head693468a:cargo test -p victory-shader --lib dot2cargo test -p victory-shadercargo test -p xtask --bin xtask policycargo test --workspace --no-fail-fastcargo clippy -p victory-shader --all-targetsrustfmt --checkonlower/dot2.rsThe one failure,
victory-hlemodules::lifecycle::tests::showing_a_title_window_shows_its_stand_in, opens a window and fails the same way over SSH on plainmainf3578e3. With #1790 merged,fspx_programs_run_with_the_hardwares_dot_productsnow passes on the RX 5700.No game data used.
AI use: Claude Code (Claude Opus 5.5) did the rebase and the move and wrote this comment; I ran the tests on the hardware above.
@towiice on GitHub · 2026-11-24 03:50 UTC · original · reviewed
Tested:
stable-x86_64-pc-windows-gnullvm(llvm-mingw 23.1.6).cargo +stable-x86_64-pc-windows-gnullvm test -p victory-shaderv_dot2_f32_f16_sums_f16_products_in_f32(exact f32 summation without f16 overflow)v_dot2_f32_f16_applies_op_sel_and_negation_per_half(half-swapping & per-half negation)v_dot2_f32_f16_clamps_to_zero_onev_dot2c_f32_f16_accumulates_into_its_destinationAll new VALU test cases pass cleanly without regressions.
@mercuryVM on GitHub · 2026-11-24 06:33 UTC · original · approved these changes
Tested 1d20123 on Windows 11, RTX 5070, MSVC:
cargo test --workspace --no-fail-fastpasses (268 passed, 0 failed), including the newvalu_testson hardware and WARP.victory translate <title exe> --validate --pipelinesgives the same counts before and after: 12 of 12 programs emitted, 12 validated, 12 pipelines. None of these programs use the ops.legacyF16ToF32(op 131) widens each half exactly, and f16 × f16 is exact in f32, so only the two adds round. The shortcut comment says so.-0.0 - x, which negates zeros correctly too. The f32 addend goes throughf(self, 2), which appliesneg_lobit 2.neg_hibit 2, SDWA, omod, and abs/neg/op_sel on the VOP3 form ofv_dot2c.v_dot2creads its accumulator from the destination's current value, the same way thev_fmac_f32path does.No issues found.
AI-assisted (Claude Code).
@catminou4 on GitHub · 2026-11-24 12:34 UTC · original · reviewed
Textually clean merge with current main (
ffe310e), but it fails to compile after merge — a semantic conflict: main'sLower::packed_srcnow takes a 4thboolargument, and this PR's call incrates/victory-shader/src/emit/lower.rs:3973still passes 3:Needs a rebase onto current main plus updating that call site with the new flag. I'll re-review once it's green.
@fuzeofficlal on GitHub · 2026-11-26 17:23 UTC · original · requested changes
Tested head
693468ad6525ba2fcfe97a6881b31bff01a41218merged ontomain(63bcca43) on Windows 11 (RTX 5090 + WARP, Rust 1.98.1 MSVC, SDKdxil.dll+dxc.exe).What passed:
crates/victory-shader/src/emit/lower.rsstays at520,657bytes (under the 512 KiB limit;523,479bytes even co-merged with#2094).cargo xtask policy,cargo clippy --locked -p victory-shader --all-targets -- -D warnings(default and--all-features), and all 6v_dot2*tests pass on RTX 5090 and WARP withdxil.dllvalidation.f16subnormal2^-48tie-breakers around±2^24/2^24 + 2, signed-zero combinations,f32::MAX,±Inf,neg_lobit 2 onsrc2, VOP3v_dot2cwithclamp, and modifier rejections) passed on both RTX 5090 and WARP.One blocking issue found:
v_dot2c_f32_f16silently miscompiles inline float constants (crates/victory-shader/src/emit/lower/dot2.rs:39): thev_dot2_f32_f16branch (dot2.rs:37) passesfloat = truetopacked_src, which decodes inline float constants240..=248viaf16_operand(so1.0=0x0000_3C00->(1.0, 0.0)). The!packed(v_dot2c_f32_f16) branch on line 39 instead callsself.src(inst, k)?, which goes throughself.operandand decodes240..=248as f32 bit patterns.v_dot2c_f32_f16 v3, 1.0, v2(src0 = 242,v2 = 0x4400_4200=(3.0, 4.0),v3 = 0.0) splits0x3F80_0000intof16 (0.0, 1.875)and returns0x40f0_0000(7.5) (whilev_dot2_f32_f16with the same operands returns3.0).Operand::Const(240..=248)on the!packedpath (matching howv_pk_fmac_f16refuses unmeasured constant operands inlower.rs) or decode them according to measured RDNA2 hardware behavior (while preservingself.src0for DPP).Minor non-blocking note:
dot2.rs:78-81emits a duplicateSaturate:dot2.rs:78-80appliesif v.clamp { r = self.unary(7, r); }and then callsself.write_f(inst, r, guard), which appliesif v.clamp { f = self.unary(7, f); }a second time (dxc -dumpbinconfirms two back-to-back@dx.op.unary.f32(i32 7, ...)calls). Removing lines 78-80 leaves a singleSaturate.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.