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 |
Tobin Ehlis | b835d1b | 2015-07-03 10:34:49 -0600 | [diff] [blame] | 43 | #include "vk_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" |
Tobin Ehlis | 0c6f9ee | 2015-07-03 09:42:57 -0600 | [diff] [blame] | 49 | #include "vk_icd.h" |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 50 | #include "cJSON.h" |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 51 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 52 | void loader_add_to_ext_list( |
| 53 | struct loader_extension_list *ext_list, |
| 54 | uint32_t prop_list_count, |
| 55 | const struct loader_extension_property *prop_list); |
| 56 | |
Courtney Goeltzenleuchter | ed48830 | 2015-06-01 14:09:34 -0600 | [diff] [blame] | 57 | static loader_platform_dl_handle loader_add_layer_lib( |
| 58 | const char *chain_type, |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 59 | struct loader_layer_properties *layer_prop); |
Courtney Goeltzenleuchter | ed48830 | 2015-06-01 14:09:34 -0600 | [diff] [blame] | 60 | |
| 61 | static void loader_remove_layer_lib( |
| 62 | struct loader_instance *inst, |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 63 | struct loader_layer_properties *layer_prop); |
Courtney Goeltzenleuchter | ed48830 | 2015-06-01 14:09:34 -0600 | [diff] [blame] | 64 | |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 65 | struct loader_struct loader = {0}; |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 66 | |
Courtney Goeltzenleuchter | 9ec39ac | 2015-06-22 17:45:21 -0600 | [diff] [blame] | 67 | static void * VKAPI loader_GetInstanceProcAddr(VkInstance instance, const char * pName); |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 68 | static bool loader_init_ext_list(struct loader_extension_list *ext_info); |
Courtney Goeltzenleuchter | 9ec39ac | 2015-06-22 17:45:21 -0600 | [diff] [blame] | 69 | |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 70 | enum loader_debug { |
| 71 | LOADER_INFO_BIT = VK_BIT(0), |
| 72 | LOADER_WARN_BIT = VK_BIT(1), |
| 73 | LOADER_PERF_BIT = VK_BIT(2), |
| 74 | LOADER_ERROR_BIT = VK_BIT(3), |
| 75 | LOADER_DEBUG_BIT = VK_BIT(4), |
| 76 | }; |
| 77 | |
| 78 | uint32_t g_loader_debug = 0; |
| 79 | uint32_t g_loader_log_msgs = 0; |
| 80 | |
Jon Ashburn | 6301a0f | 2015-05-29 13:15:39 -0600 | [diff] [blame] | 81 | //thread safety lock for accessing global data structures such as "loader" |
| 82 | // all entrypoints on the instance chain need to be locked except GPA |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 83 | // additionally CreateDevice and DestroyDevice needs to be locked |
Jon Ashburn | 6301a0f | 2015-05-29 13:15:39 -0600 | [diff] [blame] | 84 | loader_platform_thread_mutex loader_lock; |
| 85 | |
| 86 | const VkLayerInstanceDispatchTable instance_disp = { |
Courtney Goeltzenleuchter | 9ec39ac | 2015-06-22 17:45:21 -0600 | [diff] [blame] | 87 | .GetInstanceProcAddr = loader_GetInstanceProcAddr, |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 88 | .CreateInstance = loader_CreateInstance, |
| 89 | .DestroyInstance = loader_DestroyInstance, |
| 90 | .EnumeratePhysicalDevices = loader_EnumeratePhysicalDevices, |
Chris Forbes | bc0bb77 | 2015-06-21 22:55:02 +1200 | [diff] [blame] | 91 | .GetPhysicalDeviceFeatures = loader_GetPhysicalDeviceFeatures, |
| 92 | .GetPhysicalDeviceFormatInfo = loader_GetPhysicalDeviceFormatInfo, |
| 93 | .GetPhysicalDeviceLimits = loader_GetPhysicalDeviceLimits, |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 94 | .GetPhysicalDeviceProperties = loader_GetPhysicalDeviceProperties, |
| 95 | .GetPhysicalDevicePerformance = loader_GetPhysicalDevicePerformance, |
| 96 | .GetPhysicalDeviceQueueCount = loader_GetPhysicalDeviceQueueCount, |
| 97 | .GetPhysicalDeviceQueueProperties = loader_GetPhysicalDeviceQueueProperties, |
| 98 | .GetPhysicalDeviceMemoryProperties = loader_GetPhysicalDeviceMemoryProperties, |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 99 | .GetPhysicalDeviceExtensionProperties = loader_GetPhysicalDeviceExtensionProperties, |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 100 | .GetPhysicalDeviceLayerProperties = loader_GetPhysicalDeviceLayerProperties, |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 101 | .DbgCreateMsgCallback = loader_DbgCreateMsgCallback, |
| 102 | .DbgDestroyMsgCallback = loader_DbgDestroyMsgCallback, |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 103 | }; |
| 104 | |
| 105 | LOADER_PLATFORM_THREAD_ONCE_DECLARATION(once_icd); |
| 106 | LOADER_PLATFORM_THREAD_ONCE_DECLARATION(once_layer); |
| 107 | LOADER_PLATFORM_THREAD_ONCE_DECLARATION(once_exts); |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 108 | |
Courtney Goeltzenleuchter | 7f5aafc | 2015-07-05 11:28:29 -0600 | [diff] [blame^] | 109 | void* loader_heap_alloc( |
| 110 | struct loader_instance *instance, |
| 111 | size_t size, |
| 112 | VkSystemAllocType alloc_type) |
| 113 | { |
| 114 | if (instance && instance->alloc_callbacks.pfnAlloc) { |
| 115 | /* TODO: What should default alignment be? 1, 4, 8, other? */ |
| 116 | return instance->alloc_callbacks.pfnAlloc(instance->alloc_callbacks.pUserData, size, 4, alloc_type); |
| 117 | } |
| 118 | return malloc(size); |
| 119 | } |
| 120 | |
| 121 | void* loader_aligned_heap_alloc( |
| 122 | struct loader_instance *instance, |
| 123 | size_t size, |
| 124 | size_t alignment, |
| 125 | VkSystemAllocType alloc_type) |
| 126 | { |
| 127 | if (!instance && instance->alloc_callbacks.pfnAlloc) { |
| 128 | return instance->alloc_callbacks.pfnAlloc(instance->alloc_callbacks.pUserData, size, alignment, alloc_type); |
| 129 | } |
| 130 | return aligned_alloc(size, alignment); |
| 131 | } |
| 132 | |
| 133 | void loader_heap_free( |
| 134 | struct loader_instance *instance, |
| 135 | void *pMem) |
| 136 | { |
| 137 | if (!instance && instance->alloc_callbacks.pfnFree) { |
| 138 | return instance->alloc_callbacks.pfnFree(instance->alloc_callbacks.pUserData, pMem); |
| 139 | } |
| 140 | return free(pMem); |
| 141 | } |
| 142 | |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 143 | static void loader_log(VkFlags msg_type, int32_t msg_code, |
| 144 | const char *format, ...) |
| 145 | { |
| 146 | char msg[256]; |
| 147 | va_list ap; |
| 148 | int ret; |
| 149 | |
| 150 | if (!(msg_type & g_loader_log_msgs)) { |
| 151 | return; |
| 152 | } |
| 153 | |
| 154 | va_start(ap, format); |
| 155 | ret = vsnprintf(msg, sizeof(msg), format, ap); |
| 156 | if ((ret >= (int) sizeof(msg)) || ret < 0) { |
| 157 | msg[sizeof(msg)-1] = '\0'; |
| 158 | } |
| 159 | va_end(ap); |
| 160 | |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 161 | #if defined(WIN32) |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 162 | OutputDebugString(msg); |
| 163 | #endif |
| 164 | fputs(msg, stderr); |
| 165 | fputc('\n', stderr); |
| 166 | } |
| 167 | |
| 168 | #if defined(WIN32) |
| 169 | /** |
| 170 | * Find the list of registry files (names within a key) in key "location". |
| 171 | * |
| 172 | * This function looks in the registry (hive = DEFAULT_VK_REGISTRY_HIVE) key as given in "location" |
| 173 | * for a list or name/values which are added to a returned list (function return value). |
| 174 | * The DWORD values within the key must be 0 or they are skipped. |
| 175 | * Function return is a string with a ';' seperated list of filenames. |
| 176 | * Function return is NULL if no valid name/value pairs are found in the key, |
| 177 | * or the key is not found. |
| 178 | * |
| 179 | * \returns |
| 180 | * A string list of filenames as pointer. |
| 181 | * When done using the returned string list, pointer should be freed. |
| 182 | */ |
| 183 | static char *loader_get_registry_files(const char *location) |
| 184 | { |
| 185 | LONG rtn_value; |
| 186 | HKEY hive, key; |
| 187 | DWORD access_flags = KEY_QUERY_VALUE; |
| 188 | char name[2048]; |
| 189 | char *out = NULL; |
| 190 | |
| 191 | hive = DEFAULT_VK_REGISTRY_HIVE; |
| 192 | rtn_value = RegOpenKeyEx(hive, location, 0, access_flags, &key); |
| 193 | if (rtn_value != ERROR_SUCCESS) { |
| 194 | // We didn't find the key. Try the 32-bit hive (where we've seen the |
| 195 | // key end up on some people's systems): |
| 196 | access_flags |= KEY_WOW64_32KEY; |
| 197 | rtn_value = RegOpenKeyEx(hive, location, 0, access_flags, &key); |
| 198 | if (rtn_value != ERROR_SUCCESS) { |
| 199 | // We still couldn't find the key, so give up: |
| 200 | return NULL; |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | DWORD idx = 0; |
| 205 | DWORD name_size = sizeof(name); |
| 206 | DWORD value; |
| 207 | DWORD total_size = 4096; |
| 208 | DWORD value_size = sizeof(value); |
| 209 | while((rtn_value = RegEnumValue(key, idx++, name, &name_size, NULL, NULL, (LPBYTE) &value, &value_size)) == ERROR_SUCCESS) { |
| 210 | if (value_size == sizeof(value) && value == 0) { |
| 211 | if (out == NULL) { |
| 212 | out = malloc(total_size); |
| 213 | out[0] = '\0'; |
| 214 | } |
| 215 | else if (strlen(out) + name_size + 1 > total_size) { |
| 216 | out = realloc(out, total_size * 2); |
| 217 | total_size *= 2; |
| 218 | } |
| 219 | if (out == NULL) { |
| 220 | loader_log(VK_DBG_REPORT_ERROR_BIT, 0, "Out of memory, failed loader_get_registry_files"); |
| 221 | return NULL; |
| 222 | } |
| 223 | if (strlen(out) == 0) |
| 224 | snprintf(out, name_size + 1, "%s", name); |
| 225 | else |
| 226 | snprintf(out + strlen(out), name_size + 1, "%c%s", PATH_SEPERATOR, name); |
| 227 | } |
| 228 | } |
| 229 | return out; |
| 230 | } |
| 231 | |
Ian Elliott | 5aa4ea2 | 2015-03-31 15:32:41 -0600 | [diff] [blame] | 232 | char *loader_get_registry_string(const HKEY hive, |
| 233 | const LPCTSTR sub_key, |
| 234 | const char *value) |
| 235 | { |
| 236 | DWORD access_flags = KEY_QUERY_VALUE; |
| 237 | DWORD value_type; |
| 238 | HKEY key; |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 239 | LONG rtn_value; |
Ian Elliott | 5aa4ea2 | 2015-03-31 15:32:41 -0600 | [diff] [blame] | 240 | char *rtn_str = NULL; |
Tony Barbour | 18f7155 | 2015-04-22 11:36:22 -0600 | [diff] [blame] | 241 | DWORD rtn_len = 0; |
Ian Elliott | 5aa4ea2 | 2015-03-31 15:32:41 -0600 | [diff] [blame] | 242 | size_t allocated_len = 0; |
| 243 | |
| 244 | rtn_value = RegOpenKeyEx(hive, sub_key, 0, access_flags, &key); |
| 245 | if (rtn_value != ERROR_SUCCESS) { |
| 246 | // We didn't find the key. Try the 32-bit hive (where we've seen the |
| 247 | // key end up on some people's systems): |
| 248 | access_flags |= KEY_WOW64_32KEY; |
| 249 | rtn_value = RegOpenKeyEx(hive, sub_key, 0, access_flags, &key); |
| 250 | if (rtn_value != ERROR_SUCCESS) { |
| 251 | // We still couldn't find the key, so give up: |
| 252 | return NULL; |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | rtn_value = RegQueryValueEx(key, value, NULL, &value_type, |
Ian Elliott | f851ddf | 2015-04-28 15:57:32 -0600 | [diff] [blame] | 257 | (PVOID) rtn_str, (LPDWORD) &rtn_len); |
Ian Elliott | 5aa4ea2 | 2015-03-31 15:32:41 -0600 | [diff] [blame] | 258 | if (rtn_value == ERROR_SUCCESS) { |
| 259 | // If we get to here, we found the key, and need to allocate memory |
| 260 | // large enough for rtn_str, and query again: |
| 261 | allocated_len = rtn_len + 4; |
| 262 | rtn_str = malloc(allocated_len); |
| 263 | rtn_value = RegQueryValueEx(key, value, NULL, &value_type, |
Ian Elliott | f851ddf | 2015-04-28 15:57:32 -0600 | [diff] [blame] | 264 | (PVOID) rtn_str, (LPDWORD) &rtn_len); |
Ian Elliott | 5aa4ea2 | 2015-03-31 15:32:41 -0600 | [diff] [blame] | 265 | if (rtn_value == ERROR_SUCCESS) { |
| 266 | // We added 4 extra bytes to rtn_str, so that we can ensure that |
| 267 | // the string is NULL-terminated (albeit, in a brute-force manner): |
| 268 | rtn_str[allocated_len-1] = '\0'; |
| 269 | } else { |
| 270 | // This should never occur, but in case it does, clean up: |
| 271 | free(rtn_str); |
| 272 | rtn_str = NULL; |
| 273 | } |
| 274 | } // else - shouldn't happen, but if it does, return rtn_str, which is NULL |
| 275 | |
| 276 | // Close the registry key that was opened: |
| 277 | RegCloseKey(key); |
| 278 | |
| 279 | return rtn_str; |
| 280 | } |
| 281 | |
| 282 | |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 283 | // For ICD developers, look in the registry, and look for an environment |
| 284 | // variable for a path(s) where to find the ICD(s): |
| 285 | static char *loader_get_registry_and_env(const char *env_var, |
| 286 | const char *registry_value) |
| 287 | { |
| 288 | char *env_str = getenv(env_var); |
| 289 | size_t env_len = (env_str == NULL) ? 0 : strlen(env_str); |
Ian Elliott | 5aa4ea2 | 2015-03-31 15:32:41 -0600 | [diff] [blame] | 290 | char *registry_str = NULL; |
Tony Barbour | 18f7155 | 2015-04-22 11:36:22 -0600 | [diff] [blame] | 291 | size_t registry_len = 0; |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 292 | char *rtn_str = NULL; |
| 293 | size_t rtn_len; |
| 294 | |
Ian Elliott | 5aa4ea2 | 2015-03-31 15:32:41 -0600 | [diff] [blame] | 295 | registry_str = loader_get_registry_string(HKEY_LOCAL_MACHINE, |
Ian Elliott | 06ebd75 | 2015-04-09 18:07:15 -0600 | [diff] [blame] | 296 | "Software\\Vulkan", |
Ian Elliott | 5aa4ea2 | 2015-03-31 15:32:41 -0600 | [diff] [blame] | 297 | registry_value); |
Ian Elliott | f851ddf | 2015-04-28 15:57:32 -0600 | [diff] [blame] | 298 | registry_len = (registry_str) ? (DWORD) strlen(registry_str) : 0; |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 299 | |
| 300 | rtn_len = env_len + registry_len + 1; |
| 301 | if (rtn_len <= 2) { |
| 302 | // We found neither the desired registry value, nor the environment |
| 303 | // variable; return NULL: |
| 304 | return NULL; |
| 305 | } else { |
| 306 | // We found something, and so we need to allocate memory for the string |
| 307 | // to return: |
| 308 | rtn_str = malloc(rtn_len); |
| 309 | } |
| 310 | |
Ian Elliott | 5aa4ea2 | 2015-03-31 15:32:41 -0600 | [diff] [blame] | 311 | if (registry_len == 0) { |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 312 | // We didn't find the desired registry value, and so we must have found |
| 313 | // only the environment variable: |
| 314 | _snprintf(rtn_str, rtn_len, "%s", env_str); |
| 315 | } else if (env_str != NULL) { |
| 316 | // We found both the desired registry value and the environment |
| 317 | // variable, so concatenate them both: |
| 318 | _snprintf(rtn_str, rtn_len, "%s;%s", registry_str, env_str); |
| 319 | } else { |
| 320 | // We must have only found the desired registry value: |
| 321 | _snprintf(rtn_str, rtn_len, "%s", registry_str); |
| 322 | } |
| 323 | |
Ian Elliott | 2de26bc | 2015-04-03 13:13:01 -0600 | [diff] [blame] | 324 | if (registry_str) { |
| 325 | free(registry_str); |
| 326 | } |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 327 | |
| 328 | return(rtn_str); |
| 329 | } |
| 330 | #endif // WIN32 |
| 331 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 332 | bool compare_vk_extension_properties(const VkExtensionProperties *op1, const VkExtensionProperties *op2) |
| 333 | { |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 334 | return strcmp(op1->extName, op2->extName) == 0 ? true : false; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | /* |
Jon Ashburn | bd6c488 | 2015-07-02 12:59:25 -0600 | [diff] [blame] | 338 | * Search the given ext_array for an extension |
| 339 | * matching the given vk_ext_prop |
| 340 | */ |
| 341 | bool has_vk_extension_property_array( |
| 342 | const VkExtensionProperties *vk_ext_prop, |
| 343 | const uint32_t count, |
| 344 | const VkExtensionProperties *ext_array) |
| 345 | { |
| 346 | for (uint32_t i = 0; i < count; i++) { |
| 347 | if (compare_vk_extension_properties(vk_ext_prop, &ext_array[i])) |
| 348 | return true; |
| 349 | } |
| 350 | return false; |
| 351 | } |
| 352 | |
| 353 | /* |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 354 | * Search the given ext_list for an extension |
| 355 | * matching the given vk_ext_prop |
| 356 | */ |
| 357 | bool has_vk_extension_property( |
| 358 | const VkExtensionProperties *vk_ext_prop, |
| 359 | const struct loader_extension_list *ext_list) |
| 360 | { |
| 361 | for (uint32_t i = 0; i < ext_list->count; i++) { |
| 362 | if (compare_vk_extension_properties(&ext_list->list[i].info, vk_ext_prop)) |
| 363 | return true; |
| 364 | } |
| 365 | return false; |
| 366 | } |
| 367 | |
| 368 | /* |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 369 | * Search the given layer list for a layer |
| 370 | * matching the given layer name |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 371 | */ |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 372 | static struct loader_layer_properties *get_layer_property( |
| 373 | const char *name, |
| 374 | const struct loader_layer_list *layer_list) |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 375 | { |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 376 | for (uint32_t i = 0; i < layer_list->count; i++) { |
| 377 | const VkLayerProperties *item = &layer_list->list[i].info; |
| 378 | if (strcmp(name, item->layerName) == 0) |
| 379 | return &layer_list->list[i]; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 380 | } |
| 381 | return NULL; |
| 382 | } |
| 383 | |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 384 | static void loader_add_global_extensions( |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 385 | const PFN_vkGetGlobalExtensionProperties fp_get_props, |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 386 | const char *lib_name, |
Jon Ashburn | 953bb3c | 2015-06-10 16:11:42 -0600 | [diff] [blame] | 387 | const loader_platform_dl_handle lib_handle, |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 388 | const enum extension_origin origin, |
| 389 | struct loader_extension_list *ext_list) |
| 390 | { |
| 391 | uint32_t i, count; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 392 | struct loader_extension_property ext_props; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 393 | VkExtensionProperties *extension_properties; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 394 | VkResult res; |
| 395 | |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 396 | res = fp_get_props(NULL, &count, NULL); |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 397 | if (res != VK_SUCCESS) { |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 398 | loader_log(VK_DBG_REPORT_WARN_BIT, 0, "Error getting global extension count from %s", lib_name); |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 399 | return; |
| 400 | } |
Jon Ashburn | 953bb3c | 2015-06-10 16:11:42 -0600 | [diff] [blame] | 401 | |
Courtney Goeltzenleuchter | 7f5aafc | 2015-07-05 11:28:29 -0600 | [diff] [blame^] | 402 | extension_properties = loader_stack_alloc(count * sizeof(VkExtensionProperties)); |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 403 | |
| 404 | res = fp_get_props(NULL, &count, extension_properties); |
| 405 | if (res != VK_SUCCESS) { |
| 406 | loader_log(VK_DBG_REPORT_WARN_BIT, 0, "Error getting global extensions from %s", lib_name); |
| 407 | return; |
| 408 | } |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 409 | |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 410 | for (i = 0; i < count; i++) { |
Courtney Goeltzenleuchter | 0f1d8eb | 2015-06-07 17:28:17 -0600 | [diff] [blame] | 411 | memset(&ext_props, 0, sizeof(ext_props)); |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 412 | memcpy(&ext_props.info, &extension_properties[i], sizeof(VkExtensionProperties)); |
| 413 | //TODO eventually get this from the layer config file |
| 414 | ext_props.origin = origin; |
| 415 | ext_props.lib_name = lib_name; |
Jon Ashburn | 953bb3c | 2015-06-10 16:11:42 -0600 | [diff] [blame] | 416 | |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 417 | char spec_version[64], version[64]; |
| 418 | |
| 419 | snprintf(spec_version, sizeof(spec_version), "%d.%d.%d", |
| 420 | VK_MAJOR(ext_props.info.specVersion), |
| 421 | VK_MINOR(ext_props.info.specVersion), |
| 422 | VK_PATCH(ext_props.info.specVersion)); |
| 423 | snprintf(version, sizeof(version), "%d.%d.%d", |
| 424 | VK_MAJOR(ext_props.info.version), |
| 425 | VK_MINOR(ext_props.info.version), |
| 426 | VK_PATCH(ext_props.info.version)); |
| 427 | |
| 428 | loader_log(VK_DBG_REPORT_DEBUG_BIT, 0, |
| 429 | "Global Extension: %s (%s) version %s, Vulkan version %s", |
| 430 | ext_props.info.extName, lib_name, version, spec_version); |
| 431 | loader_add_to_ext_list(ext_list, 1, &ext_props); |
| 432 | } |
| 433 | |
| 434 | return; |
| 435 | } |
| 436 | |
Courtney Goeltzenleuchter | 7f5aafc | 2015-07-05 11:28:29 -0600 | [diff] [blame^] | 437 | /* TODO: Need to use loader_heap_alloc or loader_stack_alloc */ |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 438 | static void loader_add_global_layer_properties( |
| 439 | const char *lib_name, |
| 440 | const loader_platform_dl_handle lib_handle, |
| 441 | struct loader_layer_list *layer_list) |
| 442 | { |
| 443 | uint32_t i, count; |
| 444 | VkLayerProperties *layer_properties; |
| 445 | PFN_vkGetGlobalExtensionProperties fp_get_ext_props; |
| 446 | PFN_vkGetGlobalLayerProperties fp_get_layer_props; |
| 447 | VkResult res; |
| 448 | |
| 449 | fp_get_ext_props = loader_platform_get_proc_address(lib_handle, "vkGetGlobalExtensionProperties"); |
| 450 | if (!fp_get_ext_props) { |
| 451 | loader_log(VK_DBG_REPORT_WARN_BIT, 0, |
| 452 | "Couldn't dlsym vkGetGlobalExtensionProperties from library %s", |
| 453 | lib_name); |
| 454 | return; |
| 455 | } |
| 456 | |
| 457 | fp_get_layer_props = loader_platform_get_proc_address(lib_handle, "vkGetGlobalLayerProperties"); |
| 458 | if (!fp_get_layer_props) { |
| 459 | loader_log(VK_DBG_REPORT_WARN_BIT, 0, |
| 460 | "Couldn't dlsym vkGetGlobalLayerProperties from library %s", |
| 461 | lib_name); |
| 462 | return; |
| 463 | } |
| 464 | |
| 465 | res = fp_get_layer_props(&count, NULL); |
| 466 | if (res != VK_SUCCESS) { |
| 467 | loader_log(VK_DBG_REPORT_WARN_BIT, 0, "Error getting global layer count from %s", lib_name); |
| 468 | return; |
| 469 | } |
| 470 | |
| 471 | if (count == 0) { |
| 472 | return; |
| 473 | } |
| 474 | |
Courtney Goeltzenleuchter | 7f5aafc | 2015-07-05 11:28:29 -0600 | [diff] [blame^] | 475 | layer_properties = loader_stack_alloc(count * sizeof(VkLayerProperties)); |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 476 | |
| 477 | res = fp_get_layer_props(&count, layer_properties); |
| 478 | if (res != VK_SUCCESS) { |
| 479 | loader_log(VK_DBG_REPORT_WARN_BIT, 0, "Error getting %d global layer properties from %s", |
| 480 | count, lib_name); |
| 481 | return; |
| 482 | } |
| 483 | |
| 484 | for (i = 0; i < count; i++) { |
| 485 | struct loader_layer_properties *layer = &layer_list->list[layer_list->count]; |
| 486 | layer->lib_info.lib_name = malloc(strlen(lib_name) + 1); |
| 487 | if (layer->lib_info.lib_name == NULL) { |
| 488 | loader_log(VK_DBG_REPORT_ERROR_BIT, 0, "layer library %s ignored: out of memory", lib_name); |
| 489 | return; |
| 490 | } |
| 491 | |
| 492 | strcpy(layer->lib_info.lib_name, lib_name); |
| 493 | memcpy(&layer->info, &layer_properties[i], sizeof(VkLayerProperties)); |
| 494 | loader_init_ext_list(&layer->instance_extension_list); |
| 495 | loader_init_ext_list(&layer->device_extension_list); |
| 496 | loader_log(VK_DBG_REPORT_DEBUG_BIT, 0, "Collecting global extensions for layer %s (%s)", |
| 497 | layer->info.layerName, layer->info.description); |
| 498 | |
| 499 | loader_add_to_layer_list(layer_list, 1, layer); |
| 500 | |
| 501 | loader_add_global_extensions( |
| 502 | fp_get_ext_props, |
| 503 | lib_name, |
| 504 | lib_handle, |
| 505 | VK_EXTENSION_ORIGIN_LAYER, |
| 506 | &layer->instance_extension_list); |
| 507 | } |
| 508 | |
| 509 | return; |
| 510 | } |
| 511 | |
| 512 | static void loader_add_physical_device_extensions( |
| 513 | PFN_vkGetPhysicalDeviceExtensionProperties get_phys_dev_ext_props, |
| 514 | VkPhysicalDevice physical_device, |
| 515 | const enum extension_origin origin, |
| 516 | const char *lib_name, |
| 517 | struct loader_extension_list *ext_list) |
| 518 | { |
| 519 | uint32_t i, count; |
| 520 | VkResult res; |
| 521 | struct loader_extension_property ext_props; |
| 522 | VkExtensionProperties *extension_properties; |
| 523 | |
| 524 | memset(&ext_props, 0, sizeof(ext_props)); |
| 525 | ext_props.origin = origin; |
| 526 | ext_props.lib_name = lib_name; |
| 527 | |
| 528 | if (get_phys_dev_ext_props) { |
| 529 | res = get_phys_dev_ext_props(physical_device, NULL, &count, NULL); |
| 530 | if (res == VK_SUCCESS && count > 0) { |
Courtney Goeltzenleuchter | 7f5aafc | 2015-07-05 11:28:29 -0600 | [diff] [blame^] | 531 | |
| 532 | extension_properties = loader_stack_alloc(count * sizeof(VkExtensionProperties)); |
| 533 | |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 534 | res = get_phys_dev_ext_props(physical_device, NULL, &count, extension_properties); |
| 535 | for (i = 0; i < count; i++) { |
| 536 | char spec_version[64], version[64]; |
| 537 | |
| 538 | memcpy(&ext_props.info, &extension_properties[i], sizeof(VkExtensionProperties)); |
| 539 | |
| 540 | snprintf(spec_version, sizeof(spec_version), "%d.%d.%d", |
| 541 | VK_MAJOR(ext_props.info.specVersion), |
| 542 | VK_MINOR(ext_props.info.specVersion), |
| 543 | VK_PATCH(ext_props.info.specVersion)); |
| 544 | snprintf(version, sizeof(version), "%d.%d.%d", |
| 545 | VK_MAJOR(ext_props.info.version), |
| 546 | VK_MINOR(ext_props.info.version), |
| 547 | VK_PATCH(ext_props.info.version)); |
| 548 | |
| 549 | loader_log(VK_DBG_REPORT_DEBUG_BIT, 0, |
| 550 | "PhysicalDevice Extension: %s (%s) version %s, Vulkan version %s", |
| 551 | ext_props.info.extName, lib_name, version, spec_version); |
| 552 | loader_add_to_ext_list(ext_list, 1, &ext_props); |
Jon Ashburn | 953bb3c | 2015-06-10 16:11:42 -0600 | [diff] [blame] | 553 | } |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 554 | } else { |
| 555 | loader_log(VK_DBG_REPORT_ERROR_BIT, 0, "Error getting physical device extension info count from Layer %s", ext_props.lib_name); |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 556 | } |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 557 | } |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 558 | |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 559 | return; |
| 560 | } |
| 561 | |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 562 | static void loader_add_physical_device_layer_properties( |
| 563 | struct loader_icd *icd, |
| 564 | char *lib_name, |
| 565 | const loader_platform_dl_handle lib_handle) |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 566 | { |
| 567 | uint32_t i, count; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 568 | VkLayerProperties *layer_properties; |
| 569 | PFN_vkGetPhysicalDeviceExtensionProperties fp_get_ext_props; |
| 570 | PFN_vkGetPhysicalDeviceLayerProperties fp_get_layer_props; |
| 571 | VkPhysicalDevice gpu = icd->gpus[0]; |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 572 | VkResult res; |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 573 | |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 574 | fp_get_ext_props = loader_platform_get_proc_address(lib_handle, "vkGetPhysicalDeviceExtensionProperties"); |
| 575 | if (!fp_get_ext_props) { |
| 576 | loader_log(VK_DBG_REPORT_INFO_BIT, 0, |
| 577 | "Couldn't dlsym vkGetPhysicalDeviceExtensionProperties from library %s", |
| 578 | lib_name); |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 579 | return; |
| 580 | } |
| 581 | |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 582 | fp_get_layer_props = loader_platform_get_proc_address(lib_handle, "vkGetPhysicalDeviceLayerProperties"); |
| 583 | if (!fp_get_layer_props) { |
| 584 | loader_log(VK_DBG_REPORT_INFO_BIT, 0, |
| 585 | "Couldn't dlsym vkGetPhysicalDeviceLayerProperties from library %s", |
| 586 | lib_name); |
| 587 | return; |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 588 | } |
| 589 | |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 590 | /* |
| 591 | * NOTE: We assume that all GPUs of an ICD support the same PhysicalDevice |
| 592 | * layers and extensions. Thus only ask for info about the first gpu. |
| 593 | */ |
| 594 | res = fp_get_layer_props(gpu, &count, NULL); |
| 595 | if (res != VK_SUCCESS) { |
| 596 | loader_log(VK_DBG_REPORT_ERROR_BIT, 0, "Error getting PhysicalDevice layer count from %s", lib_name); |
| 597 | return; |
| 598 | } |
| 599 | |
| 600 | if (count == 0) { |
| 601 | return; |
| 602 | } |
| 603 | |
Courtney Goeltzenleuchter | 7f5aafc | 2015-07-05 11:28:29 -0600 | [diff] [blame^] | 604 | layer_properties = loader_stack_alloc(count * sizeof(VkLayerProperties)); |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 605 | |
| 606 | res = fp_get_layer_props(gpu, &count, layer_properties); |
| 607 | if (res != VK_SUCCESS) { |
| 608 | loader_log(VK_DBG_REPORT_ERROR_BIT, 0, "Error getting %d PhysicalDevice layer properties from %s", |
| 609 | count, lib_name); |
| 610 | return; |
| 611 | } |
| 612 | |
| 613 | for (i = 0; i < count; i++) { |
| 614 | struct loader_layer_properties layer; |
| 615 | memset(&layer, 0, sizeof(struct loader_layer_properties)); |
| 616 | layer.lib_info.lib_name = lib_name; |
| 617 | memcpy(&layer.info, &layer_properties[i], sizeof(VkLayerProperties)); |
| 618 | loader_init_ext_list(&layer.instance_extension_list); |
| 619 | loader_init_ext_list(&layer.device_extension_list); |
| 620 | loader_log(VK_DBG_REPORT_DEBUG_BIT, 0, "Collecting PhysicalDevice extensions for layer %s (%s)", |
| 621 | layer.info.layerName, layer.info.description); |
| 622 | loader_add_to_layer_list(&icd->layer_properties_cache, 1, &layer); |
| 623 | loader_add_physical_device_extensions( |
| 624 | fp_get_ext_props, |
| 625 | icd->gpus[i], |
| 626 | VK_EXTENSION_ORIGIN_LAYER, |
| 627 | lib_name, |
| 628 | &layer.device_extension_list); |
| 629 | } |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 630 | return; |
| 631 | } |
| 632 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 633 | static bool loader_init_ext_list(struct loader_extension_list *ext_info) |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 634 | { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 635 | ext_info->capacity = 32 * sizeof(struct loader_extension_property); |
Courtney Goeltzenleuchter | 7f5aafc | 2015-07-05 11:28:29 -0600 | [diff] [blame^] | 636 | /* TODO: Need to use loader_stack_alloc or loader_heap_alloc */ |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 637 | ext_info->list = malloc(ext_info->capacity); |
| 638 | if (ext_info->list == NULL) { |
| 639 | return false; |
| 640 | } |
| 641 | memset(ext_info->list, 0, ext_info->capacity); |
| 642 | ext_info->count = 0; |
| 643 | return true; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 644 | } |
| 645 | |
Courtney Goeltzenleuchter | 7d0023c | 2015-06-08 15:09:22 -0600 | [diff] [blame] | 646 | void loader_destroy_ext_list(struct loader_extension_list *ext_info) |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 647 | { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 648 | free(ext_info->list); |
| 649 | ext_info->count = 0; |
| 650 | ext_info->capacity = 0; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 651 | } |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 652 | |
Jon Ashburn | bd6c488 | 2015-07-02 12:59:25 -0600 | [diff] [blame] | 653 | /** |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 654 | * Search the given search_list for any layers in the props list. |
| 655 | * Add these to the output layer_list. Don't add duplicates to the output layer_list. |
Jon Ashburn | bd6c488 | 2015-07-02 12:59:25 -0600 | [diff] [blame] | 656 | */ |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 657 | static void loader_add_layer_names_to_list( |
| 658 | struct loader_layer_list *output_list, |
| 659 | uint32_t name_count, |
| 660 | const char * const *names, |
| 661 | const struct loader_layer_list *search_list) |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 662 | { |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 663 | struct loader_layer_properties *layer_prop; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 664 | |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 665 | for (uint32_t i = 0; i < name_count; i++) { |
| 666 | const char *search_target = names[i]; |
| 667 | layer_prop = get_layer_property(search_target, search_list); |
| 668 | if (!layer_prop) { |
| 669 | loader_log(VK_DBG_REPORT_WARN_BIT, 0, "Unable to find extension %s", search_target); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 670 | continue; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 671 | } |
| 672 | |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 673 | loader_add_to_layer_list(output_list, 1, layer_prop); |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 674 | } |
| 675 | } |
| 676 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 677 | /* |
| 678 | * Append non-duplicate extension properties defined in prop_list |
| 679 | * to the given ext_info list |
| 680 | */ |
| 681 | void loader_add_to_ext_list( |
| 682 | struct loader_extension_list *ext_list, |
| 683 | uint32_t prop_list_count, |
| 684 | const struct loader_extension_property *props) |
| 685 | { |
| 686 | uint32_t i; |
| 687 | struct loader_extension_property *cur_ext; |
| 688 | |
| 689 | if (ext_list->list == NULL || ext_list->capacity == 0) { |
| 690 | loader_init_ext_list(ext_list); |
| 691 | } |
| 692 | |
| 693 | if (ext_list->list == NULL) |
| 694 | return; |
| 695 | |
| 696 | for (i = 0; i < prop_list_count; i++) { |
| 697 | cur_ext = (struct loader_extension_property *) &props[i]; |
| 698 | |
| 699 | // look for duplicates |
| 700 | if (has_vk_extension_property(&cur_ext->info, ext_list)) { |
| 701 | continue; |
| 702 | } |
| 703 | |
| 704 | // add to list at end |
| 705 | // check for enough capacity |
| 706 | if (ext_list->count * sizeof(struct loader_extension_property) |
| 707 | >= ext_list->capacity) { |
| 708 | // double capacity |
| 709 | ext_list->capacity *= 2; |
Courtney Goeltzenleuchter | 7f5aafc | 2015-07-05 11:28:29 -0600 | [diff] [blame^] | 710 | /* TODO: Need to use loader_stack_alloc or loader_heap_alloc */ |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 711 | ext_list->list = realloc(ext_list->list, ext_list->capacity); |
| 712 | } |
Courtney Goeltzenleuchter | 0f1d8eb | 2015-06-07 17:28:17 -0600 | [diff] [blame] | 713 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 714 | memcpy(&ext_list->list[ext_list->count], cur_ext, sizeof(struct loader_extension_property)); |
| 715 | ext_list->count++; |
| 716 | } |
| 717 | } |
| 718 | |
Courtney Goeltzenleuchter | 7f5aafc | 2015-07-05 11:28:29 -0600 | [diff] [blame^] | 719 | /* |
| 720 | * Manage lists of VkLayerProperties |
| 721 | */ |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 722 | static bool loader_init_layer_list(struct loader_layer_list *list) |
| 723 | { |
| 724 | list->capacity = 32 * sizeof(struct loader_layer_properties); |
Courtney Goeltzenleuchter | 7f5aafc | 2015-07-05 11:28:29 -0600 | [diff] [blame^] | 725 | /* TODO: Need to use loader_stack_alloc or loader_heap_alloc */ |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 726 | list->list = malloc(list->capacity); |
| 727 | if (list->list == NULL) { |
| 728 | return false; |
| 729 | } |
| 730 | memset(list->list, 0, list->capacity); |
| 731 | list->count = 0; |
| 732 | return true; |
| 733 | } |
| 734 | |
| 735 | void loader_destroy_layer_list(struct loader_layer_list *layer_list) |
| 736 | { |
| 737 | free(layer_list->list); |
| 738 | layer_list->count = 0; |
| 739 | layer_list->capacity = 0; |
| 740 | } |
| 741 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 742 | /* |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 743 | * Search the given layer list for a list |
| 744 | * matching the given VkLayerProperties |
| 745 | */ |
| 746 | bool has_vk_layer_property( |
| 747 | const VkLayerProperties *vk_layer_prop, |
| 748 | const struct loader_layer_list *list) |
| 749 | { |
| 750 | for (uint32_t i = 0; i < list->count; i++) { |
| 751 | if (strcmp(vk_layer_prop->layerName, list->list[i].info.layerName) == 0) |
| 752 | return true; |
| 753 | } |
| 754 | return false; |
| 755 | } |
| 756 | |
| 757 | /* |
| 758 | * Search the given layer list for a layer |
| 759 | * matching the given name |
| 760 | */ |
| 761 | bool has_layer_name( |
| 762 | const char *name, |
| 763 | const struct loader_layer_list *list) |
| 764 | { |
| 765 | for (uint32_t i = 0; i < list->count; i++) { |
| 766 | if (strcmp(name, list->list[i].info.layerName) == 0) |
| 767 | return true; |
| 768 | } |
| 769 | return false; |
| 770 | } |
| 771 | |
| 772 | /* |
| 773 | * Append non-duplicate layer properties defined in prop_list |
| 774 | * to the given layer_info list |
| 775 | */ |
| 776 | void loader_add_to_layer_list( |
| 777 | struct loader_layer_list *list, |
| 778 | uint32_t prop_list_count, |
| 779 | const struct loader_layer_properties *props) |
| 780 | { |
| 781 | uint32_t i; |
| 782 | struct loader_layer_properties *layer; |
| 783 | |
| 784 | if (list->list == NULL || list->capacity == 0) { |
| 785 | loader_init_layer_list(list); |
| 786 | } |
| 787 | |
| 788 | if (list->list == NULL) |
| 789 | return; |
| 790 | |
| 791 | for (i = 0; i < prop_list_count; i++) { |
| 792 | layer = (struct loader_layer_properties *) &props[i]; |
| 793 | |
| 794 | // look for duplicates |
| 795 | if (has_vk_layer_property(&layer->info, list)) { |
| 796 | continue; |
| 797 | } |
| 798 | |
| 799 | // add to list at end |
| 800 | // check for enough capacity |
| 801 | if (list->count * sizeof(struct loader_layer_properties) |
| 802 | >= list->capacity) { |
| 803 | // double capacity |
| 804 | list->capacity *= 2; |
| 805 | list->list = realloc(list->list, list->capacity); |
| 806 | } |
| 807 | |
| 808 | memcpy(&list->list[list->count], layer, sizeof(struct loader_layer_properties)); |
| 809 | list->count++; |
| 810 | } |
| 811 | } |
| 812 | |
| 813 | /* |
| 814 | * Search the search_list for any layer with |
| 815 | * a name that matches the given layer_name. |
| 816 | * Add all matching layers to the found_list |
| 817 | * Do not add if found VkLayerProperties is already |
| 818 | * on the found_list. |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 819 | */ |
Jon Ashburn | bd6c488 | 2015-07-02 12:59:25 -0600 | [diff] [blame] | 820 | static void loader_find_layer_name_add_list( |
| 821 | const char *name, |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 822 | const struct loader_layer_list *search_list, |
| 823 | struct loader_layer_list *found_list) |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 824 | { |
| 825 | for (uint32_t i = 0; i < search_list->count; i++) { |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 826 | struct loader_layer_properties *layer_prop = &search_list->list[i]; |
| 827 | if (0 == strcmp(layer_prop->info.layerName, name)) { |
| 828 | /* Found a layer with the same name, add to found_list */ |
| 829 | loader_add_to_layer_list(found_list, 1, layer_prop); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 830 | } |
| 831 | } |
| 832 | } |
| 833 | |
| 834 | bool loader_is_extension_scanned(const VkExtensionProperties *ext_prop) |
Jon Ashburn | fc2e38c | 2015-04-14 09:15:32 -0600 | [diff] [blame] | 835 | { |
| 836 | uint32_t i; |
| 837 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 838 | for (i = 0; i < loader.global_extensions.count; i++) { |
| 839 | 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] | 840 | return true; |
| 841 | } |
| 842 | return false; |
| 843 | } |
| 844 | |
Jon Ashburn | bd6c488 | 2015-07-02 12:59:25 -0600 | [diff] [blame] | 845 | /* |
| 846 | * For global exenstions implemented within the loader (i.e. DEBUG_REPORT |
| 847 | * the extension must provide two entry points for the loader to use: |
| 848 | * - "trampoline" entry point - this is the address returned by GetProcAddr |
| 849 | * and will always do what's necessary to support a global call. |
| 850 | * - "terminator" function - this function will be put at the end of the |
| 851 | * instance chain and will contain the necessary logica to call / process |
| 852 | * the extension for the appropriate ICDs that are available. |
| 853 | * There is no generic mechanism for including these functions, the references |
| 854 | * must be placed into the appropriate loader entry points. |
| 855 | * GetInstanceProcAddr: call extension GetInstanceProcAddr to check for GetProcAddr requests |
| 856 | * loader_coalesce_extensions(void) - add extension records to the list of global |
| 857 | * extension available to the app. |
| 858 | * instance_disp - add function pointer for terminator function to this array. |
| 859 | * The extension itself should be in a separate file that will be |
| 860 | * linked directly with the loader. |
| 861 | */ |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 862 | void loader_coalesce_extensions(void) |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 863 | { |
| 864 | uint32_t i; |
| 865 | struct loader_scanned_icds *icd_list = loader.scanned_icd_list; |
| 866 | |
| 867 | // traverse scanned icd list adding non-duplicate extensions to the list |
| 868 | while (icd_list != NULL) { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 869 | loader_add_to_ext_list(&loader.global_extensions, |
| 870 | icd_list->global_extension_list.count, |
| 871 | icd_list->global_extension_list.list); |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 872 | icd_list = icd_list->next; |
| 873 | }; |
| 874 | |
| 875 | //Traverse layers list adding non-duplicate extensions to the list |
Jon Ashburn | 5ef2060 | 2015-07-02 09:40:15 -0600 | [diff] [blame] | 876 | for (i = 0; i < loader.scanned_layers.count; i++) { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 877 | loader_add_to_ext_list(&loader.global_extensions, |
Jon Ashburn | 5ef2060 | 2015-07-02 09:40:15 -0600 | [diff] [blame] | 878 | loader.scanned_layers.list[i].instance_extension_list.count, |
| 879 | loader.scanned_layers.list[i].instance_extension_list.list); |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 880 | } |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 881 | |
| 882 | // Traverse loader's extensions, adding non-duplicate extensions to the list |
| 883 | debug_report_add_instance_extensions(&loader.global_extensions); |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 884 | } |
| 885 | |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 886 | static struct loader_icd *loader_get_icd_and_device(const VkDevice device, |
| 887 | struct loader_device **found_dev) |
| 888 | { |
| 889 | *found_dev = NULL; |
| 890 | for (struct loader_instance *inst = loader.instances; inst; inst = inst->next) { |
| 891 | for (struct loader_icd *icd = inst->icds; icd; icd = icd->next) { |
| 892 | for (struct loader_device *dev = icd->logical_device_list; dev; dev = dev->next) |
| 893 | if (dev->device == device) { |
| 894 | *found_dev = dev; |
| 895 | return icd; |
| 896 | } |
| 897 | } |
| 898 | } |
| 899 | return NULL; |
| 900 | } |
| 901 | |
| 902 | static void loader_destroy_logical_device(struct loader_device *dev) |
| 903 | { |
| 904 | free(dev->app_extension_props); |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 905 | if (dev->activated_layer_list.count) |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 906 | loader_destroy_layer_list(&dev->activated_layer_list); |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 907 | free(dev); |
| 908 | } |
| 909 | |
| 910 | static struct loader_device *loader_add_logical_device(const VkDevice dev, struct loader_device **device_list) |
| 911 | { |
| 912 | struct loader_device *new_dev; |
| 913 | |
| 914 | new_dev = malloc(sizeof(struct loader_device)); |
| 915 | if (!new_dev) { |
| 916 | loader_log(VK_DBG_REPORT_ERROR_BIT, 0, "Failed to malloc struct laoder-device"); |
| 917 | return NULL; |
| 918 | } |
| 919 | |
| 920 | memset(new_dev, 0, sizeof(struct loader_device)); |
| 921 | |
| 922 | new_dev->next = *device_list; |
| 923 | new_dev->device = dev; |
| 924 | *device_list = new_dev; |
| 925 | return new_dev; |
| 926 | } |
| 927 | |
| 928 | void loader_remove_logical_device(VkDevice device) |
| 929 | { |
| 930 | struct loader_device *found_dev, *dev, *prev_dev; |
| 931 | struct loader_icd *icd; |
| 932 | icd = loader_get_icd_and_device(device, &found_dev); |
| 933 | |
| 934 | if (!icd || !found_dev) |
| 935 | return; |
| 936 | |
| 937 | prev_dev = NULL; |
| 938 | dev = icd->logical_device_list; |
| 939 | while (dev && dev != found_dev) { |
| 940 | prev_dev = dev; |
| 941 | dev = dev->next; |
| 942 | } |
| 943 | |
| 944 | if (prev_dev) |
| 945 | prev_dev->next = found_dev->next; |
| 946 | else |
| 947 | icd->logical_device_list = found_dev->next; |
| 948 | loader_destroy_logical_device(found_dev); |
| 949 | } |
| 950 | |
| 951 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 952 | static void loader_icd_destroy( |
| 953 | struct loader_instance *ptr_inst, |
| 954 | struct loader_icd *icd) |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 955 | { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 956 | ptr_inst->total_icd_count--; |
Jon Ashburn | 128f942 | 2015-05-28 19:16:58 -0600 | [diff] [blame] | 957 | free(icd->gpus); |
Courtney Goeltzenleuchter | 1f157ac | 2015-06-14 19:57:15 -0600 | [diff] [blame] | 958 | for (struct loader_device *dev = icd->logical_device_list; dev; ) { |
| 959 | struct loader_device *next_dev = dev->next; |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 960 | loader_destroy_logical_device(dev); |
Courtney Goeltzenleuchter | 1f157ac | 2015-06-14 19:57:15 -0600 | [diff] [blame] | 961 | dev = next_dev; |
| 962 | } |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 963 | |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 964 | free(icd); |
| 965 | } |
| 966 | |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 967 | 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] | 968 | { |
| 969 | struct loader_icd *icd; |
| 970 | |
| 971 | icd = malloc(sizeof(*icd)); |
| 972 | if (!icd) |
| 973 | return NULL; |
| 974 | |
Courtney Goeltzenleuchter | 55001bb | 2014-10-28 10:29:27 -0600 | [diff] [blame] | 975 | memset(icd, 0, sizeof(*icd)); |
| 976 | |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 977 | icd->scanned_icds = scanned; |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 978 | |
| 979 | return icd; |
| 980 | } |
| 981 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 982 | static struct loader_icd *loader_icd_add( |
| 983 | struct loader_instance *ptr_inst, |
| 984 | const struct loader_scanned_icds *scanned) |
Chia-I Wu | 13a61a5 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 985 | { |
| 986 | struct loader_icd *icd; |
| 987 | |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 988 | icd = loader_icd_create(scanned); |
Chia-I Wu | 13a61a5 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 989 | if (!icd) |
| 990 | return NULL; |
| 991 | |
Chia-I Wu | 13a61a5 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 992 | /* prepend to the list */ |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 993 | icd->next = ptr_inst->icds; |
| 994 | ptr_inst->icds = icd; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 995 | ptr_inst->total_icd_count++; |
Chia-I Wu | 13a61a5 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 996 | |
| 997 | return icd; |
| 998 | } |
| 999 | |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 1000 | static void loader_scanned_icd_add(const char *filename) |
| 1001 | { |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1002 | loader_platform_dl_handle handle; |
Jon Ashburn | 3da71f2 | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 1003 | void *fp_create_inst; |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 1004 | void *fp_get_global_ext_props; |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 1005 | void *fp_get_device_ext_props; |
Jon Ashburn | 953bb3c | 2015-06-10 16:11:42 -0600 | [diff] [blame] | 1006 | PFN_vkGPA fp_get_proc_addr; |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 1007 | struct loader_scanned_icds *new_node; |
| 1008 | |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1009 | // Used to call: dlopen(filename, RTLD_LAZY); |
| 1010 | handle = loader_platform_open_library(filename); |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 1011 | if (!handle) { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1012 | 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] | 1013 | return; |
| 1014 | } |
| 1015 | |
| 1016 | #define LOOKUP(func_ptr, func) do { \ |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1017 | 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] | 1018 | if (!func_ptr) { \ |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1019 | 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] | 1020 | return; \ |
| 1021 | } \ |
| 1022 | } while (0) |
| 1023 | |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 1024 | LOOKUP(fp_create_inst, CreateInstance); |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 1025 | LOOKUP(fp_get_global_ext_props, GetGlobalExtensionProperties); |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 1026 | LOOKUP(fp_get_device_ext_props, GetPhysicalDeviceExtensionProperties); |
Jon Ashburn | 953bb3c | 2015-06-10 16:11:42 -0600 | [diff] [blame] | 1027 | LOOKUP(fp_get_proc_addr, GetDeviceProcAddr); |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 1028 | #undef LOOKUP |
| 1029 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1030 | new_node = (struct loader_scanned_icds *) malloc(sizeof(struct loader_scanned_icds) |
| 1031 | + strlen(filename) + 1); |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 1032 | if (!new_node) { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1033 | 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] | 1034 | return; |
| 1035 | } |
| 1036 | |
| 1037 | new_node->handle = handle; |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 1038 | new_node->CreateInstance = fp_create_inst; |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 1039 | new_node->GetGlobalExtensionProperties = fp_get_global_ext_props; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1040 | loader_init_ext_list(&new_node->global_extension_list); |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 1041 | loader_init_ext_list(&new_node->device_extension_list); |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 1042 | new_node->next = loader.scanned_icd_list; |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 1043 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1044 | new_node->lib_name = (char *) (new_node + 1); |
| 1045 | if (!new_node->lib_name) { |
| 1046 | loader_log(VK_DBG_REPORT_WARN_BIT, 0, "Out of memory can't add icd"); |
| 1047 | return; |
| 1048 | } |
| 1049 | strcpy(new_node->lib_name, filename); |
| 1050 | |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1051 | loader.scanned_icd_list = new_node; |
| 1052 | |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1053 | loader_add_global_extensions( |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 1054 | (PFN_vkGetGlobalExtensionProperties) fp_get_global_ext_props, |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1055 | new_node->lib_name, |
Jon Ashburn | 953bb3c | 2015-06-10 16:11:42 -0600 | [diff] [blame] | 1056 | handle, |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1057 | VK_EXTENSION_ORIGIN_ICD, |
| 1058 | &new_node->global_extension_list); |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1059 | } |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1060 | |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1061 | static struct loader_extension_list *loader_global_extensions(const char *pLayerName) |
| 1062 | { |
| 1063 | if (pLayerName == NULL || (strlen(pLayerName) == 0)) { |
| 1064 | return &loader.global_extensions; |
| 1065 | } |
| 1066 | |
| 1067 | /* TODO: Add code to query global extensions from layer */ |
| 1068 | for (uint32_t i = 0; i < loader.scanned_layers.count; i++) { |
| 1069 | struct loader_layer_properties *work_layer = &loader.scanned_layers.list[i]; |
| 1070 | if (strcmp(work_layer->info.layerName, pLayerName) == 0) { |
| 1071 | return &work_layer->instance_extension_list; |
| 1072 | } |
| 1073 | } |
| 1074 | |
| 1075 | return NULL; |
| 1076 | } |
| 1077 | |
| 1078 | static struct loader_layer_list *loader_global_layers() |
| 1079 | { |
| 1080 | return &loader.scanned_layers; |
| 1081 | } |
| 1082 | |
| 1083 | static void loader_physical_device_layers( |
| 1084 | struct loader_icd *icd, |
| 1085 | uint32_t *count, |
| 1086 | struct loader_layer_list **list) |
| 1087 | { |
| 1088 | *count = icd->layer_properties_cache.count; |
| 1089 | *list = &icd->layer_properties_cache; |
| 1090 | } |
| 1091 | |
| 1092 | static void loader_physical_device_extensions( |
| 1093 | struct loader_icd *icd, |
| 1094 | uint32_t gpu_idx, |
| 1095 | const char *layer_name, |
| 1096 | uint32_t *count, |
| 1097 | struct loader_extension_list **list) |
| 1098 | { |
| 1099 | if (layer_name == NULL || (strlen(layer_name) == 0)) { |
| 1100 | *count = icd->device_extension_cache[gpu_idx].count; |
| 1101 | *list = &icd->device_extension_cache[gpu_idx]; |
| 1102 | return; |
| 1103 | } |
| 1104 | for (uint32_t i = 0; i < icd->layer_properties_cache.count; i++) { |
| 1105 | if (strcmp(layer_name, icd->layer_properties_cache.list[i].info.layerName) == 0) { |
| 1106 | *count = icd->layer_properties_cache.list[i].device_extension_list.count; |
| 1107 | *list = &icd->layer_properties_cache.list[i].device_extension_list; |
| 1108 | } |
| 1109 | } |
| 1110 | } |
| 1111 | |
Jon Ashburn | 3da71f2 | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 1112 | static void loader_icd_init_entrys(struct loader_icd *icd, |
| 1113 | struct loader_scanned_icds *scanned_icds) |
| 1114 | { |
| 1115 | /* initialize entrypoint function pointers */ |
| 1116 | |
| 1117 | #define LOOKUP(func) do { \ |
| 1118 | icd->func = (PFN_vk ##func) loader_platform_get_proc_address(scanned_icds->handle, "vk" #func); \ |
| 1119 | if (!icd->func) { \ |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1120 | 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] | 1121 | return; \ |
| 1122 | } \ |
| 1123 | } while (0) |
| 1124 | |
Jon Ashburn | 8d1b0b5 | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 1125 | /* could change this to use GetInstanceProcAddr in driver instead of dlsym */ |
| 1126 | LOOKUP(GetDeviceProcAddr); |
Jon Ashburn | 3da71f2 | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 1127 | LOOKUP(DestroyInstance); |
| 1128 | LOOKUP(EnumeratePhysicalDevices); |
Chris Forbes | bc0bb77 | 2015-06-21 22:55:02 +1200 | [diff] [blame] | 1129 | LOOKUP(GetPhysicalDeviceFeatures); |
| 1130 | LOOKUP(GetPhysicalDeviceFormatInfo); |
| 1131 | LOOKUP(GetPhysicalDeviceLimits); |
Jon Ashburn | 3da71f2 | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 1132 | LOOKUP(CreateDevice); |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 1133 | LOOKUP(GetPhysicalDeviceProperties); |
| 1134 | LOOKUP(GetPhysicalDeviceMemoryProperties); |
| 1135 | LOOKUP(GetPhysicalDevicePerformance); |
| 1136 | LOOKUP(GetPhysicalDeviceQueueCount); |
| 1137 | LOOKUP(GetPhysicalDeviceQueueProperties); |
| 1138 | LOOKUP(GetPhysicalDeviceExtensionProperties); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1139 | LOOKUP(DbgCreateMsgCallback); |
| 1140 | LOOKUP(DbgDestroyMsgCallback); |
Jon Ashburn | 3da71f2 | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 1141 | #undef LOOKUP |
| 1142 | |
| 1143 | return; |
| 1144 | } |
| 1145 | |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 1146 | static void loader_debug_init(void) |
| 1147 | { |
| 1148 | const char *env; |
| 1149 | |
| 1150 | if (g_loader_debug > 0) |
| 1151 | return; |
| 1152 | |
| 1153 | g_loader_debug = 0; |
| 1154 | |
| 1155 | /* parse comma-separated debug options */ |
| 1156 | env = getenv("LOADER_DEBUG"); |
| 1157 | while (env) { |
| 1158 | const char *p = strchr(env, ','); |
| 1159 | size_t len; |
| 1160 | |
| 1161 | if (p) |
| 1162 | len = p - env; |
| 1163 | else |
| 1164 | len = strlen(env); |
| 1165 | |
| 1166 | if (len > 0) { |
| 1167 | if (strncmp(env, "warn", len) == 0) { |
| 1168 | g_loader_debug |= LOADER_WARN_BIT; |
| 1169 | g_loader_log_msgs |= VK_DBG_REPORT_WARN_BIT; |
| 1170 | } else if (strncmp(env, "info", len) == 0) { |
| 1171 | g_loader_debug |= LOADER_INFO_BIT; |
| 1172 | g_loader_log_msgs |= VK_DBG_REPORT_INFO_BIT; |
| 1173 | } else if (strncmp(env, "perf", len) == 0) { |
| 1174 | g_loader_debug |= LOADER_PERF_BIT; |
| 1175 | g_loader_log_msgs |= VK_DBG_REPORT_PERF_WARN_BIT; |
| 1176 | } else if (strncmp(env, "error", len) == 0) { |
| 1177 | g_loader_debug |= LOADER_ERROR_BIT; |
| 1178 | g_loader_log_msgs |= VK_DBG_REPORT_ERROR_BIT; |
| 1179 | } else if (strncmp(env, "debug", len) == 0) { |
| 1180 | g_loader_debug |= LOADER_DEBUG_BIT; |
| 1181 | g_loader_log_msgs |= VK_DBG_REPORT_DEBUG_BIT; |
| 1182 | } |
| 1183 | } |
| 1184 | |
| 1185 | if (!p) |
| 1186 | break; |
| 1187 | |
| 1188 | env = p + 1; |
| 1189 | } |
| 1190 | } |
| 1191 | |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1192 | struct loader_manifest_files { |
| 1193 | uint32_t count; |
| 1194 | char **filename_list; |
| 1195 | }; |
| 1196 | |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 1197 | /** |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1198 | * Get next file or dirname given a string list or registry key path |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 1199 | * |
| 1200 | * \returns |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1201 | * A pointer to first char in the next path. |
| 1202 | * The next path (or NULL) in the list is returned in next_path. |
| 1203 | * Note: input string is modified in some cases. PASS IN A COPY! |
| 1204 | */ |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1205 | static char *loader_get_next_path(char *path) |
| 1206 | { |
| 1207 | uint32_t len; |
| 1208 | char *next; |
| 1209 | |
| 1210 | if (path == NULL) |
| 1211 | return NULL; |
| 1212 | next = strchr(path, PATH_SEPERATOR); |
| 1213 | if (next == NULL) { |
| 1214 | len = (uint32_t) strlen(path); |
| 1215 | next = path + len; |
| 1216 | } |
| 1217 | else { |
| 1218 | *next = '\0'; |
| 1219 | next++; |
| 1220 | } |
| 1221 | |
| 1222 | return next; |
| 1223 | } |
| 1224 | |
| 1225 | /** |
| 1226 | * Given a filename (file) and a list of paths (dir), try to find an existing |
| 1227 | * file in the paths. If filename already is a path then no |
| 1228 | * searching in the given paths. |
| 1229 | * |
| 1230 | * \returns |
| 1231 | * A string in out_fullpath of either the full path or file. |
| 1232 | * Side effect is that dir string maybe modified. |
| 1233 | */ |
| 1234 | static void loader_get_fullpath(const char *file, |
| 1235 | char *dir, |
| 1236 | size_t out_size, |
| 1237 | char *out_fullpath) |
| 1238 | { |
| 1239 | char *next_dir; |
| 1240 | if (strchr(file,DIRECTORY_SYMBOL) == NULL) { |
| 1241 | //find file exists with prepending given path |
| 1242 | while (*dir) { |
| 1243 | next_dir = loader_get_next_path(dir); |
| 1244 | snprintf(out_fullpath, out_size, "%s%c%s", |
| 1245 | dir, DIRECTORY_SYMBOL, file); |
| 1246 | if (loader_platform_file_exists(out_fullpath)) { |
| 1247 | return; |
| 1248 | } |
| 1249 | dir = next_dir; |
| 1250 | } |
| 1251 | } |
| 1252 | snprintf(out_fullpath, out_size, "%s", file); |
| 1253 | } |
| 1254 | |
| 1255 | /** |
| 1256 | * Read a JSON file into a buffer. |
| 1257 | * |
| 1258 | * \returns |
| 1259 | * A pointer to a cJSON object representing the JSON parse tree. |
| 1260 | * This returned buffer should be freed by caller. |
| 1261 | */ |
| 1262 | static cJSON *loader_get_json(const char *filename) |
| 1263 | { |
| 1264 | FILE *file; |
| 1265 | char *json_buf; |
| 1266 | cJSON *json; |
| 1267 | uint64_t len; |
| 1268 | file = fopen(filename,"rb"); |
| 1269 | fseek(file, 0, SEEK_END); |
| 1270 | len = ftell(file); |
| 1271 | fseek(file, 0, SEEK_SET); |
Courtney Goeltzenleuchter | 7f5aafc | 2015-07-05 11:28:29 -0600 | [diff] [blame^] | 1272 | json_buf = (char*) loader_stack_alloc(len+1); |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1273 | if (json_buf == NULL) { |
| 1274 | loader_log(VK_DBG_REPORT_ERROR_BIT, 0, "Out of memory can't get JSON file"); |
| 1275 | fclose(file); |
| 1276 | return NULL; |
| 1277 | } |
| 1278 | if (fread(json_buf, sizeof(char), len, file) != len) { |
| 1279 | loader_log(VK_DBG_REPORT_ERROR_BIT, 0, "fread failed can't get JSON file"); |
| 1280 | fclose(file); |
| 1281 | return NULL; |
| 1282 | } |
| 1283 | fclose(file); |
| 1284 | json_buf[len] = '\0'; |
| 1285 | |
| 1286 | //parse text from file |
| 1287 | json = cJSON_Parse(json_buf); |
| 1288 | if (json == NULL) |
| 1289 | loader_log(VK_DBG_REPORT_ERROR_BIT, 0, "Can't parse JSON file %s", filename); |
| 1290 | return json; |
| 1291 | } |
| 1292 | |
| 1293 | /** |
| 1294 | * Find the Vulkan library manifest files. |
| 1295 | * |
| 1296 | * This function scans the location or env_override directories/files |
| 1297 | * for a list of JSON manifest files. If env_override is non-NULL |
| 1298 | * and has a valid value. Then the location is ignored. Otherwise |
| 1299 | * location is used to look for manifest files. The location |
| 1300 | * is interpreted as Registry path on Windows and a directory path(s) |
| 1301 | * on Linux. |
| 1302 | * |
| 1303 | * \returns |
| 1304 | * A string list of manifest files to be opened in out_files param. |
| 1305 | * List has a pointer to string for each manifest filename. |
| 1306 | * When done using the list in out_files, pointers should be freed. |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 1307 | * Location or override string lists can be either files or directories as follows: |
| 1308 | * | location | override |
| 1309 | * -------------------------------- |
| 1310 | * Win ICD | files | files |
| 1311 | * Win Layer | files | dirs |
| 1312 | * Linux ICD | dirs | files |
| 1313 | * Linux Layer| dirs | dirs |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1314 | */ |
| 1315 | static void loader_get_manifest_files(const char *env_override, |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 1316 | bool is_layer, |
| 1317 | const char *location, |
| 1318 | struct loader_manifest_files *out_files) |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1319 | { |
| 1320 | char *override = NULL; |
| 1321 | char *loc; |
| 1322 | char *file, *next_file, *name; |
| 1323 | size_t alloced_count = 64; |
| 1324 | char full_path[2048]; |
| 1325 | DIR *sysdir = NULL; |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 1326 | bool list_is_dirs = false; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1327 | struct dirent *dent; |
| 1328 | |
| 1329 | out_files->count = 0; |
| 1330 | out_files->filename_list = NULL; |
| 1331 | |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1332 | if (env_override != NULL && (override = getenv(env_override))) { |
| 1333 | #if defined(__linux__) |
| 1334 | if (geteuid() != getuid()) { |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 1335 | /* Don't allow setuid apps to use the env var: */ |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1336 | override = NULL; |
| 1337 | } |
| 1338 | #endif |
| 1339 | } |
| 1340 | |
| 1341 | if (location == NULL) { |
| 1342 | loader_log(VK_DBG_REPORT_ERROR_BIT, 0, |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 1343 | "Can't get manifest files with NULL location, env_override=%s", |
| 1344 | env_override); |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1345 | return; |
| 1346 | } |
| 1347 | |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 1348 | #if defined(__linux__) |
| 1349 | list_is_dirs = (override == NULL || is_layer) ? true : false; |
| 1350 | #else //WIN32 |
| 1351 | list_is_dirs = (is_layer && override != NULL) ? true : false; |
| 1352 | #endif |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1353 | // Make a copy of the input we are using so it is not modified |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 1354 | // Also handle getting the location(s) from registry on Windows |
| 1355 | if (override == NULL) { |
| 1356 | #if defined (_WIN32) |
| 1357 | loc = loader_get_registry_files(location); |
| 1358 | if (loc == NULL) { |
| 1359 | loader_log(VK_DBG_REPORT_ERROR_BIT, 0, "Registry lookup failed can't get manifest files"); |
| 1360 | return; |
| 1361 | } |
| 1362 | #else |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1363 | loc = alloca(strlen(location) + 1); |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 1364 | if (loc == NULL) { |
| 1365 | loader_log(VK_DBG_REPORT_ERROR_BIT, 0, "Out of memory can't get manifest files"); |
| 1366 | return; |
| 1367 | } |
| 1368 | strcpy(loc, location); |
| 1369 | #endif |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1370 | } |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 1371 | else { |
Courtney Goeltzenleuchter | 7f5aafc | 2015-07-05 11:28:29 -0600 | [diff] [blame^] | 1372 | loc = loader_stack_alloc(strlen(override) + 1); |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 1373 | if (loc == NULL) { |
| 1374 | loader_log(VK_DBG_REPORT_ERROR_BIT, 0, "Out of memory can't get manifest files"); |
| 1375 | return; |
| 1376 | } |
| 1377 | strcpy(loc, override); |
| 1378 | } |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1379 | |
| 1380 | file = loc; |
| 1381 | while (*file) { |
| 1382 | next_file = loader_get_next_path(file); |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 1383 | if (list_is_dirs) { |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1384 | sysdir = opendir(file); |
| 1385 | name = NULL; |
| 1386 | if (sysdir) { |
| 1387 | dent = readdir(sysdir); |
| 1388 | if (dent == NULL) |
| 1389 | break; |
| 1390 | name = &(dent->d_name[0]); |
| 1391 | loader_get_fullpath(name, file, sizeof(full_path), full_path); |
| 1392 | name = full_path; |
| 1393 | } |
| 1394 | } |
| 1395 | else { |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 1396 | #if defined(__linux__) |
| 1397 | // only Linux has relative paths |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1398 | char *dir; |
| 1399 | // make a copy of location so it isn't modified |
| 1400 | dir = alloca(strlen(location) + 1); |
| 1401 | if (dir == NULL) { |
| 1402 | loader_log(VK_DBG_REPORT_ERROR_BIT, 0, "Out of memory can't get manifest files"); |
| 1403 | return; |
| 1404 | } |
| 1405 | strcpy(dir, location); |
| 1406 | |
| 1407 | loader_get_fullpath(file, dir, sizeof(full_path), full_path); |
| 1408 | |
| 1409 | name = full_path; |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 1410 | #else // WIN32 |
| 1411 | name = file; |
| 1412 | #endif |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1413 | } |
| 1414 | while (name) { |
| 1415 | /* Look for files ending with ".json" suffix */ |
| 1416 | uint32_t nlen = (uint32_t) strlen(name); |
| 1417 | const char *suf = name + nlen - 5; |
| 1418 | if ((nlen > 5) && !strncmp(suf, ".json", 5)) { |
| 1419 | if (out_files->count == 0) { |
| 1420 | out_files->filename_list = malloc(alloced_count * sizeof(char *)); |
| 1421 | } |
| 1422 | else if (out_files->count == alloced_count) { |
| 1423 | out_files->filename_list = realloc(out_files->filename_list, |
| 1424 | alloced_count * sizeof(char *) * 2); |
| 1425 | alloced_count *= 2; |
| 1426 | } |
| 1427 | if (out_files->filename_list == NULL) { |
| 1428 | loader_log(VK_DBG_REPORT_ERROR_BIT, 0, "Out of memory can't alloc manifest file list"); |
| 1429 | return; |
| 1430 | } |
| 1431 | out_files->filename_list[out_files->count] = malloc(strlen(name) + 1); |
| 1432 | if (out_files->filename_list[out_files->count] == NULL) { |
| 1433 | loader_log(VK_DBG_REPORT_ERROR_BIT, 0, "Out of memory can't get manifest files"); |
| 1434 | return; |
| 1435 | } |
| 1436 | strcpy(out_files->filename_list[out_files->count], name); |
| 1437 | out_files->count++; |
Jon Ashburn | f70f361 | 2015-07-02 10:08:47 -0600 | [diff] [blame] | 1438 | } else if (!list_is_dirs) { |
| 1439 | loader_log(VK_DBG_REPORT_WARN_BIT, 0, "Skipping manifest file %s, file name must end in .json", name); |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1440 | } |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 1441 | if (list_is_dirs) { |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1442 | dent = readdir(sysdir); |
| 1443 | if (dent == NULL) |
| 1444 | break; |
| 1445 | name = &(dent->d_name[0]); |
| 1446 | loader_get_fullpath(name, file, sizeof(full_path), full_path); |
| 1447 | name = full_path; |
| 1448 | } |
| 1449 | else { |
| 1450 | break; |
| 1451 | } |
| 1452 | } |
| 1453 | if (sysdir) |
| 1454 | closedir(sysdir); |
| 1455 | file = next_file; |
| 1456 | } |
| 1457 | return; |
| 1458 | } |
| 1459 | |
| 1460 | /** |
| 1461 | * Try to find the Vulkan ICD driver(s). |
| 1462 | * |
| 1463 | * This function scans the default system loader path(s) or path |
| 1464 | * specified by the \c VK_ICD_FILENAMES environment variable in |
| 1465 | * order to find loadable VK ICDs manifest files. From these |
| 1466 | * manifest files it finds the ICD libraries. |
| 1467 | * |
| 1468 | * \returns |
Jon Ashburn | 3a37aee | 2015-06-30 16:44:28 -0600 | [diff] [blame] | 1469 | * void |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 1470 | */ |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 1471 | void loader_icd_scan(void) |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1472 | { |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1473 | char *file_str; |
| 1474 | struct loader_manifest_files manifest_files; |
| 1475 | |
Jon Ashburn | 6301a0f | 2015-05-29 13:15:39 -0600 | [diff] [blame] | 1476 | |
| 1477 | // convenient place to initialize a mutex |
| 1478 | loader_platform_thread_create_mutex(&loader_lock); |
| 1479 | |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1480 | // convenient place to initialize logging |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 1481 | loader_debug_init(); |
| 1482 | |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1483 | // Get a list of manifest files for ICDs |
| 1484 | loader_get_manifest_files("VK_ICD_FILENAMES", false, DEFAULT_VK_DRIVERS_INFO, |
| 1485 | &manifest_files); |
| 1486 | for (uint32_t i = 0; i < manifest_files.count; i++) { |
| 1487 | file_str = manifest_files.filename_list[i]; |
| 1488 | if (file_str == NULL) |
| 1489 | continue; |
| 1490 | |
| 1491 | cJSON *json, *icd_json; |
| 1492 | json = loader_get_json(file_str); |
| 1493 | icd_json = cJSON_GetObjectItem(json, "ICD"); |
| 1494 | if (icd_json != NULL) { |
| 1495 | icd_json = cJSON_GetObjectItem(icd_json, "library_path"); |
| 1496 | if (icd_json != NULL) { |
| 1497 | char *icd_filename = cJSON_PrintUnformatted(icd_json); |
| 1498 | char *icd_file = icd_filename; |
| 1499 | if (icd_filename != NULL) { |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1500 | char def_dir[] = DEFAULT_VK_DRIVERS_PATH; |
| 1501 | char *dir = def_dir; |
| 1502 | // strip off extra quotes |
| 1503 | if (icd_filename[strlen(icd_filename) - 1] == '"') |
| 1504 | icd_filename[strlen(icd_filename) - 1] = '\0'; |
| 1505 | if (icd_filename[0] == '"') |
| 1506 | icd_filename++; |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 1507 | #if defined(__linux__) |
| 1508 | char full_path[2048]; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1509 | loader_get_fullpath(icd_filename, dir, sizeof(full_path), full_path); |
| 1510 | loader_scanned_icd_add(full_path); |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 1511 | #else // WIN32 |
| 1512 | loader_scanned_icd_add(icd_filename); |
| 1513 | #endif |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1514 | free(icd_file); |
| 1515 | } |
| 1516 | } |
| 1517 | else |
| 1518 | loader_log(VK_DBG_REPORT_WARN_BIT, 0, "Can't find \"library_path\" in ICD JSON file %s, skipping", file_str); |
| 1519 | } |
| 1520 | else |
| 1521 | loader_log(VK_DBG_REPORT_WARN_BIT, 0, "Can't find \"ICD\" object in ICD JSON file %s, skipping", file_str); |
| 1522 | |
| 1523 | free(file_str); |
| 1524 | cJSON_Delete(json); |
| 1525 | } |
| 1526 | free(manifest_files.filename_list); |
| 1527 | |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1528 | } |
| 1529 | |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 1530 | |
Jon Ashburn | 5ef2060 | 2015-07-02 09:40:15 -0600 | [diff] [blame] | 1531 | void loader_layer_scan(void) |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 1532 | { |
| 1533 | const char *p, *next; |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 1534 | char *libPaths = NULL; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 1535 | DIR *curdir; |
| 1536 | struct dirent *dent; |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 1537 | size_t len, i; |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 1538 | char temp_str[1024]; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 1539 | |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 1540 | #if defined(WIN32) |
| 1541 | bool must_free_libPaths; |
| 1542 | libPaths = loader_get_registry_and_env(LAYERS_PATH_ENV, |
| 1543 | LAYERS_PATH_REGISTRY_VALUE); |
| 1544 | if (libPaths != NULL) { |
| 1545 | must_free_libPaths = true; |
| 1546 | } else { |
| 1547 | must_free_libPaths = false; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1548 | libPaths = DEFAULT_VK_LAYERS_PATH; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 1549 | } |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 1550 | #else // WIN32 |
| 1551 | if (geteuid() == getuid()) { |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1552 | /* Don't allow setuid apps to use the LAYERS_PATH_ENV env var: */ |
Courtney Goeltzenleuchter | 66b72f9 | 2015-02-18 20:03:02 -0700 | [diff] [blame] | 1553 | libPaths = getenv(LAYERS_PATH_ENV); |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 1554 | } |
| 1555 | if (libPaths == NULL) { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1556 | libPaths = DEFAULT_VK_LAYERS_PATH; |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 1557 | } |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1558 | #endif // WIN32 |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 1559 | |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 1560 | if (libPaths == NULL) { |
| 1561 | // Have no paths to search: |
Courtney Goeltzenleuchter | 57985ce | 2014-12-01 09:29:42 -0700 | [diff] [blame] | 1562 | return; |
| 1563 | } |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 1564 | len = strlen(libPaths); |
Courtney Goeltzenleuchter | 57985ce | 2014-12-01 09:29:42 -0700 | [diff] [blame] | 1565 | loader.layer_dirs = malloc(len+1); |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 1566 | if (loader.layer_dirs == NULL) { |
Jon Ashburn | 90c6a0e | 2015-06-04 15:30:58 -0600 | [diff] [blame] | 1567 | loader_log(VK_DBG_REPORT_WARN_BIT, 0, "Out of memory can't add layer directories"); |
| 1568 | |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 1569 | free(libPaths); |
Courtney Goeltzenleuchter | a66265b | 2014-12-02 18:12:51 -0700 | [diff] [blame] | 1570 | return; |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 1571 | } |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1572 | // 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] | 1573 | strcpy(loader.layer_dirs, libPaths); |
| 1574 | #if defined(WIN32) |
| 1575 | // Free any allocated memory: |
| 1576 | if (must_free_libPaths) { |
| 1577 | free(libPaths); |
| 1578 | must_free_libPaths = false; |
| 1579 | } |
| 1580 | #endif // WIN32 |
Courtney Goeltzenleuchter | 57985ce | 2014-12-01 09:29:42 -0700 | [diff] [blame] | 1581 | libPaths = loader.layer_dirs; |
| 1582 | |
Jon Ashburn | 5ef2060 | 2015-07-02 09:40:15 -0600 | [diff] [blame] | 1583 | if (loader.scanned_layers.capacity == 0) { |
| 1584 | loader.scanned_layers.list = malloc(sizeof(struct loader_layer_properties) * 64); |
| 1585 | if (loader.scanned_layers.list == NULL) { |
| 1586 | //TODO ERR log |
| 1587 | return; |
| 1588 | } |
| 1589 | memset(loader.scanned_layers.list, 0, sizeof(struct loader_layer_properties) * 64); |
| 1590 | loader.scanned_layers.capacity = sizeof(struct loader_layer_properties) * 64; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 1591 | } |
Jon Ashburn | 5ef2060 | 2015-07-02 09:40:15 -0600 | [diff] [blame] | 1592 | else { |
| 1593 | /* cleanup any previously scanned libraries */ |
| 1594 | //TODO make sure everything is cleaned up properly |
| 1595 | for (i = 0; i < loader.scanned_layers.count; i++) { |
| 1596 | if (loader.scanned_layers.list[i].lib_info.lib_name != NULL) |
| 1597 | free(loader.scanned_layers.list[i].lib_info.lib_name); |
Jon Ashburn | 5ef2060 | 2015-07-02 09:40:15 -0600 | [diff] [blame] | 1598 | loader_destroy_ext_list(&loader.scanned_layers.list[i].instance_extension_list); |
| 1599 | loader_destroy_ext_list(&loader.scanned_layers.list[i].device_extension_list); |
| 1600 | loader.scanned_layers.list[i].lib_info.lib_name = NULL; |
| 1601 | } |
| 1602 | loader.scanned_layers.count = 0; |
| 1603 | } |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 1604 | |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 1605 | for (p = libPaths; *p; p = next) { |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1606 | next = strchr(p, PATH_SEPERATOR); |
| 1607 | if (next == NULL) { |
Courtney Goeltzenleuchter | 0f1d8eb | 2015-06-07 17:28:17 -0600 | [diff] [blame] | 1608 | len = (uint32_t) strlen(p); |
| 1609 | next = p + len; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1610 | } |
| 1611 | else { |
Courtney Goeltzenleuchter | 0f1d8eb | 2015-06-07 17:28:17 -0600 | [diff] [blame] | 1612 | len = (uint32_t) (next - p); |
| 1613 | *(char *) next = '\0'; |
| 1614 | next++; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1615 | } |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 1616 | |
Courtney Goeltzenleuchter | 0f1d8eb | 2015-06-07 17:28:17 -0600 | [diff] [blame] | 1617 | curdir = opendir(p); |
| 1618 | if (curdir) { |
| 1619 | dent = readdir(curdir); |
| 1620 | while (dent) { |
| 1621 | /* Look for layers starting with VK_LAYER_LIBRARY_PREFIX and |
| 1622 | * ending with VK_LIBRARY_SUFFIX |
| 1623 | */ |
| 1624 | if (!strncmp(dent->d_name, |
| 1625 | VK_LAYER_LIBRARY_PREFIX, |
| 1626 | VK_LAYER_LIBRARY_PREFIX_LEN)) { |
| 1627 | uint32_t nlen = (uint32_t) strlen(dent->d_name); |
| 1628 | const char *suf = dent->d_name + nlen - VK_LIBRARY_SUFFIX_LEN; |
| 1629 | if ((nlen > VK_LIBRARY_SUFFIX_LEN) && |
| 1630 | !strncmp(suf, |
| 1631 | VK_LIBRARY_SUFFIX, |
| 1632 | VK_LIBRARY_SUFFIX_LEN)) { |
| 1633 | loader_platform_dl_handle handle; |
| 1634 | snprintf(temp_str, sizeof(temp_str), |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1635 | "%s%c%s",p, DIRECTORY_SYMBOL, dent->d_name); |
Courtney Goeltzenleuchter | 0f1d8eb | 2015-06-07 17:28:17 -0600 | [diff] [blame] | 1636 | // Used to call: dlopen(temp_str, RTLD_LAZY) |
| 1637 | loader_log(VK_DBG_REPORT_DEBUG_BIT, 0, |
Courtney Goeltzenleuchter | 1e4602f | 2015-06-09 09:44:13 -0600 | [diff] [blame] | 1638 | "Attempt to open library: %s", temp_str); |
Courtney Goeltzenleuchter | 0f1d8eb | 2015-06-07 17:28:17 -0600 | [diff] [blame] | 1639 | if ((handle = loader_platform_open_library(temp_str)) == NULL) { |
Courtney Goeltzenleuchter | 1e4602f | 2015-06-09 09:44:13 -0600 | [diff] [blame] | 1640 | loader_log(VK_DBG_REPORT_DEBUG_BIT, 0, "open library failed"); |
Courtney Goeltzenleuchter | 0f1d8eb | 2015-06-07 17:28:17 -0600 | [diff] [blame] | 1641 | dent = readdir(curdir); |
| 1642 | continue; |
| 1643 | } |
| 1644 | loader_log(VK_DBG_REPORT_DEBUG_BIT, 0, |
Courtney Goeltzenleuchter | 1e4602f | 2015-06-09 09:44:13 -0600 | [diff] [blame] | 1645 | "Opened library: %s", temp_str); |
Courtney Goeltzenleuchter | a9e4af4 | 2015-06-01 14:49:17 -0600 | [diff] [blame] | 1646 | |
Courtney Goeltzenleuchter | 1e4602f | 2015-06-09 09:44:13 -0600 | [diff] [blame] | 1647 | loader_log(VK_DBG_REPORT_DEBUG_BIT, 0, "Collecting global extensions for %s", temp_str); |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1648 | |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1649 | loader_add_global_layer_properties(temp_str, handle, &loader.scanned_layers); |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 1650 | |
Courtney Goeltzenleuchter | 0f1d8eb | 2015-06-07 17:28:17 -0600 | [diff] [blame] | 1651 | loader_platform_close_library(handle); |
| 1652 | } |
| 1653 | } |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 1654 | |
Courtney Goeltzenleuchter | 0f1d8eb | 2015-06-07 17:28:17 -0600 | [diff] [blame] | 1655 | dent = readdir(curdir); |
| 1656 | } // while (dir_entry) |
Courtney Goeltzenleuchter | 0f1d8eb | 2015-06-07 17:28:17 -0600 | [diff] [blame] | 1657 | closedir(curdir); |
| 1658 | } // if (curdir)) |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1659 | } // for (libpaths) |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 1660 | } |
| 1661 | |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 1662 | static void* VKAPI loader_gpa_instance_internal(VkInstance inst, const char * pName) |
| 1663 | { |
| 1664 | // inst is not wrapped |
| 1665 | if (inst == VK_NULL_HANDLE) { |
| 1666 | return NULL; |
| 1667 | } |
| 1668 | VkLayerInstanceDispatchTable* disp_table = * (VkLayerInstanceDispatchTable **) inst; |
| 1669 | void *addr; |
| 1670 | |
Jon Ashburn | 8fd0825 | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 1671 | if (!strcmp(pName, "vkGetInstanceProcAddr")) |
| 1672 | return (void *) loader_gpa_instance_internal; |
| 1673 | |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 1674 | if (disp_table == NULL) |
| 1675 | return NULL; |
| 1676 | |
| 1677 | addr = loader_lookup_instance_dispatch_table(disp_table, pName); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1678 | if (addr) { |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 1679 | return addr; |
Jon Ashburn | 3d526cb | 2015-04-13 18:10:06 -0600 | [diff] [blame] | 1680 | } |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1681 | |
| 1682 | if (disp_table->GetInstanceProcAddr == NULL) { |
| 1683 | return NULL; |
| 1684 | } |
| 1685 | return disp_table->GetInstanceProcAddr(inst, pName); |
Jon Ashburn | 3d526cb | 2015-04-13 18:10:06 -0600 | [diff] [blame] | 1686 | } |
| 1687 | |
Jon Ashburn | 128f942 | 2015-05-28 19:16:58 -0600 | [diff] [blame] | 1688 | 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] | 1689 | { |
Jon Ashburn | 128f942 | 2015-05-28 19:16:58 -0600 | [diff] [blame] | 1690 | |
Jon Ashburn | 98bd454 | 2015-01-29 16:44:24 -0700 | [diff] [blame] | 1691 | for (struct loader_instance *inst = loader.instances; inst; inst = inst->next) { |
| 1692 | for (struct loader_icd *icd = inst->icds; icd; icd = icd->next) { |
| 1693 | for (uint32_t i = 0; i < icd->gpu_count; i++) |
Jon Ashburn | 128f942 | 2015-05-28 19:16:58 -0600 | [diff] [blame] | 1694 | if (icd->gpus[i] == gpu) { |
Jon Ashburn | 98bd454 | 2015-01-29 16:44:24 -0700 | [diff] [blame] | 1695 | *gpu_index = i; |
| 1696 | return icd; |
| 1697 | } |
| 1698 | } |
Jon Ashburn | 876b1ac | 2014-10-17 15:09:07 -0600 | [diff] [blame] | 1699 | } |
| 1700 | return NULL; |
| 1701 | } |
| 1702 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1703 | static loader_platform_dl_handle loader_add_layer_lib( |
Jon Ashburn | 4f67d74 | 2015-05-27 13:19:22 -0600 | [diff] [blame] | 1704 | const char *chain_type, |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1705 | struct loader_layer_properties *layer_prop) |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 1706 | { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1707 | struct loader_lib_info *new_layer_lib_list, *my_lib; |
| 1708 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1709 | for (uint32_t i = 0; i < loader.loaded_layer_lib_count; i++) { |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1710 | if (strcmp(loader.loaded_layer_lib_list[i].lib_name, layer_prop->lib_info.lib_name) == 0) { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1711 | /* Have already loaded this library, just increment ref count */ |
| 1712 | loader.loaded_layer_lib_list[i].ref_count++; |
Courtney Goeltzenleuchter | ca8c81a | 2015-06-14 11:59:07 -0600 | [diff] [blame] | 1713 | loader_log(VK_DBG_REPORT_DEBUG_BIT, 0, |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 1714 | "%s Chain: Increment layer reference count for layer library %s", |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1715 | chain_type, layer_prop->lib_info.lib_name); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1716 | return loader.loaded_layer_lib_list[i].lib_handle; |
| 1717 | } |
| 1718 | } |
| 1719 | |
| 1720 | /* Haven't seen this library so load it */ |
| 1721 | new_layer_lib_list = realloc(loader.loaded_layer_lib_list, |
| 1722 | (loader.loaded_layer_lib_count + 1) * sizeof(struct loader_lib_info)); |
| 1723 | if (!new_layer_lib_list) { |
| 1724 | loader_log(VK_DBG_REPORT_ERROR_BIT, 0, "loader: malloc failed"); |
| 1725 | return NULL; |
| 1726 | } |
| 1727 | |
| 1728 | my_lib = &new_layer_lib_list[loader.loaded_layer_lib_count]; |
| 1729 | |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1730 | /* NOTE: We require that the layer property be immutable */ |
| 1731 | my_lib->lib_name = (char *) layer_prop->lib_info.lib_name; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1732 | my_lib->ref_count = 0; |
| 1733 | my_lib->lib_handle = NULL; |
| 1734 | |
| 1735 | if ((my_lib->lib_handle = loader_platform_open_library(my_lib->lib_name)) == NULL) { |
| 1736 | loader_log(VK_DBG_REPORT_ERROR_BIT, 0, |
| 1737 | loader_platform_open_library_error(my_lib->lib_name)); |
| 1738 | return NULL; |
| 1739 | } else { |
Courtney Goeltzenleuchter | ca8c81a | 2015-06-14 11:59:07 -0600 | [diff] [blame] | 1740 | loader_log(VK_DBG_REPORT_DEBUG_BIT, 0, |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 1741 | "Chain: %s: Loading layer library %s", |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1742 | chain_type, layer_prop->lib_info.lib_name); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1743 | } |
| 1744 | loader.loaded_layer_lib_count++; |
| 1745 | loader.loaded_layer_lib_list = new_layer_lib_list; |
| 1746 | my_lib->ref_count++; |
| 1747 | |
| 1748 | return my_lib->lib_handle; |
| 1749 | } |
| 1750 | |
| 1751 | static void loader_remove_layer_lib( |
| 1752 | struct loader_instance *inst, |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1753 | struct loader_layer_properties *layer_prop) |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1754 | { |
| 1755 | uint32_t idx; |
| 1756 | struct loader_lib_info *new_layer_lib_list, *my_lib; |
| 1757 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1758 | for (uint32_t i = 0; i < loader.loaded_layer_lib_count; i++) { |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1759 | if (strcmp(loader.loaded_layer_lib_list[i].lib_name, layer_prop->lib_info.lib_name) == 0) { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1760 | /* found matching library */ |
| 1761 | idx = i; |
| 1762 | my_lib = &loader.loaded_layer_lib_list[i]; |
| 1763 | break; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 1764 | } |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 1765 | } |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 1766 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1767 | my_lib->ref_count--; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1768 | if (my_lib->ref_count > 0) { |
Courtney Goeltzenleuchter | ca8c81a | 2015-06-14 11:59:07 -0600 | [diff] [blame] | 1769 | loader_log(VK_DBG_REPORT_DEBUG_BIT, 0, |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1770 | "Decrement reference count for layer library %s", layer_prop->lib_info.lib_name); |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 1771 | return; |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 1772 | } |
Jon Ashburn | 19c2502 | 2015-04-14 14:14:48 -0600 | [diff] [blame] | 1773 | |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 1774 | loader_platform_close_library(my_lib->lib_handle); |
Courtney Goeltzenleuchter | ca8c81a | 2015-06-14 11:59:07 -0600 | [diff] [blame] | 1775 | loader_log(VK_DBG_REPORT_DEBUG_BIT, 0, |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1776 | "Unloading layer library %s", layer_prop->lib_info.lib_name); |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 1777 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1778 | /* Need to remove unused library from list */ |
| 1779 | new_layer_lib_list = malloc((loader.loaded_layer_lib_count - 1) * sizeof(struct loader_lib_info)); |
| 1780 | if (!new_layer_lib_list) { |
| 1781 | loader_log(VK_DBG_REPORT_ERROR_BIT, 0, "loader: malloc failed"); |
| 1782 | return; |
| 1783 | } |
| 1784 | |
| 1785 | if (idx > 0) { |
| 1786 | /* Copy records before idx */ |
| 1787 | memcpy(new_layer_lib_list, &loader.loaded_layer_lib_list[0], |
| 1788 | sizeof(struct loader_lib_info) * idx); |
| 1789 | } |
| 1790 | if (idx < (loader.loaded_layer_lib_count - 1)) { |
| 1791 | /* Copy records after idx */ |
| 1792 | memcpy(&new_layer_lib_list[idx], &loader.loaded_layer_lib_list[idx+1], |
| 1793 | sizeof(struct loader_lib_info) * (loader.loaded_layer_lib_count - idx - 1)); |
| 1794 | } |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 1795 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1796 | free(loader.loaded_layer_lib_list); |
| 1797 | loader.loaded_layer_lib_count--; |
| 1798 | loader.loaded_layer_lib_list = new_layer_lib_list; |
Jon Ashburn | b835805 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 1799 | } |
| 1800 | |
Jon Ashburn | 0c26e71 | 2015-07-02 16:10:32 -0600 | [diff] [blame] | 1801 | static void loader_add_layer_implicit( |
| 1802 | const enum layer_type type, |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1803 | struct loader_layer_list *list, |
| 1804 | struct loader_layer_list *search_list) |
Jon Ashburn | 0c26e71 | 2015-07-02 16:10:32 -0600 | [diff] [blame] | 1805 | { |
| 1806 | uint32_t i; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1807 | for (i = 0; i < search_list->count; i++) { |
| 1808 | const struct loader_layer_properties *prop = &search_list->list[i]; |
Jon Ashburn | 0c26e71 | 2015-07-02 16:10:32 -0600 | [diff] [blame] | 1809 | if (prop->type & type) { |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1810 | /* Found an layer with the same type, add to layer_list */ |
| 1811 | loader_add_to_layer_list(list, 1, prop); |
Jon Ashburn | 0c26e71 | 2015-07-02 16:10:32 -0600 | [diff] [blame] | 1812 | } |
| 1813 | } |
| 1814 | |
| 1815 | } |
| 1816 | |
| 1817 | /** |
| 1818 | * Get the layer name(s) from the env_name environment variable. If layer |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1819 | * is found in search_list then add it to layer_list. |
Jon Ashburn | 0c26e71 | 2015-07-02 16:10:32 -0600 | [diff] [blame] | 1820 | */ |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1821 | static void loader_add_layer_env( |
Jon Ashburn | eb6d568 | 2015-07-02 14:10:53 -0600 | [diff] [blame] | 1822 | const char *env_name, |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1823 | struct loader_layer_list *layer_list, |
| 1824 | const struct loader_layer_list *search_list) |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 1825 | { |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 1826 | char *layerEnv; |
Jon Ashburn | eb6d568 | 2015-07-02 14:10:53 -0600 | [diff] [blame] | 1827 | char *next, *name; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 1828 | |
Jon Ashburn | eb6d568 | 2015-07-02 14:10:53 -0600 | [diff] [blame] | 1829 | layerEnv = getenv(env_name); |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 1830 | if (layerEnv == NULL) { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1831 | return; |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 1832 | } |
Courtney Goeltzenleuchter | 7f5aafc | 2015-07-05 11:28:29 -0600 | [diff] [blame^] | 1833 | name = loader_stack_alloc(strlen(layerEnv) + 1); |
Jon Ashburn | eb6d568 | 2015-07-02 14:10:53 -0600 | [diff] [blame] | 1834 | if (name == NULL) { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1835 | return; |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 1836 | } |
Jon Ashburn | eb6d568 | 2015-07-02 14:10:53 -0600 | [diff] [blame] | 1837 | strcpy(name, layerEnv); |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 1838 | |
Jon Ashburn | eb6d568 | 2015-07-02 14:10:53 -0600 | [diff] [blame] | 1839 | while (name && *name ) { |
| 1840 | next = loader_get_next_path(name); |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1841 | loader_find_layer_name_add_list(name, search_list, layer_list); |
Jon Ashburn | eb6d568 | 2015-07-02 14:10:53 -0600 | [diff] [blame] | 1842 | name = next; |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 1843 | } |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 1844 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1845 | return; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 1846 | } |
| 1847 | |
Courtney Goeltzenleuchter | 7d0023c | 2015-06-08 15:09:22 -0600 | [diff] [blame] | 1848 | void loader_deactivate_instance_layers(struct loader_instance *instance) |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 1849 | { |
Jon Ashburn | bd6c488 | 2015-07-02 12:59:25 -0600 | [diff] [blame] | 1850 | if (!instance->activated_layer_list.count) { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1851 | return; |
| 1852 | } |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 1853 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1854 | /* Create instance chain of enabled layers */ |
Courtney Goeltzenleuchter | 7d0023c | 2015-06-08 15:09:22 -0600 | [diff] [blame] | 1855 | for (uint32_t i = 0; i < instance->activated_layer_list.count; i++) { |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1856 | struct loader_layer_properties *layer_prop = &instance->activated_layer_list.list[i]; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1857 | |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1858 | loader_remove_layer_lib(instance, layer_prop); |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 1859 | } |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1860 | loader_destroy_layer_list(&instance->activated_layer_list); |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 1861 | } |
| 1862 | |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1863 | void loader_enable_instance_layers( |
| 1864 | struct loader_instance *inst, |
| 1865 | const VkInstanceCreateInfo *pCreateInfo) |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1866 | { |
| 1867 | if (inst == NULL) |
| 1868 | return; |
| 1869 | |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1870 | if (!loader_init_layer_list(&inst->activated_layer_list)) { |
Jon Ashburn | bd6c488 | 2015-07-02 12:59:25 -0600 | [diff] [blame] | 1871 | loader_log(VK_DBG_REPORT_ERROR_BIT, 0, "Failed to malloc Instance activated layer list"); |
| 1872 | return; |
| 1873 | } |
| 1874 | |
Jon Ashburn | 0c26e71 | 2015-07-02 16:10:32 -0600 | [diff] [blame] | 1875 | /* Add any implicit layers first */ |
| 1876 | loader_add_layer_implicit( |
| 1877 | VK_LAYER_TYPE_INSTANCE_IMPLICIT, |
| 1878 | &inst->activated_layer_list, |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1879 | &loader.scanned_layers); |
Jon Ashburn | 0c26e71 | 2015-07-02 16:10:32 -0600 | [diff] [blame] | 1880 | |
Jon Ashburn | bd6c488 | 2015-07-02 12:59:25 -0600 | [diff] [blame] | 1881 | /* Add any layers specified via environment variable first */ |
Jon Ashburn | eb6d568 | 2015-07-02 14:10:53 -0600 | [diff] [blame] | 1882 | loader_add_layer_env( |
| 1883 | "VK_INSTANCE_LAYERS", |
| 1884 | &inst->activated_layer_list, |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1885 | &loader.scanned_layers); |
Jon Ashburn | bd6c488 | 2015-07-02 12:59:25 -0600 | [diff] [blame] | 1886 | |
| 1887 | /* Add layers specified by the application */ |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1888 | loader_add_layer_names_to_list( |
| 1889 | &inst->activated_layer_list, |
| 1890 | pCreateInfo->layerCount, |
| 1891 | pCreateInfo->ppEnabledLayerNames, |
| 1892 | &loader.scanned_layers); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1893 | } |
| 1894 | |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 1895 | uint32_t loader_activate_instance_layers(struct loader_instance *inst) |
| 1896 | { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1897 | uint32_t layer_idx; |
Jon Ashburn | 128f942 | 2015-05-28 19:16:58 -0600 | [diff] [blame] | 1898 | VkBaseLayerObject *wrappedInstance; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1899 | |
David Pinedo | a0a8a24 | 2015-06-24 15:29:18 -0600 | [diff] [blame] | 1900 | if (inst == NULL) { |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 1901 | return 0; |
David Pinedo | a0a8a24 | 2015-06-24 15:29:18 -0600 | [diff] [blame] | 1902 | } |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 1903 | |
| 1904 | // NOTE inst is unwrapped at this point in time |
| 1905 | VkObject baseObj = (VkObject) inst; |
| 1906 | VkObject nextObj = (VkObject) inst; |
| 1907 | VkBaseLayerObject *nextInstObj; |
| 1908 | PFN_vkGetInstanceProcAddr nextGPA = loader_gpa_instance_internal; |
| 1909 | |
Jon Ashburn | bd6c488 | 2015-07-02 12:59:25 -0600 | [diff] [blame] | 1910 | if (!inst->activated_layer_list.count) { |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 1911 | return 0; |
| 1912 | } |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1913 | |
Jon Ashburn | 128f942 | 2015-05-28 19:16:58 -0600 | [diff] [blame] | 1914 | wrappedInstance = malloc(sizeof(VkBaseLayerObject) |
Jon Ashburn | bd6c488 | 2015-07-02 12:59:25 -0600 | [diff] [blame] | 1915 | * inst->activated_layer_list.count); |
Jon Ashburn | 128f942 | 2015-05-28 19:16:58 -0600 | [diff] [blame] | 1916 | if (!wrappedInstance) { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1917 | loader_log(VK_DBG_REPORT_ERROR_BIT, 0, "Failed to malloc Instance objects for layer"); |
| 1918 | return 0; |
| 1919 | } |
| 1920 | |
| 1921 | /* Create instance chain of enabled layers */ |
Jon Ashburn | bd6c488 | 2015-07-02 12:59:25 -0600 | [diff] [blame] | 1922 | layer_idx = inst->activated_layer_list.count - 1; |
Courtney Goeltzenleuchter | 0f1d8eb | 2015-06-07 17:28:17 -0600 | [diff] [blame] | 1923 | for (int32_t i = inst->activated_layer_list.count - 1; i >= 0; i--) { |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1924 | struct loader_layer_properties *layer_prop = &inst->activated_layer_list.list[i]; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1925 | loader_platform_dl_handle lib_handle; |
| 1926 | |
Jon Ashburn | bd6c488 | 2015-07-02 12:59:25 -0600 | [diff] [blame] | 1927 | /* |
Courtney Goeltzenleuchter | ee3b16a | 2015-06-01 14:12:42 -0600 | [diff] [blame] | 1928 | * Note: An extension's Get*ProcAddr should not return a function pointer for |
| 1929 | * any extension entry points until the extension has been enabled. |
| 1930 | * To do this requires a different behavior from Get*ProcAddr functions implemented |
| 1931 | * in layers. |
| 1932 | * The very first call to a layer will be it's Get*ProcAddr function requesting |
| 1933 | * the layer's vkGet*ProcAddr. The layer should intialize it's internal dispatch table |
| 1934 | * with the wrapped object given (either Instance or Device) and return the layer's |
| 1935 | * Get*ProcAddr function. The layer should also use this opportunity to record the |
| 1936 | * baseObject so that it can find the correct local dispatch table on future calls. |
| 1937 | * Subsequent calls to Get*ProcAddr, CreateInstance, CreateDevice |
| 1938 | * will not use a wrapped object and must look up their local dispatch table from |
| 1939 | * the given baseObject. |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1940 | */ |
Jon Ashburn | 128f942 | 2015-05-28 19:16:58 -0600 | [diff] [blame] | 1941 | nextInstObj = (wrappedInstance + layer_idx); |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 1942 | nextInstObj->pGPA = nextGPA; |
| 1943 | nextInstObj->baseObject = baseObj; |
| 1944 | nextInstObj->nextObject = nextObj; |
| 1945 | nextObj = (VkObject) nextInstObj; |
| 1946 | |
| 1947 | char funcStr[256]; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1948 | snprintf(funcStr, 256, "%sGetInstanceProcAddr", layer_prop->info.layerName); |
| 1949 | lib_handle = loader_add_layer_lib("instance", layer_prop); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1950 | if ((nextGPA = (PFN_vkGetInstanceProcAddr) loader_platform_get_proc_address(lib_handle, funcStr)) == NULL) |
| 1951 | nextGPA = (PFN_vkGetInstanceProcAddr) loader_platform_get_proc_address(lib_handle, "vkGetInstanceProcAddr"); |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 1952 | if (!nextGPA) { |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1953 | loader_log(VK_DBG_REPORT_ERROR_BIT, 0, "Failed to find vkGetInstanceProcAddr in layer %s", layer_prop->lib_info.lib_name); |
Courtney Goeltzenleuchter | a9e4af4 | 2015-06-01 14:49:17 -0600 | [diff] [blame] | 1954 | |
| 1955 | /* TODO: Should we return nextObj, nextGPA to previous? */ |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 1956 | continue; |
| 1957 | } |
| 1958 | |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 1959 | loader_log(VK_DBG_REPORT_INFO_BIT, 0, |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1960 | "Insert instance layer %s (%s)", |
| 1961 | layer_prop->info.layerName, |
| 1962 | layer_prop->lib_info.lib_name); |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 1963 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1964 | layer_idx--; |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 1965 | } |
| 1966 | |
Jon Ashburn | 8fd0825 | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 1967 | 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] | 1968 | |
Jon Ashburn | 128f942 | 2015-05-28 19:16:58 -0600 | [diff] [blame] | 1969 | free(wrappedInstance); |
Jon Ashburn | bd6c488 | 2015-07-02 12:59:25 -0600 | [diff] [blame] | 1970 | return inst->activated_layer_list.count; |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 1971 | } |
| 1972 | |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 1973 | void loader_activate_instance_layer_extensions(struct loader_instance *inst) |
| 1974 | { |
| 1975 | |
| 1976 | loader_init_instance_extension_dispatch_table(inst->disp, |
| 1977 | inst->disp->GetInstanceProcAddr, |
Jon Ashburn | 128f942 | 2015-05-28 19:16:58 -0600 | [diff] [blame] | 1978 | (VkInstance) inst); |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 1979 | } |
| 1980 | |
Courtney Goeltzenleuchter | a6628c2 | 2015-06-25 16:27:24 -0600 | [diff] [blame] | 1981 | static void loader_enable_device_layers( |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1982 | struct loader_device *dev, |
| 1983 | const VkDeviceCreateInfo *pCreateInfo) |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1984 | { |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1985 | if (dev == NULL) |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1986 | return; |
| 1987 | |
Jon Ashburn | bd6c488 | 2015-07-02 12:59:25 -0600 | [diff] [blame] | 1988 | if (dev->activated_layer_list.list == NULL || dev->activated_layer_list.capacity == 0) { |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1989 | loader_init_layer_list(&dev->activated_layer_list); |
Jon Ashburn | bd6c488 | 2015-07-02 12:59:25 -0600 | [diff] [blame] | 1990 | } |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1991 | |
Jon Ashburn | bd6c488 | 2015-07-02 12:59:25 -0600 | [diff] [blame] | 1992 | if (dev->activated_layer_list.list == NULL) { |
| 1993 | loader_log(VK_DBG_REPORT_ERROR_BIT, 0, "Failed to malloc device activated layer list"); |
| 1994 | return; |
| 1995 | } |
| 1996 | |
Jon Ashburn | 0c26e71 | 2015-07-02 16:10:32 -0600 | [diff] [blame] | 1997 | /* Add any implicit layers first */ |
| 1998 | loader_add_layer_implicit( |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1999 | VK_LAYER_TYPE_DEVICE_IMPLICIT, |
| 2000 | &dev->activated_layer_list, |
| 2001 | &loader.scanned_layers); |
Jon Ashburn | 0c26e71 | 2015-07-02 16:10:32 -0600 | [diff] [blame] | 2002 | |
| 2003 | /* Add any layers specified via environment variable next */ |
Jon Ashburn | eb6d568 | 2015-07-02 14:10:53 -0600 | [diff] [blame] | 2004 | loader_add_layer_env( |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 2005 | "VK_DEVICE_LAYERS", |
| 2006 | &dev->activated_layer_list, |
| 2007 | &loader.scanned_layers); |
Jon Ashburn | bd6c488 | 2015-07-02 12:59:25 -0600 | [diff] [blame] | 2008 | |
| 2009 | /* Add layers specified by the application */ |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 2010 | loader_add_layer_names_to_list( |
| 2011 | &dev->activated_layer_list, |
| 2012 | pCreateInfo->layerCount, |
| 2013 | pCreateInfo->ppEnabledLayerNames, |
| 2014 | &loader.scanned_layers); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 2015 | } |
| 2016 | |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 2017 | /* |
| 2018 | * This function terminates the device chain fro CreateDevice. |
| 2019 | * CreateDevice is a special case and so the loader call's |
| 2020 | * the ICD's CreateDevice before creating the chain. Since |
| 2021 | * we can't call CreateDevice twice we must terminate the |
| 2022 | * device chain with something else. |
| 2023 | */ |
Courtney Goeltzenleuchter | ca173b8 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 2024 | static VkResult scratch_vkCreateDevice( |
| 2025 | VkPhysicalDevice gpu, |
| 2026 | const VkDeviceCreateInfo *pCreateInfo, |
| 2027 | VkDevice *pDevice) |
| 2028 | { |
| 2029 | return VK_SUCCESS; |
| 2030 | } |
| 2031 | |
| 2032 | static void * VKAPI loader_GetDeviceChainProcAddr(VkDevice device, const char * name) |
| 2033 | { |
Courtney Goeltzenleuchter | ca173b8 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 2034 | if (!strcmp(name, "vkGetDeviceProcAddr")) |
| 2035 | return (void *) loader_GetDeviceChainProcAddr; |
| 2036 | if (!strcmp(name, "vkCreateDevice")) |
| 2037 | return (void *) scratch_vkCreateDevice; |
| 2038 | |
Courtney Goeltzenleuchter | 3e029d1 | 2015-06-29 16:09:23 -0600 | [diff] [blame] | 2039 | struct loader_device *found_dev; |
| 2040 | struct loader_icd *icd = loader_get_icd_and_device(device, &found_dev); |
| 2041 | return icd->GetDeviceProcAddr(device, name); |
Courtney Goeltzenleuchter | ca173b8 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 2042 | } |
| 2043 | |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 2044 | static uint32_t loader_activate_device_layers( |
Courtney Goeltzenleuchter | ca173b8 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 2045 | VkPhysicalDevice gpu, |
| 2046 | VkDevice device, |
| 2047 | struct loader_device *dev, |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 2048 | struct loader_icd *icd) |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 2049 | { |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 2050 | if (!icd) |
| 2051 | return 0; |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 2052 | |
David Pinedo | a0a8a24 | 2015-06-24 15:29:18 -0600 | [diff] [blame] | 2053 | if (!dev) { |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 2054 | return 0; |
David Pinedo | a0a8a24 | 2015-06-24 15:29:18 -0600 | [diff] [blame] | 2055 | } |
Jon Ashburn | 94e7049 | 2015-06-10 10:13:10 -0600 | [diff] [blame] | 2056 | |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 2057 | /* activate any layer libraries */ |
Jon Ashburn | 94e7049 | 2015-06-10 10:13:10 -0600 | [diff] [blame] | 2058 | VkObject nextObj = (VkObject) device; |
| 2059 | VkObject baseObj = nextObj; |
| 2060 | VkBaseLayerObject *nextGpuObj; |
Courtney Goeltzenleuchter | ca173b8 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 2061 | PFN_vkGetDeviceProcAddr nextGPA = loader_GetDeviceChainProcAddr; |
Jon Ashburn | 94e7049 | 2015-06-10 10:13:10 -0600 | [diff] [blame] | 2062 | VkBaseLayerObject *wrappedGpus; |
Courtney Goeltzenleuchter | ca173b8 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 2063 | |
Jon Ashburn | 94e7049 | 2015-06-10 10:13:10 -0600 | [diff] [blame] | 2064 | if (!dev->activated_layer_list.count) |
| 2065 | return 0; |
| 2066 | |
| 2067 | wrappedGpus = malloc(sizeof (VkBaseLayerObject) * dev->activated_layer_list.count); |
| 2068 | if (!wrappedGpus) { |
| 2069 | loader_log(VK_DBG_REPORT_ERROR_BIT, 0, "Failed to malloc Gpu objects for layer"); |
| 2070 | return 0; |
| 2071 | } |
Courtney Goeltzenleuchter | ca173b8 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 2072 | |
Jon Ashburn | 94e7049 | 2015-06-10 10:13:10 -0600 | [diff] [blame] | 2073 | for (int32_t i = dev->activated_layer_list.count - 1; i >= 0; i--) { |
| 2074 | |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 2075 | struct loader_layer_properties *layer_prop = &dev->activated_layer_list.list[i]; |
Jon Ashburn | 94e7049 | 2015-06-10 10:13:10 -0600 | [diff] [blame] | 2076 | loader_platform_dl_handle lib_handle; |
| 2077 | |
Jon Ashburn | 94e7049 | 2015-06-10 10:13:10 -0600 | [diff] [blame] | 2078 | nextGpuObj = (wrappedGpus + i); |
| 2079 | nextGpuObj->pGPA = nextGPA; |
| 2080 | nextGpuObj->baseObject = baseObj; |
| 2081 | nextGpuObj->nextObject = nextObj; |
| 2082 | nextObj = (VkObject) nextGpuObj; |
| 2083 | |
| 2084 | char funcStr[256]; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 2085 | snprintf(funcStr, 256, "%sGetDeviceProcAddr", layer_prop->info.layerName); |
| 2086 | lib_handle = loader_add_layer_lib("device", layer_prop); |
Jon Ashburn | 94e7049 | 2015-06-10 10:13:10 -0600 | [diff] [blame] | 2087 | if ((nextGPA = (PFN_vkGetDeviceProcAddr) loader_platform_get_proc_address(lib_handle, funcStr)) == NULL) |
| 2088 | nextGPA = (PFN_vkGetDeviceProcAddr) loader_platform_get_proc_address(lib_handle, "vkGetDeviceProcAddr"); |
| 2089 | if (!nextGPA) { |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 2090 | loader_log(VK_DBG_REPORT_ERROR_BIT, 0, "Failed to find vkGetDeviceProcAddr in layer %s", layer_prop->info.layerName); |
Jon Ashburn | 94e7049 | 2015-06-10 10:13:10 -0600 | [diff] [blame] | 2091 | continue; |
| 2092 | } |
| 2093 | |
| 2094 | loader_log(VK_DBG_REPORT_INFO_BIT, 0, |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 2095 | "Insert device layer library %s (%s)", |
| 2096 | layer_prop->info.layerName, |
| 2097 | layer_prop->lib_info.lib_name); |
Jon Ashburn | 94e7049 | 2015-06-10 10:13:10 -0600 | [diff] [blame] | 2098 | |
| 2099 | } |
| 2100 | |
| 2101 | loader_init_device_dispatch_table(&dev->loader_dispatch, nextGPA, |
| 2102 | (VkPhysicalDevice) nextObj, (VkPhysicalDevice) baseObj); |
| 2103 | free(wrappedGpus); |
| 2104 | |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 2105 | return dev->activated_layer_list.count; |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 2106 | } |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 2107 | |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 2108 | VkResult loader_CreateInstance( |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 2109 | const VkInstanceCreateInfo* pCreateInfo, |
| 2110 | VkInstance* pInstance) |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 2111 | { |
Jon Ashburn | eed0c00 | 2015-05-21 17:42:17 -0600 | [diff] [blame] | 2112 | struct loader_instance *ptr_instance = *(struct loader_instance **) pInstance; |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 2113 | struct loader_scanned_icds *scanned_icds; |
| 2114 | struct loader_icd *icd; |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 2115 | VkResult res; |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 2116 | |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 2117 | scanned_icds = loader.scanned_icd_list; |
| 2118 | while (scanned_icds) { |
| 2119 | icd = loader_icd_add(ptr_instance, scanned_icds); |
| 2120 | if (icd) { |
Jon Ashburn | b317fad | 2015-04-04 14:52:07 -0600 | [diff] [blame] | 2121 | res = scanned_icds->CreateInstance(pCreateInfo, |
Jon Ashburn | 3da71f2 | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 2122 | &(icd->instance)); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 2123 | if (res != VK_SUCCESS) |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 2124 | { |
| 2125 | ptr_instance->icds = ptr_instance->icds->next; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 2126 | loader_icd_destroy(ptr_instance, icd); |
Jon Ashburn | 3da71f2 | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 2127 | icd->instance = VK_NULL_HANDLE; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 2128 | loader_log(VK_DBG_REPORT_WARN_BIT, 0, |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 2129 | "ICD ignored: failed to CreateInstance on device"); |
Jon Ashburn | 3da71f2 | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 2130 | } else |
| 2131 | { |
| 2132 | loader_icd_init_entrys(icd, scanned_icds); |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 2133 | } |
| 2134 | } |
| 2135 | scanned_icds = scanned_icds->next; |
| 2136 | } |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 2137 | |
Ian Elliott | eb45076 | 2015-02-05 15:19:15 -0700 | [diff] [blame] | 2138 | if (ptr_instance->icds == NULL) { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 2139 | return VK_ERROR_INCOMPATIBLE_DRIVER; |
Ian Elliott | eb45076 | 2015-02-05 15:19:15 -0700 | [diff] [blame] | 2140 | } |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 2141 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 2142 | return res; |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 2143 | } |
| 2144 | |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 2145 | VkResult loader_DestroyInstance( |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 2146 | VkInstance instance) |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 2147 | { |
Courtney Goeltzenleuchter | deceded | 2015-06-08 15:04:02 -0600 | [diff] [blame] | 2148 | struct loader_instance *ptr_instance = loader_instance(instance); |
Jon Ashburn | 3da71f2 | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 2149 | struct loader_icd *icds = ptr_instance->icds; |
Jon Ashburn | a6fd261 | 2015-06-16 14:43:19 -0600 | [diff] [blame] | 2150 | struct loader_icd *next_icd; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 2151 | VkResult res; |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 2152 | |
| 2153 | // Remove this instance from the list of instances: |
| 2154 | struct loader_instance *prev = NULL; |
| 2155 | struct loader_instance *next = loader.instances; |
| 2156 | while (next != NULL) { |
| 2157 | if (next == ptr_instance) { |
| 2158 | // Remove this instance from the list: |
| 2159 | if (prev) |
| 2160 | prev->next = next->next; |
Jon Ashburn | c5c4960 | 2015-02-03 09:26:59 -0700 | [diff] [blame] | 2161 | else |
| 2162 | loader.instances = next->next; |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 2163 | break; |
| 2164 | } |
| 2165 | prev = next; |
| 2166 | next = next->next; |
| 2167 | } |
| 2168 | if (next == NULL) { |
| 2169 | // This must be an invalid instance handle or empty list |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 2170 | return VK_ERROR_INVALID_HANDLE; |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 2171 | } |
| 2172 | |
Jon Ashburn | 3da71f2 | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 2173 | while (icds) { |
| 2174 | if (icds->instance) { |
| 2175 | res = icds->DestroyInstance(icds->instance); |
Tony Barbour | f20f87b | 2015-04-22 09:02:32 -0600 | [diff] [blame] | 2176 | if (res != VK_SUCCESS) |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 2177 | loader_log(VK_DBG_REPORT_WARN_BIT, 0, |
Tony Barbour | f20f87b | 2015-04-22 09:02:32 -0600 | [diff] [blame] | 2178 | "ICD ignored: failed to DestroyInstance on device"); |
| 2179 | } |
Jon Ashburn | a6fd261 | 2015-06-16 14:43:19 -0600 | [diff] [blame] | 2180 | next_icd = icds->next; |
Jon Ashburn | 3da71f2 | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 2181 | icds->instance = VK_NULL_HANDLE; |
Jon Ashburn | a6fd261 | 2015-06-16 14:43:19 -0600 | [diff] [blame] | 2182 | loader_icd_destroy(ptr_instance, icds); |
| 2183 | |
| 2184 | icds = next_icd; |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 2185 | } |
| 2186 | |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 2187 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 2188 | return VK_SUCCESS; |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 2189 | } |
| 2190 | |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 2191 | VkResult loader_init_physical_device_info( |
| 2192 | struct loader_instance *ptr_instance) |
| 2193 | { |
| 2194 | struct loader_icd *icd; |
| 2195 | uint32_t n, count = 0; |
| 2196 | VkResult res = VK_ERROR_UNKNOWN; |
| 2197 | |
| 2198 | icd = ptr_instance->icds; |
| 2199 | while (icd) { |
| 2200 | res = icd->EnumeratePhysicalDevices(icd->instance, &n, NULL); |
| 2201 | if (res != VK_SUCCESS) |
| 2202 | return res; |
| 2203 | icd->gpu_count = n; |
| 2204 | count += n; |
| 2205 | icd = icd->next; |
| 2206 | } |
| 2207 | |
| 2208 | ptr_instance->total_gpu_count = count; |
| 2209 | |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 2210 | icd = ptr_instance->icds; |
| 2211 | while (icd) { |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 2212 | |
| 2213 | n = icd->gpu_count; |
Jon Ashburn | 128f942 | 2015-05-28 19:16:58 -0600 | [diff] [blame] | 2214 | icd->gpus = (VkPhysicalDevice *) malloc(n * sizeof(VkPhysicalDevice)); |
| 2215 | if (!icd->gpus) { |
| 2216 | /* TODO: Add cleanup code here */ |
| 2217 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 2218 | } |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 2219 | res = icd->EnumeratePhysicalDevices( |
| 2220 | icd->instance, |
| 2221 | &n, |
Jon Ashburn | 128f942 | 2015-05-28 19:16:58 -0600 | [diff] [blame] | 2222 | icd->gpus); |
| 2223 | if ((res == VK_SUCCESS) && (n == icd->gpu_count)) { |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 2224 | |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 2225 | for (unsigned int i = 0; i < n; i++) { |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 2226 | |
Jon Ashburn | 128f942 | 2015-05-28 19:16:58 -0600 | [diff] [blame] | 2227 | loader_init_dispatch(icd->gpus[i], ptr_instance->disp); |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 2228 | |
| 2229 | if (!loader_init_ext_list(&icd->device_extension_cache[i])) { |
| 2230 | /* TODO: Add cleanup code here */ |
| 2231 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 2232 | } |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 2233 | if (res == VK_SUCCESS) { |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 2234 | |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 2235 | loader_add_physical_device_extensions( |
| 2236 | icd->GetPhysicalDeviceExtensionProperties, |
| 2237 | icd->gpus[0], |
| 2238 | VK_EXTENSION_ORIGIN_ICD, |
| 2239 | icd->scanned_icds->lib_name, |
| 2240 | &icd->device_extension_cache[i]); |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 2241 | |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 2242 | for (uint32_t l = 0; l < loader.scanned_layers.count; l++) { |
| 2243 | loader_platform_dl_handle lib_handle; |
| 2244 | char *lib_name = loader.scanned_layers.list[i].lib_info.lib_name; |
| 2245 | |
| 2246 | lib_handle = loader_platform_open_library(lib_name); |
| 2247 | if (lib_handle == NULL) { |
| 2248 | loader_log(VK_DBG_REPORT_DEBUG_BIT, 0, "open library failed: %s", lib_name); |
| 2249 | continue; |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 2250 | } |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 2251 | loader_log(VK_DBG_REPORT_DEBUG_BIT, 0, |
| 2252 | "library: %s", lib_name); |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 2253 | |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 2254 | loader_add_physical_device_layer_properties( |
| 2255 | icd, lib_name, lib_handle); |
| 2256 | |
| 2257 | loader_platform_close_library(lib_handle); |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 2258 | } |
| 2259 | } |
| 2260 | |
| 2261 | if (res != VK_SUCCESS) { |
| 2262 | /* clean up any extension lists previously created before this request failed */ |
| 2263 | for (uint32_t j = 0; j < i; j++) { |
| 2264 | loader_destroy_ext_list(&icd->device_extension_cache[i]); |
| 2265 | } |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 2266 | |
| 2267 | loader_destroy_layer_list(&icd->layer_properties_cache); |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 2268 | return res; |
| 2269 | } |
| 2270 | } |
| 2271 | |
| 2272 | count += n; |
| 2273 | } |
| 2274 | |
| 2275 | icd = icd->next; |
| 2276 | } |
| 2277 | |
| 2278 | return VK_SUCCESS; |
| 2279 | } |
| 2280 | |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 2281 | VkResult loader_EnumeratePhysicalDevices( |
Courtney Goeltzenleuchter | 5e41f1d | 2015-04-20 12:48:54 -0600 | [diff] [blame] | 2282 | VkInstance instance, |
| 2283 | uint32_t* pPhysicalDeviceCount, |
| 2284 | VkPhysicalDevice* pPhysicalDevices) |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 2285 | { |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 2286 | uint32_t index = 0; |
Jon Ashburn | 4c392fb | 2015-01-28 19:57:09 -0700 | [diff] [blame] | 2287 | struct loader_instance *ptr_instance = (struct loader_instance *) instance; |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 2288 | struct loader_icd *icd = ptr_instance->icds; |
Jon Ashburn | 4c392fb | 2015-01-28 19:57:09 -0700 | [diff] [blame] | 2289 | |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 2290 | if (ptr_instance->total_gpu_count == 0) { |
| 2291 | loader_init_physical_device_info(ptr_instance); |
Jon Ashburn | 4c392fb | 2015-01-28 19:57:09 -0700 | [diff] [blame] | 2292 | } |
| 2293 | |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 2294 | *pPhysicalDeviceCount = ptr_instance->total_gpu_count; |
| 2295 | if (!pPhysicalDevices) { |
| 2296 | return VK_SUCCESS; |
| 2297 | } |
Jon Ashburn | 4c392fb | 2015-01-28 19:57:09 -0700 | [diff] [blame] | 2298 | |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 2299 | while (icd) { |
| 2300 | assert((index + icd->gpu_count) <= *pPhysicalDeviceCount); |
Jon Ashburn | 128f942 | 2015-05-28 19:16:58 -0600 | [diff] [blame] | 2301 | memcpy(&pPhysicalDevices[index], icd->gpus, icd->gpu_count * sizeof(VkPhysicalDevice)); |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 2302 | index += icd->gpu_count; |
| 2303 | icd = icd->next; |
| 2304 | } |
| 2305 | |
| 2306 | return VK_SUCCESS; |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 2307 | } |
| 2308 | |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 2309 | VkResult loader_GetPhysicalDeviceProperties( |
Jon Ashburn | 3da71f2 | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 2310 | VkPhysicalDevice gpu, |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 2311 | VkPhysicalDeviceProperties* pProperties) |
Jon Ashburn | 3da71f2 | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 2312 | { |
| 2313 | uint32_t gpu_index; |
Jon Ashburn | 128f942 | 2015-05-28 19:16:58 -0600 | [diff] [blame] | 2314 | struct loader_icd *icd = loader_get_icd(gpu, &gpu_index); |
Jon Ashburn | 3da71f2 | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 2315 | VkResult res = VK_ERROR_INITIALIZATION_FAILED; |
| 2316 | |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 2317 | if (icd->GetPhysicalDeviceProperties) |
| 2318 | res = icd->GetPhysicalDeviceProperties(gpu, pProperties); |
| 2319 | |
| 2320 | return res; |
| 2321 | } |
| 2322 | |
| 2323 | VkResult loader_GetPhysicalDevicePerformance( |
| 2324 | VkPhysicalDevice gpu, |
| 2325 | VkPhysicalDevicePerformance* pPerformance) |
| 2326 | { |
| 2327 | uint32_t gpu_index; |
| 2328 | struct loader_icd *icd = loader_get_icd(gpu, &gpu_index); |
| 2329 | VkResult res = VK_ERROR_INITIALIZATION_FAILED; |
| 2330 | |
| 2331 | if (icd->GetPhysicalDevicePerformance) |
| 2332 | res = icd->GetPhysicalDevicePerformance(gpu, pPerformance); |
| 2333 | |
| 2334 | return res; |
| 2335 | } |
| 2336 | |
| 2337 | VkResult loader_GetPhysicalDeviceQueueCount( |
| 2338 | VkPhysicalDevice gpu, |
| 2339 | uint32_t* pCount) |
| 2340 | { |
| 2341 | uint32_t gpu_index; |
| 2342 | struct loader_icd *icd = loader_get_icd(gpu, &gpu_index); |
| 2343 | VkResult res = VK_ERROR_INITIALIZATION_FAILED; |
| 2344 | |
| 2345 | if (icd->GetPhysicalDeviceQueueCount) |
| 2346 | res = icd->GetPhysicalDeviceQueueCount(gpu, pCount); |
| 2347 | |
| 2348 | return res; |
| 2349 | } |
| 2350 | |
| 2351 | VkResult loader_GetPhysicalDeviceQueueProperties ( |
| 2352 | VkPhysicalDevice gpu, |
| 2353 | uint32_t count, |
| 2354 | VkPhysicalDeviceQueueProperties * pProperties) |
| 2355 | { |
| 2356 | uint32_t gpu_index; |
| 2357 | struct loader_icd *icd = loader_get_icd(gpu, &gpu_index); |
| 2358 | VkResult res = VK_ERROR_INITIALIZATION_FAILED; |
| 2359 | |
| 2360 | if (icd->GetPhysicalDeviceQueueProperties) |
| 2361 | res = icd->GetPhysicalDeviceQueueProperties(gpu, count, pProperties); |
| 2362 | |
| 2363 | return res; |
| 2364 | } |
| 2365 | |
| 2366 | VkResult loader_GetPhysicalDeviceMemoryProperties ( |
| 2367 | VkPhysicalDevice gpu, |
| 2368 | VkPhysicalDeviceMemoryProperties* pProperties) |
| 2369 | { |
| 2370 | uint32_t gpu_index; |
| 2371 | struct loader_icd *icd = loader_get_icd(gpu, &gpu_index); |
| 2372 | VkResult res = VK_ERROR_INITIALIZATION_FAILED; |
| 2373 | |
| 2374 | if (icd->GetPhysicalDeviceMemoryProperties) |
| 2375 | res = icd->GetPhysicalDeviceMemoryProperties(gpu, pProperties); |
Jon Ashburn | 3da71f2 | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 2376 | |
| 2377 | return res; |
| 2378 | } |
| 2379 | |
Chris Forbes | bc0bb77 | 2015-06-21 22:55:02 +1200 | [diff] [blame] | 2380 | VkResult loader_GetPhysicalDeviceFeatures( |
| 2381 | VkPhysicalDevice physicalDevice, |
| 2382 | VkPhysicalDeviceFeatures* pFeatures) |
| 2383 | { |
| 2384 | uint32_t gpu_index; |
| 2385 | struct loader_icd *icd = loader_get_icd(physicalDevice, &gpu_index); |
| 2386 | VkResult res = VK_ERROR_INITIALIZATION_FAILED; |
| 2387 | |
| 2388 | if (icd->GetPhysicalDeviceFeatures) |
| 2389 | res = icd->GetPhysicalDeviceFeatures(physicalDevice, pFeatures); |
| 2390 | |
| 2391 | return res; |
| 2392 | } |
| 2393 | |
| 2394 | VkResult loader_GetPhysicalDeviceFormatInfo( |
| 2395 | VkPhysicalDevice physicalDevice, |
| 2396 | VkFormat format, |
| 2397 | VkFormatProperties* pFormatInfo) |
| 2398 | { |
| 2399 | uint32_t gpu_index; |
| 2400 | struct loader_icd *icd = loader_get_icd(physicalDevice, &gpu_index); |
| 2401 | VkResult res = VK_ERROR_INITIALIZATION_FAILED; |
| 2402 | |
| 2403 | if (icd->GetPhysicalDeviceFormatInfo) |
| 2404 | res = icd->GetPhysicalDeviceFormatInfo(physicalDevice, format, pFormatInfo); |
| 2405 | |
| 2406 | return res; |
| 2407 | } |
| 2408 | |
| 2409 | VkResult loader_GetPhysicalDeviceLimits( |
| 2410 | VkPhysicalDevice physicalDevice, |
| 2411 | VkPhysicalDeviceLimits* pLimits) |
| 2412 | { |
| 2413 | uint32_t gpu_index; |
| 2414 | struct loader_icd *icd = loader_get_icd(physicalDevice, &gpu_index); |
| 2415 | VkResult res = VK_ERROR_INITIALIZATION_FAILED; |
| 2416 | |
| 2417 | if (icd->GetPhysicalDeviceLimits) |
| 2418 | res = icd->GetPhysicalDeviceLimits(physicalDevice, pLimits); |
| 2419 | |
| 2420 | return res; |
| 2421 | } |
| 2422 | |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 2423 | VkResult loader_CreateDevice( |
| 2424 | VkPhysicalDevice gpu, |
| 2425 | const VkDeviceCreateInfo* pCreateInfo, |
| 2426 | VkDevice* pDevice) |
| 2427 | { |
| 2428 | uint32_t gpu_index; |
Jon Ashburn | 128f942 | 2015-05-28 19:16:58 -0600 | [diff] [blame] | 2429 | struct loader_icd *icd = loader_get_icd(gpu, &gpu_index); |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 2430 | struct loader_device *dev; |
Courtney Goeltzenleuchter | ca173b8 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 2431 | VkResult res; |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 2432 | |
Courtney Goeltzenleuchter | ca173b8 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 2433 | if (!icd->CreateDevice) { |
| 2434 | return VK_ERROR_INITIALIZATION_FAILED; |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 2435 | } |
| 2436 | |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 2437 | /* |
| 2438 | * TODO: Must filter CreateInfo extension list to only |
| 2439 | * those extensions supported by the ICD. |
| 2440 | * TODO: Probably should verify that every extension is |
| 2441 | * covered by either the ICD or some layer. |
| 2442 | */ |
| 2443 | |
Courtney Goeltzenleuchter | ca173b8 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 2444 | res = icd->CreateDevice(gpu, pCreateInfo, pDevice); |
| 2445 | if (res != VK_SUCCESS) { |
| 2446 | return res; |
| 2447 | } |
| 2448 | |
| 2449 | dev = loader_add_logical_device(*pDevice, &icd->logical_device_list); |
| 2450 | if (dev == NULL) { |
| 2451 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 2452 | } |
| 2453 | PFN_vkGetDeviceProcAddr get_proc_addr = icd->GetDeviceProcAddr; |
| 2454 | loader_init_device_dispatch_table(&dev->loader_dispatch, get_proc_addr, |
| 2455 | icd->gpus[gpu_index], icd->gpus[gpu_index]); |
| 2456 | |
| 2457 | dev->loader_dispatch.CreateDevice = scratch_vkCreateDevice; |
| 2458 | loader_init_dispatch(*pDevice, &dev->loader_dispatch); |
| 2459 | |
Courtney Goeltzenleuchter | ca173b8 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 2460 | /* |
| 2461 | * Put together the complete list of extensions to enable |
| 2462 | * This includes extensions requested via environment variables. |
| 2463 | */ |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 2464 | loader_enable_device_layers(dev, pCreateInfo); |
Courtney Goeltzenleuchter | ca173b8 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 2465 | |
| 2466 | /* |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 2467 | * Load the libraries and build the device chain |
Courtney Goeltzenleuchter | ca173b8 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 2468 | * terminating with the selected device. |
| 2469 | */ |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 2470 | loader_activate_device_layers(gpu, *pDevice, dev, icd); |
Courtney Goeltzenleuchter | ca173b8 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 2471 | |
| 2472 | res = dev->loader_dispatch.CreateDevice(gpu, pCreateInfo, pDevice); |
| 2473 | |
| 2474 | dev->loader_dispatch.CreateDevice = icd->CreateDevice; |
| 2475 | |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 2476 | return res; |
| 2477 | } |
| 2478 | |
Courtney Goeltzenleuchter | 9ec39ac | 2015-06-22 17:45:21 -0600 | [diff] [blame] | 2479 | static void * VKAPI loader_GetInstanceProcAddr(VkInstance instance, const char * pName) |
Jon Ashburn | b0fbe91 | 2015-05-06 10:15:07 -0600 | [diff] [blame] | 2480 | { |
Jon Ashburn | 07daee7 | 2015-05-21 18:13:33 -0600 | [diff] [blame] | 2481 | if (instance == VK_NULL_HANDLE) |
| 2482 | return NULL; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 2483 | |
Jon Ashburn | 07daee7 | 2015-05-21 18:13:33 -0600 | [diff] [blame] | 2484 | void *addr; |
| 2485 | /* get entrypoint addresses that are global (in the loader)*/ |
| 2486 | addr = globalGetProcAddr(pName); |
| 2487 | if (addr) |
| 2488 | return addr; |
Jon Ashburn | b0fbe91 | 2015-05-06 10:15:07 -0600 | [diff] [blame] | 2489 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 2490 | struct loader_instance *ptr_instance = (struct loader_instance *) instance; |
| 2491 | |
Jon Ashburn | 922c8f6 | 2015-06-18 09:05:37 -0600 | [diff] [blame] | 2492 | /* return any extension global entrypoints */ |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 2493 | addr = debug_report_instance_gpa(ptr_instance, pName); |
| 2494 | if (addr) { |
| 2495 | return addr; |
| 2496 | } |
| 2497 | |
Jon Ashburn | 922c8f6 | 2015-06-18 09:05:37 -0600 | [diff] [blame] | 2498 | /* TODO Remove this once WSI has no loader special code */ |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 2499 | addr = wsi_lunarg_GetInstanceProcAddr(instance, pName); |
David Pinedo | a0a8a24 | 2015-06-24 15:29:18 -0600 | [diff] [blame] | 2500 | if (addr) { |
Jon Ashburn | 922c8f6 | 2015-06-18 09:05:37 -0600 | [diff] [blame] | 2501 | return addr; |
David Pinedo | a0a8a24 | 2015-06-24 15:29:18 -0600 | [diff] [blame] | 2502 | } |
Jon Ashburn | 07daee7 | 2015-05-21 18:13:33 -0600 | [diff] [blame] | 2503 | |
| 2504 | /* return the instance dispatch table entrypoint for extensions */ |
| 2505 | const VkLayerInstanceDispatchTable *disp_table = * (VkLayerInstanceDispatchTable **) instance; |
| 2506 | if (disp_table == NULL) |
| 2507 | return NULL; |
| 2508 | |
| 2509 | addr = loader_lookup_instance_dispatch_table(disp_table, pName); |
| 2510 | if (addr) |
| 2511 | return addr; |
Jon Ashburn | b0fbe91 | 2015-05-06 10:15:07 -0600 | [diff] [blame] | 2512 | |
| 2513 | return NULL; |
| 2514 | } |
| 2515 | |
Courtney Goeltzenleuchter | 9ec39ac | 2015-06-22 17:45:21 -0600 | [diff] [blame] | 2516 | LOADER_EXPORT void * VKAPI vkGetInstanceProcAddr(VkInstance instance, const char * pName) |
| 2517 | { |
| 2518 | return loader_GetInstanceProcAddr(instance, pName); |
| 2519 | } |
| 2520 | |
| 2521 | static void * VKAPI loader_GetDeviceProcAddr(VkDevice device, const char * pName) |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 2522 | { |
Jon Ashburn | 8d1b0b5 | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 2523 | if (device == VK_NULL_HANDLE) { |
| 2524 | return NULL; |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 2525 | } |
Jon Ashburn | 3d526cb | 2015-04-13 18:10:06 -0600 | [diff] [blame] | 2526 | |
Chia-I Wu | f46b81a | 2015-01-04 11:12:47 +0800 | [diff] [blame] | 2527 | void *addr; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 2528 | |
Jon Ashburn | 3d526cb | 2015-04-13 18:10:06 -0600 | [diff] [blame] | 2529 | /* for entrypoints that loader must handle (ie non-dispatchable or create object) |
| 2530 | make sure the loader entrypoint is returned */ |
| 2531 | addr = loader_non_passthrough_gpa(pName); |
Ian Elliott | e19c915 | 2015-04-15 12:53:19 -0600 | [diff] [blame] | 2532 | if (addr) { |
Jon Ashburn | 3d526cb | 2015-04-13 18:10:06 -0600 | [diff] [blame] | 2533 | return addr; |
Ian Elliott | e19c915 | 2015-04-15 12:53:19 -0600 | [diff] [blame] | 2534 | } |
Jon Ashburn | 3d526cb | 2015-04-13 18:10:06 -0600 | [diff] [blame] | 2535 | |
Jon Ashburn | 07daee7 | 2015-05-21 18:13:33 -0600 | [diff] [blame] | 2536 | /* return any extension device entrypoints the loader knows about */ |
Jon Ashburn | 922c8f6 | 2015-06-18 09:05:37 -0600 | [diff] [blame] | 2537 | /* TODO once WSI has no loader special code remove this */ |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 2538 | addr = wsi_lunarg_GetDeviceProcAddr(device, pName); |
David Pinedo | a0a8a24 | 2015-06-24 15:29:18 -0600 | [diff] [blame] | 2539 | if (addr) { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 2540 | return addr; |
David Pinedo | a0a8a24 | 2015-06-24 15:29:18 -0600 | [diff] [blame] | 2541 | } |
Jon Ashburn | 07daee7 | 2015-05-21 18:13:33 -0600 | [diff] [blame] | 2542 | |
Jon Ashburn | 3d526cb | 2015-04-13 18:10:06 -0600 | [diff] [blame] | 2543 | /* return the dispatch table entrypoint for the fastest case */ |
Jon Ashburn | 8d1b0b5 | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 2544 | const VkLayerDispatchTable *disp_table = * (VkLayerDispatchTable **) device; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 2545 | if (disp_table == NULL) |
| 2546 | return NULL; |
| 2547 | |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 2548 | addr = loader_lookup_device_dispatch_table(disp_table, pName); |
Chia-I Wu | f46b81a | 2015-01-04 11:12:47 +0800 | [diff] [blame] | 2549 | if (addr) |
| 2550 | return addr; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 2551 | else { |
Jon Ashburn | 8d1b0b5 | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 2552 | if (disp_table->GetDeviceProcAddr == NULL) |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 2553 | return NULL; |
Jon Ashburn | 8d1b0b5 | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 2554 | return disp_table->GetDeviceProcAddr(device, pName); |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 2555 | } |
| 2556 | } |
| 2557 | |
Courtney Goeltzenleuchter | 9ec39ac | 2015-06-22 17:45:21 -0600 | [diff] [blame] | 2558 | LOADER_EXPORT void * VKAPI vkGetDeviceProcAddr(VkDevice device, const char * pName) |
| 2559 | { |
| 2560 | return loader_GetDeviceProcAddr(device, pName); |
| 2561 | } |
| 2562 | |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 2563 | LOADER_EXPORT VkResult VKAPI vkGetGlobalExtensionProperties( |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 2564 | const char* pLayerName, |
| 2565 | uint32_t* pCount, |
| 2566 | VkExtensionProperties* pProperties) |
| 2567 | { |
| 2568 | struct loader_extension_list *global_extension_list; |
| 2569 | |
| 2570 | /* Scan/discover all ICD libraries in a single-threaded manner */ |
| 2571 | loader_platform_thread_once(&once_icd, loader_icd_scan); |
| 2572 | |
| 2573 | /* get layer libraries in a single-threaded manner */ |
| 2574 | loader_platform_thread_once(&once_layer, loader_layer_scan); |
| 2575 | |
| 2576 | /* merge any duplicate extensions */ |
| 2577 | loader_platform_thread_once(&once_exts, loader_coalesce_extensions); |
| 2578 | |
| 2579 | uint32_t copy_size; |
| 2580 | |
| 2581 | if (pCount == NULL) { |
| 2582 | return VK_ERROR_INVALID_POINTER; |
| 2583 | } |
| 2584 | |
| 2585 | loader_platform_thread_lock_mutex(&loader_lock); |
| 2586 | |
| 2587 | global_extension_list = loader_global_extensions(pLayerName); |
| 2588 | if (global_extension_list == NULL) { |
| 2589 | loader_platform_thread_unlock_mutex(&loader_lock); |
| 2590 | return VK_ERROR_INVALID_LAYER; |
| 2591 | } |
| 2592 | |
| 2593 | if (pProperties == NULL) { |
| 2594 | *pCount = global_extension_list->count; |
| 2595 | loader_platform_thread_unlock_mutex(&loader_lock); |
| 2596 | return VK_SUCCESS; |
| 2597 | } |
| 2598 | |
| 2599 | copy_size = *pCount < global_extension_list->count ? *pCount : global_extension_list->count; |
| 2600 | for (uint32_t i = 0; i < copy_size; i++) { |
| 2601 | memcpy(&pProperties[i], |
| 2602 | &global_extension_list->list[i].info, |
| 2603 | sizeof(VkExtensionProperties)); |
| 2604 | } |
| 2605 | *pCount = copy_size; |
| 2606 | |
| 2607 | loader_platform_thread_unlock_mutex(&loader_lock); |
| 2608 | |
| 2609 | if (copy_size < global_extension_list->count) { |
| 2610 | return VK_INCOMPLETE; |
| 2611 | } |
| 2612 | |
| 2613 | return VK_SUCCESS; |
| 2614 | } |
| 2615 | |
| 2616 | LOADER_EXPORT VkResult VKAPI vkGetGlobalLayerProperties( |
| 2617 | uint32_t* pCount, |
| 2618 | VkLayerProperties* pProperties) |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 2619 | { |
Jon Ashburn | 6301a0f | 2015-05-29 13:15:39 -0600 | [diff] [blame] | 2620 | |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 2621 | /* Scan/discover all ICD libraries in a single-threaded manner */ |
| 2622 | loader_platform_thread_once(&once_icd, loader_icd_scan); |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 2623 | |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 2624 | /* get layer libraries in a single-threaded manner */ |
Jon Ashburn | 5ef2060 | 2015-07-02 09:40:15 -0600 | [diff] [blame] | 2625 | loader_platform_thread_once(&once_layer, loader_layer_scan); |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 2626 | |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 2627 | /* merge any duplicate extensions */ |
| 2628 | loader_platform_thread_once(&once_exts, loader_coalesce_extensions); |
| 2629 | |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 2630 | uint32_t copy_size; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 2631 | |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 2632 | if (pCount == NULL) { |
| 2633 | return VK_ERROR_INVALID_POINTER; |
| 2634 | } |
| 2635 | |
| 2636 | /* TODO: do we still need to lock */ |
Jon Ashburn | 6301a0f | 2015-05-29 13:15:39 -0600 | [diff] [blame] | 2637 | loader_platform_thread_lock_mutex(&loader_lock); |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 2638 | |
| 2639 | struct loader_layer_list *layer_list; |
| 2640 | layer_list = loader_global_layers(); |
| 2641 | |
| 2642 | if (pProperties == NULL) { |
| 2643 | *pCount = layer_list->count; |
| 2644 | loader_platform_thread_unlock_mutex(&loader_lock); |
| 2645 | return VK_SUCCESS; |
| 2646 | } |
| 2647 | |
| 2648 | copy_size = *pCount < layer_list->count ? *pCount : layer_list->count; |
| 2649 | for (uint32_t i = 0; i < copy_size; i++) { |
| 2650 | memcpy(&pProperties[i], &layer_list->list[i].info, sizeof(VkLayerProperties)); |
| 2651 | } |
| 2652 | *pCount = copy_size; |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 2653 | |
Jon Ashburn | 6301a0f | 2015-05-29 13:15:39 -0600 | [diff] [blame] | 2654 | loader_platform_thread_unlock_mutex(&loader_lock); |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 2655 | |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 2656 | if (copy_size < layer_list->count) { |
| 2657 | return VK_INCOMPLETE; |
| 2658 | } |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 2659 | |
| 2660 | return VK_SUCCESS; |
| 2661 | } |
| 2662 | |
| 2663 | VkResult loader_GetPhysicalDeviceExtensionProperties( |
| 2664 | VkPhysicalDevice gpu, |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 2665 | const char* pLayerName, |
| 2666 | uint32_t* pCount, |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 2667 | VkExtensionProperties* pProperties) |
| 2668 | { |
| 2669 | uint32_t gpu_index; |
Jon Ashburn | 128f942 | 2015-05-28 19:16:58 -0600 | [diff] [blame] | 2670 | struct loader_icd *icd = loader_get_icd(gpu, &gpu_index); |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 2671 | uint32_t copy_size; |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 2672 | |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 2673 | if (pCount == NULL) { |
| 2674 | return VK_ERROR_INVALID_POINTER; |
| 2675 | } |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 2676 | |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 2677 | uint32_t count; |
| 2678 | struct loader_extension_list *list; |
| 2679 | loader_physical_device_extensions(icd, gpu_index, pLayerName, &count, &list); |
| 2680 | |
| 2681 | if (pProperties == NULL) { |
| 2682 | *pCount = count; |
| 2683 | return VK_SUCCESS; |
| 2684 | } |
| 2685 | |
| 2686 | copy_size = *pCount < count ? *pCount : count; |
| 2687 | for (uint32_t i = 0; i < copy_size; i++) { |
| 2688 | memcpy(&pProperties[i], |
| 2689 | &list->list[i].info, |
| 2690 | sizeof(VkExtensionProperties)); |
| 2691 | } |
| 2692 | *pCount = copy_size; |
| 2693 | |
| 2694 | if (copy_size < count) { |
| 2695 | return VK_INCOMPLETE; |
| 2696 | } |
| 2697 | |
| 2698 | return VK_SUCCESS; |
| 2699 | } |
| 2700 | |
| 2701 | VkResult loader_GetPhysicalDeviceLayerProperties( |
| 2702 | VkPhysicalDevice gpu, |
| 2703 | uint32_t* pCount, |
| 2704 | VkLayerProperties* pProperties) |
| 2705 | { |
| 2706 | uint32_t gpu_index; |
| 2707 | struct loader_icd *icd = loader_get_icd(gpu, &gpu_index); |
| 2708 | uint32_t copy_size; |
| 2709 | |
| 2710 | if (pCount == NULL) { |
| 2711 | return VK_ERROR_INVALID_POINTER; |
| 2712 | } |
| 2713 | |
| 2714 | uint32_t count; |
| 2715 | struct loader_layer_list *layer_list; |
| 2716 | loader_physical_device_layers(icd, &count, &layer_list); |
| 2717 | |
| 2718 | if (pProperties == NULL) { |
| 2719 | *pCount = count; |
| 2720 | return VK_SUCCESS; |
| 2721 | } |
| 2722 | |
| 2723 | copy_size = *pCount < count ? *pCount : count; |
| 2724 | for (uint32_t i = 0; i < copy_size; i++) { |
| 2725 | memcpy(&pProperties[i], |
| 2726 | &layer_list->list[i].info, |
| 2727 | sizeof(VkLayerProperties)); |
| 2728 | } |
| 2729 | *pCount = copy_size; |
| 2730 | |
| 2731 | if (copy_size < count) { |
| 2732 | return VK_INCOMPLETE; |
| 2733 | } |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 2734 | |
| 2735 | return VK_SUCCESS; |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 2736 | } |