Просмотр исходного кода

Added setName for index, vertex, and frame buffers.

Бранимир Караџић 7 лет назад
Родитель
Сommit
fd45604047
5 измененных файлов с 183 добавлено и 27 удалено
  1. 45 0
      include/bgfx/bgfx.h
  2. 3 0
      include/bgfx/c99/platform.h
  3. 1 1
      include/bgfx/defines.h
  4. 81 21
      src/bgfx.cpp
  5. 53 5
      src/bgfx_p.h

+ 45 - 0
include/bgfx/bgfx.h

@@ -2122,6 +2122,21 @@ namespace bgfx
 		, uint16_t _flags = BGFX_BUFFER_NONE
 		);
 
+	/// Set static index buffer debug name.
+	///
+	/// @param[in] _handle Static index buffer handle.
+	/// @param[in] _name Static index buffer name.
+	/// @param[in] _len Static index buffer name length (if length is INT32_MAX, it's expected
+	///   that _name is zero terminated string.
+	///
+	/// @attention C99 equivalent is `bgfx_set_index_buffer_name`.
+	///
+	void setName(
+		  IndexBufferHandle _handle
+		, const char* _name
+		, int32_t _len = INT32_MAX
+		);
+
 	/// Destroy static index buffer.
 	///
 	/// @param[in] _handle Static index buffer handle.
@@ -2156,6 +2171,21 @@ namespace bgfx
 		, uint16_t _flags = BGFX_BUFFER_NONE
 		);
 
+	/// Set static vertex buffer debug name.
+	///
+	/// @param[in] _handle Static vertex buffer handle.
+	/// @param[in] _name Static vertex buffer name.
+	/// @param[in] _len Static vertex buffer name length (if length is INT32_MAX, it's expected
+	///   that _name is zero terminated string.
+	///
+	/// @attention C99 equivalent is `bgfx_set_vertex_buffer_name`.
+	///
+	void setName(
+		  VertexBufferHandle _handle
+		, const char* _name
+		, int32_t _len = INT32_MAX
+		);
+
 	/// Destroy static vertex buffer.
 	///
 	/// @param[in] _handle Static vertex buffer handle.
@@ -2953,6 +2983,21 @@ namespace bgfx
 		, TextureFormat::Enum _depthFormat = TextureFormat::Count
 		);
 
+	/// Set frame buffer debug name.
+	///
+	/// @param[in] _handle frame buffer handle.
+	/// @param[in] _name frame buffer name.
+	/// @param[in] _len frame buffer name length (if length is INT32_MAX, it's expected
+	///   that _name is zero terminated string.
+	///
+	/// @attention C99 equivalent is `bgfx_set_frame_buffer_name`.
+	///
+	void setName(
+		  FrameBufferHandle _handle
+		, const char* _name
+		, int32_t _len = INT32_MAX
+		);
+
 	/// Obtain texture handle of frame buffer attachment.
 	///
 	/// @param[in] _handle Frame buffer handle.

+ 3 - 0
include/bgfx/c99/platform.h

@@ -92,8 +92,10 @@ typedef struct bgfx_interface_vtbl
     void (*dbg_text_vprintf)(uint16_t _x, uint16_t _y, uint8_t _attr, const char* _format, va_list _argList);
     void (*dbg_text_image)(uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const void* _data, uint16_t _pitch);
     bgfx_index_buffer_handle_t (*create_index_buffer)(const bgfx_memory_t* _mem, uint16_t _flags);
+    void (*set_index_buffer_name)(bgfx_index_buffer_handle_t _handle, const char* _name, int32_t _len);
     void (*destroy_index_buffer)(bgfx_index_buffer_handle_t _handle);
     bgfx_vertex_buffer_handle_t (*create_vertex_buffer)(const bgfx_memory_t* _mem, const bgfx_vertex_decl_t* _decl, uint16_t _flags);
