Recompiler: compile translated HLSL with strict IEEE float rules #3778
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3778"
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 Raul-Paiva on 2026-12-03T07:35:32Z.
Fixes two of the wave64 mismatches #3716's reference interpreter found on the HLSL path:
0 − (+0)giving −0, andinf − infgiving 0 instead of NaN.The cached DXC compiles of translated console programs (
dxc::compile_cached,compile_cached_in) passed DXC no arguments, so it compiled them with its default fast math. Fast math lets DXC fold0 - xto-xandx - xto 0:v_sub_f32 0, +0gave −0 (0x80000000), not +0;v_sub_f32 inf, infgave 0, not NaN.The console's VALU keeps both. The interpreter found them in the split wave64 form (CharlyRien's group 2: 94 seeds; the NaN class: 3 seeds), and the direct DXIL path and the per-lane form got them right on NVIDIA. These compiles now pass
-Gis(strict IEEE), like the tests that compare a form with the HLSL one already do. The arguments are part of their cache key, so DXIL compiled with fast math is not reused.-Gisis not enough on AMD. stijn-boer's RX 9060 XT run (DXC 1.9.2609.5) showed the DXIL given to the GPU keepsfsub float 0.000000e+00, %xandfsub float %x, %xwith no fast-math flags. Yet every lane still returned −0 and 0: the driver folds both again. So the second commit translates the forms a compiler can fold on sight differently. Av_sub_f32/v_subrev_f32with a constant zero source, or the same source twice, goes throughsub_ieee, the same subtraction with these results chosen on the bits with integer compares:No float rule can fold these compares away. Every other subtraction is emitted as before.
Related: #2168 (fast math losing −0 in f16 HLSL) and #105 (an audit that names
-Gis); #2183 kept the zero sign in f16 multiplies one at a time.The fuzz tables of #3716 and #3746 list "-0 for +0" on NVIDIA as a known outcome of the HLSL split form (and, in #3746, the HLSL wave32 form). With this change those outcomes should match, so whichever of these PRs lands second updates those entries.
What is in it
Recompiler: compile translated HLSL with strict IEEE float rules, incrates/xcl/src/gpu/recomp/dxc.rs:TRANSLATED_ARGS = ["-Gis"], passed bycompile_cached_inandcompile_generated_in;key_for_toolchainhashes those arguments into the DXIL cache key;gpu_translated_hlsl_keeps_signed_zero_and_nan(tests.rs).Recompiler: subtractions a driver can fold keep their zeros and NaN, incrates/xcl/src/gpu/recomp/emit.rs:sub_foldablepicks the forms;sub_ieeeis a new HLSL prelude helper;foldable_subtractions_go_through_sub_ieee, plus NaN − NaN, −0 − (−0) and 0 − 2.5 added to the GPU test.Tested
6010258f, onmain0c725d5d):gpu_translated_hlsl_keeps_signed_zero_and_nanruns on this GPU in wave32 and the split wave64 form, not skipped, and passes.foldable_subtractions_go_through_sub_ieeepasses. With the first commit'semit.rsit fails (assertion failed: one(("V_SUB_F32", "ENC_VOP2", &[("VDST", 10), ("SRC0", 128), ("VSRC1", 1)]))).-Gison the GPU test's program keepssub_ieee's integer compares and selects around eachfsub. It drops only the checks a constant +0 or the same operand makes trivial.cargo test --release -p xcl --lib gpu::recomp -- --test-threads=4: 537 passed, 0 failed, 21 ignored.gpu::dxil: 354 passed, 0 failed, 4 ignored. SKIPPED: all "no wave64" (21 ingpu::recomp, 1 ingpu::dxil).cargo test --release -p xcl --no-fail-fast --test '*' -- --test-threads=4):gpu_two_pass_cache_e2e::two_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobs("releasing the title PSOs releases their two-pass state", left 1, right 0), passed 2/2 when rerun alone on this head. That test does not reach the subtraction code.main0c725d5d: 151 passed, 0 failed, 20 ignored.0c725d5d(88e8c4fconmain16c2fd08): integration 151/0/20 on both trees;e2epassed 2/2 on both after one XAudio2 timing failure on the PR.main078358a0) against078358a0, run serially (--test-threads=1) with the 21 tests that end the binary skipped on both:main: 2820 passed, 13 failed, 32 ignored;list_x::a_reset_while_the_last_submit_runs_records_on_another_pc_list, passes alone 3/3 on both.-Gis, on 3b2f5877 against078358a0:xcl shaders <pack> --precompile --limit 1000withXCL_DIRECT_DXIL=0and a freshXCL_DXIL_CACHEeach run, two runs each, alternating:main, 79.7 and 80.3 s with it, within run-to-run noise;sub_ieeeadds a few integer operations to the subtractions it covers only.maina815de93):gpu_translated_hlsl_keeps_signed_zero_and_nan,foldable_subtractions_go_through_sub_ieeeand the DXC cache tests: 16 passed, 0 failed, no skips. Every lane of wave32 and split wave64 gives +0 for0 − (+0)and NaN forinf − inf; the first commit alone (88e8c4fc) gave −0 and 0 there.cargo test --workspace --no-fail-fast: 3005 passed, 18 failed, 56 ignored with this PR;main: 3003 passed, 18 failed, 56 ignored, the same failures.88e8c4fcpassed with DXC 1.9.2609.5 and 1.8.2502.8.Regression run
scripts/smoke.ps1 -Seconds 120 -Title 'retail title A', release builds of clean trees, one after the other on the machine in Tested, withXCL_DEVICE_TYPE=lockhart XCL_DIRECT_DXIL=1 XCL_HEAP_WINDOWS=1 XCL_WATCH_HOT=0 XCL_DRED=1 XCL_GPU_WAIT_TIMEOUT_MS=60000(XCL_DIRECT_DXIL=1keeps vertex and pixel shaders on the HLSL path this changes). The title is left on its own, with no input. Each tree had one warm-up run first.main:This PR:
Not tested
XCL_DIRECT_DXIL,lower.rs), which emitsfsubitself. Not checked on AMD, and not changed here.main; the test here covers these cases.xcl shaders --compile N(the compile-time sample,shaders.rscompile_samples) still callsdxc::compilewithoutTRANSLATED_ARGS, so its times are without-Gis. Left as it is.AI use
🤖 Generated with Claude Code
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-03T07:38:38Z.
Review of
88e8c4fc(code reading only, not a merge-check) · 2 nitsIn short: The PR compiles translated HLSL with DXC's
-Gis(strict IEEE), so0 - xno longer folds to-xandx - xno longer folds to 0. Av_sub_f32 0, +0now gives +0, andinf - infgives NaN, as on the console. The flag is part of the DXIL cache key, and a GPU test covers both waves. The change is small and right. Two nits; nothing blocks it.Nit
x − xgiving −0". The body and the test show0 − (+0)giving −0, andinf − infgiving 0 instead of NaN.EXPECTEDtables and fuzz classes list "-0 for +0" on the HLSL split and HLSL wave32 forms as known on NVIDIA. Once this lands, those outcomes become matches, and the pinnedKnownMismatchlines will need updating, depending on how the harness treats a known mismatch that went away. Whichever lands second should adjust them. Say so in the description.Checked and fine
TRANSLATED_ARGSgoes tocompilefromcompile_cached_inandcompile_generated_in, so every cached translated compile gets it.compilepassesextrathrough to bothcompile_wholeand the linked path (compile_linked, which compiles the library with the sameextra).key_for_toolchainhashes the arguments, so both the exact and the generated keys change and DXIL built with fast math is not reused. The HLSL path recompiles once, which the description says.compile_cached(SCALE_ARGS_HLSL, the mesh pass-through,rect_list_gs) also get-Gis, which is harmless for them.-Giscombines with the-O0/-O1choice for large sources.gpu_translated_hlsl_keeps_signed_zero_and_nanruns throughcompile_cached_inin wave32 and in the split wave64 form, checks all lanes, and fails without the change, as Tested says. The precompile timing shows no cost beyond noise, and DXIL grows 1.1 %.Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by Raul-Paiva on 2026-12-03T07:47:14Z.
Thanks. Both are fixed in the description:
0 − (+0)giving −0 (andinf − infgiving 0 instead of NaN).No code change, so the head (
88e8c4fc) and its smoke run stay as they are.The reply was posted by Claude Code (Claude Opus 5.5) on my behalf, and I reviewed it before it went out.
Imported from ivall/xcl. Originally posted by stijn-boer on 2026-12-03T08:00:13Z.
merge-check
base:
16c2fd082ahead:
88e8c4fc76verdict: not yet: the new translated-HLSL regression returned negative zero for zero minus positive zero on AMD in both focused runs.
Windows / AMD RDNA4 — first strict IEEE HLSL check on
88e8c4fThe PR fast-forwarded cleanly from
mainat16c2fd08.git diff --checkpassed. Both builds used separate Cargo target directories.Setup
AMD Radeon RX 9060 XT (driver 32.0.32029.2010), Ryzen 7 5700X, Windows 10 21H2 build 19044.6332, Rust 1.100.0 debug, Agility SDK 1.620.2 with matching debug layer, DXC 1.9.2609.5.
Tested
cargo build --workspacepassed on both.cargo test --workspace --no-fail-fast -- --test-threads=4 --show-outputexited 101 on both.SKIPPEDnoticesmainCounts are partial because the library and
gpu_compute_e2eexited0xc0000409on both builds. Both loggedfuzz_validate_and_gpu_3andtwo_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobsfailures. The additionalfuzz_validate_and_gpu_1failure on the PR also reproduced when run in isolation on base. Both debug-layer E2E tests and the texture-state check passed on both builds.cargo test -p xcl --lib gpu_translated_hlsl_keeps_signed_zero_and_nan -- --test-threads=1 --show-output --nocapturefailed twice with no skips. Wave32 lane 0 returned0x80000000for0 - (+0), expected0x00000000. The first assertion stopped both runs.cargo test -p xcl --lib gpu::recomp::dxc::cache_tests:: -- --test-threads=1 --show-output --nocaptureyielded 14 passed, 0 failed, 0 ignored, 0 skip notices.Diff review
The sampled runtime compile path passes
-Gisand includes that option in the cache key. The focused case still returned negative zero with that path on this configuration. The result does not identify whether the sign changed during translation, DXC optimization, or execution.Not tested
Remaining tests after the workspace aborts, later NaN and wave64 assertions after the signed-zero failure, and retail smoke (tier 1).
AI use
Codex (GPT-6) prepared the test builds, ran the tests, reviewed the diff, and drafted this report.
Imported from ivall/xcl. Originally posted by Raul-Paiva on 2026-12-03T09:23:43Z.
Thanks, that is a real finding. I looked at what DXC makes of the test's program,
v_sub_f32 v10, 0, v1, which translates toasfloat(0u) - asfloat(v1). This is with DXC 1.8.2502.11,cs_6_6,-Fc:mainbefore this PR):fsub fast float -0.000000e+00, %26. This is the fold the PR removes.-Gis(this PR):fsub float 0.000000e+00, %26. No fast-math flags, and the constant is +0.preciseon that line instead of-Gisgives the samefsub float 0.000000e+00, %26, so DXIL has nothing stricter to say.So on NVIDIA the DXIL the GPU gets is already strict, and the test passes. If DXC 1.9.2609.5 gives the same
fsub float 0.0, x, then your −0 comes from the AMD driver's own compiler folding0 - xto-xafter DXC. DXIL leaves the shader flagDisableMathRefactoringoff (no DXC option I know of sets it), so the driver may be allowed to do that. I cannot check it here: I have no AMD GPU.Two things would settle it, if you have time:
fsubline fromdxc -T cs_6_6 -E main -Gis -Fc out.llwith your DXC 1.9, on the test's HLSL (t.hlslin the test, beforecompile_cached_in).inf - inf(v11) and-0 - (+0)(v12) are right on your card. The test stops at the first assertion, so they were not reached.If it is the driver, a change to DXC's arguments cannot fix that
0 - xon AMD, and the test as written would fail on the maintainer's RDNA4 run. Then the PR needs either a translation ofv_sub_f32 0, xthat a driver cannot fold, or a narrower claim and test. I'd rather know which before changing it.The reply was posted by Claude Code (Claude Opus 5.5) on my behalf, and I reviewed it before it went out.
Imported from ivall/xcl. Originally posted by Gevroska on 2026-12-03T11:15:08Z.
@Raul-Paiva I checked the DXC
1.9.2609.5part of your question. In a separate disassembly probe using the three representative HLSL expressions,-Gispreserved all threefsuboperations withoutfast. The zero operand in+0.0 - xstayed positive. With default optimization, that expression becamefsub fast -0.0, x, andx - xfolded to a literal zero store.I also ran your unchanged GPU test on
88e8c4fcon my RTX 3080. With both DXC/DXIL1.9.2609.5and1.8.2502.8, all 32 wave32 lanes and all 64 split-wave64 lanes passed these assertions:0 - (+0)returned0x00000000.inf - infclassified as NaN.-0 - (+0)returned0x80000000.Both adapter controls and both shader runs passed with zero skips. That confirms the compiler output and all three GPU assertions on Ampere. I don’t have an AMD readback to determine where the reported negative zero is introduced on that adapter.
AI disclosure: OpenAI Codex GPT-6.2 Sol performed the compiler comparison and GPU tests. A separate GPT-6.2 Sol reviewer verified the evidence. GPT-6.2 Astra drafted this comment.
I reviewed and approved this comment before posting.
Imported from ivall/xcl. Originally posted by stijn-boer on 2026-12-03T11:48:49Z.
AMD retest of #3778 with #3707 and #3455
The signed-zero failure still reproduces, and the readback also shows
inf - infreturning zero. The exact DXIL passed to the GPU runner retains all three strict subtractions in both wave modes.Setup
AMD Radeon RX 9060 XT (driver 32.0.32029.2010), Ryzen 7 5700X, Windows 10 21H2 build 19044.6332, Rust 1.100.0, Agility SDK 1.620.2 with matching debug layer, and DXC/DXIL 1.9.2609.5.
main0c725d5da298b90797993b568e30e6ff6b16e8b6plus #37077b19e27dand #34551895d9e8, yielding local mergeb52925216.88e8c4fc766142152a5fd5e72d7ce2e878a77817, yielding local merge0b392c0d. The merges andgit diff --checkwere clean. The builds used separate Cargo target directories.Unchanged regression
cargo test -p xcl --lib gpu_translated_hlsl_keeps_signed_zero_and_nan -- --test-threads=1 --show-output --nocapturereported 0 passed, 1 failed, 0 ignored, 0 skips. Wave32 lane 0 returned0x80000000for0 - (+0), where the assertion expects0x00000000.AMD readback and exact DXIL
I reran the same command with temporary instrumentation that dumps the generated
t.hlsland cached compiler output and reports every lane instead of stopping at the first mismatch. One diagnostic execution completed with 0 skips. Every lane in each wave returned the same bits.0 - (+0)0x000000000x800000000x80000000inf - inf0x000000000x00000000-0 - (+0)0x800000000x800000000x80000000dxc -T cs_6_6 -E main -Gis -Fc out.llon the generated HLSL emitted the following v10 instructions.dxc -dumpbinon the actual blob given to the runner showed the same instructions.For v11, both strict blobs also kept the self-subtraction,
%35 = fsub float %34, %34in wave32 and%39 = fsub float %38, %38in split wave64. With default DXC options, the v10 instructions usedfsub fastwith a negative-zero operand, and the v11 self-subtraction disappeared. The two incorrect values arise after DXC emits strict DXIL. This is consistent with AMD driver optimization. The driver’s compiled shader was outside the scope of this run.Workspace comparison
cargo build --workspacepassed on both. Both runs ofcargo test --workspace --no-fail-fast -- --test-threads=4 --show-output --skip grooming_leaves_a_window_under_1_gib_only_its_holeexited 101. The same test was excluded from both after its subprocess stalled in the initial run.SKIPPEDlog noticesBoth debug-layer integration tests passed on both builds. Many workspace GPU tests reported Agility initialization failures or no GPU, including the new regression. The pass totals include those early returns. The AMD readback above is from the isolated test runs, which used the GPU successfully.
Not tested
Retail smoke and AMD driver machine code.
AI use
OpenAI Codex (GPT-6, exact variant unavailable) prepared the local test builds, ran the tests and diagnostic, and drafted this report.
Imported from ivall/xcl. Originally posted by Raul-Paiva on 2026-12-03T11:54:25Z.
Thanks, that settles the DXC half. With DXC 1.9.2609.5 and
-Gis,+0.0 - xstays a plainfsubwith a +0 operand, the same as with 1.8.2502.11 here. The test also passes on your RTX 3080 with both versions, so on NVIDIA what the GPU runs matches the DXIL.Edited: stijn-boer's AMD retest, posted a few minutes before this reply, answers the other half. The blob given to the runner keeps
fsub float 0.000000e+00, %xandfsub float %x, %x, and the RX 9060 XT still returns −0 for0 - (+0)and 0 forinf - infin every lane. So the AMD driver folds both after DXC, and-Gisalone cannot fix them there. I'm changing the translation of these two forms to something a driver cannot fold, and will post the new head with its results here.The reply was posted by Claude Code (Claude Opus 5.5) on my behalf, and I reviewed it before it went out.
Imported from ivall/xcl. Originally posted by Raul-Paiva on 2026-12-03T14:15:37Z.
Thanks for the AMD retest and the per-lane readback. They show the driver folds both forms after DXC, since the blob keeps
fsub float 0.000000e+00, %xandfsub float %x, %x. So-Gisalone could not fix them on your card.The new head
6010258f(rebased ontomain0c725d5d) adds a second commit for that. Av_sub_f32/v_subrev_f32with a constant zero source, or the same source twice, now goes throughsub_ieee. It is the same subtraction, but these results are chosen on the bits with integer compares, which no float rule can fold:Other subtractions are unchanged. DXC 1.8 with
-Giskeeps those compares and selects around eachfsub. The GPU test now also checks NaN − NaN, −0 − (−0) and 0 − 2.5.On my RTX 3070 Laptop the test passes in wave32 and split wave64. I have no AMD card, so whether your RX 9060 XT now gives +0 and NaN is still open. If you can run
gpu_translated_hlsl_keeps_signed_zero_and_nanon6010258f, that would settle it. The description has the rest: tests, the smoke run, and what is not covered, such as a zero reaching the subtraction through another register, and the direct DXIL path.The reply was posted by Claude Code (Claude Opus 5.5) on my behalf, and I reviewed it before it went out.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-03T14:16:53Z.
Follow-up review of
6010258f, since88e8c4fc(code reading only, not a merge-check) · 2 mediumIn short: The new commit
6010258fcovers the AMD case that-Gismissed. The driver folds0 - xandx - xagain even in DXIL that has no fast-math flags, so these forms now go throughsub_ieee, which works out the zeros and NaN with integer compares. The helper is right even if the driver still folds thefsubinside it. Both earlier nits are fixed. The commit has not yet run on the AMD GPU it targets, and the whole suite is not reported on this head.Medium
6010258f. The reasoning holds (see below), but the test that failed on AMD should be run there on this head before merging:gpu_translated_hlsl_keeps_signed_zero_and_nan, ideally with the suite.gpu::recompandgpu::dxiland the integration tests on6010258f. The whole lib suite ran only on the first commit one rebase earlier (3b2f5877). CONTRIBUTING.md asks forcargo test --workspace -- --test-threads=4on the head under review.Checked and fine
0 − (+0)giving −0, andinf − infgiving 0 instead of NaN.sub_ieeeholds even if the driver folds itsa - b, because every case a fold changes is replaced by aselecton the bits:ua & ~ub(−0 only for −0 − +0);abeforeb.0 - xwith nonzerox, orx - xwith finite nonzerox) has the same value folded or not.sub_foldablecompares the full source expressions, modifiers included, so|v| - |v|is covered, andv - (-v)(not foldable to 0) is not. A zero constant with anegmodifier is still caught on the raw source (0u/0x00000000u/0x80000000u).v_subrev_f32swaps the operands before the check and the call.foldable_subtractions_go_through_sub_ieeecovers both opcodes, VOP2 and VOP3, and the negative cases.main0c725d5dand this head, on the same title for 120 s.Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by stijn-boer on 2026-12-03T14:47:59Z.
merge-check
base:
a815de932chead:
6010258fb1merge: clean (local merge 9dda203562c5022a39dcc8bf7b1266674e7aa4e8; git diff --check clean)
build: cargo build --workspace passed on both trees
tests: the expanded AMD GPU regression passed without skips in wave32 and split wave64. The lowering check and all 14 DXC cache checks passed. Both filtered workspace runs exited 101 with the same 17 named failures and 18 total failures. No PR-only failure was observed.
review: the updated lowering routes constant-zero and same-source f32 subtracts through sub_ieee. The helper selects signed-zero and NaN results using integer bit tests, and the DXC flag is included in the translated cache key.
performance: outside this focused AMD recompiler retest
verdict: safe to merge: this head fixes both reproduced AMD GPU failures, and the same workspace failures appeared on main. The workspace runs had GPU skips, so the signed-zero and NaN result comes from the isolated GPU test.
hardware / tool and model: AMD Radeon RX 9060 XT (32.0.32029.2010), Ryzen 7 5700X, Windows 10 21H2 build 19044.6332 / OpenAI Codex (GPT-6, exact variant unavailable)
Focused AMD retest
On the prior head, the RX 9060 XT returned negative zero for
0 - (+0)and zero forinf - infin every tested lane. On6010258f, the unchanged test passed each assertion in all 32 wave32 lanes and all 64 split-wave64 lanes.0 - (+0)0x00000000inf - inf-0 - (+0)0x80000000NaN - NaN-0 - (-0)0x000000000 - 2.5-2.5Ran
cargo test -p xcl --lib <filter> -- --test-threads=1 --show-output --nocaptureforgpu_translated_hlsl_keeps_signed_zero_and_nan,foldable_subtractions_go_through_sub_ieee, andgpu::recomp::dxc::cache_tests::. The three runs reported 16 passed, 0 failed, 0 ignored, 0 skips in total. Used Rust 1.100.0, DXC/DXIL 1.9.2609.5, and Agility SDK 1.620.2 with the matching debug layer. Plain main already included #3707. No other PR was added.Workspace comparison
cargo test --workspace --no-fail-fast -- --test-threads=4 --show-output --skip grooming_leaves_a_window_under_1_gib_only_its_holeSKIPPEDlog noticesThe named failures matched across the library and two-pass driver-cache E2E. Both debug-layer E2E checks passed on both trees. The grooming test was filtered out on both because it previously stalled on this host. GPU skip notices can repeat in captured output, and libtest pass totals include early returns. The new GPU regression skipped during the workspace run and executed successfully in isolation.
Not tested: the filtered grooming case, retail smoke and performance on this AMD host, zero propagated through a different register, and the equivalent float cases on the direct DXIL backend.
AI use: OpenAI Codex (GPT-6, exact variant unavailable) prepared the test builds, ran the tests, compared the logs, and drafted this report.
Imported from ivall/xcl. Originally posted by Raul-Paiva on 2026-12-03T15:24:38Z.
Thanks for running it on the RX 9060 XT. It settles the AMD side: every lane now gives +0 and NaN, and the workspace run shows the same failures as
mainand none of its own. It also covers the whole suite on this head, which Foniass asked for.I've added your results to Tested, and the AMD line under Not tested is now only a retail title and frame times there.
The reply was posted by Claude Code (Claude Opus 5.5) on my behalf, and I reviewed it before it went out.
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.