[Impeller] remove Vulkan pipeline cache mutex. (#43085)
At least from what I've found online, this API is already safe to call from multiple threads. From testing, at startup the presence of the mutex is adding ~100ms to shader creation time, as all compilations across N threads are fighting for the same lock.
https://github.com/flutter/flutter/issues/129050
diff --git a/impeller/renderer/backend/vulkan/pipeline_cache_vk.cc b/impeller/renderer/backend/vulkan/pipeline_cache_vk.cc
index 8c40f6a..8220d1d 100644
--- a/impeller/renderer/backend/vulkan/pipeline_cache_vk.cc
+++ b/impeller/renderer/backend/vulkan/pipeline_cache_vk.cc
@@ -68,13 +68,6 @@
OpenCacheFile(cache_directory_, kPipelineCacheFileName, vk_caps);
vk::PipelineCacheCreateInfo cache_info;
-
- // TODO(csg): VK_PIPELINE_CACHE_CREATE_EXTERNALLY_SYNCHRONIZED_BIT is behind
- // an extension. Check it and set it. If not, the implementation is doing
- // unnecessary synchronization.
- // cache_info.flags =
- // vk::PipelineCacheCreateFlagBits::eExternallySynchronized;
-
if (existing_cache_data) {
cache_info.initialDataSize = existing_cache_data->GetSize();
cache_info.pInitialData = existing_cache_data->GetMapping();
@@ -126,7 +119,6 @@
return {};
}
- Lock lock(cache_mutex_);
auto [result, pipeline] =
strong_device->GetDevice().createGraphicsPipelineUnique(*cache_, info);
if (result != vk::Result::eSuccess) {
@@ -143,7 +135,6 @@
return {};
}
- Lock lock(cache_mutex_);
auto [result, pipeline] =
strong_device->GetDevice().createComputePipelineUnique(*cache_, info);
if (result != vk::Result::eSuccess) {
@@ -162,7 +153,6 @@
if (!IsValid()) {
return nullptr;
}
- Lock lock(cache_mutex_);
auto [result, data] =
strong_device->GetDevice().getPipelineCacheData(*cache_);
if (result != vk::Result::eSuccess) {
diff --git a/impeller/renderer/backend/vulkan/pipeline_cache_vk.h b/impeller/renderer/backend/vulkan/pipeline_cache_vk.h
index fdcb8a9..519ad7c 100644
--- a/impeller/renderer/backend/vulkan/pipeline_cache_vk.h
+++ b/impeller/renderer/backend/vulkan/pipeline_cache_vk.h
@@ -37,8 +37,7 @@
const std::shared_ptr<const Capabilities> caps_;
std::weak_ptr<DeviceHolder> device_holder_;
const fml::UniqueFD cache_directory_;
- mutable Mutex cache_mutex_;
- vk::UniquePipelineCache cache_ IPLR_GUARDED_BY(cache_mutex_);
+ vk::UniquePipelineCache cache_;
bool is_valid_ = false;
std::shared_ptr<fml::Mapping> CopyPipelineCacheData() const;