shader: lower v_add_f64, v_mul_f64, v_fma_f64, v_min_f64 and v_max_f64 #99
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/uiliannn--VItoriaBr!99
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-99"
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?
@lcg007xd-c on GitHub · 2026-11-25 22:41 UTC · original
lcg007xd-c:shader-f64-arith→main· +140 −0 · 2 files · 1 commits · openWhat is broken
The basic f64 arithmetic decodes, but a program using it fails to translate with
v_add_f64 is not supported(or the matching name):v_add_f64v_mul_f64v_min_f64v_max_f64v_fma_f64The one exception is the whole-wave
v_add_f64sum thatwave.rsrecognizes. That case is tested invalu_tests::whole_wave_f64_sum_and_cvt_f32_f64, so the title has f64 math in it. An f64 add or multiply outside that pattern still stops the translation.Semantics
They are IEEE binary64 add, multiply, fused multiply-add, and min/max (AMD's RDNA2 ISA, §12.12). For min/max:
max_minalready does for f32 here.The change (
emit/lower.rs, invalu_op)f64_pair, which handles VGPR/SGPR pairs, 0, the f64 inline constants, the GFX10 literal-in-high-dword rule, andabs/neg. Each pair is joined with DXILMakeDouble.fadd/fmulon doubles, DXILFma(opcode 47, a double-only op), andDMax/DMin(35/36). Two zeros get the f32 rule:+0unless both are−0for max,−0unless neither is for min.SplitDoubleand written to the destination pair.DOUBLES, as the wave sum does.f64_pairas before, so the DPP adds of a wave sum still reach the wave pass.Tests
emit::lower::tests::f64_arithmetic_translates(every host): all five decode, and a program that stores the result translates. Without thelower.rschange it fails:v_add_f64 [d5640000, 00020701]: GFX10 code at 0x24: v_add_f64 is not supported.valu_tests::f64_add_mul_fma_min_max_match_ieee(Windows/GPU): both dwords of each result against Rust's f64 for six pairs: an exact sum,0.1 + 0.2rounding,−0vs+0,1e300 · 1e10→ inf, NaN with a number, and −7 vs inf.lli. I compared against Rust's f64 on 46 values, including the smallest normal, denormals (5e-324,−1e-310),f64::MAXand 30 scrambled patterns. I checked both dwords of all five operations, plusnegon a source. All match.Run here (Linux, Rust 1.98.1):
cargo test -p victory-shader --lib --locked: 188 passed, 0 failed, 2 ignored.CARGO_FEATURE_PURE=1 cargo clippy -p victory-shader --all-targets --target x86_64-pc-windows-msvc -- -D warnings: clean.Not run here: the GPU case, since I have no Windows machine. A host without double-precision shader support (
DoublePrecisionFloatShaderOps) would refuse the PSO, as it would for the wave sum.🤖 Generated with Claude Code
VOP3 0x164..=0x167 and 0x14C decoded but failed to translate ("v_add_f64 is not supported"), apart from the whole-wave v_add_f64 sum the wave pass recognizes. They are IEEE binary64 arithmetic (AMD's RDNA2 ISA) and lower in the host's doubles, with the DOUBLES flag the wave sum already uses: each operand pair (abs/neg applied by f64_pair) joined by MakeDouble, the result split back with SplitDouble. min/max are DMin/DMax (the other operand of one NaN) with -0 ordered below +0, as max_min does for f32. Output modifiers are refused. Co-Authored-By: Claude Opus 5.5 <[email protected]>@upipibi on GitHub · 2026-11-26 23:15 UTC · original · edited 2026-11-26 23:19 UTC
This is a pointer to f64 work and AMD hardware results from other VIctory repositories, since the GPU test here hasn't run on hardware yet. I put it together by reading the code. I have not run any of it.
At
3328d80,v_fma_f64already uses thetertiary.f64entry point for opcode 47 (lower.rs:7389). Belobug/VIctory-Belobug-AMD#202 found that the other name for it fails DXIL validation, so that part is fine here. Each source pair goes straight intomakeDouble(lower.rs:7383, operands fromf64_pairat:8145).That is where AMD hardware has gone wrong elsewhere:
emit/lower/double.rs. In its thread, "FIND-21" was measured on RDNA1, RDNA2 and RDNA3 on native Windows:v_add_f64/v_mul_f64give wrong words when two source pairs share a dword. A single double read from dwords 1 and 2 of one load is wrong too, because the driver readsv[2:3]as(v2, v2). NVIDIA and WARP were correct. The fix there (commit c4da80b,unfolded_pair,double.rs:43-56: a lane-index shift at:51XORed into both dwords at:54-55;fsrc64at:108) makes each source dword pass through a zero the compiler cannot fold beforemakeDouble. In that thread, the test passed on an RX 5700 XT, an RX 6950 XT, an RX 7900 XTX and a gfx1036 iGPU.src_f64. It passed on an RX 9060 XT, an RX 6950 XT, an RX 7900 XT and WARP.v_cvt_i32_f64(NaN)andv_cvt_u32_f64(NaN)giving different results across hosts (a non-zero result under Wine on an RTX 5080, zero natively on an RTX 3050 and on WARP). That is relevant to #101.I haven't checked whether
f64_add_mul_fma_min_max_match_ieeecovers sources that share a dword or sit at an odd offset. If it doesn't, someone with an AMD card would need to run the overlapping-pair and odd-dword cases from #1262 against this branch to see whether it is affected.AI-assisted (Claude Code, Claude Opus 5.5).
@lmouz823-lang on GitHub · 2026-11-27 14:15 UTC · original
I can take the Windows/NVIDIA synthetic GPU validation for this PR on an RTX 4060 Laptop (8 GiB), Windows 11, driver 610.88. I'll test head
3328d80a9de24882226103f3bcb3efd46b4843c4, runf64_arithmetic_translatesandf64_add_mul_fma_min_max_match_ieee, and check that the GPU case actually executes rather than skips. I'll report the exact revision, commands and result here. This will be NVIDIA evidence only; the AMD register-overlap concern above will remain unverified.AI-assisted with Codex.
@lmouz823-lang on GitHub · 2026-11-27 14:27 UTC · original
Completed the native Windows check on exact head
3328d80a9de24882226103f3bcb3efd46b4843c4(RTX 4060 Laptop, driver 610.88; Windows 11 build 26200; Rust 1.98.1 MSVC; SDKdxil.dll1.8.2502.11).The untouched head does not pass the GPU test here.
f64_arithmetic_translatespasses, butf64_add_mul_fma_min_max_match_ieeeexits 101 with:A local diagnostic print isolated this to
v_fma_f64, low dword; add/mul/min/max reached both hardware and WARP and passed their checks first. The missing metadata bit is0x40(EnableDoubleExtensions): DXC marks double Fma as using that extension, and its SFI0 feature bit is0x20.I tested the small local diff below: set metadata bit 6 only for
v_fma_f64, map it to SFI00x20, and tighten the NaN assertion. The original exponent-only assertion also accepts infinity; the replacement checks both result words, including a NaN payload located only in the low word.After that diff:
VICTORY_STRICT_TESTS=1andVICTORY_DXILexplicitly pointing to the SDK DLL above; no device skips. The helper's validator-load branch itself remains optional; the same explicit DLL path produced the original rejection.0x7ff0000000000001). This is a CPU assertion test inside the Windows-only test module.git diff --checkclean.Commands (with
VICTORY_STRICT_TESTS=1andVICTORY_DXILset as above):Hardware identification from the test log:
WARP is the additional backend in the existing test, not a substitute for the physical GPU result. These are synthetic tests only; I did not test AMD, run the game, or run the complete workspace suite/clippy. The temporary per-op diagnostic print is not in this diff.
Local diff against
3328d80(not committed)AI-assisted investigation and local validation with 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.