Jesse Hall | 80523e2 | 2016-01-06 16:47:54 -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 | |
Chia-I Wu | c96880f | 2016-03-26 06:56:45 +0800 | [diff] [blame] | 19 | #include "layers_extensions.h" |
Jesse Hall | 1a7eb59 | 2016-05-01 21:04:40 +0200 | [diff] [blame] | 20 | |
Jesse Hall | 80523e2 | 2016-01-06 16:47:54 -0800 | [diff] [blame] | 21 | #include <alloca.h> |
| 22 | #include <dirent.h> |
| 23 | #include <dlfcn.h> |
Jesse Hall | 80523e2 | 2016-01-06 16:47:54 -0800 | [diff] [blame] | 24 | #include <string.h> |
Mark Salyzyn | a5e161b | 2016-09-29 08:08:05 -0700 | [diff] [blame] | 25 | #include <sys/prctl.h> |
| 26 | |
| 27 | #include <mutex> |
| 28 | #include <string> |
Jesse Hall | 80523e2 | 2016-01-06 16:47:54 -0800 | [diff] [blame] | 29 | #include <vector> |
Jesse Hall | 1a7eb59 | 2016-05-01 21:04:40 +0200 | [diff] [blame] | 30 | |
Jesse Hall | 40c07a1 | 2016-05-11 22:56:29 -0700 | [diff] [blame] | 31 | #include <android/dlext.h> |
Mark Salyzyn | a5e161b | 2016-09-29 08:08:05 -0700 | [diff] [blame] | 32 | #include <android-base/strings.h> |
Jesse Hall | 1a7eb59 | 2016-05-01 21:04:40 +0200 | [diff] [blame] | 33 | #include <cutils/properties.h> |
Cody Northrop | d2aa3ab | 2017-10-20 09:01:53 -0600 | [diff] [blame] | 34 | #include <graphicsenv/GraphicsEnv.h> |
Mark Salyzyn | 7823e12 | 2016-09-29 08:08:05 -0700 | [diff] [blame] | 35 | #include <log/log.h> |
Victor Khimenko | bbf7700 | 2018-08-16 22:38:36 +0200 | [diff] [blame] | 36 | #include <nativebridge/native_bridge.h> |
| 37 | #include <nativeloader/native_loader.h> |
Yiwei Zhang | fdd0c2a | 2019-01-30 20:16:37 -0800 | [diff] [blame] | 38 | #include <utils/Trace.h> |
Jesse Hall | 1a7eb59 | 2016-05-01 21:04:40 +0200 | [diff] [blame] | 39 | #include <ziparchive/zip_archive.h> |
| 40 | |
Yiwei Zhang | a885c06 | 2019-10-24 12:07:57 -0700 | [diff] [blame] | 41 | // TODO(b/143296676): This file currently builds up global data structures as it |
Jesse Hall | aa41094 | 2016-01-17 13:07:10 -0800 | [diff] [blame] | 42 | // loads, and never cleans them up. This means we're doing heap allocations |
| 43 | // without going through an app-provided allocator, but worse, we'll leak those |
| 44 | // allocations if the loader is unloaded. |
| 45 | // |
| 46 | // We should allocate "enough" BSS space, and suballocate from there. Will |
| 47 | // probably want to intern strings, etc., and will need some custom/manual data |
| 48 | // structures. |
| 49 | |
Jesse Hall | 80523e2 | 2016-01-06 16:47:54 -0800 | [diff] [blame] | 50 | namespace vulkan { |
Chia-I Wu | c96880f | 2016-03-26 06:56:45 +0800 | [diff] [blame] | 51 | namespace api { |
| 52 | |
Jesse Hall | 80523e2 | 2016-01-06 16:47:54 -0800 | [diff] [blame] | 53 | struct Layer { |
| 54 | VkLayerProperties properties; |
| 55 | size_t library_idx; |
Chia-I Wu | bea09db | 2016-04-22 09:42:41 +0800 | [diff] [blame] | 56 | |
Chia-I Wu | 25700b4 | 2016-04-28 06:36:09 +0800 | [diff] [blame] | 57 | // true if the layer intercepts vkCreateDevice and device commands |
Chia-I Wu | bea09db | 2016-04-22 09:42:41 +0800 | [diff] [blame] | 58 | bool is_global; |
| 59 | |
| 60 | std::vector<VkExtensionProperties> instance_extensions; |
| 61 | std::vector<VkExtensionProperties> device_extensions; |
Jesse Hall | 80523e2 | 2016-01-06 16:47:54 -0800 | [diff] [blame] | 62 | }; |
Jesse Hall | 80523e2 | 2016-01-06 16:47:54 -0800 | [diff] [blame] | 63 | |
| 64 | namespace { |
| 65 | |
Jesse Hall | 1a7eb59 | 2016-05-01 21:04:40 +0200 | [diff] [blame] | 66 | const char kSystemLayerLibraryDir[] = "/data/local/debug/vulkan"; |
| 67 | |
Chia-I Wu | 6693f5c | 2016-04-18 12:20:02 +0800 | [diff] [blame] | 68 | class LayerLibrary { |
| 69 | public: |
Cody Northrop | d2aa3ab | 2017-10-20 09:01:53 -0600 | [diff] [blame] | 70 | explicit LayerLibrary(const std::string& path, |
| 71 | const std::string& filename) |
| 72 | : path_(path), |
| 73 | filename_(filename), |
| 74 | dlhandle_(nullptr), |
Victor Khimenko | bbf7700 | 2018-08-16 22:38:36 +0200 | [diff] [blame] | 75 | native_bridge_(false), |
Cody Northrop | d2aa3ab | 2017-10-20 09:01:53 -0600 | [diff] [blame] | 76 | refcount_(0) {} |
Chia-I Wu | 7434959 | 2016-04-18 12:08:39 +0800 | [diff] [blame] | 77 | |
Chih-Hung Hsieh | 5bc849f | 2018-09-25 14:21:50 -0700 | [diff] [blame] | 78 | LayerLibrary(LayerLibrary&& other) noexcept |
Chia-I Wu | 6693f5c | 2016-04-18 12:20:02 +0800 | [diff] [blame] | 79 | : path_(std::move(other.path_)), |
Cody Northrop | d2aa3ab | 2017-10-20 09:01:53 -0600 | [diff] [blame] | 80 | filename_(std::move(other.filename_)), |
Chia-I Wu | 6693f5c | 2016-04-18 12:20:02 +0800 | [diff] [blame] | 81 | dlhandle_(other.dlhandle_), |
Victor Khimenko | bbf7700 | 2018-08-16 22:38:36 +0200 | [diff] [blame] | 82 | native_bridge_(other.native_bridge_), |
Chia-I Wu | 6693f5c | 2016-04-18 12:20:02 +0800 | [diff] [blame] | 83 | refcount_(other.refcount_) { |
| 84 | other.dlhandle_ = nullptr; |
| 85 | other.refcount_ = 0; |
Chia-I Wu | 50174ee | 2016-04-18 16:33:20 +0800 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | LayerLibrary(const LayerLibrary&) = delete; |
| 89 | LayerLibrary& operator=(const LayerLibrary&) = delete; |
| 90 | |
Chia-I Wu | a622974 | 2016-04-26 07:37:44 +0800 | [diff] [blame] | 91 | // these are thread-safe |
Chia-I Wu | fd0389f | 2016-04-18 12:11:00 +0800 | [diff] [blame] | 92 | bool Open(); |
Chia-I Wu | d91c74f | 2016-04-18 12:12:36 +0800 | [diff] [blame] | 93 | void Close(); |
Chia-I Wu | fd0389f | 2016-04-18 12:11:00 +0800 | [diff] [blame] | 94 | |
Chia-I Wu | 50174ee | 2016-04-18 16:33:20 +0800 | [diff] [blame] | 95 | bool EnumerateLayers(size_t library_idx, |
Chia-I Wu | bea09db | 2016-04-22 09:42:41 +0800 | [diff] [blame] | 96 | std::vector<Layer>& instance_layers) const; |
Chia-I Wu | 50174ee | 2016-04-18 16:33:20 +0800 | [diff] [blame] | 97 | |
Nick Desaulniers | 60307ce | 2019-10-25 13:34:21 -0700 | [diff] [blame] | 98 | void* GetGPA(const Layer& layer, const std::string_view gpa_name) const; |
Chia-I Wu | ba11327 | 2016-04-18 16:38:39 +0800 | [diff] [blame] | 99 | |
Cody Northrop | d2aa3ab | 2017-10-20 09:01:53 -0600 | [diff] [blame] | 100 | const std::string GetFilename() { return filename_; } |
| 101 | |
Chia-I Wu | 6693f5c | 2016-04-18 12:20:02 +0800 | [diff] [blame] | 102 | private: |
Victor Khimenko | bbf7700 | 2018-08-16 22:38:36 +0200 | [diff] [blame] | 103 | // TODO(b/79940628): remove that adapter when we could use NativeBridgeGetTrampoline |
| 104 | // for native libraries. |
| 105 | template<typename Func = void*> |
| 106 | Func GetTrampoline(const char* name) const { |
| 107 | if (native_bridge_) { |
| 108 | return reinterpret_cast<Func>(android::NativeBridgeGetTrampoline( |
| 109 | dlhandle_, name, nullptr, 0)); |
| 110 | } |
| 111 | return reinterpret_cast<Func>(dlsym(dlhandle_, name)); |
| 112 | } |
| 113 | |
Chia-I Wu | 6693f5c | 2016-04-18 12:20:02 +0800 | [diff] [blame] | 114 | const std::string path_; |
Chia-I Wu | a622974 | 2016-04-26 07:37:44 +0800 | [diff] [blame] | 115 | |
Cody Northrop | d2aa3ab | 2017-10-20 09:01:53 -0600 | [diff] [blame] | 116 | // Track the filename alone so we can detect duplicates |
| 117 | const std::string filename_; |
| 118 | |
Chia-I Wu | a622974 | 2016-04-26 07:37:44 +0800 | [diff] [blame] | 119 | std::mutex mutex_; |
Chia-I Wu | 6693f5c | 2016-04-18 12:20:02 +0800 | [diff] [blame] | 120 | void* dlhandle_; |
Victor Khimenko | bbf7700 | 2018-08-16 22:38:36 +0200 | [diff] [blame] | 121 | bool native_bridge_; |
Chia-I Wu | 6693f5c | 2016-04-18 12:20:02 +0800 | [diff] [blame] | 122 | size_t refcount_; |
Jesse Hall | 80523e2 | 2016-01-06 16:47:54 -0800 | [diff] [blame] | 123 | }; |
Chia-I Wu | 7434959 | 2016-04-18 12:08:39 +0800 | [diff] [blame] | 124 | |
Chia-I Wu | fd0389f | 2016-04-18 12:11:00 +0800 | [diff] [blame] | 125 | bool LayerLibrary::Open() { |
Chia-I Wu | a622974 | 2016-04-26 07:37:44 +0800 | [diff] [blame] | 126 | std::lock_guard<std::mutex> lock(mutex_); |
Chia-I Wu | 6693f5c | 2016-04-18 12:20:02 +0800 | [diff] [blame] | 127 | if (refcount_++ == 0) { |
Jesse Hall | 1a7eb59 | 2016-05-01 21:04:40 +0200 | [diff] [blame] | 128 | ALOGV("opening layer library '%s'", path_.c_str()); |
Jesse Hall | 40c07a1 | 2016-05-11 22:56:29 -0700 | [diff] [blame] | 129 | // Libraries in the system layer library dir can't be loaded into |
| 130 | // the application namespace. That causes compatibility problems, since |
| 131 | // any symbol dependencies will be resolved by system libraries. They |
| 132 | // can't safely use libc++_shared, for example. Which is one reason |
| 133 | // (among several) we only allow them in non-user builds. |
Cody Northrop | d2aa3ab | 2017-10-20 09:01:53 -0600 | [diff] [blame] | 134 | auto app_namespace = android::GraphicsEnv::getInstance().getAppNamespace(); |
Jesse Hall | 40c07a1 | 2016-05-11 22:56:29 -0700 | [diff] [blame] | 135 | if (app_namespace && |
| 136 | !android::base::StartsWith(path_, kSystemLayerLibraryDir)) { |
Nicolas Geoffray | a655dac | 2019-01-11 15:59:42 +0000 | [diff] [blame] | 137 | char* error_msg = nullptr; |
| 138 | dlhandle_ = OpenNativeLibraryInNamespace( |
Victor Khimenko | bbf7700 | 2018-08-16 22:38:36 +0200 | [diff] [blame] | 139 | app_namespace, path_.c_str(), &native_bridge_, &error_msg); |
| 140 | if (!dlhandle_) { |
Nicolas Geoffray | a655dac | 2019-01-11 15:59:42 +0000 | [diff] [blame] | 141 | ALOGE("failed to load layer library '%s': %s", path_.c_str(), error_msg); |
| 142 | android::NativeLoaderFreeErrorMessage(error_msg); |
Victor Khimenko | bbf7700 | 2018-08-16 22:38:36 +0200 | [diff] [blame] | 143 | refcount_ = 0; |
| 144 | return false; |
| 145 | } |
Jesse Hall | 40c07a1 | 2016-05-11 22:56:29 -0700 | [diff] [blame] | 146 | } else { |
Victor Khimenko | bbf7700 | 2018-08-16 22:38:36 +0200 | [diff] [blame] | 147 | dlhandle_ = dlopen(path_.c_str(), RTLD_NOW | RTLD_LOCAL); |
| 148 | if (!dlhandle_) { |
| 149 | ALOGE("failed to load layer library '%s': %s", path_.c_str(), |
| 150 | dlerror()); |
| 151 | refcount_ = 0; |
| 152 | return false; |
| 153 | } |
Chia-I Wu | fd0389f | 2016-04-18 12:11:00 +0800 | [diff] [blame] | 154 | } |
| 155 | } |
Chia-I Wu | fd0389f | 2016-04-18 12:11:00 +0800 | [diff] [blame] | 156 | return true; |
| 157 | } |
| 158 | |
Chia-I Wu | d91c74f | 2016-04-18 12:12:36 +0800 | [diff] [blame] | 159 | void LayerLibrary::Close() { |
Chia-I Wu | a622974 | 2016-04-26 07:37:44 +0800 | [diff] [blame] | 160 | std::lock_guard<std::mutex> lock(mutex_); |
Chia-I Wu | 6693f5c | 2016-04-18 12:20:02 +0800 | [diff] [blame] | 161 | if (--refcount_ == 0) { |
Jesse Hall | 1a7eb59 | 2016-05-01 21:04:40 +0200 | [diff] [blame] | 162 | ALOGV("closing layer library '%s'", path_.c_str()); |
Nicolas Geoffray | a655dac | 2019-01-11 15:59:42 +0000 | [diff] [blame] | 163 | char* error_msg = nullptr; |
Jacky.Deng | 01728c1 | 2018-08-28 15:25:31 +0800 | [diff] [blame] | 164 | if (!android::CloseNativeLibrary(dlhandle_, native_bridge_, &error_msg)) { |
Nicolas Geoffray | a655dac | 2019-01-11 15:59:42 +0000 | [diff] [blame] | 165 | ALOGE("failed to unload library '%s': %s", path_.c_str(), error_msg); |
| 166 | android::NativeLoaderFreeErrorMessage(error_msg); |
Jacky.Deng | 01728c1 | 2018-08-28 15:25:31 +0800 | [diff] [blame] | 167 | refcount_++; |
| 168 | } else { |
| 169 | dlhandle_ = nullptr; |
| 170 | } |
Chia-I Wu | d91c74f | 2016-04-18 12:12:36 +0800 | [diff] [blame] | 171 | } |
Chia-I Wu | d91c74f | 2016-04-18 12:12:36 +0800 | [diff] [blame] | 172 | } |
| 173 | |
Chia-I Wu | 50174ee | 2016-04-18 16:33:20 +0800 | [diff] [blame] | 174 | bool LayerLibrary::EnumerateLayers(size_t library_idx, |
Chia-I Wu | bea09db | 2016-04-22 09:42:41 +0800 | [diff] [blame] | 175 | std::vector<Layer>& instance_layers) const { |
Jesse Hall | aa41094 | 2016-01-17 13:07:10 -0800 | [diff] [blame] | 176 | PFN_vkEnumerateInstanceLayerProperties enumerate_instance_layers = |
Victor Khimenko | bbf7700 | 2018-08-16 22:38:36 +0200 | [diff] [blame] | 177 | GetTrampoline<PFN_vkEnumerateInstanceLayerProperties>( |
| 178 | "vkEnumerateInstanceLayerProperties"); |
Jesse Hall | aa41094 | 2016-01-17 13:07:10 -0800 | [diff] [blame] | 179 | PFN_vkEnumerateInstanceExtensionProperties enumerate_instance_extensions = |
Victor Khimenko | bbf7700 | 2018-08-16 22:38:36 +0200 | [diff] [blame] | 180 | GetTrampoline<PFN_vkEnumerateInstanceExtensionProperties>( |
| 181 | "vkEnumerateInstanceExtensionProperties"); |
Chia-I Wu | 5f093bf | 2016-04-19 12:22:52 +0800 | [diff] [blame] | 182 | if (!enumerate_instance_layers || !enumerate_instance_extensions) { |
Jesse Hall | 1a7eb59 | 2016-05-01 21:04:40 +0200 | [diff] [blame] | 183 | ALOGE("layer library '%s' missing some instance enumeration functions", |
Chia-I Wu | 5f093bf | 2016-04-19 12:22:52 +0800 | [diff] [blame] | 184 | path_.c_str()); |
| 185 | return false; |
| 186 | } |
| 187 | |
| 188 | // device functions are optional |
Jesse Hall | aa41094 | 2016-01-17 13:07:10 -0800 | [diff] [blame] | 189 | PFN_vkEnumerateDeviceLayerProperties enumerate_device_layers = |
Victor Khimenko | bbf7700 | 2018-08-16 22:38:36 +0200 | [diff] [blame] | 190 | GetTrampoline<PFN_vkEnumerateDeviceLayerProperties>( |
| 191 | "vkEnumerateDeviceLayerProperties"); |
Jesse Hall | aa41094 | 2016-01-17 13:07:10 -0800 | [diff] [blame] | 192 | PFN_vkEnumerateDeviceExtensionProperties enumerate_device_extensions = |
Victor Khimenko | bbf7700 | 2018-08-16 22:38:36 +0200 | [diff] [blame] | 193 | GetTrampoline<PFN_vkEnumerateDeviceExtensionProperties>( |
| 194 | "vkEnumerateDeviceExtensionProperties"); |
Jesse Hall | 80523e2 | 2016-01-06 16:47:54 -0800 | [diff] [blame] | 195 | |
Chia-I Wu | 5f093bf | 2016-04-19 12:22:52 +0800 | [diff] [blame] | 196 | // get layer counts |
Jesse Hall | aa41094 | 2016-01-17 13:07:10 -0800 | [diff] [blame] | 197 | uint32_t num_instance_layers = 0; |
| 198 | uint32_t num_device_layers = 0; |
Chia-I Wu | 5f093bf | 2016-04-19 12:22:52 +0800 | [diff] [blame] | 199 | VkResult result = enumerate_instance_layers(&num_instance_layers, nullptr); |
| 200 | if (result != VK_SUCCESS || !num_instance_layers) { |
Jesse Hall | aa41094 | 2016-01-17 13:07:10 -0800 | [diff] [blame] | 201 | if (result != VK_SUCCESS) { |
Jesse Hall | 1a7eb59 | 2016-05-01 21:04:40 +0200 | [diff] [blame] | 202 | ALOGE( |
Jesse Hall | aa41094 | 2016-01-17 13:07:10 -0800 | [diff] [blame] | 203 | "vkEnumerateInstanceLayerProperties failed for library '%s': " |
| 204 | "%d", |
Chia-I Wu | 6693f5c | 2016-04-18 12:20:02 +0800 | [diff] [blame] | 205 | path_.c_str(), result); |
Jesse Hall | aa41094 | 2016-01-17 13:07:10 -0800 | [diff] [blame] | 206 | } |
Chia-I Wu | 5f093bf | 2016-04-19 12:22:52 +0800 | [diff] [blame] | 207 | return false; |
Jesse Hall | 80523e2 | 2016-01-06 16:47:54 -0800 | [diff] [blame] | 208 | } |
Jesse Hall | aa41094 | 2016-01-17 13:07:10 -0800 | [diff] [blame] | 209 | if (enumerate_device_layers) { |
| 210 | result = enumerate_device_layers(VK_NULL_HANDLE, &num_device_layers, |
| 211 | nullptr); |
| 212 | if (result != VK_SUCCESS) { |
Jesse Hall | 1a7eb59 | 2016-05-01 21:04:40 +0200 | [diff] [blame] | 213 | ALOGE( |
Jesse Hall | aa41094 | 2016-01-17 13:07:10 -0800 | [diff] [blame] | 214 | "vkEnumerateDeviceLayerProperties failed for library '%s': %d", |
Chia-I Wu | 6693f5c | 2016-04-18 12:20:02 +0800 | [diff] [blame] | 215 | path_.c_str(), result); |
Chia-I Wu | 50174ee | 2016-04-18 16:33:20 +0800 | [diff] [blame] | 216 | return false; |
Jesse Hall | aa41094 | 2016-01-17 13:07:10 -0800 | [diff] [blame] | 217 | } |
| 218 | } |
Chia-I Wu | 5f093bf | 2016-04-19 12:22:52 +0800 | [diff] [blame] | 219 | |
| 220 | // get layer properties |
Nick Desaulniers | 60307ce | 2019-10-25 13:34:21 -0700 | [diff] [blame] | 221 | std::vector<VkLayerProperties> properties(num_instance_layers + num_device_layers); |
| 222 | result = enumerate_instance_layers(&num_instance_layers, properties.data()); |
Nick Desaulniers | 03b11cf | 2019-10-25 11:23:08 -0700 | [diff] [blame] | 223 | if (result != VK_SUCCESS) { |
| 224 | ALOGE("vkEnumerateInstanceLayerProperties failed for library '%s': %d", |
| 225 | path_.c_str(), result); |
| 226 | return false; |
| 227 | } |
Jesse Hall | aa41094 | 2016-01-17 13:07:10 -0800 | [diff] [blame] | 228 | if (num_device_layers > 0) { |
| 229 | result = enumerate_device_layers(VK_NULL_HANDLE, &num_device_layers, |
Nick Desaulniers | 60307ce | 2019-10-25 13:34:21 -0700 | [diff] [blame] | 230 | &properties[num_instance_layers]); |
Jesse Hall | aa41094 | 2016-01-17 13:07:10 -0800 | [diff] [blame] | 231 | if (result != VK_SUCCESS) { |
Jesse Hall | 1a7eb59 | 2016-05-01 21:04:40 +0200 | [diff] [blame] | 232 | ALOGE( |
Jesse Hall | aa41094 | 2016-01-17 13:07:10 -0800 | [diff] [blame] | 233 | "vkEnumerateDeviceLayerProperties failed for library '%s': %d", |
Chia-I Wu | 6693f5c | 2016-04-18 12:20:02 +0800 | [diff] [blame] | 234 | path_.c_str(), result); |
Chia-I Wu | 50174ee | 2016-04-18 16:33:20 +0800 | [diff] [blame] | 235 | return false; |
Jesse Hall | aa41094 | 2016-01-17 13:07:10 -0800 | [diff] [blame] | 236 | } |
Jesse Hall | 80523e2 | 2016-01-06 16:47:54 -0800 | [diff] [blame] | 237 | } |
| 238 | |
Chia-I Wu | bea09db | 2016-04-22 09:42:41 +0800 | [diff] [blame] | 239 | // append layers to instance_layers |
Chia-I Wu | 50174ee | 2016-04-18 16:33:20 +0800 | [diff] [blame] | 240 | size_t prev_num_instance_layers = instance_layers.size(); |
Chia-I Wu | 50174ee | 2016-04-18 16:33:20 +0800 | [diff] [blame] | 241 | instance_layers.reserve(prev_num_instance_layers + num_instance_layers); |
Jesse Hall | aa41094 | 2016-01-17 13:07:10 -0800 | [diff] [blame] | 242 | for (size_t i = 0; i < num_instance_layers; i++) { |
| 243 | const VkLayerProperties& props = properties[i]; |
| 244 | |
Jesse Hall | 80523e2 | 2016-01-06 16:47:54 -0800 | [diff] [blame] | 245 | Layer layer; |
Jesse Hall | aa41094 | 2016-01-17 13:07:10 -0800 | [diff] [blame] | 246 | layer.properties = props; |
Jesse Hall | 80523e2 | 2016-01-06 16:47:54 -0800 | [diff] [blame] | 247 | layer.library_idx = library_idx; |
Chia-I Wu | bea09db | 2016-04-22 09:42:41 +0800 | [diff] [blame] | 248 | layer.is_global = false; |
Jesse Hall | 80523e2 | 2016-01-06 16:47:54 -0800 | [diff] [blame] | 249 | |
Chia-I Wu | 5f093bf | 2016-04-19 12:22:52 +0800 | [diff] [blame] | 250 | uint32_t count = 0; |
| 251 | result = |
| 252 | enumerate_instance_extensions(props.layerName, &count, nullptr); |
| 253 | if (result != VK_SUCCESS) { |
Jesse Hall | 1a7eb59 | 2016-05-01 21:04:40 +0200 | [diff] [blame] | 254 | ALOGE( |
| 255 | "vkEnumerateInstanceExtensionProperties(\"%s\") failed for " |
| 256 | "library '%s': %d", |
Chia-I Wu | 5f093bf | 2016-04-19 12:22:52 +0800 | [diff] [blame] | 257 | props.layerName, path_.c_str(), result); |
| 258 | instance_layers.resize(prev_num_instance_layers); |
| 259 | return false; |
| 260 | } |
Chia-I Wu | bea09db | 2016-04-22 09:42:41 +0800 | [diff] [blame] | 261 | layer.instance_extensions.resize(count); |
| 262 | result = enumerate_instance_extensions( |
| 263 | props.layerName, &count, layer.instance_extensions.data()); |
Chia-I Wu | 5f093bf | 2016-04-19 12:22:52 +0800 | [diff] [blame] | 264 | if (result != VK_SUCCESS) { |
Jesse Hall | 1a7eb59 | 2016-05-01 21:04:40 +0200 | [diff] [blame] | 265 | ALOGE( |
| 266 | "vkEnumerateInstanceExtensionProperties(\"%s\") failed for " |
| 267 | "library '%s': %d", |
Chia-I Wu | 5f093bf | 2016-04-19 12:22:52 +0800 | [diff] [blame] | 268 | props.layerName, path_.c_str(), result); |
| 269 | instance_layers.resize(prev_num_instance_layers); |
| 270 | return false; |
Jesse Hall | 80523e2 | 2016-01-06 16:47:54 -0800 | [diff] [blame] | 271 | } |
| 272 | |
Chia-I Wu | 279ccc0 | 2016-04-18 16:45:15 +0800 | [diff] [blame] | 273 | for (size_t j = 0; j < num_device_layers; j++) { |
| 274 | const auto& dev_props = properties[num_instance_layers + j]; |
| 275 | if (memcmp(&props, &dev_props, sizeof(props)) == 0) { |
Chia-I Wu | bea09db | 2016-04-22 09:42:41 +0800 | [diff] [blame] | 276 | layer.is_global = true; |
Chia-I Wu | 279ccc0 | 2016-04-18 16:45:15 +0800 | [diff] [blame] | 277 | break; |
| 278 | } |
| 279 | } |
Jesse Hall | aa41094 | 2016-01-17 13:07:10 -0800 | [diff] [blame] | 280 | |
Chia-I Wu | bea09db | 2016-04-22 09:42:41 +0800 | [diff] [blame] | 281 | if (layer.is_global && enumerate_device_extensions) { |
Jesse Hall | aa41094 | 2016-01-17 13:07:10 -0800 | [diff] [blame] | 282 | result = enumerate_device_extensions( |
| 283 | VK_NULL_HANDLE, props.layerName, &count, nullptr); |
| 284 | if (result != VK_SUCCESS) { |
Jesse Hall | 1a7eb59 | 2016-05-01 21:04:40 +0200 | [diff] [blame] | 285 | ALOGE( |
| 286 | "vkEnumerateDeviceExtensionProperties(\"%s\") failed for " |
Chia-I Wu | 50174ee | 2016-04-18 16:33:20 +0800 | [diff] [blame] | 287 | "library '%s': %d", |
Chia-I Wu | 6693f5c | 2016-04-18 12:20:02 +0800 | [diff] [blame] | 288 | props.layerName, path_.c_str(), result); |
Chia-I Wu | 50174ee | 2016-04-18 16:33:20 +0800 | [diff] [blame] | 289 | instance_layers.resize(prev_num_instance_layers); |
Chia-I Wu | 50174ee | 2016-04-18 16:33:20 +0800 | [diff] [blame] | 290 | return false; |
Jesse Hall | aa41094 | 2016-01-17 13:07:10 -0800 | [diff] [blame] | 291 | } |
Chia-I Wu | bea09db | 2016-04-22 09:42:41 +0800 | [diff] [blame] | 292 | layer.device_extensions.resize(count); |
| 293 | result = enumerate_device_extensions( |
| 294 | VK_NULL_HANDLE, props.layerName, &count, |
| 295 | layer.device_extensions.data()); |
Jesse Hall | aa41094 | 2016-01-17 13:07:10 -0800 | [diff] [blame] | 296 | if (result != VK_SUCCESS) { |
Jesse Hall | 1a7eb59 | 2016-05-01 21:04:40 +0200 | [diff] [blame] | 297 | ALOGE( |
| 298 | "vkEnumerateDeviceExtensionProperties(\"%s\") failed for " |
Chia-I Wu | 50174ee | 2016-04-18 16:33:20 +0800 | [diff] [blame] | 299 | "library '%s': %d", |
Chia-I Wu | 6693f5c | 2016-04-18 12:20:02 +0800 | [diff] [blame] | 300 | props.layerName, path_.c_str(), result); |
Chia-I Wu | 50174ee | 2016-04-18 16:33:20 +0800 | [diff] [blame] | 301 | instance_layers.resize(prev_num_instance_layers); |
Chia-I Wu | 50174ee | 2016-04-18 16:33:20 +0800 | [diff] [blame] | 302 | return false; |
Jesse Hall | aa41094 | 2016-01-17 13:07:10 -0800 | [diff] [blame] | 303 | } |
| 304 | } |
| 305 | |
Chia-I Wu | bea09db | 2016-04-22 09:42:41 +0800 | [diff] [blame] | 306 | instance_layers.push_back(layer); |
Jesse Hall | 1a7eb59 | 2016-05-01 21:04:40 +0200 | [diff] [blame] | 307 | ALOGD("added %s layer '%s' from library '%s'", |
| 308 | (layer.is_global) ? "global" : "instance", props.layerName, |
| 309 | path_.c_str()); |
Jesse Hall | 80523e2 | 2016-01-06 16:47:54 -0800 | [diff] [blame] | 310 | } |
| 311 | |
Chia-I Wu | 50174ee | 2016-04-18 16:33:20 +0800 | [diff] [blame] | 312 | return true; |
| 313 | } |
Jesse Hall | 80523e2 | 2016-01-06 16:47:54 -0800 | [diff] [blame] | 314 | |
Nick Desaulniers | 60307ce | 2019-10-25 13:34:21 -0700 | [diff] [blame] | 315 | void* LayerLibrary::GetGPA(const Layer& layer, const std::string_view gpa_name) const { |
| 316 | std::string layer_name { layer.properties.layerName }; |
| 317 | if (void* gpa = GetTrampoline((layer_name.append(gpa_name).c_str()))) |
| 318 | return gpa; |
| 319 | return GetTrampoline((std::string {"vk"}.append(gpa_name)).c_str()); |
Chia-I Wu | ba11327 | 2016-04-18 16:38:39 +0800 | [diff] [blame] | 320 | } |
| 321 | |
Jesse Hall | 1a7eb59 | 2016-05-01 21:04:40 +0200 | [diff] [blame] | 322 | // ---------------------------------------------------------------------------- |
| 323 | |
Chia-I Wu | 50174ee | 2016-04-18 16:33:20 +0800 | [diff] [blame] | 324 | std::vector<LayerLibrary> g_layer_libraries; |
| 325 | std::vector<Layer> g_instance_layers; |
Chia-I Wu | 50174ee | 2016-04-18 16:33:20 +0800 | [diff] [blame] | 326 | |
Cody Northrop | d2aa3ab | 2017-10-20 09:01:53 -0600 | [diff] [blame] | 327 | void AddLayerLibrary(const std::string& path, const std::string& filename) { |
| 328 | LayerLibrary library(path + "/" + filename, filename); |
Chia-I Wu | 50174ee | 2016-04-18 16:33:20 +0800 | [diff] [blame] | 329 | if (!library.Open()) |
| 330 | return; |
| 331 | |
Chia-I Wu | bea09db | 2016-04-22 09:42:41 +0800 | [diff] [blame] | 332 | if (!library.EnumerateLayers(g_layer_libraries.size(), g_instance_layers)) { |
Chia-I Wu | 50174ee | 2016-04-18 16:33:20 +0800 | [diff] [blame] | 333 | library.Close(); |
| 334 | return; |
| 335 | } |
| 336 | |
| 337 | library.Close(); |
| 338 | |
| 339 | g_layer_libraries.emplace_back(std::move(library)); |
Jesse Hall | 80523e2 | 2016-01-06 16:47:54 -0800 | [diff] [blame] | 340 | } |
| 341 | |
Jesse Hall | 1a7eb59 | 2016-05-01 21:04:40 +0200 | [diff] [blame] | 342 | template <typename Functor> |
| 343 | void ForEachFileInDir(const std::string& dirname, Functor functor) { |
| 344 | auto dir_deleter = [](DIR* handle) { closedir(handle); }; |
| 345 | std::unique_ptr<DIR, decltype(dir_deleter)> dir(opendir(dirname.c_str()), |
| 346 | dir_deleter); |
| 347 | if (!dir) { |
| 348 | // It's normal for some search directories to not exist, especially |
| 349 | // /data/local/debug/vulkan. |
Jesse Hall | 80523e2 | 2016-01-06 16:47:54 -0800 | [diff] [blame] | 350 | int err = errno; |
Jesse Hall | 1a7eb59 | 2016-05-01 21:04:40 +0200 | [diff] [blame] | 351 | ALOGW_IF(err != ENOENT, "failed to open layer directory '%s': %s", |
| 352 | dirname.c_str(), strerror(err)); |
Jesse Hall | 80523e2 | 2016-01-06 16:47:54 -0800 | [diff] [blame] | 353 | return; |
| 354 | } |
Jesse Hall | 1a7eb59 | 2016-05-01 21:04:40 +0200 | [diff] [blame] | 355 | ALOGD("searching for layers in '%s'", dirname.c_str()); |
| 356 | dirent* entry; |
| 357 | while ((entry = readdir(dir.get())) != nullptr) |
| 358 | functor(entry->d_name); |
| 359 | } |
Jesse Hall | 80523e2 | 2016-01-06 16:47:54 -0800 | [diff] [blame] | 360 | |
Jesse Hall | 1a7eb59 | 2016-05-01 21:04:40 +0200 | [diff] [blame] | 361 | template <typename Functor> |
| 362 | void ForEachFileInZip(const std::string& zipname, |
| 363 | const std::string& dir_in_zip, |
| 364 | Functor functor) { |
| 365 | int32_t err; |
| 366 | ZipArchiveHandle zip = nullptr; |
| 367 | if ((err = OpenArchive(zipname.c_str(), &zip)) != 0) { |
| 368 | ALOGE("failed to open apk '%s': %d", zipname.c_str(), err); |
| 369 | return; |
Jesse Hall | 80523e2 | 2016-01-06 16:47:54 -0800 | [diff] [blame] | 370 | } |
Jesse Hall | 1a7eb59 | 2016-05-01 21:04:40 +0200 | [diff] [blame] | 371 | std::string prefix(dir_in_zip + "/"); |
Jesse Hall | 1a7eb59 | 2016-05-01 21:04:40 +0200 | [diff] [blame] | 372 | void* iter_cookie = nullptr; |
Elliott Hughes | 5449204 | 2019-05-08 12:00:32 -0700 | [diff] [blame] | 373 | if ((err = StartIteration(zip, &iter_cookie, prefix, "")) != 0) { |
Jesse Hall | 1a7eb59 | 2016-05-01 21:04:40 +0200 | [diff] [blame] | 374 | ALOGE("failed to iterate entries in apk '%s': %d", zipname.c_str(), |
| 375 | err); |
| 376 | CloseArchive(zip); |
| 377 | return; |
| 378 | } |
| 379 | ALOGD("searching for layers in '%s!/%s'", zipname.c_str(), |
| 380 | dir_in_zip.c_str()); |
| 381 | ZipEntry entry; |
Elliott Hughes | c1f2485 | 2019-05-22 19:47:17 -0700 | [diff] [blame] | 382 | std::string name; |
Jesse Hall | 1a7eb59 | 2016-05-01 21:04:40 +0200 | [diff] [blame] | 383 | while (Next(iter_cookie, &entry, &name) == 0) { |
Elliott Hughes | c1f2485 | 2019-05-22 19:47:17 -0700 | [diff] [blame] | 384 | std::string filename(name.substr(prefix.length())); |
Jesse Hall | 1a7eb59 | 2016-05-01 21:04:40 +0200 | [diff] [blame] | 385 | // only enumerate direct entries of the directory, not subdirectories |
Jesse Hall | 8c6c10e | 2016-05-19 10:58:35 -0700 | [diff] [blame] | 386 | if (filename.find('/') != filename.npos) |
| 387 | continue; |
| 388 | // Check whether it *may* be possible to load the library directly from |
| 389 | // the APK. Loading still may fail for other reasons, but this at least |
| 390 | // lets us avoid failed-to-load log messages in the typical case of |
| 391 | // compressed and/or unaligned libraries. |
| 392 | if (entry.method != kCompressStored || entry.offset % PAGE_SIZE != 0) |
| 393 | continue; |
| 394 | functor(filename); |
Jesse Hall | 1a7eb59 | 2016-05-01 21:04:40 +0200 | [diff] [blame] | 395 | } |
| 396 | EndIteration(iter_cookie); |
| 397 | CloseArchive(zip); |
| 398 | } |
Jesse Hall | 80523e2 | 2016-01-06 16:47:54 -0800 | [diff] [blame] | 399 | |
Jesse Hall | 1a7eb59 | 2016-05-01 21:04:40 +0200 | [diff] [blame] | 400 | template <typename Functor> |
| 401 | void ForEachFileInPath(const std::string& path, Functor functor) { |
| 402 | size_t zip_pos = path.find("!/"); |
| 403 | if (zip_pos == std::string::npos) { |
| 404 | ForEachFileInDir(path, functor); |
| 405 | } else { |
| 406 | ForEachFileInZip(path.substr(0, zip_pos), path.substr(zip_pos + 2), |
| 407 | functor); |
| 408 | } |
| 409 | } |
| 410 | |
| 411 | void DiscoverLayersInPathList(const std::string& pathstr) { |
Yiwei Zhang | fdd0c2a | 2019-01-30 20:16:37 -0800 | [diff] [blame] | 412 | ATRACE_CALL(); |
| 413 | |
Jesse Hall | 1a7eb59 | 2016-05-01 21:04:40 +0200 | [diff] [blame] | 414 | std::vector<std::string> paths = android::base::Split(pathstr, ":"); |
| 415 | for (const auto& path : paths) { |
| 416 | ForEachFileInPath(path, [&](const std::string& filename) { |
| 417 | if (android::base::StartsWith(filename, "libVkLayer") && |
| 418 | android::base::EndsWith(filename, ".so")) { |
Cody Northrop | d2aa3ab | 2017-10-20 09:01:53 -0600 | [diff] [blame] | 419 | |
| 420 | // Check to ensure we haven't seen this layer already |
| 421 | // Let the first instance of the shared object be enumerated |
| 422 | // We're searching for layers in following order: |
| 423 | // 1. system path |
| 424 | // 2. libraryPermittedPath (if enabled) |
| 425 | // 3. libraryPath |
| 426 | |
| 427 | bool duplicate = false; |
| 428 | for (auto& layer : g_layer_libraries) { |
| 429 | if (layer.GetFilename() == filename) { |
| 430 | ALOGV("Skipping duplicate layer %s in %s", |
| 431 | filename.c_str(), path.c_str()); |
| 432 | duplicate = true; |
| 433 | } |
| 434 | } |
| 435 | |
| 436 | if (!duplicate) |
| 437 | AddLayerLibrary(path, filename); |
Jesse Hall | 1a7eb59 | 2016-05-01 21:04:40 +0200 | [diff] [blame] | 438 | } |
| 439 | }); |
| 440 | } |
Jesse Hall | 80523e2 | 2016-01-06 16:47:54 -0800 | [diff] [blame] | 441 | } |
| 442 | |
Chia-I Wu | dab2565 | 2016-04-28 07:15:51 +0800 | [diff] [blame] | 443 | const VkExtensionProperties* FindExtension( |
| 444 | const std::vector<VkExtensionProperties>& extensions, |
| 445 | const char* name) { |
| 446 | auto it = std::find_if(extensions.cbegin(), extensions.cend(), |
| 447 | [=](const VkExtensionProperties& ext) { |
| 448 | return (strcmp(ext.extensionName, name) == 0); |
| 449 | }); |
| 450 | return (it != extensions.cend()) ? &*it : nullptr; |
| 451 | } |
| 452 | |
Jesse Hall | 80523e2 | 2016-01-06 16:47:54 -0800 | [diff] [blame] | 453 | void* GetLayerGetProcAddr(const Layer& layer, |
Nick Desaulniers | 60307ce | 2019-10-25 13:34:21 -0700 | [diff] [blame] | 454 | const std::string_view gpa_name) { |
Jesse Hall | 80523e2 | 2016-01-06 16:47:54 -0800 | [diff] [blame] | 455 | const LayerLibrary& library = g_layer_libraries[layer.library_idx]; |
Nick Desaulniers | 60307ce | 2019-10-25 13:34:21 -0700 | [diff] [blame] | 456 | return library.GetGPA(layer, gpa_name); |
Jesse Hall | 80523e2 | 2016-01-06 16:47:54 -0800 | [diff] [blame] | 457 | } |
| 458 | |
Jesse Hall | aa41094 | 2016-01-17 13:07:10 -0800 | [diff] [blame] | 459 | } // anonymous namespace |
| 460 | |
Jesse Hall | aa41094 | 2016-01-17 13:07:10 -0800 | [diff] [blame] | 461 | void DiscoverLayers() { |
Yiwei Zhang | fdd0c2a | 2019-01-30 20:16:37 -0800 | [diff] [blame] | 462 | ATRACE_CALL(); |
| 463 | |
Yiwei Zhang | 6a674c9 | 2019-11-08 11:55:36 -0800 | [diff] [blame] | 464 | if (android::GraphicsEnv::getInstance().isDebuggable()) { |
Jesse Hall | 1a7eb59 | 2016-05-01 21:04:40 +0200 | [diff] [blame] | 465 | DiscoverLayersInPathList(kSystemLayerLibraryDir); |
| 466 | } |
Cody Northrop | d2aa3ab | 2017-10-20 09:01:53 -0600 | [diff] [blame] | 467 | if (!android::GraphicsEnv::getInstance().getLayerPaths().empty()) |
| 468 | DiscoverLayersInPathList(android::GraphicsEnv::getInstance().getLayerPaths()); |
Jesse Hall | aa41094 | 2016-01-17 13:07:10 -0800 | [diff] [blame] | 469 | } |
| 470 | |
Chia-I Wu | 25700b4 | 2016-04-28 06:36:09 +0800 | [diff] [blame] | 471 | uint32_t GetLayerCount() { |
Chia-I Wu | bea09db | 2016-04-22 09:42:41 +0800 | [diff] [blame] | 472 | return static_cast<uint32_t>(g_instance_layers.size()); |
Jesse Hall | aa41094 | 2016-01-17 13:07:10 -0800 | [diff] [blame] | 473 | } |
| 474 | |
Chia-I Wu | 25700b4 | 2016-04-28 06:36:09 +0800 | [diff] [blame] | 475 | const Layer& GetLayer(uint32_t index) { |
| 476 | return g_instance_layers[index]; |
| 477 | } |
Chia-I Wu | bea09db | 2016-04-22 09:42:41 +0800 | [diff] [blame] | 478 | |
Chia-I Wu | 04c6551 | 2016-04-27 09:54:02 +0800 | [diff] [blame] | 479 | const Layer* FindLayer(const char* name) { |
| 480 | auto layer = |
| 481 | std::find_if(g_instance_layers.cbegin(), g_instance_layers.cend(), |
| 482 | [=](const Layer& entry) { |
| 483 | return strcmp(entry.properties.layerName, name) == 0; |
| 484 | }); |
| 485 | return (layer != g_instance_layers.cend()) ? &*layer : nullptr; |
| 486 | } |
| 487 | |
Chia-I Wu | 25700b4 | 2016-04-28 06:36:09 +0800 | [diff] [blame] | 488 | const VkLayerProperties& GetLayerProperties(const Layer& layer) { |
| 489 | return layer.properties; |
| 490 | } |
Chia-I Wu | bea09db | 2016-04-22 09:42:41 +0800 | [diff] [blame] | 491 | |
Chia-I Wu | 25700b4 | 2016-04-28 06:36:09 +0800 | [diff] [blame] | 492 | bool IsLayerGlobal(const Layer& layer) { |
| 493 | return layer.is_global; |
Jesse Hall | aa41094 | 2016-01-17 13:07:10 -0800 | [diff] [blame] | 494 | } |
| 495 | |
Chia-I Wu | 04c6551 | 2016-04-27 09:54:02 +0800 | [diff] [blame] | 496 | const VkExtensionProperties* GetLayerInstanceExtensions(const Layer& layer, |
| 497 | uint32_t& count) { |
| 498 | count = static_cast<uint32_t>(layer.instance_extensions.size()); |
| 499 | return layer.instance_extensions.data(); |
Jesse Hall | aa41094 | 2016-01-17 13:07:10 -0800 | [diff] [blame] | 500 | } |
| 501 | |
Chia-I Wu | 04c6551 | 2016-04-27 09:54:02 +0800 | [diff] [blame] | 502 | const VkExtensionProperties* GetLayerDeviceExtensions(const Layer& layer, |
| 503 | uint32_t& count) { |
| 504 | count = static_cast<uint32_t>(layer.device_extensions.size()); |
| 505 | return layer.device_extensions.data(); |
Jesse Hall | aa41094 | 2016-01-17 13:07:10 -0800 | [diff] [blame] | 506 | } |
| 507 | |
Chia-I Wu | dab2565 | 2016-04-28 07:15:51 +0800 | [diff] [blame] | 508 | const VkExtensionProperties* FindLayerInstanceExtension(const Layer& layer, |
| 509 | const char* name) { |
| 510 | return FindExtension(layer.instance_extensions, name); |
Jesse Hall | aa41094 | 2016-01-17 13:07:10 -0800 | [diff] [blame] | 511 | } |
| 512 | |
Chia-I Wu | dab2565 | 2016-04-28 07:15:51 +0800 | [diff] [blame] | 513 | const VkExtensionProperties* FindLayerDeviceExtension(const Layer& layer, |
| 514 | const char* name) { |
| 515 | return FindExtension(layer.device_extensions, name); |
Jesse Hall | aa41094 | 2016-01-17 13:07:10 -0800 | [diff] [blame] | 516 | } |
| 517 | |
Chia-I Wu | dab2565 | 2016-04-28 07:15:51 +0800 | [diff] [blame] | 518 | LayerRef GetLayerRef(const Layer& layer) { |
| 519 | LayerLibrary& library = g_layer_libraries[layer.library_idx]; |
| 520 | return LayerRef((library.Open()) ? &layer : nullptr); |
| 521 | } |
| 522 | |
| 523 | LayerRef::LayerRef(const Layer* layer) : layer_(layer) {} |
Jesse Hall | 80523e2 | 2016-01-06 16:47:54 -0800 | [diff] [blame] | 524 | |
| 525 | LayerRef::~LayerRef() { |
| 526 | if (layer_) { |
| 527 | LayerLibrary& library = g_layer_libraries[layer_->library_idx]; |
Chia-I Wu | d91c74f | 2016-04-18 12:12:36 +0800 | [diff] [blame] | 528 | library.Close(); |
Jesse Hall | 80523e2 | 2016-01-06 16:47:54 -0800 | [diff] [blame] | 529 | } |
| 530 | } |
| 531 | |
Chih-Hung Hsieh | 5bc849f | 2018-09-25 14:21:50 -0700 | [diff] [blame] | 532 | LayerRef::LayerRef(LayerRef&& other) noexcept : layer_(other.layer_) { |
Michael Lentine | 54e6f08 | 2016-01-20 11:25:28 -0600 | [diff] [blame] | 533 | other.layer_ = nullptr; |
| 534 | } |
Jesse Hall | 80523e2 | 2016-01-06 16:47:54 -0800 | [diff] [blame] | 535 | |
| 536 | PFN_vkGetInstanceProcAddr LayerRef::GetGetInstanceProcAddr() const { |
| 537 | return layer_ ? reinterpret_cast<PFN_vkGetInstanceProcAddr>( |
Nick Desaulniers | 60307ce | 2019-10-25 13:34:21 -0700 | [diff] [blame] | 538 | GetLayerGetProcAddr(*layer_, "GetInstanceProcAddr")) |
Jesse Hall | 80523e2 | 2016-01-06 16:47:54 -0800 | [diff] [blame] | 539 | : nullptr; |
| 540 | } |
| 541 | |
| 542 | PFN_vkGetDeviceProcAddr LayerRef::GetGetDeviceProcAddr() const { |
| 543 | return layer_ ? reinterpret_cast<PFN_vkGetDeviceProcAddr>( |
Nick Desaulniers | 60307ce | 2019-10-25 13:34:21 -0700 | [diff] [blame] | 544 | GetLayerGetProcAddr(*layer_, "GetDeviceProcAddr")) |
Jesse Hall | 80523e2 | 2016-01-06 16:47:54 -0800 | [diff] [blame] | 545 | : nullptr; |
| 546 | } |
| 547 | |
Chia-I Wu | c96880f | 2016-03-26 06:56:45 +0800 | [diff] [blame] | 548 | } // namespace api |
Jesse Hall | 80523e2 | 2016-01-06 16:47:54 -0800 | [diff] [blame] | 549 | } // namespace vulkan |