Commit 148ecd89 by Tim Van Patten Committed by Commit Bot

Vulkan: Handle VK_ERROR_OUT_OF_DATE returned by vkAcquireNextImageKHR()

There is some new Android HWUI/SkiaGL code, that (in certain cases) looks up the underlying Vulkan swapchain that ANGLE created, and adds an image to it. This causes the next call to vkAcquireNextImageKHR() to return VK_ERROR_OUT_OF_DATE and requires the swapchain to be recreated. Bug: angleproject:3480 Test: Use ANGLE on Android and verify apps load correctly. Change-Id: I21c86035664878e75d6a9dc769546747aa4c8256 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1632424 Commit-Queue: Tim Van Patten <timvp@google.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 55ca3a51
......@@ -537,7 +537,14 @@ angle::Result WindowSurfaceVk::initializeImpl(DisplayVk *displayVk)
ANGLE_TRY(createSwapChain(displayVk, extents, VK_NULL_HANDLE));
return nextSwapchainImage(displayVk);
VkResult vkResult = nextSwapchainImage(displayVk);
// VK_SUBOPTIMAL_KHR is ok since we still have an Image that can be presented successfully
if (ANGLE_UNLIKELY((vkResult != VK_SUCCESS) && (vkResult != VK_SUBOPTIMAL_KHR)))
{
ANGLE_VK_TRY(displayVk, vkResult);
}
return angle::Result::Continue;
}
angle::Result WindowSurfaceVk::recreateSwapchain(ContextVk *contextVk,
......@@ -983,7 +990,17 @@ angle::Result WindowSurfaceVk::swapImpl(const gl::Context *context, EGLint *rect
// http://anglebug.com/2927
TRACE_EVENT0("gpu.angle", "nextSwapchainImage");
// Get the next available swapchain image.
ANGLE_TRY(nextSwapchainImage(contextVk));
VkResult result = nextSwapchainImage(contextVk);
// If SUBOPTIMAL/OUT_OF_DATE is returned, it's ok, we just need to recreate the swapchain
// before continuing.
if (ANGLE_UNLIKELY((result == VK_ERROR_OUT_OF_DATE_KHR) || (result == VK_SUBOPTIMAL_KHR)))
{
ANGLE_TRY(checkForOutOfDateSwapchain(contextVk, currentSwapHistoryIndex, true));
// Try one more time and bail if we fail
result = nextSwapchainImage(contextVk);
}
ANGLE_VK_TRY(contextVk, result);
}
RendererVk *renderer = contextVk->getRenderer();
......@@ -992,16 +1009,24 @@ angle::Result WindowSurfaceVk::swapImpl(const gl::Context *context, EGLint *rect
return angle::Result::Continue;
}
angle::Result WindowSurfaceVk::nextSwapchainImage(vk::Context *context)
VkResult WindowSurfaceVk::nextSwapchainImage(vk::Context *context)
{
VkDevice device = context->getDevice();
vk::Scoped<vk::Semaphore> aquireImageSemaphore(device);
ANGLE_VK_TRY(context, aquireImageSemaphore.get().init(device));
VkResult result = aquireImageSemaphore.get().init(device);
if (ANGLE_UNLIKELY(result != VK_SUCCESS))
{
return result;
}
ANGLE_VK_TRY(context, vkAcquireNextImageKHR(device, mSwapchain, UINT64_MAX,
aquireImageSemaphore.get().getHandle(),
VK_NULL_HANDLE, &mCurrentSwapchainImageIndex));
result = vkAcquireNextImageKHR(device, mSwapchain, UINT64_MAX,
aquireImageSemaphore.get().getHandle(), VK_NULL_HANDLE,
&mCurrentSwapchainImageIndex);
if (ANGLE_UNLIKELY(result != VK_SUCCESS))
{
return result;
}
// After presenting, the flush semaphore chain is cleared. The semaphore returned by
// vkAcquireNextImage will start a new chain.
......@@ -1029,7 +1054,7 @@ angle::Result WindowSurfaceVk::nextSwapchainImage(vk::Context *context)
mColorRenderTarget.updateSwapchainImage(&image.image, &image.imageView);
}
return angle::Result::Continue;
return VK_SUCCESS;
}
egl::Error WindowSurfaceVk::postSubBuffer(const gl::Context *context,
......
......@@ -167,7 +167,7 @@ class WindowSurfaceVk : public SurfaceVk
bool presentOutOfDate);
void releaseSwapchainImages(ContextVk *contextVk);
void destroySwapChainImages(DisplayVk *displayVk);
angle::Result nextSwapchainImage(vk::Context *context);
VkResult nextSwapchainImage(vk::Context *context);
angle::Result present(ContextVk *contextVk,
EGLint *rects,
EGLint n_rects,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment