Shaders: speed up DXBC container MD5 hashing by 16-43% #2808

Open
github-bot wants to merge 1 commit from github-bot/gh-2808 into main AGit
Owner

@⁠brainbudt on GitHub · 2026-11-25 21:06 UTC · original
brainbudt:perf/dxbc-md5-hash → main · +190 −58 · 2 files · 1 commits · open

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

  • Specialize the four MD5 rounds and construct the DXBC-specific padding in a 64-byte stack buffer in crates/victory-shader/src/emit/container.rs.
  • Add exact wire-byte, digest-boundary, and malformed-field tests, plus an ignored release benchmark for container emission and parsing.
  • Pure safe Rust, no new dependencies; clean merge compatibility checked against #1065 and #1303.

Benchmark (8,652-byte synthetic 5-part container, median of 5 alternating release runs)

Host Operation Before After Gain
macOS ARM64 Build + DXBC hash 18.31 µs 10.53 µs -42.5%
Linux x86-64 Build + DXBC hash 16.84 µs 14.15 µs -16.0%

Verification

  • Byte-for-byte identical output across 4,096 payload lengths (9,443,207 bytes compared) and 1,513 parser input pairs on both macOS ARM64 and Linux x86-64.
  • Windows MSVC cargo check -p victory-shader --target x86_64-pc-windows-msvc --tests and all-target Clippy -D warnings passed (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).

**@⁠brainbudt** on GitHub · 2026-11-25 21:06 UTC · [original](https://github.com/Marvisak/VIctory/pull/2808) `brainbudt:perf/dxbc-md5-hash` → `main` · +190 −58 · 2 files · 1 commits · open 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 - Specialize the four MD5 rounds and construct the DXBC-specific padding in a 64-byte stack buffer in `crates/victory-shader/src/emit/container.rs`. - Add exact wire-byte, digest-boundary, and malformed-field tests, plus an ignored release benchmark for container emission and parsing. - Pure safe Rust, no new dependencies; clean merge compatibility checked against #1065 and #1303. ### Benchmark (8,652-byte synthetic 5-part container, median of 5 alternating release runs) | Host | Operation | Before | After | Gain | |---|---|---:|---:|---:| | macOS ARM64 | Build + DXBC hash | 18.31 µs | 10.53 µs | -42.5% | | Linux x86-64 | Build + DXBC hash | 16.84 µs | 14.15 µs | -16.0% | ### Verification - Byte-for-byte identical output across 4,096 payload lengths (9,443,207 bytes compared) and 1,513 parser input pairs on both macOS ARM64 and Linux x86-64. - Windows MSVC `cargo check -p victory-shader --target x86_64-pc-windows-msvc --tests` and all-target Clippy `-D warnings` passed (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).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:14:45 +00:00
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-25 21:23 UTC · original

Reviewed and benchmarked 7d7efe35 on Windows 11 against main (13f91ca).

Code review & byte-exactness

  • Pure safe Rust (as_chunks::<64>() / as_chunks::<4>()), unrolling all 4 MD5 rounds and removing the temporary tail Vec allocation while preserving DXBC's non-standard padding (len << 3 and len << 1 | 1) across both rest.len() < 56 and rest.len() >= 56 boundaries.
  • Independently cross-checked every length 0..=256 (all 64-byte remainder classes plus block boundaries 55, 56, 63, 64, 119, 120, 128) as well as 511, 512, 513, 4095, 4096 against 13f91ca: 100% byte-identical digests.

Verification & same-machine --release benchmark (rustc 1.98.1 MSVC, Windows SDK 10.0.26100.0)

  • RTX 5090 (emit::container dxbc::): 6/6 passed; WARP + dxil.dll full victory-shader --features host: 270 passed, 0 failed (skipping only the 3 hardware-only synthetic_tests).
  • cargo clippy --locked -p victory-shader --all-targets -- -D warnings (default & --features host): 0 warnings; cargo xtask policy: 184 files ok; clean git merge-tree vs 13f91ca.
  • 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, with build() container allocation dominating the remainder).
