Skip to content

Recompiler: canonicalize split compute pieces and prune unused bindings (#2088) - #2711

Draft
ZekkJJ wants to merge 1 commit into
xcl-dev:mainfrom
ZekkJJ:dxil/split-piece-canonicalize
Draft

ZekkJJ wants to merge 1 commit into
xcl-dev:mainfrom
ZekkJJ:dxil/split-piece-canonicalize

Conversation

@ZekkJJ

@ZekkJJ ZekkJJ commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

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_canonical and Shader::prune_unused_bindings.
  • crates/xcl/src/gpu/dxil/module/split.rs and crates/xcl/src/gpu/dxil/graphics_tests.rs: piece-local static binding pruning in make_piece plus determinism, dynamic indexing, Phi/undef, NaN/-0.0, and GPU parity tests.

Tested

  • Hardware: Windows 11, AMD Ryzen 7 8845HS, NVIDIA GeForce RTX 4060 Laptop GPU (driver 32.0.16.1656), rustc 1.98.1.
  • cargo build --locked --workspace -j 2: passed (0 errors).
  • 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, ignored dump_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 (0 errors).
  • Offline direct-DXIL compute corpus benchmark (b49be183 vs dfead370, 28 compute units / 50 split pieces / 33 unique PSOs, 3 alternating trials per arm): 0 validation failures across all trials; total serialized piece DXIL dropped from 6,353,292 B to 6,238,132 B (-1.81%).
  • Offline corpus runs on RTX 4060: 30 RDNA2-family compute units (90 pieces -> 32 unique PSO builds, 58 cache hits, 0 validation failures) and 30 captured compute units (52 pieces -> 35 unique PSO builds, 17 cache hits, 0 validation failures).

Regression run

  • Draft PR pending paired scripts/smoke.ps1 execution on an unpacked retail build and full non-DXIL workspace test sweep before marking ready for review.

Not tested

  • Full cargo test --workspace on dfead370 (DXIL library, gpu_compute_e2e, and e2e verified above), paired scripts/smoke.ps1 (no retail title directory on this machine), AMD / Intel hardware, Linux / Wine.

AI use

  • Google Antigravity (Gemini); assisted with implementation, tests, benchmark validation, and PR preparation under author direction.

…gs (xcl-dev#2088)

Part of xcl-dev#2088

Restrict bitcode declaration compaction/canonicalization to split compute dispatch pieces (Module::try_to_canonical_bitcode + Shader::finish_optimized_canonical) so unsplit graphics and whole compute shaders preserve exact upstream bitcode while semantically identical pieces share identical DXIL containers and driver cache keys.

Additionally prune statically unreferenced dx.resources / PSV0 bindings in each piece when all dx.op.createHandleFromBinding calls use constant ResBind operands, preserving dynamic indexing, wave64 metadata, NaN/-0.0 bit patterns, and static sampler register mappings.

Co-Authored-By: Gemini 4 Hydrogen <noreply@antigravity.dev>
@Lum7nt

Lum7nt commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Tested on \dfead3702a1e8c3b6b30afeccf51efc1e885b10b\ (\dfead370, clean PR head):

  • Hardware / OS / Toolchain: NVIDIA GeForce RTX 3060 12 GB (driver \32.0.15.8142\ / 581.42, wave32), Intel Core i5-10400, Windows 11 (NT \10.0.22631.0),
    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.
  • Focused run (\cargo test -p xcl --lib gpu::dxil:: -- --test-threads=1): 189 passed, 0 failed, 3 ignored (\1149 filtered out; 1 \SKIPPED: \gpu::dxil::kernel::dispatch_chain_native_wave64_builds_whole: no wave64).
  • Workspace suite (\cargo test --workspace --no-fail-fast -- --test-threads=4): 1425 passed, 5 failed, 47 ignored (1312 lib + 113 integration; +5 passed over \origin/main\ \�49be183's 1420 passed / 5 failed / 47 ignored).
    • The 5 failures are the same 5 pre-existing \ID3D12PipelineState::GetCachedBlob()\ failures observed on \origin/main\ \�49be183\ on this driver/setup (\passthrough_mesh_stream_accepts_a_triangle_driver_blob, \split_compute_program_prebuilds_and_caches_chain_pieces, \split_compute_prefers_the_offline_whole_pipeline, \offline_compute_pipeline_is_reused_by_a_second_process, \offline_split_compute_pipeline_is_reused_by_a_second_process).
    • \SKIPPED\ checks: 20
      o wave64, 3 per-lane gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426\ refusals, 2 no D3D12 debug layer, 1 \cannot disable the driver cache (0x887A002D), 1
      o heap windows.

Not tested

  • Native wave64 / AMD / Intel GPUs, Linux / Wine, \XCL_SAMPLE_*\ tests (unset), and \scripts/smoke.ps1\ (no retail title folder here).

AI use

  • Antigravity (\Gemini 4 Hydrogen (Low)) checked out \dfead370, ran \gpu::dxil::\ and the workspace suite on this machine, and drafted this report.

@Prime1997 Prime1997 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read-through and GPU run of dfead37. 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

  1. The .chain.pso name 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.
  2. Every existing piece blob goes cold once after this change, because the canonical form changes the hash. Expected, but worth saying in the description so people do not report the one-time rebuild as a regression.
  3. The description gives the counts after the change (for example 90 pieces to 32 unique builds) and the DXIL size before and after, but not the unique-pipeline count for the same corpus on main, and no compile time. That one comparison would make the benefit reviewable.
  4. Nit: the canonical writer gains several expect() calls. As far as I can tell a panic there comes back as an Err from the translator thread's join rather than taking the process down, but returning the error directly would be clearer.
  5. A few of the new tests assert less than their names promise. Worth a pass to make each one fail when the behaviour in its name is removed.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants