Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for rendering in multiple windows #5497

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading