From efcb10aef61cd47da903a9e4fda053a9100cef09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Tue, 16 Dec 2014 20:12:09 -0800 Subject: [PATCH] Fixed compute program destruction. --- include/bgfx.h | 9 +++++++++ src/bgfx.cpp | 8 ++++---- src/bgfx_p.h | 23 +++++++++++++++-------- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/include/bgfx.h b/include/bgfx.h index 8a070810f..d3d490b18 100644 --- a/include/bgfx.h +++ b/include/bgfx.h @@ -790,6 +790,15 @@ namespace bgfx /// ProgramHandle createProgram(ShaderHandle _vsh, ShaderHandle _fsh, bool _destroyShaders = false); + /// Create program with compute shader. + /// + /// @param _csh Compute shader. + /// @param _destroyShader If true, shader will be destroyed when + /// program is destroyed. + /// @returns Program handle. + /// + ProgramHandle createProgram(ShaderHandle _csh, bool _destroyShader = false); + /// Destroy program. void destroyProgram(ProgramHandle _handle); diff --git a/src/bgfx.cpp b/src/bgfx.cpp index 9e8c01f3d..d733674bb 100644 --- a/src/bgfx.cpp +++ b/src/bgfx.cpp @@ -2235,14 +2235,14 @@ again: return handle; } - ProgramHandle createProgram(ShaderHandle _vsh, bool _destroyShaders) + ProgramHandle createProgram(ShaderHandle _csh, bool _destroyShader) { BGFX_CHECK_MAIN_THREAD(); - ProgramHandle handle = s_ctx->createProgram(_vsh); + ProgramHandle handle = s_ctx->createProgram(_csh); - if (_destroyShaders) + if (_destroyShader) { - destroyShader(_vsh); + destroyShader(_csh); } return handle; diff --git a/src/bgfx_p.h b/src/bgfx_p.h index 430b7421a..58a4140e8 100644 --- a/src/bgfx_p.h +++ b/src/bgfx_p.h @@ -2467,8 +2467,9 @@ namespace bgfx { shaderIncRef(_vsh); shaderIncRef(_fsh); - m_programRef[handle.idx].m_vsh = _vsh; - m_programRef[handle.idx].m_fsh = _fsh; + ProgramRef& pr = m_programRef[handle.idx]; + pr.m_vsh = _vsh; + pr.m_fsh = _fsh; CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::CreateProgram); cmdbuf.write(handle); @@ -2495,14 +2496,15 @@ namespace bgfx if (isValid(handle) ) { shaderIncRef(_vsh); - m_programRef[handle.idx].m_vsh = _vsh; + ProgramRef& pr = m_programRef[handle.idx]; + pr.m_vsh = _vsh; + ShaderHandle fsh = BGFX_INVALID_HANDLE; + pr.m_fsh = fsh; CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::CreateProgram); cmdbuf.write(handle); cmdbuf.write(_vsh); - - ShaderHandle invalid = BGFX_INVALID_HANDLE; - cmdbuf.write(invalid); + cmdbuf.write(fsh); } return handle; @@ -2514,8 +2516,13 @@ namespace bgfx cmdbuf.write(_handle); m_submit->free(_handle); - shaderDecRef(m_programRef[_handle.idx].m_vsh); - shaderDecRef(m_programRef[_handle.idx].m_fsh); + const ProgramRef& pr = m_programRef[_handle.idx]; + shaderDecRef(pr.m_vsh); + + if (isValid(pr.m_fsh) ) + { + shaderDecRef(pr.m_fsh); + } } BGFX_API_FUNC(TextureHandle createTexture(const Memory* _mem, uint32_t _flags, uint8_t _skip, TextureInfo* _info) )