18
\$\begingroup\$

How do you query the amount of VRAM available when using DirectX?

\$\endgroup\$

2 Answers 2

9
\$\begingroup\$

According to Game Coding Complete 3, there are a few ways:

  • DX7's GetAvailableVidMem() - usually pretty good. Doesn't work too well on cards with shared memory.
  • WMI (Windows Management Interface) has a similar result to the above.
  • DxDiag uses both to give a better result.
  • D3D9 has a GetAvailableTextureMemory() function, but can only be used on Windows Vista/7.

Look for a DX sample in March 08 or later SDK called 'VideoMemory'.

\$\endgroup\$
2
  • \$\begingroup\$ DX Sample for Video Memory is great -- should have found that before asking ;) \$\endgroup\$ Commented Oct 8, 2010 at 17:38
  • 2
    \$\begingroup\$ Considering how many computers will use shared memory, I would not recommend DX7's version. And how can the D3D9 version of this be only available on Vista+ ? D3D9 was there in XP... \$\endgroup\$
    – Bahbar
    Commented Oct 12, 2010 at 20:57
5
\$\begingroup\$

For DX9EX on Vista and later:

IDXGIDevice * pDXGIDevice;
hr = g_pd3dDevice->QueryInterface(__uuidof(IDXGIDevice), (void **)&pDXGIDevice);
IDXGIAdapter * pDXGIAdapter;
pDXGIDevice->GetAdapter(&pDXGIAdapter);
DXGI_ADAPTER_DESC adapterDesc;
pDXGIAdapter->GetDesc(&adapterDesc);
return adapterDesc.DedicatedVideoMemory;

(from http://msdn.microsoft.com/en-us/library/bb174526(v=VS.85).aspx )

\$\endgroup\$
1
  • \$\begingroup\$ Not calling Release() on pDXGIDevice after a successful call to QueryInterface() will lead to a memory leak. \$\endgroup\$
    – Vinz
    Commented Nov 17, 2018 at 0:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .