Repository navigation
display(macOS): draw on the view's display link at the screen's rate - #8199
UTMapp-bot wants to merge 4 commits into
Conversation
…ink draws" This reverts commit 9f10688 (utmapp#8195). The CAMetalDisplayLink it fixed is reverted next and replaced by a display link that lets MTKView keep handling its drawables, which does not need this fix. Assisted-by: Claude:claude-opus-5-5
This reverts commit 216660f (utmapp#7983). Its CAMetalDisplayLink hands out the layer's drawables itself, so VMMetalView had to replace MTKView's drawable, render pass descriptor and drawable sizing, and frames were drawn at a stale size (utmapp#8191). The next commit fixes the 60 Hz cap without changing how MTKView draws. Assisted-by: Claude:claude-opus-5-5
MTKView's own timer can stay at 60 Hz for a window on a 120 Hz ProMotion panel while the main display is a 60 Hz one (utmapp#7983). On macOS 14 and later, draw from the display link NSView makes instead: it follows the screen the view is on, and each tick only asks MTKView to draw, so MTKView keeps acquiring and sizing its drawables as it does with its own timer, and a frame always has the view's pixel size (utmapp#8191). macOS 12 and 13 keep MTKView's own timer. Without an FPS limit the link keeps its default rate range, the native rate of whichever screen it is on, so the rate follows the window to another screen and a change of the screen's refresh rate. A range pinned to the screen's rate when it was read stayed at 60 Hz for a window that opened on a 60 Hz screen. With a limit, the link is pinned to the limit. Assisted-by: Claude:claude-opus-5-5
A QEMU display window drawn at another size than the view's pixels is scaled, which blurred every guest in 5.0.9 (utmapp#8191). Draw frames through VMMetalView.drawDisplayLinkFrame(), as the window's display link does, without a VM: after each resize the drawable must have the view's pixel size, and a one-pixel checkerboard drawn by CSMetalRenderer at 1:1 must come back unchanged. With drawDisplayLinkFrame() doing what 5.0.9's display link did (hand the renderer the layer's next drawable), both fail: the drawable keeps the size the view had first. Assisted-by: Claude:claude-opus-5-5
|
Closing this: with a real 60 Hz external display it does not fix the 60 Hz cap, and What was wrong with this PRI had only tested with the built-in 120 Hz panel as the sole display, where every timer runs at 120. In #7983's setup (a 60 Hz external as the main display, the VM window on the 120 Hz built-in panel), draw ticks per second were:
So #7983 chose the right mechanism. The 5.0.9 blur came from how it handled the drawables, which #8195 fixed. Test campaignI compared three builds:
Setup and method:
A few notes on the table:
Recommendation: keep
|
Replaces the
CAMetalDisplayLinkof #7983 (and #8195's fix for it) with the display link NSView makes on macOS 14 and later. Each tick only asks MTKView to draw, so MTKView handles its drawables as it does with its own timer. As decided in #8195, this reverts both and lands the new commit and its tests in one PR:CAMetalDisplayLink. It handed out the layer's drawables itself, soVMMetalViewhad to replace MTKView's drawable, render pass descriptor and drawable sizing, and frames were drawn at a stale size (5.0.9 regression: Retina mode appears blurry in Windows and Debian #8191).VMMetalView.drawDisplayLinkFrame()(draw()). MTKView acquires and sizes the drawables, andVMMetalViewoverrides none of it.Tests/macOS/VMMetalViewDrawableTests.swift): frames drawn throughdrawDisplayLinkFrame(), without a VM.CSMetalRendererat 1:1 must come back unchanged.Testing
Tested by an AI agent on a MacBook Pro (Apple M2 Max) with only its built-in panel, a Retina display at backing scale 2 that supports ProMotion and fixed rates, on macOS 27.2. The guest was Ubuntu 26.04 arm64 GNOME on QEMU with
virtio-gpu-gl-pci, GPU acceleration on and dynamic resolution on, each boot disposable.Frame rate follows the screen. To show the pinned rate, I switched the built-in panel's mode for the login session with
CGConfigureDisplayWithDisplayMode. I opened the VM window with the panel at 60 Hz, then switched the panel to 120 Hz (ProMotion). The link's rate comes from temporary logging of1 / (targetTimestamp - timestamp)in the link callback; the logging is not committed.With an FPS limit of 30 (
QEMURendererFPSLimit) on the 120 Hz panel, the link ran at 30 Hz. The limit was absent before the test and was removed after it. The panel was set back to its original 120 Hz mode.Retina sharpness (#8191): the VM window was captured at full pixel size and edge contrast measured over the same text in the guest's top bar, as in #8195.
Top bar at 1:1, 5.0.9 then this PR:
Pause and resume: while the VM is paused, UTM uses 0.0% CPU. After resuming, the window updates again:
vkcubeframes reach it, at the rate this guest renders.Unit tests:
./scripts/test_utm.sh -only-testing:UTMTests/VMMetalViewDrawableTestspasses, and so doesVMMetalViewKeyboardTests.Tests/Static/run_all.shpasses. For a fail-before check, I madedrawDisplayLinkFrame()temporarily do what 5.0.9's display link did: hand the renderer the layer's next drawable. Both tests then fail: the drawable stays 800x600 while the view is 1280x800, 640x400 or 64x48 pixels, and the checkerboard does not come back.Not tested:
Known and unchanged:
CSMetalRenderertakes a drawable on every tick before it checks whether there is a new frame, so an idle guest costs one drawable per tick (idle CPU 2.8% of a core here, Debug build). Checking first in CocoaSpice would save that.