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 | 1930060 | 2014-08-04 08:03:57 +0800 | [diff] [blame] | 44 | #include "loader.h" |
Jon Ashburn | 07daee7 | 2015-05-21 18:13:33 -0600 | [diff] [blame] | 45 | #include "wsi_lunarg.h" |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 46 | #include "gpa_helper.h" |
| 47 | #include "table_ops.h" |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 48 | #include "vkIcd.h" |
Ian Elliott | 655cad7 | 2015-02-12 17:08:34 -0700 | [diff] [blame] | 49 | // The following is #included again to catch certain OS-specific functions |
| 50 | // being used: |
| 51 | #include "loader_platform.h" |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 52 | |
Jon Ashburn | b835805 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 53 | struct layer_name_pair { |
| 54 | char *layer_name; |
| 55 | const char *lib_name; |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 56 | }; |
| 57 | |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 58 | struct extension_property { |
| 59 | char extName[VK_MAX_EXTENSION_NAME]; |
| 60 | uint32_t version; |
| 61 | bool hosted; // does the extension reside in one driver/layer |
| 62 | }; |
| 63 | |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 64 | struct loader_scanned_icds { |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 65 | loader_platform_dl_handle handle; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 66 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 67 | PFN_vkCreateInstance CreateInstance; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 68 | PFN_vkGetGlobalExtensionInfo GetGlobalExtensionInfo; |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 69 | struct loader_scanned_icds *next; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 70 | uint32_t extension_count; |
| 71 | struct extension_property *extensions; |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 72 | }; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 73 | |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 74 | struct loader_struct loader = {0}; |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 75 | |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 76 | VkLayerInstanceDispatchTable instance_disp = { |
| 77 | .GetInstanceProcAddr = vkGetInstanceProcAddr, |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 78 | .CreateInstance = loader_CreateInstance, |
| 79 | .DestroyInstance = loader_DestroyInstance, |
| 80 | .EnumeratePhysicalDevices = loader_EnumeratePhysicalDevices, |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 81 | .GetPhysicalDeviceInfo = loader_GetPhysicalDeviceInfo, |
| 82 | .CreateDevice = loader_CreateDevice, |
Jon Ashburn | eceb13e | 2015-05-18 15:28:32 -0600 | [diff] [blame] | 83 | .GetGlobalExtensionInfo = vkGetGlobalExtensionInfo, |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 84 | .GetPhysicalDeviceExtensionInfo = loader_GetPhysicalDeviceExtensionInfo, |
| 85 | .EnumerateLayers = loader_EnumerateLayers, |
| 86 | .GetMultiDeviceCompatibility = loader_GetMultiDeviceCompatibility, |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 87 | .DbgRegisterMsgCallback = loader_DbgRegisterMsgCallback, |
| 88 | .DbgUnregisterMsgCallback = loader_DbgUnregisterMsgCallback, |
| 89 | .DbgSetGlobalOption = loader_DbgSetGlobalOption, |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 90 | .GetDisplayInfoWSI = loader_GetDisplayInfoWSI |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 91 | }; |
| 92 | |
| 93 | LOADER_PLATFORM_THREAD_ONCE_DECLARATION(once_icd); |
| 94 | LOADER_PLATFORM_THREAD_ONCE_DECLARATION(once_layer); |
| 95 | LOADER_PLATFORM_THREAD_ONCE_DECLARATION(once_exts); |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 96 | |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 97 | #if defined(WIN32) |
Ian Elliott | 5aa4ea2 | 2015-03-31 15:32:41 -0600 | [diff] [blame] | 98 | char *loader_get_registry_string(const HKEY hive, |
| 99 | const LPCTSTR sub_key, |
| 100 | const char *value) |
| 101 | { |
| 102 | DWORD access_flags = KEY_QUERY_VALUE; |
| 103 | DWORD value_type; |
| 104 | HKEY key; |
Ian Elliott | f851ddf | 2015-04-28 15:57:32 -0600 | [diff] [blame] | 105 | VkResult rtn_value; |
Ian Elliott | 5aa4ea2 | 2015-03-31 15:32:41 -0600 | [diff] [blame] | 106 | char *rtn_str = NULL; |
Tony Barbour | 18f7155 | 2015-04-22 11:36:22 -0600 | [diff] [blame] | 107 | DWORD rtn_len = 0; |
Ian Elliott | 5aa4ea2 | 2015-03-31 15:32:41 -0600 | [diff] [blame] | 108 | size_t allocated_len = 0; |
| 109 | |
| 110 | rtn_value = RegOpenKeyEx(hive, sub_key, 0, access_flags, &key); |
| 111 | if (rtn_value != ERROR_SUCCESS) { |
| 112 | // We didn't find the key. Try the 32-bit hive (where we've seen the |
| 113 | // key end up on some people's systems): |
| 114 | access_flags |= KEY_WOW64_32KEY; |
| 115 | rtn_value = RegOpenKeyEx(hive, sub_key, 0, access_flags, &key); |
| 116 | if (rtn_value != ERROR_SUCCESS) { |
| 117 | // We still couldn't find the key, so give up: |
| 118 | return NULL; |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | rtn_value = RegQueryValueEx(key, value, NULL, &value_type, |
Ian Elliott | f851ddf | 2015-04-28 15:57:32 -0600 | [diff] [blame] | 123 | (PVOID) rtn_str, (LPDWORD) &rtn_len); |
Ian Elliott | 5aa4ea2 | 2015-03-31 15:32:41 -0600 | [diff] [blame] | 124 | if (rtn_value == ERROR_SUCCESS) { |
| 125 | // If we get to here, we found the key, and need to allocate memory |
| 126 | // large enough for rtn_str, and query again: |
| 127 | allocated_len = rtn_len + 4; |
| 128 | rtn_str = malloc(allocated_len); |
| 129 | rtn_value = RegQueryValueEx(key, value, NULL, &value_type, |
Ian Elliott | f851ddf | 2015-04-28 15:57:32 -0600 | [diff] [blame] | 130 | (PVOID) rtn_str, (LPDWORD) &rtn_len); |
Ian Elliott | 5aa4ea2 | 2015-03-31 15:32:41 -0600 | [diff] [blame] | 131 | if (rtn_value == ERROR_SUCCESS) { |
| 132 | // We added 4 extra bytes to rtn_str, so that we can ensure that |
| 133 | // the string is NULL-terminated (albeit, in a brute-force manner): |
| 134 | rtn_str[allocated_len-1] = '\0'; |
| 135 | } else { |
| 136 | // This should never occur, but in case it does, clean up: |
| 137 | free(rtn_str); |
| 138 | rtn_str = NULL; |
| 139 | } |
| 140 | } // else - shouldn't happen, but if it does, return rtn_str, which is NULL |
| 141 | |
| 142 | // Close the registry key that was opened: |
| 143 | RegCloseKey(key); |
| 144 | |
| 145 | return rtn_str; |
| 146 | } |
| 147 | |
| 148 | |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 149 | // For ICD developers, look in the registry, and look for an environment |
| 150 | // variable for a path(s) where to find the ICD(s): |
| 151 | static char *loader_get_registry_and_env(const char *env_var, |
| 152 | const char *registry_value) |
| 153 | { |
| 154 | char *env_str = getenv(env_var); |
| 155 | size_t env_len = (env_str == NULL) ? 0 : strlen(env_str); |
Ian Elliott | 5aa4ea2 | 2015-03-31 15:32:41 -0600 | [diff] [blame] | 156 | char *registry_str = NULL; |
Tony Barbour | 18f7155 | 2015-04-22 11:36:22 -0600 | [diff] [blame] | 157 | size_t registry_len = 0; |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 158 | char *rtn_str = NULL; |
| 159 | size_t rtn_len; |
| 160 | |
Ian Elliott | 5aa4ea2 | 2015-03-31 15:32:41 -0600 | [diff] [blame] | 161 | registry_str = loader_get_registry_string(HKEY_LOCAL_MACHINE, |
Ian Elliott | 06ebd75 | 2015-04-09 18:07:15 -0600 | [diff] [blame] | 162 | "Software\\Vulkan", |
Ian Elliott | 5aa4ea2 | 2015-03-31 15:32:41 -0600 | [diff] [blame] | 163 | registry_value); |
Ian Elliott | f851ddf | 2015-04-28 15:57:32 -0600 | [diff] [blame] | 164 | registry_len = (registry_str) ? (DWORD) strlen(registry_str) : 0; |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 165 | |
| 166 | rtn_len = env_len + registry_len + 1; |
| 167 | if (rtn_len <= 2) { |
| 168 | // We found neither the desired registry value, nor the environment |
| 169 | // variable; return NULL: |
| 170 | return NULL; |
| 171 | } else { |
| 172 | // We found something, and so we need to allocate memory for the string |
| 173 | // to return: |
| 174 | rtn_str = malloc(rtn_len); |
| 175 | } |
| 176 | |
Ian Elliott | 5aa4ea2 | 2015-03-31 15:32:41 -0600 | [diff] [blame] | 177 | if (registry_len == 0) { |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 178 | // We didn't find the desired registry value, and so we must have found |
| 179 | // only the environment variable: |
| 180 | _snprintf(rtn_str, rtn_len, "%s", env_str); |
| 181 | } else if (env_str != NULL) { |
| 182 | // We found both the desired registry value and the environment |
| 183 | // variable, so concatenate them both: |
| 184 | _snprintf(rtn_str, rtn_len, "%s;%s", registry_str, env_str); |
| 185 | } else { |
| 186 | // We must have only found the desired registry value: |
| 187 | _snprintf(rtn_str, rtn_len, "%s", registry_str); |
| 188 | } |
| 189 | |
Ian Elliott | 2de26bc | 2015-04-03 13:13:01 -0600 | [diff] [blame] | 190 | if (registry_str) { |
| 191 | free(registry_str); |
| 192 | } |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 193 | |
| 194 | return(rtn_str); |
| 195 | } |
| 196 | #endif // WIN32 |
| 197 | |
| 198 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 199 | 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] | 200 | const char *format, ...) |
| 201 | { |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 202 | char msg[256]; |
| 203 | va_list ap; |
| 204 | int ret; |
| 205 | |
| 206 | va_start(ap, format); |
| 207 | ret = vsnprintf(msg, sizeof(msg), format, ap); |
Ian Elliott | 4204584 | 2015-02-13 14:29:21 -0700 | [diff] [blame] | 208 | if ((ret >= (int) sizeof(msg)) || ret < 0) { |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 209 | msg[sizeof(msg) - 1] = '\0'; |
| 210 | } |
| 211 | va_end(ap); |
| 212 | |
Jon Ashburn | ae053e9 | 2015-04-24 14:10:50 -0700 | [diff] [blame] | 213 | #if defined(WIN32) |
| 214 | OutputDebugString(msg); |
Jon Ashburn | 1de3940 | 2015-05-05 16:20:46 -0600 | [diff] [blame] | 215 | #endif |
Courtney Goeltzenleuchter | c80a557 | 2015-04-13 14:10:06 -0600 | [diff] [blame] | 216 | fputs(msg, stderr); |
| 217 | fputc('\n', stderr); |
Jon Ashburn | 1de3940 | 2015-05-05 16:20:46 -0600 | [diff] [blame] | 218 | |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 219 | } |
| 220 | |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 221 | static bool has_extension(struct extension_property *exts, uint32_t count, |
| 222 | const char *name, bool must_be_hosted) |
| 223 | { |
| 224 | uint32_t i; |
| 225 | for (i = 0; i < count; i++) { |
| 226 | if (!strcmp(name, exts[i].extName) && (!must_be_hosted || exts[i].hosted)) |
| 227 | return true; |
| 228 | } |
| 229 | return false; |
| 230 | } |
| 231 | |
| 232 | static void get_global_extensions(PFN_vkGetGlobalExtensionInfo fp_get, |
| 233 | uint32_t *count_out, |
| 234 | struct extension_property **props_out) |
| 235 | { |
| 236 | uint32_t i, count, cur; |
| 237 | size_t siz = sizeof(count); |
| 238 | struct extension_property *ext_props; |
| 239 | VkExtensionProperties vk_prop; |
| 240 | VkResult res; |
| 241 | |
| 242 | *count_out = 0; |
| 243 | *props_out = NULL; |
| 244 | res = fp_get(VK_EXTENSION_INFO_TYPE_COUNT, 0, &siz, &count); |
| 245 | if (res != VK_SUCCESS) { |
| 246 | loader_log(VK_DBG_MSG_WARNING, 0, "Error getting global extension count from ICD"); |
| 247 | return; |
| 248 | } |
| 249 | ext_props = (struct extension_property *) malloc(sizeof(struct extension_property) * count); |
| 250 | if (ext_props == NULL) { |
| 251 | loader_log(VK_DBG_MSG_WARNING, 0, "Out of memory didn't get global extensions from ICD"); |
| 252 | return; |
| 253 | } |
| 254 | siz = sizeof(VkExtensionProperties); |
| 255 | cur = 0; |
| 256 | for (i = 0; i < count; i++) { |
| 257 | res = fp_get(VK_EXTENSION_INFO_TYPE_PROPERTIES, i, &siz, &vk_prop); |
| 258 | if (res == VK_SUCCESS) { |
| 259 | (ext_props + cur)->hosted = false; |
| 260 | (ext_props + cur)->version = vk_prop.version; |
| 261 | strncpy((ext_props + cur)->extName, vk_prop.extName, VK_MAX_EXTENSION_NAME); |
| 262 | (ext_props + cur)->extName[VK_MAX_EXTENSION_NAME - 1] = '\0'; |
| 263 | cur++; |
| 264 | } |
| 265 | *count_out = cur; |
| 266 | *props_out = ext_props; |
| 267 | } |
| 268 | return; |
| 269 | } |
| 270 | |
| 271 | static void loader_init_ext_list() |
| 272 | { |
| 273 | loader.scanned_ext_list_capacity = 256 * sizeof(struct extension_property *); |
| 274 | loader.scanned_ext_list = malloc(loader.scanned_ext_list_capacity); |
| 275 | memset(loader.scanned_ext_list, 0, loader.scanned_ext_list_capacity); |
| 276 | loader.scanned_ext_list_count = 0; |
| 277 | } |
| 278 | |
| 279 | #if 0 // currently no place to call this |
| 280 | static void loader_destroy_ext_list() |
| 281 | { |
| 282 | free(loader.scanned_ext_list); |
| 283 | loader.scanned_ext_list_capacity = 0; |
| 284 | loader.scanned_ext_list_count = 0; |
| 285 | } |
| 286 | #endif |
| 287 | |
| 288 | static void loader_add_to_ext_list(uint32_t count, |
Jon Ashburn | 19c2502 | 2015-04-14 14:14:48 -0600 | [diff] [blame] | 289 | struct extension_property *prop_list, |
| 290 | bool is_layer_ext) |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 291 | { |
| 292 | uint32_t i, j; |
| 293 | bool duplicate; |
| 294 | struct extension_property *cur_ext; |
| 295 | |
| 296 | if (loader.scanned_ext_list == NULL || loader.scanned_ext_list_capacity == 0) |
| 297 | loader_init_ext_list(); |
| 298 | |
| 299 | if (loader.scanned_ext_list == NULL) |
| 300 | return; |
| 301 | |
| 302 | struct extension_property *ext_list, **ext_list_addr; |
| 303 | |
| 304 | for (i = 0; i < count; i++) { |
| 305 | cur_ext = prop_list + i; |
| 306 | |
| 307 | // look for duplicates or not |
| 308 | duplicate = false; |
| 309 | for (j = 0; j < loader.scanned_ext_list_count; j++) { |
| 310 | ext_list = loader.scanned_ext_list[j]; |
| 311 | if (!strcmp(cur_ext->extName, ext_list->extName)) { |
| 312 | duplicate = true; |
| 313 | ext_list->hosted = false; |
| 314 | break; |
| 315 | } |
| 316 | } |
| 317 | |
| 318 | // add to list at end |
| 319 | if (!duplicate) { |
| 320 | // check for enough capacity |
| 321 | if (loader.scanned_ext_list_count * sizeof(struct extension_property *) |
| 322 | >= loader.scanned_ext_list_capacity) { |
| 323 | // double capacity |
| 324 | loader.scanned_ext_list_capacity *= 2; |
| 325 | loader.scanned_ext_list = realloc(loader.scanned_ext_list, |
| 326 | loader.scanned_ext_list_capacity); |
| 327 | } |
| 328 | ext_list_addr = &(loader.scanned_ext_list[loader.scanned_ext_list_count++]); |
| 329 | *ext_list_addr = cur_ext; |
| 330 | cur_ext->hosted = true; |
| 331 | } |
| 332 | |
| 333 | } |
| 334 | } |
| 335 | |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 336 | bool loader_is_extension_scanned(const char *name) |
Jon Ashburn | fc2e38c | 2015-04-14 09:15:32 -0600 | [diff] [blame] | 337 | { |
| 338 | uint32_t i; |
| 339 | |
| 340 | for (i = 0; i < loader.scanned_ext_list_count; i++) { |
| 341 | if (!strcmp(name, loader.scanned_ext_list[i]->extName)) |
| 342 | return true; |
| 343 | } |
| 344 | return false; |
| 345 | } |
| 346 | |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 347 | void loader_coalesce_extensions(void) |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 348 | { |
| 349 | uint32_t i; |
| 350 | struct loader_scanned_icds *icd_list = loader.scanned_icd_list; |
| 351 | |
| 352 | // traverse scanned icd list adding non-duplicate extensions to the list |
| 353 | while (icd_list != NULL) { |
Jon Ashburn | 19c2502 | 2015-04-14 14:14:48 -0600 | [diff] [blame] | 354 | loader_add_to_ext_list(icd_list->extension_count, icd_list->extensions, false); |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 355 | icd_list = icd_list->next; |
| 356 | }; |
| 357 | |
| 358 | //Traverse layers list adding non-duplicate extensions to the list |
| 359 | for (i = 0; i < loader.scanned_layer_count; i++) { |
| 360 | loader_add_to_ext_list(loader.scanned_layers[i].extension_count, |
Jon Ashburn | 19c2502 | 2015-04-14 14:14:48 -0600 | [diff] [blame] | 361 | loader.scanned_layers[i].extensions, true); |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 362 | } |
| 363 | } |
| 364 | |
| 365 | static void loader_icd_destroy(struct loader_icd *icd) |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 366 | { |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 367 | loader_platform_close_library(icd->scanned_icds->handle); |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 368 | free(icd); |
| 369 | } |
| 370 | |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 371 | 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] | 372 | { |
| 373 | struct loader_icd *icd; |
| 374 | |
| 375 | icd = malloc(sizeof(*icd)); |
| 376 | if (!icd) |
| 377 | return NULL; |
| 378 | |
Courtney Goeltzenleuchter | 55001bb | 2014-10-28 10:29:27 -0600 | [diff] [blame] | 379 | memset(icd, 0, sizeof(*icd)); |
| 380 | |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 381 | icd->scanned_icds = scanned; |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 382 | |
| 383 | return icd; |
| 384 | } |
| 385 | |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 386 | static struct loader_icd *loader_icd_add(struct loader_instance *ptr_inst, |
| 387 | const struct loader_scanned_icds *scanned) |
Chia-I Wu | 13a61a5 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 388 | { |
| 389 | struct loader_icd *icd; |
| 390 | |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 391 | icd = loader_icd_create(scanned); |
Chia-I Wu | 13a61a5 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 392 | if (!icd) |
| 393 | return NULL; |
| 394 | |
Chia-I Wu | 13a61a5 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 395 | /* prepend to the list */ |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 396 | icd->next = ptr_inst->icds; |
| 397 | ptr_inst->icds = icd; |
Chia-I Wu | 13a61a5 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 398 | |
| 399 | return icd; |
| 400 | } |
| 401 | |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 402 | static void loader_scanned_icd_add(const char *filename) |
| 403 | { |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 404 | loader_platform_dl_handle handle; |
Jon Ashburn | 3da71f2 | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 405 | void *fp_create_inst; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 406 | void *fp_get_global_ext_info; |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 407 | struct loader_scanned_icds *new_node; |
| 408 | |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 409 | // Used to call: dlopen(filename, RTLD_LAZY); |
| 410 | handle = loader_platform_open_library(filename); |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 411 | if (!handle) { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 412 | 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] | 413 | return; |
| 414 | } |
| 415 | |
| 416 | #define LOOKUP(func_ptr, func) do { \ |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 417 | 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] | 418 | if (!func_ptr) { \ |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 419 | 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] | 420 | return; \ |
| 421 | } \ |
| 422 | } while (0) |
| 423 | |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 424 | LOOKUP(fp_create_inst, CreateInstance); |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 425 | LOOKUP(fp_get_global_ext_info, GetGlobalExtensionInfo); |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 426 | #undef LOOKUP |
| 427 | |
| 428 | new_node = (struct loader_scanned_icds *) malloc(sizeof(struct loader_scanned_icds)); |
| 429 | if (!new_node) { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 430 | 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] | 431 | return; |
| 432 | } |
| 433 | |
| 434 | new_node->handle = handle; |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 435 | new_node->CreateInstance = fp_create_inst; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 436 | new_node->GetGlobalExtensionInfo = fp_get_global_ext_info; |
| 437 | new_node->extension_count = 0; |
| 438 | new_node->extensions = NULL; |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 439 | new_node->next = loader.scanned_icd_list; |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 440 | |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 441 | loader.scanned_icd_list = new_node; |
| 442 | |
| 443 | if (fp_get_global_ext_info) { |
| 444 | get_global_extensions((PFN_vkGetGlobalExtensionInfo) fp_get_global_ext_info, |
| 445 | &new_node->extension_count, |
| 446 | &new_node->extensions); |
| 447 | } else { |
| 448 | loader_log(VK_DBG_MSG_WARNING, 0, "Couldn't get global extensions from ICD"); |
| 449 | } |
| 450 | } |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 451 | |
Jon Ashburn | 3da71f2 | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 452 | static void loader_icd_init_entrys(struct loader_icd *icd, |
| 453 | struct loader_scanned_icds *scanned_icds) |
| 454 | { |
| 455 | /* initialize entrypoint function pointers */ |
| 456 | |
| 457 | #define LOOKUP(func) do { \ |
| 458 | icd->func = (PFN_vk ##func) loader_platform_get_proc_address(scanned_icds->handle, "vk" #func); \ |
| 459 | if (!icd->func) { \ |
| 460 | loader_log(VK_DBG_MSG_WARNING, 0, loader_platform_get_proc_address_error("vk" #func)); \ |
| 461 | return; \ |
| 462 | } \ |
| 463 | } while (0) |
| 464 | |
Jon Ashburn | 8d1b0b5 | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 465 | /* could change this to use GetInstanceProcAddr in driver instead of dlsym */ |
| 466 | LOOKUP(GetDeviceProcAddr); |
Jon Ashburn | 3da71f2 | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 467 | LOOKUP(DestroyInstance); |
| 468 | LOOKUP(EnumeratePhysicalDevices); |
| 469 | LOOKUP(GetPhysicalDeviceInfo); |
| 470 | LOOKUP(CreateDevice); |
| 471 | LOOKUP(GetPhysicalDeviceExtensionInfo); |
| 472 | LOOKUP(EnumerateLayers); |
| 473 | LOOKUP(GetMultiDeviceCompatibility); |
| 474 | LOOKUP(DbgRegisterMsgCallback); |
| 475 | LOOKUP(DbgUnregisterMsgCallback); |
| 476 | LOOKUP(DbgSetGlobalOption); |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 477 | LOOKUP(GetDisplayInfoWSI); |
Jon Ashburn | 3da71f2 | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 478 | #undef LOOKUP |
| 479 | |
| 480 | return; |
| 481 | } |
| 482 | |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 483 | /** |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 484 | * Try to \c loader_icd_scan VK driver(s). |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 485 | * |
| 486 | * This function scans the default system path or path |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 487 | * specified by the \c LIBVK_DRIVERS_PATH environment variable in |
| 488 | * order to find loadable VK ICDs with the name of libVK_*. |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 489 | * |
| 490 | * \returns |
| 491 | * void; but side effect is to set loader_icd_scanned to true |
| 492 | */ |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 493 | void loader_icd_scan(void) |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 494 | { |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 495 | const char *p, *next; |
| 496 | char *libPaths = NULL; |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 497 | DIR *sysdir; |
| 498 | struct dirent *dent; |
| 499 | char icd_library[1024]; |
Jon Ashburn | 5cda59c | 2014-10-03 16:31:35 -0600 | [diff] [blame] | 500 | char path[1024]; |
Ian Elliott | 1962880 | 2015-02-04 12:06:46 -0700 | [diff] [blame] | 501 | uint32_t len; |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 502 | #if defined(WIN32) |
| 503 | bool must_free_libPaths; |
| 504 | libPaths = loader_get_registry_and_env(DRIVER_PATH_ENV, |
| 505 | DRIVER_PATH_REGISTRY_VALUE); |
| 506 | if (libPaths != NULL) { |
| 507 | must_free_libPaths = true; |
| 508 | } else { |
| 509 | must_free_libPaths = false; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 510 | libPaths = DEFAULT_VK_DRIVERS_PATH; |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 511 | } |
| 512 | #else // WIN32 |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 513 | if (geteuid() == getuid()) { |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 514 | /* Don't allow setuid apps to use the DRIVER_PATH_ENV env var: */ |
| 515 | libPaths = getenv(DRIVER_PATH_ENV); |
| 516 | } |
| 517 | if (libPaths == NULL) { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 518 | libPaths = DEFAULT_VK_DRIVERS_PATH; |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 519 | } |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 520 | #endif // WIN32 |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 521 | |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 522 | for (p = libPaths; *p; p = next) { |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 523 | next = strchr(p, PATH_SEPERATOR); |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 524 | if (next == NULL) { |
Ian Elliott | 1962880 | 2015-02-04 12:06:46 -0700 | [diff] [blame] | 525 | len = (uint32_t) strlen(p); |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 526 | next = p + len; |
| 527 | } |
| 528 | else { |
Ian Elliott | 1962880 | 2015-02-04 12:06:46 -0700 | [diff] [blame] | 529 | len = (uint32_t) (next - p); |
Jon Ashburn | 5cda59c | 2014-10-03 16:31:35 -0600 | [diff] [blame] | 530 | sprintf(path, "%.*s", (len > sizeof(path) - 1) ? (int) sizeof(path) - 1 : len, p); |
| 531 | p = path; |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 532 | next++; |
| 533 | } |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 534 | |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 535 | // TODO/TBD: Do we want to do this on Windows, or just let Windows take |
| 536 | // care of its own search path (which it apparently has)? |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 537 | sysdir = opendir(p); |
| 538 | if (sysdir) { |
| 539 | dent = readdir(sysdir); |
| 540 | while (dent) { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 541 | /* Look for ICDs starting with VK_DRIVER_LIBRARY_PREFIX and |
| 542 | * ending with VK_LIBRARY_SUFFIX |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 543 | */ |
| 544 | if (!strncmp(dent->d_name, |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 545 | VK_DRIVER_LIBRARY_PREFIX, |
| 546 | VK_DRIVER_LIBRARY_PREFIX_LEN)) { |
Ian Elliott | 1962880 | 2015-02-04 12:06:46 -0700 | [diff] [blame] | 547 | uint32_t nlen = (uint32_t) strlen(dent->d_name); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 548 | const char *suf = dent->d_name + nlen - VK_LIBRARY_SUFFIX_LEN; |
| 549 | if ((nlen > VK_LIBRARY_SUFFIX_LEN) && |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 550 | !strncmp(suf, |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 551 | VK_LIBRARY_SUFFIX, |
| 552 | VK_LIBRARY_SUFFIX_LEN)) { |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 553 | snprintf(icd_library, 1024, "%s" DIRECTORY_SYMBOL "%s", p,dent->d_name); |
| 554 | loader_scanned_icd_add(icd_library); |
| 555 | } |
| 556 | } |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 557 | |
| 558 | dent = readdir(sysdir); |
| 559 | } |
| 560 | closedir(sysdir); |
| 561 | } |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 562 | } |
| 563 | |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 564 | #if defined(WIN32) |
| 565 | // Free any allocated memory: |
| 566 | if (must_free_libPaths) { |
| 567 | free(libPaths); |
| 568 | } |
| 569 | #endif // WIN32 |
| 570 | |
| 571 | // Note that we've scanned for ICDs: |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 572 | loader.icds_scanned = true; |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 573 | } |
| 574 | |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 575 | |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 576 | void layer_lib_scan(void) |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 577 | { |
| 578 | const char *p, *next; |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 579 | char *libPaths = NULL; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 580 | DIR *curdir; |
| 581 | struct dirent *dent; |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 582 | size_t len, i; |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 583 | char temp_str[1024]; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 584 | uint32_t count; |
| 585 | PFN_vkGetGlobalExtensionInfo fp_get_ext; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 586 | |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 587 | #if defined(WIN32) |
| 588 | bool must_free_libPaths; |
| 589 | libPaths = loader_get_registry_and_env(LAYERS_PATH_ENV, |
| 590 | LAYERS_PATH_REGISTRY_VALUE); |
| 591 | if (libPaths != NULL) { |
| 592 | must_free_libPaths = true; |
| 593 | } else { |
| 594 | must_free_libPaths = false; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 595 | libPaths = DEFAULT_VK_LAYERS_PATH; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 596 | } |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 597 | #else // WIN32 |
| 598 | if (geteuid() == getuid()) { |
| 599 | /* 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] | 600 | libPaths = getenv(LAYERS_PATH_ENV); |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 601 | } |
| 602 | if (libPaths == NULL) { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 603 | libPaths = DEFAULT_VK_LAYERS_PATH; |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 604 | } |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 605 | #endif // WIN32 |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 606 | |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 607 | if (libPaths == NULL) { |
| 608 | // Have no paths to search: |
Courtney Goeltzenleuchter | 57985ce | 2014-12-01 09:29:42 -0700 | [diff] [blame] | 609 | return; |
| 610 | } |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 611 | len = strlen(libPaths); |
Courtney Goeltzenleuchter | 57985ce | 2014-12-01 09:29:42 -0700 | [diff] [blame] | 612 | loader.layer_dirs = malloc(len+1); |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 613 | if (loader.layer_dirs == NULL) { |
| 614 | free(libPaths); |
Courtney Goeltzenleuchter | a66265b | 2014-12-02 18:12:51 -0700 | [diff] [blame] | 615 | return; |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 616 | } |
| 617 | // Alloc passed, so we know there is enough space to hold the string, don't |
| 618 | // need strncpy |
| 619 | strcpy(loader.layer_dirs, libPaths); |
| 620 | #if defined(WIN32) |
| 621 | // Free any allocated memory: |
| 622 | if (must_free_libPaths) { |
| 623 | free(libPaths); |
| 624 | must_free_libPaths = false; |
| 625 | } |
| 626 | #endif // WIN32 |
Courtney Goeltzenleuchter | 57985ce | 2014-12-01 09:29:42 -0700 | [diff] [blame] | 627 | libPaths = loader.layer_dirs; |
| 628 | |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 629 | /* cleanup any previously scanned libraries */ |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 630 | for (i = 0; i < loader.scanned_layer_count; i++) { |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 631 | if (loader.scanned_layers[i].name != NULL) |
| 632 | free(loader.scanned_layers[i].name); |
| 633 | if (loader.scanned_layers[i].extensions != NULL) |
| 634 | free(loader.scanned_layers[i].extensions); |
| 635 | loader.scanned_layers[i].name = NULL; |
| 636 | loader.scanned_layers[i].extensions = NULL; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 637 | } |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 638 | loader.scanned_layer_count = 0; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 639 | count = 0; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 640 | |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 641 | for (p = libPaths; *p; p = next) { |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 642 | next = strchr(p, PATH_SEPERATOR); |
| 643 | if (next == NULL) { |
| 644 | len = (uint32_t) strlen(p); |
| 645 | next = p + len; |
| 646 | } |
| 647 | else { |
| 648 | len = (uint32_t) (next - p); |
| 649 | *(char *) next = '\0'; |
| 650 | next++; |
| 651 | } |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 652 | |
| 653 | curdir = opendir(p); |
| 654 | if (curdir) { |
| 655 | dent = readdir(curdir); |
| 656 | while (dent) { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 657 | /* Look for layers starting with VK_LAYER_LIBRARY_PREFIX and |
| 658 | * ending with VK_LIBRARY_SUFFIX |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 659 | */ |
| 660 | if (!strncmp(dent->d_name, |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 661 | VK_LAYER_LIBRARY_PREFIX, |
| 662 | VK_LAYER_LIBRARY_PREFIX_LEN)) { |
Ian Elliott | 1962880 | 2015-02-04 12:06:46 -0700 | [diff] [blame] | 663 | uint32_t nlen = (uint32_t) strlen(dent->d_name); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 664 | const char *suf = dent->d_name + nlen - VK_LIBRARY_SUFFIX_LEN; |
| 665 | if ((nlen > VK_LIBRARY_SUFFIX_LEN) && |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 666 | !strncmp(suf, |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 667 | VK_LIBRARY_SUFFIX, |
| 668 | VK_LIBRARY_SUFFIX_LEN)) { |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 669 | loader_platform_dl_handle handle; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 670 | snprintf(temp_str, sizeof(temp_str), |
| 671 | "%s" DIRECTORY_SYMBOL "%s",p,dent->d_name); |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 672 | // Used to call: dlopen(temp_str, RTLD_LAZY) |
| 673 | if ((handle = loader_platform_open_library(temp_str)) == NULL) { |
| 674 | dent = readdir(curdir); |
| 675 | continue; |
| 676 | } |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 677 | if (count == MAX_LAYER_LIBRARIES) { |
| 678 | loader_log(VK_DBG_MSG_ERROR, 0, |
| 679 | "%s ignored: max layer libraries exceed", |
| 680 | temp_str); |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 681 | break; |
| 682 | } |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 683 | fp_get_ext = loader_platform_get_proc_address(handle, |
| 684 | "vkGetGlobalExtensionInfo"); |
| 685 | |
| 686 | if (!fp_get_ext) { |
| 687 | loader_log(VK_DBG_MSG_WARNING, 0, |
| 688 | "Couldn't dlsym vkGetGlobalExtensionInfo from library %s", |
| 689 | temp_str); |
| 690 | dent = readdir(curdir); |
| 691 | loader_platform_close_library(handle); |
| 692 | continue; |
| 693 | } |
| 694 | |
| 695 | loader.scanned_layers[count].name = |
| 696 | malloc(strlen(temp_str) + 1); |
| 697 | if (loader.scanned_layers[count].name == NULL) { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 698 | 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] | 699 | break; |
| 700 | } |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 701 | |
| 702 | get_global_extensions(fp_get_ext, |
| 703 | &loader.scanned_layers[count].extension_count, |
| 704 | &loader.scanned_layers[count].extensions); |
| 705 | |
| 706 | |
| 707 | strcpy(loader.scanned_layers[count].name, temp_str); |
| 708 | count++; |
| 709 | loader_platform_close_library(handle); |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 710 | } |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 711 | } |
| 712 | |
| 713 | dent = readdir(curdir); |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 714 | } // while (dir_entry) |
| 715 | if (count == MAX_LAYER_LIBRARIES) |
| 716 | break; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 717 | closedir(curdir); |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 718 | } // if (curdir)) |
| 719 | } // for (libpaths) |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 720 | |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 721 | loader.scanned_layer_count = count; |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 722 | loader.layer_scanned = true; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 723 | } |
| 724 | |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 725 | static void* VKAPI loader_gpa_instance_internal(VkInstance inst, const char * pName) |
| 726 | { |
| 727 | // inst is not wrapped |
| 728 | if (inst == VK_NULL_HANDLE) { |
| 729 | return NULL; |
| 730 | } |
| 731 | VkLayerInstanceDispatchTable* disp_table = * (VkLayerInstanceDispatchTable **) inst; |
| 732 | void *addr; |
| 733 | |
| 734 | if (disp_table == NULL) |
| 735 | return NULL; |
| 736 | |
| 737 | addr = loader_lookup_instance_dispatch_table(disp_table, pName); |
| 738 | if (addr) |
| 739 | return addr; |
| 740 | else { |
| 741 | if (disp_table->GetInstanceProcAddr == NULL) |
| 742 | return NULL; |
| 743 | return disp_table->GetInstanceProcAddr(inst, pName); |
Jon Ashburn | 3d526cb | 2015-04-13 18:10:06 -0600 | [diff] [blame] | 744 | } |
| 745 | } |
| 746 | |
Jon Ashburn | 1ed042c | 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 | 876b1ac | 2014-10-17 15:09:07 -0600 | [diff] [blame] | 748 | { |
Jon Ashburn | 4d9f465 | 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 | 98bd454 | 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 | b050c68 | 2015-04-17 12:36:38 -0600 | [diff] [blame] | 757 | if ((icd->gpus + i) == gpu || (void*)(icd->gpus +i)->baseObject == gpu) { |
Jon Ashburn | 98bd454 | 2015-01-29 16:44:24 -0700 | [diff] [blame] | 758 | *gpu_index = i; |
| 759 | return icd; |
| 760 | } |
| 761 | } |
Jon Ashburn | 876b1ac | 2014-10-17 15:09:07 -0600 | [diff] [blame] | 762 | } |
| 763 | return NULL; |
| 764 | } |
| 765 | |
Mark Lobodzinski | 17caf57 | 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 | 876b1ac | 2014-10-17 15:09:07 -0600 | [diff] [blame] | 767 | { |
Jon Ashburn | 6b4d70c | 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 | 876b1ac | 2014-10-17 15:09:07 -0600 | [diff] [blame] | 772 | } |
| 773 | |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 774 | static void loader_init_device_layer_libs(struct loader_icd *icd, uint32_t gpu_index, |
Jon Ashburn | 19c2502 | 2015-04-14 14:14:48 -0600 | [diff] [blame] | 775 | struct layer_name_pair * pLayerNames, |
| 776 | uint32_t count) |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 777 | { |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 778 | if (!icd) |
| 779 | return; |
Jon Ashburn | df7d584 | 2014-10-16 15:48:50 -0600 | [diff] [blame] | 780 | |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 781 | struct loader_layers *obj; |
| 782 | bool foundLib; |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 783 | for (uint32_t i = 0; i < count; i++) { |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 784 | foundLib = false; |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 785 | for (uint32_t j = 0; j < icd->layer_count[gpu_index]; j++) { |
Jon Ashburn | 19c2502 | 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 | 6b4d70c | 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 | b835805 | 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 | 2d4ab1e | 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 | d8e229c | 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 | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 801 | continue; |
| 802 | } else { |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 803 | loader_log(VK_DBG_MSG_UNKNOWN, 0, "Inserting device layer %s from library %s", |
Jon Ashburn | 19c2502 | 2015-04-14 14:14:48 -0600 | [diff] [blame] | 804 | pLayerNames[i].layer_name, pLayerNames[i].lib_name); |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 805 | } |
Jon Ashburn | b835805 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 806 | free(pLayerNames[i].layer_name); |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 807 | icd->layer_count[gpu_index]++; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 808 | } |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 809 | } |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 810 | } |
| 811 | |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 812 | static void loader_init_instance_layer_libs(struct loader_instance *inst, |
| 813 | struct layer_name_pair * pLayerNames, |
| 814 | uint32_t count) |
| 815 | { |
| 816 | if (!inst) |
| 817 | return; |
| 818 | |
| 819 | struct loader_layers *obj; |
| 820 | bool foundLib; |
| 821 | for (uint32_t i = 0; i < count; i++) { |
| 822 | foundLib = false; |
| 823 | for (uint32_t j = 0; j < inst->layer_count; j++) { |
| 824 | if (inst->layer_libs[j].lib_handle && |
| 825 | !strcmp(inst->layer_libs[j].name, |
| 826 | (char *) pLayerNames[i].layer_name) && |
| 827 | strcmp("Validation", (char *) pLayerNames[i].layer_name)) { |
| 828 | foundLib = true; |
| 829 | break; |
| 830 | } |
| 831 | } |
| 832 | if (!foundLib) { |
| 833 | obj = &(inst->layer_libs[i]); |
| 834 | strncpy(obj->name, (char *) pLayerNames[i].layer_name, sizeof(obj->name) - 1); |
| 835 | obj->name[sizeof(obj->name) - 1] = '\0'; |
| 836 | // Used to call: dlopen(pLayerNames[i].lib_name, RTLD_LAZY | RTLD_DEEPBIND) |
| 837 | if ((obj->lib_handle = loader_platform_open_library(pLayerNames[i].lib_name)) == NULL) { |
| 838 | loader_log(VK_DBG_MSG_ERROR, 0, loader_platform_open_library_error(pLayerNames[i].lib_name)); |
| 839 | continue; |
| 840 | } else { |
| 841 | loader_log(VK_DBG_MSG_UNKNOWN, 0, "Inserting instance layer %s from library %s", |
| 842 | pLayerNames[i].layer_name, pLayerNames[i].lib_name); |
| 843 | } |
| 844 | free(pLayerNames[i].layer_name); |
| 845 | inst->layer_count++; |
| 846 | } |
| 847 | } |
| 848 | } |
| 849 | |
Jon Ashburn | 3d45475 | 2015-05-08 14:35:08 -0600 | [diff] [blame] | 850 | static bool find_layer_extension(const char *pExtName, uint32_t *out_count, |
Jon Ashburn | 19c2502 | 2015-04-14 14:14:48 -0600 | [diff] [blame] | 851 | char *lib_name[MAX_LAYER_LIBRARIES]) |
Jon Ashburn | b835805 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 852 | { |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 853 | char *search_name; |
Jon Ashburn | 19c2502 | 2015-04-14 14:14:48 -0600 | [diff] [blame] | 854 | uint32_t j, found_count = 0; |
| 855 | bool must_be_hosted; |
| 856 | bool found = false; |
Jon Ashburn | b835805 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 857 | |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 858 | /* |
| 859 | * The loader provides the abstraction that make layers and extensions work via |
| 860 | * the currently defined extension mechanism. That is, when app queries for an extension |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 861 | * via vkGetGlobalExtensionInfo, the loader will call both the driver as well as any layers |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 862 | * to see who implements that extension. Then, if the app enables the extension during |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 863 | * vkCreateInstance the loader will find and load any layers that implement that extension. |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 864 | */ |
Jon Ashburn | b835805 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 865 | |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 866 | // TODO: what about GetPhysicalDeviceExtension for device specific layers/extensions |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 867 | |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 868 | for (j = 0; j < loader.scanned_layer_count; j++) { |
Jon Ashburn | 19c2502 | 2015-04-14 14:14:48 -0600 | [diff] [blame] | 869 | |
| 870 | if (!strcmp("Validation", pExtName)) |
| 871 | must_be_hosted = false; |
| 872 | else |
| 873 | must_be_hosted = true; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 874 | if (has_extension(loader.scanned_layers[j].extensions, |
| 875 | loader.scanned_layers[j].extension_count, pExtName, |
Jon Ashburn | 19c2502 | 2015-04-14 14:14:48 -0600 | [diff] [blame] | 876 | must_be_hosted)) { |
Jon Ashburn | b835805 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 877 | |
Jon Ashburn | 19c2502 | 2015-04-14 14:14:48 -0600 | [diff] [blame] | 878 | found = true; |
| 879 | lib_name[found_count] = loader.scanned_layers[j].name; |
| 880 | found_count++; |
| 881 | } else { |
| 882 | // Extension not found in list for the layer, so test the layer name |
| 883 | // as if it is an extension name. Use default layer name based on |
| 884 | // library name VK_LAYER_LIBRARY_PREFIX<name>.VK_LIBRARY_SUFFIX |
| 885 | char *pEnd; |
| 886 | size_t siz; |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 887 | |
Jon Ashburn | 19c2502 | 2015-04-14 14:14:48 -0600 | [diff] [blame] | 888 | search_name = loader.scanned_layers[j].name; |
| 889 | search_name = basename(search_name); |
| 890 | search_name += strlen(VK_LAYER_LIBRARY_PREFIX); |
| 891 | pEnd = strrchr(search_name, '.'); |
| 892 | siz = (int) (pEnd - search_name); |
| 893 | if (siz != strlen(pExtName)) |
| 894 | continue; |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 895 | |
Jon Ashburn | 19c2502 | 2015-04-14 14:14:48 -0600 | [diff] [blame] | 896 | if (strncmp(search_name, pExtName, siz) == 0) { |
| 897 | found = true; |
| 898 | lib_name[found_count] = loader.scanned_layers[j].name; |
| 899 | found_count++; |
| 900 | } |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 901 | } |
| 902 | } |
Jon Ashburn | 19c2502 | 2015-04-14 14:14:48 -0600 | [diff] [blame] | 903 | |
| 904 | *out_count = found_count; |
| 905 | return found; |
Jon Ashburn | b835805 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 906 | } |
| 907 | |
Jon Ashburn | 3d45475 | 2015-05-08 14:35:08 -0600 | [diff] [blame] | 908 | static uint32_t loader_get_layer_env(struct layer_name_pair *pLayerNames) |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 909 | { |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 910 | char *layerEnv; |
Jon Ashburn | 19c2502 | 2015-04-14 14:14:48 -0600 | [diff] [blame] | 911 | uint32_t i, len, found_count, count = 0; |
Jon Ashburn | d09bd10 | 2014-10-22 21:15:26 -0600 | [diff] [blame] | 912 | char *p, *pOrig, *next, *name; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 913 | |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 914 | #if defined(WIN32) |
| 915 | layerEnv = loader_get_registry_and_env(LAYER_NAMES_ENV, |
| 916 | LAYER_NAMES_REGISTRY_VALUE); |
| 917 | #else // WIN32 |
| 918 | layerEnv = getenv(LAYER_NAMES_ENV); |
| 919 | #endif // WIN32 |
| 920 | if (layerEnv == NULL) { |
Jon Ashburn | 3fb5544 | 2014-10-23 10:29:09 -0600 | [diff] [blame] | 921 | return 0; |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 922 | } |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 923 | p = malloc(strlen(layerEnv) + 1); |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 924 | if (p == NULL) { |
| 925 | #if defined(WIN32) |
| 926 | free(layerEnv); |
| 927 | #endif // WIN32 |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 928 | return 0; |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 929 | } |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 930 | strcpy(p, layerEnv); |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 931 | #if defined(WIN32) |
| 932 | free(layerEnv); |
| 933 | #endif // WIN32 |
Jon Ashburn | d09bd10 | 2014-10-22 21:15:26 -0600 | [diff] [blame] | 934 | pOrig = p; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 935 | |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 936 | while (p && *p && count < MAX_LAYER_LIBRARIES) { |
Jon Ashburn | 19c2502 | 2015-04-14 14:14:48 -0600 | [diff] [blame] | 937 | char *lib_name[MAX_LAYER_LIBRARIES]; |
| 938 | //memset(&lib_name[0], 0, sizeof(const char *) * MAX_LAYER_LIBRARIES); |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 939 | next = strchr(p, PATH_SEPERATOR); |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 940 | if (next == NULL) { |
Ian Elliott | 1962880 | 2015-02-04 12:06:46 -0700 | [diff] [blame] | 941 | len = (uint32_t) strlen(p); |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 942 | next = p + len; |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 943 | } else { |
Ian Elliott | 1962880 | 2015-02-04 12:06:46 -0700 | [diff] [blame] | 944 | len = (uint32_t) (next - p); |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 945 | *(char *) next = '\0'; |
| 946 | next++; |
| 947 | } |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 948 | name = basename(p); |
Jon Ashburn | 3d45475 | 2015-05-08 14:35:08 -0600 | [diff] [blame] | 949 | if (!find_layer_extension(name, &found_count, lib_name)) { |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 950 | p = next; |
| 951 | continue; |
| 952 | } |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 953 | |
Jon Ashburn | 19c2502 | 2015-04-14 14:14:48 -0600 | [diff] [blame] | 954 | for (i = 0; i < found_count; i++) { |
| 955 | len = (uint32_t) strlen(name); |
| 956 | pLayerNames[count].layer_name = malloc(len + 1); |
| 957 | if (!pLayerNames[count].layer_name) { |
| 958 | free(pOrig); |
| 959 | return count; |
| 960 | } |
| 961 | strncpy((char *) pLayerNames[count].layer_name, name, len); |
| 962 | pLayerNames[count].layer_name[len] = '\0'; |
| 963 | pLayerNames[count].lib_name = lib_name[i]; |
| 964 | count++; |
Jon Ashburn | d09bd10 | 2014-10-22 21:15:26 -0600 | [diff] [blame] | 965 | } |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 966 | p = next; |
| 967 | |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 968 | } |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 969 | |
Jon Ashburn | d09bd10 | 2014-10-22 21:15:26 -0600 | [diff] [blame] | 970 | free(pOrig); |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 971 | return count; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 972 | } |
| 973 | |
Jon Ashburn | 3d45475 | 2015-05-08 14:35:08 -0600 | [diff] [blame] | 974 | static uint32_t loader_get_layer_libs(uint32_t ext_count, const char *const* ext_names, struct layer_name_pair **ppLayerNames) |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 975 | { |
Jon Ashburn | b835805 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 976 | static struct layer_name_pair layerNames[MAX_LAYER_LIBRARIES]; |
Jon Ashburn | 19c2502 | 2015-04-14 14:14:48 -0600 | [diff] [blame] | 977 | char *lib_name[MAX_LAYER_LIBRARIES]; |
| 978 | uint32_t found_count, count = 0; |
| 979 | bool skip; |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 980 | |
| 981 | *ppLayerNames = &layerNames[0]; |
Courtney Goeltzenleuchter | 89ba928 | 2015-02-17 14:21:21 -0700 | [diff] [blame] | 982 | /* Load any layers specified in the environment first */ |
Jon Ashburn | 3d45475 | 2015-05-08 14:35:08 -0600 | [diff] [blame] | 983 | count = loader_get_layer_env(layerNames); |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 984 | |
Jon Ashburn | bacb0f5 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 985 | for (uint32_t i = 0; i < ext_count; i++) { |
| 986 | const char *pExtName = ext_names[i]; |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 987 | |
Jon Ashburn | 19c2502 | 2015-04-14 14:14:48 -0600 | [diff] [blame] | 988 | skip = false; |
| 989 | for (uint32_t j = 0; j < count; j++) { |
| 990 | if (!strcmp(pExtName, layerNames[j].layer_name) ) { |
| 991 | // Extension / Layer already on the list skip it |
| 992 | skip = true; |
| 993 | break; |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 994 | } |
Jon Ashburn | 19c2502 | 2015-04-14 14:14:48 -0600 | [diff] [blame] | 995 | } |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 996 | |
Jon Ashburn | 3d45475 | 2015-05-08 14:35:08 -0600 | [diff] [blame] | 997 | if (!skip && find_layer_extension(pExtName, &found_count, lib_name)) { |
Jon Ashburn | 19c2502 | 2015-04-14 14:14:48 -0600 | [diff] [blame] | 998 | |
| 999 | for (uint32_t j = 0; j < found_count; j++) { |
| 1000 | uint32_t len; |
| 1001 | len = (uint32_t) strlen(pExtName); |
| 1002 | |
| 1003 | |
| 1004 | layerNames[count].layer_name = malloc(len + 1); |
| 1005 | if (!layerNames[count].layer_name) |
| 1006 | return count; |
| 1007 | strncpy((char *) layerNames[count].layer_name, pExtName, len); |
| 1008 | layerNames[count].layer_name[len] = '\0'; |
| 1009 | layerNames[count].lib_name = lib_name[j]; |
| 1010 | count++; |
| 1011 | } |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 1012 | } |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 1013 | } |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 1014 | |
| 1015 | return count; |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 1016 | } |
| 1017 | |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 1018 | //TODO static void loader_deactivate_device_layer(device) |
| 1019 | |
| 1020 | static void loader_deactivate_instance_layer(const struct loader_instance *instance) |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 1021 | { |
| 1022 | struct loader_icd *icd; |
| 1023 | struct loader_layers *libs; |
| 1024 | |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 1025 | for (icd = instance->icds; icd; icd = icd->next) { |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 1026 | if (icd->gpus) |
| 1027 | free(icd->gpus); |
| 1028 | icd->gpus = NULL; |
| 1029 | if (icd->loader_dispatch) |
| 1030 | free(icd->loader_dispatch); |
| 1031 | icd->loader_dispatch = NULL; |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1032 | for (uint32_t j = 0; j < icd->gpu_count; j++) { |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 1033 | if (icd->layer_count[j] > 0) { |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1034 | for (uint32_t i = 0; i < icd->layer_count[j]; i++) { |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 1035 | libs = &(icd->layer_libs[j][i]); |
| 1036 | if (libs->lib_handle) |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1037 | loader_platform_close_library(libs->lib_handle); |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 1038 | libs->lib_handle = NULL; |
| 1039 | } |
Jon Ashburn | d09bd10 | 2014-10-22 21:15:26 -0600 | [diff] [blame] | 1040 | if (icd->wrappedGpus[j]) |
| 1041 | free(icd->wrappedGpus[j]); |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 1042 | } |
| 1043 | icd->layer_count[j] = 0; |
| 1044 | } |
| 1045 | icd->gpu_count = 0; |
| 1046 | } |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 1047 | |
| 1048 | free(instance->wrappedInstance); |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 1049 | } |
| 1050 | |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 1051 | uint32_t loader_activate_instance_layers(struct loader_instance *inst) |
| 1052 | { |
| 1053 | uint32_t count; |
| 1054 | struct layer_name_pair *pLayerNames; |
| 1055 | if (inst == NULL) |
| 1056 | return 0; |
| 1057 | |
| 1058 | // NOTE inst is unwrapped at this point in time |
| 1059 | VkObject baseObj = (VkObject) inst; |
| 1060 | VkObject nextObj = (VkObject) inst; |
| 1061 | VkBaseLayerObject *nextInstObj; |
| 1062 | PFN_vkGetInstanceProcAddr nextGPA = loader_gpa_instance_internal; |
| 1063 | |
| 1064 | count = loader_get_layer_libs(inst->extension_count, (const char *const*) inst->extension_names, &pLayerNames); |
| 1065 | if (!count) |
| 1066 | return 0; |
| 1067 | loader_init_instance_layer_libs(inst, pLayerNames, count); |
| 1068 | |
| 1069 | inst->wrappedInstance = malloc(sizeof(VkBaseLayerObject) * count); |
| 1070 | if (! inst->wrappedInstance) { |
| 1071 | loader_log(VK_DBG_MSG_ERROR, 0, "Failed to malloc Instance objects for layer"); |
| 1072 | return 0; |
| 1073 | } |
| 1074 | for (int32_t i = count - 1; i >= 0; i--) { |
| 1075 | nextInstObj = (inst->wrappedInstance + i); |
| 1076 | nextInstObj->pGPA = nextGPA; |
| 1077 | nextInstObj->baseObject = baseObj; |
| 1078 | nextInstObj->nextObject = nextObj; |
| 1079 | nextObj = (VkObject) nextInstObj; |
| 1080 | |
| 1081 | char funcStr[256]; |
| 1082 | snprintf(funcStr, 256, "%sGetInstanceProcAddr",inst->layer_libs[i].name); |
| 1083 | if ((nextGPA = (PFN_vkGetInstanceProcAddr) loader_platform_get_proc_address(inst->layer_libs[i].lib_handle, funcStr)) == NULL) |
| 1084 | nextGPA = (PFN_vkGetInstanceProcAddr) loader_platform_get_proc_address(inst->layer_libs[i].lib_handle, "vkGetInstanceProcAddr"); |
| 1085 | if (!nextGPA) { |
| 1086 | loader_log(VK_DBG_MSG_ERROR, 0, "Failed to find vkGetInstanceProcAddr in layer %s", inst->layer_libs[i].name); |
| 1087 | continue; |
| 1088 | } |
| 1089 | |
| 1090 | if (i == 0) { |
| 1091 | loader_init_instance_dispatch_table(inst->disp, nextGPA, (VkInstance) nextObj); |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 1092 | } |
| 1093 | |
| 1094 | } |
| 1095 | |
| 1096 | return inst->layer_count; |
| 1097 | } |
| 1098 | |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 1099 | uint32_t loader_activate_device_layers(VkDevice device, struct loader_icd *icd, uint32_t gpu_index, uint32_t ext_count, const char *const* ext_names) |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 1100 | { |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1101 | uint32_t count; |
Jon Ashburn | b835805 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 1102 | struct layer_name_pair *pLayerNames; |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 1103 | if (!icd) |
| 1104 | return 0; |
Jon Ashburn | 83a6425 | 2015-04-15 11:31:12 -0600 | [diff] [blame] | 1105 | assert(gpu_index < MAX_GPUS_FOR_LAYER); |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 1106 | |
| 1107 | /* activate any layer libraries */ |
| 1108 | if (!loader_layers_activated(icd, gpu_index)) { |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 1109 | VkObject nextObj = (VkObject) device; |
| 1110 | VkObject baseObj = nextObj; |
| 1111 | VkBaseLayerObject *nextGpuObj; |
Jon Ashburn | 7c09612 | 2015-05-22 09:19:49 -0600 | [diff] [blame] | 1112 | PFN_vkGetDeviceProcAddr nextGPA = icd->GetDeviceProcAddr; |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 1113 | |
Jon Ashburn | 3d45475 | 2015-05-08 14:35:08 -0600 | [diff] [blame] | 1114 | count = loader_get_layer_libs(ext_count, ext_names, &pLayerNames); |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 1115 | if (!count) |
| 1116 | return 0; |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 1117 | loader_init_device_layer_libs(icd, gpu_index, pLayerNames, count); |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 1118 | |
Jon Ashburn | bacb0f5 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 1119 | icd->wrappedGpus[gpu_index] = malloc(sizeof(VkBaseLayerObject) * icd->layer_count[gpu_index]); |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 1120 | if (! icd->wrappedGpus[gpu_index]) { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1121 | loader_log(VK_DBG_MSG_ERROR, 0, "Failed to malloc Gpu objects for layer"); |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 1122 | return 0; |
| 1123 | } |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1124 | 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] | 1125 | nextGpuObj = (icd->wrappedGpus[gpu_index] + i); |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 1126 | nextGpuObj->pGPA = nextGPA; |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 1127 | nextGpuObj->baseObject = baseObj; |
| 1128 | nextGpuObj->nextObject = nextObj; |
| 1129 | nextObj = (VkObject) nextGpuObj; |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 1130 | |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 1131 | char funcStr[256]; |
Jon Ashburn | 8d1b0b5 | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 1132 | snprintf(funcStr, 256, "%sGetDeviceProcAddr",icd->layer_libs[gpu_index][i].name); |
| 1133 | if ((nextGPA = (PFN_vkGetDeviceProcAddr) loader_platform_get_proc_address(icd->layer_libs[gpu_index][i].lib_handle, funcStr)) == NULL) |
| 1134 | nextGPA = (PFN_vkGetDeviceProcAddr) loader_platform_get_proc_address(icd->layer_libs[gpu_index][i].lib_handle, "vkGetDeviceProcAddr"); |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 1135 | if (!nextGPA) { |
Jon Ashburn | 8d1b0b5 | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 1136 | loader_log(VK_DBG_MSG_ERROR, 0, "Failed to find vkGetDeviceProcAddr in layer %s", icd->layer_libs[gpu_index][i].name); |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 1137 | continue; |
| 1138 | } |
| 1139 | |
Jon Ashburn | f261001 | 2014-10-24 15:48:55 -0600 | [diff] [blame] | 1140 | if (i == 0) { |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 1141 | loader_init_device_dispatch_table(icd->loader_dispatch + gpu_index, nextGPA, (VkPhysicalDevice) nextObj); |
Jon Ashburn | f261001 | 2014-10-24 15:48:55 -0600 | [diff] [blame] | 1142 | //Insert the new wrapped objects into the list with loader object at head |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 1143 | nextGpuObj = icd->wrappedGpus[gpu_index] + icd->layer_count[gpu_index] - 1; |
| 1144 | nextGpuObj->nextObject = baseObj; |
Jon Ashburn | 8d1b0b5 | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 1145 | nextGpuObj->pGPA = icd->GetDeviceProcAddr; |
Jon Ashburn | f261001 | 2014-10-24 15:48:55 -0600 | [diff] [blame] | 1146 | } |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 1147 | |
| 1148 | } |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 1149 | } |
| 1150 | else { |
| 1151 | //make sure requested Layers matches currently activated Layers |
Jon Ashburn | 3d45475 | 2015-05-08 14:35:08 -0600 | [diff] [blame] | 1152 | count = loader_get_layer_libs(ext_count, ext_names, &pLayerNames); |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1153 | for (uint32_t i = 0; i < count; i++) { |
Jon Ashburn | b835805 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 1154 | 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] | 1155 | loader_log(VK_DBG_MSG_ERROR, 0, "Layers activated != Layers requested"); |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 1156 | break; |
| 1157 | } |
| 1158 | } |
| 1159 | if (count != icd->layer_count[gpu_index]) { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1160 | 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] | 1161 | } |
| 1162 | } |
| 1163 | return icd->layer_count[gpu_index]; |
| 1164 | } |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 1165 | |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 1166 | VkResult loader_CreateInstance( |
Courtney Goeltzenleuchter | 95487bc | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 1167 | const VkInstanceCreateInfo* pCreateInfo, |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1168 | VkInstance* pInstance) |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 1169 | { |
Jon Ashburn | eed0c00 | 2015-05-21 17:42:17 -0600 | [diff] [blame] | 1170 | struct loader_instance *ptr_instance = *(struct loader_instance **) pInstance; |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 1171 | struct loader_scanned_icds *scanned_icds; |
| 1172 | struct loader_icd *icd; |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 1173 | VkResult res; |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 1174 | |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 1175 | scanned_icds = loader.scanned_icd_list; |
| 1176 | while (scanned_icds) { |
| 1177 | icd = loader_icd_add(ptr_instance, scanned_icds); |
| 1178 | if (icd) { |
Jon Ashburn | b317fad | 2015-04-04 14:52:07 -0600 | [diff] [blame] | 1179 | res = scanned_icds->CreateInstance(pCreateInfo, |
Jon Ashburn | 3da71f2 | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 1180 | &(icd->instance)); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1181 | if (res != VK_SUCCESS) |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 1182 | { |
| 1183 | ptr_instance->icds = ptr_instance->icds->next; |
| 1184 | loader_icd_destroy(icd); |
Jon Ashburn | 3da71f2 | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 1185 | icd->instance = VK_NULL_HANDLE; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1186 | loader_log(VK_DBG_MSG_WARNING, 0, |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 1187 | "ICD ignored: failed to CreateInstance on device"); |
Jon Ashburn | 3da71f2 | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 1188 | } else |
| 1189 | { |
| 1190 | loader_icd_init_entrys(icd, scanned_icds); |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 1191 | } |
| 1192 | } |
| 1193 | scanned_icds = scanned_icds->next; |
| 1194 | } |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 1195 | |
Ian Elliott | eb45076 | 2015-02-05 15:19:15 -0700 | [diff] [blame] | 1196 | if (ptr_instance->icds == NULL) { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1197 | return VK_ERROR_INCOMPATIBLE_DRIVER; |
Ian Elliott | eb45076 | 2015-02-05 15:19:15 -0700 | [diff] [blame] | 1198 | } |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 1199 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1200 | return VK_SUCCESS; |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 1201 | } |
| 1202 | |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 1203 | VkResult loader_DestroyInstance( |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1204 | VkInstance instance) |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 1205 | { |
| 1206 | struct loader_instance *ptr_instance = (struct loader_instance *) instance; |
Jon Ashburn | 3da71f2 | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 1207 | struct loader_icd *icds = ptr_instance->icds; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1208 | VkResult res; |
Jon Ashburn | 340d666 | 2015-04-08 15:49:00 -0600 | [diff] [blame] | 1209 | uint32_t i; |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 1210 | |
| 1211 | // Remove this instance from the list of instances: |
| 1212 | struct loader_instance *prev = NULL; |
| 1213 | struct loader_instance *next = loader.instances; |
| 1214 | while (next != NULL) { |
| 1215 | if (next == ptr_instance) { |
| 1216 | // Remove this instance from the list: |
Jon Ashburn | 340d666 | 2015-04-08 15:49:00 -0600 | [diff] [blame] | 1217 | for (i = 0; i < ptr_instance->extension_count; i++) { |
| 1218 | free(ptr_instance->extension_names[i]); |
| 1219 | } |
Jon Ashburn | f347439 | 2015-05-19 14:33:18 -0600 | [diff] [blame] | 1220 | free(ptr_instance->disp); |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 1221 | if (prev) |
| 1222 | prev->next = next->next; |
Jon Ashburn | c5c4960 | 2015-02-03 09:26:59 -0700 | [diff] [blame] | 1223 | else |
| 1224 | loader.instances = next->next; |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 1225 | break; |
| 1226 | } |
| 1227 | prev = next; |
| 1228 | next = next->next; |
| 1229 | } |
| 1230 | if (next == NULL) { |
| 1231 | // This must be an invalid instance handle or empty list |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1232 | return VK_ERROR_INVALID_HANDLE; |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 1233 | } |
| 1234 | |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 1235 | loader_deactivate_instance_layer(ptr_instance); |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 1236 | |
Jon Ashburn | 3da71f2 | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 1237 | while (icds) { |
| 1238 | if (icds->instance) { |
| 1239 | res = icds->DestroyInstance(icds->instance); |
Tony Barbour | f20f87b | 2015-04-22 09:02:32 -0600 | [diff] [blame] | 1240 | if (res != VK_SUCCESS) |
| 1241 | loader_log(VK_DBG_MSG_WARNING, 0, |
| 1242 | "ICD ignored: failed to DestroyInstance on device"); |
| 1243 | } |
Jon Ashburn | 3da71f2 | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 1244 | icds->instance = VK_NULL_HANDLE; |
| 1245 | icds = icds->next; |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 1246 | } |
| 1247 | |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 1248 | free(ptr_instance); |
| 1249 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1250 | return VK_SUCCESS; |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 1251 | } |
| 1252 | |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 1253 | VkResult loader_EnumeratePhysicalDevices( |
Courtney Goeltzenleuchter | 5e41f1d | 2015-04-20 12:48:54 -0600 | [diff] [blame] | 1254 | VkInstance instance, |
| 1255 | uint32_t* pPhysicalDeviceCount, |
| 1256 | VkPhysicalDevice* pPhysicalDevices) |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 1257 | { |
Jon Ashburn | 4c392fb | 2015-01-28 19:57:09 -0700 | [diff] [blame] | 1258 | struct loader_instance *ptr_instance = (struct loader_instance *) instance; |
| 1259 | struct loader_icd *icd; |
Jon Ashburn | 83a6425 | 2015-04-15 11:31:12 -0600 | [diff] [blame] | 1260 | uint32_t n, count = 0; |
Tony Barbour | f20f87b | 2015-04-22 09:02:32 -0600 | [diff] [blame] | 1261 | VkResult res = VK_ERROR_UNKNOWN; |
Jon Ashburn | 4c392fb | 2015-01-28 19:57:09 -0700 | [diff] [blame] | 1262 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1263 | //in spirit of VK don't error check on the instance parameter |
Jon Ashburn | 4c392fb | 2015-01-28 19:57:09 -0700 | [diff] [blame] | 1264 | icd = ptr_instance->icds; |
Jon Ashburn | 83a6425 | 2015-04-15 11:31:12 -0600 | [diff] [blame] | 1265 | if (pPhysicalDevices == NULL) { |
| 1266 | while (icd) { |
Jon Ashburn | 3da71f2 | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 1267 | res = icd->EnumeratePhysicalDevices( |
| 1268 | icd->instance, |
Jon Ashburn | 83a6425 | 2015-04-15 11:31:12 -0600 | [diff] [blame] | 1269 | &n, NULL); |
| 1270 | if (res != VK_SUCCESS) |
| 1271 | return res; |
| 1272 | icd->gpu_count = n; |
| 1273 | count += n; |
| 1274 | icd = icd->next; |
Jon Ashburn | 4c392fb | 2015-01-28 19:57:09 -0700 | [diff] [blame] | 1275 | } |
| 1276 | |
Jon Ashburn | 83a6425 | 2015-04-15 11:31:12 -0600 | [diff] [blame] | 1277 | ptr_instance->total_gpu_count = count; |
Courtney Goeltzenleuchter | 64ca923 | 2015-02-10 18:40:14 -0700 | [diff] [blame] | 1278 | |
Jon Ashburn | 83a6425 | 2015-04-15 11:31:12 -0600 | [diff] [blame] | 1279 | } else |
| 1280 | { |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 1281 | VkPhysicalDevice* gpus; |
Jon Ashburn | 83a6425 | 2015-04-15 11:31:12 -0600 | [diff] [blame] | 1282 | if (*pPhysicalDeviceCount < ptr_instance->total_gpu_count) |
| 1283 | return VK_ERROR_INVALID_VALUE; |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 1284 | gpus = malloc( sizeof(VkPhysicalDevice) * *pPhysicalDeviceCount); |
Jon Ashburn | 83a6425 | 2015-04-15 11:31:12 -0600 | [diff] [blame] | 1285 | if (!gpus) |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 1286 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Jon Ashburn | 83a6425 | 2015-04-15 11:31:12 -0600 | [diff] [blame] | 1287 | while (icd) { |
| 1288 | VkBaseLayerObject * wrapped_gpus; |
Jon Ashburn | 8d1b0b5 | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 1289 | PFN_vkGetDeviceProcAddr get_proc_addr = icd->GetDeviceProcAddr; |
Jon Ashburn | 83a6425 | 2015-04-15 11:31:12 -0600 | [diff] [blame] | 1290 | |
Courtney Goeltzenleuchter | 5e41f1d | 2015-04-20 12:48:54 -0600 | [diff] [blame] | 1291 | n = *pPhysicalDeviceCount; |
Jon Ashburn | 3da71f2 | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 1292 | res = icd->EnumeratePhysicalDevices( |
| 1293 | icd->instance, |
Jon Ashburn | 83a6425 | 2015-04-15 11:31:12 -0600 | [diff] [blame] | 1294 | &n, |
| 1295 | gpus); |
| 1296 | if (res == VK_SUCCESS && n) { |
| 1297 | wrapped_gpus = (VkBaseLayerObject*) malloc(n * |
| 1298 | sizeof(VkBaseLayerObject)); |
| 1299 | icd->gpus = wrapped_gpus; |
| 1300 | icd->gpu_count = n; |
| 1301 | icd->loader_dispatch = (VkLayerDispatchTable *) malloc(n * |
| 1302 | sizeof(VkLayerDispatchTable)); |
| 1303 | for (unsigned int i = 0; i < n; i++) { |
| 1304 | (wrapped_gpus + i)->baseObject = gpus[i]; |
| 1305 | (wrapped_gpus + i)->pGPA = get_proc_addr; |
| 1306 | (wrapped_gpus + i)->nextObject = gpus[i]; |
| 1307 | memcpy(pPhysicalDevices + count, gpus, sizeof(*pPhysicalDevices)); |
Jon Ashburn | fbb4e25 | 2015-05-04 16:27:53 -0600 | [diff] [blame] | 1308 | loader_init_device_dispatch_table(icd->loader_dispatch + i, |
Jon Ashburn | 83a6425 | 2015-04-15 11:31:12 -0600 | [diff] [blame] | 1309 | get_proc_addr, gpus[i]); |
| 1310 | |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 1311 | loader_init_dispatch(gpus[i], ptr_instance->disp); |
Courtney Goeltzenleuchter | 64ca923 | 2015-02-10 18:40:14 -0700 | [diff] [blame] | 1312 | } |
| 1313 | |
Jon Ashburn | 83a6425 | 2015-04-15 11:31:12 -0600 | [diff] [blame] | 1314 | count += n; |
| 1315 | |
| 1316 | if (count >= *pPhysicalDeviceCount) { |
| 1317 | break; |
| 1318 | } |
Jon Ashburn | 4c392fb | 2015-01-28 19:57:09 -0700 | [diff] [blame] | 1319 | } |
| 1320 | |
Jon Ashburn | 83a6425 | 2015-04-15 11:31:12 -0600 | [diff] [blame] | 1321 | icd = icd->next; |
Jon Ashburn | 4c392fb | 2015-01-28 19:57:09 -0700 | [diff] [blame] | 1322 | } |
Jon Ashburn | 4c392fb | 2015-01-28 19:57:09 -0700 | [diff] [blame] | 1323 | } |
| 1324 | |
Jon Ashburn | 83a6425 | 2015-04-15 11:31:12 -0600 | [diff] [blame] | 1325 | *pPhysicalDeviceCount = count; |
Jon Ashburn | 4c392fb | 2015-01-28 19:57:09 -0700 | [diff] [blame] | 1326 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1327 | return (count > 0) ? VK_SUCCESS : res; |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 1328 | } |
| 1329 | |
Jon Ashburn | 3da71f2 | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 1330 | VkResult loader_GetPhysicalDeviceInfo( |
| 1331 | VkPhysicalDevice gpu, |
| 1332 | VkPhysicalDeviceInfoType infoType, |
| 1333 | size_t* pDataSize, |
| 1334 | void* pData) |
| 1335 | { |
| 1336 | uint32_t gpu_index; |
| 1337 | struct loader_icd *icd = loader_get_icd((const VkBaseLayerObject *) gpu, &gpu_index); |
| 1338 | VkResult res = VK_ERROR_INITIALIZATION_FAILED; |
| 1339 | |
| 1340 | if (icd->GetPhysicalDeviceInfo) |
| 1341 | res = icd->GetPhysicalDeviceInfo(gpu, infoType, pDataSize, pData); |
| 1342 | |
| 1343 | return res; |
| 1344 | } |
| 1345 | |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 1346 | VkResult loader_CreateDevice( |
| 1347 | VkPhysicalDevice gpu, |
| 1348 | const VkDeviceCreateInfo* pCreateInfo, |
| 1349 | VkDevice* pDevice) |
| 1350 | { |
| 1351 | uint32_t gpu_index; |
| 1352 | struct loader_icd *icd = loader_get_icd((const VkBaseLayerObject *) gpu, &gpu_index); |
| 1353 | VkResult res = VK_ERROR_INITIALIZATION_FAILED; |
| 1354 | struct loader_instance *ptr_instance; |
| 1355 | |
| 1356 | ptr_instance = loader.instances; |
| 1357 | if (icd->CreateDevice) { |
| 1358 | res = icd->CreateDevice(gpu, pCreateInfo, pDevice); |
| 1359 | if (res == VK_SUCCESS) { |
| 1360 | VkLayerDispatchTable *dev_disp = icd->loader_dispatch + gpu_index; |
| 1361 | loader_init_dispatch(*pDevice, dev_disp); |
| 1362 | } |
| 1363 | //TODO fix this extension parameters once support GetDeviceExtensionInfo() |
| 1364 | // don't know which instance we are on with this call |
| 1365 | |
| 1366 | loader_activate_device_layers(*pDevice, icd, gpu_index, ptr_instance->extension_count, |
| 1367 | (const char *const*) ptr_instance->extension_names); |
| 1368 | } |
| 1369 | |
| 1370 | return res; |
| 1371 | } |
| 1372 | |
Jon Ashburn | b0fbe91 | 2015-05-06 10:15:07 -0600 | [diff] [blame] | 1373 | LOADER_EXPORT void * VKAPI vkGetInstanceProcAddr(VkInstance instance, const char * pName) |
| 1374 | { |
Jon Ashburn | 07daee7 | 2015-05-21 18:13:33 -0600 | [diff] [blame] | 1375 | if (instance == VK_NULL_HANDLE) |
| 1376 | return NULL; |
| 1377 | void *addr; |
| 1378 | /* get entrypoint addresses that are global (in the loader)*/ |
| 1379 | addr = globalGetProcAddr(pName); |
| 1380 | if (addr) |
| 1381 | return addr; |
Jon Ashburn | b0fbe91 | 2015-05-06 10:15:07 -0600 | [diff] [blame] | 1382 | |
Jon Ashburn | 07daee7 | 2015-05-21 18:13:33 -0600 | [diff] [blame] | 1383 | /* return any extension global entrypoints */ |
Jon Ashburn | 35842a3 | 2015-05-22 09:51:03 -0600 | [diff] [blame] | 1384 | bool wsi_enabled; |
| 1385 | addr = wsi_lunarg_GetInstanceProcAddr(instance, pName, &wsi_enabled); |
Jon Ashburn | 07daee7 | 2015-05-21 18:13:33 -0600 | [diff] [blame] | 1386 | if (addr) |
Jon Ashburn | 35842a3 | 2015-05-22 09:51:03 -0600 | [diff] [blame] | 1387 | return (wsi_enabled) ? addr : NULL; |
Jon Ashburn | 07daee7 | 2015-05-21 18:13:33 -0600 | [diff] [blame] | 1388 | |
| 1389 | /* return the instance dispatch table entrypoint for extensions */ |
| 1390 | const VkLayerInstanceDispatchTable *disp_table = * (VkLayerInstanceDispatchTable **) instance; |
| 1391 | if (disp_table == NULL) |
| 1392 | return NULL; |
| 1393 | |
| 1394 | addr = loader_lookup_instance_dispatch_table(disp_table, pName); |
| 1395 | if (addr) |
| 1396 | return addr; |
Jon Ashburn | b0fbe91 | 2015-05-06 10:15:07 -0600 | [diff] [blame] | 1397 | |
| 1398 | return NULL; |
| 1399 | } |
| 1400 | |
Jon Ashburn | 8d1b0b5 | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 1401 | LOADER_EXPORT void * VKAPI vkGetDeviceProcAddr(VkDevice device, const char * pName) |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 1402 | { |
Jon Ashburn | 8d1b0b5 | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 1403 | if (device == VK_NULL_HANDLE) { |
| 1404 | return NULL; |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1405 | } |
Jon Ashburn | 3d526cb | 2015-04-13 18:10:06 -0600 | [diff] [blame] | 1406 | |
Chia-I Wu | f46b81a | 2015-01-04 11:12:47 +0800 | [diff] [blame] | 1407 | void *addr; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 1408 | |
Jon Ashburn | 3d526cb | 2015-04-13 18:10:06 -0600 | [diff] [blame] | 1409 | /* for entrypoints that loader must handle (ie non-dispatchable or create object) |
| 1410 | make sure the loader entrypoint is returned */ |
| 1411 | addr = loader_non_passthrough_gpa(pName); |
Ian Elliott | e19c915 | 2015-04-15 12:53:19 -0600 | [diff] [blame] | 1412 | if (addr) { |
Jon Ashburn | 3d526cb | 2015-04-13 18:10:06 -0600 | [diff] [blame] | 1413 | return addr; |
Ian Elliott | e19c915 | 2015-04-15 12:53:19 -0600 | [diff] [blame] | 1414 | } |
Jon Ashburn | 3d526cb | 2015-04-13 18:10:06 -0600 | [diff] [blame] | 1415 | |
Jon Ashburn | 07daee7 | 2015-05-21 18:13:33 -0600 | [diff] [blame] | 1416 | /* return any extension device entrypoints the loader knows about */ |
Jon Ashburn | 35842a3 | 2015-05-22 09:51:03 -0600 | [diff] [blame] | 1417 | bool wsi_enabled; |
| 1418 | addr = wsi_lunarg_GetDeviceProcAddr(device, pName, &wsi_enabled); |
Jon Ashburn | 07daee7 | 2015-05-21 18:13:33 -0600 | [diff] [blame] | 1419 | if (addr) |
Jon Ashburn | 35842a3 | 2015-05-22 09:51:03 -0600 | [diff] [blame] | 1420 | return (wsi_enabled) ? addr : NULL; |
Jon Ashburn | 07daee7 | 2015-05-21 18:13:33 -0600 | [diff] [blame] | 1421 | |
Jon Ashburn | 3d526cb | 2015-04-13 18:10:06 -0600 | [diff] [blame] | 1422 | /* return the dispatch table entrypoint for the fastest case */ |
Jon Ashburn | 8d1b0b5 | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 1423 | const VkLayerDispatchTable *disp_table = * (VkLayerDispatchTable **) device; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 1424 | if (disp_table == NULL) |
| 1425 | return NULL; |
| 1426 | |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 1427 | addr = loader_lookup_device_dispatch_table(disp_table, pName); |
Chia-I Wu | f46b81a | 2015-01-04 11:12:47 +0800 | [diff] [blame] | 1428 | if (addr) |
| 1429 | return addr; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 1430 | else { |
Jon Ashburn | 8d1b0b5 | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 1431 | if (disp_table->GetDeviceProcAddr == NULL) |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 1432 | return NULL; |
Jon Ashburn | 8d1b0b5 | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 1433 | return disp_table->GetDeviceProcAddr(device, pName); |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 1434 | } |
| 1435 | } |
| 1436 | |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1437 | //TODO make sure createInstance enables extensions that are valid (loader does) |
| 1438 | //TODO make sure CreateDevice enables extensions that are valid (left for layers/drivers to do) |
| 1439 | |
| 1440 | //TODO how is layer extension going to be enabled? |
| 1441 | //Need to call createInstance on the layer or something |
| 1442 | |
Jon Ashburn | eceb13e | 2015-05-18 15:28:32 -0600 | [diff] [blame] | 1443 | LOADER_EXPORT VkResult VKAPI vkGetGlobalExtensionInfo( |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1444 | VkExtensionInfoType infoType, |
| 1445 | uint32_t extensionIndex, |
| 1446 | size_t* pDataSize, |
| 1447 | void* pData) |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 1448 | { |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1449 | VkExtensionProperties *ext_props; |
| 1450 | uint32_t *count; |
| 1451 | /* Scan/discover all ICD libraries in a single-threaded manner */ |
| 1452 | loader_platform_thread_once(&once_icd, loader_icd_scan); |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 1453 | |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1454 | /* get layer libraries in a single-threaded manner */ |
| 1455 | loader_platform_thread_once(&once_layer, layer_lib_scan); |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 1456 | |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1457 | /* merge any duplicate extensions */ |
| 1458 | loader_platform_thread_once(&once_exts, loader_coalesce_extensions); |
| 1459 | |
| 1460 | |
| 1461 | if (pDataSize == NULL) |
| 1462 | return VK_ERROR_INVALID_POINTER; |
| 1463 | |
| 1464 | switch (infoType) { |
| 1465 | case VK_EXTENSION_INFO_TYPE_COUNT: |
| 1466 | *pDataSize = sizeof(uint32_t); |
| 1467 | if (pData == NULL) |
| 1468 | return VK_SUCCESS; |
| 1469 | count = (uint32_t *) pData; |
| 1470 | *count = loader.scanned_ext_list_count; |
| 1471 | break; |
| 1472 | case VK_EXTENSION_INFO_TYPE_PROPERTIES: |
| 1473 | *pDataSize = sizeof(VkExtensionProperties); |
| 1474 | if (pData == NULL) |
| 1475 | return VK_SUCCESS; |
| 1476 | if (extensionIndex >= loader.scanned_ext_list_count) |
| 1477 | return VK_ERROR_INVALID_VALUE; |
| 1478 | ext_props = (VkExtensionProperties *) pData; |
| 1479 | ext_props->version = loader.scanned_ext_list[extensionIndex]->version; |
| 1480 | strncpy(ext_props->extName, loader.scanned_ext_list[extensionIndex]->extName |
| 1481 | , VK_MAX_EXTENSION_NAME); |
| 1482 | ext_props->extName[VK_MAX_EXTENSION_NAME - 1] = '\0'; |
| 1483 | break; |
| 1484 | default: |
| 1485 | loader_log(VK_DBG_MSG_WARNING, 0, "Invalid infoType in vkGetGlobalExtensionInfo"); |
| 1486 | return VK_ERROR_INVALID_VALUE; |
| 1487 | }; |
| 1488 | |
| 1489 | return VK_SUCCESS; |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 1490 | } |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 1491 | VkResult loader_GetPhysicalDeviceExtensionInfo( |
| 1492 | VkPhysicalDevice gpu, |
| 1493 | VkExtensionInfoType infoType, |
| 1494 | uint32_t extensionIndex, |
| 1495 | size_t* pDataSize, |
| 1496 | void* pData) |
| 1497 | { |
| 1498 | uint32_t gpu_index; |
| 1499 | struct loader_icd *icd = loader_get_icd((const VkBaseLayerObject *) gpu, &gpu_index); |
| 1500 | VkResult res = VK_ERROR_INITIALIZATION_FAILED; |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 1501 | |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 1502 | if (icd->GetPhysicalDeviceExtensionInfo) |
| 1503 | res = icd->GetPhysicalDeviceExtensionInfo(gpu, infoType, extensionIndex, |
| 1504 | pDataSize, pData); |
| 1505 | |
| 1506 | return res; |
| 1507 | } |
| 1508 | |
| 1509 | VkResult loader_EnumerateLayers( |
| 1510 | VkPhysicalDevice gpu, |
| 1511 | size_t maxStringSize, |
| 1512 | size_t* pLayerCount, |
| 1513 | char* const* pOutLayers, |
| 1514 | void* pReserved) |
Jon Ashburn | f7bcf9b | 2014-10-15 15:30:23 -0600 | [diff] [blame] | 1515 | { |
Courtney Goeltzenleuchter | d9dc0c7 | 2015-04-20 11:04:54 -0600 | [diff] [blame] | 1516 | size_t maxLayerCount; |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1517 | uint32_t gpu_index; |
Ian Elliott | 1962880 | 2015-02-04 12:06:46 -0700 | [diff] [blame] | 1518 | size_t count = 0; |
Jon Ashburn | 1323eb7 | 2014-12-02 13:03:09 -0700 | [diff] [blame] | 1519 | char *lib_name; |
Jon Ashburn | bacb0f5 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 1520 | struct loader_icd *icd = loader_get_icd((const VkBaseLayerObject *) gpu, &gpu_index); |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1521 | loader_platform_dl_handle handle; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1522 | PFN_vkEnumerateLayers fpEnumerateLayers; |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1523 | char layer_buf[16][256]; |
| 1524 | char * layers[16]; |
Jon Ashburn | f7bcf9b | 2014-10-15 15:30:23 -0600 | [diff] [blame] | 1525 | |
Courtney Goeltzenleuchter | d9dc0c7 | 2015-04-20 11:04:54 -0600 | [diff] [blame] | 1526 | if (pLayerCount == NULL || pOutLayers == NULL) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1527 | return VK_ERROR_INVALID_POINTER; |
Jon Ashburn | f7bcf9b | 2014-10-15 15:30:23 -0600 | [diff] [blame] | 1528 | |
Courtney Goeltzenleuchter | d9dc0c7 | 2015-04-20 11:04:54 -0600 | [diff] [blame] | 1529 | maxLayerCount = *pLayerCount; |
| 1530 | |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 1531 | if (!icd) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1532 | return VK_ERROR_UNAVAILABLE; |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 1533 | |
Jon Ashburn | 1323eb7 | 2014-12-02 13:03:09 -0700 | [diff] [blame] | 1534 | for (int i = 0; i < 16; i++) |
| 1535 | layers[i] = &layer_buf[i][0]; |
| 1536 | |
| 1537 | for (unsigned int j = 0; j < loader.scanned_layer_count && count < maxLayerCount; j++) { |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1538 | lib_name = loader.scanned_layers[j].name; |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1539 | // Used to call: dlopen(*lib_name, RTLD_LAZY) |
| 1540 | if ((handle = loader_platform_open_library(lib_name)) == NULL) |
Jon Ashburn | 1323eb7 | 2014-12-02 13:03:09 -0700 | [diff] [blame] | 1541 | continue; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1542 | if ((fpEnumerateLayers = loader_platform_get_proc_address(handle, "vkEnumerateLayers")) == NULL) { |
| 1543 | //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] | 1544 | char *pEnd, *cpyStr; |
Ian Elliott | 4204584 | 2015-02-13 14:29:21 -0700 | [diff] [blame] | 1545 | size_t siz; |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1546 | loader_platform_close_library(handle); |
Jon Ashburn | 1323eb7 | 2014-12-02 13:03:09 -0700 | [diff] [blame] | 1547 | lib_name = basename(lib_name); |
| 1548 | pEnd = strrchr(lib_name, '.'); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1549 | siz = (int) (pEnd - lib_name - strlen(VK_LAYER_LIBRARY_PREFIX) + 1); |
Jon Ashburn | 1323eb7 | 2014-12-02 13:03:09 -0700 | [diff] [blame] | 1550 | if (pEnd == NULL || siz <= 0) |
| 1551 | continue; |
| 1552 | cpyStr = malloc(siz); |
| 1553 | if (cpyStr == NULL) { |
| 1554 | free(cpyStr); |
| 1555 | continue; |
| 1556 | } |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1557 | strncpy(cpyStr, lib_name + strlen(VK_LAYER_LIBRARY_PREFIX), siz); |
Jon Ashburn | 1323eb7 | 2014-12-02 13:03:09 -0700 | [diff] [blame] | 1558 | cpyStr[siz - 1] = '\0'; |
| 1559 | if (siz > maxStringSize) |
Ian Elliott | 1962880 | 2015-02-04 12:06:46 -0700 | [diff] [blame] | 1560 | siz = (int) maxStringSize; |
Jon Ashburn | 1323eb7 | 2014-12-02 13:03:09 -0700 | [diff] [blame] | 1561 | strncpy((char *) (pOutLayers[count]), cpyStr, siz); |
| 1562 | pOutLayers[count][siz - 1] = '\0'; |
| 1563 | count++; |
| 1564 | free(cpyStr); |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 1565 | } else { |
Courtney Goeltzenleuchter | d9dc0c7 | 2015-04-20 11:04:54 -0600 | [diff] [blame] | 1566 | size_t cnt = 16; /* only allow 16 layers, for now */ |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1567 | uint32_t n; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1568 | VkResult res; |
Ian Elliott | 1962880 | 2015-02-04 12:06:46 -0700 | [diff] [blame] | 1569 | n = (uint32_t) ((maxStringSize < 256) ? maxStringSize : 256); |
Courtney Goeltzenleuchter | d9dc0c7 | 2015-04-20 11:04:54 -0600 | [diff] [blame] | 1570 | res = fpEnumerateLayers((VkPhysicalDevice) NULL, n, &cnt, layers, (char *) icd->gpus + gpu_index); |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1571 | loader_platform_close_library(handle); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1572 | if (res != VK_SUCCESS) |
Jon Ashburn | 1323eb7 | 2014-12-02 13:03:09 -0700 | [diff] [blame] | 1573 | continue; |
| 1574 | if (cnt + count > maxLayerCount) |
| 1575 | cnt = maxLayerCount - count; |
Ian Elliott | 1962880 | 2015-02-04 12:06:46 -0700 | [diff] [blame] | 1576 | for (uint32_t i = (uint32_t) count; i < cnt + count; i++) { |
Jon Ashburn | 1323eb7 | 2014-12-02 13:03:09 -0700 | [diff] [blame] | 1577 | strncpy((char *) (pOutLayers[i]), (char *) layers[i - count], n); |
| 1578 | if (n > 0) |
| 1579 | pOutLayers[i - count][n - 1] = '\0'; |
| 1580 | } |
| 1581 | count += cnt; |
| 1582 | } |
| 1583 | } |
| 1584 | |
Courtney Goeltzenleuchter | d9dc0c7 | 2015-04-20 11:04:54 -0600 | [diff] [blame] | 1585 | *pLayerCount = count; |
Jon Ashburn | f7bcf9b | 2014-10-15 15:30:23 -0600 | [diff] [blame] | 1586 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1587 | return VK_SUCCESS; |
Jon Ashburn | f7bcf9b | 2014-10-15 15:30:23 -0600 | [diff] [blame] | 1588 | } |
| 1589 | |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 1590 | VkResult loader_GetMultiDeviceCompatibility( |
| 1591 | VkPhysicalDevice gpu0, |
| 1592 | VkPhysicalDevice gpu1, |
| 1593 | VkPhysicalDeviceCompatibilityInfo* pInfo) |
| 1594 | { |
| 1595 | uint32_t gpu_index; |
| 1596 | struct loader_icd *icd = loader_get_icd((const VkBaseLayerObject *) gpu0, &gpu_index); |
| 1597 | VkResult res = VK_ERROR_INITIALIZATION_FAILED; |
| 1598 | |
| 1599 | if (icd->GetMultiDeviceCompatibility) |
| 1600 | res = icd->GetMultiDeviceCompatibility(gpu0, gpu1, pInfo); |
| 1601 | |
| 1602 | return res; |
| 1603 | } |
| 1604 | |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 1605 | VkResult loader_DbgRegisterMsgCallback(VkInstance instance, VK_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback, void* pUserData) |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1606 | { |
Jon Ashburn | 01e2d66 | 2014-11-14 09:52:42 -0700 | [diff] [blame] | 1607 | const struct loader_icd *icd; |
Jon Ashburn | 98bd454 | 2015-01-29 16:44:24 -0700 | [diff] [blame] | 1608 | struct loader_instance *inst; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1609 | VkResult res; |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1610 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1611 | if (instance == VK_NULL_HANDLE) |
| 1612 | return VK_ERROR_INVALID_HANDLE; |
Courtney Goeltzenleuchter | c80a557 | 2015-04-13 14:10:06 -0600 | [diff] [blame] | 1613 | |
| 1614 | assert(loader.icds_scanned); |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1615 | |
Jon Ashburn | 98bd454 | 2015-01-29 16:44:24 -0700 | [diff] [blame] | 1616 | for (inst = loader.instances; inst; inst = inst->next) { |
Mike Stroyan | b050c68 | 2015-04-17 12:36:38 -0600 | [diff] [blame] | 1617 | if ((VkInstance) inst == instance) |
Jon Ashburn | bb51025 | 2015-03-17 13:47:55 -0600 | [diff] [blame] | 1618 | break; |
| 1619 | } |
| 1620 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1621 | if (inst == VK_NULL_HANDLE) |
| 1622 | return VK_ERROR_INVALID_HANDLE; |
Jon Ashburn | bb51025 | 2015-03-17 13:47:55 -0600 | [diff] [blame] | 1623 | |
| 1624 | for (icd = inst->icds; icd; icd = icd->next) { |
Jon Ashburn | 3da71f2 | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 1625 | if (!icd->DbgRegisterMsgCallback) |
| 1626 | continue; |
| 1627 | res = icd->DbgRegisterMsgCallback(icd->instance, |
Jon Ashburn | 98bd454 | 2015-01-29 16:44:24 -0700 | [diff] [blame] | 1628 | pfnMsgCallback, pUserData); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1629 | if (res != VK_SUCCESS) |
Jon Ashburn | 01e2d66 | 2014-11-14 09:52:42 -0700 | [diff] [blame] | 1630 | break; |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1631 | } |
| 1632 | |
Jon Ashburn | bb51025 | 2015-03-17 13:47:55 -0600 | [diff] [blame] | 1633 | |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1634 | /* roll back on errors */ |
| 1635 | if (icd) { |
Jon Ashburn | bb51025 | 2015-03-17 13:47:55 -0600 | [diff] [blame] | 1636 | for (const struct loader_icd *tmp = inst->icds; tmp != icd; |
Jon Ashburn | 98bd454 | 2015-01-29 16:44:24 -0700 | [diff] [blame] | 1637 | tmp = tmp->next) { |
Jon Ashburn | 3da71f2 | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 1638 | if (!tmp->DbgUnregisterMsgCallback) |
| 1639 | continue; |
| 1640 | tmp->DbgUnregisterMsgCallback(tmp->instance, |
| 1641 | pfnMsgCallback); |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1642 | } |
| 1643 | |
| 1644 | return res; |
| 1645 | } |
| 1646 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1647 | return VK_SUCCESS; |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1648 | } |
| 1649 | |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 1650 | VkResult loader_DbgUnregisterMsgCallback(VkInstance instance, VK_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback) |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1651 | { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1652 | VkResult res = VK_SUCCESS; |
Jon Ashburn | bb51025 | 2015-03-17 13:47:55 -0600 | [diff] [blame] | 1653 | struct loader_instance *inst; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1654 | if (instance == VK_NULL_HANDLE) |
| 1655 | return VK_ERROR_INVALID_HANDLE; |
Courtney Goeltzenleuchter | c80a557 | 2015-04-13 14:10:06 -0600 | [diff] [blame] | 1656 | |
| 1657 | assert(loader.icds_scanned); |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1658 | |
Jon Ashburn | bb51025 | 2015-03-17 13:47:55 -0600 | [diff] [blame] | 1659 | for (inst = loader.instances; inst; inst = inst->next) { |
Mike Stroyan | b050c68 | 2015-04-17 12:36:38 -0600 | [diff] [blame] | 1660 | if ((VkInstance) inst == instance) |
Jon Ashburn | bb51025 | 2015-03-17 13:47:55 -0600 | [diff] [blame] | 1661 | break; |
| 1662 | } |
| 1663 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1664 | if (inst == VK_NULL_HANDLE) |
| 1665 | return VK_ERROR_INVALID_HANDLE; |
Jon Ashburn | bb51025 | 2015-03-17 13:47:55 -0600 | [diff] [blame] | 1666 | |
| 1667 | for (const struct loader_icd * icd = inst->icds; icd; icd = icd->next) { |
Jon Ashburn | 3da71f2 | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 1668 | VkResult r; |
| 1669 | if (!icd->DbgUnregisterMsgCallback) |
| 1670 | continue; |
| 1671 | r = icd->DbgUnregisterMsgCallback(icd->instance, pfnMsgCallback); |
| 1672 | if (r != VK_SUCCESS) { |
| 1673 | res = r; |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1674 | } |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1675 | } |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1676 | return res; |
| 1677 | } |
| 1678 | |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 1679 | VkResult loader_DbgSetGlobalOption(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] | 1680 | { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1681 | VkResult res = VK_SUCCESS; |
Jon Ashburn | bb51025 | 2015-03-17 13:47:55 -0600 | [diff] [blame] | 1682 | struct loader_instance *inst; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1683 | if (instance == VK_NULL_HANDLE) |
| 1684 | return VK_ERROR_INVALID_HANDLE; |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1685 | |
Courtney Goeltzenleuchter | c80a557 | 2015-04-13 14:10:06 -0600 | [diff] [blame] | 1686 | assert(loader.icds_scanned); |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1687 | |
Jon Ashburn | bb51025 | 2015-03-17 13:47:55 -0600 | [diff] [blame] | 1688 | for (inst = loader.instances; inst; inst = inst->next) { |
Mike Stroyan | b050c68 | 2015-04-17 12:36:38 -0600 | [diff] [blame] | 1689 | if ((VkInstance) inst == instance) |
Jon Ashburn | bb51025 | 2015-03-17 13:47:55 -0600 | [diff] [blame] | 1690 | break; |
| 1691 | } |
| 1692 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1693 | if (inst == VK_NULL_HANDLE) |
| 1694 | return VK_ERROR_INVALID_HANDLE; |
Jon Ashburn | bb51025 | 2015-03-17 13:47:55 -0600 | [diff] [blame] | 1695 | for (const struct loader_icd * icd = inst->icds; icd; icd = icd->next) { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1696 | VkResult r; |
Jon Ashburn | 3da71f2 | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 1697 | if (!icd->DbgSetGlobalOption) |
| 1698 | continue; |
| 1699 | r = icd->DbgSetGlobalOption(icd->instance, dbgOption, |
Jon Ashburn | 98bd454 | 2015-01-29 16:44:24 -0700 | [diff] [blame] | 1700 | dataSize, pData); |
Jon Ashburn | bb51025 | 2015-03-17 13:47:55 -0600 | [diff] [blame] | 1701 | /* unfortunately we cannot roll back */ |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1702 | if (r != VK_SUCCESS) { |
Jon Ashburn | bb51025 | 2015-03-17 13:47:55 -0600 | [diff] [blame] | 1703 | res = r; |
Jon Ashburn | 01e2d66 | 2014-11-14 09:52:42 -0700 | [diff] [blame] | 1704 | } |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1705 | } |
| 1706 | |
| 1707 | return res; |
| 1708 | } |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 1709 | |