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

Freeing buffers on Metal can be slower than expected #5885

Open
AkiSakurai opened this issue Jul 3, 2023 · 1 comment
Open

Freeing buffers on Metal can be slower than expected #5885

AkiSakurai opened this issue Jul 3, 2023 · 1 comment

Comments

@AkiSakurai
Copy link
Contributor

This issue is not observed when using the OpenGL renderer. I have not tested it on other operating systems.

2023-07-03 13:44:04 [verbose]: Duration:133ms Freed Vertex Buffers: 4496
2023-07-03 13:44:09 [verbose]: Duration:30ms Freed Vertex Buffers: 1116

The versions of osu! and osu!framework used were from the GitHub repositories located at https://github.com/ppy/osu/tree/1f3d833b058e90dbfdb901f61149b1fc0135542f and 19cbb8f, respectively.

These modifications were used to generate the log.

diff --git a/osu.Framework/Graphics/Rendering/Renderer.cs b/osu.Framework/Graphics/Rendering/Renderer.cs
index 360bf9d3a..08bba7468 100644
--- a/osu.Framework/Graphics/Rendering/Renderer.cs
+++ b/osu.Framework/Graphics/Rendering/Renderer.cs
@@ -18,6 +18,7 @@
 using osu.Framework.Graphics.Textures;
 using osu.Framework.IO.Stores;
 using osu.Framework.Lists;
+using osu.Framework.Logging;
 using osu.Framework.Platform;
 using osu.Framework.Statistics;
 using osu.Framework.Threading;
@@ -820,11 +821,17 @@ private void freeUnusedVertexBuffers()
             if (ResetId % vbo_free_check_interval != 0)
                 return;
 
+            var start = System.Diagnostics.Stopwatch.GetTimestamp();
+            var freedVertexBuffers = 0;
             foreach (var buf in vertexBuffersInUse)
             {
-                if (buf.InUse && ResetId - buf.LastUseResetId > vbo_free_check_interval)
+                if (buf.InUse && ResetId - buf.LastUseResetId > vbo_free_check_interval){
                     buf.Free();
+                    freedVertexBuffers ++;
+                }
             }
+            var duration = System.Diagnostics.Stopwatch.GetTimestamp() - start;
+            Logger.Log($"Duration:{duration/1000/1000}ms Freed Vertex Buffers: {freedVertexBuffers}");
 
             vertexBuffersInUse.RemoveAll(b => !b.InUse);
         }
@peppy
Copy link
Sponsor Member

peppy commented Jul 3, 2023

We are very aware of metal performance issues across the board and are actively working on improving the situation. Freeing buffers is just one of many pain points.

The issue is going to lie within veldrid, FWIW.

@peppy peppy changed the title Lag spikes caused by a large number of vertex buffers being freed at once with metal renderer. Freeing buffers on metal can be slower than expected Jul 3, 2023
@frenzibyte frenzibyte changed the title Freeing buffers on metal can be slower than expected Freeing buffers on Metal can be slower than expected Jul 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants