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