Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1 | /* |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 2 | * Vulkan |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2014 LunarG, Inc. |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 7 | * copy of this software and associated documentation files (the "Software"), |
| 8 | * to deal in the Software without restriction, including without limitation |
| 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 10 | * and/or sell copies of the Software, and to permit persons to whom the |
| 11 | * Software is furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included |
| 14 | * in all copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 22 | * DEALINGS IN THE SOFTWARE. |
Chia-I Wu | 701f3f6 | 2014-09-02 08:32:09 +0800 | [diff] [blame] | 23 | * |
| 24 | * Authors: |
| 25 | * Chia-I Wu <olv@lunarg.com> |
Jon Ashburn | 01e2d66 | 2014-11-14 09:52:42 -0700 | [diff] [blame] | 26 | * Jon Ashburn <jon@lunarg.com> |
Chia-I Wu | 701f3f6 | 2014-09-02 08:32:09 +0800 | [diff] [blame] | 27 | * Courtney Goeltzenleuchter <courtney@lunarg.com> |
Ian Elliott | 5aa4ea2 | 2015-03-31 15:32:41 -0600 | [diff] [blame] | 28 | * Ian Elliott <ian@lunarg.com> |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 29 | */ |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 30 | #define _GNU_SOURCE |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 31 | #include <stdio.h> |
| 32 | #include <stdlib.h> |
| 33 | #include <stdarg.h> |
| 34 | #include <stdbool.h> |
| 35 | #include <string.h> |
| 36 | |
Chia-I Wu | 13a61a5 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 37 | #include <sys/types.h> |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 38 | #if defined(WIN32) |
| 39 | #include "dirent_on_windows.h" |
| 40 | #else // WIN32 |
Chia-I Wu | 13a61a5 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 41 | #include <dirent.h> |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 42 | #endif // WIN32 |
| 43 | #include "loader_platform.h" |
Chia-I Wu | 1930060 | 2014-08-04 08:03:57 +0800 | [diff] [blame] | 44 | #include "loader.h" |
Jon Ashburn | 07daee7 | 2015-05-21 18:13:33 -0600 | [diff] [blame] | 45 | #include "wsi_lunarg.h" |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 46 | #include "gpa_helper.h" |
| 47 | #include "table_ops.h" |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 48 | #include "debug_report.h" |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 49 | #include "vkIcd.h" |
Ian Elliott | 655cad7 | 2015-02-12 17:08:34 -0700 | [diff] [blame] | 50 | // The following is #included again to catch certain OS-specific functions |
| 51 | // being used: |
| 52 | #include "loader_platform.h" |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 53 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 54 | void loader_add_to_ext_list( |
| 55 | struct loader_extension_list *ext_list, |
| 56 | uint32_t prop_list_count, |
| 57 | const struct loader_extension_property *prop_list); |
| 58 | |
Courtney Goeltzenleuchter | ed48830 | 2015-06-01 14:09:34 -0600 | [diff] [blame] | 59 | static loader_platform_dl_handle loader_add_layer_lib( |
| 60 | const char *chain_type, |
| 61 | struct loader_extension_property *ext_prop); |
| 62 | |
| 63 | static void loader_remove_layer_lib( |
| 64 | struct loader_instance *inst, |
| 65 | struct loader_extension_property *ext_prop); |
| 66 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 67 | /* TODO: do we need to lock around access to linked lists and such? */ |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 68 | struct loader_struct loader = {0}; |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 69 | |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 70 | enum loader_debug { |
| 71 | LOADER_INFO_BIT = VK_BIT(0), |
| 72 | LOADER_WARN_BIT = VK_BIT(1), |
| 73 | LOADER_PERF_BIT = VK_BIT(2), |
| 74 | LOADER_ERROR_BIT = VK_BIT(3), |
| 75 | LOADER_DEBUG_BIT = VK_BIT(4), |
| 76 | }; |
| 77 | |
| 78 | uint32_t g_loader_debug = 0; |
| 79 | uint32_t g_loader_log_msgs = 0; |
| 80 | |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 81 | VkLayerInstanceDispatchTable instance_disp = { |
| 82 | .GetInstanceProcAddr = vkGetInstanceProcAddr, |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 83 | .CreateInstance = loader_CreateInstance, |
| 84 | .DestroyInstance = loader_DestroyInstance, |
| 85 | .EnumeratePhysicalDevices = loader_EnumeratePhysicalDevices, |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 86 | .GetPhysicalDeviceInfo = loader_GetPhysicalDeviceInfo, |
| 87 | .CreateDevice = loader_CreateDevice, |
Jon Ashburn | eceb13e | 2015-05-18 15:28:32 -0600 | [diff] [blame] | 88 | .GetGlobalExtensionInfo = vkGetGlobalExtensionInfo, |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 89 | .GetPhysicalDeviceExtensionInfo = vkGetPhysicalDeviceExtensionInfo, |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 90 | .GetMultiDeviceCompatibility = loader_GetMultiDeviceCompatibility, |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 91 | .GetDisplayInfoWSI = loader_GetDisplayInfoWSI, |
| 92 | .DbgCreateMsgCallback = loader_DbgCreateMsgCallback, |
| 93 | .DbgDestroyMsgCallback = loader_DbgDestroyMsgCallback, |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 94 | }; |
| 95 | |
| 96 | LOADER_PLATFORM_THREAD_ONCE_DECLARATION(once_icd); |
| 97 | LOADER_PLATFORM_THREAD_ONCE_DECLARATION(once_layer); |
| 98 | LOADER_PLATFORM_THREAD_ONCE_DECLARATION(once_exts); |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 99 | |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 100 | #if defined(WIN32) |
Ian Elliott | 5aa4ea2 | 2015-03-31 15:32:41 -0600 | [diff] [blame] | 101 | char *loader_get_registry_string(const HKEY hive, |
| 102 | const LPCTSTR sub_key, |
| 103 | const char *value) |
| 104 | { |
| 105 | DWORD access_flags = KEY_QUERY_VALUE; |
| 106 | DWORD value_type; |
| 107 | HKEY key; |
Ian Elliott | f851ddf | 2015-04-28 15:57:32 -0600 | [diff] [blame] | 108 | VkResult rtn_value; |
Ian Elliott | 5aa4ea2 | 2015-03-31 15:32:41 -0600 | [diff] [blame] | 109 | char *rtn_str = NULL; |
Tony Barbour | 18f7155 | 2015-04-22 11:36:22 -0600 | [diff] [blame] | 110 | DWORD rtn_len = 0; |
Ian Elliott | 5aa4ea2 | 2015-03-31 15:32:41 -0600 | [diff] [blame] | 111 | size_t allocated_len = 0; |
| 112 | |
| 113 | rtn_value = RegOpenKeyEx(hive, sub_key, 0, access_flags, &key); |
| 114 | if (rtn_value != ERROR_SUCCESS) { |
| 115 | // We didn't find the key. Try the 32-bit hive (where we've seen the |
| 116 | // key end up on some people's systems): |
| 117 | access_flags |= KEY_WOW64_32KEY; |
| 118 | rtn_value = RegOpenKeyEx(hive, sub_key, 0, access_flags, &key); |
| 119 | if (rtn_value != ERROR_SUCCESS) { |
| 120 | // We still couldn't find the key, so give up: |
| 121 | return NULL; |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | rtn_value = RegQueryValueEx(key, value, NULL, &value_type, |
Ian Elliott | f851ddf | 2015-04-28 15:57:32 -0600 | [diff] [blame] | 126 | (PVOID) rtn_str, (LPDWORD) &rtn_len); |
Ian Elliott | 5aa4ea2 | 2015-03-31 15:32:41 -0600 | [diff] [blame] | 127 | if (rtn_value == ERROR_SUCCESS) { |
| 128 | // If we get to here, we found the key, and need to allocate memory |
| 129 | // large enough for rtn_str, and query again: |
| 130 | allocated_len = rtn_len + 4; |
| 131 | rtn_str = malloc(allocated_len); |
| 132 | rtn_value = RegQueryValueEx(key, value, NULL, &value_type, |
Ian Elliott | f851ddf | 2015-04-28 15:57:32 -0600 | [diff] [blame] | 133 | (PVOID) rtn_str, (LPDWORD) &rtn_len); |
Ian Elliott | 5aa4ea2 | 2015-03-31 15:32:41 -0600 | [diff] [blame] | 134 | if (rtn_value == ERROR_SUCCESS) { |
| 135 | // We added 4 extra bytes to rtn_str, so that we can ensure that |
| 136 | // the string is NULL-terminated (albeit, in a brute-force manner): |
| 137 | rtn_str[allocated_len-1] = '\0'; |
| 138 | } else { |
| 139 | // This should never occur, but in case it does, clean up: |
| 140 | free(rtn_str); |
| 141 | rtn_str = NULL; |
| 142 | } |
| 143 | } // else - shouldn't happen, but if it does, return rtn_str, which is NULL |
| 144 | |
| 145 | // Close the registry key that was opened: |
| 146 | RegCloseKey(key); |
| 147 | |
| 148 | return rtn_str; |
| 149 | } |
| 150 | |
| 151 | |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 152 | // For ICD developers, look in the registry, and look for an environment |
| 153 | // variable for a path(s) where to find the ICD(s): |
| 154 | static char *loader_get_registry_and_env(const char *env_var, |
| 155 | const char *registry_value) |
| 156 | { |
| 157 | char *env_str = getenv(env_var); |
| 158 | size_t env_len = (env_str == NULL) ? 0 : strlen(env_str); |
Ian Elliott | 5aa4ea2 | 2015-03-31 15:32:41 -0600 | [diff] [blame] | 159 | char *registry_str = NULL; |
Tony Barbour | 18f7155 | 2015-04-22 11:36:22 -0600 | [diff] [blame] | 160 | size_t registry_len = 0; |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 161 | char *rtn_str = NULL; |
| 162 | size_t rtn_len; |
| 163 | |
Ian Elliott | 5aa4ea2 | 2015-03-31 15:32:41 -0600 | [diff] [blame] | 164 | registry_str = loader_get_registry_string(HKEY_LOCAL_MACHINE, |
Ian Elliott | 06ebd75 | 2015-04-09 18:07:15 -0600 | [diff] [blame] | 165 | "Software\\Vulkan", |
Ian Elliott | 5aa4ea2 | 2015-03-31 15:32:41 -0600 | [diff] [blame] | 166 | registry_value); |
Ian Elliott | f851ddf | 2015-04-28 15:57:32 -0600 | [diff] [blame] | 167 | registry_len = (registry_str) ? (DWORD) strlen(registry_str) : 0; |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 168 | |
| 169 | rtn_len = env_len + registry_len + 1; |
| 170 | if (rtn_len <= 2) { |
| 171 | // We found neither the desired registry value, nor the environment |
| 172 | // variable; return NULL: |
| 173 | return NULL; |
| 174 | } else { |
| 175 | // We found something, and so we need to allocate memory for the string |
| 176 | // to return: |
| 177 | rtn_str = malloc(rtn_len); |
| 178 | } |
| 179 | |
Ian Elliott | 5aa4ea2 | 2015-03-31 15:32:41 -0600 | [diff] [blame] | 180 | if (registry_len == 0) { |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 181 | // We didn't find the desired registry value, and so we must have found |
| 182 | // only the environment variable: |
| 183 | _snprintf(rtn_str, rtn_len, "%s", env_str); |
| 184 | } else if (env_str != NULL) { |
| 185 | // We found both the desired registry value and the environment |
| 186 | // variable, so concatenate them both: |
| 187 | _snprintf(rtn_str, rtn_len, "%s;%s", registry_str, env_str); |
| 188 | } else { |
| 189 | // We must have only found the desired registry value: |
| 190 | _snprintf(rtn_str, rtn_len, "%s", registry_str); |
| 191 | } |
| 192 | |
Ian Elliott | 2de26bc | 2015-04-03 13:13:01 -0600 | [diff] [blame] | 193 | if (registry_str) { |
| 194 | free(registry_str); |
| 195 | } |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 196 | |
| 197 | return(rtn_str); |
| 198 | } |
| 199 | #endif // WIN32 |
| 200 | |
| 201 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 202 | static void loader_log(VkFlags msg_type, int32_t msg_code, |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 203 | const char *format, ...) |
| 204 | { |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 205 | char msg[256]; |
| 206 | va_list ap; |
| 207 | int ret; |
| 208 | |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 209 | if (!(msg_code & g_loader_log_msgs)) { |
| 210 | return; |
| 211 | } |
| 212 | |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 213 | va_start(ap, format); |
| 214 | ret = vsnprintf(msg, sizeof(msg), format, ap); |
Ian Elliott | 4204584 | 2015-02-13 14:29:21 -0700 | [diff] [blame] | 215 | if ((ret >= (int) sizeof(msg)) || ret < 0) { |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 216 | msg[sizeof(msg) - 1] = '\0'; |
| 217 | } |
| 218 | va_end(ap); |
| 219 | |
Jon Ashburn | ae053e9 | 2015-04-24 14:10:50 -0700 | [diff] [blame] | 220 | #if defined(WIN32) |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 221 | OutputDebugString(msg); |
Jon Ashburn | 1de3940 | 2015-05-05 16:20:46 -0600 | [diff] [blame] | 222 | #endif |
Courtney Goeltzenleuchter | c80a557 | 2015-04-13 14:10:06 -0600 | [diff] [blame] | 223 | fputs(msg, stderr); |
| 224 | fputc('\n', stderr); |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 225 | } |
| 226 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 227 | bool compare_vk_extension_properties(const VkExtensionProperties *op1, const VkExtensionProperties *op2) |
| 228 | { |
| 229 | return memcmp(op1, op2, sizeof(VkExtensionProperties)) == 0 ? true : false; |
| 230 | } |
| 231 | |
| 232 | /* |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 233 | * Search the given ext_list for an extension |
| 234 | * matching the given vk_ext_prop |
| 235 | */ |
| 236 | bool has_vk_extension_property( |
| 237 | const VkExtensionProperties *vk_ext_prop, |
| 238 | const struct loader_extension_list *ext_list) |
| 239 | { |
| 240 | for (uint32_t i = 0; i < ext_list->count; i++) { |
| 241 | if (compare_vk_extension_properties(&ext_list->list[i].info, vk_ext_prop)) |
| 242 | return true; |
| 243 | } |
| 244 | return false; |
| 245 | } |
| 246 | |
| 247 | /* |
| 248 | * Search the given ext_list for an extension |
| 249 | * matching the given vk_ext_prop |
| 250 | */ |
| 251 | static struct loader_extension_property *get_extension_property_from_vkext( |
| 252 | const VkExtensionProperties *vk_ext_prop, |
| 253 | const struct loader_extension_list *ext_list) |
| 254 | { |
| 255 | for (uint32_t i = 0; i < ext_list->count; i++) { |
| 256 | if (compare_vk_extension_properties(&ext_list->list[i].info, vk_ext_prop)) |
| 257 | return &ext_list->list[i]; |
| 258 | } |
| 259 | return NULL; |
| 260 | } |
| 261 | |
| 262 | static void get_global_extensions( |
| 263 | const PFN_vkGetGlobalExtensionInfo fp_get, |
Courtney Goeltzenleuchter | 0f1d8eb | 2015-06-07 17:28:17 -0600 | [diff] [blame] | 264 | const char *get_extension_info_name, |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 265 | const char *lib_name, |
| 266 | const enum extension_origin origin, |
| 267 | struct loader_extension_list *ext_list) |
| 268 | { |
| 269 | uint32_t i, count; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 270 | size_t siz = sizeof(count); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 271 | struct loader_extension_property ext_props; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 272 | VkResult res; |
| 273 | |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 274 | res = fp_get(VK_EXTENSION_INFO_TYPE_COUNT, 0, &siz, &count); |
| 275 | if (res != VK_SUCCESS) { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 276 | loader_log(VK_DBG_REPORT_WARN_BIT, 0, "Error getting global extension count from ICD"); |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 277 | return; |
| 278 | } |
| 279 | siz = sizeof(VkExtensionProperties); |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 280 | for (i = 0; i < count; i++) { |
Courtney Goeltzenleuchter | 0f1d8eb | 2015-06-07 17:28:17 -0600 | [diff] [blame] | 281 | memset(&ext_props, 0, sizeof(ext_props)); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 282 | res = fp_get(VK_EXTENSION_INFO_TYPE_PROPERTIES, i, &siz, &ext_props.info); |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 283 | if (res == VK_SUCCESS) { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 284 | ext_props.hosted = false; |
| 285 | ext_props.origin = origin; |
| 286 | ext_props.lib_name = lib_name; |
Courtney Goeltzenleuchter | 0f1d8eb | 2015-06-07 17:28:17 -0600 | [diff] [blame] | 287 | strncpy(ext_props.get_extension_info_name, get_extension_info_name, MAX_EXTENSION_NAME_SIZE); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 288 | loader_add_to_ext_list(ext_list, 1, &ext_props); |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 289 | } |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 290 | } |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 291 | |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 292 | return; |
| 293 | } |
| 294 | |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 295 | static void get_physical_device_layer_extensions( |
| 296 | struct loader_instance *ptr_instance, |
| 297 | VkPhysicalDevice physical_device, |
| 298 | const uint32_t layer_index, |
| 299 | struct loader_extension_list *ext_list) |
| 300 | { |
| 301 | uint32_t i, count; |
| 302 | size_t siz = sizeof(count); |
| 303 | VkResult res; |
| 304 | loader_platform_dl_handle lib_handle; |
| 305 | PFN_vkGetPhysicalDeviceExtensionInfo fp_get; |
| 306 | struct loader_extension_property ext_props; |
| 307 | |
| 308 | if (!loader.scanned_layers[layer_index].physical_device_extensions_supported) { |
| 309 | return; |
| 310 | } |
| 311 | |
| 312 | ext_props.origin = VK_EXTENSION_ORIGIN_LAYER; |
| 313 | ext_props.lib_name = loader.scanned_layers[layer_index].lib_name; |
Jon Ashburn | 128f942 | 2015-05-28 19:16:58 -0600 | [diff] [blame] | 314 | char funcStr[MAX_EXTENSION_NAME_SIZE+1]; // add one character for 0 termination |
| 315 | snprintf(funcStr, MAX_EXTENSION_NAME_SIZE, "%sGetPhysicalDeviceExtensionInfo", ext_props.info.name); |
| 316 | funcStr[MAX_EXTENSION_NAME_SIZE] = 0; // make sure string is 0 terminated |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 317 | lib_handle = loader_add_layer_lib("device", &ext_props); |
Courtney Goeltzenleuchter | 0f1d8eb | 2015-06-07 17:28:17 -0600 | [diff] [blame] | 318 | |
| 319 | /* first try extension specific function, then generic */ |
| 320 | fp_get = (PFN_vkGetPhysicalDeviceExtensionInfo) loader_platform_get_proc_address(lib_handle, funcStr); |
| 321 | if (!fp_get) { |
Jon Ashburn | 128f942 | 2015-05-28 19:16:58 -0600 | [diff] [blame] | 322 | sprintf(funcStr, "vkGetPhysicalDeviceExtensionInfo"); |
| 323 | fp_get = (PFN_vkGetPhysicalDeviceExtensionInfo) loader_platform_get_proc_address(lib_handle, funcStr); |
Courtney Goeltzenleuchter | 0f1d8eb | 2015-06-07 17:28:17 -0600 | [diff] [blame] | 324 | } |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 325 | if (fp_get) { |
| 326 | res = fp_get(physical_device, VK_EXTENSION_INFO_TYPE_COUNT, 0, &siz, &count); |
| 327 | if (res == VK_SUCCESS) { |
| 328 | siz = sizeof(VkExtensionProperties); |
| 329 | for (i = 0; i < count; i++) { |
| 330 | memset(&ext_props, 0, sizeof(ext_props)); |
| 331 | res = fp_get(physical_device, VK_EXTENSION_INFO_TYPE_PROPERTIES, i, &siz, &ext_props.info); |
| 332 | if (res == VK_SUCCESS && (ext_props.info.sType == VK_STRUCTURE_TYPE_EXTENSION_PROPERTIES)) { |
| 333 | ext_props.hosted = false; |
| 334 | ext_props.origin = VK_EXTENSION_ORIGIN_LAYER; |
Jon Ashburn | 128f942 | 2015-05-28 19:16:58 -0600 | [diff] [blame] | 335 | strcpy(ext_props.get_extension_info_name, funcStr); |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 336 | ext_props.lib_name = loader.scanned_layers[layer_index].lib_name; |
| 337 | loader_add_to_ext_list(ext_list, 1, &ext_props); |
| 338 | } |
| 339 | } |
| 340 | } else { |
| 341 | loader_log(VK_DBG_REPORT_WARN_BIT, 0, "Error getting physical device extension info count from Layer %s", ext_props.lib_name); |
| 342 | } |
| 343 | } |
| 344 | |
| 345 | loader_remove_layer_lib(ptr_instance, &ext_props); |
| 346 | return; |
| 347 | } |
| 348 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 349 | static bool loader_init_ext_list(struct loader_extension_list *ext_info) |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 350 | { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 351 | ext_info->capacity = 32 * sizeof(struct loader_extension_property); |
| 352 | ext_info->list = malloc(ext_info->capacity); |
| 353 | if (ext_info->list == NULL) { |
| 354 | return false; |
| 355 | } |
| 356 | memset(ext_info->list, 0, ext_info->capacity); |
| 357 | ext_info->count = 0; |
| 358 | return true; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 359 | } |
| 360 | |
Courtney Goeltzenleuchter | 7d0023c | 2015-06-08 15:09:22 -0600 | [diff] [blame] | 361 | void loader_destroy_ext_list(struct loader_extension_list *ext_info) |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 362 | { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 363 | free(ext_info->list); |
| 364 | ext_info->count = 0; |
| 365 | ext_info->capacity = 0; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 366 | } |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 367 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 368 | static void loader_add_vk_ext_to_ext_list( |
| 369 | struct loader_extension_list *ext_list, |
| 370 | uint32_t prop_list_count, |
| 371 | const VkExtensionProperties *props, |
| 372 | const struct loader_extension_list *search_list) |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 373 | { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 374 | struct loader_extension_property *ext_prop; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 375 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 376 | for (uint32_t i = 0; i < prop_list_count; i++) { |
| 377 | // look for duplicates |
| 378 | if (has_vk_extension_property(&props[i], ext_list)) { |
| 379 | continue; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 380 | } |
| 381 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 382 | ext_prop = get_extension_property_from_vkext(&props[i], search_list); |
| 383 | if (!ext_prop) { |
| 384 | loader_log(VK_DBG_REPORT_WARN_BIT, 0, "Unable to find extension %s", props[i].name); |
| 385 | continue; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 386 | } |
| 387 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 388 | loader_add_to_ext_list(ext_list, 1, ext_prop); |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 389 | } |
| 390 | } |
| 391 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 392 | /* |
| 393 | * Append non-duplicate extension properties defined in prop_list |
| 394 | * to the given ext_info list |
| 395 | */ |
| 396 | void loader_add_to_ext_list( |
| 397 | struct loader_extension_list *ext_list, |
| 398 | uint32_t prop_list_count, |
| 399 | const struct loader_extension_property *props) |
| 400 | { |
| 401 | uint32_t i; |
| 402 | struct loader_extension_property *cur_ext; |
| 403 | |
| 404 | if (ext_list->list == NULL || ext_list->capacity == 0) { |
| 405 | loader_init_ext_list(ext_list); |
| 406 | } |
| 407 | |
| 408 | if (ext_list->list == NULL) |
| 409 | return; |
| 410 | |
| 411 | for (i = 0; i < prop_list_count; i++) { |
| 412 | cur_ext = (struct loader_extension_property *) &props[i]; |
| 413 | |
| 414 | // look for duplicates |
| 415 | if (has_vk_extension_property(&cur_ext->info, ext_list)) { |
| 416 | continue; |
| 417 | } |
| 418 | |
| 419 | // add to list at end |
| 420 | // check for enough capacity |
| 421 | if (ext_list->count * sizeof(struct loader_extension_property) |
| 422 | >= ext_list->capacity) { |
| 423 | // double capacity |
| 424 | ext_list->capacity *= 2; |
| 425 | ext_list->list = realloc(ext_list->list, ext_list->capacity); |
| 426 | } |
Courtney Goeltzenleuchter | 0f1d8eb | 2015-06-07 17:28:17 -0600 | [diff] [blame] | 427 | |
| 428 | /* |
| 429 | * Check if any extensions already on the list come from the same |
| 430 | * library and use the same Get*ExtensionInfo. If so, link this |
| 431 | * extension to the previous as an alias. That way when we activate |
| 432 | * extensions we only activiate the associated layer once no |
| 433 | * matter how many extensions are used. |
| 434 | */ |
| 435 | for (uint32_t j = 0; j < ext_list->count; j++) { |
| 436 | struct loader_extension_property *active_property = &ext_list->list[j]; |
| 437 | if (cur_ext->lib_name && |
| 438 | cur_ext->origin == VK_EXTENSION_ORIGIN_LAYER && |
| 439 | active_property->origin == VK_EXTENSION_ORIGIN_LAYER && |
| 440 | strcmp(cur_ext->lib_name, active_property->lib_name) == 0 && |
| 441 | strcmp(cur_ext->get_extension_info_name, active_property->get_extension_info_name) == 0 && |
| 442 | active_property->alias == NULL) { |
| 443 | cur_ext->alias = active_property; |
| 444 | break; |
| 445 | } |
| 446 | } |
| 447 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 448 | memcpy(&ext_list->list[ext_list->count], cur_ext, sizeof(struct loader_extension_property)); |
| 449 | ext_list->count++; |
| 450 | } |
| 451 | } |
| 452 | |
| 453 | /* |
| 454 | * Search the search_list for any extension with |
| 455 | * a name that matches the given ext_name. |
| 456 | * Add all matching extensions to the found_list |
| 457 | * Do not add if found VkExtensionProperties is already |
| 458 | * on the found_list |
| 459 | */ |
| 460 | static void loader_search_ext_list_for_name( |
| 461 | const char *ext_name, |
| 462 | const struct loader_extension_list *search_list, |
| 463 | struct loader_extension_list *found_list) |
| 464 | { |
| 465 | for (uint32_t i = 0; i < search_list->count; i++) { |
| 466 | struct loader_extension_property *ext_prop = &search_list->list[i]; |
| 467 | if (0 == strcmp(ext_prop->info.name, ext_name)) { |
| 468 | /* Found an extension with the same name, add to found_list */ |
| 469 | loader_add_to_ext_list(found_list, 1, &search_list->list[i]); |
| 470 | } |
| 471 | } |
| 472 | } |
| 473 | |
| 474 | bool loader_is_extension_scanned(const VkExtensionProperties *ext_prop) |
Jon Ashburn | fc2e38c | 2015-04-14 09:15:32 -0600 | [diff] [blame] | 475 | { |
| 476 | uint32_t i; |
| 477 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 478 | for (i = 0; i < loader.global_extensions.count; i++) { |
| 479 | if (compare_vk_extension_properties(&loader.global_extensions.list[i].info, ext_prop)) |
Jon Ashburn | fc2e38c | 2015-04-14 09:15:32 -0600 | [diff] [blame] | 480 | return true; |
| 481 | } |
| 482 | return false; |
| 483 | } |
| 484 | |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 485 | void loader_coalesce_extensions(void) |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 486 | { |
| 487 | uint32_t i; |
| 488 | struct loader_scanned_icds *icd_list = loader.scanned_icd_list; |
| 489 | |
| 490 | // traverse scanned icd list adding non-duplicate extensions to the list |
| 491 | while (icd_list != NULL) { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 492 | loader_add_to_ext_list(&loader.global_extensions, |
| 493 | icd_list->global_extension_list.count, |
| 494 | icd_list->global_extension_list.list); |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 495 | icd_list = icd_list->next; |
| 496 | }; |
| 497 | |
| 498 | //Traverse layers list adding non-duplicate extensions to the list |
| 499 | for (i = 0; i < loader.scanned_layer_count; i++) { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 500 | loader_add_to_ext_list(&loader.global_extensions, |
| 501 | loader.scanned_layers[i].global_extension_list.count, |
| 502 | loader.scanned_layers[i].global_extension_list.list); |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 503 | } |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 504 | |
| 505 | // Traverse loader's extensions, adding non-duplicate extensions to the list |
| 506 | debug_report_add_instance_extensions(&loader.global_extensions); |
Jon Ashburn | 0c5d4ab | 2015-05-26 13:57:35 -0600 | [diff] [blame] | 507 | wsi_lunarg_add_instance_extensions(&loader.global_extensions); |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 508 | } |
| 509 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 510 | static void loader_icd_destroy( |
| 511 | struct loader_instance *ptr_inst, |
| 512 | struct loader_icd *icd) |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 513 | { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 514 | ptr_inst->total_icd_count--; |
Jon Ashburn | 128f942 | 2015-05-28 19:16:58 -0600 | [diff] [blame] | 515 | free(icd->gpus); |
| 516 | free(icd->loader_dispatch); |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 517 | free(icd); |
| 518 | } |
| 519 | |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 520 | 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] | 521 | { |
| 522 | struct loader_icd *icd; |
| 523 | |
| 524 | icd = malloc(sizeof(*icd)); |
| 525 | if (!icd) |
| 526 | return NULL; |
| 527 | |
Courtney Goeltzenleuchter | 55001bb | 2014-10-28 10:29:27 -0600 | [diff] [blame] | 528 | memset(icd, 0, sizeof(*icd)); |
| 529 | |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 530 | icd->scanned_icds = scanned; |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 531 | |
| 532 | return icd; |
| 533 | } |
| 534 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 535 | static struct loader_icd *loader_icd_add( |
| 536 | struct loader_instance *ptr_inst, |
| 537 | const struct loader_scanned_icds *scanned) |
Chia-I Wu | 13a61a5 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 538 | { |
| 539 | struct loader_icd *icd; |
| 540 | |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 541 | icd = loader_icd_create(scanned); |
Chia-I Wu | 13a61a5 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 542 | if (!icd) |
| 543 | return NULL; |
| 544 | |
Chia-I Wu | 13a61a5 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 545 | /* prepend to the list */ |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 546 | icd->next = ptr_inst->icds; |
| 547 | ptr_inst->icds = icd; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 548 | ptr_inst->total_icd_count++; |
Chia-I Wu | 13a61a5 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 549 | |
| 550 | return icd; |
| 551 | } |
| 552 | |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 553 | static void loader_scanned_icd_add(const char *filename) |
| 554 | { |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 555 | loader_platform_dl_handle handle; |
Jon Ashburn | 3da71f2 | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 556 | void *fp_create_inst; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 557 | void *fp_get_global_ext_info; |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 558 | void *fp_get_device_ext_info; |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 559 | struct loader_scanned_icds *new_node; |
| 560 | |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 561 | // Used to call: dlopen(filename, RTLD_LAZY); |
| 562 | handle = loader_platform_open_library(filename); |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 563 | if (!handle) { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 564 | loader_log(VK_DBG_REPORT_WARN_BIT, 0, loader_platform_open_library_error(filename)); |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 565 | return; |
| 566 | } |
| 567 | |
| 568 | #define LOOKUP(func_ptr, func) do { \ |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 569 | 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] | 570 | if (!func_ptr) { \ |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 571 | loader_log(VK_DBG_REPORT_WARN_BIT, 0, loader_platform_get_proc_address_error("vk" #func)); \ |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 572 | return; \ |
| 573 | } \ |
| 574 | } while (0) |
| 575 | |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 576 | LOOKUP(fp_create_inst, CreateInstance); |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 577 | LOOKUP(fp_get_global_ext_info, GetGlobalExtensionInfo); |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 578 | LOOKUP(fp_get_device_ext_info, GetPhysicalDeviceExtensionInfo); |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 579 | #undef LOOKUP |
| 580 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 581 | new_node = (struct loader_scanned_icds *) malloc(sizeof(struct loader_scanned_icds) |
| 582 | + strlen(filename) + 1); |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 583 | if (!new_node) { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 584 | loader_log(VK_DBG_REPORT_WARN_BIT, 0, "Out of memory can't add icd"); |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 585 | return; |
| 586 | } |
| 587 | |
| 588 | new_node->handle = handle; |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 589 | new_node->CreateInstance = fp_create_inst; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 590 | new_node->GetGlobalExtensionInfo = fp_get_global_ext_info; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 591 | loader_init_ext_list(&new_node->global_extension_list); |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 592 | loader_init_ext_list(&new_node->device_extension_list); |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 593 | new_node->next = loader.scanned_icd_list; |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 594 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 595 | new_node->lib_name = (char *) (new_node + 1); |
| 596 | if (!new_node->lib_name) { |
| 597 | loader_log(VK_DBG_REPORT_WARN_BIT, 0, "Out of memory can't add icd"); |
| 598 | return; |
| 599 | } |
| 600 | strcpy(new_node->lib_name, filename); |
| 601 | |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 602 | loader.scanned_icd_list = new_node; |
| 603 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 604 | get_global_extensions( |
| 605 | (PFN_vkGetGlobalExtensionInfo) fp_get_global_ext_info, |
Courtney Goeltzenleuchter | 0f1d8eb | 2015-06-07 17:28:17 -0600 | [diff] [blame] | 606 | "vkGetGlobalExtensionInfo", |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 607 | new_node->lib_name, |
| 608 | VK_EXTENSION_ORIGIN_ICD, |
| 609 | &new_node->global_extension_list); |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 610 | } |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 611 | |
Jon Ashburn | 3da71f2 | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 612 | static void loader_icd_init_entrys(struct loader_icd *icd, |
| 613 | struct loader_scanned_icds *scanned_icds) |
| 614 | { |
| 615 | /* initialize entrypoint function pointers */ |
| 616 | |
| 617 | #define LOOKUP(func) do { \ |
| 618 | icd->func = (PFN_vk ##func) loader_platform_get_proc_address(scanned_icds->handle, "vk" #func); \ |
| 619 | if (!icd->func) { \ |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 620 | loader_log(VK_DBG_REPORT_WARN_BIT, 0, loader_platform_get_proc_address_error("vk" #func)); \ |
Jon Ashburn | 3da71f2 | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 621 | return; \ |
| 622 | } \ |
| 623 | } while (0) |
| 624 | |
Jon Ashburn | 8d1b0b5 | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 625 | /* could change this to use GetInstanceProcAddr in driver instead of dlsym */ |
| 626 | LOOKUP(GetDeviceProcAddr); |
Jon Ashburn | 3da71f2 | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 627 | LOOKUP(DestroyInstance); |
| 628 | LOOKUP(EnumeratePhysicalDevices); |
| 629 | LOOKUP(GetPhysicalDeviceInfo); |
| 630 | LOOKUP(CreateDevice); |
| 631 | LOOKUP(GetPhysicalDeviceExtensionInfo); |
Jon Ashburn | 3da71f2 | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 632 | LOOKUP(GetMultiDeviceCompatibility); |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 633 | LOOKUP(GetDisplayInfoWSI); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 634 | LOOKUP(DbgCreateMsgCallback); |
| 635 | LOOKUP(DbgDestroyMsgCallback); |
Jon Ashburn | 3da71f2 | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 636 | #undef LOOKUP |
| 637 | |
| 638 | return; |
| 639 | } |
| 640 | |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 641 | static void loader_debug_init(void) |
| 642 | { |
| 643 | const char *env; |
| 644 | |
| 645 | if (g_loader_debug > 0) |
| 646 | return; |
| 647 | |
| 648 | g_loader_debug = 0; |
| 649 | |
| 650 | /* parse comma-separated debug options */ |
| 651 | env = getenv("LOADER_DEBUG"); |
| 652 | while (env) { |
| 653 | const char *p = strchr(env, ','); |
| 654 | size_t len; |
| 655 | |
| 656 | if (p) |
| 657 | len = p - env; |
| 658 | else |
| 659 | len = strlen(env); |
| 660 | |
| 661 | if (len > 0) { |
| 662 | if (strncmp(env, "warn", len) == 0) { |
| 663 | g_loader_debug |= LOADER_WARN_BIT; |
| 664 | g_loader_log_msgs |= VK_DBG_REPORT_WARN_BIT; |
| 665 | } else if (strncmp(env, "info", len) == 0) { |
| 666 | g_loader_debug |= LOADER_INFO_BIT; |
| 667 | g_loader_log_msgs |= VK_DBG_REPORT_INFO_BIT; |
| 668 | } else if (strncmp(env, "perf", len) == 0) { |
| 669 | g_loader_debug |= LOADER_PERF_BIT; |
| 670 | g_loader_log_msgs |= VK_DBG_REPORT_PERF_WARN_BIT; |
| 671 | } else if (strncmp(env, "error", len) == 0) { |
| 672 | g_loader_debug |= LOADER_ERROR_BIT; |
| 673 | g_loader_log_msgs |= VK_DBG_REPORT_ERROR_BIT; |
| 674 | } else if (strncmp(env, "debug", len) == 0) { |
| 675 | g_loader_debug |= LOADER_DEBUG_BIT; |
| 676 | g_loader_log_msgs |= VK_DBG_REPORT_DEBUG_BIT; |
| 677 | } |
| 678 | } |
| 679 | |
| 680 | if (!p) |
| 681 | break; |
| 682 | |
| 683 | env = p + 1; |
| 684 | } |
| 685 | } |
| 686 | |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 687 | /** |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 688 | * Try to \c loader_icd_scan VK driver(s). |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 689 | * |
| 690 | * This function scans the default system path or path |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 691 | * specified by the \c LIBVK_DRIVERS_PATH environment variable in |
| 692 | * order to find loadable VK ICDs with the name of libVK_*. |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 693 | * |
| 694 | * \returns |
| 695 | * void; but side effect is to set loader_icd_scanned to true |
| 696 | */ |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 697 | void loader_icd_scan(void) |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 698 | { |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 699 | const char *p, *next; |
| 700 | char *libPaths = NULL; |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 701 | DIR *sysdir; |
| 702 | struct dirent *dent; |
| 703 | char icd_library[1024]; |
Jon Ashburn | 5cda59c | 2014-10-03 16:31:35 -0600 | [diff] [blame] | 704 | char path[1024]; |
Ian Elliott | 1962880 | 2015-02-04 12:06:46 -0700 | [diff] [blame] | 705 | uint32_t len; |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 706 | #if defined(WIN32) |
| 707 | bool must_free_libPaths; |
| 708 | libPaths = loader_get_registry_and_env(DRIVER_PATH_ENV, |
| 709 | DRIVER_PATH_REGISTRY_VALUE); |
| 710 | if (libPaths != NULL) { |
| 711 | must_free_libPaths = true; |
| 712 | } else { |
| 713 | must_free_libPaths = false; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 714 | libPaths = DEFAULT_VK_DRIVERS_PATH; |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 715 | } |
| 716 | #else // WIN32 |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 717 | if (geteuid() == getuid()) { |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 718 | /* Don't allow setuid apps to use the DRIVER_PATH_ENV env var: */ |
| 719 | libPaths = getenv(DRIVER_PATH_ENV); |
| 720 | } |
| 721 | if (libPaths == NULL) { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 722 | libPaths = DEFAULT_VK_DRIVERS_PATH; |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 723 | } |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 724 | #endif // WIN32 |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 725 | |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 726 | loader_debug_init(); |
| 727 | |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 728 | for (p = libPaths; *p; p = next) { |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 729 | next = strchr(p, PATH_SEPERATOR); |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 730 | if (next == NULL) { |
Ian Elliott | 1962880 | 2015-02-04 12:06:46 -0700 | [diff] [blame] | 731 | len = (uint32_t) strlen(p); |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 732 | next = p + len; |
| 733 | } |
| 734 | else { |
Ian Elliott | 1962880 | 2015-02-04 12:06:46 -0700 | [diff] [blame] | 735 | len = (uint32_t) (next - p); |
Jon Ashburn | 5cda59c | 2014-10-03 16:31:35 -0600 | [diff] [blame] | 736 | sprintf(path, "%.*s", (len > sizeof(path) - 1) ? (int) sizeof(path) - 1 : len, p); |
| 737 | p = path; |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 738 | next++; |
| 739 | } |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 740 | |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 741 | // TODO/TBD: Do we want to do this on Windows, or just let Windows take |
| 742 | // care of its own search path (which it apparently has)? |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 743 | sysdir = opendir(p); |
| 744 | if (sysdir) { |
| 745 | dent = readdir(sysdir); |
| 746 | while (dent) { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 747 | /* Look for ICDs starting with VK_DRIVER_LIBRARY_PREFIX and |
| 748 | * ending with VK_LIBRARY_SUFFIX |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 749 | */ |
| 750 | if (!strncmp(dent->d_name, |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 751 | VK_DRIVER_LIBRARY_PREFIX, |
| 752 | VK_DRIVER_LIBRARY_PREFIX_LEN)) { |
Ian Elliott | 1962880 | 2015-02-04 12:06:46 -0700 | [diff] [blame] | 753 | uint32_t nlen = (uint32_t) strlen(dent->d_name); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 754 | const char *suf = dent->d_name + nlen - VK_LIBRARY_SUFFIX_LEN; |
| 755 | if ((nlen > VK_LIBRARY_SUFFIX_LEN) && |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 756 | !strncmp(suf, |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 757 | VK_LIBRARY_SUFFIX, |
| 758 | VK_LIBRARY_SUFFIX_LEN)) { |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 759 | snprintf(icd_library, 1024, "%s" DIRECTORY_SYMBOL "%s", p,dent->d_name); |
| 760 | loader_scanned_icd_add(icd_library); |
| 761 | } |
| 762 | } |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 763 | |
| 764 | dent = readdir(sysdir); |
| 765 | } |
| 766 | closedir(sysdir); |
| 767 | } |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 768 | } |
| 769 | |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 770 | #if defined(WIN32) |
| 771 | // Free any allocated memory: |
| 772 | if (must_free_libPaths) { |
| 773 | free(libPaths); |
| 774 | } |
| 775 | #endif // WIN32 |
| 776 | |
| 777 | // Note that we've scanned for ICDs: |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 778 | loader.icds_scanned = true; |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 779 | } |
| 780 | |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 781 | |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 782 | void layer_lib_scan(void) |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 783 | { |
| 784 | const char *p, *next; |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 785 | char *libPaths = NULL; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 786 | DIR *curdir; |
| 787 | struct dirent *dent; |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 788 | size_t len, i; |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 789 | char temp_str[1024]; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 790 | uint32_t count; |
| 791 | PFN_vkGetGlobalExtensionInfo fp_get_ext; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 792 | |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 793 | #if defined(WIN32) |
| 794 | bool must_free_libPaths; |
| 795 | libPaths = loader_get_registry_and_env(LAYERS_PATH_ENV, |
| 796 | LAYERS_PATH_REGISTRY_VALUE); |
| 797 | if (libPaths != NULL) { |
| 798 | must_free_libPaths = true; |
| 799 | } else { |
| 800 | must_free_libPaths = false; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 801 | libPaths = DEFAULT_VK_LAYERS_PATH; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 802 | } |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 803 | #else // WIN32 |
| 804 | if (geteuid() == getuid()) { |
| 805 | /* 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] | 806 | libPaths = getenv(LAYERS_PATH_ENV); |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 807 | } |
| 808 | if (libPaths == NULL) { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 809 | libPaths = DEFAULT_VK_LAYERS_PATH; |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 810 | } |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 811 | #endif // WIN32 |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 812 | |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 813 | if (libPaths == NULL) { |
| 814 | // Have no paths to search: |
Courtney Goeltzenleuchter | 57985ce | 2014-12-01 09:29:42 -0700 | [diff] [blame] | 815 | return; |
| 816 | } |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 817 | len = strlen(libPaths); |
Courtney Goeltzenleuchter | 57985ce | 2014-12-01 09:29:42 -0700 | [diff] [blame] | 818 | loader.layer_dirs = malloc(len+1); |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 819 | if (loader.layer_dirs == NULL) { |
| 820 | free(libPaths); |
Courtney Goeltzenleuchter | a66265b | 2014-12-02 18:12:51 -0700 | [diff] [blame] | 821 | return; |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 822 | } |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 823 | // Alloc passed, so we know there is enough space to hold the string |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 824 | strcpy(loader.layer_dirs, libPaths); |
| 825 | #if defined(WIN32) |
| 826 | // Free any allocated memory: |
| 827 | if (must_free_libPaths) { |
| 828 | free(libPaths); |
| 829 | must_free_libPaths = false; |
| 830 | } |
| 831 | #endif // WIN32 |
Courtney Goeltzenleuchter | 57985ce | 2014-12-01 09:29:42 -0700 | [diff] [blame] | 832 | libPaths = loader.layer_dirs; |
| 833 | |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 834 | /* cleanup any previously scanned libraries */ |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 835 | for (i = 0; i < loader.scanned_layer_count; i++) { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 836 | if (loader.scanned_layers[i].lib_name != NULL) |
| 837 | free(loader.scanned_layers[i].lib_name); |
| 838 | loader_destroy_ext_list(&loader.scanned_layers[i].global_extension_list); |
| 839 | loader.scanned_layers[i].lib_name = NULL; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 840 | } |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 841 | loader.scanned_layer_count = 0; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 842 | count = 0; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 843 | |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 844 | for (p = libPaths; *p; p = next) { |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 845 | next = strchr(p, PATH_SEPERATOR); |
| 846 | if (next == NULL) { |
Courtney Goeltzenleuchter | 0f1d8eb | 2015-06-07 17:28:17 -0600 | [diff] [blame] | 847 | len = (uint32_t) strlen(p); |
| 848 | next = p + len; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 849 | } |
| 850 | else { |
Courtney Goeltzenleuchter | 0f1d8eb | 2015-06-07 17:28:17 -0600 | [diff] [blame] | 851 | len = (uint32_t) (next - p); |
| 852 | *(char *) next = '\0'; |
| 853 | next++; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 854 | } |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 855 | |
Courtney Goeltzenleuchter | 0f1d8eb | 2015-06-07 17:28:17 -0600 | [diff] [blame] | 856 | curdir = opendir(p); |
| 857 | if (curdir) { |
| 858 | dent = readdir(curdir); |
| 859 | while (dent) { |
| 860 | /* Look for layers starting with VK_LAYER_LIBRARY_PREFIX and |
| 861 | * ending with VK_LIBRARY_SUFFIX |
| 862 | */ |
| 863 | if (!strncmp(dent->d_name, |
| 864 | VK_LAYER_LIBRARY_PREFIX, |
| 865 | VK_LAYER_LIBRARY_PREFIX_LEN)) { |
| 866 | uint32_t nlen = (uint32_t) strlen(dent->d_name); |
| 867 | const char *suf = dent->d_name + nlen - VK_LIBRARY_SUFFIX_LEN; |
| 868 | if ((nlen > VK_LIBRARY_SUFFIX_LEN) && |
| 869 | !strncmp(suf, |
| 870 | VK_LIBRARY_SUFFIX, |
| 871 | VK_LIBRARY_SUFFIX_LEN)) { |
| 872 | loader_platform_dl_handle handle; |
| 873 | snprintf(temp_str, sizeof(temp_str), |
| 874 | "%s" DIRECTORY_SYMBOL "%s",p,dent->d_name); |
| 875 | // Used to call: dlopen(temp_str, RTLD_LAZY) |
| 876 | loader_log(VK_DBG_REPORT_DEBUG_BIT, 0, |
| 877 | "Attempt to open library: %s\n", temp_str); |
| 878 | if ((handle = loader_platform_open_library(temp_str)) == NULL) { |
Courtney Goeltzenleuchter | 57fb157 | 2015-06-08 15:13:50 -0600 | [diff] [blame] | 879 | loader_log(VK_DBG_REPORT_DEBUG_BIT, 0, "open library failed\n"); |
Courtney Goeltzenleuchter | 0f1d8eb | 2015-06-07 17:28:17 -0600 | [diff] [blame] | 880 | dent = readdir(curdir); |
| 881 | continue; |
| 882 | } |
| 883 | loader_log(VK_DBG_REPORT_DEBUG_BIT, 0, |
| 884 | "Opened library: %s\n", temp_str); |
Courtney Goeltzenleuchter | a9e4af4 | 2015-06-01 14:49:17 -0600 | [diff] [blame] | 885 | |
Courtney Goeltzenleuchter | 0f1d8eb | 2015-06-07 17:28:17 -0600 | [diff] [blame] | 886 | /* TODO: Remove fixed count */ |
| 887 | if (count == MAX_LAYER_LIBRARIES) { |
| 888 | loader_log(VK_DBG_REPORT_ERROR_BIT, 0, |
| 889 | "%s ignored: max layer libraries exceed", |
| 890 | temp_str); |
| 891 | break; |
| 892 | } |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 893 | |
Courtney Goeltzenleuchter | 0f1d8eb | 2015-06-07 17:28:17 -0600 | [diff] [blame] | 894 | fp_get_ext = loader_platform_get_proc_address(handle, "vkGetGlobalExtensionInfo"); |
| 895 | if (!fp_get_ext) { |
| 896 | loader_log(VK_DBG_REPORT_WARN_BIT, 0, |
| 897 | "Couldn't dlsym vkGetGlobalExtensionInfo from library %s", |
| 898 | temp_str); |
| 899 | dent = readdir(curdir); |
| 900 | loader_platform_close_library(handle); |
| 901 | continue; |
| 902 | } |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 903 | |
Courtney Goeltzenleuchter | 0f1d8eb | 2015-06-07 17:28:17 -0600 | [diff] [blame] | 904 | loader.scanned_layers[count].lib_name = |
| 905 | malloc(strlen(temp_str) + 1); |
| 906 | if (loader.scanned_layers[count].lib_name == NULL) { |
| 907 | loader_log(VK_DBG_REPORT_ERROR_BIT, 0, "%s ignored: out of memory", temp_str); |
| 908 | break; |
| 909 | } |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 910 | |
Courtney Goeltzenleuchter | 0f1d8eb | 2015-06-07 17:28:17 -0600 | [diff] [blame] | 911 | strcpy(loader.scanned_layers[count].lib_name, temp_str); |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 912 | |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 913 | loader_log(VK_DBG_REPORT_DEBUG_BIT, 0, "Collecting global extensions for %s\n", temp_str); |
Courtney Goeltzenleuchter | 0f1d8eb | 2015-06-07 17:28:17 -0600 | [diff] [blame] | 914 | get_global_extensions( |
| 915 | fp_get_ext, |
| 916 | "vkGetGlobalExtensionInfo", |
| 917 | loader.scanned_layers[count].lib_name, |
| 918 | VK_EXTENSION_ORIGIN_LAYER, |
| 919 | &loader.scanned_layers[count].global_extension_list); |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 920 | |
Courtney Goeltzenleuchter | 0f1d8eb | 2015-06-07 17:28:17 -0600 | [diff] [blame] | 921 | fp_get_ext = loader_platform_get_proc_address(handle, |
| 922 | "vkGetPhysicalDeviceExtensionInfo"); |
| 923 | if (fp_get_ext) { |
| 924 | loader.scanned_layers[count].physical_device_extensions_supported = true; |
| 925 | } |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 926 | |
Courtney Goeltzenleuchter | 0f1d8eb | 2015-06-07 17:28:17 -0600 | [diff] [blame] | 927 | count++; |
| 928 | loader_platform_close_library(handle); |
| 929 | } |
| 930 | } |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 931 | |
Courtney Goeltzenleuchter | 0f1d8eb | 2015-06-07 17:28:17 -0600 | [diff] [blame] | 932 | dent = readdir(curdir); |
| 933 | } // while (dir_entry) |
| 934 | if (count == MAX_LAYER_LIBRARIES) |
| 935 | break; |
| 936 | closedir(curdir); |
| 937 | } // if (curdir)) |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 938 | } // for (libpaths) |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 939 | |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 940 | loader.scanned_layer_count = count; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 941 | loader.layers_scanned = true; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 942 | } |
| 943 | |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 944 | static void* VKAPI loader_gpa_instance_internal(VkInstance inst, const char * pName) |
| 945 | { |
| 946 | // inst is not wrapped |
| 947 | if (inst == VK_NULL_HANDLE) { |
| 948 | return NULL; |
| 949 | } |
| 950 | VkLayerInstanceDispatchTable* disp_table = * (VkLayerInstanceDispatchTable **) inst; |
| 951 | void *addr; |
| 952 | |
Jon Ashburn | 8fd0825 | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 953 | if (!strcmp(pName, "vkGetInstanceProcAddr")) |
| 954 | return (void *) loader_gpa_instance_internal; |
| 955 | |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 956 | if (disp_table == NULL) |
| 957 | return NULL; |
| 958 | |
| 959 | addr = loader_lookup_instance_dispatch_table(disp_table, pName); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 960 | if (addr) { |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 961 | return addr; |
Jon Ashburn | 3d526cb | 2015-04-13 18:10:06 -0600 | [diff] [blame] | 962 | } |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 963 | |
| 964 | if (disp_table->GetInstanceProcAddr == NULL) { |
| 965 | return NULL; |
| 966 | } |
| 967 | return disp_table->GetInstanceProcAddr(inst, pName); |
Jon Ashburn | 3d526cb | 2015-04-13 18:10:06 -0600 | [diff] [blame] | 968 | } |
| 969 | |
Jon Ashburn | 128f942 | 2015-05-28 19:16:58 -0600 | [diff] [blame] | 970 | struct loader_icd * loader_get_icd(const VkPhysicalDevice gpu, uint32_t *gpu_index) |
Jon Ashburn | 876b1ac | 2014-10-17 15:09:07 -0600 | [diff] [blame] | 971 | { |
Jon Ashburn | 128f942 | 2015-05-28 19:16:58 -0600 | [diff] [blame] | 972 | |
Jon Ashburn | 98bd454 | 2015-01-29 16:44:24 -0700 | [diff] [blame] | 973 | for (struct loader_instance *inst = loader.instances; inst; inst = inst->next) { |
| 974 | for (struct loader_icd *icd = inst->icds; icd; icd = icd->next) { |
| 975 | for (uint32_t i = 0; i < icd->gpu_count; i++) |
Jon Ashburn | 128f942 | 2015-05-28 19:16:58 -0600 | [diff] [blame] | 976 | if (icd->gpus[i] == gpu) { |
Jon Ashburn | 98bd454 | 2015-01-29 16:44:24 -0700 | [diff] [blame] | 977 | *gpu_index = i; |
| 978 | return icd; |
| 979 | } |
| 980 | } |
Jon Ashburn | 876b1ac | 2014-10-17 15:09:07 -0600 | [diff] [blame] | 981 | } |
| 982 | return NULL; |
| 983 | } |
| 984 | |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 985 | 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] | 986 | { |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 987 | if (icd->layer_count[gpu_index]) |
| 988 | return true; |
| 989 | else |
| 990 | return false; |
Jon Ashburn | 876b1ac | 2014-10-17 15:09:07 -0600 | [diff] [blame] | 991 | } |
| 992 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 993 | static loader_platform_dl_handle loader_add_layer_lib( |
Jon Ashburn | 4f67d74 | 2015-05-27 13:19:22 -0600 | [diff] [blame] | 994 | const char *chain_type, |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 995 | struct loader_extension_property *ext_prop) |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 996 | { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 997 | struct loader_lib_info *new_layer_lib_list, *my_lib; |
| 998 | |
| 999 | /* Only loader layer libraries here */ |
| 1000 | if (ext_prop->origin != VK_EXTENSION_ORIGIN_LAYER) { |
| 1001 | return NULL; |
| 1002 | } |
| 1003 | |
| 1004 | for (uint32_t i = 0; i < loader.loaded_layer_lib_count; i++) { |
| 1005 | if (strcmp(loader.loaded_layer_lib_list[i].lib_name, ext_prop->lib_name) == 0) { |
| 1006 | /* Have already loaded this library, just increment ref count */ |
| 1007 | loader.loaded_layer_lib_list[i].ref_count++; |
Jon Ashburn | e68a9ff | 2015-05-25 14:11:37 -0600 | [diff] [blame] | 1008 | loader_log(VK_DBG_REPORT_INFO_BIT, 0, |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 1009 | "%s Chain: Increment layer reference count for layer library %s", |
| 1010 | chain_type, ext_prop->lib_name); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1011 | return loader.loaded_layer_lib_list[i].lib_handle; |
| 1012 | } |
| 1013 | } |
| 1014 | |
| 1015 | /* Haven't seen this library so load it */ |
| 1016 | new_layer_lib_list = realloc(loader.loaded_layer_lib_list, |
| 1017 | (loader.loaded_layer_lib_count + 1) * sizeof(struct loader_lib_info)); |
| 1018 | if (!new_layer_lib_list) { |
| 1019 | loader_log(VK_DBG_REPORT_ERROR_BIT, 0, "loader: malloc failed"); |
| 1020 | return NULL; |
| 1021 | } |
| 1022 | |
| 1023 | my_lib = &new_layer_lib_list[loader.loaded_layer_lib_count]; |
| 1024 | |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 1025 | /* NOTE: We require that the extension property be immutable */ |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1026 | my_lib->lib_name = ext_prop->lib_name; |
| 1027 | my_lib->ref_count = 0; |
| 1028 | my_lib->lib_handle = NULL; |
| 1029 | |
| 1030 | if ((my_lib->lib_handle = loader_platform_open_library(my_lib->lib_name)) == NULL) { |
| 1031 | loader_log(VK_DBG_REPORT_ERROR_BIT, 0, |
| 1032 | loader_platform_open_library_error(my_lib->lib_name)); |
| 1033 | return NULL; |
| 1034 | } else { |
| 1035 | loader_log(VK_DBG_REPORT_INFO_BIT, 0, |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 1036 | "Chain: %s: Loading layer library %s", |
| 1037 | chain_type, ext_prop->lib_name); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1038 | } |
| 1039 | loader.loaded_layer_lib_count++; |
| 1040 | loader.loaded_layer_lib_list = new_layer_lib_list; |
| 1041 | my_lib->ref_count++; |
| 1042 | |
| 1043 | return my_lib->lib_handle; |
| 1044 | } |
| 1045 | |
| 1046 | static void loader_remove_layer_lib( |
| 1047 | struct loader_instance *inst, |
| 1048 | struct loader_extension_property *ext_prop) |
| 1049 | { |
| 1050 | uint32_t idx; |
| 1051 | struct loader_lib_info *new_layer_lib_list, *my_lib; |
| 1052 | |
| 1053 | /* Only loader layer libraries here */ |
| 1054 | if (ext_prop->origin != VK_EXTENSION_ORIGIN_LAYER) { |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 1055 | return; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1056 | } |
Jon Ashburn | df7d584 | 2014-10-16 15:48:50 -0600 | [diff] [blame] | 1057 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1058 | for (uint32_t i = 0; i < loader.loaded_layer_lib_count; i++) { |
| 1059 | if (strcmp(loader.loaded_layer_lib_list[i].lib_name, ext_prop->lib_name) == 0) { |
| 1060 | /* found matching library */ |
| 1061 | idx = i; |
| 1062 | my_lib = &loader.loaded_layer_lib_list[i]; |
| 1063 | break; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 1064 | } |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 1065 | } |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 1066 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1067 | my_lib->ref_count--; |
| 1068 | inst->layer_count--; |
| 1069 | if (my_lib->ref_count > 0) { |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 1070 | loader_log(VK_DBG_REPORT_INFO_BIT, 0, |
| 1071 | "Decrement reference count for layer library %s", ext_prop->lib_name); |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 1072 | return; |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 1073 | } |
Jon Ashburn | 19c2502 | 2015-04-14 14:14:48 -0600 | [diff] [blame] | 1074 | |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 1075 | loader_platform_close_library(my_lib->lib_handle); |
| 1076 | loader_log(VK_DBG_REPORT_INFO_BIT, 0, |
| 1077 | "Unloading layer library %s", ext_prop->lib_name); |
| 1078 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1079 | /* Need to remove unused library from list */ |
| 1080 | new_layer_lib_list = malloc((loader.loaded_layer_lib_count - 1) * sizeof(struct loader_lib_info)); |
| 1081 | if (!new_layer_lib_list) { |
| 1082 | loader_log(VK_DBG_REPORT_ERROR_BIT, 0, "loader: malloc failed"); |
| 1083 | return; |
| 1084 | } |
| 1085 | |
| 1086 | if (idx > 0) { |
| 1087 | /* Copy records before idx */ |
| 1088 | memcpy(new_layer_lib_list, &loader.loaded_layer_lib_list[0], |
| 1089 | sizeof(struct loader_lib_info) * idx); |
| 1090 | } |
| 1091 | if (idx < (loader.loaded_layer_lib_count - 1)) { |
| 1092 | /* Copy records after idx */ |
| 1093 | memcpy(&new_layer_lib_list[idx], &loader.loaded_layer_lib_list[idx+1], |
| 1094 | sizeof(struct loader_lib_info) * (loader.loaded_layer_lib_count - idx - 1)); |
| 1095 | } |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 1096 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1097 | free(loader.loaded_layer_lib_list); |
| 1098 | loader.loaded_layer_lib_count--; |
| 1099 | loader.loaded_layer_lib_list = new_layer_lib_list; |
Jon Ashburn | b835805 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 1100 | } |
| 1101 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1102 | static void loader_add_layer_env( |
| 1103 | struct loader_extension_list *ext_list, |
| 1104 | const struct loader_extension_list *search_list) |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 1105 | { |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 1106 | char *layerEnv; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1107 | uint32_t len; |
Jon Ashburn | d09bd10 | 2014-10-22 21:15:26 -0600 | [diff] [blame] | 1108 | char *p, *pOrig, *next, *name; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 1109 | |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 1110 | #if defined(WIN32) |
| 1111 | layerEnv = loader_get_registry_and_env(LAYER_NAMES_ENV, |
| 1112 | LAYER_NAMES_REGISTRY_VALUE); |
| 1113 | #else // WIN32 |
| 1114 | layerEnv = getenv(LAYER_NAMES_ENV); |
| 1115 | #endif // WIN32 |
| 1116 | if (layerEnv == NULL) { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1117 | return; |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 1118 | } |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 1119 | p = malloc(strlen(layerEnv) + 1); |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 1120 | if (p == NULL) { |
| 1121 | #if defined(WIN32) |
| 1122 | free(layerEnv); |
| 1123 | #endif // WIN32 |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1124 | return; |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 1125 | } |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 1126 | strcpy(p, layerEnv); |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 1127 | #if defined(WIN32) |
| 1128 | free(layerEnv); |
| 1129 | #endif // WIN32 |
Jon Ashburn | d09bd10 | 2014-10-22 21:15:26 -0600 | [diff] [blame] | 1130 | pOrig = p; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 1131 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1132 | while (p && *p ) { |
Jon Ashburn | 19c2502 | 2015-04-14 14:14:48 -0600 | [diff] [blame] | 1133 | //memset(&lib_name[0], 0, sizeof(const char *) * MAX_LAYER_LIBRARIES); |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1134 | next = strchr(p, PATH_SEPERATOR); |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 1135 | if (next == NULL) { |
Ian Elliott | 1962880 | 2015-02-04 12:06:46 -0700 | [diff] [blame] | 1136 | len = (uint32_t) strlen(p); |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 1137 | next = p + len; |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 1138 | } else { |
Ian Elliott | 1962880 | 2015-02-04 12:06:46 -0700 | [diff] [blame] | 1139 | len = (uint32_t) (next - p); |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 1140 | *(char *) next = '\0'; |
| 1141 | next++; |
| 1142 | } |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 1143 | name = basename(p); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1144 | loader_search_ext_list_for_name(name, search_list, ext_list); |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 1145 | p = next; |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 1146 | } |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 1147 | |
Jon Ashburn | d09bd10 | 2014-10-22 21:15:26 -0600 | [diff] [blame] | 1148 | free(pOrig); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1149 | return; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 1150 | } |
| 1151 | |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 1152 | |
Courtney Goeltzenleuchter | 7d0023c | 2015-06-08 15:09:22 -0600 | [diff] [blame] | 1153 | void loader_deactivate_instance_layers(struct loader_instance *instance) |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 1154 | { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1155 | if (!instance->layer_count) { |
| 1156 | return; |
| 1157 | } |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 1158 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1159 | /* Create instance chain of enabled layers */ |
Courtney Goeltzenleuchter | 7d0023c | 2015-06-08 15:09:22 -0600 | [diff] [blame] | 1160 | for (uint32_t i = 0; i < instance->activated_layer_list.count; i++) { |
| 1161 | struct loader_extension_property *ext_prop = &instance->activated_layer_list.list[i]; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1162 | |
| 1163 | loader_remove_layer_lib(instance, ext_prop); |
| 1164 | |
| 1165 | instance->layer_count--; |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 1166 | } |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 1167 | |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 1168 | } |
| 1169 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1170 | void loader_enable_instance_layers(struct loader_instance *inst) |
| 1171 | { |
| 1172 | if (inst == NULL) |
| 1173 | return; |
| 1174 | |
| 1175 | /* Add any layers specified in the environment first */ |
| 1176 | loader_add_layer_env(&inst->enabled_instance_extensions, &loader.global_extensions); |
| 1177 | |
| 1178 | /* Add layers / extensions specified by the application */ |
| 1179 | loader_add_vk_ext_to_ext_list( |
| 1180 | &inst->enabled_instance_extensions, |
| 1181 | inst->app_extension_count, |
| 1182 | inst->app_extension_props, |
| 1183 | &loader.global_extensions); |
| 1184 | } |
| 1185 | |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 1186 | uint32_t loader_activate_instance_layers(struct loader_instance *inst) |
| 1187 | { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1188 | uint32_t layer_idx; |
Jon Ashburn | 128f942 | 2015-05-28 19:16:58 -0600 | [diff] [blame] | 1189 | VkBaseLayerObject *wrappedInstance; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1190 | |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 1191 | if (inst == NULL) |
| 1192 | return 0; |
| 1193 | |
| 1194 | // NOTE inst is unwrapped at this point in time |
| 1195 | VkObject baseObj = (VkObject) inst; |
| 1196 | VkObject nextObj = (VkObject) inst; |
| 1197 | VkBaseLayerObject *nextInstObj; |
| 1198 | PFN_vkGetInstanceProcAddr nextGPA = loader_gpa_instance_internal; |
| 1199 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1200 | /* |
| 1201 | * Figure out how many actual layers will need to be wrapped. |
| 1202 | */ |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1203 | for (uint32_t i = 0; i < inst->enabled_instance_extensions.count; i++) { |
| 1204 | struct loader_extension_property *ext_prop = &inst->enabled_instance_extensions.list[i]; |
Courtney Goeltzenleuchter | 0f1d8eb | 2015-06-07 17:28:17 -0600 | [diff] [blame] | 1205 | if (ext_prop->alias) { |
| 1206 | ext_prop = ext_prop->alias; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1207 | } |
Courtney Goeltzenleuchter | 0f1d8eb | 2015-06-07 17:28:17 -0600 | [diff] [blame] | 1208 | if (ext_prop->origin != VK_EXTENSION_ORIGIN_LAYER) { |
| 1209 | continue; |
| 1210 | } |
| 1211 | loader_add_to_ext_list(&inst->activated_layer_list, 1, ext_prop); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1212 | } |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 1213 | |
Courtney Goeltzenleuchter | 0f1d8eb | 2015-06-07 17:28:17 -0600 | [diff] [blame] | 1214 | inst->layer_count = inst->activated_layer_list.count; |
| 1215 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1216 | if (!inst->layer_count) { |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 1217 | return 0; |
| 1218 | } |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1219 | |
Jon Ashburn | 128f942 | 2015-05-28 19:16:58 -0600 | [diff] [blame] | 1220 | wrappedInstance = malloc(sizeof(VkBaseLayerObject) |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1221 | * inst->layer_count); |
Jon Ashburn | 128f942 | 2015-05-28 19:16:58 -0600 | [diff] [blame] | 1222 | if (!wrappedInstance) { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1223 | loader_log(VK_DBG_REPORT_ERROR_BIT, 0, "Failed to malloc Instance objects for layer"); |
| 1224 | return 0; |
| 1225 | } |
| 1226 | |
| 1227 | /* Create instance chain of enabled layers */ |
| 1228 | layer_idx = inst->layer_count - 1; |
Courtney Goeltzenleuchter | 0f1d8eb | 2015-06-07 17:28:17 -0600 | [diff] [blame] | 1229 | for (int32_t i = inst->activated_layer_list.count - 1; i >= 0; i--) { |
| 1230 | struct loader_extension_property *ext_prop = &inst->activated_layer_list.list[i]; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1231 | loader_platform_dl_handle lib_handle; |
| 1232 | |
| 1233 | /* |
Courtney Goeltzenleuchter | ee3b16a | 2015-06-01 14:12:42 -0600 | [diff] [blame] | 1234 | * For global exenstions implemented within the loader (i.e. WSI, DEBUG_REPORT |
| 1235 | * the extension must provide two entry points for the loader to use: |
| 1236 | * - "trampoline" entry point - this is the address returned by GetProcAddr |
| 1237 | * and will always do what's necessary to support a global call. |
| 1238 | * - "terminator" function - this function will be put at the end of the |
| 1239 | * instance chain and will contain the necessary logica to call / process |
| 1240 | * the extension for the appropriate ICDs that are available. |
| 1241 | * There is no generic mechanism for including these functions, the references |
| 1242 | * must be placed into the appropriate loader entry points. |
| 1243 | * GetInstanceProcAddr: call extension GetInstanceProcAddr to check for GetProcAddr requests |
| 1244 | * loader_coalesce_extensions(void) - add extension records to the list of global |
| 1245 | * extension available to the app. |
| 1246 | * instance_disp - add function pointer for terminator function to this array. |
| 1247 | * The extension itself should be in a separate file that will be |
| 1248 | * linked directly with the loader. |
| 1249 | * Note: An extension's Get*ProcAddr should not return a function pointer for |
| 1250 | * any extension entry points until the extension has been enabled. |
| 1251 | * To do this requires a different behavior from Get*ProcAddr functions implemented |
| 1252 | * in layers. |
| 1253 | * The very first call to a layer will be it's Get*ProcAddr function requesting |
| 1254 | * the layer's vkGet*ProcAddr. The layer should intialize it's internal dispatch table |
| 1255 | * with the wrapped object given (either Instance or Device) and return the layer's |
| 1256 | * Get*ProcAddr function. The layer should also use this opportunity to record the |
| 1257 | * baseObject so that it can find the correct local dispatch table on future calls. |
| 1258 | * Subsequent calls to Get*ProcAddr, CreateInstance, CreateDevice |
| 1259 | * will not use a wrapped object and must look up their local dispatch table from |
| 1260 | * the given baseObject. |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1261 | */ |
Courtney Goeltzenleuchter | 0f1d8eb | 2015-06-07 17:28:17 -0600 | [diff] [blame] | 1262 | assert(ext_prop->origin == VK_EXTENSION_ORIGIN_LAYER); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1263 | |
Jon Ashburn | 128f942 | 2015-05-28 19:16:58 -0600 | [diff] [blame] | 1264 | nextInstObj = (wrappedInstance + layer_idx); |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 1265 | nextInstObj->pGPA = nextGPA; |
| 1266 | nextInstObj->baseObject = baseObj; |
| 1267 | nextInstObj->nextObject = nextObj; |
| 1268 | nextObj = (VkObject) nextInstObj; |
| 1269 | |
| 1270 | char funcStr[256]; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1271 | snprintf(funcStr, 256, "%sGetInstanceProcAddr", ext_prop->info.name); |
Jon Ashburn | 4f67d74 | 2015-05-27 13:19:22 -0600 | [diff] [blame] | 1272 | lib_handle = loader_add_layer_lib("instance", ext_prop); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1273 | if ((nextGPA = (PFN_vkGetInstanceProcAddr) loader_platform_get_proc_address(lib_handle, funcStr)) == NULL) |
| 1274 | nextGPA = (PFN_vkGetInstanceProcAddr) loader_platform_get_proc_address(lib_handle, "vkGetInstanceProcAddr"); |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 1275 | if (!nextGPA) { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1276 | loader_log(VK_DBG_REPORT_ERROR_BIT, 0, "Failed to find vkGetInstanceProcAddr in layer %s", ext_prop->lib_name); |
Courtney Goeltzenleuchter | a9e4af4 | 2015-06-01 14:49:17 -0600 | [diff] [blame] | 1277 | |
| 1278 | /* TODO: Should we return nextObj, nextGPA to previous? */ |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 1279 | continue; |
| 1280 | } |
| 1281 | |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 1282 | loader_log(VK_DBG_REPORT_INFO_BIT, 0, |
| 1283 | "Insert instance layer library %s for extension: %s", |
| 1284 | ext_prop->lib_name, ext_prop->info.name); |
| 1285 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1286 | layer_idx--; |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 1287 | } |
| 1288 | |
Jon Ashburn | 8fd0825 | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 1289 | loader_init_instance_core_dispatch_table(inst->disp, nextGPA, (VkInstance) nextObj, (VkInstance) baseObj); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1290 | |
Jon Ashburn | 128f942 | 2015-05-28 19:16:58 -0600 | [diff] [blame] | 1291 | free(wrappedInstance); |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 1292 | return inst->layer_count; |
| 1293 | } |
| 1294 | |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 1295 | void loader_activate_instance_layer_extensions(struct loader_instance *inst) |
| 1296 | { |
| 1297 | |
| 1298 | loader_init_instance_extension_dispatch_table(inst->disp, |
| 1299 | inst->disp->GetInstanceProcAddr, |
Jon Ashburn | 128f942 | 2015-05-28 19:16:58 -0600 | [diff] [blame] | 1300 | (VkInstance) inst); |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 1301 | } |
| 1302 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1303 | void loader_enable_device_layers(struct loader_icd *icd, uint32_t gpu_index) |
| 1304 | { |
| 1305 | if (icd == NULL) |
| 1306 | return; |
| 1307 | |
| 1308 | /* Add any layers specified in the environment first */ |
| 1309 | loader_add_layer_env(&icd->enabled_device_extensions[gpu_index], &loader.global_extensions); |
| 1310 | |
| 1311 | /* Add layers / extensions specified by the application */ |
| 1312 | loader_add_vk_ext_to_ext_list( |
| 1313 | &icd->enabled_device_extensions[gpu_index], |
| 1314 | icd->app_extension_count[gpu_index], |
| 1315 | icd->app_extension_props[gpu_index], |
| 1316 | &loader.global_extensions); |
| 1317 | } |
| 1318 | |
| 1319 | extern uint32_t loader_activate_device_layers( |
| 1320 | VkDevice device, |
| 1321 | struct loader_icd *icd, |
| 1322 | uint32_t gpu_index, |
| 1323 | uint32_t ext_count, |
| 1324 | const VkExtensionProperties *ext_props) |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 1325 | { |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1326 | uint32_t count; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1327 | uint32_t layer_idx; |
| 1328 | |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 1329 | if (!icd) |
| 1330 | return 0; |
Jon Ashburn | 83a6425 | 2015-04-15 11:31:12 -0600 | [diff] [blame] | 1331 | assert(gpu_index < MAX_GPUS_FOR_LAYER); |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 1332 | |
| 1333 | /* activate any layer libraries */ |
| 1334 | if (!loader_layers_activated(icd, gpu_index)) { |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 1335 | VkObject nextObj = (VkObject) device; |
| 1336 | VkObject baseObj = nextObj; |
| 1337 | VkBaseLayerObject *nextGpuObj; |
Jon Ashburn | 7c09612 | 2015-05-22 09:19:49 -0600 | [diff] [blame] | 1338 | PFN_vkGetDeviceProcAddr nextGPA = icd->GetDeviceProcAddr; |
Jon Ashburn | ce94f31 | 2015-05-28 19:25:20 -0600 | [diff] [blame^] | 1339 | VkBaseLayerObject *wrappedGpus; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1340 | count = 0; |
| 1341 | for (uint32_t i = 0; i < icd->enabled_device_extensions[gpu_index].count; i++) { |
| 1342 | struct loader_extension_property *ext_prop = &icd->enabled_device_extensions[gpu_index].list[i]; |
| 1343 | if (ext_prop->origin == VK_EXTENSION_ORIGIN_LAYER) { |
| 1344 | count++; |
| 1345 | } |
| 1346 | } |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 1347 | if (!count) |
| 1348 | return 0; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1349 | |
| 1350 | icd->layer_count[gpu_index] = count; |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 1351 | |
Jon Ashburn | ce94f31 | 2015-05-28 19:25:20 -0600 | [diff] [blame^] | 1352 | wrappedGpus = malloc(sizeof(VkBaseLayerObject) * icd->layer_count[gpu_index]); |
| 1353 | if (! wrappedGpus) { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1354 | loader_log(VK_DBG_REPORT_ERROR_BIT, 0, "Failed to malloc Gpu objects for layer"); |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 1355 | return 0; |
| 1356 | } |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1357 | layer_idx = count - 1; |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1358 | for (int32_t i = icd->layer_count[gpu_index] - 1; i >= 0; i--) { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1359 | struct loader_extension_property *ext_prop = &icd->enabled_device_extensions[gpu_index].list[i]; |
| 1360 | loader_platform_dl_handle lib_handle; |
| 1361 | |
| 1362 | if (ext_prop->origin != VK_EXTENSION_ORIGIN_LAYER) { |
| 1363 | continue; |
| 1364 | } |
| 1365 | |
Jon Ashburn | ce94f31 | 2015-05-28 19:25:20 -0600 | [diff] [blame^] | 1366 | nextGpuObj = (wrappedGpus + i); |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 1367 | nextGpuObj->pGPA = nextGPA; |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 1368 | nextGpuObj->baseObject = baseObj; |
| 1369 | nextGpuObj->nextObject = nextObj; |
| 1370 | nextObj = (VkObject) nextGpuObj; |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 1371 | |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 1372 | char funcStr[256]; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1373 | snprintf(funcStr, 256, "%sGetDeviceProcAddr", ext_prop->info.name); |
Jon Ashburn | 4f67d74 | 2015-05-27 13:19:22 -0600 | [diff] [blame] | 1374 | lib_handle = loader_add_layer_lib("device", ext_prop); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1375 | if ((nextGPA = (PFN_vkGetDeviceProcAddr) loader_platform_get_proc_address(lib_handle, funcStr)) == NULL) |
| 1376 | nextGPA = (PFN_vkGetDeviceProcAddr) loader_platform_get_proc_address(lib_handle, "vkGetDeviceProcAddr"); |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 1377 | if (!nextGPA) { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1378 | loader_log(VK_DBG_REPORT_ERROR_BIT, 0, "Failed to find vkGetDeviceProcAddr in layer %s", ext_prop->info.name); |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 1379 | continue; |
| 1380 | } |
| 1381 | |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 1382 | loader_log(VK_DBG_REPORT_INFO_BIT, 0, |
| 1383 | "Insert device layer library %s for extension: %s", |
| 1384 | ext_prop->lib_name, ext_prop->info.name); |
| 1385 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1386 | layer_idx--; |
| 1387 | } |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 1388 | |
Jon Ashburn | 8fd0825 | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 1389 | loader_init_device_dispatch_table(icd->loader_dispatch + gpu_index, nextGPA, |
| 1390 | (VkPhysicalDevice) nextObj, (VkPhysicalDevice) baseObj); |
Jon Ashburn | ce94f31 | 2015-05-28 19:25:20 -0600 | [diff] [blame^] | 1391 | free(wrappedGpus); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1392 | } else { |
| 1393 | // TODO: Check that active layers match requested? |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 1394 | } |
| 1395 | return icd->layer_count[gpu_index]; |
| 1396 | } |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 1397 | |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 1398 | VkResult loader_CreateInstance( |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1399 | const VkInstanceCreateInfo* pCreateInfo, |
| 1400 | VkInstance* pInstance) |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 1401 | { |
Jon Ashburn | eed0c00 | 2015-05-21 17:42:17 -0600 | [diff] [blame] | 1402 | struct loader_instance *ptr_instance = *(struct loader_instance **) pInstance; |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 1403 | struct loader_scanned_icds *scanned_icds; |
| 1404 | struct loader_icd *icd; |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 1405 | VkResult res; |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 1406 | |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 1407 | scanned_icds = loader.scanned_icd_list; |
| 1408 | while (scanned_icds) { |
| 1409 | icd = loader_icd_add(ptr_instance, scanned_icds); |
| 1410 | if (icd) { |
Jon Ashburn | b317fad | 2015-04-04 14:52:07 -0600 | [diff] [blame] | 1411 | res = scanned_icds->CreateInstance(pCreateInfo, |
Jon Ashburn | 3da71f2 | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 1412 | &(icd->instance)); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1413 | if (res != VK_SUCCESS) |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 1414 | { |
| 1415 | ptr_instance->icds = ptr_instance->icds->next; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1416 | loader_icd_destroy(ptr_instance, icd); |
Jon Ashburn | 3da71f2 | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 1417 | icd->instance = VK_NULL_HANDLE; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1418 | loader_log(VK_DBG_REPORT_WARN_BIT, 0, |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 1419 | "ICD ignored: failed to CreateInstance on device"); |
Jon Ashburn | 3da71f2 | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 1420 | } else |
| 1421 | { |
| 1422 | loader_icd_init_entrys(icd, scanned_icds); |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 1423 | } |
| 1424 | } |
| 1425 | scanned_icds = scanned_icds->next; |
| 1426 | } |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 1427 | |
Ian Elliott | eb45076 | 2015-02-05 15:19:15 -0700 | [diff] [blame] | 1428 | if (ptr_instance->icds == NULL) { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1429 | return VK_ERROR_INCOMPATIBLE_DRIVER; |
Ian Elliott | eb45076 | 2015-02-05 15:19:15 -0700 | [diff] [blame] | 1430 | } |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 1431 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1432 | return res; |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 1433 | } |
| 1434 | |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 1435 | VkResult loader_DestroyInstance( |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1436 | VkInstance instance) |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 1437 | { |
Courtney Goeltzenleuchter | deceded | 2015-06-08 15:04:02 -0600 | [diff] [blame] | 1438 | struct loader_instance *ptr_instance = loader_instance(instance); |
Jon Ashburn | 3da71f2 | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 1439 | struct loader_icd *icds = ptr_instance->icds; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1440 | VkResult res; |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 1441 | |
| 1442 | // Remove this instance from the list of instances: |
| 1443 | struct loader_instance *prev = NULL; |
| 1444 | struct loader_instance *next = loader.instances; |
| 1445 | while (next != NULL) { |
| 1446 | if (next == ptr_instance) { |
| 1447 | // Remove this instance from the list: |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1448 | free(ptr_instance->app_extension_props); |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 1449 | if (prev) |
| 1450 | prev->next = next->next; |
Jon Ashburn | c5c4960 | 2015-02-03 09:26:59 -0700 | [diff] [blame] | 1451 | else |
| 1452 | loader.instances = next->next; |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 1453 | break; |
| 1454 | } |
| 1455 | prev = next; |
| 1456 | next = next->next; |
| 1457 | } |
| 1458 | if (next == NULL) { |
| 1459 | // This must be an invalid instance handle or empty list |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1460 | return VK_ERROR_INVALID_HANDLE; |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 1461 | } |
| 1462 | |
Jon Ashburn | 3da71f2 | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 1463 | while (icds) { |
| 1464 | if (icds->instance) { |
| 1465 | res = icds->DestroyInstance(icds->instance); |
Tony Barbour | f20f87b | 2015-04-22 09:02:32 -0600 | [diff] [blame] | 1466 | if (res != VK_SUCCESS) |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1467 | loader_log(VK_DBG_REPORT_WARN_BIT, 0, |
Tony Barbour | f20f87b | 2015-04-22 09:02:32 -0600 | [diff] [blame] | 1468 | "ICD ignored: failed to DestroyInstance on device"); |
| 1469 | } |
Jon Ashburn | 128f942 | 2015-05-28 19:16:58 -0600 | [diff] [blame] | 1470 | loader_icd_destroy(ptr_instance, icds); |
Jon Ashburn | 3da71f2 | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 1471 | icds->instance = VK_NULL_HANDLE; |
| 1472 | icds = icds->next; |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 1473 | } |
| 1474 | |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 1475 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1476 | return VK_SUCCESS; |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 1477 | } |
| 1478 | |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 1479 | VkResult loader_init_physical_device_info( |
| 1480 | struct loader_instance *ptr_instance) |
| 1481 | { |
| 1482 | struct loader_icd *icd; |
| 1483 | uint32_t n, count = 0; |
| 1484 | VkResult res = VK_ERROR_UNKNOWN; |
| 1485 | |
| 1486 | icd = ptr_instance->icds; |
| 1487 | while (icd) { |
| 1488 | res = icd->EnumeratePhysicalDevices(icd->instance, &n, NULL); |
| 1489 | if (res != VK_SUCCESS) |
| 1490 | return res; |
| 1491 | icd->gpu_count = n; |
| 1492 | count += n; |
| 1493 | icd = icd->next; |
| 1494 | } |
| 1495 | |
| 1496 | ptr_instance->total_gpu_count = count; |
| 1497 | |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 1498 | icd = ptr_instance->icds; |
| 1499 | while (icd) { |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 1500 | PFN_vkGetDeviceProcAddr get_proc_addr = icd->GetDeviceProcAddr; |
| 1501 | |
| 1502 | n = icd->gpu_count; |
Jon Ashburn | 128f942 | 2015-05-28 19:16:58 -0600 | [diff] [blame] | 1503 | icd->gpus = (VkPhysicalDevice *) malloc(n * sizeof(VkPhysicalDevice)); |
| 1504 | if (!icd->gpus) { |
| 1505 | /* TODO: Add cleanup code here */ |
| 1506 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 1507 | } |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 1508 | res = icd->EnumeratePhysicalDevices( |
| 1509 | icd->instance, |
| 1510 | &n, |
Jon Ashburn | 128f942 | 2015-05-28 19:16:58 -0600 | [diff] [blame] | 1511 | icd->gpus); |
| 1512 | if ((res == VK_SUCCESS) && (n == icd->gpu_count)) { |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 1513 | |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 1514 | icd->loader_dispatch = (VkLayerDispatchTable *) malloc(n * |
| 1515 | sizeof(VkLayerDispatchTable)); |
| 1516 | for (unsigned int i = 0; i < n; i++) { |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 1517 | |
| 1518 | loader_init_device_dispatch_table(icd->loader_dispatch + i, |
Jon Ashburn | 128f942 | 2015-05-28 19:16:58 -0600 | [diff] [blame] | 1519 | get_proc_addr, icd->gpus[i], icd->gpus[i]); |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 1520 | |
Jon Ashburn | 128f942 | 2015-05-28 19:16:58 -0600 | [diff] [blame] | 1521 | loader_init_dispatch(icd->gpus[i], ptr_instance->disp); |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 1522 | |
| 1523 | if (!loader_init_ext_list(&icd->device_extension_cache[i])) { |
| 1524 | /* TODO: Add cleanup code here */ |
| 1525 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 1526 | } |
| 1527 | if (res == VK_SUCCESS && icd->GetPhysicalDeviceExtensionInfo) { |
| 1528 | size_t data_size; |
| 1529 | uint32_t extension_count; |
| 1530 | |
| 1531 | data_size = sizeof(extension_count); |
Jon Ashburn | 128f942 | 2015-05-28 19:16:58 -0600 | [diff] [blame] | 1532 | res = icd->GetPhysicalDeviceExtensionInfo(icd->gpus[i], VK_EXTENSION_INFO_TYPE_COUNT, 0, &data_size, &extension_count); |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 1533 | if (data_size == sizeof(extension_count) && res == VK_SUCCESS) { |
| 1534 | struct loader_extension_property ext_props; |
| 1535 | |
| 1536 | /* Gather all the ICD extensions */ |
| 1537 | for (uint32_t extension_id = 0; extension_id < extension_count; extension_id++) { |
| 1538 | data_size = sizeof(VkExtensionProperties); |
Jon Ashburn | 128f942 | 2015-05-28 19:16:58 -0600 | [diff] [blame] | 1539 | res = icd->GetPhysicalDeviceExtensionInfo(icd->gpus[i], VK_EXTENSION_INFO_TYPE_PROPERTIES, |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 1540 | extension_id, &data_size, &ext_props.info); |
| 1541 | if (data_size == sizeof(VkExtensionProperties) && res == VK_SUCCESS) { |
| 1542 | ext_props.hosted = false; |
| 1543 | ext_props.origin = VK_EXTENSION_ORIGIN_ICD; |
| 1544 | ext_props.lib_name = icd->scanned_icds->lib_name; |
Jon Ashburn | 128f942 | 2015-05-28 19:16:58 -0600 | [diff] [blame] | 1545 | // For ICDs, this is the only option |
| 1546 | strcpy(ext_props.get_extension_info_name, "vkGetPhysicalDeviceExtensionInfo"); |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 1547 | loader_add_to_ext_list(&icd->device_extension_cache[i], 1, &ext_props); |
| 1548 | } |
| 1549 | } |
| 1550 | |
| 1551 | // Traverse layers list adding non-duplicate extensions to the list |
| 1552 | for (uint32_t l = 0; l < loader.scanned_layer_count; l++) { |
Jon Ashburn | 128f942 | 2015-05-28 19:16:58 -0600 | [diff] [blame] | 1553 | get_physical_device_layer_extensions(ptr_instance, icd->gpus[i], l, &icd->device_extension_cache[i]); |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 1554 | } |
| 1555 | } |
| 1556 | } |
| 1557 | |
| 1558 | if (res != VK_SUCCESS) { |
| 1559 | /* clean up any extension lists previously created before this request failed */ |
| 1560 | for (uint32_t j = 0; j < i; j++) { |
| 1561 | loader_destroy_ext_list(&icd->device_extension_cache[i]); |
| 1562 | } |
| 1563 | return res; |
| 1564 | } |
| 1565 | } |
| 1566 | |
| 1567 | count += n; |
| 1568 | } |
| 1569 | |
| 1570 | icd = icd->next; |
| 1571 | } |
| 1572 | |
| 1573 | return VK_SUCCESS; |
| 1574 | } |
| 1575 | |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 1576 | VkResult loader_EnumeratePhysicalDevices( |
Courtney Goeltzenleuchter | 5e41f1d | 2015-04-20 12:48:54 -0600 | [diff] [blame] | 1577 | VkInstance instance, |
| 1578 | uint32_t* pPhysicalDeviceCount, |
| 1579 | VkPhysicalDevice* pPhysicalDevices) |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 1580 | { |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 1581 | uint32_t index = 0; |
Jon Ashburn | 4c392fb | 2015-01-28 19:57:09 -0700 | [diff] [blame] | 1582 | struct loader_instance *ptr_instance = (struct loader_instance *) instance; |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 1583 | struct loader_icd *icd = ptr_instance->icds; |
Jon Ashburn | 4c392fb | 2015-01-28 19:57:09 -0700 | [diff] [blame] | 1584 | |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 1585 | if (ptr_instance->total_gpu_count == 0) { |
| 1586 | loader_init_physical_device_info(ptr_instance); |
Jon Ashburn | 4c392fb | 2015-01-28 19:57:09 -0700 | [diff] [blame] | 1587 | } |
| 1588 | |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 1589 | *pPhysicalDeviceCount = ptr_instance->total_gpu_count; |
| 1590 | if (!pPhysicalDevices) { |
| 1591 | return VK_SUCCESS; |
| 1592 | } |
Jon Ashburn | 4c392fb | 2015-01-28 19:57:09 -0700 | [diff] [blame] | 1593 | |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 1594 | while (icd) { |
| 1595 | assert((index + icd->gpu_count) <= *pPhysicalDeviceCount); |
Jon Ashburn | 128f942 | 2015-05-28 19:16:58 -0600 | [diff] [blame] | 1596 | memcpy(&pPhysicalDevices[index], icd->gpus, icd->gpu_count * sizeof(VkPhysicalDevice)); |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 1597 | index += icd->gpu_count; |
| 1598 | icd = icd->next; |
| 1599 | } |
| 1600 | |
| 1601 | return VK_SUCCESS; |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 1602 | } |
| 1603 | |
Jon Ashburn | 3da71f2 | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 1604 | VkResult loader_GetPhysicalDeviceInfo( |
| 1605 | VkPhysicalDevice gpu, |
| 1606 | VkPhysicalDeviceInfoType infoType, |
| 1607 | size_t* pDataSize, |
| 1608 | void* pData) |
| 1609 | { |
| 1610 | uint32_t gpu_index; |
Jon Ashburn | 128f942 | 2015-05-28 19:16:58 -0600 | [diff] [blame] | 1611 | struct loader_icd *icd = loader_get_icd(gpu, &gpu_index); |
Jon Ashburn | 3da71f2 | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 1612 | VkResult res = VK_ERROR_INITIALIZATION_FAILED; |
| 1613 | |
| 1614 | if (icd->GetPhysicalDeviceInfo) |
| 1615 | res = icd->GetPhysicalDeviceInfo(gpu, infoType, pDataSize, pData); |
| 1616 | |
| 1617 | return res; |
| 1618 | } |
| 1619 | |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 1620 | VkResult loader_CreateDevice( |
| 1621 | VkPhysicalDevice gpu, |
| 1622 | const VkDeviceCreateInfo* pCreateInfo, |
| 1623 | VkDevice* pDevice) |
| 1624 | { |
| 1625 | uint32_t gpu_index; |
Jon Ashburn | 128f942 | 2015-05-28 19:16:58 -0600 | [diff] [blame] | 1626 | struct loader_icd *icd = loader_get_icd(gpu, &gpu_index); |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 1627 | VkResult res = VK_ERROR_INITIALIZATION_FAILED; |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 1628 | |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 1629 | if (icd->CreateDevice) { |
| 1630 | res = icd->CreateDevice(gpu, pCreateInfo, pDevice); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1631 | if (res != VK_SUCCESS) { |
| 1632 | return res; |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 1633 | } |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1634 | |
| 1635 | VkLayerDispatchTable *dev_disp = icd->loader_dispatch + gpu_index; |
| 1636 | loader_init_dispatch(*pDevice, dev_disp); |
| 1637 | |
| 1638 | icd->app_extension_count[gpu_index] = pCreateInfo->extensionCount; |
| 1639 | icd->app_extension_props[gpu_index] = (VkExtensionProperties *) malloc(sizeof(VkExtensionProperties) * pCreateInfo->extensionCount); |
| 1640 | if (icd->app_extension_props[gpu_index] == NULL && (icd->app_extension_count[gpu_index] > 0)) { |
| 1641 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 1642 | } |
| 1643 | |
| 1644 | /* Make local copy of extension list */ |
| 1645 | if (icd->app_extension_count[gpu_index] > 0 && icd->app_extension_props[gpu_index] != NULL) { |
| 1646 | memcpy(icd->app_extension_props[gpu_index], pCreateInfo->pEnabledExtensions, sizeof(VkExtensionProperties) * pCreateInfo->extensionCount); |
| 1647 | } |
| 1648 | |
Courtney Goeltzenleuchter | ee3b16a | 2015-06-01 14:12:42 -0600 | [diff] [blame] | 1649 | /* |
| 1650 | * Put together the complete list of extensions to enable |
| 1651 | * This includes extensions requested via environment variables. |
| 1652 | */ |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1653 | loader_enable_device_layers(icd, gpu_index); |
| 1654 | |
Courtney Goeltzenleuchter | ee3b16a | 2015-06-01 14:12:42 -0600 | [diff] [blame] | 1655 | /* |
| 1656 | * Load the libraries needed by the extensions on the |
| 1657 | * enabled extension list. This will build the |
| 1658 | * device instance chain terminating with the |
| 1659 | * selected device. |
| 1660 | */ |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1661 | loader_activate_device_layers(*pDevice, icd, gpu_index, |
| 1662 | icd->app_extension_count[gpu_index], |
| 1663 | icd->app_extension_props[gpu_index]); |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 1664 | } |
| 1665 | |
| 1666 | return res; |
| 1667 | } |
| 1668 | |
Jon Ashburn | b0fbe91 | 2015-05-06 10:15:07 -0600 | [diff] [blame] | 1669 | LOADER_EXPORT void * VKAPI vkGetInstanceProcAddr(VkInstance instance, const char * pName) |
| 1670 | { |
Jon Ashburn | 07daee7 | 2015-05-21 18:13:33 -0600 | [diff] [blame] | 1671 | if (instance == VK_NULL_HANDLE) |
| 1672 | return NULL; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1673 | |
Jon Ashburn | 07daee7 | 2015-05-21 18:13:33 -0600 | [diff] [blame] | 1674 | void *addr; |
| 1675 | /* get entrypoint addresses that are global (in the loader)*/ |
| 1676 | addr = globalGetProcAddr(pName); |
| 1677 | if (addr) |
| 1678 | return addr; |
Jon Ashburn | b0fbe91 | 2015-05-06 10:15:07 -0600 | [diff] [blame] | 1679 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1680 | struct loader_instance *ptr_instance = (struct loader_instance *) instance; |
| 1681 | |
| 1682 | addr = debug_report_instance_gpa(ptr_instance, pName); |
| 1683 | if (addr) { |
| 1684 | return addr; |
| 1685 | } |
| 1686 | |
Jon Ashburn | 07daee7 | 2015-05-21 18:13:33 -0600 | [diff] [blame] | 1687 | /* return any extension global entrypoints */ |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1688 | addr = wsi_lunarg_GetInstanceProcAddr(instance, pName); |
Jon Ashburn | 07daee7 | 2015-05-21 18:13:33 -0600 | [diff] [blame] | 1689 | if (addr) |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1690 | return (ptr_instance->wsi_lunarg_enabled) ? addr : NULL; |
Jon Ashburn | 07daee7 | 2015-05-21 18:13:33 -0600 | [diff] [blame] | 1691 | |
| 1692 | /* return the instance dispatch table entrypoint for extensions */ |
| 1693 | const VkLayerInstanceDispatchTable *disp_table = * (VkLayerInstanceDispatchTable **) instance; |
| 1694 | if (disp_table == NULL) |
| 1695 | return NULL; |
| 1696 | |
| 1697 | addr = loader_lookup_instance_dispatch_table(disp_table, pName); |
| 1698 | if (addr) |
| 1699 | return addr; |
Jon Ashburn | b0fbe91 | 2015-05-06 10:15:07 -0600 | [diff] [blame] | 1700 | |
| 1701 | return NULL; |
| 1702 | } |
| 1703 | |
Jon Ashburn | 8d1b0b5 | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 1704 | LOADER_EXPORT void * VKAPI vkGetDeviceProcAddr(VkDevice device, const char * pName) |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 1705 | { |
Jon Ashburn | 8d1b0b5 | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 1706 | if (device == VK_NULL_HANDLE) { |
| 1707 | return NULL; |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1708 | } |
Jon Ashburn | 3d526cb | 2015-04-13 18:10:06 -0600 | [diff] [blame] | 1709 | |
Chia-I Wu | f46b81a | 2015-01-04 11:12:47 +0800 | [diff] [blame] | 1710 | void *addr; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 1711 | |
Jon Ashburn | 3d526cb | 2015-04-13 18:10:06 -0600 | [diff] [blame] | 1712 | /* for entrypoints that loader must handle (ie non-dispatchable or create object) |
| 1713 | make sure the loader entrypoint is returned */ |
| 1714 | addr = loader_non_passthrough_gpa(pName); |
Ian Elliott | e19c915 | 2015-04-15 12:53:19 -0600 | [diff] [blame] | 1715 | if (addr) { |
Jon Ashburn | 3d526cb | 2015-04-13 18:10:06 -0600 | [diff] [blame] | 1716 | return addr; |
Ian Elliott | e19c915 | 2015-04-15 12:53:19 -0600 | [diff] [blame] | 1717 | } |
Jon Ashburn | 3d526cb | 2015-04-13 18:10:06 -0600 | [diff] [blame] | 1718 | |
Jon Ashburn | 07daee7 | 2015-05-21 18:13:33 -0600 | [diff] [blame] | 1719 | /* return any extension device entrypoints the loader knows about */ |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1720 | addr = wsi_lunarg_GetDeviceProcAddr(device, pName); |
Jon Ashburn | 07daee7 | 2015-05-21 18:13:33 -0600 | [diff] [blame] | 1721 | if (addr) |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1722 | return addr; |
Jon Ashburn | 07daee7 | 2015-05-21 18:13:33 -0600 | [diff] [blame] | 1723 | |
Jon Ashburn | 3d526cb | 2015-04-13 18:10:06 -0600 | [diff] [blame] | 1724 | /* return the dispatch table entrypoint for the fastest case */ |
Jon Ashburn | 8d1b0b5 | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 1725 | const VkLayerDispatchTable *disp_table = * (VkLayerDispatchTable **) device; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 1726 | if (disp_table == NULL) |
| 1727 | return NULL; |
| 1728 | |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 1729 | addr = loader_lookup_device_dispatch_table(disp_table, pName); |
Chia-I Wu | f46b81a | 2015-01-04 11:12:47 +0800 | [diff] [blame] | 1730 | if (addr) |
| 1731 | return addr; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 1732 | else { |
Jon Ashburn | 8d1b0b5 | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 1733 | if (disp_table->GetDeviceProcAddr == NULL) |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 1734 | return NULL; |
Jon Ashburn | 8d1b0b5 | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 1735 | return disp_table->GetDeviceProcAddr(device, pName); |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 1736 | } |
| 1737 | } |
| 1738 | |
Jon Ashburn | eceb13e | 2015-05-18 15:28:32 -0600 | [diff] [blame] | 1739 | LOADER_EXPORT VkResult VKAPI vkGetGlobalExtensionInfo( |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1740 | VkExtensionInfoType infoType, |
| 1741 | uint32_t extensionIndex, |
| 1742 | size_t* pDataSize, |
| 1743 | void* pData) |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 1744 | { |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1745 | uint32_t *count; |
| 1746 | /* Scan/discover all ICD libraries in a single-threaded manner */ |
| 1747 | loader_platform_thread_once(&once_icd, loader_icd_scan); |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 1748 | |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1749 | /* get layer libraries in a single-threaded manner */ |
| 1750 | loader_platform_thread_once(&once_layer, layer_lib_scan); |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 1751 | |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1752 | /* merge any duplicate extensions */ |
| 1753 | loader_platform_thread_once(&once_exts, loader_coalesce_extensions); |
| 1754 | |
| 1755 | |
| 1756 | if (pDataSize == NULL) |
| 1757 | return VK_ERROR_INVALID_POINTER; |
| 1758 | |
| 1759 | switch (infoType) { |
| 1760 | case VK_EXTENSION_INFO_TYPE_COUNT: |
| 1761 | *pDataSize = sizeof(uint32_t); |
| 1762 | if (pData == NULL) |
| 1763 | return VK_SUCCESS; |
| 1764 | count = (uint32_t *) pData; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1765 | *count = loader.global_extensions.count; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1766 | break; |
| 1767 | case VK_EXTENSION_INFO_TYPE_PROPERTIES: |
| 1768 | *pDataSize = sizeof(VkExtensionProperties); |
| 1769 | if (pData == NULL) |
| 1770 | return VK_SUCCESS; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1771 | if (extensionIndex >= loader.global_extensions.count) |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1772 | return VK_ERROR_INVALID_VALUE; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1773 | memcpy((VkExtensionProperties *) pData, |
| 1774 | &loader.global_extensions.list[extensionIndex], |
| 1775 | sizeof(VkExtensionProperties)); |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1776 | break; |
| 1777 | default: |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1778 | loader_log(VK_DBG_REPORT_WARN_BIT, 0, "Invalid infoType in vkGetGlobalExtensionInfo"); |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1779 | return VK_ERROR_INVALID_VALUE; |
| 1780 | }; |
| 1781 | |
| 1782 | return VK_SUCCESS; |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 1783 | } |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 1784 | |
| 1785 | LOADER_EXPORT VkResult VKAPI vkGetPhysicalDeviceExtensionInfo( |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 1786 | VkPhysicalDevice gpu, |
| 1787 | VkExtensionInfoType infoType, |
| 1788 | uint32_t extensionIndex, |
| 1789 | size_t* pDataSize, |
| 1790 | void* pData) |
| 1791 | { |
| 1792 | uint32_t gpu_index; |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 1793 | uint32_t *count; |
Jon Ashburn | 128f942 | 2015-05-28 19:16:58 -0600 | [diff] [blame] | 1794 | struct loader_icd *icd = loader_get_icd(gpu, &gpu_index); |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 1795 | |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 1796 | if (pDataSize == NULL) |
| 1797 | return VK_ERROR_INVALID_POINTER; |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 1798 | |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 1799 | switch (infoType) { |
| 1800 | case VK_EXTENSION_INFO_TYPE_COUNT: |
| 1801 | *pDataSize = sizeof(uint32_t); |
| 1802 | if (pData == NULL) |
| 1803 | return VK_SUCCESS; |
| 1804 | count = (uint32_t *) pData; |
| 1805 | *count = icd->device_extension_cache[gpu_index].count; |
| 1806 | break; |
| 1807 | case VK_EXTENSION_INFO_TYPE_PROPERTIES: |
| 1808 | *pDataSize = sizeof(VkExtensionProperties); |
| 1809 | if (pData == NULL) |
| 1810 | return VK_SUCCESS; |
| 1811 | if (extensionIndex >= icd->device_extension_cache[gpu_index].count) |
| 1812 | return VK_ERROR_INVALID_VALUE; |
| 1813 | memcpy((VkExtensionProperties *) pData, |
| 1814 | &icd->device_extension_cache[gpu_index].list[extensionIndex], |
| 1815 | sizeof(VkExtensionProperties)); |
| 1816 | break; |
| 1817 | default: |
| 1818 | return VK_ERROR_INVALID_VALUE; |
| 1819 | }; |
| 1820 | |
| 1821 | return VK_SUCCESS; |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 1822 | } |
| 1823 | |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 1824 | VkResult loader_GetMultiDeviceCompatibility( |
| 1825 | VkPhysicalDevice gpu0, |
| 1826 | VkPhysicalDevice gpu1, |
| 1827 | VkPhysicalDeviceCompatibilityInfo* pInfo) |
| 1828 | { |
| 1829 | uint32_t gpu_index; |
Jon Ashburn | 128f942 | 2015-05-28 19:16:58 -0600 | [diff] [blame] | 1830 | struct loader_icd *icd = loader_get_icd(gpu0, &gpu_index); |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 1831 | VkResult res = VK_ERROR_INITIALIZATION_FAILED; |
| 1832 | |
| 1833 | if (icd->GetMultiDeviceCompatibility) |
| 1834 | res = icd->GetMultiDeviceCompatibility(gpu0, gpu1, pInfo); |
| 1835 | |
| 1836 | return res; |
| 1837 | } |