Recompiler: simplify self-squared and constant factors in direct DXIL mul_legacy #2252
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2262"
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 ramon-victor on 2026-11-25T11:46:09Z.
Specializes
Lw::mul_legacy(loweringv_mul_legacy_f32, the most frequent instruction in retail console shaders) in the direct DXIL translator for self-squared operands (x * x), constant±0.0factors, and non-zero non-subnormal constant factors while preserving exact IEEE-754 / RDNA2 zero-override semantics.x * x(including identicalbitcast i32 -> f32wrappers and(-x) * (-x)): emits plainfmul(a, a)(1 op instead of 5), bit-identical for all2^{32}f32 values ((±0)^2 = +0.0,(±Inf)^2 = +Inf,NaN^2 = NaN).±0.0: folds directly to+0.0(0 ops instead of 5).fcmp oeq 0.0andorwhile keeping the other operand's zero check so e.g.2.0 * -0.0and+Inf * 0.0still yield+0.0(3 ops instead of 5).fmul(a, b).Part of #1269.
What is in it
crates/xcl/src/gpu/dxil/module.rs: addModule::const_f32_bits(resolving constantf32,bitcast i32 -> f32of integer constants, andfsub -0.0, kon non-subnormal/zero constants) andModule::same_f32(matching identicalbitcastwrappers emitted per operand byLw::fsrc).crates/xcl/src/gpu/dxil/prelude.rs: add self-square, constant-zero, and non-zero-constant fast paths toLw::mul_legacy, plusmul_legacy_fastpath_tests::gpu_direct_mul_legacy_fastpaths_validate_and_match_ieeechecking DXIL validation, disassembly (0/1fcmp oeqcounts), and GPU bit-exactness across+0.0,-0.0, finite,±Inf,qNaN, andsNaNinputs.On a seeded 600-program sample (
xcl shaders <archive> --direct --sample 600 --seed 3 --max-bytes 40000 --validate --threads 8, 573 programs within the cap), all 573/573 validate cleanly (0validator failures):41,323,736 B -> 41,147,056 B(-176,680 B,-0.43%)263.12 ms -> 250.88 ms(-4.7%)Tested
621.24, wave32), AMD Ryzen 7 5700X, Windows 11 Pro26300,rustc 1.99.0(x86_64-pc-windows-msvc), DXC/DXIL1.8.2502.11(Windows SDK10.0.26100.0).cargo test -p xcl --lib gpu::dxil::prelude::mul_legacy_fastpath_tests(debug):1 passed; 0 failed..\scripts\test.ps1(debug, full workspace on headb0c2efd):1251 passed; 0 failed; 46 ignored(25 GPU sub-checks skipped on this wave32 adapter: 21no wave64, 1no heap windows, 3 per-lane#1426refusals).cargo build --release -p xcl+ direct DXIL validation sweep on 573 sampled retail shader programs:573/573translated anddxil.dll-validated (0failures).Regression run
Not tested
XCL_SAMPLE_*env vars unset).AI use
const_f32_bits,same_f32, and themul_legacyfast paths, added validation/disassembly/GPU parity tests, rebased ontoorigin/main(1a0bbe3), and ran the workspace test suite, 573-shader benchmark, and 60 s smoke regression run.Imported from ivall/xcl. Originally posted by DarkPanda69 on 2026-11-25T12:35:58Z.
Update for head
b0c2efd(rebased ontomain1a0bbe3, tested as is): same result. The new test passes on both cards; wholegpu::filter: RX 9070 XT 630 passed, 2 failed (only the #2115 fuzz seeds now); RTX 3060 632 passed, 0 failed.The AMD native wave64 run listed as untested, plus an RTX 3060: the new test passes on both.
Head
2ae104ftested as is (it no longer applies cleanly on currentmain; its base is426a5a7), debug, Windows 11 Pro 26200,cargo test -p xcl --lib -- gpu:: --test-threads=4:gpu_direct_mul_legacy_fastpaths_validate_and_match_ieeeok. 627 passed, 3 failed, 22 ignored, 6 SKIPPED. All three failures also fail on the base without this PR: the AMD fuzz seeds tracked in #2115 andgpu_image_get_resinfo_past_last_level(fixed onmainsince).Not tested: the head rebased onto current
main, a title withXCL_DIRECT_DXIL=1.AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.
Imported from ivall/xcl. Originally posted by nnonno91 on 2026-11-25T15:28:14Z.
Independent Windows check of
b0c2efde0a9c3ba6e8e5a9476398bc556e7ee9f7. The legacy multiply shortcut cases matched the reference on Radeon integrated graphics and RTX 5090, including the upper half of a logical wave64.Tested
cargo test --locked -p xcl --lib mul_legacy_fastpath_tests -- --nocapture --test-threads=1on each selected adapter. The wave32 fixture reported 1 passed, 0 failed, 0 ignored, no logged skips per adapter.Not tested
Parent revision, performance, retail titles, or the full workspace suite.
AI use
OpenAI Codex (GPT-6.2 Sol) prepared and ran the tests, verified the results, and wrote this report.
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T16:53:33Z.
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 raylitebull on 2026-11-25T18:41:06Z.
Diff review, CI, and both AMD and NVIDIA checks passed on
b0c2efd, but recentorigin/mainmerges turned this branchCONFLICTING/DIRTY. Please rebase ontoorigin/mainso it becomes mergeable again.Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T07:41:53Z.
Triage (#1607) – head
b0c2efdNo open PR makes this change. Main's
prelude.rs::mul_legacy(#3269, behindrdna_float_enabled, on by default) already folds a constant zero factor. With one finite non-zero constant, main uses a plainfmuland skips the other operand's zero check. That gives -0.0 for2.0 * -0.0, wheremul_legacygives +0.0. This PR keeps that check. The self-square (same_f32) fast path is not on main. When you rebase, reconcile the constant branches with main's instead of adding a second set.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.