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