From 4fbf9b7d85977c5ea4f19ce61bb53206321eb3d6 Mon Sep 17 00:00:00 2001 From: Eoin Mcloughlin Date: Wed, 16 Oct 2024 17:50:09 +0100 Subject: [PATCH 1/4] Fix race condition when swapping buffers of secondary windows --- Robust.Client/Graphics/Clyde/GLContext/GLContextWindow.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Robust.Client/Graphics/Clyde/GLContext/GLContextWindow.cs b/Robust.Client/Graphics/Clyde/GLContext/GLContextWindow.cs index d5dc1938480..cfbfb03f5e4 100644 --- a/Robust.Client/Graphics/Clyde/GLContext/GLContextWindow.cs +++ b/Robust.Client/Graphics/Clyde/GLContext/GLContextWindow.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Threading; using System.Threading.Channels; @@ -212,8 +212,8 @@ private void BlitThreadDoSecondaryWindowBlit(WindowData window) GL.DrawArrays(PrimitiveType.TriangleStrip, 0, 4); Clyde.CheckGlError(); - window.BlitDoneEvent?.Set(); Clyde._windowing!.WindowSwapBuffers(window.Reg); + window.BlitDoneEvent?.Set(); } private unsafe void BlitThreadInit(WindowData reg) From 97b5e7f4610d44083215f55d52359942f3363206 Mon Sep 17 00:00:00 2001 From: Eoin Mcloughlin Date: Wed, 16 Oct 2024 18:39:04 +0100 Subject: [PATCH 2/4] Avoid creating opengl 3.3 windows, to avoid Steam overlay bug --- Robust.Client/Graphics/Clyde/GLContext/GLContextWindow.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Robust.Client/Graphics/Clyde/GLContext/GLContextWindow.cs b/Robust.Client/Graphics/Clyde/GLContext/GLContextWindow.cs index cfbfb03f5e4..a05b37dbe6a 100644 --- a/Robust.Client/Graphics/Clyde/GLContext/GLContextWindow.cs +++ b/Robust.Client/Graphics/Clyde/GLContext/GLContextWindow.cs @@ -43,10 +43,13 @@ public override GLContextSpec[] SpecsToTry return new[] { - GetVersionSpec(RendererOpenGLVersion.GL33), GetVersionSpec(RendererOpenGLVersion.GL31), GetVersionSpec(RendererOpenGLVersion.GLES3), GetVersionSpec(RendererOpenGLVersion.GLES2), + // Preferentially create renderers with versions other than 3.3 + // As activating the Steam Overlay with multiple 3.3 windows + // causes the overlay to get corrupted. + GetVersionSpec(RendererOpenGLVersion.GL33), }; } } From 4be96450902e2949676f6e9cc7f54dccd4ce4d9c Mon Sep 17 00:00:00 2001 From: Eoin Mcloughlin Date: Sat, 19 Oct 2024 11:22:55 +0100 Subject: [PATCH 3/4] Revert "Avoid creating opengl 3.3 windows, to avoid Steam overlay bug" This reverts commit 97b5e7f4610d44083215f55d52359942f3363206. --- Robust.Client/Graphics/Clyde/GLContext/GLContextWindow.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Robust.Client/Graphics/Clyde/GLContext/GLContextWindow.cs b/Robust.Client/Graphics/Clyde/GLContext/GLContextWindow.cs index a05b37dbe6a..cfbfb03f5e4 100644 --- a/Robust.Client/Graphics/Clyde/GLContext/GLContextWindow.cs +++ b/Robust.Client/Graphics/Clyde/GLContext/GLContextWindow.cs @@ -43,13 +43,10 @@ public override GLContextSpec[] SpecsToTry return new[] { + GetVersionSpec(RendererOpenGLVersion.GL33), GetVersionSpec(RendererOpenGLVersion.GL31), GetVersionSpec(RendererOpenGLVersion.GLES3), GetVersionSpec(RendererOpenGLVersion.GLES2), - // Preferentially create renderers with versions other than 3.3 - // As activating the Steam Overlay with multiple 3.3 windows - // causes the overlay to get corrupted. - GetVersionSpec(RendererOpenGLVersion.GL33), }; } } From 9d1b2466f75cfc4df75b5075a66bf54d9445d3a1 Mon Sep 17 00:00:00 2001 From: Eoin Mcloughlin Date: Sat, 19 Oct 2024 11:51:44 +0100 Subject: [PATCH 4/4] Add CVar to perform unlocking test --- .../Graphics/Clyde/GLContext/GLContextWindow.cs | 11 ++++++++++- Robust.Shared/CVars.cs | 8 ++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Robust.Client/Graphics/Clyde/GLContext/GLContextWindow.cs b/Robust.Client/Graphics/Clyde/GLContext/GLContextWindow.cs index cfbfb03f5e4..887b954129f 100644 --- a/Robust.Client/Graphics/Clyde/GLContext/GLContextWindow.cs +++ b/Robust.Client/Graphics/Clyde/GLContext/GLContextWindow.cs @@ -176,6 +176,7 @@ private void BlitSecondaryWindows() window.BlitDoneEvent!.Reset(); window.BlitStartEvent!.Set(); window.BlitDoneEvent.Wait(); + window.UnlockBeforeSwap = Clyde._cfg.GetCVar(CVars.DisplayThreadUnlockBeforeSwap); } } else @@ -212,8 +213,15 @@ private void BlitThreadDoSecondaryWindowBlit(WindowData window) GL.DrawArrays(PrimitiveType.TriangleStrip, 0, 4); Clyde.CheckGlError(); + if (window.UnlockBeforeSwap) + { + window.BlitDoneEvent?.Set(); + } Clyde._windowing!.WindowSwapBuffers(window.Reg); - window.BlitDoneEvent?.Set(); + if (!window.UnlockBeforeSwap) + { + window.BlitDoneEvent?.Set(); + } } private unsafe void BlitThreadInit(WindowData reg) @@ -336,6 +344,7 @@ private sealed class WindowData public Thread? BlitThread; public ManualResetEventSlim? BlitStartEvent; public ManualResetEventSlim? BlitDoneEvent; + public bool UnlockBeforeSwap; } } } diff --git a/Robust.Shared/CVars.cs b/Robust.Shared/CVars.cs index c57b3ea6909..d276d0fea89 100644 --- a/Robust.Shared/CVars.cs +++ b/Robust.Shared/CVars.cs @@ -1105,6 +1105,14 @@ protected CVars() public static readonly CVarDef DisplayThreadWindowBlit = CVarDef.Create("display.thread_window_blit", true, CVar.CLIENTONLY); + /// + /// Diagnostic flag for testing. When using a separate thread for multi-window blitting, + /// should the worker be unblocked before the SwapBuffers(). Setting to true may improve + /// performance but may cause crashes or rendering errors. + /// + public static readonly CVarDef DisplayThreadUnlockBeforeSwap = + CVarDef.Create("display.thread_unlock_before_swap", false, CVar.CLIENTONLY); + /// /// Buffer size of input command channel from windowing thread to main game thread. ///