diff --git a/include/dawn/dawn_wsi.h b/include/dawn/dawn_wsi.h index aecb252893..154c2fe97f 100644 --- a/include/dawn/dawn_wsi.h +++ b/include/dawn/dawn_wsi.h @@ -20,6 +20,7 @@ // Error message (or nullptr if there was no error) typedef const char* DawnSwapChainError; constexpr DawnSwapChainError DAWN_SWAP_CHAIN_NO_ERROR = nullptr; +constexpr DawnSwapChainError DAWN_SWAP_CHAIN_ERROR_OUT_OF_DATE = "Out of date"; typedef struct { /// Backend-specific texture id/name/pointer diff --git a/src/dawn/native/SwapChain.cpp b/src/dawn/native/SwapChain.cpp index 16fedc4e09..12d09f0f80 100644 --- a/src/dawn/native/SwapChain.cpp +++ b/src/dawn/native/SwapChain.cpp @@ -195,7 +195,12 @@ TextureViewBase* OldSwapChainBase::APIGetCurrentTextureView() { // Get the texture but remove the external refcount because it is never passed outside // of dawn_native - mCurrentTexture = AcquireRef(GetNextTextureImpl(&descriptor)); + TextureBase* texture = GetNextTextureImpl(&descriptor); + if (texture == nullptr) { + // Swapchain out of date + return nullptr; + } + mCurrentTexture = AcquireRef(texture); mCurrentTextureView = mCurrentTexture->APICreateView(); return mCurrentTextureView.Get(); diff --git a/src/dawn/native/vulkan/NativeSwapChainImplVk.cpp b/src/dawn/native/vulkan/NativeSwapChainImplVk.cpp index 375db0e5d2..7deb1dbed9 100644 --- a/src/dawn/native/vulkan/NativeSwapChainImplVk.cpp +++ b/src/dawn/native/vulkan/NativeSwapChainImplVk.cpp @@ -103,10 +103,10 @@ DawnSwapChainError NativeSwapChainImpl::Configure(WGPUTextureFormat format, uint32_t height) { UpdateSurfaceConfig(); - ASSERT(mInfo.capabilities.minImageExtent.width <= width); - ASSERT(mInfo.capabilities.maxImageExtent.width >= width); - ASSERT(mInfo.capabilities.minImageExtent.height <= height); - ASSERT(mInfo.capabilities.maxImageExtent.height >= height); +// ASSERT(mInfo.capabilities.minImageExtent.width <= width); +// ASSERT(mInfo.capabilities.maxImageExtent.width >= width); +// ASSERT(mInfo.capabilities.minImageExtent.height <= height); +// ASSERT(mInfo.capabilities.maxImageExtent.height >= height); ASSERT(format == static_cast(GetPreferredFormat())); // TODO(crbug.com/dawn/269): need to check usage works too @@ -177,9 +177,12 @@ DawnSwapChainError NativeSwapChainImpl::GetNextTexture(DawnSwapChainNextTexture* } } - if (mDevice->fn.AcquireNextImageKHR(mDevice->GetVkDevice(), mSwapChain, - std::numeric_limits::max(), semaphore, VkFence{}, - &mLastImageIndex) != VK_SUCCESS) { + const auto result = mDevice->fn.AcquireNextImageKHR( + mDevice->GetVkDevice(), mSwapChain, std::numeric_limits::max(), semaphore, + VkFence{}, &mLastImageIndex); + if (result == VK_ERROR_OUT_OF_DATE_KHR) { + return DAWN_SWAP_CHAIN_ERROR_OUT_OF_DATE; + } else if (result != VK_SUCCESS) { ASSERT(false); } @@ -211,7 +214,8 @@ DawnSwapChainError NativeSwapChainImpl::Present() { presentInfo.pResults = nullptr; VkQueue queue = mDevice->GetQueue(); - if (mDevice->fn.QueuePresentKHR(queue, &presentInfo) != VK_SUCCESS) { + const auto result = mDevice->fn.QueuePresentKHR(queue, &presentInfo); + if (result != VK_SUCCESS && result != VK_ERROR_OUT_OF_DATE_KHR) { ASSERT(false); } diff --git a/src/dawn/native/vulkan/SwapChainVk.cpp b/src/dawn/native/vulkan/SwapChainVk.cpp index 63de95e9f9..24a45eb163 100644 --- a/src/dawn/native/vulkan/SwapChainVk.cpp +++ b/src/dawn/native/vulkan/SwapChainVk.cpp @@ -59,7 +59,9 @@ TextureBase* OldSwapChain::GetNextTextureImpl(const TextureDescriptor* descripto DawnSwapChainError error = im.GetNextTexture(im.userData, &next); if (error) { - GetDevice()->HandleError(InternalErrorType::Internal, error); + if (error != DAWN_SWAP_CHAIN_ERROR_OUT_OF_DATE) { + GetDevice()->HandleError(InternalErrorType::Internal, error); + } return nullptr; }