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

Open
github-bot wants to merge 1 commit from github-bot/gh-28 into beta AGit
Owner

@⁠spy0eye-beep on GitHub · 2026-11-25 17:32 UTC · original
spy0eye-beep:klbf-fast-hash → beta · +115 −5 · 3 files · 1 commits · open

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

**@⁠spy0eye-beep** on GitHub · 2026-11-25 17:32 UTC · [original](https://github.com/PastiiJay/klbf-lab/pull/28) `spy0eye-beep:klbf-fast-hash` → `beta` · +115 −5 · 3 files · 1 commits · open ## 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)
Texture memory is hashed with BLAKE3 to tell whether it changed; on one
thread that was about 4.5 GB/s, 3.7 ms for 16 MB. From 1 MiB on it now runs
on several threads (blake3's rayon feature, Hasher::update_rayon): 0.58 ms
for 16 MB here. The hash is the same (BLAKE3 hashes a fixed tree of 1 KiB
chunks): the_wide_hash_is_the_hash checks it against blake3::hash around
the switch and chunk boundaries.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:52:55 +00:00
Author
Owner

@⁠PastiiJay on GitHub · 2026-11-25 18:38 UTC · original

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

**@⁠PastiiJay** on GitHub · 2026-11-25 18:38 UTC · [original](https://github.com/PastiiJay/klbf-lab/pull/28#issuecomment-7171184012) Thanks a lot @⁠spy0eye-beep! Noted. It goes into tonight's RX 9070 XT test queue and I'll report the result here.
Author
Owner

@⁠HandshakeHackin on GitHub · 2026-11-26 03:11 UTC · original

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

**@⁠HandshakeHackin** on GitHub · 2026-11-26 03:11 UTC · [original](https://github.com/PastiiJay/klbf-lab/pull/28#issuecomment-7181479748) 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)
Author
Owner

@⁠PastiiJay on GitHub · 2026-11-26 10:42 UTC · original

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

**@⁠PastiiJay** on GitHub · 2026-11-26 10:42 UTC · [original](https://github.com/PastiiJay/klbf-lab/pull/28#issuecomment-7189726162) Thanks for the small-VM rerun; good to know it holds on fewer cores. We'll check it in game.
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/28/head:github-bot/gh-28'
git switch 'github-bot/gh-28'

Merge

Merge the changes and update on Forgejo.
git switch 'beta'
git merge --no-ff 'github-bot/gh-28'
git switch 'github-bot/gh-28'
git rebase 'beta'
git switch 'beta'
git merge --ff-only 'github-bot/gh-28'
git switch 'github-bot/gh-28'
git rebase 'beta'
git switch 'beta'
git merge --no-ff 'github-bot/gh-28'
git switch 'beta'
git merge --squash 'github-bot/gh-28'
git switch 'beta'
git merge --ff-only 'github-bot/gh-28'
git switch 'beta'
git merge 'github-bot/gh-28'
git push origin 'beta'
This discussion has been locked. Commenting is limited to contributors.
No description provided.