Skip to content

Commit

Permalink
Merge pull request #5686 from peppy/move-renderer-info-display
Browse files Browse the repository at this point in the history
Show renderer information above frame statistics display
  • Loading branch information
smoogipoo authored Mar 21, 2023
2 parents 0e97e94 + e80fe86 commit cec00cd
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 19 deletions.
2 changes: 1 addition & 1 deletion osu.Framework/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
38 changes: 23 additions & 15 deletions osu.Framework/Graphics/Performance/PerformanceOverlay.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. 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<FrameStatisticsDisplay>, IStateful<FrameStatisticsMode>
internal partial class PerformanceOverlay : FillFlowContainer, IStateful<FrameStatisticsMode>
{
private readonly GameThread[] threads;
[Resolved]
private GameHost host { get; set; } = null!;

private FrameStatisticsMode state;

public event Action<FrameStatisticsMode> StateChanged;
public event Action<FrameStatisticsMode>? StateChanged;

private bool initialised;

Expand All @@ -36,6 +38,11 @@ public FrameStatisticsMode State
}
}

public PerformanceOverlay()
{
Direction = FillDirection.Vertical;
}

protected override void LoadComplete()
{
base.LoadComplete();
Expand All @@ -58,15 +65,22 @@ 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 });
}

this.FadeIn(100);
break;
}

foreach (FrameStatisticsDisplay d in Children)
foreach (FrameStatisticsDisplay d in Children.OfType<FrameStatisticsDisplay>())
d.State = state;

StateChanged?.Invoke(State);
Expand All @@ -77,16 +91,10 @@ private ArrayPool<Rgba32> 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<Rgba32>.Create(FrameStatisticsDisplay.HEIGHT, bucketSize);
}

public PerformanceOverlay(IEnumerable<GameThread> threads)
{
this.threads = threads.ToArray();
Direction = FillDirection.Vertical;
}
}

public enum FrameStatisticsMode
Expand Down
6 changes: 5 additions & 1 deletion osu.Framework/Platform/GameHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public abstract class GameHost : IIpcHost, IDisposable

public IRenderer Renderer { get; private set; }

public string RendererInfo { get; private set; }

/// <summary>
/// Whether "unlimited" frame limiter should be allowed to exceed sane limits.
/// Only use this for benchmarking purposes (see <see cref="maximum_sane_fps"/> for further reasoning).
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions osu.Framework/Threading/DrawThread.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit cec00cd

Please sign in to comment.