D3D9/12: Added GPU memory info.

This commit is contained in:
Branimir Karadžić 2017-10-01 21:18:29 -07:00
parent 7030de8d73
commit 5a9adcc337
4 changed files with 31 additions and 30 deletions

View File

@ -53,11 +53,11 @@ namespace bgfx
typedef NvApiStatus (NVAPICALL* PFN_NVAPI_GPUGETMEMORYINFO)(NvPhysicalGpuHandle* _handle, NvMemoryInfoV2* _memoryInfo);
typedef NvApiStatus (NVAPICALL* PFN_NVAPI_GPUGETFULLNAME)(NvPhysicalGpuHandle* _physicalGpu, char _name[64]);
#define NVAPI_INITIALIZE UINT32_C(0x0150e828)
#define NVAPI_UNLOAD UINT32_C(0xd22bdd7e)
#define NVAPI_ENUMPHYSICALGPUS UINT32_C(0xe5ac921f)
#define NVAPI_GPUGETMEMORYINFO UINT32_C(0x07f9b368)
#define NVAPI_GPUGETFULLNAME UINT32_C(0xceee8e9f)
#define NVAPI_INITIALIZE UINT32_C(0x0150e828)
#define NVAPI_UNLOAD UINT32_C(0xd22bdd7e)
#define NVAPI_ENUMPHYSICALGPUS UINT32_C(0xe5ac921f)
#define NVAPI_GPUGETMEMORYINFO UINT32_C(0x07f9b368)
#define NVAPI_GPUGETFULLNAME UINT32_C(0xceee8e9f)
static PFN_NVAPI_QUERYINTERFACE nvApiQueryInterface;
static PFN_NVAPI_INITIALIZE nvApiInitialize;
@ -149,15 +149,15 @@ namespace bgfx
m_nvGpu = NULL;
}
bx::dlclose(m_nvApiDll);
m_nvApiDll = NULL;
if (NULL != m_nvApiDll)
{
bx::dlclose(m_nvApiDll);
m_nvApiDll = NULL;
}
}
void NvApi::getMemoryInfo(int64_t& _gpuMemoryUsed, int64_t& _gpuMemoryMax)
{
_gpuMemoryMax = -INT64_MAX;
_gpuMemoryUsed = -INT64_MAX;
if (NULL != m_nvGpu)
{
NvMemoryInfoV2 memInfo;
@ -173,6 +173,11 @@ namespace bgfx
// BX_TRACE("curAvailableDedicatedVideoMemory: %d KiB", memInfo.curAvailableDedicatedVideoMemory);
}
}
else
{
_gpuMemoryMax = -INT64_MAX;
_gpuMemoryUsed = -INT64_MAX;
}
}
} // namespace bgfx

View File

