fix(display): hide window immediately on WM_CLOSE and tighten Vulkan close lock polling #3182

Merged
HumanBean merged 3 commits from cfw34683/Longshot:fix/fast-window-close into main 2026-12-05 17:43:36 +00:00
Contributor

Summary

When quitting via the Insert menu power button (Quit / Restart now) or closing the window on Windows, WM_CLOSE runs rx_close_asked() (mkwvk_close_asked()) and hos_window_closed_exit() (hos_close_finish()) synchronously on the Win32 window thread.

Previously:

  • The game window remained visible and frozen throughout pipeline cache save, Vulkan swapchain/DLSS teardown, and host save/pad/network shutdown.
  • mkwvk_close_asked() slept 50 ms between try_to_lock / try_lock attempts on present_image_mu and dev.present_mu, making it easy to miss the short unlocked window between back-to-back presents and stall shutdown by 50+ ms per miss.
  • Shutdown phases were not timed in 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)) before rx_close_asked(). The HWND remains valid while hidden so Vulkan swapchain teardown still succeeds.
  • gpu/vk/vk_main.cpp (mkwvk_close_asked): tighten present_image_mu and dev.present_mu lock polling from 50 ms to 2 ms (matching dlss_nr_close / dlss_fg_close) while keeping the same 5 s give_up_at budget, and log renderer close duration (vk: renderer close finished in %lld ms) after crash_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: add WM_CLOSE and WM_APP + 9 (restart) ordering tests verifying capture release and ShowWindow(w, SW_HIDE) run before rx_close_asked() and hos_window_closed_exit(), and declare/stub hos_now_ns() in the isolated close-chain fixtures.

Testing

Tested:

  • Windows (Windows 11, NVIDIA GeForce RTX 3070 Ti, driver 621.47, kokiri-start save):
    • python -I scripts/dev.py smoke on PR head 3fe8c119: PASS (in play from kokiri-start, 900 frames, the menu opened, zero FATAL: lines).
    • Repeated windowed WM_CLOSE runs (5 runs each on base c5d95dfb vs. head 3fe8c119, after 120 presented frames in play) in both normal presentation and renderer frame generation (RX_VK_FRAMEGEN=1):
      • All 10 head runs exited cleanly (exit_code = 0, stop: close work done, zero FATAL: / crash / swapchain / queue-busy warnings).
      • Window hid in 1.1–1.5 ms on head vs. 96.5–152.3 ms on base across both paths.
    • Game-free checks on Windows after rebasing onto a66fa5fc (7daa003d0): 15 targeted display/close/save/stop checks passed (0 failed).
  • Linux AMD lab (Linux 7.3.3-1-cachyos, Core i7-9700K, Radeon RX 580, Mesa RADV 3:26.2.6-1, headless A/B/A/B by HumanBean on 7bc53f841 vs. 7daa003d0):
    • No fps or frame-time regression (61.5/60.8 vs 60.5/60.7 fps); clean closes (vk: renderer close finished in 1 ms, host tail 0 ms, no Vulkan errors).
  • Linux (Ubuntu 26.10, kernel 7.3.0):
    • 14 targeted close/display/save/stop game-free checks + tests/test_present_semaphores.py passed.

Still to test:

  • Linux / Steam Deck (Vulkan normal + frame-gen paths): repeated closes on base vs. head, expecting clean swapchain retirement and no teardown stalls (@Beanstalk / by hand).
  • Windows DLSS-G (RTX 40/50-series) if available, to confirm clean Streamline/NGX swapchain teardown when HWND is hidden before rx_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_finish OS/driver process teardown). Clean teardown (rc=0, no swapchain/queue-busy warnings) on 10/10 head runs. Numbers still hold after rebasing onto a66fa5fc: the rebased commits (7daa003d0) are identical in diff to 3fe8c119, and no intervening commit on main touched WM_CLOSE, mkwvk_close_asked(), or hos_close_finish().

