Skip to content

Commit

Permalink
CPU: Add low-power PPTC load mode.
Browse files Browse the repository at this point in the history
Specifically, this setting causes the translation load core count to get reduced by two-thirds, for lower-power but still fast loading, and for unstable CPUs.
  • Loading branch information
GreemDev committed Oct 15, 2024
1 parent 4ee1dff commit 0faf3f5
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 32 deletions.
3 changes: 3 additions & 0 deletions src/ARMeilleure/Optimizations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ namespace ARMeilleure

public static class Optimizations
{
// low-core count PPTC
public static bool EcoFriendly { get; set; } = false;

public static bool FastFP { get; set; } = true;

public static bool AllowLcqInFunctionTable { get; set; } = true;
Expand Down
7 changes: 6 additions & 1 deletion src/ARMeilleure/Translation/PTC/Ptc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -795,10 +795,15 @@ public void MakeAndSaveTranslations(Translator translator)
return;
}



int degreeOfParallelism = Environment.ProcessorCount;

if (Optimizations.EcoFriendly)
degreeOfParallelism /= 3;

// If there are enough cores lying around, we leave one alone for other tasks.
if (degreeOfParallelism > 4)
if (degreeOfParallelism > 4 && !Optimizations.EcoFriendly)
{
degreeOfParallelism--;
}
Expand Down
4 changes: 1 addition & 3 deletions src/Ryujinx.Graphics.Vulkan/MemoryAllocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@ private MemoryAllocation Allocate(int memoryTypeIndex, ulong size, ulong alignme
}
}