+    void (*set_vertex_buffer_name)(bgfx_vertex_buffer_handle_t _handle, const char* _name, int32_t _len);
     void (*destroy_vertex_buffer)(bgfx_vertex_buffer_handle_t _handle);
     bgfx_dynamic_index_buffer_handle_t (*create_dynamic_index_buffer)(uint32_t _num, uint16_t _flags);
     bgfx_dynamic_index_buffer_handle_t (*create_dynamic_index_buffer_mem)(const bgfx_memory_t* _mem, uint16_t _flags);
@@ -137,6 +139,7 @@ typedef struct bgfx_interface_vtbl
     bgfx_frame_buffer_handle_t (*create_frame_buffer_scaled)(bgfx_backbuffer_ratio_t _ratio, bgfx_texture_format_t _format, uint64_t _textureFlags);
     bgfx_frame_buffer_handle_t (*create_frame_buffer_from_attachment)(uint8_t _num, const bgfx_attachment_t* _attachment, bool _destroyTextures);
     bgfx_frame_buffer_handle_t (*create_frame_buffer_from_nwh)(void* _nwh, uint16_t _width, uint16_t _height, bgfx_texture_format_t _format, bgfx_texture_format_t _depthFormat);
+    void (*set_frame_buffer_name)(bgfx_frame_buffer_handle_t _handle, const char* _name, int32_t _len);
     bgfx_texture_handle_t (*get_texture)(bgfx_frame_buffer_handle_t _handle, uint8_t _attachment);
     void (*destroy_frame_buffer)(bgfx_frame_buffer_handle_t _handle);
     bgfx_uniform_handle_t (*create_uniform)(const char* _name, bgfx_uniform_type_t _type, uint16_t _num);

+ 1 - 1
include/bgfx/defines.h

@@ -6,7 +6,7 @@
 #ifndef BGFX_DEFINES_H_HEADER_GUARD
 #define BGFX_DEFINES_H_HEADER_GUARD
 
-#define BGFX_API_VERSION UINT32_C(92)
+#define BGFX_API_VERSION UINT32_C(93)
 
 /// Color RGB/alpha/depth write. When it's not specified write will be disabled.
 #define BGFX_STATE_WRITE_R                 UINT64_C(0x0000000000000001) //!< Enable R write.

+ 81 - 21
src/bgfx.cpp

