Chia-I Wu | 9d51816 | 2016-03-24 14:55:27 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Yiwei Zhang | fdd0c2a | 2019-01-30 20:16:37 -0800 | [diff] [blame] | 17 | #define ATRACE_TAG ATRACE_TAG_GRAPHICS |
| 18 | |
Yiwei Zhang | 5e86220 | 2019-06-21 14:59:16 -0700 | [diff] [blame] | 19 | #include "driver.h" |
| 20 | |
| 21 | #include <dlfcn.h> |
Mark Salyzyn | 7823e12 | 2016-09-29 08:08:05 -0700 | [diff] [blame] | 22 | #include <malloc.h> |
Chia-I Wu | dbb7e9c | 2016-03-24 15:09:38 +0800 | [diff] [blame] | 23 | #include <stdlib.h> |
| 24 | #include <string.h> |
Chia-I Wu | 9d51816 | 2016-03-24 14:55:27 +0800 | [diff] [blame] | 25 | |
Sundong Ahn | bc37dd5 | 2020-04-23 21:21:00 +0900 | [diff] [blame] | 26 | #include <SurfaceFlingerProperties.h> |
| 27 | #include <android-base/properties.h> |
Jesse Hall | 53457db | 2016-12-14 16:54:06 -0800 | [diff] [blame] | 28 | #include <android/dlext.h> |
Courtney Goeltzenleuchter | 7671d46 | 2018-01-24 11:51:01 -0800 | [diff] [blame] | 29 | #include <android/hardware/configstore/1.0/ISurfaceFlingerConfigs.h> |
| 30 | #include <configstore/Utils.h> |
Jiyong Park | 27c39e1 | 2017-05-08 13:00:02 +0900 | [diff] [blame] | 31 | #include <graphicsenv/GraphicsEnv.h> |
Yiwei Zhang | 5e86220 | 2019-06-21 14:59:16 -0700 | [diff] [blame] | 32 | #include <log/log.h> |
| 33 | #include <sys/prctl.h> |
Yiwei Zhang | d986181 | 2019-02-13 11:51:55 -0800 | [diff] [blame] | 34 | #include <utils/Timers.h> |
Yiwei Zhang | fdd0c2a | 2019-01-30 20:16:37 -0800 | [diff] [blame] | 35 | #include <utils/Trace.h> |
Yiwei Zhang | 40e84f1 | 2020-10-14 08:42:26 -0700 | [diff] [blame] | 36 | #include <vndksupport/linker.h> |
Jesse Hall | 53457db | 2016-12-14 16:54:06 -0800 | [diff] [blame] | 37 | |
Yiwei Zhang | 5e86220 | 2019-06-21 14:59:16 -0700 | [diff] [blame] | 38 | #include <algorithm> |
| 39 | #include <array> |
Nick Desaulniers | 7c123cc | 2019-10-21 13:52:41 -0700 | [diff] [blame] | 40 | #include <climits> |
Yiwei Zhang | 5e86220 | 2019-06-21 14:59:16 -0700 | [diff] [blame] | 41 | #include <new> |
| 42 | #include <vector> |
Wei Wang | f9b05ee | 2017-07-19 20:59:39 -0700 | [diff] [blame] | 43 | |
Jesse Hall | b7c4e3b | 2016-04-11 13:51:38 -0700 | [diff] [blame] | 44 | #include "stubhal.h" |
Chia-I Wu | 9d51816 | 2016-03-24 14:55:27 +0800 | [diff] [blame] | 45 | |
Courtney Goeltzenleuchter | 7671d46 | 2018-01-24 11:51:01 -0800 | [diff] [blame] | 46 | using namespace android::hardware::configstore; |
| 47 | using namespace android::hardware::configstore::V1_0; |
| 48 | |
Chia-I Wu | dbb7e9c | 2016-03-24 15:09:38 +0800 | [diff] [blame] | 49 | // #define ENABLE_ALLOC_CALLSTACKS 1 |
| 50 | #if ENABLE_ALLOC_CALLSTACKS |
| 51 | #include <utils/CallStack.h> |
| 52 | #define ALOGD_CALLSTACK(...) \ |
| 53 | do { \ |
| 54 | ALOGD(__VA_ARGS__); \ |
| 55 | android::CallStack callstack; \ |
| 56 | callstack.update(); \ |
| 57 | callstack.log(LOG_TAG, ANDROID_LOG_DEBUG, " "); \ |
| 58 | } while (false) |
| 59 | #else |
| 60 | #define ALOGD_CALLSTACK(...) \ |
| 61 | do { \ |
| 62 | } while (false) |
| 63 | #endif |
| 64 | |
Chia-I Wu | 9d51816 | 2016-03-24 14:55:27 +0800 | [diff] [blame] | 65 | namespace vulkan { |
| 66 | namespace driver { |
| 67 | |
Chia-I Wu | 136b8eb | 2016-03-24 15:01:52 +0800 | [diff] [blame] | 68 | namespace { |
| 69 | |
Chia-I Wu | 31b2e4f | 2016-05-23 10:47:57 +0800 | [diff] [blame] | 70 | class Hal { |
| 71 | public: |
| 72 | static bool Open(); |
| 73 | |
| 74 | static const Hal& Get() { return hal_; } |
| 75 | static const hwvulkan_device_t& Device() { return *Get().dev_; } |
| 76 | |
Chia-I Wu | 3193825 | 2016-05-23 15:31:02 +0800 | [diff] [blame] | 77 | int GetDebugReportIndex() const { return debug_report_index_; } |
| 78 | |
Chia-I Wu | 31b2e4f | 2016-05-23 10:47:57 +0800 | [diff] [blame] | 79 | private: |
Chia-I Wu | 3193825 | 2016-05-23 15:31:02 +0800 | [diff] [blame] | 80 | Hal() : dev_(nullptr), debug_report_index_(-1) {} |
Chia-I Wu | 31b2e4f | 2016-05-23 10:47:57 +0800 | [diff] [blame] | 81 | Hal(const Hal&) = delete; |
| 82 | Hal& operator=(const Hal&) = delete; |
| 83 | |
Yiwei Zhang | 901f8ee | 2020-07-31 13:18:49 -0700 | [diff] [blame] | 84 | bool ShouldUnloadBuiltinDriver(); |
| 85 | void UnloadBuiltinDriver(); |
Chia-I Wu | 3193825 | 2016-05-23 15:31:02 +0800 | [diff] [blame] | 86 | bool InitDebugReportIndex(); |
| 87 | |
Chia-I Wu | 31b2e4f | 2016-05-23 10:47:57 +0800 | [diff] [blame] | 88 | static Hal hal_; |
| 89 | |
| 90 | const hwvulkan_device_t* dev_; |
Chia-I Wu | 3193825 | 2016-05-23 15:31:02 +0800 | [diff] [blame] | 91 | int debug_report_index_; |
Chia-I Wu | 31b2e4f | 2016-05-23 10:47:57 +0800 | [diff] [blame] | 92 | }; |
| 93 | |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 94 | class CreateInfoWrapper { |
| 95 | public: |
Chia-I Wu | 31b2e4f | 2016-05-23 10:47:57 +0800 | [diff] [blame] | 96 | CreateInfoWrapper(const VkInstanceCreateInfo& create_info, |
Yiwei Zhang | 2cefa73 | 2020-07-10 21:07:30 -0700 | [diff] [blame] | 97 | uint32_t icd_api_version, |
Chia-I Wu | ff4a6c7 | 2016-03-24 16:05:56 +0800 | [diff] [blame] | 98 | const VkAllocationCallbacks& allocator); |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 99 | CreateInfoWrapper(VkPhysicalDevice physical_dev, |
| 100 | const VkDeviceCreateInfo& create_info, |
Yiwei Zhang | 2cefa73 | 2020-07-10 21:07:30 -0700 | [diff] [blame] | 101 | uint32_t icd_api_version, |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 102 | const VkAllocationCallbacks& allocator); |
| 103 | ~CreateInfoWrapper(); |
| 104 | |
Chia-I Wu | 3e6c2d6 | 2016-04-11 13:55:56 +0800 | [diff] [blame] | 105 | VkResult Validate(); |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 106 | |
Chia-I Wu | 3e6c2d6 | 2016-04-11 13:55:56 +0800 | [diff] [blame] | 107 | const std::bitset<ProcHook::EXTENSION_COUNT>& GetHookExtensions() const; |
| 108 | const std::bitset<ProcHook::EXTENSION_COUNT>& GetHalExtensions() const; |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 109 | |
Chia-I Wu | ff4a6c7 | 2016-03-24 16:05:56 +0800 | [diff] [blame] | 110 | explicit operator const VkInstanceCreateInfo*() const; |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 111 | explicit operator const VkDeviceCreateInfo*() const; |
| 112 | |
| 113 | private: |
| 114 | struct ExtensionFilter { |
| 115 | VkExtensionProperties* exts; |
| 116 | uint32_t ext_count; |
| 117 | |
| 118 | const char** names; |
| 119 | uint32_t name_count; |
Yiwei Zhang | d7ea44a | 2020-08-13 12:54:27 -0700 | [diff] [blame] | 120 | ExtensionFilter() |
| 121 | : exts(nullptr), ext_count(0), names(nullptr), name_count(0) {} |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 122 | }; |
| 123 | |
Yiwei Zhang | d4fd122 | 2020-07-03 22:18:42 -0700 | [diff] [blame] | 124 | VkResult SanitizeApiVersion(); |
Chia-I Wu | 3e6c2d6 | 2016-04-11 13:55:56 +0800 | [diff] [blame] | 125 | VkResult SanitizePNext(); |
Chia-I Wu | 3e6c2d6 | 2016-04-11 13:55:56 +0800 | [diff] [blame] | 126 | VkResult SanitizeLayers(); |
| 127 | VkResult SanitizeExtensions(); |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 128 | |
Chia-I Wu | 3e6c2d6 | 2016-04-11 13:55:56 +0800 | [diff] [blame] | 129 | VkResult QueryExtensionCount(uint32_t& count) const; |
| 130 | VkResult EnumerateExtensions(uint32_t& count, |
| 131 | VkExtensionProperties* props) const; |
| 132 | VkResult InitExtensionFilter(); |
| 133 | void FilterExtension(const char* name); |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 134 | |
| 135 | const bool is_instance_; |
| 136 | const VkAllocationCallbacks& allocator_; |
Yiwei Zhang | d4fd122 | 2020-07-03 22:18:42 -0700 | [diff] [blame] | 137 | const uint32_t loader_api_version_; |
Yiwei Zhang | 2cefa73 | 2020-07-10 21:07:30 -0700 | [diff] [blame] | 138 | const uint32_t icd_api_version_; |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 139 | |
Chia-I Wu | 31b2e4f | 2016-05-23 10:47:57 +0800 | [diff] [blame] | 140 | VkPhysicalDevice physical_dev_; |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 141 | |
| 142 | union { |
| 143 | VkInstanceCreateInfo instance_info_; |
| 144 | VkDeviceCreateInfo dev_info_; |
| 145 | }; |
| 146 | |
Ian Elliott | f3e872d | 2017-11-02 10:15:13 -0600 | [diff] [blame] | 147 | VkApplicationInfo application_info_; |
| 148 | |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 149 | ExtensionFilter extension_filter_; |
| 150 | |
| 151 | std::bitset<ProcHook::EXTENSION_COUNT> hook_extensions_; |
| 152 | std::bitset<ProcHook::EXTENSION_COUNT> hal_extensions_; |
| 153 | }; |
| 154 | |
Chia-I Wu | 31b2e4f | 2016-05-23 10:47:57 +0800 | [diff] [blame] | 155 | Hal Hal::hal_; |
| 156 | |
Jesse Hall | 53457db | 2016-12-14 16:54:06 -0800 | [diff] [blame] | 157 | const std::array<const char*, 2> HAL_SUBNAME_KEY_PROPERTIES = {{ |
Peter Collingbourne | 161c76b | 2020-04-22 13:12:23 -0700 | [diff] [blame] | 158 | "ro.hardware.vulkan", |
Jesse Hall | 53457db | 2016-12-14 16:54:06 -0800 | [diff] [blame] | 159 | "ro.board.platform", |
| 160 | }}; |
Yiwei Zhang | 40e84f1 | 2020-10-14 08:42:26 -0700 | [diff] [blame] | 161 | constexpr int LIB_DL_FLAGS = RTLD_LOCAL | RTLD_NOW; |
Jesse Hall | 53457db | 2016-12-14 16:54:06 -0800 | [diff] [blame] | 162 | |
Peiyong Lin | efa0cbd | 2020-01-29 20:51:50 -0800 | [diff] [blame] | 163 | // LoadDriver returns: |
| 164 | // * 0 when succeed, or |
| 165 | // * -ENOENT when fail to open binary libraries, or |
| 166 | // * -EINVAL when fail to find HAL_MODULE_INFO_SYM_AS_STR or |
| 167 | // HWVULKAN_HARDWARE_MODULE_ID in the library. |
Jesse Hall | 00e61ff | 2017-04-07 16:48:02 -0700 | [diff] [blame] | 168 | int LoadDriver(android_namespace_t* library_namespace, |
| 169 | const hwvulkan_module_t** module) { |
Yiwei Zhang | fdd0c2a | 2019-01-30 20:16:37 -0800 | [diff] [blame] | 170 | ATRACE_CALL(); |
| 171 | |
Jesse Hall | 53457db | 2016-12-14 16:54:06 -0800 | [diff] [blame] | 172 | void* so = nullptr; |
Jesse Hall | 53457db | 2016-12-14 16:54:06 -0800 | [diff] [blame] | 173 | for (auto key : HAL_SUBNAME_KEY_PROPERTIES) { |
Yiwei Zhang | 40e84f1 | 2020-10-14 08:42:26 -0700 | [diff] [blame] | 174 | std::string lib_name = android::base::GetProperty(key, ""); |
| 175 | if (lib_name.empty()) |
| 176 | continue; |
| 177 | |
| 178 | lib_name = "vulkan." + lib_name + ".so"; |
| 179 | if (library_namespace) { |
| 180 | // load updated driver |
| 181 | const android_dlextinfo dlextinfo = { |
| 182 | .flags = ANDROID_DLEXT_USE_NAMESPACE, |
| 183 | .library_namespace = library_namespace, |
| 184 | }; |
| 185 | so = android_dlopen_ext(lib_name.c_str(), LIB_DL_FLAGS, &dlextinfo); |
Yiwei Zhang | 9058b8f | 2020-11-12 20:23:00 +0000 | [diff] [blame] | 186 | ALOGE("Could not load %s from updatable gfx driver namespace: %s.", |
| 187 | lib_name.c_str(), dlerror()); |
Yiwei Zhang | 40e84f1 | 2020-10-14 08:42:26 -0700 | [diff] [blame] | 188 | } else { |
| 189 | // load built-in driver |
| 190 | so = android_load_sphal_library(lib_name.c_str(), LIB_DL_FLAGS); |
Jesse Hall | 53457db | 2016-12-14 16:54:06 -0800 | [diff] [blame] | 191 | } |
Yiwei Zhang | 40e84f1 | 2020-10-14 08:42:26 -0700 | [diff] [blame] | 192 | if (so) |
| 193 | break; |
Jesse Hall | 53457db | 2016-12-14 16:54:06 -0800 | [diff] [blame] | 194 | } |
| 195 | if (!so) |
| 196 | return -ENOENT; |
| 197 | |
Jesse Hall | 00e61ff | 2017-04-07 16:48:02 -0700 | [diff] [blame] | 198 | auto hmi = static_cast<hw_module_t*>(dlsym(so, HAL_MODULE_INFO_SYM_AS_STR)); |
Jesse Hall | 53457db | 2016-12-14 16:54:06 -0800 | [diff] [blame] | 199 | if (!hmi) { |
| 200 | ALOGE("couldn't find symbol '%s' in HAL library: %s", HAL_MODULE_INFO_SYM_AS_STR, dlerror()); |
| 201 | dlclose(so); |
| 202 | return -EINVAL; |
| 203 | } |
| 204 | if (strcmp(hmi->id, HWVULKAN_HARDWARE_MODULE_ID) != 0) { |
| 205 | ALOGE("HAL id '%s' != '%s'", hmi->id, HWVULKAN_HARDWARE_MODULE_ID); |
| 206 | dlclose(so); |
| 207 | return -EINVAL; |
| 208 | } |
| 209 | hmi->dso = so; |
Jesse Hall | 00e61ff | 2017-04-07 16:48:02 -0700 | [diff] [blame] | 210 | *module = reinterpret_cast<const hwvulkan_module_t*>(hmi); |
Jesse Hall | 53457db | 2016-12-14 16:54:06 -0800 | [diff] [blame] | 211 | return 0; |
| 212 | } |
| 213 | |
Jesse Hall | 00e61ff | 2017-04-07 16:48:02 -0700 | [diff] [blame] | 214 | int LoadBuiltinDriver(const hwvulkan_module_t** module) { |
Yiwei Zhang | fdd0c2a | 2019-01-30 20:16:37 -0800 | [diff] [blame] | 215 | ATRACE_CALL(); |
| 216 | |
Yiwei Zhang | d986181 | 2019-02-13 11:51:55 -0800 | [diff] [blame] | 217 | android::GraphicsEnv::getInstance().setDriverToLoad( |
Yiwei Zhang | 27ab3ac | 2019-07-02 18:10:55 -0700 | [diff] [blame] | 218 | android::GpuStatsInfo::Driver::VULKAN); |
Yiwei Zhang | 40e84f1 | 2020-10-14 08:42:26 -0700 | [diff] [blame] | 219 | return LoadDriver(nullptr, module); |
Jesse Hall | 00e61ff | 2017-04-07 16:48:02 -0700 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | int LoadUpdatedDriver(const hwvulkan_module_t** module) { |
Yiwei Zhang | fdd0c2a | 2019-01-30 20:16:37 -0800 | [diff] [blame] | 223 | ATRACE_CALL(); |
| 224 | |
Jesse Hall | 00e61ff | 2017-04-07 16:48:02 -0700 | [diff] [blame] | 225 | auto ns = android::GraphicsEnv::getInstance().getDriverNamespace(); |
| 226 | if (!ns) |
| 227 | return -ENOENT; |
Yiwei Zhang | d986181 | 2019-02-13 11:51:55 -0800 | [diff] [blame] | 228 | android::GraphicsEnv::getInstance().setDriverToLoad( |
Yiwei Zhang | 27ab3ac | 2019-07-02 18:10:55 -0700 | [diff] [blame] | 229 | android::GpuStatsInfo::Driver::VULKAN_UPDATED); |
Peiyong Lin | efa0cbd | 2020-01-29 20:51:50 -0800 | [diff] [blame] | 230 | int result = LoadDriver(ns, module); |
| 231 | if (result != 0) { |
| 232 | LOG_ALWAYS_FATAL( |
| 233 | "couldn't find an updated Vulkan implementation from %s", |
| 234 | android::GraphicsEnv::getInstance().getDriverPath().c_str()); |
| 235 | } |
| 236 | return result; |
Jesse Hall | 00e61ff | 2017-04-07 16:48:02 -0700 | [diff] [blame] | 237 | } |
| 238 | |
Chia-I Wu | 31b2e4f | 2016-05-23 10:47:57 +0800 | [diff] [blame] | 239 | bool Hal::Open() { |
Yiwei Zhang | fdd0c2a | 2019-01-30 20:16:37 -0800 | [diff] [blame] | 240 | ATRACE_CALL(); |
| 241 | |
Yiwei Zhang | d986181 | 2019-02-13 11:51:55 -0800 | [diff] [blame] | 242 | const nsecs_t openTime = systemTime(); |
| 243 | |
Yiwei Zhang | 901f8ee | 2020-07-31 13:18:49 -0700 | [diff] [blame] | 244 | if (hal_.ShouldUnloadBuiltinDriver()) { |
| 245 | hal_.UnloadBuiltinDriver(); |
| 246 | } |
| 247 | |
| 248 | if (hal_.dev_) |
| 249 | return true; |
Chia-I Wu | 31b2e4f | 2016-05-23 10:47:57 +0800 | [diff] [blame] | 250 | |
| 251 | // Use a stub device unless we successfully open a real HAL device. |
| 252 | hal_.dev_ = &stubhal::kDevice; |
| 253 | |
Jesse Hall | 53457db | 2016-12-14 16:54:06 -0800 | [diff] [blame] | 254 | int result; |
| 255 | const hwvulkan_module_t* module = nullptr; |
| 256 | |
Jesse Hall | 00e61ff | 2017-04-07 16:48:02 -0700 | [diff] [blame] | 257 | result = LoadUpdatedDriver(&module); |
Jesse Hall | 53457db | 2016-12-14 16:54:06 -0800 | [diff] [blame] | 258 | if (result == -ENOENT) { |
Jesse Hall | 00e61ff | 2017-04-07 16:48:02 -0700 | [diff] [blame] | 259 | result = LoadBuiltinDriver(&module); |
Jesse Hall | 53457db | 2016-12-14 16:54:06 -0800 | [diff] [blame] | 260 | } |
Chia-I Wu | 31b2e4f | 2016-05-23 10:47:57 +0800 | [diff] [blame] | 261 | if (result != 0) { |
Yiwei Zhang | d986181 | 2019-02-13 11:51:55 -0800 | [diff] [blame] | 262 | android::GraphicsEnv::getInstance().setDriverLoaded( |
Yiwei Zhang | 27ab3ac | 2019-07-02 18:10:55 -0700 | [diff] [blame] | 263 | android::GpuStatsInfo::Api::API_VK, false, systemTime() - openTime); |
Jesse Hall | 53457db | 2016-12-14 16:54:06 -0800 | [diff] [blame] | 264 | ALOGV("unable to load Vulkan HAL, using stub HAL (result=%d)", result); |
Chia-I Wu | 31b2e4f | 2016-05-23 10:47:57 +0800 | [diff] [blame] | 265 | return true; |
| 266 | } |
| 267 | |
Yiwei Zhang | cb9d4e4 | 2019-02-06 20:22:59 -0800 | [diff] [blame] | 268 | |
Chia-I Wu | 31b2e4f | 2016-05-23 10:47:57 +0800 | [diff] [blame] | 269 | hwvulkan_device_t* device; |
Yiwei Zhang | fdd0c2a | 2019-01-30 20:16:37 -0800 | [diff] [blame] | 270 | ATRACE_BEGIN("hwvulkan module open"); |
Chia-I Wu | 31b2e4f | 2016-05-23 10:47:57 +0800 | [diff] [blame] | 271 | result = |
| 272 | module->common.methods->open(&module->common, HWVULKAN_DEVICE_0, |
| 273 | reinterpret_cast<hw_device_t**>(&device)); |
Yiwei Zhang | fdd0c2a | 2019-01-30 20:16:37 -0800 | [diff] [blame] | 274 | ATRACE_END(); |
Chia-I Wu | 31b2e4f | 2016-05-23 10:47:57 +0800 | [diff] [blame] | 275 | if (result != 0) { |
Yiwei Zhang | d986181 | 2019-02-13 11:51:55 -0800 | [diff] [blame] | 276 | android::GraphicsEnv::getInstance().setDriverLoaded( |
Yiwei Zhang | 27ab3ac | 2019-07-02 18:10:55 -0700 | [diff] [blame] | 277 | android::GpuStatsInfo::Api::API_VK, false, systemTime() - openTime); |
Chia-I Wu | 31b2e4f | 2016-05-23 10:47:57 +0800 | [diff] [blame] | 278 | // Any device with a Vulkan HAL should be able to open the device. |
| 279 | ALOGE("failed to open Vulkan HAL device: %s (%d)", strerror(-result), |
| 280 | result); |
| 281 | return false; |
| 282 | } |
| 283 | |
| 284 | hal_.dev_ = device; |
| 285 | |
Chia-I Wu | 3193825 | 2016-05-23 15:31:02 +0800 | [diff] [blame] | 286 | hal_.InitDebugReportIndex(); |
| 287 | |
Yiwei Zhang | d986181 | 2019-02-13 11:51:55 -0800 | [diff] [blame] | 288 | android::GraphicsEnv::getInstance().setDriverLoaded( |
Yiwei Zhang | 27ab3ac | 2019-07-02 18:10:55 -0700 | [diff] [blame] | 289 | android::GpuStatsInfo::Api::API_VK, true, systemTime() - openTime); |
Yiwei Zhang | d986181 | 2019-02-13 11:51:55 -0800 | [diff] [blame] | 290 | |
Chia-I Wu | 3193825 | 2016-05-23 15:31:02 +0800 | [diff] [blame] | 291 | return true; |
| 292 | } |
| 293 | |
Yiwei Zhang | 901f8ee | 2020-07-31 13:18:49 -0700 | [diff] [blame] | 294 | bool Hal::ShouldUnloadBuiltinDriver() { |
| 295 | // Should not unload since the driver was not loaded |
| 296 | if (!hal_.dev_) |
| 297 | return false; |
| 298 | |
| 299 | // Should not unload if stubhal is used on the device |
| 300 | if (hal_.dev_ == &stubhal::kDevice) |
| 301 | return false; |
| 302 | |
| 303 | // Unload the driver if updated driver is chosen |
| 304 | if (android::GraphicsEnv::getInstance().getDriverNamespace()) |
| 305 | return true; |
| 306 | |
| 307 | return false; |
| 308 | } |
| 309 | |
| 310 | void Hal::UnloadBuiltinDriver() { |
| 311 | ATRACE_CALL(); |
| 312 | |
| 313 | ALOGD("Unload builtin Vulkan driver."); |
| 314 | |
| 315 | // Close the opened device |
| 316 | ALOG_ASSERT(!hal_.dev_->common.close(hal_.dev_->common), |
| 317 | "hw_device_t::close() failed."); |
| 318 | |
| 319 | // Close the opened shared library in the hw_module_t |
Yiwei Zhang | 40e84f1 | 2020-10-14 08:42:26 -0700 | [diff] [blame] | 320 | android_unload_sphal_library(hal_.dev_->common.module->dso); |
Yiwei Zhang | 901f8ee | 2020-07-31 13:18:49 -0700 | [diff] [blame] | 321 | |
| 322 | hal_.dev_ = nullptr; |
| 323 | hal_.debug_report_index_ = -1; |
| 324 | } |
| 325 | |
Chia-I Wu | 3193825 | 2016-05-23 15:31:02 +0800 | [diff] [blame] | 326 | bool Hal::InitDebugReportIndex() { |
Yiwei Zhang | fdd0c2a | 2019-01-30 20:16:37 -0800 | [diff] [blame] | 327 | ATRACE_CALL(); |
| 328 | |
Chia-I Wu | 3193825 | 2016-05-23 15:31:02 +0800 | [diff] [blame] | 329 | uint32_t count; |
| 330 | if (dev_->EnumerateInstanceExtensionProperties(nullptr, &count, nullptr) != |
| 331 | VK_SUCCESS) { |
| 332 | ALOGE("failed to get HAL instance extension count"); |
| 333 | return false; |
| 334 | } |
| 335 | |
| 336 | VkExtensionProperties* exts = reinterpret_cast<VkExtensionProperties*>( |
| 337 | malloc(sizeof(VkExtensionProperties) * count)); |
| 338 | if (!exts) { |
| 339 | ALOGE("failed to allocate HAL instance extension array"); |
| 340 | return false; |
| 341 | } |
| 342 | |
| 343 | if (dev_->EnumerateInstanceExtensionProperties(nullptr, &count, exts) != |
| 344 | VK_SUCCESS) { |
| 345 | ALOGE("failed to enumerate HAL instance extensions"); |
| 346 | free(exts); |
| 347 | return false; |
| 348 | } |
| 349 | |
| 350 | for (uint32_t i = 0; i < count; i++) { |
| 351 | if (strcmp(exts[i].extensionName, VK_EXT_DEBUG_REPORT_EXTENSION_NAME) == |
| 352 | 0) { |
| 353 | debug_report_index_ = static_cast<int>(i); |
| 354 | break; |
| 355 | } |
| 356 | } |
| 357 | |
| 358 | free(exts); |
| 359 | |
Chia-I Wu | 31b2e4f | 2016-05-23 10:47:57 +0800 | [diff] [blame] | 360 | return true; |
| 361 | } |
| 362 | |
| 363 | CreateInfoWrapper::CreateInfoWrapper(const VkInstanceCreateInfo& create_info, |
Yiwei Zhang | 2cefa73 | 2020-07-10 21:07:30 -0700 | [diff] [blame] | 364 | uint32_t icd_api_version, |
Chia-I Wu | ff4a6c7 | 2016-03-24 16:05:56 +0800 | [diff] [blame] | 365 | const VkAllocationCallbacks& allocator) |
| 366 | : is_instance_(true), |
| 367 | allocator_(allocator), |
Ian Elliott | fa7af49 | 2021-07-20 17:40:24 -0600 | [diff] [blame] | 368 | loader_api_version_(VK_API_VERSION_1_2), |
Yiwei Zhang | 2cefa73 | 2020-07-10 21:07:30 -0700 | [diff] [blame] | 369 | icd_api_version_(icd_api_version), |
Chia-I Wu | 31b2e4f | 2016-05-23 10:47:57 +0800 | [diff] [blame] | 370 | physical_dev_(VK_NULL_HANDLE), |
Chia-I Wu | ff4a6c7 | 2016-03-24 16:05:56 +0800 | [diff] [blame] | 371 | instance_info_(create_info), |
Yiwei Zhang | d4fd122 | 2020-07-03 22:18:42 -0700 | [diff] [blame] | 372 | extension_filter_() {} |
Chia-I Wu | ff4a6c7 | 2016-03-24 16:05:56 +0800 | [diff] [blame] | 373 | |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 374 | CreateInfoWrapper::CreateInfoWrapper(VkPhysicalDevice physical_dev, |
| 375 | const VkDeviceCreateInfo& create_info, |
Yiwei Zhang | 2cefa73 | 2020-07-10 21:07:30 -0700 | [diff] [blame] | 376 | uint32_t icd_api_version, |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 377 | const VkAllocationCallbacks& allocator) |
| 378 | : is_instance_(false), |
| 379 | allocator_(allocator), |
Ian Elliott | fa7af49 | 2021-07-20 17:40:24 -0600 | [diff] [blame] | 380 | loader_api_version_(VK_API_VERSION_1_2), |
Yiwei Zhang | 2cefa73 | 2020-07-10 21:07:30 -0700 | [diff] [blame] | 381 | icd_api_version_(icd_api_version), |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 382 | physical_dev_(physical_dev), |
| 383 | dev_info_(create_info), |
Yiwei Zhang | d4fd122 | 2020-07-03 22:18:42 -0700 | [diff] [blame] | 384 | extension_filter_() {} |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 385 | |
| 386 | CreateInfoWrapper::~CreateInfoWrapper() { |
| 387 | allocator_.pfnFree(allocator_.pUserData, extension_filter_.exts); |
| 388 | allocator_.pfnFree(allocator_.pUserData, extension_filter_.names); |
| 389 | } |
| 390 | |
Chia-I Wu | 3e6c2d6 | 2016-04-11 13:55:56 +0800 | [diff] [blame] | 391 | VkResult CreateInfoWrapper::Validate() { |
Yiwei Zhang | d4fd122 | 2020-07-03 22:18:42 -0700 | [diff] [blame] | 392 | VkResult result = SanitizeApiVersion(); |
| 393 | if (result == VK_SUCCESS) |
| 394 | result = SanitizePNext(); |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 395 | if (result == VK_SUCCESS) |
Chia-I Wu | 3e6c2d6 | 2016-04-11 13:55:56 +0800 | [diff] [blame] | 396 | result = SanitizeLayers(); |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 397 | if (result == VK_SUCCESS) |
Chia-I Wu | 3e6c2d6 | 2016-04-11 13:55:56 +0800 | [diff] [blame] | 398 | result = SanitizeExtensions(); |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 399 | |
| 400 | return result; |
| 401 | } |
| 402 | |
| 403 | const std::bitset<ProcHook::EXTENSION_COUNT>& |
Chia-I Wu | 3e6c2d6 | 2016-04-11 13:55:56 +0800 | [diff] [blame] | 404 | CreateInfoWrapper::GetHookExtensions() const { |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 405 | return hook_extensions_; |
| 406 | } |
| 407 | |
| 408 | const std::bitset<ProcHook::EXTENSION_COUNT>& |
Chia-I Wu | 3e6c2d6 | 2016-04-11 13:55:56 +0800 | [diff] [blame] | 409 | CreateInfoWrapper::GetHalExtensions() const { |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 410 | return hal_extensions_; |
| 411 | } |
| 412 | |
Chia-I Wu | ff4a6c7 | 2016-03-24 16:05:56 +0800 | [diff] [blame] | 413 | CreateInfoWrapper::operator const VkInstanceCreateInfo*() const { |
| 414 | return &instance_info_; |
| 415 | } |
| 416 | |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 417 | CreateInfoWrapper::operator const VkDeviceCreateInfo*() const { |
| 418 | return &dev_info_; |
| 419 | } |
| 420 | |
Yiwei Zhang | d4fd122 | 2020-07-03 22:18:42 -0700 | [diff] [blame] | 421 | VkResult CreateInfoWrapper::SanitizeApiVersion() { |
Yiwei Zhang | 2cefa73 | 2020-07-10 21:07:30 -0700 | [diff] [blame] | 422 | if (!is_instance_ || !instance_info_.pApplicationInfo) |
| 423 | return VK_SUCCESS; |
Yiwei Zhang | d4fd122 | 2020-07-03 22:18:42 -0700 | [diff] [blame] | 424 | |
Yiwei Zhang | 2cefa73 | 2020-07-10 21:07:30 -0700 | [diff] [blame] | 425 | if (icd_api_version_ > VK_API_VERSION_1_0 || |
| 426 | instance_info_.pApplicationInfo->apiVersion < VK_API_VERSION_1_1) |
| 427 | return VK_SUCCESS; |
Yiwei Zhang | d4fd122 | 2020-07-03 22:18:42 -0700 | [diff] [blame] | 428 | |
Yiwei Zhang | 2cefa73 | 2020-07-10 21:07:30 -0700 | [diff] [blame] | 429 | // override apiVersion to avoid error return from 1.0 icd |
| 430 | application_info_ = *instance_info_.pApplicationInfo; |
| 431 | application_info_.apiVersion = VK_API_VERSION_1_0; |
| 432 | instance_info_.pApplicationInfo = &application_info_; |
Yiwei Zhang | d4fd122 | 2020-07-03 22:18:42 -0700 | [diff] [blame] | 433 | |
| 434 | return VK_SUCCESS; |
| 435 | } |
| 436 | |
Chia-I Wu | 3e6c2d6 | 2016-04-11 13:55:56 +0800 | [diff] [blame] | 437 | VkResult CreateInfoWrapper::SanitizePNext() { |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 438 | const struct StructHeader { |
| 439 | VkStructureType type; |
| 440 | const void* next; |
| 441 | } * header; |
| 442 | |
| 443 | if (is_instance_) { |
| 444 | header = reinterpret_cast<const StructHeader*>(instance_info_.pNext); |
| 445 | |
| 446 | // skip leading VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFOs |
| 447 | while (header && |
| 448 | header->type == VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO) |
| 449 | header = reinterpret_cast<const StructHeader*>(header->next); |
| 450 | |
| 451 | instance_info_.pNext = header; |
| 452 | } else { |
| 453 | header = reinterpret_cast<const StructHeader*>(dev_info_.pNext); |
| 454 | |
| 455 | // skip leading VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFOs |
| 456 | while (header && |
| 457 | header->type == VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO) |
| 458 | header = reinterpret_cast<const StructHeader*>(header->next); |
| 459 | |
| 460 | dev_info_.pNext = header; |
| 461 | } |
| 462 | |
| 463 | return VK_SUCCESS; |
| 464 | } |
| 465 | |
Chia-I Wu | 3e6c2d6 | 2016-04-11 13:55:56 +0800 | [diff] [blame] | 466 | VkResult CreateInfoWrapper::SanitizeLayers() { |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 467 | auto& layer_names = (is_instance_) ? instance_info_.ppEnabledLayerNames |
| 468 | : dev_info_.ppEnabledLayerNames; |
| 469 | auto& layer_count = (is_instance_) ? instance_info_.enabledLayerCount |
| 470 | : dev_info_.enabledLayerCount; |
| 471 | |
| 472 | // remove all layers |
| 473 | layer_names = nullptr; |
| 474 | layer_count = 0; |
| 475 | |
| 476 | return VK_SUCCESS; |
| 477 | } |
| 478 | |
Chia-I Wu | 3e6c2d6 | 2016-04-11 13:55:56 +0800 | [diff] [blame] | 479 | VkResult CreateInfoWrapper::SanitizeExtensions() { |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 480 | auto& ext_names = (is_instance_) ? instance_info_.ppEnabledExtensionNames |
| 481 | : dev_info_.ppEnabledExtensionNames; |
| 482 | auto& ext_count = (is_instance_) ? instance_info_.enabledExtensionCount |
| 483 | : dev_info_.enabledExtensionCount; |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 484 | |
Chia-I Wu | 3e6c2d6 | 2016-04-11 13:55:56 +0800 | [diff] [blame] | 485 | VkResult result = InitExtensionFilter(); |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 486 | if (result != VK_SUCCESS) |
| 487 | return result; |
| 488 | |
Yiwei Zhang | 2cefa73 | 2020-07-10 21:07:30 -0700 | [diff] [blame] | 489 | if (is_instance_ && icd_api_version_ < loader_api_version_) { |
Yiwei Zhang | 7c0c07c | 2020-07-04 23:49:47 -0700 | [diff] [blame] | 490 | for (uint32_t i = 0; i < ext_count; i++) { |
| 491 | // Upon api downgrade, skip the promoted instance extensions in the |
| 492 | // first pass to avoid duplicate extensions. |
| 493 | const std::optional<uint32_t> version = |
| 494 | GetInstanceExtensionPromotedVersion(ext_names[i]); |
Yiwei Zhang | 2cefa73 | 2020-07-10 21:07:30 -0700 | [diff] [blame] | 495 | if (version && *version > icd_api_version_ && |
Yiwei Zhang | 7c0c07c | 2020-07-04 23:49:47 -0700 | [diff] [blame] | 496 | *version <= loader_api_version_) |
| 497 | continue; |
| 498 | |
| 499 | FilterExtension(ext_names[i]); |
| 500 | } |
| 501 | |
| 502 | // Enable the required extensions to support core functionalities. |
| 503 | const auto promoted_extensions = GetPromotedInstanceExtensions( |
Yiwei Zhang | 2cefa73 | 2020-07-10 21:07:30 -0700 | [diff] [blame] | 504 | icd_api_version_, loader_api_version_); |
Yiwei Zhang | 7c0c07c | 2020-07-04 23:49:47 -0700 | [diff] [blame] | 505 | for (const auto& promoted_extension : promoted_extensions) |
| 506 | FilterExtension(promoted_extension); |
| 507 | } else { |
| 508 | for (uint32_t i = 0; i < ext_count; i++) |
| 509 | FilterExtension(ext_names[i]); |
| 510 | } |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 511 | |
Jesse Hall | d3d887a | 2018-03-05 13:34:45 -0800 | [diff] [blame] | 512 | // Enable device extensions that contain physical-device commands, so that |
| 513 | // vkGetInstanceProcAddr will return those physical-device commands. |
| 514 | if (is_instance_) { |
| 515 | hook_extensions_.set(ProcHook::KHR_swapchain); |
| 516 | } |
| 517 | |
Yiwei Zhang | 2cefa73 | 2020-07-10 21:07:30 -0700 | [diff] [blame] | 518 | const uint32_t api_version = |
| 519 | is_instance_ ? loader_api_version_ |
| 520 | : std::min(icd_api_version_, loader_api_version_); |
| 521 | switch (api_version) { |
Ian Elliott | fa7af49 | 2021-07-20 17:40:24 -0600 | [diff] [blame] | 522 | case VK_API_VERSION_1_2: |
| 523 | hook_extensions_.set(ProcHook::EXTENSION_CORE_1_2); |
| 524 | hal_extensions_.set(ProcHook::EXTENSION_CORE_1_2); |
| 525 | [[clang::fallthrough]]; |
Yiwei Zhang | 2cefa73 | 2020-07-10 21:07:30 -0700 | [diff] [blame] | 526 | case VK_API_VERSION_1_1: |
| 527 | hook_extensions_.set(ProcHook::EXTENSION_CORE_1_1); |
| 528 | hal_extensions_.set(ProcHook::EXTENSION_CORE_1_1); |
| 529 | [[clang::fallthrough]]; |
| 530 | case VK_API_VERSION_1_0: |
| 531 | hook_extensions_.set(ProcHook::EXTENSION_CORE_1_0); |
| 532 | hal_extensions_.set(ProcHook::EXTENSION_CORE_1_0); |
| 533 | break; |
| 534 | default: |
| 535 | ALOGE("Unknown API version[%u]", api_version); |
| 536 | break; |
| 537 | } |
| 538 | |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 539 | ext_names = extension_filter_.names; |
| 540 | ext_count = extension_filter_.name_count; |
| 541 | |
| 542 | return VK_SUCCESS; |
| 543 | } |
| 544 | |
Chia-I Wu | 3e6c2d6 | 2016-04-11 13:55:56 +0800 | [diff] [blame] | 545 | VkResult CreateInfoWrapper::QueryExtensionCount(uint32_t& count) const { |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 546 | if (is_instance_) { |
Chia-I Wu | 31b2e4f | 2016-05-23 10:47:57 +0800 | [diff] [blame] | 547 | return Hal::Device().EnumerateInstanceExtensionProperties( |
| 548 | nullptr, &count, nullptr); |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 549 | } else { |
| 550 | const auto& driver = GetData(physical_dev_).driver; |
| 551 | return driver.EnumerateDeviceExtensionProperties(physical_dev_, nullptr, |
| 552 | &count, nullptr); |
| 553 | } |
| 554 | } |
| 555 | |
Chia-I Wu | 3e6c2d6 | 2016-04-11 13:55:56 +0800 | [diff] [blame] | 556 | VkResult CreateInfoWrapper::EnumerateExtensions( |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 557 | uint32_t& count, |
| 558 | VkExtensionProperties* props) const { |
| 559 | if (is_instance_) { |
Chia-I Wu | 31b2e4f | 2016-05-23 10:47:57 +0800 | [diff] [blame] | 560 | return Hal::Device().EnumerateInstanceExtensionProperties( |
| 561 | nullptr, &count, props); |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 562 | } else { |
| 563 | const auto& driver = GetData(physical_dev_).driver; |
| 564 | return driver.EnumerateDeviceExtensionProperties(physical_dev_, nullptr, |
| 565 | &count, props); |
| 566 | } |
| 567 | } |
| 568 | |
Chia-I Wu | 3e6c2d6 | 2016-04-11 13:55:56 +0800 | [diff] [blame] | 569 | VkResult CreateInfoWrapper::InitExtensionFilter() { |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 570 | // query extension count |
| 571 | uint32_t count; |
Chia-I Wu | 3e6c2d6 | 2016-04-11 13:55:56 +0800 | [diff] [blame] | 572 | VkResult result = QueryExtensionCount(count); |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 573 | if (result != VK_SUCCESS || count == 0) |
| 574 | return result; |
| 575 | |
| 576 | auto& filter = extension_filter_; |
| 577 | filter.exts = |
| 578 | reinterpret_cast<VkExtensionProperties*>(allocator_.pfnAllocation( |
| 579 | allocator_.pUserData, sizeof(VkExtensionProperties) * count, |
| 580 | alignof(VkExtensionProperties), |
| 581 | VK_SYSTEM_ALLOCATION_SCOPE_COMMAND)); |
| 582 | if (!filter.exts) |
| 583 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 584 | |
| 585 | // enumerate extensions |
Chia-I Wu | 3e6c2d6 | 2016-04-11 13:55:56 +0800 | [diff] [blame] | 586 | result = EnumerateExtensions(count, filter.exts); |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 587 | if (result != VK_SUCCESS && result != VK_INCOMPLETE) |
| 588 | return result; |
| 589 | |
| 590 | if (!count) |
| 591 | return VK_SUCCESS; |
| 592 | |
| 593 | filter.ext_count = count; |
| 594 | |
| 595 | // allocate name array |
Yiwei Zhang | 7c0c07c | 2020-07-04 23:49:47 -0700 | [diff] [blame] | 596 | if (is_instance_) { |
| 597 | uint32_t enabled_ext_count = instance_info_.enabledExtensionCount; |
| 598 | |
| 599 | // It requires enabling additional promoted extensions to downgrade api, |
| 600 | // so we reserve enough space here. |
Yiwei Zhang | 2cefa73 | 2020-07-10 21:07:30 -0700 | [diff] [blame] | 601 | if (icd_api_version_ < loader_api_version_) { |
Yiwei Zhang | 7c0c07c | 2020-07-04 23:49:47 -0700 | [diff] [blame] | 602 | enabled_ext_count += CountPromotedInstanceExtensions( |
Yiwei Zhang | 2cefa73 | 2020-07-10 21:07:30 -0700 | [diff] [blame] | 603 | icd_api_version_, loader_api_version_); |
Yiwei Zhang | 7c0c07c | 2020-07-04 23:49:47 -0700 | [diff] [blame] | 604 | } |
| 605 | |
| 606 | count = std::min(filter.ext_count, enabled_ext_count); |
| 607 | } else { |
| 608 | count = std::min(filter.ext_count, dev_info_.enabledExtensionCount); |
| 609 | } |
Yiwei Zhang | d7ea44a | 2020-08-13 12:54:27 -0700 | [diff] [blame] | 610 | |
| 611 | if (!count) |
| 612 | return VK_SUCCESS; |
| 613 | |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 614 | filter.names = reinterpret_cast<const char**>(allocator_.pfnAllocation( |
| 615 | allocator_.pUserData, sizeof(const char*) * count, alignof(const char*), |
| 616 | VK_SYSTEM_ALLOCATION_SCOPE_COMMAND)); |
| 617 | if (!filter.names) |
| 618 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 619 | |
| 620 | return VK_SUCCESS; |
| 621 | } |
| 622 | |
Chia-I Wu | 3e6c2d6 | 2016-04-11 13:55:56 +0800 | [diff] [blame] | 623 | void CreateInfoWrapper::FilterExtension(const char* name) { |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 624 | auto& filter = extension_filter_; |
| 625 | |
| 626 | ProcHook::Extension ext_bit = GetProcHookExtension(name); |
| 627 | if (is_instance_) { |
| 628 | switch (ext_bit) { |
| 629 | case ProcHook::KHR_android_surface: |
| 630 | case ProcHook::KHR_surface: |
Courtney Goeltzenleuchter | e278daf | 2017-02-02 16:54:57 -0700 | [diff] [blame] | 631 | case ProcHook::EXT_swapchain_colorspace: |
Chris Forbes | 2452cf7 | 2017-03-16 16:30:17 +1300 | [diff] [blame] | 632 | case ProcHook::KHR_get_surface_capabilities2: |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 633 | hook_extensions_.set(ext_bit); |
| 634 | // return now as these extensions do not require HAL support |
| 635 | return; |
| 636 | case ProcHook::EXT_debug_report: |
| 637 | // both we and HAL can take part in |
| 638 | hook_extensions_.set(ext_bit); |
| 639 | break; |
Chris Forbes | 6aa30db | 2017-02-20 17:12:53 +1300 | [diff] [blame] | 640 | case ProcHook::KHR_get_physical_device_properties2: |
Yiwei Zhang | e4f6417 | 2020-07-05 15:17:32 -0700 | [diff] [blame] | 641 | case ProcHook::KHR_device_group_creation: |
Yiwei Zhang | e1f3501 | 2020-07-05 22:52:04 -0700 | [diff] [blame] | 642 | case ProcHook::KHR_external_memory_capabilities: |
| 643 | case ProcHook::KHR_external_semaphore_capabilities: |
| 644 | case ProcHook::KHR_external_fence_capabilities: |
Jesse Hall | 7f983a8 | 2018-03-29 14:46:45 -0700 | [diff] [blame] | 645 | case ProcHook::EXTENSION_UNKNOWN: |
| 646 | // Extensions we don't need to do anything about at this level |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 647 | break; |
Jesse Hall | 7f983a8 | 2018-03-29 14:46:45 -0700 | [diff] [blame] | 648 | |
Yiwei Zhang | 2314310 | 2019-04-10 18:24:05 -0700 | [diff] [blame] | 649 | case ProcHook::KHR_bind_memory2: |
Jesse Hall | 7f983a8 | 2018-03-29 14:46:45 -0700 | [diff] [blame] | 650 | case ProcHook::KHR_incremental_present: |
| 651 | case ProcHook::KHR_shared_presentable_image: |
| 652 | case ProcHook::KHR_swapchain: |
| 653 | case ProcHook::EXT_hdr_metadata: |
| 654 | case ProcHook::ANDROID_external_memory_android_hardware_buffer: |
| 655 | case ProcHook::ANDROID_native_buffer: |
| 656 | case ProcHook::GOOGLE_display_timing: |
Yiwei Zhang | 7cc36a5 | 2019-10-11 19:02:09 -0700 | [diff] [blame] | 657 | case ProcHook::EXTENSION_CORE_1_0: |
| 658 | case ProcHook::EXTENSION_CORE_1_1: |
Yiwei Zhang | 6be097b | 2020-10-19 20:22:05 -0700 | [diff] [blame] | 659 | case ProcHook::EXTENSION_CORE_1_2: |
Jesse Hall | 7f983a8 | 2018-03-29 14:46:45 -0700 | [diff] [blame] | 660 | case ProcHook::EXTENSION_COUNT: |
| 661 | // Device and meta extensions. If we ever get here it's a bug in |
| 662 | // our code. But enumerating them lets us avoid having a default |
| 663 | // case, and default hides other bugs. |
| 664 | ALOGE( |
| 665 | "CreateInfoWrapper::FilterExtension: invalid instance " |
| 666 | "extension '%s'. FIX ME", |
| 667 | name); |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 668 | return; |
Jesse Hall | 7f983a8 | 2018-03-29 14:46:45 -0700 | [diff] [blame] | 669 | |
| 670 | // Don't use a default case. Without it, -Wswitch will tell us |
| 671 | // at compile time if someone adds a new ProcHook extension but |
| 672 | // doesn't handle it above. That's a real bug that has |
| 673 | // not-immediately-obvious effects. |
| 674 | // |
| 675 | // default: |
| 676 | // break; |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 677 | } |
| 678 | } else { |
| 679 | switch (ext_bit) { |
| 680 | case ProcHook::KHR_swapchain: |
| 681 | // map VK_KHR_swapchain to VK_ANDROID_native_buffer |
| 682 | name = VK_ANDROID_NATIVE_BUFFER_EXTENSION_NAME; |
| 683 | ext_bit = ProcHook::ANDROID_native_buffer; |
| 684 | break; |
Ian Elliott | 9e85373 | 2017-02-03 11:24:07 -0700 | [diff] [blame] | 685 | case ProcHook::KHR_incremental_present: |
Ian Elliott | 8a97726 | 2017-01-19 09:05:58 -0700 | [diff] [blame] | 686 | case ProcHook::GOOGLE_display_timing: |
Chris Forbes | fa25e63 | 2017-02-22 12:36:02 +1300 | [diff] [blame] | 687 | case ProcHook::KHR_shared_presentable_image: |
Ian Elliott | 8a97726 | 2017-01-19 09:05:58 -0700 | [diff] [blame] | 688 | hook_extensions_.set(ext_bit); |
| 689 | // return now as these extensions do not require HAL support |
| 690 | return; |
Courtney Goeltzenleuchter | d634c48 | 2017-01-05 15:55:31 -0700 | [diff] [blame] | 691 | case ProcHook::EXT_hdr_metadata: |
Yiwei Zhang | 2314310 | 2019-04-10 18:24:05 -0700 | [diff] [blame] | 692 | case ProcHook::KHR_bind_memory2: |
Courtney Goeltzenleuchter | d634c48 | 2017-01-05 15:55:31 -0700 | [diff] [blame] | 693 | hook_extensions_.set(ext_bit); |
| 694 | break; |
Jesse Hall | 7f983a8 | 2018-03-29 14:46:45 -0700 | [diff] [blame] | 695 | case ProcHook::ANDROID_external_memory_android_hardware_buffer: |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 696 | case ProcHook::EXTENSION_UNKNOWN: |
Jesse Hall | 7f983a8 | 2018-03-29 14:46:45 -0700 | [diff] [blame] | 697 | // Extensions we don't need to do anything about at this level |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 698 | break; |
Jesse Hall | 7f983a8 | 2018-03-29 14:46:45 -0700 | [diff] [blame] | 699 | |
| 700 | case ProcHook::KHR_android_surface: |
| 701 | case ProcHook::KHR_get_physical_device_properties2: |
Yiwei Zhang | e4f6417 | 2020-07-05 15:17:32 -0700 | [diff] [blame] | 702 | case ProcHook::KHR_device_group_creation: |
Yiwei Zhang | e1f3501 | 2020-07-05 22:52:04 -0700 | [diff] [blame] | 703 | case ProcHook::KHR_external_memory_capabilities: |
| 704 | case ProcHook::KHR_external_semaphore_capabilities: |
| 705 | case ProcHook::KHR_external_fence_capabilities: |
Jesse Hall | 7f983a8 | 2018-03-29 14:46:45 -0700 | [diff] [blame] | 706 | case ProcHook::KHR_get_surface_capabilities2: |
| 707 | case ProcHook::KHR_surface: |
| 708 | case ProcHook::EXT_debug_report: |
| 709 | case ProcHook::EXT_swapchain_colorspace: |
| 710 | case ProcHook::ANDROID_native_buffer: |
Yiwei Zhang | 7cc36a5 | 2019-10-11 19:02:09 -0700 | [diff] [blame] | 711 | case ProcHook::EXTENSION_CORE_1_0: |
| 712 | case ProcHook::EXTENSION_CORE_1_1: |
Yiwei Zhang | 6be097b | 2020-10-19 20:22:05 -0700 | [diff] [blame] | 713 | case ProcHook::EXTENSION_CORE_1_2: |
Jesse Hall | 7f983a8 | 2018-03-29 14:46:45 -0700 | [diff] [blame] | 714 | case ProcHook::EXTENSION_COUNT: |
| 715 | // Instance and meta extensions. If we ever get here it's a bug |
| 716 | // in our code. But enumerating them lets us avoid having a |
| 717 | // default case, and default hides other bugs. |
| 718 | ALOGE( |
| 719 | "CreateInfoWrapper::FilterExtension: invalid device " |
| 720 | "extension '%s'. FIX ME", |
| 721 | name); |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 722 | return; |
Jesse Hall | 7f983a8 | 2018-03-29 14:46:45 -0700 | [diff] [blame] | 723 | |
| 724 | // Don't use a default case. Without it, -Wswitch will tell us |
| 725 | // at compile time if someone adds a new ProcHook extension but |
| 726 | // doesn't handle it above. That's a real bug that has |
| 727 | // not-immediately-obvious effects. |
| 728 | // |
| 729 | // default: |
| 730 | // break; |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 731 | } |
| 732 | } |
| 733 | |
| 734 | for (uint32_t i = 0; i < filter.ext_count; i++) { |
| 735 | const VkExtensionProperties& props = filter.exts[i]; |
| 736 | // ignore unknown extensions |
| 737 | if (strcmp(name, props.extensionName) != 0) |
| 738 | continue; |
| 739 | |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 740 | filter.names[filter.name_count++] = name; |
Chia-I Wu | 1600e26 | 2016-04-12 09:40:06 +0800 | [diff] [blame] | 741 | if (ext_bit != ProcHook::EXTENSION_UNKNOWN) { |
| 742 | if (ext_bit == ProcHook::ANDROID_native_buffer) |
| 743 | hook_extensions_.set(ProcHook::KHR_swapchain); |
| 744 | |
| 745 | hal_extensions_.set(ext_bit); |
| 746 | } |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 747 | |
| 748 | break; |
| 749 | } |
| 750 | } |
| 751 | |
Chia-I Wu | dbb7e9c | 2016-03-24 15:09:38 +0800 | [diff] [blame] | 752 | VKAPI_ATTR void* DefaultAllocate(void*, |
| 753 | size_t size, |
| 754 | size_t alignment, |
| 755 | VkSystemAllocationScope) { |
| 756 | void* ptr = nullptr; |
| 757 | // Vulkan requires 'alignment' to be a power of two, but posix_memalign |
| 758 | // additionally requires that it be at least sizeof(void*). |
| 759 | int ret = posix_memalign(&ptr, std::max(alignment, sizeof(void*)), size); |
| 760 | ALOGD_CALLSTACK("Allocate: size=%zu align=%zu => (%d) %p", size, alignment, |
| 761 | ret, ptr); |
| 762 | return ret == 0 ? ptr : nullptr; |
| 763 | } |
| 764 | |
| 765 | VKAPI_ATTR void* DefaultReallocate(void*, |
| 766 | void* ptr, |
| 767 | size_t size, |
| 768 | size_t alignment, |
| 769 | VkSystemAllocationScope) { |
| 770 | if (size == 0) { |
| 771 | free(ptr); |
| 772 | return nullptr; |
| 773 | } |
| 774 | |
Yiwei Zhang | a885c06 | 2019-10-24 12:07:57 -0700 | [diff] [blame] | 775 | // TODO(b/143295633): Right now we never shrink allocations; if the new |
Chia-I Wu | dbb7e9c | 2016-03-24 15:09:38 +0800 | [diff] [blame] | 776 | // request is smaller than the existing chunk, we just continue using it. |
| 777 | // Right now the loader never reallocs, so this doesn't matter. If that |
| 778 | // changes, or if this code is copied into some other project, this should |
| 779 | // probably have a heuristic to allocate-copy-free when doing so will save |
| 780 | // "enough" space. |
| 781 | size_t old_size = ptr ? malloc_usable_size(ptr) : 0; |
| 782 | if (size <= old_size) |
| 783 | return ptr; |
| 784 | |
| 785 | void* new_ptr = nullptr; |
| 786 | if (posix_memalign(&new_ptr, std::max(alignment, sizeof(void*)), size) != 0) |
| 787 | return nullptr; |
| 788 | if (ptr) { |
| 789 | memcpy(new_ptr, ptr, std::min(old_size, size)); |
| 790 | free(ptr); |
| 791 | } |
| 792 | return new_ptr; |
| 793 | } |
| 794 | |
| 795 | VKAPI_ATTR void DefaultFree(void*, void* ptr) { |
| 796 | ALOGD_CALLSTACK("Free: %p", ptr); |
| 797 | free(ptr); |
| 798 | } |
| 799 | |
Chia-I Wu | ff4a6c7 | 2016-03-24 16:05:56 +0800 | [diff] [blame] | 800 | InstanceData* AllocateInstanceData(const VkAllocationCallbacks& allocator) { |
| 801 | void* data_mem = allocator.pfnAllocation( |
| 802 | allocator.pUserData, sizeof(InstanceData), alignof(InstanceData), |
| 803 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
| 804 | if (!data_mem) |
| 805 | return nullptr; |
| 806 | |
| 807 | return new (data_mem) InstanceData(allocator); |
| 808 | } |
| 809 | |
| 810 | void FreeInstanceData(InstanceData* data, |
| 811 | const VkAllocationCallbacks& allocator) { |
| 812 | data->~InstanceData(); |
| 813 | allocator.pfnFree(allocator.pUserData, data); |
| 814 | } |
| 815 | |
Chia-I Wu | 950d6e1 | 2016-05-03 09:12:35 +0800 | [diff] [blame] | 816 | DeviceData* AllocateDeviceData( |
| 817 | const VkAllocationCallbacks& allocator, |
| 818 | const DebugReportCallbackList& debug_report_callbacks) { |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 819 | void* data_mem = allocator.pfnAllocation( |
| 820 | allocator.pUserData, sizeof(DeviceData), alignof(DeviceData), |
| 821 | VK_SYSTEM_ALLOCATION_SCOPE_DEVICE); |
| 822 | if (!data_mem) |
| 823 | return nullptr; |
| 824 | |
Chia-I Wu | 950d6e1 | 2016-05-03 09:12:35 +0800 | [diff] [blame] | 825 | return new (data_mem) DeviceData(allocator, debug_report_callbacks); |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 826 | } |
| 827 | |
| 828 | void FreeDeviceData(DeviceData* data, const VkAllocationCallbacks& allocator) { |
| 829 | data->~DeviceData(); |
| 830 | allocator.pfnFree(allocator.pUserData, data); |
| 831 | } |
| 832 | |
Chia-I Wu | 136b8eb | 2016-03-24 15:01:52 +0800 | [diff] [blame] | 833 | } // anonymous namespace |
| 834 | |
Chia-I Wu | 136b8eb | 2016-03-24 15:01:52 +0800 | [diff] [blame] | 835 | bool OpenHAL() { |
Chia-I Wu | 31b2e4f | 2016-05-23 10:47:57 +0800 | [diff] [blame] | 836 | return Hal::Open(); |
Chia-I Wu | 136b8eb | 2016-03-24 15:01:52 +0800 | [diff] [blame] | 837 | } |
| 838 | |
Chia-I Wu | dbb7e9c | 2016-03-24 15:09:38 +0800 | [diff] [blame] | 839 | const VkAllocationCallbacks& GetDefaultAllocator() { |
| 840 | static const VkAllocationCallbacks kDefaultAllocCallbacks = { |
| 841 | .pUserData = nullptr, |
| 842 | .pfnAllocation = DefaultAllocate, |
| 843 | .pfnReallocation = DefaultReallocate, |
| 844 | .pfnFree = DefaultFree, |
| 845 | }; |
| 846 | |
| 847 | return kDefaultAllocCallbacks; |
| 848 | } |
| 849 | |
Chia-I Wu | eb7db12 | 2016-03-24 09:11:06 +0800 | [diff] [blame] | 850 | PFN_vkVoidFunction GetInstanceProcAddr(VkInstance instance, const char* pName) { |
| 851 | const ProcHook* hook = GetProcHook(pName); |
| 852 | if (!hook) |
Chia-I Wu | 31b2e4f | 2016-05-23 10:47:57 +0800 | [diff] [blame] | 853 | return Hal::Device().GetInstanceProcAddr(instance, pName); |
Chia-I Wu | eb7db12 | 2016-03-24 09:11:06 +0800 | [diff] [blame] | 854 | |
| 855 | if (!instance) { |
| 856 | if (hook->type == ProcHook::GLOBAL) |
| 857 | return hook->proc; |
| 858 | |
Chia-I Wu | 109f898 | 2016-04-22 06:40:40 +0800 | [diff] [blame] | 859 | // v0 layers expect |
| 860 | // |
| 861 | // vkGetInstanceProcAddr(VK_NULL_HANDLE, "vkCreateDevice"); |
| 862 | // |
| 863 | // to work. |
| 864 | if (strcmp(pName, "vkCreateDevice") == 0) |
| 865 | return hook->proc; |
| 866 | |
Chia-I Wu | eb7db12 | 2016-03-24 09:11:06 +0800 | [diff] [blame] | 867 | ALOGE( |
Chia-I Wu | e201c3f | 2016-05-03 13:26:08 +0800 | [diff] [blame] | 868 | "internal vkGetInstanceProcAddr called for %s without an instance", |
Chia-I Wu | eb7db12 | 2016-03-24 09:11:06 +0800 | [diff] [blame] | 869 | pName); |
| 870 | |
Chia-I Wu | 109f898 | 2016-04-22 06:40:40 +0800 | [diff] [blame] | 871 | return nullptr; |
Chia-I Wu | eb7db12 | 2016-03-24 09:11:06 +0800 | [diff] [blame] | 872 | } |
| 873 | |
| 874 | PFN_vkVoidFunction proc; |
| 875 | |
| 876 | switch (hook->type) { |
| 877 | case ProcHook::INSTANCE: |
| 878 | proc = (GetData(instance).hook_extensions[hook->extension]) |
| 879 | ? hook->proc |
Chia-I Wu | 36cc00a | 2016-04-13 16:52:06 +0800 | [diff] [blame] | 880 | : nullptr; |
Chia-I Wu | eb7db12 | 2016-03-24 09:11:06 +0800 | [diff] [blame] | 881 | break; |
| 882 | case ProcHook::DEVICE: |
Yiwei Zhang | 7cc36a5 | 2019-10-11 19:02:09 -0700 | [diff] [blame] | 883 | proc = (hook->extension == ProcHook::EXTENSION_CORE_1_0) |
Chia-I Wu | eb7db12 | 2016-03-24 09:11:06 +0800 | [diff] [blame] | 884 | ? hook->proc |
| 885 | : hook->checked_proc; |
| 886 | break; |
| 887 | default: |
| 888 | ALOGE( |
Chia-I Wu | e201c3f | 2016-05-03 13:26:08 +0800 | [diff] [blame] | 889 | "internal vkGetInstanceProcAddr called for %s with an instance", |
Chia-I Wu | eb7db12 | 2016-03-24 09:11:06 +0800 | [diff] [blame] | 890 | pName); |
| 891 | proc = nullptr; |
| 892 | break; |
| 893 | } |
| 894 | |
| 895 | return proc; |
| 896 | } |
| 897 | |
| 898 | PFN_vkVoidFunction GetDeviceProcAddr(VkDevice device, const char* pName) { |
| 899 | const ProcHook* hook = GetProcHook(pName); |
| 900 | if (!hook) |
Chia-I Wu | cc5e276 | 2016-03-24 13:01:16 +0800 | [diff] [blame] | 901 | return GetData(device).driver.GetDeviceProcAddr(device, pName); |
Chia-I Wu | eb7db12 | 2016-03-24 09:11:06 +0800 | [diff] [blame] | 902 | |
| 903 | if (hook->type != ProcHook::DEVICE) { |
Chia-I Wu | e201c3f | 2016-05-03 13:26:08 +0800 | [diff] [blame] | 904 | ALOGE("internal vkGetDeviceProcAddr called for %s", pName); |
Chia-I Wu | eb7db12 | 2016-03-24 09:11:06 +0800 | [diff] [blame] | 905 | return nullptr; |
| 906 | } |
| 907 | |
Chia-I Wu | 36cc00a | 2016-04-13 16:52:06 +0800 | [diff] [blame] | 908 | return (GetData(device).hook_extensions[hook->extension]) ? hook->proc |
| 909 | : nullptr; |
Chia-I Wu | eb7db12 | 2016-03-24 09:11:06 +0800 | [diff] [blame] | 910 | } |
| 911 | |
Chia-I Wu | ff4a6c7 | 2016-03-24 16:05:56 +0800 | [diff] [blame] | 912 | VkResult EnumerateInstanceExtensionProperties( |
| 913 | const char* pLayerName, |
| 914 | uint32_t* pPropertyCount, |
| 915 | VkExtensionProperties* pProperties) { |
Yiwei Zhang | 5e86220 | 2019-06-21 14:59:16 -0700 | [diff] [blame] | 916 | std::vector<VkExtensionProperties> loader_extensions; |
Ian Elliott | 34a327b | 2017-03-28 13:20:35 -0600 | [diff] [blame] | 917 | loader_extensions.push_back({ |
| 918 | VK_KHR_SURFACE_EXTENSION_NAME, |
| 919 | VK_KHR_SURFACE_SPEC_VERSION}); |
| 920 | loader_extensions.push_back({ |
| 921 | VK_KHR_ANDROID_SURFACE_EXTENSION_NAME, |
| 922 | VK_KHR_ANDROID_SURFACE_SPEC_VERSION}); |
| 923 | loader_extensions.push_back({ |
| 924 | VK_EXT_SWAPCHAIN_COLOR_SPACE_EXTENSION_NAME, |
| 925 | VK_EXT_SWAPCHAIN_COLOR_SPACE_SPEC_VERSION}); |
Chris Forbes | 1609500 | 2017-05-05 15:33:29 -0700 | [diff] [blame] | 926 | loader_extensions.push_back({ |
| 927 | VK_KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME, |
| 928 | VK_KHR_GET_SURFACE_CAPABILITIES_2_SPEC_VERSION}); |
Ian Elliott | 34a327b | 2017-03-28 13:20:35 -0600 | [diff] [blame] | 929 | |
Chia-I Wu | 3193825 | 2016-05-23 15:31:02 +0800 | [diff] [blame] | 930 | static const VkExtensionProperties loader_debug_report_extension = { |
| 931 | VK_EXT_DEBUG_REPORT_EXTENSION_NAME, VK_EXT_DEBUG_REPORT_SPEC_VERSION, |
| 932 | }; |
Chia-I Wu | ff4a6c7 | 2016-03-24 16:05:56 +0800 | [diff] [blame] | 933 | |
| 934 | // enumerate our extensions first |
| 935 | if (!pLayerName && pProperties) { |
| 936 | uint32_t count = std::min( |
| 937 | *pPropertyCount, static_cast<uint32_t>(loader_extensions.size())); |
| 938 | |
Yiwei Zhang | 5e86220 | 2019-06-21 14:59:16 -0700 | [diff] [blame] | 939 | std::copy_n(loader_extensions.data(), count, pProperties); |
Chia-I Wu | ff4a6c7 | 2016-03-24 16:05:56 +0800 | [diff] [blame] | 940 | |
| 941 | if (count < loader_extensions.size()) { |
| 942 | *pPropertyCount = count; |
| 943 | return VK_INCOMPLETE; |
| 944 | } |
| 945 | |
| 946 | pProperties += count; |
| 947 | *pPropertyCount -= count; |
Chia-I Wu | 3193825 | 2016-05-23 15:31:02 +0800 | [diff] [blame] | 948 | |
| 949 | if (Hal::Get().GetDebugReportIndex() < 0) { |
| 950 | if (!*pPropertyCount) { |
| 951 | *pPropertyCount = count; |
| 952 | return VK_INCOMPLETE; |
| 953 | } |
| 954 | |
| 955 | pProperties[0] = loader_debug_report_extension; |
| 956 | pProperties += 1; |
| 957 | *pPropertyCount -= 1; |
| 958 | } |
Chia-I Wu | ff4a6c7 | 2016-03-24 16:05:56 +0800 | [diff] [blame] | 959 | } |
| 960 | |
Yiwei Zhang | fdd0c2a | 2019-01-30 20:16:37 -0800 | [diff] [blame] | 961 | ATRACE_BEGIN("driver.EnumerateInstanceExtensionProperties"); |
Chia-I Wu | 31b2e4f | 2016-05-23 10:47:57 +0800 | [diff] [blame] | 962 | VkResult result = Hal::Device().EnumerateInstanceExtensionProperties( |
Chia-I Wu | ff4a6c7 | 2016-03-24 16:05:56 +0800 | [diff] [blame] | 963 | pLayerName, pPropertyCount, pProperties); |
Yiwei Zhang | fdd0c2a | 2019-01-30 20:16:37 -0800 | [diff] [blame] | 964 | ATRACE_END(); |
Chia-I Wu | ff4a6c7 | 2016-03-24 16:05:56 +0800 | [diff] [blame] | 965 | |
Chia-I Wu | 3193825 | 2016-05-23 15:31:02 +0800 | [diff] [blame] | 966 | if (!pLayerName && (result == VK_SUCCESS || result == VK_INCOMPLETE)) { |
| 967 | int idx = Hal::Get().GetDebugReportIndex(); |
| 968 | if (idx < 0) { |
| 969 | *pPropertyCount += 1; |
| 970 | } else if (pProperties && |
| 971 | static_cast<uint32_t>(idx) < *pPropertyCount) { |
| 972 | pProperties[idx].specVersion = |
| 973 | std::min(pProperties[idx].specVersion, |
| 974 | loader_debug_report_extension.specVersion); |
| 975 | } |
| 976 | |
Chia-I Wu | ff4a6c7 | 2016-03-24 16:05:56 +0800 | [diff] [blame] | 977 | *pPropertyCount += loader_extensions.size(); |
Chia-I Wu | 3193825 | 2016-05-23 15:31:02 +0800 | [diff] [blame] | 978 | } |
Chia-I Wu | ff4a6c7 | 2016-03-24 16:05:56 +0800 | [diff] [blame] | 979 | |
| 980 | return result; |
| 981 | } |
| 982 | |
Yiwei Zhang | 93b521c | 2020-07-11 16:32:09 -0700 | [diff] [blame] | 983 | void QueryPresentationProperties( |
Chris Forbes | fa25e63 | 2017-02-22 12:36:02 +1300 | [diff] [blame] | 984 | VkPhysicalDevice physicalDevice, |
Yiwei Zhang | 93b521c | 2020-07-11 16:32:09 -0700 | [diff] [blame] | 985 | VkPhysicalDevicePresentationPropertiesANDROID* presentation_properties) { |
Chris Forbes | e056c12 | 2021-07-22 13:54:04 -0700 | [diff] [blame] | 986 | ATRACE_CALL(); |
| 987 | |
Chris Forbes | fa25e63 | 2017-02-22 12:36:02 +1300 | [diff] [blame] | 988 | // Request the android-specific presentation properties via GPDP2 |
Yiwei Zhang | 93b521c | 2020-07-11 16:32:09 -0700 | [diff] [blame] | 989 | VkPhysicalDeviceProperties2 properties = { |
| 990 | VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2, |
Chris Forbes | fa25e63 | 2017-02-22 12:36:02 +1300 | [diff] [blame] | 991 | presentation_properties, |
Yiwei Zhang | 93b521c | 2020-07-11 16:32:09 -0700 | [diff] [blame] | 992 | {}, |
Chris Forbes | fa25e63 | 2017-02-22 12:36:02 +1300 | [diff] [blame] | 993 | }; |
| 994 | |
| 995 | #pragma clang diagnostic push |
| 996 | #pragma clang diagnostic ignored "-Wold-style-cast" |
| 997 | presentation_properties->sType = |
| 998 | VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRESENTATION_PROPERTIES_ANDROID; |
| 999 | #pragma clang diagnostic pop |
| 1000 | presentation_properties->pNext = nullptr; |
| 1001 | presentation_properties->sharedImage = VK_FALSE; |
| 1002 | |
Chris Forbes | e056c12 | 2021-07-22 13:54:04 -0700 | [diff] [blame] | 1003 | const auto& driver = GetData(physicalDevice).driver; |
| 1004 | |
| 1005 | if (driver.GetPhysicalDeviceProperties2) { |
| 1006 | // >= 1.1 driver, supports core GPDP2 entrypoint. |
| 1007 | driver.GetPhysicalDeviceProperties2(physicalDevice, &properties); |
| 1008 | } else if (driver.GetPhysicalDeviceProperties2KHR) { |
| 1009 | // Old driver, but may support presentation properties |
| 1010 | // if we have the GPDP2 extension. Otherwise, no presentation |
| 1011 | // properties supported. |
| 1012 | driver.GetPhysicalDeviceProperties2KHR(physicalDevice, &properties); |
| 1013 | } |
Chris Forbes | fa25e63 | 2017-02-22 12:36:02 +1300 | [diff] [blame] | 1014 | } |
| 1015 | |
Chia-I Wu | 01cf305 | 2016-03-24 16:16:21 +0800 | [diff] [blame] | 1016 | VkResult EnumerateDeviceExtensionProperties( |
| 1017 | VkPhysicalDevice physicalDevice, |
| 1018 | const char* pLayerName, |
| 1019 | uint32_t* pPropertyCount, |
| 1020 | VkExtensionProperties* pProperties) { |
| 1021 | const InstanceData& data = GetData(physicalDevice); |
Chris Forbes | fa25e63 | 2017-02-22 12:36:02 +1300 | [diff] [blame] | 1022 | // extensions that are unconditionally exposed by the loader |
Yiwei Zhang | 5e86220 | 2019-06-21 14:59:16 -0700 | [diff] [blame] | 1023 | std::vector<VkExtensionProperties> loader_extensions; |
Chris Forbes | fa25e63 | 2017-02-22 12:36:02 +1300 | [diff] [blame] | 1024 | loader_extensions.push_back({ |
| 1025 | VK_KHR_INCREMENTAL_PRESENT_EXTENSION_NAME, |
| 1026 | VK_KHR_INCREMENTAL_PRESENT_SPEC_VERSION}); |
Chris Forbes | fa25e63 | 2017-02-22 12:36:02 +1300 | [diff] [blame] | 1027 | |
Sundong Ahn | bc37dd5 | 2020-04-23 21:21:00 +0900 | [diff] [blame] | 1028 | bool hdrBoardConfig = android::sysprop::has_HDR_display(false); |
Courtney Goeltzenleuchter | 7671d46 | 2018-01-24 11:51:01 -0800 | [diff] [blame] | 1029 | if (hdrBoardConfig) { |
| 1030 | loader_extensions.push_back({VK_EXT_HDR_METADATA_EXTENSION_NAME, |
| 1031 | VK_EXT_HDR_METADATA_SPEC_VERSION}); |
| 1032 | } |
| 1033 | |
Chris Forbes | 1609500 | 2017-05-05 15:33:29 -0700 | [diff] [blame] | 1034 | VkPhysicalDevicePresentationPropertiesANDROID presentation_properties; |
Yiwei Zhang | 93b521c | 2020-07-11 16:32:09 -0700 | [diff] [blame] | 1035 | QueryPresentationProperties(physicalDevice, &presentation_properties); |
| 1036 | if (presentation_properties.sharedImage) { |
Chris Forbes | 1609500 | 2017-05-05 15:33:29 -0700 | [diff] [blame] | 1037 | loader_extensions.push_back({ |
| 1038 | VK_KHR_SHARED_PRESENTABLE_IMAGE_EXTENSION_NAME, |
| 1039 | VK_KHR_SHARED_PRESENTABLE_IMAGE_SPEC_VERSION}); |
Chris Forbes | fa25e63 | 2017-02-22 12:36:02 +1300 | [diff] [blame] | 1040 | } |
Ian Elliott | d4b50aa | 2017-01-09 16:21:36 -0700 | [diff] [blame] | 1041 | |
Ian Elliott | 5c34de2 | 2017-04-10 14:42:30 -0600 | [diff] [blame] | 1042 | // conditionally add VK_GOOGLE_display_timing if present timestamps are |
| 1043 | // supported by the driver: |
Yiwei Zhang | 98d15e0 | 2020-08-15 13:48:36 -0700 | [diff] [blame] | 1044 | if (android::base::GetBoolProperty("service.sf.present_timestamp", false)) { |
Ian Elliott | 5c34de2 | 2017-04-10 14:42:30 -0600 | [diff] [blame] | 1045 | loader_extensions.push_back({ |
| 1046 | VK_GOOGLE_DISPLAY_TIMING_EXTENSION_NAME, |
| 1047 | VK_GOOGLE_DISPLAY_TIMING_SPEC_VERSION}); |
| 1048 | } |
| 1049 | |
Ian Elliott | d4b50aa | 2017-01-09 16:21:36 -0700 | [diff] [blame] | 1050 | // enumerate our extensions first |
| 1051 | if (!pLayerName && pProperties) { |
| 1052 | uint32_t count = std::min( |
| 1053 | *pPropertyCount, static_cast<uint32_t>(loader_extensions.size())); |
| 1054 | |
Yiwei Zhang | 5e86220 | 2019-06-21 14:59:16 -0700 | [diff] [blame] | 1055 | std::copy_n(loader_extensions.data(), count, pProperties); |
Ian Elliott | d4b50aa | 2017-01-09 16:21:36 -0700 | [diff] [blame] | 1056 | |
| 1057 | if (count < loader_extensions.size()) { |
| 1058 | *pPropertyCount = count; |
| 1059 | return VK_INCOMPLETE; |
| 1060 | } |
| 1061 | |
| 1062 | pProperties += count; |
| 1063 | *pPropertyCount -= count; |
| 1064 | } |
Chia-I Wu | 01cf305 | 2016-03-24 16:16:21 +0800 | [diff] [blame] | 1065 | |
Yiwei Zhang | fdd0c2a | 2019-01-30 20:16:37 -0800 | [diff] [blame] | 1066 | ATRACE_BEGIN("driver.EnumerateDeviceExtensionProperties"); |
Chia-I Wu | 01cf305 | 2016-03-24 16:16:21 +0800 | [diff] [blame] | 1067 | VkResult result = data.driver.EnumerateDeviceExtensionProperties( |
| 1068 | physicalDevice, pLayerName, pPropertyCount, pProperties); |
Yiwei Zhang | fdd0c2a | 2019-01-30 20:16:37 -0800 | [diff] [blame] | 1069 | ATRACE_END(); |
Chia-I Wu | 01cf305 | 2016-03-24 16:16:21 +0800 | [diff] [blame] | 1070 | |
Ian Elliott | d4b50aa | 2017-01-09 16:21:36 -0700 | [diff] [blame] | 1071 | if (pProperties) { |
| 1072 | // map VK_ANDROID_native_buffer to VK_KHR_swapchain |
| 1073 | for (uint32_t i = 0; i < *pPropertyCount; i++) { |
| 1074 | auto& prop = pProperties[i]; |
Chia-I Wu | 01cf305 | 2016-03-24 16:16:21 +0800 | [diff] [blame] | 1075 | |
Ian Elliott | d4b50aa | 2017-01-09 16:21:36 -0700 | [diff] [blame] | 1076 | if (strcmp(prop.extensionName, |
| 1077 | VK_ANDROID_NATIVE_BUFFER_EXTENSION_NAME) != 0) |
| 1078 | continue; |
Chia-I Wu | 01cf305 | 2016-03-24 16:16:21 +0800 | [diff] [blame] | 1079 | |
Ian Elliott | d4b50aa | 2017-01-09 16:21:36 -0700 | [diff] [blame] | 1080 | memcpy(prop.extensionName, VK_KHR_SWAPCHAIN_EXTENSION_NAME, |
| 1081 | sizeof(VK_KHR_SWAPCHAIN_EXTENSION_NAME)); |
Yiwei Zhang | 14f4d42 | 2019-04-17 12:24:39 -0700 | [diff] [blame] | 1082 | |
| 1083 | if (prop.specVersion >= 8) { |
| 1084 | prop.specVersion = VK_KHR_SWAPCHAIN_SPEC_VERSION; |
| 1085 | } else { |
| 1086 | prop.specVersion = 68; |
| 1087 | } |
Ian Elliott | d4b50aa | 2017-01-09 16:21:36 -0700 | [diff] [blame] | 1088 | } |
| 1089 | } |
Chia-I Wu | 01cf305 | 2016-03-24 16:16:21 +0800 | [diff] [blame] | 1090 | |
Ian Elliott | d4b50aa | 2017-01-09 16:21:36 -0700 | [diff] [blame] | 1091 | // restore loader extension count |
| 1092 | if (!pLayerName && (result == VK_SUCCESS || result == VK_INCOMPLETE)) { |
| 1093 | *pPropertyCount += loader_extensions.size(); |
Chia-I Wu | 01cf305 | 2016-03-24 16:16:21 +0800 | [diff] [blame] | 1094 | } |
| 1095 | |
| 1096 | return result; |
| 1097 | } |
| 1098 | |
Chia-I Wu | ff4a6c7 | 2016-03-24 16:05:56 +0800 | [diff] [blame] | 1099 | VkResult CreateInstance(const VkInstanceCreateInfo* pCreateInfo, |
| 1100 | const VkAllocationCallbacks* pAllocator, |
| 1101 | VkInstance* pInstance) { |
| 1102 | const VkAllocationCallbacks& data_allocator = |
| 1103 | (pAllocator) ? *pAllocator : GetDefaultAllocator(); |
| 1104 | |
Yiwei Zhang | 2cefa73 | 2020-07-10 21:07:30 -0700 | [diff] [blame] | 1105 | VkResult result = VK_SUCCESS; |
| 1106 | uint32_t icd_api_version = VK_API_VERSION_1_0; |
| 1107 | PFN_vkEnumerateInstanceVersion pfn_enumerate_instance_version = |
| 1108 | reinterpret_cast<PFN_vkEnumerateInstanceVersion>( |
| 1109 | Hal::Device().GetInstanceProcAddr(nullptr, |
| 1110 | "vkEnumerateInstanceVersion")); |
| 1111 | if (pfn_enumerate_instance_version) { |
| 1112 | ATRACE_BEGIN("pfn_enumerate_instance_version"); |
| 1113 | result = (*pfn_enumerate_instance_version)(&icd_api_version); |
| 1114 | ATRACE_END(); |
| 1115 | if (result != VK_SUCCESS) |
| 1116 | return result; |
| 1117 | |
Trevor David Black | b68a225 | 2021-08-23 16:37:18 +0000 | [diff] [blame] | 1118 | icd_api_version ^= VK_API_VERSION_PATCH(icd_api_version); |
Yiwei Zhang | 2cefa73 | 2020-07-10 21:07:30 -0700 | [diff] [blame] | 1119 | } |
| 1120 | |
| 1121 | CreateInfoWrapper wrapper(*pCreateInfo, icd_api_version, data_allocator); |
| 1122 | result = wrapper.Validate(); |
Chia-I Wu | ff4a6c7 | 2016-03-24 16:05:56 +0800 | [diff] [blame] | 1123 | if (result != VK_SUCCESS) |
| 1124 | return result; |
| 1125 | |
| 1126 | InstanceData* data = AllocateInstanceData(data_allocator); |
| 1127 | if (!data) |
| 1128 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 1129 | |
Chia-I Wu | 3e6c2d6 | 2016-04-11 13:55:56 +0800 | [diff] [blame] | 1130 | data->hook_extensions |= wrapper.GetHookExtensions(); |
Chia-I Wu | ff4a6c7 | 2016-03-24 16:05:56 +0800 | [diff] [blame] | 1131 | |
| 1132 | // call into the driver |
| 1133 | VkInstance instance; |
Yiwei Zhang | fdd0c2a | 2019-01-30 20:16:37 -0800 | [diff] [blame] | 1134 | ATRACE_BEGIN("driver.CreateInstance"); |
Chia-I Wu | 31b2e4f | 2016-05-23 10:47:57 +0800 | [diff] [blame] | 1135 | result = Hal::Device().CreateInstance( |
Chia-I Wu | ff4a6c7 | 2016-03-24 16:05:56 +0800 | [diff] [blame] | 1136 | static_cast<const VkInstanceCreateInfo*>(wrapper), pAllocator, |
| 1137 | &instance); |
Yiwei Zhang | fdd0c2a | 2019-01-30 20:16:37 -0800 | [diff] [blame] | 1138 | ATRACE_END(); |
Chia-I Wu | ff4a6c7 | 2016-03-24 16:05:56 +0800 | [diff] [blame] | 1139 | if (result != VK_SUCCESS) { |
| 1140 | FreeInstanceData(data, data_allocator); |
| 1141 | return result; |
| 1142 | } |
| 1143 | |
| 1144 | // initialize InstanceDriverTable |
| 1145 | if (!SetData(instance, *data) || |
Chia-I Wu | 31b2e4f | 2016-05-23 10:47:57 +0800 | [diff] [blame] | 1146 | !InitDriverTable(instance, Hal::Device().GetInstanceProcAddr, |
Chia-I Wu | cbe07ef | 2016-04-13 15:01:00 +0800 | [diff] [blame] | 1147 | wrapper.GetHalExtensions())) { |
Chia-I Wu | ff4a6c7 | 2016-03-24 16:05:56 +0800 | [diff] [blame] | 1148 | data->driver.DestroyInstance = reinterpret_cast<PFN_vkDestroyInstance>( |
Chia-I Wu | 31b2e4f | 2016-05-23 10:47:57 +0800 | [diff] [blame] | 1149 | Hal::Device().GetInstanceProcAddr(instance, "vkDestroyInstance")); |
Chia-I Wu | ff4a6c7 | 2016-03-24 16:05:56 +0800 | [diff] [blame] | 1150 | if (data->driver.DestroyInstance) |
| 1151 | data->driver.DestroyInstance(instance, pAllocator); |
| 1152 | |
| 1153 | FreeInstanceData(data, data_allocator); |
| 1154 | |
| 1155 | return VK_ERROR_INCOMPATIBLE_DRIVER; |
| 1156 | } |
| 1157 | |
| 1158 | data->get_device_proc_addr = reinterpret_cast<PFN_vkGetDeviceProcAddr>( |
Chia-I Wu | 31b2e4f | 2016-05-23 10:47:57 +0800 | [diff] [blame] | 1159 | Hal::Device().GetInstanceProcAddr(instance, "vkGetDeviceProcAddr")); |
Chia-I Wu | ff4a6c7 | 2016-03-24 16:05:56 +0800 | [diff] [blame] | 1160 | if (!data->get_device_proc_addr) { |
| 1161 | data->driver.DestroyInstance(instance, pAllocator); |
| 1162 | FreeInstanceData(data, data_allocator); |
| 1163 | |
| 1164 | return VK_ERROR_INCOMPATIBLE_DRIVER; |
| 1165 | } |
| 1166 | |
| 1167 | *pInstance = instance; |
| 1168 | |
| 1169 | return VK_SUCCESS; |
| 1170 | } |
| 1171 | |
| 1172 | void DestroyInstance(VkInstance instance, |
| 1173 | const VkAllocationCallbacks* pAllocator) { |
| 1174 | InstanceData& data = GetData(instance); |
| 1175 | data.driver.DestroyInstance(instance, pAllocator); |
| 1176 | |
| 1177 | VkAllocationCallbacks local_allocator; |
| 1178 | if (!pAllocator) { |
| 1179 | local_allocator = data.allocator; |
| 1180 | pAllocator = &local_allocator; |
| 1181 | } |
| 1182 | |
| 1183 | FreeInstanceData(&data, *pAllocator); |
| 1184 | } |
| 1185 | |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 1186 | VkResult CreateDevice(VkPhysicalDevice physicalDevice, |
| 1187 | const VkDeviceCreateInfo* pCreateInfo, |
| 1188 | const VkAllocationCallbacks* pAllocator, |
| 1189 | VkDevice* pDevice) { |
| 1190 | const InstanceData& instance_data = GetData(physicalDevice); |
| 1191 | const VkAllocationCallbacks& data_allocator = |
| 1192 | (pAllocator) ? *pAllocator : instance_data.allocator; |
| 1193 | |
Yiwei Zhang | 2cefa73 | 2020-07-10 21:07:30 -0700 | [diff] [blame] | 1194 | VkPhysicalDeviceProperties properties; |
| 1195 | ATRACE_BEGIN("driver.GetPhysicalDeviceProperties"); |
| 1196 | instance_data.driver.GetPhysicalDeviceProperties(physicalDevice, |
| 1197 | &properties); |
| 1198 | ATRACE_END(); |
| 1199 | |
| 1200 | CreateInfoWrapper wrapper( |
| 1201 | physicalDevice, *pCreateInfo, |
Trevor David Black | b68a225 | 2021-08-23 16:37:18 +0000 | [diff] [blame] | 1202 | properties.apiVersion ^ VK_API_VERSION_PATCH(properties.apiVersion), |
Yiwei Zhang | 2cefa73 | 2020-07-10 21:07:30 -0700 | [diff] [blame] | 1203 | data_allocator); |
Chia-I Wu | 3e6c2d6 | 2016-04-11 13:55:56 +0800 | [diff] [blame] | 1204 | VkResult result = wrapper.Validate(); |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 1205 | if (result != VK_SUCCESS) |
| 1206 | return result; |
| 1207 | |
Yiwei Zhang | fdd0c2a | 2019-01-30 20:16:37 -0800 | [diff] [blame] | 1208 | ATRACE_BEGIN("AllocateDeviceData"); |
Chia-I Wu | 950d6e1 | 2016-05-03 09:12:35 +0800 | [diff] [blame] | 1209 | DeviceData* data = AllocateDeviceData(data_allocator, |
| 1210 | instance_data.debug_report_callbacks); |
Yiwei Zhang | fdd0c2a | 2019-01-30 20:16:37 -0800 | [diff] [blame] | 1211 | ATRACE_END(); |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 1212 | if (!data) |
| 1213 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 1214 | |
Chia-I Wu | 3e6c2d6 | 2016-04-11 13:55:56 +0800 | [diff] [blame] | 1215 | data->hook_extensions |= wrapper.GetHookExtensions(); |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 1216 | |
| 1217 | // call into the driver |
| 1218 | VkDevice dev; |
Yiwei Zhang | fdd0c2a | 2019-01-30 20:16:37 -0800 | [diff] [blame] | 1219 | ATRACE_BEGIN("driver.CreateDevice"); |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 1220 | result = instance_data.driver.CreateDevice( |
| 1221 | physicalDevice, static_cast<const VkDeviceCreateInfo*>(wrapper), |
| 1222 | pAllocator, &dev); |
Yiwei Zhang | fdd0c2a | 2019-01-30 20:16:37 -0800 | [diff] [blame] | 1223 | ATRACE_END(); |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 1224 | if (result != VK_SUCCESS) { |
| 1225 | FreeDeviceData(data, data_allocator); |
| 1226 | return result; |
| 1227 | } |
| 1228 | |
| 1229 | // initialize DeviceDriverTable |
| 1230 | if (!SetData(dev, *data) || |
Chia-I Wu | cbe07ef | 2016-04-13 15:01:00 +0800 | [diff] [blame] | 1231 | !InitDriverTable(dev, instance_data.get_device_proc_addr, |
| 1232 | wrapper.GetHalExtensions())) { |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 1233 | data->driver.DestroyDevice = reinterpret_cast<PFN_vkDestroyDevice>( |
| 1234 | instance_data.get_device_proc_addr(dev, "vkDestroyDevice")); |
| 1235 | if (data->driver.DestroyDevice) |
| 1236 | data->driver.DestroyDevice(dev, pAllocator); |
| 1237 | |
| 1238 | FreeDeviceData(data, data_allocator); |
| 1239 | |
| 1240 | return VK_ERROR_INCOMPATIBLE_DRIVER; |
| 1241 | } |
Chris Forbes | d827791 | 2017-02-10 14:59:59 +1300 | [diff] [blame] | 1242 | |
| 1243 | // sanity check ANDROID_native_buffer implementation, whose set of |
| 1244 | // entrypoints varies according to the spec version. |
| 1245 | if ((wrapper.GetHalExtensions()[ProcHook::ANDROID_native_buffer]) && |
| 1246 | !data->driver.GetSwapchainGrallocUsageANDROID && |
| 1247 | !data->driver.GetSwapchainGrallocUsage2ANDROID) { |
| 1248 | ALOGE("Driver's implementation of ANDROID_native_buffer is broken;" |
| 1249 | " must expose at least one of " |
| 1250 | "vkGetSwapchainGrallocUsageANDROID or " |
| 1251 | "vkGetSwapchainGrallocUsage2ANDROID"); |
| 1252 | |
| 1253 | data->driver.DestroyDevice(dev, pAllocator); |
| 1254 | FreeDeviceData(data, data_allocator); |
| 1255 | |
| 1256 | return VK_ERROR_INCOMPATIBLE_DRIVER; |
| 1257 | } |
| 1258 | |
Yiwei Zhang | 2cefa73 | 2020-07-10 21:07:30 -0700 | [diff] [blame] | 1259 | if (properties.deviceType == VK_PHYSICAL_DEVICE_TYPE_CPU) { |
| 1260 | // Log that the app is hitting software Vulkan implementation |
| 1261 | android::GraphicsEnv::getInstance().setTargetStats( |
| 1262 | android::GpuStatsInfo::Stats::CPU_VULKAN_IN_USE); |
| 1263 | } |
| 1264 | |
Jesse Hall | dc22507 | 2016-05-30 22:40:14 -0700 | [diff] [blame] | 1265 | data->driver_device = dev; |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 1266 | |
| 1267 | *pDevice = dev; |
| 1268 | |
| 1269 | return VK_SUCCESS; |
| 1270 | } |
| 1271 | |
| 1272 | void DestroyDevice(VkDevice device, const VkAllocationCallbacks* pAllocator) { |
| 1273 | DeviceData& data = GetData(device); |
| 1274 | data.driver.DestroyDevice(device, pAllocator); |
| 1275 | |
| 1276 | VkAllocationCallbacks local_allocator; |
| 1277 | if (!pAllocator) { |
| 1278 | local_allocator = data.allocator; |
| 1279 | pAllocator = &local_allocator; |
| 1280 | } |
| 1281 | |
| 1282 | FreeDeviceData(&data, *pAllocator); |
| 1283 | } |
| 1284 | |
Chia-I Wu | ff4a6c7 | 2016-03-24 16:05:56 +0800 | [diff] [blame] | 1285 | VkResult EnumeratePhysicalDevices(VkInstance instance, |
| 1286 | uint32_t* pPhysicalDeviceCount, |
| 1287 | VkPhysicalDevice* pPhysicalDevices) { |
Yiwei Zhang | fdd0c2a | 2019-01-30 20:16:37 -0800 | [diff] [blame] | 1288 | ATRACE_CALL(); |
| 1289 | |
Chia-I Wu | ff4a6c7 | 2016-03-24 16:05:56 +0800 | [diff] [blame] | 1290 | const auto& data = GetData(instance); |
| 1291 | |
| 1292 | VkResult result = data.driver.EnumeratePhysicalDevices( |
| 1293 | instance, pPhysicalDeviceCount, pPhysicalDevices); |
| 1294 | if ((result == VK_SUCCESS || result == VK_INCOMPLETE) && pPhysicalDevices) { |
| 1295 | for (uint32_t i = 0; i < *pPhysicalDeviceCount; i++) |
| 1296 | SetData(pPhysicalDevices[i], data); |
| 1297 | } |
| 1298 | |
| 1299 | return result; |
| 1300 | } |
| 1301 | |
Daniel Koch | f25f5bb | 2017-10-05 00:26:58 -0400 | [diff] [blame] | 1302 | VkResult EnumeratePhysicalDeviceGroups( |
| 1303 | VkInstance instance, |
| 1304 | uint32_t* pPhysicalDeviceGroupCount, |
| 1305 | VkPhysicalDeviceGroupProperties* pPhysicalDeviceGroupProperties) { |
Yiwei Zhang | fdd0c2a | 2019-01-30 20:16:37 -0800 | [diff] [blame] | 1306 | ATRACE_CALL(); |
| 1307 | |
Yiwei Zhang | 4cd9cc9 | 2018-01-08 17:55:50 -0800 | [diff] [blame] | 1308 | VkResult result = VK_SUCCESS; |
Daniel Koch | f25f5bb | 2017-10-05 00:26:58 -0400 | [diff] [blame] | 1309 | const auto& data = GetData(instance); |
| 1310 | |
Yiwei Zhang | e4f6417 | 2020-07-05 15:17:32 -0700 | [diff] [blame] | 1311 | if (!data.driver.EnumeratePhysicalDeviceGroups && |
| 1312 | !data.driver.EnumeratePhysicalDeviceGroupsKHR) { |
Yiwei Zhang | 4cd9cc9 | 2018-01-08 17:55:50 -0800 | [diff] [blame] | 1313 | uint32_t device_count = 0; |
| 1314 | result = EnumeratePhysicalDevices(instance, &device_count, nullptr); |
| 1315 | if (result < 0) |
| 1316 | return result; |
Chad Versace | 32c087f | 2018-09-09 07:28:05 -0700 | [diff] [blame] | 1317 | |
Yiwei Zhang | 4cd9cc9 | 2018-01-08 17:55:50 -0800 | [diff] [blame] | 1318 | if (!pPhysicalDeviceGroupProperties) { |
| 1319 | *pPhysicalDeviceGroupCount = device_count; |
| 1320 | return result; |
| 1321 | } |
| 1322 | |
Yiwei Zhang | 4cd9cc9 | 2018-01-08 17:55:50 -0800 | [diff] [blame] | 1323 | if (!device_count) { |
| 1324 | *pPhysicalDeviceGroupCount = 0; |
| 1325 | return result; |
| 1326 | } |
Chad Versace | 32c087f | 2018-09-09 07:28:05 -0700 | [diff] [blame] | 1327 | device_count = std::min(device_count, *pPhysicalDeviceGroupCount); |
| 1328 | if (!device_count) |
| 1329 | return VK_INCOMPLETE; |
Yiwei Zhang | 4cd9cc9 | 2018-01-08 17:55:50 -0800 | [diff] [blame] | 1330 | |
Yiwei Zhang | 5e86220 | 2019-06-21 14:59:16 -0700 | [diff] [blame] | 1331 | std::vector<VkPhysicalDevice> devices(device_count); |
Chad Versace | 32c087f | 2018-09-09 07:28:05 -0700 | [diff] [blame] | 1332 | *pPhysicalDeviceGroupCount = device_count; |
Yiwei Zhang | 5e86220 | 2019-06-21 14:59:16 -0700 | [diff] [blame] | 1333 | result = |
| 1334 | EnumeratePhysicalDevices(instance, &device_count, devices.data()); |
Yiwei Zhang | 4cd9cc9 | 2018-01-08 17:55:50 -0800 | [diff] [blame] | 1335 | if (result < 0) |
| 1336 | return result; |
| 1337 | |
Yiwei Zhang | 4cd9cc9 | 2018-01-08 17:55:50 -0800 | [diff] [blame] | 1338 | for (uint32_t i = 0; i < device_count; ++i) { |
| 1339 | pPhysicalDeviceGroupProperties[i].physicalDeviceCount = 1; |
| 1340 | pPhysicalDeviceGroupProperties[i].physicalDevices[0] = devices[i]; |
| 1341 | pPhysicalDeviceGroupProperties[i].subsetAllocation = 0; |
| 1342 | } |
| 1343 | } else { |
Yiwei Zhang | e4f6417 | 2020-07-05 15:17:32 -0700 | [diff] [blame] | 1344 | if (data.driver.EnumeratePhysicalDeviceGroups) { |
| 1345 | result = data.driver.EnumeratePhysicalDeviceGroups( |
| 1346 | instance, pPhysicalDeviceGroupCount, |
| 1347 | pPhysicalDeviceGroupProperties); |
| 1348 | } else { |
| 1349 | result = data.driver.EnumeratePhysicalDeviceGroupsKHR( |
| 1350 | instance, pPhysicalDeviceGroupCount, |
| 1351 | pPhysicalDeviceGroupProperties); |
| 1352 | } |
Yiwei Zhang | 4cd9cc9 | 2018-01-08 17:55:50 -0800 | [diff] [blame] | 1353 | if ((result == VK_SUCCESS || result == VK_INCOMPLETE) && |
| 1354 | *pPhysicalDeviceGroupCount && pPhysicalDeviceGroupProperties) { |
| 1355 | for (uint32_t i = 0; i < *pPhysicalDeviceGroupCount; i++) { |
| 1356 | for (uint32_t j = 0; |
| 1357 | j < pPhysicalDeviceGroupProperties[i].physicalDeviceCount; |
| 1358 | j++) { |
| 1359 | SetData( |
| 1360 | pPhysicalDeviceGroupProperties[i].physicalDevices[j], |
Ian Elliott | cd8ad33 | 2017-10-13 09:21:12 -0600 | [diff] [blame] | 1361 | data); |
Yiwei Zhang | 4cd9cc9 | 2018-01-08 17:55:50 -0800 | [diff] [blame] | 1362 | } |
Ian Elliott | cd8ad33 | 2017-10-13 09:21:12 -0600 | [diff] [blame] | 1363 | } |
| 1364 | } |
Daniel Koch | f25f5bb | 2017-10-05 00:26:58 -0400 | [diff] [blame] | 1365 | } |
| 1366 | |
| 1367 | return result; |
| 1368 | } |
| 1369 | |
Chia-I Wu | ba0be41 | 2016-03-24 16:24:40 +0800 | [diff] [blame] | 1370 | void GetDeviceQueue(VkDevice device, |
| 1371 | uint32_t queueFamilyIndex, |
| 1372 | uint32_t queueIndex, |
| 1373 | VkQueue* pQueue) { |
Yiwei Zhang | fdd0c2a | 2019-01-30 20:16:37 -0800 | [diff] [blame] | 1374 | ATRACE_CALL(); |
| 1375 | |
Chia-I Wu | ba0be41 | 2016-03-24 16:24:40 +0800 | [diff] [blame] | 1376 | const auto& data = GetData(device); |
| 1377 | |
| 1378 | data.driver.GetDeviceQueue(device, queueFamilyIndex, queueIndex, pQueue); |
| 1379 | SetData(*pQueue, data); |
| 1380 | } |
| 1381 | |
Daniel Koch | f25f5bb | 2017-10-05 00:26:58 -0400 | [diff] [blame] | 1382 | void GetDeviceQueue2(VkDevice device, |
| 1383 | const VkDeviceQueueInfo2* pQueueInfo, |
| 1384 | VkQueue* pQueue) { |
Yiwei Zhang | fdd0c2a | 2019-01-30 20:16:37 -0800 | [diff] [blame] | 1385 | ATRACE_CALL(); |
| 1386 | |
Daniel Koch | f25f5bb | 2017-10-05 00:26:58 -0400 | [diff] [blame] | 1387 | const auto& data = GetData(device); |
| 1388 | |
| 1389 | data.driver.GetDeviceQueue2(device, pQueueInfo, pQueue); |
Yiwei Zhang | f5b9f73 | 2018-02-07 14:06:09 -0800 | [diff] [blame] | 1390 | if (*pQueue != VK_NULL_HANDLE) SetData(*pQueue, data); |
Daniel Koch | f25f5bb | 2017-10-05 00:26:58 -0400 | [diff] [blame] | 1391 | } |
| 1392 | |
Yiwei Zhang | 93b521c | 2020-07-11 16:32:09 -0700 | [diff] [blame] | 1393 | VkResult AllocateCommandBuffers( |
| 1394 | VkDevice device, |
| 1395 | const VkCommandBufferAllocateInfo* pAllocateInfo, |
| 1396 | VkCommandBuffer* pCommandBuffers) { |
Yiwei Zhang | fdd0c2a | 2019-01-30 20:16:37 -0800 | [diff] [blame] | 1397 | ATRACE_CALL(); |
| 1398 | |
Chia-I Wu | 6a58a8a | 2016-03-24 16:29:51 +0800 | [diff] [blame] | 1399 | const auto& data = GetData(device); |
| 1400 | |
| 1401 | VkResult result = data.driver.AllocateCommandBuffers(device, pAllocateInfo, |
| 1402 | pCommandBuffers); |
| 1403 | if (result == VK_SUCCESS) { |
| 1404 | for (uint32_t i = 0; i < pAllocateInfo->commandBufferCount; i++) |
| 1405 | SetData(pCommandBuffers[i], data); |
| 1406 | } |
| 1407 | |
| 1408 | return result; |
| 1409 | } |
| 1410 | |
Yiwei Zhang | 93b521c | 2020-07-11 16:32:09 -0700 | [diff] [blame] | 1411 | VkResult QueueSubmit(VkQueue queue, |
| 1412 | uint32_t submitCount, |
| 1413 | const VkSubmitInfo* pSubmits, |
| 1414 | VkFence fence) { |
Yiwei Zhang | 899d175 | 2019-09-23 16:05:35 -0700 | [diff] [blame] | 1415 | ATRACE_CALL(); |
| 1416 | |
| 1417 | const auto& data = GetData(queue); |
| 1418 | |
| 1419 | return data.driver.QueueSubmit(queue, submitCount, pSubmits, fence); |
| 1420 | } |
| 1421 | |
Yiwei Zhang | a55624b | 2020-07-05 16:05:26 -0700 | [diff] [blame] | 1422 | void GetPhysicalDeviceFeatures2(VkPhysicalDevice physicalDevice, |
| 1423 | VkPhysicalDeviceFeatures2* pFeatures) { |
| 1424 | ATRACE_CALL(); |
| 1425 | |
| 1426 | const auto& driver = GetData(physicalDevice).driver; |
| 1427 | |
| 1428 | if (driver.GetPhysicalDeviceFeatures2) { |
| 1429 | driver.GetPhysicalDeviceFeatures2(physicalDevice, pFeatures); |
| 1430 | return; |
| 1431 | } |
| 1432 | |
| 1433 | driver.GetPhysicalDeviceFeatures2KHR(physicalDevice, pFeatures); |
| 1434 | } |
| 1435 | |
| 1436 | void GetPhysicalDeviceProperties2(VkPhysicalDevice physicalDevice, |
| 1437 | VkPhysicalDeviceProperties2* pProperties) { |
| 1438 | ATRACE_CALL(); |
| 1439 | |
| 1440 | const auto& driver = GetData(physicalDevice).driver; |
| 1441 | |
| 1442 | if (driver.GetPhysicalDeviceProperties2) { |
| 1443 | driver.GetPhysicalDeviceProperties2(physicalDevice, pProperties); |
| 1444 | return; |
| 1445 | } |
| 1446 | |
| 1447 | driver.GetPhysicalDeviceProperties2KHR(physicalDevice, pProperties); |
| 1448 | } |
| 1449 | |
| 1450 | void GetPhysicalDeviceFormatProperties2( |
| 1451 | VkPhysicalDevice physicalDevice, |
| 1452 | VkFormat format, |
| 1453 | VkFormatProperties2* pFormatProperties) { |
| 1454 | ATRACE_CALL(); |
| 1455 | |
| 1456 | const auto& driver = GetData(physicalDevice).driver; |
| 1457 | |
| 1458 | if (driver.GetPhysicalDeviceFormatProperties2) { |
| 1459 | driver.GetPhysicalDeviceFormatProperties2(physicalDevice, format, |
| 1460 | pFormatProperties); |
| 1461 | return; |
| 1462 | } |
| 1463 | |
| 1464 | driver.GetPhysicalDeviceFormatProperties2KHR(physicalDevice, format, |
| 1465 | pFormatProperties); |
| 1466 | } |
| 1467 | |
| 1468 | VkResult GetPhysicalDeviceImageFormatProperties2( |
| 1469 | VkPhysicalDevice physicalDevice, |
| 1470 | const VkPhysicalDeviceImageFormatInfo2* pImageFormatInfo, |
| 1471 | VkImageFormatProperties2* pImageFormatProperties) { |
| 1472 | ATRACE_CALL(); |
| 1473 | |
| 1474 | const auto& driver = GetData(physicalDevice).driver; |
| 1475 | |
| 1476 | if (driver.GetPhysicalDeviceImageFormatProperties2) { |
| 1477 | return driver.GetPhysicalDeviceImageFormatProperties2( |
| 1478 | physicalDevice, pImageFormatInfo, pImageFormatProperties); |
| 1479 | } |
| 1480 | |
| 1481 | return driver.GetPhysicalDeviceImageFormatProperties2KHR( |
| 1482 | physicalDevice, pImageFormatInfo, pImageFormatProperties); |
| 1483 | } |
| 1484 | |
| 1485 | void GetPhysicalDeviceQueueFamilyProperties2( |
| 1486 | VkPhysicalDevice physicalDevice, |
| 1487 | uint32_t* pQueueFamilyPropertyCount, |
| 1488 | VkQueueFamilyProperties2* pQueueFamilyProperties) { |
| 1489 | ATRACE_CALL(); |
| 1490 | |
| 1491 | const auto& driver = GetData(physicalDevice).driver; |
| 1492 | |
| 1493 | if (driver.GetPhysicalDeviceQueueFamilyProperties2) { |
| 1494 | driver.GetPhysicalDeviceQueueFamilyProperties2( |
| 1495 | physicalDevice, pQueueFamilyPropertyCount, pQueueFamilyProperties); |
| 1496 | return; |
| 1497 | } |
| 1498 | |
| 1499 | driver.GetPhysicalDeviceQueueFamilyProperties2KHR( |
| 1500 | physicalDevice, pQueueFamilyPropertyCount, pQueueFamilyProperties); |
| 1501 | } |
| 1502 | |
| 1503 | void GetPhysicalDeviceMemoryProperties2( |
| 1504 | VkPhysicalDevice physicalDevice, |
| 1505 | VkPhysicalDeviceMemoryProperties2* pMemoryProperties) { |
| 1506 | ATRACE_CALL(); |
| 1507 | |
| 1508 | const auto& driver = GetData(physicalDevice).driver; |
| 1509 | |
| 1510 | if (driver.GetPhysicalDeviceMemoryProperties2) { |
| 1511 | driver.GetPhysicalDeviceMemoryProperties2(physicalDevice, |
| 1512 | pMemoryProperties); |
| 1513 | return; |
| 1514 | } |
| 1515 | |
| 1516 | driver.GetPhysicalDeviceMemoryProperties2KHR(physicalDevice, |
| 1517 | pMemoryProperties); |
| 1518 | } |
| 1519 | |
| 1520 | void GetPhysicalDeviceSparseImageFormatProperties2( |
| 1521 | VkPhysicalDevice physicalDevice, |
| 1522 | const VkPhysicalDeviceSparseImageFormatInfo2* pFormatInfo, |
| 1523 | uint32_t* pPropertyCount, |
| 1524 | VkSparseImageFormatProperties2* pProperties) { |
| 1525 | ATRACE_CALL(); |
| 1526 | |
| 1527 | const auto& driver = GetData(physicalDevice).driver; |
| 1528 | |
| 1529 | if (driver.GetPhysicalDeviceSparseImageFormatProperties2) { |
| 1530 | driver.GetPhysicalDeviceSparseImageFormatProperties2( |
| 1531 | physicalDevice, pFormatInfo, pPropertyCount, pProperties); |
| 1532 | return; |
| 1533 | } |
| 1534 | |
| 1535 | driver.GetPhysicalDeviceSparseImageFormatProperties2KHR( |
| 1536 | physicalDevice, pFormatInfo, pPropertyCount, pProperties); |
| 1537 | } |
| 1538 | |
Yiwei Zhang | e1f3501 | 2020-07-05 22:52:04 -0700 | [diff] [blame] | 1539 | void GetPhysicalDeviceExternalBufferProperties( |
| 1540 | VkPhysicalDevice physicalDevice, |
| 1541 | const VkPhysicalDeviceExternalBufferInfo* pExternalBufferInfo, |
| 1542 | VkExternalBufferProperties* pExternalBufferProperties) { |
| 1543 | ATRACE_CALL(); |
| 1544 | |
| 1545 | const auto& driver = GetData(physicalDevice).driver; |
| 1546 | |
| 1547 | if (driver.GetPhysicalDeviceExternalBufferProperties) { |
| 1548 | driver.GetPhysicalDeviceExternalBufferProperties( |
| 1549 | physicalDevice, pExternalBufferInfo, pExternalBufferProperties); |
| 1550 | return; |
| 1551 | } |
| 1552 | |
| 1553 | if (driver.GetPhysicalDeviceExternalBufferPropertiesKHR) { |
| 1554 | driver.GetPhysicalDeviceExternalBufferPropertiesKHR( |
| 1555 | physicalDevice, pExternalBufferInfo, pExternalBufferProperties); |
| 1556 | return; |
| 1557 | } |
| 1558 | |
| 1559 | memset(&pExternalBufferProperties->externalMemoryProperties, 0, |
| 1560 | sizeof(VkExternalMemoryProperties)); |
| 1561 | } |
| 1562 | |
| 1563 | void GetPhysicalDeviceExternalSemaphoreProperties( |
| 1564 | VkPhysicalDevice physicalDevice, |
| 1565 | const VkPhysicalDeviceExternalSemaphoreInfo* pExternalSemaphoreInfo, |
| 1566 | VkExternalSemaphoreProperties* pExternalSemaphoreProperties) { |
| 1567 | ATRACE_CALL(); |
| 1568 | |
| 1569 | const auto& driver = GetData(physicalDevice).driver; |
| 1570 | |
| 1571 | if (driver.GetPhysicalDeviceExternalSemaphoreProperties) { |
| 1572 | driver.GetPhysicalDeviceExternalSemaphoreProperties( |
| 1573 | physicalDevice, pExternalSemaphoreInfo, |
| 1574 | pExternalSemaphoreProperties); |
| 1575 | return; |
| 1576 | } |
| 1577 | |
| 1578 | if (driver.GetPhysicalDeviceExternalSemaphorePropertiesKHR) { |
| 1579 | driver.GetPhysicalDeviceExternalSemaphorePropertiesKHR( |
| 1580 | physicalDevice, pExternalSemaphoreInfo, |
| 1581 | pExternalSemaphoreProperties); |
| 1582 | return; |
| 1583 | } |
| 1584 | |
| 1585 | pExternalSemaphoreProperties->exportFromImportedHandleTypes = 0; |
| 1586 | pExternalSemaphoreProperties->compatibleHandleTypes = 0; |
| 1587 | pExternalSemaphoreProperties->externalSemaphoreFeatures = 0; |
| 1588 | } |
| 1589 | |
| 1590 | void GetPhysicalDeviceExternalFenceProperties( |
| 1591 | VkPhysicalDevice physicalDevice, |
| 1592 | const VkPhysicalDeviceExternalFenceInfo* pExternalFenceInfo, |
| 1593 | VkExternalFenceProperties* pExternalFenceProperties) { |
| 1594 | ATRACE_CALL(); |
| 1595 | |
| 1596 | const auto& driver = GetData(physicalDevice).driver; |
| 1597 | |
| 1598 | if (driver.GetPhysicalDeviceExternalFenceProperties) { |
| 1599 | driver.GetPhysicalDeviceExternalFenceProperties( |
| 1600 | physicalDevice, pExternalFenceInfo, pExternalFenceProperties); |
| 1601 | return; |
| 1602 | } |
| 1603 | |
| 1604 | if (driver.GetPhysicalDeviceExternalFencePropertiesKHR) { |
| 1605 | driver.GetPhysicalDeviceExternalFencePropertiesKHR( |
| 1606 | physicalDevice, pExternalFenceInfo, pExternalFenceProperties); |
| 1607 | return; |
| 1608 | } |
| 1609 | |
| 1610 | pExternalFenceProperties->exportFromImportedHandleTypes = 0; |
| 1611 | pExternalFenceProperties->compatibleHandleTypes = 0; |
| 1612 | pExternalFenceProperties->externalFenceFeatures = 0; |
| 1613 | } |
| 1614 | |
Chia-I Wu | 9d51816 | 2016-03-24 14:55:27 +0800 | [diff] [blame] | 1615 | } // namespace driver |
| 1616 | } // namespace vulkan |