@ -5752,6 +5752,15 @@ data.NumQualityLevels = 0;
perfStats.gpuMemoryMax = -INT64_MAX;
perfStats.gpuMemoryUsed = -INT64_MAX;
#if BX_PLATFORM_WINDOWS
DXGI_QUERY_VIDEO_MEMORY_INFO vmi[2];
DX_CHECK(m_adapter->QueryVideoMemoryInfo(0, DXGI_MEMORY_SEGMENT_GROUP_LOCAL, &vmi[0]) );
DX_CHECK(m_adapter->QueryVideoMemoryInfo(0, DXGI_MEMORY_SEGMENT_GROUP_NON_LOCAL, &vmi[1]) );
perfStats.gpuMemoryMax = int64_t(vmi[0].Budget);
perfStats.gpuMemoryUsed = int64_t(vmi[0].CurrentUsage);
#endif // BX_PLATFORM_WINDOWS
if (_render->m_debug & (BGFX_DEBUG_IFH|BGFX_DEBUG_STATS) )
{
// PIX_BEGINEVENT(D3DCOLOR_FRAME, L"debugstats");
@ -5802,10 +5811,6 @@ data.NumQualityLevels = 0;
);
#if BX_PLATFORM_WINDOWS
DXGI_QUERY_VIDEO_MEMORY_INFO vmi[2];
DX_CHECK(m_adapter->QueryVideoMemoryInfo(0, DXGI_MEMORY_SEGMENT_GROUP_LOCAL, &vmi[0]) );
DX_CHECK(m_adapter->QueryVideoMemoryInfo(0, DXGI_MEMORY_SEGMENT_GROUP_NON_LOCAL, &vmi[1]) );
for (uint32_t ii = 0; ii < BX_COUNTOF(vmi); ++ii)
{
const DXGI_QUERY_VIDEO_MEMORY_INFO& memInfo = vmi[ii];

View File

@ -453,6 +453,8 @@ namespace bgfx { namespace d3d9
errorState = ErrorState::LoadedD3D9;
m_nvapi.init();
if (BX_ENABLED(BGFX_CONFIG_DEBUG_PIX) )
{
D3DPERF_SetMarker = (PFN_D3DPERF_SET_MARKER )bx::dlsym(m_d3d9dll, "D3DPERF_SetMarker");
@ -879,10 +881,9 @@ namespace bgfx { namespace d3d9
DX_RELEASE(m_d3d9, 0);
}
#if BX_PLATFORM_WINDOWS
case ErrorState::LoadedD3D9:
m_nvapi.shutdown();
bx::dlclose(m_d3d9dll);
#endif // BX_PLATFORM_WINDOWS
case ErrorState::Default:
break;
@ -928,9 +929,8 @@ namespace bgfx { namespace d3d9
DX_RELEASE(m_d3d9, 0);
}
#if BX_PLATFORM_WINDOWS
m_nvapi.shutdown();
bx::dlclose(m_d3d9dll);
#endif // BX_PLATFORM_WINDOWS
m_initialized = false;
}
@ -1186,7 +1186,6 @@ namespace bgfx { namespace d3d9
void requestScreenShot(FrameBufferHandle _handle, const char* _filePath) override
{
#if BX_PLATFORM_WINDOWS
IDirect3DSwapChain9* swapChain = isValid(_handle)
? m_frameBuffers[_handle.idx].m_swapChain
: m_swapChain
@ -1250,9 +1249,6 @@ namespace bgfx { namespace d3d9
DX_CHECK(surface->UnlockRect() );
DX_RELEASE(surface, 0);
#else
BX_UNUSED(_handle, _filePath);
#endif // BX_PLATFORM_WINDOWS
}
void updateViewName(uint8_t _id, const char* _name) override
@ -1421,7 +1417,6 @@ namespace bgfx { namespace d3d9
m_textVideoMem.resize(false, _resolution.m_width, _resolution.m_height);
m_textVideoMem.clear();
#if BX_PLATFORM_WINDOWS
D3DDEVICE_CREATION_PARAMETERS dcp;
DX_CHECK(m_device->GetCreationParameters(&dcp) );
@ -1429,7 +1424,6 @@ namespace bgfx { namespace d3d9
DX_CHECK(m_d3d9->GetAdapterDisplayMode(dcp.AdapterOrdinal, &dm) );
m_params.BackBufferFormat = dm.Format;
#endif // BX_PLATFORM_WINDOWS
m_params.BackBufferWidth = _resolution.m_width;
m_params.BackBufferHeight = _resolution.m_height;
@ -1554,7 +1548,6 @@ namespace bgfx { namespace d3d9
hr = m_frameBuffers[m_windows[ii].idx].present();
}
#if BX_PLATFORM_WINDOWS
if (isLost(hr) )
{
do
@ -1576,7 +1569,6 @@ namespace bgfx { namespace d3d9
{
BX_TRACE("Present failed with err 0x%08x.", hr);
}
#endif // BX_PLATFORM_
}
}
}
@ -2180,9 +2172,7 @@ namespace bgfx { namespace d3d9
setInputLayout(BX_COUNTOF(decls), decls, _numInstanceData);
}
#if BX_PLATFORM_WINDOWS
D3DCAPS9 m_caps;
#endif // BX_PLATFORM_WINDOWS
IDirect3D9Ex* m_d3d9ex;
IDirect3DDevice9Ex* m_deviceEx;
@ -2210,6 +2200,7 @@ namespace bgfx { namespace d3d9
IDirect3DVertexDeclaration9* m_instanceDataDecls[BGFX_CONFIG_MAX_INSTANCE_DATA_COUNT];
void* m_d3d9dll;
NvApi m_nvapi;
uint32_t m_adapter;
D3DDEVTYPE m_deviceType;
D3DPRESENT_PARAMETERS m_params;
@ -4382,8 +4373,7 @@ namespace bgfx { namespace d3d9
perfStats.numDraw = statsKeyType[0];
perfStats.numCompute = statsKeyType[1];
perfStats.maxGpuLatency = maxGpuLatency;
perfStats.gpuMemoryMax = -INT64_MAX;
perfStats.gpuMemoryUsed = -INT64_MAX;
m_nvapi.getMemoryInfo(perfStats.gpuMemoryUsed, perfStats.gpuMemoryMax);
if (_render->m_debug & (BGFX_DEBUG_IFH|BGFX_DEBUG_STATS) )
{

View File

@ -23,6 +23,7 @@
#include "renderer.h"
#include "renderer_d3d.h"
#include "nvapi.h"
namespace bgfx { namespace d3d9
{