shader: lower v_add_f64, v_mul_f64, v_fma_f64, v_min_f64 and v_max_f64 #99

Open
github-bot wants to merge 1 commit from github-bot/gh-99 into main AGit
Owner

@⁠lcg007xd-c on GitHub · 2026-11-25 22:41 UTC · original
lcg007xd-c:shader-f64-arith → main · +140 −0 · 2 files · 1 commits · open

What 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):

VOP3 opcode Instruction
0x164 v_add_f64
0x165 v_mul_f64
0x166 v_min_f64
0x167 v_max_f64
0x14C v_fma_f64

The one exception is the whole-wave v_add_f64 sum that wave.rs recognizes. That case is tested in valu_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:

  • with one NaN operand, the result is the other operand;
  • −0 orders below +0, as max_min already does for f32 here.

The change (emit/lower.rs, in valu_op)

  • Operands: read with the existing f64_pair, which handles VGPR/SGPR pairs, 0, the f64 inline constants, the GFX10 literal-in-high-dword rule, and abs/neg. Each pair is joined with DXIL MakeDouble.
  • Arithmetic: fadd/fmul on doubles, DXIL Fma (opcode 47, a double-only op), and DMax/DMin (35/36). Two zeros get the f32 rule: +0 unless both are −0 for max, −0 unless neither is for min.
  • Result: split with SplitDouble and written to the destination pair.
  • Flag: this sets DOUBLES, as the wave sum does.
  • Modifiers: output modifiers (clamp/omod) are refused. DPP/SDWA operands are refused by f64_pair as 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 the lower.rs change 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.2 rounding, −0 vs +0, 1e300 · 1e10 → inf, NaN with a number, and −7 vs inf.
  • CPU run: I ran these on Linux through the CPU harness of #62, which runs the emitted DXIL with LLVM's lli. I compared against Rust's f64 on 46 values, including the smallest normal, denormals (5e-324, −1e-310), f64::MAX and 30 scrambled patterns. I checked both dwords of all five operations, plus neg on a source. All match.
    • For that I added MakeDouble/SplitDouble and the f64 Fma/DMax/DMin to #62's runtime (a third commit there).

Run here (Linux, Rust 1.98.1):

  • cargo test -p victory-shader --lib --locked: 188 passed, 0 failed, 2 ignored.
  • Portable clippy and 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

