Merge pull request #573 from andr3wmac/extended_profiling

Extended Remotery profiling.
This commit is contained in:
Branimir Karadžić 2015-11-16 08:42:49 -08:00
commit 9897e6c784
7 changed files with 107 additions and 20 deletions

View file

@ -4,12 +4,6 @@
*/
#include <bx/bx.h>
#if BX_PLATFORM_WINDOWS
// BK - Remotery needs WinSock, but on VS2015/Win10 build
// fails if WinSock2 is included after Windows.h?!
# include <WinSock2.h>
#endif // BX_PLATFORM_WINDOWS
#include <bgfx/bgfx.h>
#include <bx/string.h>
#include <bx/readerwriter.h>
@ -25,7 +19,7 @@
#include "input.h"
#define RMT_ENABLED ENTRY_CONFIG_PROFILER
#include <remotery/lib/Remotery.c>
#include <remotery/lib/Remotery.h>
extern "C" int _main_(int _argc, char** _argv);

View file

@ -94,6 +94,7 @@ if _OPTIONS["with-profiler"] then
defines {
"ENTRY_CONFIG_PROFILER=1",
"BGFX_CONFIG_PROFILER_REMOTERY=1",
"_WINSOCKAPI_"
}
end

View file

@ -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 <remotery/lib/Remotery.c>
#endif
namespace bgfx
{
#define BGFX_MAIN_THREAD_MAGIC UINT32_C(0x78666762)

View file

@ -53,14 +53,24 @@
# if BGFX_CONFIG_PROFILER_MICROPROFILE
# include <microprofile.h>
# 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 <remotery/lib/Remotery.h>
# 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

View file

@ -13,9 +13,24 @@
# include <windows.ui.xaml.media.dxinterop.h>
#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;

View file

@ -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();
}
}

View file

@ -10,6 +10,20 @@
# include <bx/timer.h>
# include <bx/uint32_t.h>
#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;