Avoid shader container copies on warm cache hits #4865

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

@⁠VazirAPI on GitHub · 2026-12-01 12:03 UTC · original
VazirAPI:perf/shader-cache-input → main · +40 −3 · 2 files · 1 commits · open

What it changes

Every shader-cache lookup first allocated and copied the build fingerprint and the entire shader container into a joined input buffer, including validated warm hits. Hash the two borrowed slices directly and allocate contiguous converter input only after a miss.

CacheKey::new_parts produces exactly the same hash as CacheKey::new over the concatenated input. Existing keys, cache format and translator fingerprint stay unchanged. Translation, corruption handling, cache-write failures and miss publication retain their existing paths. This removes one container-sized temporary allocation and copy per warm lookup; it does not remove hashing or decoded-output allocations.

How it was tested

  • Tested commit: 44e5288ce1ee94c0140169abce3a37e7a73c490d (same tree as the final local checks).

  • GPU and profile: CPU-only synthetic cache inputs on Windows 11; no game files, game run or FPS measurement.

  • Toolchain: pinned Rust 1.98.1, native x86_64-pc-windows-gnu with MinGW. MSVC and upstream CI are not claimed here.

  • Before: added borrowed-input API tests failed to compile because the API was absent.

  • After: cargo test -p victory-pipeline --locked --offline: 17 passed, 0 failed. Tests cover chunk boundaries including empty chunks, BLAKE3 block/chunk edges, converter versioning, and locating an entry written from contiguous input.

  • cargo test -p victory-gpu --lib --locked --offline shader_cache::tests: 12 passed, 0 failed. These cover warm hits, translation failures, damaged/truncated entries, write failures and linked/masked key variants.

  • The chunk-boundary test also pins a digest obtained by compiling the unchanged CacheKey implementation from main 5fabb46e, so compatibility does not rely only on comparing the two new API paths.

  • Release key-generation microbenchmark on i7-13620H (median of 9 batches of 32 calls):

    Container Concatenate + hash Borrowed hash Temporary allocated bytes, before / after
    4 KiB 2.862 us 2.665 us 4,128 / 0
    1 MiB 403.518 us 215.306 us 1,048,608 / 0
    16 MiB 6.707262 ms 3.808703 ms 16,777,248 / 0

    Compared CacheKey::new(converter, &[build, container].concat()) with CacheKey::new_parts(converter, &[build, container]), checking equal keys. Allocation counted through a forwarding system allocator. This measures only key generation, not disk reads, complete cache lookups, startup time or FPS. Larger inputs demonstrate allocation scaling; they are synthetic, not a measured distribution of game shaders.

  • For shader changes, wave sizes tested: no GPU shader dispatch; emitted shaders are unchanged.

  • cargo test passed for the crates it touches: full pipeline suite yes; focused GPU shader-cache tests yes. The full GPU/workspace suites were not completed locally; no full-suite pass is claimed.

  • cargo clippy --workspace --all-targets --all-features --locked --offline -- -D warnings: stops at the same five existing findings on clean main 5fabb46e and this commit, compared by diagnostic and location: font.rs:213,260 (argument counts), menu.rs:667 (is-multiple-of), panel.rs:602,668 (collapsible if). Existing repair #4680 covers them; no unrelated fixes are bundled here.

  • cargo xtask policy --staged: 2 files OK. git diff --cached --check: passed.

Checked for overlap

  • Searched open and closed PRs/issues for shader-cache copies, allocations, CacheKey parts and concatenation; inspected the open-PR file listing. Related: #2072 shares same-key cold misses through a gate, but still constructs contiguous input; this change only avoids the warm-hit input copy. #1012 and #636 change cache fallback/integrity behavior and retain the joined input. Cache-key configuration work and stale-key-test repairs are separate concerns. No competing implementation of borrowed-part cache hashing was found.

AI-assisted implementation and review with OpenAI Codex.

