mirror of https://github.com/bkaradzic/bgfx
Added internal debug names for index/vertex buffers, shaders, and textures.
This commit is contained in:
parent
207be77452
commit
a0c2907c22
|
@ -124,7 +124,7 @@ static bgfx::ShaderHandle loadShader(bx::FileReaderI* _reader, const char* _name
|
||||||
bx::strCat(filePath, BX_COUNTOF(filePath), ".bin");
|
bx::strCat(filePath, BX_COUNTOF(filePath), ".bin");
|
||||||
|
|
||||||
bgfx::ShaderHandle handle = bgfx::createShader(loadMem(_reader, filePath) );
|
bgfx::ShaderHandle handle = bgfx::createShader(loadMem(_reader, filePath) );
|
||||||
bgfx::setName(handle, filePath);
|
bgfx::setName(handle, _name);
|
||||||
|
|
||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
|
|
15
src/bgfx.cpp
15
src/bgfx.cpp
|
@ -297,6 +297,21 @@ namespace bgfx
|
||||||
PlatformData g_platformData;
|
PlatformData g_platformData;
|
||||||
bool g_platformDataChangedSinceReset = false;
|
bool g_platformDataChangedSinceReset = false;
|
||||||
|
|
||||||
|
const char* getTypeName(Handle _handle)
|
||||||
|
{
|
||||||
|
switch (_handle.type)
|
||||||
|
{
|
||||||
|
case Handle::IndexBuffer: return "IB";
|
||||||
|
case Handle::Shader: return "S";
|
||||||
|
case Handle::Texture: return "T";
|
||||||
|
case Handle::VertexBuffer: return "VB";
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
|
||||||
|
BX_CHECK(false, "You should not be here.");
|
||||||
|
return "?";
|
||||||
|
}
|
||||||
|
|
||||||
void AllocatorStub::checkLeaks()
|
void AllocatorStub::checkLeaks()
|
||||||
{
|
{
|
||||||
#if BGFX_CONFIG_MEMORY_TRACKING
|
#if BGFX_CONFIG_MEMORY_TRACKING
|
||||||
|
|
59
src/bgfx_p.h
59
src/bgfx_p.h
|
@ -282,8 +282,10 @@ namespace bgfx
|
||||||
{
|
{
|
||||||
enum Enum
|
enum Enum
|
||||||
{
|
{
|
||||||
|
IndexBuffer,
|
||||||
Shader,
|
Shader,
|
||||||
Texture,
|
Texture,
|
||||||
|
VertexBuffer,
|
||||||
|
|
||||||
Count
|
Count
|
||||||
};
|
};
|
||||||
|
@ -292,17 +294,21 @@ namespace bgfx
|
||||||
uint16_t idx;
|
uint16_t idx;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline Handle convert(ShaderHandle _handle)
|
#define CONVERT_HANDLE(_name) \
|
||||||
{
|
inline Handle convert(_name##Handle _handle) \
|
||||||
Handle handle = { Handle::Shader, _handle.idx };
|
{ \
|
||||||
return handle;
|
Handle handle = { Handle::_name, _handle.idx }; \
|
||||||
|
return handle; \
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Handle convert(TextureHandle _handle)
|
CONVERT_HANDLE(IndexBuffer);
|
||||||
{
|
CONVERT_HANDLE(Shader);
|
||||||
Handle handle = { Handle::Texture, _handle.idx };
|
CONVERT_HANDLE(Texture);
|
||||||
return handle;
|
CONVERT_HANDLE(VertexBuffer);
|
||||||
}
|
|
||||||
|
#undef CONVERT_HANDLE
|
||||||
|
|
||||||
|
const char* getTypeName(Handle _handle);
|
||||||
|
|
||||||
inline bool isValid(const VertexDecl& _decl)
|
inline bool isValid(const VertexDecl& _decl)
|
||||||
{
|
{
|
||||||
|
@ -2948,6 +2954,8 @@ namespace bgfx
|
||||||
cmdbuf.write(handle);
|
cmdbuf.write(handle);
|
||||||
cmdbuf.write(_mem);
|
cmdbuf.write(_mem);
|
||||||
cmdbuf.write(_flags);
|
cmdbuf.write(_flags);
|
||||||
|
|
||||||
|
setDebugName(convert(handle) );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -2966,7 +2974,7 @@ namespace bgfx
|
||||||
IndexBuffer& ref = m_indexBuffers[_handle.idx];
|
IndexBuffer& ref = m_indexBuffers[_handle.idx];
|
||||||
ref.m_name.set(_name);
|
ref.m_name.set(_name);
|
||||||
|
|
||||||
// setName(convert(_handle), _name);
|
setName(convert(_handle), _name);
|
||||||
}
|
}
|
||||||
|
|
||||||
BGFX_API_FUNC(void destroyIndexBuffer(IndexBufferHandle _handle) )
|
BGFX_API_FUNC(void destroyIndexBuffer(IndexBufferHandle _handle) )
|
||||||
|
@ -3032,6 +3040,8 @@ namespace bgfx
|
||||||
cmdbuf.write(declHandle);
|
cmdbuf.write(declHandle);
|
||||||
cmdbuf.write(_flags);
|
cmdbuf.write(_flags);
|
||||||
|
|
||||||
|
setDebugName(convert(handle) );
|
||||||
|
|
||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3050,7 +3060,7 @@ namespace bgfx
|
||||||
VertexBuffer& ref = m_vertexBuffers[_handle.idx];
|
VertexBuffer& ref = m_vertexBuffers[_handle.idx];
|
||||||
ref.m_name.set(_name);
|
ref.m_name.set(_name);
|
||||||
|
|
||||||
// setName(convert(_handle), _name);
|
setName(convert(_handle), _name);
|
||||||
}
|
}
|
||||||
|
|
||||||
BGFX_API_FUNC(void destroyVertexBuffer(VertexBufferHandle _handle) )
|
BGFX_API_FUNC(void destroyVertexBuffer(VertexBufferHandle _handle) )
|
||||||
|
@ -3142,6 +3152,8 @@ namespace bgfx
|
||||||
cmdbuf.write(size);
|
cmdbuf.write(size);
|
||||||
cmdbuf.write(_flags);
|
cmdbuf.write(_flags);
|
||||||
|
|
||||||
|
setDebugName(convert(indexBufferHandle), "Dynamic Index Buffer");
|
||||||
|
|
||||||
ptr = uint64_t(indexBufferHandle.idx) << 32;
|
ptr = uint64_t(indexBufferHandle.idx) << 32;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -3325,6 +3337,8 @@ namespace bgfx
|
||||||
cmdbuf.write(size);
|
cmdbuf.write(size);
|
||||||
cmdbuf.write(_flags);
|
cmdbuf.write(_flags);
|
||||||
|
|
||||||
|
setDebugName(convert(vertexBufferHandle), "Dynamic Vertex Buffer");
|
||||||
|
|
||||||
ptr = uint64_t(vertexBufferHandle.idx)<<32;
|
ptr = uint64_t(vertexBufferHandle.idx)<<32;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -3485,6 +3499,8 @@ namespace bgfx
|
||||||
tib->data = (uint8_t *)tib + BX_ALIGN_16(sizeof(TransientIndexBuffer) );
|
tib->data = (uint8_t *)tib + BX_ALIGN_16(sizeof(TransientIndexBuffer) );
|
||||||
tib->size = _size;
|
tib->size = _size;
|
||||||
tib->handle = handle;
|
tib->handle = handle;
|
||||||
|
|
||||||
|
setDebugName(convert(handle), "Transient Index Buffer");
|
||||||
}
|
}
|
||||||
|
|
||||||
return tib;
|
return tib;
|
||||||
|
@ -3547,6 +3563,8 @@ namespace bgfx
|
||||||
tvb->stride = stride;
|
tvb->stride = stride;
|
||||||
tvb->handle = handle;
|
tvb->handle = handle;
|
||||||
tvb->decl = declHandle;
|
tvb->decl = declHandle;
|
||||||
|
|
||||||
|
setDebugName(convert(handle), "Transient Vertex Buffer");
|
||||||
}
|
}
|
||||||
|
|
||||||
return tvb;
|
return tvb;
|
||||||
|
@ -3778,6 +3796,8 @@ namespace bgfx
|
||||||
cmdbuf.write(handle);
|
cmdbuf.write(handle);
|
||||||
cmdbuf.write(_mem);
|
cmdbuf.write(_mem);
|
||||||
|
|
||||||
|
setDebugName(convert(handle) );
|
||||||
|
|
||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3802,12 +3822,21 @@ namespace bgfx
|
||||||
|
|
||||||
void setName(Handle _handle, const bx::StringView& _name)
|
void setName(Handle _handle, const bx::StringView& _name)
|
||||||
{
|
{
|
||||||
|
char tmp[1024];
|
||||||
|
uint16_t len = 1+(uint16_t)bx::snprintf(tmp, BX_COUNTOF(tmp), "%sH %d: %.*s", getTypeName(_handle), _handle.idx, _name.getLength(), _name.getPtr() );
|
||||||
|
|
||||||
CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::SetName);
|
CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::SetName);
|
||||||
cmdbuf.write(_handle);
|
cmdbuf.write(_handle);
|
||||||
uint16_t len = uint16_t(_name.getLength()+1);
|
|
||||||
cmdbuf.write(len);
|
cmdbuf.write(len);
|
||||||
cmdbuf.write(_name.getPtr(), len-1);
|
cmdbuf.write(tmp, len);
|
||||||
cmdbuf.write('\0');
|
}
|
||||||
|
|
||||||
|
void setDebugName(Handle _handle, const bx::StringView& _name = "")
|
||||||
|
{
|
||||||
|
if (BX_ENABLED(BGFX_CONFIG_DEBUG) )
|
||||||
|
{
|
||||||
|
setName(_handle, _name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BGFX_API_FUNC(void setName(ShaderHandle _handle, const bx::StringView& _name) )
|
BGFX_API_FUNC(void setName(ShaderHandle _handle, const bx::StringView& _name) )
|
||||||
|
@ -4088,6 +4117,8 @@ namespace bgfx
|
||||||
cmdbuf.write(_flags);
|
cmdbuf.write(_flags);
|
||||||
cmdbuf.write(_skip);
|
cmdbuf.write(_skip);
|
||||||
|
|
||||||
|
setDebugName(convert(handle) );
|
||||||
|
|
||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2001,6 +2001,10 @@ namespace bgfx { namespace d3d11
|
||||||
{
|
{
|
||||||
switch (_handle.type)
|
switch (_handle.type)
|
||||||
{
|
{
|
||||||
|
case Handle::IndexBuffer:
|
||||||
|
setDebugObjectName(m_indexBuffers[_handle.idx].m_ptr, "%s", _name);
|
||||||
|
break;
|
||||||
|
|
||||||
case Handle::Shader:
|
case Handle::Shader:
|
||||||
setDebugObjectName(m_shaders[_handle.idx].m_ptr, "%s", _name);
|
setDebugObjectName(m_shaders[_handle.idx].m_ptr, "%s", _name);
|
||||||
break;
|
break;
|
||||||
|
@ -2009,6 +2013,10 @@ namespace bgfx { namespace d3d11
|
||||||
setDebugObjectName(m_textures[_handle.idx].m_ptr, "%s", _name);
|
setDebugObjectName(m_textures[_handle.idx].m_ptr, "%s", _name);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case Handle::VertexBuffer:
|
||||||
|
setDebugObjectName(m_vertexBuffers[_handle.idx].m_ptr, "%s", _name);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
BX_CHECK(false, "Invalid handle type?! %d", _handle.type);
|
BX_CHECK(false, "Invalid handle type?! %d", _handle.type);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -1876,6 +1876,10 @@ namespace bgfx { namespace d3d12
|
||||||
{
|
{
|
||||||
switch (_handle.type)
|
switch (_handle.type)
|
||||||
{
|
{
|
||||||
|
case Handle::IndexBuffer:
|
||||||
|
setDebugObjectName(m_indexBuffers[_handle.idx].m_ptr, "%s", _name);
|
||||||
|
break;
|
||||||
|
|
||||||
case Handle::Shader:
|
case Handle::Shader:
|
||||||
// setDebugObjectName(m_shaders[_handle.idx].m_ptr, "%s", _name);
|
// setDebugObjectName(m_shaders[_handle.idx].m_ptr, "%s", _name);
|
||||||
break;
|
break;
|
||||||
|
@ -1884,6 +1888,10 @@ namespace bgfx { namespace d3d12
|
||||||
setDebugObjectName(m_textures[_handle.idx].m_ptr, "%s", _name);
|
setDebugObjectName(m_textures[_handle.idx].m_ptr, "%s", _name);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case Handle::VertexBuffer:
|
||||||
|
setDebugObjectName(m_vertexBuffers[_handle.idx].m_ptr, "%s", _name);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
BX_CHECK(false, "Invalid handle type?! %d", _handle.type);
|
BX_CHECK(false, "Invalid handle type?! %d", _handle.type);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -2985,6 +2985,10 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
|
||||||
{
|
{
|
||||||
switch (_handle.type)
|
switch (_handle.type)
|
||||||
{
|
{
|
||||||
|
case Handle::IndexBuffer:
|
||||||
|
GL_CHECK(glObjectLabel(GL_BUFFER, m_indexBuffers[_handle.idx].m_id, -1, _name) );
|
||||||
|
break;
|
||||||
|
|
||||||
case Handle::Shader:
|
case Handle::Shader:
|
||||||
GL_CHECK(glObjectLabel(GL_SHADER, m_shaders[_handle.idx].m_id, -1, _name) );
|
GL_CHECK(glObjectLabel(GL_SHADER, m_shaders[_handle.idx].m_id, -1, _name) );
|
||||||
break;
|
break;
|
||||||
|
@ -2993,6 +2997,10 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
|
||||||
GL_CHECK(glObjectLabel(GL_TEXTURE, m_textures[_handle.idx].m_id, -1, _name) );
|
GL_CHECK(glObjectLabel(GL_TEXTURE, m_textures[_handle.idx].m_id, -1, _name) );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case Handle::VertexBuffer:
|
||||||
|
GL_CHECK(glObjectLabel(GL_BUFFER, m_vertexBuffers[_handle.idx].m_id, -1, _name) );
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
BX_CHECK(false, "Invalid handle type?! %d", _handle.type);
|
BX_CHECK(false, "Invalid handle type?! %d", _handle.type);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -1019,6 +1019,10 @@ namespace bgfx { namespace mtl
|
||||||
{
|
{
|
||||||
switch (_handle.type)
|
switch (_handle.type)
|
||||||
{
|
{
|
||||||
|
case Handle::IndexBuffer:
|
||||||
|
// m_indexBuffers[_handle.idx].m_ptr.setLabel(_name);
|
||||||
|
break;
|
||||||
|
|
||||||
case Handle::Shader:
|
case Handle::Shader:
|
||||||
m_shaders[_handle.idx].m_function.setLabel(_name);
|
m_shaders[_handle.idx].m_function.setLabel(_name);
|
||||||
break;
|
break;
|
||||||
|
@ -1027,6 +1031,10 @@ namespace bgfx { namespace mtl
|
||||||
m_textures[_handle.idx].m_ptr.setLabel(_name);
|
m_textures[_handle.idx].m_ptr.setLabel(_name);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case Handle::VertexBuffer:
|
||||||
|
// m_vertexBuffers[_handle.idx].m_ptr.setLabel(_name);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
BX_CHECK(false, "Invalid handle type?! %d", _handle.type);
|
BX_CHECK(false, "Invalid handle type?! %d", _handle.type);
|
||||||
break;
|
break;
|
||||||
|
@ -2135,7 +2143,7 @@ namespace bgfx { namespace mtl
|
||||||
ComputePipelineReflection reflection = NULL;
|
ComputePipelineReflection reflection = NULL;
|
||||||
pso->m_cps = m_device.newComputePipelineStateWithFunction(program.m_vsh->m_function, MTLPipelineOptionBufferTypeInfo, &reflection);
|
pso->m_cps = m_device.newComputePipelineStateWithFunction(program.m_vsh->m_function, MTLPipelineOptionBufferTypeInfo, &reflection);
|
||||||
processArguments(pso, reflection.arguments, NULL);
|
processArguments(pso, reflection.arguments, NULL);
|
||||||
|
|
||||||
for (uint32_t ii = 0; ii < 3; ++ii)
|
for (uint32_t ii = 0; ii < 3; ++ii)
|
||||||
{
|
{
|
||||||
pso->m_numThreads[ii] = program.m_vsh->m_numThreads[ii];
|
pso->m_numThreads[ii] = program.m_vsh->m_numThreads[ii];
|
||||||
|
@ -2378,7 +2386,7 @@ namespace bgfx { namespace mtl
|
||||||
bx::read(&reader, m_numThreads[ii]);
|
bx::read(&reader, m_numThreads[ii]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t shaderSize;
|
uint32_t shaderSize;
|
||||||
bx::read(&reader, shaderSize);
|
bx::read(&reader, shaderSize);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue