diff options
Diffstat (limited to 'vulkan/libvulkan/api.cpp')
-rw-r--r-- | vulkan/libvulkan/api.cpp | 92 |
1 files changed, 41 insertions, 51 deletions
diff --git a/vulkan/libvulkan/api.cpp b/vulkan/libvulkan/api.cpp index d1cd397da4..5b9affd03a 100644 --- a/vulkan/libvulkan/api.cpp +++ b/vulkan/libvulkan/api.cpp @@ -33,7 +33,6 @@ #include <unordered_set> #include <utility> -#include <android-base/properties.h> #include <android-base/strings.h> #include <cutils/properties.h> #include <log/log.h> @@ -135,7 +134,7 @@ class OverrideLayerNames { // If no layers specified via Settings, check legacy properties if (implicit_layers_.count <= 0) { ParseDebugVulkanLayers(); - ParseDebugVulkanLayer(); + property_list(ParseDebugVulkanLayer, this); // sort by priorities auto& arr = implicit_layers_; @@ -182,39 +181,30 @@ class OverrideLayerNames { AddImplicitLayer(prio, p, strlen(p)); } - void ParseDebugVulkanLayer() { - // Checks for consecutive debug.vulkan.layer.<priority> system - // properties after always checking an initial fixed range. + static void ParseDebugVulkanLayer(const char* key, + const char* val, + void* user_data) { static const char prefix[] = "debug.vulkan.layer."; - static constexpr int kFixedRangeBeginInclusive = 0; - static constexpr int kFixedRangeEndInclusive = 9; - - bool logged = false; - - int priority = kFixedRangeBeginInclusive; - while (true) { - const std::string prop_key = - std::string(prefix) + std::to_string(priority); - const std::string prop_val = - android::base::GetProperty(prop_key, ""); - - if (!prop_val.empty()) { - if (!logged) { - ALOGI( - "Detected Vulkan layers configured with " - "debug.vulkan.layer.<priority>. Checking for " - "debug.vulkan.layer.<priority> in the range [%d, %d] " - "followed by a consecutive scan.", - kFixedRangeBeginInclusive, kFixedRangeEndInclusive); - logged = true; - } - AddImplicitLayer(priority, prop_val.c_str(), prop_val.length()); - } else if (priority >= kFixedRangeEndInclusive) { - return; - } + const size_t prefix_len = sizeof(prefix) - 1; + + if (strncmp(key, prefix, prefix_len) || val[0] == '\0') + return; + key += prefix_len; + + // debug.vulkan.layer.<priority> + int priority = -1; + if (key[0] >= '0' && key[0] <= '9') + priority = atoi(key); - ++priority; + if (priority < 0) { + ALOGW("Ignored implicit layer %s with invalid priority %s", val, + key); + return; } + + OverrideLayerNames& override_layers = + *reinterpret_cast<OverrideLayerNames*>(user_data); + override_layers.AddImplicitLayer(priority, val, strlen(val)); } void AddImplicitLayer(int priority, const char* name, size_t len) { @@ -1184,18 +1174,23 @@ const LayerChain::ActiveLayer* LayerChain::GetActiveLayers( // ---------------------------------------------------------------------------- bool EnsureInitialized() { - static bool initialized = false; - static pid_t init_attempted_for_pid = 0; - static std::mutex init_lock; - - std::lock_guard<std::mutex> lock(init_lock); - if (init_attempted_for_pid == getpid()) - return initialized; - - init_attempted_for_pid = getpid(); - if (driver::OpenHAL()) { - DiscoverLayers(); - initialized = true; + 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<std::mutex> lock(layer_lock); + if (pid != getpid()) { + pid = getpid(); + DiscoverLayers(); + } } return initialized; @@ -1261,7 +1256,7 @@ VkResult EnumerateInstanceLayerProperties(uint32_t* pPropertyCount, ATRACE_CALL(); if (!EnsureInitialized()) - return VK_ERROR_OUT_OF_HOST_MEMORY; + return VK_ERROR_INITIALIZATION_FAILED; uint32_t count = GetLayerCount(); @@ -1285,7 +1280,7 @@ VkResult EnumerateInstanceExtensionProperties( ATRACE_CALL(); if (!EnsureInitialized()) - return VK_ERROR_OUT_OF_HOST_MEMORY; + return VK_ERROR_INITIALIZATION_FAILED; if (pLayerName) { const Layer* layer = FindLayer(pLayerName); @@ -1461,11 +1456,6 @@ VkResult EnumerateDeviceExtensionProperties( VkResult EnumerateInstanceVersion(uint32_t* pApiVersion) { ATRACE_CALL(); - // Load the driver here if not done yet. This api will be used in Zygote - // for Vulkan driver pre-loading because of the minimum overhead. - if (!EnsureInitialized()) - return VK_ERROR_OUT_OF_HOST_MEMORY; - *pApiVersion = VK_API_VERSION_1_1; return VK_SUCCESS; } |