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