Repository navigation
Conversation
|
A second NVIDIA generation: RTX 3070 8 GB (Ampere, 32-lane waves, split wave64), driver 616.56, Windows 11, debug,
Added 21:44Z: whole workspace at the current head AI-assisted (Claude Code, Claude Opus 5.5). Synthetic tests only. |
Melow-code
left a comment
There was a problem hiding this comment.
Fold logic is correct on the edges we checked: masks saturate at w=64 (the old AShr had a wrong shift count, fixed by the precalculated sx), free_bitcast excludes NaN/Inf both ways, bc_only pre-pass properly distinguishes bitcast-uses from other select arms, and the Int64Ops removal is paired with the DCE keep-list change.
Three points for the author to confirm:
- The BitCast alias key placed back in the CSE table in-place — a core test would pin this.
- Value id ordering as total order for canonicalize — harmless for CSE, worth noting.
- The new ReadNone DCE-able intrinsics (threadId, groupId, flattenedThreadIdInGroup) should get a validator run on a shader that uses them only in that context.
|
Thanks @upipibi for the RTX 3070 verification and @ruipedro-pinheiro for the thorough review! Confirming all three points on
Leaving AI use: Google Antigravity (Gemini 4 Neon) checked the line citations against |
…direct DXIL (xcl-dev#1906) 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)
9ea9ad1 to
d73513a
Compare
|
Updated CPU checks on rebased head Tested
Not tested Earlier report preserved below; its commit-specific results apply to the earlier head only. CPU-only integer optimizer checks on exact head Tested
Not tested AI use CPU validator follow-up1176dcc is a separate test-only commit on top of the companion above. Four serialized compute shaders cover a predeclared-but-unused i64 feature, constant i64 arithmetic, the high half of a zero-extended i32, and live i64 multiplication/high extraction. All pass SDK validator 1.9.2602.17; disassembly shows
This adds validator coverage only for those four serialized feature cases; the other limits above still apply. No GPU, retail execution or performance check. Codex (GPT-6; exact variant unavailable) prepared and ran this follow-up. |
|
Diff audit passed across Remaining before merge:
|
d73513a to
c640e80
Compare
|
@raylitebull Done — rebased cleanly onto AI use: Google Antigravity (Gemini 4 Neon). |
|
Rebased head Remaining before merge: one independent AMD GPU run confirming |
|
Tested Independent Intel Arc A770 validation of clean detached head Prebuilt outside the GPU lock with Ran the prebuilt executable in a fresh Windows PowerShell process with process-scoped & 'L:/XclTooling/Invoke-ArcTest.ps1' -Test {
& 'L:\XclTooling\verify-pr1523-1362129-t3-cf2e05e7\target\debug\build\xcl\97fdf2b9ff8e1482\out\xcl-97fdf2b9ff8e1482.exe' gpu::dxil::core_tests::opt_folds_i64_bitcast_selects_and_commutative_cse --exact --nocapture --test-threads=1
}1 passed, 0 failed, 0 ignored, 0 skipped (1,088 filtered out, 0.84 s). The native test and Arc wrapper each exited 0, and the lock was released. DXIL validation and disassembly checks passed for the synthetic shader and four-window loop, including the absence of the checked 64-bit integer requirement and constant bitcast instructions. On wave32, the synthetic direct-DXIL shader returned alternating PR #1906 was open at the tested head before and after the run. The only Arc report in the PR discussion at both checks covered the earlier Not tested Full DXIL or workspace suites, native or split wave64, release builds, other GPUs, retail smoke, and performance. AI use T3 Code / Codex ( |
c640e80 to
5ca498a
Compare
|
Rebased cleanly onto Re-verified locally on RTX 4060 (release): AI use: Google Antigravity (Gemini 4 Neon & Gemini 4 Carbon). |
|
Verification on RTX 3060 Ti (Windows 11), branch merged with current
Thanks! |
|
Independent AMD verification on RX 6750 XT, driver
A local stack of #1974 + #1946 + #1906 passed all four DXIL fuzz partitions: 2,000 validated, 1,232 GPU-compared, 0 mismatches. Not tested: full suite or retail title. AI use: OpenAI Codex (GPT-5) ran and analyzed the tests; I reviewed the results. |
5ca498a to
9f45961
Compare
|
Rebased onto
AI use: rebased, tested, and drafted with Google Antigravity (Gemini 4 Neon). |
Melow-code
left a comment
There was a problem hiding this comment.
Review: XCL PR #1906 — fold 64-bit ints, bitcast selects and commutative CSE in direct DXIL
Author: Decodere. opt.rs +277/-37, core_tests.rs +104, kernel.rs version bump, shader.rs flag inference. Fetch: git fetch xcl pull/1906/head:xcl1906 (base 689f2db).
Verdict: mergeable, with two points to confirm
The fold logic is correct everywhere I could find an edge:
- The width handling is sound: masks saturate at w=64 (
u64::MAXinstead of1u64 << 64), signed folding sign-extends by((x << (64-w)) as i64) >> (64-w)and takes the already-i64 value at w=64, and the oldAShrformula with a64 - w + yshift count (wrong for w=64) is replaced by the precomputedsx >> y. - The
LShr(ZExt)zero-fold and the window-high patternLShr(Or(ZExt(lo), Shl(ZExt(hi), sh)), sh) → hicarry their two preconditions: the shift must reach past the low part's width (sh >= sw), and the high part must not overflow the window (sw + sh <= w). Both are checked, and the check is mirrored for both operand orders of theOr. Correct. free_bitcastkeeps finite constants only: both directions filter(bits & 0x7FFF_FFFF) < 0x7F80_0000, which excludes NaN and Inf while letting −0.0 through (correct: its bit pattern is exact). Same mask logic for f16↔i16 at 0x7C00. Doubles are excluded entirely, consistent with keeping theDoubles/DoubleExtensionsshader flags untouched.- The
Select(c, t, select(c, _, f))collapse checks the resolved conditions against each other, and thebc_onlypre-pass is careful: aSelectcondition marks its value as having a non-bitcast use, arms of other same-condition selects are exempt (they die in the collapse), and everything else — including the select's own condition — disqualifies the in-place rewrite. The in-placeBitCast(Select) → Selectthen leaves the original(op, ty)in the CSE table so dominated bitcasts of the same select still hit it. Sound. - Removing
Int64Opswhen no i64 survives is paired with dropping i64 types from the DCE keep-list, so a module that folds its last i64 loses the flag and the dead ops both. Thew > 32guards becamew > 64, which is what makes the i64 folding legal at all. TRANSLATOR_VERSION7 → 8 invalidates every translation cache, which is required since modules re-fold.
The 977-program 0-validator-error claim plus the GPU parity tests on a 4060 is the strongest evidence available for this kind of change; the bisect switch (fold split from cse in XCL_DXIL_NO_OPT) is the right shape for a regression if one shows up.
Points to confirm (non-blocking)
simplify_bitcast_selectreplaces the instruction in place and keeps(op, ty)as a CSE alias key. If the select's own result is later bitcast again, the alias insert at the end of the loop writesrepl[i].unwrap_or(...)into the table under the bitcast key — verify that a dominatedBitCast(v, to)of the same select actually matches that key after the replacement (the key is(Op::Cast(BitCast, v, to), to), while the original bitcast key was(Op::Cast(BitCast, select_value, to), to); samevonly if the select itself is reused). One core test would pin this.canonicalize_commutativeswaps on Value id order (*b < *a). Values are reused numbers after earlier replacement rounds, so id order is a total order over live values — fine — but a constant operand always sorts against its creation id, soadd v10, 5canonicalizes toadd 5, v10only if 5's id is lower. Harmless for CSE correctness (both directions canonicalize the same way), just worth knowing when reading CSE hits.- The
ReadNoneDCE list now includesdx.op.threadId,dx.op.groupId.*anddx.op.flattenedThreadIdInGroup.*. Those are cheap and pure, so DCE is legal — but a shader whose only use was dead-code-eliminated still emits them if the entry block references them in metadata; worth one validator run on a shader that uses them and nothing else.
9f45961 to
9dbe28b
Compare
|
Rebased cleanly onto AI use: rebased, tested, and drafted with Google Antigravity (Gemini 4 Neon). |
9dbe28b to
74cf3a7
Compare
|
Rebased Re-verified |
…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. - Add validator + RTX 4060 GPU execution parity tests (direct-DXIL cache invalidation is automatic via `XCL_DIRECT_DXIL_SOURCE_ID`). 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)
74cf3a7 to
894e29d
Compare
bmjask
left a comment
There was a problem hiding this comment.
No concrete source-level defect found. i64 width/sign handling, finite bitcast folds, select/CSE dominance, and Int64Ops cleanup look correct; current Windows CI and RTX/Intel/AMD validation are strong. Residual gaps are no Direct-DXIL live title smoke and no native-wave64/heap-window run. I found no blocker.
|
@Decodere, a measurement and an offer for this PR, from work on the size of the DXIL we hand the NVIDIA driver (#1096). Bound DXIL over 802 compute programs a retail title (title: ea3b5e4d) has in use at its device-memory crash, translated offline with a release
The two passes run in
On the NVIDIA driver (RTX 5070 Ti, driver blob bytes), the select fold on its own, on main: −5.4 % native code over 4 of the largest of these programs (3.60 → 3.40 MB). The pair fold changes the DXIL only: on a synthetic chain of 512 Branch, two commits on this PR's head: https://github.com/Kalmarv/xcl/commits/op-diet/on-1906 (compare: Decodere/xcl@dxil-opt-post-phi...Kalmarv:xcl:op-diet/on-1906). Each commit has a GPU test that translates the same program with and without its pass and compares every VGPR of every lane and the SGPRs. If you want them, I can open that as a PR into your branch, or you can take them over with credit, whichever suits you. Tested: on an RTX 2060 (NVIDIA 595.91) under Wine 11.21 + vkd3d-proton, at AI use: Claude Code, Claude Opus 5.5 (code, tests, measurements, this comment). |
|
@Kalmarv Thanks for running the 802-program measurement on Since AI use: Google Antigravity (Gemini 4 Neon) reviewed this reply; |
Extends the direct-DXIL optimizer (
gpu::dxil::module::opt) to fold post-phi value redundancies that remain after initial lowering and trivial-phi elimination: 64-bit integer window/pack arithmetic, finite constantBitCasts, zero-duplicationbitcast(select(...))folding around VGPR float updates, nested same-conditionSelectchains, commutative integer ops and compares before dominator CSE, and expanded flag-neutral intrinsic DCE. Part of #1269.Because the DXIL validator verifies that shader feature flags match the emitted instructions,
f64instructions stay untouched,BitCastconstant folding excludes NaN and Inf in both directions, andShader::infer_type_featuresclearsFeature::Int64Opsafter optimization when no surviving instruction usesi64so folding away all 64-bit ops never failsFlags must match usage. Control-flow simplification stays in the existing#2194simplify_cfgpass (composing cleanly with post-mergef64-onlywideDCE) rather than adding terminator folding here.What is in it
crates/xcl/src/gpu/dxil/module/opt.rs:XCL_DXIL_NO_OPT=foldfromcsefor independent bisecting (XCL_DXIL_NO_OPT=phi,fold,cse,dce,mergeorall).i64arithmetic, shifts,LShr(ZExt)andLShr(Or(ZExt, Shl(ZExt)))window-high patterns,Trunc(ZExt|SExt),i1select/compare identities, andZExt(i1)compares), composing cleanly with#2279algebraic bitmask folds.BitCast(i32 <-> f32,i16 <-> f16, excluding NaN and Inf symmetrically), reuse dominatingBitCasts from CSE, collapse nested same-conditionSelectchains, and pushBitCastthroughSelectonly when theSelecthas no surviving non-bitcast uses (accounting for bypassed same-condition inner selects, so noSelectis duplicated) with scoped CSE alias registration.Add/Mul/And/Or/Xor) and integerCmppredicates before dominator CSE, and expand flag-neutralReadNonedx.op.*DCE.crates/xcl/src/gpu/dxil/shader.rs: clearFeature::Int64Opsininfer_type_features()when no surviving instruction usesi64.crates/xcl/src/gpu/dxil/core_tests.rs: addopt_folds_i64_bitcast_selects_and_commutative_csecoveringi64window-high +Int64Opscleanup, finite vs+InfconstantBitCasts,bitcast(select), nested selects, commutative CSE,zext(i1)compares, multi-window RDNA2 loop folding, DXC validation, and RTX 4060 GPU execution + HLSL parity.XCL_DIRECT_DXIL_SOURCE_ID(Recompiler: direct DXIL cache entries change when its sources do #1947), so no manualTRANSLATOR_VERSIONbump is needed.(Rebased onto
origin/main6d12f58ato integrate cleanly with#2173ीincore_tests.rsand#2279algebraic bitmask folds inopt.rs.)Tested
stable-x86_64-pc-windows-msvc), DXC 1.9.2609.5; release build.cargo test --release -p xcl --lib gpu::dxil::module::opt::tests -- --test-threads=1 --nocapture:7 passed, 0 failed, 0 ignored(0.00 s,0skipped) on both RTX 4060 and WARP (XCL_ADAPTER=warp), including#2194simplify_cfg_*and#2279algebraic bitmask fold tests.cargo test --release -p xcl --lib gpu::dxil::core_tests -- --test-threads=1 --nocapture:20 passed, 0 failed, 1 ignored(1.26 s,0skipped) on RTX 4060, including#2173,#2368flat-load tests, andopt_folds_i64_bitcast_selects_and_commutative_cse.XCL_ADAPTER=warp):opt_folds_i64_bitcast_selects_and_commutative_cse1 passed, 0 failed(0.02 s; DXC validation + disassembly checks ran; GPU parity portion cleanlySKIPPED: no wave32).cargo build --release --workspace+cargo test --release --workspace --no-fail-fast -- --test-threads=4 --nocapture:1424 passed, 0 failed, 46 ignoredacross37test binaries (184/184gpu::dxil::*passed,0failures).SKIPPEDGPU/runtime tests on this adapter (29lines):21no wave64subcases (RTX 4060 is 32-lane waves only)3intentional per-lane#1426refusals (V_MUL_F16,V_PK_MUL_F16,V_CVT_F16_F32) ingpu::recomp::lower_dxil::tests3D3D12 debug-layer tests (nod3d12SDKLayers.dll)1shaders::tests::pso_measurement_compiles_an_exact_synthetic_record(Windows Developer Mode required)1heap_window_out_of_memory_falls_back_to_the_switch_form(no heap windows)689f2db4vs this optimization pass on a 300-record seed-1 retail shader pack sample, 252/252 = 100.0% translated across 22 CS, 4 GS, 98 MS, 97 PS, 31 VS):0, panics:0, timeouts:0(also0errors across 977/977 translated programs in a 1,000-record--max-bytes 65536validated sweep, and0errors across 13/13 in a 20-record--validatecheck withXCL_DXIL_NO_OPT=fold).12,208,376 -> 11,811,244 B(-397,132 B,-3.25%; 252/252 shrank, 0 unchanged, 0 grew; per-shader median-3.35%, range-0.46%to-7.82%).1,683,483 -> 1,576,845(-106,638,-6.33%);bitcast:191,134 -> 136,196(-54,938,-28.74%);select:265,081 -> 258,991(-6,090,-2.30%);i64ops:79,848 -> 49,251(-30,597,-38.32%).2.1 s(main) vs1.9 s(PR).CreateComputePipelineStatecheck on 15 unique-hash retail direct-DXIL compute shaders (28–37 KB, alternatingmain/PRorder, verified cold vs0.5–1.1 mswarm 2nd calls):0driver errors.497,560 -> 480,904 B(-3.35%).3,037.9 ms -> 3,123.3 ms(+2.81%; 7 faster / 8 slower, median+1.70%, range-12.57%to+21.83%, within single-shot driver variance).Regression run
scripts/smoke.ps1onorigin/main(889ef3e8aa7f267323ab4879e735e65da6bcef10) and on this PR's head commit (894e29d63b3a668f5d04bb74a6cc88f06798805f):Not tested
XCL_DIRECT_DXIL=1enabled (the default smoke run above exercises the default HLSL runtime path; direct-DXIL coverage was verified via corpus DXC validation, cold RTX 4060 PSO creation, and direct-DXIL GPU execution parity tests).--release), and re-running the 252-program corpus/cold-PSO measurement after the#2194/#2180/#2279merge-conflict rebases.AI use
#2194/#2180/#2173/#2279rebases, and PR description; every line of the diff, test output, benchmark run, and smoke check was verified on local RTX 4060 hardware.