Added ability to set view name for profiling events.

This commit is contained in:
bkaradzic 2013-06-09 15:28:25 -07:00
parent 493766caa6
commit a5c6c0bf5b
12 changed files with 197 additions and 77 deletions

View file

@ -706,8 +706,10 @@ namespace bgfx
void updateTexture3D(TextureHandle _handle, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _z, uint16_t _width, uint16_t _height, uint16_t _depth, const Memory* _mem); void updateTexture3D(TextureHandle _handle, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _z, uint16_t _width, uint16_t _height, uint16_t _depth, const Memory* _mem);
/// Update Cube texture. /// Update Cube texture.
///
/// @param _side Cubemap side, where 0 is +X, 1 is -X, 2 is +Y, 3 is /// @param _side Cubemap side, where 0 is +X, 1 is -X, 2 is +Y, 3 is
/// -Y, 4 is +Z, and 5 is -Z. /// -Y, 4 is +Z, and 5 is -Z.
///
void updateTextureCube(TextureHandle _handle, uint8_t _side, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const Memory* _mem); void updateTextureCube(TextureHandle _handle, uint8_t _side, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const Memory* _mem);
/// Destroy texture. /// Destroy texture.
@ -725,6 +727,16 @@ namespace bgfx
/// Destroy shader uniform parameter. /// Destroy shader uniform parameter.
void destroyUniform(UniformHandle _handle); void destroyUniform(UniformHandle _handle);
/// Set view name.
///
/// @param _id view id.
/// @param _name View name.
///
/// NOTE:
/// This is debug only feature.
///
void setViewName(uint8_t _id, const char* _name);
/// Set view rectangle. Draw primitive outside view will be clipped. /// Set view rectangle. Draw primitive outside view will be clipped.
void setViewRect(uint8_t _id, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height); void setViewRect(uint8_t _id, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height);

View file

@ -748,6 +748,13 @@ namespace bgfx
m_submit->m_transientVb = createTransientVertexBuffer(BGFX_CONFIG_TRANSIENT_VERTEX_BUFFER_SIZE); m_submit->m_transientVb = createTransientVertexBuffer(BGFX_CONFIG_TRANSIENT_VERTEX_BUFFER_SIZE);
m_submit->m_transientIb = createTransientIndexBuffer(BGFX_CONFIG_TRANSIENT_INDEX_BUFFER_SIZE); m_submit->m_transientIb = createTransientIndexBuffer(BGFX_CONFIG_TRANSIENT_INDEX_BUFFER_SIZE);
frame(); frame();
for (uint8_t ii = 0; ii < BGFX_CONFIG_MAX_VIEWS; ++ii)
{
char name[256];
bx::snprintf(name, sizeof(name), "%02d view", ii);
setViewName(ii, name);
}
} }
void Context::shutdown() void Context::shutdown()
@ -1271,6 +1278,12 @@ namespace bgfx
s_ctx.destroyUniform(_handle); s_ctx.destroyUniform(_handle);
} }
void setViewName(uint8_t _id, const char* _name)
{
BGFX_CHECK_MAIN_THREAD();
s_ctx.setViewName(_id, _name);
}
void setViewRect(uint8_t _id, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height) void setViewRect(uint8_t _id, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height)
{ {
BGFX_CHECK_MAIN_THREAD(); BGFX_CHECK_MAIN_THREAD();
@ -1445,9 +1458,6 @@ namespace bgfx
void saveScreenShot(const char* _filePath) void saveScreenShot(const char* _filePath)
{ {
BGFX_CHECK_MAIN_THREAD(); BGFX_CHECK_MAIN_THREAD();
uint32_t len = (uint32_t)strlen(_filePath)+1; s_ctx.saveScreenShot(_filePath);
const Memory* mem = alloc(len);
memcpy(mem->data, _filePath, mem->size);
return s_ctx.saveScreenShot(mem);
} }
} }

View file

