Compare commits

...

3 Commits

Author SHA1 Message Date
Marco Carvalho
8edfb2bc7b "static readonly" constants should be "const" instead (#5560)
* "static readonly" constants should be "const" instead

* change fields to PascalCase
2023-08-13 19:07:57 -03:00
MutantAura
ddefb4fff4 Remove animations on listbox items (#5563) 2023-08-13 22:40:40 +02:00
MutantAura
2efd74b9cb Ava UI: Make some settings methods async (#5332)
* Ava: Asynchronously load Vulkan device settings items.

* Sound checks, timezones and network interface async

* Refresh UI items once awaited tasks complete

* Remove unused dep

* Timezone UI update

* Use UIThread dispatcher for thread-unsafe collections + simplify GPU collection.

* Remove empty lines

* Remove unused string

* Dispatch property changes

* format changes

* format 2

* Use Tasks instead of async void

* Make NetworkInterfaceIndex access thread safe.
2023-08-12 22:43:03 +02:00
8 changed files with 69 additions and 65 deletions

View File

@@ -32,7 +32,7 @@ namespace ARMeilleure.Instructions
15L << 56 | 14L << 48 | 13L << 40 | 12L << 32 | 07L << 24 | 06L << 16 | 05L << 8 | 04L << 0, // S 15L << 56 | 14L << 48 | 13L << 40 | 12L << 32 | 07L << 24 | 06L << 16 | 05L << 8 | 04L << 0, // S
}; };
public static readonly long ZeroMask = 128L << 56 | 128L << 48 | 128L << 40 | 128L << 32 | 128L << 24 | 128L << 16 | 128L << 8 | 128L << 0; public const long ZeroMask = 128L << 56 | 128L << 48 | 128L << 40 | 128L << 32 | 128L << 24 | 128L << 16 | 128L << 8 | 128L << 0;
public static ulong X86GetGf2p8LogicalShiftLeft(int shift) public static ulong X86GetGf2p8LogicalShiftLeft(int shift)
{ {

View File

@@ -335,28 +335,6 @@
Value="{DynamicResource AppListBackgroundColor}" /> Value="{DynamicResource AppListBackgroundColor}" />
<Setter Property="BorderThickness" <Setter Property="BorderThickness"
Value="2"/> Value="2"/>
<Style.Animations>
<Animation Duration="0:0:0.7">
<KeyFrame Cue="0%">
<Setter Property="MaxHeight"
Value="0" />
<Setter Property="Opacity"
Value="0.0" />
</KeyFrame>
<KeyFrame Cue="50%">
<Setter Property="MaxHeight"
Value="1000" />
<Setter Property="Opacity"
Value="0.3" />
</KeyFrame>
<KeyFrame Cue="100%">
<Setter Property="MaxHeight"
Value="1000" />
<Setter Property="Opacity"
Value="1.0" />
</KeyFrame>
</Animation>
</Style.Animations>
</Style> </Style>
<Style Selector="ListBox ListBoxItem:selected /template/ ContentPresenter"> <Style Selector="ListBox ListBoxItem:selected /template/ ContentPresenter">
<Setter Property="Background" <Setter Property="Background"

View File

@@ -37,7 +37,7 @@ namespace Ryujinx.Modules
private static readonly string _homeDir = AppDomain.CurrentDomain.BaseDirectory; private static readonly string _homeDir = AppDomain.CurrentDomain.BaseDirectory;
private static readonly string _updateDir = Path.Combine(Path.GetTempPath(), "Ryujinx", "update"); private static readonly string _updateDir = Path.Combine(Path.GetTempPath(), "Ryujinx", "update");
private static readonly string _updatePublishDir = Path.Combine(_updateDir, "publish"); private static readonly string _updatePublishDir = Path.Combine(_updateDir, "publish");
private static readonly int _connectionCount = 4; private const int ConnectionCount = 4;
private static string _buildVer; private static string _buildVer;
private static string _platformExt; private static string _platformExt;
@@ -344,22 +344,22 @@ namespace Ryujinx.Modules
private static void DoUpdateWithMultipleThreads(TaskDialog taskDialog, string downloadUrl, string updateFile) private static void DoUpdateWithMultipleThreads(TaskDialog taskDialog, string downloadUrl, string updateFile)
{ {
// Multi-Threaded Updater // Multi-Threaded Updater
long chunkSize = _buildSize / _connectionCount; long chunkSize = _buildSize / ConnectionCount;
long remainderChunk = _buildSize % _connectionCount; long remainderChunk = _buildSize % ConnectionCount;
int completedRequests = 0; int completedRequests = 0;
int totalProgressPercentage = 0; int totalProgressPercentage = 0;
int[] progressPercentage = new int[_connectionCount]; int[] progressPercentage = new int[ConnectionCount];
List<byte[]> list = new(_connectionCount); List<byte[]> list = new(ConnectionCount);
List<WebClient> webClients = new(_connectionCount); List<WebClient> webClients = new(ConnectionCount);
for (int i = 0; i < _connectionCount; i++) for (int i = 0; i < ConnectionCount; i++)
{ {
list.Add(Array.Empty<byte>()); list.Add(Array.Empty<byte>());
} }
for (int i = 0; i < _connectionCount; i++) for (int i = 0; i < ConnectionCount; i++)
{ {
#pragma warning disable SYSLIB0014 #pragma warning disable SYSLIB0014
// TODO: WebClient is obsolete and need to be replaced with a more complex logic using HttpClient. // TODO: WebClient is obsolete and need to be replaced with a more complex logic using HttpClient.
@@ -368,7 +368,7 @@ namespace Ryujinx.Modules
webClients.Add(client); webClients.Add(client);
if (i == _connectionCount - 1) if (i == ConnectionCount - 1)
{ {
client.Headers.Add("Range", $"bytes={chunkSize * i}-{(chunkSize * (i + 1) - 1) + remainderChunk}"); client.Headers.Add("Range", $"bytes={chunkSize * i}-{(chunkSize * (i + 1) - 1) + remainderChunk}");
} }
@@ -385,7 +385,7 @@ namespace Ryujinx.Modules
Interlocked.Exchange(ref progressPercentage[index], args.ProgressPercentage); Interlocked.Exchange(ref progressPercentage[index], args.ProgressPercentage);
Interlocked.Add(ref totalProgressPercentage, args.ProgressPercentage); Interlocked.Add(ref totalProgressPercentage, args.ProgressPercentage);
taskDialog.SetProgressBarState(totalProgressPercentage / _connectionCount, TaskDialogProgressState.Normal); taskDialog.SetProgressBarState(totalProgressPercentage / ConnectionCount, TaskDialogProgressState.Normal);
}; };
client.DownloadDataCompleted += (_, args) => client.DownloadDataCompleted += (_, args) =>
@@ -404,10 +404,10 @@ namespace Ryujinx.Modules
list[index] = args.Result; list[index] = args.Result;
Interlocked.Increment(ref completedRequests); Interlocked.Increment(ref completedRequests);
if (Equals(completedRequests, _connectionCount)) if (Equals(completedRequests, ConnectionCount))
{ {
byte[] mergedFileBytes = new byte[_buildSize]; byte[] mergedFileBytes = new byte[_buildSize];
for (int connectionIndex = 0, destinationOffset = 0; connectionIndex < _connectionCount; connectionIndex++) for (int connectionIndex = 0, destinationOffset = 0; connectionIndex < ConnectionCount; connectionIndex++)
{ {
Array.Copy(list[connectionIndex], 0, mergedFileBytes, destinationOffset, list[connectionIndex].Length); Array.Copy(list[connectionIndex], 0, mergedFileBytes, destinationOffset, list[connectionIndex].Length);
destinationOffset += list[connectionIndex].Length; destinationOffset += list[connectionIndex].Length;

View File

@@ -1,7 +1,6 @@
using Avalonia.Collections; using Avalonia.Collections;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Threading; using Avalonia.Threading;
using DynamicData;
using LibHac.Tools.FsSystem; using LibHac.Tools.FsSystem;
using Ryujinx.Audio.Backends.OpenAL; using Ryujinx.Audio.Backends.OpenAL;
using Ryujinx.Audio.Backends.SDL2; using Ryujinx.Audio.Backends.SDL2;
@@ -24,6 +23,7 @@ using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using System.Net.NetworkInformation; using System.Net.NetworkInformation;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Threading.Tasks;
using TimeZone = Ryujinx.Ava.UI.Models.TimeZone; using TimeZone = Ryujinx.Ava.UI.Models.TimeZone;
namespace Ryujinx.Ava.UI.ViewModels namespace Ryujinx.Ava.UI.ViewModels
@@ -44,7 +44,7 @@ namespace Ryujinx.Ava.UI.ViewModels
private float _volume; private float _volume;
private bool _isVulkanAvailable = true; private bool _isVulkanAvailable = true;
private bool _directoryChanged; private bool _directoryChanged;
private List<string> _gpuIds = new(); private readonly List<string> _gpuIds = new();
private KeyboardHotkeys _keyboardHotkeys; private KeyboardHotkeys _keyboardHotkeys;
private int _graphicsBackendIndex; private int _graphicsBackendIndex;
private string _customThemePath; private string _customThemePath;
@@ -278,7 +278,7 @@ namespace Ryujinx.Ava.UI.ViewModels
_contentManager = contentManager; _contentManager = contentManager;
if (Program.PreviewerDetached) if (Program.PreviewerDetached)
{ {
LoadTimeZones(); Task.Run(LoadTimeZones);
} }
} }
@@ -290,27 +290,34 @@ namespace Ryujinx.Ava.UI.ViewModels
_validTzRegions = new List<string>(); _validTzRegions = new List<string>();
_networkInterfaces = new Dictionary<string, string>(); _networkInterfaces = new Dictionary<string, string>();
CheckSoundBackends(); Task.Run(CheckSoundBackends);
PopulateNetworkInterfaces(); Task.Run(PopulateNetworkInterfaces);
if (Program.PreviewerDetached) if (Program.PreviewerDetached)
{ {
LoadAvailableGpus(); Task.Run(LoadAvailableGpus);
LoadCurrentConfiguration(); LoadCurrentConfiguration();
} }
} }
public void CheckSoundBackends() public async Task CheckSoundBackends()
{ {
IsOpenAlEnabled = OpenALHardwareDeviceDriver.IsSupported; IsOpenAlEnabled = OpenALHardwareDeviceDriver.IsSupported;
IsSoundIoEnabled = SoundIoHardwareDeviceDriver.IsSupported; IsSoundIoEnabled = SoundIoHardwareDeviceDriver.IsSupported;
IsSDL2Enabled = SDL2HardwareDeviceDriver.IsSupported; IsSDL2Enabled = SDL2HardwareDeviceDriver.IsSupported;
await Dispatcher.UIThread.InvokeAsync(() =>
{
OnPropertyChanged(nameof(IsOpenAlEnabled));
OnPropertyChanged(nameof(IsSoundIoEnabled));
OnPropertyChanged(nameof(IsSDL2Enabled));
});
} }
private void LoadAvailableGpus() private async Task LoadAvailableGpus()
{ {
_gpuIds = new List<string>(); AvailableGpus.Clear();
List<string> names = new();
var devices = VulkanRenderer.GetPhysicalDevices(); var devices = VulkanRenderer.GetPhysicalDevices();
if (devices.Length == 0) if (devices.Length == 0)
@@ -321,17 +328,24 @@ namespace Ryujinx.Ava.UI.ViewModels
else else
{ {
foreach (var device in devices) foreach (var device in devices)
{
await Dispatcher.UIThread.InvokeAsync(() =>
{ {
_gpuIds.Add(device.Id); _gpuIds.Add(device.Id);
names.Add($"{device.Name} {(device.IsDiscrete ? "(dGPU)" : "")}");
AvailableGpus.Add(new ComboBoxItem { Content = $"{device.Name} {(device.IsDiscrete ? "(dGPU)" : "")}" });
});
} }
} }
AvailableGpus.Clear(); // GPU configuration needs to be loaded during the async method or it will always return 0.
AvailableGpus.AddRange(names.Select(x => new ComboBoxItem { Content = x })); PreferredGpuIndex = _gpuIds.Contains(ConfigurationState.Instance.Graphics.PreferredGpu) ?
_gpuIds.IndexOf(ConfigurationState.Instance.Graphics.PreferredGpu) : 0;
Dispatcher.UIThread.Post(() => OnPropertyChanged(nameof(PreferredGpuIndex)));
} }
public void LoadTimeZones() public async Task LoadTimeZones()
{ {
_timeZoneContentManager = new TimeZoneContentManager(); _timeZoneContentManager = new TimeZoneContentManager();
@@ -344,21 +358,34 @@ namespace Ryujinx.Ava.UI.ViewModels
string abbr2 = abbr.StartsWith('+') || abbr.StartsWith('-') ? string.Empty : abbr; string abbr2 = abbr.StartsWith('+') || abbr.StartsWith('-') ? string.Empty : abbr;
await Dispatcher.UIThread.InvokeAsync(() =>
{
TimeZones.Add(new TimeZone($"UTC{hours:+0#;-0#;+00}:{minutes:D2}", location, abbr2)); TimeZones.Add(new TimeZone($"UTC{hours:+0#;-0#;+00}:{minutes:D2}", location, abbr2));
_validTzRegions.Add(location); _validTzRegions.Add(location);
} });
} }
private void PopulateNetworkInterfaces() Dispatcher.UIThread.Post(() => OnPropertyChanged(nameof(TimeZone)));
}
private async Task PopulateNetworkInterfaces()
{ {
_networkInterfaces.Clear(); _networkInterfaces.Clear();
_networkInterfaces.Add(LocaleManager.Instance[LocaleKeys.NetworkInterfaceDefault], "0"); _networkInterfaces.Add(LocaleManager.Instance[LocaleKeys.NetworkInterfaceDefault], "0");
foreach (NetworkInterface networkInterface in NetworkInterface.GetAllNetworkInterfaces()) foreach (NetworkInterface networkInterface in NetworkInterface.GetAllNetworkInterfaces())
{
await Dispatcher.UIThread.InvokeAsync(() =>
{ {
_networkInterfaces.Add(networkInterface.Name, networkInterface.Id); _networkInterfaces.Add(networkInterface.Name, networkInterface.Id);
});
} }
// Network interface index needs to be loaded during the async method or it will always return 0.
NetworkInterfaceIndex = _networkInterfaces.Values.ToList().IndexOf(ConfigurationState.Instance.Multiplayer.LanInterfaceId.Value);
Dispatcher.UIThread.Post(() => OnPropertyChanged(nameof(NetworkInterfaceIndex)));
} }
public void ValidateAndSetTimeZone(string location) public void ValidateAndSetTimeZone(string location)
@@ -416,7 +443,7 @@ namespace Ryujinx.Ava.UI.ViewModels
// Graphics // Graphics
GraphicsBackendIndex = (int)config.Graphics.GraphicsBackend.Value; GraphicsBackendIndex = (int)config.Graphics.GraphicsBackend.Value;
PreferredGpuIndex = _gpuIds.Contains(config.Graphics.PreferredGpu) ? _gpuIds.IndexOf(config.Graphics.PreferredGpu) : 0; // Physical devices are queried asynchronously hence the prefered index config value is loaded in LoadAvailableGpus().
EnableShaderCache = config.Graphics.EnableShaderCache; EnableShaderCache = config.Graphics.EnableShaderCache;
EnableTextureRecompression = config.Graphics.EnableTextureRecompression; EnableTextureRecompression = config.Graphics.EnableTextureRecompression;
EnableMacroHLE = config.Graphics.EnableMacroHLE; EnableMacroHLE = config.Graphics.EnableMacroHLE;
@@ -437,6 +464,7 @@ namespace Ryujinx.Ava.UI.ViewModels
// Network // Network
EnableInternetAccess = config.System.EnableInternetAccess; EnableInternetAccess = config.System.EnableInternetAccess;
// LAN interface index is loaded asynchronously in PopulateNetworkInterfaces()
// Logging // Logging
EnableFileLog = config.Logger.EnableFileLog; EnableFileLog = config.Logger.EnableFileLog;
@@ -450,8 +478,6 @@ namespace Ryujinx.Ava.UI.ViewModels
EnableFsAccessLog = config.Logger.EnableFsAccessLog; EnableFsAccessLog = config.Logger.EnableFsAccessLog;
FsGlobalAccessLogMode = config.System.FsGlobalAccessLogMode; FsGlobalAccessLogMode = config.System.FsGlobalAccessLogMode;
OpenglDebugLevel = (int)config.Logger.GraphicsDebugLevel.Value; OpenglDebugLevel = (int)config.Logger.GraphicsDebugLevel.Value;
NetworkInterfaceIndex = _networkInterfaces.Values.ToList().IndexOf(config.Multiplayer.LanInterfaceId.Value);
} }
public void SaveSettings() public void SaveSettings()

View File

@@ -28,8 +28,8 @@ namespace Ryujinx.Common.SystemInterop
[LibraryImport(X11LibraryName)] [LibraryImport(X11LibraryName)]
private static partial int XCloseDisplay(IntPtr display); private static partial int XCloseDisplay(IntPtr display);
private static readonly double _standardDpiScale = 96.0; private const double StandardDpiScale = 96.0;
private static readonly double _maxScaleFactor = 1.25; private const double MaxScaleFactor = 1.25;
/// <summary> /// <summary>
/// Marks the application as DPI-Aware when running on the Windows operating system. /// Marks the application as DPI-Aware when running on the Windows operating system.
@@ -90,7 +90,7 @@ namespace Ryujinx.Common.SystemInterop
{ {
double userDpiScale = GetActualScaleFactor(); double userDpiScale = GetActualScaleFactor();
return Math.Min(userDpiScale / _standardDpiScale, _maxScaleFactor); return Math.Min(userDpiScale / StandardDpiScale, MaxScaleFactor);
} }
} }
} }

