perf(vk): no bursts at 13 fps with video memory at the driver's limit #2401
Closed
msxdan wants to merge 2 commits from
perf/vram-limit-stalls into main
pull from: perf/vram-limit-stalls
merge into: MagicBeanDev:main
MagicBeanDev:main
MagicBeanDev:github/pr/2893
MagicBeanDev:github/pr/2890
MagicBeanDev:github/pr/2887
MagicBeanDev:github/pr/2878
MagicBeanDev:github/pr/2875
MagicBeanDev:github/pr/2874
MagicBeanDev:github/pr/2873
MagicBeanDev:github/pr/2871
MagicBeanDev:github/pr/2756
MagicBeanDev:github/pr/2897
MagicBeanDev:github/pr/2896
MagicBeanDev:github/pr/2718
MagicBeanDev:github/pr/2842
MagicBeanDev:github/pr/2691
MagicBeanDev:github/pr/2895
MagicBeanDev:github/pr/2743
MagicBeanDev:github/pr/2765
MagicBeanDev:github/pr/2708
MagicBeanDev:github/pr/2732
MagicBeanDev:github/pr/2755
MagicBeanDev:github/pr/2817
MagicBeanDev:github/pr/2876
MagicBeanDev:release-please--branches--main
MagicBeanDev:release-please--branches--main--release-notes
MagicBeanDev:github/pr/2778
MagicBeanDev:github/pr/2888
MagicBeanDev:github/pr/2866
MagicBeanDev:github/pr/2877
MagicBeanDev:github/pr/2800
MagicBeanDev:github/pr/2829
MagicBeanDev:github/pr/2850
MagicBeanDev:github/pr/2889
MagicBeanDev:github/pr/2882
MagicBeanDev:github/pr/2860
MagicBeanDev:github/pr/2849
MagicBeanDev:github/pr/2886
MagicBeanDev:github/pr/2794
MagicBeanDev:github/pr/2840
MagicBeanDev:github/pr/2830
MagicBeanDev:github/pr/2834
MagicBeanDev:github/pr/2719
MagicBeanDev:github/pr/2742
MagicBeanDev:github/pr/2741
MagicBeanDev:github/pr/2820
MagicBeanDev:github/pr/2771
MagicBeanDev:github/pr/2859
MagicBeanDev:github/pr/2858
MagicBeanDev:github/pr/2823
MagicBeanDev:github/pr/2757
MagicBeanDev:github/pr/2769
MagicBeanDev:github/pr/2844
MagicBeanDev:github/pr/2843
MagicBeanDev:github/pr/2673
MagicBeanDev:github/pr/2855
MagicBeanDev:github/pr/2739
MagicBeanDev:github/pr/2807
MagicBeanDev:github/pr/2851
MagicBeanDev:github/pr/2789
MagicBeanDev:github/pr/2814
MagicBeanDev:github/pr/2818
MagicBeanDev:github/pr/2774
MagicBeanDev:github/pr/2772
MagicBeanDev:github/pr/2750
MagicBeanDev:github/pr/2786
MagicBeanDev:github/pr/2785
MagicBeanDev:github/pr/2782
MagicBeanDev:github/pr/2779
MagicBeanDev:github/pr/2775
MagicBeanDev:github/pr/2706
MagicBeanDev:github/pr/2766
MagicBeanDev:github/pr/2747
MagicBeanDev:github/pr/2759
MagicBeanDev:github/pr/2745
MagicBeanDev:github/pr/2740
MagicBeanDev:github/pr/2733
MagicBeanDev:github/pr/2725
MagicBeanDev:github/pr/2727
MagicBeanDev:github/pr/2728
MagicBeanDev:github/pr/2729
MagicBeanDev:github/pr/2721
MagicBeanDev:github/pr/2722
MagicBeanDev:github/pr/2715
MagicBeanDev:github/pr/2714
MagicBeanDev:github/pr/2707
MagicBeanDev:github/pr/2703
MagicBeanDev:github/pr/2705
MagicBeanDev:github/pr/2697
MagicBeanDev:github/pr/2679
MagicBeanDev:github/pr/2676
MagicBeanDev:github/pr/2669
MagicBeanDev:docs/what-hookshot-connects-to
MagicBeanDev:fix/hdr-encode-test
MagicBeanDev:fix/main-tests
MagicBeanDev:fix/play-cache-files
MagicBeanDev:perf/game-barrier-order
MagicBeanDev:feat/heap-lazy
MagicBeanDev:feat/texture-detail
MagicBeanDev:perf/astc-opaque-bc1
MagicBeanDev:fix/fs-dir-lock
MagicBeanDev:fix/framegen-native-kept
MagicBeanDev:fix/update-no-downgrade
MagicBeanDev:port/k10-gcn-f16-mirrors
MagicBeanDev:fix/framegen-mult-cap
MagicBeanDev:chore/release-as-2.1.1
MagicBeanDev:perf/pcache-load-switch
MagicBeanDev:fix/prepare-progress-log
MagicBeanDev:fix/update-closes-stale-game
MagicBeanDev:fix/hdr-scaled-sampled
MagicBeanDev:perf/first-start-preset
MagicBeanDev:perf/zero-upload
MagicBeanDev:fix/vcore-escape-2s
MagicBeanDev:test/fake-gh-atomic
MagicBeanDev:perf/batch-idle-flush
MagicBeanDev:test/finish-stub-a
MagicBeanDev:chore/record-2.1.0
MagicBeanDev:fix/main-red-tests
MagicBeanDev:fix/test-display-startup-driver-cache
MagicBeanDev:feat/mesh-shader-mode
MagicBeanDev:fix/menu-probes-at-startup
MagicBeanDev:fix/fps-counter-classic
MagicBeanDev:fix/test-log-batch-flake
MagicBeanDev:fix/narrow-screen-hud
MagicBeanDev:ci/prereleases
MagicBeanDev:release/v2.0.15
MagicBeanDev:hotfix/v2.0.15
MagicBeanDev:fix/present-ahead-replay
MagicBeanDev:release/v2.0.13
MagicBeanDev:fix/bracket-paths-2013
MagicBeanDev:fix/hdr-overlays-2013
MagicBeanDev:fix/fps-counter-scale-2013
MagicBeanDev:fix/stick-seen-at-rest
MagicBeanDev:hotfix/menu-fits-screen
MagicBeanDev:fix/f1-always-opens-menu
MagicBeanDev:fix/ini-keep-lines
MagicBeanDev:claude/cranky-pike-7cf247
MagicBeanDev:perf/texture-answer-flat
MagicBeanDev:fix/stamp-test-modules
MagicBeanDev:fix/appimage-fonts
MagicBeanDev:fix/display-awake
MagicBeanDev:release/v2.0.12
MagicBeanDev:fix/discord-windows
MagicBeanDev:rc/v2.0.12-tests
MagicBeanDev:fix/dlss-keep-feature
MagicBeanDev:rc/v2.0.12
MagicBeanDev:button-icons
No reviewers
Labels
Clear labels
accessibility
Barrier affecting people with disabilities
autorelease: pending
autorelease: tagged
bug
Something isn't working
dependencies
Pull requests that update a dependency file
documentation
Improvements or additions to documentation
duplicate
This issue or pull request already exists
enhancement
New feature or request
github_actions
Pull requests that update GitHub Actions code
good first issue
Good for newcomers
help wanted
Extra attention is needed
invalid
This doesn't seem right
question
Further information is requested
testing wanted
wontfix
This will not be worked on
No labels
accessibility
autorelease: pending
autorelease: tagged
bug
dependencies
documentation
duplicate
enhancement
github_actions
good first issue
help wanted
invalid
question
testing wanted
wontfix
Milestone
Clear milestone
No items
No milestone
Assignees
Clear assignees
No assignees
1 participant
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Hookshot!2401
Loading…
Reference in a new issue
No description provided.
Delete branch "perf/vram-limit-stalls"
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?
In Hyrule Castle Town's market on a 12 GB card the game drops to about 13 fps for seconds at a time. Video memory is at the driver's limit there, the GPU falls a frame or more behind, and every submit then waits 40-60 ms for it.
What changed
Two changes to what happens once video memory is at the driver's limit:
vk_timeline_waitgives up after 8 ms, not 250 (gpu/vk/vk_replay.cpp). The wait is a capture's, for a page the GPU writes back that the CPU wrote too (the exposure meter's). With the GPU behind it was 40-60 ms of the game's main thread or of the presenting one at every submit. Past the timeout the page is copied as it is, which is what already happened after 250 ms.gpu/vk/vk_texture.cpp,texture_frame): 55% of what the driver allows from 90% used, 47% from 94%, 40% from 97%, kept until the count is back under 85%. At the limit nothing squeezed while VMA's blocks had room, and the blocks keep what an eviction frees, so the count stayed at the limit and the driver paged. It is not the budget from the start: Hyrule Field fits at 91% with 5.5 GB of textures, and held to 4 GB it made 2000 more uploads in 76 s.No new switches.
How it was tested
RTX 5070 12 GB, driver 615.78.08, Linux (CachyOS, KDE Wayland), Ryzen 9 9900X, 2560x1440 output, frame generation off. Played by hand, a save loaded in Kokiri Forest, then the market by the Cheats page's teleport and a walk round the plaza with the camera turning. Numbers are from
RX_VK_FRAME_TRACE=1, frames outside the loads.Same options, same code base (
49f75dc8), caches already used on both sides:49f75dc8(96 s)On main the stalls come as two bursts, 15 s and 25 s long, with nearly every frame at 75-100 ms and ~60 ms of it memory sync.
What that table does not isolate: the build on the right also carried other changes of mine that are not in this pull request (upload bytes written by their own threads, the executable's code kept in memory on Linux, program cache reads on a worker, and
RX_VK_GPL=1). The two timings this pull request is about are the ones that moved, but I have not measured these two commits alone against main.Later sessions, same PC and options:
RX_VK_GPLand on main at1ceaa2ba, with these two commits plus the upload threads and the Linux one: 52-61 fps in the market, the 8 ms timeout hit once in the session.python -I -B tests/run_all.py: 329 pass here; the 6 that fail fail the same way on main at1ceaa2baon this PC (nozstandard, nolibtk, the local clang on two fixtures).Not tested on Windows, on AMD or Intel cards, or on cards with less than 12 GB.
What could go wrong
Related issues
None of these was tested on its reporter's PC, so this does not claim to fix them.
VRAM: 10250 MB used of 10616 MB allowedwith the texture budget at 6144 MB,memory syncat 15-35 ms of a frame's replay time, and 10-23 fps in the town.a capture's wait for write-back ... timed outeach time. That is the wait this pull request cuts to 8 ms; the GPU time there is long for other reasons, which this does not touch.Assisted-by: Claude Fable 5.2
Co-Authored-By: Claude Fable 5.2 [email protected]
Thanks, this is a careful write-up, and the honesty about what the table doesn't isolate helps a lot. The problem is real (#2398's log matches yours). I have two concerns before this goes in, and one question about how it fits with the other VRAM work.
1. The 8 ms timeout applies on every GPU, not just at the VRAM limit. By default (
RX_VK_CAPTURE_WAIT=2) this wait is the replay thread's, intake_capture, for the exposure meter's late pages. That wait is what fixed the one-frame exposure flashes (40-120 a minute in Kokiri Forest, see the comment incapture_make). On any GPU-bound card the GPU sits a frame behind as a matter of course, with no memory pressure at all. A 3060 Ti or 4050 at 30-40 fps will often be more than 8 ms behind, so the stale copy would become the normal path there and bring the flashes back. Under 250 ms it was a rare fallback. Details inline.2. The step down near the limit hasn't been tried on small cards, and it bypasses the guards just below it. On an 8 GB card the default budget is already 45% of the allowance, so the 40% step is what bites there. Once a card reaches 97% it's held at 40% until the count is under 85%. With compaction off, the blocks keep what an eviction frees, so on 4-8 GB cards that may never happen: a cap 11% under the default for the rest of the session. The step also ignores
room_in_blocks, which was added because squeezing at 97% while the blocks had 1.2 GB free emptied a paused game's textures on a 4 GB RX 5500M. A fixed cap doesn't ratchet the way the old one did, so it's milder, but it's the same situation. This is the same open point we raised on #2198: fixed 90%/97% rules that now apply to 8 GB cards by default, with no test below 12 GB. A run on an 8 GB card (Hyrule Field, then the market) would settle it.3. Overlap with #2198. Both PRs go after the same thing: the count stuck at the limit because freed texture memory stays inside VMA's blocks. #2198 turns compaction on by default, which gives that space back and holds the count at 85% (80% reserve), and it evicts only long-unused textures. The camera-turn thrash it fixes (2.3-2.6 GB of live textures let go every 600 presents) is exactly what a cruder cap would bring back. If both land, this step runs before the hold. When it sets the lower budget,
held < budgetis false,evict_tostays 0, and the plain 7/8 eviction runs in place of #2198's long-unused-only pass. So this PR wouldn't fix #2198's open point, and it would partly override #2198. Could you try the market on main withRX_VK_COMPACT=1(or on #2198's branch) without the step? If compaction alone gets the count off the limit, the step may not be needed. If it doesn't, the step should probably defer to the hold when compaction is on. Both PRs touch the same lines oftexture_frame, so whichever lands second needs a rebase.Related: #2368 (keep GPU-drawn textures) and #2154 (keep mirrors) don't touch these paths. #2288's ASTC counting is merged and this branch already has it.
Smaller things:
vk_timeline_wait's signature line (vk_replay.cpp:266) still says "at most 250 ms".RX_VK_GPL=1.CI: only the title check is showing, and it's still pending. The build and test workflows haven't run on this branch yet, and it's 19 commits behind main.
Holding off on approving until there's a run on an 8 GB card and an answer on the compaction question.
@ -276,0 +277,4 @@if (vkWaitSemaphores(dev.device, &wi, 8000000ull) == VK_TIMEOUT) {static std::atomic<int64_t> n{0};if (const int64_t k = ++n; k == 1 || k % 100 == 0)logf("vk: a capture's wait for write-back %llu went on without it after 8 ms (done %llu): %lld so far", (unsigned long long)v,On every GPU-bound system, not only at the VRAM limit, the GPU is regularly more than 8 ms behind the last submission that writes the exposure page back. When that happens,
take_capturecopies the late pages without their write-back, and the mirror sync puts the GPU's older words back over the newer ones. That brings back the one-frame exposure flash that this wait exists to prevent (seecapture_make). Could the short timeout be used only while VRAM is pressed (compact.pressed/ the step below is active), with 250 ms kept otherwise? Or could you show with a frame-by-frame check on a slower card that the flashes don't come back?@ -3898,0 +3890,4 @@// kept until the count is back under 85%. At the limit nothing below squeezes while the blocks have room, and the blocks keep// what an eviction frees, so the count stayed there: the driver paged and the replay waited for the GPU in bursts of seconds// (Hyrule Castle Town's market on a 12 GB card). Not from the start: Hyrule Field fits at 91%, and uploads more with lessif (known && !vram_env) {This runs before the compaction's hold and before the
room_in_blocksguard, and it ignores both. With #2198's compaction on by default, a 40-55% cap set here makesheld < budgetfalse, so the hold's long-unused-only pass gives way to a plain 7/8 eviction. With compaction off, it squeezes even when the blocks hold an eighth of the allowance free (the 4 GB RX 5500M case). Maybe skip it whencompact_on(), and respectroom_in_blocks?@ -3898,0 +3902,4 @@} else if (used < allowed / 100 * 85) {tight = 0;}if (tight) budget = std::min(budget, allowed / 100 * (tight == 3 ? tight_pct : tight == 2 ? tight_pct + 7 : tight_pct + 15));On an 8 GB card the default
ownis 45% of the allowance, so step 3 (40%) cuts about 11% for as long as the count stays over 85%. With compaction off, that's probably the rest of the session on small cards. A run on an 8 GB card would show whether the scene's working set fits under 35% (7/8 of 40%), or whether this turns into the evict-and-upload loop that the description's last risk mentions.Thanks for the review. I ran what you asked for, and you are right on the main point: compaction alone gets the count off the limit here, so I am closing this in favour of #2198.
Same PC as in the description (RTX 5070 12 GB, driver 615.78.08, Linux, 2560x1440, frame generation off), main at
1ceaa2baplus test-only switches to turn each part on and off in one build. An input script loads a save in Kokiri Forest, teleports to the market and walks round the plaza with the camera turning for 83 s; frames counted from the arrival,RX_VK_FRAME_TRACE=1. Two runs each unless said.RX_VK_COMPACT=1RX_VK_COMPACT=1with the step (one run)What I take from it:
RX_VK_COMPACT=1afterwards: 48-65 fps in the market, no frame with over 20 ms of memory sync, the count at 88%.I will try #2198's branch on this card and the same route and post the numbers there.