Setup: Windows 11, NVIDIA GeForce RTX 3070 Ti (driver 621.47, nvidia_ampere), windowed longshot-game.exe via dev.py rt (kokiri-start, 120 frames in play, 5 repeated WM_CLOSE runs per configuration, warm shader cache).

Metric (min / median / max, n=5) Before: main @ c5d95dfb After: this PR @ 3fe8c119 Delta (median)
Normal — Time to window hide 96.5 / 99.8 / 152.3 ms 1.1 / 1.2 / 1.5 ms -98.6 ms (~83x faster)
Normal — Total process exit 821.1 / 837.0 / 913.9 ms 806.7 / 818.9 / 825.8 ms -18.1 ms (mean 849.8 → 816.6 ms)
Normal — vk: renderer close finished / host tail n/a 1 / 2.0 / 7 ms (host tail 0 ms) Clean (rc=0, 5/5)
Framegen (RX_VK_FRAMEGEN=1) — Time to window hide 98.8 / 100.4 / 105.9 ms 1.1 / 1.1 / 1.5 ms -99.3 ms (~91x faster)
Framegen (RX_VK_FRAMEGEN=1) — Total process exit 821.4 / 830.0 / 846.7 ms 798.0 / 829.1 / 887.8 ms -0.9 ms (within noise)
Framegen (RX_VK_FRAMEGEN=1) — vk: renderer close finished / host tail n/a 1 / 3.0 / 6 ms (host tail 0 ms) Clean (rc=0, 5/5)

Risks

  • Hiding the Win32 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.
  • Polling present_image_mu / dev.present_mu every 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.
  • Players notice no settings/save/cache changes after updating.

Checklist

Ready for review

  • One topic, on current main; the title is a Conventional Commit.
  • Tested on my own PC, in the game for a change the game runs, as Testing says.
  • mise run test passes (15 targeted game-free checks pass on Windows after rebasing onto a66fa5fc).
  • Measured against main, or Measurements says why there is nothing to measure.
  • No game files, build output or hand-edited generated files; third_party/ untouched; nothing GPL-incompatible.

When it applies

  • A fix: a game-free test that fails on main and passes here.
  • A check under tests/ that reads changed source is updated, not weakened.
  • Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths.
  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers.

Ready to merge

  • Everything in Still to test has run, its results in Tested.
  • Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers").
  • Approved in review, every comment answered.
  • CI passes on the head; on current main, measured again or a comment says why the numbers still hold.
