Shaders: speed up DXBC container MD5 hashing by 16-43% #2806
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2808"
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 Marvisak/VIctory. Originally posted by brainbudt on 2026-11-25T21:06:38Z.
Every emitted DXBC container is MD5-hashed, and the compressor previously selected word schedules and rotation amounts inside its 64-step loop while allocating a temporary buffer to finalize each digest.
What changed
crates/victory-shader/src/emit/container.rs.Benchmark (8,652-byte synthetic 5-part container, median of 5 alternating release runs)
Verification
cargo check -p victory-shader --target x86_64-pc-windows-msvc --testsand all-target Clippy-D warningspassed (default and all features).Reviewed with mistral-loop: 2 rounds with Mistral Large 4 and DeepSeek V4.1 Flash on high. Verdict: approved.
Created with gpt-6.2-astra in Codex (orchestrated with Gemini 4 Neon in T3 Code).
Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T21:17:22Z.
Review: COMMENTED
Checked the nonstandard padding carefully: the D3D12 container hash puts the bit count FIRST (bytes 0-3), then data tail + 0x80, and
2*len+1at bytes 60-63. The rewrite reproduces both cases exactly — rest < 56 single block[bitcount][rest][0x80][zeros][len<<1|1]and rest ≥ 56 with the 0x80-terminated first block then[bitcount][zeros][len<<1|1]. Round specialization uses the canonical schedule (7/12/17/22, 5/9/14/20, 4/11/16/23, 6/10/15/21). The malformed-fields test is a useful parse-coverage bonus. LGTM.Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T21:23:31Z.
Reviewed and benchmarked
7d7efe35on Windows 11 againstmain(13f91ca).Code review & byte-exactness
as_chunks::<64>()/as_chunks::<4>()), unrolling all 4 MD5 rounds and removing the temporarytailVecallocation while preserving DXBC's non-standard padding (len << 3andlen << 1 | 1) across bothrest.len() < 56andrest.len() >= 56boundaries.0..=256(all 64-byte remainder classes plus block boundaries55, 56, 63, 64, 119, 120, 128) as well as511, 512, 513, 4095, 4096against13f91ca: 100% byte-identical digests.Verification & same-machine
--releasebenchmark (rustc 1.98.1MSVC, Windows SDK10.0.26100.0)emit::container dxbc::): 6/6 passed; WARP +dxil.dllfullvictory-shader --features host: 270 passed, 0 failed (skipping only the 3 hardware-onlysynthetic_tests).cargo clippy --locked -p victory-shader --all-targets -- -D warnings(default &--features host): 0 warnings;cargo xtask policy: 184 files ok; cleangit merge-treevs13f91ca.container_throughput(--release, 5-run median, 8,652 B 5-part container):build + hash:10,264.1 ns/op(13f91ca) ->9,385.8 ns/op(-8.6% / 1.09× on MSVC, withbuild()container allocation dominating the remainder).Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-25T21:25:26Z.
Local verification on Windows / rustc 1.100.0 / MSVC, no game data, no GPU, no clippy/rustup, CARGO_BUILD_JOBS=2.
cargo test --locked -p victory-shader --lib container --quiet-> 3 passed, 1 ignored benchmark, 0 failed (273 filtered out).cargo test --locked -p victory-shader --lib reports_malformed_fields --quiet-> 1 passed.git diff --check origin/main..HEADclean.odd_parts_match_wire_bytes,dxbc_hash_padding_boundariesandreports_malformed_fieldsare all absent from origin/main, so the wire-byte, digest-boundary and malformed-field coverage is new here.emit::memory_tests::heap_direct_texture_reads_mark_their_heap_indexcrashes on unmodified base13f91caon this machine (pre-existing).AI-assisted (Hy4 flash).
Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T02:50:13Z.
Review: APPROVED
Tested merged onto
origin/main(63bcca4) on Windows 11 x64:cargo test -p victory-shader --lib emit::container::tests: 3 passed, 0 failed, 1 ignored (odd_parts_match_wire_bytes,md5_core_matches_the_standard,dxbc_hash_padding_boundaries).cargo test -p victory-shader --lib dxbc::tests: 3 passed, 0 failed (includingreports_malformed_fields).cargo clippy -p victory-shader --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T02:18:55Z.
Automated triage for the maintainers.
This speeds up the DXBC container hash in
emit/container.rs:hashbuilds its padded tail in a stack array instead of aVec, andmd5_blockis unrolled by round. I checked the unrolled step order, the per-round message schedules ((5i+1),(3i+5),7imod 16 give the same words as the global index), and both tail cases (rest < 56and>= 56) against the old code. They match, anddxbc_hash_padding_boundariespins the old digests at the block boundaries. The newreports_malformed_fieldstest covers existing parse errors. The benchmark is#[ignore]d.CI: passing.
Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-27T02:16:36Z.
Review: APPROVED
Reviewed
7d7efe35fffd379721ab910f833dffd87e7706c5.LGTM — switching
container::hashtoas_chunks::<64>()+ a stack[0; 64]tail buffer and specializing the four rounds inmd5_blockpreserves byte-for-byte equivalence with the previous padding/compression implementation across all boundary remainders (< 56vs>= 56), anddxbc::tests::reports_malformed_fieldsadds solid parser error coverage.Verified locally:
cargo xtask policy(191 files ok),cargo clippy -p victory-shader --all-targets/--all-features(-D warnings), and zero newrustfmtdiffs (dxbc.rspasses cleanly;container.rsonly has the pre-existingconst Ktable layout).dxbc::tests(3 passed) andemit::container::tests(3 passed) pass, and--releasecontainer_throughputpasses on an 8,652-byte container (parse + find DXIL 30.48 ns/op,build + hash 9259.74 ns/op).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.