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