From 901f8ee258dbfff2090dc45badf3446266f0ae16 Mon Sep 17 00:00:00 2001 From: Yiwei Zhang Date: Fri, 31 Jul 2020 13:18:49 -0700 Subject: Vulkan: unload builtin driver to reload updated driver if needed Android historically preloads GL driver in Zygote to speed up app launch time and avoid the duplicate extra memory for each process loading the graphics driver. In Android 10, we landed GL driver unloading mechanism to ship updatable driver and ANGLE without perf overhead on the rest of the system. To get prepared for the HWUI Vulkan backend being turned on as the default renderer for UI componments, this CL will do the same to the Vulkan driver to preload it in Zygote and unload so to reload updated driver if needed. Bug: 135536511 Test: atest CtsUiRenderingTestCases no regression on VK backend Change-Id: I2909f6ecc4f011b1f3670aacdf817ed3b6e9a487 --- vulkan/libvulkan/api.cpp | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) (limited to 'vulkan/libvulkan/api.cpp') diff --git a/vulkan/libvulkan/api.cpp b/vulkan/libvulkan/api.cpp index 80166c8434..2d4690a2af 100644 --- a/vulkan/libvulkan/api.cpp +++ b/vulkan/libvulkan/api.cpp @@ -1174,23 +1174,18 @@ const LayerChain::ActiveLayer* LayerChain::GetActiveLayers( // ---------------------------------------------------------------------------- bool EnsureInitialized() { - static std::once_flag once_flag; - static bool initialized; - - std::call_once(once_flag, []() { - if (driver::OpenHAL()) { - initialized = true; - } - }); - - { - static pid_t pid = getpid() + 1; - static std::mutex layer_lock; - std::lock_guard lock(layer_lock); - if (pid != getpid()) { - pid = getpid(); - DiscoverLayers(); - } + static bool initialized = false; + static pid_t init_attempted_for_pid = 0; + static std::mutex init_lock; + + std::lock_guard lock(init_lock); + if (init_attempted_for_pid == getpid()) + return initialized; + + init_attempted_for_pid = getpid(); + if (driver::OpenHAL()) { + DiscoverLayers(); + initialized = true; } return initialized; -- cgit v1.2.3-59-g8ed1b