From 78ba0ded93228326714cd254a76aaaa0941ab397 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Tue, 4 Jun 2024 21:06:51 +0900 Subject: [PATCH] Revert "internal/glfw: bug fix: limit the DWM swap interval to Vista and 7" This reverts commit 86e0bcc26472c8da05fac66d84d5dd3869d55e00. Reason: This caused some issues like too much GPU usages. Updates #2961 Closes #3003 --- internal/glfw/wgl_context_windows.go | 45 +++++++++++++++++----------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/internal/glfw/wgl_context_windows.go b/internal/glfw/wgl_context_windows.go index cff168e75..305755f97 100644 --- a/internal/glfw/wgl_context_windows.go +++ b/internal/glfw/wgl_context_windows.go @@ -261,18 +261,23 @@ func makeContextCurrentWGL(window *Window) error { } func swapBuffersWGL(window *Window) error { - if window.monitor == nil { - // HACK: Use DwmFlush when desktop composition is enabled on Windows Vista and 7 - if !winver.IsWindows8OrGreater() && winver.IsWindowsVistaOrGreater() { - enabled, err := _DwmIsCompositionEnabled() + if window.monitor == nil && winver.IsWindowsVistaOrGreater() { + // DWM Composition is always enabled on Win8+ + enabled := winver.IsWindows8OrGreater() + + if !enabled { + var err error + enabled, err = _DwmIsCompositionEnabled() if err != nil { return err } - if enabled { - for i := 0; i < window.context.platform.interval; i++ { - // Ignore an error from DWM functions as they might not be implemented e.g. on Proton (#2113). - _ = _DwmFlush() - } + } + + // HACK: Use DwmFlush when desktop composition is enabled + if enabled { + for i := 0; i < window.context.platform.interval; i++ { + // Ignore an error from DWM functions as they might not be implemented e.g. on Proton (#2113). + _ = _DwmFlush() } } } @@ -292,19 +297,23 @@ func swapIntervalWGL(interval int) error { window.context.platform.interval = interval - if window.monitor == nil { - // HACK: Disable WGL swap interval when desktop composition is enabled on Windows - // Vista and 7 to avoid interfering with DWM vsync - if !winver.IsWindows8OrGreater() && winver.IsWindowsVistaOrGreater() { - enabled, err := _DwmIsCompositionEnabled() + if window.monitor == nil && winver.IsWindowsVistaOrGreater() { + // DWM Composition is always enabled on Win8+ + enabled := winver.IsWindows8OrGreater() + + if !enabled { + e, err := _DwmIsCompositionEnabled() // Ignore an error from DWM functions as they might not be implemented e.g. on Proton (#2113). if err == nil { - enabled = false - } - if enabled { - interval = 0 + enabled = e } } + + // HACK: Disable WGL swap interval when desktop composition is enabled to + // avoid interfering with DWM vsync + if enabled { + interval = 0 + } } if _glfw.platformContext.EXT_swap_control {