fix(vk): make the swapchain again when the window's held image never comes back #2083
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!2083
Loading…
Reference in a new issue
No description provided.
Delete branch "HumanBean/Longshot:fix/fg-held-image-remake"
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?
Summary
With frame generation on (the built-in one or FSR 3), on an RX 9070 XT under Windows in full screen, the picture froze after Alt+Tab while the game and its sound went on; leaving full screen (F11) brought it back. Five reports, still on nightly-617 and v3.0.0, and lately sometimes with no Alt+Tab at all.
The cause is in the hold that #1458 added for #1376. AMD's Windows driver hands an image back from
vkAcquireNextImageKHRat once and signals its fence once the system lets the image go. An image that isn't free within 250 ms is held, and every later present looks at it again without waiting, and presents nothing else. The system lets an image go when another one is shown, and none ever is, so the image never comes back, even once the game is in front again. Only a new swapchain (F11) lets it go. The reporter's log (#1482, nightly-455) shows it:the window's image was not given back in 250 msright aftergame window not in front, still nogiven backaftergame window in front, and the picture back only afterdisplay: windowedmade the swapchain again. Frame generation makes it far more likely: two presents a frame, a set's images acquired ahead, and the display thread's presents waiting on each other. Any single 250 ms hitch (Alt+Tab, an overlay, a mode switch in full screen) then freezes the picture for good. That would also explain the freezes with no Alt+Tab.Now an image held for 1 s counts as never coming back, and the present makes the swapchain again itself, the same remake F11 does: the presenter drained first, the queue's lock held, the held image and its fence let go as #1458 already handles at a new swapchain. While the window stays hidden, the new chain's first image is held again, so the remakes are kept apart: the next one after 2 s, then every 4 s while no image comes back, and the count starts over once one does. A remake that cannot be made (a window with no size) is tried again only after that wait, not at every present. Each remake is logged (
vk: the window's image was not given back in N s: the swapchain made again, the first 16).Read first:
present_image_with_trial's hold ingpu/vk/vk_replay.cpp(afterimage_free), andheld_remake_due/kHeldRemakeNsbesidekImageFreeNs.Fixes #1482. See #1376, #1458.
Testing
Tested: Linux (X11), RTX 3090, NVIDIA 620.70.06, this PR @
19680d95as a pack over main 9dd41326's base, through the job queue, withfg_alttab_run.py: kokiri-start save to play, frame generation 2x by the built-in generator, then by FSR 3.1 FG; for each, F11 twice (windowed and back), the window minimized and raised with xdotool, and a walk. After each of the 12 steps the presents went on (frames replayed before and after, about 60 fps) and the shot showed the scene moving. No crash or device loss. As expected on NVIDIA, no image was held, so the log has nonot given backorthe swapchain made againline: the new code didn't run here. The held-image path needs AMD on Windows (Beanstalk).Checks:
tests/test_present_held_image.pyis new. It cutspresent_image's acquire, its submit and the image helpers out ofvk_replay.cppand runs them, on each platform's side of_WIN32, against a model engine that hands images back at once and lets them go later (AMD on Windows), with a clock. Onmainit fails ("the window seen again, its held image never let go: no frame copied in 3 s"). Here it checks:Three broken variants (no remake, no back-off, a failed remake retried at each present) must fail.
test_present_image_free.pyandtest_present_acquire_ahead.pycut the same code; their models' holds stay under 1 s, so they don't change. The tests were not run on this PC (its rule: no test suites here). CI on the forge runs them.Still to test:
the swapchain made againlines in the log at those times (@Beanstalk, request below).Beanstalk request (to post as a comment):
Measurements
Verdict: fixes the freeze in the model, the test failing on
mainand passing here. This PC can't reach the hold (NVIDIA on Linux waits in the acquire), so there is no on-screen before and after here. No cost while the window is seen: the new code runs only on a present that finds its image held.Setup:
tests/test_present_held_image.py(CI); in-game: one run on this PC (Testing)9dd4132619680d95not given back in 250 ms, then frozen untildisplay: windowedRisks
unseengives none). A revert is enough to undo it. No switch, no saved setting.Checklist
Ready for review
main; the title is a Conventional Commit.mise run testpasses (any failure that also fails onmainis named). (Not run on this PC, its rule: CI on the forge runs it.)main, or Measurements says why there is nothing to measure.third_party/untouched; nothing GPL-incompatible.When it applies
mainand passes here. (Written to fail onmainand pass here; not run on this PC, CI to confirm.)tests/that reads changed source is updated, not weakened. (test_present_image_free.pyandtest_present_acquire_ahead.pyread the changed hold. Their holds stay under 1 s, so they need no change. CI to confirm.)docs/dev/reference/threads.md, the present's hold.)Assisted-by:/Co-Authored-By:trailers.Ready to merge
main, measured again or a comment says why the numbers still hold.🤖 Generated with Claude Code
https://claude.ai/code/session_017vw8e2uxGKQxzDeQ15jjNK
Tested in game: Linux X11, RTX 3090, NVIDIA 620.70.06, this PR @
19680d95over main 9dd41326's base, through the job queue: kokiri-start, frame generation 2x built-in then FSR 3.1 FG; F11 twice, minimize and raise, walk, for each. Presents went on after all 12 steps at ~60 fps, no crash. NVIDIA holds no image, so the new remake path didn't run here: it needs AMD on Windows (Beanstalk).@Beanstalk Windows with an AMD RX 9000 or 7000 card, and one NVIDIA RTX card: set frame generation on (the built-in 2x first, then FSR 3 frame generation), full screen, in Hyrule Field. Alt+Tab to another window for about 10 seconds and back, 5 times; then play 10 minutes in full screen without Alt+Tab. Check that the picture always comes back moving within 5 seconds of returning (on main, the picture stays frozen until F11 while the sound goes on). Post the log lines with "not given back" and "the swapchain made again", and say whether the picture ever froze.
Beanstalk test farm · ⛔ can't be tested as asked
Commit
19680d9· approved by HumanBean (untrusted) · dashboardNot run: the farm can't test this as asked, so nothing is built or run:
⚠️ Note: The alternative omits the five focus changes and ten-minute full-screen play period; missing held-image logs are unjudged because the run may never reach that path.
⚠️ Note: Frame-time measurements are not proof that the displayed picture is moving.
What it could test instead: The alternative plan runs full-screen Hyrule Field on Windows AMD RX 7000/9000 and NVIDIA RTX PCs, comparing main and the PR with built-in and FSR frame generation. It measures frame times and records whether held-image log lines appear; a crash, device loss, or substantial frame-time regression fails the plan. The two frame-generation modes are separate matrix cells, and the run takes about 21 minutes per tester.
A member of
BigBeanscan comment@Beanstalk <new words>to ask for something else, or@Beanstalk test it anywayto run the plan regardless.WIP: fix(vk): make the swapchain again when the window's held image never comes backto fix(vk): make the swapchain again when the window's held image never comes back