@ -478,6 +478,7 @@ namespace bgfx
UpdateTexture, UpdateTexture,
CreateRenderTarget, CreateRenderTarget,
CreateUniform, CreateUniform,
UpdateViewName,
End, End,
RendererShutdownEnd, RendererShutdownEnd,
DestroyVertexDecl, DestroyVertexDecl,
@ -520,10 +521,12 @@ namespace bgfx
read(reinterpret_cast<uint8_t*>(&_in), sizeof(Type) ); read(reinterpret_cast<uint8_t*>(&_in), sizeof(Type) );
} }
void skip(uint32_t _size) const uint8_t* skip(uint32_t _size)
{ {
BX_CHECK(m_pos < m_size, ""); BX_CHECK(m_pos < m_size, "");
const uint8_t* result = &m_buffer[m_pos];
m_pos += _size; m_pos += _size;
return result;
} }
void reset() void reset()
@ -2161,7 +2164,7 @@ namespace bgfx
cmdbuf.write(handle); cmdbuf.write(handle);
cmdbuf.write(_type); cmdbuf.write(_type);
cmdbuf.write(_num); cmdbuf.write(_num);
uint8_t len = (uint8_t)strlen(_name); uint8_t len = (uint8_t)strlen(_name)+1;
cmdbuf.write(len); cmdbuf.write(len);
cmdbuf.write(_name, len); cmdbuf.write(_name, len);
} }
@ -2176,10 +2179,12 @@ namespace bgfx
m_submit->free(_handle); m_submit->free(_handle);
} }
void saveScreenShot(const Memory* _mem) void saveScreenShot(const char* _filePath)
{ {
CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::SaveScreenShot); CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::SaveScreenShot);
cmdbuf.write(_mem); uint16_t len = (uint16_t)strlen(_filePath)+1;
cmdbuf.write(len);
cmdbuf.write(_filePath, len);
} }
void setUniform(UniformHandle _handle, const void* _value, uint16_t _num) void setUniform(UniformHandle _handle, const void* _value, uint16_t _num)
@ -2194,6 +2199,15 @@ namespace bgfx
BX_CHECK(false, "NOT IMPLEMENTED!"); BX_CHECK(false, "NOT IMPLEMENTED!");
} }
void setViewName(uint8_t _id, const char* _name)
{
CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::UpdateViewName);
cmdbuf.write(_id);
uint16_t len = (uint16_t)strlen(_name)+1;
cmdbuf.write(len);
cmdbuf.write(_name, len);
}
void setViewRect(uint8_t _id, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height) void setViewRect(uint8_t _id, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height)
{ {
Rect& rect = m_rect[_id]; Rect& rect = m_rect[_id];
@ -2461,7 +2475,8 @@ namespace bgfx
void rendererDestroyRenderTarget(RenderTargetHandle _handle); void rendererDestroyRenderTarget(RenderTargetHandle _handle);
void rendererCreateUniform(UniformHandle _handle, UniformType::Enum _type, uint16_t _num, const char* _name); void rendererCreateUniform(UniformHandle _handle, UniformType::Enum _type, uint16_t _num, const char* _name);
void rendererDestroyUniform(UniformHandle _handle); void rendererDestroyUniform(UniformHandle _handle);
void rendererSaveScreenShot(Memory* _mem); void rendererSaveScreenShot(const char* _filePath);
void rendererUpdateViewName(uint8_t _id, const char* _name);
void rendererUpdateUniform(uint16_t _loc, const void* _data, uint32_t _size); void rendererUpdateUniform(uint16_t _loc, const void* _data, uint32_t _size);
void rendererUpdateUniforms(ConstantBuffer* _constantBuffer, uint32_t _begin, uint32_t _end) void rendererUpdateUniforms(ConstantBuffer* _constantBuffer, uint32_t _begin, uint32_t _end)
@ -2906,9 +2921,7 @@ namespace bgfx
uint8_t len; uint8_t len;
_cmdbuf.read(len); _cmdbuf.read(len);
char name[256]; const char* name = (const char*)_cmdbuf.skip(len);
_cmdbuf.read(name, len);
name[len] = '\0';
rendererCreateUniform(handle, type, num, name); rendererCreateUniform(handle, type, num, name);
} }
@ -2925,12 +2938,26 @@ namespace bgfx
case CommandBuffer::SaveScreenShot: case CommandBuffer::SaveScreenShot:
{ {
Memory* mem; uint16_t len;
_cmdbuf.read(mem); _cmdbuf.read(len);
rendererSaveScreenShot(mem); const char* filePath = (const char*)_cmdbuf.skip(len);
release(mem); rendererSaveScreenShot(filePath);
}
break;
case CommandBuffer::UpdateViewName:
{
uint8_t id;
_cmdbuf.read(id);
uint16_t len;
_cmdbuf.read(len);
const char* name = (const char*)_cmdbuf.skip(len);
rendererUpdateViewName(id, name);
} }
break; break;

View file

@ -93,7 +93,7 @@
/// DX9 PIX markers /// DX9 PIX markers
#ifndef BGFX_CONFIG_DEBUG_PIX #ifndef BGFX_CONFIG_DEBUG_PIX
# define BGFX_CONFIG_DEBUG_PIX 0 # define BGFX_CONFIG_DEBUG_PIX BGFX_CONFIG_DEBUG
#endif // BGFX_CONFIG_DEBUG_PIX #endif // BGFX_CONFIG_DEBUG_PIX
/// AMD gDEBugger markers /// AMD gDEBugger markers

View file

