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