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.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);
|
||||
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)
|
||||
{
|
||||
Logger.WriteLine(ex.ToString());
|
||||
Logger.WriteLine("F:" + ex.ToString());
|
||||
}
|
||||
|
||||
InitGPUClocks();
|
||||
|
||||
@@ -3,6 +3,7 @@ using NvAPIWrapper.Native;
|
||||
using NvAPIWrapper.Native.GPU;
|
||||
using NvAPIWrapper.Native.GPU.Structures;
|
||||
using NvAPIWrapper.Native.Interfaces.GPU;
|
||||
using static NvAPIWrapper.Native.GPU.Structures.PerformanceStates20InfoV1;
|
||||
|
||||
namespace GHelper.Gpu;
|
||||
|
||||
@@ -48,7 +49,13 @@ public class NvidiaGpuControl : IGpuControl
|
||||
public void GetClocks(out int core, out int memory)
|
||||
{
|
||||
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;
|
||||
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;
|
||||
|
||||
PhysicalGPU internalGpu = _internalGpu!;
|
||||
PerformanceStates20InfoV1 states = (PerformanceStates20InfoV1)GPUApi.GetPerformanceStates20(internalGpu.Handle);
|
||||
|
||||
states._NumberOfPerformanceStates = 1;
|
||||
states._NumberOfClocks = 2;
|
||||
states.PerformanceStates[0]._Clocks[0]._FrequencyDeltaInkHz = new PerformanceStates20ParameterDelta(core * 1000);
|
||||
states.PerformanceStates[0]._Clocks[1]._FrequencyDeltaInkHz = new PerformanceStates20ParameterDelta(memory * 1000);
|
||||
var coreClock = new PerformanceStates20ClockEntryV1(PublicClockDomain.Graphics, new PerformanceStates20ParameterDelta(core * 1000));
|
||||
var memoryClock = new PerformanceStates20ClockEntryV1(PublicClockDomain.Memory, 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
|
||||
{
|
||||
GPUApi.SetPerformanceStates20(internalGpu.Handle, states);
|
||||
GPUApi.SetPerformanceStates20(internalGpu.Handle, overclock);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.WriteLine(ex.Message);
|
||||
Logger.WriteLine(ex.ToString());
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
141
app/Program.cs
141
app/Program.cs
@@ -4,43 +4,12 @@ using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.Management;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security.Principal;
|
||||
using Tools;
|
||||
|
||||
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
|
||||
{
|
||||
public static NotifyIcon trayIcon = new NotifyIcon
|
||||
@@ -64,58 +33,12 @@ namespace GHelper
|
||||
|
||||
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
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
|
||||
string? argument = null;
|
||||
if (args.Length > 0) argument = args[0];
|
||||
string action = "";
|
||||
if (args.Length > 0) action = args[0];
|
||||
|
||||
Thread.CurrentThread.CurrentUICulture = CultureInfo.CurrentUICulture;
|
||||
Debug.WriteLine(CultureInfo.CurrentUICulture);
|
||||
@@ -171,9 +94,9 @@ namespace GHelper
|
||||
var ghk = new KeyHandler(KeyHandler.SHIFT | KeyHandler.CTRL, Keys.F5, ds);
|
||||
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();
|
||||
@@ -317,7 +240,10 @@ namespace GHelper
|
||||
settingsForm.BeginInvoke(settingsForm.CyclePerformanceMode);
|
||||
break;
|
||||
case "ghelper":
|
||||
settingsForm.BeginInvoke(SettingsToggle);
|
||||
settingsForm.BeginInvoke(delegate
|
||||
{
|
||||
SettingsToggle();
|
||||
});
|
||||
break;
|
||||
case "custom":
|
||||
CustomKey(name);
|
||||
@@ -357,7 +283,7 @@ namespace GHelper
|
||||
|
||||
}
|
||||
|
||||
static void SettingsToggle(string? argument = null)
|
||||
static void SettingsToggle(string action = "")
|
||||
{
|
||||
if (settingsForm.Visible)
|
||||
settingsForm.Hide();
|
||||
@@ -366,7 +292,7 @@ namespace GHelper
|
||||
settingsForm.Show();
|
||||
settingsForm.Activate();
|
||||
|
||||
if (argument == "gpu")
|
||||
if (action == "gpu")
|
||||
{
|
||||
nvControl.SetClocksFromConfig();
|
||||
settingsForm.FansToggle();
|
||||
@@ -394,6 +320,53 @@ namespace GHelper
|
||||
NativeMethods.UnregisterPowerSettingNotification(unRegPowerNotify);
|
||||
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