[pr-performance][shaders] Hash shader cache keys without copying containers #253

Open
qnjk wants to merge 2 commits from qnjk/Darner:perf-shader-cache-key-without-copy into main
First-time contributor

Tested with a local Xbox build via offline shader warm-up. Gameplay and FPS were not measured.

Contributor role (optional)

  • Fluxer ID:

What it changes

On main, each disk-cache lookup constructs a temporary buffer containing the 32-byte build fingerprint followed by the shader container. This includes cache hits. Hash the two slices in order and pass the original container directly to the translator on a miss. A regression test reads an entry written under the original concatenated key.

How it was tested

  • Tested revision: f3840d73d3504c30218debfbc8795b9225447317 plus this patch, Rust 1.98.1 on Windows.

  • cargo test --locked -p darner-pipeline: 15 passed.

  • cargo test --locked -p darner-gpu --lib shader_cache::tests: 14 passed.

  • cargo xtask policy: 555 files passed.

  • cargo build --locked -p darner: passed. An offline darner translate <title-exe> --warm all --jobs 1 with an isolated cache translated 15 of 15 shaders on the first run. A second run served 15 of 15 from the cache. The executable's SHA-256 matched before and after.

  • Changes a default: no.

  • A/B result for key construction: a local counting-allocator probe used the original concatenation (A) and the split-input hash (B). Both produced the same key for synthetic inputs of 0, 64, 2048 and 65536 bytes. Each size was measured once per path.

    Synthetic container A B
    64 KiB 1 allocation, 65,568 bytes 0 allocations, 0 bytes
  • Gates run: both workspace Clippy gates passed. cargo test --workspace --locked failed at watch::tests::ask_once_by_res_splits_reservations_without_refusals (watch.rs:8614). I reproduced the same assertion on clean main using the test executable built by cargo test --locked -p darner-gpu --features record --lib, with --test-threads 12. PR #150 addresses it.

  • The darner-hle test executable passed 493 tests outside the sandbox with --test-threads=1, including tests which require loopback and NTFS hard links.

  • Between the serial workspace run and a run of the darner-shader test executable with --skip emit:: --skip oracle64::legacy_mul_forms_are_exact, 556 shader tests passed and 17 were marked ignored. The exhaustive multiplication oracle was stopped before completion.

  • Gameplay: offline shader warm-up only.

  • Shader wave sizes tested: no dedicated wave-size comparison.

  • Hardware dependence: the allocation probe covers CPU-side cache-key construction.

  • Coverage gaps: gameplay frame times and different GPUs.

Checklist

  • I ran this change in the game, or say below why it can't be (docs, tests only).
    • Both cache paths were exercised by offline warm-up with a local build.
  • This PR contains one change based on main.
  • The diff follows docs/asset-policy.md.
  • I recorded this PR's dependencies below.
    • Depends on: none

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches.
  • Related PRs: #32, #33, #38, #39, #40, #41, #43, #44, #45, #46, #47, #48, #49, #96, #142 share files. #142 changes preload selection and cache bookkeeping.
  • Replaces or overlaps: none found for the copy in cache-key construction.
Tested with a local Xbox build via offline shader warm-up. Gameplay and FPS were not measured. ## Contributor role (optional) - Fluxer ID: ## What it changes On main, each disk-cache lookup constructs a temporary buffer containing the 32-byte build fingerprint followed by the shader container. This includes cache hits. Hash the two slices in order and pass the original container directly to the translator on a miss. A regression test reads an entry written under the original concatenated key. ## How it was tested - Tested revision: `f3840d73d3504c30218debfbc8795b9225447317` plus this patch, Rust 1.98.1 on Windows. - `cargo test --locked -p darner-pipeline`: 15 passed. - `cargo test --locked -p darner-gpu --lib shader_cache::tests`: 14 passed. - `cargo xtask policy`: 555 files passed. - `cargo build --locked -p darner`: passed. An offline `darner translate <title-exe> --warm all --jobs 1` with an isolated cache translated 15 of 15 shaders on the first run. A second run served 15 of 15 from the cache. The executable's SHA-256 matched before and after. - Changes a default: no. - A/B result for key construction: a local counting-allocator probe used the original concatenation (A) and the split-input hash (B). Both produced the same key for synthetic inputs of 0, 64, 2048 and 65536 bytes. Each size was measured once per path. | Synthetic container | A | B | |---|---:|---:| | 64 KiB | 1 allocation, 65,568 bytes | 0 allocations, 0 bytes | - Gates run: both workspace Clippy gates passed. `cargo test --workspace --locked` failed at `watch::tests::ask_once_by_res_splits_reservations_without_refusals` (`watch.rs:8614`). I reproduced the same assertion on clean main using the test executable built by `cargo test --locked -p darner-gpu --features record --lib`, with `--test-threads 12`. PR #150 addresses it. - The `darner-hle` test executable passed 493 tests outside the sandbox with `--test-threads=1`, including tests which require loopback and NTFS hard links. - Between the serial workspace run and a run of the `darner-shader` test executable with `--skip emit:: --skip oracle64::legacy_mul_forms_are_exact`, 556 shader tests passed and 17 were marked ignored. The exhaustive multiplication oracle was stopped before completion. - Gameplay: offline shader warm-up only. - Shader wave sizes tested: no dedicated wave-size comparison. - Hardware dependence: the allocation probe covers CPU-side cache-key construction. - Coverage gaps: gameplay frame times and different GPUs. ## Checklist - [ ] I ran this change in the game, or say below why it can't be (docs, tests only). - Both cache paths were exercised by offline warm-up with a local build. - [x] This PR contains one change based on `main`. - [x] The diff follows `docs/asset-policy.md`. - [x] I recorded this PR's dependencies below. - Depends on: none ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. - Related PRs: #32, #33, #38, #39, #40, #41, #43, #44, #45, #46, #47, #48, #49, #96, #142 share files. #142 changes preload selection and cache bookkeeping. - Replaces or overlaps: none found for the copy in cache-key construction.
First-time contributor

