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), |
Trevor David Black | 628c41a | 2021-09-27 05:07:22 +0000 | [diff] [blame] | 368 | loader_api_version_(VK_API_VERSION_1_3), |
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), |
Trevor David Black | 628c41a | 2021-09-27 05:07:22 +0000 | [diff] [blame] | 380 | loader_api_version_(VK_API_VERSION_1_3), |
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) { |
Trevor David Black | 628c41a | 2021-09-27 05:07:22 +0000 | [diff] [blame] | 522 | case VK_API_VERSION_1_3: |
| 523 | hook_extensions_.set(ProcHook::EXTENSION_CORE_1_3); |
| 524 | hal_extensions_.set(ProcHook::EXTENSION_CORE_1_3); |
| 525 | [[clang::fallthrough]]; |
Ian Elliott | fa7af49 | 2021-07-20 17:40:24 -0600 | [diff] [blame] | 526 | case VK_API_VERSION_1_2: |
| 527 | hook_extensions_.set(ProcHook::EXTENSION_CORE_1_2); |
| 528 | hal_extensions_.set(ProcHook::EXTENSION_CORE_1_2); |
| 529 | [[clang::fallthrough]]; |
Yiwei Zhang | 2cefa73 | 2020-07-10 21:07:30 -0700 | [diff] [blame] | 530 | case VK_API_VERSION_1_1: |
| 531 | hook_extensions_.set(ProcHook::EXTENSION_CORE_1_1); |
| 532 | hal_extensions_.set(ProcHook::EXTENSION_CORE_1_1); |
| 533 | [[clang::fallthrough]]; |
| 534 | case VK_API_VERSION_1_0: |
| 535 | hook_extensions_.set(ProcHook::EXTENSION_CORE_1_0); |
| 536 | hal_extensions_.set(ProcHook::EXTENSION_CORE_1_0); |
| 537 | break; |
| 538 | default: |
| 539 | ALOGE("Unknown API version[%u]", api_version); |
| 540 | break; |
| 541 | } |
| 542 | |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 543 | ext_names = extension_filter_.names; |
| 544 | ext_count = extension_filter_.name_count; |
| 545 | |
| 546 | return VK_SUCCESS; |
| 547 | } |
| 548 | |
Chia-I Wu | 3e6c2d6 | 2016-04-11 13:55:56 +0800 | [diff] [blame] | 549 | VkResult CreateInfoWrapper::QueryExtensionCount(uint32_t& count) const { |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 550 | if (is_instance_) { |
Chia-I Wu | 31b2e4f | 2016-05-23 10:47:57 +0800 | [diff] [blame] | 551 | return Hal::Device().EnumerateInstanceExtensionProperties( |
| 552 | nullptr, &count, nullptr); |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 553 | } else { |
| 554 | const auto& driver = GetData(physical_dev_).driver; |
| 555 | return driver.EnumerateDeviceExtensionProperties(physical_dev_, nullptr, |
| 556 | &count, nullptr); |
| 557 | } |
| 558 | } |
| 559 | |
Chia-I Wu | 3e6c2d6 | 2016-04-11 13:55:56 +0800 | [diff] [blame] | 560 | VkResult CreateInfoWrapper::EnumerateExtensions( |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 561 | uint32_t& count, |
| 562 | VkExtensionProperties* props) const { |
| 563 | if (is_instance_) { |
Chia-I Wu | 31b2e4f | 2016-05-23 10:47:57 +0800 | [diff] [blame] | 564 | return Hal::Device().EnumerateInstanceExtensionProperties( |
| 565 | nullptr, &count, props); |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 566 | } else { |
| 567 | const auto& driver = GetData(physical_dev_).driver; |
| 568 | return driver.EnumerateDeviceExtensionProperties(physical_dev_, nullptr, |
| 569 | &count, props); |
| 570 | } |
| 571 | } |
| 572 | |
Chia-I Wu | 3e6c2d6 | 2016-04-11 13:55:56 +0800 | [diff] [blame] | 573 | VkResult CreateInfoWrapper::InitExtensionFilter() { |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 574 | // query extension count |
| 575 | uint32_t count; |
Chia-I Wu | 3e6c2d6 | 2016-04-11 13:55:56 +0800 | [diff] [blame] | 576 | VkResult result = QueryExtensionCount(count); |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 577 | if (result != VK_SUCCESS || count == 0) |
| 578 | return result; |
| 579 | |
| 580 | auto& filter = extension_filter_; |
| 581 | filter.exts = |
| 582 | reinterpret_cast<VkExtensionProperties*>(allocator_.pfnAllocation( |
| 583 | allocator_.pUserData, sizeof(VkExtensionProperties) * count, |
| 584 | alignof(VkExtensionProperties), |
| 585 | VK_SYSTEM_ALLOCATION_SCOPE_COMMAND)); |
| 586 | if (!filter.exts) |
| 587 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 588 | |
| 589 | // enumerate extensions |
Chia-I Wu | 3e6c2d6 | 2016-04-11 13:55:56 +0800 | [diff] [blame] | 590 | result = EnumerateExtensions(count, filter.exts); |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 591 | if (result != VK_SUCCESS && result != VK_INCOMPLETE) |
| 592 | return result; |
| 593 | |
| 594 | if (!count) |
| 595 | return VK_SUCCESS; |
| 596 | |
| 597 | filter.ext_count = count; |
| 598 | |
| 599 | // allocate name array |
Yiwei Zhang | 7c0c07c | 2020-07-04 23:49:47 -0700 | [diff] [blame] | 600 | if (is_instance_) { |
| 601 | uint32_t enabled_ext_count = instance_info_.enabledExtensionCount; |
| 602 | |
| 603 | // It requires enabling additional promoted extensions to downgrade api, |
| 604 | // so we reserve enough space here. |
Yiwei Zhang | 2cefa73 | 2020-07-10 21:07:30 -0700 | [diff] [blame] | 605 | if (icd_api_version_ < loader_api_version_) { |
Yiwei Zhang | 7c0c07c | 2020-07-04 23:49:47 -0700 | [diff] [blame] | 606 | enabled_ext_count += CountPromotedInstanceExtensions( |
Yiwei Zhang | 2cefa73 | 2020-07-10 21:07:30 -0700 | [diff] [blame] | 607 | icd_api_version_, loader_api_version_); |
Yiwei Zhang | 7c0c07c | 2020-07-04 23:49:47 -0700 | [diff] [blame] | 608 | } |
| 609 | |
| 610 | count = std::min(filter.ext_count, enabled_ext_count); |
| 611 | } else { |
| 612 | count = std::min(filter.ext_count, dev_info_.enabledExtensionCount); |
| 613 | } |
Yiwei Zhang | d7ea44a | 2020-08-13 12:54:27 -0700 | [diff] [blame] | 614 | |
| 615 | if (!count) |
| 616 | return VK_SUCCESS; |
| 617 | |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 618 | filter.names = reinterpret_cast<const char**>(allocator_.pfnAllocation( |
| 619 | allocator_.pUserData, sizeof(const char*) * count, alignof(const char*), |
| 620 | VK_SYSTEM_ALLOCATION_SCOPE_COMMAND)); |
| 621 | if (!filter.names) |
| 622 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 623 | |
| 624 | return VK_SUCCESS; |
| 625 | } |
| 626 | |
Chia-I Wu | 3e6c2d6 | 2016-04-11 13:55:56 +0800 | [diff] [blame] | 627 | void CreateInfoWrapper::FilterExtension(const char* name) { |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 628 | auto& filter = extension_filter_; |
| 629 | |
| 630 | ProcHook::Extension ext_bit = GetProcHookExtension(name); |
| 631 | if (is_instance_) { |
| 632 | switch (ext_bit) { |
| 633 | case ProcHook::KHR_android_surface: |
| 634 | case ProcHook::KHR_surface: |
Ian Elliott | bb67b24 | 2022-03-16 09:52:28 -0600 | [diff] [blame] | 635 | case ProcHook::KHR_surface_protected_capabilities: |
Courtney Goeltzenleuchter | e278daf | 2017-02-02 16:54:57 -0700 | [diff] [blame] | 636 | case ProcHook::EXT_swapchain_colorspace: |
Chris Forbes | 2452cf7 | 2017-03-16 16:30:17 +1300 | [diff] [blame] | 637 | case ProcHook::KHR_get_surface_capabilities2: |
Ian Elliott | 1ce053f | 2022-03-16 09:49:53 -0600 | [diff] [blame] | 638 | case ProcHook::GOOGLE_surfaceless_query: |
Chris Forbes | 9d0d9ff | 2022-12-28 01:58:31 +0000 | [diff] [blame] | 639 | case ProcHook::EXT_surface_maintenance1: |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 640 | hook_extensions_.set(ext_bit); |
| 641 | // return now as these extensions do not require HAL support |
| 642 | return; |
| 643 | case ProcHook::EXT_debug_report: |
| 644 | // both we and HAL can take part in |
| 645 | hook_extensions_.set(ext_bit); |
| 646 | break; |
Chris Forbes | 6aa30db | 2017-02-20 17:12:53 +1300 | [diff] [blame] | 647 | case ProcHook::KHR_get_physical_device_properties2: |
Yiwei Zhang | e4f6417 | 2020-07-05 15:17:32 -0700 | [diff] [blame] | 648 | case ProcHook::KHR_device_group_creation: |
Yiwei Zhang | e1f3501 | 2020-07-05 22:52:04 -0700 | [diff] [blame] | 649 | case ProcHook::KHR_external_memory_capabilities: |
| 650 | case ProcHook::KHR_external_semaphore_capabilities: |
| 651 | case ProcHook::KHR_external_fence_capabilities: |
Jesse Hall | 7f983a8 | 2018-03-29 14:46:45 -0700 | [diff] [blame] | 652 | case ProcHook::EXTENSION_UNKNOWN: |
| 653 | // 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] | 654 | break; |
Jesse Hall | 7f983a8 | 2018-03-29 14:46:45 -0700 | [diff] [blame] | 655 | |
Yiwei Zhang | 2314310 | 2019-04-10 18:24:05 -0700 | [diff] [blame] | 656 | case ProcHook::KHR_bind_memory2: |
Jesse Hall | 7f983a8 | 2018-03-29 14:46:45 -0700 | [diff] [blame] | 657 | case ProcHook::KHR_incremental_present: |
| 658 | case ProcHook::KHR_shared_presentable_image: |
| 659 | case ProcHook::KHR_swapchain: |
| 660 | case ProcHook::EXT_hdr_metadata: |
Chris Forbes | 9d0d9ff | 2022-12-28 01:58:31 +0000 | [diff] [blame] | 661 | case ProcHook::EXT_swapchain_maintenance1: |
Jesse Hall | 7f983a8 | 2018-03-29 14:46:45 -0700 | [diff] [blame] | 662 | case ProcHook::ANDROID_external_memory_android_hardware_buffer: |
| 663 | case ProcHook::ANDROID_native_buffer: |
| 664 | case ProcHook::GOOGLE_display_timing: |
Chris Forbes | 9d0d9ff | 2022-12-28 01:58:31 +0000 | [diff] [blame] | 665 | case ProcHook::KHR_external_fence_fd: |
Yiwei Zhang | 7cc36a5 | 2019-10-11 19:02:09 -0700 | [diff] [blame] | 666 | case ProcHook::EXTENSION_CORE_1_0: |
| 667 | case ProcHook::EXTENSION_CORE_1_1: |
Yiwei Zhang | 6be097b | 2020-10-19 20:22:05 -0700 | [diff] [blame] | 668 | case ProcHook::EXTENSION_CORE_1_2: |
Trevor David Black | b700ae8 | 2021-09-27 04:50:04 +0000 | [diff] [blame] | 669 | case ProcHook::EXTENSION_CORE_1_3: |
Jesse Hall | 7f983a8 | 2018-03-29 14:46:45 -0700 | [diff] [blame] | 670 | case ProcHook::EXTENSION_COUNT: |
| 671 | // Device and meta extensions. If we ever get here it's a bug in |
| 672 | // our code. But enumerating them lets us avoid having a default |
| 673 | // case, and default hides other bugs. |
| 674 | ALOGE( |
| 675 | "CreateInfoWrapper::FilterExtension: invalid instance " |
| 676 | "extension '%s'. FIX ME", |
| 677 | name); |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 678 | return; |
Jesse Hall | 7f983a8 | 2018-03-29 14:46:45 -0700 | [diff] [blame] | 679 | |
| 680 | // Don't use a default case. Without it, -Wswitch will tell us |
| 681 | // at compile time if someone adds a new ProcHook extension but |
| 682 | // doesn't handle it above. That's a real bug that has |
| 683 | // not-immediately-obvious effects. |
| 684 | // |
| 685 | // default: |
| 686 | // break; |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 687 | } |
| 688 | } else { |
| 689 | switch (ext_bit) { |
| 690 | case ProcHook::KHR_swapchain: |
| 691 | // map VK_KHR_swapchain to VK_ANDROID_native_buffer |
| 692 | name = VK_ANDROID_NATIVE_BUFFER_EXTENSION_NAME; |
| 693 | ext_bit = ProcHook::ANDROID_native_buffer; |
| 694 | break; |
Ian Elliott | 9e85373 | 2017-02-03 11:24:07 -0700 | [diff] [blame] | 695 | case ProcHook::KHR_incremental_present: |
Ian Elliott | 334a410 | 2022-12-22 18:51:09 +0000 | [diff] [blame] | 696 | case ProcHook::KHR_shared_presentable_image: |
Chris Forbes | 9d0d9ff | 2022-12-28 01:58:31 +0000 | [diff] [blame] | 697 | case ProcHook::GOOGLE_display_timing: |
Ian Elliott | 8a97726 | 2017-01-19 09:05:58 -0700 | [diff] [blame] | 698 | hook_extensions_.set(ext_bit); |
| 699 | // return now as these extensions do not require HAL support |
| 700 | return; |
Chris Forbes | 9d0d9ff | 2022-12-28 01:58:31 +0000 | [diff] [blame] | 701 | case ProcHook::EXT_swapchain_maintenance1: |
| 702 | // map VK_KHR_swapchain_maintenance1 to KHR_external_fence_fd |
| 703 | name = VK_KHR_EXTERNAL_FENCE_FD_EXTENSION_NAME; |
| 704 | ext_bit = ProcHook::KHR_external_fence_fd; |
| 705 | break; |
Courtney Goeltzenleuchter | d634c48 | 2017-01-05 15:55:31 -0700 | [diff] [blame] | 706 | case ProcHook::EXT_hdr_metadata: |
Yiwei Zhang | 2314310 | 2019-04-10 18:24:05 -0700 | [diff] [blame] | 707 | case ProcHook::KHR_bind_memory2: |
Courtney Goeltzenleuchter | d634c48 | 2017-01-05 15:55:31 -0700 | [diff] [blame] | 708 | hook_extensions_.set(ext_bit); |
| 709 | break; |
Jesse Hall | 7f983a8 | 2018-03-29 14:46:45 -0700 | [diff] [blame] | 710 | case ProcHook::ANDROID_external_memory_android_hardware_buffer: |
Chris Forbes | 9d0d9ff | 2022-12-28 01:58:31 +0000 | [diff] [blame] | 711 | case ProcHook::KHR_external_fence_fd: |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 712 | case ProcHook::EXTENSION_UNKNOWN: |
Jesse Hall | 7f983a8 | 2018-03-29 14:46:45 -0700 | [diff] [blame] | 713 | // 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] | 714 | break; |
Jesse Hall | 7f983a8 | 2018-03-29 14:46:45 -0700 | [diff] [blame] | 715 | |
| 716 | case ProcHook::KHR_android_surface: |
| 717 | case ProcHook::KHR_get_physical_device_properties2: |
Yiwei Zhang | e4f6417 | 2020-07-05 15:17:32 -0700 | [diff] [blame] | 718 | case ProcHook::KHR_device_group_creation: |
Yiwei Zhang | e1f3501 | 2020-07-05 22:52:04 -0700 | [diff] [blame] | 719 | case ProcHook::KHR_external_memory_capabilities: |
| 720 | case ProcHook::KHR_external_semaphore_capabilities: |
| 721 | case ProcHook::KHR_external_fence_capabilities: |
Jesse Hall | 7f983a8 | 2018-03-29 14:46:45 -0700 | [diff] [blame] | 722 | case ProcHook::KHR_get_surface_capabilities2: |
| 723 | case ProcHook::KHR_surface: |
Ian Elliott | bb67b24 | 2022-03-16 09:52:28 -0600 | [diff] [blame] | 724 | case ProcHook::KHR_surface_protected_capabilities: |
Jesse Hall | 7f983a8 | 2018-03-29 14:46:45 -0700 | [diff] [blame] | 725 | case ProcHook::EXT_debug_report: |
| 726 | case ProcHook::EXT_swapchain_colorspace: |
Chris Forbes | 9d0d9ff | 2022-12-28 01:58:31 +0000 | [diff] [blame] | 727 | case ProcHook::EXT_surface_maintenance1: |
Ian Elliott | 1ce053f | 2022-03-16 09:49:53 -0600 | [diff] [blame] | 728 | case ProcHook::GOOGLE_surfaceless_query: |
Jesse Hall | 7f983a8 | 2018-03-29 14:46:45 -0700 | [diff] [blame] | 729 | case ProcHook::ANDROID_native_buffer: |
Yiwei Zhang | 7cc36a5 | 2019-10-11 19:02:09 -0700 | [diff] [blame] | 730 | case ProcHook::EXTENSION_CORE_1_0: |
| 731 | case ProcHook::EXTENSION_CORE_1_1: |
Yiwei Zhang | 6be097b | 2020-10-19 20:22:05 -0700 | [diff] [blame] | 732 | case ProcHook::EXTENSION_CORE_1_2: |
Trevor David Black | b700ae8 | 2021-09-27 04:50:04 +0000 | [diff] [blame] | 733 | case ProcHook::EXTENSION_CORE_1_3: |
Jesse Hall | 7f983a8 | 2018-03-29 14:46:45 -0700 | [diff] [blame] | 734 | case ProcHook::EXTENSION_COUNT: |
| 735 | // Instance and meta extensions. If we ever get here it's a bug |
| 736 | // in our code. But enumerating them lets us avoid having a |
| 737 | // default case, and default hides other bugs. |
| 738 | ALOGE( |
| 739 | "CreateInfoWrapper::FilterExtension: invalid device " |
| 740 | "extension '%s'. FIX ME", |
| 741 | name); |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 742 | return; |
Jesse Hall | 7f983a8 | 2018-03-29 14:46:45 -0700 | [diff] [blame] | 743 | |
| 744 | // Don't use a default case. Without it, -Wswitch will tell us |
| 745 | // at compile time if someone adds a new ProcHook extension but |
| 746 | // doesn't handle it above. That's a real bug that has |
| 747 | // not-immediately-obvious effects. |
| 748 | // |
| 749 | // default: |
| 750 | // break; |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 751 | } |
| 752 | } |
| 753 | |
| 754 | for (uint32_t i = 0; i < filter.ext_count; i++) { |
| 755 | const VkExtensionProperties& props = filter.exts[i]; |
| 756 | // ignore unknown extensions |
| 757 | if (strcmp(name, props.extensionName) != 0) |
| 758 | continue; |
| 759 | |
Chris Forbes | 9d0d9ff | 2022-12-28 01:58:31 +0000 | [diff] [blame] | 760 | if (ext_bit != ProcHook::EXTENSION_UNKNOWN && |
| 761 | hal_extensions_.test(ext_bit)) { |
| 762 | ALOGI("CreateInfoWrapper::FilterExtension: already have '%s'.", name); |
| 763 | continue; |
| 764 | } |
| 765 | |
Ian Elliott | 3b48e15 | 2023-08-10 13:32:55 -0600 | [diff] [blame] | 766 | // Ignore duplicate extensions (see: b/288929054) |
| 767 | bool duplicate_entry = false; |
| 768 | for (uint32_t j = 0; j < filter.name_count; j++) { |
| 769 | if (strcmp(name, filter.names[j]) == 0) { |
| 770 | duplicate_entry = true; |
| 771 | break; |
| 772 | } |
| 773 | } |
| 774 | if (duplicate_entry == true) |
| 775 | continue; |
| 776 | |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 777 | filter.names[filter.name_count++] = name; |
Chia-I Wu | 1600e26 | 2016-04-12 09:40:06 +0800 | [diff] [blame] | 778 | if (ext_bit != ProcHook::EXTENSION_UNKNOWN) { |
| 779 | if (ext_bit == ProcHook::ANDROID_native_buffer) |
| 780 | hook_extensions_.set(ProcHook::KHR_swapchain); |
Chris Forbes | 9d0d9ff | 2022-12-28 01:58:31 +0000 | [diff] [blame] | 781 | if (ext_bit == ProcHook::KHR_external_fence_fd) |
| 782 | hook_extensions_.set(ProcHook::EXT_swapchain_maintenance1); |
Chia-I Wu | 1600e26 | 2016-04-12 09:40:06 +0800 | [diff] [blame] | 783 | |
| 784 | hal_extensions_.set(ext_bit); |
| 785 | } |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 786 | |
| 787 | break; |
| 788 | } |
| 789 | } |
| 790 | |
Chia-I Wu | dbb7e9c | 2016-03-24 15:09:38 +0800 | [diff] [blame] | 791 | VKAPI_ATTR void* DefaultAllocate(void*, |
| 792 | size_t size, |
| 793 | size_t alignment, |
| 794 | VkSystemAllocationScope) { |
| 795 | void* ptr = nullptr; |
| 796 | // Vulkan requires 'alignment' to be a power of two, but posix_memalign |
| 797 | // additionally requires that it be at least sizeof(void*). |
| 798 | int ret = posix_memalign(&ptr, std::max(alignment, sizeof(void*)), size); |
| 799 | ALOGD_CALLSTACK("Allocate: size=%zu align=%zu => (%d) %p", size, alignment, |
| 800 | ret, ptr); |
| 801 | return ret == 0 ? ptr : nullptr; |
| 802 | } |
| 803 | |
| 804 | VKAPI_ATTR void* DefaultReallocate(void*, |
| 805 | void* ptr, |
| 806 | size_t size, |
| 807 | size_t alignment, |
| 808 | VkSystemAllocationScope) { |
| 809 | if (size == 0) { |
| 810 | free(ptr); |
| 811 | return nullptr; |
| 812 | } |
| 813 | |
Yiwei Zhang | a885c06 | 2019-10-24 12:07:57 -0700 | [diff] [blame] | 814 | // 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] | 815 | // request is smaller than the existing chunk, we just continue using it. |
| 816 | // Right now the loader never reallocs, so this doesn't matter. If that |
| 817 | // changes, or if this code is copied into some other project, this should |
| 818 | // probably have a heuristic to allocate-copy-free when doing so will save |
| 819 | // "enough" space. |
| 820 | size_t old_size = ptr ? malloc_usable_size(ptr) : 0; |
| 821 | if (size <= old_size) |
| 822 | return ptr; |
| 823 | |
| 824 | void* new_ptr = nullptr; |
| 825 | if (posix_memalign(&new_ptr, std::max(alignment, sizeof(void*)), size) != 0) |
| 826 | return nullptr; |
| 827 | if (ptr) { |
| 828 | memcpy(new_ptr, ptr, std::min(old_size, size)); |
| 829 | free(ptr); |
| 830 | } |
| 831 | return new_ptr; |
| 832 | } |
| 833 | |
| 834 | VKAPI_ATTR void DefaultFree(void*, void* ptr) { |
| 835 | ALOGD_CALLSTACK("Free: %p", ptr); |
| 836 | free(ptr); |
| 837 | } |
| 838 | |
Chia-I Wu | ff4a6c7 | 2016-03-24 16:05:56 +0800 | [diff] [blame] | 839 | InstanceData* AllocateInstanceData(const VkAllocationCallbacks& allocator) { |
| 840 | void* data_mem = allocator.pfnAllocation( |
| 841 | allocator.pUserData, sizeof(InstanceData), alignof(InstanceData), |
| 842 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
| 843 | if (!data_mem) |
| 844 | return nullptr; |
| 845 | |
| 846 | return new (data_mem) InstanceData(allocator); |
| 847 | } |
| 848 | |
| 849 | void FreeInstanceData(InstanceData* data, |
| 850 | const VkAllocationCallbacks& allocator) { |
| 851 | data->~InstanceData(); |
| 852 | allocator.pfnFree(allocator.pUserData, data); |
| 853 | } |
| 854 | |
Chia-I Wu | 950d6e1 | 2016-05-03 09:12:35 +0800 | [diff] [blame] | 855 | DeviceData* AllocateDeviceData( |
| 856 | const VkAllocationCallbacks& allocator, |
| 857 | const DebugReportCallbackList& debug_report_callbacks) { |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 858 | void* data_mem = allocator.pfnAllocation( |
| 859 | allocator.pUserData, sizeof(DeviceData), alignof(DeviceData), |
| 860 | VK_SYSTEM_ALLOCATION_SCOPE_DEVICE); |
| 861 | if (!data_mem) |
| 862 | return nullptr; |
| 863 | |
Chia-I Wu | 950d6e1 | 2016-05-03 09:12:35 +0800 | [diff] [blame] | 864 | return new (data_mem) DeviceData(allocator, debug_report_callbacks); |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 865 | } |
| 866 | |
| 867 | void FreeDeviceData(DeviceData* data, const VkAllocationCallbacks& allocator) { |
| 868 | data->~DeviceData(); |
| 869 | allocator.pfnFree(allocator.pUserData, data); |
| 870 | } |
| 871 | |
Chia-I Wu | 136b8eb | 2016-03-24 15:01:52 +0800 | [diff] [blame] | 872 | } // anonymous namespace |
| 873 | |
Chia-I Wu | 136b8eb | 2016-03-24 15:01:52 +0800 | [diff] [blame] | 874 | bool OpenHAL() { |
Chia-I Wu | 31b2e4f | 2016-05-23 10:47:57 +0800 | [diff] [blame] | 875 | return Hal::Open(); |
Chia-I Wu | 136b8eb | 2016-03-24 15:01:52 +0800 | [diff] [blame] | 876 | } |
| 877 | |
Chia-I Wu | dbb7e9c | 2016-03-24 15:09:38 +0800 | [diff] [blame] | 878 | const VkAllocationCallbacks& GetDefaultAllocator() { |
| 879 | static const VkAllocationCallbacks kDefaultAllocCallbacks = { |
| 880 | .pUserData = nullptr, |
| 881 | .pfnAllocation = DefaultAllocate, |
| 882 | .pfnReallocation = DefaultReallocate, |
| 883 | .pfnFree = DefaultFree, |
| 884 | }; |
| 885 | |
| 886 | return kDefaultAllocCallbacks; |
| 887 | } |
| 888 | |
Chia-I Wu | eb7db12 | 2016-03-24 09:11:06 +0800 | [diff] [blame] | 889 | PFN_vkVoidFunction GetInstanceProcAddr(VkInstance instance, const char* pName) { |
| 890 | const ProcHook* hook = GetProcHook(pName); |
| 891 | if (!hook) |
Chia-I Wu | 31b2e4f | 2016-05-23 10:47:57 +0800 | [diff] [blame] | 892 | return Hal::Device().GetInstanceProcAddr(instance, pName); |
Chia-I Wu | eb7db12 | 2016-03-24 09:11:06 +0800 | [diff] [blame] | 893 | |
| 894 | if (!instance) { |
| 895 | if (hook->type == ProcHook::GLOBAL) |
| 896 | return hook->proc; |
| 897 | |
Chia-I Wu | 109f898 | 2016-04-22 06:40:40 +0800 | [diff] [blame] | 898 | // v0 layers expect |
| 899 | // |
| 900 | // vkGetInstanceProcAddr(VK_NULL_HANDLE, "vkCreateDevice"); |
| 901 | // |
| 902 | // to work. |
| 903 | if (strcmp(pName, "vkCreateDevice") == 0) |
| 904 | return hook->proc; |
| 905 | |
Chia-I Wu | eb7db12 | 2016-03-24 09:11:06 +0800 | [diff] [blame] | 906 | ALOGE( |
Chia-I Wu | e201c3f | 2016-05-03 13:26:08 +0800 | [diff] [blame] | 907 | "internal vkGetInstanceProcAddr called for %s without an instance", |
Chia-I Wu | eb7db12 | 2016-03-24 09:11:06 +0800 | [diff] [blame] | 908 | pName); |
| 909 | |
Chia-I Wu | 109f898 | 2016-04-22 06:40:40 +0800 | [diff] [blame] | 910 | return nullptr; |
Chia-I Wu | eb7db12 | 2016-03-24 09:11:06 +0800 | [diff] [blame] | 911 | } |
| 912 | |
| 913 | PFN_vkVoidFunction proc; |
| 914 | |
| 915 | switch (hook->type) { |
| 916 | case ProcHook::INSTANCE: |
| 917 | proc = (GetData(instance).hook_extensions[hook->extension]) |
| 918 | ? hook->proc |
Chia-I Wu | 36cc00a | 2016-04-13 16:52:06 +0800 | [diff] [blame] | 919 | : nullptr; |
Chia-I Wu | eb7db12 | 2016-03-24 09:11:06 +0800 | [diff] [blame] | 920 | break; |
| 921 | case ProcHook::DEVICE: |
Yiwei Zhang | 7cc36a5 | 2019-10-11 19:02:09 -0700 | [diff] [blame] | 922 | proc = (hook->extension == ProcHook::EXTENSION_CORE_1_0) |
Chia-I Wu | eb7db12 | 2016-03-24 09:11:06 +0800 | [diff] [blame] | 923 | ? hook->proc |
| 924 | : hook->checked_proc; |
| 925 | break; |
| 926 | default: |
| 927 | ALOGE( |
Chia-I Wu | e201c3f | 2016-05-03 13:26:08 +0800 | [diff] [blame] | 928 | "internal vkGetInstanceProcAddr called for %s with an instance", |
Chia-I Wu | eb7db12 | 2016-03-24 09:11:06 +0800 | [diff] [blame] | 929 | pName); |
| 930 | proc = nullptr; |
| 931 | break; |
| 932 | } |
| 933 | |
| 934 | return proc; |
| 935 | } |
| 936 | |
| 937 | PFN_vkVoidFunction GetDeviceProcAddr(VkDevice device, const char* pName) { |
| 938 | const ProcHook* hook = GetProcHook(pName); |
| 939 | if (!hook) |
Chia-I Wu | cc5e276 | 2016-03-24 13:01:16 +0800 | [diff] [blame] | 940 | return GetData(device).driver.GetDeviceProcAddr(device, pName); |
Chia-I Wu | eb7db12 | 2016-03-24 09:11:06 +0800 | [diff] [blame] | 941 | |
| 942 | if (hook->type != ProcHook::DEVICE) { |
Chia-I Wu | e201c3f | 2016-05-03 13:26:08 +0800 | [diff] [blame] | 943 | ALOGE("internal vkGetDeviceProcAddr called for %s", pName); |
Chia-I Wu | eb7db12 | 2016-03-24 09:11:06 +0800 | [diff] [blame] | 944 | return nullptr; |
| 945 | } |
| 946 | |
Chia-I Wu | 36cc00a | 2016-04-13 16:52:06 +0800 | [diff] [blame] | 947 | return (GetData(device).hook_extensions[hook->extension]) ? hook->proc |
| 948 | : nullptr; |
Chia-I Wu | eb7db12 | 2016-03-24 09:11:06 +0800 | [diff] [blame] | 949 | } |
| 950 | |
Chia-I Wu | ff4a6c7 | 2016-03-24 16:05:56 +0800 | [diff] [blame] | 951 | VkResult EnumerateInstanceExtensionProperties( |
| 952 | const char* pLayerName, |
| 953 | uint32_t* pPropertyCount, |
| 954 | VkExtensionProperties* pProperties) { |
Yiwei Zhang | 5e86220 | 2019-06-21 14:59:16 -0700 | [diff] [blame] | 955 | std::vector<VkExtensionProperties> loader_extensions; |
Ian Elliott | c7c4aa3 | 2022-02-28 16:47:43 -0700 | [diff] [blame] | 956 | loader_extensions.push_back( |
Ian Elliott | 4d1ad47 | 2022-03-14 17:27:47 -0600 | [diff] [blame] | 957 | {VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_SURFACE_SPEC_VERSION}); |
Ian Elliott | bb67b24 | 2022-03-16 09:52:28 -0600 | [diff] [blame] | 958 | loader_extensions.push_back( |
| 959 | {VK_KHR_SURFACE_PROTECTED_CAPABILITIES_EXTENSION_NAME, |
| 960 | VK_KHR_SURFACE_PROTECTED_CAPABILITIES_SPEC_VERSION}); |
Ian Elliott | 34a327b | 2017-03-28 13:20:35 -0600 | [diff] [blame] | 961 | loader_extensions.push_back({ |
| 962 | VK_KHR_ANDROID_SURFACE_EXTENSION_NAME, |
| 963 | VK_KHR_ANDROID_SURFACE_SPEC_VERSION}); |
| 964 | loader_extensions.push_back({ |
| 965 | VK_EXT_SWAPCHAIN_COLOR_SPACE_EXTENSION_NAME, |
| 966 | VK_EXT_SWAPCHAIN_COLOR_SPACE_SPEC_VERSION}); |
Ian Elliott | e7f036c | 2022-03-15 16:49:21 -0600 | [diff] [blame] | 967 | loader_extensions.push_back( |
| 968 | {VK_KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME, |
| 969 | VK_KHR_GET_SURFACE_CAPABILITIES_2_SPEC_VERSION}); |
Ian Elliott | 1ce053f | 2022-03-16 09:49:53 -0600 | [diff] [blame] | 970 | loader_extensions.push_back({VK_GOOGLE_SURFACELESS_QUERY_EXTENSION_NAME, |
| 971 | VK_GOOGLE_SURFACELESS_QUERY_SPEC_VERSION}); |
Chris Forbes | 9d0d9ff | 2022-12-28 01:58:31 +0000 | [diff] [blame] | 972 | loader_extensions.push_back({ |
| 973 | VK_EXT_SURFACE_MAINTENANCE_1_EXTENSION_NAME, |
| 974 | VK_EXT_SURFACE_MAINTENANCE_1_SPEC_VERSION}); |
Ian Elliott | 34a327b | 2017-03-28 13:20:35 -0600 | [diff] [blame] | 975 | |
Chia-I Wu | 3193825 | 2016-05-23 15:31:02 +0800 | [diff] [blame] | 976 | static const VkExtensionProperties loader_debug_report_extension = { |
| 977 | VK_EXT_DEBUG_REPORT_EXTENSION_NAME, VK_EXT_DEBUG_REPORT_SPEC_VERSION, |
| 978 | }; |
Chia-I Wu | ff4a6c7 | 2016-03-24 16:05:56 +0800 | [diff] [blame] | 979 | |
| 980 | // enumerate our extensions first |
| 981 | if (!pLayerName && pProperties) { |
| 982 | uint32_t count = std::min( |
| 983 | *pPropertyCount, static_cast<uint32_t>(loader_extensions.size())); |
| 984 | |
Yiwei Zhang | 5e86220 | 2019-06-21 14:59:16 -0700 | [diff] [blame] | 985 | std::copy_n(loader_extensions.data(), count, pProperties); |
Chia-I Wu | ff4a6c7 | 2016-03-24 16:05:56 +0800 | [diff] [blame] | 986 | |
| 987 | if (count < loader_extensions.size()) { |
| 988 | *pPropertyCount = count; |
| 989 | return VK_INCOMPLETE; |
| 990 | } |
| 991 | |
| 992 | pProperties += count; |
| 993 | *pPropertyCount -= count; |
Chia-I Wu | 3193825 | 2016-05-23 15:31:02 +0800 | [diff] [blame] | 994 | |
| 995 | if (Hal::Get().GetDebugReportIndex() < 0) { |
| 996 | if (!*pPropertyCount) { |
| 997 | *pPropertyCount = count; |
| 998 | return VK_INCOMPLETE; |
| 999 | } |
| 1000 | |
| 1001 | pProperties[0] = loader_debug_report_extension; |
| 1002 | pProperties += 1; |
| 1003 | *pPropertyCount -= 1; |
| 1004 | } |
Chia-I Wu | ff4a6c7 | 2016-03-24 16:05:56 +0800 | [diff] [blame] | 1005 | } |
| 1006 | |
Yiwei Zhang | fdd0c2a | 2019-01-30 20:16:37 -0800 | [diff] [blame] | 1007 | ATRACE_BEGIN("driver.EnumerateInstanceExtensionProperties"); |
Chia-I Wu | 31b2e4f | 2016-05-23 10:47:57 +0800 | [diff] [blame] | 1008 | VkResult result = Hal::Device().EnumerateInstanceExtensionProperties( |
Chia-I Wu | ff4a6c7 | 2016-03-24 16:05:56 +0800 | [diff] [blame] | 1009 | pLayerName, pPropertyCount, pProperties); |
Yiwei Zhang | fdd0c2a | 2019-01-30 20:16:37 -0800 | [diff] [blame] | 1010 | ATRACE_END(); |
Chia-I Wu | ff4a6c7 | 2016-03-24 16:05:56 +0800 | [diff] [blame] | 1011 | |
Chia-I Wu | 3193825 | 2016-05-23 15:31:02 +0800 | [diff] [blame] | 1012 | if (!pLayerName && (result == VK_SUCCESS || result == VK_INCOMPLETE)) { |
| 1013 | int idx = Hal::Get().GetDebugReportIndex(); |
| 1014 | if (idx < 0) { |
| 1015 | *pPropertyCount += 1; |
| 1016 | } else if (pProperties && |
| 1017 | static_cast<uint32_t>(idx) < *pPropertyCount) { |
| 1018 | pProperties[idx].specVersion = |
| 1019 | std::min(pProperties[idx].specVersion, |
| 1020 | loader_debug_report_extension.specVersion); |
| 1021 | } |
| 1022 | |
Chia-I Wu | ff4a6c7 | 2016-03-24 16:05:56 +0800 | [diff] [blame] | 1023 | *pPropertyCount += loader_extensions.size(); |
Chia-I Wu | 3193825 | 2016-05-23 15:31:02 +0800 | [diff] [blame] | 1024 | } |
Chia-I Wu | ff4a6c7 | 2016-03-24 16:05:56 +0800 | [diff] [blame] | 1025 | |
| 1026 | return result; |
| 1027 | } |
| 1028 | |
Yiwei Zhang | 93b521c | 2020-07-11 16:32:09 -0700 | [diff] [blame] | 1029 | void QueryPresentationProperties( |
Chris Forbes | fa25e63 | 2017-02-22 12:36:02 +1300 | [diff] [blame] | 1030 | VkPhysicalDevice physicalDevice, |
Yiwei Zhang | 93b521c | 2020-07-11 16:32:09 -0700 | [diff] [blame] | 1031 | VkPhysicalDevicePresentationPropertiesANDROID* presentation_properties) { |
Chris Forbes | e056c12 | 2021-07-22 13:54:04 -0700 | [diff] [blame] | 1032 | ATRACE_CALL(); |
| 1033 | |
Chris Forbes | fa25e63 | 2017-02-22 12:36:02 +1300 | [diff] [blame] | 1034 | // Request the android-specific presentation properties via GPDP2 |
Yiwei Zhang | 93b521c | 2020-07-11 16:32:09 -0700 | [diff] [blame] | 1035 | VkPhysicalDeviceProperties2 properties = { |
| 1036 | VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2, |
Chris Forbes | fa25e63 | 2017-02-22 12:36:02 +1300 | [diff] [blame] | 1037 | presentation_properties, |
Yiwei Zhang | 93b521c | 2020-07-11 16:32:09 -0700 | [diff] [blame] | 1038 | {}, |
Chris Forbes | fa25e63 | 2017-02-22 12:36:02 +1300 | [diff] [blame] | 1039 | }; |
| 1040 | |
| 1041 | #pragma clang diagnostic push |
| 1042 | #pragma clang diagnostic ignored "-Wold-style-cast" |
| 1043 | presentation_properties->sType = |
| 1044 | VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRESENTATION_PROPERTIES_ANDROID; |
| 1045 | #pragma clang diagnostic pop |
| 1046 | presentation_properties->pNext = nullptr; |
| 1047 | presentation_properties->sharedImage = VK_FALSE; |
| 1048 | |
Chris Forbes | e056c12 | 2021-07-22 13:54:04 -0700 | [diff] [blame] | 1049 | const auto& driver = GetData(physicalDevice).driver; |
| 1050 | |
| 1051 | if (driver.GetPhysicalDeviceProperties2) { |
| 1052 | // >= 1.1 driver, supports core GPDP2 entrypoint. |
| 1053 | driver.GetPhysicalDeviceProperties2(physicalDevice, &properties); |
| 1054 | } else if (driver.GetPhysicalDeviceProperties2KHR) { |
| 1055 | // Old driver, but may support presentation properties |
| 1056 | // if we have the GPDP2 extension. Otherwise, no presentation |
| 1057 | // properties supported. |
| 1058 | driver.GetPhysicalDeviceProperties2KHR(physicalDevice, &properties); |
| 1059 | } |
Chris Forbes | fa25e63 | 2017-02-22 12:36:02 +1300 | [diff] [blame] | 1060 | } |
| 1061 | |
Trevor David Black | 929e9cd | 2022-11-22 04:12:19 +0000 | [diff] [blame] | 1062 | VkResult GetAndroidNativeBufferSpecVersion9Support( |
| 1063 | VkPhysicalDevice physicalDevice, |
| 1064 | bool& support) { |
| 1065 | support = false; |
| 1066 | |
Trevor David Black | 2cc4468 | 2022-03-09 00:31:38 +0000 | [diff] [blame] | 1067 | const InstanceData& data = GetData(physicalDevice); |
| 1068 | |
| 1069 | // Call to get propertyCount |
| 1070 | uint32_t propertyCount = 0; |
| 1071 | ATRACE_BEGIN("driver.EnumerateDeviceExtensionProperties"); |
| 1072 | VkResult result = data.driver.EnumerateDeviceExtensionProperties( |
| 1073 | physicalDevice, nullptr, &propertyCount, nullptr); |
| 1074 | ATRACE_END(); |
| 1075 | |
Trevor David Black | 929e9cd | 2022-11-22 04:12:19 +0000 | [diff] [blame] | 1076 | if (result != VK_SUCCESS && result != VK_INCOMPLETE) { |
| 1077 | return result; |
| 1078 | } |
| 1079 | |
Trevor David Black | 2cc4468 | 2022-03-09 00:31:38 +0000 | [diff] [blame] | 1080 | // Call to enumerate properties |
| 1081 | std::vector<VkExtensionProperties> properties(propertyCount); |
| 1082 | ATRACE_BEGIN("driver.EnumerateDeviceExtensionProperties"); |
| 1083 | result = data.driver.EnumerateDeviceExtensionProperties( |
| 1084 | physicalDevice, nullptr, &propertyCount, properties.data()); |
| 1085 | ATRACE_END(); |
| 1086 | |
Trevor David Black | 929e9cd | 2022-11-22 04:12:19 +0000 | [diff] [blame] | 1087 | if (result != VK_SUCCESS && result != VK_INCOMPLETE) { |
| 1088 | return result; |
| 1089 | } |
| 1090 | |
Trevor David Black | 2cc4468 | 2022-03-09 00:31:38 +0000 | [diff] [blame] | 1091 | for (uint32_t i = 0; i < propertyCount; i++) { |
| 1092 | auto& prop = properties[i]; |
| 1093 | |
| 1094 | if (strcmp(prop.extensionName, |
| 1095 | VK_ANDROID_NATIVE_BUFFER_EXTENSION_NAME) != 0) |
| 1096 | continue; |
| 1097 | |
| 1098 | if (prop.specVersion >= 9) { |
Trevor David Black | 929e9cd | 2022-11-22 04:12:19 +0000 | [diff] [blame] | 1099 | support = true; |
| 1100 | return result; |
Trevor David Black | 2cc4468 | 2022-03-09 00:31:38 +0000 | [diff] [blame] | 1101 | } |
| 1102 | } |
| 1103 | |
Trevor David Black | 929e9cd | 2022-11-22 04:12:19 +0000 | [diff] [blame] | 1104 | return result; |
Trevor David Black | 2cc4468 | 2022-03-09 00:31:38 +0000 | [diff] [blame] | 1105 | } |
| 1106 | |
Chris Forbes | 9d0d9ff | 2022-12-28 01:58:31 +0000 | [diff] [blame] | 1107 | bool CanSupportSwapchainMaintenance1Extension(VkPhysicalDevice physicalDevice) { |
| 1108 | const auto& driver = GetData(physicalDevice).driver; |
| 1109 | if (!driver.GetPhysicalDeviceExternalFenceProperties) |
| 1110 | return false; |
| 1111 | |
| 1112 | // Requires support for external fences imported from sync fds. |
| 1113 | // This is _almost_ universal on Android, but may be missing on |
| 1114 | // some extremely old drivers, or on strange implementations like |
| 1115 | // cuttlefish. |
| 1116 | VkPhysicalDeviceExternalFenceInfo fenceInfo = { |
| 1117 | VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_FENCE_INFO, |
| 1118 | nullptr, |
| 1119 | VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT |
| 1120 | }; |
| 1121 | VkExternalFenceProperties fenceProperties = { |
| 1122 | VK_STRUCTURE_TYPE_EXTERNAL_FENCE_PROPERTIES, |
| 1123 | nullptr, |
| 1124 | 0, 0, 0 |
| 1125 | }; |
| 1126 | |
| 1127 | GetPhysicalDeviceExternalFenceProperties(physicalDevice, &fenceInfo, &fenceProperties); |
| 1128 | if (fenceProperties.externalFenceFeatures & VK_EXTERNAL_FENCE_FEATURE_IMPORTABLE_BIT) |
| 1129 | return true; |
| 1130 | |
| 1131 | return false; |
| 1132 | } |
| 1133 | |
Chia-I Wu | 01cf305 | 2016-03-24 16:16:21 +0800 | [diff] [blame] | 1134 | VkResult EnumerateDeviceExtensionProperties( |
| 1135 | VkPhysicalDevice physicalDevice, |
| 1136 | const char* pLayerName, |
| 1137 | uint32_t* pPropertyCount, |
| 1138 | VkExtensionProperties* pProperties) { |
| 1139 | const InstanceData& data = GetData(physicalDevice); |
Chris Forbes | fa25e63 | 2017-02-22 12:36:02 +1300 | [diff] [blame] | 1140 | // extensions that are unconditionally exposed by the loader |
Yiwei Zhang | 5e86220 | 2019-06-21 14:59:16 -0700 | [diff] [blame] | 1141 | std::vector<VkExtensionProperties> loader_extensions; |
Chris Forbes | fa25e63 | 2017-02-22 12:36:02 +1300 | [diff] [blame] | 1142 | loader_extensions.push_back({ |
| 1143 | VK_KHR_INCREMENTAL_PRESENT_EXTENSION_NAME, |
| 1144 | VK_KHR_INCREMENTAL_PRESENT_SPEC_VERSION}); |
Chris Forbes | fa25e63 | 2017-02-22 12:36:02 +1300 | [diff] [blame] | 1145 | |
Sundong Ahn | bc37dd5 | 2020-04-23 21:21:00 +0900 | [diff] [blame] | 1146 | bool hdrBoardConfig = android::sysprop::has_HDR_display(false); |
Courtney Goeltzenleuchter | 7671d46 | 2018-01-24 11:51:01 -0800 | [diff] [blame] | 1147 | if (hdrBoardConfig) { |
| 1148 | loader_extensions.push_back({VK_EXT_HDR_METADATA_EXTENSION_NAME, |
| 1149 | VK_EXT_HDR_METADATA_SPEC_VERSION}); |
| 1150 | } |
| 1151 | |
Chris Forbes | 1609500 | 2017-05-05 15:33:29 -0700 | [diff] [blame] | 1152 | VkPhysicalDevicePresentationPropertiesANDROID presentation_properties; |
Yiwei Zhang | 93b521c | 2020-07-11 16:32:09 -0700 | [diff] [blame] | 1153 | QueryPresentationProperties(physicalDevice, &presentation_properties); |
| 1154 | if (presentation_properties.sharedImage) { |
Chris Forbes | 1609500 | 2017-05-05 15:33:29 -0700 | [diff] [blame] | 1155 | loader_extensions.push_back({ |
| 1156 | VK_KHR_SHARED_PRESENTABLE_IMAGE_EXTENSION_NAME, |
| 1157 | VK_KHR_SHARED_PRESENTABLE_IMAGE_SPEC_VERSION}); |
Chris Forbes | fa25e63 | 2017-02-22 12:36:02 +1300 | [diff] [blame] | 1158 | } |
Ian Elliott | d4b50aa | 2017-01-09 16:21:36 -0700 | [diff] [blame] | 1159 | |
Ian Elliott | 5c34de2 | 2017-04-10 14:42:30 -0600 | [diff] [blame] | 1160 | // conditionally add VK_GOOGLE_display_timing if present timestamps are |
| 1161 | // supported by the driver: |
Yiwei Zhang | 98d15e0 | 2020-08-15 13:48:36 -0700 | [diff] [blame] | 1162 | if (android::base::GetBoolProperty("service.sf.present_timestamp", false)) { |
Ian Elliott | 5c34de2 | 2017-04-10 14:42:30 -0600 | [diff] [blame] | 1163 | loader_extensions.push_back({ |
| 1164 | VK_GOOGLE_DISPLAY_TIMING_EXTENSION_NAME, |
| 1165 | VK_GOOGLE_DISPLAY_TIMING_SPEC_VERSION}); |
| 1166 | } |
| 1167 | |
Trevor David Black | 2cc4468 | 2022-03-09 00:31:38 +0000 | [diff] [blame] | 1168 | // Conditionally add VK_EXT_IMAGE_COMPRESSION_CONTROL* if feature and ANB |
| 1169 | // support is provided by the driver |
| 1170 | VkPhysicalDeviceImageCompressionControlSwapchainFeaturesEXT |
| 1171 | swapchainCompFeats = {}; |
| 1172 | swapchainCompFeats.sType = |
| 1173 | VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_COMPRESSION_CONTROL_SWAPCHAIN_FEATURES_EXT; |
| 1174 | swapchainCompFeats.pNext = nullptr; |
Trevor David Black | 929e9cd | 2022-11-22 04:12:19 +0000 | [diff] [blame] | 1175 | swapchainCompFeats.imageCompressionControlSwapchain = false; |
Trevor David Black | 2cc4468 | 2022-03-09 00:31:38 +0000 | [diff] [blame] | 1176 | VkPhysicalDeviceImageCompressionControlFeaturesEXT imageCompFeats = {}; |
| 1177 | imageCompFeats.sType = |
| 1178 | VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_COMPRESSION_CONTROL_FEATURES_EXT; |
| 1179 | imageCompFeats.pNext = &swapchainCompFeats; |
Trevor David Black | 929e9cd | 2022-11-22 04:12:19 +0000 | [diff] [blame] | 1180 | imageCompFeats.imageCompressionControl = false; |
Trevor David Black | 2cc4468 | 2022-03-09 00:31:38 +0000 | [diff] [blame] | 1181 | |
| 1182 | VkPhysicalDeviceFeatures2 feats2 = {}; |
| 1183 | feats2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2; |
| 1184 | feats2.pNext = &imageCompFeats; |
| 1185 | |
Trevor David Black | 929e9cd | 2022-11-22 04:12:19 +0000 | [diff] [blame] | 1186 | const auto& driver = GetData(physicalDevice).driver; |
| 1187 | if (driver.GetPhysicalDeviceFeatures2 || |
| 1188 | driver.GetPhysicalDeviceFeatures2KHR) { |
| 1189 | GetPhysicalDeviceFeatures2(physicalDevice, &feats2); |
| 1190 | } |
Trevor David Black | 2cc4468 | 2022-03-09 00:31:38 +0000 | [diff] [blame] | 1191 | |
Trevor David Black | 929e9cd | 2022-11-22 04:12:19 +0000 | [diff] [blame] | 1192 | bool anb9 = false; |
| 1193 | VkResult result = |
| 1194 | GetAndroidNativeBufferSpecVersion9Support(physicalDevice, anb9); |
| 1195 | |
| 1196 | if (result != VK_SUCCESS && result != VK_INCOMPLETE) { |
| 1197 | return result; |
| 1198 | } |
Trevor David Black | 2cc4468 | 2022-03-09 00:31:38 +0000 | [diff] [blame] | 1199 | |
| 1200 | if (anb9 && imageCompFeats.imageCompressionControl) { |
| 1201 | loader_extensions.push_back( |
| 1202 | {VK_EXT_IMAGE_COMPRESSION_CONTROL_EXTENSION_NAME, |
| 1203 | VK_EXT_IMAGE_COMPRESSION_CONTROL_SPEC_VERSION}); |
| 1204 | } |
| 1205 | if (anb9 && swapchainCompFeats.imageCompressionControlSwapchain) { |
| 1206 | loader_extensions.push_back( |
| 1207 | {VK_EXT_IMAGE_COMPRESSION_CONTROL_SWAPCHAIN_EXTENSION_NAME, |
| 1208 | VK_EXT_IMAGE_COMPRESSION_CONTROL_SWAPCHAIN_SPEC_VERSION}); |
| 1209 | } |
| 1210 | |
Chris Forbes | 9d0d9ff | 2022-12-28 01:58:31 +0000 | [diff] [blame] | 1211 | if (CanSupportSwapchainMaintenance1Extension(physicalDevice)) { |
| 1212 | loader_extensions.push_back({ |
| 1213 | VK_EXT_SWAPCHAIN_MAINTENANCE_1_EXTENSION_NAME, |
| 1214 | VK_EXT_SWAPCHAIN_MAINTENANCE_1_SPEC_VERSION}); |
| 1215 | } |
| 1216 | |
Ian Elliott | d4b50aa | 2017-01-09 16:21:36 -0700 | [diff] [blame] | 1217 | // enumerate our extensions first |
| 1218 | if (!pLayerName && pProperties) { |
| 1219 | uint32_t count = std::min( |
| 1220 | *pPropertyCount, static_cast<uint32_t>(loader_extensions.size())); |
| 1221 | |
Yiwei Zhang | 5e86220 | 2019-06-21 14:59:16 -0700 | [diff] [blame] | 1222 | std::copy_n(loader_extensions.data(), count, pProperties); |
Ian Elliott | d4b50aa | 2017-01-09 16:21:36 -0700 | [diff] [blame] | 1223 | |
| 1224 | if (count < loader_extensions.size()) { |
| 1225 | *pPropertyCount = count; |
| 1226 | return VK_INCOMPLETE; |
| 1227 | } |
| 1228 | |
| 1229 | pProperties += count; |
| 1230 | *pPropertyCount -= count; |
| 1231 | } |
Chia-I Wu | 01cf305 | 2016-03-24 16:16:21 +0800 | [diff] [blame] | 1232 | |
Yiwei Zhang | fdd0c2a | 2019-01-30 20:16:37 -0800 | [diff] [blame] | 1233 | ATRACE_BEGIN("driver.EnumerateDeviceExtensionProperties"); |
Trevor David Black | 929e9cd | 2022-11-22 04:12:19 +0000 | [diff] [blame] | 1234 | result = data.driver.EnumerateDeviceExtensionProperties( |
Chia-I Wu | 01cf305 | 2016-03-24 16:16:21 +0800 | [diff] [blame] | 1235 | physicalDevice, pLayerName, pPropertyCount, pProperties); |
Yiwei Zhang | fdd0c2a | 2019-01-30 20:16:37 -0800 | [diff] [blame] | 1236 | ATRACE_END(); |
Chia-I Wu | 01cf305 | 2016-03-24 16:16:21 +0800 | [diff] [blame] | 1237 | |
Ian Elliott | d4b50aa | 2017-01-09 16:21:36 -0700 | [diff] [blame] | 1238 | if (pProperties) { |
| 1239 | // map VK_ANDROID_native_buffer to VK_KHR_swapchain |
| 1240 | for (uint32_t i = 0; i < *pPropertyCount; i++) { |
| 1241 | auto& prop = pProperties[i]; |
Chia-I Wu | 01cf305 | 2016-03-24 16:16:21 +0800 | [diff] [blame] | 1242 | |
Ian Elliott | d4b50aa | 2017-01-09 16:21:36 -0700 | [diff] [blame] | 1243 | if (strcmp(prop.extensionName, |
| 1244 | VK_ANDROID_NATIVE_BUFFER_EXTENSION_NAME) != 0) |
| 1245 | continue; |
Chia-I Wu | 01cf305 | 2016-03-24 16:16:21 +0800 | [diff] [blame] | 1246 | |
Ian Elliott | d4b50aa | 2017-01-09 16:21:36 -0700 | [diff] [blame] | 1247 | memcpy(prop.extensionName, VK_KHR_SWAPCHAIN_EXTENSION_NAME, |
| 1248 | sizeof(VK_KHR_SWAPCHAIN_EXTENSION_NAME)); |
Yiwei Zhang | 14f4d42 | 2019-04-17 12:24:39 -0700 | [diff] [blame] | 1249 | |
| 1250 | if (prop.specVersion >= 8) { |
| 1251 | prop.specVersion = VK_KHR_SWAPCHAIN_SPEC_VERSION; |
| 1252 | } else { |
| 1253 | prop.specVersion = 68; |
| 1254 | } |
Ian Elliott | d4b50aa | 2017-01-09 16:21:36 -0700 | [diff] [blame] | 1255 | } |
| 1256 | } |
Chia-I Wu | 01cf305 | 2016-03-24 16:16:21 +0800 | [diff] [blame] | 1257 | |
Ian Elliott | d4b50aa | 2017-01-09 16:21:36 -0700 | [diff] [blame] | 1258 | // restore loader extension count |
| 1259 | if (!pLayerName && (result == VK_SUCCESS || result == VK_INCOMPLETE)) { |
| 1260 | *pPropertyCount += loader_extensions.size(); |
Chia-I Wu | 01cf305 | 2016-03-24 16:16:21 +0800 | [diff] [blame] | 1261 | } |
| 1262 | |
| 1263 | return result; |
| 1264 | } |
| 1265 | |
Chia-I Wu | ff4a6c7 | 2016-03-24 16:05:56 +0800 | [diff] [blame] | 1266 | VkResult CreateInstance(const VkInstanceCreateInfo* pCreateInfo, |
| 1267 | const VkAllocationCallbacks* pAllocator, |
| 1268 | VkInstance* pInstance) { |
| 1269 | const VkAllocationCallbacks& data_allocator = |
| 1270 | (pAllocator) ? *pAllocator : GetDefaultAllocator(); |
| 1271 | |
Yiwei Zhang | 2cefa73 | 2020-07-10 21:07:30 -0700 | [diff] [blame] | 1272 | VkResult result = VK_SUCCESS; |
| 1273 | uint32_t icd_api_version = VK_API_VERSION_1_0; |
| 1274 | PFN_vkEnumerateInstanceVersion pfn_enumerate_instance_version = |
| 1275 | reinterpret_cast<PFN_vkEnumerateInstanceVersion>( |
| 1276 | Hal::Device().GetInstanceProcAddr(nullptr, |
| 1277 | "vkEnumerateInstanceVersion")); |
| 1278 | if (pfn_enumerate_instance_version) { |
| 1279 | ATRACE_BEGIN("pfn_enumerate_instance_version"); |
| 1280 | result = (*pfn_enumerate_instance_version)(&icd_api_version); |
| 1281 | ATRACE_END(); |
| 1282 | if (result != VK_SUCCESS) |
| 1283 | return result; |
| 1284 | |
Trevor David Black | b68a225 | 2021-08-23 16:37:18 +0000 | [diff] [blame] | 1285 | icd_api_version ^= VK_API_VERSION_PATCH(icd_api_version); |
Yiwei Zhang | 2cefa73 | 2020-07-10 21:07:30 -0700 | [diff] [blame] | 1286 | } |
| 1287 | |
| 1288 | CreateInfoWrapper wrapper(*pCreateInfo, icd_api_version, data_allocator); |
| 1289 | result = wrapper.Validate(); |
Chia-I Wu | ff4a6c7 | 2016-03-24 16:05:56 +0800 | [diff] [blame] | 1290 | if (result != VK_SUCCESS) |
| 1291 | return result; |
| 1292 | |
| 1293 | InstanceData* data = AllocateInstanceData(data_allocator); |
| 1294 | if (!data) |
| 1295 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 1296 | |
Chia-I Wu | 3e6c2d6 | 2016-04-11 13:55:56 +0800 | [diff] [blame] | 1297 | data->hook_extensions |= wrapper.GetHookExtensions(); |
Chia-I Wu | ff4a6c7 | 2016-03-24 16:05:56 +0800 | [diff] [blame] | 1298 | |
| 1299 | // call into the driver |
| 1300 | VkInstance instance; |
Yiwei Zhang | fdd0c2a | 2019-01-30 20:16:37 -0800 | [diff] [blame] | 1301 | ATRACE_BEGIN("driver.CreateInstance"); |
Chia-I Wu | 31b2e4f | 2016-05-23 10:47:57 +0800 | [diff] [blame] | 1302 | result = Hal::Device().CreateInstance( |
Chia-I Wu | ff4a6c7 | 2016-03-24 16:05:56 +0800 | [diff] [blame] | 1303 | static_cast<const VkInstanceCreateInfo*>(wrapper), pAllocator, |
| 1304 | &instance); |
Yiwei Zhang | fdd0c2a | 2019-01-30 20:16:37 -0800 | [diff] [blame] | 1305 | ATRACE_END(); |
Chia-I Wu | ff4a6c7 | 2016-03-24 16:05:56 +0800 | [diff] [blame] | 1306 | if (result != VK_SUCCESS) { |
| 1307 | FreeInstanceData(data, data_allocator); |
| 1308 | return result; |
| 1309 | } |
| 1310 | |
| 1311 | // initialize InstanceDriverTable |
| 1312 | if (!SetData(instance, *data) || |
Chia-I Wu | 31b2e4f | 2016-05-23 10:47:57 +0800 | [diff] [blame] | 1313 | !InitDriverTable(instance, Hal::Device().GetInstanceProcAddr, |
Chia-I Wu | cbe07ef | 2016-04-13 15:01:00 +0800 | [diff] [blame] | 1314 | wrapper.GetHalExtensions())) { |
Chia-I Wu | ff4a6c7 | 2016-03-24 16:05:56 +0800 | [diff] [blame] | 1315 | data->driver.DestroyInstance = reinterpret_cast<PFN_vkDestroyInstance>( |
Chia-I Wu | 31b2e4f | 2016-05-23 10:47:57 +0800 | [diff] [blame] | 1316 | Hal::Device().GetInstanceProcAddr(instance, "vkDestroyInstance")); |
Chia-I Wu | ff4a6c7 | 2016-03-24 16:05:56 +0800 | [diff] [blame] | 1317 | if (data->driver.DestroyInstance) |
| 1318 | data->driver.DestroyInstance(instance, pAllocator); |
| 1319 | |
| 1320 | FreeInstanceData(data, data_allocator); |
| 1321 | |
| 1322 | return VK_ERROR_INCOMPATIBLE_DRIVER; |
| 1323 | } |
| 1324 | |
| 1325 | data->get_device_proc_addr = reinterpret_cast<PFN_vkGetDeviceProcAddr>( |
Chia-I Wu | 31b2e4f | 2016-05-23 10:47:57 +0800 | [diff] [blame] | 1326 | Hal::Device().GetInstanceProcAddr(instance, "vkGetDeviceProcAddr")); |
Chia-I Wu | ff4a6c7 | 2016-03-24 16:05:56 +0800 | [diff] [blame] | 1327 | if (!data->get_device_proc_addr) { |
| 1328 | data->driver.DestroyInstance(instance, pAllocator); |
| 1329 | FreeInstanceData(data, data_allocator); |
| 1330 | |
| 1331 | return VK_ERROR_INCOMPATIBLE_DRIVER; |
| 1332 | } |
| 1333 | |
Serdar Kocdemir | b2901c9 | 2022-11-17 00:39:05 +0000 | [diff] [blame] | 1334 | // TODO(b/259516419) avoid getting stats from hwui |
| 1335 | // const bool reportStats = (pCreateInfo->pApplicationInfo == nullptr ) |
| 1336 | // || (strcmp("android framework", |
| 1337 | // pCreateInfo->pApplicationInfo->pEngineName) != 0); |
| 1338 | const bool reportStats = true; |
| 1339 | if (reportStats) { |
| 1340 | // Set stats for Vulkan api version requested with application info |
| 1341 | if (pCreateInfo->pApplicationInfo) { |
| 1342 | const uint32_t vulkanApiVersion = |
| 1343 | pCreateInfo->pApplicationInfo->apiVersion; |
| 1344 | android::GraphicsEnv::getInstance().setTargetStats( |
| 1345 | android::GpuStatsInfo::Stats::CREATED_VULKAN_API_VERSION, |
| 1346 | vulkanApiVersion); |
| 1347 | } |
| 1348 | |
| 1349 | // Update stats for the extensions requested |
| 1350 | android::GraphicsEnv::getInstance().setVulkanInstanceExtensions( |
| 1351 | pCreateInfo->enabledExtensionCount, |
| 1352 | pCreateInfo->ppEnabledExtensionNames); |
| 1353 | } |
| 1354 | |
Chia-I Wu | ff4a6c7 | 2016-03-24 16:05:56 +0800 | [diff] [blame] | 1355 | *pInstance = instance; |
| 1356 | |
| 1357 | return VK_SUCCESS; |
| 1358 | } |
| 1359 | |
| 1360 | void DestroyInstance(VkInstance instance, |
| 1361 | const VkAllocationCallbacks* pAllocator) { |
| 1362 | InstanceData& data = GetData(instance); |
| 1363 | data.driver.DestroyInstance(instance, pAllocator); |
| 1364 | |
| 1365 | VkAllocationCallbacks local_allocator; |
| 1366 | if (!pAllocator) { |
| 1367 | local_allocator = data.allocator; |
| 1368 | pAllocator = &local_allocator; |
| 1369 | } |
| 1370 | |
| 1371 | FreeInstanceData(&data, *pAllocator); |
| 1372 | } |
| 1373 | |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 1374 | VkResult CreateDevice(VkPhysicalDevice physicalDevice, |
| 1375 | const VkDeviceCreateInfo* pCreateInfo, |
| 1376 | const VkAllocationCallbacks* pAllocator, |
| 1377 | VkDevice* pDevice) { |
| 1378 | const InstanceData& instance_data = GetData(physicalDevice); |
| 1379 | const VkAllocationCallbacks& data_allocator = |
| 1380 | (pAllocator) ? *pAllocator : instance_data.allocator; |
| 1381 | |
Yiwei Zhang | 2cefa73 | 2020-07-10 21:07:30 -0700 | [diff] [blame] | 1382 | VkPhysicalDeviceProperties properties; |
| 1383 | ATRACE_BEGIN("driver.GetPhysicalDeviceProperties"); |
| 1384 | instance_data.driver.GetPhysicalDeviceProperties(physicalDevice, |
| 1385 | &properties); |
| 1386 | ATRACE_END(); |
| 1387 | |
| 1388 | CreateInfoWrapper wrapper( |
| 1389 | physicalDevice, *pCreateInfo, |
Trevor David Black | b68a225 | 2021-08-23 16:37:18 +0000 | [diff] [blame] | 1390 | properties.apiVersion ^ VK_API_VERSION_PATCH(properties.apiVersion), |
Yiwei Zhang | 2cefa73 | 2020-07-10 21:07:30 -0700 | [diff] [blame] | 1391 | data_allocator); |
Chia-I Wu | 3e6c2d6 | 2016-04-11 13:55:56 +0800 | [diff] [blame] | 1392 | VkResult result = wrapper.Validate(); |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 1393 | if (result != VK_SUCCESS) |
| 1394 | return result; |
| 1395 | |
Yiwei Zhang | fdd0c2a | 2019-01-30 20:16:37 -0800 | [diff] [blame] | 1396 | ATRACE_BEGIN("AllocateDeviceData"); |
Chia-I Wu | 950d6e1 | 2016-05-03 09:12:35 +0800 | [diff] [blame] | 1397 | DeviceData* data = AllocateDeviceData(data_allocator, |
| 1398 | instance_data.debug_report_callbacks); |
Yiwei Zhang | fdd0c2a | 2019-01-30 20:16:37 -0800 | [diff] [blame] | 1399 | ATRACE_END(); |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 1400 | if (!data) |
| 1401 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 1402 | |
Chia-I Wu | 3e6c2d6 | 2016-04-11 13:55:56 +0800 | [diff] [blame] | 1403 | data->hook_extensions |= wrapper.GetHookExtensions(); |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 1404 | |
| 1405 | // call into the driver |
| 1406 | VkDevice dev; |
Yiwei Zhang | fdd0c2a | 2019-01-30 20:16:37 -0800 | [diff] [blame] | 1407 | ATRACE_BEGIN("driver.CreateDevice"); |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 1408 | result = instance_data.driver.CreateDevice( |
| 1409 | physicalDevice, static_cast<const VkDeviceCreateInfo*>(wrapper), |
| 1410 | pAllocator, &dev); |
Yiwei Zhang | fdd0c2a | 2019-01-30 20:16:37 -0800 | [diff] [blame] | 1411 | ATRACE_END(); |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 1412 | if (result != VK_SUCCESS) { |
| 1413 | FreeDeviceData(data, data_allocator); |
| 1414 | return result; |
| 1415 | } |
| 1416 | |
| 1417 | // initialize DeviceDriverTable |
| 1418 | if (!SetData(dev, *data) || |
Chia-I Wu | cbe07ef | 2016-04-13 15:01:00 +0800 | [diff] [blame] | 1419 | !InitDriverTable(dev, instance_data.get_device_proc_addr, |
| 1420 | wrapper.GetHalExtensions())) { |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 1421 | data->driver.DestroyDevice = reinterpret_cast<PFN_vkDestroyDevice>( |
| 1422 | instance_data.get_device_proc_addr(dev, "vkDestroyDevice")); |
| 1423 | if (data->driver.DestroyDevice) |
| 1424 | data->driver.DestroyDevice(dev, pAllocator); |
| 1425 | |
| 1426 | FreeDeviceData(data, data_allocator); |
| 1427 | |
| 1428 | return VK_ERROR_INCOMPATIBLE_DRIVER; |
| 1429 | } |
Chris Forbes | d827791 | 2017-02-10 14:59:59 +1300 | [diff] [blame] | 1430 | |
Trevor David Black | 2cc4468 | 2022-03-09 00:31:38 +0000 | [diff] [blame] | 1431 | // Confirming ANDROID_native_buffer implementation, whose set of |
Chris Forbes | d827791 | 2017-02-10 14:59:59 +1300 | [diff] [blame] | 1432 | // entrypoints varies according to the spec version. |
| 1433 | if ((wrapper.GetHalExtensions()[ProcHook::ANDROID_native_buffer]) && |
| 1434 | !data->driver.GetSwapchainGrallocUsageANDROID && |
Trevor David Black | 2cc4468 | 2022-03-09 00:31:38 +0000 | [diff] [blame] | 1435 | !data->driver.GetSwapchainGrallocUsage2ANDROID && |
Trevor David Black | b6ca842 | 2023-07-26 20:00:04 +0000 | [diff] [blame] | 1436 | !data->driver.GetSwapchainGrallocUsage3ANDROID && |
| 1437 | !data->driver.GetSwapchainGrallocUsage4ANDROID) { |
Trevor David Black | 2cc4468 | 2022-03-09 00:31:38 +0000 | [diff] [blame] | 1438 | ALOGE( |
| 1439 | "Driver's implementation of ANDROID_native_buffer is broken;" |
| 1440 | " must expose at least one of " |
| 1441 | "vkGetSwapchainGrallocUsageANDROID or " |
| 1442 | "vkGetSwapchainGrallocUsage2ANDROID or " |
Trevor David Black | b6ca842 | 2023-07-26 20:00:04 +0000 | [diff] [blame] | 1443 | "vkGetSwapchainGrallocUsage3ANDROID or " |
| 1444 | "vkGetSwapchainGrallocUsage4ANDROID"); |
Chris Forbes | d827791 | 2017-02-10 14:59:59 +1300 | [diff] [blame] | 1445 | |
| 1446 | data->driver.DestroyDevice(dev, pAllocator); |
| 1447 | FreeDeviceData(data, data_allocator); |
| 1448 | |
| 1449 | return VK_ERROR_INCOMPATIBLE_DRIVER; |
| 1450 | } |
| 1451 | |
Yiwei Zhang | 2cefa73 | 2020-07-10 21:07:30 -0700 | [diff] [blame] | 1452 | if (properties.deviceType == VK_PHYSICAL_DEVICE_TYPE_CPU) { |
| 1453 | // Log that the app is hitting software Vulkan implementation |
| 1454 | android::GraphicsEnv::getInstance().setTargetStats( |
| 1455 | android::GpuStatsInfo::Stats::CPU_VULKAN_IN_USE); |
| 1456 | } |
| 1457 | |
Jesse Hall | dc22507 | 2016-05-30 22:40:14 -0700 | [diff] [blame] | 1458 | data->driver_device = dev; |
Trevor David Black | d7320ef | 2023-08-23 21:21:51 +0000 | [diff] [blame^] | 1459 | data->driver_physical_device = physicalDevice; |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 1460 | |
| 1461 | *pDevice = dev; |
| 1462 | |
Serdar Kocdemir | b2901c9 | 2022-11-17 00:39:05 +0000 | [diff] [blame] | 1463 | // TODO(b/259516419) avoid getting stats from hwui |
| 1464 | const bool reportStats = true; |
| 1465 | if (reportStats) { |
| 1466 | android::GraphicsEnv::getInstance().setTargetStats( |
| 1467 | android::GpuStatsInfo::Stats::CREATED_VULKAN_DEVICE); |
| 1468 | |
| 1469 | // Set stats for creating a Vulkan device and report features in use |
| 1470 | const VkPhysicalDeviceFeatures* pEnabledFeatures = |
| 1471 | pCreateInfo->pEnabledFeatures; |
| 1472 | if (!pEnabledFeatures) { |
| 1473 | // Use features from the chained VkPhysicalDeviceFeatures2 |
| 1474 | // structure, if given |
| 1475 | const VkPhysicalDeviceFeatures2* features2 = |
| 1476 | reinterpret_cast<const VkPhysicalDeviceFeatures2*>( |
| 1477 | pCreateInfo->pNext); |
| 1478 | while (features2 && |
| 1479 | features2->sType != |
| 1480 | VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2) { |
| 1481 | features2 = reinterpret_cast<const VkPhysicalDeviceFeatures2*>( |
| 1482 | features2->pNext); |
| 1483 | } |
| 1484 | if (features2) { |
| 1485 | pEnabledFeatures = &features2->features; |
| 1486 | } |
| 1487 | } |
| 1488 | const VkBool32* pFeatures = |
| 1489 | reinterpret_cast<const VkBool32*>(pEnabledFeatures); |
| 1490 | if (pFeatures) { |
| 1491 | // VkPhysicalDeviceFeatures consists of VkBool32 values, go over all |
| 1492 | // of them using pointer arithmetic here and save the features in a |
| 1493 | // 64-bit bitfield |
| 1494 | static_assert( |
| 1495 | (sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32)) <= 64, |
| 1496 | "VkPhysicalDeviceFeatures has too many elements for bitfield " |
| 1497 | "packing"); |
| 1498 | static_assert( |
| 1499 | (sizeof(VkPhysicalDeviceFeatures) % sizeof(VkBool32)) == 0, |
| 1500 | "VkPhysicalDeviceFeatures has invalid size for bitfield " |
| 1501 | "packing"); |
| 1502 | const int numFeatures = |
| 1503 | sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32); |
| 1504 | |
| 1505 | uint64_t enableFeatureBits = 0; |
| 1506 | for (int i = 0; i < numFeatures; i++) { |
| 1507 | if (pFeatures[i] != VK_FALSE) { |
| 1508 | enableFeatureBits |= (uint64_t(1) << i); |
| 1509 | } |
| 1510 | } |
| 1511 | android::GraphicsEnv::getInstance().setTargetStats( |
| 1512 | android::GpuStatsInfo::Stats::VULKAN_DEVICE_FEATURES_ENABLED, |
| 1513 | enableFeatureBits); |
| 1514 | } |
| 1515 | |
| 1516 | // Update stats for the extensions requested |
| 1517 | android::GraphicsEnv::getInstance().setVulkanDeviceExtensions( |
| 1518 | pCreateInfo->enabledExtensionCount, |
| 1519 | pCreateInfo->ppEnabledExtensionNames); |
| 1520 | } |
| 1521 | |
Chia-I Wu | 4901db7 | 2016-03-24 16:38:58 +0800 | [diff] [blame] | 1522 | return VK_SUCCESS; |
| 1523 | } |
| 1524 | |
| 1525 | void DestroyDevice(VkDevice device, const VkAllocationCallbacks* pAllocator) { |
| 1526 | DeviceData& data = GetData(device); |
| 1527 | data.driver.DestroyDevice(device, pAllocator); |
| 1528 | |
| 1529 | VkAllocationCallbacks local_allocator; |
| 1530 | if (!pAllocator) { |
| 1531 | local_allocator = data.allocator; |
| 1532 | pAllocator = &local_allocator; |
| 1533 | } |
| 1534 | |
| 1535 | FreeDeviceData(&data, *pAllocator); |
| 1536 | } |
| 1537 | |
Chia-I Wu | ff4a6c7 | 2016-03-24 16:05:56 +0800 | [diff] [blame] | 1538 | VkResult EnumeratePhysicalDevices(VkInstance instance, |
| 1539 | uint32_t* pPhysicalDeviceCount, |
| 1540 | VkPhysicalDevice* pPhysicalDevices) { |
Yiwei Zhang | fdd0c2a | 2019-01-30 20:16:37 -0800 | [diff] [blame] | 1541 | ATRACE_CALL(); |
| 1542 | |
Chia-I Wu | ff4a6c7 | 2016-03-24 16:05:56 +0800 | [diff] [blame] | 1543 | const auto& data = GetData(instance); |
| 1544 | |
| 1545 | VkResult result = data.driver.EnumeratePhysicalDevices( |
| 1546 | instance, pPhysicalDeviceCount, pPhysicalDevices); |
| 1547 | if ((result == VK_SUCCESS || result == VK_INCOMPLETE) && pPhysicalDevices) { |
| 1548 | for (uint32_t i = 0; i < *pPhysicalDeviceCount; i++) |
| 1549 | SetData(pPhysicalDevices[i], data); |
| 1550 | } |
| 1551 | |
| 1552 | return result; |
| 1553 | } |
| 1554 | |
Daniel Koch | f25f5bb | 2017-10-05 00:26:58 -0400 | [diff] [blame] | 1555 | VkResult EnumeratePhysicalDeviceGroups( |
| 1556 | VkInstance instance, |
| 1557 | uint32_t* pPhysicalDeviceGroupCount, |
| 1558 | VkPhysicalDeviceGroupProperties* pPhysicalDeviceGroupProperties) { |
Yiwei Zhang | fdd0c2a | 2019-01-30 20:16:37 -0800 | [diff] [blame] | 1559 | ATRACE_CALL(); |
| 1560 | |
Yiwei Zhang | 4cd9cc9 | 2018-01-08 17:55:50 -0800 | [diff] [blame] | 1561 | VkResult result = VK_SUCCESS; |
Daniel Koch | f25f5bb | 2017-10-05 00:26:58 -0400 | [diff] [blame] | 1562 | const auto& data = GetData(instance); |
| 1563 | |
Yiwei Zhang | e4f6417 | 2020-07-05 15:17:32 -0700 | [diff] [blame] | 1564 | if (!data.driver.EnumeratePhysicalDeviceGroups && |
| 1565 | !data.driver.EnumeratePhysicalDeviceGroupsKHR) { |
Yiwei Zhang | 4cd9cc9 | 2018-01-08 17:55:50 -0800 | [diff] [blame] | 1566 | uint32_t device_count = 0; |
| 1567 | result = EnumeratePhysicalDevices(instance, &device_count, nullptr); |
| 1568 | if (result < 0) |
| 1569 | return result; |
Chad Versace | 32c087f | 2018-09-09 07:28:05 -0700 | [diff] [blame] | 1570 | |
Yiwei Zhang | 4cd9cc9 | 2018-01-08 17:55:50 -0800 | [diff] [blame] | 1571 | if (!pPhysicalDeviceGroupProperties) { |
| 1572 | *pPhysicalDeviceGroupCount = device_count; |
| 1573 | return result; |
| 1574 | } |
| 1575 | |
Yiwei Zhang | 4cd9cc9 | 2018-01-08 17:55:50 -0800 | [diff] [blame] | 1576 | if (!device_count) { |
| 1577 | *pPhysicalDeviceGroupCount = 0; |
| 1578 | return result; |
| 1579 | } |
Chad Versace | 32c087f | 2018-09-09 07:28:05 -0700 | [diff] [blame] | 1580 | device_count = std::min(device_count, *pPhysicalDeviceGroupCount); |
| 1581 | if (!device_count) |
| 1582 | return VK_INCOMPLETE; |
Yiwei Zhang | 4cd9cc9 | 2018-01-08 17:55:50 -0800 | [diff] [blame] | 1583 | |
Yiwei Zhang | 5e86220 | 2019-06-21 14:59:16 -0700 | [diff] [blame] | 1584 | std::vector<VkPhysicalDevice> devices(device_count); |
Chad Versace | 32c087f | 2018-09-09 07:28:05 -0700 | [diff] [blame] | 1585 | *pPhysicalDeviceGroupCount = device_count; |
Yiwei Zhang | 5e86220 | 2019-06-21 14:59:16 -0700 | [diff] [blame] | 1586 | result = |
| 1587 | EnumeratePhysicalDevices(instance, &device_count, devices.data()); |
Yiwei Zhang | 4cd9cc9 | 2018-01-08 17:55:50 -0800 | [diff] [blame] | 1588 | if (result < 0) |
| 1589 | return result; |
| 1590 | |
Yiwei Zhang | 4cd9cc9 | 2018-01-08 17:55:50 -0800 | [diff] [blame] | 1591 | for (uint32_t i = 0; i < device_count; ++i) { |
| 1592 | pPhysicalDeviceGroupProperties[i].physicalDeviceCount = 1; |
| 1593 | pPhysicalDeviceGroupProperties[i].physicalDevices[0] = devices[i]; |
| 1594 | pPhysicalDeviceGroupProperties[i].subsetAllocation = 0; |
| 1595 | } |
| 1596 | } else { |
Yiwei Zhang | e4f6417 | 2020-07-05 15:17:32 -0700 | [diff] [blame] | 1597 | if (data.driver.EnumeratePhysicalDeviceGroups) { |
| 1598 | result = data.driver.EnumeratePhysicalDeviceGroups( |
| 1599 | instance, pPhysicalDeviceGroupCount, |
| 1600 | pPhysicalDeviceGroupProperties); |
| 1601 | } else { |
| 1602 | result = data.driver.EnumeratePhysicalDeviceGroupsKHR( |
| 1603 | instance, pPhysicalDeviceGroupCount, |
| 1604 | pPhysicalDeviceGroupProperties); |
| 1605 | } |
Yiwei Zhang | 4cd9cc9 | 2018-01-08 17:55:50 -0800 | [diff] [blame] | 1606 | if ((result == VK_SUCCESS || result == VK_INCOMPLETE) && |
| 1607 | *pPhysicalDeviceGroupCount && pPhysicalDeviceGroupProperties) { |
| 1608 | for (uint32_t i = 0; i < *pPhysicalDeviceGroupCount; i++) { |
| 1609 | for (uint32_t j = 0; |
| 1610 | j < pPhysicalDeviceGroupProperties[i].physicalDeviceCount; |
| 1611 | j++) { |
| 1612 | SetData( |
| 1613 | pPhysicalDeviceGroupProperties[i].physicalDevices[j], |
Ian Elliott | cd8ad33 | 2017-10-13 09:21:12 -0600 | [diff] [blame] | 1614 | data); |
Yiwei Zhang | 4cd9cc9 | 2018-01-08 17:55:50 -0800 | [diff] [blame] | 1615 | } |
Ian Elliott | cd8ad33 | 2017-10-13 09:21:12 -0600 | [diff] [blame] | 1616 | } |
| 1617 | } |
Daniel Koch | f25f5bb | 2017-10-05 00:26:58 -0400 | [diff] [blame] | 1618 | } |
| 1619 | |
| 1620 | return result; |
| 1621 | } |
| 1622 | |
Chia-I Wu | ba0be41 | 2016-03-24 16:24:40 +0800 | [diff] [blame] | 1623 | void GetDeviceQueue(VkDevice device, |
| 1624 | uint32_t queueFamilyIndex, |
| 1625 | uint32_t queueIndex, |
| 1626 | VkQueue* pQueue) { |
Yiwei Zhang | fdd0c2a | 2019-01-30 20:16:37 -0800 | [diff] [blame] | 1627 | ATRACE_CALL(); |
| 1628 | |
Chia-I Wu | ba0be41 | 2016-03-24 16:24:40 +0800 | [diff] [blame] | 1629 | const auto& data = GetData(device); |
| 1630 | |
| 1631 | data.driver.GetDeviceQueue(device, queueFamilyIndex, queueIndex, pQueue); |
| 1632 | SetData(*pQueue, data); |
| 1633 | } |
| 1634 | |
Daniel Koch | f25f5bb | 2017-10-05 00:26:58 -0400 | [diff] [blame] | 1635 | void GetDeviceQueue2(VkDevice device, |
| 1636 | const VkDeviceQueueInfo2* pQueueInfo, |
| 1637 | VkQueue* pQueue) { |
Yiwei Zhang | fdd0c2a | 2019-01-30 20:16:37 -0800 | [diff] [blame] | 1638 | ATRACE_CALL(); |
| 1639 | |
Daniel Koch | f25f5bb | 2017-10-05 00:26:58 -0400 | [diff] [blame] | 1640 | const auto& data = GetData(device); |
| 1641 | |
| 1642 | data.driver.GetDeviceQueue2(device, pQueueInfo, pQueue); |
Yiwei Zhang | f5b9f73 | 2018-02-07 14:06:09 -0800 | [diff] [blame] | 1643 | if (*pQueue != VK_NULL_HANDLE) SetData(*pQueue, data); |
Daniel Koch | f25f5bb | 2017-10-05 00:26:58 -0400 | [diff] [blame] | 1644 | } |
| 1645 | |
Yiwei Zhang | 93b521c | 2020-07-11 16:32:09 -0700 | [diff] [blame] | 1646 | VkResult AllocateCommandBuffers( |
| 1647 | VkDevice device, |
| 1648 | const VkCommandBufferAllocateInfo* pAllocateInfo, |
| 1649 | VkCommandBuffer* pCommandBuffers) { |
Yiwei Zhang | fdd0c2a | 2019-01-30 20:16:37 -0800 | [diff] [blame] | 1650 | ATRACE_CALL(); |
| 1651 | |
Chia-I Wu | 6a58a8a | 2016-03-24 16:29:51 +0800 | [diff] [blame] | 1652 | const auto& data = GetData(device); |
| 1653 | |
| 1654 | VkResult result = data.driver.AllocateCommandBuffers(device, pAllocateInfo, |
| 1655 | pCommandBuffers); |
| 1656 | if (result == VK_SUCCESS) { |
| 1657 | for (uint32_t i = 0; i < pAllocateInfo->commandBufferCount; i++) |
| 1658 | SetData(pCommandBuffers[i], data); |
| 1659 | } |
| 1660 | |
| 1661 | return result; |
| 1662 | } |
| 1663 | |
Yiwei Zhang | 93b521c | 2020-07-11 16:32:09 -0700 | [diff] [blame] | 1664 | VkResult QueueSubmit(VkQueue queue, |
| 1665 | uint32_t submitCount, |
| 1666 | const VkSubmitInfo* pSubmits, |
| 1667 | VkFence fence) { |
Yiwei Zhang | 899d175 | 2019-09-23 16:05:35 -0700 | [diff] [blame] | 1668 | ATRACE_CALL(); |
| 1669 | |
| 1670 | const auto& data = GetData(queue); |
| 1671 | |
| 1672 | return data.driver.QueueSubmit(queue, submitCount, pSubmits, fence); |
| 1673 | } |
| 1674 | |
Yiwei Zhang | a55624b | 2020-07-05 16:05:26 -0700 | [diff] [blame] | 1675 | void GetPhysicalDeviceFeatures2(VkPhysicalDevice physicalDevice, |
| 1676 | VkPhysicalDeviceFeatures2* pFeatures) { |
| 1677 | ATRACE_CALL(); |
| 1678 | |
| 1679 | const auto& driver = GetData(physicalDevice).driver; |
| 1680 | |
| 1681 | if (driver.GetPhysicalDeviceFeatures2) { |
| 1682 | driver.GetPhysicalDeviceFeatures2(physicalDevice, pFeatures); |
Trevor David Black | 2cc4468 | 2022-03-09 00:31:38 +0000 | [diff] [blame] | 1683 | } else { |
| 1684 | driver.GetPhysicalDeviceFeatures2KHR(physicalDevice, pFeatures); |
| 1685 | } |
| 1686 | |
| 1687 | // Conditionally add imageCompressionControlSwapchain if |
| 1688 | // imageCompressionControl is supported Check for imageCompressionControl in |
| 1689 | // the pChain |
| 1690 | bool imageCompressionControl = false; |
| 1691 | bool imageCompressionControlInChain = false; |
| 1692 | bool imageCompressionControlSwapchainInChain = false; |
| 1693 | VkPhysicalDeviceFeatures2* pFeats = pFeatures; |
| 1694 | while (pFeats) { |
| 1695 | switch (pFeats->sType) { |
| 1696 | case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_COMPRESSION_CONTROL_FEATURES_EXT: { |
| 1697 | const VkPhysicalDeviceImageCompressionControlFeaturesEXT* |
| 1698 | compressionFeat = reinterpret_cast< |
| 1699 | const VkPhysicalDeviceImageCompressionControlFeaturesEXT*>( |
| 1700 | pFeats); |
| 1701 | imageCompressionControl = |
| 1702 | compressionFeat->imageCompressionControl; |
| 1703 | imageCompressionControlInChain = true; |
| 1704 | } break; |
| 1705 | |
| 1706 | case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_COMPRESSION_CONTROL_SWAPCHAIN_FEATURES_EXT: { |
Trevor David Black | 929e9cd | 2022-11-22 04:12:19 +0000 | [diff] [blame] | 1707 | VkPhysicalDeviceImageCompressionControlSwapchainFeaturesEXT* |
| 1708 | compressionFeat = reinterpret_cast< |
| 1709 | VkPhysicalDeviceImageCompressionControlSwapchainFeaturesEXT*>( |
| 1710 | pFeats); |
| 1711 | compressionFeat->imageCompressionControlSwapchain = false; |
Trevor David Black | 2cc4468 | 2022-03-09 00:31:38 +0000 | [diff] [blame] | 1712 | imageCompressionControlSwapchainInChain = true; |
| 1713 | } break; |
| 1714 | |
Chris Forbes | 9d0d9ff | 2022-12-28 01:58:31 +0000 | [diff] [blame] | 1715 | case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SWAPCHAIN_MAINTENANCE_1_FEATURES_EXT: { |
| 1716 | auto smf = reinterpret_cast<VkPhysicalDeviceSwapchainMaintenance1FeaturesEXT *>( |
| 1717 | pFeats); |
| 1718 | smf->swapchainMaintenance1 = true; |
| 1719 | } break; |
| 1720 | |
Trevor David Black | 2cc4468 | 2022-03-09 00:31:38 +0000 | [diff] [blame] | 1721 | default: |
| 1722 | break; |
| 1723 | } |
| 1724 | pFeats = reinterpret_cast<VkPhysicalDeviceFeatures2*>(pFeats->pNext); |
| 1725 | } |
| 1726 | |
| 1727 | if (!imageCompressionControlSwapchainInChain) { |
Yiwei Zhang | a55624b | 2020-07-05 16:05:26 -0700 | [diff] [blame] | 1728 | return; |
| 1729 | } |
| 1730 | |
Trevor David Black | 2cc4468 | 2022-03-09 00:31:38 +0000 | [diff] [blame] | 1731 | // If not in pchain, explicitly query for imageCompressionControl |
| 1732 | if (!imageCompressionControlInChain) { |
| 1733 | VkPhysicalDeviceImageCompressionControlFeaturesEXT imageCompFeats = {}; |
| 1734 | imageCompFeats.sType = |
| 1735 | VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_COMPRESSION_CONTROL_FEATURES_EXT; |
| 1736 | imageCompFeats.pNext = nullptr; |
Trevor David Black | 929e9cd | 2022-11-22 04:12:19 +0000 | [diff] [blame] | 1737 | imageCompFeats.imageCompressionControl = false; |
Trevor David Black | 2cc4468 | 2022-03-09 00:31:38 +0000 | [diff] [blame] | 1738 | |
| 1739 | VkPhysicalDeviceFeatures2 feats2 = {}; |
| 1740 | feats2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2; |
| 1741 | feats2.pNext = &imageCompFeats; |
| 1742 | |
| 1743 | if (driver.GetPhysicalDeviceFeatures2) { |
| 1744 | driver.GetPhysicalDeviceFeatures2(physicalDevice, &feats2); |
| 1745 | } else { |
| 1746 | driver.GetPhysicalDeviceFeatures2KHR(physicalDevice, &feats2); |
| 1747 | } |
| 1748 | |
| 1749 | imageCompressionControl = imageCompFeats.imageCompressionControl; |
| 1750 | } |
| 1751 | |
| 1752 | // Only enumerate imageCompressionControlSwapchin if imageCompressionControl |
| 1753 | if (imageCompressionControl) { |
| 1754 | pFeats = pFeatures; |
| 1755 | while (pFeats) { |
| 1756 | switch (pFeats->sType) { |
| 1757 | case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_COMPRESSION_CONTROL_SWAPCHAIN_FEATURES_EXT: { |
| 1758 | VkPhysicalDeviceImageCompressionControlSwapchainFeaturesEXT* |
| 1759 | compressionFeat = reinterpret_cast< |
| 1760 | VkPhysicalDeviceImageCompressionControlSwapchainFeaturesEXT*>( |
| 1761 | pFeats); |
| 1762 | compressionFeat->imageCompressionControlSwapchain = true; |
| 1763 | } break; |
| 1764 | |
| 1765 | default: |
| 1766 | break; |
| 1767 | } |
| 1768 | pFeats = |
| 1769 | reinterpret_cast<VkPhysicalDeviceFeatures2*>(pFeats->pNext); |
| 1770 | } |
| 1771 | } |
Yiwei Zhang | a55624b | 2020-07-05 16:05:26 -0700 | [diff] [blame] | 1772 | } |
| 1773 | |
| 1774 | void GetPhysicalDeviceProperties2(VkPhysicalDevice physicalDevice, |
| 1775 | VkPhysicalDeviceProperties2* pProperties) { |
| 1776 | ATRACE_CALL(); |
| 1777 | |
| 1778 | const auto& driver = GetData(physicalDevice).driver; |
| 1779 | |
| 1780 | if (driver.GetPhysicalDeviceProperties2) { |
| 1781 | driver.GetPhysicalDeviceProperties2(physicalDevice, pProperties); |
| 1782 | return; |
| 1783 | } |
| 1784 | |
| 1785 | driver.GetPhysicalDeviceProperties2KHR(physicalDevice, pProperties); |
| 1786 | } |
| 1787 | |
| 1788 | void GetPhysicalDeviceFormatProperties2( |
| 1789 | VkPhysicalDevice physicalDevice, |
| 1790 | VkFormat format, |
| 1791 | VkFormatProperties2* pFormatProperties) { |
| 1792 | ATRACE_CALL(); |
| 1793 | |
| 1794 | const auto& driver = GetData(physicalDevice).driver; |
| 1795 | |
| 1796 | if (driver.GetPhysicalDeviceFormatProperties2) { |
| 1797 | driver.GetPhysicalDeviceFormatProperties2(physicalDevice, format, |
| 1798 | pFormatProperties); |
| 1799 | return; |
| 1800 | } |
| 1801 | |
| 1802 | driver.GetPhysicalDeviceFormatProperties2KHR(physicalDevice, format, |
| 1803 | pFormatProperties); |
| 1804 | } |
| 1805 | |
| 1806 | VkResult GetPhysicalDeviceImageFormatProperties2( |
| 1807 | VkPhysicalDevice physicalDevice, |
| 1808 | const VkPhysicalDeviceImageFormatInfo2* pImageFormatInfo, |
| 1809 | VkImageFormatProperties2* pImageFormatProperties) { |
| 1810 | ATRACE_CALL(); |
| 1811 | |
| 1812 | const auto& driver = GetData(physicalDevice).driver; |
| 1813 | |
| 1814 | if (driver.GetPhysicalDeviceImageFormatProperties2) { |
| 1815 | return driver.GetPhysicalDeviceImageFormatProperties2( |
| 1816 | physicalDevice, pImageFormatInfo, pImageFormatProperties); |
| 1817 | } |
| 1818 | |
| 1819 | return driver.GetPhysicalDeviceImageFormatProperties2KHR( |
| 1820 | physicalDevice, pImageFormatInfo, pImageFormatProperties); |
| 1821 | } |
| 1822 | |
| 1823 | void GetPhysicalDeviceQueueFamilyProperties2( |
| 1824 | VkPhysicalDevice physicalDevice, |
| 1825 | uint32_t* pQueueFamilyPropertyCount, |
| 1826 | VkQueueFamilyProperties2* pQueueFamilyProperties) { |
| 1827 | ATRACE_CALL(); |
| 1828 | |
| 1829 | const auto& driver = GetData(physicalDevice).driver; |
| 1830 | |
| 1831 | if (driver.GetPhysicalDeviceQueueFamilyProperties2) { |
| 1832 | driver.GetPhysicalDeviceQueueFamilyProperties2( |
| 1833 | physicalDevice, pQueueFamilyPropertyCount, pQueueFamilyProperties); |
| 1834 | return; |
| 1835 | } |
| 1836 | |
| 1837 | driver.GetPhysicalDeviceQueueFamilyProperties2KHR( |
| 1838 | physicalDevice, pQueueFamilyPropertyCount, pQueueFamilyProperties); |
| 1839 | } |
| 1840 | |
| 1841 | void GetPhysicalDeviceMemoryProperties2( |
| 1842 | VkPhysicalDevice physicalDevice, |
| 1843 | VkPhysicalDeviceMemoryProperties2* pMemoryProperties) { |
| 1844 | ATRACE_CALL(); |
| 1845 | |
| 1846 | const auto& driver = GetData(physicalDevice).driver; |
| 1847 | |
| 1848 | if (driver.GetPhysicalDeviceMemoryProperties2) { |
| 1849 | driver.GetPhysicalDeviceMemoryProperties2(physicalDevice, |
| 1850 | pMemoryProperties); |
| 1851 | return; |
| 1852 | } |
| 1853 | |
| 1854 | driver.GetPhysicalDeviceMemoryProperties2KHR(physicalDevice, |
| 1855 | pMemoryProperties); |
| 1856 | } |
| 1857 | |
| 1858 | void GetPhysicalDeviceSparseImageFormatProperties2( |
| 1859 | VkPhysicalDevice physicalDevice, |
| 1860 | const VkPhysicalDeviceSparseImageFormatInfo2* pFormatInfo, |
| 1861 | uint32_t* pPropertyCount, |
| 1862 | VkSparseImageFormatProperties2* pProperties) { |
| 1863 | ATRACE_CALL(); |
| 1864 | |
| 1865 | const auto& driver = GetData(physicalDevice).driver; |
| 1866 | |
| 1867 | if (driver.GetPhysicalDeviceSparseImageFormatProperties2) { |
| 1868 | driver.GetPhysicalDeviceSparseImageFormatProperties2( |
| 1869 | physicalDevice, pFormatInfo, pPropertyCount, pProperties); |
| 1870 | return; |
| 1871 | } |
| 1872 | |
| 1873 | driver.GetPhysicalDeviceSparseImageFormatProperties2KHR( |
| 1874 | physicalDevice, pFormatInfo, pPropertyCount, pProperties); |
| 1875 | } |
| 1876 | |
Yiwei Zhang | e1f3501 | 2020-07-05 22:52:04 -0700 | [diff] [blame] | 1877 | void GetPhysicalDeviceExternalBufferProperties( |
| 1878 | VkPhysicalDevice physicalDevice, |
| 1879 | const VkPhysicalDeviceExternalBufferInfo* pExternalBufferInfo, |
| 1880 | VkExternalBufferProperties* pExternalBufferProperties) { |
| 1881 | ATRACE_CALL(); |
| 1882 | |
| 1883 | const auto& driver = GetData(physicalDevice).driver; |
| 1884 | |
| 1885 | if (driver.GetPhysicalDeviceExternalBufferProperties) { |
| 1886 | driver.GetPhysicalDeviceExternalBufferProperties( |
| 1887 | physicalDevice, pExternalBufferInfo, pExternalBufferProperties); |
| 1888 | return; |
| 1889 | } |
| 1890 | |
| 1891 | if (driver.GetPhysicalDeviceExternalBufferPropertiesKHR) { |
| 1892 | driver.GetPhysicalDeviceExternalBufferPropertiesKHR( |
| 1893 | physicalDevice, pExternalBufferInfo, pExternalBufferProperties); |
| 1894 | return; |
| 1895 | } |
| 1896 | |
| 1897 | memset(&pExternalBufferProperties->externalMemoryProperties, 0, |
| 1898 | sizeof(VkExternalMemoryProperties)); |
| 1899 | } |
| 1900 | |
| 1901 | void GetPhysicalDeviceExternalSemaphoreProperties( |
| 1902 | VkPhysicalDevice physicalDevice, |
| 1903 | const VkPhysicalDeviceExternalSemaphoreInfo* pExternalSemaphoreInfo, |
| 1904 | VkExternalSemaphoreProperties* pExternalSemaphoreProperties) { |
| 1905 | ATRACE_CALL(); |
| 1906 | |
| 1907 | const auto& driver = GetData(physicalDevice).driver; |
| 1908 | |
| 1909 | if (driver.GetPhysicalDeviceExternalSemaphoreProperties) { |
| 1910 | driver.GetPhysicalDeviceExternalSemaphoreProperties( |
| 1911 | physicalDevice, pExternalSemaphoreInfo, |
| 1912 | pExternalSemaphoreProperties); |
| 1913 | return; |
| 1914 | } |
| 1915 | |
| 1916 | if (driver.GetPhysicalDeviceExternalSemaphorePropertiesKHR) { |
| 1917 | driver.GetPhysicalDeviceExternalSemaphorePropertiesKHR( |
| 1918 | physicalDevice, pExternalSemaphoreInfo, |
| 1919 | pExternalSemaphoreProperties); |
| 1920 | return; |
| 1921 | } |
| 1922 | |
| 1923 | pExternalSemaphoreProperties->exportFromImportedHandleTypes = 0; |
| 1924 | pExternalSemaphoreProperties->compatibleHandleTypes = 0; |
| 1925 | pExternalSemaphoreProperties->externalSemaphoreFeatures = 0; |
| 1926 | } |
| 1927 | |
| 1928 | void GetPhysicalDeviceExternalFenceProperties( |
| 1929 | VkPhysicalDevice physicalDevice, |
| 1930 | const VkPhysicalDeviceExternalFenceInfo* pExternalFenceInfo, |
| 1931 | VkExternalFenceProperties* pExternalFenceProperties) { |
| 1932 | ATRACE_CALL(); |
| 1933 | |
| 1934 | const auto& driver = GetData(physicalDevice).driver; |
| 1935 | |
| 1936 | if (driver.GetPhysicalDeviceExternalFenceProperties) { |
| 1937 | driver.GetPhysicalDeviceExternalFenceProperties( |
| 1938 | physicalDevice, pExternalFenceInfo, pExternalFenceProperties); |
| 1939 | return; |
| 1940 | } |
| 1941 | |
| 1942 | if (driver.GetPhysicalDeviceExternalFencePropertiesKHR) { |
| 1943 | driver.GetPhysicalDeviceExternalFencePropertiesKHR( |
| 1944 | physicalDevice, pExternalFenceInfo, pExternalFenceProperties); |
| 1945 | return; |
| 1946 | } |
| 1947 | |
| 1948 | pExternalFenceProperties->exportFromImportedHandleTypes = 0; |
| 1949 | pExternalFenceProperties->compatibleHandleTypes = 0; |
| 1950 | pExternalFenceProperties->externalFenceFeatures = 0; |
| 1951 | } |
| 1952 | |
Chia-I Wu | 9d51816 | 2016-03-24 14:55:27 +0800 | [diff] [blame] | 1953 | } // namespace driver |
| 1954 | } // namespace vulkan |