@@ -1923,11 +1923,12 @@ namespace bgfx
 
 		if (BX_ENABLED(BGFX_CONFIG_DEBUG) )
 		{
-#define CHECK_HANDLE_LEAK(_handleAlloc)                                               \
+#define CHECK_HANDLE_LEAK(_name, _handleAlloc)                                        \
 	BX_MACRO_BLOCK_BEGIN                                                              \
 		if (0 != _handleAlloc.getNumHandles() )                                       \
 		{                                                                             \
-			BX_TRACE("LEAK: " #_handleAlloc " %d (max: %d)"                           \
+			BX_TRACE("LEAK: %s %d (max: %d)"                                          \
+				, _name                                                               \
 				, _handleAlloc.getNumHandles()                                        \
 				, _handleAlloc.getMaxHandles()                                        \
 				);                                                                    \
@@ -1938,11 +1939,34 @@ namespace bgfx
 		}                                                                             \
 	BX_MACRO_BLOCK_END
 
-#define CHECK_HANDLE_LEAK_NAME(_handleAlloc, _type, _ref)                             \
+#define CHECK_HANDLE_LEAK_NAME(_name, _handleAlloc, _type, _ref)                      \
 	BX_MACRO_BLOCK_BEGIN                                                              \
 		if (0 != _handleAlloc.getNumHandles() )                                       \
 		{                                                                             \
-			BX_TRACE("LEAK: " #_handleAlloc " %d (max: %d)"                           \
+			BX_TRACE("LEAK: %s %d (max: %d)"                                          \
+				, _name                                                               \
+				, _handleAlloc.getNumHandles()                                        \
+				, _handleAlloc.getMaxHandles()                                        \
+				);                                                                    \
+			for (uint16_t ii = 0, num = _handleAlloc.getNumHandles(); ii < num; ++ii) \
+			{                                                                         \
+				uint16_t idx = _handleAlloc.getHandleAt(ii);                          \
+				const _type& ref = _ref[idx]; BX_UNUSED(ref);                         \
+				BX_TRACE("\t%3d: %4d %s"                                              \
+					, ii                                                              \
+					, idx                                                             \
+					, ref.m_name.getPtr()                                             \
+					);                                                                \
+			}                                                                         \
+		}                                                                             \
+	BX_MACRO_BLOCK_END
+
+#define CHECK_HANDLE_LEAK_RC_NAME(_name, _handleAlloc, _type, _ref)                   \
+	BX_MACRO_BLOCK_BEGIN                                                              \
+		if (0 != _handleAlloc.getNumHandles() )                                       \
+		{                                                                             \
+			BX_TRACE("LEAK: %s %d (max: %d)"                                          \
+				, _name                                                               \
 				, _handleAlloc.getNumHandles()                                        \
 				, _handleAlloc.getMaxHandles()                                        \
 				);                                                                    \
@@ -1951,26 +1975,26 @@ namespace bgfx
 				uint16_t idx = _handleAlloc.getHandleAt(ii);                          \
 				const _type& ref = _ref[idx]; BX_UNUSED(ref);                         \
 				BX_TRACE("\t%3d: %4d %s (count %d)"                                   \
-						, ii                                                          \
-						, idx                                                         \
-						, ref.m_name.getPtr()                                         \
-						, ref.m_refCount                                              \
-						);                                                            \
+					, ii                                                              \
+					, idx                                                             \
+					, ref.m_name.getPtr()                                             \
+					, ref.m_refCount                                                  \
+					);                                                                \
 			}                                                                         \
 		}                                                                             \
 	BX_MACRO_BLOCK_END
 
-			CHECK_HANDLE_LEAK     (m_dynamicIndexBufferHandle                          );
-			CHECK_HANDLE_LEAK     (m_dynamicVertexBufferHandle                         );
-			CHECK_HANDLE_LEAK     (m_indexBufferHandle                                 );
-			CHECK_HANDLE_LEAK     (m_vertexDeclHandle                                  );
-			CHECK_HANDLE_LEAK     (m_vertexBufferHandle                                );
-			CHECK_HANDLE_LEAK_NAME(m_shaderHandle,             ShaderRef,  m_shaderRef );
-			CHECK_HANDLE_LEAK     (m_programHandle                                     );
-			CHECK_HANDLE_LEAK_NAME(m_textureHandle,            TextureRef, m_textureRef);
-			CHECK_HANDLE_LEAK     (m_frameBufferHandle                                 );
-			CHECK_HANDLE_LEAK_NAME(m_uniformHandle,            UniformRef, m_uniformRef);
-			CHECK_HANDLE_LEAK     (m_occlusionQueryHandle                              );
+			CHECK_HANDLE_LEAK        ("DynamicIndexBufferHandle",  m_dynamicIndexBufferHandle                                  );
+			CHECK_HANDLE_LEAK        ("DynamicVertexBufferHandle", m_dynamicVertexBufferHandle                                 );
+			CHECK_HANDLE_LEAK_NAME   ("IndexBufferHandle",         m_indexBufferHandle,        IndexBuffer,    m_indexBuffers  );
+			CHECK_HANDLE_LEAK        ("VertexDeclHandle",          m_vertexDeclHandle                                          );
+			CHECK_HANDLE_LEAK_NAME   ("VertexBufferHandle",        m_vertexBufferHandle,       VertexBuffer,   m_vertexBuffers );
+			CHECK_HANDLE_LEAK_RC_NAME("ShaderHandle",              m_shaderHandle,             ShaderRef,      m_shaderRef     );
+			CHECK_HANDLE_LEAK        ("ProgramHandle",             m_programHandle                                             );
+			CHECK_HANDLE_LEAK_RC_NAME("TextureHandle",             m_textureHandle,            TextureRef,     m_textureRef    );
+			CHECK_HANDLE_LEAK_NAME   ("FrameBufferHandle",         m_frameBufferHandle,        FrameBufferRef, m_frameBufferRef);
+			CHECK_HANDLE_LEAK_RC_NAME("UniformHandle",             m_uniformHandle,            UniformRef,     m_uniformRef    );
+			CHECK_HANDLE_LEAK        ("OcclusionQueryHandle",      m_occlusionQueryHandle                                      );
 #undef CHECK_HANDLE_LEAK
 #undef CHECK_HANDLE_LEAK_NAME
 		}
