Repository navigation
Conversation
…ot 250 The wait is for a page the GPU writes back that the CPU wrote too (the exposure meter's). With the GPU a frame or more behind, as with video memory at the driver's limit in Hyrule Castle Town's market, it was 40-60 ms of the game's main thread or of the presenting one at every submit, frame after frame for seconds: bursts at 13 fps. Past 8 ms the page is copied as it is, as it already was after the 250 ms: at worst the exposure steps for a frame, where the frame was a stall.
… budget steps down At the limit nothing squeezed while VMA's blocks had room, and the blocks keep what an eviction frees, so the driver's count stayed there. In Hyrule Castle Town's market (6 GB of textures, the game's other 3.5-3.8 GB, 1.3-3 GB free but scattered in the blocks: 9985 of 10195 MB on an RTX 5070 12 GB) the driver paged, the replay waited ~60 ms a frame for the GPU in bursts of seconds, and at 100% the driver's own allocations stalled (vkAllocateMemory 50-115 ms a submit). The budget is held to 55% of what the driver allows from 90% used, 47% from 94%, 40% from 97%, and a step is kept until the count is back under 85%. Not the budget from the start: Hyrule Field fits with 5.5 GB of textures at 91%, and held to 4 GB it made 2000 uploads more in 76 s.
hckrman101
left a comment
There was a problem hiding this comment.
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, in take_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 in capture_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 < budget is false, evict_to stays 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 with RX_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 of texture_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:
- Nit: the comment on
vk_timeline_wait's signature line (vk_replay.cpp:266) still says "at most 250 ms". - Nit: the 8 ms change and the budget step are independent. Each of them, measured alone against main, would make this much easier to judge, since the table also carries the upload threads, the Linux one and
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.
| // GPU a frame or more behind (video memory at the driver's limit in Hyrule Castle Town's market) it was 40-60 ms of the | ||
| // game's main thread or the presenting one a submit, frame after frame for seconds. Past the 8 ms the page is copied as it is, | ||
| // as with no wait: at worst the exposure steps for a frame, where the frame was a stall | ||
| if (vkWaitSemaphores(dev.device, &wi, 8000000ull) == VK_TIMEOUT) { |
There was a problem hiding this comment.
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_capture copies 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 (see capture_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?
| // 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 less | ||
| if (known && !vram_env) { |
There was a problem hiding this comment.
This runs before the compaction's hold and before the room_in_blocks guard, and it ignores both. With #2198's compaction on by default, a 40-55% cap set here makes held < budget false, 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 when compact_on(), and respect room_in_blocks?
| } 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)); |
There was a problem hiding this comment.
On an 8 GB card the default own is 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 1ceaa2b plus 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,
What I take from it:
I will try #2198's branch on this card and the same route and post the numbers there. |
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 (49f75dc), caches already used on both sides:
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 at 1ceaa2b, 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 at 1ceaa2b on 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 noreply@anthropic.com