diff --git a/indra/llwindow/lldxhardware.cpp b/indra/llwindow/lldxhardware.cpp index 66725a7e857698c34376c7406bf1fef9288e793e..4de34368553814aec20e27c440d804a4268d4110 100644 --- a/indra/llwindow/lldxhardware.cpp +++ b/indra/llwindow/lldxhardware.cpp @@ -401,7 +401,7 @@ void LLDXHardware::cleanup() BOOL LLDXHardware::updateVRAM() { - SIZE_T vram = getMBVideoMemoryViaDXGI(); + U64 vram = getMBVideoMemoryViaDXGI(); if (vram > 0) { @@ -411,12 +411,11 @@ BOOL LLDXHardware::updateVRAM() return FALSE; } -S32 LLDXHardware::getMBVideoMemoryViaDXGI() +U64 LLDXHardware::getMBVideoMemoryViaDXGI() { HRESULT hr; - BOOL bGotMemory = FALSE; HRESULT hrCoInitialize = S_OK; - SIZE_T vram = 0; + U64 vram = 0; hrCoInitialize = CoInitialize(0); if (SUCCEEDED(hrCoInitialize)) @@ -426,34 +425,35 @@ S32 LLDXHardware::getMBVideoMemoryViaDXGI() hr = CreateDXGIFactory1(IID_PPV_ARGS(&pDXGIFactory)); if (SUCCEEDED(hr)) { - assert(pDXGIFactory != 0); - - for (UINT index = 0; ; ++index) + llassert(pDXGIFactory != 0); + IDXGIAdapter1* dxgiAdapter = nullptr; + IDXGIAdapter1* tmpDxgiAdapter = nullptr; + UINT adapterIndex = 0; + while (pDXGIFactory->EnumAdapters1(adapterIndex, &tmpDxgiAdapter) != DXGI_ERROR_NOT_FOUND) { - IDXGIAdapter1* pAdapter = nullptr; - hr = pDXGIFactory->EnumAdapters1(index, &pAdapter); - if (FAILED(hr)) // DXGIERR_NOT_FOUND is expected when the end of the list is hit - break; - DXGI_ADAPTER_DESC1 desc; - memset(&desc, 0, sizeof(DXGI_ADAPTER_DESC1)); - if (SUCCEEDED(pAdapter->GetDesc1(&desc))) + hr = tmpDxgiAdapter->GetDesc1(&desc); + if (SUCCEEDED(hr) && !dxgiAdapter && desc.Flags == 0 && tmpDxgiAdapter) { - if (desc.Flags == 0) - { - vram = desc.DedicatedVideoMemory; - bGotMemory = TRUE; - } + tmpDxgiAdapter->QueryInterface(IID_PPV_ARGS(&dxgiAdapter)); } - SAFE_RELEASE(pAdapter); - if (bGotMemory != FALSE) - break; + SAFE_RELEASE(tmpDxgiAdapter); + ++adapterIndex; } + if (dxgiAdapter != nullptr) + { + DXGI_ADAPTER_DESC1 desc; + dxgiAdapter->GetDesc1(&desc); + vram = desc.DedicatedVideoMemory; + + SAFE_RELEASE(dxgiAdapter); + } + SAFE_RELEASE(pDXGIFactory); } CoUninitialize(); } - return vram / (1024 * 1024); + return vram; } LLSD LLDXHardware::getDisplayInfo() diff --git a/indra/llwindow/lldxhardware.h b/indra/llwindow/lldxhardware.h index f43a7b7cb57062430ae9cc27aedbe74dc786d93a..e4f0736b6b9081e8c422f2d3fa52f054afd8d667 100644 --- a/indra/llwindow/lldxhardware.h +++ b/indra/llwindow/lldxhardware.h @@ -96,7 +96,7 @@ class LLDXHardware // Will get memory of best GPU in MB, return memory on sucsess, 0 on failure // Note: WMI is not accurate in some cases - static S32 getMBVideoMemoryViaDXGI(); + static U64 getMBVideoMemoryViaDXGI(); // Find a particular device that matches the following specs. // Empty strings indicate that you don't care. @@ -109,7 +109,7 @@ class LLDXHardware typedef std::map<std::string, LLDXDevice *> device_map_t; // device_map_t mDevices; protected: - S32 mVRAM; + S32 mVRAM; // stored in megabytes }; extern void (*gWriteDebug)(const char* msg);