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