@ -36,6 +36,28 @@ namespace bgfx
# define DX_CHECK(_call) _call # define DX_CHECK(_call) _call
#endif // BGFX_CONFIG_DEBUG #endif // BGFX_CONFIG_DEBUG
typedef int (WINAPI *D3DPERF_BeginEventFunc)(DWORD _color, LPCWSTR _wszName);
typedef int (WINAPI *D3DPERF_EndEventFunc)();
typedef void (WINAPI *D3DPERF_SetMarkerFunc)(DWORD _color, LPCWSTR _wszName);
typedef void (WINAPI *D3DPERF_SetRegionFunc)(DWORD _color, LPCWSTR _wszName);
typedef BOOL (WINAPI *D3DPERF_QueryRepeatFrameFunc)();
typedef void (WINAPI *D3DPERF_SetOptionsFunc)(DWORD _options);
typedef DWORD (WINAPI *D3DPERF_GetStatusFunc)();
#define _PIX_SETMARKER(_col, _name) s_renderCtx.m_D3DPERF_SetMarker(_col, _name)
#define _PIX_BEGINEVENT(_col, _name) s_renderCtx.m_D3DPERF_BeginEvent(_col, _name)
#define _PIX_ENDEVENT() s_renderCtx.m_D3DPERF_EndEvent()
#if BGFX_CONFIG_DEBUG_PIX
# define PIX_SETMARKER(_color, _name) _PIX_SETMARKER(_color, _name)
# define PIX_BEGINEVENT(_color, _name) _PIX_BEGINEVENT(_color, _name)
# define PIX_ENDEVENT() _PIX_ENDEVENT()
#else
# define PIX_SETMARKER(_color, _name)
# define PIX_BEGINEVENT(_color, _name)
# define PIX_ENDEVENT()
#endif // BGFX_CONFIG_DEBUG_PIX
#if BGFX_CONFIG_DEBUG #if BGFX_CONFIG_DEBUG
# define DX_CHECK_REFCOUNT(_ptr, _expected) \ # define DX_CHECK_REFCOUNT(_ptr, _expected) \
do { \ do { \

View file

@ -10,6 +10,8 @@
namespace bgfx namespace bgfx
{ {
static wchar_t s_viewNameW[BGFX_CONFIG_MAX_VIEWS][256];
typedef HRESULT (WINAPI * PFN_CREATEDXGIFACTORY)(REFIID _riid, void** _factory); typedef HRESULT (WINAPI * PFN_CREATEDXGIFACTORY)(REFIID _riid, void** _factory);
static const D3D11_PRIMITIVE_TOPOLOGY s_primType[] = static const D3D11_PRIMITIVE_TOPOLOGY s_primType[] =
@ -321,6 +323,22 @@ namespace bgfx
m_d3d11dll = LoadLibrary("d3d11.dll"); m_d3d11dll = LoadLibrary("d3d11.dll");
BGFX_FATAL(NULL != m_d3d11dll, Fatal::UnableToInitialize, "Failed to load d3d11.dll."); BGFX_FATAL(NULL != m_d3d11dll, Fatal::UnableToInitialize, "Failed to load d3d11.dll.");
#if BGFX_CONFIG_DEBUG_PIX
// D3D11_1.h has ID3DUserDefinedAnnotation
// http://msdn.microsoft.com/en-us/library/windows/desktop/hh446881%28v=vs.85%29.aspx
m_d3d9dll = LoadLibrary("d3d9.dll");
BGFX_FATAL(NULL != m_d3d9dll, Fatal::UnableToInitialize, "Failed to load d3d9.dll.");
m_D3DPERF_SetMarker = (D3DPERF_SetMarkerFunc)GetProcAddress(m_d3d9dll, "D3DPERF_SetMarker");
m_D3DPERF_BeginEvent = (D3DPERF_BeginEventFunc)GetProcAddress(m_d3d9dll, "D3DPERF_BeginEvent");
m_D3DPERF_EndEvent = (D3DPERF_EndEventFunc)GetProcAddress(m_d3d9dll, "D3DPERF_EndEvent");
BX_CHECK(NULL != m_D3DPERF_SetMarker
&& NULL != m_D3DPERF_BeginEvent
&& NULL != m_D3DPERF_EndEvent
, "Failed to initialize PIX events."
);
#endif // BGFX_CONFIG_DEBUG_PIX
PFN_D3D11_CREATE_DEVICE d3D11CreateDevice = (PFN_D3D11_CREATE_DEVICE)GetProcAddress(m_d3d11dll, "D3D11CreateDevice"); PFN_D3D11_CREATE_DEVICE d3D11CreateDevice = (PFN_D3D11_CREATE_DEVICE)GetProcAddress(m_d3d11dll, "D3D11CreateDevice");
BGFX_FATAL(NULL != d3D11CreateDevice, Fatal::UnableToInitialize, "Function D3D11CreateDevice not found."); BGFX_FATAL(NULL != d3D11CreateDevice, Fatal::UnableToInitialize, "Function D3D11CreateDevice not found.");
@ -1030,7 +1048,7 @@ namespace bgfx
} }
} }
void saveScreenShot(Memory* _mem) void saveScreenShot(const char* _filePath)
{ {
ID3D11Texture2D* backBuffer; ID3D11Texture2D* backBuffer;
DX_CHECK(m_swapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (void**)&backBuffer) ); DX_CHECK(m_swapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (void**)&backBuffer) );
@ -1070,7 +1088,7 @@ namespace bgfx
D3D11_MAPPED_SUBRESOURCE mapped; D3D11_MAPPED_SUBRESOURCE mapped;
DX_CHECK(m_deviceCtx->Map(texture, 0, D3D11_MAP_READ, 0, &mapped) ); DX_CHECK(m_deviceCtx->Map(texture, 0, D3D11_MAP_READ, 0, &mapped) );
g_callback->screenShot( (const char*)_mem->data g_callback->screenShot(_filePath
, backBufferDesc.Width , backBufferDesc.Width
, backBufferDesc.Height , backBufferDesc.Height
, mapped.RowPitch , mapped.RowPitch
@ -1086,6 +1104,13 @@ namespace bgfx
DX_RELEASE(backBuffer, 0); DX_RELEASE(backBuffer, 0);
} }
#if BGFX_CONFIG_DEBUG_PIX
HMODULE m_d3d9dll;
D3DPERF_SetMarkerFunc m_D3DPERF_SetMarker;
D3DPERF_BeginEventFunc m_D3DPERF_BeginEvent;
D3DPERF_EndEventFunc m_D3DPERF_EndEvent;
#endif // BGFX_CONFIG_DEBUG_PIX
HMODULE m_d3d11dll; HMODULE m_d3d11dll;
HMODULE m_dxgidll; HMODULE m_dxgidll;
D3D_DRIVER_TYPE m_driverType; D3D_DRIVER_TYPE m_driverType;
@ -2211,9 +2236,14 @@ namespace bgfx
s_renderCtx.m_uniforms[_handle.idx].destroy(); s_renderCtx.m_uniforms[_handle.idx].destroy();
} }
void Context::rendererSaveScreenShot(Memory* _mem) void Context::rendererSaveScreenShot(const char* _filePath)
{ {
s_renderCtx.saveScreenShot(_mem); s_renderCtx.saveScreenShot(_filePath);
}
void Context::rendererUpdateViewName(uint8_t _id, const char* _name)
{
mbstowcs(&s_viewNameW[_id][0], _name, 256*sizeof(wchar_t) );
} }
void Context::rendererUpdateUniform(uint16_t _loc, const void* _data, uint32_t _size) void Context::rendererUpdateUniform(uint16_t _loc, const void* _data, uint32_t _size)
@ -2223,6 +2253,8 @@ namespace bgfx
void Context::rendererSubmit() void Context::rendererSubmit()
{ {
PIX_BEGINEVENT(D3DCOLOR_RGBA(0xff, 0x00, 0x00, 0xff), L"rendererSubmit");
ID3D11DeviceContext* deviceCtx = s_renderCtx.m_deviceCtx; ID3D11DeviceContext* deviceCtx = s_renderCtx.m_deviceCtx;
s_renderCtx.updateResolution(m_render->m_resolution); s_renderCtx.updateResolution(m_render->m_resolution);
@ -2295,6 +2327,9 @@ namespace bgfx
currentState.m_flags = newFlags; currentState.m_flags = newFlags;
currentState.m_stencil = newStencil; currentState.m_stencil = newStencil;
PIX_ENDEVENT();
PIX_BEGINEVENT(D3DCOLOR_RGBA(0xff, 0x00, 0x00, 0xff), s_viewNameW[key.m_view]);
view = key.m_view; view = key.m_view;
programIdx = invalidHandle; programIdx = invalidHandle;
@ -2721,7 +2756,7 @@ namespace bgfx
if (m_render->m_debug & (BGFX_DEBUG_IFH|BGFX_DEBUG_STATS) ) if (m_render->m_debug & (BGFX_DEBUG_IFH|BGFX_DEBUG_STATS) )
{ {
// PIX_BEGINEVENT(D3DCOLOR_RGBA(0x40, 0x40, 0x40, 0xff), "debugstats"); PIX_BEGINEVENT(D3DCOLOR_RGBA(0x40, 0x40, 0x40, 0xff), L"debugstats");
TextVideoMem& tvm = s_renderCtx.m_textVideoMem; TextVideoMem& tvm = s_renderCtx.m_textVideoMem;
@ -2785,15 +2820,15 @@ namespace bgfx
m_textVideoMemBlitter.blit(tvm); m_textVideoMemBlitter.blit(tvm);
// PIX_ENDEVENT(); PIX_ENDEVENT();
} }
else if (m_render->m_debug & BGFX_DEBUG_TEXT) else if (m_render->m_debug & BGFX_DEBUG_TEXT)
{ {
// PIX_BEGINEVENT(D3DCOLOR_RGBA(0x40, 0x40, 0x40, 0xff), "debugtext"); PIX_BEGINEVENT(D3DCOLOR_RGBA(0x40, 0x40, 0x40, 0xff), L"debugtext");
m_textVideoMemBlitter.blit(m_render->m_textVideoMem); m_textVideoMemBlitter.blit(m_render->m_textVideoMem);
// PIX_ENDEVENT(); PIX_ENDEVENT();
} }
} }
} }

