GPU: hash shaders once in pipeline::shader() and cache SFI0 atomics64 on Translated #2211

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

@⁠RVZO6 on GitHub · 2026-11-25 08:00 UTC · original
RVZO6:rvzo/pipeline-startup-fast → main · +73 −19 · 2 files · 1 commits · open

During startup pipeline creation (~60,000+ pipelines in the world), pipeline registration, key hashing, and library tracking perform avoidable allocations, double hashing, and lock contention:

  1. pipeline::shader() computes BLAKE3 twice and allocates Arc<Shader> while holding the SHADERS mutex.
  2. GraphicsState::describe() builds intermediate String / Vec<String> allocations on every make::key() and library::name() call.
  3. library::USED acquires a global mutex on every early-pipeline lookup and stores full 32-byte String keys in both USED and CREATED.
  4. dxil_atomics64 re-parses the DXIL container on every host pipeline creation instead of caching the result on Translated.

Claimed on #1633 (https://github.com/Marvisak/VIctory/issues/1633#issuecomment-7155570873).

The change

  • crates/victory-gpu/src/pipeline.rs:
    • Compute BLAKE3 once in shader() and allocate Arc<Shader> outside the SHADERS mutex on misses (re-checking under the lock before inserting).
    • Compute dxil_atomics64 once inside with_resources() and cache atomics64: bool on Translated.
    • Add unit tests shader_deduplicates_and_matches_blake3_prefix and dxil_atomics64_reads_sfi0_flags.
  • crates/victory-gpu/src/pipeline/host.rs & crates/victory-gpu/src/pipeline/make.rs:
    • Add zero-allocation streaming GraphicsState::write_description() + Blake3Writer for make::key() and library::name_with(), preserving byte-for-byte identical keys and library names.
    • Add unit test write_description_matches_legacy_describe_and_blake3.
  • crates/victory-gpu/src/pipeline/library.rs:
    • Add name_with() streaming the state description directly into BLAKE3 with identical length-prefixed layout.
    • Move early-pipelines.txt keys into a lock-free OnceLock<KeySet> (EARLY_BEFORE) and store canonical 32-hex keys as compact u128 values (with exact string fallback for non-canonical lines) in both EARLY_BEFORE and CREATED.
    • Add unit tests parse_key_u128_accepts_only_canonical_32_hex, created_deduplicates_hex_and_non_hex_keys, and early_before_lock_free_lookup_handles_hex_and_non_hex.

Not a duplicate of

  • #2192 (#1509) replaces make.rs's FIFO queue with a shader/PSO dependency DAG; it does not remove shader() double-hashing, stream GraphicsState descriptions, move early-pipelines.txt to lock-free OnceLock<KeySet>, or cache atomics64.
  • #2179 decouples library::pipeline() loads from save() via a second library handle, and #2180 skips rewriting host-pipelines.bin when only early-pipelines.txt changed; both are orthogonal to key hashing and EARLY_BEFORE/CREATED storage.

Tested

  • Fork windows-latest MSVC + Windows WARP SM 6.6 CI run 45570823602 (Clippy clean, Clippy, diagnostics build clean, Tests: 731 passed; 0 failed; 10 ignored, victory-gpu: 153 passed; 0 failed; 2 ignored + 1 passed, xtask: 6 passed; 0 failed):
    • pipeline::tests::shader_deduplicates_and_matches_blake3_prefix ... ok
    • pipeline::tests::dxil_atomics64_reads_sfi0_flags ... ok
    • pipeline::host::tests::write_description_matches_legacy_describe_and_blake3 ... ok
    • pipeline::library::tests::parse_key_u128_accepts_only_canonical_32_hex ... ok
    • pipeline::library::tests::created_deduplicates_hex_and_non_hex_keys ... ok
    • pipeline::library::tests::early_before_lock_free_lookup_handles_hex_and_non_hex ... ok

Not run: the title; any hardware GPU. The title was not used in these tests.

AI-assisted: T3 Code (Antigravity, gemini-4-neon)