Independent Windows build, gate, and code-read review of 4cc87e1d5 (based on main f3840d73d). Not run in-game.

Environment

  • Windows 11 Pro 26H2 (build 26300.10075), Intel Core i9-14900K, NVIDIA RTX A2000 12GB (driver 621.47), Rust 1.98.1 (x86_64-pc-windows-msvc), MSVC 19.44.35230.

Measured results

  • Gate 1 (cargo clippy --workspace --all-targets --locked -- -D warnings): PASS
  • Gate 2 (cargo clippy --workspace --all-targets --all-features --locked -- -D warnings): PASS
  • cargo xtask policy: PASS (asset policy: 555 files ok)
  • cargo test --locked -p darner-pipeline: PASS (15 passed; 0 failed in 0.07 s)
  • cargo test --locked -p darner-gpu --lib shader_cache: PASS (14 passed; 0 failed in 3.92 s, including new reads_shader_cache_entries_written_with_concatenated_keys)

Code-read audit

  • Bit-for-bit BLAKE3 key equivalence verified: CacheKey::from_parts (crates/darner-pipeline/src/cache.rs:22-31) streams converter.id().as_bytes(), [0], converter.version().to_le_bytes(), then each slice in parts (build, then container) with no extra length prefixes or separators. Because BLAKE3's streaming Hasher::update is strictly associative across arbitrary chunk boundaries, the resulting hash is identical to hashing [&build[..], container].concat() (verified across BLAKE3's 1024-byte chunk boundary by the new 2048-byte regression test).
  • Translate is private to crates/darner-gpu/src/shader_cache.rs; Translate::convert drops &input[32..] in lockstep with cache.convert_and_store(&key, &converter, container), and Cache::convert_and_store (crates/darner-pipeline/src/cache.rs:133-135) uses the caller's key directly without re-hashing input.

Verdict: PASS.

AI-assisted: yes (Gemini 4 Neon).

Independent Windows build, gate, and code-read review of `4cc87e1d5` (based on `main` `f3840d73d`). Not run in-game. ### Environment - Windows 11 Pro 26H2 (build 26300.10075), Intel Core i9-14900K, NVIDIA RTX A2000 12GB (driver 621.47), Rust 1.98.1 (`x86_64-pc-windows-msvc`), MSVC 19.44.35230. ### Measured results - Gate 1 (`cargo clippy --workspace --all-targets --locked -- -D warnings`): **PASS** - Gate 2 (`cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`): **PASS** - `cargo xtask policy`: **PASS** (`asset policy: 555 files ok`) - `cargo test --locked -p darner-pipeline`: **PASS** (`15 passed; 0 failed` in 0.07 s) - `cargo test --locked -p darner-gpu --lib shader_cache`: **PASS** (`14 passed; 0 failed` in 3.92 s, including new `reads_shader_cache_entries_written_with_concatenated_keys`) ### Code-read audit - **Bit-for-bit BLAKE3 key equivalence verified:** `CacheKey::from_parts` (`crates/darner-pipeline/src/cache.rs:22-31`) streams `converter.id().as_bytes()`, `[0]`, `converter.version().to_le_bytes()`, then each slice in `parts` (`build`, then `container`) with no extra length prefixes or separators. Because BLAKE3's streaming `Hasher::update` is strictly associative across arbitrary chunk boundaries, the resulting hash is identical to hashing `[&build[..], container].concat()` (verified across BLAKE3's 1024-byte chunk boundary by the new 2048-byte regression test). - `Translate` is private to `crates/darner-gpu/src/shader_cache.rs`; `Translate::convert` drops `&input[32..]` in lockstep with `cache.convert_and_store(&key, &converter, container)`, and `Cache::convert_and_store` (`crates/darner-pipeline/src/cache.rs:133-135`) uses the caller's `key` directly without re-hashing `input`. **Verdict:** PASS. AI-assisted: yes (Gemini 4 Neon).
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 'perf-shader-cache-key-without-copy:qnjk-perf-shader-cache-key-without-copy'
git switch 'qnjk-perf-shader-cache-key-without-copy'

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 'qnjk-perf-shader-cache-key-without-copy'
git switch 'qnjk-perf-shader-cache-key-without-copy'
git rebase 'main'
git switch 'main'
git merge --ff-only 'qnjk-perf-shader-cache-key-without-copy'
git switch 'qnjk-perf-shader-cache-key-without-copy'
git rebase 'main'
git switch 'main'
git merge --no-ff 'qnjk-perf-shader-cache-key-without-copy'
git switch 'main'
git merge --squash 'qnjk-perf-shader-cache-key-without-copy'
git switch 'main'
git merge --ff-only 'qnjk-perf-shader-cache-key-without-copy'
git switch 'main'
git merge 'qnjk-perf-shader-cache-key-without-copy'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
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
TrustNo1/Darner!253
No description provided.