Recompiler: canonicalize split compute pieces and prune unused bindings (#2088) #2711
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!2711
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@ZekkJJ on GitHub · 2026-11-26 07:59 UTC · original
ZekkJJ:dxil/split-piece-canonicalize→main· +1179 −125 · 4 files · 1 commits · draftCanonicalizes 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.@Lum7nt on GitHub · 2026-11-26 09:03 UTC · original
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.@Prime1997 on GitHub · 2026-11-26 11:49 UTC · original · reviewed
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
@safesearch77 on GitHub · 2026-11-26 14:10 UTC · original
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.
@ZekkJJ on GitHub · 2026-11-26 14:31 UTC · original
@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.
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.