Recompiler: direct DXIL folds 64-bit and float constants #1913

Closed
nFaktorial wants to merge 1 commit from upstream-pr/1923 into main
nFaktorial commented 2026-11-24 23:21:47 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by nFaktorial on 2026-11-24T23:21:47Z.


The direct DXIL backend's optimizer (Module::optimize) skipped every i64 instruction, so that the Int64Ops flag set while building kept matching the code. The memory-window address math is i64 (zext, shl, or, add of an offset, lshr, trunc), and much of it has constant operands, so it reached the driver as written. Float literals also stayed as bitcast i32 <constant> to float instructions. Part of #1269.

i64 instructions are now folded and removed like 32-bit ones, and Shader::infer_type_features drops Int64Ops once no i64 instruction is left (the validator refuses the flag without one: "Flags must match usage"). Doubles are unchanged. A bitcast of a 32-bit constant becomes the constant of the other type, and fcmp of two float constants is decided at build time, except for denormals, which a driver may flush. A legacy multiply by a literal loses its "is the literal zero" compare.

On a retail shader pack, against main 689f2db (xcl shaders --direct --sample 3000 --seed 7 --split 1 --windows 4): DXIL 1.41 % smaller in total over 2 989 programs (median −1.30 %; 2 913 smaller, 58 up to 0.64 % larger). On a 292-program sample: 2.9 % fewer instructions (3 011 771 instead of 3 102 808 in the dxc -dumpbin listings), lines with an i64 101 495 instead of 153 220. A small, safe cut; it does not change the per-lane work or the EXEC guards.

What is in it

  • Recompiler: direct DXIL folds 64-bit and float constants
    • crates/xcl/src/gpu/dxil/module/opt.rs: i64 folding and dead-code removal (doubles excluded as before), float constant bitcasts and compares, a low_bits helper for 64-bit masks.
    • crates/xcl/src/gpu/dxil/shader.rs: infer_type_features removes Int64Ops when no i64 instruction remains.
    • crates/xcl/src/gpu/dxil/ops_tests.rs: constant_i64_and_float_operations_fold_away checks the listing (no i64 left, the literal's compare gone, the denormal's kept), the validator and the GPU results. Without the shader.rs change the validator rejects it ("Flags must match usage").
    • crates/xcl/src/gpu/dxil/kernel.rs: TRANSLATOR_VERSION 7 → 8 (the containers change).
    • Size: runtime +70/−20, test +58.

Tested

  • NVIDIA GeForce RTX 3070 8 GB (driver 610.88, 32-lane waves), AMD Ryzen 7 5800X, 16 GB RAM, Windows 11 26200, Rust 1.97.1 (MSVC 14.41), debug tests, release smoke and sweeps. Head df10025.
  • cargo test --workspace -- --test-threads=4 with the SDK's DXC 1.7.2308.16: 976 passed, 0 failed, 45 ignored; 88 SKIPPED, 65 of them the validation step (validator 1.7 < 1.8).
  • The same with XCL_DXC_DIR set to DXC 1.9.2602.17, so the DXIL tests run their validation step: 976 passed, 0 failed, 45 ignored; 23 SKIPPED: 18 no wave64, 3 per-lane f16 / V_CVT_F16_F32 refusals, no heap windows, and the PSO measurement (Developer Mode off).
  • xcl shaders --direct ... --validate over the 3 000-program sample: 0 validator failures (DXC 1.9.2602.17).
  • Retail title with XCL_DIRECT_DXIL=1, an earlier pair of 120 s runs of the same tree (main 689f2db against this change): both built the same three compute pipelines, with 3.2 %, 1.7 % and 1.9 % less DXIL here (80 520 → 77 928, 27 500 → 27 032, 38 888 → 38 168 B), 1 776 against 1 772 frames, no device removal or crash.

Regression run

main:

xcl-smoke v1
commit: 689f2db477c3c062cf162649781640ef8a977c18
gpu: NVIDIA GeForce RTX 3070
title: 6ca5cab7
seconds: 120
exit: 0x0
frames shown: 2859 (PresentX 2859)
presents per 2 s (last 3): 60 61 60
device removals: 0
crashes: 0
peak commit: 10069 MB

This PR:

