2
0
Эх сурвалжийг харах

Vulkan: Submit main CB before attempting to read from a GPU resource. Fixed scene picking.

BearishSun 9 жил өмнө
parent
commit
d5ab33634d

+ 2 - 1
Source/BansheeCore/Include/BsRenderAPI.h

@@ -505,7 +505,8 @@ namespace bs
 		/** 
 		/** 
 		 * Executes all commands in the provided command buffer. Command buffer cannot be secondary.
 		 * Executes all commands in the provided command buffer. Command buffer cannot be secondary.
 		 *
 		 *
-		 * @param[in]	commandBuffer	Command buffer whose commands to execute.
+		 * @param[in]	commandBuffer	Command buffer whose commands to execute. Set to null to submit the main command
+		 *								buffer.
 		 * @param[in]	syncMask		Optional synchronization mask that determines if the submitted command buffer
 		 * @param[in]	syncMask		Optional synchronization mask that determines if the submitted command buffer
 		 *								depends on any other command buffers. Use the CommandSyncMask class to generate
 		 *								depends on any other command buffers. Use the CommandSyncMask class to generate
 		 *								a mask using existing command buffers.
 		 *								a mask using existing command buffers.

+ 3 - 0
Source/BansheeCore/Source/BsMesh.cpp

@@ -423,6 +423,9 @@ namespace bs
 		std::function<void(const SPtr<MeshCore>&, const SPtr<MeshData>&, AsyncOp&)> func =
 		std::function<void(const SPtr<MeshCore>&, const SPtr<MeshData>&, AsyncOp&)> func =
 			[&](const SPtr<MeshCore>& mesh, const SPtr<MeshData>& _meshData, AsyncOp& asyncOp)
 			[&](const SPtr<MeshCore>& mesh, const SPtr<MeshData>& _meshData, AsyncOp& asyncOp)
 		{
 		{
+			// Make sure any queued command start executing before reading
+			RenderAPICore::instance().submitCommandBuffer(nullptr);
+
 			mesh->readData(*_meshData);
 			mesh->readData(*_meshData);
 			_meshData->_unlock();
 			_meshData->_unlock();
 			asyncOp._completeOperation();
 			asyncOp._completeOperation();

+ 3 - 0
Source/BansheeCore/Source/BsTexture.cpp

@@ -385,6 +385,9 @@ namespace bs
 			[&](const SPtr<TextureCore>& texture, UINT32 _face, UINT32 _mipLevel, const SPtr<PixelData>& _pixData, 
 			[&](const SPtr<TextureCore>& texture, UINT32 _face, UINT32 _mipLevel, const SPtr<PixelData>& _pixData, 
 				AsyncOp& asyncOp)
 				AsyncOp& asyncOp)
 		{
 		{
+			// Make sure any queued command start executing before reading
+			RenderAPICore::instance().submitCommandBuffer(nullptr);
+
 			texture->readData(*_pixData, _face, _mipLevel);
 			texture->readData(*_pixData, _face, _mipLevel);
 			_pixData->_unlock();
 			_pixData->_unlock();
 			asyncOp._completeOperation();
 			asyncOp._completeOperation();

+ 3 - 2
Source/BansheeEditor/Source/BsScenePicking.cpp

@@ -375,13 +375,14 @@ namespace bs
 		bs_stack_free(renderableIndices);
 		bs_stack_free(renderableIndices);
 	}
 	}
 
 
-	void ScenePickingCore::corePickingEnd(const SPtr<RenderTargetCore>& target, const Rect2& viewportArea, const Vector2I& position,
-		const Vector2I& area, bool gatherSnapData, AsyncOp& asyncOp)
+	void ScenePickingCore::corePickingEnd(const SPtr<RenderTargetCore>& target, const Rect2& viewportArea, 
+		const Vector2I& position, const Vector2I& area, bool gatherSnapData, AsyncOp& asyncOp)
 	{
 	{
 		const RenderTargetProperties& rtProps = target->getProperties();
 		const RenderTargetProperties& rtProps = target->getProperties();
 		RenderAPICore& rs = RenderAPICore::instance();
 		RenderAPICore& rs = RenderAPICore::instance();
 
 
 		rs.setRenderTarget(nullptr);
 		rs.setRenderTarget(nullptr);
+		rs.submitCommandBuffer(nullptr);
 
 
 		if (rtProps.isWindow())
 		if (rtProps.isWindow())
 		{
 		{

+ 3 - 6
Source/BansheeVulkanRenderAPI/Source/BsVulkanRenderAPI.cpp

@@ -523,16 +523,13 @@ namespace bs
 	{
 	{
 		THROW_IF_NOT_CORE_THREAD;
 		THROW_IF_NOT_CORE_THREAD;
 
 
-		if (commandBuffer == nullptr)
-			return;
+		VulkanCommandBuffer* cmdBuffer = getCB(commandBuffer);
 
 
 		// Submit all transfer buffers first
 		// Submit all transfer buffers first
-		VulkanCommandBuffer& cmdBuffer = static_cast<VulkanCommandBuffer&>(*commandBuffer);
-
 		VulkanCommandBufferManager& cbm = static_cast<VulkanCommandBufferManager&>(CommandBufferManager::instance());
 		VulkanCommandBufferManager& cbm = static_cast<VulkanCommandBufferManager&>(CommandBufferManager::instance());
-		cbm.flushTransferBuffers(cmdBuffer.getDeviceIdx());
+		cbm.flushTransferBuffers(cmdBuffer->getDeviceIdx());
 
 
-		cmdBuffer.submit(syncMask);
+		cmdBuffer->submit(syncMask);
 	}
 	}
 	
 	
 	void VulkanRenderAPI::convertProjectionMatrix(const Matrix4& matrix, Matrix4& dest)
 	void VulkanRenderAPI::convertProjectionMatrix(const Matrix4& matrix, Matrix4& dest)