Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GPU Power limit slider for 2024 models #2142

Merged
merged 6 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions app/AsusACPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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_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;
Expand Down Expand Up @@ -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 = 50;

public const int MinGPUTemp = 75;
public const int MaxGPUTemp = 87;

Expand Down Expand Up @@ -285,6 +291,7 @@ public AsusACPI()
if (AppConfig.IsIntelHX())
{
MaxTotal = 175;
MaxGPUPower = 70;
}

if (AppConfig.DynamicBoost5())
Expand Down
6 changes: 6 additions & 0 deletions app/Display/ScreenNative.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class DeviceComparer : IComparer
{
public int Compare(object x, object y)

Check warning on line 10 in app/Display/ScreenNative.cs

View workflow job for this annotation

GitHub Actions / build

Nullability of reference types in type of parameter 'x' of 'int DeviceComparer.Compare(object x, object y)' doesn't match implicitly implemented member 'int IComparer.Compare(object? x, object? y)' (possibly because of nullability attributes).

Check warning on line 10 in app/Display/ScreenNative.cs

View workflow job for this annotation

GitHub Actions / build

Nullability of reference types in type of parameter 'y' of 'int DeviceComparer.Compare(object x, object y)' doesn't match implicitly implemented member 'int IComparer.Compare(object? x, object? y)' (possibly because of nullability attributes).
{
uint displayX = ((DISPLAYCONFIG_TARGET_DEVICE_NAME)x).connectorInstance;
uint displayY = ((DISPLAYCONFIG_TARGET_DEVICE_NAME)y).connectorInstance;
Expand All @@ -23,7 +23,7 @@

class ScreenComparer : IComparer
{
public int Compare(object x, object y)

Check warning on line 26 in app/Display/ScreenNative.cs

View workflow job for this annotation

GitHub Actions / build

Nullability of reference types in type of parameter 'x' of 'int ScreenComparer.Compare(object x, object y)' doesn't match implicitly implemented member 'int IComparer.Compare(object? x, object? y)' (possibly because of nullability attributes).

Check warning on line 26 in app/Display/ScreenNative.cs

View workflow job for this annotation

GitHub Actions / build

Nullability of reference types in type of parameter 'y' of 'int ScreenComparer.Compare(object x, object y)' doesn't match implicitly implemented member 'int IComparer.Compare(object? x, object? y)' (possibly because of nullability attributes).
{
int displayX = Int32.Parse(((Screen)x).DeviceName.Replace(@"\\.\DISPLAY", ""));
int displayY = Int32.Parse(((Screen)y).DeviceName.Replace(@"\\.\DISPLAY", ""));
Expand All @@ -42,6 +42,12 @@
[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
{
Expand Down
8 changes: 5 additions & 3 deletions app/Extra.cs
Original file line number Diff line number Diff line change
Expand Up @@ -398,17 +398,19 @@ public Extra()
InitServices();
InitHibernate();

//InitACPITesting();
InitACPITesting();

}

private void InitACPITesting()
{
if (!AppConfig.Is("debug")) return;

pictureScan.Visible = true;
panelACPI.Visible = true;

textACPICommand.Text = "120075";
textACPIParam.Text = "1";
textACPICommand.Text = "120098";
textACPIParam.Text = "25";

buttonACPISend.Click += ButtonACPISend_Click;
pictureScan.Click += PictureScan_Click;
Expand Down
73 changes: 68 additions & 5 deletions app/Fans.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 45 additions & 18 deletions app/Fans.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public partial class Fans : RForm

FanSensorControl fanSensorControl;

static int gpuPowerBase = 0;

public Fans()
{

Expand Down Expand Up @@ -144,17 +146,22 @@ public Fans()
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;

Expand Down Expand Up @@ -541,41 +548,48 @@ public void InitGPU()
{
gpuVisible = buttonGPU.Visible = true;

gpuPowerBase = Program.acpi.DeviceGet(AsusACPI.GPU_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");
int clock_limit = AppConfig.GetMode("gpu_clock_limit");

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();
int _clockLimit = nvControl.GetMaxGPUCLock();

if (_clockLimit == 0) clock_limit = NvidiaGpuControl.MaxClockLimit;
else if (_clockLimit > 0) clock_limit = _clockLimit;
if (_clockLimit == 0) clock_limit = NvidiaGpuControl.MaxClockLimit;
else if (_clockLimit > 0) clock_limit = _clockLimit;

try
{
labelGPU.Text = nvControl.FullName;
}
catch
{
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);
Expand All @@ -584,9 +598,13 @@ public void InitGPU()
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();

}
Expand All @@ -610,6 +628,9 @@ private void VisualiseGPUSettings()
labelGPUClockLimit.Text = "Default";
else
labelGPUClockLimit.Text = $"{trackGPUClockLimit.Value} MHz";

labelGPUPower.Text = (gpuPowerBase + trackGPUPower.Value) + "W";

}

private void trackGPUClockLimit_Scroll(object? sender, EventArgs e)
Expand Down Expand Up @@ -640,6 +661,7 @@ private void trackGPUPower_Scroll(object? sender, EventArgs e)
{
AppConfig.SetMode("gpu_boost", trackGPUBoost.Value);
AppConfig.SetMode("gpu_temp", trackGPUTemp.Value);
AppConfig.SetMode("gpu_power", trackGPUPower.Value);

VisualiseGPUSettings();
}
Expand Down Expand Up @@ -1089,19 +1111,24 @@ private void ButtonReset_Click(object? sender, EventArgs e)

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;

AppConfig.SetMode("gpu_clock_limit", trackGPUClockLimit.Value);
trackGPUPower.Value = (gpuPowerVar >= 0) ? gpuPowerVar : AsusACPI.MaxGPUPower;

AppConfig.SetMode("gpu_boost", trackGPUBoost.Value);
AppConfig.SetMode("gpu_temp", trackGPUTemp.Value);

AppConfig.SetMode("gpu_core", trackGPUCore.Value);
AppConfig.SetMode("gpu_memory", trackGPUMemory.Value);
AppConfig.RemoveMode("gpu_power");

AppConfig.RemoveMode("gpu_clock_limit");
AppConfig.RemoveMode("gpu_core");
AppConfig.RemoveMode("gpu_memory");

VisualiseGPUSettings();
modeControl.SetGPUClocks(true);
Expand Down
2 changes: 1 addition & 1 deletion app/GHelper.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<PlatformTarget>AnyCPU</PlatformTarget>
<ProduceReferenceAssembly>False</ProduceReferenceAssembly>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<AssemblyVersion>0.155</AssemblyVersion>
<AssemblyVersion>0.156</AssemblyVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand Down
Loading
Loading