D3D12.X: add opt-in first-demand capture sidecar for Chain::whole fallbacks #2786
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!2786
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2786"
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?
@Decodere on GitHub · 2026-11-26 12:33 UTC · original
Decodere:feat-chain-whole-capture-sidecar→main· +1225 −15 · 4 files · 1 commits · openAdd an opt-in first-demand capture sidecar for
dispatch_chain::Chain::wholefallbacks (Step 1 of#2741). WhenXCL_CAPTURE_CHAIN_WHOLEis unset or whitespace-empty,dispatch_chain::buildskipsChainWholeMeta::new(capture_meta: Option<ChainWholeMeta>) and capture performs zero extra hashing, cache-key formatting, sampler allocation, I/O, thread spawning, DXGI queries, or locking; when set, each distinct final chain-ABI whole PSO demand is recorded in monotonic first-demand sequence order to a versioned UTF-8 JSONL sidecar strictly outsideChain::build_whole.Part of #2741
Part of #2088
What is in it
crates/xcl/src/hle/d3d12x/real/chain_whole_capture.rs: opt-in capture gated byXCL_CAPTURE_CHAIN_WHOLE=<path>and optionalXCL_CAPTURE_CHAIN_WHOLE_MAX=<u64>sequence cutoff (0= header only; disabled undercfg!(test)so tests never touch process env or user paths). Exposesenabled()(cachedOnceLockcheck) andbuild_meta_if(enabled, make)so disabled split-chain builds never constructChainWholeMeta. Serializes replay metadata only (no shader bytes or local paths) as versioned JSONL (schema_version: 1) on a dedicated background writer thread (xcl-chain-capture):kind: "header"):xcl_version,translator_source_id,direct_dxil_source_id,direct_dxil_translator_version,per_lane_source_id,chain_rs_abi_version(1),sequence_cutoff,captured_at_unix_ms, best-effort DXGIadapter(description, PCI IDs,is_software, UMDdriver_version),agility_runtime(status,version),dxc(dxcompiler/dxilversion/commit metadata without local directory paths), and effective 12-field computetranslation_options(direct_dxil,direct_compact,direct_compact_nest,per_lane,safe_barrier,heap_windows,split_wave64_forced,dispatch_piece_limit, plusdxil_no_optcanonical sorted subset of["cse","dce","merge","phi"]fromXCL_DXIL_NO_OPT,x64_all_masksfromXCL_X64_ALL_MASKS,wave64_spinfromXCL_WAVE64_SPIN, andrecomp_structuredfromXCL_RECOMP_NO_STRUCTURED, with backward-compatible serde defaults).kind: "demand"): 1-based monotonicseq,elapsed_ms,timestamp_unix_ms,present_count,reason,already_ready,source_record_hash,whole_dxil_hash,whole_dxil_len,effective_flags,node_mask,chain_rs_abi_version,chain_rs_id(FNV-1a 64 over ABI version and ordered static samplers), orderedstatic_samplers,disk_cache_name(driver_cache::name_for(..., true)), effectivemem_windows, andsplit_wave64.source_record_hash,whole_dxil_hash,whole_dxil_len,effective_flags,node_mask,chain_rs_abi_version,chain_rs_id) under a leaf mutex with non-blocking channel enqueue so line order matchesseqwithout disk I/O under lock; degrades silently with one warning on I/O errors.crates/xcl/src/hle/d3d12x/real/dispatch_chain.rs: storecapture_meta: Option<ChainWholeMeta>onChain, lazily constructed indispatch_chain::buildonly whenchain_whole_capture::enabled()is true; whenSome, record demand inChain::wholebefore checkingself.whole.get()or acquiringself.build_whole(capturing even when already ready); classify direct dispatch fallback reasons viaclassify_direct_fallback(BundlebeforeMissingRecordingAllocatorbeforeScratchUnavailable).crates/xcl/src/hle/d3d12x/bind.rs: passChainWholeReason::Indirectfromexecute_indirecttodispatch_chain::whole.crates/xcl/src/hle/d3d12x/real.rs: declarechain_whole_capture, pass effectivepso::mem_windows()andwave32_only(this)intodispatch_chain::build, and flush pending capture records inend_titlebefore suspending threads.chain_whole_capture::testsanddispatch_chain::tests):off_by_default_creates_no_file_and_no_io,captures_all_four_reasons_in_monotonic_sequence_order,deduplicates_first_demand_by_final_identity_and_keeps_distinct_identities_separate,records_demand_even_when_whole_pso_is_already_ready,sequence_cutoff_caps_distinct_demands_including_zero,chain_root_signature_identity_tracks_sampler_order_and_comparison,unwritable_target_path_fails_gracefully_without_panicking,disabled_capture_skips_metadata_construction_for_unset_and_empty_paths,translation_options_record_dxil_no_opt_and_extra_compute_switches,classify_direct_fallback_distinguishes_bundle_missing_allocator_and_scratch_unavailable,whole_capture_runs_outside_build_whole_lock, anddisabled_capture_path_skips_metadata_construction_and_on_demand_callback.Tested
rustc 1.100.0, DXC1.9.2609.5, debug (WARP) and release (RTX 4060).hle::d3d12x::real::chain_whole_capture::+hle::d3d12x::real::dispatch_chain::tests::, 12 new + 2 existing,--test-threads=1):XCL_ADAPTER=warp):14 passed, 0 failed, 0 ignored(0skipped;chain_whole_capture9/0/0in0.01 s,dispatch_chain5/0/0in0.52 s).14 passed, 0 failed, 0 ignored(0skipped;chain_whole_capture9/0/0in0.01 s,dispatch_chain5/0/0in0.63 s).hle::d3d12x::real::+hle::d3d12x::bind::,--test-threads=4):80 passed, 0 failed, 0 ignored(0skipped;real72in0.78 s,bind8in0.31 s).cargo clippy --workspace --all-targets:0warnings and0errors inchain_whole_capture.rs, and0new warnings or errors across all added/changed lines indispatch_chain.rs,bind.rs, andreal.rs(3 pre-existingmainclippy::approx_constanterrors remain in untouchedlower_valu.rs,lower_wide.rs, andrecomp/lower.rs).cargo test --release --workspace --no-fail-fast -- --test-threads=4:1447 passed, 0 failed, 47 ignoredacross 37 targets (xcl --lib:1321 passed, 0 failed, 27 ignoredin15.91 s;29SKIPPEDlines whose optional env vars or sample packs were unset).title: 29640639withXCL_CAPTURE_CHAIN_WHOLE,XCL_CAPTURE_CHAIN_WHOLE_MAX=64, andXCL_DIRECT_DXIL=1:1577frames (PresentX 1577),60 60 60presents/2 s,0device removals,0crashes,13969 MBpeak commit (exit: 0x0);end_titlecleanly flushed a 984-byte UTF-8 LF JSONL sidecar containing theschema_version: 1header with live RTX 4060 adapter/driver (32.0.16.2114), DXC (1.9.2609.5), and all 12 effectivetranslation_optionsfields (direct_dxil: true,dxil_no_opt: [],x64_all_masks: false,wave64_spin: true,recomp_structured: true, plus the original 8 fields;0demand lines because this title split0compute programs during the 60 s run).Regression run
Default-flags quiet 60 s
scripts/smoke.ps1runs ontitle: 29640639(XCL_CAPTURE_CHAIN_WHOLEunset):main:
PR:
Not tested
Chain::wholefallbacks (title: 29640639reported0 programs splitduring the 60 s run; demand emission, deduplication, cutoff, all fourChainWholeReasonvalues, disabled-path gating, 12-fieldtranslation_optionscapture, and off-build_whole-lock ordering are verified via deterministic unit/D3D12 tests).#2741Part 2 / Steps 2-4).agility_runtime.status == "loaded").#[ignore]workspace tests and 29SKIPPEDoptional-env/sample-pack tests.AI use
chain_whole_capturesidecar, disabled-path metadata gating, 12-fieldTranslationOptionsMetacapture,ChainWholeReasonplumbing, and 12 unit tests againstorigin/main(b49be183), ran clippy, debug WARP and release RTX 4060 test suites, and quiet 60 s smokes, and drafted this PR description.@thehollowedone on GitHub · 2026-11-26 12:50 UTC · original
Independent review and focused Windows check of head
7587c013againstmainb49be18. I checked both paths in the exact-head source.The disabled capture path still does work on every successful split-chain build.
dispatch_chain::buildconstructsChainWholeMetabefore it checks whetherXCL_CAPTURE_CHAIN_WHOLEis set. The constructor scanswholetwice (fnv64directly and throughdriver_cache::name_for), allocates the cache name, copies static samplers, and retains them. This occurs even if noChain::wholefallback follows. The title smoke in the description split zero programs, so it cannot measure this path. Could metadata construction be gated on the cached capture setting, with an off/empty-setting regression that verifies the constructor is never called? I have not measured the time cost.The sidecar omits an option that changes the whole DXIL.
current_translation_optionsdoes not recordXCL_DXIL_NO_OPT. The split compute path callsoptimize(), which reads that variable to skipphi,cse,dce, ormerge. For example, disabling DCE can produce different whole DXIL while the recorded translation options remain identical. The digest would reveal a mismatch, but a later replay could not reproduce the setting from this sidecar. Could the header record the effective disabled passes, with a default-versus-dcemetadata regression? Other existing translator switches are worth checking before freezing schema version 1.Small candidate diff shape
enabled()can read the existing cached configuration. The explicit capture-session test would constructSome(meta); the default path should constructNone. Add the effectiveXCL_DXIL_NO_OPTvalue toTranslationOptionsMetaseparately.Tested: Windows 11 build 26300, RTX 3080 Ti / driver 621.35, Ryzen 7 9800X3D, rustc 1.99.1 MSVC, DXC 1.8.2502.11, signed D3D12 Agility 1.620.2.
cargo test --offline --locked -p xcl --lib hle::d3d12x::real::chain_whole_capture:: -- --test-threads=1: 7 passed, 0 failed, 0 ignored. The same command withhle::d3d12x::real::dispatch_chain::tests::: 4 passed, 0 failed, 0 ignored; the D3D12 lock-order test ran with no GPU skip. The full debug workspace run was stopped after four GPU tests remained running for over a minute with no further output; it produced no final counts. No retail fallback capture was run on this machine.AI use: Codex (GPT-6.2 Sol) inspected the exact-head source, ran the focused tests, and drafted this review. I verified the two points against the code before posting.
7587c01324to3b6609fbbe@afpruivo on GitHub · 2026-11-26 13:26 UTC · original · edited 2026-11-26 13:45 UTC
Tested
3b6609fb(and earlier7587c013) on an RTX 3090 with a retail title that does reachChain::whole. At3b6609fb, 480 s gave 247 demand records, and 220 of them match a whole-form driver build in the log by record hash and whole-DXIL size. This fills the "live retail title" item under Not tested.Setup
title: 3c290c16).mainb49be18+ this PR. 480 s withXCL_DIRECT_DXIL=1 XCL_DRED=1 XCL_CAPTURE_CHAIN_WHOLE=<path>, scripted A presses.xcl.exewas in a 2 GiB shader-heap profile (#2590). Each run starts from the same XCL cache state (the files a run adds are moved aside afterwards).Results at
3b6609fbcargo test --release -p xcl --lib -- hle::d3d12x::real::chain_whole_capture:: hle::d3d12x::real::dispatch_chain::: 14 passed, 0 failed, 0 ignored.0x0, 2,121 frames, no device removal, no crash, peak commit 40,501 MB. World start (#101) at 82.5 s. 287 programs split.E:(the title's drive isG:): no overlay redirect this time.translation_optionsnow carriesdxil_no_opt: [],x64_all_masks: false,wave64_spin: true,recomp_structured: true.seq1–247 with no gaps, 247 distinct identities. Reasons: 225indirect, 22missing_recording_allocator.driver compile startfor the same record hash with the same whole-DXIL size.Repeat: the two runs (
7587c013, then3b6609fb, same cache state) captured 223 and 247 whole forms, with 213 in both, 10 only in the first and 34 only in the second. So one run's capture covers most, but not all, of what the next run needs. Merging several captures may be worth it for part 2.Results at
7587c013(the first run): 11 of 11 tests passed. 480 s gave 223 demands (220indirect, 3missing_recording_allocator), 216 matched to driver builds, exit0x0, 2,078 frames, peak commit 39,039 MB.Notes from the first run, both answered above by @Decodere:
G:\…the file ended up under%LOCALAPPDATA%\XCL\<package>\overlay\…. A path outside the title's drives works, as this run shows.elapsed_mscounts from the first demand, not from the start of the run.Not tested:
XCL_CAPTURE_CHAIN_WHOLE_MAX; thebundleandscratch_unavailablereasons in a title; the cost of the disabled path; AMD;nvidia-dev, where this PR conflicts.AI use: Claude Code (Claude Opus 5.5) read the diff, ran the builds, the tests and both runs on my machine, matched the sidecars against the logs, and drafted this. Checked by me before posting.
@Decodere on GitHub · 2026-11-26 13:30 UTC · original
Updated in
3b6609fb.@thehollowedone — Thanks for the review; both points are addressed in
3b6609fb:Chain::capture_metais nowOption<ChainWholeMeta>, constructed indispatch_chain::buildviachain_whole_capture::build_meta_if(chain_whole_capture::enabled(), || ChainWholeMeta::new(...))(reading the cachedOnceLockconfig), andChain::whole_withskipson_demandwhenNone. Covered bydisabled_capture_skips_metadata_construction_for_unset_and_empty_pathsanddisabled_capture_path_skips_metadata_construction_and_on_demand_callback.translation_options: Auditedpso.rs::cache_allowedandgpu/{dxil,recomp}and added the 4 missing non-pixel compute translator switches toTranslationOptionsMeta:dxil_no_opt(normalized fromXCL_DXIL_NO_OPT),x64_all_masks(XCL_X64_ALL_MASKS),wave64_spin(XCL_WAVE64_SPIN), andrecomp_structured(XCL_RECOMP_NO_STRUCTURED), with serde defaults for compatibility. Covered bytranslation_options_record_dxil_no_opt_and_extra_compute_switchesand verified in a live 60 s RTX 4060 capture header (984bytes, UTF-8 LF JSONL).Re-verified on
3b6609fbwith debug WARP (14/0/0), release RTX 4060 targeted (14/0/0) +real::/bind::(80/0/0),0new clippy warnings across the 4 modified files, full release workspace (1447 passed, 0 failed, 47 ignored), and quiet 60 s default (1536frames,60 60 60,14019 MB,0rem/crash) + live capture (1577frames,60 60 60,13969 MB) smokes.@afpruivo — Huge thanks for testing live demand capture on RTX 3090 (
223gapless records /216matched whole-form builds /0missingChain::wholebuilds!). Both operational notes make sense:CreateFilepath, so pointingXCL_CAPTURE_CHAIN_WHOLEat a host path outside the mounted drive avoids overlay redirection.elapsed_mscurrently anchors at first demand while Part 2 replay orders strictly byseq.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.