Skip to content

Recompiler: simplify self-squared and constant factors in direct DXIL mul_legacy - #2262

Open
ramon-victor wants to merge 1 commit into
xcl-dev:mainfrom
ramon-victor:opt/dxil-mul-legacy-fastpath
Open

ramon-victor wants to merge 1 commit into
xcl-dev:mainfrom
ramon-victor:opt/dxil-mul-legacy-fastpath

Conversation

@ramon-victor

@ramon-victor ramon-victor commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Specializes Lw::mul_legacy (lowering v_mul_legacy_f32, the most frequent instruction in retail console shaders) in the direct DXIL translator for self-squared operands (x * x), constant ±0.0 factors, and non-zero non-subnormal constant factors while preserving exact IEEE-754 / RDNA2 zero-override semantics.

  • x * x (including identical bitcast i32 -> f32 wrappers and (-x) * (-x)): emits plain fmul(a, a) (1 op instead of 5), bit-identical for all $2^{32}$ f32 values ((±0)^2 = +0.0, (±Inf)^2 = +Inf, NaN^2 = NaN).
  • Either operand is constant ±0.0: folds directly to +0.0 (0 ops instead of 5).
  • One operand is a non-zero non-subnormal constant (normal, Inf, or NaN; exponent bits non-zero so FTZ cannot turn it into zero): skips that operand's fcmp oeq 0.0 and or while keeping the other operand's zero check so e.g. 2.0 * -0.0 and +Inf * 0.0 still yield +0.0 (3 ops instead of 5).
  • Both operands are non-zero non-subnormal constants: emits plain fmul(a, b).

Part of #1269.

What is in it

  • crates/xcl/src/gpu/dxil/module.rs: add Module::const_f32_bits (resolving constant f32, bitcast i32 -> f32 of integer constants, and fsub -0.0, k on non-subnormal/zero constants) and Module::same_f32 (matching identical bitcast wrappers emitted per operand by Lw::fsrc).
  • crates/xcl/src/gpu/dxil/prelude.rs: add self-square, constant-zero, and non-zero-constant fast paths to Lw::mul_legacy, plus mul_legacy_fastpath_tests::gpu_direct_mul_legacy_fastpaths_validate_and_match_ieee checking DXIL validation, disassembly (0/1 fcmp oeq counts), and GPU bit-exactness across +0.0, -0.0, finite, ±Inf, qNaN, and sNaN inputs.

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 (0 validator failures):

  • Total emitted DXIL: 41,323,736 B -> 41,147,056 B (-176,680 B, -0.43%)
  • Translation time p95: 263.12 ms -> 250.88 ms (-4.7%)

Tested

  • Hardware and toolchain: NVIDIA GeForce RTX 3070 (8 GiB, driver 621.24, wave32), AMD Ryzen 7 5700X, Windows 11 Pro 26300, rustc 1.99.0 (x86_64-pc-windows-msvc), DXC/DXIL 1.8.2502.11 (Windows SDK 10.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 head b0c2efd): 1251 passed; 0 failed; 46 ignored (25 GPU sub-checks skipped on this wave32 adapter: 21 no wave64, 1 no heap windows, 3 per-lane #1426 refusals).
  • cargo build --release -p xcl + direct DXIL validation sweep on 573 sampled retail shader programs: 573/573 translated and dxil.dll-validated (0 failures).

Regression run

xcl-smoke v1
commit: f087b998d0d51a9f11bbfa0761967a63e778edd9
gpu: NVIDIA GeForce RTX 3070
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1618 (PresentX 1618)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14467 MB
xcl-smoke v1
commit: b0c2efde0a9c3ba6e8e5a9476398bc556e7ee9f7
gpu: NVIDIA GeForce RTX 3070
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1623 (PresentX 1623)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14448 MB

Not tested

  • Native wave64 GPU hardware (AMD/Intel): RTX 3070 only supports wave32, so native wave64 tests skip on this adapter.
  • Sample-gated tests (XCL_SAMPLE_* env vars unset).

AI use

  • Antigravity (Gemini 4 Neon): designed and implemented const_f32_bits, same_f32, and the mul_legacy fast paths, added validation/disassembly/GPU parity tests, rebased onto origin/main (1a0bbe3), and ran the workspace test suite, 573-shader benchmark, and 60 s smoke regression run.

@DarkPanda69

DarkPanda69 commented Nov 25, 2026 •

Copy link
Copy Markdown

Update for head b0c2efd (rebased onto main 1a0bbe3, tested as is): same result. The new test passes on both cards; whole gpu:: 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 2ae104f tested as is (it no longer applies cleanly on current main; its base is 426a5a7), debug, Windows 11 Pro 26200, cargo test -p xcl --lib -- gpu:: --test-threads=4:

Not tested: the head rebased onto current main, a title with XCL_DIRECT_DXIL=1.
AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.

@ramon-victor
ramon-victor force-pushed the opt/dxil-mul-legacy-fastpath branch from 2ae104f to b0c2efd Compare November 25, 2026 12:38
@throny throny added the goal:world-load Bears on the retail title getting past world loading label Nov 25, 2026
@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

Thanks!

@raylitebull

Copy link
Copy Markdown
Member

Diff review, CI, and both AMD and NVIDIA checks passed on b0c2efd, but recent origin/main merges turned this branch CONFLICTING/DIRTY. Please rebase onto origin/main so it becomes mergeable again.

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Triage (#1607) – head b0c2efd

No open PR makes this change. Main's prelude.rs::mul_legacy (#3269, behind rdna_float_enabled, on by default) already folds a constant zero factor. With one finite non-zero constant, main uses a plain fmul and skips the other operand's zero check. That gives -0.0 for 2.0 * -0.0, where mul_legacy gives +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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

goal:world-load Bears on the retail title getting past world loading

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants