Repository navigation
Recompiler: direct DXIL decides compares of two float constants - #1943
Closed
nFaktorial wants to merge 2 commits into
Closed
nFaktorial wants to merge 2 commits into
nFaktorial wants to merge 2 commits into
Conversation
…direct DXIL Extend `gpu::dxil::module::opt` to fold remaining post-phi redundancies in direct-DXIL shaders without colliding with CFG-level folding or violating DXC validator shader-flag invariants: - Enable 64-bit integer constant/identity folding and DCE (`i64` arithmetic, shifts, `LShr(ZExt)` / `LShr(Or(ZExt, Shl(ZExt)))` window-high patterns, `Trunc(ZExt|SExt)`, and `i1` / `ZExt(i1)` compares) and clear `Feature::Int64Ops` in `Shader::infer_type_features` when no surviving instruction uses `i64`. - Fold finite constant `BitCast` (`i32 <-> f32`, `i16 <-> f16`, excluding NaN and Inf in both directions), reuse dominating `BitCast`s from CSE, collapse nested same-condition `Select` chains, and push `BitCast` through `Select` only when the `Select` has no surviving non-bitcast uses (preventing select duplication). - Canonicalize commutative integer binops (`Add`/`Mul`/`And`/`Or`/`Xor`) and integer `Cmp` predicates before dominator CSE, separate `XCL_DXIL_NO_OPT=fold` from `cse`, and expand flag-neutral `ReadNone` intrinsic DCE. - Bump `dxil::kernel::TRANSLATOR_VERSION` (7 -> 8) and add validator + RTX 4060 GPU execution parity tests. On a 252-program validated direct-DXIL corpus sample (100% across CS/GS/MS/PS/VS): -3.25% DXIL bytes (-397 KB, 252/252 shrank), -6.33% instructions, -28.74% bitcasts, -2.30% selects, -38.32% i64 ops, 0 validator errors (and 0 errors across 977 programs in a 1,000-record sample). Assisted-by: Google Antigravity (Gemini 4 Neon)
The direct translator keeps registers as i32, so a float literal reaches an fcmp as a bitcast of an integer constant. Once the optimizer folds that bitcast (#1906), the compare has two constants but stayed in the code. A legacy multiply by a literal kept its "is the literal zero" test that way. Module::optimize now decides fcmp of two 32-bit float constants at build time, for all ordered and unordered predicates, except where an operand is a denormal: a driver may flush it to zero. TRANSLATOR_VERSION goes to 9: the emitted containers change. Assisted-by: Claude Code (Claude Opus 5.5) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
|
CPU-only predicate matrix on exact head Tested
Not tested AI use |
Contributor
|
Verification on RTX 3060 Ti (Windows 11): merge conflict with current |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #1906; only the top commit (
bbd6dd0) belongs here. Part of #1269.The direct translator keeps registers as i32, so a float literal reaches an
fcmpas a bitcast of an integer constant. #1906 folds that bitcast, but the compare of two constants stays in the code, for example the "is the literal zero" test of every legacy multiply by a literal. This PR decidesfcmpof two 32-bit float constants at build time, for all ordered and unordered predicates, except where an operand is a denormal (a driver may flush it to zero). It replaces the float part of my #1923, which duplicated #1906.On a retail shader pack, against #1906's head
9ea9ad1(xcl shaders --direct --sample 3000 --seed 7 --split 1 --windows 4): DXIL 0.31 % smaller in total over 2 990 programs (2 335 smaller, none larger, 655 the same). In the first 400 of them (dxc -dumpbin): 142 469fcmpinstead of 148 570 (−4.1 %), 4 340 854 instructions instead of 4 359 046.What is in it
Recompiler: direct DXIL decides compares of two float constantscrates/xcl/src/gpu/dxil/module/opt.rs: anfcmparm insimplify_opand aconst_f32helper (a null float is +0).crates/xcl/src/gpu/dxil/ops_tests.rs:float_constant_compares_fold_awaychecks the listing (only the compare of a variable and the denormal's stay), the validator and the GPU results of a legacy multiply by 1.5 and five predicates on constants (−0 against +0 among them). It fails without theopt.rschange.crates/xcl/src/gpu/dxil/kernel.rs:TRANSLATOR_VERSION8 → 9.opt.rs, the version line), test +48.Tested
bbd6dd0(on Recompiler: fold 64-bit ints, bitcast selects and commutative CSE in direct DXIL #1906's9ea9ad1, basemain689f2db).cargo test --workspace -- --test-threads=4with the SDK's DXC 1.7.2308.16: 977 passed, 0 failed, 45 ignored; 89SKIPPED, 66 of them the validation step (validator 1.7 < 1.8), 18no wave64.XCL_DXC_DIRset to DXC 1.9.2602.17: 977 passed, 0 failed, 45 ignored; 23SKIPPED: 18no wave64, 3 per-lane f16 /V_CVT_F16_F32refusals,no heap windows, and the PSO measurement (Developer Mode off).xcl shaders --direct ... --validateover the 3 000-program sample: 0 validator failures (DXC 1.9.2602.17), on this branch and on Recompiler: fold 64-bit ints, bitcast selects and commutative CSE in direct DXIL #1906.Regression run
main:This PR:
Both runs:
XCL_DIRECT_DXIL=1 XCL_PSO_PRELOAD=0, A pressed every 4 s from 20 s, 120 s. Both built the same three compute pipelines through the direct backend: 80 520, 27 500 and 38 888 B of DXIL onmain, 74 008, 26 112 and 36 824 B with #1906 and this commit.Not tested
CreateComputePipelineState) of the smaller DXIL.no wave64).AI use
🤖 Generated with Claude Code