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 <jmadill@chromium.org>
Reviewed-by: Tim Van Patten <timvp@google.com>
Commit-Queue: Courtney Goeltzenleuchter <courtneygo@google.com>
This commit is contained in:
Courtney Goeltzenleuchter 2020-09-17 08:27:04 -06:00 коммит произвёл Commit Bot
Родитель 512059a99c
Коммит 3c64fe30ca
2 изменённых файлов: 20 добавлений и 7 удалений

Просмотреть файл

@ -512,7 +512,10 @@ void RendererVk::onDestroy()
mOneOffCommandPool.destroy(mDevice); mOneOffCommandPool.destroy(mDevice);
mFenceRecycler.destroy(mDevice); {
std::lock_guard<std::mutex> lock(mFenceRecyclerMutex);
mFenceRecycler.destroy(mDevice);
}
mPipelineLayoutCache.destroy(mDevice); mPipelineLayoutCache.destroy(mDevice);
mDescriptorSetLayoutCache.destroy(mDevice); mDescriptorSetLayoutCache.destroy(mDevice);
@ -2205,19 +2208,27 @@ VkResult RendererVk::queuePresent(egl::ContextPriority priority,
angle::Result RendererVk::newSharedFence(vk::Context *context, angle::Result RendererVk::newSharedFence(vk::Context *context,
vk::Shared<vk::Fence> *sharedFenceOut) vk::Shared<vk::Fence> *sharedFenceOut)
{ {
bool gotRecycledFence = false;
vk::Fence fence; vk::Fence fence;
if (mFenceRecycler.empty()) {
std::lock_guard<std::mutex> lock(mFenceRecyclerMutex);
if (!mFenceRecycler.empty())
{
mFenceRecycler.fetch(&fence);
gotRecycledFence = true;
}
}
if (gotRecycledFence)
{
ANGLE_VK_TRY(context, fence.reset(mDevice));
}
else
{ {
VkFenceCreateInfo fenceCreateInfo = {}; VkFenceCreateInfo fenceCreateInfo = {};
fenceCreateInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; fenceCreateInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
fenceCreateInfo.flags = 0; fenceCreateInfo.flags = 0;
ANGLE_VK_TRY(context, fence.init(mDevice, fenceCreateInfo)); 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)); sharedFenceOut->assign(mDevice, std::move(fence));
return angle::Result::Continue; return angle::Result::Continue;
} }

Просмотреть файл

@ -200,6 +200,7 @@ class RendererVk : angle::NonCopyable
angle::Result newSharedFence(vk::Context *context, vk::Shared<vk::Fence> *sharedFenceOut); angle::Result newSharedFence(vk::Context *context, vk::Shared<vk::Fence> *sharedFenceOut);
inline void resetSharedFence(vk::Shared<vk::Fence> *sharedFenceIn) inline void resetSharedFence(vk::Shared<vk::Fence> *sharedFenceIn)
{ {
std::lock_guard<std::mutex> lock(mFenceRecyclerMutex);
sharedFenceIn->resetAndRecycle(&mFenceRecycler); sharedFenceIn->resetAndRecycle(&mFenceRecycler);
} }
@ -336,6 +337,7 @@ class RendererVk : angle::NonCopyable
bool mDeviceLost; bool mDeviceLost;
std::mutex mFenceRecyclerMutex;
vk::Recycler<vk::Fence> mFenceRecycler; vk::Recycler<vk::Fence> mFenceRecycler;
std::mutex mGarbageMutex; std::mutex mGarbageMutex;