This commit is contained in:
PhyxionNL
2021-08-19 23:07:19 +02:00
committed by GitHub
parent 8ff92f3b08
commit e061f72229
4 changed files with 81 additions and 42 deletions
@@ -27,6 +27,29 @@ namespace LibreHardwareMonitor.Hardware
return null;
}
public static string GetActualDeviceIdentifier(string deviceIdentifier)
{
string identifier = deviceIdentifier;
// For example:
// \\?\ROOT#BasicRender#0000#{1ca05180-a699-450a-9a0c-de4fbe3ddd89} --> ROOT\BasicRender\0000
// \\?\PCI#VEN_1002&DEV_731F&SUBSYS_57051682&REV_C4#6&e539058&0&00000019#{1ca05180-a699-450a-9a0c-de4fbe3ddd89} --> PCI\VEN_1002&DEV_731F&SUBSYS_57051682&REV_C4\6&e539058&0&00000019
if (identifier.StartsWith(@"\\?\"))
identifier = identifier.Substring(4);
if (identifier.Length > 0 && identifier[identifier.Length - 1] == '}')
{
int lastIndex = identifier.LastIndexOf('{');
if (lastIndex > 0)
identifier = identifier.Substring(0, lastIndex - 1);
}
identifier = identifier.Replace('#', '\\');
return identifier;
}
public static bool GetDeviceInfoByIdentifier(string deviceIdentifier, out D3DDeviceInfo deviceInfo)
{
deviceInfo = new D3DDeviceInfo();
+18 -9
View File
@@ -49,7 +49,7 @@ namespace LibreHardwareMonitor.Hardware.Gpu
private readonly Sensor _temperaturePlx;
private readonly Sensor _temperatureSoC;
private readonly Sensor _temperatureVddc;
private readonly string _windowsDeviceName;
private readonly string _d3dDeviceId;
public AmdGpu(AtiAdlxx.ADLAdapterInfo adapterInfo, ISettings settings)
: base(adapterInfo.AdapterName.Trim(), new Identifier("gpu-amd", adapterInfo.AdapterIndex.ToString(CultureInfo.InvariantCulture)), settings)
@@ -91,16 +91,18 @@ namespace LibreHardwareMonitor.Hardware.Gpu
if (!Software.OperatingSystem.IsUnix)
{
string convertedPnpString = adapterInfo.PNPString.Replace("\\", "#");
string[] deviceIdentifiers = D3DDisplayDevice.GetDeviceIdentifiers();
if (deviceIdentifiers != null)
string[] deviceIds = D3DDisplayDevice.GetDeviceIdentifiers();
if (deviceIds != null)
{
foreach (string deviceIdentifier in deviceIdentifiers)
foreach (string deviceId in deviceIds)
{
if (deviceIdentifier.IndexOf(convertedPnpString, StringComparison.OrdinalIgnoreCase) != -1 &&
D3DDisplayDevice.GetDeviceInfoByIdentifier(deviceIdentifier, out D3DDisplayDevice.D3DDeviceInfo deviceInfo))
string actualDeviceId = D3DDisplayDevice.GetActualDeviceIdentifier(deviceId);
if ((actualDeviceId.IndexOf(adapterInfo.PNPString, StringComparison.OrdinalIgnoreCase) != -1 ||
adapterInfo.PNPString.IndexOf(actualDeviceId, StringComparison.OrdinalIgnoreCase) != -1) &&
D3DDisplayDevice.GetDeviceInfoByIdentifier(deviceId, out D3DDisplayDevice.D3DDeviceInfo deviceInfo))
{
_windowsDeviceName = deviceIdentifier;
_d3dDeviceId = deviceId;
int nodeSensorIndex = 2;
int memorySensorIndex = 0;
@@ -220,7 +222,7 @@ namespace LibreHardwareMonitor.Hardware.Gpu
public override void Update()
{
if (_windowsDeviceName != null && D3DDisplayDevice.GetDeviceInfoByIdentifier(_windowsDeviceName, out D3DDisplayDevice.D3DDeviceInfo deviceInfo))
if (_d3dDeviceId != null && D3DDisplayDevice.GetDeviceInfoByIdentifier(_d3dDeviceId, out D3DDisplayDevice.D3DDeviceInfo deviceInfo))
{
_gpuDedicatedMemoryUsage.Value = 1f * deviceInfo.GpuDedicatedUsed / 1024 / 1024;
_gpuSharedMemoryUsage.Value = 1f * deviceInfo.GpuSharedUsed / 1024 / 1024;
@@ -739,6 +741,13 @@ namespace LibreHardwareMonitor.Hardware.Gpu
r.AppendLine();
}
if (_d3dDeviceId != null)
{
r.AppendLine("D3D");
r.AppendLine();
r.AppendLine(" Id: " + _d3dDeviceId);
}
return r.ToString();
}
}
@@ -7,6 +7,7 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using LibreHardwareMonitor.Interop;
@@ -41,8 +42,11 @@ namespace LibreHardwareMonitor.Hardware.Gpu
if (numberOfAdapters > 0)
{
List<AmdGpu> potentialHardware = new();
AtiAdlxx.ADLAdapterInfo[] adapterInfo = new AtiAdlxx.ADLAdapterInfo[numberOfAdapters];
if (AtiAdlxx.ADL_Adapter_AdapterInfo_Get(adapterInfo) == AtiAdlxx.ADLStatus.ADL_OK)
{
for (int i = 0; i < numberOfAdapters; i++)
{
AtiAdlxx.ADL_Adapter_Active_Get(adapterInfo[i].AdapterIndex, out int isActive);
@@ -56,6 +60,8 @@ namespace LibreHardwareMonitor.Hardware.Gpu
_report.AppendLine(adapterInfo[i].AdapterName);
_report.Append("UDID: ");
_report.AppendLine(adapterInfo[i].UDID);
_report.Append("PNPString: ");
_report.AppendLine(adapterInfo[i].PNPString);
_report.Append("Present: ");
_report.AppendLine(adapterInfo[i].Present.ToString(CultureInfo.InvariantCulture));
_report.Append("VendorID: 0x");
@@ -70,21 +76,18 @@ namespace LibreHardwareMonitor.Hardware.Gpu
_report.AppendLine(adapterId.ToString("X", CultureInfo.InvariantCulture));
if (!string.IsNullOrEmpty(adapterInfo[i].UDID) && adapterInfo[i].VendorID == AtiAdlxx.ATI_VENDOR_ID)
{
bool found = false;
foreach (AmdGpu gpu in _hardware)
if (gpu.BusNumber == adapterInfo[i].BusNumber && gpu.DeviceNumber == adapterInfo[i].DeviceNumber)
{
found = true;
break;
}
if (!found)
_hardware.Add(new AmdGpu(adapterInfo[i], settings));
}
potentialHardware.Add(new AmdGpu(adapterInfo[i], settings));
_report.AppendLine();
}
}
foreach (IGrouping<string, AmdGpu> amdGpus in potentialHardware.GroupBy(x => $"{x.BusNumber}-{x.DeviceNumber}"))
{
var amdGpu = amdGpus.OrderByDescending(x => x.Sensors.Length).FirstOrDefault();
if (amdGpu != null)
_hardware.Add(amdGpu);
}
}
}
}
@@ -41,7 +41,7 @@ namespace LibreHardwareMonitor.Hardware.Gpu
private readonly Sensor[] _powers;
private readonly Sensor _powerUsage;
private readonly Sensor[] _temperatures;
private readonly string _windowsDeviceName;
private readonly string _d3dDeviceId;
public NvidiaGpu(int adapterIndex, PhysicalGPU physicalGpu, ISettings settings)
: base(GetName(physicalGpu),
@@ -217,23 +217,28 @@ namespace LibreHardwareMonitor.Hardware.Gpu
if (pciInfo is { } pci)
{
string[] deviceIdentifiers = D3DDisplayDevice.GetDeviceIdentifiers();
if (deviceIdentifiers != null)
string[] deviceIds = D3DDisplayDevice.GetDeviceIdentifiers();
if (deviceIds != null)
{
foreach (string deviceIdentifier in deviceIdentifiers)
foreach (string deviceId in deviceIds)
{
if (deviceIdentifier.IndexOf("VEN_" + pci.pciVendorId.ToString("X"), StringComparison.OrdinalIgnoreCase) != -1 &&
deviceIdentifier.IndexOf("DEV_" + pci.pciDeviceId.ToString("X"), StringComparison.OrdinalIgnoreCase) != -1 &&
deviceIdentifier.IndexOf("SUBSYS_" + pci.pciSubSystemId.ToString("X"), StringComparison.OrdinalIgnoreCase) != -1)
if (deviceId.IndexOf("VEN_" + pci.pciVendorId.ToString("X"), StringComparison.OrdinalIgnoreCase) != -1 &&
deviceId.IndexOf("DEV_" + pci.pciDeviceId.ToString("X"), StringComparison.OrdinalIgnoreCase) != -1 &&
deviceId.IndexOf("SUBSYS_" + pci.pciSubSystemId.ToString("X"), StringComparison.OrdinalIgnoreCase) != -1)
{
bool isMatch = false;
string actualDeviceId = D3DDisplayDevice.GetActualDeviceIdentifier(deviceId);
try
{
if (Registry.GetValue(@"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\nvlddmkm\Enum", adapterIndex.ToString(), null) is string adapterPnpId)
{
if (deviceIdentifier.IndexOf(adapterPnpId.Replace('\\', '#'), StringComparison.OrdinalIgnoreCase) != -1)
if (actualDeviceId.IndexOf(adapterPnpId, StringComparison.OrdinalIgnoreCase) != -1 ||
adapterPnpId.IndexOf(actualDeviceId, StringComparison.OrdinalIgnoreCase) != -1)
{
isMatch = true;
}
}
}
catch
@@ -245,15 +250,7 @@ namespace LibreHardwareMonitor.Hardware.Gpu
{
try
{
string path = deviceIdentifier;
if (path.StartsWith(@"\\?\"))
path = path.Substring(4);
path = path.Replace('#', '\\');
int index = path.IndexOf('{');
if (index != -1)
path = path.Substring(0, index);
string path = actualDeviceId;
path = @"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\" + path;
if (Registry.GetValue(path, "LocationInformation", null) is string locationInformation)
@@ -261,7 +258,7 @@ namespace LibreHardwareMonitor.Hardware.Gpu
// For example:
// @System32\drivers\pci.sys,#65536;PCI bus %1, device %2, function %3;(38,0,0)
index = locationInformation.IndexOf('(');
int index = locationInformation.IndexOf('(');
if (index != -1)
{
index++;
@@ -282,12 +279,12 @@ namespace LibreHardwareMonitor.Hardware.Gpu
}
}
if (isMatch && D3DDisplayDevice.GetDeviceInfoByIdentifier(deviceIdentifier, out D3DDisplayDevice.D3DDeviceInfo deviceInfo))
if (isMatch && D3DDisplayDevice.GetDeviceInfoByIdentifier(deviceId, out D3DDisplayDevice.D3DDeviceInfo deviceInfo))
{
int nodeSensorIndex = (_loads?.Length ?? 0) + (_powers?.Length ?? 0);
int memorySensorIndex = 3; // There are three normal GPU memory sensors.
_windowsDeviceName = deviceIdentifier;
_d3dDeviceId = deviceId;
_gpuDedicatedMemoryUsage = new Sensor("D3D Dedicated Memory Used", memorySensorIndex++, SensorType.SmallData, this, settings);
_gpuSharedMemoryUsage = new Sensor("D3D Shared Memory Used", memorySensorIndex, SensorType.SmallData, this, settings);
@@ -345,7 +342,7 @@ namespace LibreHardwareMonitor.Hardware.Gpu
public override void Update()
{
if (_windowsDeviceName != null && D3DDisplayDevice.GetDeviceInfoByIdentifier(_windowsDeviceName, out D3DDisplayDevice.D3DDeviceInfo deviceInfo))
if (_d3dDeviceId != null && D3DDisplayDevice.GetDeviceInfoByIdentifier(_d3dDeviceId, out D3DDisplayDevice.D3DDeviceInfo deviceInfo))
{
_gpuDedicatedMemoryUsage.Value = 1f * deviceInfo.GpuDedicatedUsed / 1024 / 1024;
_gpuSharedMemoryUsage.Value = 1f * deviceInfo.GpuSharedUsed / 1024 / 1024;
@@ -611,6 +608,13 @@ namespace LibreHardwareMonitor.Hardware.Gpu
catch (Exception e) when (e is NVIDIAApiException or NVIDIANotSupportedException)
{ }
if (_d3dDeviceId != null)
{
r.AppendLine("D3D");
r.AppendLine();
r.AppendLine(" Id: " + _d3dDeviceId);
}
return r.ToString();
}