diff --git a/app/AsusACPI.cs b/app/AsusACPI.cs index e545062f..f5986bcb 100644 --- a/app/AsusACPI.cs +++ b/app/AsusACPI.cs @@ -105,6 +105,9 @@ public class AsusACPI public const uint CORES_CPU = 0x001200D2; // Intel E-core and P-core configuration in a format 0x0[E]0[P] public const uint CORES_MAX = 0x001200D3; // Maximum Intel E-core and P-core availability + public const uint GPU_POWER_BASE = 0x00120099; // Base part GPU TGP + public const uint GPU_POWER = 0x00120098; // Additonal part of GPU TGP + public const int APU_MEM = 0x000600C1; public const int TUF_KB_BRIGHTNESS = 0x00050021; @@ -150,6 +153,9 @@ public class AsusACPI public const int MinGPUBoost = 5; public static int MaxGPUBoost = 25; + public static int MinGPUPower = 0; + public static int MaxGPUPower = 25; + public const int MinGPUTemp = 75; public const int MaxGPUTemp = 87; diff --git a/app/Display/ScreenNative.cs b/app/Display/ScreenNative.cs index 0b260fd3..e2346aaa 100644 --- a/app/Display/ScreenNative.cs +++ b/app/Display/ScreenNative.cs @@ -42,6 +42,12 @@ namespace GHelper.Display [DllImport("gdi32")] internal static extern bool GetDeviceGammaRamp(IntPtr dcHandle, ref GammaRamp ramp); + [DllImport("gdi32", CharSet = CharSet.Unicode)] + internal static extern bool SetICMProfileW(IntPtr dcHandle, string lpFileName); + + [DllImport("gdi32", CharSet = CharSet.Unicode)] + internal static extern bool SetICMMode(IntPtr dcHandle, int mode); + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] public struct DEVMODE { diff --git a/app/Fans.Designer.cs b/app/Fans.Designer.cs index 8b653e1c..8b995106 100644 --- a/app/Fans.Designer.cs +++ b/app/Fans.Designer.cs @@ -31,14 +31,14 @@ namespace GHelper /// private void InitializeComponent() { - ChartArea chartArea1 = new ChartArea(); - Title title1 = new Title(); - ChartArea chartArea2 = new ChartArea(); - Title title2 = new Title(); - ChartArea chartArea3 = new ChartArea(); - Title title3 = new Title(); - ChartArea chartArea4 = new ChartArea(); - Title title4 = new Title(); + ChartArea chartArea13 = new ChartArea(); + Title title13 = new Title(); + ChartArea chartArea14 = new ChartArea(); + Title title14 = new Title(); + ChartArea chartArea15 = new ChartArea(); + Title title15 = new Title(); + ChartArea chartArea16 = new ChartArea(); + Title title16 = new Title(); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Fans)); panelFans = new Panel(); labelTip = new Label(); @@ -147,6 +147,10 @@ namespace GHelper buttonAdvanced = new RButton(); buttonGPU = new RButton(); buttonCPU = new RButton(); + panelGPUPower = new Panel(); + labelGPUPower = new Label(); + labelGPUPowerTitle = new Label(); + trackGPUPower = new TrackBar(); panelFans.SuspendLayout(); tableFanCharts.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)chartGPU).BeginInit(); @@ -204,6 +208,8 @@ namespace GHelper ((System.ComponentModel.ISupportInitialize)pictureGPU).BeginInit(); panelNav.SuspendLayout(); tableNav.SuspendLayout(); + panelGPUPower.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)trackGPUPower).BeginInit(); SuspendLayout(); // // panelFans @@ -260,8 +266,8 @@ namespace GHelper // // chartGPU // - chartArea1.Name = "ChartArea1"; - chartGPU.ChartAreas.Add(chartArea1); + chartArea13.Name = "ChartArea1"; + chartGPU.ChartAreas.Add(chartArea13); chartGPU.Dock = DockStyle.Fill; chartGPU.Location = new Point(12, 493); chartGPU.Margin = new Padding(2, 10, 2, 10); @@ -269,13 +275,13 @@ namespace GHelper chartGPU.Size = new Size(782, 463); chartGPU.TabIndex = 17; chartGPU.Text = "chartGPU"; - title1.Name = "Title1"; - chartGPU.Titles.Add(title1); + title13.Name = "Title1"; + chartGPU.Titles.Add(title13); // // chartCPU // - chartArea2.Name = "ChartArea1"; - chartCPU.ChartAreas.Add(chartArea2); + chartArea14.Name = "ChartArea1"; + chartCPU.ChartAreas.Add(chartArea14); chartCPU.Dock = DockStyle.Fill; chartCPU.Location = new Point(12, 10); chartCPU.Margin = new Padding(2, 10, 2, 10); @@ -283,13 +289,13 @@ namespace GHelper chartCPU.Size = new Size(782, 463); chartCPU.TabIndex = 14; chartCPU.Text = "chartCPU"; - title2.Name = "Title1"; - chartCPU.Titles.Add(title2); + title14.Name = "Title1"; + chartCPU.Titles.Add(title14); // // chartXGM // - chartArea3.Name = "ChartAreaXGM"; - chartXGM.ChartAreas.Add(chartArea3); + chartArea15.Name = "ChartAreaXGM"; + chartXGM.ChartAreas.Add(chartArea15); chartXGM.Dock = DockStyle.Fill; chartXGM.Location = new Point(12, 1459); chartXGM.Margin = new Padding(2, 10, 2, 10); @@ -297,14 +303,14 @@ namespace GHelper chartXGM.Size = new Size(782, 463); chartXGM.TabIndex = 14; chartXGM.Text = "chartXGM"; - title3.Name = "Title4"; - chartXGM.Titles.Add(title3); + title15.Name = "Title4"; + chartXGM.Titles.Add(title15); chartXGM.Visible = false; // // chartMid // - chartArea4.Name = "ChartArea3"; - chartMid.ChartAreas.Add(chartArea4); + chartArea16.Name = "ChartArea3"; + chartMid.ChartAreas.Add(chartArea16); chartMid.Dock = DockStyle.Fill; chartMid.Location = new Point(12, 976); chartMid.Margin = new Padding(2, 10, 2, 10); @@ -312,8 +318,8 @@ namespace GHelper chartMid.Size = new Size(782, 463); chartMid.TabIndex = 14; chartMid.Text = "chartMid"; - title4.Name = "Title3"; - chartMid.Titles.Add(title4); + title16.Name = "Title3"; + chartMid.Titles.Add(title16); chartMid.Visible = false; // // panelTitleFans @@ -533,7 +539,7 @@ namespace GHelper panelAdvanced.Controls.Add(panelTitleTemp); panelAdvanced.Controls.Add(panelDownload); panelAdvanced.Dock = DockStyle.Top; - panelAdvanced.Location = new Point(10, 1644); + panelAdvanced.Location = new Point(10, 1768); panelAdvanced.Name = "panelAdvanced"; panelAdvanced.Size = new Size(520, 992); panelAdvanced.TabIndex = 14; @@ -864,7 +870,7 @@ namespace GHelper panelPower.Controls.Add(panelPowerMode); panelPower.Controls.Add(panelPowerModeTItle); panelPower.Dock = DockStyle.Top; - panelPower.Location = new Point(10, 764); + panelPower.Location = new Point(10, 888); panelPower.Margin = new Padding(4); panelPower.Name = "panelPower"; panelPower.Size = new Size(520, 880); @@ -1235,6 +1241,7 @@ namespace GHelper // panelGPU // panelGPU.AutoSize = true; + panelGPU.Controls.Add(panelGPUPower); panelGPU.Controls.Add(panelGPUTemp); panelGPU.Controls.Add(panelGPUBoost); panelGPU.Controls.Add(panelGPUMemory); @@ -1246,7 +1253,7 @@ namespace GHelper panelGPU.Margin = new Padding(4); panelGPU.Name = "panelGPU"; panelGPU.Padding = new Padding(0, 0, 0, 18); - panelGPU.Size = new Size(520, 698); + panelGPU.Size = new Size(520, 822); panelGPU.TabIndex = 44; panelGPU.Visible = false; // @@ -1619,6 +1626,55 @@ namespace GHelper buttonCPU.TextImageRelation = TextImageRelation.ImageBeforeText; buttonCPU.UseVisualStyleBackColor = false; // + // panelGPUPower + // + panelGPUPower.AutoSize = true; + panelGPUPower.AutoSizeMode = AutoSizeMode.GrowAndShrink; + panelGPUPower.Controls.Add(labelGPUPower); + panelGPUPower.Controls.Add(labelGPUPowerTitle); + panelGPUPower.Controls.Add(trackGPUPower); + panelGPUPower.Dock = DockStyle.Top; + panelGPUPower.Location = new Point(0, 680); + panelGPUPower.Margin = new Padding(4); + panelGPUPower.MaximumSize = new Size(0, 124); + panelGPUPower.Name = "panelGPUPower"; + panelGPUPower.Size = new Size(520, 124); + panelGPUPower.TabIndex = 49; + // + // labelGPUPower + // + labelGPUPower.Font = new Font("Segoe UI", 9F, FontStyle.Bold, GraphicsUnit.Point); + labelGPUPower.Location = new Point(374, 14); + labelGPUPower.Margin = new Padding(4, 0, 4, 0); + labelGPUPower.Name = "labelGPUPower"; + labelGPUPower.Size = new Size(124, 32); + labelGPUPower.TabIndex = 44; + labelGPUPower.Text = "105W"; + labelGPUPower.TextAlign = ContentAlignment.TopRight; + // + // labelGPUPowerTitle + // + labelGPUPowerTitle.AutoSize = true; + labelGPUPowerTitle.Location = new Point(10, 14); + labelGPUPowerTitle.Margin = new Padding(4, 0, 4, 0); + labelGPUPowerTitle.Name = "labelGPUPowerTitle"; + labelGPUPowerTitle.Size = new Size(130, 32); + labelGPUPowerTitle.TabIndex = 43; + labelGPUPowerTitle.Text = "GPU Power"; + // + // trackGPUPower + // + trackGPUPower.Location = new Point(6, 48); + trackGPUPower.Margin = new Padding(4, 2, 4, 2); + trackGPUPower.Maximum = 25; + trackGPUPower.Minimum = 5; + trackGPUPower.Name = "trackGPUPower"; + trackGPUPower.Size = new Size(496, 90); + trackGPUPower.TabIndex = 42; + trackGPUPower.TickFrequency = 5; + trackGPUPower.TickStyle = TickStyle.TopLeft; + trackGPUPower.Value = 25; + // // Fans // AutoScaleDimensions = new SizeF(192F, 192F); @@ -1720,6 +1776,9 @@ namespace GHelper ((System.ComponentModel.ISupportInitialize)pictureGPU).EndInit(); panelNav.ResumeLayout(false); tableNav.ResumeLayout(false); + panelGPUPower.ResumeLayout(false); + panelGPUPower.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)trackGPUPower).EndInit(); ResumeLayout(false); PerformLayout(); } @@ -1833,5 +1892,9 @@ namespace GHelper private TrackBar trackSlow; private Panel panelDownload; private RButton buttonDownload; + private Panel panelGPUPower; + private Label labelGPUPower; + private Label labelGPUPowerTitle; + private TrackBar trackGPUPower; } } \ No newline at end of file diff --git a/app/Fans.cs b/app/Fans.cs index 796a02c7..2fea5bcc 100644 --- a/app/Fans.cs +++ b/app/Fans.cs @@ -31,6 +31,8 @@ namespace GHelper FanSensorControl fanSensorControl; + static int gpuPowerBase = 0; + public Fans() { @@ -144,17 +146,22 @@ namespace GHelper trackGPUTemp.Minimum = AsusACPI.MinGPUTemp; trackGPUTemp.Maximum = AsusACPI.MaxGPUTemp; + trackGPUPower.Minimum = AsusACPI.MinGPUPower; + trackGPUPower.Maximum = AsusACPI.MaxGPUPower; + trackGPUClockLimit.Scroll += trackGPUClockLimit_Scroll; trackGPUCore.Scroll += trackGPU_Scroll; trackGPUMemory.Scroll += trackGPU_Scroll; trackGPUBoost.Scroll += trackGPUPower_Scroll; trackGPUTemp.Scroll += trackGPUPower_Scroll; + trackGPUPower.Scroll += trackGPUPower_Scroll; trackGPUCore.MouseUp += TrackGPU_MouseUp; trackGPUMemory.MouseUp += TrackGPU_MouseUp; trackGPUBoost.MouseUp += TrackGPU_MouseUp; trackGPUTemp.MouseUp += TrackGPU_MouseUp; + trackGPUPower.MouseUp += TrackGPU_MouseUp; trackGPUClockLimit.MouseUp += TrackGPU_MouseUp; @@ -541,8 +548,12 @@ namespace GHelper { gpuVisible = buttonGPU.Visible = true; + gpuPowerBase = Program.acpi.DeviceGet(AsusACPI.GPU_POWER_BASE); + int gpuPowerVar = Program.acpi.DeviceGet(AsusACPI.GPU_POWER); + int gpu_boost = AppConfig.GetMode("gpu_boost"); int gpu_temp = AppConfig.GetMode("gpu_temp"); + int gpu_power = AppConfig.GetMode("gpu_power"); int core = AppConfig.GetMode("gpu_core"); int memory = AppConfig.GetMode("gpu_memory"); @@ -550,32 +561,35 @@ namespace GHelper if (gpu_boost < 0) gpu_boost = AsusACPI.MaxGPUBoost; if (gpu_temp < 0) gpu_temp = AsusACPI.MaxGPUTemp; + if (gpu_power < 0) gpu_power = (gpuPowerVar >= 0) ? gpuPowerVar : AsusACPI.MaxGPUPower; if (core == -1) core = 0; if (memory == -1) memory = 0; if (clock_limit == -1) clock_limit = NvidiaGpuControl.MaxClockLimit; - if (nvControl.GetClocks(out int current_core, out int current_memory)) + if (nvControl is not null) { - core = current_core; - memory = current_memory; + if (nvControl.GetClocks(out int current_core, out int current_memory)) + { + core = current_core; + memory = current_memory; + } + + int _clockLimit = nvControl.GetMaxGPUCLock(); + + if (_clockLimit == 0) clock_limit = NvidiaGpuControl.MaxClockLimit; + else if (_clockLimit > 0) clock_limit = _clockLimit; + + try + { + labelGPU.Text = nvControl.FullName; + } + catch + { + + } } - int _clockLimit = nvControl.GetMaxGPUCLock(); - - if (_clockLimit == 0) clock_limit = NvidiaGpuControl.MaxClockLimit; - else if (_clockLimit > 0) clock_limit = _clockLimit; - - try - { - labelGPU.Text = nvControl.FullName; - } - catch - { - - } - - //} trackGPUClockLimit.Value = Math.Max(Math.Min(clock_limit, NvidiaGpuControl.MaxClockLimit), NvidiaGpuControl.MinClockLimit); trackGPUCore.Value = Math.Max(Math.Min(core, NvidiaGpuControl.MaxCoreOffset), NvidiaGpuControl.MinCoreOffset); @@ -584,9 +598,13 @@ namespace GHelper trackGPUBoost.Value = Math.Max(Math.Min(gpu_boost, AsusACPI.MaxGPUBoost), AsusACPI.MinGPUBoost); trackGPUTemp.Value = Math.Max(Math.Min(gpu_temp, AsusACPI.MaxGPUTemp), AsusACPI.MinGPUTemp); + trackGPUPower.Value = Math.Max(Math.Min(gpu_power, AsusACPI.MaxGPUPower), AsusACPI.MinGPUPower); + panelGPUBoost.Visible = (Program.acpi.DeviceGet(AsusACPI.PPT_GPUC0) >= 0); panelGPUTemp.Visible = (Program.acpi.DeviceGet(AsusACPI.PPT_GPUC2) >= 0); + panelGPUPower.Visible = gpuPowerBase > 0 && gpuPowerVar >= 0; + VisualiseGPUSettings(); } @@ -610,6 +628,9 @@ namespace GHelper labelGPUClockLimit.Text = "Default"; else labelGPUClockLimit.Text = $"{trackGPUClockLimit.Value} MHz"; + + labelGPUPower.Text = (gpuPowerBase + trackGPUPower.Value) + "W"; + } private void trackGPUClockLimit_Scroll(object? sender, EventArgs e) @@ -640,6 +661,7 @@ namespace GHelper { AppConfig.SetMode("gpu_boost", trackGPUBoost.Value); AppConfig.SetMode("gpu_temp", trackGPUTemp.Value); + AppConfig.SetMode("gpu_power", trackGPUPower.Value); VisualiseGPUSettings(); } @@ -1089,16 +1111,21 @@ namespace GHelper if (gpuVisible) { + int gpuPowerVar = Program.acpi.DeviceGet(AsusACPI.GPU_POWER); + trackGPUClockLimit.Value = NvidiaGpuControl.MaxClockLimit; trackGPUCore.Value = 0; trackGPUMemory.Value = 0; + trackGPUBoost.Value = AsusACPI.MaxGPUBoost; trackGPUTemp.Value = AsusACPI.MaxGPUTemp; + trackGPUPower.Value = (gpuPowerVar >= 0) ? gpuPowerVar : AsusACPI.MaxGPUPower; AppConfig.SetMode("gpu_clock_limit", trackGPUClockLimit.Value); AppConfig.SetMode("gpu_boost", trackGPUBoost.Value); AppConfig.SetMode("gpu_temp", trackGPUTemp.Value); + AppConfig.SetMode("gpu_power", trackGPUPower.Value); AppConfig.SetMode("gpu_core", trackGPUCore.Value); AppConfig.SetMode("gpu_memory", trackGPUMemory.Value); diff --git a/app/Mode/ModeControl.cs b/app/Mode/ModeControl.cs index cb43f672..0d22adf9 100644 --- a/app/Mode/ModeControl.cs +++ b/app/Mode/ModeControl.cs @@ -346,18 +346,20 @@ namespace GHelper.Mode int gpu_boost = AppConfig.GetMode("gpu_boost"); int gpu_temp = AppConfig.GetMode("gpu_temp"); + int gpu_power = AppConfig.GetMode("gpu_power"); int boostResult = -1; - if (gpu_boost < AsusACPI.MinGPUBoost || gpu_boost > AsusACPI.MaxGPUBoost) return; - if (gpu_temp < AsusACPI.MinGPUTemp || gpu_temp > AsusACPI.MaxGPUTemp) return; + if (gpu_power >= AsusACPI.MinGPUPower && gpu_power <= AsusACPI.MaxGPUPower && Program.acpi.DeviceGet(AsusACPI.GPU_POWER) >= 0) + Program.acpi.DeviceSet(AsusACPI.GPU_POWER, gpu_power, "PowerLimit TGP (GPU VAR)"); - if (Program.acpi.DeviceGet(AsusACPI.PPT_GPUC0) >= 0) - boostResult = Program.acpi.DeviceSet(AsusACPI.PPT_GPUC0, gpu_boost, "PowerLimit C0"); + if (gpu_boost >= AsusACPI.MinGPUBoost && gpu_boost <= AsusACPI.MaxGPUBoost && Program.acpi.DeviceGet(AsusACPI.PPT_GPUC0) >= 0) + boostResult = Program.acpi.DeviceSet(AsusACPI.PPT_GPUC0, gpu_boost, "PowerLimit C0 (GPU BOOST)"); - if (Program.acpi.DeviceGet(AsusACPI.PPT_GPUC2) >= 0) - Program.acpi.DeviceSet(AsusACPI.PPT_GPUC2, gpu_temp, "PowerLimit C2"); + if (gpu_temp >= AsusACPI.MinGPUTemp && gpu_temp <= AsusACPI.MaxGPUTemp && Program.acpi.DeviceGet(AsusACPI.PPT_GPUC2) >= 0) + Program.acpi.DeviceSet(AsusACPI.PPT_GPUC2, gpu_temp, "PowerLimit C2 (GPU TEMP)"); + // Fallback if (boostResult == 0) Program.acpi.DeviceSet(AsusACPI.PPT_GPUC0, gpu_boost, "PowerLimit C0");