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