Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1 | /* |
Courtney Goeltzenleuchter | d8e229c | 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 | 701f3f6 | 2014-09-02 08:32:09 +0800 | [diff] [blame] | 23 | * |
| 24 | * Authors: |
| 25 | * Chia-I Wu <olv@lunarg.com> |
Jon Ashburn | 01e2d66 | 2014-11-14 09:52:42 -0700 | [diff] [blame] | 26 | * Jon Ashburn <jon@lunarg.com> |
Chia-I Wu | 701f3f6 | 2014-09-02 08:32:09 +0800 | [diff] [blame] | 27 | * Courtney Goeltzenleuchter <courtney@lunarg.com> |
Ian Elliott | 5aa4ea2 | 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 | 6b4d70c | 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 | 13a61a5 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 37 | #include <sys/types.h> |
Ian Elliott | 2d4ab1e | 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 | 13a61a5 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 41 | #include <dirent.h> |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 42 | #endif // WIN32 |
| 43 | #include "loader_platform.h" |
Chia-I Wu | f46b81a | 2015-01-04 11:12:47 +0800 | [diff] [blame] | 44 | #include "table_ops.h" |
Chia-I Wu | 1930060 | 2014-08-04 08:03:57 +0800 | [diff] [blame] | 45 | #include "loader.h" |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 46 | #include "vkIcd.h" |
Ian Elliott | 655cad7 | 2015-02-12 17:08:34 -0700 | [diff] [blame] | 47 | // The following is #included again to catch certain OS-specific functions |
| 48 | // being used: |
| 49 | #include "loader_platform.h" |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 50 | |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 51 | struct loader_instance { |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 52 | struct loader_icd *icds; |
| 53 | struct loader_instance *next; |
Jon Ashburn | 340d666 | 2015-04-08 15:49:00 -0600 | [diff] [blame^] | 54 | uint32_t extension_count; |
| 55 | char **extension_names; |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 56 | }; |
| 57 | |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 58 | struct loader_layers { |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 59 | loader_platform_dl_handle lib_handle; |
Jon Ashburn | b835805 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 60 | char name[256]; |
| 61 | }; |
| 62 | |
| 63 | struct layer_name_pair { |
| 64 | char *layer_name; |
| 65 | const char *lib_name; |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 66 | }; |
| 67 | |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 68 | struct loader_icd { |
Jon Ashburn | 46d1f58 | 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 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 71 | VK_LAYER_DISPATCH_TABLE *loader_dispatch; |
| 72 | uint32_t layer_count[VK_MAX_PHYSICAL_GPUS]; |
| 73 | struct loader_layers layer_libs[VK_MAX_PHYSICAL_GPUS][MAX_LAYER_LIBRARIES]; |
| 74 | VK_BASE_LAYER_OBJECT *wrappedGpus[VK_MAX_PHYSICAL_GPUS]; |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 75 | uint32_t gpu_count; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 76 | VK_BASE_LAYER_OBJECT *gpus; |
Jon Ashburn | df7d584 | 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 | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 81 | |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 82 | struct loader_scanned_icds { |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 83 | loader_platform_dl_handle handle; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 84 | PFN_vkGetProcAddr GetProcAddr; |
| 85 | PFN_vkCreateInstance CreateInstance; |
| 86 | PFN_vkDestroyInstance DestroyInstance; |
| 87 | PFN_vkEnumerateGpus EnumerateGpus; |
| 88 | PFN_vkGetExtensionSupport GetExtensionSupport; |
| 89 | VkInstance instance; |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 90 | struct loader_scanned_icds *next; |
| 91 | }; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 92 | |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 93 | // Note: Since the following is a static structure, all members are initialized |
| 94 | // to zero. |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 95 | static struct { |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 96 | struct loader_instance *instances; |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 97 | bool icds_scanned; |
| 98 | struct loader_scanned_icds *scanned_icd_list; |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 99 | bool layer_scanned; |
Courtney Goeltzenleuchter | 57985ce | 2014-12-01 09:29:42 -0700 | [diff] [blame] | 100 | char *layer_dirs; |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 101 | unsigned int scanned_layer_count; |
| 102 | char *scanned_layer_names[MAX_LAYER_LIBRARIES]; |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 103 | } loader; |
| 104 | |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 105 | |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 106 | #if defined(WIN32) |
Ian Elliott | 5aa4ea2 | 2015-03-31 15:32:41 -0600 | [diff] [blame] | 107 | char *loader_get_registry_string(const HKEY hive, |
| 108 | const LPCTSTR sub_key, |
| 109 | const char *value) |
| 110 | { |
| 111 | DWORD access_flags = KEY_QUERY_VALUE; |
| 112 | DWORD value_type; |
| 113 | HKEY key; |
| 114 | LONG rtn_value; |
| 115 | char *rtn_str = NULL; |
| 116 | size_t rtn_len = 0; |
| 117 | size_t allocated_len = 0; |
| 118 | |
| 119 | rtn_value = RegOpenKeyEx(hive, sub_key, 0, access_flags, &key); |
| 120 | if (rtn_value != ERROR_SUCCESS) { |
| 121 | // We didn't find the key. Try the 32-bit hive (where we've seen the |
| 122 | // key end up on some people's systems): |
| 123 | access_flags |= KEY_WOW64_32KEY; |
| 124 | rtn_value = RegOpenKeyEx(hive, sub_key, 0, access_flags, &key); |
| 125 | if (rtn_value != ERROR_SUCCESS) { |
| 126 | // We still couldn't find the key, so give up: |
| 127 | return NULL; |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | rtn_value = RegQueryValueEx(key, value, NULL, &value_type, |
| 132 | (PVOID) rtn_str, &rtn_len); |
| 133 | if (rtn_value == ERROR_SUCCESS) { |
| 134 | // If we get to here, we found the key, and need to allocate memory |
| 135 | // large enough for rtn_str, and query again: |
| 136 | allocated_len = rtn_len + 4; |
| 137 | rtn_str = malloc(allocated_len); |
| 138 | rtn_value = RegQueryValueEx(key, value, NULL, &value_type, |
| 139 | (PVOID) rtn_str, &rtn_len); |
| 140 | if (rtn_value == ERROR_SUCCESS) { |
| 141 | // We added 4 extra bytes to rtn_str, so that we can ensure that |
| 142 | // the string is NULL-terminated (albeit, in a brute-force manner): |
| 143 | rtn_str[allocated_len-1] = '\0'; |
| 144 | } else { |
| 145 | // This should never occur, but in case it does, clean up: |
| 146 | free(rtn_str); |
| 147 | rtn_str = NULL; |
| 148 | } |
| 149 | } // else - shouldn't happen, but if it does, return rtn_str, which is NULL |
| 150 | |
| 151 | // Close the registry key that was opened: |
| 152 | RegCloseKey(key); |
| 153 | |
| 154 | return rtn_str; |
| 155 | } |
| 156 | |
| 157 | |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 158 | // For ICD developers, look in the registry, and look for an environment |
| 159 | // variable for a path(s) where to find the ICD(s): |
| 160 | static char *loader_get_registry_and_env(const char *env_var, |
| 161 | const char *registry_value) |
| 162 | { |
| 163 | char *env_str = getenv(env_var); |
| 164 | size_t env_len = (env_str == NULL) ? 0 : strlen(env_str); |
Ian Elliott | 5aa4ea2 | 2015-03-31 15:32:41 -0600 | [diff] [blame] | 165 | char *registry_str = NULL; |
| 166 | DWORD registry_len = 0; |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 167 | char *rtn_str = NULL; |
| 168 | size_t rtn_len; |
| 169 | |
Ian Elliott | 5aa4ea2 | 2015-03-31 15:32:41 -0600 | [diff] [blame] | 170 | registry_str = loader_get_registry_string(HKEY_LOCAL_MACHINE, |
Ian Elliott | 06ebd75 | 2015-04-09 18:07:15 -0600 | [diff] [blame] | 171 | "Software\\Vulkan", |
Ian Elliott | 5aa4ea2 | 2015-03-31 15:32:41 -0600 | [diff] [blame] | 172 | registry_value); |
Ian Elliott | 2de26bc | 2015-04-03 13:13:01 -0600 | [diff] [blame] | 173 | registry_len = (registry_str) ? strlen(registry_str) : 0; |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 174 | |
| 175 | rtn_len = env_len + registry_len + 1; |
| 176 | if (rtn_len <= 2) { |
| 177 | // We found neither the desired registry value, nor the environment |
| 178 | // variable; return NULL: |
| 179 | return NULL; |
| 180 | } else { |
| 181 | // We found something, and so we need to allocate memory for the string |
| 182 | // to return: |
| 183 | rtn_str = malloc(rtn_len); |
| 184 | } |
| 185 | |
Ian Elliott | 5aa4ea2 | 2015-03-31 15:32:41 -0600 | [diff] [blame] | 186 | if (registry_len == 0) { |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 187 | // We didn't find the desired registry value, and so we must have found |
| 188 | // only the environment variable: |
| 189 | _snprintf(rtn_str, rtn_len, "%s", env_str); |
| 190 | } else if (env_str != NULL) { |
| 191 | // We found both the desired registry value and the environment |
| 192 | // variable, so concatenate them both: |
| 193 | _snprintf(rtn_str, rtn_len, "%s;%s", registry_str, env_str); |
| 194 | } else { |
| 195 | // We must have only found the desired registry value: |
| 196 | _snprintf(rtn_str, rtn_len, "%s", registry_str); |
| 197 | } |
| 198 | |
Ian Elliott | 2de26bc | 2015-04-03 13:13:01 -0600 | [diff] [blame] | 199 | if (registry_str) { |
| 200 | free(registry_str); |
| 201 | } |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 202 | |
| 203 | return(rtn_str); |
| 204 | } |
| 205 | #endif // WIN32 |
| 206 | |
| 207 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 208 | 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] | 209 | const char *format, ...) |
| 210 | { |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 211 | char msg[256]; |
| 212 | va_list ap; |
| 213 | int ret; |
| 214 | |
| 215 | va_start(ap, format); |
| 216 | ret = vsnprintf(msg, sizeof(msg), format, ap); |
Ian Elliott | 4204584 | 2015-02-13 14:29:21 -0700 | [diff] [blame] | 217 | if ((ret >= (int) sizeof(msg)) || ret < 0) { |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 218 | msg[sizeof(msg) - 1] = '\0'; |
| 219 | } |
| 220 | va_end(ap); |
| 221 | |
Courtney Goeltzenleuchter | c80a557 | 2015-04-13 14:10:06 -0600 | [diff] [blame] | 222 | fputs(msg, stderr); |
| 223 | fputc('\n', stderr); |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | static void |
| 227 | loader_icd_destroy(struct loader_icd *icd) |
| 228 | { |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 229 | loader_platform_close_library(icd->scanned_icds->handle); |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 230 | free(icd); |
| 231 | } |
| 232 | |
| 233 | static struct loader_icd * |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 234 | loader_icd_create(const struct loader_scanned_icds *scanned) |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 235 | { |
| 236 | struct loader_icd *icd; |
| 237 | |
| 238 | icd = malloc(sizeof(*icd)); |
| 239 | if (!icd) |
| 240 | return NULL; |
| 241 | |
Courtney Goeltzenleuchter | 55001bb | 2014-10-28 10:29:27 -0600 | [diff] [blame] | 242 | memset(icd, 0, sizeof(*icd)); |
| 243 | |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 244 | icd->scanned_icds = scanned; |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 245 | |
| 246 | return icd; |
| 247 | } |
| 248 | |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 249 | static struct loader_icd *loader_icd_add(struct loader_instance *ptr_inst, |
| 250 | const struct loader_scanned_icds *scanned) |
Chia-I Wu | 13a61a5 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 251 | { |
| 252 | struct loader_icd *icd; |
| 253 | |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 254 | icd = loader_icd_create(scanned); |
Chia-I Wu | 13a61a5 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 255 | if (!icd) |
| 256 | return NULL; |
| 257 | |
Chia-I Wu | 13a61a5 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 258 | /* prepend to the list */ |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 259 | icd->next = ptr_inst->icds; |
| 260 | ptr_inst->icds = icd; |
Chia-I Wu | 13a61a5 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 261 | |
| 262 | return icd; |
| 263 | } |
| 264 | |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 265 | static void loader_scanned_icd_add(const char *filename) |
| 266 | { |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 267 | loader_platform_dl_handle handle; |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 268 | void *fp_gpa, *fp_enumerate, *fp_create_inst, *fp_destroy_inst, *fp_get_extension_support; |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 269 | struct loader_scanned_icds *new_node; |
| 270 | |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 271 | // Used to call: dlopen(filename, RTLD_LAZY); |
| 272 | handle = loader_platform_open_library(filename); |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 273 | if (!handle) { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 274 | loader_log(VK_DBG_MSG_WARNING, 0, loader_platform_open_library_error(filename)); |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 275 | return; |
| 276 | } |
| 277 | |
| 278 | #define LOOKUP(func_ptr, func) do { \ |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 279 | func_ptr = (PFN_vk ##func) loader_platform_get_proc_address(handle, "vk" #func); \ |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 280 | if (!func_ptr) { \ |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 281 | loader_log(VK_DBG_MSG_WARNING, 0, loader_platform_get_proc_address_error("vk" #func)); \ |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 282 | return; \ |
| 283 | } \ |
| 284 | } while (0) |
| 285 | |
| 286 | LOOKUP(fp_gpa, GetProcAddr); |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 287 | LOOKUP(fp_create_inst, CreateInstance); |
| 288 | LOOKUP(fp_destroy_inst, DestroyInstance); |
Jon Ashburn | 4c392fb | 2015-01-28 19:57:09 -0700 | [diff] [blame] | 289 | LOOKUP(fp_enumerate, EnumerateGpus); |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 290 | LOOKUP(fp_get_extension_support, GetExtensionSupport); |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 291 | #undef LOOKUP |
| 292 | |
| 293 | new_node = (struct loader_scanned_icds *) malloc(sizeof(struct loader_scanned_icds)); |
| 294 | if (!new_node) { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 295 | loader_log(VK_DBG_MSG_WARNING, 0, "Out of memory can't add icd"); |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 296 | return; |
| 297 | } |
| 298 | |
| 299 | new_node->handle = handle; |
| 300 | new_node->GetProcAddr = fp_gpa; |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 301 | new_node->CreateInstance = fp_create_inst; |
| 302 | new_node->DestroyInstance = fp_destroy_inst; |
Jon Ashburn | 4c392fb | 2015-01-28 19:57:09 -0700 | [diff] [blame] | 303 | new_node->EnumerateGpus = fp_enumerate; |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 304 | new_node->GetExtensionSupport = fp_get_extension_support; |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 305 | new_node->next = loader.scanned_icd_list; |
| 306 | loader.scanned_icd_list = new_node; |
| 307 | } |
| 308 | |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 309 | |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 310 | /** |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 311 | * Try to \c loader_icd_scan VK driver(s). |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 312 | * |
| 313 | * This function scans the default system path or path |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 314 | * specified by the \c LIBVK_DRIVERS_PATH environment variable in |
| 315 | * order to find loadable VK ICDs with the name of libVK_*. |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 316 | * |
| 317 | * \returns |
| 318 | * void; but side effect is to set loader_icd_scanned to true |
| 319 | */ |
| 320 | static void loader_icd_scan(void) |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 321 | { |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 322 | const char *p, *next; |
| 323 | char *libPaths = NULL; |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 324 | DIR *sysdir; |
| 325 | struct dirent *dent; |
| 326 | char icd_library[1024]; |
Jon Ashburn | 5cda59c | 2014-10-03 16:31:35 -0600 | [diff] [blame] | 327 | char path[1024]; |
Ian Elliott | 1962880 | 2015-02-04 12:06:46 -0700 | [diff] [blame] | 328 | uint32_t len; |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 329 | #if defined(WIN32) |
| 330 | bool must_free_libPaths; |
| 331 | libPaths = loader_get_registry_and_env(DRIVER_PATH_ENV, |
| 332 | DRIVER_PATH_REGISTRY_VALUE); |
| 333 | if (libPaths != NULL) { |
| 334 | must_free_libPaths = true; |
| 335 | } else { |
| 336 | must_free_libPaths = false; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 337 | libPaths = DEFAULT_VK_DRIVERS_PATH; |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 338 | } |
| 339 | #else // WIN32 |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 340 | if (geteuid() == getuid()) { |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 341 | /* Don't allow setuid apps to use the DRIVER_PATH_ENV env var: */ |
| 342 | libPaths = getenv(DRIVER_PATH_ENV); |
| 343 | } |
| 344 | if (libPaths == NULL) { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 345 | libPaths = DEFAULT_VK_DRIVERS_PATH; |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 346 | } |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 347 | #endif // WIN32 |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 348 | |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 349 | for (p = libPaths; *p; p = next) { |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 350 | next = strchr(p, PATH_SEPERATOR); |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 351 | if (next == NULL) { |
Ian Elliott | 1962880 | 2015-02-04 12:06:46 -0700 | [diff] [blame] | 352 | len = (uint32_t) strlen(p); |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 353 | next = p + len; |
| 354 | } |
| 355 | else { |
Ian Elliott | 1962880 | 2015-02-04 12:06:46 -0700 | [diff] [blame] | 356 | len = (uint32_t) (next - p); |
Jon Ashburn | 5cda59c | 2014-10-03 16:31:35 -0600 | [diff] [blame] | 357 | sprintf(path, "%.*s", (len > sizeof(path) - 1) ? (int) sizeof(path) - 1 : len, p); |
| 358 | p = path; |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 359 | next++; |
| 360 | } |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 361 | |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 362 | // TODO/TBD: Do we want to do this on Windows, or just let Windows take |
| 363 | // care of its own search path (which it apparently has)? |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 364 | sysdir = opendir(p); |
| 365 | if (sysdir) { |
| 366 | dent = readdir(sysdir); |
| 367 | while (dent) { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 368 | /* Look for ICDs starting with VK_DRIVER_LIBRARY_PREFIX and |
| 369 | * ending with VK_LIBRARY_SUFFIX |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 370 | */ |
| 371 | if (!strncmp(dent->d_name, |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 372 | VK_DRIVER_LIBRARY_PREFIX, |
| 373 | VK_DRIVER_LIBRARY_PREFIX_LEN)) { |
Ian Elliott | 1962880 | 2015-02-04 12:06:46 -0700 | [diff] [blame] | 374 | uint32_t nlen = (uint32_t) strlen(dent->d_name); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 375 | const char *suf = dent->d_name + nlen - VK_LIBRARY_SUFFIX_LEN; |
| 376 | if ((nlen > VK_LIBRARY_SUFFIX_LEN) && |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 377 | !strncmp(suf, |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 378 | VK_LIBRARY_SUFFIX, |
| 379 | VK_LIBRARY_SUFFIX_LEN)) { |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 380 | snprintf(icd_library, 1024, "%s" DIRECTORY_SYMBOL "%s", p,dent->d_name); |
| 381 | loader_scanned_icd_add(icd_library); |
| 382 | } |
| 383 | } |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 384 | |
| 385 | dent = readdir(sysdir); |
| 386 | } |
| 387 | closedir(sysdir); |
| 388 | } |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 389 | } |
| 390 | |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 391 | #if defined(WIN32) |
| 392 | // Free any allocated memory: |
| 393 | if (must_free_libPaths) { |
| 394 | free(libPaths); |
| 395 | } |
| 396 | #endif // WIN32 |
| 397 | |
| 398 | // Note that we've scanned for ICDs: |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 399 | loader.icds_scanned = true; |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 400 | } |
| 401 | |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 402 | |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 403 | static void layer_lib_scan(void) |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 404 | { |
| 405 | const char *p, *next; |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 406 | char *libPaths = NULL; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 407 | DIR *curdir; |
| 408 | struct dirent *dent; |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 409 | size_t len, i; |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 410 | char temp_str[1024]; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 411 | |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 412 | #if defined(WIN32) |
| 413 | bool must_free_libPaths; |
| 414 | libPaths = loader_get_registry_and_env(LAYERS_PATH_ENV, |
| 415 | LAYERS_PATH_REGISTRY_VALUE); |
| 416 | if (libPaths != NULL) { |
| 417 | must_free_libPaths = true; |
| 418 | } else { |
| 419 | must_free_libPaths = false; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 420 | libPaths = DEFAULT_VK_LAYERS_PATH; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 421 | } |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 422 | #else // WIN32 |
| 423 | if (geteuid() == getuid()) { |
| 424 | /* Don't allow setuid apps to use the DRIVER_PATH_ENV env var: */ |
Courtney Goeltzenleuchter | 66b72f9 | 2015-02-18 20:03:02 -0700 | [diff] [blame] | 425 | libPaths = getenv(LAYERS_PATH_ENV); |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 426 | } |
| 427 | if (libPaths == NULL) { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 428 | libPaths = DEFAULT_VK_LAYERS_PATH; |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 429 | } |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 430 | #endif // WIN32 |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 431 | |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 432 | if (libPaths == NULL) { |
| 433 | // Have no paths to search: |
Courtney Goeltzenleuchter | 57985ce | 2014-12-01 09:29:42 -0700 | [diff] [blame] | 434 | return; |
| 435 | } |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 436 | len = strlen(libPaths); |
Courtney Goeltzenleuchter | 57985ce | 2014-12-01 09:29:42 -0700 | [diff] [blame] | 437 | loader.layer_dirs = malloc(len+1); |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 438 | if (loader.layer_dirs == NULL) { |
| 439 | free(libPaths); |
Courtney Goeltzenleuchter | a66265b | 2014-12-02 18:12:51 -0700 | [diff] [blame] | 440 | return; |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 441 | } |
| 442 | // Alloc passed, so we know there is enough space to hold the string, don't |
| 443 | // need strncpy |
| 444 | strcpy(loader.layer_dirs, libPaths); |
| 445 | #if defined(WIN32) |
| 446 | // Free any allocated memory: |
| 447 | if (must_free_libPaths) { |
| 448 | free(libPaths); |
| 449 | must_free_libPaths = false; |
| 450 | } |
| 451 | #endif // WIN32 |
Courtney Goeltzenleuchter | 57985ce | 2014-12-01 09:29:42 -0700 | [diff] [blame] | 452 | libPaths = loader.layer_dirs; |
| 453 | |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 454 | /* cleanup any previously scanned libraries */ |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 455 | for (i = 0; i < loader.scanned_layer_count; i++) { |
| 456 | if (loader.scanned_layer_names[i] != NULL) |
| 457 | free(loader.scanned_layer_names[i]); |
| 458 | loader.scanned_layer_names[i] = NULL; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 459 | } |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 460 | loader.scanned_layer_count = 0; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 461 | |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 462 | for (p = libPaths; *p; p = next) { |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 463 | next = strchr(p, PATH_SEPERATOR); |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 464 | if (next == NULL) { |
Ian Elliott | 1962880 | 2015-02-04 12:06:46 -0700 | [diff] [blame] | 465 | len = (uint32_t) strlen(p); |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 466 | next = p + len; |
| 467 | } |
| 468 | else { |
Ian Elliott | 1962880 | 2015-02-04 12:06:46 -0700 | [diff] [blame] | 469 | len = (uint32_t) (next - p); |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 470 | *(char *) next = '\0'; |
| 471 | next++; |
| 472 | } |
| 473 | |
| 474 | curdir = opendir(p); |
| 475 | if (curdir) { |
| 476 | dent = readdir(curdir); |
| 477 | while (dent) { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 478 | /* Look for layers starting with VK_LAYER_LIBRARY_PREFIX and |
| 479 | * ending with VK_LIBRARY_SUFFIX |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 480 | */ |
| 481 | if (!strncmp(dent->d_name, |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 482 | VK_LAYER_LIBRARY_PREFIX, |
| 483 | VK_LAYER_LIBRARY_PREFIX_LEN)) { |
Ian Elliott | 1962880 | 2015-02-04 12:06:46 -0700 | [diff] [blame] | 484 | uint32_t nlen = (uint32_t) strlen(dent->d_name); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 485 | const char *suf = dent->d_name + nlen - VK_LIBRARY_SUFFIX_LEN; |
| 486 | if ((nlen > VK_LIBRARY_SUFFIX_LEN) && |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 487 | !strncmp(suf, |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 488 | VK_LIBRARY_SUFFIX, |
| 489 | VK_LIBRARY_SUFFIX_LEN)) { |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 490 | loader_platform_dl_handle handle; |
| 491 | snprintf(temp_str, sizeof(temp_str), "%s" DIRECTORY_SYMBOL "%s",p,dent->d_name); |
| 492 | // Used to call: dlopen(temp_str, RTLD_LAZY) |
| 493 | if ((handle = loader_platform_open_library(temp_str)) == NULL) { |
| 494 | dent = readdir(curdir); |
| 495 | continue; |
| 496 | } |
| 497 | if (loader.scanned_layer_count == MAX_LAYER_LIBRARIES) { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 498 | loader_log(VK_DBG_MSG_ERROR, 0, "%s ignored: max layer libraries exceed", temp_str); |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 499 | break; |
| 500 | } |
| 501 | if ((loader.scanned_layer_names[loader.scanned_layer_count] = malloc(strlen(temp_str) + 1)) == NULL) { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 502 | loader_log(VK_DBG_MSG_ERROR, 0, "%s ignored: out of memory", temp_str); |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 503 | break; |
| 504 | } |
| 505 | strcpy(loader.scanned_layer_names[loader.scanned_layer_count], temp_str); |
| 506 | loader.scanned_layer_count++; |
| 507 | loader_platform_close_library(handle); |
| 508 | } |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 509 | } |
| 510 | |
| 511 | dent = readdir(curdir); |
| 512 | } |
| 513 | closedir(curdir); |
| 514 | } |
| 515 | } |
| 516 | |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 517 | loader.layer_scanned = true; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 518 | } |
| 519 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 520 | static void loader_init_dispatch_table(VK_LAYER_DISPATCH_TABLE *tab, PFN_vkGetProcAddr fpGPA, VkPhysicalGpu gpu) |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 521 | { |
Chia-I Wu | f46b81a | 2015-01-04 11:12:47 +0800 | [diff] [blame] | 522 | loader_initialize_dispatch_table(tab, fpGPA, gpu); |
| 523 | |
Jon Ashburn | f7bcf9b | 2014-10-15 15:30:23 -0600 | [diff] [blame] | 524 | if (tab->EnumerateLayers == NULL) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 525 | tab->EnumerateLayers = vkEnumerateLayers; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 526 | } |
| 527 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 528 | static struct loader_icd * loader_get_icd(const VK_BASE_LAYER_OBJECT *gpu, uint32_t *gpu_index) |
Jon Ashburn | 876b1ac | 2014-10-17 15:09:07 -0600 | [diff] [blame] | 529 | { |
Jon Ashburn | 98bd454 | 2015-01-29 16:44:24 -0700 | [diff] [blame] | 530 | for (struct loader_instance *inst = loader.instances; inst; inst = inst->next) { |
| 531 | for (struct loader_icd *icd = inst->icds; icd; icd = icd->next) { |
| 532 | for (uint32_t i = 0; i < icd->gpu_count; i++) |
| 533 | if ((icd->gpus + i) == gpu || (icd->gpus +i)->baseObject == |
| 534 | gpu->baseObject) { |
| 535 | *gpu_index = i; |
| 536 | return icd; |
| 537 | } |
| 538 | } |
Jon Ashburn | 876b1ac | 2014-10-17 15:09:07 -0600 | [diff] [blame] | 539 | } |
| 540 | return NULL; |
| 541 | } |
| 542 | |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 543 | static bool loader_layers_activated(const struct loader_icd *icd, const uint32_t gpu_index) |
Jon Ashburn | 876b1ac | 2014-10-17 15:09:07 -0600 | [diff] [blame] | 544 | { |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 545 | if (icd->layer_count[gpu_index]) |
| 546 | return true; |
| 547 | else |
| 548 | return false; |
Jon Ashburn | 876b1ac | 2014-10-17 15:09:07 -0600 | [diff] [blame] | 549 | } |
| 550 | |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 551 | static void loader_init_layer_libs(struct loader_icd *icd, uint32_t gpu_index, struct layer_name_pair * pLayerNames, uint32_t count) |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 552 | { |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 553 | if (!icd) |
| 554 | return; |
Jon Ashburn | df7d584 | 2014-10-16 15:48:50 -0600 | [diff] [blame] | 555 | |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 556 | struct loader_layers *obj; |
| 557 | bool foundLib; |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 558 | for (uint32_t i = 0; i < count; i++) { |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 559 | foundLib = false; |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 560 | for (uint32_t j = 0; j < icd->layer_count[gpu_index]; j++) { |
Jon Ashburn | b835805 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 561 | if (icd->layer_libs[gpu_index][j].lib_handle && !strcmp(icd->layer_libs[gpu_index][j].name, (char *) pLayerNames[i].layer_name)) { |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 562 | foundLib = true; |
| 563 | break; |
| 564 | } |
| 565 | } |
| 566 | if (!foundLib) { |
| 567 | obj = &(icd->layer_libs[gpu_index][i]); |
Jon Ashburn | b835805 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 568 | strncpy(obj->name, (char *) pLayerNames[i].layer_name, sizeof(obj->name) - 1); |
| 569 | obj->name[sizeof(obj->name) - 1] = '\0'; |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 570 | // Used to call: dlopen(pLayerNames[i].lib_name, RTLD_LAZY | RTLD_DEEPBIND) |
| 571 | if ((obj->lib_handle = loader_platform_open_library(pLayerNames[i].lib_name)) == NULL) { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 572 | loader_log(VK_DBG_MSG_ERROR, 0, loader_platform_open_library_error(pLayerNames[i].lib_name)); |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 573 | continue; |
| 574 | } else { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 575 | loader_log(VK_DBG_MSG_UNKNOWN, 0, "Inserting layer %s from library %s", pLayerNames[i].layer_name, pLayerNames[i].lib_name); |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 576 | } |
Jon Ashburn | b835805 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 577 | free(pLayerNames[i].layer_name); |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 578 | icd->layer_count[gpu_index]++; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 579 | } |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 580 | } |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 581 | } |
| 582 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 583 | static VkResult find_layer_extension(struct loader_icd *icd, uint32_t gpu_index, const char *pExtName, const char **lib_name) |
Jon Ashburn | b835805 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 584 | { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 585 | VkResult err; |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 586 | char *search_name; |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 587 | loader_platform_dl_handle handle; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 588 | PFN_vkGetExtensionSupport fpGetExtensionSupport; |
Jon Ashburn | b835805 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 589 | |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 590 | /* |
| 591 | * The loader provides the abstraction that make layers and extensions work via |
| 592 | * the currently defined extension mechanism. That is, when app queries for an extension |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 593 | * via vkGetExtensionSupport, the loader will call both the driver as well as any layers |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 594 | * to see who implements that extension. Then, if the app enables the extension during |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 595 | * vkCreateDevice the loader will find and load any layers that implement that extension. |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 596 | */ |
Jon Ashburn | b835805 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 597 | |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 598 | // TODO: What if extension is in multiple places? |
| 599 | |
| 600 | // TODO: Who should we ask first? Driver or layers? Do driver for now. |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 601 | err = icd->scanned_icds[gpu_index].GetExtensionSupport((VkPhysicalGpu) (icd->gpus[gpu_index].nextObject), pExtName); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 602 | if (err == VK_SUCCESS) { |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 603 | if (lib_name) { |
| 604 | *lib_name = NULL; |
Jon Ashburn | b835805 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 605 | } |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 606 | return VK_SUCCESS; |
Jon Ashburn | b835805 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 607 | } |
| 608 | |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 609 | for (unsigned int j = 0; j < loader.scanned_layer_count; j++) { |
| 610 | search_name = loader.scanned_layer_names[j]; |
| 611 | |
| 612 | if ((handle = loader_platform_open_library(search_name)) == NULL) |
| 613 | continue; |
| 614 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 615 | fpGetExtensionSupport = loader_platform_get_proc_address(handle, "vkGetExtensionSupport"); |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 616 | |
| 617 | if (fpGetExtensionSupport != NULL) { |
| 618 | // Found layer's GetExtensionSupport call |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 619 | err = fpGetExtensionSupport((VkPhysicalGpu) (icd->gpus + gpu_index), pExtName); |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 620 | |
| 621 | loader_platform_close_library(handle); |
| 622 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 623 | if (err == VK_SUCCESS) { |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 624 | if (lib_name) { |
| 625 | *lib_name = loader.scanned_layer_names[j]; |
| 626 | } |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 627 | return VK_SUCCESS; |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 628 | } |
| 629 | } else { |
| 630 | loader_platform_close_library(handle); |
| 631 | } |
| 632 | |
| 633 | // No GetExtensionSupport or GetExtensionSupport returned invalid extension |
| 634 | // for the layer, so test the layer name as if it is an extension name |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 635 | // use default layer name based on library name VK_LAYER_LIBRARY_PREFIX<name>.VK_LIBRARY_SUFFIX |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 636 | char *pEnd; |
| 637 | size_t siz; |
| 638 | |
| 639 | search_name = basename(search_name); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 640 | search_name += strlen(VK_LAYER_LIBRARY_PREFIX); |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 641 | pEnd = strrchr(search_name, '.'); |
| 642 | siz = (int) (pEnd - search_name); |
| 643 | if (siz != strlen(pExtName)) |
| 644 | continue; |
| 645 | |
| 646 | if (strncmp(search_name, pExtName, siz) == 0) { |
| 647 | if (lib_name) { |
| 648 | *lib_name = loader.scanned_layer_names[j]; |
| 649 | } |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 650 | return VK_SUCCESS; |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 651 | } |
| 652 | } |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 653 | return VK_ERROR_INVALID_EXTENSION; |
Jon Ashburn | b835805 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 654 | } |
| 655 | |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 656 | static uint32_t loader_get_layer_env(struct loader_icd *icd, uint32_t gpu_index, struct layer_name_pair *pLayerNames) |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 657 | { |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 658 | char *layerEnv; |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 659 | uint32_t len, count = 0; |
Jon Ashburn | d09bd10 | 2014-10-22 21:15:26 -0600 | [diff] [blame] | 660 | char *p, *pOrig, *next, *name; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 661 | |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 662 | #if defined(WIN32) |
| 663 | layerEnv = loader_get_registry_and_env(LAYER_NAMES_ENV, |
| 664 | LAYER_NAMES_REGISTRY_VALUE); |
| 665 | #else // WIN32 |
| 666 | layerEnv = getenv(LAYER_NAMES_ENV); |
| 667 | #endif // WIN32 |
| 668 | if (layerEnv == NULL) { |
Jon Ashburn | 3fb5544 | 2014-10-23 10:29:09 -0600 | [diff] [blame] | 669 | return 0; |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 670 | } |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 671 | p = malloc(strlen(layerEnv) + 1); |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 672 | if (p == NULL) { |
| 673 | #if defined(WIN32) |
| 674 | free(layerEnv); |
| 675 | #endif // WIN32 |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 676 | return 0; |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 677 | } |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 678 | strcpy(p, layerEnv); |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 679 | #if defined(WIN32) |
| 680 | free(layerEnv); |
| 681 | #endif // WIN32 |
Jon Ashburn | d09bd10 | 2014-10-22 21:15:26 -0600 | [diff] [blame] | 682 | pOrig = p; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 683 | |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 684 | while (p && *p && count < MAX_LAYER_LIBRARIES) { |
Jon Ashburn | b835805 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 685 | const char *lib_name = NULL; |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 686 | next = strchr(p, PATH_SEPERATOR); |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 687 | if (next == NULL) { |
Ian Elliott | 1962880 | 2015-02-04 12:06:46 -0700 | [diff] [blame] | 688 | len = (uint32_t) strlen(p); |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 689 | next = p + len; |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 690 | } else { |
Ian Elliott | 1962880 | 2015-02-04 12:06:46 -0700 | [diff] [blame] | 691 | len = (uint32_t) (next - p); |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 692 | *(char *) next = '\0'; |
| 693 | next++; |
| 694 | } |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 695 | name = basename(p); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 696 | if (find_layer_extension(icd, gpu_index, name, &lib_name) != VK_SUCCESS) { |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 697 | p = next; |
| 698 | continue; |
| 699 | } |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 700 | |
Ian Elliott | 1962880 | 2015-02-04 12:06:46 -0700 | [diff] [blame] | 701 | len = (uint32_t) strlen(name); |
Jon Ashburn | b835805 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 702 | pLayerNames[count].layer_name = malloc(len + 1); |
| 703 | if (!pLayerNames[count].layer_name) { |
Jon Ashburn | d09bd10 | 2014-10-22 21:15:26 -0600 | [diff] [blame] | 704 | free(pOrig); |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 705 | return count; |
Jon Ashburn | d09bd10 | 2014-10-22 21:15:26 -0600 | [diff] [blame] | 706 | } |
Jon Ashburn | b835805 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 707 | strncpy((char *) pLayerNames[count].layer_name, name, len); |
| 708 | pLayerNames[count].layer_name[len] = '\0'; |
| 709 | pLayerNames[count].lib_name = lib_name; |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 710 | count++; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 711 | p = next; |
| 712 | |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 713 | } |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 714 | |
Jon Ashburn | d09bd10 | 2014-10-22 21:15:26 -0600 | [diff] [blame] | 715 | free(pOrig); |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 716 | return count; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 717 | } |
| 718 | |
Courtney Goeltzenleuchter | 95487bc | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 719 | static uint32_t loader_get_layer_libs(struct loader_icd *icd, uint32_t gpu_index, const VkDeviceCreateInfo* pCreateInfo, struct layer_name_pair **ppLayerNames) |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 720 | { |
Jon Ashburn | b835805 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 721 | static struct layer_name_pair layerNames[MAX_LAYER_LIBRARIES]; |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 722 | const char *lib_name = NULL; |
| 723 | uint32_t count = 0; |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 724 | |
| 725 | *ppLayerNames = &layerNames[0]; |
Courtney Goeltzenleuchter | 89ba928 | 2015-02-17 14:21:21 -0700 | [diff] [blame] | 726 | /* Load any layers specified in the environment first */ |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 727 | count = loader_get_layer_env(icd, gpu_index, layerNames); |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 728 | |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 729 | for (uint32_t i = 0; i < pCreateInfo->extensionCount; i++) { |
| 730 | const char *pExtName = pCreateInfo->ppEnabledExtensionNames[i]; |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 731 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 732 | if (find_layer_extension(icd, gpu_index, pExtName, &lib_name) == VK_SUCCESS) { |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 733 | uint32_t len; |
| 734 | |
| 735 | /* |
| 736 | * the library name is NULL if the driver supports this |
| 737 | * extension and thus no layer to load. |
| 738 | */ |
| 739 | if (lib_name == NULL) |
| 740 | continue; |
| 741 | |
| 742 | len = (uint32_t) strlen(pExtName); |
| 743 | for (uint32_t j = 0; j < count; j++) { |
| 744 | if (len == strlen(layerNames[j].layer_name) && |
| 745 | strncmp(pExtName, layerNames[j].layer_name, len) == 0) { |
| 746 | // Extension / Layer already on the list |
| 747 | continue; |
Jon Ashburn | c0e8601 | 2015-02-18 11:29:58 -0700 | [diff] [blame] | 748 | } |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 749 | } |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 750 | |
| 751 | layerNames[count].layer_name = malloc(len + 1); |
| 752 | if (!layerNames[count].layer_name) |
| 753 | return count; |
| 754 | strncpy((char *) layerNames[count].layer_name, pExtName, len); |
| 755 | layerNames[count].layer_name[len] = '\0'; |
| 756 | layerNames[count].lib_name = lib_name; |
| 757 | count++; |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 758 | } |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 759 | } |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 760 | |
| 761 | return count; |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 762 | } |
| 763 | |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 764 | static void loader_deactivate_layer(const struct loader_instance *instance) |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 765 | { |
| 766 | struct loader_icd *icd; |
| 767 | struct loader_layers *libs; |
| 768 | |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 769 | for (icd = instance->icds; icd; icd = icd->next) { |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 770 | if (icd->gpus) |
| 771 | free(icd->gpus); |
| 772 | icd->gpus = NULL; |
| 773 | if (icd->loader_dispatch) |
| 774 | free(icd->loader_dispatch); |
| 775 | icd->loader_dispatch = NULL; |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 776 | for (uint32_t j = 0; j < icd->gpu_count; j++) { |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 777 | if (icd->layer_count[j] > 0) { |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 778 | for (uint32_t i = 0; i < icd->layer_count[j]; i++) { |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 779 | libs = &(icd->layer_libs[j][i]); |
| 780 | if (libs->lib_handle) |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 781 | loader_platform_close_library(libs->lib_handle); |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 782 | libs->lib_handle = NULL; |
| 783 | } |
Jon Ashburn | d09bd10 | 2014-10-22 21:15:26 -0600 | [diff] [blame] | 784 | if (icd->wrappedGpus[j]) |
| 785 | free(icd->wrappedGpus[j]); |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 786 | } |
| 787 | icd->layer_count[j] = 0; |
| 788 | } |
| 789 | icd->gpu_count = 0; |
| 790 | } |
| 791 | } |
| 792 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 793 | extern uint32_t loader_activate_layers(VkPhysicalGpu gpu, const VkDeviceCreateInfo* pCreateInfo) |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 794 | { |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 795 | uint32_t gpu_index; |
| 796 | uint32_t count; |
Jon Ashburn | b835805 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 797 | struct layer_name_pair *pLayerNames; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 798 | struct loader_icd *icd = loader_get_icd((const VK_BASE_LAYER_OBJECT *) gpu, &gpu_index); |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 799 | |
| 800 | if (!icd) |
| 801 | return 0; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 802 | assert(gpu_index < VK_MAX_PHYSICAL_GPUS); |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 803 | |
| 804 | /* activate any layer libraries */ |
| 805 | if (!loader_layers_activated(icd, gpu_index)) { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 806 | VK_BASE_LAYER_OBJECT *gpuObj = (VK_BASE_LAYER_OBJECT *) gpu; |
| 807 | VK_BASE_LAYER_OBJECT *nextGpuObj, *baseObj = gpuObj->baseObject; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 808 | PFN_vkGetProcAddr nextGPA = vkGetProcAddr; |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 809 | |
Jon Ashburn | b835805 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 810 | count = loader_get_layer_libs(icd, gpu_index, pCreateInfo, &pLayerNames); |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 811 | if (!count) |
| 812 | return 0; |
Jon Ashburn | b835805 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 813 | loader_init_layer_libs(icd, gpu_index, pLayerNames, count); |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 814 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 815 | icd->wrappedGpus[gpu_index] = malloc(sizeof(VK_BASE_LAYER_OBJECT) * icd->layer_count[gpu_index]); |
Jon Ashburn | d09bd10 | 2014-10-22 21:15:26 -0600 | [diff] [blame] | 816 | if (! icd->wrappedGpus[gpu_index]) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 817 | loader_log(VK_DBG_MSG_ERROR, 0, "Failed to malloc Gpu objects for layer"); |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 818 | for (int32_t i = icd->layer_count[gpu_index] - 1; i >= 0; i--) { |
Jon Ashburn | d09bd10 | 2014-10-22 21:15:26 -0600 | [diff] [blame] | 819 | nextGpuObj = (icd->wrappedGpus[gpu_index] + i); |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 820 | nextGpuObj->pGPA = nextGPA; |
Jon Ashburn | f261001 | 2014-10-24 15:48:55 -0600 | [diff] [blame] | 821 | nextGpuObj->baseObject = baseObj; |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 822 | nextGpuObj->nextObject = gpuObj; |
| 823 | gpuObj = nextGpuObj; |
| 824 | |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 825 | char funcStr[256]; |
| 826 | snprintf(funcStr, 256, "%sGetProcAddr",icd->layer_libs[gpu_index][i].name); |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 827 | if ((nextGPA = (PFN_vkGetProcAddr) loader_platform_get_proc_address(icd->layer_libs[gpu_index][i].lib_handle, funcStr)) == NULL) |
| 828 | nextGPA = (PFN_vkGetProcAddr) loader_platform_get_proc_address(icd->layer_libs[gpu_index][i].lib_handle, "vkGetProcAddr"); |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 829 | if (!nextGPA) { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 830 | loader_log(VK_DBG_MSG_ERROR, 0, "Failed to find vkGetProcAddr in layer %s", icd->layer_libs[gpu_index][i].name); |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 831 | continue; |
| 832 | } |
| 833 | |
Jon Ashburn | f261001 | 2014-10-24 15:48:55 -0600 | [diff] [blame] | 834 | if (i == 0) { |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 835 | loader_init_dispatch_table(icd->loader_dispatch + gpu_index, nextGPA, gpuObj); |
Jon Ashburn | f261001 | 2014-10-24 15:48:55 -0600 | [diff] [blame] | 836 | //Insert the new wrapped objects into the list with loader object at head |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 837 | ((VK_BASE_LAYER_OBJECT *) gpu)->nextObject = gpuObj; |
| 838 | ((VK_BASE_LAYER_OBJECT *) gpu)->pGPA = nextGPA; |
Jon Ashburn | f261001 | 2014-10-24 15:48:55 -0600 | [diff] [blame] | 839 | gpuObj = icd->wrappedGpus[gpu_index] + icd->layer_count[gpu_index] - 1; |
| 840 | gpuObj->nextObject = baseObj; |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 841 | gpuObj->pGPA = icd->scanned_icds->GetProcAddr; |
Jon Ashburn | f261001 | 2014-10-24 15:48:55 -0600 | [diff] [blame] | 842 | } |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 843 | |
| 844 | } |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 845 | } |
| 846 | else { |
| 847 | //make sure requested Layers matches currently activated Layers |
Jon Ashburn | b835805 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 848 | count = loader_get_layer_libs(icd, gpu_index, pCreateInfo, &pLayerNames); |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 849 | for (uint32_t i = 0; i < count; i++) { |
Jon Ashburn | b835805 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 850 | if (strcmp(icd->layer_libs[gpu_index][i].name, pLayerNames[i].layer_name)) { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 851 | loader_log(VK_DBG_MSG_ERROR, 0, "Layers activated != Layers requested"); |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 852 | break; |
| 853 | } |
| 854 | } |
| 855 | if (count != icd->layer_count[gpu_index]) { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 856 | loader_log(VK_DBG_MSG_ERROR, 0, "Number of Layers activated != number requested"); |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 857 | } |
| 858 | } |
| 859 | return icd->layer_count[gpu_index]; |
| 860 | } |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 861 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 862 | LOADER_EXPORT VkResult VKAPI vkCreateInstance( |
Courtney Goeltzenleuchter | 95487bc | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 863 | const VkInstanceCreateInfo* pCreateInfo, |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 864 | VkInstance* pInstance) |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 865 | { |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 866 | static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(once_icd); |
| 867 | static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(once_layer); |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 868 | struct loader_instance *ptr_instance = NULL; |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 869 | struct loader_scanned_icds *scanned_icds; |
| 870 | struct loader_icd *icd; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 871 | VkResult res = VK_ERROR_INITIALIZATION_FAILED; |
Jon Ashburn | 340d666 | 2015-04-08 15:49:00 -0600 | [diff] [blame^] | 872 | uint32_t i; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 873 | |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 874 | /* Scan/discover all ICD libraries in a single-threaded manner */ |
| 875 | loader_platform_thread_once(&once_icd, loader_icd_scan); |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 876 | |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 877 | /* get layer libraries in a single-threaded manner */ |
| 878 | loader_platform_thread_once(&once_layer, layer_lib_scan); |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 879 | |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 880 | ptr_instance = (struct loader_instance*) malloc(sizeof(struct loader_instance)); |
| 881 | if (ptr_instance == NULL) { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 882 | return VK_ERROR_OUT_OF_MEMORY; |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 883 | } |
| 884 | memset(ptr_instance, 0, sizeof(struct loader_instance)); |
Jon Ashburn | 340d666 | 2015-04-08 15:49:00 -0600 | [diff] [blame^] | 885 | ptr_instance->extension_count = pCreateInfo->extensionCount; |
| 886 | ptr_instance->extension_names = (ptr_instance->extension_count > 0) ? |
| 887 | malloc(sizeof (char *) * ptr_instance->extension_count) : NULL; |
| 888 | for (i = 0; i < ptr_instance->extension_count; i++) { |
| 889 | ptr_instance->extension_names[i] = malloc(strlen(pCreateInfo->ppEnabledExtensionNames[i] + 1)); |
| 890 | if (ptr_instance->extension_names[i] == NULL) |
| 891 | return VK_ERROR_OUT_OF_MEMORY; |
| 892 | strcpy(ptr_instance->extension_names[i], pCreateInfo->ppEnabledExtensionNames[i]); |
| 893 | } |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 894 | ptr_instance->next = loader.instances; |
| 895 | loader.instances = ptr_instance; |
| 896 | |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 897 | scanned_icds = loader.scanned_icd_list; |
| 898 | while (scanned_icds) { |
| 899 | icd = loader_icd_add(ptr_instance, scanned_icds); |
| 900 | if (icd) { |
Jon Ashburn | b317fad | 2015-04-04 14:52:07 -0600 | [diff] [blame] | 901 | res = scanned_icds->CreateInstance(pCreateInfo, |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 902 | &(scanned_icds->instance)); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 903 | if (res != VK_SUCCESS) |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 904 | { |
| 905 | ptr_instance->icds = ptr_instance->icds->next; |
| 906 | loader_icd_destroy(icd); |
| 907 | scanned_icds->instance = NULL; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 908 | loader_log(VK_DBG_MSG_WARNING, 0, |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 909 | "ICD ignored: failed to CreateInstance on device"); |
| 910 | } |
| 911 | } |
| 912 | scanned_icds = scanned_icds->next; |
| 913 | } |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 914 | |
Ian Elliott | eb45076 | 2015-02-05 15:19:15 -0700 | [diff] [blame] | 915 | if (ptr_instance->icds == NULL) { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 916 | return VK_ERROR_INCOMPATIBLE_DRIVER; |
Ian Elliott | eb45076 | 2015-02-05 15:19:15 -0700 | [diff] [blame] | 917 | } |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 918 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 919 | *pInstance = (VkInstance) ptr_instance; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 920 | return VK_SUCCESS; |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 921 | } |
| 922 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 923 | LOADER_EXPORT VkResult VKAPI vkDestroyInstance( |
| 924 | VkInstance instance) |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 925 | { |
| 926 | struct loader_instance *ptr_instance = (struct loader_instance *) instance; |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 927 | struct loader_scanned_icds *scanned_icds; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 928 | VkResult res; |
Jon Ashburn | 340d666 | 2015-04-08 15:49:00 -0600 | [diff] [blame^] | 929 | uint32_t i; |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 930 | |
| 931 | // Remove this instance from the list of instances: |
| 932 | struct loader_instance *prev = NULL; |
| 933 | struct loader_instance *next = loader.instances; |
| 934 | while (next != NULL) { |
| 935 | if (next == ptr_instance) { |
| 936 | // Remove this instance from the list: |
Jon Ashburn | 340d666 | 2015-04-08 15:49:00 -0600 | [diff] [blame^] | 937 | for (i = 0; i < ptr_instance->extension_count; i++) { |
| 938 | free(ptr_instance->extension_names[i]); |
| 939 | } |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 940 | if (prev) |
| 941 | prev->next = next->next; |
Jon Ashburn | c5c4960 | 2015-02-03 09:26:59 -0700 | [diff] [blame] | 942 | else |
| 943 | loader.instances = next->next; |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 944 | break; |
| 945 | } |
| 946 | prev = next; |
| 947 | next = next->next; |
| 948 | } |
| 949 | if (next == NULL) { |
| 950 | // This must be an invalid instance handle or empty list |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 951 | return VK_ERROR_INVALID_HANDLE; |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 952 | } |
| 953 | |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 954 | // cleanup any prior layer initializations |
| 955 | loader_deactivate_layer(ptr_instance); |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 956 | |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 957 | scanned_icds = loader.scanned_icd_list; |
| 958 | while (scanned_icds) { |
| 959 | if (scanned_icds->instance) |
| 960 | res = scanned_icds->DestroyInstance(scanned_icds->instance); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 961 | if (res != VK_SUCCESS) |
| 962 | loader_log(VK_DBG_MSG_WARNING, 0, |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 963 | "ICD ignored: failed to DestroyInstance on device"); |
| 964 | scanned_icds->instance = NULL; |
| 965 | scanned_icds = scanned_icds->next; |
| 966 | } |
| 967 | |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 968 | free(ptr_instance); |
| 969 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 970 | return VK_SUCCESS; |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 971 | } |
| 972 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 973 | LOADER_EXPORT VkResult VKAPI vkEnumerateGpus( |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 974 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 975 | VkInstance instance, |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 976 | uint32_t maxGpus, |
| 977 | uint32_t* pGpuCount, |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 978 | VkPhysicalGpu* pGpus) |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 979 | { |
Jon Ashburn | 4c392fb | 2015-01-28 19:57:09 -0700 | [diff] [blame] | 980 | struct loader_instance *ptr_instance = (struct loader_instance *) instance; |
| 981 | struct loader_icd *icd; |
Jon Ashburn | 8d66a05 | 2015-01-29 15:47:01 -0700 | [diff] [blame] | 982 | uint32_t count = 0; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 983 | VkResult res; |
Jon Ashburn | 4c392fb | 2015-01-28 19:57:09 -0700 | [diff] [blame] | 984 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 985 | //in spirit of VK don't error check on the instance parameter |
Jon Ashburn | 4c392fb | 2015-01-28 19:57:09 -0700 | [diff] [blame] | 986 | icd = ptr_instance->icds; |
| 987 | while (icd) { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 988 | VkPhysicalGpu gpus[VK_MAX_PHYSICAL_GPUS]; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 989 | VK_BASE_LAYER_OBJECT * wrapped_gpus; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 990 | PFN_vkGetProcAddr get_proc_addr = icd->scanned_icds->GetProcAddr; |
Jon Ashburn | 8d66a05 | 2015-01-29 15:47:01 -0700 | [diff] [blame] | 991 | uint32_t n, max = maxGpus - count; |
Jon Ashburn | 4c392fb | 2015-01-28 19:57:09 -0700 | [diff] [blame] | 992 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 993 | if (max > VK_MAX_PHYSICAL_GPUS) { |
| 994 | max = VK_MAX_PHYSICAL_GPUS; |
Jon Ashburn | 4c392fb | 2015-01-28 19:57:09 -0700 | [diff] [blame] | 995 | } |
| 996 | |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 997 | res = icd->scanned_icds->EnumerateGpus(icd->scanned_icds->instance, |
| 998 | max, &n, |
Jon Ashburn | 4c392fb | 2015-01-28 19:57:09 -0700 | [diff] [blame] | 999 | gpus); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1000 | if (res == VK_SUCCESS && n) { |
| 1001 | wrapped_gpus = (VK_BASE_LAYER_OBJECT*) malloc(n * |
| 1002 | sizeof(VK_BASE_LAYER_OBJECT)); |
Jon Ashburn | 4c392fb | 2015-01-28 19:57:09 -0700 | [diff] [blame] | 1003 | icd->gpus = wrapped_gpus; |
| 1004 | icd->gpu_count = n; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1005 | icd->loader_dispatch = (VK_LAYER_DISPATCH_TABLE *) malloc(n * |
| 1006 | sizeof(VK_LAYER_DISPATCH_TABLE)); |
Ian Elliott | 1962880 | 2015-02-04 12:06:46 -0700 | [diff] [blame] | 1007 | for (unsigned int i = 0; i < n; i++) { |
Jon Ashburn | 4c392fb | 2015-01-28 19:57:09 -0700 | [diff] [blame] | 1008 | (wrapped_gpus + i)->baseObject = gpus[i]; |
| 1009 | (wrapped_gpus + i)->pGPA = get_proc_addr; |
| 1010 | (wrapped_gpus + i)->nextObject = gpus[i]; |
| 1011 | memcpy(pGpus + count, &wrapped_gpus, sizeof(*pGpus)); |
| 1012 | loader_init_dispatch_table(icd->loader_dispatch + i, |
| 1013 | get_proc_addr, gpus[i]); |
Courtney Goeltzenleuchter | 64ca923 | 2015-02-10 18:40:14 -0700 | [diff] [blame] | 1014 | |
| 1015 | /* Verify ICD compatibility */ |
| 1016 | if (!valid_loader_magic_value(gpus[i])) { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1017 | loader_log(VK_DBG_MSG_WARNING, 0, |
Courtney Goeltzenleuchter | 64ca923 | 2015-02-10 18:40:14 -0700 | [diff] [blame] | 1018 | "Loader: Incompatible ICD, first dword must be initialized to ICD_LOADER_MAGIC. See loader/README.md for details.\n"); |
| 1019 | assert(0); |
| 1020 | } |
| 1021 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1022 | const VK_LAYER_DISPATCH_TABLE **disp; |
| 1023 | disp = (const VK_LAYER_DISPATCH_TABLE **) gpus[i]; |
Jon Ashburn | 4c392fb | 2015-01-28 19:57:09 -0700 | [diff] [blame] | 1024 | *disp = icd->loader_dispatch + i; |
| 1025 | } |
| 1026 | |
Jon Ashburn | 4c392fb | 2015-01-28 19:57:09 -0700 | [diff] [blame] | 1027 | count += n; |
| 1028 | |
| 1029 | if (count >= maxGpus) { |
| 1030 | break; |
| 1031 | } |
| 1032 | } |
| 1033 | |
| 1034 | icd = icd->next; |
| 1035 | } |
| 1036 | |
Jon Ashburn | 4c392fb | 2015-01-28 19:57:09 -0700 | [diff] [blame] | 1037 | *pGpuCount = count; |
| 1038 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1039 | return (count > 0) ? VK_SUCCESS : res; |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 1040 | } |
| 1041 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1042 | LOADER_EXPORT void * VKAPI vkGetProcAddr(VkPhysicalGpu gpu, const char * pName) |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 1043 | { |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1044 | if (gpu == NULL) { |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 1045 | return NULL; |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1046 | } |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1047 | VK_BASE_LAYER_OBJECT* gpuw = (VK_BASE_LAYER_OBJECT *) gpu; |
| 1048 | VK_LAYER_DISPATCH_TABLE * disp_table = * (VK_LAYER_DISPATCH_TABLE **) gpuw->baseObject; |
Chia-I Wu | f46b81a | 2015-01-04 11:12:47 +0800 | [diff] [blame] | 1049 | void *addr; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 1050 | |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 1051 | if (disp_table == NULL) |
| 1052 | return NULL; |
| 1053 | |
Chia-I Wu | f46b81a | 2015-01-04 11:12:47 +0800 | [diff] [blame] | 1054 | addr = loader_lookup_dispatch_table(disp_table, pName); |
| 1055 | if (addr) |
| 1056 | return addr; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 1057 | else { |
Jon Ashburn | f261001 | 2014-10-24 15:48:55 -0600 | [diff] [blame] | 1058 | if (disp_table->GetProcAddr == NULL) |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 1059 | return NULL; |
Jon Ashburn | f261001 | 2014-10-24 15:48:55 -0600 | [diff] [blame] | 1060 | return disp_table->GetProcAddr(gpuw->nextObject, pName); |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 1061 | } |
| 1062 | } |
| 1063 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1064 | LOADER_EXPORT VkResult VKAPI vkGetExtensionSupport(VkPhysicalGpu gpu, const char *pExtName) |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 1065 | { |
| 1066 | uint32_t gpu_index; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1067 | struct loader_icd *icd = loader_get_icd((const VK_BASE_LAYER_OBJECT *) gpu, &gpu_index); |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 1068 | |
| 1069 | if (!icd) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1070 | return VK_ERROR_UNAVAILABLE; |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 1071 | |
| 1072 | return find_layer_extension(icd, gpu_index, pExtName, NULL); |
| 1073 | } |
| 1074 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1075 | LOADER_EXPORT VkResult VKAPI vkEnumerateLayers(VkPhysicalGpu gpu, size_t maxLayerCount, size_t maxStringSize, size_t* pOutLayerCount, char* const* pOutLayers, void* pReserved) |
Jon Ashburn | f7bcf9b | 2014-10-15 15:30:23 -0600 | [diff] [blame] | 1076 | { |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1077 | uint32_t gpu_index; |
Ian Elliott | 1962880 | 2015-02-04 12:06:46 -0700 | [diff] [blame] | 1078 | size_t count = 0; |
Jon Ashburn | 1323eb7 | 2014-12-02 13:03:09 -0700 | [diff] [blame] | 1079 | char *lib_name; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1080 | struct loader_icd *icd = loader_get_icd((const VK_BASE_LAYER_OBJECT *) gpu, &gpu_index); |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1081 | loader_platform_dl_handle handle; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1082 | PFN_vkEnumerateLayers fpEnumerateLayers; |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1083 | char layer_buf[16][256]; |
| 1084 | char * layers[16]; |
Jon Ashburn | f7bcf9b | 2014-10-15 15:30:23 -0600 | [diff] [blame] | 1085 | |
Jon Ashburn | 1323eb7 | 2014-12-02 13:03:09 -0700 | [diff] [blame] | 1086 | if (pOutLayerCount == NULL || pOutLayers == NULL) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1087 | return VK_ERROR_INVALID_POINTER; |
Jon Ashburn | f7bcf9b | 2014-10-15 15:30:23 -0600 | [diff] [blame] | 1088 | |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 1089 | if (!icd) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1090 | return VK_ERROR_UNAVAILABLE; |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 1091 | |
Jon Ashburn | 1323eb7 | 2014-12-02 13:03:09 -0700 | [diff] [blame] | 1092 | for (int i = 0; i < 16; i++) |
| 1093 | layers[i] = &layer_buf[i][0]; |
| 1094 | |
| 1095 | for (unsigned int j = 0; j < loader.scanned_layer_count && count < maxLayerCount; j++) { |
| 1096 | lib_name = loader.scanned_layer_names[j]; |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1097 | // Used to call: dlopen(*lib_name, RTLD_LAZY) |
| 1098 | if ((handle = loader_platform_open_library(lib_name)) == NULL) |
Jon Ashburn | 1323eb7 | 2014-12-02 13:03:09 -0700 | [diff] [blame] | 1099 | continue; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1100 | if ((fpEnumerateLayers = loader_platform_get_proc_address(handle, "vkEnumerateLayers")) == NULL) { |
| 1101 | //use default layer name based on library name VK_LAYER_LIBRARY_PREFIX<name>.VK_LIBRARY_SUFFIX |
Jon Ashburn | 1323eb7 | 2014-12-02 13:03:09 -0700 | [diff] [blame] | 1102 | char *pEnd, *cpyStr; |
Ian Elliott | 4204584 | 2015-02-13 14:29:21 -0700 | [diff] [blame] | 1103 | size_t siz; |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1104 | loader_platform_close_library(handle); |
Jon Ashburn | 1323eb7 | 2014-12-02 13:03:09 -0700 | [diff] [blame] | 1105 | lib_name = basename(lib_name); |
| 1106 | pEnd = strrchr(lib_name, '.'); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1107 | siz = (int) (pEnd - lib_name - strlen(VK_LAYER_LIBRARY_PREFIX) + 1); |
Jon Ashburn | 1323eb7 | 2014-12-02 13:03:09 -0700 | [diff] [blame] | 1108 | if (pEnd == NULL || siz <= 0) |
| 1109 | continue; |
| 1110 | cpyStr = malloc(siz); |
| 1111 | if (cpyStr == NULL) { |
| 1112 | free(cpyStr); |
| 1113 | continue; |
| 1114 | } |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1115 | strncpy(cpyStr, lib_name + strlen(VK_LAYER_LIBRARY_PREFIX), siz); |
Jon Ashburn | 1323eb7 | 2014-12-02 13:03:09 -0700 | [diff] [blame] | 1116 | cpyStr[siz - 1] = '\0'; |
| 1117 | if (siz > maxStringSize) |
Ian Elliott | 1962880 | 2015-02-04 12:06:46 -0700 | [diff] [blame] | 1118 | siz = (int) maxStringSize; |
Jon Ashburn | 1323eb7 | 2014-12-02 13:03:09 -0700 | [diff] [blame] | 1119 | strncpy((char *) (pOutLayers[count]), cpyStr, siz); |
| 1120 | pOutLayers[count][siz - 1] = '\0'; |
| 1121 | count++; |
| 1122 | free(cpyStr); |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 1123 | } else { |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1124 | size_t cnt; |
| 1125 | uint32_t n; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1126 | VkResult res; |
Ian Elliott | 1962880 | 2015-02-04 12:06:46 -0700 | [diff] [blame] | 1127 | n = (uint32_t) ((maxStringSize < 256) ? maxStringSize : 256); |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1128 | res = fpEnumerateLayers(NULL, 16, n, &cnt, layers, (char *) icd->gpus + gpu_index); |
| 1129 | loader_platform_close_library(handle); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1130 | if (res != VK_SUCCESS) |
Jon Ashburn | 1323eb7 | 2014-12-02 13:03:09 -0700 | [diff] [blame] | 1131 | continue; |
| 1132 | if (cnt + count > maxLayerCount) |
| 1133 | cnt = maxLayerCount - count; |
Ian Elliott | 1962880 | 2015-02-04 12:06:46 -0700 | [diff] [blame] | 1134 | for (uint32_t i = (uint32_t) count; i < cnt + count; i++) { |
Jon Ashburn | 1323eb7 | 2014-12-02 13:03:09 -0700 | [diff] [blame] | 1135 | strncpy((char *) (pOutLayers[i]), (char *) layers[i - count], n); |
| 1136 | if (n > 0) |
| 1137 | pOutLayers[i - count][n - 1] = '\0'; |
| 1138 | } |
| 1139 | count += cnt; |
| 1140 | } |
| 1141 | } |
| 1142 | |
Jon Ashburn | f7bcf9b | 2014-10-15 15:30:23 -0600 | [diff] [blame] | 1143 | *pOutLayerCount = count; |
| 1144 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1145 | return VK_SUCCESS; |
Jon Ashburn | f7bcf9b | 2014-10-15 15:30:23 -0600 | [diff] [blame] | 1146 | } |
| 1147 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1148 | 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] | 1149 | { |
Jon Ashburn | 01e2d66 | 2014-11-14 09:52:42 -0700 | [diff] [blame] | 1150 | const struct loader_icd *icd; |
Jon Ashburn | 98bd454 | 2015-01-29 16:44:24 -0700 | [diff] [blame] | 1151 | struct loader_instance *inst; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1152 | VkResult res; |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1153 | uint32_t gpu_idx; |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1154 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1155 | if (instance == VK_NULL_HANDLE) |
| 1156 | return VK_ERROR_INVALID_HANDLE; |
Courtney Goeltzenleuchter | c80a557 | 2015-04-13 14:10:06 -0600 | [diff] [blame] | 1157 | |
| 1158 | assert(loader.icds_scanned); |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1159 | |
Jon Ashburn | 98bd454 | 2015-01-29 16:44:24 -0700 | [diff] [blame] | 1160 | for (inst = loader.instances; inst; inst = inst->next) { |
Jon Ashburn | bb51025 | 2015-03-17 13:47:55 -0600 | [diff] [blame] | 1161 | if (inst == instance) |
| 1162 | break; |
| 1163 | } |
| 1164 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1165 | if (inst == VK_NULL_HANDLE) |
| 1166 | return VK_ERROR_INVALID_HANDLE; |
Jon Ashburn | bb51025 | 2015-03-17 13:47:55 -0600 | [diff] [blame] | 1167 | |
| 1168 | for (icd = inst->icds; icd; icd = icd->next) { |
| 1169 | for (uint32_t i = 0; i < icd->gpu_count; i++) { |
| 1170 | res = (icd->loader_dispatch + i)->DbgRegisterMsgCallback(icd->scanned_icds->instance, |
Jon Ashburn | 98bd454 | 2015-01-29 16:44:24 -0700 | [diff] [blame] | 1171 | pfnMsgCallback, pUserData); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1172 | if (res != VK_SUCCESS) { |
Jon Ashburn | bb51025 | 2015-03-17 13:47:55 -0600 | [diff] [blame] | 1173 | gpu_idx = i; |
Jon Ashburn | 98bd454 | 2015-01-29 16:44:24 -0700 | [diff] [blame] | 1174 | break; |
Jon Ashburn | bb51025 | 2015-03-17 13:47:55 -0600 | [diff] [blame] | 1175 | } |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1176 | } |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1177 | if (res != VK_SUCCESS) |
Jon Ashburn | 01e2d66 | 2014-11-14 09:52:42 -0700 | [diff] [blame] | 1178 | break; |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1179 | } |
| 1180 | |
Jon Ashburn | bb51025 | 2015-03-17 13:47:55 -0600 | [diff] [blame] | 1181 | |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1182 | /* roll back on errors */ |
| 1183 | if (icd) { |
Jon Ashburn | bb51025 | 2015-03-17 13:47:55 -0600 | [diff] [blame] | 1184 | for (const struct loader_icd *tmp = inst->icds; tmp != icd; |
Jon Ashburn | 98bd454 | 2015-01-29 16:44:24 -0700 | [diff] [blame] | 1185 | tmp = tmp->next) { |
Jon Ashburn | bb51025 | 2015-03-17 13:47:55 -0600 | [diff] [blame] | 1186 | for (uint32_t i = 0; i < icd->gpu_count; i++) |
| 1187 | (tmp->loader_dispatch + i)->DbgUnregisterMsgCallback(tmp->scanned_icds->instance, pfnMsgCallback); |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1188 | } |
Jon Ashburn | 01e2d66 | 2014-11-14 09:52:42 -0700 | [diff] [blame] | 1189 | /* and gpus on current icd */ |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1190 | for (uint32_t i = 0; i < gpu_idx; i++) |
Courtney Goeltzenleuchter | c80a557 | 2015-04-13 14:10:06 -0600 | [diff] [blame] | 1191 | (icd->loader_dispatch + i)->DbgUnregisterMsgCallback(icd->scanned_icds->instance, pfnMsgCallback); |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1192 | |
| 1193 | return res; |
| 1194 | } |
| 1195 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1196 | return VK_SUCCESS; |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1197 | } |
| 1198 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1199 | 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] | 1200 | { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1201 | VkResult res = VK_SUCCESS; |
Jon Ashburn | bb51025 | 2015-03-17 13:47:55 -0600 | [diff] [blame] | 1202 | struct loader_instance *inst; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1203 | if (instance == VK_NULL_HANDLE) |
| 1204 | return VK_ERROR_INVALID_HANDLE; |
Courtney Goeltzenleuchter | c80a557 | 2015-04-13 14:10:06 -0600 | [diff] [blame] | 1205 | |
| 1206 | assert(loader.icds_scanned); |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1207 | |
Jon Ashburn | bb51025 | 2015-03-17 13:47:55 -0600 | [diff] [blame] | 1208 | for (inst = loader.instances; inst; inst = inst->next) { |
| 1209 | if (inst == instance) |
| 1210 | break; |
| 1211 | } |
| 1212 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1213 | if (inst == VK_NULL_HANDLE) |
| 1214 | return VK_ERROR_INVALID_HANDLE; |
Jon Ashburn | bb51025 | 2015-03-17 13:47:55 -0600 | [diff] [blame] | 1215 | |
| 1216 | for (const struct loader_icd * icd = inst->icds; icd; icd = icd->next) { |
| 1217 | for (uint32_t i = 0; i < icd->gpu_count; i++) { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1218 | VkResult r; |
Jon Ashburn | bb51025 | 2015-03-17 13:47:55 -0600 | [diff] [blame] | 1219 | r = (icd->loader_dispatch + i)->DbgUnregisterMsgCallback(icd->scanned_icds->instance, pfnMsgCallback); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1220 | if (r != VK_SUCCESS) { |
Jon Ashburn | bb51025 | 2015-03-17 13:47:55 -0600 | [diff] [blame] | 1221 | res = r; |
Jon Ashburn | 01e2d66 | 2014-11-14 09:52:42 -0700 | [diff] [blame] | 1222 | } |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1223 | } |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1224 | } |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1225 | return res; |
| 1226 | } |
| 1227 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1228 | 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] | 1229 | { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1230 | VkResult res = VK_SUCCESS; |
Jon Ashburn | bb51025 | 2015-03-17 13:47:55 -0600 | [diff] [blame] | 1231 | struct loader_instance *inst; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1232 | if (instance == VK_NULL_HANDLE) |
| 1233 | return VK_ERROR_INVALID_HANDLE; |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1234 | |
Courtney Goeltzenleuchter | c80a557 | 2015-04-13 14:10:06 -0600 | [diff] [blame] | 1235 | assert(loader.icds_scanned); |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1236 | |
Jon Ashburn | bb51025 | 2015-03-17 13:47:55 -0600 | [diff] [blame] | 1237 | for (inst = loader.instances; inst; inst = inst->next) { |
| 1238 | if (inst == instance) |
| 1239 | break; |
| 1240 | } |
| 1241 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1242 | if (inst == VK_NULL_HANDLE) |
| 1243 | return VK_ERROR_INVALID_HANDLE; |
Jon Ashburn | bb51025 | 2015-03-17 13:47:55 -0600 | [diff] [blame] | 1244 | for (const struct loader_icd * icd = inst->icds; icd; icd = icd->next) { |
| 1245 | for (uint32_t i = 0; i < icd->gpu_count; i++) { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1246 | VkResult r; |
Jon Ashburn | bb51025 | 2015-03-17 13:47:55 -0600 | [diff] [blame] | 1247 | r = (icd->loader_dispatch + i)->DbgSetGlobalOption(icd->scanned_icds->instance, dbgOption, |
Jon Ashburn | 98bd454 | 2015-01-29 16:44:24 -0700 | [diff] [blame] | 1248 | dataSize, pData); |
Jon Ashburn | bb51025 | 2015-03-17 13:47:55 -0600 | [diff] [blame] | 1249 | /* unfortunately we cannot roll back */ |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1250 | if (r != VK_SUCCESS) { |
Jon Ashburn | bb51025 | 2015-03-17 13:47:55 -0600 | [diff] [blame] | 1251 | res = r; |
Jon Ashburn | 01e2d66 | 2014-11-14 09:52:42 -0700 | [diff] [blame] | 1252 | } |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1253 | } |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1254 | } |
| 1255 | |
| 1256 | return res; |
| 1257 | } |