Parcourir la source

Fixed compute program destruction.

Branimir Karadžić il y a 11 ans
Parent
commit
efcb10aef6
3 fichiers modifiés avec 28 ajouts et 12 suppressions
  1. 9 0
      include/bgfx.h
  2. 4 4
      src/bgfx.cpp
  3. 15 8
      src/bgfx_p.h

+ 9 - 0
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);
 

+ 4 - 4
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;

+ 15 - 8
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) )