fix(display): hide window immediately on WM_CLOSE and tighten Vulkan close lock polling #3182
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/mods
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
4 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!3182
Loading…
Reference in a new issue
No description provided.
Delete branch "cfw34683/Longshot:fix/fast-window-close"
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
When quitting via the Insert menu power button (Quit / Restart now) or closing the window on Windows,
WM_CLOSErunsrx_close_asked()(mkwvk_close_asked()) andhos_window_closed_exit()(hos_close_finish()) synchronously on the Win32 window thread.Previously:
mkwvk_close_asked()slept 50 ms betweentry_to_lock/try_lockattempts onpresent_image_muanddev.present_mu, making it easy to miss the short unlocked window between back-to-back presents and stall shutdown by 50+ ms per miss.longshot_log.txt, making slow closes hard to diagnose.Changes:
host/display.c(wndproc,WM_CLOSE): release cursor capture (mouse_capture(w, 0)) and hide the window immediately (ShowWindow(w, SW_HIDE)) beforerx_close_asked(). TheHWNDremains valid while hidden so Vulkan swapchain teardown still succeeds.gpu/vk/vk_main.cpp(mkwvk_close_asked): tightenpresent_image_muanddev.present_mulock polling from 50 ms to 2 ms (matchingdlss_nr_close/dlss_fg_close) while keeping the same 5 sgive_up_atbudget, and log renderer close duration (vk: renderer close finished in %lld ms) aftercrash_markers::close().host/hos_close.c(hos_close_finish): log host close tail duration (stop: close work done (host tail %.0f ms; ...)).tests/screensaver_test.c,tests/test_windows_stop.py,tests/test_fs_save_commit.py: addWM_CLOSEandWM_APP + 9(restart) ordering tests verifying capture release andShowWindow(w, SW_HIDE)run beforerx_close_asked()andhos_window_closed_exit(), and declare/stubhos_now_ns()in the isolated close-chain fixtures.Testing
Tested:
kokiri-startsave):python -I scripts/dev.py smokeon PR head3fe8c119: PASS (in play from kokiri-start, 900 frames, the menu opened, zeroFATAL:lines).WM_CLOSEruns (5 runs each on basec5d95dfbvs. head3fe8c119, after 120 presented frames in play) in both normal presentation and renderer frame generation (RX_VK_FRAMEGEN=1):exit_code = 0,stop: close work done, zeroFATAL:/ crash / swapchain / queue-busy warnings).a66fa5fc(7daa003d0): 15 targeted display/close/save/stop checks passed (0 failed).7bc53f841vs.7daa003d0):vk: renderer close finished in 1 ms,host tail 0 ms, no Vulkan errors).tests/test_present_semaphores.pypassed.Still to test:
@Beanstalk/ by hand).HWNDis hidden beforerx_close_asked()(@Beanstalk/ by hand).Measurements
Verdict: Better on Windows perceived close responsiveness (~83–91x faster time-to-hide: ~100 ms → ~1.1–1.2 ms); modestly better / neutral on total process exit time on warm-cache runs (-18.1 ms median normal, -0.9 ms median framegen, where ~800 ms is post-
hos_close_finishOS/driver process teardown). Clean teardown (rc=0, no swapchain/queue-busy warnings) on 10/10 head runs. Numbers still hold after rebasing ontoa66fa5fc: the rebased commits (7daa003d0) are identical in diff to3fe8c119, and no intervening commit onmaintouchedWM_CLOSE,mkwvk_close_asked(), orhos_close_finish().Setup: Windows 11, NVIDIA GeForce RTX 3070 Ti (driver 621.47,
nvidia_ampere), windowedlongshot-game.exeviadev.py rt(kokiri-start, 120 frames in play, 5 repeatedWM_CLOSEruns per configuration, warm shader cache).c5d95dfb3fe8c119vk: renderer close finished/ host tailrc=0, 5/5)RX_VK_FRAMEGEN=1) — Time to window hideRX_VK_FRAMEGEN=1) — Total process exitRX_VK_FRAMEGEN=1) —vk: renderer close finished/ host tailrc=0, 5/5)Risks
HWND(ShowWindow(w, SW_HIDE)) before Vulkan swapchain retirement could interact unexpectedly with a specific GPU driver or frame-generation layer on Windows (tested clean on NVIDIA RTX 3070 Ti normal +RX_VK_FRAMEGEN=1, 10/10 runs); if any issue appears, a clean revert restores prior behavior with no user-data or config impact.present_image_mu/dev.present_muevery 2 ms instead of 50 ms slightly increases wakeups during the brief shutdown window (bounded by the same 5 s deadline); no runtime/gameplay cost.Checklist
Ready for review
main; the title is a Conventional Commit.mise run testpasses (15 targeted game-free checks pass on Windows after rebasing ontoa66fa5fc).main, or Measurements says why there is nothing to measure.third_party/untouched; nothing GPL-incompatible.When it applies
mainand passes here.tests/that reads changed source is updated, not weakened.Assisted-by:/Co-Authored-By:trailers.Ready to merge
main, measured again or a comment says why the numbers still hold.@review
Recommendation: Request changes. The close-chain fixture no longer compiles, and the fix has no game-free test that exercises the new behavior. The reported verification also does not show that the window closes promptly in game or that the shorter polling interval improves shutdown time.
The change hides the Windows window before shutdown, polls Vulkan close locks more often on both platforms, and logs the duration of the host cleanup tail. It should make a frozen window less visible, but its shutdown-time gain and effects on real Vulkan configurations remain unmeasured.
Blocking (1): must change before merging.
tests/screensaver_test.c:110: The fix has no game-free test for the new close behavior. (more on the line) Do: Add a fixture case that sends WM_CLOSE and checks that capture is released and the window hidden before renderer shutdown, including the restart route.Should fix (2): not blocking, but worth doing before merging.
host/hos_close.c:27: The reported close duration excludes the renderer shutdown that can account for most of the wait. (more on the line) Do: Time the renderer and host phases separately, or start a total-close timer before rx_close_asked and label the existing measurement as the host tail.Testing before merging (1) (runs on the systems it can change; it doesn't hold the recommendation)
gpu/vk/vk_main.cpp:2327: The claimed shutdown improvement and safe swapchain teardown need an in-game comparison. (more on the line) Do: Compare repeated closes on base and head on Windows and Linux, including a frame-generation path and Steam Deck or another affected Linux configuration; report time to hide, total exit time and teardown results.@fixcan do L2, L3 and L5.Checks: Still running: 11 checks.
More: does it help, other systems, switches, what was read
Does it help: Unproven. The PR reports 15 game-free checks and a syntax check, but no in-game close result or before-and-after shutdown timings.
Other systems: The window change affects Windows close and restart; Vulkan lock polling also affects Linux, including Steam Deck, and the normal and frame-generation presentation paths. No hardware runs are reported for those paths. The host timing log is shared by window, control, game and Windows stop exits.
Switches: None.
Reviewed:
53981d3591againstc5d95dfb68: Read AGENTS.md, CONTRIBUTING.md, docs/dev/standards.md, the PR template, the diff and commit log, host/hos_close.c, tests/screensaver_test.c, and the changed sections and surrounding close paths in host/display.c and gpu/vk/vk_main.cpp. Skimmed the presentation locking, shutdown callers and relevant tests. The full large renderer and display files were not read in full; docs/review-checklist.md and ../Tooling/AGENTS.md were absent. No recorded runs, translations or generated files were changed.; nothing run (a code review).Checked and fine:
Testing: No commands from the project, builds or tests were run, as requested. CI was still running in the supplied status.
Overlaps and merge order: Not checked; network access was unavailable.
Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.
@ -2326,1 +2325,3 @@std::this_thread::sleep_for(std::chrono::milliseconds(50));// Poll every 2 ms (matching dlss_nr_close/dlss_fg_close) instead of 50 ms so we catch the// short unlocked gap between frames immediately rather than stalling shutdown by 50+ ms per miss.while (!pi.owns_lock() && std::chrono::steady_clock::now() < give_up_at) {L4 (should fix): The claimed shutdown improvement and safe swapchain teardown need an in-game comparison.
When: The polling interval changes on Windows and Linux, including frame-generated presentation, but the PR supplies no timing or game run showing the effect or confirming teardown on those paths.
Do: Compare repeated closes on base and head on Windows and Linux, including a frame-generation path and Steam Deck or another affected Linux configuration; report time to hide, total exit time and teardown results.
@ -24,2 +24,4 @@keep its watchdog alive until all explicit close work and the log flush have returned. */void hos_close_finish(void) {/* Track elapsed close time so slow shutdown phases are visible in longshot_log.txt. */const int64_t t0 = hos_now_ns();L3 (should fix): The reported close duration excludes the renderer shutdown that can account for most of the wait.
When: On WM_CLOSE, rx_close_asked completes pipeline cache saving, preparation waits and Vulkan teardown before hos_close_finish starts this timer. A multi-second renderer shutdown can consequently be logged as only a few milliseconds of close work, obscuring the slow phase the timing is meant to diagnose.
Do: Time the renderer and host phases separately, or start a total-close timer before rx_close_asked and label the existing measurement as the host tail.
@ -107,2 +107,4 @@static void hos_restart_ask(void) { unexpected(); } /* (host/hos_close.c: WM_APP + 9 and WM_CLOSE end the process) */static void hos_window_closed_exit(void) { unexpected(); }/* (host/display.c: WM_CLOSE hides the window immediately before shutdown drains; never runs here) */static BOOL ShowWindow(HWND w, int cmd) { (void)w; (void)cmd; unexpected(); return FALSE; }L2 (blocking): The fix has no game-free test for the new close behavior.
When: This stub aborts if ShowWindow is called and the fixture never sends WM_CLOSE; the existing close checks only require the previous shutdown calls. Removing the new hide and cursor-release calls would leave the reported tests passing.
Do: Add a fixture case that sends WM_CLOSE and checks that capture is released and the window hidden before renderer shutdown, including the restart route.
Addressed BeanBot's review items in
3fe8c119:#include <stdint.h>andhos_now_ns()stubs/declarations totests/test_windows_stop.pyandtests/test_fs_save_commit.py.WM_CLOSEandWM_APP + 9(restart) ordering tests intests/screensaver_test.cverifyingmouse_capture(w, 0)andShowWindow(w, SW_HIDE)run beforerx_close_asked()andhos_window_closed_exit().vk: renderer close finished in %lld ms, aftercrash_markers::close()) ingpu/vk/vk_main.cppand labeledhos_close_finish()'s log explicitly as the host tail.In-game before/after close timing runs (L4) are still pending on Windows and Linux.
@review
Recommendation: Approve. The code is ready: only testing is left. The close ordering is now covered by a game-free test, and renderer and host shutdown have separate timings. The claimed improvement and safe teardown still need in-game comparisons on the affected systems. Recommend approval; not approved on the forge.
Windows hides the window before shutdown work, and Vulkan polls shutdown locks more frequently. The added timing and tests help diagnose and check the close path, at the cost of more wakeups during shutdown; the practical gain remains unmeasured.
Testing before merging (1) (runs on the systems it can change; it doesn't hold the recommendation)
gpu/vk/vk_main.cpp:2327: The claimed shutdown improvement and safe swapchain teardown need an in-game comparison. When: The polling interval changes on Windows and Linux, including frame-generated presentation, but the PR supplies no timing or game run showing the effect or confirming teardown on those paths. Do: Compare repeated closes on base and head on Windows and Linux, including a frame-generation path and Steam Deck or another affected Linux configuration; report time to hide, total exit time and teardown results.Since the last review (on
53981d3591)Resolved: L2 (The fix has no game-free test for the new close behavior.); L3 (The reported close duration excludes the renderer shutdown that can account for most of th…); L5 (The PR description omits the required testing, measurements, risks and checklist sections.)
Still open: L4 (The claimed shutdown improvement and safe swapchain teardown need an in-game comparison.)
Checks: Still running: 11 checks.
More: does it help, other systems, switches, what was read
Does it help: Unproven: the description reports no in-game before-and-after close timings. It reports 14 targeted game-free checks and the present semaphore check passing on Linux.
Other systems: The polling and renderer timing also run on Linux and affect normal and frame-generated presents; hiding the window is Windows-specific. Driver, frame-generation and Steam Deck teardown behavior remain untested in game.
Switches: None.
Reviewed:
3fe8c119b1againstc5d95dfb68: Read the diff, commits, repository rules and PR template, close-chain tests and relevant shutdown paths; skimmed the larger changed renderer, display and save-test files and their callers. The separate Tooling checkout and review checklist were not present.; nothing run (a code review).Checked and fine:
Testing: No commands that build or run tests were executed. The author reports targeted game-free checks passing; in-game Windows and Linux comparisons remain pending, and CI is still running.
Overlaps and merge order: Not checked; network access is closed.
Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.
Added Windows in-game before/after close measurements (L4) on Windows 11 + NVIDIA GeForce RTX 3070 Ti (driver 621.47,
kokiri-start, 120 frames in play, 5 repeatedWM_CLOSEruns each on basec5d95dfbvs. head3fe8c119):vk: renderer close finished1–7 ms (median 2.0 ms), host tail 0 ms; 5/5 clean (rc=0, no swapchain/queue-busy warnings).RX_VK_FRAMEGEN=1): time-to-hide 100.4 ms → 1.1 ms median (98.8–105.9 ms → 1.1–1.5 ms); total exit 830.0 ms → 829.1 ms median (within noise — ~800 ms is post-hos_close_finishOS/driver teardown);vk: renderer close finished1–6 ms (median 3.0 ms), host tail 0 ms; 5/5 clean (rc=0).dev.py smokeon head3fe8c119: PASS (kokiri-start, 900 frames, menu opened, zeroFATAL:lines).PR description updated with the full table. Linux / Steam Deck in-game close runs remain listed under Still to test.
3fe8c119b17daa003d06@Beanstalk Compare repeated in-game closes on base vs. PR head on Linux (including Steam Deck / RADV and normal + frame-generation presentation paths) and Windows with DLSS Frame Generation if available: verify clean swapchain teardown (no queue-busy warnings, crashes, or FATAL lines) and report
vk: renderer close finished,host tail, and total exit time.@cfw34683 only members of
BigBeanscan start the farm.One of them can approve this request by reacting 👍 to it or to this comment.This request was for7daa003, and the PR has changed since (6741d20), so a 👍 no longer approves it. Comment@Beanstalkagain to ask for the new commit.AMD lab A/B/A/B:
main7bc53f841(A) against this PR's head7daa003d0merged onto it (B). AMD lab PC: Linux 7.3.3-1-cachyos, Core i7-9700K, 15 GB RAM (zram swap), Radeon RX 580 with Mesa RADV 3:26.2.6-1. A/B/A/B, 90 s per run after a 15 s warm-up, each a timing job in the queue, headless, uncapped, V-Sync and frame generation off.Scenario: standing in the Market, 1280x720 output, 33 % render scale, then a close through the control bridge at the end of each run.
No fps or frame-time change; the closes were clean. The runs can't show a faster close.
vk: renderer close finished in 1 msandstop: close work done (host tail 0 ms; ...). A has no such timings to compare with.Not covered: the window hide (the runs are headless, and it is Windows-only), closes with frame generation, Steam Deck. This is two closes per side, not a stress test of repeated closes.