Mark Lobodzinski | 317574e | 2016-08-29 14:21:14 -0600 | [diff] [blame] | 1 | /* |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 2 | * |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3 | * Copyright (c) 2014-2017 The Khronos Group Inc. |
| 4 | * Copyright (c) 2014-2017 Valve Corporation |
| 5 | * Copyright (c) 2014-2017 LunarG, Inc. |
Courtney Goeltzenleuchter | f821dad | 2015-12-02 14:53:22 -0700 | [diff] [blame] | 6 | * Copyright (C) 2015 Google Inc. |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 7 | * |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 8 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 | * you may not use this file except in compliance with the License. |
| 10 | * You may obtain a copy of the License at |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 11 | * |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 12 | * http://www.apache.org/licenses/LICENSE-2.0 |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 13 | * |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 14 | * Unless required by applicable law or agreed to in writing, software |
| 15 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 | * See the License for the specific language governing permissions and |
| 18 | * limitations under the License. |
| 19 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 20 | * |
Courtney Goeltzenleuchter | 0555952 | 2015-10-30 11:14:30 -0600 | [diff] [blame] | 21 | * Author: Jon Ashburn <jon@lunarg.com> |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 22 | * Author: Courtney Goeltzenleuchter <courtney@LunarG.com> |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 23 | * Author: Mark Young <marky@lunarg.com> |
Courtney Goeltzenleuchter | 0555952 | 2015-10-30 11:14:30 -0600 | [diff] [blame] | 24 | * |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 25 | */ |
Mark Lobodzinski | faa9081 | 2015-11-25 13:26:15 -0700 | [diff] [blame] | 26 | |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 27 | #define _GNU_SOURCE |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 28 | #include <stdio.h> |
| 29 | #include <stdlib.h> |
| 30 | #include <stdarg.h> |
| 31 | #include <stdbool.h> |
| 32 | #include <string.h> |
Benjamin Saunders | 31a4801 | 2017-01-29 14:49:54 -0800 | [diff] [blame] | 33 | #include <stddef.h> |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 34 | |
Chia-I Wu | 13a61a5 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 35 | #include <sys/types.h> |
Johannes van Waveren | 9bd80501 | 2015-10-28 11:45:00 -0500 | [diff] [blame] | 36 | #if defined(_WIN32) |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 37 | #include "dirent_on_windows.h" |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 38 | #else // _WIN32 |
Chia-I Wu | 13a61a5 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 39 | #include <dirent.h> |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 40 | #endif // _WIN32 |
Tobin Ehlis | b835d1b | 2015-07-03 10:34:49 -0600 | [diff] [blame] | 41 | #include "vk_loader_platform.h" |
Chia-I Wu | 1930060 | 2014-08-04 08:03:57 +0800 | [diff] [blame] | 42 | #include "loader.h" |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 43 | #include "gpa_helper.h" |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 44 | #include "debug_report.h" |
Ian Elliott | 954fa34 | 2015-10-30 15:28:23 -0600 | [diff] [blame] | 45 | #include "wsi.h" |
David Pinedo | 9316d3b | 2015-11-06 12:54:48 -0700 | [diff] [blame] | 46 | #include "vulkan/vk_icd.h" |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 47 | #include "cJSON.h" |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 48 | #include "murmurhash.h" |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 49 | |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 50 | #if defined(_WIN32) |
| 51 | #include <Cfgmgr32.h> |
| 52 | #include <initguid.h> |
| 53 | #include <Devpkey.h> |
| 54 | #endif |
| 55 | |
Mark Young | ba7ee02 | 2017-03-09 10:41:25 -0700 | [diff] [blame] | 56 | // This is a CMake generated file with #defines for any functions/includes |
| 57 | // that it found present. This is currently necessary to properly determine |
| 58 | // if secure_getenv or __secure_getenv are present |
Jamie Madill | e09268a | 2017-03-21 13:48:13 -0400 | [diff] [blame] | 59 | #if !defined(VULKAN_NON_CMAKE_BUILD) |
Mark Young | ba7ee02 | 2017-03-09 10:41:25 -0700 | [diff] [blame] | 60 | #include "loader_cmake_config.h" |
Jamie Madill | e09268a | 2017-03-21 13:48:13 -0400 | [diff] [blame] | 61 | #endif // !defined(VULKAN_NON_CMAKE_BUILD) |
Mark Young | ba7ee02 | 2017-03-09 10:41:25 -0700 | [diff] [blame] | 62 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 63 | // Generated file containing all the extension data |
| 64 | #include "vk_loader_extensions.c" |
| 65 | |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 66 | struct loader_struct loader = {0}; |
Jon Ashburn | 87d6aa9 | 2015-08-28 15:19:27 -0600 | [diff] [blame] | 67 | // TLS for instance for alloc/free callbacks |
| 68 | THREAD_LOCAL_DECL struct loader_instance *tls_instance; |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 69 | |
Courtney Goeltzenleuchter | 0ef13a0 | 2015-12-16 16:19:46 -0700 | [diff] [blame] | 70 | static size_t loader_platform_combine_path(char *dest, size_t len, ...); |
Daniel Dadap | 00b4aba | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 71 | |
Jon Ashburn | 24cd4be | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 72 | struct loader_phys_dev_per_icd { |
| 73 | uint32_t count; |
| 74 | VkPhysicalDevice *phys_devs; |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 75 | struct loader_icd_term *this_icd_term; |
Jon Ashburn | 24cd4be | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 76 | }; |
| 77 | |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 78 | enum loader_debug { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 79 | LOADER_INFO_BIT = 0x01, |
| 80 | LOADER_WARN_BIT = 0x02, |
| 81 | LOADER_PERF_BIT = 0x04, |
| 82 | LOADER_ERROR_BIT = 0x08, |
| 83 | LOADER_DEBUG_BIT = 0x10, |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 84 | }; |
| 85 | |
| 86 | uint32_t g_loader_debug = 0; |
| 87 | uint32_t g_loader_log_msgs = 0; |
| 88 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 89 | // thread safety lock for accessing global data structures such as "loader" |
Jon Ashburn | 6301a0f | 2015-05-29 13:15:39 -0600 | [diff] [blame] | 90 | // all entrypoints on the instance chain need to be locked except GPA |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 91 | // additionally CreateDevice and DestroyDevice needs to be locked |
Jon Ashburn | 6301a0f | 2015-05-29 13:15:39 -0600 | [diff] [blame] | 92 | loader_platform_thread_mutex loader_lock; |
Jon Ashburn | 6461ef2 | 2015-09-22 13:11:00 -0600 | [diff] [blame] | 93 | loader_platform_thread_mutex loader_json_lock; |
Jon Ashburn | 6301a0f | 2015-05-29 13:15:39 -0600 | [diff] [blame] | 94 | |
Jon Ashburn | 8810c5f | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 95 | LOADER_PLATFORM_THREAD_ONCE_DECLARATION(once_init); |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 96 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 97 | void *loader_instance_heap_alloc(const struct loader_instance *instance, size_t size, VkSystemAllocationScope alloc_scope) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 98 | void *pMemory = NULL; |
| 99 | #if (DEBUG_DISABLE_APP_ALLOCATORS == 1) |
| 100 | { |
| 101 | #else |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 102 | if (instance && instance->alloc_callbacks.pfnAllocation) { |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 103 | // These are internal structures, so it's best to align everything to |
| 104 | // the largest unit size which is the size of a uint64_t. |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 105 | pMemory = instance->alloc_callbacks.pfnAllocation(instance->alloc_callbacks.pUserData, size, sizeof(uint64_t), alloc_scope); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 106 | } else { |
| 107 | #endif |
| 108 | pMemory = malloc(size); |
Courtney Goeltzenleuchter | 7f5aafc | 2015-07-05 11:28:29 -0600 | [diff] [blame] | 109 | } |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 110 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 111 | return pMemory; |
Courtney Goeltzenleuchter | 7f5aafc | 2015-07-05 11:28:29 -0600 | [diff] [blame] | 112 | } |
| 113 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 114 | void loader_instance_heap_free(const struct loader_instance *instance, void *pMemory) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 115 | if (pMemory != NULL) { |
| 116 | #if (DEBUG_DISABLE_APP_ALLOCATORS == 1) |
| 117 | { |
| 118 | #else |
| 119 | if (instance && instance->alloc_callbacks.pfnFree) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 120 | instance->alloc_callbacks.pfnFree(instance->alloc_callbacks.pUserData, pMemory); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 121 | } else { |
| 122 | #endif |
| 123 | free(pMemory); |
Mark Young | d077f99 | 2016-06-30 11:03:59 -0600 | [diff] [blame] | 124 | } |
Mark Young | 4b0b922 | 2016-06-29 18:33:53 -0600 | [diff] [blame] | 125 | } |
Mark Young | 4b0b922 | 2016-06-29 18:33:53 -0600 | [diff] [blame] | 126 | } |
| 127 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 128 | void *loader_instance_heap_realloc(const struct loader_instance *instance, void *pMemory, size_t orig_size, size_t size, |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 129 | VkSystemAllocationScope alloc_scope) { |
| 130 | void *pNewMem = NULL; |
| 131 | if (pMemory == NULL || orig_size == 0) { |
| 132 | pNewMem = loader_instance_heap_alloc(instance, size, alloc_scope); |
| 133 | } else if (size == 0) { |
| 134 | loader_instance_heap_free(instance, pMemory); |
| 135 | #if (DEBUG_DISABLE_APP_ALLOCATORS == 1) |
| 136 | #else |
| 137 | } else if (instance && instance->alloc_callbacks.pfnReallocation) { |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 138 | // These are internal structures, so it's best to align everything to |
| 139 | // the largest unit size which is the size of a uint64_t. |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 140 | pNewMem = instance->alloc_callbacks.pfnReallocation(instance->alloc_callbacks.pUserData, pMemory, size, sizeof(uint64_t), |
| 141 | alloc_scope); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 142 | #endif |
| 143 | } else { |
| 144 | pNewMem = realloc(pMemory, size); |
| 145 | } |
| 146 | return pNewMem; |
Mark Young | 4b0b922 | 2016-06-29 18:33:53 -0600 | [diff] [blame] | 147 | } |
| 148 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 149 | void *loader_instance_tls_heap_alloc(size_t size) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 150 | return loader_instance_heap_alloc(tls_instance, size, VK_SYSTEM_ALLOCATION_SCOPE_COMMAND); |
Mark Young | 4b0b922 | 2016-06-29 18:33:53 -0600 | [diff] [blame] | 151 | } |
Mark Young | 4b0b922 | 2016-06-29 18:33:53 -0600 | [diff] [blame] | 152 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 153 | void loader_instance_tls_heap_free(void *pMemory) { loader_instance_heap_free(tls_instance, pMemory); } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 154 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 155 | void *loader_device_heap_alloc(const struct loader_device *device, size_t size, VkSystemAllocationScope alloc_scope) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 156 | void *pMemory = NULL; |
| 157 | #if (DEBUG_DISABLE_APP_ALLOCATORS == 1) |
| 158 | { |
| 159 | #else |
| 160 | if (device && device->alloc_callbacks.pfnAllocation) { |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 161 | // These are internal structures, so it's best to align everything to |
| 162 | // the largest unit size which is the size of a uint64_t. |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 163 | pMemory = device->alloc_callbacks.pfnAllocation(device->alloc_callbacks.pUserData, size, sizeof(uint64_t), alloc_scope); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 164 | } else { |
| 165 | #endif |
| 166 | pMemory = malloc(size); |
| 167 | } |
| 168 | return pMemory; |
| 169 | } |
| 170 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 171 | void loader_device_heap_free(const struct loader_device *device, void *pMemory) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 172 | if (pMemory != NULL) { |
| 173 | #if (DEBUG_DISABLE_APP_ALLOCATORS == 1) |
| 174 | { |
| 175 | #else |
| 176 | if (device && device->alloc_callbacks.pfnFree) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 177 | device->alloc_callbacks.pfnFree(device->alloc_callbacks.pUserData, pMemory); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 178 | } else { |
| 179 | #endif |
| 180 | free(pMemory); |
| 181 | } |
| 182 | } |
| 183 | } |
| 184 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 185 | void *loader_device_heap_realloc(const struct loader_device *device, void *pMemory, size_t orig_size, size_t size, |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 186 | VkSystemAllocationScope alloc_scope) { |
| 187 | void *pNewMem = NULL; |
| 188 | if (pMemory == NULL || orig_size == 0) { |
| 189 | pNewMem = loader_device_heap_alloc(device, size, alloc_scope); |
| 190 | } else if (size == 0) { |
| 191 | loader_device_heap_free(device, pMemory); |
| 192 | #if (DEBUG_DISABLE_APP_ALLOCATORS == 1) |
| 193 | #else |
| 194 | } else if (device && device->alloc_callbacks.pfnReallocation) { |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 195 | // These are internal structures, so it's best to align everything to |
| 196 | // the largest unit size which is the size of a uint64_t. |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 197 | pNewMem = device->alloc_callbacks.pfnReallocation(device->alloc_callbacks.pUserData, pMemory, size, sizeof(uint64_t), |
| 198 | alloc_scope); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 199 | #endif |
| 200 | } else { |
| 201 | pNewMem = realloc(pMemory, size); |
| 202 | } |
| 203 | return pNewMem; |
| 204 | } |
| 205 | |
| 206 | // Environment variables |
| 207 | #if defined(__linux__) |
| 208 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 209 | static inline char *loader_getenv(const char *name, const struct loader_instance *inst) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 210 | // No allocation of memory necessary for Linux, but we should at least touch |
| 211 | // the inst pointer to get rid of compiler warnings. |
| 212 | (void)inst; |
Mark Young | d8c6b69 | 2017-03-09 11:39:41 -0700 | [diff] [blame] | 213 | return getenv(name); |
| 214 | } |
| 215 | |
Mark Young | d8c6b69 | 2017-03-09 11:39:41 -0700 | [diff] [blame] | 216 | static inline char *loader_secure_getenv(const char *name, const struct loader_instance *inst) { |
| 217 | // No allocation of memory necessary for Linux, but we should at least touch |
| 218 | // the inst pointer to get rid of compiler warnings. |
| 219 | (void)inst; |
Mark Young | f2f2a66 | 2017-03-08 10:11:52 -0700 | [diff] [blame] | 220 | |
Mark Young | ba7ee02 | 2017-03-09 10:41:25 -0700 | [diff] [blame] | 221 | #ifdef HAVE_SECURE_GETENV |
| 222 | return secure_getenv(name); |
| 223 | #elif defined(HAVE___SECURE_GETENV) |
Mark Young | f2f2a66 | 2017-03-08 10:11:52 -0700 | [diff] [blame] | 224 | return __secure_getenv(name); |
| 225 | #else |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 226 | #pragma message( \ |
| 227 | "Warning: Falling back to non-secure getenv for environmental lookups! Consider" \ |
| 228 | " updating to a different libc.") |
Mark Young | d8c6b69 | 2017-03-09 11:39:41 -0700 | [diff] [blame] | 229 | return loader_getenv(name, inst); |
Mark Young | f2f2a66 | 2017-03-08 10:11:52 -0700 | [diff] [blame] | 230 | #endif |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 231 | } |
Mark Young | f2f2a66 | 2017-03-08 10:11:52 -0700 | [diff] [blame] | 232 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 233 | static inline void loader_free_getenv(char *val, const struct loader_instance *inst) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 234 | // No freeing of memory necessary for Linux, but we should at least touch |
| 235 | // the val and inst pointers to get rid of compiler warnings. |
| 236 | (void)val; |
| 237 | (void)inst; |
| 238 | } |
| 239 | |
| 240 | #elif defined(WIN32) |
| 241 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 242 | static inline char *loader_getenv(const char *name, const struct loader_instance *inst) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 243 | char *retVal; |
| 244 | DWORD valSize; |
| 245 | |
| 246 | valSize = GetEnvironmentVariableA(name, NULL, 0); |
| 247 | |
| 248 | // valSize DOES include the null terminator, so for any set variable |
| 249 | // will always be at least 1. If it's 0, the variable wasn't set. |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 250 | if (valSize == 0) return NULL; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 251 | |
| 252 | // Allocate the space necessary for the registry entry |
| 253 | if (NULL != inst && NULL != inst->alloc_callbacks.pfnAllocation) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 254 | retVal = (char *)inst->alloc_callbacks.pfnAllocation(inst->alloc_callbacks.pUserData, valSize, sizeof(char *), |
| 255 | VK_SYSTEM_ALLOCATION_SCOPE_COMMAND); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 256 | } else { |
| 257 | retVal = (char *)malloc(valSize); |
| 258 | } |
| 259 | |
| 260 | if (NULL != retVal) { |
| 261 | GetEnvironmentVariableA(name, retVal, valSize); |
| 262 | } |
| 263 | |
| 264 | return retVal; |
| 265 | } |
| 266 | |
Mark Young | d8c6b69 | 2017-03-09 11:39:41 -0700 | [diff] [blame] | 267 | static inline char *loader_secure_getenv(const char *name, const struct loader_instance *inst) { |
Mark Young | bb3a29c | 2017-05-19 12:29:43 -0600 | [diff] [blame] | 268 | // No secure version for Windows as far as I know |
Mark Young | d8c6b69 | 2017-03-09 11:39:41 -0700 | [diff] [blame] | 269 | return loader_getenv(name, inst); |
| 270 | } |
| 271 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 272 | static inline void loader_free_getenv(char *val, const struct loader_instance *inst) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 273 | if (NULL != inst && NULL != inst->alloc_callbacks.pfnFree) { |
| 274 | inst->alloc_callbacks.pfnFree(inst->alloc_callbacks.pUserData, val); |
| 275 | } else { |
| 276 | free((void *)val); |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | #else |
| 281 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 282 | static inline char *loader_getenv(const char *name, const struct loader_instance *inst) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 283 | // stub func |
| 284 | (void)inst; |
| 285 | (void)name; |
| 286 | return NULL; |
| 287 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 288 | static inline void loader_free_getenv(char *val, const struct loader_instance *inst) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 289 | // stub func |
| 290 | (void)val; |
| 291 | (void)inst; |
| 292 | } |
| 293 | |
| 294 | #endif |
| 295 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 296 | void loader_log(const struct loader_instance *inst, VkFlags msg_type, int32_t msg_code, const char *format, ...) { |
Jon Ashburn | 86723b0 | 2015-07-31 15:47:59 -0600 | [diff] [blame] | 297 | char msg[512]; |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 298 | char cmd_line_msg[512]; |
Mark Young | 5de3af7 | 2017-04-25 08:08:29 -0600 | [diff] [blame] | 299 | size_t cmd_line_size = sizeof(cmd_line_msg); |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 300 | va_list ap; |
| 301 | int ret; |
| 302 | |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 303 | va_start(ap, format); |
| 304 | ret = vsnprintf(msg, sizeof(msg), format, ap); |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 305 | if ((ret >= (int)sizeof(msg)) || ret < 0) { |
| 306 | msg[sizeof(msg) - 1] = '\0'; |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 307 | } |
| 308 | va_end(ap); |
| 309 | |
Courtney Goeltzenleuchter | 7347739 | 2015-12-03 13:48:01 -0700 | [diff] [blame] | 310 | if (inst) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 311 | util_DebugReportMessage(inst, msg_type, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, (uint64_t)(uintptr_t)inst, 0, msg_code, |
| 312 | "loader", msg); |
Courtney Goeltzenleuchter | 7347739 | 2015-12-03 13:48:01 -0700 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | if (!(msg_type & g_loader_log_msgs)) { |
| 316 | return; |
| 317 | } |
| 318 | |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 319 | cmd_line_msg[0] = '\0'; |
Mark Young | 5de3af7 | 2017-04-25 08:08:29 -0600 | [diff] [blame] | 320 | cmd_line_size -= 1; |
| 321 | size_t original_size = cmd_line_size; |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 322 | |
| 323 | va_start(ap, format); |
| 324 | if ((msg_type & LOADER_INFO_BIT) != 0) { |
Mark Young | 6ef95f4 | 2017-02-17 09:02:23 -0700 | [diff] [blame] | 325 | strncat(cmd_line_msg, "INFO", cmd_line_size); |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 326 | cmd_line_size -= 4; |
| 327 | } |
| 328 | if ((msg_type & LOADER_WARN_BIT) != 0) { |
Mark Young | 5de3af7 | 2017-04-25 08:08:29 -0600 | [diff] [blame] | 329 | if (cmd_line_size != original_size) { |
Mark Young | 6ef95f4 | 2017-02-17 09:02:23 -0700 | [diff] [blame] | 330 | strncat(cmd_line_msg, " | ", cmd_line_size); |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 331 | cmd_line_size -= 3; |
| 332 | } |
Mark Young | 6ef95f4 | 2017-02-17 09:02:23 -0700 | [diff] [blame] | 333 | strncat(cmd_line_msg, "WARNING", cmd_line_size); |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 334 | cmd_line_size -= 7; |
| 335 | } |
| 336 | if ((msg_type & LOADER_PERF_BIT) != 0) { |
Mark Young | 5de3af7 | 2017-04-25 08:08:29 -0600 | [diff] [blame] | 337 | if (cmd_line_size != original_size) { |
Mark Young | 6ef95f4 | 2017-02-17 09:02:23 -0700 | [diff] [blame] | 338 | strncat(cmd_line_msg, " | ", cmd_line_size); |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 339 | cmd_line_size -= 3; |
| 340 | } |
Mark Young | 6ef95f4 | 2017-02-17 09:02:23 -0700 | [diff] [blame] | 341 | strncat(cmd_line_msg, "PERF", cmd_line_size); |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 342 | cmd_line_size -= 4; |
| 343 | } |
| 344 | if ((msg_type & LOADER_ERROR_BIT) != 0) { |
Mark Young | 5de3af7 | 2017-04-25 08:08:29 -0600 | [diff] [blame] | 345 | if (cmd_line_size != original_size) { |
Mark Young | 6ef95f4 | 2017-02-17 09:02:23 -0700 | [diff] [blame] | 346 | strncat(cmd_line_msg, " | ", cmd_line_size); |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 347 | cmd_line_size -= 3; |
| 348 | } |
Mark Young | 6ef95f4 | 2017-02-17 09:02:23 -0700 | [diff] [blame] | 349 | strncat(cmd_line_msg, "ERROR", cmd_line_size); |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 350 | cmd_line_size -= 5; |
| 351 | } |
| 352 | if ((msg_type & LOADER_DEBUG_BIT) != 0) { |
Mark Young | 5de3af7 | 2017-04-25 08:08:29 -0600 | [diff] [blame] | 353 | if (cmd_line_size != original_size) { |
Mark Young | 6ef95f4 | 2017-02-17 09:02:23 -0700 | [diff] [blame] | 354 | strncat(cmd_line_msg, " | ", cmd_line_size); |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 355 | cmd_line_size -= 3; |
| 356 | } |
Mark Young | 6ef95f4 | 2017-02-17 09:02:23 -0700 | [diff] [blame] | 357 | strncat(cmd_line_msg, "DEBUG", cmd_line_size); |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 358 | cmd_line_size -= 5; |
| 359 | } |
Mark Young | 5de3af7 | 2017-04-25 08:08:29 -0600 | [diff] [blame] | 360 | if (cmd_line_size != original_size) { |
Mark Young | 6ef95f4 | 2017-02-17 09:02:23 -0700 | [diff] [blame] | 361 | strncat(cmd_line_msg, ": ", cmd_line_size); |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 362 | cmd_line_size -= 2; |
| 363 | } |
Mark Young | 5de3af7 | 2017-04-25 08:08:29 -0600 | [diff] [blame] | 364 | |
| 365 | if (0 < cmd_line_size) { |
| 366 | // If the message is too long, trim it down |
| 367 | if (strlen(msg) > cmd_line_size) { |
| 368 | msg[cmd_line_size - 1] = '\0'; |
| 369 | } |
| 370 | strncat(cmd_line_msg, msg, cmd_line_size); |
| 371 | } else { |
| 372 | // Shouldn't get here, but check to make sure if we've already overrun |
| 373 | // the string boundary |
| 374 | assert(false); |
| 375 | } |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 376 | |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 377 | #if defined(WIN32) |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 378 | OutputDebugString(cmd_line_msg); |
mschott | b9cdb78 | 2015-07-22 14:11:29 +0200 | [diff] [blame] | 379 | OutputDebugString("\n"); |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 380 | #endif |
Mark Young | 5de3af7 | 2017-04-25 08:08:29 -0600 | [diff] [blame] | 381 | |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 382 | fputs(cmd_line_msg, stderr); |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 383 | fputc('\n', stderr); |
| 384 | } |
| 385 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 386 | VKAPI_ATTR VkResult VKAPI_CALL vkSetInstanceDispatch(VkInstance instance, void *object) { |
Jon Ashburn | c3c5877 | 2016-03-29 11:16:01 -0600 | [diff] [blame] | 387 | struct loader_instance *inst = loader_get_instance(instance); |
| 388 | if (!inst) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 389 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 390 | "vkSetInstanceDispatch: Can not retrieve Instance " |
| 391 | "dispatch table."); |
Jon Ashburn | c3c5877 | 2016-03-29 11:16:01 -0600 | [diff] [blame] | 392 | return VK_ERROR_INITIALIZATION_FAILED; |
| 393 | } |
| 394 | loader_set_dispatch(object, inst->disp); |
| 395 | return VK_SUCCESS; |
| 396 | } |
| 397 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 398 | VKAPI_ATTR VkResult VKAPI_CALL vkSetDeviceDispatch(VkDevice device, void *object) { |
Jon Ashburn | ed8f231 | 2016-03-31 10:52:22 -0600 | [diff] [blame] | 399 | struct loader_device *dev; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 400 | struct loader_icd_term *icd_term = loader_get_icd_and_device(device, &dev, NULL); |
Jon Ashburn | ed8f231 | 2016-03-31 10:52:22 -0600 | [diff] [blame] | 401 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 402 | if (NULL == icd_term) { |
Jon Ashburn | ed8f231 | 2016-03-31 10:52:22 -0600 | [diff] [blame] | 403 | return VK_ERROR_INITIALIZATION_FAILED; |
| 404 | } |
| 405 | loader_set_dispatch(object, &dev->loader_dispatch); |
| 406 | return VK_SUCCESS; |
| 407 | } |
| 408 | |
Lenny Komow | f7c0938 | 2017-08-31 16:35:08 -0600 | [diff] [blame] | 409 | #if defined(_WIN32) |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 410 | // Find the list of registry files (names VulkanDriverName/VulkanDriverNameWow) in hkr. |
| 411 | // |
| 412 | // This function looks for filename in given device handle, filename is then added to return list |
| 413 | // function return true if filename was appended to reg_data list |
| 414 | // If error occures result is updated with failure reason |
Lenny Komow | f7c0938 | 2017-08-31 16:35:08 -0600 | [diff] [blame] | 415 | bool loaderGetDeviceRegistryEntry(const struct loader_instance *inst, char **reg_data, PDWORD total_size, DEVINST dev_id, LPCTSTR value_name, VkResult *result) |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 416 | { |
| 417 | HKEY hkrKey = INVALID_HANDLE_VALUE; |
Lenny Komow | f7c0938 | 2017-08-31 16:35:08 -0600 | [diff] [blame] | 418 | DWORD requiredSize, data_type; |
| 419 | char *manifest_path = NULL; |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 420 | bool found = false; |
| 421 | |
| 422 | if (NULL == total_size || NULL == reg_data) { |
| 423 | *result = VK_ERROR_INITIALIZATION_FAILED; |
| 424 | return false; |
| 425 | } |
| 426 | |
Lenny Komow | f7c0938 | 2017-08-31 16:35:08 -0600 | [diff] [blame] | 427 | CONFIGRET status = CM_Open_DevNode_Key(dev_id, KEY_QUERY_VALUE, 0, RegDisposition_OpenExisting, &hkrKey, CM_REGISTRY_SOFTWARE); |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 428 | if (status != CR_SUCCESS) { |
| 429 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
Lenny Komow | f7c0938 | 2017-08-31 16:35:08 -0600 | [diff] [blame] | 430 | "loaderGetDeviceRegistryEntry: Failed to open registry key for DeviceID(%d)", dev_id); |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 431 | *result = VK_ERROR_INITIALIZATION_FAILED; |
| 432 | return false; |
| 433 | } |
| 434 | |
| 435 | // query value |
| 436 | LSTATUS ret = RegQueryValueEx( |
| 437 | hkrKey, |
Lenny Komow | f7c0938 | 2017-08-31 16:35:08 -0600 | [diff] [blame] | 438 | value_name, |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 439 | NULL, |
| 440 | NULL, |
| 441 | NULL, |
| 442 | &requiredSize); |
| 443 | |
| 444 | if (ret != ERROR_SUCCESS) { |
Lenny Komow | f7c0938 | 2017-08-31 16:35:08 -0600 | [diff] [blame] | 445 | if (ret == ERROR_FILE_NOT_FOUND) { |
| 446 | loader_log(inst, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, |
| 447 | "loaderGetDeviceRegistryEntry: Device ID(%d) Does not contain a value for \"%s\"", dev_id, value_name); |
| 448 | } else { |
| 449 | loader_log(inst, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, |
| 450 | "loaderGetDeviceRegistryEntry: DeviceID(%d) Failed to obtain %s size", dev_id, value_name); |
| 451 | } |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 452 | goto out; |
| 453 | } |
| 454 | |
Lenny Komow | f7c0938 | 2017-08-31 16:35:08 -0600 | [diff] [blame] | 455 | manifest_path = loader_instance_heap_alloc(inst, requiredSize, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
| 456 | if (manifest_path == NULL) { |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 457 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 458 | "loaderGetDeviceRegistryEntry: Failed to allocate space for DriverName."); |
| 459 | *result = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 460 | goto out; |
| 461 | } |
| 462 | |
| 463 | ret = RegQueryValueEx( |
| 464 | hkrKey, |
Lenny Komow | f7c0938 | 2017-08-31 16:35:08 -0600 | [diff] [blame] | 465 | value_name, |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 466 | NULL, |
Lenny Komow | f7c0938 | 2017-08-31 16:35:08 -0600 | [diff] [blame] | 467 | &data_type, |
Jamie Madill | a11ae0b | 2017-11-08 14:48:32 -0500 | [diff] [blame] | 468 | (BYTE *)manifest_path, |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 469 | &requiredSize |
| 470 | ); |
| 471 | |
| 472 | if (ret != ERROR_SUCCESS) { |
| 473 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Lenny Komow | f7c0938 | 2017-08-31 16:35:08 -0600 | [diff] [blame] | 474 | "loaderGetDeviceRegistryEntry: DeviceID(%d) Failed to obtain %s", value_name); |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 475 | |
| 476 | *result = VK_ERROR_INITIALIZATION_FAILED; |
| 477 | goto out; |
| 478 | } |
| 479 | |
Lenny Komow | f7c0938 | 2017-08-31 16:35:08 -0600 | [diff] [blame] | 480 | if (data_type != REG_SZ && data_type != REG_MULTI_SZ) { |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 481 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Lenny Komow | f7c0938 | 2017-08-31 16:35:08 -0600 | [diff] [blame] | 482 | "loaderGetDeviceRegistryEntry: Invalid %s data type. Expected REG_SZ or REG_MULTI_SZ.", value_name); |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 483 | *result = VK_ERROR_INITIALIZATION_FAILED; |
| 484 | goto out; |
| 485 | } |
| 486 | |
| 487 | if (NULL == *reg_data) { |
| 488 | *reg_data = loader_instance_heap_alloc(inst, *total_size, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
| 489 | if (NULL == *reg_data) { |
| 490 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Lenny Komow | f7c0938 | 2017-08-31 16:35:08 -0600 | [diff] [blame] | 491 | "loaderGetDeviceRegistryEntry: Failed to allocate space for registry data for key %s", manifest_path); |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 492 | *result = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 493 | goto out; |
| 494 | } |
| 495 | *reg_data[0] = '\0'; |
| 496 | } else if (strlen(*reg_data) + requiredSize + 1 > *total_size) { |
| 497 | void *new_ptr = loader_instance_heap_realloc(inst, *reg_data, *total_size, *total_size * 2, |
| 498 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
| 499 | if (NULL == new_ptr) { |
| 500 | loader_log( |
| 501 | inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 502 | "loaderGetDeviceRegistryEntry: Failed to reallocate space for registry value of size %d for key %s", |
Lenny Komow | f7c0938 | 2017-08-31 16:35:08 -0600 | [diff] [blame] | 503 | *total_size * 2, manifest_path); |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 504 | *result = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 505 | goto out; |
| 506 | } |
| 507 | *reg_data = new_ptr; |
| 508 | *total_size *= 2; |
| 509 | } |
| 510 | |
Lenny Komow | f7c0938 | 2017-08-31 16:35:08 -0600 | [diff] [blame] | 511 | for (char *curr_filename = manifest_path; curr_filename[0] != '\0'; curr_filename += strlen(curr_filename) + 1) { |
| 512 | if (strlen(*reg_data) == 0) { |
| 513 | (void)snprintf(*reg_data, requiredSize + 1, "%s", curr_filename); |
| 514 | } else { |
| 515 | (void)snprintf(*reg_data + strlen(*reg_data), requiredSize + 2, "%c%s", PATH_SEPARATOR, curr_filename); |
| 516 | } |
| 517 | loader_log(inst, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, __FUNCTION__ ": Located json file \"%s\" from PnP registry: %s", curr_filename, value_name); |
| 518 | |
| 519 | if (data_type == REG_SZ) { |
| 520 | break; |
| 521 | } |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 522 | } |
| 523 | found = true; |
| 524 | |
| 525 | out: |
Lenny Komow | f7c0938 | 2017-08-31 16:35:08 -0600 | [diff] [blame] | 526 | if (manifest_path != NULL) { |
| 527 | loader_instance_heap_free(inst, manifest_path); |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 528 | } |
| 529 | RegCloseKey(hkrKey); |
| 530 | return found; |
| 531 | } |
| 532 | |
| 533 | // Find the list of registry files (names VulkanDriverName/VulkanDriverNameWow) in hkr . |
| 534 | // |
| 535 | // This function looks for display devices and childish software components |
| 536 | // for a list of files which are added to a returned list (function return |
| 537 | // value). |
| 538 | // Function return is a string with a ';' separated list of filenames. |
| 539 | // Function return is NULL if no valid name/value pairs are found in the key, |
| 540 | // or the key is not found. |
| 541 | // |
| 542 | // *reg_data contains a string list of filenames as pointer. |
| 543 | // When done using the returned string list, the caller should free the pointer. |
Lenny Komow | f7c0938 | 2017-08-31 16:35:08 -0600 | [diff] [blame] | 544 | VkResult loaderGetDeviceRegistryFiles(const struct loader_instance *inst, char **reg_data, PDWORD reg_data_size, LPCTSTR value_name) { |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 545 | static const char* softwareComponentGUID = "{5c4c3332-344d-483c-8739-259e934c9cc8}"; |
| 546 | static const char* displayGUID = "{4d36e968-e325-11ce-bfc1-08002be10318}"; |
| 547 | const ULONG flags = CM_GETIDLIST_FILTER_CLASS | CM_GETIDLIST_FILTER_PRESENT; |
| 548 | |
| 549 | char childGuid[MAX_GUID_STRING_LEN + 2]; // +2 for brackets {} |
| 550 | ULONG childGuidSize = sizeof(childGuid); |
| 551 | |
| 552 | DEVINST devID = 0, childID = 0; |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 553 | char *pDeviceNames = NULL; |
| 554 | ULONG deviceNamesSize = 0; |
| 555 | VkResult result = VK_SUCCESS; |
| 556 | bool found = false; |
| 557 | |
| 558 | if (NULL == reg_data) { |
| 559 | result = VK_ERROR_INITIALIZATION_FAILED; |
| 560 | return result; |
| 561 | } |
| 562 | |
| 563 | // if after obtaining the DeviceNameSize, new device is added start over |
| 564 | do { |
| 565 | CM_Get_Device_ID_List_Size(&deviceNamesSize, displayGUID, flags); |
| 566 | |
| 567 | if (pDeviceNames != NULL) { |
| 568 | loader_instance_heap_free(inst, pDeviceNames); |
| 569 | } |
| 570 | |
| 571 | pDeviceNames = loader_instance_heap_alloc(inst, deviceNamesSize, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
| 572 | if (pDeviceNames == NULL) { |
| 573 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 574 | "loaderGetDeviceRegistryFiles: Failed to allocate space for display device names."); |
| 575 | result = VK_ERROR_OUT_OF_HOST_MEMORY; |
Slawomir Cygan | 018bfd5 | 2017-08-25 10:54:03 +0200 | [diff] [blame] | 576 | return result; |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 577 | } |
| 578 | } while (CM_Get_Device_ID_List(displayGUID, pDeviceNames, deviceNamesSize, flags) == CR_BUFFER_SMALL); |
| 579 | |
| 580 | if (pDeviceNames) { |
| 581 | |
| 582 | for (char *deviceName = pDeviceNames; *deviceName; deviceName += strlen(deviceName) + 1) { |
| 583 | CONFIGRET status = CM_Locate_DevNode(&devID, deviceName, CM_LOCATE_DEVNODE_NORMAL); |
| 584 | if (CR_SUCCESS != status) { |
| 585 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 586 | "loaderGetRegistryFiles: failed to open DevNode %s", deviceName); |
| 587 | continue; |
| 588 | } |
| 589 | ULONG ulStatus, ulProblem; |
| 590 | status = CM_Get_DevNode_Status(&ulStatus, &ulProblem, devID, 0); |
| 591 | |
| 592 | if (CR_SUCCESS != status) |
| 593 | { |
| 594 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 595 | "loaderGetRegistryFiles: failed to probe device status %s", deviceName); |
| 596 | continue; |
| 597 | } |
| 598 | if ((ulStatus & DN_HAS_PROBLEM) && (ulProblem == CM_PROB_NEED_RESTART || ulProblem == DN_NEED_RESTART)) |
| 599 | { |
Lenny Komow | e17a12a | 2017-08-10 09:25:49 -0600 | [diff] [blame] | 600 | loader_log(inst, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 601 | "loaderGetRegistryFiles: device %s is pending reboot, skipping ...", deviceName); |
| 602 | continue; |
| 603 | } |
| 604 | |
Lenny Komow | e17a12a | 2017-08-10 09:25:49 -0600 | [diff] [blame] | 605 | loader_log(inst, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 606 | "loaderGetRegistryFiles: opening device %s", deviceName); |
| 607 | |
Lenny Komow | f7c0938 | 2017-08-31 16:35:08 -0600 | [diff] [blame] | 608 | if (loaderGetDeviceRegistryEntry(inst, reg_data, reg_data_size, devID, value_name, &result)) { |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 609 | found = true; |
| 610 | continue; |
| 611 | } |
Igor Ostrowski | 2153273 | 2017-10-06 18:26:23 +0200 | [diff] [blame] | 612 | else if (result == VK_ERROR_OUT_OF_HOST_MEMORY) { |
| 613 | break; |
| 614 | } |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 615 | |
| 616 | status = CM_Get_Child(&childID, devID, 0); |
| 617 | if (status != CR_SUCCESS) { |
Lenny Komow | e17a12a | 2017-08-10 09:25:49 -0600 | [diff] [blame] | 618 | loader_log(inst, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 619 | "loaderGetRegistryFiles: unable to open child-device error:%d", status); |
| 620 | continue; |
| 621 | } |
| 622 | |
| 623 | do { |
| 624 | char buffer[MAX_DEVICE_ID_LEN]; |
| 625 | CM_Get_Device_ID(childID, buffer, MAX_DEVICE_ID_LEN, 0); |
| 626 | |
Lenny Komow | e17a12a | 2017-08-10 09:25:49 -0600 | [diff] [blame] | 627 | loader_log(inst, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 628 | "loaderGetRegistryFiles: Opening child device %d - %s", childID, buffer); |
| 629 | |
| 630 | status = CM_Get_DevNode_Registry_Property(childID, CM_DRP_CLASSGUID, NULL, &childGuid, &childGuidSize, 0); |
| 631 | if (status != CR_SUCCESS) { |
| 632 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 633 | "loaderGetRegistryFiles: unable to obtain GUID for:%d error:%d", childID, status); |
| 634 | |
| 635 | result = VK_ERROR_INITIALIZATION_FAILED; |
| 636 | continue; |
| 637 | } |
| 638 | |
| 639 | if (strcmp(childGuid, softwareComponentGUID) != 0) { |
| 640 | loader_log(inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, |
| 641 | "loaderGetRegistryFiles: GUID for %d is not SoftwareComponent skipping", childID); |
| 642 | continue; |
| 643 | } |
| 644 | |
Lenny Komow | f7c0938 | 2017-08-31 16:35:08 -0600 | [diff] [blame] | 645 | if (loaderGetDeviceRegistryEntry(inst, reg_data, reg_data_size, childID, value_name, &result)) { |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 646 | found = true; |
| 647 | break; // check next-display-device |
| 648 | } |
| 649 | |
| 650 | } while (CM_Get_Sibling(&childID, childID, 0) == CR_SUCCESS); |
| 651 | } |
| 652 | |
| 653 | loader_instance_heap_free(inst, pDeviceNames); |
| 654 | } |
| 655 | |
| 656 | if (!found && result != VK_ERROR_OUT_OF_HOST_MEMORY) { |
| 657 | result = VK_ERROR_INITIALIZATION_FAILED; |
| 658 | } |
| 659 | |
| 660 | return result; |
| 661 | } |
| 662 | |
Tony Barbour | ea96890 | 2015-07-29 14:26:21 -0600 | [diff] [blame] | 663 | static char *loader_get_next_path(char *path); |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 664 | |
| 665 | // Find the list of registry files (names within a key) in key "location". |
| 666 | // |
| 667 | // This function looks in the registry (hive = DEFAULT_VK_REGISTRY_HIVE) key as |
| 668 | // given in "location" |
| 669 | // for a list or name/values which are added to a returned list (function return |
| 670 | // value). |
| 671 | // The DWORD values within the key must be 0 or they are skipped. |
| 672 | // Function return is a string with a ';' separated list of filenames. |
| 673 | // Function return is NULL if no valid name/value pairs are found in the key, |
| 674 | // or the key is not found. |
| 675 | // |
| 676 | // *reg_data contains a string list of filenames as pointer. |
| 677 | // When done using the returned string list, the caller should free the pointer. |
Slawomir Cygan | 8f9f255 | 2017-08-09 11:36:52 +0200 | [diff] [blame] | 678 | VkResult loaderGetRegistryFiles(const struct loader_instance *inst, char *location, bool use_secondary_hive, char **reg_data, PDWORD reg_data_size) { |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 679 | LONG rtn_value; |
Lenny Komow | da849dc | 2017-03-01 17:22:29 -0700 | [diff] [blame] | 680 | HKEY hive = DEFAULT_VK_REGISTRY_HIVE, key; |
Piers Daniell | 524ec73 | 2015-11-05 16:58:26 -0700 | [diff] [blame] | 681 | DWORD access_flags; |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 682 | char name[2048]; |
Tony Barbour | ea96890 | 2015-07-29 14:26:21 -0600 | [diff] [blame] | 683 | char *loc = location; |
| 684 | char *next; |
Lenny Komow | da849dc | 2017-03-01 17:22:29 -0700 | [diff] [blame] | 685 | DWORD idx; |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 686 | DWORD name_size = sizeof(name); |
| 687 | DWORD value; |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 688 | DWORD value_size = sizeof(value); |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 689 | VkResult result = VK_SUCCESS; |
| 690 | bool found = false; |
| 691 | |
| 692 | if (NULL == reg_data) { |
| 693 | result = VK_ERROR_INITIALIZATION_FAILED; |
| 694 | goto out; |
| 695 | } |
Tony Barbour | ea96890 | 2015-07-29 14:26:21 -0600 | [diff] [blame] | 696 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 697 | while (*loc) { |
Tony Barbour | ea96890 | 2015-07-29 14:26:21 -0600 | [diff] [blame] | 698 | next = loader_get_next_path(loc); |
Piers Daniell | 524ec73 | 2015-11-05 16:58:26 -0700 | [diff] [blame] | 699 | access_flags = KEY_QUERY_VALUE; |
Tony Barbour | ea96890 | 2015-07-29 14:26:21 -0600 | [diff] [blame] | 700 | rtn_value = RegOpenKeyEx(hive, loc, 0, access_flags, &key); |
Lenny Komow | da849dc | 2017-03-01 17:22:29 -0700 | [diff] [blame] | 701 | if (ERROR_SUCCESS == rtn_value) { |
| 702 | idx = 0; |
| 703 | while ((rtn_value = RegEnumValue(key, idx++, name, &name_size, NULL, NULL, (LPBYTE)&value, &value_size)) == |
| 704 | ERROR_SUCCESS) { |
| 705 | if (value_size == sizeof(value) && value == 0) { |
| 706 | if (NULL == *reg_data) { |
Slawomir Cygan | 8f9f255 | 2017-08-09 11:36:52 +0200 | [diff] [blame] | 707 | *reg_data = loader_instance_heap_alloc(inst, *reg_data_size, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Lenny Komow | da849dc | 2017-03-01 17:22:29 -0700 | [diff] [blame] | 708 | if (NULL == *reg_data) { |
| 709 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | bb3a29c | 2017-05-19 12:29:43 -0600 | [diff] [blame] | 710 | "loaderGetRegistryFiles: Failed to allocate space for registry data for key %s", name); |
Lenny Komow | da849dc | 2017-03-01 17:22:29 -0700 | [diff] [blame] | 711 | result = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 712 | goto out; |
| 713 | } |
| 714 | *reg_data[0] = '\0'; |
Slawomir Cygan | 8f9f255 | 2017-08-09 11:36:52 +0200 | [diff] [blame] | 715 | } else if (strlen(*reg_data) + name_size + 1 > *reg_data_size) { |
| 716 | void *new_ptr = loader_instance_heap_realloc(inst, *reg_data, *reg_data_size, *reg_data_size * 2, |
Mark Young | bb3a29c | 2017-05-19 12:29:43 -0600 | [diff] [blame] | 717 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
| 718 | if (NULL == new_ptr) { |
| 719 | loader_log( |
| 720 | inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 721 | "loaderGetRegistryFiles: Failed to reallocate space for registry value of size %d for key %s", |
Slawomir Cygan | 8f9f255 | 2017-08-09 11:36:52 +0200 | [diff] [blame] | 722 | *reg_data_size * 2, name); |
Lenny Komow | da849dc | 2017-03-01 17:22:29 -0700 | [diff] [blame] | 723 | result = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 724 | goto out; |
| 725 | } |
Mark Young | bb3a29c | 2017-05-19 12:29:43 -0600 | [diff] [blame] | 726 | *reg_data = new_ptr; |
Slawomir Cygan | 8f9f255 | 2017-08-09 11:36:52 +0200 | [diff] [blame] | 727 | *reg_data_size *= 2; |
Lenny Komow | da849dc | 2017-03-01 17:22:29 -0700 | [diff] [blame] | 728 | } |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 729 | loader_log( |
| 730 | inst, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, "Located json file \"%s\" from registry \"%s\\%s\"", name, |
| 731 | hive == DEFAULT_VK_REGISTRY_HIVE ? DEFAULT_VK_REGISTRY_HIVE_STR : SECONDARY_VK_REGISTRY_HIVE_STR, location); |
Lenny Komow | da849dc | 2017-03-01 17:22:29 -0700 | [diff] [blame] | 732 | if (strlen(*reg_data) == 0) { |
| 733 | (void)snprintf(*reg_data, name_size + 1, "%s", name); |
| 734 | } else { |
| 735 | (void)snprintf(*reg_data + strlen(*reg_data), name_size + 2, "%c%s", PATH_SEPARATOR, name); |
| 736 | } |
| 737 | found = true; |
| 738 | } |
| 739 | name_size = 2048; |
| 740 | } |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 741 | } |
Tony Barbour | ea96890 | 2015-07-29 14:26:21 -0600 | [diff] [blame] | 742 | |
Lenny Komow | da849dc | 2017-03-01 17:22:29 -0700 | [diff] [blame] | 743 | // Advance the location - if the next location is in the secondary hive, then reset the locations and advance the hive |
| 744 | if (use_secondary_hive && (hive == DEFAULT_VK_REGISTRY_HIVE) && (*next == '\0')) { |
| 745 | loc = location; |
| 746 | hive = SECONDARY_VK_REGISTRY_HIVE; |
| 747 | } else { |
| 748 | loc = next; |
Tony Barbour | ea96890 | 2015-07-29 14:26:21 -0600 | [diff] [blame] | 749 | } |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 750 | } |
Tony Barbour | ea96890 | 2015-07-29 14:26:21 -0600 | [diff] [blame] | 751 | |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 752 | if (!found && result != VK_ERROR_OUT_OF_HOST_MEMORY) { |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 753 | result = VK_ERROR_INITIALIZATION_FAILED; |
| 754 | } |
| 755 | |
| 756 | out: |
| 757 | |
| 758 | return result; |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 759 | } |
| 760 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 761 | #endif // WIN32 |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 762 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 763 | // Combine path elements, separating each element with the platform-specific |
| 764 | // directory separator, and save the combined string to a destination buffer, |
Mark Young | dee312c | 2017-03-08 13:38:35 -0700 | [diff] [blame] | 765 | // not exceeding the given length. Path elements are given as variable args, |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 766 | // with a NULL element terminating the list. |
| 767 | // |
| 768 | // \returns the total length of the combined string, not including an ASCII |
| 769 | // NUL termination character. This length may exceed the available storage: |
| 770 | // in this case, the written string will be truncated to avoid a buffer |
| 771 | // overrun, and the return value will greater than or equal to the storage |
| 772 | // size. A NULL argument may be provided as the destination buffer in order |
| 773 | // to determine the required string length without actually writing a string. |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 774 | static size_t loader_platform_combine_path(char *dest, size_t len, ...) { |
Courtney Goeltzenleuchter | 0ef13a0 | 2015-12-16 16:19:46 -0700 | [diff] [blame] | 775 | size_t required_len = 0; |
Daniel Dadap | 00b4aba | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 776 | va_list ap; |
| 777 | const char *component; |
| 778 | |
| 779 | va_start(ap, len); |
| 780 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 781 | while ((component = va_arg(ap, const char *))) { |
Daniel Dadap | 00b4aba | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 782 | if (required_len > 0) { |
| 783 | // This path element is not the first non-empty element; prepend |
| 784 | // a directory separator if space allows |
| 785 | if (dest && required_len + 1 < len) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 786 | (void)snprintf(dest + required_len, len - required_len, "%c", DIRECTORY_SYMBOL); |
Daniel Dadap | 00b4aba | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 787 | } |
| 788 | required_len++; |
| 789 | } |
| 790 | |
| 791 | if (dest && required_len < len) { |
| 792 | strncpy(dest + required_len, component, len - required_len); |
| 793 | } |
| 794 | required_len += strlen(component); |
| 795 | } |
| 796 | |
| 797 | va_end(ap); |
| 798 | |
| 799 | // strncpy(3) won't add a NUL terminating byte in the event of truncation. |
| 800 | if (dest && required_len >= len) { |
| 801 | dest[len - 1] = '\0'; |
| 802 | } |
| 803 | |
| 804 | return required_len; |
| 805 | } |
| 806 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 807 | // Given string of three part form "maj.min.pat" convert to a vulkan version number. |
Mark Young | 60861ac | 2016-09-02 11:39:26 -0600 | [diff] [blame] | 808 | static uint32_t loader_make_version(char *vers_str) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 809 | uint32_t vers = 0, major = 0, minor = 0, patch = 0; |
Mark Young | 60861ac | 2016-09-02 11:39:26 -0600 | [diff] [blame] | 810 | char *vers_tok; |
Jon Ashburn | c7237a7 | 2015-08-03 09:08:46 -0600 | [diff] [blame] | 811 | |
Mark Young | 60861ac | 2016-09-02 11:39:26 -0600 | [diff] [blame] | 812 | if (!vers_str) { |
Jon Ashburn | c7237a7 | 2015-08-03 09:08:46 -0600 | [diff] [blame] | 813 | return vers; |
Jon Ashburn | c7237a7 | 2015-08-03 09:08:46 -0600 | [diff] [blame] | 814 | } |
Mark Young | 60861ac | 2016-09-02 11:39:26 -0600 | [diff] [blame] | 815 | |
| 816 | vers_tok = strtok(vers_str, ".\"\n\r"); |
| 817 | if (NULL != vers_tok) { |
| 818 | major = (uint16_t)atoi(vers_tok); |
| 819 | vers_tok = strtok(NULL, ".\"\n\r"); |
| 820 | if (NULL != vers_tok) { |
| 821 | minor = (uint16_t)atoi(vers_tok); |
| 822 | vers_tok = strtok(NULL, ".\"\n\r"); |
| 823 | if (NULL != vers_tok) { |
| 824 | patch = (uint16_t)atoi(vers_tok); |
| 825 | } |
| 826 | } |
| 827 | } |
Jon Ashburn | c7237a7 | 2015-08-03 09:08:46 -0600 | [diff] [blame] | 828 | |
| 829 | return VK_MAKE_VERSION(major, minor, patch); |
Jon Ashburn | c7237a7 | 2015-08-03 09:08:46 -0600 | [diff] [blame] | 830 | } |
| 831 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 832 | bool compare_vk_extension_properties(const VkExtensionProperties *op1, const VkExtensionProperties *op2) { |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 833 | return strcmp(op1->extensionName, op2->extensionName) == 0 ? true : false; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 834 | } |
| 835 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 836 | // Search the given ext_array for an extension matching the given vk_ext_prop |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 837 | bool has_vk_extension_property_array(const VkExtensionProperties *vk_ext_prop, const uint32_t count, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 838 | const VkExtensionProperties *ext_array) { |
Jon Ashburn | bd6c488 | 2015-07-02 12:59:25 -0600 | [diff] [blame] | 839 | for (uint32_t i = 0; i < count; i++) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 840 | if (compare_vk_extension_properties(vk_ext_prop, &ext_array[i])) return true; |
Jon Ashburn | bd6c488 | 2015-07-02 12:59:25 -0600 | [diff] [blame] | 841 | } |
| 842 | return false; |
| 843 | } |
| 844 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 845 | // Search the given ext_list for an extension matching the given vk_ext_prop |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 846 | bool has_vk_extension_property(const VkExtensionProperties *vk_ext_prop, const struct loader_extension_list *ext_list) { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 847 | for (uint32_t i = 0; i < ext_list->count; i++) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 848 | if (compare_vk_extension_properties(&ext_list->list[i], vk_ext_prop)) return true; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 849 | } |
| 850 | return false; |
| 851 | } |
| 852 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 853 | // Search the given ext_list for a device extension matching the given ext_prop |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 854 | bool has_vk_dev_ext_property(const VkExtensionProperties *ext_prop, const struct loader_device_extension_list *ext_list) { |
Jon Ashburn | b872696 | 2016-04-08 15:03:35 -0600 | [diff] [blame] | 855 | for (uint32_t i = 0; i < ext_list->count; i++) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 856 | if (compare_vk_extension_properties(&ext_list->list[i].props, ext_prop)) return true; |
Jon Ashburn | b872696 | 2016-04-08 15:03:35 -0600 | [diff] [blame] | 857 | } |
| 858 | return false; |
| 859 | } |
| 860 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 861 | // Search the given layer list for a layer matching the given layer name |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 862 | static struct loader_layer_properties *loader_get_layer_property(const char *name, const struct loader_layer_list *layer_list) { |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 863 | for (uint32_t i = 0; i < layer_list->count; i++) { |
| 864 | const VkLayerProperties *item = &layer_list->list[i].info; |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 865 | if (strcmp(name, item->layerName) == 0) return &layer_list->list[i]; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 866 | } |
| 867 | return NULL; |
| 868 | } |
| 869 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 870 | // Get the next unused layer property in the list. Init the property to zero. |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 871 | static struct loader_layer_properties *loader_get_next_layer_property(const struct loader_instance *inst, |
| 872 | struct loader_layer_list *layer_list) { |
Jon Ashburn | e13ecc9 | 2015-08-03 17:19:30 -0600 | [diff] [blame] | 873 | if (layer_list->capacity == 0) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 874 | layer_list->list = |
| 875 | loader_instance_heap_alloc(inst, sizeof(struct loader_layer_properties) * 64, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Jon Ashburn | e13ecc9 | 2015-08-03 17:19:30 -0600 | [diff] [blame] | 876 | if (layer_list->list == NULL) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 877 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 878 | "loader_get_next_layer_property: Out of memory can " |
| 879 | "not add any layer properties to list"); |
Jon Ashburn | e13ecc9 | 2015-08-03 17:19:30 -0600 | [diff] [blame] | 880 | return NULL; |
| 881 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 882 | memset(layer_list->list, 0, sizeof(struct loader_layer_properties) * 64); |
Jon Ashburn | e13ecc9 | 2015-08-03 17:19:30 -0600 | [diff] [blame] | 883 | layer_list->capacity = sizeof(struct loader_layer_properties) * 64; |
| 884 | } |
| 885 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 886 | // Ensure enough room to add an entry |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 887 | if ((layer_list->count + 1) * sizeof(struct loader_layer_properties) > layer_list->capacity) { |
Mark Young | bb3a29c | 2017-05-19 12:29:43 -0600 | [diff] [blame] | 888 | void *new_ptr = loader_instance_heap_realloc(inst, layer_list->list, layer_list->capacity, layer_list->capacity * 2, |
| 889 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
| 890 | if (NULL == new_ptr) { |
| 891 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, "loader_get_next_layer_property: realloc failed for layer list"); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 892 | return NULL; |
Jon Ashburn | e13ecc9 | 2015-08-03 17:19:30 -0600 | [diff] [blame] | 893 | } |
Mark Young | bb3a29c | 2017-05-19 12:29:43 -0600 | [diff] [blame] | 894 | layer_list->list = new_ptr; |
Jon Ashburn | e13ecc9 | 2015-08-03 17:19:30 -0600 | [diff] [blame] | 895 | layer_list->capacity *= 2; |
| 896 | } |
| 897 | |
| 898 | layer_list->count++; |
| 899 | return &(layer_list->list[layer_list->count - 1]); |
| 900 | } |
| 901 | |
Mark Young | dee312c | 2017-03-08 13:38:35 -0700 | [diff] [blame] | 902 | // Remove all layer properties entries from the list |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 903 | void loader_delete_layer_properties(const struct loader_instance *inst, struct loader_layer_list *layer_list) { |
Cort Stratton | 6974a13 | 2017-11-28 12:11:05 -0800 | [diff] [blame] | 904 | uint32_t i, j, k; |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 905 | struct loader_device_extension_list *dev_ext_list; |
Cort Stratton | 6974a13 | 2017-11-28 12:11:05 -0800 | [diff] [blame] | 906 | struct loader_dev_ext_props *ext_props; |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 907 | if (!layer_list) return; |
Jon Ashburn | b82c185 | 2015-08-11 14:49:54 -0600 | [diff] [blame] | 908 | |
Jon Ashburn | e13ecc9 | 2015-08-03 17:19:30 -0600 | [diff] [blame] | 909 | for (i = 0; i < layer_list->count; i++) { |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 910 | if (NULL != layer_list->list[i].component_layer_names) { |
| 911 | loader_instance_heap_free(inst, layer_list->list[i].component_layer_names); |
| 912 | layer_list->list[i].component_layer_names = NULL; |
| 913 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 914 | loader_destroy_generic_list(inst, (struct loader_generic_list *)&layer_list->list[i].instance_extension_list); |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 915 | dev_ext_list = &layer_list->list[i].device_extension_list; |
Cort Stratton | 6974a13 | 2017-11-28 12:11:05 -0800 | [diff] [blame] | 916 | if (dev_ext_list->capacity > 0 && NULL != dev_ext_list->list) { |
| 917 | for (j = 0; j < dev_ext_list->count; j++) { |
| 918 | ext_props = &dev_ext_list->list[j]; |
| 919 | if (ext_props->entrypoint_count > 0) { |
| 920 | for (k = 0; k < ext_props->entrypoint_count; k++) { |
| 921 | loader_instance_heap_free(inst, ext_props->entrypoints[k]); |
| 922 | } |
| 923 | loader_instance_heap_free(inst, ext_props->entrypoints); |
| 924 | } |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 925 | } |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 926 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 927 | loader_destroy_generic_list(inst, (struct loader_generic_list *)dev_ext_list); |
Jon Ashburn | e13ecc9 | 2015-08-03 17:19:30 -0600 | [diff] [blame] | 928 | } |
| 929 | layer_list->count = 0; |
| 930 | |
Jon Ashburn | b82c185 | 2015-08-11 14:49:54 -0600 | [diff] [blame] | 931 | if (layer_list->capacity > 0) { |
| 932 | layer_list->capacity = 0; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 933 | loader_instance_heap_free(inst, layer_list->list); |
Jon Ashburn | b82c185 | 2015-08-11 14:49:54 -0600 | [diff] [blame] | 934 | } |
Jon Ashburn | e13ecc9 | 2015-08-03 17:19:30 -0600 | [diff] [blame] | 935 | } |
| 936 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 937 | static VkResult loader_add_instance_extensions(const struct loader_instance *inst, |
| 938 | const PFN_vkEnumerateInstanceExtensionProperties fp_get_props, const char *lib_name, |
| 939 | struct loader_extension_list *ext_list) { |
Courtney Goeltzenleuchter | 36eeb74 | 2015-12-21 16:41:47 -0700 | [diff] [blame] | 940 | uint32_t i, count = 0; |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 941 | VkExtensionProperties *ext_props; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 942 | VkResult res = VK_SUCCESS; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 943 | |
Courtney Goeltzenleuchter | 5c6cf47 | 2015-07-06 22:28:18 -0600 | [diff] [blame] | 944 | if (!fp_get_props) { |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 945 | // No EnumerateInstanceExtensionProperties defined |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 946 | goto out; |
Courtney Goeltzenleuchter | 5c6cf47 | 2015-07-06 22:28:18 -0600 | [diff] [blame] | 947 | } |
| 948 | |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 949 | res = fp_get_props(NULL, &count, NULL); |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 950 | if (res != VK_SUCCESS) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 951 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 952 | "loader_add_instance_extensions: Error getting Instance " |
| 953 | "extension count from %s", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 954 | lib_name); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 955 | goto out; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 956 | } |
Jon Ashburn | 953bb3c | 2015-06-10 16:11:42 -0600 | [diff] [blame] | 957 | |
Courtney Goeltzenleuchter | 5c6cf47 | 2015-07-06 22:28:18 -0600 | [diff] [blame] | 958 | if (count == 0) { |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 959 | // No ExtensionProperties to report |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 960 | goto out; |
Courtney Goeltzenleuchter | 5c6cf47 | 2015-07-06 22:28:18 -0600 | [diff] [blame] | 961 | } |
| 962 | |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 963 | ext_props = loader_stack_alloc(count * sizeof(VkExtensionProperties)); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 964 | if (NULL == ext_props) { |
| 965 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 966 | goto out; |
| 967 | } |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 968 | |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 969 | res = fp_get_props(NULL, &count, ext_props); |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 970 | if (res != VK_SUCCESS) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 971 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 972 | "loader_add_instance_extensions: Error getting Instance " |
| 973 | "extensions from %s", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 974 | lib_name); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 975 | goto out; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 976 | } |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 977 | |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 978 | for (i = 0; i < count; i++) { |
Courtney Goeltzenleuchter | 5304373 | 2015-07-12 13:20:05 -0600 | [diff] [blame] | 979 | char spec_version[64]; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 980 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 981 | bool ext_unsupported = wsi_unsupported_instance_extension(&ext_props[i]); |
Jon Ashburn | 6fa520f | 2016-03-25 12:49:35 -0600 | [diff] [blame] | 982 | if (!ext_unsupported) { |
Mark Young | 02df1a8 | 2017-04-18 19:52:18 -0600 | [diff] [blame] | 983 | (void)snprintf(spec_version, sizeof(spec_version), "%d.%d.%d", VK_VERSION_MAJOR(ext_props[i].specVersion), |
| 984 | VK_VERSION_MINOR(ext_props[i].specVersion), VK_VERSION_PATCH(ext_props[i].specVersion)); |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 985 | loader_log(inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, "Instance Extension: %s (%s) version %s", ext_props[i].extensionName, |
| 986 | lib_name, spec_version); |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 987 | |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 988 | res = loader_add_to_ext_list(inst, ext_list, 1, &ext_props[i]); |
| 989 | if (res != VK_SUCCESS) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 990 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 991 | "loader_add_instance_extensions: Failed to add %s " |
| 992 | "to Instance extension list", |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 993 | lib_name); |
| 994 | goto out; |
| 995 | } |
Jon Ashburn | 6fa520f | 2016-03-25 12:49:35 -0600 | [diff] [blame] | 996 | } |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 997 | } |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 998 | |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 999 | out: |
| 1000 | return res; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1001 | } |
| 1002 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 1003 | // Initialize ext_list with the physical device extensions. |
| 1004 | // The extension properties are passed as inputs in count and ext_props. |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1005 | static VkResult loader_init_device_extensions(const struct loader_instance *inst, struct loader_physical_device_term *phys_dev_term, |
| 1006 | uint32_t count, VkExtensionProperties *ext_props, |
| 1007 | struct loader_extension_list *ext_list) { |
Jon Ashburn | 00eb6c0 | 2015-11-02 17:40:01 -0700 | [diff] [blame] | 1008 | VkResult res; |
| 1009 | uint32_t i; |
| 1010 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1011 | res = loader_init_generic_list(inst, (struct loader_generic_list *)ext_list, sizeof(VkExtensionProperties)); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1012 | if (VK_SUCCESS != res) { |
| 1013 | return res; |
Jon Ashburn | 00eb6c0 | 2015-11-02 17:40:01 -0700 | [diff] [blame] | 1014 | } |
| 1015 | |
| 1016 | for (i = 0; i < count; i++) { |
| 1017 | char spec_version[64]; |
Mark Young | 02df1a8 | 2017-04-18 19:52:18 -0600 | [diff] [blame] | 1018 | (void)snprintf(spec_version, sizeof(spec_version), "%d.%d.%d", VK_VERSION_MAJOR(ext_props[i].specVersion), |
| 1019 | VK_VERSION_MINOR(ext_props[i].specVersion), VK_VERSION_PATCH(ext_props[i].specVersion)); |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1020 | loader_log(inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, "Device Extension: %s (%s) version %s", ext_props[i].extensionName, |
| 1021 | phys_dev_term->this_icd_term->scanned_icd->lib_name, spec_version); |
Jon Ashburn | 00eb6c0 | 2015-11-02 17:40:01 -0700 | [diff] [blame] | 1022 | res = loader_add_to_ext_list(inst, ext_list, 1, &ext_props[i]); |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1023 | if (res != VK_SUCCESS) return res; |
Jon Ashburn | 00eb6c0 | 2015-11-02 17:40:01 -0700 | [diff] [blame] | 1024 | } |
| 1025 | |
| 1026 | return VK_SUCCESS; |
| 1027 | } |
| 1028 | |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 1029 | VkResult loader_add_device_extensions(const struct loader_instance *inst, |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1030 | PFN_vkEnumerateDeviceExtensionProperties fpEnumerateDeviceExtensionProperties, |
| 1031 | VkPhysicalDevice physical_device, const char *lib_name, |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 1032 | struct loader_extension_list *ext_list) { |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1033 | uint32_t i, count; |
| 1034 | VkResult res; |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 1035 | VkExtensionProperties *ext_props; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1036 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1037 | res = fpEnumerateDeviceExtensionProperties(physical_device, NULL, &count, NULL); |
Jon Ashburn | 00eb6c0 | 2015-11-02 17:40:01 -0700 | [diff] [blame] | 1038 | if (res == VK_SUCCESS && count > 0) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1039 | ext_props = loader_stack_alloc(count * sizeof(VkExtensionProperties)); |
Mark Young | 9a3ddd4 | 2016-10-21 16:25:47 -0600 | [diff] [blame] | 1040 | if (!ext_props) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1041 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1042 | "loader_add_device_extensions: Failed to allocate space" |
| 1043 | " for device extension properties."); |
Jon Ashburn | 00eb6c0 | 2015-11-02 17:40:01 -0700 | [diff] [blame] | 1044 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Mark Young | 9a3ddd4 | 2016-10-21 16:25:47 -0600 | [diff] [blame] | 1045 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1046 | res = fpEnumerateDeviceExtensionProperties(physical_device, NULL, &count, ext_props); |
Mark Young | 9a3ddd4 | 2016-10-21 16:25:47 -0600 | [diff] [blame] | 1047 | if (res != VK_SUCCESS) { |
Jon Ashburn | 24cd4be | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 1048 | return res; |
Mark Young | 9a3ddd4 | 2016-10-21 16:25:47 -0600 | [diff] [blame] | 1049 | } |
Jon Ashburn | 00eb6c0 | 2015-11-02 17:40:01 -0700 | [diff] [blame] | 1050 | for (i = 0; i < count; i++) { |
| 1051 | char spec_version[64]; |
Mark Young | 02df1a8 | 2017-04-18 19:52:18 -0600 | [diff] [blame] | 1052 | (void)snprintf(spec_version, sizeof(spec_version), "%d.%d.%d", VK_VERSION_MAJOR(ext_props[i].specVersion), |
| 1053 | VK_VERSION_MINOR(ext_props[i].specVersion), VK_VERSION_PATCH(ext_props[i].specVersion)); |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1054 | loader_log(inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, "Device Extension: %s (%s) version %s", ext_props[i].extensionName, |
| 1055 | lib_name, spec_version); |
Jon Ashburn | 00eb6c0 | 2015-11-02 17:40:01 -0700 | [diff] [blame] | 1056 | res = loader_add_to_ext_list(inst, ext_list, 1, &ext_props[i]); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1057 | if (res != VK_SUCCESS) { |
Jon Ashburn | 00eb6c0 | 2015-11-02 17:40:01 -0700 | [diff] [blame] | 1058 | return res; |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1059 | } |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1060 | } |
Jon Ashburn | 00eb6c0 | 2015-11-02 17:40:01 -0700 | [diff] [blame] | 1061 | } else { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1062 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1063 | "loader_add_device_extensions: Error getting physical " |
| 1064 | "device extension info count from library %s", |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1065 | lib_name); |
Jon Ashburn | 00eb6c0 | 2015-11-02 17:40:01 -0700 | [diff] [blame] | 1066 | return res; |
| 1067 | } |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1068 | |
Jon Ashburn | 24cd4be | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 1069 | return VK_SUCCESS; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1070 | } |
| 1071 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1072 | VkResult loader_init_generic_list(const struct loader_instance *inst, struct loader_generic_list *list_info, size_t element_size) { |
Mark Young | 84ba048 | 2016-09-02 11:45:00 -0600 | [diff] [blame] | 1073 | size_t capacity = 32 * element_size; |
| 1074 | list_info->count = 0; |
| 1075 | list_info->capacity = 0; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1076 | list_info->list = loader_instance_heap_alloc(inst, capacity, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Jon Ashburn | 6e6a216 | 2015-12-10 08:51:10 -0700 | [diff] [blame] | 1077 | if (list_info->list == NULL) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1078 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1079 | "loader_init_generic_list: Failed to allocate space " |
| 1080 | "for generic list"); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1081 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1082 | } |
Mark Young | 84ba048 | 2016-09-02 11:45:00 -0600 | [diff] [blame] | 1083 | memset(list_info->list, 0, capacity); |
| 1084 | list_info->capacity = capacity; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1085 | return VK_SUCCESS; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1086 | } |
| 1087 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1088 | void loader_destroy_generic_list(const struct loader_instance *inst, struct loader_generic_list *list) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1089 | loader_instance_heap_free(inst, list->list); |
Jon Ashburn | 6e6a216 | 2015-12-10 08:51:10 -0700 | [diff] [blame] | 1090 | list->count = 0; |
| 1091 | list->capacity = 0; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1092 | } |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1093 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 1094 | // Append non-duplicate extension properties defined in props to the given ext_list. |
| 1095 | // Return - Vk_SUCCESS on success |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1096 | VkResult loader_add_to_ext_list(const struct loader_instance *inst, struct loader_extension_list *ext_list, |
| 1097 | uint32_t prop_list_count, const VkExtensionProperties *props) { |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 1098 | uint32_t i; |
| 1099 | const VkExtensionProperties *cur_ext; |
| 1100 | |
| 1101 | if (ext_list->list == NULL || ext_list->capacity == 0) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1102 | VkResult res = loader_init_generic_list(inst, (struct loader_generic_list *)ext_list, sizeof(VkExtensionProperties)); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1103 | if (VK_SUCCESS != res) { |
| 1104 | return res; |
| 1105 | } |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 1106 | } |
| 1107 | |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 1108 | for (i = 0; i < prop_list_count; i++) { |
| 1109 | cur_ext = &props[i]; |
| 1110 | |
| 1111 | // look for duplicates |
| 1112 | if (has_vk_extension_property(cur_ext, ext_list)) { |
| 1113 | continue; |
| 1114 | } |
| 1115 | |
| 1116 | // add to list at end |
| 1117 | // check for enough capacity |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1118 | if (ext_list->count * sizeof(VkExtensionProperties) >= ext_list->capacity) { |
Mark Young | bb3a29c | 2017-05-19 12:29:43 -0600 | [diff] [blame] | 1119 | void *new_ptr = loader_instance_heap_realloc(inst, ext_list->list, ext_list->capacity, ext_list->capacity * 2, |
| 1120 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
| 1121 | if (new_ptr == NULL) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1122 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1123 | "loader_add_to_ext_list: Failed to reallocate " |
| 1124 | "space for extension list"); |
Jon Ashburn | 24cd4be | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 1125 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1126 | } |
Mark Young | bb3a29c | 2017-05-19 12:29:43 -0600 | [diff] [blame] | 1127 | ext_list->list = new_ptr; |
Jon Ashburn | 24cd4be | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 1128 | |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 1129 | // double capacity |
| 1130 | ext_list->capacity *= 2; |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 1131 | } |
| 1132 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1133 | memcpy(&ext_list->list[ext_list->count], cur_ext, sizeof(VkExtensionProperties)); |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 1134 | ext_list->count++; |
| 1135 | } |
Jon Ashburn | 24cd4be | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 1136 | return VK_SUCCESS; |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 1137 | } |
| 1138 | |
Mark Young | dee312c | 2017-03-08 13:38:35 -0700 | [diff] [blame] | 1139 | // Append one extension property defined in props with entrypoints defined in entries to the given |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 1140 | // ext_list. Do not append if a duplicate. |
| 1141 | // Return - Vk_SUCCESS on success |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1142 | VkResult loader_add_to_dev_ext_list(const struct loader_instance *inst, struct loader_device_extension_list *ext_list, |
| 1143 | const VkExtensionProperties *props, uint32_t entry_count, char **entrys) { |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1144 | uint32_t idx; |
| 1145 | if (ext_list->list == NULL || ext_list->capacity == 0) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1146 | VkResult res = loader_init_generic_list(inst, (struct loader_generic_list *)ext_list, sizeof(struct loader_dev_ext_props)); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1147 | if (VK_SUCCESS != res) { |
| 1148 | return res; |
| 1149 | } |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1150 | } |
| 1151 | |
Jon Ashburn | b872696 | 2016-04-08 15:03:35 -0600 | [diff] [blame] | 1152 | // look for duplicates |
| 1153 | if (has_vk_dev_ext_property(props, ext_list)) { |
| 1154 | return VK_SUCCESS; |
| 1155 | } |
| 1156 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1157 | idx = ext_list->count; |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1158 | // add to list at end |
| 1159 | // check for enough capacity |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1160 | if (idx * sizeof(struct loader_dev_ext_props) >= ext_list->capacity) { |
Mark Young | bb3a29c | 2017-05-19 12:29:43 -0600 | [diff] [blame] | 1161 | void *new_ptr = loader_instance_heap_realloc(inst, ext_list->list, ext_list->capacity, ext_list->capacity * 2, |
| 1162 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1163 | |
Mark Young | bb3a29c | 2017-05-19 12:29:43 -0600 | [diff] [blame] | 1164 | if (NULL == new_ptr) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1165 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | bb3a29c | 2017-05-19 12:29:43 -0600 | [diff] [blame] | 1166 | "loader_add_to_dev_ext_list: Failed to reallocate space for device extension list"); |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1167 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1168 | } |
Mark Young | bb3a29c | 2017-05-19 12:29:43 -0600 | [diff] [blame] | 1169 | ext_list->list = new_ptr; |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1170 | |
| 1171 | // double capacity |
| 1172 | ext_list->capacity *= 2; |
| 1173 | } |
| 1174 | |
GabrÃel Arthúr Pétursson | 7151014 | 2017-06-03 01:38:49 +0000 | [diff] [blame] | 1175 | memcpy(&ext_list->list[idx].props, props, sizeof(*props)); |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1176 | ext_list->list[idx].entrypoint_count = entry_count; |
Mark Young | 3f7a3b3 | 2017-06-26 14:03:08 -0600 | [diff] [blame] | 1177 | if (entry_count == 0) { |
| 1178 | ext_list->list[idx].entrypoints = NULL; |
| 1179 | } else { |
| 1180 | ext_list->list[idx].entrypoints = |
| 1181 | loader_instance_heap_alloc(inst, sizeof(char *) * entry_count, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
| 1182 | if (ext_list->list[idx].entrypoints == NULL) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1183 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1184 | "loader_add_to_dev_ext_list: Failed to allocate space " |
Mark Young | 3f7a3b3 | 2017-06-26 14:03:08 -0600 | [diff] [blame] | 1185 | "for device extension entrypoint list in list %d", |
| 1186 | idx); |
| 1187 | ext_list->list[idx].entrypoint_count = 0; |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1188 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1189 | } |
Mark Young | 3f7a3b3 | 2017-06-26 14:03:08 -0600 | [diff] [blame] | 1190 | for (uint32_t i = 0; i < entry_count; i++) { |
| 1191 | ext_list->list[idx].entrypoints[i] = |
| 1192 | loader_instance_heap_alloc(inst, strlen(entrys[i]) + 1, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
| 1193 | if (ext_list->list[idx].entrypoints[i] == NULL) { |
| 1194 | for (uint32_t j = 0; j < i; j++) { |
| 1195 | loader_instance_heap_free(inst, ext_list->list[idx].entrypoints[j]); |
| 1196 | } |
| 1197 | loader_instance_heap_free(inst, ext_list->list[idx].entrypoints); |
| 1198 | ext_list->list[idx].entrypoint_count = 0; |
| 1199 | ext_list->list[idx].entrypoints = NULL; |
| 1200 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1201 | "loader_add_to_dev_ext_list: Failed to allocate space " |
| 1202 | "for device extension entrypoint %d name", |
| 1203 | i); |
| 1204 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 1205 | } |
| 1206 | strcpy(ext_list->list[idx].entrypoints[i], entrys[i]); |
| 1207 | } |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1208 | } |
| 1209 | ext_list->count++; |
| 1210 | |
| 1211 | return VK_SUCCESS; |
| 1212 | } |
| 1213 | |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 1214 | // Prototype of loader_add_meta_layer function since we use it in the loader_add_implicit_layer, but can also |
| 1215 | // call loader_add_implicit_layer from loader_add_meta_layer. |
| 1216 | bool loader_add_meta_layer(const struct loader_instance *inst, const struct loader_layer_properties *prop, |
Mark Young | 283fe1c | 2017-05-04 12:16:35 -0600 | [diff] [blame] | 1217 | struct loader_layer_list *target_list, struct loader_layer_list *expanded_target_list, |
| 1218 | const struct loader_layer_list *source_list); |
| 1219 | |
| 1220 | // Search the given layer list for a list matching the given VkLayerProperties |
| 1221 | bool has_vk_layer_property(const VkLayerProperties *vk_layer_prop, const struct loader_layer_list *list) { |
| 1222 | for (uint32_t i = 0; i < list->count; i++) { |
| 1223 | if (strcmp(vk_layer_prop->layerName, list->list[i].info.layerName) == 0) return true; |
| 1224 | } |
| 1225 | return false; |
| 1226 | } |
| 1227 | |
| 1228 | // Search the given layer list for a layer matching the given name |
| 1229 | bool has_layer_name(const char *name, const struct loader_layer_list *list) { |
| 1230 | for (uint32_t i = 0; i < list->count; i++) { |
| 1231 | if (strcmp(name, list->list[i].info.layerName) == 0) return true; |
| 1232 | } |
| 1233 | return false; |
| 1234 | } |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 1235 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 1236 | // Search the given search_list for any layers in the props list. Add these to the |
| 1237 | // output layer_list. Don't add duplicates to the output layer_list. |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1238 | static VkResult loader_add_layer_names_to_list(const struct loader_instance *inst, struct loader_layer_list *output_list, |
Mark Young | 283fe1c | 2017-05-04 12:16:35 -0600 | [diff] [blame] | 1239 | struct loader_layer_list *expanded_output_list, uint32_t name_count, |
| 1240 | const char *const *names, const struct loader_layer_list *source_list) { |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1241 | struct loader_layer_properties *layer_prop; |
Courtney Goeltzenleuchter | 40caf0b | 2015-07-06 09:06:34 -0600 | [diff] [blame] | 1242 | VkResult err = VK_SUCCESS; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1243 | |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1244 | for (uint32_t i = 0; i < name_count; i++) { |
Mark Young | 283fe1c | 2017-05-04 12:16:35 -0600 | [diff] [blame] | 1245 | const char *source_name = names[i]; |
| 1246 | layer_prop = loader_get_layer_property(source_name, source_list); |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 1247 | if (NULL == layer_prop) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1248 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1249 | "loader_add_layer_names_to_list: Unable to find layer" |
| 1250 | " %s", |
Mark Young | 283fe1c | 2017-05-04 12:16:35 -0600 | [diff] [blame] | 1251 | source_name); |
Courtney Goeltzenleuchter | 55659b7 | 2015-09-14 18:01:17 -0600 | [diff] [blame] | 1252 | err = VK_ERROR_LAYER_NOT_PRESENT; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1253 | continue; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1254 | } |
| 1255 | |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 1256 | // If not a meta-layer, simply add it. |
| 1257 | if (0 == (layer_prop->type_flags & VK_LAYER_TYPE_FLAG_META_LAYER)) { |
Mark Young | 283fe1c | 2017-05-04 12:16:35 -0600 | [diff] [blame] | 1258 | if (!has_vk_layer_property(&layer_prop->info, output_list)) { |
| 1259 | loader_add_to_layer_list(inst, output_list, 1, layer_prop); |
| 1260 | } |
| 1261 | if (!has_vk_layer_property(&layer_prop->info, expanded_output_list)) { |
| 1262 | loader_add_to_layer_list(inst, expanded_output_list, 1, layer_prop); |
| 1263 | } |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 1264 | } else { |
Mark Young | 283fe1c | 2017-05-04 12:16:35 -0600 | [diff] [blame] | 1265 | if (!has_vk_layer_property(&layer_prop->info, output_list) || |
| 1266 | !has_vk_layer_property(&layer_prop->info, expanded_output_list)) { |
| 1267 | loader_add_meta_layer(inst, layer_prop, output_list, expanded_output_list, source_list); |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 1268 | } |
| 1269 | } |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1270 | } |
Courtney Goeltzenleuchter | 40caf0b | 2015-07-06 09:06:34 -0600 | [diff] [blame] | 1271 | |
| 1272 | return err; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1273 | } |
| 1274 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 1275 | // Manage lists of VkLayerProperties |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1276 | static bool loader_init_layer_list(const struct loader_instance *inst, struct loader_layer_list *list) { |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1277 | list->capacity = 32 * sizeof(struct loader_layer_properties); |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1278 | list->list = loader_instance_heap_alloc(inst, list->capacity, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1279 | if (list->list == NULL) { |
| 1280 | return false; |
| 1281 | } |
| 1282 | memset(list->list, 0, list->capacity); |
| 1283 | list->count = 0; |
| 1284 | return true; |
| 1285 | } |
| 1286 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1287 | void loader_destroy_layer_list(const struct loader_instance *inst, struct loader_device *device, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1288 | struct loader_layer_list *layer_list) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1289 | if (device) { |
| 1290 | loader_device_heap_free(device, layer_list->list); |
| 1291 | } else { |
| 1292 | loader_instance_heap_free(inst, layer_list->list); |
| 1293 | } |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1294 | layer_list->count = 0; |
| 1295 | layer_list->capacity = 0; |
| 1296 | } |
| 1297 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 1298 | // Append non-duplicate layer properties defined in prop_list to the given layer_info list |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1299 | VkResult loader_add_to_layer_list(const struct loader_instance *inst, struct loader_layer_list *list, uint32_t prop_list_count, |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1300 | const struct loader_layer_properties *props) { |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1301 | uint32_t i; |
| 1302 | struct loader_layer_properties *layer; |
| 1303 | |
| 1304 | if (list->list == NULL || list->capacity == 0) { |
Jon Ashburn | e39a4f8 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 1305 | loader_init_layer_list(inst, list); |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1306 | } |
| 1307 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1308 | if (list->list == NULL) return VK_SUCCESS; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1309 | |
| 1310 | for (i = 0; i < prop_list_count; i++) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1311 | layer = (struct loader_layer_properties *)&props[i]; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1312 | |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 1313 | // Look for duplicates, and skip |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1314 | if (has_vk_layer_property(&layer->info, list)) { |
| 1315 | continue; |
| 1316 | } |
| 1317 | |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 1318 | // Check for enough capacity |
| 1319 | if (((list->count + 1) * sizeof(struct loader_layer_properties)) >= list->capacity) { |
| 1320 | size_t new_capacity = list->capacity * 2; |
Mark Young | bb3a29c | 2017-05-19 12:29:43 -0600 | [diff] [blame] | 1321 | void *new_ptr = |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 1322 | loader_instance_heap_realloc(inst, list->list, list->capacity, new_capacity, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Mark Young | bb3a29c | 2017-05-19 12:29:43 -0600 | [diff] [blame] | 1323 | if (NULL == new_ptr) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1324 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | bb3a29c | 2017-05-19 12:29:43 -0600 | [diff] [blame] | 1325 | "loader_add_to_layer_list: Realloc failed for when attempting to add new layer"); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1326 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 1327 | } |
Mark Young | bb3a29c | 2017-05-19 12:29:43 -0600 | [diff] [blame] | 1328 | list->list = new_ptr; |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 1329 | list->capacity = new_capacity; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1330 | } |
| 1331 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1332 | memcpy(&list->list[list->count], layer, sizeof(struct loader_layer_properties)); |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1333 | list->count++; |
| 1334 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1335 | |
| 1336 | return VK_SUCCESS; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1337 | } |
| 1338 | |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 1339 | // Check the individual implicit layer for the enable/disable environment variable settings. Only add it after |
| 1340 | // every check has passed indicating it should be used. |
| 1341 | static void loader_add_implicit_layer(const struct loader_instance *inst, const struct loader_layer_properties *prop, |
Mark Young | 283fe1c | 2017-05-04 12:16:35 -0600 | [diff] [blame] | 1342 | struct loader_layer_list *target_list, struct loader_layer_list *expanded_target_list, |
| 1343 | const struct loader_layer_list *source_list) { |
Jean-Francois Roy | bd7ceab | 2017-07-06 14:10:13 -0700 | [diff] [blame] | 1344 | bool enable = loader_is_implicit_layer_enabled(inst, prop); |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 1345 | if (enable) { |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 1346 | if (0 == (prop->type_flags & VK_LAYER_TYPE_FLAG_META_LAYER)) { |
Mark Young | c8b807a | 2017-07-14 17:11:31 -0600 | [diff] [blame] | 1347 | if (NULL != target_list && !has_vk_layer_property(&prop->info, target_list)) { |
Mark Young | 283fe1c | 2017-05-04 12:16:35 -0600 | [diff] [blame] | 1348 | loader_add_to_layer_list(inst, target_list, 1, prop); |
| 1349 | } |
| 1350 | if (NULL != expanded_target_list && !has_vk_layer_property(&prop->info, expanded_target_list)) { |
| 1351 | loader_add_to_layer_list(inst, expanded_target_list, 1, prop); |
| 1352 | } |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 1353 | } else { |
Mark Young | 283fe1c | 2017-05-04 12:16:35 -0600 | [diff] [blame] | 1354 | if (!has_vk_layer_property(&prop->info, target_list) || |
| 1355 | (NULL != expanded_target_list && !has_vk_layer_property(&prop->info, expanded_target_list))) { |
| 1356 | loader_add_meta_layer(inst, prop, target_list, expanded_target_list, source_list); |
| 1357 | } |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 1358 | } |
| 1359 | } |
| 1360 | } |
| 1361 | |
| 1362 | // Add the component layers of a meta-layer to the active list of layers |
| 1363 | bool loader_add_meta_layer(const struct loader_instance *inst, const struct loader_layer_properties *prop, |
Mark Young | 283fe1c | 2017-05-04 12:16:35 -0600 | [diff] [blame] | 1364 | struct loader_layer_list *target_list, struct loader_layer_list *expanded_target_list, |
| 1365 | const struct loader_layer_list *source_list) { |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 1366 | bool found = true; |
| 1367 | |
| 1368 | // We need to add all the individual component layers |
| 1369 | for (uint32_t comp_layer = 0; comp_layer < prop->num_component_layers; comp_layer++) { |
| 1370 | bool found_comp = false; |
| 1371 | const struct loader_layer_properties *search_prop = |
| 1372 | loader_get_layer_property(prop->component_layer_names[comp_layer], source_list); |
| 1373 | if (search_prop != NULL) { |
| 1374 | found_comp = true; |
Mark Young | 283fe1c | 2017-05-04 12:16:35 -0600 | [diff] [blame] | 1375 | |
| 1376 | // If the component layer is itself an implicit layer, we need to do the implicit layer enable |
| 1377 | // checks |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 1378 | if (0 == (search_prop->type_flags & VK_LAYER_TYPE_FLAG_EXPLICIT_LAYER)) { |
Mark Young | 283fe1c | 2017-05-04 12:16:35 -0600 | [diff] [blame] | 1379 | loader_add_implicit_layer(inst, search_prop, target_list, expanded_target_list, source_list); |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 1380 | } else { |
Mark Young | 283fe1c | 2017-05-04 12:16:35 -0600 | [diff] [blame] | 1381 | if (NULL != expanded_target_list && !has_vk_layer_property(&search_prop->info, expanded_target_list)) { |
| 1382 | loader_add_to_layer_list(inst, expanded_target_list, 1, search_prop); |
| 1383 | } |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 1384 | } |
| 1385 | } |
| 1386 | if (!found_comp) { |
| 1387 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 1388 | "loader_add_meta_layer: Failed to find layer name %s component layer " |
| 1389 | "%s to activate", |
| 1390 | search_prop->info.layerName, prop->component_layer_names[comp_layer]); |
| 1391 | found = false; |
| 1392 | } |
| 1393 | } |
Mark Young | c8b807a | 2017-07-14 17:11:31 -0600 | [diff] [blame] | 1394 | |
| 1395 | // Add this layer to the overall target list (not the expanded one) |
| 1396 | if (found && !has_vk_layer_property(&prop->info, target_list)) { |
| 1397 | loader_add_to_layer_list(inst, target_list, 1, prop); |
| 1398 | } |
| 1399 | |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 1400 | return found; |
| 1401 | } |
| 1402 | |
| 1403 | // Search the source_list for any layer with a name that matches the given name and a type |
| 1404 | // that matches the given type. Add all matching layers to the target_list. |
| 1405 | // Do not add if found loader_layer_properties is already on the target_list. |
| 1406 | void loader_find_layer_name_add_list(const struct loader_instance *inst, const char *name, const enum layer_type_flags type_flags, |
Mark Young | 283fe1c | 2017-05-04 12:16:35 -0600 | [diff] [blame] | 1407 | const struct loader_layer_list *source_list, struct loader_layer_list *target_list, |
| 1408 | struct loader_layer_list *expanded_target_list) { |
Jon Ashburn | 56151d6 | 2015-10-05 09:03:21 -0600 | [diff] [blame] | 1409 | bool found = false; |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 1410 | for (uint32_t i = 0; i < source_list->count; i++) { |
| 1411 | struct loader_layer_properties *source_prop = &source_list->list[i]; |
| 1412 | if (0 == strcmp(source_prop->info.layerName, name) && (source_prop->type_flags & type_flags) == type_flags) { |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 1413 | // If not a meta-layer, simply add it. |
| 1414 | if (0 == (source_prop->type_flags & VK_LAYER_TYPE_FLAG_META_LAYER)) { |
Mark Young | c8b807a | 2017-07-14 17:11:31 -0600 | [diff] [blame] | 1415 | if (NULL != target_list && !has_vk_layer_property(&source_prop->info, target_list) && |
Mark Young | 283fe1c | 2017-05-04 12:16:35 -0600 | [diff] [blame] | 1416 | VK_SUCCESS == loader_add_to_layer_list(inst, target_list, 1, source_prop)) { |
| 1417 | found = true; |
| 1418 | } |
Mark Young | c8b807a | 2017-07-14 17:11:31 -0600 | [diff] [blame] | 1419 | if (NULL != expanded_target_list && !has_vk_layer_property(&source_prop->info, expanded_target_list) && |
Mark Young | 283fe1c | 2017-05-04 12:16:35 -0600 | [diff] [blame] | 1420 | VK_SUCCESS == loader_add_to_layer_list(inst, expanded_target_list, 1, source_prop)) { |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 1421 | found = true; |
| 1422 | } |
| 1423 | } else { |
Mark Young | 283fe1c | 2017-05-04 12:16:35 -0600 | [diff] [blame] | 1424 | found = loader_add_meta_layer(inst, source_prop, target_list, expanded_target_list, source_list); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1425 | } |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1426 | } |
| 1427 | } |
Jon Ashburn | 56151d6 | 2015-10-05 09:03:21 -0600 | [diff] [blame] | 1428 | if (!found) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1429 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 1430 | "loader_find_layer_name_add_list: Failed to find layer name %s to activate", name); |
Jon Ashburn | 56151d6 | 2015-10-05 09:03:21 -0600 | [diff] [blame] | 1431 | } |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1432 | } |
| 1433 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1434 | static VkExtensionProperties *get_extension_property(const char *name, const struct loader_extension_list *list) { |
Courtney Goeltzenleuchter | 746db73 | 2015-07-06 17:42:01 -0600 | [diff] [blame] | 1435 | for (uint32_t i = 0; i < list->count; i++) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1436 | if (strcmp(name, list->list[i].extensionName) == 0) return &list->list[i]; |
Jon Ashburn | fc2e38c | 2015-04-14 09:15:32 -0600 | [diff] [blame] | 1437 | } |
Courtney Goeltzenleuchter | 746db73 | 2015-07-06 17:42:01 -0600 | [diff] [blame] | 1438 | return NULL; |
Jon Ashburn | fc2e38c | 2015-04-14 09:15:32 -0600 | [diff] [blame] | 1439 | } |
| 1440 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1441 | static VkExtensionProperties *get_dev_extension_property(const char *name, const struct loader_device_extension_list *list) { |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1442 | for (uint32_t i = 0; i < list->count; i++) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1443 | if (strcmp(name, list->list[i].props.extensionName) == 0) return &list->list[i].props; |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1444 | } |
| 1445 | return NULL; |
| 1446 | } |
| 1447 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 1448 | // For Instance extensions implemented within the loader (i.e. DEBUG_REPORT |
| 1449 | // the extension must provide two entry points for the loader to use: |
| 1450 | // - "trampoline" entry point - this is the address returned by GetProcAddr |
| 1451 | // and will always do what's necessary to support a |
| 1452 | // global call. |
| 1453 | // - "terminator" function - this function will be put at the end of the |
| 1454 | // instance chain and will contain the necessary logic |
| 1455 | // to call / process the extension for the appropriate |
| 1456 | // ICDs that are available. |
| 1457 | // There is no generic mechanism for including these functions, the references |
| 1458 | // must be placed into the appropriate loader entry points. |
| 1459 | // GetInstanceProcAddr: call extension GetInstanceProcAddr to check for GetProcAddr |
| 1460 | // requests |
| 1461 | // loader_coalesce_extensions(void) - add extension records to the list of global |
| 1462 | // extension available to the app. |
| 1463 | // instance_disp - add function pointer for terminator function |
| 1464 | // to this array. |
| 1465 | // The extension itself should be in a separate file that will be linked directly |
| 1466 | // with the loader. |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1467 | VkResult loader_get_icd_loader_instance_extensions(const struct loader_instance *inst, struct loader_icd_tramp_list *icd_tramp_list, |
| 1468 | struct loader_extension_list *inst_exts) { |
Jon Ashburn | 5c6a46f | 2015-08-14 14:49:22 -0600 | [diff] [blame] | 1469 | struct loader_extension_list icd_exts; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1470 | VkResult res = VK_SUCCESS; |
Mark Young | 2b2ece7 | 2017-02-10 11:19:02 -0700 | [diff] [blame] | 1471 | char *env_value; |
| 1472 | bool filter_extensions = true; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1473 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1474 | loader_log(inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, "Build ICD instance extension list"); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1475 | |
Mark Young | 2b2ece7 | 2017-02-10 11:19:02 -0700 | [diff] [blame] | 1476 | // Check if a user wants to disable the instance extension filtering behavior |
| 1477 | env_value = loader_getenv("VK_LOADER_DISABLE_INST_EXT_FILTER", inst); |
| 1478 | if (NULL != env_value && atoi(env_value) != 0) { |
| 1479 | filter_extensions = false; |
| 1480 | } |
| 1481 | loader_free_getenv(env_value, inst); |
| 1482 | |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1483 | // traverse scanned icd list adding non-duplicate extensions to the list |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1484 | for (uint32_t i = 0; i < icd_tramp_list->count; i++) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1485 | res = loader_init_generic_list(inst, (struct loader_generic_list *)&icd_exts, sizeof(VkExtensionProperties)); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1486 | if (VK_SUCCESS != res) { |
| 1487 | goto out; |
| 1488 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1489 | res = loader_add_instance_extensions(inst, icd_tramp_list->scanned_list[i].EnumerateInstanceExtensionProperties, |
| 1490 | icd_tramp_list->scanned_list[i].lib_name, &icd_exts); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1491 | if (VK_SUCCESS == res) { |
Mark Young | 2b2ece7 | 2017-02-10 11:19:02 -0700 | [diff] [blame] | 1492 | if (filter_extensions) { |
| 1493 | // Remove any extensions not recognized by the loader |
| 1494 | for (int32_t j = 0; j < (int32_t)icd_exts.count; j++) { |
| 1495 | // See if the extension is in the list of supported extensions |
| 1496 | bool found = false; |
| 1497 | for (uint32_t k = 0; LOADER_INSTANCE_EXTENSIONS[k] != NULL; k++) { |
| 1498 | if (strcmp(icd_exts.list[j].extensionName, LOADER_INSTANCE_EXTENSIONS[k]) == 0) { |
| 1499 | found = true; |
| 1500 | break; |
| 1501 | } |
Lenny Komow | 4053b81 | 2016-12-29 16:27:28 -0700 | [diff] [blame] | 1502 | } |
Lenny Komow | 4053b81 | 2016-12-29 16:27:28 -0700 | [diff] [blame] | 1503 | |
Mark Young | 2b2ece7 | 2017-02-10 11:19:02 -0700 | [diff] [blame] | 1504 | // If it isn't in the list, remove it |
| 1505 | if (!found) { |
| 1506 | for (uint32_t k = j + 1; k < icd_exts.count; k++) { |
| 1507 | icd_exts.list[k - 1] = icd_exts.list[k]; |
| 1508 | } |
| 1509 | --icd_exts.count; |
| 1510 | --j; |
Lenny Komow | 4053b81 | 2016-12-29 16:27:28 -0700 | [diff] [blame] | 1511 | } |
Lenny Komow | 4053b81 | 2016-12-29 16:27:28 -0700 | [diff] [blame] | 1512 | } |
| 1513 | } |
| 1514 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1515 | res = loader_add_to_ext_list(inst, inst_exts, icd_exts.count, icd_exts.list); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1516 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1517 | loader_destroy_generic_list(inst, (struct loader_generic_list *)&icd_exts); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1518 | if (VK_SUCCESS != res) { |
| 1519 | goto out; |
| 1520 | } |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1521 | }; |
| 1522 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1523 | // Traverse loader's extensions, adding non-duplicate extensions to the list |
Jon Ashburn | e39a4f8 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 1524 | debug_report_add_instance_extensions(inst, inst_exts); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1525 | |
| 1526 | out: |
| 1527 | return res; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1528 | } |
| 1529 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1530 | struct loader_icd_term *loader_get_icd_and_device(const VkDevice device, struct loader_device **found_dev, uint32_t *icd_index) { |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1531 | *found_dev = NULL; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1532 | for (struct loader_instance *inst = loader.instances; inst; inst = inst->next) { |
Lenny Komow | 2716731 | 2017-03-31 13:43:35 -0600 | [diff] [blame] | 1533 | uint32_t index = 0; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1534 | for (struct loader_icd_term *icd_term = inst->icd_terms; icd_term; icd_term = icd_term->next) { |
| 1535 | for (struct loader_device *dev = icd_term->logical_device_list; dev; dev = dev->next) |
Mark Young | 65cb366 | 2016-11-07 13:27:02 -0700 | [diff] [blame] | 1536 | // Value comparison of device prevents object wrapping by layers |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1537 | if (loader_get_dispatch(dev->icd_device) == loader_get_dispatch(device) || |
| 1538 | loader_get_dispatch(dev->chain_device) == loader_get_dispatch(device)) { |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1539 | *found_dev = dev; |
Mark Young | 16573c7 | 2016-06-28 10:52:43 -0600 | [diff] [blame] | 1540 | if (NULL != icd_index) { |
| 1541 | *icd_index = index; |
| 1542 | } |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1543 | return icd_term; |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1544 | } |
Mark Young | 16573c7 | 2016-06-28 10:52:43 -0600 | [diff] [blame] | 1545 | index++; |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1546 | } |
| 1547 | } |
| 1548 | return NULL; |
| 1549 | } |
| 1550 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1551 | void loader_destroy_logical_device(const struct loader_instance *inst, struct loader_device *dev, |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1552 | const VkAllocationCallbacks *pAllocator) { |
| 1553 | if (pAllocator) { |
| 1554 | dev->alloc_callbacks = *pAllocator; |
| 1555 | } |
Mark Young | 283fe1c | 2017-05-04 12:16:35 -0600 | [diff] [blame] | 1556 | if (NULL != dev->expanded_activated_layer_list.list) { |
| 1557 | loader_deactivate_layers(inst, dev, &dev->expanded_activated_layer_list); |
| 1558 | } |
| 1559 | if (NULL != dev->app_activated_layer_list.list) { |
| 1560 | loader_destroy_layer_list(inst, dev, &dev->app_activated_layer_list); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1561 | } |
| 1562 | loader_device_heap_free(dev, dev); |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1563 | } |
| 1564 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1565 | struct loader_device *loader_create_logical_device(const struct loader_instance *inst, const VkAllocationCallbacks *pAllocator) { |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1566 | struct loader_device *new_dev; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1567 | #if (DEBUG_DISABLE_APP_ALLOCATORS == 1) |
| 1568 | { |
| 1569 | #else |
| 1570 | if (pAllocator) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1571 | new_dev = (struct loader_device *)pAllocator->pfnAllocation(pAllocator->pUserData, sizeof(struct loader_device), |
| 1572 | sizeof(int *), VK_SYSTEM_ALLOCATION_SCOPE_DEVICE); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1573 | } else { |
| 1574 | #endif |
| 1575 | new_dev = (struct loader_device *)malloc(sizeof(struct loader_device)); |
| 1576 | } |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1577 | |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1578 | if (!new_dev) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1579 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1580 | "loader_create_logical_device: Failed to alloc struct " |
| 1581 | "loader_device"); |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1582 | return NULL; |
| 1583 | } |
| 1584 | |
| 1585 | memset(new_dev, 0, sizeof(struct loader_device)); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1586 | if (pAllocator) { |
| 1587 | new_dev->alloc_callbacks = *pAllocator; |
| 1588 | } |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1589 | |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1590 | return new_dev; |
| 1591 | } |
| 1592 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1593 | void loader_add_logical_device(const struct loader_instance *inst, struct loader_icd_term *icd_term, struct loader_device *dev) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1594 | dev->next = icd_term->logical_device_list; |
| 1595 | icd_term->logical_device_list = dev; |
Piers Daniell | 295fe40 | 2016-03-29 11:51:11 -0600 | [diff] [blame] | 1596 | } |
| 1597 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1598 | void loader_remove_logical_device(const struct loader_instance *inst, struct loader_icd_term *icd_term, |
| 1599 | struct loader_device *found_dev, const VkAllocationCallbacks *pAllocator) { |
Jon Ashburn | 781a7ae | 2015-11-19 15:43:26 -0700 | [diff] [blame] | 1600 | struct loader_device *dev, *prev_dev; |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1601 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1602 | if (!icd_term || !found_dev) return; |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1603 | |
| 1604 | prev_dev = NULL; |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1605 | dev = icd_term->logical_device_list; |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1606 | while (dev && dev != found_dev) { |
| 1607 | prev_dev = dev; |
| 1608 | dev = dev->next; |
| 1609 | } |
| 1610 | |
| 1611 | if (prev_dev) |
| 1612 | prev_dev->next = found_dev->next; |
| 1613 | else |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1614 | icd_term->logical_device_list = found_dev->next; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1615 | loader_destroy_logical_device(inst, found_dev, pAllocator); |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1616 | } |
| 1617 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1618 | static void loader_icd_destroy(struct loader_instance *ptr_inst, struct loader_icd_term *icd_term, |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1619 | const VkAllocationCallbacks *pAllocator) { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1620 | ptr_inst->total_icd_count--; |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1621 | for (struct loader_device *dev = icd_term->logical_device_list; dev;) { |
Courtney Goeltzenleuchter | 1f157ac | 2015-06-14 19:57:15 -0600 | [diff] [blame] | 1622 | struct loader_device *next_dev = dev->next; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1623 | loader_destroy_logical_device(ptr_inst, dev, pAllocator); |
Courtney Goeltzenleuchter | 1f157ac | 2015-06-14 19:57:15 -0600 | [diff] [blame] | 1624 | dev = next_dev; |
| 1625 | } |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1626 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1627 | loader_instance_heap_free(ptr_inst, icd_term); |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1628 | } |
| 1629 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1630 | static struct loader_icd_term *loader_icd_create(const struct loader_instance *inst) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1631 | struct loader_icd_term *icd_term; |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1632 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1633 | icd_term = loader_instance_heap_alloc(inst, sizeof(struct loader_icd_term), VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1634 | if (!icd_term) { |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1635 | return NULL; |
Mark Young | db13a2a | 2016-09-06 13:53:03 -0600 | [diff] [blame] | 1636 | } |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1637 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1638 | memset(icd_term, 0, sizeof(struct loader_icd_term)); |
Courtney Goeltzenleuchter | 55001bb | 2014-10-28 10:29:27 -0600 | [diff] [blame] | 1639 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1640 | return icd_term; |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1641 | } |
| 1642 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1643 | static struct loader_icd_term *loader_icd_add(struct loader_instance *ptr_inst, const struct loader_scanned_icd *scanned_icd) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1644 | struct loader_icd_term *icd_term; |
Chia-I Wu | 13a61a5 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 1645 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1646 | icd_term = loader_icd_create(ptr_inst); |
| 1647 | if (!icd_term) { |
Chia-I Wu | 13a61a5 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 1648 | return NULL; |
Mark Young | db13a2a | 2016-09-06 13:53:03 -0600 | [diff] [blame] | 1649 | } |
Chia-I Wu | 13a61a5 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 1650 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1651 | icd_term->scanned_icd = scanned_icd; |
| 1652 | icd_term->this_instance = ptr_inst; |
Jon Ashburn | 3d00233 | 2015-08-20 16:35:30 -0600 | [diff] [blame] | 1653 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 1654 | // Prepend to the list |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1655 | icd_term->next = ptr_inst->icd_terms; |
| 1656 | ptr_inst->icd_terms = icd_term; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1657 | ptr_inst->total_icd_count++; |
Chia-I Wu | 13a61a5 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 1658 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1659 | return icd_term; |
Chia-I Wu | 13a61a5 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 1660 | } |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1661 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 1662 | // Determine the ICD interface version to use. |
| 1663 | // @param icd |
| 1664 | // @param pVersion Output parameter indicating which version to use or 0 if |
| 1665 | // the negotiation API is not supported by the ICD |
| 1666 | // @return bool indicating true if the selected interface version is supported |
| 1667 | // by the loader, false indicates the version is not supported |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1668 | bool loader_get_icd_interface_version(PFN_vkNegotiateLoaderICDInterfaceVersion fp_negotiate_icd_version, uint32_t *pVersion) { |
Jon Ashburn | 17b4c86 | 2016-04-25 11:09:37 -0600 | [diff] [blame] | 1669 | if (fp_negotiate_icd_version == NULL) { |
| 1670 | // ICD does not support the negotiation API, it supports version 0 or 1 |
| 1671 | // calling code must determine if it is version 0 or 1 |
| 1672 | *pVersion = 0; |
| 1673 | } else { |
| 1674 | // ICD supports the negotiation API, so call it with the loader's |
| 1675 | // latest version supported |
| 1676 | *pVersion = CURRENT_LOADER_ICD_INTERFACE_VERSION; |
| 1677 | VkResult result = fp_negotiate_icd_version(pVersion); |
| 1678 | |
| 1679 | if (result == VK_ERROR_INCOMPATIBLE_DRIVER) { |
| 1680 | // ICD no longer supports the loader's latest interface version so |
| 1681 | // fail loading the ICD |
| 1682 | return false; |
| 1683 | } |
| 1684 | } |
| 1685 | |
| 1686 | #if MIN_SUPPORTED_LOADER_ICD_INTERFACE_VERSION > 0 |
| 1687 | if (*pVersion < MIN_SUPPORTED_LOADER_ICD_INTERFACE_VERSION) { |
| 1688 | // Loader no longer supports the ICD's latest interface version so fail |
| 1689 | // loading the ICD |
| 1690 | return false; |
| 1691 | } |
| 1692 | #endif |
| 1693 | return true; |
| 1694 | } |
Chia-I Wu | 13a61a5 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 1695 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1696 | void loader_scanned_icd_clear(const struct loader_instance *inst, struct loader_icd_tramp_list *icd_tramp_list) { |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 1697 | if (0 != icd_tramp_list->capacity) { |
| 1698 | for (uint32_t i = 0; i < icd_tramp_list->count; i++) { |
| 1699 | loader_platform_close_library(icd_tramp_list->scanned_list[i].handle); |
| 1700 | loader_instance_heap_free(inst, icd_tramp_list->scanned_list[i].lib_name); |
| 1701 | } |
| 1702 | loader_instance_heap_free(inst, icd_tramp_list->scanned_list); |
| 1703 | icd_tramp_list->capacity = 0; |
| 1704 | icd_tramp_list->count = 0; |
| 1705 | icd_tramp_list->scanned_list = NULL; |
Jon Ashburn | 8810c5f | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 1706 | } |
Jon Ashburn | 8810c5f | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 1707 | } |
| 1708 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1709 | static VkResult loader_scanned_icd_init(const struct loader_instance *inst, struct loader_icd_tramp_list *icd_tramp_list) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1710 | VkResult err = VK_SUCCESS; |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1711 | loader_scanned_icd_clear(inst, icd_tramp_list); |
| 1712 | icd_tramp_list->capacity = 8 * sizeof(struct loader_scanned_icd); |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1713 | icd_tramp_list->scanned_list = loader_instance_heap_alloc(inst, icd_tramp_list->capacity, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1714 | if (NULL == icd_tramp_list->scanned_list) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1715 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1716 | "loader_scanned_icd_init: Realloc failed for layer list when " |
| 1717 | "attempting to add new layer"); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1718 | err = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 1719 | } |
| 1720 | return err; |
Jon Ashburn | 8810c5f | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 1721 | } |
| 1722 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1723 | static VkResult loader_scanned_icd_add(const struct loader_instance *inst, struct loader_icd_tramp_list *icd_tramp_list, |
| 1724 | const char *filename, uint32_t api_version) { |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1725 | loader_platform_dl_handle handle; |
Tony Barbour | 1d2cd3f | 2015-07-03 10:33:54 -0600 | [diff] [blame] | 1726 | PFN_vkCreateInstance fp_create_inst; |
Jon Ashburn | fd4d09d | 2016-01-07 09:44:27 -0700 | [diff] [blame] | 1727 | PFN_vkEnumerateInstanceExtensionProperties fp_get_inst_ext_props; |
Jon Ashburn | c624c88 | 2015-07-16 10:17:29 -0600 | [diff] [blame] | 1728 | PFN_vkGetInstanceProcAddr fp_get_proc_addr; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 1729 | PFN_GetPhysicalDeviceProcAddr fp_get_phys_dev_proc_addr = NULL; |
Jon Ashburn | 17b4c86 | 2016-04-25 11:09:37 -0600 | [diff] [blame] | 1730 | PFN_vkNegotiateLoaderICDInterfaceVersion fp_negotiate_icd_version; |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1731 | struct loader_scanned_icd *new_scanned_icd; |
Jon Ashburn | 17b4c86 | 2016-04-25 11:09:37 -0600 | [diff] [blame] | 1732 | uint32_t interface_vers; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1733 | VkResult res = VK_SUCCESS; |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 1734 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 1735 | // TODO implement smarter opening/closing of libraries. For now this |
| 1736 | // function leaves libraries open and the scanned_icd_clear closes them |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1737 | handle = loader_platform_open_library(filename); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1738 | if (NULL == handle) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1739 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, loader_platform_open_library_error(filename)); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1740 | goto out; |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 1741 | } |
| 1742 | |
Jon Ashburn | 17b4c86 | 2016-04-25 11:09:37 -0600 | [diff] [blame] | 1743 | // Get and settle on an ICD interface version |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1744 | fp_negotiate_icd_version = loader_platform_get_proc_address(handle, "vk_icdNegotiateLoaderICDInterfaceVersion"); |
Jon Ashburn | 17b4c86 | 2016-04-25 11:09:37 -0600 | [diff] [blame] | 1745 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1746 | if (!loader_get_icd_interface_version(fp_negotiate_icd_version, &interface_vers)) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1747 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1748 | "loader_scanned_icd_add: ICD %s doesn't support interface" |
| 1749 | " version compatible with loader, skip this ICD.", |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1750 | filename); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1751 | goto out; |
Jon Ashburn | 17b4c86 | 2016-04-25 11:09:37 -0600 | [diff] [blame] | 1752 | } |
| 1753 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1754 | fp_get_proc_addr = loader_platform_get_proc_address(handle, "vk_icdGetInstanceProcAddr"); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1755 | if (NULL == fp_get_proc_addr) { |
Jon Ashburn | 17b4c86 | 2016-04-25 11:09:37 -0600 | [diff] [blame] | 1756 | assert(interface_vers == 0); |
| 1757 | // Use deprecated interface from version 0 |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1758 | fp_get_proc_addr = loader_platform_get_proc_address(handle, "vkGetInstanceProcAddr"); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1759 | if (NULL == fp_get_proc_addr) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1760 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | dee312c | 2017-03-08 13:38:35 -0700 | [diff] [blame] | 1761 | "loader_scanned_icd_add: Attempt to retrieve either " |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1762 | "\'vkGetInstanceProcAddr\' or " |
| 1763 | "\'vk_icdGetInstanceProcAddr\' from ICD %s failed.", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1764 | filename); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1765 | goto out; |
Jon Ashburn | fd4d09d | 2016-01-07 09:44:27 -0700 | [diff] [blame] | 1766 | } else { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1767 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 1768 | "loader_scanned_icd_add: Using deprecated ICD " |
| 1769 | "interface of \'vkGetInstanceProcAddr\' instead of " |
| 1770 | "\'vk_icdGetInstanceProcAddr\' for ICD %s", |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1771 | filename); |
Jon Ashburn | fd4d09d | 2016-01-07 09:44:27 -0700 | [diff] [blame] | 1772 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1773 | fp_create_inst = loader_platform_get_proc_address(handle, "vkCreateInstance"); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1774 | if (NULL == fp_create_inst) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1775 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1776 | "loader_scanned_icd_add: Failed querying " |
| 1777 | "\'vkCreateInstance\' via dlsym/loadlibrary for " |
| 1778 | "ICD %s", |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1779 | filename); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1780 | goto out; |
Jon Ashburn | 69a5f7a | 2016-01-11 14:41:35 -0700 | [diff] [blame] | 1781 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1782 | fp_get_inst_ext_props = loader_platform_get_proc_address(handle, "vkEnumerateInstanceExtensionProperties"); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1783 | if (NULL == fp_get_inst_ext_props) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1784 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1785 | "loader_scanned_icd_add: Could not get \'vkEnumerate" |
| 1786 | "InstanceExtensionProperties\' via dlsym/loadlibrary " |
| 1787 | "for ICD %s", |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1788 | filename); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1789 | goto out; |
Jon Ashburn | 69a5f7a | 2016-01-11 14:41:35 -0700 | [diff] [blame] | 1790 | } |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1791 | } else { |
Jon Ashburn | 17b4c86 | 2016-04-25 11:09:37 -0600 | [diff] [blame] | 1792 | // Use newer interface version 1 or later |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 1793 | if (interface_vers == 0) { |
Jon Ashburn | 17b4c86 | 2016-04-25 11:09:37 -0600 | [diff] [blame] | 1794 | interface_vers = 1; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 1795 | } |
Jon Ashburn | 17b4c86 | 2016-04-25 11:09:37 -0600 | [diff] [blame] | 1796 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1797 | fp_create_inst = (PFN_vkCreateInstance)fp_get_proc_addr(NULL, "vkCreateInstance"); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1798 | if (NULL == fp_create_inst) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1799 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1800 | "loader_scanned_icd_add: Could not get " |
| 1801 | "\'vkCreateInstance\' via \'vk_icdGetInstanceProcAddr\'" |
| 1802 | " for ICD %s", |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1803 | filename); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1804 | goto out; |
Jon Ashburn | 69a5f7a | 2016-01-11 14:41:35 -0700 | [diff] [blame] | 1805 | } |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1806 | fp_get_inst_ext_props = |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1807 | (PFN_vkEnumerateInstanceExtensionProperties)fp_get_proc_addr(NULL, "vkEnumerateInstanceExtensionProperties"); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1808 | if (NULL == fp_get_inst_ext_props) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1809 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1810 | "loader_scanned_icd_add: Could not get \'vkEnumerate" |
| 1811 | "InstanceExtensionProperties\' via " |
| 1812 | "\'vk_icdGetInstanceProcAddr\' for ICD %s", |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1813 | filename); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1814 | goto out; |
Jon Ashburn | 69a5f7a | 2016-01-11 14:41:35 -0700 | [diff] [blame] | 1815 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1816 | fp_get_phys_dev_proc_addr = loader_platform_get_proc_address(handle, "vk_icdGetPhysicalDeviceProcAddr"); |
Jon Ashburn | fd4d09d | 2016-01-07 09:44:27 -0700 | [diff] [blame] | 1817 | } |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 1818 | |
Jon Ashburn | 8810c5f | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 1819 | // check for enough capacity |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1820 | if ((icd_tramp_list->count * sizeof(struct loader_scanned_icd)) >= icd_tramp_list->capacity) { |
Mark Young | bb3a29c | 2017-05-19 12:29:43 -0600 | [diff] [blame] | 1821 | void *new_ptr = loader_instance_heap_realloc(inst, icd_tramp_list->scanned_list, icd_tramp_list->capacity, |
| 1822 | icd_tramp_list->capacity * 2, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
| 1823 | if (NULL == new_ptr) { |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1824 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1825 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | bb3a29c | 2017-05-19 12:29:43 -0600 | [diff] [blame] | 1826 | "loader_scanned_icd_add: Realloc failed on icd library list for ICD %s", filename); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1827 | goto out; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1828 | } |
Mark Young | bb3a29c | 2017-05-19 12:29:43 -0600 | [diff] [blame] | 1829 | icd_tramp_list->scanned_list = new_ptr; |
| 1830 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1831 | // double capacity |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1832 | icd_tramp_list->capacity *= 2; |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 1833 | } |
| 1834 | |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 1835 | new_scanned_icd = &(icd_tramp_list->scanned_list[icd_tramp_list->count]); |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1836 | new_scanned_icd->handle = handle; |
| 1837 | new_scanned_icd->api_version = api_version; |
| 1838 | new_scanned_icd->GetInstanceProcAddr = fp_get_proc_addr; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 1839 | new_scanned_icd->GetPhysicalDeviceProcAddr = fp_get_phys_dev_proc_addr; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1840 | new_scanned_icd->EnumerateInstanceExtensionProperties = fp_get_inst_ext_props; |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1841 | new_scanned_icd->CreateInstance = fp_create_inst; |
| 1842 | new_scanned_icd->interface_version = interface_vers; |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 1843 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1844 | new_scanned_icd->lib_name = (char *)loader_instance_heap_alloc(inst, strlen(filename) + 1, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1845 | if (NULL == new_scanned_icd->lib_name) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1846 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, "loader_scanned_icd_add: Out of memory can't add ICD %s", filename); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1847 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1848 | goto out; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1849 | } |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1850 | strcpy(new_scanned_icd->lib_name, filename); |
| 1851 | icd_tramp_list->count++; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1852 | |
| 1853 | out: |
| 1854 | |
| 1855 | return res; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1856 | } |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1857 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1858 | static void loader_debug_init(void) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1859 | char *env, *orig; |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 1860 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1861 | if (g_loader_debug > 0) return; |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 1862 | |
| 1863 | g_loader_debug = 0; |
| 1864 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 1865 | // Parse comma-separated debug options |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1866 | orig = env = loader_getenv("VK_LOADER_DEBUG", NULL); |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 1867 | while (env) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1868 | char *p = strchr(env, ','); |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 1869 | size_t len; |
| 1870 | |
| 1871 | if (p) |
| 1872 | len = p - env; |
| 1873 | else |
| 1874 | len = strlen(env); |
| 1875 | |
| 1876 | if (len > 0) { |
Michael Worcester | 25c73e7 | 2015-12-10 18:06:24 +0000 | [diff] [blame] | 1877 | if (strncmp(env, "all", len) == 0) { |
| 1878 | g_loader_debug = ~0u; |
| 1879 | g_loader_log_msgs = ~0u; |
| 1880 | } else if (strncmp(env, "warn", len) == 0) { |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 1881 | g_loader_debug |= LOADER_WARN_BIT; |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 1882 | g_loader_log_msgs |= VK_DEBUG_REPORT_WARNING_BIT_EXT; |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 1883 | } else if (strncmp(env, "info", len) == 0) { |
| 1884 | g_loader_debug |= LOADER_INFO_BIT; |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 1885 | g_loader_log_msgs |= VK_DEBUG_REPORT_INFORMATION_BIT_EXT; |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 1886 | } else if (strncmp(env, "perf", len) == 0) { |
| 1887 | g_loader_debug |= LOADER_PERF_BIT; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1888 | g_loader_log_msgs |= VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT; |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 1889 | } else if (strncmp(env, "error", len) == 0) { |
| 1890 | g_loader_debug |= LOADER_ERROR_BIT; |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1891 | g_loader_log_msgs |= VK_DEBUG_REPORT_ERROR_BIT_EXT; |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 1892 | } else if (strncmp(env, "debug", len) == 0) { |
| 1893 | g_loader_debug |= LOADER_DEBUG_BIT; |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1894 | g_loader_log_msgs |= VK_DEBUG_REPORT_DEBUG_BIT_EXT; |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 1895 | } |
| 1896 | } |
| 1897 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1898 | if (!p) break; |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 1899 | |
| 1900 | env = p + 1; |
| 1901 | } |
Jon Ashburn | 38a497f | 2016-01-04 14:01:38 -0700 | [diff] [blame] | 1902 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1903 | loader_free_getenv(orig, NULL); |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 1904 | } |
| 1905 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1906 | void loader_initialize(void) { |
Jon Ashburn | 6461ef2 | 2015-09-22 13:11:00 -0600 | [diff] [blame] | 1907 | // initialize mutexs |
Jon Ashburn | 8810c5f | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 1908 | loader_platform_thread_create_mutex(&loader_lock); |
Jon Ashburn | 6461ef2 | 2015-09-22 13:11:00 -0600 | [diff] [blame] | 1909 | loader_platform_thread_create_mutex(&loader_json_lock); |
Jon Ashburn | 8810c5f | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 1910 | |
| 1911 | // initialize logging |
| 1912 | loader_debug_init(); |
Jon Ashburn | 87d6aa9 | 2015-08-28 15:19:27 -0600 | [diff] [blame] | 1913 | |
| 1914 | // initial cJSON to use alloc callbacks |
| 1915 | cJSON_Hooks alloc_fns = { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1916 | .malloc_fn = loader_instance_tls_heap_alloc, .free_fn = loader_instance_tls_heap_free, |
Jon Ashburn | 87d6aa9 | 2015-08-28 15:19:27 -0600 | [diff] [blame] | 1917 | }; |
| 1918 | cJSON_InitHooks(&alloc_fns); |
Jon Ashburn | 8810c5f | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 1919 | } |
| 1920 | |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1921 | struct loader_manifest_files { |
| 1922 | uint32_t count; |
| 1923 | char **filename_list; |
| 1924 | }; |
| 1925 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 1926 | // Get next file or dirname given a string list or registry key path |
| 1927 | // |
| 1928 | // \returns |
| 1929 | // A pointer to first char in the next path. |
| 1930 | // The next path (or NULL) in the list is returned in next_path. |
| 1931 | // Note: input string is modified in some cases. PASS IN A COPY! |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1932 | static char *loader_get_next_path(char *path) { |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1933 | uint32_t len; |
| 1934 | char *next; |
| 1935 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1936 | if (path == NULL) return NULL; |
Frank Henigman | 5717310 | 2016-11-24 22:15:20 -0500 | [diff] [blame] | 1937 | next = strchr(path, PATH_SEPARATOR); |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1938 | if (next == NULL) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1939 | len = (uint32_t)strlen(path); |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1940 | next = path + len; |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1941 | } else { |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1942 | *next = '\0'; |
| 1943 | next++; |
| 1944 | } |
| 1945 | |
| 1946 | return next; |
| 1947 | } |
| 1948 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 1949 | // Given a path which is absolute or relative, expand the path if relative or |
| 1950 | // leave the path unmodified if absolute. The base path to prepend to relative |
| 1951 | // paths is given in rel_base. |
| 1952 | // |
| 1953 | // @return - A string in out_fullpath of the full absolute path |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1954 | static void loader_expand_path(const char *path, const char *rel_base, size_t out_size, char *out_fullpath) { |
Jon Ashburn | 1531517 | 2015-07-07 15:06:25 -0600 | [diff] [blame] | 1955 | if (loader_platform_is_path_absolute(path)) { |
Daniel Dadap | 00b4aba | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 1956 | // do not prepend a base to an absolute path |
| 1957 | rel_base = ""; |
Jon Ashburn | 1531517 | 2015-07-07 15:06:25 -0600 | [diff] [blame] | 1958 | } |
Daniel Dadap | 00b4aba | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 1959 | |
| 1960 | loader_platform_combine_path(out_fullpath, out_size, rel_base, path, NULL); |
Jon Ashburn | 1531517 | 2015-07-07 15:06:25 -0600 | [diff] [blame] | 1961 | } |
| 1962 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 1963 | // Given a filename (file) and a list of paths (dir), try to find an existing |
| 1964 | // file in the paths. If filename already is a path then no searching in the given paths. |
| 1965 | // |
| 1966 | // @return - A string in out_fullpath of either the full path or file. |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1967 | static void loader_get_fullpath(const char *file, const char *dirs, size_t out_size, char *out_fullpath) { |
Daniel Dadap | 00b4aba | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 1968 | if (!loader_platform_is_path(file) && *dirs) { |
| 1969 | char *dirs_copy, *dir, *next_dir; |
| 1970 | |
| 1971 | dirs_copy = loader_stack_alloc(strlen(dirs) + 1); |
| 1972 | strcpy(dirs_copy, dirs); |
| 1973 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1974 | // find if file exists after prepending paths in given list |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1975 | for (dir = dirs_copy; *dir && (next_dir = loader_get_next_path(dir)); dir = next_dir) { |
| 1976 | loader_platform_combine_path(out_fullpath, out_size, dir, file, NULL); |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1977 | if (loader_platform_file_exists(out_fullpath)) { |
| 1978 | return; |
| 1979 | } |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1980 | } |
| 1981 | } |
Daniel Dadap | 00b4aba | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 1982 | |
Karl Schultz | e2ef9e6 | 2017-01-13 14:01:35 -0700 | [diff] [blame] | 1983 | (void)snprintf(out_fullpath, out_size, "%s", file); |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1984 | } |
| 1985 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 1986 | // Read a JSON file into a buffer. |
| 1987 | // |
| 1988 | // @return - A pointer to a cJSON object representing the JSON parse tree. |
| 1989 | // This returned buffer should be freed by caller. |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1990 | static VkResult loader_get_json(const struct loader_instance *inst, const char *filename, cJSON **json) { |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1991 | FILE *file = NULL; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1992 | char *json_buf; |
Mark Young | 93ecb1d | 2016-01-13 13:47:16 -0700 | [diff] [blame] | 1993 | size_t len; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1994 | VkResult res = VK_SUCCESS; |
| 1995 | |
| 1996 | if (NULL == json) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1997 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, "loader_get_json: Received invalid JSON file"); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1998 | res = VK_ERROR_INITIALIZATION_FAILED; |
| 1999 | goto out; |
| 2000 | } |
| 2001 | |
| 2002 | *json = NULL; |
| 2003 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2004 | file = fopen(filename, "rb"); |
Jon Ashburn | aa4ea47 | 2015-08-27 08:30:50 -0600 | [diff] [blame] | 2005 | if (!file) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2006 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, "loader_get_json: Failed to open JSON file %s", filename); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2007 | res = VK_ERROR_INITIALIZATION_FAILED; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 2008 | goto out; |
Jon Ashburn | aa4ea47 | 2015-08-27 08:30:50 -0600 | [diff] [blame] | 2009 | } |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2010 | fseek(file, 0, SEEK_END); |
| 2011 | len = ftell(file); |
| 2012 | fseek(file, 0, SEEK_SET); |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2013 | json_buf = (char *)loader_stack_alloc(len + 1); |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2014 | if (json_buf == NULL) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2015 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 2016 | "loader_get_json: Failed to allocate space for " |
| 2017 | "JSON file %s buffer of length %d", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2018 | filename, len); |
| 2019 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 2020 | goto out; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2021 | } |
| 2022 | if (fread(json_buf, sizeof(char), len, file) != len) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2023 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, "loader_get_json: Failed to read JSON file %s.", filename); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2024 | res = VK_ERROR_INITIALIZATION_FAILED; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 2025 | goto out; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2026 | } |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2027 | json_buf[len] = '\0'; |
| 2028 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 2029 | // Parse text from file |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 2030 | *json = cJSON_Parse(json_buf); |
| 2031 | if (*json == NULL) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2032 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 2033 | "loader_get_json: Failed to parse JSON file %s, " |
| 2034 | "this is usually because something ran out of " |
| 2035 | "memory.", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2036 | filename); |
| 2037 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 2038 | goto out; |
| 2039 | } |
| 2040 | |
| 2041 | out: |
| 2042 | if (NULL != file) { |
| 2043 | fclose(file); |
| 2044 | } |
| 2045 | |
| 2046 | return res; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2047 | } |
| 2048 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 2049 | // Do a deep copy of the loader_layer_properties structure. |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2050 | VkResult loader_copy_layer_properties(const struct loader_instance *inst, struct loader_layer_properties *dst, |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2051 | struct loader_layer_properties *src) { |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 2052 | uint32_t cnt, i; |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2053 | memcpy(dst, src, sizeof(*src)); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2054 | dst->instance_extension_list.list = loader_instance_heap_alloc( |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2055 | inst, sizeof(VkExtensionProperties) * src->instance_extension_list.count, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2056 | if (NULL == dst->instance_extension_list.list) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2057 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 2058 | "loader_copy_layer_properties: Failed to allocate space " |
| 2059 | "for instance extension list of size %d.", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2060 | src->instance_extension_list.count); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2061 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 2062 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2063 | dst->instance_extension_list.capacity = sizeof(VkExtensionProperties) * src->instance_extension_list.count; |
| 2064 | memcpy(dst->instance_extension_list.list, src->instance_extension_list.list, dst->instance_extension_list.capacity); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2065 | dst->device_extension_list.list = loader_instance_heap_alloc( |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2066 | inst, sizeof(struct loader_dev_ext_props) * src->device_extension_list.count, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2067 | if (NULL == dst->device_extension_list.list) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2068 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 2069 | "loader_copy_layer_properties: Failed to allocate space " |
| 2070 | "for device extension list of size %d.", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2071 | src->device_extension_list.count); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2072 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 2073 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2074 | memset(dst->device_extension_list.list, 0, sizeof(struct loader_dev_ext_props) * src->device_extension_list.count); |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 2075 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2076 | dst->device_extension_list.capacity = sizeof(struct loader_dev_ext_props) * src->device_extension_list.count; |
| 2077 | memcpy(dst->device_extension_list.list, src->device_extension_list.list, dst->device_extension_list.capacity); |
| 2078 | if (src->device_extension_list.count > 0 && src->device_extension_list.list->entrypoint_count > 0) { |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 2079 | cnt = src->device_extension_list.list->entrypoint_count; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2080 | dst->device_extension_list.list->entrypoints = |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2081 | loader_instance_heap_alloc(inst, sizeof(char *) * cnt, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2082 | if (NULL == dst->device_extension_list.list->entrypoints) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2083 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 2084 | "loader_copy_layer_properties: Failed to allocate space " |
| 2085 | "for device extension entrypoint list of size %d.", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2086 | cnt); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2087 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 2088 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2089 | memset(dst->device_extension_list.list->entrypoints, 0, sizeof(char *) * cnt); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2090 | |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 2091 | for (i = 0; i < cnt; i++) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2092 | dst->device_extension_list.list->entrypoints[i] = loader_instance_heap_alloc( |
| 2093 | inst, strlen(src->device_extension_list.list->entrypoints[i]) + 1, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2094 | if (NULL == dst->device_extension_list.list->entrypoints[i]) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2095 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 2096 | "loader_copy_layer_properties: Failed to " |
| 2097 | "allocate space for device extension entrypoint " |
| 2098 | "%d name of length", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2099 | i); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2100 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 2101 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2102 | strcpy(dst->device_extension_list.list->entrypoints[i], src->device_extension_list.list->entrypoints[i]); |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 2103 | } |
| 2104 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2105 | |
| 2106 | return VK_SUCCESS; |
Jon Ashburn | 3d00233 | 2015-08-20 16:35:30 -0600 | [diff] [blame] | 2107 | } |
| 2108 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2109 | static bool loader_find_layer_name_list(const char *name, const struct loader_layer_list *layer_list) { |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2110 | if (NULL == layer_list) { |
| 2111 | return false; |
| 2112 | } |
| 2113 | for (uint32_t j = 0; j < layer_list->count; j++) { |
| 2114 | if (!strcmp(name, layer_list->list[j].info.layerName)) { |
| 2115 | return true; |
| 2116 | } |
| 2117 | } |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 2118 | return false; |
| 2119 | } |
| 2120 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2121 | bool loader_find_layer_name_array(const char *name, uint32_t layer_count, const char layer_list[][VK_MAX_EXTENSION_NAME_SIZE]) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2122 | if (!layer_list) return false; |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 2123 | for (uint32_t j = 0; j < layer_count; j++) |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2124 | if (!strcmp(name, layer_list[j])) return true; |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 2125 | return false; |
| 2126 | } |
| 2127 | |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2128 | const char *std_validation_str = "VK_LAYER_LUNARG_standard_validation"; |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 2129 | |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2130 | // Adds the legacy VK_LAYER_LUNARG_standard_validation as a meta-layer if it |
| 2131 | // fails to find it in the list already. This is usually an indication that a |
| 2132 | // newer loader is being used with an older layer set. |
| 2133 | static bool loader_add_legacy_std_val_layer(const struct loader_instance *inst, struct loader_layer_list *layer_instance_list) { |
| 2134 | uint32_t i; |
| 2135 | bool success = true; |
| 2136 | struct loader_layer_properties *props = loader_get_next_layer_property(inst, layer_instance_list); |
| 2137 | const char std_validation_names[6][VK_MAX_EXTENSION_NAME_SIZE] = { |
Mark Young | c8b807a | 2017-07-14 17:11:31 -0600 | [diff] [blame] | 2138 | "VK_LAYER_GOOGLE_threading", "VK_LAYER_LUNARG_parameter_validation", "VK_LAYER_LUNARG_object_tracker", |
| 2139 | "VK_LAYER_LUNARG_core_validation", "VK_LAYER_GOOGLE_unique_objects"}; |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2140 | uint32_t layer_count = sizeof(std_validation_names) / sizeof(std_validation_names[0]); |
| 2141 | |
| 2142 | loader_log(inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, |
| 2143 | "Adding VK_LAYER_LUNARG_standard_validation using the loader legacy path. This is" |
| 2144 | " not an error."); |
| 2145 | |
| 2146 | if (NULL == props) { |
| 2147 | goto out; |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 2148 | } |
Jon Ashburn | 7148344 | 2016-02-11 18:59:43 -0700 | [diff] [blame] | 2149 | |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 2150 | memset(props, 0, sizeof(struct loader_layer_properties)); |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2151 | props->type_flags = VK_LAYER_TYPE_FLAG_INSTANCE_LAYER | VK_LAYER_TYPE_FLAG_EXPLICIT_LAYER | VK_LAYER_TYPE_FLAG_META_LAYER; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2152 | strncpy(props->info.description, "LunarG Standard Validation Layer", sizeof(props->info.description)); |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 2153 | props->info.implementationVersion = 1; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2154 | strncpy(props->info.layerName, std_validation_str, sizeof(props->info.layerName)); |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 2155 | props->info.specVersion = VK_MAKE_VERSION(1, 0, VK_HEADER_VERSION); |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 2156 | |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2157 | props->component_layer_names = |
| 2158 | loader_instance_heap_alloc(inst, sizeof(char[MAX_STRING_SIZE]) * layer_count, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
| 2159 | if (NULL == props->component_layer_names) { |
| 2160 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 2161 | "Failed to allocate space for legacy VK_LAYER_LUNARG_standard_validation" |
| 2162 | " meta-layer component_layers information."); |
| 2163 | success = false; |
| 2164 | goto out; |
| 2165 | } |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 2166 | for (i = 0; i < layer_count; i++) { |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2167 | strncpy(props->component_layer_names[i], std_validation_names[i], MAX_STRING_SIZE - 1); |
| 2168 | props->component_layer_names[i][MAX_STRING_SIZE - 1] = '\0'; |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 2169 | } |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 2170 | |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2171 | out: |
| 2172 | |
| 2173 | if (!success && NULL != props && NULL != props->component_layer_names) { |
| 2174 | loader_instance_heap_free(inst, props->component_layer_names); |
| 2175 | props->component_layer_names = NULL; |
| 2176 | } |
| 2177 | |
| 2178 | return success; |
| 2179 | } |
| 2180 | |
| 2181 | // Verify that all component layers in a meta-layer are valid. |
| 2182 | static bool verify_meta_layer_comp_layers(const struct loader_instance *inst, struct loader_layer_properties *prop, |
| 2183 | struct loader_layer_list *instance_layers) { |
| 2184 | bool success = true; |
Mark Young | c82a062 | 2017-05-05 11:17:17 -0600 | [diff] [blame] | 2185 | const uint32_t expected_major = VK_VERSION_MAJOR(prop->info.specVersion); |
| 2186 | const uint32_t expected_minor = VK_VERSION_MINOR(prop->info.specVersion); |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2187 | |
| 2188 | for (uint32_t comp_layer = 0; comp_layer < prop->num_component_layers; comp_layer++) { |
| 2189 | if (!loader_find_layer_name_list(prop->component_layer_names[comp_layer], instance_layers)) { |
| 2190 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 2191 | "Meta-layer %s can't find component layer %s at index %d." |
| 2192 | " Skipping this layer.", |
| 2193 | prop->info.layerName, prop->component_layer_names[comp_layer], comp_layer); |
| 2194 | success = false; |
| 2195 | break; |
| 2196 | } else { |
| 2197 | struct loader_layer_properties *comp_prop = |
| 2198 | loader_get_layer_property(prop->component_layer_names[comp_layer], instance_layers); |
| 2199 | if (comp_prop == NULL) { |
| 2200 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 2201 | "Meta-layer %s can't find property for component layer %s at index %d." |
| 2202 | " Skipping this layer.", |
| 2203 | prop->info.layerName, prop->component_layer_names[comp_layer], comp_layer); |
| 2204 | success = false; |
| 2205 | break; |
| 2206 | } |
| 2207 | |
| 2208 | // Check the version of each layer, they need to at least match MAJOR and MINOR |
Mark Young | c82a062 | 2017-05-05 11:17:17 -0600 | [diff] [blame] | 2209 | uint32_t cur_major = VK_VERSION_MAJOR(comp_prop->info.specVersion); |
| 2210 | uint32_t cur_minor = VK_VERSION_MINOR(comp_prop->info.specVersion); |
| 2211 | if (cur_major != expected_major || cur_minor != expected_minor) { |
| 2212 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 2213 | "Meta-layer uses API version %d.%d, but component layer %d uses API " |
| 2214 | "version %d.%d. Skipping this layer.", |
| 2215 | expected_major, expected_minor, comp_layer, cur_major, cur_minor); |
| 2216 | success = false; |
| 2217 | break; |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2218 | } |
| 2219 | |
| 2220 | // Make sure the layer isn't using it's own name |
| 2221 | if (!strcmp(prop->info.layerName, prop->component_layer_names[comp_layer])) { |
| 2222 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 2223 | "Meta-layer %s lists itself in its component layer list at index %d." |
| 2224 | " Skipping this layer.", |
| 2225 | prop->info.layerName, comp_layer); |
| 2226 | success = false; |
| 2227 | break; |
| 2228 | } |
| 2229 | if (comp_prop->type_flags & VK_LAYER_TYPE_FLAG_META_LAYER) { |
| 2230 | loader_log(inst, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, |
| 2231 | "verify_meta_layer_comp_layers: Adding meta-layer %s which also contains meta-layer %s", |
| 2232 | prop->info.layerName, comp_prop->info.layerName); |
| 2233 | |
| 2234 | // Make sure if the layer is using a meta-layer in its component list that we also verify that. |
| 2235 | if (!verify_meta_layer_comp_layers(inst, comp_prop, instance_layers)) { |
| 2236 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 2237 | "Meta-layer %s component layer %s can not find all component layers." |
| 2238 | " Skipping this layer.", |
| 2239 | prop->info.layerName, prop->component_layer_names[comp_layer]); |
| 2240 | success = false; |
| 2241 | break; |
| 2242 | } |
| 2243 | } |
| 2244 | |
| 2245 | // Add any instance and device extensions from component layers to this layer |
| 2246 | // list, so that anyone querying extensions will only need to look at the meta-layer |
| 2247 | for (uint32_t ext = 0; ext < comp_prop->instance_extension_list.count; ext++) { |
| 2248 | loader_log(inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, "Meta-layer %s component layer %s adding instance extension %s", |
| 2249 | prop->info.layerName, prop->component_layer_names[comp_layer], |
| 2250 | comp_prop->instance_extension_list.list[ext].extensionName); |
| 2251 | if (!has_vk_extension_property(&comp_prop->instance_extension_list.list[ext], &prop->instance_extension_list)) { |
| 2252 | loader_add_to_ext_list(inst, &prop->instance_extension_list, 1, &comp_prop->instance_extension_list.list[ext]); |
| 2253 | } |
| 2254 | } |
| 2255 | |
| 2256 | for (uint32_t ext = 0; ext < comp_prop->device_extension_list.count; ext++) { |
| 2257 | loader_log(inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, "Meta-layer %s component layer %s adding device extension %s", |
| 2258 | prop->info.layerName, prop->component_layer_names[comp_layer], |
| 2259 | comp_prop->device_extension_list.list[ext].props.extensionName); |
| 2260 | if (!has_vk_dev_ext_property(&comp_prop->device_extension_list.list[ext].props, &prop->device_extension_list)) { |
| 2261 | loader_add_to_dev_ext_list(inst, &prop->device_extension_list, |
| 2262 | &comp_prop->device_extension_list.list[ext].props, 0, NULL); |
| 2263 | } |
| 2264 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2265 | } |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2266 | } |
| 2267 | if (success) { |
| 2268 | loader_log(inst, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, "Meta-layer %s all %d component layers appear to be valid.", |
| 2269 | prop->info.layerName, prop->num_component_layers); |
| 2270 | } |
| 2271 | return success; |
| 2272 | } |
| 2273 | |
| 2274 | // Verify that all meta-layers in a layer list are valid. |
| 2275 | static void verify_all_meta_layers(const struct loader_instance *inst, struct loader_layer_list *instance_layers) { |
Mark Young | 697317f | 2017-05-09 10:31:12 -0600 | [diff] [blame] | 2276 | for (int32_t i = 0; i < (int32_t)instance_layers->count; i++) { |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2277 | struct loader_layer_properties *prop = &instance_layers->list[i]; |
| 2278 | |
| 2279 | // If this is a meta-layer, make sure it is valid |
| 2280 | if ((prop->type_flags & VK_LAYER_TYPE_FLAG_META_LAYER) && !verify_meta_layer_comp_layers(inst, prop, instance_layers)) { |
| 2281 | loader_log(inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, |
| 2282 | "Removing meta-layer %s from instance layer list since it appears invalid.", prop->info.layerName); |
| 2283 | |
| 2284 | // Delete the component layers |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2285 | loader_instance_heap_free(inst, prop->component_layer_names); |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2286 | |
Mark Young | 70ede4c | 2017-05-09 15:23:33 -0600 | [diff] [blame] | 2287 | // Remove the current invalid meta-layer from the layer list. Use memmove since we are |
| 2288 | // overlapping the source and destination addresses. |
| 2289 | memmove(&instance_layers->list[i], &instance_layers->list[i + 1], |
| 2290 | sizeof(struct loader_layer_properties) * (instance_layers->count - 1 - i)); |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2291 | |
Mark Young | 70ede4c | 2017-05-09 15:23:33 -0600 | [diff] [blame] | 2292 | // Decrement the count (because we now have one less) and decrement the loop index since we need to |
| 2293 | // re-check this index. |
| 2294 | instance_layers->count--; |
Mark Young | 697317f | 2017-05-09 10:31:12 -0600 | [diff] [blame] | 2295 | i--; |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2296 | } |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 2297 | } |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 2298 | } |
| 2299 | |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2300 | // This structure is used to store the json file version |
Mark Young | dee312c | 2017-03-08 13:38:35 -0700 | [diff] [blame] | 2301 | // in a more manageable way. |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2302 | typedef struct { |
| 2303 | uint16_t major; |
| 2304 | uint16_t minor; |
| 2305 | uint16_t patch; |
| 2306 | } layer_json_version; |
| 2307 | |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2308 | static VkResult loader_read_json_layer(const struct loader_instance *inst, struct loader_layer_list *layer_instance_list, |
| 2309 | cJSON *layer_node, layer_json_version version, cJSON *item, cJSON *disable_environment, |
| 2310 | bool is_implicit, char *filename) { |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2311 | char *temp; |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2312 | char *name, *type, *library_path_str, *api_version; |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2313 | char *implementation_version, *description; |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2314 | cJSON *ext_item, *library_path, *component_layers; |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2315 | VkExtensionProperties ext_prop; |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2316 | VkResult result = VK_ERROR_INITIALIZATION_FAILED; |
| 2317 | struct loader_layer_properties *props = NULL; |
| 2318 | int i, j; |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2319 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 2320 | // The following are required in the "layer" object: |
| 2321 | // (required) "name" |
| 2322 | // (required) "type" |
Nekotekina | d431e13 | 2017-06-11 13:13:07 +0300 | [diff] [blame] | 2323 | // (required) "library_path" |
| 2324 | // (required) "api_version" |
| 2325 | // (required) "implementation_version" |
| 2326 | // (required) "description" |
| 2327 | // (required for implicit layers) "disable_environment" |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2328 | #define GET_JSON_OBJECT(node, var) \ |
| 2329 | { \ |
| 2330 | var = cJSON_GetObjectItem(node, #var); \ |
| 2331 | if (var == NULL) { \ |
| 2332 | layer_node = layer_node->next; \ |
| 2333 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, \ |
| 2334 | "Didn't find required layer object %s in manifest " \ |
| 2335 | "JSON file, skipping this layer", \ |
| 2336 | #var); \ |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2337 | goto out; \ |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2338 | } \ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2339 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2340 | #define GET_JSON_ITEM(node, var) \ |
| 2341 | { \ |
| 2342 | item = cJSON_GetObjectItem(node, #var); \ |
| 2343 | if (item == NULL) { \ |
| 2344 | layer_node = layer_node->next; \ |
| 2345 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, \ |
| 2346 | "Didn't find required layer value %s in manifest JSON " \ |
| 2347 | "file, skipping this layer", \ |
| 2348 | #var); \ |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2349 | goto out; \ |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2350 | } \ |
| 2351 | temp = cJSON_Print(item); \ |
| 2352 | if (temp == NULL) { \ |
| 2353 | layer_node = layer_node->next; \ |
| 2354 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, \ |
| 2355 | "Problem accessing layer value %s in manifest JSON " \ |
| 2356 | "file, skipping this layer", \ |
| 2357 | #var); \ |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2358 | result = VK_ERROR_OUT_OF_HOST_MEMORY; \ |
| 2359 | goto out; \ |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2360 | } \ |
| 2361 | temp[strlen(temp) - 1] = '\0'; \ |
| 2362 | var = loader_stack_alloc(strlen(temp) + 1); \ |
| 2363 | strcpy(var, &temp[1]); \ |
| 2364 | cJSON_Free(temp); \ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2365 | } |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2366 | GET_JSON_ITEM(layer_node, name) |
| 2367 | GET_JSON_ITEM(layer_node, type) |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2368 | GET_JSON_ITEM(layer_node, api_version) |
| 2369 | GET_JSON_ITEM(layer_node, implementation_version) |
| 2370 | GET_JSON_ITEM(layer_node, description) |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2371 | |
| 2372 | // Add list entry |
| 2373 | if (!strcmp(type, "DEVICE")) { |
| 2374 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, "Device layers are deprecated skipping this layer"); |
| 2375 | layer_node = layer_node->next; |
| 2376 | goto out; |
| 2377 | } |
| 2378 | |
| 2379 | // Allow either GLOBAL or INSTANCE type interchangeably to handle |
| 2380 | // layers that must work with older loaders |
| 2381 | if (!strcmp(type, "INSTANCE") || !strcmp(type, "GLOBAL")) { |
| 2382 | if (layer_instance_list == NULL) { |
| 2383 | layer_node = layer_node->next; |
| 2384 | goto out; |
| 2385 | } |
| 2386 | props = loader_get_next_layer_property(inst, layer_instance_list); |
| 2387 | if (NULL == props) { |
| 2388 | // Error already triggered in loader_get_next_layer_property. |
| 2389 | result = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 2390 | goto out; |
| 2391 | } |
| 2392 | props->type_flags = VK_LAYER_TYPE_FLAG_INSTANCE_LAYER; |
| 2393 | if (!is_implicit) { |
| 2394 | props->type_flags |= VK_LAYER_TYPE_FLAG_EXPLICIT_LAYER; |
| 2395 | } |
| 2396 | } else { |
| 2397 | layer_node = layer_node->next; |
| 2398 | goto out; |
| 2399 | } |
| 2400 | |
| 2401 | // Library path no longer required unless component_layers is also not defined |
| 2402 | library_path = cJSON_GetObjectItem(layer_node, "library_path"); |
| 2403 | component_layers = cJSON_GetObjectItem(layer_node, "component_layers"); |
| 2404 | if (NULL != library_path) { |
| 2405 | if (NULL != component_layers) { |
| 2406 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 2407 | "Indicating meta-layer-specific component_layers, but also " |
| 2408 | "defining layer library path. Both are not compatible, so " |
| 2409 | "skipping this layer"); |
| 2410 | goto out; |
| 2411 | } |
| 2412 | props->num_component_layers = 0; |
| 2413 | props->component_layer_names = NULL; |
| 2414 | |
| 2415 | temp = cJSON_Print(library_path); |
| 2416 | if (NULL == temp) { |
| 2417 | layer_node = layer_node->next; |
| 2418 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 2419 | "Problem accessing layer value library_path in manifest JSON " |
| 2420 | "file, skipping this layer"); |
| 2421 | result = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 2422 | goto out; |
| 2423 | } |
| 2424 | temp[strlen(temp) - 1] = '\0'; |
| 2425 | library_path_str = loader_stack_alloc(strlen(temp) + 1); |
| 2426 | strcpy(library_path_str, &temp[1]); |
| 2427 | cJSON_Free(temp); |
| 2428 | |
| 2429 | char *fullpath = props->lib_name; |
| 2430 | char *rel_base; |
| 2431 | if (NULL != library_path_str) { |
| 2432 | if (loader_platform_is_path(library_path_str)) { |
| 2433 | // A relative or absolute path |
| 2434 | char *name_copy = loader_stack_alloc(strlen(filename) + 1); |
| 2435 | strcpy(name_copy, filename); |
| 2436 | rel_base = loader_platform_dirname(name_copy); |
| 2437 | loader_expand_path(library_path_str, rel_base, MAX_STRING_SIZE, fullpath); |
| 2438 | } else { |
| 2439 | // A filename which is assumed in a system directory |
| 2440 | loader_get_fullpath(library_path_str, DEFAULT_VK_LAYERS_PATH, MAX_STRING_SIZE, fullpath); |
| 2441 | } |
| 2442 | } |
| 2443 | } else if (NULL != component_layers) { |
| 2444 | if (version.major == 1 && (version.minor < 1 || version.patch < 1)) { |
| 2445 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 2446 | "Indicating meta-layer-specific component_layers, but using older " |
| 2447 | "JSON file version."); |
| 2448 | } |
| 2449 | int count = cJSON_GetArraySize(component_layers); |
| 2450 | props->num_component_layers = count; |
| 2451 | |
| 2452 | // Allocate buffer for layer names |
| 2453 | props->component_layer_names = |
| 2454 | loader_instance_heap_alloc(inst, sizeof(char[MAX_STRING_SIZE]) * count, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
| 2455 | if (NULL == props->component_layer_names) { |
| 2456 | result = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 2457 | goto out; |
| 2458 | } |
| 2459 | |
| 2460 | // Copy the component layers into the array |
| 2461 | for (i = 0; i < count; i++) { |
| 2462 | cJSON *comp_layer = cJSON_GetArrayItem(component_layers, i); |
| 2463 | if (NULL != comp_layer) { |
| 2464 | temp = cJSON_Print(comp_layer); |
| 2465 | if (NULL == temp) { |
| 2466 | result = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 2467 | goto out; |
| 2468 | } |
| 2469 | temp[strlen(temp) - 1] = '\0'; |
| 2470 | strncpy(props->component_layer_names[i], temp + 1, MAX_STRING_SIZE - 1); |
| 2471 | props->component_layer_names[i][MAX_STRING_SIZE - 1] = '\0'; |
| 2472 | cJSON_Free(temp); |
| 2473 | } |
| 2474 | } |
| 2475 | |
| 2476 | // This is now, officially, a meta-layer |
| 2477 | props->type_flags |= VK_LAYER_TYPE_FLAG_META_LAYER; |
| 2478 | loader_log(inst, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, "Encountered meta-layer %s", name); |
| 2479 | |
| 2480 | // Make sure we set up other things so we head down the correct branches below |
| 2481 | library_path_str = NULL; |
| 2482 | } else { |
| 2483 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 2484 | "Layer missing both library_path and component_layers fields. One or the " |
| 2485 | "other MUST be defined. Skipping this layer"); |
| 2486 | goto out; |
| 2487 | } |
| 2488 | |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2489 | if (is_implicit) { |
| 2490 | GET_JSON_OBJECT(layer_node, disable_environment) |
| 2491 | } |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 2492 | #undef GET_JSON_ITEM |
| 2493 | #undef GET_JSON_OBJECT |
| 2494 | |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2495 | strncpy(props->info.layerName, name, sizeof(props->info.layerName)); |
| 2496 | props->info.layerName[sizeof(props->info.layerName) - 1] = '\0'; |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2497 | props->info.specVersion = loader_make_version(api_version); |
| 2498 | props->info.implementationVersion = atoi(implementation_version); |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2499 | strncpy((char *)props->info.description, description, sizeof(props->info.description)); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2500 | props->info.description[sizeof(props->info.description) - 1] = '\0'; |
| 2501 | if (is_implicit) { |
| 2502 | if (!disable_environment || !disable_environment->child) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2503 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 2504 | "Didn't find required layer child value disable_environment" |
| 2505 | "in manifest JSON file, skipping this layer"); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2506 | layer_node = layer_node->next; |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2507 | goto out; |
Jon Ashburn | fb8ac01 | 2015-08-12 16:39:32 -0600 | [diff] [blame] | 2508 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2509 | strncpy(props->disable_env_var.name, disable_environment->child->string, sizeof(props->disable_env_var.name)); |
| 2510 | props->disable_env_var.name[sizeof(props->disable_env_var.name) - 1] = '\0'; |
| 2511 | strncpy(props->disable_env_var.value, disable_environment->child->valuestring, sizeof(props->disable_env_var.value)); |
| 2512 | props->disable_env_var.value[sizeof(props->disable_env_var.value) - 1] = '\0'; |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2513 | } |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 2514 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 2515 | // Now get all optional items and objects and put in list: |
| 2516 | // functions |
| 2517 | // instance_extensions |
| 2518 | // device_extensions |
| 2519 | // enable_environment (implicit layers only) |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2520 | #define GET_JSON_OBJECT(node, var) \ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2521 | { var = cJSON_GetObjectItem(node, #var); } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2522 | #define GET_JSON_ITEM(node, var) \ |
| 2523 | { \ |
| 2524 | item = cJSON_GetObjectItem(node, #var); \ |
| 2525 | if (item != NULL) { \ |
| 2526 | temp = cJSON_Print(item); \ |
| 2527 | if (temp != NULL) { \ |
| 2528 | temp[strlen(temp) - 1] = '\0'; \ |
| 2529 | var = loader_stack_alloc(strlen(temp) + 1); \ |
| 2530 | strcpy(var, &temp[1]); \ |
| 2531 | cJSON_Free(temp); \ |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2532 | } else { \ |
| 2533 | result = VK_ERROR_OUT_OF_HOST_MEMORY; \ |
| 2534 | goto out; \ |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2535 | } \ |
| 2536 | } \ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2537 | } |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 2538 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2539 | cJSON *instance_extensions, *device_extensions, *functions, *enable_environment; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2540 | cJSON *entrypoints = NULL; |
| 2541 | char *vkGetInstanceProcAddr = NULL; |
| 2542 | char *vkGetDeviceProcAddr = NULL; |
| 2543 | char *vkNegotiateLoaderLayerInterfaceVersion = NULL; |
| 2544 | char *spec_version = NULL; |
| 2545 | char **entry_array = NULL; |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 2546 | |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2547 | // Layer interface functions |
| 2548 | // vkGetInstanceProcAddr |
| 2549 | // vkGetDeviceProcAddr |
| 2550 | // vkNegotiateLoaderLayerInterfaceVersion (starting with JSON file 1.1.0) |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2551 | GET_JSON_OBJECT(layer_node, functions) |
| 2552 | if (functions != NULL) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2553 | if (version.major > 1 || version.minor >= 1) { |
| 2554 | GET_JSON_ITEM(functions, vkNegotiateLoaderLayerInterfaceVersion) |
| 2555 | if (vkNegotiateLoaderLayerInterfaceVersion != NULL) |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2556 | strncpy(props->functions.str_negotiate_interface, vkNegotiateLoaderLayerInterfaceVersion, |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2557 | sizeof(props->functions.str_negotiate_interface)); |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2558 | props->functions.str_negotiate_interface[sizeof(props->functions.str_negotiate_interface) - 1] = '\0'; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2559 | } else { |
| 2560 | props->functions.str_negotiate_interface[0] = '\0'; |
| 2561 | } |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2562 | GET_JSON_ITEM(functions, vkGetInstanceProcAddr) |
| 2563 | GET_JSON_ITEM(functions, vkGetDeviceProcAddr) |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2564 | if (vkGetInstanceProcAddr != NULL) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2565 | strncpy(props->functions.str_gipa, vkGetInstanceProcAddr, sizeof(props->functions.str_gipa)); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2566 | if (version.major > 1 || version.minor >= 1) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2567 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 2568 | "Indicating layer-specific vkGetInstanceProcAddr " |
| 2569 | "function is deprecated starting with JSON file " |
| 2570 | "version 1.1.0. Instead, use the new " |
| 2571 | "vkNegotiateLayerInterfaceVersion function to " |
| 2572 | "return the GetInstanceProcAddr function for this" |
| 2573 | "layer"); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2574 | } |
| 2575 | } |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2576 | props->functions.str_gipa[sizeof(props->functions.str_gipa) - 1] = '\0'; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2577 | if (vkGetDeviceProcAddr != NULL) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2578 | strncpy(props->functions.str_gdpa, vkGetDeviceProcAddr, sizeof(props->functions.str_gdpa)); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2579 | if (version.major > 1 || version.minor >= 1) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2580 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 2581 | "Indicating layer-specific vkGetDeviceProcAddr " |
| 2582 | "function is deprecated starting with JSON file " |
| 2583 | "version 1.1.0. Instead, use the new " |
| 2584 | "vkNegotiateLayerInterfaceVersion function to " |
| 2585 | "return the GetDeviceProcAddr function for this" |
| 2586 | "layer"); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2587 | } |
| 2588 | } |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2589 | props->functions.str_gdpa[sizeof(props->functions.str_gdpa) - 1] = '\0'; |
| 2590 | } |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2591 | |
| 2592 | // instance_extensions |
| 2593 | // array of { |
| 2594 | // name |
| 2595 | // spec_version |
| 2596 | // } |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2597 | GET_JSON_OBJECT(layer_node, instance_extensions) |
| 2598 | if (instance_extensions != NULL) { |
| 2599 | int count = cJSON_GetArraySize(instance_extensions); |
| 2600 | for (i = 0; i < count; i++) { |
| 2601 | ext_item = cJSON_GetArrayItem(instance_extensions, i); |
| 2602 | GET_JSON_ITEM(ext_item, name) |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2603 | if (name != NULL) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2604 | strncpy(ext_prop.extensionName, name, sizeof(ext_prop.extensionName)); |
| 2605 | ext_prop.extensionName[sizeof(ext_prop.extensionName) - 1] = '\0'; |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2606 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2607 | GET_JSON_ITEM(ext_item, spec_version) |
| 2608 | if (NULL != spec_version) { |
| 2609 | ext_prop.specVersion = atoi(spec_version); |
| 2610 | } else { |
| 2611 | ext_prop.specVersion = 0; |
| 2612 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2613 | bool ext_unsupported = wsi_unsupported_instance_extension(&ext_prop); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2614 | if (!ext_unsupported) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2615 | loader_add_to_ext_list(inst, &props->instance_extension_list, 1, &ext_prop); |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 2616 | } |
Jon Ashburn | fb8ac01 | 2015-08-12 16:39:32 -0600 | [diff] [blame] | 2617 | } |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2618 | } |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2619 | |
| 2620 | // device_extensions |
| 2621 | // array of { |
| 2622 | // name |
| 2623 | // spec_version |
| 2624 | // entrypoints |
| 2625 | // } |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2626 | GET_JSON_OBJECT(layer_node, device_extensions) |
| 2627 | if (device_extensions != NULL) { |
| 2628 | int count = cJSON_GetArraySize(device_extensions); |
| 2629 | for (i = 0; i < count; i++) { |
| 2630 | ext_item = cJSON_GetArrayItem(device_extensions, i); |
| 2631 | GET_JSON_ITEM(ext_item, name) |
| 2632 | GET_JSON_ITEM(ext_item, spec_version) |
| 2633 | if (name != NULL) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2634 | strncpy(ext_prop.extensionName, name, sizeof(ext_prop.extensionName)); |
| 2635 | ext_prop.extensionName[sizeof(ext_prop.extensionName) - 1] = '\0'; |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2636 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2637 | if (NULL != spec_version) { |
| 2638 | ext_prop.specVersion = atoi(spec_version); |
| 2639 | } else { |
| 2640 | ext_prop.specVersion = 0; |
| 2641 | } |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2642 | // entrypoints = cJSON_GetObjectItem(ext_item, "entrypoints"); |
| 2643 | GET_JSON_OBJECT(ext_item, entrypoints) |
| 2644 | int entry_count; |
| 2645 | if (entrypoints == NULL) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2646 | loader_add_to_dev_ext_list(inst, &props->device_extension_list, &ext_prop, 0, NULL); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2647 | continue; |
| 2648 | } |
| 2649 | entry_count = cJSON_GetArraySize(entrypoints); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2650 | if (entry_count) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2651 | entry_array = (char **)loader_stack_alloc(sizeof(char *) * entry_count); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2652 | } |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2653 | for (j = 0; j < entry_count; j++) { |
| 2654 | ext_item = cJSON_GetArrayItem(entrypoints, j); |
| 2655 | if (ext_item != NULL) { |
| 2656 | temp = cJSON_Print(ext_item); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2657 | if (NULL == temp) { |
| 2658 | entry_array[j] = NULL; |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2659 | result = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 2660 | goto out; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2661 | } |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2662 | temp[strlen(temp) - 1] = '\0'; |
| 2663 | entry_array[j] = loader_stack_alloc(strlen(temp) + 1); |
| 2664 | strcpy(entry_array[j], &temp[1]); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2665 | cJSON_Free(temp); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2666 | } |
| 2667 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2668 | loader_add_to_dev_ext_list(inst, &props->device_extension_list, &ext_prop, entry_count, entry_array); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2669 | } |
| 2670 | } |
| 2671 | if (is_implicit) { |
| 2672 | GET_JSON_OBJECT(layer_node, enable_environment) |
| 2673 | |
| 2674 | // enable_environment is optional |
| 2675 | if (enable_environment) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2676 | strncpy(props->enable_env_var.name, enable_environment->child->string, sizeof(props->enable_env_var.name)); |
| 2677 | props->enable_env_var.name[sizeof(props->enable_env_var.name) - 1] = '\0'; |
| 2678 | strncpy(props->enable_env_var.value, enable_environment->child->valuestring, sizeof(props->enable_env_var.value)); |
| 2679 | props->enable_env_var.value[sizeof(props->enable_env_var.value) - 1] = '\0'; |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2680 | } |
| 2681 | } |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2682 | |
| 2683 | result = VK_SUCCESS; |
| 2684 | |
| 2685 | out: |
| 2686 | |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 2687 | #undef GET_JSON_ITEM |
| 2688 | #undef GET_JSON_OBJECT |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2689 | |
| 2690 | if (VK_SUCCESS != result && NULL != props) { |
| 2691 | props->num_component_layers = 0; |
| 2692 | if (NULL != props->component_layer_names) { |
| 2693 | loader_instance_heap_free(inst, props->component_layer_names); |
| 2694 | } |
| 2695 | props->component_layer_names = NULL; |
| 2696 | } |
| 2697 | |
| 2698 | return result; |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2699 | } |
| 2700 | |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2701 | static inline bool is_valid_layer_json_version(const layer_json_version *layer_json) { |
| 2702 | // Supported versions are: 1.0.0, 1.0.1, and 1.1.0. |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2703 | if ((layer_json->major == 1 && layer_json->minor == 1 && layer_json->patch < 2) || |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2704 | (layer_json->major == 1 && layer_json->minor == 0 && layer_json->patch < 2)) { |
| 2705 | return true; |
| 2706 | } |
| 2707 | return false; |
| 2708 | } |
| 2709 | |
| 2710 | static inline bool layer_json_supports_layers_tag(const layer_json_version *layer_json) { |
| 2711 | // Supported versions started in 1.0.1, so anything newer |
| 2712 | if ((layer_json->major > 1 || layer_json->minor > 0 || layer_json->patch > 1)) { |
| 2713 | return true; |
| 2714 | } |
| 2715 | return false; |
| 2716 | } |
| 2717 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 2718 | // Given a cJSON struct (json) of the top level JSON object from layer manifest |
| 2719 | // file, add entry to the layer_list. Fill out the layer_properties in this list |
| 2720 | // entry from the input cJSON object. |
| 2721 | // |
| 2722 | // \returns |
| 2723 | // void |
| 2724 | // layer_list has a new entry and initialized accordingly. |
| 2725 | // If the json input object does not have all the required fields no entry |
| 2726 | // is added to the list. |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2727 | static VkResult loader_add_layer_properties(const struct loader_instance *inst, struct loader_layer_list *layer_instance_list, |
| 2728 | cJSON *json, bool is_implicit, char *filename) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2729 | // The following Fields in layer manifest file that are required: |
Nekotekina | d431e13 | 2017-06-11 13:13:07 +0300 | [diff] [blame] | 2730 | // - "file_format_version" |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2731 | // - If more than one "layer" object are used, then the "layers" array is |
Mark Young | dee312c | 2017-03-08 13:38:35 -0700 | [diff] [blame] | 2732 | // required |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2733 | VkResult result = VK_ERROR_INITIALIZATION_FAILED; |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2734 | cJSON *item, *layers_node, *layer_node; |
Mike Stroyan | 8190821 | 2017-03-14 13:09:12 -0600 | [diff] [blame] | 2735 | layer_json_version json_version = {0, 0, 0}; |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2736 | char *vers_tok; |
| 2737 | cJSON *disable_environment = NULL; |
| 2738 | item = cJSON_GetObjectItem(json, "file_format_version"); |
| 2739 | if (item == NULL) { |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2740 | goto out; |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2741 | } |
| 2742 | char *file_vers = cJSON_PrintUnformatted(item); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2743 | if (NULL == file_vers) { |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2744 | goto out; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2745 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2746 | loader_log(inst, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, "Found manifest file %s, version %s", filename, file_vers); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2747 | // Get the major/minor/and patch as integers for easier comparison |
| 2748 | vers_tok = strtok(file_vers, ".\"\n\r"); |
| 2749 | if (NULL != vers_tok) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2750 | json_version.major = (uint16_t)atoi(vers_tok); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2751 | vers_tok = strtok(NULL, ".\"\n\r"); |
| 2752 | if (NULL != vers_tok) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2753 | json_version.minor = (uint16_t)atoi(vers_tok); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2754 | vers_tok = strtok(NULL, ".\"\n\r"); |
| 2755 | if (NULL != vers_tok) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2756 | json_version.patch = (uint16_t)atoi(vers_tok); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2757 | } |
| 2758 | } |
| 2759 | } |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2760 | |
| 2761 | if (!is_valid_layer_json_version(&json_version)) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2762 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 2763 | "loader_add_layer_properties: %s invalid layer " |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2764 | "manifest file version %d.%d.%d. May cause errors.", |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2765 | filename, json_version.major, json_version.minor, json_version.patch); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2766 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2767 | cJSON_Free(file_vers); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2768 | |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2769 | // If "layers" is present, read in the array of layer objects |
| 2770 | layers_node = cJSON_GetObjectItem(json, "layers"); |
| 2771 | if (layers_node != NULL) { |
| 2772 | int numItems = cJSON_GetArraySize(layers_node); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2773 | if (!layer_json_supports_layers_tag(&json_version)) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2774 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 2775 | "loader_add_layer_properties: \'layers\' tag not " |
| 2776 | "supported until file version 1.0.1, but %s is " |
| 2777 | "reporting version %s", |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2778 | filename, file_vers); |
| 2779 | } |
| 2780 | for (int curLayer = 0; curLayer < numItems; curLayer++) { |
| 2781 | layer_node = cJSON_GetArrayItem(layers_node, curLayer); |
| 2782 | if (layer_node == NULL) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2783 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 2784 | "loader_add_layer_properties: Can not find " |
| 2785 | "\'layers\' array element %d object in manifest " |
| 2786 | "JSON file %s. Skipping this file", |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2787 | curLayer, filename); |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2788 | goto out; |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2789 | } |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2790 | result = loader_read_json_layer(inst, layer_instance_list, layer_node, json_version, item, disable_environment, |
| 2791 | is_implicit, filename); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2792 | } |
| 2793 | } else { |
| 2794 | // Otherwise, try to read in individual layers |
| 2795 | layer_node = cJSON_GetObjectItem(json, "layer"); |
| 2796 | if (layer_node == NULL) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2797 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 2798 | "loader_add_layer_properties: Can not find \'layer\' " |
| 2799 | "object in manifest JSON file %s. Skipping this file.", |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2800 | filename); |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2801 | goto out; |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2802 | } |
| 2803 | // Loop through all "layer" objects in the file to get a count of them |
| 2804 | // first. |
| 2805 | uint16_t layer_count = 0; |
| 2806 | cJSON *tempNode = layer_node; |
| 2807 | do { |
| 2808 | tempNode = tempNode->next; |
| 2809 | layer_count++; |
| 2810 | } while (tempNode != NULL); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2811 | |
| 2812 | // Throw a warning if we encounter multiple "layer" objects in file |
| 2813 | // versions newer than 1.0.0. Having multiple objects with the same |
| 2814 | // name at the same level is actually a JSON standard violation. |
| 2815 | if (layer_count > 1 && layer_json_supports_layers_tag(&json_version)) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2816 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 2817 | "loader_add_layer_properties: Multiple \'layer\' nodes" |
| 2818 | " are deprecated starting in file version \"1.0.1\". " |
| 2819 | "Please use \'layers\' : [] array instead in %s.", |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2820 | filename); |
| 2821 | } else { |
| 2822 | do { |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2823 | result = loader_read_json_layer(inst, layer_instance_list, layer_node, json_version, item, disable_environment, |
| 2824 | is_implicit, filename); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2825 | layer_node = layer_node->next; |
| 2826 | } while (layer_node != NULL); |
| 2827 | } |
| 2828 | } |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2829 | |
| 2830 | out: |
| 2831 | |
| 2832 | return result; |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 2833 | } |
| 2834 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 2835 | // Find the Vulkan library manifest files. |
| 2836 | // |
| 2837 | // This function scans the "location" or "env_override" directories/files |
| 2838 | // for a list of JSON manifest files. If env_override is non-NULL |
| 2839 | // and has a valid value. Then the location is ignored. Otherwise |
| 2840 | // location is used to look for manifest files. The location |
| 2841 | // is interpreted as Registry path on Windows and a directory path(s) |
| 2842 | // on Linux. "home_location" is an additional directory in the users home |
| 2843 | // directory to look at. It is expanded into the dir path |
| 2844 | // $XDG_DATA_HOME/home_location or $HOME/.local/share/home_location depending |
| 2845 | // on environment variables. This "home_location" is only used on Linux. |
| 2846 | // |
| 2847 | // \returns |
| 2848 | // VKResult |
| 2849 | // A string list of manifest files to be opened in out_files param. |
| 2850 | // List has a pointer to string for each manifest filename. |
| 2851 | // When done using the list in out_files, pointers should be freed. |
| 2852 | // Location or override string lists can be either files or directories as |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2853 | // follows: |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 2854 | // | location | override |
| 2855 | // -------------------------------- |
| 2856 | // Win ICD | files | files |
| 2857 | // Win Layer | files | dirs |
| 2858 | // Linux ICD | dirs | files |
| 2859 | // Linux Layer| dirs | dirs |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2860 | static VkResult loader_get_manifest_files(const struct loader_instance *inst, const char *env_override, const char *source_override, |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2861 | bool is_layer, bool warn_if_not_present, const char *location, |
| 2862 | const char *relative_location, struct loader_manifest_files *out_files) { |
Mark Young | bb3a29c | 2017-05-19 12:29:43 -0600 | [diff] [blame] | 2863 | const char *override = NULL; |
Frank Henigman | b1c27cb | 2016-11-24 20:02:09 -0500 | [diff] [blame] | 2864 | char *override_getenv = NULL; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2865 | char *loc, *orig_loc = NULL; |
| 2866 | char *reg = NULL; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2867 | char *file, *next_file, *name; |
| 2868 | size_t alloced_count = 64; |
| 2869 | char full_path[2048]; |
| 2870 | DIR *sysdir = NULL; |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2871 | bool list_is_dirs = false; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2872 | struct dirent *dent; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2873 | VkResult res = VK_SUCCESS; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2874 | |
| 2875 | out_files->count = 0; |
| 2876 | out_files->filename_list = NULL; |
| 2877 | |
Jamie Madill | 00c3c91 | 2016-04-06 18:26:46 -0400 | [diff] [blame] | 2878 | if (source_override != NULL) { |
| 2879 | override = source_override; |
Frank Henigman | b1c27cb | 2016-11-24 20:02:09 -0500 | [diff] [blame] | 2880 | } else if (env_override != NULL) { |
Johannes van Waveren | 9bd80501 | 2015-10-28 11:45:00 -0500 | [diff] [blame] | 2881 | #if !defined(_WIN32) |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 2882 | if (geteuid() != getuid() || getegid() != getgid()) { |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 2883 | // Don't allow setuid apps to use the env var: |
Frank Henigman | b1c27cb | 2016-11-24 20:02:09 -0500 | [diff] [blame] | 2884 | env_override = NULL; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2885 | } |
| 2886 | #endif |
Frank Henigman | b1c27cb | 2016-11-24 20:02:09 -0500 | [diff] [blame] | 2887 | if (env_override != NULL) { |
Mark Young | d8c6b69 | 2017-03-09 11:39:41 -0700 | [diff] [blame] | 2888 | override = override_getenv = loader_secure_getenv(env_override, inst); |
Frank Henigman | b1c27cb | 2016-11-24 20:02:09 -0500 | [diff] [blame] | 2889 | } |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2890 | } |
| 2891 | |
Jon Ashburn | b682221 | 2016-02-16 15:34:16 -0700 | [diff] [blame] | 2892 | #if !defined(_WIN32) |
Benjamin Saunders | 31a4801 | 2017-01-29 14:49:54 -0800 | [diff] [blame] | 2893 | if (relative_location == NULL) { |
Jon Ashburn | b682221 | 2016-02-16 15:34:16 -0700 | [diff] [blame] | 2894 | #else |
Benjamin Saunders | 31a4801 | 2017-01-29 14:49:54 -0800 | [diff] [blame] | 2895 | relative_location = NULL; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2896 | if (location == NULL) { |
Jon Ashburn | b682221 | 2016-02-16 15:34:16 -0700 | [diff] [blame] | 2897 | #endif |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2898 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 2899 | "loader_get_manifest_files: Can not get manifest files with " |
| 2900 | "NULL location, env_override=%s", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2901 | (env_override != NULL) ? env_override : ""); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2902 | res = VK_ERROR_INITIALIZATION_FAILED; |
| 2903 | goto out; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2904 | } |
| 2905 | |
Johannes van Waveren | 9bd80501 | 2015-10-28 11:45:00 -0500 | [diff] [blame] | 2906 | #if defined(_WIN32) |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2907 | list_is_dirs = (is_layer && override != NULL) ? true : false; |
Johannes van Waveren | 9bd80501 | 2015-10-28 11:45:00 -0500 | [diff] [blame] | 2908 | #else |
| 2909 | list_is_dirs = (override == NULL || is_layer) ? true : false; |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2910 | #endif |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2911 | // Make a copy of the input we are using so it is not modified |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2912 | // Also handle getting the location(s) from registry on Windows |
| 2913 | if (override == NULL) { |
Benjamin Saunders | 31a4801 | 2017-01-29 14:49:54 -0800 | [diff] [blame] | 2914 | size_t loc_size = 0; |
| 2915 | #if !defined(_WIN32) |
Mark Young | d8c6b69 | 2017-03-09 11:39:41 -0700 | [diff] [blame] | 2916 | const char *xdgconfdirs = loader_secure_getenv("XDG_CONFIG_DIRS", inst); |
| 2917 | const char *xdgdatadirs = loader_secure_getenv("XDG_DATA_DIRS", inst); |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2918 | if (xdgconfdirs == NULL || xdgconfdirs[0] == '\0') xdgconfdirs = FALLBACK_CONFIG_DIRS; |
| 2919 | if (xdgdatadirs == NULL || xdgdatadirs[0] == '\0') xdgdatadirs = FALLBACK_DATA_DIRS; |
Benjamin Saunders | 31a4801 | 2017-01-29 14:49:54 -0800 | [diff] [blame] | 2920 | const size_t rel_size = strlen(relative_location); |
| 2921 | // Leave space for trailing separators |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2922 | loc_size += strlen(xdgconfdirs) + strlen(xdgdatadirs) + 2 * rel_size + 2; |
Benjamin Saunders | 31a4801 | 2017-01-29 14:49:54 -0800 | [diff] [blame] | 2923 | for (const char *x = xdgconfdirs; *x; ++x) |
| 2924 | if (*x == PATH_SEPARATOR) loc_size += rel_size; |
| 2925 | for (const char *x = xdgdatadirs; *x; ++x) |
| 2926 | if (*x == PATH_SEPARATOR) loc_size += rel_size; |
| 2927 | loc_size += strlen(SYSCONFDIR) + rel_size + 1; |
| 2928 | #if defined(EXTRASYSCONFDIR) |
| 2929 | loc_size += strlen(EXTRASYSCONFDIR) + rel_size + 1; |
| 2930 | #endif |
| 2931 | #else |
| 2932 | loc_size += strlen(location) + 1; |
| 2933 | #endif |
| 2934 | loc = loader_stack_alloc(loc_size); |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2935 | if (loc == NULL) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2936 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 2937 | "loader_get_manifest_files: Failed to allocate " |
| 2938 | "%d bytes for manifest file location.", |
Benjamin Saunders | 31a4801 | 2017-01-29 14:49:54 -0800 | [diff] [blame] | 2939 | loc_size); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2940 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 2941 | goto out; |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2942 | } |
Benjamin Saunders | 31a4801 | 2017-01-29 14:49:54 -0800 | [diff] [blame] | 2943 | char *loc_write = loc; |
| 2944 | #if !defined(_WIN32) |
| 2945 | const char *loc_read; |
Karl Schultz | 52f5daa | 2017-02-12 12:34:03 -0700 | [diff] [blame] | 2946 | size_t start, stop; |
Benjamin Saunders | 31a4801 | 2017-01-29 14:49:54 -0800 | [diff] [blame] | 2947 | |
| 2948 | loc_read = &xdgconfdirs[0]; |
Karl Schultz | 52f5daa | 2017-02-12 12:34:03 -0700 | [diff] [blame] | 2949 | start = 0; |
| 2950 | while (loc_read[start] != '\0') { |
| 2951 | while (loc_read[start] == PATH_SEPARATOR) { |
| 2952 | start++; |
| 2953 | } |
| 2954 | stop = start; |
| 2955 | while (loc_read[stop] != PATH_SEPARATOR && loc_read[stop] != '\0') { |
| 2956 | stop++; |
| 2957 | } |
| 2958 | const size_t s = stop - start; |
| 2959 | if (s) { |
| 2960 | memcpy(loc_write, &loc_read[start], s); |
Benjamin Saunders | 31a4801 | 2017-01-29 14:49:54 -0800 | [diff] [blame] | 2961 | loc_write += s; |
| 2962 | memcpy(loc_write, relative_location, rel_size); |
| 2963 | loc_write += rel_size; |
| 2964 | *loc_write++ = PATH_SEPARATOR; |
Karl Schultz | 52f5daa | 2017-02-12 12:34:03 -0700 | [diff] [blame] | 2965 | start = stop; |
Benjamin Saunders | 31a4801 | 2017-01-29 14:49:54 -0800 | [diff] [blame] | 2966 | } |
| 2967 | } |
| 2968 | |
| 2969 | memcpy(loc_write, SYSCONFDIR, strlen(SYSCONFDIR)); |
| 2970 | loc_write += strlen(SYSCONFDIR); |
| 2971 | memcpy(loc_write, relative_location, rel_size); |
| 2972 | loc_write += rel_size; |
| 2973 | *loc_write++ = PATH_SEPARATOR; |
| 2974 | |
| 2975 | #if defined(EXTRASYSCONFDIR) |
| 2976 | memcpy(loc_write, EXTRASYSCONFDIR, strlen(EXTRASYSCONFDIR)); |
| 2977 | loc_write += strlen(EXTRASYSCONFDIR); |
| 2978 | memcpy(loc_write, relative_location, rel_size); |
| 2979 | loc_write += rel_size; |
| 2980 | *loc_write++ = PATH_SEPARATOR; |
| 2981 | #endif |
| 2982 | |
| 2983 | loc_read = &xdgdatadirs[0]; |
Karl Schultz | 52f5daa | 2017-02-12 12:34:03 -0700 | [diff] [blame] | 2984 | start = 0; |
| 2985 | while (loc_read[start] != '\0') { |
| 2986 | while (loc_read[start] == PATH_SEPARATOR) { |
| 2987 | start++; |
| 2988 | } |
| 2989 | stop = start; |
| 2990 | while (loc_read[stop] != PATH_SEPARATOR && loc_read[stop] != '\0') { |
| 2991 | stop++; |
| 2992 | } |
| 2993 | const size_t s = stop - start; |
| 2994 | if (s) { |
| 2995 | memcpy(loc_write, &loc_read[start], s); |
Benjamin Saunders | 31a4801 | 2017-01-29 14:49:54 -0800 | [diff] [blame] | 2996 | loc_write += s; |
| 2997 | memcpy(loc_write, relative_location, rel_size); |
| 2998 | loc_write += rel_size; |
| 2999 | *loc_write++ = PATH_SEPARATOR; |
Karl Schultz | 52f5daa | 2017-02-12 12:34:03 -0700 | [diff] [blame] | 3000 | start = stop; |
Benjamin Saunders | 31a4801 | 2017-01-29 14:49:54 -0800 | [diff] [blame] | 3001 | } |
| 3002 | } |
Karl Schultz | 52f5daa | 2017-02-12 12:34:03 -0700 | [diff] [blame] | 3003 | |
Benjamin Saunders | 31a4801 | 2017-01-29 14:49:54 -0800 | [diff] [blame] | 3004 | --loc_write; |
| 3005 | #else |
| 3006 | memcpy(loc_write, location, strlen(location)); |
| 3007 | loc_write += strlen(location); |
| 3008 | #endif |
| 3009 | assert(loc_write - loc < (ptrdiff_t)loc_size); |
| 3010 | *loc_write = '\0'; |
| 3011 | |
Johannes van Waveren | 9bd80501 | 2015-10-28 11:45:00 -0500 | [diff] [blame] | 3012 | #if defined(_WIN32) |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 3013 | VkResult regHKR_result = VK_SUCCESS; |
| 3014 | |
Slawomir Cygan | 8f9f255 | 2017-08-09 11:36:52 +0200 | [diff] [blame] | 3015 | DWORD reg_size = 4096; |
| 3016 | |
Lenny Komow | f7c0938 | 2017-08-31 16:35:08 -0600 | [diff] [blame] | 3017 | if (!strncmp(loc, DEFAULT_VK_DRIVERS_INFO, sizeof(DEFAULT_VK_DRIVERS_INFO))) { |
| 3018 | regHKR_result = loaderGetDeviceRegistryFiles(inst, ®, ®_size, LoaderPnpDriverRegistry()); |
| 3019 | } else if (!strncmp(loc, DEFAULT_VK_ELAYERS_INFO, sizeof(DEFAULT_VK_ELAYERS_INFO))) { |
| 3020 | regHKR_result = loaderGetDeviceRegistryFiles(inst, ®, ®_size, LoaderPnpELayerRegistry()); |
| 3021 | } else if (!strncmp(loc, DEFAULT_VK_ILAYERS_INFO, sizeof(DEFAULT_VK_ILAYERS_INFO))) { |
| 3022 | regHKR_result = loaderGetDeviceRegistryFiles(inst, ®, ®_size, LoaderPnpILayerRegistry()); |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 3023 | } |
| 3024 | |
Slawomir Cygan | 8f9f255 | 2017-08-09 11:36:52 +0200 | [diff] [blame] | 3025 | VkResult reg_result = loaderGetRegistryFiles(inst, loc, is_layer, ®, ®_size); |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 3026 | |
| 3027 | if ((VK_SUCCESS != reg_result && VK_SUCCESS != regHKR_result) || NULL == reg) { |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 3028 | if (!is_layer) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3029 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 3030 | "loader_get_manifest_files: Registry lookup failed " |
| 3031 | "to get ICD manifest files. Possibly missing Vulkan" |
| 3032 | " driver?"); |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 3033 | if (VK_SUCCESS == regHKR_result || VK_ERROR_OUT_OF_HOST_MEMORY == regHKR_result) { |
| 3034 | res = regHKR_result; |
| 3035 | } else if (VK_SUCCESS == reg_result || VK_ERROR_OUT_OF_HOST_MEMORY == reg_result) { |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 3036 | res = reg_result; |
| 3037 | } else { |
| 3038 | res = VK_ERROR_INCOMPATIBLE_DRIVER; |
| 3039 | } |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 3040 | } else { |
Mark Young | f8c2010 | 2016-11-07 16:26:17 -0700 | [diff] [blame] | 3041 | if (warn_if_not_present) { |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 3042 | // This is only a warning for layers |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3043 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 3044 | "loader_get_manifest_files: Registry lookup failed " |
| 3045 | "to get layer manifest files."); |
Mark Young | f8c2010 | 2016-11-07 16:26:17 -0700 | [diff] [blame] | 3046 | } |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 3047 | if (reg_result == VK_ERROR_OUT_OF_HOST_MEMORY) { |
| 3048 | res = reg_result; |
| 3049 | } else { |
| 3050 | // Return success for now since it's not critical for layers |
| 3051 | res = VK_SUCCESS; |
| 3052 | } |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 3053 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3054 | goto out; |
Jon Ashburn | 24265ac | 2015-07-31 09:33:21 -0600 | [diff] [blame] | 3055 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3056 | orig_loc = loc; |
| 3057 | loc = reg; |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 3058 | #endif |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3059 | } else { |
Courtney Goeltzenleuchter | 7f5aafc | 2015-07-05 11:28:29 -0600 | [diff] [blame] | 3060 | loc = loader_stack_alloc(strlen(override) + 1); |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 3061 | if (loc == NULL) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3062 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 3063 | "loader_get_manifest_files: Failed to allocate space for " |
| 3064 | "override environment variable of length %d", |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3065 | strlen(override) + 1); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3066 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 3067 | goto out; |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 3068 | } |
| 3069 | strcpy(loc, override); |
| 3070 | } |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3071 | |
Liam Middlebrook | 9b14e89 | 2015-07-23 18:32:20 -0700 | [diff] [blame] | 3072 | // Print out the paths being searched if debugging is enabled |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3073 | loader_log(inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, "Searching the following paths for manifest files: %s\n", loc); |
Liam Middlebrook | 9b14e89 | 2015-07-23 18:32:20 -0700 | [diff] [blame] | 3074 | |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3075 | file = loc; |
| 3076 | while (*file) { |
| 3077 | next_file = loader_get_next_path(file); |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 3078 | if (list_is_dirs) { |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3079 | sysdir = opendir(file); |
| 3080 | name = NULL; |
| 3081 | if (sysdir) { |
| 3082 | dent = readdir(sysdir); |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3083 | if (dent == NULL) break; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3084 | name = &(dent->d_name[0]); |
| 3085 | loader_get_fullpath(name, file, sizeof(full_path), full_path); |
| 3086 | name = full_path; |
| 3087 | } |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3088 | } else { |
Johannes van Waveren | 9bd80501 | 2015-10-28 11:45:00 -0500 | [diff] [blame] | 3089 | #if defined(_WIN32) |
| 3090 | name = file; |
| 3091 | #else |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 3092 | // only Linux has relative paths |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3093 | char *dir; |
| 3094 | // make a copy of location so it isn't modified |
Jason Ekstrand | cc7550e | 2015-10-10 08:33:37 -0700 | [diff] [blame] | 3095 | dir = loader_stack_alloc(strlen(loc) + 1); |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3096 | if (dir == NULL) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3097 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 3098 | "loader_get_manifest_files: Failed to allocate " |
| 3099 | "space for relative location path length %d", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3100 | strlen(loc) + 1); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3101 | goto out; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3102 | } |
Jason Ekstrand | cc7550e | 2015-10-10 08:33:37 -0700 | [diff] [blame] | 3103 | strcpy(dir, loc); |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3104 | |
| 3105 | loader_get_fullpath(file, dir, sizeof(full_path), full_path); |
| 3106 | |
| 3107 | name = full_path; |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 3108 | #endif |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3109 | } |
| 3110 | while (name) { |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 3111 | // Look for files ending with ".json" suffix |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3112 | uint32_t nlen = (uint32_t)strlen(name); |
| 3113 | const char *suf = name + nlen - 5; |
Lenny Komow | 408e0bd | 2017-08-09 16:01:59 -0600 | [diff] [blame] | 3114 | |
| 3115 | // Check if the file is already present |
| 3116 | bool file_already_loaded = false; |
| 3117 | for (uint32_t i = 0; i < out_files->count; ++i) { |
| 3118 | if (!strcmp(out_files->filename_list[i], name)) { |
| 3119 | file_already_loaded = true; |
| 3120 | } |
| 3121 | } |
| 3122 | |
| 3123 | if (!file_already_loaded && (nlen > 5) && !strncmp(suf, ".json", 5)) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3124 | if (out_files->count == 0) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3125 | out_files->filename_list = |
| 3126 | loader_instance_heap_alloc(inst, alloced_count * sizeof(char *), VK_SYSTEM_ALLOCATION_SCOPE_COMMAND); |
Mark Young | bb3a29c | 2017-05-19 12:29:43 -0600 | [diff] [blame] | 3127 | if (NULL == out_files->filename_list) { |
| 3128 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 3129 | "loader_get_manifest_files: Failed to allocate space for manifest file name list"); |
| 3130 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 3131 | goto out; |
| 3132 | } |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3133 | } else if (out_files->count == alloced_count) { |
Mark Young | bb3a29c | 2017-05-19 12:29:43 -0600 | [diff] [blame] | 3134 | void *new_ptr = |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3135 | loader_instance_heap_realloc(inst, out_files->filename_list, alloced_count * sizeof(char *), |
| 3136 | alloced_count * sizeof(char *) * 2, VK_SYSTEM_ALLOCATION_SCOPE_COMMAND); |
Mark Young | bb3a29c | 2017-05-19 12:29:43 -0600 | [diff] [blame] | 3137 | if (NULL == new_ptr) { |
| 3138 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 3139 | "loader_get_manifest_files: Failed to reallocate space for manifest file name list"); |
| 3140 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 3141 | goto out; |
| 3142 | } |
| 3143 | out_files->filename_list = new_ptr; |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3144 | alloced_count *= 2; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3145 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3146 | out_files->filename_list[out_files->count] = |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3147 | loader_instance_heap_alloc(inst, strlen(name) + 1, VK_SYSTEM_ALLOCATION_SCOPE_COMMAND); |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3148 | if (out_files->filename_list[out_files->count] == NULL) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3149 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 3150 | "loader_get_manifest_files: Failed to allocate " |
| 3151 | "space for manifest file %d list", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3152 | out_files->count); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3153 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 3154 | goto out; |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3155 | } |
| 3156 | strcpy(out_files->filename_list[out_files->count], name); |
| 3157 | out_files->count++; |
Lenny Komow | 408e0bd | 2017-08-09 16:01:59 -0600 | [diff] [blame] | 3158 | } else if(file_already_loaded) { |
| 3159 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 3160 | "Skipping manifest file %s - The file has already been read once", name); |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3161 | } else if (!list_is_dirs) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3162 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, "Skipping manifest file %s, file name must end in .json", |
| 3163 | name); |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3164 | } |
| 3165 | if (list_is_dirs) { |
| 3166 | dent = readdir(sysdir); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3167 | if (dent == NULL) { |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3168 | break; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3169 | } |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3170 | name = &(dent->d_name[0]); |
| 3171 | loader_get_fullpath(name, file, sizeof(full_path), full_path); |
| 3172 | name = full_path; |
| 3173 | } else { |
| 3174 | break; |
| 3175 | } |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3176 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3177 | if (sysdir) { |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3178 | closedir(sysdir); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3179 | sysdir = NULL; |
| 3180 | } |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3181 | file = next_file; |
Jon Ashburn | 67e262e | 2016-02-18 12:45:39 -0700 | [diff] [blame] | 3182 | #if !defined(_WIN32) |
Benjamin Saunders | 31a4801 | 2017-01-29 14:49:54 -0800 | [diff] [blame] | 3183 | if (relative_location != NULL && (next_file == NULL || *next_file == '\0') && override == NULL) { |
Mark Young | d8c6b69 | 2017-03-09 11:39:41 -0700 | [diff] [blame] | 3184 | char *xdgdatahome = loader_secure_getenv("XDG_DATA_HOME", inst); |
John Drinkwater | 9ac3f4f | 2016-08-01 17:00:00 +0100 | [diff] [blame] | 3185 | size_t len; |
| 3186 | if (xdgdatahome != NULL) { |
Mark Young | 6ef95f4 | 2017-02-17 09:02:23 -0700 | [diff] [blame] | 3187 | size_t alloc_len = strlen(xdgdatahome) + 2 + strlen(relative_location); |
| 3188 | char *home_loc = loader_stack_alloc(alloc_len); |
Jon Ashburn | 67e262e | 2016-02-18 12:45:39 -0700 | [diff] [blame] | 3189 | if (home_loc == NULL) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3190 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 3191 | "loader_get_manifest_files: Failed to allocate " |
| 3192 | "space for manifest file XDG Home location"); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3193 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 3194 | goto out; |
Jon Ashburn | 67e262e | 2016-02-18 12:45:39 -0700 | [diff] [blame] | 3195 | } |
John Drinkwater | 9ac3f4f | 2016-08-01 17:00:00 +0100 | [diff] [blame] | 3196 | strcpy(home_loc, xdgdatahome); |
Jon Ashburn | 67e262e | 2016-02-18 12:45:39 -0700 | [diff] [blame] | 3197 | // Add directory separator if needed |
Benjamin Saunders | 31a4801 | 2017-01-29 14:49:54 -0800 | [diff] [blame] | 3198 | if (relative_location[0] != DIRECTORY_SYMBOL) { |
Jon Ashburn | 67e262e | 2016-02-18 12:45:39 -0700 | [diff] [blame] | 3199 | len = strlen(home_loc); |
| 3200 | home_loc[len] = DIRECTORY_SYMBOL; |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 3201 | home_loc[len + 1] = '\0'; |
Jon Ashburn | 67e262e | 2016-02-18 12:45:39 -0700 | [diff] [blame] | 3202 | } |
Mark Young | 6ef95f4 | 2017-02-17 09:02:23 -0700 | [diff] [blame] | 3203 | strncat(home_loc, relative_location, alloc_len); |
Jon Ashburn | 67e262e | 2016-02-18 12:45:39 -0700 | [diff] [blame] | 3204 | file = home_loc; |
| 3205 | next_file = loader_get_next_path(file); |
Benjamin Saunders | 31a4801 | 2017-01-29 14:49:54 -0800 | [diff] [blame] | 3206 | relative_location = NULL; |
Jon Ashburn | 67e262e | 2016-02-18 12:45:39 -0700 | [diff] [blame] | 3207 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3208 | loader_log(inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, "Searching the following path for manifest files: %s\n", |
| 3209 | home_loc); |
Jon Ashburn | 67e262e | 2016-02-18 12:45:39 -0700 | [diff] [blame] | 3210 | list_is_dirs = true; |
John Drinkwater | 9ac3f4f | 2016-08-01 17:00:00 +0100 | [diff] [blame] | 3211 | |
| 3212 | } else { |
Mark Young | d8c6b69 | 2017-03-09 11:39:41 -0700 | [diff] [blame] | 3213 | char *home = loader_secure_getenv("HOME", inst); |
John Drinkwater | 9ac3f4f | 2016-08-01 17:00:00 +0100 | [diff] [blame] | 3214 | if (home != NULL) { |
Mark Young | 6ef95f4 | 2017-02-17 09:02:23 -0700 | [diff] [blame] | 3215 | size_t alloc_len = strlen(home) + 16 + strlen(relative_location); |
| 3216 | char *home_loc = loader_stack_alloc(alloc_len); |
John Drinkwater | 9ac3f4f | 2016-08-01 17:00:00 +0100 | [diff] [blame] | 3217 | if (home_loc == NULL) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3218 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 3219 | "loader_get_manifest_files: Failed to allocate " |
| 3220 | "space for manifest file Home location"); |
John Drinkwater | 9ac3f4f | 2016-08-01 17:00:00 +0100 | [diff] [blame] | 3221 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 3222 | goto out; |
| 3223 | } |
Mark Young | 6ef95f4 | 2017-02-17 09:02:23 -0700 | [diff] [blame] | 3224 | strncpy(home_loc, home, alloc_len); |
John Drinkwater | 9ac3f4f | 2016-08-01 17:00:00 +0100 | [diff] [blame] | 3225 | |
| 3226 | len = strlen(home); |
| 3227 | if (home[len] != DIRECTORY_SYMBOL) { |
| 3228 | home_loc[len] = DIRECTORY_SYMBOL; |
| 3229 | home_loc[len + 1] = '\0'; |
| 3230 | } |
Mark Young | 6ef95f4 | 2017-02-17 09:02:23 -0700 | [diff] [blame] | 3231 | strncat(home_loc, ".local/share", alloc_len); |
John Drinkwater | 9ac3f4f | 2016-08-01 17:00:00 +0100 | [diff] [blame] | 3232 | |
Benjamin Saunders | 31a4801 | 2017-01-29 14:49:54 -0800 | [diff] [blame] | 3233 | if (relative_location[0] != DIRECTORY_SYMBOL) { |
John Drinkwater | 9ac3f4f | 2016-08-01 17:00:00 +0100 | [diff] [blame] | 3234 | len = strlen(home_loc); |
| 3235 | home_loc[len] = DIRECTORY_SYMBOL; |
| 3236 | home_loc[len + 1] = '\0'; |
| 3237 | } |
Mark Young | 6ef95f4 | 2017-02-17 09:02:23 -0700 | [diff] [blame] | 3238 | strncat(home_loc, relative_location, alloc_len); |
John Drinkwater | 9ac3f4f | 2016-08-01 17:00:00 +0100 | [diff] [blame] | 3239 | file = home_loc; |
| 3240 | next_file = loader_get_next_path(file); |
Benjamin Saunders | 31a4801 | 2017-01-29 14:49:54 -0800 | [diff] [blame] | 3241 | relative_location = NULL; |
John Drinkwater | 9ac3f4f | 2016-08-01 17:00:00 +0100 | [diff] [blame] | 3242 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3243 | loader_log(inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, "Searching the following path for manifest files: %s\n", |
| 3244 | home_loc); |
John Drinkwater | 9ac3f4f | 2016-08-01 17:00:00 +0100 | [diff] [blame] | 3245 | list_is_dirs = true; |
| 3246 | } else { |
| 3247 | // without knowing HOME, we just.. give up |
| 3248 | } |
Jon Ashburn | 67e262e | 2016-02-18 12:45:39 -0700 | [diff] [blame] | 3249 | } |
| 3250 | } |
| 3251 | #endif |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3252 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3253 | |
| 3254 | out: |
| 3255 | if (VK_SUCCESS != res && NULL != out_files->filename_list) { |
| 3256 | for (uint32_t remove = 0; remove < out_files->count; remove++) { |
| 3257 | loader_instance_heap_free(inst, out_files->filename_list[remove]); |
| 3258 | } |
| 3259 | loader_instance_heap_free(inst, out_files->filename_list); |
| 3260 | out_files->count = 0; |
| 3261 | out_files->filename_list = NULL; |
| 3262 | } |
| 3263 | |
| 3264 | if (NULL != sysdir) { |
| 3265 | closedir(sysdir); |
| 3266 | } |
| 3267 | |
Frank Henigman | b1c27cb | 2016-11-24 20:02:09 -0500 | [diff] [blame] | 3268 | if (override_getenv != NULL) { |
| 3269 | loader_free_getenv(override_getenv, inst); |
| 3270 | } |
| 3271 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3272 | if (NULL != reg && reg != orig_loc) { |
| 3273 | loader_instance_heap_free(inst, reg); |
| 3274 | } |
| 3275 | return res; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3276 | } |
| 3277 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3278 | void loader_init_icd_lib_list() {} |
Jon Ashburn | 8810c5f | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 3279 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3280 | void loader_destroy_icd_lib_list() {} |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 3281 | |
| 3282 | // Try to find the Vulkan ICD driver(s). |
| 3283 | // |
| 3284 | // This function scans the default system loader path(s) or path |
| 3285 | // specified by the \c VK_ICD_FILENAMES environment variable in |
| 3286 | // order to find loadable VK ICDs manifest files. From these |
| 3287 | // manifest files it finds the ICD libraries. |
| 3288 | // |
| 3289 | // \returns |
| 3290 | // Vulkan result |
| 3291 | // (on result == VK_SUCCESS) a list of icds that were discovered |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3292 | VkResult loader_icd_scan(const struct loader_instance *inst, struct loader_icd_tramp_list *icd_tramp_list) { |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3293 | char *file_str; |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 3294 | uint16_t file_major_vers = 0; |
| 3295 | uint16_t file_minor_vers = 0; |
| 3296 | uint16_t file_patch_vers = 0; |
| 3297 | char *vers_tok; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3298 | struct loader_manifest_files manifest_files; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3299 | VkResult res = VK_SUCCESS; |
| 3300 | bool lockedMutex = false; |
| 3301 | cJSON *json = NULL; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3302 | uint32_t num_good_icds = 0; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3303 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3304 | memset(&manifest_files, 0, sizeof(struct loader_manifest_files)); |
| 3305 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 3306 | res = loader_scanned_icd_init(inst, icd_tramp_list); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3307 | if (VK_SUCCESS != res) { |
| 3308 | goto out; |
| 3309 | } |
| 3310 | |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3311 | // Get a list of manifest files for ICDs |
Benjamin Saunders | 31a4801 | 2017-01-29 14:49:54 -0800 | [diff] [blame] | 3312 | res = loader_get_manifest_files(inst, "VK_ICD_FILENAMES", NULL, false, true, DEFAULT_VK_DRIVERS_INFO, RELATIVE_VK_DRIVERS_INFO, |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3313 | &manifest_files); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3314 | if (VK_SUCCESS != res || manifest_files.count == 0) { |
| 3315 | goto out; |
| 3316 | } |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 3317 | |
Jon Ashburn | 6461ef2 | 2015-09-22 13:11:00 -0600 | [diff] [blame] | 3318 | loader_platform_thread_lock_mutex(&loader_json_lock); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3319 | lockedMutex = true; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3320 | for (uint32_t i = 0; i < manifest_files.count; i++) { |
| 3321 | file_str = manifest_files.filename_list[i]; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3322 | if (file_str == NULL) { |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3323 | continue; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3324 | } |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3325 | |
Mark Young | dcd5f7e | 2017-04-25 10:35:54 -0600 | [diff] [blame] | 3326 | VkResult temp_res = loader_get_json(inst, file_str, &json); |
| 3327 | if (NULL == json || temp_res != VK_SUCCESS) { |
Mark Young | d66edd5 | 2017-03-10 17:31:18 -0700 | [diff] [blame] | 3328 | if (NULL != json) { |
| 3329 | cJSON_Delete(json); |
| 3330 | json = NULL; |
| 3331 | } |
Mark Young | dcd5f7e | 2017-04-25 10:35:54 -0600 | [diff] [blame] | 3332 | // If we haven't already found an ICD, copy this result to |
| 3333 | // the returned result. |
| 3334 | if (num_good_icds == 0) { |
| 3335 | res = temp_res; |
| 3336 | } |
| 3337 | if (temp_res == VK_ERROR_OUT_OF_HOST_MEMORY) { |
Mark Young | d66edd5 | 2017-03-10 17:31:18 -0700 | [diff] [blame] | 3338 | break; |
| 3339 | } else { |
| 3340 | continue; |
| 3341 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3342 | } |
Mark Young | dcd5f7e | 2017-04-25 10:35:54 -0600 | [diff] [blame] | 3343 | res = temp_res; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3344 | |
Jon Ashburn | 005617f | 2015-11-17 17:35:40 -0700 | [diff] [blame] | 3345 | cJSON *item, *itemICD; |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 3346 | item = cJSON_GetObjectItem(json, "file_format_version"); |
Jon Ashburn | 6461ef2 | 2015-09-22 13:11:00 -0600 | [diff] [blame] | 3347 | if (item == NULL) { |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3348 | if (num_good_icds == 0) { |
| 3349 | res = VK_ERROR_INITIALIZATION_FAILED; |
| 3350 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3351 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 3352 | "loader_icd_scan: ICD JSON %s does not have a" |
| 3353 | " \'file_format_version\' field. Skipping ICD JSON.", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3354 | file_str); |
Derrick Owens | 62e16ef | 2016-09-09 15:49:07 -0400 | [diff] [blame] | 3355 | cJSON_Delete(json); |
| 3356 | json = NULL; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3357 | continue; |
Jon Ashburn | 6461ef2 | 2015-09-22 13:11:00 -0600 | [diff] [blame] | 3358 | } |
Mark Young | d66edd5 | 2017-03-10 17:31:18 -0700 | [diff] [blame] | 3359 | |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 3360 | char *file_vers = cJSON_Print(item); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3361 | if (NULL == file_vers) { |
Mark Young | d66edd5 | 2017-03-10 17:31:18 -0700 | [diff] [blame] | 3362 | // Only reason the print can fail is if there was an allocation issue |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3363 | if (num_good_icds == 0) { |
| 3364 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 3365 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3366 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 3367 | "loader_icd_scan: Failed retrieving ICD JSON %s" |
| 3368 | " \'file_format_version\' field. Skipping ICD JSON", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3369 | file_str); |
Derrick Owens | cd92b8b | 2016-09-09 15:45:13 -0400 | [diff] [blame] | 3370 | cJSON_Delete(json); |
| 3371 | json = NULL; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3372 | continue; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3373 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3374 | loader_log(inst, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, "Found ICD manifest file %s, version %s", file_str, file_vers); |
Mark Young | d66edd5 | 2017-03-10 17:31:18 -0700 | [diff] [blame] | 3375 | |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 3376 | // Get the major/minor/and patch as integers for easier comparison |
| 3377 | vers_tok = strtok(file_vers, ".\"\n\r"); |
| 3378 | if (NULL != vers_tok) { |
Jamie Madill | 970ebcf | 2016-07-06 11:19:42 -0400 | [diff] [blame] | 3379 | file_major_vers = (uint16_t)atoi(vers_tok); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 3380 | vers_tok = strtok(NULL, ".\"\n\r"); |
| 3381 | if (NULL != vers_tok) { |
Jamie Madill | 970ebcf | 2016-07-06 11:19:42 -0400 | [diff] [blame] | 3382 | file_minor_vers = (uint16_t)atoi(vers_tok); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 3383 | vers_tok = strtok(NULL, ".\"\n\r"); |
| 3384 | if (NULL != vers_tok) { |
Jamie Madill | 970ebcf | 2016-07-06 11:19:42 -0400 | [diff] [blame] | 3385 | file_patch_vers = (uint16_t)atoi(vers_tok); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 3386 | } |
| 3387 | } |
| 3388 | } |
Mark Young | d66edd5 | 2017-03-10 17:31:18 -0700 | [diff] [blame] | 3389 | |
| 3390 | if (file_major_vers != 1 || file_minor_vers != 0 || file_patch_vers > 1) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3391 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 3392 | "loader_icd_scan: Unexpected manifest file version " |
| 3393 | "(expected 1.0.0 or 1.0.1), may cause errors"); |
Mark Young | d66edd5 | 2017-03-10 17:31:18 -0700 | [diff] [blame] | 3394 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3395 | cJSON_Free(file_vers); |
Mark Young | d66edd5 | 2017-03-10 17:31:18 -0700 | [diff] [blame] | 3396 | |
Jon Ashburn | 005617f | 2015-11-17 17:35:40 -0700 | [diff] [blame] | 3397 | itemICD = cJSON_GetObjectItem(json, "ICD"); |
| 3398 | if (itemICD != NULL) { |
| 3399 | item = cJSON_GetObjectItem(itemICD, "library_path"); |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 3400 | if (item != NULL) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3401 | char *temp = cJSON_Print(item); |
Jon Ashburn | 8625130 | 2015-08-25 16:48:24 -0600 | [diff] [blame] | 3402 | if (!temp || strlen(temp) == 0) { |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3403 | if (num_good_icds == 0) { |
| 3404 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 3405 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3406 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 3407 | "loader_icd_scan: Failed retrieving ICD JSON %s" |
| 3408 | " \'library_path\' field. Skipping ICD JSON.", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3409 | file_str); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3410 | cJSON_Free(temp); |
Jon Ashburn | 8625130 | 2015-08-25 16:48:24 -0600 | [diff] [blame] | 3411 | cJSON_Delete(json); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3412 | json = NULL; |
Jon Ashburn | 8625130 | 2015-08-25 16:48:24 -0600 | [diff] [blame] | 3413 | continue; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3414 | } |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3415 | // strip out extra quotes |
Jon Ashburn | 8625130 | 2015-08-25 16:48:24 -0600 | [diff] [blame] | 3416 | temp[strlen(temp) - 1] = '\0'; |
| 3417 | char *library_path = loader_stack_alloc(strlen(temp) + 1); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3418 | if (NULL == library_path) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3419 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 3420 | "loader_icd_scan: Failed to allocate space for " |
| 3421 | "ICD JSON %s \'library_path\' value. Skipping " |
| 3422 | "ICD JSON.", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3423 | file_str); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3424 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 3425 | cJSON_Free(temp); |
| 3426 | cJSON_Delete(json); |
| 3427 | json = NULL; |
| 3428 | goto out; |
| 3429 | } |
Jon Ashburn | 8625130 | 2015-08-25 16:48:24 -0600 | [diff] [blame] | 3430 | strcpy(library_path, &temp[1]); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3431 | cJSON_Free(temp); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3432 | if (strlen(library_path) == 0) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3433 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 3434 | "loader_icd_scan: ICD JSON %s \'library_path\'" |
| 3435 | " field is empty. Skipping ICD JSON.", |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3436 | file_str); |
Jon Ashburn | 8625130 | 2015-08-25 16:48:24 -0600 | [diff] [blame] | 3437 | cJSON_Delete(json); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3438 | json = NULL; |
Jon Ashburn | 8625130 | 2015-08-25 16:48:24 -0600 | [diff] [blame] | 3439 | continue; |
| 3440 | } |
Jamie Madill | 2fcbd15 | 2016-04-27 16:33:23 -0400 | [diff] [blame] | 3441 | char fullpath[MAX_STRING_SIZE]; |
Jon Ashburn | 8625130 | 2015-08-25 16:48:24 -0600 | [diff] [blame] | 3442 | // Print out the paths being searched if debugging is enabled |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3443 | loader_log(inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, "Searching for ICD drivers named %s, using default dir %s", |
| 3444 | library_path, DEFAULT_VK_DRIVERS_PATH); |
Daniel Dadap | 00b4aba | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 3445 | if (loader_platform_is_path(library_path)) { |
Jon Ashburn | 8625130 | 2015-08-25 16:48:24 -0600 | [diff] [blame] | 3446 | // a relative or absolute path |
Daniel Dadap | 00b4aba | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 3447 | char *name_copy = loader_stack_alloc(strlen(file_str) + 1); |
| 3448 | char *rel_base; |
Jon Ashburn | 8625130 | 2015-08-25 16:48:24 -0600 | [diff] [blame] | 3449 | strcpy(name_copy, file_str); |
| 3450 | rel_base = loader_platform_dirname(name_copy); |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3451 | loader_expand_path(library_path, rel_base, sizeof(fullpath), fullpath); |
Daniel Dadap | 00b4aba | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 3452 | } else { |
Jamie Madill | 2fcbd15 | 2016-04-27 16:33:23 -0400 | [diff] [blame] | 3453 | // a filename which is assumed in a system directory |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3454 | loader_get_fullpath(library_path, DEFAULT_VK_DRIVERS_PATH, sizeof(fullpath), fullpath); |
Jon Ashburn | 8625130 | 2015-08-25 16:48:24 -0600 | [diff] [blame] | 3455 | } |
Jon Ashburn | 005617f | 2015-11-17 17:35:40 -0700 | [diff] [blame] | 3456 | |
| 3457 | uint32_t vers = 0; |
| 3458 | item = cJSON_GetObjectItem(itemICD, "api_version"); |
| 3459 | if (item != NULL) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3460 | temp = cJSON_Print(item); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3461 | if (NULL == temp) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3462 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 3463 | "loader_icd_scan: Failed retrieving ICD JSON %s" |
| 3464 | " \'api_version\' field. Skipping ICD JSON.", |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3465 | file_str); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3466 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3467 | // Only reason the print can fail is if there was an |
| 3468 | // allocation issue |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3469 | if (num_good_icds == 0) { |
| 3470 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 3471 | } |
| 3472 | |
| 3473 | cJSON_Free(temp); |
| 3474 | cJSON_Delete(json); |
| 3475 | json = NULL; |
| 3476 | continue; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3477 | } |
Jon Ashburn | 005617f | 2015-11-17 17:35:40 -0700 | [diff] [blame] | 3478 | vers = loader_make_version(temp); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3479 | cJSON_Free(temp); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3480 | } else { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3481 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 3482 | "loader_icd_scan: ICD JSON %s does not have an" |
| 3483 | " \'api_version\' field.", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3484 | file_str); |
Jon Ashburn | 005617f | 2015-11-17 17:35:40 -0700 | [diff] [blame] | 3485 | } |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3486 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3487 | res = loader_scanned_icd_add(inst, icd_tramp_list, fullpath, vers); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3488 | if (VK_SUCCESS != res) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3489 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 3490 | "loader_icd_scan: Failed to add ICD JSON %s. " |
| 3491 | " Skipping ICD JSON.", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3492 | fullpath); |
Mark Young | d66edd5 | 2017-03-10 17:31:18 -0700 | [diff] [blame] | 3493 | cJSON_Delete(json); |
| 3494 | json = NULL; |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3495 | continue; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3496 | } |
| 3497 | num_good_icds++; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3498 | } else { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3499 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 3500 | "loader_icd_scan: Failed to find \'library_path\' " |
| 3501 | "object in ICD JSON file %s. Skipping ICD JSON.", |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3502 | file_str); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3503 | } |
| 3504 | } else { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3505 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 3506 | "loader_icd_scan: Can not find \'ICD\' object in ICD JSON " |
| 3507 | "file %s. Skipping ICD JSON", |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3508 | file_str); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3509 | } |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3510 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3511 | cJSON_Delete(json); |
| 3512 | json = NULL; |
| 3513 | } |
| 3514 | |
| 3515 | out: |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3516 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3517 | if (NULL != json) { |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3518 | cJSON_Delete(json); |
| 3519 | } |
Mark Young | d66edd5 | 2017-03-10 17:31:18 -0700 | [diff] [blame] | 3520 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3521 | if (NULL != manifest_files.filename_list) { |
| 3522 | for (uint32_t i = 0; i < manifest_files.count; i++) { |
| 3523 | if (NULL != manifest_files.filename_list[i]) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3524 | loader_instance_heap_free(inst, manifest_files.filename_list[i]); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3525 | } |
| 3526 | } |
| 3527 | loader_instance_heap_free(inst, manifest_files.filename_list); |
| 3528 | } |
| 3529 | if (lockedMutex) { |
| 3530 | loader_platform_thread_unlock_mutex(&loader_json_lock); |
| 3531 | } |
Mark Young | d66edd5 | 2017-03-10 17:31:18 -0700 | [diff] [blame] | 3532 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3533 | return res; |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 3534 | } |
| 3535 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3536 | void loader_layer_scan(const struct loader_instance *inst, struct loader_layer_list *instance_layers) { |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 3537 | char *file_str; |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3538 | struct loader_manifest_files manifest_files[2]; // [0] = explicit, [1] = implicit |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 3539 | cJSON *json; |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3540 | uint32_t implicit; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3541 | bool lockedMutex = false; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 3542 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3543 | memset(manifest_files, 0, sizeof(struct loader_manifest_files) * 2); |
| 3544 | |
| 3545 | // Get a list of manifest files for explicit layers |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3546 | if (VK_SUCCESS != loader_get_manifest_files(inst, LAYERS_PATH_ENV, LAYERS_SOURCE_PATH, true, true, DEFAULT_VK_ELAYERS_INFO, |
Benjamin Saunders | 31a4801 | 2017-01-29 14:49:54 -0800 | [diff] [blame] | 3547 | RELATIVE_VK_ELAYERS_INFO, &manifest_files[0])) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3548 | goto out; |
| 3549 | } |
| 3550 | |
| 3551 | // Get a list of manifest files for any implicit layers |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3552 | // Pass NULL for environment variable override - implicit layers are not |
| 3553 | // overridden by LAYERS_PATH_ENV |
Benjamin Saunders | 31a4801 | 2017-01-29 14:49:54 -0800 | [diff] [blame] | 3554 | if (VK_SUCCESS != loader_get_manifest_files(inst, NULL, NULL, true, false, DEFAULT_VK_ILAYERS_INFO, RELATIVE_VK_ILAYERS_INFO, |
Mark Young | f8c2010 | 2016-11-07 16:26:17 -0700 | [diff] [blame] | 3555 | &manifest_files[1])) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3556 | goto out; |
| 3557 | } |
Jon Ashburn | 90c6a0e | 2015-06-04 15:30:58 -0600 | [diff] [blame] | 3558 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3559 | // Make sure we have at least one layer, if not, go ahead and return |
| 3560 | if (manifest_files[0].count == 0 && manifest_files[1].count == 0) { |
| 3561 | goto out; |
| 3562 | } |
| 3563 | |
| 3564 | // cleanup any previously scanned libraries |
Jon Ashburn | e39a4f8 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 3565 | loader_delete_layer_properties(inst, instance_layers); |
Jon Ashburn | b2ef137 | 2015-07-16 17:19:31 -0600 | [diff] [blame] | 3566 | |
Jon Ashburn | 6461ef2 | 2015-09-22 13:11:00 -0600 | [diff] [blame] | 3567 | loader_platform_thread_lock_mutex(&loader_json_lock); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3568 | lockedMutex = true; |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3569 | for (implicit = 0; implicit < 2; implicit++) { |
Jamie Madill | 970ebcf | 2016-07-06 11:19:42 -0400 | [diff] [blame] | 3570 | for (uint32_t i = 0; i < manifest_files[implicit].count; i++) { |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3571 | file_str = manifest_files[implicit].filename_list[i]; |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3572 | if (file_str == NULL) continue; |
Courtney Goeltzenleuchter | a9e4af4 | 2015-06-01 14:49:17 -0600 | [diff] [blame] | 3573 | |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3574 | // parse file into JSON struct |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3575 | VkResult res = loader_get_json(inst, file_str, &json); |
| 3576 | if (VK_ERROR_OUT_OF_HOST_MEMORY == res) { |
| 3577 | break; |
| 3578 | } else if (VK_SUCCESS != res || NULL == json) { |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3579 | continue; |
| 3580 | } |
| 3581 | |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 3582 | VkResult local_res = loader_add_layer_properties(inst, instance_layers, json, (implicit == 1), file_str); |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3583 | cJSON_Delete(json); |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 3584 | |
| 3585 | if (VK_SUCCESS != local_res) { |
| 3586 | goto out; |
| 3587 | } |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 3588 | } |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 3589 | } |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 3590 | |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 3591 | // See if "VK_LAYER_LUNARG_standard_validation" already in list. |
| 3592 | bool found_std_val = false; |
| 3593 | for (uint32_t i = 0; i < instance_layers->count; i++) { |
| 3594 | struct loader_layer_properties *props = &instance_layers->list[i]; |
| 3595 | if (strcmp(props->info.layerName, std_validation_str) == 0) { |
| 3596 | found_std_val = true; |
| 3597 | break; |
| 3598 | } |
| 3599 | } |
| 3600 | |
| 3601 | // If we didn't find the VK_LAYER_LUNARG_standard_validation meta-layer in |
| 3602 | // the list, then we need to add it manually. This is likely because we're |
| 3603 | // dealing with a new loader, but an old layer folder. |
| 3604 | if (!found_std_val && !loader_add_legacy_std_val_layer(inst, instance_layers)) { |
| 3605 | goto out; |
| 3606 | } |
| 3607 | |
| 3608 | // Verify any meta-layers in the list are valid and all the component layers are |
| 3609 | // actually present in the available layer list |
| 3610 | verify_all_meta_layers(inst, instance_layers); |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 3611 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3612 | out: |
| 3613 | |
| 3614 | for (uint32_t manFile = 0; manFile < 2; manFile++) { |
| 3615 | if (NULL != manifest_files[manFile].filename_list) { |
| 3616 | for (uint32_t i = 0; i < manifest_files[manFile].count; i++) { |
| 3617 | if (NULL != manifest_files[manFile].filename_list[i]) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3618 | loader_instance_heap_free(inst, manifest_files[manFile].filename_list[i]); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3619 | } |
| 3620 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3621 | loader_instance_heap_free(inst, manifest_files[manFile].filename_list); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3622 | } |
| 3623 | } |
| 3624 | if (lockedMutex) { |
| 3625 | loader_platform_thread_unlock_mutex(&loader_json_lock); |
| 3626 | } |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 3627 | } |
| 3628 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3629 | void loader_implicit_layer_scan(const struct loader_instance *inst, struct loader_layer_list *instance_layers) { |
Jeremy Hayes | 3e2bd5a | 2016-04-01 11:40:26 -0600 | [diff] [blame] | 3630 | char *file_str; |
| 3631 | struct loader_manifest_files manifest_files; |
| 3632 | cJSON *json; |
| 3633 | uint32_t i; |
| 3634 | |
| 3635 | // Pass NULL for environment variable override - implicit layers are not |
| 3636 | // overridden by LAYERS_PATH_ENV |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 3637 | VkResult res = loader_get_manifest_files(inst, NULL, NULL, true, false, DEFAULT_VK_ILAYERS_INFO, RELATIVE_VK_ILAYERS_INFO, |
| 3638 | &manifest_files); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3639 | if (VK_SUCCESS != res || manifest_files.count == 0) { |
Jeremy Hayes | 3e2bd5a | 2016-04-01 11:40:26 -0600 | [diff] [blame] | 3640 | return; |
| 3641 | } |
| 3642 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 3643 | // Cleanup any previously scanned libraries |
Jeremy Hayes | 3e2bd5a | 2016-04-01 11:40:26 -0600 | [diff] [blame] | 3644 | loader_delete_layer_properties(inst, instance_layers); |
Jeremy Hayes | 3e2bd5a | 2016-04-01 11:40:26 -0600 | [diff] [blame] | 3645 | |
| 3646 | loader_platform_thread_lock_mutex(&loader_json_lock); |
| 3647 | |
| 3648 | for (i = 0; i < manifest_files.count; i++) { |
| 3649 | file_str = manifest_files.filename_list[i]; |
| 3650 | if (file_str == NULL) { |
| 3651 | continue; |
| 3652 | } |
| 3653 | |
| 3654 | // parse file into JSON struct |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3655 | res = loader_get_json(inst, file_str, &json); |
| 3656 | if (VK_ERROR_OUT_OF_HOST_MEMORY == res) { |
| 3657 | break; |
| 3658 | } else if (VK_SUCCESS != res || NULL == json) { |
Jeremy Hayes | 3e2bd5a | 2016-04-01 11:40:26 -0600 | [diff] [blame] | 3659 | continue; |
| 3660 | } |
| 3661 | |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 3662 | res = loader_add_layer_properties(inst, instance_layers, json, true, file_str); |
Jeremy Hayes | 3e2bd5a | 2016-04-01 11:40:26 -0600 | [diff] [blame] | 3663 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3664 | loader_instance_heap_free(inst, file_str); |
Jeremy Hayes | 3e2bd5a | 2016-04-01 11:40:26 -0600 | [diff] [blame] | 3665 | cJSON_Delete(json); |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 3666 | |
| 3667 | if (VK_ERROR_OUT_OF_HOST_MEMORY == res) { |
| 3668 | break; |
| 3669 | } |
Jeremy Hayes | 3e2bd5a | 2016-04-01 11:40:26 -0600 | [diff] [blame] | 3670 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3671 | loader_instance_heap_free(inst, manifest_files.filename_list); |
Jeremy Hayes | 3e2bd5a | 2016-04-01 11:40:26 -0600 | [diff] [blame] | 3672 | loader_platform_thread_unlock_mutex(&loader_json_lock); |
| 3673 | } |
| 3674 | |
Jean-Francois Roy | bd7ceab | 2017-07-06 14:10:13 -0700 | [diff] [blame] | 3675 | // Check if an implicit layer should be enabled. |
| 3676 | bool loader_is_implicit_layer_enabled(const struct loader_instance *inst, const struct loader_layer_properties *prop) { |
| 3677 | bool enable = false; |
| 3678 | char *env_value = NULL; |
| 3679 | |
| 3680 | // if no enable_environment variable is specified, this implicit layer |
| 3681 | // should always be enabled. Otherwise check if the variable is set |
| 3682 | if (prop->enable_env_var.name[0] == 0) { |
| 3683 | enable = true; |
| 3684 | } else { |
| 3685 | env_value = loader_secure_getenv(prop->enable_env_var.name, inst); |
| 3686 | if (env_value && !strcmp(prop->enable_env_var.value, env_value)) enable = true; |
| 3687 | loader_free_getenv(env_value, inst); |
| 3688 | } |
| 3689 | |
| 3690 | // disable_environment has priority, i.e. if both enable and disable |
| 3691 | // environment variables are set, the layer is disabled. Implicit |
| 3692 | // layers are required to have a disable_environment variables |
| 3693 | env_value = loader_secure_getenv(prop->disable_env_var.name, inst); |
| 3694 | if (env_value && !strcmp(prop->disable_env_var.value, env_value)) enable = false; |
| 3695 | loader_free_getenv(env_value, inst); |
| 3696 | |
| 3697 | return enable; |
| 3698 | } |
| 3699 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3700 | static VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL loader_gpdpa_instance_internal(VkInstance inst, const char *pName) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3701 | // inst is not wrapped |
| 3702 | if (inst == VK_NULL_HANDLE) { |
| 3703 | return NULL; |
| 3704 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3705 | VkLayerInstanceDispatchTable *disp_table = *(VkLayerInstanceDispatchTable **)inst; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3706 | void *addr; |
| 3707 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3708 | if (disp_table == NULL) return NULL; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3709 | |
| 3710 | bool found_name; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3711 | addr = loader_lookup_instance_dispatch_table(disp_table, pName, &found_name); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3712 | if (found_name) { |
| 3713 | return addr; |
| 3714 | } |
| 3715 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3716 | if (loader_phys_dev_ext_gpa(loader_get_instance(inst), pName, true, NULL, &addr)) return addr; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3717 | |
| 3718 | // Don't call down the chain, this would be an infinite loop |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3719 | loader_log(NULL, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, "loader_gpdpa_instance_internal() unrecognized name %s", pName); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3720 | return NULL; |
| 3721 | } |
| 3722 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3723 | static VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL loader_gpdpa_instance_terminator(VkInstance inst, const char *pName) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3724 | // inst is not wrapped |
| 3725 | if (inst == VK_NULL_HANDLE) { |
| 3726 | return NULL; |
| 3727 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3728 | VkLayerInstanceDispatchTable *disp_table = *(VkLayerInstanceDispatchTable **)inst; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3729 | void *addr; |
| 3730 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3731 | if (disp_table == NULL) return NULL; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3732 | |
| 3733 | bool found_name; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3734 | addr = loader_lookup_instance_dispatch_table(disp_table, pName, &found_name); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3735 | if (found_name) { |
| 3736 | return addr; |
| 3737 | } |
| 3738 | |
| 3739 | // Get the terminator, but don't perform checking since it should already |
| 3740 | // have been setup if we get here. |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3741 | if (loader_phys_dev_ext_gpa(loader_get_instance(inst), pName, false, NULL, &addr)) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3742 | return addr; |
| 3743 | } |
| 3744 | |
| 3745 | // Don't call down the chain, this would be an infinite loop |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3746 | loader_log(NULL, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, "loader_gpdpa_instance_terminator() unrecognized name %s", pName); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3747 | return NULL; |
| 3748 | } |
| 3749 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3750 | static VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL loader_gpa_instance_internal(VkInstance inst, const char *pName) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3751 | if (!strcmp(pName, "vkGetInstanceProcAddr")) { |
| 3752 | return (PFN_vkVoidFunction)loader_gpa_instance_internal; |
| 3753 | } |
| 3754 | if (!strcmp(pName, "vk_layerGetPhysicalDeviceProcAddr")) { |
| 3755 | return (PFN_vkVoidFunction)loader_gpdpa_instance_terminator; |
| 3756 | } |
| 3757 | if (!strcmp(pName, "vkCreateInstance")) { |
| 3758 | return (PFN_vkVoidFunction)terminator_CreateInstance; |
| 3759 | } |
| 3760 | if (!strcmp(pName, "vkCreateDevice")) { |
| 3761 | return (PFN_vkVoidFunction)terminator_CreateDevice; |
| 3762 | } |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3763 | |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 3764 | // inst is not wrapped |
| 3765 | if (inst == VK_NULL_HANDLE) { |
| 3766 | return NULL; |
| 3767 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3768 | VkLayerInstanceDispatchTable *disp_table = *(VkLayerInstanceDispatchTable **)inst; |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 3769 | void *addr; |
| 3770 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3771 | if (disp_table == NULL) return NULL; |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 3772 | |
Jon Ashburn | c7d3e73 | 2016-03-08 09:30:30 -0700 | [diff] [blame] | 3773 | bool found_name; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3774 | addr = loader_lookup_instance_dispatch_table(disp_table, pName, &found_name); |
Jon Ashburn | c7d3e73 | 2016-03-08 09:30:30 -0700 | [diff] [blame] | 3775 | if (found_name) { |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 3776 | return addr; |
Jon Ashburn | 3d526cb | 2015-04-13 18:10:06 -0600 | [diff] [blame] | 3777 | } |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3778 | |
Jon Ashburn | c7d3e73 | 2016-03-08 09:30:30 -0700 | [diff] [blame] | 3779 | // Don't call down the chain, this would be an infinite loop |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3780 | loader_log(NULL, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, "loader_gpa_instance_internal() unrecognized name %s", pName); |
Jon Ashburn | c7d3e73 | 2016-03-08 09:30:30 -0700 | [diff] [blame] | 3781 | return NULL; |
Jon Ashburn | 3d526cb | 2015-04-13 18:10:06 -0600 | [diff] [blame] | 3782 | } |
| 3783 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3784 | VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL loader_gpa_device_internal(VkDevice device, const char *pName) { |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 3785 | struct loader_device *dev; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3786 | struct loader_icd_term *icd_term = loader_get_icd_and_device(device, &dev, NULL); |
Mark Young | 16573c7 | 2016-06-28 10:52:43 -0600 | [diff] [blame] | 3787 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 3788 | // Return this function if a layer above here is asking for the vkGetDeviceProcAddr. |
| 3789 | // This is so we can properly intercept any device commands needing a terminator. |
| 3790 | if (!strcmp(pName, "vkGetDeviceProcAddr")) { |
| 3791 | return (PFN_vkVoidFunction)loader_gpa_device_internal; |
| 3792 | } |
| 3793 | |
Mark Young | 65cb366 | 2016-11-07 13:27:02 -0700 | [diff] [blame] | 3794 | // NOTE: Device Funcs needing Trampoline/Terminator. |
| 3795 | // Overrides for device functions needing a trampoline and |
| 3796 | // a terminator because certain device entry-points still need to go |
| 3797 | // through a terminator before hitting the ICD. This could be for |
| 3798 | // several reasons, but the main one is currently unwrapping an |
| 3799 | // object before passing the appropriate info along to the ICD. |
| 3800 | // This is why we also have to override the direct ICD call to |
| 3801 | // vkGetDeviceProcAddr to intercept those calls. |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 3802 | PFN_vkVoidFunction addr = get_extension_device_proc_terminator(pName); |
| 3803 | if (NULL != addr) { |
| 3804 | return addr; |
Mark Young | 16573c7 | 2016-06-28 10:52:43 -0600 | [diff] [blame] | 3805 | } |
| 3806 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 3807 | return icd_term->dispatch.GetDeviceProcAddr(device, pName); |
Piers Daniell | 295fe40 | 2016-03-29 11:51:11 -0600 | [diff] [blame] | 3808 | } |
| 3809 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 3810 | // Initialize device_ext dispatch table entry as follows: |
| 3811 | // If dev == NULL find all logical devices created within this instance and |
| 3812 | // init the entry (given by idx) in the ext dispatch table. |
| 3813 | // If dev != NULL only initialize the entry in the given dev's dispatch table. |
| 3814 | // The initialization value is gotten by calling down the device chain with |
| 3815 | // GDPA. |
| 3816 | // If GDPA returns NULL then don't initialize the dispatch table entry. |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3817 | static void loader_init_dispatch_dev_ext_entry(struct loader_instance *inst, struct loader_device *dev, uint32_t idx, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3818 | const char *funcName) |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3819 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3820 | { |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3821 | void *gdpa_value; |
| 3822 | if (dev != NULL) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3823 | gdpa_value = dev->loader_dispatch.core_dispatch.GetDeviceProcAddr(dev->chain_device, funcName); |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3824 | if (gdpa_value != NULL) dev->loader_dispatch.ext_dispatch.dev_ext[idx] = (PFN_vkDevExt)gdpa_value; |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3825 | } else { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3826 | for (struct loader_icd_term *icd_term = inst->icd_terms; icd_term != NULL; icd_term = icd_term->next) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 3827 | struct loader_device *ldev = icd_term->logical_device_list; |
Karl Schultz | 2558bd3 | 2016-02-24 14:39:39 -0700 | [diff] [blame] | 3828 | while (ldev) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3829 | gdpa_value = ldev->loader_dispatch.core_dispatch.GetDeviceProcAddr(ldev->chain_device, funcName); |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3830 | if (gdpa_value != NULL) ldev->loader_dispatch.ext_dispatch.dev_ext[idx] = (PFN_vkDevExt)gdpa_value; |
Karl Schultz | 2558bd3 | 2016-02-24 14:39:39 -0700 | [diff] [blame] | 3831 | ldev = ldev->next; |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3832 | } |
| 3833 | } |
| 3834 | } |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3835 | } |
| 3836 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 3837 | // Find all dev extension in the hash table and initialize the dispatch table |
| 3838 | // for dev for each of those extension entrypoints found in hash table. |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3839 | void loader_init_dispatch_dev_ext(struct loader_instance *inst, struct loader_device *dev) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3840 | for (uint32_t i = 0; i < MAX_NUM_UNKNOWN_EXTS; i++) { |
| 3841 | if (inst->dev_ext_disp_hash[i].func_name != NULL) |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3842 | loader_init_dispatch_dev_ext_entry(inst, dev, i, inst->dev_ext_disp_hash[i].func_name); |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3843 | } |
| 3844 | } |
| 3845 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3846 | static bool loader_check_icds_for_dev_ext_address(struct loader_instance *inst, const char *funcName) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 3847 | struct loader_icd_term *icd_term; |
| 3848 | icd_term = inst->icd_terms; |
| 3849 | while (NULL != icd_term) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3850 | if (icd_term->scanned_icd->GetInstanceProcAddr(icd_term->instance, funcName)) |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3851 | // this icd supports funcName |
| 3852 | return true; |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 3853 | icd_term = icd_term->next; |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3854 | } |
| 3855 | |
| 3856 | return false; |
| 3857 | } |
| 3858 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3859 | static bool loader_check_layer_list_for_dev_ext_address(const struct loader_layer_list *const layers, const char *funcName) { |
Jeremy Hayes | 1eb1f62 | 2016-03-03 16:03:03 -0700 | [diff] [blame] | 3860 | // Iterate over the layers. |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 3861 | for (uint32_t layer = 0; layer < layers->count; ++layer) { |
Jeremy Hayes | 1eb1f62 | 2016-03-03 16:03:03 -0700 | [diff] [blame] | 3862 | // Iterate over the extensions. |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3863 | const struct loader_device_extension_list *const extensions = &(layers->list[layer].device_extension_list); |
| 3864 | for (uint32_t extension = 0; extension < extensions->count; ++extension) { |
Jeremy Hayes | 1eb1f62 | 2016-03-03 16:03:03 -0700 | [diff] [blame] | 3865 | // Iterate over the entry points. |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3866 | const struct loader_dev_ext_props *const property = &(extensions->list[extension]); |
| 3867 | for (uint32_t entry = 0; entry < property->entrypoint_count; ++entry) { |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 3868 | if (strcmp(property->entrypoints[entry], funcName) == 0) { |
Jeremy Hayes | 1eb1f62 | 2016-03-03 16:03:03 -0700 | [diff] [blame] | 3869 | return true; |
| 3870 | } |
| 3871 | } |
| 3872 | } |
| 3873 | } |
| 3874 | |
| 3875 | return false; |
| 3876 | } |
| 3877 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3878 | static void loader_free_dev_ext_table(struct loader_instance *inst) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3879 | for (uint32_t i = 0; i < MAX_NUM_UNKNOWN_EXTS; i++) { |
| 3880 | loader_instance_heap_free(inst, inst->dev_ext_disp_hash[i].func_name); |
| 3881 | loader_instance_heap_free(inst, inst->dev_ext_disp_hash[i].list.index); |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3882 | } |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3883 | memset(inst->dev_ext_disp_hash, 0, sizeof(inst->dev_ext_disp_hash)); |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3884 | } |
| 3885 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3886 | static bool loader_add_dev_ext_table(struct loader_instance *inst, uint32_t *ptr_idx, const char *funcName) { |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3887 | uint32_t i; |
| 3888 | uint32_t idx = *ptr_idx; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3889 | struct loader_dispatch_hash_list *list = &inst->dev_ext_disp_hash[idx].list; |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3890 | |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3891 | if (!inst->dev_ext_disp_hash[idx].func_name) { |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3892 | // no entry here at this idx, so use it |
| 3893 | assert(list->capacity == 0); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3894 | inst->dev_ext_disp_hash[idx].func_name = |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3895 | (char *)loader_instance_heap_alloc(inst, strlen(funcName) + 1, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3896 | if (inst->dev_ext_disp_hash[idx].func_name == NULL) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3897 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 3898 | "loader_add_dev_ext_table: Failed to allocate memory " |
| 3899 | "for func_name %s", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3900 | funcName); |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3901 | return false; |
| 3902 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3903 | strncpy(inst->dev_ext_disp_hash[idx].func_name, funcName, strlen(funcName) + 1); |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3904 | return true; |
| 3905 | } |
| 3906 | |
| 3907 | // check for enough capacity |
| 3908 | if (list->capacity == 0) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3909 | list->index = loader_instance_heap_alloc(inst, 8 * sizeof(*(list->index)), VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3910 | if (list->index == NULL) { |
Mark Young | bb3a29c | 2017-05-19 12:29:43 -0600 | [diff] [blame] | 3911 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, "loader_add_dev_ext_table: Failed to allocate memory for list index", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3912 | funcName); |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3913 | return false; |
| 3914 | } |
| 3915 | list->capacity = 8 * sizeof(*(list->index)); |
| 3916 | } else if (list->capacity < (list->count + 1) * sizeof(*(list->index))) { |
Mark Young | bb3a29c | 2017-05-19 12:29:43 -0600 | [diff] [blame] | 3917 | void *new_ptr = loader_instance_heap_realloc(inst, list->index, list->capacity, list->capacity * 2, |
| 3918 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
| 3919 | if (NULL == new_ptr) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3920 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | bb3a29c | 2017-05-19 12:29:43 -0600 | [diff] [blame] | 3921 | "loader_add_dev_ext_table: Failed to reallocate memory for list index", funcName); |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3922 | return false; |
| 3923 | } |
Mark Young | bb3a29c | 2017-05-19 12:29:43 -0600 | [diff] [blame] | 3924 | list->index = new_ptr; |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3925 | list->capacity *= 2; |
| 3926 | } |
| 3927 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3928 | // find an unused index in the hash table and use it |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3929 | i = (idx + 1) % MAX_NUM_UNKNOWN_EXTS; |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3930 | do { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3931 | if (!inst->dev_ext_disp_hash[i].func_name) { |
| 3932 | assert(inst->dev_ext_disp_hash[i].list.capacity == 0); |
| 3933 | inst->dev_ext_disp_hash[i].func_name = |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3934 | (char *)loader_instance_heap_alloc(inst, strlen(funcName) + 1, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3935 | if (inst->dev_ext_disp_hash[i].func_name == NULL) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3936 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 3937 | "loader_add_dev_ext_table: Failed to allocate memory " |
| 3938 | "for func_name %s", |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3939 | funcName); |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3940 | return false; |
| 3941 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3942 | strncpy(inst->dev_ext_disp_hash[i].func_name, funcName, strlen(funcName) + 1); |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3943 | list->index[list->count] = i; |
| 3944 | list->count++; |
| 3945 | *ptr_idx = i; |
| 3946 | return true; |
| 3947 | } |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3948 | i = (i + 1) % MAX_NUM_UNKNOWN_EXTS; |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3949 | } while (i != idx); |
| 3950 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3951 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 3952 | "loader_add_dev_ext_table: Could not insert into hash table; is " |
| 3953 | "it full?"); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3954 | |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3955 | return false; |
| 3956 | } |
| 3957 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3958 | static bool loader_name_in_dev_ext_table(struct loader_instance *inst, uint32_t *idx, const char *funcName) { |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3959 | uint32_t alt_idx; |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3960 | if (inst->dev_ext_disp_hash[*idx].func_name && !strcmp(inst->dev_ext_disp_hash[*idx].func_name, funcName)) return true; |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3961 | |
| 3962 | // funcName wasn't at the primary spot in the hash table |
| 3963 | // search the list of secondary locations (shallow search, not deep search) |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3964 | for (uint32_t i = 0; i < inst->dev_ext_disp_hash[*idx].list.count; i++) { |
| 3965 | alt_idx = inst->dev_ext_disp_hash[*idx].list.index[i]; |
| 3966 | if (!strcmp(inst->dev_ext_disp_hash[*idx].func_name, funcName)) { |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3967 | *idx = alt_idx; |
| 3968 | return true; |
| 3969 | } |
| 3970 | } |
| 3971 | |
| 3972 | return false; |
| 3973 | } |
| 3974 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 3975 | // This function returns generic trampoline code address for unknown entry |
| 3976 | // points. |
| 3977 | // Presumably, these unknown entry points (as given by funcName) are device |
| 3978 | // extension entrypoints. A hash table is used to keep a list of unknown entry |
| 3979 | // points and their mapping to the device extension dispatch table |
| 3980 | // (struct loader_dev_ext_dispatch_table). |
| 3981 | // \returns |
| 3982 | // For a given entry point string (funcName), if an existing mapping is found |
| 3983 | // the |
| 3984 | // trampoline address for that mapping is returned. Otherwise, this unknown |
| 3985 | // entry point |
| 3986 | // has not been seen yet. Next check if a layer or ICD supports it. If so then |
| 3987 | // a |
| 3988 | // new entry in the hash table is initialized and that trampoline address for |
| 3989 | // the new entry is returned. Null is returned if the hash table is full or |
| 3990 | // if no discovered layer or ICD returns a non-NULL GetProcAddr for it. |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3991 | void *loader_dev_ext_gpa(struct loader_instance *inst, const char *funcName) { |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3992 | uint32_t idx; |
| 3993 | uint32_t seed = 0; |
| 3994 | |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3995 | idx = murmurhash(funcName, strlen(funcName), seed) % MAX_NUM_UNKNOWN_EXTS; |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3996 | |
| 3997 | if (loader_name_in_dev_ext_table(inst, &idx, funcName)) |
| 3998 | // found funcName already in hash |
| 3999 | return loader_get_dev_ext_trampoline(idx); |
| 4000 | |
| 4001 | // Check if funcName is supported in either ICDs or a layer library |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4002 | if (!loader_check_icds_for_dev_ext_address(inst, funcName) && |
Lenny Komow | b1685e0 | 2017-08-29 16:08:39 -0600 | [diff] [blame] | 4003 | !loader_check_layer_list_for_dev_ext_address(&inst->app_activated_layer_list, funcName)) { |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 4004 | // if support found in layers continue on |
| 4005 | return NULL; |
| 4006 | } |
| 4007 | |
| 4008 | if (loader_add_dev_ext_table(inst, &idx, funcName)) { |
| 4009 | // successfully added new table entry |
Mark Young | dee312c | 2017-03-08 13:38:35 -0700 | [diff] [blame] | 4010 | // init any dev dispatch table entries as needed |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 4011 | loader_init_dispatch_dev_ext_entry(inst, NULL, idx, funcName); |
| 4012 | return loader_get_dev_ext_trampoline(idx); |
| 4013 | } |
| 4014 | |
| 4015 | return NULL; |
| 4016 | } |
| 4017 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4018 | static bool loader_check_icds_for_phys_dev_ext_address(struct loader_instance *inst, const char *funcName) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4019 | struct loader_icd_term *icd_term; |
| 4020 | icd_term = inst->icd_terms; |
| 4021 | while (NULL != icd_term) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4022 | if (icd_term->scanned_icd->interface_version >= MIN_PHYS_DEV_EXTENSION_ICD_INTERFACE_VERSION && |
| 4023 | icd_term->scanned_icd->GetPhysicalDeviceProcAddr(icd_term->instance, funcName)) |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4024 | // this icd supports funcName |
| 4025 | return true; |
| 4026 | icd_term = icd_term->next; |
| 4027 | } |
| 4028 | |
| 4029 | return false; |
| 4030 | } |
| 4031 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4032 | static bool loader_check_layer_list_for_phys_dev_ext_address(struct loader_instance *inst, const char *funcName) { |
Mark Young | 283fe1c | 2017-05-04 12:16:35 -0600 | [diff] [blame] | 4033 | struct loader_layer_properties *layer_prop_list = inst->expanded_activated_layer_list.list; |
| 4034 | for (uint32_t layer = 0; layer < inst->expanded_activated_layer_list.count; ++layer) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4035 | // If this layer supports the vk_layerGetPhysicalDeviceProcAddr, then call |
| 4036 | // it and see if it returns a valid pointer for this function name. |
| 4037 | if (layer_prop_list[layer].interface_version > 1) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4038 | const struct loader_layer_functions *const functions = &(layer_prop_list[layer].functions); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4039 | if (NULL != functions->get_physical_device_proc_addr && |
Tony Barbour | 55bd539 | 2017-05-17 12:17:18 -0600 | [diff] [blame] | 4040 | NULL != functions->get_physical_device_proc_addr((VkInstance)inst->instance, funcName)) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4041 | return true; |
| 4042 | } |
| 4043 | } |
| 4044 | } |
| 4045 | |
| 4046 | return false; |
| 4047 | } |
| 4048 | |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4049 | static void loader_free_phys_dev_ext_table(struct loader_instance *inst) { |
| 4050 | for (uint32_t i = 0; i < MAX_NUM_UNKNOWN_EXTS; i++) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4051 | loader_instance_heap_free(inst, inst->phys_dev_ext_disp_hash[i].func_name); |
| 4052 | loader_instance_heap_free(inst, inst->phys_dev_ext_disp_hash[i].list.index); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4053 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4054 | memset(inst->phys_dev_ext_disp_hash, 0, sizeof(inst->phys_dev_ext_disp_hash)); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4055 | } |
| 4056 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4057 | static bool loader_add_phys_dev_ext_table(struct loader_instance *inst, uint32_t *ptr_idx, const char *funcName) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4058 | uint32_t i; |
| 4059 | uint32_t idx = *ptr_idx; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4060 | struct loader_dispatch_hash_list *list = &inst->phys_dev_ext_disp_hash[idx].list; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4061 | |
| 4062 | if (!inst->phys_dev_ext_disp_hash[idx].func_name) { |
| 4063 | // no entry here at this idx, so use it |
| 4064 | assert(list->capacity == 0); |
| 4065 | inst->phys_dev_ext_disp_hash[idx].func_name = |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4066 | (char *)loader_instance_heap_alloc(inst, strlen(funcName) + 1, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4067 | if (inst->phys_dev_ext_disp_hash[idx].func_name == NULL) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 4068 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4069 | "loader_add_phys_dev_ext_table() can't allocate memory for " |
| 4070 | "func_name"); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4071 | return false; |
| 4072 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4073 | strncpy(inst->phys_dev_ext_disp_hash[idx].func_name, funcName, strlen(funcName) + 1); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4074 | return true; |
| 4075 | } |
| 4076 | |
| 4077 | // check for enough capacity |
| 4078 | if (list->capacity == 0) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4079 | list->index = loader_instance_heap_alloc(inst, 8 * sizeof(*(list->index)), VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4080 | if (list->index == NULL) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4081 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, "loader_add_phys_dev_ext_table() can't allocate list memory"); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4082 | return false; |
| 4083 | } |
| 4084 | list->capacity = 8 * sizeof(*(list->index)); |
| 4085 | } else if (list->capacity < (list->count + 1) * sizeof(*(list->index))) { |
Mark Young | bb3a29c | 2017-05-19 12:29:43 -0600 | [diff] [blame] | 4086 | void *new_ptr = loader_instance_heap_realloc(inst, list->index, list->capacity, list->capacity * 2, |
| 4087 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
| 4088 | if (NULL == new_ptr) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4089 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, "loader_add_phys_dev_ext_table() can't reallocate list memory"); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4090 | return false; |
| 4091 | } |
Mark Young | bb3a29c | 2017-05-19 12:29:43 -0600 | [diff] [blame] | 4092 | list->index = new_ptr; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4093 | list->capacity *= 2; |
| 4094 | } |
| 4095 | |
| 4096 | // find an unused index in the hash table and use it |
| 4097 | i = (idx + 1) % MAX_NUM_UNKNOWN_EXTS; |
| 4098 | do { |
| 4099 | if (!inst->phys_dev_ext_disp_hash[i].func_name) { |
| 4100 | assert(inst->phys_dev_ext_disp_hash[i].list.capacity == 0); |
| 4101 | inst->phys_dev_ext_disp_hash[i].func_name = |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4102 | (char *)loader_instance_heap_alloc(inst, strlen(funcName) + 1, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4103 | if (inst->phys_dev_ext_disp_hash[i].func_name == NULL) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 4104 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | dee312c | 2017-03-08 13:38:35 -0700 | [diff] [blame] | 4105 | "loader_add_dev_ext_table() can't reallocate " |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 4106 | "func_name memory"); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4107 | return false; |
| 4108 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4109 | strncpy(inst->phys_dev_ext_disp_hash[i].func_name, funcName, strlen(funcName) + 1); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4110 | list->index[list->count] = i; |
| 4111 | list->count++; |
| 4112 | *ptr_idx = i; |
| 4113 | return true; |
| 4114 | } |
| 4115 | i = (i + 1) % MAX_NUM_UNKNOWN_EXTS; |
| 4116 | } while (i != idx); |
| 4117 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 4118 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4119 | "loader_add_phys_dev_ext_table() couldn't insert into hash table; is " |
| 4120 | "it full?"); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4121 | return false; |
| 4122 | } |
| 4123 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4124 | static bool loader_name_in_phys_dev_ext_table(struct loader_instance *inst, uint32_t *idx, const char *funcName) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4125 | uint32_t alt_idx; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4126 | if (inst->phys_dev_ext_disp_hash[*idx].func_name && !strcmp(inst->phys_dev_ext_disp_hash[*idx].func_name, funcName)) |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4127 | return true; |
| 4128 | |
| 4129 | // funcName wasn't at the primary spot in the hash table |
| 4130 | // search the list of secondary locations (shallow search, not deep search) |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4131 | for (uint32_t i = 0; i < inst->phys_dev_ext_disp_hash[*idx].list.count; i++) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4132 | alt_idx = inst->phys_dev_ext_disp_hash[*idx].list.index[i]; |
| 4133 | if (!strcmp(inst->phys_dev_ext_disp_hash[*idx].func_name, funcName)) { |
| 4134 | *idx = alt_idx; |
| 4135 | return true; |
| 4136 | } |
| 4137 | } |
| 4138 | |
| 4139 | return false; |
| 4140 | } |
| 4141 | |
| 4142 | // This function returns a generic trampoline and/or terminator function |
| 4143 | // address for any unknown physical device extension commands. A hash |
| 4144 | // table is used to keep a list of unknown entry points and their |
| 4145 | // mapping to the physical device extension dispatch table (struct |
| 4146 | // loader_phys_dev_ext_dispatch_table). |
| 4147 | // For a given entry point string (funcName), if an existing mapping is |
| 4148 | // found, then the trampoline address for that mapping is returned in |
| 4149 | // tramp_addr (if it is not NULL) and the terminator address for that |
| 4150 | // mapping is returned in term_addr (if it is not NULL). Otherwise, |
| 4151 | // this unknown entry point has not been seen yet. |
| 4152 | // If it has not been seen before, and perform_checking is 'true', |
| 4153 | // check if a layer or and ICD supports it. If so then a new entry in |
| 4154 | // the hash table is initialized and the trampoline and/or terminator |
| 4155 | // addresses are returned. |
| 4156 | // Null is returned if the hash table is full or if no discovered layer or |
| 4157 | // ICD returns a non-NULL GetProcAddr for it. |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4158 | bool loader_phys_dev_ext_gpa(struct loader_instance *inst, const char *funcName, bool perform_checking, void **tramp_addr, |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4159 | void **term_addr) { |
| 4160 | uint32_t idx; |
| 4161 | uint32_t seed = 0; |
| 4162 | bool success = false; |
| 4163 | |
| 4164 | if (inst == NULL) { |
| 4165 | goto out; |
| 4166 | } |
| 4167 | |
| 4168 | if (NULL != tramp_addr) { |
| 4169 | *tramp_addr = NULL; |
| 4170 | } |
| 4171 | if (NULL != term_addr) { |
| 4172 | *term_addr = NULL; |
| 4173 | } |
| 4174 | |
| 4175 | // We should always check to see if any ICD supports it. |
| 4176 | if (!loader_check_icds_for_phys_dev_ext_address(inst, funcName)) { |
| 4177 | // If we're not checking layers, or we are and it's not in a layer, just |
| 4178 | // return |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4179 | if (!perform_checking || !loader_check_layer_list_for_phys_dev_ext_address(inst, funcName)) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4180 | goto out; |
| 4181 | } |
| 4182 | } |
| 4183 | |
| 4184 | idx = murmurhash(funcName, strlen(funcName), seed) % MAX_NUM_UNKNOWN_EXTS; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4185 | if (perform_checking && !loader_name_in_phys_dev_ext_table(inst, &idx, funcName)) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4186 | uint32_t i; |
| 4187 | bool added = false; |
| 4188 | |
| 4189 | // Only need to add first one to get index in Instance. Others will use |
| 4190 | // the same index. |
| 4191 | if (!added && loader_add_phys_dev_ext_table(inst, &idx, funcName)) { |
| 4192 | added = true; |
| 4193 | } |
| 4194 | |
| 4195 | // Setup the ICD function pointers |
| 4196 | struct loader_icd_term *icd_term = inst->icd_terms; |
| 4197 | while (NULL != icd_term) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4198 | if (MIN_PHYS_DEV_EXTENSION_ICD_INTERFACE_VERSION <= icd_term->scanned_icd->interface_version && |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4199 | NULL != icd_term->scanned_icd->GetPhysicalDeviceProcAddr) { |
| 4200 | icd_term->phys_dev_ext[idx] = |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4201 | (PFN_PhysDevExt)icd_term->scanned_icd->GetPhysicalDeviceProcAddr(icd_term->instance, funcName); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4202 | |
| 4203 | // Make sure we set the instance dispatch to point to the |
| 4204 | // loader's terminator now since we can at least handle it |
| 4205 | // in one ICD. |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4206 | inst->disp->phys_dev_ext[idx] = loader_get_phys_dev_ext_termin(idx); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4207 | } else { |
| 4208 | icd_term->phys_dev_ext[idx] = NULL; |
| 4209 | } |
| 4210 | |
| 4211 | icd_term = icd_term->next; |
| 4212 | } |
| 4213 | |
| 4214 | // Now, search for the first layer attached and query using it to get |
| 4215 | // the first entry point. |
Mark Young | 283fe1c | 2017-05-04 12:16:35 -0600 | [diff] [blame] | 4216 | for (i = 0; i < inst->expanded_activated_layer_list.count; i++) { |
| 4217 | struct loader_layer_properties *layer_prop = &inst->expanded_activated_layer_list.list[i]; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4218 | if (layer_prop->interface_version > 1 && NULL != layer_prop->functions.get_physical_device_proc_addr) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4219 | inst->disp->phys_dev_ext[idx] = |
Tony Barbour | 55bd539 | 2017-05-17 12:17:18 -0600 | [diff] [blame] | 4220 | (PFN_PhysDevExt)layer_prop->functions.get_physical_device_proc_addr((VkInstance)inst->instance, funcName); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4221 | if (NULL != inst->disp->phys_dev_ext[idx]) { |
| 4222 | break; |
| 4223 | } |
| 4224 | } |
| 4225 | } |
| 4226 | } |
| 4227 | |
| 4228 | if (NULL != tramp_addr) { |
| 4229 | *tramp_addr = loader_get_phys_dev_ext_tramp(idx); |
| 4230 | } |
| 4231 | |
| 4232 | if (NULL != term_addr) { |
| 4233 | *term_addr = loader_get_phys_dev_ext_termin(idx); |
| 4234 | } |
| 4235 | |
| 4236 | success = true; |
| 4237 | |
| 4238 | out: |
| 4239 | return success; |
| 4240 | } |
| 4241 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4242 | struct loader_instance *loader_get_instance(const VkInstance instance) { |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 4243 | // look up the loader_instance in our list by comparing dispatch tables, as |
| 4244 | // there is no guarantee the instance is still a loader_instance* after any |
| 4245 | // layers which wrap the instance object. |
Jon Ashburn | e0e6457 | 2015-09-30 12:56:42 -0600 | [diff] [blame] | 4246 | const VkLayerInstanceDispatchTable *disp; |
| 4247 | struct loader_instance *ptr_instance = NULL; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4248 | disp = loader_get_instance_layer_dispatch(instance); |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4249 | for (struct loader_instance *inst = loader.instances; inst; inst = inst->next) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4250 | if (&inst->disp->layer_inst_disp == disp) { |
Jon Ashburn | e0e6457 | 2015-09-30 12:56:42 -0600 | [diff] [blame] | 4251 | ptr_instance = inst; |
| 4252 | break; |
| 4253 | } |
| 4254 | } |
| 4255 | return ptr_instance; |
| 4256 | } |
| 4257 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4258 | static loader_platform_dl_handle loader_open_layer_lib(const struct loader_instance *inst, const char *chain_type, |
| 4259 | struct loader_layer_properties *prop) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4260 | if ((prop->lib_handle = loader_platform_open_library(prop->lib_name)) == NULL) { |
Mark Young | b986b5f | 2017-05-16 09:48:55 -0600 | [diff] [blame] | 4261 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, loader_platform_open_library_error(prop->lib_name)); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 4262 | } else { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4263 | loader_log(inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, "Loading layer library %s", prop->lib_name); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 4264 | } |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 4265 | |
Jon Ashburn | 4dc1d8a | 2016-04-20 13:21:17 -0600 | [diff] [blame] | 4266 | return prop->lib_handle; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 4267 | } |
| 4268 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4269 | static void loader_close_layer_lib(const struct loader_instance *inst, struct loader_layer_properties *prop) { |
Jon Ashburn | 4dc1d8a | 2016-04-20 13:21:17 -0600 | [diff] [blame] | 4270 | if (prop->lib_handle) { |
| 4271 | loader_platform_close_library(prop->lib_handle); |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4272 | loader_log(inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, "Unloading layer library %s", prop->lib_name); |
Jon Ashburn | 4dc1d8a | 2016-04-20 13:21:17 -0600 | [diff] [blame] | 4273 | prop->lib_handle = NULL; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 4274 | } |
Jon Ashburn | 4dc1d8a | 2016-04-20 13:21:17 -0600 | [diff] [blame] | 4275 | } |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 4276 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4277 | void loader_deactivate_layers(const struct loader_instance *instance, struct loader_device *device, |
Jon Ashburn | 4dc1d8a | 2016-04-20 13:21:17 -0600 | [diff] [blame] | 4278 | struct loader_layer_list *list) { |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 4279 | // Delete instance list of enabled layers and close any layer libraries |
Jon Ashburn | 4dc1d8a | 2016-04-20 13:21:17 -0600 | [diff] [blame] | 4280 | for (uint32_t i = 0; i < list->count; i++) { |
| 4281 | struct loader_layer_properties *layer_prop = &list->list[i]; |
Courtney Goeltzenleuchter | 80bfd0e | 2015-12-17 09:51:22 -0700 | [diff] [blame] | 4282 | |
Jon Ashburn | 4dc1d8a | 2016-04-20 13:21:17 -0600 | [diff] [blame] | 4283 | loader_close_layer_lib(instance, layer_prop); |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 4284 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4285 | loader_destroy_layer_list(instance, device, list); |
Jon Ashburn | b835805 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 4286 | } |
| 4287 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 4288 | // Go through the search_list and find any layers which match type. If layer |
| 4289 | // type match is found in then add it to ext_list. |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 4290 | static void loader_add_implicit_layers(const struct loader_instance *inst, struct loader_layer_list *target_list, |
Mark Young | 283fe1c | 2017-05-04 12:16:35 -0600 | [diff] [blame] | 4291 | struct loader_layer_list *expanded_target_list, |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 4292 | const struct loader_layer_list *source_list) { |
| 4293 | for (uint32_t src_layer = 0; src_layer < source_list->count; src_layer++) { |
| 4294 | const struct loader_layer_properties *prop = &source_list->list[src_layer]; |
| 4295 | if (0 == (prop->type_flags & VK_LAYER_TYPE_FLAG_EXPLICIT_LAYER)) { |
Mark Young | 283fe1c | 2017-05-04 12:16:35 -0600 | [diff] [blame] | 4296 | loader_add_implicit_layer(inst, prop, target_list, expanded_target_list, source_list); |
Jon Ashburn | 0c26e71 | 2015-07-02 16:10:32 -0600 | [diff] [blame] | 4297 | } |
| 4298 | } |
Jon Ashburn | 0c26e71 | 2015-07-02 16:10:32 -0600 | [diff] [blame] | 4299 | } |
| 4300 | |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 4301 | // Get the layer name(s) from the env_name environment variable. If layer is found in |
| 4302 | // search_list then add it to layer_list. But only add it to layer_list if type_flags matches. |
| 4303 | static void loader_add_env_layers(struct loader_instance *inst, const enum layer_type_flags type_flags, const char *env_name, |
Mark Young | 283fe1c | 2017-05-04 12:16:35 -0600 | [diff] [blame] | 4304 | struct loader_layer_list *target_list, struct loader_layer_list *expanded_target_list, |
| 4305 | const struct loader_layer_list *source_list) { |
Jon Ashburn | eb6d568 | 2015-07-02 14:10:53 -0600 | [diff] [blame] | 4306 | char *next, *name; |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 4307 | char *layer_env = loader_secure_getenv(env_name, inst); |
| 4308 | if (layer_env == NULL) { |
| 4309 | goto out; |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 4310 | } |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 4311 | name = loader_stack_alloc(strlen(layer_env) + 1); |
Jon Ashburn | eb6d568 | 2015-07-02 14:10:53 -0600 | [diff] [blame] | 4312 | if (name == NULL) { |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 4313 | goto out; |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 4314 | } |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 4315 | strcpy(name, layer_env); |
Jon Ashburn | 38a497f | 2016-01-04 14:01:38 -0700 | [diff] [blame] | 4316 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4317 | while (name && *name) { |
Jon Ashburn | eb6d568 | 2015-07-02 14:10:53 -0600 | [diff] [blame] | 4318 | next = loader_get_next_path(name); |
Mark Young | 283fe1c | 2017-05-04 12:16:35 -0600 | [diff] [blame] | 4319 | loader_find_layer_name_add_list(inst, name, type_flags, source_list, target_list, expanded_target_list); |
Jon Ashburn | eb6d568 | 2015-07-02 14:10:53 -0600 | [diff] [blame] | 4320 | name = next; |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 4321 | } |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 4322 | |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 4323 | out: |
| 4324 | |
| 4325 | if (layer_env != NULL) { |
| 4326 | loader_free_getenv(layer_env, inst); |
| 4327 | } |
| 4328 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 4329 | return; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 4330 | } |
| 4331 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4332 | VkResult loader_enable_instance_layers(struct loader_instance *inst, const VkInstanceCreateInfo *pCreateInfo, |
| 4333 | const struct loader_layer_list *instance_layers) { |
Courtney Goeltzenleuchter | 40caf0b | 2015-07-06 09:06:34 -0600 | [diff] [blame] | 4334 | VkResult err; |
| 4335 | |
Courtney Goeltzenleuchter | 55659b7 | 2015-09-14 18:01:17 -0600 | [diff] [blame] | 4336 | assert(inst && "Cannot have null instance"); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 4337 | |
Mark Young | 283fe1c | 2017-05-04 12:16:35 -0600 | [diff] [blame] | 4338 | if (!loader_init_layer_list(inst, &inst->app_activated_layer_list)) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 4339 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4340 | "loader_enable_instance_layers: Failed to initialize" |
Mark Young | 283fe1c | 2017-05-04 12:16:35 -0600 | [diff] [blame] | 4341 | " application version of the layer list"); |
| 4342 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 4343 | } |
| 4344 | |
| 4345 | if (!loader_init_layer_list(inst, &inst->expanded_activated_layer_list)) { |
| 4346 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4347 | "loader_enable_instance_layers: Failed to initialize" |
| 4348 | " expanded version of the layer list"); |
Courtney Goeltzenleuchter | 40caf0b | 2015-07-06 09:06:34 -0600 | [diff] [blame] | 4349 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Jon Ashburn | bd6c488 | 2015-07-02 12:59:25 -0600 | [diff] [blame] | 4350 | } |
| 4351 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 4352 | // Add any implicit layers first |
Mark Young | 283fe1c | 2017-05-04 12:16:35 -0600 | [diff] [blame] | 4353 | loader_add_implicit_layers(inst, &inst->app_activated_layer_list, &inst->expanded_activated_layer_list, instance_layers); |
Jon Ashburn | 0c26e71 | 2015-07-02 16:10:32 -0600 | [diff] [blame] | 4354 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 4355 | // Add any layers specified via environment variable next |
Mark Young | 283fe1c | 2017-05-04 12:16:35 -0600 | [diff] [blame] | 4356 | loader_add_env_layers(inst, VK_LAYER_TYPE_FLAG_EXPLICIT_LAYER, "VK_INSTANCE_LAYERS", &inst->app_activated_layer_list, |
| 4357 | &inst->expanded_activated_layer_list, instance_layers); |
Jon Ashburn | bd6c488 | 2015-07-02 12:59:25 -0600 | [diff] [blame] | 4358 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 4359 | // Add layers specified by the application |
Mark Young | 283fe1c | 2017-05-04 12:16:35 -0600 | [diff] [blame] | 4360 | err = loader_add_layer_names_to_list(inst, &inst->app_activated_layer_list, &inst->expanded_activated_layer_list, |
| 4361 | pCreateInfo->enabledLayerCount, pCreateInfo->ppEnabledLayerNames, instance_layers); |
Courtney Goeltzenleuchter | 40caf0b | 2015-07-06 09:06:34 -0600 | [diff] [blame] | 4362 | |
| 4363 | return err; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 4364 | } |
| 4365 | |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4366 | // Determine the layer interface version to use. |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4367 | bool loader_get_layer_interface_version(PFN_vkNegotiateLoaderLayerInterfaceVersion fp_negotiate_layer_version, |
| 4368 | VkNegotiateLayerInterface *interface_struct) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4369 | memset(interface_struct, 0, sizeof(VkNegotiateLayerInterface)); |
Mark Young | 21aa6d6 | 2017-03-29 13:39:27 -0600 | [diff] [blame] | 4370 | interface_struct->sType = LAYER_NEGOTIATE_INTERFACE_STRUCT; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4371 | interface_struct->loaderLayerInterfaceVersion = 1; |
| 4372 | |
| 4373 | if (fp_negotiate_layer_version != NULL) { |
| 4374 | // Layer supports the negotiation API, so call it with the loader's |
| 4375 | // latest version supported |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4376 | interface_struct->loaderLayerInterfaceVersion = CURRENT_LOADER_LAYER_INTERFACE_VERSION; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4377 | VkResult result = fp_negotiate_layer_version(interface_struct); |
| 4378 | |
| 4379 | if (result != VK_SUCCESS) { |
| 4380 | // Layer no longer supports the loader's latest interface version so |
| 4381 | // fail loading the Layer |
| 4382 | return false; |
| 4383 | } |
| 4384 | } |
| 4385 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4386 | if (interface_struct->loaderLayerInterfaceVersion < MIN_SUPPORTED_LOADER_LAYER_INTERFACE_VERSION) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4387 | // Loader no longer supports the layer's latest interface version so |
| 4388 | // fail loading the layer |
| 4389 | return false; |
| 4390 | } |
| 4391 | |
| 4392 | return true; |
| 4393 | } |
| 4394 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 4395 | // Given the list of layers to activate in the loader_instance |
| 4396 | // structure. This function will add a VkLayerInstanceCreateInfo |
| 4397 | // structure to the VkInstanceCreateInfo.pNext pointer. |
| 4398 | // Each activated layer will have it's own VkLayerInstanceLink |
| 4399 | // structure that tells the layer what Get*ProcAddr to call to |
| 4400 | // get function pointers to the next layer down. |
| 4401 | // Once the chain info has been created this function will |
| 4402 | // execute the CreateInstance call chain. Each layer will |
| 4403 | // then have an opportunity in it's CreateInstance function |
| 4404 | // to setup it's dispatch table when the lower layer returns |
| 4405 | // successfully. |
| 4406 | // Each layer can wrap or not-wrap the returned VkInstance object |
| 4407 | // as it sees fit. |
| 4408 | // The instance chain is terminated by a loader function |
| 4409 | // that will call CreateInstance on all available ICD's and |
| 4410 | // cache those VkInstance objects for future use. |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4411 | VkResult loader_create_instance_chain(const VkInstanceCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator, |
| 4412 | struct loader_instance *inst, VkInstance *created_instance) { |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4413 | uint32_t activated_layers = 0; |
| 4414 | VkLayerInstanceCreateInfo chain_info; |
| 4415 | VkLayerInstanceLink *layer_instance_link_info = NULL; |
| 4416 | VkInstanceCreateInfo loader_create_info; |
| 4417 | VkResult res; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 4418 | |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4419 | PFN_vkGetInstanceProcAddr next_gipa = loader_gpa_instance_internal; |
| 4420 | PFN_vkGetInstanceProcAddr cur_gipa = loader_gpa_instance_internal; |
| 4421 | PFN_GetPhysicalDeviceProcAddr next_gpdpa = loader_gpdpa_instance_internal; |
| 4422 | PFN_GetPhysicalDeviceProcAddr cur_gpdpa = loader_gpdpa_instance_internal; |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 4423 | |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4424 | memcpy(&loader_create_info, pCreateInfo, sizeof(VkInstanceCreateInfo)); |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 4425 | |
Mark Young | 283fe1c | 2017-05-04 12:16:35 -0600 | [diff] [blame] | 4426 | if (inst->expanded_activated_layer_list.count > 0) { |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4427 | chain_info.u.pLayerInfo = NULL; |
| 4428 | chain_info.pNext = pCreateInfo->pNext; |
| 4429 | chain_info.sType = VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO; |
| 4430 | chain_info.function = VK_LAYER_LINK_INFO; |
| 4431 | loader_create_info.pNext = &chain_info; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 4432 | |
Mark Young | 283fe1c | 2017-05-04 12:16:35 -0600 | [diff] [blame] | 4433 | layer_instance_link_info = loader_stack_alloc(sizeof(VkLayerInstanceLink) * inst->expanded_activated_layer_list.count); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4434 | if (!layer_instance_link_info) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 4435 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4436 | "loader_create_instance_chain: Failed to alloc Instance" |
| 4437 | " objects for layer"); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4438 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 4439 | } |
| 4440 | |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4441 | // Create instance chain of enabled layers |
Mark Young | 283fe1c | 2017-05-04 12:16:35 -0600 | [diff] [blame] | 4442 | for (int32_t i = inst->expanded_activated_layer_list.count - 1; i >= 0; i--) { |
| 4443 | struct loader_layer_properties *layer_prop = &inst->expanded_activated_layer_list.list[i]; |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4444 | loader_platform_dl_handle lib_handle; |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 4445 | |
Jon Ashburn | 4dc1d8a | 2016-04-20 13:21:17 -0600 | [diff] [blame] | 4446 | lib_handle = loader_open_layer_lib(inst, "instance", layer_prop); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4447 | if (!lib_handle) { |
Courtney Goeltzenleuchter | 524b7e3 | 2016-01-14 16:06:06 -0700 | [diff] [blame] | 4448 | continue; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4449 | } |
| 4450 | |
| 4451 | if (NULL == layer_prop->functions.negotiate_layer_interface) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4452 | PFN_vkNegotiateLoaderLayerInterfaceVersion negotiate_interface = NULL; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4453 | bool functions_in_interface = false; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4454 | if (strlen(layer_prop->functions.str_negotiate_interface) == 0) { |
| 4455 | negotiate_interface = (PFN_vkNegotiateLoaderLayerInterfaceVersion)loader_platform_get_proc_address( |
| 4456 | lib_handle, "vkNegotiateLoaderLayerInterfaceVersion"); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4457 | } else { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4458 | negotiate_interface = (PFN_vkNegotiateLoaderLayerInterfaceVersion)loader_platform_get_proc_address( |
| 4459 | lib_handle, layer_prop->functions.str_negotiate_interface); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4460 | } |
| 4461 | |
| 4462 | // If we can negotiate an interface version, then we can also |
| 4463 | // get everything we need from the one function call, so try |
| 4464 | // that first, and see if we can get all the function pointers |
| 4465 | // necessary from that one call. |
| 4466 | if (NULL != negotiate_interface) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4467 | layer_prop->functions.negotiate_layer_interface = negotiate_interface; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4468 | |
| 4469 | VkNegotiateLayerInterface interface_struct; |
| 4470 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4471 | if (loader_get_layer_interface_version(negotiate_interface, &interface_struct)) { |
Mark Young | dee312c | 2017-03-08 13:38:35 -0700 | [diff] [blame] | 4472 | // Go ahead and set the properties version to the |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4473 | // correct value. |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4474 | layer_prop->interface_version = interface_struct.loaderLayerInterfaceVersion; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4475 | |
| 4476 | // If the interface is 2 or newer, we have access to the |
| 4477 | // new GetPhysicalDeviceProcAddr function, so grab it, |
| 4478 | // and the other necessary functions, from the |
| 4479 | // structure. |
| 4480 | if (interface_struct.loaderLayerInterfaceVersion > 1) { |
| 4481 | cur_gipa = interface_struct.pfnGetInstanceProcAddr; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4482 | cur_gpdpa = interface_struct.pfnGetPhysicalDeviceProcAddr; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4483 | if (cur_gipa != NULL) { |
| 4484 | // We've set the functions, so make sure we |
| 4485 | // don't do the unnecessary calls later. |
| 4486 | functions_in_interface = true; |
| 4487 | } |
| 4488 | } |
| 4489 | } |
| 4490 | } |
| 4491 | |
| 4492 | if (!functions_in_interface) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4493 | if ((cur_gipa = layer_prop->functions.get_instance_proc_addr) == NULL) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4494 | if (strlen(layer_prop->functions.str_gipa) == 0) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4495 | cur_gipa = |
| 4496 | (PFN_vkGetInstanceProcAddr)loader_platform_get_proc_address(lib_handle, "vkGetInstanceProcAddr"); |
| 4497 | layer_prop->functions.get_instance_proc_addr = cur_gipa; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4498 | } else { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4499 | cur_gipa = (PFN_vkGetInstanceProcAddr)loader_platform_get_proc_address(lib_handle, |
| 4500 | layer_prop->functions.str_gipa); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4501 | } |
| 4502 | |
| 4503 | if (NULL == cur_gipa) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 4504 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4505 | "loader_create_instance_chain: Failed to" |
| 4506 | " find \'vkGetInstanceProcAddr\' in " |
| 4507 | "layer %s", |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4508 | layer_prop->lib_name); |
| 4509 | continue; |
| 4510 | } |
| 4511 | } |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4512 | } |
| 4513 | } |
| 4514 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4515 | layer_instance_link_info[activated_layers].pNext = chain_info.u.pLayerInfo; |
| 4516 | layer_instance_link_info[activated_layers].pfnNextGetInstanceProcAddr = next_gipa; |
| 4517 | layer_instance_link_info[activated_layers].pfnNextGetPhysicalDeviceProcAddr = next_gpdpa; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4518 | next_gipa = cur_gipa; |
| 4519 | if (layer_prop->interface_version > 1 && cur_gpdpa != NULL) { |
| 4520 | layer_prop->functions.get_physical_device_proc_addr = cur_gpdpa; |
| 4521 | next_gpdpa = cur_gpdpa; |
| 4522 | } |
| 4523 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4524 | chain_info.u.pLayerInfo = &layer_instance_link_info[activated_layers]; |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4525 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4526 | loader_log(inst, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, "Insert instance layer %s (%s)", layer_prop->info.layerName, |
| 4527 | layer_prop->lib_name); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4528 | |
| 4529 | activated_layers++; |
| 4530 | } |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 4531 | } |
| 4532 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4533 | PFN_vkCreateInstance fpCreateInstance = (PFN_vkCreateInstance)next_gipa(*created_instance, "vkCreateInstance"); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4534 | if (fpCreateInstance) { |
Jon Ashburn | c3c5877 | 2016-03-29 11:16:01 -0600 | [diff] [blame] | 4535 | VkLayerInstanceCreateInfo create_info_disp; |
| 4536 | |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 4537 | create_info_disp.sType = VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO; |
Jon Ashburn | ed8f231 | 2016-03-31 10:52:22 -0600 | [diff] [blame] | 4538 | create_info_disp.function = VK_LOADER_DATA_CALLBACK; |
Jon Ashburn | c3c5877 | 2016-03-29 11:16:01 -0600 | [diff] [blame] | 4539 | |
| 4540 | create_info_disp.u.pfnSetInstanceLoaderData = vkSetInstanceDispatch; |
| 4541 | |
| 4542 | create_info_disp.pNext = loader_create_info.pNext; |
| 4543 | loader_create_info.pNext = &create_info_disp; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4544 | res = fpCreateInstance(&loader_create_info, pAllocator, created_instance); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4545 | } else { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 4546 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4547 | "loader_create_instance_chain: Failed to find " |
| 4548 | "\'vkCreateInstance\'"); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4549 | // Couldn't find CreateInstance function! |
| 4550 | res = VK_ERROR_INITIALIZATION_FAILED; |
| 4551 | } |
| 4552 | |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4553 | if (res == VK_SUCCESS) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4554 | loader_init_instance_core_dispatch_table(&inst->disp->layer_inst_disp, next_gipa, *created_instance); |
Jon Ashburn | 4e8c416 | 2016-03-08 15:21:30 -0700 | [diff] [blame] | 4555 | inst->instance = *created_instance; |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4556 | } |
| 4557 | |
| 4558 | return res; |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 4559 | } |
| 4560 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4561 | void loader_activate_instance_layer_extensions(struct loader_instance *inst, VkInstance created_inst) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4562 | loader_init_instance_extension_dispatch_table(&inst->disp->layer_inst_disp, inst->disp->layer_inst_disp.GetInstanceProcAddr, |
| 4563 | created_inst); |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 4564 | } |
| 4565 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4566 | VkResult loader_create_device_chain(const struct loader_physical_device_tramp *pd, const VkDeviceCreateInfo *pCreateInfo, |
| 4567 | const VkAllocationCallbacks *pAllocator, const struct loader_instance *inst, |
| 4568 | struct loader_device *dev) { |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4569 | uint32_t activated_layers = 0; |
| 4570 | VkLayerDeviceLink *layer_device_link_info; |
| 4571 | VkLayerDeviceCreateInfo chain_info; |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4572 | VkDeviceCreateInfo loader_create_info; |
| 4573 | VkResult res; |
Courtney Goeltzenleuchter | ca173b8 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 4574 | |
Jamie Madill | 3512787 | 2017-03-15 16:17:46 -0400 | [diff] [blame] | 4575 | PFN_vkGetDeviceProcAddr fpGDPA = NULL, nextGDPA = loader_gpa_device_internal; |
| 4576 | PFN_vkGetInstanceProcAddr fpGIPA = NULL, nextGIPA = loader_gpa_instance_internal; |
Courtney Goeltzenleuchter | ca173b8 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 4577 | |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4578 | memcpy(&loader_create_info, pCreateInfo, sizeof(VkDeviceCreateInfo)); |
| 4579 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 4580 | // Before we continue, we need to find out if the KHX_device_group extension is in the enabled list. If it is, we then |
| 4581 | // need to look for the corresponding VkDeviceGroupDeviceCreateInfoKHX struct in the device list. This is because we |
| 4582 | // need to replace all the incoming physical device values (which are really loader trampoline physical device values) |
| 4583 | // with the layer/ICD version. |
| 4584 | if (inst->enabled_known_extensions.khx_device_group_creation == 1) { |
| 4585 | struct VkStructureHeader *pNext = (struct VkStructureHeader *)loader_create_info.pNext; |
| 4586 | struct VkStructureHeader *pPrev = (struct VkStructureHeader *)&loader_create_info; |
| 4587 | while (NULL != pNext) { |
| 4588 | if (VK_STRUCTURE_TYPE_DEVICE_GROUP_DEVICE_CREATE_INFO_KHX == pNext->sType) { |
| 4589 | VkDeviceGroupDeviceCreateInfoKHX *cur_struct = (VkDeviceGroupDeviceCreateInfoKHX *)pNext; |
| 4590 | if (0 < cur_struct->physicalDeviceCount && NULL != cur_struct->pPhysicalDevices) { |
| 4591 | VkDeviceGroupDeviceCreateInfoKHX *temp_struct = loader_stack_alloc(sizeof(VkDeviceGroupDeviceCreateInfoKHX)); |
| 4592 | VkPhysicalDevice *phys_dev_array = NULL; |
| 4593 | if (NULL == temp_struct) { |
| 4594 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 4595 | } |
| 4596 | memcpy(temp_struct, cur_struct, sizeof(VkDeviceGroupDeviceCreateInfoKHX)); |
| 4597 | phys_dev_array = loader_stack_alloc(sizeof(VkPhysicalDevice) * cur_struct->physicalDeviceCount); |
| 4598 | if (NULL == phys_dev_array) { |
| 4599 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 4600 | } |
| 4601 | |
| 4602 | // Before calling down, replace the incoming physical device values (which are really loader trampoline |
| 4603 | // physical devices) with the next layer (or possibly even the terminator) physical device values. |
| 4604 | struct loader_physical_device_tramp *cur_tramp; |
| 4605 | for (uint32_t phys_dev = 0; phys_dev < cur_struct->physicalDeviceCount; phys_dev++) { |
| 4606 | cur_tramp = (struct loader_physical_device_tramp *)cur_struct->pPhysicalDevices[phys_dev]; |
| 4607 | phys_dev_array[phys_dev] = cur_tramp->phys_dev; |
| 4608 | } |
| 4609 | temp_struct->pPhysicalDevices = phys_dev_array; |
| 4610 | |
| 4611 | // Replace the old struct in the pNext chain with this one. |
| 4612 | pPrev->pNext = (const void *)temp_struct; |
| 4613 | pNext = (struct VkStructureHeader *)(temp_struct); |
| 4614 | } |
| 4615 | break; |
| 4616 | } |
| 4617 | |
| 4618 | pPrev = pNext; |
| 4619 | pNext = (struct VkStructureHeader *)(pPrev->pNext); |
| 4620 | } |
| 4621 | } |
| 4622 | |
Mark Young | 283fe1c | 2017-05-04 12:16:35 -0600 | [diff] [blame] | 4623 | layer_device_link_info = loader_stack_alloc(sizeof(VkLayerDeviceLink) * dev->expanded_activated_layer_list.count); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4624 | if (!layer_device_link_info) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 4625 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4626 | "loader_create_device_chain: Failed to alloc Device objects" |
| 4627 | " for layer. Skipping Layer."); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4628 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
David Pinedo | a0a8a24 | 2015-06-24 15:29:18 -0600 | [diff] [blame] | 4629 | } |
Jon Ashburn | 94e7049 | 2015-06-10 10:13:10 -0600 | [diff] [blame] | 4630 | |
Mark Young | 283fe1c | 2017-05-04 12:16:35 -0600 | [diff] [blame] | 4631 | if (dev->expanded_activated_layer_list.count > 0) { |
Jon Ashburn | 72690f2 | 2016-03-29 12:52:13 -0600 | [diff] [blame] | 4632 | chain_info.sType = VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO; |
| 4633 | chain_info.function = VK_LAYER_LINK_INFO; |
| 4634 | chain_info.u.pLayerInfo = NULL; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4635 | chain_info.pNext = loader_create_info.pNext; |
Jon Ashburn | 72690f2 | 2016-03-29 12:52:13 -0600 | [diff] [blame] | 4636 | loader_create_info.pNext = &chain_info; |
| 4637 | |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4638 | // Create instance chain of enabled layers |
Mark Young | 283fe1c | 2017-05-04 12:16:35 -0600 | [diff] [blame] | 4639 | for (int32_t i = dev->expanded_activated_layer_list.count - 1; i >= 0; i--) { |
| 4640 | struct loader_layer_properties *layer_prop = &dev->expanded_activated_layer_list.list[i]; |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4641 | loader_platform_dl_handle lib_handle; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4642 | bool functions_in_interface = false; |
Courtney Goeltzenleuchter | ca173b8 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 4643 | |
Jon Ashburn | 4dc1d8a | 2016-04-20 13:21:17 -0600 | [diff] [blame] | 4644 | lib_handle = loader_open_layer_lib(inst, "device", layer_prop); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4645 | if (!lib_handle) { |
Courtney Goeltzenleuchter | 524b7e3 | 2016-01-14 16:06:06 -0700 | [diff] [blame] | 4646 | continue; |
Jon Ashburn | 21c21ee | 2015-09-09 11:29:24 -0600 | [diff] [blame] | 4647 | } |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4648 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 4649 | // If we can negotiate an interface version, then we can also get everything we need from the one function |
| 4650 | // call, so try that first, and see if we can get all the function pointers necessary from that one call. |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4651 | if (NULL == layer_prop->functions.negotiate_layer_interface) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4652 | PFN_vkNegotiateLoaderLayerInterfaceVersion negotiate_interface = NULL; |
| 4653 | if (strlen(layer_prop->functions.str_negotiate_interface) == 0) { |
| 4654 | negotiate_interface = (PFN_vkNegotiateLoaderLayerInterfaceVersion)loader_platform_get_proc_address( |
| 4655 | lib_handle, "vkNegotiateLoaderLayerInterfaceVersion"); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4656 | } else { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4657 | negotiate_interface = (PFN_vkNegotiateLoaderLayerInterfaceVersion)loader_platform_get_proc_address( |
| 4658 | lib_handle, layer_prop->functions.str_negotiate_interface); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4659 | } |
| 4660 | |
| 4661 | if (NULL != negotiate_interface) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4662 | layer_prop->functions.negotiate_layer_interface = negotiate_interface; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4663 | |
| 4664 | VkNegotiateLayerInterface interface_struct; |
| 4665 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4666 | if (loader_get_layer_interface_version(negotiate_interface, &interface_struct)) { |
Mark Young | dee312c | 2017-03-08 13:38:35 -0700 | [diff] [blame] | 4667 | // Go ahead and set the properties version to the correct value. |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4668 | layer_prop->interface_version = interface_struct.loaderLayerInterfaceVersion; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4669 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 4670 | // If the interface is 2 or newer, we have access to the new GetPhysicalDeviceProcAddr |
| 4671 | // function, so grab it, and the other necessary functions, from the structure. |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4672 | if (interface_struct.loaderLayerInterfaceVersion > 1) { |
| 4673 | fpGIPA = interface_struct.pfnGetInstanceProcAddr; |
| 4674 | fpGDPA = interface_struct.pfnGetDeviceProcAddr; |
| 4675 | if (fpGIPA != NULL && fpGDPA) { |
| 4676 | // We've set the functions, so make sure we |
| 4677 | // don't do the unnecessary calls later. |
| 4678 | functions_in_interface = true; |
| 4679 | } |
| 4680 | } |
| 4681 | } |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4682 | } |
| 4683 | } |
| 4684 | |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4685 | if (!functions_in_interface) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4686 | if ((fpGIPA = layer_prop->functions.get_instance_proc_addr) == NULL) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4687 | if (strlen(layer_prop->functions.str_gipa) == 0) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4688 | fpGIPA = (PFN_vkGetInstanceProcAddr)loader_platform_get_proc_address(lib_handle, "vkGetInstanceProcAddr"); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4689 | layer_prop->functions.get_instance_proc_addr = fpGIPA; |
| 4690 | } else |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4691 | fpGIPA = |
| 4692 | (PFN_vkGetInstanceProcAddr)loader_platform_get_proc_address(lib_handle, layer_prop->functions.str_gipa); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4693 | if (!fpGIPA) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 4694 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4695 | "loader_create_device_chain: Failed to find " |
| 4696 | "\'vkGetInstanceProcAddr\' in layer %s. Skipping" |
| 4697 | " layer.", |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4698 | layer_prop->lib_name); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4699 | continue; |
| 4700 | } |
| 4701 | } |
| 4702 | if ((fpGDPA = layer_prop->functions.get_device_proc_addr) == NULL) { |
| 4703 | if (strlen(layer_prop->functions.str_gdpa) == 0) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4704 | fpGDPA = (PFN_vkGetDeviceProcAddr)loader_platform_get_proc_address(lib_handle, "vkGetDeviceProcAddr"); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4705 | layer_prop->functions.get_device_proc_addr = fpGDPA; |
| 4706 | } else |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4707 | fpGDPA = |
| 4708 | (PFN_vkGetDeviceProcAddr)loader_platform_get_proc_address(lib_handle, layer_prop->functions.str_gdpa); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4709 | if (!fpGDPA) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4710 | loader_log(inst, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, "Failed to find vkGetDeviceProcAddr in layer %s", |
| 4711 | layer_prop->lib_name); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4712 | continue; |
| 4713 | } |
| 4714 | } |
| 4715 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4716 | layer_device_link_info[activated_layers].pNext = chain_info.u.pLayerInfo; |
| 4717 | layer_device_link_info[activated_layers].pfnNextGetInstanceProcAddr = nextGIPA; |
| 4718 | layer_device_link_info[activated_layers].pfnNextGetDeviceProcAddr = nextGDPA; |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4719 | chain_info.u.pLayerInfo = &layer_device_link_info[activated_layers]; |
| 4720 | nextGIPA = fpGIPA; |
| 4721 | nextGDPA = fpGDPA; |
| 4722 | |
Lenny Komow | 7ddd432 | 2017-10-16 15:03:37 -0600 | [diff] [blame] | 4723 | loader_log(inst, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, "Inserted device layer %s (%s)", layer_prop->info.layerName, |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4724 | layer_prop->lib_name); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4725 | |
| 4726 | activated_layers++; |
Jon Ashburn | 94e7049 | 2015-06-10 10:13:10 -0600 | [diff] [blame] | 4727 | } |
Jon Ashburn | 94e7049 | 2015-06-10 10:13:10 -0600 | [diff] [blame] | 4728 | } |
| 4729 | |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 4730 | VkDevice created_device = (VkDevice)dev; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4731 | PFN_vkCreateDevice fpCreateDevice = (PFN_vkCreateDevice)nextGIPA(inst->instance, "vkCreateDevice"); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4732 | if (fpCreateDevice) { |
Jon Ashburn | ed8f231 | 2016-03-31 10:52:22 -0600 | [diff] [blame] | 4733 | VkLayerDeviceCreateInfo create_info_disp; |
| 4734 | |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 4735 | create_info_disp.sType = VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO; |
Jon Ashburn | ed8f231 | 2016-03-31 10:52:22 -0600 | [diff] [blame] | 4736 | create_info_disp.function = VK_LOADER_DATA_CALLBACK; |
| 4737 | |
| 4738 | create_info_disp.u.pfnSetDeviceLoaderData = vkSetDeviceDispatch; |
| 4739 | |
| 4740 | create_info_disp.pNext = loader_create_info.pNext; |
| 4741 | loader_create_info.pNext = &create_info_disp; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4742 | res = fpCreateDevice(pd->phys_dev, &loader_create_info, pAllocator, &created_device); |
Piers Daniell | efbbfc1 | 2016-04-05 17:28:06 -0600 | [diff] [blame] | 4743 | if (res != VK_SUCCESS) { |
| 4744 | return res; |
| 4745 | } |
Mark Young | 65cb366 | 2016-11-07 13:27:02 -0700 | [diff] [blame] | 4746 | dev->chain_device = created_device; |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4747 | } else { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 4748 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4749 | "loader_create_device_chain: Failed to find \'vkCreateDevice\' " |
| 4750 | "in layer %s"); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4751 | // Couldn't find CreateDevice function! |
| 4752 | return VK_ERROR_INITIALIZATION_FAILED; |
| 4753 | } |
Jon Ashburn | 94e7049 | 2015-06-10 10:13:10 -0600 | [diff] [blame] | 4754 | |
Mark Young | 65cb366 | 2016-11-07 13:27:02 -0700 | [diff] [blame] | 4755 | // Initialize device dispatch table |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4756 | loader_init_device_dispatch_table(&dev->loader_dispatch, nextGDPA, dev->chain_device); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4757 | |
| 4758 | return res; |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 4759 | } |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 4760 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4761 | VkResult loader_validate_layers(const struct loader_instance *inst, const uint32_t layer_count, |
| 4762 | const char *const *ppEnabledLayerNames, const struct loader_layer_list *list) { |
Courtney Goeltzenleuchter | 3b8c5ff | 2015-07-06 17:45:08 -0600 | [diff] [blame] | 4763 | struct loader_layer_properties *prop; |
| 4764 | |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 4765 | for (uint32_t i = 0; i < layer_count; i++) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4766 | VkStringErrorFlags result = vk_string_validate(MaxLoaderStringLength, ppEnabledLayerNames[i]); |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 4767 | if (result != VK_STRING_ERROR_NONE) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 4768 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4769 | "loader_validate_layers: Device ppEnabledLayerNames " |
| 4770 | "contains string that is too long or is badly formed"); |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 4771 | return VK_ERROR_LAYER_NOT_PRESENT; |
| 4772 | } |
| 4773 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4774 | prop = loader_get_layer_property(ppEnabledLayerNames[i], list); |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 4775 | if (NULL == prop) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 4776 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | c8b807a | 2017-07-14 17:11:31 -0600 | [diff] [blame] | 4777 | "loader_validate_layers: Layer %d does not exist in the list of available layers", i); |
Courtney Goeltzenleuchter | 55659b7 | 2015-09-14 18:01:17 -0600 | [diff] [blame] | 4778 | return VK_ERROR_LAYER_NOT_PRESENT; |
Courtney Goeltzenleuchter | 3b8c5ff | 2015-07-06 17:45:08 -0600 | [diff] [blame] | 4779 | } |
| 4780 | } |
Courtney Goeltzenleuchter | 3b8c5ff | 2015-07-06 17:45:08 -0600 | [diff] [blame] | 4781 | return VK_SUCCESS; |
| 4782 | } |
| 4783 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4784 | VkResult loader_validate_instance_extensions(const struct loader_instance *inst, const struct loader_extension_list *icd_exts, |
| 4785 | const struct loader_layer_list *instance_layers, |
| 4786 | const VkInstanceCreateInfo *pCreateInfo) { |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 4787 | VkExtensionProperties *extension_prop; |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 4788 | struct loader_layer_properties *layer_prop; |
Mark Young | 48cea0c | 2017-05-26 14:39:54 -0600 | [diff] [blame] | 4789 | char *env_value; |
| 4790 | bool check_if_known = true; |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 4791 | |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 4792 | for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4793 | VkStringErrorFlags result = vk_string_validate(MaxLoaderStringLength, pCreateInfo->ppEnabledExtensionNames[i]); |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 4794 | if (result != VK_STRING_ERROR_NONE) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 4795 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | 48cea0c | 2017-05-26 14:39:54 -0600 | [diff] [blame] | 4796 | "loader_validate_instance_extensions: Instance ppEnabledExtensionNames contains " |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 4797 | "string that is too long or is badly formed"); |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 4798 | return VK_ERROR_EXTENSION_NOT_PRESENT; |
| 4799 | } |
| 4800 | |
Mark Young | 48cea0c | 2017-05-26 14:39:54 -0600 | [diff] [blame] | 4801 | // Check if a user wants to disable the instance extension filtering behavior |
| 4802 | env_value = loader_getenv("VK_LOADER_DISABLE_INST_EXT_FILTER", inst); |
| 4803 | if (NULL != env_value && atoi(env_value) != 0) { |
| 4804 | check_if_known = false; |
Lenny Komow | 4053b81 | 2016-12-29 16:27:28 -0700 | [diff] [blame] | 4805 | } |
Mark Young | 48cea0c | 2017-05-26 14:39:54 -0600 | [diff] [blame] | 4806 | loader_free_getenv(env_value, inst); |
Lenny Komow | 4053b81 | 2016-12-29 16:27:28 -0700 | [diff] [blame] | 4807 | |
Mark Young | 48cea0c | 2017-05-26 14:39:54 -0600 | [diff] [blame] | 4808 | if (check_if_known) { |
| 4809 | // See if the extension is in the list of supported extensions |
| 4810 | bool found = false; |
| 4811 | for (uint32_t j = 0; LOADER_INSTANCE_EXTENSIONS[j] != NULL; j++) { |
| 4812 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], LOADER_INSTANCE_EXTENSIONS[j]) == 0) { |
| 4813 | found = true; |
| 4814 | break; |
| 4815 | } |
| 4816 | } |
| 4817 | |
| 4818 | // If it isn't in the list, return an error |
| 4819 | if (!found) { |
| 4820 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4821 | "loader_validate_instance_extensions: Extension %s not found in list of known instance extensions.", |
| 4822 | pCreateInfo->ppEnabledExtensionNames[i]); |
| 4823 | return VK_ERROR_EXTENSION_NOT_PRESENT; |
| 4824 | } |
Lenny Komow | 4053b81 | 2016-12-29 16:27:28 -0700 | [diff] [blame] | 4825 | } |
| 4826 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4827 | extension_prop = get_extension_property(pCreateInfo->ppEnabledExtensionNames[i], icd_exts); |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 4828 | |
| 4829 | if (extension_prop) { |
| 4830 | continue; |
| 4831 | } |
| 4832 | |
| 4833 | extension_prop = NULL; |
| 4834 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 4835 | // Not in global list, search layer extension lists |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 4836 | for (uint32_t j = 0; j < pCreateInfo->enabledLayerCount; j++) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4837 | layer_prop = loader_get_layer_property(pCreateInfo->ppEnabledLayerNames[j], instance_layers); |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 4838 | if (NULL == layer_prop) { |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 4839 | // Should NOT get here, loader_validate_layers should have already filtered this case out. |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 4840 | continue; |
| 4841 | } |
| 4842 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4843 | extension_prop = get_extension_property(pCreateInfo->ppEnabledExtensionNames[i], &layer_prop->instance_extension_list); |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 4844 | if (extension_prop) { |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 4845 | // Found the extension in one of the layers enabled by the app. |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 4846 | break; |
| 4847 | } |
| 4848 | } |
| 4849 | |
| 4850 | if (!extension_prop) { |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4851 | // Didn't find extension name in any of the global layers, error out |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 4852 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | 48cea0c | 2017-05-26 14:39:54 -0600 | [diff] [blame] | 4853 | "loader_validate_instance_extensions: Instance extension %s not supported by available ICDs or enabled " |
| 4854 | "layers.", |
| 4855 | pCreateInfo->ppEnabledExtensionNames[i]); |
Courtney Goeltzenleuchter | 55659b7 | 2015-09-14 18:01:17 -0600 | [diff] [blame] | 4856 | return VK_ERROR_EXTENSION_NOT_PRESENT; |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 4857 | } |
| 4858 | } |
| 4859 | return VK_SUCCESS; |
| 4860 | } |
| 4861 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4862 | VkResult loader_validate_device_extensions(struct loader_physical_device_tramp *phys_dev, |
| 4863 | const struct loader_layer_list *activated_device_layers, |
| 4864 | const struct loader_extension_list *icd_exts, const VkDeviceCreateInfo *pCreateInfo) { |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 4865 | VkExtensionProperties *extension_prop; |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 4866 | struct loader_layer_properties *layer_prop; |
| 4867 | |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 4868 | for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4869 | VkStringErrorFlags result = vk_string_validate(MaxLoaderStringLength, pCreateInfo->ppEnabledExtensionNames[i]); |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 4870 | if (result != VK_STRING_ERROR_NONE) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 4871 | loader_log(phys_dev->this_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | 48cea0c | 2017-05-26 14:39:54 -0600 | [diff] [blame] | 4872 | "loader_validate_device_extensions: Device ppEnabledExtensionNames contains " |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 4873 | "string that is too long or is badly formed"); |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 4874 | return VK_ERROR_EXTENSION_NOT_PRESENT; |
| 4875 | } |
| 4876 | |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 4877 | const char *extension_name = pCreateInfo->ppEnabledExtensionNames[i]; |
Jon Ashburn | 014438f | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 4878 | extension_prop = get_extension_property(extension_name, icd_exts); |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 4879 | |
| 4880 | if (extension_prop) { |
| 4881 | continue; |
| 4882 | } |
| 4883 | |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4884 | // Not in global list, search activated layer extension lists |
Jon Ashburn | 471f44c | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 4885 | for (uint32_t j = 0; j < activated_device_layers->count; j++) { |
| 4886 | layer_prop = &activated_device_layers->list[j]; |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 4887 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4888 | extension_prop = get_dev_extension_property(extension_name, &layer_prop->device_extension_list); |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 4889 | if (extension_prop) { |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4890 | // Found the extension in one of the layers enabled by the app. |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 4891 | break; |
| 4892 | } |
| 4893 | } |
| 4894 | |
| 4895 | if (!extension_prop) { |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4896 | // Didn't find extension name in any of the device layers, error out |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 4897 | loader_log(phys_dev->this_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | 48cea0c | 2017-05-26 14:39:54 -0600 | [diff] [blame] | 4898 | "loader_validate_device_extensions: Device extension %s not supported by selected physical device " |
| 4899 | "or enabled layers.", |
| 4900 | pCreateInfo->ppEnabledExtensionNames[i]); |
Courtney Goeltzenleuchter | 55659b7 | 2015-09-14 18:01:17 -0600 | [diff] [blame] | 4901 | return VK_ERROR_EXTENSION_NOT_PRESENT; |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 4902 | } |
| 4903 | } |
Courtney Goeltzenleuchter | 3b8c5ff | 2015-07-06 17:45:08 -0600 | [diff] [blame] | 4904 | return VK_SUCCESS; |
| 4905 | } |
| 4906 | |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4907 | // Terminator functions for the Instance chain |
| 4908 | // All named terminator_<Vulakn API name> |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4909 | VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateInstance(const VkInstanceCreateInfo *pCreateInfo, |
| 4910 | const VkAllocationCallbacks *pAllocator, VkInstance *pInstance) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4911 | struct loader_icd_term *icd_term; |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 4912 | VkExtensionProperties *prop; |
Courtney Goeltzenleuchter | 746db73 | 2015-07-06 17:42:01 -0600 | [diff] [blame] | 4913 | char **filtered_extension_names = NULL; |
| 4914 | VkInstanceCreateInfo icd_create_info; |
Courtney Goeltzenleuchter | 40caf0b | 2015-07-06 09:06:34 -0600 | [diff] [blame] | 4915 | VkResult res = VK_SUCCESS; |
Mark Young | 8b4edb5 | 2016-11-11 09:31:55 -0700 | [diff] [blame] | 4916 | bool one_icd_successful = false; |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 4917 | |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 4918 | struct loader_instance *ptr_instance = (struct loader_instance *)*pInstance; |
Tony Barbour | 3c78ff4 | 2015-12-04 13:24:39 -0700 | [diff] [blame] | 4919 | memcpy(&icd_create_info, pCreateInfo, sizeof(icd_create_info)); |
| 4920 | |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 4921 | icd_create_info.enabledLayerCount = 0; |
Courtney Goeltzenleuchter | 746db73 | 2015-07-06 17:42:01 -0600 | [diff] [blame] | 4922 | icd_create_info.ppEnabledLayerNames = NULL; |
Courtney Goeltzenleuchter | 746db73 | 2015-07-06 17:42:01 -0600 | [diff] [blame] | 4923 | |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4924 | // NOTE: Need to filter the extensions to only those supported by the ICD. |
| 4925 | // No ICD will advertise support for layers. An ICD library could |
| 4926 | // support a layer, but it would be independent of the actual ICD, |
| 4927 | // just in the same library. |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4928 | filtered_extension_names = loader_stack_alloc(pCreateInfo->enabledExtensionCount * sizeof(char *)); |
Courtney Goeltzenleuchter | 746db73 | 2015-07-06 17:42:01 -0600 | [diff] [blame] | 4929 | if (!filtered_extension_names) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 4930 | loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | 48cea0c | 2017-05-26 14:39:54 -0600 | [diff] [blame] | 4931 | "terminator_CreateInstance: Failed create extension name array for %d extensions", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4932 | pCreateInfo->enabledExtensionCount); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 4933 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 4934 | goto out; |
Courtney Goeltzenleuchter | 746db73 | 2015-07-06 17:42:01 -0600 | [diff] [blame] | 4935 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4936 | icd_create_info.ppEnabledExtensionNames = (const char *const *)filtered_extension_names; |
Courtney Goeltzenleuchter | 746db73 | 2015-07-06 17:42:01 -0600 | [diff] [blame] | 4937 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4938 | for (uint32_t i = 0; i < ptr_instance->icd_tramp_list.count; i++) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4939 | icd_term = loader_icd_add(ptr_instance, &ptr_instance->icd_tramp_list.scanned_list[i]); |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4940 | if (NULL == icd_term) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 4941 | loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | c8b807a | 2017-07-14 17:11:31 -0600 | [diff] [blame] | 4942 | "terminator_CreateInstance: Failed to add ICD %d to ICD trampoline list.", i); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 4943 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 4944 | goto out; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4945 | } |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 4946 | |
Lenny Komow | a44cc85 | 2017-09-12 22:54:21 -0600 | [diff] [blame] | 4947 | // If any error happens after here, we need to remove the ICD from the list, |
| 4948 | // because we've already added it, but haven't validated it |
| 4949 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4950 | icd_create_info.enabledExtensionCount = 0; |
| 4951 | struct loader_extension_list icd_exts; |
Courtney Goeltzenleuchter | 746db73 | 2015-07-06 17:42:01 -0600 | [diff] [blame] | 4952 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4953 | loader_log(ptr_instance, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, "Build ICD instance extension list"); |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 4954 | // traverse scanned icd list adding non-duplicate extensions to the list |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4955 | res = loader_init_generic_list(ptr_instance, (struct loader_generic_list *)&icd_exts, sizeof(VkExtensionProperties)); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 4956 | if (VK_ERROR_OUT_OF_HOST_MEMORY == res) { |
| 4957 | // If out of memory, bail immediately. |
| 4958 | goto out; |
| 4959 | } else if (VK_SUCCESS != res) { |
Mark Young | 7e47129 | 2016-09-06 09:53:45 -0600 | [diff] [blame] | 4960 | // Something bad happened with this ICD, so free it and try the |
| 4961 | // next. |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4962 | ptr_instance->icd_terms = icd_term->next; |
| 4963 | icd_term->next = NULL; |
| 4964 | loader_icd_destroy(ptr_instance, icd_term, pAllocator); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 4965 | continue; |
| 4966 | } |
| 4967 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4968 | res = loader_add_instance_extensions(ptr_instance, icd_term->scanned_icd->EnumerateInstanceExtensionProperties, |
| 4969 | icd_term->scanned_icd->lib_name, &icd_exts); |
Mark Young | db13a2a | 2016-09-06 13:53:03 -0600 | [diff] [blame] | 4970 | if (VK_SUCCESS != res) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4971 | loader_destroy_generic_list(ptr_instance, (struct loader_generic_list *)&icd_exts); |
Mark Young | db13a2a | 2016-09-06 13:53:03 -0600 | [diff] [blame] | 4972 | if (VK_ERROR_OUT_OF_HOST_MEMORY == res) { |
| 4973 | // If out of memory, bail immediately. |
| 4974 | goto out; |
| 4975 | } else { |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 4976 | // Something bad happened with this ICD, so free it and try the next. |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4977 | ptr_instance->icd_terms = icd_term->next; |
| 4978 | icd_term->next = NULL; |
| 4979 | loader_icd_destroy(ptr_instance, icd_term, pAllocator); |
Mark Young | db13a2a | 2016-09-06 13:53:03 -0600 | [diff] [blame] | 4980 | continue; |
| 4981 | } |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 4982 | } |
Courtney Goeltzenleuchter | 36eeb74 | 2015-12-21 16:41:47 -0700 | [diff] [blame] | 4983 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4984 | for (uint32_t j = 0; j < pCreateInfo->enabledExtensionCount; j++) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4985 | prop = get_extension_property(pCreateInfo->ppEnabledExtensionNames[j], &icd_exts); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4986 | if (prop) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4987 | filtered_extension_names[icd_create_info.enabledExtensionCount] = (char *)pCreateInfo->ppEnabledExtensionNames[j]; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4988 | icd_create_info.enabledExtensionCount++; |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 4989 | } |
| 4990 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4991 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4992 | loader_destroy_generic_list(ptr_instance, (struct loader_generic_list *)&icd_exts); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4993 | |
Mark Young | 8b4edb5 | 2016-11-11 09:31:55 -0700 | [diff] [blame] | 4994 | VkResult icd_result = |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4995 | ptr_instance->icd_tramp_list.scanned_list[i].CreateInstance(&icd_create_info, pAllocator, &(icd_term->instance)); |
Mark Young | 8b4edb5 | 2016-11-11 09:31:55 -0700 | [diff] [blame] | 4996 | if (VK_ERROR_OUT_OF_HOST_MEMORY == icd_result) { |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 4997 | // If out of memory, bail immediately. |
Mark Young | 8b4edb5 | 2016-11-11 09:31:55 -0700 | [diff] [blame] | 4998 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 4999 | goto out; |
Mark Young | 8b4edb5 | 2016-11-11 09:31:55 -0700 | [diff] [blame] | 5000 | } else if (VK_SUCCESS != icd_result) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 5001 | loader_log(ptr_instance, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 5002 | "terminator_CreateInstance: Failed to CreateInstance in " |
| 5003 | "ICD %d. Skipping ICD.", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5004 | i); |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5005 | ptr_instance->icd_terms = icd_term->next; |
| 5006 | icd_term->next = NULL; |
| 5007 | loader_icd_destroy(ptr_instance, icd_term, pAllocator); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 5008 | continue; |
| 5009 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 5010 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 5011 | if (!loader_icd_init_entries(icd_term, icd_term->instance, |
| 5012 | ptr_instance->icd_tramp_list.scanned_list[i].GetInstanceProcAddr)) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5013 | loader_log(ptr_instance, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 5014 | "terminator_CreateInstance: Failed to CreateInstance and find " |
| 5015 | "entrypoints with ICD. Skipping ICD."); |
Lenny Komow | a44cc85 | 2017-09-12 22:54:21 -0600 | [diff] [blame] | 5016 | ptr_instance->icd_terms = icd_term->next; |
| 5017 | icd_term->next = NULL; |
| 5018 | loader_icd_destroy(ptr_instance, icd_term, pAllocator); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 5019 | continue; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 5020 | } |
Mark Young | 8b4edb5 | 2016-11-11 09:31:55 -0700 | [diff] [blame] | 5021 | |
| 5022 | // If we made it this far, at least one ICD was successful |
| 5023 | one_icd_successful = true; |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 5024 | } |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 5025 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 5026 | // If no ICDs were added to instance list and res is unchanged from it's initial value, the loader was unable to |
| 5027 | // find a suitable ICD. |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5028 | if (VK_SUCCESS == res && (ptr_instance->icd_terms == NULL || !one_icd_successful)) { |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 5029 | res = VK_ERROR_INCOMPATIBLE_DRIVER; |
| 5030 | } |
| 5031 | |
| 5032 | out: |
| 5033 | |
| 5034 | if (VK_SUCCESS != res) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5035 | while (NULL != ptr_instance->icd_terms) { |
| 5036 | icd_term = ptr_instance->icd_terms; |
| 5037 | ptr_instance->icd_terms = icd_term->next; |
| 5038 | if (NULL != icd_term->instance) { |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 5039 | icd_term->dispatch.DestroyInstance(icd_term->instance, pAllocator); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 5040 | } |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5041 | loader_icd_destroy(ptr_instance, icd_term, pAllocator); |
Courtney Goeltzenleuchter | 40caf0b | 2015-07-06 09:06:34 -0600 | [diff] [blame] | 5042 | } |
Ian Elliott | eb45076 | 2015-02-05 15:19:15 -0700 | [diff] [blame] | 5043 | } |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 5044 | |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 5045 | return res; |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 5046 | } |
| 5047 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5048 | VKAPI_ATTR void VKAPI_CALL terminator_DestroyInstance(VkInstance instance, const VkAllocationCallbacks *pAllocator) { |
Courtney Goeltzenleuchter | deceded | 2015-06-08 15:04:02 -0600 | [diff] [blame] | 5049 | struct loader_instance *ptr_instance = loader_instance(instance); |
Karl Schultz | e2ef9e6 | 2017-01-13 14:01:35 -0700 | [diff] [blame] | 5050 | if (NULL == ptr_instance) { |
| 5051 | return; |
| 5052 | } |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5053 | struct loader_icd_term *icd_terms = ptr_instance->icd_terms; |
| 5054 | struct loader_icd_term *next_icd_term; |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 5055 | |
| 5056 | // Remove this instance from the list of instances: |
| 5057 | struct loader_instance *prev = NULL; |
| 5058 | struct loader_instance *next = loader.instances; |
| 5059 | while (next != NULL) { |
| 5060 | if (next == ptr_instance) { |
| 5061 | // Remove this instance from the list: |
| 5062 | if (prev) |
| 5063 | prev->next = next->next; |
Jon Ashburn | c5c4960 | 2015-02-03 09:26:59 -0700 | [diff] [blame] | 5064 | else |
| 5065 | loader.instances = next->next; |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 5066 | break; |
| 5067 | } |
| 5068 | prev = next; |
| 5069 | next = next->next; |
| 5070 | } |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 5071 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5072 | while (NULL != icd_terms) { |
| 5073 | if (icd_terms->instance) { |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 5074 | icd_terms->dispatch.DestroyInstance(icd_terms->instance, pAllocator); |
Tony Barbour | f20f87b | 2015-04-22 09:02:32 -0600 | [diff] [blame] | 5075 | } |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5076 | next_icd_term = icd_terms->next; |
| 5077 | icd_terms->instance = VK_NULL_HANDLE; |
| 5078 | loader_icd_destroy(ptr_instance, icd_terms, pAllocator); |
Jon Ashburn | a6fd261 | 2015-06-16 14:43:19 -0600 | [diff] [blame] | 5079 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5080 | icd_terms = next_icd_term; |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 5081 | } |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 5082 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5083 | loader_delete_layer_properties(ptr_instance, &ptr_instance->instance_layer_list); |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5084 | loader_scanned_icd_clear(ptr_instance, &ptr_instance->icd_tramp_list); |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5085 | loader_destroy_generic_list(ptr_instance, (struct loader_generic_list *)&ptr_instance->ext_list); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 5086 | if (NULL != ptr_instance->phys_devs_term) { |
Mark Young | 0193d65 | 2016-12-28 16:10:10 -0700 | [diff] [blame] | 5087 | for (uint32_t i = 0; i < ptr_instance->phys_dev_count_term; i++) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5088 | loader_instance_heap_free(ptr_instance, ptr_instance->phys_devs_term[i]); |
Lenny Komow | 8a1f8a5 | 2016-12-20 15:35:11 -0700 | [diff] [blame] | 5089 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 5090 | loader_instance_heap_free(ptr_instance, ptr_instance->phys_devs_term); |
Lenny Komow | 8a1f8a5 | 2016-12-20 15:35:11 -0700 | [diff] [blame] | 5091 | } |
Mark Young | d66edd5 | 2017-03-10 17:31:18 -0700 | [diff] [blame] | 5092 | if (NULL != ptr_instance->phys_dev_groups_term) { |
| 5093 | for (uint32_t i = 0; i < ptr_instance->phys_dev_group_count_term; i++) { |
| 5094 | loader_instance_heap_free(ptr_instance, ptr_instance->phys_dev_groups_term[i]); |
| 5095 | } |
| 5096 | loader_instance_heap_free(ptr_instance, ptr_instance->phys_dev_groups_term); |
| 5097 | } |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 5098 | loader_free_dev_ext_table(ptr_instance); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 5099 | loader_free_phys_dev_ext_table(ptr_instance); |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 5100 | } |
| 5101 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5102 | VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo *pCreateInfo, |
| 5103 | const VkAllocationCallbacks *pAllocator, VkDevice *pDevice) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 5104 | VkResult res = VK_SUCCESS; |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5105 | struct loader_physical_device_term *phys_dev_term; |
| 5106 | phys_dev_term = (struct loader_physical_device_term *)physicalDevice; |
| 5107 | struct loader_icd_term *icd_term = phys_dev_term->this_icd_term; |
Jon Ashburn | 24cd4be | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 5108 | |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 5109 | struct loader_device *dev = (struct loader_device *)*pDevice; |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 5110 | PFN_vkCreateDevice fpCreateDevice = icd_term->dispatch.CreateDevice; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 5111 | struct loader_extension_list icd_exts; |
| 5112 | |
Mark Young | 65cb366 | 2016-11-07 13:27:02 -0700 | [diff] [blame] | 5113 | dev->phys_dev_term = phys_dev_term; |
| 5114 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 5115 | icd_exts.list = NULL; |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 5116 | |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 5117 | if (fpCreateDevice == NULL) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5118 | loader_log(icd_term->this_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5119 | "terminator_CreateDevice: No vkCreateDevice command exposed " |
| 5120 | "by ICD %s", |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5121 | icd_term->scanned_icd->lib_name); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 5122 | res = VK_ERROR_INITIALIZATION_FAILED; |
| 5123 | goto out; |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 5124 | } |
| 5125 | |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 5126 | VkDeviceCreateInfo localCreateInfo; |
| 5127 | memcpy(&localCreateInfo, pCreateInfo, sizeof(localCreateInfo)); |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 5128 | |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5129 | // NOTE: Need to filter the extensions to only those supported by the ICD. |
Mark Young | e1ea901 | 2017-03-09 14:17:40 -0700 | [diff] [blame] | 5130 | // No ICD will advertise support for layers. An ICD library could support a layer, |
| 5131 | // but it would be independent of the actual ICD, just in the same library. |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 5132 | char **filtered_extension_names = NULL; |
Mark Young | e1ea901 | 2017-03-09 14:17:40 -0700 | [diff] [blame] | 5133 | if (0 < pCreateInfo->enabledExtensionCount) { |
| 5134 | filtered_extension_names = loader_stack_alloc(pCreateInfo->enabledExtensionCount * sizeof(char *)); |
| 5135 | if (NULL == filtered_extension_names) { |
| 5136 | loader_log(icd_term->this_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 5137 | "terminator_CreateDevice: Failed to create extension name " |
| 5138 | "storage for %d extensions %d", |
| 5139 | pCreateInfo->enabledExtensionCount); |
| 5140 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 5141 | } |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 5142 | } |
| 5143 | |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 5144 | localCreateInfo.enabledLayerCount = 0; |
| 5145 | localCreateInfo.ppEnabledLayerNames = NULL; |
| 5146 | |
| 5147 | localCreateInfo.enabledExtensionCount = 0; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5148 | localCreateInfo.ppEnabledExtensionNames = (const char *const *)filtered_extension_names; |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 5149 | |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5150 | // Get the physical device (ICD) extensions |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5151 | res = loader_init_generic_list(icd_term->this_instance, (struct loader_generic_list *)&icd_exts, sizeof(VkExtensionProperties)); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 5152 | if (VK_SUCCESS != res) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 5153 | goto out; |
Jon Ashburn | 014438f | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 5154 | } |
| 5155 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 5156 | res = loader_add_device_extensions(icd_term->this_instance, icd_term->dispatch.EnumerateDeviceExtensionProperties, |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5157 | phys_dev_term->phys_dev, icd_term->scanned_icd->lib_name, &icd_exts); |
Jon Ashburn | 014438f | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 5158 | if (res != VK_SUCCESS) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 5159 | goto out; |
Jon Ashburn | 014438f | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 5160 | } |
| 5161 | |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 5162 | for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) { |
| 5163 | const char *extension_name = pCreateInfo->ppEnabledExtensionNames[i]; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5164 | VkExtensionProperties *prop = get_extension_property(extension_name, &icd_exts); |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 5165 | if (prop) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5166 | filtered_extension_names[localCreateInfo.enabledExtensionCount] = (char *)extension_name; |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 5167 | localCreateInfo.enabledExtensionCount++; |
Mark Young | 9a3ddd4 | 2016-10-21 16:25:47 -0600 | [diff] [blame] | 5168 | } else { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 5169 | loader_log(icd_term->this_instance, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 5170 | "vkCreateDevice extension %s not available for " |
| 5171 | "devices associated with ICD %s", |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5172 | extension_name, icd_term->scanned_icd->lib_name); |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 5173 | } |
| 5174 | } |
| 5175 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 5176 | // Before we continue, If KHX_device_group is the list of enabled and viable extensions, then we then need to look for the |
| 5177 | // corresponding VkDeviceGroupDeviceCreateInfoKHX struct in the device list and replace all the physical device values (which |
| 5178 | // are really loader physical device terminator values) with the ICD versions. |
| 5179 | if (icd_term->this_instance->enabled_known_extensions.khx_device_group_creation == 1) { |
| 5180 | struct VkStructureHeader *pNext = (struct VkStructureHeader *)localCreateInfo.pNext; |
| 5181 | struct VkStructureHeader *pPrev = (struct VkStructureHeader *)&localCreateInfo; |
| 5182 | while (NULL != pNext) { |
| 5183 | if (VK_STRUCTURE_TYPE_DEVICE_GROUP_DEVICE_CREATE_INFO_KHX == pNext->sType) { |
| 5184 | VkDeviceGroupDeviceCreateInfoKHX *cur_struct = (VkDeviceGroupDeviceCreateInfoKHX *)pNext; |
| 5185 | if (0 < cur_struct->physicalDeviceCount && NULL != cur_struct->pPhysicalDevices) { |
| 5186 | VkDeviceGroupDeviceCreateInfoKHX *temp_struct = loader_stack_alloc(sizeof(VkDeviceGroupDeviceCreateInfoKHX)); |
| 5187 | VkPhysicalDevice *phys_dev_array = NULL; |
| 5188 | if (NULL == temp_struct) { |
| 5189 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 5190 | } |
| 5191 | memcpy(temp_struct, cur_struct, sizeof(VkDeviceGroupDeviceCreateInfoKHX)); |
| 5192 | phys_dev_array = loader_stack_alloc(sizeof(VkPhysicalDevice) * cur_struct->physicalDeviceCount); |
| 5193 | if (NULL == phys_dev_array) { |
| 5194 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 5195 | } |
| 5196 | |
| 5197 | // Before calling down, replace the incoming physical device values (which are really loader terminator |
| 5198 | // physical devices) with the ICDs physical device values. |
| 5199 | struct loader_physical_device_term *cur_term; |
| 5200 | for (uint32_t phys_dev = 0; phys_dev < cur_struct->physicalDeviceCount; phys_dev++) { |
| 5201 | cur_term = (struct loader_physical_device_term *)cur_struct->pPhysicalDevices[phys_dev]; |
| 5202 | phys_dev_array[phys_dev] = cur_term->phys_dev; |
| 5203 | } |
| 5204 | temp_struct->pPhysicalDevices = phys_dev_array; |
| 5205 | |
| 5206 | // Replace the old struct in the pNext chain with this one. |
| 5207 | pPrev->pNext = (const void *)temp_struct; |
| 5208 | pNext = (struct VkStructureHeader *)(temp_struct); |
| 5209 | } |
| 5210 | break; |
| 5211 | } |
| 5212 | |
| 5213 | pPrev = pNext; |
| 5214 | pNext = (struct VkStructureHeader *)(pPrev->pNext); |
| 5215 | } |
| 5216 | } |
| 5217 | |
Lenny Komow | 34d78d2 | 2017-05-24 15:47:15 -0600 | [diff] [blame] | 5218 | // Handle loader emulation for structs that are not supported by the ICD: |
| 5219 | // Presently, the emulation leaves the pNext chain alone. This means that the ICD will receive items in the chain which |
| 5220 | // are not recognized by the ICD. If this causes the ICD to fail, then the items would have to be removed here. The current |
| 5221 | // implementation does not remove them because copying the pNext chain would be impossible if the loader does not recognize |
| 5222 | // the any of the struct types, as the loader would not know the size to allocate and copy. |
| 5223 | if (icd_term->dispatch.GetPhysicalDeviceFeatures2KHR == NULL) { |
| 5224 | const void *pNext = localCreateInfo.pNext; |
| 5225 | while (pNext != NULL) { |
| 5226 | switch (*(VkStructureType *)pNext) { |
| 5227 | case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2_KHR: { |
| 5228 | loader_log(icd_term->this_instance, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, |
| 5229 | "vkCreateDevice: Emulating handling of VkPhysicalDeviceFeatures2KHR in pNext chain for ICD \"%s\"", |
| 5230 | icd_term->scanned_icd->lib_name); |
| 5231 | const VkPhysicalDeviceFeatures2KHR *features = pNext; |
| 5232 | |
| 5233 | // Verify that VK_KHR_get_physical_device_properties2 is enabled |
| 5234 | if (icd_term->this_instance->enabled_known_extensions.khr_get_physical_device_properties2) { |
| 5235 | localCreateInfo.pEnabledFeatures = &features->features; |
| 5236 | } |
| 5237 | |
| 5238 | // Leave this item in the pNext chain for now |
| 5239 | |
| 5240 | pNext = features->pNext; |
| 5241 | break; |
| 5242 | } |
| 5243 | |
| 5244 | case VK_STRUCTURE_TYPE_DEVICE_GROUP_DEVICE_CREATE_INFO_KHX: { |
| 5245 | loader_log( |
| 5246 | icd_term->this_instance, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, |
| 5247 | "vkCreateDevice: Emulating handling of VkDeviceGroupDeviceCreateInfoKHX in pNext chain for ICD \"%s\"", |
| 5248 | icd_term->scanned_icd->lib_name); |
| 5249 | const VkDeviceGroupDeviceCreateInfoKHX *group_info = pNext; |
| 5250 | |
| 5251 | // The group must contain only this one device, since physical device groups aren't actually supported |
| 5252 | if (group_info->physicalDeviceCount != 1 || group_info->pPhysicalDevices[0] != physicalDevice) { |
| 5253 | loader_log(icd_term->this_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 5254 | "vkCreateDevice: Emulation failed to create device from device group info"); |
| 5255 | res = VK_ERROR_INITIALIZATION_FAILED; |
| 5256 | goto out; |
| 5257 | } |
| 5258 | |
| 5259 | // Nothing needs to be done here because we're leaving the item in the pNext chain and because the spec states |
| 5260 | // that the physicalDevice argument must be included in the device group, and we've already checked that it is |
| 5261 | |
| 5262 | pNext = group_info->pNext; |
| 5263 | break; |
| 5264 | } |
| 5265 | |
| 5266 | // Multiview properties are also allowed, but since VK_KHX_multiview is a device extension, we'll just let the ICD |
| 5267 | // handle that error when the user enables the extension here |
| 5268 | default: { |
| 5269 | const struct VkStructureHeader *header = pNext; |
| 5270 | pNext = header->pNext; |
| 5271 | break; |
| 5272 | } |
| 5273 | } |
| 5274 | } |
| 5275 | } |
| 5276 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5277 | res = fpCreateDevice(phys_dev_term->phys_dev, &localCreateInfo, pAllocator, &dev->icd_device); |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 5278 | if (res != VK_SUCCESS) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5279 | loader_log(icd_term->this_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5280 | "terminator_CreateDevice: Failed in ICD %s vkCreateDevice" |
| 5281 | "call", |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5282 | icd_term->scanned_icd->lib_name); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 5283 | goto out; |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 5284 | } |
| 5285 | |
Mark Young | 65cb366 | 2016-11-07 13:27:02 -0700 | [diff] [blame] | 5286 | *pDevice = dev->icd_device; |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5287 | loader_add_logical_device(icd_term->this_instance, icd_term, dev); |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 5288 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 5289 | // Init dispatch pointer in new device object |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 5290 | loader_init_dispatch(*pDevice, &dev->loader_dispatch); |
| 5291 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 5292 | out: |
| 5293 | if (NULL != icd_exts.list) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5294 | loader_destroy_generic_list(icd_term->this_instance, (struct loader_generic_list *)&icd_exts); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 5295 | } |
| 5296 | |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 5297 | return res; |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 5298 | } |
| 5299 | |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5300 | VkResult setupLoaderTrampPhysDevs(VkInstance instance) { |
Jon Ashburn | 24cd4be | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 5301 | VkResult res = VK_SUCCESS; |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5302 | VkPhysicalDevice *local_phys_devs = NULL; |
| 5303 | struct loader_instance *inst; |
| 5304 | uint32_t total_count = 0; |
| 5305 | struct loader_physical_device_tramp **new_phys_devs = NULL; |
Jon Ashburn | 4c392fb | 2015-01-28 19:57:09 -0700 | [diff] [blame] | 5306 | |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5307 | inst = loader_get_instance(instance); |
| 5308 | if (NULL == inst) { |
| 5309 | res = VK_ERROR_INITIALIZATION_FAILED; |
| 5310 | goto out; |
| 5311 | } |
Mark Young | d66edd5 | 2017-03-10 17:31:18 -0700 | [diff] [blame] | 5312 | |
Mark Young | bb3a29c | 2017-05-19 12:29:43 -0600 | [diff] [blame] | 5313 | // Query how many GPUs there |
Mark Young | d66edd5 | 2017-03-10 17:31:18 -0700 | [diff] [blame] | 5314 | res = inst->disp->layer_inst_disp.EnumeratePhysicalDevices(instance, &total_count, NULL); |
| 5315 | if (res != VK_SUCCESS) { |
| 5316 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 5317 | "setupLoaderTrampPhysDevs: Failed during dispatch call " |
| 5318 | "of \'vkEnumeratePhysicalDevices\' to lower layers or " |
| 5319 | "loader to get count."); |
| 5320 | goto out; |
| 5321 | } |
| 5322 | |
| 5323 | // Really use what the total GPU count is since Optimus and other layers may mess |
| 5324 | // the count up. |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5325 | total_count = inst->total_gpu_count; |
| 5326 | |
| 5327 | // Create an array for the new physical devices, which will be stored |
| 5328 | // in the instance for the trampoline code. |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5329 | new_phys_devs = (struct loader_physical_device_tramp **)loader_instance_heap_alloc( |
| 5330 | inst, total_count * sizeof(struct loader_physical_device_tramp *), VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5331 | if (NULL == new_phys_devs) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 5332 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 5333 | "setupLoaderTrampPhysDevs: Failed to allocate new physical device" |
| 5334 | " array of size %d", |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5335 | total_count); |
Mark Young | d8382d7 | 2016-12-23 16:59:58 -0700 | [diff] [blame] | 5336 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 5337 | goto out; |
| 5338 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5339 | memset(new_phys_devs, 0, total_count * sizeof(struct loader_physical_device_tramp *)); |
Jon Ashburn | 014438f | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 5340 | |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5341 | // Create a temporary array (on the stack) to keep track of the |
| 5342 | // returned VkPhysicalDevice values. |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5343 | local_phys_devs = loader_stack_alloc(sizeof(VkPhysicalDevice) * total_count); |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5344 | if (NULL == local_phys_devs) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 5345 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 5346 | "setupLoaderTrampPhysDevs: Failed to allocate local " |
| 5347 | "physical device array of size %d", |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5348 | total_count); |
| 5349 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 5350 | goto out; |
| 5351 | } |
| 5352 | memset(local_phys_devs, 0, sizeof(VkPhysicalDevice) * total_count); |
| 5353 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5354 | res = inst->disp->layer_inst_disp.EnumeratePhysicalDevices(instance, &total_count, local_phys_devs); |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5355 | if (VK_SUCCESS != res) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 5356 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 5357 | "setupLoaderTrampPhysDevs: Failed during dispatch call " |
| 5358 | "of \'vkEnumeratePhysicalDevices\' to lower layers or " |
Mark Young | d66edd5 | 2017-03-10 17:31:18 -0700 | [diff] [blame] | 5359 | "loader to get content."); |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5360 | goto out; |
| 5361 | } |
| 5362 | |
| 5363 | // Copy or create everything to fill the new array of physical devices |
| 5364 | for (uint32_t new_idx = 0; new_idx < total_count; new_idx++) { |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5365 | // Check if this physical device is already in the old buffer |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5366 | for (uint32_t old_idx = 0; old_idx < inst->phys_dev_count_tramp; old_idx++) { |
| 5367 | if (local_phys_devs[new_idx] == inst->phys_devs_tramp[old_idx]->phys_dev) { |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5368 | new_phys_devs[new_idx] = inst->phys_devs_tramp[old_idx]; |
| 5369 | break; |
| 5370 | } |
Mark Young | d8382d7 | 2016-12-23 16:59:58 -0700 | [diff] [blame] | 5371 | } |
| 5372 | |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5373 | // If this physical device isn't in the old buffer, create it |
| 5374 | if (NULL == new_phys_devs[new_idx]) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5375 | new_phys_devs[new_idx] = (struct loader_physical_device_tramp *)loader_instance_heap_alloc( |
| 5376 | inst, sizeof(struct loader_physical_device_tramp), VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5377 | if (NULL == new_phys_devs[new_idx]) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 5378 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 5379 | "setupLoaderTrampPhysDevs: Failed to allocate " |
| 5380 | "physical device trampoline object %d", |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5381 | new_idx); |
| 5382 | total_count = new_idx; |
Mark Young | d8382d7 | 2016-12-23 16:59:58 -0700 | [diff] [blame] | 5383 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 5384 | goto out; |
| 5385 | } |
| 5386 | |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5387 | // Initialize the new physicalDevice object |
| 5388 | loader_set_dispatch((void *)new_phys_devs[new_idx], inst->disp); |
| 5389 | new_phys_devs[new_idx]->this_instance = inst; |
| 5390 | new_phys_devs[new_idx]->phys_dev = local_phys_devs[new_idx]; |
Mark Young | 559d750 | 2016-09-26 11:38:46 -0600 | [diff] [blame] | 5391 | } |
Lenny Komow | a5e0112 | 2016-12-22 15:29:43 -0700 | [diff] [blame] | 5392 | } |
Mark Young | 559d750 | 2016-09-26 11:38:46 -0600 | [diff] [blame] | 5393 | |
Lenny Komow | a5e0112 | 2016-12-22 15:29:43 -0700 | [diff] [blame] | 5394 | out: |
Mark Young | d8382d7 | 2016-12-23 16:59:58 -0700 | [diff] [blame] | 5395 | |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5396 | if (VK_SUCCESS != res) { |
| 5397 | if (NULL != new_phys_devs) { |
| 5398 | for (uint32_t i = 0; i < total_count; i++) { |
| 5399 | loader_instance_heap_free(inst, new_phys_devs[i]); |
Lenny Komow | a5e0112 | 2016-12-22 15:29:43 -0700 | [diff] [blame] | 5400 | } |
| 5401 | loader_instance_heap_free(inst, new_phys_devs); |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5402 | } |
| 5403 | total_count = 0; |
| 5404 | } else { |
| 5405 | // Free everything that didn't carry over to the new array of |
| 5406 | // physical devices |
| 5407 | if (NULL != inst->phys_devs_tramp) { |
| 5408 | for (uint32_t i = 0; i < inst->phys_dev_count_tramp; i++) { |
| 5409 | bool found = false; |
| 5410 | for (uint32_t j = 0; j < total_count; j++) { |
| 5411 | if (inst->phys_devs_tramp[i] == new_phys_devs[j]) { |
| 5412 | found = true; |
| 5413 | break; |
| 5414 | } |
| 5415 | } |
| 5416 | if (!found) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5417 | loader_instance_heap_free(inst, inst->phys_devs_tramp[i]); |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5418 | } |
| 5419 | } |
| 5420 | loader_instance_heap_free(inst, inst->phys_devs_tramp); |
| 5421 | } |
Mark Young | d8382d7 | 2016-12-23 16:59:58 -0700 | [diff] [blame] | 5422 | |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5423 | // Swap in the new physical device list |
| 5424 | inst->phys_dev_count_tramp = total_count; |
| 5425 | inst->phys_devs_tramp = new_phys_devs; |
| 5426 | } |
| 5427 | |
| 5428 | return res; |
| 5429 | } |
| 5430 | |
| 5431 | VkResult setupLoaderTermPhysDevs(struct loader_instance *inst) { |
| 5432 | VkResult res = VK_SUCCESS; |
| 5433 | struct loader_icd_term *icd_term; |
| 5434 | struct loader_phys_dev_per_icd *icd_phys_dev_array = NULL; |
| 5435 | struct loader_physical_device_term **new_phys_devs = NULL; |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5436 | |
| 5437 | inst->total_gpu_count = 0; |
| 5438 | |
| 5439 | // Allocate something to store the physical device characteristics |
| 5440 | // that we read from each ICD. |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5441 | icd_phys_dev_array = |
| 5442 | (struct loader_phys_dev_per_icd *)loader_stack_alloc(sizeof(struct loader_phys_dev_per_icd) * inst->total_icd_count); |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5443 | if (NULL == icd_phys_dev_array) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 5444 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 5445 | "setupLoaderTermPhysDevs: Failed to allocate temporary " |
| 5446 | "ICD Physical device info array of size %d", |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5447 | inst->total_gpu_count); |
| 5448 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 5449 | goto out; |
| 5450 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5451 | memset(icd_phys_dev_array, 0, sizeof(struct loader_phys_dev_per_icd) * inst->total_icd_count); |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5452 | icd_term = inst->icd_terms; |
| 5453 | |
| 5454 | // For each ICD, query the number of physical devices, and then get an |
| 5455 | // internal value for those physical devices. |
Karl Schultz | 47dd59d | 2017-01-20 13:19:20 -0700 | [diff] [blame] | 5456 | for (uint32_t icd_idx = 0; NULL != icd_term; icd_term = icd_term->next, icd_idx++) { |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 5457 | res = icd_term->dispatch.EnumeratePhysicalDevices(icd_term->instance, &icd_phys_dev_array[icd_idx].count, NULL); |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5458 | if (VK_SUCCESS != res) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 5459 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 5460 | "setupLoaderTermPhysDevs: Call to " |
| 5461 | "ICD %d's \'vkEnumeratePhysicalDevices\' failed with" |
| 5462 | " error 0x%08x", |
Karl Schultz | 47dd59d | 2017-01-20 13:19:20 -0700 | [diff] [blame] | 5463 | icd_idx, res); |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5464 | goto out; |
| 5465 | } |
| 5466 | |
Karl Schultz | 47dd59d | 2017-01-20 13:19:20 -0700 | [diff] [blame] | 5467 | icd_phys_dev_array[icd_idx].phys_devs = |
| 5468 | (VkPhysicalDevice *)loader_stack_alloc(icd_phys_dev_array[icd_idx].count * sizeof(VkPhysicalDevice)); |
| 5469 | if (NULL == icd_phys_dev_array[icd_idx].phys_devs) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 5470 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 5471 | "setupLoaderTermPhysDevs: Failed to allocate temporary " |
| 5472 | "ICD Physical device array for ICD %d of size %d", |
Karl Schultz | 47dd59d | 2017-01-20 13:19:20 -0700 | [diff] [blame] | 5473 | icd_idx, inst->total_gpu_count); |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5474 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 5475 | goto out; |
| 5476 | } |
| 5477 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 5478 | res = icd_term->dispatch.EnumeratePhysicalDevices(icd_term->instance, &(icd_phys_dev_array[icd_idx].count), |
| 5479 | icd_phys_dev_array[icd_idx].phys_devs); |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5480 | if (VK_SUCCESS != res) { |
| 5481 | goto out; |
| 5482 | } |
Karl Schultz | 47dd59d | 2017-01-20 13:19:20 -0700 | [diff] [blame] | 5483 | inst->total_gpu_count += icd_phys_dev_array[icd_idx].count; |
| 5484 | icd_phys_dev_array[icd_idx].this_icd_term = icd_term; |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5485 | } |
| 5486 | |
| 5487 | if (0 == inst->total_gpu_count) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 5488 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 5489 | "setupLoaderTermPhysDevs: Failed to detect any valid" |
| 5490 | " GPUs in the current config"); |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5491 | res = VK_ERROR_INITIALIZATION_FAILED; |
| 5492 | goto out; |
| 5493 | } |
| 5494 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5495 | new_phys_devs = loader_instance_heap_alloc(inst, sizeof(struct loader_physical_device_term *) * inst->total_gpu_count, |
| 5496 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5497 | if (NULL == new_phys_devs) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 5498 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 5499 | "setupLoaderTermPhysDevs: Failed to allocate new physical" |
| 5500 | " device array of size %d", |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5501 | inst->total_gpu_count); |
| 5502 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 5503 | goto out; |
| 5504 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5505 | memset(new_phys_devs, 0, sizeof(struct loader_physical_device_term *) * inst->total_gpu_count); |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5506 | |
| 5507 | // Copy or create everything to fill the new array of physical devices |
| 5508 | uint32_t idx = 0; |
| 5509 | for (uint32_t icd_idx = 0; icd_idx < inst->total_icd_count; icd_idx++) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5510 | for (uint32_t pd_idx = 0; pd_idx < icd_phys_dev_array[icd_idx].count; pd_idx++) { |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5511 | // Check if this physical device is already in the old buffer |
| 5512 | if (NULL != inst->phys_devs_term) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5513 | for (uint32_t old_idx = 0; old_idx < inst->phys_dev_count_term; old_idx++) { |
| 5514 | if (icd_phys_dev_array[icd_idx].phys_devs[pd_idx] == inst->phys_devs_term[old_idx]->phys_dev) { |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5515 | new_phys_devs[idx] = inst->phys_devs_term[old_idx]; |
| 5516 | break; |
| 5517 | } |
| 5518 | } |
| 5519 | } |
| 5520 | // If this physical device isn't in the old buffer, then we |
| 5521 | // need to create it. |
| 5522 | if (NULL == new_phys_devs[idx]) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5523 | new_phys_devs[idx] = loader_instance_heap_alloc(inst, sizeof(struct loader_physical_device_term), |
| 5524 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5525 | if (NULL == new_phys_devs[idx]) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 5526 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 5527 | "setupLoaderTermPhysDevs: Failed to allocate " |
| 5528 | "physical device terminator object %d", |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5529 | idx); |
| 5530 | inst->total_gpu_count = idx; |
| 5531 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 5532 | goto out; |
| 5533 | } |
| 5534 | |
| 5535 | loader_set_dispatch((void *)new_phys_devs[idx], inst->disp); |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5536 | new_phys_devs[idx]->this_icd_term = icd_phys_dev_array[icd_idx].this_icd_term; |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5537 | new_phys_devs[idx]->icd_index = (uint8_t)(icd_idx); |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5538 | new_phys_devs[idx]->phys_dev = icd_phys_dev_array[icd_idx].phys_devs[pd_idx]; |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5539 | } |
| 5540 | idx++; |
| 5541 | } |
| 5542 | } |
| 5543 | |
| 5544 | out: |
| 5545 | |
| 5546 | if (VK_SUCCESS != res) { |
Mark Young | 156e855 | 2017-02-03 16:27:42 -0700 | [diff] [blame] | 5547 | if (NULL != new_phys_devs) { |
| 5548 | // We've encountered an error, so we should free the new buffers. |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5549 | for (uint32_t i = 0; i < inst->total_gpu_count; i++) { |
| 5550 | loader_instance_heap_free(inst, new_phys_devs[i]); |
| 5551 | } |
Mark Young | 156e855 | 2017-02-03 16:27:42 -0700 | [diff] [blame] | 5552 | loader_instance_heap_free(inst, new_phys_devs); |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5553 | } |
Mark Young | 156e855 | 2017-02-03 16:27:42 -0700 | [diff] [blame] | 5554 | inst->total_gpu_count = 0; |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5555 | } else { |
| 5556 | // Free everything that didn't carry over to the new array of |
| 5557 | // physical devices. Everything else will have been copied over |
| 5558 | // to the new array. |
| 5559 | if (NULL != inst->phys_devs_term) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5560 | for (uint32_t cur_pd = 0; cur_pd < inst->phys_dev_count_term; cur_pd++) { |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5561 | bool found = false; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5562 | for (uint32_t new_pd_idx = 0; new_pd_idx < inst->total_gpu_count; new_pd_idx++) { |
| 5563 | if (inst->phys_devs_term[cur_pd] == new_phys_devs[new_pd_idx]) { |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5564 | found = true; |
| 5565 | break; |
| 5566 | } |
| 5567 | } |
| 5568 | if (!found) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5569 | loader_instance_heap_free(inst, inst->phys_devs_term[cur_pd]); |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5570 | } |
| 5571 | } |
| 5572 | loader_instance_heap_free(inst, inst->phys_devs_term); |
| 5573 | } |
| 5574 | |
| 5575 | // Swap out old and new devices list |
| 5576 | inst->phys_dev_count_term = inst->total_gpu_count; |
| 5577 | inst->phys_devs_term = new_phys_devs; |
| 5578 | } |
| 5579 | |
| 5580 | return res; |
| 5581 | } |
| 5582 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5583 | VKAPI_ATTR VkResult VKAPI_CALL terminator_EnumeratePhysicalDevices(VkInstance instance, uint32_t *pPhysicalDeviceCount, |
| 5584 | VkPhysicalDevice *pPhysicalDevices) { |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5585 | struct loader_instance *inst = (struct loader_instance *)instance; |
| 5586 | VkResult res = VK_SUCCESS; |
| 5587 | |
Mark Young | d66edd5 | 2017-03-10 17:31:18 -0700 | [diff] [blame] | 5588 | // Always call the setup loader terminator physical devices because they may |
| 5589 | // have changed at any point. |
| 5590 | res = setupLoaderTermPhysDevs(inst); |
| 5591 | if (VK_SUCCESS != res) { |
| 5592 | goto out; |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5593 | } |
| 5594 | |
| 5595 | uint32_t copy_count = inst->total_gpu_count; |
| 5596 | if (NULL != pPhysicalDevices) { |
| 5597 | if (copy_count > *pPhysicalDeviceCount) { |
| 5598 | copy_count = *pPhysicalDeviceCount; |
| 5599 | res = VK_INCOMPLETE; |
| 5600 | } |
| 5601 | |
| 5602 | for (uint32_t i = 0; i < copy_count; i++) { |
| 5603 | pPhysicalDevices[i] = (VkPhysicalDevice)inst->phys_devs_term[i]; |
Jon Ashburn | 014438f | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 5604 | } |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 5605 | } |
Mark Young | 559d750 | 2016-09-26 11:38:46 -0600 | [diff] [blame] | 5606 | |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 5607 | *pPhysicalDeviceCount = copy_count; |
| 5608 | |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5609 | out: |
| 5610 | |
Jon Ashburn | 24cd4be | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 5611 | return res; |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 5612 | } |
| 5613 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5614 | VKAPI_ATTR void VKAPI_CALL terminator_GetPhysicalDeviceProperties(VkPhysicalDevice physicalDevice, |
| 5615 | VkPhysicalDeviceProperties *pProperties) { |
| 5616 | struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice; |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5617 | struct loader_icd_term *icd_term = phys_dev_term->this_icd_term; |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 5618 | if (NULL != icd_term->dispatch.GetPhysicalDeviceProperties) { |
| 5619 | icd_term->dispatch.GetPhysicalDeviceProperties(phys_dev_term->phys_dev, pProperties); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5620 | } |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 5621 | } |
| 5622 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5623 | VKAPI_ATTR void VKAPI_CALL terminator_GetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice, |
| 5624 | uint32_t *pQueueFamilyPropertyCount, |
| 5625 | VkQueueFamilyProperties *pProperties) { |
| 5626 | struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice; |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5627 | struct loader_icd_term *icd_term = phys_dev_term->this_icd_term; |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 5628 | if (NULL != icd_term->dispatch.GetPhysicalDeviceQueueFamilyProperties) { |
| 5629 | icd_term->dispatch.GetPhysicalDeviceQueueFamilyProperties(phys_dev_term->phys_dev, pQueueFamilyPropertyCount, pProperties); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5630 | } |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 5631 | } |
| 5632 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5633 | VKAPI_ATTR void VKAPI_CALL terminator_GetPhysicalDeviceMemoryProperties(VkPhysicalDevice physicalDevice, |
| 5634 | VkPhysicalDeviceMemoryProperties *pProperties) { |
| 5635 | struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice; |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5636 | struct loader_icd_term *icd_term = phys_dev_term->this_icd_term; |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 5637 | if (NULL != icd_term->dispatch.GetPhysicalDeviceMemoryProperties) { |
| 5638 | icd_term->dispatch.GetPhysicalDeviceMemoryProperties(phys_dev_term->phys_dev, pProperties); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5639 | } |
Jon Ashburn | 3da71f2 | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 5640 | } |
| 5641 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5642 | VKAPI_ATTR void VKAPI_CALL terminator_GetPhysicalDeviceFeatures(VkPhysicalDevice physicalDevice, |
| 5643 | VkPhysicalDeviceFeatures *pFeatures) { |
| 5644 | struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice; |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5645 | struct loader_icd_term *icd_term = phys_dev_term->this_icd_term; |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 5646 | if (NULL != icd_term->dispatch.GetPhysicalDeviceFeatures) { |
| 5647 | icd_term->dispatch.GetPhysicalDeviceFeatures(phys_dev_term->phys_dev, pFeatures); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5648 | } |
Chris Forbes | bc0bb77 | 2015-06-21 22:55:02 +1200 | [diff] [blame] | 5649 | } |
| 5650 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5651 | VKAPI_ATTR void VKAPI_CALL terminator_GetPhysicalDeviceFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, |
| 5652 | VkFormatProperties *pFormatInfo) { |
| 5653 | struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice; |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5654 | struct loader_icd_term *icd_term = phys_dev_term->this_icd_term; |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 5655 | if (NULL != icd_term->dispatch.GetPhysicalDeviceFormatProperties) { |
| 5656 | icd_term->dispatch.GetPhysicalDeviceFormatProperties(phys_dev_term->phys_dev, format, pFormatInfo); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5657 | } |
Chris Forbes | bc0bb77 | 2015-06-21 22:55:02 +1200 | [diff] [blame] | 5658 | } |
| 5659 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5660 | VKAPI_ATTR VkResult VKAPI_CALL terminator_GetPhysicalDeviceImageFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, |
| 5661 | VkImageType type, VkImageTiling tiling, |
| 5662 | VkImageUsageFlags usage, VkImageCreateFlags flags, |
| 5663 | VkImageFormatProperties *pImageFormatProperties) { |
| 5664 | struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice; |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5665 | struct loader_icd_term *icd_term = phys_dev_term->this_icd_term; |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 5666 | if (NULL == icd_term->dispatch.GetPhysicalDeviceImageFormatProperties) { |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5667 | loader_log(icd_term->this_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 5668 | "Encountered the vkEnumerateDeviceLayerProperties " |
| 5669 | "terminator. This means a layer improperly continued."); |
Chia-I Wu | 1724104 | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 5670 | return VK_ERROR_INITIALIZATION_FAILED; |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5671 | } |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 5672 | return icd_term->dispatch.GetPhysicalDeviceImageFormatProperties(phys_dev_term->phys_dev, format, type, tiling, usage, flags, |
| 5673 | pImageFormatProperties); |
Jon Ashburn | 754864f | 2015-07-23 18:49:07 -0600 | [diff] [blame] | 5674 | } |
| 5675 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5676 | VKAPI_ATTR void VKAPI_CALL terminator_GetPhysicalDeviceSparseImageFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, |
| 5677 | VkImageType type, VkSampleCountFlagBits samples, |
| 5678 | VkImageUsageFlags usage, VkImageTiling tiling, |
| 5679 | uint32_t *pNumProperties, |
| 5680 | VkSparseImageFormatProperties *pProperties) { |
| 5681 | struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice; |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5682 | struct loader_icd_term *icd_term = phys_dev_term->this_icd_term; |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 5683 | if (NULL != icd_term->dispatch.GetPhysicalDeviceSparseImageFormatProperties) { |
| 5684 | icd_term->dispatch.GetPhysicalDeviceSparseImageFormatProperties(phys_dev_term->phys_dev, format, type, samples, usage, |
| 5685 | tiling, pNumProperties, pProperties); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5686 | } |
Mark Lobodzinski | 16e8bef | 2015-07-03 15:58:09 -0600 | [diff] [blame] | 5687 | } |
| 5688 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5689 | VKAPI_ATTR VkResult VKAPI_CALL terminator_EnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice, |
| 5690 | const char *pLayerName, uint32_t *pPropertyCount, |
| 5691 | VkExtensionProperties *pProperties) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5692 | struct loader_physical_device_term *phys_dev_term; |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 5693 | |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 5694 | struct loader_layer_list implicit_layer_list = {0}; |
| 5695 | struct loader_extension_list all_exts = {0}; |
| 5696 | struct loader_extension_list icd_exts = {0}; |
Jon Ashburn | 471f44c | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 5697 | |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 5698 | assert(pLayerName == NULL || strlen(pLayerName) == 0); |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 5699 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 5700 | // Any layer or trampoline wrapping should be removed at this point in time can just cast to the expected |
| 5701 | // type for VkPhysicalDevice. |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5702 | phys_dev_term = (struct loader_physical_device_term *)physicalDevice; |
Jon Ashburn | 471f44c | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 5703 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 5704 | // This case is during the call down the instance chain with pLayerName == NULL |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5705 | struct loader_icd_term *icd_term = phys_dev_term->this_icd_term; |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 5706 | uint32_t icd_ext_count = *pPropertyCount; |
| 5707 | VkResult res; |
Jon Ashburn | 471f44c | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 5708 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 5709 | // Get the available device extensions |
| 5710 | res = icd_term->dispatch.EnumerateDeviceExtensionProperties(phys_dev_term->phys_dev, NULL, &icd_ext_count, pProperties); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 5711 | if (res != VK_SUCCESS) { |
| 5712 | goto out; |
| 5713 | } |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 5714 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5715 | if (!loader_init_layer_list(icd_term->this_instance, &implicit_layer_list)) { |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 5716 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 5717 | goto out; |
| 5718 | } |
Jon Ashburn | 471f44c | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 5719 | |
Mark Young | 283fe1c | 2017-05-04 12:16:35 -0600 | [diff] [blame] | 5720 | loader_add_implicit_layers(icd_term->this_instance, &implicit_layer_list, NULL, &icd_term->this_instance->instance_layer_list); |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 5721 | // We need to determine which implicit layers are active, and then add their extensions. This can't be cached as |
| 5722 | // it depends on results of environment variables (which can change). |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 5723 | if (pProperties != NULL) { |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 5724 | // Initialize dev_extension list within the physicalDevice object |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5725 | res = loader_init_device_extensions(icd_term->this_instance, phys_dev_term, icd_ext_count, pProperties, &icd_exts); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 5726 | if (res != VK_SUCCESS) { |
| 5727 | goto out; |
| 5728 | } |
Jon Ashburn | 471f44c | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 5729 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 5730 | // We need to determine which implicit layers are active, and then add their extensions. This can't be cached as |
| 5731 | // it depends on results of environment variables (which can change). |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5732 | res = loader_add_to_ext_list(icd_term->this_instance, &all_exts, icd_exts.count, icd_exts.list); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 5733 | if (res != VK_SUCCESS) { |
| 5734 | goto out; |
| 5735 | } |
Jon Ashburn | 471f44c | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 5736 | |
Mark Young | 283fe1c | 2017-05-04 12:16:35 -0600 | [diff] [blame] | 5737 | loader_add_implicit_layers(icd_term->this_instance, &implicit_layer_list, NULL, |
| 5738 | &icd_term->this_instance->instance_layer_list); |
Jon Ashburn | 471f44c | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 5739 | |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 5740 | for (uint32_t i = 0; i < implicit_layer_list.count; i++) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5741 | for (uint32_t j = 0; j < implicit_layer_list.list[i].device_extension_list.count; j++) { |
| 5742 | res = loader_add_to_ext_list(icd_term->this_instance, &all_exts, 1, |
| 5743 | &implicit_layer_list.list[i].device_extension_list.list[j].props); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 5744 | if (res != VK_SUCCESS) { |
| 5745 | goto out; |
| 5746 | } |
Jon Ashburn | 471f44c | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 5747 | } |
Jon Ashburn | 471f44c | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 5748 | } |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 5749 | uint32_t capacity = *pPropertyCount; |
| 5750 | VkExtensionProperties *props = pProperties; |
Jon Ashburn | 471f44c | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 5751 | |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 5752 | for (uint32_t i = 0; i < all_exts.count && i < capacity; i++) { |
| 5753 | props[i] = all_exts.list[i]; |
| 5754 | } |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 5755 | |
| 5756 | // Wasn't enough space for the extensions, we did partial copy now return VK_INCOMPLETE |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 5757 | if (capacity < all_exts.count) { |
| 5758 | res = VK_INCOMPLETE; |
| 5759 | } else { |
| 5760 | *pPropertyCount = all_exts.count; |
| 5761 | } |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 5762 | } else { |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 5763 | // Just return the count; need to add in the count of implicit layer extensions |
| 5764 | // don't worry about duplicates being added in the count |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 5765 | *pPropertyCount = icd_ext_count; |
| 5766 | |
| 5767 | for (uint32_t i = 0; i < implicit_layer_list.count; i++) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5768 | *pPropertyCount += implicit_layer_list.list[i].device_extension_list.count; |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 5769 | } |
| 5770 | res = VK_SUCCESS; |
Jon Ashburn | b82c185 | 2015-08-11 14:49:54 -0600 | [diff] [blame] | 5771 | } |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 5772 | |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 5773 | out: |
| 5774 | |
| 5775 | if (NULL != implicit_layer_list.list) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5776 | loader_destroy_generic_list(icd_term->this_instance, (struct loader_generic_list *)&implicit_layer_list); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 5777 | } |
| 5778 | if (NULL != all_exts.list) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5779 | loader_destroy_generic_list(icd_term->this_instance, (struct loader_generic_list *)&all_exts); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 5780 | } |
| 5781 | if (NULL != icd_exts.list) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5782 | loader_destroy_generic_list(icd_term->this_instance, (struct loader_generic_list *)&icd_exts); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 5783 | } |
| 5784 | |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 5785 | return res; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 5786 | } |
| 5787 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5788 | VKAPI_ATTR VkResult VKAPI_CALL terminator_EnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice, uint32_t *pPropertyCount, |
| 5789 | VkLayerProperties *pProperties) { |
| 5790 | struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice; |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5791 | struct loader_icd_term *icd_term = phys_dev_term->this_icd_term; |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 5792 | loader_log(icd_term->this_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 5793 | "Encountered the vkEnumerateDeviceLayerProperties " |
| 5794 | "terminator. This means a layer improperly continued."); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5795 | // Should never get here this call isn't dispatched down the chain |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 5796 | return VK_ERROR_INITIALIZATION_FAILED; |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 5797 | } |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 5798 | |
Jon Ashburn | f2b4e38 | 2016-02-10 20:50:19 -0700 | [diff] [blame] | 5799 | VkStringErrorFlags vk_string_validate(const int max_length, const char *utf8) { |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 5800 | VkStringErrorFlags result = VK_STRING_ERROR_NONE; |
Karl Schultz | 2558bd3 | 2016-02-24 14:39:39 -0700 | [diff] [blame] | 5801 | int num_char_bytes = 0; |
Jon Ashburn | f2b4e38 | 2016-02-10 20:50:19 -0700 | [diff] [blame] | 5802 | int i, j; |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 5803 | |
Courtney Goeltzenleuchter | 7a3486d | 2016-12-21 16:24:34 -0700 | [diff] [blame] | 5804 | for (i = 0; i <= max_length; i++) { |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 5805 | if (utf8[i] == 0) { |
| 5806 | break; |
Courtney Goeltzenleuchter | 7a3486d | 2016-12-21 16:24:34 -0700 | [diff] [blame] | 5807 | } else if (i == max_length) { |
| 5808 | result |= VK_STRING_ERROR_LENGTH; |
| 5809 | break; |
Mark Lobodzinski | 36b4de2 | 2016-02-12 11:30:14 -0700 | [diff] [blame] | 5810 | } else if ((utf8[i] >= 0x20) && (utf8[i] < 0x7f)) { |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 5811 | num_char_bytes = 0; |
Jon Ashburn | f2b4e38 | 2016-02-10 20:50:19 -0700 | [diff] [blame] | 5812 | } else if ((utf8[i] & UTF8_ONE_BYTE_MASK) == UTF8_ONE_BYTE_CODE) { |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 5813 | num_char_bytes = 1; |
Jon Ashburn | f2b4e38 | 2016-02-10 20:50:19 -0700 | [diff] [blame] | 5814 | } else if ((utf8[i] & UTF8_TWO_BYTE_MASK) == UTF8_TWO_BYTE_CODE) { |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 5815 | num_char_bytes = 2; |
| 5816 | } else if ((utf8[i] & UTF8_THREE_BYTE_MASK) == UTF8_THREE_BYTE_CODE) { |
| 5817 | num_char_bytes = 3; |
| 5818 | } else { |
| 5819 | result = VK_STRING_ERROR_BAD_DATA; |
| 5820 | } |
| 5821 | |
| 5822 | // Validate the following num_char_bytes of data |
| 5823 | for (j = 0; (j < num_char_bytes) && (i < max_length); j++) { |
| 5824 | if (++i == max_length) { |
| 5825 | result |= VK_STRING_ERROR_LENGTH; |
| 5826 | break; |
| 5827 | } |
| 5828 | if ((utf8[i] & UTF8_DATA_BYTE_MASK) != UTF8_DATA_BYTE_CODE) { |
| 5829 | result |= VK_STRING_ERROR_BAD_DATA; |
| 5830 | } |
| 5831 | } |
| 5832 | } |
| 5833 | return result; |
| 5834 | } |