Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1 | /* |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 2 | * Vulkan |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2014 LunarG, Inc. |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 7 | * copy of this software and associated documentation files (the "Software"), |
| 8 | * to deal in the Software without restriction, including without limitation |
| 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 10 | * and/or sell copies of the Software, and to permit persons to whom the |
| 11 | * Software is furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included |
| 14 | * in all copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 22 | * DEALINGS IN THE SOFTWARE. |
Chia-I Wu | 44e4236 | 2014-09-02 08:32:09 +0800 | [diff] [blame] | 23 | * |
| 24 | * Authors: |
| 25 | * Chia-I Wu <olv@lunarg.com> |
Jon Ashburn | 406a0fe | 2014-11-14 09:52:42 -0700 | [diff] [blame] | 26 | * Jon Ashburn <jon@lunarg.com> |
Chia-I Wu | 44e4236 | 2014-09-02 08:32:09 +0800 | [diff] [blame] | 27 | * Courtney Goeltzenleuchter <courtney@lunarg.com> |
Ian Elliott | 7600513 | 2015-03-31 15:32:41 -0600 | [diff] [blame] | 28 | * Ian Elliott <ian@lunarg.com> |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 29 | */ |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 30 | #define _GNU_SOURCE |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 31 | #include <stdio.h> |
| 32 | #include <stdlib.h> |
| 33 | #include <stdarg.h> |
| 34 | #include <stdbool.h> |
| 35 | #include <string.h> |
| 36 | |
Chia-I Wu | 894a117 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 37 | #include <sys/types.h> |
Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 38 | #if defined(WIN32) |
| 39 | #include "dirent_on_windows.h" |
| 40 | #else // WIN32 |
Chia-I Wu | 894a117 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 41 | #include <dirent.h> |
Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 42 | #endif // WIN32 |
| 43 | #include "loader_platform.h" |
Chia-I Wu | 38e5a2c | 2015-01-04 11:12:47 +0800 | [diff] [blame] | 44 | #include "table_ops.h" |
Jon Ashburn | e18431b | 2015-04-13 18:10:06 -0600 | [diff] [blame] | 45 | #include "gpa_helper.h" |
Chia-I Wu | 468e3c3 | 2014-08-04 08:03:57 +0800 | [diff] [blame] | 46 | #include "loader.h" |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 47 | #include "vkIcd.h" |
Ian Elliott | 20f0687 | 2015-02-12 17:08:34 -0700 | [diff] [blame] | 48 | // The following is #included again to catch certain OS-specific functions |
| 49 | // being used: |
| 50 | #include "loader_platform.h" |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 51 | |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 52 | struct loader_layers { |
Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 53 | loader_platform_dl_handle lib_handle; |
Jon Ashburn | ead95c5 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 54 | char name[256]; |
| 55 | }; |
| 56 | |
| 57 | struct layer_name_pair { |
| 58 | char *layer_name; |
| 59 | const char *lib_name; |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 60 | }; |
| 61 | |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 62 | struct extension_property { |
| 63 | char extName[VK_MAX_EXTENSION_NAME]; |
| 64 | uint32_t version; |
| 65 | bool hosted; // does the extension reside in one driver/layer |
| 66 | }; |
| 67 | |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 68 | struct loader_icd { |
Jon Ashburn | 14275da | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 69 | const struct loader_scanned_icds *scanned_icds; |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 70 | |
Jon Ashburn | 301c5f0 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 71 | VkLayerDispatchTable *loader_dispatch; |
Jon Ashburn | 07b309a | 2015-04-15 11:31:12 -0600 | [diff] [blame] | 72 | uint32_t layer_count[MAX_GPUS_FOR_LAYER]; |
| 73 | struct loader_layers layer_libs[MAX_GPUS_FOR_LAYER][MAX_LAYER_LIBRARIES]; |
| 74 | VkBaseLayerObject *wrappedGpus[MAX_GPUS_FOR_LAYER]; |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 75 | uint32_t gpu_count; |
Jon Ashburn | 301c5f0 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 76 | VkBaseLayerObject *gpus; |
Jon Ashburn | 815bddd | 2014-10-16 15:48:50 -0600 | [diff] [blame] | 77 | |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 78 | struct loader_icd *next; |
| 79 | }; |
| 80 | |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 81 | |
Jon Ashburn | 14275da | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 82 | struct loader_scanned_icds { |
Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 83 | loader_platform_dl_handle handle; |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 84 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 85 | PFN_vkGetProcAddr GetProcAddr; |
| 86 | PFN_vkCreateInstance CreateInstance; |
| 87 | PFN_vkDestroyInstance DestroyInstance; |
Jon Ashburn | 07b309a | 2015-04-15 11:31:12 -0600 | [diff] [blame] | 88 | PFN_vkEnumeratePhysicalDevices EnumeratePhysicalDevices; |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 89 | PFN_vkGetGlobalExtensionInfo GetGlobalExtensionInfo; |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 90 | VkInstance instance; |
Jon Ashburn | 14275da | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 91 | struct loader_scanned_icds *next; |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 92 | uint32_t extension_count; |
| 93 | struct extension_property *extensions; |
Jon Ashburn | 14275da | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 94 | }; |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 95 | |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 96 | struct loader_scanned_layers { |
| 97 | char *name; |
| 98 | uint32_t extension_count; |
| 99 | struct extension_property *extensions; |
| 100 | }; |
Jon Ashburn | 349508d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 101 | // Note: Since the following is a static structure, all members are initialized |
| 102 | // to zero. |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 103 | static struct { |
Jon Ashburn | 349508d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 104 | struct loader_instance *instances; |
Jon Ashburn | 14275da | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 105 | bool icds_scanned; |
| 106 | struct loader_scanned_icds *scanned_icd_list; |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 107 | bool layer_scanned; |
Courtney Goeltzenleuchter | bce445a | 2014-12-01 09:29:42 -0700 | [diff] [blame] | 108 | char *layer_dirs; |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 109 | unsigned int scanned_layer_count; |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 110 | struct loader_scanned_layers scanned_layers[MAX_LAYER_LIBRARIES]; |
| 111 | size_t scanned_ext_list_capacity; |
| 112 | uint32_t scanned_ext_list_count; // coalesced from all layers/drivers |
| 113 | struct extension_property **scanned_ext_list; |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 114 | } loader; |
| 115 | |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 116 | static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(once_icd); |
| 117 | static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(once_layer); |
| 118 | static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(once_exts); |
Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 119 | |
Ian Elliott | 225188f | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 120 | #if defined(WIN32) |
Ian Elliott | 7600513 | 2015-03-31 15:32:41 -0600 | [diff] [blame] | 121 | char *loader_get_registry_string(const HKEY hive, |
| 122 | const LPCTSTR sub_key, |
| 123 | const char *value) |
| 124 | { |
| 125 | DWORD access_flags = KEY_QUERY_VALUE; |
| 126 | DWORD value_type; |
| 127 | HKEY key; |
Ian Elliott | 464711a | 2015-04-28 15:57:32 -0600 | [diff] [blame] | 128 | VkResult rtn_value; |
Ian Elliott | 7600513 | 2015-03-31 15:32:41 -0600 | [diff] [blame] | 129 | char *rtn_str = NULL; |
Tony Barbour | a938abb | 2015-04-22 11:36:22 -0600 | [diff] [blame] | 130 | DWORD rtn_len = 0; |
Ian Elliott | 7600513 | 2015-03-31 15:32:41 -0600 | [diff] [blame] | 131 | size_t allocated_len = 0; |
| 132 | |
| 133 | rtn_value = RegOpenKeyEx(hive, sub_key, 0, access_flags, &key); |
| 134 | if (rtn_value != ERROR_SUCCESS) { |
| 135 | // We didn't find the key. Try the 32-bit hive (where we've seen the |
| 136 | // key end up on some people's systems): |
| 137 | access_flags |= KEY_WOW64_32KEY; |
| 138 | rtn_value = RegOpenKeyEx(hive, sub_key, 0, access_flags, &key); |
| 139 | if (rtn_value != ERROR_SUCCESS) { |
| 140 | // We still couldn't find the key, so give up: |
| 141 | return NULL; |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | rtn_value = RegQueryValueEx(key, value, NULL, &value_type, |
Ian Elliott | 464711a | 2015-04-28 15:57:32 -0600 | [diff] [blame] | 146 | (PVOID) rtn_str, (LPDWORD) &rtn_len); |
Ian Elliott | 7600513 | 2015-03-31 15:32:41 -0600 | [diff] [blame] | 147 | if (rtn_value == ERROR_SUCCESS) { |
| 148 | // If we get to here, we found the key, and need to allocate memory |
| 149 | // large enough for rtn_str, and query again: |
| 150 | allocated_len = rtn_len + 4; |
| 151 | rtn_str = malloc(allocated_len); |
| 152 | rtn_value = RegQueryValueEx(key, value, NULL, &value_type, |
Ian Elliott | 464711a | 2015-04-28 15:57:32 -0600 | [diff] [blame] | 153 | (PVOID) rtn_str, (LPDWORD) &rtn_len); |
Ian Elliott | 7600513 | 2015-03-31 15:32:41 -0600 | [diff] [blame] | 154 | if (rtn_value == ERROR_SUCCESS) { |
| 155 | // We added 4 extra bytes to rtn_str, so that we can ensure that |
| 156 | // the string is NULL-terminated (albeit, in a brute-force manner): |
| 157 | rtn_str[allocated_len-1] = '\0'; |
| 158 | } else { |
| 159 | // This should never occur, but in case it does, clean up: |
| 160 | free(rtn_str); |
| 161 | rtn_str = NULL; |
| 162 | } |
| 163 | } // else - shouldn't happen, but if it does, return rtn_str, which is NULL |
| 164 | |
| 165 | // Close the registry key that was opened: |
| 166 | RegCloseKey(key); |
| 167 | |
| 168 | return rtn_str; |
| 169 | } |
| 170 | |
| 171 | |
Ian Elliott | 225188f | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 172 | // For ICD developers, look in the registry, and look for an environment |
| 173 | // variable for a path(s) where to find the ICD(s): |
| 174 | static char *loader_get_registry_and_env(const char *env_var, |
| 175 | const char *registry_value) |
| 176 | { |
| 177 | char *env_str = getenv(env_var); |
| 178 | size_t env_len = (env_str == NULL) ? 0 : strlen(env_str); |
Ian Elliott | 7600513 | 2015-03-31 15:32:41 -0600 | [diff] [blame] | 179 | char *registry_str = NULL; |
Tony Barbour | a938abb | 2015-04-22 11:36:22 -0600 | [diff] [blame] | 180 | size_t registry_len = 0; |
Ian Elliott | 225188f | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 181 | char *rtn_str = NULL; |
| 182 | size_t rtn_len; |
| 183 | |
Ian Elliott | 7600513 | 2015-03-31 15:32:41 -0600 | [diff] [blame] | 184 | registry_str = loader_get_registry_string(HKEY_LOCAL_MACHINE, |
Ian Elliott | 10ec962 | 2015-04-09 18:07:15 -0600 | [diff] [blame] | 185 | "Software\\Vulkan", |
Ian Elliott | 7600513 | 2015-03-31 15:32:41 -0600 | [diff] [blame] | 186 | registry_value); |
Ian Elliott | 464711a | 2015-04-28 15:57:32 -0600 | [diff] [blame] | 187 | registry_len = (registry_str) ? (DWORD) strlen(registry_str) : 0; |
Ian Elliott | 225188f | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 188 | |
| 189 | rtn_len = env_len + registry_len + 1; |
| 190 | if (rtn_len <= 2) { |
| 191 | // We found neither the desired registry value, nor the environment |
| 192 | // variable; return NULL: |
| 193 | return NULL; |
| 194 | } else { |
| 195 | // We found something, and so we need to allocate memory for the string |
| 196 | // to return: |
| 197 | rtn_str = malloc(rtn_len); |
| 198 | } |
| 199 | |
Ian Elliott | 7600513 | 2015-03-31 15:32:41 -0600 | [diff] [blame] | 200 | if (registry_len == 0) { |
Ian Elliott | 225188f | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 201 | // We didn't find the desired registry value, and so we must have found |
| 202 | // only the environment variable: |
| 203 | _snprintf(rtn_str, rtn_len, "%s", env_str); |
| 204 | } else if (env_str != NULL) { |
| 205 | // We found both the desired registry value and the environment |
| 206 | // variable, so concatenate them both: |
| 207 | _snprintf(rtn_str, rtn_len, "%s;%s", registry_str, env_str); |
| 208 | } else { |
| 209 | // We must have only found the desired registry value: |
| 210 | _snprintf(rtn_str, rtn_len, "%s", registry_str); |
| 211 | } |
| 212 | |
Ian Elliott | 7518ecd | 2015-04-03 13:13:01 -0600 | [diff] [blame] | 213 | if (registry_str) { |
| 214 | free(registry_str); |
| 215 | } |
Ian Elliott | 225188f | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 216 | |
| 217 | return(rtn_str); |
| 218 | } |
| 219 | #endif // WIN32 |
| 220 | |
| 221 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 222 | static void loader_log(VK_DBG_MSG_TYPE msg_type, int32_t msg_code, |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 223 | const char *format, ...) |
| 224 | { |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 225 | char msg[256]; |
| 226 | va_list ap; |
| 227 | int ret; |
| 228 | |
| 229 | va_start(ap, format); |
| 230 | ret = vsnprintf(msg, sizeof(msg), format, ap); |
Ian Elliott | 642f892 | 2015-02-13 14:29:21 -0700 | [diff] [blame] | 231 | if ((ret >= (int) sizeof(msg)) || ret < 0) { |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 232 | msg[sizeof(msg) - 1] = '\0'; |
| 233 | } |
| 234 | va_end(ap); |
| 235 | |
Jon Ashburn | b67859d | 2015-04-24 14:10:50 -0700 | [diff] [blame] | 236 | #if defined(WIN32) |
| 237 | OutputDebugString(msg); |
Jon Ashburn | 1da405d | 2015-05-05 16:20:46 -0600 | [diff] [blame] | 238 | #endif |
Courtney Goeltzenleuchter | 9d36ef4 | 2015-04-13 14:10:06 -0600 | [diff] [blame] | 239 | fputs(msg, stderr); |
| 240 | fputc('\n', stderr); |
Jon Ashburn | 1da405d | 2015-05-05 16:20:46 -0600 | [diff] [blame] | 241 | |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 242 | } |
| 243 | |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 244 | static bool has_extension(struct extension_property *exts, uint32_t count, |
| 245 | const char *name, bool must_be_hosted) |
| 246 | { |
| 247 | uint32_t i; |
| 248 | for (i = 0; i < count; i++) { |
| 249 | if (!strcmp(name, exts[i].extName) && (!must_be_hosted || exts[i].hosted)) |
| 250 | return true; |
| 251 | } |
| 252 | return false; |
| 253 | } |
| 254 | |
| 255 | static void get_global_extensions(PFN_vkGetGlobalExtensionInfo fp_get, |
| 256 | uint32_t *count_out, |
| 257 | struct extension_property **props_out) |
| 258 | { |
| 259 | uint32_t i, count, cur; |
| 260 | size_t siz = sizeof(count); |
| 261 | struct extension_property *ext_props; |
| 262 | VkExtensionProperties vk_prop; |
| 263 | VkResult res; |
| 264 | |
| 265 | *count_out = 0; |
| 266 | *props_out = NULL; |
| 267 | res = fp_get(VK_EXTENSION_INFO_TYPE_COUNT, 0, &siz, &count); |
| 268 | if (res != VK_SUCCESS) { |
| 269 | loader_log(VK_DBG_MSG_WARNING, 0, "Error getting global extension count from ICD"); |
| 270 | return; |
| 271 | } |
| 272 | ext_props = (struct extension_property *) malloc(sizeof(struct extension_property) * count); |
| 273 | if (ext_props == NULL) { |
| 274 | loader_log(VK_DBG_MSG_WARNING, 0, "Out of memory didn't get global extensions from ICD"); |
| 275 | return; |
| 276 | } |
| 277 | siz = sizeof(VkExtensionProperties); |
| 278 | cur = 0; |
| 279 | for (i = 0; i < count; i++) { |
| 280 | res = fp_get(VK_EXTENSION_INFO_TYPE_PROPERTIES, i, &siz, &vk_prop); |
| 281 | if (res == VK_SUCCESS) { |
| 282 | (ext_props + cur)->hosted = false; |
| 283 | (ext_props + cur)->version = vk_prop.version; |
| 284 | strncpy((ext_props + cur)->extName, vk_prop.extName, VK_MAX_EXTENSION_NAME); |
| 285 | (ext_props + cur)->extName[VK_MAX_EXTENSION_NAME - 1] = '\0'; |
| 286 | cur++; |
| 287 | } |
| 288 | *count_out = cur; |
| 289 | *props_out = ext_props; |
| 290 | } |
| 291 | return; |
| 292 | } |
| 293 | |
| 294 | static void loader_init_ext_list() |
| 295 | { |
| 296 | loader.scanned_ext_list_capacity = 256 * sizeof(struct extension_property *); |
| 297 | loader.scanned_ext_list = malloc(loader.scanned_ext_list_capacity); |
| 298 | memset(loader.scanned_ext_list, 0, loader.scanned_ext_list_capacity); |
| 299 | loader.scanned_ext_list_count = 0; |
| 300 | } |
| 301 | |
| 302 | #if 0 // currently no place to call this |
| 303 | static void loader_destroy_ext_list() |
| 304 | { |
| 305 | free(loader.scanned_ext_list); |
| 306 | loader.scanned_ext_list_capacity = 0; |
| 307 | loader.scanned_ext_list_count = 0; |
| 308 | } |
| 309 | #endif |
| 310 | |
| 311 | static void loader_add_to_ext_list(uint32_t count, |
Jon Ashburn | 4d3b752 | 2015-04-14 14:14:48 -0600 | [diff] [blame] | 312 | struct extension_property *prop_list, |
| 313 | bool is_layer_ext) |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 314 | { |
| 315 | uint32_t i, j; |
| 316 | bool duplicate; |
| 317 | struct extension_property *cur_ext; |
| 318 | |
| 319 | if (loader.scanned_ext_list == NULL || loader.scanned_ext_list_capacity == 0) |
| 320 | loader_init_ext_list(); |
| 321 | |
| 322 | if (loader.scanned_ext_list == NULL) |
| 323 | return; |
| 324 | |
| 325 | struct extension_property *ext_list, **ext_list_addr; |
| 326 | |
| 327 | for (i = 0; i < count; i++) { |
| 328 | cur_ext = prop_list + i; |
| 329 | |
| 330 | // look for duplicates or not |
| 331 | duplicate = false; |
| 332 | for (j = 0; j < loader.scanned_ext_list_count; j++) { |
| 333 | ext_list = loader.scanned_ext_list[j]; |
| 334 | if (!strcmp(cur_ext->extName, ext_list->extName)) { |
| 335 | duplicate = true; |
| 336 | ext_list->hosted = false; |
| 337 | break; |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | // add to list at end |
| 342 | if (!duplicate) { |
| 343 | // check for enough capacity |
| 344 | if (loader.scanned_ext_list_count * sizeof(struct extension_property *) |
| 345 | >= loader.scanned_ext_list_capacity) { |
| 346 | // double capacity |
| 347 | loader.scanned_ext_list_capacity *= 2; |
| 348 | loader.scanned_ext_list = realloc(loader.scanned_ext_list, |
| 349 | loader.scanned_ext_list_capacity); |
| 350 | } |
| 351 | ext_list_addr = &(loader.scanned_ext_list[loader.scanned_ext_list_count++]); |
| 352 | *ext_list_addr = cur_ext; |
| 353 | cur_ext->hosted = true; |
| 354 | } |
| 355 | |
| 356 | } |
| 357 | } |
| 358 | |
Jon Ashburn | 42e4103 | 2015-04-14 09:15:32 -0600 | [diff] [blame] | 359 | static bool loader_is_extension_scanned(const char *name) |
| 360 | { |
| 361 | uint32_t i; |
| 362 | |
| 363 | for (i = 0; i < loader.scanned_ext_list_count; i++) { |
| 364 | if (!strcmp(name, loader.scanned_ext_list[i]->extName)) |
| 365 | return true; |
| 366 | } |
| 367 | return false; |
| 368 | } |
| 369 | |
Tony Barbour | a938abb | 2015-04-22 11:36:22 -0600 | [diff] [blame] | 370 | static void loader_coalesce_extensions(void) |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 371 | { |
| 372 | uint32_t i; |
| 373 | struct loader_scanned_icds *icd_list = loader.scanned_icd_list; |
| 374 | |
| 375 | // traverse scanned icd list adding non-duplicate extensions to the list |
| 376 | while (icd_list != NULL) { |
Jon Ashburn | 4d3b752 | 2015-04-14 14:14:48 -0600 | [diff] [blame] | 377 | loader_add_to_ext_list(icd_list->extension_count, icd_list->extensions, false); |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 378 | icd_list = icd_list->next; |
| 379 | }; |
| 380 | |
| 381 | //Traverse layers list adding non-duplicate extensions to the list |
| 382 | for (i = 0; i < loader.scanned_layer_count; i++) { |
| 383 | loader_add_to_ext_list(loader.scanned_layers[i].extension_count, |
Jon Ashburn | 4d3b752 | 2015-04-14 14:14:48 -0600 | [diff] [blame] | 384 | loader.scanned_layers[i].extensions, true); |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 385 | } |
| 386 | } |
| 387 | |
| 388 | static void loader_icd_destroy(struct loader_icd *icd) |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 389 | { |
Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 390 | loader_platform_close_library(icd->scanned_icds->handle); |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 391 | free(icd); |
| 392 | } |
| 393 | |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 394 | static struct loader_icd * loader_icd_create(const struct loader_scanned_icds *scanned) |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 395 | { |
| 396 | struct loader_icd *icd; |
| 397 | |
| 398 | icd = malloc(sizeof(*icd)); |
| 399 | if (!icd) |
| 400 | return NULL; |
| 401 | |
Courtney Goeltzenleuchter | 6f92816 | 2014-10-28 10:29:27 -0600 | [diff] [blame] | 402 | memset(icd, 0, sizeof(*icd)); |
| 403 | |
Jon Ashburn | 14275da | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 404 | icd->scanned_icds = scanned; |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 405 | |
| 406 | return icd; |
| 407 | } |
| 408 | |
Jon Ashburn | 3336df8 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 409 | static struct loader_icd *loader_icd_add(struct loader_instance *ptr_inst, |
| 410 | const struct loader_scanned_icds *scanned) |
Chia-I Wu | 894a117 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 411 | { |
| 412 | struct loader_icd *icd; |
| 413 | |
Jon Ashburn | 14275da | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 414 | icd = loader_icd_create(scanned); |
Chia-I Wu | 894a117 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 415 | if (!icd) |
| 416 | return NULL; |
| 417 | |
Chia-I Wu | 894a117 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 418 | /* prepend to the list */ |
Jon Ashburn | 3336df8 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 419 | icd->next = ptr_inst->icds; |
| 420 | ptr_inst->icds = icd; |
Chia-I Wu | 894a117 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 421 | |
| 422 | return icd; |
| 423 | } |
| 424 | |
Jon Ashburn | 14275da | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 425 | static void loader_scanned_icd_add(const char *filename) |
| 426 | { |
Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 427 | loader_platform_dl_handle handle; |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 428 | void *fp_gpa, *fp_enumerate, *fp_create_inst, *fp_destroy_inst; |
| 429 | void *fp_get_global_ext_info; |
Jon Ashburn | 14275da | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 430 | struct loader_scanned_icds *new_node; |
| 431 | |
Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 432 | // Used to call: dlopen(filename, RTLD_LAZY); |
| 433 | handle = loader_platform_open_library(filename); |
Jon Ashburn | 14275da | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 434 | if (!handle) { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 435 | loader_log(VK_DBG_MSG_WARNING, 0, loader_platform_open_library_error(filename)); |
Jon Ashburn | 14275da | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 436 | return; |
| 437 | } |
| 438 | |
| 439 | #define LOOKUP(func_ptr, func) do { \ |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 440 | func_ptr = (PFN_vk ##func) loader_platform_get_proc_address(handle, "vk" #func); \ |
Jon Ashburn | 14275da | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 441 | if (!func_ptr) { \ |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 442 | loader_log(VK_DBG_MSG_WARNING, 0, loader_platform_get_proc_address_error("vk" #func)); \ |
Jon Ashburn | 14275da | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 443 | return; \ |
| 444 | } \ |
| 445 | } while (0) |
| 446 | |
| 447 | LOOKUP(fp_gpa, GetProcAddr); |
Jon Ashburn | 3336df8 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 448 | LOOKUP(fp_create_inst, CreateInstance); |
| 449 | LOOKUP(fp_destroy_inst, DestroyInstance); |
Jon Ashburn | 07b309a | 2015-04-15 11:31:12 -0600 | [diff] [blame] | 450 | LOOKUP(fp_enumerate, EnumeratePhysicalDevices); |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 451 | LOOKUP(fp_get_global_ext_info, GetGlobalExtensionInfo); |
Jon Ashburn | 14275da | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 452 | #undef LOOKUP |
| 453 | |
| 454 | new_node = (struct loader_scanned_icds *) malloc(sizeof(struct loader_scanned_icds)); |
| 455 | if (!new_node) { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 456 | loader_log(VK_DBG_MSG_WARNING, 0, "Out of memory can't add icd"); |
Jon Ashburn | 14275da | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 457 | return; |
| 458 | } |
| 459 | |
| 460 | new_node->handle = handle; |
| 461 | new_node->GetProcAddr = fp_gpa; |
Jon Ashburn | 3336df8 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 462 | new_node->CreateInstance = fp_create_inst; |
| 463 | new_node->DestroyInstance = fp_destroy_inst; |
Jon Ashburn | 07b309a | 2015-04-15 11:31:12 -0600 | [diff] [blame] | 464 | new_node->EnumeratePhysicalDevices = fp_enumerate; |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 465 | new_node->GetGlobalExtensionInfo = fp_get_global_ext_info; |
| 466 | new_node->extension_count = 0; |
| 467 | new_node->extensions = NULL; |
Jon Ashburn | 14275da | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 468 | new_node->next = loader.scanned_icd_list; |
Jon Ashburn | 14275da | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 469 | |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 470 | loader.scanned_icd_list = new_node; |
| 471 | |
| 472 | if (fp_get_global_ext_info) { |
| 473 | get_global_extensions((PFN_vkGetGlobalExtensionInfo) fp_get_global_ext_info, |
| 474 | &new_node->extension_count, |
| 475 | &new_node->extensions); |
| 476 | } else { |
| 477 | loader_log(VK_DBG_MSG_WARNING, 0, "Couldn't get global extensions from ICD"); |
| 478 | } |
| 479 | } |
Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 480 | |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 481 | /** |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 482 | * Try to \c loader_icd_scan VK driver(s). |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 483 | * |
| 484 | * This function scans the default system path or path |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 485 | * specified by the \c LIBVK_DRIVERS_PATH environment variable in |
| 486 | * order to find loadable VK ICDs with the name of libVK_*. |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 487 | * |
| 488 | * \returns |
| 489 | * void; but side effect is to set loader_icd_scanned to true |
| 490 | */ |
| 491 | static void loader_icd_scan(void) |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 492 | { |
Ian Elliott | 225188f | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 493 | const char *p, *next; |
| 494 | char *libPaths = NULL; |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 495 | DIR *sysdir; |
| 496 | struct dirent *dent; |
| 497 | char icd_library[1024]; |
Jon Ashburn | 0f45b2a | 2014-10-03 16:31:35 -0600 | [diff] [blame] | 498 | char path[1024]; |
Ian Elliott | 64f74a8 | 2015-02-04 12:06:46 -0700 | [diff] [blame] | 499 | uint32_t len; |
Ian Elliott | 225188f | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 500 | #if defined(WIN32) |
| 501 | bool must_free_libPaths; |
| 502 | libPaths = loader_get_registry_and_env(DRIVER_PATH_ENV, |
| 503 | DRIVER_PATH_REGISTRY_VALUE); |
| 504 | if (libPaths != NULL) { |
| 505 | must_free_libPaths = true; |
| 506 | } else { |
| 507 | must_free_libPaths = false; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 508 | libPaths = DEFAULT_VK_DRIVERS_PATH; |
Ian Elliott | 225188f | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 509 | } |
| 510 | #else // WIN32 |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 511 | if (geteuid() == getuid()) { |
Ian Elliott | 225188f | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 512 | /* Don't allow setuid apps to use the DRIVER_PATH_ENV env var: */ |
| 513 | libPaths = getenv(DRIVER_PATH_ENV); |
| 514 | } |
| 515 | if (libPaths == NULL) { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 516 | libPaths = DEFAULT_VK_DRIVERS_PATH; |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 517 | } |
Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 518 | #endif // WIN32 |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 519 | |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 520 | for (p = libPaths; *p; p = next) { |
Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 521 | next = strchr(p, PATH_SEPERATOR); |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 522 | if (next == NULL) { |
Ian Elliott | 64f74a8 | 2015-02-04 12:06:46 -0700 | [diff] [blame] | 523 | len = (uint32_t) strlen(p); |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 524 | next = p + len; |
| 525 | } |
| 526 | else { |
Ian Elliott | 64f74a8 | 2015-02-04 12:06:46 -0700 | [diff] [blame] | 527 | len = (uint32_t) (next - p); |
Jon Ashburn | 0f45b2a | 2014-10-03 16:31:35 -0600 | [diff] [blame] | 528 | sprintf(path, "%.*s", (len > sizeof(path) - 1) ? (int) sizeof(path) - 1 : len, p); |
| 529 | p = path; |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 530 | next++; |
| 531 | } |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 532 | |
Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 533 | // TODO/TBD: Do we want to do this on Windows, or just let Windows take |
| 534 | // care of its own search path (which it apparently has)? |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 535 | sysdir = opendir(p); |
| 536 | if (sysdir) { |
| 537 | dent = readdir(sysdir); |
| 538 | while (dent) { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 539 | /* Look for ICDs starting with VK_DRIVER_LIBRARY_PREFIX and |
| 540 | * ending with VK_LIBRARY_SUFFIX |
Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 541 | */ |
| 542 | if (!strncmp(dent->d_name, |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 543 | VK_DRIVER_LIBRARY_PREFIX, |
| 544 | VK_DRIVER_LIBRARY_PREFIX_LEN)) { |
Ian Elliott | 64f74a8 | 2015-02-04 12:06:46 -0700 | [diff] [blame] | 545 | uint32_t nlen = (uint32_t) strlen(dent->d_name); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 546 | const char *suf = dent->d_name + nlen - VK_LIBRARY_SUFFIX_LEN; |
| 547 | if ((nlen > VK_LIBRARY_SUFFIX_LEN) && |
Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 548 | !strncmp(suf, |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 549 | VK_LIBRARY_SUFFIX, |
| 550 | VK_LIBRARY_SUFFIX_LEN)) { |
Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 551 | snprintf(icd_library, 1024, "%s" DIRECTORY_SYMBOL "%s", p,dent->d_name); |
| 552 | loader_scanned_icd_add(icd_library); |
| 553 | } |
| 554 | } |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 555 | |
| 556 | dent = readdir(sysdir); |
| 557 | } |
| 558 | closedir(sysdir); |
| 559 | } |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 560 | } |
| 561 | |
Ian Elliott | 225188f | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 562 | #if defined(WIN32) |
| 563 | // Free any allocated memory: |
| 564 | if (must_free_libPaths) { |
| 565 | free(libPaths); |
| 566 | } |
| 567 | #endif // WIN32 |
| 568 | |
| 569 | // Note that we've scanned for ICDs: |
Jon Ashburn | 14275da | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 570 | loader.icds_scanned = true; |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 571 | } |
| 572 | |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 573 | |
Ian Elliott | 225188f | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 574 | static void layer_lib_scan(void) |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 575 | { |
| 576 | const char *p, *next; |
Ian Elliott | 225188f | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 577 | char *libPaths = NULL; |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 578 | DIR *curdir; |
| 579 | struct dirent *dent; |
Ian Elliott | 225188f | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 580 | size_t len, i; |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 581 | char temp_str[1024]; |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 582 | uint32_t count; |
| 583 | PFN_vkGetGlobalExtensionInfo fp_get_ext; |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 584 | |
Ian Elliott | 225188f | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 585 | #if defined(WIN32) |
| 586 | bool must_free_libPaths; |
| 587 | libPaths = loader_get_registry_and_env(LAYERS_PATH_ENV, |
| 588 | LAYERS_PATH_REGISTRY_VALUE); |
| 589 | if (libPaths != NULL) { |
| 590 | must_free_libPaths = true; |
| 591 | } else { |
| 592 | must_free_libPaths = false; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 593 | libPaths = DEFAULT_VK_LAYERS_PATH; |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 594 | } |
Ian Elliott | 225188f | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 595 | #else // WIN32 |
| 596 | if (geteuid() == getuid()) { |
| 597 | /* Don't allow setuid apps to use the DRIVER_PATH_ENV env var: */ |
Courtney Goeltzenleuchter | 4ee0171 | 2015-02-18 20:03:02 -0700 | [diff] [blame] | 598 | libPaths = getenv(LAYERS_PATH_ENV); |
Ian Elliott | 225188f | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 599 | } |
| 600 | if (libPaths == NULL) { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 601 | libPaths = DEFAULT_VK_LAYERS_PATH; |
Ian Elliott | 225188f | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 602 | } |
Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 603 | #endif // WIN32 |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 604 | |
Ian Elliott | 225188f | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 605 | if (libPaths == NULL) { |
| 606 | // Have no paths to search: |
Courtney Goeltzenleuchter | bce445a | 2014-12-01 09:29:42 -0700 | [diff] [blame] | 607 | return; |
| 608 | } |
Ian Elliott | 225188f | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 609 | len = strlen(libPaths); |
Courtney Goeltzenleuchter | bce445a | 2014-12-01 09:29:42 -0700 | [diff] [blame] | 610 | loader.layer_dirs = malloc(len+1); |
Ian Elliott | 225188f | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 611 | if (loader.layer_dirs == NULL) { |
| 612 | free(libPaths); |
Courtney Goeltzenleuchter | 688c74b | 2014-12-02 18:12:51 -0700 | [diff] [blame] | 613 | return; |
Ian Elliott | 225188f | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 614 | } |
| 615 | // Alloc passed, so we know there is enough space to hold the string, don't |
| 616 | // need strncpy |
| 617 | strcpy(loader.layer_dirs, libPaths); |
| 618 | #if defined(WIN32) |
| 619 | // Free any allocated memory: |
| 620 | if (must_free_libPaths) { |
| 621 | free(libPaths); |
| 622 | must_free_libPaths = false; |
| 623 | } |
| 624 | #endif // WIN32 |
Courtney Goeltzenleuchter | bce445a | 2014-12-01 09:29:42 -0700 | [diff] [blame] | 625 | libPaths = loader.layer_dirs; |
| 626 | |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 627 | /* cleanup any previously scanned libraries */ |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 628 | for (i = 0; i < loader.scanned_layer_count; i++) { |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 629 | if (loader.scanned_layers[i].name != NULL) |
| 630 | free(loader.scanned_layers[i].name); |
| 631 | if (loader.scanned_layers[i].extensions != NULL) |
| 632 | free(loader.scanned_layers[i].extensions); |
| 633 | loader.scanned_layers[i].name = NULL; |
| 634 | loader.scanned_layers[i].extensions = NULL; |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 635 | } |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 636 | loader.scanned_layer_count = 0; |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 637 | count = 0; |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 638 | |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 639 | for (p = libPaths; *p; p = next) { |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 640 | next = strchr(p, PATH_SEPERATOR); |
| 641 | if (next == NULL) { |
| 642 | len = (uint32_t) strlen(p); |
| 643 | next = p + len; |
| 644 | } |
| 645 | else { |
| 646 | len = (uint32_t) (next - p); |
| 647 | *(char *) next = '\0'; |
| 648 | next++; |
| 649 | } |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 650 | |
| 651 | curdir = opendir(p); |
| 652 | if (curdir) { |
| 653 | dent = readdir(curdir); |
| 654 | while (dent) { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 655 | /* Look for layers starting with VK_LAYER_LIBRARY_PREFIX and |
| 656 | * ending with VK_LIBRARY_SUFFIX |
Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 657 | */ |
| 658 | if (!strncmp(dent->d_name, |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 659 | VK_LAYER_LIBRARY_PREFIX, |
| 660 | VK_LAYER_LIBRARY_PREFIX_LEN)) { |
Ian Elliott | 64f74a8 | 2015-02-04 12:06:46 -0700 | [diff] [blame] | 661 | uint32_t nlen = (uint32_t) strlen(dent->d_name); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 662 | const char *suf = dent->d_name + nlen - VK_LIBRARY_SUFFIX_LEN; |
| 663 | if ((nlen > VK_LIBRARY_SUFFIX_LEN) && |
Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 664 | !strncmp(suf, |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 665 | VK_LIBRARY_SUFFIX, |
| 666 | VK_LIBRARY_SUFFIX_LEN)) { |
Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 667 | loader_platform_dl_handle handle; |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 668 | snprintf(temp_str, sizeof(temp_str), |
| 669 | "%s" DIRECTORY_SYMBOL "%s",p,dent->d_name); |
Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 670 | // Used to call: dlopen(temp_str, RTLD_LAZY) |
| 671 | if ((handle = loader_platform_open_library(temp_str)) == NULL) { |
| 672 | dent = readdir(curdir); |
| 673 | continue; |
| 674 | } |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 675 | if (count == MAX_LAYER_LIBRARIES) { |
| 676 | loader_log(VK_DBG_MSG_ERROR, 0, |
| 677 | "%s ignored: max layer libraries exceed", |
| 678 | temp_str); |
Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 679 | break; |
| 680 | } |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 681 | fp_get_ext = loader_platform_get_proc_address(handle, |
| 682 | "vkGetGlobalExtensionInfo"); |
| 683 | |
| 684 | if (!fp_get_ext) { |
| 685 | loader_log(VK_DBG_MSG_WARNING, 0, |
| 686 | "Couldn't dlsym vkGetGlobalExtensionInfo from library %s", |
| 687 | temp_str); |
| 688 | dent = readdir(curdir); |
| 689 | loader_platform_close_library(handle); |
| 690 | continue; |
| 691 | } |
| 692 | |
| 693 | loader.scanned_layers[count].name = |
| 694 | malloc(strlen(temp_str) + 1); |
| 695 | if (loader.scanned_layers[count].name == NULL) { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 696 | loader_log(VK_DBG_MSG_ERROR, 0, "%s ignored: out of memory", temp_str); |
Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 697 | break; |
| 698 | } |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 699 | |
| 700 | get_global_extensions(fp_get_ext, |
| 701 | &loader.scanned_layers[count].extension_count, |
| 702 | &loader.scanned_layers[count].extensions); |
| 703 | |
| 704 | |
| 705 | strcpy(loader.scanned_layers[count].name, temp_str); |
| 706 | count++; |
| 707 | loader_platform_close_library(handle); |
Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 708 | } |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 709 | } |
| 710 | |
| 711 | dent = readdir(curdir); |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 712 | } // while (dir_entry) |
| 713 | if (count == MAX_LAYER_LIBRARIES) |
| 714 | break; |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 715 | closedir(curdir); |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 716 | } // if (curdir)) |
| 717 | } // for (libpaths) |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 718 | |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 719 | loader.scanned_layer_count = count; |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 720 | loader.layer_scanned = true; |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 721 | } |
| 722 | |
Chia-I Wu | 7225996 | 2015-04-17 10:49:15 +0800 | [diff] [blame] | 723 | static void * VKAPI loader_gpa_internal(VkPhysicalDevice gpu, const char * pName) |
Jon Ashburn | e18431b | 2015-04-13 18:10:06 -0600 | [diff] [blame] | 724 | { |
Mike Stroyan | 230e625 | 2015-04-17 12:36:38 -0600 | [diff] [blame] | 725 | if (gpu == VK_NULL_HANDLE) { |
Jon Ashburn | e18431b | 2015-04-13 18:10:06 -0600 | [diff] [blame] | 726 | return NULL;; |
| 727 | } |
| 728 | VkBaseLayerObject* gpuw = (VkBaseLayerObject *) gpu; |
| 729 | VkLayerDispatchTable * disp_table = * (VkLayerDispatchTable **) gpuw->baseObject; |
| 730 | void *addr; |
| 731 | |
| 732 | if (disp_table == NULL) |
| 733 | return NULL; |
| 734 | |
| 735 | addr = loader_lookup_dispatch_table(disp_table, pName); |
| 736 | if (addr) |
| 737 | return addr; |
| 738 | else { |
| 739 | if (disp_table->GetProcAddr == NULL) |
| 740 | return NULL; |
Jon Ashburn | 5468156 | 2015-04-24 17:15:00 -0700 | [diff] [blame] | 741 | if (gpuw->baseObject == gpuw->nextObject) |
| 742 | return gpuw->pGPA(gpuw->baseObject, pName); |
Jon Ashburn | e18431b | 2015-04-13 18:10:06 -0600 | [diff] [blame] | 743 | return disp_table->GetProcAddr(gpuw->nextObject, pName); |
| 744 | } |
| 745 | } |
| 746 | |
Jon Ashburn | da7c20d | 2015-05-01 18:00:33 -0600 | [diff] [blame] | 747 | struct loader_icd * loader_get_icd(const VkBaseLayerObject *gpu, uint32_t *gpu_index) |
Jon Ashburn | b55278a | 2014-10-17 15:09:07 -0600 | [diff] [blame] | 748 | { |
Jon Ashburn | 630e44f | 2015-04-08 21:33:34 -0600 | [diff] [blame] | 749 | /* |
| 750 | * NOTE: at this time icd->gpus is pointing to wrapped GPUs, but no where else |
| 751 | * are wrapped gpus used. Should go away. The incoming gpu is NOT wrapped so |
| 752 | * need to test it against the wrapped GPU's base object. |
| 753 | */ |
Jon Ashburn | dc67ef5 | 2015-01-29 16:44:24 -0700 | [diff] [blame] | 754 | for (struct loader_instance *inst = loader.instances; inst; inst = inst->next) { |
| 755 | for (struct loader_icd *icd = inst->icds; icd; icd = icd->next) { |
| 756 | for (uint32_t i = 0; i < icd->gpu_count; i++) |
Mike Stroyan | 230e625 | 2015-04-17 12:36:38 -0600 | [diff] [blame] | 757 | if ((icd->gpus + i) == gpu || (void*)(icd->gpus +i)->baseObject == gpu) { |
Jon Ashburn | dc67ef5 | 2015-01-29 16:44:24 -0700 | [diff] [blame] | 758 | *gpu_index = i; |
| 759 | return icd; |
| 760 | } |
| 761 | } |
Jon Ashburn | b55278a | 2014-10-17 15:09:07 -0600 | [diff] [blame] | 762 | } |
| 763 | return NULL; |
| 764 | } |
| 765 | |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 766 | static bool loader_layers_activated(const struct loader_icd *icd, const uint32_t gpu_index) |
Jon Ashburn | b55278a | 2014-10-17 15:09:07 -0600 | [diff] [blame] | 767 | { |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 768 | if (icd->layer_count[gpu_index]) |
| 769 | return true; |
| 770 | else |
| 771 | return false; |
Jon Ashburn | b55278a | 2014-10-17 15:09:07 -0600 | [diff] [blame] | 772 | } |
| 773 | |
Jon Ashburn | 4d3b752 | 2015-04-14 14:14:48 -0600 | [diff] [blame] | 774 | static void loader_init_layer_libs(struct loader_icd *icd, uint32_t gpu_index, |
| 775 | struct layer_name_pair * pLayerNames, |
| 776 | uint32_t count) |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 777 | { |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 778 | if (!icd) |
| 779 | return; |
Jon Ashburn | 815bddd | 2014-10-16 15:48:50 -0600 | [diff] [blame] | 780 | |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 781 | struct loader_layers *obj; |
| 782 | bool foundLib; |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 783 | for (uint32_t i = 0; i < count; i++) { |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 784 | foundLib = false; |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 785 | for (uint32_t j = 0; j < icd->layer_count[gpu_index]; j++) { |
Jon Ashburn | 4d3b752 | 2015-04-14 14:14:48 -0600 | [diff] [blame] | 786 | if (icd->layer_libs[gpu_index][j].lib_handle && |
| 787 | !strcmp(icd->layer_libs[gpu_index][j].name, |
| 788 | (char *) pLayerNames[i].layer_name) && |
| 789 | strcmp("Validation", (char *) pLayerNames[i].layer_name)) { |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 790 | foundLib = true; |
| 791 | break; |
| 792 | } |
| 793 | } |
| 794 | if (!foundLib) { |
| 795 | obj = &(icd->layer_libs[gpu_index][i]); |
Jon Ashburn | ead95c5 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 796 | strncpy(obj->name, (char *) pLayerNames[i].layer_name, sizeof(obj->name) - 1); |
| 797 | obj->name[sizeof(obj->name) - 1] = '\0'; |
Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 798 | // Used to call: dlopen(pLayerNames[i].lib_name, RTLD_LAZY | RTLD_DEEPBIND) |
| 799 | if ((obj->lib_handle = loader_platform_open_library(pLayerNames[i].lib_name)) == NULL) { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 800 | loader_log(VK_DBG_MSG_ERROR, 0, loader_platform_open_library_error(pLayerNames[i].lib_name)); |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 801 | continue; |
| 802 | } else { |
Jon Ashburn | 4d3b752 | 2015-04-14 14:14:48 -0600 | [diff] [blame] | 803 | loader_log(VK_DBG_MSG_UNKNOWN, 0, "Inserting layer %s from library %s", |
| 804 | pLayerNames[i].layer_name, pLayerNames[i].lib_name); |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 805 | } |
Jon Ashburn | ead95c5 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 806 | free(pLayerNames[i].layer_name); |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 807 | icd->layer_count[gpu_index]++; |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 808 | } |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 809 | } |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 810 | } |
| 811 | |
Jon Ashburn | 4d3b752 | 2015-04-14 14:14:48 -0600 | [diff] [blame] | 812 | static bool find_layer_extension(struct loader_icd *icd, uint32_t gpu_index, |
| 813 | const char *pExtName, uint32_t *out_count, |
| 814 | char *lib_name[MAX_LAYER_LIBRARIES]) |
Jon Ashburn | ead95c5 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 815 | { |
Courtney Goeltzenleuchter | 0199e95 | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 816 | char *search_name; |
Jon Ashburn | 4d3b752 | 2015-04-14 14:14:48 -0600 | [diff] [blame] | 817 | uint32_t j, found_count = 0; |
| 818 | bool must_be_hosted; |
| 819 | bool found = false; |
Jon Ashburn | ead95c5 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 820 | |
Courtney Goeltzenleuchter | 0199e95 | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 821 | /* |
| 822 | * The loader provides the abstraction that make layers and extensions work via |
| 823 | * the currently defined extension mechanism. That is, when app queries for an extension |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 824 | * via vkGetGlobalExtensionInfo, the loader will call both the driver as well as any layers |
Courtney Goeltzenleuchter | 0199e95 | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 825 | * to see who implements that extension. Then, if the app enables the extension during |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 826 | * vkCreateInstance the loader will find and load any layers that implement that extension. |
Courtney Goeltzenleuchter | 0199e95 | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 827 | */ |
Jon Ashburn | ead95c5 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 828 | |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 829 | // TODO: what about GetPhysicalDeviceExtension for device specific layers/extensions |
Courtney Goeltzenleuchter | 0199e95 | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 830 | |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 831 | for (j = 0; j < loader.scanned_layer_count; j++) { |
Jon Ashburn | 4d3b752 | 2015-04-14 14:14:48 -0600 | [diff] [blame] | 832 | |
| 833 | if (!strcmp("Validation", pExtName)) |
| 834 | must_be_hosted = false; |
| 835 | else |
| 836 | must_be_hosted = true; |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 837 | if (has_extension(loader.scanned_layers[j].extensions, |
| 838 | loader.scanned_layers[j].extension_count, pExtName, |
Jon Ashburn | 4d3b752 | 2015-04-14 14:14:48 -0600 | [diff] [blame] | 839 | must_be_hosted)) { |
Jon Ashburn | ead95c5 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 840 | |
Jon Ashburn | 4d3b752 | 2015-04-14 14:14:48 -0600 | [diff] [blame] | 841 | found = true; |
| 842 | lib_name[found_count] = loader.scanned_layers[j].name; |
| 843 | found_count++; |
| 844 | } else { |
| 845 | // Extension not found in list for the layer, so test the layer name |
| 846 | // as if it is an extension name. Use default layer name based on |
| 847 | // library name VK_LAYER_LIBRARY_PREFIX<name>.VK_LIBRARY_SUFFIX |
| 848 | char *pEnd; |
| 849 | size_t siz; |
Courtney Goeltzenleuchter | 0199e95 | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 850 | |
Jon Ashburn | 4d3b752 | 2015-04-14 14:14:48 -0600 | [diff] [blame] | 851 | search_name = loader.scanned_layers[j].name; |
| 852 | search_name = basename(search_name); |
| 853 | search_name += strlen(VK_LAYER_LIBRARY_PREFIX); |
| 854 | pEnd = strrchr(search_name, '.'); |
| 855 | siz = (int) (pEnd - search_name); |
| 856 | if (siz != strlen(pExtName)) |
| 857 | continue; |
Courtney Goeltzenleuchter | 0199e95 | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 858 | |
Jon Ashburn | 4d3b752 | 2015-04-14 14:14:48 -0600 | [diff] [blame] | 859 | if (strncmp(search_name, pExtName, siz) == 0) { |
| 860 | found = true; |
| 861 | lib_name[found_count] = loader.scanned_layers[j].name; |
| 862 | found_count++; |
| 863 | } |
Courtney Goeltzenleuchter | 0199e95 | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 864 | } |
| 865 | } |
Jon Ashburn | 4d3b752 | 2015-04-14 14:14:48 -0600 | [diff] [blame] | 866 | |
| 867 | *out_count = found_count; |
| 868 | return found; |
Jon Ashburn | ead95c5 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 869 | } |
| 870 | |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 871 | static uint32_t loader_get_layer_env(struct loader_icd *icd, uint32_t gpu_index, struct layer_name_pair *pLayerNames) |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 872 | { |
Ian Elliott | 225188f | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 873 | char *layerEnv; |
Jon Ashburn | 4d3b752 | 2015-04-14 14:14:48 -0600 | [diff] [blame] | 874 | uint32_t i, len, found_count, count = 0; |
Jon Ashburn | b4d0053 | 2014-10-22 21:15:26 -0600 | [diff] [blame] | 875 | char *p, *pOrig, *next, *name; |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 876 | |
Ian Elliott | 225188f | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 877 | #if defined(WIN32) |
| 878 | layerEnv = loader_get_registry_and_env(LAYER_NAMES_ENV, |
| 879 | LAYER_NAMES_REGISTRY_VALUE); |
| 880 | #else // WIN32 |
| 881 | layerEnv = getenv(LAYER_NAMES_ENV); |
| 882 | #endif // WIN32 |
| 883 | if (layerEnv == NULL) { |
Jon Ashburn | 4fbcb03 | 2014-10-23 10:29:09 -0600 | [diff] [blame] | 884 | return 0; |
Ian Elliott | 225188f | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 885 | } |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 886 | p = malloc(strlen(layerEnv) + 1); |
Ian Elliott | 225188f | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 887 | if (p == NULL) { |
| 888 | #if defined(WIN32) |
| 889 | free(layerEnv); |
| 890 | #endif // WIN32 |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 891 | return 0; |
Ian Elliott | 225188f | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 892 | } |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 893 | strcpy(p, layerEnv); |
Ian Elliott | 225188f | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 894 | #if defined(WIN32) |
| 895 | free(layerEnv); |
| 896 | #endif // WIN32 |
Jon Ashburn | b4d0053 | 2014-10-22 21:15:26 -0600 | [diff] [blame] | 897 | pOrig = p; |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 898 | |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 899 | while (p && *p && count < MAX_LAYER_LIBRARIES) { |
Jon Ashburn | 4d3b752 | 2015-04-14 14:14:48 -0600 | [diff] [blame] | 900 | char *lib_name[MAX_LAYER_LIBRARIES]; |
| 901 | //memset(&lib_name[0], 0, sizeof(const char *) * MAX_LAYER_LIBRARIES); |
Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 902 | next = strchr(p, PATH_SEPERATOR); |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 903 | if (next == NULL) { |
Ian Elliott | 64f74a8 | 2015-02-04 12:06:46 -0700 | [diff] [blame] | 904 | len = (uint32_t) strlen(p); |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 905 | next = p + len; |
Courtney Goeltzenleuchter | 0199e95 | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 906 | } else { |
Ian Elliott | 64f74a8 | 2015-02-04 12:06:46 -0700 | [diff] [blame] | 907 | len = (uint32_t) (next - p); |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 908 | *(char *) next = '\0'; |
| 909 | next++; |
| 910 | } |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 911 | name = basename(p); |
Jon Ashburn | 4d3b752 | 2015-04-14 14:14:48 -0600 | [diff] [blame] | 912 | if (!find_layer_extension(icd, gpu_index, name, &found_count, lib_name)) { |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 913 | p = next; |
| 914 | continue; |
| 915 | } |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 916 | |
Jon Ashburn | 4d3b752 | 2015-04-14 14:14:48 -0600 | [diff] [blame] | 917 | for (i = 0; i < found_count; i++) { |
| 918 | len = (uint32_t) strlen(name); |
| 919 | pLayerNames[count].layer_name = malloc(len + 1); |
| 920 | if (!pLayerNames[count].layer_name) { |
| 921 | free(pOrig); |
| 922 | return count; |
| 923 | } |
| 924 | strncpy((char *) pLayerNames[count].layer_name, name, len); |
| 925 | pLayerNames[count].layer_name[len] = '\0'; |
| 926 | pLayerNames[count].lib_name = lib_name[i]; |
| 927 | count++; |
Jon Ashburn | b4d0053 | 2014-10-22 21:15:26 -0600 | [diff] [blame] | 928 | } |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 929 | p = next; |
| 930 | |
Courtney Goeltzenleuchter | 0199e95 | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 931 | } |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 932 | |
Jon Ashburn | b4d0053 | 2014-10-22 21:15:26 -0600 | [diff] [blame] | 933 | free(pOrig); |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 934 | return count; |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 935 | } |
| 936 | |
Jon Ashburn | 301c5f0 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 937 | static uint32_t loader_get_layer_libs(struct loader_icd *icd, uint32_t gpu_index, uint32_t ext_count, const char *const* ext_names, struct layer_name_pair **ppLayerNames) |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 938 | { |
Jon Ashburn | ead95c5 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 939 | static struct layer_name_pair layerNames[MAX_LAYER_LIBRARIES]; |
Jon Ashburn | 4d3b752 | 2015-04-14 14:14:48 -0600 | [diff] [blame] | 940 | char *lib_name[MAX_LAYER_LIBRARIES]; |
| 941 | uint32_t found_count, count = 0; |
| 942 | bool skip; |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 943 | |
| 944 | *ppLayerNames = &layerNames[0]; |
Courtney Goeltzenleuchter | 34e6667 | 2015-02-17 14:21:21 -0700 | [diff] [blame] | 945 | /* Load any layers specified in the environment first */ |
Courtney Goeltzenleuchter | 0199e95 | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 946 | count = loader_get_layer_env(icd, gpu_index, layerNames); |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 947 | |
Jon Ashburn | 301c5f0 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 948 | for (uint32_t i = 0; i < ext_count; i++) { |
| 949 | const char *pExtName = ext_names[i]; |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 950 | |
Jon Ashburn | 4d3b752 | 2015-04-14 14:14:48 -0600 | [diff] [blame] | 951 | skip = false; |
| 952 | for (uint32_t j = 0; j < count; j++) { |
| 953 | if (!strcmp(pExtName, layerNames[j].layer_name) ) { |
| 954 | // Extension / Layer already on the list skip it |
| 955 | skip = true; |
| 956 | break; |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 957 | } |
Jon Ashburn | 4d3b752 | 2015-04-14 14:14:48 -0600 | [diff] [blame] | 958 | } |
Courtney Goeltzenleuchter | 0199e95 | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 959 | |
Jon Ashburn | 4d3b752 | 2015-04-14 14:14:48 -0600 | [diff] [blame] | 960 | if (!skip && find_layer_extension(icd, gpu_index, pExtName, &found_count, lib_name)) { |
| 961 | |
| 962 | for (uint32_t j = 0; j < found_count; j++) { |
| 963 | uint32_t len; |
| 964 | len = (uint32_t) strlen(pExtName); |
| 965 | |
| 966 | |
| 967 | layerNames[count].layer_name = malloc(len + 1); |
| 968 | if (!layerNames[count].layer_name) |
| 969 | return count; |
| 970 | strncpy((char *) layerNames[count].layer_name, pExtName, len); |
| 971 | layerNames[count].layer_name[len] = '\0'; |
| 972 | layerNames[count].lib_name = lib_name[j]; |
| 973 | count++; |
| 974 | } |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 975 | } |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 976 | } |
Courtney Goeltzenleuchter | 0199e95 | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 977 | |
| 978 | return count; |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 979 | } |
| 980 | |
Jon Ashburn | 14275da | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 981 | static void loader_deactivate_layer(const struct loader_instance *instance) |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 982 | { |
| 983 | struct loader_icd *icd; |
| 984 | struct loader_layers *libs; |
| 985 | |
Jon Ashburn | 14275da | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 986 | for (icd = instance->icds; icd; icd = icd->next) { |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 987 | if (icd->gpus) |
| 988 | free(icd->gpus); |
| 989 | icd->gpus = NULL; |
| 990 | if (icd->loader_dispatch) |
| 991 | free(icd->loader_dispatch); |
| 992 | icd->loader_dispatch = NULL; |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 993 | for (uint32_t j = 0; j < icd->gpu_count; j++) { |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 994 | if (icd->layer_count[j] > 0) { |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 995 | for (uint32_t i = 0; i < icd->layer_count[j]; i++) { |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 996 | libs = &(icd->layer_libs[j][i]); |
| 997 | if (libs->lib_handle) |
Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 998 | loader_platform_close_library(libs->lib_handle); |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 999 | libs->lib_handle = NULL; |
| 1000 | } |
Jon Ashburn | b4d0053 | 2014-10-22 21:15:26 -0600 | [diff] [blame] | 1001 | if (icd->wrappedGpus[j]) |
| 1002 | free(icd->wrappedGpus[j]); |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 1003 | } |
| 1004 | icd->layer_count[j] = 0; |
| 1005 | } |
| 1006 | icd->gpu_count = 0; |
| 1007 | } |
| 1008 | } |
| 1009 | |
Jon Ashburn | 301c5f0 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 1010 | extern uint32_t loader_activate_layers(struct loader_icd *icd, uint32_t gpu_index, uint32_t ext_count, const char *const* ext_names) |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 1011 | { |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1012 | uint32_t count; |
Jon Ashburn | 301c5f0 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 1013 | VkBaseLayerObject *gpu; |
Jon Ashburn | ead95c5 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 1014 | struct layer_name_pair *pLayerNames; |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 1015 | if (!icd) |
| 1016 | return 0; |
Jon Ashburn | 07b309a | 2015-04-15 11:31:12 -0600 | [diff] [blame] | 1017 | assert(gpu_index < MAX_GPUS_FOR_LAYER); |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 1018 | |
Jon Ashburn | 301c5f0 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 1019 | gpu = icd->gpus + gpu_index; |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 1020 | /* activate any layer libraries */ |
| 1021 | if (!loader_layers_activated(icd, gpu_index)) { |
Jon Ashburn | 301c5f0 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 1022 | VkBaseLayerObject *gpuObj = gpu; |
Mike Stroyan | 230e625 | 2015-04-17 12:36:38 -0600 | [diff] [blame] | 1023 | VkBaseLayerObject *nextGpuObj, *baseObj = (VkBaseLayerObject *) gpuObj->baseObject; |
Jon Ashburn | e18431b | 2015-04-13 18:10:06 -0600 | [diff] [blame] | 1024 | PFN_vkGetProcAddr nextGPA = loader_gpa_internal; |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 1025 | |
Jon Ashburn | 301c5f0 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 1026 | count = loader_get_layer_libs(icd, gpu_index, ext_count, ext_names, &pLayerNames); |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 1027 | if (!count) |
| 1028 | return 0; |
Jon Ashburn | ead95c5 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 1029 | loader_init_layer_libs(icd, gpu_index, pLayerNames, count); |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 1030 | |
Jon Ashburn | 301c5f0 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 1031 | icd->wrappedGpus[gpu_index] = malloc(sizeof(VkBaseLayerObject) * icd->layer_count[gpu_index]); |
Jon Ashburn | b4d0053 | 2014-10-22 21:15:26 -0600 | [diff] [blame] | 1032 | if (! icd->wrappedGpus[gpu_index]) |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1033 | loader_log(VK_DBG_MSG_ERROR, 0, "Failed to malloc Gpu objects for layer"); |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1034 | for (int32_t i = icd->layer_count[gpu_index] - 1; i >= 0; i--) { |
Jon Ashburn | b4d0053 | 2014-10-22 21:15:26 -0600 | [diff] [blame] | 1035 | nextGpuObj = (icd->wrappedGpus[gpu_index] + i); |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 1036 | nextGpuObj->pGPA = nextGPA; |
Mike Stroyan | 230e625 | 2015-04-17 12:36:38 -0600 | [diff] [blame] | 1037 | nextGpuObj->baseObject = (VkObject) baseObj; |
| 1038 | nextGpuObj->nextObject = (VkObject) gpuObj; |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 1039 | gpuObj = nextGpuObj; |
| 1040 | |
Jon Ashburn | 8d8dad0 | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 1041 | char funcStr[256]; |
| 1042 | snprintf(funcStr, 256, "%sGetProcAddr",icd->layer_libs[gpu_index][i].name); |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1043 | if ((nextGPA = (PFN_vkGetProcAddr) loader_platform_get_proc_address(icd->layer_libs[gpu_index][i].lib_handle, funcStr)) == NULL) |
| 1044 | nextGPA = (PFN_vkGetProcAddr) loader_platform_get_proc_address(icd->layer_libs[gpu_index][i].lib_handle, "vkGetProcAddr"); |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 1045 | if (!nextGPA) { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1046 | loader_log(VK_DBG_MSG_ERROR, 0, "Failed to find vkGetProcAddr in layer %s", icd->layer_libs[gpu_index][i].name); |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 1047 | continue; |
| 1048 | } |
| 1049 | |
Jon Ashburn | 3e7c080 | 2014-10-24 15:48:55 -0600 | [diff] [blame] | 1050 | if (i == 0) { |
Jon Ashburn | 9a9bb64 | 2015-05-04 16:27:53 -0600 | [diff] [blame^] | 1051 | loader_init_device_dispatch_table(icd->loader_dispatch + gpu_index, nextGPA, (VkPhysicalDevice) gpuObj); |
Jon Ashburn | 3e7c080 | 2014-10-24 15:48:55 -0600 | [diff] [blame] | 1052 | //Insert the new wrapped objects into the list with loader object at head |
Mike Stroyan | 230e625 | 2015-04-17 12:36:38 -0600 | [diff] [blame] | 1053 | gpu->nextObject = (VkObject) gpuObj; |
Jon Ashburn | 301c5f0 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 1054 | gpu->pGPA = nextGPA; |
Jon Ashburn | 3e7c080 | 2014-10-24 15:48:55 -0600 | [diff] [blame] | 1055 | gpuObj = icd->wrappedGpus[gpu_index] + icd->layer_count[gpu_index] - 1; |
Mike Stroyan | 230e625 | 2015-04-17 12:36:38 -0600 | [diff] [blame] | 1056 | gpuObj->nextObject = (VkObject) baseObj; |
Jon Ashburn | 14275da | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 1057 | gpuObj->pGPA = icd->scanned_icds->GetProcAddr; |
Jon Ashburn | 3e7c080 | 2014-10-24 15:48:55 -0600 | [diff] [blame] | 1058 | } |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 1059 | |
| 1060 | } |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 1061 | } |
| 1062 | else { |
| 1063 | //make sure requested Layers matches currently activated Layers |
Jon Ashburn | 301c5f0 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 1064 | count = loader_get_layer_libs(icd, gpu_index, ext_count, ext_names, &pLayerNames); |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1065 | for (uint32_t i = 0; i < count; i++) { |
Jon Ashburn | ead95c5 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 1066 | if (strcmp(icd->layer_libs[gpu_index][i].name, pLayerNames[i].layer_name)) { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1067 | loader_log(VK_DBG_MSG_ERROR, 0, "Layers activated != Layers requested"); |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 1068 | break; |
| 1069 | } |
| 1070 | } |
| 1071 | if (count != icd->layer_count[gpu_index]) { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1072 | loader_log(VK_DBG_MSG_ERROR, 0, "Number of Layers activated != number requested"); |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 1073 | } |
| 1074 | } |
| 1075 | return icd->layer_count[gpu_index]; |
| 1076 | } |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 1077 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1078 | LOADER_EXPORT VkResult VKAPI vkCreateInstance( |
Courtney Goeltzenleuchter | ddcb619 | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 1079 | const VkInstanceCreateInfo* pCreateInfo, |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1080 | VkInstance* pInstance) |
Jon Ashburn | 349508d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 1081 | { |
| 1082 | struct loader_instance *ptr_instance = NULL; |
Jon Ashburn | 3336df8 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 1083 | struct loader_scanned_icds *scanned_icds; |
| 1084 | struct loader_icd *icd; |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1085 | VkResult res = VK_ERROR_INITIALIZATION_FAILED; |
Jon Ashburn | 063cd37 | 2015-04-08 15:49:00 -0600 | [diff] [blame] | 1086 | uint32_t i; |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 1087 | |
Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1088 | /* Scan/discover all ICD libraries in a single-threaded manner */ |
| 1089 | loader_platform_thread_once(&once_icd, loader_icd_scan); |
Jon Ashburn | 3336df8 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 1090 | |
Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1091 | /* get layer libraries in a single-threaded manner */ |
| 1092 | loader_platform_thread_once(&once_layer, layer_lib_scan); |
Jon Ashburn | 3336df8 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 1093 | |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1094 | /* merge any duplicate extensions */ |
| 1095 | loader_platform_thread_once(&once_exts, loader_coalesce_extensions); |
| 1096 | |
Jon Ashburn | 349508d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 1097 | ptr_instance = (struct loader_instance*) malloc(sizeof(struct loader_instance)); |
| 1098 | if (ptr_instance == NULL) { |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 1099 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Jon Ashburn | 349508d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 1100 | } |
| 1101 | memset(ptr_instance, 0, sizeof(struct loader_instance)); |
Jon Ashburn | 063cd37 | 2015-04-08 15:49:00 -0600 | [diff] [blame] | 1102 | ptr_instance->extension_count = pCreateInfo->extensionCount; |
| 1103 | ptr_instance->extension_names = (ptr_instance->extension_count > 0) ? |
| 1104 | malloc(sizeof (char *) * ptr_instance->extension_count) : NULL; |
Jon Ashburn | 42e4103 | 2015-04-14 09:15:32 -0600 | [diff] [blame] | 1105 | if (ptr_instance->extension_names == NULL && (ptr_instance->extension_count > 0)) |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 1106 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Jon Ashburn | 063cd37 | 2015-04-08 15:49:00 -0600 | [diff] [blame] | 1107 | for (i = 0; i < ptr_instance->extension_count; i++) { |
Jon Ashburn | 42e4103 | 2015-04-14 09:15:32 -0600 | [diff] [blame] | 1108 | if (!loader_is_extension_scanned(pCreateInfo->ppEnabledExtensionNames[i])) |
| 1109 | return VK_ERROR_INVALID_EXTENSION; |
| 1110 | ptr_instance->extension_names[i] = malloc(strlen(pCreateInfo->ppEnabledExtensionNames[i]) + 1); |
Jon Ashburn | 063cd37 | 2015-04-08 15:49:00 -0600 | [diff] [blame] | 1111 | if (ptr_instance->extension_names[i] == NULL) |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 1112 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Jon Ashburn | 063cd37 | 2015-04-08 15:49:00 -0600 | [diff] [blame] | 1113 | strcpy(ptr_instance->extension_names[i], pCreateInfo->ppEnabledExtensionNames[i]); |
| 1114 | } |
Jon Ashburn | 349508d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 1115 | ptr_instance->next = loader.instances; |
| 1116 | loader.instances = ptr_instance; |
| 1117 | |
Jon Ashburn | 3336df8 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 1118 | scanned_icds = loader.scanned_icd_list; |
| 1119 | while (scanned_icds) { |
| 1120 | icd = loader_icd_add(ptr_instance, scanned_icds); |
| 1121 | if (icd) { |
Jon Ashburn | 29669a4 | 2015-04-04 14:52:07 -0600 | [diff] [blame] | 1122 | res = scanned_icds->CreateInstance(pCreateInfo, |
Jon Ashburn | 3336df8 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 1123 | &(scanned_icds->instance)); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1124 | if (res != VK_SUCCESS) |
Jon Ashburn | 3336df8 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 1125 | { |
| 1126 | ptr_instance->icds = ptr_instance->icds->next; |
| 1127 | loader_icd_destroy(icd); |
Mike Stroyan | 230e625 | 2015-04-17 12:36:38 -0600 | [diff] [blame] | 1128 | scanned_icds->instance = VK_NULL_HANDLE; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1129 | loader_log(VK_DBG_MSG_WARNING, 0, |
Jon Ashburn | 3336df8 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 1130 | "ICD ignored: failed to CreateInstance on device"); |
| 1131 | } |
| 1132 | } |
| 1133 | scanned_icds = scanned_icds->next; |
| 1134 | } |
Jon Ashburn | 349508d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 1135 | |
Ian Elliott | 617fdec | 2015-02-05 15:19:15 -0700 | [diff] [blame] | 1136 | if (ptr_instance->icds == NULL) { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1137 | return VK_ERROR_INCOMPATIBLE_DRIVER; |
Ian Elliott | 617fdec | 2015-02-05 15:19:15 -0700 | [diff] [blame] | 1138 | } |
Jon Ashburn | 3336df8 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 1139 | |
Jon Ashburn | 9a9bb64 | 2015-05-04 16:27:53 -0600 | [diff] [blame^] | 1140 | loader_init_instance_dispatch_table(&ptr_instance->disp); |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1141 | *pInstance = (VkInstance) ptr_instance; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1142 | return VK_SUCCESS; |
Jon Ashburn | 349508d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 1143 | } |
| 1144 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1145 | LOADER_EXPORT VkResult VKAPI vkDestroyInstance( |
| 1146 | VkInstance instance) |
Jon Ashburn | 349508d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 1147 | { |
| 1148 | struct loader_instance *ptr_instance = (struct loader_instance *) instance; |
Jon Ashburn | 3336df8 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 1149 | struct loader_scanned_icds *scanned_icds; |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1150 | VkResult res; |
Jon Ashburn | 063cd37 | 2015-04-08 15:49:00 -0600 | [diff] [blame] | 1151 | uint32_t i; |
Jon Ashburn | 349508d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 1152 | |
| 1153 | // Remove this instance from the list of instances: |
| 1154 | struct loader_instance *prev = NULL; |
| 1155 | struct loader_instance *next = loader.instances; |
| 1156 | while (next != NULL) { |
| 1157 | if (next == ptr_instance) { |
| 1158 | // Remove this instance from the list: |
Jon Ashburn | 063cd37 | 2015-04-08 15:49:00 -0600 | [diff] [blame] | 1159 | for (i = 0; i < ptr_instance->extension_count; i++) { |
| 1160 | free(ptr_instance->extension_names[i]); |
| 1161 | } |
Jon Ashburn | 349508d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 1162 | if (prev) |
| 1163 | prev->next = next->next; |
Jon Ashburn | 2cabd25 | 2015-02-03 09:26:59 -0700 | [diff] [blame] | 1164 | else |
| 1165 | loader.instances = next->next; |
Jon Ashburn | 349508d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 1166 | break; |
| 1167 | } |
| 1168 | prev = next; |
| 1169 | next = next->next; |
| 1170 | } |
| 1171 | if (next == NULL) { |
| 1172 | // This must be an invalid instance handle or empty list |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1173 | return VK_ERROR_INVALID_HANDLE; |
Jon Ashburn | 349508d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 1174 | } |
| 1175 | |
Jon Ashburn | 3336df8 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 1176 | // cleanup any prior layer initializations |
| 1177 | loader_deactivate_layer(ptr_instance); |
Jon Ashburn | 349508d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 1178 | |
Jon Ashburn | 3336df8 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 1179 | scanned_icds = loader.scanned_icd_list; |
| 1180 | while (scanned_icds) { |
Tony Barbour | 22a3086 | 2015-04-22 09:02:32 -0600 | [diff] [blame] | 1181 | if (scanned_icds->instance) { |
Jon Ashburn | 3336df8 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 1182 | res = scanned_icds->DestroyInstance(scanned_icds->instance); |
Tony Barbour | 22a3086 | 2015-04-22 09:02:32 -0600 | [diff] [blame] | 1183 | if (res != VK_SUCCESS) |
| 1184 | loader_log(VK_DBG_MSG_WARNING, 0, |
| 1185 | "ICD ignored: failed to DestroyInstance on device"); |
| 1186 | } |
Mike Stroyan | 230e625 | 2015-04-17 12:36:38 -0600 | [diff] [blame] | 1187 | scanned_icds->instance = VK_NULL_HANDLE; |
Jon Ashburn | 3336df8 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 1188 | scanned_icds = scanned_icds->next; |
| 1189 | } |
| 1190 | |
Jon Ashburn | 349508d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 1191 | free(ptr_instance); |
| 1192 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1193 | return VK_SUCCESS; |
Jon Ashburn | 349508d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 1194 | } |
| 1195 | |
Jon Ashburn | 07b309a | 2015-04-15 11:31:12 -0600 | [diff] [blame] | 1196 | LOADER_EXPORT VkResult VKAPI vkEnumeratePhysicalDevices( |
Courtney Goeltzenleuchter | 9f530cb | 2015-04-20 12:48:54 -0600 | [diff] [blame] | 1197 | VkInstance instance, |
| 1198 | uint32_t* pPhysicalDeviceCount, |
| 1199 | VkPhysicalDevice* pPhysicalDevices) |
Jon Ashburn | 349508d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 1200 | { |
Jon Ashburn | b048a9b | 2015-01-28 19:57:09 -0700 | [diff] [blame] | 1201 | struct loader_instance *ptr_instance = (struct loader_instance *) instance; |
| 1202 | struct loader_icd *icd; |
Jon Ashburn | 07b309a | 2015-04-15 11:31:12 -0600 | [diff] [blame] | 1203 | uint32_t n, count = 0; |
Tony Barbour | 22a3086 | 2015-04-22 09:02:32 -0600 | [diff] [blame] | 1204 | VkResult res = VK_ERROR_UNKNOWN; |
Jon Ashburn | b048a9b | 2015-01-28 19:57:09 -0700 | [diff] [blame] | 1205 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1206 | //in spirit of VK don't error check on the instance parameter |
Jon Ashburn | b048a9b | 2015-01-28 19:57:09 -0700 | [diff] [blame] | 1207 | icd = ptr_instance->icds; |
Jon Ashburn | 07b309a | 2015-04-15 11:31:12 -0600 | [diff] [blame] | 1208 | if (pPhysicalDevices == NULL) { |
| 1209 | while (icd) { |
| 1210 | res = icd->scanned_icds->EnumeratePhysicalDevices( |
| 1211 | icd->scanned_icds->instance, |
| 1212 | &n, NULL); |
| 1213 | if (res != VK_SUCCESS) |
| 1214 | return res; |
| 1215 | icd->gpu_count = n; |
| 1216 | count += n; |
| 1217 | icd = icd->next; |
Jon Ashburn | b048a9b | 2015-01-28 19:57:09 -0700 | [diff] [blame] | 1218 | } |
| 1219 | |
Jon Ashburn | 07b309a | 2015-04-15 11:31:12 -0600 | [diff] [blame] | 1220 | ptr_instance->total_gpu_count = count; |
Courtney Goeltzenleuchter | ba7133b | 2015-02-10 18:40:14 -0700 | [diff] [blame] | 1221 | |
Jon Ashburn | 07b309a | 2015-04-15 11:31:12 -0600 | [diff] [blame] | 1222 | } else |
| 1223 | { |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 1224 | VkPhysicalDevice* gpus; |
Jon Ashburn | 07b309a | 2015-04-15 11:31:12 -0600 | [diff] [blame] | 1225 | if (*pPhysicalDeviceCount < ptr_instance->total_gpu_count) |
| 1226 | return VK_ERROR_INVALID_VALUE; |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 1227 | gpus = malloc( sizeof(VkPhysicalDevice) * *pPhysicalDeviceCount); |
Jon Ashburn | 07b309a | 2015-04-15 11:31:12 -0600 | [diff] [blame] | 1228 | if (!gpus) |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 1229 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Jon Ashburn | 07b309a | 2015-04-15 11:31:12 -0600 | [diff] [blame] | 1230 | while (icd) { |
| 1231 | VkBaseLayerObject * wrapped_gpus; |
| 1232 | PFN_vkGetProcAddr get_proc_addr = icd->scanned_icds->GetProcAddr; |
| 1233 | |
Courtney Goeltzenleuchter | 9f530cb | 2015-04-20 12:48:54 -0600 | [diff] [blame] | 1234 | n = *pPhysicalDeviceCount; |
Jon Ashburn | 07b309a | 2015-04-15 11:31:12 -0600 | [diff] [blame] | 1235 | res = icd->scanned_icds->EnumeratePhysicalDevices( |
| 1236 | icd->scanned_icds->instance, |
| 1237 | &n, |
| 1238 | gpus); |
| 1239 | if (res == VK_SUCCESS && n) { |
| 1240 | wrapped_gpus = (VkBaseLayerObject*) malloc(n * |
| 1241 | sizeof(VkBaseLayerObject)); |
| 1242 | icd->gpus = wrapped_gpus; |
| 1243 | icd->gpu_count = n; |
| 1244 | icd->loader_dispatch = (VkLayerDispatchTable *) malloc(n * |
| 1245 | sizeof(VkLayerDispatchTable)); |
| 1246 | for (unsigned int i = 0; i < n; i++) { |
| 1247 | (wrapped_gpus + i)->baseObject = gpus[i]; |
| 1248 | (wrapped_gpus + i)->pGPA = get_proc_addr; |
| 1249 | (wrapped_gpus + i)->nextObject = gpus[i]; |
| 1250 | memcpy(pPhysicalDevices + count, gpus, sizeof(*pPhysicalDevices)); |
Jon Ashburn | 9a9bb64 | 2015-05-04 16:27:53 -0600 | [diff] [blame^] | 1251 | loader_init_device_dispatch_table(icd->loader_dispatch + i, |
Jon Ashburn | 07b309a | 2015-04-15 11:31:12 -0600 | [diff] [blame] | 1252 | get_proc_addr, gpus[i]); |
| 1253 | |
| 1254 | /* Verify ICD compatibility */ |
Tony Barbour | 11e76ac | 2015-04-20 16:28:46 -0600 | [diff] [blame] | 1255 | if (!valid_loader_magic_value(gpus[i])) { |
Jon Ashburn | 07b309a | 2015-04-15 11:31:12 -0600 | [diff] [blame] | 1256 | loader_log(VK_DBG_MSG_WARNING, 0, |
Courtney Goeltzenleuchter | ba7133b | 2015-02-10 18:40:14 -0700 | [diff] [blame] | 1257 | "Loader: Incompatible ICD, first dword must be initialized to ICD_LOADER_MAGIC. See loader/README.md for details.\n"); |
Jon Ashburn | 07b309a | 2015-04-15 11:31:12 -0600 | [diff] [blame] | 1258 | assert(0); |
| 1259 | } |
| 1260 | |
| 1261 | const VkLayerDispatchTable **disp; |
| 1262 | disp = (const VkLayerDispatchTable **) gpus[i]; |
| 1263 | *disp = icd->loader_dispatch + i; |
| 1264 | loader_activate_layers(icd, i, ptr_instance->extension_count, |
| 1265 | (const char *const*) ptr_instance->extension_names); |
Courtney Goeltzenleuchter | ba7133b | 2015-02-10 18:40:14 -0700 | [diff] [blame] | 1266 | } |
| 1267 | |
Jon Ashburn | 07b309a | 2015-04-15 11:31:12 -0600 | [diff] [blame] | 1268 | count += n; |
| 1269 | |
| 1270 | if (count >= *pPhysicalDeviceCount) { |
| 1271 | break; |
| 1272 | } |
Jon Ashburn | b048a9b | 2015-01-28 19:57:09 -0700 | [diff] [blame] | 1273 | } |
| 1274 | |
Jon Ashburn | 07b309a | 2015-04-15 11:31:12 -0600 | [diff] [blame] | 1275 | icd = icd->next; |
Jon Ashburn | b048a9b | 2015-01-28 19:57:09 -0700 | [diff] [blame] | 1276 | } |
Jon Ashburn | b048a9b | 2015-01-28 19:57:09 -0700 | [diff] [blame] | 1277 | } |
| 1278 | |
Jon Ashburn | 07b309a | 2015-04-15 11:31:12 -0600 | [diff] [blame] | 1279 | *pPhysicalDeviceCount = count; |
Jon Ashburn | b048a9b | 2015-01-28 19:57:09 -0700 | [diff] [blame] | 1280 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1281 | return (count > 0) ? VK_SUCCESS : res; |
Jon Ashburn | 349508d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 1282 | } |
| 1283 | |
Jon Ashburn | 53c1677 | 2015-05-06 10:15:07 -0600 | [diff] [blame] | 1284 | LOADER_EXPORT void * VKAPI vkGetInstanceProcAddr(VkInstance instance, const char * pName) |
| 1285 | { |
| 1286 | if (instance != VK_NULL_HANDLE) { |
| 1287 | |
| 1288 | /* return entrypoint addresses that are global (in the loader)*/ |
| 1289 | return globalGetProcAddr(pName); |
| 1290 | } |
| 1291 | |
| 1292 | return NULL; |
| 1293 | } |
| 1294 | |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 1295 | LOADER_EXPORT void * VKAPI vkGetProcAddr(VkPhysicalDevice gpu, const char * pName) |
Jon Ashburn | 349508d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 1296 | { |
Mike Stroyan | 230e625 | 2015-04-17 12:36:38 -0600 | [diff] [blame] | 1297 | if (gpu == VK_NULL_HANDLE) { |
Jon Ashburn | e18431b | 2015-04-13 18:10:06 -0600 | [diff] [blame] | 1298 | |
| 1299 | /* return entrypoint addresses that are global (in the loader)*/ |
| 1300 | return globalGetProcAddr(pName); |
Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1301 | } |
Jon Ashburn | e18431b | 2015-04-13 18:10:06 -0600 | [diff] [blame] | 1302 | |
Chia-I Wu | 38e5a2c | 2015-01-04 11:12:47 +0800 | [diff] [blame] | 1303 | void *addr; |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 1304 | |
Jon Ashburn | e18431b | 2015-04-13 18:10:06 -0600 | [diff] [blame] | 1305 | /* for entrypoints that loader must handle (ie non-dispatchable or create object) |
| 1306 | make sure the loader entrypoint is returned */ |
| 1307 | addr = loader_non_passthrough_gpa(pName); |
Ian Elliott | fdf00b6 | 2015-04-15 12:53:19 -0600 | [diff] [blame] | 1308 | if (addr) { |
Jon Ashburn | e18431b | 2015-04-13 18:10:06 -0600 | [diff] [blame] | 1309 | return addr; |
Ian Elliott | fdf00b6 | 2015-04-15 12:53:19 -0600 | [diff] [blame] | 1310 | } |
Jon Ashburn | e18431b | 2015-04-13 18:10:06 -0600 | [diff] [blame] | 1311 | |
| 1312 | /* return the dispatch table entrypoint for the fastest case */ |
| 1313 | const VkLayerDispatchTable *disp_table = * (VkLayerDispatchTable **) gpu; |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 1314 | if (disp_table == NULL) |
| 1315 | return NULL; |
| 1316 | |
Chia-I Wu | 38e5a2c | 2015-01-04 11:12:47 +0800 | [diff] [blame] | 1317 | addr = loader_lookup_dispatch_table(disp_table, pName); |
| 1318 | if (addr) |
| 1319 | return addr; |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 1320 | else { |
Jon Ashburn | 3e7c080 | 2014-10-24 15:48:55 -0600 | [diff] [blame] | 1321 | if (disp_table->GetProcAddr == NULL) |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 1322 | return NULL; |
Jon Ashburn | e18431b | 2015-04-13 18:10:06 -0600 | [diff] [blame] | 1323 | return disp_table->GetProcAddr(gpu, pName); |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 1324 | } |
| 1325 | } |
| 1326 | |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1327 | //TODO make sure createInstance enables extensions that are valid (loader does) |
| 1328 | //TODO make sure CreateDevice enables extensions that are valid (left for layers/drivers to do) |
| 1329 | |
| 1330 | //TODO how is layer extension going to be enabled? |
| 1331 | //Need to call createInstance on the layer or something |
| 1332 | |
| 1333 | LOADER_EXPORT VkResult VKAPI vkGetGlobalExtensionInfo( |
| 1334 | VkExtensionInfoType infoType, |
| 1335 | uint32_t extensionIndex, |
| 1336 | size_t* pDataSize, |
| 1337 | void* pData) |
Courtney Goeltzenleuchter | 0199e95 | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 1338 | { |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1339 | VkExtensionProperties *ext_props; |
| 1340 | uint32_t *count; |
| 1341 | /* Scan/discover all ICD libraries in a single-threaded manner */ |
| 1342 | loader_platform_thread_once(&once_icd, loader_icd_scan); |
Courtney Goeltzenleuchter | 0199e95 | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 1343 | |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1344 | /* get layer libraries in a single-threaded manner */ |
| 1345 | loader_platform_thread_once(&once_layer, layer_lib_scan); |
Courtney Goeltzenleuchter | 0199e95 | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 1346 | |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1347 | /* merge any duplicate extensions */ |
| 1348 | loader_platform_thread_once(&once_exts, loader_coalesce_extensions); |
| 1349 | |
| 1350 | |
| 1351 | if (pDataSize == NULL) |
| 1352 | return VK_ERROR_INVALID_POINTER; |
| 1353 | |
| 1354 | switch (infoType) { |
| 1355 | case VK_EXTENSION_INFO_TYPE_COUNT: |
| 1356 | *pDataSize = sizeof(uint32_t); |
| 1357 | if (pData == NULL) |
| 1358 | return VK_SUCCESS; |
| 1359 | count = (uint32_t *) pData; |
| 1360 | *count = loader.scanned_ext_list_count; |
| 1361 | break; |
| 1362 | case VK_EXTENSION_INFO_TYPE_PROPERTIES: |
| 1363 | *pDataSize = sizeof(VkExtensionProperties); |
| 1364 | if (pData == NULL) |
| 1365 | return VK_SUCCESS; |
| 1366 | if (extensionIndex >= loader.scanned_ext_list_count) |
| 1367 | return VK_ERROR_INVALID_VALUE; |
| 1368 | ext_props = (VkExtensionProperties *) pData; |
| 1369 | ext_props->version = loader.scanned_ext_list[extensionIndex]->version; |
| 1370 | strncpy(ext_props->extName, loader.scanned_ext_list[extensionIndex]->extName |
| 1371 | , VK_MAX_EXTENSION_NAME); |
| 1372 | ext_props->extName[VK_MAX_EXTENSION_NAME - 1] = '\0'; |
| 1373 | break; |
| 1374 | default: |
| 1375 | loader_log(VK_DBG_MSG_WARNING, 0, "Invalid infoType in vkGetGlobalExtensionInfo"); |
| 1376 | return VK_ERROR_INVALID_VALUE; |
| 1377 | }; |
| 1378 | |
| 1379 | return VK_SUCCESS; |
Courtney Goeltzenleuchter | 0199e95 | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 1380 | } |
| 1381 | |
Courtney Goeltzenleuchter | bb1f360 | 2015-04-20 11:04:54 -0600 | [diff] [blame] | 1382 | LOADER_EXPORT VkResult VKAPI vkEnumerateLayers(VkPhysicalDevice gpu, size_t maxStringSize, size_t* pLayerCount, char* const* pOutLayers, void* pReserved) |
Jon Ashburn | 96f28fc | 2014-10-15 15:30:23 -0600 | [diff] [blame] | 1383 | { |
Courtney Goeltzenleuchter | bb1f360 | 2015-04-20 11:04:54 -0600 | [diff] [blame] | 1384 | size_t maxLayerCount; |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1385 | uint32_t gpu_index; |
Ian Elliott | 64f74a8 | 2015-02-04 12:06:46 -0700 | [diff] [blame] | 1386 | size_t count = 0; |
Jon Ashburn | b9a54ac | 2014-12-02 13:03:09 -0700 | [diff] [blame] | 1387 | char *lib_name; |
Jon Ashburn | 301c5f0 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 1388 | struct loader_icd *icd = loader_get_icd((const VkBaseLayerObject *) gpu, &gpu_index); |
Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1389 | loader_platform_dl_handle handle; |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1390 | PFN_vkEnumerateLayers fpEnumerateLayers; |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1391 | char layer_buf[16][256]; |
| 1392 | char * layers[16]; |
Jon Ashburn | 96f28fc | 2014-10-15 15:30:23 -0600 | [diff] [blame] | 1393 | |
Courtney Goeltzenleuchter | bb1f360 | 2015-04-20 11:04:54 -0600 | [diff] [blame] | 1394 | if (pLayerCount == NULL || pOutLayers == NULL) |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1395 | return VK_ERROR_INVALID_POINTER; |
Jon Ashburn | 96f28fc | 2014-10-15 15:30:23 -0600 | [diff] [blame] | 1396 | |
Courtney Goeltzenleuchter | bb1f360 | 2015-04-20 11:04:54 -0600 | [diff] [blame] | 1397 | maxLayerCount = *pLayerCount; |
| 1398 | |
Jon Ashburn | 14275da | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 1399 | if (!icd) |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1400 | return VK_ERROR_UNAVAILABLE; |
Jon Ashburn | 14275da | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 1401 | |
Jon Ashburn | b9a54ac | 2014-12-02 13:03:09 -0700 | [diff] [blame] | 1402 | for (int i = 0; i < 16; i++) |
| 1403 | layers[i] = &layer_buf[i][0]; |
| 1404 | |
| 1405 | for (unsigned int j = 0; j < loader.scanned_layer_count && count < maxLayerCount; j++) { |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1406 | lib_name = loader.scanned_layers[j].name; |
Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1407 | // Used to call: dlopen(*lib_name, RTLD_LAZY) |
| 1408 | if ((handle = loader_platform_open_library(lib_name)) == NULL) |
Jon Ashburn | b9a54ac | 2014-12-02 13:03:09 -0700 | [diff] [blame] | 1409 | continue; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1410 | if ((fpEnumerateLayers = loader_platform_get_proc_address(handle, "vkEnumerateLayers")) == NULL) { |
| 1411 | //use default layer name based on library name VK_LAYER_LIBRARY_PREFIX<name>.VK_LIBRARY_SUFFIX |
Jon Ashburn | b9a54ac | 2014-12-02 13:03:09 -0700 | [diff] [blame] | 1412 | char *pEnd, *cpyStr; |
Ian Elliott | 642f892 | 2015-02-13 14:29:21 -0700 | [diff] [blame] | 1413 | size_t siz; |
Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1414 | loader_platform_close_library(handle); |
Jon Ashburn | b9a54ac | 2014-12-02 13:03:09 -0700 | [diff] [blame] | 1415 | lib_name = basename(lib_name); |
| 1416 | pEnd = strrchr(lib_name, '.'); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1417 | siz = (int) (pEnd - lib_name - strlen(VK_LAYER_LIBRARY_PREFIX) + 1); |
Jon Ashburn | b9a54ac | 2014-12-02 13:03:09 -0700 | [diff] [blame] | 1418 | if (pEnd == NULL || siz <= 0) |
| 1419 | continue; |
| 1420 | cpyStr = malloc(siz); |
| 1421 | if (cpyStr == NULL) { |
| 1422 | free(cpyStr); |
| 1423 | continue; |
| 1424 | } |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1425 | strncpy(cpyStr, lib_name + strlen(VK_LAYER_LIBRARY_PREFIX), siz); |
Jon Ashburn | b9a54ac | 2014-12-02 13:03:09 -0700 | [diff] [blame] | 1426 | cpyStr[siz - 1] = '\0'; |
| 1427 | if (siz > maxStringSize) |
Ian Elliott | 64f74a8 | 2015-02-04 12:06:46 -0700 | [diff] [blame] | 1428 | siz = (int) maxStringSize; |
Jon Ashburn | b9a54ac | 2014-12-02 13:03:09 -0700 | [diff] [blame] | 1429 | strncpy((char *) (pOutLayers[count]), cpyStr, siz); |
| 1430 | pOutLayers[count][siz - 1] = '\0'; |
| 1431 | count++; |
| 1432 | free(cpyStr); |
Courtney Goeltzenleuchter | 0199e95 | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 1433 | } else { |
Courtney Goeltzenleuchter | bb1f360 | 2015-04-20 11:04:54 -0600 | [diff] [blame] | 1434 | size_t cnt = 16; /* only allow 16 layers, for now */ |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1435 | uint32_t n; |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1436 | VkResult res; |
Ian Elliott | 64f74a8 | 2015-02-04 12:06:46 -0700 | [diff] [blame] | 1437 | n = (uint32_t) ((maxStringSize < 256) ? maxStringSize : 256); |
Courtney Goeltzenleuchter | bb1f360 | 2015-04-20 11:04:54 -0600 | [diff] [blame] | 1438 | res = fpEnumerateLayers((VkPhysicalDevice) NULL, n, &cnt, layers, (char *) icd->gpus + gpu_index); |
Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1439 | loader_platform_close_library(handle); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1440 | if (res != VK_SUCCESS) |
Jon Ashburn | b9a54ac | 2014-12-02 13:03:09 -0700 | [diff] [blame] | 1441 | continue; |
| 1442 | if (cnt + count > maxLayerCount) |
| 1443 | cnt = maxLayerCount - count; |
Ian Elliott | 64f74a8 | 2015-02-04 12:06:46 -0700 | [diff] [blame] | 1444 | for (uint32_t i = (uint32_t) count; i < cnt + count; i++) { |
Jon Ashburn | b9a54ac | 2014-12-02 13:03:09 -0700 | [diff] [blame] | 1445 | strncpy((char *) (pOutLayers[i]), (char *) layers[i - count], n); |
| 1446 | if (n > 0) |
| 1447 | pOutLayers[i - count][n - 1] = '\0'; |
| 1448 | } |
| 1449 | count += cnt; |
| 1450 | } |
| 1451 | } |
| 1452 | |
Courtney Goeltzenleuchter | bb1f360 | 2015-04-20 11:04:54 -0600 | [diff] [blame] | 1453 | *pLayerCount = count; |
Jon Ashburn | 96f28fc | 2014-10-15 15:30:23 -0600 | [diff] [blame] | 1454 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1455 | return VK_SUCCESS; |
Jon Ashburn | 96f28fc | 2014-10-15 15:30:23 -0600 | [diff] [blame] | 1456 | } |
| 1457 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1458 | LOADER_EXPORT VkResult VKAPI vkDbgRegisterMsgCallback(VkInstance instance, VK_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback, void* pUserData) |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1459 | { |
Jon Ashburn | 406a0fe | 2014-11-14 09:52:42 -0700 | [diff] [blame] | 1460 | const struct loader_icd *icd; |
Jon Ashburn | dc67ef5 | 2015-01-29 16:44:24 -0700 | [diff] [blame] | 1461 | struct loader_instance *inst; |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1462 | VkResult res; |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1463 | uint32_t gpu_idx; |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1464 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1465 | if (instance == VK_NULL_HANDLE) |
| 1466 | return VK_ERROR_INVALID_HANDLE; |
Courtney Goeltzenleuchter | 9d36ef4 | 2015-04-13 14:10:06 -0600 | [diff] [blame] | 1467 | |
| 1468 | assert(loader.icds_scanned); |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1469 | |
Jon Ashburn | dc67ef5 | 2015-01-29 16:44:24 -0700 | [diff] [blame] | 1470 | for (inst = loader.instances; inst; inst = inst->next) { |
Mike Stroyan | 230e625 | 2015-04-17 12:36:38 -0600 | [diff] [blame] | 1471 | if ((VkInstance) inst == instance) |
Jon Ashburn | c0db2af | 2015-03-17 13:47:55 -0600 | [diff] [blame] | 1472 | break; |
| 1473 | } |
| 1474 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1475 | if (inst == VK_NULL_HANDLE) |
| 1476 | return VK_ERROR_INVALID_HANDLE; |
Jon Ashburn | c0db2af | 2015-03-17 13:47:55 -0600 | [diff] [blame] | 1477 | |
| 1478 | for (icd = inst->icds; icd; icd = icd->next) { |
| 1479 | for (uint32_t i = 0; i < icd->gpu_count; i++) { |
| 1480 | res = (icd->loader_dispatch + i)->DbgRegisterMsgCallback(icd->scanned_icds->instance, |
Jon Ashburn | dc67ef5 | 2015-01-29 16:44:24 -0700 | [diff] [blame] | 1481 | pfnMsgCallback, pUserData); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1482 | if (res != VK_SUCCESS) { |
Jon Ashburn | c0db2af | 2015-03-17 13:47:55 -0600 | [diff] [blame] | 1483 | gpu_idx = i; |
Jon Ashburn | dc67ef5 | 2015-01-29 16:44:24 -0700 | [diff] [blame] | 1484 | break; |
Jon Ashburn | c0db2af | 2015-03-17 13:47:55 -0600 | [diff] [blame] | 1485 | } |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1486 | } |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1487 | if (res != VK_SUCCESS) |
Jon Ashburn | 406a0fe | 2014-11-14 09:52:42 -0700 | [diff] [blame] | 1488 | break; |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1489 | } |
| 1490 | |
Jon Ashburn | c0db2af | 2015-03-17 13:47:55 -0600 | [diff] [blame] | 1491 | |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1492 | /* roll back on errors */ |
| 1493 | if (icd) { |
Jon Ashburn | c0db2af | 2015-03-17 13:47:55 -0600 | [diff] [blame] | 1494 | for (const struct loader_icd *tmp = inst->icds; tmp != icd; |
Jon Ashburn | dc67ef5 | 2015-01-29 16:44:24 -0700 | [diff] [blame] | 1495 | tmp = tmp->next) { |
Jon Ashburn | c0db2af | 2015-03-17 13:47:55 -0600 | [diff] [blame] | 1496 | for (uint32_t i = 0; i < icd->gpu_count; i++) |
| 1497 | (tmp->loader_dispatch + i)->DbgUnregisterMsgCallback(tmp->scanned_icds->instance, pfnMsgCallback); |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1498 | } |
Jon Ashburn | 406a0fe | 2014-11-14 09:52:42 -0700 | [diff] [blame] | 1499 | /* and gpus on current icd */ |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1500 | for (uint32_t i = 0; i < gpu_idx; i++) |
Courtney Goeltzenleuchter | 9d36ef4 | 2015-04-13 14:10:06 -0600 | [diff] [blame] | 1501 | (icd->loader_dispatch + i)->DbgUnregisterMsgCallback(icd->scanned_icds->instance, pfnMsgCallback); |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1502 | |
| 1503 | return res; |
| 1504 | } |
| 1505 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1506 | return VK_SUCCESS; |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1507 | } |
| 1508 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1509 | LOADER_EXPORT VkResult VKAPI vkDbgUnregisterMsgCallback(VkInstance instance, VK_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback) |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1510 | { |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1511 | VkResult res = VK_SUCCESS; |
Jon Ashburn | c0db2af | 2015-03-17 13:47:55 -0600 | [diff] [blame] | 1512 | struct loader_instance *inst; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1513 | if (instance == VK_NULL_HANDLE) |
| 1514 | return VK_ERROR_INVALID_HANDLE; |
Courtney Goeltzenleuchter | 9d36ef4 | 2015-04-13 14:10:06 -0600 | [diff] [blame] | 1515 | |
| 1516 | assert(loader.icds_scanned); |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1517 | |
Jon Ashburn | c0db2af | 2015-03-17 13:47:55 -0600 | [diff] [blame] | 1518 | for (inst = loader.instances; inst; inst = inst->next) { |
Mike Stroyan | 230e625 | 2015-04-17 12:36:38 -0600 | [diff] [blame] | 1519 | if ((VkInstance) inst == instance) |
Jon Ashburn | c0db2af | 2015-03-17 13:47:55 -0600 | [diff] [blame] | 1520 | break; |
| 1521 | } |
| 1522 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1523 | if (inst == VK_NULL_HANDLE) |
| 1524 | return VK_ERROR_INVALID_HANDLE; |
Jon Ashburn | c0db2af | 2015-03-17 13:47:55 -0600 | [diff] [blame] | 1525 | |
| 1526 | for (const struct loader_icd * icd = inst->icds; icd; icd = icd->next) { |
| 1527 | for (uint32_t i = 0; i < icd->gpu_count; i++) { |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1528 | VkResult r; |
Jon Ashburn | c0db2af | 2015-03-17 13:47:55 -0600 | [diff] [blame] | 1529 | r = (icd->loader_dispatch + i)->DbgUnregisterMsgCallback(icd->scanned_icds->instance, pfnMsgCallback); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1530 | if (r != VK_SUCCESS) { |
Jon Ashburn | c0db2af | 2015-03-17 13:47:55 -0600 | [diff] [blame] | 1531 | res = r; |
Jon Ashburn | 406a0fe | 2014-11-14 09:52:42 -0700 | [diff] [blame] | 1532 | } |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1533 | } |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1534 | } |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1535 | return res; |
| 1536 | } |
| 1537 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1538 | LOADER_EXPORT VkResult VKAPI vkDbgSetGlobalOption(VkInstance instance, VK_DBG_GLOBAL_OPTION dbgOption, size_t dataSize, const void* pData) |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1539 | { |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1540 | VkResult res = VK_SUCCESS; |
Jon Ashburn | c0db2af | 2015-03-17 13:47:55 -0600 | [diff] [blame] | 1541 | struct loader_instance *inst; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1542 | if (instance == VK_NULL_HANDLE) |
| 1543 | return VK_ERROR_INVALID_HANDLE; |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1544 | |
Courtney Goeltzenleuchter | 9d36ef4 | 2015-04-13 14:10:06 -0600 | [diff] [blame] | 1545 | assert(loader.icds_scanned); |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1546 | |
Jon Ashburn | c0db2af | 2015-03-17 13:47:55 -0600 | [diff] [blame] | 1547 | for (inst = loader.instances; inst; inst = inst->next) { |
Mike Stroyan | 230e625 | 2015-04-17 12:36:38 -0600 | [diff] [blame] | 1548 | if ((VkInstance) inst == instance) |
Jon Ashburn | c0db2af | 2015-03-17 13:47:55 -0600 | [diff] [blame] | 1549 | break; |
| 1550 | } |
| 1551 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1552 | if (inst == VK_NULL_HANDLE) |
| 1553 | return VK_ERROR_INVALID_HANDLE; |
Jon Ashburn | c0db2af | 2015-03-17 13:47:55 -0600 | [diff] [blame] | 1554 | for (const struct loader_icd * icd = inst->icds; icd; icd = icd->next) { |
| 1555 | for (uint32_t i = 0; i < icd->gpu_count; i++) { |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1556 | VkResult r; |
Jon Ashburn | c0db2af | 2015-03-17 13:47:55 -0600 | [diff] [blame] | 1557 | r = (icd->loader_dispatch + i)->DbgSetGlobalOption(icd->scanned_icds->instance, dbgOption, |
Jon Ashburn | dc67ef5 | 2015-01-29 16:44:24 -0700 | [diff] [blame] | 1558 | dataSize, pData); |
Jon Ashburn | c0db2af | 2015-03-17 13:47:55 -0600 | [diff] [blame] | 1559 | /* unfortunately we cannot roll back */ |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1560 | if (r != VK_SUCCESS) { |
Jon Ashburn | c0db2af | 2015-03-17 13:47:55 -0600 | [diff] [blame] | 1561 | res = r; |
Jon Ashburn | 406a0fe | 2014-11-14 09:52:42 -0700 | [diff] [blame] | 1562 | } |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1563 | } |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1564 | } |
| 1565 | |
| 1566 | return res; |
| 1567 | } |