From 54c8d695903f9c7cc737d6028a5bbedbc7f252ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Fri, 28 Jul 2017 16:43:16 -0700 Subject: [PATCH] Fixed shader ref counting. --- src/bgfx.cpp | 20 +++++++++++++------- src/bgfx_p.h | 12 ++++-------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/bgfx.cpp b/src/bgfx.cpp index 3f8926807..da370480e 100644 --- a/src/bgfx.cpp +++ b/src/bgfx.cpp @@ -1513,13 +1513,19 @@ namespace bgfx 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 CHECK_HANDLE_LEAK(m_dynamicIndexBufferHandle); diff --git a/src/bgfx_p.h b/src/bgfx_p.h index e56314e1f..249c4b886 100644 --- a/src/bgfx_p.h +++ b/src/bgfx_p.h @@ -3062,6 +3062,7 @@ namespace bgfx { ShaderHandle handle = { idx }; shaderIncRef(handle); + release(_mem); return handle; } @@ -3083,7 +3084,6 @@ namespace bgfx sr.m_refCount = 1; sr.m_hash = iohash; sr.m_num = 0; - sr.m_owned = false; sr.m_uniforms = NULL; UniformHandle* uniforms = (UniformHandle*)alloca(count*sizeof(UniformHandle) ); @@ -3169,12 +3169,7 @@ namespace bgfx 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) @@ -3227,6 +3222,8 @@ namespace bgfx ProgramHandle handle = { idx }; ProgramRef& pr = m_programRef[handle.idx]; ++pr.m_refCount; + shaderIncRef(pr.m_vsh); + shaderIncRef(pr.m_fsh); return handle; } @@ -4342,7 +4339,6 @@ namespace bgfx uint32_t m_hash; int16_t m_refCount; uint16_t m_num; - bool m_owned; }; struct ProgramRef