Repository navigation
Conversation
towiice
left a comment
There was a problem hiding this comment.
Tested:
- Hardware: NVIDIA GeForce GTX 1650 SUPER (Turing TU116, 4 GB VRAM, 32-wide subgroups / wave32, driver 610.88), Windows 11 x64 (26H2 / 10.0.26300), toolchain
stable-x86_64-pc-windows-gnullvm(llvm-mingw 23.1.6). - Test command:
cargo +stable-x86_64-pc-windows-gnullvm test -p victory-shader - Result: 73 passed, 0 failed (6.95 s):
v_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_destination
All new VALU test cases pass cleanly without regressions.
|
Verified Not covered: the dot products executed on a real GPU (no SM 6.6 device here) and title shaders (no game data). |
|
Ran
|
|
RDNA2 hardware measurement of the 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.
For example, halves 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. |
mercuryVM
left a comment
There was a problem hiding this comment.
Tested 1d20123 on Windows 11, RTX 5070, MSVC: cargo test --workspace --no-fail-fast passes (268 passed, 0 failed), including the new valu_tests on hardware and WARP. victory translate <title exe> --validate --pipelines gives 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.- Per-half negation is
-0.0 - x, which negates zeros correctly too. The f32 addend goes throughf(self, 2), which appliesneg_lobit 2. - The modifiers that aren't modelled are refused rather than ignored:
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).
|
AMD hardware check, Windows 11, Adrenalin driver: RX 9070 (RDNA4) and Ryzen 9600X iGPU (RDNA2, gfx1036), each picked as the hardware device of
|
|
Corpus run note: merged locally with current main (c7a5f49), this PR no longer compiles:
|
|
Following up on the gfx1036 single-rounding measurement: on an RTX 4090 under Wine/vkd3d-proton, DXIL 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. |
catminou4
left a comment
There was a problem hiding this comment.
Textually clean merge with current main (ffe310e), but it fails to compile after merge — a semantic conflict: main's Lower::packed_src now takes a 4th bool argument, and this PR's call in crates/victory-shader/src/emit/lower.rs:3973 still passes 3:
error[E0061]: this method takes 4 arguments but 3 arguments were supplied
--> crates/victory-shader/src/emit/lower.rs:3973:34
= note: argument #4 of type `bool` is missing
Needs a rebase onto current main plus updating that call site with the new flag. I'll re-review once it's green.
1d20123 to
2b0d00b
Compare
RDNA2 rounds the exact sum of the two f16 products and the f32 addend once (measured on gfx1036 in Marvisak#465), where summing the products first rounds twice: (1, 2^-12) . (1, 2^-12) - 1 gives 2^-24 on the hardware and 0 that way. The sum is now Boldo and Melquiond's correctly rounded sum of three: two TwoSums, their errors added with rounding to odd, then one final rounded add. A zero tail keeps the sign of an all-negative-zero sum, and an infinite or NaN term gives the plain sum.
|
Thanks for the measurements. Both points are addressed, and the branch is rebased on Rounding (@Lyrnc, @MichaelSmithAI). New tests,
Rebase (@slint6614-dev). Tested on Windows 11, AMD Radeon RX 5700 (RDNA1, driver 26.11.2) and WARP,
I 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. |
Applied as the net diff of upstream PR Marvisak#465 (head 2b0d00b), 3 commits: 2b0d00b,e1da1435,4c879baf.
|
Re-checked
The 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. |
The two products of f16 halves, exact in f32, summed with the f32 addend (v_dot2c: the destination). VOP3P op_sel/op_sel_hi pick each half, neg_lo/neg_hi negate them and clamp saturates; modifiers not modelled are refused. Tests run each case on the host GPU and WARP.
RDNA2 rounds the exact sum of the two f16 products and the f32 addend once (measured on gfx1036 in Marvisak#465), where summing the products first rounds twice: (1, 2^-12) . (1, 2^-12) - 1 gives 2^-24 on the hardware and 0 that way. The sum is now Boldo and Melquiond's correctly rounded sum of three: two TwoSums, their errors added with rounding to odd, then one final rounded add. A zero tail keeps the sign of an all-negative-zero sum, and an infinite or NaN term gives the plain sum.
2b0d00b to
bdced0f
Compare
|
Rebased on Re-run on Windows 11, AMD Radeon RX 5700 (RDNA1, driver 26.11.2) and WARP,
Neither failure comes from this branch:
|
|
Automated triage for the maintainers. Merge candidate. Lowers CI: no check runs on the head commit. Generated by Claude Code |
Two 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.