summaryrefslogtreecommitdiff
path: root/vulkan/libvulkan/driver.cpp
diff options
context:
space:
mode:
author Xin Li <delphij@google.com> 2020-08-29 01:34:09 -0700
committer Xin Li <delphij@google.com> 2020-08-29 01:34:09 -0700
commite8b4e700b8950a07ea4155a31b742254002b7fad (patch)
tree2d41d10a4615e16694be0eb20487ce96a128e41c /vulkan/libvulkan/driver.cpp
parent9592c9d586e606d0d762b4334981159d2236295b (diff)
parent3fab51ee7064bc478ebaeadf068ceb628ca2365a (diff)
Merge Android R (rvc-dev-plus-aosp-without-vendor@6692709)
Bug: 166295507 Merged-In: I70ea776b8589ac3a7982c710c5c8b2941d86e55b Change-Id: Ic1d535e9d2d6f80d95215240dbdb024995b045f8
Diffstat (limited to 'vulkan/libvulkan/driver.cpp')
-rw-r--r--vulkan/libvulkan/driver.cpp111
1 files changed, 57 insertions, 54 deletions
diff --git a/vulkan/libvulkan/driver.cpp b/vulkan/libvulkan/driver.cpp
index 6ddb9d9b9a..01cbf399ff 100644
--- a/vulkan/libvulkan/driver.cpp
+++ b/vulkan/libvulkan/driver.cpp
@@ -16,43 +16,39 @@
#define ATRACE_TAG ATRACE_TAG_GRAPHICS
+#include "driver.h"
+
+#include <dlfcn.h>
#include <malloc.h>
#include <stdlib.h>
#include <string.h>
-#include <sys/prctl.h>
-
-#include <dlfcn.h>
-#include <algorithm>
-#include <array>
-#include <climits>
-#include <new>
-#include <sstream>
-#include <string>
-
-#include <log/log.h>
+#include <SurfaceFlingerProperties.h>
+#include <android-base/properties.h>
#include <android/dlext.h>
#include <android/hardware/configstore/1.0/ISurfaceFlingerConfigs.h>
#include <configstore/Utils.h>
#include <cutils/properties.h>
#include <graphicsenv/GraphicsEnv.h>
+#include <log/log.h>
+#include <nativeloader/dlext_namespaces.h>
+#include <sys/prctl.h>
#include <utils/Timers.h>
#include <utils/Trace.h>
-#include <utils/Vector.h>
-#include "android-base/properties.h"
+#include <algorithm>
+#include <array>
+#include <climits>
+#include <new>
+#include <string_view>
+#include <sstream>
+#include <vector>
-#include "driver.h"
#include "stubhal.h"
using namespace android::hardware::configstore;
using namespace android::hardware::configstore::V1_0;
-// TODO(b/37049319) Get this from a header once one exists
-extern "C" {
-android_namespace_t* android_get_exported_namespace(const char*);
-}
-
// #define ENABLE_ALLOC_CALLSTACKS 1
#if ENABLE_ALLOC_CALLSTACKS
#include <utils/CallStack.h>
@@ -169,6 +165,11 @@ const std::array<const char*, 2> HAL_SUBNAME_KEY_PROPERTIES = {{
"ro.board.platform",
}};
+// LoadDriver returns:
+// * 0 when succeed, or
+// * -ENOENT when fail to open binary libraries, or
+// * -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 hwvulkan_module_t** module) {
ATRACE_CALL();
@@ -214,7 +215,7 @@ int LoadBuiltinDriver(const hwvulkan_module_t** module) {
if (!ns)
return -ENOENT;
android::GraphicsEnv::getInstance().setDriverToLoad(
- android::GraphicsEnv::Driver::VULKAN);
+ android::GpuStatsInfo::Driver::VULKAN);
return LoadDriver(ns, module);
}
@@ -225,8 +226,14 @@ int LoadUpdatedDriver(const hwvulkan_module_t** module) {
if (!ns)
return -ENOENT;
android::GraphicsEnv::getInstance().setDriverToLoad(
- android::GraphicsEnv::Driver::VULKAN_UPDATED);
- return LoadDriver(ns, module);
+ android::GpuStatsInfo::Driver::VULKAN_UPDATED);
+ int result = LoadDriver(ns, module);
+ if (result != 0) {
+ LOG_ALWAYS_FATAL(
+ "couldn't find an updated Vulkan implementation from %s",
+ android::GraphicsEnv::getInstance().getDriverPath().c_str());
+ }
+ return result;
}
bool Hal::Open() {
@@ -245,22 +252,10 @@ bool Hal::Open() {
result = LoadUpdatedDriver(&module);
if (result == -ENOENT) {
result = LoadBuiltinDriver(&module);
- if (result != 0) {
- // -ENOENT means the sphal namespace doesn't exist, not that there
- // is a problem with the driver.
- ALOGW_IF(
- result != -ENOENT,
- "Failed to load Vulkan driver into sphal namespace. This "
- "usually means the driver has forbidden library dependencies."
- "Please fix, this will soon stop working.");
- result =
- hw_get_module(HWVULKAN_HARDWARE_MODULE_ID,
- reinterpret_cast<const hw_module_t**>(&module));
- }
}
if (result != 0) {
android::GraphicsEnv::getInstance().setDriverLoaded(
- android::GraphicsEnv::Api::API_VK, false, systemTime() - openTime);
+ android::GpuStatsInfo::Api::API_VK, false, systemTime() - openTime);
ALOGV("unable to load Vulkan HAL, using stub HAL (result=%d)", result);
return true;
}
@@ -274,7 +269,7 @@ bool Hal::Open() {
ATRACE_END();
if (result != 0) {
android::GraphicsEnv::getInstance().setDriverLoaded(
- android::GraphicsEnv::Api::API_VK, false, systemTime() - openTime);
+ android::GpuStatsInfo::Api::API_VK, false, systemTime() - openTime);
// Any device with a Vulkan HAL should be able to open the device.
ALOGE("failed to open Vulkan HAL device: %s (%d)", strerror(-result),
result);
@@ -286,7 +281,7 @@ bool Hal::Open() {
hal_.InitDebugReportIndex();
android::GraphicsEnv::getInstance().setDriverLoaded(
- android::GraphicsEnv::Api::API_VK, true, systemTime() - openTime);
+ android::GpuStatsInfo::Api::API_VK, true, systemTime() - openTime);
return true;
}
@@ -652,13 +647,16 @@ void CreateInfoWrapper::DowngradeApiVersion() {
void CreateInfoWrapper::UpgradeDeviceCoreApiVersion(uint32_t api_version) {
ALOG_ASSERT(!is_instance_, "Device only API called by instance wrapper.");
+
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wold-style-cast"
api_version ^= VK_VERSION_PATCH(api_version);
#pragma clang diagnostic pop
+
// cap the API version to the loader supported highest version
if (api_version > VK_API_VERSION_1_1)
api_version = VK_API_VERSION_1_1;
+
switch (api_version) {
case VK_API_VERSION_1_1:
hook_extensions_.set(ProcHook::EXTENSION_CORE_1_1);
@@ -695,7 +693,7 @@ VKAPI_ATTR void* DefaultReallocate(void*,
return nullptr;
}
- // TODO(jessehall): Right now we never shrink allocations; if the new
+ // TODO(b/143295633): Right now we never shrink allocations; if the new
// request is smaller than the existing chunk, we just continue using it.
// Right now the loader never reallocs, so this doesn't matter. If that
// changes, or if this code is copied into some other project, this should
@@ -836,8 +834,7 @@ VkResult EnumerateInstanceExtensionProperties(
const char* pLayerName,
uint32_t* pPropertyCount,
VkExtensionProperties* pProperties) {
-
- android::Vector<VkExtensionProperties> loader_extensions;
+ std::vector<VkExtensionProperties> loader_extensions;
loader_extensions.push_back({
VK_KHR_SURFACE_EXTENSION_NAME,
VK_KHR_SURFACE_SPEC_VERSION});
@@ -860,7 +857,7 @@ VkResult EnumerateInstanceExtensionProperties(
uint32_t count = std::min(
*pPropertyCount, static_cast<uint32_t>(loader_extensions.size()));
- std::copy_n(loader_extensions.begin(), count, pProperties);
+ std::copy_n(loader_extensions.data(), count, pProperties);
if (count < loader_extensions.size()) {
*pPropertyCount = count;
@@ -906,8 +903,7 @@ VkResult EnumerateInstanceExtensionProperties(
bool QueryPresentationProperties(
VkPhysicalDevice physicalDevice,
- VkPhysicalDevicePresentationPropertiesANDROID *presentation_properties)
-{
+ VkPhysicalDevicePresentationPropertiesANDROID *presentation_properties) {
const InstanceData& data = GetData(physicalDevice);
// GPDP2 must be present and enabled on the instance.
@@ -947,14 +943,12 @@ VkResult EnumerateDeviceExtensionProperties(
VkExtensionProperties* pProperties) {
const InstanceData& data = GetData(physicalDevice);
// extensions that are unconditionally exposed by the loader
- android::Vector<VkExtensionProperties> loader_extensions;
+ std::vector<VkExtensionProperties> loader_extensions;
loader_extensions.push_back({
VK_KHR_INCREMENTAL_PRESENT_EXTENSION_NAME,
VK_KHR_INCREMENTAL_PRESENT_SPEC_VERSION});
- bool hdrBoardConfig =
- getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::hasHDRDisplay>(
- false);
+ bool hdrBoardConfig = android::sysprop::has_HDR_display(false);
if (hdrBoardConfig) {
loader_extensions.push_back({VK_EXT_HDR_METADATA_EXTENSION_NAME,
VK_EXT_HDR_METADATA_SPEC_VERSION});
@@ -981,7 +975,7 @@ VkResult EnumerateDeviceExtensionProperties(
uint32_t count = std::min(
*pPropertyCount, static_cast<uint32_t>(loader_extensions.size()));
- std::copy_n(loader_extensions.begin(), count, pProperties);
+ std::copy_n(loader_extensions.data(), count, pProperties);
if (count < loader_extensions.size()) {
*pPropertyCount = count;
@@ -1203,11 +1197,10 @@ VkResult CreateDevice(VkPhysicalDevice physicalDevice,
if (properties.deviceType == VK_PHYSICAL_DEVICE_TYPE_CPU) {
// Log that the app is hitting software Vulkan implementation
android::GraphicsEnv::getInstance().setTargetStats(
- android::GraphicsEnv::Stats::CPU_VULKAN_IN_USE);
+ android::GpuStatsInfo::Stats::CPU_VULKAN_IN_USE);
}
data->driver_device = dev;
- data->driver_version = properties.driverVersion;
*pDevice = dev;
@@ -1272,11 +1265,10 @@ VkResult EnumeratePhysicalDeviceGroups(
if (!device_count)
return VK_INCOMPLETE;
- android::Vector<VkPhysicalDevice> devices;
- devices.resize(device_count);
+ std::vector<VkPhysicalDevice> devices(device_count);
*pPhysicalDeviceGroupCount = device_count;
- result = EnumeratePhysicalDevices(instance, &device_count,
- devices.editArray());
+ result =
+ EnumeratePhysicalDevices(instance, &device_count, devices.data());
if (result < 0)
return result;
@@ -1347,5 +1339,16 @@ AllocateCommandBuffers(VkDevice device,
return result;
}
+VKAPI_ATTR VkResult QueueSubmit(VkQueue queue,
+ uint32_t submitCount,
+ const VkSubmitInfo* pSubmits,
+ VkFence fence) {
+ ATRACE_CALL();
+
+ const auto& data = GetData(queue);
+
+ return data.driver.QueueSubmit(queue, submitCount, pSubmits, fence);
+}
+
} // namespace driver
} // namespace vulkan