Added bgfx::setName to set resource debug name.

This commit is contained in:
Branimir Karadžić 2017-08-30 21:46:57 -07:00
parent 15891b39ad
commit 3aec2b89bf
12 changed files with 159 additions and 2 deletions

View File

@ -123,7 +123,10 @@ static bgfx::ShaderHandle loadShader(bx::FileReaderI* _reader, const char* _name
bx::strCat(filePath, BX_COUNTOF(filePath), _name);
bx::strCat(filePath, BX_COUNTOF(filePath), ".bin");
return bgfx::createShader(loadMem(_reader, filePath) );
bgfx::ShaderHandle handle = bgfx::createShader(loadMem(_reader, filePath) );
bgfx::setName(handle, filePath);
return handle;
}
bgfx::ShaderHandle loadShader(const char* _name)
@ -217,6 +220,8 @@ bgfx::TextureHandle loadTexture(bx::FileReaderI* _reader, const char* _filePath,
);
}
bgfx::setName(handle, _filePath);
if (NULL != _info)
{
bgfx::calcTextureSize(

View File

@ -1552,6 +1552,15 @@ namespace bgfx
, uint16_t _max = 0
);
/// Set shader debug name.
///
/// @param[in] _handle Shader handle.
/// @param[in] _name Shader name.
///
/// @attention C99 equivalent is `bgfx_set_shader_name`.
///
void setName(ShaderHandle _handle, const char* _name);
/// Destroy shader. Once program is created with shader it is safe to
/// destroy shader.
///
@ -1896,6 +1905,15 @@ namespace bgfx
///
uint32_t readTexture(TextureHandle _handle, void* _data, uint8_t _mip = 0);
/// Set texture debug name.
///
/// @param[in] _handle Texture handle.
/// @param[in] _name Texture name.
///
/// @attention C99 equivalent is `bgfx_set_texture_name`.
///
void setName(TextureHandle _handle, const char* _name);
/// Destroy texture.
///
/// @param[in] _handle Texture handle.

View File

@ -2535,6 +2535,20 @@ namespace bgfx
}
break;
case CommandBuffer::SetName:
{
Handle handle;
_cmdbuf.read(handle);
uint16_t len;
_cmdbuf.read(len);
const char* name = (const char*)_cmdbuf.skip(len);
m_renderCtx->setName(handle, name);
}
break;
default:
BX_CHECK(false, "Invalid command: %d", command);
break;
@ -3044,6 +3058,12 @@ error:
return s_ctx->getShaderUniforms(_handle, _uniforms, _max);
}
void setName(ShaderHandle _handle, const char* _name)
{
BGFX_CHECK_MAIN_THREAD();
s_ctx->setName(_handle, _name);
}
void destroy(ShaderHandle _handle)
{
BGFX_CHECK_MAIN_THREAD();
@ -3373,6 +3393,12 @@ error:
return s_ctx->createTexture(mem, _flags, 0, NULL, BackbufferRatio::Count);
}
void setName(TextureHandle _handle, const char* _name)
{
BGFX_CHECK_MAIN_THREAD();
s_ctx->setName(_handle, _name);
}
void destroy(TextureHandle _handle)
{
BGFX_CHECK_MAIN_THREAD();

View File

@ -239,6 +239,32 @@ namespace bgfx
typedef uint32_t RenderItemCount;
#endif // BGFX_CONFIG_MAX_DRAW_CALLS < (64<<10)
struct Handle
{
enum Enum
{
Shader,
Texture,
Count
};
uint16_t type;
uint16_t idx;
};
inline Handle convert(ShaderHandle _handle)
{
Handle handle = { Handle::Shader, _handle.idx };
return handle;
}
inline Handle convert(TextureHandle _handle)
{
Handle handle = { Handle::Texture, _handle.idx };
return handle;
}
struct Clear
{
uint8_t m_index[8];
@ -612,6 +638,7 @@ namespace bgfx
CreateUniform,
UpdateViewName,
InvalidateOcclusionQuery,
SetName,
End,
RendererShutdownEnd,
DestroyVertexDecl,
@ -2257,6 +2284,7 @@ namespace bgfx
virtual void updateUniform(uint16_t _loc, const void* _data, uint32_t _size) = 0;
virtual void setMarker(const char* _marker, uint32_t _size) = 0;
virtual void invalidateOcclusionQuery(OcclusionQueryHandle _handle) = 0;
virtual void setName(Handle _handle, const char* _name) = 0;
virtual void submit(Frame* _render, ClearQuad& _clearQuad, TextVideoMemBlitter& _textVideoMemBlitter) = 0;
virtual void blitSetup(TextVideoMemBlitter& _blitter) = 0;
virtual void blitRender(TextVideoMemBlitter& _blitter, uint32_t _numIndices) = 0;
@ -3134,6 +3162,25 @@ namespace bgfx
return sr.m_num;
}
void setName(Handle _handle, const char* _name)
{
CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::SetName);
cmdbuf.write(_handle);
uint16_t len = (uint8_t)bx::strLen(_name)+1;
cmdbuf.write(len);
cmdbuf.write(_name, len);
}
BGFX_API_FUNC(void setName(ShaderHandle _handle, const char* _name) )
{
BGFX_CHECK_HANDLE("setName", m_shaderHandle, _handle);
ShaderRef& sr = m_shaderRef[_handle.idx];
sr.m_name.set(_name);
setName(convert(_handle), _name);
}
BGFX_API_FUNC(void destroyShader(ShaderHandle _handle) )
{
BGFX_CHECK_HANDLE("destroyShader", m_shaderHandle, _handle);
@ -3381,6 +3428,16 @@ namespace bgfx
return handle;
}
BGFX_API_FUNC(void setName(TextureHandle _handle, const char* _name) )
{
BGFX_CHECK_HANDLE("setName", m_textureHandle, _handle);
TextureRef& ref = m_textureRef[_handle.idx];
ref.m_name.set(_name);
setName(convert(_handle), _name);
}
BGFX_API_FUNC(void destroyTexture(TextureHandle _handle) )
{
BGFX_CHECK_HANDLE("destroyTexture", m_textureHandle, _handle);
@ -3452,6 +3509,8 @@ namespace bgfx
int32_t refs = --ref.m_refCount;
if (0 == refs)
{
ref.m_name.clear();
bool ok = m_submit->free(_handle); BX_UNUSED(ok);
BX_CHECK(ok, "Texture handle %d is already destroyed!", _handle.idx);
@ -4315,6 +4374,7 @@ namespace bgfx
struct ShaderRef
{
UniformHandle* m_uniforms;
String m_name;
uint32_t m_hash;
int16_t m_refCount;
uint16_t m_num;
@ -4337,6 +4397,7 @@ namespace bgfx
struct TextureRef
{
String m_name;
int16_t m_refCount;
uint8_t m_bbRatio;
uint8_t m_format;

View File

@ -2133,6 +2133,24 @@ BX_PRAGMA_DIAGNOSTIC_POP();
m_occlusionQuery.invalidate(_handle);
}
virtual void setName(Handle _handle, const char* _name) override
{
switch (_handle.type)
{
case Handle::Shader:
setDebugObjectName(m_shaders[_handle.idx].m_ptr, _name);
break;
case Handle::Texture:
setDebugObjectName(m_textures[_handle.idx].m_ptr, _name);
break;
default:
BX_CHECK(false, "Invalid handle type?! %d", _handle.type);
break;
}
}
void submitBlit(BlitState& _bs, uint16_t _view);
void submit(Frame* _render, ClearQuad& _clearQuad, TextVideoMemBlitter& _textVideoMemBlitter) override;

View File

@ -154,7 +154,7 @@ namespace bgfx { namespace d3d11
ID3D11ComputeShader* m_computeShader;
ID3D11PixelShader* m_pixelShader;
ID3D11VertexShader* m_vertexShader;
IUnknown* m_ptr;
ID3D11DeviceChild* m_ptr;
};
const Memory* m_code;
ID3D11Buffer* m_buffer;

View File

@ -1683,6 +1683,11 @@ namespace bgfx { namespace d3d12
m_occlusionQuery.invalidate(_handle);
}
virtual void setName(Handle _handle, const char* _name) override
{
BX_UNUSED(_handle, _name)
}
void submitBlit(BlitState& _bs, uint16_t _view);
void submit(Frame* _render, ClearQuad& _clearQuad, TextVideoMemBlitter& _textVideoMemBlitter) override;

View File

@ -1292,6 +1292,11 @@ namespace bgfx { namespace d3d9
m_occlusionQuery.invalidate(_handle);
}
virtual void setName(Handle _handle, const char* _name) override
{
BX_UNUSED(_handle, _name)
}
void submitBlit(BlitState& _bs, uint16_t _view);
void submit(Frame* _render, ClearQuad& _clearQuad, TextVideoMemBlitter& _textVideoMemBlitter) override;

View File

@ -2982,6 +2982,11 @@ namespace bgfx { namespace gl
m_occlusionQuery.invalidate(_handle);
}
virtual void setName(Handle _handle, const char* _name) override
{
BX_UNUSED(_handle, _name)
}
void submitBlit(BlitState& _bs, uint16_t _view);
void submit(Frame* _render, ClearQuad& _clearQuad, TextVideoMemBlitter& _textVideoMemBlitter) override;

View File

@ -989,6 +989,11 @@ namespace bgfx { namespace mtl
m_occlusionQuery.invalidate(_handle);
}
virtual void setName(Handle _handle, const char* _name) override
{
BX_UNUSED(_handle, _name)
}
void submitBlit(BlitState& _bs, uint16_t _view);
void submit(Frame* _render, ClearQuad& _clearQuad, TextVideoMemBlitter& _textVideoMemBlitter) override;

View File

@ -204,6 +204,10 @@ namespace bgfx { namespace noop
{
}
virtual void setName(Handle /*_handle*/, const char* /*_name*/) override
{
}
void submit(Frame* /*_render*/, ClearQuad& /*_clearQuad*/, TextVideoMemBlitter& /*_textVideoMemBlitter*/) override
{
}

View File

@ -2122,6 +2122,11 @@ VK_IMPORT_DEVICE
BX_UNUSED(_handle);
}
virtual void setName(Handle _handle, const char* _name) override
{
BX_UNUSED(_handle, _name)
}
void submitBlit(BlitState& _bs, uint16_t _view);
void submit(Frame* _render, ClearQuad& _clearQuad, TextVideoMemBlitter& _textVideoMemBlitter) override;