Skip to content

display(macOS): revert the display link and its follow-up fix (#7983, #8195) - #8205

Merged
osy merged 2 commits into
utmapp:mainfrom
UTMapp-bot:revert/display-link
Nov 18, 2026
Merged

osy merged 2 commits into
utmapp:mainfrom
UTMapp-bot:revert/display-link

Conversation

@UTMapp-bot

Copy link
Copy Markdown
Collaborator

Reverts #8195 and #7983. The QEMU display window on macOS goes back to drawing from MTKView's own timer, as in 5.0.8.

The maintainer has decided to revert these changes completely rather than ship another hot patch. @dragoshont, this concerns your #7983. Thank you for finding the 60 Hz cap and for the careful measurements in that PR. Two regressions got past several rounds of validation, one of them in an emergency release, and each fix added another override of MTKView's internals. So UTM will follow Apple's framework behavior here, even where that behavior is a framework bug, rather than maintain a workaround this fragile. If the remaining cap (below) affects you, please report it to Apple with Feedback Assistant as a MetalKit bug: MTKView's internal display link stays on the display that was main when the view was created, and doesn't follow the window to a faster screen.

Fixes #8204

What still works: 120 Hz is not gone

On a Mac with a 120 Hz ProMotion panel, VM windows are drawn at the full 120 Hz in the common setups:

  • No external display. The window is drawn at the panel's rate. Measured here: 120 draws per second, about 120 fps from a guest rendering at 120 Hz.
  • The built-in panel is the main display (it has the menu bar) and an external display is connected. A window on the built-in panel is drawn at 120 Hz.
  • A window on the main display, whatever it is. It's drawn at that display's rate. Measured with a 60 Hz external as main; a faster external as main was not tested.
  • A refresh-rate change of the panel (ProMotion ↔ 60 Hz in System Settings) is followed: MTKView's timer follows its display's current mode. This was shown with a stock MTKView in a small test app, not yet in UTM.

Also unchanged from 5.0.8:

Where 120 Hz does not work after this revert

MTKView's timer stays on the display that was the main display when the VM window was created. So:

  • A window on a 120 Hz panel while a slower external display is the main display. For example, a MacBook Pro with a 60 Hz external monitor set as main and the VM window on the built-in panel: the window is drawn at 60 Hz. This is 75HZ is maximum in VM #7820 / display: fix 60 Hz cap on ProMotion screens #7983's case, and it comes back.
  • Two displays with different refresh rates in general, for a window on a display faster than the one that was main when the window opened.
  • The main display changes while a VM window is open. The window keeps the old main display's rate until it is opened again.
  • A window that opened on a 60 Hz display and is then moved to a 120 Hz one stays at 60 Hz until the VM starts again. Its frame rate is set from the screen it opened on.
  • Secondary display windows (a VM with several displays) take their rate from the screen they open on and keep it.
  • The guest is told one rate while the window draws at another in the capped case. Since qemu: tell the guest the host display's refresh rate #7982 (also in 5.0.9, not reverted here), UTM tells QEMU the refresh rate of the screen the window is on when the VM starts. On a 120 Hz panel next to a 60 Hz main display, the guest renders at 120 Hz while 60 frames a second reach the screen. 5.0.8 never had this combination.

Two smaller behaviors also return to 5.0.8's:

  • A changed FPS limit takes effect at the next VM start, not when a paused VM resumes.
  • The timer keeps ticking while the window is minimized, hidden or the VM is paused. UTM measured 0.6% CPU paused, against 0.0% with the display link.

History

All times UTC.

When What
2026-08-13 #7820: VM display capped below the panel's refresh rate.
2026-10-18 #7983 (@dragoshont) opened. It replaces MTKView's timer with a CAMetalDisplayLink on macOS 14+, so a window on a 120 Hz panel is no longer held at a 60 Hz main display's rate.
2026-11-12 Bot retest of the rebased #7983. It measured frame rates only: 120 Hz on the panel next to a 60 Hz main display, moves, pause, FPS limit, full screen. #7983 merged.
2026-11-16 5.0.9 released with #7983.
2026-11-17 01:46 #8191: Retina mode blurry in 5.0.9 (Windows and Linux guests). Cause: the display link handed out the layer's drawables while MTKView, paused, never applied its drawable size to the layer. Every frame was drawn at the size the window opened with and then scaled.
2026-11-17 07:02 #8195 (bot) opened: keep the layer's drawable size in step with the view. Merged 15:08.
2026-11-17 15:13 The maintainer asked for other possible regressions, a simpler approach, and regression tests.
2026-11-17 18:34 #8199 opened: replace the CAMetalDisplayLink with NSView.displayLink. Tested only with the built-in panel as the sole display.
2026-11-18 about 00:30–04:00 Tested with a real 60 Hz external display: #8199 does not escape the cap (60 Hz), nor does NSScreen.displayLink. Only a presenting CAMetalDisplayLink (#7983) reaches 120 Hz. #8199 closed.
2026-11-18 04:15 5.0.9-1 emergency release cut at 9cc3119, with #8195. It has since been deleted.
2026-11-18 05:29 #8204: UTM crashes at VM start with CAMetalLayerInvalidOperation: -nextDrawable should not be called when using CAMetalDisplayLink. Present since #7983, so in 5.0.9 too; reported on 5.0.9-1.
2026-11-18 This revert.

Edge cases found and handled after #7983 was merged

  • Fixed in display(macOS): keep Retina displays sharp when the display link draws #8195 and its review:
    • The layer kept its first drawable size (5.0.9 regression: Retina mode appears blurry in Windows and Debian #8191).
    • A one-frame lag when syncing the size from the frame callback; the sync moved to the resize and backing-scale changes themselves.
    • A zero drawable size during window transitions.
    • Drawables the link took before a resize; those frames are now skipped.
    • The size sync limited to display-link mode, so macOS 12/13 were untouched.
  • Found in follow-up review and testing, not merged:
    • MTKView settings dropped by the hand-built render pass descriptor (depth, stencil, sample count).
    • A draw arriving outside the link callback falls back to MTKView's own drawable. This was noted as a risk, but not tested; it is macOS: VM startup crash in nextDrawable when using CAMetalDisplayLink #8204.
    • A drawable taken on every idle tick.
    • The rate range pinned to the screen's rate when read, not following a refresh-rate change.
    • The link holding the view strongly.
    • The link running before the VM is live.
    • NSView.displayLink and NSScreen.displayLink capped at the main display's rate, just like MTKView's timer.
    • An alternative that retargets MTKView's own CVDisplayLink to the window's screen. It works, but it reads a private MTKView ivar and keeps drawing while hidden.

The two regressions that got past validation

  1. 5.0.9 regression: Retina mode appears blurry in Windows and Debian #8191 (blur), in 5.0.9. display: fix 60 Hz cap on ProMotion screens #7983's testing and the bot's retest measured the frame rate it improved, not image quality or drawable size. Every resized or Retina window was affected.
  2. macOS: VM startup crash in nextDrawable when using CAMetalDisplayLink #8204 (startup crash), in 5.0.9 and 5.0.9-1.
    • It is a startup ordering race: MTKView's timer runs between adding the view and pausing it, and a draw it queued then reaches the layer after the display link owns it.
    • No test targeted startup ordering. A 21-scenario comparison of the options on 2026-11-18 started each build only a few times.
    • On this Mac it does not fire on its own (0 crashes in 10 starts on 5.0.9-1); it reproduces every time with a 100 ms delay in that gap.

Testing

Tested by an AI agent on a MacBook Pro (Apple M2 Max), macOS 27.2, with its built-in 120 Hz ProMotion panel and a 1280x720 60 Hz external display. Guest: Ubuntu 26.04 arm64 on virtio-gpu-gl-pci, booted disposable.

Results on the code in this PR:

  • Startup, 20 cycles: start the VM, check that its window opened, stop it. 20 of 20 windows opened, UTM stayed up, and there were no new crash reports.
  • Sharpness, Retina mode at 1:1 on the built-in panel: the same edge-contrast measurement on the guest's top-bar text as in display(macOS): keep Retina displays sharp when the display link draws #8195 gives 21.691/13.579. The 5.0.8 release, measured in the same session, gives identical values.
  • Rendering: the guest's display mode was 120 Hz, and kmscube ran on its console. With the built-in panel as the only display, 120 fps reached the window (686 frames at 8.3 ms).
  • Not repeated on this exact build: the case with a 60 Hz external as the main display. The external display was disconnected during this run. That case is covered by the run below.

The same code (with temporary counters, not committed) went through the 21-scenario comparison and the unplug test on 2026-11-18 as option "A". Every step drew at the view's pixel size (0 mismatches). It was capped at 60 Hz only when a 60 Hz external was the main display, and it recovered when the external display was unplugged and plugged back.

osy added 2 commits November 17, 2026 22:08
…ink draws"

This reverts commit 9f10688 (utmapp#8195), a
fix for the CAMetalDisplayLink of utmapp#7983, which is reverted next.

Assisted-by: Claude:claude-opus-5-5
This reverts commit 216660f (utmapp#7983).

Drawing from a CAMetalDisplayLink while MTKView still owns the drawing
setup made the display blurry in 5.0.9 (utmapp#8191, fixed by utmapp#8195, reverted
before this) and can crash at VM start when a draw MTKView's own timer
queued asks the layer for a drawable while the link owns it (utmapp#8204).
Each fix adds another override of MTKView's internals. Go back to
MTKView's own timer: a window on a 120 Hz panel is again drawn at the
main display's rate when that is a slower external display.

Assisted-by: Claude:claude-opus-5-5
@osy
osy merged commit a83a99f into utmapp:main Nov 18, 2026
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

macOS: VM startup crash in nextDrawable when using CAMetalDisplayLink

2 participants