|
@@ -15,6 +15,7 @@ namespace bgfx
|
|
|
* http://docs.nvidia.com/gameworks/content/gameworkslibrary/coresdk/nvapi/index.html
|
|
* http://docs.nvidia.com/gameworks/content/gameworkslibrary/coresdk/nvapi/index.html
|
|
|
* https://github.com/jNizM/AHK_NVIDIA_NvAPI/blob/master/info/NvAPI_IDs.txt
|
|
* https://github.com/jNizM/AHK_NVIDIA_NvAPI/blob/master/info/NvAPI_IDs.txt
|
|
|
*/
|
|
*/
|
|
|
|
|
+
|
|
|
struct NvPhysicalGpuHandle;
|
|
struct NvPhysicalGpuHandle;
|
|
|
|
|
|
|
|
#define NVAPI_MAX_PHYSICAL_GPUS 64
|
|
#define NVAPI_MAX_PHYSICAL_GPUS 64
|
|
@@ -68,9 +69,34 @@ namespace bgfx
|
|
|
static PFN_NVAPI_GPUGETMEMORYINFO nvApiGpuGetMemoryInfo;
|
|
static PFN_NVAPI_GPUGETMEMORYINFO nvApiGpuGetMemoryInfo;
|
|
|
static PFN_NVAPI_GPUGETFULLNAME nvApiGpuGetFullName;
|
|
static PFN_NVAPI_GPUGETFULLNAME nvApiGpuGetFullName;
|
|
|
|
|
|
|
|
|
|
+ /*
|
|
|
|
|
+ * NVIDIA Aftermath
|
|
|
|
|
+ *
|
|
|
|
|
+ * Reference:
|
|
|
|
|
+ * https://developer.nvidia.com/nvidia-aftermath
|
|
|
|
|
+ */
|
|
|
|
|
+
|
|
|
|
|
+ typedef int32_t (*PFN_NVAFTERMATH_DX12_INITIALIZE)(int32_t _version, int32_t _flags, const ID3D12Device* _device);
|
|
|
|
|
+ typedef int32_t (*PFN_NVAFTERMATH_DX12_CREATECONTEXTHANDLE)(const ID3D12CommandList* _commandList, NvAftermathContextHandle** _outContextHandle);
|
|
|
|
|
+ typedef int32_t (*PFN_NVAFTERMATH_RELEASECONTEXTHANDLE)(const NvAftermathContextHandle* _contextHandle);
|
|
|
|
|
+ typedef int32_t (*PFN_NVAFTERMATH_SETEVENTMARKER)(const NvAftermathContextHandle* _contextHandle, const void* _markerData, uint32_t _markerSize);
|
|
|
|
|
+ typedef int32_t (*PFN_NVAFTERMATH_GETDATA)(uint32_t _numContexts, const NvAftermathContextHandle** _contextHandles, void* _outContextData);
|
|
|
|
|
+ typedef int32_t (*PFN_NVAFTERMATH_GETDEVICESTATUS)(void* _outStatus);
|
|
|
|
|
+ typedef int32_t (*PFN_NVAFTERMATH_GETPAGEFAULTINFORMATION)(void* _outPageFaultInformation);
|
|
|
|
|
+
|
|
|
|
|
+ static PFN_NVAFTERMATH_DX12_INITIALIZE nvAftermathDx12Initialize;
|
|
|
|
|
+ static PFN_NVAFTERMATH_DX12_CREATECONTEXTHANDLE nvAftermathDx12CreateContextHandle;
|
|
|
|
|
+ static PFN_NVAFTERMATH_RELEASECONTEXTHANDLE nvAftermathReleaseContextHandle;
|
|
|
|
|
+ static PFN_NVAFTERMATH_SETEVENTMARKER nvAftermathSetEventMarker;
|
|
|
|
|
+ static PFN_NVAFTERMATH_GETDATA nvAftermathGetData;
|
|
|
|
|
+ static PFN_NVAFTERMATH_GETDEVICESTATUS nvAftermathGetDeviceStatus;
|
|
|
|
|
+ static PFN_NVAFTERMATH_GETPAGEFAULTINFORMATION nvAftermathGetPageFaultInformation;
|
|
|
|
|
+
|
|
|
NvApi::NvApi()
|
|
NvApi::NvApi()
|
|
|
: m_nvApiDll(NULL)
|
|
: m_nvApiDll(NULL)
|
|
|
, m_nvGpu(NULL)
|
|
, m_nvGpu(NULL)
|
|
|
|
|
+ , m_nvAftermathDll(NULL)
|
|
|
|
|
+ , m_aftermathHandle(NULL)
|
|
|
{
|
|
{
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -78,11 +104,11 @@ namespace bgfx
|
|
|
{
|
|
{
|
|
|
m_nvGpu = NULL;
|
|
m_nvGpu = NULL;
|
|
|
m_nvApiDll = bx::dlopen(
|
|
m_nvApiDll = bx::dlopen(
|
|
|
-#if BX_ARCH_32BIT
|
|
|
|
|
- "nvapi.dll"
|
|
|
|
|
-#else
|
|
|
|
|
- "nvapi64.dll"
|
|
|
|
|
|
|
+ "nvapi"
|
|
|
|
|
+#if BX_ARCH_64BIT
|
|
|
|
|
+ "64"
|
|
|
#endif // BX_ARCH_32BIT
|
|
#endif // BX_ARCH_32BIT
|
|
|
|
|
+ ".dll"
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
if (NULL != m_nvApiDll)
|
|
if (NULL != m_nvApiDll)
|
|
@@ -99,8 +125,8 @@ namespace bgfx
|
|
|
nvApiGpuGetMemoryInfo = (PFN_NVAPI_GPUGETMEMORYINFO )nvApiQueryInterface(NVAPI_GPUGETMEMORYINFO);
|
|
nvApiGpuGetMemoryInfo = (PFN_NVAPI_GPUGETMEMORYINFO )nvApiQueryInterface(NVAPI_GPUGETMEMORYINFO);
|
|
|
nvApiGpuGetFullName = (PFN_NVAPI_GPUGETFULLNAME )nvApiQueryInterface(NVAPI_GPUGETFULLNAME);
|
|
nvApiGpuGetFullName = (PFN_NVAPI_GPUGETFULLNAME )nvApiQueryInterface(NVAPI_GPUGETFULLNAME);
|
|
|
|
|
|
|
|
- nvApiD3D11MultiDrawInstancedIndirect = (NvMultiDrawIndirectFn)nvApiQueryInterface(NVAPI_MULTIDRAWINSTANCEDINDIRECT);
|
|
|
|
|
- nvApiD3D11MultiDrawIndexedInstancedIndirect = (NvMultiDrawIndirectFn)nvApiQueryInterface(NVAPI_MULTIDRAWINDEXEDINSTANCEDINDIRECT);
|
|
|
|
|
|
|
+ nvApiD3D11MultiDrawInstancedIndirect = (PFN_NVAPI_MULTIDRAWINDIRECT)nvApiQueryInterface(NVAPI_MULTIDRAWINSTANCEDINDIRECT);
|
|
|
|
|
+ nvApiD3D11MultiDrawIndexedInstancedIndirect = (PFN_NVAPI_MULTIDRAWINDIRECT)nvApiQueryInterface(NVAPI_MULTIDRAWINDEXEDINSTANCEDINDIRECT);
|
|
|
|
|
|
|
|
initialized = true
|
|
initialized = true
|
|
|
&& NULL != nvApiInitialize
|
|
&& NULL != nvApiInitialize
|
|
@@ -159,6 +185,8 @@ namespace bgfx
|
|
|
bx::dlclose(m_nvApiDll);
|
|
bx::dlclose(m_nvApiDll);
|
|
|
m_nvApiDll = NULL;
|
|
m_nvApiDll = NULL;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ shutdownAftermath();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void NvApi::getMemoryInfo(int64_t& _gpuMemoryUsed, int64_t& _gpuMemoryMax)
|
|
void NvApi::getMemoryInfo(int64_t& _gpuMemoryUsed, int64_t& _gpuMemoryMax)
|
|
@@ -185,4 +213,87 @@ namespace bgfx
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ bool NvApi::initAftermath(const ID3D12Device* _device, const ID3D12CommandList* _commandList)
|
|
|
|
|
+ {
|
|
|
|
|
+ m_nvAftermathDll = bx::dlopen(
|
|
|
|
|
+ "GFSDK_Aftermath_Lib."
|
|
|
|
|
+#if BX_ARCH_32BIT
|
|
|
|
|
+ "x86"
|
|
|
|
|
+#else
|
|
|
|
|
+ "x64"
|
|
|
|
|
+#endif // BX_ARCH_32BIT
|
|
|
|
|
+ ".dll"
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ if (NULL != m_nvAftermathDll)
|
|
|
|
|
+ {
|
|
|
|
|
+ nvAftermathDx12Initialize = (PFN_NVAFTERMATH_DX12_INITIALIZE )bx::dlsym(m_nvAftermathDll, "GFSDK_Aftermath_DX12_Initialize");
|
|
|
|
|
+ nvAftermathDx12CreateContextHandle = (PFN_NVAFTERMATH_DX12_CREATECONTEXTHANDLE)bx::dlsym(m_nvAftermathDll, "GFSDK_Aftermath_DX12_CreateContextHandle");
|
|
|
|
|
+ nvAftermathReleaseContextHandle = (PFN_NVAFTERMATH_RELEASECONTEXTHANDLE )bx::dlsym(m_nvAftermathDll, "GFSDK_Aftermath_ReleaseContextHandle");
|
|
|
|
|
+ nvAftermathSetEventMarker = (PFN_NVAFTERMATH_SETEVENTMARKER )bx::dlsym(m_nvAftermathDll, "GFSDK_Aftermath_SetEventMarker");
|
|
|
|
|
+ nvAftermathGetData = (PFN_NVAFTERMATH_GETDATA )bx::dlsym(m_nvAftermathDll, "GFSDK_Aftermath_GetData");
|
|
|
|
|
+ nvAftermathGetDeviceStatus = (PFN_NVAFTERMATH_GETDEVICESTATUS )bx::dlsym(m_nvAftermathDll, "GFSDK_Aftermath_GetDeviceStatus");
|
|
|
|
|
+ nvAftermathGetPageFaultInformation = (PFN_NVAFTERMATH_GETPAGEFAULTINFORMATION )bx::dlsym(m_nvAftermathDll, "GFSDK_Aftermath_GetPageFaultInformation");
|
|
|
|
|
+
|
|
|
|
|
+ bool initialized = true
|
|
|
|
|
+ && NULL != nvAftermathDx12Initialize
|
|
|
|
|
+ && NULL != nvAftermathDx12CreateContextHandle
|
|
|
|
|
+ && NULL != nvAftermathReleaseContextHandle
|
|
|
|
|
+ && NULL != nvAftermathSetEventMarker
|
|
|
|
|
+ && NULL != nvAftermathGetData
|
|
|
|
|
+ && NULL != nvAftermathGetDeviceStatus
|
|
|
|
|
+ && NULL != nvAftermathGetPageFaultInformation
|
|
|
|
|
+ ;
|
|
|
|
|
+
|
|
|
|
|
+ if (initialized)
|
|
|
|
|
+ {
|
|
|
|
|
+ int32_t result;
|
|
|
|
|
+ result = nvAftermathDx12Initialize(0x13, 1, _device);
|
|
|
|
|
+ if (1 == result)
|
|
|
|
|
+ {
|
|
|
|
|
+ result = nvAftermathDx12CreateContextHandle(_commandList, &m_aftermathHandle);
|
|
|
|
|
+ BX_WARN(1 == result, "%x", result);
|
|
|
|
|
+
|
|
|
|
|
+ if (1 == result)
|
|
|
|
|
+ {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ shutdownAftermath();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ void NvApi::shutdownAftermath()
|
|
|
|
|
+ {
|
|
|
|
|
+ if (NULL != m_nvAftermathDll)
|
|
|
|
|
+ {
|
|
|
|
|
+ if (NULL != m_aftermathHandle)
|
|
|
|
|
+ {
|
|
|
|
|
+ nvAftermathReleaseContextHandle(m_aftermathHandle);
|
|
|
|
|
+ m_aftermathHandle = NULL;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ bx::dlclose(m_nvAftermathDll);
|
|
|
|
|
+ m_nvAftermathDll = NULL;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+#define NVA_CHECK(_call) \
|
|
|
|
|
+ BX_MACRO_BLOCK_BEGIN \
|
|
|
|
|
+ int32_t __result__ = _call; \
|
|
|
|
|
+ BX_CHECK(1 == __result__, #_call " FAILED 0x%08x\n", __result__); \
|
|
|
|
|
+ BX_MACRO_BLOCK_END
|
|
|
|
|
+
|
|
|
|
|
+ void NvApi::setMarker(const bx::StringView& _marker)
|
|
|
|
|
+ {
|
|
|
|
|
+ if (NULL != m_aftermathHandle)
|
|
|
|
|
+ {
|
|
|
|
|
+ NVA_CHECK(nvAftermathSetEventMarker(m_aftermathHandle, _marker.getPtr(), _marker.getLength() ) );
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
} // namespace bgfx
|
|
} // namespace bgfx
|