Recompiler: speed up direct DXIL BitWriter, Module interning, and Shader::op #2056
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!2056
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2056"
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?
@zondy1i on GitHub · 2026-11-25 02:15 UTC · original
zondy1i:dxil/builder-bitwriter-fastpath→main· +372 −67 · 4 files · 1 commits · openPart of #1269.
Follows up #1927 by removing hot-path allocations, SipHash lookups, and byte-by-byte bit flushing across the direct DXIL builder and bitcode writer while keeping the emitted DXIL bit-for-bit identical.
What changed
crates/xcl/src/gpu/dxil/bitstream.rs:BitWriter::with_capacityfor pre-sized output buffers.BitWriter::emitin 32-bit little-endian words instead of byte-by-byte (draining residual bytes inalign32).BitWriter::vbr(value < hi).BitWriter::record_strdirectly without allocating an intermediateVec<u64>.crates/xcl/src/gpu/dxil/module.rs:FastMap(likessa.rs::VarHasher) fortype_ids,const_ids,func_ids, andmd_strings(none of these maps are iterated for output; bitcode writes from the orderedVecs).Tyhandles (void,i1,i8,i32,i64,f16,f32,f64) on first intern so type-table order stays unchanged.Module::insts_use_typewithOp::for_each_operandinstead of allocating aVec<Value>viainst_infoon every instruction.Module::call_with_firstandModule::func_matches_op; pre-sizeBitWriterand reuse a singleoperands: Vec<u64>acrosswrite_types,ConstDef::Aggregate,MdDef::Node,named_md, andwrite_inst.crates/xcl/src/gpu/dxil/shader.rs:dx.opfunction ids inShader::op_cachekeyed by(op, overload, ret), validating name prefix and parameter types without allocating before reusing the cached id (and falling back todeclare_opon any mismatch so error reporting is preserved).Shader::op, before the cache lookup, so a cache hit still verifies them;Shader::dispatch_piecestarts with an emptyop_cache.crates/xcl/src/gpu/dxil/bitstream.rs&crates/xcl/src/gpu/dxil/bitreader_tests.rs:align32across all residual bit counts0..=31,record_strequivalence,insts_use_typeoperand scanning,op_cachemismatch fallback, and the attribute check on a cache hit (shader_op_cache_hit_still_checks_dx_op_attributes).Benchmark
Seeded 500-program direct DXIL sweep (
--direct --sample 500 --seed 1 --max-bytes 262144 --split 1, release build, Windows 11, Ryzen 5 7500F, median of 3 runs each):main(3da2abb)a423147, same diff rebased to9975777)The benchmark and the byte-for-byte check were measured on the pre-rebase head
9975777; the changes since only initialiseop_cacheindispatch_pieceand move a debug-only assertion, so the emitted DXIL is unchanged.Byte-for-byte check: 100/100 dumped
.dxilcontainers (--sample 100 --seed 1 --max-bytes 262144 --split 1) have identical SHA-256 hashes againstmain.Tested
rustc 1.100.0, DXC /dxil.dll1.9.2609.5, NVIDIA GeForce RTX 3060 Ti 8 GB (driver621.01).origin/main(b49be183). The merge was text-clean but no longer compiled (E0063 inShader::dispatch_piece, whichmainadded after this PR's base), so it now setsop_cache: FastMap::default()there; reported by @thehollowedone and @oni-swr. The same review pointed out that a warmedShader::opcache hit skipped the debug check of the DXC function attributes, so the check now runs before the lookup.cargo test --workspace -- --test-threads=4on8fc4de1: 1440 passed, 0 failed, 47 ignored across 37 test binaries (29 runtimeSKIPPEDnotices from adapter-gated tests); includesdx_op_attrs_match_dxc,shader_op_cache_hit_still_checks_dx_op_attributes,dispatch_chain_*andtranslation_is_byte_identical_across_runs_and_threads.main(pre-rebase head9975777).Not tested
gpu::dxil::fuzz_tests, AMD / Intel GPUs, Linux / Wine / vkd3d-proton.Regression run
main:PR:
AI use
Antigravity (Gemini 4 Neon) assisted with implementation, unit tests, and benchmarking; all changes were reviewed and verified locally.
@WebIdentity1 on GitHub · 2026-11-25 02:24 UTC · original · edited 2026-11-25 02:29 UTC
Independent synthetic comparison of parent
3da2abb81606df622610e009f0430de99aa9881cand heada423147005f9d691260086edc899dee79dcfb4c3: identical DXIL and correct GPU output, with a 5.6% lower median translation time for the larger fixture. This is a public-input check, separate from the pack benchmark in the description.Tested — native Windows10 Home19045, Ryzen7800X3D, RTX3090 driver591.74, Rust/Cargo1.98.1MSVC, DXC/DXIL1.8.2502.11, release. Runtime sources unchanged; identical local test-only fixture on both revisions.
XCL_ADAPTER=3090,XCL_SPLIT_WAVE64=1,XCL_DIRECT_COMPACT=0; noXCL_DXIL_NO_OPToverride.The fixture uses
translate_computewith the production compute ABI, a 64-lane split-wave64 group, live raw-buffer inputs and an integer add/xor chain with varying literals. It validates the resulting DXIL and checks all64 output words against a CPU calculation, plus all64 input words remain unchanged.Small row: one process per revision, five timed translations after one warm-up. Large row: base/head/head/base fresh-process order, five timed translations after a warm-up per process (ten timings per revision). Individual process medians are27.819 /27.634ms for parent and26.082 /26.213ms for PR. The timer wraps the existing
translate_computeAPI, including its worker creation; final explicit validation and GPU work are outside the timer. This workload mainly exercises module construction/interning and serialization; it is not a substitute for broad opcode-cache or pack coverage.Peak process commit before GPU initialization was15.42–15.66MiB on parent and15.24–15.30MiB on PR for the larger fixture. The small fixture was4.80 versus4.92MiB. These are whole-process high-water marks, including the harness, warm-up and retained reference DXIL; they do not establish a substantial memory saving.
Both sizes have matching SHA-256 containers across revisions, and every timed translation equals its process's reference bytes. Six native test processes each passed 1 /0 /0 /0 skipped, six real GPU dispatches total. Both317-file manifests matched before/after build, after all runs, and locally. Both copied release-test executable hashes also remained unchanged. Release builds passed; the selected command was:
Not tested — full workspace, retail smoke/gameplay, AMD/Intel, production-pack performance, concurrent translation memory, cold driver PSO time or GPU throughput. The GPU checks establish output correctness here, not a rendering speedup. No runtime edit, commit/push or competing PR.
AI use — Codex (GPT-6) wrote the synthetic fixture, ran/reviewed the native comparisons, verified hashes and prepared this report.
Reproducible test-only fixture (append to recomp/tests.rs; XCL_PROBE_PAIRS selects size)
@JJAutoCompare on GitHub · 2026-11-25 02:32 UTC · original
PR #2056 — independent CPU test report
Tested
cargo test --locked -p xcl --lib --jobs 2 -- --exact --test-threads=1 --nocapture gpu::dxil::bitstream::tests::emit_word_flush_and_align32_match_byte_by_byte gpu::dxil::bitstream::tests::record_str_matches_record_bytes gpu::dxil::bitreader_tests::insts_use_type_finds_result_and_operand_types gpu::dxil::bitreader_tests::shader_op_cache_rejects_mismatched_redeclaration
4 passed, 0 failed, 0 ignored, 0 skipped, 1088 filtered out. Cargo exited 0. Word flushing and 32-bit alignment matched the reference across all 32 residual lengths, string record encoding matched ordinary record encoding, integer operand scanning found the i64 operands of an i1 comparison, and the declaration-cache lookup preserved the builder error for mismatched parameter types.
Not tested
GPU execution, DXIL validation or whole-shader byte parity, retail packs or smoke runs, performance, malformed shaders or arbitrary inputs, and the rest of the workspace test suite.
AI use
T3 Code / Codex (gpt-6.2-sol) selected and ran the four checked-in tests and wrote this report from the recorded output.
@DavidM1911 on GitHub · 2026-11-25 04:41 UTC · original
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)Thanks!
@anes66 on GitHub · 2026-11-25 06:17 UTC · original
CPU-only serialization checks on exact head
99757777918cef2f8f3da5f90564a442c974cabdpassed. Optional test companion 8ce813f is directly on that head, with tests only. It adds two bitstream tests and carries forward our mixed-record fixtures from #1927.Tested
cbc296ab65a2661a61e3e2da109134bcd5319f60's three changed production files (bitstream.rs,module.rs,shader.rs), with the same bitreader fixture overlay: 8 passed / 0 failed / 0 ignored / 0 skips. The PR implementation also passes those eight tests. Both produce 79,936 byte-identical raw-bitcode bytes, SHA-256f2f7fed408e1e265ca3b7e39f5139dae858c743062d1804efb90926a3f5f3576.cargo test --locked -p xcl --lib gpu::dxil::bitstream::tests:: -j 2 -- --nocapture --test-threads=1: 7 passed / 0 failed / 0 ignored / 0 skips.cargo test --locked -p xcl --lib gpu::dxil::bitreader_tests:: -j 2 -- --nocapture --test-threads=1: 8 passed / 0 failed / 0 ignored / 0 skips.< hito<= hifails the independent bit reference. Restored before the final passing runs and commit; final raw-bitcode hash still matches the parent control.Not tested
Serialized DXIL validation, GPU execution, fuzz suite, retail input, release or newer-main integration. Printed debug timings are not controlled performance evidence. This checks these output contracts and one synthetic module's identity, not every module or a measured startup speedup.
AI use: Codex (GPT-6; exact variant unavailable) wrote/reused the test fixtures and temporary control, ran CPU verification and prepared this report.
@thehollowedone on GitHub · 2026-11-25 13:56 UTC · original
Independent release check of 9975777 against its exact parent cbc296a. Windows 11 build 26300, Ryzen 7 9800X3D, RTX 3080 Ti / 621.35, Rust 1.99.1 MSVC, DXC 1.8.2502.11.
I reran the public synthetic add/XOR fixture with 4,096 pairs and one 64-lane group using split wave64. I built both test binaries with
cargo test --offline --locked --release -p xcl --lib -j 4 --no-run --message-format=json. The test-only fixture was identical on both revisions. Fresh process order was parent, PR, PR, parent, with two warm-ups and seven timed translations per process.Synthetic input only. No retail or gameplay performance claim.
AI-assisted. Codex (GPT-6, exact variant unavailable) adapted the fixture, ran the tests and drafted this report.
@oni-swr on GitHub · 2026-11-25 21:10 UTC · original
Tested
XCL_ADAPTER=radeon.99757777918cef2f8f3da5f90564a442c974cabd. Baselineorigin/mainwas6d12f58a229bc73889878a448c64dc3af25eeba0.cargo test --workspace --no-fail-fast -- --test-threads=4: 1,157 passed, 1 failed, 46 ignored, 16SKIPPEDnotices (exit 101). The sole failure wasgpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1, also the sole baseline failure.cargo test -p xcl --lib gpu::dxil::bitstream::tests -- --test-threads=1: 5 passed, 0 failed, 0 ignored.cargo test -p xcl --lib gpu::dxil::bitreader_tests -- --test-threads=1: 6 passed, 0 failed, 0 ignored.cargo test --workspace --no-fail-fast -- --test-threads=4: 1,422 passed, 1 failed, 46 ignored, 25SKIPPEDnotices (exit 101); its sole failure was the same fuzz test.Not tested
origin/main(6d12f58a229bc73889878a448c64dc3af25eeba0) did not compile: aShaderinitializer is missing the newop_cachefield. The GPU suite above ran on the exact PR head.AI use
@thehollowedone on GitHub · 2026-11-25 23:00 UTC · original
Follow-up to the current-main compile failure already reported. I reproduced it with #2056 head
9975777merged without a commit intomaine1d84b7:cargo check --offline --locked -p xclfailed with E0063 atshader.rs:166. Main addedShader::dispatch_piece()after this PR's base; itsSelfinitializer needsop_cache: FastMap::default(). An empty per-piece cache is appropriate becauseModule::declarations()carries the declarations and IDs, and the first lookup resolves them.I found one smaller diagnostic regression while checking that merge. On a warmed
Shader::opcache hit, the existing debug assertion for DXC function attributes indeclare_opis bypassed. A local debug regression that calls opcode 35 withReadNoneand thenNonefailed before the assertion was moved (should panicdid not panic), and passed after it was moved before the cache lookup. This affects the builder's debug check; I did not find a retail output failure.Suggested diff for the rebase (tested locally, not committed or pushed):
On the isolated merge with this diff:
cargo check --offline --locked -p xclpassed;dispatch_chain_payload_skips_middle_pieceand the new cache-hit regression each passed 1/0;cargo test --offline --locked --workspace --no-fail-fast -- --test-threads=4passed 1,428/0/46 across 37 binaries with 25 explicit GPU skips (21 no native wave64, 3 unsupported f16 forms, 1 no heap windows). This is integration evidence for an uncommitted tree, not a test report for a clean rebased PR head. No title smoke or AMD run was done. AI use: Codex (GPT-6; exact variant unavailable) built and tested the local patch and drafted this comment; GPT-6.2 Astra Low reviewed the merge path.@zondy1i on GitHub · 2026-11-26 02:59 UTC · original
Rebased onto current
main(b49be183) and fixed the two points from the reports above:maindid not compile (E0063 inShader::dispatch_piece, whichmainadded after this PR's base): it now starts with an emptyop_cache.Shader::opcache lookup, so a cache hit still verifies them; new testshader_op_cache_hit_still_checks_dx_op_attributes.Full workspace suite on the new head
8fc4de1: 1440 passed, 0 failed; 60 s smoke is in the description. Thanks @thehollowedone and @oni-swr for the reports. The benchmark and the 100/100 byte-identity check are from the previous head (the changes since do not touch the emitted DXIL).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.