Recompiler: translate f64 division ops (v_div_scale/fmas/fixup_f64) #817
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/823"
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 ivall/xcl. Originally posted by mastrr9 on 2026-11-24T06:07:54Z.
v_div_scale_f64,v_div_fmas_f64, andv_div_fixup_f64were previously reported unsupported, leaving shaders that emit LLVM'sfdiv doublesequence untranslated.What is in it
crates/xcl/src/gpu/recomp/emit.rs:v_div_scale_f64passessrc0through unscaled and setsSDST(VCC) tofalse(matchingv_div_scale_f32).v_div_fmas_f64emitsfma(a, b, c)(since scale carry is 0).v_div_fixup_f64emitsdiv_fixup_d(q, d, n)(placed afterldexp_dinPRELUDE): handles IEEE 754 special cases on the bits, usesqdirectly with the quotient sign in the safe normal range (e_n >= 55,3 <= e_d <= 2042,3 <= e_q <= 2045), and falls back todiv_d(n, d)(precisemantissa division + single-rounded denormal scaling) where scaling matters.crates/xcl/src/gpu/recomp/tests.rs:div_f64_translates(HLSL + DXC check) andgpu_div_f64(full LLVM f64 division sequence verified bit-for-bit against CPU IEEE division across 512+ special, denormal, extreme-exponent, and random pairs).Tested
617.42/32.0.16.1742), Windows 11 Pro 25H2 (26200.9974), D3D12 debug layer installed (d3d12SDKLayers.dll),rustc 1.100.0 (0ef1bc386 2026-11-09)MSVC, DXC from Windows SDK10.0.26100.0, debug build.93b8b1d118d6db4b6e134166c0ada511a8950354):cargo build --workspace && cargo test --workspace -- --test-threads=4gpu::recomp::tests::div_f64_translates—okgpu::recomp::tests::gpu_div_f64—ok(executed on RTX 5080 wave32, bit-exact on all 512+ pairs, not skipped)gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask(no wave64),gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware(no wave64).Regression run
Smoke run by @Toons29 in comment below: https://github.com/xcl-dev/xcl/pull/823#issuecomment-7151535852
Contributed by a community tester; the PR author did not run it. Both blocks are pasted as posted.
main:
PR:
Tester's setup and limits: AMD Radeon RX 9070 (RDNA4, driver 32.0.32029.2010), Ryzen 7 7800X3D, 32 GB, Windows 11 build 26300, Rust 1.100.0,
cargo build --release -p xcl, 60 s,XCL_NETWORK=0. This is a regression check only: it does not show whether the run reaches the code this PR changes.Tester's AI use: Claude Code (Claude Opus 5.5) built both trees and ran
scripts/smoke.ps1; the tester checked the blocks before posting.Not tested
AI use
v_div_scale_f64/v_div_fmas_f64/v_div_fixup_f64translation,div_d/div_fixup_dhelpers, and tests.div_d/div_fixup_dbelowldexp_dafter catching a DXC compile error on Windows), ran the full Windows RTX 5080 MSVC + D3D12 debug-layer workspace suite, and drafted this PR description.Imported from ivall/xcl. Originally posted by SlopTart on 2026-11-24T06:41:30Z.
2|
3|AMD/wave64 + release-build datapoint - and the bit-exactness does NOT hold here: your
gpu_div_f64fails on RDNA3, deterministically, and only in the wave64 form.4|
5|Machine: RX 7900 XT (RADV NAVI31), Mesa 26.2.5, kernel 7.2 (Arch), Wine = Proton Experimental (wine-11.0), patched vkd3d-proton v3.1, Rust 1.100.0 cross
x86_64-pc-windows-gnu, release profile,XCL_NETWORK=0, native wave64. Same rig as my Linux rows in #42 / #718.6|
7|Merged state: head
93b8b1d(fast-forward ontobeaa245), clean.8|
9|Full suite,
cargo test --workspace --release --no-fail-fast -- --test-threads=4: 704 passed, 11 failed, 41 ignored (17 suites). 10 are this rig's known set (7 stable Wine-lane, my #42 row, + the #718 trio). The 11th is yours:10|
11|-
gpu::recomp::tests::gpu_div_f64- FAIL, deterministic: 3 of 3 isolated reruns + the full suite, identical pair set. The wave32 form passes; the wave64 form is off by exactly 1 ulp on 19 of the checked pairs. Every mismatch sits where your fixup falls back todiv_d(extreme exponents / denormal territory), including the clean case1.7976931348623157e308 / 1.7976931348623157e308 = 0.9999999999999999 (0x3fefffffffffffff), want 1e0. Sample of the set:12| -
-3.3895232148356776e228 / 1.7976931348623157e308 = ...2fc9, want ...2fca13| -
1.005e2 / 1.7976931348623157e308 = 0x0059200000000000, want 0x005920000000000114| -
2.225073858507201e-308 / -1.644453431147607e-308 = ...947f, want ...947e15|-
div_f64_translates(HLSL/DXC check) passes.16|- Note this rig's f64 lane already has known failures (
gpu_f64_math_randometc., my #42 row) - but those are different ops and a different pattern; your wave32 form passing while wave64 fails 1-ulp points at the wave64 path or thediv_dfallback under this DXC/radv pipeline, not at general f64 brokenness.17|
18|Not tested: retail titles (none here), Windows, RDNA4, debug build.
19|Counts only, no game data.
20|AI use: Hermes agent (local Qwen-class) ran the suite and drafted this; I checked it before posting.
Imported from ivall/xcl. Originally posted by dcastell1 on 2026-11-24T06:55:00Z.
Verified on Windows 11 10.0.26300, NVIDIA GeForce RTX 5090 (driver 621.24), Rust 1.100.0 MSVC 14.44.35207, debug build, on
main@beaa245:All green: the translated f64 division ops builds and runs, the workspace has no new failure against
mainon this box (737 passed there), and nothing else changes verdict. Restored the tree afterwards; no game data, hardware adapter, no Wine.AI-assisted (opencode): applied the patch to a built tree, ran the suite, reverted it.
Imported from ivall/xcl. Originally posted by mastrr9 on 2026-11-24T07:06:12Z.
Huge catch — thank you for running this on RDNA3 wave64!
Root cause: In
div_d,precise double r = mn / md;assumed the driver's double division is IEEE correctly rounded (as on NVIDIA), whereas RADV wave64 lowersdoubledivision via approximate reciprocal (~1 ULP low, e.g.mn == mdreturning0x3fefffffffffffffinstead of1.0).Fix (squashed into
fb5ca84a252484bda54daf65f39a825f11978be2):r = fma(rem, 1.0 / md, r); rem = fma(-md, r, mn);followed by an exact 1-ULP IEEE round-to-nearest-even adjustment comparingremagainst the exact power-of-two half-ULP boundmd * (0.5 * ulp(r)), updatingrem = fma(-md, r, mn)if adjusted (so the denormal rounding step below also sees the exact remainder).f64::MAX / f64::MAX) with simulated±4 ULPcorrupted hardwaremn / mdand±2 ULPcorrupted1.0 / md— 0 mismatches.Re-tested on native Windows 11 + NVIDIA RTX 5080 (
fb5ca84a252484bda54daf65f39a825f11978be2, driver617.42,rustc 1.100.0):cargo build --workspaceclean,cargo test --workspace -- --test-threads=4: 715 passed, 0 failed, 41 ignored (SKIPPED: only the 2no wave64tests). If you get a chance to re-rungpu_div_f64on your RX 7900 XT, I'd love to know if wave64 is bit-exact now!(Assisted-by: Antigravity / Gemini 4 Neon + Claude Sonnet 5.5)
Imported from ivall/xcl. Originally posted by SlopTart on 2026-11-24T08:10:01Z.
Re-ran on the RX 7900 XT at
fb5ca84(merged onto main1ec4c98for the run): the fix works for the normal range butgpu_div_f64still fails here - wave64 leg only, and the residue is purely denormal.f64::MAX / f64::MAX->0x3fefffffffffffff). All gone - MAX/MAX and the normal-range pairs are bit-exact now.5e-324 / -6.591622639274444e-308. The wave32 leg passes clean, as before.Sample (full list of 8 is in the test output):
Reading from your fix note: the FMA refinement + RNE adjustment lands
rexactly for normals, but the denormal rounding step still computes through the approximate reciprocal path - same root cause one layer down. Theremyou feed into it is exact now, so the fixup may only need the subnormal scale handled without re-touching1.0 / md.Determinism: same 8 pairs on reruns (isolated, release,
--test-threadsdefault). Happy to re-verify any follow-up.Counts only, no game data.
Machine: RX 7900 XT (RADV NAVI31), Mesa 26.2.5, kernel 7.2 (Arch), Proton Experimental (wine-11.0), patched vkd3d-proton v3.1, Rust cross
x86_64-pc-windows-gnu,XCL_NETWORK=0, release profile. My Linux rows: #42 / #718.AI use: Hermes agent (local Qwen-class) ran the suite and drafted this; I checked it before posting.
Imported from ivall/xcl. Originally posted by KENAJBBY on 2026-11-24T09:32:04Z.
Native wave64 run on RDNA2 under the Windows AMD driver, at
66d892164d14eb091f175c2763574d02e348fd2e(its basebeaa245; it also merges cleanly withmain077ce40):gpu_div_f64passes, both the wave64 and the wave32 pass, every pair bit-exact. This head has the same code asfb5ca84, which failed on 8 denormal pairs on the RX 7900 XT under RADV in the comment above. The test's pairs are fixed (seeded RNG), so this run checked the same pairs.Tested
gfx1036, native 64-lane waves, mesh shaders), driver 32.0.21030.2001; NVIDIA GeForce RTX 5070 Ti, driver 621.24 (32-lane waves only); Windows 11 Pro 26200; Rust 1.100.0stable-x86_64-pc-windows-msvc, debug; DXC 1.9.2602.17XCL_ADAPTER=radeon XCL_REQUIRE_GPU=wave64,mesh cargo test --workspace --no-fail-fast -- --test-threads=4: 715 passed, 0 failed, 41 ignored, 0SKIPPED.mainbeaa245on the same machine: 713 passed, 0 failed, 41 ignored, 0SKIPPED. The +2 arediv_f64_translatesandgpu_div_f64.gpu_div_f64alone on the Radeon (--exact,XCL_REQUIRE_GPU=wave64,mesh), 3 runs: passed each time.XCL_ADAPTER=nvidia XCL_REQUIRE_GPU=mesh, same command: 712 passed, 3 failed, 41 ignored.SKIPPED(no wave64):gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware.gpu_div_f64passes there too (split wave64 + wave32).placed_title_textures_share_vram_and_preserve_pixels(cubemap extra_pages must be reused at same va) plustransitions_apply_when_their_list_is_submittedandd32s8_targets_take_their_own_size_of_video_memoryon itsPoisonError. They are not from this PR.main077ce40fails the same three on this machine on both adapters, and the first Radeon run of this PR did too. Other test runs were using the same GPUs at the time. Alone (cargo test -p xcl --lib -- --test-threads=4 title_textures::tests vram::tests), they pass on this head: 20 passed, 0 failed on the Radeon and on the RTX.So on this machine the remaining RDNA3 mismatches do not show up, in either wave size. That points at how RADV / vkd3d-proton runs the f64 denormal path rather than at XCL's wave64 form, but I have not checked RADV myself.
Not tested
scripts/smoke.ps1); noXCL_SAMPLE_*setAI use
Imported from ivall/xcl. Originally posted by iggyvilla on 2026-11-24T13:04:33Z.
Test report for
66d892164d14eb091f175c2763574d02e348fd2e(current head of #823, basebeaa245; not merged withmain): the targeted GPU tests on an AMD RDNA2 card. The command was run, and its output captured, by an agent (omp, DeepSeek V4.1 Flash); the text below was checked against the PR head's source and written by Claude Code (Claude Sonnet 5.5).Tested
cargo test -p xcl --lib --release -- div_f64:No
SKIPPEDline, so the GPU path ran.gpu_div_f64loops overgpu_waves(); on a native wave64 adapter that is wave64 and wave32. In each it runs the same 512 pairs (34 fixed edge cases, the rest random) and compares the result bit for bit withn / d, treating NaN as equal to NaN.What this shows
Not tested
cargo test --workspace; no compare-side e2e.crates/xcl/src/gpu/recomp/emit.rsis runtime code, so the PR still needs thescripts/smoke.ps1pair (main vs head). This report is GPU test evidence only; no retail title was run.main. The raw test output was not kept as a file; the block above is the agent's capture.AI use
Claude Code, Claude Sonnet 5.5: checked the report against the PR head's
tests.rsand wrote this text; it ran nothing. The build and test run were done by omp with DeepSeek V4.1 Flash, which changed no code.Imported from ivall/xcl. Originally posted by mastrr9 on 2026-11-24T14:38:12Z.
Huge thanks @SlopTart, @KENAJBBY, and @iggyvilla for the thorough cross-GPU data! Confirming bit-exact pass across both wave64 and wave32 on two independent Windows RDNA2 GPUs (
gfx1036and RX 6650 XT) alongside NVIDIA RTX 5080 (with the remaining 8 denormal pairs isolated specifically to RADV's wave64 path) gives a very clear picture.Imported from ivall/xcl. Originally posted by Toons29 on 2026-11-25T03:02:47Z.
Regression run of
66d89216on the retail title, for this PR's Regression run section. Both blocks are fromscripts/smoke.ps1as printed, not edited:mainon4178e888, this PR on its head commit with no uncommitted changes, same title and time.Against the limits in CONTRIBUTING.md: 100 % of
main's frames, 100 % of its peak commit, no crash, no device removal.AMD Radeon RX 9070 (RDNA4, driver 32.0.32029.2010), Ryzen 7 7800X3D, 32 GB, Windows 11 build 26300, Rust 1.100.0,
cargo build --release -p xcl, 60 s,XCL_NETWORK=0. This is a regression check only: it does not show whether the run reaches the code this PR changes.AI use: Claude Code (Claude Opus 5.5) built both trees and ran
scripts/smoke.ps1; I checked the blocks before posting.Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T10:38:38Z.
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)Thanks!
Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-11-29T20:41:06Z.
Nothing has happened on this PR for 3 days, so it is marked
staleand will be closed in 4 days. A push or a comment takes the mark off: rebase it ontomainif it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.Imported from ivall/xcl. Originally posted by saintwolf on 2026-11-30T17:08:03Z.
merge-check claim
head:
66d892164dImported from ivall/xcl. Originally posted by saintwolf on 2026-11-30T17:13:35Z.
merge-check
base:
9dfbe3ea66head:
66d892164dmerge: clean (trial merge 265f4e19a799b716fdd6d3cb251c123cc7502d86; git diff --check clean; +145/-0 in crates/xcl/src/gpu/recomp/emit.rs and tests.rs)
build: cargo build --workspace -> ok (pre-existing warnings only, none from the PR's lines)
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2886 passed, 2 failed, 51 ignored; SKIPPED: 27, the standard set for this card (22 "no wave64" — wave32-only GPU, 2 "no heap windows", 1 "cannot disable the driver cache (Developer Mode)", 2 "no xgameruntime.dll"). Failing: (1) gpu::dxil::msaa_tests::gpu_direct_image_get_resinfo_d16 — pre-existing on this machine, identical on base
9dfbe3ea; (2) the new gpu_div_f64 in the default environment: kernel tests run on the direct-DXIL backend when XCL_DIRECT_DXIL is unset, and the direct backend still has no f64 division (v_div_scale_f64 hits the "VALU 64-bit" catch-all at dxil/lower_wide.rs:1032). I reproduced the identical panic on a clean base worktree with only the test file applied, so this is not a regression — this PR touches only the HLSL recompiler, and the game compute path falls back to it when the direct backend cannot translate a program (direct_fallback, recomp/pso.rs:1280). On the HLSL path the PR actually changes (XCL_DIRECT_DXIL=0) I confirmed first-hand: both new tests fail on base and pass with the change, and gpu_div_f64 is bit-exact against CPU IEEE division for all 512 pairs on this card.review: read the whole diff and the surrounding code. The three new ops mirror the existing f32 division handling (v_div_scale_f32 at emit.rs:4268, v_div_fmas_f32 / v_div_fixup_f32 at 4181–4182): v_div_scale_f64 is the identity with VCC 0, v_div_fmas_f64 is a plain fma of the already-scaled reciprocal sequence, v_div_fixup_f64 is the IEEE special-case table. I hand-verified div_d against IEEE RNE: the ULP constants (2^-52 / 2^-53), the exact half-ULP tie bounds (the power-of-two scaling is exact), the subnormal sticky/round path including the t = 2^53 carry rolling into the min-normal encoding, and the fixup table (NaN priority, 0/0, ±0 / ±inf). The GPU test drives a genuine Newton reciprocal sequence (constant 242 = 1.0 verified) and checks 34 hand-picked edge pairs plus 478 seeded random pairs bit-for-bit. Thread: dcastell1's RTX 5090 full suite clean; SlopTart's RX 7900 XT (RADV wave64) found a deterministic 1-ULP failure on 19 pairs, root-caused by the author to RADV's approximate-reciprocal double division and fixed in-tree (
fb5ca84: one FMA refinement step plus an exact 1-ULP RNE adjustment, verified off-tree against ±4-ULP / ±2-ULP corrupted-division simulation, 0 mismatches on 20k pairs); SlopTart's re-run confirmed the 19 are gone with 8 denormal pairs remaining, isolated to RADV's f64 denormal path; at the current head, iggyvilla (gfx1036 RDNA2 wave64 iGPU, 715/0/41) and KENAJBBY (RX 6650 XT, release) both bit-exact in both wave sizes, and the author's xcl-smoke main-vs-head pair on an RX 9070 is 100% of main's frames and peak commit with no crashes or device removals. No duplicates; sibling #3312 (f32 div_fixup fallbacks) touches the same file but is a different concern — only a rebase-ordering note. Pure additions, no unsafe, no new dependencies, no stop-criteria files.performance: none; the division sequence is the same shape as the f32 one it mirrors.
verdict: safe to merge
hardware / tool and model: RTX 4070 SUPER (driver 32.0.16.2140), Ryzen 7 7800X3D, Windows 11 build 26300, Rust 1.100.0 / OpenCode, Qwen 3.8 27B
Imported from ivall/xcl. Originally posted by brainhay5 on 2026-11-30T17:21:52Z.
merge-check claim
head:
66d892164dImported from ivall/xcl. Originally posted by brainhay5 on 2026-11-30T20:29:05Z.
merge-check
base:
9dfbe3ea66head:
66d892164dmerge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2885 passed, 3 failed, 51 ignored; 29 SKIPPED lines; failing: gpu::dxil::msaa_tests::gpu_direct_image_get_resinfo_d16 (fails on base too), test_title_runs_and_game_folder_is_untouched (fails on base too), gpu::recomp::tests::gpu_div_f64 (does not exist on base — this PR adds it, and it fails)
review: automated check: diff inspected for safety only (no build/CI/toolchain/script changes, no process/network/runtime-loading code); no line-by-line review and no duplicate search performed.
performance: not assessed beyond the suite.
verdict: not yet: adds failing test(s): gpu::recomp::tests::gpu_div_f64
hardware / tool and model: RTX 5070 Ti 16 GB, driver 610.88 (32.0.16.1088); Ryzen 7 5800X3D, 64 GB; Windows 11 22631; OpenCode agent, DeepSeek V4.1 Flash 1017
Imported from ivall/xcl. Originally posted by Chrysana on 2026-12-01T00:13:53Z.
merge-check
base:
d0832e614fhead:
66d892164dmerge: clean (git diff --check clean)
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2883 passed, 10 failed, 51 ignored (base: 2882 passed, 9 failed, 51 ignored); SKIPPED: 6, the same as on base (2 no heap windows, 1 cannot disable the driver cache without Developer Mode, 3 no D3D12 debug layer). This card runs wave64, so the wave64 halves of the GPU tests run here too. failing: the same 8 tests as on base (fuzz_validate_and_gpu_1, fuzz_validate_and_gpu_3, gpu_smem_flat_descriptor_windows_and_limits, f32_programs_on_the_gpu, gpu_f32_compares_with_nan, gpu_float_compares_random, gpu_ps_readfirstlane_loop_on_a_primitive_edge_ends, two_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobs, counted twice), plus this PR's new gpu_div_f64, which fails before it reaches the GPU:
"v_div_scale_f64 v[4:5], vcc, v[2:3], v[2:3], v[0:1]: VALU 64-bit". Run alone with XCL_DIRECT_DXIL=0, gpu_div_f64 passes in wave32 and wave64: all 512 pairs bit-exact against the CPU, denormal and special cases included. div_f64_translates passes.review: I read the whole diff. The HLSL side looks right to me. v_div_scale_f64 passes src0 through with VCC = 0, v_div_fmas_f64 is a plain fma (which is right with VCC = 0), and div_fixup_d falls back to the exact div_d wherever the skipped scaling would matter. And it holds bit for bit on RDNA 4. The test fails because the direct-DXIL translator has no v_div_scale_f64 / v_div_fmas_f64 / v_div_fixup_f64 (gpu/dxil/lower_wide.rs:1032, "VALU 64-bit"), and the GPU test runner doesn't fall back to HLSL. In a title, a shader the direct path rejects falls back to the HLSL path, so this code would be used there. But as it stands the PR puts a failing test into the suite on every GPU.
performance: only shaders that use these ops change, and they currently can't be translated at all; div_d / div_fixup_d are long, but they run only for f64 division. Not measured (Tier 1, no title run).
verdict: not yet: gpu_div_f64 fails on the default path (no direct-DXIL lowering of the three ops, lower_wide.rs:1032); either add it or have the test run the HLSL path. The HLSL fix itself is bit-exact on AMD RDNA 4 in wave32 and wave64
hardware / tool and model: AMD Radeon RX 9070 XT 16 GB (RDNA 4, driver 32.0.32015.2008), AMD Ryzen 7 9800X3D, 32 GB RAM, Windows 11 25H2 build 26200.9974, rustc 1.100.1 / Claude Code (Claude Opus 5.5)
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T04:12:45Z.
Triage (#1607) – head
66d8921No open or merged PR translates
v_div_scale_f64/v_div_fmas_f64/v_div_fixup_f64. Main handles only the f32/f16 forms, and #1144, #3023 and #3312 cover f32 div_fmas/div_fixup only. The approach mirrors the existing f32 path (no pre-scaling, VCC 0), withdiv_das the exact fallback where scaling would matter, and the GPU test checks every result bit-exact against the CPU division.Recommendation: keep open.
AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.