From 6c395391a14920e2c739815fe32cbf08202a5999 Mon Sep 17 00:00:00 2001 From: Andrew Mac Date: Mon, 16 Nov 2015 10:42:56 -0400 Subject: [PATCH] Extended Remotery profiling. --- examples/common/entry/entry.cpp | 8 +----- scripts/genie.lua | 1 + src/bgfx.cpp | 6 +++++ src/bgfx_p.h | 10 ++++++++ src/renderer_d3d11.cpp | 40 +++++++++++++++++++++++++++--- src/renderer_d3d9.cpp | 18 +++++++++++--- src/renderer_gl.cpp | 44 +++++++++++++++++++++++++++------ 7 files changed, 107 insertions(+), 20 deletions(-) diff --git a/examples/common/entry/entry.cpp b/examples/common/entry/entry.cpp index c99688ffa..a7a4fc659 100644 --- a/examples/common/entry/entry.cpp +++ b/examples/common/entry/entry.cpp @@ -4,12 +4,6 @@ */ #include -#if BX_PLATFORM_WINDOWS -// BK - Remotery needs WinSock, but on VS2015/Win10 build -// fails if WinSock2 is included after Windows.h?! -# include -#endif // BX_PLATFORM_WINDOWS - #include #include #include @@ -25,7 +19,7 @@ #include "input.h" #define RMT_ENABLED ENTRY_CONFIG_PROFILER -#include +#include extern "C" int _main_(int _argc, char** _argv); diff --git a/scripts/genie.lua b/scripts/genie.lua index 96e1e022e..9512cc59c 100644 --- a/scripts/genie.lua +++ b/scripts/genie.lua @@ -94,6 +94,7 @@ if _OPTIONS["with-profiler"] then defines { "ENTRY_CONFIG_PROFILER=1", "BGFX_CONFIG_PROFILER_REMOTERY=1", + "_WINSOCKAPI_" } end diff --git a/src/bgfx.cpp b/src/bgfx.cpp index b75037ef8..6e96c6ff1 100644 --- a/src/bgfx.cpp +++ b/src/bgfx.cpp @@ -5,6 +5,12 @@ #include "bgfx_p.h" +#if BGFX_CONFIG_PROFILER_REMOTERY +# define RMT_USE_D3D11 BGFX_CONFIG_RENDERER_DIRECT3D11 +# define RMT_USE_OPENGL 0 +# include +#endif + namespace bgfx { #define BGFX_MAIN_THREAD_MAGIC UINT32_C(0x78666762) diff --git a/src/bgfx_p.h b/src/bgfx_p.h index d9fa751b9..b10f16d70 100644 --- a/src/bgfx_p.h +++ b/src/bgfx_p.h @@ -53,14 +53,24 @@ # if BGFX_CONFIG_PROFILER_MICROPROFILE # include # define BGFX_PROFILER_SCOPE(_group, _name, _color) MICROPROFILE_SCOPEI(#_group, #_name, _color) +# define BGFX_PROFILER_BEGIN(_group, _name, _color) BX_NOOP() +# define BGFX_PROFILER_BEGIN_DYNAMIC(_namestr) BX_NOOP() +# define BGFX_PROFILER_END() BX_NOOP() # define BGFX_PROFILER_SET_CURRENT_THREAD_NAME(_name) BX_NOOP() # elif BGFX_CONFIG_PROFILER_REMOTERY # define RMT_ENABLED BGFX_CONFIG_PROFILER_REMOTERY +# define RMT_USE_D3D11 BGFX_CONFIG_RENDERER_DIRECT3D11 # include # define BGFX_PROFILER_SCOPE(_group, _name, _color) rmt_ScopedCPUSample(_group##_##_name) +# define BGFX_PROFILER_BEGIN(_group, _name, _color) rmt_BeginCPUSample(_group##_##_name) +# define BGFX_PROFILER_BEGIN_DYNAMIC(_namestr) rmt_BeginCPUSampleDynamic(_namestr) +# define BGFX_PROFILER_END() rmt_EndCPUSample() # define BGFX_PROFILER_SET_CURRENT_THREAD_NAME(_name) rmt_SetCurrentThreadName(_name) # else # define BGFX_PROFILER_SCOPE(_group, _name, _color) BX_NOOP() +# define BGFX_PROFILER_BEGIN(_group, _name, _color) BX_NOOP() +# define BGFX_PROFILER_BEGIN_DYNAMIC(_namestr) BX_NOOP() +# define BGFX_PROFILER_END() BX_NOOP() # define BGFX_PROFILER_SET_CURRENT_THREAD_NAME(_name) BX_NOOP() # endif // BGFX_CONFIG_PROFILER_* #endif // BGFX_PROFILER_SCOPE diff --git a/src/renderer_d3d11.cpp b/src/renderer_d3d11.cpp index fe793d0bc..f41b155c1 100644 --- a/src/renderer_d3d11.cpp +++ b/src/renderer_d3d11.cpp @@ -13,9 +13,24 @@ # include #endif // BX_PLATFORM_WINRT +#if BGFX_CONFIG_PROFILER_REMOTERY +# define BGFX_GPU_PROFILER_BIND(_device, _context) rmt_BindD3D11(_device, _context) +# define BGFX_GPU_PROFILER_UNBIND() rmt_UnbindD3D11() +# define BGFX_GPU_PROFILER_BEGIN(_group, _name, _color) rmt_BeginD3D11Sample(_group##_##_name) +# define BGFX_GPU_PROFILER_BEGIN_DYNAMIC(_namestr) rmt_BeginD3D11SampleDynamic(_namestr) +# define BGFX_GPU_PROFILER_END() rmt_EndD3D11Sample() +#else +# define BGFX_GPU_PROFILER_BIND(_device, _context) BX_NOOP() +# define BGFX_GPU_PROFILER_UNBIND() BX_NOOP() +# define BGFX_GPU_PROFILER_BEGIN(_group, _name, _color) BX_NOOP() +# define BGFX_GPU_PROFILER_BEGIN_DYNAMIC(_namestr) BX_NOOP() +# define BGFX_GPU_PROFILER_END() BX_NOOP() +#endif + namespace bgfx { namespace d3d11 { static wchar_t s_viewNameW[BGFX_CONFIG_MAX_VIEWS][BGFX_CONFIG_MAX_VIEW_NAME]; + static char s_viewName[BGFX_CONFIG_MAX_VIEWS][BGFX_CONFIG_MAX_VIEW_NAME]; struct PrimInfo { @@ -1405,9 +1420,8 @@ BX_PRAGMA_DIAGNOSTIC_POP(); // Init reserved part of view name. for (uint32_t ii = 0; ii < BGFX_CONFIG_MAX_VIEWS; ++ii) { - char name[BGFX_CONFIG_MAX_VIEW_NAME_RESERVED+1]; - bx::snprintf(name, sizeof(name), "%3d ", ii); - mbstowcs(s_viewNameW[ii], name, BGFX_CONFIG_MAX_VIEW_NAME_RESERVED); + bx::snprintf(s_viewName[ii], BGFX_CONFIG_MAX_VIEW_NAME_RESERVED + 1, "%3d ", ii); + mbstowcs(s_viewNameW[ii], s_viewName[ii], BGFX_CONFIG_MAX_VIEW_NAME_RESERVED); } if (BX_ENABLED(BGFX_CONFIG_DEBUG) @@ -1449,6 +1463,7 @@ BX_PRAGMA_DIAGNOSTIC_POP(); postReset(); } + BGFX_GPU_PROFILER_BIND(m_device, m_deviceCtx); return true; error: @@ -1501,6 +1516,8 @@ BX_PRAGMA_DIAGNOSTIC_POP(); void shutdown() { + BGFX_GPU_PROFILER_UNBIND(); + preReset(); m_ovr.shutdown(); @@ -1864,6 +1881,11 @@ BX_PRAGMA_DIAGNOSTIC_POP(); , BX_COUNTOF(s_viewNameW[0])-BGFX_CONFIG_MAX_VIEW_NAME_RESERVED ); } + + bx::strlcpy(&s_viewName[_id][BGFX_CONFIG_MAX_VIEW_NAME_RESERVED] + , _name + , BX_COUNTOF(s_viewName[0]) - BGFX_CONFIG_MAX_VIEW_NAME_RESERVED + ); } void updateUniform(uint16_t _loc, const void* _data, uint32_t _size) BX_OVERRIDE @@ -4622,6 +4644,7 @@ BX_PRAGMA_DIAGNOSTIC_POP(); void RendererContextD3D11::submit(Frame* _render, ClearQuad& _clearQuad, TextVideoMemBlitter& _textVideoMemBlitter) { PIX_BEGINEVENT(D3DCOLOR_RGBA(0xff, 0x00, 0x00, 0xff), L"rendererSubmit"); + BGFX_GPU_PROFILER_BEGIN_DYNAMIC("rendererSubmit"); ID3D11DeviceContext* deviceCtx = m_deviceCtx; @@ -4754,6 +4777,13 @@ BX_PRAGMA_DIAGNOSTIC_POP(); } PIX_ENDEVENT(); + if (item > 1) + { + BGFX_GPU_PROFILER_END(); + BGFX_PROFILER_END(); + } + BGFX_PROFILER_BEGIN_DYNAMIC(s_viewName[view]); + BGFX_GPU_PROFILER_BEGIN_DYNAMIC(s_viewName[view]); viewState.m_rect = _render->m_rect[view]; if (viewRestart) @@ -5498,10 +5528,14 @@ BX_PRAGMA_DIAGNOSTIC_POP(); captureElapsed = -bx::getHPCounter(); capture(); captureElapsed += bx::getHPCounter(); + + BGFX_GPU_PROFILER_END(); + BGFX_PROFILER_END(); } } PIX_ENDEVENT(); + BGFX_GPU_PROFILER_END(); int64_t now = bx::getHPCounter(); elapsed += now; diff --git a/src/renderer_d3d9.cpp b/src/renderer_d3d9.cpp index 73ec6d93a..8fe2a7a44 100644 --- a/src/renderer_d3d9.cpp +++ b/src/renderer_d3d9.cpp @@ -11,6 +11,7 @@ namespace bgfx { namespace d3d9 { static wchar_t s_viewNameW[BGFX_CONFIG_MAX_VIEWS][BGFX_CONFIG_MAX_VIEW_NAME]; + static char s_viewName[BGFX_CONFIG_MAX_VIEWS][BGFX_CONFIG_MAX_VIEW_NAME]; struct PrimInfo { @@ -732,9 +733,8 @@ namespace bgfx { namespace d3d9 // Init reserved part of view name. for (uint32_t ii = 0; ii < BGFX_CONFIG_MAX_VIEWS; ++ii) { - char name[BGFX_CONFIG_MAX_VIEW_NAME_RESERVED+1]; - bx::snprintf(name, sizeof(name), "%3d ", ii); - mbstowcs(s_viewNameW[ii], name, BGFX_CONFIG_MAX_VIEW_NAME_RESERVED); + bx::snprintf(s_viewName[ii], BGFX_CONFIG_MAX_VIEW_NAME_RESERVED + 1, "%3d ", ii); + mbstowcs(s_viewNameW[ii], s_viewName[ii], BGFX_CONFIG_MAX_VIEW_NAME_RESERVED); } if (NULL != m_deviceEx) @@ -1106,6 +1106,11 @@ namespace bgfx { namespace d3d9 , BX_COUNTOF(s_viewNameW[0])-BGFX_CONFIG_MAX_VIEW_NAME_RESERVED ); } + + bx::strlcpy(&s_viewName[_id][BGFX_CONFIG_MAX_VIEW_NAME_RESERVED] + , _name + , BX_COUNTOF(s_viewName[0]) - BGFX_CONFIG_MAX_VIEW_NAME_RESERVED + ); } void updateUniform(uint16_t _loc, const void* _data, uint32_t _size) BX_OVERRIDE @@ -3564,6 +3569,11 @@ namespace bgfx { namespace d3d9 PIX_ENDEVENT(); PIX_BEGINEVENT(D3DCOLOR_RGBA(0xff, 0x00, 0x00, 0xff), s_viewNameW[key.m_view]); + if (item > 0) + { + BGFX_PROFILER_END(); + } + BGFX_PROFILER_BEGIN_DYNAMIC(s_viewName[key.m_view]); view = key.m_view; programIdx = invalidHandle; @@ -4077,6 +4087,8 @@ namespace bgfx { namespace d3d9 captureElapsed = -bx::getHPCounter(); capture(); captureElapsed += bx::getHPCounter(); + + BGFX_PROFILER_END(); } } diff --git a/src/renderer_gl.cpp b/src/renderer_gl.cpp index a6918d3f4..1351975bc 100644 --- a/src/renderer_gl.cpp +++ b/src/renderer_gl.cpp @@ -10,6 +10,20 @@ # include # include +#if BGFX_CONFIG_PROFILER_REMOTERY +# define BGFX_GPU_PROFILER_BIND() rmt_BindOpenGL() +# define BGFX_GPU_PROFILER_UNBIND() rmt_UnbindOpenGL() +# define BGFX_GPU_PROFILER_BEGIN(_group, _name, _color) rmt_BeginOpenGLSample(_group##_##_name) +# define BGFX_GPU_PROFILER_BEGIN_DYNAMIC(_namestr) rmt_BeginOpenGLSampleDynamic(_namestr) +# define BGFX_GPU_PROFILER_END() rmt_EndOpenGLSample() +#else +# define BGFX_GPU_PROFILER_BIND(_device, _context) BX_NOOP() +# define BGFX_GPU_PROFILER_UNBIND() BX_NOOP() +# define BGFX_GPU_PROFILER_BEGIN(_group, _name, _color) BX_NOOP() +# define BGFX_GPU_PROFILER_BEGIN_DYNAMIC(_namestr) BX_NOOP() +# define BGFX_GPU_PROFILER_END() BX_NOOP() +#endif + namespace bgfx { namespace gl { static char s_viewName[BGFX_CONFIG_MAX_VIEWS][BGFX_CONFIG_MAX_VIEW_NAME]; @@ -1958,10 +1972,14 @@ namespace bgfx { namespace gl } ovrPostReset(); + + BGFX_GPU_PROFILER_BIND(); } void shutdown() { + BGFX_GPU_PROFILER_UNBIND(); + ovrPreReset(); m_ovr.shutdown(); @@ -2272,13 +2290,10 @@ namespace bgfx { namespace gl void updateViewName(uint8_t _id, const char* _name) BX_OVERRIDE { - if (BX_ENABLED(BGFX_CONFIG_DEBUG_PIX) ) - { - bx::strlcpy(&s_viewName[_id][BGFX_CONFIG_MAX_VIEW_NAME_RESERVED] - , _name - , BX_COUNTOF(s_viewName[0])-BGFX_CONFIG_MAX_VIEW_NAME_RESERVED - ); - } + bx::strlcpy(&s_viewName[_id][BGFX_CONFIG_MAX_VIEW_NAME_RESERVED] + , _name + , BX_COUNTOF(s_viewName[0])-BGFX_CONFIG_MAX_VIEW_NAME_RESERVED + ); } void updateUniform(uint16_t _loc, const void* _data, uint32_t _size) BX_OVERRIDE @@ -5217,6 +5232,8 @@ namespace bgfx { namespace gl void RendererContextGL::submit(Frame* _render, ClearQuad& _clearQuad, TextVideoMemBlitter& _textVideoMemBlitter) { + BGFX_GPU_PROFILER_BEGIN_DYNAMIC("rendererSubmit"); + if (1 < m_numWindows && m_vaoSupport) { @@ -5383,6 +5400,14 @@ namespace bgfx { namespace gl eye = 0; } + if (item > 1) + { + BGFX_GPU_PROFILER_END(); + BGFX_PROFILER_END(); + } + BGFX_PROFILER_BEGIN_DYNAMIC(s_viewName[view]); + BGFX_GPU_PROFILER_BEGIN_DYNAMIC(s_viewName[view]); + viewState.m_rect = _render->m_rect[view]; if (viewRestart) { @@ -6266,9 +6291,14 @@ namespace bgfx { namespace gl captureElapsed = -bx::getHPCounter(); capture(); captureElapsed += bx::getHPCounter(); + + BGFX_GPU_PROFILER_END(); + BGFX_PROFILER_END(); } } + BGFX_GPU_PROFILER_END(); + m_glctx.makeCurrent(NULL); int64_t now = bx::getHPCounter(); elapsed += now;