Skip to content

Commit

Permalink
2 unmerged PRs from original Ryujinx:
Browse files Browse the repository at this point in the history
Implement shader compile counter (currently not translated, will change, need to pull changes.)
Remove event logic in favor of a single init function.
Thanks @MutantAura
  • Loading branch information
GreemDev committed Oct 24, 2024
1 parent 7618ef1 commit a01a06c
Show file tree
Hide file tree
Showing 10 changed files with 101 additions and 36 deletions.
10 changes: 6 additions & 4 deletions src/Ryujinx.Common/ReactiveObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@ public T Value
}
}

public static implicit operator T(ReactiveObject<T> obj)
{
return obj.Value;
}
public static implicit operator T(ReactiveObject<T> obj) => obj.Value;
}

public static class ReactiveObjectHelper
{
public static void Toggle(this ReactiveObject<bool> rBoolean) => rBoolean.Value = !rBoolean.Value;
}

public class ReactiveEventArgs<T>(T oldValue, T newValue)
Expand Down
2 changes: 2 additions & 0 deletions src/Ryujinx.Graphics.GAL/IRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public interface IRenderer : IDisposable
IPipeline Pipeline { get; }

IWindow Window { get; }

uint ProgramCount { get; }

void BackgroundContextAction(Action action, bool alwaysBackground = false);

Expand Down
4 changes: 4 additions & 0 deletions src/Ryujinx.Graphics.GAL/Multithreading/ThreadedRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ public class ThreadedRenderer : IRenderer
private int _refProducerPtr;
private int _refConsumerPtr;

public uint ProgramCount { get; set; } = 0;

private Action _interruptAction;
private readonly object _interruptLock = new();

Expand Down Expand Up @@ -307,6 +309,8 @@ public IProgram CreateProgram(ShaderSource[] shaders, ShaderInfo info)

Programs.Add(request);

ProgramCount++;

New<CreateProgramCommand>().Set(Ref((IProgramRequest)request));
QueueCommand();

Expand Down
4 changes: 4 additions & 0 deletions src/Ryujinx.Graphics.OpenGL/OpenGLRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public sealed class OpenGLRenderer : IRenderer

private readonly Sync _sync;

public uint ProgramCount { get; set; } = 0;

public event EventHandler<ScreenCaptureImageInfo> ScreenCaptured;

internal PersistentBuffers PersistentBuffers { get; }
Expand Down Expand Up @@ -94,6 +96,8 @@ public IImageArray CreateImageArray(int size, bool isBuffer)

public IProgram CreateProgram(ShaderSource[] shaders, ShaderInfo info)
{
ProgramCount++;

return new Program(shaders, info.FragmentOutputMap);
}

Expand Down
4 changes: 4 additions & 0 deletions src/Ryujinx.Graphics.Vulkan/VulkanRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public sealed class VulkanRenderer : IRenderer

private bool _initialized;

public uint ProgramCount { get; set; } = 0;

internal FormatCapabilities FormatCapabilities { get; private set; }
internal HardwareCapabilities Capabilities;

Expand Down Expand Up @@ -544,6 +546,8 @@ public IImageArray CreateImageArray(int size, bool isBuffer)

public IProgram CreateProgram(ShaderSource[] sources, ShaderInfo info)
{
ProgramCount++;

bool isCompute = sources.Length == 1 && sources[0].Stage == ShaderStage.Compute;

if (info.State.HasValue || isCompute)
Expand Down
47 changes: 35 additions & 12 deletions src/Ryujinx/AppHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ private enum CursorStates
private CursorStates _cursorState = !ConfigurationState.Instance.Hid.EnableMouse.Value ?
CursorStates.CursorIsVisible : CursorStates.CursorIsHidden;

private DateTime _lastShaderReset;
private uint _displayCount;
private uint _previousCount = 0;

private bool _isStopped;
private bool _isActive;
private bool _renderingStarted;
Expand All @@ -120,7 +124,6 @@ private enum CursorStates
private readonly object _lockObject = new();

public event EventHandler AppExit;
public event EventHandler<StatusInitEventArgs> StatusInitEvent;
public event EventHandler<StatusUpdatedEventArgs> StatusUpdatedEvent;

public VirtualFileSystem VirtualFileSystem { get; }
Expand Down Expand Up @@ -511,8 +514,7 @@ private void Exit()
}

