From 250e4ed622d108c1b687dbc8c25b1c7b721b2f72 Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Sun, 17 Mar 2019 14:42:14 +0200 Subject: [PATCH 1/4] - do not use OpenGL function to clear screen in Cocoa backend In fullscreen mode there is a white flash (of the default background color) on startup To overcome this an explicit glClear() with flush buffers was used In order to make video mode switch more generic, any backend specific functionality should be avoided here --- src/posix/cocoa/i_video.mm | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/src/posix/cocoa/i_video.mm b/src/posix/cocoa/i_video.mm index 1b6b5815f..b1334778f 100644 --- a/src/posix/cocoa/i_video.mm +++ b/src/posix/cocoa/i_video.mm @@ -52,10 +52,7 @@ #include "version.h" #include "doomerrors.h" -#include "gl/renderer/gl_renderer.h" #include "gl/system/gl_framebuffer.h" -#include "gl/textures/gl_samplers.h" - #include "vulkan/system/vk_framebuffer.h" @@ -182,6 +179,12 @@ namespace @implementation OpenGLCocoaView +- (void)drawRect:(NSRect)dirtyRect +{ + [NSColor.blackColor setFill]; + NSRectFill(dirtyRect); +} + - (void)resetCursorRects { [super resetCursorRects]; @@ -327,9 +330,6 @@ void SetupOpenGLView(CocoaWindow* window) [[glView openGLContext] makeCurrentContext]; [window setContentView:glView]; - - // To be able to use OpenGL functions in SetMode() - ogl_LoadFunctions(); } } // unnamed namespace @@ -658,14 +658,6 @@ void SystemGLFrameBuffer::SetMode(const bool fullscreen, const bool hiDPI) SetWindowedMode(); } - const NSSize viewSize = I_GetContentViewSize(m_window); - - glViewport(0, 0, static_cast(viewSize.width), static_cast(viewSize.height)); - glClearColor(0.0f, 0.0f, 0.0f, 1.0f); - glClear(GL_COLOR_BUFFER_BIT); - - [[NSOpenGLContext currentContext] flushBuffer]; - [m_window updateTitle]; if (![m_window isKeyWindow]) From 83de8ae5a0a0fe7972aaaeb2cdadd1fdcb7df186 Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Sun, 17 Mar 2019 14:43:27 +0200 Subject: [PATCH 2/4] - fixed white flash on startup with Metal-based view --- src/posix/cocoa/i_video.mm | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/posix/cocoa/i_video.mm b/src/posix/cocoa/i_video.mm index b1334778f..2d0bb1113 100644 --- a/src/posix/cocoa/i_video.mm +++ b/src/posix/cocoa/i_video.mm @@ -237,11 +237,6 @@ namespace m_cursor = cursor; } --(BOOL) wantsUpdateLayer -{ - return YES; -} - +(Class) layerClass { return NSClassFromString(@"CAMetalLayer"); @@ -365,7 +360,8 @@ public: const NSRect contentRect = [ms_window contentRectForFrameRect:[ms_window frame]]; NSView* vulkanView = [[VulkanCocoaView alloc] initWithFrame:contentRect]; - [vulkanView setWantsLayer:YES]; + vulkanView.wantsLayer = YES; + vulkanView.layer.backgroundColor = NSColor.blackColor.CGColor; [ms_window setContentView:vulkanView]; } From 97fc3aa9a65bdcc365d150de35590238905e67f8 Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Sun, 17 Mar 2019 14:45:19 +0200 Subject: [PATCH 3/4] - avoid Vulkan initialization when it's disabled in Cocoa backend --- src/posix/cocoa/i_video.mm | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/posix/cocoa/i_video.mm b/src/posix/cocoa/i_video.mm index 2d0bb1113..f89331ede 100644 --- a/src/posix/cocoa/i_video.mm +++ b/src/posix/cocoa/i_video.mm @@ -364,24 +364,24 @@ public: vulkanView.layer.backgroundColor = NSColor.blackColor.CGColor; [ms_window setContentView:vulkanView]; + + try + { + m_vulkanDevice = new VulkanDevice(); + fb = new VulkanFrameBuffer(nullptr, fullscreen, m_vulkanDevice); + } + catch (std::exception const&) + { + ms_isVulkanEnabled = false; + + SetupOpenGLView(ms_window); + } } else { SetupOpenGLView(ms_window); } - try - { - m_vulkanDevice = new VulkanDevice(); - fb = new VulkanFrameBuffer(nullptr, fullscreen, m_vulkanDevice); - } - catch (std::exception const&) - { - ms_isVulkanEnabled = false; - - SetupOpenGLView(ms_window); - } - if (fb == nullptr) { fb = new OpenGLRenderer::OpenGLFrameBuffer(0, fullscreen); From be9a43f1777a4ad41a51159916e35e44053fa33e Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Sun, 17 Mar 2019 18:20:24 +0200 Subject: [PATCH 4/4] - added temp hack for perf issue with Metal layer in fullscreen --- src/posix/cocoa/i_video.mm | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/posix/cocoa/i_video.mm b/src/posix/cocoa/i_video.mm index f89331ede..682b2239c 100644 --- a/src/posix/cocoa/i_video.mm +++ b/src/posix/cocoa/i_video.mm @@ -391,6 +391,16 @@ public: fb->SetMode(fullscreen, vid_hidpi); fb->SetSize(fb->GetClientWidth(), fb->GetClientHeight()); + // This lame hack is a temporary workaround for strange performance issues + // with fullscreen window and Core Animation's Metal layer + // It is somehow related to initial window level and flags + // Toggling fullscreen -> window -> fullscreen mysteriously solves the problem + if (ms_isVulkanEnabled && fullscreen) + { + fb->SetMode(false, vid_hidpi); + fb->SetMode(true, vid_hidpi); + } + return fb; }