Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a4f2d92c authored by Jooyung Han's avatar Jooyung Han Committed by Gerrit Code Review
Browse files

Merge "Load vulkan driver from an apex when ro.vulkan.apex is set" into main

parents 8f331666 749b0eca
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -109,6 +109,7 @@ cc_library_shared {
        "libnativeloader_lazy",
        "libnativewindow",
        "libvndksupport",
        "libdl_android",
        "android.hardware.graphics.common@1.0",
        "libSurfaceFlingerProp",
    ],
+29 −6
Original line number Diff line number Diff line
@@ -46,6 +46,8 @@
using namespace android::hardware::configstore;
using namespace android::hardware::configstore::V1_0;

extern "C" android_namespace_t* android_get_exported_namespace(const char*);

// #define ENABLE_ALLOC_CALLSTACKS 1
#if ENABLE_ALLOC_CALLSTACKS
#include <utils/CallStack.h>
@@ -159,6 +161,7 @@ const std::array<const char*, 2> HAL_SUBNAME_KEY_PROPERTIES = {{
    "ro.board.platform",
}};
constexpr int LIB_DL_FLAGS = RTLD_LOCAL | RTLD_NOW;
constexpr char RO_VULKAN_APEX_PROPERTY[] = "ro.vulkan.apex";

// LoadDriver returns:
// * 0 when succeed, or
@@ -166,6 +169,7 @@ constexpr int LIB_DL_FLAGS = RTLD_LOCAL | RTLD_NOW;
// * -EINVAL when fail to find HAL_MODULE_INFO_SYM_AS_STR or
//   HWVULKAN_HARDWARE_MODULE_ID in the library.
int LoadDriver(android_namespace_t* library_namespace,
               const char* ns_name,
               const hwvulkan_module_t** module) {
    ATRACE_CALL();

@@ -184,10 +188,8 @@ int LoadDriver(android_namespace_t* library_namespace,
            };
            so = android_dlopen_ext(lib_name.c_str(), LIB_DL_FLAGS, &dlextinfo);
            if (!so) {
                ALOGE(
                    "Could not load %s from updatable gfx driver namespace: "
                    "%s.",
                    lib_name.c_str(), dlerror());
                ALOGE("Could not load %s from %s namespace: %s.",
                      lib_name.c_str(), ns_name, dlerror());
            }
        } else {
            // load built-in driver
@@ -215,12 +217,30 @@ int LoadDriver(android_namespace_t* library_namespace,
    return 0;
}

int LoadDriverFromApex(const hwvulkan_module_t** module) {
    ATRACE_CALL();

    auto apex_name = android::base::GetProperty(RO_VULKAN_APEX_PROPERTY, "");
    if (apex_name == "") {
        return -ENOENT;
    }
    // Get linker namespace for Vulkan APEX
    std::replace(apex_name.begin(), apex_name.end(), '.', '_');
    auto ns = android_get_exported_namespace(apex_name.c_str());
    if (!ns) {
        return -ENOENT;
    }
    android::GraphicsEnv::getInstance().setDriverToLoad(
        android::GpuStatsInfo::Driver::VULKAN);
    return LoadDriver(ns, apex_name.c_str(), module);
}

int LoadBuiltinDriver(const hwvulkan_module_t** module) {
    ATRACE_CALL();

    android::GraphicsEnv::getInstance().setDriverToLoad(
        android::GpuStatsInfo::Driver::VULKAN);
    return LoadDriver(nullptr, module);
    return LoadDriver(nullptr, nullptr, module);
}

int LoadUpdatedDriver(const hwvulkan_module_t** module) {
@@ -231,7 +251,7 @@ int LoadUpdatedDriver(const hwvulkan_module_t** module) {
        return -ENOENT;
    android::GraphicsEnv::getInstance().setDriverToLoad(
        android::GpuStatsInfo::Driver::VULKAN_UPDATED);
    int result = LoadDriver(ns, module);
    int result = LoadDriver(ns, "updatable gfx driver", module);
    if (result != 0) {
        LOG_ALWAYS_FATAL(
            "couldn't find an updated Vulkan implementation from %s",
@@ -259,6 +279,9 @@ bool Hal::Open() {
    const hwvulkan_module_t* module = nullptr;

    result = LoadUpdatedDriver(&module);
    if (result == -ENOENT) {
        result = LoadDriverFromApex(&module);
    }
    if (result == -ENOENT) {
        result = LoadBuiltinDriver(&module);
    }