## Summary When quitting via the Insert menu power button (**Quit** / **Restart now**) or closing the window on Windows, `WM_CLOSE` runs `rx_close_asked()` (`mkwvk_close_asked()`) and `hos_window_closed_exit()` (`hos_close_finish()`) synchronously on the Win32 window thread. Previously: - The game window remained visible and frozen throughout pipeline cache save, Vulkan swapchain/DLSS teardown, and host save/pad/network shutdown. - `mkwvk_close_asked()` slept **50 ms** between `try_to_lock` / `try_lock` attempts on `present_image_mu` and `dev.present_mu`, making it easy to miss the short unlocked window between back-to-back presents and stall shutdown by 50+ ms per miss. - Shutdown phases were not timed in `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)`) before `rx_close_asked()`. The `HWND` remains valid while hidden so Vulkan swapchain teardown still succeeds. - `gpu/vk/vk_main.cpp` (`mkwvk_close_asked`): tighten `present_image_mu` and `dev.present_mu` lock polling from **50 ms** to **2 ms** (matching `dlss_nr_close` / `dlss_fg_close`) while keeping the same 5 s `give_up_at` budget, and log renderer close duration (`vk: renderer close finished in %lld ms`) after `crash_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`: add `WM_CLOSE` and `WM_APP + 9` (restart) ordering tests verifying capture release and `ShowWindow(w, SW_HIDE)` run before `rx_close_asked()` and `hos_window_closed_exit()`, and declare/stub `hos_now_ns()` in the isolated close-chain fixtures. ## Testing **Tested:** - **Windows (Windows 11, NVIDIA GeForce RTX 3070 Ti, driver 621.47, `kokiri-start` save):** - `python -I scripts/dev.py smoke` on PR head `3fe8c119`: **PASS** (`in play from kokiri-start, 900 frames, the menu opened`, zero `FATAL:` lines). - Repeated windowed `WM_CLOSE` runs (5 runs each on base `c5d95dfb` vs. head `3fe8c119`, after 120 presented frames in play) in both **normal presentation** and **renderer frame generation (`RX_VK_FRAMEGEN=1`)**: - All 10 head runs exited cleanly (`exit_code = 0`, `stop: close work done`, zero `FATAL:` / crash / swapchain / queue-busy warnings). - Window hid in **1.1–1.5 ms** on head vs. **96.5–152.3 ms** on base across both paths. - Game-free checks on Windows after rebasing onto `a66fa5fc` (`7daa003d0`): 15 targeted display/close/save/stop checks passed (`0 failed`). - **Linux AMD lab (Linux 7.3.3-1-cachyos, Core i7-9700K, Radeon RX 580, Mesa RADV 3:26.2.6-1, headless A/B/A/B by HumanBean on `7bc53f841` vs. `7daa003d0`):** - No fps or frame-time regression (61.5/60.8 vs 60.5/60.7 fps); clean closes (`vk: renderer close finished in 1 ms`, `host tail 0 ms`, no Vulkan errors). - **Linux (Ubuntu 26.10, kernel 7.3.0):** - 14 targeted close/display/save/stop game-free checks + `tests/test_present_semaphores.py` passed. **Still to test:** - Linux / Steam Deck (Vulkan normal + frame-gen paths): repeated closes on base vs. head, expecting clean swapchain retirement and no teardown stalls (`@Beanstalk` / by hand). - Windows DLSS-G (RTX 40/50-series) if available, to confirm clean Streamline/NGX swapchain teardown when `HWND` is hidden before `rx_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_finish` OS/driver process teardown). Clean teardown (`rc=0`, no swapchain/queue-busy warnings) on 10/10 head runs. Numbers still hold after rebasing onto `a66fa5fc`: the rebased commits (`7daa003d0`) are identical in diff to `3fe8c119`, and no intervening commit on `main` touched `WM_CLOSE`, `mkwvk_close_asked()`, or `hos_close_finish()`. Setup: Windows 11, NVIDIA GeForce RTX 3070 Ti (driver 621.47, `nvidia_ampere`), windowed `longshot-game.exe` via `dev.py rt` (`kokiri-start`, 120 frames in play, 5 repeated `WM_CLOSE` runs per configuration, warm shader cache). | Metric (min / **median** / max, n=5) | Before: main @ c5d95dfb | After: this PR @ 3fe8c119 | Delta (median) | |---|---:|---:|---:| | **Normal** — Time to window hide | 96.5 / **99.8** / 152.3 ms | 1.1 / **1.2** / 1.5 ms | **-98.6 ms** (~83x faster) | | **Normal** — Total process exit | 821.1 / **837.0** / 913.9 ms | 806.7 / **818.9** / 825.8 ms | **-18.1 ms** (mean 849.8 → 816.6 ms) | | **Normal** — `vk: renderer close finished` / host tail | n/a | 1 / **2.0** / 7 ms (host tail **0 ms**) | Clean (`rc=0`, 5/5) | | **Framegen (`RX_VK_FRAMEGEN=1`)** — Time to window hide | 98.8 / **100.4** / 105.9 ms | 1.1 / **1.1** / 1.5 ms | **-99.3 ms** (~91x faster) | | **Framegen (`RX_VK_FRAMEGEN=1`)** — Total process exit | 821.4 / **830.0** / 846.7 ms | 798.0 / **829.1** / 887.8 ms | **-0.9 ms** (within noise) | | **Framegen (`RX_VK_FRAMEGEN=1`)** — `vk: renderer close finished` / host tail | n/a | 1 / **3.0** / 6 ms (host tail **0 ms**) | Clean (`rc=0`, 5/5) | ## Risks - Hiding the Win32 `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. - Polling `present_image_mu` / `dev.present_mu` every 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. - Players notice no settings/save/cache changes after updating. ## Checklist ### Ready for review - [x] One topic, on current `main`; the title is a Conventional Commit. - [x] Tested on my own PC, in the game for a change the game runs, as Testing says. - [x] `mise run test` passes (15 targeted game-free checks pass on Windows after rebasing onto `a66fa5fc`). - [x] Measured against `main`, or Measurements says why there is nothing to measure. - [x] No game files, build output or hand-edited generated files; `third_party/` untouched; nothing GPL-incompatible. ### When it applies - [x] A fix: a game-free test that fails on `main` and passes here. - [x] A check under `tests/` that reads changed source is updated, not weakened. - [x] Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths. - [x] AI assistance recorded with `Assisted-by:` / `Co-Authored-By:` trailers. ### Ready to merge - [ ] Everything in Still to test has run, its results in Tested. - [ ] Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers"). - [ ] Approved in review, every comment answered. - [ ] CI passes on the head; on current `main`, measured again or a comment says why the numbers still hold.
fix(display): hide window immediately on WM_CLOSE and tighten Vulkan close lock polling
Some checks failed
PR description / Title and description (pull_request_target) Has been cancelled
CI / What the change needs (pull_request) Has been cancelled
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Has been cancelled
CI / Third-party parts and guide screenshots (pull_request) Has been cancelled
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Has been cancelled
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Has been cancelled
CI / Renderer build check (Windows, compile --only renderer, without and with FSR 4) (pull_request) Has been cancelled
CI / Renderer build check (Linux, compile --only renderer, without and with FSR 4) (pull_request) Has been cancelled
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Has been cancelled
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
c434926e03
When quitting via the Insert power menu (or window close), WM_CLOSE runs Vulkan teardown, pipeline cache save, and host close cleanup synchronously on the Win32 window thread. Previously the window stayed visible and frozen throughout, and mkwvk_close_asked() slept 50 ms between try_lock polls on present_image_mu and dev.present_mu.

