Compare commits

...

9 Commits

Author SHA1 Message Date
WilliamWsyHK
e486b902b1 Skip processing application for LDN if it does not have control holder (#460) [ci-skip] 2024-12-30 01:53:06 -06:00
Evan Husted
0ab5b41c4b misc: Move dirty hack related stuff into a separate viewmodel, only show slider when translation delay is enabled. 2024-12-30 01:33:07 -06:00
Otozinclus
d10a478cce Shader translation delay hack (#469)
A workaround to avoid a freeze when translating shaders with the Metal
backend, that would happen after changing version or going from Vulkan
to Metal. 

Adds a delay in milliseconds, configurable in the UI behind the Dirty Hacks mechanism.

---------

Co-authored-by: Evan Husted <greem@greemdev.net>
2024-12-30 01:12:51 -06:00
Evan Husted
ec1020b165 UI: Dirty hacks clarification [ci skip] 2024-12-30 01:10:40 -06:00
Evan Husted
4082ebad1a Fix PR builds 2024-12-30 00:35:43 -06:00
Evan Husted
da8ea06074 misc: Small cleanups 2024-12-30 00:14:55 -06:00
Evan Husted
7f9dccb293 misc: chore: Cleanup DummyHardwareDeviceDriver.cs 2024-12-30 00:09:31 -06:00
Evan Husted
8e4a77aba0 UI: Text in the shader translation slider tooltip 2024-12-30 00:09:19 -06:00
Evan Husted
8fd8a776c9 misc: prevent crashes 2024-12-29 23:39:40 -06:00
12 changed files with 151 additions and 108 deletions

View File

@@ -13,7 +13,7 @@ mkdir -p AppDir/usr/bin
cp distribution/linux/Ryujinx.desktop AppDir/Ryujinx.desktop cp distribution/linux/Ryujinx.desktop AppDir/Ryujinx.desktop
cp distribution/linux/appimage/AppRun AppDir/AppRun cp distribution/linux/appimage/AppRun AppDir/AppRun
cp src/Ryujinx.UI.Common/Resources/Logo_Ryujinx.png AppDir/Ryujinx.svg cp distribution/misc/Logo.svg AppDir/Ryujinx.svg
cp -r "$BUILDDIR"/* AppDir/usr/bin/ cp -r "$BUILDDIR"/* AppDir/usr/bin/

View File

@@ -9,20 +9,12 @@ namespace Ryujinx.Audio.Backends.Dummy
{ {
public class DummyHardwareDeviceDriver : IHardwareDeviceDriver public class DummyHardwareDeviceDriver : IHardwareDeviceDriver
{ {
private readonly ManualResetEvent _updateRequiredEvent; private readonly ManualResetEvent _updateRequiredEvent = new(false);
private readonly ManualResetEvent _pauseEvent; private readonly ManualResetEvent _pauseEvent = new(true);
public static bool IsSupported => true; public static bool IsSupported => true;
public float Volume { get; set; } public float Volume { get; set; } = 1f;
public DummyHardwareDeviceDriver()
{
_updateRequiredEvent = new ManualResetEvent(false);
_pauseEvent = new ManualResetEvent(true);
Volume = 1f;
}
public IHardwareDeviceSession OpenDeviceSession(Direction direction, IVirtualMemoryManager memoryManager, SampleFormat sampleFormat, uint sampleRate, uint channelCount) public IHardwareDeviceSession OpenDeviceSession(Direction direction, IVirtualMemoryManager memoryManager, SampleFormat sampleFormat, uint sampleRate, uint channelCount)
{ {
@@ -60,7 +52,7 @@ namespace Ryujinx.Audio.Backends.Dummy
Dispose(true); Dispose(true);
} }
protected virtual void Dispose(bool disposing) private void Dispose(bool disposing)
{ {
if (disposing) if (disposing)
{ {

View File

@@ -13,13 +13,13 @@ namespace Ryujinx.Common.Configuration
public record EnabledDirtyHack(DirtyHacks Hack, int Value) public record EnabledDirtyHack(DirtyHacks Hack, int Value)
{ {
private static readonly byte[] _packedFormat = [8, 32]; public static readonly byte[] PackedFormat = [8, 32];
public ulong Pack() => BitTricks.PackBitFields([(uint)Hack, (uint)Value], _packedFormat); public ulong Pack() => BitTricks.PackBitFields([(uint)Hack, (uint)Value], PackedFormat);
public static EnabledDirtyHack FromPacked(ulong packedHack) public static EnabledDirtyHack Unpack(ulong packedHack)
{ {
var unpackedFields = BitTricks.UnpackBitFields(packedHack, _packedFormat); var unpackedFields = BitTricks.UnpackBitFields(packedHack, PackedFormat);
if (unpackedFields is not [var hack, var value]) if (unpackedFields is not [var hack, var value])
throw new ArgumentException(nameof(packedHack)); throw new ArgumentException(nameof(packedHack));
@@ -39,12 +39,21 @@ namespace Ryujinx.Common.Configuration
public DirtyHackCollection(ulong[] packedHacks) public DirtyHackCollection(ulong[] packedHacks)
{ {
foreach ((DirtyHacks dirtyHacks, int value) in packedHacks.Select(EnabledDirtyHack.FromPacked)) foreach ((DirtyHacks dirtyHacks, int value) in packedHacks.Select(EnabledDirtyHack.Unpack))
{ {
Add(dirtyHacks, value); Add(dirtyHacks, value);
} }
} }
public ulong[] PackEntries() =>
this
.Select(it =>
BitTricks.PackBitFields([(uint)it.Key, (uint)it.Value], EnabledDirtyHack.PackedFormat))
.ToArray();
public static implicit operator DirtyHackCollection(EnabledDirtyHack[] hacks) => new(hacks);
public static implicit operator DirtyHackCollection(ulong[] packedHacks) => new(packedHacks);
public new int this[DirtyHacks hack] => TryGetValue(hack, out var value) ? value : -1; public new int this[DirtyHacks hack] => TryGetValue(hack, out var value) ? value : -1;
public bool IsEnabled(DirtyHacks hack) => ContainsKey(hack); public bool IsEnabled(DirtyHacks hack) => ContainsKey(hack);

View File

@@ -1,3 +1,4 @@
using Ryujinx.Common.Configuration;
using Ryujinx.Common.Logging; using Ryujinx.Common.Logging;
using Ryujinx.Graphics.GAL; using Ryujinx.Graphics.GAL;
using Ryujinx.Graphics.Shader; using Ryujinx.Graphics.Shader;
@@ -366,6 +367,9 @@ namespace Ryujinx.Graphics.Gpu.Shader.DiskCache
{ {
try try
{ {
if (_context.DirtyHacks.IsEnabled(DirtyHacks.ShaderCompilationThreadSleep))
Thread.Sleep(_context.DirtyHacks[DirtyHacks.ShaderCompilationThreadSleep]);
AsyncProgramTranslation asyncTranslation = new(guestShaders, specState, programIndex, isCompute); AsyncProgramTranslation asyncTranslation = new(guestShaders, specState, programIndex, isCompute);
_asyncTranslationQueue.Add(asyncTranslation, _cancellationToken); _asyncTranslationQueue.Add(asyncTranslation, _cancellationToken);
} }

View File

@@ -0,0 +1,77 @@
using Gommon;
using Ryujinx.Ava.Utilities.Configuration;
namespace Ryujinx.Ava.UI.ViewModels
{
public class SettingsHacksViewModel : BaseModel
{
private readonly SettingsViewModel _baseViewModel;
public SettingsHacksViewModel() {}
public SettingsHacksViewModel(SettingsViewModel settingsVm)
{
_baseViewModel = settingsVm;
}
private bool _xc2MenuSoftlockFix = ConfigurationState.Instance.Hacks.Xc2MenuSoftlockFix;
private bool _shaderTranslationThreadSleep = ConfigurationState.Instance.Hacks.EnableShaderTranslationDelay;
private int _shaderTranslationSleepDelay = ConfigurationState.Instance.Hacks.ShaderTranslationDelay;
public bool Xc2MenuSoftlockFixEnabled
{
get => _xc2MenuSoftlockFix;
set
{
_xc2MenuSoftlockFix = value;
OnPropertyChanged();
}
}
public bool ShaderTranslationDelayEnabled
{
get => _shaderTranslationThreadSleep;
set
{
_shaderTranslationThreadSleep = value;
OnPropertyChanged();
}
}
public string ShaderTranslationDelayTooltipText => $"Current value: {ShaderTranslationDelay}";
public int ShaderTranslationDelay
{
get => _shaderTranslationSleepDelay;
set
{
_shaderTranslationSleepDelay = value;
OnPropertiesChanged(nameof(ShaderTranslationDelay), nameof(ShaderTranslationDelayTooltipText));
}
}
public static string Xc2MenuFixTooltip { get; } = Lambda.String(sb =>
{
sb.AppendLine(
"This fix applies a 2ms delay (via 'Thread.Sleep(2)') every time the game tries to read data from the emulated Switch filesystem.")
.AppendLine();
sb.AppendLine("From the issue on GitHub:").AppendLine();
sb.Append(
"When clicking very fast from game main menu to 2nd submenu, " +
"there is a low chance that the game will softlock, " +
"the submenu won't show up, while background music is still there.");
});
public static string ShaderTranslationDelayTooltip { get; } = Lambda.String(sb =>
{
sb.AppendLine("This hack applies the delay you specify every time shaders are attempted to be translated.")
.AppendLine();
sb.Append("Configurable via slider, only when this option is enabled.");
});
}
}

View File

@@ -65,9 +65,7 @@ namespace Ryujinx.Ava.UI.ViewModels
private string _ldnPassphrase; private string _ldnPassphrase;
private string _ldnServer; private string _ldnServer;
private bool _xc2MenuSoftlockFix = ConfigurationState.Instance.Hacks.Xc2MenuSoftlockFix; public SettingsHacksViewModel DirtyHacks { get; }
private bool _shaderTranslationThreadSleep = ConfigurationState.Instance.Hacks.EnableShaderCompilationThreadSleep;
private int _shaderTranslationSleepDelay = ConfigurationState.Instance.Hacks.ShaderCompilationThreadSleepDelay;
public int ResolutionScale public int ResolutionScale
{ {
@@ -279,39 +277,6 @@ namespace Ryujinx.Ava.UI.ViewModels
} }
} }
public bool Xc2MenuSoftlockFixEnabled
{
get => _xc2MenuSoftlockFix;
set
{
_xc2MenuSoftlockFix = value;
OnPropertyChanged();
}
}
public bool ShaderTranslationDelayEnabled
{
get => _shaderTranslationThreadSleep;
set
{
_shaderTranslationThreadSleep = value;
OnPropertyChanged();
}
}
public int ShaderTranslationDelay
{
get => _shaderTranslationSleepDelay;
set
{
_shaderTranslationSleepDelay = value;
OnPropertyChanged();
}
}
public int Language { get; set; } public int Language { get; set; }
public int Region { get; set; } public int Region { get; set; }
public int FsGlobalAccessLogMode { get; set; } public int FsGlobalAccessLogMode { get; set; }
@@ -424,9 +389,12 @@ namespace Ryujinx.Ava.UI.ViewModels
{ {
_virtualFileSystem = virtualFileSystem; _virtualFileSystem = virtualFileSystem;
_contentManager = contentManager; _contentManager = contentManager;
if (Program.PreviewerDetached) if (Program.PreviewerDetached)
{ {
Task.Run(LoadTimeZones); Task.Run(LoadTimeZones);
DirtyHacks = new SettingsHacksViewModel(this);
} }
} }
@@ -446,6 +414,8 @@ namespace Ryujinx.Ava.UI.ViewModels
{ {
Task.Run(LoadAvailableGpus); Task.Run(LoadAvailableGpus);
LoadCurrentConfiguration(); LoadCurrentConfiguration();
DirtyHacks = new SettingsHacksViewModel(this);
} }
} }
@@ -660,9 +630,9 @@ namespace Ryujinx.Ava.UI.ViewModels
OpenglDebugLevel = (int)config.Logger.GraphicsDebugLevel.Value; OpenglDebugLevel = (int)config.Logger.GraphicsDebugLevel.Value;
MultiplayerModeIndex = (int)config.Multiplayer.Mode.Value; MultiplayerModeIndex = (int)config.Multiplayer.Mode.Value;
DisableP2P = config.Multiplayer.DisableP2p.Value; DisableP2P = config.Multiplayer.DisableP2p;
LdnPassphrase = config.Multiplayer.LdnPassphrase.Value; LdnPassphrase = config.Multiplayer.LdnPassphrase;
LdnServer = config.Multiplayer.LdnServer.Value; LdnServer = config.Multiplayer.LdnServer;
} }
public void SaveSettings() public void SaveSettings()
@@ -786,9 +756,9 @@ namespace Ryujinx.Ava.UI.ViewModels
config.Multiplayer.LdnServer.Value = LdnServer; config.Multiplayer.LdnServer.Value = LdnServer;
// Dirty Hacks // Dirty Hacks
config.Hacks.Xc2MenuSoftlockFix.Value = Xc2MenuSoftlockFixEnabled; config.Hacks.Xc2MenuSoftlockFix.Value = DirtyHacks.Xc2MenuSoftlockFixEnabled;
config.Hacks.EnableShaderCompilationThreadSleep.Value = ShaderTranslationDelayEnabled; config.Hacks.EnableShaderTranslationDelay.Value = DirtyHacks.ShaderTranslationDelayEnabled;
config.Hacks.ShaderCompilationThreadSleepDelay.Value = ShaderTranslationDelay; config.Hacks.ShaderTranslationDelay.Value = DirtyHacks.ShaderTranslationDelay;
config.ToFileFormat().SaveConfig(Program.ConfigurationPath); config.ToFileFormat().SaveConfig(Program.ConfigurationPath);
@@ -822,24 +792,5 @@ namespace Ryujinx.Ava.UI.ViewModels
RevertIfNotSaved(); RevertIfNotSaved();
CloseWindow?.Invoke(); CloseWindow?.Invoke();
} }
public static string Xc2MenuFixTooltip { get; } = Lambda.String(sb =>
{
sb.AppendLine(
"This fix applies a 2ms delay (via 'Thread.Sleep(2)') every time the game tries to read data from the emulated Switch filesystem.")
.AppendLine();
sb.AppendLine("From the issue on GitHub:").AppendLine();
sb.Append(
"When clicking very fast from game main menu to 2nd submenu, " +
"there is a low chance that the game will softlock, " +
"the submenu won't show up, while background music is still there.");
});
public static string ShaderTranslationDelayTooltip { get; } = Lambda.String(sb =>
{
sb.Append(
"This hack applies the delay you specify every time shaders are attempted to be translated.");
});
} }
} }

View File

@@ -29,34 +29,35 @@
<TextBlock <TextBlock
Foreground="{DynamicResource SecondaryTextColor}" Foreground="{DynamicResource SecondaryTextColor}"
TextDecorations="Underline" TextDecorations="Underline"
Text="Game-specific hacks &amp; tricks to alleviate performance issues or crashing. May cause issues." /> Text="Game-specific hacks &amp; tricks to alleviate performance issues or crashing. Will cause issues." />
<StackPanel <StackPanel
Margin="0,10,0,0" Margin="0,10,0,0"
Orientation="Horizontal" Orientation="Horizontal"
HorizontalAlignment="Center" HorizontalAlignment="Center"
ToolTip.Tip="{Binding Xc2MenuFixTooltip}"> ToolTip.Tip="{Binding DirtyHacks.Xc2MenuFixTooltip}">
<CheckBox <CheckBox
Margin="0" Margin="0"
IsChecked="{Binding Xc2MenuSoftlockFixEnabled}"/> IsChecked="{Binding DirtyHacks.Xc2MenuSoftlockFixEnabled}"/>
<TextBlock <TextBlock
VerticalAlignment="Center" VerticalAlignment="Center"
Text="Xenoblade Chronicles 2 Menu Softlock Fix" /> Text="Xenoblade Chronicles 2 Menu Softlock Fix" />
</StackPanel> </StackPanel>
<!--<Separator/> <Separator/>
<StackPanel <StackPanel
Margin="0,10,0,0" Margin="0,10,0,0"
Orientation="Horizontal" Orientation="Horizontal"
HorizontalAlignment="Center" HorizontalAlignment="Center"
ToolTip.Tip="{Binding ShaderTranslationDelayTooltip}"> ToolTip.Tip="{Binding DirtyHacks.ShaderTranslationDelayTooltip}">
<CheckBox <CheckBox
Margin="0" Margin="0"
IsChecked="{Binding ShaderTranslationDelayEnabled}"/> IsChecked="{Binding DirtyHacks.ShaderTranslationDelayEnabled}"/>
<TextBlock VerticalAlignment="Center" <TextBlock VerticalAlignment="Center"
Text="Arbitrary Delay on Shader Translation"/> Text="Arbitrary Delay on Shader Translation"/>
</StackPanel> </StackPanel>
<Slider HorizontalAlignment="Center" <Slider IsVisible="{Binding DirtyHacks.ShaderTranslationDelayEnabled}"
Value="{Binding ShaderTranslationDelay}" HorizontalAlignment="Center"
ToolTip.Tip="{Binding ShaderTranslationDelay}" Value="{Binding DirtyHacks.ShaderTranslationDelay}"
ToolTip.Tip="{Binding DirtyHacks.ShaderTranslationDelayTooltipText}"
Width="175" Width="175"
Margin="0,-3,0,0" Margin="0,-3,0,0"
Height="32" Height="32"
@@ -68,7 +69,7 @@
VerticalAlignment="Center" VerticalAlignment="Center"
Minimum="1" Minimum="1"
Maximum="1000" /> Maximum="1000" />
<Separator/>--> <Separator/>
</StackPanel> </StackPanel>
</Border> </Border>
</ScrollViewer> </ScrollViewer>

View File

@@ -1,13 +1,9 @@
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Interactivity;
using Ryujinx.Ava.UI.ViewModels;
namespace Ryujinx.Ava.UI.Views.Settings namespace Ryujinx.Ava.UI.Views.Settings
{ {
public partial class SettingsHacksView : UserControl public partial class SettingsHacksView : UserControl
{ {
public SettingsViewModel ViewModel;
public SettingsHacksView() public SettingsHacksView()
{ {
InitializeComponent(); InitializeComponent();

View File

@@ -170,7 +170,7 @@ namespace Ryujinx.Ava.UI.Windows
{ {
var ldnGameDataArray = e.LdnData.ToList(); var ldnGameDataArray = e.LdnData.ToList();
ViewModel.LdnData.Clear(); ViewModel.LdnData.Clear();
foreach (var application in ViewModel.Applications) foreach (var application in ViewModel.Applications.Where(it => it.HasControlHolder))
{ {
ref var controlHolder = ref application.ControlHolder.Value; ref var controlHolder = ref application.ControlHolder.Value;

View File

@@ -87,7 +87,7 @@ namespace Ryujinx.Ava.UI.Windows
NavPanel.Content = LoggingPage; NavPanel.Content = LoggingPage;
break; break;
case nameof(HacksPage): case nameof(HacksPage):
HacksPage.ViewModel = ViewModel; HacksPage.DataContext = ViewModel;
NavPanel.Content = HacksPage; NavPanel.Content = HacksPage;
break; break;
default: default:

View File

@@ -752,13 +752,14 @@ namespace Ryujinx.Ava.Utilities.Configuration
Hacks.ShowDirtyHacks.Value = configurationFileFormat.ShowDirtyHacks; Hacks.ShowDirtyHacks.Value = configurationFileFormat.ShowDirtyHacks;
{ {
EnabledDirtyHack[] hacks = configurationFileFormat.DirtyHacks.Select(EnabledDirtyHack.FromPacked).ToArray(); EnabledDirtyHack[] hacks = (configurationFileFormat.DirtyHacks ?? []).Select(EnabledDirtyHack.Unpack).ToArray();
Hacks.Xc2MenuSoftlockFix.Value = hacks.Any(it => it.Hack == DirtyHacks.Xc2MenuSoftlockFix); Hacks.Xc2MenuSoftlockFix.Value = hacks.Any(it => it.Hack == DirtyHacks.Xc2MenuSoftlockFix);
var shaderCompilationThreadSleep = hacks.FirstOrDefault(it => it.Hack == DirtyHacks.ShaderCompilationThreadSleep); var shaderCompilationThreadSleep = hacks.FirstOrDefault(it =>
Hacks.EnableShaderCompilationThreadSleep.Value = shaderCompilationThreadSleep != null; it.Hack == DirtyHacks.ShaderCompilationThreadSleep);
Hacks.ShaderCompilationThreadSleepDelay.Value = shaderCompilationThreadSleep?.Value ?? 0; Hacks.EnableShaderTranslationDelay.Value = shaderCompilationThreadSleep != null;
Hacks.ShaderTranslationDelay.Value = shaderCompilationThreadSleep?.Value ?? 0;
} }
if (configurationFileUpdated) if (configurationFileUpdated)

View File

@@ -10,6 +10,7 @@ using Ryujinx.Common.Logging;
using Ryujinx.HLE; using Ryujinx.HLE;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using RyuLogger = Ryujinx.Common.Logging.Logger;
namespace Ryujinx.Ava.Utilities.Configuration namespace Ryujinx.Ava.Utilities.Configuration
{ {
@@ -628,24 +629,35 @@ namespace Ryujinx.Ava.Utilities.Configuration
public ReactiveObject<bool> Xc2MenuSoftlockFix { get; private set; } public ReactiveObject<bool> Xc2MenuSoftlockFix { get; private set; }
public ReactiveObject<bool> EnableShaderCompilationThreadSleep { get; private set; } public ReactiveObject<bool> EnableShaderTranslationDelay { get; private set; }
public ReactiveObject<int> ShaderCompilationThreadSleepDelay { get; private set; } public ReactiveObject<int> ShaderTranslationDelay { get; private set; }
public HacksSection() public HacksSection()
{ {
ShowDirtyHacks = new ReactiveObject<bool>(); ShowDirtyHacks = new ReactiveObject<bool>();
Xc2MenuSoftlockFix = new ReactiveObject<bool>(); Xc2MenuSoftlockFix = new ReactiveObject<bool>();
Xc2MenuSoftlockFix.Event += HackChanged; Xc2MenuSoftlockFix.Event += HackChanged;
EnableShaderCompilationThreadSleep = new ReactiveObject<bool>(); EnableShaderTranslationDelay = new ReactiveObject<bool>();
EnableShaderCompilationThreadSleep.Event += HackChanged; EnableShaderTranslationDelay.Event += HackChanged;
ShaderCompilationThreadSleepDelay = new ReactiveObject<int>(); ShaderTranslationDelay = new ReactiveObject<int>();
} }
private void HackChanged(object sender, ReactiveEventArgs<bool> rxe) private void HackChanged(object sender, ReactiveEventArgs<bool> rxe)
{ {
Ryujinx.Common.Logging.Logger.Info?.Print(LogClass.Configuration, $"EnabledDirtyHacks set to: [{EnabledHacks.Select(x => x.Hack).JoinToString(", ")}]", "LogValueChange"); var newHacks = EnabledHacks.Select(x => x.Hack)
.JoinToString(", ");
if (newHacks != _lastHackCollection)
{
RyuLogger.Info?.Print(LogClass.Configuration,
$"EnabledDirtyHacks set to: [{newHacks}]", "LogValueChange");
_lastHackCollection = newHacks;
} }
}
private static string _lastHackCollection;
public EnabledDirtyHack[] EnabledHacks public EnabledDirtyHack[] EnabledHacks
{ {
@@ -656,8 +668,8 @@ namespace Ryujinx.Ava.Utilities.Configuration
if (Xc2MenuSoftlockFix) if (Xc2MenuSoftlockFix)
Apply(DirtyHacks.Xc2MenuSoftlockFix); Apply(DirtyHacks.Xc2MenuSoftlockFix);
if (EnableShaderCompilationThreadSleep) if (EnableShaderTranslationDelay)
Apply(DirtyHacks.ShaderCompilationThreadSleep, ShaderCompilationThreadSleepDelay); Apply(DirtyHacks.ShaderCompilationThreadSleep, ShaderTranslationDelay);
return enabledHacks.ToArray(); return enabledHacks.ToArray();