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