_isStopped = true;
_isActive = false;
DiscordIntegrationModule.SwitchToMainState();
Stop();
}

public void DisposeContext()
Expand Down Expand Up @@ -1043,21 +1045,23 @@ private void RenderLoop()

public void InitStatus()
{
StatusInitEvent?.Invoke(this, new StatusInitEventArgs(
ConfigurationState.Instance.Graphics.GraphicsBackend.Value switch
{
GraphicsBackend.Vulkan => "Vulkan",
GraphicsBackend.OpenGl => "OpenGL",
_ => throw new NotImplementedException()
},
$"GPU: {_renderer.GetHardwareInfo().GpuDriver}"));
_viewModel.BackendText = ConfigurationState.Instance.Graphics.GraphicsBackend.Value switch
{
GraphicsBackend.Vulkan => "Vulkan",
GraphicsBackend.OpenGl => "OpenGL",
_ => throw new NotImplementedException()
};

_viewModel.GpuNameText = $"GPU: {_renderer.GetHardwareInfo().GpuDriver}";
}

public void UpdateStatus()
{
// Run a status update only when a frame is to be drawn. This prevents from updating the ui and wasting a render when no frame is queued.
string dockedMode = ConfigurationState.Instance.System.EnableDockedMode ? LocaleManager.Instance[LocaleKeys.Docked] : LocaleManager.Instance[LocaleKeys.Handheld];

UpdateShaderCount();

if (GraphicsConfig.ResScale != 1)
{
dockedMode += $" ({GraphicsConfig.ResScale}x)";
Expand All @@ -1069,7 +1073,8 @@ public void UpdateStatus()
dockedMode,
ConfigurationState.Instance.Graphics.AspectRatio.Value.ToText(),
LocaleManager.Instance[LocaleKeys.Game] + $": {Device.Statistics.GetGameFrameRate():00.00} FPS ({Device.Statistics.GetGameFrameTime():00.00} ms)",
$"FIFO: {Device.Statistics.GetFifoPercent():00.00} %"));
$"FIFO: {Device.Statistics.GetFifoPercent():00.00} %",
_displayCount));
}

public async Task ShowExitPrompt()
Expand All @@ -1095,6 +1100,24 @@ public async Task ShowExitPrompt()
}
}

private void UpdateShaderCount()
{
// If there is a mismatch between total program compile and previous count
// this means new shaders have been compiled and should be displayed.
if (_renderer.ProgramCount != _previousCount)
{
_displayCount += _renderer.ProgramCount - _previousCount;
_lastShaderReset = DateTime.Now;
_previousCount = _renderer.ProgramCount;
}
// Check if 5s has passed since any new shaders were compiled.
// If yes, reset the counter.
else if (_lastShaderReset.AddSeconds(5) <= DateTime.Now)
{
_displayCount = 0;
}
}

private bool UpdateFrame()
{
if (!_isActive)
Expand Down
5 changes: 4 additions & 1 deletion src/Ryujinx/UI/Models/StatusUpdatedEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,18 @@ internal class StatusUpdatedEventArgs : EventArgs
public string DockedMode { get; }
public string FifoStatus { get; }
public string GameStatus { get; }

public uint ShaderCount { get; }

public StatusUpdatedEventArgs(bool vSyncEnabled, string volumeStatus, string dockedMode, string aspectRatio, string gameStatus, string fifoStatus)
public StatusUpdatedEventArgs(bool vSyncEnabled, string volumeStatus, string dockedMode, string aspectRatio, string gameStatus, string fifoStatus, uint shaderCount)
{
VSyncEnabled = vSyncEnabled;
VolumeStatus = volumeStatus;
DockedMode = dockedMode;
AspectRatio = aspectRatio;
GameStatus = gameStatus;
FifoStatus = fifoStatus;
ShaderCount = shaderCount;
}
}
}
41 changes: 27 additions & 14 deletions src/Ryujinx/UI/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using DynamicData;
using DynamicData.Binding;
using FluentAvalonia.UI.Controls;
using Gommon;
using LibHac.Common;
using Ryujinx.Ava.Common;
using Ryujinx.Ava.Common.Locale;
Expand Down Expand Up @@ -64,7 +65,9 @@ public class MainWindowViewModel : BaseModel
private string _gameStatusText;
private string _volumeStatusText;
private string _gpuStatusText;
private string _shaderCountText;
private bool _isAmiiboRequested;
private bool _showRightmostSeparator;
private bool _isGameRunning;
private bool _isFullScreen;
private int _progressMaximum;
Expand Down Expand Up @@ -256,6 +259,17 @@ public bool StatusBarVisible

