Added ability to set marker for profiling events.

This commit is contained in:
bkaradzic 2013-06-10 22:41:03 -07:00
parent a5c6c0bf5b
commit 1f4539ec7c
7 changed files with 83 additions and 56 deletions

View File

@ -777,6 +777,9 @@ namespace bgfx
/// Set view view and projection matrices for multiple views.
void setViewTransformMask(uint32_t _viewMask, const void* _view, const void* _proj, uint8_t _other = 0xff);
/// Sets debug marker.
void setMarker(const char* _marker);
/// Set render states for draw primitive.
///
/// @param _state State flags. Default state for primitive type is

View File

@ -670,7 +670,7 @@ namespace bgfx
return s_ctx.renderFrame();
}
const uint32_t g_uniformTypeSize[UniformType::Count] =
const uint32_t g_uniformTypeSize[UniformType::Count+1] =
{
sizeof(int32_t),
sizeof(float),
@ -682,6 +682,7 @@ namespace bgfx
4*sizeof(float),
3*3*sizeof(float),
4*4*sizeof(float),
1,
};
void ConstantBuffer::writeUniform(UniformType::Enum _type, uint16_t _loc, const void* _value, uint16_t _num)
@ -698,6 +699,14 @@ namespace bgfx
write(&_value, sizeof(void*) );
}
void ConstantBuffer::writeMarker(const char* _marker)
{
uint16_t num = (uint16_t)strlen(_marker)+1;
uint32_t opcode = encodeOpcode(bgfx::UniformType::Count, 0, num, true);
write(opcode);
write(_marker, num);
}
void Context::init(bool _createRenderThread)
{
BX_CHECK(!m_rendererInitialized, "Already initialized?");
@ -1344,6 +1353,12 @@ namespace bgfx
s_ctx.setViewTransformMask(_viewMask, _view, _proj, _other);
}
void setMarker(const char* _marker)
{
BGFX_CHECK_MAIN_THREAD();
s_ctx.m_submit->setMarker(_marker);
}
void setState(uint64_t _state, uint32_t _rgba)
{
BGFX_CHECK_MAIN_THREAD();
@ -1374,12 +1389,6 @@ namespace bgfx
s_ctx.setUniform(_handle, _value, _num);
}
void setUniform(ProgramHandle _program, UniformHandle _handle, const void* _value)
{
BGFX_CHECK_MAIN_THREAD();
s_ctx.setUniform(_program, _handle, _value);
}
void setIndexBuffer(IndexBufferHandle _handle, uint32_t _firstIndex, uint32_t _numIndices)
{
BGFX_CHECK_MAIN_THREAD();

View File

@ -191,7 +191,7 @@ namespace bgfx
const Memory* m_mem;
};
extern const uint32_t g_uniformTypeSize[UniformType::Count];
extern const uint32_t g_uniformTypeSize[UniformType::Count+1];
extern CallbackI* g_callback;
extern ReallocFn g_realloc;
extern FreeFn g_free;
@ -653,16 +653,14 @@ namespace bgfx
uint16_t m_num;
};
#define CONSTANT_OPCODE_MASK(_bits) ( (1<<_bits)-1)
#define CONSTANT_OPCODE_TYPE_BITS 5
#define CONSTANT_OPCODE_TYPE_MASK CONSTANT_OPCODE_MASK(CONSTANT_OPCODE_TYPE_BITS)
#define CONSTANT_OPCODE_LOC_BITS 16
#define CONSTANT_OPCODE_LOC_MASK CONSTANT_OPCODE_MASK(CONSTANT_OPCODE_LOC_BITS)
#define CONSTANT_OPCODE_NUM_BITS 10
#define CONSTANT_OPCODE_NUM_MASK CONSTANT_OPCODE_MASK(CONSTANT_OPCODE_NUM_BITS)
#define CONSTANT_OPCODE_COPY_BITS 1
#define CONSTANT_OPCODE_COPY_MASK CONSTANT_OPCODE_MASK(CONSTANT_OPCODE_COPY_BITS)
#define CONSTANT_OPCODE_TYPE_SHIFT 27
#define CONSTANT_OPCODE_TYPE_MASK UINT32_C(0xf8000000)
#define CONSTANT_OPCODE_LOC_SHIFT 11
#define CONSTANT_OPCODE_LOC_MASK UINT32_C(0x07fff800)
#define CONSTANT_OPCODE_NUM_SHIFT 1
#define CONSTANT_OPCODE_NUM_MASK UINT32_C(0x000007fe)
#define CONSTANT_OPCODE_COPY_SHIFT 0
#define CONSTANT_OPCODE_COPY_MASK UINT32_C(0x00000001)
#define BGFX_UNIFORM_FRAGMENTBIT UINT8_C(0x10)
@ -684,41 +682,21 @@ namespace bgfx
static uint32_t encodeOpcode(UniformType::Enum _type, uint16_t _loc, uint16_t _num, uint16_t _copy)
{
uint32_t opcode = 0;
opcode <<= CONSTANT_OPCODE_TYPE_BITS;
opcode |= _type&CONSTANT_OPCODE_TYPE_MASK;
opcode <<= CONSTANT_OPCODE_LOC_BITS;
opcode |= _loc&CONSTANT_OPCODE_LOC_MASK;
opcode <<= CONSTANT_OPCODE_NUM_BITS;
opcode |= _num&CONSTANT_OPCODE_NUM_MASK;
opcode <<= CONSTANT_OPCODE_COPY_BITS;
opcode |= _copy&CONSTANT_OPCODE_COPY_MASK;
return opcode;
const uint32_t type = _type << CONSTANT_OPCODE_TYPE_SHIFT;
const uint32_t loc = _loc << CONSTANT_OPCODE_LOC_SHIFT;
const uint32_t num = _num << CONSTANT_OPCODE_NUM_SHIFT;
const uint32_t copy = _copy << CONSTANT_OPCODE_COPY_SHIFT;
return type|loc|num|copy;
}
static void decodeOpcode(uint32_t _opcode, UniformType::Enum& _type, uint16_t& _loc, uint16_t& _num, uint16_t& _copy)
{
uint32_t copy;
uint32_t num;
uint32_t loc;
copy = _opcode&CONSTANT_OPCODE_COPY_MASK;
_opcode >>= CONSTANT_OPCODE_COPY_BITS;
num = _opcode&CONSTANT_OPCODE_NUM_MASK;
_opcode >>= CONSTANT_OPCODE_NUM_BITS;
loc = _opcode&CONSTANT_OPCODE_LOC_MASK;
_opcode >>= CONSTANT_OPCODE_LOC_BITS;
_type = (UniformType::Enum)(_opcode&CONSTANT_OPCODE_TYPE_MASK);
_opcode >>= CONSTANT_OPCODE_TYPE_BITS;
const uint32_t type = (_opcode&CONSTANT_OPCODE_TYPE_MASK) >> CONSTANT_OPCODE_TYPE_SHIFT;
const uint32_t loc = (_opcode&CONSTANT_OPCODE_LOC_MASK) >> CONSTANT_OPCODE_LOC_SHIFT;
const uint32_t num = (_opcode&CONSTANT_OPCODE_NUM_MASK) >> CONSTANT_OPCODE_NUM_SHIFT;
const uint32_t copy = (_opcode&CONSTANT_OPCODE_COPY_MASK) >> CONSTANT_OPCODE_COPY_SHIFT;
_type = (UniformType::Enum)(type);
_copy = (uint16_t)copy;
_num = (uint16_t)num;
_loc = (uint16_t)loc;
@ -777,6 +755,7 @@ namespace bgfx
void writeUniform(UniformType::Enum _type, uint16_t _loc, const void* _value, uint16_t _num = 1);
void writeUniformRef(UniformType::Enum _type, uint16_t _loc, const void* _value, uint16_t _num = 1);
void writeMarker(const char* _marker);
void commit();
private:
@ -996,6 +975,11 @@ namespace bgfx
}
}
void setMarker(const char* _name)
{
m_constantBuffer->writeMarker(_name);
}
void setState(uint64_t _state, uint32_t _rgba)
{
uint8_t blend = ( (_state&BGFX_STATE_BLEND_MASK)>>BGFX_STATE_BLEND_SHIFT)&0xff;
@ -2194,11 +2178,6 @@ namespace bgfx
m_submit->writeConstant(uniform.m_type, _handle, _value, uint16_min(uniform.m_num, _num) );
}
void setUniform(ProgramHandle /*_program*/, UniformHandle /*_handle*/, const void* /*_value*/)
{
BX_CHECK(false, "NOT IMPLEMENTED!");
}
void setViewName(uint8_t _id, const char* _name)
{
CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::UpdateViewName);
@ -2478,6 +2457,7 @@ namespace bgfx
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 rendererSetMarker(const char* _marker, uint32_t _size);
void rendererUpdateUniforms(ConstantBuffer* _constantBuffer, uint32_t _begin, uint32_t _end)
{
@ -2497,10 +2477,16 @@ namespace bgfx
uint16_t copy;
ConstantBuffer::decodeOpcode(opcode, type, loc, num, copy);
const char* data;
uint32_t size = g_uniformTypeSize[type]*num;
data = _constantBuffer->read(size);
rendererUpdateUniform(loc, data, size);
const char* data = _constantBuffer->read(size);
if (UniformType::Count > type)
{
rendererUpdateUniform(loc, data, size);
}
else
{
rendererSetMarker(data, size);
}
}
}

