GPU: reduce shader and pipeline RAM usage (Weak cache, deflate containers, 32 MiB DXIL cache) #2974
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!2974
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@0xKaji on GitHub · 2026-11-26 01:50 UTC · original
0xKaji:perf/shader-pipeline-memory→main· +315 −56 · 6 files · 5 commits · openSummary
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).@Marvisak on GitHub · 2026-11-26 05:30 UTC · original
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
@fuzeofficlal on GitHub · 2026-11-26 02:09 UTC · original · reviewed
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 warnings@kotekompotek on GitHub · 2026-11-26 02:32 UTC · original · reviewed
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.
@0xKaji on GitHub · 2026-11-26 12:22 UTC · original
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):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.