@@ -2372,10 +2396,10 @@ namespace bgfx
 	BGFX_RENDERER_CONTEXT(d3d9);
 	BGFX_RENDERER_CONTEXT(d3d11);
 	BGFX_RENDERER_CONTEXT(d3d12);
+	BGFX_RENDERER_CONTEXT(gnm);
 	BGFX_RENDERER_CONTEXT(mtl);
 	BGFX_RENDERER_CONTEXT(gl);
 	BGFX_RENDERER_CONTEXT(vk);
-	BGFX_RENDERER_CONTEXT(gnm);
 
 #undef BGFX_RENDERER_CONTEXT
 
@@ -3777,6 +3801,11 @@ namespace bgfx
 		return s_ctx->createIndexBuffer(_mem, _flags);
 	}
 
+	void setName(IndexBufferHandle _handle, const char* _name, int32_t _len)
+	{
+		s_ctx->setName(_handle, bx::StringView(_name, _len) );
+	}
+
 	void destroy(IndexBufferHandle _handle)
 	{
 		s_ctx->destroyIndexBuffer(_handle);
@@ -3789,6 +3818,11 @@ namespace bgfx
 		return s_ctx->createVertexBuffer(_mem, _decl, _flags);
 	}
 
+	void setName(VertexBufferHandle _handle, const char* _name, int32_t _len)
+	{
+		s_ctx->setName(_handle, bx::StringView(_name, _len) );
+	}
+
 	void destroy(VertexBufferHandle _handle)
 	{
 		s_ctx->destroyVertexBuffer(_handle);
@@ -4398,6 +4432,11 @@ namespace bgfx
 			);
 	}
 
