mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2024-11-28 18:45:54 -05:00
Fixed sampler state ref leak.
This commit is contained in:
parent
e1a13b1bbf
commit
d6cb01f72d
3 changed files with 29 additions and 9 deletions
|
@ -34,6 +34,12 @@ namespace bgfx
|
|||
#endif // BGFX_CONFIG_DEBUG
|
||||
|
||||
#if BGFX_CONFIG_DEBUG
|
||||
# define DX_CHECK_REFCOUNT(_ptr, _expected) \
|
||||
do { \
|
||||
ULONG count = getRefCount(_ptr); \
|
||||
BX_CHECK(_expected == count, "RefCount is %d (expected %d).", count, _expected); \
|
||||
} while (0)
|
||||
|
||||
# define DX_RELEASE(_ptr, _expected) \
|
||||
do { \
|
||||
if (NULL != _ptr) \
|
||||
|
@ -44,6 +50,7 @@ namespace bgfx
|
|||
} \
|
||||
} while (0)
|
||||
#else
|
||||
# define DX_CHECK_REFCOUNT(_ptr, _expected)
|
||||
# define DX_RELEASE(_ptr, _expected) \
|
||||
do { \
|
||||
if (NULL != _ptr) \
|
||||
|
@ -53,6 +60,13 @@ namespace bgfx
|
|||
} \
|
||||
} while (0)
|
||||
#endif // BGFX_CONFIG_DEBUG
|
||||
|
||||
inline int getRefCount(IUnknown* _interface)
|
||||
{
|
||||
_interface->AddRef();
|
||||
return _interface->Release();
|
||||
}
|
||||
|
||||
} // namespace bgfx
|
||||
|
||||
#endif // __RENDERER_D3D_H__
|
||||
|
|
|
@ -1423,6 +1423,7 @@ namespace bgfx
|
|||
desc.MinLOD = 0;
|
||||
desc.MaxLOD = D3D11_FLOAT32_MAX;
|
||||
s_renderCtx.m_device->CreateSamplerState(&desc, &m_sampler);
|
||||
DX_CHECK_REFCOUNT(m_sampler, 1);
|
||||
|
||||
s_renderCtx.m_samplerStateCache.add(_flags, m_sampler);
|
||||
}
|
||||
|
@ -1750,6 +1751,12 @@ namespace bgfx
|
|||
}
|
||||
}
|
||||
|
||||
void Texture::destroy()
|
||||
{
|
||||
DX_RELEASE(m_srv, 0);
|
||||
DX_RELEASE(m_ptr, 0);
|
||||
}
|
||||
|
||||
void Texture::commit(uint8_t _stage)
|
||||
{
|
||||
s_renderCtx.m_textureStage.m_srv[_stage] = m_srv;
|
||||
|
@ -1834,7 +1841,11 @@ namespace bgfx
|
|||
// DX_CHECK(s_renderCtx.m_device->CreateShaderResourceView(m_depthTexture, NULL, &m_srv) );
|
||||
}
|
||||
|
||||
m_sampler = s_renderCtx.m_samplerStateCache.find(_flags);
|
||||
_textureFlags &= BGFX_TEXTURE_MIN_MASK|BGFX_TEXTURE_MAG_MASK|BGFX_TEXTURE_MIP_MASK
|
||||
| BGFX_TEXTURE_U_MASK|BGFX_TEXTURE_V_MASK|BGFX_TEXTURE_W_MASK
|
||||
;
|
||||
|
||||
m_sampler = s_renderCtx.m_samplerStateCache.find(_textureFlags);
|
||||
if (NULL == m_sampler)
|
||||
{
|
||||
D3D11_SAMPLER_DESC desc;
|
||||
|
@ -1852,8 +1863,9 @@ namespace bgfx
|
|||
desc.MinLOD = 0;
|
||||
desc.MaxLOD = D3D11_FLOAT32_MAX;
|
||||
s_renderCtx.m_device->CreateSamplerState(&desc, &m_sampler);
|
||||
DX_CHECK_REFCOUNT(m_sampler, 1);
|
||||
|
||||
s_renderCtx.m_samplerStateCache.add(_flags, m_sampler);
|
||||
s_renderCtx.m_samplerStateCache.add(_textureFlags, m_sampler);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -238,13 +238,7 @@ namespace bgfx
|
|||
}
|
||||
|
||||
void create(const Memory* _mem, uint32_t _flags);
|
||||
|
||||
void destroy()
|
||||
{
|
||||
DX_RELEASE(m_srv, 0);
|
||||
DX_RELEASE(m_ptr, 0);
|
||||
}
|
||||
|
||||
void destroy();
|
||||
void update(uint8_t _side, uint8_t _mip, const Rect& _rect, uint16_t _z, uint16_t _depth, const Memory* _mem);
|
||||
void commit(uint8_t _stage);
|
||||
|
||||
|
|
Loading…
Reference in a new issue