- Release cursor capture and hide the HWND immediately on WM_CLOSE before rx_close_asked() (the HWND remains valid while hidden for swapchain teardown).
- Tighten mkwvk_close_asked() try_lock polling from 50 ms to 2 ms (matching dlss_nr_close/dlss_fg_close) while keeping the 5 s give_up_at budget.
- Log elapsed ms in hos_close_finish() so slow shutdown phases are visible in longshot_log.txt.
- Add SW_HIDE / ShowWindow stubs to tests/screensaver_test.c.

Assisted-by: Antigravity
Merge branch 'main' into fix/fast-window-close
Some checks failed
PR description / Title and description (pull_request_target) Has been cancelled
CI / What the change needs (pull_request) Has been cancelled
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Has been cancelled
CI / Third-party parts and guide screenshots (pull_request) Has been cancelled
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Has been cancelled
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Has been cancelled
CI / Renderer build check (Windows, compile --only renderer, without and with FSR 4) (pull_request) Has been cancelled
CI / Renderer build check (Linux, compile --only renderer, without and with FSR 4) (pull_request) Has been cancelled
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Has been cancelled
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
53981d3591
Owner
@review
BeanBot left a comment

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.

  1. L2 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.

  • L3 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.
  • L5: The PR description omits the required testing, measurements, risks and checklist sections. When: Its verification lists checks but gives no in-game environment or result, remaining hardware tests, measurement verdict, risks or applicable checklist, so a maintainer cannot assess readiness from the description. Do: Complete the repository PR template with the actual results, outstanding runs, measurements and risks.

