From 40e84f1f8fa962b6b19a402fedf75f1db4a73a6f Mon Sep 17 00:00:00 2001 From: Yiwei Zhang Date: Wed, 14 Oct 2020 08:42:26 -0700 Subject: Vulkan: load built-in driver into default namespace as a fallback There isn't sphal in vendor config because the default has the same access there. This change allows vendor processes to load Vulkan driver into the default namespace. Bug: 170258171 Test: Vulkan driver can be loaded into vendor processes Change-Id: If58493e6954e4e8d2309aaca392fcdffea9c6b9a --- vulkan/libvulkan/driver.cpp | 50 +++++++++++++++++++-------------------------- 1 file changed, 21 insertions(+), 29 deletions(-) (limited to 'vulkan/libvulkan/driver.cpp') diff --git a/vulkan/libvulkan/driver.cpp b/vulkan/libvulkan/driver.cpp index 4068a16d80..5c1d023ce9 100644 --- a/vulkan/libvulkan/driver.cpp +++ b/vulkan/libvulkan/driver.cpp @@ -28,20 +28,17 @@ #include #include #include -#include #include #include -#include #include #include #include +#include #include #include #include #include -#include -#include #include #include "stubhal.h" @@ -157,19 +154,11 @@ class CreateInfoWrapper { Hal Hal::hal_; -void* LoadLibrary(const android_dlextinfo& dlextinfo, - const std::string_view subname) { - ATRACE_CALL(); - - std::stringstream ss; - ss << "vulkan." << subname << ".so"; - return android_dlopen_ext(ss.str().c_str(), RTLD_LOCAL | RTLD_NOW, &dlextinfo); -} - const std::array HAL_SUBNAME_KEY_PROPERTIES = {{ "ro.hardware.vulkan", "ro.board.platform", }}; +constexpr int LIB_DL_FLAGS = RTLD_LOCAL | RTLD_NOW; // LoadDriver returns: // * 0 when succeed, or @@ -180,20 +169,26 @@ int LoadDriver(android_namespace_t* library_namespace, const hwvulkan_module_t** module) { ATRACE_CALL(); - const android_dlextinfo dlextinfo = { - .flags = ANDROID_DLEXT_USE_NAMESPACE, - .library_namespace = library_namespace, - }; void* so = nullptr; - char prop[PROPERTY_VALUE_MAX]; for (auto key : HAL_SUBNAME_KEY_PROPERTIES) { - int prop_len = property_get(key, prop, nullptr); - if (prop_len > 0 && prop_len <= UINT_MAX) { - std::string_view lib_name(prop, static_cast(prop_len)); - so = LoadLibrary(dlextinfo, lib_name); - if (so) - break; + std::string lib_name = android::base::GetProperty(key, ""); + if (lib_name.empty()) + continue; + + lib_name = "vulkan." + lib_name + ".so"; + if (library_namespace) { + // load updated driver + const android_dlextinfo dlextinfo = { + .flags = ANDROID_DLEXT_USE_NAMESPACE, + .library_namespace = library_namespace, + }; + so = android_dlopen_ext(lib_name.c_str(), LIB_DL_FLAGS, &dlextinfo); + } else { + // load built-in driver + so = android_load_sphal_library(lib_name.c_str(), LIB_DL_FLAGS); } + if (so) + break; } if (!so) return -ENOENT; @@ -217,12 +212,9 @@ int LoadDriver(android_namespace_t* library_namespace, int LoadBuiltinDriver(const hwvulkan_module_t** module) { ATRACE_CALL(); - auto ns = android_get_exported_namespace("sphal"); - if (!ns) - return -ENOENT; android::GraphicsEnv::getInstance().setDriverToLoad( android::GpuStatsInfo::Driver::VULKAN); - return LoadDriver(ns, module); + return LoadDriver(nullptr, module); } int LoadUpdatedDriver(const hwvulkan_module_t** module) { @@ -323,7 +315,7 @@ void Hal::UnloadBuiltinDriver() { "hw_device_t::close() failed."); // Close the opened shared library in the hw_module_t - dlclose(hal_.dev_->common.module->dso); + android_unload_sphal_library(hal_.dev_->common.module->dso); hal_.dev_ = nullptr; hal_.debug_report_index_ = -1; -- cgit v1.2.3-59-g8ed1b