From 3c64fe30ca6abd82bfe8f478867de0b31181efdc Mon Sep 17 00:00:00 2001 From: Courtney Goeltzenleuchter Date: Thu, 17 Sep 2020 08:27:04 -0600 Subject: [PATCH] Vulkan: need to serialize access to mFenceRecycler It's possible for multiple threads to touch mFenceRecycler so need to protect it with a mutex to prevent race conditions. Bug: b/168744476 Change-Id: I9898d2e9ebf0974581a1074cbda5be41a09cd790 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2415401 Reviewed-by: Jamie Madill Reviewed-by: Tim Van Patten Commit-Queue: Courtney Goeltzenleuchter --- src/libANGLE/renderer/vulkan/RendererVk.cpp | 25 +++++++++++++++------ src/libANGLE/renderer/vulkan/RendererVk.h | 2 ++ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/libANGLE/renderer/vulkan/RendererVk.cpp b/src/libANGLE/renderer/vulkan/RendererVk.cpp index ed676eb2d..643bc3bd9 100644 --- a/src/libANGLE/renderer/vulkan/RendererVk.cpp +++ b/src/libANGLE/renderer/vulkan/RendererVk.cpp @@ -512,7 +512,10 @@ void RendererVk::onDestroy() mOneOffCommandPool.destroy(mDevice); - mFenceRecycler.destroy(mDevice); + { + std::lock_guard lock(mFenceRecyclerMutex); + mFenceRecycler.destroy(mDevice); + } mPipelineLayoutCache.destroy(mDevice); mDescriptorSetLayoutCache.destroy(mDevice); @@ -2205,19 +2208,27 @@ VkResult RendererVk::queuePresent(egl::ContextPriority priority, angle::Result RendererVk::newSharedFence(vk::Context *context, vk::Shared *sharedFenceOut) { + bool gotRecycledFence = false; vk::Fence fence; - if (mFenceRecycler.empty()) + { + std::lock_guard lock(mFenceRecyclerMutex); + if (!mFenceRecycler.empty()) + { + mFenceRecycler.fetch(&fence); + gotRecycledFence = true; + } + } + if (gotRecycledFence) + { + ANGLE_VK_TRY(context, fence.reset(mDevice)); + } + else { VkFenceCreateInfo fenceCreateInfo = {}; fenceCreateInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; fenceCreateInfo.flags = 0; ANGLE_VK_TRY(context, fence.init(mDevice, fenceCreateInfo)); } - else - { - mFenceRecycler.fetch(&fence); - ANGLE_VK_TRY(context, fence.reset(mDevice)); - } sharedFenceOut->assign(mDevice, std::move(fence)); return angle::Result::Continue; } diff --git a/src/libANGLE/renderer/vulkan/RendererVk.h b/src/libANGLE/renderer/vulkan/RendererVk.h index 46e66252a..e86c95054 100644 --- a/src/libANGLE/renderer/vulkan/RendererVk.h +++ b/src/libANGLE/renderer/vulkan/RendererVk.h @@ -200,6 +200,7 @@ class RendererVk : angle::NonCopyable angle::Result newSharedFence(vk::Context *context, vk::Shared *sharedFenceOut); inline void resetSharedFence(vk::Shared *sharedFenceIn) { + std::lock_guard lock(mFenceRecyclerMutex); sharedFenceIn->resetAndRecycle(&mFenceRecycler); } @@ -336,6 +337,7 @@ class RendererVk : angle::NonCopyable bool mDeviceLost; + std::mutex mFenceRecyclerMutex; vk::Recycler mFenceRecycler; std::mutex mGarbageMutex;