diff --git a/PowerControl/Helpers/AMD.cs b/PowerControl/Helpers/AMD.cs new file mode 100644 index 0000000..3dabf67 --- /dev/null +++ b/PowerControl/Helpers/AMD.cs @@ -0,0 +1,44 @@ +using Microsoft.Win32; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PowerControl.Helpers +{ + internal class AMD + { + // TODO: This CLSID is likely to change over time and be broken + // pnputil /enum-devices /class Display + const String GPUDriverKey = "SYSTEM\\CurrentControlSet\\Control\\Class\\{4d36e968-e325-11ce-bfc1-08002be10318}\\0000"; + const String DriverDesc = "DriverDesc"; + const String ExpectedDriverDesc = "AMD Custom GPU 0405"; + const String GPUScaling = "GPUScaling00"; + + internal static bool IsGPUScalingEnabled() + { + try + { + var registry = Registry.LocalMachine.OpenSubKey(GPUDriverKey); + if (registry == null) + return false; + + var driverDesc = registry.GetValue(DriverDesc); + if (driverDesc is String && ((string)driverDesc) != ExpectedDriverDesc) + return false; + + var scalingBytes = registry.GetValue(GPUScaling); + if (scalingBytes is not byte[]) + return false; + + var scaling = BitConverter.ToUInt32((byte[])scalingBytes); + return scaling == 1; + } + catch + { + return false; + } + } + } +} diff --git a/PowerControl/Helpers/WindowsSettingsBrightnessController.cs b/PowerControl/Helpers/WindowsSettingsBrightnessController.cs index cd8ffb9..1cb498c 100644 --- a/PowerControl/Helpers/WindowsSettingsBrightnessController.cs +++ b/PowerControl/Helpers/WindowsSettingsBrightnessController.cs @@ -11,16 +11,23 @@ namespace PowerControl.Helpers { public static int Get() { - using var mclass = new ManagementClass("WmiMonitorBrightness") + try { - Scope = new ManagementScope(@"\\.\root\wmi") - }; - using var instances = mclass.GetInstances(); - foreach (ManagementObject instance in instances) - { - return (byte)instance.GetPropertyValue("CurrentBrightness"); + using var mclass = new ManagementClass("WmiMonitorBrightness") + { + Scope = new ManagementScope(@"\\.\root\wmi") + }; + using var instances = mclass.GetInstances(); + foreach (ManagementObject instance in instances) + { + return (byte)instance.GetPropertyValue("CurrentBrightness"); + } + return -1; + } + catch + { + return -1; } - return -1; } public static int Get(double roundValue = 10.0) diff --git a/PowerControl/MenuStack.cs b/PowerControl/MenuStack.cs index 8d58d76..0f44734 100644 --- a/PowerControl/MenuStack.cs +++ b/PowerControl/MenuStack.cs @@ -56,7 +56,7 @@ namespace PowerControl Name = "Resolution", ApplyDelay = 1000, ResetValue = () => { - if (!Settings.Default.EnableExperimentalFeatures) + if (!AMD.IsGPUScalingEnabled() && !Settings.Default.EnableExperimentalFeatures) return null; return Helpers.PhysicalMonitorBrightnessController.GetAllResolutions().Last(); }, @@ -69,7 +69,7 @@ namespace PowerControl }, CurrentValue = delegate() { - if (!Settings.Default.EnableExperimentalFeatures) + if (!AMD.IsGPUScalingEnabled() && !Settings.Default.EnableExperimentalFeatures) return null; return Helpers.PhysicalMonitorBrightnessController.GetResolution(); }, diff --git a/dump/gpu_scaling/DisableGPUScale.reg b/dump/gpu_scaling/DisableGPUScale.reg new file mode 100644 index 0000000..ca0a766 Binary files /dev/null and b/dump/gpu_scaling/DisableGPUScale.reg differ diff --git a/dump/gpu_scaling/EnableGPUScaleAspect.reg b/dump/gpu_scaling/EnableGPUScaleAspect.reg new file mode 100644 index 0000000..531876a Binary files /dev/null and b/dump/gpu_scaling/EnableGPUScaleAspect.reg differ diff --git a/dump/gpu_scaling/EnableGPUScaleCenter.reg b/dump/gpu_scaling/EnableGPUScaleCenter.reg new file mode 100644 index 0000000..22b4110 Binary files /dev/null and b/dump/gpu_scaling/EnableGPUScaleCenter.reg differ diff --git a/dump/gpu_scaling/EnableGPUScaleFull.reg b/dump/gpu_scaling/EnableGPUScaleFull.reg new file mode 100644 index 0000000..112e144 Binary files /dev/null and b/dump/gpu_scaling/EnableGPUScaleFull.reg differ