diff options
Diffstat (limited to 'vulkan/libvulkan/driver.cpp')
-rw-r--r-- | vulkan/libvulkan/driver.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/vulkan/libvulkan/driver.cpp b/vulkan/libvulkan/driver.cpp index 26c192374d..09811a036a 100644 --- a/vulkan/libvulkan/driver.cpp +++ b/vulkan/libvulkan/driver.cpp @@ -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 |