mirror of
https://github.com/jkocon/g-helper.git
synced 2026-02-23 13:00:52 +01:00
GPU overclocking fixes
This commit is contained in:
@@ -428,7 +428,7 @@ namespace Starlight.AnimeMatrix
|
|||||||
g.CompositingQuality = CompositingQuality.HighQuality;
|
g.CompositingQuality = CompositingQuality.HighQuality;
|
||||||
g.SmoothingMode = SmoothingMode.AntiAlias;
|
g.SmoothingMode = SmoothingMode.AntiAlias;
|
||||||
|
|
||||||
using (Font font = new Font("Calibri", 16F, GraphicsUnit.Pixel))
|
using (Font font = new Font("Calibri", 14F, GraphicsUnit.Pixel))
|
||||||
{
|
{
|
||||||
SizeF textSize = g.MeasureString(text, font);
|
SizeF textSize = g.MeasureString(text, font);
|
||||||
g.DrawString(text, font, Brushes.White, 4, 0);
|
g.DrawString(text, font, Brushes.White, 4, 0);
|
||||||
|
|||||||
35
app/CustomContextMenu.cs
Normal file
35
app/CustomContextMenu.cs
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
namespace GHelper
|
||||||
|
{
|
||||||
|
class CustomContextMenu : ContextMenuStrip
|
||||||
|
{
|
||||||
|
[DllImport("dwmapi.dll", CharSet = CharSet.Unicode, SetLastError = true)]
|
||||||
|
private static extern long DwmSetWindowAttribute(IntPtr hwnd,
|
||||||
|
DWMWINDOWATTRIBUTE attribute,
|
||||||
|
ref DWM_WINDOW_CORNER_PREFERENCE pvAttribute,
|
||||||
|
uint cbAttribute);
|
||||||
|
|
||||||
|
public CustomContextMenu()
|
||||||
|
{
|
||||||
|
var preference = DWM_WINDOW_CORNER_PREFERENCE.DWMWCP_ROUNDSMALL; //change as you want
|
||||||
|
DwmSetWindowAttribute(Handle,
|
||||||
|
DWMWINDOWATTRIBUTE.DWMWA_WINDOW_CORNER_PREFERENCE,
|
||||||
|
ref preference,
|
||||||
|
sizeof(uint));
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum DWMWINDOWATTRIBUTE
|
||||||
|
{
|
||||||
|
DWMWA_WINDOW_CORNER_PREFERENCE = 33
|
||||||
|
}
|
||||||
|
public enum DWM_WINDOW_CORNER_PREFERENCE
|
||||||
|
{
|
||||||
|
DWMWA_DEFAULT = 0,
|
||||||
|
DWMWCP_DONOTROUND = 1,
|
||||||
|
DWMWCP_ROUND = 2,
|
||||||
|
DWMWCP_ROUNDSMALL = 3,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -131,7 +131,7 @@ namespace GHelper
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Logger.WriteLine(ex.ToString());
|
Logger.WriteLine("F:" + ex.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
InitGPUClocks();
|
InitGPUClocks();
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using NvAPIWrapper.Native;
|
|||||||
using NvAPIWrapper.Native.GPU;
|
using NvAPIWrapper.Native.GPU;
|
||||||
using NvAPIWrapper.Native.GPU.Structures;
|
using NvAPIWrapper.Native.GPU.Structures;
|
||||||
using NvAPIWrapper.Native.Interfaces.GPU;
|
using NvAPIWrapper.Native.Interfaces.GPU;
|
||||||
|
using static NvAPIWrapper.Native.GPU.Structures.PerformanceStates20InfoV1;
|
||||||
|
|
||||||
namespace GHelper.Gpu;
|
namespace GHelper.Gpu;
|
||||||
|
|
||||||
@@ -48,7 +49,13 @@ public class NvidiaGpuControl : IGpuControl
|
|||||||
public void GetClocks(out int core, out int memory)
|
public void GetClocks(out int core, out int memory)
|
||||||
{
|
{
|
||||||
PhysicalGPU internalGpu = _internalGpu!;
|
PhysicalGPU internalGpu = _internalGpu!;
|
||||||
PerformanceStates20InfoV1 states = (PerformanceStates20InfoV1)GPUApi.GetPerformanceStates20(internalGpu.Handle);
|
Logger.WriteLine(internalGpu.FullName);
|
||||||
|
Logger.WriteLine(internalGpu.ArchitectInformation.ToString());
|
||||||
|
|
||||||
|
IPerformanceStates20Info states = GPUApi.GetPerformanceStates20(internalGpu.Handle);
|
||||||
|
|
||||||
|
Logger.WriteLine("IPerformanceStates20Info type : " + states.GetType());
|
||||||
|
|
||||||
core = states.Clocks[PerformanceStateId.P0_3DPerformance][0].FrequencyDeltaInkHz.DeltaValue / 1000;
|
core = states.Clocks[PerformanceStateId.P0_3DPerformance][0].FrequencyDeltaInkHz.DeltaValue / 1000;
|
||||||
memory = states.Clocks[PerformanceStateId.P0_3DPerformance][1].FrequencyDeltaInkHz.DeltaValue / 1000;
|
memory = states.Clocks[PerformanceStateId.P0_3DPerformance][1].FrequencyDeltaInkHz.DeltaValue / 1000;
|
||||||
}
|
}
|
||||||
@@ -68,23 +75,29 @@ public class NvidiaGpuControl : IGpuControl
|
|||||||
if (memory < MinMemoryOffset || memory > MaxMemoryOffset) return 0;
|
if (memory < MinMemoryOffset || memory > MaxMemoryOffset) return 0;
|
||||||
|
|
||||||
PhysicalGPU internalGpu = _internalGpu!;
|
PhysicalGPU internalGpu = _internalGpu!;
|
||||||
PerformanceStates20InfoV1 states = (PerformanceStates20InfoV1)GPUApi.GetPerformanceStates20(internalGpu.Handle);
|
|
||||||
|
|
||||||
states._NumberOfPerformanceStates = 1;
|
var coreClock = new PerformanceStates20ClockEntryV1(PublicClockDomain.Graphics, new PerformanceStates20ParameterDelta(core * 1000));
|
||||||
states._NumberOfClocks = 2;
|
var memoryClock = new PerformanceStates20ClockEntryV1(PublicClockDomain.Memory, new PerformanceStates20ParameterDelta(memory * 1000));
|
||||||
states.PerformanceStates[0]._Clocks[0]._FrequencyDeltaInkHz = new PerformanceStates20ParameterDelta(core * 1000);
|
|
||||||
states.PerformanceStates[0]._Clocks[1]._FrequencyDeltaInkHz = new PerformanceStates20ParameterDelta(memory * 1000);
|
PerformanceStates20ClockEntryV1[] clocks = { coreClock , memoryClock};
|
||||||
|
PerformanceStates20BaseVoltageEntryV1[] voltages = { };
|
||||||
|
|
||||||
|
PerformanceState20[] performanceStates = { new PerformanceState20(PerformanceStateId.P0_3DPerformance, clocks, voltages) };
|
||||||
|
|
||||||
|
var overclock = new PerformanceStates20InfoV1(performanceStates, 2, 0);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
GPUApi.SetPerformanceStates20(internalGpu.Handle, states);
|
GPUApi.SetPerformanceStates20(internalGpu.Handle, overclock);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Logger.WriteLine(ex.Message);
|
Logger.WriteLine(ex.ToString());
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
141
app/Program.cs
141
app/Program.cs
@@ -4,43 +4,12 @@ using System.Diagnostics;
|
|||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Management;
|
using System.Management;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using System.Security.Principal;
|
using System.Security.Principal;
|
||||||
using Tools;
|
using Tools;
|
||||||
|
|
||||||
namespace GHelper
|
namespace GHelper
|
||||||
{
|
{
|
||||||
|
|
||||||
class CustomContextMenu : ContextMenuStrip
|
|
||||||
{
|
|
||||||
[DllImport("dwmapi.dll", CharSet = CharSet.Unicode, SetLastError = true)]
|
|
||||||
private static extern long DwmSetWindowAttribute(IntPtr hwnd,
|
|
||||||
DWMWINDOWATTRIBUTE attribute,
|
|
||||||
ref DWM_WINDOW_CORNER_PREFERENCE pvAttribute,
|
|
||||||
uint cbAttribute);
|
|
||||||
|
|
||||||
public CustomContextMenu()
|
|
||||||
{
|
|
||||||
var preference = DWM_WINDOW_CORNER_PREFERENCE.DWMWCP_ROUNDSMALL; //change as you want
|
|
||||||
DwmSetWindowAttribute(Handle,
|
|
||||||
DWMWINDOWATTRIBUTE.DWMWA_WINDOW_CORNER_PREFERENCE,
|
|
||||||
ref preference,
|
|
||||||
sizeof(uint));
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum DWMWINDOWATTRIBUTE
|
|
||||||
{
|
|
||||||
DWMWA_WINDOW_CORNER_PREFERENCE = 33
|
|
||||||
}
|
|
||||||
public enum DWM_WINDOW_CORNER_PREFERENCE
|
|
||||||
{
|
|
||||||
DWMWA_DEFAULT = 0,
|
|
||||||
DWMWCP_DONOTROUND = 1,
|
|
||||||
DWMWCP_ROUND = 2,
|
|
||||||
DWMWCP_ROUNDSMALL = 3,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static class Program
|
static class Program
|
||||||
{
|
{
|
||||||
public static NotifyIcon trayIcon = new NotifyIcon
|
public static NotifyIcon trayIcon = new NotifyIcon
|
||||||
@@ -64,58 +33,12 @@ namespace GHelper
|
|||||||
|
|
||||||
public static NvidiaGpuControl nvControl = new NvidiaGpuControl();
|
public static NvidiaGpuControl nvControl = new NvidiaGpuControl();
|
||||||
|
|
||||||
static void CheckProcesses()
|
|
||||||
{
|
|
||||||
Process currentProcess = Process.GetCurrentProcess();
|
|
||||||
Process[] processes = Process.GetProcessesByName(currentProcess.ProcessName);
|
|
||||||
|
|
||||||
if (processes.Length > 1)
|
|
||||||
{
|
|
||||||
foreach (Process process in processes)
|
|
||||||
if (process.Id != currentProcess.Id)
|
|
||||||
try
|
|
||||||
{
|
|
||||||
process.Kill();
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Logger.WriteLine(ex.ToString());
|
|
||||||
MessageBox.Show(Properties.Strings.AppAlreadyRunningText, Properties.Strings.AppAlreadyRunning, MessageBoxButtons.OK);
|
|
||||||
Application.Exit();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool IsUserAdministrator()
|
|
||||||
{
|
|
||||||
WindowsIdentity identity = WindowsIdentity.GetCurrent();
|
|
||||||
WindowsPrincipal principal = new WindowsPrincipal(identity);
|
|
||||||
return principal.IsInRole(WindowsBuiltInRole.Administrator);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void RunAsAdmin(string? param = null)
|
|
||||||
{
|
|
||||||
// Check if the current user is an administrator
|
|
||||||
if (!IsUserAdministrator())
|
|
||||||
{
|
|
||||||
ProcessStartInfo startInfo = new ProcessStartInfo();
|
|
||||||
startInfo.UseShellExecute = true;
|
|
||||||
startInfo.WorkingDirectory = Environment.CurrentDirectory;
|
|
||||||
startInfo.FileName = Application.ExecutablePath;
|
|
||||||
startInfo.Arguments = param;
|
|
||||||
startInfo.Verb = "runas";
|
|
||||||
Process.Start(startInfo);
|
|
||||||
//Application.Exit();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// The main entry point for the application
|
// The main entry point for the application
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
|
|
||||||
string? argument = null;
|
string action = "";
|
||||||
if (args.Length > 0) argument = args[0];
|
if (args.Length > 0) action = args[0];
|
||||||
|
|
||||||
Thread.CurrentThread.CurrentUICulture = CultureInfo.CurrentUICulture;
|
Thread.CurrentThread.CurrentUICulture = CultureInfo.CurrentUICulture;
|
||||||
Debug.WriteLine(CultureInfo.CurrentUICulture);
|
Debug.WriteLine(CultureInfo.CurrentUICulture);
|
||||||
@@ -171,9 +94,9 @@ namespace GHelper
|
|||||||
var ghk = new KeyHandler(KeyHandler.SHIFT | KeyHandler.CTRL, Keys.F5, ds);
|
var ghk = new KeyHandler(KeyHandler.SHIFT | KeyHandler.CTRL, Keys.F5, ds);
|
||||||
ghk.Register();
|
ghk.Register();
|
||||||
|
|
||||||
if (Environment.CurrentDirectory.Trim('\\') == Application.StartupPath.Trim('\\'))
|
if (Environment.CurrentDirectory.Trim('\\') == Application.StartupPath.Trim('\\') || action.Length > 0)
|
||||||
{
|
{
|
||||||
SettingsToggle(argument);
|
SettingsToggle(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
Application.Run();
|
Application.Run();
|
||||||
@@ -317,7 +240,10 @@ namespace GHelper
|
|||||||
settingsForm.BeginInvoke(settingsForm.CyclePerformanceMode);
|
settingsForm.BeginInvoke(settingsForm.CyclePerformanceMode);
|
||||||
break;
|
break;
|
||||||
case "ghelper":
|
case "ghelper":
|
||||||
settingsForm.BeginInvoke(SettingsToggle);
|
settingsForm.BeginInvoke(delegate
|
||||||
|
{
|
||||||
|
SettingsToggle();
|
||||||
|
});
|
||||||
break;
|
break;
|
||||||
case "custom":
|
case "custom":
|
||||||
CustomKey(name);
|
CustomKey(name);
|
||||||
@@ -357,7 +283,7 @@ namespace GHelper
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void SettingsToggle(string? argument = null)
|
static void SettingsToggle(string action = "")
|
||||||
{
|
{
|
||||||
if (settingsForm.Visible)
|
if (settingsForm.Visible)
|
||||||
settingsForm.Hide();
|
settingsForm.Hide();
|
||||||
@@ -366,7 +292,7 @@ namespace GHelper
|
|||||||
settingsForm.Show();
|
settingsForm.Show();
|
||||||
settingsForm.Activate();
|
settingsForm.Activate();
|
||||||
|
|
||||||
if (argument == "gpu")
|
if (action == "gpu")
|
||||||
{
|
{
|
||||||
nvControl.SetClocksFromConfig();
|
nvControl.SetClocksFromConfig();
|
||||||
settingsForm.FansToggle();
|
settingsForm.FansToggle();
|
||||||
@@ -394,6 +320,53 @@ namespace GHelper
|
|||||||
NativeMethods.UnregisterPowerSettingNotification(unRegPowerNotify);
|
NativeMethods.UnregisterPowerSettingNotification(unRegPowerNotify);
|
||||||
Application.Exit();
|
Application.Exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void CheckProcesses()
|
||||||
|
{
|
||||||
|
Process currentProcess = Process.GetCurrentProcess();
|
||||||
|
Process[] processes = Process.GetProcessesByName(currentProcess.ProcessName);
|
||||||
|
|
||||||
|
if (processes.Length > 1)
|
||||||
|
{
|
||||||
|
foreach (Process process in processes)
|
||||||
|
if (process.Id != currentProcess.Id)
|
||||||
|
try
|
||||||
|
{
|
||||||
|
process.Kill();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Logger.WriteLine(ex.ToString());
|
||||||
|
MessageBox.Show(Properties.Strings.AppAlreadyRunningText, Properties.Strings.AppAlreadyRunning, MessageBoxButtons.OK);
|
||||||
|
Application.Exit();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool IsUserAdministrator()
|
||||||
|
{
|
||||||
|
WindowsIdentity identity = WindowsIdentity.GetCurrent();
|
||||||
|
WindowsPrincipal principal = new WindowsPrincipal(identity);
|
||||||
|
return principal.IsInRole(WindowsBuiltInRole.Administrator);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void RunAsAdmin(string? param = null)
|
||||||
|
{
|
||||||
|
// Check if the current user is an administrator
|
||||||
|
if (!IsUserAdministrator())
|
||||||
|
{
|
||||||
|
ProcessStartInfo startInfo = new ProcessStartInfo();
|
||||||
|
startInfo.UseShellExecute = true;
|
||||||
|
startInfo.WorkingDirectory = Environment.CurrentDirectory;
|
||||||
|
startInfo.FileName = Application.ExecutablePath;
|
||||||
|
startInfo.Arguments = param;
|
||||||
|
startInfo.Verb = "runas";
|
||||||
|
Process.Start(startInfo);
|
||||||
|
//Application.Exit();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user