public bool ShowFirmwareStatus => !ShowLoadProgress;

public bool ShowRightmostSeparator
{
get => _showRightmostSeparator;
set
{
_showRightmostSeparator = value;

OnPropertyChanged();
}
}

public bool IsGameRunning
{
get => _isGameRunning;
Expand Down Expand Up @@ -506,6 +520,16 @@ public string GpuNameText
OnPropertyChanged();
}
}

public string ShaderCountText
{
get => _shaderCountText;
set
{
_shaderCountText = value;
OnPropertyChanged();
}
}

public string BackendText
{
Expand Down Expand Up @@ -1187,8 +1211,7 @@ private void PrepareLoadScreen()
private void InitializeGame()
{
RendererHostControl.WindowCreated += RendererHost_Created;

AppHost.StatusInitEvent += Init_StatusBar;

AppHost.StatusUpdatedEvent += Update_StatusBar;
AppHost.AppExit += AppHost_AppExit;

Expand All @@ -1215,18 +1238,6 @@ private async Task HandleRelaunch()
}
}

private void Init_StatusBar(object sender, StatusInitEventArgs args)
{
if (ShowMenuAndStatusBar && !ShowLoadProgress)
{
Dispatcher.UIThread.InvokeAsync(() =>
{
GpuNameText = args.GpuName;
BackendText = args.GpuBackend;
});
}
}

private void Update_StatusBar(object sender, StatusUpdatedEventArgs args)
{
if (ShowMenuAndStatusBar && !ShowLoadProgress)
Expand All @@ -1249,6 +1260,8 @@ private void Update_StatusBar(object sender, StatusUpdatedEventArgs args)
GameStatusText = args.GameStatus;
VolumeStatusText = args.VolumeStatus;
FifoStatusText = args.FifoStatus;
ShaderCountText = args.ShaderCount > 0 ? $"Compiling shaders: {args.ShaderCount}" : string.Empty;
ShowRightmostSeparator = !ShaderCountText.IsNullOrEmpty();

ShowStatusSeparator = true;
});
Expand Down
7 changes: 2 additions & 5 deletions src/Ryujinx/UI/ViewModels/ModManagerViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Avalonia.Platform.Storage;
using Avalonia.Threading;
using DynamicData;
using Gommon;
using Ryujinx.Ava.Common.Locale;
using Ryujinx.Ava.UI.Helpers;
using Ryujinx.Ava.UI.Models;
Expand Down Expand Up @@ -313,11 +314,7 @@ public async void Add()

public void DeleteAll()
{
foreach (var mod in Mods)
{
Delete(mod);
}

Mods.ForEach(Delete);
Mods.Clear();
OnPropertyChanged(nameof(ModCount));
Sort();
Expand Down
13 changes: 13 additions & 0 deletions src/Ryujinx/UI/Views/Main/MainStatusBarView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,19 @@
IsVisible="{Binding !ShowLoadProgress}"
Text="{Binding GpuNameText}"
TextAlignment="Start" />
<Border
Width="2"
Height="12"
Margin="0"
BorderBrush="Gray"
BorderThickness="1"
IsVisible="{Binding ShowRightmostSeparator}" />
<TextBlock
Name="ShaderCount"
Margin="5,0,5,0"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Text="{Binding ShaderCountText}" />
</StackPanel>
<StackPanel
Grid.Column="3"
Expand Down

0 comments on commit a01a06c

Please sign in to comment.