GPU: reduce shader and pipeline RAM usage (Weak cache, deflate containers, 32 MiB DXIL cache) #2972
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2974"
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?
Imported from Marvisak/VIctory. Originally posted by 0xKaji on 2026-11-26T01:50:52Z.
Summary
SHADERScache & pruning (pipeline.rs): storeWeak<Shader>in the global shader map with periodic pruning instead of retaining every shader forever.Pending::graphics& failed containers (pipeline.rs,make.rs): dropGraphicsStateonceHostPipeline::newfinishes and clearShader::containerif translation fails.Shader::containerin RAM (pipeline.rs): deflate containers >= 1 KiB withminiz_oxide(level 1) while kept in memory.pipeline.rs,pipeline/host.rs): keep translated DXIL bytecode in a 32 MiB FIFO cache instead of retaining every translated DXIL buffer inTranslated, reloading on miss fromshader_cachevia the compressed container. (Note: cachingatomics64onTranslatedand hashing once inShader::newalso overlaps slightly with #2211.)Testing
cargo xwin check --tests --profile diag -p victory-gpu --features diagnostics --target x86_64-pc-windows-msvc --lockedpasses cleanly.unreferenced_shaders_are_released_from_cache,dxil_cache_evicts_oldest_past_cap,large_shader_containers_are_stored_compressed,graphics_state_is_released_after_make) pass under Wine (RTX 3060).Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T02:09:04Z.
Review: COMMENTED
Reviewed and verified against
main(63bcca43) on Windows 11 (RTX 5090 + WARP,VICTORY_D3D12_DEBUG=1) — clean design, thread-safe, and ready to merge:miniz_oxidewith--locked(zero new dependencies).SHADERS,Shader.container, andDXIL_CACHEnever nest);HostPipeline::newretainsVec<Option<Arc<[u8]>>>across PSO creation andrectangle_gsso bytecode pointers stay valid;Shader::dxil()falls back throught.host.dxil->DXIL_CACHE->shader_cache::host_shader(&container)cleanly;Pending.graphicsis safely dropped afterPending::make()completes.shader()computesblake3::hash(bytes)once beforeShader::new()computes it again, and deflate compression runs while holding theSHADERSmutex — compressing/hashing before locking would cut contention during bulk shader loads.)Local verification:
victory-gpu(VICTORY_D3D12_DEBUG=1): RTX 5090 and WARP both passed defaultpipeline::27/27,shader_cache::4/4,draw::20/20, and--features diagnosticspipeline::30/30 (including all 4 new memory-reclamation unit tests)cargo clippy --all-targets -- -D warnings(default &--features diagnostics) +cargo xtask policy(191 files ok): 0 warningsImported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-26T02:32:47Z.
Review: COMMENTED
Verified all three mechanisms: (1) Weak shader cache prunes dead entries amortized at max(2*len,1024), and dedup still works among live pipelines holding Arcs. (2) container compression stores only when deflate actually wins, translation failure frees it entirely via Empty. (3) host.dxil moves to a bounded FIFO; dxil() correctly chains empty-slot -> RAM cache -> disk shader cache -> re-insert, and the Arc lives in dxils during CreateGraphicsPipelineState so bytecode pointers stay valid. atomics64 hoist to per-translation is right too.
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T05:30:33Z.
Automated triage for the maintainers.
This reduces RAM use in
crates/victory-gpu/src/pipeline.rsin three ways:SHADERSholdsWeak<Shader>with pruning, title containers of 1 KiB and up are deflated in memory (miniz_oxide, already a dependency), and translated DXIL moves out ofTranslatedinto a 32 MiB FIFODXIL_CACHE.HostPipeline::newfetches the DXIL through the newShader::dxil. The 64-bit-atomics check is hoisted intoTranslated::atomics64, which overlaps #2211. CI: passing.What it needs:
Shader::dxilcallsshader_cache::host_shaderon the inflated container. When there is no disk cache (CACHEunset), that is a full retranslation inside pipeline creation. With a disk cache it is a file read plus an inflate. The same happens for any DXIL over 32 MiB, whichDxilCache::insertnever keeps. Please show how often misses happen in a play session and what they cost, or keep the DXIL resident when there is no disk cache.Shader::containertoContainer::Empty. That is fine fortranslated()(itsOnceLockcaches the failure), but say so in a comment, sincecontainer_bytes()then returns nothing for that shader.atomics64: one should rebase on the other.Verdict: needs work. CI: passing.
Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by 0xKaji on 2026-11-26T12:22:45Z.
Addressed all triage and review notes:
Shader::translatednow only movest.host.dxilintoDXIL_CACHEwhenshader_cache::counts() > (0, 0)anddxil.len() <= DXIL_CACHE_BYTES. Without a disk cache (or for oversized DXIL),t.host.dxilstays resident soShader::dxil()never triggers a re-translation.Container::Emptyon failure: added comment notingself.translated'sOnceLockcachesNonepermanently, socontainer_bytes()is never needed again for failed shaders.SHADERSmutex:pipeline::shadernow computesblake3::hashonce and runs deflate compression before acquiring theSHADERSlock (per @fuzeofficlal's note).mainvs combined branch):Imported from Marvisak/VIctory. Originally posted by shortselow-byte on 2026-11-27T01:20:06Z.
In-game miss rate and cost of
DXIL_CACHE, measured on heade1630fb4ee(GTA VI, Series S profile, RX 6900 XT / RDNA 2, Ryzen 5 5600X, 16 GB RAM, disk shader cache warm with 25,756 shaders).To answer the triage's "how often misses happen in a play session and what they cost", I added a local measure-only counter to
Shader::dxil()(not proposed for the PR): hits, misses, and the time a miss spends incontainer_bytes()+shader_cache::host_shader.DXIL cache over one 330 s session (menus → world load → ~3 min in the world):
So with a disk cache, 5 misses in 3,007 lookups (0.17 %), 4.7 ms in total for the whole session. No miss after 172 s, and the host log's "being made" count stays at 0 from 148 s to the end (330 s) in the world. With a warm disk cache the eviction cost is negligible on this route. I did not test the no-cache case, which your latest push now keeps resident anyway.
Rust heap,
main63bcca4vs this PR, same binary profile (diag), same cache, one run each:main, 112 s on the PR): 1,865 → 1,671 MB (−194 MB).That is one run per side, so treat the memory figures as indicative only. Frame times are not comparable: on this 16 GB machine both world runs hit the system commit limit (
0x8007000E),mainaborted at 179 s, the PR run started logging allocation failures at ~324 s and was stopped by my script at 330 s. That is a property of the machine, not of the PR, so I am not counting it either way.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.