Browse Source

Fixed shader ref counting.

Branimir Karadžić 8 năm trước cách đây
mục cha
commit
54c8d69590
2 tập tin đã thay đổi với 17 bổ sung15 xóa
  1. 13 7
      src/bgfx.cpp
  2. 4 8
      src/bgfx_p.h

+ 13 - 7
src/bgfx.cpp

@@ -1513,13 +1513,19 @@ namespace bgfx
 
 
 		if (BX_ENABLED(BGFX_CONFIG_DEBUG) )
 		if (BX_ENABLED(BGFX_CONFIG_DEBUG) )
 		{
 		{
-#define CHECK_HANDLE_LEAK(_handleAlloc) \
-					BX_MACRO_BLOCK_BEGIN \
-						BX_WARN(0 == _handleAlloc.getNumHandles() \
-							, "LEAK: " #_handleAlloc " %d (max: %d)" \
-							, _handleAlloc.getNumHandles() \
-							, _handleAlloc.getMaxHandles() \
-							); \
+#define CHECK_HANDLE_LEAK(_handleAlloc)                                                               \
+					BX_MACRO_BLOCK_BEGIN                                                              \
+						if (0 != _handleAlloc.getNumHandles() )                                       \
+						{                                                                             \
+							BX_TRACE("LEAK: " #_handleAlloc " %d (max: %d)"                           \
+								, _handleAlloc.getNumHandles()                                        \
+								, _handleAlloc.getMaxHandles()                                        \
+								);                                                                    \
+							for (uint16_t ii = 0, num = _handleAlloc.getNumHandles(); ii < num; ++ii) \
+							{                                                                         \
+								BX_TRACE("\t%3d: %d", ii, _handleAlloc.getHandleAt(ii) );             \
+							}                                                                         \
+						}                                                                             \
 					BX_MACRO_BLOCK_END
 					BX_MACRO_BLOCK_END
 
 
 			CHECK_HANDLE_LEAK(m_dynamicIndexBufferHandle);
 			CHECK_HANDLE_LEAK(m_dynamicIndexBufferHandle);

+ 4 - 8
src/bgfx_p.h

@@ -3062,6 +3062,7 @@ namespace bgfx
 			{
 			{
 				ShaderHandle handle = { idx };
 				ShaderHandle handle = { idx };
 				shaderIncRef(handle);
 				shaderIncRef(handle);
+				release(_mem);
 				return handle;
 				return handle;
 			}
 			}
 
 
@@ -3083,7 +3084,6 @@ namespace bgfx
 				sr.m_refCount = 1;
 				sr.m_refCount = 1;
 				sr.m_hash     = iohash;
 				sr.m_hash     = iohash;
 				sr.m_num      = 0;
 				sr.m_num      = 0;
-				sr.m_owned    = false;
 				sr.m_uniforms = NULL;
 				sr.m_uniforms = NULL;
 
 
 				UniformHandle* uniforms = (UniformHandle*)alloca(count*sizeof(UniformHandle) );
 				UniformHandle* uniforms = (UniformHandle*)alloca(count*sizeof(UniformHandle) );
@@ -3169,12 +3169,7 @@ namespace bgfx
 
 
 		void shaderTakeOwnership(ShaderHandle _handle)
 		void shaderTakeOwnership(ShaderHandle _handle)
 		{
 		{
-			ShaderRef& sr = m_shaderRef[_handle.idx];
-			if (!sr.m_owned)
-			{
-				sr.m_owned = true;
-				shaderDecRef(_handle);
-			}
+			shaderDecRef(_handle);
 		}
 		}
 
 
 		void shaderIncRef(ShaderHandle _handle)
 		void shaderIncRef(ShaderHandle _handle)
@@ -3227,6 +3222,8 @@ namespace bgfx
 				ProgramHandle handle = { idx };
 				ProgramHandle handle = { idx };
 				ProgramRef& pr = m_programRef[handle.idx];
 				ProgramRef& pr = m_programRef[handle.idx];
 				++pr.m_refCount;
 				++pr.m_refCount;
+				shaderIncRef(pr.m_vsh);
+				shaderIncRef(pr.m_fsh);
 				return handle;
 				return handle;
 			}
 			}
 
 
@@ -4342,7 +4339,6 @@ namespace bgfx
 			uint32_t m_hash;
 			uint32_t m_hash;
 			int16_t  m_refCount;
 			int16_t  m_refCount;
 			uint16_t m_num;
 			uint16_t m_num;
-			bool     m_owned;
 		};
 		};
 
 
 		struct ProgramRef
 		struct ProgramRef