Skip to content
Snippets Groups Projects
Commit 5c78f0dc authored by Rye Mutt's avatar Rye Mutt :bread:
Browse files

Fix getting video memory via DXGI

parent e59ad682
No related branches found
No related tags found
No related merge requests found
...@@ -401,7 +401,7 @@ void LLDXHardware::cleanup() ...@@ -401,7 +401,7 @@ void LLDXHardware::cleanup()
BOOL LLDXHardware::updateVRAM() BOOL LLDXHardware::updateVRAM()
{ {
SIZE_T vram = getMBVideoMemoryViaDXGI(); U64 vram = getMBVideoMemoryViaDXGI();
if (vram > 0) if (vram > 0)
{ {
...@@ -411,12 +411,11 @@ BOOL LLDXHardware::updateVRAM() ...@@ -411,12 +411,11 @@ BOOL LLDXHardware::updateVRAM()
return FALSE; return FALSE;
} }
S32 LLDXHardware::getMBVideoMemoryViaDXGI() U64 LLDXHardware::getMBVideoMemoryViaDXGI()
{ {
HRESULT hr; HRESULT hr;
BOOL bGotMemory = FALSE;
HRESULT hrCoInitialize = S_OK; HRESULT hrCoInitialize = S_OK;
SIZE_T vram = 0; U64 vram = 0;
hrCoInitialize = CoInitialize(0); hrCoInitialize = CoInitialize(0);
if (SUCCEEDED(hrCoInitialize)) if (SUCCEEDED(hrCoInitialize))
...@@ -426,34 +425,35 @@ S32 LLDXHardware::getMBVideoMemoryViaDXGI() ...@@ -426,34 +425,35 @@ S32 LLDXHardware::getMBVideoMemoryViaDXGI()
hr = CreateDXGIFactory1(IID_PPV_ARGS(&pDXGIFactory)); hr = CreateDXGIFactory1(IID_PPV_ARGS(&pDXGIFactory));
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
assert(pDXGIFactory != 0); llassert(pDXGIFactory != 0);
IDXGIAdapter1* dxgiAdapter = nullptr;
for (UINT index = 0; ; ++index) 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; DXGI_ADAPTER_DESC1 desc;
memset(&desc, 0, sizeof(DXGI_ADAPTER_DESC1)); hr = tmpDxgiAdapter->GetDesc1(&desc);
if (SUCCEEDED(pAdapter->GetDesc1(&desc))) if (SUCCEEDED(hr) && !dxgiAdapter && desc.Flags == 0 && tmpDxgiAdapter)
{ {
if (desc.Flags == 0) tmpDxgiAdapter->QueryInterface(IID_PPV_ARGS(&dxgiAdapter));
{
vram = desc.DedicatedVideoMemory;
bGotMemory = TRUE;
}
} }
SAFE_RELEASE(pAdapter); SAFE_RELEASE(tmpDxgiAdapter);
if (bGotMemory != FALSE) ++adapterIndex;
break;
} }
if (dxgiAdapter != nullptr)
{
DXGI_ADAPTER_DESC1 desc;
dxgiAdapter->GetDesc1(&desc);
vram = desc.DedicatedVideoMemory;
SAFE_RELEASE(dxgiAdapter);
}
SAFE_RELEASE(pDXGIFactory); SAFE_RELEASE(pDXGIFactory);
} }
CoUninitialize(); CoUninitialize();
} }
return vram / (1024 * 1024); return vram;
} }
LLSD LLDXHardware::getDisplayInfo() LLSD LLDXHardware::getDisplayInfo()
......
...@@ -96,7 +96,7 @@ class LLDXHardware ...@@ -96,7 +96,7 @@ class LLDXHardware
// Will get memory of best GPU in MB, return memory on sucsess, 0 on failure // Will get memory of best GPU in MB, return memory on sucsess, 0 on failure
// Note: WMI is not accurate in some cases // Note: WMI is not accurate in some cases
static S32 getMBVideoMemoryViaDXGI(); static U64 getMBVideoMemoryViaDXGI();
// Find a particular device that matches the following specs. // Find a particular device that matches the following specs.
// Empty strings indicate that you don't care. // Empty strings indicate that you don't care.
...@@ -109,7 +109,7 @@ class LLDXHardware ...@@ -109,7 +109,7 @@ class LLDXHardware
typedef std::map<std::string, LLDXDevice *> device_map_t; typedef std::map<std::string, LLDXDevice *> device_map_t;
// device_map_t mDevices; // device_map_t mDevices;
protected: protected:
S32 mVRAM; S32 mVRAM; // stored in megabytes
}; };
extern void (*gWriteDebug)(const char* msg); extern void (*gWriteDebug)(const char* msg);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment