diff --git a/examples/common/bgfx_utils.cpp b/examples/common/bgfx_utils.cpp index f249b82d1..e9883557a 100644 --- a/examples/common/bgfx_utils.cpp +++ b/examples/common/bgfx_utils.cpp @@ -124,7 +124,7 @@ static bgfx::ShaderHandle loadShader(bx::FileReaderI* _reader, const char* _name bx::strCat(filePath, BX_COUNTOF(filePath), ".bin"); bgfx::ShaderHandle handle = bgfx::createShader(loadMem(_reader, filePath) ); - bgfx::setName(handle, filePath); + bgfx::setName(handle, _name); return handle; } diff --git a/src/bgfx.cpp b/src/bgfx.cpp index 9d5853ec4..d36c18806 100644 --- a/src/bgfx.cpp +++ b/src/bgfx.cpp @@ -297,6 +297,21 @@ namespace bgfx PlatformData g_platformData; 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() { #if BGFX_CONFIG_MEMORY_TRACKING diff --git a/src/bgfx_p.h b/src/bgfx_p.h index c3c627222..6184fbf88 100644 --- a/src/bgfx_p.h +++ b/src/bgfx_p.h @@ -282,8 +282,10 @@ namespace bgfx { enum Enum { + IndexBuffer, Shader, Texture, + VertexBuffer, Count }; @@ -292,17 +294,21 @@ namespace bgfx uint16_t idx; }; - inline Handle convert(ShaderHandle _handle) - { - Handle handle = { Handle::Shader, _handle.idx }; - return handle; +#define CONVERT_HANDLE(_name) \ + inline Handle convert(_name##Handle _handle) \ + { \ + Handle handle = { Handle::_name, _handle.idx }; \ + return handle; \ } - inline Handle convert(TextureHandle _handle) - { - Handle handle = { Handle::Texture, _handle.idx }; - return handle; - } + CONVERT_HANDLE(IndexBuffer); + CONVERT_HANDLE(Shader); + CONVERT_HANDLE(Texture); + CONVERT_HANDLE(VertexBuffer); + +#undef CONVERT_HANDLE + + const char* getTypeName(Handle _handle); inline bool isValid(const VertexDecl& _decl) { @@ -2948,6 +2954,8 @@ namespace bgfx cmdbuf.write(handle); cmdbuf.write(_mem); cmdbuf.write(_flags); + + setDebugName(convert(handle) ); } else { @@ -2966,7 +2974,7 @@ namespace bgfx IndexBuffer& ref = m_indexBuffers[_handle.idx]; ref.m_name.set(_name); -// setName(convert(_handle), _name); + setName(convert(_handle), _name); } BGFX_API_FUNC(void destroyIndexBuffer(IndexBufferHandle _handle) ) @@ -3032,6 +3040,8 @@ namespace bgfx cmdbuf.write(declHandle); cmdbuf.write(_flags); + setDebugName(convert(handle) ); + return handle; } @@ -3050,7 +3060,7 @@ namespace bgfx VertexBuffer& ref = m_vertexBuffers[_handle.idx]; ref.m_name.set(_name); -// setName(convert(_handle), _name); + setName(convert(_handle), _name); } BGFX_API_FUNC(void destroyVertexBuffer(VertexBufferHandle _handle) ) @@ -3142,6 +3152,8 @@ namespace bgfx cmdbuf.write(size); cmdbuf.write(_flags); + setDebugName(convert(indexBufferHandle), "Dynamic Index Buffer"); + ptr = uint64_t(indexBufferHandle.idx) << 32; } else @@ -3325,6 +3337,8 @@ namespace bgfx cmdbuf.write(size); cmdbuf.write(_flags); + setDebugName(convert(vertexBufferHandle), "Dynamic Vertex Buffer"); + ptr = uint64_t(vertexBufferHandle.idx)<<32; } else @@ -3485,6 +3499,8 @@ namespace bgfx tib->data = (uint8_t *)tib + BX_ALIGN_16(sizeof(TransientIndexBuffer) ); tib->size = _size; tib->handle = handle; + + setDebugName(convert(handle), "Transient Index Buffer"); } return tib; @@ -3547,6 +3563,8 @@ namespace bgfx tvb->stride = stride; tvb->handle = handle; tvb->decl = declHandle; + + setDebugName(convert(handle), "Transient Vertex Buffer"); } return tvb; @@ -3778,6 +3796,8 @@ namespace bgfx cmdbuf.write(handle); cmdbuf.write(_mem); + setDebugName(convert(handle) ); + return handle; } @@ -3802,12 +3822,21 @@ namespace bgfx 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); cmdbuf.write(_handle); - uint16_t len = uint16_t(_name.getLength()+1); cmdbuf.write(len); - cmdbuf.write(_name.getPtr(), len-1); - cmdbuf.write('\0'); + cmdbuf.write(tmp, len); + } + + 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) ) @@ -4088,6 +4117,8 @@ namespace bgfx cmdbuf.write(_flags); cmdbuf.write(_skip); + setDebugName(convert(handle) ); + return handle; } diff --git a/src/renderer_d3d11.cpp b/src/renderer_d3d11.cpp index 87873b2c0..04334051a 100644 --- a/src/renderer_d3d11.cpp +++ b/src/renderer_d3d11.cpp @@ -2001,6 +2001,10 @@ namespace bgfx { namespace d3d11 { switch (_handle.type) { + case Handle::IndexBuffer: + setDebugObjectName(m_indexBuffers[_handle.idx].m_ptr, "%s", _name); + break; + case Handle::Shader: setDebugObjectName(m_shaders[_handle.idx].m_ptr, "%s", _name); break; @@ -2009,6 +2013,10 @@ namespace bgfx { namespace d3d11 setDebugObjectName(m_textures[_handle.idx].m_ptr, "%s", _name); break; + case Handle::VertexBuffer: + setDebugObjectName(m_vertexBuffers[_handle.idx].m_ptr, "%s", _name); + break; + default: BX_CHECK(false, "Invalid handle type?! %d", _handle.type); break; diff --git a/src/renderer_d3d12.cpp b/src/renderer_d3d12.cpp index ead53b9eb..c39076348 100644 --- a/src/renderer_d3d12.cpp +++ b/src/renderer_d3d12.cpp @@ -1876,6 +1876,10 @@ namespace bgfx { namespace d3d12 { switch (_handle.type) { + case Handle::IndexBuffer: + setDebugObjectName(m_indexBuffers[_handle.idx].m_ptr, "%s", _name); + break; + case Handle::Shader: // setDebugObjectName(m_shaders[_handle.idx].m_ptr, "%s", _name); break; @@ -1884,6 +1888,10 @@ namespace bgfx { namespace d3d12 setDebugObjectName(m_textures[_handle.idx].m_ptr, "%s", _name); break; + case Handle::VertexBuffer: + setDebugObjectName(m_vertexBuffers[_handle.idx].m_ptr, "%s", _name); + break; + default: BX_CHECK(false, "Invalid handle type?! %d", _handle.type); break; diff --git a/src/renderer_gl.cpp b/src/renderer_gl.cpp index 9bbb15e3f..e20925831 100644 --- a/src/renderer_gl.cpp +++ b/src/renderer_gl.cpp @@ -2985,6 +2985,10 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); { switch (_handle.type) { + case Handle::IndexBuffer: + GL_CHECK(glObjectLabel(GL_BUFFER, m_indexBuffers[_handle.idx].m_id, -1, _name) ); + break; + case Handle::Shader: GL_CHECK(glObjectLabel(GL_SHADER, m_shaders[_handle.idx].m_id, -1, _name) ); 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) ); break; + case Handle::VertexBuffer: + GL_CHECK(glObjectLabel(GL_BUFFER, m_vertexBuffers[_handle.idx].m_id, -1, _name) ); + break; + default: BX_CHECK(false, "Invalid handle type?! %d", _handle.type); break; diff --git a/src/renderer_mtl.mm b/src/renderer_mtl.mm index 2e4a11c12..7d506e030 100644 --- a/src/renderer_mtl.mm +++ b/src/renderer_mtl.mm @@ -1019,6 +1019,10 @@ namespace bgfx { namespace mtl { switch (_handle.type) { + case Handle::IndexBuffer: +// m_indexBuffers[_handle.idx].m_ptr.setLabel(_name); + break; + case Handle::Shader: m_shaders[_handle.idx].m_function.setLabel(_name); break; @@ -1027,6 +1031,10 @@ namespace bgfx { namespace mtl m_textures[_handle.idx].m_ptr.setLabel(_name); break; + case Handle::VertexBuffer: +// m_vertexBuffers[_handle.idx].m_ptr.setLabel(_name); + break; + default: BX_CHECK(false, "Invalid handle type?! %d", _handle.type); break; @@ -2135,7 +2143,7 @@ namespace bgfx { namespace mtl ComputePipelineReflection reflection = NULL; pso->m_cps = m_device.newComputePipelineStateWithFunction(program.m_vsh->m_function, MTLPipelineOptionBufferTypeInfo, &reflection); processArguments(pso, reflection.arguments, NULL); - + for (uint32_t ii = 0; ii < 3; ++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]); } } - + uint32_t shaderSize; bx::read(&reader, shaderSize);