GPU: a snapshot that fails to allocate frees the idle pool and tries once more #2153
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!2153
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2153"
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?
@desplmfao on GitHub · 2026-11-25 06:20 UTC · original
desplmfao:fix/snapshot-pool-472→main· +15 −1 · 1 files · 6 commits · openWhen a write snapshot needs a buffer and none in the idle pool fits,
pooledcallsVec::with_capacity. If that allocation fails, the process aborts, even though the idle pool may hold hundreds of MB that nothing is using.Change
crates/victory-gpu/src/shadow.rs,pooled(15 lines):try_reserve_exactfirst.snapshot allocation failed; freeing the idle pool, and reserves once more withreserve_exact. That still aborts if memory is really gone.give_backandPOOL_BYTESaremain's, unchanged.History
This PR started as #472 (by @SaymonMaster14) brought up to date with
main: an idle pool cap, a shared texture read buffer, and adstoragebuffer change.mainhas since done these its own way: a 512 MiB pool cap, and8f2a6f14for per-thread read buffers. As triage suggested, the PR is reduced to the one partmaindoesn't cover, the allocation retry. #472's commit is still in the branch history, but none of its changes are in the diff.How it was found
Reading
pooledwhile bringing #472 up to date withmain. I haven't seen this abort in a title run; it matters on hosts where commit is tight, such as 16 GiB machines under Wine.Tested
cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.shadow::tests on an RTX 5080 under Proton: 10 passed.AI-assisted (Claude Code).
🤖 Generated with Claude Code
@yualk on GitHub · 2026-11-25 07:01 UTC · original
Independent Windows x64 CPU-only probe on parent
940d32f69vs this exactd23e5d9, using each pin's realpooled/give_back, touched pages, andGetProcessMemoryInfo(PROCESS_MEMORY_COUNTERS_EX). Only the idle shadow pool was exercised; no title, GPU dispatch, texture staging, or DirectStorage inputs.[8,32,96]kept and reused all leases on both.[384,128,128]kept all 640 MiB on both (largest + 256 MiB spare), so this is not a hard 256 MiB total-idle cap. The absolute values include allocator overhead. These are controlled refill costs, not an FPS or live game commit claim. AI-assisted.@desplmfao on GitHub · 2026-11-25 08:08 UTC · original
Added
d389937: when a new snapshot buffer can't be allocated, the idle pool is freed and the allocation tried once more (try_reserve_exactfirst, so a failed attempt returns instead of aborting). The idea comes from fxceless/victory-fork#360 (avt0m4t48, credited in the commit). It only changes the out-of-memory path.cargo test -p victory-gpu shadow: 4 passed. Clippy is clean.@desplmfao on GitHub · 2026-11-25 08:33 UTC · original
@yualk thanks for the independent probe. That matches the intent: the largest idle buffer is always kept, and others only up to 256 MiB more, so
[384,128,128]keeping 640 MiB is by design, not a total cap. Keeping the largest is what saves most of the page faults on the hot path (the world's big heap snapshot). The extra faults you measured are the cost of refilling the smaller ones. In the game that cost didn't show up in frame time: 428–452 ms per world frame with this PR against 442–451 ms without it (RTX 5080, Linux/Proton), while the idle pool went from 2,040 MB to 111–214 MB.@Marvisak on GitHub · 2026-11-25 11:24 UTC · original · edited 2026-11-26 03:25 UTC
Automated triage for the maintainers.
Verdict: merge candidate. Thanks for splitting it as suggested. The diff is now only
crates/victory-gpu/src/shadow.rspooled: when no idle buffer fits, it callstry_reserve_exact; on failure it logs, clears the idle pool, and callsreserve_exactonce more, which still aborts if memory is really gone.give_backandPOOL_BYTESaremain's, somain's 512 MiB cap is unchanged.Checked: when the first attempt succeeds the second
reserve_exactis a no-op (capacity already ≥n), and with an empty pool the behaviour is the same asmain'sVec::with_capacity. So this only changes the out-of-memory path, as described.CI: passing (
check; one earlier run on the same head failed and the later run passed).Generated by Claude Code
@desplmfao on GitHub · 2026-11-25 11:30 UTC · original
Thanks for the triage. Done in
0f13780:staging_bytesindstorage.rsis back tomain's version, and this PR no longer touchesvictory-hle. It came along with the #472 rebase. As you say, the pool cap doesn't need it, and I have no evidence that the console counts the intermediate buffer, so it's out rather than moved. What's left is the pool cap (give_back,POOL_BYTES), the idle-pool retry beforereserve_exactaborts, and the shared textureSCRATCH. Clippy is clean.@desplmfao on GitHub · 2026-11-25 15:42 UTC · original
Merged
mainincb471dc(merge commit, no rebase).mainhas since covered part of this PR in its own way, so the PR is smaller now:main's8f2a6f14(a texture refresh reads into its thread's own buffer) does the same job, and I tookmain'stexture.rsas is.shadow.rs, about 40 lines againstmain): a snapshot grows in place instead of being made anew and copied; when an allocation fails, the idle pool is freed and it tries once more instead of aborting; and the pool keeps its largest buffer plus at most 256 MB / 8 others, wheremainnow keeps up to 512 MB in all.The 2 GB in the title was measured against
mainbefore its own 512 MB cap. Against today'smain, the saving is the difference between the two caps, which I haven't measured yet.shadow::tests: 8 passed under Wine; clippy clean.@desplmfao on GitHub · 2026-11-25 15:50 UTC · original
The
checkfailure oncb471dcisn't from this PR. The failing test isemit::memory_tests::heap_direct_texture_reads_mark_their_heap_indexinvictory-shader, and this PR only changesvictory-gpu/src/shadow.rs.main's own CI fails the same way atda82e444, the commit I merged.mainhas since added67e8ae14("Shader tests: the compute harness zeroes its UAVs"), whose CI is still running. Once that's green, I'll mergemainagain so this PR's CI follows.@desplmfao on GitHub · 2026-11-26 02:33 UTC · original
Split as suggested, in
c21a054.give_backandPOOL_BYTESaremain's again, somain's 512 MiB cap applies unchanged. As you pointed out, our rule could hold more than that. The PR is now only the allocation retry inpooled: try to reserve, and if that fails, free the idle pool and reserve once more. The diff is 15 lines inshadow.rs,shadow::gives 10 passed under Wine, and clippy is clean. The title is updated to match.@catminou4 on GitHub · 2026-11-25 06:33 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.
Idle snapshot pool memory capped (#472 rebased, 2 GB RAM) — memory-cap fix for long sessions; mixed gpu+hle, Windows-only.
@fuzeofficlal on GitHub · 2026-11-26 15:13 UTC · original · approved these changes
Reviewed
crates/victory-gpu/src/shadow.rsatc21a0542(already based onorigin/main63bcca43) and verified on RTX 5090 and WARP (VICTORY_D3D12_WARP=1) withVICTORY_D3D12_DEBUG=1.Allocation retry & state-safety audit
pooled(n)(crates/victory-gpu/src/shadow.rs:102-128), when no idle buffer fits,v.try_reserve_exact(n)(shadow.rs:117) runs first:POOLand the trailingv.reserve_exact(n)(shadow.rs:124) is a no-op (no second allocation).!pool.is_empty(), it logs a warning, releases the idle pool (pool.clear()atshadow.rs:122, freeing up toPOOL_BYTES= 512 MiB), and attemptsv.reserve_exact(n)once more — no retry loop, and if commit is still exhausted it aborts cleanly beforeShadow::writingmutatesself.beforesegments.POOLacross the clear-and-retry prevents another thread from refilling the pool or racing the retry;POOLis a leaf lock never nested with other locks.Verification
cargo run -p xtask -- policy: 191 files ok.cargo clippy -p victory-gpu --all-targets -- -D warnings(default and--all-features): clean.shadow::withVICTORY_D3D12_DEBUG=1: 10/10 passed on RTX 5090 and 10/10 passed on WARP (--features diagnostics).pooled(0), pool miss (verifying smaller pooled buffers remain intact whentry_reserve_exactsucceeds), and pool hit reuse (len() == 0, capacity preserved) passed cleanly.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.