[PR #1415] [CLOSED] macOS: VSync off no longer holds a window to the display's refresh rate #3504

Closed
opened 2026-11-03 04:10:00 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/1415
Author: @ludovic111
Created: 10/23/2026
Status: ❌ Closed

Base: main ← Head: fix/macos-uncapped-redraw


📝 Commits (1)

  • 2b8326b macOS: VSync off no longer holds a window to the display's refresh rate

📊 Changes

4 files changed (+71 additions, -5 deletions)

View changed files

📝 Cargo.toml (+5 -2)
📝 crates/horizon-client/src/gfx.rs (+23 -2)
📝 third_party/wgpu-hal/src/metal/mod.rs (+19 -1)
📝 third_party/wgpu-hal/src/metal/surface.rs (+24 -0)

📄 Description

🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself.

What

On macOS a window with VSync off ran at the display's refresh rate: the published Mac mini benchmarks sit at 144 FPS on a 144 Hz screen (frame p50 6.95 ms) with 0.7 ms of CPU a frame, while vanilla's OpenGL window on the same Mac reaches 175 FPS (#1333).

Why: with VSync off the Metal layer presents without display sync (setDisplaySyncEnabled(false), Immediate), but a window's compositor still takes one drawable a refresh. The CAMetalLayer has three; once two are waiting for the display, nextDrawable (in get_current_texture) blocks until the next refresh releases one. (winit's request_redraw isn't it: on macOS it is delivered at the end of the same loop iteration.)

Fix:

  • Vendored wgpu-hal (Metal): the surface counts the drawables presented and not yet shown (or dropped), from each drawable's addPresentedHandler. With display sync off and one still queued, acquire_texture returns Timeout instead of waiting. If a handler never comes, it stops after 100 ms (count reset, saturating decrements). Cargo.toml's patch note says so.
  • Renderer: on that Timeout with VSync off (macOS only), the frame is drawn into the offscreen target and not presented. The display shows the newest frame each refresh, as vanilla's GL window drops the frames it has no time for. The offscreen target is made when first needed and dropped on resize; offscreen-only mode now has its own flag (windowless), so surface recreation still works in a window. VSync on (Fifo) is unchanged.

Fixes #1333 once proven on a screen, see below.

Not proven yet: needs an unlocked Mac

The Mac mini's session is locked (CGSSessionScreenIsLocked = Yes), so a window there is never composited: a windowed run draws 0 frames, on main as on this branch (the hal's occlusion check returns Occluded first). Offscreen runs don't present at all, so they can't show the cap. To prove it: with the screen unlocked, python3 tools/perf_bench.py --game horizon --distances 12 --scenes village --repeats 1 on main and on this branch; main should read ~144 FPS, this branch well above it (offscreen, the same build draws this scene at ~1,500 FPS). This PR stays a draft until that run.

How tested

  • cargo fmt --all --check, cargo clippy -p horizon-client -- -D warnings on macOS: clean (wgpu-hal is built as a patched dependency; rustfmt on the two hal files)
  • Linux, Windows: the code is behind cfg(target_os = "macos") there (and only reached with a Timeout, which Vulkan's acquire doesn't return here)

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon/pull/1415 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/23/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/macos-uncapped-redraw` --- ### 📝 Commits (1) - [`2b8326b`](https://github.com/horizon-rust/horizon/commit/2b8326b13167aef7a65999ce0f71d07331fda9c1) macOS: VSync off no longer holds a window to the display's refresh rate ### 📊 Changes **4 files changed** (+71 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `Cargo.toml` (+5 -2) 📝 `crates/horizon-client/src/gfx.rs` (+23 -2) 📝 `third_party/wgpu-hal/src/metal/mod.rs` (+19 -1) 📝 `third_party/wgpu-hal/src/metal/surface.rs` (+24 -0) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. ## What On macOS a window with VSync off ran at the display's refresh rate: the published Mac mini benchmarks sit at 144 FPS on a 144 Hz screen (frame p50 6.95 ms) with 0.7 ms of CPU a frame, while vanilla's OpenGL window on the same Mac reaches 175 FPS (#1333). Why: with VSync off the Metal layer presents without display sync (`setDisplaySyncEnabled(false)`, Immediate), but a window's compositor still takes one drawable a refresh. The CAMetalLayer has three; once two are waiting for the display, `nextDrawable` (in `get_current_texture`) blocks until the next refresh releases one. (winit's `request_redraw` isn't it: on macOS it is delivered at the end of the same loop iteration.) Fix: - **Vendored wgpu-hal (Metal):** the surface counts the drawables presented and not yet shown (or dropped), from each drawable's `addPresentedHandler`. With display sync off and one still queued, `acquire_texture` returns `Timeout` instead of waiting. If a handler never comes, it stops after 100 ms (count reset, saturating decrements). Cargo.toml's patch note says so. - **Renderer:** on that `Timeout` with VSync off (macOS only), the frame is drawn into the offscreen target and not presented. The display shows the newest frame each refresh, as vanilla's GL window drops the frames it has no time for. The offscreen target is made when first needed and dropped on resize; offscreen-only mode now has its own flag (`windowless`), so surface recreation still works in a window. VSync on (Fifo) is unchanged. Fixes #1333 once proven on a screen, see below. ## Not proven yet: needs an unlocked Mac The Mac mini's session is locked (`CGSSessionScreenIsLocked = Yes`), so a window there is never composited: a windowed run draws 0 frames, on main as on this branch (the hal's occlusion check returns `Occluded` first). Offscreen runs don't present at all, so they can't show the cap. To prove it: with the screen unlocked, `python3 tools/perf_bench.py --game horizon --distances 12 --scenes village --repeats 1` on main and on this branch; main should read ~144 FPS, this branch well above it (offscreen, the same build draws this scene at ~1,500 FPS). This PR stays a draft until that run. ## How tested - `cargo fmt --all --check`, `cargo clippy -p horizon-client -- -D warnings` on macOS: clean (wgpu-hal is built as a patched dependency; rustfmt on the two hal files) - Linux, Windows: the code is behind `cfg(target_os = "macos")` there (and only reached with a Timeout, which Vulkan's acquire doesn't return here) 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 04:10:00 +07:00
Sign in to join this conversation.
No milestone
No project
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.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#3504
No description provided.