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