internal int FindSuitableMemoryTypeIndex(
uint memoryTypeBits,
MemoryPropertyFlags flags)
internal int FindSuitableMemoryTypeIndex(uint memoryTypeBits, MemoryPropertyFlags flags)
{
for (int i = 0; i < _physicalDevice.PhysicalDeviceMemoryProperties.MemoryTypeCount; i++)
{
Expand Down
31 changes: 14 additions & 17 deletions src/Ryujinx.Headless.SDL2/StatusUpdatedEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,20 @@

namespace Ryujinx.Headless.SDL2
{
class StatusUpdatedEventArgs : EventArgs
class StatusUpdatedEventArgs(
bool vSyncEnabled,
string dockedMode,
string aspectRatio,
string gameStatus,
string fifoStatus,
string gpuName)
: EventArgs
{
public bool VSyncEnabled;
public string DockedMode;
public string AspectRatio;
public string GameStatus;
public string FifoStatus;
public string GpuName;

public StatusUpdatedEventArgs(bool vSyncEnabled, string dockedMode, string aspectRatio, string gameStatus, string fifoStatus, string gpuName)
{
VSyncEnabled = vSyncEnabled;
DockedMode = dockedMode;
AspectRatio = aspectRatio;
GameStatus = gameStatus;
FifoStatus = fifoStatus;
GpuName = gpuName;
}
public bool VSyncEnabled = vSyncEnabled;
public string DockedMode = dockedMode;
public string AspectRatio = aspectRatio;
public string GameStatus = gameStatus;
public string FifoStatus = fifoStatus;
public string GpuName = gpuName;
}
}
11 changes: 2 additions & 9 deletions src/Ryujinx.Input.SDL2/SDL2Keyboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,9 @@ namespace Ryujinx.Input.SDL2
{
class SDL2Keyboard : IKeyboard
{
private class ButtonMappingEntry
private readonly record struct ButtonMappingEntry(GamepadButtonInputId To, Key From)
{
public readonly GamepadButtonInputId To;
public readonly Key From;

public ButtonMappingEntry(GamepadButtonInputId to, Key from)
{
To = to;
From = from;
}
public bool IsValid => To is not GamepadButtonInputId.Unbound && From is not Key.Unbound;
}

private readonly object _userMappingLock = new();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class ConfigurationFileFormat
/// <summary>
/// The current version of the file format
/// </summary>
public const int CurrentVersion = 52;
public const int CurrentVersion = 53;

/// <summary>
/// Version of the configuration file format
Expand Down Expand Up @@ -207,6 +207,11 @@ public class ConfigurationFileFormat
/// </summary>
public bool EnablePtc { get; set; }

/// <summary>
/// Enables or disables low-power profiled translation cache persistency loading
/// </summary>
public bool EnableLowPowerPtc { get; set; }

/// <summary>
/// Enables or disables guest Internet access
/// </summary>
Expand Down
18 changes: 18 additions & 0 deletions src/Ryujinx.UI.Common/Configuration/ConfigurationState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,11 @@ public class SystemSection
/// </summary>
public ReactiveObject<bool> EnablePtc { get; private set; }

/// <summary>
/// Enables or disables low-power profiled translation cache persistency loading
/// </summary>
public ReactiveObject<bool> EnableLowPowerPtc { get; private set; }

/// <summary>
/// Enables or disables guest Internet access
/// </summary>
Expand Down Expand Up @@ -382,6 +387,8 @@ public SystemSection()
EnableDockedMode.Event += static (sender, e) => LogValueChange(e, nameof(EnableDockedMode));
EnablePtc = new ReactiveObject<bool>();
EnablePtc.Event += static (sender, e) => LogValueChange(e, nameof(EnablePtc));
EnableLowPowerPtc = new ReactiveObject<bool>();
EnableLowPowerPtc.Event += static (sender, e) => LogValueChange(e, nameof(EnableLowPowerPtc));
EnableInternetAccess = new ReactiveObject<bool>();
EnableInternetAccess.Event += static (sender, e) => LogValueChange(e, nameof(EnableInternetAccess));
EnableFsIntegrityChecks = new ReactiveObject<bool>();
Expand Down Expand Up @@ -706,6 +713,7 @@ public ConfigurationFileFormat ToFileFormat()
EnableMacroHLE = Graphics.EnableMacroHLE,
EnableColorSpacePassthrough = Graphics.EnableColorSpacePassthrough,
EnablePtc = System.EnablePtc,
EnableLowPowerPtc = System.EnableLowPowerPtc,
EnableInternetAccess = System.EnableInternetAccess,
EnableFsIntegrityChecks = System.EnableFsIntegrityChecks,
FsGlobalAccessLogMode = System.FsGlobalAccessLogMode,
Expand Down Expand Up @@ -1495,6 +1503,15 @@ public void Load(ConfigurationFileFormat configurationFileFormat, string configu
configurationFileUpdated = true;
}

if (configurationFileFormat.Version < 53)
{
Ryujinx.Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 53.");

configurationFileFormat.EnableLowPowerPtc = false;

configurationFileUpdated = true;
}

Logger.EnableFileLog.Value = configurationFileFormat.EnableFileLog;
Graphics.ResScale.Value = configurationFileFormat.ResScale;
Graphics.ResScaleCustom.Value = configurationFileFormat.ResScaleCustom;
Expand Down Expand Up @@ -1534,6 +1551,7 @@ public void Load(ConfigurationFileFormat configurationFileFormat, string configu
Graphics.EnableMacroHLE.Value = configurationFileFormat.EnableMacroHLE;
Graphics.EnableColorSpacePassthrough.Value = configurationFileFormat.EnableColorSpacePassthrough;
System.EnablePtc.Value = configurationFileFormat.EnablePtc;
System.EnableLowPowerPtc.Value = configurationFileFormat.EnableLowPowerPtc;
System.EnableInternetAccess.Value = configurationFileFormat.EnableInternetAccess;
System.EnableFsIntegrityChecks.Value = configurationFileFormat.EnableFsIntegrityChecks;
System.FsGlobalAccessLogMode.Value = configurationFileFormat.FsGlobalAccessLogMode;
Expand Down
2 changes: 2 additions & 0 deletions src/Ryujinx/AppHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,8 @@ private void SaveBitmapAsPng(SKBitmap bitmap, string path)

public void Start()
{
ARMeilleure.Optimizations.EcoFriendly = ConfigurationState.Instance.System.EnableLowPowerPtc;

if (OperatingSystem.IsWindows())
{
_windowsMultimediaTimerResolution = new WindowsMultimediaTimerResolution(1);
Expand Down
3 changes: 3 additions & 0 deletions src/Ryujinx/UI/ViewModels/SettingsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ public bool AutoloadDirectoryChanged
public bool EnableMouse { get; set; }
public bool EnableVsync { get; set; }
public bool EnablePptc { get; set; }
public bool EnableLowPowerPptc { get; set; }
public bool EnableInternetAccess { get; set; }
public bool EnableFsIntegrityChecks { get; set; }
public bool IgnoreMissingServices { get; set; }
Expand Down Expand Up @@ -448,6 +449,7 @@ public void LoadCurrentConfiguration()

// CPU
EnablePptc = config.System.EnablePtc;
EnableLowPowerPptc = config.System.EnableLowPowerPtc;
MemoryMode = (int)config.System.MemoryManagerMode.Value;
UseHypervisor = config.System.UseHypervisor;

Expand Down Expand Up @@ -548,6 +550,7 @@ public void SaveSettings()

// CPU
config.System.EnablePtc.Value = EnablePptc;
config.System.EnableLowPowerPtc.Value = EnableLowPowerPptc;
config.System.MemoryManagerMode.Value = (MemoryManagerMode)MemoryMode;
config.System.UseHypervisor.Value = UseHypervisor;

Expand Down
6 changes: 5 additions & 1 deletion src/Ryujinx/UI/Views/Settings/SettingsCPUView.axaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<UserControl
<UserControl
x:Class="Ryujinx.Ava.UI.Views.Settings.SettingsCPUView"
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Expand Down Expand Up @@ -32,6 +32,10 @@
<TextBlock Text="{locale:Locale SettingsTabSystemEnablePptc}"
ToolTip.Tip="{locale:Locale PptcToggleTooltip}" />
</CheckBox>
<CheckBox IsChecked="{Binding EnableLowPowerPptc}">
<TextBlock Text="Low-power PPTC cache"
ToolTip.Tip="Load the PPTC cache using a third of the amount of cores." />
</CheckBox>
</StackPanel>
<Separator Height="1" />
<TextBlock Classes="h1" Text="{locale:Locale SettingsTabCpuMemory}" />
Expand Down

0 comments on commit 0faf3f5

Please sign in to comment.