Use CsWin32 (#1912)
* Use CsWin32 * Update LibreHardwareMonitorLib/Hardware/Cpu/CpuLoad.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update LibreHardwareMonitorLib/Hardware/Battery/BatteryGroup.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update pull requests.yml * Update pull requests.yml * Update master.yml * A couple more to CsWin32 * Restore PawnIO defaults Fixes #1910 --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
+1
-1
@@ -11,7 +11,7 @@ insert_final_newline = true
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
trim_trailing_whitespace = true
|
||||
end_of_line = lf
|
||||
end_of_line = crlf
|
||||
|
||||
[project.json]
|
||||
indent_size = 2
|
||||
|
||||
@@ -31,10 +31,10 @@ jobs:
|
||||
} | Set-Content Directory.Build.props
|
||||
|
||||
- name: NuGet restore
|
||||
run: nuget restore LibreHardwareMonitor.sln
|
||||
run: dotnet restore LibreHardwareMonitor.sln
|
||||
|
||||
- name: Build
|
||||
run: msbuild LibreHardwareMonitor.sln -p:Configuration=Release -m
|
||||
run: dotnet build LibreHardwareMonitor.sln --configuration Release --no-restore
|
||||
|
||||
- name: Publish net472
|
||||
uses: actions/upload-artifact@v4
|
||||
|
||||
@@ -30,11 +30,11 @@ jobs:
|
||||
else { $_ -replace $m.Value, ("<Version>{0}.{1}.{2}-ci${{ github.run_number }}</Version>" -f $m.Groups[1].Value,$m.Groups[2].Value,([convert]::ToInt32($m.Groups[3].Value)+1)); }
|
||||
} | Set-Content Directory.Build.props
|
||||
|
||||
- name: NuGet restore
|
||||
run: nuget restore LibreHardwareMonitor.sln
|
||||
- name: Restore packages
|
||||
run: dotnet restore LibreHardwareMonitor.sln
|
||||
|
||||
- name: Build
|
||||
run: msbuild LibreHardwareMonitor.sln -p:Configuration=Release -m
|
||||
run: dotnet build LibreHardwareMonitor.sln --configuration Release --no-restore
|
||||
|
||||
- name: Publish net472
|
||||
uses: actions/upload-artifact@v4
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<GenerateResourceUsePreserializedResources>true</GenerateResourceUsePreserializedResources>
|
||||
<Platforms>x64</Platforms>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<ProductVersion>9.0.30729</ProductVersion>
|
||||
@@ -13,11 +14,11 @@
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<OutputPath>..\bin\$(Configuration)\</OutputPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<DebugType>full</DebugType>
|
||||
<DefineConstants>TRACE;DEBUG;PERF_TEST</DefineConstants>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
|
||||
+16
-16
@@ -1,7 +1,7 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 16.0.29306.81
|
||||
# Visual Studio Version 18
|
||||
VisualStudioVersion = 18.0.11018.127 d18.0
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LibreHardwareMonitorLib", "LibreHardwareMonitorLib\LibreHardwareMonitorLib.csproj", "{B0397530-545A-471D-BB74-027AE456DF1A}"
|
||||
EndProject
|
||||
@@ -22,22 +22,22 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
Debug|x64 = Debug|x64
|
||||
Release|x64 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{B0397530-545A-471D-BB74-027AE456DF1A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{B0397530-545A-471D-BB74-027AE456DF1A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{B0397530-545A-471D-BB74-027AE456DF1A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{B0397530-545A-471D-BB74-027AE456DF1A}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{F5E0C1F7-9E9B-46F2-AC88-8C9C1C923880}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{F5E0C1F7-9E9B-46F2-AC88-8C9C1C923880}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{F5E0C1F7-9E9B-46F2-AC88-8C9C1C923880}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{F5E0C1F7-9E9B-46F2-AC88-8C9C1C923880}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{E73BB233-D88B-44A7-A98F-D71EE158381D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{E73BB233-D88B-44A7-A98F-D71EE158381D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{E73BB233-D88B-44A7-A98F-D71EE158381D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{E73BB233-D88B-44A7-A98F-D71EE158381D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{B0397530-545A-471D-BB74-027AE456DF1A}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{B0397530-545A-471D-BB74-027AE456DF1A}.Debug|x64.Build.0 = Debug|x64
|
||||
{B0397530-545A-471D-BB74-027AE456DF1A}.Release|x64.ActiveCfg = Release|x64
|
||||
{B0397530-545A-471D-BB74-027AE456DF1A}.Release|x64.Build.0 = Release|x64
|
||||
{F5E0C1F7-9E9B-46F2-AC88-8C9C1C923880}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{F5E0C1F7-9E9B-46F2-AC88-8C9C1C923880}.Debug|x64.Build.0 = Debug|x64
|
||||
{F5E0C1F7-9E9B-46F2-AC88-8C9C1C923880}.Release|x64.ActiveCfg = Release|x64
|
||||
{F5E0C1F7-9E9B-46F2-AC88-8C9C1C923880}.Release|x64.Build.0 = Release|x64
|
||||
{E73BB233-D88B-44A7-A98F-D71EE158381D}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{E73BB233-D88B-44A7-A98F-D71EE158381D}.Debug|x64.Build.0 = Debug|x64
|
||||
{E73BB233-D88B-44A7-A98F-D71EE158381D}.Release|x64.ActiveCfg = Release|x64
|
||||
{E73BB233-D88B-44A7-A98F-D71EE158381D}.Release|x64.Build.0 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
|
||||
<PropertyGroup>
|
||||
<GenerateResourceUsePreserializedResources>true</GenerateResourceUsePreserializedResources>
|
||||
<Platforms>x64</Platforms>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
@@ -15,13 +16,12 @@
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<OutputPath>..\bin\$(Configuration)\</OutputPath>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<GenerateResourceUsePreserializedResources>true</GenerateResourceUsePreserializedResources>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<DebugType>full</DebugType>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<DebugType>none</DebugType>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
|
||||
@@ -8,6 +8,9 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using Windows.Win32;
|
||||
using Windows.Win32.Devices.DeviceAndDriverInstallation;
|
||||
using Windows.Win32.Foundation;
|
||||
using LibreHardwareMonitor.Interop;
|
||||
using Microsoft.Win32.SafeHandles;
|
||||
|
||||
@@ -52,45 +55,48 @@ internal class BatteryGroup : IGroup
|
||||
if (Software.OperatingSystem.IsUnix)
|
||||
return;
|
||||
|
||||
IntPtr hdev = SetupApi.SetupDiGetClassDevs(ref SetupApi.GUID_DEVICE_BATTERY, IntPtr.Zero, IntPtr.Zero, SetupApi.DIGCF_PRESENT | SetupApi.DIGCF_DEVICEINTERFACE);
|
||||
if (hdev != SetupApi.INVALID_HANDLE_VALUE)
|
||||
SetupDiDestroyDeviceInfoListSafeHandle hdev = PInvoke.SetupDiGetClassDevs(PInvoke.GUID_DEVICE_BATTERY, null, HWND.Null, SETUP_DI_GET_CLASS_DEVS_FLAGS.DIGCF_PRESENT | SETUP_DI_GET_CLASS_DEVS_FLAGS.DIGCF_DEVICEINTERFACE);
|
||||
if (!hdev.IsInvalid)
|
||||
{
|
||||
for (uint i = 0; ; i++)
|
||||
{
|
||||
SetupApi.SP_DEVICE_INTERFACE_DATA did = default;
|
||||
did.cbSize = (uint)Marshal.SizeOf(typeof(SetupApi.SP_DEVICE_INTERFACE_DATA));
|
||||
SP_DEVICE_INTERFACE_DATA data = default;
|
||||
data.cbSize = (uint)sizeof(SP_DEVICE_INTERFACE_DATA);
|
||||
|
||||
if (!SetupApi.SetupDiEnumDeviceInterfaces(hdev,
|
||||
IntPtr.Zero,
|
||||
ref SetupApi.GUID_DEVICE_BATTERY,
|
||||
if (!PInvoke.SetupDiEnumDeviceInterfaces(hdev,
|
||||
null,
|
||||
PInvoke.GUID_DEVICE_BATTERY,
|
||||
i,
|
||||
ref did))
|
||||
ref data))
|
||||
{
|
||||
if (Marshal.GetLastWin32Error() == SetupApi.ERROR_NO_MORE_ITEMS)
|
||||
if (Marshal.GetLastWin32Error() == (int) WIN32_ERROR.ERROR_NO_MORE_ITEMS)
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
SetupApi.SetupDiGetDeviceInterfaceDetail(hdev,
|
||||
did,
|
||||
IntPtr.Zero,
|
||||
uint cbRequired = 0;
|
||||
|
||||
PInvoke.SetupDiGetDeviceInterfaceDetail(hdev,
|
||||
data,
|
||||
null,
|
||||
0,
|
||||
out uint cbRequired,
|
||||
IntPtr.Zero);
|
||||
&cbRequired,
|
||||
null);
|
||||
|
||||
if (Marshal.GetLastWin32Error() == SetupApi.ERROR_INSUFFICIENT_BUFFER)
|
||||
if (Marshal.GetLastWin32Error() == (int) WIN32_ERROR.ERROR_INSUFFICIENT_BUFFER)
|
||||
{
|
||||
IntPtr pdidd = Kernel32.LocalAlloc(Kernel32.LPTR, cbRequired);
|
||||
Marshal.WriteInt32(pdidd, Environment.Is64BitProcess ? 8 : 4 + Marshal.SystemDefaultCharSize); // cbSize.
|
||||
IntPtr buffer = Marshal.AllocHGlobal((int)cbRequired);
|
||||
SP_DEVICE_INTERFACE_DETAIL_DATA_W* pData = (SP_DEVICE_INTERFACE_DETAIL_DATA_W*) buffer;
|
||||
pData->cbSize = (uint)sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_W);
|
||||
|
||||
if (SetupApi.SetupDiGetDeviceInterfaceDetail(hdev,
|
||||
did,
|
||||
pdidd,
|
||||
if (PInvoke.SetupDiGetDeviceInterfaceDetail(hdev,
|
||||
data,
|
||||
pData,
|
||||
cbRequired,
|
||||
out _,
|
||||
IntPtr.Zero))
|
||||
&cbRequired,
|
||||
null) )
|
||||
{
|
||||
string devicePath = new((char*)(pdidd + 4));
|
||||
string devicePath = pData->DevicePath.ToString();
|
||||
|
||||
SafeFileHandle battery = Kernel32.CreateFile(devicePath, FileAccess.ReadWrite, FileShare.ReadWrite, IntPtr.Zero, FileMode.Open, FileAttributes.Normal, IntPtr.Zero);
|
||||
if (!battery.IsInvalid)
|
||||
@@ -134,12 +140,12 @@ internal class BatteryGroup : IGroup
|
||||
}
|
||||
}
|
||||
|
||||
Kernel32.LocalFree(pdidd);
|
||||
Marshal.FreeHGlobal(buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SetupApi.SetupDiDestroyDeviceInfoList(hdev);
|
||||
hdev.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,6 @@ internal sealed class Amd10Cpu : AmdCpu
|
||||
_pawnModule = new AmdFamily10();
|
||||
|
||||
// AMD family 1Xh processors support only one temperature sensor
|
||||
ushort miscellaneousControlDeviceId;
|
||||
_coreTemperature = new Sensor("CPU Cores", 0, SensorType.Temperature, this, new[] { new ParameterDescription("Offset [°C]", "Temperature offset.", 0) }, settings);
|
||||
_coreVoltage = new Sensor("CPU Cores", 0, SensorType.Voltage, this, settings);
|
||||
ActivateSensor(_coreVoltage);
|
||||
|
||||
@@ -9,16 +9,18 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using Windows.Wdk;
|
||||
using Windows.Wdk.System.SystemInformation;
|
||||
using Windows.Win32.Foundation;
|
||||
using Windows.Win32.System.WindowsProgramming;
|
||||
|
||||
namespace LibreHardwareMonitor.Hardware.Cpu;
|
||||
|
||||
internal class CpuLoad
|
||||
{
|
||||
private static readonly bool _queryIdleTimeSeparated = QueryIdleTimeSeparated();
|
||||
|
||||
private readonly double[] _threadLoads;
|
||||
private double _totalLoad;
|
||||
private long[] _idleTimes;
|
||||
private double _totalLoad;
|
||||
private long[] _totalTimes;
|
||||
|
||||
public CpuLoad(CpuId[][] cpuid)
|
||||
@@ -47,23 +49,49 @@ internal class CpuLoad
|
||||
return !Software.OperatingSystem.IsUnix ? GetWindowsTimes(out idle, out total) : GetUnixTimes(out idle, out total);
|
||||
}
|
||||
|
||||
private static bool GetWindowsTimes(out long[] idle, out long[] total)
|
||||
private static unsafe bool GetWindowsTimes(out long[] idle, out long[] total)
|
||||
{
|
||||
idle = null;
|
||||
total = null;
|
||||
|
||||
//use the idle time routine only with a few specific windows 11 versions
|
||||
if (_queryIdleTimeSeparated)
|
||||
return GetWindowsTimesFromIdleTimes(out idle, out total);
|
||||
int size = sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION) * 64;
|
||||
uint returnSize = 0;
|
||||
IntPtr handle = Marshal.AllocHGlobal(size);
|
||||
SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION[] perfInformation;
|
||||
|
||||
//Query processor performance information
|
||||
Interop.NtDll.SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION[] perfInformation = new Interop.NtDll.SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION[64];
|
||||
int perfSize = Marshal.SizeOf(typeof(Interop.NtDll.SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION));
|
||||
if (Interop.NtDll.NtQuerySystemInformation(Interop.NtDll.SYSTEM_INFORMATION_CLASS.SystemProcessorPerformanceInformation, perfInformation, perfInformation.Length * perfSize, out int perfReturn) != 0)
|
||||
return false;
|
||||
while (true)
|
||||
{
|
||||
//Query processor performance information
|
||||
NTSTATUS status = PInvoke.NtQuerySystemInformation(SYSTEM_INFORMATION_CLASS.SystemProcessorPerformanceInformation, (void*)handle, (uint)size, &returnSize);
|
||||
if (status == NTSTATUS.STATUS_INFO_LENGTH_MISMATCH)
|
||||
{
|
||||
size = (int)returnSize;
|
||||
handle = Marshal.ReAllocHGlobal(handle, new IntPtr(size));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (status != NTSTATUS.STATUS_SUCCESS)
|
||||
{
|
||||
Marshal.FreeHGlobal(handle);
|
||||
return false;
|
||||
}
|
||||
|
||||
idle = new long[perfReturn / perfSize];
|
||||
total = new long[perfReturn / perfSize];
|
||||
SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION* perfInformationPtr = (SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION*)handle;
|
||||
|
||||
int perfItemsCount = (int)(returnSize / sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION));
|
||||
perfInformation = new SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION[perfItemsCount];
|
||||
for (int i = 0; i < perfItemsCount; i++)
|
||||
{
|
||||
perfInformation[i] = perfInformationPtr[i];
|
||||
}
|
||||
|
||||
Marshal.FreeHGlobal(handle);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
idle = new long[perfInformation.Length];
|
||||
total = new long[perfInformation.Length];
|
||||
for (int i = 0; i < total.Length; i++)
|
||||
{
|
||||
idle[i] = perfInformation[i].IdleTime;
|
||||
@@ -73,52 +101,13 @@ internal class CpuLoad
|
||||
return true;
|
||||
}
|
||||
|
||||
private static bool GetWindowsTimesFromIdleTimes(out long[] idle, out long[] total)
|
||||
{
|
||||
idle = null;
|
||||
total = null;
|
||||
|
||||
Interop.NtDll.SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION[] perfInformation = new Interop.NtDll.SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION[64];
|
||||
int perfSize = Marshal.SizeOf(typeof(Interop.NtDll.SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION));
|
||||
Interop.NtDll.SYSTEM_PROCESSOR_IDLE_INFORMATION[] idleInformation = new Interop.NtDll.SYSTEM_PROCESSOR_IDLE_INFORMATION[64];
|
||||
int idleSize = Marshal.SizeOf(typeof(Interop.NtDll.SYSTEM_PROCESSOR_IDLE_INFORMATION));
|
||||
|
||||
//Query processor performance and idle information
|
||||
//these 2 methods must be called as directly as possible one after the other
|
||||
|
||||
//Query processor idle information
|
||||
if (Interop.NtDll.NtQuerySystemInformation(Interop.NtDll.SYSTEM_INFORMATION_CLASS.SystemProcessorIdleInformation, idleInformation, idleInformation.Length * idleSize, out int idleReturn) != 0)
|
||||
return false;
|
||||
|
||||
//Query processor performance information
|
||||
if (Interop.NtDll.NtQuerySystemInformation(Interop.NtDll.SYSTEM_INFORMATION_CLASS.SystemProcessorPerformanceInformation, perfInformation, perfInformation.Length * perfSize, out int perfReturn) != 0)
|
||||
return false;
|
||||
|
||||
int perfItemsCount = perfReturn / perfSize;
|
||||
int idleItemsCount = idleReturn / idleSize;
|
||||
|
||||
if (perfItemsCount != idleItemsCount)
|
||||
return false;
|
||||
|
||||
idle = new long[perfItemsCount];
|
||||
total = new long[perfItemsCount];
|
||||
|
||||
for (int i = 0; i < perfItemsCount; i++)
|
||||
{
|
||||
idle[i] = idleInformation[i].IdleTime;
|
||||
total[i] = perfInformation[i].KernelTime + perfInformation[i].UserTime;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static bool GetUnixTimes(out long[] idle, out long[] total)
|
||||
{
|
||||
idle = null;
|
||||
total = null;
|
||||
|
||||
List<long> idleList = new();
|
||||
List<long> totalList = new();
|
||||
List<long> idleList = [];
|
||||
List<long> totalList = [];
|
||||
|
||||
if (!File.Exists("/proc/stat"))
|
||||
return false;
|
||||
@@ -131,7 +120,7 @@ internal class CpuLoad
|
||||
// 0=cpu 1=user 2=nice 3=system 4=idle 5=iowait 6=irq 7=softirq 8=steal 9=guest 10=guest_nice
|
||||
foreach (string cpuInfo in cpuInfos.Where(s => s.StartsWith("cpu") && s.Length > 3 && s[3] != ' '))
|
||||
{
|
||||
string[] overall = cpuInfo.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
string[] overall = cpuInfo.Split([' '], StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
try
|
||||
{
|
||||
@@ -214,21 +203,9 @@ internal class CpuLoad
|
||||
{
|
||||
total = 0;
|
||||
}
|
||||
|
||||
|
||||
_totalLoad = Math.Round(total * 100.0, 2);
|
||||
_totalTimes = newTotalTimes;
|
||||
_idleTimes = newIdleTimes;
|
||||
}
|
||||
|
||||
private static bool QueryIdleTimeSeparated()
|
||||
{
|
||||
if (Software.OperatingSystem.IsUnix)
|
||||
return false;
|
||||
|
||||
// From Windows 11 22H2 the CPU idle time returned by SystemProcessorPerformanceInformation is invalid, this issue has been fixed with 24H2.
|
||||
OperatingSystem os = Environment.OSVersion;
|
||||
Version win1122H2 = new Version(10, 0, 22621, 0);
|
||||
Version win1124H2 = new Version(10, 0, 26100, 0);
|
||||
return os.Version >= win1122H2 && os.Version < win1124H2;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,20 +7,30 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using LibreHardwareMonitor.Interop;
|
||||
using Windows.Wdk.Graphics.Direct3D;
|
||||
using Windows.Win32;
|
||||
using Windows.Win32.Devices.DeviceAndDriverInstallation;
|
||||
using Windows.Win32.Foundation;
|
||||
|
||||
namespace LibreHardwareMonitor.Hardware;
|
||||
|
||||
internal static class D3DDisplayDevice
|
||||
{
|
||||
public static string[] GetDeviceIdentifiers()
|
||||
public static unsafe string[] GetDeviceIdentifiers()
|
||||
{
|
||||
if (CfgMgr32.CM_Get_Device_Interface_List_Size(out uint size, ref CfgMgr32.GUID_DISPLAY_DEVICE_ARRIVAL, null, CfgMgr32.CM_GET_DEVICE_INTERFACE_LIST_PRESENT) != CfgMgr32.CR_SUCCESS)
|
||||
if (PInvoke.CM_Get_Device_Interface_List_Size(out uint size, PInvoke.GUID_DISPLAY_DEVICE_ARRIVAL, null, CM_GET_DEVICE_INTERFACE_LIST_FLAGS.CM_GET_DEVICE_INTERFACE_LIST_PRESENT) !=
|
||||
CONFIGRET.CR_SUCCESS)
|
||||
return null;
|
||||
|
||||
char[] data = new char[size];
|
||||
if (CfgMgr32.CM_Get_Device_Interface_List(ref CfgMgr32.GUID_DISPLAY_DEVICE_ARRIVAL, null, data, (uint)data.Length, CfgMgr32.CM_GET_DEVICE_INTERFACE_LIST_PRESENT) == CfgMgr32.CR_SUCCESS)
|
||||
return new string(data).Split('\0').Where(m => !string.IsNullOrEmpty(m)).ToArray();
|
||||
fixed (char* pData = data)
|
||||
{
|
||||
if (PInvoke.CM_Get_Device_Interface_List(PInvoke.GUID_DISPLAY_DEVICE_ARRIVAL, null, pData, (uint)data.Length, CM_GET_DEVICE_INTERFACE_LIST_FLAGS.CM_GET_DEVICE_INTERFACE_LIST_PRESENT) ==
|
||||
CONFIGRET.CR_SUCCESS)
|
||||
{
|
||||
return new string(data).Split('\0').Where(m => !string.IsNullOrEmpty(m)).ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -51,21 +61,21 @@ internal static class D3DDisplayDevice
|
||||
{
|
||||
deviceInfo = new D3DDeviceInfo();
|
||||
|
||||
OpenAdapterFromDeviceName(out uint status, deviceIdentifier, out D3dkmth.D3DKMT_OPENADAPTERFROMDEVICENAME adapter);
|
||||
if (status != WinNt.STATUS_SUCCESS)
|
||||
OpenAdapterFromDeviceName(out NTSTATUS status, deviceIdentifier, out D3DKMT_OPENADAPTERFROMDEVICENAME adapter);
|
||||
if (status != NTSTATUS.STATUS_SUCCESS)
|
||||
return false;
|
||||
|
||||
GetAdapterType(out status, adapter, out D3dkmth.D3DKMT_ADAPTERTYPE adapterType);
|
||||
if (status != WinNt.STATUS_SUCCESS)
|
||||
GetAdapterType(out status, adapter, out D3DKMT_ADAPTERTYPE adapterType);
|
||||
if (status != NTSTATUS.STATUS_SUCCESS)
|
||||
return false;
|
||||
|
||||
if (!adapterType.Value.HasFlag(D3dkmth.D3DKMT_ADAPTERTYPE_FLAGS.SoftwareDevice))
|
||||
if (adapterType.Anonymous.Anonymous.SoftwareDevice)
|
||||
return false;
|
||||
|
||||
deviceInfo.Integrated = !adapterType.Value.HasFlag(D3dkmth.D3DKMT_ADAPTERTYPE_FLAGS.HybridIntegrated);
|
||||
deviceInfo.Integrated = adapterType.Anonymous.Anonymous.HybridIntegrated;
|
||||
|
||||
GetQueryStatisticsAdapterInformation(out status, adapter, out D3dkmth.D3DKMT_QUERYSTATISTICS_ADAPTER_INFORMATION adapterInformation);
|
||||
if (status != WinNt.STATUS_SUCCESS)
|
||||
GetQueryStatisticsAdapterInformation(out status, adapter, out D3DKMT_QUERYSTATISTICS_ADAPTER_INFORMATION adapterInformation);
|
||||
if (status != NTSTATUS.STATUS_SUCCESS)
|
||||
return false;
|
||||
|
||||
uint segmentCount = adapterInformation.NbSegments;
|
||||
@@ -77,25 +87,25 @@ internal static class D3DDisplayDevice
|
||||
|
||||
for (uint nodeId = 0; nodeId < nodeCount; nodeId++)
|
||||
{
|
||||
GetNodeMetaData(out status, adapter, nodeId, out D3dkmth.D3DKMT_NODEMETADATA nodeMetaData);
|
||||
if (status != WinNt.STATUS_SUCCESS)
|
||||
GetNodeMetaData(out status, adapter, nodeId, out D3DKMT_NODEMETADATA nodeMetaData);
|
||||
if (status != NTSTATUS.STATUS_SUCCESS)
|
||||
return false;
|
||||
|
||||
GetQueryStatisticsNode(out status, adapter, nodeId, out D3dkmth.D3DKMT_QUERYSTATISTICS_NODE_INFORMATION nodeInformation);
|
||||
if (status != WinNt.STATUS_SUCCESS)
|
||||
GetQueryStatisticsNode(out status, adapter, nodeId, out D3DKMT_QUERYSTATISTICS_NODE_INFORMATION nodeInformation);
|
||||
if (status != NTSTATUS.STATUS_SUCCESS)
|
||||
return false;
|
||||
|
||||
deviceInfo.Nodes[nodeId] = new D3DDeviceNodeInfo
|
||||
{
|
||||
Id = nodeId,
|
||||
Id = nodeId,
|
||||
Name = GetNodeEngineTypeString(nodeMetaData),
|
||||
RunningTime = nodeInformation.GlobalInformation.RunningTime.QuadPart,
|
||||
RunningTime = nodeInformation.GlobalInformation.RunningTime,
|
||||
QueryTime = queryTime
|
||||
};
|
||||
}
|
||||
|
||||
GetSegmentSize(out status, adapter, out D3dkmth.D3DKMT_SEGMENTSIZEINFO segmentSizeInfo);
|
||||
if (status != WinNt.STATUS_SUCCESS)
|
||||
GetSegmentSize(out status, adapter, out D3DKMT_SEGMENTSIZEINFO segmentSizeInfo);
|
||||
if (status != NTSTATUS.STATUS_SUCCESS)
|
||||
return false;
|
||||
|
||||
deviceInfo.GpuSharedLimit = segmentSizeInfo.SharedSystemMemorySize;
|
||||
@@ -104,8 +114,8 @@ internal static class D3DDisplayDevice
|
||||
|
||||
for (uint segmentId = 0; segmentId < segmentCount; segmentId++)
|
||||
{
|
||||
GetQueryStatisticsSegment(out status, adapter, segmentId, out D3dkmth.D3DKMT_QUERYSTATISTICS_SEGMENT_INFORMATION segmentInformation);
|
||||
if (status != WinNt.STATUS_SUCCESS)
|
||||
GetQueryStatisticsSegment(out status, adapter, segmentId, out D3DKMT_QUERYSTATISTICS_SEGMENT_INFORMATION segmentInformation);
|
||||
if (status != NTSTATUS.STATUS_SUCCESS)
|
||||
return false;
|
||||
|
||||
ulong bytesResident = segmentInformation.BytesResident;
|
||||
@@ -126,140 +136,138 @@ internal static class D3DDisplayDevice
|
||||
}
|
||||
|
||||
CloseAdapter(out status, adapter);
|
||||
return status == WinNt.STATUS_SUCCESS;
|
||||
return status == NTSTATUS.STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
private static string GetNodeEngineTypeString(D3dkmth.D3DKMT_NODEMETADATA nodeMetaData)
|
||||
private static string GetNodeEngineTypeString(D3DKMT_NODEMETADATA nodeMetaData)
|
||||
{
|
||||
return nodeMetaData.NodeData.EngineType switch
|
||||
{
|
||||
D3dkmdt.DXGK_ENGINE_TYPE.DXGK_ENGINE_TYPE_OTHER => "D3D " + (!string.IsNullOrWhiteSpace(nodeMetaData.NodeData.FriendlyName) ? nodeMetaData.NodeData.FriendlyName : "Other"),
|
||||
D3dkmdt.DXGK_ENGINE_TYPE.DXGK_ENGINE_TYPE_3D => "D3D 3D",
|
||||
D3dkmdt.DXGK_ENGINE_TYPE.DXGK_ENGINE_TYPE_VIDEO_DECODE => "D3D Video Decode",
|
||||
D3dkmdt.DXGK_ENGINE_TYPE.DXGK_ENGINE_TYPE_VIDEO_ENCODE => "D3D Video Encode",
|
||||
D3dkmdt.DXGK_ENGINE_TYPE.DXGK_ENGINE_TYPE_VIDEO_PROCESSING => "D3D Video Processing",
|
||||
D3dkmdt.DXGK_ENGINE_TYPE.DXGK_ENGINE_TYPE_SCENE_ASSEMBLY => "D3D Scene Assembly",
|
||||
D3dkmdt.DXGK_ENGINE_TYPE.DXGK_ENGINE_TYPE_COPY => "D3D Copy",
|
||||
D3dkmdt.DXGK_ENGINE_TYPE.DXGK_ENGINE_TYPE_OVERLAY => "D3D Overlay",
|
||||
D3dkmdt.DXGK_ENGINE_TYPE.DXGK_ENGINE_TYPE_CRYPTO => "D3D Crypto",
|
||||
DXGK_ENGINE_TYPE.DXGK_ENGINE_TYPE_OTHER => "D3D " + (nodeMetaData.NodeData.FriendlyName.Length > 0 ? nodeMetaData.NodeData.FriendlyName : "Other"),
|
||||
DXGK_ENGINE_TYPE.DXGK_ENGINE_TYPE_3D => "D3D 3D",
|
||||
DXGK_ENGINE_TYPE.DXGK_ENGINE_TYPE_VIDEO_DECODE => "D3D Video Decode",
|
||||
DXGK_ENGINE_TYPE.DXGK_ENGINE_TYPE_VIDEO_ENCODE => "D3D Video Encode",
|
||||
DXGK_ENGINE_TYPE.DXGK_ENGINE_TYPE_VIDEO_PROCESSING => "D3D Video Processing",
|
||||
DXGK_ENGINE_TYPE.DXGK_ENGINE_TYPE_SCENE_ASSEMBLY => "D3D Scene Assembly",
|
||||
DXGK_ENGINE_TYPE.DXGK_ENGINE_TYPE_COPY => "D3D Copy",
|
||||
DXGK_ENGINE_TYPE.DXGK_ENGINE_TYPE_OVERLAY => "D3D Overlay",
|
||||
DXGK_ENGINE_TYPE.DXGK_ENGINE_TYPE_CRYPTO => "D3D Crypto",
|
||||
_ => "D3D Unknown"
|
||||
};
|
||||
}
|
||||
|
||||
private static void GetSegmentSize
|
||||
private static unsafe void GetSegmentSize
|
||||
(
|
||||
out uint status,
|
||||
D3dkmth.D3DKMT_OPENADAPTERFROMDEVICENAME adapter,
|
||||
out D3dkmth.D3DKMT_SEGMENTSIZEINFO sizeInformation)
|
||||
out NTSTATUS status,
|
||||
D3DKMT_OPENADAPTERFROMDEVICENAME adapter,
|
||||
out D3DKMT_SEGMENTSIZEINFO sizeInformation)
|
||||
{
|
||||
IntPtr segmentSizePtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(D3dkmth.D3DKMT_SEGMENTSIZEINFO)));
|
||||
sizeInformation = new D3dkmth.D3DKMT_SEGMENTSIZEINFO();
|
||||
Marshal.StructureToPtr(sizeInformation, segmentSizePtr, true);
|
||||
IntPtr segmentSizePtr = Marshal.AllocHGlobal(sizeof(D3DKMT_SEGMENTSIZEINFO));
|
||||
|
||||
var queryAdapterInfo = new D3dkmth.D3DKMT_QUERYADAPTERINFO
|
||||
var queryAdapterInfo = new D3DKMT_QUERYADAPTERINFO
|
||||
{
|
||||
hAdapter = adapter.hAdapter,
|
||||
Type = D3dkmth.KMTQUERYADAPTERINFOTYPE.KMTQAITYPE_GETSEGMENTSIZE,
|
||||
pPrivateDriverData = segmentSizePtr,
|
||||
PrivateDriverDataSize = Marshal.SizeOf(typeof(D3dkmth.D3DKMT_SEGMENTSIZEINFO))
|
||||
Type = KMTQUERYADAPTERINFOTYPE.KMTQAITYPE_GETSEGMENTSIZE,
|
||||
pPrivateDriverData = (void*)segmentSizePtr,
|
||||
PrivateDriverDataSize = (uint)sizeof(D3DKMT_SEGMENTSIZEINFO)
|
||||
};
|
||||
|
||||
status = Gdi32.D3DKMTQueryAdapterInfo(ref queryAdapterInfo);
|
||||
sizeInformation = Marshal.PtrToStructure<D3dkmth.D3DKMT_SEGMENTSIZEINFO>(segmentSizePtr);
|
||||
status = Windows.Wdk.PInvoke.D3DKMTQueryAdapterInfo(ref queryAdapterInfo);
|
||||
sizeInformation = *(D3DKMT_SEGMENTSIZEINFO*)segmentSizePtr;
|
||||
Marshal.FreeHGlobal(segmentSizePtr);
|
||||
}
|
||||
|
||||
private static void GetNodeMetaData(out uint status, D3dkmth.D3DKMT_OPENADAPTERFROMDEVICENAME adapter, uint nodeId, out D3dkmth.D3DKMT_NODEMETADATA nodeMetaDataResult)
|
||||
private static unsafe void GetNodeMetaData(out NTSTATUS status, D3DKMT_OPENADAPTERFROMDEVICENAME adapter, uint nodeId, out D3DKMT_NODEMETADATA nodeMetaDataResult)
|
||||
{
|
||||
IntPtr nodeMetaDataPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(D3dkmth.D3DKMT_NODEMETADATA)));
|
||||
nodeMetaDataResult = new D3dkmth.D3DKMT_NODEMETADATA { NodeOrdinalAndAdapterIndex = nodeId };
|
||||
Marshal.StructureToPtr(nodeMetaDataResult, nodeMetaDataPtr, true);
|
||||
IntPtr nodeMetaDataPtr = Marshal.AllocHGlobal(sizeof(D3DKMT_NODEMETADATA));
|
||||
|
||||
var queryAdapterInfo = new D3dkmth.D3DKMT_QUERYADAPTERINFO
|
||||
D3DKMT_NODEMETADATA* pData = (D3DKMT_NODEMETADATA*)nodeMetaDataPtr;
|
||||
pData->NodeOrdinalAndAdapterIndex = nodeId;
|
||||
|
||||
var queryAdapterInfo = new D3DKMT_QUERYADAPTERINFO
|
||||
{
|
||||
hAdapter = adapter.hAdapter,
|
||||
Type = D3dkmth.KMTQUERYADAPTERINFOTYPE.KMTQAITYPE_NODEMETADATA,
|
||||
pPrivateDriverData = nodeMetaDataPtr,
|
||||
PrivateDriverDataSize = Marshal.SizeOf(typeof(D3dkmth.D3DKMT_NODEMETADATA))
|
||||
Type = KMTQUERYADAPTERINFOTYPE.KMTQAITYPE_NODEMETADATA,
|
||||
pPrivateDriverData = (void*)nodeMetaDataPtr,
|
||||
PrivateDriverDataSize = (uint)sizeof(D3DKMT_NODEMETADATA)
|
||||
};
|
||||
|
||||
status = Gdi32.D3DKMTQueryAdapterInfo(ref queryAdapterInfo);
|
||||
nodeMetaDataResult = Marshal.PtrToStructure<D3dkmth.D3DKMT_NODEMETADATA>(nodeMetaDataPtr);
|
||||
status = Windows.Wdk.PInvoke.D3DKMTQueryAdapterInfo(ref queryAdapterInfo);
|
||||
nodeMetaDataResult = *(D3DKMT_NODEMETADATA*)nodeMetaDataPtr;
|
||||
Marshal.FreeHGlobal(nodeMetaDataPtr);
|
||||
}
|
||||
|
||||
private static void GetQueryStatisticsNode(out uint status, D3dkmth.D3DKMT_OPENADAPTERFROMDEVICENAME adapter, uint nodeId, out D3dkmth.D3DKMT_QUERYSTATISTICS_NODE_INFORMATION nodeInformation)
|
||||
private static void GetQueryStatisticsNode(out NTSTATUS status, D3DKMT_OPENADAPTERFROMDEVICENAME adapter, uint nodeId, out D3DKMT_QUERYSTATISTICS_NODE_INFORMATION nodeInformation)
|
||||
{
|
||||
var queryElement = new D3dkmth.D3DKMT_QUERYSTATISTICS_QUERY_ELEMENT { QueryNode = { NodeId = nodeId } };
|
||||
|
||||
var queryStatistics = new D3dkmth.D3DKMT_QUERYSTATISTICS
|
||||
var queryStatistics = new D3DKMT_QUERYSTATISTICS
|
||||
{
|
||||
AdapterLuid = adapter.AdapterLuid, Type = D3dkmth.D3DKMT_QUERYSTATISTICS_TYPE.D3DKMT_QUERYSTATISTICS_NODE, QueryElement = queryElement
|
||||
AdapterLuid = adapter.AdapterLuid,
|
||||
Type = D3DKMT_QUERYSTATISTICS_TYPE.D3DKMT_QUERYSTATISTICS_NODE,
|
||||
Anonymous = new D3DKMT_QUERYSTATISTICS._Anonymous_e__Union { QueryNode = new D3DKMT_QUERYSTATISTICS_QUERY_NODE { NodeId = nodeId } }
|
||||
};
|
||||
|
||||
status = Gdi32.D3DKMTQueryStatistics(ref queryStatistics);
|
||||
|
||||
status = Windows.Wdk.PInvoke.D3DKMTQueryStatistics(queryStatistics);
|
||||
nodeInformation = queryStatistics.QueryResult.NodeInformation;
|
||||
}
|
||||
|
||||
private static void GetQueryStatisticsSegment
|
||||
(
|
||||
out uint status,
|
||||
D3dkmth.D3DKMT_OPENADAPTERFROMDEVICENAME adapter,
|
||||
out NTSTATUS status,
|
||||
D3DKMT_OPENADAPTERFROMDEVICENAME adapter,
|
||||
uint segmentId,
|
||||
out D3dkmth.D3DKMT_QUERYSTATISTICS_SEGMENT_INFORMATION segmentInformation)
|
||||
out D3DKMT_QUERYSTATISTICS_SEGMENT_INFORMATION segmentInformation)
|
||||
{
|
||||
var queryElement = new D3dkmth.D3DKMT_QUERYSTATISTICS_QUERY_ELEMENT { QuerySegment = { SegmentId = segmentId } };
|
||||
|
||||
var queryStatistics = new D3dkmth.D3DKMT_QUERYSTATISTICS
|
||||
var queryStatistics = new D3DKMT_QUERYSTATISTICS
|
||||
{
|
||||
AdapterLuid = adapter.AdapterLuid, Type = D3dkmth.D3DKMT_QUERYSTATISTICS_TYPE.D3DKMT_QUERYSTATISTICS_SEGMENT, QueryElement = queryElement
|
||||
AdapterLuid = adapter.AdapterLuid,
|
||||
Type = D3DKMT_QUERYSTATISTICS_TYPE.D3DKMT_QUERYSTATISTICS_SEGMENT,
|
||||
Anonymous = new D3DKMT_QUERYSTATISTICS._Anonymous_e__Union { QuerySegment = new D3DKMT_QUERYSTATISTICS_QUERY_SEGMENT { SegmentId = segmentId } }
|
||||
};
|
||||
|
||||
status = Gdi32.D3DKMTQueryStatistics(ref queryStatistics);
|
||||
|
||||
status = Windows.Wdk.PInvoke.D3DKMTQueryStatistics(queryStatistics);
|
||||
segmentInformation = queryStatistics.QueryResult.SegmentInformation;
|
||||
}
|
||||
|
||||
private static void GetQueryStatisticsAdapterInformation
|
||||
(
|
||||
out uint status,
|
||||
D3dkmth.D3DKMT_OPENADAPTERFROMDEVICENAME adapter,
|
||||
out D3dkmth.D3DKMT_QUERYSTATISTICS_ADAPTER_INFORMATION adapterInformation)
|
||||
out NTSTATUS status,
|
||||
D3DKMT_OPENADAPTERFROMDEVICENAME adapter,
|
||||
out D3DKMT_QUERYSTATISTICS_ADAPTER_INFORMATION adapterInformation)
|
||||
{
|
||||
var queryStatistics = new D3dkmth.D3DKMT_QUERYSTATISTICS { AdapterLuid = adapter.AdapterLuid, Type = D3dkmth.D3DKMT_QUERYSTATISTICS_TYPE.D3DKMT_QUERYSTATISTICS_ADAPTER };
|
||||
var queryStatistics = new D3DKMT_QUERYSTATISTICS { AdapterLuid = adapter.AdapterLuid, Type = D3DKMT_QUERYSTATISTICS_TYPE.D3DKMT_QUERYSTATISTICS_ADAPTER };
|
||||
|
||||
status = Gdi32.D3DKMTQueryStatistics(ref queryStatistics);
|
||||
status = Windows.Wdk.PInvoke.D3DKMTQueryStatistics(queryStatistics);
|
||||
|
||||
adapterInformation = queryStatistics.QueryResult.AdapterInformation;
|
||||
}
|
||||
|
||||
private static void GetAdapterType(out uint status, D3dkmth.D3DKMT_OPENADAPTERFROMDEVICENAME adapter, out D3dkmth.D3DKMT_ADAPTERTYPE adapterTypeResult)
|
||||
private static unsafe void GetAdapterType(out NTSTATUS status, D3DKMT_OPENADAPTERFROMDEVICENAME adapter, out D3DKMT_ADAPTERTYPE adapterTypeResult)
|
||||
{
|
||||
IntPtr adapterTypePtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(D3dkmth.D3DKMT_ADAPTERTYPE)));
|
||||
var queryAdapterInfo = new D3dkmth.D3DKMT_QUERYADAPTERINFO
|
||||
IntPtr adapterTypePtr = Marshal.AllocHGlobal(sizeof(D3DKMT_ADAPTERTYPE));
|
||||
|
||||
var queryAdapterInfo = new D3DKMT_QUERYADAPTERINFO
|
||||
{
|
||||
hAdapter = adapter.hAdapter,
|
||||
Type = D3dkmth.KMTQUERYADAPTERINFOTYPE.KMTQAITYPE_ADAPTERTYPE,
|
||||
pPrivateDriverData = adapterTypePtr,
|
||||
PrivateDriverDataSize = Marshal.SizeOf(typeof(D3dkmth.D3DKMT_ADAPTERTYPE))
|
||||
hAdapter = adapter.hAdapter, Type = KMTQUERYADAPTERINFOTYPE.KMTQAITYPE_ADAPTERTYPE, pPrivateDriverData = (void*)adapterTypePtr, PrivateDriverDataSize = (uint)sizeof(D3DKMT_ADAPTERTYPE)
|
||||
};
|
||||
|
||||
status = Gdi32.D3DKMTQueryAdapterInfo(ref queryAdapterInfo);
|
||||
adapterTypeResult = Marshal.PtrToStructure<D3dkmth.D3DKMT_ADAPTERTYPE>(adapterTypePtr);
|
||||
status = Windows.Wdk.PInvoke.D3DKMTQueryAdapterInfo(ref queryAdapterInfo);
|
||||
adapterTypeResult = *(D3DKMT_ADAPTERTYPE*)adapterTypePtr;
|
||||
Marshal.FreeHGlobal(adapterTypePtr);
|
||||
}
|
||||
|
||||
private static void OpenAdapterFromDeviceName(out uint status, string displayDeviceName, out D3dkmth.D3DKMT_OPENADAPTERFROMDEVICENAME adapter)
|
||||
private static unsafe void OpenAdapterFromDeviceName(out NTSTATUS status, string displayDeviceName, out D3DKMT_OPENADAPTERFROMDEVICENAME adapter)
|
||||
{
|
||||
adapter = new D3dkmth.D3DKMT_OPENADAPTERFROMDEVICENAME { pDeviceName = displayDeviceName };
|
||||
status = Gdi32.D3DKMTOpenAdapterFromDeviceName(ref adapter);
|
||||
fixed (char* pDisplayDeviceName = displayDeviceName)
|
||||
{
|
||||
adapter = new D3DKMT_OPENADAPTERFROMDEVICENAME { pDeviceName = new PCWSTR(pDisplayDeviceName) };
|
||||
status = Windows.Wdk.PInvoke.D3DKMTOpenAdapterFromDeviceName(ref adapter);
|
||||
}
|
||||
}
|
||||
|
||||
private static void CloseAdapter(out uint status, D3dkmth.D3DKMT_OPENADAPTERFROMDEVICENAME adapter)
|
||||
private static void CloseAdapter(out NTSTATUS status, D3DKMT_OPENADAPTERFROMDEVICENAME adapter)
|
||||
{
|
||||
var closeAdapter = new D3dkmth.D3DKMT_CLOSEADAPTER { hAdapter = adapter.hAdapter };
|
||||
status = Gdi32.D3DKMTCloseAdapter(ref closeAdapter);
|
||||
var closeAdapter = new D3DKMT_CLOSEADAPTER { hAdapter = adapter.hAdapter };
|
||||
status = Windows.Wdk.PInvoke.D3DKMTCloseAdapter(closeAdapter);
|
||||
}
|
||||
|
||||
public struct D3DDeviceNodeInfo
|
||||
|
||||
@@ -4,34 +4,34 @@
|
||||
// Partial Copyright (C) Michael Möller <mmoeller@openhardwaremonitor.org> and Contributors.
|
||||
// All Rights Reserved.
|
||||
|
||||
using System.Runtime.InteropServices;
|
||||
using LibreHardwareMonitor.Interop;
|
||||
using Windows.Win32;
|
||||
using Windows.Win32.System.SystemInformation;
|
||||
|
||||
namespace LibreHardwareMonitor.Hardware.Memory;
|
||||
|
||||
internal static class MemoryWindows
|
||||
internal static unsafe class MemoryWindows
|
||||
{
|
||||
public static void Update(TotalMemory memory)
|
||||
{
|
||||
Kernel32.MEMORYSTATUSEX status = new() { dwLength = (uint)Marshal.SizeOf<Kernel32.MEMORYSTATUSEX>() };
|
||||
MEMORYSTATUSEX status = new() { dwLength = (uint)sizeof(MEMORYSTATUSEX) };
|
||||
|
||||
if (!Kernel32.GlobalMemoryStatusEx(ref status))
|
||||
if (!PInvoke.GlobalMemoryStatusEx(ref status))
|
||||
return;
|
||||
|
||||
memory.PhysicalMemoryUsed.Value = (float)(status.ullTotalPhys - status.ullAvailPhys) / (1024 * 1024 * 1024);
|
||||
memory.PhysicalMemoryUsed.Value = (float)(status.ullTotalPhys - status.ullAvailPhys) / (1024 * 1024 * 1024);
|
||||
memory.PhysicalMemoryAvailable.Value = (float)status.ullAvailPhys / (1024 * 1024 * 1024);
|
||||
memory.PhysicalMemoryLoad.Value = 100.0f - ((100.0f * status.ullAvailPhys) / status.ullTotalPhys);
|
||||
memory.PhysicalMemoryLoad.Value = 100.0f - ((100.0f * status.ullAvailPhys) / status.ullTotalPhys);
|
||||
}
|
||||
|
||||
public static void Update(VirtualMemory memory)
|
||||
{
|
||||
Kernel32.MEMORYSTATUSEX status = new() { dwLength = (uint)Marshal.SizeOf<Kernel32.MEMORYSTATUSEX>() };
|
||||
MEMORYSTATUSEX status = new() { dwLength = (uint)sizeof(MEMORYSTATUSEX) };
|
||||
|
||||
if (!Kernel32.GlobalMemoryStatusEx(ref status))
|
||||
if (!PInvoke.GlobalMemoryStatusEx(ref status))
|
||||
return;
|
||||
|
||||
memory.VirtualMemoryUsed.Value = (float)(status.ullTotalPageFile - status.ullAvailPageFile) / (1024 * 1024 * 1024);
|
||||
memory.VirtualMemoryUsed.Value = (float)(status.ullTotalPageFile - status.ullAvailPageFile) / (1024 * 1024 * 1024);
|
||||
memory.VirtualMemoryAvailable.Value = (float)status.ullAvailPageFile / (1024 * 1024 * 1024);
|
||||
memory.VirtualMemoryLoad.Value = 100.0f - ((100.0f * status.ullAvailPageFile) / status.ullTotalPageFile);
|
||||
memory.VirtualMemoryLoad.Value = 100.0f - ((100.0f * status.ullAvailPageFile) / status.ullTotalPageFile);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ internal static class OpCode
|
||||
// }
|
||||
|
||||
private static readonly byte[] CpuId32 =
|
||||
{
|
||||
[
|
||||
0x55, // push ebp
|
||||
0x8B,
|
||||
0xEC, // mov ebp, esp
|
||||
@@ -100,10 +100,10 @@ internal static class OpCode
|
||||
0xC2,
|
||||
0x18,
|
||||
0x00 // ret 18h
|
||||
};
|
||||
];
|
||||
|
||||
private static readonly byte[] CpuId64Linux =
|
||||
{
|
||||
[
|
||||
0x49,
|
||||
0x89,
|
||||
0xD2, // mov r10, rdx
|
||||
@@ -131,10 +131,10 @@ internal static class OpCode
|
||||
0x11, // mov dword ptr [r9], edx
|
||||
0x5B, // pop rbx
|
||||
0xC3 // ret
|
||||
};
|
||||
];
|
||||
|
||||
private static readonly byte[] CpuId64Windows =
|
||||
{
|
||||
[
|
||||
0x48,
|
||||
0x89,
|
||||
0x5C,
|
||||
@@ -172,21 +172,21 @@ internal static class OpCode
|
||||
0x89,
|
||||
0x10, // mov dword ptr [rax], edx
|
||||
0xC3 // ret
|
||||
};
|
||||
];
|
||||
|
||||
// unsigned __int64 __stdcall rdtsc() {
|
||||
// return __rdtsc();
|
||||
// }
|
||||
|
||||
private static readonly byte[] Rdtsc32 =
|
||||
{
|
||||
[
|
||||
0x0F,
|
||||
0x31, // rdtsc
|
||||
0xC3 // ret
|
||||
};
|
||||
];
|
||||
|
||||
private static readonly byte[] Rdtsc64 =
|
||||
{
|
||||
[
|
||||
0x0F,
|
||||
0x31, // rdtsc
|
||||
0x48,
|
||||
@@ -197,7 +197,7 @@ internal static class OpCode
|
||||
0x0B,
|
||||
0xC2, // or rax, rdx
|
||||
0xC3 // ret
|
||||
};
|
||||
];
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
|
||||
public delegate bool CpuidDelegate(uint index, uint ecxValue, out uint eax, out uint ebx, out uint ecx, out uint edx);
|
||||
@@ -245,7 +245,7 @@ internal static class OpCode
|
||||
(int)mmapFlags.GetField("MAP_PRIVATE").GetValue(null));
|
||||
|
||||
if (mmap != null)
|
||||
_codeBuffer = (IntPtr)mmap.Invoke(null, new[] { IntPtr.Zero, _size, mmapProtsParam, mmapFlagsParam, -1, 0 });
|
||||
_codeBuffer = (IntPtr)mmap.Invoke(null, [IntPtr.Zero, _size, mmapProtsParam, mmapFlagsParam, -1, 0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -272,30 +272,16 @@ internal static class OpCode
|
||||
#if NETFRAMEWORK
|
||||
Assembly assembly = Assembly.Load("Mono.Posix, Version=2.0.0.0, Culture=neutral, " + "PublicKeyToken=0738eb9f132ed756");
|
||||
#else
|
||||
Assembly assembly = Assembly.Load("Mono.Posix.NETStandard, Version=1.0.0.0, Culture=neutral");
|
||||
Assembly assembly = Assembly.Load("Mono.Posix.NETStandard, Version=1.0.0.0, Culture=neutral");
|
||||
#endif
|
||||
|
||||
Type sysCall = assembly.GetType("Mono.Unix.Native.Syscall");
|
||||
MethodInfo method = sysCall.GetMethod("munmap");
|
||||
method?.Invoke(null, new object[] { _codeBuffer, _size });
|
||||
method?.Invoke(null, [_codeBuffer, _size]);
|
||||
}
|
||||
else
|
||||
{
|
||||
Interop.Kernel32.VirtualFree(_codeBuffer, UIntPtr.Zero, Interop.Kernel32.MEM.MEM_RELEASE);
|
||||
}
|
||||
}
|
||||
|
||||
public static bool CpuIdTx(uint index, uint ecxValue, out uint eax, out uint ebx, out uint ecx, out uint edx, GroupAffinity affinity)
|
||||
{
|
||||
GroupAffinity previousAffinity = ThreadAffinity.Set(affinity);
|
||||
if (previousAffinity == GroupAffinity.Undefined)
|
||||
{
|
||||
eax = ebx = ecx = edx = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
CpuId(index, ecxValue, out eax, out ebx, out ecx, out edx);
|
||||
ThreadAffinity.Set(previousAffinity);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
// All Rights Reserved.
|
||||
|
||||
using System;
|
||||
using Windows.Win32;
|
||||
using LibreHardwareMonitor.Interop;
|
||||
|
||||
namespace LibreHardwareMonitor.Hardware;
|
||||
@@ -16,7 +17,7 @@ internal static class ThreadAffinity
|
||||
/// </summary>
|
||||
static ThreadAffinity()
|
||||
{
|
||||
ProcessorGroupCount = Software.OperatingSystem.IsUnix ? 1 : Kernel32.GetActiveProcessorGroupCount();
|
||||
ProcessorGroupCount = Software.OperatingSystem.IsUnix ? 1 : PInvoke.GetActiveProcessorGroupCount();
|
||||
|
||||
if (ProcessorGroupCount < 1)
|
||||
ProcessorGroupCount = 1;
|
||||
@@ -58,7 +59,7 @@ internal static class ThreadAffinity
|
||||
|
||||
var groupAffinity = new Kernel32.GROUP_AFFINITY { Group = affinity.Group, Mask = (UIntPtr)affinity.Mask };
|
||||
|
||||
IntPtr currentThread = Kernel32.GetCurrentThread();
|
||||
IntPtr currentThread = PInvoke.GetCurrentThread();
|
||||
|
||||
return Kernel32.SetThreadGroupAffinity(currentThread,
|
||||
ref groupAffinity,
|
||||
|
||||
@@ -1,150 +0,0 @@
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
|
||||
// If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
// Copyright (C) LibreHardwareMonitor and Contributors.
|
||||
// All Rights Reserved.
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
namespace LibreHardwareMonitor.Interop;
|
||||
|
||||
internal class AdvApi32
|
||||
{
|
||||
private const string DllName = "advapi32.dll";
|
||||
|
||||
[DllImport(DllName, SetLastError = true, CallingConvention = CallingConvention.Winapi)]
|
||||
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
|
||||
internal static extern IntPtr OpenSCManager(string lpMachineName, string lpDatabaseName, SC_MANAGER_ACCESS_MASK dwDesiredAccess);
|
||||
|
||||
[DllImport(DllName, CallingConvention = CallingConvention.Winapi)]
|
||||
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
internal static extern bool CloseServiceHandle(IntPtr hSCObject);
|
||||
|
||||
[DllImport(DllName, CallingConvention = CallingConvention.Winapi, SetLastError = true)]
|
||||
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
|
||||
internal static extern IntPtr CreateService
|
||||
(
|
||||
IntPtr hSCManager,
|
||||
string lpServiceName,
|
||||
string lpDisplayName,
|
||||
SERVICE_ACCESS_MASK dwDesiredAccess,
|
||||
SERVICE_TYPE dwServiceType,
|
||||
SERVICE_START dwStartType,
|
||||
SERVICE_ERROR dwErrorControl,
|
||||
string lpBinaryPathName,
|
||||
string lpLoadOrderGroup,
|
||||
string lpdwTagId,
|
||||
string lpDependencies,
|
||||
string lpServiceStartName,
|
||||
string lpPassword);
|
||||
|
||||
[DllImport(DllName, CallingConvention = CallingConvention.Winapi, SetLastError = true)]
|
||||
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
|
||||
internal static extern IntPtr OpenService(IntPtr hSCManager, string lpServiceName, SERVICE_ACCESS_MASK dwDesiredAccess);
|
||||
|
||||
[DllImport(DllName, CallingConvention = CallingConvention.Winapi, SetLastError = true)]
|
||||
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
internal static extern bool DeleteService(IntPtr hService);
|
||||
|
||||
[DllImport(DllName, CallingConvention = CallingConvention.Winapi, SetLastError = true)]
|
||||
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
internal static extern bool StartService(IntPtr hService, uint dwNumServiceArgs, string[] lpServiceArgVectors);
|
||||
|
||||
[DllImport(DllName, CallingConvention = CallingConvention.Winapi, SetLastError = true)]
|
||||
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
internal static extern bool ControlService(IntPtr hService, SERVICE_CONTROL dwControl, ref SERVICE_STATUS lpServiceStatus);
|
||||
|
||||
[Flags]
|
||||
internal enum SC_MANAGER_ACCESS_MASK : uint
|
||||
{
|
||||
SC_MANAGER_CONNECT = 0x00001,
|
||||
SC_MANAGER_CREATE_SERVICE = 0x00002,
|
||||
SC_MANAGER_ENUMERATE_SERVICE = 0x00004,
|
||||
SC_MANAGER_LOCK = 0x00008,
|
||||
SC_MANAGER_QUERY_LOCK_STATUS = 0x00010,
|
||||
SC_MANAGER_MODIFY_BOOT_CONFIG = 0x00020,
|
||||
SC_MANAGER_ALL_ACCESS = 0xF003F
|
||||
}
|
||||
|
||||
internal enum SERVICE_ACCESS_MASK : uint
|
||||
{
|
||||
SERVICE_QUERY_CONFIG = 0x00001,
|
||||
SERVICE_CHANGE_CONFIG = 0x00002,
|
||||
SERVICE_QUERY_STATUS = 0x00004,
|
||||
SERVICE_ENUMERATE_DEPENDENTS = 0x00008,
|
||||
SERVICE_START = 0x00010,
|
||||
SERVICE_STOP = 0x00020,
|
||||
SERVICE_PAUSE_CONTINUE = 0x00040,
|
||||
SERVICE_INTERROGATE = 0x00080,
|
||||
SERVICE_USER_DEFINED_CONTROL = 0x00100,
|
||||
SERVICE_ALL_ACCESS = 0xF01FF
|
||||
}
|
||||
|
||||
internal enum SERVICE_TYPE : uint
|
||||
{
|
||||
SERVICE_DRIVER = 0x0000000B,
|
||||
SERVICE_WIN32 = 0x00000030,
|
||||
SERVICE_ADAPTER = 0x00000004,
|
||||
SERVICE_FILE_SYSTEM_DRIVER = 0x00000002,
|
||||
SERVICE_KERNEL_DRIVER = 0x00000001,
|
||||
SERVICE_RECOGNIZER_DRIVER = 0x00000008,
|
||||
SERVICE_WIN32_OWN_PROCESS = 0x00000010,
|
||||
SERVICE_WIN32_SHARE_PROCESS = 0x00000020,
|
||||
SERVICE_USER_OWN_PROCESS = 0x00000050,
|
||||
SERVICE_USER_SHARE_PROCESS = 0x00000060,
|
||||
SERVICE_INTERACTIVE_PROCESS = 0x00000100
|
||||
}
|
||||
|
||||
internal enum SERVICE_START : uint
|
||||
{
|
||||
SERVICE_BOOT_START = 0,
|
||||
SERVICE_SYSTEM_START = 1,
|
||||
SERVICE_AUTO_START = 2,
|
||||
SERVICE_DEMAND_START = 3,
|
||||
SERVICE_DISABLED = 4
|
||||
}
|
||||
|
||||
internal enum SERVICE_ERROR : uint
|
||||
{
|
||||
SERVICE_ERROR_IGNORE = 0,
|
||||
SERVICE_ERROR_NORMAL = 1,
|
||||
SERVICE_ERROR_SEVERE = 2,
|
||||
SERVICE_ERROR_CRITICAL = 3
|
||||
}
|
||||
|
||||
internal enum SERVICE_CONTROL : uint
|
||||
{
|
||||
SERVICE_CONTROL_STOP = 1,
|
||||
SERVICE_CONTROL_PAUSE = 2,
|
||||
SERVICE_CONTROL_CONTINUE = 3,
|
||||
SERVICE_CONTROL_INTERROGATE = 4,
|
||||
SERVICE_CONTROL_SHUTDOWN = 5,
|
||||
SERVICE_CONTROL_PARAMCHANGE = 6,
|
||||
SERVICE_CONTROL_NETBINDADD = 7,
|
||||
SERVICE_CONTROL_NETBINDREMOVE = 8,
|
||||
SERVICE_CONTROL_NETBINDENABLE = 9,
|
||||
SERVICE_CONTROL_NETBINDDISABLE = 10,
|
||||
SERVICE_CONTROL_DEVICEEVENT = 11,
|
||||
SERVICE_CONTROL_HARDWAREPROFILECHANGE = 12,
|
||||
SERVICE_CONTROL_POWEREVENT = 13,
|
||||
SERVICE_CONTROL_SESSIONCHANGE = 14
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
internal struct SERVICE_STATUS
|
||||
{
|
||||
public uint dwServiceType;
|
||||
public uint dwCurrentState;
|
||||
public uint dwControlsAccepted;
|
||||
public uint dwWin32ExitCode;
|
||||
public uint dwServiceSpecificExitCode;
|
||||
public uint dwCheckPoint;
|
||||
public uint dwWaitHint;
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
|
||||
// If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
// Copyright (C) LibreHardwareMonitor and Contributors.
|
||||
// All Rights Reserved.
|
||||
|
||||
// ReSharper disable IdentifierTypo
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace LibreHardwareMonitor.Interop;
|
||||
|
||||
internal static class CfgMgr32
|
||||
{
|
||||
internal const uint CM_GET_DEVICE_INTERFACE_LIST_PRESENT = 0;
|
||||
internal const int CR_SUCCESS = 0;
|
||||
|
||||
internal const string DllName = "CfgMgr32.dll";
|
||||
internal static Guid GUID_DISPLAY_DEVICE_ARRIVAL = new("1CA05180-A699-450A-9A0C-DE4FBE3DDD89");
|
||||
|
||||
[DllImport(DllName, CharSet = CharSet.Unicode)]
|
||||
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
|
||||
internal static extern uint CM_Get_Device_Interface_List_Size(out uint size, ref Guid interfaceClassGuid, string deviceID, uint flags);
|
||||
|
||||
[DllImport(DllName, CharSet = CharSet.Unicode)]
|
||||
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
|
||||
internal static extern uint CM_Get_Device_Interface_List(ref Guid interfaceClassGuid, string deviceID, char[] buffer, uint bufferLength, uint flags);
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
|
||||
// If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
// Copyright (C) LibreHardwareMonitor and Contributors.
|
||||
// All Rights Reserved.
|
||||
|
||||
// ReSharper disable IdentifierTypo
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace LibreHardwareMonitor.Interop;
|
||||
|
||||
internal static class D3dkmdt
|
||||
{
|
||||
internal enum DXGK_ENGINE_TYPE
|
||||
{
|
||||
DXGK_ENGINE_TYPE_OTHER = 0,
|
||||
DXGK_ENGINE_TYPE_3D = 1,
|
||||
DXGK_ENGINE_TYPE_VIDEO_DECODE = 2,
|
||||
DXGK_ENGINE_TYPE_VIDEO_ENCODE = 3,
|
||||
DXGK_ENGINE_TYPE_VIDEO_PROCESSING = 4,
|
||||
DXGK_ENGINE_TYPE_SCENE_ASSEMBLY = 5,
|
||||
DXGK_ENGINE_TYPE_COPY = 6,
|
||||
DXGK_ENGINE_TYPE_OVERLAY = 7,
|
||||
DXGK_ENGINE_TYPE_CRYPTO,
|
||||
DXGK_ENGINE_TYPE_MAX
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct DXGK_NODEMETADATA_FLAGS
|
||||
{
|
||||
public uint Value;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Unicode)]
|
||||
internal struct DXGK_NODEMETADATA
|
||||
{
|
||||
public DXGK_ENGINE_TYPE EngineType;
|
||||
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
|
||||
public string FriendlyName;
|
||||
|
||||
public DXGK_NODEMETADATA_FLAGS Flags;
|
||||
public byte GpuMmuSupported;
|
||||
public byte IoMmuSupported;
|
||||
}
|
||||
}
|
||||
@@ -1,562 +0,0 @@
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
|
||||
// If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
// Copyright (C) LibreHardwareMonitor and Contributors.
|
||||
// All Rights Reserved.
|
||||
|
||||
// ReSharper disable IdentifierTypo
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace LibreHardwareMonitor.Interop;
|
||||
|
||||
internal static class D3dkmth
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct D3DKMT_CLOSEADAPTER
|
||||
{
|
||||
public uint hAdapter;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct D3DKMT_QUERYADAPTERINFO
|
||||
{
|
||||
public uint hAdapter;
|
||||
public KMTQUERYADAPTERINFOTYPE Type;
|
||||
public IntPtr pPrivateDriverData;
|
||||
public int PrivateDriverDataSize;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct D3DKMT_OPENADAPTERFROMDEVICENAME
|
||||
{
|
||||
[MarshalAs(UnmanagedType.LPWStr)]
|
||||
public string pDeviceName;
|
||||
|
||||
public uint hAdapter;
|
||||
public WinNt.LUID AdapterLuid;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct D3DKMT_ADAPTERTYPE
|
||||
{
|
||||
public D3DKMT_ADAPTERTYPE_FLAGS Value;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct D3DKMT_QUERYSTATISTICS_QUERY_SEGMENT
|
||||
{
|
||||
public uint SegmentId;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct D3DKMT_QUERYSTATISTICS_QUERY_NODE
|
||||
{
|
||||
public uint NodeId;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct D3DKMT_QUERYSTATISTICS_QUERY_VIDPNSOURCE
|
||||
{
|
||||
public uint VidPnSourceId;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct D3DKMT_QUERYSTATISTICS_REFERENCE_DMA_BUFFER
|
||||
{
|
||||
public uint NbCall;
|
||||
public uint NbAllocationsReferenced;
|
||||
public uint MaxNbAllocationsReferenced;
|
||||
public uint NbNULLReference;
|
||||
public uint NbWriteReference;
|
||||
public uint NbRenamedAllocationsReferenced;
|
||||
public uint NbIterationSearchingRenamedAllocation;
|
||||
public uint NbLockedAllocationReferenced;
|
||||
public uint NbAllocationWithValidPrepatchingInfoReferenced;
|
||||
public uint NbAllocationWithInvalidPrepatchingInfoReferenced;
|
||||
public uint NbDMABufferSuccessfullyPrePatched;
|
||||
public uint NbPrimariesReferencesOverflow;
|
||||
public uint NbAllocationWithNonPreferredResources;
|
||||
public uint NbAllocationInsertedInMigrationTable;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct D3DKMT_SEGMENTSIZEINFO
|
||||
{
|
||||
public ulong DedicatedVideoMemorySize;
|
||||
public ulong DedicatedSystemMemorySize;
|
||||
public ulong SharedSystemMemorySize;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct D3DKMT_QUERYSTATISTICS_RENAMING
|
||||
{
|
||||
public uint NbAllocationsRenamed;
|
||||
public uint NbAllocationsShrinked;
|
||||
public uint NbRenamedBuffer;
|
||||
public uint MaxRenamingListLength;
|
||||
public uint NbFailuresDueToRenamingLimit;
|
||||
public uint NbFailuresDueToCreateAllocation;
|
||||
public uint NbFailuresDueToOpenAllocation;
|
||||
public uint NbFailuresDueToLowResource;
|
||||
public uint NbFailuresDueToNonRetiredLimit;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct D3DKMT_QUERYSTATISTICS_COUNTER
|
||||
{
|
||||
public uint Count;
|
||||
public ulong Bytes;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct D3DKMT_QUERYSTATISTICS_PREPRATION
|
||||
{
|
||||
public uint BroadcastStall;
|
||||
public uint NbDMAPrepared;
|
||||
public uint NbDMAPreparedLongPath;
|
||||
public uint ImmediateHighestPreparationPass;
|
||||
public D3DKMT_QUERYSTATISTICS_COUNTER AllocationsTrimmed;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct D3DKMT_QUERYSTATISTICS_PAGING_FAULT
|
||||
{
|
||||
public D3DKMT_QUERYSTATISTICS_COUNTER Faults;
|
||||
public D3DKMT_QUERYSTATISTICS_COUNTER FaultsFirstTimeAccess;
|
||||
public D3DKMT_QUERYSTATISTICS_COUNTER FaultsReclaimed;
|
||||
public D3DKMT_QUERYSTATISTICS_COUNTER FaultsMigration;
|
||||
public D3DKMT_QUERYSTATISTICS_COUNTER FaultsIncorrectResource;
|
||||
public D3DKMT_QUERYSTATISTICS_COUNTER FaultsLostContent;
|
||||
public D3DKMT_QUERYSTATISTICS_COUNTER FaultsEvicted;
|
||||
public D3DKMT_QUERYSTATISTICS_COUNTER AllocationsMEM_RESET;
|
||||
public D3DKMT_QUERYSTATISTICS_COUNTER AllocationsUnresetSuccess;
|
||||
public D3DKMT_QUERYSTATISTICS_COUNTER AllocationsUnresetFail;
|
||||
|
||||
public uint AllocationsUnresetSuccessRead;
|
||||
public uint AllocationsUnresetFailRead;
|
||||
|
||||
public D3DKMT_QUERYSTATISTICS_COUNTER Evictions;
|
||||
public D3DKMT_QUERYSTATISTICS_COUNTER EvictionsDueToPreparation;
|
||||
public D3DKMT_QUERYSTATISTICS_COUNTER EvictionsDueToLock;
|
||||
public D3DKMT_QUERYSTATISTICS_COUNTER EvictionsDueToClose;
|
||||
public D3DKMT_QUERYSTATISTICS_COUNTER EvictionsDueToPurge;
|
||||
public D3DKMT_QUERYSTATISTICS_COUNTER EvictionsDueToSuspendCPUAccess;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct D3DKMT_QUERYSTATISTICS_PAGING_TRANSFER
|
||||
{
|
||||
public ulong BytesFilled;
|
||||
public ulong BytesDiscarded;
|
||||
public ulong BytesMappedIntoAperture;
|
||||
public ulong BytesUnmappedFromAperture;
|
||||
public ulong BytesTransferredFromMdlToMemory;
|
||||
public ulong BytesTransferredFromMemoryToMdl;
|
||||
public ulong BytesTransferredFromApertureToMemory;
|
||||
public ulong BytesTransferredFromMemoryToAperture;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct D3DKMT_QUERYSTATISTICS_SWIZZLING_RANGE
|
||||
{
|
||||
public uint NbRangesAcquired;
|
||||
public uint NbRangesReleased;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct D3DKMT_QUERYSTATISTICS_LOCKS
|
||||
{
|
||||
public uint NbLocks;
|
||||
public uint NbLocksWaitFlag;
|
||||
public uint NbLocksDiscardFlag;
|
||||
public uint NbLocksNoOverwrite;
|
||||
public uint NbLocksNoReadSync;
|
||||
public uint NbLocksLinearization;
|
||||
public uint NbComplexLocks;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct D3DKMT_QUERYSTATISTICS_ALLOCATIONS
|
||||
{
|
||||
public D3DKMT_QUERYSTATISTICS_COUNTER Created;
|
||||
public D3DKMT_QUERYSTATISTICS_COUNTER Destroyed;
|
||||
public D3DKMT_QUERYSTATISTICS_COUNTER Opened;
|
||||
public D3DKMT_QUERYSTATISTICS_COUNTER Closed;
|
||||
public D3DKMT_QUERYSTATISTICS_COUNTER MigratedSuccess;
|
||||
public D3DKMT_QUERYSTATISTICS_COUNTER MigratedFail;
|
||||
public D3DKMT_QUERYSTATISTICS_COUNTER MigratedAbandoned;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct D3DKMT_QUERYSTATISTICS_TERMINATIONS
|
||||
{
|
||||
public D3DKMT_QUERYSTATISTICS_COUNTER TerminatedShared;
|
||||
public D3DKMT_QUERYSTATISTICS_COUNTER TerminatedNonShared;
|
||||
public D3DKMT_QUERYSTATISTICS_COUNTER DestroyedShared;
|
||||
public D3DKMT_QUERYSTATISTICS_COUNTER DestroyedNonShared;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct D3DKMT_QUERYSTATISTICS_ADAPTER_INFORMATION
|
||||
{
|
||||
public uint NbSegments;
|
||||
public uint NodeCount;
|
||||
public uint VidPnSourceCount;
|
||||
|
||||
public uint VSyncEnabled;
|
||||
public uint TdrDetectedCount;
|
||||
|
||||
public long ZeroLengthDmaBuffers;
|
||||
public ulong RestartedPeriod;
|
||||
|
||||
public D3DKMT_QUERYSTATISTICS_REFERENCE_DMA_BUFFER ReferenceDmaBuffer;
|
||||
public D3DKMT_QUERYSTATISTICS_RENAMING Renaming;
|
||||
public D3DKMT_QUERYSTATISTICS_PREPRATION Preparation;
|
||||
public D3DKMT_QUERYSTATISTICS_PAGING_FAULT PagingFault;
|
||||
public D3DKMT_QUERYSTATISTICS_PAGING_TRANSFER PagingTransfer;
|
||||
public D3DKMT_QUERYSTATISTICS_SWIZZLING_RANGE SwizzlingRange;
|
||||
public D3DKMT_QUERYSTATISTICS_LOCKS Locks;
|
||||
public D3DKMT_QUERYSTATISTICS_ALLOCATIONS Allocations;
|
||||
public D3DKMT_QUERYSTATISTICS_TERMINATIONS Terminations;
|
||||
|
||||
private readonly ulong Reserved;
|
||||
private readonly ulong Reserved1;
|
||||
private readonly ulong Reserved2;
|
||||
private readonly ulong Reserved3;
|
||||
private readonly ulong Reserved4;
|
||||
private readonly ulong Reserved5;
|
||||
private readonly ulong Reserved6;
|
||||
private readonly ulong Reserved7;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct D3DKMT_QUERYSTATISTICS_MEMORY
|
||||
{
|
||||
public ulong TotalBytesEvicted;
|
||||
public uint AllocsCommitted;
|
||||
public uint AllocsResident;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal unsafe struct D3DKMT_QUERYSTATISTICS_SEGMENT_INFORMATION
|
||||
{
|
||||
public ulong CommitLimit;
|
||||
public ulong BytesCommitted;
|
||||
public ulong BytesResident;
|
||||
public D3DKMT_QUERYSTATISTICS_MEMORY Memory;
|
||||
public uint Aperture; // boolean
|
||||
public fixed ulong TotalBytesEvictedByPriority[5]; // D3DKMT_QUERYSTATISTICS_SEGMENT_PREFERENCE_MAX
|
||||
public ulong SystemMemoryEndAddress;
|
||||
public D3DKMT_QUERYSTATISTICS_SEGMENT_INFORMATION_POWER_FLAGS PowerFlags;
|
||||
public fixed ulong Reserved[6];
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Explicit)]
|
||||
internal struct D3DKMT_QUERYSTATISTICS_SEGMENT_INFORMATION_POWER_FLAGS
|
||||
{
|
||||
[FieldOffset(0)]
|
||||
public ulong PreservedDuringStandby;
|
||||
|
||||
[FieldOffset(1)]
|
||||
public ulong PreservedDuringHibernate;
|
||||
|
||||
[FieldOffset(2)]
|
||||
public ulong PartiallyPreservedDuringHibernate;
|
||||
|
||||
[FieldOffset(3)]
|
||||
public ulong Reserved;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct D3DKMT_QUERYSTATISTICS_VIDEO_MEMORY
|
||||
{
|
||||
public uint AllocsCommitted;
|
||||
public D3DKMT_QUERYSTATISTICS_COUNTER AllocsResidentIn0;
|
||||
public D3DKMT_QUERYSTATISTICS_COUNTER AllocsResidentIn1;
|
||||
public D3DKMT_QUERYSTATISTICS_COUNTER AllocsResidentIn2;
|
||||
public D3DKMT_QUERYSTATISTICS_COUNTER AllocsResidentIn3;
|
||||
public D3DKMT_QUERYSTATISTICS_COUNTER AllocsResidentIn4;
|
||||
public D3DKMT_QUERYSTATISTICS_COUNTER AllocsResidentInNonPreferred;
|
||||
public ulong TotalBytesEvictedDueToPreparation;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct D3DKMT_QUERYSTATISTICS_PROCESS_SEGMENT_POLICY
|
||||
{
|
||||
public ulong UseMRU;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal unsafe struct D3DKMT_QUERYSTATISTICS_PROCESS_SEGMENT_INFORMATION
|
||||
{
|
||||
public ulong BytesCommitted;
|
||||
public ulong MaximumWorkingSet;
|
||||
public ulong MinimumWorkingSet;
|
||||
|
||||
public uint NbReferencedAllocationEvictedInPeriod;
|
||||
|
||||
public D3DKMT_QUERYSTATISTICS_VIDEO_MEMORY VideoMemory;
|
||||
public D3DKMT_QUERYSTATISTICS_PROCESS_SEGMENT_POLICY _Policy;
|
||||
|
||||
public fixed ulong Reserved[8];
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct D3DKMT_QUERYSTATISTICS_PREEMPTION_INFORMATION
|
||||
{
|
||||
public uint PreemptionCounter;
|
||||
public uint PreemptionCounter1;
|
||||
public uint PreemptionCounter2;
|
||||
public uint PreemptionCounter3;
|
||||
public uint PreemptionCounter4;
|
||||
public uint PreemptionCounter5;
|
||||
public uint PreemptionCounter6;
|
||||
public uint PreemptionCounter7;
|
||||
public uint PreemptionCounter8;
|
||||
public uint PreemptionCounter9;
|
||||
public uint PreemptionCounter10;
|
||||
public uint PreemptionCounter11;
|
||||
public uint PreemptionCounter12;
|
||||
public uint PreemptionCounter13;
|
||||
public uint PreemptionCounter14;
|
||||
public uint PreemptionCounter15;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal unsafe struct D3DKMT_QUERYSTATISTICS_PROCESS_NODE_INFORMATION
|
||||
{
|
||||
public WinNt.LARGE_INTEGER RunningTime; // 100ns
|
||||
public uint ContextSwitch;
|
||||
private readonly D3DKMT_QUERYSTATISTICS_PREEMPTION_INFORMATION PreemptionStatistics;
|
||||
private readonly D3DKMT_QUERYSTATISTICS_PACKET_INFORMATION PacketStatistics;
|
||||
private fixed ulong Reserved[8];
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal unsafe struct D3DKMT_QUERYSTATISTICS_NODE_INFORMATION
|
||||
{
|
||||
public D3DKMT_QUERYSTATISTICS_PROCESS_NODE_INFORMATION GlobalInformation; // global
|
||||
|
||||
public D3DKMT_QUERYSTATISTICS_PROCESS_NODE_INFORMATION SystemInformation; // system thread
|
||||
|
||||
//public UInt32 NodeId; // Win10
|
||||
public fixed ulong Reserved[8];
|
||||
}
|
||||
|
||||
internal struct D3DKMT_QUERYSTATISTICS_DMA_PACKET_TYPE_INFORMATION
|
||||
{
|
||||
public uint PacketSubmitted;
|
||||
public uint PacketCompleted;
|
||||
public uint PacketPreempted;
|
||||
public uint PacketFaulted;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct D3DKMT_QUERYSTATISTICS_QUEUE_PACKET_TYPE_INFORMATION
|
||||
{
|
||||
public uint PacketSubmited;
|
||||
public uint PacketCompleted;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct D3DKMT_QUERYSTATISTICS_PACKET_INFORMATION
|
||||
{
|
||||
public D3DKMT_QUERYSTATISTICS_QUEUE_PACKET_TYPE_INFORMATION QueuePacket;
|
||||
public D3DKMT_QUERYSTATISTICS_QUEUE_PACKET_TYPE_INFORMATION QueuePacket1;
|
||||
public D3DKMT_QUERYSTATISTICS_QUEUE_PACKET_TYPE_INFORMATION QueuePacket2;
|
||||
public D3DKMT_QUERYSTATISTICS_QUEUE_PACKET_TYPE_INFORMATION QueuePacket3;
|
||||
public D3DKMT_QUERYSTATISTICS_QUEUE_PACKET_TYPE_INFORMATION QueuePacket4;
|
||||
public D3DKMT_QUERYSTATISTICS_QUEUE_PACKET_TYPE_INFORMATION QueuePacket5;
|
||||
public D3DKMT_QUERYSTATISTICS_QUEUE_PACKET_TYPE_INFORMATION QueuePacket6;
|
||||
public D3DKMT_QUERYSTATISTICS_QUEUE_PACKET_TYPE_INFORMATION QueuePacket7;
|
||||
|
||||
public D3DKMT_QUERYSTATISTICS_DMA_PACKET_TYPE_INFORMATION DmaPacket;
|
||||
public D3DKMT_QUERYSTATISTICS_DMA_PACKET_TYPE_INFORMATION DmaPacket1;
|
||||
public D3DKMT_QUERYSTATISTICS_DMA_PACKET_TYPE_INFORMATION DmaPacket2;
|
||||
public D3DKMT_QUERYSTATISTICS_DMA_PACKET_TYPE_INFORMATION DmaPacket3;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Explicit)]
|
||||
internal struct D3DKMT_QUERYSTATISTICS_RESULT
|
||||
{
|
||||
[FieldOffset(0), MarshalAs(UnmanagedType.Struct)]
|
||||
public D3DKMT_QUERYSTATISTICS_ADAPTER_INFORMATION AdapterInformation;
|
||||
|
||||
[FieldOffset(0), MarshalAs(UnmanagedType.Struct)]
|
||||
public D3DKMT_QUERYSTATISTICS_SEGMENT_INFORMATION SegmentInformation;
|
||||
|
||||
[FieldOffset(0), MarshalAs(UnmanagedType.Struct)]
|
||||
public D3DKMT_QUERYSTATISTICS_PROCESS_SEGMENT_INFORMATION ProcessSegmentInformation;
|
||||
|
||||
[FieldOffset(0), MarshalAs(UnmanagedType.Struct)]
|
||||
public D3DKMT_QUERYSTATISTICS_NODE_INFORMATION NodeInformation;
|
||||
|
||||
// D3DKMT_QUERYSTATISTICS_PROCESS_INFORMATION ProcessInformation;
|
||||
// D3DKMT_QUERYSTATISTICS_PROCESS_NODE_INFORMATION ProcessNodeInformation;
|
||||
// D3DKMT_QUERYSTATISTICS_PHYSICAL_ADAPTER_INFORMATION PhysAdapterInformation;
|
||||
// D3DKMT_QUERYSTATISTICS_SEGMENT_INFORMATION_V1 SegmentInformationV1; // WIN7
|
||||
// D3DKMT_QUERYSTATISTICS_VIDPNSOURCE_INFORMATION VidPnSourceInformation;
|
||||
// D3DKMT_QUERYSTATISTICS_PROCESS_ADAPTER_INFORMATION ProcessAdapterInformation;
|
||||
// D3DKMT_QUERYSTATISTICS_PROCESS_VIDPNSOURCE_INFORMATION ProcessVidPnSourceInformation;
|
||||
// D3DKMT_QUERYSTATISTICS_PROCESS_SEGMENT_GROUP_INFORMATION ProcessSegmentGroupInformation;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Explicit)]
|
||||
internal struct D3DKMT_QUERYSTATISTICS_QUERY_ELEMENT
|
||||
{
|
||||
[FieldOffset(0)]
|
||||
public D3DKMT_QUERYSTATISTICS_QUERY_SEGMENT QuerySegment;
|
||||
|
||||
[FieldOffset(0)]
|
||||
public D3DKMT_QUERYSTATISTICS_QUERY_SEGMENT QueryProcessSegment;
|
||||
|
||||
[FieldOffset(0)]
|
||||
public D3DKMT_QUERYSTATISTICS_QUERY_NODE QueryNode;
|
||||
|
||||
[FieldOffset(0)]
|
||||
public D3DKMT_QUERYSTATISTICS_QUERY_NODE QueryProcessNode;
|
||||
|
||||
[FieldOffset(0)]
|
||||
public D3DKMT_QUERYSTATISTICS_QUERY_VIDPNSOURCE QueryVidPnSource;
|
||||
|
||||
[FieldOffset(0)]
|
||||
public D3DKMT_QUERYSTATISTICS_QUERY_VIDPNSOURCE QueryProcessVidPnSource;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct D3DKMT_QUERYSTATISTICS
|
||||
{
|
||||
public D3DKMT_QUERYSTATISTICS_TYPE Type;
|
||||
public WinNt.LUID AdapterLuid;
|
||||
public IntPtr ProcessHandle;
|
||||
public D3DKMT_QUERYSTATISTICS_RESULT QueryResult;
|
||||
public D3DKMT_QUERYSTATISTICS_QUERY_ELEMENT QueryElement;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
internal struct D3DKMT_NODEMETADATA
|
||||
{
|
||||
public uint NodeOrdinalAndAdapterIndex;
|
||||
public D3dkmdt.DXGK_NODEMETADATA NodeData;
|
||||
}
|
||||
|
||||
[Flags]
|
||||
internal enum D3DKMT_ADAPTERTYPE_FLAGS : uint
|
||||
{
|
||||
RenderSupported = 0,
|
||||
DisplaySupported = 1,
|
||||
SoftwareDevice = 2,
|
||||
PostDevice = 4,
|
||||
HybridDiscrete = 8,
|
||||
HybridIntegrated = 16,
|
||||
IndirectDisplayDevice = 32,
|
||||
Paravirtualized = 64,
|
||||
ACGSupported = 128,
|
||||
SupportSetTimingsFromVidPn = 256,
|
||||
Detachable = 512,
|
||||
ComputeOnly = 1024,
|
||||
Prototype = 2045
|
||||
}
|
||||
|
||||
internal enum D3DKMT_QUERYSTATISTICS_TYPE
|
||||
{
|
||||
D3DKMT_QUERYSTATISTICS_ADAPTER,
|
||||
D3DKMT_QUERYSTATISTICS_PROCESS,
|
||||
D3DKMT_QUERYSTATISTICS_PROCESS_ADAPTER,
|
||||
D3DKMT_QUERYSTATISTICS_SEGMENT,
|
||||
D3DKMT_QUERYSTATISTICS_PROCESS_SEGMENT,
|
||||
D3DKMT_QUERYSTATISTICS_NODE,
|
||||
D3DKMT_QUERYSTATISTICS_PROCESS_NODE,
|
||||
D3DKMT_QUERYSTATISTICS_VIDPNSOURCE,
|
||||
D3DKMT_QUERYSTATISTICS_PROCESS_VIDPNSOURCE,
|
||||
D3DKMT_QUERYSTATISTICS_PROCESS_SEGMENT_GROUP,
|
||||
D3DKMT_QUERYSTATISTICS_PHYSICAL_ADAPTER
|
||||
}
|
||||
|
||||
internal enum D3DKMT_QUERYSTATISTICS_DMA_PACKET_TYPE
|
||||
{
|
||||
D3DKMT_ClientRenderBuffer = 0,
|
||||
D3DKMT_ClientPagingBuffer = 1,
|
||||
D3DKMT_SystemPagingBuffer = 2,
|
||||
D3DKMT_SystemPreemptionBuffer = 3,
|
||||
D3DKMT_DmaPacketTypeMax
|
||||
}
|
||||
|
||||
internal enum KMTQUERYADAPTERINFOTYPE
|
||||
{
|
||||
KMTQAITYPE_UMDRIVERPRIVATE = 0,
|
||||
KMTQAITYPE_UMDRIVERNAME = 1,
|
||||
KMTQAITYPE_UMOPENGLINFO = 2,
|
||||
KMTQAITYPE_GETSEGMENTSIZE = 3,
|
||||
KMTQAITYPE_ADAPTERGUID = 4,
|
||||
KMTQAITYPE_FLIPQUEUEINFO = 5,
|
||||
KMTQAITYPE_ADAPTERADDRESS = 6,
|
||||
KMTQAITYPE_SETWORKINGSETINFO = 7,
|
||||
KMTQAITYPE_ADAPTERREGISTRYINFO = 8,
|
||||
KMTQAITYPE_CURRENTDISPLAYMODE = 9,
|
||||
KMTQAITYPE_MODELIST = 10,
|
||||
KMTQAITYPE_CHECKDRIVERUPDATESTATUS = 11,
|
||||
KMTQAITYPE_VIRTUALADDRESSINFO = 12,
|
||||
KMTQAITYPE_DRIVERVERSION = 13,
|
||||
KMTQAITYPE_ADAPTERTYPE = 15,
|
||||
KMTQAITYPE_OUTPUTDUPLCONTEXTSCOUNT = 16,
|
||||
KMTQAITYPE_WDDM_1_2_CAPS = 17,
|
||||
KMTQAITYPE_UMD_DRIVER_VERSION = 18,
|
||||
KMTQAITYPE_DIRECTFLIP_SUPPORT = 19,
|
||||
KMTQAITYPE_MULTIPLANEOVERLAY_SUPPORT = 20,
|
||||
KMTQAITYPE_DLIST_DRIVER_NAME = 21,
|
||||
KMTQAITYPE_WDDM_1_3_CAPS = 22,
|
||||
KMTQAITYPE_MULTIPLANEOVERLAY_HUD_SUPPORT = 23,
|
||||
KMTQAITYPE_WDDM_2_0_CAPS = 24,
|
||||
KMTQAITYPE_NODEMETADATA = 25,
|
||||
KMTQAITYPE_CPDRIVERNAME = 26,
|
||||
KMTQAITYPE_XBOX = 27,
|
||||
KMTQAITYPE_INDEPENDENTFLIP_SUPPORT = 28,
|
||||
KMTQAITYPE_MIRACASTCOMPANIONDRIVERNAME = 29,
|
||||
KMTQAITYPE_PHYSICALADAPTERCOUNT = 30,
|
||||
KMTQAITYPE_PHYSICALADAPTERDEVICEIDS = 31,
|
||||
KMTQAITYPE_DRIVERCAPS_EXT = 32,
|
||||
KMTQAITYPE_QUERY_MIRACAST_DRIVER_TYPE = 33,
|
||||
KMTQAITYPE_QUERY_GPUMMU_CAPS = 34,
|
||||
KMTQAITYPE_QUERY_MULTIPLANEOVERLAY_DECODE_SUPPORT = 35,
|
||||
KMTQAITYPE_QUERY_HW_PROTECTION_TEARDOWN_COUNT = 36,
|
||||
KMTQAITYPE_QUERY_ISBADDRIVERFORHWPROTECTIONDISABLED = 37,
|
||||
KMTQAITYPE_MULTIPLANEOVERLAY_SECONDARY_SUPPORT = 38,
|
||||
KMTQAITYPE_INDEPENDENTFLIP_SECONDARY_SUPPORT = 39,
|
||||
KMTQAITYPE_PANELFITTER_SUPPORT = 40,
|
||||
KMTQAITYPE_PHYSICALADAPTERPNPKEY = 41,
|
||||
KMTQAITYPE_GETSEGMENTGROUPSIZE = 42,
|
||||
KMTQAITYPE_MPO3DDI_SUPPORT = 43,
|
||||
KMTQAITYPE_HWDRM_SUPPORT = 44,
|
||||
KMTQAITYPE_MPOKERNELCAPS_SUPPORT = 45,
|
||||
KMTQAITYPE_MULTIPLANEOVERLAY_STRETCH_SUPPORT = 46,
|
||||
KMTQAITYPE_GET_DEVICE_VIDPN_OWNERSHIP_INFO = 47,
|
||||
KMTQAITYPE_QUERYREGISTRY = 48,
|
||||
KMTQAITYPE_KMD_DRIVER_VERSION = 49,
|
||||
KMTQAITYPE_BLOCKLIST_KERNEL = 50,
|
||||
KMTQAITYPE_BLOCKLIST_RUNTIME = 51,
|
||||
KMTQAITYPE_ADAPTERGUID_RENDER = 52,
|
||||
KMTQAITYPE_ADAPTERADDRESS_RENDER = 53,
|
||||
KMTQAITYPE_ADAPTERREGISTRYINFO_RENDER = 54,
|
||||
KMTQAITYPE_CHECKDRIVERUPDATESTATUS_RENDER = 55,
|
||||
KMTQAITYPE_DRIVERVERSION_RENDER = 56,
|
||||
KMTQAITYPE_ADAPTERTYPE_RENDER = 57,
|
||||
KMTQAITYPE_WDDM_1_2_CAPS_RENDER = 58,
|
||||
KMTQAITYPE_WDDM_1_3_CAPS_RENDER = 59,
|
||||
KMTQAITYPE_QUERY_ADAPTER_UNIQUE_GUID = 60,
|
||||
KMTQAITYPE_NODEPERFDATA = 61,
|
||||
KMTQAITYPE_ADAPTERPERFDATA = 62,
|
||||
KMTQAITYPE_ADAPTERPERFDATA_CAPS = 63,
|
||||
KMTQUITYPE_GPUVERSION = 64,
|
||||
KMTQAITYPE_DRIVER_DESCRIPTION = 65,
|
||||
KMTQAITYPE_DRIVER_DESCRIPTION_RENDER = 66,
|
||||
KMTQAITYPE_SCANOUT_CAPS = 67,
|
||||
KMTQAITYPE_DISPLAY_UMDRIVERNAME = 71,
|
||||
KMTQAITYPE_PARAVIRTUALIZATION_RENDER = 68,
|
||||
KMTQAITYPE_SERVICENAME = 69,
|
||||
KMTQAITYPE_WDDM_2_7_CAPS = 70,
|
||||
KMTQAITYPE_TRACKEDWORKLOAD_SUPPORT = 72
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
|
||||
// If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
// Copyright (C) LibreHardwareMonitor and Contributors.
|
||||
// All Rights Reserved.
|
||||
|
||||
// ReSharper disable IdentifierTypo
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace LibreHardwareMonitor.Interop;
|
||||
|
||||
internal static class Gdi32
|
||||
{
|
||||
internal const string DllName = "Gdi32.dll";
|
||||
|
||||
[DllImport(DllName, ExactSpelling = true)]
|
||||
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
|
||||
internal static extern uint D3DKMTCloseAdapter(ref D3dkmth.D3DKMT_CLOSEADAPTER closeAdapter);
|
||||
|
||||
[DllImport(DllName, ExactSpelling = true)]
|
||||
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
|
||||
internal static extern uint D3DKMTOpenAdapterFromDeviceName(ref D3dkmth.D3DKMT_OPENADAPTERFROMDEVICENAME openAdapterFromDeviceName);
|
||||
|
||||
[DllImport(DllName, ExactSpelling = true)]
|
||||
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
|
||||
internal static extern uint D3DKMTQueryAdapterInfo(ref D3dkmth.D3DKMT_QUERYADAPTERINFO queryAdapterInfo);
|
||||
|
||||
[DllImport(DllName, ExactSpelling = true)]
|
||||
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
|
||||
internal static extern uint D3DKMTQueryStatistics(ref D3dkmth.D3DKMT_QUERYSTATISTICS queryStatistics);
|
||||
}
|
||||
@@ -84,18 +84,6 @@ public class Kernel32
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert Win32 error code to HRESULT.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// HRESULT_FROM_WIN32 macro equivalent.
|
||||
/// </remarks>
|
||||
/// <param name="errorCode">Win32 error code</param>
|
||||
/// <returns>HRESULT</returns>
|
||||
internal static int HResultFromWin32(int errorCode) => errorCode <= 0
|
||||
? errorCode
|
||||
: (int)((errorCode & 0x0000FFFF) | 0x80070000);
|
||||
|
||||
internal static SafeFileHandle OpenDevice(string devicePath)
|
||||
{
|
||||
SafeFileHandle hDevice = CreateFile(devicePath, FileAccess.ReadWrite, FileShare.ReadWrite, IntPtr.Zero, FileMode.Open, FileAttributes.Normal, IntPtr.Zero);
|
||||
@@ -105,11 +93,6 @@ public class Kernel32
|
||||
return hDevice;
|
||||
}
|
||||
|
||||
[DllImport(DllName, CharSet = CharSet.Auto, SetLastError = true)]
|
||||
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
internal static extern bool GlobalMemoryStatusEx(ref MEMORYSTATUSEX lpBuffer);
|
||||
|
||||
[DllImport(DllName, CallingConvention = CallingConvention.Winapi, CharSet = CharSet.Auto, SetLastError = true)]
|
||||
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
|
||||
internal static extern SafeFileHandle CreateFile
|
||||
@@ -332,14 +315,6 @@ public class Kernel32
|
||||
ref uint lpBytesReturned,
|
||||
[In][Optional] IntPtr lpOverlapped);
|
||||
|
||||
[DllImport(DllName, CallingConvention = CallingConvention.Winapi)]
|
||||
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
|
||||
internal static extern IntPtr LocalAlloc(uint uFlags, ulong uBytes);
|
||||
|
||||
[DllImport(DllName, CallingConvention = CallingConvention.Winapi)]
|
||||
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
|
||||
internal static extern IntPtr LocalFree(IntPtr hMem);
|
||||
|
||||
[DllImport(DllName, SetLastError = true)]
|
||||
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
|
||||
internal static extern void RtlZeroMemory(IntPtr Destination, int Length);
|
||||
@@ -361,14 +336,6 @@ public class Kernel32
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
internal static extern bool FreeLibrary(IntPtr module);
|
||||
|
||||
[DllImport(DllName, CallingConvention = CallingConvention.Winapi)]
|
||||
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
|
||||
internal static extern IntPtr GetCurrentThread();
|
||||
|
||||
[DllImport(DllName, CallingConvention = CallingConvention.Winapi)]
|
||||
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
|
||||
internal static extern ushort GetActiveProcessorGroupCount();
|
||||
|
||||
[DllImport(DllName, CallingConvention = CallingConvention.Winapi)]
|
||||
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
|
||||
internal static extern bool SetThreadGroupAffinity(IntPtr thread, ref GROUP_AFFINITY groupAffinity, out GROUP_AFFINITY previousGroupAffinity);
|
||||
@@ -381,31 +348,6 @@ public class Kernel32
|
||||
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
|
||||
internal static extern bool VirtualFree(IntPtr lpAddress, UIntPtr dwSize, MEM dwFreeType);
|
||||
|
||||
[DllImport(DllName, CallingConvention = CallingConvention.Winapi)]
|
||||
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
|
||||
internal static extern bool DeviceIoControl
|
||||
(
|
||||
SafeFileHandle device,
|
||||
IOControlCode ioControlCode,
|
||||
[MarshalAs(UnmanagedType.AsAny)] [In] object inBuffer,
|
||||
uint inBufferSize,
|
||||
[MarshalAs(UnmanagedType.AsAny)] [Out] object outBuffer,
|
||||
uint nOutBufferSize,
|
||||
out uint bytesReturned,
|
||||
IntPtr overlapped);
|
||||
|
||||
[DllImport(DllName, CallingConvention = CallingConvention.Winapi, SetLastError = true)]
|
||||
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
|
||||
internal static extern IntPtr CreateFile
|
||||
(
|
||||
string lpFileName,
|
||||
uint dwDesiredAccess,
|
||||
FileShare dwShareMode,
|
||||
IntPtr lpSecurityAttributes,
|
||||
FileMode dwCreationDisposition,
|
||||
FileAttributes dwFlagsAndAttributes,
|
||||
IntPtr hTemplateFile);
|
||||
|
||||
[DllImport(DllName, CallingConvention = CallingConvention.Winapi, SetLastError = true)]
|
||||
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
|
||||
internal static extern int EnumSystemFirmwareTables(Provider firmwareTableProviderSignature, IntPtr firmwareTableBuffer, int bufferSize);
|
||||
@@ -714,20 +656,6 @@ public class Kernel32
|
||||
PropertyQueryMaxDefined
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct MEMORYSTATUSEX
|
||||
{
|
||||
public uint dwLength;
|
||||
public uint dwMemoryLoad;
|
||||
public ulong ullTotalPhys;
|
||||
public ulong ullAvailPhys;
|
||||
public ulong ullTotalPageFile;
|
||||
public ulong ullAvailPageFile;
|
||||
public ulong ullTotalVirtual;
|
||||
public ulong ullAvailVirtual;
|
||||
public ulong ullAvailExtendedVirtual;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
public struct SMART_ATTRIBUTE
|
||||
{
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
|
||||
// If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
// Copyright (C) LibreHardwareMonitor and Contributors.
|
||||
// All Rights Reserved.
|
||||
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
namespace LibreHardwareMonitor.Interop;
|
||||
|
||||
internal class NtDll
|
||||
{
|
||||
private const string DllName = "ntdll.dll";
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
|
||||
{
|
||||
public long IdleTime;
|
||||
public long KernelTime;
|
||||
public long UserTime;
|
||||
public long DpcTime;
|
||||
public long InterruptTime;
|
||||
public uint InterruptCount;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct SYSTEM_PROCESSOR_IDLE_INFORMATION
|
||||
{
|
||||
public long IdleTime;
|
||||
public long C1Time;
|
||||
public long C2Time;
|
||||
public long C3Time;
|
||||
public uint C1Transitions;
|
||||
public uint C2Transitions;
|
||||
public uint C3Transitions;
|
||||
public uint Padding;
|
||||
}
|
||||
|
||||
internal enum SYSTEM_INFORMATION_CLASS
|
||||
{
|
||||
SystemProcessorPerformanceInformation = 8,
|
||||
SystemProcessorIdleInformation = 42
|
||||
}
|
||||
|
||||
[DllImport(DllName)]
|
||||
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
|
||||
internal static extern int NtQuerySystemInformation(SYSTEM_INFORMATION_CLASS SystemInformationClass, [Out] SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION[] SystemInformation, int SystemInformationLength, out int ReturnLength);
|
||||
|
||||
[DllImport(DllName)]
|
||||
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
|
||||
internal static extern int NtQuerySystemInformation(SYSTEM_INFORMATION_CLASS SystemInformationClass, [Out] SYSTEM_PROCESSOR_IDLE_INFORMATION[] SystemInformation, int SystemInformationLength, out int ReturnLength);
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
|
||||
// If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
// Copyright (C) LibreHardwareMonitor and Contributors.
|
||||
// All Rights Reserved.
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace LibreHardwareMonitor.Interop;
|
||||
|
||||
internal class SetupApi
|
||||
{
|
||||
internal const int DIGCF_DEVICEINTERFACE = 0x00000010;
|
||||
internal const int DIGCF_PRESENT = 0x00000002;
|
||||
internal const int ERROR_INSUFFICIENT_BUFFER = 122;
|
||||
internal const int ERROR_NO_MORE_ITEMS = 259;
|
||||
|
||||
private const string DllName = "SetupAPI.dll";
|
||||
internal static Guid GUID_DEVICE_BATTERY = new(0x72631e54, 0x78A4, 0x11d0, 0xbc, 0xf7, 0x00, 0xaa, 0x00, 0xb7, 0xb3, 0x2a);
|
||||
internal static readonly IntPtr INVALID_HANDLE_VALUE = new(-1);
|
||||
|
||||
[DllImport(DllName, CallingConvention = CallingConvention.Winapi, SetLastError = true)]
|
||||
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
|
||||
internal static extern IntPtr SetupDiGetClassDevs(ref Guid ClassGuid, IntPtr Enumerator, IntPtr hwndParent, uint Flags);
|
||||
|
||||
[DllImport(DllName, CallingConvention = CallingConvention.Winapi, SetLastError = true)]
|
||||
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
internal static extern bool SetupDiEnumDeviceInterfaces
|
||||
(IntPtr DeviceInfoSet, IntPtr DeviceInfoData, ref Guid InterfaceClassGuid, uint MemberIndex, ref SP_DEVICE_INTERFACE_DATA DeviceInterfaceData);
|
||||
|
||||
[DllImport(DllName, SetLastError = true, EntryPoint = "SetupDiGetDeviceInterfaceDetailW", CharSet = CharSet.Unicode)]
|
||||
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
internal static extern bool SetupDiGetDeviceInterfaceDetail
|
||||
(
|
||||
IntPtr DeviceInfoSet,
|
||||
in SP_DEVICE_INTERFACE_DATA DeviceInterfaceData,
|
||||
[Out, Optional] IntPtr DeviceInterfaceDetailData,
|
||||
uint DeviceInterfaceDetailDataSize,
|
||||
out uint RequiredSize,
|
||||
IntPtr DeviceInfoData = default);
|
||||
|
||||
[DllImport(DllName, CallingConvention = CallingConvention.Winapi, SetLastError = true)]
|
||||
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
internal static extern bool SetupDiDestroyDeviceInfoList(IntPtr DeviceInfoSet);
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct SP_DEVICE_INTERFACE_DATA
|
||||
{
|
||||
public uint cbSize;
|
||||
public Guid InterfaceClassGuid;
|
||||
public uint Flags;
|
||||
public IntPtr Reserved;
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
|
||||
// If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
// Copyright (C) LibreHardwareMonitor and Contributors.
|
||||
// All Rights Reserved.
|
||||
|
||||
// ReSharper disable IdentifierTypo
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace LibreHardwareMonitor.Interop;
|
||||
|
||||
/// <summary>
|
||||
/// Contains Win32 definitions for Windows NT.
|
||||
/// </summary>
|
||||
internal static class WinNt
|
||||
{
|
||||
internal const int STATUS_SUCCESS = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Describes a local identifier for an adapter.
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct LUID
|
||||
{
|
||||
public readonly uint LowPart;
|
||||
public readonly int HighPart;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents a 64-bit signed integer value.
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Explicit, Size = 8)]
|
||||
internal struct LARGE_INTEGER
|
||||
{
|
||||
[FieldOffset(0)]
|
||||
public long QuadPart;
|
||||
|
||||
[FieldOffset(0)]
|
||||
public uint LowPart;
|
||||
|
||||
[FieldOffset(4)]
|
||||
public int HighPart;
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@
|
||||
<LangVersion>latest</LangVersion>
|
||||
<PackageIcon>packageicon.png</PackageIcon>
|
||||
<GenerateResourceUsePreserializedResources>true</GenerateResourceUsePreserializedResources>
|
||||
<Platforms>x64</Platforms>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)'=='Debug'">
|
||||
<OutputPath>..\bin\Debug\</OutputPath>
|
||||
@@ -48,8 +49,13 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="HidSharp" Version="2.6.2" />
|
||||
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.205">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="RAMSPDToolkit-NDD" Version="1.3.2" />
|
||||
<PackageReference Include="System.Management" Version="9.0.9" />
|
||||
<PackageReference Include="System.Memory" Version="4.6.3" Condition="'$(TargetFramework)' == 'net472'" />
|
||||
<PackageReference Include="System.Threading.AccessControl" Version="9.0.9" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
CM_Get_Device_Interface_List_Size
|
||||
CM_Get_Device_Interface_List
|
||||
GUID_DISPLAY_DEVICE_ARRIVAL
|
||||
NtQuerySystemInformation
|
||||
SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
|
||||
STATUS_INFO_LENGTH_MISMATCH
|
||||
STATUS_SUCCESS
|
||||
D3DKMTCloseAdapter
|
||||
D3DKMTOpenAdapterFromDeviceName
|
||||
D3DKMTQueryAdapterInfo
|
||||
D3DKMTQueryStatistics
|
||||
D3DKMT_ADAPTERTYPE
|
||||
D3DKMT_QUERYSTATISTICS_QUERY_ELEMENT
|
||||
D3DKMT_SEGMENTSIZEINFO
|
||||
D3DKMT_NODEMETADATA
|
||||
D3DKMT_QUERYSTATISTICS_NODE_INFORMATION
|
||||
SetupDiDestroyDeviceInfoList
|
||||
SetupDiGetDeviceInterfaceDetail
|
||||
SetupDiEnumDeviceInterfaces
|
||||
SetupDiGetClassDevs
|
||||
GUID_DEVICE_BATTERY
|
||||
WIN32_ERROR
|
||||
HRESULT_FROM_WIN32
|
||||
GlobalMemoryStatusEx
|
||||
GetCurrentThread
|
||||
GetActiveProcessorGroupCount
|
||||
@@ -3,34 +3,20 @@ using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using Windows.Win32.Foundation;
|
||||
using LibreHardwareMonitor.Interop;
|
||||
using Microsoft.Win32;
|
||||
using Microsoft.Win32.SafeHandles;
|
||||
using PInvoke = Windows.Win32.PInvoke;
|
||||
|
||||
namespace LibreHardwareMonitor.PawnIo;
|
||||
|
||||
public class PawnIo
|
||||
{
|
||||
private const uint DEVICE_TYPE = 41394u << 16;
|
||||
private const uint IOCTL_PIO_LOAD_BINARY = 0x821 << 2;
|
||||
private const uint IOCTL_PIO_EXECUTE_FN = 0x841 << 2;
|
||||
private const int FN_NAME_LENGTH = 32;
|
||||
|
||||
private enum ControlCode : uint
|
||||
{
|
||||
LoadBinary = DEVICE_TYPE | IOCTL_PIO_LOAD_BINARY,
|
||||
Execute = DEVICE_TYPE | IOCTL_PIO_EXECUTE_FN
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether PawnIO is installed on the system.
|
||||
/// </summary>
|
||||
public static bool IsInstalled => Version is not null;
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the version information for the installed PawnIO.
|
||||
/// </summary>
|
||||
public static Version Version { get; } = null;
|
||||
private const uint IOCTL_PIO_EXECUTE_FN = 0x841 << 2;
|
||||
private const uint IOCTL_PIO_LOAD_BINARY = 0x821 << 2;
|
||||
|
||||
private readonly SafeFileHandle _handle;
|
||||
|
||||
@@ -46,12 +32,28 @@ public class PawnIo
|
||||
|
||||
private PawnIo(SafeFileHandle handle) => _handle = handle;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether PawnIO is installed on the system.
|
||||
/// </summary>
|
||||
public static bool IsInstalled => Version is not null;
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the version information for the installed PawnIO.
|
||||
/// </summary>
|
||||
public static Version Version { get; }
|
||||
|
||||
public bool IsLoaded => _handle is
|
||||
{
|
||||
IsInvalid: false,
|
||||
IsClosed: false
|
||||
};
|
||||
|
||||
internal static PawnIo LoadModuleFromResource(Assembly assembly, string resourceName)
|
||||
{
|
||||
SafeFileHandle handle = Kernel32.CreateFile(@"\\.\PawnIO", FileAccess.ReadWrite, FileShare.ReadWrite, IntPtr.Zero, FileMode.Open, FileAttributes.Normal, IntPtr.Zero);
|
||||
|
||||
if (handle.IsInvalid)
|
||||
return new(null);
|
||||
return new PawnIo(null);
|
||||
|
||||
uint read = 0;
|
||||
|
||||
@@ -61,39 +63,32 @@ public class PawnIo
|
||||
byte[] bin = memory.ToArray();
|
||||
|
||||
if (Kernel32.DeviceIoControl(handle, (uint)ControlCode.LoadBinary, bin, (uint)bin.Length, null, 0u, ref read, IntPtr.Zero))
|
||||
return new(handle);
|
||||
return new PawnIo(handle);
|
||||
|
||||
return new(null);
|
||||
return new PawnIo(null);
|
||||
}
|
||||
|
||||
public bool IsLoaded => _handle is
|
||||
{
|
||||
IsInvalid: false,
|
||||
IsClosed: false
|
||||
};
|
||||
|
||||
public void Close() => _handle.Close();
|
||||
|
||||
public long[] Execute(string name, long[] input, int outLength)
|
||||
{
|
||||
if (!IsLoaded)
|
||||
return [];
|
||||
|
||||
uint read = 0;
|
||||
|
||||
byte[] output = new byte[outLength * sizeof(long)];
|
||||
byte[] inp = new byte[input.Length * sizeof(long) + FN_NAME_LENGTH];
|
||||
Buffer.BlockCopy(Encoding.ASCII.GetBytes(name), 0, inp, 0, Math.Min(FN_NAME_LENGTH - 1, name.Length));
|
||||
Buffer.BlockCopy(input, 0, inp, FN_NAME_LENGTH, input.Length * sizeof(long));
|
||||
|
||||
if (Kernel32.DeviceIoControl(_handle, (uint)ControlCode.Execute, inp, (uint)inp.Length, output, (uint)output.Length, ref read))
|
||||
if (IsLoaded)
|
||||
{
|
||||
long[] outp = new long[read / sizeof(long)];
|
||||
Buffer.BlockCopy(output, 0, outp, 0, (int)read);
|
||||
return outp;
|
||||
byte[] output = new byte[outLength * sizeof(long)];
|
||||
byte[] inp = new byte[(input.Length * sizeof(long)) + FN_NAME_LENGTH];
|
||||
Buffer.BlockCopy(Encoding.ASCII.GetBytes(name), 0, inp, 0, Math.Min(FN_NAME_LENGTH - 1, name.Length));
|
||||
Buffer.BlockCopy(input, 0, inp, FN_NAME_LENGTH, input.Length * sizeof(long));
|
||||
|
||||
uint read = 0;
|
||||
if (Kernel32.DeviceIoControl(_handle, (uint)ControlCode.Execute, inp, (uint)inp.Length, output, (uint)output.Length, ref read))
|
||||
{
|
||||
long[] outp = new long[read / sizeof(long)];
|
||||
Buffer.BlockCopy(output, 0, outp, 0, (int)read);
|
||||
return outp;
|
||||
}
|
||||
}
|
||||
|
||||
return [];
|
||||
return new long[outLength];
|
||||
}
|
||||
|
||||
public int ExecuteHr(string name, long[] inBuffer, uint inSize, long[] outBuffer, uint outSize, out uint returnSize)
|
||||
@@ -113,7 +108,7 @@ public class PawnIo
|
||||
uint read = 0;
|
||||
|
||||
byte[] output = new byte[outSize * sizeof(long)];
|
||||
byte[] inp = new byte[inSize * sizeof(long) + FN_NAME_LENGTH];
|
||||
byte[] inp = new byte[(inSize * sizeof(long)) + FN_NAME_LENGTH];
|
||||
Buffer.BlockCopy(Encoding.ASCII.GetBytes(name), 0, inp, 0, Math.Min(FN_NAME_LENGTH - 1, name.Length));
|
||||
Buffer.BlockCopy(inBuffer, 0, inp, FN_NAME_LENGTH, inBuffer.Length * sizeof(long));
|
||||
|
||||
@@ -125,7 +120,12 @@ public class PawnIo
|
||||
}
|
||||
|
||||
returnSize = 0;
|
||||
return PInvoke.HRESULT_FROM_WIN32((WIN32_ERROR)Marshal.GetLastWin32Error());
|
||||
}
|
||||
|
||||
return Kernel32.HResultFromWin32(Marshal.GetLastWin32Error());
|
||||
private enum ControlCode : uint
|
||||
{
|
||||
LoadBinary = DEVICE_TYPE | IOCTL_PIO_LOAD_BINARY,
|
||||
Execute = DEVICE_TYPE | IOCTL_PIO_EXECUTE_FN
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,33 +7,11 @@ namespace LibreHardwareMonitor;
|
||||
|
||||
internal sealed class RAMSPDToolkitDriver : IPawnIODriver
|
||||
{
|
||||
internal class PawnIOModule : IPawnIOModule, IDisposable
|
||||
{
|
||||
public PawnIOModule(PawnIo.PawnIo pawnIO)
|
||||
{
|
||||
_pawnIO = pawnIO;
|
||||
}
|
||||
|
||||
PawnIo.PawnIo _pawnIO;
|
||||
|
||||
public int Execute(string name, long[] inBuffer, uint inSize, long[] outBuffer, uint outSize, out uint returnSize)
|
||||
=> _pawnIO.ExecuteHr(name, inBuffer, inSize, outBuffer, outSize, out returnSize);
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (_pawnIO != null)
|
||||
{
|
||||
_pawnIO.Close();
|
||||
_pawnIO = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const string I801ModuleFilename = "SmbusI801.bin";
|
||||
const string Piix4ModuleFilename = "SmbusPIIX4.bin";
|
||||
const string Nct6793ModuleFilename = "SmbusNCT6793.bin";
|
||||
const string Piix4ModuleFilename = "SmbusPIIX4.bin";
|
||||
|
||||
private List<PawnIOModule> _pawnIOModules = new();
|
||||
private readonly List<PawnIOModule> _pawnIOModules = new();
|
||||
|
||||
public bool IsOpen => true;
|
||||
|
||||
@@ -79,10 +57,8 @@ internal sealed class RAMSPDToolkitDriver : IPawnIODriver
|
||||
_pawnIOModules.Add(pawnIOModule);
|
||||
return pawnIOModule;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void Unload()
|
||||
@@ -90,4 +66,26 @@ internal sealed class RAMSPDToolkitDriver : IPawnIODriver
|
||||
_pawnIOModules.ForEach(p => p.Dispose());
|
||||
_pawnIOModules.Clear();
|
||||
}
|
||||
|
||||
internal class PawnIOModule : IPawnIOModule, IDisposable
|
||||
{
|
||||
private PawnIo.PawnIo _pawnIO;
|
||||
|
||||
public PawnIOModule(PawnIo.PawnIo pawnIO)
|
||||
{
|
||||
_pawnIO = pawnIO;
|
||||
}
|
||||
|
||||
public int Execute(string name, long[] inBuffer, uint inSize, long[] outBuffer, uint outSize, out uint returnSize)
|
||||
=> _pawnIO.ExecuteHr(name, inBuffer, inSize, outBuffer, outSize, out returnSize);
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (_pawnIO != null)
|
||||
{
|
||||
_pawnIO.Close();
|
||||
_pawnIO = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user