Skip to content

Commit 42f1dd9

Browse files
committed
fix: Use DXGI to get adapter memory as WMI is unreliable
1 parent 0a9d939 commit 42f1dd9

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

Source/ORTS.Common/SystemInfo.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
using System.Collections.Generic;
2525
using System.Globalization;
2626
using System.Diagnostics;
27+
using SharpDX.DXGI;
2728

2829
namespace ORTS.Common
2930
{
@@ -87,13 +88,16 @@ static SystemInfo()
8788
Trace.WriteLine(error);
8889
}
8990

91+
// The WMI data for AdapterRAM is unreliable, so we have to use DXGI to get the real numbers.
92+
// Alas, DXGI doesn't give us the manufacturer name for the adapter, so we combine it with WMI.
93+
var descriptions = new Factory1().Adapters.Select(adapter => adapter.Description).ToArray();
9094
try
9195
{
9296
GPUs = new ManagementClass("Win32_VideoController").GetInstances().Cast<ManagementObject>().Select(adapter => new GPU
9397
{
9498
Name = (string)adapter["Name"],
9599
Manufacturer = (string)adapter["AdapterCompatibility"],
96-
MemoryMB = (uint?)adapter["AdapterRAM"] / 1024 / 1024 ?? 0,
100+
MemoryMB = (uint)((long)descriptions.FirstOrDefault(desc => desc.Description == (string)adapter["Name"]).DedicatedVideoMemory / 1024 / 1024),
97101
}).ToList();
98102
}
99103
catch (ManagementException error)

0 commit comments

Comments
 (0)