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