fix(vk): the overlays let go what a present's copy read only after every present still on the GPU #1536
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/renderer
area/saves
area/tooling
area/upscaling
beanstalk: approved
beanstalk: failed
beanstalk: needs approval
beanstalk: running
beanstalk: tested
ci: approved
good first issue
gpu/amd
gpu/igpu
gpu/intel
gpu/nvidia
help wanted
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
needs measurements
platform/linux
platform/macos
platform/steam-deck
platform/windows
preview
priority
critical
priority
high
priority
low
regression
risk
high
risk
low
risk
medium
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
ci: approved
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!1536
Loading…
Reference in a new issue
No description provided.
Delete branch "pmwork-personal/Longshot:fix/ui-frees-after-presents-in-flight"
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?
Type: fix · Risk: low · Tested on: Windows 11, RTX 5090 (NVIDIA 621.24) · Needs: the tester's RTX 5080 at 360 Hz (the report's PC), Linux and AMD (any frame generation at 3x or more)
TL;DR
With frame generation at 3x or more, Longshot's overlay (the Insert menu, the FPS counter) let go of its upload buffers
and old font textures 4 frames after their last use, but since #1362 up to 6 frames (8 from 4x) can still be on the GPU,
so the GPU could read memory already let go. A test-only log shows it on an RTX 5090; it is the likely cause of a
tester's lost GPU ("device lost") on an RTX 5080 seconds after choosing 3x, and at every start with 3x saved. The overlay
now waits as long as the most frames that can be in flight.
Breakdown
gpu/vk/vk_imgui.cpplet go of what a present's copy read 4 presents later ("present_image keepsthree frames in flight"); #1362 gave present_image up to
kPresentSlotsMax(8) frame slots and sends a set's copies tothe GPU together, behind the game's next frame, so at 3x and up a copy could read a buffer or a texture already gone.
kPresentSlotsMax + 1presents (as Dear ImGui's own vertex buffers,ImageCount).while the copy that read it was still on the GPU: main 10 of 44 in each of 3 runs, this PR 0 of 44 in 2 runs.
A second RTX 5080 report (#1491, DLSS FG at 2x) is not this bug: 2x keeps 4 frame slots, which the old wait covered.
Why
A tester (RTX 5080, NVIDIA 621.24, 1920x1080 at 360 Hz, V-Sync Auto, Reflex On) stepped Frame generation from Auto to 2x
to 3x by Built-in FG in the Insert menu: 8 s after 3x the device was lost (
submit 81189 failed (-4),0 checkpoints).With 3x saved, every start lost the device 5 s in, at the start-up screen. Auto (3 frame slots) and 2x (4) were safe: the
overlay's 4 presents covered them. 3x takes 6 slots, 4x and up 8 (
present_slots_for, docs/design.md section 13 rule 4).Since #1442 the same slots apply under FIFO too (V-Sync On, and Auto with DLSS FG), so every present mode is
exposed at 3x and up, not only mailbox and immediate. The checkpoints are on the replay's recordings, not the present's
copies: hence 0. The crash message named
RX_VK_PRESENT_QUEUE=0; the presents' own queue (#1476) does not make theselet-gos (the same 10 of 44 with it off, below). #1491 (another RTX 5080 on 621.24, DLSS FG at 2x, a lost device at the
start-up logo since nightly-458) cannot be this bug and may be the queue's: not this PR's, and asked there separately.
Reported by null (nullifyshot) on Discord, with the log and both crash records.
See #1362, #1442, #1476, #1491.
How to reproduce
Seen on: Windows 11 build 26300, RTX 5080, NVIDIA 621.24, 1920x1080 at 360 Hz (the tester's report); on an RTX 5090
(NVIDIA 621.24) the let-gos show in the test-only log below, without a lost device
Settings and switches: Frame generation 3x (or more), Frame generation by Built-in FG, V-Sync Auto, Frame pacing Off,
NVIDIA Reflex On; main
310e7c9dSteps: save Frame generation at 3x and start the game; or in play, open the Insert menu and step Frame generation to
3x, then change rows that add glyphs (Menu size, the FPS counter).
Expected: the game runs.
Actual: the device is lost seconds later (
vk: FATAL: the GPU device was lost).What changed
The overlay now keeps what a present's copy read until every copy that can still be on the GPU is done:
kPresentSlotsMax + 1presents instead of 4. A game-free test models present_image's frame slots, and the design notessay what the slots bound.
gpu/vk/vk_imgui.cpp:kFramesLater(how many presents the overlay keeps what it let go) iskPresentSlotsMax + 1,not 4; the comment says why.
tests/test_ui_texture_upload.py,tests/ui_texture_upload_test.cpp: the windowed cases and a newring-destroymodelpresent_image's ring (
present_slots_for,kPresentSlotsMax, cut from the sources): nothing let go while a copy thatread it can still be on the GPU, and let go after. Fails on main: "an upload's staging buffer, let go 4 presents after
the copy that used it, while present_image keeps 8 copies in flight".
docs/design.mdsection 13 rule 4: the slots also bound what a copy reads;kFramesLatercarries that rule'sdoc:anchor, and
tests/test_doc_anchors.pykeeps it there.gpu/vk/vk_internal.h:kPresentSlotsMax's comment names bothof its followers.
docs/tested/2026-11-17-overlay-frees-*.md: the seven runs below.Measurements
Verdict: fixed. On main at 3x the overlay let go 10 of 44 staging buffers while the present copy that read them was
still on the GPU, in each of 3 runs; with this PR 0 of 44 in 2 runs. The RTX 5090 here did not lose the device either way
(the freed memory stays mapped in its block, and the GPU reads stale bytes): the counts are the evidence, not a crash.
Hardware: Windows 11 Pro build 26300, RTX 5090, NVIDIA 621.24, AMD Ryzen 7 9800X3D, 64 GB, 5120x2160 at 165 Hz (G-Sync)
Scene: the start-up screen and the title (the tester's second crash: 5 s after each start); then a save in play in Hyrule
Market (child), the tester's map
Method: main
310e7c9dand this branch as measured (60911109; since rebased onto4b68c42bas50bc545c, the same code with reworded comments, itsdoc:anchor and that anchor's row), each with one test-only DIAGNOSTIC commit that is not in this PR (presentcopies numbered by frame slot in
vk_replay.cpp;vk_imgui.cppreapasks whether the copy that read what it lets go isdone, and logs each that is not);
dev_packs.pypacks on one base (nightly-396 @7887c497). Settings: the Launcher's, withFrame generation 3x, Frame generation by Built-in FG, V-Sync Auto (mailbox), Frame pacing Off. Each run: 75 s from the start
with 3x saved, then the control bridge changes Menu size, the FPS counter and Frame generation (2x, 3x, 4x) every 4 s for
75 s (each needs new glyphs: uploads, and lets go of old ones), then quits. Runs in turn: main, this PR, main with
RX_VK_FG_TIMELINE=0, main withRX_VK_PRESENT_QUEUE=0, main, this PR.How to reproduce: the DIAGNOSTIC commit's two hunks below on the build to check, the settings above,
longshot_ctl.py option setfor the rows.310e7c9d310e7c9d310e7c9dThe numbers still hold on main
4b68c42b: of the 4 commits since310e7c9d(#1496, #1497, #1500, #1473), none touchesvk_imgui.cpp,present_slots_fororkPresentSlotsMax, and #1496's changes invk_framegen.cppact under FIFOonly (these runs were mailbox) or add a log that is off by default.
Flags and settings
None: this PR adds or changes no switch, menu row or ini key.
RX_VK_FG_TIMELINE=0andRX_VK_PRESENT_QUEUE=0were run above only to tell the causes apart.
A replay of the tester's own session (his settings from the report over the Launcher's; in play in Hyrule Market, the Insert
menu driven by its keys: Upscaler DLSS to FSR 3.1 and back, Render resolution down to Ultra Performance and back to DLAA,
Frame generation Off, Auto, 2x, 3x, Frame generation by through its three makers, then Menu size and the FPS counter
changed with the menu open) on main: the swapchain made again as in his log (mailbox, 6 then 8 images), 46 let go, 0 while
their copy was on the GPU, no device lost: in play this GPU kept up within 4 presents.
Testing
Tested:
tester's session on main (also FSR 3.1 FG and DLSS FG); no device lost or crash, with main or with this PR.
python -I -B tests/run_all.pyon 60911109 (before the rebase; the 4 commits since touch none of these files) (Windows, llvm-mingw clang 23): 666 passed, 53 failed, 48 skipped; the 53fail on main
310e7c9dtoo (the 44 of main415a8944on this PC, and 9 newer ones run on main here: test_compute_warm_apart,test_dev_packs, test_draw_stream_visibility, test_fsr_image_retirement, test_invalidate_quick, test_libc_hooks,
test_psychov35_fsr3_fg, test_sdiv_overflow, test_switch_table).
tests/test_ui_texture_upload.pypasses here and failson main; with
kFramesLater = kPresentSlotsMax - 1it fails again.Not testable by hand: the tester's 360 Hz display and RTX 5080.
Not tested: Linux, AMD, Intel (the same code; no other path), and a Linux build (the new line uses
kPresentSlotsMaxas the same file's Dear ImGui
ImageCountalready does).Must be tested:
Insert menu, expecting no device lost (by hand: the reporter; asked to try
RX_VK_FG_TIMELINE=0andRX_VK_PRESENT_QUEUE=0meanwhile, one at a time, which tells this bug from the queue).Risks
What could break: nothing that I know of. What the overlay lets go now lives 9 presents instead of 4: a few MB to
tens of MB for a moment when the font atlas grows several times at the start-up screen; a given-up texture keeps its
descriptor set longer (Dear ImGui's pool has 16; if it ran out, the overlays skip a frame, as before); headless
(
RX_VK_SHOT_MENU) it takes 9 menu shots before anything is let go; and up to 9 presents' worth instead of 4 is stillheld at exit.
Turning it off: none needed;
RX_VK_FG_TIMELINE=0(3 frame slots) or Frame generation 2x avoided it before.Compatibility: Nothing changes: saves, longshot_options.ini, caches and the vk ABI as before.
Issues
See #1362, #1442, #1476
Checklist
Everyone
type(scope): description) of the status line's type.can't be run by hand is in Testing's Not testable by hand, with why.
in Risks.
main.python -I -B tests/run_all.pypasses (any failure that also fails onmainis named).third_party/untouched (a new folder with aPROVENANCE.mdinstead).When it applies
Assisted-by:/Co-Authored-By:trailers.docs/tested/for each new measured run (format indocs/tested-configurations.md).mainand passing here.tests/that reads changed source updated in this PR, not weakened.🤖 Generated with Claude Code
Assisted-by: Claude Code
Co-Authored-By: Claude Opus 5.5 [email protected]
test_ui_texture_upload now models present_image's ring of frame slots (vk_replay.cpp present_slots_for, up to kPresentSlotsMax): in a window, the wait for a frame slot is all that tells the CPU a present's copy is done, so what the overlays recorded into the copy of present P may still be read until present P + the ring's slots. The windowed cases and the new ring-destroy (a texture Dear ImGui gives up when its atlas grows) check that nothing is let go before that, and that it is let go after. Fails on main: vk_imgui.cpp lets them go 4 presents later ("present_image keeps three frames in flight"), while frame generation on the game's timeline keeps up to 8 copies in flight since #1362. Co-Authored-By: Claude Opus 5.5 <[email protected]> Assisted-by: Claude Codevk_imgui.cpp let go of its staging buffers and the textures Dear ImGui gives up 4 presents after their last use ("present_image keeps three frames in flight"). Since #1362, frame generation on the game's timeline keeps a frame slot per frame of two sets (present_slots_for: 6 at 3x, 8 from 4x up; under FIFO too since #1442) and sends a set's copies to the GPU together, behind the game's next frame, so at 3x and up a copy could still read a buffer or a texture already let go. A test-only log showed it on an RTX 5090 (10 of 44 let-gos at 3x, no lost device there); it is a likely cause of a tester's lost device on an RTX 5080 (NVIDIA 621.24, Built-in FG, 8 s after 3x was chosen, and 5 s after every start with 3x saved), not reproduced. kFramesLater is now kPresentSlotsMax + 1, one spare as Dear ImGui's own vertex buffers (ImageCount), with its docs/design.md anchor (section 13 rule 4, which now says what the slots also bound) and its row in tests/test_doc_anchors.py. Co-Authored-By: Claude Opus 5.5 <[email protected]> Assisted-by: Claude CodeTested in game: Windows 11 Pro 26300, RTX 5090, NVIDIA 621.24, 5120x2160 at 165 Hz: frame generation 2x, 3x and 4x by Built-in FG at V-Sync Auto (mailbox), at the start-up screen and the title with Menu size, the FPS counter and Frame generation changed every 4 s, main and this branch in turn, two runs each, with a test-only log of each overlay let-go while its present copy was still on the GPU: main 10 of 44 in each run, this branch 0 of 44; no device lost, crash or missing overlay either way. A replay of the tester's own session in play (Hyrule Market, the Insert menu driven by its keys, FSR 3.1 FG and DLSS FG too) on main: no device lost.