From f207c1293526a0869756e526edd304f6a656830f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Trzci=C5=84ski?= Date: Mon, 19 Dec 2022 22:47:10 +0100 Subject: [PATCH] PowerControl: Decompose `MenuStack.cs` into `Options/` --- PowerControl/Menu/MenuItem.cs | 2 +- PowerControl/Menu/MenuRoot.cs | 2 +- PowerControl/MenuStack.cs | 543 +-------------------- PowerControl/Options/Brightness.cs | 22 + PowerControl/Options/CPUFrequency.cs | 62 +++ PowerControl/Options/FPSLimit.cs | 54 ++ PowerControl/Options/FanControl.cs | 32 ++ PowerControl/Options/GPUColors.cs | 27 + PowerControl/Options/GPUFrequency.cs | 44 ++ PowerControl/Options/GPUScalingItem.cs | 44 ++ PowerControl/Options/PerformanceOverlay.cs | 82 ++++ PowerControl/Options/RefreshRate.cs | 34 ++ PowerControl/Options/Resolution.cs | 43 ++ PowerControl/Options/SMT.cs | 36 ++ PowerControl/Options/Sharpening.cs | 31 ++ PowerControl/Options/SteamController.cs | 34 ++ PowerControl/Options/TDP.cs | 64 +++ PowerControl/Options/Volume.cs | 32 ++ 18 files changed, 660 insertions(+), 528 deletions(-) create mode 100644 PowerControl/Options/Brightness.cs create mode 100644 PowerControl/Options/CPUFrequency.cs create mode 100644 PowerControl/Options/FPSLimit.cs create mode 100644 PowerControl/Options/FanControl.cs create mode 100644 PowerControl/Options/GPUColors.cs create mode 100644 PowerControl/Options/GPUFrequency.cs create mode 100644 PowerControl/Options/GPUScalingItem.cs create mode 100644 PowerControl/Options/PerformanceOverlay.cs create mode 100644 PowerControl/Options/RefreshRate.cs create mode 100644 PowerControl/Options/Resolution.cs create mode 100644 PowerControl/Options/SMT.cs create mode 100644 PowerControl/Options/Sharpening.cs create mode 100644 PowerControl/Options/SteamController.cs create mode 100644 PowerControl/Options/TDP.cs create mode 100644 PowerControl/Options/Volume.cs diff --git a/PowerControl/Menu/MenuItem.cs b/PowerControl/Menu/MenuItem.cs index c743add..7347628 100644 --- a/PowerControl/Menu/MenuItem.cs +++ b/PowerControl/Menu/MenuItem.cs @@ -2,7 +2,7 @@ namespace PowerControl.Menu { public abstract class MenuItem { - public static readonly String[] Helpers = + public static readonly String[] OSDHelpers = { "", "", diff --git a/PowerControl/Menu/MenuRoot.cs b/PowerControl/Menu/MenuRoot.cs index 9956e2d..47f4ff7 100644 --- a/PowerControl/Menu/MenuRoot.cs +++ b/PowerControl/Menu/MenuRoot.cs @@ -49,7 +49,7 @@ namespace PowerControl.Menu { var sb = new StringBuilder(); - sb.AppendJoin("", Helpers); + sb.AppendJoin("", OSDHelpers); if (Name != "") sb.AppendLine(Color(Name, Colors.Blue)); diff --git a/PowerControl/MenuStack.cs b/PowerControl/MenuStack.cs index 0472ea3..22de21b 100644 --- a/PowerControl/MenuStack.cs +++ b/PowerControl/MenuStack.cs @@ -1,9 +1,3 @@ -using CommonHelpers; -using PowerControl.Helpers; -using PowerControl.Helpers.AMD; -using System.Diagnostics; -using static PowerControl.Helpers.AMD.DCE; - namespace PowerControl { internal class MenuStack @@ -13,531 +7,28 @@ namespace PowerControl Name = String.Format("\r\n\r\nPower Control v{0}\r\n", Application.ProductVersion.ToString()), Items = { - new Menu.MenuItemWithOptions() - { - Name = "Brightness", - Options = { 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100 }, - CycleOptions = false, - CurrentValue = delegate() - { - return Helpers.WindowsSettingsBrightnessController.Get(5.0); - }, - ApplyValue = delegate(object selected) - { - Helpers.WindowsSettingsBrightnessController.Set((int)selected); - - return Helpers.WindowsSettingsBrightnessController.Get(5.0); - } - }, - new Menu.MenuItemWithOptions() - { - Name = "Volume", - Options = { 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100 }, - CycleOptions = false, - CurrentValue = delegate() - { - try { return Helpers.AudioManager.GetMasterVolume(5.0); } - catch(Exception) { return null; } - }, - ApplyValue = delegate(object selected) - { - try - { - Helpers.AudioManager.SetMasterVolumeMute(false); - Helpers.AudioManager.SetMasterVolume((int)selected); - - return Helpers.AudioManager.GetMasterVolume(5.0); - } - catch(Exception) - { - // In some cases MasterVolume device is missing - return null; - } - } - }, + Options.Brightness.Instance, + Options.Volume.Instance, new Menu.MenuItemSeparator(), - new Menu.MenuItemWithOptions() - { - Name = "Resolution", - ApplyDelay = 1000, - ResetValue = () => { - if (!GPUScaling.SafeResolutionChange && !Settings.Default.EnableExperimentalFeatures) - return null; - return DisplayResolutionController.GetAllResolutions().Last(); - }, - OptionsValues = delegate() - { - var resolutions = DisplayResolutionController.GetAllResolutions(); - if (resolutions.Count() > 1) - return resolutions.Select(item => (object)item).ToArray(); - return null; - }, - CurrentValue = delegate() - { - if (!GPUScaling.SafeResolutionChange && !Settings.Default.EnableExperimentalFeatures) - return null; - return DisplayResolutionController.GetResolution(); - }, - ApplyValue = delegate(object selected) - { - DisplayResolutionController.SetResolution((DisplayResolutionController.DisplayResolution)selected); - // force refresh Refresh Rate - Root["Refresh Rate"].Update(); - // force reset and refresh of FPS limit - Root["FPS Limit"].Reset(); - Root["FPS Limit"].Update(); - return DisplayResolutionController.GetResolution(); - } - }, - new Menu.MenuItemWithOptions() - { - Name = "Refresh Rate", - ApplyDelay = 1000, - ResetValue = () => { return DisplayResolutionController.GetRefreshRates().Max(); }, - OptionsValues = delegate() - { - var refreshRates = DisplayResolutionController.GetRefreshRates(); - if (refreshRates.Count() > 1) - return refreshRates.Select(item => (object)item).ToArray(); - return null; - }, - CurrentValue = delegate() - { - return DisplayResolutionController.GetRefreshRate(); - }, - ApplyValue = delegate(object selected) - { - DisplayResolutionController.SetRefreshRate((int)selected); - // force reset and refresh of FPS limit - Root["FPS Limit"].Reset(); - Root["FPS Limit"].Update(); - return DisplayResolutionController.GetRefreshRate(); - } - }, - new Menu.MenuItemWithOptions() - { - Name = "FPS Limit", - ApplyDelay = 500, - ResetValue = () => { return "Off"; }, - OptionsValues = delegate() - { - var refreshRate = DisplayResolutionController.GetRefreshRate(); - return new object[] - { - refreshRate / 4, refreshRate / 2, refreshRate, "Off" - }; - }, - CurrentValue = delegate() - { - try - { - RTSS.LoadProfile(); - if (RTSS.GetProfileProperty("FramerateLimit", out int framerate)) - return (framerate == 0) ? "Off" : framerate; - } - catch - { - } - return null; - }, - ApplyValue = delegate(object selected) - { - try - { - int framerate = 0; - if (selected != null && selected.ToString() != "Off") - framerate = (int)selected; - - RTSS.LoadProfile(); - if (!RTSS.SetProfileProperty("FramerateLimit", framerate)) - return null; - if (!RTSS.GetProfileProperty("FramerateLimit", out framerate)) - return null; - RTSS.SaveProfile(); - RTSS.UpdateProfiles(); - return (framerate == 0) ? "Off" : framerate; - } - catch - { - } - return null; - } - }, - new Menu.MenuItemWithOptions() - { - Name = "GPU Scaling", - ApplyDelay = 1000, - Options = Enum.GetValues().Cast().Prepend("Off").ToArray(), - CurrentValue = delegate() - { - if (!GPUScaling.IsSupported) - return null; - if (!GPUScaling.Enabled) - return "Off"; - return GPUScaling.Mode; - }, - ApplyValue = delegate(object selected) - { - if (!GPUScaling.IsSupported) - return null; - - if (selected is GPUScaling.ScalingMode) - GPUScaling.Mode = (GPUScaling.ScalingMode)selected; - else - GPUScaling.Enabled = false; - - // Since the RadeonSoftware will try to revert values - RadeonSoftware.Kill(); - - Root["Resolution"].Update(); - Root["Refresh Rate"].Update(); - Root["FPS Limit"].Reset(); - Root["FPS Limit"].Update(); - - if (!GPUScaling.Enabled) - return "Off"; - return GPUScaling.Mode; - } - }, + Options.Resolution.Instance, + Options.RefreshRate.Instance, + Options.FPSLimit.Instance, + Options.GPUScalingItem.Instance, #if DEBUG - new Menu.MenuItemWithOptions() - { - Name = "Sharpening", - ApplyDelay = 500, - Options = { "Off", "On" }, - CurrentValue = delegate() - { - var value = ImageSharpening.Enabled; - if (value is null) - return null; - return value.Value ? "On" : "Off"; - }, - ApplyValue = delegate(object selected) - { - ImageSharpening.Enabled = (string)selected == "On"; - - var value = ImageSharpening.Enabled; - if (value is null) - return null; - return value.Value ? "On" : "Off"; - } - }, + Options.Sharpening.Instance, #endif - new Menu.MenuItemWithOptions() - { - Name = "Colors", - ApplyDelay = 1000, - Options = Enum.GetValues().Cast().ToList(), - CurrentValue = delegate() - { - return DCE.Current; - }, - ApplyValue = delegate(object selected) - { - if (DCE.Current is null) - return null; - - DCE.Current = (DCE.Mode)selected; - RadeonSoftware.Kill(); - return DCE.Current; - } - }, + Options.GPUColors.Instance, new Menu.MenuItemSeparator(), - new Menu.MenuItemWithOptions() - { - Name = "TDP", - Options = { "3W", "4W", "5W", "6W", "7W", "8W", "10W", "12W", "15W" }, - ApplyDelay = 1000, - ResetValue = () => { return "15W"; }, - ActiveOption = "?", - ApplyValue = delegate(object selected) - { - if (!Settings.Default.AckAntiCheat( - Controller.TitleWithVersion, - "TDP", - "Changing TDP requires kernel access for a short period. Leave the game if it uses anti-cheat protection.") - ) - return null; - - uint mW = uint.Parse(selected.ToString().Replace("W", "")) * 1000; - - if (VangoghGPU.IsSupported) - { - return Instance.WithGlobalMutex(200, () => - { - using (var sd = VangoghGPU.Open()) - { - if (sd is null) - return null; - - sd.SlowTDP = mW; - sd.FastTDP = mW; - } - - return selected; - }); - } - else - { - uint stampLimit = mW/10; - - Process.Start(new ProcessStartInfo() - { - FileName = "Resources/RyzenAdj/ryzenadj.exe", - ArgumentList = { - "--stapm-limit=" + stampLimit.ToString(), - "--slow-limit=" + mW.ToString(), - "--fast-limit=" + mW.ToString(), - }, - WindowStyle = ProcessWindowStyle.Hidden, - UseShellExecute = false, - CreateNoWindow = true - }); - - return selected; - } - } - }, - new Menu.MenuItemWithOptions() - { - Name = "GPU", - Options = { "Default", "400MHz", "800MHz", "1200MHz", "1600MHz" }, - ApplyDelay = 1000, - Visible = VangoghGPU.IsSupported, - ActiveOption = "?", - ResetValue = () => { return "Default"; }, - ApplyValue = delegate(object selected) - { - if (!Settings.Default.AckAntiCheat( - Controller.TitleWithVersion, - "GPU", - "Changing GPU frequency requires kernel access for a short period. Leave the game if it uses anti-cheat protection.") - ) - return null; - - return Instance.WithGlobalMutex(200, () => - { - using (var sd = VangoghGPU.Open()) - { - if (sd is null) - return null; - - if (selected.ToString() == "Default") - { - sd.HardMinGfxClock = 200; - return selected; - } - - sd.HardMinGfxClock = uint.Parse(selected.ToString().Replace("MHz", "")); - return selected; - } - }); - } - }, - new Menu.MenuItemWithOptions() - { - Name = "CPU", - Options = { "Default", "Power-Save", "Balanced", "Max" }, - ApplyDelay = 1000, - ActiveOption = "?", - Visible = VangoghGPU.IsSupported, - ResetValue = () => { return "Default"; }, - ApplyValue = delegate(object selected) - { - if (!Settings.Default.AckAntiCheat( - Controller.TitleWithVersion, - "CPU", - "Changing GPU frequency requires kernel access for a short period. Leave the game if it uses anti-cheat protection.") - ) - return null; - - return Instance.WithGlobalMutex(200, () => - { - using (var sd = VangoghGPU.Open()) - { - if (sd is null) - return null; - - switch(selected.ToString()) - { - case "Default": - sd.MinCPUClock = 1400; - sd.MaxCPUClock = 3500; - break; - - case "Power-Save": - sd.MinCPUClock = 1400; - sd.MaxCPUClock = 1800; - break; - - case "Balanced": - sd.MinCPUClock = 2200; - sd.MaxCPUClock = 2800; - break; - - case "Max": - sd.MinCPUClock = 3000; - sd.MaxCPUClock = 3500; - break; - - default: - return null; - } - return selected; - } - }); - } - }, - new Menu.MenuItemWithOptions() - { - Name = "SMT", - ApplyDelay = 500, - Options = { "No", "Yes" }, - ResetValue = () => { return "Yes"; }, - CurrentValue = delegate() - { - if (!RTSS.IsOSDForeground(out var processId)) - return null; - if (!ProcessorCores.HasSMTThreads()) - return null; - - return ProcessorCores.IsUsingSMT(processId.Value) ? "Yes" : "No"; - }, - ApplyValue = delegate(object selected) - { - if (!RTSS.IsOSDForeground(out var processId)) - return null; - if (!ProcessorCores.HasSMTThreads()) - return null; - - ProcessorCores.SetProcessSMT(processId.Value, selected.ToString() == "Yes"); - - return ProcessorCores.IsUsingSMT(processId.Value) ? "Yes" : "No"; - } - }, + Options.TDP.Instance, + Options.GPUFrequency.Instance, + Options.CPUFrequency.Instance, + Options.SMT.Instance, new Menu.MenuItemSeparator(), - new Menu.MenuItemWithOptions() - { - Name = "OSD", - ApplyDelay = 500, - OptionsValues = delegate() - { - return Enum.GetValues().Select(item => (object)item).ToArray(); - }, - CurrentValue = delegate() - { - if (SharedData.GetExistingValue(out var value)) - return value.CurrentEnabled; - return null; - }, - ApplyValue = delegate(object selected) - { - if (!SharedData.GetExistingValue(out var value)) - return null; - value.DesiredEnabled = (OverlayEnabled)selected; - if (!SharedData.SetExistingValue(value)) - return null; - return selected; - } - }, - new Menu.MenuItemWithOptions() - { - Name = "OSD Mode", - ApplyDelay = 500, - OptionsValues = delegate() - { - return Enum.GetValues().Select(item => (object)item).ToArray(); - }, - CurrentValue = delegate() - { - if (SharedData.GetExistingValue(out var value)) - return value.Current; - return null; - }, - ApplyValue = delegate(object selected) - { - if (!SharedData.GetExistingValue(out var value)) - return null; - value.Desired = (OverlayMode)selected; - if (!SharedData.SetExistingValue(value)) - return null; - return selected; - } - }, - new Menu.MenuItemWithOptions() - { - Name = "OSD Kernel Drivers", - ApplyDelay = 500, - OptionsValues = delegate() - { - return Enum.GetValues().Select(item => (object)item).ToArray(); - }, - CurrentValue = delegate() - { - if (SharedData.GetExistingValue(out var value)) - return value.KernelDriversLoaded; - return null; - }, - ApplyValue = delegate(object selected) - { - if (!SharedData.GetExistingValue(out var value)) - return null; - value.DesiredKernelDriversLoaded = (KernelDriversLoaded)selected; - if (!SharedData.SetExistingValue(value)) - return null; - return selected; - } - }, - new Menu.MenuItemWithOptions() - { - Name = "FAN", - ApplyDelay = 500, - OptionsValues = delegate() - { - return Enum.GetValues().Select(item => (object)item).ToArray(); - }, - CurrentValue = delegate() - { - if (SharedData.GetExistingValue(out var value)) - return value.Current; - return null; - }, - ApplyValue = delegate(object selected) - { - if (!SharedData.GetExistingValue(out var value)) - return null; - value.Desired = (FanMode)selected; - if (!SharedData.SetExistingValue(value)) - return null; - return selected; - } - }, - new Menu.MenuItemWithOptions() - { - Name = "Controller", - ApplyDelay = 500, - OptionsValues = delegate() - { - if (SharedData.GetExistingValue(out var value)) - return value.SelectableProfiles.SplitWithN(); - return null; - }, - CurrentValue = delegate() - { - if (SharedData.GetExistingValue(out var value)) - return value.CurrentProfile.Length > 0 ? value.CurrentProfile : null; - return null; - }, - ApplyValue = delegate(object selected) - { - if (!SharedData.GetExistingValue(out var value)) - return null; - value.DesiredProfile = (String)selected; - if (!SharedData.SetExistingValue(value)) - return null; - return selected; - } - } + Options.PerformanceOverlay.EnabledInstance, + Options.PerformanceOverlay.ModeInstance, + Options.PerformanceOverlay.KernelDriversInstance, + Options.FanControl.Instance, + Options.SteamController.Instance } }; } diff --git a/PowerControl/Options/Brightness.cs b/PowerControl/Options/Brightness.cs new file mode 100644 index 0000000..4c6225b --- /dev/null +++ b/PowerControl/Options/Brightness.cs @@ -0,0 +1,22 @@ +namespace PowerControl.Options +{ + public static class Brightness + { + public static Menu.MenuItemWithOptions Instance = new Menu.MenuItemWithOptions() + { + Name = "Brightness", + Options = { 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100 }, + CycleOptions = false, + CurrentValue = delegate () + { + return Helpers.WindowsSettingsBrightnessController.Get(5.0); + }, + ApplyValue = delegate (object selected) + { + Helpers.WindowsSettingsBrightnessController.Set((int)selected); + + return Helpers.WindowsSettingsBrightnessController.Get(5.0); + } + }; + } +} \ No newline at end of file diff --git a/PowerControl/Options/CPUFrequency.cs b/PowerControl/Options/CPUFrequency.cs new file mode 100644 index 0000000..a18ce12 --- /dev/null +++ b/PowerControl/Options/CPUFrequency.cs @@ -0,0 +1,62 @@ +using PowerControl.Helpers.AMD; + +namespace PowerControl.Options +{ + public static class CPUFrequency + { + public static Menu.MenuItemWithOptions Instance = new Menu.MenuItemWithOptions() + { + Name = "CPU", + Options = { "Default", "Power-Save", "Balanced", "Max" }, + ApplyDelay = 1000, + ActiveOption = "?", + Visible = VangoghGPU.IsSupported, + ResetValue = () => { return "Default"; }, + ApplyValue = delegate (object selected) + { + if (!Settings.Default.AckAntiCheat( + Controller.TitleWithVersion, + "CPU", + "Changing GPU frequency requires kernel access for a short period. Leave the game if it uses anti-cheat protection.") + ) + return null; + + return CommonHelpers.Instance.WithGlobalMutex(200, () => + { + using (var sd = VangoghGPU.Open()) + { + if (sd is null) + return null; + + switch (selected.ToString()) + { + case "Default": + sd.MinCPUClock = 1400; + sd.MaxCPUClock = 3500; + break; + + case "Power-Save": + sd.MinCPUClock = 1400; + sd.MaxCPUClock = 1800; + break; + + case "Balanced": + sd.MinCPUClock = 2200; + sd.MaxCPUClock = 2800; + break; + + case "Max": + sd.MinCPUClock = 3000; + sd.MaxCPUClock = 3500; + break; + + default: + return null; + } + return selected; + } + }); + } + }; + } +} diff --git a/PowerControl/Options/FPSLimit.cs b/PowerControl/Options/FPSLimit.cs new file mode 100644 index 0000000..6ab9a53 --- /dev/null +++ b/PowerControl/Options/FPSLimit.cs @@ -0,0 +1,54 @@ +using CommonHelpers; +using PowerControl.Helpers; + +namespace PowerControl.Options +{ + public static class FPSLimit + { + public static Menu.MenuItemWithOptions Instance = new Menu.MenuItemWithOptions() + { + Name = "FPS Limit", + ApplyDelay = 500, + ResetValue = () => { return "Off"; }, + OptionsValues = delegate () + { + var refreshRate = DisplayResolutionController.GetRefreshRate(); + return new object[] + { + refreshRate / 4, refreshRate / 2, refreshRate, "Off" + }; + }, + CurrentValue = delegate () + { + try + { + RTSS.LoadProfile(); + if (RTSS.GetProfileProperty("FramerateLimit", out int framerate)) + return (framerate == 0) ? "Off" : framerate; + } + catch { } + return null; + }, + ApplyValue = delegate (object selected) + { + try + { + int framerate = 0; + if (selected != null && selected.ToString() != "Off") + framerate = (int)selected; + + RTSS.LoadProfile(); + if (!RTSS.SetProfileProperty("FramerateLimit", framerate)) + return null; + if (!RTSS.GetProfileProperty("FramerateLimit", out framerate)) + return null; + RTSS.SaveProfile(); + RTSS.UpdateProfiles(); + return (framerate == 0) ? "Off" : framerate; + } + catch { } + return null; + } + }; + } +} diff --git a/PowerControl/Options/FanControl.cs b/PowerControl/Options/FanControl.cs new file mode 100644 index 0000000..b958742 --- /dev/null +++ b/PowerControl/Options/FanControl.cs @@ -0,0 +1,32 @@ +using CommonHelpers; + +namespace PowerControl.Options +{ + public static class FanControl + { + public static Menu.MenuItemWithOptions Instance = new Menu.MenuItemWithOptions() + { + Name = "FAN", + ApplyDelay = 500, + OptionsValues = delegate () + { + return Enum.GetValues().Select(item => (object)item).ToArray(); + }, + CurrentValue = delegate () + { + if (SharedData.GetExistingValue(out var value)) + return value.Current; + return null; + }, + ApplyValue = delegate (object selected) + { + if (!SharedData.GetExistingValue(out var value)) + return null; + value.Desired = (FanMode)selected; + if (!SharedData.SetExistingValue(value)) + return null; + return selected; + } + }; + } +} diff --git a/PowerControl/Options/GPUColors.cs b/PowerControl/Options/GPUColors.cs new file mode 100644 index 0000000..5d6cb3d --- /dev/null +++ b/PowerControl/Options/GPUColors.cs @@ -0,0 +1,27 @@ +using PowerControl.Helpers.AMD; + +namespace PowerControl.Options +{ + public static class GPUColors + { + public static Menu.MenuItemWithOptions Instance = new Menu.MenuItemWithOptions() + { + Name = "Colors", + ApplyDelay = 1000, + Options = Enum.GetValues().Cast().ToList(), + CurrentValue = delegate () + { + return DCE.Current; + }, + ApplyValue = delegate (object selected) + { + if (DCE.Current is null) + return null; + + DCE.Current = (DCE.Mode)selected; + RadeonSoftware.Kill(); + return DCE.Current; + } + }; + } +} diff --git a/PowerControl/Options/GPUFrequency.cs b/PowerControl/Options/GPUFrequency.cs new file mode 100644 index 0000000..7dc5465 --- /dev/null +++ b/PowerControl/Options/GPUFrequency.cs @@ -0,0 +1,44 @@ +using PowerControl.Helpers.AMD; + +namespace PowerControl.Options +{ + public static class GPUFrequency + { + public static Menu.MenuItemWithOptions Instance = new Menu.MenuItemWithOptions() + { + Name = "GPU", + Options = { "Default", "400MHz", "800MHz", "1200MHz", "1600MHz" }, + ApplyDelay = 1000, + Visible = VangoghGPU.IsSupported, + ActiveOption = "?", + ResetValue = () => { return "Default"; }, + ApplyValue = delegate (object selected) + { + if (!Settings.Default.AckAntiCheat( + Controller.TitleWithVersion, + "GPU", + "Changing GPU frequency requires kernel access for a short period. Leave the game if it uses anti-cheat protection.") + ) + return null; + + return CommonHelpers.Instance.WithGlobalMutex(200, () => + { + using (var sd = VangoghGPU.Open()) + { + if (sd is null) + return null; + + if (selected.ToString() == "Default") + { + sd.HardMinGfxClock = 200; + return selected; + } + + sd.HardMinGfxClock = uint.Parse(selected.ToString().Replace("MHz", "")); + return selected; + } + }); + } + }; + } +} diff --git a/PowerControl/Options/GPUScalingItem.cs b/PowerControl/Options/GPUScalingItem.cs new file mode 100644 index 0000000..5d2ad0d --- /dev/null +++ b/PowerControl/Options/GPUScalingItem.cs @@ -0,0 +1,44 @@ +using PowerControl.Helpers.AMD; + +namespace PowerControl.Options +{ + public static class GPUScalingItem + { + public static Menu.MenuItemWithOptions Instance = new Menu.MenuItemWithOptions() + { + Name = "GPU Scaling", + ApplyDelay = 1000, + Options = Enum.GetValues().Cast().Prepend("Off").ToArray(), + CurrentValue = delegate () + { + if (!GPUScaling.IsSupported) + return null; + if (!GPUScaling.Enabled) + return "Off"; + return GPUScaling.Mode; + }, + ApplyValue = delegate (object selected) + { + if (!GPUScaling.IsSupported) + return null; + + if (selected is GPUScaling.ScalingMode) + GPUScaling.Mode = (GPUScaling.ScalingMode)selected; + else + GPUScaling.Enabled = false; + + // Since the RadeonSoftware will try to revert values + RadeonSoftware.Kill(); + + Resolution.Instance.Update(); + RefreshRate.Instance.Update(); + FPSLimit.Instance.Reset(); + FPSLimit.Instance.Update(); + + if (!GPUScaling.Enabled) + return "Off"; + return GPUScaling.Mode; + } + }; + } +} diff --git a/PowerControl/Options/PerformanceOverlay.cs b/PowerControl/Options/PerformanceOverlay.cs new file mode 100644 index 0000000..683e285 --- /dev/null +++ b/PowerControl/Options/PerformanceOverlay.cs @@ -0,0 +1,82 @@ +using CommonHelpers; + +namespace PowerControl.Options +{ + public static class PerformanceOverlay + { + public static Menu.MenuItemWithOptions EnabledInstance = new Menu.MenuItemWithOptions() + { + Name = "OSD", + ApplyDelay = 500, + OptionsValues = delegate () + { + return Enum.GetValues().Select(item => (object)item).ToArray(); + }, + CurrentValue = delegate () + { + if (SharedData.GetExistingValue(out var value)) + return value.CurrentEnabled; + return null; + }, + ApplyValue = delegate (object selected) + { + if (!SharedData.GetExistingValue(out var value)) + return null; + value.DesiredEnabled = (OverlayEnabled)selected; + if (!SharedData.SetExistingValue(value)) + return null; + return selected; + } + }; + + public static Menu.MenuItemWithOptions ModeInstance = new Menu.MenuItemWithOptions() + { + Name = "OSD Mode", + ApplyDelay = 500, + OptionsValues = delegate () + { + return Enum.GetValues().Select(item => (object)item).ToArray(); + }, + CurrentValue = delegate () + { + if (SharedData.GetExistingValue(out var value)) + return value.Current; + return null; + }, + ApplyValue = delegate (object selected) + { + if (!SharedData.GetExistingValue(out var value)) + return null; + value.Desired = (OverlayMode)selected; + if (!SharedData.SetExistingValue(value)) + return null; + return selected; + } + }; + + public static Menu.MenuItemWithOptions KernelDriversInstance = new Menu.MenuItemWithOptions() + { + Name = "OSD Kernel Drivers", + ApplyDelay = 500, + OptionsValues = delegate () + { + return Enum.GetValues().Select(item => (object)item).ToArray(); + }, + CurrentValue = delegate () + { + if (SharedData.GetExistingValue(out var value)) + return value.KernelDriversLoaded; + return null; + }, + ApplyValue = delegate (object selected) + { + if (!SharedData.GetExistingValue(out var value)) + return null; + value.DesiredKernelDriversLoaded = (KernelDriversLoaded)selected; + if (!SharedData.SetExistingValue(value)) + return null; + return selected; + } + }; + } +} diff --git a/PowerControl/Options/RefreshRate.cs b/PowerControl/Options/RefreshRate.cs new file mode 100644 index 0000000..4b0ee95 --- /dev/null +++ b/PowerControl/Options/RefreshRate.cs @@ -0,0 +1,34 @@ +using PowerControl.Helpers; +using PowerControl.Helpers.AMD; + +namespace PowerControl.Options +{ + public static class RefreshRate + { + public static Menu.MenuItemWithOptions Instance = new Menu.MenuItemWithOptions() + { + Name = "Refresh Rate", + ApplyDelay = 1000, + ResetValue = () => { return DisplayResolutionController.GetRefreshRates().Max(); }, + OptionsValues = delegate () + { + var refreshRates = DisplayResolutionController.GetRefreshRates(); + if (refreshRates.Count() > 1) + return refreshRates.Select(item => (object)item).ToArray(); + return null; + }, + CurrentValue = delegate () + { + return DisplayResolutionController.GetRefreshRate(); + }, + ApplyValue = delegate (object selected) + { + DisplayResolutionController.SetRefreshRate((int)selected); + // force reset and refresh of FPS limit + FPSLimit.Instance.Reset(); + FPSLimit.Instance.Update(); + return DisplayResolutionController.GetRefreshRate(); + } + }; + } +} diff --git a/PowerControl/Options/Resolution.cs b/PowerControl/Options/Resolution.cs new file mode 100644 index 0000000..a248356 --- /dev/null +++ b/PowerControl/Options/Resolution.cs @@ -0,0 +1,43 @@ +using PowerControl.Helpers; +using PowerControl.Helpers.AMD; + +namespace PowerControl.Options +{ + public static class Resolution + { + public static Menu.MenuItemWithOptions Instance = new Menu.MenuItemWithOptions() + { + Name = "Resolution", + ApplyDelay = 1000, + ResetValue = () => + { + if (!GPUScaling.SafeResolutionChange && !Settings.Default.EnableExperimentalFeatures) + return null; + return DisplayResolutionController.GetAllResolutions().Last(); + }, + OptionsValues = delegate () + { + var resolutions = DisplayResolutionController.GetAllResolutions(); + if (resolutions.Count() > 1) + return resolutions.Select(item => (object)item).ToArray(); + return null; + }, + CurrentValue = delegate () + { + if (!GPUScaling.SafeResolutionChange && !Settings.Default.EnableExperimentalFeatures) + return null; + return DisplayResolutionController.GetResolution(); + }, + ApplyValue = delegate (object selected) + { + DisplayResolutionController.SetResolution((DisplayResolutionController.DisplayResolution)selected); + // force refresh Refresh Rate + RefreshRate.Instance.Update(); + // force reset and refresh of FPS limit + FPSLimit.Instance.Reset(); + FPSLimit.Instance.Update(); + return DisplayResolutionController.GetResolution(); + } + }; + } +} diff --git a/PowerControl/Options/SMT.cs b/PowerControl/Options/SMT.cs new file mode 100644 index 0000000..4e24f8b --- /dev/null +++ b/PowerControl/Options/SMT.cs @@ -0,0 +1,36 @@ +using CommonHelpers; +using PowerControl.Helpers; + +namespace PowerControl.Options +{ + public static class SMT + { + public static Menu.MenuItemWithOptions Instance = new Menu.MenuItemWithOptions() + { + Name = "SMT", + ApplyDelay = 500, + Options = { "No", "Yes" }, + ResetValue = () => { return "Yes"; }, + CurrentValue = delegate () + { + if (!RTSS.IsOSDForeground(out var processId)) + return null; + if (!ProcessorCores.HasSMTThreads()) + return null; + + return ProcessorCores.IsUsingSMT(processId.Value) ? "Yes" : "No"; + }, + ApplyValue = delegate (object selected) + { + if (!RTSS.IsOSDForeground(out var processId)) + return null; + if (!ProcessorCores.HasSMTThreads()) + return null; + + ProcessorCores.SetProcessSMT(processId.Value, selected.ToString() == "Yes"); + + return ProcessorCores.IsUsingSMT(processId.Value) ? "Yes" : "No"; + } + }; + } +} diff --git a/PowerControl/Options/Sharpening.cs b/PowerControl/Options/Sharpening.cs new file mode 100644 index 0000000..d22bdb5 --- /dev/null +++ b/PowerControl/Options/Sharpening.cs @@ -0,0 +1,31 @@ +using PowerControl.Helpers; +using PowerControl.Helpers.AMD; + +namespace PowerControl.Options +{ + public static class Sharpening + { + public static Menu.MenuItemWithOptions Instance = new Menu.MenuItemWithOptions() + { + Name = "Sharpening", + ApplyDelay = 500, + Options = { "Off", "On" }, + CurrentValue = delegate () + { + var value = ImageSharpening.Enabled; + if (value is null) + return null; + return value.Value ? "On" : "Off"; + }, + ApplyValue = delegate (object selected) + { + ImageSharpening.Enabled = (string)selected == "On"; + + var value = ImageSharpening.Enabled; + if (value is null) + return null; + return value.Value ? "On" : "Off"; + } + }; + } +} \ No newline at end of file diff --git a/PowerControl/Options/SteamController.cs b/PowerControl/Options/SteamController.cs new file mode 100644 index 0000000..4dac5f3 --- /dev/null +++ b/PowerControl/Options/SteamController.cs @@ -0,0 +1,34 @@ +using CommonHelpers; + +namespace PowerControl.Options +{ + public static class SteamController + { + public static Menu.MenuItemWithOptions Instance = new Menu.MenuItemWithOptions() + { + Name = "Controller", + ApplyDelay = 500, + OptionsValues = delegate () + { + if (SharedData.GetExistingValue(out var value)) + return value.SelectableProfiles.SplitWithN(); + return null; + }, + CurrentValue = delegate () + { + if (SharedData.GetExistingValue(out var value)) + return value.CurrentProfile.Length > 0 ? value.CurrentProfile : null; + return null; + }, + ApplyValue = delegate (object selected) + { + if (!SharedData.GetExistingValue(out var value)) + return null; + value.DesiredProfile = (String)selected; + if (!SharedData.SetExistingValue(value)) + return null; + return selected; + } + }; + } +} diff --git a/PowerControl/Options/TDP.cs b/PowerControl/Options/TDP.cs new file mode 100644 index 0000000..42647dc --- /dev/null +++ b/PowerControl/Options/TDP.cs @@ -0,0 +1,64 @@ +using System.Diagnostics; +using PowerControl.Helpers.AMD; + +namespace PowerControl.Options +{ + public static class TDP + { + public static Menu.MenuItemWithOptions Instance = new Menu.MenuItemWithOptions() + { + Name = "TDP", + Options = { "3W", "4W", "5W", "6W", "7W", "8W", "10W", "12W", "15W" }, + ApplyDelay = 1000, + ResetValue = () => { return "15W"; }, + ActiveOption = "?", + ApplyValue = delegate (object selected) + { + if (!Settings.Default.AckAntiCheat( + Controller.TitleWithVersion, + "TDP", + "Changing TDP requires kernel access for a short period. Leave the game if it uses anti-cheat protection.") + ) + return null; + + uint mW = uint.Parse(selected.ToString().Replace("W", "")) * 1000; + + if (VangoghGPU.IsSupported) + { + return CommonHelpers.Instance.WithGlobalMutex(200, () => + { + using (var sd = VangoghGPU.Open()) + { + if (sd is null) + return null; + + sd.SlowTDP = mW; + sd.FastTDP = mW; + } + + return selected; + }); + } + else + { + uint stampLimit = mW / 10; + + Process.Start(new ProcessStartInfo() + { + FileName = "Resources/RyzenAdj/ryzenadj.exe", + ArgumentList = { + "--stapm-limit=" + stampLimit.ToString(), + "--slow-limit=" + mW.ToString(), + "--fast-limit=" + mW.ToString(), + }, + WindowStyle = ProcessWindowStyle.Hidden, + UseShellExecute = false, + CreateNoWindow = true + }); + + return selected; + } + } + }; + } +} diff --git a/PowerControl/Options/Volume.cs b/PowerControl/Options/Volume.cs new file mode 100644 index 0000000..33fd255 --- /dev/null +++ b/PowerControl/Options/Volume.cs @@ -0,0 +1,32 @@ +namespace PowerControl.Options +{ + public static class Volume + { + public static Menu.MenuItemWithOptions Instance = new Menu.MenuItemWithOptions() + { + Name = "Volume", + Options = { 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100 }, + CycleOptions = false, + CurrentValue = delegate () + { + try { return Helpers.AudioManager.GetMasterVolume(5.0); } + catch (Exception) { return null; } + }, + ApplyValue = delegate (object selected) + { + try + { + Helpers.AudioManager.SetMasterVolumeMute(false); + Helpers.AudioManager.SetMasterVolume((int)selected); + + return Helpers.AudioManager.GetMasterVolume(5.0); + } + catch (Exception) + { + // In some cases MasterVolume device is missing + return null; + } + } + }; + } +}