Recompiler: canonicalize split compute pieces and prune unused bindings (#2088) #2701
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2711"
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 ZekkJJ on 2026-11-26T07:59:50Z.
Canonicalizes DXIL bitcode emission and prunes statically unused resource bindings on split compute dispatch-chain pieces so semantically identical pieces share identical DXIL containers and driver cache keys.
Part of #2088.
What is in it
crates/xcl/src/gpu/dxil/module.rs: deterministic canonical bitcode emission (Module::try_to_canonical_bitcode,BitcodePlan,PlanWalker) scoped to split compute pieces without altering unsplit compute or graphics bitcode.crates/xcl/src/gpu/dxil/shader.rs:Shader::finish_optimized_canonicalandShader::prune_unused_bindings.crates/xcl/src/gpu/dxil/module/split.rsandcrates/xcl/src/gpu/dxil/graphics_tests.rs: piece-local static binding pruning inmake_pieceplus determinism, dynamic indexing,Phi/undef, NaN/-0.0, and GPU parity tests.Tested
32.0.16.1656),rustc 1.98.1.cargo build --locked --workspace -j 2: passed (0errors).cargo test --locked -j 2 -p xcl --lib gpu::dxil:: -- --test-threads=1:189 passed; 0 failed; 3 ignored(34.89s;SKIPPED gpu::dxil::kernel::dispatch_chain_native_wave64_builds_whole: no wave64, ignoreddump_dxc_lowering,amd_reduced_seeds,debug_seed).cargo test --locked -j 2 -p xcl --test gpu_compute_e2e -- --test-threads=1:7 passed; 0 failed; 0 ignored(8.05s;SKIPPED heap_window_out_of_memory_falls_back_to_the_switch_form: no heap windows).cargo test --locked -j 2 -p xcl --test e2e -- --test-threads=1:4 passed; 0 failed; 0 ignored(11.89s).git diff --check b49be183..dfead370: passed (0errors).b49be183vsdfead370, 28 compute units / 50 split pieces / 33 unique PSOs, 3 alternating trials per arm):0validation failures across all trials; total serialized piece DXIL dropped from6,353,292 Bto6,238,132 B(-1.81%).90pieces ->32unique PSO builds,58cache hits,0validation failures) and 30 captured compute units (52pieces ->35unique PSO builds,17cache hits,0validation failures).Regression run
scripts/smoke.ps1execution on an unpacked retail build and full non-DXIL workspace test sweep before marking ready for review.Not tested
cargo test --workspaceondfead370(DXIL library,gpu_compute_e2e, ande2everified above), pairedscripts/smoke.ps1(no retail title directory on this machine), AMD / Intel hardware, Linux / Wine.AI use
Gemini); assisted with implementation, tests, benchmark validation, and PR preparation under author direction.Imported from ivall/xcl. Originally posted by Lum7nt on 2026-11-26T09:03:05Z.
Tested on \
dfead3702a\ (\dfead370, clean PR head):ustc 1.100.0\ (\x86_64-pc-windows-msvc), DXC \1.8.2502.11\ (Windows SDK \10.0.26100.0), debug profile, \XCL_ADAPTER=nvidia.
o wave64, 3 per-lane #1426\ refusals, 2 no D3D12 debug layer, 1 \cannot disable the driver cache (0x887A002D), 1
o heap windows.
Not tested
AI use
dfead370, ran \gpu::dxil::\ and the workspace suite on this machine, and drafted this report.Imported from ivall/xcl. Originally posted by Prime1997 on 2026-11-26T11:49:48Z.
Review: COMMENTED
Read-through and GPU run of
dfead370. An AI tool (Claude Code) helped with the reading and ran the tests; each point below was checked against the code at this head.Test results (RTX 3060 Ti 8 GB, NVIDIA 617.14 / 32.0.16.1714, i5-10400, Windows 11 26200.9974, rustc 1.100.0, DXC 1.9.2609.5, debug, isolated cache and data roots):
cargo test --lib gpu::dxil:: -- --test-threads=4: 189 passed, 0 failed, 3 ignored. One test reported SKIPPED (dispatch_chain_native_wave64_builds_whole, this card has no wave64). The GPU halves of the tests ran.Points for the author
.chain.psoname does not include the root signature or static samplers, and pruning now makes the pieces sampler-agnostic. I could not confirm how a driver reacts when a cached blob made under one sampler set is offered to a pipeline with another. If the answer is "it refuses and we rebuild", that is fine, but it would be good to have a test that shows it, or the sampler set in the name.expect()calls. As far as I can tell a panic there comes back as anErrfrom the translator thread'sjoinrather than taking the process down, but returning the error directly would be clearer.I did not find a defect. The reach looks narrow (only programs that are actually split), so points 1 and 3 are what I would want answered before this leaves draft.
Generated by Claude Code
Imported from ivall/xcl. Originally posted by safesearch77 on 2026-11-26T14:10:05Z.
Reviewed
dfead370againstmain(b49be183). Non-split bitcode preservation (BitcodePlan::unsplit)and the
referenced_bindings/PSV0renumbering check out, with a few concrete catches:Feature::TiledResourcesleaks from piece 0 into downstream pieces, andinfer_piece_featuresstill runs before
dst.m.optimize()(split.rs:270-303).Shader::dispatch_piece(shader.rs:169) clonesself.featuresinto every piece, andinfer_piece_features(split.rs:284-303) stripsDoubles,Int64Ops,DoubleExtensions,ResourceHeapIndexing,SamplerHeapIndexing, andTypedUavLoadAdditionalFormats, but neverclears
Feature::TiledResources(1 << 12indx.entryPointsflags,0x100inSFI0),which
clamp_arg(ops.rs:882) sets on anySample/SampleBias/SampleGrad/SampleCmpwith
Some(min_lod).sample_grad(..., Some(min_lod))) and adownstream piece does not,
prune_unused_bindingsremoves the texture and sampler bindings fromthe downstream piece while leaving
TiledResources(0x100) set in itsSFI0and entry flags —so two shaders with identical downstream pieces still emit different containers (
SFI00x4100vs
0x4000, differentdriver_cache::name_forkeys) and claimTiledResourceson a piece withno texture bindings.
make_pieceinlineddst.m.optimize()(split.rs:277) belowdst.infer_piece_features()(
split.rs:270), andinfer_piece_featureswalks all ofself.m.instsrather than reachableblocks (
block_layout().0), so acreateHandleFromHeapor UAVtextureLoadeliminated bydst.m.optimize()still leaves its feature flag set on the piece. Runninginfer_piece_featuresafter
dst.m.optimize()over reachable blocks and clearingTiledResourceswhen no survivingcall uses a clamp/status fixes both.
Two vacuous assertions in
canonical_bitcode_drops_unreachable_phi_operands_and_distinguishes_undef(
split.rs:1443, 1469-1490).use_undefcomparess.raw_store(out, off, &[merged])(1 dword, write mask1) againsts.raw_store(out, off, &[merged, zero])(2 dwords, write mask3).Shader::raw_store(
shader.rs:363-375) always passesi32 undefforoffset1and unused value lanes, sodisassemble(&clean_undef).unwrap().contains("undef")is true forclean_zeroas well, andassert_ne!(clean_zero, clean_undef)passes because the write mask differs (i8 1vsi8 3),not because
undefwas distinguished from0(passing&[merged, undef_i32]vs&[merged, zero]keeps mask
3on both).!dis.contains("-1158620499") && !dis.contains("3134250669")for0xBAD0_DEAD(line 1443), whose signed
i32decimal is-1160716627(0xBAD0_DEADu32 as i32;-1158620499is
0xBAF0_DAAD), so DXC disassembly would never match either string on a leak.Cleanup / scope nits:
println!("CANON_PIECE1 ...")atsplit.rs:1279-1287, and the test namegraphics_bitcode_canonicalizes_unused_decls_and_preserves_resources(graphics_tests.rs:1241)still says
canonicalizesafter narrowing graphics back toBitcodePlan::unsplit.+1,179/-125(1,304changed lines, over the ~800-line guideline inCONTRIBUTING.md),splitting
BitcodePlancanonical bitcode emission andreferenced_bindings+prune_unused_bindingsinto a 2-PR stack would make each piece much smaller to review.
Checked with
cargo check --tests(x86_64-pc-windows-gnu) and a host-siderustc --testharness ongpu/dxil(reproducingSFI00x4100vs0x4000); no Windows DXC validator or GPU run.AI use: Antigravity (Claude Sonnet 5.5, Gemini 4 Carbon) audited the diff and ran the host reproduction;
I re-checked each point against the source before posting.
Imported from ivall/xcl. Originally posted by ZekkJJ on 2026-11-26T14:31:14Z.
@safesearch77 @Prime1997 Thanks for the detailed findings. Feature inference after optimization, TiledResources canonicalization, sampler cache identity and the test assertions need addressing before this leaves draft.
Imported from ivall/xcl. Originally posted by bielfreedom on 2026-11-26T17:22:36Z.
AMD Windows data for #2711: on an RX 9070 XT the whole programs are unchanged, and the split pieces get about 2 % smaller. Over 26 large retail compute programs, no two pieces became identical. The pipeline count stays at 76, and AMD's driver time is the same or slightly lower.
Setup
xcl shadersthat writes every program's DXIL size and everyCreateComputePipelineStatetime to a file:mainb49be18;dfead37merged onto it.xcl shaders <retail shaders.rpf> --precompile --only cs [--pipelines]withXCL_DIRECT_DXIL=1, switch windows,XCL_PSO_DISK_CACHE=0, one driver thread, and a fresh translation cache and exe name per run, so every build is cold.Results
main, as the description says.mainmain's first round is the outlier. On the second round the two are 2 % apart, so I would not claim a driver gain from this set. The cache-key sharing the PR is after does not show up here, because none of these pieces became identical.Not tested: heap windows, GPU output, and a title run.
AI use: Claude Code (Claude Opus 5.5) built the binaries, ran the measurements and wrote this report; I posted it.
Imported from ivall/xcl. Originally posted by JJAutoCompare on 2026-11-27T00:27:46Z.
Tested:
dfead3702a1e8c3b6b30afeccf51efc1e885b10b, Windows 11 build 26200.9974, Ryzen 7 3800X, Intel Arc A770 driver 32.0.101.9175, Rust 1.100.0 MSVC, DXC/DXIL 1.9.2602.17, debug.cargo test --locked -j 2 -p xcl --lib --no-run, then the checked-ingpu::dxil::module::opt::testsand split optimization filters: 11 CPU passes. The canonical fixture produced three pieces per variant with matching downstream bytes and matching 2,184-byte tail containers. Three Arc passes in separate exact invocations ofcanonical_pieces_preserve_dynamic_indexing_and_match_gpu,dispatch_chain_divergent_forward_edges_3d, andwave64_metadata_dynamic_bindings_and_split_static_samplers_stay_valid. Whole/split readbacks matched, including 384/768 result words and 16 guards in the 3D cases. Zero failures, ignores or skips.Not tested: Native wave64, retail smoke, workspace suite, and corpus-level size or performance.
AI use: T3 Code / Codex (
gpt-6.2-sol) ran and reran the checks and wrote the report.Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T08:46:41Z.
Triage (#1607) – head
dfead37Half of this PR is now on main. Commit
2b39525("Recompiler: prune unused split-piece resource bindings") addedModule::referenced_bindings,Shader::prune_unused_bindingsand themake_piececall afteroptimize(), which conflicts with this diff. Main keeps the survivors in their original order. This PR also sortsbindings.The canonical bitcode writer is not on main, and no other open PR does it:
try_to_canonical_bitcode,BitcodePlan,finish_optimized_canonical. That part still stands. It needs a rebase that drops the duplicated pruning. At about 1180 lines it is also well over the size limit.Recommendation: keep open.
AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.