Commit 6939a023 by Jamie Madill Committed by Commit Bot

Vulkan: Fix racy access to VkPipelineCache.

Use a mutex to guard against the object init. The accesses to the cache internals are internally synchronized. There is a Vulkan ext that allows for external cache synchronization that we could investigate at some point. Detected by looking at MultithreadingTest with TSAN enabled. Bug: b/168744561 Change-Id: I1d4744e1aa970bcd57cac49f7ecaf8c238ea61c2 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2415183 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarCourtney Goeltzenleuchter <courtneygo@google.com>
parent f2749096
......@@ -1918,6 +1918,11 @@ angle::Result RendererVk::initPipelineCache(DisplayVk *display,
angle::Result RendererVk::getPipelineCache(vk::PipelineCache **pipelineCache)
{
// Note that unless external synchronization is specifically requested the pipeline cache
// is internally synchronized. See VK_EXT_pipeline_creation_cache_control. We might want
// to investigate controlling synchronization manually in ANGLE at some point for perf.
std::lock_guard<std::mutex> lock(mPipelineCacheMutex);
if (mPipelineCacheInitialized)
{
*pipelineCache = &mPipelineCache;
......
......@@ -233,7 +233,11 @@ class RendererVk : angle::NonCopyable
using ExtensionNameList = angle::FixedVector<const char *, kMaxExtensionNames>;
angle::Result getPipelineCache(vk::PipelineCache **pipelineCache);
void onNewGraphicsPipeline() { mPipelineCacheDirty = true; }
void onNewGraphicsPipeline()
{
std::lock_guard<std::mutex> lock(mPipelineCacheMutex);
mPipelineCacheDirty = true;
}
void onNewValidationMessage(const std::string &message);
std::string getAndClearLastValidationMessage(uint32_t *countSinceLastClear);
......@@ -342,6 +346,7 @@ class RendererVk : angle::NonCopyable
// All access to the pipeline cache is done through EGL objects so it is thread safe to not use
// a lock.
std::mutex mPipelineCacheMutex;
vk::PipelineCache mPipelineCache;
egl::BlobCache::Key mPipelineCacheVkBlobKey;
uint32_t mPipelineCacheVkUpdateTimeout;
......
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