View File

@@ -8,7 +8,7 @@ namespace Ryujinx.Graphics.Vulkan
/// </summary> /// </summary>
class MultiFenceHolder class MultiFenceHolder
{ {
private static readonly int _bufferUsageTrackingGranularity = 4096; private const int BufferUsageTrackingGranularity = 4096;
private readonly FenceHolder[] _fences; private readonly FenceHolder[] _fences;
private readonly BufferUsageBitmap _bufferUsageBitmap; private readonly BufferUsageBitmap _bufferUsageBitmap;
@@ -28,7 +28,7 @@ namespace Ryujinx.Graphics.Vulkan
public MultiFenceHolder(int size) public MultiFenceHolder(int size)
{ {
_fences = new FenceHolder[CommandBufferPool.MaxCommandBuffers]; _fences = new FenceHolder[CommandBufferPool.MaxCommandBuffers];
_bufferUsageBitmap = new BufferUsageBitmap(size, _bufferUsageTrackingGranularity); _bufferUsageBitmap = new BufferUsageBitmap(size, BufferUsageTrackingGranularity);
} }
/// <summary> /// <summary>

View File

@@ -8,7 +8,7 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler
{ {
class Demangler class Demangler
{ {
private static readonly string _base36 = "0123456789abcdefghijklmnopqrstuvwxyz"; private const string Base36 = "0123456789abcdefghijklmnopqrstuvwxyz";
private readonly List<BaseNode> _substitutionList = new(); private readonly List<BaseNode> _substitutionList = new();
private List<BaseNode> _templateParamList = new(); private List<BaseNode> _templateParamList = new();
@@ -87,7 +87,7 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler
for (int i = 0; i < reversedEncoded.Length; i++) for (int i = 0; i < reversedEncoded.Length; i++)
{ {
int value = _base36.IndexOf(reversedEncoded[i]); int value = Base36.IndexOf(reversedEncoded[i]);
if (value == -1) if (value == -1)
{ {
return -1; return -1;

View File

@@ -20,7 +20,7 @@
"sdk", "sdk",
}; };
public static readonly string MainNpdmPath = "/main.npdm"; public const string MainNpdmPath = "/main.npdm";
public const int NroAsetMagic = ('A' << 0) | ('S' << 8) | ('E' << 16) | ('T' << 24); public const int NroAsetMagic = ('A' << 0) | ('S' << 8) | ('E' << 16) | ('T' << 24);