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

Add a fence pool for frame tracking fences #5921

Merged
merged 4 commits into from
Jul 12, 2023
Merged
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
15 changes: 12 additions & 3 deletions osu.Framework/Graphics/Veldrid/VeldridRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ protected internal override bool AllowTearing
/// </summary>
private readonly List<FrameCompletionFence> pendingFramesFences = new List<FrameCompletionFence>();

/// <summary>
/// We are using fences every frame. Construction can be expensive, so let's pool some.
/// </summary>
private readonly Queue<Fence> perFrameFencePool = new Queue<Fence>();

public VeldridIndexData SharedLinearIndex { get; }
public VeldridIndexData SharedQuadIndex { get; }

Expand Down Expand Up @@ -268,7 +273,9 @@ private void updateLastCompletedFrameIndex()
}

lastSignalledFenceIndex ??= i;
fence.Fence.Dispose();

Device.ResetFence(fence.Fence);
perFrameFencePool.Enqueue(fence.Fence);
}

if (lastSignalledFenceIndex != null)
Expand All @@ -291,8 +298,10 @@ protected internal override void FinishFrame()
BufferUpdateCommands.End();
Device.SubmitCommands(BufferUpdateCommands);

// This is disposed via the end-of-lifetime tracking in pendingFrameFences.
var fence = Factory.CreateFence(false);
// This is returned via the end-of-lifetime tracking in `pendingFrameFences`.
// See `updateLastCompletedFrameIndex`.
if (!perFrameFencePool.TryDequeue(out Fence? fence))
fence = Factory.CreateFence(false);

Commands.End();
Device.SubmitCommands(Commands, fence);
Expand Down