+	void setName(FrameBufferHandle _handle, const char* _name, int32_t _len)
+	{
+		s_ctx->setName(_handle, bx::StringView(_name, _len) );
+	}
+
 	TextureHandle getTexture(FrameBufferHandle _handle, uint8_t _attachment)
 	{
 		return s_ctx->getTexture(_handle, _attachment);
@@ -5368,6 +5407,12 @@ BGFX_C_API bgfx_index_buffer_handle_t bgfx_create_index_buffer(const bgfx_memory
 	return handle.c;
 }
 
+void bgfx_set_index_buffer_name(bgfx_index_buffer_handle_t _handle, const char* _name, int32_t _len)
+{
+	union { bgfx_index_buffer_handle_t c; bgfx::IndexBufferHandle cpp; } handle = { _handle };
+	bgfx::setName(handle.cpp, _name, _len);
+}
+
 BGFX_C_API void bgfx_destroy_index_buffer(bgfx_index_buffer_handle_t _handle)
 {
 	union { bgfx_index_buffer_handle_t c; bgfx::IndexBufferHandle cpp; } handle = { _handle };
@@ -5382,6 +5427,12 @@ BGFX_C_API bgfx_vertex_buffer_handle_t bgfx_create_vertex_buffer(const bgfx_memo
 	return handle.c;
 }
 
+void bgfx_set_vertex_buffer_name(bgfx_vertex_buffer_handle_t _handle, const char* _name, int32_t _len)
+{
+	union { bgfx_vertex_buffer_handle_t c; bgfx::VertexBufferHandle cpp; } handle = { _handle };
+	bgfx::setName(handle.cpp, _name, _len);
+}
+
 BGFX_C_API void bgfx_destroy_vertex_buffer(bgfx_vertex_buffer_handle_t _handle)
 {
 	union { bgfx_vertex_buffer_handle_t c; bgfx::VertexBufferHandle cpp; } handle = { _handle };
@@ -5665,6 +5716,12 @@ BGFX_C_API bgfx_frame_buffer_handle_t bgfx_create_frame_buffer_from_nwh(void* _n
 	return handle.c;
 }
 
+void bgfx_set_frame_buffer_name(bgfx_frame_buffer_handle_t _handle, const char* _name, int32_t _len)
+{
+	union { bgfx_frame_buffer_handle_t c; bgfx::FrameBufferHandle cpp; } handle = { _handle };
+	bgfx::setName(handle.cpp, _name, _len);
+}
+
 BGFX_C_API bgfx_texture_handle_t bgfx_get_texture(bgfx_frame_buffer_handle_t _handle, uint8_t _attachment)
 {
 	union { bgfx_frame_buffer_handle_t c; bgfx::FrameBufferHandle cpp; } handle = { _handle };
@@ -6270,8 +6327,10 @@ BGFX_C_API bgfx_interface_vtbl_t* bgfx_get_interface(uint32_t _version)
 	BGFX_IMPORT_FUNC(dbg_text_vprintf)                                     \
 	BGFX_IMPORT_FUNC(dbg_text_image)                                       \
 	BGFX_IMPORT_FUNC(create_index_buffer)                                  \
+	BGFX_IMPORT_FUNC(set_index_buffer_name)                                \
 	BGFX_IMPORT_FUNC(destroy_index_buffer)                                 \
 	BGFX_IMPORT_FUNC(create_vertex_buffer)                                 \
+	BGFX_IMPORT_FUNC(set_vertex_buffer_name)                               \
 	BGFX_IMPORT_FUNC(destroy_vertex_buffer)                                \
 	BGFX_IMPORT_FUNC(create_dynamic_index_buffer)                          \
 	BGFX_IMPORT_FUNC(create_dynamic_index_buffer_mem)                      \
@@ -6315,6 +6374,7 @@ BGFX_C_API bgfx_interface_vtbl_t* bgfx_get_interface(uint32_t _version)
 	BGFX_IMPORT_FUNC(create_frame_buffer_scaled)                           \
 	BGFX_IMPORT_FUNC(create_frame_buffer_from_attachment)                  \
 	BGFX_IMPORT_FUNC(create_frame_buffer_from_nwh)                         \
+	BGFX_IMPORT_FUNC(set_frame_buffer_name)                                \
 	BGFX_IMPORT_FUNC(get_texture)                                          \
 	BGFX_IMPORT_FUNC(destroy_frame_buffer)                                 \
 	BGFX_IMPORT_FUNC(create_uniform)                                       \

+ 53 - 5
src/bgfx_p.h

@@ -1660,11 +1660,13 @@ namespace bgfx
 
 	struct IndexBuffer
 	{
+		String   m_name;
 		uint32_t m_size;
 	};
 
 	struct VertexBuffer
 	{
+		String   m_name;
 		uint32_t m_size;
 		uint16_t m_stride;
 	};
@@ -2879,6 +2881,18 @@ namespace bgfx
 			return handle;
 		}
 
+		BGFX_API_FUNC(void setName(IndexBufferHandle _handle, const bx::StringView& _name) )
+		{
+			BGFX_MUTEX_SCOPE(m_resourceApiLock);
+
+			BGFX_CHECK_HANDLE("setName", m_indexBufferHandle, _handle);
+
+			IndexBuffer& ref = m_indexBuffers[_handle.idx];
+			ref.m_name.set(_name);
+
+//			setName(convert(_handle), _name);
+		}
+
 		BGFX_API_FUNC(void destroyIndexBuffer(IndexBufferHandle _handle) )
 		{
 			BGFX_MUTEX_SCOPE(m_resourceApiLock);
@@ -2887,6 +2901,9 @@ namespace bgfx
 			bool ok = m_submit->free(_handle); BX_UNUSED(ok);
 			BX_CHECK(ok, "Index buffer handle %d is already destroyed!", _handle.idx);
 
+			IndexBuffer& ref = m_indexBuffers[_handle.idx];
+			ref.m_name.clear();
+
 			CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::DestroyIndexBuffer);
 			cmdbuf.write(_handle);
 		}
@@ -2948,6 +2965,18 @@ namespace bgfx
 			return BGFX_INVALID_HANDLE;
 		}
 
+		BGFX_API_FUNC(void setName(VertexBufferHandle _handle, const bx::StringView& _name) )
+		{
+			BGFX_MUTEX_SCOPE(m_resourceApiLock);
+
+			BGFX_CHECK_HANDLE("setName", m_vertexBufferHandle, _handle);
+
+			VertexBuffer& ref = m_vertexBuffers[_handle.idx];
+			ref.m_name.set(_name);
+
+//			setName(convert(_handle), _name);
+		}
+
 		BGFX_API_FUNC(void destroyVertexBuffer(VertexBufferHandle _handle) )
 		{
 			BGFX_MUTEX_SCOPE(m_resourceApiLock);
@@ -2956,6 +2985,9 @@ namespace bgfx
 			bool ok = m_submit->free(_handle); BX_UNUSED(ok);
 			BX_CHECK(ok, "Vertex buffer handle %d is already destroyed!", _handle.idx);
 
+			VertexBuffer& ref = m_vertexBuffers[_handle.idx];
+			ref.m_name.clear();
+
 			CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::DestroyVertexBuffer);
 			cmdbuf.write(_handle);
 		}