**@⁠VazirAPI** on GitHub · 2026-12-01 12:03 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4864) `VazirAPI:perf/shader-cache-input` → `main` · +40 −3 · 2 files · 1 commits · open ## What it changes Every shader-cache lookup first allocated and copied the build fingerprint and the entire shader container into a joined input buffer, including validated warm hits. Hash the two borrowed slices directly and allocate contiguous converter input only after a miss. `CacheKey::new_parts` produces exactly the same hash as `CacheKey::new` over the concatenated input. Existing keys, cache format and translator fingerprint stay unchanged. Translation, corruption handling, cache-write failures and miss publication retain their existing paths. This removes one container-sized temporary allocation and copy per warm lookup; it does not remove hashing or decoded-output allocations. ## How it was tested - Tested commit: `44e5288ce1ee94c0140169abce3a37e7a73c490d` (same tree as the final local checks). - GPU and profile: CPU-only synthetic cache inputs on Windows 11; no game files, game run or FPS measurement. - Toolchain: pinned Rust 1.98.1, native `x86_64-pc-windows-gnu` with MinGW. MSVC and upstream CI are not claimed here. - Before: added borrowed-input API tests failed to compile because the API was absent. - After: `cargo test -p victory-pipeline --locked --offline`: 17 passed, 0 failed. Tests cover chunk boundaries including empty chunks, BLAKE3 block/chunk edges, converter versioning, and locating an entry written from contiguous input. - `cargo test -p victory-gpu --lib --locked --offline shader_cache::tests`: 12 passed, 0 failed. These cover warm hits, translation failures, damaged/truncated entries, write failures and linked/masked key variants. - The chunk-boundary test also pins a digest obtained by compiling the unchanged `CacheKey` implementation from main 5fabb46e, so compatibility does not rely only on comparing the two new API paths. - Release key-generation microbenchmark on i7-13620H (median of 9 batches of 32 calls): | Container | Concatenate + hash | Borrowed hash | Temporary allocated bytes, before / after | | --- | ---: | ---: | ---: | | 4 KiB | 2.862 us | 2.665 us | 4,128 / 0 | | 1 MiB | 403.518 us | 215.306 us | 1,048,608 / 0 | | 16 MiB | 6.707262 ms | 3.808703 ms | 16,777,248 / 0 | Compared `CacheKey::new(converter, &[build, container].concat())` with `CacheKey::new_parts(converter, &[build, container])`, checking equal keys. Allocation counted through a forwarding system allocator. This measures only key generation, not disk reads, complete cache lookups, startup time or FPS. Larger inputs demonstrate allocation scaling; they are synthetic, not a measured distribution of game shaders. - For shader changes, wave sizes tested: no GPU shader dispatch; emitted shaders are unchanged. - `cargo test` passed for the crates it touches: full pipeline suite yes; focused GPU shader-cache tests yes. The full GPU/workspace suites were not completed locally; no full-suite pass is claimed. - `cargo clippy --workspace --all-targets --all-features --locked --offline -- -D warnings`: stops at the same five existing findings on clean main 5fabb46e and this commit, compared by diagnostic and location: `font.rs:213,260` (argument counts), `menu.rs:667` (is-multiple-of), `panel.rs:602,668` (collapsible if). [Existing repair #4680](https://git.gtahub.st/github/trustno1-coder--VIctory-NVIDIA/pulls/4680) covers them; no unrelated fixes are bundled here. - `cargo xtask policy --staged`: 2 files OK. `git diff --cached --check`: passed. ## Checked for overlap - [x] Searched open and closed PRs/issues for shader-cache copies, allocations, `CacheKey` parts and concatenation; inspected the open-PR file listing. Related: #2072 shares same-key cold misses through a gate, but still constructs contiguous input; this change only avoids the warm-hit input copy. #1012 and #636 change cache fallback/integrity behavior and retain the joined input. Cache-key configuration work and stale-key-test repairs are separate concerns. No competing implementation of borrowed-part cache hashing was found. AI-assisted implementation and review with OpenAI Codex.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 12:04:25 +00:00
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/4865/head:github-bot/gh-4864'
git switch 'github-bot/gh-4864'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-4864'
git switch 'github-bot/gh-4864'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-4864'
git switch 'github-bot/gh-4864'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-4864'
git switch 'main'
git merge --squash 'github-bot/gh-4864'
git switch 'main'
git merge --ff-only 'github-bot/gh-4864'
git switch 'main'
git merge 'github-bot/gh-4864'
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/trustno1-coder--VIctory-NVIDIA!4865
No description provided.