xcl-smoke v1
commit: df10025244f64eb58d470a8910d3ed9a1433835e
gpu: NVIDIA GeForce RTX 3070
title: 6ca5cab7
seconds: 120
exit: 0x0
frames shown: 2922 (PresentX 2922)
presents per 2 s (last 3): 50 31 60
device removals: 0
crashes: 0
peak commit: 9794 MB

Both runs: XCL_DIRECT_DXIL=1 XCL_PSO_PRELOAD=0, A pressed every 4 s from 20 s, 120 s. In these two the title took the first A press only after 100 s, so they stay in its first menus (main built one compute pipeline, this branch none).

Not tested

  • Driver compile time (CreateComputePipelineState) of the smaller DXIL was not measured; the three title pipelines are too few to time.
  • AMD and wave64 hardware: the 32-lane-only RTX 3070 skips the native-wave64 tests (no wave64).
  • None of the runs gets past the title's menus (no Xbox Live sign-in): they build at most three compute pipelines through the direct backend, so the world load is not covered.

AI use

  • Claude Code (Claude Opus 5.5) found the pattern in the dumped DXIL, wrote the code and the test, ran the measurements, tests and smoke runs, and wrote this description.

🤖 Generated with Claude Code

<!-- greyfinch-sync:ivall/xcl:issue:6593422721 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1923). Originally posted by [nFaktorial](https://github.com/nFaktorial) on 2026-11-24T23:21:47Z. --- The direct DXIL backend's optimizer (`Module::optimize`) skipped every i64 instruction, so that the `Int64Ops` flag set while building kept matching the code. The memory-window address math is i64 (`zext`, `shl`, `or`, `add` of an offset, `lshr`, `trunc`), and much of it has constant operands, so it reached the driver as written. Float literals also stayed as `bitcast i32 <constant> to float` instructions. Part of #1269. i64 instructions are now folded and removed like 32-bit ones, and `Shader::infer_type_features` drops `Int64Ops` once no i64 instruction is left (the validator refuses the flag without one: "Flags must match usage"). Doubles are unchanged. A bitcast of a 32-bit constant becomes the constant of the other type, and `fcmp` of two float constants is decided at build time, except for denormals, which a driver may flush. A legacy multiply by a literal loses its "is the literal zero" compare. On a retail shader pack, against `main` `689f2db` (`xcl shaders --direct --sample 3000 --seed 7 --split 1 --windows 4`): DXIL **1.41 % smaller** in total over 2 989 programs (median −1.30 %; 2 913 smaller, 58 up to 0.64 % larger). On a 292-program sample: 2.9 % fewer instructions (3 011 771 instead of 3 102 808 in the `dxc -dumpbin` listings), lines with an i64 101 495 instead of 153 220. A small, safe cut; it does not change the per-lane work or the EXEC guards. **What is in it** - `Recompiler: direct DXIL folds 64-bit and float constants` - `crates/xcl/src/gpu/dxil/module/opt.rs`: i64 folding and dead-code removal (doubles excluded as before), float constant bitcasts and compares, a `low_bits` helper for 64-bit masks. - `crates/xcl/src/gpu/dxil/shader.rs`: `infer_type_features` removes `Int64Ops` when no i64 instruction remains. - `crates/xcl/src/gpu/dxil/ops_tests.rs`: `constant_i64_and_float_operations_fold_away` checks the listing (no i64 left, the literal's compare gone, the denormal's kept), the validator and the GPU results. Without the `shader.rs` change the validator rejects it ("Flags must match usage"). - `crates/xcl/src/gpu/dxil/kernel.rs`: `TRANSLATOR_VERSION` 7 → 8 (the containers change). - Size: runtime +70/−20, test +58. **Tested** - NVIDIA GeForce RTX 3070 8 GB (driver 610.88, 32-lane waves), AMD Ryzen 7 5800X, 16 GB RAM, Windows 11 26200, Rust 1.97.1 (MSVC 14.41), debug tests, release smoke and sweeps. Head `df10025`. - `cargo test --workspace -- --test-threads=4` with the SDK's DXC 1.7.2308.16: 976 passed, 0 failed, 45 ignored; 88 `SKIPPED`, 65 of them the validation step (validator 1.7 < 1.8). - The same with `XCL_DXC_DIR` set to DXC 1.9.2602.17, so the DXIL tests run their validation step: 976 passed, 0 failed, 45 ignored; 23 `SKIPPED`: 18 `no wave64`, 3 per-lane f16 / `V_CVT_F16_F32` refusals, `no heap windows`, and the PSO measurement (Developer Mode off). - `xcl shaders --direct ... --validate` over the 3 000-program sample: 0 validator failures (DXC 1.9.2602.17). - Retail title with `XCL_DIRECT_DXIL=1`, an earlier pair of 120 s runs of the same tree (`main` `689f2db` against this change): both built the same three compute pipelines, with 3.2 %, 1.7 % and 1.9 % less DXIL here (80 520 → 77 928, 27 500 → 27 032, 38 888 → 38 168 B), 1 776 against 1 772 frames, no device removal or crash. **Regression run** `main`: ``` xcl-smoke v1 commit: 689f2db477c3c062cf162649781640ef8a977c18 gpu: NVIDIA GeForce RTX 3070 title: 6ca5cab7 seconds: 120 exit: 0x0 frames shown: 2859 (PresentX 2859) presents per 2 s (last 3): 60 61 60 device removals: 0 crashes: 0 peak commit: 10069 MB ``` This PR: ``` xcl-smoke v1 commit: df10025244f64eb58d470a8910d3ed9a1433835e gpu: NVIDIA GeForce RTX 3070 title: 6ca5cab7 seconds: 120 exit: 0x0 frames shown: 2922 (PresentX 2922) presents per 2 s (last 3): 50 31 60 device removals: 0 crashes: 0 peak commit: 9794 MB ``` Both runs: `XCL_DIRECT_DXIL=1 XCL_PSO_PRELOAD=0`, A pressed every 4 s from 20 s, 120 s. In these two the title took the first A press only after 100 s, so they stay in its first menus (`main` built one compute pipeline, this branch none). **Not tested** - Driver compile time (`CreateComputePipelineState`) of the smaller DXIL was not measured; the three title pipelines are too few to time. - AMD and wave64 hardware: the 32-lane-only RTX 3070 skips the native-wave64 tests (`no wave64`). - None of the runs gets past the title's menus (no Xbox Live sign-in): they build at most three compute pipelines through the direct backend, so the world load is not covered. **AI use** - Claude Code (Claude Opus 5.5) found the pattern in the dumped DXIL, wrote the code and the test, ran the measurements, tests and smoke runs, and wrote this description. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
upstream-sync closed this pull request 2026-11-25 00:08:23 +00:00
upipibi commented 2026-11-25 00:08:54 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by upipibi on 2026-11-24T23:24:43Z.


NVIDIA run: RTX 3070 8 GB (Ampere, split wave64), driver 616.56, Windows 11, debug, df10025 merged onto main 689f2db (clean).

  • constant_i64_and_float_operations_fold_away: passes.
  • XCL_DIRECT_DXIL=1 cargo test -p xcl --lib -- gpu_ --skip gpu_sparse_vram --test-threads=4: 110 passed, 0 failed, 1 ignored, the same as main on this machine. That run also covers the memory-window i64 address math and the Int64Ops flag change (the validator accepted every program). The sparse test was skipped because of #1727.

Overlap with #1906 is proposed on #1607.

AI-assisted (Claude Code). Synthetic tests only.

<!-- greyfinch-sync:ivall/xcl:comment:7147368691 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1923#issuecomment-7147368691). Originally posted by [upipibi](https://github.com/upipibi) on 2026-11-24T23:24:43Z. --- NVIDIA run: RTX 3070 8 GB (Ampere, split wave64), driver 616.56, Windows 11, debug, `df10025` merged onto `main` `689f2db` (clean). - `constant_i64_and_float_operations_fold_away`: passes. - `XCL_DIRECT_DXIL=1 cargo test -p xcl --lib -- gpu_ --skip gpu_sparse_vram --test-threads=4`: 110 passed, 0 failed, 1 ignored, the same as `main` on this machine. That run also covers the memory-window i64 address math and the `Int64Ops` flag change (the validator accepted every program). The sparse test was skipped because of #1727. Overlap with #1906 is proposed on #1607. AI-assisted (Claude Code). Synthetic tests only.
DavidM1911 commented 2026-11-25 03:05:45 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T02:33:47Z.


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!

<!-- greyfinch-sync:ivall/xcl:comment:7150882841 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1923#issuecomment-7150882841). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-25T02:33:47Z. --- 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!

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!1913
No description provided.