**@⁠fuzeofficlal** on GitHub · 2026-11-25 21:23 UTC · [original](https://github.com/Marvisak/VIctory/pull/2808#issuecomment-7175013852) Reviewed and benchmarked `7d7efe35` on Windows 11 against `main` (`13f91ca`). ### Code review & byte-exactness - Pure safe Rust (`as_chunks::<64>()` / `as_chunks::<4>()`), unrolling all 4 MD5 rounds and removing the temporary `tail` `Vec` allocation while preserving DXBC's non-standard padding (`len << 3` and `len << 1 | 1`) across both `rest.len() < 56` and `rest.len() >= 56` boundaries. - Independently cross-checked every length `0..=256` (all 64-byte remainder classes plus block boundaries `55, 56, 63, 64, 119, 120, 128`) as well as `511, 512, 513, 4095, 4096` against `13f91ca`: **100% byte-identical digests**. ### Verification & same-machine `--release` benchmark (`rustc 1.98.1` MSVC, Windows SDK `10.0.26100.0`) - RTX 5090 (`emit::container dxbc::`): **6/6 passed**; WARP + `dxil.dll` full `victory-shader --features host`: **270 passed, 0 failed** (skipping only the 3 hardware-only `synthetic_tests`). - `cargo clippy --locked -p victory-shader --all-targets -- -D warnings` (default & `--features host`): **0 warnings**; `cargo xtask policy`: **184 files ok**; clean `git merge-tree` vs `13f91ca`. - `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, with `build()` container allocation dominating the remainder).
Author
Owner

@⁠cloph-dsp on GitHub · 2026-11-25 21:25 UTC · original

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).
  • Targeted: cargo test --locked -p victory-shader --lib reports_malformed_fields --quiet -> 1 passed.
  • git diff --check origin/main..HEAD clean.
  • Negative control: odd_parts_match_wire_bytes, dxbc_hash_padding_boundaries and reports_malformed_fields are all absent from origin/main, so the wire-byte, digest-boundary and malformed-field coverage is new here.
  • The rewritten MD5 block scheduler keeps the same D3D12 container digest; the synthetic tests cover exact wire bytes, padding at 56/64-byte boundaries and seven malformed field cases.
  • Full victory-shader lib was not run: emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index crashes on unmodified base 13f91ca on this machine (pre-existing).

AI-assisted (Hy4 flash).

**@⁠cloph-dsp** on GitHub · 2026-11-25 21:25 UTC · [original](https://github.com/Marvisak/VIctory/pull/2808#issuecomment-7175056606) 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). - Targeted: `cargo test --locked -p victory-shader --lib reports_malformed_fields --quiet` -> 1 passed. - `git diff --check origin/main..HEAD` clean. - Negative control: `odd_parts_match_wire_bytes`, `dxbc_hash_padding_boundaries` and `reports_malformed_fields` are all absent from origin/main, so the wire-byte, digest-boundary and malformed-field coverage is new here. - The rewritten MD5 block scheduler keeps the same D3D12 container digest; the synthetic tests cover exact wire bytes, padding at 56/64-byte boundaries and seven malformed field cases. - Full victory-shader lib was not run: `emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index` crashes on unmodified base 13f91ca on this machine (pre-existing). AI-assisted (Hy4 flash).
Author
Owner

@⁠Marvisak on GitHub · 2026-11-26 02:18 UTC · original

Automated triage for the maintainers.

This speeds up the DXBC container hash in emit/container.rs: hash builds its padded tail in a stack array instead of a Vec, and md5_block is unrolled by round. I checked the unrolled step order, the per-round message schedules ((5i+1), (3i+5), 7i mod 16 give the same words as the global index), and both tail cases (rest < 56 and >= 56) against the old code. They match, and dxbc_hash_padding_boundaries pins the old digests at the block boundaries. The new reports_malformed_fields test covers existing parse errors. The benchmark is #[ignore]d.

CI: passing.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-26 02:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/2808#issuecomment-7180681699) <!-- victory-triage v1 head=7d7efe35fffd379721ab910f833dffd87e7706c5 verdict=merge-candidate at=2026-11-26T02:18:50Z --> Automated triage for the maintainers. This speeds up the DXBC container hash in `emit/container.rs`: `hash` builds its padded tail in a stack array instead of a `Vec`, and `md5_block` is unrolled by round. I checked the unrolled step order, the per-round message schedules (`(5i+1)`, `(3i+5)`, `7i` mod 16 give the same words as the global index), and both tail cases (`rest < 56` and `>= 56`) against the old code. They match, and `dxbc_hash_padding_boundaries` pins the old digests at the block boundaries. The new `reports_malformed_fields` test covers existing parse errors. The benchmark is `#[ignore]`d. CI: passing. --- _Generated by [Claude Code](https://claude.ai/code)_
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2808/head:github-bot/gh-2808'
git switch 'github-bot/gh-2808'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2808'
git switch 'github-bot/gh-2808'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2808'
git switch 'github-bot/gh-2808'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2808'
git switch 'main'
git merge --squash 'github-bot/gh-2808'
git switch 'main'
git merge --ff-only 'github-bot/gh-2808'
git switch 'main'
git merge 'github-bot/gh-2808'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2808
No description provided.