Fixes for rendering in multiple windows (#5497)

* Fix race condition when swapping buffers of secondary windows

* Avoid creating opengl 3.3 windows, to avoid Steam overlay bug

* Revert "Avoid creating opengl 3.3 windows, to avoid Steam overlay bug"

This reverts commit 97b5e7f461.

* Add CVar to perform unlocking test
This commit is contained in:
eoineoineoin
2024-10-19 15:13:29 +01:00
committed by GitHub
parent 32bca7cfd4
commit 5a82df216d
2 changed files with 19 additions and 2 deletions

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Channels;
@@ -176,6 +176,7 @@ namespace Robust.Client.Graphics.Clyde
window.BlitDoneEvent!.Reset();
window.BlitStartEvent!.Set();
window.BlitDoneEvent.Wait();
window.UnlockBeforeSwap = Clyde._cfg.GetCVar(CVars.DisplayThreadUnlockBeforeSwap);
}
}
else
@@ -212,8 +213,15 @@ namespace Robust.Client.Graphics.Clyde
GL.DrawArrays(PrimitiveType.TriangleStrip, 0, 4);
Clyde.CheckGlError();
window.BlitDoneEvent?.Set();
if (window.UnlockBeforeSwap)
{
window.BlitDoneEvent?.Set();
}
Clyde._windowing!.WindowSwapBuffers(window.Reg);
if (!window.UnlockBeforeSwap)
{
window.BlitDoneEvent?.Set();
}
}
private unsafe void BlitThreadInit(WindowData reg)
@@ -336,6 +344,7 @@ namespace Robust.Client.Graphics.Clyde
public Thread? BlitThread;
public ManualResetEventSlim? BlitStartEvent;
public ManualResetEventSlim? BlitDoneEvent;
public bool UnlockBeforeSwap;
}
}
}

View File

@@ -1105,6 +1105,14 @@ namespace Robust.Shared
public static readonly CVarDef<bool> DisplayThreadWindowBlit =
CVarDef.Create("display.thread_window_blit", true, CVar.CLIENTONLY);
/// <summary>
/// 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.
/// </summary>
public static readonly CVarDef<bool> DisplayThreadUnlockBeforeSwap =
CVarDef.Create("display.thread_unlock_before_swap", false, CVar.CLIENTONLY);
/// <summary>
/// Buffer size of input command channel from windowing thread to main game thread.
/// </summary>