**@⁠lcg007xd-c** on GitHub · 2026-11-25 22:41 UTC · [original](https://github.com/uiliannn/VItoriaBr/pull/99) `lcg007xd-c:shader-f64-arith` → `main` · +140 −0 · 2 files · 1 commits · open ## What 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): | VOP3 opcode | Instruction | |---|---| | 0x164 | `v_add_f64` | | 0x165 | `v_mul_f64` | | 0x166 | `v_min_f64` | | 0x167 | `v_max_f64` | | 0x14C | `v_fma_f64` | The one exception is the whole-wave `v_add_f64` sum that `wave.rs` recognizes. That case is tested in `valu_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: - with one NaN operand, the result is the other operand; - −0 orders below +0, as `max_min` already does for f32 here. ## The change (`emit/lower.rs`, in `valu_op`) - **Operands:** read with the existing `f64_pair`, which handles VGPR/SGPR pairs, 0, the f64 inline constants, the GFX10 literal-in-high-dword rule, and `abs`/`neg`. Each pair is joined with DXIL `MakeDouble`. - **Arithmetic:** `fadd`/`fmul` on doubles, DXIL `Fma` (opcode 47, a double-only op), and `DMax`/`DMin` (35/36). Two zeros get the f32 rule: `+0` unless both are `−0` for max, `−0` unless neither is for min. - **Result:** split with `SplitDouble` and written to the destination pair. - **Flag:** this sets `DOUBLES`, as the wave sum does. - **Modifiers:** output modifiers (clamp/omod) are refused. DPP/SDWA operands are refused by `f64_pair` as 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 the `lower.rs` change 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.2` rounding, `−0` vs `+0`, `1e300 · 1e10` → inf, NaN with a number, and −7 vs inf. - **CPU run:** I ran these on Linux through the CPU harness of #62, which runs the emitted DXIL with LLVM's `lli`. I compared against Rust's f64 on 46 values, including the smallest normal, denormals (`5e-324`, `−1e-310`), `f64::MAX` and 30 scrambled patterns. I checked both dwords of all five operations, plus `neg` on a source. All match. - For that I added MakeDouble/SplitDouble and the f64 Fma/DMax/DMin to #62's runtime (a third commit there). **Run here** (Linux, Rust 1.98.1): - `cargo test -p victory-shader --lib --locked`: 188 passed, 0 failed, 2 ignored. - Portable clippy and `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](https://claude.com/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]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:43:56 +00:00
Author
Owner

@⁠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_f64 already uses the tertiary.f64 entry 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 into makeDouble (lower.rs:7383, operands from f64_pair at :8145).

That is where AMD hardware has gone wrong elsewhere:

  • Marvisak/VIctory#1262 (open, head faf20ac) is the same instruction set plus compares and conversions, in emit/lower/double.rs. In its thread, "FIND-21" was measured on RDNA1, RDNA2 and RDNA3 on native Windows: v_add_f64/v_mul_f64 give 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 reads v[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 :51 XORed into both dwords at :54-55; fsrc64 at :108) makes each source dword pass through a zero the compiler cannot fold before makeDouble. In that thread, the test passed on an RX 5700 XT, an RX 6950 XT, an RX 7900 XTX and a gfx1036 iGPU.
  • Belobug/VIctory-Belobug-AMD#198 (open, head c289582) gets around the same problem a different way, in src_f64. It passed on an RX 9060 XT, an RX 6950 XT, an RX 7900 XT and WARP.
  • The #1262 thread also reports v_cvt_i32_f64(NaN) and v_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_ieee covers 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).

**@⁠upipibi** on GitHub · 2026-11-26 23:15 UTC · [original](https://github.com/uiliannn/VItoriaBr/pull/99#issuecomment-7205386703) · 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_f64` already uses the `tertiary.f64` entry 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 into `makeDouble` (`lower.rs:7383`, operands from `f64_pair` at `:8145`). That is where AMD hardware has gone wrong elsewhere: - Marvisak/VIctory#1262 (open, head faf20ac) is the same instruction set plus compares and conversions, in `emit/lower/double.rs`. In its thread, "FIND-21" was measured on RDNA1, RDNA2 and RDNA3 on native Windows: `v_add_f64`/`v_mul_f64` give 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 reads `v[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 `:51` XORed into both dwords at `:54-55`; `fsrc64` at `:108`) makes each source dword pass through a zero the compiler cannot fold before `makeDouble`. In that thread, the test passed on an RX 5700 XT, an RX 6950 XT, an RX 7900 XTX and a gfx1036 iGPU. - Belobug/VIctory-Belobug-AMD#198 (open, head c289582) gets around the same problem a different way, in `src_f64`. It passed on an RX 9060 XT, an RX 6950 XT, an RX 7900 XT and WARP. - The #1262 thread also reports `v_cvt_i32_f64(NaN)` and `v_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_ieee` covers 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).
Author
Owner

@⁠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, run f64_arithmetic_translates and f64_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:15 UTC · [original](https://github.com/uiliannn/VItoriaBr/pull/99#issuecomment-7220542091) 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`, run `f64_arithmetic_translates` and `f64_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.
Author
Owner

@⁠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; SDK dxil.dll 1.8.2502.11).

The untouched head does not pass the GPU test here. f64_arithmetic_translates passes, but f64_add_mul_fma_min_max_match_ieee exits 101 with:

DXIL validation failed: error: Flags must match usage.
Flags declared=1073741828, actual=1073741892

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 is 0x40 (EnableDoubleExtensions): DXC marks double Fma as using that extension, and its SFI0 feature bit is 0x20.

I tested the small local diff below: set metadata bit 6 only for v_fma_f64, map it to SFI0 0x20, 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:

  • Exact GPU test: passed, with VICTORY_STRICT_TESTS=1 and VICTORY_DXIL explicitly 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.
  • Exact translation test: passed.
  • New NaN assertion regression: passed (rejects ±infinity; accepts quiet NaN and 0x7ff0000000000001). This is a CPU assertion test inside the Windows-only test module.
  • Asset policy: 195 files ok; git diff --check clean.

Commands (with VICTORY_STRICT_TESTS=1 and VICTORY_DXIL set as above):

cargo test --release --locked -p victory-shader --lib emit::lower::tests::f64_arithmetic_translates -- --exact --nocapture --test-threads=1
cargo test --release --locked -p victory-shader --lib emit::valu_tests::f64_add_mul_fma_min_max_match_ieee -- --exact --nocapture --test-threads=1
cargo test --release --locked -p victory-shader --lib emit::valu_tests::f64_nan_words_reject_infinities_and_accept_low_payload -- --exact --nocapture --test-threads=1
cargo run --release --locked -p xtask -- policy

Hardware identification from the test log:

VICTORY HOST GPU: NVIDIA GeForce RTX 4060 Laptop GPU (vendor 0x10de)
VICTORY HOST GPU: Microsoft Basic Render Driver (vendor 0x1414)

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)
diff --git a/crates/victory-shader/src/emit/lower.rs b/crates/victory-shader/src/emit/lower.rs
index bb0cc29..3d18676 100644
--- a/crates/victory-shader/src/emit/lower.rs
+++ b/crates/victory-shader/src/emit/lower.rs
@@ -7386,6 +7386,9 @@ impl<'a> Lower<'a> {
                     "v_add_f64" => self.s.m.bin(c, Bin::Add, d[0], d[1]),
                     "v_mul_f64" => self.s.m.bin(c, Bin::Mul, d[0], d[1]),
                     "v_fma_f64" => {
+                        // DXIL's double Fma requires the double-extensions
+                        // feature in addition to basic double precision.
+                        self.s.flags |= flags::DOUBLE_EXTENSIONS;
                         self.s.op(c, "tertiary.f64", Attr::ReadNone, f64t, 47, &[d[0], d[1], d[2]])
                     }
                     _ => {
diff --git a/crates/victory-shader/src/emit/shader.rs b/crates/victory-shader/src/emit/shader.rs
index 8364a42..6aa3b34 100644
--- a/crates/victory-shader/src/emit/shader.rs
+++ b/crates/victory-shader/src/emit/shader.rs
@@ -93,6 +93,7 @@ pub const USER_DISPATCH_THREADS_X: u32 = 0x104;
 pub(crate) mod flags {
     pub const RAW_BUFFERS: u64 = 1 << 4;
     pub const DOUBLES: u64 = 1 << 2;
+    pub const DOUBLE_EXTENSIONS: u64 = 1 << 6;
     pub const STENCIL_REF: u64 = 1 << 11;
     pub const TYPED_UAV_LOADS: u64 = 1 << 13;
     pub const WAVE_OPS: u64 = 1 << 19;
@@ -892,6 +893,9 @@ impl Shader {
         if self.flags & flags::DOUBLES != 0 {
             features |= 0x1;
         }
+        if self.flags & flags::DOUBLE_EXTENSIONS != 0 {
+            features |= 0x20;
+        }
         if self.flags & flags::STENCIL_REF != 0 {
             features |= 0x200;
         }
diff --git a/crates/victory-shader/src/emit/valu_tests.rs b/crates/victory-shader/src/emit/valu_tests.rs
index b99d8da..229f321 100644
--- a/crates/victory-shader/src/emit/valu_tests.rs
+++ b/crates/victory-shader/src/emit/valu_tests.rs
@@ -269,6 +269,18 @@ fn run_cases_on(
     assert!(ran > 0, "no SM 6.6 device available ({devices:?})");
 }
 
+fn f64_words_are_nan(lo: u32, hi: u32) -> bool {
+    f64::from_bits(u64::from(lo) | (u64::from(hi) << 32)).is_nan()
+}
+
+#[test]
+fn f64_nan_words_reject_infinities_and_accept_low_payload() {
+    assert!(!f64_words_are_nan(0, 0x7ff0_0000));
+    assert!(!f64_words_are_nan(0, 0xfff0_0000));
+    assert!(f64_words_are_nan(0, 0x7ff8_0000));
+    assert!(f64_words_are_nan(1, 0x7ff0_0000));
+}
+
 #[test]
 fn f64_add_mul_fma_min_max_match_ieee() {
     // op v[5:6], v[1:2], v[3:4] (v_fma_f64: + v[1:2]); then v_mov_b32 v0,
@@ -286,15 +298,20 @@ fn f64_add_mul_fma_min_max_match_ieee() {
     let inputs: Vec<[u32; 4]> = pairs.iter().map(|&(a, b)| { let (a, b) = (d(a), d(b)); [a[0], a[1], b[0], b[1]] }).collect();
     for (op, name, f) in ops {
         let w = [0x35 << 26 | op << 16 | 5, 0x101 | 0x103 << 9 | 0x101 << 18];
+        let mut low_words = std::collections::BTreeMap::<String, Vec<u32>>::new();
         for (h, src) in [(0, 5u8), (1, 6)] {
             let shader = build_valu_cs(&[w[0], w[1], vop1(0x001, 0, vgpr(src))]);
             run_cases(&shader, &inputs, |backend, i, _, got| {
                 let (a, b) = pairs[i];
                 let r = f(a, b);
                 if r.is_nan() {
-                    // Any NaN: the high dword's exponent all ones, some mantissa bit set.
-                    if h == 1 {
-                        assert_eq!(got & 0x7FF0_0000, 0x7FF0_0000, "{backend}: {name}({a}, {b}) high dword {got:#010x}, want a NaN");
+                    // Check both dwords: an all-ones exponent alone also
+                    // admits infinities, and a NaN payload can be in the low word.
+                    if h == 0 {
+                        low_words.entry(backend.to_owned()).or_insert_with(|| vec![0; pairs.len()])[i] = got;
+                    } else {
+                        let lo = low_words.get(backend).expect("low dword was read first")[i];
+                        assert!(f64_words_are_nan(lo, got), "{backend}: {name}({a}, {b}) words [{lo:#010x}, {got:#010x}], want a NaN");
                     }
                     return;
                 }

AI-assisted investigation and local validation with Codex.

**@⁠lmouz823-lang** on GitHub · 2026-11-27 14:27 UTC · [original](https://github.com/uiliannn/VItoriaBr/pull/99#issuecomment-7220809870) Completed the native Windows check on exact head `3328d80a9de24882226103f3bcb3efd46b4843c4` (RTX 4060 Laptop, driver 610.88; Windows 11 build 26200; Rust 1.98.1 MSVC; SDK `dxil.dll` 1.8.2502.11). **The untouched head does not pass the GPU test here.** `f64_arithmetic_translates` passes, but `f64_add_mul_fma_min_max_match_ieee` exits 101 with: ```text DXIL validation failed: error: Flags must match usage. Flags declared=1073741828, actual=1073741892 ``` 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 is `0x40` (`EnableDoubleExtensions`): [DXC marks double Fma as using that extension](https://github.com/microsoft/DirectXShaderCompiler/blob/main/lib/DXIL/DxilShaderFlags.cpp), and its [SFI0 feature bit is `0x20`](https://github.com/microsoft/DirectXShaderCompiler/blob/main/include/dxc/DXIL/DxilConstants.h). I tested the small local diff below: set metadata bit 6 only for `v_fma_f64`, map it to SFI0 `0x20`, 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: - Exact GPU test: **passed**, with `VICTORY_STRICT_TESTS=1` and `VICTORY_DXIL` explicitly 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. - Exact translation test: **passed**. - New NaN assertion regression: **passed** (rejects ±infinity; accepts quiet NaN and `0x7ff0000000000001`). This is a CPU assertion test inside the Windows-only test module. - Asset policy: **195 files ok**; `git diff --check` clean. Commands (with `VICTORY_STRICT_TESTS=1` and `VICTORY_DXIL` set as above): ```text cargo test --release --locked -p victory-shader --lib emit::lower::tests::f64_arithmetic_translates -- --exact --nocapture --test-threads=1 cargo test --release --locked -p victory-shader --lib emit::valu_tests::f64_add_mul_fma_min_max_match_ieee -- --exact --nocapture --test-threads=1 cargo test --release --locked -p victory-shader --lib emit::valu_tests::f64_nan_words_reject_infinities_and_accept_low_payload -- --exact --nocapture --test-threads=1 cargo run --release --locked -p xtask -- policy ``` Hardware identification from the test log: ```text VICTORY HOST GPU: NVIDIA GeForce RTX 4060 Laptop GPU (vendor 0x10de) VICTORY HOST GPU: Microsoft Basic Render Driver (vendor 0x1414) ``` 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. <details> <summary>Local diff against 3328d80 (not committed)</summary> ```diff diff --git a/crates/victory-shader/src/emit/lower.rs b/crates/victory-shader/src/emit/lower.rs index bb0cc29..3d18676 100644 --- a/crates/victory-shader/src/emit/lower.rs +++ b/crates/victory-shader/src/emit/lower.rs @@ -7386,6 +7386,9 @@ impl<'a> Lower<'a> { "v_add_f64" => self.s.m.bin(c, Bin::Add, d[0], d[1]), "v_mul_f64" => self.s.m.bin(c, Bin::Mul, d[0], d[1]), "v_fma_f64" => { + // DXIL's double Fma requires the double-extensions + // feature in addition to basic double precision. + self.s.flags |= flags::DOUBLE_EXTENSIONS; self.s.op(c, "tertiary.f64", Attr::ReadNone, f64t, 47, &[d[0], d[1], d[2]]) } _ => { diff --git a/crates/victory-shader/src/emit/shader.rs b/crates/victory-shader/src/emit/shader.rs index 8364a42..6aa3b34 100644 --- a/crates/victory-shader/src/emit/shader.rs +++ b/crates/victory-shader/src/emit/shader.rs @@ -93,6 +93,7 @@ pub const USER_DISPATCH_THREADS_X: u32 = 0x104; pub(crate) mod flags { pub const RAW_BUFFERS: u64 = 1 << 4; pub const DOUBLES: u64 = 1 << 2; + pub const DOUBLE_EXTENSIONS: u64 = 1 << 6; pub const STENCIL_REF: u64 = 1 << 11; pub const TYPED_UAV_LOADS: u64 = 1 << 13; pub const WAVE_OPS: u64 = 1 << 19; @@ -892,6 +893,9 @@ impl Shader { if self.flags & flags::DOUBLES != 0 { features |= 0x1; } + if self.flags & flags::DOUBLE_EXTENSIONS != 0 { + features |= 0x20; + } if self.flags & flags::STENCIL_REF != 0 { features |= 0x200; } diff --git a/crates/victory-shader/src/emit/valu_tests.rs b/crates/victory-shader/src/emit/valu_tests.rs index b99d8da..229f321 100644 --- a/crates/victory-shader/src/emit/valu_tests.rs +++ b/crates/victory-shader/src/emit/valu_tests.rs @@ -269,6 +269,18 @@ fn run_cases_on( assert!(ran > 0, "no SM 6.6 device available ({devices:?})"); } +fn f64_words_are_nan(lo: u32, hi: u32) -> bool { + f64::from_bits(u64::from(lo) | (u64::from(hi) << 32)).is_nan() +} + +#[test] +fn f64_nan_words_reject_infinities_and_accept_low_payload() { + assert!(!f64_words_are_nan(0, 0x7ff0_0000)); + assert!(!f64_words_are_nan(0, 0xfff0_0000)); + assert!(f64_words_are_nan(0, 0x7ff8_0000)); + assert!(f64_words_are_nan(1, 0x7ff0_0000)); +} + #[test] fn f64_add_mul_fma_min_max_match_ieee() { // op v[5:6], v[1:2], v[3:4] (v_fma_f64: + v[1:2]); then v_mov_b32 v0, @@ -286,15 +298,20 @@ fn f64_add_mul_fma_min_max_match_ieee() { let inputs: Vec<[u32; 4]> = pairs.iter().map(|&(a, b)| { let (a, b) = (d(a), d(b)); [a[0], a[1], b[0], b[1]] }).collect(); for (op, name, f) in ops { let w = [0x35 << 26 | op << 16 | 5, 0x101 | 0x103 << 9 | 0x101 << 18]; + let mut low_words = std::collections::BTreeMap::<String, Vec<u32>>::new(); for (h, src) in [(0, 5u8), (1, 6)] { let shader = build_valu_cs(&[w[0], w[1], vop1(0x001, 0, vgpr(src))]); run_cases(&shader, &inputs, |backend, i, _, got| { let (a, b) = pairs[i]; let r = f(a, b); if r.is_nan() { - // Any NaN: the high dword's exponent all ones, some mantissa bit set. - if h == 1 { - assert_eq!(got & 0x7FF0_0000, 0x7FF0_0000, "{backend}: {name}({a}, {b}) high dword {got:#010x}, want a NaN"); + // Check both dwords: an all-ones exponent alone also + // admits infinities, and a NaN payload can be in the low word. + if h == 0 { + low_words.entry(backend.to_owned()).or_insert_with(|| vec![0; pairs.len()])[i] = got; + } else { + let lo = low_words.get(backend).expect("low dword was read first")[i]; + assert!(f64_words_are_nan(lo, got), "{backend}: {name}({a}, {b}) words [{lo:#010x}, {got:#010x}], want a NaN"); } return; } ``` </details> AI-assisted investigation and local validation with Codex.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/99/head:github-bot/gh-99'
git switch 'github-bot/gh-99'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-99'
git switch 'github-bot/gh-99'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-99'
git switch 'github-bot/gh-99'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-99'
git switch 'main'
git merge --squash 'github-bot/gh-99'
git switch 'main'
git merge --ff-only 'github-bot/gh-99'
git switch 'main'
git merge 'github-bot/gh-99'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.