Testing before merging (1) (runs on the systems it can change; it doesn't hold the recommendation)

  • L4 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.

@fix can 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: 53981d3591 against c5d95dfb68: 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:

  • The commit records AI assistance with an Assisted-by trailer.
  • No game-derived files, generated outputs, API version changes or switch changes appear in the diff.
  • The changed Vulkan close path retains the existing lock order and deadline-based fallback.

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.

**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. 1. **L2** `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. - **L3** `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. - **L5**: The PR description omits the required testing, measurements, risks and checklist sections. *When:* Its verification lists checks but gives no in-game environment or result, remaining hardware tests, measurement verdict, risks or applicable checklist, so a maintainer cannot assess readiness from the description. **Do:** Complete the repository PR template with the actual results, outstanding runs, measurements and risks. **Testing before merging (1)** (runs on the systems it can change; it doesn't hold the recommendation) - **L4** `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. `@fix` can do L2, L3 and L5. **Checks:** Still running: 11 checks. <details> <summary>More: does it help, other systems, switches, what was read</summary> **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:** 53981d359196 against c5d95dfb68c0: 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:** - The commit records AI assistance with an Assisted-by trailer. - No game-derived files, generated outputs, API version changes or switch changes appear in the diff. - The changed Vulkan close path retains the existing lock order and deadline-based fallback. **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. </details> --- <sub>Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.</sub>
@ -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) {
Member

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.

**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.
host/hos_close.c Outdated
@ -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();
Member

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.

**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; }
Member

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.

**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.
fix(display): address review feedback on close tests and timing
Some checks failed
PR description / Title and description (pull_request_target) Has been cancelled
CI / What the change needs (pull_request) Has been cancelled
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Has been cancelled
CI / Third-party parts and guide screenshots (pull_request) Has been cancelled
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Has been cancelled
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Has been cancelled
CI / Renderer build check (Windows, compile --only renderer, without and with FSR 4) (pull_request) Has been cancelled
CI / Renderer build check (Linux, compile --only renderer, without and with FSR 4) (pull_request) Has been cancelled
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Has been cancelled
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
3fe8c119b1
- Add <stdint.h> and hos_now_ns() declarations/stubs in tests/test_windows_stop.py and tests/test_fs_save_commit.py so both close-chain fixtures compile cleanly.
- Add WM_CLOSE and WM_APP + 9 (restart) ordering cases to tests/screensaver_test.c verifying mouse_capture(w, 0) and ShowWindow(w, SW_HIDE) run before rx_close_asked() and hos_window_closed_exit().
- Time mkwvk_close_asked() separately (after crash_markers::close()) and label hos_close_finish()'s elapsed log explicitly as the host tail.

Assisted-by: Antigravity
Author
Contributor

Addressed BeanBot's review items in 3fe8c119:

  • Close-chain fixtures (blocking): Added #include <stdint.h> and hos_now_ns() stubs/declarations to tests/test_windows_stop.py and tests/test_fs_save_commit.py.
  • L2 (blocking): Added WM_CLOSE and WM_APP + 9 (restart) ordering tests in tests/screensaver_test.c verifying mouse_capture(w, 0) and ShowWindow(w, SW_HIDE) run before rx_close_asked() and hos_window_closed_exit().
  • L3: Added scoped renderer close timing (vk: renderer close finished in %lld ms, after crash_markers::close()) in gpu/vk/vk_main.cpp and labeled hos_close_finish()'s log explicitly as the host tail.
  • L5: Updated the PR description to follow the repository PR template.

In-game before/after close timing runs (L4) are still pending on Windows and Linux.

Addressed BeanBot's review items in `3fe8c119`: - **Close-chain fixtures (blocking):** Added `#include <stdint.h>` and `hos_now_ns()` stubs/declarations to `tests/test_windows_stop.py` and `tests/test_fs_save_commit.py`. - **L2 (blocking):** Added `WM_CLOSE` and `WM_APP + 9` (restart) ordering tests in `tests/screensaver_test.c` verifying `mouse_capture(w, 0)` and `ShowWindow(w, SW_HIDE)` run before `rx_close_asked()` and `hos_window_closed_exit()`. - **L3:** Added scoped renderer close timing (`vk: renderer close finished in %lld ms`, after `crash_markers::close()`) in `gpu/vk/vk_main.cpp` and labeled `hos_close_finish()`'s log explicitly as the host tail. - **L5:** Updated the PR description to follow the repository PR template. In-game before/after close timing runs (L4) are still pending on Windows and Linux.
Owner
@review
BeanBot left a comment

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)

  • L4 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: 3fe8c119b1 against c5d95dfb68: 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:

  • The save fixture declares the existing hos_now_ns implementation, and the Windows stop fixture supplies a stub.
  • The fix retains the window-hide and tighter polling changes.

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.

