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