Fix same memory for different GPUs. (#2232)

* Fix same memory for different GPUs.

* Status check
This commit is contained in:
Blacktempel
2026-02-19 16:21:49 +01:00
committed by GitHub
parent 3d331e3370
commit 315a767fa0
2 changed files with 61 additions and 4 deletions
@@ -702,14 +702,31 @@ internal sealed class NvidiaGpu : GenericGpu
}
}
if (_displayHandle != null)
if (NvApi.NvAPI_GPU_GetMemoryInfoEx != null || _displayHandle != null)
{
NvApi.NvMemoryInfo memoryInfo = GetMemoryInfo(out status);
uint free = 0;
uint total = 0;
//Size in bytes
NvApi.NvMemoryInfoEx memoryInfoEx = GetMemoryInfoEx(out status);
if (status == NvApi.NvStatus.OK)
{
uint free = memoryInfo.CurrentAvailableDedicatedVideoMemory;
uint total = memoryInfo.DedicatedVideoMemory;
free = (uint)(memoryInfoEx.CurrentAvailableDedicatedVideoMemory / 1024);
total = (uint)(memoryInfoEx.DedicatedVideoMemory / 1024);
}
else
{
//Size in kilobytes, fallback for older drivers
NvApi.NvMemoryInfo memoryInfo = GetMemoryInfo(out status);
if (status == NvApi.NvStatus.OK)
{
free = memoryInfo.CurrentAvailableDedicatedVideoMemory;
total = memoryInfo.DedicatedVideoMemory;
}
}
if (status == NvApi.NvStatus.OK)
{
_memoryTotal.Value = total / 1024;
ActivateSensor(_memoryTotal);
@@ -1142,6 +1159,23 @@ internal sealed class NvidiaGpu : GenericGpu
return status == NvApi.NvStatus.OK ? memoryInfo : default;
}
private NvApi.NvMemoryInfoEx GetMemoryInfoEx(out NvApi.NvStatus status)
{
if (NvApi.NvAPI_GPU_GetMemoryInfoEx == null)
{
status = NvApi.NvStatus.Error;
return default;
}
NvApi.NvMemoryInfoEx memoryInfoEx = new()
{
Version = (uint)NvApi.MAKE_NVAPI_VERSION<NvApi.NvMemoryInfoEx>(1)
};
status = NvApi.NvAPI_GPU_GetMemoryInfoEx(_handle, ref memoryInfoEx);
return status == NvApi.NvStatus.OK ? memoryInfoEx : default;
}
private NvApi.NvGpuClockFrequencies GetClockFrequencies(out NvApi.NvStatus status)
{
if (NvApi.NvAPI_GPU_GetAllClockFrequencies == null)
+23
View File
@@ -42,6 +42,7 @@ internal static class NvApi
public static NvAPI_GPU_GetCoolerSettingsDelegate NvAPI_GPU_GetCoolerSettings { get; internal set; }
public static NvAPI_GPU_GetDynamicPstatesInfoExDelegate NvAPI_GPU_GetDynamicPstatesInfoEx { get; internal set; }
public static NvAPI_GPU_GetMemoryInfoDelegate NvAPI_GPU_GetMemoryInfo { get; internal set; }
public static NvAPI_GPU_GetMemoryInfoExDelegate NvAPI_GPU_GetMemoryInfoEx { get; internal set; }
public static NvAPI_GPU_GetPCIIdentifiersDelegate NvAPI_GPU_GetPCIIdentifiers { get; internal set; }
public static NvAPI_GPU_GetTachReadingDelegate NvAPI_GPU_GetTachReading { get; internal set; }
public static NvAPI_GPU_GetThermalSettingsDelegate NvAPI_GPU_GetThermalSettings { get; internal set; }
@@ -84,6 +85,7 @@ internal static class NvApi
NvAPI_GPU_GetCoolerSettings = GetDelegate<NvAPI_GPU_GetCoolerSettingsDelegate>(0xDA141340);
NvAPI_GPU_SetCoolerLevels = GetDelegate<NvAPI_GPU_SetCoolerLevelsDelegate>(0x891FA0AE);
NvAPI_GPU_GetMemoryInfo = GetDelegate<NvAPI_GPU_GetMemoryInfoDelegate>(0x774AA982);
NvAPI_GPU_GetMemoryInfoEx = GetDelegate<NvAPI_GPU_GetMemoryInfoExDelegate>(0xC0599498);
NvAPI_GetDisplayDriverVersion = GetDelegate<NvAPI_GetDisplayDriverVersionDelegate>(0xF951A4D1);
_nvAPI_GetInterfaceVersionString = GetDelegate<NvAPI_GetInterfaceVersionStringDelegate>(0x01053FA5);
NvAPI_GPU_GetPCIIdentifiers = GetDelegate<NvAPI_GPU_GetPCIIdentifiersDelegate>(0x2DDFB66E);
@@ -146,6 +148,9 @@ internal static class NvApi
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate NvStatus NvAPI_GPU_GetMemoryInfoDelegate(NvDisplayHandle displayHandle, ref NvMemoryInfo nvMemoryInfo);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate NvStatus NvAPI_GPU_GetMemoryInfoExDelegate(NvPhysicalGpuHandle gpuHandle, ref NvMemoryInfoEx nvMemoryInfo);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate NvStatus NvAPI_GPU_GetPCIIdentifiersDelegate(NvPhysicalGpuHandle gpuHandle, out uint deviceId, out uint subSystemId, out uint revisionId, out uint extDeviceId);
@@ -576,6 +581,24 @@ internal static class NvApi
public uint CurrentAvailableDedicatedVideoMemory;
}
[StructLayout(LayoutKind.Sequential)]
internal struct NvMemoryInfoEx
{
public uint Version;
public ulong DedicatedVideoMemory;
public ulong AvailableDedicatedVideoMemory;
public ulong SystemVideoMemory;
public ulong SharedSystemMemory;
public ulong CurrentAvailableDedicatedVideoMemory;
public ulong DedicatedVideoMemoryEvictionsSize;
public ulong DedicatedVideoMemoryEvictionCount;
public ulong DedicatedVideoMemoryPromotionsSize;
public ulong DedicatedVideoMemoryPromotionCount;
}
[StructLayout(LayoutKind.Sequential, Pack = 8)]
internal struct NvDisplayDriverVersion
{