blob: 08038b71d6fc0191dd177d6ee04a4ef833520545 [file] [log] [blame]
Jesse Hall80523e22016-01-06 16:47:54 -08001/*
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
Michael Lentined0b7cb52016-01-19 13:57:26 -060017// #define LOG_NDEBUG 0
18
Chia-I Wuc96880f2016-03-26 06:56:45 +080019#include "layers_extensions.h"
Jesse Hall80523e22016-01-06 16:47:54 -080020#include <alloca.h>
21#include <dirent.h>
22#include <dlfcn.h>
23#include <mutex>
24#include <sys/prctl.h>
25#include <string>
26#include <string.h>
27#include <vector>
28#include <log/log.h>
29#include <vulkan/vulkan_loader_data.h>
30
Jesse Hallb1471272016-01-17 21:36:58 -080031// TODO(jessehall): The whole way we deal with extensions is pretty hokey, and
32// not a good long-term solution. Having a hard-coded enum of extensions is
33// bad, of course. Representing sets of extensions (requested, supported, etc.)
34// as a bitset isn't necessarily bad, if the mapping from extension to bit were
35// dynamic. Need to rethink this completely when there's a little more time.
36
Jesse Hallaa410942016-01-17 13:07:10 -080037// TODO(jessehall): This file currently builds up global data structures as it
38// loads, and never cleans them up. This means we're doing heap allocations
39// without going through an app-provided allocator, but worse, we'll leak those
40// allocations if the loader is unloaded.
41//
42// We should allocate "enough" BSS space, and suballocate from there. Will
43// probably want to intern strings, etc., and will need some custom/manual data
44// structures.
45
46// TODO(jessehall): Currently we have separate lists for instance and device
47// layers. Most layers are both; we should use one entry for each layer name,
48// with a mask saying what kind(s) it is.
49
Jesse Hall80523e22016-01-06 16:47:54 -080050namespace vulkan {
Chia-I Wuc96880f2016-03-26 06:56:45 +080051namespace api {
52
Jesse Hall80523e22016-01-06 16:47:54 -080053struct Layer {
54 VkLayerProperties properties;
55 size_t library_idx;
56 std::vector<VkExtensionProperties> extensions;
57};
Jesse Hall80523e22016-01-06 16:47:54 -080058
59namespace {
60
Chia-I Wu6693f5c2016-04-18 12:20:02 +080061class LayerLibrary {
62 public:
63 LayerLibrary(const std::string& path)
64 : path_(path), dlhandle_(nullptr), refcount_(0) {}
Chia-I Wu74349592016-04-18 12:08:39 +080065
Chia-I Wu50174ee2016-04-18 16:33:20 +080066 LayerLibrary(LayerLibrary&& other)
Chia-I Wu6693f5c2016-04-18 12:20:02 +080067 : path_(std::move(other.path_)),
68 dlhandle_(other.dlhandle_),
69 refcount_(other.refcount_) {
70 other.dlhandle_ = nullptr;
71 other.refcount_ = 0;
Chia-I Wu50174ee2016-04-18 16:33:20 +080072 }
73
74 LayerLibrary(const LayerLibrary&) = delete;
75 LayerLibrary& operator=(const LayerLibrary&) = delete;
76
Chia-I Wua6229742016-04-26 07:37:44 +080077 // these are thread-safe
Chia-I Wufd0389f2016-04-18 12:11:00 +080078 bool Open();
Chia-I Wud91c74f2016-04-18 12:12:36 +080079 void Close();
Chia-I Wufd0389f2016-04-18 12:11:00 +080080
Chia-I Wu50174ee2016-04-18 16:33:20 +080081 bool EnumerateLayers(size_t library_idx,
82 std::vector<Layer>& instance_layers,
83 std::vector<Layer>& device_layers) const;
84
Chia-I Wuba113272016-04-18 16:38:39 +080085 void* GetGPA(const Layer& layer,
86 const char* gpa_name,
87 size_t gpa_name_len) const;
88
Chia-I Wu6693f5c2016-04-18 12:20:02 +080089 private:
90 const std::string path_;
Chia-I Wua6229742016-04-26 07:37:44 +080091
92 std::mutex mutex_;
Chia-I Wu6693f5c2016-04-18 12:20:02 +080093 void* dlhandle_;
94 size_t refcount_;
Jesse Hall80523e22016-01-06 16:47:54 -080095};
Chia-I Wu74349592016-04-18 12:08:39 +080096
Chia-I Wufd0389f2016-04-18 12:11:00 +080097bool LayerLibrary::Open() {
Chia-I Wua6229742016-04-26 07:37:44 +080098 std::lock_guard<std::mutex> lock(mutex_);
99
Chia-I Wu6693f5c2016-04-18 12:20:02 +0800100 if (refcount_++ == 0) {
101 dlhandle_ = dlopen(path_.c_str(), RTLD_NOW | RTLD_LOCAL);
102 ALOGV("Opening library %s", path_.c_str());
103 if (!dlhandle_) {
104 ALOGE("failed to load layer library '%s': %s", path_.c_str(),
Chia-I Wufd0389f2016-04-18 12:11:00 +0800105 dlerror());
Chia-I Wu6693f5c2016-04-18 12:20:02 +0800106 refcount_ = 0;
Chia-I Wufd0389f2016-04-18 12:11:00 +0800107 return false;
108 }
109 }
Chia-I Wu6693f5c2016-04-18 12:20:02 +0800110 ALOGV("Refcount on activate is %zu", refcount_);
Chia-I Wufd0389f2016-04-18 12:11:00 +0800111 return true;
112}
113
Chia-I Wud91c74f2016-04-18 12:12:36 +0800114void LayerLibrary::Close() {
Chia-I Wua6229742016-04-26 07:37:44 +0800115 std::lock_guard<std::mutex> lock(mutex_);
116
Chia-I Wu6693f5c2016-04-18 12:20:02 +0800117 if (--refcount_ == 0) {
118 ALOGV("Closing library %s", path_.c_str());
119 dlclose(dlhandle_);
120 dlhandle_ = nullptr;
Chia-I Wud91c74f2016-04-18 12:12:36 +0800121 }
Chia-I Wu6693f5c2016-04-18 12:20:02 +0800122 ALOGV("Refcount on destruction is %zu", refcount_);
Chia-I Wud91c74f2016-04-18 12:12:36 +0800123}
124
Chia-I Wu50174ee2016-04-18 16:33:20 +0800125bool LayerLibrary::EnumerateLayers(size_t library_idx,
126 std::vector<Layer>& instance_layers,
127 std::vector<Layer>& device_layers) const {
Jesse Hallaa410942016-01-17 13:07:10 -0800128 PFN_vkEnumerateInstanceLayerProperties enumerate_instance_layers =
Jesse Hall80523e22016-01-06 16:47:54 -0800129 reinterpret_cast<PFN_vkEnumerateInstanceLayerProperties>(
Chia-I Wu6693f5c2016-04-18 12:20:02 +0800130 dlsym(dlhandle_, "vkEnumerateInstanceLayerProperties"));
Jesse Hallaa410942016-01-17 13:07:10 -0800131 PFN_vkEnumerateInstanceExtensionProperties enumerate_instance_extensions =
Jesse Hall80523e22016-01-06 16:47:54 -0800132 reinterpret_cast<PFN_vkEnumerateInstanceExtensionProperties>(
Chia-I Wu6693f5c2016-04-18 12:20:02 +0800133 dlsym(dlhandle_, "vkEnumerateInstanceExtensionProperties"));
Jesse Hallaa410942016-01-17 13:07:10 -0800134 PFN_vkEnumerateDeviceLayerProperties enumerate_device_layers =
135 reinterpret_cast<PFN_vkEnumerateDeviceLayerProperties>(
Chia-I Wu6693f5c2016-04-18 12:20:02 +0800136 dlsym(dlhandle_, "vkEnumerateDeviceLayerProperties"));
Jesse Hallaa410942016-01-17 13:07:10 -0800137 PFN_vkEnumerateDeviceExtensionProperties enumerate_device_extensions =
138 reinterpret_cast<PFN_vkEnumerateDeviceExtensionProperties>(
Chia-I Wu6693f5c2016-04-18 12:20:02 +0800139 dlsym(dlhandle_, "vkEnumerateDeviceExtensionProperties"));
Jesse Hallaa410942016-01-17 13:07:10 -0800140 if (!((enumerate_instance_layers && enumerate_instance_extensions) ||
141 (enumerate_device_layers && enumerate_device_extensions))) {
142 ALOGV(
143 "layer library '%s' has neither instance nor device enumeraion "
144 "functions",
Chia-I Wu6693f5c2016-04-18 12:20:02 +0800145 path_.c_str());
Chia-I Wu50174ee2016-04-18 16:33:20 +0800146 return false;
Jesse Hall80523e22016-01-06 16:47:54 -0800147 }
148
Jesse Hallaa410942016-01-17 13:07:10 -0800149 VkResult result;
150 uint32_t num_instance_layers = 0;
151 uint32_t num_device_layers = 0;
152 if (enumerate_instance_layers) {
153 result = enumerate_instance_layers(&num_instance_layers, nullptr);
154 if (result != VK_SUCCESS) {
155 ALOGW(
156 "vkEnumerateInstanceLayerProperties failed for library '%s': "
157 "%d",
Chia-I Wu6693f5c2016-04-18 12:20:02 +0800158 path_.c_str(), result);
Chia-I Wu50174ee2016-04-18 16:33:20 +0800159 return false;
Jesse Hallaa410942016-01-17 13:07:10 -0800160 }
Jesse Hall80523e22016-01-06 16:47:54 -0800161 }
Jesse Hallaa410942016-01-17 13:07:10 -0800162 if (enumerate_device_layers) {
163 result = enumerate_device_layers(VK_NULL_HANDLE, &num_device_layers,
164 nullptr);
165 if (result != VK_SUCCESS) {
166 ALOGW(
167 "vkEnumerateDeviceLayerProperties failed for library '%s': %d",
Chia-I Wu6693f5c2016-04-18 12:20:02 +0800168 path_.c_str(), result);
Chia-I Wu50174ee2016-04-18 16:33:20 +0800169 return false;
Jesse Hallaa410942016-01-17 13:07:10 -0800170 }
171 }
172 VkLayerProperties* properties = static_cast<VkLayerProperties*>(alloca(
173 (num_instance_layers + num_device_layers) * sizeof(VkLayerProperties)));
174 if (num_instance_layers > 0) {
175 result = enumerate_instance_layers(&num_instance_layers, properties);
176 if (result != VK_SUCCESS) {
177 ALOGW(
178 "vkEnumerateInstanceLayerProperties failed for library '%s': "
179 "%d",
Chia-I Wu6693f5c2016-04-18 12:20:02 +0800180 path_.c_str(), result);
Chia-I Wu50174ee2016-04-18 16:33:20 +0800181 return false;
Jesse Hallaa410942016-01-17 13:07:10 -0800182 }
183 }
184 if (num_device_layers > 0) {
185 result = enumerate_device_layers(VK_NULL_HANDLE, &num_device_layers,
186 properties + num_instance_layers);
187 if (result != VK_SUCCESS) {
188 ALOGW(
189 "vkEnumerateDeviceLayerProperties failed for library '%s': %d",
Chia-I Wu6693f5c2016-04-18 12:20:02 +0800190 path_.c_str(), result);
Chia-I Wu50174ee2016-04-18 16:33:20 +0800191 return false;
Jesse Hallaa410942016-01-17 13:07:10 -0800192 }
Jesse Hall80523e22016-01-06 16:47:54 -0800193 }
194
Chia-I Wu50174ee2016-04-18 16:33:20 +0800195 size_t prev_num_instance_layers = instance_layers.size();
196 size_t prev_num_device_layers = device_layers.size();
197 instance_layers.reserve(prev_num_instance_layers + num_instance_layers);
198 device_layers.reserve(prev_num_device_layers + num_device_layers);
Jesse Hallaa410942016-01-17 13:07:10 -0800199 for (size_t i = 0; i < num_instance_layers; i++) {
200 const VkLayerProperties& props = properties[i];
201
Jesse Hall80523e22016-01-06 16:47:54 -0800202 Layer layer;
Jesse Hallaa410942016-01-17 13:07:10 -0800203 layer.properties = props;
Jesse Hall80523e22016-01-06 16:47:54 -0800204 layer.library_idx = library_idx;
205
Jesse Hallaa410942016-01-17 13:07:10 -0800206 if (enumerate_instance_extensions) {
207 uint32_t count = 0;
208 result =
209 enumerate_instance_extensions(props.layerName, &count, nullptr);
210 if (result != VK_SUCCESS) {
211 ALOGW(
212 "vkEnumerateInstanceExtensionProperties(%s) failed for "
Chia-I Wu50174ee2016-04-18 16:33:20 +0800213 "library '%s': %d",
Chia-I Wu6693f5c2016-04-18 12:20:02 +0800214 props.layerName, path_.c_str(), result);
Chia-I Wu50174ee2016-04-18 16:33:20 +0800215 instance_layers.resize(prev_num_instance_layers);
216 return false;
Jesse Hallaa410942016-01-17 13:07:10 -0800217 }
218 layer.extensions.resize(count);
219 result = enumerate_instance_extensions(props.layerName, &count,
220 layer.extensions.data());
221 if (result != VK_SUCCESS) {
222 ALOGW(
223 "vkEnumerateInstanceExtensionProperties(%s) failed for "
Chia-I Wu50174ee2016-04-18 16:33:20 +0800224 "library '%s': %d",
Chia-I Wu6693f5c2016-04-18 12:20:02 +0800225 props.layerName, path_.c_str(), result);
Chia-I Wu50174ee2016-04-18 16:33:20 +0800226 instance_layers.resize(prev_num_instance_layers);
227 return false;
Jesse Hallaa410942016-01-17 13:07:10 -0800228 }
Jesse Hall80523e22016-01-06 16:47:54 -0800229 }
230
Chia-I Wu50174ee2016-04-18 16:33:20 +0800231 instance_layers.push_back(layer);
Jesse Hallb1471272016-01-17 21:36:58 -0800232 ALOGV(" added instance layer '%s'", props.layerName);
Jesse Hallaa410942016-01-17 13:07:10 -0800233 }
234 for (size_t i = 0; i < num_device_layers; i++) {
235 const VkLayerProperties& props = properties[num_instance_layers + i];
236
237 Layer layer;
238 layer.properties = props;
239 layer.library_idx = library_idx;
240
241 if (enumerate_device_extensions) {
242 uint32_t count;
243 result = enumerate_device_extensions(
244 VK_NULL_HANDLE, props.layerName, &count, nullptr);
245 if (result != VK_SUCCESS) {
246 ALOGW(
247 "vkEnumerateDeviceExtensionProperties(%s) failed for "
Chia-I Wu50174ee2016-04-18 16:33:20 +0800248 "library '%s': %d",
Chia-I Wu6693f5c2016-04-18 12:20:02 +0800249 props.layerName, path_.c_str(), result);
Chia-I Wu50174ee2016-04-18 16:33:20 +0800250 instance_layers.resize(prev_num_instance_layers);
251 device_layers.resize(prev_num_device_layers);
252 return false;
Jesse Hallaa410942016-01-17 13:07:10 -0800253 }
254 layer.extensions.resize(count);
255 result =
256 enumerate_device_extensions(VK_NULL_HANDLE, props.layerName,
257 &count, layer.extensions.data());
258 if (result != VK_SUCCESS) {
259 ALOGW(
260 "vkEnumerateDeviceExtensionProperties(%s) failed for "
Chia-I Wu50174ee2016-04-18 16:33:20 +0800261 "library '%s': %d",
Chia-I Wu6693f5c2016-04-18 12:20:02 +0800262 props.layerName, path_.c_str(), result);
Chia-I Wu50174ee2016-04-18 16:33:20 +0800263 instance_layers.resize(prev_num_instance_layers);
264 device_layers.resize(prev_num_device_layers);
265 return false;
Jesse Hallaa410942016-01-17 13:07:10 -0800266 }
267 }
268
Chia-I Wu50174ee2016-04-18 16:33:20 +0800269 device_layers.push_back(layer);
Jesse Hallb1471272016-01-17 21:36:58 -0800270 ALOGV(" added device layer '%s'", props.layerName);
Jesse Hall80523e22016-01-06 16:47:54 -0800271 }
272
Chia-I Wu50174ee2016-04-18 16:33:20 +0800273 return true;
274}
Jesse Hall80523e22016-01-06 16:47:54 -0800275
Chia-I Wuba113272016-04-18 16:38:39 +0800276void* LayerLibrary::GetGPA(const Layer& layer,
277 const char* gpa_name,
278 size_t gpa_name_len) const {
279 void* gpa;
280 size_t layer_name_len =
281 std::max(size_t{2}, strlen(layer.properties.layerName));
282 char* name = static_cast<char*>(alloca(layer_name_len + gpa_name_len + 1));
283 strcpy(name, layer.properties.layerName);
284 strcpy(name + layer_name_len, gpa_name);
Chia-I Wu6693f5c2016-04-18 12:20:02 +0800285 if (!(gpa = dlsym(dlhandle_, name))) {
Chia-I Wuba113272016-04-18 16:38:39 +0800286 strcpy(name, "vk");
287 strcpy(name + 2, gpa_name);
Chia-I Wu6693f5c2016-04-18 12:20:02 +0800288 gpa = dlsym(dlhandle_, name);
Chia-I Wuba113272016-04-18 16:38:39 +0800289 }
290 return gpa;
291}
292
Chia-I Wu50174ee2016-04-18 16:33:20 +0800293std::vector<LayerLibrary> g_layer_libraries;
294std::vector<Layer> g_instance_layers;
295std::vector<Layer> g_device_layers;
296
297void AddLayerLibrary(const std::string& path) {
298 ALOGV("examining layer library '%s'", path.c_str());
299
300 LayerLibrary library(path);
301 if (!library.Open())
302 return;
303
304 if (!library.EnumerateLayers(g_layer_libraries.size(), g_instance_layers,
305 g_device_layers)) {
306 library.Close();
307 return;
308 }
309
310 library.Close();
311
312 g_layer_libraries.emplace_back(std::move(library));
Jesse Hall80523e22016-01-06 16:47:54 -0800313}
314
315void DiscoverLayersInDirectory(const std::string& dir_path) {
316 ALOGV("looking for layers in '%s'", dir_path.c_str());
317
318 DIR* directory = opendir(dir_path.c_str());
319 if (!directory) {
320 int err = errno;
321 ALOGV_IF(err != ENOENT, "failed to open layer directory '%s': %s (%d)",
322 dir_path.c_str(), strerror(err), err);
323 return;
324 }
325
326 std::string path;
327 path.reserve(dir_path.size() + 20);
328 path.append(dir_path);
329 path.append("/");
330
331 struct dirent* entry;
332 while ((entry = readdir(directory))) {
333 size_t libname_len = strlen(entry->d_name);
Jesse Halla7ac76d2016-01-08 22:29:42 -0800334 if (strncmp(entry->d_name, "libVkLayer", 10) != 0 ||
Jesse Hall80523e22016-01-06 16:47:54 -0800335 strncmp(entry->d_name + libname_len - 3, ".so", 3) != 0)
336 continue;
337 path.append(entry->d_name);
338 AddLayerLibrary(path);
339 path.resize(dir_path.size() + 1);
340 }
341
342 closedir(directory);
343}
344
345void* GetLayerGetProcAddr(const Layer& layer,
346 const char* gpa_name,
347 size_t gpa_name_len) {
348 const LayerLibrary& library = g_layer_libraries[layer.library_idx];
Chia-I Wuba113272016-04-18 16:38:39 +0800349 return library.GetGPA(layer, gpa_name, gpa_name_len);
Jesse Hall80523e22016-01-06 16:47:54 -0800350}
351
Jesse Hallaa410942016-01-17 13:07:10 -0800352uint32_t EnumerateLayers(const std::vector<Layer>& layers,
353 uint32_t count,
354 VkLayerProperties* properties) {
355 uint32_t n = std::min(count, static_cast<uint32_t>(layers.size()));
Jesse Hall80523e22016-01-06 16:47:54 -0800356 for (uint32_t i = 0; i < n; i++) {
Jesse Hallaa410942016-01-17 13:07:10 -0800357 properties[i] = layers[i].properties;
Jesse Hall80523e22016-01-06 16:47:54 -0800358 }
Jesse Hallaa410942016-01-17 13:07:10 -0800359 return static_cast<uint32_t>(layers.size());
Jesse Hall80523e22016-01-06 16:47:54 -0800360}
361
Jesse Hallaa410942016-01-17 13:07:10 -0800362void GetLayerExtensions(const std::vector<Layer>& layers,
363 const char* name,
Jesse Hall80523e22016-01-06 16:47:54 -0800364 const VkExtensionProperties** properties,
365 uint32_t* count) {
Jesse Hallaa410942016-01-17 13:07:10 -0800366 auto layer =
367 std::find_if(layers.cbegin(), layers.cend(), [=](const Layer& entry) {
368 return strcmp(entry.properties.layerName, name) == 0;
369 });
370 if (layer == layers.cend()) {
371 *properties = nullptr;
372 *count = 0;
373 } else {
374 *properties = layer->extensions.data();
375 *count = static_cast<uint32_t>(layer->extensions.size());
Jesse Hall80523e22016-01-06 16:47:54 -0800376 }
377}
378
Jesse Hallaa410942016-01-17 13:07:10 -0800379LayerRef GetLayerRef(std::vector<Layer>& layers, const char* name) {
380 for (uint32_t id = 0; id < layers.size(); id++) {
Michael Lentined0b7cb52016-01-19 13:57:26 -0600381 if (strcmp(name, layers[id].properties.layerName) == 0) {
Jesse Hallaa410942016-01-17 13:07:10 -0800382 LayerLibrary& library = g_layer_libraries[layers[id].library_idx];
Chia-I Wufd0389f2016-04-18 12:11:00 +0800383 return LayerRef((library.Open()) ? &layers[id] : nullptr);
Jesse Hall80523e22016-01-06 16:47:54 -0800384 }
385 }
386 return LayerRef(nullptr);
387}
388
Jesse Hallaa410942016-01-17 13:07:10 -0800389} // anonymous namespace
390
Jesse Hallaa410942016-01-17 13:07:10 -0800391void DiscoverLayers() {
392 if (prctl(PR_GET_DUMPABLE, 0, 0, 0, 0))
393 DiscoverLayersInDirectory("/data/local/debug/vulkan");
394 if (!LoaderData::GetInstance().layer_path.empty())
395 DiscoverLayersInDirectory(LoaderData::GetInstance().layer_path.c_str());
396}
397
398uint32_t EnumerateInstanceLayers(uint32_t count,
399 VkLayerProperties* properties) {
400 return EnumerateLayers(g_instance_layers, count, properties);
401}
402
403uint32_t EnumerateDeviceLayers(uint32_t count, VkLayerProperties* properties) {
404 return EnumerateLayers(g_device_layers, count, properties);
405}
406
407void GetInstanceLayerExtensions(const char* name,
408 const VkExtensionProperties** properties,
409 uint32_t* count) {
410 GetLayerExtensions(g_instance_layers, name, properties, count);
411}
412
413void GetDeviceLayerExtensions(const char* name,
414 const VkExtensionProperties** properties,
415 uint32_t* count) {
416 GetLayerExtensions(g_device_layers, name, properties, count);
417}
418
419LayerRef GetInstanceLayerRef(const char* name) {
420 return GetLayerRef(g_instance_layers, name);
421}
422
423LayerRef GetDeviceLayerRef(const char* name) {
424 return GetLayerRef(g_device_layers, name);
425}
426
Jesse Hall80523e22016-01-06 16:47:54 -0800427LayerRef::LayerRef(Layer* layer) : layer_(layer) {}
428
429LayerRef::~LayerRef() {
430 if (layer_) {
431 LayerLibrary& library = g_layer_libraries[layer_->library_idx];
Chia-I Wud91c74f2016-04-18 12:12:36 +0800432 library.Close();
Jesse Hall80523e22016-01-06 16:47:54 -0800433 }
434}
435
Michael Lentine57036832016-03-04 11:03:35 -0600436const char* LayerRef::GetName() const {
Courtney Goeltzenleuchtereff63112016-02-08 20:12:59 -0700437 return layer_->properties.layerName;
438}
439
440uint32_t LayerRef::GetSpecVersion() {
441 return layer_->properties.specVersion;
442}
443
Michael Lentine54e6f082016-01-20 11:25:28 -0600444LayerRef::LayerRef(LayerRef&& other) : layer_(std::move(other.layer_)) {
445 other.layer_ = nullptr;
446}
Jesse Hall80523e22016-01-06 16:47:54 -0800447
448PFN_vkGetInstanceProcAddr LayerRef::GetGetInstanceProcAddr() const {
449 return layer_ ? reinterpret_cast<PFN_vkGetInstanceProcAddr>(
450 GetLayerGetProcAddr(*layer_, "GetInstanceProcAddr", 19))
451 : nullptr;
452}
453
454PFN_vkGetDeviceProcAddr LayerRef::GetGetDeviceProcAddr() const {
455 return layer_ ? reinterpret_cast<PFN_vkGetDeviceProcAddr>(
456 GetLayerGetProcAddr(*layer_, "GetDeviceProcAddr", 17))
457 : nullptr;
458}
459
Jesse Hallb1471272016-01-17 21:36:58 -0800460bool LayerRef::SupportsExtension(const char* name) const {
461 return std::find_if(layer_->extensions.cbegin(), layer_->extensions.cend(),
462 [=](const VkExtensionProperties& ext) {
463 return strcmp(ext.extensionName, name) == 0;
464 }) != layer_->extensions.cend();
465}
466
Chia-I Wuc96880f2016-03-26 06:56:45 +0800467} // namespace api
Jesse Hall80523e22016-01-06 16:47:54 -0800468} // namespace vulkan