diff options
| -rw-r--r-- | libs/hwui/renderthread/VulkanManager.cpp | 28 | ||||
| -rw-r--r-- | libs/hwui/renderthread/VulkanManager.h | 5 |
2 files changed, 16 insertions, 17 deletions
diff --git a/libs/hwui/renderthread/VulkanManager.cpp b/libs/hwui/renderthread/VulkanManager.cpp index a6e8c08ffbe8..e2b541aa5ecb 100644 --- a/libs/hwui/renderthread/VulkanManager.cpp +++ b/libs/hwui/renderthread/VulkanManager.cpp @@ -384,25 +384,23 @@ void VulkanManager::setupDevice(GrVkExtensions& grExtensions, VkPhysicalDeviceFe } void VulkanManager::initialize() { - std::lock_guard _lock{mInitializeLock}; + std::call_once(mInitFlag, [&] { + GET_PROC(EnumerateInstanceVersion); + uint32_t instanceVersion; + LOG_ALWAYS_FATAL_IF(mEnumerateInstanceVersion(&instanceVersion)); + LOG_ALWAYS_FATAL_IF(instanceVersion < VK_MAKE_VERSION(1, 1, 0)); - if (mDevice != VK_NULL_HANDLE) { - return; - } - - GET_PROC(EnumerateInstanceVersion); - uint32_t instanceVersion; - LOG_ALWAYS_FATAL_IF(mEnumerateInstanceVersion(&instanceVersion)); - LOG_ALWAYS_FATAL_IF(instanceVersion < VK_MAKE_VERSION(1, 1, 0)); + this->setupDevice(mExtensions, mPhysicalDeviceFeatures2); - this->setupDevice(mExtensions, mPhysicalDeviceFeatures2); + mGetDeviceQueue(mDevice, mGraphicsQueueIndex, 0, &mGraphicsQueue); + mGetDeviceQueue(mDevice, mGraphicsQueueIndex, 1, &mAHBUploadQueue); - mGetDeviceQueue(mDevice, mGraphicsQueueIndex, 0, &mGraphicsQueue); - mGetDeviceQueue(mDevice, mGraphicsQueueIndex, 1, &mAHBUploadQueue); + if (Properties::enablePartialUpdates && Properties::useBufferAge) { + mSwapBehavior = SwapBehavior::BufferAge; + } - if (Properties::enablePartialUpdates && Properties::useBufferAge) { - mSwapBehavior = SwapBehavior::BufferAge; - } + mInitialized = true; + }); } static void onGrContextReleased(void* context) { diff --git a/libs/hwui/renderthread/VulkanManager.h b/libs/hwui/renderthread/VulkanManager.h index 2be1ffdbc423..dbef7fbd51b2 100644 --- a/libs/hwui/renderthread/VulkanManager.h +++ b/libs/hwui/renderthread/VulkanManager.h @@ -70,7 +70,7 @@ public: void initialize(); // Quick check to see if the VulkanManager has been initialized. - bool hasVkContext() { return mDevice != VK_NULL_HANDLE; } + bool hasVkContext() { return mInitialized; } // Create and destroy functions for wrapping an ANativeWindow in a VulkanSurface VulkanSurface* createSurface(ANativeWindow* window, @@ -204,7 +204,8 @@ private: VkSemaphore mSwapSemaphore = VK_NULL_HANDLE; void* mDestroySemaphoreContext = nullptr; - std::mutex mInitializeLock; + std::once_flag mInitFlag; + std::atomic_bool mInitialized = false; }; } /* namespace renderthread */ |