From 9f84e626c0b50988acdc30f550d9e8ee1b86b495 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Sun, 19 Mar 2023 13:43:07 +0900 Subject: [PATCH 1/3] Move renderer information out of draw thread `Name` --- osu.Framework/Platform/GameHost.cs | 6 +++++- osu.Framework/Threading/DrawThread.cs | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/osu.Framework/Platform/GameHost.cs b/osu.Framework/Platform/GameHost.cs index 3065c416e1..fc2d950e96 100644 --- a/osu.Framework/Platform/GameHost.cs +++ b/osu.Framework/Platform/GameHost.cs @@ -59,6 +59,8 @@ public abstract class GameHost : IIpcHost, IDisposable public IRenderer Renderer { get; private set; } + public string RendererInfo { get; private set; } + /// /// Whether "unlimited" frame limiter should be allowed to exceed sane limits. /// Only use this for benchmarking purposes (see for further reasoning). @@ -722,7 +724,9 @@ public void Run(Game game) // Prepare renderer (requires config). Dependencies.CacheAs(Renderer); - RegisterThread(DrawThread = new DrawThread(DrawFrame, this, $"{Renderer.GetType().ReadableName().Replace("Renderer", "")} / {(Window?.GraphicsSurface.Type.ToString() ?? "headless")}") + RendererInfo = $"{Renderer.GetType().ReadableName().Replace("Renderer", "")} / {(Window?.GraphicsSurface.Type.ToString() ?? "headless")}"; + + RegisterThread(DrawThread = new DrawThread(DrawFrame, this) { ActiveHz = MaximumDrawHz, InactiveHz = MaximumInactiveHz, diff --git a/osu.Framework/Threading/DrawThread.cs b/osu.Framework/Threading/DrawThread.cs index 4c85cdf269..dc701906a0 100644 --- a/osu.Framework/Threading/DrawThread.cs +++ b/osu.Framework/Threading/DrawThread.cs @@ -14,8 +14,8 @@ public class DrawThread : GameThread { private readonly GameHost host; - public DrawThread(Action onNewFrame, GameHost host, string? rendererInfo = "unknown") - : base(onNewFrame, $"Draw ({rendererInfo})") + public DrawThread(Action onNewFrame, GameHost host) + : base(onNewFrame, "Draw") { this.host = host; } From 2471bd6392df0c58ebe2e0422ce833f390ec5ce0 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Sun, 19 Mar 2023 13:56:47 +0900 Subject: [PATCH 2/3] Show renderer info above frame statistics displays instead of inline --- osu.Framework/Game.cs | 2 +- .../Performance/PerformanceOverlay.cs | 37 ++++++++++++------- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/osu.Framework/Game.cs b/osu.Framework/Game.cs index 6974f0dfff..1c276a866b 100644 --- a/osu.Framework/Game.cs +++ b/osu.Framework/Game.cs @@ -246,7 +246,7 @@ protected override void LoadComplete() PerformanceOverlay performanceOverlay; - LoadComponentAsync(performanceOverlay = new PerformanceOverlay(Host.Threads) + LoadComponentAsync(performanceOverlay = new PerformanceOverlay { Margin = new MarginPadding(5), Direction = FillDirection.Vertical, diff --git a/osu.Framework/Graphics/Performance/PerformanceOverlay.cs b/osu.Framework/Graphics/Performance/PerformanceOverlay.cs index f0194462db..db778da16a 100644 --- a/osu.Framework/Graphics/Performance/PerformanceOverlay.cs +++ b/osu.Framework/Graphics/Performance/PerformanceOverlay.cs @@ -1,24 +1,27 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System; using System.Buffers; using osu.Framework.Graphics.Containers; using osu.Framework.Threading; using System.Collections.Generic; using System.Linq; +using osu.Framework.Allocation; +using osu.Framework.Graphics.Sprites; +using osu.Framework.Platform; using SixLabors.ImageSharp.PixelFormats; namespace osu.Framework.Graphics.Performance { - internal partial class PerformanceOverlay : FillFlowContainer, IStateful + internal partial class PerformanceOverlay : FillFlowContainer, IStateful { - private readonly GameThread[] threads; + [Resolved] + private GameHost host { get; set; } = null!; + private FrameStatisticsMode state; - public event Action StateChanged; + public event Action? StateChanged; private bool initialised; @@ -36,6 +39,11 @@ public FrameStatisticsMode State } } + public PerformanceOverlay() + { + Direction = FillDirection.Vertical; + } + protected override void LoadComplete() { base.LoadComplete(); @@ -58,7 +66,14 @@ private void updateState() var uploadPool = createUploadPool(); - foreach (GameThread t in threads) + Add(new SpriteText + { + Text = $"Renderer: {host.RendererInfo}", + Alpha = 0.75f, + Origin = Anchor.TopRight, + }); + + foreach (GameThread t in host.Threads) Add(new FrameStatisticsDisplay(t, uploadPool) { State = state }); } @@ -66,7 +81,7 @@ private void updateState() break; } - foreach (FrameStatisticsDisplay d in Children) + foreach (FrameStatisticsDisplay d in Children.OfType()) d.State = state; StateChanged?.Invoke(State); @@ -77,16 +92,10 @@ private ArrayPool createUploadPool() // bucket size should be enough to allow some overhead when running multi-threaded with draw at 60hz. const int max_expected_thread_update_rate = 2000; - int bucketSize = threads.Length * (max_expected_thread_update_rate / 60); + int bucketSize = host.Threads.Count() * (max_expected_thread_update_rate / 60); return ArrayPool.Create(FrameStatisticsDisplay.HEIGHT, bucketSize); } - - public PerformanceOverlay(IEnumerable threads) - { - this.threads = threads.ToArray(); - Direction = FillDirection.Vertical; - } } public enum FrameStatisticsMode From 939e65ceb47262b09e0253a46c761347260d7a43 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Sun, 19 Mar 2023 17:08:48 +0900 Subject: [PATCH 3/3] Remove unused using statement --- osu.Framework/Graphics/Performance/PerformanceOverlay.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/osu.Framework/Graphics/Performance/PerformanceOverlay.cs b/osu.Framework/Graphics/Performance/PerformanceOverlay.cs index db778da16a..488a0ed82c 100644 --- a/osu.Framework/Graphics/Performance/PerformanceOverlay.cs +++ b/osu.Framework/Graphics/Performance/PerformanceOverlay.cs @@ -5,7 +5,6 @@ using System.Buffers; using osu.Framework.Graphics.Containers; using osu.Framework.Threading; -using System.Collections.Generic; using System.Linq; using osu.Framework.Allocation; using osu.Framework.Graphics.Sprites;