Recompiler: outline repeated direct-DXIL helpers into internal functions #3654
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3654"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ivall/xcl. Originally posted by Kalmarv on 2026-12-02T04:02:38Z.
What is in it
Outlines repeated direct-DXIL helper sequences into shared internal LLVM functions with inherited
BLOCKINFOfunction abbreviations, rebased directly ontomain(5eaadb54c) on top of#3655'sHelperBodyrepresentation (+968/-150across 10 files incrates/xcl/src/gpu/dxil/:+547/-143production code and+421/-7unit/DXC-validation tests). This PR is now independent of#3645(no longer stacked on it).BLOCKINFOfunction abbreviations and internal helper builders (module.rs,bitreader_tests.rs):#3655's existingHelperBody/FuncDecl.helper_bodyrepresentation (no duplicate struct or emission path).BLOCK_BLOCKINFO/BLOCKINFO_CODE_SETBIDfunction-block abbreviations once per module somainand every internal helper inherit the same abbreviations; updates the bitreader test helper to decode inheritedBLOCKINFOabbreviations.Op::CallOutput(reads a privateallocaslot written by a multi-word helper call) and internal helper builders for heap loads (xcl.sbuf.word,xcl.sbuf.word2,xcl.sbuf.word4,xcl.raw.word4), dynamic format decode (xcl.fmt.decode), legacy multiply (xcl.mul.legacy), word-resultfmad(xcl.fmad.words), and carried flat read windows (xcl.read.carry).kernel.rs,lower.rs,lower_mem.rs,lower_window.rs,prelude.rs,shader.rs):v_mul_legacy_f32, non-compute/compute word-resultfmad, and carried flat read windows through the shared internal helpers.fmt_encode,scalar_flat_read, andf16RNE rounding inline (dropping the overlapping#3650hunks andxcl.f16.rne— which also resolves the RTX 2070 SUPERgpu_s_round_mode_controls_f16_rounding_across_modesdriver failure — as well as the unrelatedballot_ps_quad/waterfallhunks).XCL_DXIL_OUTLINE=0(kernel::outline_enabled()) to keep all outlined helpers inline and appendsxcl-dxil-outline-0to the translator cache tag.module/opt.rs,module/split.rs):Op::CallOutputin operand traversal/rewriting and DCE, marksReadNonehelper bodieslane_local, and includes all four heap-load helpers (SCALAR_HEAP_WORD,SCALAR_HEAP_PAIR,SCALAR_HEAP_QUAD,RAW_HEAP_QUAD) in both DCEremovableand theflaggedraw-load preservation guard.infer_piece_featuresto inferFeature::ResourceHeapIndexingfor all four heap-load helpers and updatesdispatch_block_costto charge everyf.helper_bodyagainst piece instruction budgets.module.rs,module/opt.rs,module/split.rs,lower_mem.rs,bitreader_tests.rs):BLOCKINFOabbreviation inheritance,xcl.fmad.words,xcl.read.carry,xcl.mul.legacy,xcl.fmt.decode,xcl.sbuf.word*/xcl.raw.word4,SCALAR_HEAP_WORDDCE + flag preservation, split-piece feature inference and helper-body budget accounting, andXCL_DXIL_OUTLINE=0inline opt-out.+547/-143(with+421/-7in tests). TheBLOCKINFOabbreviations,Op::CallOutput/ helper builders, lowering call sites, DCE/split accounting, andXCL_DXIL_OUTLINE=0opt-out form one cohesive outlining change.Tested
rustc 1.99.0 (b940084d7 2026-09-28), DXC1.9.2609.5(debug + release).cargo build --release -p xcl: clean (39 warnings; 0 new warnings vsmain5eaadb54c).scripts/test.ps1(cargo build --workspace,cargo bench -p xcl --bench '*' -- --test,cargo test --workspace -- --test-threads=4, withXCL_DXC_DIRset to DXC1.9.2609.5): 2988 passed, 0 failed, 52 ignored across all 43 test targets (24SKIPPEDGPU tests on this adapter: 22no wave64, 2no heap windows; 0 DXC skips).gpu::recomp::tests::gpu_s_round_mode_controls_f16_rounding_across_modes,scalar_heap_word_is_dce_removable_and_preserves_raw_load_flag,piece_budget_counts_every_outlined_helper_body,piece_feature_inference_marks_resource_heap_indexing_for_all_heap_load_helpers, anddxil_outline_opt_out_keeps_helpers_inlineall passed with DXC1.9.2609.5.Regression run
Regression check only (both runs warm on the same title after an initial cache-warming run for the PR head, since changing
crates/xcl/src/gpu/dxil/*.rsand emitted bitcode bytes busts the translated and driver shader caches on the first cold run, which recorded 1004 frames with 0 removals / 0 crashes). No frame-rate or memory speedup is claimed from the smoke delta.Baseline (
main):PR head (warm):
Not tested
xcl.f16.rnehas been removed andgpu_s_round_mode_controls_f16_rounding_across_modespasses on RTX 5070 Ti).XCL_HEAP_WINDOWS=1GPU tests (2 skipped under defaultscripts/test.ps1).29440ec74.AI use
GPT-6) wrote the initial direct-DXIL helper-outlining changes.Gemini 4 Neon) rebased the change directly ontomain(5eaadb54c) atop#3655'sHelperBody, dropped the#3650-overlapping and unrelated hunks (includingxcl.f16.rne), addressed theopt.rs/split.rs/XCL_DXIL_OUTLINE=0review findings and added unit/DXC-validation tests, rancargo build --release -p xcl,scripts/test.ps1, and the 60 s smoke pair, and drafted this description.Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T08:45:19Z.
Review (head
03d8adeb, diff read, not a merge-check):HelperBodysetup inmodule.rs(~96, ~1430, ~1595, plus theValue::Funcwork-list in liveness) is nearly line for line the same as #3655's commitb995046b6, down to the comment "The entry is declared when the Shader is created, before any helper". Thexcl.f16.rnebody (module.rs~845) is the same RNE sequence that #3650 puts inline inf32_to_f16_rne. #3650 also reworks the dynamicfmt_pack/fmt_encodepath and the carried flat-read window, as this PR does withxcl.fmt.encodeandxcl.read.carry. Suggested split: (1) the helper infrastructure as one PR that both this and #3655 stack on, (2) the arithmetic helpers, (3) the heap-load helpers, (4) the format helpers. Each should leave out what #3650 already covers.lower_valu.rs~1345,lanes.rs~879), scalar liveness inwaterfall.rs~166/~330 is now computed lazily, andf32_to_f16_rneswaps the oldf32_to_f16_rm(f, 0)for a different algorithm (lower_wide.rs~708). By reading, the quad change and the new RNE sequence look equivalent to the old code, but each belongs in its own PR.dispatch_block_cost(module/split.rs~608) adds body sizes forxcl.sbuf.word,xcl.fmt.encodeandxcl.read.carryonly.xcl.f16.rne(21-instruction body; the old inline conversion was about 60) andxcl.mul.legacy(8) are not gated to whole entries, so split compute uses them too. Each call counts as one instruction. A piece heavy inv_cvt_f16_f32orv_mul_legacy_f32can then be several times overXCL_DIRECT_SPLIT_INSTRUCTIONSonce the driver inlines the helper. This contradicts the description's claim that split boundaries stay within budget, and the test (~768) covers onlyxcl.sbuf.word.define internalfunctions with arguments in non-library cs/ps DXIL are something DXC never emits. Here they includecreateHandleFromHeap/annotateHandleplus pointer out-arguments to entryallocas (xcl.sbuf.word2/4,xcl.raw.word4,lower_mem.rs~1289-1360). The evidence is the DXC validator and NVIDIA only. The maintainer's batch runs on AMD RDNA4, whose compiler this codebase already notes as sensitive (opt.rs~730,shader.rsllvm.ident). There is no switch to turn outlining off. Please add an AMD run or an opt-out. Also, the smoke run shows 12% fewer frames than main (1215 vs 1387, still over the 80% gate), which the description does not explain.flagged(opt.rs~1473) to the heap-load helpers. #3664 moves that block intoeliminate_dead. Whichever lands second must keep the helper names there, or a shader whose only raw loads are dead helper calls loses the load but keepsRawAndStructuredBuffers.Fine: function records mark helpers internal and non-proto. Bodies follow the entry in declaration order, as the LLVM 3.7 reader expects. BLOCKINFO abbreviations are defined before any local ones, so their IDs match.
CallOutputkeeps the call live and is neither CSE'd nor forwarded. Live types skip entry-only lookups for helper-local operands. Feature scans anduses_fmadknow the helper names. The helpers in this PR contain no wave, quad, derivative or barrier ops, so convergence and helper-lane behaviour inside them is unchanged.AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by Decodere on 2026-12-02T08:56:50Z.
Diff review (head
03d8adeb8, read-only code review — not a test report):Clean
BLOCKINFOshared-abbreviation encoding (crates/xcl/src/gpu/dxil/module.rs:1572-1581), solidCallOutputnon-CSE/non-forwarding design (opt.rs:523,:1555), andValue::Funcwork-list propagation for helper liveness (module.rs:1633-1666). Reading the full diff (+1677/-334across 17 files) turned up 3 concrete issues worth addressing before merge:SCALAR_HEAP_WORD(xcl.sbuf.word) is omitted fromopt.rsremovableand theflaggedraw-load guard (crates/xcl/src/gpu/dxil/module/opt.rs:526-534,:1473;crates/xcl/src/gpu/dxil/module.rs:81,:633-644):finish_heap_loadmarks 1-word scalar loadsFnAttrs::ReadOnly(module.rs:637-638), whereas multi-word loads (width > 1) useFnAttrs::NoUnwind(module.rs:641). Inremovable(opt.rs:528-533), helper calls are only removable whend.attrs == FnAttrs::ReadNoneord.namematchesSCALAR_HEAP_PAIR | SCALAR_HEAP_QUAD | RAW_HEAP_QUAD, and theReadOnlyfallback requires a"dx.op."prefix — so deadxcl.sbuf.wordcalls are never dead-code eliminated.flagged(opt.rs:1473) similarly omitsSCALAR_HEAP_WORD. AddingSCALAR_HEAP_WORDto bothremovableandflaggedenables DCE of dead 1-word outlined loads while still preservingRawAndStructuredBuffersvalidity when every raw load is dead.split.rsfeature inference and piece-budget accounting miss several outlined helpers (crates/xcl/src/gpu/dxil/module/split.rs:298-309,:608-624):split.rs:301-302checks onlySCALAR_HEAP_WORDforFeature::ResourceHeapIndexing, omittingSCALAR_HEAP_PAIR,SCALAR_HEAP_QUAD, andRAW_HEAP_QUAD(implicitly relying onwhole_entry_loadspreventing them in split pieces).dispatch_block_cost(split.rs:608-624) adds helper body instruction counts only forSCALAR_HEAP_WORD,FORMAT_ENCODER, andCARRIED_READ_WINDOW, omittingxcl.f16.rne(module.rs:845, 21 instructions) andxcl.mul.legacy(module.rs:811-812, 8 instructions), both of which are emitted in split compute shaders (lower_wide.rs:709-710,prelude.rs:233). Pieces heavy in half-conversion or legacy multiply count each call as 1 instruction instead of the inlined body size.Stacking, overlap with
#3645/#3650/#3655, and default-ON driver risk:bc4792159(+685/-154) embeds open PR#3645verbatim; commit03d8adeb8(+992/-180) also duplicates#3650's RNE half-conversion logic asxcl.f16.rne(module.rs:845), introduces a competingstruct HelperBody(module.rs:96-101) that conflicts with#3655, and bundles unrelatedballot_ps_quadEXEC masking (lower_valu.rs:1345,lanes.rs:879) and lazyscalar_live_in(waterfall.rs:166,:330).#3645and#3650, splitting sharedHelperBodyinfrastructure (shared with#3655) from the individual outlining passes, and adding an opt-out or AMD validation for default-ONdefine internalhelpers withallocaout-pointers will keep review and bisecting clean.AI use: Antigravity (Gemini 4 Neon) audited the full diff against
mainand drafted this review.Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T10:57:56Z.
merge-check
base:
1c8b551475head:
03d8adeb89merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2930 passed, 0 failed, 51 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on main); failing: none
review: read by one reviewer at this same head; the review is at https://github.com/xcl-dev/xcl/pull/3654#issuecomment-7339882618 and its findings stand. Most serious: its own commit is +992/-180 with no split, the split budget misses two new helpers, and outlining is on by default with no AMD run.
performance: 60 s smoke of a retail title, main
1c8b5514vs this merge (03d8adeb): 1652 -> 1434 frames shown (86 %; last presents per 2 s: 60 60 60), peak commit 18228 -> 16099 MB, 0 device removals, 0 crashes. This run is lower than most today: the PC was in use at the time (a browser and Discord running), and main's own runs on this machine today ranged from 1370 to 1652 frames, so the difference isn't clearly from this PR.verdict: not yet: its own commit is +992/-180 with no split, the split budget misses two new helpers, and outlining is on by default with no AMD run (see the review)
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5
AI-written and posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-02T14:33:19Z.
With this PR in,
main'sgpu_s_round_mode_controls_f16_rounding_across_modesfails on native Windows with an NVIDIA card: RTX 2070 SUPER 8 GB (driver 621.01), Windows 11 26200, debug, 1 run each.v_mul_f16under round-toward-zero gets the result of thev_pk_mul_f16high half next to it (0xFBFFwhere0x7BFFis expected).This was found on our integration branch, which carries this PR at
44e1860a, not onmainplus this PR alone. A first-parent bisect there passes at the commit before the merge (11d46940) and fails at the merge.The translated module looks right: disassembled, each
xcl.f16.rnecall takes its own product. With the f32→f16 round-to-nearest-even inline again (as #3650 writes it) and the other helpers still outlined, the test passes on the same PC. So it looks like the driver mixing up two calls of the outlined helper. That is a guess from the symptom, not shown.Not tested:
main+ this PR alone; AMD; other NVIDIA drivers.AI use: Claude Code (Claude Opus 5.5) ran the bisect and wrote this comment.
Imported from ivall/xcl. Originally posted by Kalmarv on 2026-12-02T15:46:56Z.
Rebased
#3654directly ontomain(5eaadb54c) as29440ec74(no longer stacked on#3645, and reusing#3655'sHelperBodydirectly) and addressed all points from@Foniass,@Decodere, and@Royalflamejlh:+2437/-482across 15 files ->+968/-150across 10 files;+547/-143production,+421/-7tests):xcl.f16.rne,fmt_encode, andscalar_flat_readedits so there is no overlap with#3650(insteadshared_scalar_wordstemporarily bindsuma_base_valto the helper'sbaseargument).xcl.f16.rnealso addresses@Royalflamejlh's RTX 2070 SUPER report ongpu_s_round_mode_controls_f16_rounding_across_modes, which passes inscripts/test.ps1here (not yet re-verified on RTX 2070 SUPER / driver 621.01).ballot_ps_quad/waterfallhunks (core_tests.rs,lanes.rs,lower_valu.rs,lower_wide.rs,waterfall.rsnow have zero diff).opt.rsDCE & raw-load flag guard (@Foniass): AddedSCALAR_HEAP_WORDalongsideSCALAR_HEAP_PAIR,SCALAR_HEAP_QUAD, andRAW_HEAP_QUADin bothremovableandflagged, covered byscalar_heap_word_is_dce_removable_and_preserves_raw_load_flag(validated with DXC1.9.2609.5).split.rsfeature inference & piece budgets (@Foniass): Updatedinfer_piece_featuresto inferFeature::ResourceHeapIndexingfor all four heap-load helpers and updateddispatch_block_costto charge everyf.helper_body(including#3655's helpers andxcl.mul.legacy) against piece budgets, covered bypiece_feature_inference_marks_resource_heap_indexing_for_all_heap_load_helpersandpiece_budget_counts_every_outlined_helper_body.@Decodere): AddedXCL_DXIL_OUTLINE=0(kernel::outline_enabled(), cache tagxcl-dxil-outline-0) to keep all outlined helpers inline, covered bydxil_outline_opt_out_keeps_helpers_inline.29440ec74(RTX 5070 Ti, driver 610.74, DXC1.9.2609.5):cargo build --release -p xcl: clean, 39 warnings (0 new vsmain5eaadb54c).scripts/test.ps1: 2988 passed, 0 failed, 52 ignored across 43 test targets (24SKIPPEDGPU tests: 22no wave64, 2no heap windows; 0 DXC skips;gpu_s_round_mode_controls_f16_rounding_across_modespassed;cargo bench -p xcl --bench '*' -- --testpassed).scripts/smoke.ps1regression check (title: ea3b5e4d):main5eaadb54c1640 frames (0 removals, 0 crashes, 17384 MB peak commit) vs29440ec74warm 1694 frames (0 removals, 0 crashes, 15177 MB peak commit; initial cold-cache compile run was 1004 frames, 0 removals, 0 crashes). Updated the PR description with bothxcl-smoke v1blocks and regression-only framing (AMD/Intel and RTX 2070 SUPER still untested).(Updated by Antigravity, Gemini 4 Neon, building on Codex, GPT-6's initial changes.)
Imported from ivall/xcl. Originally posted by Kalmarv on 2026-12-02T16:26:57Z.
Moving to Draft until we verify compatibility with AMD (
amdxc64.dll, #3694) and Linuxvkd3d-proton(dxil-spirv, #3707).In #3707, @lucsoft found that
dxil-spirvaborts (std::terminate()) on internal DXIL functions that take pointer parameters (Cannot reliably convert LLVM pointer type), and #3694 shows AMD's Windows compiler crashing (0xc0000409/0x887A0005) on #3655's internal@xcl.spin.wait/@xcl.barrier.arrivehelpers. This PR'sxcl.sbuf.word2,xcl.sbuf.word4, andxcl.raw.word4helpers currently pass privateallocai32*output pointers and emit internal DXIL functions as well, so it should not merge until we test whether value-only internal helpers (without pointer parameters) are accepted by bothamdxc64.dllanddxil-spirv— or drop internal functions if not.AI use: Antigravity (Gemini 4 Neon) cross-checked #3654 against #3694 and #3707 and drafted this note.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-03T03:43:12Z.
merge-check
base:
078358a058head:
29440ec740merge: clean
build: ok
tests: 3020 passed, 0 failed, 52 ignored; 28 skipped, the same as on main
review: 1 high, 4 medium (below)
performance: 60 s smoke run: 1669 → 1538 frames (92 % of main), peak commit 17577 → 15608 MB, no device removal, no crash
title run: retail title on the RTX 5070 Ti (driver 621.14), into the world by scripted presses: 24 s there, 0 device removals, 0 crashes, 9.2 presents/s; run with
XCL_SKIP_CS=95cc13288a27a96e(the NVIDIA hang at the end of loading, #3541) and NVIDIA's 2048 MB shader heap (#2590)verdict: not yet: 1 blocking finding (critical or high, below)
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5
In short: Moves repeated direct-DXIL sequences (heap scalar/raw loads, format decode, v_mul_legacy, word fmad, carried read window) into internal DXIL functions with shared BLOCKINFO abbreviations; on by default, with an XCL_DXIL_OUTLINE=0 opt-out. It now reuses #3655's HelperBody, drops the overlaps with #3650 and the unrelated hunks, and counts every helper in the split budget. It is blocked because it adds internal functions with pointer parameters on the default path, the construct #3707 removes because dxil-spirv aborts on it; it also conflicts with #3707 in code and in intent.
High
Medium
Checked and fine
How this was tested
078358a0, thencargo build --workspaceandcargo test --workspace --no-fail-fast -- --test-threads=4.scripts/smoke.ps1: 60 s of a retail title on main078358a0and on this merge; presents per 2 s at the end: 60 60 60.XCL_RUN_SECONDS=300and scripted A presses counted from the first frame (XCL_PRESS_BASE=frame, #3712) into the world from an existing save; time in the world is counted from the first in-world draw call to the end of the run.Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by Kalmarv on 2026-12-03T13:01:13Z.
Closing this PR as superseded by #3707 (
a815de932), which established the single-function non-library DXIL invariant viaModule::inline_helpers()for AMDamdxc64.dll(#3694) and Linuxvkd3d-proton(dxil-spirv) compatibility.Emitting internal DXIL helper functions (including pointer out-parameters) into non-library shaders conflicts with that invariant, while running
inline_helpers()erases the outlined functions. Thanks to@Foniass,@Decodere,@Royalflamejlh, and@lucsoftfor the reviews and cross-driver testing.Pull request closed