Textures: hash big texture memory on several threads (same hash, up to 6x faster) #28

Open
spy0eye-beep wants to merge 77 commits from upstream-pr/28 into main
spy0eye-beep commented 2026-11-25 17:32:08 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by spy0eye-beep on 2026-11-25T17:32:08Z.


What

Texture memory is hashed with BLAKE3 at a check to tell whether it changed (partly mapped textures, through_copy, view memory taken by turn, the unlocked read). That ran on one thread: about 4.5 GB/s here, 3.7 ms for a 16 MB texture.

From 1 MiB on, the hash now runs on several threads (blake3 with its rayon feature, Hasher::update_rayon). The hash is the same: BLAKE3 hashes a fixed tree of 1 KiB chunks, whichever thread hashes which part. So what is detected as changed, uploaded and drawn is unchanged.

cargo test --release -p victory-gpu --lib content_hash_speed -- --ignored --nocapture, i7-13620H (6 P + 4 E cores):

texture one thread content_hash
1 MB 0.22 ms 0.07 ms
4 MB 0.89 ms 0.17 ms
16 MB 3.73 ms 0.58 ms

Below 1 MiB it stays on one thread (blake3::hash), where threads cost more than they save.

Same output

  • New test the_wide_hash_is_the_hash: content_hash equals blake3::hash at 0, 1, 1024, 1025 bytes, at the 1 MiB switch ±1, past it by a chunk, and at 3, 8 and 9 MiB plus odd tails.
  • The four blake3::hash(read|tiled) calls in texture.rs are the only ones changed; pipeline and shader-cache hashes are left alone.

Cost

  • New dependencies through blake3/rayon: rayon-core, crossbeam-deque, crossbeam-epoch, crossbeam-utils (Cargo.lock +36 lines). Rayon's pool starts on the first big hash, one thread per logical CPU.

