metal, window: a minimised or covered window presents nothing instead of stalling #341

Merged
derz92 merged 1 commit from upstream-pr/341 into main 2026-11-27 16:14:20 +00:00
derz92 commented 2026-11-27 13:02:37 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by derz92 on 2026-11-27T13:02:37Z.


What this changes

Refs #333.

While the game window is minimised or wholly covered, a present no longer waits for a drawable. victory_metal::present::try_present counts the frame as shown and draws nothing, as in a headless run. The window's event loop reports its visibility each pass: isMiniaturized, or occlusionState without NSWindowOcclusionStateVisible. It does that through victory_gpu::set_window_hidden, a re-export of victory_metal::present::set_window_hidden, so the app gains no dependency and Cargo.lock doesn't change. A drawable acquisition already in flight is still taken. When the window can be seen again, presents go back to the layer. The change is logged once each way (present: the window's visibility changed hidden=…).

How it was tested

Apple M5 Max, 36 GB, macOS 26.5, windowed, --console series-s, VICTORY_COUNT_GREEN=1. The window was minimised from outside with System Events (AXMinimized) 12 s into the run and restored 30 s later:

  • Before: with the window minimised, presents fell to ~18/s for about 5 s and then stopped. The title stopped with them (details in #333).
  • With this change: hidden=true at 12:28:37, hidden=false at 12:29:07. Presents kept going all the time it was minimised (22–30 per second), it drew normally once restored, and the run went on into the story load with no fault.

Checks:

  • cargo test -p victory-metal --lib present (arm64): 3 passed. The new test is a_hidden_window_presents_without_a_drawable: with a drawable worker that never answers, three hidden presents return Ok(true) and count, and once visible again the present waits as before. Both present tests now take a lock, since the flag is process-wide.
  • cargo test --target x86_64-apple-darwin -p victory-hle -p victory-loader -p victory: all pass except host_posix::ucrt::tests::dlls_that_are_not_the_c_runtime_are_left_alone, which fails the same way on main at 86786a72.
  • cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings
  • cargo xtask policy
  • Ran the game, as above.

Checklist

  • No game files, game code, disassembly listings or SDK files are included
  • Guesses about undocumented console behaviour are marked in the code and in docs/native-host.md (none: this is host presentation)
  • New diagnostics are behind a VICTORY_* variable and documented (no new diagnostics)
<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:5527085004 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/341). Originally posted by [derz92](https://github.com/derz92) on 2026-11-27T13:02:37Z. --- ## What this changes Refs #333. While the game window is minimised or wholly covered, a present no longer waits for a drawable. `victory_metal::present::try_present` counts the frame as shown and draws nothing, as in a headless run. The window's event loop reports its visibility each pass: `isMiniaturized`, or `occlusionState` without `NSWindowOcclusionStateVisible`. It does that through `victory_gpu::set_window_hidden`, a re-export of `victory_metal::present::set_window_hidden`, so the app gains no dependency and `Cargo.lock` doesn't change. A drawable acquisition already in flight is still taken. When the window can be seen again, presents go back to the layer. The change is logged once each way (`present: the window's visibility changed hidden=…`). ## How it was tested Apple M5 Max, 36 GB, macOS 26.5, windowed, `--console series-s`, `VICTORY_COUNT_GREEN=1`. The window was minimised from outside with System Events (`AXMinimized`) 12 s into the run and restored 30 s later: - **Before:** with the window minimised, presents fell to ~18/s for about 5 s and then stopped. The title stopped with them (details in #333). - **With this change:** `hidden=true` at 12:28:37, `hidden=false` at 12:29:07. Presents kept going all the time it was minimised (22–30 per second), it drew normally once restored, and the run went on into the story load with no fault. Checks: - [x] `cargo test -p victory-metal --lib present` (arm64): 3 passed. The new test is `a_hidden_window_presents_without_a_drawable`: with a drawable worker that never answers, three hidden presents return `Ok(true)` and count, and once visible again the present waits as before. Both present tests now take a lock, since the flag is process-wide. - [x] `cargo test --target x86_64-apple-darwin -p victory-hle -p victory-loader -p victory`: all pass except `host_posix::ucrt::tests::dlls_that_are_not_the_c_runtime_are_left_alone`, which fails the same way on main at 86786a72. - [x] `cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings` - [x] `cargo xtask policy` - [x] Ran the game, as above. ## Checklist - [x] No game files, game code, disassembly listings or SDK files are included - [x] Guesses about undocumented console behaviour are marked in the code and in docs/native-host.md (none: this is host presentation) - [x] New diagnostics are behind a `VICTORY_*` variable and documented (no new diagnostics)
LakshanSivakumar commented 2026-11-27 16:15:19 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T16:15:19Z.


Merged in 4cf84c83. Before pushing I ran the tests (native arm64), Windows clippy, the policy check, a release build, and one headless game run of the exact tree (170 s, Series S): menus at 30 fps, the world entered at about 81 s and kept presenting to the end at about 1 frame a second, 0 GPU errors, no crash. The run was headless, so I did not try minimising a window. Thanks.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7223041975 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/341#issuecomment-7223041975). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-27T16:15:19Z. --- Merged in 4cf84c83. Before pushing I ran the tests (native arm64), Windows clippy, the policy check, a release build, and one headless game run of the exact tree (170 s, Series S): menus at 30 fps, the world entered at about 81 s and kept presenting to the end at about 1 frame a second, 0 GPU errors, no crash. The run was headless, so I did not try minimising a window. Thanks.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
LakshanSivakumar/Native-Victory-macOS!341
No description provided.