**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) - **L4** `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 53981d359196) 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. <details> <summary>More: does it help, other systems, switches, what was read</summary> **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:** 3fe8c119b13f against c5d95dfb68c0: 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:** - The save fixture declares the existing hos_now_ns implementation, and the Windows stop fixture supplies a stub. - The fix retains the window-hide and tighter polling changes. **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. </details> --- <sub>Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.</sub>
Author
Contributor

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 repeated WM_CLOSE runs each on base c5d95dfb vs. head 3fe8c119):

  • Normal presentation: time-to-hide 99.8 ms → 1.2 ms median (96.5–152.3 ms → 1.1–1.5 ms); total exit 837.0 ms → 818.9 ms median (mean 849.8 → 816.6 ms); vk: renderer close finished 1–7 ms (median 2.0 ms), host tail 0 ms; 5/5 clean (rc=0, no swapchain/queue-busy warnings).
  • Renderer frame generation (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_finish OS/driver teardown); vk: renderer close finished 1–6 ms (median 3.0 ms), host tail 0 ms; 5/5 clean (rc=0).
  • dev.py smoke on head 3fe8c119: PASS (kokiri-start, 900 frames, menu opened, zero FATAL: lines).

PR description updated with the full table. Linux / Steam Deck in-game close runs remain listed under Still to test.

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 repeated `WM_CLOSE` runs each on base `c5d95dfb` vs. head `3fe8c119`): - **Normal presentation:** time-to-hide **99.8 ms → 1.2 ms** median (96.5–152.3 ms → 1.1–1.5 ms); total exit **837.0 ms → 818.9 ms** median (mean 849.8 → 816.6 ms); `vk: renderer close finished` **1–7 ms** (median 2.0 ms), host tail **0 ms**; 5/5 clean (`rc=0`, no swapchain/queue-busy warnings). - **Renderer frame generation (`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_finish` OS/driver teardown); `vk: renderer close finished` **1–6 ms** (median 3.0 ms), host tail **0 ms**; 5/5 clean (`rc=0`). - **`dev.py smoke`** on head `3fe8c119`: **PASS** (`kokiri-start`, 900 frames, menu opened, zero `FATAL:` lines). PR description updated with the full table. Linux / Steam Deck in-game close runs remain listed under *Still to test*.
cfw34683 force-pushed fix/fast-window-close from 3fe8c119b1
Some checks failed
PR description / Title and description (pull_request_target) Has been cancelled
CI / What the change needs (pull_request) Has been cancelled
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Has been cancelled
CI / Third-party parts and guide screenshots (pull_request) Has been cancelled
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Has been cancelled
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Has been cancelled
CI / Renderer build check (Windows, compile --only renderer, without and with FSR 4) (pull_request) Has been cancelled
CI / Renderer build check (Linux, compile --only renderer, without and with FSR 4) (pull_request) Has been cancelled
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Has been cancelled
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
to 7daa003d06
Some checks failed
beanstalk/approval waiting for a BigBean's 👍 on the request
PR description / Title and description (pull_request_target) Has been cancelled
CI / What the change needs (pull_request) Has been cancelled
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Has been cancelled
CI / Third-party parts and guide screenshots (pull_request) Has been cancelled
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Has been cancelled
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Has been cancelled
CI / Renderer build check (Windows, compile --only renderer, without and with FSR 4) (pull_request) Has been cancelled
CI / Renderer build check (Linux, compile --only renderer, without and with FSR 4) (pull_request) Has been cancelled
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Has been cancelled
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
2026-12-04 20:46:26 +00:00
Compare
Author
Contributor

@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.

@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.
Member

@cfw34683 only members of BigBeans can start the farm.

One of them can approve this request by reacting 👍 to it or to this comment. This request was for 7daa003, and the PR has changed since (6741d20), so a 👍 no longer approves it. Comment @Beanstalk again to ask for the new commit.

@cfw34683 only members of `BigBeans` can start the farm. ~~One of them can approve this request by reacting 👍 to it or to this comment.~~ This request was for `7daa003`, and the PR has changed since (`6741d20`), so a 👍 no longer approves it. Comment `@Beanstalk` again to ask for the new commit.
Owner

AMD lab A/B/A/B: main 7bc53f841 (A) against this PR's head 7daa003d0 merged 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.

A1 B1 A2 B2
Average fps 61.5 60.5 60.8 60.7
Median frame 16.15 ms 16.44 ms 16.37 ms 16.44 ms
p99 frame 19.25 ms 19.81 ms 20.01 ms 19.26 ms
Frames of 50 ms or more 0 0 0 0
Quit request to the session stopped 0.86 s 0.86 s 0.60 s 0.91 s
  • Both B runs log vk: renderer close finished in 1 ms and stop: close work done (host tail 0 ms; ...). A has no such timings to compare with.
  • The stop time is measured from the harness's side and includes its own polling, so it is too coarse for a difference of tens of ms. It shows no hang and no large change.
  • No Vulkan errors in the logs.

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.

**AMD lab A/B/A/B:** `main` `7bc53f841` (A) against this PR's head `7daa003d0` merged 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.** | | A1 | B1 | A2 | B2 | |---|---:|---:|---:|---:| | Average fps | 61.5 | 60.5 | 60.8 | 60.7 | | Median frame | 16.15 ms | 16.44 ms | 16.37 ms | 16.44 ms | | p99 frame | 19.25 ms | 19.81 ms | 20.01 ms | 19.26 ms | | Frames of 50 ms or more | 0 | 0 | 0 | 0 | | Quit request to the session stopped | 0.86 s | 0.86 s | 0.60 s | 0.91 s | - Both B runs log `vk: renderer close finished in 1 ms` and `stop: close work done (host tail 0 ms; ...)`. A has no such timings to compare with. - The stop time is measured from the harness's side and includes its own polling, so it is too coarse for a difference of tens of ms. It shows no hang and no large change. - No Vulkan errors in the logs. 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.
Merge branch 'main' into fix/fast-window-close
Some checks are pending
CI / What the change needs (pull_request) Blocked by required conditions
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Blocked by required conditions
CI / Third-party parts and guide screenshots (pull_request) Blocked by required conditions
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Blocked by required conditions
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Blocked by required conditions
CI / Renderer build check (Windows, compile --only renderer, without and with FSR 4) (pull_request) Blocked by required conditions
CI / Renderer build check (Linux, compile --only renderer, without and with FSR 4) (pull_request) Blocked by required conditions
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Blocked by required conditions
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Blocked by required conditions
CI / Website build and checks (pull_request) Blocked by required conditions
beanstalk/approval changed since the request: ask again
PR description / Title and description (pull_request_target) Successful in 7s
6741d2088a
HumanBean deleted branch fix/fast-window-close 2026-12-05 17:43:36 +00:00
Some checks are pending
CI / What the change needs (pull_request) Blocked by required conditions
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Blocked by required conditions
CI / Third-party parts and guide screenshots (pull_request) Blocked by required conditions
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Blocked by required conditions
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Blocked by required conditions
CI / Renderer build check (Windows, compile --only renderer, without and with FSR 4) (pull_request) Blocked by required conditions
CI / Renderer build check (Linux, compile --only renderer, without and with FSR 4) (pull_request) Blocked by required conditions
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Blocked by required conditions
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Blocked by required conditions
CI / Website build and checks (pull_request) Blocked by required conditions
beanstalk/approval changed since the request: ask again
PR description / Title and description (pull_request_target) Successful in 7s
Some workflows are waiting to be reviewed.
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
4 participants
Notifications
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/Longshot!3182
No description provided.