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

Commit 22f7f68e authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Vulkan: load built-in driver into default namespace as a fallback"

parents 64f45cf2 40e84f1f
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -89,7 +89,6 @@ cc_library_shared {
        "libhardware",
        "libhardware",
        "libsync",
        "libsync",
        "libbase",
        "libbase",
        "libdl_android",
        "libhidlbase",
        "libhidlbase",
        "liblog",
        "liblog",
        "libui",
        "libui",
@@ -100,6 +99,7 @@ cc_library_shared {
        "libnativebridge_lazy",
        "libnativebridge_lazy",
        "libnativeloader_lazy",
        "libnativeloader_lazy",
        "libnativewindow",
        "libnativewindow",
        "libvndksupport",
        "android.hardware.graphics.common@1.0",
        "android.hardware.graphics.common@1.0",
        "libSurfaceFlingerProp",
        "libSurfaceFlingerProp",
    ],
    ],
+21 −29
Original line number Original line Diff line number Diff line
@@ -28,20 +28,17 @@
#include <android/dlext.h>
#include <android/dlext.h>
#include <android/hardware/configstore/1.0/ISurfaceFlingerConfigs.h>
#include <android/hardware/configstore/1.0/ISurfaceFlingerConfigs.h>
#include <configstore/Utils.h>
#include <configstore/Utils.h>
#include <cutils/properties.h>
#include <graphicsenv/GraphicsEnv.h>
#include <graphicsenv/GraphicsEnv.h>
#include <log/log.h>
#include <log/log.h>
#include <nativeloader/dlext_namespaces.h>
#include <sys/prctl.h>
#include <sys/prctl.h>
#include <utils/Timers.h>
#include <utils/Timers.h>
#include <utils/Trace.h>
#include <utils/Trace.h>
#include <vndksupport/linker.h>


#include <algorithm>
#include <algorithm>
#include <array>
#include <array>
#include <climits>
#include <climits>
#include <new>
#include <new>
#include <string_view>
#include <sstream>
#include <vector>
#include <vector>


#include "stubhal.h"
#include "stubhal.h"
@@ -157,19 +154,11 @@ class CreateInfoWrapper {


Hal Hal::hal_;
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<const char*, 2> HAL_SUBNAME_KEY_PROPERTIES = {{
const std::array<const char*, 2> HAL_SUBNAME_KEY_PROPERTIES = {{
    "ro.hardware.vulkan",
    "ro.hardware.vulkan",
    "ro.board.platform",
    "ro.board.platform",
}};
}};
constexpr int LIB_DL_FLAGS = RTLD_LOCAL | RTLD_NOW;


// LoadDriver returns:
// LoadDriver returns:
// * 0 when succeed, or
// * 0 when succeed, or
@@ -180,21 +169,27 @@ int LoadDriver(android_namespace_t* library_namespace,
               const hwvulkan_module_t** module) {
               const hwvulkan_module_t** module) {
    ATRACE_CALL();
    ATRACE_CALL();


    void* so = nullptr;
    for (auto key : HAL_SUBNAME_KEY_PROPERTIES) {
        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 = {
            const android_dlextinfo dlextinfo = {
                .flags = ANDROID_DLEXT_USE_NAMESPACE,
                .flags = ANDROID_DLEXT_USE_NAMESPACE,
                .library_namespace = library_namespace,
                .library_namespace = library_namespace,
            };
            };
    void* so = nullptr;
            so = android_dlopen_ext(lib_name.c_str(), LIB_DL_FLAGS, &dlextinfo);
    char prop[PROPERTY_VALUE_MAX];
        } else {
    for (auto key : HAL_SUBNAME_KEY_PROPERTIES) {
            // load built-in driver
        int prop_len = property_get(key, prop, nullptr);
            so = android_load_sphal_library(lib_name.c_str(), LIB_DL_FLAGS);
        if (prop_len > 0 && prop_len <= UINT_MAX) {
        }
            std::string_view lib_name(prop, static_cast<unsigned int>(prop_len));
            so = LoadLibrary(dlextinfo, lib_name);
        if (so)
        if (so)
            break;
            break;
    }
    }
    }
    if (!so)
    if (!so)
        return -ENOENT;
        return -ENOENT;


@@ -217,12 +212,9 @@ int LoadDriver(android_namespace_t* library_namespace,
int LoadBuiltinDriver(const hwvulkan_module_t** module) {
int LoadBuiltinDriver(const hwvulkan_module_t** module) {
    ATRACE_CALL();
    ATRACE_CALL();


    auto ns = android_get_exported_namespace("sphal");
    if (!ns)
        return -ENOENT;
    android::GraphicsEnv::getInstance().setDriverToLoad(
    android::GraphicsEnv::getInstance().setDriverToLoad(
        android::GpuStatsInfo::Driver::VULKAN);
        android::GpuStatsInfo::Driver::VULKAN);
    return LoadDriver(ns, module);
    return LoadDriver(nullptr, module);
}
}


int LoadUpdatedDriver(const hwvulkan_module_t** module) {
int LoadUpdatedDriver(const hwvulkan_module_t** module) {
@@ -323,7 +315,7 @@ void Hal::UnloadBuiltinDriver() {
                "hw_device_t::close() failed.");
                "hw_device_t::close() failed.");


    // Close the opened shared library in the hw_module_t
    // 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_.dev_ = nullptr;
    hal_.debug_report_index_ = -1;
    hal_.debug_report_index_ = -1;