View file

@ -10,6 +10,9 @@
#include <d3d11.h> #include <d3d11.h>
#include "renderer_d3d.h" #include "renderer_d3d.h"
#define D3DCOLOR_ARGB(_a, _r, _g, _b) ( (DWORD)( ( ( (_a)&0xff)<<24)|( ( (_r)&0xff)<<16)|( ( (_g)&0xff)<<8)|( (_b)&0xff) ) )
#define D3DCOLOR_RGBA(_r, _g, _b, _a) D3DCOLOR_ARGB(_a, _r, _g, _b)
namespace bgfx namespace bgfx
{ {
template <typename Ty> template <typename Ty>

View file

@ -10,6 +10,8 @@
namespace bgfx namespace bgfx
{ {
static wchar_t s_viewNameW[BGFX_CONFIG_MAX_VIEWS][256];
static const D3DPRIMITIVETYPE s_primType[] = static const D3DPRIMITIVETYPE s_primType[] =
{ {
D3DPT_TRIANGLELIST, D3DPT_TRIANGLELIST,
@ -250,10 +252,18 @@ namespace bgfx
m_d3d9dll = LoadLibrary("d3d9.dll"); m_d3d9dll = LoadLibrary("d3d9.dll");
BGFX_FATAL(NULL != m_d3d9dll, Fatal::UnableToInitialize, "Failed to load d3d9.dll."); BGFX_FATAL(NULL != m_d3d9dll, Fatal::UnableToInitialize, "Failed to load d3d9.dll.");
#if BGFX_CONFIG_DEBUG_PIX
m_D3DPERF_SetMarker = (D3DPERF_SetMarkerFunc)GetProcAddress(m_d3d9dll, "D3DPERF_SetMarker"); m_D3DPERF_SetMarker = (D3DPERF_SetMarkerFunc)GetProcAddress(m_d3d9dll, "D3DPERF_SetMarker");
m_D3DPERF_BeginEvent = (D3DPERF_BeginEventFunc)GetProcAddress(m_d3d9dll, "D3DPERF_BeginEvent"); m_D3DPERF_BeginEvent = (D3DPERF_BeginEventFunc)GetProcAddress(m_d3d9dll, "D3DPERF_BeginEvent");
m_D3DPERF_EndEvent = (D3DPERF_EndEventFunc)GetProcAddress(m_d3d9dll, "D3DPERF_EndEvent"); m_D3DPERF_EndEvent = (D3DPERF_EndEventFunc)GetProcAddress(m_d3d9dll, "D3DPERF_EndEvent");
BX_CHECK(NULL != m_D3DPERF_SetMarker
&& NULL != m_D3DPERF_BeginEvent
&& NULL != m_D3DPERF_EndEvent
, "Failed to initialize PIX events."
);
#endif // BGFX_CONFIG_DEBUG_PIX
#if BGFX_CONFIG_RENDERER_DIRECT3D9EX #if BGFX_CONFIG_RENDERER_DIRECT3D9EX
Direct3DCreate9ExFn direct3DCreate9Ex = (Direct3DCreate9ExFn)GetProcAddress(m_d3d9dll, "Direct3DCreate9Ex"); Direct3DCreate9ExFn direct3DCreate9Ex = (Direct3DCreate9ExFn)GetProcAddress(m_d3d9dll, "Direct3DCreate9Ex");
BGFX_FATAL(NULL != direct3DCreate9Ex, Fatal::UnableToInitialize, "Function Direct3DCreate9Ex not found."); BGFX_FATAL(NULL != direct3DCreate9Ex, Fatal::UnableToInitialize, "Function Direct3DCreate9Ex not found.");
@ -797,7 +807,7 @@ namespace bgfx
} }
} }
void saveScreenShot(Memory* _mem) void saveScreenShot(const char* _filePath)
{ {
#if BX_PLATFORM_WINDOWS #if BX_PLATFORM_WINDOWS
IDirect3DSurface9* surface; IDirect3DSurface9* surface;
@ -832,7 +842,7 @@ namespace bgfx
uint8_t* data = (uint8_t*)rect.pBits; uint8_t* data = (uint8_t*)rect.pBits;
uint32_t bytesPerPixel = rect.Pitch/dm.Width; uint32_t bytesPerPixel = rect.Pitch/dm.Width;
g_callback->screenShot( (const char*)_mem->data g_callback->screenShot(_filePath
, m_params.BackBufferWidth , m_params.BackBufferWidth
, m_params.BackBufferHeight , m_params.BackBufferHeight
, rect.Pitch , rect.Pitch
@ -849,9 +859,11 @@ namespace bgfx
#if BX_PLATFORM_WINDOWS #if BX_PLATFORM_WINDOWS
D3DCAPS9 m_caps; D3DCAPS9 m_caps;
# if BGFX_CONFIG_DEBUG_PIX
D3DPERF_SetMarkerFunc m_D3DPERF_SetMarker; D3DPERF_SetMarkerFunc m_D3DPERF_SetMarker;
D3DPERF_BeginEventFunc m_D3DPERF_BeginEvent; D3DPERF_BeginEventFunc m_D3DPERF_BeginEvent;
D3DPERF_EndEventFunc m_D3DPERF_EndEvent; D3DPERF_EndEventFunc m_D3DPERF_EndEvent;
# endif // BGFX_CONFIG_DEBUG_PIX
#endif // BX_PLATFORM_WINDOWS #endif // BX_PLATFORM_WINDOWS
#if BGFX_CONFIG_RENDERER_DIRECT3D9EX #if BGFX_CONFIG_RENDERER_DIRECT3D9EX
@ -2122,9 +2134,14 @@ namespace bgfx
g_free(s_renderCtx.m_uniforms[_handle.idx]); g_free(s_renderCtx.m_uniforms[_handle.idx]);
} }
void Context::rendererSaveScreenShot(Memory* _mem) void Context::rendererSaveScreenShot(const char* _filePath)
{ {
s_renderCtx.saveScreenShot(_mem); s_renderCtx.saveScreenShot(_filePath);
}
void Context::rendererUpdateViewName(uint8_t _id, const char* _name)
{
mbstowcs(&s_viewNameW[_id][0], _name, 256*sizeof(wchar_t) );
} }
void Context::rendererUpdateUniform(uint16_t _loc, const void* _data, uint32_t _size) void Context::rendererUpdateUniform(uint16_t _loc, const void* _data, uint32_t _size)
@ -2136,7 +2153,7 @@ namespace bgfx
{ {
IDirect3DDevice9* device = s_renderCtx.m_device; IDirect3DDevice9* device = s_renderCtx.m_device;
PIX_BEGINEVENT(D3DCOLOR_RGBA(0xff, 0x00, 0x00, 0xff), "rendererSubmit"); PIX_BEGINEVENT(D3DCOLOR_RGBA(0xff, 0x00, 0x00, 0xff), L"rendererSubmit");
s_renderCtx.updateResolution(m_render->m_resolution); s_renderCtx.updateResolution(m_render->m_resolution);
@ -2209,7 +2226,7 @@ namespace bgfx
currentState.m_stencil = newStencil; currentState.m_stencil = newStencil;
PIX_ENDEVENT(); PIX_ENDEVENT();
PIX_BEGINEVENT(D3DCOLOR_RGBA(0xff, 0x00, 0x00, 0xff), "view"); PIX_BEGINEVENT(D3DCOLOR_RGBA(0xff, 0x00, 0x00, 0xff), s_viewNameW[key.m_view]);
view = key.m_view; view = key.m_view;
programIdx = invalidHandle; programIdx = invalidHandle;
@ -2761,7 +2778,7 @@ namespace bgfx
if (m_render->m_debug & (BGFX_DEBUG_IFH|BGFX_DEBUG_STATS) ) if (m_render->m_debug & (BGFX_DEBUG_IFH|BGFX_DEBUG_STATS) )
{ {
PIX_BEGINEVENT(D3DCOLOR_RGBA(0x40, 0x40, 0x40, 0xff), "debugstats"); PIX_BEGINEVENT(D3DCOLOR_RGBA(0x40, 0x40, 0x40, 0xff), L"debugstats");
TextVideoMem& tvm = s_renderCtx.m_textVideoMem; TextVideoMem& tvm = s_renderCtx.m_textVideoMem;
@ -2823,7 +2840,7 @@ namespace bgfx
} }
else if (m_render->m_debug & BGFX_DEBUG_TEXT) else if (m_render->m_debug & BGFX_DEBUG_TEXT)
{ {
PIX_BEGINEVENT(D3DCOLOR_RGBA(0x40, 0x40, 0x40, 0xff), "debugtext"); PIX_BEGINEVENT(D3DCOLOR_RGBA(0x40, 0x40, 0x40, 0xff), L"debugtext");
m_textVideoMemBlitter.blit(m_render->m_textVideoMem); m_textVideoMemBlitter.blit(m_render->m_textVideoMem);

View file

@ -28,18 +28,6 @@ typedef HRESULT (WINAPI *Direct3DCreate9ExFn)(UINT SDKVersion, IDirect3D9Ex**);
typedef IDirect3D9* (WINAPI *Direct3DCreate9Fn)(UINT SDKVersion); typedef IDirect3D9* (WINAPI *Direct3DCreate9Fn)(UINT SDKVersion);
# endif // BGFX_CONFIG_RENDERER_DIRECT3D9EX # endif // BGFX_CONFIG_RENDERER_DIRECT3D9EX
typedef int (WINAPI *D3DPERF_BeginEventFunc)(D3DCOLOR col, LPCWSTR wszName);
typedef int (WINAPI *D3DPERF_EndEventFunc)();
typedef void (WINAPI *D3DPERF_SetMarkerFunc)(D3DCOLOR col, LPCWSTR wszName);
typedef void (WINAPI *D3DPERF_SetRegionFunc)(D3DCOLOR col, LPCWSTR wszName);
typedef BOOL (WINAPI *D3DPERF_QueryRepeatFrameFunc)();
typedef void (WINAPI *D3DPERF_SetOptionsFunc)(DWORD dwOptions);
typedef DWORD (WINAPI *D3DPERF_GetStatusFunc)();
# define _PIX_SETMARKER(_col, _name) s_renderCtx.m_D3DPERF_SetMarker(_col, L#_name)
# define _PIX_BEGINEVENT(_col, _name) s_renderCtx.m_D3DPERF_BeginEvent(_col, L#_name)
# define _PIX_ENDEVENT() s_renderCtx.m_D3DPERF_EndEvent()
#elif BX_PLATFORM_XBOX360 #elif BX_PLATFORM_XBOX360
# include <xgraphics.h> # include <xgraphics.h>
# define D3DUSAGE_DYNAMIC 0 // not supported on X360 # define D3DUSAGE_DYNAMIC 0 // not supported on X360
@ -60,16 +48,6 @@ typedef DWORD (WINAPI *D3DPERF_GetStatusFunc)();
namespace bgfx namespace bgfx
{ {
#if BGFX_CONFIG_DEBUG_PIX
# define PIX_SETMARKER(_col, _name) _PIX_SETMARKER(_col, _name)
# define PIX_BEGINEVENT(_col, _name) _PIX_BEGINEVENT(_col, _name)
# define PIX_ENDEVENT() _PIX_ENDEVENT()
#else
# define PIX_SETMARKER(_col, _name)
# define PIX_BEGINEVENT(_col, _name)
# define PIX_ENDEVENT()
#endif // BGFX_CONFIG_DEBUG_PIX
# ifndef D3DFMT_ATI1 # ifndef D3DFMT_ATI1
# define D3DFMT_ATI1 ( (D3DFORMAT)BX_MAKEFOURCC('A', 'T', 'I', '1') ) # define D3DFMT_ATI1 ( (D3DFORMAT)BX_MAKEFOURCC('A', 'T', 'I', '1') )
# endif // D3DFMT_ATI1 # endif // D3DFMT_ATI1

View file

@ -12,6 +12,8 @@
namespace bgfx namespace bgfx
{ {
static char s_viewName[BGFX_CONFIG_MAX_VIEWS][256];
struct Extension struct Extension
{ {
enum Enum enum Enum
@ -143,6 +145,16 @@ namespace bgfx
static PFNGLDRAWELEMENTSINSTANCEDBGFXPROC s_drawElementsInstanced = stubDrawElementsInstanced; static PFNGLDRAWELEMENTSINSTANCEDBGFXPROC s_drawElementsInstanced = stubDrawElementsInstanced;
#endif // BGFX_CONFIG_RENDERER_OPENGLES3 #endif // BGFX_CONFIG_RENDERER_OPENGLES3
#if BGFX_CONFIG_DEBUG_GREMEDY
static void GL_APIENTRY stubStringMarkerGREMEDY(GLsizei /*_len*/, const GLvoid* /*_string*/)
{
}
static void GL_APIENTRY stubFrameTerminatorGREMEDY()
{
}
#endif // BGFX_CONFIG_DEBUG_GREMEDY
typedef void (*PostSwapBuffersFn)(uint32_t _width, uint32_t _height); typedef void (*PostSwapBuffersFn)(uint32_t _width, uint32_t _height);
static void rgbaToBgra(uint8_t* _data, uint32_t _width, uint32_t _height) static void rgbaToBgra(uint8_t* _data, uint32_t _width, uint32_t _height)
@ -472,7 +484,7 @@ namespace bgfx
} }
} }
void saveScreenShot(Memory* _mem) void saveScreenShot(const char* _filePath)
{ {
uint32_t length = m_resolution.m_width*m_resolution.m_height*4; uint32_t length = m_resolution.m_width*m_resolution.m_height*4;
uint8_t* data = (uint8_t*)g_realloc(NULL, length); uint8_t* data = (uint8_t*)g_realloc(NULL, length);
@ -495,7 +507,7 @@ namespace bgfx
rgbaToBgra(data, width, height); rgbaToBgra(data, width, height);
} }
g_callback->screenShot( (const char*)_mem->data g_callback->screenShot(_filePath
, width , width
, height , height
, width*4 , width*4
@ -515,6 +527,15 @@ namespace bgfx
m_version = getGLString(GL_VERSION); m_version = getGLString(GL_VERSION);
m_glslVersion = getGLString(GL_SHADING_LANGUAGE_VERSION); m_glslVersion = getGLString(GL_SHADING_LANGUAGE_VERSION);
#if BGFX_CONFIG_DEBUG_GREMEDY
if (NULL == glStringMarkerGREMEDY
|| NULL == glFrameTerminatorGREMEDY)
{
glStringMarkerGREMEDY = stubStringMarkerGREMEDY;
glFrameTerminatorGREMEDY = stubFrameTerminatorGREMEDY;
}
#endif // BGFX_CONFIG_DEBUG_GREMEDY
#if BGFX_CONFIG_RENDERER_OPENGL #if BGFX_CONFIG_RENDERER_OPENGL
m_queries.create(); m_queries.create();
#endif // BGFX_CONFIG_RENDERER_OPENGL #endif // BGFX_CONFIG_RENDERER_OPENGL
@ -2559,9 +2580,14 @@ namespace bgfx
g_free(s_renderCtx.m_uniforms[_handle.idx]); g_free(s_renderCtx.m_uniforms[_handle.idx]);
} }
void Context::rendererSaveScreenShot(Memory* _mem) void Context::rendererSaveScreenShot(const char* _filePath)
{ {
s_renderCtx.saveScreenShot(_mem); s_renderCtx.saveScreenShot(_filePath);
}
void Context::rendererUpdateViewName(uint8_t _id, const char* _name)
{
bx::strlcpy(&s_viewName[_id][0], _name, sizeof(s_viewName[0][0]) );
} }
void Context::rendererUpdateUniform(uint16_t _loc, const void* _data, uint32_t _size) void Context::rendererUpdateUniform(uint16_t _loc, const void* _data, uint32_t _size)
@ -2657,7 +2683,7 @@ namespace bgfx
changedStencil = packStencil(BGFX_STENCIL_MASK, BGFX_STENCIL_MASK); changedStencil = packStencil(BGFX_STENCIL_MASK, BGFX_STENCIL_MASK);
currentState.m_flags = newFlags; currentState.m_flags = newFlags;
GREMEDY_SETMARKER("view"); GREMEDY_SETMARKER(s_viewName[key.m_view]);
view = key.m_view; view = key.m_view;
programIdx = invalidHandle; programIdx = invalidHandle;

View file

@ -253,22 +253,8 @@ namespace bgfx
#endif // BGFX_CONFIG_DEBUG #endif // BGFX_CONFIG_DEBUG
#if BGFX_CONFIG_DEBUG_GREMEDY #if BGFX_CONFIG_DEBUG_GREMEDY
# define _GREMEDY_SETMARKER(_string) \ # define _GREMEDY_SETMARKER(_string) glStringMarkerGREMEDY(0, _string)
do \ # define _GREMEDY_FRAMETERMINATOR() glFrameTerminatorGREMEDY()
{ \
if (NULL != glStringMarkerGREMEDY) \
{ \
glStringMarkerGREMEDY( (GLsizei)strlen(_string), _string); \
} \
} while(0)
# define _GREMEDY_FRAMETERMINATOR() \
do \
{ \
if (NULL != glStringMarkerGREMEDY) \
{ \
glFrameTerminatorGREMEDY(); \
} \
} while(0)
#else #else
# define _GREMEDY_SETMARKER(_string) do {} while(0) # define _GREMEDY_SETMARKER(_string) do {} while(0)
# define _GREMEDY_FRAMETERMINATOR() do {} while(0) # define _GREMEDY_FRAMETERMINATOR() do {} while(0)

View file

@ -156,7 +156,11 @@ namespace bgfx
{ {
} }
void Context::rendererSaveScreenShot(Memory* /*_mem*/) void Context::rendererSaveScreenShot(const char* /*_filePath*/)
{
}
void Context::rendererUpdateViewName(uint8_t /*_id*/, const char* /*_name*/)
{ {
} }