Testing

  • cargo test -p victory-gpu --all-features on the RTX 4060 Laptop: 163 passed, 0 failed.
  • cargo build --release -p victory: OK. Clippy: only beta's existing two errors. rustfmt: no new differences. cargo xtask policy reports the same 4 findings as beta (lower.rs size, logo.svg, two .py files), none new.
  • Not measured in the title: how much of a frame this saves depends on how many textures are hashed per frame (fxceless/victory-fork#26 shows 13-35 ms of "textures" for 10-34 MB).

AI-assisted (Claude).

🤖 Generated with Claude Code

<!-- greyfinch-sync:PastiiJay/klbf-lab:issue:5496081083 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/28). Originally posted by [spy0eye-beep](https://github.com/spy0eye-beep) on 2026-11-25T17:32:08Z. --- ## What Texture memory is hashed with BLAKE3 at a check to tell whether it changed (partly mapped textures, `through_copy`, view memory taken by turn, the unlocked read). That ran on one thread: about 4.5 GB/s here, 3.7 ms for a 16 MB texture. From 1 MiB on, the hash now runs on several threads (`blake3` with its `rayon` feature, `Hasher::update_rayon`). **The hash is the same**: BLAKE3 hashes a fixed tree of 1 KiB chunks, whichever thread hashes which part. So what is detected as changed, uploaded and drawn is unchanged. `cargo test --release -p victory-gpu --lib content_hash_speed -- --ignored --nocapture`, i7-13620H (6 P + 4 E cores): | texture | one thread | `content_hash` | |---|---|---| | 1 MB | 0.22 ms | 0.07 ms | | 4 MB | 0.89 ms | 0.17 ms | | 16 MB | 3.73 ms | **0.58 ms** | Below 1 MiB it stays on one thread (`blake3::hash`), where threads cost more than they save. ## Same output - New test `the_wide_hash_is_the_hash`: `content_hash` equals `blake3::hash` at 0, 1, 1024, 1025 bytes, at the 1 MiB switch ±1, past it by a chunk, and at 3, 8 and 9 MiB plus odd tails. - The four `blake3::hash(read|tiled)` calls in `texture.rs` are the only ones changed; pipeline and shader-cache hashes are left alone. ## Cost - New dependencies through `blake3/rayon`: `rayon-core`, `crossbeam-deque`, `crossbeam-epoch`, `crossbeam-utils` (Cargo.lock +36 lines). Rayon's pool starts on the first big hash, one thread per logical CPU. ## Testing - `cargo test -p victory-gpu --all-features` on the RTX 4060 Laptop: 163 passed, 0 failed. - `cargo build --release -p victory`: OK. Clippy: only `beta`'s existing two errors. rustfmt: no new differences. `cargo xtask policy` reports the same 4 findings as `beta` (`lower.rs` size, `logo.svg`, two `.py` files), none new. - Not measured in the title: how much of a frame this saves depends on how many textures are hashed per frame (fxceless/victory-fork#26 shows 13-35 ms of "textures" for 10-34 MB). AI-assisted (Claude). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
PastiiJay commented 2026-11-25 18:38:14 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by PastiiJay on 2026-11-25T18:38:14Z.


Thanks a lot @spy0eye-beep! Noted. It goes into tonight's RX 9070 XT test queue and I'll report the result here.

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7171184012 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/28#issuecomment-7171184012). Originally posted by [PastiiJay](https://github.com/PastiiJay) on 2026-11-25T18:38:14Z. --- Thanks a lot @spy0eye-beep! Noted. It goes into tonight's RX 9070 XT test queue and I'll report the result here.
HandshakeHackin commented 2026-11-26 03:11:38 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by HandshakeHackin on 2026-11-26T03:11:38Z.


I reran the unmodified release benchmark at 39ad849 on a smaller Windows VM (AMD EPYC 7763, 2 cores / 4 logical processors). The eleven byte-for-byte hash fixtures passed with RAYON_NUM_THREADS=1, 2, and the unset default. The table gives median milliseconds per hash over six interleaved runs of each configuration.

Input Serial BLAKE3 PR, 1 worker PR, 2 workers PR, default
1 MiB 0.26 0.28 0.19 0.16
4 MiB 1.03 1.06 0.58 0.49
16 MiB 4.19 4.23 2.66 1.83

The serial column is the paired serial reference from the default-pool runs. On this VM the default paid off at the 1 MiB threshold, while a single-worker Rayon pool had a small overhead. These are isolated texture-hash timings. Runner, per-round results, and medians

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7181479748 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/28#issuecomment-7181479748). Originally posted by [HandshakeHackin](https://github.com/HandshakeHackin) on 2026-11-26T03:11:38Z. --- I reran the unmodified release benchmark at `39ad849` on a smaller Windows VM (AMD EPYC 7763, 2 cores / 4 logical processors). The eleven byte-for-byte hash fixtures passed with `RAYON_NUM_THREADS=1`, `2`, and the unset default. The table gives median milliseconds per hash over six interleaved runs of each configuration. | Input | Serial BLAKE3 | PR, 1 worker | PR, 2 workers | PR, default | |---|---:|---:|---:|---:|---:| | 1 MiB | 0.26 | 0.28 | 0.19 | 0.16 | | 4 MiB | 1.03 | 1.06 | 0.58 | 0.49 | | 16 MiB | 4.19 | 4.23 | 2.66 | 1.83 | The serial column is the paired serial reference from the default-pool runs. On this VM the default paid off at the 1 MiB threshold, while a single-worker Rayon pool had a small overhead. These are isolated texture-hash timings. [Runner, per-round results, and medians](https://github.com/HandshakeHackin/klbf-lab/actions/runs/45746858556/job/139664894874)
PastiiJay commented 2026-11-26 10:42:30 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by PastiiJay on 2026-11-26T10:42:30Z.


Thanks for the small-VM rerun; good to know it holds on fewer cores. We'll check it in game.

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7189726162 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/28#issuecomment-7189726162). Originally posted by [PastiiJay](https://github.com/PastiiJay) on 2026-11-26T10:42:30Z. --- Thanks for the small-VM rerun; good to know it holds on fewer cores. We'll check it in game.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/28:upstream-pr/28'
git switch 'upstream-pr/28'

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.

git switch 'main'
git merge --no-ff 'upstream-pr/28'
git switch 'upstream-pr/28'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/28'
git switch 'upstream-pr/28'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/28'
git switch 'main'
git merge --squash 'upstream-pr/28'
git switch 'main'
git merge --ff-only 'upstream-pr/28'
git switch 'main'
git merge 'upstream-pr/28'
git push origin 'main'
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
PastiiJay/klbf-lab!28
No description provided.