View File

@ -2251,6 +2251,16 @@ namespace bgfx
memcpy(s_renderCtx.m_uniforms[_loc].m_data, _data, _size);
}
void Context::rendererSetMarker(const char* _marker, uint32_t _size)
{
#if BGFX_CONFIG_DEBUG_PIX
uint32_t size = _size*sizeof(wchar_t);
wchar_t* name = (wchar_t*)alloca(size);
mbstowcs(name, _marker, size-2);
PIX_SETMARKER(D3DCOLOR_RGBA(0xff, 0xff, 0xff, 0xff), name);
#endif // BGFX_CONFIG_DEBUG_PIX
}
void Context::rendererSubmit()
{
PIX_BEGINEVENT(D3DCOLOR_RGBA(0xff, 0x00, 0x00, 0xff), L"rendererSubmit");

View File

@ -2149,6 +2149,16 @@ namespace bgfx
memcpy(s_renderCtx.m_uniforms[_loc], _data, _size);
}
void Context::rendererSetMarker(const char* _marker, uint32_t _size)
{
#if BGFX_CONFIG_DEBUG_PIX
uint32_t size = _size*sizeof(wchar_t);
wchar_t* name = (wchar_t*)alloca(size);
mbstowcs(name, _marker, size-2);
PIX_SETMARKER(D3DCOLOR_RGBA(0xff, 0xff, 0xff, 0xff), name);
#endif // BGFX_CONFIG_DEBUG_PIX
}
void Context::rendererSubmit()
{
IDirect3DDevice9* device = s_renderCtx.m_device;

View File

@ -2595,6 +2595,11 @@ namespace bgfx
memcpy(s_renderCtx.m_uniforms[_loc], _data, _size);
}
void Context::rendererSetMarker(const char* _marker, uint32_t /*_size*/)
{
GREMEDY_SETMARKER(_marker);
}
void Context::rendererSubmit()
{
const GLuint defaultVao = s_renderCtx.m_vaoSupport;

View File

@ -168,6 +168,10 @@ namespace bgfx
{
}
void Context::rendererSetMarker(const char* /*_marker*/, uint32_t /*_size*/)
{
}
void Context::rendererSubmit()
{
}