瀏覽代碼

Vulkan: Properly release Vulkan command buffer when its parent object goes out of scope

BearishSun 9 年之前
父節點
當前提交
79ed48723e

+ 2 - 0
Source/BansheeVulkanRenderAPI/Include/BsVulkanCommandBuffer.h

@@ -451,6 +451,8 @@ namespace bs { namespace ct
 		VulkanCommandBuffer(VulkanDevice& device, GpuQueueType type, UINT32 deviceIdx, UINT32 queueIdx,
 			bool secondary);
 
+		~VulkanCommandBuffer();
+
 		/** 
 		 * Tasks the command buffer to find a new internal command buffer. Call this after the command buffer has been
 		 * submitted to a queue (it's not allowed to be used until the queue is done with it).

+ 5 - 3
Source/BansheeVulkanRenderAPI/Source/BsVulkanCommandBuffer.cpp

@@ -657,9 +657,6 @@ namespace bs { namespace ct
 
 	void VulkanCmdBuffer::reset()
 	{
-		if (mState != State::Submitted)
-			return;
-
 		mState = State::Ready;
 		vkResetCommandBuffer(mCmdBuffer, VK_COMMAND_BUFFER_RESET_RELEASE_RESOURCES_BIT); // Note: Maybe better not to release resources?
 
@@ -1678,6 +1675,11 @@ namespace bs { namespace ct
 		acquireNewBuffer();
 	}
 
+	VulkanCommandBuffer::~VulkanCommandBuffer()
+	{
+		mBuffer->reset();
+	}
+
 	void VulkanCommandBuffer::acquireNewBuffer()
 	{
 		VulkanCmdBufferPool& pool = mDevice.getCmdBufferPool();