Check if AMD GPU scaling is enabled to allow changing resolution by default

This commit is contained in:
Kamil Trzciński 2022-11-19 21:28:28 +01:00
parent 85c8ee379f
commit a7f16dbde6
7 changed files with 61 additions and 10 deletions

View file

@ -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;
}
}
}
}

View file

@ -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)

View file

@ -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();
},

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.