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

Vulkan: Don't attempt to present the back buffer if it was never even acquired

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

+ 5 - 3
Source/BansheeVulkanRenderAPI/Include/BsVulkanSwapChain.h

@@ -57,10 +57,12 @@ namespace bs
 		void acquireBackBuffer();
 
 		/** 
-		 * Prepares the swap chain for the present operation. Returns the index of the image representing the current
-		 * back buffer.
+		 * Prepares the swap chain for the present operation. 
+		 * 
+		 * @param[out] backBufferIdx	Index of the image representing the current back buffer.
+		 * @return						True if there is anything to present, false otherwise.
 		 */
-		UINT32 prepareForPresent();
+		bool prepareForPresent(UINT32& backBufferIdx);
 
 		/** Returns information describing the current back buffer. */
 		const SwapChainSurface& getBackBuffer() { return mSurfaces[mCurrentBackBufferIdx]; }

+ 4 - 1
Source/BansheeVulkanRenderAPI/Source/BsVulkanQueue.cpp

@@ -70,7 +70,10 @@ namespace bs
 
 	void VulkanQueue::present(VulkanSwapChain* swapChain, VulkanSemaphore** waitSemaphores, UINT32 semaphoresCount)
 	{
-		UINT32 backBufferIdx = swapChain->prepareForPresent();
+		UINT32 backBufferIdx;
+		if (!swapChain->prepareForPresent(backBufferIdx))
+			return; // Nothing to present (back buffer wasn't even acquired)
+
 		VkSwapchainKHR vkSwapChain = swapChain->getHandle();
 
 		VkPresentInfoKHR presentInfo;

+ 6 - 2
Source/BansheeVulkanRenderAPI/Source/BsVulkanSwapChain.cpp

@@ -233,12 +233,16 @@ namespace bs
 		mCurrentBackBufferIdx = imageIndex;
 	}
 
-	UINT32 VulkanSwapChain::prepareForPresent()
+	bool VulkanSwapChain::prepareForPresent(UINT32& backBufferIdx)
 	{
+		if (!mSurfaces[mCurrentBackBufferIdx].acquired)
+			return false;
+
 		assert(mSurfaces[mCurrentBackBufferIdx].acquired && "Attempting to present an unacquired back buffer.");
 		mSurfaces[mCurrentBackBufferIdx].acquired = false;
 
-		return mCurrentBackBufferIdx;
+		backBufferIdx = mCurrentBackBufferIdx;
+		return true;
 	}
 
 	void VulkanSwapChain::clear(VkSwapchainKHR swapChain)