Shaders: precompute MD5 round constants and avoid per-block Vec in md… #1475

Merged
Texbirds merged 1 commit from upstream-pr/1476 into main 2026-11-25 00:23:05 +00:00
Texbirds commented 2026-11-24 18:18:13 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Texbirds on 2026-11-24T18:18:13Z.


…5_block

Problem

md5_block in crates/victory-shader/src/emit/container.rs allocates a Vec<u32> and calls f64::sin() 64 times for every 64-byte block of emitted DXIL container data.

Fix

  • Replace the runtime sin() calculation with the standard RFC 1321 const K: [u32; 64] table.
  • Unpack the 16 input words into a stack [u32; 16] array instead of heap-allocating a Vec<u32> per block.
  • Verified bit-identical to the existing md5_core_matches_the_standard test.
<!-- greyfinch-sync:Marvisak/VIctory:issue:6588490712 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1476). Originally posted by [Texbirds](https://github.com/Texbirds) on 2026-11-24T18:18:13Z. --- …5_block ### Problem `md5_block` in `crates/victory-shader/src/emit/container.rs` allocates a `Vec<u32>` and calls `f64::sin()` 64 times for every 64-byte block of emitted DXIL container data. ### Fix - Replace the runtime `sin()` calculation with the standard RFC 1321 `const K: [u32; 64]` table. - Unpack the 16 input words into a stack `[u32; 16]` array instead of heap-allocating a `Vec<u32>` per block. - Verified bit-identical to the existing `md5_core_matches_the_standard` test.
catminou4 commented 2026-11-24 19:03:32 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T18:42:16Z.

Review: APPROVED


Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (ffe310e), cargo test -p victory-shader --locked → 96 passed, 0 failed. Execution/valu tests are #[cfg(all(test, windows))] and were not run here; lowering/structure coverage only.

MD5 block function: the per-round K constants are now the standard RFC 1321 table (spot-checked first/last entries) instead of being recomputed via sin() per round, the message words are a stack array instead of a Vec, and the round loop iterates the table directly. Pure perf/clarity, no semantic change. 96 passed on macOS.

<!-- greyfinch-sync:Marvisak/VIctory:review:6045234447 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1476#pullrequestreview-6045234447). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T18:42:16Z. **Review:** APPROVED --- Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (ffe310e), `cargo test -p victory-shader --locked` → 96 passed, 0 failed. Execution/valu tests are `#[cfg(all(test, windows))]` and were not run here; lowering/structure coverage only. MD5 block function: the per-round `K` constants are now the standard RFC 1321 table (spot-checked first/last entries) instead of being recomputed via `sin()` per round, the message words are a stack array instead of a `Vec`, and the round loop iterates the table directly. Pure perf/clarity, no semantic change. 96 passed on macOS.
sinan-cmyk commented 2026-11-24 21:03:25 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by sinan-cmyk on 2026-11-24T20:13:33Z.


Offline measurement on a retail dump, and the shader tests on Ada

Result: no count change against main.

Offline. I merged head 711d651 onto main ffe310e (clean merge) and ran victory translate --validate --list on shaders.rpf (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with main program by program (25,889 programs). Validated: 21,724 on main, 21,724 with this PR.

No program changes its failure reason either. That is the expected result for a fix whose instructions sit behind the earlier failures on main. The count shows that the change rejects nothing. It does not show whether the output is right.

Tests: with the same merge, cargo test --locked -p victory-shader --lib passed 120, failed 0. The bitcode benchmark is ignored, as on main, where 120 pass. The run was on an RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter, with VICTORY_WARP unset.

No shader names or data are included, per the asset policy. AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7143216437 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1476#issuecomment-7143216437). Originally posted by [sinan-cmyk](https://github.com/sinan-cmyk) on 2026-11-24T20:13:33Z. --- ### Offline measurement on a retail dump, and the shader tests on Ada **Result: no count change against `main`.** **Offline.** I merged head 711d651 onto `main` ffe310e (clean merge) and ran `victory translate --validate --list` on `shaders.rpf` (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with `main` program by program (25,889 programs). Validated: 21,724 on `main`, 21,724 with this PR. No program changes its failure reason either. That is the expected result for a fix whose instructions sit behind the earlier failures on `main`. The count shows that the change rejects nothing. It does not show whether the output is right. **Tests:** with the same merge, `cargo test --locked -p victory-shader --lib` passed 120, failed 0. The bitcode benchmark is ignored, as on `main`, where 120 pass. The run was on an RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter, with `VICTORY_WARP` unset. No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
upstream-sync closed this pull request 2026-11-25 01:06:38 +00:00
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!1475
No description provided.