Я пытаюсь прочитать количество VRAM, используя следующий код
bool HasWDDMDriver()
{
HMODULE hD3D9 = NULL;
hD3D9 = LoadLibrary(L"d3d9.dll");
if (NULL == hD3D9) {
return false;
}
typedef HRESULT(WINAPI *LPDIRECT3DCREATE9EX)(UINT,
IDirect3D9Ex**);
LPDIRECT3DCREATE9EX pD3D9Create9Ex = NULL;
//
// Try to create a IDirect3D9Ex interface (also known as a DX9L
// interface).
// This interface can only be created if the driver is written
// according to the Windows Display Driver Model (WDDM).
//
pD3D9Create9Ex = (LPDIRECT3DCREATE9EX)GetProcAddress(
hD3D9, "Direct3DCreate9Ex");
bool res = pD3D9Create9Ex != NULL;
return res;
}
void getGPUMemory()
{
bool wddmDriver = HasWDDMDriver();//Because DXGI is only available on systems with WDDM drivers
if (wddmDriver)
{
unsigned int DedicatedVideoMemory = 0;
unsigned int DedicatedSystemMemory = 0;
unsigned int SharedSystemMemory = 0;
IDXGIFactory *Factory;
CreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&Factory);
UINT AdapterIndex = 0;
if (Factory != NULL)
{
IDXGIAdapter* adapter = NULL;
while (Factory->EnumAdapters(AdapterIndex, &adapter) != DXGI_ERROR_NOT_FOUND)
{
if (adapter)
{
DXGI_ADAPTER_DESC desc;
adapter->GetDesc(&desc);
int dvm = ((desc.DedicatedVideoMemory / 1024) / 1024);
int dsm = ((desc.DedicatedSystemMemory / 1024) / 1024);
int ssm = ((desc.SharedSystemMemory / 1024) / 1024);
if (!((desc.VendorId == 0x1414) && (desc.DeviceId == 0x8c)))//This is Microsoft Basic Render Driver
{
DedicatedVideoMemory = DedicatedVideoMemory + dvm;
DedicatedSystemMemory = DedicatedSystemMemory + dsm;
SharedSystemMemory = SharedSystemMemory + ssm;
}
}
++AdapterIndex;
}
}
unsigned int TotalMemory = 0;
TotalMemory = DedicatedVideoMemory + SharedSystemMemory;
cout << "Dedicated Video Memory = " << DedicatedVideoMemory
<< "\nDedicated System Memory = " << DedicatedSystemMemory
<< "\nShared System Memory = " << SharedSystemMemory
<< "\nTotal Memory (Dedicated Video Memory + Shared System Memory) = " << TotalMemory
<< "\nLoop Count = " << AdapterIndex;
}
}
Его вывод не совпадает со значениями, показанными в окнах, пожалуйста, смотрите изображения.
У dvm, dsm и ssm разная величина различий в разных системах.
Пожалуйста, помогите улучшить это.
Кроме того, тот же образец в .net будет оценен.
Задача ещё не решена.
Других решений пока нет …