Repository navigation
Recompiler: eliminate DXIL bitcode double-copy and intermediate allocations in container assembly - #2664
Conversation
…ations in container assembly Replace `program_part` (which allocated a `24 + bitcode.len()` Vec and copied the entire DXIL bitcode before copying it a second time into the final container) with a stack-allocated 24-byte `program_header` and a shared `assemble_container` helper that pre-sizes the output container once and copies `bitcode` directly in a single pass. Eliminate heap allocations for fixed 8-byte `SFI0`/`ISG1`/`OSG1` chunks and the intermediate `parts` Vec, exact-size `psv_part`, `signature_part` (borrowing `&str` instead of cloning `String`s), and `psv_part_full` (removing the temporary `all` Vec). Keeps `hash`/`md5_block`, all public signatures, `assert!(bitcode_len % 4 == 0)`, and emitted DXBC bytes 100% identical. Part of xcl-dev#2508 Part of xcl-dev#1833 Assisted-by: Google Antigravity (Gemini 4 Neon)
luckyteagirl
left a comment
There was a problem hiding this comment.
Could the full-PSV fixture compare against known pre-change PSV bytes? The container reference receives pfull from psv_part_full() under test, so the equality check verifies container placement and hashing but cannot catch a same-length PSV serialization change. In an isolated copy of this exact-head module, swapping psv.info1[0] and [1] in the serializer left the new test passing; an independent expected-byte check rejected the mutation. A golden PSV fixture or standalone reference serialization would support the PR's byte-identical guarantee. This is a test-oracle gap, not evidence that the current serializer emits wrong bytes. Verified with a focused standalone Rust harness at 902a8dc966ea7119f9c259701bb6819b1dcaa206; no full workspace or GPU run. AI-assisted review with Codex.
|
Native wave64 run on an AMD RX 9070 XT, plus an RTX 3060: the 2 new tests pass, and nothing else changes in the direct-DXIL GPU suite, so every direct-DXIL container the suite builds still validates and runs with this assembly code. Head
On both cards, the only result changes against Not tested: cold-cache compilation timings, the D3D12 debug-layer tests (no |
|
Tested on the Linux/Wine lane, full standard env (AMD rig: Ryzen 9 9900X, 96 GB DDR5, RX 7900 XT 20 GB, Arch kernel 7.2.15, Mesa 26.2.5 RADV, wine-11.0 Proton, rustc 1.94.0; |
|
Ran the DXIL container tests at Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only, 16 GB) driver 32.0.16.2124, Intel Core i5-12400F, 64 GB RAM, rustc 1.100.0 (0ef1bc386 2026-11-09) MSVC 14.44.35207, DXC 1.9.2609.5, debug build. All five tests pass, including the two new ones ( What this adds: the author tested on an Ampere RTX 4060 in release mode with the same DXC version; this is a Blackwell wave32 part in the debug test profile. The thread has no report from another machine. Not tested: the release micro-benchmark timings, a paired 60 s smoke run, the full workspace suite, AMD and Intel GPUs, native wave64, Wine, release profile, title data. AI-assisted (OpenCode), model: DeepSeek V4.1 Flash Free - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; the worktree was not modified; no game data was used. |
Write the DXIL program header and bitcode directly into one exactly sized container allocation. Remove intermediate part, string, and signature allocations while preserving all public formats and digest coverage. Keep an independent golden full-PSV byte fixture from the prior serializer so a same-length field reordering cannot hide behind the new assembly helpers. The upstream release microbenchmark reported 2.18-2.47x faster 1-2 MiB container assembly. GNU Windows-target cargo check passed here; Windows/MSVC, GPU tests, and title smoke were not run on this host. Adapted from PR xcl-dev#2664. Assisted-by: Google Antigravity (Gemini 4 Neon) Assisted-by: Codex (GPT-5.6-sol)
Write the DXIL program header and bitcode directly into one exactly sized container allocation. Remove intermediate part, string, and signature allocations while preserving all public formats and digest coverage. Keep an independent golden full-PSV byte fixture from the prior serializer so a same-length field reordering cannot hide behind the new assembly helpers. The upstream release microbenchmark reported 2.18-2.47x faster 1-2 MiB container assembly. GNU Windows-target cargo check passed here; Windows/MSVC, GPU tests, and title smoke were not run on this host. Adapted from PR xcl-dev#2664. Assisted-by: Google Antigravity (Gemini 4 Neon) Assisted-by: Codex (GPT-5.6-sol)
Write the DXIL program header and bitcode directly into one exactly sized container allocation. Remove intermediate part, string, and signature allocations while preserving all public formats and digest coverage. Keep an independent golden full-PSV byte fixture from the prior serializer so a same-length field reordering cannot hide behind the new assembly helpers. The upstream release microbenchmark reported 2.18-2.47x faster 1-2 MiB container assembly. GNU Windows-target cargo check passed here; Windows/MSVC, GPU tests, and title smoke were not run on this host. Adapted from PR xcl-dev#2664. Assisted-by: Google Antigravity (Gemini 4 Neon) Assisted-by: Codex (GPT-5.6-sol)
Write the DXIL program header and bitcode directly into one exactly sized container allocation. Remove intermediate part, string, and signature allocations while preserving all public formats and digest coverage. Keep an independent golden full-PSV byte fixture from the prior serializer so a same-length field reordering cannot hide behind the new assembly helpers. The upstream release microbenchmark reported 2.18-2.47x faster 1-2 MiB container assembly. GNU Windows-target cargo check passed here; Windows/MSVC, GPU tests, and title smoke were not run on this host. Adapted from PR xcl-dev#2664. Assisted-by: Google Antigravity (Gemini 4 Neon) Assisted-by: Codex (GPT-5.6-sol) Assisted-by: Codex (GPT-5.6-sol)
What is in it
Part of #2508
Part of #1833
Eliminates the full-bitcode double allocation/copy and intermediate part/string
Vecallocations during direct-DXIL DXBC container assembly incrates/xcl/src/gpu/dxil/container.rs(+219/-108lines;L76–131hash/md5_blockcompletely untouched for zero conflict with #1878; all public signatures,assert!(bitcode_len % 4 == 0), and emitted container bytes remain 100% identical):program_part(which allocated a24 + bitcode.len()Vec<u8>and copied the entire bitcode before copying it a second time intoout) with a stack-allocatedprogram_header(stage, sm, dxil_version, bitcode_len) -> [u8; 24](retainingassert!(bitcode_len % 4 == 0)).const EMPTY_SIGNATURE: [u8; 8] = [0, 0, 0, 0, 8, 0, 0, 0](removingempty_signature() -> Vec<u8>) and a sharedassemble_container(prefix_parts, stage, sm, bitcode)helper that computes exacttotal, allocatesVec::with_capacity(total)once (debug_assert_eq!(out.len(), total)), writes prefix parts andDXILheader +bitcodedirectly (1x memcpy, zero intermediatebitcode-sizedVec), and signsout[4..20]viahash(&out[20..]).container()andcontainer_with_signatures()to pass stack arrays of borrowed slices (SFI0,ISG1,OSG1, optionalPSG1,PSV0) toassemble_container, removing the duplicated serialization loops and intermediateparts: Vec/features.to_le_bytes().to_vec()heap allocations.psv_part(computingstr_len = (psv.entry.len() + 2).next_multiple_of(4)andexact_len = 68 + res_len + str_len, writing the string table directly intopwith zero temporarystringsVec).signature_partto borrowoffs: Vec<(&str, u32)>(zeroStringclones) and exact-sizep = Vec::with_capacity(8 + 32 * elems.len() + strings.len()).psv_part_full, removing the temporaryall: Vec<&PsvSigElement>allocation by chainingpsv.inputs/outputs/prims, pre-sizingstrings,name_off,idx_off, and allocatingp = Vec::with_capacity(p_len)once.digest_matches_dxc_signed_container,digest_covers_both_tail_layouts, andpsv_matches_dxc_layout_for_compute_with_two_raw_uavsuntouched, and addedparts_and_containers_are_exact_sized_and_match_reference_layoutandprogram_header_rejects_unaligned_bitcode.Tested
rustc 1.100.0, DXC1.9.2609.5 (01b62ad4), release builds.b49be183: exact-capacity check failed withpsv_part=104/160, signature_part=52/64, psv_part_full=76/80(all over-allocated byVec::new()growth).rustc -Oback-to-back comparison of pre-fixprogram_part+parts Vecvs post-fixprogram_header+assemble_container, excluding untouchedhash()):1 MiBbitcode (400iterations):533.0 µs/call->216.0 µs/call(2.47xfaster,-59.5%, eliminating a 1 MiB transient allocation + copy).2 MiBbitcode (200iterations):974.6 µs/call->446.5 µs/call(2.18xfaster,-54.2%, eliminating a 2 MiB transient allocation + copy).XCL_ADAPTER=warp,XCL_WARP=1):cargo test --release -p xcl --lib -- gpu::dxil::container::tests:: --nocapture->5 passed; 0 failed; 0 ignored(0skipped,0.00s).cargo clippy --all-targets:0new warnings incontainer.rs(only the 4 pre-existingchunks_exact/% 4lints on untouchedL82/L111and intentionally keptL139/L281).cargo test --release -p xcl --lib -- gpu::dxil:: --nocapture->186 passed; 0 failed; 3 ignored(5.38s;container::tests::5/0/0with0skipped;1pre-existingwave64skipdispatch_chain_native_wave64_builds_whole).cargo test --release --workspace --no-fail-fast -- --test-threads=4 --nocapture:37binaries,1437passed,0failed,47ignored (0compiler warnings incontainer.rs),29pre-existing environment-gatedSKIPPEDlines (none incontainer):21wave64-only GPU tests (no wave64on RTX 4060 32-lane waves)3per-lane wave32 shader tests (refused)3D3D12 debug layer tests (no d3d12SDKLayers.dll/ debug layer unavailable)1heap-window OOM fallback test (no heap windows)1PSO driver-cache measurement test (cannot disable the driver cache)Regression run
Paired 60 s retail smoke (
scripts/smoke.ps1, RTX 4060): both base and HEAD sustained60 60 60presents per 2 s with0device removals and0crashes (1536vs1562total frames,14023 MBvs14009 MBpeak commit).Base (
origin/main):HEAD (
fix-dxil-container-single-copy-and-exact-sizing):Not tested
AI use
Google Antigravity (Gemini 4 Neon) authored the
container.rssingle-copy / exact-sizing refactoring, parity tests, micro-benchmark, and verification runs; verified via failing-first check, WARP and RTX 4060 test suites,cargo clippy --all-targets, full RTX 4060 release workspace tests, and paired 60 s retail smoke runs.