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