How can i get available Video Memory?

Aug 12, 2013 at 12:25 PM
Edited Aug 12, 2013 at 12:31 PM
How can i get the available Video Memory?

Ive modificate Hieroglyph3 for this, because i need the amount of GPU memory i have. Is it possible that you add it someday for me?

The Hieroglyph3 Modification:
UINT64 RendererDX11::GetAvailableVideoMemory()
{
    // Acquire the DXGI device, then the adapter, then the output...

    IDXGIDevice * pDXGIDevice = NULL;
    IDXGIAdapter * pDXGIAdapter = NULL;
    
    HRESULT hr = m_pDevice->QueryInterface(__uuidof(IDXGIDevice), (void **)&pDXGIDevice);
    pDXGIDevice->GetAdapter( &pDXGIAdapter );
    // Take the first output in the adapter.

    DXGI_ADAPTER_DESC AdapterDesc;
    pDXGIAdapter->GetDesc( &AdapterDesc );

    // Use the output interface to get the output description.
    UINT64 availableVideoMem = 0;

    if( AdapterDesc.DedicatedVideoMemory )
        availableVideoMem = AdapterDesc.DedicatedVideoMemory;
    else
        availableVideoMem = AdapterDesc.SharedSystemMemory;

    // Release all of the interfaces

    pDXGIDevice->Release();
    pDXGIAdapter->Release();

    // Return the current output's resolution from the description.
    return availableVideoMem;
}
native DirectX:
 IDXGIDevice* pDXGIDevice = NULL;
    IDXGIAdapter* pDXGIAdapter = NULL;

    pd3dDevice->QueryInterface( IID_IDXGIDevice, ( void** )&pDXGIDevice );
    pDXGIDevice->GetAdapter( &pDXGIAdapter );

    DXGI_ADAPTER_DESC AdapterDesc;
    pDXGIAdapter->GetDesc( &AdapterDesc );

    if( AdapterDesc.DedicatedVideoMemory ) {
        g_AvailableVideoMem = AdapterDesc.DedicatedVideoMemory;
    } else {
        g_AvailableVideoMem = AdapterDesc.SharedSystemMemory;
    }

    SAFE_RELEASE( pDXGIDevice );
    SAFE_RELEASE( pDXGIAdapter );
SharpDX:
using (var xgidev = Device.QueryInterface<SharpDX.DXGI.Device>())
            using (var adapter = xgidev.Adapter)
            {
                g_AvailableVideoMem = adapter.Description.DedicatedVideoMemory;
                if(g_AvailableVideoMem == 0)
                    g_AvailableVideoMem = adapter.Description.SharedSystemMemory;

                if (g_AvailableVideoMem < 0)
                    g_AvailableVideoMem *= -1;
            }
Coordinator
Aug 13, 2013 at 1:53 AM
Sure, I can add this. I'm working on another commit right now, so it should be in fairly soon. Thanks for the contribution!
Aug 13, 2013 at 3:30 AM
Edited Aug 13, 2013 at 3:33 AM
Very nice.

Can you implement this methods too in the Vector3f class?

Returns the square of the length of the specified 3-D vector.
http://msdn.microsoft.com/en-us/library/windows/desktop/ms904578.aspx
float Vector3f::LengthSq( const Vector3f& A ) {
    return Dot(A, A);
}
As Member function perhaps too:
float Vector3f::LengthSq(  ) {
    return Dot(*this, *this);
}
Coordinator
Oct 1, 2013 at 9:55 PM
Both of these methods have been added in commit 85478. Please let me know if you find any issues with them!