GPU: add opt-in idle shader cache trimming #1584

Open
github-bot wants to merge 2 commits from github-bot/gh-1584 into main AGit
Owner

@⁠srijann07 on GitHub · 2026-11-24 19:28 UTC · original
srijann07:memory/trim-idle-shaders → main · +123 −7 · 2 files · 2 commits · open

Motivation

Related to #471. The shader cache retains every unique shader container for the lifetime of the process, even after all pipelines using it have been released.

Changes

  • Add opt-in VICTORY_TRIM_IDLE_SHADERS=1.
  • Sweep cache-only shader entries every 256 new cache entries.
  • Preserve shaders owned by active pipelines and workers.
  • Keep default behavior and disk shader cache unchanged.
  • Add documentation and three regression tests.

Verification

Limitations

Experimental and disabled by default. Not a hard memory cap or VRAM optimization. Cache sweeps run under a mutex and only on new entries. Evicted shaders may require additional translation. Synthetic payload savings are not measured process RAM savings. No in-game measurements or game assets used.

AI-assisted development.

**@⁠srijann07** on GitHub · 2026-11-24 19:28 UTC · [original](https://github.com/Marvisak/VIctory/pull/1584) `srijann07:memory/trim-idle-shaders` → `main` · +123 −7 · 2 files · 2 commits · open ## Motivation Related to #471. The shader cache retains every unique shader container for the lifetime of the process, even after all pipelines using it have been released. ## Changes - Add opt-in `VICTORY_TRIM_IDLE_SHADERS=1`. - Sweep cache-only shader entries every 256 new cache entries. - Preserve shaders owned by active pipelines and workers. - Keep default behavior and disk shader cache unchanged. - Add documentation and three regression tests. ## Verification - Standard and diagnostics Clippy: passed. - Workspace tests: 345 passed, 0 failed, 6 ignored. - All three new regression tests passed. - Synthetic retained shader payload reduced from 16 MiB to 64 KiB. - CI: https://github.com/srijann07/VIctory/actions/runs/45469217973 ## Limitations Experimental and disabled by default. Not a hard memory cap or VRAM optimization. Cache sweeps run under a mutex and only on new entries. Evicted shaders may require additional translation. Synthetic payload savings are not measured process RAM savings. No in-game measurements or game assets used. AI-assisted development.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:37:10 +00:00
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 01:31 UTC · original · edited 2026-11-25 06:21 UTC

Automated triage for the maintainers.

Merge candidate. Adds an opt-in VICTORY_TRIM_IDLE_SHADERS=1 that turns the SHADERS map in crates/victory-gpu/src/pipeline.rs into a ShaderCache which, every 256 new containers, drops entries whose Arc is held only by the cache. I checked that every other holder of an Arc<Shader> (pipelines, pipeline/make.rs pending jobs, pipeline/host.rs) keeps its own strong reference, so live shaders keep their identity and their translation; an evicted container is simply rebuilt (and retranslated or read from the disk cache) on next use. The default path is unchanged and the three tests exercise the cache directly. Note that no memory saving in the title has been measured yet; the README section says so.

Thanks for the rebase: it now merges cleanly with main (940d32f), so this is a full review of the new head.

CI: passing (check).


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 01:31 UTC · [original](https://github.com/Marvisak/VIctory/pull/1584#issuecomment-7149645088) · edited 2026-11-25 06:21 UTC <!-- victory-triage v1 head=1ba845ee1287321c87c247109a26807250fecc48 verdict=merge-candidate at=2026-11-25T06:20:58Z --> Automated triage for the maintainers. **Merge candidate.** Adds an opt-in `VICTORY_TRIM_IDLE_SHADERS=1` that turns the `SHADERS` map in `crates/victory-gpu/src/pipeline.rs` into a `ShaderCache` which, every 256 new containers, drops entries whose `Arc` is held only by the cache. I checked that every other holder of an `Arc<Shader>` (pipelines, `pipeline/make.rs` pending jobs, `pipeline/host.rs`) keeps its own strong reference, so live shaders keep their identity and their translation; an evicted container is simply rebuilt (and retranslated or read from the disk cache) on next use. The default path is unchanged and the three tests exercise the cache directly. Note that no memory saving in the title has been measured yet; the README section says so. Thanks for the rebase: it now merges cleanly with `main` (940d32f), so this is a full review of the new head. CI: passing (`check`). --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠srijann07 on GitHub · 2026-11-25 06:09 UTC · original

Rebased onto upstream main (940d32f). All conflicts have been resolved, and fresh Windows CI, both Clippy configurations and tests passed.

CI: https://github.com/srijann07/VIctory/actions/runs/45557268421

Ready for review. Thanks!

**@⁠srijann07** on GitHub · 2026-11-25 06:09 UTC · [original](https://github.com/Marvisak/VIctory/pull/1584#issuecomment-7154497387) Rebased onto upstream main (940d32f). All conflicts have been resolved, and fresh Windows CI, both Clippy configurations and tests passed. CI: https://github.com/srijann07/VIctory/actions/runs/45557268421 Ready for review. Thanks!
Author
Owner

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

Code review (concurrency/refcount audit) and RTX 5090 + WARP verification at head 1ba845ee1287 merged cleanly onto main (63bcca43c6a0):

  • Code review (crates/victory-gpu/src/pipeline.rs:953-964):
    • Opt-in (VICTORY_TRIM_IDLE_SHADERS == "1" cached in OnceLock<bool>), completely silent by default.
    • Thread safety of trim_idle() (Arc::strong_count(shader) > 1): because ShaderCache is exclusively guarded by SHADERS: Mutex<Option<ShaderCache>> and new clones can only originate from a lookup holding SHADERS or from an existing external Arc, observing strong_count == 1 under the lock guarantees no live external reference exists, preventing premature eviction with no nested lock acquisition. Amortized every 256 cache misses with shrink_to_fit() only on large shrink.
  • Verified (Windows 11, NVIDIA RTX 5090 + WARP, VICTORY_D3D12_DEBUG=1, Rust 1.98.1):
    • cargo xtask policy: 191 files ok; cargo clippy --locked -p victory-gpu --tests -- -D warnings (default + --features diagnostics): 0 warnings
    • shader_cache pipeline::: 30/30 passed default on RTX 5090; 33/33 passed (--features diagnostics) on both RTX 5090 and WARP (including all 3 new idle-trim tests).

LGTM.

**@⁠fuzeofficlal** on GitHub · 2026-11-26 01:03 UTC · [original](https://github.com/Marvisak/VIctory/pull/1584#issuecomment-7179379045) Code review (concurrency/refcount audit) and RTX 5090 + WARP verification at head `1ba845ee1287` merged cleanly onto `main` (`63bcca43c6a0`): - **Code review (`crates/victory-gpu/src/pipeline.rs:953-964`)**: - Opt-in (`VICTORY_TRIM_IDLE_SHADERS == "1"` cached in `OnceLock<bool>`), completely silent by default. - Thread safety of `trim_idle()` (`Arc::strong_count(shader) > 1`): because `ShaderCache` is exclusively guarded by `SHADERS: Mutex<Option<ShaderCache>>` and new clones can only originate from a lookup holding `SHADERS` or from an existing external `Arc`, observing `strong_count == 1` under the lock guarantees no live external reference exists, preventing premature eviction with no nested lock acquisition. Amortized every 256 cache misses with `shrink_to_fit()` only on large shrink. - **Verified (Windows 11, NVIDIA RTX 5090 + WARP, `VICTORY_D3D12_DEBUG=1`, Rust 1.98.1)**: - `cargo xtask policy`: `191 files ok`; `cargo clippy --locked -p victory-gpu --tests -- -D warnings` (default + `--features diagnostics`): 0 warnings - `shader_cache pipeline::`: **30/30 passed** default on RTX 5090; **33/33 passed** (`--features diagnostics`) on both RTX 5090 and WARP (including all 3 new idle-trim tests). LGTM.
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/1584/head:github-bot/gh-1584'
git switch 'github-bot/gh-1584'

Merge

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