gpu: pool: reuse GPU-completed texture pieces by fence instead of waiting 5 s #364
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/lobomfz--VIctory-xmem!364
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-364"
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?
@lucamzanon on GitHub · 2026-12-03 20:14 UTC · original
lucamzanon:xmem/6-vram-reclaim→main· +564 −100 · 1 files · 3 commits · openProblem
On 16 GB cards (e.g., RX 9070 XT at 4K RT),
TEXTURESpool pieces returned topool.rswaited a fullREST = 5000 msbefore becoming reusable or letting their containing 64 MiB block retire back to VRAM. During those 5 s, the 1/s sweep saw no VRAM relief and kept evicting, amplifying VRAM peaks (~94% usage) and texture churn (no_room_passes,made_again) — related to #269.Changes (
crates/victory-gpu/src/pool.rsonly)ebf2bc3—pool: what goes empty is the caller's to retire:take/take_ripeso whole freed blocks are returned to the caller forhost::retireinstead of dropped inline.(taken, dropped)fromtake_piece(eliminatingpool.rs'sclippy::too_many_argumentswarning).d9346bb—pool: pieces the card is through with are used again at once:free_from = STARTED + queued() + FENCE_LAG (128 = BURY_LAG)on returnedTEXTURESpieces (staging remains clock-based since it is system RAM).Pool::by_fence(finished)gated by an O(1)leastwatermark immediately releases fence-completed pieces whentake_pieceneeds room (before allocating new blocks) and duringroom()'s 1/s sweep, keepingRESTas fallback.STARTED + queued() + 128 <= FINISHEDcriterion ashost::retire/bury, with zero extra COM/vkd3d calls.Verification & A/B/B/A Results (RX 9070 XT 16 GB / Ryzen 7 5700X, Linux RADV)
pool.rsunit tests pass;cargo checkandcargo test --no-run(x86_64-pc-windows-msvc) pass; 0 clippy warnings inpool.rs.VICTORY_BENCH=rt, 1440p → 4K FSR 4 Quality, no FG, scripted moving gameplay viadiag+VICTORY_KEYS_FILE, 94,199 warm pipelines):4m x 4, moving)26.50 fps/13.00 GB(13.0/13.0)26.95 fps/12.75 GB(12.7/12.8)3m x 4, moving)25.60 fps/13.00 GB(13.1/12.9)25.60 fps* /12.65 GB(12.7/12.6)Peak VRAM dropped on 4/4 interleaved pairs across both scenes with 0 crashes. (Prison Run 3 coincided with an unrelated background compile on the test host and is excluded from the clean FPS line; clean Run 2 was
25.60 fps, 1% low10.70vs baseline10.30.)@Kal0s-design on GitHub · 2026-12-03 20:59 UTC · original
Tested
d9346bbon Windows 11, native MSVC build, toolchain 1.98.1. The D3D12 tests ran on one NVIDIA desktop card. I only built and tested victory-gpu. I didn't run anything in game.Checking the fence rule
free_from = STARTED + queued() + FENCE_LAG, compared against FINISHED, is the same testhost::retireuses.retirestampsnewest_submission()(host.rs:377-378 on main) andburydrops onceat <= finished - BURY_LAG(host.rs:393). So a pooled piece is never reused sooner than main would destroy a committed texture let go at the same moment. Usually it waits longer than that. The host texture is let go throughretire(resource.rs, plus the descriptor slots at descriptor/host.rs:3099), soReclaim::releasenormally fires insidebury, andgivethen stamps another 128 on top. Lists that are open or still waiting in the line get the same cover they get today, no more and no less.The rest looks fine to me:
GetCompletedValue, then the store at host.rs:4172), so it never runs ahead of the card.resting,least,resting_bytes) is under the pool mutex. A stale FINISHED read only delays reuse.saturating_add, andrested()passes 0, which can never reachleast.droppedreturn ends up inlet_go/retire(pool.rsroom,staging,texture_with_growth). Sinceebf2bc3the only inline drop was in the test-onlytake_ripe, and that's gone.Two places where the margin is now smaller than before. Neither is new, and both need a D3D12 call to fail first:
Signal/SetEventOnCompletionfailed (host.rs:4724 warns, then 4732 stores).retirealready has that exposure for whole objects. For pool pieces the cover goes from 5 s to about 128 submissions.SignalorSetEventOnCompletionfails at texture/ahead.rs:288/291 afterExecuteCommandLists,finish(jobs)(:269) drops the jobs, andJob::copy(:42) can be the lastArc<HostTexture>. Then the piece goes back stamped on the main queue's count while the copy might still be running. Before this PR that case had the 5 s of REST to hide behind.In practice both of these mean a device that is already gone, so I wouldn't hold the PR on them. I couldn't build a local test for either without injecting D3D12 failures.
Tests
pool::tests, 12 plus the 3 card_pool ones the filter also picks up): 20/20 runs in debug and 20/20 in release, all passing.cargo test -p victory-gpu --lib -- --test-threads=4 --skip descriptor::tests::views_die_with_their_resource:842767a: 309 / 5 / 230b652f8: 338 / 5 / 23indirect::tests::host_list_*, two inpipeline::host::tests, and the watch test that is flaky here anyway.Clippy
cargo clippy -p victory-gpu --all-targets: thetoo_many_argumentswarning ontake_pieceis gone, and pool.rs has no warnings left. victory-gpu goes from 27 to 26 warnings, nothing new.AI-assisted: yes
@joaowtrdev on GitHub · 2026-12-03 22:10 UTC · original
Tested this together with #354 on an RX 9070 XT at 4K with FSR 4 Performance and RT on: 1% low 6.9 → 7.9 and presents over 100 ms 64 → 44 per minute while driving, same average fps, no device lost. Details in the comment on #354: #354
Since I tested both at once, I can't tell how much of that is this PR. My release log has no per-second VRAM line, so I couldn't check the peak you measured. If there is a switch or a log line that shows it, I can run this one alone against
main.@fsrajner on GitHub · 2026-12-03 22:17 UTC · original
Tested this on an RX 9070 XT at 4K with RT, together with #354 (and #351/#352) on top of main. In this scene (the intro, about 2 minutes) it made no measurable difference for us. A longer run with more texture streaming might show it better.
Setup: RX 9070 XT 16 GB, Ryzen 7 7800X3D, CachyOS, RADV from this repo's
setup.sh(Mesa 26.3.1 + patches). Series X, 3840x2160 output, FSR 4 Quality (4.1.2), RT at defaults, headless gamescope. Same save (the intro), the game stops 120 s after the first press; metric over the 5 sstats: framewindows after loading. 2 runs per variant, main =6064c04.UNIFORM_GUEST_LOADS=1+CLUSTER_GUEST_LOADS=1UNIFORM_GUEST_LOADS=1+CLUSTER_GUEST_LOADS=1Run-to-run spread here is about ±1 ms/frame, and the worst window moves between 56 and 72 ms, so all of these are within noise.
@Luxuride on GitHub · 2026-12-04 12:20 UTC · original
The fence half is good and its tests are better than the rest of the pool code — it is just already inside another open PR, so please don't spend more time here.
What I checked:
rest_msfield andwith_rest(most, fenced, rest_ms)on top of yourby_fencework. That is the one to review; this branch is the safer half alone, so if the maintainer distrusts the 250 ms staging rest, take this one instead — not both.resting_bytes,least,free == BLOCK − out − resting, 4000 random ops) is exactly what this pool always needed. It should survive the rebase onto the combined branch.crates/victory-gpu/src/pool.rs:353callsself.spares(...)fordroppedright afterby_fencemade blocks whole and before theself.kept(...)retry. A block the fence just emptied can be handed tohost::retire— a 64 MiB heap freed and rebuilt — even though the space it freed would have served the take in progress. Your own test encodes that churn as intended; retryingkeptfirst and only collecting spares if it fails would be better.by_fencereports "any piece freed" rather than "any block whole", so reclaim does a fullsparesscan on partial frees. Harmless, one line from precise.173 behind, no conflict.
d9346bbd10to69cb811078@lucamzanon on GitHub · 2026-12-04 12:57 UTC · original
Thanks @Luxuride! Rebased onto
main(0fd7614) and applied both pool improvements in69cb811so this stays clean as the standalone fence-only option if preferred over the combined 250 ms staging-rest PR:take_piecenow retriesself.kept(...)before callingself.spares(...)afterby_fence, so a block just emptied by the fence serves the allocation in progress instead of being retired and immediately rebuilt.by_fencenow returns(freed_any, whole_any)sosparesonly runs when a block actually became whole (not on partial frees).blocks_made_whole_by_the_fence_go_back_at_onceand re-verified 15/15pool::testsunder Wine + 0 clippy warnings inpool.rs.@joaowtrdev — sorry for the late reply! On Linux with AMD/RADV we sampled
/sys/class/drm/card*/device/mem_info_vram_usedonce per second from an external loop alongside the game; you can also build with--profile diag --features diagnostics(or enableVICTORY_PANEL=full) for per-frame telemetry.github-bot referenced this pull request2026-12-05 11:18:26 +00:00
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.