diff --git a/app/Mode/ModeControl.cs b/app/Mode/ModeControl.cs index 388dfe63..2a14d251 100644 --- a/app/Mode/ModeControl.cs +++ b/app/Mode/ModeControl.cs @@ -280,35 +280,38 @@ namespace GHelper.Mode public void SetGPUClocks(bool launchAsAdmin = true) { - - int gpu_core = AppConfig.GetMode("gpu_core"); - int gpu_memory = AppConfig.GetMode("gpu_memory"); - - if (gpu_core == -1 && gpu_memory == -1) return; - - //if ((gpu_core > -5 && gpu_core < 5) && (gpu_memory > -5 && gpu_memory < 5)) launchAsAdmin = false; - - if (Program.acpi.DeviceGet(AsusACPI.GPUEco) == 1) return; - if (HardwareControl.GpuControl is null) return; - if (!HardwareControl.GpuControl!.IsNvidia) return; - - using NvidiaGpuControl nvControl = (NvidiaGpuControl)HardwareControl.GpuControl; - try + Task.Run(() => { - int getStatus = nvControl.GetClocks(out int current_core, out int current_memory); - if (getStatus != -1) + + int gpu_core = AppConfig.GetMode("gpu_core"); + int gpu_memory = AppConfig.GetMode("gpu_memory"); + + if (gpu_core == -1 && gpu_memory == -1) return; + + //if ((gpu_core > -5 && gpu_core < 5) && (gpu_memory > -5 && gpu_memory < 5)) launchAsAdmin = false; + + if (Program.acpi.DeviceGet(AsusACPI.GPUEco) == 1) return; + if (HardwareControl.GpuControl is null) return; + if (!HardwareControl.GpuControl!.IsNvidia) return; + + using NvidiaGpuControl nvControl = (NvidiaGpuControl)HardwareControl.GpuControl; + try { - if (Math.Abs(gpu_core - current_core) < 5 && Math.Abs(gpu_memory - current_memory) < 5) return; + int getStatus = nvControl.GetClocks(out int current_core, out int current_memory); + if (getStatus != -1) + { + if (Math.Abs(gpu_core - current_core) < 5 && Math.Abs(gpu_memory - current_memory) < 5) return; + } + + int setStatus = nvControl.SetClocks(gpu_core, gpu_memory); + if (launchAsAdmin && setStatus == -1) ProcessHelper.RunAsAdmin("gpu"); + } - - int setStatus = nvControl.SetClocks(gpu_core, gpu_memory); - if (launchAsAdmin && setStatus == -1) ProcessHelper.RunAsAdmin("gpu"); - - } - catch (Exception ex) - { - Logger.WriteLine(ex.ToString()); - } + catch (Exception ex) + { + Logger.WriteLine(ex.ToString()); + } + }); } public void SetGPUPower() diff --git a/app/Mode/PowerNative.cs b/app/Mode/PowerNative.cs index 23cdc30c..f9174535 100644 --- a/app/Mode/PowerNative.cs +++ b/app/Mode/PowerNative.cs @@ -72,7 +72,12 @@ namespace GHelper.Mode [DllImportAttribute("powrprof.dll", EntryPoint = "PowerSetActiveOverlayScheme")] public static extern uint PowerSetActiveOverlayScheme(Guid OverlaySchemeGuid); - + public static Dictionary powerModes = new Dictionary + { + { "961cc777-2547-4f9d-8174-7d86181b8a7a", "Best Power Efficiency" }, + { "00000000-0000-0000-0000-000000000000", "Balanced" }, + { "ded574b5-45a0-4f42-8737-46345c09c238", "Best Performance" }, + }; static Guid GetActiveScheme() { IntPtr pActiveSchemeGuid; @@ -135,17 +140,27 @@ namespace GHelper.Mode if (overlays.Contains(scheme)) { + + Guid activeSchemeGuid = GetActiveScheme(); + Guid balanced = new Guid("381b4222-f694-41f0-9685-ff5bb260df2e"); + + if (activeSchemeGuid != balanced && !AppConfig.Is("skip_power_plan")) + { + PowerSetActiveScheme(IntPtr.Zero, balanced); + Logger.WriteLine("Balanced Plan: " + balanced); + } + uint status = PowerGetEffectiveOverlayScheme(out Guid activeScheme); if (status != 0 || activeScheme != guidScheme) { PowerSetActiveOverlayScheme(guidScheme); - Logger.WriteLine("Power mode: " + scheme); + Logger.WriteLine("Power Mode: " + scheme); } } else { PowerSetActiveScheme(IntPtr.Zero, guidScheme); - Logger.WriteLine("Power plan: " + scheme); + Logger.WriteLine("Power Plan: " + scheme); }