From 5887142da7dd0a1156cdb73aa4a4c916be147c66 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Fri, 19 Jan 2024 18:28:39 +0900 Subject: [PATCH] internal/grpahicsdriver/metal/mtl: use 3 drawings for fullscreen Hajime found that renderings were delayed with 2 drawing in fullscreen though FPS might be lowered. This is mysterious but there is no other good solution. Updates #2883 --- internal/graphicsdriver/metal/view_macos.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/internal/graphicsdriver/metal/view_macos.go b/internal/graphicsdriver/metal/view_macos.go index 189cc8d32..ef1f04483 100644 --- a/internal/graphicsdriver/metal/view_macos.go +++ b/internal/graphicsdriver/metal/view_macos.go @@ -36,6 +36,8 @@ func (v *view) setUIView(uiview uintptr) { } func (v *view) update() { + v.ml.SetMaximumDrawableCount(v.maximumDrawableCount()) + if !v.windowChanged { return } @@ -44,6 +46,7 @@ func (v *view) update() { cocoaWindow := cocoa.NSWindow{ID: objc.ID(v.window)} cocoaWindow.ContentView().SetLayer(uintptr(v.ml.Layer())) cocoaWindow.ContentView().SetWantsLayer(true) + v.windowChanged = false } @@ -61,6 +64,16 @@ func (v *view) maximumDrawableCount() int { return 3 } - // Use 2 for Arm Mac (#2883). + // Use 3 in fullscren. + // Though this might degrade FPS, this is necessary to avoid mysterious rendering delays. + if v.isFullscreen() { + return 3 + } + + // Use 2 for a Wnidow to avoid mysterious blinking (#2883). return 2 } + +func (v *view) isFullscreen() bool { + return cocoa.NSWindow{ID: objc.ID(v.window)}.StyleMask()&cocoa.NSWindowStyleMaskFullScreen != 0 +}