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