@@ -4242,6 +4274,18 @@ namespace bgfx
 			return handle;
 		}
 
+		BGFX_API_FUNC(void setName(FrameBufferHandle _handle, const bx::StringView& _name) )
+		{
+			BGFX_MUTEX_SCOPE(m_resourceApiLock);
+
+			BGFX_CHECK_HANDLE("setName", m_frameBufferHandle, _handle);
+
+			FrameBufferRef& ref = m_frameBufferRef[_handle.idx];
+			ref.m_name.set(_name);
+
+//			setName(convert(_handle), _name);
+		}
+
 		BGFX_API_FUNC(TextureHandle getTexture(FrameBufferHandle _handle, uint8_t _attachment) )
 		{
 			BGFX_MUTEX_SCOPE(m_resourceApiLock);
@@ -4270,6 +4314,8 @@ namespace bgfx
 			cmdbuf.write(_handle);
 
 			FrameBufferRef& ref = m_frameBufferRef[_handle.idx];
+			ref.m_name.clear();
+
 			if (!ref.m_window)
 			{
 				for (uint32_t ii = 0; ii < BX_COUNTOF(ref.un.m_th); ++ii)
@@ -4789,6 +4835,8 @@ namespace bgfx
 
 		struct FrameBufferRef
 		{
+			String m_name;
+
 			union un
 			{
 				TextureHandle m_th[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS];
@@ -4799,19 +4847,19 @@ namespace bgfx
 
 		typedef bx::HandleHashMapT<BGFX_CONFIG_MAX_UNIFORMS*2> UniformHashMap;
 		UniformHashMap m_uniformHashMap;
-		UniformRef m_uniformRef[BGFX_CONFIG_MAX_UNIFORMS];
+		UniformRef     m_uniformRef[BGFX_CONFIG_MAX_UNIFORMS];
 
 		typedef bx::HandleHashMapT<BGFX_CONFIG_MAX_SHADERS*2> ShaderHashMap;
 		ShaderHashMap m_shaderHashMap;
-		ShaderRef m_shaderRef[BGFX_CONFIG_MAX_SHADERS];
+		ShaderRef     m_shaderRef[BGFX_CONFIG_MAX_SHADERS];
 
 		typedef bx::HandleHashMapT<BGFX_CONFIG_MAX_PROGRAMS*2> ProgramHashMap;
 		ProgramHashMap m_programHashMap;
-		ProgramRef m_programRef[BGFX_CONFIG_MAX_PROGRAMS];
+		ProgramRef     m_programRef[BGFX_CONFIG_MAX_PROGRAMS];
 
-		TextureRef m_textureRef[BGFX_CONFIG_MAX_TEXTURES];
+		TextureRef     m_textureRef[BGFX_CONFIG_MAX_TEXTURES];
 		FrameBufferRef m_frameBufferRef[BGFX_CONFIG_MAX_FRAME_BUFFERS];
-		VertexDeclRef m_declRef;
+		VertexDeclRef  m_declRef;
 
 		ViewId m_viewRemap[BGFX_CONFIG_MAX_VIEWS];
 		uint32_t m_seq[BGFX_CONFIG_MAX_VIEWS];