From ee6794225d2be8cb56afb9ba441a89d5e1319b87 Mon Sep 17 00:00:00 2001 From: der richter Date: Sat, 6 Apr 2024 23:31:05 +0200 Subject: mac/vulkan: add support for frame timing via presentation feedback --- video/out/mac_common.swift | 20 ++++++++++++++++++-- video/out/vulkan/context_mac.m | 7 +++++++ 2 files changed, 25 insertions(+), 2 deletions(-) (limited to 'video/out') diff --git a/video/out/mac_common.swift b/video/out/mac_common.swift index 4551c47d91..f29815d73d 100644 --- a/video/out/mac_common.swift +++ b/video/out/mac_common.swift @@ -20,6 +20,7 @@ import Cocoa class MacCommon: Common { @objc var layer: MetalLayer? + var presentation: Presentation? var timer: PreciseTimer? var swapTime: UInt64 = 0 let swapLock: NSCondition = NSCondition() @@ -30,6 +31,7 @@ class MacCommon: Common { super.init(option, log) self.vo = vo input = InputHelper(vo.pointee.input_ctx, option) + presentation = Presentation(common: self) timer = PreciseTimer(common: self) DispatchQueue.main.sync { @@ -89,7 +91,7 @@ class MacCommon: Common { } @objc func swapBuffer() { - if option.mac.macos_render_timer != RENDER_TIMER_SYSTEM { + if option.mac.macos_render_timer > RENDER_TIMER_SYSTEM { swapLock.lock() while(swapTime < 1) { swapLock.wait() @@ -99,6 +101,15 @@ class MacCommon: Common { } } + @objc func fillVsync(info: UnsafeMutablePointer) { + if option.mac.macos_render_timer != RENDER_TIMER_PRESENTATION_FEEDBACK { return } + + let next = presentation?.next() + info.pointee.vsync_duration = next?.duration ?? -1 + info.pointee.skipped_vsyncs = next?.skipped ?? -1 + info.pointee.last_queue_display_time = next?.time ?? -1 + } + override func displayLinkCallback(_ displayLink: CVDisplayLink, _ inNow: UnsafePointer, _ inOutputTime: UnsafePointer, @@ -112,13 +123,18 @@ class MacCommon: Common { self.swapLock.unlock() } - if option.mac.macos_render_timer != RENDER_TIMER_SYSTEM { + if option.mac.macos_render_timer > RENDER_TIMER_SYSTEM { if let timer = self.timer, option.mac.macos_render_timer == RENDER_TIMER_PRECISE { timer.scheduleAt(time: inOutputTime.pointee.hostTime, closure: signalSwap) return kCVReturnSuccess } signalSwap() + return kCVReturnSuccess + } + + if option.mac.macos_render_timer == RENDER_TIMER_PRESENTATION_FEEDBACK { + presentation?.add(time: inOutputTime.pointee) } return kCVReturnSuccess diff --git a/video/out/vulkan/context_mac.m b/video/out/vulkan/context_mac.m index be5c077155..bedd0d4f9e 100644 --- a/video/out/vulkan/context_mac.m +++ b/video/out/vulkan/context_mac.m @@ -44,6 +44,12 @@ static void mac_vk_swap_buffers(struct ra_ctx *ctx) [p->vo_mac swapBuffer]; } +static void mac_vk_get_vsync(struct ra_ctx *ctx, struct vo_vsync_info *info) +{ + struct priv *p = ctx->priv; + [p->vo_mac fillVsyncWithInfo:info]; +} + static bool mac_vk_init(struct ra_ctx *ctx) { struct priv *p = ctx->priv = talloc_zero(ctx, struct priv); @@ -66,6 +72,7 @@ static bool mac_vk_init(struct ra_ctx *ctx) struct ra_vk_ctx_params params = { .swap_buffers = mac_vk_swap_buffers, + .get_vsync = mac_vk_get_vsync, }; VkInstance inst = vk->vkinst->instance; -- cgit v1.2.3