Repository navigation
Shaders: double-precision add, mul, fma, min, max, compares and conversions (stacked on #416) - #1262
MamaLeVrai wants to merge 5 commits into
Conversation
…rsions Builds on the double type and makeDouble of Marvisak#416 (v_cvt_f32_f64), which this commit includes below it. A double is a VGPR or SGPR pair; DXIL has fadd, fmul, fma, fmax and fmin for it. Lowered: v_add_f64, v_mul_f64, v_fma_f64, v_max_f64, v_min_f64, every v_cmp_*_f64 and v_cmpx_*_f64 except class, v_cvt_f64_f32, v_cvt_f64_i32, v_cvt_f64_u32, v_cvt_i32_f64 and v_cvt_u32_f64. Sources take the abs and neg modifiers on the sign bit, inline float constants, literals (the high dword) and SGPR pairs; output modifiers on a double result are refused. fma and the double/integer conversions are D3D11.1 double extensions, so they set the new DOUBLE_EXTENSIONS flag (ShaderFlags bit 6, SFI0 0x20), which the validator checks. Of two zeros, min and max follow the f32 rule. A constant v_cmp_f/v_cmp_tru builds no doubles: WARP loses the device on a double `fcmp false`. The new code is in emit/lower/double.rs; Marvisak#416's double_src there becomes fsrc64 (any source, not only the first). Tests (valu_tests.rs) run each instruction on the host GPU and WARP and compare with Rust's f64: IEEE results with NaN, infinities, zeros and overflow, min/max zero order, abs/neg, SGPR pairs, all 16 compare predicates, and saturating conversions. Checked on an RX 6950 XT: clippy (both CI runs) is clean and cargo test --workspace passes. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Setup: Linux, RX 9070 XT, RADV (Mesa 26.3.1), dxil-spirv master, spirv-val 1.3. Your head folded onto a base of origin/main
No program gained or lost and the failure table is identical to the base, reason for reason: nothing in this capture reaches the class you lower, so this is a no-regression result only (same 10 SPIR-V validation failures as the base). Not tested: in-game. |
catminou4
left a comment
There was a problem hiding this comment.
Double-precision lowering (new emit/lower/double.rs) with DOUBLES/DOUBLE_EXTENSIONS shader flags mapped to SFI0 feature bits 0x1/0x20. The valu tests cover cvt_f32_f64 (incl. inline-constant high word, e64 modifiers) and IEEE f64 add/mul/fma/min/max NaN/zero ordering — all Windows-gated, so macOS verifies compilation and the existing suite only. Local verification: macOS arm64, rustc 1.98.1, PR head merged into main ffe310e, cargo test -p victory-shader --locked. Shader execution tests (valu_tests/host) are #[cfg(all(test, windows))], so macOS covers lowering/decode/unit tests only. 96 passed, 0 failed. Double-predication corner cases are exactly where hardware runs matter; please make sure the valu suite is run on Windows before merge.
|
Thanks, both. catminou4: the valu suite you ask to be run on Windows before merge ran here on Windows, on an RX 6950 XT and on WARP, and passes (add, mul, fma, min, max, abs and neg, SGPR pairs, all 16 compares, the conversions, with NaN, infinities, zeros and overflow); clippy with and without |
valu_tests.rs: both sides append tests at two places, each ending in the same closing lines; both kept. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Automated triage for the maintainers. Merge candidate. The merge of New in Open point for the maintainers: of two zeros, CI: passing ( Generated by Claude Code |
|
A result from a host not reported here: Arch Linux, Wine 11.22, vkd3d-proton, RTX 5080, driver 620.73.04, It is NaN only, for both A compare and a select fixes it: Separately, the red CI looks unrelated to this PR: that run (00:57 UTC) failed only Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
|
On native Windows D3D12, my RTX 3050 Laptop (Ampere, driver 32.0.16.1062) returned I merged That gives one native Ampere data point. A native run on the same RTX 5080 would help distinguish adapter and software-stack differences. AI-assisted. |
…x, compares and conversions (stacked on Marvisak#416)
|
FIND-21 (from #1633) on this PR, measured on two more AMD architectures: Setup. Case.
Both wrong results are what you get if Not specific to The test I used, for #[test]
fn f64_sources_sharing_a_dword() {
// v_add_f64 / v_mul_f64 v[6:7], v[1:2], v[2:3]: v2 is the high dword of
// the first source and the low dword of the second (FIND-21).
let a = f64::from_bits(0x3ff8_0000_0000_0000); // 1.5: v1 = 0, v2 = 0x3ff80000
let b = f64::from_bits(0x4000_0000_3ff8_0000); // v2, v3 = 0x40000000
let inputs = [[0, 0x3ff8_0000, 0x4000_0000, 0]];
type Op = (&'static str, u16, fn(f64, f64) -> f64);
let ops: [Op; 2] = [
("v_add_f64", 0x164, |x, y| x + y),
("v_mul_f64", 0x165, |x, y| x * y),
];
for (name, op, f) in ops {
let want = f(a, b);
run_f64_raw(
&vop3(op, 6, vgpr(1), vgpr(2), 0),
&inputs,
|backend, _, got| {
eprintln!(
"{backend}: {name}: {:#018x} ({}), want {:#018x} ({want})",
got,
f64::from_bits(got),
want.to_bits()
);
assert!(
same_f64(got, want),
"{backend}: {name} of shared-dword sources = {}, want {want}",
f64::from_bits(got)
);
},
);
}
}Synthetic test only, no game files. Tested with AI assistance (Claude Code). |
|
Follow-up to my FIND-21 comment above. The sources don't have to share a dword. A single double read from dwords 1 and 2 of one 4-dword load is wrong on its own. Same setup (RX 7900 XTX and the gfx1036 iGPU, identical words on both), with
Every failing result is the double with dword 1 as both halves:
My guess, not verified: these values are uniform, so they sit in an SGPR tuple. A 64-bit SGPR operand needs an even-aligned pair, and the driver's copy of the odd-aligned pair It is not limited to this PR. Synthetic test only, no game files. Tested with AI assistance (Claude Code). |
|
Progress on my #1633 claim (FP64 verification of this PR on native Windows D3D12). The results on RTX 5090, the Ryzen 9 9950X3D iGPU and WARP are below. The Radeon 860M is not done yet. Setup.
To pick the iGPU as the hardware adapter I used a local test-only patch: 1. The PR's own f64 tests
No backend was skipped. On native RTX 5090, 2. FIND-21 (doubles at an odd dword offset, or sharing a dword) These are bvtterbroot's cases, run over two inputs:
The iGPU's wrong words are identical to bvtterbroot's RX 7900 XTX and 7800X3D iGPU results (same AMD driver build as that iGPU). Every one is consistent with Synthetic inputs only, no game files. Revisions as above; the local merge and test patch are not pushed. AI-assisted verification (Claude Code). |
…(feature bits: kept both)
On AMD's D3D12 compiler (RX 6950 XT, driver 32.0.21045.29003; also reported on RDNA3 and a gfx1036 iGPU), a double built from dwords 1 and 2 of one uniform 4-dword load (the root constants here) reads its low dword as both halves, alone or when two sources share a dword. WARP and NVIDIA are right. Each dword of a register-pair f64 source is now XORed with the lane index shifted right by 31, a zero the compiler cannot fold. With it the doubles come out right on the RX 6950 XT and WARP. Inline constants and literals are unchanged. Cost: one lane index and one shift per program, one XOR per dword of a register-pair source. New test f64_reads_uniform_pairs_at_odd_dwords, 4 inputs: add, mul, fma, max, min, cvt_f32/i32/u32_f64 and two compares on v[2:3] and on sources sharing a dword; a disjoint-pair add and v_cvt_f64_f32 as controls; and 64-bit integer shifts and v_mad_u64_u32 on v[2:3], which were right on AMD without the change. Without the lowering change it fails with 45 wrong hardware results (WARP none); with it, it passes on both backends. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks bvtterbroot for FIND-21 and the cases, and JoeY54 for the RTX 5090 and 9950X3D runs. Your words made this quick to pin down. Reproduced on an RX 6950 XT (RDNA2, driver 32.0.21045.29003, Windows 11 26300), PR head
These were also wrong, all as if Workaround ( Why it works, as far as I know: it is the same idea as bvtterbroot's Results with the change
Cost: per program, one lane index and one shift, in the entry block. Per dword of a register-pair f64 source, one XOR. That is two 32-bit ALU ops next to an f64 op, which runs at 1/16 rate on RDNA2. I did not time it. If a later compiler proves the lane index's range, it could fold the zero away and bring the bug back. The test would catch that. Not tested here: RDNA3, NVIDIA, and inputs that differ per lane. The harness runs one thread, so all its inputs are uniform. AI-assisted (Claude Code); no game data. |
…_f32_u32 from main) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
The branch is mergeable again:
On the RX 6950 XT: AI-assisted (Claude Code); no game data. |
|
Two results for the outstanding NVIDIA and per-lane questions. Native Windows D3D12, RTX 5080 (driver 621.40) and Microsoft WARP, Windows build 26300.10075. I resolved each D3D12 device LUID through DXGI and verified completed UAV readbacks. Register pairs with lane-varying inputs. At
NaN-to-integer on native RTX 5080. I also tested Local test-only instrumentation, with Codex assistance. I did not run the varying-lane fixture on AMD hardware. |
…x, compares and conversions (stacked on Marvisak#416)
fuzeofficlal
left a comment
There was a problem hiding this comment.
Verified on main (63bcca43) across three D3D12 adapters (RTX 5090, AMD Ryzen 9 9950X integrated RDNA2 gfx1036, and Microsoft WARP) with Windows SDK dxil.dll:
cargo xtask policy(192 files ok;crates/victory-shader/src/emit/lower.rs=521,403B< 524,288B) andcargo clippy --locked -p victory-shader --all-targets -- -D warnings(default and--all-features) pass.- All 11 new tests (
cvt_f32_f64_*,f64_*,v_cmp_f64_*) pass on RTX 5090 and WARP. - Additional probes confirmed true fused
v_fma_f64rounding,v_cvt_i32_f64/v_cvt_u32_f64saturation and NaN -> 0 behavior, modifier rejections, and the odd-dword uniform pair case (f64_reads_uniform_pairs_at_odd_dwords) passing 4/4 on RTX 5090, AMD RDNA2 iGPU (gfx1036), and WARP.
Blocking issue: dead-code-eliminated f64 instructions fail DXIL validation (Flags must match usage)
crates/victory-shader/src/emit/lower/double.rs eagerly sets flags::DOUBLES (L114, L127, L249) and flags::DOUBLE_EXTENSIONS (L225, L249, L262) during lowering, but Module::uses() (crates/victory-shader/src/emit/bitcode.rs:530-551) and Shader::finish() (crates/victory-shader/src/emit/shader.rs:579-587) were not updated to recompute those two flags from live emitted instructions.
Because makeDouble, splitDouble, fadd, fmul, fma, and double/int casts are pure (Attr::ReadNone), any dead double instruction — an unused destination VGPR, a constant-folded dead branch, or a dead instruction whose write_f64 rejects clamp/omod (double.rs:142) after fsrc64 has already set DOUBLES — is stripped by Module::write(), leaving stale DOUBLES / DOUBLE_EXTENSIONS bits declared. dxil.dll then rejects the entire shader:
- Dead
v_add_f64(unused destination):error: Flags must match usage. note: Flags declared=1073741828, actual=1073741824 - Dead
v_fma_f64alongside a livev_add_f64:error: Flags must match usage. note: Flags declared=1074266180, actual=1074266116(staleDOUBLE_EXTENSIONS) - Dead
v_add_f64withclamp=1:error: Flags must match usage. note: Flags declared=1073741828, actual=1073741824 - Dead
v_cvt_i32_f64/ deadv_cvt_f64_i32:error: Flags must match usage. note: Flags declared=1073741892, actual=1073741824
Suggested fix (verified against dxil.dll)
Extend Uses and Module::uses() in crates/victory-shader/src/emit/bitcode.rs to track:
doubles: any live instruction whose result type or any operand type isTypeDef::Doubledouble_extensions: any liveOp::Calltodx.op.tertiary.f64with opcode47(Fma), or any liveOp::Cast(Cast::FpToUi | Cast::FpToSi | Cast::UiToFp | Cast::SiToFp, v)where eitherinst.tyorself.type_of(*v)isTypeDef::Double
Then reconcile (flags::DOUBLES, uses.doubles) and (flags::DOUBLE_EXTENSIONS, uses.double_extensions) in Shader::finish() (crates/victory-shader/src/emit/shader.rs:579-587) alongside INT64 and WAVE_OPS. Testing this patch locally passes dxil.dll validation on all 5 dead-code cases above, all 11 live double operations, and all 11 PR unit/GPU tests. Adding a validator test for dead f64 / v_fma_f64 instructions would lock this in.
|
The workaround on RDNA3, which wasn't tested yet:
So the opaque zero ( Synthetic tests only, no game files. Tested with AI assistance (Claude Code). |
|
RDNA1 hardware verification — RX 5700 XT (Navi 10), driver 32.0.21045.29003, Windows 11 26200, SDK dxil.dll 1.9.2602.17. Synthetic tests only, no game data.
So FIND-21 also affects RDNA1, and the opaque-zero workaround fixes it there. AI use: Claude Code (Claude Opus 5.5). |
|
FIND-21 hardware verification (VT-01) on PR head
This run covers the patched revision using synthetic inputs only. AI-assisted verification. |
Stacked on #416: the first commit here is that PR's
v_cvt_f32_f64, kept unchanged so its author stays credited. If #416 merges first, this rebases to the one commit on top; if this merges first, #416 can close.What
Double-precision VALU instructions that no shader lowers yet (no open PR covers them). A double is a VGPR/SGPR pair; DXIL has
fadd,fmul,fma,fmaxandfminfor it.v_add_f64,v_mul_f64,v_fma_f64,v_max_f64,v_min_f64v_cmp_*_f64/v_cmpx_*_f64exceptclassv_cvt_f64_f32,v_cvt_f64_i32,v_cvt_f64_u32,v_cvt_i32_f64,v_cvt_u32_f64Sources take abs/neg (on the sign bit, abs first), inline float constants, literals (high dword) and SGPR pairs. Output modifiers (clamp, omod) on a double result are refused.
Still refused, as DXIL has no double form: rounding (
floor,ceil,trunc,rndne),sqrt,rcp,rsq,ldexp,frexp,fract,class.Notes for review
fmaand the double/integer conversions are D3D11.1 double extensions. The validator rejects them withFlags must match usageunless ShaderFlags bit 6 and SFI00x20are set, so there is a newDOUBLE_EXTENSIONSflag.makeDouble,splitDouble,fadd,fmul, min/max and the float conversions need onlyDOUBLES.v_cmp_f_f64/v_cmp_tru_f64builds no doubles: on WARP a doublefcmp falselost the device.max_min). I did not check that rule against console hardware for f64.double_srcis nowfsrc64(inst, k)inemit/lower/double.rs, so any source works, not only the first. Its tests still pass unchanged.Tests
Six new tests in
valu_tests.rs, each run on the host GPU and on WARP and compared with Rust'sf64: IEEE results (NaN, infinities, zeros, overflow, underflow), min/max zero order, abs/neg combinations, SGPR pairs, all 16 compare predicates, and saturating conversions (NaN to 0).Run locally on an RX 6950 XT:
cargo clippy --workspace --all-targets --locked -- -D warnings: clean, with and without--all-featurescargo test --workspace --locked: all pass (130 passed, 1 ignored invictory-shader)No game data or console output is used or committed; the expected values come from IEEE 754 via Rust.
🤖 Generated with Claude Code