Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1 | /* |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 2 | * |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3 | * Copyright (c) 2014-2016 The Khronos Group Inc. |
| 4 | * Copyright (c) 2014-2016 Valve Corporation |
| 5 | * Copyright (c) 2014-2016 LunarG, Inc. |
Courtney Goeltzenleuchter | ebbb96d | 2015-12-02 14:53:22 -0700 | [diff] [blame] | 6 | * Copyright (C) 2015 Google Inc. |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 7 | * |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 9 | * of this software and/or associated documentation files (the "Materials"), to |
| 10 | * deal in the Materials without restriction, including without limitation the |
| 11 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 12 | * sell copies of the Materials, and to permit persons to whom the Materials are |
| 13 | * furnished to do so, subject to the following conditions: |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 14 | * |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 15 | * The above copyright notice(s) and this permission notice shall be included in |
| 16 | * all copies or substantial portions of the Materials. |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 17 | * |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 18 | * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
Chia-I Wu | 44e4236 | 2014-09-02 08:32:09 +0800 | [diff] [blame] | 21 | * |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 22 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
| 23 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
| 24 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE |
| 25 | * USE OR OTHER DEALINGS IN THE MATERIALS. |
| 26 | * |
Courtney Goeltzenleuchter | 96cd795 | 2015-10-30 11:14:30 -0600 | [diff] [blame] | 27 | * Author: Jon Ashburn <jon@lunarg.com> |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 28 | * Author: Courtney Goeltzenleuchter <courtney@LunarG.com> |
Courtney Goeltzenleuchter | 96cd795 | 2015-10-30 11:14:30 -0600 | [diff] [blame] | 29 | * |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 30 | */ |
Mark Lobodzinski | 28214d9 | 2015-11-25 13:26:15 -0700 | [diff] [blame] | 31 | |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 32 | #define _GNU_SOURCE |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 33 | #include <stdio.h> |
| 34 | #include <stdlib.h> |
| 35 | #include <stdarg.h> |
| 36 | #include <stdbool.h> |
| 37 | #include <string.h> |
| 38 | |
Chia-I Wu | 894a117 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 39 | #include <sys/types.h> |
Johannes van Waveren | a6ce7b7 | 2015-10-28 11:45:00 -0500 | [diff] [blame] | 40 | #if defined(_WIN32) |
Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 41 | #include "dirent_on_windows.h" |
Johannes van Waveren | a6ce7b7 | 2015-10-28 11:45:00 -0500 | [diff] [blame] | 42 | #else // _WIN32 |
Chia-I Wu | 894a117 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 43 | #include <dirent.h> |
Johannes van Waveren | a6ce7b7 | 2015-10-28 11:45:00 -0500 | [diff] [blame] | 44 | #endif // _WIN32 |
Tobin Ehlis | 7a51d90 | 2015-07-03 10:34:49 -0600 | [diff] [blame] | 45 | #include "vk_loader_platform.h" |
Chia-I Wu | 468e3c3 | 2014-08-04 08:03:57 +0800 | [diff] [blame] | 46 | #include "loader.h" |
Jon Ashburn | fce93d9 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 47 | #include "gpa_helper.h" |
| 48 | #include "table_ops.h" |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 49 | #include "debug_report.h" |
Ian Elliott | a81e8ac | 2015-10-30 15:28:23 -0600 | [diff] [blame] | 50 | #include "wsi.h" |
David Pinedo | 329ca9e | 2015-11-06 12:54:48 -0700 | [diff] [blame] | 51 | #include "vulkan/vk_icd.h" |
Jon Ashburn | ffd5d67 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 52 | #include "cJSON.h" |
Jon Ashburn | 429e19f | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 53 | #include "murmurhash.h" |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 54 | |
Jon Ashburn | 7f7fea8 | 2016-04-04 13:52:53 -0600 | [diff] [blame] | 55 | #if defined(__GNUC__) |
Jon Ashburn | 9b2a8c9 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 56 | #if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 17) |
| 57 | #define secure_getenv __secure_getenv |
| 58 | #endif |
Jon Ashburn | 7f7fea8 | 2016-04-04 13:52:53 -0600 | [diff] [blame] | 59 | #endif |
| 60 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 61 | static loader_platform_dl_handle |
| 62 | loader_add_layer_lib(const struct loader_instance *inst, const char *chain_type, |
| 63 | struct loader_layer_properties *layer_prop); |
Courtney Goeltzenleuchter | 71cd74d | 2015-06-01 14:09:34 -0600 | [diff] [blame] | 64 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 65 | static void loader_remove_layer_lib(struct loader_instance *inst, |
| 66 | struct loader_layer_properties *layer_prop); |
Courtney Goeltzenleuchter | 71cd74d | 2015-06-01 14:09:34 -0600 | [diff] [blame] | 67 | |
Jon Ashburn | fce93d9 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 68 | struct loader_struct loader = {0}; |
Jon Ashburn | 413d658 | 2015-08-28 15:19:27 -0600 | [diff] [blame] | 69 | // TLS for instance for alloc/free callbacks |
| 70 | THREAD_LOCAL_DECL struct loader_instance *tls_instance; |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 71 | |
Courtney Goeltzenleuchter | e728d12 | 2015-12-16 16:19:46 -0700 | [diff] [blame] | 72 | static size_t loader_platform_combine_path(char *dest, size_t len, ...); |
Daniel Dadap | 2e13fca | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 73 | |
Jon Ashburn | 251258f | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 74 | struct loader_phys_dev_per_icd { |
| 75 | uint32_t count; |
| 76 | VkPhysicalDevice *phys_devs; |
Jon Ashburn | 8766043 | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 77 | struct loader_icd *this_icd; |
Jon Ashburn | 251258f | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 78 | }; |
| 79 | |
Courtney Goeltzenleuchter | 8b253f9 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 80 | enum loader_debug { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 81 | LOADER_INFO_BIT = 0x01, |
| 82 | LOADER_WARN_BIT = 0x02, |
| 83 | LOADER_PERF_BIT = 0x04, |
| 84 | LOADER_ERROR_BIT = 0x08, |
| 85 | LOADER_DEBUG_BIT = 0x10, |
Courtney Goeltzenleuchter | 8b253f9 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 86 | }; |
| 87 | |
| 88 | uint32_t g_loader_debug = 0; |
| 89 | uint32_t g_loader_log_msgs = 0; |
| 90 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 91 | // thread safety lock for accessing global data structures such as "loader" |
Jon Ashburn | b40f256 | 2015-05-29 13:15:39 -0600 | [diff] [blame] | 92 | // all entrypoints on the instance chain need to be locked except GPA |
Jon Ashburn | ffd5d67 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 93 | // additionally CreateDevice and DestroyDevice needs to be locked |
Jon Ashburn | b40f256 | 2015-05-29 13:15:39 -0600 | [diff] [blame] | 94 | loader_platform_thread_mutex loader_lock; |
Jon Ashburn | d02fc2c | 2015-09-22 13:11:00 -0600 | [diff] [blame] | 95 | loader_platform_thread_mutex loader_json_lock; |
Jon Ashburn | b40f256 | 2015-05-29 13:15:39 -0600 | [diff] [blame] | 96 | |
Jon Ashburn | 715de58 | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 97 | const char *std_validation_str = "VK_LAYER_LUNARG_standard_validation"; |
| 98 | |
Ian Elliott | 1d73e66 | 2015-07-06 14:36:13 -0600 | [diff] [blame] | 99 | // This table contains the loader's instance dispatch table, which contains |
| 100 | // default functions if no instance layers are activated. This contains |
| 101 | // pointers to "terminator functions". |
Jon Ashburn | b40f256 | 2015-05-29 13:15:39 -0600 | [diff] [blame] | 102 | const VkLayerInstanceDispatchTable instance_disp = { |
Jon Ashburn | 8aa75cb | 2015-09-28 16:15:00 -0600 | [diff] [blame] | 103 | .GetInstanceProcAddr = vkGetInstanceProcAddr, |
Jon Ashburn | a9c4a57 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 104 | .DestroyInstance = terminator_DestroyInstance, |
| 105 | .EnumeratePhysicalDevices = terminator_EnumeratePhysicalDevices, |
| 106 | .GetPhysicalDeviceFeatures = terminator_GetPhysicalDeviceFeatures, |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 107 | .GetPhysicalDeviceFormatProperties = |
Jon Ashburn | a9c4a57 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 108 | terminator_GetPhysicalDeviceFormatProperties, |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 109 | .GetPhysicalDeviceImageFormatProperties = |
Jon Ashburn | a9c4a57 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 110 | terminator_GetPhysicalDeviceImageFormatProperties, |
| 111 | .GetPhysicalDeviceProperties = terminator_GetPhysicalDeviceProperties, |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 112 | .GetPhysicalDeviceQueueFamilyProperties = |
Jon Ashburn | a9c4a57 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 113 | terminator_GetPhysicalDeviceQueueFamilyProperties, |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 114 | .GetPhysicalDeviceMemoryProperties = |
Jon Ashburn | a9c4a57 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 115 | terminator_GetPhysicalDeviceMemoryProperties, |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 116 | .EnumerateDeviceExtensionProperties = |
Jon Ashburn | a9c4a57 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 117 | terminator_EnumerateDeviceExtensionProperties, |
| 118 | .EnumerateDeviceLayerProperties = terminator_EnumerateDeviceLayerProperties, |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 119 | .GetPhysicalDeviceSparseImageFormatProperties = |
Jon Ashburn | a9c4a57 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 120 | terminator_GetPhysicalDeviceSparseImageFormatProperties, |
| 121 | .DestroySurfaceKHR = terminator_DestroySurfaceKHR, |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 122 | .GetPhysicalDeviceSurfaceSupportKHR = |
Jon Ashburn | a9c4a57 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 123 | terminator_GetPhysicalDeviceSurfaceSupportKHR, |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 124 | .GetPhysicalDeviceSurfaceCapabilitiesKHR = |
Jon Ashburn | a9c4a57 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 125 | terminator_GetPhysicalDeviceSurfaceCapabilitiesKHR, |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 126 | .GetPhysicalDeviceSurfaceFormatsKHR = |
Jon Ashburn | a9c4a57 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 127 | terminator_GetPhysicalDeviceSurfaceFormatsKHR, |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 128 | .GetPhysicalDeviceSurfacePresentModesKHR = |
Jon Ashburn | a9c4a57 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 129 | terminator_GetPhysicalDeviceSurfacePresentModesKHR, |
| 130 | .CreateDebugReportCallbackEXT = terminator_CreateDebugReportCallback, |
| 131 | .DestroyDebugReportCallbackEXT = terminator_DestroyDebugReportCallback, |
| 132 | .DebugReportMessageEXT = terminator_DebugReportMessage, |
Ian Elliott | 40c4a1f | 2015-11-23 10:17:23 -0700 | [diff] [blame] | 133 | #ifdef VK_USE_PLATFORM_MIR_KHR |
Jon Ashburn | a9c4a57 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 134 | .CreateMirSurfaceKHR = terminator_CreateMirSurfaceKHR, |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 135 | .GetPhysicalDeviceMirPresentationSupportKHR = |
Jon Ashburn | a9c4a57 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 136 | terminator_GetPhysicalDeviceMirPresentationSupportKHR, |
Ian Elliott | 40c4a1f | 2015-11-23 10:17:23 -0700 | [diff] [blame] | 137 | #endif |
| 138 | #ifdef VK_USE_PLATFORM_WAYLAND_KHR |
Jon Ashburn | a9c4a57 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 139 | .CreateWaylandSurfaceKHR = terminator_CreateWaylandSurfaceKHR, |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 140 | .GetPhysicalDeviceWaylandPresentationSupportKHR = |
Jon Ashburn | a9c4a57 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 141 | terminator_GetPhysicalDeviceWaylandPresentationSupportKHR, |
Ian Elliott | 40c4a1f | 2015-11-23 10:17:23 -0700 | [diff] [blame] | 142 | #endif |
| 143 | #ifdef VK_USE_PLATFORM_WIN32_KHR |
Jon Ashburn | a9c4a57 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 144 | .CreateWin32SurfaceKHR = terminator_CreateWin32SurfaceKHR, |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 145 | .GetPhysicalDeviceWin32PresentationSupportKHR = |
Jon Ashburn | a9c4a57 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 146 | terminator_GetPhysicalDeviceWin32PresentationSupportKHR, |
Ian Elliott | 40c4a1f | 2015-11-23 10:17:23 -0700 | [diff] [blame] | 147 | #endif |
| 148 | #ifdef VK_USE_PLATFORM_XCB_KHR |
Jon Ashburn | a9c4a57 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 149 | .CreateXcbSurfaceKHR = terminator_CreateXcbSurfaceKHR, |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 150 | .GetPhysicalDeviceXcbPresentationSupportKHR = |
Jon Ashburn | a9c4a57 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 151 | terminator_GetPhysicalDeviceXcbPresentationSupportKHR, |
Ian Elliott | 40c4a1f | 2015-11-23 10:17:23 -0700 | [diff] [blame] | 152 | #endif |
| 153 | #ifdef VK_USE_PLATFORM_XLIB_KHR |
Jon Ashburn | a9c4a57 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 154 | .CreateXlibSurfaceKHR = terminator_CreateXlibSurfaceKHR, |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 155 | .GetPhysicalDeviceXlibPresentationSupportKHR = |
Jon Ashburn | a9c4a57 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 156 | terminator_GetPhysicalDeviceXlibPresentationSupportKHR, |
Ian Elliott | 40c4a1f | 2015-11-23 10:17:23 -0700 | [diff] [blame] | 157 | #endif |
Mark Lobodzinski | b3e934d | 2015-12-10 16:25:21 -0700 | [diff] [blame] | 158 | #ifdef VK_USE_PLATFORM_ANDROID_KHR |
Jon Ashburn | a9c4a57 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 159 | .CreateAndroidSurfaceKHR = terminator_CreateAndroidSurfaceKHR, |
Mark Lobodzinski | b3e934d | 2015-12-10 16:25:21 -0700 | [diff] [blame] | 160 | #endif |
Jon Ashburn | 00df045 | 2016-03-08 09:30:30 -0700 | [diff] [blame] | 161 | .GetPhysicalDeviceDisplayPropertiesKHR = |
| 162 | terminator_GetPhysicalDeviceDisplayPropertiesKHR, |
| 163 | .GetPhysicalDeviceDisplayPlanePropertiesKHR = |
| 164 | terminator_GetPhysicalDeviceDisplayPlanePropertiesKHR, |
| 165 | .GetDisplayPlaneSupportedDisplaysKHR = |
| 166 | terminator_GetDisplayPlaneSupportedDisplaysKHR, |
Jon Ashburn | 9b2a8c9 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 167 | .GetDisplayModePropertiesKHR = terminator_GetDisplayModePropertiesKHR, |
| 168 | .CreateDisplayModeKHR = terminator_CreateDisplayModeKHR, |
| 169 | .GetDisplayPlaneCapabilitiesKHR = terminator_GetDisplayPlaneCapabilitiesKHR, |
| 170 | .CreateDisplayPlaneSurfaceKHR = terminator_CreateDisplayPlaneSurfaceKHR, |
Jon Ashburn | fce93d9 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 171 | }; |
| 172 | |
Jon Ashburn | 754f199 | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 173 | LOADER_PLATFORM_THREAD_ONCE_DECLARATION(once_init); |
Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 174 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 175 | void *loader_heap_alloc(const struct loader_instance *instance, size_t size, |
| 176 | VkSystemAllocationScope alloc_scope) { |
Chia-I Wu | 1f85191 | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 177 | if (instance && instance->alloc_callbacks.pfnAllocation) { |
Courtney Goeltzenleuchter | b620ace | 2015-07-05 11:28:29 -0600 | [diff] [blame] | 178 | /* TODO: What should default alignment be? 1, 4, 8, other? */ |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 179 | return instance->alloc_callbacks.pfnAllocation( |
| 180 | instance->alloc_callbacks.pUserData, size, sizeof(int), |
| 181 | alloc_scope); |
Courtney Goeltzenleuchter | b620ace | 2015-07-05 11:28:29 -0600 | [diff] [blame] | 182 | } |
| 183 | return malloc(size); |
| 184 | } |
| 185 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 186 | void loader_heap_free(const struct loader_instance *instance, void *pMemory) { |
| 187 | if (pMemory == NULL) |
| 188 | return; |
Jon Ashburn | cfe4e68 | 2015-08-14 12:51:47 -0600 | [diff] [blame] | 189 | if (instance && instance->alloc_callbacks.pfnFree) { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 190 | instance->alloc_callbacks.pfnFree(instance->alloc_callbacks.pUserData, |
| 191 | pMemory); |
Jon Ashburn | fab6ee2 | 2015-08-13 08:28:48 -0600 | [diff] [blame] | 192 | return; |
Courtney Goeltzenleuchter | b620ace | 2015-07-05 11:28:29 -0600 | [diff] [blame] | 193 | } |
Chia-I Wu | 1f85191 | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 194 | free(pMemory); |
Courtney Goeltzenleuchter | b620ace | 2015-07-05 11:28:29 -0600 | [diff] [blame] | 195 | } |
| 196 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 197 | void *loader_heap_realloc(const struct loader_instance *instance, void *pMemory, |
| 198 | size_t orig_size, size_t size, |
| 199 | VkSystemAllocationScope alloc_scope) { |
| 200 | if (pMemory == NULL || orig_size == 0) |
Chia-I Wu | 69f4012 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 201 | return loader_heap_alloc(instance, size, alloc_scope); |
Jon Ashburn | e5e60df | 2015-08-27 15:23:52 -0600 | [diff] [blame] | 202 | if (size == 0) { |
Chia-I Wu | 1f85191 | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 203 | loader_heap_free(instance, pMemory); |
Jon Ashburn | e5e60df | 2015-08-27 15:23:52 -0600 | [diff] [blame] | 204 | return NULL; |
| 205 | } |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 206 | // TODO use the callback realloc function |
Chia-I Wu | 1f85191 | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 207 | if (instance && instance->alloc_callbacks.pfnAllocation) { |
Jon Ashburn | e5e60df | 2015-08-27 15:23:52 -0600 | [diff] [blame] | 208 | if (size <= orig_size) { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 209 | memset(((uint8_t *)pMemory) + size, 0, orig_size - size); |
Chia-I Wu | 1f85191 | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 210 | return pMemory; |
Jon Ashburn | e5e60df | 2015-08-27 15:23:52 -0600 | [diff] [blame] | 211 | } |
Jon Ashburn | 9a3c2b4 | 2016-01-07 15:21:14 -0700 | [diff] [blame] | 212 | /* TODO: What should default alignment be? 1, 4, 8, other? */ |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 213 | void *new_ptr = instance->alloc_callbacks.pfnAllocation( |
| 214 | instance->alloc_callbacks.pUserData, size, sizeof(int), |
| 215 | alloc_scope); |
Jon Ashburn | e5e60df | 2015-08-27 15:23:52 -0600 | [diff] [blame] | 216 | if (!new_ptr) |
| 217 | return NULL; |
Chia-I Wu | 1f85191 | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 218 | memcpy(new_ptr, pMemory, orig_size); |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 219 | instance->alloc_callbacks.pfnFree(instance->alloc_callbacks.pUserData, |
| 220 | pMemory); |
Jon Ashburn | 3869266 | 2016-01-27 10:56:10 -0700 | [diff] [blame] | 221 | return new_ptr; |
Jon Ashburn | e5e60df | 2015-08-27 15:23:52 -0600 | [diff] [blame] | 222 | } |
Chia-I Wu | 1f85191 | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 223 | return realloc(pMemory, size); |
Jon Ashburn | e5e60df | 2015-08-27 15:23:52 -0600 | [diff] [blame] | 224 | } |
| 225 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 226 | void *loader_tls_heap_alloc(size_t size) { |
| 227 | return loader_heap_alloc(tls_instance, size, |
| 228 | VK_SYSTEM_ALLOCATION_SCOPE_COMMAND); |
Jon Ashburn | 413d658 | 2015-08-28 15:19:27 -0600 | [diff] [blame] | 229 | } |
| 230 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 231 | void loader_tls_heap_free(void *pMemory) { |
Chia-I Wu | 1f85191 | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 232 | loader_heap_free(tls_instance, pMemory); |
Jon Ashburn | 413d658 | 2015-08-28 15:19:27 -0600 | [diff] [blame] | 233 | } |
| 234 | |
Jon Ashburn | 7d1a53d | 2016-02-12 08:20:06 -0700 | [diff] [blame] | 235 | void loader_log(const struct loader_instance *inst, VkFlags msg_type, |
Jon Ashburn | a9c4a57 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 236 | int32_t msg_code, const char *format, ...) { |
Jon Ashburn | 2b77916 | 2015-07-31 15:47:59 -0600 | [diff] [blame] | 237 | char msg[512]; |
Jon Ashburn | ee33ae7 | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 238 | va_list ap; |
| 239 | int ret; |
| 240 | |
Jon Ashburn | ee33ae7 | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 241 | va_start(ap, format); |
| 242 | ret = vsnprintf(msg, sizeof(msg), format, ap); |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 243 | if ((ret >= (int)sizeof(msg)) || ret < 0) { |
| 244 | msg[sizeof(msg) - 1] = '\0'; |
Jon Ashburn | ee33ae7 | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 245 | } |
| 246 | va_end(ap); |
| 247 | |
Courtney Goeltzenleuchter | 05525da | 2015-12-03 13:48:01 -0700 | [diff] [blame] | 248 | if (inst) { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 249 | util_DebugReportMessage(inst, msg_type, |
| 250 | VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, |
| 251 | (uint64_t)inst, 0, msg_code, "loader", msg); |
Courtney Goeltzenleuchter | 05525da | 2015-12-03 13:48:01 -0700 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | if (!(msg_type & g_loader_log_msgs)) { |
| 255 | return; |
| 256 | } |
| 257 | |
Ian Elliott | 225188f | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 258 | #if defined(WIN32) |
Jon Ashburn | ee33ae7 | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 259 | OutputDebugString(msg); |
mschott | 632564c | 2015-07-22 14:11:29 +0200 | [diff] [blame] | 260 | OutputDebugString("\n"); |
Jon Ashburn | ee33ae7 | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 261 | #endif |
| 262 | fputs(msg, stderr); |
| 263 | fputc('\n', stderr); |
| 264 | } |
| 265 | |
Jon Ashburn | 9b2a8c9 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 266 | VKAPI_ATTR VkResult VKAPI_CALL |
| 267 | vkSetInstanceDispatch(VkInstance instance, void *object) { |
Jon Ashburn | 7ec8ec8 | 2016-03-29 11:16:01 -0600 | [diff] [blame] | 268 | |
| 269 | struct loader_instance *inst = loader_get_instance(instance); |
| 270 | if (!inst) { |
| 271 | return VK_ERROR_INITIALIZATION_FAILED; |
| 272 | } |
| 273 | loader_set_dispatch(object, inst->disp); |
| 274 | return VK_SUCCESS; |
| 275 | } |
| 276 | |
Jon Ashburn | 9b2a8c9 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 277 | VKAPI_ATTR VkResult VKAPI_CALL |
| 278 | vkSetDeviceDispatch(VkDevice device, void *object) { |
Jon Ashburn | 94d58ea | 2016-03-31 10:52:22 -0600 | [diff] [blame] | 279 | struct loader_device *dev; |
| 280 | struct loader_icd *icd = loader_get_icd_and_device(device, &dev); |
| 281 | |
| 282 | if (!icd) { |
| 283 | return VK_ERROR_INITIALIZATION_FAILED; |
| 284 | } |
| 285 | loader_set_dispatch(object, &dev->loader_dispatch); |
| 286 | return VK_SUCCESS; |
| 287 | } |
| 288 | |
Jon Ashburn | ee33ae7 | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 289 | #if defined(WIN32) |
Tony Barbour | 76096e6 | 2015-07-29 14:26:21 -0600 | [diff] [blame] | 290 | static char *loader_get_next_path(char *path); |
Jon Ashburn | ee33ae7 | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 291 | /** |
| 292 | * Find the list of registry files (names within a key) in key "location". |
| 293 | * |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 294 | * This function looks in the registry (hive = DEFAULT_VK_REGISTRY_HIVE) key as |
| 295 | *given in "location" |
| 296 | * for a list or name/values which are added to a returned list (function return |
| 297 | *value). |
Jon Ashburn | ee33ae7 | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 298 | * 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] | 299 | * Function return is a string with a ';' separated list of filenames. |
Jon Ashburn | ee33ae7 | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 300 | * Function return is NULL if no valid name/value pairs are found in the key, |
| 301 | * or the key is not found. |
| 302 | * |
| 303 | * \returns |
| 304 | * A string list of filenames as pointer. |
| 305 | * When done using the returned string list, pointer should be freed. |
| 306 | */ |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 307 | static char *loader_get_registry_files(const struct loader_instance *inst, |
| 308 | char *location) { |
Jon Ashburn | ee33ae7 | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 309 | LONG rtn_value; |
| 310 | HKEY hive, key; |
Piers Daniell | b1f6f6d | 2015-11-05 16:58:26 -0700 | [diff] [blame] | 311 | DWORD access_flags; |
Jon Ashburn | ee33ae7 | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 312 | char name[2048]; |
| 313 | char *out = NULL; |
Tony Barbour | 76096e6 | 2015-07-29 14:26:21 -0600 | [diff] [blame] | 314 | char *loc = location; |
| 315 | char *next; |
Jon Ashburn | ee33ae7 | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 316 | DWORD idx = 0; |
| 317 | DWORD name_size = sizeof(name); |
| 318 | DWORD value; |
| 319 | DWORD total_size = 4096; |
| 320 | DWORD value_size = sizeof(value); |
Tony Barbour | 76096e6 | 2015-07-29 14:26:21 -0600 | [diff] [blame] | 321 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 322 | while (*loc) { |
Tony Barbour | 76096e6 | 2015-07-29 14:26:21 -0600 | [diff] [blame] | 323 | next = loader_get_next_path(loc); |
| 324 | hive = DEFAULT_VK_REGISTRY_HIVE; |
Piers Daniell | b1f6f6d | 2015-11-05 16:58:26 -0700 | [diff] [blame] | 325 | access_flags = KEY_QUERY_VALUE; |
Tony Barbour | 76096e6 | 2015-07-29 14:26:21 -0600 | [diff] [blame] | 326 | rtn_value = RegOpenKeyEx(hive, loc, 0, access_flags, &key); |
| 327 | if (rtn_value != ERROR_SUCCESS) { |
Mark Young | 2acdd15 | 2016-01-13 13:47:16 -0700 | [diff] [blame] | 328 | // We still couldn't find the key, so give up: |
| 329 | loc = next; |
| 330 | continue; |
Jon Ashburn | ee33ae7 | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 331 | } |
Tony Barbour | 76096e6 | 2015-07-29 14:26:21 -0600 | [diff] [blame] | 332 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 333 | while ((rtn_value = RegEnumValue(key, idx++, name, &name_size, NULL, |
| 334 | NULL, (LPBYTE)&value, &value_size)) == |
| 335 | ERROR_SUCCESS) { |
Tony Barbour | 76096e6 | 2015-07-29 14:26:21 -0600 | [diff] [blame] | 336 | if (value_size == sizeof(value) && value == 0) { |
| 337 | if (out == NULL) { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 338 | out = loader_heap_alloc( |
| 339 | inst, total_size, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Tony Barbour | 76096e6 | 2015-07-29 14:26:21 -0600 | [diff] [blame] | 340 | out[0] = '\0'; |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 341 | } else if (strlen(out) + name_size + 1 > total_size) { |
| 342 | out = loader_heap_realloc( |
| 343 | inst, out, total_size, total_size * 2, |
| 344 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Tony Barbour | 76096e6 | 2015-07-29 14:26:21 -0600 | [diff] [blame] | 345 | total_size *= 2; |
| 346 | } |
| 347 | if (out == NULL) { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 348 | loader_log( |
| 349 | inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 350 | "Out of memory, failed loader_get_registry_files"); |
Tony Barbour | 76096e6 | 2015-07-29 14:26:21 -0600 | [diff] [blame] | 351 | return NULL; |
| 352 | } |
| 353 | if (strlen(out) == 0) |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 354 | snprintf(out, name_size + 1, "%s", name); |
Tony Barbour | 76096e6 | 2015-07-29 14:26:21 -0600 | [diff] [blame] | 355 | else |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 356 | snprintf(out + strlen(out), name_size + 2, "%c%s", |
| 357 | PATH_SEPERATOR, name); |
Tony Barbour | 76096e6 | 2015-07-29 14:26:21 -0600 | [diff] [blame] | 358 | } |
| 359 | name_size = 2048; |
| 360 | } |
| 361 | loc = next; |
Jon Ashburn | ee33ae7 | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 362 | } |
Tony Barbour | 76096e6 | 2015-07-29 14:26:21 -0600 | [diff] [blame] | 363 | |
Jon Ashburn | ee33ae7 | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 364 | return out; |
| 365 | } |
| 366 | |
Ian Elliott | 225188f | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 367 | #endif // WIN32 |
| 368 | |
Jon Ashburn | 4b7f35f | 2015-08-03 09:08:46 -0600 | [diff] [blame] | 369 | /** |
Daniel Dadap | 2e13fca | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 370 | * Combine path elements, separating each element with the platform-specific |
| 371 | * directory separator, and save the combined string to a destination buffer, |
| 372 | * not exceeding the given length. Path elements are given as variadic args, |
| 373 | * with a NULL element terminating the list. |
| 374 | * |
| 375 | * \returns the total length of the combined string, not including an ASCII |
| 376 | * NUL termination character. This length may exceed the available storage: |
| 377 | * in this case, the written string will be truncated to avoid a buffer |
| 378 | * overrun, and the return value will greater than or equal to the storage |
| 379 | * size. A NULL argument may be provided as the destination buffer in order |
| 380 | * to determine the required string length without actually writing a string. |
| 381 | */ |
| 382 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 383 | static size_t loader_platform_combine_path(char *dest, size_t len, ...) { |
Courtney Goeltzenleuchter | e728d12 | 2015-12-16 16:19:46 -0700 | [diff] [blame] | 384 | size_t required_len = 0; |
Daniel Dadap | 2e13fca | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 385 | va_list ap; |
| 386 | const char *component; |
| 387 | |
| 388 | va_start(ap, len); |
| 389 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 390 | while ((component = va_arg(ap, const char *))) { |
Daniel Dadap | 2e13fca | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 391 | if (required_len > 0) { |
| 392 | // This path element is not the first non-empty element; prepend |
| 393 | // a directory separator if space allows |
| 394 | if (dest && required_len + 1 < len) { |
| 395 | snprintf(dest + required_len, len - required_len, "%c", |
| 396 | DIRECTORY_SYMBOL); |
| 397 | } |
| 398 | required_len++; |
| 399 | } |
| 400 | |
| 401 | if (dest && required_len < len) { |
| 402 | strncpy(dest + required_len, component, len - required_len); |
| 403 | } |
| 404 | required_len += strlen(component); |
| 405 | } |
| 406 | |
| 407 | va_end(ap); |
| 408 | |
| 409 | // strncpy(3) won't add a NUL terminating byte in the event of truncation. |
| 410 | if (dest && required_len >= len) { |
| 411 | dest[len - 1] = '\0'; |
| 412 | } |
| 413 | |
| 414 | return required_len; |
| 415 | } |
| 416 | |
Daniel Dadap | 2e13fca | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 417 | /** |
Jon Ashburn | 4b7f35f | 2015-08-03 09:08:46 -0600 | [diff] [blame] | 418 | * Given string of three part form "maj.min.pat" convert to a vulkan version |
| 419 | * number. |
| 420 | */ |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 421 | static uint32_t loader_make_version(const char *vers_str) { |
| 422 | uint32_t vers = 0, major = 0, minor = 0, patch = 0; |
| 423 | char *minor_str = NULL; |
Jon Ashburn | 4b7f35f | 2015-08-03 09:08:46 -0600 | [diff] [blame] | 424 | char *patch_str = NULL; |
| 425 | char *cstr; |
| 426 | char *str; |
| 427 | |
| 428 | if (!vers_str) |
| 429 | return vers; |
| 430 | cstr = loader_stack_alloc(strlen(vers_str) + 1); |
| 431 | strcpy(cstr, vers_str); |
| 432 | while ((str = strchr(cstr, '.')) != NULL) { |
| 433 | if (minor_str == NULL) { |
| 434 | minor_str = str + 1; |
| 435 | *str = '\0'; |
| 436 | major = atoi(cstr); |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 437 | } else if (patch_str == NULL) { |
Jon Ashburn | 4b7f35f | 2015-08-03 09:08:46 -0600 | [diff] [blame] | 438 | patch_str = str + 1; |
| 439 | *str = '\0'; |
| 440 | minor = atoi(minor_str); |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 441 | } else { |
Jon Ashburn | 4b7f35f | 2015-08-03 09:08:46 -0600 | [diff] [blame] | 442 | return vers; |
| 443 | } |
| 444 | cstr = str + 1; |
| 445 | } |
| 446 | patch = atoi(patch_str); |
| 447 | |
| 448 | return VK_MAKE_VERSION(major, minor, patch); |
Jon Ashburn | 4b7f35f | 2015-08-03 09:08:46 -0600 | [diff] [blame] | 449 | } |
| 450 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 451 | bool compare_vk_extension_properties(const VkExtensionProperties *op1, |
| 452 | const VkExtensionProperties *op2) { |
Chia-I Wu | 1f85191 | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 453 | return strcmp(op1->extensionName, op2->extensionName) == 0 ? true : false; |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 454 | } |
| 455 | |
Jon Ashburn | 1b111de | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 456 | /** |
Jon Ashburn | 6037841 | 2015-07-02 12:59:25 -0600 | [diff] [blame] | 457 | * Search the given ext_array for an extension |
| 458 | * matching the given vk_ext_prop |
| 459 | */ |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 460 | bool has_vk_extension_property_array(const VkExtensionProperties *vk_ext_prop, |
| 461 | const uint32_t count, |
| 462 | const VkExtensionProperties *ext_array) { |
Jon Ashburn | 6037841 | 2015-07-02 12:59:25 -0600 | [diff] [blame] | 463 | for (uint32_t i = 0; i < count; i++) { |
| 464 | if (compare_vk_extension_properties(vk_ext_prop, &ext_array[i])) |
| 465 | return true; |
| 466 | } |
| 467 | return false; |
| 468 | } |
| 469 | |
Jon Ashburn | 1b111de | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 470 | /** |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 471 | * Search the given ext_list for an extension |
| 472 | * matching the given vk_ext_prop |
| 473 | */ |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 474 | bool has_vk_extension_property(const VkExtensionProperties *vk_ext_prop, |
| 475 | const struct loader_extension_list *ext_list) { |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 476 | for (uint32_t i = 0; i < ext_list->count; i++) { |
Jon Ashburn | c4748dc | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 477 | if (compare_vk_extension_properties(&ext_list->list[i], vk_ext_prop)) |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 478 | return true; |
| 479 | } |
| 480 | return false; |
| 481 | } |
| 482 | |
Jon Ashburn | e178310 | 2016-04-08 15:03:35 -0600 | [diff] [blame] | 483 | /** |
| 484 | * Search the given ext_list for a device extension matching the given ext_prop |
| 485 | */ |
Jon Ashburn | 9b2a8c9 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 486 | bool has_vk_dev_ext_property( |
| 487 | const VkExtensionProperties *ext_prop, |
| 488 | const struct loader_device_extension_list *ext_list) { |
Jon Ashburn | e178310 | 2016-04-08 15:03:35 -0600 | [diff] [blame] | 489 | for (uint32_t i = 0; i < ext_list->count; i++) { |
| 490 | if (compare_vk_extension_properties(&ext_list->list[i].props, ext_prop)) |
| 491 | return true; |
| 492 | } |
| 493 | return false; |
| 494 | } |
| 495 | |
Jon Ashburn | 0bf6a18 | 2015-07-16 17:19:31 -0600 | [diff] [blame] | 496 | static inline bool loader_is_layer_type_device(const enum layer_type type) { |
| 497 | if ((type & VK_LAYER_TYPE_DEVICE_EXPLICIT) || |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 498 | (type & VK_LAYER_TYPE_DEVICE_IMPLICIT)) |
Jon Ashburn | 0bf6a18 | 2015-07-16 17:19:31 -0600 | [diff] [blame] | 499 | return true; |
| 500 | return false; |
| 501 | } |
| 502 | |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 503 | /* |
Jon Ashburn | 1b111de | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 504 | * 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] | 505 | */ |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 506 | static struct loader_layer_properties * |
| 507 | loader_get_layer_property(const char *name, |
| 508 | const struct loader_layer_list *layer_list) { |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 509 | for (uint32_t i = 0; i < layer_list->count; i++) { |
| 510 | const VkLayerProperties *item = &layer_list->list[i].info; |
| 511 | if (strcmp(name, item->layerName) == 0) |
| 512 | return &layer_list->list[i]; |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 513 | } |
| 514 | return NULL; |
| 515 | } |
| 516 | |
Jon Ashburn | 8e4fab4 | 2015-08-03 17:19:30 -0600 | [diff] [blame] | 517 | /** |
| 518 | * Get the next unused layer property in the list. Init the property to zero. |
| 519 | */ |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 520 | static struct loader_layer_properties * |
| 521 | loader_get_next_layer_property(const struct loader_instance *inst, |
| 522 | struct loader_layer_list *layer_list) { |
Jon Ashburn | 8e4fab4 | 2015-08-03 17:19:30 -0600 | [diff] [blame] | 523 | if (layer_list->capacity == 0) { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 524 | layer_list->list = |
| 525 | loader_heap_alloc(inst, sizeof(struct loader_layer_properties) * 64, |
| 526 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Jon Ashburn | 8e4fab4 | 2015-08-03 17:19:30 -0600 | [diff] [blame] | 527 | if (layer_list->list == NULL) { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 528 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 529 | "Out of memory can't add any layer properties to list"); |
Jon Ashburn | 8e4fab4 | 2015-08-03 17:19:30 -0600 | [diff] [blame] | 530 | return NULL; |
| 531 | } |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 532 | memset(layer_list->list, 0, |
| 533 | sizeof(struct loader_layer_properties) * 64); |
Jon Ashburn | 8e4fab4 | 2015-08-03 17:19:30 -0600 | [diff] [blame] | 534 | layer_list->capacity = sizeof(struct loader_layer_properties) * 64; |
| 535 | } |
| 536 | |
| 537 | // ensure enough room to add an entry |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 538 | if ((layer_list->count + 1) * sizeof(struct loader_layer_properties) > |
| 539 | layer_list->capacity) { |
| 540 | layer_list->list = loader_heap_realloc( |
| 541 | inst, layer_list->list, layer_list->capacity, |
| 542 | layer_list->capacity * 2, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Jon Ashburn | 8e4fab4 | 2015-08-03 17:19:30 -0600 | [diff] [blame] | 543 | if (layer_list->list == NULL) { |
Courtney Goeltzenleuchter | acb1359 | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 544 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 545 | "realloc failed for layer list"); |
Jon Ashburn | 8e4fab4 | 2015-08-03 17:19:30 -0600 | [diff] [blame] | 546 | } |
| 547 | layer_list->capacity *= 2; |
| 548 | } |
| 549 | |
| 550 | layer_list->count++; |
| 551 | return &(layer_list->list[layer_list->count - 1]); |
| 552 | } |
| 553 | |
| 554 | /** |
| 555 | * Remove all layer properties entrys from the list |
| 556 | */ |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 557 | void loader_delete_layer_properties(const struct loader_instance *inst, |
| 558 | struct loader_layer_list *layer_list) { |
Jon Ashburn | 738136f | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 559 | uint32_t i, j; |
| 560 | struct loader_device_extension_list *dev_ext_list; |
Jon Ashburn | 182b830 | 2015-08-11 14:49:54 -0600 | [diff] [blame] | 561 | if (!layer_list) |
| 562 | return; |
| 563 | |
Jon Ashburn | 8e4fab4 | 2015-08-03 17:19:30 -0600 | [diff] [blame] | 564 | for (i = 0; i < layer_list->count; i++) { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 565 | loader_destroy_generic_list( |
| 566 | inst, (struct loader_generic_list *)&layer_list->list[i] |
| 567 | .instance_extension_list); |
Jon Ashburn | 738136f | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 568 | dev_ext_list = &layer_list->list[i].device_extension_list; |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 569 | if (dev_ext_list->capacity > 0 && |
| 570 | dev_ext_list->list->entrypoint_count > 0) { |
| 571 | for (j = 0; j < dev_ext_list->list->entrypoint_count; j++) { |
Jon Ashburn | 738136f | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 572 | loader_heap_free(inst, dev_ext_list->list->entrypoints[j]); |
| 573 | } |
| 574 | loader_heap_free(inst, dev_ext_list->list->entrypoints); |
| 575 | } |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 576 | loader_destroy_generic_list(inst, |
| 577 | (struct loader_generic_list *)dev_ext_list); |
Jon Ashburn | 8e4fab4 | 2015-08-03 17:19:30 -0600 | [diff] [blame] | 578 | } |
| 579 | layer_list->count = 0; |
| 580 | |
Jon Ashburn | 182b830 | 2015-08-11 14:49:54 -0600 | [diff] [blame] | 581 | if (layer_list->capacity > 0) { |
| 582 | layer_list->capacity = 0; |
Jon Ashburn | e58f1a3 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 583 | loader_heap_free(inst, layer_list->list); |
Jon Ashburn | 182b830 | 2015-08-11 14:49:54 -0600 | [diff] [blame] | 584 | } |
Jon Ashburn | 8e4fab4 | 2015-08-03 17:19:30 -0600 | [diff] [blame] | 585 | } |
| 586 | |
Courtney Goeltzenleuchter | 03c80a6 | 2015-12-02 14:00:19 -0700 | [diff] [blame] | 587 | static void loader_add_instance_extensions( |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 588 | const struct loader_instance *inst, |
| 589 | const PFN_vkEnumerateInstanceExtensionProperties fp_get_props, |
| 590 | const char *lib_name, struct loader_extension_list *ext_list) { |
Courtney Goeltzenleuchter | f843d2d | 2015-12-21 16:41:47 -0700 | [diff] [blame] | 591 | uint32_t i, count = 0; |
Jon Ashburn | c4748dc | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 592 | VkExtensionProperties *ext_props; |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 593 | VkResult res; |
| 594 | |
Courtney Goeltzenleuchter | aa9faab | 2015-07-06 22:28:18 -0600 | [diff] [blame] | 595 | if (!fp_get_props) { |
Courtney Goeltzenleuchter | 74c4ce9 | 2015-09-14 17:22:16 -0600 | [diff] [blame] | 596 | /* No EnumerateInstanceExtensionProperties defined */ |
Courtney Goeltzenleuchter | aa9faab | 2015-07-06 22:28:18 -0600 | [diff] [blame] | 597 | return; |
| 598 | } |
| 599 | |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 600 | res = fp_get_props(NULL, &count, NULL); |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 601 | if (res != VK_SUCCESS) { |
Mark Lobodzinski | 5c13d4d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 602 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 603 | "Error getting Instance extension count from %s", lib_name); |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 604 | return; |
| 605 | } |
Jon Ashburn | 6069926 | 2015-06-10 16:11:42 -0600 | [diff] [blame] | 606 | |
Courtney Goeltzenleuchter | aa9faab | 2015-07-06 22:28:18 -0600 | [diff] [blame] | 607 | if (count == 0) { |
| 608 | /* No ExtensionProperties to report */ |
| 609 | return; |
| 610 | } |
| 611 | |
Jon Ashburn | c4748dc | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 612 | ext_props = loader_stack_alloc(count * sizeof(VkExtensionProperties)); |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 613 | |
Jon Ashburn | c4748dc | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 614 | res = fp_get_props(NULL, &count, ext_props); |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 615 | if (res != VK_SUCCESS) { |
Mark Lobodzinski | 5c13d4d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 616 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 617 | "Error getting Instance extensions from %s", lib_name); |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 618 | return; |
| 619 | } |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 620 | |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 621 | for (i = 0; i < count; i++) { |
Courtney Goeltzenleuchter | 73a21d3 | 2015-07-12 13:20:05 -0600 | [diff] [blame] | 622 | char spec_version[64]; |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 623 | |
Jon Ashburn | 9b2a8c9 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 624 | bool ext_unsupported = |
| 625 | wsi_unsupported_instance_extension(&ext_props[i]); |
Jon Ashburn | c666cff | 2016-03-25 12:49:35 -0600 | [diff] [blame] | 626 | if (!ext_unsupported) { |
| 627 | snprintf(spec_version, sizeof(spec_version), "%d.%d.%d", |
| 628 | VK_MAJOR(ext_props[i].specVersion), |
| 629 | VK_MINOR(ext_props[i].specVersion), |
| 630 | VK_PATCH(ext_props[i].specVersion)); |
| 631 | loader_log(inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, |
| 632 | "Instance Extension: %s (%s) version %s", |
| 633 | ext_props[i].extensionName, lib_name, spec_version); |
| 634 | loader_add_to_ext_list(inst, ext_list, 1, &ext_props[i]); |
| 635 | } |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 636 | } |
| 637 | |
| 638 | return; |
| 639 | } |
| 640 | |
Jon Ashburn | db5a5bc | 2015-11-02 17:40:01 -0700 | [diff] [blame] | 641 | /* |
| 642 | * Initialize ext_list with the physical device extensions. |
| 643 | * The extension properties are passed as inputs in count and ext_props. |
| 644 | */ |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 645 | static VkResult |
| 646 | loader_init_device_extensions(const struct loader_instance *inst, |
| 647 | struct loader_physical_device *phys_dev, |
| 648 | uint32_t count, VkExtensionProperties *ext_props, |
| 649 | struct loader_extension_list *ext_list) { |
Jon Ashburn | db5a5bc | 2015-11-02 17:40:01 -0700 | [diff] [blame] | 650 | VkResult res; |
| 651 | uint32_t i; |
| 652 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 653 | if (!loader_init_generic_list(inst, (struct loader_generic_list *)ext_list, |
Jon Ashburn | 8f6be30 | 2015-12-10 08:51:10 -0700 | [diff] [blame] | 654 | sizeof(VkExtensionProperties))) { |
Jon Ashburn | db5a5bc | 2015-11-02 17:40:01 -0700 | [diff] [blame] | 655 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 656 | } |
| 657 | |
| 658 | for (i = 0; i < count; i++) { |
| 659 | char spec_version[64]; |
| 660 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 661 | snprintf(spec_version, sizeof(spec_version), "%d.%d.%d", |
| 662 | VK_MAJOR(ext_props[i].specVersion), |
| 663 | VK_MINOR(ext_props[i].specVersion), |
| 664 | VK_PATCH(ext_props[i].specVersion)); |
Courtney Goeltzenleuchter | acb1359 | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 665 | loader_log(inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 666 | "Device Extension: %s (%s) version %s", |
| 667 | ext_props[i].extensionName, |
| 668 | phys_dev->this_icd->this_icd_lib->lib_name, spec_version); |
Jon Ashburn | db5a5bc | 2015-11-02 17:40:01 -0700 | [diff] [blame] | 669 | res = loader_add_to_ext_list(inst, ext_list, 1, &ext_props[i]); |
| 670 | if (res != VK_SUCCESS) |
| 671 | return res; |
| 672 | } |
| 673 | |
| 674 | return VK_SUCCESS; |
| 675 | } |
| 676 | |
Jon Ashburn | a9c4a57 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 677 | VkResult loader_add_device_extensions(const struct loader_instance *inst, |
Jon Ashburn | 9b2a8c9 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 678 | PFN_vkEnumerateDeviceExtensionProperties |
| 679 | fpEnumerateDeviceExtensionProperties, |
Jon Ashburn | a9c4a57 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 680 | VkPhysicalDevice physical_device, |
| 681 | const char *lib_name, |
| 682 | struct loader_extension_list *ext_list) { |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 683 | uint32_t i, count; |
| 684 | VkResult res; |
Jon Ashburn | c4748dc | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 685 | VkExtensionProperties *ext_props; |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 686 | |
Piers Daniell | fc50041 | 2016-03-29 11:51:11 -0600 | [diff] [blame] | 687 | res = fpEnumerateDeviceExtensionProperties(physical_device, NULL, &count, |
| 688 | NULL); |
Jon Ashburn | db5a5bc | 2015-11-02 17:40:01 -0700 | [diff] [blame] | 689 | if (res == VK_SUCCESS && count > 0) { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 690 | ext_props = loader_stack_alloc(count * sizeof(VkExtensionProperties)); |
Jon Ashburn | db5a5bc | 2015-11-02 17:40:01 -0700 | [diff] [blame] | 691 | if (!ext_props) |
| 692 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Piers Daniell | fc50041 | 2016-03-29 11:51:11 -0600 | [diff] [blame] | 693 | res = fpEnumerateDeviceExtensionProperties(physical_device, NULL, |
| 694 | &count, ext_props); |
Jon Ashburn | db5a5bc | 2015-11-02 17:40:01 -0700 | [diff] [blame] | 695 | if (res != VK_SUCCESS) |
Jon Ashburn | 251258f | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 696 | return res; |
Jon Ashburn | db5a5bc | 2015-11-02 17:40:01 -0700 | [diff] [blame] | 697 | for (i = 0; i < count; i++) { |
| 698 | char spec_version[64]; |
| 699 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 700 | snprintf(spec_version, sizeof(spec_version), "%d.%d.%d", |
| 701 | VK_MAJOR(ext_props[i].specVersion), |
| 702 | VK_MINOR(ext_props[i].specVersion), |
| 703 | VK_PATCH(ext_props[i].specVersion)); |
Courtney Goeltzenleuchter | acb1359 | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 704 | loader_log(inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 705 | "Device Extension: %s (%s) version %s", |
| 706 | ext_props[i].extensionName, lib_name, spec_version); |
Jon Ashburn | db5a5bc | 2015-11-02 17:40:01 -0700 | [diff] [blame] | 707 | res = loader_add_to_ext_list(inst, ext_list, 1, &ext_props[i]); |
| 708 | if (res != VK_SUCCESS) |
| 709 | return res; |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 710 | } |
Jon Ashburn | db5a5bc | 2015-11-02 17:40:01 -0700 | [diff] [blame] | 711 | } else { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 712 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 713 | "Error getting physical device extension info count from " |
| 714 | "library %s", |
| 715 | lib_name); |
Jon Ashburn | db5a5bc | 2015-11-02 17:40:01 -0700 | [diff] [blame] | 716 | return res; |
| 717 | } |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 718 | |
Jon Ashburn | 251258f | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 719 | return VK_SUCCESS; |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 720 | } |
| 721 | |
Jon Ashburn | a9c4a57 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 722 | bool loader_init_generic_list(const struct loader_instance *inst, |
| 723 | struct loader_generic_list *list_info, |
| 724 | size_t element_size) { |
Jon Ashburn | 8f6be30 | 2015-12-10 08:51:10 -0700 | [diff] [blame] | 725 | list_info->capacity = 32 * element_size; |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 726 | list_info->list = loader_heap_alloc(inst, list_info->capacity, |
| 727 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Jon Ashburn | 8f6be30 | 2015-12-10 08:51:10 -0700 | [diff] [blame] | 728 | if (list_info->list == NULL) { |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 729 | return false; |
| 730 | } |
Jon Ashburn | 8f6be30 | 2015-12-10 08:51:10 -0700 | [diff] [blame] | 731 | memset(list_info->list, 0, list_info->capacity); |
| 732 | list_info->count = 0; |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 733 | return true; |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 734 | } |
| 735 | |
Jon Ashburn | 8f6be30 | 2015-12-10 08:51:10 -0700 | [diff] [blame] | 736 | void loader_destroy_generic_list(const struct loader_instance *inst, |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 737 | struct loader_generic_list *list) { |
Jon Ashburn | 8f6be30 | 2015-12-10 08:51:10 -0700 | [diff] [blame] | 738 | loader_heap_free(inst, list->list); |
| 739 | list->count = 0; |
| 740 | list->capacity = 0; |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 741 | } |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 742 | |
Jon Ashburn | c4748dc | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 743 | /* |
| 744 | * Append non-duplicate extension properties defined in props |
| 745 | * to the given ext_list. |
Jon Ashburn | 251258f | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 746 | * Return |
| 747 | * Vk_SUCCESS on success |
Jon Ashburn | c4748dc | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 748 | */ |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 749 | VkResult loader_add_to_ext_list(const struct loader_instance *inst, |
| 750 | struct loader_extension_list *ext_list, |
| 751 | uint32_t prop_list_count, |
| 752 | const VkExtensionProperties *props) { |
Jon Ashburn | c4748dc | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 753 | uint32_t i; |
| 754 | const VkExtensionProperties *cur_ext; |
| 755 | |
| 756 | if (ext_list->list == NULL || ext_list->capacity == 0) { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 757 | loader_init_generic_list(inst, (struct loader_generic_list *)ext_list, |
Jon Ashburn | 8f6be30 | 2015-12-10 08:51:10 -0700 | [diff] [blame] | 758 | sizeof(VkExtensionProperties)); |
Jon Ashburn | c4748dc | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 759 | } |
| 760 | |
| 761 | if (ext_list->list == NULL) |
Jon Ashburn | 251258f | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 762 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Jon Ashburn | c4748dc | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 763 | |
| 764 | for (i = 0; i < prop_list_count; i++) { |
| 765 | cur_ext = &props[i]; |
| 766 | |
| 767 | // look for duplicates |
| 768 | if (has_vk_extension_property(cur_ext, ext_list)) { |
| 769 | continue; |
| 770 | } |
| 771 | |
| 772 | // add to list at end |
| 773 | // check for enough capacity |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 774 | if (ext_list->count * sizeof(VkExtensionProperties) >= |
| 775 | ext_list->capacity) { |
Jon Ashburn | e58f1a3 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 776 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 777 | ext_list->list = loader_heap_realloc( |
| 778 | inst, ext_list->list, ext_list->capacity, |
| 779 | ext_list->capacity * 2, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Jon Ashburn | 251258f | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 780 | |
| 781 | if (ext_list->list == NULL) |
| 782 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 783 | |
Jon Ashburn | c4748dc | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 784 | // double capacity |
| 785 | ext_list->capacity *= 2; |
Jon Ashburn | c4748dc | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 786 | } |
| 787 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 788 | memcpy(&ext_list->list[ext_list->count], cur_ext, |
| 789 | sizeof(VkExtensionProperties)); |
Jon Ashburn | c4748dc | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 790 | ext_list->count++; |
| 791 | } |
Jon Ashburn | 251258f | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 792 | return VK_SUCCESS; |
Jon Ashburn | c4748dc | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 793 | } |
| 794 | |
Jon Ashburn | 738136f | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 795 | /* |
| 796 | * Append one extension property defined in props with entrypoints |
Jon Ashburn | e178310 | 2016-04-08 15:03:35 -0600 | [diff] [blame] | 797 | * defined in entrys to the given ext_list. Do not append if a duplicate |
Jon Ashburn | 738136f | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 798 | * Return |
| 799 | * Vk_SUCCESS on success |
| 800 | */ |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 801 | VkResult |
| 802 | loader_add_to_dev_ext_list(const struct loader_instance *inst, |
| 803 | struct loader_device_extension_list *ext_list, |
| 804 | const VkExtensionProperties *props, |
| 805 | uint32_t entry_count, char **entrys) { |
Jon Ashburn | 738136f | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 806 | uint32_t idx; |
| 807 | if (ext_list->list == NULL || ext_list->capacity == 0) { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 808 | loader_init_generic_list(inst, (struct loader_generic_list *)ext_list, |
Jon Ashburn | 738136f | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 809 | sizeof(struct loader_dev_ext_props)); |
| 810 | } |
| 811 | |
| 812 | if (ext_list->list == NULL) |
| 813 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 814 | |
Jon Ashburn | e178310 | 2016-04-08 15:03:35 -0600 | [diff] [blame] | 815 | // look for duplicates |
| 816 | if (has_vk_dev_ext_property(props, ext_list)) { |
| 817 | return VK_SUCCESS; |
| 818 | } |
| 819 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 820 | idx = ext_list->count; |
Jon Ashburn | 738136f | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 821 | // add to list at end |
| 822 | // check for enough capacity |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 823 | if (idx * sizeof(struct loader_dev_ext_props) >= ext_list->capacity) { |
Jon Ashburn | 738136f | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 824 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 825 | ext_list->list = loader_heap_realloc( |
| 826 | inst, ext_list->list, ext_list->capacity, ext_list->capacity * 2, |
| 827 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Jon Ashburn | 738136f | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 828 | |
| 829 | if (ext_list->list == NULL) |
| 830 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 831 | |
| 832 | // double capacity |
| 833 | ext_list->capacity *= 2; |
| 834 | } |
| 835 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 836 | memcpy(&ext_list->list[idx].props, props, |
| 837 | sizeof(struct loader_dev_ext_props)); |
Jon Ashburn | 738136f | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 838 | ext_list->list[idx].entrypoint_count = entry_count; |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 839 | ext_list->list[idx].entrypoints = |
| 840 | loader_heap_alloc(inst, sizeof(char *) * entry_count, |
| 841 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Jon Ashburn | 738136f | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 842 | if (ext_list->list[idx].entrypoints == NULL) |
| 843 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 844 | for (uint32_t i = 0; i < entry_count; i++) { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 845 | ext_list->list[idx].entrypoints[i] = loader_heap_alloc( |
| 846 | inst, strlen(entrys[i]) + 1, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Jon Ashburn | 738136f | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 847 | if (ext_list->list[idx].entrypoints[i] == NULL) |
| 848 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 849 | strcpy(ext_list->list[idx].entrypoints[i], entrys[i]); |
| 850 | } |
| 851 | ext_list->count++; |
| 852 | |
| 853 | return VK_SUCCESS; |
| 854 | } |
| 855 | |
Jon Ashburn | 6037841 | 2015-07-02 12:59:25 -0600 | [diff] [blame] | 856 | /** |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 857 | * Search the given search_list for any layers in the props list. |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 858 | * Add these to the output layer_list. Don't add duplicates to the output |
| 859 | * layer_list. |
Jon Ashburn | 6037841 | 2015-07-02 12:59:25 -0600 | [diff] [blame] | 860 | */ |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 861 | static VkResult |
| 862 | loader_add_layer_names_to_list(const struct loader_instance *inst, |
| 863 | struct loader_layer_list *output_list, |
| 864 | uint32_t name_count, const char *const *names, |
| 865 | const struct loader_layer_list *search_list) { |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 866 | struct loader_layer_properties *layer_prop; |
Courtney Goeltzenleuchter | 1fcceeb | 2015-07-06 09:06:34 -0600 | [diff] [blame] | 867 | VkResult err = VK_SUCCESS; |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 868 | |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 869 | for (uint32_t i = 0; i < name_count; i++) { |
| 870 | const char *search_target = names[i]; |
Jon Ashburn | 8e4fab4 | 2015-08-03 17:19:30 -0600 | [diff] [blame] | 871 | layer_prop = loader_get_layer_property(search_target, search_list); |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 872 | if (!layer_prop) { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 873 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 874 | "Unable to find layer %s", search_target); |
Courtney Goeltzenleuchter | ac544f3 | 2015-09-14 18:01:17 -0600 | [diff] [blame] | 875 | err = VK_ERROR_LAYER_NOT_PRESENT; |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 876 | continue; |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 877 | } |
| 878 | |
Jon Ashburn | e58f1a3 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 879 | loader_add_to_layer_list(inst, output_list, 1, layer_prop); |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 880 | } |
Courtney Goeltzenleuchter | 1fcceeb | 2015-07-06 09:06:34 -0600 | [diff] [blame] | 881 | |
| 882 | return err; |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 883 | } |
| 884 | |
Courtney Goeltzenleuchter | b620ace | 2015-07-05 11:28:29 -0600 | [diff] [blame] | 885 | /* |
| 886 | * Manage lists of VkLayerProperties |
| 887 | */ |
Jon Ashburn | e58f1a3 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 888 | static bool loader_init_layer_list(const struct loader_instance *inst, |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 889 | struct loader_layer_list *list) { |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 890 | list->capacity = 32 * sizeof(struct loader_layer_properties); |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 891 | list->list = loader_heap_alloc(inst, list->capacity, |
| 892 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 893 | if (list->list == NULL) { |
| 894 | return false; |
| 895 | } |
| 896 | memset(list->list, 0, list->capacity); |
| 897 | list->count = 0; |
| 898 | return true; |
| 899 | } |
| 900 | |
Jon Ashburn | e58f1a3 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 901 | void loader_destroy_layer_list(const struct loader_instance *inst, |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 902 | struct loader_layer_list *layer_list) { |
Jon Ashburn | e58f1a3 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 903 | loader_heap_free(inst, layer_list->list); |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 904 | layer_list->count = 0; |
| 905 | layer_list->capacity = 0; |
| 906 | } |
| 907 | |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 908 | /* |
Courtney Goeltzenleuchter | c5cf7d7 | 2015-07-05 12:53:31 -0600 | [diff] [blame] | 909 | * Manage list of layer libraries (loader_lib_info) |
| 910 | */ |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 911 | static bool |
| 912 | loader_init_layer_library_list(const struct loader_instance *inst, |
| 913 | struct loader_layer_library_list *list) { |
Courtney Goeltzenleuchter | c5cf7d7 | 2015-07-05 12:53:31 -0600 | [diff] [blame] | 914 | list->capacity = 32 * sizeof(struct loader_lib_info); |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 915 | list->list = loader_heap_alloc(inst, list->capacity, |
| 916 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Courtney Goeltzenleuchter | c5cf7d7 | 2015-07-05 12:53:31 -0600 | [diff] [blame] | 917 | if (list->list == NULL) { |
| 918 | return false; |
| 919 | } |
| 920 | memset(list->list, 0, list->capacity); |
| 921 | list->count = 0; |
| 922 | return true; |
| 923 | } |
| 924 | |
Jon Ashburn | e58f1a3 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 925 | void loader_destroy_layer_library_list(const struct loader_instance *inst, |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 926 | struct loader_layer_library_list *list) { |
Courtney Goeltzenleuchter | c5cf7d7 | 2015-07-05 12:53:31 -0600 | [diff] [blame] | 927 | for (uint32_t i = 0; i < list->count; i++) { |
Jon Ashburn | e58f1a3 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 928 | loader_heap_free(inst, list->list[i].lib_name); |
Courtney Goeltzenleuchter | c5cf7d7 | 2015-07-05 12:53:31 -0600 | [diff] [blame] | 929 | } |
Jon Ashburn | e58f1a3 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 930 | loader_heap_free(inst, list->list); |
Courtney Goeltzenleuchter | c5cf7d7 | 2015-07-05 12:53:31 -0600 | [diff] [blame] | 931 | list->count = 0; |
| 932 | list->capacity = 0; |
| 933 | } |
| 934 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 935 | void loader_add_to_layer_library_list(const struct loader_instance *inst, |
| 936 | struct loader_layer_library_list *list, |
| 937 | uint32_t item_count, |
| 938 | const struct loader_lib_info *new_items) { |
Courtney Goeltzenleuchter | c5cf7d7 | 2015-07-05 12:53:31 -0600 | [diff] [blame] | 939 | uint32_t i; |
| 940 | struct loader_lib_info *item; |
| 941 | |
| 942 | if (list->list == NULL || list->capacity == 0) { |
Jon Ashburn | e58f1a3 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 943 | loader_init_layer_library_list(inst, list); |
Courtney Goeltzenleuchter | c5cf7d7 | 2015-07-05 12:53:31 -0600 | [diff] [blame] | 944 | } |
| 945 | |
| 946 | if (list->list == NULL) |
| 947 | return; |
| 948 | |
| 949 | for (i = 0; i < item_count; i++) { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 950 | item = (struct loader_lib_info *)&new_items[i]; |
Courtney Goeltzenleuchter | c5cf7d7 | 2015-07-05 12:53:31 -0600 | [diff] [blame] | 951 | |
| 952 | // look for duplicates |
| 953 | for (uint32_t j = 0; j < list->count; j++) { |
| 954 | if (strcmp(list->list[i].lib_name, new_items->lib_name) == 0) { |
| 955 | continue; |
| 956 | } |
| 957 | } |
| 958 | |
| 959 | // add to list at end |
| 960 | // check for enough capacity |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 961 | if (list->count * sizeof(struct loader_lib_info) >= list->capacity) { |
Jon Ashburn | e58f1a3 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 962 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 963 | list->list = loader_heap_realloc( |
| 964 | inst, list->list, list->capacity, list->capacity * 2, |
| 965 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Courtney Goeltzenleuchter | c5cf7d7 | 2015-07-05 12:53:31 -0600 | [diff] [blame] | 966 | // double capacity |
| 967 | list->capacity *= 2; |
Courtney Goeltzenleuchter | c5cf7d7 | 2015-07-05 12:53:31 -0600 | [diff] [blame] | 968 | } |
| 969 | |
| 970 | memcpy(&list->list[list->count], item, sizeof(struct loader_lib_info)); |
| 971 | list->count++; |
| 972 | } |
| 973 | } |
| 974 | |
Courtney Goeltzenleuchter | c5cf7d7 | 2015-07-05 12:53:31 -0600 | [diff] [blame] | 975 | /* |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 976 | * Search the given layer list for a list |
| 977 | * matching the given VkLayerProperties |
| 978 | */ |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 979 | bool has_vk_layer_property(const VkLayerProperties *vk_layer_prop, |
| 980 | const struct loader_layer_list *list) { |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 981 | for (uint32_t i = 0; i < list->count; i++) { |
| 982 | if (strcmp(vk_layer_prop->layerName, list->list[i].info.layerName) == 0) |
| 983 | return true; |
| 984 | } |
| 985 | return false; |
| 986 | } |
| 987 | |
| 988 | /* |
| 989 | * Search the given layer list for a layer |
| 990 | * matching the given name |
| 991 | */ |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 992 | bool has_layer_name(const char *name, const struct loader_layer_list *list) { |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 993 | for (uint32_t i = 0; i < list->count; i++) { |
| 994 | if (strcmp(name, list->list[i].info.layerName) == 0) |
| 995 | return true; |
| 996 | } |
| 997 | return false; |
| 998 | } |
| 999 | |
| 1000 | /* |
| 1001 | * Append non-duplicate layer properties defined in prop_list |
| 1002 | * to the given layer_info list |
| 1003 | */ |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1004 | void loader_add_to_layer_list(const struct loader_instance *inst, |
| 1005 | struct loader_layer_list *list, |
| 1006 | uint32_t prop_list_count, |
| 1007 | const struct loader_layer_properties *props) { |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1008 | uint32_t i; |
| 1009 | struct loader_layer_properties *layer; |
| 1010 | |
| 1011 | if (list->list == NULL || list->capacity == 0) { |
Jon Ashburn | e58f1a3 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 1012 | loader_init_layer_list(inst, list); |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1013 | } |
| 1014 | |
| 1015 | if (list->list == NULL) |
| 1016 | return; |
| 1017 | |
| 1018 | for (i = 0; i < prop_list_count; i++) { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1019 | layer = (struct loader_layer_properties *)&props[i]; |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1020 | |
| 1021 | // look for duplicates |
| 1022 | if (has_vk_layer_property(&layer->info, list)) { |
| 1023 | continue; |
| 1024 | } |
| 1025 | |
| 1026 | // add to list at end |
| 1027 | // check for enough capacity |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1028 | if (list->count * sizeof(struct loader_layer_properties) >= |
| 1029 | list->capacity) { |
Jon Ashburn | e58f1a3 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 1030 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1031 | list->list = loader_heap_realloc( |
| 1032 | inst, list->list, list->capacity, list->capacity * 2, |
| 1033 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1034 | // double capacity |
| 1035 | list->capacity *= 2; |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1036 | } |
| 1037 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1038 | memcpy(&list->list[list->count], layer, |
| 1039 | sizeof(struct loader_layer_properties)); |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1040 | list->count++; |
| 1041 | } |
| 1042 | } |
| 1043 | |
Jon Ashburn | f2ddb73 | 2015-07-07 10:27:45 -0600 | [diff] [blame] | 1044 | /** |
| 1045 | * Search the search_list for any layer with a name |
| 1046 | * 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] | 1047 | * Add all matching layers to the found_list |
Jon Ashburn | f2ddb73 | 2015-07-07 10:27:45 -0600 | [diff] [blame] | 1048 | * Do not add if found loader_layer_properties is already |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1049 | * on the found_list. |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1050 | */ |
Jon Ashburn | 9b2a8c9 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 1051 | void loader_find_layer_name_add_list( |
| 1052 | const struct loader_instance *inst, const char *name, |
| 1053 | const enum layer_type type, const struct loader_layer_list *search_list, |
| 1054 | struct loader_layer_list *found_list) { |
Jon Ashburn | 87c8fe9 | 2015-10-05 09:03:21 -0600 | [diff] [blame] | 1055 | bool found = false; |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1056 | for (uint32_t i = 0; i < search_list->count; i++) { |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1057 | struct loader_layer_properties *layer_prop = &search_list->list[i]; |
Jon Ashburn | f2ddb73 | 2015-07-07 10:27:45 -0600 | [diff] [blame] | 1058 | if (0 == strcmp(layer_prop->info.layerName, name) && |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1059 | (layer_prop->type & type)) { |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1060 | /* Found a layer with the same name, add to found_list */ |
Jon Ashburn | e58f1a3 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 1061 | loader_add_to_layer_list(inst, found_list, 1, layer_prop); |
Jon Ashburn | 87c8fe9 | 2015-10-05 09:03:21 -0600 | [diff] [blame] | 1062 | found = true; |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1063 | } |
| 1064 | } |
Jon Ashburn | 87c8fe9 | 2015-10-05 09:03:21 -0600 | [diff] [blame] | 1065 | if (!found) { |
Mark Lobodzinski | 5c13d4d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 1066 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1067 | "Warning, couldn't find layer name %s to activate", name); |
Jon Ashburn | 87c8fe9 | 2015-10-05 09:03:21 -0600 | [diff] [blame] | 1068 | } |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1069 | } |
| 1070 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1071 | static VkExtensionProperties * |
| 1072 | get_extension_property(const char *name, |
| 1073 | const struct loader_extension_list *list) { |
Courtney Goeltzenleuchter | ab27f46 | 2015-07-06 17:42:01 -0600 | [diff] [blame] | 1074 | for (uint32_t i = 0; i < list->count; i++) { |
Chia-I Wu | 1f85191 | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1075 | if (strcmp(name, list->list[i].extensionName) == 0) |
Courtney Goeltzenleuchter | ab27f46 | 2015-07-06 17:42:01 -0600 | [diff] [blame] | 1076 | return &list->list[i]; |
Jon Ashburn | 42e4103 | 2015-04-14 09:15:32 -0600 | [diff] [blame] | 1077 | } |
Courtney Goeltzenleuchter | ab27f46 | 2015-07-06 17:42:01 -0600 | [diff] [blame] | 1078 | return NULL; |
Jon Ashburn | 42e4103 | 2015-04-14 09:15:32 -0600 | [diff] [blame] | 1079 | } |
| 1080 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1081 | static VkExtensionProperties * |
| 1082 | get_dev_extension_property(const char *name, |
| 1083 | const struct loader_device_extension_list *list) { |
Jon Ashburn | 738136f | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1084 | for (uint32_t i = 0; i < list->count; i++) { |
| 1085 | if (strcmp(name, list->list[i].props.extensionName) == 0) |
| 1086 | return &list->list[i].props; |
| 1087 | } |
| 1088 | return NULL; |
| 1089 | } |
| 1090 | |
Jon Ashburn | 6037841 | 2015-07-02 12:59:25 -0600 | [diff] [blame] | 1091 | /* |
Courtney Goeltzenleuchter | f5f244d | 2016-01-15 14:15:00 -0700 | [diff] [blame] | 1092 | * This function will return the pNext pointer of any |
| 1093 | * CreateInfo extensions that are not loader extensions. |
| 1094 | * This is used to skip past the loader extensions prepended |
| 1095 | * to the list during CreateInstance and CreateDevice. |
| 1096 | */ |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1097 | void *loader_strip_create_extensions(const void *pNext) { |
| 1098 | VkLayerInstanceCreateInfo *create_info = (VkLayerInstanceCreateInfo *)pNext; |
Courtney Goeltzenleuchter | f5f244d | 2016-01-15 14:15:00 -0700 | [diff] [blame] | 1099 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1100 | while ( |
| 1101 | create_info && |
| 1102 | (create_info->sType == VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO || |
| 1103 | create_info->sType == VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO)) { |
| 1104 | create_info = (VkLayerInstanceCreateInfo *)create_info->pNext; |
Courtney Goeltzenleuchter | f5f244d | 2016-01-15 14:15:00 -0700 | [diff] [blame] | 1105 | } |
| 1106 | |
| 1107 | return create_info; |
| 1108 | } |
| 1109 | |
| 1110 | /* |
Courtney Goeltzenleuchter | 03c80a6 | 2015-12-02 14:00:19 -0700 | [diff] [blame] | 1111 | * For Instance extensions implemented within the loader (i.e. DEBUG_REPORT |
Jon Ashburn | 6037841 | 2015-07-02 12:59:25 -0600 | [diff] [blame] | 1112 | * the extension must provide two entry points for the loader to use: |
| 1113 | * - "trampoline" entry point - this is the address returned by GetProcAddr |
| 1114 | * and will always do what's necessary to support a global call. |
| 1115 | * - "terminator" function - this function will be put at the end of the |
Jon Ashburn | 2818eb7 | 2015-11-30 17:21:25 -0700 | [diff] [blame] | 1116 | * instance chain and will contain the necessary logic to call / process |
Jon Ashburn | 6037841 | 2015-07-02 12:59:25 -0600 | [diff] [blame] | 1117 | * the extension for the appropriate ICDs that are available. |
| 1118 | * There is no generic mechanism for including these functions, the references |
| 1119 | * must be placed into the appropriate loader entry points. |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1120 | * GetInstanceProcAddr: call extension GetInstanceProcAddr to check for |
| 1121 | * GetProcAddr requests |
| 1122 | * loader_coalesce_extensions(void) - add extension records to the list of |
| 1123 | * global |
Jon Ashburn | 6037841 | 2015-07-02 12:59:25 -0600 | [diff] [blame] | 1124 | * extension available to the app. |
| 1125 | * instance_disp - add function pointer for terminator function to this array. |
| 1126 | * The extension itself should be in a separate file that will be |
| 1127 | * linked directly with the loader. |
| 1128 | */ |
Jon Ashburn | c1d1eb7 | 2015-08-14 11:57:54 -0600 | [diff] [blame] | 1129 | |
Jon Ashburn | 754f199 | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 1130 | void loader_get_icd_loader_instance_extensions( |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1131 | const struct loader_instance *inst, struct loader_icd_libs *icd_libs, |
| 1132 | struct loader_extension_list *inst_exts) { |
Jon Ashburn | 85f9807 | 2015-08-14 14:49:22 -0600 | [diff] [blame] | 1133 | struct loader_extension_list icd_exts; |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1134 | loader_log(inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, |
| 1135 | "Build ICD instance extension list"); |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1136 | // traverse scanned icd list adding non-duplicate extensions to the list |
Jon Ashburn | 754f199 | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 1137 | for (uint32_t i = 0; i < icd_libs->count; i++) { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1138 | loader_init_generic_list(inst, (struct loader_generic_list *)&icd_exts, |
Jon Ashburn | 8f6be30 | 2015-12-10 08:51:10 -0700 | [diff] [blame] | 1139 | sizeof(VkExtensionProperties)); |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1140 | loader_add_instance_extensions( |
| 1141 | inst, icd_libs->list[i].EnumerateInstanceExtensionProperties, |
| 1142 | icd_libs->list[i].lib_name, &icd_exts); |
| 1143 | loader_add_to_ext_list(inst, inst_exts, icd_exts.count, icd_exts.list); |
| 1144 | loader_destroy_generic_list(inst, |
| 1145 | (struct loader_generic_list *)&icd_exts); |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1146 | }; |
| 1147 | |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1148 | // Traverse loader's extensions, adding non-duplicate extensions to the list |
Jon Ashburn | e58f1a3 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 1149 | debug_report_add_instance_extensions(inst, inst_exts); |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1150 | } |
| 1151 | |
Jon Ashburn | e58f1a3 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 1152 | struct loader_icd *loader_get_icd_and_device(const VkDevice device, |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1153 | struct loader_device **found_dev) { |
Jon Ashburn | cb5a5ac | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1154 | *found_dev = NULL; |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1155 | for (struct loader_instance *inst = loader.instances; inst; |
| 1156 | inst = inst->next) { |
Jon Ashburn | cb5a5ac | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1157 | for (struct loader_icd *icd = inst->icds; icd; icd = icd->next) { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1158 | for (struct loader_device *dev = icd->logical_device_list; dev; |
| 1159 | dev = dev->next) |
| 1160 | /* Value comparison of device prevents object wrapping by layers |
| 1161 | */ |
| 1162 | if (loader_get_dispatch(dev->device) == |
| 1163 | loader_get_dispatch(device)) { |
Jon Ashburn | cb5a5ac | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1164 | *found_dev = dev; |
| 1165 | return icd; |
| 1166 | } |
| 1167 | } |
| 1168 | } |
| 1169 | return NULL; |
| 1170 | } |
| 1171 | |
Jon Ashburn | e58f1a3 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 1172 | static void loader_destroy_logical_device(const struct loader_instance *inst, |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1173 | struct loader_device *dev) { |
Jon Ashburn | e58f1a3 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 1174 | loader_heap_free(inst, dev->app_extension_props); |
BogDan Vatra | babfa70 | 2016-01-04 14:05:49 +0200 | [diff] [blame] | 1175 | loader_destroy_layer_list(inst, &dev->activated_layer_list); |
Jon Ashburn | e58f1a3 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 1176 | loader_heap_free(inst, dev); |
Jon Ashburn | cb5a5ac | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1177 | } |
| 1178 | |
Jon Ashburn | a9c4a57 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 1179 | struct loader_device * |
Piers Daniell | fc50041 | 2016-03-29 11:51:11 -0600 | [diff] [blame] | 1180 | loader_create_logical_device(const struct loader_instance *inst) { |
Jon Ashburn | cb5a5ac | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1181 | struct loader_device *new_dev; |
| 1182 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1183 | new_dev = loader_heap_alloc(inst, sizeof(struct loader_device), |
| 1184 | VK_SYSTEM_ALLOCATION_SCOPE_DEVICE); |
Jon Ashburn | cb5a5ac | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1185 | if (!new_dev) { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1186 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1187 | "Failed to alloc struct loader-device"); |
Jon Ashburn | cb5a5ac | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1188 | return NULL; |
| 1189 | } |
| 1190 | |
| 1191 | memset(new_dev, 0, sizeof(struct loader_device)); |
| 1192 | |
Jon Ashburn | cb5a5ac | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1193 | return new_dev; |
| 1194 | } |
| 1195 | |
Piers Daniell | fc50041 | 2016-03-29 11:51:11 -0600 | [diff] [blame] | 1196 | void loader_add_logical_device(const struct loader_instance *inst, |
| 1197 | struct loader_icd *icd, |
| 1198 | struct loader_device *dev) { |
| 1199 | dev->next = icd->logical_device_list; |
| 1200 | icd->logical_device_list = dev; |
| 1201 | } |
| 1202 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1203 | void loader_remove_logical_device(const struct loader_instance *inst, |
| 1204 | struct loader_icd *icd, |
| 1205 | struct loader_device *found_dev) { |
Jon Ashburn | dbf8cee | 2015-11-19 15:43:26 -0700 | [diff] [blame] | 1206 | struct loader_device *dev, *prev_dev; |
Jon Ashburn | cb5a5ac | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1207 | |
| 1208 | if (!icd || !found_dev) |
| 1209 | return; |
| 1210 | |
| 1211 | prev_dev = NULL; |
| 1212 | dev = icd->logical_device_list; |
| 1213 | while (dev && dev != found_dev) { |
| 1214 | prev_dev = dev; |
| 1215 | dev = dev->next; |
| 1216 | } |
| 1217 | |
| 1218 | if (prev_dev) |
| 1219 | prev_dev->next = found_dev->next; |
| 1220 | else |
| 1221 | icd->logical_device_list = found_dev->next; |
Jon Ashburn | e58f1a3 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 1222 | loader_destroy_logical_device(inst, found_dev); |
Jon Ashburn | cb5a5ac | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1223 | } |
| 1224 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1225 | static void loader_icd_destroy(struct loader_instance *ptr_inst, |
| 1226 | struct loader_icd *icd) { |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1227 | ptr_inst->total_icd_count--; |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1228 | for (struct loader_device *dev = icd->logical_device_list; dev;) { |
Courtney Goeltzenleuchter | 6b70e36 | 2015-06-14 19:57:15 -0600 | [diff] [blame] | 1229 | struct loader_device *next_dev = dev->next; |
Jon Ashburn | e58f1a3 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 1230 | loader_destroy_logical_device(ptr_inst, dev); |
Courtney Goeltzenleuchter | 6b70e36 | 2015-06-14 19:57:15 -0600 | [diff] [blame] | 1231 | dev = next_dev; |
| 1232 | } |
Jon Ashburn | cb5a5ac | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1233 | |
Jon Ashburn | e58f1a3 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 1234 | loader_heap_free(ptr_inst, icd); |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1235 | } |
| 1236 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1237 | static struct loader_icd * |
| 1238 | loader_icd_create(const struct loader_instance *inst) { |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1239 | struct loader_icd *icd; |
| 1240 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1241 | icd = loader_heap_alloc(inst, sizeof(*icd), |
| 1242 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1243 | if (!icd) |
| 1244 | return NULL; |
| 1245 | |
Courtney Goeltzenleuchter | 6f92816 | 2014-10-28 10:29:27 -0600 | [diff] [blame] | 1246 | memset(icd, 0, sizeof(*icd)); |
| 1247 | |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1248 | return icd; |
| 1249 | } |
| 1250 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1251 | static struct loader_icd * |
| 1252 | loader_icd_add(struct loader_instance *ptr_inst, |
| 1253 | const struct loader_scanned_icds *icd_lib) { |
Chia-I Wu | 894a117 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 1254 | struct loader_icd *icd; |
| 1255 | |
Jon Ashburn | e58f1a3 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 1256 | icd = loader_icd_create(ptr_inst); |
Chia-I Wu | 894a117 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 1257 | if (!icd) |
| 1258 | return NULL; |
| 1259 | |
Jon Ashburn | e9ca8fa | 2015-08-20 16:35:30 -0600 | [diff] [blame] | 1260 | icd->this_icd_lib = icd_lib; |
| 1261 | icd->this_instance = ptr_inst; |
| 1262 | |
Chia-I Wu | 894a117 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 1263 | /* prepend to the list */ |
Jon Ashburn | 3336df8 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 1264 | icd->next = ptr_inst->icds; |
| 1265 | ptr_inst->icds = icd; |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1266 | ptr_inst->total_icd_count++; |
Chia-I Wu | 894a117 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 1267 | |
| 1268 | return icd; |
| 1269 | } |
| 1270 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1271 | void loader_scanned_icd_clear(const struct loader_instance *inst, |
| 1272 | struct loader_icd_libs *icd_libs) { |
Jon Ashburn | 754f199 | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 1273 | if (icd_libs->capacity == 0) |
| 1274 | return; |
| 1275 | for (uint32_t i = 0; i < icd_libs->count; i++) { |
| 1276 | loader_platform_close_library(icd_libs->list[i].handle); |
Jon Ashburn | e58f1a3 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 1277 | loader_heap_free(inst, icd_libs->list[i].lib_name); |
Jon Ashburn | 754f199 | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 1278 | } |
Jon Ashburn | e58f1a3 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 1279 | loader_heap_free(inst, icd_libs->list); |
Jon Ashburn | 754f199 | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 1280 | icd_libs->capacity = 0; |
| 1281 | icd_libs->count = 0; |
| 1282 | icd_libs->list = NULL; |
| 1283 | } |
| 1284 | |
Jon Ashburn | e58f1a3 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 1285 | static void loader_scanned_icd_init(const struct loader_instance *inst, |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1286 | struct loader_icd_libs *icd_libs) { |
Jon Ashburn | e58f1a3 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 1287 | loader_scanned_icd_clear(inst, icd_libs); |
Jon Ashburn | 754f199 | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 1288 | icd_libs->capacity = 8 * sizeof(struct loader_scanned_icds); |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1289 | icd_libs->list = loader_heap_alloc(inst, icd_libs->capacity, |
| 1290 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Jon Ashburn | 754f199 | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 1291 | } |
| 1292 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1293 | static void loader_scanned_icd_add(const struct loader_instance *inst, |
| 1294 | struct loader_icd_libs *icd_libs, |
| 1295 | const char *filename, uint32_t api_version) { |
Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1296 | loader_platform_dl_handle handle; |
Tony Barbour | de4124d | 2015-07-03 10:33:54 -0600 | [diff] [blame] | 1297 | PFN_vkCreateInstance fp_create_inst; |
Jon Ashburn | 6b68994 | 2016-01-07 09:44:27 -0700 | [diff] [blame] | 1298 | PFN_vkEnumerateInstanceExtensionProperties fp_get_inst_ext_props; |
Jon Ashburn | ce7e3d9 | 2015-07-16 10:17:29 -0600 | [diff] [blame] | 1299 | PFN_vkGetInstanceProcAddr fp_get_proc_addr; |
Jon Ashburn | 14275da | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 1300 | struct loader_scanned_icds *new_node; |
| 1301 | |
Jon Ashburn | 754f199 | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 1302 | /* TODO implement ref counting of libraries, for now this function leaves |
| 1303 | libraries open and the scanned_icd_clear closes them */ |
Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1304 | // Used to call: dlopen(filename, RTLD_LAZY); |
| 1305 | handle = loader_platform_open_library(filename); |
Jon Ashburn | 14275da | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 1306 | if (!handle) { |
Mark Lobodzinski | 5c13d4d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 1307 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1308 | loader_platform_open_library_error(filename)); |
Jon Ashburn | 14275da | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 1309 | return; |
| 1310 | } |
| 1311 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1312 | fp_get_proc_addr = |
| 1313 | loader_platform_get_proc_address(handle, "vk_icdGetInstanceProcAddr"); |
Jon Ashburn | 6b68994 | 2016-01-07 09:44:27 -0700 | [diff] [blame] | 1314 | if (!fp_get_proc_addr) { |
Jon Ashburn | 3f19e05 | 2016-01-11 14:41:35 -0700 | [diff] [blame] | 1315 | // Use deprecated interface |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1316 | fp_get_proc_addr = |
| 1317 | loader_platform_get_proc_address(handle, "vkGetInstanceProcAddr"); |
Jon Ashburn | 6b68994 | 2016-01-07 09:44:27 -0700 | [diff] [blame] | 1318 | if (!fp_get_proc_addr) { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1319 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1320 | loader_platform_get_proc_address_error( |
| 1321 | "vk_icdGetInstanceProcAddr")); |
Jon Ashburn | 6b68994 | 2016-01-07 09:44:27 -0700 | [diff] [blame] | 1322 | return; |
| 1323 | } else { |
Mark Lobodzinski | 5c13d4d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 1324 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1325 | "Using deprecated ICD interface of " |
| 1326 | "vkGetInstanceProcAddr instead of " |
| 1327 | "vk_icdGetInstanceProcAddr"); |
Jon Ashburn | 6b68994 | 2016-01-07 09:44:27 -0700 | [diff] [blame] | 1328 | } |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1329 | fp_create_inst = |
| 1330 | loader_platform_get_proc_address(handle, "vkCreateInstance"); |
Jon Ashburn | 3f19e05 | 2016-01-11 14:41:35 -0700 | [diff] [blame] | 1331 | if (!fp_create_inst) { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1332 | loader_log( |
| 1333 | inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1334 | "Couldn't get vkCreateInstance via dlsym/loadlibrary from ICD"); |
Jon Ashburn | 3f19e05 | 2016-01-11 14:41:35 -0700 | [diff] [blame] | 1335 | return; |
| 1336 | } |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1337 | fp_get_inst_ext_props = loader_platform_get_proc_address( |
| 1338 | handle, "vkEnumerateInstanceExtensionProperties"); |
Jon Ashburn | 3f19e05 | 2016-01-11 14:41:35 -0700 | [diff] [blame] | 1339 | if (!fp_get_inst_ext_props) { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1340 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1341 | "Couldn't get vkEnumerateInstanceExtensionProperties " |
| 1342 | "via dlsym/loadlibrary from ICD"); |
Jon Ashburn | 3f19e05 | 2016-01-11 14:41:35 -0700 | [diff] [blame] | 1343 | return; |
| 1344 | } |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1345 | } else { |
Jon Ashburn | 3f19e05 | 2016-01-11 14:41:35 -0700 | [diff] [blame] | 1346 | // Use newer interface |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1347 | fp_create_inst = |
| 1348 | (PFN_vkCreateInstance)fp_get_proc_addr(NULL, "vkCreateInstance"); |
Jon Ashburn | 3f19e05 | 2016-01-11 14:41:35 -0700 | [diff] [blame] | 1349 | if (!fp_create_inst) { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1350 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1351 | "Couldn't get vkCreateInstance via " |
| 1352 | "vk_icdGetInstanceProcAddr from ICD"); |
Jon Ashburn | 3f19e05 | 2016-01-11 14:41:35 -0700 | [diff] [blame] | 1353 | return; |
| 1354 | } |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1355 | fp_get_inst_ext_props = |
| 1356 | (PFN_vkEnumerateInstanceExtensionProperties)fp_get_proc_addr( |
| 1357 | NULL, "vkEnumerateInstanceExtensionProperties"); |
Jon Ashburn | 3f19e05 | 2016-01-11 14:41:35 -0700 | [diff] [blame] | 1358 | if (!fp_get_inst_ext_props) { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1359 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1360 | "Couldn't get vkEnumerateInstanceExtensionProperties " |
| 1361 | "via vk_icdGetInstanceProcAddr from ICD"); |
Jon Ashburn | 3f19e05 | 2016-01-11 14:41:35 -0700 | [diff] [blame] | 1362 | return; |
| 1363 | } |
Jon Ashburn | 6b68994 | 2016-01-07 09:44:27 -0700 | [diff] [blame] | 1364 | } |
Jon Ashburn | 14275da | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 1365 | |
Jon Ashburn | 754f199 | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 1366 | // check for enough capacity |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1367 | if ((icd_libs->count * sizeof(struct loader_scanned_icds)) >= |
| 1368 | icd_libs->capacity) { |
Jon Ashburn | e58f1a3 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 1369 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1370 | icd_libs->list = loader_heap_realloc( |
| 1371 | inst, icd_libs->list, icd_libs->capacity, icd_libs->capacity * 2, |
| 1372 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
| 1373 | // double capacity |
| 1374 | icd_libs->capacity *= 2; |
Jon Ashburn | 14275da | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 1375 | } |
Jon Ashburn | 754f199 | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 1376 | new_node = &(icd_libs->list[icd_libs->count]); |
Jon Ashburn | 14275da | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 1377 | |
| 1378 | new_node->handle = handle; |
Jon Ashburn | 0083b22 | 2015-11-17 17:35:40 -0700 | [diff] [blame] | 1379 | new_node->api_version = api_version; |
Jon Ashburn | ce7e3d9 | 2015-07-16 10:17:29 -0600 | [diff] [blame] | 1380 | new_node->GetInstanceProcAddr = fp_get_proc_addr; |
Jon Ashburn | 6b68994 | 2016-01-07 09:44:27 -0700 | [diff] [blame] | 1381 | new_node->EnumerateInstanceExtensionProperties = fp_get_inst_ext_props; |
Jon Ashburn | 3336df8 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 1382 | new_node->CreateInstance = fp_create_inst; |
Jon Ashburn | 14275da | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 1383 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1384 | new_node->lib_name = (char *)loader_heap_alloc( |
| 1385 | inst, strlen(filename) + 1, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1386 | if (!new_node->lib_name) { |
Mark Lobodzinski | 5c13d4d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 1387 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1388 | "Out of memory can't add icd"); |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1389 | return; |
| 1390 | } |
| 1391 | strcpy(new_node->lib_name, filename); |
Jon Ashburn | 754f199 | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 1392 | icd_libs->count++; |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1393 | } |
Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1394 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1395 | static bool loader_icd_init_entrys(struct loader_icd *icd, VkInstance inst, |
| 1396 | const PFN_vkGetInstanceProcAddr fp_gipa) { |
| 1397 | /* initialize entrypoint function pointers */ |
Jon Ashburn | 0dd356d | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 1398 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1399 | #define LOOKUP_GIPA(func, required) \ |
| 1400 | do { \ |
| 1401 | icd->func = (PFN_vk##func)fp_gipa(inst, "vk" #func); \ |
| 1402 | if (!icd->func && required) { \ |
| 1403 | loader_log((struct loader_instance *)inst, \ |
Jon Ashburn | a9c4a57 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 1404 | VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, \ |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1405 | loader_platform_get_proc_address_error("vk" #func)); \ |
| 1406 | return false; \ |
| 1407 | } \ |
Jon Ashburn | 0dd356d | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 1408 | } while (0) |
| 1409 | |
Jon Ashburn | ce7e3d9 | 2015-07-16 10:17:29 -0600 | [diff] [blame] | 1410 | LOOKUP_GIPA(GetDeviceProcAddr, true); |
| 1411 | LOOKUP_GIPA(DestroyInstance, true); |
| 1412 | LOOKUP_GIPA(EnumeratePhysicalDevices, true); |
| 1413 | LOOKUP_GIPA(GetPhysicalDeviceFeatures, true); |
| 1414 | LOOKUP_GIPA(GetPhysicalDeviceFormatProperties, true); |
Jon Ashburn | 4e18956 | 2015-07-23 18:49:07 -0600 | [diff] [blame] | 1415 | LOOKUP_GIPA(GetPhysicalDeviceImageFormatProperties, true); |
Jon Ashburn | ce7e3d9 | 2015-07-16 10:17:29 -0600 | [diff] [blame] | 1416 | LOOKUP_GIPA(CreateDevice, true); |
| 1417 | LOOKUP_GIPA(GetPhysicalDeviceProperties, true); |
| 1418 | LOOKUP_GIPA(GetPhysicalDeviceMemoryProperties, true); |
Cody Northrop | ef72e2a | 2015-08-03 17:04:53 -0600 | [diff] [blame] | 1419 | LOOKUP_GIPA(GetPhysicalDeviceQueueFamilyProperties, true); |
Courtney Goeltzenleuchter | 74c4ce9 | 2015-09-14 17:22:16 -0600 | [diff] [blame] | 1420 | LOOKUP_GIPA(EnumerateDeviceExtensionProperties, true); |
Jon Ashburn | ce7e3d9 | 2015-07-16 10:17:29 -0600 | [diff] [blame] | 1421 | LOOKUP_GIPA(GetPhysicalDeviceSparseImageFormatProperties, true); |
Courtney Goeltzenleuchter | acb1359 | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1422 | LOOKUP_GIPA(CreateDebugReportCallbackEXT, false); |
| 1423 | LOOKUP_GIPA(DestroyDebugReportCallbackEXT, false); |
Ian Elliott | 338dedb | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 1424 | LOOKUP_GIPA(GetPhysicalDeviceSurfaceSupportKHR, false); |
Ian Elliott | 8cda180 | 2015-11-19 16:05:09 -0700 | [diff] [blame] | 1425 | LOOKUP_GIPA(GetPhysicalDeviceSurfaceCapabilitiesKHR, false); |
| 1426 | LOOKUP_GIPA(GetPhysicalDeviceSurfaceFormatsKHR, false); |
| 1427 | LOOKUP_GIPA(GetPhysicalDeviceSurfacePresentModesKHR, false); |
Petros Bantolas | 5ba5d5d | 2016-04-14 12:50:42 +0100 | [diff] [blame] | 1428 | LOOKUP_GIPA(GetPhysicalDeviceDisplayPropertiesKHR, false); |
| 1429 | LOOKUP_GIPA(GetDisplayModePropertiesKHR, false); |
| 1430 | LOOKUP_GIPA(CreateDisplayPlaneSurfaceKHR, false); |
| 1431 | LOOKUP_GIPA(GetPhysicalDeviceDisplayPlanePropertiesKHR, false); |
| 1432 | LOOKUP_GIPA(GetDisplayPlaneSupportedDisplaysKHR, false); |
| 1433 | LOOKUP_GIPA(CreateDisplayModeKHR, false); |
| 1434 | LOOKUP_GIPA(GetDisplayPlaneCapabilitiesKHR, false); |
| 1435 | LOOKUP_GIPA(DestroySurfaceKHR, false); |
Ian Elliott | 4e309e9 | 2015-11-24 15:39:10 -0700 | [diff] [blame] | 1436 | #ifdef VK_USE_PLATFORM_WIN32_KHR |
| 1437 | LOOKUP_GIPA(GetPhysicalDeviceWin32PresentationSupportKHR, false); |
| 1438 | #endif |
| 1439 | #ifdef VK_USE_PLATFORM_XCB_KHR |
| 1440 | LOOKUP_GIPA(GetPhysicalDeviceXcbPresentationSupportKHR, false); |
| 1441 | #endif |
Karl Schultz | b7cfe36 | 2016-03-08 07:55:27 -0700 | [diff] [blame] | 1442 | #ifdef VK_USE_PLATFORM_XLIB_KHR |
| 1443 | LOOKUP_GIPA(GetPhysicalDeviceXlibPresentationSupportKHR, false); |
| 1444 | #endif |
Jason Ekstrand | cd0672c | 2016-02-12 17:25:03 -0800 | [diff] [blame] | 1445 | #ifdef VK_USE_PLATFORM_WAYLAND_KHR |
| 1446 | LOOKUP_GIPA(GetPhysicalDeviceWaylandPresentationSupportKHR, false); |
| 1447 | #endif |
Jon Ashburn | 0dd356d | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 1448 | |
Jon Ashburn | ce7e3d9 | 2015-07-16 10:17:29 -0600 | [diff] [blame] | 1449 | #undef LOOKUP_GIPA |
Ian Elliott | 1d73e66 | 2015-07-06 14:36:13 -0600 | [diff] [blame] | 1450 | |
Jon Ashburn | ce7e3d9 | 2015-07-16 10:17:29 -0600 | [diff] [blame] | 1451 | return true; |
Jon Ashburn | 0dd356d | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 1452 | } |
| 1453 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1454 | static void loader_debug_init(void) { |
Jon Ashburn | 5b25d9f | 2016-01-04 14:01:38 -0700 | [diff] [blame] | 1455 | const char *env, *orig; |
Courtney Goeltzenleuchter | 8b253f9 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 1456 | |
| 1457 | if (g_loader_debug > 0) |
| 1458 | return; |
| 1459 | |
| 1460 | g_loader_debug = 0; |
| 1461 | |
| 1462 | /* parse comma-separated debug options */ |
Jon Ashburn | 5b25d9f | 2016-01-04 14:01:38 -0700 | [diff] [blame] | 1463 | orig = env = loader_getenv("VK_LOADER_DEBUG"); |
Courtney Goeltzenleuchter | 8b253f9 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 1464 | while (env) { |
| 1465 | const char *p = strchr(env, ','); |
| 1466 | size_t len; |
| 1467 | |
| 1468 | if (p) |
| 1469 | len = p - env; |
| 1470 | else |
| 1471 | len = strlen(env); |
| 1472 | |
| 1473 | if (len > 0) { |
Michael Worcester | c21f5ad | 2015-12-10 18:06:24 +0000 | [diff] [blame] | 1474 | if (strncmp(env, "all", len) == 0) { |
| 1475 | g_loader_debug = ~0u; |
| 1476 | g_loader_log_msgs = ~0u; |
| 1477 | } else if (strncmp(env, "warn", len) == 0) { |
Courtney Goeltzenleuchter | 8b253f9 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 1478 | g_loader_debug |= LOADER_WARN_BIT; |
Mark Lobodzinski | 5c13d4d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 1479 | g_loader_log_msgs |= VK_DEBUG_REPORT_WARNING_BIT_EXT; |
Courtney Goeltzenleuchter | 8b253f9 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 1480 | } else if (strncmp(env, "info", len) == 0) { |
| 1481 | g_loader_debug |= LOADER_INFO_BIT; |
Mark Lobodzinski | 5c13d4d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 1482 | g_loader_log_msgs |= VK_DEBUG_REPORT_INFORMATION_BIT_EXT; |
Courtney Goeltzenleuchter | 8b253f9 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 1483 | } else if (strncmp(env, "perf", len) == 0) { |
| 1484 | g_loader_debug |= LOADER_PERF_BIT; |
Jon Ashburn | a9c4a57 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 1485 | g_loader_log_msgs |= |
| 1486 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT; |
Courtney Goeltzenleuchter | 8b253f9 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 1487 | } else if (strncmp(env, "error", len) == 0) { |
| 1488 | g_loader_debug |= LOADER_ERROR_BIT; |
Courtney Goeltzenleuchter | acb1359 | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1489 | g_loader_log_msgs |= VK_DEBUG_REPORT_ERROR_BIT_EXT; |
Courtney Goeltzenleuchter | 8b253f9 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 1490 | } else if (strncmp(env, "debug", len) == 0) { |
| 1491 | g_loader_debug |= LOADER_DEBUG_BIT; |
Courtney Goeltzenleuchter | acb1359 | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1492 | g_loader_log_msgs |= VK_DEBUG_REPORT_DEBUG_BIT_EXT; |
Courtney Goeltzenleuchter | 8b253f9 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 1493 | } |
| 1494 | } |
| 1495 | |
| 1496 | if (!p) |
| 1497 | break; |
| 1498 | |
| 1499 | env = p + 1; |
| 1500 | } |
Jon Ashburn | 5b25d9f | 2016-01-04 14:01:38 -0700 | [diff] [blame] | 1501 | |
| 1502 | loader_free_getenv(orig); |
Courtney Goeltzenleuchter | 8b253f9 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 1503 | } |
| 1504 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1505 | void loader_initialize(void) { |
Jon Ashburn | d02fc2c | 2015-09-22 13:11:00 -0600 | [diff] [blame] | 1506 | // initialize mutexs |
Jon Ashburn | 754f199 | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 1507 | loader_platform_thread_create_mutex(&loader_lock); |
Jon Ashburn | d02fc2c | 2015-09-22 13:11:00 -0600 | [diff] [blame] | 1508 | loader_platform_thread_create_mutex(&loader_json_lock); |
Jon Ashburn | 754f199 | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 1509 | |
| 1510 | // initialize logging |
| 1511 | loader_debug_init(); |
Jon Ashburn | 413d658 | 2015-08-28 15:19:27 -0600 | [diff] [blame] | 1512 | |
| 1513 | // initial cJSON to use alloc callbacks |
| 1514 | cJSON_Hooks alloc_fns = { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1515 | .malloc_fn = loader_tls_heap_alloc, .free_fn = loader_tls_heap_free, |
Jon Ashburn | 413d658 | 2015-08-28 15:19:27 -0600 | [diff] [blame] | 1516 | }; |
| 1517 | cJSON_InitHooks(&alloc_fns); |
Jon Ashburn | 754f199 | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 1518 | } |
| 1519 | |
Jon Ashburn | ffd5d67 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1520 | struct loader_manifest_files { |
| 1521 | uint32_t count; |
| 1522 | char **filename_list; |
| 1523 | }; |
| 1524 | |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 1525 | /** |
Jon Ashburn | ffd5d67 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1526 | * 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] | 1527 | * |
| 1528 | * \returns |
Jon Ashburn | ffd5d67 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1529 | * A pointer to first char in the next path. |
| 1530 | * The next path (or NULL) in the list is returned in next_path. |
| 1531 | * Note: input string is modified in some cases. PASS IN A COPY! |
| 1532 | */ |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1533 | static char *loader_get_next_path(char *path) { |
Jon Ashburn | ffd5d67 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1534 | uint32_t len; |
| 1535 | char *next; |
| 1536 | |
| 1537 | if (path == NULL) |
| 1538 | return NULL; |
| 1539 | next = strchr(path, PATH_SEPERATOR); |
| 1540 | if (next == NULL) { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1541 | len = (uint32_t)strlen(path); |
Jon Ashburn | ffd5d67 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1542 | next = path + len; |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1543 | } else { |
Jon Ashburn | ffd5d67 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1544 | *next = '\0'; |
| 1545 | next++; |
| 1546 | } |
| 1547 | |
| 1548 | return next; |
| 1549 | } |
| 1550 | |
| 1551 | /** |
Daniel Dadap | 2e13fca | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 1552 | * Given a path which is absolute or relative, expand the path if relative or |
| 1553 | * leave the path unmodified if absolute. The base path to prepend to relative |
| 1554 | * paths is given in rel_base. |
Jon Ashburn | 3814450 | 2015-07-07 15:06:25 -0600 | [diff] [blame] | 1555 | * |
| 1556 | * \returns |
| 1557 | * A string in out_fullpath of the full absolute path |
Jon Ashburn | 3814450 | 2015-07-07 15:06:25 -0600 | [diff] [blame] | 1558 | */ |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1559 | static void loader_expand_path(const char *path, const char *rel_base, |
| 1560 | size_t out_size, char *out_fullpath) { |
Jon Ashburn | 3814450 | 2015-07-07 15:06:25 -0600 | [diff] [blame] | 1561 | if (loader_platform_is_path_absolute(path)) { |
Daniel Dadap | 2e13fca | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 1562 | // do not prepend a base to an absolute path |
| 1563 | rel_base = ""; |
Jon Ashburn | 3814450 | 2015-07-07 15:06:25 -0600 | [diff] [blame] | 1564 | } |
Daniel Dadap | 2e13fca | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 1565 | |
| 1566 | loader_platform_combine_path(out_fullpath, out_size, rel_base, path, NULL); |
Jon Ashburn | 3814450 | 2015-07-07 15:06:25 -0600 | [diff] [blame] | 1567 | } |
| 1568 | |
| 1569 | /** |
Jon Ashburn | ffd5d67 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1570 | * Given a filename (file) and a list of paths (dir), try to find an existing |
| 1571 | * file in the paths. If filename already is a path then no |
| 1572 | * searching in the given paths. |
| 1573 | * |
| 1574 | * \returns |
| 1575 | * A string in out_fullpath of either the full path or file. |
Jon Ashburn | ffd5d67 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1576 | */ |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1577 | static void loader_get_fullpath(const char *file, const char *dirs, |
| 1578 | size_t out_size, char *out_fullpath) { |
Daniel Dadap | 2e13fca | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 1579 | if (!loader_platform_is_path(file) && *dirs) { |
| 1580 | char *dirs_copy, *dir, *next_dir; |
| 1581 | |
| 1582 | dirs_copy = loader_stack_alloc(strlen(dirs) + 1); |
| 1583 | strcpy(dirs_copy, dirs); |
| 1584 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1585 | // find if file exists after prepending paths in given list |
| 1586 | for (dir = dirs_copy; *dir && (next_dir = loader_get_next_path(dir)); |
Daniel Dadap | 2e13fca | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 1587 | dir = next_dir) { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1588 | loader_platform_combine_path(out_fullpath, out_size, dir, file, |
| 1589 | NULL); |
Jon Ashburn | ffd5d67 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1590 | if (loader_platform_file_exists(out_fullpath)) { |
| 1591 | return; |
| 1592 | } |
Jon Ashburn | ffd5d67 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1593 | } |
| 1594 | } |
Daniel Dadap | 2e13fca | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 1595 | |
Jon Ashburn | ffd5d67 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1596 | snprintf(out_fullpath, out_size, "%s", file); |
| 1597 | } |
| 1598 | |
| 1599 | /** |
| 1600 | * Read a JSON file into a buffer. |
| 1601 | * |
| 1602 | * \returns |
| 1603 | * A pointer to a cJSON object representing the JSON parse tree. |
| 1604 | * This returned buffer should be freed by caller. |
| 1605 | */ |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1606 | static cJSON *loader_get_json(const struct loader_instance *inst, |
| 1607 | const char *filename) { |
Jon Ashburn | ffd5d67 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1608 | FILE *file; |
| 1609 | char *json_buf; |
| 1610 | cJSON *json; |
Mark Young | 2acdd15 | 2016-01-13 13:47:16 -0700 | [diff] [blame] | 1611 | size_t len; |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1612 | file = fopen(filename, "rb"); |
Jon Ashburn | a01fb3e | 2015-08-27 08:30:50 -0600 | [diff] [blame] | 1613 | if (!file) { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1614 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1615 | "Couldn't open JSON file %s", filename); |
Jon Ashburn | a01fb3e | 2015-08-27 08:30:50 -0600 | [diff] [blame] | 1616 | return NULL; |
| 1617 | } |
Jon Ashburn | ffd5d67 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1618 | fseek(file, 0, SEEK_END); |
| 1619 | len = ftell(file); |
| 1620 | fseek(file, 0, SEEK_SET); |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1621 | json_buf = (char *)loader_stack_alloc(len + 1); |
Jon Ashburn | ffd5d67 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1622 | if (json_buf == NULL) { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1623 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1624 | "Out of memory can't get JSON file"); |
Jon Ashburn | ffd5d67 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1625 | fclose(file); |
| 1626 | return NULL; |
| 1627 | } |
| 1628 | if (fread(json_buf, sizeof(char), len, file) != len) { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1629 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1630 | "fread failed can't get JSON file"); |
Jon Ashburn | ffd5d67 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1631 | fclose(file); |
| 1632 | return NULL; |
| 1633 | } |
| 1634 | fclose(file); |
| 1635 | json_buf[len] = '\0'; |
| 1636 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1637 | // parse text from file |
Jon Ashburn | ffd5d67 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1638 | json = cJSON_Parse(json_buf); |
| 1639 | if (json == NULL) |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1640 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1641 | "Can't parse JSON file %s", filename); |
Jon Ashburn | ffd5d67 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1642 | return json; |
| 1643 | } |
| 1644 | |
| 1645 | /** |
Jon Ashburn | e9ca8fa | 2015-08-20 16:35:30 -0600 | [diff] [blame] | 1646 | * Do a deep copy of the loader_layer_properties structure. |
| 1647 | */ |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1648 | static void loader_copy_layer_properties(const struct loader_instance *inst, |
| 1649 | struct loader_layer_properties *dst, |
| 1650 | struct loader_layer_properties *src) { |
Jon Ashburn | 738136f | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1651 | uint32_t cnt, i; |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1652 | memcpy(dst, src, sizeof(*src)); |
| 1653 | dst->instance_extension_list.list = |
| 1654 | loader_heap_alloc(inst, sizeof(VkExtensionProperties) * |
| 1655 | src->instance_extension_list.count, |
| 1656 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
| 1657 | dst->instance_extension_list.capacity = |
| 1658 | sizeof(VkExtensionProperties) * src->instance_extension_list.count; |
Jon Ashburn | e58f1a3 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 1659 | memcpy(dst->instance_extension_list.list, src->instance_extension_list.list, |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1660 | dst->instance_extension_list.capacity); |
| 1661 | dst->device_extension_list.list = |
| 1662 | loader_heap_alloc(inst, sizeof(struct loader_dev_ext_props) * |
| 1663 | src->device_extension_list.count, |
| 1664 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Jon Ashburn | 738136f | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1665 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1666 | dst->device_extension_list.capacity = |
| 1667 | sizeof(struct loader_dev_ext_props) * src->device_extension_list.count; |
Jon Ashburn | e58f1a3 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 1668 | memcpy(dst->device_extension_list.list, src->device_extension_list.list, |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1669 | dst->device_extension_list.capacity); |
Jon Ashburn | 738136f | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1670 | if (src->device_extension_list.count > 0 && |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1671 | src->device_extension_list.list->entrypoint_count > 0) { |
Jon Ashburn | 738136f | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1672 | cnt = src->device_extension_list.list->entrypoint_count; |
| 1673 | dst->device_extension_list.list->entrypoints = loader_heap_alloc( |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1674 | inst, sizeof(char *) * cnt, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Jon Ashburn | 738136f | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1675 | for (i = 0; i < cnt; i++) { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1676 | dst->device_extension_list.list->entrypoints[i] = loader_heap_alloc( |
| 1677 | inst, |
| 1678 | strlen(src->device_extension_list.list->entrypoints[i]) + 1, |
| 1679 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Jon Ashburn | 738136f | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1680 | strcpy(dst->device_extension_list.list->entrypoints[i], |
| 1681 | src->device_extension_list.list->entrypoints[i]); |
| 1682 | } |
| 1683 | } |
Jon Ashburn | e9ca8fa | 2015-08-20 16:35:30 -0600 | [diff] [blame] | 1684 | } |
| 1685 | |
Jon Ashburn | 715de58 | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 1686 | static bool |
| 1687 | loader_find_layer_name_list(const char *name, |
| 1688 | const struct loader_layer_list *layer_list) { |
| 1689 | if (!layer_list) |
| 1690 | return false; |
| 1691 | for (uint32_t j = 0; j < layer_list->count; j++) |
| 1692 | if (!strcmp(name, layer_list->list[j].info.layerName)) |
| 1693 | return true; |
| 1694 | return false; |
| 1695 | } |
| 1696 | |
| 1697 | static bool loader_find_layer_name(const char *name, uint32_t layer_count, |
| 1698 | const char **layer_list) { |
| 1699 | if (!layer_list) |
| 1700 | return false; |
| 1701 | for (uint32_t j = 0; j < layer_count; j++) |
| 1702 | if (!strcmp(name, layer_list[j])) |
| 1703 | return true; |
| 1704 | return false; |
| 1705 | } |
| 1706 | |
| 1707 | static bool loader_find_layer_name_array( |
| 1708 | const char *name, uint32_t layer_count, |
| 1709 | const char layer_list[][VK_MAX_EXTENSION_NAME_SIZE]) { |
| 1710 | if (!layer_list) |
| 1711 | return false; |
| 1712 | for (uint32_t j = 0; j < layer_count; j++) |
| 1713 | if (!strcmp(name, layer_list[j])) |
| 1714 | return true; |
| 1715 | return false; |
| 1716 | } |
| 1717 | |
| 1718 | /** |
| 1719 | * Searches through an array of layer names (ppp_layer_names) looking for a |
| 1720 | * layer key_name. |
| 1721 | * If not found then simply returns updating nothing. |
| 1722 | * Otherwise, it uses expand_count, expand_names adding them to layer names. |
Chris Forbes | 5ca7f06 | 2016-04-07 09:04:49 +1200 | [diff] [blame] | 1723 | * Any duplicate (pre-existing) expand_names in layer names are removed. |
| 1724 | * Order is otherwise preserved, with the layer key_name being replaced by the |
| 1725 | * expand_names. |
Jon Ashburn | 715de58 | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 1726 | * @param inst |
| 1727 | * @param layer_count |
| 1728 | * @param ppp_layer_names |
| 1729 | */ |
| 1730 | void loader_expand_layer_names( |
Jon Ashburn | 9b2a8c9 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 1731 | const struct loader_instance *inst, const char *key_name, |
Jon Ashburn | 715de58 | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 1732 | uint32_t expand_count, |
| 1733 | const char expand_names[][VK_MAX_EXTENSION_NAME_SIZE], |
Jon Ashburn | 9b2a8c9 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 1734 | uint32_t *layer_count, char const *const **ppp_layer_names) { |
Jon Ashburn | a0eecb2 | 2016-02-11 18:59:43 -0700 | [diff] [blame] | 1735 | |
Jon Ashburn | 9b2a8c9 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 1736 | char const *const *pp_src_layers = *ppp_layer_names; |
Jon Ashburn | 715de58 | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 1737 | |
Jon Ashburn | 9b2a8c9 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 1738 | if (!loader_find_layer_name(key_name, *layer_count, |
| 1739 | (char const **)pp_src_layers)) |
Chris Forbes | eef20d0 | 2016-04-06 20:49:02 +1200 | [diff] [blame] | 1740 | return; // didn't find the key_name in the list. |
Jon Ashburn | a0eecb2 | 2016-02-11 18:59:43 -0700 | [diff] [blame] | 1741 | |
Jon Ashburn | 715de58 | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 1742 | loader_log(inst, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, |
| 1743 | "Found meta layer %s, replacing with actual layer group", |
| 1744 | key_name); |
Chris Forbes | eef20d0 | 2016-04-06 20:49:02 +1200 | [diff] [blame] | 1745 | |
Jon Ashburn | 9b2a8c9 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 1746 | char const **pp_dst_layers = loader_heap_alloc( |
| 1747 | inst, (expand_count + *layer_count - 1) * sizeof(char const *), |
| 1748 | VK_SYSTEM_ALLOCATION_SCOPE_COMMAND); |
Chris Forbes | eef20d0 | 2016-04-06 20:49:02 +1200 | [diff] [blame] | 1749 | |
| 1750 | // copy layers from src to dst, stripping key_name and anything in |
| 1751 | // expand_names. |
| 1752 | uint32_t src_index, dst_index = 0; |
| 1753 | for (src_index = 0; src_index < *layer_count; src_index++) { |
Jon Ashburn | 9b2a8c9 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 1754 | if (loader_find_layer_name_array(pp_src_layers[src_index], expand_count, |
| 1755 | expand_names)) { |
Chris Forbes | 5ca7f06 | 2016-04-07 09:04:49 +1200 | [diff] [blame] | 1756 | continue; |
| 1757 | } |
| 1758 | |
| 1759 | if (!strcmp(pp_src_layers[src_index], key_name)) { |
| 1760 | // insert all expand_names in place of key_name |
| 1761 | uint32_t expand_index; |
Jon Ashburn | 9b2a8c9 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 1762 | for (expand_index = 0; expand_index < expand_count; |
| 1763 | expand_index++) { |
Chris Forbes | 5ca7f06 | 2016-04-07 09:04:49 +1200 | [diff] [blame] | 1764 | pp_dst_layers[dst_index++] = expand_names[expand_index]; |
| 1765 | } |
Chris Forbes | eef20d0 | 2016-04-06 20:49:02 +1200 | [diff] [blame] | 1766 | continue; |
Jon Ashburn | 715de58 | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 1767 | } |
Chris Forbes | eef20d0 | 2016-04-06 20:49:02 +1200 | [diff] [blame] | 1768 | |
| 1769 | pp_dst_layers[dst_index++] = pp_src_layers[src_index]; |
Jon Ashburn | 715de58 | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 1770 | } |
| 1771 | |
Chris Forbes | eef20d0 | 2016-04-06 20:49:02 +1200 | [diff] [blame] | 1772 | *ppp_layer_names = pp_dst_layers; |
| 1773 | *layer_count = dst_index; |
Jon Ashburn | 715de58 | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 1774 | } |
| 1775 | |
Chris Forbes | eef20d0 | 2016-04-06 20:49:02 +1200 | [diff] [blame] | 1776 | void loader_delete_shadow_dev_layer_names(const struct loader_instance *inst, |
| 1777 | const VkDeviceCreateInfo *orig, |
| 1778 | VkDeviceCreateInfo *ours) { |
| 1779 | /* Free the layer names array iff we had to reallocate it */ |
| 1780 | if (orig->ppEnabledLayerNames != ours->ppEnabledLayerNames) { |
| 1781 | loader_heap_free(inst, (void *)ours->ppEnabledLayerNames); |
Jon Ashburn | 715de58 | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 1782 | } |
| 1783 | } |
| 1784 | |
Chris Forbes | eef20d0 | 2016-04-06 20:49:02 +1200 | [diff] [blame] | 1785 | void loader_delete_shadow_inst_layer_names(const struct loader_instance *inst, |
| 1786 | const VkInstanceCreateInfo *orig, |
| 1787 | VkInstanceCreateInfo *ours) { |
| 1788 | /* Free the layer names array iff we had to reallocate it */ |
| 1789 | if (orig->ppEnabledLayerNames != ours->ppEnabledLayerNames) { |
| 1790 | loader_heap_free(inst, (void *)ours->ppEnabledLayerNames); |
Jon Ashburn | 715de58 | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 1791 | } |
| 1792 | } |
| 1793 | |
| 1794 | /** |
| 1795 | * Searches through the existing instance and device layer lists looking for |
| 1796 | * the set of required layer names. If found then it adds a meta property to the |
| 1797 | * layer list. |
| 1798 | * Assumes the required layers are the same for both instance and device lists. |
| 1799 | * @param inst |
| 1800 | * @param layer_count number of layers in layer_names |
| 1801 | * @param layer_names array of required layer names |
| 1802 | * @param layer_instance_list |
| 1803 | * @param layer_device_list |
| 1804 | */ |
| 1805 | static void loader_add_layer_property_meta( |
| 1806 | const struct loader_instance *inst, uint32_t layer_count, |
| 1807 | const char layer_names[][VK_MAX_EXTENSION_NAME_SIZE], |
| 1808 | struct loader_layer_list *layer_instance_list, |
| 1809 | struct loader_layer_list *layer_device_list) { |
| 1810 | uint32_t i, j; |
| 1811 | bool found; |
| 1812 | struct loader_layer_list *layer_list; |
| 1813 | |
Jon Ashburn | 9255c18 | 2016-02-19 15:22:10 -0700 | [diff] [blame] | 1814 | if (0 == layer_count || (!layer_instance_list && !layer_device_list)) |
| 1815 | return; |
| 1816 | if ((layer_instance_list && (layer_count > layer_instance_list->count)) && |
| 1817 | (layer_device_list && (layer_count > layer_device_list->count))) |
Jon Ashburn | 715de58 | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 1818 | return; |
| 1819 | |
| 1820 | for (j = 0; j < 2; j++) { |
| 1821 | if (j == 0) |
| 1822 | layer_list = layer_instance_list; |
| 1823 | else |
| 1824 | layer_list = layer_device_list; |
| 1825 | found = true; |
Jon Ashburn | 9255c18 | 2016-02-19 15:22:10 -0700 | [diff] [blame] | 1826 | if (layer_list == NULL) |
| 1827 | continue; |
Jon Ashburn | 715de58 | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 1828 | for (i = 0; i < layer_count; i++) { |
| 1829 | if (loader_find_layer_name_list(layer_names[i], layer_list)) |
| 1830 | continue; |
| 1831 | found = false; |
| 1832 | break; |
| 1833 | } |
| 1834 | |
| 1835 | struct loader_layer_properties *props; |
| 1836 | if (found) { |
| 1837 | props = loader_get_next_layer_property(inst, layer_list); |
| 1838 | props->type = VK_LAYER_TYPE_META_EXPLICT; |
| 1839 | strncpy(props->info.description, "LunarG Standard Validation Layer", |
| 1840 | sizeof(props->info.description)); |
| 1841 | props->info.implementationVersion = 1; |
| 1842 | strncpy(props->info.layerName, std_validation_str, |
| 1843 | sizeof(props->info.layerName)); |
| 1844 | // TODO what about specVersion? for now insert loader's built |
| 1845 | // version |
Jon Ashburn | 310a256 | 2016-04-07 11:57:03 -0600 | [diff] [blame] | 1846 | props->info.specVersion = VK_MAKE_VERSION(1, 0, VK_HEADER_VERSION); |
Jon Ashburn | 715de58 | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 1847 | } |
| 1848 | } |
| 1849 | } |
| 1850 | |
Jon Ashburn | e9ca8fa | 2015-08-20 16:35:30 -0600 | [diff] [blame] | 1851 | /** |
Jon Ashburn | 1b111de | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 1852 | * Given a cJSON struct (json) of the top level JSON object from layer manifest |
| 1853 | * file, add entry to the layer_list. |
Jon Ashburn | 8e4fab4 | 2015-08-03 17:19:30 -0600 | [diff] [blame] | 1854 | * 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] | 1855 | * |
| 1856 | * \returns |
| 1857 | * void |
| 1858 | * layer_list has a new entry and initialized accordingly. |
| 1859 | * If the json input object does not have all the required fields no entry |
| 1860 | * is added to the list. |
| 1861 | */ |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1862 | static void |
| 1863 | loader_add_layer_properties(const struct loader_instance *inst, |
| 1864 | struct loader_layer_list *layer_instance_list, |
| 1865 | struct loader_layer_list *layer_device_list, |
| 1866 | cJSON *json, bool is_implicit, char *filename) { |
Jon Ashburn | 1b111de | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 1867 | /* Fields in layer manifest file that are required: |
| 1868 | * (required) “file_format_version” |
| 1869 | * following are required in the "layer" object: |
| 1870 | * (required) "name" |
| 1871 | * (required) "type" |
| 1872 | * (required) “library_path” |
Jon Ashburn | 44fe006 | 2015-11-18 16:46:48 -0700 | [diff] [blame] | 1873 | * (required) “api_version” |
Jon Ashburn | 1b111de | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 1874 | * (required) “implementation_version” |
| 1875 | * (required) “description” |
| 1876 | * (required for implicit layers) “disable_environment” |
| 1877 | * |
| 1878 | * First get all required items and if any missing abort |
| 1879 | */ |
| 1880 | |
| 1881 | cJSON *item, *layer_node, *ext_item; |
| 1882 | char *temp; |
Jon Ashburn | 44fe006 | 2015-11-18 16:46:48 -0700 | [diff] [blame] | 1883 | char *name, *type, *library_path, *api_version; |
Jon Ashburn | 1b111de | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 1884 | char *implementation_version, *description; |
Karl Schultz | c50a598 | 2016-02-24 14:39:39 -0700 | [diff] [blame] | 1885 | cJSON *disable_environment = NULL; |
Jon Ashburn | 738136f | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1886 | int i, j; |
Jon Ashburn | c4748dc | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 1887 | VkExtensionProperties ext_prop; |
Jon Ashburn | 1b111de | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 1888 | item = cJSON_GetObjectItem(json, "file_format_version"); |
| 1889 | if (item == NULL) { |
| 1890 | return; |
| 1891 | } |
| 1892 | char *file_vers = cJSON_PrintUnformatted(item); |
Mark Lobodzinski | 5c13d4d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 1893 | loader_log(inst, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1894 | "Found manifest file %s, version %s", filename, file_vers); |
Jon Ashburn | 44fe006 | 2015-11-18 16:46:48 -0700 | [diff] [blame] | 1895 | if (strcmp(file_vers, "\"1.0.0\"") != 0) |
Mark Lobodzinski | 5c13d4d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 1896 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1897 | "Unexpected manifest file version (expected 1.0.0), may " |
| 1898 | "cause errors"); |
Jon Ashburn | 413d658 | 2015-08-28 15:19:27 -0600 | [diff] [blame] | 1899 | loader_tls_heap_free(file_vers); |
Jon Ashburn | 1b111de | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 1900 | |
Jon Ashburn | 1b111de | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 1901 | layer_node = cJSON_GetObjectItem(json, "layer"); |
| 1902 | if (layer_node == NULL) { |
Mark Lobodzinski | 5c13d4d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 1903 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1904 | "Can't find \"layer\" object in manifest JSON file, " |
| 1905 | "skipping this file"); |
Jon Ashburn | 1b111de | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 1906 | return; |
| 1907 | } |
Jon Ashburn | 082569b | 2015-08-12 16:39:32 -0600 | [diff] [blame] | 1908 | |
| 1909 | // loop through all "layer" objects in the file |
| 1910 | do { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1911 | #define GET_JSON_OBJECT(node, var) \ |
| 1912 | { \ |
| 1913 | var = cJSON_GetObjectItem(node, #var); \ |
| 1914 | if (var == NULL) { \ |
| 1915 | layer_node = layer_node->next; \ |
Jon Ashburn | a9c4a57 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 1916 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, \ |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1917 | "Didn't find required layer object %s in manifest " \ |
| 1918 | "JSON file, skipping this layer", \ |
| 1919 | #var); \ |
| 1920 | continue; \ |
| 1921 | } \ |
| 1922 | } |
| 1923 | #define GET_JSON_ITEM(node, var) \ |
| 1924 | { \ |
| 1925 | item = cJSON_GetObjectItem(node, #var); \ |
| 1926 | if (item == NULL) { \ |
| 1927 | layer_node = layer_node->next; \ |
Jon Ashburn | a9c4a57 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 1928 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, \ |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1929 | "Didn't find required layer value %s in manifest JSON " \ |
| 1930 | "file, skipping this layer", \ |
| 1931 | #var); \ |
| 1932 | continue; \ |
| 1933 | } \ |
| 1934 | temp = cJSON_Print(item); \ |
| 1935 | temp[strlen(temp) - 1] = '\0'; \ |
| 1936 | var = loader_stack_alloc(strlen(temp) + 1); \ |
| 1937 | strcpy(var, &temp[1]); \ |
| 1938 | loader_tls_heap_free(temp); \ |
| 1939 | } |
Jon Ashburn | 082569b | 2015-08-12 16:39:32 -0600 | [diff] [blame] | 1940 | GET_JSON_ITEM(layer_node, name) |
| 1941 | GET_JSON_ITEM(layer_node, type) |
| 1942 | GET_JSON_ITEM(layer_node, library_path) |
Jon Ashburn | 44fe006 | 2015-11-18 16:46:48 -0700 | [diff] [blame] | 1943 | GET_JSON_ITEM(layer_node, api_version) |
Jon Ashburn | 082569b | 2015-08-12 16:39:32 -0600 | [diff] [blame] | 1944 | GET_JSON_ITEM(layer_node, implementation_version) |
| 1945 | GET_JSON_ITEM(layer_node, description) |
| 1946 | if (is_implicit) { |
| 1947 | GET_JSON_OBJECT(layer_node, disable_environment) |
| 1948 | } |
Jon Ashburn | 1b111de | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 1949 | #undef GET_JSON_ITEM |
| 1950 | #undef GET_JSON_OBJECT |
| 1951 | |
Jon Ashburn | 082569b | 2015-08-12 16:39:32 -0600 | [diff] [blame] | 1952 | // add list entry |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1953 | struct loader_layer_properties *props = NULL; |
Jon Ashburn | 082569b | 2015-08-12 16:39:32 -0600 | [diff] [blame] | 1954 | if (!strcmp(type, "DEVICE")) { |
| 1955 | if (layer_device_list == NULL) { |
| 1956 | layer_node = layer_node->next; |
| 1957 | continue; |
| 1958 | } |
Jon Ashburn | e58f1a3 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 1959 | props = loader_get_next_layer_property(inst, layer_device_list); |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1960 | props->type = (is_implicit) ? VK_LAYER_TYPE_DEVICE_IMPLICIT |
| 1961 | : VK_LAYER_TYPE_DEVICE_EXPLICIT; |
Jon Ashburn | 082569b | 2015-08-12 16:39:32 -0600 | [diff] [blame] | 1962 | } |
| 1963 | if (!strcmp(type, "INSTANCE")) { |
| 1964 | if (layer_instance_list == NULL) { |
| 1965 | layer_node = layer_node->next; |
| 1966 | continue; |
| 1967 | } |
Jon Ashburn | e58f1a3 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 1968 | props = loader_get_next_layer_property(inst, layer_instance_list); |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1969 | props->type = (is_implicit) ? VK_LAYER_TYPE_INSTANCE_IMPLICIT |
| 1970 | : VK_LAYER_TYPE_INSTANCE_EXPLICIT; |
Jon Ashburn | 082569b | 2015-08-12 16:39:32 -0600 | [diff] [blame] | 1971 | } |
| 1972 | if (!strcmp(type, "GLOBAL")) { |
| 1973 | if (layer_instance_list != NULL) |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1974 | props = |
| 1975 | loader_get_next_layer_property(inst, layer_instance_list); |
Jon Ashburn | 082569b | 2015-08-12 16:39:32 -0600 | [diff] [blame] | 1976 | else if (layer_device_list != NULL) |
Jon Ashburn | e58f1a3 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 1977 | props = loader_get_next_layer_property(inst, layer_device_list); |
Jon Ashburn | 082569b | 2015-08-12 16:39:32 -0600 | [diff] [blame] | 1978 | else { |
| 1979 | layer_node = layer_node->next; |
| 1980 | continue; |
| 1981 | } |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1982 | props->type = (is_implicit) ? VK_LAYER_TYPE_GLOBAL_IMPLICIT |
| 1983 | : VK_LAYER_TYPE_GLOBAL_EXPLICIT; |
Jon Ashburn | 082569b | 2015-08-12 16:39:32 -0600 | [diff] [blame] | 1984 | } |
Jon Ashburn | 0bf6a18 | 2015-07-16 17:19:31 -0600 | [diff] [blame] | 1985 | |
Jon Ashburn | b8605fe | 2015-09-18 12:53:16 -0600 | [diff] [blame] | 1986 | if (props == NULL) { |
| 1987 | layer_node = layer_node->next; |
| 1988 | continue; |
| 1989 | } |
| 1990 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1991 | strncpy(props->info.layerName, name, sizeof(props->info.layerName)); |
| 1992 | props->info.layerName[sizeof(props->info.layerName) - 1] = '\0'; |
Jon Ashburn | 3814450 | 2015-07-07 15:06:25 -0600 | [diff] [blame] | 1993 | |
Jon Ashburn | 082569b | 2015-08-12 16:39:32 -0600 | [diff] [blame] | 1994 | char *rel_base; |
Jon Ashburn | fc8f38d | 2015-12-01 17:11:02 -0700 | [diff] [blame] | 1995 | if (loader_platform_is_path(library_path)) { |
Jon Ashburn | 082569b | 2015-08-12 16:39:32 -0600 | [diff] [blame] | 1996 | // a relative or absolute path |
Daniel Dadap | 2e13fca | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 1997 | char *name_copy = loader_stack_alloc(strlen(filename) + 1); |
Jon Ashburn | 082569b | 2015-08-12 16:39:32 -0600 | [diff] [blame] | 1998 | strcpy(name_copy, filename); |
| 1999 | rel_base = loader_platform_dirname(name_copy); |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2000 | loader_expand_path(library_path, rel_base, MAX_STRING_SIZE, |
Jon Ashburn | b1e6b56 | 2016-04-15 13:19:43 -0600 | [diff] [blame] | 2001 | props->lib_name); |
Daniel Dadap | 2e13fca | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 2002 | } else { |
Jon Ashburn | b1e6b56 | 2016-04-15 13:19:43 -0600 | [diff] [blame] | 2003 | // a filename which will be passed to the OSes library loader |
| 2004 | strncpy(props->lib_name, library_path, sizeof(props->lib_name)); |
| 2005 | props->lib_name[sizeof(props->lib_name) - 1] = '\0'; |
Jon Ashburn | 082569b | 2015-08-12 16:39:32 -0600 | [diff] [blame] | 2006 | } |
Jon Ashburn | 44fe006 | 2015-11-18 16:46:48 -0700 | [diff] [blame] | 2007 | props->info.specVersion = loader_make_version(api_version); |
| 2008 | props->info.implementationVersion = atoi(implementation_version); |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2009 | strncpy((char *)props->info.description, description, |
| 2010 | sizeof(props->info.description)); |
| 2011 | props->info.description[sizeof(props->info.description) - 1] = '\0'; |
Jon Ashburn | 082569b | 2015-08-12 16:39:32 -0600 | [diff] [blame] | 2012 | if (is_implicit) { |
Jon Ashburn | 42afe58 | 2016-02-12 14:46:41 -0700 | [diff] [blame] | 2013 | if (!disable_environment || !disable_environment->child) { |
Jon Ashburn | a9c4a57 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 2014 | loader_log( |
| 2015 | inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 2016 | "Didn't find required layer child value disable_environment" |
| 2017 | "in manifest JSON file, skipping this layer"); |
Jon Ashburn | 42afe58 | 2016-02-12 14:46:41 -0700 | [diff] [blame] | 2018 | layer_node = layer_node->next; |
| 2019 | continue; |
| 2020 | } |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2021 | strncpy(props->disable_env_var.name, |
| 2022 | disable_environment->child->string, |
| 2023 | sizeof(props->disable_env_var.name)); |
| 2024 | props->disable_env_var |
| 2025 | .name[sizeof(props->disable_env_var.name) - 1] = '\0'; |
| 2026 | strncpy(props->disable_env_var.value, |
| 2027 | disable_environment->child->valuestring, |
| 2028 | sizeof(props->disable_env_var.value)); |
| 2029 | props->disable_env_var |
| 2030 | .value[sizeof(props->disable_env_var.value) - 1] = '\0'; |
Jon Ashburn | 082569b | 2015-08-12 16:39:32 -0600 | [diff] [blame] | 2031 | } |
Jon Ashburn | 1b111de | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 2032 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2033 | /** |
| 2034 | * Now get all optional items and objects and put in list: |
| 2035 | * functions |
| 2036 | * instance_extensions |
| 2037 | * device_extensions |
| 2038 | * enable_environment (implicit layers only) |
| 2039 | */ |
| 2040 | #define GET_JSON_OBJECT(node, var) \ |
| 2041 | { var = cJSON_GetObjectItem(node, #var); } |
| 2042 | #define GET_JSON_ITEM(node, var) \ |
| 2043 | { \ |
| 2044 | item = cJSON_GetObjectItem(node, #var); \ |
| 2045 | if (item != NULL) { \ |
| 2046 | temp = cJSON_Print(item); \ |
| 2047 | temp[strlen(temp) - 1] = '\0'; \ |
| 2048 | var = loader_stack_alloc(strlen(temp) + 1); \ |
| 2049 | strcpy(var, &temp[1]); \ |
| 2050 | loader_tls_heap_free(temp); \ |
| 2051 | } \ |
| 2052 | } |
Jon Ashburn | 1b111de | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 2053 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2054 | cJSON *instance_extensions, *device_extensions, *functions, |
| 2055 | *enable_environment; |
Jon Ashburn | 738136f | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 2056 | cJSON *entrypoints; |
| 2057 | char *vkGetInstanceProcAddr, *vkGetDeviceProcAddr, *spec_version; |
| 2058 | char **entry_array; |
| 2059 | vkGetInstanceProcAddr = NULL; |
| 2060 | vkGetDeviceProcAddr = NULL; |
| 2061 | spec_version = NULL; |
| 2062 | entrypoints = NULL; |
| 2063 | entry_array = NULL; |
| 2064 | /** |
| 2065 | * functions |
| 2066 | * vkGetInstanceProcAddr |
| 2067 | * vkGetDeviceProcAddr |
| 2068 | */ |
Jon Ashburn | 082569b | 2015-08-12 16:39:32 -0600 | [diff] [blame] | 2069 | GET_JSON_OBJECT(layer_node, functions) |
| 2070 | if (functions != NULL) { |
| 2071 | GET_JSON_ITEM(functions, vkGetInstanceProcAddr) |
| 2072 | GET_JSON_ITEM(functions, vkGetDeviceProcAddr) |
Jon Ashburn | 2db0804 | 2015-09-09 11:29:24 -0600 | [diff] [blame] | 2073 | if (vkGetInstanceProcAddr != NULL) |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2074 | strncpy(props->functions.str_gipa, vkGetInstanceProcAddr, |
| 2075 | sizeof(props->functions.str_gipa)); |
| 2076 | props->functions.str_gipa[sizeof(props->functions.str_gipa) - 1] = |
| 2077 | '\0'; |
Jon Ashburn | 2db0804 | 2015-09-09 11:29:24 -0600 | [diff] [blame] | 2078 | if (vkGetDeviceProcAddr != NULL) |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2079 | strncpy(props->functions.str_gdpa, vkGetDeviceProcAddr, |
| 2080 | sizeof(props->functions.str_gdpa)); |
| 2081 | props->functions.str_gdpa[sizeof(props->functions.str_gdpa) - 1] = |
| 2082 | '\0'; |
Jon Ashburn | 1b111de | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 2083 | } |
Jon Ashburn | 738136f | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 2084 | /** |
| 2085 | * instance_extensions |
| 2086 | * array of |
| 2087 | * name |
| 2088 | * spec_version |
| 2089 | */ |
Jon Ashburn | 082569b | 2015-08-12 16:39:32 -0600 | [diff] [blame] | 2090 | GET_JSON_OBJECT(layer_node, instance_extensions) |
| 2091 | if (instance_extensions != NULL) { |
| 2092 | int count = cJSON_GetArraySize(instance_extensions); |
| 2093 | for (i = 0; i < count; i++) { |
| 2094 | ext_item = cJSON_GetArrayItem(instance_extensions, i); |
| 2095 | GET_JSON_ITEM(ext_item, name) |
Jon Ashburn | 44fe006 | 2015-11-18 16:46:48 -0700 | [diff] [blame] | 2096 | GET_JSON_ITEM(ext_item, spec_version) |
Jon Ashburn | 738136f | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 2097 | if (name != NULL) { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2098 | strncpy(ext_prop.extensionName, name, |
| 2099 | sizeof(ext_prop.extensionName)); |
| 2100 | ext_prop.extensionName[sizeof(ext_prop.extensionName) - 1] = |
| 2101 | '\0'; |
Jon Ashburn | 738136f | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 2102 | } |
Jon Ashburn | 44fe006 | 2015-11-18 16:46:48 -0700 | [diff] [blame] | 2103 | ext_prop.specVersion = atoi(spec_version); |
Jon Ashburn | 9b2a8c9 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 2104 | bool ext_unsupported = |
| 2105 | wsi_unsupported_instance_extension(&ext_prop); |
Jon Ashburn | c666cff | 2016-03-25 12:49:35 -0600 | [diff] [blame] | 2106 | if (!ext_unsupported) { |
Jon Ashburn | 9b2a8c9 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 2107 | loader_add_to_ext_list( |
| 2108 | inst, &props->instance_extension_list, 1, &ext_prop); |
Jon Ashburn | c666cff | 2016-03-25 12:49:35 -0600 | [diff] [blame] | 2109 | } |
Jon Ashburn | 082569b | 2015-08-12 16:39:32 -0600 | [diff] [blame] | 2110 | } |
Jon Ashburn | 1b111de | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 2111 | } |
Jon Ashburn | 738136f | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 2112 | /** |
| 2113 | * device_extensions |
| 2114 | * array of |
| 2115 | * name |
| 2116 | * spec_version |
| 2117 | * entrypoints |
| 2118 | */ |
Jon Ashburn | 082569b | 2015-08-12 16:39:32 -0600 | [diff] [blame] | 2119 | GET_JSON_OBJECT(layer_node, device_extensions) |
| 2120 | if (device_extensions != NULL) { |
| 2121 | int count = cJSON_GetArraySize(device_extensions); |
| 2122 | for (i = 0; i < count; i++) { |
| 2123 | ext_item = cJSON_GetArrayItem(device_extensions, i); |
Jon Ashburn | 738136f | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 2124 | GET_JSON_ITEM(ext_item, name) |
| 2125 | GET_JSON_ITEM(ext_item, spec_version) |
| 2126 | if (name != NULL) { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2127 | strncpy(ext_prop.extensionName, name, |
| 2128 | sizeof(ext_prop.extensionName)); |
| 2129 | ext_prop.extensionName[sizeof(ext_prop.extensionName) - 1] = |
| 2130 | '\0'; |
Jon Ashburn | 738136f | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 2131 | } |
Jon Ashburn | 44fe006 | 2015-11-18 16:46:48 -0700 | [diff] [blame] | 2132 | ext_prop.specVersion = atoi(spec_version); |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2133 | // entrypoints = cJSON_GetObjectItem(ext_item, "entrypoints"); |
Jon Ashburn | 738136f | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 2134 | GET_JSON_OBJECT(ext_item, entrypoints) |
| 2135 | int entry_count; |
Courtney Goeltzenleuchter | d020070 | 2016-02-05 13:09:59 -0700 | [diff] [blame] | 2136 | if (entrypoints == NULL) { |
Jon Ashburn | 7ec85cd | 2016-02-10 20:50:19 -0700 | [diff] [blame] | 2137 | loader_add_to_dev_ext_list(inst, |
| 2138 | &props->device_extension_list, |
Courtney Goeltzenleuchter | d020070 | 2016-02-05 13:09:59 -0700 | [diff] [blame] | 2139 | &ext_prop, 0, NULL); |
Jon Ashburn | 738136f | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 2140 | continue; |
Courtney Goeltzenleuchter | d020070 | 2016-02-05 13:09:59 -0700 | [diff] [blame] | 2141 | } |
Jon Ashburn | 738136f | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 2142 | entry_count = cJSON_GetArraySize(entrypoints); |
| 2143 | if (entry_count) |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2144 | entry_array = (char **)loader_stack_alloc(sizeof(char *) * |
| 2145 | entry_count); |
Jon Ashburn | 738136f | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 2146 | for (j = 0; j < entry_count; j++) { |
| 2147 | ext_item = cJSON_GetArrayItem(entrypoints, j); |
| 2148 | if (ext_item != NULL) { |
| 2149 | temp = cJSON_Print(ext_item); |
| 2150 | temp[strlen(temp) - 1] = '\0'; |
| 2151 | entry_array[j] = loader_stack_alloc(strlen(temp) + 1); |
| 2152 | strcpy(entry_array[j], &temp[1]); |
| 2153 | loader_tls_heap_free(temp); |
Jon Ashburn | 8f6be30 | 2015-12-10 08:51:10 -0700 | [diff] [blame] | 2154 | } |
| 2155 | } |
Jon Ashburn | 738136f | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 2156 | loader_add_to_dev_ext_list(inst, &props->device_extension_list, |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2157 | &ext_prop, entry_count, entry_array); |
Jon Ashburn | 738136f | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 2158 | } |
| 2159 | } |
Jon Ashburn | 082569b | 2015-08-12 16:39:32 -0600 | [diff] [blame] | 2160 | if (is_implicit) { |
| 2161 | GET_JSON_OBJECT(layer_node, enable_environment) |
Jon Ashburn | d2c905c | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 2162 | |
| 2163 | // enable_environment is optional |
| 2164 | if (enable_environment) { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2165 | strncpy(props->enable_env_var.name, |
| 2166 | enable_environment->child->string, |
| 2167 | sizeof(props->enable_env_var.name)); |
| 2168 | props->enable_env_var |
| 2169 | .name[sizeof(props->enable_env_var.name) - 1] = '\0'; |
| 2170 | strncpy(props->enable_env_var.value, |
| 2171 | enable_environment->child->valuestring, |
| 2172 | sizeof(props->enable_env_var.value)); |
| 2173 | props->enable_env_var |
| 2174 | .value[sizeof(props->enable_env_var.value) - 1] = '\0'; |
Jon Ashburn | d2c905c | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 2175 | } |
Jon Ashburn | 082569b | 2015-08-12 16:39:32 -0600 | [diff] [blame] | 2176 | } |
Jon Ashburn | 1b111de | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 2177 | #undef GET_JSON_ITEM |
| 2178 | #undef GET_JSON_OBJECT |
Jon Ashburn | 082569b | 2015-08-12 16:39:32 -0600 | [diff] [blame] | 2179 | // for global layers need to add them to both device and instance list |
| 2180 | if (!strcmp(type, "GLOBAL")) { |
| 2181 | struct loader_layer_properties *dev_props; |
| 2182 | if (layer_instance_list == NULL || layer_device_list == NULL) { |
| 2183 | layer_node = layer_node->next; |
| 2184 | continue; |
| 2185 | } |
Jon Ashburn | e58f1a3 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 2186 | dev_props = loader_get_next_layer_property(inst, layer_device_list); |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2187 | // copy into device layer list |
Jon Ashburn | e58f1a3 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 2188 | loader_copy_layer_properties(inst, dev_props, props); |
Jon Ashburn | 082569b | 2015-08-12 16:39:32 -0600 | [diff] [blame] | 2189 | } |
| 2190 | layer_node = layer_node->next; |
| 2191 | } while (layer_node != NULL); |
| 2192 | return; |
Jon Ashburn | 1b111de | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 2193 | } |
| 2194 | |
| 2195 | /** |
Jon Ashburn | ffd5d67 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2196 | * Find the Vulkan library manifest files. |
| 2197 | * |
Jon Ashburn | a867ee4 | 2016-02-16 15:34:16 -0700 | [diff] [blame] | 2198 | * This function scans the "location" or "env_override" directories/files |
Jon Ashburn | ffd5d67 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2199 | * for a list of JSON manifest files. If env_override is non-NULL |
| 2200 | * and has a valid value. Then the location is ignored. Otherwise |
| 2201 | * location is used to look for manifest files. The location |
| 2202 | * is interpreted as Registry path on Windows and a directory path(s) |
Jon Ashburn | a867ee4 | 2016-02-16 15:34:16 -0700 | [diff] [blame] | 2203 | * on Linux. "home_location" is an additional directory in the users home |
| 2204 | * directory to look at. It is exapanded into the dir path $HOME/home_location. |
| 2205 | * This "home_location" is only used on Linux. |
Jon Ashburn | ffd5d67 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2206 | * |
| 2207 | * \returns |
| 2208 | * A string list of manifest files to be opened in out_files param. |
| 2209 | * List has a pointer to string for each manifest filename. |
| 2210 | * When done using the list in out_files, pointers should be freed. |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2211 | * Location or override string lists can be either files or directories as |
| 2212 | *follows: |
Jon Ashburn | ee33ae7 | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2213 | * | location | override |
| 2214 | * -------------------------------- |
| 2215 | * Win ICD | files | files |
| 2216 | * Win Layer | files | dirs |
| 2217 | * Linux ICD | dirs | files |
| 2218 | * Linux Layer| dirs | dirs |
Jon Ashburn | ffd5d67 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2219 | */ |
Jon Ashburn | e58f1a3 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 2220 | static void loader_get_manifest_files(const struct loader_instance *inst, |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2221 | const char *env_override, bool is_layer, |
Jon Ashburn | ee33ae7 | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2222 | const char *location, |
Jon Ashburn | a867ee4 | 2016-02-16 15:34:16 -0700 | [diff] [blame] | 2223 | const char *home_location, |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2224 | struct loader_manifest_files *out_files) { |
Jon Ashburn | ffd5d67 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2225 | char *override = NULL; |
| 2226 | char *loc; |
| 2227 | char *file, *next_file, *name; |
| 2228 | size_t alloced_count = 64; |
| 2229 | char full_path[2048]; |
| 2230 | DIR *sysdir = NULL; |
Jon Ashburn | ee33ae7 | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2231 | bool list_is_dirs = false; |
Jon Ashburn | ffd5d67 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2232 | struct dirent *dent; |
| 2233 | |
| 2234 | out_files->count = 0; |
| 2235 | out_files->filename_list = NULL; |
| 2236 | |
Jon Ashburn | 5b25d9f | 2016-01-04 14:01:38 -0700 | [diff] [blame] | 2237 | if (env_override != NULL && (override = loader_getenv(env_override))) { |
Johannes van Waveren | a6ce7b7 | 2015-10-28 11:45:00 -0500 | [diff] [blame] | 2238 | #if !defined(_WIN32) |
Jon Ashburn | 9b2a8c9 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 2239 | if (geteuid() != getuid() || getegid() != getgid()) { |
Jon Ashburn | ee33ae7 | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2240 | /* Don't allow setuid apps to use the env var: */ |
Jon Ashburn | 5b25d9f | 2016-01-04 14:01:38 -0700 | [diff] [blame] | 2241 | loader_free_getenv(override); |
Jon Ashburn | ffd5d67 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2242 | override = NULL; |
| 2243 | } |
| 2244 | #endif |
| 2245 | } |
| 2246 | |
Jon Ashburn | a867ee4 | 2016-02-16 15:34:16 -0700 | [diff] [blame] | 2247 | #if !defined(_WIN32) |
| 2248 | if (location == NULL && home_location == NULL) { |
| 2249 | #else |
| 2250 | home_location = NULL; |
Jon Ashburn | ffd5d67 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2251 | if (location == NULL) { |
Jon Ashburn | a867ee4 | 2016-02-16 15:34:16 -0700 | [diff] [blame] | 2252 | #endif |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2253 | loader_log( |
| 2254 | inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Jon Ashburn | ee33ae7 | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2255 | "Can't get manifest files with NULL location, env_override=%s", |
| 2256 | env_override); |
Jon Ashburn | ffd5d67 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2257 | return; |
| 2258 | } |
| 2259 | |
Johannes van Waveren | a6ce7b7 | 2015-10-28 11:45:00 -0500 | [diff] [blame] | 2260 | #if defined(_WIN32) |
Jon Ashburn | ee33ae7 | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2261 | list_is_dirs = (is_layer && override != NULL) ? true : false; |
Johannes van Waveren | a6ce7b7 | 2015-10-28 11:45:00 -0500 | [diff] [blame] | 2262 | #else |
| 2263 | list_is_dirs = (override == NULL || is_layer) ? true : false; |
Jon Ashburn | ee33ae7 | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2264 | #endif |
Jon Ashburn | ffd5d67 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2265 | // 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] | 2266 | // Also handle getting the location(s) from registry on Windows |
| 2267 | if (override == NULL) { |
Jon Ashburn | cdc9f0a | 2015-07-31 10:11:24 -0600 | [diff] [blame] | 2268 | loc = loader_stack_alloc(strlen(location) + 1); |
Jon Ashburn | ee33ae7 | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2269 | if (loc == NULL) { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2270 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 2271 | "Out of memory can't get manifest files"); |
Jon Ashburn | ee33ae7 | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2272 | return; |
| 2273 | } |
| 2274 | strcpy(loc, location); |
Johannes van Waveren | a6ce7b7 | 2015-10-28 11:45:00 -0500 | [diff] [blame] | 2275 | #if defined(_WIN32) |
Jon Ashburn | 6fb9a53 | 2015-08-28 14:58:46 -0700 | [diff] [blame] | 2276 | loc = loader_get_registry_files(inst, loc); |
Jon Ashburn | c1381ed | 2015-07-31 09:33:21 -0600 | [diff] [blame] | 2277 | if (loc == NULL) { |
Mark Lobodzinski | 5c13d4d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 2278 | if (!is_layer) { |
| 2279 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 2280 | "Registry lookup failed can't get ICD manifest " |
| 2281 | "files, do you have a Vulkan driver installed"); |
| 2282 | } else { |
| 2283 | // warning only for layers |
| 2284 | loader_log( |
| 2285 | inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 2286 | "Registry lookup failed can't get layer manifest files"); |
| 2287 | } |
Jon Ashburn | c1381ed | 2015-07-31 09:33:21 -0600 | [diff] [blame] | 2288 | return; |
| 2289 | } |
Jon Ashburn | ee33ae7 | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2290 | #endif |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2291 | } else { |
Courtney Goeltzenleuchter | b620ace | 2015-07-05 11:28:29 -0600 | [diff] [blame] | 2292 | loc = loader_stack_alloc(strlen(override) + 1); |
Jon Ashburn | ee33ae7 | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2293 | if (loc == NULL) { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2294 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 2295 | "Out of memory can't get manifest files"); |
Jon Ashburn | ee33ae7 | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2296 | return; |
| 2297 | } |
| 2298 | strcpy(loc, override); |
Jon Ashburn | 5b25d9f | 2016-01-04 14:01:38 -0700 | [diff] [blame] | 2299 | loader_free_getenv(override); |
Jon Ashburn | ee33ae7 | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2300 | } |
Jon Ashburn | ffd5d67 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2301 | |
Liam Middlebrook | f2a6ec4 | 2015-07-23 18:32:20 -0700 | [diff] [blame] | 2302 | // Print out the paths being searched if debugging is enabled |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2303 | loader_log(inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, |
| 2304 | "Searching the following paths for manifest files: %s\n", loc); |
Liam Middlebrook | f2a6ec4 | 2015-07-23 18:32:20 -0700 | [diff] [blame] | 2305 | |
Jon Ashburn | ffd5d67 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2306 | file = loc; |
| 2307 | while (*file) { |
| 2308 | next_file = loader_get_next_path(file); |
Jon Ashburn | ee33ae7 | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2309 | if (list_is_dirs) { |
Jon Ashburn | ffd5d67 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2310 | sysdir = opendir(file); |
| 2311 | name = NULL; |
| 2312 | if (sysdir) { |
| 2313 | dent = readdir(sysdir); |
| 2314 | if (dent == NULL) |
| 2315 | break; |
| 2316 | name = &(dent->d_name[0]); |
| 2317 | loader_get_fullpath(name, file, sizeof(full_path), full_path); |
| 2318 | name = full_path; |
| 2319 | } |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2320 | } else { |
Johannes van Waveren | a6ce7b7 | 2015-10-28 11:45:00 -0500 | [diff] [blame] | 2321 | #if defined(_WIN32) |
| 2322 | name = file; |
| 2323 | #else |
Jon Ashburn | ee33ae7 | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2324 | // only Linux has relative paths |
Jon Ashburn | ffd5d67 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2325 | char *dir; |
| 2326 | // make a copy of location so it isn't modified |
Jason Ekstrand | 35fa1a1 | 2015-10-10 08:33:37 -0700 | [diff] [blame] | 2327 | dir = loader_stack_alloc(strlen(loc) + 1); |
Jon Ashburn | ffd5d67 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2328 | if (dir == NULL) { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2329 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 2330 | "Out of memory can't get manifest files"); |
Jon Ashburn | ffd5d67 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2331 | return; |
| 2332 | } |
Jason Ekstrand | 35fa1a1 | 2015-10-10 08:33:37 -0700 | [diff] [blame] | 2333 | strcpy(dir, loc); |
Jon Ashburn | ffd5d67 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2334 | |
| 2335 | loader_get_fullpath(file, dir, sizeof(full_path), full_path); |
| 2336 | |
| 2337 | name = full_path; |
Jon Ashburn | ee33ae7 | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2338 | #endif |
Jon Ashburn | ffd5d67 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2339 | } |
| 2340 | while (name) { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2341 | /* Look for files ending with ".json" suffix */ |
| 2342 | uint32_t nlen = (uint32_t)strlen(name); |
| 2343 | const char *suf = name + nlen - 5; |
| 2344 | if ((nlen > 5) && !strncmp(suf, ".json", 5)) { |
| 2345 | if (out_files->count == 0) { |
| 2346 | out_files->filename_list = |
| 2347 | loader_heap_alloc(inst, alloced_count * sizeof(char *), |
| 2348 | VK_SYSTEM_ALLOCATION_SCOPE_COMMAND); |
| 2349 | } else if (out_files->count == alloced_count) { |
| 2350 | out_files->filename_list = |
| 2351 | loader_heap_realloc(inst, out_files->filename_list, |
| 2352 | alloced_count * sizeof(char *), |
| 2353 | alloced_count * sizeof(char *) * 2, |
| 2354 | VK_SYSTEM_ALLOCATION_SCOPE_COMMAND); |
| 2355 | alloced_count *= 2; |
Jon Ashburn | ffd5d67 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2356 | } |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2357 | if (out_files->filename_list == NULL) { |
| 2358 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 2359 | "Out of memory can't alloc manifest file list"); |
| 2360 | return; |
Jon Ashburn | ffd5d67 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2361 | } |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2362 | out_files->filename_list[out_files->count] = loader_heap_alloc( |
| 2363 | inst, strlen(name) + 1, VK_SYSTEM_ALLOCATION_SCOPE_COMMAND); |
| 2364 | if (out_files->filename_list[out_files->count] == NULL) { |
| 2365 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 2366 | "Out of memory can't get manifest files"); |
| 2367 | return; |
| 2368 | } |
| 2369 | strcpy(out_files->filename_list[out_files->count], name); |
| 2370 | out_files->count++; |
| 2371 | } else if (!list_is_dirs) { |
| 2372 | loader_log( |
Mark Lobodzinski | 5c13d4d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 2373 | inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2374 | "Skipping manifest file %s, file name must end in .json", |
| 2375 | name); |
| 2376 | } |
| 2377 | if (list_is_dirs) { |
| 2378 | dent = readdir(sysdir); |
| 2379 | if (dent == NULL) |
Jon Ashburn | ffd5d67 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2380 | break; |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2381 | name = &(dent->d_name[0]); |
| 2382 | loader_get_fullpath(name, file, sizeof(full_path), full_path); |
| 2383 | name = full_path; |
| 2384 | } else { |
| 2385 | break; |
| 2386 | } |
Jon Ashburn | ffd5d67 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2387 | } |
| 2388 | if (sysdir) |
| 2389 | closedir(sysdir); |
| 2390 | file = next_file; |
Jon Ashburn | 824e764 | 2016-02-18 12:45:39 -0700 | [diff] [blame] | 2391 | #if !defined(_WIN32) |
Jon Ashburn | a9c4a57 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 2392 | if (home_location != NULL && |
| 2393 | (next_file == NULL || *next_file == '\0') && override == NULL) { |
Jon Ashburn | 824e764 | 2016-02-18 12:45:39 -0700 | [diff] [blame] | 2394 | char *home = secure_getenv("HOME"); |
| 2395 | if (home != NULL) { |
| 2396 | size_t len; |
| 2397 | char *home_loc = loader_stack_alloc(strlen(home) + 2 + |
| 2398 | strlen(home_location)); |
| 2399 | if (home_loc == NULL) { |
| 2400 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Jon Ashburn | a9c4a57 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 2401 | "Out of memory can't get manifest files"); |
Jon Ashburn | 824e764 | 2016-02-18 12:45:39 -0700 | [diff] [blame] | 2402 | return; |
| 2403 | } |
| 2404 | strcpy(home_loc, home); |
| 2405 | // Add directory separator if needed |
| 2406 | if (home_location[0] != DIRECTORY_SYMBOL) { |
| 2407 | len = strlen(home_loc); |
| 2408 | home_loc[len] = DIRECTORY_SYMBOL; |
Jon Ashburn | a9c4a57 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 2409 | home_loc[len + 1] = '\0'; |
Jon Ashburn | 824e764 | 2016-02-18 12:45:39 -0700 | [diff] [blame] | 2410 | } |
| 2411 | strcat(home_loc, home_location); |
| 2412 | file = home_loc; |
| 2413 | next_file = loader_get_next_path(file); |
| 2414 | home_location = NULL; |
| 2415 | |
Jon Ashburn | a9c4a57 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 2416 | loader_log( |
| 2417 | inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, |
| 2418 | "Searching the following paths for manifest files: %s\n", |
| 2419 | home_loc); |
Jon Ashburn | 824e764 | 2016-02-18 12:45:39 -0700 | [diff] [blame] | 2420 | list_is_dirs = true; |
| 2421 | } |
| 2422 | } |
| 2423 | #endif |
Jon Ashburn | ffd5d67 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2424 | } |
| 2425 | return; |
| 2426 | } |
| 2427 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2428 | void loader_init_icd_lib_list() {} |
Jon Ashburn | 754f199 | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 2429 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2430 | void loader_destroy_icd_lib_list() {} |
Jon Ashburn | ffd5d67 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2431 | /** |
| 2432 | * Try to find the Vulkan ICD driver(s). |
| 2433 | * |
| 2434 | * This function scans the default system loader path(s) or path |
| 2435 | * specified by the \c VK_ICD_FILENAMES environment variable in |
| 2436 | * order to find loadable VK ICDs manifest files. From these |
| 2437 | * manifest files it finds the ICD libraries. |
| 2438 | * |
| 2439 | * \returns |
Jon Ashburn | 754f199 | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 2440 | * a list of icds that were discovered |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 2441 | */ |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2442 | void loader_icd_scan(const struct loader_instance *inst, |
| 2443 | struct loader_icd_libs *icds) { |
Jon Ashburn | ffd5d67 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2444 | char *file_str; |
| 2445 | struct loader_manifest_files manifest_files; |
| 2446 | |
Jon Ashburn | e58f1a3 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 2447 | loader_scanned_icd_init(inst, icds); |
Jon Ashburn | ffd5d67 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2448 | // Get a list of manifest files for ICDs |
Jon Ashburn | e58f1a3 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 2449 | loader_get_manifest_files(inst, "VK_ICD_FILENAMES", false, |
Jon Ashburn | a867ee4 | 2016-02-16 15:34:16 -0700 | [diff] [blame] | 2450 | DEFAULT_VK_DRIVERS_INFO, HOME_VK_DRIVERS_INFO, |
| 2451 | &manifest_files); |
Jon Ashburn | 1b111de | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 2452 | if (manifest_files.count == 0) |
| 2453 | return; |
Jon Ashburn | d02fc2c | 2015-09-22 13:11:00 -0600 | [diff] [blame] | 2454 | loader_platform_thread_lock_mutex(&loader_json_lock); |
Jon Ashburn | ffd5d67 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2455 | for (uint32_t i = 0; i < manifest_files.count; i++) { |
| 2456 | file_str = manifest_files.filename_list[i]; |
| 2457 | if (file_str == NULL) |
| 2458 | continue; |
| 2459 | |
Jon Ashburn | 1b111de | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 2460 | cJSON *json; |
Courtney Goeltzenleuchter | 05525da | 2015-12-03 13:48:01 -0700 | [diff] [blame] | 2461 | json = loader_get_json(inst, file_str); |
Jon Ashburn | a01fb3e | 2015-08-27 08:30:50 -0600 | [diff] [blame] | 2462 | if (!json) |
| 2463 | continue; |
Jon Ashburn | 0083b22 | 2015-11-17 17:35:40 -0700 | [diff] [blame] | 2464 | cJSON *item, *itemICD; |
Jon Ashburn | 1b111de | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 2465 | item = cJSON_GetObjectItem(json, "file_format_version"); |
Jon Ashburn | d02fc2c | 2015-09-22 13:11:00 -0600 | [diff] [blame] | 2466 | if (item == NULL) { |
| 2467 | loader_platform_thread_unlock_mutex(&loader_json_lock); |
Jon Ashburn | 1b111de | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 2468 | return; |
Jon Ashburn | d02fc2c | 2015-09-22 13:11:00 -0600 | [diff] [blame] | 2469 | } |
Jon Ashburn | 1b111de | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 2470 | char *file_vers = cJSON_Print(item); |
Mark Lobodzinski | 5c13d4d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 2471 | loader_log(inst, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2472 | "Found manifest file %s, version %s", file_str, file_vers); |
Jon Ashburn | 1b111de | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 2473 | if (strcmp(file_vers, "\"1.0.0\"") != 0) |
Mark Lobodzinski | 5c13d4d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 2474 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2475 | "Unexpected manifest file version (expected 1.0.0), may " |
| 2476 | "cause errors"); |
Jon Ashburn | 413d658 | 2015-08-28 15:19:27 -0600 | [diff] [blame] | 2477 | loader_tls_heap_free(file_vers); |
Jon Ashburn | 0083b22 | 2015-11-17 17:35:40 -0700 | [diff] [blame] | 2478 | itemICD = cJSON_GetObjectItem(json, "ICD"); |
| 2479 | if (itemICD != NULL) { |
| 2480 | item = cJSON_GetObjectItem(itemICD, "library_path"); |
Jon Ashburn | 1b111de | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 2481 | if (item != NULL) { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2482 | char *temp = cJSON_Print(item); |
Jon Ashburn | 10442c1 | 2015-08-25 16:48:24 -0600 | [diff] [blame] | 2483 | if (!temp || strlen(temp) == 0) { |
Mark Lobodzinski | 5c13d4d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 2484 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2485 | "Can't find \"library_path\" in ICD JSON file " |
| 2486 | "%s, skipping", |
| 2487 | file_str); |
Jon Ashburn | 413d658 | 2015-08-28 15:19:27 -0600 | [diff] [blame] | 2488 | loader_tls_heap_free(temp); |
Jon Ashburn | e58f1a3 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 2489 | loader_heap_free(inst, file_str); |
Jon Ashburn | 10442c1 | 2015-08-25 16:48:24 -0600 | [diff] [blame] | 2490 | cJSON_Delete(json); |
| 2491 | continue; |
Jon Ashburn | ffd5d67 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2492 | } |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2493 | // strip out extra quotes |
Jon Ashburn | 10442c1 | 2015-08-25 16:48:24 -0600 | [diff] [blame] | 2494 | temp[strlen(temp) - 1] = '\0'; |
| 2495 | char *library_path = loader_stack_alloc(strlen(temp) + 1); |
| 2496 | strcpy(library_path, &temp[1]); |
Jon Ashburn | 413d658 | 2015-08-28 15:19:27 -0600 | [diff] [blame] | 2497 | loader_tls_heap_free(temp); |
Jon Ashburn | 10442c1 | 2015-08-25 16:48:24 -0600 | [diff] [blame] | 2498 | if (!library_path || strlen(library_path) == 0) { |
Mark Lobodzinski | 5c13d4d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 2499 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2500 | "Can't find \"library_path\" in ICD JSON file " |
| 2501 | "%s, skipping", |
| 2502 | file_str); |
Jon Ashburn | e58f1a3 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 2503 | loader_heap_free(inst, file_str); |
Jon Ashburn | 10442c1 | 2015-08-25 16:48:24 -0600 | [diff] [blame] | 2504 | cJSON_Delete(json); |
| 2505 | continue; |
| 2506 | } |
Jon Ashburn | b1e6b56 | 2016-04-15 13:19:43 -0600 | [diff] [blame] | 2507 | char fullpath[MAX_STRING_SIZE], *fpath; |
Jon Ashburn | 10442c1 | 2015-08-25 16:48:24 -0600 | [diff] [blame] | 2508 | // Print out the paths being searched if debugging is enabled |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2509 | loader_log( |
| 2510 | inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, |
Jon Ashburn | b1e6b56 | 2016-04-15 13:19:43 -0600 | [diff] [blame] | 2511 | "Searching for ICD drivers named %s\n", |
| 2512 | library_path); |
Daniel Dadap | 2e13fca | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 2513 | if (loader_platform_is_path(library_path)) { |
Jon Ashburn | 10442c1 | 2015-08-25 16:48:24 -0600 | [diff] [blame] | 2514 | // a relative or absolute path |
Daniel Dadap | 2e13fca | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 2515 | char *name_copy = loader_stack_alloc(strlen(file_str) + 1); |
| 2516 | char *rel_base; |
Jon Ashburn | 10442c1 | 2015-08-25 16:48:24 -0600 | [diff] [blame] | 2517 | strcpy(name_copy, file_str); |
| 2518 | rel_base = loader_platform_dirname(name_copy); |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2519 | loader_expand_path(library_path, rel_base, sizeof(fullpath), |
| 2520 | fullpath); |
Jon Ashburn | b1e6b56 | 2016-04-15 13:19:43 -0600 | [diff] [blame] | 2521 | fpath = fullpath; |
Daniel Dadap | 2e13fca | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 2522 | } else { |
Jon Ashburn | b1e6b56 | 2016-04-15 13:19:43 -0600 | [diff] [blame] | 2523 | // a filename which will be passed to the OSes library loader |
| 2524 | fpath = library_path; |
Jon Ashburn | 10442c1 | 2015-08-25 16:48:24 -0600 | [diff] [blame] | 2525 | } |
Jon Ashburn | 0083b22 | 2015-11-17 17:35:40 -0700 | [diff] [blame] | 2526 | |
| 2527 | uint32_t vers = 0; |
| 2528 | item = cJSON_GetObjectItem(itemICD, "api_version"); |
| 2529 | if (item != NULL) { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2530 | temp = cJSON_Print(item); |
Jon Ashburn | 0083b22 | 2015-11-17 17:35:40 -0700 | [diff] [blame] | 2531 | vers = loader_make_version(temp); |
| 2532 | loader_tls_heap_free(temp); |
| 2533 | } |
Jon Ashburn | b1e6b56 | 2016-04-15 13:19:43 -0600 | [diff] [blame] | 2534 | loader_scanned_icd_add(inst, icds, fpath, vers); |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2535 | } else |
Mark Lobodzinski | 5c13d4d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 2536 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2537 | "Can't find \"library_path\" object in ICD JSON " |
| 2538 | "file %s, skipping", |
| 2539 | file_str); |
| 2540 | } else |
| 2541 | loader_log( |
Mark Lobodzinski | 5c13d4d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 2542 | inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2543 | "Can't find \"ICD\" object in ICD JSON file %s, skipping", |
| 2544 | file_str); |
Jon Ashburn | ffd5d67 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2545 | |
Jon Ashburn | e58f1a3 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 2546 | loader_heap_free(inst, file_str); |
Jon Ashburn | ffd5d67 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2547 | cJSON_Delete(json); |
| 2548 | } |
Jon Ashburn | e58f1a3 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 2549 | loader_heap_free(inst, manifest_files.filename_list); |
Jon Ashburn | d02fc2c | 2015-09-22 13:11:00 -0600 | [diff] [blame] | 2550 | loader_platform_thread_unlock_mutex(&loader_json_lock); |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 2551 | } |
| 2552 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2553 | void loader_layer_scan(const struct loader_instance *inst, |
Jon Ashburn | e58f1a3 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 2554 | struct loader_layer_list *instance_layers, |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2555 | struct loader_layer_list *device_layers) { |
Jon Ashburn | 1b111de | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 2556 | char *file_str; |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2557 | struct loader_manifest_files |
| 2558 | manifest_files[2]; // [0] = explicit, [1] = implicit |
Jon Ashburn | 1b111de | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 2559 | cJSON *json; |
| 2560 | uint32_t i; |
Jon Ashburn | d2c905c | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 2561 | uint32_t implicit; |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 2562 | |
Jon Ashburn | 715de58 | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 2563 | // Get a list of manifest files for explicit layers |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2564 | loader_get_manifest_files(inst, LAYERS_PATH_ENV, true, |
Jon Ashburn | a867ee4 | 2016-02-16 15:34:16 -0700 | [diff] [blame] | 2565 | DEFAULT_VK_ELAYERS_INFO, HOME_VK_ELAYERS_INFO, |
| 2566 | &manifest_files[0]); |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2567 | // Pass NULL for environment variable override - implicit layers are not |
| 2568 | // overridden by LAYERS_PATH_ENV |
Jon Ashburn | ec71e11 | 2015-12-24 13:58:35 -0700 | [diff] [blame] | 2569 | loader_get_manifest_files(inst, NULL, true, DEFAULT_VK_ILAYERS_INFO, |
Jon Ashburn | a867ee4 | 2016-02-16 15:34:16 -0700 | [diff] [blame] | 2570 | HOME_VK_ILAYERS_INFO, &manifest_files[1]); |
Jon Ashburn | d2c905c | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 2571 | if (manifest_files[0].count == 0 && manifest_files[1].count == 0) |
Courtney Goeltzenleuchter | bce445a | 2014-12-01 09:29:42 -0700 | [diff] [blame] | 2572 | return; |
Jon Ashburn | 0dcd619 | 2015-06-04 15:30:58 -0600 | [diff] [blame] | 2573 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2574 | #if 0 // TODO |
Jon Ashburn | 1b111de | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 2575 | /** |
Courtney Goeltzenleuchter | c5cf7d7 | 2015-07-05 12:53:31 -0600 | [diff] [blame] | 2576 | * We need a list of the layer libraries, not just a list of |
| 2577 | * the layer properties (a layer library could expose more than |
| 2578 | * one layer property). This list of scanned layers would be |
| 2579 | * used to check for global and physicaldevice layer properties. |
| 2580 | */ |
| 2581 | if (!loader_init_layer_library_list(&loader.scanned_layer_libraries)) { |
Courtney Goeltzenleuchter | acb1359 | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 2582 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Jon Ashburn | e58f1a3 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 2583 | "Alloc for layer list failed: %s line: %d", __FILE__, __LINE__); |
Courtney Goeltzenleuchter | c5cf7d7 | 2015-07-05 12:53:31 -0600 | [diff] [blame] | 2584 | return; |
Jon Ashburn | 68a6392 | 2015-07-02 09:40:15 -0600 | [diff] [blame] | 2585 | } |
Jon Ashburn | 1b111de | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 2586 | #endif |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 2587 | |
Jon Ashburn | 8e4fab4 | 2015-08-03 17:19:30 -0600 | [diff] [blame] | 2588 | /* cleanup any previously scanned libraries */ |
Jon Ashburn | e58f1a3 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 2589 | loader_delete_layer_properties(inst, instance_layers); |
| 2590 | loader_delete_layer_properties(inst, device_layers); |
Jon Ashburn | 0bf6a18 | 2015-07-16 17:19:31 -0600 | [diff] [blame] | 2591 | |
Jon Ashburn | d02fc2c | 2015-09-22 13:11:00 -0600 | [diff] [blame] | 2592 | loader_platform_thread_lock_mutex(&loader_json_lock); |
Jon Ashburn | d2c905c | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 2593 | for (implicit = 0; implicit < 2; implicit++) { |
| 2594 | for (i = 0; i < manifest_files[implicit].count; i++) { |
| 2595 | file_str = manifest_files[implicit].filename_list[i]; |
| 2596 | if (file_str == NULL) |
| 2597 | continue; |
Courtney Goeltzenleuchter | aa68505 | 2015-06-01 14:49:17 -0600 | [diff] [blame] | 2598 | |
Jon Ashburn | d2c905c | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 2599 | // parse file into JSON struct |
| 2600 | json = loader_get_json(inst, file_str); |
| 2601 | if (!json) { |
| 2602 | continue; |
| 2603 | } |
| 2604 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2605 | // TODO error if device layers expose instance_extensions |
| 2606 | // TODO error if instance layers expose device extensions |
| 2607 | loader_add_layer_properties(inst, instance_layers, device_layers, |
| 2608 | json, (implicit == 1), file_str); |
Jon Ashburn | d2c905c | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 2609 | |
| 2610 | loader_heap_free(inst, file_str); |
| 2611 | cJSON_Delete(json); |
Jon Ashburn | 1b111de | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 2612 | } |
Jon Ashburn | 1b111de | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 2613 | } |
Jon Ashburn | d2c905c | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 2614 | if (manifest_files[0].count != 0) |
| 2615 | loader_heap_free(inst, manifest_files[0].filename_list); |
| 2616 | |
| 2617 | if (manifest_files[1].count != 0) |
| 2618 | loader_heap_free(inst, manifest_files[1].filename_list); |
Jon Ashburn | 715de58 | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 2619 | |
| 2620 | // add a meta layer for validation if the validation layers are all present |
| 2621 | loader_add_layer_property_meta( |
| 2622 | inst, sizeof(std_validation_names) / sizeof(std_validation_names[0]), |
| 2623 | std_validation_names, instance_layers, device_layers); |
| 2624 | |
Jon Ashburn | d02fc2c | 2015-09-22 13:11:00 -0600 | [diff] [blame] | 2625 | loader_platform_thread_unlock_mutex(&loader_json_lock); |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 2626 | } |
| 2627 | |
Jeremy Hayes | 0005c0c | 2016-04-01 11:40:26 -0600 | [diff] [blame] | 2628 | void loader_implicit_layer_scan(const struct loader_instance *inst, |
Jon Ashburn | 9b2a8c9 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 2629 | struct loader_layer_list *instance_layers, |
| 2630 | struct loader_layer_list *device_layers) { |
Jeremy Hayes | 0005c0c | 2016-04-01 11:40:26 -0600 | [diff] [blame] | 2631 | char *file_str; |
| 2632 | struct loader_manifest_files manifest_files; |
| 2633 | cJSON *json; |
| 2634 | uint32_t i; |
| 2635 | |
| 2636 | // Pass NULL for environment variable override - implicit layers are not |
| 2637 | // overridden by LAYERS_PATH_ENV |
| 2638 | loader_get_manifest_files(inst, NULL, true, DEFAULT_VK_ILAYERS_INFO, |
| 2639 | HOME_VK_ILAYERS_INFO, &manifest_files); |
| 2640 | if (manifest_files.count == 0) { |
| 2641 | return; |
| 2642 | } |
| 2643 | |
| 2644 | /* cleanup any previously scanned libraries */ |
| 2645 | loader_delete_layer_properties(inst, instance_layers); |
| 2646 | loader_delete_layer_properties(inst, device_layers); |
| 2647 | |
| 2648 | loader_platform_thread_lock_mutex(&loader_json_lock); |
| 2649 | |
| 2650 | for (i = 0; i < manifest_files.count; i++) { |
| 2651 | file_str = manifest_files.filename_list[i]; |
| 2652 | if (file_str == NULL) { |
| 2653 | continue; |
| 2654 | } |
| 2655 | |
| 2656 | // parse file into JSON struct |
| 2657 | json = loader_get_json(inst, file_str); |
| 2658 | if (!json) { |
| 2659 | continue; |
| 2660 | } |
| 2661 | |
Jon Ashburn | 9b2a8c9 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 2662 | loader_add_layer_properties(inst, instance_layers, device_layers, json, |
| 2663 | true, file_str); |
Jeremy Hayes | 0005c0c | 2016-04-01 11:40:26 -0600 | [diff] [blame] | 2664 | |
| 2665 | loader_heap_free(inst, file_str); |
| 2666 | cJSON_Delete(json); |
| 2667 | } |
| 2668 | |
| 2669 | if (manifest_files.count != 0) { |
| 2670 | loader_heap_free(inst, manifest_files.filename_list); |
| 2671 | } |
| 2672 | |
| 2673 | // add a meta layer for validation if the validation layers are all present |
| 2674 | loader_add_layer_property_meta( |
| 2675 | inst, sizeof(std_validation_names) / sizeof(std_validation_names[0]), |
| 2676 | std_validation_names, instance_layers, device_layers); |
| 2677 | |
| 2678 | loader_platform_thread_unlock_mutex(&loader_json_lock); |
| 2679 | } |
| 2680 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2681 | static VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL |
| 2682 | loader_gpa_instance_internal(VkInstance inst, const char *pName) { |
Courtney Goeltzenleuchter | 2bdf6da | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 2683 | if (!strcmp(pName, "vkGetInstanceProcAddr")) |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2684 | return (void *)loader_gpa_instance_internal; |
Courtney Goeltzenleuchter | 2bdf6da | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 2685 | if (!strcmp(pName, "vkCreateInstance")) |
Jon Ashburn | a9c4a57 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 2686 | return (void *)terminator_CreateInstance; |
Courtney Goeltzenleuchter | 2bdf6da | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 2687 | if (!strcmp(pName, "vkCreateDevice")) |
Jon Ashburn | a9c4a57 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 2688 | return (void *)terminator_CreateDevice; |
Courtney Goeltzenleuchter | 2bdf6da | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 2689 | |
Jon Ashburn | fce93d9 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 2690 | // inst is not wrapped |
| 2691 | if (inst == VK_NULL_HANDLE) { |
| 2692 | return NULL; |
| 2693 | } |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2694 | VkLayerInstanceDispatchTable *disp_table = |
| 2695 | *(VkLayerInstanceDispatchTable **)inst; |
Jon Ashburn | fce93d9 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 2696 | void *addr; |
| 2697 | |
| 2698 | if (disp_table == NULL) |
| 2699 | return NULL; |
| 2700 | |
Jon Ashburn | 00df045 | 2016-03-08 09:30:30 -0700 | [diff] [blame] | 2701 | bool found_name; |
Jon Ashburn | 9b2a8c9 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 2702 | addr = |
| 2703 | loader_lookup_instance_dispatch_table(disp_table, pName, &found_name); |
Jon Ashburn | 00df045 | 2016-03-08 09:30:30 -0700 | [diff] [blame] | 2704 | if (found_name) { |
Jon Ashburn | fce93d9 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 2705 | return addr; |
Jon Ashburn | e18431b | 2015-04-13 18:10:06 -0600 | [diff] [blame] | 2706 | } |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 2707 | |
Jon Ashburn | 00df045 | 2016-03-08 09:30:30 -0700 | [diff] [blame] | 2708 | // Don't call down the chain, this would be an infinite loop |
| 2709 | loader_log(NULL, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
Jon Ashburn | 9b2a8c9 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 2710 | "loader_gpa_instance_internal() unrecognized name %s", pName); |
Jon Ashburn | 00df045 | 2016-03-08 09:30:30 -0700 | [diff] [blame] | 2711 | return NULL; |
Jon Ashburn | e18431b | 2015-04-13 18:10:06 -0600 | [diff] [blame] | 2712 | } |
| 2713 | |
Piers Daniell | fc50041 | 2016-03-29 11:51:11 -0600 | [diff] [blame] | 2714 | static VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL |
Jon Ashburn | 9b2a8c9 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 2715 | loader_gpa_device_internal(VkDevice device, const char *pName) { |
| 2716 | struct loader_device *dev; |
| 2717 | struct loader_icd *icd = loader_get_icd_and_device(device, &dev); |
Piers Daniell | fc50041 | 2016-03-29 11:51:11 -0600 | [diff] [blame] | 2718 | return icd->GetDeviceProcAddr(device, pName); |
| 2719 | } |
| 2720 | |
Jon Ashburn | 429e19f | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 2721 | /** |
| 2722 | * Initialize device_ext dispatch table entry as follows: |
| 2723 | * If dev == NULL find all logical devices created within this instance and |
| 2724 | * init the entry (given by idx) in the ext dispatch table. |
| 2725 | * If dev != NULL only initialize the entry in the given dev's dispatch table. |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2726 | * The initialization value is gotten by calling down the device chain with |
| 2727 | * GDPA. |
Jon Ashburn | 429e19f | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 2728 | * If GDPA returns NULL then don't initialize the dispatch table entry. |
| 2729 | */ |
| 2730 | static void loader_init_dispatch_dev_ext_entry(struct loader_instance *inst, |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2731 | struct loader_device *dev, |
| 2732 | uint32_t idx, |
| 2733 | const char *funcName) |
Jon Ashburn | 429e19f | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 2734 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2735 | { |
Jon Ashburn | 429e19f | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 2736 | void *gdpa_value; |
| 2737 | if (dev != NULL) { |
| 2738 | gdpa_value = dev->loader_dispatch.core_dispatch.GetDeviceProcAddr( |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2739 | dev->device, funcName); |
Jon Ashburn | 429e19f | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 2740 | if (gdpa_value != NULL) |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2741 | dev->loader_dispatch.ext_dispatch.DevExt[idx] = |
| 2742 | (PFN_vkDevExt)gdpa_value; |
Jon Ashburn | 429e19f | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 2743 | } else { |
| 2744 | for (uint32_t i = 0; i < inst->total_icd_count; i++) { |
| 2745 | struct loader_icd *icd = &inst->icds[i]; |
Karl Schultz | c50a598 | 2016-02-24 14:39:39 -0700 | [diff] [blame] | 2746 | struct loader_device *ldev = icd->logical_device_list; |
| 2747 | while (ldev) { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2748 | gdpa_value = |
Karl Schultz | c50a598 | 2016-02-24 14:39:39 -0700 | [diff] [blame] | 2749 | ldev->loader_dispatch.core_dispatch.GetDeviceProcAddr( |
| 2750 | ldev->device, funcName); |
Jon Ashburn | 429e19f | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 2751 | if (gdpa_value != NULL) |
Karl Schultz | c50a598 | 2016-02-24 14:39:39 -0700 | [diff] [blame] | 2752 | ldev->loader_dispatch.ext_dispatch.DevExt[idx] = |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2753 | (PFN_vkDevExt)gdpa_value; |
Karl Schultz | c50a598 | 2016-02-24 14:39:39 -0700 | [diff] [blame] | 2754 | ldev = ldev->next; |
Jon Ashburn | 429e19f | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 2755 | } |
| 2756 | } |
| 2757 | } |
Jon Ashburn | 429e19f | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 2758 | } |
| 2759 | |
| 2760 | /** |
| 2761 | * Find all dev extension in the hash table and initialize the dispatch table |
| 2762 | * for dev for each of those extension entrypoints found in hash table. |
| 2763 | |
| 2764 | */ |
Jon Ashburn | a9c4a57 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 2765 | void loader_init_dispatch_dev_ext(struct loader_instance *inst, |
| 2766 | struct loader_device *dev) { |
Jon Ashburn | 429e19f | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 2767 | for (uint32_t i = 0; i < MAX_NUM_DEV_EXTS; i++) { |
| 2768 | if (inst->disp_hash[i].func_name != NULL) |
| 2769 | loader_init_dispatch_dev_ext_entry(inst, dev, i, |
| 2770 | inst->disp_hash[i].func_name); |
| 2771 | } |
| 2772 | } |
| 2773 | |
| 2774 | static bool loader_check_icds_for_address(struct loader_instance *inst, |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2775 | const char *funcName) { |
Jon Ashburn | 429e19f | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 2776 | struct loader_icd *icd; |
| 2777 | icd = inst->icds; |
| 2778 | while (icd) { |
| 2779 | if (icd->this_icd_lib->GetInstanceProcAddr(icd->instance, funcName)) |
| 2780 | // this icd supports funcName |
| 2781 | return true; |
| 2782 | icd = icd->next; |
| 2783 | } |
| 2784 | |
| 2785 | return false; |
| 2786 | } |
| 2787 | |
Jon Ashburn | 9b2a8c9 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 2788 | static bool loader_check_layer_list_for_address( |
| 2789 | const struct loader_layer_list *const layers, const char *funcName) { |
Jeremy Hayes | 4c90acf | 2016-03-03 16:03:03 -0700 | [diff] [blame] | 2790 | // Iterate over the layers. |
Jon Ashburn | 9b2a8c9 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 2791 | for (uint32_t layer = 0; layer < layers->count; ++layer) { |
Jeremy Hayes | 4c90acf | 2016-03-03 16:03:03 -0700 | [diff] [blame] | 2792 | // Iterate over the extensions. |
Jon Ashburn | 9b2a8c9 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 2793 | const struct loader_device_extension_list *const extensions = |
| 2794 | &(layers->list[layer].device_extension_list); |
| 2795 | for (uint32_t extension = 0; extension < extensions->count; |
| 2796 | ++extension) { |
Jeremy Hayes | 4c90acf | 2016-03-03 16:03:03 -0700 | [diff] [blame] | 2797 | // Iterate over the entry points. |
Jon Ashburn | 9b2a8c9 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 2798 | const struct loader_dev_ext_props *const property = |
| 2799 | &(extensions->list[extension]); |
| 2800 | for (uint32_t entry = 0; entry < property->entrypoint_count; |
| 2801 | ++entry) { |
| 2802 | if (strcmp(property->entrypoints[entry], funcName) == 0) { |
Jeremy Hayes | 4c90acf | 2016-03-03 16:03:03 -0700 | [diff] [blame] | 2803 | return true; |
| 2804 | } |
| 2805 | } |
| 2806 | } |
| 2807 | } |
| 2808 | |
| 2809 | return false; |
| 2810 | } |
| 2811 | |
Jon Ashburn | 9b2a8c9 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 2812 | static bool |
| 2813 | loader_check_layers_for_address(const struct loader_instance *const inst, |
| 2814 | const char *funcName) { |
| 2815 | if (loader_check_layer_list_for_address(&inst->instance_layer_list, |
| 2816 | funcName)) { |
Jeremy Hayes | 4c90acf | 2016-03-03 16:03:03 -0700 | [diff] [blame] | 2817 | return true; |
| 2818 | } |
| 2819 | |
Jon Ashburn | 9b2a8c9 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 2820 | if (loader_check_layer_list_for_address(&inst->device_layer_list, |
| 2821 | funcName)) { |
Jeremy Hayes | 4c90acf | 2016-03-03 16:03:03 -0700 | [diff] [blame] | 2822 | return true; |
| 2823 | } |
| 2824 | |
| 2825 | return false; |
| 2826 | } |
| 2827 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2828 | static void loader_free_dev_ext_table(struct loader_instance *inst) { |
Jon Ashburn | 429e19f | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 2829 | for (uint32_t i = 0; i < MAX_NUM_DEV_EXTS; i++) { |
| 2830 | loader_heap_free(inst, inst->disp_hash[i].func_name); |
| 2831 | loader_heap_free(inst, inst->disp_hash[i].list.index); |
Jon Ashburn | 429e19f | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 2832 | } |
| 2833 | memset(inst->disp_hash, 0, sizeof(inst->disp_hash)); |
| 2834 | } |
| 2835 | |
| 2836 | static bool loader_add_dev_ext_table(struct loader_instance *inst, |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2837 | uint32_t *ptr_idx, const char *funcName) { |
Jon Ashburn | 429e19f | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 2838 | uint32_t i; |
| 2839 | uint32_t idx = *ptr_idx; |
| 2840 | struct loader_dispatch_hash_list *list = &inst->disp_hash[idx].list; |
| 2841 | |
| 2842 | if (!inst->disp_hash[idx].func_name) { |
| 2843 | // no entry here at this idx, so use it |
| 2844 | assert(list->capacity == 0); |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2845 | inst->disp_hash[idx].func_name = (char *)loader_heap_alloc( |
| 2846 | inst, strlen(funcName) + 1, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Jon Ashburn | 429e19f | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 2847 | if (inst->disp_hash[idx].func_name == NULL) { |
Courtney Goeltzenleuchter | acb1359 | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 2848 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2849 | "loader_add_dev_ext_table() can't allocate memory for " |
| 2850 | "func_name"); |
Jon Ashburn | 429e19f | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 2851 | return false; |
| 2852 | } |
| 2853 | strncpy(inst->disp_hash[idx].func_name, funcName, strlen(funcName) + 1); |
| 2854 | return true; |
| 2855 | } |
| 2856 | |
| 2857 | // check for enough capacity |
| 2858 | if (list->capacity == 0) { |
| 2859 | list->index = loader_heap_alloc(inst, 8 * sizeof(*(list->index)), |
| 2860 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
| 2861 | if (list->index == NULL) { |
Courtney Goeltzenleuchter | acb1359 | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 2862 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Jon Ashburn | 429e19f | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 2863 | "loader_add_dev_ext_table() can't allocate list memory"); |
| 2864 | return false; |
| 2865 | } |
| 2866 | list->capacity = 8 * sizeof(*(list->index)); |
| 2867 | } else if (list->capacity < (list->count + 1) * sizeof(*(list->index))) { |
| 2868 | list->index = loader_heap_realloc(inst, list->index, list->capacity, |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2869 | list->capacity * 2, |
| 2870 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Jon Ashburn | 429e19f | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 2871 | if (list->index == NULL) { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2872 | loader_log( |
| 2873 | inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 2874 | "loader_add_dev_ext_table() can't reallocate list memory"); |
Jon Ashburn | 429e19f | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 2875 | return false; |
| 2876 | } |
| 2877 | list->capacity *= 2; |
| 2878 | } |
| 2879 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2880 | // find an unused index in the hash table and use it |
Jon Ashburn | 429e19f | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 2881 | i = (idx + 1) % MAX_NUM_DEV_EXTS; |
| 2882 | do { |
| 2883 | if (!inst->disp_hash[i].func_name) { |
| 2884 | assert(inst->disp_hash[i].list.capacity == 0); |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2885 | inst->disp_hash[i].func_name = |
| 2886 | (char *)loader_heap_alloc(inst, strlen(funcName) + 1, |
| 2887 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Jon Ashburn | 429e19f | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 2888 | if (inst->disp_hash[i].func_name == NULL) { |
Courtney Goeltzenleuchter | acb1359 | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 2889 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2890 | "loader_add_dev_ext_table() can't rallocate " |
| 2891 | "func_name memory"); |
Jon Ashburn | 429e19f | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 2892 | return false; |
| 2893 | } |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2894 | strncpy(inst->disp_hash[i].func_name, funcName, |
| 2895 | strlen(funcName) + 1); |
Jon Ashburn | 429e19f | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 2896 | list->index[list->count] = i; |
| 2897 | list->count++; |
| 2898 | *ptr_idx = i; |
| 2899 | return true; |
| 2900 | } |
| 2901 | i = (i + 1) % MAX_NUM_DEV_EXTS; |
| 2902 | } while (i != idx); |
| 2903 | |
Courtney Goeltzenleuchter | acb1359 | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 2904 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2905 | "loader_add_dev_ext_table() couldn't insert into hash table; is " |
| 2906 | "it full?"); |
Jon Ashburn | 429e19f | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 2907 | return false; |
| 2908 | } |
| 2909 | |
| 2910 | static bool loader_name_in_dev_ext_table(struct loader_instance *inst, |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2911 | uint32_t *idx, const char *funcName) { |
Jon Ashburn | 429e19f | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 2912 | uint32_t alt_idx; |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2913 | if (inst->disp_hash[*idx].func_name && |
| 2914 | !strcmp(inst->disp_hash[*idx].func_name, funcName)) |
Jon Ashburn | 429e19f | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 2915 | return true; |
| 2916 | |
| 2917 | // funcName wasn't at the primary spot in the hash table |
| 2918 | // search the list of secondary locations (shallow search, not deep search) |
| 2919 | for (uint32_t i = 0; i < inst->disp_hash[*idx].list.count; i++) { |
| 2920 | alt_idx = inst->disp_hash[*idx].list.index[i]; |
| 2921 | if (!strcmp(inst->disp_hash[*idx].func_name, funcName)) { |
| 2922 | *idx = alt_idx; |
| 2923 | return true; |
| 2924 | } |
| 2925 | } |
| 2926 | |
| 2927 | return false; |
| 2928 | } |
| 2929 | |
| 2930 | /** |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2931 | * This function returns generic trampoline code address for unknown entry |
| 2932 | * points. |
Jon Ashburn | 429e19f | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 2933 | * Presumably, these unknown entry points (as given by funcName) are device |
| 2934 | * extension entrypoints. A hash table is used to keep a list of unknown entry |
| 2935 | * points and their mapping to the device extension dispatch table |
| 2936 | * (struct loader_dev_ext_dispatch_table). |
| 2937 | * \returns |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2938 | * For a given entry point string (funcName), if an existing mapping is found |
| 2939 | * the |
| 2940 | * trampoline address for that mapping is returned. Otherwise, this unknown |
| 2941 | * entry point |
| 2942 | * has not been seen yet. Next check if a layer or ICD supports it. If so then |
| 2943 | * a |
Jon Ashburn | 429e19f | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 2944 | * new entry in the hash table is initialized and that trampoline address for |
| 2945 | * the new entry is returned. Null is returned if the hash table is full or |
| 2946 | * if no discovered layer or ICD returns a non-NULL GetProcAddr for it. |
| 2947 | */ |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2948 | void *loader_dev_ext_gpa(struct loader_instance *inst, const char *funcName) { |
Jon Ashburn | 429e19f | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 2949 | uint32_t idx; |
| 2950 | uint32_t seed = 0; |
| 2951 | |
| 2952 | idx = murmurhash(funcName, strlen(funcName), seed) % MAX_NUM_DEV_EXTS; |
| 2953 | |
| 2954 | if (loader_name_in_dev_ext_table(inst, &idx, funcName)) |
| 2955 | // found funcName already in hash |
| 2956 | return loader_get_dev_ext_trampoline(idx); |
| 2957 | |
| 2958 | // Check if funcName is supported in either ICDs or a layer library |
Jeremy Hayes | 4c90acf | 2016-03-03 16:03:03 -0700 | [diff] [blame] | 2959 | if (!loader_check_icds_for_address(inst, funcName) && |
| 2960 | !loader_check_layers_for_address(inst, funcName)) { |
Jon Ashburn | 429e19f | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 2961 | // if support found in layers continue on |
| 2962 | return NULL; |
| 2963 | } |
| 2964 | |
| 2965 | if (loader_add_dev_ext_table(inst, &idx, funcName)) { |
| 2966 | // successfully added new table entry |
| 2967 | // init any dev dispatch table entrys as needed |
| 2968 | loader_init_dispatch_dev_ext_entry(inst, NULL, idx, funcName); |
| 2969 | return loader_get_dev_ext_trampoline(idx); |
| 2970 | } |
| 2971 | |
| 2972 | return NULL; |
| 2973 | } |
| 2974 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2975 | struct loader_instance *loader_get_instance(const VkInstance instance) { |
Jon Ashburn | 0c5eea2 | 2015-09-30 12:56:42 -0600 | [diff] [blame] | 2976 | /* look up the loader_instance in our list by comparing dispatch tables, as |
| 2977 | * there is no guarantee the instance is still a loader_instance* after any |
| 2978 | * layers which wrap the instance object. |
| 2979 | */ |
| 2980 | const VkLayerInstanceDispatchTable *disp; |
| 2981 | struct loader_instance *ptr_instance = NULL; |
| 2982 | disp = loader_get_instance_dispatch(instance); |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2983 | for (struct loader_instance *inst = loader.instances; inst; |
| 2984 | inst = inst->next) { |
Jon Ashburn | 0c5eea2 | 2015-09-30 12:56:42 -0600 | [diff] [blame] | 2985 | if (inst->disp == disp) { |
| 2986 | ptr_instance = inst; |
| 2987 | break; |
| 2988 | } |
| 2989 | } |
| 2990 | return ptr_instance; |
| 2991 | } |
| 2992 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2993 | static loader_platform_dl_handle |
| 2994 | loader_add_layer_lib(const struct loader_instance *inst, const char *chain_type, |
| 2995 | struct loader_layer_properties *layer_prop) { |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 2996 | struct loader_lib_info *new_layer_lib_list, *my_lib; |
Jon Ashburn | e58f1a3 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 2997 | size_t new_alloc_size; |
Courtney Goeltzenleuchter | c5cf7d7 | 2015-07-05 12:53:31 -0600 | [diff] [blame] | 2998 | /* |
| 2999 | * TODO: We can now track this information in the |
| 3000 | * scanned_layer_libraries list. |
| 3001 | */ |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3002 | for (uint32_t i = 0; i < loader.loaded_layer_lib_count; i++) { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3003 | if (strcmp(loader.loaded_layer_lib_list[i].lib_name, |
| 3004 | layer_prop->lib_name) == 0) { |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3005 | /* Have already loaded this library, just increment ref count */ |
| 3006 | loader.loaded_layer_lib_list[i].ref_count++; |
Courtney Goeltzenleuchter | acb1359 | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 3007 | loader_log(inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3008 | "%s Chain: Increment layer reference count for layer " |
| 3009 | "library %s", |
Jon Ashburn | e9ca8fa | 2015-08-20 16:35:30 -0600 | [diff] [blame] | 3010 | chain_type, layer_prop->lib_name); |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3011 | return loader.loaded_layer_lib_list[i].lib_handle; |
| 3012 | } |
| 3013 | } |
| 3014 | |
| 3015 | /* Haven't seen this library so load it */ |
Jon Ashburn | e58f1a3 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 3016 | new_alloc_size = 0; |
| 3017 | if (loader.loaded_layer_lib_capacity == 0) |
| 3018 | new_alloc_size = 8 * sizeof(struct loader_lib_info); |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3019 | else if (loader.loaded_layer_lib_capacity <= |
| 3020 | loader.loaded_layer_lib_count * sizeof(struct loader_lib_info)) |
Jon Ashburn | e58f1a3 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 3021 | new_alloc_size = loader.loaded_layer_lib_capacity * 2; |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3022 | |
Jon Ashburn | e58f1a3 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 3023 | if (new_alloc_size) { |
| 3024 | new_layer_lib_list = loader_heap_realloc( |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3025 | inst, loader.loaded_layer_lib_list, |
| 3026 | loader.loaded_layer_lib_capacity, new_alloc_size, |
| 3027 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Jon Ashburn | e58f1a3 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 3028 | if (!new_layer_lib_list) { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3029 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 3030 | "loader: realloc failed in loader_add_layer_lib"); |
Jon Ashburn | e58f1a3 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 3031 | return NULL; |
| 3032 | } |
| 3033 | loader.loaded_layer_lib_capacity = new_alloc_size; |
Courtney Goeltzenleuchter | 65e31cc | 2015-12-09 12:26:34 -0700 | [diff] [blame] | 3034 | loader.loaded_layer_lib_list = new_layer_lib_list; |
Jon Ashburn | e58f1a3 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 3035 | } else |
| 3036 | new_layer_lib_list = loader.loaded_layer_lib_list; |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3037 | my_lib = &new_layer_lib_list[loader.loaded_layer_lib_count]; |
| 3038 | |
Jon Ashburn | e9ca8fa | 2015-08-20 16:35:30 -0600 | [diff] [blame] | 3039 | strncpy(my_lib->lib_name, layer_prop->lib_name, sizeof(my_lib->lib_name)); |
| 3040 | my_lib->lib_name[sizeof(my_lib->lib_name) - 1] = '\0'; |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3041 | my_lib->ref_count = 0; |
| 3042 | my_lib->lib_handle = NULL; |
| 3043 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3044 | if ((my_lib->lib_handle = loader_platform_open_library(my_lib->lib_name)) == |
| 3045 | NULL) { |
Courtney Goeltzenleuchter | acb1359 | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 3046 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3047 | loader_platform_open_library_error(my_lib->lib_name)); |
| 3048 | return NULL; |
| 3049 | } else { |
Courtney Goeltzenleuchter | acb1359 | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 3050 | loader_log(inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3051 | "Chain: %s: Loading layer library %s", chain_type, |
| 3052 | layer_prop->lib_name); |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3053 | } |
| 3054 | loader.loaded_layer_lib_count++; |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3055 | my_lib->ref_count++; |
| 3056 | |
| 3057 | return my_lib->lib_handle; |
| 3058 | } |
| 3059 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3060 | static void |
| 3061 | loader_remove_layer_lib(struct loader_instance *inst, |
| 3062 | struct loader_layer_properties *layer_prop) { |
Courtney Goeltzenleuchter | 4672497 | 2015-12-17 09:51:22 -0700 | [diff] [blame] | 3063 | uint32_t idx = loader.loaded_layer_lib_count; |
Tony Barbour | 9687cb1 | 2015-07-14 13:34:05 -0600 | [diff] [blame] | 3064 | struct loader_lib_info *new_layer_lib_list, *my_lib = NULL; |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3065 | |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3066 | for (uint32_t i = 0; i < loader.loaded_layer_lib_count; i++) { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3067 | if (strcmp(loader.loaded_layer_lib_list[i].lib_name, |
| 3068 | layer_prop->lib_name) == 0) { |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3069 | /* found matching library */ |
| 3070 | idx = i; |
| 3071 | my_lib = &loader.loaded_layer_lib_list[i]; |
| 3072 | break; |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 3073 | } |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 3074 | } |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 3075 | |
Courtney Goeltzenleuchter | 4672497 | 2015-12-17 09:51:22 -0700 | [diff] [blame] | 3076 | if (idx == loader.loaded_layer_lib_count) { |
Jon Ashburn | db68e4b | 2015-12-17 14:30:21 -0700 | [diff] [blame] | 3077 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Courtney Goeltzenleuchter | 4672497 | 2015-12-17 09:51:22 -0700 | [diff] [blame] | 3078 | "Unable to unref library %s", layer_prop->lib_name); |
| 3079 | return; |
| 3080 | } |
| 3081 | |
Tony Barbour | 9687cb1 | 2015-07-14 13:34:05 -0600 | [diff] [blame] | 3082 | if (my_lib) { |
| 3083 | my_lib->ref_count--; |
| 3084 | if (my_lib->ref_count > 0) { |
Courtney Goeltzenleuchter | acb1359 | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 3085 | loader_log(inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3086 | "Decrement reference count for layer library %s", |
| 3087 | layer_prop->lib_name); |
Tony Barbour | 9687cb1 | 2015-07-14 13:34:05 -0600 | [diff] [blame] | 3088 | return; |
| 3089 | } |
Courtney Goeltzenleuchter | 0199e95 | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 3090 | } |
Courtney Goeltzenleuchter | 23b5f8d | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 3091 | loader_platform_close_library(my_lib->lib_handle); |
Courtney Goeltzenleuchter | acb1359 | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 3092 | loader_log(inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, |
Jon Ashburn | e9ca8fa | 2015-08-20 16:35:30 -0600 | [diff] [blame] | 3093 | "Unloading layer library %s", layer_prop->lib_name); |
Courtney Goeltzenleuchter | 23b5f8d | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 3094 | |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3095 | /* Need to remove unused library from list */ |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3096 | new_layer_lib_list = |
| 3097 | loader_heap_alloc(inst, loader.loaded_layer_lib_capacity, |
| 3098 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3099 | if (!new_layer_lib_list) { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3100 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 3101 | "loader: heap alloc failed loader_remove_layer_library"); |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3102 | return; |
| 3103 | } |
| 3104 | |
| 3105 | if (idx > 0) { |
| 3106 | /* Copy records before idx */ |
| 3107 | memcpy(new_layer_lib_list, &loader.loaded_layer_lib_list[0], |
| 3108 | sizeof(struct loader_lib_info) * idx); |
| 3109 | } |
| 3110 | if (idx < (loader.loaded_layer_lib_count - 1)) { |
| 3111 | /* Copy records after idx */ |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3112 | memcpy(&new_layer_lib_list[idx], &loader.loaded_layer_lib_list[idx + 1], |
| 3113 | sizeof(struct loader_lib_info) * |
| 3114 | (loader.loaded_layer_lib_count - idx - 1)); |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3115 | } |
Courtney Goeltzenleuchter | 23b5f8d | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 3116 | |
Jon Ashburn | e58f1a3 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 3117 | loader_heap_free(inst, loader.loaded_layer_lib_list); |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3118 | loader.loaded_layer_lib_count--; |
| 3119 | loader.loaded_layer_lib_list = new_layer_lib_list; |
Jon Ashburn | ead95c5 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 3120 | } |
| 3121 | |
Jon Ashburn | 1b111de | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 3122 | /** |
| 3123 | * Go through the search_list and find any layers which match type. If layer |
| 3124 | * type match is found in then add it to ext_list. |
| 3125 | */ |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3126 | static void |
| 3127 | loader_add_layer_implicit(const struct loader_instance *inst, |
| 3128 | const enum layer_type type, |
| 3129 | struct loader_layer_list *list, |
| 3130 | const struct loader_layer_list *search_list) { |
Jon Ashburn | d2c905c | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3131 | bool enable; |
| 3132 | char *env_value; |
Jon Ashburn | 535bd00 | 2015-07-02 16:10:32 -0600 | [diff] [blame] | 3133 | uint32_t i; |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 3134 | for (i = 0; i < search_list->count; i++) { |
| 3135 | const struct loader_layer_properties *prop = &search_list->list[i]; |
Jon Ashburn | 535bd00 | 2015-07-02 16:10:32 -0600 | [diff] [blame] | 3136 | if (prop->type & type) { |
Jon Ashburn | d2c905c | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3137 | /* Found an implicit layer, see if it should be enabled */ |
| 3138 | enable = false; |
| 3139 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3140 | // if no enable_environment variable is specified, this implicit |
| 3141 | // layer |
Jon Ashburn | d2c905c | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3142 | // should always be enabled. Otherwise check if the variable is set |
| 3143 | if (prop->enable_env_var.name[0] == 0) { |
| 3144 | enable = true; |
| 3145 | } else { |
Jon Ashburn | 5b25d9f | 2016-01-04 14:01:38 -0700 | [diff] [blame] | 3146 | env_value = loader_getenv(prop->enable_env_var.name); |
Jon Ashburn | d2c905c | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3147 | if (env_value && !strcmp(prop->enable_env_var.value, env_value)) |
| 3148 | enable = true; |
Jon Ashburn | 5b25d9f | 2016-01-04 14:01:38 -0700 | [diff] [blame] | 3149 | loader_free_getenv(env_value); |
Jon Ashburn | d2c905c | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3150 | } |
| 3151 | |
| 3152 | // disable_environment has priority, i.e. if both enable and disable |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3153 | // environment variables are set, the layer is disabled. Implicit |
| 3154 | // layers |
Jon Ashburn | d2c905c | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3155 | // are required to have a disable_environment variables |
Jon Ashburn | 5b25d9f | 2016-01-04 14:01:38 -0700 | [diff] [blame] | 3156 | env_value = loader_getenv(prop->disable_env_var.name); |
Jon Ashburn | d2c905c | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3157 | if (env_value) |
| 3158 | enable = false; |
Jon Ashburn | 5b25d9f | 2016-01-04 14:01:38 -0700 | [diff] [blame] | 3159 | loader_free_getenv(env_value); |
Jon Ashburn | d2c905c | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3160 | |
| 3161 | if (enable) |
| 3162 | loader_add_to_layer_list(inst, list, 1, prop); |
Jon Ashburn | 535bd00 | 2015-07-02 16:10:32 -0600 | [diff] [blame] | 3163 | } |
| 3164 | } |
Jon Ashburn | 535bd00 | 2015-07-02 16:10:32 -0600 | [diff] [blame] | 3165 | } |
| 3166 | |
| 3167 | /** |
| 3168 | * 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] | 3169 | * is found in search_list then add it to layer_list. But only add it to |
| 3170 | * layer_list if type matches. |
Jon Ashburn | 535bd00 | 2015-07-02 16:10:32 -0600 | [diff] [blame] | 3171 | */ |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3172 | static void loader_add_layer_env(const struct loader_instance *inst, |
| 3173 | const enum layer_type type, |
| 3174 | const char *env_name, |
| 3175 | struct loader_layer_list *layer_list, |
| 3176 | const struct loader_layer_list *search_list) { |
Ian Elliott | 225188f | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 3177 | char *layerEnv; |
Jon Ashburn | a2e6efe | 2015-07-02 14:10:53 -0600 | [diff] [blame] | 3178 | char *next, *name; |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 3179 | |
Jon Ashburn | 5b25d9f | 2016-01-04 14:01:38 -0700 | [diff] [blame] | 3180 | layerEnv = loader_getenv(env_name); |
Ian Elliott | 225188f | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 3181 | if (layerEnv == NULL) { |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3182 | return; |
Ian Elliott | 225188f | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 3183 | } |
Courtney Goeltzenleuchter | b620ace | 2015-07-05 11:28:29 -0600 | [diff] [blame] | 3184 | name = loader_stack_alloc(strlen(layerEnv) + 1); |
Jon Ashburn | a2e6efe | 2015-07-02 14:10:53 -0600 | [diff] [blame] | 3185 | if (name == NULL) { |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3186 | return; |
Ian Elliott | 225188f | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 3187 | } |
Jon Ashburn | a2e6efe | 2015-07-02 14:10:53 -0600 | [diff] [blame] | 3188 | strcpy(name, layerEnv); |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 3189 | |
Jon Ashburn | 5b25d9f | 2016-01-04 14:01:38 -0700 | [diff] [blame] | 3190 | loader_free_getenv(layerEnv); |
| 3191 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3192 | while (name && *name) { |
Jon Ashburn | a2e6efe | 2015-07-02 14:10:53 -0600 | [diff] [blame] | 3193 | next = loader_get_next_path(name); |
Jon Ashburn | a0eecb2 | 2016-02-11 18:59:43 -0700 | [diff] [blame] | 3194 | if (!strcmp(std_validation_str, name)) { |
| 3195 | /* add meta list of layers |
| 3196 | don't attempt to remove duplicate layers already added by app or |
| 3197 | env var |
| 3198 | */ |
| 3199 | loader_log(inst, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, |
| 3200 | "Expanding meta layer %s found in environment variable", |
| 3201 | std_validation_str); |
| 3202 | for (uint32_t i = 0; i < sizeof(std_validation_names) / |
| 3203 | sizeof(std_validation_names[0]); |
| 3204 | i++) { |
| 3205 | loader_find_layer_name_add_list(inst, std_validation_names[i], |
| 3206 | type, search_list, layer_list); |
| 3207 | } |
| 3208 | } else { |
| 3209 | loader_find_layer_name_add_list(inst, name, type, search_list, |
| 3210 | layer_list); |
| 3211 | } |
Jon Ashburn | a2e6efe | 2015-07-02 14:10:53 -0600 | [diff] [blame] | 3212 | name = next; |
Courtney Goeltzenleuchter | 0199e95 | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 3213 | } |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 3214 | |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3215 | return; |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 3216 | } |
| 3217 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3218 | void loader_deactivate_instance_layers(struct loader_instance *instance) { |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3219 | /* Create instance chain of enabled layers */ |
Courtney Goeltzenleuchter | 3d8dc1f | 2015-06-08 15:09:22 -0600 | [diff] [blame] | 3220 | for (uint32_t i = 0; i < instance->activated_layer_list.count; i++) { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3221 | struct loader_layer_properties *layer_prop = |
| 3222 | &instance->activated_layer_list.list[i]; |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3223 | |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 3224 | loader_remove_layer_lib(instance, layer_prop); |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 3225 | } |
Jon Ashburn | e58f1a3 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 3226 | loader_destroy_layer_list(instance, &instance->activated_layer_list); |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 3227 | } |
| 3228 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3229 | VkResult |
| 3230 | loader_enable_instance_layers(struct loader_instance *inst, |
| 3231 | const VkInstanceCreateInfo *pCreateInfo, |
| 3232 | const struct loader_layer_list *instance_layers) { |
Courtney Goeltzenleuchter | 1fcceeb | 2015-07-06 09:06:34 -0600 | [diff] [blame] | 3233 | VkResult err; |
| 3234 | |
Courtney Goeltzenleuchter | ac544f3 | 2015-09-14 18:01:17 -0600 | [diff] [blame] | 3235 | assert(inst && "Cannot have null instance"); |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3236 | |
Jon Ashburn | e58f1a3 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 3237 | if (!loader_init_layer_list(inst, &inst->activated_layer_list)) { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3238 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 3239 | "Failed to alloc Instance activated layer list"); |
Courtney Goeltzenleuchter | 1fcceeb | 2015-07-06 09:06:34 -0600 | [diff] [blame] | 3240 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Jon Ashburn | 6037841 | 2015-07-02 12:59:25 -0600 | [diff] [blame] | 3241 | } |
| 3242 | |
Jon Ashburn | 535bd00 | 2015-07-02 16:10:32 -0600 | [diff] [blame] | 3243 | /* Add any implicit layers first */ |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3244 | loader_add_layer_implicit(inst, VK_LAYER_TYPE_INSTANCE_IMPLICIT, |
| 3245 | &inst->activated_layer_list, instance_layers); |
Jon Ashburn | 535bd00 | 2015-07-02 16:10:32 -0600 | [diff] [blame] | 3246 | |
Jon Ashburn | 1b111de | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 3247 | /* Add any layers specified via environment variable next */ |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3248 | loader_add_layer_env(inst, VK_LAYER_TYPE_INSTANCE_EXPLICIT, |
| 3249 | "VK_INSTANCE_LAYERS", &inst->activated_layer_list, |
Courtney Goeltzenleuchter | 2bdf6da | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3250 | instance_layers); |
Jon Ashburn | 6037841 | 2015-07-02 12:59:25 -0600 | [diff] [blame] | 3251 | |
| 3252 | /* Add layers specified by the application */ |
Courtney Goeltzenleuchter | 1fcceeb | 2015-07-06 09:06:34 -0600 | [diff] [blame] | 3253 | err = loader_add_layer_names_to_list( |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3254 | inst, &inst->activated_layer_list, pCreateInfo->enabledLayerCount, |
| 3255 | pCreateInfo->ppEnabledLayerNames, instance_layers); |
Courtney Goeltzenleuchter | 1fcceeb | 2015-07-06 09:06:34 -0600 | [diff] [blame] | 3256 | |
| 3257 | return err; |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3258 | } |
| 3259 | |
Courtney Goeltzenleuchter | 2bdf6da | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3260 | /* |
| 3261 | * Given the list of layers to activate in the loader_instance |
| 3262 | * structure. This function will add a VkLayerInstanceCreateInfo |
| 3263 | * structure to the VkInstanceCreateInfo.pNext pointer. |
| 3264 | * Each activated layer will have it's own VkLayerInstanceLink |
| 3265 | * structure that tells the layer what Get*ProcAddr to call to |
| 3266 | * get function pointers to the next layer down. |
| 3267 | * Once the chain info has been created this function will |
| 3268 | * execute the CreateInstance call chain. Each layer will |
| 3269 | * then have an opportunity in it's CreateInstance function |
| 3270 | * to setup it's dispatch table when the lower layer returns |
| 3271 | * successfully. |
| 3272 | * Each layer can wrap or not-wrap the returned VkInstance object |
| 3273 | * as it sees fit. |
| 3274 | * The instance chain is terminated by a loader function |
| 3275 | * that will call CreateInstance on all available ICD's and |
| 3276 | * cache those VkInstance objects for future use. |
| 3277 | */ |
| 3278 | VkResult loader_create_instance_chain(const VkInstanceCreateInfo *pCreateInfo, |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3279 | const VkAllocationCallbacks *pAllocator, |
Jon Ashburn | e44367a | 2016-01-20 08:08:25 -0700 | [diff] [blame] | 3280 | struct loader_instance *inst, |
Jon Ashburn | a4b3494 | 2016-02-03 12:37:30 -0700 | [diff] [blame] | 3281 | VkInstance *created_instance) { |
Courtney Goeltzenleuchter | 2bdf6da | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3282 | uint32_t activated_layers = 0; |
| 3283 | VkLayerInstanceCreateInfo chain_info; |
| 3284 | VkLayerInstanceLink *layer_instance_link_info = NULL; |
| 3285 | VkInstanceCreateInfo loader_create_info; |
| 3286 | VkResult res; |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3287 | |
Courtney Goeltzenleuchter | 2bdf6da | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3288 | PFN_vkGetInstanceProcAddr nextGIPA = loader_gpa_instance_internal; |
| 3289 | PFN_vkGetInstanceProcAddr fpGIPA = loader_gpa_instance_internal; |
Jon Ashburn | fce93d9 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 3290 | |
Courtney Goeltzenleuchter | 2bdf6da | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3291 | memcpy(&loader_create_info, pCreateInfo, sizeof(VkInstanceCreateInfo)); |
Jon Ashburn | fce93d9 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 3292 | |
Courtney Goeltzenleuchter | 2bdf6da | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3293 | if (inst->activated_layer_list.count > 0) { |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3294 | |
Courtney Goeltzenleuchter | 2bdf6da | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3295 | chain_info.u.pLayerInfo = NULL; |
| 3296 | chain_info.pNext = pCreateInfo->pNext; |
| 3297 | chain_info.sType = VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO; |
| 3298 | chain_info.function = VK_LAYER_LINK_INFO; |
| 3299 | loader_create_info.pNext = &chain_info; |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3300 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3301 | layer_instance_link_info = loader_stack_alloc( |
| 3302 | sizeof(VkLayerInstanceLink) * inst->activated_layer_list.count); |
Courtney Goeltzenleuchter | 2bdf6da | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3303 | if (!layer_instance_link_info) { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3304 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 3305 | "Failed to alloc Instance objects for layer"); |
Courtney Goeltzenleuchter | 2bdf6da | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3306 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Jon Ashburn | fce93d9 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 3307 | } |
| 3308 | |
Courtney Goeltzenleuchter | 2bdf6da | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3309 | /* Create instance chain of enabled layers */ |
| 3310 | for (int32_t i = inst->activated_layer_list.count - 1; i >= 0; i--) { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3311 | struct loader_layer_properties *layer_prop = |
| 3312 | &inst->activated_layer_list.list[i]; |
Courtney Goeltzenleuchter | 2bdf6da | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3313 | loader_platform_dl_handle lib_handle; |
Courtney Goeltzenleuchter | 23b5f8d | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 3314 | |
Courtney Goeltzenleuchter | 2bdf6da | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3315 | lib_handle = loader_add_layer_lib(inst, "instance", layer_prop); |
| 3316 | if (!lib_handle) |
Courtney Goeltzenleuchter | 5e5065e | 2016-01-14 16:06:06 -0700 | [diff] [blame] | 3317 | continue; |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3318 | if ((fpGIPA = layer_prop->functions.get_instance_proc_addr) == |
| 3319 | NULL) { |
| 3320 | if (layer_prop->functions.str_gipa == NULL || |
| 3321 | strlen(layer_prop->functions.str_gipa) == 0) { |
| 3322 | fpGIPA = (PFN_vkGetInstanceProcAddr) |
| 3323 | loader_platform_get_proc_address( |
| 3324 | lib_handle, "vkGetInstanceProcAddr"); |
Courtney Goeltzenleuchter | 2bdf6da | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3325 | layer_prop->functions.get_instance_proc_addr = fpGIPA; |
| 3326 | } else |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3327 | fpGIPA = (PFN_vkGetInstanceProcAddr) |
| 3328 | loader_platform_get_proc_address( |
| 3329 | lib_handle, layer_prop->functions.str_gipa); |
Courtney Goeltzenleuchter | 2bdf6da | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3330 | if (!fpGIPA) { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3331 | loader_log( |
| 3332 | inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 3333 | "Failed to find vkGetInstanceProcAddr in layer %s", |
| 3334 | layer_prop->lib_name); |
Courtney Goeltzenleuchter | 2bdf6da | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3335 | continue; |
| 3336 | } |
| 3337 | } |
| 3338 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3339 | layer_instance_link_info[activated_layers].pNext = |
| 3340 | chain_info.u.pLayerInfo; |
| 3341 | layer_instance_link_info[activated_layers] |
| 3342 | .pfnNextGetInstanceProcAddr = nextGIPA; |
| 3343 | chain_info.u.pLayerInfo = |
| 3344 | &layer_instance_link_info[activated_layers]; |
Courtney Goeltzenleuchter | 2bdf6da | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3345 | nextGIPA = fpGIPA; |
| 3346 | |
Mark Lobodzinski | 5c13d4d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 3347 | loader_log(inst, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3348 | "Insert instance layer %s (%s)", |
| 3349 | layer_prop->info.layerName, layer_prop->lib_name); |
Courtney Goeltzenleuchter | 2bdf6da | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3350 | |
| 3351 | activated_layers++; |
| 3352 | } |
Jon Ashburn | fce93d9 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 3353 | } |
| 3354 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3355 | PFN_vkCreateInstance fpCreateInstance = |
Jon Ashburn | a4b3494 | 2016-02-03 12:37:30 -0700 | [diff] [blame] | 3356 | (PFN_vkCreateInstance)nextGIPA(*created_instance, "vkCreateInstance"); |
Courtney Goeltzenleuchter | 2bdf6da | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3357 | if (fpCreateInstance) { |
Jon Ashburn | 7ec8ec8 | 2016-03-29 11:16:01 -0600 | [diff] [blame] | 3358 | VkLayerInstanceCreateInfo create_info_disp; |
| 3359 | |
Jon Ashburn | 9b2a8c9 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 3360 | create_info_disp.sType = VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO; |
Jon Ashburn | 94d58ea | 2016-03-31 10:52:22 -0600 | [diff] [blame] | 3361 | create_info_disp.function = VK_LOADER_DATA_CALLBACK; |
Jon Ashburn | 7ec8ec8 | 2016-03-29 11:16:01 -0600 | [diff] [blame] | 3362 | |
| 3363 | create_info_disp.u.pfnSetInstanceLoaderData = vkSetInstanceDispatch; |
| 3364 | |
| 3365 | create_info_disp.pNext = loader_create_info.pNext; |
| 3366 | loader_create_info.pNext = &create_info_disp; |
Jon Ashburn | 7ec85cd | 2016-02-10 20:50:19 -0700 | [diff] [blame] | 3367 | res = |
| 3368 | fpCreateInstance(&loader_create_info, pAllocator, created_instance); |
Courtney Goeltzenleuchter | 2bdf6da | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3369 | } else { |
| 3370 | // Couldn't find CreateInstance function! |
| 3371 | res = VK_ERROR_INITIALIZATION_FAILED; |
| 3372 | } |
| 3373 | |
| 3374 | if (res != VK_SUCCESS) { |
| 3375 | // TODO: Need to clean up here |
| 3376 | } else { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3377 | loader_init_instance_core_dispatch_table(inst->disp, nextGIPA, |
Jon Ashburn | a4b3494 | 2016-02-03 12:37:30 -0700 | [diff] [blame] | 3378 | *created_instance); |
Jon Ashburn | 48cd3ae | 2016-03-08 15:21:30 -0700 | [diff] [blame] | 3379 | inst->instance = *created_instance; |
Courtney Goeltzenleuchter | 2bdf6da | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3380 | } |
| 3381 | |
| 3382 | return res; |
Jon Ashburn | fce93d9 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 3383 | } |
| 3384 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3385 | void loader_activate_instance_layer_extensions(struct loader_instance *inst, |
| 3386 | VkInstance created_inst) { |
Courtney Goeltzenleuchter | 23b5f8d | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 3387 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3388 | loader_init_instance_extension_dispatch_table( |
| 3389 | inst->disp, inst->disp->GetInstanceProcAddr, created_inst); |
Courtney Goeltzenleuchter | 23b5f8d | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 3390 | } |
| 3391 | |
Jon Ashburn | a9c4a57 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 3392 | VkResult |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3393 | loader_enable_device_layers(const struct loader_instance *inst, |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3394 | struct loader_layer_list *activated_layer_list, |
| 3395 | const VkDeviceCreateInfo *pCreateInfo, |
| 3396 | const struct loader_layer_list *device_layers) |
Jon Ashburn | 182b830 | 2015-08-11 14:49:54 -0600 | [diff] [blame] | 3397 | |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3398 | { |
Courtney Goeltzenleuchter | 1fcceeb | 2015-07-06 09:06:34 -0600 | [diff] [blame] | 3399 | VkResult err; |
| 3400 | |
Jon Ashburn | 6c2fa49 | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 3401 | assert(activated_layer_list && "Cannot have null output layer list"); |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3402 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3403 | if (activated_layer_list->list == NULL || |
| 3404 | activated_layer_list->capacity == 0) { |
Jon Ashburn | 6c2fa49 | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 3405 | loader_init_layer_list(inst, activated_layer_list); |
Jon Ashburn | 6037841 | 2015-07-02 12:59:25 -0600 | [diff] [blame] | 3406 | } |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3407 | |
Jon Ashburn | 6c2fa49 | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 3408 | if (activated_layer_list->list == NULL) { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3409 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 3410 | "Failed to alloc device activated layer list"); |
Courtney Goeltzenleuchter | 1fcceeb | 2015-07-06 09:06:34 -0600 | [diff] [blame] | 3411 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Jon Ashburn | 6037841 | 2015-07-02 12:59:25 -0600 | [diff] [blame] | 3412 | } |
| 3413 | |
Jon Ashburn | 535bd00 | 2015-07-02 16:10:32 -0600 | [diff] [blame] | 3414 | /* Add any implicit layers first */ |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3415 | loader_add_layer_implicit(inst, VK_LAYER_TYPE_DEVICE_IMPLICIT, |
| 3416 | activated_layer_list, device_layers); |
Jon Ashburn | 535bd00 | 2015-07-02 16:10:32 -0600 | [diff] [blame] | 3417 | |
| 3418 | /* Add any layers specified via environment variable next */ |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3419 | loader_add_layer_env(inst, VK_LAYER_TYPE_DEVICE_EXPLICIT, |
| 3420 | "VK_DEVICE_LAYERS", activated_layer_list, |
| 3421 | device_layers); |
Jon Ashburn | 6037841 | 2015-07-02 12:59:25 -0600 | [diff] [blame] | 3422 | |
| 3423 | /* Add layers specified by the application */ |
Courtney Goeltzenleuchter | 1fcceeb | 2015-07-06 09:06:34 -0600 | [diff] [blame] | 3424 | err = loader_add_layer_names_to_list( |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3425 | inst, activated_layer_list, pCreateInfo->enabledLayerCount, |
| 3426 | pCreateInfo->ppEnabledLayerNames, device_layers); |
Courtney Goeltzenleuchter | 1fcceeb | 2015-07-06 09:06:34 -0600 | [diff] [blame] | 3427 | |
| 3428 | return err; |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3429 | } |
| 3430 | |
Jon Ashburn | 9b2a8c9 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 3431 | VkResult |
| 3432 | loader_create_device_chain(const struct loader_physical_device_tramp *pd, |
| 3433 | const VkDeviceCreateInfo *pCreateInfo, |
| 3434 | const VkAllocationCallbacks *pAllocator, |
| 3435 | const struct loader_instance *inst, |
| 3436 | struct loader_device *dev) { |
Courtney Goeltzenleuchter | 2bdf6da | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3437 | uint32_t activated_layers = 0; |
| 3438 | VkLayerDeviceLink *layer_device_link_info; |
| 3439 | VkLayerDeviceCreateInfo chain_info; |
Courtney Goeltzenleuchter | 2bdf6da | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3440 | VkDeviceCreateInfo loader_create_info; |
| 3441 | VkResult res; |
Courtney Goeltzenleuchter | be63799 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 3442 | |
Piers Daniell | fc50041 | 2016-03-29 11:51:11 -0600 | [diff] [blame] | 3443 | PFN_vkGetDeviceProcAddr fpGDPA, nextGDPA = loader_gpa_device_internal; |
Courtney Goeltzenleuchter | 2bdf6da | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3444 | PFN_vkGetInstanceProcAddr fpGIPA, nextGIPA = loader_gpa_instance_internal; |
Courtney Goeltzenleuchter | be63799 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 3445 | |
Courtney Goeltzenleuchter | 2bdf6da | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3446 | memcpy(&loader_create_info, pCreateInfo, sizeof(VkDeviceCreateInfo)); |
| 3447 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3448 | layer_device_link_info = loader_stack_alloc( |
| 3449 | sizeof(VkLayerDeviceLink) * dev->activated_layer_list.count); |
Courtney Goeltzenleuchter | 2bdf6da | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3450 | if (!layer_device_link_info) { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3451 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 3452 | "Failed to alloc Device objects for layer"); |
Courtney Goeltzenleuchter | 2bdf6da | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3453 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
David Pinedo | 0fab78b | 2015-06-24 15:29:18 -0600 | [diff] [blame] | 3454 | } |
Jon Ashburn | 612539f | 2015-06-10 10:13:10 -0600 | [diff] [blame] | 3455 | |
Courtney Goeltzenleuchter | 2bdf6da | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3456 | if (dev->activated_layer_list.count > 0) { |
Jon Ashburn | 1d41bc5 | 2016-03-29 12:52:13 -0600 | [diff] [blame] | 3457 | chain_info.sType = VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO; |
| 3458 | chain_info.function = VK_LAYER_LINK_INFO; |
| 3459 | chain_info.u.pLayerInfo = NULL; |
| 3460 | chain_info.pNext = pCreateInfo->pNext; |
| 3461 | loader_create_info.pNext = &chain_info; |
| 3462 | |
Courtney Goeltzenleuchter | 2bdf6da | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3463 | /* Create instance chain of enabled layers */ |
| 3464 | for (int32_t i = dev->activated_layer_list.count - 1; i >= 0; i--) { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3465 | struct loader_layer_properties *layer_prop = |
| 3466 | &dev->activated_layer_list.list[i]; |
Courtney Goeltzenleuchter | 2bdf6da | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3467 | loader_platform_dl_handle lib_handle; |
Courtney Goeltzenleuchter | be63799 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 3468 | |
Courtney Goeltzenleuchter | 2bdf6da | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3469 | lib_handle = loader_add_layer_lib(inst, "device", layer_prop); |
| 3470 | if (!lib_handle) |
Courtney Goeltzenleuchter | 5e5065e | 2016-01-14 16:06:06 -0700 | [diff] [blame] | 3471 | continue; |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3472 | if ((fpGIPA = layer_prop->functions.get_instance_proc_addr) == |
| 3473 | NULL) { |
| 3474 | if (layer_prop->functions.str_gipa == NULL || |
| 3475 | strlen(layer_prop->functions.str_gipa) == 0) { |
| 3476 | fpGIPA = (PFN_vkGetInstanceProcAddr) |
| 3477 | loader_platform_get_proc_address( |
| 3478 | lib_handle, "vkGetInstanceProcAddr"); |
Courtney Goeltzenleuchter | 2bdf6da | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3479 | layer_prop->functions.get_instance_proc_addr = fpGIPA; |
| 3480 | } else |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3481 | fpGIPA = (PFN_vkGetInstanceProcAddr) |
| 3482 | loader_platform_get_proc_address( |
| 3483 | lib_handle, layer_prop->functions.str_gipa); |
Courtney Goeltzenleuchter | 2bdf6da | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3484 | if (!fpGIPA) { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3485 | loader_log( |
| 3486 | inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 3487 | "Failed to find vkGetInstanceProcAddr in layer %s", |
| 3488 | layer_prop->lib_name); |
Courtney Goeltzenleuchter | 2bdf6da | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3489 | continue; |
| 3490 | } |
Jon Ashburn | 2db0804 | 2015-09-09 11:29:24 -0600 | [diff] [blame] | 3491 | } |
Courtney Goeltzenleuchter | 2bdf6da | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3492 | if ((fpGDPA = layer_prop->functions.get_device_proc_addr) == NULL) { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3493 | if (layer_prop->functions.str_gdpa == NULL || |
| 3494 | strlen(layer_prop->functions.str_gdpa) == 0) { |
| 3495 | fpGDPA = (PFN_vkGetDeviceProcAddr) |
| 3496 | loader_platform_get_proc_address(lib_handle, |
| 3497 | "vkGetDeviceProcAddr"); |
Courtney Goeltzenleuchter | 2bdf6da | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3498 | layer_prop->functions.get_device_proc_addr = fpGDPA; |
| 3499 | } else |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3500 | fpGDPA = (PFN_vkGetDeviceProcAddr) |
| 3501 | loader_platform_get_proc_address( |
| 3502 | lib_handle, layer_prop->functions.str_gdpa); |
Courtney Goeltzenleuchter | 2bdf6da | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3503 | if (!fpGDPA) { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3504 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 3505 | "Failed to find vkGetDeviceProcAddr in layer %s", |
| 3506 | layer_prop->lib_name); |
Courtney Goeltzenleuchter | 2bdf6da | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3507 | continue; |
| 3508 | } |
| 3509 | } |
| 3510 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3511 | layer_device_link_info[activated_layers].pNext = |
| 3512 | chain_info.u.pLayerInfo; |
| 3513 | layer_device_link_info[activated_layers] |
| 3514 | .pfnNextGetInstanceProcAddr = nextGIPA; |
| 3515 | layer_device_link_info[activated_layers].pfnNextGetDeviceProcAddr = |
| 3516 | nextGDPA; |
Courtney Goeltzenleuchter | 2bdf6da | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3517 | chain_info.u.pLayerInfo = &layer_device_link_info[activated_layers]; |
| 3518 | nextGIPA = fpGIPA; |
| 3519 | nextGDPA = fpGDPA; |
| 3520 | |
Mark Lobodzinski | 5c13d4d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 3521 | loader_log(inst, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, |
Courtney Goeltzenleuchter | 2bdf6da | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3522 | "Insert device layer %s (%s)", |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3523 | layer_prop->info.layerName, layer_prop->lib_name); |
Courtney Goeltzenleuchter | 2bdf6da | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3524 | |
| 3525 | activated_layers++; |
Jon Ashburn | 612539f | 2015-06-10 10:13:10 -0600 | [diff] [blame] | 3526 | } |
Jon Ashburn | 612539f | 2015-06-10 10:13:10 -0600 | [diff] [blame] | 3527 | } |
| 3528 | |
Jon Ashburn | 9b2a8c9 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 3529 | VkDevice created_device = (VkDevice)dev; |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3530 | PFN_vkCreateDevice fpCreateDevice = |
Jon Ashburn | 48cd3ae | 2016-03-08 15:21:30 -0700 | [diff] [blame] | 3531 | (PFN_vkCreateDevice)nextGIPA(inst->instance, "vkCreateDevice"); |
Courtney Goeltzenleuchter | 2bdf6da | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3532 | if (fpCreateDevice) { |
Jon Ashburn | 94d58ea | 2016-03-31 10:52:22 -0600 | [diff] [blame] | 3533 | VkLayerDeviceCreateInfo create_info_disp; |
| 3534 | |
Jon Ashburn | 9b2a8c9 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 3535 | create_info_disp.sType = VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO; |
Jon Ashburn | 94d58ea | 2016-03-31 10:52:22 -0600 | [diff] [blame] | 3536 | create_info_disp.function = VK_LOADER_DATA_CALLBACK; |
| 3537 | |
| 3538 | create_info_disp.u.pfnSetDeviceLoaderData = vkSetDeviceDispatch; |
| 3539 | |
| 3540 | create_info_disp.pNext = loader_create_info.pNext; |
| 3541 | loader_create_info.pNext = &create_info_disp; |
Jon Ashburn | 8766043 | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 3542 | res = fpCreateDevice(pd->phys_dev, &loader_create_info, pAllocator, |
Jon Ashburn | 1d41bc5 | 2016-03-29 12:52:13 -0600 | [diff] [blame] | 3543 | &created_device); |
Piers Daniell | e435397 | 2016-04-05 17:28:06 -0600 | [diff] [blame] | 3544 | if (res != VK_SUCCESS) { |
| 3545 | return res; |
| 3546 | } |
Jon Ashburn | 1d41bc5 | 2016-03-29 12:52:13 -0600 | [diff] [blame] | 3547 | dev->device = created_device; |
Courtney Goeltzenleuchter | 2bdf6da | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3548 | } else { |
| 3549 | // Couldn't find CreateDevice function! |
| 3550 | return VK_ERROR_INITIALIZATION_FAILED; |
| 3551 | } |
Jon Ashburn | 612539f | 2015-06-10 10:13:10 -0600 | [diff] [blame] | 3552 | |
Courtney Goeltzenleuchter | 2bdf6da | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3553 | /* Initialize device dispatch table */ |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3554 | loader_init_device_dispatch_table(&dev->loader_dispatch, nextGDPA, |
Courtney Goeltzenleuchter | 2bdf6da | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3555 | dev->device); |
| 3556 | |
| 3557 | return res; |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 3558 | } |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 3559 | |
Mark Lobodzinski | c882eee | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 3560 | VkResult loader_validate_layers(const struct loader_instance *inst, |
| 3561 | const uint32_t layer_count, |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3562 | const char *const *ppEnabledLayerNames, |
| 3563 | const struct loader_layer_list *list) { |
Courtney Goeltzenleuchter | 5d9f29b | 2015-07-06 17:45:08 -0600 | [diff] [blame] | 3564 | struct loader_layer_properties *prop; |
| 3565 | |
Courtney Goeltzenleuchter | a17697f | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 3566 | for (uint32_t i = 0; i < layer_count; i++) { |
Jon Ashburn | 7ec85cd | 2016-02-10 20:50:19 -0700 | [diff] [blame] | 3567 | VkStringErrorFlags result = |
| 3568 | vk_string_validate(MaxLoaderStringLength, ppEnabledLayerNames[i]); |
Mark Lobodzinski | c882eee | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 3569 | if (result != VK_STRING_ERROR_NONE) { |
| 3570 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Jon Ashburn | 7ec85cd | 2016-02-10 20:50:19 -0700 | [diff] [blame] | 3571 | "Loader: Device ppEnabledLayerNames contains string " |
| 3572 | "that is too long or is badly formed"); |
Mark Lobodzinski | c882eee | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 3573 | return VK_ERROR_LAYER_NOT_PRESENT; |
| 3574 | } |
| 3575 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3576 | prop = loader_get_layer_property(ppEnabledLayerNames[i], list); |
Courtney Goeltzenleuchter | 5d9f29b | 2015-07-06 17:45:08 -0600 | [diff] [blame] | 3577 | if (!prop) { |
Courtney Goeltzenleuchter | ac544f3 | 2015-09-14 18:01:17 -0600 | [diff] [blame] | 3578 | return VK_ERROR_LAYER_NOT_PRESENT; |
Courtney Goeltzenleuchter | 5d9f29b | 2015-07-06 17:45:08 -0600 | [diff] [blame] | 3579 | } |
| 3580 | } |
Courtney Goeltzenleuchter | 5d9f29b | 2015-07-06 17:45:08 -0600 | [diff] [blame] | 3581 | return VK_SUCCESS; |
| 3582 | } |
| 3583 | |
| 3584 | VkResult loader_validate_instance_extensions( |
Mark Lobodzinski | c882eee | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 3585 | const struct loader_instance *inst, |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3586 | const struct loader_extension_list *icd_exts, |
| 3587 | const struct loader_layer_list *instance_layer, |
| 3588 | const VkInstanceCreateInfo *pCreateInfo) { |
Mark Lobodzinski | c882eee | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 3589 | |
Jon Ashburn | c4748dc | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 3590 | VkExtensionProperties *extension_prop; |
Courtney Goeltzenleuchter | a17697f | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 3591 | struct loader_layer_properties *layer_prop; |
| 3592 | |
Jon Ashburn | a4ae48b | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 3593 | for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) { |
Jon Ashburn | 7ec85cd | 2016-02-10 20:50:19 -0700 | [diff] [blame] | 3594 | VkStringErrorFlags result = vk_string_validate( |
| 3595 | MaxLoaderStringLength, pCreateInfo->ppEnabledExtensionNames[i]); |
Mark Lobodzinski | c882eee | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 3596 | if (result != VK_STRING_ERROR_NONE) { |
| 3597 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Jon Ashburn | 7ec85cd | 2016-02-10 20:50:19 -0700 | [diff] [blame] | 3598 | "Loader: Instance ppEnabledExtensionNames contains " |
| 3599 | "string that is too long or is badly formed"); |
Mark Lobodzinski | c882eee | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 3600 | return VK_ERROR_EXTENSION_NOT_PRESENT; |
| 3601 | } |
| 3602 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3603 | extension_prop = get_extension_property( |
| 3604 | pCreateInfo->ppEnabledExtensionNames[i], icd_exts); |
Courtney Goeltzenleuchter | a17697f | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 3605 | |
| 3606 | if (extension_prop) { |
| 3607 | continue; |
| 3608 | } |
| 3609 | |
| 3610 | extension_prop = NULL; |
| 3611 | |
| 3612 | /* Not in global list, search layer extension lists */ |
Jon Ashburn | a4ae48b | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 3613 | for (uint32_t j = 0; j < pCreateInfo->enabledLayerCount; j++) { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3614 | layer_prop = loader_get_layer_property( |
| 3615 | pCreateInfo->ppEnabledLayerNames[i], instance_layer); |
Courtney Goeltzenleuchter | a17697f | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 3616 | if (!layer_prop) { |
Courtney Goeltzenleuchter | 91371ff | 2015-07-06 20:46:50 -0600 | [diff] [blame] | 3617 | /* Should NOT get here, loader_validate_layers |
Courtney Goeltzenleuchter | a17697f | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 3618 | * should have already filtered this case out. |
| 3619 | */ |
| 3620 | continue; |
| 3621 | } |
| 3622 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3623 | extension_prop = |
| 3624 | get_extension_property(pCreateInfo->ppEnabledExtensionNames[i], |
| 3625 | &layer_prop->instance_extension_list); |
Courtney Goeltzenleuchter | a17697f | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 3626 | if (extension_prop) { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3627 | /* Found the extension in one of the layers enabled by the app. |
| 3628 | */ |
Courtney Goeltzenleuchter | a17697f | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 3629 | break; |
| 3630 | } |
| 3631 | } |
| 3632 | |
| 3633 | if (!extension_prop) { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3634 | /* Didn't find extension name in any of the global layers, error out |
| 3635 | */ |
Courtney Goeltzenleuchter | ac544f3 | 2015-09-14 18:01:17 -0600 | [diff] [blame] | 3636 | return VK_ERROR_EXTENSION_NOT_PRESENT; |
Courtney Goeltzenleuchter | a17697f | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 3637 | } |
| 3638 | } |
| 3639 | return VK_SUCCESS; |
| 3640 | } |
| 3641 | |
| 3642 | VkResult loader_validate_device_extensions( |
Jon Ashburn | 3c4a114 | 2016-03-24 15:49:57 -0600 | [diff] [blame] | 3643 | struct loader_physical_device_tramp *phys_dev, |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3644 | const struct loader_layer_list *activated_device_layers, |
Jon Ashburn | 8766043 | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 3645 | const struct loader_extension_list *icd_exts, |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3646 | const VkDeviceCreateInfo *pCreateInfo) { |
Jon Ashburn | c4748dc | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 3647 | VkExtensionProperties *extension_prop; |
Courtney Goeltzenleuchter | a17697f | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 3648 | struct loader_layer_properties *layer_prop; |
| 3649 | |
Jon Ashburn | a4ae48b | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 3650 | for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) { |
Mark Lobodzinski | c882eee | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 3651 | |
Jon Ashburn | 7ec85cd | 2016-02-10 20:50:19 -0700 | [diff] [blame] | 3652 | VkStringErrorFlags result = vk_string_validate( |
| 3653 | MaxLoaderStringLength, pCreateInfo->ppEnabledExtensionNames[i]); |
Mark Lobodzinski | c882eee | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 3654 | if (result != VK_STRING_ERROR_NONE) { |
Jon Ashburn | 9b2a8c9 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 3655 | loader_log(phys_dev->this_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3656 | 0, "Loader: Device ppEnabledExtensionNames contains " |
| 3657 | "string that is too long or is badly formed"); |
Mark Lobodzinski | c882eee | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 3658 | return VK_ERROR_EXTENSION_NOT_PRESENT; |
| 3659 | } |
| 3660 | |
Courtney Goeltzenleuchter | a17697f | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 3661 | const char *extension_name = pCreateInfo->ppEnabledExtensionNames[i]; |
Jon Ashburn | 8766043 | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 3662 | extension_prop = get_extension_property(extension_name, icd_exts); |
Courtney Goeltzenleuchter | a17697f | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 3663 | |
| 3664 | if (extension_prop) { |
| 3665 | continue; |
| 3666 | } |
| 3667 | |
Jon Ashburn | 6c2fa49 | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 3668 | /* Not in global list, search activated layer extension lists */ |
| 3669 | for (uint32_t j = 0; j < activated_device_layers->count; j++) { |
| 3670 | layer_prop = &activated_device_layers->list[j]; |
Courtney Goeltzenleuchter | a17697f | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 3671 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3672 | extension_prop = get_dev_extension_property( |
| 3673 | extension_name, &layer_prop->device_extension_list); |
Courtney Goeltzenleuchter | a17697f | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 3674 | if (extension_prop) { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3675 | /* Found the extension in one of the layers enabled by the app. |
| 3676 | */ |
Courtney Goeltzenleuchter | a17697f | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 3677 | break; |
| 3678 | } |
| 3679 | } |
| 3680 | |
| 3681 | if (!extension_prop) { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3682 | /* Didn't find extension name in any of the device layers, error out |
| 3683 | */ |
Courtney Goeltzenleuchter | ac544f3 | 2015-09-14 18:01:17 -0600 | [diff] [blame] | 3684 | return VK_ERROR_EXTENSION_NOT_PRESENT; |
Courtney Goeltzenleuchter | a17697f | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 3685 | } |
| 3686 | } |
Courtney Goeltzenleuchter | 5d9f29b | 2015-07-06 17:45:08 -0600 | [diff] [blame] | 3687 | return VK_SUCCESS; |
| 3688 | } |
| 3689 | |
Jon Ashburn | a9c4a57 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 3690 | /** |
| 3691 | * Terminator functions for the Instance chain |
| 3692 | * All named terminator_<Vulakn API name> |
| 3693 | */ |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3694 | VKAPI_ATTR VkResult VKAPI_CALL |
Jon Ashburn | a9c4a57 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 3695 | terminator_CreateInstance(const VkInstanceCreateInfo *pCreateInfo, |
| 3696 | const VkAllocationCallbacks *pAllocator, |
| 3697 | VkInstance *pInstance) { |
Jon Ashburn | 3336df8 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 3698 | struct loader_icd *icd; |
Jon Ashburn | c4748dc | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 3699 | VkExtensionProperties *prop; |
Courtney Goeltzenleuchter | ab27f46 | 2015-07-06 17:42:01 -0600 | [diff] [blame] | 3700 | char **filtered_extension_names = NULL; |
| 3701 | VkInstanceCreateInfo icd_create_info; |
Courtney Goeltzenleuchter | 1fcceeb | 2015-07-06 09:06:34 -0600 | [diff] [blame] | 3702 | VkResult res = VK_SUCCESS; |
Jon Ashburn | 2869bc7 | 2015-11-19 09:29:51 -0700 | [diff] [blame] | 3703 | bool success = false; |
Jon Ashburn | 349508d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 3704 | |
Jon Ashburn | 9b2a8c9 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 3705 | struct loader_instance *ptr_instance = (struct loader_instance *)*pInstance; |
Tony Barbour | 809d5d3 | 2015-12-04 13:24:39 -0700 | [diff] [blame] | 3706 | memcpy(&icd_create_info, pCreateInfo, sizeof(icd_create_info)); |
| 3707 | |
Jon Ashburn | a4ae48b | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 3708 | icd_create_info.enabledLayerCount = 0; |
Courtney Goeltzenleuchter | ab27f46 | 2015-07-06 17:42:01 -0600 | [diff] [blame] | 3709 | icd_create_info.ppEnabledLayerNames = NULL; |
Courtney Goeltzenleuchter | ab27f46 | 2015-07-06 17:42:01 -0600 | [diff] [blame] | 3710 | |
Courtney Goeltzenleuchter | f5f244d | 2016-01-15 14:15:00 -0700 | [diff] [blame] | 3711 | // strip off the VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO entries |
| 3712 | icd_create_info.pNext = loader_strip_create_extensions(pCreateInfo->pNext); |
Courtney Goeltzenleuchter | 2bdf6da | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3713 | |
Courtney Goeltzenleuchter | ab27f46 | 2015-07-06 17:42:01 -0600 | [diff] [blame] | 3714 | /* |
| 3715 | * NOTE: Need to filter the extensions to only those |
Courtney Goeltzenleuchter | a17697f | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 3716 | * supported by the ICD. |
Courtney Goeltzenleuchter | ab27f46 | 2015-07-06 17:42:01 -0600 | [diff] [blame] | 3717 | * No ICD will advertise support for layers. An ICD |
| 3718 | * library could support a layer, but it would be |
| 3719 | * independent of the actual ICD, just in the same library. |
| 3720 | */ |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3721 | filtered_extension_names = |
| 3722 | loader_stack_alloc(pCreateInfo->enabledExtensionCount * sizeof(char *)); |
Courtney Goeltzenleuchter | ab27f46 | 2015-07-06 17:42:01 -0600 | [diff] [blame] | 3723 | if (!filtered_extension_names) { |
| 3724 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 3725 | } |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3726 | icd_create_info.ppEnabledExtensionNames = |
| 3727 | (const char *const *)filtered_extension_names; |
Courtney Goeltzenleuchter | ab27f46 | 2015-07-06 17:42:01 -0600 | [diff] [blame] | 3728 | |
Jon Ashburn | 754f199 | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 3729 | for (uint32_t i = 0; i < ptr_instance->icd_libs.count; i++) { |
| 3730 | icd = loader_icd_add(ptr_instance, &ptr_instance->icd_libs.list[i]); |
Jon Ashburn | 3336df8 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 3731 | if (icd) { |
Jon Ashburn | a4ae48b | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 3732 | icd_create_info.enabledExtensionCount = 0; |
Courtney Goeltzenleuchter | f843d2d | 2015-12-21 16:41:47 -0700 | [diff] [blame] | 3733 | struct loader_extension_list icd_exts; |
| 3734 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3735 | loader_log(ptr_instance, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, |
| 3736 | "Build ICD instance extension list"); |
| 3737 | // traverse scanned icd list adding non-duplicate extensions to the |
| 3738 | // list |
| 3739 | loader_init_generic_list(ptr_instance, |
| 3740 | (struct loader_generic_list *)&icd_exts, |
Courtney Goeltzenleuchter | f843d2d | 2015-12-21 16:41:47 -0700 | [diff] [blame] | 3741 | sizeof(VkExtensionProperties)); |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3742 | loader_add_instance_extensions( |
| 3743 | ptr_instance, |
| 3744 | icd->this_icd_lib->EnumerateInstanceExtensionProperties, |
| 3745 | icd->this_icd_lib->lib_name, &icd_exts); |
Courtney Goeltzenleuchter | f843d2d | 2015-12-21 16:41:47 -0700 | [diff] [blame] | 3746 | |
Karl Schultz | c50a598 | 2016-02-24 14:39:39 -0700 | [diff] [blame] | 3747 | for (uint32_t j = 0; j < pCreateInfo->enabledExtensionCount; j++) { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3748 | prop = get_extension_property( |
Karl Schultz | c50a598 | 2016-02-24 14:39:39 -0700 | [diff] [blame] | 3749 | pCreateInfo->ppEnabledExtensionNames[j], &icd_exts); |
Courtney Goeltzenleuchter | ab27f46 | 2015-07-06 17:42:01 -0600 | [diff] [blame] | 3750 | if (prop) { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3751 | filtered_extension_names[icd_create_info |
| 3752 | .enabledExtensionCount] = |
Karl Schultz | c50a598 | 2016-02-24 14:39:39 -0700 | [diff] [blame] | 3753 | (char *)pCreateInfo->ppEnabledExtensionNames[j]; |
Jon Ashburn | a4ae48b | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 3754 | icd_create_info.enabledExtensionCount++; |
Courtney Goeltzenleuchter | ab27f46 | 2015-07-06 17:42:01 -0600 | [diff] [blame] | 3755 | } |
| 3756 | } |
| 3757 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3758 | loader_destroy_generic_list( |
| 3759 | ptr_instance, (struct loader_generic_list *)&icd_exts); |
Courtney Goeltzenleuchter | f843d2d | 2015-12-21 16:41:47 -0700 | [diff] [blame] | 3760 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3761 | res = ptr_instance->icd_libs.list[i].CreateInstance( |
| 3762 | &icd_create_info, pAllocator, &(icd->instance)); |
Jon Ashburn | 2869bc7 | 2015-11-19 09:29:51 -0700 | [diff] [blame] | 3763 | if (res == VK_SUCCESS) |
| 3764 | success = loader_icd_init_entrys( |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3765 | icd, icd->instance, |
| 3766 | ptr_instance->icd_libs.list[i].GetInstanceProcAddr); |
Jon Ashburn | ce7e3d9 | 2015-07-16 10:17:29 -0600 | [diff] [blame] | 3767 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3768 | if (res != VK_SUCCESS || !success) { |
Jon Ashburn | 3336df8 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 3769 | ptr_instance->icds = ptr_instance->icds->next; |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3770 | loader_icd_destroy(ptr_instance, icd); |
Courtney Goeltzenleuchter | acb1359 | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 3771 | loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3772 | "ICD ignored: failed to CreateInstance and find " |
| 3773 | "entrypoints with ICD"); |
Jon Ashburn | 3336df8 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 3774 | } |
| 3775 | } |
Jon Ashburn | 3336df8 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 3776 | } |
Jon Ashburn | 349508d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 3777 | |
Courtney Goeltzenleuchter | 1fcceeb | 2015-07-06 09:06:34 -0600 | [diff] [blame] | 3778 | /* |
| 3779 | * If no ICDs were added to instance list and res is unchanged |
| 3780 | * from it's initial value, the loader was unable to find |
| 3781 | * a suitable ICD. |
| 3782 | */ |
Ian Elliott | 617fdec | 2015-02-05 15:19:15 -0700 | [diff] [blame] | 3783 | if (ptr_instance->icds == NULL) { |
Courtney Goeltzenleuchter | 1fcceeb | 2015-07-06 09:06:34 -0600 | [diff] [blame] | 3784 | if (res == VK_SUCCESS) { |
| 3785 | return VK_ERROR_INCOMPATIBLE_DRIVER; |
| 3786 | } else { |
| 3787 | return res; |
| 3788 | } |
Ian Elliott | 617fdec | 2015-02-05 15:19:15 -0700 | [diff] [blame] | 3789 | } |
Jon Ashburn | 3336df8 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 3790 | |
Courtney Goeltzenleuchter | 1fcceeb | 2015-07-06 09:06:34 -0600 | [diff] [blame] | 3791 | return VK_SUCCESS; |
Jon Ashburn | 349508d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 3792 | } |
| 3793 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3794 | VKAPI_ATTR void VKAPI_CALL |
Jon Ashburn | a9c4a57 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 3795 | terminator_DestroyInstance(VkInstance instance, |
| 3796 | const VkAllocationCallbacks *pAllocator) { |
Courtney Goeltzenleuchter | 8afefb5 | 2015-06-08 15:04:02 -0600 | [diff] [blame] | 3797 | struct loader_instance *ptr_instance = loader_instance(instance); |
Jon Ashburn | 0dd356d | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 3798 | struct loader_icd *icds = ptr_instance->icds; |
Jon Ashburn | 16a16d6 | 2015-06-16 14:43:19 -0600 | [diff] [blame] | 3799 | struct loader_icd *next_icd; |
Jon Ashburn | 349508d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 3800 | |
| 3801 | // Remove this instance from the list of instances: |
| 3802 | struct loader_instance *prev = NULL; |
| 3803 | struct loader_instance *next = loader.instances; |
| 3804 | while (next != NULL) { |
| 3805 | if (next == ptr_instance) { |
| 3806 | // Remove this instance from the list: |
| 3807 | if (prev) |
| 3808 | prev->next = next->next; |
Jon Ashburn | 2cabd25 | 2015-02-03 09:26:59 -0700 | [diff] [blame] | 3809 | else |
| 3810 | loader.instances = next->next; |
Jon Ashburn | 349508d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 3811 | break; |
| 3812 | } |
| 3813 | prev = next; |
| 3814 | next = next->next; |
| 3815 | } |
Jon Ashburn | 349508d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 3816 | |
Jon Ashburn | 0dd356d | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 3817 | while (icds) { |
| 3818 | if (icds->instance) { |
Chia-I Wu | 69f4012 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 3819 | icds->DestroyInstance(icds->instance, pAllocator); |
Tony Barbour | 22a3086 | 2015-04-22 09:02:32 -0600 | [diff] [blame] | 3820 | } |
Jon Ashburn | 16a16d6 | 2015-06-16 14:43:19 -0600 | [diff] [blame] | 3821 | next_icd = icds->next; |
Jon Ashburn | 0dd356d | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 3822 | icds->instance = VK_NULL_HANDLE; |
Jon Ashburn | 16a16d6 | 2015-06-16 14:43:19 -0600 | [diff] [blame] | 3823 | loader_icd_destroy(ptr_instance, icds); |
| 3824 | |
| 3825 | icds = next_icd; |
Jon Ashburn | 3336df8 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 3826 | } |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3827 | loader_delete_layer_properties(ptr_instance, |
| 3828 | &ptr_instance->device_layer_list); |
| 3829 | loader_delete_layer_properties(ptr_instance, |
| 3830 | &ptr_instance->instance_layer_list); |
Jon Ashburn | e58f1a3 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 3831 | loader_scanned_icd_clear(ptr_instance, &ptr_instance->icd_libs); |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3832 | loader_destroy_generic_list( |
| 3833 | ptr_instance, (struct loader_generic_list *)&ptr_instance->ext_list); |
Jon Ashburn | 8766043 | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 3834 | if (ptr_instance->phys_devs_term) |
| 3835 | loader_heap_free(ptr_instance, ptr_instance->phys_devs_term); |
Jon Ashburn | 429e19f | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3836 | loader_free_dev_ext_table(ptr_instance); |
Jon Ashburn | 349508d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 3837 | } |
| 3838 | |
Jon Ashburn | a9c4a57 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 3839 | VKAPI_ATTR VkResult VKAPI_CALL |
| 3840 | terminator_CreateDevice(VkPhysicalDevice physicalDevice, |
| 3841 | const VkDeviceCreateInfo *pCreateInfo, |
| 3842 | const VkAllocationCallbacks *pAllocator, |
| 3843 | VkDevice *pDevice) { |
| 3844 | struct loader_physical_device *phys_dev; |
Jon Ashburn | 8766043 | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 3845 | phys_dev = (struct loader_physical_device *)physicalDevice; |
Jon Ashburn | 251258f | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 3846 | |
Jon Ashburn | 9b2a8c9 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 3847 | struct loader_device *dev = (struct loader_device *)*pDevice; |
Jon Ashburn | 1d41bc5 | 2016-03-29 12:52:13 -0600 | [diff] [blame] | 3848 | PFN_vkCreateDevice fpCreateDevice = phys_dev->this_icd->CreateDevice; |
Courtney Goeltzenleuchter | 23b5f8d | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 3849 | |
Jon Ashburn | a9c4a57 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 3850 | if (fpCreateDevice == NULL) { |
| 3851 | return VK_ERROR_INITIALIZATION_FAILED; |
Courtney Goeltzenleuchter | 23b5f8d | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 3852 | } |
| 3853 | |
Jon Ashburn | a9c4a57 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 3854 | VkDeviceCreateInfo localCreateInfo; |
| 3855 | memcpy(&localCreateInfo, pCreateInfo, sizeof(localCreateInfo)); |
| 3856 | localCreateInfo.pNext = loader_strip_create_extensions(pCreateInfo->pNext); |
| 3857 | |
| 3858 | /* |
| 3859 | * NOTE: Need to filter the extensions to only those |
| 3860 | * supported by the ICD. |
| 3861 | * No ICD will advertise support for layers. An ICD |
| 3862 | * library could support a layer, but it would be |
| 3863 | * independent of the actual ICD, just in the same library. |
| 3864 | */ |
| 3865 | char **filtered_extension_names = NULL; |
| 3866 | filtered_extension_names = |
| 3867 | loader_stack_alloc(pCreateInfo->enabledExtensionCount * sizeof(char *)); |
| 3868 | if (!filtered_extension_names) { |
Jon Ashburn | 251258f | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 3869 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Courtney Goeltzenleuchter | 23b5f8d | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 3870 | } |
| 3871 | |
Jon Ashburn | a9c4a57 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 3872 | localCreateInfo.enabledLayerCount = 0; |
| 3873 | localCreateInfo.ppEnabledLayerNames = NULL; |
| 3874 | |
| 3875 | localCreateInfo.enabledExtensionCount = 0; |
| 3876 | localCreateInfo.ppEnabledExtensionNames = |
| 3877 | (const char *const *)filtered_extension_names; |
| 3878 | |
Jon Ashburn | 8766043 | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 3879 | /* Get the physical device (ICD) extensions */ |
| 3880 | struct loader_extension_list icd_exts; |
| 3881 | VkResult res; |
| 3882 | if (!loader_init_generic_list(phys_dev->this_icd->this_instance, |
| 3883 | (struct loader_generic_list *)&icd_exts, |
| 3884 | sizeof(VkExtensionProperties))) { |
| 3885 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 3886 | } |
| 3887 | |
| 3888 | res = loader_add_device_extensions( |
Jon Ashburn | 9b2a8c9 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 3889 | phys_dev->this_icd->this_instance, |
| 3890 | phys_dev->this_icd->EnumerateDeviceExtensionProperties, |
Jon Ashburn | 8766043 | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 3891 | phys_dev->phys_dev, phys_dev->this_icd->this_icd_lib->lib_name, |
| 3892 | &icd_exts); |
| 3893 | if (res != VK_SUCCESS) { |
| 3894 | return res; |
| 3895 | } |
| 3896 | |
Jon Ashburn | a9c4a57 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 3897 | for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) { |
| 3898 | const char *extension_name = pCreateInfo->ppEnabledExtensionNames[i]; |
Jon Ashburn | 8766043 | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 3899 | VkExtensionProperties *prop = |
| 3900 | get_extension_property(extension_name, &icd_exts); |
Jon Ashburn | a9c4a57 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 3901 | if (prop) { |
| 3902 | filtered_extension_names[localCreateInfo.enabledExtensionCount] = |
| 3903 | (char *)extension_name; |
| 3904 | localCreateInfo.enabledExtensionCount++; |
| 3905 | } |
| 3906 | } |
| 3907 | |
Jon Ashburn | a9c4a57 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 3908 | // TODO: Why does fpCreateDevice behave differently than |
| 3909 | // this_icd->CreateDevice? |
| 3910 | // VkResult res = fpCreateDevice(phys_dev->phys_dev, &localCreateInfo, |
| 3911 | // pAllocator, &localDevice); |
Jon Ashburn | 8766043 | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 3912 | res = phys_dev->this_icd->CreateDevice(phys_dev->phys_dev, &localCreateInfo, |
Jon Ashburn | 0c24d89 | 2016-04-01 11:49:39 -0600 | [diff] [blame] | 3913 | pAllocator, &dev->device); |
Jon Ashburn | a9c4a57 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 3914 | |
| 3915 | if (res != VK_SUCCESS) { |
| 3916 | return res; |
| 3917 | } |
| 3918 | |
Jon Ashburn | 0c24d89 | 2016-04-01 11:49:39 -0600 | [diff] [blame] | 3919 | *pDevice = dev->device; |
Jon Ashburn | 9b2a8c9 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 3920 | loader_add_logical_device(phys_dev->this_icd->this_instance, |
| 3921 | phys_dev->this_icd, dev); |
Jon Ashburn | a9c4a57 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 3922 | |
| 3923 | /* Init dispatch pointer in new device object */ |
| 3924 | loader_init_dispatch(*pDevice, &dev->loader_dispatch); |
| 3925 | |
| 3926 | return res; |
Courtney Goeltzenleuchter | 23b5f8d | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 3927 | } |
| 3928 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3929 | VKAPI_ATTR VkResult VKAPI_CALL |
Jon Ashburn | a9c4a57 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 3930 | terminator_EnumeratePhysicalDevices(VkInstance instance, |
| 3931 | uint32_t *pPhysicalDeviceCount, |
| 3932 | VkPhysicalDevice *pPhysicalDevices) { |
Jon Ashburn | 251258f | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 3933 | uint32_t i; |
Jon Ashburn | 8766043 | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 3934 | struct loader_instance *inst = (struct loader_instance *)instance; |
Jon Ashburn | 251258f | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 3935 | VkResult res = VK_SUCCESS; |
Jon Ashburn | b048a9b | 2015-01-28 19:57:09 -0700 | [diff] [blame] | 3936 | |
Jon Ashburn | 8766043 | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 3937 | struct loader_icd *icd; |
| 3938 | struct loader_phys_dev_per_icd *phys_devs; |
| 3939 | |
| 3940 | inst->total_gpu_count = 0; |
| 3941 | phys_devs = (struct loader_phys_dev_per_icd *)loader_stack_alloc( |
| 3942 | sizeof(struct loader_phys_dev_per_icd) * inst->total_icd_count); |
| 3943 | if (!phys_devs) |
| 3944 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 3945 | |
| 3946 | icd = inst->icds; |
| 3947 | for (i = 0; i < inst->total_icd_count; i++) { |
| 3948 | assert(icd); |
| 3949 | res = icd->EnumeratePhysicalDevices(icd->instance, &phys_devs[i].count, |
| 3950 | NULL); |
| 3951 | if (res != VK_SUCCESS) |
| 3952 | return res; |
| 3953 | icd = icd->next; |
Jon Ashburn | b048a9b | 2015-01-28 19:57:09 -0700 | [diff] [blame] | 3954 | } |
| 3955 | |
Jon Ashburn | 8766043 | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 3956 | icd = inst->icds; |
| 3957 | for (i = 0; i < inst->total_icd_count; i++) { |
| 3958 | assert(icd); |
| 3959 | phys_devs[i].phys_devs = (VkPhysicalDevice *)loader_stack_alloc( |
| 3960 | phys_devs[i].count * sizeof(VkPhysicalDevice)); |
| 3961 | if (!phys_devs[i].phys_devs) { |
| 3962 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 3963 | } |
| 3964 | res = icd->EnumeratePhysicalDevices( |
| 3965 | icd->instance, &(phys_devs[i].count), phys_devs[i].phys_devs); |
| 3966 | if ((res == VK_SUCCESS)) { |
| 3967 | inst->total_gpu_count += phys_devs[i].count; |
| 3968 | } else { |
| 3969 | return res; |
| 3970 | } |
| 3971 | phys_devs[i].this_icd = icd; |
| 3972 | icd = icd->next; |
| 3973 | } |
| 3974 | |
| 3975 | *pPhysicalDeviceCount = inst->total_gpu_count; |
Courtney Goeltzenleuchter | 23b5f8d | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 3976 | if (!pPhysicalDevices) { |
Jon Ashburn | 251258f | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 3977 | return res; |
Courtney Goeltzenleuchter | 23b5f8d | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 3978 | } |
Jon Ashburn | b048a9b | 2015-01-28 19:57:09 -0700 | [diff] [blame] | 3979 | |
Jon Ashburn | 8766043 | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 3980 | /* Initialize the output pPhysicalDevices with wrapped loader terminator |
| 3981 | * physicalDevice objects; save this list of wrapped objects in instance |
| 3982 | * struct for later cleanup and use by trampoline code */ |
| 3983 | uint32_t j, idx = 0; |
| 3984 | uint32_t copy_count = 0; |
| 3985 | |
| 3986 | copy_count = (inst->total_gpu_count < *pPhysicalDeviceCount) |
| 3987 | ? inst->total_gpu_count |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3988 | : *pPhysicalDeviceCount; |
Jon Ashburn | 8766043 | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 3989 | |
Jon Ashburn | 8766043 | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 3990 | if (inst->phys_devs_term) |
| 3991 | loader_heap_free(inst, inst->phys_devs_term); |
| 3992 | inst->phys_devs_term = loader_heap_alloc( |
| 3993 | inst, sizeof(struct loader_physical_device) * copy_count, |
| 3994 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
| 3995 | if (!inst->phys_devs_term) |
| 3996 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 3997 | |
| 3998 | for (i = 0; idx < copy_count && i < inst->total_icd_count; i++) { |
Jon Ashburn | fc53d90 | 2016-03-11 14:43:57 -0700 | [diff] [blame] | 3999 | |
Jon Ashburn | 8766043 | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 4000 | for (j = 0; j < phys_devs[i].count && idx < copy_count; j++) { |
| 4001 | loader_set_dispatch((void *)&inst->phys_devs_term[idx], inst->disp); |
| 4002 | inst->phys_devs_term[idx].this_icd = phys_devs[i].this_icd; |
| 4003 | inst->phys_devs_term[idx].phys_dev = phys_devs[i].phys_devs[j]; |
| 4004 | pPhysicalDevices[idx] = |
| 4005 | (VkPhysicalDevice)&inst->phys_devs_term[idx]; |
| 4006 | idx++; |
| 4007 | } |
Courtney Goeltzenleuchter | 23b5f8d | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 4008 | } |
Courtney Goeltzenleuchter | 2bdf6da | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4009 | *pPhysicalDeviceCount = copy_count; |
| 4010 | |
Piers Daniell | fc50041 | 2016-03-29 11:51:11 -0600 | [diff] [blame] | 4011 | // TODO: Is phys_devs being leaked? |
| 4012 | |
Jon Ashburn | 8766043 | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 4013 | if (copy_count < inst->total_gpu_count) { |
| 4014 | inst->total_gpu_count = copy_count; |
Courtney Goeltzenleuchter | 2bdf6da | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4015 | return VK_INCOMPLETE; |
| 4016 | } |
Jon Ashburn | 251258f | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 4017 | return res; |
Jon Ashburn | 349508d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 4018 | } |
| 4019 | |
Jon Ashburn | a9c4a57 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 4020 | VKAPI_ATTR void VKAPI_CALL terminator_GetPhysicalDeviceProperties( |
| 4021 | VkPhysicalDevice physicalDevice, VkPhysicalDeviceProperties *pProperties) { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4022 | struct loader_physical_device *phys_dev = |
| 4023 | (struct loader_physical_device *)physicalDevice; |
Jon Ashburn | 251258f | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 4024 | struct loader_icd *icd = phys_dev->this_icd; |
Jon Ashburn | 0dd356d | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 4025 | |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 4026 | if (icd->GetPhysicalDeviceProperties) |
Jon Ashburn | 251258f | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 4027 | icd->GetPhysicalDeviceProperties(phys_dev->phys_dev, pProperties); |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 4028 | } |
| 4029 | |
Jon Ashburn | a9c4a57 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 4030 | VKAPI_ATTR void VKAPI_CALL terminator_GetPhysicalDeviceQueueFamilyProperties( |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4031 | VkPhysicalDevice physicalDevice, uint32_t *pQueueFamilyPropertyCount, |
| 4032 | VkQueueFamilyProperties *pProperties) { |
| 4033 | struct loader_physical_device *phys_dev = |
| 4034 | (struct loader_physical_device *)physicalDevice; |
Jon Ashburn | 251258f | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 4035 | struct loader_icd *icd = phys_dev->this_icd; |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 4036 | |
Cody Northrop | ef72e2a | 2015-08-03 17:04:53 -0600 | [diff] [blame] | 4037 | if (icd->GetPhysicalDeviceQueueFamilyProperties) |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4038 | icd->GetPhysicalDeviceQueueFamilyProperties( |
| 4039 | phys_dev->phys_dev, pQueueFamilyPropertyCount, pProperties); |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 4040 | } |
| 4041 | |
Jon Ashburn | a9c4a57 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 4042 | VKAPI_ATTR void VKAPI_CALL terminator_GetPhysicalDeviceMemoryProperties( |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4043 | VkPhysicalDevice physicalDevice, |
| 4044 | VkPhysicalDeviceMemoryProperties *pProperties) { |
| 4045 | struct loader_physical_device *phys_dev = |
| 4046 | (struct loader_physical_device *)physicalDevice; |
Jon Ashburn | 251258f | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 4047 | struct loader_icd *icd = phys_dev->this_icd; |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 4048 | |
| 4049 | if (icd->GetPhysicalDeviceMemoryProperties) |
Jon Ashburn | 251258f | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 4050 | icd->GetPhysicalDeviceMemoryProperties(phys_dev->phys_dev, pProperties); |
Jon Ashburn | 0dd356d | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 4051 | } |
| 4052 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4053 | VKAPI_ATTR void VKAPI_CALL |
Jon Ashburn | a9c4a57 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 4054 | terminator_GetPhysicalDeviceFeatures(VkPhysicalDevice physicalDevice, |
| 4055 | VkPhysicalDeviceFeatures *pFeatures) { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4056 | struct loader_physical_device *phys_dev = |
| 4057 | (struct loader_physical_device *)physicalDevice; |
Jon Ashburn | 251258f | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 4058 | struct loader_icd *icd = phys_dev->this_icd; |
Chris Forbes | d757630 | 2015-06-21 22:55:02 +1200 | [diff] [blame] | 4059 | |
| 4060 | if (icd->GetPhysicalDeviceFeatures) |
Jon Ashburn | 251258f | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 4061 | icd->GetPhysicalDeviceFeatures(phys_dev->phys_dev, pFeatures); |
Chris Forbes | d757630 | 2015-06-21 22:55:02 +1200 | [diff] [blame] | 4062 | } |
| 4063 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4064 | VKAPI_ATTR void VKAPI_CALL |
Jon Ashburn | a9c4a57 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 4065 | terminator_GetPhysicalDeviceFormatProperties(VkPhysicalDevice physicalDevice, |
| 4066 | VkFormat format, |
| 4067 | VkFormatProperties *pFormatInfo) { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4068 | struct loader_physical_device *phys_dev = |
| 4069 | (struct loader_physical_device *)physicalDevice; |
Jon Ashburn | 251258f | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 4070 | struct loader_icd *icd = phys_dev->this_icd; |
Chris Forbes | d757630 | 2015-06-21 22:55:02 +1200 | [diff] [blame] | 4071 | |
Courtney Goeltzenleuchter | 4da96aa | 2015-07-12 12:52:09 -0600 | [diff] [blame] | 4072 | if (icd->GetPhysicalDeviceFormatProperties) |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4073 | icd->GetPhysicalDeviceFormatProperties(phys_dev->phys_dev, format, |
| 4074 | pFormatInfo); |
Chris Forbes | d757630 | 2015-06-21 22:55:02 +1200 | [diff] [blame] | 4075 | } |
| 4076 | |
Jon Ashburn | a9c4a57 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 4077 | VKAPI_ATTR VkResult VKAPI_CALL |
| 4078 | terminator_GetPhysicalDeviceImageFormatProperties( |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4079 | VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, |
| 4080 | VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags, |
| 4081 | VkImageFormatProperties *pImageFormatProperties) { |
| 4082 | struct loader_physical_device *phys_dev = |
| 4083 | (struct loader_physical_device *)physicalDevice; |
Jon Ashburn | 251258f | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 4084 | struct loader_icd *icd = phys_dev->this_icd; |
Jon Ashburn | 4e18956 | 2015-07-23 18:49:07 -0600 | [diff] [blame] | 4085 | |
Chia-I Wu | 5202c54 | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 4086 | if (!icd->GetPhysicalDeviceImageFormatProperties) |
| 4087 | return VK_ERROR_INITIALIZATION_FAILED; |
| 4088 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4089 | return icd->GetPhysicalDeviceImageFormatProperties( |
| 4090 | phys_dev->phys_dev, format, type, tiling, usage, flags, |
| 4091 | pImageFormatProperties); |
Jon Ashburn | 4e18956 | 2015-07-23 18:49:07 -0600 | [diff] [blame] | 4092 | } |
| 4093 | |
Jon Ashburn | a9c4a57 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 4094 | VKAPI_ATTR void VKAPI_CALL |
| 4095 | terminator_GetPhysicalDeviceSparseImageFormatProperties( |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4096 | VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, |
| 4097 | VkSampleCountFlagBits samples, VkImageUsageFlags usage, |
| 4098 | VkImageTiling tiling, uint32_t *pNumProperties, |
| 4099 | VkSparseImageFormatProperties *pProperties) { |
| 4100 | struct loader_physical_device *phys_dev = |
| 4101 | (struct loader_physical_device *)physicalDevice; |
Jon Ashburn | 251258f | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 4102 | struct loader_icd *icd = phys_dev->this_icd; |
Mark Lobodzinski | 83d4e6a | 2015-07-03 15:58:09 -0600 | [diff] [blame] | 4103 | |
| 4104 | if (icd->GetPhysicalDeviceSparseImageFormatProperties) |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4105 | icd->GetPhysicalDeviceSparseImageFormatProperties( |
| 4106 | phys_dev->phys_dev, format, type, samples, usage, tiling, |
| 4107 | pNumProperties, pProperties); |
Mark Lobodzinski | 83d4e6a | 2015-07-03 15:58:09 -0600 | [diff] [blame] | 4108 | } |
| 4109 | |
Jon Ashburn | a9c4a57 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 4110 | VKAPI_ATTR VkResult VKAPI_CALL terminator_EnumerateDeviceExtensionProperties( |
| 4111 | VkPhysicalDevice physicalDevice, const char *pLayerName, |
| 4112 | uint32_t *pPropertyCount, VkExtensionProperties *pProperties) { |
Jon Ashburn | ed158d1 | 2015-12-14 08:52:14 -0700 | [diff] [blame] | 4113 | struct loader_physical_device *phys_dev; |
Courtney Goeltzenleuchter | 0199e95 | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 4114 | |
Jon Ashburn | 6c2fa49 | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 4115 | struct loader_layer_list implicit_layer_list; |
| 4116 | |
Jon Ashburn | 6c2c061 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 4117 | assert(pLayerName == NULL || strlen(pLayerName) == 0); |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 4118 | |
Jon Ashburn | 6c2c061 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 4119 | /* Any layer or trampoline wrapping should be removed at this point in time |
| 4120 | * can just cast to the expected type for VkPhysicalDevice. */ |
Jon Ashburn | 8766043 | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 4121 | phys_dev = (struct loader_physical_device *)physicalDevice; |
Jon Ashburn | 6c2fa49 | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 4122 | |
Jon Ashburn | 6c2c061 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 4123 | /* this case is during the call down the instance chain with pLayerName |
| 4124 | * == NULL*/ |
| 4125 | struct loader_icd *icd = phys_dev->this_icd; |
| 4126 | uint32_t icd_ext_count = *pPropertyCount; |
| 4127 | VkResult res; |
Jon Ashburn | 6c2fa49 | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 4128 | |
Jon Ashburn | 6c2c061 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 4129 | /* get device extensions */ |
Jon Ashburn | 8766043 | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 4130 | res = icd->EnumerateDeviceExtensionProperties(phys_dev->phys_dev, NULL, |
| 4131 | &icd_ext_count, pProperties); |
Jon Ashburn | 6c2c061 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 4132 | if (res != VK_SUCCESS) |
| 4133 | return res; |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4134 | |
Jon Ashburn | 8766043 | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 4135 | loader_init_layer_list(icd->this_instance, &implicit_layer_list); |
Jon Ashburn | 6c2fa49 | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 4136 | |
Jon Ashburn | 6c2c061 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 4137 | loader_add_layer_implicit( |
Jon Ashburn | 8766043 | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 4138 | icd->this_instance, VK_LAYER_TYPE_INSTANCE_IMPLICIT, |
| 4139 | &implicit_layer_list, &icd->this_instance->instance_layer_list); |
Jon Ashburn | 6c2c061 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 4140 | /* we need to determine which implicit layers are active, |
| 4141 | * and then add their extensions. This can't be cached as |
| 4142 | * it depends on results of environment variables (which can change). |
| 4143 | */ |
| 4144 | if (pProperties != NULL) { |
Jon Ashburn | 8766043 | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 4145 | struct loader_extension_list icd_exts; |
Jon Ashburn | 6c2c061 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 4146 | /* initialize dev_extension list within the physicalDevice object */ |
Jon Ashburn | 8766043 | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 4147 | res = loader_init_device_extensions(icd->this_instance, phys_dev, |
| 4148 | icd_ext_count, pProperties, |
| 4149 | &icd_exts); |
Jon Ashburn | 6c2c061 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 4150 | if (res != VK_SUCCESS) |
| 4151 | return res; |
Jon Ashburn | 6c2fa49 | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 4152 | |
Jon Ashburn | 6c2c061 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 4153 | /* we need to determine which implicit layers are active, |
| 4154 | * and then add their extensions. This can't be cached as |
| 4155 | * it depends on results of environment variables (which can |
| 4156 | * change). |
| 4157 | */ |
| 4158 | struct loader_extension_list all_exts = {0}; |
Jon Ashburn | 8766043 | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 4159 | loader_add_to_ext_list(icd->this_instance, &all_exts, icd_exts.count, |
| 4160 | icd_exts.list); |
Jon Ashburn | 6c2fa49 | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 4161 | |
Jon Ashburn | 8766043 | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 4162 | loader_init_layer_list(icd->this_instance, &implicit_layer_list); |
Jon Ashburn | 6c2fa49 | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 4163 | |
Jon Ashburn | 6c2c061 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 4164 | loader_add_layer_implicit( |
Jon Ashburn | 8766043 | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 4165 | icd->this_instance, VK_LAYER_TYPE_INSTANCE_IMPLICIT, |
| 4166 | &implicit_layer_list, &icd->this_instance->instance_layer_list); |
Jon Ashburn | 6c2fa49 | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 4167 | |
Jon Ashburn | 6c2c061 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 4168 | for (uint32_t i = 0; i < implicit_layer_list.count; i++) { |
| 4169 | for (uint32_t j = 0; |
Jon Ashburn | 8766043 | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 4170 | j < implicit_layer_list.list[i].device_extension_list.count; |
| 4171 | j++) { |
| 4172 | loader_add_to_ext_list(icd->this_instance, &all_exts, 1, |
| 4173 | &implicit_layer_list.list[i] |
| 4174 | .device_extension_list.list[j] |
| 4175 | .props); |
Jon Ashburn | 6c2fa49 | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 4176 | } |
Jon Ashburn | 6c2fa49 | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 4177 | } |
Jon Ashburn | 6c2c061 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 4178 | uint32_t capacity = *pPropertyCount; |
| 4179 | VkExtensionProperties *props = pProperties; |
Jon Ashburn | 6c2fa49 | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 4180 | |
Jon Ashburn | 6c2c061 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 4181 | for (uint32_t i = 0; i < all_exts.count && i < capacity; i++) { |
| 4182 | props[i] = all_exts.list[i]; |
| 4183 | } |
| 4184 | /* wasn't enough space for the extensions, we did partial copy now |
| 4185 | * return VK_INCOMPLETE */ |
| 4186 | if (capacity < all_exts.count) { |
| 4187 | res = VK_INCOMPLETE; |
| 4188 | } else { |
| 4189 | *pPropertyCount = all_exts.count; |
| 4190 | } |
Jon Ashburn | 8766043 | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 4191 | loader_destroy_generic_list(icd->this_instance, |
| 4192 | (struct loader_generic_list *)&all_exts); |
Jon Ashburn | 6c2c061 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 4193 | } else { |
| 4194 | /* just return the count; need to add in the count of implicit layer |
| 4195 | * extensions |
| 4196 | * don't worry about duplicates being added in the count */ |
| 4197 | *pPropertyCount = icd_ext_count; |
| 4198 | |
| 4199 | for (uint32_t i = 0; i < implicit_layer_list.count; i++) { |
| 4200 | *pPropertyCount += |
Jon Ashburn | 8766043 | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 4201 | implicit_layer_list.list[i].device_extension_list.count; |
Jon Ashburn | 6c2c061 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 4202 | } |
| 4203 | res = VK_SUCCESS; |
Jon Ashburn | 182b830 | 2015-08-11 14:49:54 -0600 | [diff] [blame] | 4204 | } |
Jon Ashburn | 6c2c061 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 4205 | |
| 4206 | loader_destroy_generic_list( |
Jon Ashburn | 8766043 | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 4207 | icd->this_instance, (struct loader_generic_list *)&implicit_layer_list); |
Jon Ashburn | 6c2c061 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 4208 | return res; |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 4209 | } |
| 4210 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4211 | VKAPI_ATTR VkResult VKAPI_CALL |
Jon Ashburn | a9c4a57 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 4212 | terminator_EnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice, |
| 4213 | uint32_t *pPropertyCount, |
| 4214 | VkLayerProperties *pProperties) { |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 4215 | |
Jon Ashburn | 6c2c061 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 4216 | // should never get here this call isn't dispatched down the chain |
| 4217 | return VK_ERROR_INITIALIZATION_FAILED; |
Jon Ashburn | 2666e2f | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 4218 | } |
Mark Lobodzinski | c882eee | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 4219 | |
Jon Ashburn | 7ec85cd | 2016-02-10 20:50:19 -0700 | [diff] [blame] | 4220 | VkStringErrorFlags vk_string_validate(const int max_length, const char *utf8) { |
Mark Lobodzinski | c882eee | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 4221 | VkStringErrorFlags result = VK_STRING_ERROR_NONE; |
Karl Schultz | c50a598 | 2016-02-24 14:39:39 -0700 | [diff] [blame] | 4222 | int num_char_bytes = 0; |
Jon Ashburn | 7ec85cd | 2016-02-10 20:50:19 -0700 | [diff] [blame] | 4223 | int i, j; |
Mark Lobodzinski | c882eee | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 4224 | |
Jon Ashburn | 7ec85cd | 2016-02-10 20:50:19 -0700 | [diff] [blame] | 4225 | for (i = 0; i < max_length; i++) { |
Mark Lobodzinski | c882eee | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 4226 | if (utf8[i] == 0) { |
| 4227 | break; |
Mark Lobodzinski | 4870635 | 2016-02-12 11:30:14 -0700 | [diff] [blame] | 4228 | } else if ((utf8[i] >= 0x20) && (utf8[i] < 0x7f)) { |
Mark Lobodzinski | c882eee | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 4229 | num_char_bytes = 0; |
Jon Ashburn | 7ec85cd | 2016-02-10 20:50:19 -0700 | [diff] [blame] | 4230 | } else if ((utf8[i] & UTF8_ONE_BYTE_MASK) == UTF8_ONE_BYTE_CODE) { |
Mark Lobodzinski | c882eee | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 4231 | num_char_bytes = 1; |
Jon Ashburn | 7ec85cd | 2016-02-10 20:50:19 -0700 | [diff] [blame] | 4232 | } else if ((utf8[i] & UTF8_TWO_BYTE_MASK) == UTF8_TWO_BYTE_CODE) { |
Mark Lobodzinski | c882eee | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 4233 | num_char_bytes = 2; |
| 4234 | } else if ((utf8[i] & UTF8_THREE_BYTE_MASK) == UTF8_THREE_BYTE_CODE) { |
| 4235 | num_char_bytes = 3; |
| 4236 | } else { |
| 4237 | result = VK_STRING_ERROR_BAD_DATA; |
| 4238 | } |
| 4239 | |
| 4240 | // Validate the following num_char_bytes of data |
| 4241 | for (j = 0; (j < num_char_bytes) && (i < max_length); j++) { |
| 4242 | if (++i == max_length) { |
| 4243 | result |= VK_STRING_ERROR_LENGTH; |
| 4244 | break; |
| 4245 | } |
| 4246 | if ((utf8[i] & UTF8_DATA_BYTE_MASK) != UTF8_DATA_BYTE_CODE) { |
| 4247 | result |= VK_STRING_ERROR_BAD_DATA; |
| 4248 | } |
| 4249 | } |
| 4250 | } |
| 4251 | return result; |
| 4252 | } |