Commit c22ef61f by Geoff Lang Committed by Commit Bot

Vulkan: Store fences instead of serials in SurfaceVK::SwapHistory

Previous swaps may not have been submitted by the same context as the current swap and we can't safely wait on serials submitted by other contexts. BUG=angleproject:2464 Change-Id: Ibcb23171feae038fd45abdefb80c4e8a373744e2 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1562521Reviewed-by: 's avatarShahbaz Youssefi <syoussefi@chromium.org> Commit-Queue: Geoff Lang <geofflang@chromium.org>
parent 37860a70
...@@ -1726,6 +1726,17 @@ angle::Result RendererVk::getSubmitFence(vk::Context *context, ...@@ -1726,6 +1726,17 @@ angle::Result RendererVk::getSubmitFence(vk::Context *context,
return angle::Result::Continue; return angle::Result::Continue;
} }
vk::Shared<vk::Fence> RendererVk::getLastSubmittedFence() const
{
vk::Shared<vk::Fence> fence;
if (!mInFlightCommands.empty())
{
fence.copy(getDevice(), mInFlightCommands.back().fence);
}
return fence;
}
angle::Result RendererVk::getTimestamp(vk::Context *context, uint64_t *timestampOut) angle::Result RendererVk::getTimestamp(vk::Context *context, uint64_t *timestampOut)
{ {
// The intent of this function is to query the timestamp without stalling the GPU. Currently, // The intent of this function is to query the timestamp without stalling the GPU. Currently,
......
...@@ -163,6 +163,7 @@ class RendererVk : angle::NonCopyable ...@@ -163,6 +163,7 @@ class RendererVk : angle::NonCopyable
// Get (or allocate) the fence that will be signaled on next submission. // Get (or allocate) the fence that will be signaled on next submission.
angle::Result getSubmitFence(vk::Context *context, vk::Shared<vk::Fence> *sharedFenceOut); angle::Result getSubmitFence(vk::Context *context, vk::Shared<vk::Fence> *sharedFenceOut);
vk::Shared<vk::Fence> getLastSubmittedFence() const;
// This should only be called from ResourceVk. // This should only be called from ResourceVk.
// TODO(jmadill): Keep in ContextVk to enable threaded rendering. // TODO(jmadill): Keep in ContextVk to enable threaded rendering.
......
...@@ -299,7 +299,7 @@ WindowSurfaceVk::SwapHistory::SwapHistory(SwapHistory &&other) ...@@ -299,7 +299,7 @@ WindowSurfaceVk::SwapHistory::SwapHistory(SwapHistory &&other)
WindowSurfaceVk::SwapHistory &WindowSurfaceVk::SwapHistory::operator=(SwapHistory &&other) WindowSurfaceVk::SwapHistory &WindowSurfaceVk::SwapHistory::operator=(SwapHistory &&other)
{ {
std::swap(serial, other.serial); std::swap(sharedFence, other.sharedFence);
std::swap(semaphores, other.semaphores); std::swap(semaphores, other.semaphores);
std::swap(swapchain, other.swapchain); std::swap(swapchain, other.swapchain);
return *this; return *this;
...@@ -315,6 +315,8 @@ void WindowSurfaceVk::SwapHistory::destroy(VkDevice device) ...@@ -315,6 +315,8 @@ void WindowSurfaceVk::SwapHistory::destroy(VkDevice device)
swapchain = VK_NULL_HANDLE; swapchain = VK_NULL_HANDLE;
} }
sharedFence.reset(device);
for (vk::Semaphore &semaphore : semaphores) for (vk::Semaphore &semaphore : semaphores)
{ {
semaphore.destroy(device); semaphore.destroy(device);
...@@ -322,6 +324,16 @@ void WindowSurfaceVk::SwapHistory::destroy(VkDevice device) ...@@ -322,6 +324,16 @@ void WindowSurfaceVk::SwapHistory::destroy(VkDevice device)
semaphores.clear(); semaphores.clear();
} }
angle::Result WindowSurfaceVk::SwapHistory::waitFence(DisplayVk *displayVk)
{
if (sharedFence.isReferenced())
{
ANGLE_VK_TRY(displayVk, sharedFence.get().wait(displayVk->getDevice(),
std::numeric_limits<uint64_t>::max()));
}
return angle::Result::Continue;
}
WindowSurfaceVk::WindowSurfaceVk(const egl::SurfaceState &surfaceState, WindowSurfaceVk::WindowSurfaceVk(const egl::SurfaceState &surfaceState,
EGLNativeWindowType window, EGLNativeWindowType window,
EGLint width, EGLint width,
...@@ -710,8 +722,8 @@ angle::Result WindowSurfaceVk::present(DisplayVk *displayVk, ...@@ -710,8 +722,8 @@ angle::Result WindowSurfaceVk::present(DisplayVk *displayVk,
SwapHistory &swap = mSwapHistory[mCurrentSwapHistoryIndex]; SwapHistory &swap = mSwapHistory[mCurrentSwapHistoryIndex];
{ {
TRACE_EVENT0("gpu.angle", "WindowSurfaceVk::present: Throttle CPU"); TRACE_EVENT0("gpu.angle", "WindowSurfaceVk::present: Throttle CPU");
ANGLE_TRY(renderer->finishToSerial(displayVk, swap.serial)); ANGLE_TRY(swap.waitFence(displayVk));
swap.destroy(renderer->getDevice()); swap.destroy(displayVk->getDevice());
} }
SwapchainImage &image = mSwapchainImages[mCurrentSwapchainImageIndex]; SwapchainImage &image = mSwapchainImages[mCurrentSwapchainImageIndex];
...@@ -776,7 +788,7 @@ angle::Result WindowSurfaceVk::present(DisplayVk *displayVk, ...@@ -776,7 +788,7 @@ angle::Result WindowSurfaceVk::present(DisplayVk *displayVk,
} }
// Update the swap history for this presentation // Update the swap history for this presentation
swap.serial = renderer->getLastSubmittedQueueSerial(); swap.sharedFence = renderer->getLastSubmittedFence();
swap.semaphores = std::move(mFlushSemaphoreChain); swap.semaphores = std::move(mFlushSemaphoreChain);
++mCurrentSwapHistoryIndex; ++mCurrentSwapHistoryIndex;
mCurrentSwapHistoryIndex = mCurrentSwapHistoryIndex =
......
...@@ -223,7 +223,11 @@ class WindowSurfaceVk : public SurfaceImpl ...@@ -223,7 +223,11 @@ class WindowSurfaceVk : public SurfaceImpl
void destroy(VkDevice device); void destroy(VkDevice device);
Serial serial; angle::Result waitFence(DisplayVk *displayVk);
// Fence associated with the last submitted work to render to this swapchain image.
vk::Shared<vk::Fence> sharedFence;
std::vector<vk::Semaphore> semaphores; std::vector<vk::Semaphore> semaphores;
VkSwapchainKHR swapchain = VK_NULL_HANDLE; VkSwapchainKHR swapchain = VK_NULL_HANDLE;
}; };
......
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