GPU: key the shader cache by the translator's sources, and keep early pipeline starts off the title's processors #147
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/fxceless--victory-fork!147
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-147"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@iurysf on GitHub · 2026-11-24 21:51 UTC · original
iurysf:shader-cache-key→main· +404 −45 · 6 files · 2 commits · openWhat's wrong
Two things make the first seconds after the game opens stutter whenever the pipeline library is large (it is after any run that reached the world) and the shader cache does not hold the current build's translations:
victory-gpu,victory-hleor the loader, adiagbuild beside areleaseone) starts with an empty cache. Every new executable translates its shaders again.What the fix does
victory-shader/build.rsandSOURCE_HASH: the BLAKE3 ofvictory-shader's sources (taken from Marvisak/VIctory#254 by wbkepler, with credit in the commit).shader_cache::build()keys entries by that hash and aCACHE_SCHEMA_VERSIONof this file's encoding, instead of the executable. It keeps the settings that change a translation (loop limit,group_sync, theVICTORY_WAVE_*andVICTORY_F16_NEARESTswitches,shader_opt), now in a smallkey()that is easy to extend.VICTORY_SHADER_CACHE_KEY=exekeys by the executable again.shader_cache::is_cached: whether an entry exists, without reading or translating.pipeline/make.rs: early work is limited toceil(workers / 4)workers (VICTORY_EARLY_WORKERS=N;0for no limit), and an early pipeline is made only if all its shaders are already translated or in the shader cache; the others stay for their first use. Requested pipelines (a draw wants them) go first and are not limited. A finished early pipeline wakes the others under the queue's lock (no lost wake-up).How it behaves after
A rebuild that does not touch
victory-shader(orshader_cache.rs's schema) keeps its cache. With an empty cache and a large library, the early starts no longer put the translator on every worker.Measured on an RTX 4070 (Ryzen 7 5800X3D, 32 GB), 40 s each, same bad condition for both: a 295 MiB pipeline library copied from an earlier run and an empty shader cache,
VICTORY_RELAY=2,VICTORY_PIPELINE_WAIT_MS=24, snapshot after the prologue, no capture:Builds: "before" is
4e17478+ #63 + the watchdog hooks and worker stacks of #28; "after" is that plus #71 and this PR (#71 changes the relay's copy-back queue, which the start-up screens do not use; the two builds were not otherwise identical). One run each.The sustained stutter is gone. Isolated holes of 1.1-1.6 s remain, with and without this change: one at 9-11 s (the title's boot-to-first-screen transition, with the GPU idle and nothing of ours in the log) and one more elsewhere between 25 and 36 s. They are not caused by the cache or the early starts; this PR does not claim to fix them.
Tests (
cargo test -p victory-gpu -- pipeline::make shader_cache, 12 pass; clippy clean forvictory-gpu,victory-shader,victory-pipeline): the key follows the translator, the loop limit and a wave switch and nothing else;SOURCE_HASHequals the digest ofvictory-shader/srcas it is now; an entry is found only for the key that stored it; the early limit (8 workers: 2, 4: 1, 5: 2, 1: 1; the setting wins, 0 is no limit); an early pipeline waits for a free early worker and a requested one does not; an early pipeline with no translation ready is skipped and still queues on its first use.Overlap and order
Looked for in the upstream open PRs and the fork's: Marvisak/VIctory#254 (the same stable key plus in-flight deduplication and an AOT
translate --write-cache: this PR takes only the key) and #1730 (translate --cache DIR, an AOT too). Neither is included: pre-translating the pack offline is the next step and complements this one (with a key that does not follow the executable, one offline run serves every build with the same translator). Fork PRs touching the same lines:cached()/host_shader; the entry is built incache_input()here, so the merge is one function. An offline pre-translation must run with the same wave width as the host.build()(portable heap, view heap limit): they become one more argument ofkey().build.rstovictory-shader(Agility SDK test exports): the two scripts have to be merged.Not covered: the translations are still made at first use when the cache has none; an offline pre-translation (the AOT) and the deduplication of concurrent translations of one shader are left for a follow-up.
AI-assisted.
@Revens2 on GitHub · 2026-11-25 05:13 UTC · original
Merging this PR on top of current main (
c96b4f2) conflicts inCargo.lockandcrates/victory-gpu/src/shader_cache.rs: main now also puts the view heap limit (probe_view_limit/view_heap_limit) into the cache key. The rebase has to keep that, or a translation cached without the clamp is served again on GPUs whose limit differs. I resolved it in a local integration branch by adding those bytes to the translator part of the key; it builds. Part of a combo with seven other PRs, it ran in the game 3 times: one run reached 900 s (median 4.95 fps), the other two stopped early (one device removed, one title breakpoint), which cannot be attributed to this PR (see #115). Not verified alone.View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.