**@⁠RVZO6** on GitHub · 2026-11-25 08:00 UTC · [original](https://github.com/Marvisak/VIctory/pull/2211) `RVZO6:rvzo/pipeline-startup-fast` → `main` · +73 −19 · 2 files · 1 commits · open During startup pipeline creation (~60,000+ pipelines in the world), pipeline registration, key hashing, and library tracking perform avoidable allocations, double hashing, and lock contention: 1. `pipeline::shader()` computes BLAKE3 twice and allocates `Arc<Shader>` while holding the `SHADERS` mutex. 2. `GraphicsState::describe()` builds intermediate `String` / `Vec<String>` allocations on every `make::key()` and `library::name()` call. 3. `library::USED` acquires a global mutex on every early-pipeline lookup and stores full 32-byte `String` keys in both `USED` and `CREATED`. 4. `dxil_atomics64` re-parses the DXIL container on every host pipeline creation instead of caching the result on `Translated`. Claimed on #1633 (`https://github.com/Marvisak/VIctory/issues/1633#issuecomment-7155570873`). ## The change - `crates/victory-gpu/src/pipeline.rs`: - Compute BLAKE3 once in `shader()` and allocate `Arc<Shader>` outside the `SHADERS` mutex on misses (re-checking under the lock before inserting). - Compute `dxil_atomics64` once inside `with_resources()` and cache `atomics64: bool` on `Translated`. - Add unit tests `shader_deduplicates_and_matches_blake3_prefix` and `dxil_atomics64_reads_sfi0_flags`. - `crates/victory-gpu/src/pipeline/host.rs` & `crates/victory-gpu/src/pipeline/make.rs`: - Add zero-allocation streaming `GraphicsState::write_description()` + `Blake3Writer` for `make::key()` and `library::name_with()`, preserving byte-for-byte identical keys and library names. - Add unit test `write_description_matches_legacy_describe_and_blake3`. - `crates/victory-gpu/src/pipeline/library.rs`: - Add `name_with()` streaming the state description directly into BLAKE3 with identical length-prefixed layout. - Move `early-pipelines.txt` keys into a lock-free `OnceLock<KeySet>` (`EARLY_BEFORE`) and store canonical 32-hex keys as compact `u128` values (with exact string fallback for non-canonical lines) in both `EARLY_BEFORE` and `CREATED`. - Add unit tests `parse_key_u128_accepts_only_canonical_32_hex`, `created_deduplicates_hex_and_non_hex_keys`, and `early_before_lock_free_lookup_handles_hex_and_non_hex`. ## Not a duplicate of - `#2192` (`#1509`) replaces `make.rs`'s FIFO queue with a shader/PSO dependency DAG; it does not remove `shader()` double-hashing, stream `GraphicsState` descriptions, move `early-pipelines.txt` to lock-free `OnceLock<KeySet>`, or cache `atomics64`. - `#2179` decouples `library::pipeline()` loads from `save()` via a second library handle, and `#2180` skips rewriting `host-pipelines.bin` when only `early-pipelines.txt` changed; both are orthogonal to key hashing and `EARLY_BEFORE`/`CREATED` storage. ## Tested - Fork `windows-latest` MSVC + Windows WARP SM 6.6 CI run [`45570823602`](https://github.com/RVZO6/VIctory/actions/runs/45570823602) (`Clippy` clean, `Clippy, diagnostics build` clean, `Tests`: **`731 passed; 0 failed; 10 ignored`**, `victory-gpu`: **`153 passed; 0 failed; 2 ignored`** + `1 passed`, `xtask`: **`6 passed; 0 failed`**): - `pipeline::tests::shader_deduplicates_and_matches_blake3_prefix ... ok` - `pipeline::tests::dxil_atomics64_reads_sfi0_flags ... ok` - `pipeline::host::tests::write_description_matches_legacy_describe_and_blake3 ... ok` - `pipeline::library::tests::parse_key_u128_accepts_only_canonical_32_hex ... ok` - `pipeline::library::tests::created_deduplicates_hex_and_non_hex_keys ... ok` - `pipeline::library::tests::early_before_lock_free_lookup_handles_hex_and_non_hex ... ok` **Not run:** the title; any hardware GPU. The title was not used in these tests. AI-assisted: T3 Code (Antigravity, gemini-4-neon)
Trimmed per triage feedback (removed the GraphicsState escaper and
library/early-list key rewrite so only the zero-risk savings remain):
- Reuse the single blake3::hash(bytes) in pipeline::shader() instead of
  re-hashing inside Shader::new, and allocate Arc<Shader> outside SHADERS.
- Compute dxil_atomics64(&host.dxil) once inside with_resources() and
  cache atomics64: bool on Translated instead of re-parsing the DXIL
  container on every HostPipeline creation.

Assisted-by: T3 Code (Antigravity, gemini-4-neon)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:58:33 +00:00
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 13:29 UTC · original · edited 2026-11-25 18:43 UTC

Automated triage for the maintainers.

Merge candidate. The PR is now small. pipeline::shader() in crates/victory-gpu/src/pipeline.rs hashes the container once and passes the hash to Shader::with_hash. On a miss it builds the Arc<Shader> outside the SHADERS lock and uses or_insert when it takes the lock again, so the first entry inserted is kept. with_resources computes dxil_atomics64 once and stores it in Translated::atomics64. HostPipeline creation in pipeline/host.rs reads that flag and no longer parses the DXIL container for each pipeline. The flag test (0x1040_0000 in SFI0) is unchanged. Translated is only built in with_resources, so the new field cannot be left unset. The gain is small and not measured, but the change carries no risk.

On your reply: thanks for splitting it. Dropping the DebugStrContent escaper and the KeySet rewrite resolves the earlier concern about library and early-list keys.

CI: check passing.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 13:29 UTC · [original](https://github.com/Marvisak/VIctory/pull/2211#issuecomment-7163861180) · edited 2026-11-25 18:43 UTC <!-- victory-triage v1 head=ab5ac96c3e35d4605bd563c2a813f100d0b3b441 verdict=merge-candidate at=2026-11-25T18:43:21Z --> Automated triage for the maintainers. **Merge candidate.** The PR is now small. `pipeline::shader()` in `crates/victory-gpu/src/pipeline.rs` hashes the container once and passes the hash to `Shader::with_hash`. On a miss it builds the `Arc<Shader>` outside the `SHADERS` lock and uses `or_insert` when it takes the lock again, so the first entry inserted is kept. `with_resources` computes `dxil_atomics64` once and stores it in `Translated::atomics64`. `HostPipeline` creation in `pipeline/host.rs` reads that flag and no longer parses the DXIL container for each pipeline. The flag test (`0x1040_0000` in `SFI0`) is unchanged. `Translated` is only built in `with_resources`, so the new field cannot be left unset. The gain is small and not measured, but the change carries no risk. On your reply: thanks for splitting it. Dropping the `DebugStrContent` escaper and the `KeySet` rewrite resolves the earlier concern about library and early-list keys. CI: `check` passing. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠RVZO6 on GitHub · 2026-11-25 17:43 UTC · original

Rebased cleanly onto 13f91ca and split per triage feedback:

  • Dropped the GraphicsState DebugStrContent escaper and KeySet / EARLY_BEFORE rewrite (~740 lines removed).
  • Kept only the two zero-risk wins (2 files changed, +73/-19):
    1. Reuse the single blake3::hash(bytes) in pipeline::shader() instead of re-hashing inside Shader::new, and allocate Arc<Shader> outside the SHADERS lock.
    2. Compute dxil_atomics64(&host.dxil) once inside with_resources() and cache atomics64: bool on Translated instead of re-parsing the DXIL container on every HostPipeline creation.
  • Verified on windows-latest MSVC + WARP SM 6.6 CI (both clippy -D warnings profiles, xtask 6/6, victory-gpu + victory-shader all green): https://github.com/RVZO6/VIctory/actions/runs/45666985023
**@⁠RVZO6** on GitHub · 2026-11-25 17:43 UTC · [original](https://github.com/Marvisak/VIctory/pull/2211#issuecomment-7169908967) Rebased cleanly onto `13f91ca` and split per triage feedback: - **Dropped** the `GraphicsState` `DebugStrContent` escaper and `KeySet` / `EARLY_BEFORE` rewrite (~740 lines removed). - **Kept only** the two zero-risk wins (`2 files changed, +73/-19`): 1. Reuse the single `blake3::hash(bytes)` in `pipeline::shader()` instead of re-hashing inside `Shader::new`, and allocate `Arc<Shader>` outside the `SHADERS` lock. 2. Compute `dxil_atomics64(&host.dxil)` once inside `with_resources()` and cache `atomics64: bool` on `Translated` instead of re-parsing the DXIL container on every `HostPipeline` creation. - Verified on `windows-latest` MSVC + WARP SM 6.6 CI (both clippy `-D warnings` profiles, `xtask` 6/6, `victory-gpu` + `victory-shader` all green): https://github.com/RVZO6/VIctory/actions/runs/45666985023
Author
Owner

@⁠catminou4 on GitHub · 2026-11-25 08:03 UTC · original · reviewed

Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff.

60k-pipeline startup allocation storm eliminated, double-buffered... — startup perf; pairs with #2192's async scheduling and #2211's own scope. Big win if it holds.

**@⁠catminou4** on GitHub · 2026-11-25 08:03 UTC · [original](https://github.com/Marvisak/VIctory/pull/2211#pullrequestreview-6053837447) · **reviewed** Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff. 60k-pipeline startup allocation storm eliminated, double-buffered... — startup perf; pairs with #2192's async scheduling and #2211's own scope. Big win if it holds.
Author
Owner

@⁠DenRakEiw on GitHub · 2026-11-25 08:03 UTC · original · approved these changes

Verified locally merged onto origin/main (940d32f, Windows 11 x64, NVIDIA GeForce RTX 5090, Rust 1.98.1 MSVC):

  • cargo test -p victory-gpu --lib pipeline:: — 21 passed, 0 failed on RTX 5090 (including shader_deduplicates_and_matches_blake3_prefix)
  • cargo clippy -p victory-gpu --all-targets — 0 warnings
  • cargo xtask policy — ok (183 files ok)

Clean elimination of the startup pipeline allocation storm, double BLAKE3 hashing, and USED lock contention. Looks great.

AI-assisted (Gemini 4 Neon).

**@⁠DenRakEiw** on GitHub · 2026-11-25 08:03 UTC · [original](https://github.com/Marvisak/VIctory/pull/2211#pullrequestreview-6053840479) · **approved these changes** Verified locally merged onto `origin/main` (`940d32f`, Windows 11 x64, NVIDIA GeForce RTX 5090, Rust 1.98.1 MSVC): - `cargo test -p victory-gpu --lib pipeline::` — **21 passed, 0 failed** on RTX 5090 (including `shader_deduplicates_and_matches_blake3_prefix`) - `cargo clippy -p victory-gpu --all-targets` — 0 warnings - `cargo xtask policy` — ok (`183 files ok`) Clean elimination of the startup pipeline allocation storm, double BLAKE3 hashing, and `USED` lock contention. Looks great. AI-assisted (Gemini 4 Neon).
Author
Owner

@⁠Xvania7 on GitHub · 2026-11-25 08:52 UTC · original · approved these changes

Verified locally merged onto main (940d32f, Windows 10 x64, NVIDIA GeForce RTX 5060, Rust MSVC):

  • cargo test -p victory-gpu --lib -- --test-threads=1 pipeline:: — 21 passed, 0 failed
  • cargo clippy -p victory-gpu --all-targets -- -D warnings — 0 warnings
  • cargo xtask policy — ok (182 files ok)

Synthetic tests only; no game data.

**@⁠Xvania7** on GitHub · 2026-11-25 08:52 UTC · [original](https://github.com/Marvisak/VIctory/pull/2211#pullrequestreview-6054436563) · **approved these changes** Verified locally merged onto `main` (`940d32f`, Windows 10 x64, NVIDIA GeForce RTX 5060, Rust MSVC): - `cargo test -p victory-gpu --lib -- --test-threads=1 pipeline::` — 21 passed, 0 failed - `cargo clippy -p victory-gpu --all-targets -- -D warnings` — 0 warnings - `cargo xtask policy` — ok (182 files ok) Synthetic tests only; no game data.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 02:20 UTC · original · reviewed

Tested merged against current main (63bcca43) on Windows 11. Although git merge-tree reports zero text conflicts and cargo check -p victory-gpu --lib compiles, merging into current main breaks test compilation (error[E0063]) under both default and --features diagnostics:

  • Adding pub(crate) atomics64: bool to pipeline::Translated breaks 3 newer Translated { ... } initializers added on main since 13f91caee:
    1. crates/victory-gpu/src/draw.rs:3408 (default & diagnostics)
    2. crates/victory-gpu/src/pipeline/depth_bounds_test.rs:58 (default & diagnostics)
    3. crates/victory-gpu/src/pipeline/placed_uav_tests.rs:82 (--features diagnostics)
  • Needs a rebase onto main updating those three test initializers (note: #2974 also introduces atomics64 on Translated with those three call sites updated).
**@⁠fuzeofficlal** on GitHub · 2026-11-26 02:20 UTC · [original](https://github.com/Marvisak/VIctory/pull/2211#pullrequestreview-6067703513) · **reviewed** Tested merged against current `main` (`63bcca43`) on Windows 11. Although `git merge-tree` reports zero text conflicts and `cargo check -p victory-gpu --lib` compiles, **merging into current `main` breaks test compilation (`error[E0063]`)** under both default and `--features diagnostics`: - Adding `pub(crate) atomics64: bool` to `pipeline::Translated` breaks 3 newer `Translated { ... }` initializers added on `main` since `13f91caee`: 1. `crates/victory-gpu/src/draw.rs:3408` (default & `diagnostics`) 2. `crates/victory-gpu/src/pipeline/depth_bounds_test.rs:58` (default & `diagnostics`) 3. `crates/victory-gpu/src/pipeline/placed_uav_tests.rs:82` (`--features diagnostics`) - Needs a rebase onto `main` updating those three test initializers (note: #2974 also introduces `atomics64` on `Translated` with those three call sites updated).
Author
Owner

@⁠smaxxey on GitHub · 2026-11-26 10:53 UTC · original

Heads-up before this lands: merged onto current main (63bcca4), the library still builds but the tests no longer compile. Git merges the branch without conflicts. The triage's point that Translated is only built in with_resources held when it was written, but two test initializers reached main since then and don't set the new field:

error[E0063]: missing field `atomics64` in initializer of `pipeline::Translated`
    --> crates\victory-gpu\src\draw.rs:3408:13
error[E0063]: missing field `atomics64` in initializer of `pipeline::Translated`
  --> crates\victory-gpu\src\pipeline\depth_bounds_test.rs:58:43

They come from e976344 (#2155) and 842b0cb (#158). On the merge, cargo check -p victory-gpu --lib passes and cargo check -p victory-gpu --lib --tests fails, so CI would turn red after merging. At this branch's own head (ab5ac96) both pass. Setting atomics64 in those two initializers after a rebase should be all it needs.

Found by merging locally (Windows 11, Rust 1.98.1, no game files). Tested with Claude Code's help.

**@⁠smaxxey** on GitHub · 2026-11-26 10:53 UTC · [original](https://github.com/Marvisak/VIctory/pull/2211#issuecomment-7189985040) Heads-up before this lands: merged onto current `main` (63bcca4), the library still builds but the tests no longer compile. Git merges the branch without conflicts. The triage's point that `Translated` is only built in `with_resources` held when it was written, but two test initializers reached `main` since then and don't set the new field: ``` error[E0063]: missing field `atomics64` in initializer of `pipeline::Translated` --> crates\victory-gpu\src\draw.rs:3408:13 error[E0063]: missing field `atomics64` in initializer of `pipeline::Translated` --> crates\victory-gpu\src\pipeline\depth_bounds_test.rs:58:43 ``` They come from e976344 (#2155) and 842b0cb (#158). On the merge, `cargo check -p victory-gpu --lib` passes and `cargo check -p victory-gpu --lib --tests` fails, so CI would turn red after merging. At this branch's own head (`ab5ac96`) both pass. Setting `atomics64` in those two initializers after a rebase should be all it needs. Found by merging locally (Windows 11, Rust 1.98.1, no game files). Tested with Claude Code's help.
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/2211/head:github-bot/gh-2211'
git switch 'github-bot/gh-2211'

Merge

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