tombox-xshader: exact v_fma_f32 on devices without 64-bit float shader ops (integer tb_fma, probe with a CPU reference) #73
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/73"
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?
Imported from omonkeyz/xbox-emulator. Originally posted by realkodr on 2026-11-21T23:20:18Z.
Library / area: tombox-xshader (
tb_fmahelpers,fma_probe,compile_fma, shader cache key), d3d12_xs (one log line)Exports changed (exports.txt rows): none
Source of the behaviour: unchanged:
v_fma_f32is a single-rounding fused multiply-add with the NaN rules the existing helpers already have. This adds a third way to compute the same result. The integer algorithm is the standard one (exact 48-bit product, aligned add with a sticky bit, round to nearest even), written for this PR and checked againstf32::mul_add.Problem
The exact
tb_fmaneeds HLSL doubles. A device withoutDoublePrecisionFloatShaderOpscannot build it. Intel Xe is one, and I'd expect the same on Windows. On such a device the new fma probe cannot run either: its shader holds both helpers,CreateComputePipelineStatefails, and the runtime logs "probe failed; exact path kept". No shader that usesv_fma_f32can then be created.The fast helper is not a way out there. Measured on the device below,
mad()is not fused: 848,336 of 5,242,880 probe results differ from the exact value.Change
fma_probe::reference()is the exact helper's arithmetic done on the CPU in f64. When the device has no doubles, the probe runs the fast helper alone and compares it with that. A unit test checks the reference againstf32::mul_addon 1,000,000 inputs.tb_fmaunderTB_INT_FMA, in 64-bit integer arithmetic, with gradual underflow and the same NaN rules as the other two.Fma::intonly if every result matches the reference.compile_fmathen passes-D TB_INT_FMA. The flag is in the shader cache key and in the cached probe result;PROBE_VERSIONis 3.Devices with doubles are probed exactly as before and never get the integer helper. The fast/exact block in
hlsl.rskeeps its shape, sohelper_lines()parses it unchanged.Results
Intel Iris Xe (TGL GT2), Mesa 26.2.7, vkd3d-proton 3.1 under Wine 11.21 (built and run with the tooling in #52). The device reports no 64-bit float ops.
mainCreateComputePipelineState 0x80070057Fma { preserve: false, any: false, int: true }execfma_single_rounding,fma_f32_full_rangewith the f64 helper-D TB_INT_FMA--lib --test opcodes --test syntheticBefore porting to HLSL, the algorithm was checked as a CPU model against
f32::mul_addon 200,000,000 inputs (random, cancellation, rounding ties, denormal inputs and results, overflow, every triple of 20 special values) with no mismatch.Not checked
Windows, and any device that has doubles. The new
hw_integer_fma_matches_referencetest (ignored, needs a GPU) runs the integer helper on whatever device is present; it should pass on WARP, NVIDIA and AMD too. I can't run it there.Cost. I have not measured the integer helper against the f64 one. It only runs where the f64 one cannot.
FXC. The helper uses
uint64_t, so it is SM6 only, like the f64 helper.The exec tests do not go through the probe. For the two
execrows above I added-D TB_INT_FMAtodxc::compilelocally; that switch is not in this PR.Other f64 uses (
v_fma_f64,tb_ldexp64, ...) still need doubles.vector_vop3keeps 6 failing cases on this device for that reason.Under Wine the adapter id reads "NVIDIA GeForce GTX 470", which is Wine's placeholder, so the cached probe result is keyed by that string there.
cargo test -p tombox-xshader --lib --test opcodes --test syntheticpasses (under Wine); the GPU tests named above pass on the Iris XeNo game or console files and no binaries included
No fake success; anything not possible is left
missingwith a note🤖 Generated with Claude Code
Imported from omonkeyz/xbox-emulator. Originally posted by QuentinDanblon on 2026-11-21T23:42:32Z.
I ran the part listed under "Not checked" on Windows, on a device that has doubles: RTX 5090, driver 32.0.16.1742, head
c00a1bf.hw_integer_fma_matches_reference(ignored test, run with--ignored)hw_fast_fma_matches_exact_pathFma { preserve: true, any: false, int: false }: preserve 0 differ, any 503,648 differ.intstays off, as intended on a device with doubles--lib--test exec fmaTOMBOX_EXEC_HW=1)Not checked:
fma_probetests picked the hardware adapter in both of my runs;TOMBOX_EXEC_HWdoes not change that.The branch merges cleanly with #36, #61, #63 and #76 (textual merge only, not tested together).
Related:
reference()and the three helpers share one NaN rule (first NaN operand, quieted). Whether RDNA2 does that forv_fma_f32is one of the things thenanprobe in #72 would measure, if someone with the hardware runs it.Imported from omonkeyz/xbox-emulator. Originally posted by SchmashinPrunes on 2026-11-22T00:11:34Z.
FYI, since
reference()and the helpers here share main's NaN rule (first NaN operand, quieted;0x7fc00000for an invalid operation): I ran thenanprobe from #72 on RDNA2 hardware (gfx1036), andv_fma_f32doesn't quite do that. Details and the fitted rules are here: https://github.com/omonkeyz/xbox-emulator/pull/41#issuecomment-7071178837In short:
0xffc00000;0 * inf + NaNreturns that default NaN rather than c;This PR keeps main's existing rule on purpose, so I don't see it as a blocker here. It's just useful context if the reference or helpers change later. Which IEEE mode console shaders use is still open (see QuentinDanblon's note on #41).
Imported from omonkeyz/xbox-emulator. Originally posted by omonkeyz on 2026-11-22T13:12:41Z.
Main's history was rewritten, which auto-closed this PR (sorry for the noise). Good idea. Please rebase on main's current fma_probe/shader_xlat code and strip the comment lines (the project keeps code free of comment lines). To resubmit:
git fetchthis repo, branch from the currentmain, cherry-pick only your own commits (the old branch is based on the previous history and cannot be merged), and open a new PR.Pull request closed