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

Open
github-bot wants to merge 1 commit from github-bot/gh-2262 into main AGit
Owner

@⁠ramon-victor on GitHub · 2026-11-25 11:46 UTC · original
ramon-victor:opt/dxil-mul-legacy-fastpath → main · +154 −4 · 2 files · 1 commits · open

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.
**@⁠ramon-victor** on GitHub · 2026-11-25 11:46 UTC · [original](https://github.com/xcl-dev/xcl/pull/2262) `ramon-victor:opt/dxil-mul-legacy-fastpath` → `main` · +154 −4 · 2 files · 1 commits · open 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:24:59 +00:00
Author
Owner

@⁠DarkPanda69 on GitHub · 2026-11-25 12:35 UTC · original · edited 2026-11-25 13:00 UTC

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:

  • RX 9070 XT (RDNA4, driver 32.0.32029.2010, waves 32..64): gpu_direct_mul_legacy_fastpaths_validate_and_match_ieee ok. 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 and gpu_image_get_resinfo_past_last_level (fixed on main since).
  • RTX 3060 (driver 32.0.16.1088): the new test ok; 630 passed, 0 failed, 22 ignored.

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.

**@⁠DarkPanda69** on GitHub · 2026-11-25 12:35 UTC · [original](https://github.com/xcl-dev/xcl/pull/2262#issuecomment-7162595873) · edited 2026-11-25 13:00 UTC **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`: - **RX 9070 XT** (RDNA4, driver 32.0.32029.2010, waves 32..64): `gpu_direct_mul_legacy_fastpaths_validate_and_match_ieee` ok. 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 and `gpu_image_get_resinfo_past_last_level` (fixed on `main` since). - **RTX 3060** (driver 32.0.16.1088): the new test ok; 630 passed, 0 failed, 22 ignored. 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.
Author
Owner

@⁠nnonno91 on GitHub · 2026-11-25 15:28 UTC · original

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

  • Windows 11 25H2 (26200.9974), Ryzen 7 9800X3D, Radeon integrated graphics (32.0.21042.62), RTX 5090 (32.0.16.1742), Rust 1.100.0 x64 MSVC, Windows SDK DXC/DXIL 1.8.2502.11. Unoptimized test profile.
  • Clean head, cargo test --locked -p xcl --lib mul_legacy_fastpath_tests -- --nocapture --test-threads=1 on each selected adapter. The wave32 fixture reported 1 passed, 0 failed, 0 ignored, no logged skips per adapter.
  • Same command with a temporary fixture-only wave64 variant. It initialized and checked all 64 lanes with the existing inputs and five operations, including positive and negative zero, infinities, and NaNs. Logs confirmed native wave64 on Radeon and split wave64 on RTX 5090. Both reported 1 passed, 0 failed, 0 ignored, no logged skips. DXIL validation and disassembly assertions also passed, and the clean worktree was restored.

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.

**@⁠nnonno91** on GitHub · 2026-11-25 15:28 UTC · [original](https://github.com/xcl-dev/xcl/pull/2262#issuecomment-7166891931) 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** - Windows 11 25H2 (26200.9974), Ryzen 7 9800X3D, Radeon integrated graphics (32.0.21042.62), RTX 5090 (32.0.16.1742), Rust 1.100.0 x64 MSVC, Windows SDK DXC/DXIL 1.8.2502.11. Unoptimized test profile. - Clean head, `cargo test --locked -p xcl --lib mul_legacy_fastpath_tests -- --nocapture --test-threads=1` on each selected adapter. The wave32 fixture reported 1 passed, 0 failed, 0 ignored, no logged skips per adapter. - Same command with a temporary fixture-only wave64 variant. It initialized and checked all 64 lanes with the existing inputs and five operations, including positive and negative zero, infinities, and NaNs. Logs confirmed native wave64 on Radeon and split wave64 on RTX 5090. Both reported 1 passed, 0 failed, 0 ignored, no logged skips. DXIL validation and disassembly assertions also passed, and the clean worktree was restored. **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.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-25 16:53 UTC · original

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!

**@⁠DavidM1911** on GitHub · 2026-11-25 16:53 UTC · [original](https://github.com/xcl-dev/xcl/pull/2262#issuecomment-7168689272) 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!
Author
Owner

@⁠raylitebull on GitHub · 2026-11-25 18:41 UTC · original

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.

**@⁠raylitebull** on GitHub · 2026-11-25 18:41 UTC · [original](https://github.com/xcl-dev/xcl/pull/2262#issuecomment-7171250258) 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.
This pull request has changes conflicting with the target branch.
  • crates/xcl/src/gpu/dxil/prelude.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2262/head:github-bot/gh-2262'
git switch 'github-bot/gh-2262'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2262'
git switch 'github-bot/gh-2262'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2262'
git switch 'github-bot/gh-2262'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2262'
git switch 'main'
git merge --squash 'github-bot/gh-2262'
git switch 'main'
git merge --ff-only 'github-bot/gh-2262'
git switch 'main'
git merge 'github-bot/gh-2262'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.