Skip to content

Commit 2e79024

Browse files
authored
Fixed incorrect VRAM detection (#1589)
* Another way to find total video memory * GetWMIVideoAdapterMemorySize var names fix * Fix ven dev string format * Uses a maximum of 4 GB of video memory * Some fixes for Nvidia optimus * Fixed uiMax value * Removed unnecessary uiMax * Fix typo * Removed unnecessary include
1 parent 0e03a42 commit 2e79024

File tree

3 files changed

+20
-63
lines changed

3 files changed

+20
-63
lines changed

Client/core/DXHook/CProxyDirect3DDevice9.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ CProxyDirect3DDevice9::CProxyDirect3DDevice9(IDirect3DDevice9* pDevice)
4545
ZeroMemory(&adaptIdent, sizeof(D3DADAPTER_IDENTIFIER9));
4646
pD3D9->GetAdapterIdentifier(iAdapter, 0, &adaptIdent);
4747

48-
int iVideoCardMemoryKBTotal = GetWMIVideoAdapterMemorySize(adaptIdent.DeviceName) / 1024;
48+
int iVideoCardMemoryKBTotal = GetWMIVideoAdapterMemorySize(adaptIdent.VendorId, adaptIdent.DeviceId) / 1024;
4949

5050
// Just incase, fallback to using texture memory stats
5151
if (iVideoCardMemoryKBTotal < 16)

Shared/sdk/SharedUtil.SysInfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ namespace SharedUtil
3535

3636
bool QueryWMI(SQueryWMIResult& outResult, const SString& strQuery, const SString& strKeys, const SString& strNamespace = "CIMV2");
3737
SString GetWMIOSVersion();
38-
unsigned int GetWMIVideoAdapterMemorySize(const SString& strDisplay);
38+
unsigned int GetWMIVideoAdapterMemorySize(const unsigned long ulVen, const unsigned long ulDev);
3939
long long GetWMITotalPhysicalMemory();
4040
void GetWMIAntiVirusStatus(std::vector<SString>& outEnabledList, std::vector<SString>& outDisabledList);
4141
void GetInstalledHotFixList(std::vector<SString>& outInstalledList);

Shared/sdk/SharedUtil.SysInfo.hpp

Lines changed: 18 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -326,77 +326,34 @@ long long SharedUtil::GetWMITotalPhysicalMemory()
326326
//
327327
//
328328
/////////////////////////////////////////////////////////////////////
329-
unsigned int SharedUtil::GetWMIVideoAdapterMemorySize(const SString& strDisplay)
329+
unsigned int SharedUtil::GetWMIVideoAdapterMemorySize(const unsigned long ulVen, const unsigned long ulDev)
330330
{
331-
// This won't change after the first call
332-
static unsigned int uiResult = 0;
333-
334-
if (uiResult == 0)
335-
{
336-
SString strDeviceId;
337-
338-
// Find a device id for the display
339-
for (int i = 0; true; i++)
340-
{
341-
DISPLAY_DEVICE device;
342-
device.cb = sizeof(device);
331+
unsigned int uiResult = 0;
343332

344-
// Get next DISPLAY_DEVICE from the system
345-
if (!EnumDisplayDevicesA(NULL, i, &device, 0))
346-
break;
333+
SString DevVen;
334+
DevVen.Format("VEN_%04X&DEV_%04X", ulVen, ulDev);
347335

348-
// Calc flags
349-
bool bAttachedToDesktop = (device.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP) != 0;
350-
bool bMirroringDriver = (device.StateFlags & DISPLAY_DEVICE_MIRRORING_DRIVER) != 0;
336+
// Get WMI info about all video controllers
337+
SQueryWMIResult result;
338+
QueryWMI(result, "Win32_VideoController", "PNPDeviceID,AdapterRAM,Availability");
351339

352-
// Only check attached, non mirror displays
353-
if (bAttachedToDesktop && !bMirroringDriver)
354-
{
355-
if (strDisplay.CompareI(device.DeviceName))
356-
{
357-
// Found a match
358-
strDeviceId = device.DeviceID;
359-
break;
360-
}
361-
}
362-
}
340+
// Check each controller for a device id match
341+
for (uint i = 0; i < result.size(); i++)
342+
{
343+
const SString& PNPDeviceID = result[i][0];
344+
const SString& AdapterRAM = result[i][1];
345+
const SString& Availability = result[i][2];
363346

364-
// Get WMI info about all video controllers
365-
SQueryWMIResult result;
366-
QueryWMI(result, "Win32_VideoController", "PNPDeviceID,AdapterRAM,Availability");
347+
unsigned int uiAdapterRAM = atoi(AdapterRAM);
348+
int iAvailability = atoi(Availability);
367349

368-
// Check each controller for a device id match
369-
for (uint i = 0; i < result.size(); i++)
350+
if ((iAvailability == 8 || iAvailability == 3) && PNPDeviceID.Contains(DevVen))
370351
{
371-
const SString& PNPDeviceID = result[i][0];
372-
const SString& AdapterRAM = result[i][1];
373-
const SString& Availability = result[i][2];
374-
375-
unsigned int uiAdapterRAM = atoi(AdapterRAM);
376-
int iAvailability = atoi(Availability);
377-
378-
if (uiResult == 0)
379-
uiResult = uiAdapterRAM;
380-
381-
if (iAvailability == 3)
382-
uiResult = std::max(uiResult, uiAdapterRAM);
383-
384-
if (uiAdapterRAM != 0)
385-
{
386-
// If this matches the previously found device, return the adapter RAM
387-
if (!strDeviceId.empty() && PNPDeviceID.BeginsWithI(strDeviceId))
388-
{
389-
uiResult = uiAdapterRAM;
390-
break; // Found match
391-
}
392-
}
352+
uiResult = uiAdapterRAM;
353+
break; // Found match
393354
}
394355
}
395356

396-
if (uiResult == 0)
397-
{
398-
uiResult = 2LL * 1024 * 1024 * 1024; // 2GB
399-
}
400357
return uiResult;
401358
}
402359

0 commit comments

Comments
 (0)