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

Commit 136b8eb3 authored by Chia-I Wu's avatar Chia-I Wu
Browse files

vulkan: move driver::OpenHAL

Move it from loader.cpp to driver.cpp.  HAL loading is now done in
driver.cpp while HAL extension queries are still done in loader.cpp.

Change-Id: I15d7ead98497adacb1bd798522f057ff6bf16909
parent 9d518161
Loading
Loading
Loading
Loading
+39 −0
Original line number Diff line number Diff line
@@ -17,13 +17,52 @@
#include <sys/prctl.h>

#include "driver.h"
#include "loader.h"

namespace vulkan {
namespace driver {

namespace {

hwvulkan_device_t* g_hwdevice = nullptr;

}  // anonymous namespace

bool Debuggable() {
    return (prctl(PR_GET_DUMPABLE, 0, 0, 0, 0) >= 0);
}

bool OpenHAL() {
    if (g_hwdevice)
        return true;

    const hwvulkan_module_t* module;
    int result =
        hw_get_module("vulkan", reinterpret_cast<const hw_module_t**>(&module));
    if (result != 0) {
        ALOGE("failed to load vulkan hal: %s (%d)", strerror(-result), result);
        return false;
    }

    hwvulkan_device_t* device;
    result =
        module->common.methods->open(&module->common, HWVULKAN_DEVICE_0,
                                     reinterpret_cast<hw_device_t**>(&device));
    if (result != 0) {
        ALOGE("failed to open vulkan driver: %s (%d)", strerror(-result),
              result);
        return false;
    }

    if (!InitLoader(device)) {
        device->common.close(&device->common);
        return false;
    }

    g_hwdevice = device;

    return true;
}

}  // namespace driver
}  // namespace vulkan
+13 −31
Original line number Diff line number Diff line
@@ -178,34 +178,14 @@ const VkAllocationCallbacks kDefaultAllocCallbacks = {
hwvulkan_device_t* g_hwdevice = nullptr;
InstanceExtensionSet g_driver_instance_extensions;

void LoadVulkanHAL() {
    static const hwvulkan_module_t* module;
    int result =
        hw_get_module("vulkan", reinterpret_cast<const hw_module_t**>(&module));
    if (result != 0) {
        ALOGE("failed to load vulkan hal: %s (%d)", strerror(-result), result);
        return;
    }
    result = module->common.methods->open(
        &module->common, HWVULKAN_DEVICE_0,
        reinterpret_cast<hw_device_t**>(&g_hwdevice));
    if (result != 0) {
        ALOGE("failed to open vulkan driver: %s (%d)", strerror(-result),
              result);
        module = nullptr;
        return;
    }

bool LoadVulkanHAL() {
    VkResult vkresult;
    uint32_t count;
    if ((vkresult = g_hwdevice->EnumerateInstanceExtensionProperties(
             nullptr, &count, nullptr)) != VK_SUCCESS) {
        ALOGE("driver EnumerateInstanceExtensionProperties failed: %d",
              vkresult);
        g_hwdevice->common.close(&g_hwdevice->common);
        g_hwdevice = nullptr;
        module = nullptr;
        return;
        return false;
    }
    VkExtensionProperties* extensions = static_cast<VkExtensionProperties*>(
        alloca(count * sizeof(VkExtensionProperties)));
@@ -213,10 +193,7 @@ void LoadVulkanHAL() {
             nullptr, &count, extensions)) != VK_SUCCESS) {
        ALOGE("driver EnumerateInstanceExtensionProperties failed: %d",
              vkresult);
        g_hwdevice->common.close(&g_hwdevice->common);
        g_hwdevice = nullptr;
        module = nullptr;
        return;
        return false;
    }
    ALOGV_IF(count > 0, "Driver-supported instance extensions:");
    for (uint32_t i = 0; i < count; i++) {
@@ -230,6 +207,8 @@ void LoadVulkanHAL() {
    // Ignore driver attempts to support loader extensions
    g_driver_instance_extensions.reset(kKHR_surface);
    g_driver_instance_extensions.reset(kKHR_android_surface);

    return true;
}

// -----------------------------------------------------------------------------
@@ -986,15 +965,18 @@ DebugReportCallbackList& GetDebugReportCallbacks(VkInstance instance) {
    return GetDispatchParent(instance).debug_report_callbacks;
}

namespace driver {

bool OpenHAL() {
    if (!g_hwdevice)
        LoadVulkanHAL();
bool InitLoader(hwvulkan_device_t* dev) {
    if (!g_hwdevice) {
        g_hwdevice = dev;
        if (!LoadVulkanHAL())
            g_hwdevice = nullptr;
    }

    return (g_hwdevice != nullptr);
}

namespace driver {

const VkAllocationCallbacks& GetDefaultAllocator() {
    return kDefaultAllocCallbacks;
}
+4 −0
Original line number Diff line number Diff line
@@ -21,6 +21,8 @@
#include "dispatch_gen.h"
#include "debug_report.h"

struct hwvulkan_device_t;

namespace vulkan {

enum InstanceExtension {
@@ -50,6 +52,8 @@ bool LoadDriverDispatchTable(VkInstance instance,
// -----------------------------------------------------------------------------
// loader.cpp

bool InitLoader(hwvulkan_device_t* dev);

// clang-format off
VKAPI_ATTR VkResult CreateInstance_Bottom(const VkInstanceCreateInfo* create_info, const VkAllocationCallbacks* allocator, VkInstance* vkinstance);
VKAPI_ATTR PFN_vkVoidFunction GetInstanceProcAddr_Bottom(VkInstance, const char* name);