Skip to content

Commit

Permalink
Fixes for rendering in multiple windows (#5497)
Browse files Browse the repository at this point in the history
* 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 97b5e7f.

* Add CVar to perform unlocking test
  • Loading branch information
eoineoineoin authored Oct 19, 2024
1 parent 32bca7c commit 5a82df2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
13 changes: 11 additions & 2 deletions Robust.Client/Graphics/Clyde/GLContext/GLContextWindow.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Channels;
Expand Down Expand Up @@ -176,6 +176,7 @@ private void BlitSecondaryWindows()
window.BlitDoneEvent!.Reset();
window.BlitStartEvent!.Set();
window.BlitDoneEvent.Wait();
window.UnlockBeforeSwap = Clyde._cfg.GetCVar(CVars.DisplayThreadUnlockBeforeSwap);
}
}
else
Expand Down Expand Up @@ -212,8 +213,15 @@ private void BlitThreadDoSecondaryWindowBlit(WindowData window)
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)
Expand Down Expand Up @@ -336,6 +344,7 @@ private sealed class WindowData
public Thread? BlitThread;
public ManualResetEventSlim? BlitStartEvent;
public ManualResetEventSlim? BlitDoneEvent;
public bool UnlockBeforeSwap;
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions Robust.Shared/CVars.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1105,6 +1105,14 @@ protected CVars()
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>
Expand Down

0 comments on commit 5a82df2

Please sign in to comment.