-
Notifications
You must be signed in to change notification settings - Fork 424
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
Conversation
@@ -215,6 +220,9 @@ protected override void Initialise(IGraphicsSurface graphicsSurface) | |||
BufferUpdateCommands = Factory.CreateCommandList(); | |||
|
|||
pipeline.Outputs = Device.SwapchainFramebuffer.OutputDescription; | |||
|
|||
for (int i = 0; i < 16; i++) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this 16 a magic number? What happens in the (unlikely) even that the pool runs dry, crash on Dequeue()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep. On metal I've never seen usages increase above 1. If we exceed 3 then we're probably going to see texture corruption and stuff elsewhere though? I can use 3 instead of 16 if it feels more robust.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or we can change it to add to the pool locally, should also be fine.
diff --git a/osu.Framework/Graphics/Veldrid/VeldridRenderer.cs b/osu.Framework/Graphics/Veldrid/VeldridRenderer.cs
index 341a48ea6..7e0b11a9a 100644
--- a/osu.Framework/Graphics/Veldrid/VeldridRenderer.cs
+++ b/osu.Framework/Graphics/Veldrid/VeldridRenderer.cs
@@ -220,9 +220,6 @@ protected override void Initialise(IGraphicsSurface graphicsSurface)
BufferUpdateCommands = Factory.CreateCommandList();
pipeline.Outputs = Device.SwapchainFramebuffer.OutputDescription;
-
- for (int i = 0; i < 16; i++)
- perFrameFencePool.Enqueue(Factory.CreateFence(false));
}
private Vector2 currentSize;
@@ -296,7 +293,8 @@ protected internal override void FinishFrame()
// This is returned via the end-of-lifetime tracking in `pendingFrameFences`.
// See `updateLastCompletedFrameIndex`.
- Fence fence = perFrameFencePool.Dequeue();
+ if (!perFrameFencePool.TryDequeue(out Fence? fence))
+ fence = Factory.CreateFence(false);
Commands.End();
Device.SubmitCommands(Commands, fence);
I think we still want this in, at least for now. Can potentially be reverted if we decide we don't want end-of-frame fencing on all platforms. |
Ignoring the fact that these tracking fences are doing nothing in D3D (they are set immediately https://github.com/ppy/veldrid/blob/6a43198af1b069e56ac53770249a5424c1859500/src/Veldrid/D3D11/D3D11GraphicsDevice.cs#L229-L232):
This is a regression so let's fix it locally for the time being.
Time spent in
ManualResetEvent
construction:Before this PR:
After this PR: