Mark Lobodzinski | 317574e | 2016-08-29 14:21:14 -0600 | [diff] [blame] | 1 | /* |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 2 | * |
Jon Ashburn | 23d36b1 | 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 | f821dad | 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 | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 8 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 | * you may not use this file except in compliance with the License. |
| 10 | * You may obtain a copy of the License at |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 11 | * |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 12 | * http://www.apache.org/licenses/LICENSE-2.0 |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 13 | * |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 14 | * Unless required by applicable law or agreed to in writing, software |
| 15 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 | * See the License for the specific language governing permissions and |
| 18 | * limitations under the License. |
| 19 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 20 | * |
Courtney Goeltzenleuchter | 0555952 | 2015-10-30 11:14:30 -0600 | [diff] [blame] | 21 | * Author: Jon Ashburn <jon@lunarg.com> |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 22 | * Author: Courtney Goeltzenleuchter <courtney@LunarG.com> |
Courtney Goeltzenleuchter | 0555952 | 2015-10-30 11:14:30 -0600 | [diff] [blame] | 23 | * |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 24 | */ |
Mark Lobodzinski | faa9081 | 2015-11-25 13:26:15 -0700 | [diff] [blame] | 25 | |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 26 | #define _GNU_SOURCE |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 27 | #include <stdio.h> |
| 28 | #include <stdlib.h> |
| 29 | #include <stdarg.h> |
| 30 | #include <stdbool.h> |
| 31 | #include <string.h> |
| 32 | |
Chia-I Wu | 13a61a5 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 33 | #include <sys/types.h> |
Johannes van Waveren | 9bd80501 | 2015-10-28 11:45:00 -0500 | [diff] [blame] | 34 | #if defined(_WIN32) |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 35 | #include "dirent_on_windows.h" |
Johannes van Waveren | 9bd80501 | 2015-10-28 11:45:00 -0500 | [diff] [blame] | 36 | #else // _WIN32 |
Chia-I Wu | 13a61a5 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 37 | #include <dirent.h> |
Johannes van Waveren | 9bd80501 | 2015-10-28 11:45:00 -0500 | [diff] [blame] | 38 | #endif // _WIN32 |
Tobin Ehlis | b835d1b | 2015-07-03 10:34:49 -0600 | [diff] [blame] | 39 | #include "vk_loader_platform.h" |
Chia-I Wu | 1930060 | 2014-08-04 08:03:57 +0800 | [diff] [blame] | 40 | #include "loader.h" |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 41 | #include "gpa_helper.h" |
| 42 | #include "table_ops.h" |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 43 | #include "debug_report.h" |
Ian Elliott | 954fa34 | 2015-10-30 15:28:23 -0600 | [diff] [blame] | 44 | #include "wsi.h" |
Mark Lobodzinski | 317574e | 2016-08-29 14:21:14 -0600 | [diff] [blame] | 45 | #include "extensions.h" |
David Pinedo | 9316d3b | 2015-11-06 12:54:48 -0700 | [diff] [blame] | 46 | #include "vulkan/vk_icd.h" |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 47 | #include "cJSON.h" |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 48 | #include "murmurhash.h" |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 49 | |
Jon Ashburn | d8ed799 | 2016-04-04 13:52:53 -0600 | [diff] [blame] | 50 | #if defined(__GNUC__) |
Jon Ashburn | 10b3f83 | 2016-05-09 11:31:40 -0600 | [diff] [blame] | 51 | #if (__GLIBC__ < 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ < 17)) |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 52 | #define secure_getenv __secure_getenv |
| 53 | #endif |
Jon Ashburn | d8ed799 | 2016-04-04 13:52:53 -0600 | [diff] [blame] | 54 | #endif |
| 55 | |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 56 | struct loader_struct loader = {0}; |
Jon Ashburn | 87d6aa9 | 2015-08-28 15:19:27 -0600 | [diff] [blame] | 57 | // TLS for instance for alloc/free callbacks |
| 58 | THREAD_LOCAL_DECL struct loader_instance *tls_instance; |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 59 | |
Courtney Goeltzenleuchter | 0ef13a0 | 2015-12-16 16:19:46 -0700 | [diff] [blame] | 60 | static size_t loader_platform_combine_path(char *dest, size_t len, ...); |
Daniel Dadap | 00b4aba | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 61 | |
Jon Ashburn | 24cd4be | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 62 | struct loader_phys_dev_per_icd { |
| 63 | uint32_t count; |
| 64 | VkPhysicalDevice *phys_devs; |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 65 | struct loader_icd_term *this_icd_term; |
Jon Ashburn | 24cd4be | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 66 | }; |
| 67 | |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 68 | enum loader_debug { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 69 | LOADER_INFO_BIT = 0x01, |
| 70 | LOADER_WARN_BIT = 0x02, |
| 71 | LOADER_PERF_BIT = 0x04, |
| 72 | LOADER_ERROR_BIT = 0x08, |
| 73 | LOADER_DEBUG_BIT = 0x10, |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 74 | }; |
| 75 | |
| 76 | uint32_t g_loader_debug = 0; |
| 77 | uint32_t g_loader_log_msgs = 0; |
| 78 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 79 | // thread safety lock for accessing global data structures such as "loader" |
Jon Ashburn | 6301a0f | 2015-05-29 13:15:39 -0600 | [diff] [blame] | 80 | // all entrypoints on the instance chain need to be locked except GPA |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 81 | // additionally CreateDevice and DestroyDevice needs to be locked |
Jon Ashburn | 6301a0f | 2015-05-29 13:15:39 -0600 | [diff] [blame] | 82 | loader_platform_thread_mutex loader_lock; |
Jon Ashburn | 6461ef2 | 2015-09-22 13:11:00 -0600 | [diff] [blame] | 83 | loader_platform_thread_mutex loader_json_lock; |
Jon Ashburn | 6301a0f | 2015-05-29 13:15:39 -0600 | [diff] [blame] | 84 | |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 85 | const char *std_validation_str = "VK_LAYER_LUNARG_standard_validation"; |
| 86 | |
Ian Elliott | d3ef02f | 2015-07-06 14:36:13 -0600 | [diff] [blame] | 87 | // This table contains the loader's instance dispatch table, which contains |
| 88 | // default functions if no instance layers are activated. This contains |
| 89 | // pointers to "terminator functions". |
Jon Ashburn | 6301a0f | 2015-05-29 13:15:39 -0600 | [diff] [blame] | 90 | const VkLayerInstanceDispatchTable instance_disp = { |
Jon Ashburn | 69e9ea2 | 2015-09-28 16:15:00 -0600 | [diff] [blame] | 91 | .GetInstanceProcAddr = vkGetInstanceProcAddr, |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 92 | .DestroyInstance = terminator_DestroyInstance, |
| 93 | .EnumeratePhysicalDevices = terminator_EnumeratePhysicalDevices, |
| 94 | .GetPhysicalDeviceFeatures = terminator_GetPhysicalDeviceFeatures, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 95 | .GetPhysicalDeviceFormatProperties = |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 96 | terminator_GetPhysicalDeviceFormatProperties, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 97 | .GetPhysicalDeviceImageFormatProperties = |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 98 | terminator_GetPhysicalDeviceImageFormatProperties, |
| 99 | .GetPhysicalDeviceProperties = terminator_GetPhysicalDeviceProperties, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 100 | .GetPhysicalDeviceQueueFamilyProperties = |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 101 | terminator_GetPhysicalDeviceQueueFamilyProperties, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 102 | .GetPhysicalDeviceMemoryProperties = |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 103 | terminator_GetPhysicalDeviceMemoryProperties, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 104 | .EnumerateDeviceExtensionProperties = |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 105 | terminator_EnumerateDeviceExtensionProperties, |
| 106 | .EnumerateDeviceLayerProperties = terminator_EnumerateDeviceLayerProperties, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 107 | .GetPhysicalDeviceSparseImageFormatProperties = |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 108 | terminator_GetPhysicalDeviceSparseImageFormatProperties, |
| 109 | .DestroySurfaceKHR = terminator_DestroySurfaceKHR, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 110 | .GetPhysicalDeviceSurfaceSupportKHR = |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 111 | terminator_GetPhysicalDeviceSurfaceSupportKHR, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 112 | .GetPhysicalDeviceSurfaceCapabilitiesKHR = |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 113 | terminator_GetPhysicalDeviceSurfaceCapabilitiesKHR, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 114 | .GetPhysicalDeviceSurfaceFormatsKHR = |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 115 | terminator_GetPhysicalDeviceSurfaceFormatsKHR, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 116 | .GetPhysicalDeviceSurfacePresentModesKHR = |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 117 | terminator_GetPhysicalDeviceSurfacePresentModesKHR, |
| 118 | .CreateDebugReportCallbackEXT = terminator_CreateDebugReportCallback, |
| 119 | .DestroyDebugReportCallbackEXT = terminator_DestroyDebugReportCallback, |
| 120 | .DebugReportMessageEXT = terminator_DebugReportMessage, |
Mark Lobodzinski | 317574e | 2016-08-29 14:21:14 -0600 | [diff] [blame] | 121 | .GetPhysicalDeviceExternalImageFormatPropertiesNV = |
| 122 | terminator_GetPhysicalDeviceExternalImageFormatPropertiesNV, |
Ian Elliott | db4300a | 2015-11-23 10:17:23 -0700 | [diff] [blame] | 123 | #ifdef VK_USE_PLATFORM_MIR_KHR |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 124 | .CreateMirSurfaceKHR = terminator_CreateMirSurfaceKHR, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 125 | .GetPhysicalDeviceMirPresentationSupportKHR = |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 126 | terminator_GetPhysicalDeviceMirPresentationSupportKHR, |
Ian Elliott | db4300a | 2015-11-23 10:17:23 -0700 | [diff] [blame] | 127 | #endif |
| 128 | #ifdef VK_USE_PLATFORM_WAYLAND_KHR |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 129 | .CreateWaylandSurfaceKHR = terminator_CreateWaylandSurfaceKHR, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 130 | .GetPhysicalDeviceWaylandPresentationSupportKHR = |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 131 | terminator_GetPhysicalDeviceWaylandPresentationSupportKHR, |
Ian Elliott | db4300a | 2015-11-23 10:17:23 -0700 | [diff] [blame] | 132 | #endif |
| 133 | #ifdef VK_USE_PLATFORM_WIN32_KHR |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 134 | .CreateWin32SurfaceKHR = terminator_CreateWin32SurfaceKHR, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 135 | .GetPhysicalDeviceWin32PresentationSupportKHR = |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 136 | terminator_GetPhysicalDeviceWin32PresentationSupportKHR, |
Ian Elliott | db4300a | 2015-11-23 10:17:23 -0700 | [diff] [blame] | 137 | #endif |
| 138 | #ifdef VK_USE_PLATFORM_XCB_KHR |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 139 | .CreateXcbSurfaceKHR = terminator_CreateXcbSurfaceKHR, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 140 | .GetPhysicalDeviceXcbPresentationSupportKHR = |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 141 | terminator_GetPhysicalDeviceXcbPresentationSupportKHR, |
Ian Elliott | db4300a | 2015-11-23 10:17:23 -0700 | [diff] [blame] | 142 | #endif |
| 143 | #ifdef VK_USE_PLATFORM_XLIB_KHR |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 144 | .CreateXlibSurfaceKHR = terminator_CreateXlibSurfaceKHR, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 145 | .GetPhysicalDeviceXlibPresentationSupportKHR = |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 146 | terminator_GetPhysicalDeviceXlibPresentationSupportKHR, |
Ian Elliott | db4300a | 2015-11-23 10:17:23 -0700 | [diff] [blame] | 147 | #endif |
Mark Lobodzinski | a8a5f85 | 2015-12-10 16:25:21 -0700 | [diff] [blame] | 148 | #ifdef VK_USE_PLATFORM_ANDROID_KHR |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 149 | .CreateAndroidSurfaceKHR = terminator_CreateAndroidSurfaceKHR, |
Mark Lobodzinski | a8a5f85 | 2015-12-10 16:25:21 -0700 | [diff] [blame] | 150 | #endif |
Jon Ashburn | c7d3e73 | 2016-03-08 09:30:30 -0700 | [diff] [blame] | 151 | .GetPhysicalDeviceDisplayPropertiesKHR = |
| 152 | terminator_GetPhysicalDeviceDisplayPropertiesKHR, |
| 153 | .GetPhysicalDeviceDisplayPlanePropertiesKHR = |
| 154 | terminator_GetPhysicalDeviceDisplayPlanePropertiesKHR, |
| 155 | .GetDisplayPlaneSupportedDisplaysKHR = |
| 156 | terminator_GetDisplayPlaneSupportedDisplaysKHR, |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 157 | .GetDisplayModePropertiesKHR = terminator_GetDisplayModePropertiesKHR, |
| 158 | .CreateDisplayModeKHR = terminator_CreateDisplayModeKHR, |
| 159 | .GetDisplayPlaneCapabilitiesKHR = terminator_GetDisplayPlaneCapabilitiesKHR, |
| 160 | .CreateDisplayPlaneSurfaceKHR = terminator_CreateDisplayPlaneSurfaceKHR, |
Mark Young | fa55278 | 2016-12-12 16:14:55 -0700 | [diff] [blame] | 161 | |
| 162 | // NVX_device_generated_commands |
| 163 | .GetPhysicalDeviceGeneratedCommandsPropertiesNVX = |
| 164 | terminator_GetPhysicalDeviceGeneratedCommandsPropertiesNVX, |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 165 | }; |
| 166 | |
Lenny Komow | 4053b81 | 2016-12-29 16:27:28 -0700 | [diff] [blame] | 167 | // A null-terminated list of all of the instance extensions supported by the |
| 168 | // loader |
| 169 | static const char *const LOADER_INSTANCE_EXTENSIONS[] = { |
| 170 | VK_KHR_SURFACE_EXTENSION_NAME, |
| 171 | VK_KHR_DISPLAY_EXTENSION_NAME, |
| 172 | #ifdef VK_USE_PLATFORM_XLIB_KHR |
| 173 | VK_KHR_XLIB_SURFACE_EXTENSION_NAME, |
| 174 | #endif |
| 175 | #ifdef VK_USE_PLATFORM_XCB_KHR |
| 176 | VK_KHR_XCB_SURFACE_EXTENSION_NAME, |
| 177 | #endif |
| 178 | #ifdef VK_USE_PLATFORM_WAYLAND_KHR |
| 179 | VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME, |
| 180 | #endif |
| 181 | #ifdef VK_USE_PLATFORM_MIR_KHR |
| 182 | VK_KHR_MIR_SURFACE_EXTENSION_NAME, |
| 183 | #endif |
| 184 | #ifdef VK_USE_PLATFORM_ANDROID_KHR |
| 185 | VK_KHR_ANDROID_SURFACE_EXTENSION_NAME, |
| 186 | #endif |
| 187 | #ifdef VK_USE_PLATFORM_WIN32_KHR |
| 188 | VK_KHR_WIN32_SURFACE_EXTENSION_NAME, |
| 189 | #endif |
| 190 | VK_EXT_DEBUG_REPORT_EXTENSION_NAME, |
| 191 | VK_NV_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME, |
| 192 | VK_EXT_VALIDATION_FLAGS_EXTENSION_NAME, |
| 193 | NULL}; |
| 194 | |
Jon Ashburn | 8810c5f | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 195 | LOADER_PLATFORM_THREAD_ONCE_DECLARATION(once_init); |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 196 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 197 | void *loader_instance_heap_alloc(const struct loader_instance *instance, |
| 198 | size_t size, |
| 199 | VkSystemAllocationScope alloc_scope) { |
| 200 | void *pMemory = NULL; |
| 201 | #if (DEBUG_DISABLE_APP_ALLOCATORS == 1) |
| 202 | { |
| 203 | #else |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 204 | if (instance && instance->alloc_callbacks.pfnAllocation) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 205 | /* These are internal structures, so it's best to align everything to |
| 206 | * the largest unit size which is the size of a uint64_t. |
| 207 | */ |
| 208 | pMemory = instance->alloc_callbacks.pfnAllocation( |
| 209 | instance->alloc_callbacks.pUserData, size, sizeof(uint64_t), |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 210 | alloc_scope); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 211 | } else { |
| 212 | #endif |
| 213 | pMemory = malloc(size); |
Courtney Goeltzenleuchter | 7f5aafc | 2015-07-05 11:28:29 -0600 | [diff] [blame] | 214 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 215 | return pMemory; |
Courtney Goeltzenleuchter | 7f5aafc | 2015-07-05 11:28:29 -0600 | [diff] [blame] | 216 | } |
| 217 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 218 | void loader_instance_heap_free(const struct loader_instance *instance, |
| 219 | void *pMemory) { |
| 220 | if (pMemory != NULL) { |
| 221 | #if (DEBUG_DISABLE_APP_ALLOCATORS == 1) |
| 222 | { |
| 223 | #else |
| 224 | if (instance && instance->alloc_callbacks.pfnFree) { |
| 225 | instance->alloc_callbacks.pfnFree( |
| 226 | instance->alloc_callbacks.pUserData, pMemory); |
| 227 | } else { |
| 228 | #endif |
| 229 | free(pMemory); |
Mark Young | d077f99 | 2016-06-30 11:03:59 -0600 | [diff] [blame] | 230 | } |
Mark Young | 4b0b922 | 2016-06-29 18:33:53 -0600 | [diff] [blame] | 231 | } |
Mark Young | 4b0b922 | 2016-06-29 18:33:53 -0600 | [diff] [blame] | 232 | } |
| 233 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 234 | void *loader_instance_heap_realloc(const struct loader_instance *instance, |
| 235 | void *pMemory, size_t orig_size, size_t size, |
| 236 | VkSystemAllocationScope alloc_scope) { |
| 237 | void *pNewMem = NULL; |
| 238 | if (pMemory == NULL || orig_size == 0) { |
| 239 | pNewMem = loader_instance_heap_alloc(instance, size, alloc_scope); |
| 240 | } else if (size == 0) { |
| 241 | loader_instance_heap_free(instance, pMemory); |
| 242 | #if (DEBUG_DISABLE_APP_ALLOCATORS == 1) |
| 243 | #else |
| 244 | } else if (instance && instance->alloc_callbacks.pfnReallocation) { |
| 245 | /* These are internal structures, so it's best to align everything to |
| 246 | * the largest unit size which is the size of a uint64_t. |
| 247 | */ |
| 248 | pNewMem = instance->alloc_callbacks.pfnReallocation( |
| 249 | instance->alloc_callbacks.pUserData, pMemory, size, |
| 250 | sizeof(uint64_t), alloc_scope); |
| 251 | #endif |
| 252 | } else { |
| 253 | pNewMem = realloc(pMemory, size); |
| 254 | } |
| 255 | return pNewMem; |
Mark Young | 4b0b922 | 2016-06-29 18:33:53 -0600 | [diff] [blame] | 256 | } |
| 257 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 258 | void *loader_instance_tls_heap_alloc(size_t size) { |
| 259 | return loader_instance_heap_alloc(tls_instance, size, |
| 260 | VK_SYSTEM_ALLOCATION_SCOPE_COMMAND); |
Mark Young | 4b0b922 | 2016-06-29 18:33:53 -0600 | [diff] [blame] | 261 | } |
Mark Young | 4b0b922 | 2016-06-29 18:33:53 -0600 | [diff] [blame] | 262 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 263 | void loader_instance_tls_heap_free(void *pMemory) { |
| 264 | loader_instance_heap_free(tls_instance, pMemory); |
| 265 | } |
| 266 | |
| 267 | void *loader_device_heap_alloc(const struct loader_device *device, size_t size, |
| 268 | VkSystemAllocationScope alloc_scope) { |
| 269 | void *pMemory = NULL; |
| 270 | #if (DEBUG_DISABLE_APP_ALLOCATORS == 1) |
| 271 | { |
| 272 | #else |
| 273 | if (device && device->alloc_callbacks.pfnAllocation) { |
| 274 | /* These are internal structures, so it's best to align everything to |
| 275 | * the largest unit size which is the size of a uint64_t. |
| 276 | */ |
| 277 | pMemory = device->alloc_callbacks.pfnAllocation( |
| 278 | device->alloc_callbacks.pUserData, size, sizeof(uint64_t), |
| 279 | alloc_scope); |
| 280 | } else { |
| 281 | #endif |
| 282 | pMemory = malloc(size); |
| 283 | } |
| 284 | return pMemory; |
| 285 | } |
| 286 | |
| 287 | void loader_device_heap_free(const struct loader_device *device, |
| 288 | void *pMemory) { |
| 289 | if (pMemory != NULL) { |
| 290 | #if (DEBUG_DISABLE_APP_ALLOCATORS == 1) |
| 291 | { |
| 292 | #else |
| 293 | if (device && device->alloc_callbacks.pfnFree) { |
| 294 | device->alloc_callbacks.pfnFree(device->alloc_callbacks.pUserData, |
| 295 | pMemory); |
| 296 | } else { |
| 297 | #endif |
| 298 | free(pMemory); |
| 299 | } |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | void *loader_device_heap_realloc(const struct loader_device *device, |
| 304 | void *pMemory, size_t orig_size, size_t size, |
| 305 | VkSystemAllocationScope alloc_scope) { |
| 306 | void *pNewMem = NULL; |
| 307 | if (pMemory == NULL || orig_size == 0) { |
| 308 | pNewMem = loader_device_heap_alloc(device, size, alloc_scope); |
| 309 | } else if (size == 0) { |
| 310 | loader_device_heap_free(device, pMemory); |
| 311 | #if (DEBUG_DISABLE_APP_ALLOCATORS == 1) |
| 312 | #else |
| 313 | } else if (device && device->alloc_callbacks.pfnReallocation) { |
| 314 | /* These are internal structures, so it's best to align everything to |
| 315 | * the largest unit size which is the size of a uint64_t. |
| 316 | */ |
| 317 | pNewMem = device->alloc_callbacks.pfnReallocation( |
| 318 | device->alloc_callbacks.pUserData, pMemory, size, sizeof(uint64_t), |
| 319 | alloc_scope); |
| 320 | #endif |
| 321 | } else { |
| 322 | pNewMem = realloc(pMemory, size); |
| 323 | } |
| 324 | return pNewMem; |
| 325 | } |
| 326 | |
| 327 | // Environment variables |
| 328 | #if defined(__linux__) |
| 329 | |
| 330 | static inline char *loader_getenv(const char *name, |
| 331 | const struct loader_instance *inst) { |
| 332 | // No allocation of memory necessary for Linux, but we should at least touch |
| 333 | // the inst pointer to get rid of compiler warnings. |
| 334 | (void)inst; |
| 335 | return getenv(name); |
| 336 | } |
Frank Henigman | b1c27cb | 2016-11-24 20:02:09 -0500 | [diff] [blame] | 337 | static inline void loader_free_getenv(char *val, |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 338 | const struct loader_instance *inst) { |
| 339 | // No freeing of memory necessary for Linux, but we should at least touch |
| 340 | // the val and inst pointers to get rid of compiler warnings. |
| 341 | (void)val; |
| 342 | (void)inst; |
| 343 | } |
| 344 | |
| 345 | #elif defined(WIN32) |
| 346 | |
| 347 | static inline char *loader_getenv(const char *name, |
| 348 | const struct loader_instance *inst) { |
| 349 | char *retVal; |
| 350 | DWORD valSize; |
| 351 | |
| 352 | valSize = GetEnvironmentVariableA(name, NULL, 0); |
| 353 | |
| 354 | // valSize DOES include the null terminator, so for any set variable |
| 355 | // will always be at least 1. If it's 0, the variable wasn't set. |
| 356 | if (valSize == 0) |
| 357 | return NULL; |
| 358 | |
| 359 | // Allocate the space necessary for the registry entry |
| 360 | if (NULL != inst && NULL != inst->alloc_callbacks.pfnAllocation) { |
| 361 | retVal = (char *)inst->alloc_callbacks.pfnAllocation( |
| 362 | inst->alloc_callbacks.pUserData, valSize, sizeof(char *), |
| 363 | VK_SYSTEM_ALLOCATION_SCOPE_COMMAND); |
| 364 | } else { |
| 365 | retVal = (char *)malloc(valSize); |
| 366 | } |
| 367 | |
| 368 | if (NULL != retVal) { |
| 369 | GetEnvironmentVariableA(name, retVal, valSize); |
| 370 | } |
| 371 | |
| 372 | return retVal; |
| 373 | } |
| 374 | |
| 375 | static inline void loader_free_getenv(char *val, |
| 376 | const struct loader_instance *inst) { |
| 377 | if (NULL != inst && NULL != inst->alloc_callbacks.pfnFree) { |
| 378 | inst->alloc_callbacks.pfnFree(inst->alloc_callbacks.pUserData, val); |
| 379 | } else { |
| 380 | free((void *)val); |
| 381 | } |
| 382 | } |
| 383 | |
| 384 | #else |
| 385 | |
| 386 | static inline char *loader_getenv(const char *name, |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 387 | const struct loader_instance *inst) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 388 | // stub func |
| 389 | (void)inst; |
| 390 | (void)name; |
| 391 | return NULL; |
| 392 | } |
Frank Henigman | b1c27cb | 2016-11-24 20:02:09 -0500 | [diff] [blame] | 393 | static inline void loader_free_getenv(char *val, |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 394 | const struct loader_instance *inst) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 395 | // stub func |
| 396 | (void)val; |
| 397 | (void)inst; |
| 398 | } |
| 399 | |
| 400 | #endif |
| 401 | |
Jon Ashburn | 2e37d75 | 2016-02-12 08:20:06 -0700 | [diff] [blame] | 402 | void loader_log(const struct loader_instance *inst, VkFlags msg_type, |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 403 | int32_t msg_code, const char *format, ...) { |
Jon Ashburn | 86723b0 | 2015-07-31 15:47:59 -0600 | [diff] [blame] | 404 | char msg[512]; |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 405 | char cmd_line_msg[512]; |
| 406 | uint16_t cmd_line_size = sizeof(cmd_line_msg); |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 407 | va_list ap; |
| 408 | int ret; |
| 409 | |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 410 | va_start(ap, format); |
| 411 | ret = vsnprintf(msg, sizeof(msg), format, ap); |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 412 | if ((ret >= (int)sizeof(msg)) || ret < 0) { |
| 413 | msg[sizeof(msg) - 1] = '\0'; |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 414 | } |
| 415 | va_end(ap); |
| 416 | |
Courtney Goeltzenleuchter | 7347739 | 2015-12-03 13:48:01 -0700 | [diff] [blame] | 417 | if (inst) { |
Karl Schultz | 9497129 | 2016-11-19 09:02:27 -0700 | [diff] [blame] | 418 | util_DebugReportMessage( |
| 419 | inst, msg_type, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, |
| 420 | (uint64_t)(uintptr_t)inst, 0, msg_code, "loader", msg); |
Courtney Goeltzenleuchter | 7347739 | 2015-12-03 13:48:01 -0700 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | if (!(msg_type & g_loader_log_msgs)) { |
| 424 | return; |
| 425 | } |
| 426 | |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 427 | cmd_line_msg[0] = '\0'; |
| 428 | |
| 429 | va_start(ap, format); |
| 430 | if ((msg_type & LOADER_INFO_BIT) != 0) { |
| 431 | strcat(cmd_line_msg, "INFO"); |
| 432 | cmd_line_size -= 4; |
| 433 | } |
| 434 | if ((msg_type & LOADER_WARN_BIT) != 0) { |
| 435 | if (cmd_line_size != sizeof(cmd_line_msg)) { |
| 436 | strcat(cmd_line_msg, " | "); |
| 437 | cmd_line_size -= 3; |
| 438 | } |
| 439 | strcat(cmd_line_msg, "WARNING"); |
| 440 | cmd_line_size -= 7; |
| 441 | } |
| 442 | if ((msg_type & LOADER_PERF_BIT) != 0) { |
| 443 | if (cmd_line_size != sizeof(cmd_line_msg)) { |
| 444 | strcat(cmd_line_msg, " | "); |
| 445 | cmd_line_size -= 3; |
| 446 | } |
| 447 | strcat(cmd_line_msg, "PERF"); |
| 448 | cmd_line_size -= 4; |
| 449 | } |
| 450 | if ((msg_type & LOADER_ERROR_BIT) != 0) { |
| 451 | if (cmd_line_size != sizeof(cmd_line_msg)) { |
| 452 | strcat(cmd_line_msg, " | "); |
| 453 | cmd_line_size -= 3; |
| 454 | } |
| 455 | strcat(cmd_line_msg, "ERROR"); |
| 456 | cmd_line_size -= 5; |
| 457 | } |
| 458 | if ((msg_type & LOADER_DEBUG_BIT) != 0) { |
| 459 | if (cmd_line_size != sizeof(cmd_line_msg)) { |
| 460 | strcat(cmd_line_msg, " | "); |
| 461 | cmd_line_size -= 3; |
| 462 | } |
| 463 | strcat(cmd_line_msg, "DEBUG"); |
| 464 | cmd_line_size -= 5; |
| 465 | } |
| 466 | if (cmd_line_size != sizeof(cmd_line_msg)) { |
| 467 | strcat(cmd_line_msg, ": "); |
| 468 | cmd_line_size -= 2; |
| 469 | } |
| 470 | strncat(cmd_line_msg, msg, cmd_line_size); |
| 471 | |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 472 | #if defined(WIN32) |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 473 | OutputDebugString(cmd_line_msg); |
mschott | b9cdb78 | 2015-07-22 14:11:29 +0200 | [diff] [blame] | 474 | OutputDebugString("\n"); |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 475 | #endif |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 476 | fputs(cmd_line_msg, stderr); |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 477 | fputc('\n', stderr); |
| 478 | } |
| 479 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 480 | VKAPI_ATTR VkResult VKAPI_CALL vkSetInstanceDispatch(VkInstance instance, |
| 481 | void *object) { |
Jon Ashburn | c3c5877 | 2016-03-29 11:16:01 -0600 | [diff] [blame] | 482 | |
| 483 | struct loader_instance *inst = loader_get_instance(instance); |
| 484 | if (!inst) { |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 485 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 486 | "vkSetInstanceDispatch: Can not retrieve Instance " |
| 487 | "dispatch table."); |
Jon Ashburn | c3c5877 | 2016-03-29 11:16:01 -0600 | [diff] [blame] | 488 | return VK_ERROR_INITIALIZATION_FAILED; |
| 489 | } |
| 490 | loader_set_dispatch(object, inst->disp); |
| 491 | return VK_SUCCESS; |
| 492 | } |
| 493 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 494 | VKAPI_ATTR VkResult VKAPI_CALL vkSetDeviceDispatch(VkDevice device, |
| 495 | void *object) { |
Jon Ashburn | ed8f231 | 2016-03-31 10:52:22 -0600 | [diff] [blame] | 496 | struct loader_device *dev; |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 497 | struct loader_icd_term *icd_term = |
| 498 | loader_get_icd_and_device(device, &dev, NULL); |
Jon Ashburn | ed8f231 | 2016-03-31 10:52:22 -0600 | [diff] [blame] | 499 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 500 | if (NULL == icd_term) { |
Jon Ashburn | ed8f231 | 2016-03-31 10:52:22 -0600 | [diff] [blame] | 501 | return VK_ERROR_INITIALIZATION_FAILED; |
| 502 | } |
| 503 | loader_set_dispatch(object, &dev->loader_dispatch); |
| 504 | return VK_SUCCESS; |
| 505 | } |
| 506 | |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 507 | #if defined(WIN32) |
Tony Barbour | ea96890 | 2015-07-29 14:26:21 -0600 | [diff] [blame] | 508 | static char *loader_get_next_path(char *path); |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 509 | |
| 510 | // Find the list of registry files (names within a key) in key "location". |
| 511 | // |
| 512 | // This function looks in the registry (hive = DEFAULT_VK_REGISTRY_HIVE) key as |
| 513 | // given in "location" |
| 514 | // for a list or name/values which are added to a returned list (function return |
| 515 | // value). |
| 516 | // The DWORD values within the key must be 0 or they are skipped. |
| 517 | // Function return is a string with a ';' separated list of filenames. |
| 518 | // Function return is NULL if no valid name/value pairs are found in the key, |
| 519 | // or the key is not found. |
| 520 | // |
| 521 | // *reg_data contains a string list of filenames as pointer. |
| 522 | // When done using the returned string list, the caller should free the pointer. |
| 523 | VkResult loaderGetRegistryFiles(const struct loader_instance *inst, |
| 524 | char *location, char **reg_data) { |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 525 | LONG rtn_value; |
| 526 | HKEY hive, key; |
Piers Daniell | 524ec73 | 2015-11-05 16:58:26 -0700 | [diff] [blame] | 527 | DWORD access_flags; |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 528 | char name[2048]; |
Tony Barbour | ea96890 | 2015-07-29 14:26:21 -0600 | [diff] [blame] | 529 | char *loc = location; |
| 530 | char *next; |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 531 | DWORD idx = 0; |
| 532 | DWORD name_size = sizeof(name); |
| 533 | DWORD value; |
| 534 | DWORD total_size = 4096; |
| 535 | DWORD value_size = sizeof(value); |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 536 | VkResult result = VK_SUCCESS; |
| 537 | bool found = false; |
| 538 | |
| 539 | if (NULL == reg_data) { |
| 540 | result = VK_ERROR_INITIALIZATION_FAILED; |
| 541 | goto out; |
| 542 | } |
Tony Barbour | ea96890 | 2015-07-29 14:26:21 -0600 | [diff] [blame] | 543 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 544 | while (*loc) { |
Tony Barbour | ea96890 | 2015-07-29 14:26:21 -0600 | [diff] [blame] | 545 | next = loader_get_next_path(loc); |
| 546 | hive = DEFAULT_VK_REGISTRY_HIVE; |
Piers Daniell | 524ec73 | 2015-11-05 16:58:26 -0700 | [diff] [blame] | 547 | access_flags = KEY_QUERY_VALUE; |
Tony Barbour | ea96890 | 2015-07-29 14:26:21 -0600 | [diff] [blame] | 548 | rtn_value = RegOpenKeyEx(hive, loc, 0, access_flags, &key); |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 549 | if (ERROR_SUCCESS != rtn_value) { |
Mark Young | 93ecb1d | 2016-01-13 13:47:16 -0700 | [diff] [blame] | 550 | // We still couldn't find the key, so give up: |
| 551 | loc = next; |
| 552 | continue; |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 553 | } |
Tony Barbour | ea96890 | 2015-07-29 14:26:21 -0600 | [diff] [blame] | 554 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 555 | while ((rtn_value = RegEnumValue(key, idx++, name, &name_size, NULL, |
| 556 | NULL, (LPBYTE)&value, &value_size)) == |
| 557 | ERROR_SUCCESS) { |
Tony Barbour | ea96890 | 2015-07-29 14:26:21 -0600 | [diff] [blame] | 558 | if (value_size == sizeof(value) && value == 0) { |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 559 | if (NULL == *reg_data) { |
| 560 | *reg_data = loader_instance_heap_alloc( |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 561 | inst, total_size, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 562 | if (NULL == *reg_data) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 563 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 564 | "loaderGetRegistryFiles: Failed to allocate " |
| 565 | "space for registry data for key %s", |
| 566 | name); |
| 567 | result = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 568 | goto out; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 569 | } |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 570 | *reg_data[0] = '\0'; |
| 571 | } else if (strlen(*reg_data) + name_size + 1 > total_size) { |
| 572 | *reg_data = loader_instance_heap_realloc( |
| 573 | inst, *reg_data, total_size, total_size * 2, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 574 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 575 | if (NULL == *reg_data) { |
| 576 | loader_log( |
| 577 | inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 578 | "loaderGetRegistryFiles: Failed to reallocate " |
| 579 | "space for registry value of size %d for key %s", |
| 580 | total_size * 2, name); |
| 581 | result = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 582 | goto out; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 583 | } |
Tony Barbour | ea96890 | 2015-07-29 14:26:21 -0600 | [diff] [blame] | 584 | total_size *= 2; |
| 585 | } |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 586 | if (strlen(*reg_data) == 0) { |
Karl Schultz | e2ef9e6 | 2017-01-13 14:01:35 -0700 | [diff] [blame] | 587 | (void)snprintf(*reg_data, name_size + 1, "%s", name); |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 588 | } else { |
Karl Schultz | e2ef9e6 | 2017-01-13 14:01:35 -0700 | [diff] [blame] | 589 | (void)snprintf(*reg_data + strlen(*reg_data), name_size + 2, |
| 590 | "%c%s", PATH_SEPARATOR, name); |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 591 | } |
| 592 | found = true; |
Tony Barbour | ea96890 | 2015-07-29 14:26:21 -0600 | [diff] [blame] | 593 | } |
| 594 | name_size = 2048; |
| 595 | } |
| 596 | loc = next; |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 597 | } |
Tony Barbour | ea96890 | 2015-07-29 14:26:21 -0600 | [diff] [blame] | 598 | |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 599 | if (!found) { |
| 600 | result = VK_ERROR_INITIALIZATION_FAILED; |
| 601 | } |
| 602 | |
| 603 | out: |
| 604 | |
| 605 | return result; |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 606 | } |
| 607 | |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 608 | #endif // WIN32 |
| 609 | |
Jon Ashburn | c7237a7 | 2015-08-03 09:08:46 -0600 | [diff] [blame] | 610 | /** |
Daniel Dadap | 00b4aba | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 611 | * Combine path elements, separating each element with the platform-specific |
| 612 | * directory separator, and save the combined string to a destination buffer, |
| 613 | * not exceeding the given length. Path elements are given as variadic args, |
| 614 | * with a NULL element terminating the list. |
| 615 | * |
| 616 | * \returns the total length of the combined string, not including an ASCII |
| 617 | * NUL termination character. This length may exceed the available storage: |
| 618 | * in this case, the written string will be truncated to avoid a buffer |
| 619 | * overrun, and the return value will greater than or equal to the storage |
| 620 | * size. A NULL argument may be provided as the destination buffer in order |
| 621 | * to determine the required string length without actually writing a string. |
| 622 | */ |
| 623 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 624 | static size_t loader_platform_combine_path(char *dest, size_t len, ...) { |
Courtney Goeltzenleuchter | 0ef13a0 | 2015-12-16 16:19:46 -0700 | [diff] [blame] | 625 | size_t required_len = 0; |
Daniel Dadap | 00b4aba | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 626 | va_list ap; |
| 627 | const char *component; |
| 628 | |
| 629 | va_start(ap, len); |
| 630 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 631 | while ((component = va_arg(ap, const char *))) { |
Daniel Dadap | 00b4aba | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 632 | if (required_len > 0) { |
| 633 | // This path element is not the first non-empty element; prepend |
| 634 | // a directory separator if space allows |
| 635 | if (dest && required_len + 1 < len) { |
Karl Schultz | e2ef9e6 | 2017-01-13 14:01:35 -0700 | [diff] [blame] | 636 | (void)snprintf(dest + required_len, len - required_len, "%c", |
| 637 | DIRECTORY_SYMBOL); |
Daniel Dadap | 00b4aba | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 638 | } |
| 639 | required_len++; |
| 640 | } |
| 641 | |
| 642 | if (dest && required_len < len) { |
| 643 | strncpy(dest + required_len, component, len - required_len); |
| 644 | } |
| 645 | required_len += strlen(component); |
| 646 | } |
| 647 | |
| 648 | va_end(ap); |
| 649 | |
| 650 | // strncpy(3) won't add a NUL terminating byte in the event of truncation. |
| 651 | if (dest && required_len >= len) { |
| 652 | dest[len - 1] = '\0'; |
| 653 | } |
| 654 | |
| 655 | return required_len; |
| 656 | } |
| 657 | |
Daniel Dadap | 00b4aba | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 658 | /** |
Jon Ashburn | c7237a7 | 2015-08-03 09:08:46 -0600 | [diff] [blame] | 659 | * Given string of three part form "maj.min.pat" convert to a vulkan version |
| 660 | * number. |
| 661 | */ |
Mark Young | 60861ac | 2016-09-02 11:39:26 -0600 | [diff] [blame] | 662 | static uint32_t loader_make_version(char *vers_str) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 663 | uint32_t vers = 0, major = 0, minor = 0, patch = 0; |
Mark Young | 60861ac | 2016-09-02 11:39:26 -0600 | [diff] [blame] | 664 | char *vers_tok; |
Jon Ashburn | c7237a7 | 2015-08-03 09:08:46 -0600 | [diff] [blame] | 665 | |
Mark Young | 60861ac | 2016-09-02 11:39:26 -0600 | [diff] [blame] | 666 | if (!vers_str) { |
Jon Ashburn | c7237a7 | 2015-08-03 09:08:46 -0600 | [diff] [blame] | 667 | return vers; |
Jon Ashburn | c7237a7 | 2015-08-03 09:08:46 -0600 | [diff] [blame] | 668 | } |
Mark Young | 60861ac | 2016-09-02 11:39:26 -0600 | [diff] [blame] | 669 | |
| 670 | vers_tok = strtok(vers_str, ".\"\n\r"); |
| 671 | if (NULL != vers_tok) { |
| 672 | major = (uint16_t)atoi(vers_tok); |
| 673 | vers_tok = strtok(NULL, ".\"\n\r"); |
| 674 | if (NULL != vers_tok) { |
| 675 | minor = (uint16_t)atoi(vers_tok); |
| 676 | vers_tok = strtok(NULL, ".\"\n\r"); |
| 677 | if (NULL != vers_tok) { |
| 678 | patch = (uint16_t)atoi(vers_tok); |
| 679 | } |
| 680 | } |
| 681 | } |
Jon Ashburn | c7237a7 | 2015-08-03 09:08:46 -0600 | [diff] [blame] | 682 | |
| 683 | return VK_MAKE_VERSION(major, minor, patch); |
Jon Ashburn | c7237a7 | 2015-08-03 09:08:46 -0600 | [diff] [blame] | 684 | } |
| 685 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 686 | bool compare_vk_extension_properties(const VkExtensionProperties *op1, |
| 687 | const VkExtensionProperties *op2) { |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 688 | return strcmp(op1->extensionName, op2->extensionName) == 0 ? true : false; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 689 | } |
| 690 | |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 691 | /** |
Jon Ashburn | bd6c488 | 2015-07-02 12:59:25 -0600 | [diff] [blame] | 692 | * Search the given ext_array for an extension |
| 693 | * matching the given vk_ext_prop |
| 694 | */ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 695 | bool has_vk_extension_property_array(const VkExtensionProperties *vk_ext_prop, |
| 696 | const uint32_t count, |
| 697 | const VkExtensionProperties *ext_array) { |
Jon Ashburn | bd6c488 | 2015-07-02 12:59:25 -0600 | [diff] [blame] | 698 | for (uint32_t i = 0; i < count; i++) { |
| 699 | if (compare_vk_extension_properties(vk_ext_prop, &ext_array[i])) |
| 700 | return true; |
| 701 | } |
| 702 | return false; |
| 703 | } |
| 704 | |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 705 | /** |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 706 | * Search the given ext_list for an extension |
| 707 | * matching the given vk_ext_prop |
| 708 | */ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 709 | bool has_vk_extension_property(const VkExtensionProperties *vk_ext_prop, |
| 710 | const struct loader_extension_list *ext_list) { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 711 | for (uint32_t i = 0; i < ext_list->count; i++) { |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 712 | if (compare_vk_extension_properties(&ext_list->list[i], vk_ext_prop)) |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 713 | return true; |
| 714 | } |
| 715 | return false; |
| 716 | } |
| 717 | |
Jon Ashburn | b872696 | 2016-04-08 15:03:35 -0600 | [diff] [blame] | 718 | /** |
| 719 | * Search the given ext_list for a device extension matching the given ext_prop |
| 720 | */ |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 721 | bool has_vk_dev_ext_property( |
| 722 | const VkExtensionProperties *ext_prop, |
| 723 | const struct loader_device_extension_list *ext_list) { |
Jon Ashburn | b872696 | 2016-04-08 15:03:35 -0600 | [diff] [blame] | 724 | for (uint32_t i = 0; i < ext_list->count; i++) { |
| 725 | if (compare_vk_extension_properties(&ext_list->list[i].props, ext_prop)) |
| 726 | return true; |
| 727 | } |
| 728 | return false; |
| 729 | } |
| 730 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 731 | /* |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 732 | * Search the given layer list for a layer matching the given layer name |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 733 | */ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 734 | static struct loader_layer_properties * |
| 735 | loader_get_layer_property(const char *name, |
| 736 | const struct loader_layer_list *layer_list) { |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 737 | for (uint32_t i = 0; i < layer_list->count; i++) { |
| 738 | const VkLayerProperties *item = &layer_list->list[i].info; |
| 739 | if (strcmp(name, item->layerName) == 0) |
| 740 | return &layer_list->list[i]; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 741 | } |
| 742 | return NULL; |
| 743 | } |
| 744 | |
Jon Ashburn | e13ecc9 | 2015-08-03 17:19:30 -0600 | [diff] [blame] | 745 | /** |
| 746 | * Get the next unused layer property in the list. Init the property to zero. |
| 747 | */ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 748 | static struct loader_layer_properties * |
| 749 | loader_get_next_layer_property(const struct loader_instance *inst, |
| 750 | struct loader_layer_list *layer_list) { |
Jon Ashburn | e13ecc9 | 2015-08-03 17:19:30 -0600 | [diff] [blame] | 751 | if (layer_list->capacity == 0) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 752 | layer_list->list = loader_instance_heap_alloc( |
| 753 | inst, sizeof(struct loader_layer_properties) * 64, |
| 754 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Jon Ashburn | e13ecc9 | 2015-08-03 17:19:30 -0600 | [diff] [blame] | 755 | if (layer_list->list == NULL) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 756 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 757 | "loader_get_next_layer_property: Out of memory can " |
| 758 | "not add any layer properties to list"); |
Jon Ashburn | e13ecc9 | 2015-08-03 17:19:30 -0600 | [diff] [blame] | 759 | return NULL; |
| 760 | } |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 761 | memset(layer_list->list, 0, |
| 762 | sizeof(struct loader_layer_properties) * 64); |
Jon Ashburn | e13ecc9 | 2015-08-03 17:19:30 -0600 | [diff] [blame] | 763 | layer_list->capacity = sizeof(struct loader_layer_properties) * 64; |
| 764 | } |
| 765 | |
| 766 | // ensure enough room to add an entry |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 767 | if ((layer_list->count + 1) * sizeof(struct loader_layer_properties) > |
| 768 | layer_list->capacity) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 769 | layer_list->list = loader_instance_heap_realloc( |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 770 | inst, layer_list->list, layer_list->capacity, |
| 771 | layer_list->capacity * 2, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Jon Ashburn | e13ecc9 | 2015-08-03 17:19:30 -0600 | [diff] [blame] | 772 | if (layer_list->list == NULL) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 773 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 774 | "loader_get_next_layer_property: realloc failed for " |
| 775 | "layer list"); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 776 | return NULL; |
Jon Ashburn | e13ecc9 | 2015-08-03 17:19:30 -0600 | [diff] [blame] | 777 | } |
| 778 | layer_list->capacity *= 2; |
| 779 | } |
| 780 | |
| 781 | layer_list->count++; |
| 782 | return &(layer_list->list[layer_list->count - 1]); |
| 783 | } |
| 784 | |
| 785 | /** |
| 786 | * Remove all layer properties entrys from the list |
| 787 | */ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 788 | void loader_delete_layer_properties(const struct loader_instance *inst, |
| 789 | struct loader_layer_list *layer_list) { |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 790 | uint32_t i, j; |
| 791 | struct loader_device_extension_list *dev_ext_list; |
Jon Ashburn | b82c185 | 2015-08-11 14:49:54 -0600 | [diff] [blame] | 792 | if (!layer_list) |
| 793 | return; |
| 794 | |
Jon Ashburn | e13ecc9 | 2015-08-03 17:19:30 -0600 | [diff] [blame] | 795 | for (i = 0; i < layer_list->count; i++) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 796 | loader_destroy_generic_list( |
| 797 | inst, (struct loader_generic_list *)&layer_list->list[i] |
| 798 | .instance_extension_list); |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 799 | dev_ext_list = &layer_list->list[i].device_extension_list; |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 800 | if (dev_ext_list->capacity > 0 && NULL != dev_ext_list->list && |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 801 | dev_ext_list->list->entrypoint_count > 0) { |
| 802 | for (j = 0; j < dev_ext_list->list->entrypoint_count; j++) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 803 | loader_instance_heap_free(inst, |
| 804 | dev_ext_list->list->entrypoints[j]); |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 805 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 806 | loader_instance_heap_free(inst, dev_ext_list->list->entrypoints); |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 807 | } |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 808 | loader_destroy_generic_list(inst, |
| 809 | (struct loader_generic_list *)dev_ext_list); |
Jon Ashburn | e13ecc9 | 2015-08-03 17:19:30 -0600 | [diff] [blame] | 810 | } |
| 811 | layer_list->count = 0; |
| 812 | |
Jon Ashburn | b82c185 | 2015-08-11 14:49:54 -0600 | [diff] [blame] | 813 | if (layer_list->capacity > 0) { |
| 814 | layer_list->capacity = 0; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 815 | loader_instance_heap_free(inst, layer_list->list); |
Jon Ashburn | b82c185 | 2015-08-11 14:49:54 -0600 | [diff] [blame] | 816 | } |
Jon Ashburn | e13ecc9 | 2015-08-03 17:19:30 -0600 | [diff] [blame] | 817 | } |
| 818 | |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 819 | static VkResult loader_add_instance_extensions( |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 820 | const struct loader_instance *inst, |
| 821 | const PFN_vkEnumerateInstanceExtensionProperties fp_get_props, |
| 822 | const char *lib_name, struct loader_extension_list *ext_list) { |
Courtney Goeltzenleuchter | 36eeb74 | 2015-12-21 16:41:47 -0700 | [diff] [blame] | 823 | uint32_t i, count = 0; |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 824 | VkExtensionProperties *ext_props; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 825 | VkResult res = VK_SUCCESS; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 826 | |
Courtney Goeltzenleuchter | 5c6cf47 | 2015-07-06 22:28:18 -0600 | [diff] [blame] | 827 | if (!fp_get_props) { |
Courtney Goeltzenleuchter | 35985f6 | 2015-09-14 17:22:16 -0600 | [diff] [blame] | 828 | /* No EnumerateInstanceExtensionProperties defined */ |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 829 | goto out; |
Courtney Goeltzenleuchter | 5c6cf47 | 2015-07-06 22:28:18 -0600 | [diff] [blame] | 830 | } |
| 831 | |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 832 | res = fp_get_props(NULL, &count, NULL); |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 833 | if (res != VK_SUCCESS) { |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 834 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 835 | "loader_add_instance_extensions: Error getting Instance " |
| 836 | "extension count from %s", |
| 837 | lib_name); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 838 | goto out; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 839 | } |
Jon Ashburn | 953bb3c | 2015-06-10 16:11:42 -0600 | [diff] [blame] | 840 | |
Courtney Goeltzenleuchter | 5c6cf47 | 2015-07-06 22:28:18 -0600 | [diff] [blame] | 841 | if (count == 0) { |
| 842 | /* No ExtensionProperties to report */ |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 843 | goto out; |
Courtney Goeltzenleuchter | 5c6cf47 | 2015-07-06 22:28:18 -0600 | [diff] [blame] | 844 | } |
| 845 | |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 846 | ext_props = loader_stack_alloc(count * sizeof(VkExtensionProperties)); |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 847 | |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 848 | res = fp_get_props(NULL, &count, ext_props); |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 849 | if (res != VK_SUCCESS) { |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 850 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 851 | "loader_add_instance_extensions: Error getting Instance " |
| 852 | "extensions from %s", |
| 853 | lib_name); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 854 | goto out; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 855 | } |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 856 | |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 857 | for (i = 0; i < count; i++) { |
Courtney Goeltzenleuchter | 5304373 | 2015-07-12 13:20:05 -0600 | [diff] [blame] | 858 | char spec_version[64]; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 859 | |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 860 | bool ext_unsupported = |
| 861 | wsi_unsupported_instance_extension(&ext_props[i]); |
Jon Ashburn | 6fa520f | 2016-03-25 12:49:35 -0600 | [diff] [blame] | 862 | if (!ext_unsupported) { |
Karl Schultz | e2ef9e6 | 2017-01-13 14:01:35 -0700 | [diff] [blame] | 863 | (void)snprintf(spec_version, sizeof(spec_version), "%d.%d.%d", |
| 864 | VK_MAJOR(ext_props[i].specVersion), |
| 865 | VK_MINOR(ext_props[i].specVersion), |
| 866 | VK_PATCH(ext_props[i].specVersion)); |
Jon Ashburn | 6fa520f | 2016-03-25 12:49:35 -0600 | [diff] [blame] | 867 | loader_log(inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, |
| 868 | "Instance Extension: %s (%s) version %s", |
| 869 | ext_props[i].extensionName, lib_name, spec_version); |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 870 | |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 871 | res = loader_add_to_ext_list(inst, ext_list, 1, &ext_props[i]); |
| 872 | if (res != VK_SUCCESS) { |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 873 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 874 | "loader_add_instance_extensions: Failed to add %s " |
| 875 | "to Instance extension list", |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 876 | lib_name); |
| 877 | goto out; |
| 878 | } |
Jon Ashburn | 6fa520f | 2016-03-25 12:49:35 -0600 | [diff] [blame] | 879 | } |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 880 | } |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 881 | |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 882 | out: |
| 883 | return res; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 884 | } |
| 885 | |
Jon Ashburn | 00eb6c0 | 2015-11-02 17:40:01 -0700 | [diff] [blame] | 886 | /* |
| 887 | * Initialize ext_list with the physical device extensions. |
| 888 | * The extension properties are passed as inputs in count and ext_props. |
| 889 | */ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 890 | static VkResult |
| 891 | loader_init_device_extensions(const struct loader_instance *inst, |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 892 | struct loader_physical_device_term *phys_dev_term, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 893 | uint32_t count, VkExtensionProperties *ext_props, |
| 894 | struct loader_extension_list *ext_list) { |
Jon Ashburn | 00eb6c0 | 2015-11-02 17:40:01 -0700 | [diff] [blame] | 895 | VkResult res; |
| 896 | uint32_t i; |
| 897 | |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 898 | res = loader_init_generic_list(inst, (struct loader_generic_list *)ext_list, |
| 899 | sizeof(VkExtensionProperties)); |
| 900 | if (VK_SUCCESS != res) { |
| 901 | return res; |
Jon Ashburn | 00eb6c0 | 2015-11-02 17:40:01 -0700 | [diff] [blame] | 902 | } |
| 903 | |
| 904 | for (i = 0; i < count; i++) { |
| 905 | char spec_version[64]; |
| 906 | |
Karl Schultz | e2ef9e6 | 2017-01-13 14:01:35 -0700 | [diff] [blame] | 907 | (void)snprintf(spec_version, sizeof(spec_version), "%d.%d.%d", |
| 908 | VK_MAJOR(ext_props[i].specVersion), |
| 909 | VK_MINOR(ext_props[i].specVersion), |
| 910 | VK_PATCH(ext_props[i].specVersion)); |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 911 | loader_log( |
| 912 | inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, |
| 913 | "Device Extension: %s (%s) version %s", ext_props[i].extensionName, |
| 914 | phys_dev_term->this_icd_term->scanned_icd->lib_name, spec_version); |
Jon Ashburn | 00eb6c0 | 2015-11-02 17:40:01 -0700 | [diff] [blame] | 915 | res = loader_add_to_ext_list(inst, ext_list, 1, &ext_props[i]); |
| 916 | if (res != VK_SUCCESS) |
| 917 | return res; |
| 918 | } |
| 919 | |
| 920 | return VK_SUCCESS; |
| 921 | } |
| 922 | |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 923 | VkResult loader_add_device_extensions(const struct loader_instance *inst, |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 924 | PFN_vkEnumerateDeviceExtensionProperties |
| 925 | fpEnumerateDeviceExtensionProperties, |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 926 | VkPhysicalDevice physical_device, |
| 927 | const char *lib_name, |
| 928 | struct loader_extension_list *ext_list) { |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 929 | uint32_t i, count; |
| 930 | VkResult res; |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 931 | VkExtensionProperties *ext_props; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 932 | |
Piers Daniell | 295fe40 | 2016-03-29 11:51:11 -0600 | [diff] [blame] | 933 | res = fpEnumerateDeviceExtensionProperties(physical_device, NULL, &count, |
| 934 | NULL); |
Jon Ashburn | 00eb6c0 | 2015-11-02 17:40:01 -0700 | [diff] [blame] | 935 | if (res == VK_SUCCESS && count > 0) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 936 | ext_props = loader_stack_alloc(count * sizeof(VkExtensionProperties)); |
Mark Young | 9a3ddd4 | 2016-10-21 16:25:47 -0600 | [diff] [blame] | 937 | if (!ext_props) { |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 938 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 939 | "loader_add_device_extensions: Failed to allocate space" |
| 940 | " for device extension properties."); |
Jon Ashburn | 00eb6c0 | 2015-11-02 17:40:01 -0700 | [diff] [blame] | 941 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Mark Young | 9a3ddd4 | 2016-10-21 16:25:47 -0600 | [diff] [blame] | 942 | } |
Piers Daniell | 295fe40 | 2016-03-29 11:51:11 -0600 | [diff] [blame] | 943 | res = fpEnumerateDeviceExtensionProperties(physical_device, NULL, |
| 944 | &count, ext_props); |
Mark Young | 9a3ddd4 | 2016-10-21 16:25:47 -0600 | [diff] [blame] | 945 | if (res != VK_SUCCESS) { |
Jon Ashburn | 24cd4be | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 946 | return res; |
Mark Young | 9a3ddd4 | 2016-10-21 16:25:47 -0600 | [diff] [blame] | 947 | } |
Jon Ashburn | 00eb6c0 | 2015-11-02 17:40:01 -0700 | [diff] [blame] | 948 | for (i = 0; i < count; i++) { |
| 949 | char spec_version[64]; |
| 950 | |
Karl Schultz | e2ef9e6 | 2017-01-13 14:01:35 -0700 | [diff] [blame] | 951 | (void)snprintf(spec_version, sizeof(spec_version), "%d.%d.%d", |
| 952 | VK_MAJOR(ext_props[i].specVersion), |
| 953 | VK_MINOR(ext_props[i].specVersion), |
| 954 | VK_PATCH(ext_props[i].specVersion)); |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 955 | loader_log(inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 956 | "Device Extension: %s (%s) version %s", |
| 957 | ext_props[i].extensionName, lib_name, spec_version); |
Jon Ashburn | 00eb6c0 | 2015-11-02 17:40:01 -0700 | [diff] [blame] | 958 | res = loader_add_to_ext_list(inst, ext_list, 1, &ext_props[i]); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 959 | if (res != VK_SUCCESS) { |
Jon Ashburn | 00eb6c0 | 2015-11-02 17:40:01 -0700 | [diff] [blame] | 960 | return res; |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 961 | } |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 962 | } |
Jon Ashburn | 00eb6c0 | 2015-11-02 17:40:01 -0700 | [diff] [blame] | 963 | } else { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 964 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 965 | "loader_add_device_extensions: Error getting physical " |
| 966 | "device extension info count from library %s", |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 967 | lib_name); |
Jon Ashburn | 00eb6c0 | 2015-11-02 17:40:01 -0700 | [diff] [blame] | 968 | return res; |
| 969 | } |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 970 | |
Jon Ashburn | 24cd4be | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 971 | return VK_SUCCESS; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 972 | } |
| 973 | |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 974 | VkResult loader_init_generic_list(const struct loader_instance *inst, |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 975 | struct loader_generic_list *list_info, |
| 976 | size_t element_size) { |
Mark Young | 84ba048 | 2016-09-02 11:45:00 -0600 | [diff] [blame] | 977 | size_t capacity = 32 * element_size; |
| 978 | list_info->count = 0; |
| 979 | list_info->capacity = 0; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 980 | list_info->list = loader_instance_heap_alloc( |
Mark Young | 84ba048 | 2016-09-02 11:45:00 -0600 | [diff] [blame] | 981 | inst, capacity, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Jon Ashburn | 6e6a216 | 2015-12-10 08:51:10 -0700 | [diff] [blame] | 982 | if (list_info->list == NULL) { |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 983 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 984 | "loader_init_generic_list: Failed to allocate space " |
| 985 | "for generic list"); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 986 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 987 | } |
Mark Young | 84ba048 | 2016-09-02 11:45:00 -0600 | [diff] [blame] | 988 | memset(list_info->list, 0, capacity); |
| 989 | list_info->capacity = capacity; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 990 | return VK_SUCCESS; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 991 | } |
| 992 | |
Jon Ashburn | 6e6a216 | 2015-12-10 08:51:10 -0700 | [diff] [blame] | 993 | void loader_destroy_generic_list(const struct loader_instance *inst, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 994 | struct loader_generic_list *list) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 995 | loader_instance_heap_free(inst, list->list); |
Jon Ashburn | 6e6a216 | 2015-12-10 08:51:10 -0700 | [diff] [blame] | 996 | list->count = 0; |
| 997 | list->capacity = 0; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 998 | } |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 999 | |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 1000 | /* |
| 1001 | * Append non-duplicate extension properties defined in props |
| 1002 | * to the given ext_list. |
Jon Ashburn | 24cd4be | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 1003 | * Return |
| 1004 | * Vk_SUCCESS on success |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 1005 | */ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1006 | VkResult loader_add_to_ext_list(const struct loader_instance *inst, |
| 1007 | struct loader_extension_list *ext_list, |
| 1008 | uint32_t prop_list_count, |
| 1009 | const VkExtensionProperties *props) { |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 1010 | uint32_t i; |
| 1011 | const VkExtensionProperties *cur_ext; |
| 1012 | |
| 1013 | if (ext_list->list == NULL || ext_list->capacity == 0) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1014 | VkResult res = loader_init_generic_list( |
| 1015 | inst, (struct loader_generic_list *)ext_list, |
| 1016 | sizeof(VkExtensionProperties)); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1017 | if (VK_SUCCESS != res) { |
| 1018 | return res; |
| 1019 | } |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 1020 | } |
| 1021 | |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 1022 | for (i = 0; i < prop_list_count; i++) { |
| 1023 | cur_ext = &props[i]; |
| 1024 | |
| 1025 | // look for duplicates |
| 1026 | if (has_vk_extension_property(cur_ext, ext_list)) { |
| 1027 | continue; |
| 1028 | } |
| 1029 | |
| 1030 | // add to list at end |
| 1031 | // check for enough capacity |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1032 | if (ext_list->count * sizeof(VkExtensionProperties) >= |
| 1033 | ext_list->capacity) { |
Jon Ashburn | e39a4f8 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 1034 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1035 | ext_list->list = loader_instance_heap_realloc( |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1036 | inst, ext_list->list, ext_list->capacity, |
| 1037 | ext_list->capacity * 2, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Jon Ashburn | 24cd4be | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 1038 | |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1039 | if (ext_list->list == NULL) { |
| 1040 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1041 | "loader_add_to_ext_list: Failed to reallocate " |
| 1042 | "space for extension list"); |
Jon Ashburn | 24cd4be | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 1043 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1044 | } |
Jon Ashburn | 24cd4be | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 1045 | |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 1046 | // double capacity |
| 1047 | ext_list->capacity *= 2; |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 1048 | } |
| 1049 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1050 | memcpy(&ext_list->list[ext_list->count], cur_ext, |
| 1051 | sizeof(VkExtensionProperties)); |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 1052 | ext_list->count++; |
| 1053 | } |
Jon Ashburn | 24cd4be | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 1054 | return VK_SUCCESS; |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 1055 | } |
| 1056 | |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1057 | /* |
| 1058 | * Append one extension property defined in props with entrypoints |
Jon Ashburn | b872696 | 2016-04-08 15:03:35 -0600 | [diff] [blame] | 1059 | * defined in entrys to the given ext_list. Do not append if a duplicate |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1060 | * Return |
| 1061 | * Vk_SUCCESS on success |
| 1062 | */ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1063 | VkResult |
| 1064 | loader_add_to_dev_ext_list(const struct loader_instance *inst, |
| 1065 | struct loader_device_extension_list *ext_list, |
| 1066 | const VkExtensionProperties *props, |
| 1067 | uint32_t entry_count, char **entrys) { |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1068 | uint32_t idx; |
| 1069 | if (ext_list->list == NULL || ext_list->capacity == 0) { |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1070 | VkResult res = loader_init_generic_list( |
| 1071 | inst, (struct loader_generic_list *)ext_list, |
| 1072 | sizeof(struct loader_dev_ext_props)); |
| 1073 | if (VK_SUCCESS != res) { |
| 1074 | return res; |
| 1075 | } |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1076 | } |
| 1077 | |
Jon Ashburn | b872696 | 2016-04-08 15:03:35 -0600 | [diff] [blame] | 1078 | // look for duplicates |
| 1079 | if (has_vk_dev_ext_property(props, ext_list)) { |
| 1080 | return VK_SUCCESS; |
| 1081 | } |
| 1082 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1083 | idx = ext_list->count; |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1084 | // add to list at end |
| 1085 | // check for enough capacity |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1086 | if (idx * sizeof(struct loader_dev_ext_props) >= ext_list->capacity) { |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1087 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1088 | ext_list->list = loader_instance_heap_realloc( |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1089 | inst, ext_list->list, ext_list->capacity, ext_list->capacity * 2, |
| 1090 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1091 | |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1092 | if (ext_list->list == NULL) { |
| 1093 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1094 | "loader_add_to_dev_ext_list: Failed to reallocate " |
| 1095 | "space for device extension list"); |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1096 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1097 | } |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1098 | |
| 1099 | // double capacity |
| 1100 | ext_list->capacity *= 2; |
| 1101 | } |
| 1102 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1103 | memcpy(&ext_list->list[idx].props, props, |
| 1104 | sizeof(struct loader_dev_ext_props)); |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1105 | ext_list->list[idx].entrypoint_count = entry_count; |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1106 | ext_list->list[idx].entrypoints = |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1107 | loader_instance_heap_alloc(inst, sizeof(char *) * entry_count, |
| 1108 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
| 1109 | if (ext_list->list[idx].entrypoints == NULL) { |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1110 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1111 | "loader_add_to_dev_ext_list: Failed to allocate space " |
| 1112 | "for device extension entrypoint list in list %d", |
| 1113 | idx); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1114 | ext_list->list[idx].entrypoint_count = 0; |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1115 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1116 | } |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1117 | for (uint32_t i = 0; i < entry_count; i++) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1118 | ext_list->list[idx].entrypoints[i] = loader_instance_heap_alloc( |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1119 | inst, strlen(entrys[i]) + 1, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1120 | if (ext_list->list[idx].entrypoints[i] == NULL) { |
| 1121 | for (uint32_t j = 0; j < i; j++) { |
| 1122 | loader_instance_heap_free(inst, |
| 1123 | ext_list->list[idx].entrypoints[j]); |
| 1124 | } |
| 1125 | loader_instance_heap_free(inst, ext_list->list[idx].entrypoints); |
| 1126 | ext_list->list[idx].entrypoint_count = 0; |
| 1127 | ext_list->list[idx].entrypoints = NULL; |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1128 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1129 | "loader_add_to_dev_ext_list: Failed to allocate space " |
| 1130 | "for device extension entrypoint %d name", |
| 1131 | i); |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1132 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1133 | } |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1134 | strcpy(ext_list->list[idx].entrypoints[i], entrys[i]); |
| 1135 | } |
| 1136 | ext_list->count++; |
| 1137 | |
| 1138 | return VK_SUCCESS; |
| 1139 | } |
| 1140 | |
Jon Ashburn | bd6c488 | 2015-07-02 12:59:25 -0600 | [diff] [blame] | 1141 | /** |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1142 | * Search the given search_list for any layers in the props list. |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1143 | * Add these to the output layer_list. Don't add duplicates to the output |
| 1144 | * layer_list. |
Jon Ashburn | bd6c488 | 2015-07-02 12:59:25 -0600 | [diff] [blame] | 1145 | */ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1146 | static VkResult |
| 1147 | loader_add_layer_names_to_list(const struct loader_instance *inst, |
| 1148 | struct loader_layer_list *output_list, |
| 1149 | uint32_t name_count, const char *const *names, |
| 1150 | const struct loader_layer_list *search_list) { |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1151 | struct loader_layer_properties *layer_prop; |
Courtney Goeltzenleuchter | 40caf0b | 2015-07-06 09:06:34 -0600 | [diff] [blame] | 1152 | VkResult err = VK_SUCCESS; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1153 | |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1154 | for (uint32_t i = 0; i < name_count; i++) { |
| 1155 | const char *search_target = names[i]; |
Jon Ashburn | e13ecc9 | 2015-08-03 17:19:30 -0600 | [diff] [blame] | 1156 | layer_prop = loader_get_layer_property(search_target, search_list); |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1157 | if (!layer_prop) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1158 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1159 | "loader_add_layer_names_to_list: Unable to find layer" |
| 1160 | " %s", |
| 1161 | search_target); |
Courtney Goeltzenleuchter | 55659b7 | 2015-09-14 18:01:17 -0600 | [diff] [blame] | 1162 | err = VK_ERROR_LAYER_NOT_PRESENT; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1163 | continue; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1164 | } |
| 1165 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1166 | err = loader_add_to_layer_list(inst, output_list, 1, layer_prop); |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1167 | } |
Courtney Goeltzenleuchter | 40caf0b | 2015-07-06 09:06:34 -0600 | [diff] [blame] | 1168 | |
| 1169 | return err; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1170 | } |
| 1171 | |
Courtney Goeltzenleuchter | 7f5aafc | 2015-07-05 11:28:29 -0600 | [diff] [blame] | 1172 | /* |
| 1173 | * Manage lists of VkLayerProperties |
| 1174 | */ |
Jon Ashburn | e39a4f8 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 1175 | static bool loader_init_layer_list(const struct loader_instance *inst, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1176 | struct loader_layer_list *list) { |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1177 | list->capacity = 32 * sizeof(struct loader_layer_properties); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1178 | list->list = loader_instance_heap_alloc( |
| 1179 | inst, list->capacity, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1180 | if (list->list == NULL) { |
| 1181 | return false; |
| 1182 | } |
| 1183 | memset(list->list, 0, list->capacity); |
| 1184 | list->count = 0; |
| 1185 | return true; |
| 1186 | } |
| 1187 | |
Jon Ashburn | e39a4f8 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 1188 | void loader_destroy_layer_list(const struct loader_instance *inst, |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1189 | struct loader_device *device, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1190 | struct loader_layer_list *layer_list) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1191 | if (device) { |
| 1192 | loader_device_heap_free(device, layer_list->list); |
| 1193 | } else { |
| 1194 | loader_instance_heap_free(inst, layer_list->list); |
| 1195 | } |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1196 | layer_list->count = 0; |
| 1197 | layer_list->capacity = 0; |
| 1198 | } |
| 1199 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1200 | /* |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1201 | * Search the given layer list for a list |
| 1202 | * matching the given VkLayerProperties |
| 1203 | */ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1204 | bool has_vk_layer_property(const VkLayerProperties *vk_layer_prop, |
| 1205 | const struct loader_layer_list *list) { |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1206 | for (uint32_t i = 0; i < list->count; i++) { |
| 1207 | if (strcmp(vk_layer_prop->layerName, list->list[i].info.layerName) == 0) |
| 1208 | return true; |
| 1209 | } |
| 1210 | return false; |
| 1211 | } |
| 1212 | |
| 1213 | /* |
| 1214 | * Search the given layer list for a layer |
| 1215 | * matching the given name |
| 1216 | */ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1217 | bool has_layer_name(const char *name, const struct loader_layer_list *list) { |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1218 | for (uint32_t i = 0; i < list->count; i++) { |
| 1219 | if (strcmp(name, list->list[i].info.layerName) == 0) |
| 1220 | return true; |
| 1221 | } |
| 1222 | return false; |
| 1223 | } |
| 1224 | |
| 1225 | /* |
| 1226 | * Append non-duplicate layer properties defined in prop_list |
| 1227 | * to the given layer_info list |
| 1228 | */ |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1229 | VkResult loader_add_to_layer_list(const struct loader_instance *inst, |
| 1230 | struct loader_layer_list *list, |
| 1231 | uint32_t prop_list_count, |
| 1232 | const struct loader_layer_properties *props) { |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1233 | uint32_t i; |
| 1234 | struct loader_layer_properties *layer; |
| 1235 | |
| 1236 | if (list->list == NULL || list->capacity == 0) { |
Jon Ashburn | e39a4f8 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 1237 | loader_init_layer_list(inst, list); |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1238 | } |
| 1239 | |
| 1240 | if (list->list == NULL) |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1241 | return VK_SUCCESS; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1242 | |
| 1243 | for (i = 0; i < prop_list_count; i++) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1244 | layer = (struct loader_layer_properties *)&props[i]; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1245 | |
| 1246 | // look for duplicates |
| 1247 | if (has_vk_layer_property(&layer->info, list)) { |
| 1248 | continue; |
| 1249 | } |
| 1250 | |
| 1251 | // add to list at end |
| 1252 | // check for enough capacity |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1253 | if (list->count * sizeof(struct loader_layer_properties) >= |
| 1254 | list->capacity) { |
Jon Ashburn | e39a4f8 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 1255 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1256 | list->list = loader_instance_heap_realloc( |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1257 | inst, list->list, list->capacity, list->capacity * 2, |
| 1258 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1259 | if (NULL == list->list) { |
| 1260 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1261 | "loader_add_to_layer_list: Realloc failed for " |
| 1262 | "when attempting to add new layer"); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1263 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 1264 | } |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1265 | // double capacity |
| 1266 | list->capacity *= 2; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1267 | } |
| 1268 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1269 | memcpy(&list->list[list->count], layer, |
| 1270 | sizeof(struct loader_layer_properties)); |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1271 | list->count++; |
| 1272 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1273 | |
| 1274 | return VK_SUCCESS; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1275 | } |
| 1276 | |
Jon Ashburn | bd332cc | 2015-07-07 10:27:45 -0600 | [diff] [blame] | 1277 | /** |
| 1278 | * Search the search_list for any layer with a name |
| 1279 | * that matches the given name and a type that matches the given type |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1280 | * Add all matching layers to the found_list |
Jon Ashburn | bd332cc | 2015-07-07 10:27:45 -0600 | [diff] [blame] | 1281 | * Do not add if found loader_layer_properties is already |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1282 | * on the found_list. |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1283 | */ |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 1284 | void loader_find_layer_name_add_list( |
| 1285 | const struct loader_instance *inst, const char *name, |
| 1286 | const enum layer_type type, const struct loader_layer_list *search_list, |
| 1287 | struct loader_layer_list *found_list) { |
Jon Ashburn | 56151d6 | 2015-10-05 09:03:21 -0600 | [diff] [blame] | 1288 | bool found = false; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1289 | for (uint32_t i = 0; i < search_list->count; i++) { |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1290 | struct loader_layer_properties *layer_prop = &search_list->list[i]; |
Jon Ashburn | bd332cc | 2015-07-07 10:27:45 -0600 | [diff] [blame] | 1291 | if (0 == strcmp(layer_prop->info.layerName, name) && |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1292 | (layer_prop->type & type)) { |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1293 | /* Found a layer with the same name, add to found_list */ |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1294 | if (VK_SUCCESS == |
| 1295 | loader_add_to_layer_list(inst, found_list, 1, layer_prop)) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1296 | found = true; |
| 1297 | } |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1298 | } |
| 1299 | } |
Jon Ashburn | 56151d6 | 2015-10-05 09:03:21 -0600 | [diff] [blame] | 1300 | if (!found) { |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 1301 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1302 | "loader_find_layer_name_add_list: Failed to find layer name " |
| 1303 | "%s to activate", |
| 1304 | name); |
Jon Ashburn | 56151d6 | 2015-10-05 09:03:21 -0600 | [diff] [blame] | 1305 | } |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1306 | } |
| 1307 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1308 | static VkExtensionProperties * |
| 1309 | get_extension_property(const char *name, |
| 1310 | const struct loader_extension_list *list) { |
Courtney Goeltzenleuchter | 746db73 | 2015-07-06 17:42:01 -0600 | [diff] [blame] | 1311 | for (uint32_t i = 0; i < list->count; i++) { |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1312 | if (strcmp(name, list->list[i].extensionName) == 0) |
Courtney Goeltzenleuchter | 746db73 | 2015-07-06 17:42:01 -0600 | [diff] [blame] | 1313 | return &list->list[i]; |
Jon Ashburn | fc2e38c | 2015-04-14 09:15:32 -0600 | [diff] [blame] | 1314 | } |
Courtney Goeltzenleuchter | 746db73 | 2015-07-06 17:42:01 -0600 | [diff] [blame] | 1315 | return NULL; |
Jon Ashburn | fc2e38c | 2015-04-14 09:15:32 -0600 | [diff] [blame] | 1316 | } |
| 1317 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1318 | static VkExtensionProperties * |
| 1319 | get_dev_extension_property(const char *name, |
| 1320 | const struct loader_device_extension_list *list) { |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1321 | for (uint32_t i = 0; i < list->count; i++) { |
| 1322 | if (strcmp(name, list->list[i].props.extensionName) == 0) |
| 1323 | return &list->list[i].props; |
| 1324 | } |
| 1325 | return NULL; |
| 1326 | } |
| 1327 | |
Courtney Goeltzenleuchter | b39ccd5 | 2016-01-15 14:15:00 -0700 | [diff] [blame] | 1328 | /* |
Courtney Goeltzenleuchter | f538ef7 | 2015-12-02 14:00:19 -0700 | [diff] [blame] | 1329 | * For Instance extensions implemented within the loader (i.e. DEBUG_REPORT |
Jon Ashburn | bd6c488 | 2015-07-02 12:59:25 -0600 | [diff] [blame] | 1330 | * the extension must provide two entry points for the loader to use: |
| 1331 | * - "trampoline" entry point - this is the address returned by GetProcAddr |
| 1332 | * and will always do what's necessary to support a global call. |
| 1333 | * - "terminator" function - this function will be put at the end of the |
Jon Ashburn | 232e3af | 2015-11-30 17:21:25 -0700 | [diff] [blame] | 1334 | * instance chain and will contain the necessary logic to call / process |
Jon Ashburn | bd6c488 | 2015-07-02 12:59:25 -0600 | [diff] [blame] | 1335 | * the extension for the appropriate ICDs that are available. |
| 1336 | * There is no generic mechanism for including these functions, the references |
| 1337 | * must be placed into the appropriate loader entry points. |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1338 | * GetInstanceProcAddr: call extension GetInstanceProcAddr to check for |
| 1339 | * GetProcAddr requests |
| 1340 | * loader_coalesce_extensions(void) - add extension records to the list of |
| 1341 | * global |
Jon Ashburn | bd6c488 | 2015-07-02 12:59:25 -0600 | [diff] [blame] | 1342 | * extension available to the app. |
| 1343 | * instance_disp - add function pointer for terminator function to this array. |
| 1344 | * The extension itself should be in a separate file that will be |
| 1345 | * linked directly with the loader. |
| 1346 | */ |
Jon Ashburn | 9a4c6aa | 2015-08-14 11:57:54 -0600 | [diff] [blame] | 1347 | |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1348 | VkResult loader_get_icd_loader_instance_extensions( |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1349 | const struct loader_instance *inst, |
| 1350 | struct loader_icd_tramp_list *icd_tramp_list, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1351 | struct loader_extension_list *inst_exts) { |
Jon Ashburn | 5c6a46f | 2015-08-14 14:49:22 -0600 | [diff] [blame] | 1352 | struct loader_extension_list icd_exts; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1353 | VkResult res = VK_SUCCESS; |
| 1354 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1355 | loader_log(inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, |
| 1356 | "Build ICD instance extension list"); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1357 | |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1358 | // traverse scanned icd list adding non-duplicate extensions to the list |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1359 | for (uint32_t i = 0; i < icd_tramp_list->count; i++) { |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1360 | res = loader_init_generic_list(inst, |
| 1361 | (struct loader_generic_list *)&icd_exts, |
| 1362 | sizeof(VkExtensionProperties)); |
| 1363 | if (VK_SUCCESS != res) { |
| 1364 | goto out; |
| 1365 | } |
| 1366 | res = loader_add_instance_extensions( |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1367 | inst, icd_tramp_list->scanned_list[i] |
| 1368 | .EnumerateInstanceExtensionProperties, |
| 1369 | icd_tramp_list->scanned_list[i].lib_name, &icd_exts); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1370 | if (VK_SUCCESS == res) { |
Lenny Komow | 4053b81 | 2016-12-29 16:27:28 -0700 | [diff] [blame] | 1371 | // Remove any extensions not recognized by the loader |
| 1372 | for (int32_t j = 0; j < (int32_t)icd_exts.count; j++) { |
| 1373 | |
| 1374 | // See if the extension is in the list of supported extensions |
| 1375 | bool found = false; |
| 1376 | for (uint32_t k = 0; LOADER_INSTANCE_EXTENSIONS[k] != NULL; |
| 1377 | k++) { |
| 1378 | if (strcmp(icd_exts.list[j].extensionName, |
| 1379 | LOADER_INSTANCE_EXTENSIONS[k]) == 0) { |
| 1380 | found = true; |
| 1381 | break; |
| 1382 | } |
| 1383 | } |
| 1384 | |
| 1385 | // If it isn't in the list, remove it |
| 1386 | if (!found) { |
| 1387 | for (uint32_t k = j + 1; k < icd_exts.count; k++) { |
| 1388 | icd_exts.list[k - 1] = icd_exts.list[k]; |
| 1389 | } |
| 1390 | --icd_exts.count; |
| 1391 | --j; |
| 1392 | } |
| 1393 | } |
| 1394 | |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1395 | res = loader_add_to_ext_list(inst, inst_exts, icd_exts.count, |
| 1396 | icd_exts.list); |
| 1397 | } |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1398 | loader_destroy_generic_list(inst, |
| 1399 | (struct loader_generic_list *)&icd_exts); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1400 | if (VK_SUCCESS != res) { |
| 1401 | goto out; |
| 1402 | } |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1403 | }; |
| 1404 | |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 1405 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1406 | // Traverse loader's extensions, adding non-duplicate extensions to the list |
Jon Ashburn | e39a4f8 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 1407 | debug_report_add_instance_extensions(inst, inst_exts); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1408 | |
| 1409 | out: |
| 1410 | return res; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1411 | } |
| 1412 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1413 | struct loader_icd_term * |
| 1414 | loader_get_icd_and_device(const VkDevice device, |
| 1415 | struct loader_device **found_dev, |
| 1416 | uint32_t *icd_index) { |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1417 | *found_dev = NULL; |
Mark Young | 16573c7 | 2016-06-28 10:52:43 -0600 | [diff] [blame] | 1418 | uint32_t index = 0; |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1419 | for (struct loader_instance *inst = loader.instances; inst; |
| 1420 | inst = inst->next) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1421 | for (struct loader_icd_term *icd_term = inst->icd_terms; icd_term; |
| 1422 | icd_term = icd_term->next) { |
| 1423 | for (struct loader_device *dev = icd_term->logical_device_list; dev; |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1424 | dev = dev->next) |
Mark Young | 65cb366 | 2016-11-07 13:27:02 -0700 | [diff] [blame] | 1425 | // Value comparison of device prevents object wrapping by layers |
| 1426 | if (loader_get_dispatch(dev->icd_device) == |
| 1427 | loader_get_dispatch(device) || |
| 1428 | loader_get_dispatch(dev->chain_device) == |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1429 | loader_get_dispatch(device)) { |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1430 | *found_dev = dev; |
Mark Young | 16573c7 | 2016-06-28 10:52:43 -0600 | [diff] [blame] | 1431 | if (NULL != icd_index) { |
| 1432 | *icd_index = index; |
| 1433 | } |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1434 | return icd_term; |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1435 | } |
Mark Young | 16573c7 | 2016-06-28 10:52:43 -0600 | [diff] [blame] | 1436 | index++; |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1437 | } |
| 1438 | } |
| 1439 | return NULL; |
| 1440 | } |
| 1441 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1442 | void loader_destroy_logical_device(const struct loader_instance *inst, |
| 1443 | struct loader_device *dev, |
| 1444 | const VkAllocationCallbacks *pAllocator) { |
| 1445 | if (pAllocator) { |
| 1446 | dev->alloc_callbacks = *pAllocator; |
| 1447 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1448 | if (NULL != dev->activated_layer_list.list) { |
| 1449 | loader_deactivate_layers(inst, dev, &dev->activated_layer_list); |
| 1450 | } |
| 1451 | loader_device_heap_free(dev, dev); |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1452 | } |
| 1453 | |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 1454 | struct loader_device * |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1455 | loader_create_logical_device(const struct loader_instance *inst, |
| 1456 | const VkAllocationCallbacks *pAllocator) { |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1457 | struct loader_device *new_dev; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1458 | #if (DEBUG_DISABLE_APP_ALLOCATORS == 1) |
| 1459 | { |
| 1460 | #else |
| 1461 | if (pAllocator) { |
| 1462 | new_dev = (struct loader_device *)pAllocator->pfnAllocation( |
| 1463 | pAllocator->pUserData, sizeof(struct loader_device), sizeof(int *), |
| 1464 | VK_SYSTEM_ALLOCATION_SCOPE_DEVICE); |
| 1465 | } else { |
| 1466 | #endif |
| 1467 | new_dev = (struct loader_device *)malloc(sizeof(struct loader_device)); |
| 1468 | } |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1469 | |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1470 | if (!new_dev) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1471 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1472 | "loader_create_logical_device: Failed to alloc struct " |
| 1473 | "loader_device"); |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1474 | return NULL; |
| 1475 | } |
| 1476 | |
| 1477 | memset(new_dev, 0, sizeof(struct loader_device)); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1478 | if (pAllocator) { |
| 1479 | new_dev->alloc_callbacks = *pAllocator; |
| 1480 | } |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1481 | |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1482 | return new_dev; |
| 1483 | } |
| 1484 | |
Piers Daniell | 295fe40 | 2016-03-29 11:51:11 -0600 | [diff] [blame] | 1485 | void loader_add_logical_device(const struct loader_instance *inst, |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1486 | struct loader_icd_term *icd_term, |
Piers Daniell | 295fe40 | 2016-03-29 11:51:11 -0600 | [diff] [blame] | 1487 | struct loader_device *dev) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1488 | dev->next = icd_term->logical_device_list; |
| 1489 | icd_term->logical_device_list = dev; |
Piers Daniell | 295fe40 | 2016-03-29 11:51:11 -0600 | [diff] [blame] | 1490 | } |
| 1491 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1492 | void loader_remove_logical_device(const struct loader_instance *inst, |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1493 | struct loader_icd_term *icd_term, |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1494 | struct loader_device *found_dev, |
| 1495 | const VkAllocationCallbacks *pAllocator) { |
Jon Ashburn | 781a7ae | 2015-11-19 15:43:26 -0700 | [diff] [blame] | 1496 | struct loader_device *dev, *prev_dev; |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1497 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1498 | if (!icd_term || !found_dev) |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1499 | return; |
| 1500 | |
| 1501 | prev_dev = NULL; |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1502 | dev = icd_term->logical_device_list; |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1503 | while (dev && dev != found_dev) { |
| 1504 | prev_dev = dev; |
| 1505 | dev = dev->next; |
| 1506 | } |
| 1507 | |
| 1508 | if (prev_dev) |
| 1509 | prev_dev->next = found_dev->next; |
| 1510 | else |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1511 | icd_term->logical_device_list = found_dev->next; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1512 | loader_destroy_logical_device(inst, found_dev, pAllocator); |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1513 | } |
| 1514 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1515 | static void loader_icd_destroy(struct loader_instance *ptr_inst, |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1516 | struct loader_icd_term *icd_term, |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1517 | const VkAllocationCallbacks *pAllocator) { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1518 | ptr_inst->total_icd_count--; |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1519 | for (struct loader_device *dev = icd_term->logical_device_list; dev;) { |
Courtney Goeltzenleuchter | 1f157ac | 2015-06-14 19:57:15 -0600 | [diff] [blame] | 1520 | struct loader_device *next_dev = dev->next; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1521 | loader_destroy_logical_device(ptr_inst, dev, pAllocator); |
Courtney Goeltzenleuchter | 1f157ac | 2015-06-14 19:57:15 -0600 | [diff] [blame] | 1522 | dev = next_dev; |
| 1523 | } |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1524 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1525 | loader_instance_heap_free(ptr_inst, icd_term); |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1526 | } |
| 1527 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1528 | static struct loader_icd_term * |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1529 | loader_icd_create(const struct loader_instance *inst) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1530 | struct loader_icd_term *icd_term; |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1531 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1532 | icd_term = loader_instance_heap_alloc(inst, sizeof(struct loader_icd_term), |
| 1533 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
| 1534 | if (!icd_term) { |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1535 | return NULL; |
Mark Young | db13a2a | 2016-09-06 13:53:03 -0600 | [diff] [blame] | 1536 | } |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1537 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1538 | memset(icd_term, 0, sizeof(struct loader_icd_term)); |
Courtney Goeltzenleuchter | 55001bb | 2014-10-28 10:29:27 -0600 | [diff] [blame] | 1539 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1540 | return icd_term; |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1541 | } |
| 1542 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1543 | static struct loader_icd_term * |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1544 | loader_icd_add(struct loader_instance *ptr_inst, |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1545 | const struct loader_scanned_icd *scanned_icd) { |
| 1546 | struct loader_icd_term *icd_term; |
Chia-I Wu | 13a61a5 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 1547 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1548 | icd_term = loader_icd_create(ptr_inst); |
| 1549 | if (!icd_term) { |
Chia-I Wu | 13a61a5 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 1550 | return NULL; |
Mark Young | db13a2a | 2016-09-06 13:53:03 -0600 | [diff] [blame] | 1551 | } |
Chia-I Wu | 13a61a5 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 1552 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1553 | icd_term->scanned_icd = scanned_icd; |
| 1554 | icd_term->this_instance = ptr_inst; |
Jon Ashburn | 3d00233 | 2015-08-20 16:35:30 -0600 | [diff] [blame] | 1555 | |
Chia-I Wu | 13a61a5 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 1556 | /* prepend to the list */ |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1557 | icd_term->next = ptr_inst->icd_terms; |
| 1558 | ptr_inst->icd_terms = icd_term; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1559 | ptr_inst->total_icd_count++; |
Chia-I Wu | 13a61a5 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 1560 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1561 | return icd_term; |
Chia-I Wu | 13a61a5 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 1562 | } |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1563 | |
Jon Ashburn | 17b4c86 | 2016-04-25 11:09:37 -0600 | [diff] [blame] | 1564 | /** |
| 1565 | * Determine the ICD interface version to use. |
| 1566 | * @param icd |
| 1567 | * @param pVersion Output parameter indicating which version to use or 0 if |
| 1568 | * the negotiation API is not supported by the ICD |
| 1569 | * @return bool indicating true if the selected interface version is supported |
| 1570 | * by the loader, false indicates the version is not supported |
| 1571 | * version 0 doesn't support vk_icdGetInstanceProcAddr nor |
| 1572 | * vk_icdNegotiateLoaderICDInterfaceVersion |
| 1573 | * version 1 supports vk_icdGetInstanceProcAddr |
| 1574 | * version 2 supports vk_icdNegotiateLoaderICDInterfaceVersion |
| 1575 | */ |
| 1576 | bool loader_get_icd_interface_version( |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1577 | PFN_vkNegotiateLoaderICDInterfaceVersion fp_negotiate_icd_version, |
| 1578 | uint32_t *pVersion) { |
Jon Ashburn | 17b4c86 | 2016-04-25 11:09:37 -0600 | [diff] [blame] | 1579 | |
| 1580 | if (fp_negotiate_icd_version == NULL) { |
| 1581 | // ICD does not support the negotiation API, it supports version 0 or 1 |
| 1582 | // calling code must determine if it is version 0 or 1 |
| 1583 | *pVersion = 0; |
| 1584 | } else { |
| 1585 | // ICD supports the negotiation API, so call it with the loader's |
| 1586 | // latest version supported |
| 1587 | *pVersion = CURRENT_LOADER_ICD_INTERFACE_VERSION; |
| 1588 | VkResult result = fp_negotiate_icd_version(pVersion); |
| 1589 | |
| 1590 | if (result == VK_ERROR_INCOMPATIBLE_DRIVER) { |
| 1591 | // ICD no longer supports the loader's latest interface version so |
| 1592 | // fail loading the ICD |
| 1593 | return false; |
| 1594 | } |
| 1595 | } |
| 1596 | |
| 1597 | #if MIN_SUPPORTED_LOADER_ICD_INTERFACE_VERSION > 0 |
| 1598 | if (*pVersion < MIN_SUPPORTED_LOADER_ICD_INTERFACE_VERSION) { |
| 1599 | // Loader no longer supports the ICD's latest interface version so fail |
| 1600 | // loading the ICD |
| 1601 | return false; |
| 1602 | } |
| 1603 | #endif |
| 1604 | return true; |
| 1605 | } |
Chia-I Wu | 13a61a5 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 1606 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1607 | void loader_scanned_icd_clear(const struct loader_instance *inst, |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1608 | struct loader_icd_tramp_list *icd_tramp_list) { |
| 1609 | if (icd_tramp_list->capacity == 0) |
Jon Ashburn | 8810c5f | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 1610 | return; |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1611 | for (uint32_t i = 0; i < icd_tramp_list->count; i++) { |
| 1612 | loader_platform_close_library(icd_tramp_list->scanned_list[i].handle); |
| 1613 | loader_instance_heap_free(inst, |
| 1614 | icd_tramp_list->scanned_list[i].lib_name); |
Jon Ashburn | 8810c5f | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 1615 | } |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1616 | loader_instance_heap_free(inst, icd_tramp_list->scanned_list); |
| 1617 | icd_tramp_list->capacity = 0; |
| 1618 | icd_tramp_list->count = 0; |
| 1619 | icd_tramp_list->scanned_list = NULL; |
Jon Ashburn | 8810c5f | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 1620 | } |
| 1621 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1622 | static VkResult |
| 1623 | loader_scanned_icd_init(const struct loader_instance *inst, |
| 1624 | struct loader_icd_tramp_list *icd_tramp_list) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1625 | VkResult err = VK_SUCCESS; |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1626 | loader_scanned_icd_clear(inst, icd_tramp_list); |
| 1627 | icd_tramp_list->capacity = 8 * sizeof(struct loader_scanned_icd); |
| 1628 | icd_tramp_list->scanned_list = loader_instance_heap_alloc( |
| 1629 | inst, icd_tramp_list->capacity, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
| 1630 | if (NULL == icd_tramp_list->scanned_list) { |
| 1631 | loader_log( |
| 1632 | inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1633 | "loader_scanned_icd_init: Realloc failed for layer list when " |
| 1634 | "attempting to add new layer"); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1635 | err = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 1636 | } |
| 1637 | return err; |
Jon Ashburn | 8810c5f | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 1638 | } |
| 1639 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1640 | static VkResult |
| 1641 | loader_scanned_icd_add(const struct loader_instance *inst, |
| 1642 | struct loader_icd_tramp_list *icd_tramp_list, |
| 1643 | const char *filename, uint32_t api_version) { |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1644 | loader_platform_dl_handle handle; |
Tony Barbour | 1d2cd3f | 2015-07-03 10:33:54 -0600 | [diff] [blame] | 1645 | PFN_vkCreateInstance fp_create_inst; |
Jon Ashburn | fd4d09d | 2016-01-07 09:44:27 -0700 | [diff] [blame] | 1646 | PFN_vkEnumerateInstanceExtensionProperties fp_get_inst_ext_props; |
Jon Ashburn | c624c88 | 2015-07-16 10:17:29 -0600 | [diff] [blame] | 1647 | PFN_vkGetInstanceProcAddr fp_get_proc_addr; |
Jon Ashburn | 17b4c86 | 2016-04-25 11:09:37 -0600 | [diff] [blame] | 1648 | PFN_vkNegotiateLoaderICDInterfaceVersion fp_negotiate_icd_version; |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1649 | struct loader_scanned_icd *new_scanned_icd; |
Jon Ashburn | 17b4c86 | 2016-04-25 11:09:37 -0600 | [diff] [blame] | 1650 | uint32_t interface_vers; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1651 | VkResult res = VK_SUCCESS; |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 1652 | |
Jon Ashburn | 4dc1d8a | 2016-04-20 13:21:17 -0600 | [diff] [blame] | 1653 | /* TODO implement smarter opening/closing of libraries. For now this |
| 1654 | * function leaves libraries open and the scanned_icd_clear closes them */ |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1655 | handle = loader_platform_open_library(filename); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1656 | if (NULL == handle) { |
| 1657 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1658 | loader_platform_open_library_error(filename)); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1659 | goto out; |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 1660 | } |
| 1661 | |
Jon Ashburn | 17b4c86 | 2016-04-25 11:09:37 -0600 | [diff] [blame] | 1662 | // Get and settle on an ICD interface version |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1663 | fp_negotiate_icd_version = loader_platform_get_proc_address( |
| 1664 | handle, "vk_icdNegotiateLoaderICDInterfaceVersion"); |
Jon Ashburn | 17b4c86 | 2016-04-25 11:09:37 -0600 | [diff] [blame] | 1665 | |
| 1666 | if (!loader_get_icd_interface_version(fp_negotiate_icd_version, |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1667 | &interface_vers)) { |
| 1668 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1669 | "loader_scanned_icd_add: ICD %s doesn't support interface" |
| 1670 | " version compatible with loader, skip this ICD.", |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1671 | filename); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1672 | goto out; |
Jon Ashburn | 17b4c86 | 2016-04-25 11:09:37 -0600 | [diff] [blame] | 1673 | } |
| 1674 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1675 | fp_get_proc_addr = |
| 1676 | loader_platform_get_proc_address(handle, "vk_icdGetInstanceProcAddr"); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1677 | if (NULL == fp_get_proc_addr) { |
Jon Ashburn | 17b4c86 | 2016-04-25 11:09:37 -0600 | [diff] [blame] | 1678 | assert(interface_vers == 0); |
| 1679 | // Use deprecated interface from version 0 |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1680 | fp_get_proc_addr = |
| 1681 | loader_platform_get_proc_address(handle, "vkGetInstanceProcAddr"); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1682 | if (NULL == fp_get_proc_addr) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1683 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1684 | "loader_scanned_icd_add: Attempt to retreive either " |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 1685 | "\'vkGetInstanceProcAddr\' or " |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1686 | "\'vk_icdGetInstanceProcAddr\' from ICD %s failed.", |
| 1687 | filename); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1688 | goto out; |
Jon Ashburn | fd4d09d | 2016-01-07 09:44:27 -0700 | [diff] [blame] | 1689 | } else { |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 1690 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1691 | "loader_scanned_icd_add: Using deprecated ICD " |
| 1692 | "interface of \'vkGetInstanceProcAddr\' instead of " |
| 1693 | "\'vk_icdGetInstanceProcAddr\' for ICD %s", |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1694 | filename); |
Jon Ashburn | fd4d09d | 2016-01-07 09:44:27 -0700 | [diff] [blame] | 1695 | } |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1696 | fp_create_inst = |
| 1697 | loader_platform_get_proc_address(handle, "vkCreateInstance"); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1698 | if (NULL == fp_create_inst) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1699 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1700 | "loader_scanned_icd_add: Failed querying " |
| 1701 | "\'vkCreateInstance\' via dlsym/loadlibrary for " |
| 1702 | "ICD %s", |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1703 | filename); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1704 | goto out; |
Jon Ashburn | 69a5f7a | 2016-01-11 14:41:35 -0700 | [diff] [blame] | 1705 | } |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1706 | fp_get_inst_ext_props = loader_platform_get_proc_address( |
| 1707 | handle, "vkEnumerateInstanceExtensionProperties"); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1708 | if (NULL == fp_get_inst_ext_props) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1709 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1710 | "loader_scanned_icd_add: Could not get \'vkEnumerate" |
| 1711 | "InstanceExtensionProperties\' via dlsym/loadlibrary " |
| 1712 | "for ICD %s", |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1713 | filename); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1714 | goto out; |
Jon Ashburn | 69a5f7a | 2016-01-11 14:41:35 -0700 | [diff] [blame] | 1715 | } |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1716 | } else { |
Jon Ashburn | 17b4c86 | 2016-04-25 11:09:37 -0600 | [diff] [blame] | 1717 | // Use newer interface version 1 or later |
| 1718 | if (interface_vers == 0) |
| 1719 | interface_vers = 1; |
| 1720 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1721 | fp_create_inst = |
| 1722 | (PFN_vkCreateInstance)fp_get_proc_addr(NULL, "vkCreateInstance"); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1723 | if (NULL == fp_create_inst) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1724 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1725 | "loader_scanned_icd_add: Could not get " |
| 1726 | "\'vkCreateInstance\' via \'vk_icdGetInstanceProcAddr\'" |
| 1727 | " for ICD %s", |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1728 | filename); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1729 | goto out; |
Jon Ashburn | 69a5f7a | 2016-01-11 14:41:35 -0700 | [diff] [blame] | 1730 | } |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1731 | fp_get_inst_ext_props = |
| 1732 | (PFN_vkEnumerateInstanceExtensionProperties)fp_get_proc_addr( |
| 1733 | NULL, "vkEnumerateInstanceExtensionProperties"); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1734 | if (NULL == fp_get_inst_ext_props) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1735 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1736 | "loader_scanned_icd_add: Could not get \'vkEnumerate" |
| 1737 | "InstanceExtensionProperties\' via " |
| 1738 | "\'vk_icdGetInstanceProcAddr\' for ICD %s", |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1739 | filename); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1740 | goto out; |
Jon Ashburn | 69a5f7a | 2016-01-11 14:41:35 -0700 | [diff] [blame] | 1741 | } |
Jon Ashburn | fd4d09d | 2016-01-07 09:44:27 -0700 | [diff] [blame] | 1742 | } |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 1743 | |
Jon Ashburn | 8810c5f | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 1744 | // check for enough capacity |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1745 | if ((icd_tramp_list->count * sizeof(struct loader_scanned_icd)) >= |
| 1746 | icd_tramp_list->capacity) { |
Jon Ashburn | e39a4f8 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 1747 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1748 | icd_tramp_list->scanned_list = loader_instance_heap_realloc( |
| 1749 | inst, icd_tramp_list->scanned_list, icd_tramp_list->capacity, |
| 1750 | icd_tramp_list->capacity * 2, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
| 1751 | if (NULL == icd_tramp_list->scanned_list) { |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1752 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1753 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1754 | "loader_scanned_icd_add: Realloc failed on icd library" |
| 1755 | " list for ICD %s", |
| 1756 | filename); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1757 | goto out; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1758 | } |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1759 | // double capacity |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1760 | icd_tramp_list->capacity *= 2; |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 1761 | } |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1762 | new_scanned_icd = &(icd_tramp_list->scanned_list[icd_tramp_list->count]); |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 1763 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1764 | new_scanned_icd->handle = handle; |
| 1765 | new_scanned_icd->api_version = api_version; |
| 1766 | new_scanned_icd->GetInstanceProcAddr = fp_get_proc_addr; |
| 1767 | new_scanned_icd->EnumerateInstanceExtensionProperties = |
| 1768 | fp_get_inst_ext_props; |
| 1769 | new_scanned_icd->CreateInstance = fp_create_inst; |
| 1770 | new_scanned_icd->interface_version = interface_vers; |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 1771 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1772 | new_scanned_icd->lib_name = (char *)loader_instance_heap_alloc( |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1773 | inst, strlen(filename) + 1, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1774 | if (NULL == new_scanned_icd->lib_name) { |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1775 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1776 | "loader_scanned_icd_add: Out of memory can't add ICD %s", |
| 1777 | filename); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1778 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1779 | goto out; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1780 | } |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1781 | strcpy(new_scanned_icd->lib_name, filename); |
| 1782 | icd_tramp_list->count++; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1783 | |
| 1784 | out: |
| 1785 | |
| 1786 | return res; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1787 | } |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1788 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1789 | static bool loader_icd_init_entrys(struct loader_icd_term *icd_term, |
| 1790 | VkInstance inst, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1791 | const PFN_vkGetInstanceProcAddr fp_gipa) { |
| 1792 | /* initialize entrypoint function pointers */ |
Jon Ashburn | 3da71f2 | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 1793 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1794 | #define LOOKUP_GIPA(func, required) \ |
| 1795 | do { \ |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1796 | icd_term->func = (PFN_vk##func)fp_gipa(inst, "vk" #func); \ |
| 1797 | if (!icd_term->func && required) { \ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1798 | loader_log((struct loader_instance *)inst, \ |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 1799 | VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, \ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1800 | loader_platform_get_proc_address_error("vk" #func)); \ |
| 1801 | return false; \ |
| 1802 | } \ |
Jon Ashburn | 3da71f2 | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 1803 | } while (0) |
| 1804 | |
Jon Ashburn | c624c88 | 2015-07-16 10:17:29 -0600 | [diff] [blame] | 1805 | LOOKUP_GIPA(GetDeviceProcAddr, true); |
| 1806 | LOOKUP_GIPA(DestroyInstance, true); |
| 1807 | LOOKUP_GIPA(EnumeratePhysicalDevices, true); |
| 1808 | LOOKUP_GIPA(GetPhysicalDeviceFeatures, true); |
| 1809 | LOOKUP_GIPA(GetPhysicalDeviceFormatProperties, true); |
Jon Ashburn | 754864f | 2015-07-23 18:49:07 -0600 | [diff] [blame] | 1810 | LOOKUP_GIPA(GetPhysicalDeviceImageFormatProperties, true); |
Jon Ashburn | c624c88 | 2015-07-16 10:17:29 -0600 | [diff] [blame] | 1811 | LOOKUP_GIPA(CreateDevice, true); |
| 1812 | LOOKUP_GIPA(GetPhysicalDeviceProperties, true); |
| 1813 | LOOKUP_GIPA(GetPhysicalDeviceMemoryProperties, true); |
Cody Northrop | d080288 | 2015-08-03 17:04:53 -0600 | [diff] [blame] | 1814 | LOOKUP_GIPA(GetPhysicalDeviceQueueFamilyProperties, true); |
Courtney Goeltzenleuchter | 35985f6 | 2015-09-14 17:22:16 -0600 | [diff] [blame] | 1815 | LOOKUP_GIPA(EnumerateDeviceExtensionProperties, true); |
Jon Ashburn | c624c88 | 2015-07-16 10:17:29 -0600 | [diff] [blame] | 1816 | LOOKUP_GIPA(GetPhysicalDeviceSparseImageFormatProperties, true); |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1817 | LOOKUP_GIPA(CreateDebugReportCallbackEXT, false); |
| 1818 | LOOKUP_GIPA(DestroyDebugReportCallbackEXT, false); |
Mark Young | 65cb366 | 2016-11-07 13:27:02 -0700 | [diff] [blame] | 1819 | LOOKUP_GIPA(DebugMarkerSetObjectTagEXT, false); |
| 1820 | LOOKUP_GIPA(DebugMarkerSetObjectNameEXT, false); |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 1821 | LOOKUP_GIPA(GetPhysicalDeviceSurfaceSupportKHR, false); |
Ian Elliott | 486c550 | 2015-11-19 16:05:09 -0700 | [diff] [blame] | 1822 | LOOKUP_GIPA(GetPhysicalDeviceSurfaceCapabilitiesKHR, false); |
| 1823 | LOOKUP_GIPA(GetPhysicalDeviceSurfaceFormatsKHR, false); |
| 1824 | LOOKUP_GIPA(GetPhysicalDeviceSurfacePresentModesKHR, false); |
Petros Bantolas | 25d27fe | 2016-04-14 12:50:42 +0100 | [diff] [blame] | 1825 | LOOKUP_GIPA(GetPhysicalDeviceDisplayPropertiesKHR, false); |
| 1826 | LOOKUP_GIPA(GetDisplayModePropertiesKHR, false); |
| 1827 | LOOKUP_GIPA(CreateDisplayPlaneSurfaceKHR, false); |
| 1828 | LOOKUP_GIPA(GetPhysicalDeviceDisplayPlanePropertiesKHR, false); |
| 1829 | LOOKUP_GIPA(GetDisplayPlaneSupportedDisplaysKHR, false); |
| 1830 | LOOKUP_GIPA(CreateDisplayModeKHR, false); |
| 1831 | LOOKUP_GIPA(GetDisplayPlaneCapabilitiesKHR, false); |
| 1832 | LOOKUP_GIPA(DestroySurfaceKHR, false); |
Mark Young | 16573c7 | 2016-06-28 10:52:43 -0600 | [diff] [blame] | 1833 | LOOKUP_GIPA(CreateSwapchainKHR, false); |
Ian Elliott | 919fa30 | 2015-11-24 15:39:10 -0700 | [diff] [blame] | 1834 | #ifdef VK_USE_PLATFORM_WIN32_KHR |
Mark Young | 16573c7 | 2016-06-28 10:52:43 -0600 | [diff] [blame] | 1835 | LOOKUP_GIPA(CreateWin32SurfaceKHR, false); |
Ian Elliott | 919fa30 | 2015-11-24 15:39:10 -0700 | [diff] [blame] | 1836 | LOOKUP_GIPA(GetPhysicalDeviceWin32PresentationSupportKHR, false); |
| 1837 | #endif |
| 1838 | #ifdef VK_USE_PLATFORM_XCB_KHR |
Mark Young | 16573c7 | 2016-06-28 10:52:43 -0600 | [diff] [blame] | 1839 | LOOKUP_GIPA(CreateXcbSurfaceKHR, false); |
Ian Elliott | 919fa30 | 2015-11-24 15:39:10 -0700 | [diff] [blame] | 1840 | LOOKUP_GIPA(GetPhysicalDeviceXcbPresentationSupportKHR, false); |
| 1841 | #endif |
Karl Schultz | 65d2018 | 2016-03-08 07:55:27 -0700 | [diff] [blame] | 1842 | #ifdef VK_USE_PLATFORM_XLIB_KHR |
Mark Young | 16573c7 | 2016-06-28 10:52:43 -0600 | [diff] [blame] | 1843 | LOOKUP_GIPA(CreateXlibSurfaceKHR, false); |
Karl Schultz | 65d2018 | 2016-03-08 07:55:27 -0700 | [diff] [blame] | 1844 | LOOKUP_GIPA(GetPhysicalDeviceXlibPresentationSupportKHR, false); |
| 1845 | #endif |
Mark Young | a7c51fd | 2016-09-16 10:18:42 -0600 | [diff] [blame] | 1846 | #ifdef VK_USE_PLATFORM_MIR_KHR |
| 1847 | LOOKUP_GIPA(CreateMirSurfaceKHR, false); |
| 1848 | LOOKUP_GIPA(GetPhysicalDeviceMirPresentationSupportKHR, false); |
| 1849 | #endif |
Jason Ekstrand | a5ebe8a | 2016-02-12 17:25:03 -0800 | [diff] [blame] | 1850 | #ifdef VK_USE_PLATFORM_WAYLAND_KHR |
Mark Young | 16573c7 | 2016-06-28 10:52:43 -0600 | [diff] [blame] | 1851 | LOOKUP_GIPA(CreateWaylandSurfaceKHR, false); |
Jason Ekstrand | a5ebe8a | 2016-02-12 17:25:03 -0800 | [diff] [blame] | 1852 | LOOKUP_GIPA(GetPhysicalDeviceWaylandPresentationSupportKHR, false); |
| 1853 | #endif |
Mark Young | fa55278 | 2016-12-12 16:14:55 -0700 | [diff] [blame] | 1854 | // NV_external_memory_capabilities |
James Jones | 389dc0c | 2016-08-18 23:41:19 +0100 | [diff] [blame] | 1855 | LOOKUP_GIPA(GetPhysicalDeviceExternalImageFormatPropertiesNV, false); |
Mark Young | fa55278 | 2016-12-12 16:14:55 -0700 | [diff] [blame] | 1856 | // NVX_device_generated_commands |
| 1857 | LOOKUP_GIPA(GetPhysicalDeviceGeneratedCommandsPropertiesNVX, false); |
Jon Ashburn | 3da71f2 | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 1858 | |
Jon Ashburn | c624c88 | 2015-07-16 10:17:29 -0600 | [diff] [blame] | 1859 | #undef LOOKUP_GIPA |
Ian Elliott | d3ef02f | 2015-07-06 14:36:13 -0600 | [diff] [blame] | 1860 | |
Jon Ashburn | c624c88 | 2015-07-16 10:17:29 -0600 | [diff] [blame] | 1861 | return true; |
Jon Ashburn | 3da71f2 | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 1862 | } |
| 1863 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1864 | static void loader_debug_init(void) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1865 | char *env, *orig; |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 1866 | |
| 1867 | if (g_loader_debug > 0) |
| 1868 | return; |
| 1869 | |
| 1870 | g_loader_debug = 0; |
| 1871 | |
| 1872 | /* parse comma-separated debug options */ |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1873 | orig = env = loader_getenv("VK_LOADER_DEBUG", NULL); |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 1874 | while (env) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1875 | char *p = strchr(env, ','); |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 1876 | size_t len; |
| 1877 | |
| 1878 | if (p) |
| 1879 | len = p - env; |
| 1880 | else |
| 1881 | len = strlen(env); |
| 1882 | |
| 1883 | if (len > 0) { |
Michael Worcester | 25c73e7 | 2015-12-10 18:06:24 +0000 | [diff] [blame] | 1884 | if (strncmp(env, "all", len) == 0) { |
| 1885 | g_loader_debug = ~0u; |
| 1886 | g_loader_log_msgs = ~0u; |
| 1887 | } else if (strncmp(env, "warn", len) == 0) { |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 1888 | g_loader_debug |= LOADER_WARN_BIT; |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 1889 | g_loader_log_msgs |= VK_DEBUG_REPORT_WARNING_BIT_EXT; |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 1890 | } else if (strncmp(env, "info", len) == 0) { |
| 1891 | g_loader_debug |= LOADER_INFO_BIT; |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 1892 | g_loader_log_msgs |= VK_DEBUG_REPORT_INFORMATION_BIT_EXT; |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 1893 | } else if (strncmp(env, "perf", len) == 0) { |
| 1894 | g_loader_debug |= LOADER_PERF_BIT; |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 1895 | g_loader_log_msgs |= |
| 1896 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT; |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 1897 | } else if (strncmp(env, "error", len) == 0) { |
| 1898 | g_loader_debug |= LOADER_ERROR_BIT; |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1899 | g_loader_log_msgs |= VK_DEBUG_REPORT_ERROR_BIT_EXT; |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 1900 | } else if (strncmp(env, "debug", len) == 0) { |
| 1901 | g_loader_debug |= LOADER_DEBUG_BIT; |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1902 | g_loader_log_msgs |= VK_DEBUG_REPORT_DEBUG_BIT_EXT; |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 1903 | } |
| 1904 | } |
| 1905 | |
| 1906 | if (!p) |
| 1907 | break; |
| 1908 | |
| 1909 | env = p + 1; |
| 1910 | } |
Jon Ashburn | 38a497f | 2016-01-04 14:01:38 -0700 | [diff] [blame] | 1911 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1912 | loader_free_getenv(orig, NULL); |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 1913 | } |
| 1914 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1915 | void loader_initialize(void) { |
Jon Ashburn | 6461ef2 | 2015-09-22 13:11:00 -0600 | [diff] [blame] | 1916 | // initialize mutexs |
Jon Ashburn | 8810c5f | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 1917 | loader_platform_thread_create_mutex(&loader_lock); |
Jon Ashburn | 6461ef2 | 2015-09-22 13:11:00 -0600 | [diff] [blame] | 1918 | loader_platform_thread_create_mutex(&loader_json_lock); |
Jon Ashburn | 8810c5f | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 1919 | |
| 1920 | // initialize logging |
| 1921 | loader_debug_init(); |
Jon Ashburn | 87d6aa9 | 2015-08-28 15:19:27 -0600 | [diff] [blame] | 1922 | |
| 1923 | // initial cJSON to use alloc callbacks |
| 1924 | cJSON_Hooks alloc_fns = { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1925 | .malloc_fn = loader_instance_tls_heap_alloc, |
| 1926 | .free_fn = loader_instance_tls_heap_free, |
Jon Ashburn | 87d6aa9 | 2015-08-28 15:19:27 -0600 | [diff] [blame] | 1927 | }; |
| 1928 | cJSON_InitHooks(&alloc_fns); |
Jon Ashburn | 8810c5f | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 1929 | } |
| 1930 | |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1931 | struct loader_manifest_files { |
| 1932 | uint32_t count; |
| 1933 | char **filename_list; |
| 1934 | }; |
| 1935 | |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 1936 | /** |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1937 | * 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] | 1938 | * |
| 1939 | * \returns |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1940 | * A pointer to first char in the next path. |
| 1941 | * The next path (or NULL) in the list is returned in next_path. |
| 1942 | * Note: input string is modified in some cases. PASS IN A COPY! |
| 1943 | */ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1944 | static char *loader_get_next_path(char *path) { |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1945 | uint32_t len; |
| 1946 | char *next; |
| 1947 | |
| 1948 | if (path == NULL) |
| 1949 | return NULL; |
Frank Henigman | 5717310 | 2016-11-24 22:15:20 -0500 | [diff] [blame] | 1950 | next = strchr(path, PATH_SEPARATOR); |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1951 | if (next == NULL) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1952 | len = (uint32_t)strlen(path); |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1953 | next = path + len; |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1954 | } else { |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1955 | *next = '\0'; |
| 1956 | next++; |
| 1957 | } |
| 1958 | |
| 1959 | return next; |
| 1960 | } |
| 1961 | |
| 1962 | /** |
Daniel Dadap | 00b4aba | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 1963 | * Given a path which is absolute or relative, expand the path if relative or |
| 1964 | * leave the path unmodified if absolute. The base path to prepend to relative |
| 1965 | * paths is given in rel_base. |
Jon Ashburn | 1531517 | 2015-07-07 15:06:25 -0600 | [diff] [blame] | 1966 | * |
| 1967 | * \returns |
| 1968 | * A string in out_fullpath of the full absolute path |
Jon Ashburn | 1531517 | 2015-07-07 15:06:25 -0600 | [diff] [blame] | 1969 | */ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1970 | static void loader_expand_path(const char *path, const char *rel_base, |
| 1971 | size_t out_size, char *out_fullpath) { |
Jon Ashburn | 1531517 | 2015-07-07 15:06:25 -0600 | [diff] [blame] | 1972 | if (loader_platform_is_path_absolute(path)) { |
Daniel Dadap | 00b4aba | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 1973 | // do not prepend a base to an absolute path |
| 1974 | rel_base = ""; |
Jon Ashburn | 1531517 | 2015-07-07 15:06:25 -0600 | [diff] [blame] | 1975 | } |
Daniel Dadap | 00b4aba | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 1976 | |
| 1977 | loader_platform_combine_path(out_fullpath, out_size, rel_base, path, NULL); |
Jon Ashburn | 1531517 | 2015-07-07 15:06:25 -0600 | [diff] [blame] | 1978 | } |
| 1979 | |
| 1980 | /** |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1981 | * Given a filename (file) and a list of paths (dir), try to find an existing |
| 1982 | * file in the paths. If filename already is a path then no |
| 1983 | * searching in the given paths. |
| 1984 | * |
| 1985 | * \returns |
| 1986 | * A string in out_fullpath of either the full path or file. |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1987 | */ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1988 | static void loader_get_fullpath(const char *file, const char *dirs, |
| 1989 | size_t out_size, char *out_fullpath) { |
Daniel Dadap | 00b4aba | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 1990 | if (!loader_platform_is_path(file) && *dirs) { |
| 1991 | char *dirs_copy, *dir, *next_dir; |
| 1992 | |
| 1993 | dirs_copy = loader_stack_alloc(strlen(dirs) + 1); |
| 1994 | strcpy(dirs_copy, dirs); |
| 1995 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1996 | // find if file exists after prepending paths in given list |
| 1997 | for (dir = dirs_copy; *dir && (next_dir = loader_get_next_path(dir)); |
Daniel Dadap | 00b4aba | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 1998 | dir = next_dir) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1999 | loader_platform_combine_path(out_fullpath, out_size, dir, file, |
| 2000 | NULL); |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2001 | if (loader_platform_file_exists(out_fullpath)) { |
| 2002 | return; |
| 2003 | } |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2004 | } |
| 2005 | } |
Daniel Dadap | 00b4aba | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 2006 | |
Karl Schultz | e2ef9e6 | 2017-01-13 14:01:35 -0700 | [diff] [blame] | 2007 | (void)snprintf(out_fullpath, out_size, "%s", file); |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2008 | } |
| 2009 | |
| 2010 | /** |
| 2011 | * Read a JSON file into a buffer. |
| 2012 | * |
| 2013 | * \returns |
| 2014 | * A pointer to a cJSON object representing the JSON parse tree. |
| 2015 | * This returned buffer should be freed by caller. |
| 2016 | */ |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 2017 | static VkResult loader_get_json(const struct loader_instance *inst, |
| 2018 | const char *filename, cJSON **json) { |
| 2019 | FILE *file = NULL; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2020 | char *json_buf; |
Mark Young | 93ecb1d | 2016-01-13 13:47:16 -0700 | [diff] [blame] | 2021 | size_t len; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 2022 | VkResult res = VK_SUCCESS; |
| 2023 | |
| 2024 | if (NULL == json) { |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2025 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 2026 | "loader_get_json: Received invalid JSON file"); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 2027 | res = VK_ERROR_INITIALIZATION_FAILED; |
| 2028 | goto out; |
| 2029 | } |
| 2030 | |
| 2031 | *json = NULL; |
| 2032 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2033 | file = fopen(filename, "rb"); |
Jon Ashburn | aa4ea47 | 2015-08-27 08:30:50 -0600 | [diff] [blame] | 2034 | if (!file) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2035 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2036 | "loader_get_json: Failed to open JSON file %s", filename); |
| 2037 | res = VK_ERROR_INITIALIZATION_FAILED; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 2038 | goto out; |
Jon Ashburn | aa4ea47 | 2015-08-27 08:30:50 -0600 | [diff] [blame] | 2039 | } |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2040 | fseek(file, 0, SEEK_END); |
| 2041 | len = ftell(file); |
| 2042 | fseek(file, 0, SEEK_SET); |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2043 | json_buf = (char *)loader_stack_alloc(len + 1); |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2044 | if (json_buf == NULL) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2045 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2046 | "loader_get_json: Failed to allocate space for " |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 2047 | "JSON file %s buffer of length %d", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2048 | filename, len); |
| 2049 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 2050 | goto out; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2051 | } |
| 2052 | if (fread(json_buf, sizeof(char), len, file) != len) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2053 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2054 | "loader_get_json: Failed to read JSON file %s.", filename); |
| 2055 | res = VK_ERROR_INITIALIZATION_FAILED; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 2056 | goto out; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2057 | } |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2058 | json_buf[len] = '\0'; |
| 2059 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2060 | // parse text from file |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 2061 | *json = cJSON_Parse(json_buf); |
| 2062 | if (*json == NULL) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2063 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2064 | "loader_get_json: Failed to parse JSON file %s, " |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 2065 | "this is usually because something ran out of " |
| 2066 | "memory.", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2067 | filename); |
| 2068 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 2069 | goto out; |
| 2070 | } |
| 2071 | |
| 2072 | out: |
| 2073 | if (NULL != file) { |
| 2074 | fclose(file); |
| 2075 | } |
| 2076 | |
| 2077 | return res; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2078 | } |
| 2079 | |
| 2080 | /** |
Jon Ashburn | 3d00233 | 2015-08-20 16:35:30 -0600 | [diff] [blame] | 2081 | * Do a deep copy of the loader_layer_properties structure. |
| 2082 | */ |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2083 | VkResult loader_copy_layer_properties(const struct loader_instance *inst, |
| 2084 | struct loader_layer_properties *dst, |
| 2085 | struct loader_layer_properties *src) { |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 2086 | uint32_t cnt, i; |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2087 | memcpy(dst, src, sizeof(*src)); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2088 | dst->instance_extension_list.list = loader_instance_heap_alloc( |
| 2089 | inst, |
| 2090 | sizeof(VkExtensionProperties) * src->instance_extension_list.count, |
| 2091 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2092 | if (NULL == dst->instance_extension_list.list) { |
| 2093 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2094 | "loader_copy_layer_properties: Failed to allocate space " |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 2095 | "for instance extension list of size %d.", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2096 | src->instance_extension_list.count); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2097 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 2098 | } |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2099 | dst->instance_extension_list.capacity = |
| 2100 | sizeof(VkExtensionProperties) * src->instance_extension_list.count; |
Jon Ashburn | e39a4f8 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 2101 | memcpy(dst->instance_extension_list.list, src->instance_extension_list.list, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2102 | dst->instance_extension_list.capacity); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2103 | dst->device_extension_list.list = loader_instance_heap_alloc( |
| 2104 | inst, |
| 2105 | sizeof(struct loader_dev_ext_props) * src->device_extension_list.count, |
| 2106 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2107 | if (NULL == dst->device_extension_list.list) { |
| 2108 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2109 | "loader_copy_layer_properties: Failed to allocate space " |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 2110 | "for device extension list of size %d.", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2111 | src->device_extension_list.count); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2112 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 2113 | } |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 2114 | memset(dst->device_extension_list.list, 0, |
| 2115 | sizeof(struct loader_dev_ext_props) * |
| 2116 | src->device_extension_list.count); |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 2117 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2118 | dst->device_extension_list.capacity = |
| 2119 | sizeof(struct loader_dev_ext_props) * src->device_extension_list.count; |
Jon Ashburn | e39a4f8 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 2120 | memcpy(dst->device_extension_list.list, src->device_extension_list.list, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2121 | dst->device_extension_list.capacity); |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 2122 | if (src->device_extension_list.count > 0 && |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2123 | src->device_extension_list.list->entrypoint_count > 0) { |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 2124 | cnt = src->device_extension_list.list->entrypoint_count; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2125 | dst->device_extension_list.list->entrypoints = |
| 2126 | loader_instance_heap_alloc(inst, sizeof(char *) * cnt, |
| 2127 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
| 2128 | if (NULL == dst->device_extension_list.list->entrypoints) { |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2129 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 2130 | "loader_copy_layer_properties: Failed to allocate space " |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 2131 | "for device extension entrypoint list of size %d.", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2132 | cnt); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2133 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 2134 | } |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 2135 | memset(dst->device_extension_list.list->entrypoints, 0, |
| 2136 | sizeof(char *) * cnt); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2137 | |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 2138 | for (i = 0; i < cnt; i++) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2139 | dst->device_extension_list.list->entrypoints[i] = |
| 2140 | loader_instance_heap_alloc( |
| 2141 | inst, |
| 2142 | strlen(src->device_extension_list.list->entrypoints[i]) + 1, |
| 2143 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
| 2144 | if (NULL == dst->device_extension_list.list->entrypoints[i]) { |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2145 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 2146 | "loader_copy_layer_properties: Failed to " |
| 2147 | "allocate space for device extension entrypoint " |
| 2148 | "%d name of length", |
| 2149 | i); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2150 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 2151 | } |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 2152 | strcpy(dst->device_extension_list.list->entrypoints[i], |
| 2153 | src->device_extension_list.list->entrypoints[i]); |
| 2154 | } |
| 2155 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2156 | |
| 2157 | return VK_SUCCESS; |
Jon Ashburn | 3d00233 | 2015-08-20 16:35:30 -0600 | [diff] [blame] | 2158 | } |
| 2159 | |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 2160 | static bool |
| 2161 | loader_find_layer_name_list(const char *name, |
| 2162 | const struct loader_layer_list *layer_list) { |
| 2163 | if (!layer_list) |
| 2164 | return false; |
| 2165 | for (uint32_t j = 0; j < layer_list->count; j++) |
| 2166 | if (!strcmp(name, layer_list->list[j].info.layerName)) |
| 2167 | return true; |
| 2168 | return false; |
| 2169 | } |
| 2170 | |
| 2171 | static bool loader_find_layer_name(const char *name, uint32_t layer_count, |
| 2172 | const char **layer_list) { |
| 2173 | if (!layer_list) |
| 2174 | return false; |
| 2175 | for (uint32_t j = 0; j < layer_count; j++) |
| 2176 | if (!strcmp(name, layer_list[j])) |
| 2177 | return true; |
| 2178 | return false; |
| 2179 | } |
| 2180 | |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 2181 | bool loader_find_layer_name_array( |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 2182 | const char *name, uint32_t layer_count, |
| 2183 | const char layer_list[][VK_MAX_EXTENSION_NAME_SIZE]) { |
| 2184 | if (!layer_list) |
| 2185 | return false; |
| 2186 | for (uint32_t j = 0; j < layer_count; j++) |
| 2187 | if (!strcmp(name, layer_list[j])) |
| 2188 | return true; |
| 2189 | return false; |
| 2190 | } |
| 2191 | |
| 2192 | /** |
| 2193 | * Searches through an array of layer names (ppp_layer_names) looking for a |
| 2194 | * layer key_name. |
| 2195 | * If not found then simply returns updating nothing. |
| 2196 | * Otherwise, it uses expand_count, expand_names adding them to layer names. |
Chris Forbes | 6936647 | 2016-04-07 09:04:49 +1200 | [diff] [blame] | 2197 | * Any duplicate (pre-existing) expand_names in layer names are removed. |
| 2198 | * Order is otherwise preserved, with the layer key_name being replaced by the |
| 2199 | * expand_names. |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 2200 | * @param inst |
| 2201 | * @param layer_count |
| 2202 | * @param ppp_layer_names |
| 2203 | */ |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2204 | VkResult loader_expand_layer_names( |
| 2205 | struct loader_instance *inst, const char *key_name, uint32_t expand_count, |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 2206 | const char expand_names[][VK_MAX_EXTENSION_NAME_SIZE], |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 2207 | uint32_t *layer_count, char const *const **ppp_layer_names) { |
Jon Ashburn | 7148344 | 2016-02-11 18:59:43 -0700 | [diff] [blame] | 2208 | |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 2209 | char const *const *pp_src_layers = *ppp_layer_names; |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 2210 | |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 2211 | if (!loader_find_layer_name(key_name, *layer_count, |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 2212 | (char const **)pp_src_layers)) { |
| 2213 | inst->activated_layers_are_std_val = false; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2214 | return VK_SUCCESS; // didn't find the key_name in the list. |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 2215 | } |
Jon Ashburn | 7148344 | 2016-02-11 18:59:43 -0700 | [diff] [blame] | 2216 | |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 2217 | loader_log(inst, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, |
| 2218 | "Found meta layer %s, replacing with actual layer group", |
| 2219 | key_name); |
Chris Forbes | bd9de05 | 2016-04-06 20:49:02 +1200 | [diff] [blame] | 2220 | |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 2221 | inst->activated_layers_are_std_val = true; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2222 | char const **pp_dst_layers = loader_instance_heap_alloc( |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 2223 | inst, (expand_count + *layer_count - 1) * sizeof(char const *), |
| 2224 | VK_SYSTEM_ALLOCATION_SCOPE_COMMAND); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2225 | if (NULL == pp_dst_layers) { |
| 2226 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2227 | "loader_expand_layer_names:: Failed to allocate space for " |
| 2228 | "std_validation layer names in pp_dst_layers."); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2229 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 2230 | } |
Chris Forbes | bd9de05 | 2016-04-06 20:49:02 +1200 | [diff] [blame] | 2231 | |
| 2232 | // copy layers from src to dst, stripping key_name and anything in |
| 2233 | // expand_names. |
| 2234 | uint32_t src_index, dst_index = 0; |
| 2235 | for (src_index = 0; src_index < *layer_count; src_index++) { |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 2236 | if (loader_find_layer_name_array(pp_src_layers[src_index], expand_count, |
| 2237 | expand_names)) { |
Chris Forbes | 6936647 | 2016-04-07 09:04:49 +1200 | [diff] [blame] | 2238 | continue; |
| 2239 | } |
| 2240 | |
| 2241 | if (!strcmp(pp_src_layers[src_index], key_name)) { |
| 2242 | // insert all expand_names in place of key_name |
| 2243 | uint32_t expand_index; |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 2244 | for (expand_index = 0; expand_index < expand_count; |
| 2245 | expand_index++) { |
Chris Forbes | 6936647 | 2016-04-07 09:04:49 +1200 | [diff] [blame] | 2246 | pp_dst_layers[dst_index++] = expand_names[expand_index]; |
| 2247 | } |
Chris Forbes | bd9de05 | 2016-04-06 20:49:02 +1200 | [diff] [blame] | 2248 | continue; |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 2249 | } |
Chris Forbes | bd9de05 | 2016-04-06 20:49:02 +1200 | [diff] [blame] | 2250 | |
| 2251 | pp_dst_layers[dst_index++] = pp_src_layers[src_index]; |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 2252 | } |
| 2253 | |
Chris Forbes | bd9de05 | 2016-04-06 20:49:02 +1200 | [diff] [blame] | 2254 | *ppp_layer_names = pp_dst_layers; |
| 2255 | *layer_count = dst_index; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2256 | |
| 2257 | return VK_SUCCESS; |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 2258 | } |
| 2259 | |
Chris Forbes | bd9de05 | 2016-04-06 20:49:02 +1200 | [diff] [blame] | 2260 | void loader_delete_shadow_inst_layer_names(const struct loader_instance *inst, |
| 2261 | const VkInstanceCreateInfo *orig, |
| 2262 | VkInstanceCreateInfo *ours) { |
| 2263 | /* Free the layer names array iff we had to reallocate it */ |
| 2264 | if (orig->ppEnabledLayerNames != ours->ppEnabledLayerNames) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2265 | loader_instance_heap_free(inst, (void *)ours->ppEnabledLayerNames); |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 2266 | } |
| 2267 | } |
| 2268 | |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 2269 | void loader_init_std_validation_props(struct loader_layer_properties *props) { |
| 2270 | memset(props, 0, sizeof(struct loader_layer_properties)); |
| 2271 | props->type = VK_LAYER_TYPE_META_EXPLICT; |
| 2272 | strncpy(props->info.description, "LunarG Standard Validation Layer", |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 2273 | sizeof(props->info.description)); |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 2274 | props->info.implementationVersion = 1; |
| 2275 | strncpy(props->info.layerName, std_validation_str, |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 2276 | sizeof(props->info.layerName)); |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 2277 | // TODO what about specVersion? for now insert loader's built version |
| 2278 | props->info.specVersion = VK_MAKE_VERSION(1, 0, VK_HEADER_VERSION); |
| 2279 | } |
| 2280 | |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 2281 | /** |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 2282 | * Searches through the existing instance layer lists looking for |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 2283 | * the set of required layer names. If found then it adds a meta property to the |
| 2284 | * layer list. |
| 2285 | * Assumes the required layers are the same for both instance and device lists. |
| 2286 | * @param inst |
| 2287 | * @param layer_count number of layers in layer_names |
| 2288 | * @param layer_names array of required layer names |
| 2289 | * @param layer_instance_list |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 2290 | */ |
| 2291 | static void loader_add_layer_property_meta( |
| 2292 | const struct loader_instance *inst, uint32_t layer_count, |
| 2293 | const char layer_names[][VK_MAX_EXTENSION_NAME_SIZE], |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 2294 | struct loader_layer_list *layer_instance_list) { |
| 2295 | uint32_t i; |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 2296 | bool found; |
| 2297 | struct loader_layer_list *layer_list; |
| 2298 | |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 2299 | if (0 == layer_count || (!layer_instance_list)) |
Jon Ashburn | 888c050 | 2016-02-19 15:22:10 -0700 | [diff] [blame] | 2300 | return; |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 2301 | if (layer_instance_list && (layer_count > layer_instance_list->count)) |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 2302 | return; |
| 2303 | |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 2304 | layer_list = layer_instance_list; |
| 2305 | |
| 2306 | found = true; |
| 2307 | if (layer_list == NULL) |
| 2308 | return; |
| 2309 | for (i = 0; i < layer_count; i++) { |
| 2310 | if (loader_find_layer_name_list(layer_names[i], layer_list)) |
Jon Ashburn | 888c050 | 2016-02-19 15:22:10 -0700 | [diff] [blame] | 2311 | continue; |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 2312 | found = false; |
| 2313 | break; |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 2314 | } |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 2315 | |
| 2316 | struct loader_layer_properties *props; |
| 2317 | if (found) { |
| 2318 | props = loader_get_next_layer_property(inst, layer_list); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2319 | if (NULL == props) { |
| 2320 | // Error already triggered in loader_get_next_layer_property. |
| 2321 | return; |
| 2322 | } |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 2323 | loader_init_std_validation_props(props); |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 2324 | } |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 2325 | } |
| 2326 | |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2327 | static void loader_read_json_layer( |
| 2328 | const struct loader_instance *inst, |
| 2329 | struct loader_layer_list *layer_instance_list, cJSON *layer_node, |
| 2330 | cJSON *item, cJSON *disable_environment, bool is_implicit, char *filename) { |
| 2331 | char *temp; |
| 2332 | char *name, *type, *library_path, *api_version; |
| 2333 | char *implementation_version, *description; |
| 2334 | cJSON *ext_item; |
| 2335 | VkExtensionProperties ext_prop; |
| 2336 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2337 | /* |
| 2338 | * The following are required in the "layer" object: |
| 2339 | * (required) "name" |
| 2340 | * (required) "type" |
| 2341 | * (required) “library_path” |
| 2342 | * (required) “api_version” |
| 2343 | * (required) “implementation_version” |
| 2344 | * (required) “description” |
| 2345 | * (required for implicit layers) “disable_environment” |
| 2346 | */ |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 2347 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2348 | #define GET_JSON_OBJECT(node, var) \ |
| 2349 | { \ |
| 2350 | var = cJSON_GetObjectItem(node, #var); \ |
| 2351 | if (var == NULL) { \ |
| 2352 | layer_node = layer_node->next; \ |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 2353 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, \ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2354 | "Didn't find required layer object %s in manifest " \ |
| 2355 | "JSON file, skipping this layer", \ |
| 2356 | #var); \ |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2357 | return; \ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2358 | } \ |
| 2359 | } |
| 2360 | #define GET_JSON_ITEM(node, var) \ |
| 2361 | { \ |
| 2362 | item = cJSON_GetObjectItem(node, #var); \ |
| 2363 | if (item == NULL) { \ |
| 2364 | layer_node = layer_node->next; \ |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 2365 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, \ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2366 | "Didn't find required layer value %s in manifest JSON " \ |
| 2367 | "file, skipping this layer", \ |
| 2368 | #var); \ |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2369 | return; \ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2370 | } \ |
| 2371 | temp = cJSON_Print(item); \ |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2372 | if (temp == NULL) { \ |
| 2373 | layer_node = layer_node->next; \ |
| 2374 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, \ |
| 2375 | "Problem accessing layer value %s in manifest JSON " \ |
| 2376 | "file, skipping this layer", \ |
| 2377 | #var); \ |
| 2378 | return; \ |
| 2379 | } \ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2380 | temp[strlen(temp) - 1] = '\0'; \ |
| 2381 | var = loader_stack_alloc(strlen(temp) + 1); \ |
| 2382 | strcpy(var, &temp[1]); \ |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2383 | cJSON_Free(temp); \ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2384 | } |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2385 | GET_JSON_ITEM(layer_node, name) |
| 2386 | GET_JSON_ITEM(layer_node, type) |
| 2387 | GET_JSON_ITEM(layer_node, library_path) |
| 2388 | GET_JSON_ITEM(layer_node, api_version) |
| 2389 | GET_JSON_ITEM(layer_node, implementation_version) |
| 2390 | GET_JSON_ITEM(layer_node, description) |
| 2391 | if (is_implicit) { |
| 2392 | GET_JSON_OBJECT(layer_node, disable_environment) |
| 2393 | } |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 2394 | #undef GET_JSON_ITEM |
| 2395 | #undef GET_JSON_OBJECT |
| 2396 | |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2397 | // add list entry |
| 2398 | struct loader_layer_properties *props = NULL; |
| 2399 | if (!strcmp(type, "DEVICE")) { |
| 2400 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 2401 | "Device layers are deprecated skipping this layer"); |
| 2402 | layer_node = layer_node->next; |
| 2403 | return; |
| 2404 | } |
| 2405 | // Allow either GLOBAL or INSTANCE type interchangeably to handle |
| 2406 | // layers that must work with older loaders |
| 2407 | if (!strcmp(type, "INSTANCE") || !strcmp(type, "GLOBAL")) { |
| 2408 | if (layer_instance_list == NULL) { |
Jon Ashburn | 432d276 | 2015-09-18 12:53:16 -0600 | [diff] [blame] | 2409 | layer_node = layer_node->next; |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2410 | return; |
Jon Ashburn | 432d276 | 2015-09-18 12:53:16 -0600 | [diff] [blame] | 2411 | } |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2412 | props = loader_get_next_layer_property(inst, layer_instance_list); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2413 | if (NULL == props) { |
| 2414 | // Error already triggered in loader_get_next_layer_property. |
| 2415 | return; |
| 2416 | } |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2417 | props->type = (is_implicit) ? VK_LAYER_TYPE_INSTANCE_IMPLICIT |
| 2418 | : VK_LAYER_TYPE_INSTANCE_EXPLICIT; |
| 2419 | } |
Jon Ashburn | 432d276 | 2015-09-18 12:53:16 -0600 | [diff] [blame] | 2420 | |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2421 | if (props == NULL) { |
| 2422 | layer_node = layer_node->next; |
| 2423 | return; |
| 2424 | } |
Jon Ashburn | 1531517 | 2015-07-07 15:06:25 -0600 | [diff] [blame] | 2425 | |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2426 | strncpy(props->info.layerName, name, sizeof(props->info.layerName)); |
| 2427 | props->info.layerName[sizeof(props->info.layerName) - 1] = '\0'; |
| 2428 | |
| 2429 | char *fullpath = props->lib_name; |
| 2430 | char *rel_base; |
| 2431 | if (loader_platform_is_path(library_path)) { |
| 2432 | // a relative or absolute path |
| 2433 | char *name_copy = loader_stack_alloc(strlen(filename) + 1); |
| 2434 | strcpy(name_copy, filename); |
| 2435 | rel_base = loader_platform_dirname(name_copy); |
| 2436 | loader_expand_path(library_path, rel_base, MAX_STRING_SIZE, fullpath); |
| 2437 | } else { |
| 2438 | // a filename which is assumed in a system directory |
| 2439 | loader_get_fullpath(library_path, DEFAULT_VK_LAYERS_PATH, |
| 2440 | MAX_STRING_SIZE, fullpath); |
| 2441 | } |
| 2442 | props->info.specVersion = loader_make_version(api_version); |
| 2443 | props->info.implementationVersion = atoi(implementation_version); |
| 2444 | strncpy((char *)props->info.description, description, |
| 2445 | sizeof(props->info.description)); |
| 2446 | props->info.description[sizeof(props->info.description) - 1] = '\0'; |
| 2447 | if (is_implicit) { |
| 2448 | if (!disable_environment || !disable_environment->child) { |
| 2449 | loader_log( |
| 2450 | inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 2451 | "Didn't find required layer child value disable_environment" |
| 2452 | "in manifest JSON file, skipping this layer"); |
| 2453 | layer_node = layer_node->next; |
| 2454 | return; |
Jon Ashburn | fb8ac01 | 2015-08-12 16:39:32 -0600 | [diff] [blame] | 2455 | } |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2456 | strncpy(props->disable_env_var.name, disable_environment->child->string, |
| 2457 | sizeof(props->disable_env_var.name)); |
| 2458 | props->disable_env_var.name[sizeof(props->disable_env_var.name) - 1] = |
| 2459 | '\0'; |
| 2460 | strncpy(props->disable_env_var.value, |
| 2461 | disable_environment->child->valuestring, |
| 2462 | sizeof(props->disable_env_var.value)); |
| 2463 | props->disable_env_var.value[sizeof(props->disable_env_var.value) - 1] = |
| 2464 | '\0'; |
| 2465 | } |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 2466 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2467 | /** |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2468 | * Now get all optional items and objects and put in list: |
| 2469 | * functions |
| 2470 | * instance_extensions |
| 2471 | * device_extensions |
| 2472 | * enable_environment (implicit layers only) |
| 2473 | */ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2474 | #define GET_JSON_OBJECT(node, var) \ |
| 2475 | { var = cJSON_GetObjectItem(node, #var); } |
| 2476 | #define GET_JSON_ITEM(node, var) \ |
| 2477 | { \ |
| 2478 | item = cJSON_GetObjectItem(node, #var); \ |
| 2479 | if (item != NULL) { \ |
| 2480 | temp = cJSON_Print(item); \ |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2481 | if (temp != NULL) { \ |
| 2482 | temp[strlen(temp) - 1] = '\0'; \ |
| 2483 | var = loader_stack_alloc(strlen(temp) + 1); \ |
| 2484 | strcpy(var, &temp[1]); \ |
| 2485 | cJSON_Free(temp); \ |
| 2486 | } \ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2487 | } \ |
| 2488 | } |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 2489 | |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2490 | cJSON *instance_extensions, *device_extensions, *functions, |
| 2491 | *enable_environment; |
| 2492 | cJSON *entrypoints; |
| 2493 | char *vkGetInstanceProcAddr, *vkGetDeviceProcAddr, *spec_version; |
| 2494 | char **entry_array; |
| 2495 | vkGetInstanceProcAddr = NULL; |
| 2496 | vkGetDeviceProcAddr = NULL; |
| 2497 | spec_version = NULL; |
| 2498 | entrypoints = NULL; |
| 2499 | entry_array = NULL; |
| 2500 | int i, j; |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 2501 | |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2502 | /** |
| 2503 | * functions |
| 2504 | * vkGetInstanceProcAddr |
| 2505 | * vkGetDeviceProcAddr |
| 2506 | */ |
| 2507 | GET_JSON_OBJECT(layer_node, functions) |
| 2508 | if (functions != NULL) { |
| 2509 | GET_JSON_ITEM(functions, vkGetInstanceProcAddr) |
| 2510 | GET_JSON_ITEM(functions, vkGetDeviceProcAddr) |
| 2511 | if (vkGetInstanceProcAddr != NULL) |
| 2512 | strncpy(props->functions.str_gipa, vkGetInstanceProcAddr, |
| 2513 | sizeof(props->functions.str_gipa)); |
| 2514 | props->functions.str_gipa[sizeof(props->functions.str_gipa) - 1] = '\0'; |
| 2515 | if (vkGetDeviceProcAddr != NULL) |
| 2516 | strncpy(props->functions.str_gdpa, vkGetDeviceProcAddr, |
| 2517 | sizeof(props->functions.str_gdpa)); |
| 2518 | props->functions.str_gdpa[sizeof(props->functions.str_gdpa) - 1] = '\0'; |
| 2519 | } |
| 2520 | /** |
| 2521 | * instance_extensions |
| 2522 | * array of |
| 2523 | * name |
| 2524 | * spec_version |
| 2525 | */ |
| 2526 | GET_JSON_OBJECT(layer_node, instance_extensions) |
| 2527 | if (instance_extensions != NULL) { |
| 2528 | int count = cJSON_GetArraySize(instance_extensions); |
| 2529 | for (i = 0; i < count; i++) { |
| 2530 | ext_item = cJSON_GetArrayItem(instance_extensions, i); |
| 2531 | GET_JSON_ITEM(ext_item, name) |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2532 | if (name != NULL) { |
| 2533 | strncpy(ext_prop.extensionName, name, |
| 2534 | sizeof(ext_prop.extensionName)); |
| 2535 | ext_prop.extensionName[sizeof(ext_prop.extensionName) - 1] = |
| 2536 | '\0'; |
| 2537 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2538 | GET_JSON_ITEM(ext_item, spec_version) |
| 2539 | if (NULL != spec_version) { |
| 2540 | ext_prop.specVersion = atoi(spec_version); |
| 2541 | } else { |
| 2542 | ext_prop.specVersion = 0; |
| 2543 | } |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2544 | bool ext_unsupported = |
| 2545 | wsi_unsupported_instance_extension(&ext_prop); |
| 2546 | if (!ext_unsupported) { |
| 2547 | loader_add_to_ext_list(inst, &props->instance_extension_list, 1, |
| 2548 | &ext_prop); |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 2549 | } |
Jon Ashburn | fb8ac01 | 2015-08-12 16:39:32 -0600 | [diff] [blame] | 2550 | } |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2551 | } |
| 2552 | /** |
| 2553 | * device_extensions |
| 2554 | * array of |
| 2555 | * name |
| 2556 | * spec_version |
| 2557 | * entrypoints |
| 2558 | */ |
| 2559 | GET_JSON_OBJECT(layer_node, device_extensions) |
| 2560 | if (device_extensions != NULL) { |
| 2561 | int count = cJSON_GetArraySize(device_extensions); |
| 2562 | for (i = 0; i < count; i++) { |
| 2563 | ext_item = cJSON_GetArrayItem(device_extensions, i); |
| 2564 | GET_JSON_ITEM(ext_item, name) |
| 2565 | GET_JSON_ITEM(ext_item, spec_version) |
| 2566 | if (name != NULL) { |
| 2567 | strncpy(ext_prop.extensionName, name, |
| 2568 | sizeof(ext_prop.extensionName)); |
| 2569 | ext_prop.extensionName[sizeof(ext_prop.extensionName) - 1] = |
| 2570 | '\0'; |
| 2571 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2572 | if (NULL != spec_version) { |
| 2573 | ext_prop.specVersion = atoi(spec_version); |
| 2574 | } else { |
| 2575 | ext_prop.specVersion = 0; |
| 2576 | } |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2577 | // entrypoints = cJSON_GetObjectItem(ext_item, "entrypoints"); |
| 2578 | GET_JSON_OBJECT(ext_item, entrypoints) |
| 2579 | int entry_count; |
| 2580 | if (entrypoints == NULL) { |
| 2581 | loader_add_to_dev_ext_list(inst, &props->device_extension_list, |
| 2582 | &ext_prop, 0, NULL); |
| 2583 | continue; |
| 2584 | } |
| 2585 | entry_count = cJSON_GetArraySize(entrypoints); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2586 | if (entry_count) { |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2587 | entry_array = |
| 2588 | (char **)loader_stack_alloc(sizeof(char *) * entry_count); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2589 | } |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2590 | for (j = 0; j < entry_count; j++) { |
| 2591 | ext_item = cJSON_GetArrayItem(entrypoints, j); |
| 2592 | if (ext_item != NULL) { |
| 2593 | temp = cJSON_Print(ext_item); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2594 | if (NULL == temp) { |
| 2595 | entry_array[j] = NULL; |
| 2596 | continue; |
| 2597 | } |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2598 | temp[strlen(temp) - 1] = '\0'; |
| 2599 | entry_array[j] = loader_stack_alloc(strlen(temp) + 1); |
| 2600 | strcpy(entry_array[j], &temp[1]); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2601 | cJSON_Free(temp); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2602 | } |
| 2603 | } |
| 2604 | loader_add_to_dev_ext_list(inst, &props->device_extension_list, |
| 2605 | &ext_prop, entry_count, entry_array); |
| 2606 | } |
| 2607 | } |
| 2608 | if (is_implicit) { |
| 2609 | GET_JSON_OBJECT(layer_node, enable_environment) |
| 2610 | |
| 2611 | // enable_environment is optional |
| 2612 | if (enable_environment) { |
| 2613 | strncpy(props->enable_env_var.name, |
| 2614 | enable_environment->child->string, |
| 2615 | sizeof(props->enable_env_var.name)); |
| 2616 | props->enable_env_var.name[sizeof(props->enable_env_var.name) - 1] = |
| 2617 | '\0'; |
| 2618 | strncpy(props->enable_env_var.value, |
| 2619 | enable_environment->child->valuestring, |
| 2620 | sizeof(props->enable_env_var.value)); |
| 2621 | props->enable_env_var |
| 2622 | .value[sizeof(props->enable_env_var.value) - 1] = '\0'; |
| 2623 | } |
| 2624 | } |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 2625 | #undef GET_JSON_ITEM |
| 2626 | #undef GET_JSON_OBJECT |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2627 | } |
| 2628 | |
| 2629 | /** |
| 2630 | * Given a cJSON struct (json) of the top level JSON object from layer manifest |
| 2631 | * file, add entry to the layer_list. Fill out the layer_properties in this list |
| 2632 | * entry from the input cJSON object. |
| 2633 | * |
| 2634 | * \returns |
| 2635 | * void |
| 2636 | * layer_list has a new entry and initialized accordingly. |
| 2637 | * If the json input object does not have all the required fields no entry |
| 2638 | * is added to the list. |
| 2639 | */ |
| 2640 | static void |
| 2641 | loader_add_layer_properties(const struct loader_instance *inst, |
| 2642 | struct loader_layer_list *layer_instance_list, |
| 2643 | cJSON *json, bool is_implicit, char *filename) { |
| 2644 | /* Fields in layer manifest file that are required: |
| 2645 | * (required) “file_format_version” |
| 2646 | * |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2647 | * If more than one "layer" object are to be used, use the "layers" array |
| 2648 | * instead. |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2649 | * |
| 2650 | * First get all required items and if any missing abort |
| 2651 | */ |
| 2652 | |
| 2653 | cJSON *item, *layers_node, *layer_node; |
| 2654 | uint16_t file_major_vers = 0; |
| 2655 | uint16_t file_minor_vers = 0; |
| 2656 | uint16_t file_patch_vers = 0; |
| 2657 | char *vers_tok; |
| 2658 | cJSON *disable_environment = NULL; |
| 2659 | item = cJSON_GetObjectItem(json, "file_format_version"); |
| 2660 | if (item == NULL) { |
| 2661 | return; |
| 2662 | } |
| 2663 | char *file_vers = cJSON_PrintUnformatted(item); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2664 | if (NULL == file_vers) { |
| 2665 | return; |
| 2666 | } |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2667 | loader_log(inst, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, |
| 2668 | "Found manifest file %s, version %s", filename, file_vers); |
| 2669 | // Get the major/minor/and patch as integers for easier comparison |
| 2670 | vers_tok = strtok(file_vers, ".\"\n\r"); |
| 2671 | if (NULL != vers_tok) { |
Jamie Madill | 970ebcf | 2016-07-06 11:19:42 -0400 | [diff] [blame] | 2672 | file_major_vers = (uint16_t)atoi(vers_tok); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2673 | vers_tok = strtok(NULL, ".\"\n\r"); |
| 2674 | if (NULL != vers_tok) { |
Jamie Madill | 970ebcf | 2016-07-06 11:19:42 -0400 | [diff] [blame] | 2675 | file_minor_vers = (uint16_t)atoi(vers_tok); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2676 | vers_tok = strtok(NULL, ".\"\n\r"); |
| 2677 | if (NULL != vers_tok) { |
Jamie Madill | 970ebcf | 2016-07-06 11:19:42 -0400 | [diff] [blame] | 2678 | file_patch_vers = (uint16_t)atoi(vers_tok); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2679 | } |
| 2680 | } |
| 2681 | } |
| 2682 | if (file_major_vers != 1 || file_minor_vers != 0 || file_patch_vers > 1) { |
| 2683 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2684 | "loader_add_layer_properties: Unexpected manifest file " |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 2685 | "version (expected 1.0.0 or 1.0.1) in %s, may cause " |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2686 | "errors", |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2687 | filename); |
| 2688 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2689 | cJSON_Free(file_vers); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2690 | // If "layers" is present, read in the array of layer objects |
| 2691 | layers_node = cJSON_GetObjectItem(json, "layers"); |
| 2692 | if (layers_node != NULL) { |
| 2693 | int numItems = cJSON_GetArraySize(layers_node); |
| 2694 | if (file_major_vers == 1 && file_minor_vers == 0 && |
| 2695 | file_patch_vers == 0) { |
| 2696 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 2697 | "loader_add_layer_properties: \'layers\' tag not " |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2698 | "supported until file version 1.0.1, but %s is " |
| 2699 | "reporting version %s", |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2700 | filename, file_vers); |
| 2701 | } |
| 2702 | for (int curLayer = 0; curLayer < numItems; curLayer++) { |
| 2703 | layer_node = cJSON_GetArrayItem(layers_node, curLayer); |
| 2704 | if (layer_node == NULL) { |
| 2705 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2706 | "loader_add_layer_properties: Can not find " |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 2707 | "\'layers\' array element %d object in manifest " |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2708 | "JSON file %s. Skipping this file", |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2709 | curLayer, filename); |
| 2710 | return; |
| 2711 | } |
| 2712 | loader_read_json_layer(inst, layer_instance_list, layer_node, item, |
| 2713 | disable_environment, is_implicit, filename); |
| 2714 | } |
| 2715 | } else { |
| 2716 | // Otherwise, try to read in individual layers |
| 2717 | layer_node = cJSON_GetObjectItem(json, "layer"); |
| 2718 | if (layer_node == NULL) { |
| 2719 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 2720 | "loader_add_layer_properties: Can not find \'layer\' " |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2721 | "object in manifest JSON file %s. Skipping this file.", |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2722 | filename); |
| 2723 | return; |
| 2724 | } |
| 2725 | // Loop through all "layer" objects in the file to get a count of them |
| 2726 | // first. |
| 2727 | uint16_t layer_count = 0; |
| 2728 | cJSON *tempNode = layer_node; |
| 2729 | do { |
| 2730 | tempNode = tempNode->next; |
| 2731 | layer_count++; |
| 2732 | } while (tempNode != NULL); |
| 2733 | /* |
| 2734 | * Throw a warning if we encounter multiple "layer" objects in file |
| 2735 | * versions newer than 1.0.0. Having multiple objects with the same |
| 2736 | * name at the same level is actually a JSON standard violation. |
| 2737 | */ |
| 2738 | if (layer_count > 1 && |
| 2739 | (file_major_vers > 1 || |
| 2740 | !(file_minor_vers == 0 && file_patch_vers == 0))) { |
| 2741 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 2742 | "loader_add_layer_properties: Multiple \'layer\' nodes" |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2743 | " are deprecated starting in file version \"1.0.1\". " |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 2744 | "Please use \'layers\' : [] array instead in %s.", |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2745 | filename); |
| 2746 | } else { |
| 2747 | do { |
| 2748 | loader_read_json_layer(inst, layer_instance_list, layer_node, |
| 2749 | item, disable_environment, is_implicit, |
| 2750 | filename); |
| 2751 | layer_node = layer_node->next; |
| 2752 | } while (layer_node != NULL); |
| 2753 | } |
| 2754 | } |
Jon Ashburn | fb8ac01 | 2015-08-12 16:39:32 -0600 | [diff] [blame] | 2755 | return; |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 2756 | } |
| 2757 | |
| 2758 | /** |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2759 | * Find the Vulkan library manifest files. |
| 2760 | * |
Jon Ashburn | b682221 | 2016-02-16 15:34:16 -0700 | [diff] [blame] | 2761 | * This function scans the "location" or "env_override" directories/files |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2762 | * for a list of JSON manifest files. If env_override is non-NULL |
| 2763 | * and has a valid value. Then the location is ignored. Otherwise |
| 2764 | * location is used to look for manifest files. The location |
| 2765 | * is interpreted as Registry path on Windows and a directory path(s) |
Jon Ashburn | b682221 | 2016-02-16 15:34:16 -0700 | [diff] [blame] | 2766 | * on Linux. "home_location" is an additional directory in the users home |
John Drinkwater | 9ac3f4f | 2016-08-01 17:00:00 +0100 | [diff] [blame] | 2767 | * directory to look at. It is expanded into the dir path |
| 2768 | * $XDG_DATA_HOME/home_location or $HOME/.local/share/home_location depending |
| 2769 | * on environment variables. This "home_location" is only used on Linux. |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2770 | * |
| 2771 | * \returns |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2772 | * VKResult |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2773 | * A string list of manifest files to be opened in out_files param. |
| 2774 | * List has a pointer to string for each manifest filename. |
| 2775 | * When done using the list in out_files, pointers should be freed. |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2776 | * Location or override string lists can be either files or directories as |
| 2777 | *follows: |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2778 | * | location | override |
| 2779 | * -------------------------------- |
| 2780 | * Win ICD | files | files |
| 2781 | * Win Layer | files | dirs |
| 2782 | * Linux ICD | dirs | files |
| 2783 | * Linux Layer| dirs | dirs |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2784 | */ |
Mark Young | f8c2010 | 2016-11-07 16:26:17 -0700 | [diff] [blame] | 2785 | static VkResult |
| 2786 | loader_get_manifest_files(const struct loader_instance *inst, |
Frank Henigman | b1c27cb | 2016-11-24 20:02:09 -0500 | [diff] [blame] | 2787 | const char *env_override, const char *source_override, |
Mark Young | f8c2010 | 2016-11-07 16:26:17 -0700 | [diff] [blame] | 2788 | bool is_layer, bool warn_if_not_present, |
| 2789 | const char *location, const char *home_location, |
| 2790 | struct loader_manifest_files *out_files) { |
Frank Henigman | b1c27cb | 2016-11-24 20:02:09 -0500 | [diff] [blame] | 2791 | const char *override = NULL; |
| 2792 | char *override_getenv = NULL; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2793 | char *loc, *orig_loc = NULL; |
| 2794 | char *reg = NULL; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2795 | char *file, *next_file, *name; |
| 2796 | size_t alloced_count = 64; |
| 2797 | char full_path[2048]; |
| 2798 | DIR *sysdir = NULL; |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2799 | bool list_is_dirs = false; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2800 | struct dirent *dent; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2801 | VkResult res = VK_SUCCESS; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2802 | |
| 2803 | out_files->count = 0; |
| 2804 | out_files->filename_list = NULL; |
| 2805 | |
Jamie Madill | 00c3c91 | 2016-04-06 18:26:46 -0400 | [diff] [blame] | 2806 | if (source_override != NULL) { |
| 2807 | override = source_override; |
Frank Henigman | b1c27cb | 2016-11-24 20:02:09 -0500 | [diff] [blame] | 2808 | } else if (env_override != NULL) { |
Johannes van Waveren | 9bd80501 | 2015-10-28 11:45:00 -0500 | [diff] [blame] | 2809 | #if !defined(_WIN32) |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 2810 | if (geteuid() != getuid() || getegid() != getgid()) { |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2811 | /* Don't allow setuid apps to use the env var: */ |
Frank Henigman | b1c27cb | 2016-11-24 20:02:09 -0500 | [diff] [blame] | 2812 | env_override = NULL; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2813 | } |
| 2814 | #endif |
Frank Henigman | b1c27cb | 2016-11-24 20:02:09 -0500 | [diff] [blame] | 2815 | if (env_override != NULL) { |
| 2816 | override = override_getenv = loader_getenv(env_override, inst); |
| 2817 | } |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2818 | } |
| 2819 | |
Jon Ashburn | b682221 | 2016-02-16 15:34:16 -0700 | [diff] [blame] | 2820 | #if !defined(_WIN32) |
| 2821 | if (location == NULL && home_location == NULL) { |
| 2822 | #else |
| 2823 | home_location = NULL; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2824 | if (location == NULL) { |
Jon Ashburn | b682221 | 2016-02-16 15:34:16 -0700 | [diff] [blame] | 2825 | #endif |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2826 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 2827 | "loader_get_manifest_files: Can not get manifest files with " |
| 2828 | "NULL location, env_override=%s", |
| 2829 | (env_override != NULL) ? env_override : ""); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2830 | res = VK_ERROR_INITIALIZATION_FAILED; |
| 2831 | goto out; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2832 | } |
| 2833 | |
Johannes van Waveren | 9bd80501 | 2015-10-28 11:45:00 -0500 | [diff] [blame] | 2834 | #if defined(_WIN32) |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2835 | list_is_dirs = (is_layer && override != NULL) ? true : false; |
Johannes van Waveren | 9bd80501 | 2015-10-28 11:45:00 -0500 | [diff] [blame] | 2836 | #else |
| 2837 | list_is_dirs = (override == NULL || is_layer) ? true : false; |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2838 | #endif |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2839 | // Make a copy of the input we are using so it is not modified |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2840 | // Also handle getting the location(s) from registry on Windows |
| 2841 | if (override == NULL) { |
Jon Ashburn | 3b78e46 | 2015-07-31 10:11:24 -0600 | [diff] [blame] | 2842 | loc = loader_stack_alloc(strlen(location) + 1); |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2843 | if (loc == NULL) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2844 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2845 | "loader_get_manifest_files: Failed to allocate " |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 2846 | "%d bytes for manifest file location.", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2847 | strlen(location)); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2848 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 2849 | goto out; |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2850 | } |
| 2851 | strcpy(loc, location); |
Johannes van Waveren | 9bd80501 | 2015-10-28 11:45:00 -0500 | [diff] [blame] | 2852 | #if defined(_WIN32) |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 2853 | VkResult reg_result = loaderGetRegistryFiles(inst, loc, ®); |
| 2854 | if (VK_SUCCESS != reg_result || NULL == reg) { |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 2855 | if (!is_layer) { |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 2856 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 2857 | "loader_get_manifest_files: Registry lookup failed " |
| 2858 | "to get ICD manifest files. Possibly missing Vulkan" |
| 2859 | " driver?"); |
| 2860 | if (VK_SUCCESS == reg_result || |
| 2861 | VK_ERROR_OUT_OF_HOST_MEMORY == reg_result) { |
| 2862 | res = reg_result; |
| 2863 | } else { |
| 2864 | res = VK_ERROR_INCOMPATIBLE_DRIVER; |
| 2865 | } |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 2866 | } else { |
Mark Young | f8c2010 | 2016-11-07 16:26:17 -0700 | [diff] [blame] | 2867 | if (warn_if_not_present) { |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 2868 | // This is only a warning for layers |
Mark Young | f8c2010 | 2016-11-07 16:26:17 -0700 | [diff] [blame] | 2869 | loader_log( |
| 2870 | inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2871 | "loader_get_manifest_files: Registry lookup failed " |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 2872 | "to get layer manifest files."); |
Mark Young | f8c2010 | 2016-11-07 16:26:17 -0700 | [diff] [blame] | 2873 | } |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 2874 | if (reg_result == VK_ERROR_OUT_OF_HOST_MEMORY) { |
| 2875 | res = reg_result; |
| 2876 | } else { |
| 2877 | // Return success for now since it's not critical for layers |
| 2878 | res = VK_SUCCESS; |
| 2879 | } |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 2880 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2881 | goto out; |
Jon Ashburn | 24265ac | 2015-07-31 09:33:21 -0600 | [diff] [blame] | 2882 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2883 | orig_loc = loc; |
| 2884 | loc = reg; |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2885 | #endif |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2886 | } else { |
Courtney Goeltzenleuchter | 7f5aafc | 2015-07-05 11:28:29 -0600 | [diff] [blame] | 2887 | loc = loader_stack_alloc(strlen(override) + 1); |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2888 | if (loc == NULL) { |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2889 | loader_log( |
| 2890 | inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 2891 | "loader_get_manifest_files: Failed to allocate space for " |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 2892 | "override environment variable of length %d", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2893 | strlen(override) + 1); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2894 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 2895 | goto out; |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2896 | } |
| 2897 | strcpy(loc, override); |
| 2898 | } |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2899 | |
Liam Middlebrook | 9b14e89 | 2015-07-23 18:32:20 -0700 | [diff] [blame] | 2900 | // Print out the paths being searched if debugging is enabled |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2901 | loader_log(inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, |
| 2902 | "Searching the following paths for manifest files: %s\n", loc); |
Liam Middlebrook | 9b14e89 | 2015-07-23 18:32:20 -0700 | [diff] [blame] | 2903 | |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2904 | file = loc; |
| 2905 | while (*file) { |
| 2906 | next_file = loader_get_next_path(file); |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2907 | if (list_is_dirs) { |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2908 | sysdir = opendir(file); |
| 2909 | name = NULL; |
| 2910 | if (sysdir) { |
| 2911 | dent = readdir(sysdir); |
| 2912 | if (dent == NULL) |
| 2913 | break; |
| 2914 | name = &(dent->d_name[0]); |
| 2915 | loader_get_fullpath(name, file, sizeof(full_path), full_path); |
| 2916 | name = full_path; |
| 2917 | } |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2918 | } else { |
Johannes van Waveren | 9bd80501 | 2015-10-28 11:45:00 -0500 | [diff] [blame] | 2919 | #if defined(_WIN32) |
| 2920 | name = file; |
| 2921 | #else |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2922 | // only Linux has relative paths |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2923 | char *dir; |
| 2924 | // make a copy of location so it isn't modified |
Jason Ekstrand | cc7550e | 2015-10-10 08:33:37 -0700 | [diff] [blame] | 2925 | dir = loader_stack_alloc(strlen(loc) + 1); |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2926 | if (dir == NULL) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2927 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2928 | "loader_get_manifest_files: Failed to allocate " |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 2929 | "space for relative location path length %d", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2930 | strlen(loc) + 1); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2931 | goto out; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2932 | } |
Jason Ekstrand | cc7550e | 2015-10-10 08:33:37 -0700 | [diff] [blame] | 2933 | strcpy(dir, loc); |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2934 | |
| 2935 | loader_get_fullpath(file, dir, sizeof(full_path), full_path); |
| 2936 | |
| 2937 | name = full_path; |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2938 | #endif |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2939 | } |
| 2940 | while (name) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2941 | /* Look for files ending with ".json" suffix */ |
| 2942 | uint32_t nlen = (uint32_t)strlen(name); |
| 2943 | const char *suf = name + nlen - 5; |
| 2944 | if ((nlen > 5) && !strncmp(suf, ".json", 5)) { |
| 2945 | if (out_files->count == 0) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2946 | out_files->filename_list = loader_instance_heap_alloc( |
| 2947 | inst, alloced_count * sizeof(char *), |
| 2948 | VK_SYSTEM_ALLOCATION_SCOPE_COMMAND); |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2949 | } else if (out_files->count == alloced_count) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2950 | out_files->filename_list = loader_instance_heap_realloc( |
| 2951 | inst, out_files->filename_list, |
| 2952 | alloced_count * sizeof(char *), |
| 2953 | alloced_count * sizeof(char *) * 2, |
| 2954 | VK_SYSTEM_ALLOCATION_SCOPE_COMMAND); |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2955 | alloced_count *= 2; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2956 | } |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2957 | if (out_files->filename_list == NULL) { |
| 2958 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2959 | "loader_get_manifest_files: Failed to allocate " |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 2960 | "space for manifest file name list"); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2961 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 2962 | goto out; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2963 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2964 | out_files->filename_list[out_files->count] = |
| 2965 | loader_instance_heap_alloc( |
| 2966 | inst, strlen(name) + 1, |
| 2967 | VK_SYSTEM_ALLOCATION_SCOPE_COMMAND); |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2968 | if (out_files->filename_list[out_files->count] == NULL) { |
| 2969 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2970 | "loader_get_manifest_files: Failed to allocate " |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 2971 | "space for manifest file %d list", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2972 | out_files->count); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2973 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 2974 | goto out; |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2975 | } |
| 2976 | strcpy(out_files->filename_list[out_files->count], name); |
| 2977 | out_files->count++; |
| 2978 | } else if (!list_is_dirs) { |
| 2979 | loader_log( |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 2980 | inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2981 | "Skipping manifest file %s, file name must end in .json", |
| 2982 | name); |
| 2983 | } |
| 2984 | if (list_is_dirs) { |
| 2985 | dent = readdir(sysdir); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2986 | if (dent == NULL) { |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2987 | break; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2988 | } |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2989 | name = &(dent->d_name[0]); |
| 2990 | loader_get_fullpath(name, file, sizeof(full_path), full_path); |
| 2991 | name = full_path; |
| 2992 | } else { |
| 2993 | break; |
| 2994 | } |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2995 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2996 | if (sysdir) { |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2997 | closedir(sysdir); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2998 | sysdir = NULL; |
| 2999 | } |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3000 | file = next_file; |
Jon Ashburn | 67e262e | 2016-02-18 12:45:39 -0700 | [diff] [blame] | 3001 | #if !defined(_WIN32) |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 3002 | if (home_location != NULL && |
| 3003 | (next_file == NULL || *next_file == '\0') && override == NULL) { |
John Drinkwater | 9ac3f4f | 2016-08-01 17:00:00 +0100 | [diff] [blame] | 3004 | char *xdgdatahome = secure_getenv("XDG_DATA_HOME"); |
| 3005 | size_t len; |
| 3006 | if (xdgdatahome != NULL) { |
| 3007 | |
| 3008 | char *home_loc = loader_stack_alloc(strlen(xdgdatahome) + 2 + |
Jon Ashburn | 67e262e | 2016-02-18 12:45:39 -0700 | [diff] [blame] | 3009 | strlen(home_location)); |
| 3010 | if (home_loc == NULL) { |
| 3011 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3012 | "loader_get_manifest_files: Failed to allocate " |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 3013 | "space for manifest file XDG Home location"); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3014 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 3015 | goto out; |
Jon Ashburn | 67e262e | 2016-02-18 12:45:39 -0700 | [diff] [blame] | 3016 | } |
John Drinkwater | 9ac3f4f | 2016-08-01 17:00:00 +0100 | [diff] [blame] | 3017 | strcpy(home_loc, xdgdatahome); |
Jon Ashburn | 67e262e | 2016-02-18 12:45:39 -0700 | [diff] [blame] | 3018 | // Add directory separator if needed |
| 3019 | if (home_location[0] != DIRECTORY_SYMBOL) { |
| 3020 | len = strlen(home_loc); |
| 3021 | home_loc[len] = DIRECTORY_SYMBOL; |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 3022 | home_loc[len + 1] = '\0'; |
Jon Ashburn | 67e262e | 2016-02-18 12:45:39 -0700 | [diff] [blame] | 3023 | } |
| 3024 | strcat(home_loc, home_location); |
| 3025 | file = home_loc; |
| 3026 | next_file = loader_get_next_path(file); |
| 3027 | home_location = NULL; |
| 3028 | |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 3029 | loader_log( |
| 3030 | inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, |
John Drinkwater | 9ac3f4f | 2016-08-01 17:00:00 +0100 | [diff] [blame] | 3031 | "Searching the following path for manifest files: %s\n", |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 3032 | home_loc); |
Jon Ashburn | 67e262e | 2016-02-18 12:45:39 -0700 | [diff] [blame] | 3033 | list_is_dirs = true; |
John Drinkwater | 9ac3f4f | 2016-08-01 17:00:00 +0100 | [diff] [blame] | 3034 | |
| 3035 | } else { |
| 3036 | |
| 3037 | char *home = secure_getenv("HOME"); |
| 3038 | if (home != NULL) { |
| 3039 | char *home_loc = loader_stack_alloc(strlen(home) + 16 + |
| 3040 | strlen(home_location)); |
| 3041 | if (home_loc == NULL) { |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3042 | loader_log( |
| 3043 | inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 3044 | "loader_get_manifest_files: Failed to allocate " |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 3045 | "space for manifest file Home location"); |
John Drinkwater | 9ac3f4f | 2016-08-01 17:00:00 +0100 | [diff] [blame] | 3046 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 3047 | goto out; |
| 3048 | } |
| 3049 | strcpy(home_loc, home); |
| 3050 | |
| 3051 | len = strlen(home); |
| 3052 | if (home[len] != DIRECTORY_SYMBOL) { |
| 3053 | home_loc[len] = DIRECTORY_SYMBOL; |
| 3054 | home_loc[len + 1] = '\0'; |
| 3055 | } |
| 3056 | strcat(home_loc, ".local/share"); |
| 3057 | |
| 3058 | if (home_location[0] != DIRECTORY_SYMBOL) { |
| 3059 | len = strlen(home_loc); |
| 3060 | home_loc[len] = DIRECTORY_SYMBOL; |
| 3061 | home_loc[len + 1] = '\0'; |
| 3062 | } |
| 3063 | strcat(home_loc, home_location); |
| 3064 | file = home_loc; |
| 3065 | next_file = loader_get_next_path(file); |
| 3066 | home_location = NULL; |
| 3067 | |
| 3068 | loader_log( |
| 3069 | inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, |
| 3070 | "Searching the following path for manifest files: %s\n", |
| 3071 | home_loc); |
| 3072 | list_is_dirs = true; |
| 3073 | } else { |
| 3074 | // without knowing HOME, we just.. give up |
| 3075 | } |
Jon Ashburn | 67e262e | 2016-02-18 12:45:39 -0700 | [diff] [blame] | 3076 | } |
| 3077 | } |
| 3078 | #endif |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3079 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3080 | |
| 3081 | out: |
| 3082 | if (VK_SUCCESS != res && NULL != out_files->filename_list) { |
| 3083 | for (uint32_t remove = 0; remove < out_files->count; remove++) { |
| 3084 | loader_instance_heap_free(inst, out_files->filename_list[remove]); |
| 3085 | } |
| 3086 | loader_instance_heap_free(inst, out_files->filename_list); |
| 3087 | out_files->count = 0; |
| 3088 | out_files->filename_list = NULL; |
| 3089 | } |
| 3090 | |
| 3091 | if (NULL != sysdir) { |
| 3092 | closedir(sysdir); |
| 3093 | } |
| 3094 | |
Frank Henigman | b1c27cb | 2016-11-24 20:02:09 -0500 | [diff] [blame] | 3095 | if (override_getenv != NULL) { |
| 3096 | loader_free_getenv(override_getenv, inst); |
| 3097 | } |
| 3098 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3099 | if (NULL != reg && reg != orig_loc) { |
| 3100 | loader_instance_heap_free(inst, reg); |
| 3101 | } |
| 3102 | return res; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3103 | } |
| 3104 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3105 | void loader_init_icd_lib_list() {} |
Jon Ashburn | 8810c5f | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 3106 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3107 | void loader_destroy_icd_lib_list() {} |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3108 | /** |
| 3109 | * Try to find the Vulkan ICD driver(s). |
| 3110 | * |
| 3111 | * This function scans the default system loader path(s) or path |
| 3112 | * specified by the \c VK_ICD_FILENAMES environment variable in |
| 3113 | * order to find loadable VK ICDs manifest files. From these |
| 3114 | * manifest files it finds the ICD libraries. |
| 3115 | * |
| 3116 | * \returns |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3117 | * Vulkan result |
| 3118 | * (on result == VK_SUCCESS) a list of icds that were discovered |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 3119 | */ |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3120 | VkResult loader_icd_scan(const struct loader_instance *inst, |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 3121 | struct loader_icd_tramp_list *icd_tramp_list) { |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3122 | char *file_str; |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 3123 | uint16_t file_major_vers = 0; |
| 3124 | uint16_t file_minor_vers = 0; |
| 3125 | uint16_t file_patch_vers = 0; |
| 3126 | char *vers_tok; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3127 | struct loader_manifest_files manifest_files; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3128 | VkResult res = VK_SUCCESS; |
| 3129 | bool lockedMutex = false; |
| 3130 | cJSON *json = NULL; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3131 | uint32_t num_good_icds = 0; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3132 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3133 | memset(&manifest_files, 0, sizeof(struct loader_manifest_files)); |
| 3134 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 3135 | res = loader_scanned_icd_init(inst, icd_tramp_list); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3136 | if (VK_SUCCESS != res) { |
| 3137 | goto out; |
| 3138 | } |
| 3139 | |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3140 | // Get a list of manifest files for ICDs |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3141 | res = loader_get_manifest_files(inst, "VK_ICD_FILENAMES", NULL, false, |
Mark Young | f8c2010 | 2016-11-07 16:26:17 -0700 | [diff] [blame] | 3142 | true, DEFAULT_VK_DRIVERS_INFO, |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3143 | HOME_VK_DRIVERS_INFO, &manifest_files); |
| 3144 | if (VK_SUCCESS != res || manifest_files.count == 0) { |
| 3145 | goto out; |
| 3146 | } |
Jon Ashburn | 6461ef2 | 2015-09-22 13:11:00 -0600 | [diff] [blame] | 3147 | loader_platform_thread_lock_mutex(&loader_json_lock); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3148 | lockedMutex = true; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3149 | for (uint32_t i = 0; i < manifest_files.count; i++) { |
| 3150 | file_str = manifest_files.filename_list[i]; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3151 | if (file_str == NULL) { |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3152 | continue; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3153 | } |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3154 | |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3155 | res = loader_get_json(inst, file_str, &json); |
| 3156 | if (VK_ERROR_OUT_OF_HOST_MEMORY == res) { |
| 3157 | break; |
| 3158 | } else if (VK_SUCCESS != res || NULL == json) { |
Jon Ashburn | aa4ea47 | 2015-08-27 08:30:50 -0600 | [diff] [blame] | 3159 | continue; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3160 | } |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3161 | |
Jon Ashburn | 005617f | 2015-11-17 17:35:40 -0700 | [diff] [blame] | 3162 | cJSON *item, *itemICD; |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 3163 | item = cJSON_GetObjectItem(json, "file_format_version"); |
Jon Ashburn | 6461ef2 | 2015-09-22 13:11:00 -0600 | [diff] [blame] | 3164 | if (item == NULL) { |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3165 | if (num_good_icds == 0) { |
| 3166 | res = VK_ERROR_INITIALIZATION_FAILED; |
| 3167 | } |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3168 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 3169 | "loader_icd_scan: ICD JSON %s does not have a" |
| 3170 | " \'file_format_version\' field. Skipping ICD JSON.", |
| 3171 | file_str); |
Derrick Owens | 62e16ef | 2016-09-09 15:49:07 -0400 | [diff] [blame] | 3172 | cJSON_Delete(json); |
| 3173 | json = NULL; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3174 | continue; |
Jon Ashburn | 6461ef2 | 2015-09-22 13:11:00 -0600 | [diff] [blame] | 3175 | } |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 3176 | char *file_vers = cJSON_Print(item); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3177 | if (NULL == file_vers) { |
| 3178 | // Only reason the print can fail is if there was an allocation |
| 3179 | // issue |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3180 | if (num_good_icds == 0) { |
| 3181 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 3182 | } |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3183 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 3184 | "loader_icd_scan: Failed retrieving ICD JSON %s" |
| 3185 | " \'file_format_version\' field. Skipping ICD JSON", |
| 3186 | file_str); |
Derrick Owens | cd92b8b | 2016-09-09 15:45:13 -0400 | [diff] [blame] | 3187 | cJSON_Delete(json); |
| 3188 | json = NULL; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3189 | continue; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3190 | } |
Mark Young | cbcbf89 | 2016-06-22 15:25:00 -0600 | [diff] [blame] | 3191 | loader_log(inst, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3192 | "Found ICD manifest file %s, version %s", file_str, |
| 3193 | file_vers); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 3194 | // Get the major/minor/and patch as integers for easier comparison |
| 3195 | vers_tok = strtok(file_vers, ".\"\n\r"); |
| 3196 | if (NULL != vers_tok) { |
Jamie Madill | 970ebcf | 2016-07-06 11:19:42 -0400 | [diff] [blame] | 3197 | file_major_vers = (uint16_t)atoi(vers_tok); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 3198 | vers_tok = strtok(NULL, ".\"\n\r"); |
| 3199 | if (NULL != vers_tok) { |
Jamie Madill | 970ebcf | 2016-07-06 11:19:42 -0400 | [diff] [blame] | 3200 | file_minor_vers = (uint16_t)atoi(vers_tok); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 3201 | vers_tok = strtok(NULL, ".\"\n\r"); |
| 3202 | if (NULL != vers_tok) { |
Jamie Madill | 970ebcf | 2016-07-06 11:19:42 -0400 | [diff] [blame] | 3203 | file_patch_vers = (uint16_t)atoi(vers_tok); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 3204 | } |
| 3205 | } |
| 3206 | } |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 3207 | if (file_major_vers != 1 || file_minor_vers != 0 || file_patch_vers > 1) |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 3208 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3209 | "loader_icd_scan: Unexpected manifest file version " |
| 3210 | "(expected 1.0.0 or 1.0.1), may cause errors"); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3211 | cJSON_Free(file_vers); |
Jon Ashburn | 005617f | 2015-11-17 17:35:40 -0700 | [diff] [blame] | 3212 | itemICD = cJSON_GetObjectItem(json, "ICD"); |
| 3213 | if (itemICD != NULL) { |
| 3214 | item = cJSON_GetObjectItem(itemICD, "library_path"); |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 3215 | if (item != NULL) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3216 | char *temp = cJSON_Print(item); |
Jon Ashburn | 8625130 | 2015-08-25 16:48:24 -0600 | [diff] [blame] | 3217 | if (!temp || strlen(temp) == 0) { |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3218 | if (num_good_icds == 0) { |
| 3219 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 3220 | } |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3221 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 3222 | "loader_icd_scan: Failed retrieving ICD JSON %s" |
| 3223 | " \'library_path\' field. Skipping ICD JSON.", |
| 3224 | file_str); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3225 | cJSON_Free(temp); |
Jon Ashburn | 8625130 | 2015-08-25 16:48:24 -0600 | [diff] [blame] | 3226 | cJSON_Delete(json); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3227 | json = NULL; |
Jon Ashburn | 8625130 | 2015-08-25 16:48:24 -0600 | [diff] [blame] | 3228 | continue; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3229 | } |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3230 | // strip out extra quotes |
Jon Ashburn | 8625130 | 2015-08-25 16:48:24 -0600 | [diff] [blame] | 3231 | temp[strlen(temp) - 1] = '\0'; |
| 3232 | char *library_path = loader_stack_alloc(strlen(temp) + 1); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3233 | if (NULL == library_path) { |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3234 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 3235 | "loader_icd_scan: Failed to allocate space for " |
| 3236 | "ICD JSON %s \'library_path\' value. Skipping " |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 3237 | "ICD JSON.", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3238 | file_str); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3239 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 3240 | cJSON_Free(temp); |
| 3241 | cJSON_Delete(json); |
| 3242 | json = NULL; |
| 3243 | goto out; |
| 3244 | } |
Jon Ashburn | 8625130 | 2015-08-25 16:48:24 -0600 | [diff] [blame] | 3245 | strcpy(library_path, &temp[1]); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3246 | cJSON_Free(temp); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3247 | if (strlen(library_path) == 0) { |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 3248 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3249 | "loader_icd_scan: ICD JSON %s \'library_path\'" |
| 3250 | " field is empty. Skipping ICD JSON.", |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3251 | file_str); |
Jon Ashburn | 8625130 | 2015-08-25 16:48:24 -0600 | [diff] [blame] | 3252 | cJSON_Delete(json); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3253 | json = NULL; |
Jon Ashburn | 8625130 | 2015-08-25 16:48:24 -0600 | [diff] [blame] | 3254 | continue; |
| 3255 | } |
Jamie Madill | 2fcbd15 | 2016-04-27 16:33:23 -0400 | [diff] [blame] | 3256 | char fullpath[MAX_STRING_SIZE]; |
Jon Ashburn | 8625130 | 2015-08-25 16:48:24 -0600 | [diff] [blame] | 3257 | // Print out the paths being searched if debugging is enabled |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3258 | loader_log( |
| 3259 | inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3260 | "Searching for ICD drivers named %s, using default dir %s", |
Jamie Madill | 2fcbd15 | 2016-04-27 16:33:23 -0400 | [diff] [blame] | 3261 | library_path, DEFAULT_VK_DRIVERS_PATH); |
Daniel Dadap | 00b4aba | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 3262 | if (loader_platform_is_path(library_path)) { |
Jon Ashburn | 8625130 | 2015-08-25 16:48:24 -0600 | [diff] [blame] | 3263 | // a relative or absolute path |
Daniel Dadap | 00b4aba | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 3264 | char *name_copy = loader_stack_alloc(strlen(file_str) + 1); |
| 3265 | char *rel_base; |
Jon Ashburn | 8625130 | 2015-08-25 16:48:24 -0600 | [diff] [blame] | 3266 | strcpy(name_copy, file_str); |
| 3267 | rel_base = loader_platform_dirname(name_copy); |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3268 | loader_expand_path(library_path, rel_base, sizeof(fullpath), |
| 3269 | fullpath); |
Daniel Dadap | 00b4aba | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 3270 | } else { |
Jamie Madill | 2fcbd15 | 2016-04-27 16:33:23 -0400 | [diff] [blame] | 3271 | // a filename which is assumed in a system directory |
| 3272 | loader_get_fullpath(library_path, DEFAULT_VK_DRIVERS_PATH, |
| 3273 | sizeof(fullpath), fullpath); |
Jon Ashburn | 8625130 | 2015-08-25 16:48:24 -0600 | [diff] [blame] | 3274 | } |
Jon Ashburn | 005617f | 2015-11-17 17:35:40 -0700 | [diff] [blame] | 3275 | |
| 3276 | uint32_t vers = 0; |
| 3277 | item = cJSON_GetObjectItem(itemICD, "api_version"); |
| 3278 | if (item != NULL) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3279 | temp = cJSON_Print(item); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3280 | if (NULL == temp) { |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3281 | loader_log( |
| 3282 | inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 3283 | "loader_icd_scan: Failed retrieving ICD JSON %s" |
| 3284 | " \'api_version\' field. Skipping ICD JSON.", |
| 3285 | file_str); |
| 3286 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3287 | // Only reason the print can fail is if there was an |
| 3288 | // allocation issue |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3289 | if (num_good_icds == 0) { |
| 3290 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 3291 | } |
| 3292 | |
| 3293 | cJSON_Free(temp); |
| 3294 | cJSON_Delete(json); |
| 3295 | json = NULL; |
| 3296 | continue; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3297 | } |
Jon Ashburn | 005617f | 2015-11-17 17:35:40 -0700 | [diff] [blame] | 3298 | vers = loader_make_version(temp); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3299 | cJSON_Free(temp); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3300 | } else { |
| 3301 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 3302 | "loader_icd_scan: ICD JSON %s does not have an" |
| 3303 | " \'api_version\' field.", |
| 3304 | file_str); |
Jon Ashburn | 005617f | 2015-11-17 17:35:40 -0700 | [diff] [blame] | 3305 | } |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3306 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 3307 | res = loader_scanned_icd_add(inst, icd_tramp_list, fullpath, |
| 3308 | vers); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3309 | if (VK_SUCCESS != res) { |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3310 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 3311 | "loader_icd_scan: Failed to add ICD JSON %s. " |
| 3312 | " Skipping ICD JSON.", |
| 3313 | fullpath); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3314 | continue; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3315 | } |
| 3316 | num_good_icds++; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3317 | } else { |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 3318 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3319 | "loader_icd_scan: Failed to find \'library_path\' " |
| 3320 | "object in ICD JSON file %s. Skipping ICD JSON.", |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3321 | file_str); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3322 | } |
| 3323 | } else { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3324 | loader_log( |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 3325 | inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3326 | "loader_icd_scan: Can not find \'ICD\' object in ICD JSON " |
| 3327 | "file %s. Skipping ICD JSON", |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3328 | file_str); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3329 | } |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3330 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3331 | cJSON_Delete(json); |
| 3332 | json = NULL; |
| 3333 | } |
| 3334 | |
| 3335 | out: |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3336 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3337 | if (NULL != json) { |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3338 | cJSON_Delete(json); |
| 3339 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3340 | if (NULL != manifest_files.filename_list) { |
| 3341 | for (uint32_t i = 0; i < manifest_files.count; i++) { |
| 3342 | if (NULL != manifest_files.filename_list[i]) { |
| 3343 | loader_instance_heap_free(inst, |
| 3344 | manifest_files.filename_list[i]); |
| 3345 | } |
| 3346 | } |
| 3347 | loader_instance_heap_free(inst, manifest_files.filename_list); |
| 3348 | } |
| 3349 | if (lockedMutex) { |
| 3350 | loader_platform_thread_unlock_mutex(&loader_json_lock); |
| 3351 | } |
| 3352 | return res; |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 3353 | } |
| 3354 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3355 | void loader_layer_scan(const struct loader_instance *inst, |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 3356 | struct loader_layer_list *instance_layers) { |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 3357 | char *file_str; |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3358 | struct loader_manifest_files |
| 3359 | manifest_files[2]; // [0] = explicit, [1] = implicit |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 3360 | cJSON *json; |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3361 | uint32_t implicit; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3362 | bool lockedMutex = false; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 3363 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3364 | memset(manifest_files, 0, sizeof(struct loader_manifest_files) * 2); |
| 3365 | |
| 3366 | // Get a list of manifest files for explicit layers |
| 3367 | if (VK_SUCCESS != |
| 3368 | loader_get_manifest_files(inst, LAYERS_PATH_ENV, LAYERS_SOURCE_PATH, |
Mark Young | f8c2010 | 2016-11-07 16:26:17 -0700 | [diff] [blame] | 3369 | true, true, DEFAULT_VK_ELAYERS_INFO, |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3370 | HOME_VK_ELAYERS_INFO, &manifest_files[0])) { |
| 3371 | goto out; |
| 3372 | } |
| 3373 | |
| 3374 | // Get a list of manifest files for any implicit layers |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3375 | // Pass NULL for environment variable override - implicit layers are not |
| 3376 | // overridden by LAYERS_PATH_ENV |
Mark Young | f8c2010 | 2016-11-07 16:26:17 -0700 | [diff] [blame] | 3377 | if (VK_SUCCESS != loader_get_manifest_files(inst, NULL, NULL, true, false, |
| 3378 | DEFAULT_VK_ILAYERS_INFO, |
| 3379 | HOME_VK_ILAYERS_INFO, |
| 3380 | &manifest_files[1])) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3381 | goto out; |
| 3382 | } |
Jon Ashburn | 90c6a0e | 2015-06-04 15:30:58 -0600 | [diff] [blame] | 3383 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3384 | // Make sure we have at least one layer, if not, go ahead and return |
| 3385 | if (manifest_files[0].count == 0 && manifest_files[1].count == 0) { |
| 3386 | goto out; |
| 3387 | } |
| 3388 | |
| 3389 | // cleanup any previously scanned libraries |
Jon Ashburn | e39a4f8 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 3390 | loader_delete_layer_properties(inst, instance_layers); |
Jon Ashburn | b2ef137 | 2015-07-16 17:19:31 -0600 | [diff] [blame] | 3391 | |
Jon Ashburn | 6461ef2 | 2015-09-22 13:11:00 -0600 | [diff] [blame] | 3392 | loader_platform_thread_lock_mutex(&loader_json_lock); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3393 | lockedMutex = true; |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3394 | for (implicit = 0; implicit < 2; implicit++) { |
Jamie Madill | 970ebcf | 2016-07-06 11:19:42 -0400 | [diff] [blame] | 3395 | for (uint32_t i = 0; i < manifest_files[implicit].count; i++) { |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3396 | file_str = manifest_files[implicit].filename_list[i]; |
| 3397 | if (file_str == NULL) |
| 3398 | continue; |
Courtney Goeltzenleuchter | a9e4af4 | 2015-06-01 14:49:17 -0600 | [diff] [blame] | 3399 | |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3400 | // parse file into JSON struct |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3401 | VkResult res = loader_get_json(inst, file_str, &json); |
| 3402 | if (VK_ERROR_OUT_OF_HOST_MEMORY == res) { |
| 3403 | break; |
| 3404 | } else if (VK_SUCCESS != res || NULL == json) { |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3405 | continue; |
| 3406 | } |
| 3407 | |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 3408 | loader_add_layer_properties(inst, instance_layers, json, |
| 3409 | (implicit == 1), file_str); |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3410 | cJSON_Delete(json); |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 3411 | } |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 3412 | } |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 3413 | |
| 3414 | // add a meta layer for validation if the validation layers are all present |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3415 | loader_add_layer_property_meta(inst, sizeof(std_validation_names) / |
| 3416 | sizeof(std_validation_names[0]), |
| 3417 | std_validation_names, instance_layers); |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 3418 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3419 | out: |
| 3420 | |
| 3421 | for (uint32_t manFile = 0; manFile < 2; manFile++) { |
| 3422 | if (NULL != manifest_files[manFile].filename_list) { |
| 3423 | for (uint32_t i = 0; i < manifest_files[manFile].count; i++) { |
| 3424 | if (NULL != manifest_files[manFile].filename_list[i]) { |
| 3425 | loader_instance_heap_free( |
| 3426 | inst, manifest_files[manFile].filename_list[i]); |
| 3427 | } |
| 3428 | } |
| 3429 | loader_instance_heap_free(inst, |
| 3430 | manifest_files[manFile].filename_list); |
| 3431 | } |
| 3432 | } |
| 3433 | if (lockedMutex) { |
| 3434 | loader_platform_thread_unlock_mutex(&loader_json_lock); |
| 3435 | } |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 3436 | } |
| 3437 | |
Jeremy Hayes | 3e2bd5a | 2016-04-01 11:40:26 -0600 | [diff] [blame] | 3438 | void loader_implicit_layer_scan(const struct loader_instance *inst, |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 3439 | struct loader_layer_list *instance_layers) { |
Jeremy Hayes | 3e2bd5a | 2016-04-01 11:40:26 -0600 | [diff] [blame] | 3440 | char *file_str; |
| 3441 | struct loader_manifest_files manifest_files; |
| 3442 | cJSON *json; |
| 3443 | uint32_t i; |
| 3444 | |
| 3445 | // Pass NULL for environment variable override - implicit layers are not |
| 3446 | // overridden by LAYERS_PATH_ENV |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3447 | VkResult res = loader_get_manifest_files( |
Mark Young | f8c2010 | 2016-11-07 16:26:17 -0700 | [diff] [blame] | 3448 | inst, NULL, NULL, true, false, DEFAULT_VK_ILAYERS_INFO, |
| 3449 | HOME_VK_ILAYERS_INFO, &manifest_files); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3450 | if (VK_SUCCESS != res || manifest_files.count == 0) { |
Jeremy Hayes | 3e2bd5a | 2016-04-01 11:40:26 -0600 | [diff] [blame] | 3451 | return; |
| 3452 | } |
| 3453 | |
| 3454 | /* cleanup any previously scanned libraries */ |
| 3455 | loader_delete_layer_properties(inst, instance_layers); |
Jeremy Hayes | 3e2bd5a | 2016-04-01 11:40:26 -0600 | [diff] [blame] | 3456 | |
| 3457 | loader_platform_thread_lock_mutex(&loader_json_lock); |
| 3458 | |
| 3459 | for (i = 0; i < manifest_files.count; i++) { |
| 3460 | file_str = manifest_files.filename_list[i]; |
| 3461 | if (file_str == NULL) { |
| 3462 | continue; |
| 3463 | } |
| 3464 | |
| 3465 | // parse file into JSON struct |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3466 | res = loader_get_json(inst, file_str, &json); |
| 3467 | if (VK_ERROR_OUT_OF_HOST_MEMORY == res) { |
| 3468 | break; |
| 3469 | } else if (VK_SUCCESS != res || NULL == json) { |
Jeremy Hayes | 3e2bd5a | 2016-04-01 11:40:26 -0600 | [diff] [blame] | 3470 | continue; |
| 3471 | } |
| 3472 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3473 | loader_add_layer_properties(inst, instance_layers, json, true, |
| 3474 | file_str); |
Jeremy Hayes | 3e2bd5a | 2016-04-01 11:40:26 -0600 | [diff] [blame] | 3475 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3476 | loader_instance_heap_free(inst, file_str); |
Jeremy Hayes | 3e2bd5a | 2016-04-01 11:40:26 -0600 | [diff] [blame] | 3477 | cJSON_Delete(json); |
| 3478 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3479 | loader_instance_heap_free(inst, manifest_files.filename_list); |
Jeremy Hayes | 3e2bd5a | 2016-04-01 11:40:26 -0600 | [diff] [blame] | 3480 | |
| 3481 | // add a meta layer for validation if the validation layers are all present |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3482 | loader_add_layer_property_meta(inst, sizeof(std_validation_names) / |
| 3483 | sizeof(std_validation_names[0]), |
| 3484 | std_validation_names, instance_layers); |
Jeremy Hayes | 3e2bd5a | 2016-04-01 11:40:26 -0600 | [diff] [blame] | 3485 | |
| 3486 | loader_platform_thread_unlock_mutex(&loader_json_lock); |
| 3487 | } |
| 3488 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3489 | static VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL |
| 3490 | loader_gpa_instance_internal(VkInstance inst, const char *pName) { |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3491 | if (!strcmp(pName, "vkGetInstanceProcAddr")) |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3492 | return (void *)loader_gpa_instance_internal; |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3493 | if (!strcmp(pName, "vkCreateInstance")) |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 3494 | return (void *)terminator_CreateInstance; |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3495 | if (!strcmp(pName, "vkCreateDevice")) |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 3496 | return (void *)terminator_CreateDevice; |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3497 | |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 3498 | // inst is not wrapped |
| 3499 | if (inst == VK_NULL_HANDLE) { |
| 3500 | return NULL; |
| 3501 | } |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3502 | VkLayerInstanceDispatchTable *disp_table = |
| 3503 | *(VkLayerInstanceDispatchTable **)inst; |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 3504 | void *addr; |
| 3505 | |
| 3506 | if (disp_table == NULL) |
| 3507 | return NULL; |
| 3508 | |
Jon Ashburn | c7d3e73 | 2016-03-08 09:30:30 -0700 | [diff] [blame] | 3509 | bool found_name; |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 3510 | addr = |
| 3511 | loader_lookup_instance_dispatch_table(disp_table, pName, &found_name); |
Jon Ashburn | c7d3e73 | 2016-03-08 09:30:30 -0700 | [diff] [blame] | 3512 | if (found_name) { |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 3513 | return addr; |
Jon Ashburn | 3d526cb | 2015-04-13 18:10:06 -0600 | [diff] [blame] | 3514 | } |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3515 | |
Jon Ashburn | c7d3e73 | 2016-03-08 09:30:30 -0700 | [diff] [blame] | 3516 | // Don't call down the chain, this would be an infinite loop |
| 3517 | loader_log(NULL, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 3518 | "loader_gpa_instance_internal() unrecognized name %s", pName); |
Jon Ashburn | c7d3e73 | 2016-03-08 09:30:30 -0700 | [diff] [blame] | 3519 | return NULL; |
Jon Ashburn | 3d526cb | 2015-04-13 18:10:06 -0600 | [diff] [blame] | 3520 | } |
| 3521 | |
Piers Daniell | f9262be | 2016-09-14 11:24:36 -0600 | [diff] [blame] | 3522 | VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 3523 | loader_gpa_device_internal(VkDevice device, const char *pName) { |
| 3524 | struct loader_device *dev; |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 3525 | struct loader_icd_term *icd_term = |
| 3526 | loader_get_icd_and_device(device, &dev, NULL); |
Mark Young | 16573c7 | 2016-06-28 10:52:43 -0600 | [diff] [blame] | 3527 | |
Mark Young | 65cb366 | 2016-11-07 13:27:02 -0700 | [diff] [blame] | 3528 | // NOTE: Device Funcs needing Trampoline/Terminator. |
| 3529 | // Overrides for device functions needing a trampoline and |
| 3530 | // a terminator because certain device entry-points still need to go |
| 3531 | // through a terminator before hitting the ICD. This could be for |
| 3532 | // several reasons, but the main one is currently unwrapping an |
| 3533 | // object before passing the appropriate info along to the ICD. |
| 3534 | // This is why we also have to override the direct ICD call to |
| 3535 | // vkGetDeviceProcAddr to intercept those calls. |
| 3536 | if (!strcmp(pName, "vkGetDeviceProcAddr")) { |
| 3537 | return (PFN_vkVoidFunction)loader_gpa_device_internal; |
| 3538 | } else if (!strcmp(pName, "vkCreateSwapchainKHR")) { |
Mark Young | 16573c7 | 2016-06-28 10:52:43 -0600 | [diff] [blame] | 3539 | return (PFN_vkVoidFunction)terminator_vkCreateSwapchainKHR; |
Mark Young | 65cb366 | 2016-11-07 13:27:02 -0700 | [diff] [blame] | 3540 | } else if (!strcmp(pName, "vkDebugMarkerSetObjectTagEXT")) { |
| 3541 | return (PFN_vkVoidFunction)terminator_DebugMarkerSetObjectTagEXT; |
| 3542 | } else if (!strcmp(pName, "vkDebugMarkerSetObjectNameEXT")) { |
| 3543 | return (PFN_vkVoidFunction)terminator_DebugMarkerSetObjectNameEXT; |
Mark Young | 16573c7 | 2016-06-28 10:52:43 -0600 | [diff] [blame] | 3544 | } |
| 3545 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 3546 | return icd_term->GetDeviceProcAddr(device, pName); |
Piers Daniell | 295fe40 | 2016-03-29 11:51:11 -0600 | [diff] [blame] | 3547 | } |
| 3548 | |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3549 | /** |
| 3550 | * Initialize device_ext dispatch table entry as follows: |
| 3551 | * If dev == NULL find all logical devices created within this instance and |
| 3552 | * init the entry (given by idx) in the ext dispatch table. |
| 3553 | * If dev != NULL only initialize the entry in the given dev's dispatch table. |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3554 | * The initialization value is gotten by calling down the device chain with |
| 3555 | * GDPA. |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3556 | * If GDPA returns NULL then don't initialize the dispatch table entry. |
| 3557 | */ |
| 3558 | static void loader_init_dispatch_dev_ext_entry(struct loader_instance *inst, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3559 | struct loader_device *dev, |
| 3560 | uint32_t idx, |
| 3561 | const char *funcName) |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3562 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3563 | { |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3564 | void *gdpa_value; |
| 3565 | if (dev != NULL) { |
| 3566 | gdpa_value = dev->loader_dispatch.core_dispatch.GetDeviceProcAddr( |
Mark Young | 65cb366 | 2016-11-07 13:27:02 -0700 | [diff] [blame] | 3567 | dev->chain_device, funcName); |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3568 | if (gdpa_value != NULL) |
Mark Young | 8191d9f | 2016-09-02 11:41:28 -0600 | [diff] [blame] | 3569 | dev->loader_dispatch.ext_dispatch.dev_ext[idx] = |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3570 | (PFN_vkDevExt)gdpa_value; |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3571 | } else { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 3572 | for (struct loader_icd_term *icd_term = inst->icd_terms; |
| 3573 | icd_term != NULL; icd_term = icd_term->next) { |
| 3574 | struct loader_device *ldev = icd_term->logical_device_list; |
Karl Schultz | 2558bd3 | 2016-02-24 14:39:39 -0700 | [diff] [blame] | 3575 | while (ldev) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3576 | gdpa_value = |
Karl Schultz | 2558bd3 | 2016-02-24 14:39:39 -0700 | [diff] [blame] | 3577 | ldev->loader_dispatch.core_dispatch.GetDeviceProcAddr( |
Mark Young | 65cb366 | 2016-11-07 13:27:02 -0700 | [diff] [blame] | 3578 | ldev->chain_device, funcName); |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3579 | if (gdpa_value != NULL) |
Mark Young | 8191d9f | 2016-09-02 11:41:28 -0600 | [diff] [blame] | 3580 | ldev->loader_dispatch.ext_dispatch.dev_ext[idx] = |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3581 | (PFN_vkDevExt)gdpa_value; |
Karl Schultz | 2558bd3 | 2016-02-24 14:39:39 -0700 | [diff] [blame] | 3582 | ldev = ldev->next; |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3583 | } |
| 3584 | } |
| 3585 | } |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3586 | } |
| 3587 | |
| 3588 | /** |
| 3589 | * Find all dev extension in the hash table and initialize the dispatch table |
| 3590 | * for dev for each of those extension entrypoints found in hash table. |
| 3591 | |
| 3592 | */ |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 3593 | void loader_init_dispatch_dev_ext(struct loader_instance *inst, |
| 3594 | struct loader_device *dev) { |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3595 | for (uint32_t i = 0; i < MAX_NUM_DEV_EXTS; i++) { |
| 3596 | if (inst->disp_hash[i].func_name != NULL) |
| 3597 | loader_init_dispatch_dev_ext_entry(inst, dev, i, |
| 3598 | inst->disp_hash[i].func_name); |
| 3599 | } |
| 3600 | } |
| 3601 | |
| 3602 | static bool loader_check_icds_for_address(struct loader_instance *inst, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3603 | const char *funcName) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 3604 | struct loader_icd_term *icd_term; |
| 3605 | icd_term = inst->icd_terms; |
| 3606 | while (NULL != icd_term) { |
| 3607 | if (icd_term->scanned_icd->GetInstanceProcAddr(icd_term->instance, |
| 3608 | funcName)) |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3609 | // this icd supports funcName |
| 3610 | return true; |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 3611 | icd_term = icd_term->next; |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3612 | } |
| 3613 | |
| 3614 | return false; |
| 3615 | } |
| 3616 | |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 3617 | static bool loader_check_layer_list_for_address( |
| 3618 | const struct loader_layer_list *const layers, const char *funcName) { |
Jeremy Hayes | 1eb1f62 | 2016-03-03 16:03:03 -0700 | [diff] [blame] | 3619 | // Iterate over the layers. |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 3620 | for (uint32_t layer = 0; layer < layers->count; ++layer) { |
Jeremy Hayes | 1eb1f62 | 2016-03-03 16:03:03 -0700 | [diff] [blame] | 3621 | // Iterate over the extensions. |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 3622 | const struct loader_device_extension_list *const extensions = |
| 3623 | &(layers->list[layer].device_extension_list); |
| 3624 | for (uint32_t extension = 0; extension < extensions->count; |
| 3625 | ++extension) { |
Jeremy Hayes | 1eb1f62 | 2016-03-03 16:03:03 -0700 | [diff] [blame] | 3626 | // Iterate over the entry points. |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 3627 | const struct loader_dev_ext_props *const property = |
| 3628 | &(extensions->list[extension]); |
| 3629 | for (uint32_t entry = 0; entry < property->entrypoint_count; |
| 3630 | ++entry) { |
| 3631 | if (strcmp(property->entrypoints[entry], funcName) == 0) { |
Jeremy Hayes | 1eb1f62 | 2016-03-03 16:03:03 -0700 | [diff] [blame] | 3632 | return true; |
| 3633 | } |
| 3634 | } |
| 3635 | } |
| 3636 | } |
| 3637 | |
| 3638 | return false; |
| 3639 | } |
| 3640 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3641 | static void loader_free_dev_ext_table(struct loader_instance *inst) { |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3642 | for (uint32_t i = 0; i < MAX_NUM_DEV_EXTS; i++) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3643 | loader_instance_heap_free(inst, inst->disp_hash[i].func_name); |
| 3644 | loader_instance_heap_free(inst, inst->disp_hash[i].list.index); |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3645 | } |
| 3646 | memset(inst->disp_hash, 0, sizeof(inst->disp_hash)); |
| 3647 | } |
| 3648 | |
| 3649 | static bool loader_add_dev_ext_table(struct loader_instance *inst, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3650 | uint32_t *ptr_idx, const char *funcName) { |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3651 | uint32_t i; |
| 3652 | uint32_t idx = *ptr_idx; |
| 3653 | struct loader_dispatch_hash_list *list = &inst->disp_hash[idx].list; |
| 3654 | |
| 3655 | if (!inst->disp_hash[idx].func_name) { |
| 3656 | // no entry here at this idx, so use it |
| 3657 | assert(list->capacity == 0); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3658 | inst->disp_hash[idx].func_name = (char *)loader_instance_heap_alloc( |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3659 | inst, strlen(funcName) + 1, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3660 | if (inst->disp_hash[idx].func_name == NULL) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 3661 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3662 | "loader_add_dev_ext_table: Failed to allocate memory " |
| 3663 | "for func_name %s", |
| 3664 | funcName); |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3665 | return false; |
| 3666 | } |
| 3667 | strncpy(inst->disp_hash[idx].func_name, funcName, strlen(funcName) + 1); |
| 3668 | return true; |
| 3669 | } |
| 3670 | |
| 3671 | // check for enough capacity |
| 3672 | if (list->capacity == 0) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 3673 | list->index = |
| 3674 | loader_instance_heap_alloc(inst, 8 * sizeof(*(list->index)), |
| 3675 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3676 | if (list->index == NULL) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 3677 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3678 | "loader_add_dev_ext_table: Failed to allocate memory " |
| 3679 | "for list index", |
| 3680 | funcName); |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3681 | return false; |
| 3682 | } |
| 3683 | list->capacity = 8 * sizeof(*(list->index)); |
| 3684 | } else if (list->capacity < (list->count + 1) * sizeof(*(list->index))) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 3685 | list->index = loader_instance_heap_realloc( |
| 3686 | inst, list->index, list->capacity, list->capacity * 2, |
| 3687 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3688 | if (list->index == NULL) { |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3689 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 3690 | "loader_add_dev_ext_table: Failed to reallocate memory " |
| 3691 | "for list index", |
| 3692 | funcName); |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3693 | return false; |
| 3694 | } |
| 3695 | list->capacity *= 2; |
| 3696 | } |
| 3697 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3698 | // find an unused index in the hash table and use it |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3699 | i = (idx + 1) % MAX_NUM_DEV_EXTS; |
| 3700 | do { |
| 3701 | if (!inst->disp_hash[i].func_name) { |
| 3702 | assert(inst->disp_hash[i].list.capacity == 0); |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 3703 | inst->disp_hash[i].func_name = (char *)loader_instance_heap_alloc( |
| 3704 | inst, strlen(funcName) + 1, |
| 3705 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3706 | if (inst->disp_hash[i].func_name == NULL) { |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3707 | loader_log( |
| 3708 | inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 3709 | "loader_add_dev_ext_table: Failed to allocate memory " |
| 3710 | "for func_name %s", |
| 3711 | funcName); |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3712 | return false; |
| 3713 | } |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3714 | strncpy(inst->disp_hash[i].func_name, funcName, |
| 3715 | strlen(funcName) + 1); |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3716 | list->index[list->count] = i; |
| 3717 | list->count++; |
| 3718 | *ptr_idx = i; |
| 3719 | return true; |
| 3720 | } |
| 3721 | i = (i + 1) % MAX_NUM_DEV_EXTS; |
| 3722 | } while (i != idx); |
| 3723 | |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3724 | loader_log( |
| 3725 | inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 3726 | "loader_add_dev_ext_table: Could not insert into hash table; is " |
| 3727 | "it full?"); |
| 3728 | |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3729 | return false; |
| 3730 | } |
| 3731 | |
| 3732 | static bool loader_name_in_dev_ext_table(struct loader_instance *inst, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3733 | uint32_t *idx, const char *funcName) { |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3734 | uint32_t alt_idx; |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3735 | if (inst->disp_hash[*idx].func_name && |
| 3736 | !strcmp(inst->disp_hash[*idx].func_name, funcName)) |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3737 | return true; |
| 3738 | |
| 3739 | // funcName wasn't at the primary spot in the hash table |
| 3740 | // search the list of secondary locations (shallow search, not deep search) |
| 3741 | for (uint32_t i = 0; i < inst->disp_hash[*idx].list.count; i++) { |
| 3742 | alt_idx = inst->disp_hash[*idx].list.index[i]; |
Karl Schultz | e2ef9e6 | 2017-01-13 14:01:35 -0700 | [diff] [blame] | 3743 | if (inst->disp_hash[*idx].func_name && |
| 3744 | !strcmp(inst->disp_hash[*idx].func_name, funcName)) { |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3745 | *idx = alt_idx; |
| 3746 | return true; |
| 3747 | } |
| 3748 | } |
| 3749 | |
| 3750 | return false; |
| 3751 | } |
| 3752 | |
| 3753 | /** |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3754 | * This function returns generic trampoline code address for unknown entry |
| 3755 | * points. |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3756 | * Presumably, these unknown entry points (as given by funcName) are device |
| 3757 | * extension entrypoints. A hash table is used to keep a list of unknown entry |
| 3758 | * points and their mapping to the device extension dispatch table |
| 3759 | * (struct loader_dev_ext_dispatch_table). |
| 3760 | * \returns |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3761 | * For a given entry point string (funcName), if an existing mapping is found |
| 3762 | * the |
| 3763 | * trampoline address for that mapping is returned. Otherwise, this unknown |
| 3764 | * entry point |
| 3765 | * has not been seen yet. Next check if a layer or ICD supports it. If so then |
| 3766 | * a |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3767 | * new entry in the hash table is initialized and that trampoline address for |
| 3768 | * the new entry is returned. Null is returned if the hash table is full or |
| 3769 | * if no discovered layer or ICD returns a non-NULL GetProcAddr for it. |
| 3770 | */ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3771 | void *loader_dev_ext_gpa(struct loader_instance *inst, const char *funcName) { |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3772 | uint32_t idx; |
| 3773 | uint32_t seed = 0; |
| 3774 | |
| 3775 | idx = murmurhash(funcName, strlen(funcName), seed) % MAX_NUM_DEV_EXTS; |
| 3776 | |
| 3777 | if (loader_name_in_dev_ext_table(inst, &idx, funcName)) |
| 3778 | // found funcName already in hash |
| 3779 | return loader_get_dev_ext_trampoline(idx); |
| 3780 | |
| 3781 | // Check if funcName is supported in either ICDs or a layer library |
Jeremy Hayes | 1eb1f62 | 2016-03-03 16:03:03 -0700 | [diff] [blame] | 3782 | if (!loader_check_icds_for_address(inst, funcName) && |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 3783 | !loader_check_layer_list_for_address(&inst->instance_layer_list, |
| 3784 | funcName)) { |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3785 | // if support found in layers continue on |
| 3786 | return NULL; |
| 3787 | } |
| 3788 | |
| 3789 | if (loader_add_dev_ext_table(inst, &idx, funcName)) { |
| 3790 | // successfully added new table entry |
| 3791 | // init any dev dispatch table entrys as needed |
| 3792 | loader_init_dispatch_dev_ext_entry(inst, NULL, idx, funcName); |
| 3793 | return loader_get_dev_ext_trampoline(idx); |
| 3794 | } |
| 3795 | |
| 3796 | return NULL; |
| 3797 | } |
| 3798 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3799 | struct loader_instance *loader_get_instance(const VkInstance instance) { |
Jon Ashburn | e0e6457 | 2015-09-30 12:56:42 -0600 | [diff] [blame] | 3800 | /* look up the loader_instance in our list by comparing dispatch tables, as |
| 3801 | * there is no guarantee the instance is still a loader_instance* after any |
| 3802 | * layers which wrap the instance object. |
| 3803 | */ |
| 3804 | const VkLayerInstanceDispatchTable *disp; |
| 3805 | struct loader_instance *ptr_instance = NULL; |
| 3806 | disp = loader_get_instance_dispatch(instance); |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3807 | for (struct loader_instance *inst = loader.instances; inst; |
| 3808 | inst = inst->next) { |
Jon Ashburn | e0e6457 | 2015-09-30 12:56:42 -0600 | [diff] [blame] | 3809 | if (inst->disp == disp) { |
| 3810 | ptr_instance = inst; |
| 3811 | break; |
| 3812 | } |
| 3813 | } |
| 3814 | return ptr_instance; |
| 3815 | } |
| 3816 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3817 | static loader_platform_dl_handle |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 3818 | loader_open_layer_lib(const struct loader_instance *inst, |
| 3819 | const char *chain_type, |
| 3820 | struct loader_layer_properties *prop) { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3821 | |
Jon Ashburn | 4dc1d8a | 2016-04-20 13:21:17 -0600 | [diff] [blame] | 3822 | if ((prop->lib_handle = loader_platform_open_library(prop->lib_name)) == |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3823 | NULL) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 3824 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3825 | "loader_open_layer_lib: Failed to open library %s", |
| 3826 | prop->lib_name); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3827 | } else { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 3828 | loader_log(inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3829 | "Loading layer library %s", prop->lib_name); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3830 | } |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3831 | |
Jon Ashburn | 4dc1d8a | 2016-04-20 13:21:17 -0600 | [diff] [blame] | 3832 | return prop->lib_handle; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3833 | } |
| 3834 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 3835 | static void loader_close_layer_lib(const struct loader_instance *inst, |
| 3836 | struct loader_layer_properties *prop) { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3837 | |
Jon Ashburn | 4dc1d8a | 2016-04-20 13:21:17 -0600 | [diff] [blame] | 3838 | if (prop->lib_handle) { |
| 3839 | loader_platform_close_library(prop->lib_handle); |
| 3840 | loader_log(inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, |
| 3841 | "Unloading layer library %s", prop->lib_name); |
| 3842 | prop->lib_handle = NULL; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 3843 | } |
Jon Ashburn | 4dc1d8a | 2016-04-20 13:21:17 -0600 | [diff] [blame] | 3844 | } |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 3845 | |
Jon Ashburn | 4dc1d8a | 2016-04-20 13:21:17 -0600 | [diff] [blame] | 3846 | void loader_deactivate_layers(const struct loader_instance *instance, |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3847 | struct loader_device *device, |
Jon Ashburn | 4dc1d8a | 2016-04-20 13:21:17 -0600 | [diff] [blame] | 3848 | struct loader_layer_list *list) { |
| 3849 | /* delete instance list of enabled layers and close any layer libraries */ |
| 3850 | for (uint32_t i = 0; i < list->count; i++) { |
| 3851 | struct loader_layer_properties *layer_prop = &list->list[i]; |
Courtney Goeltzenleuchter | 80bfd0e | 2015-12-17 09:51:22 -0700 | [diff] [blame] | 3852 | |
Jon Ashburn | 4dc1d8a | 2016-04-20 13:21:17 -0600 | [diff] [blame] | 3853 | loader_close_layer_lib(instance, layer_prop); |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 3854 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3855 | loader_destroy_layer_list(instance, device, list); |
Jon Ashburn | b835805 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 3856 | } |
| 3857 | |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 3858 | /** |
| 3859 | * Go through the search_list and find any layers which match type. If layer |
| 3860 | * type match is found in then add it to ext_list. |
| 3861 | */ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3862 | static void |
| 3863 | loader_add_layer_implicit(const struct loader_instance *inst, |
| 3864 | const enum layer_type type, |
| 3865 | struct loader_layer_list *list, |
| 3866 | const struct loader_layer_list *search_list) { |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3867 | bool enable; |
| 3868 | char *env_value; |
Jon Ashburn | 0c26e71 | 2015-07-02 16:10:32 -0600 | [diff] [blame] | 3869 | uint32_t i; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 3870 | for (i = 0; i < search_list->count; i++) { |
| 3871 | const struct loader_layer_properties *prop = &search_list->list[i]; |
Jon Ashburn | 0c26e71 | 2015-07-02 16:10:32 -0600 | [diff] [blame] | 3872 | if (prop->type & type) { |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3873 | /* Found an implicit layer, see if it should be enabled */ |
| 3874 | enable = false; |
| 3875 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3876 | // if no enable_environment variable is specified, this implicit |
| 3877 | // layer |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3878 | // should always be enabled. Otherwise check if the variable is set |
| 3879 | if (prop->enable_env_var.name[0] == 0) { |
| 3880 | enable = true; |
| 3881 | } else { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3882 | env_value = loader_getenv(prop->enable_env_var.name, inst); |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3883 | if (env_value && !strcmp(prop->enable_env_var.value, env_value)) |
| 3884 | enable = true; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3885 | loader_free_getenv(env_value, inst); |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3886 | } |
| 3887 | |
| 3888 | // disable_environment has priority, i.e. if both enable and disable |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3889 | // environment variables are set, the layer is disabled. Implicit |
| 3890 | // layers |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3891 | // are required to have a disable_environment variables |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3892 | env_value = loader_getenv(prop->disable_env_var.name, inst); |
| 3893 | if (env_value) { |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3894 | enable = false; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3895 | } |
| 3896 | loader_free_getenv(env_value, inst); |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3897 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3898 | if (enable) { |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3899 | loader_add_to_layer_list(inst, list, 1, prop); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3900 | } |
Jon Ashburn | 0c26e71 | 2015-07-02 16:10:32 -0600 | [diff] [blame] | 3901 | } |
| 3902 | } |
Jon Ashburn | 0c26e71 | 2015-07-02 16:10:32 -0600 | [diff] [blame] | 3903 | } |
| 3904 | |
| 3905 | /** |
| 3906 | * Get the layer name(s) from the env_name environment variable. If layer |
Jon Ashburn | bd332cc | 2015-07-07 10:27:45 -0600 | [diff] [blame] | 3907 | * is found in search_list then add it to layer_list. But only add it to |
| 3908 | * layer_list if type matches. |
Jon Ashburn | 0c26e71 | 2015-07-02 16:10:32 -0600 | [diff] [blame] | 3909 | */ |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 3910 | static void loader_add_layer_env(struct loader_instance *inst, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3911 | const enum layer_type type, |
| 3912 | const char *env_name, |
| 3913 | struct loader_layer_list *layer_list, |
| 3914 | const struct loader_layer_list *search_list) { |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 3915 | char *layerEnv; |
Jon Ashburn | eb6d568 | 2015-07-02 14:10:53 -0600 | [diff] [blame] | 3916 | char *next, *name; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 3917 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3918 | layerEnv = loader_getenv(env_name, inst); |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 3919 | if (layerEnv == NULL) { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3920 | return; |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 3921 | } |
Courtney Goeltzenleuchter | 7f5aafc | 2015-07-05 11:28:29 -0600 | [diff] [blame] | 3922 | name = loader_stack_alloc(strlen(layerEnv) + 1); |
Jon Ashburn | eb6d568 | 2015-07-02 14:10:53 -0600 | [diff] [blame] | 3923 | if (name == NULL) { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3924 | return; |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 3925 | } |
Jon Ashburn | eb6d568 | 2015-07-02 14:10:53 -0600 | [diff] [blame] | 3926 | strcpy(name, layerEnv); |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 3927 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3928 | loader_free_getenv(layerEnv, inst); |
Jon Ashburn | 38a497f | 2016-01-04 14:01:38 -0700 | [diff] [blame] | 3929 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3930 | while (name && *name) { |
Jon Ashburn | eb6d568 | 2015-07-02 14:10:53 -0600 | [diff] [blame] | 3931 | next = loader_get_next_path(name); |
Jon Ashburn | 7148344 | 2016-02-11 18:59:43 -0700 | [diff] [blame] | 3932 | if (!strcmp(std_validation_str, name)) { |
| 3933 | /* add meta list of layers |
| 3934 | don't attempt to remove duplicate layers already added by app or |
| 3935 | env var |
| 3936 | */ |
| 3937 | loader_log(inst, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, |
| 3938 | "Expanding meta layer %s found in environment variable", |
| 3939 | std_validation_str); |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 3940 | if (type == VK_LAYER_TYPE_INSTANCE_EXPLICIT) |
| 3941 | inst->activated_layers_are_std_val = true; |
Jon Ashburn | 7148344 | 2016-02-11 18:59:43 -0700 | [diff] [blame] | 3942 | for (uint32_t i = 0; i < sizeof(std_validation_names) / |
| 3943 | sizeof(std_validation_names[0]); |
| 3944 | i++) { |
| 3945 | loader_find_layer_name_add_list(inst, std_validation_names[i], |
| 3946 | type, search_list, layer_list); |
| 3947 | } |
| 3948 | } else { |
| 3949 | loader_find_layer_name_add_list(inst, name, type, search_list, |
| 3950 | layer_list); |
| 3951 | } |
Jon Ashburn | eb6d568 | 2015-07-02 14:10:53 -0600 | [diff] [blame] | 3952 | name = next; |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 3953 | } |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 3954 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3955 | return; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 3956 | } |
| 3957 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3958 | VkResult |
| 3959 | loader_enable_instance_layers(struct loader_instance *inst, |
| 3960 | const VkInstanceCreateInfo *pCreateInfo, |
| 3961 | const struct loader_layer_list *instance_layers) { |
Courtney Goeltzenleuchter | 40caf0b | 2015-07-06 09:06:34 -0600 | [diff] [blame] | 3962 | VkResult err; |
| 3963 | |
Courtney Goeltzenleuchter | 55659b7 | 2015-09-14 18:01:17 -0600 | [diff] [blame] | 3964 | assert(inst && "Cannot have null instance"); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3965 | |
Jon Ashburn | e39a4f8 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 3966 | if (!loader_init_layer_list(inst, &inst->activated_layer_list)) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3967 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3968 | "loader_enable_instance_layers: Failed to initialize" |
| 3969 | " the layer list"); |
Courtney Goeltzenleuchter | 40caf0b | 2015-07-06 09:06:34 -0600 | [diff] [blame] | 3970 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Jon Ashburn | bd6c488 | 2015-07-02 12:59:25 -0600 | [diff] [blame] | 3971 | } |
| 3972 | |
Jon Ashburn | 0c26e71 | 2015-07-02 16:10:32 -0600 | [diff] [blame] | 3973 | /* Add any implicit layers first */ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3974 | loader_add_layer_implicit(inst, VK_LAYER_TYPE_INSTANCE_IMPLICIT, |
| 3975 | &inst->activated_layer_list, instance_layers); |
Jon Ashburn | 0c26e71 | 2015-07-02 16:10:32 -0600 | [diff] [blame] | 3976 | |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 3977 | /* Add any layers specified via environment variable next */ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3978 | loader_add_layer_env(inst, VK_LAYER_TYPE_INSTANCE_EXPLICIT, |
| 3979 | "VK_INSTANCE_LAYERS", &inst->activated_layer_list, |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3980 | instance_layers); |
Jon Ashburn | bd6c488 | 2015-07-02 12:59:25 -0600 | [diff] [blame] | 3981 | |
| 3982 | /* Add layers specified by the application */ |
Courtney Goeltzenleuchter | 40caf0b | 2015-07-06 09:06:34 -0600 | [diff] [blame] | 3983 | err = loader_add_layer_names_to_list( |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3984 | inst, &inst->activated_layer_list, pCreateInfo->enabledLayerCount, |
| 3985 | pCreateInfo->ppEnabledLayerNames, instance_layers); |
Courtney Goeltzenleuchter | 40caf0b | 2015-07-06 09:06:34 -0600 | [diff] [blame] | 3986 | |
| 3987 | return err; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3988 | } |
| 3989 | |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3990 | /* |
| 3991 | * Given the list of layers to activate in the loader_instance |
| 3992 | * structure. This function will add a VkLayerInstanceCreateInfo |
| 3993 | * structure to the VkInstanceCreateInfo.pNext pointer. |
| 3994 | * Each activated layer will have it's own VkLayerInstanceLink |
| 3995 | * structure that tells the layer what Get*ProcAddr to call to |
| 3996 | * get function pointers to the next layer down. |
| 3997 | * Once the chain info has been created this function will |
| 3998 | * execute the CreateInstance call chain. Each layer will |
| 3999 | * then have an opportunity in it's CreateInstance function |
| 4000 | * to setup it's dispatch table when the lower layer returns |
| 4001 | * successfully. |
| 4002 | * Each layer can wrap or not-wrap the returned VkInstance object |
| 4003 | * as it sees fit. |
| 4004 | * The instance chain is terminated by a loader function |
| 4005 | * that will call CreateInstance on all available ICD's and |
| 4006 | * cache those VkInstance objects for future use. |
| 4007 | */ |
| 4008 | VkResult loader_create_instance_chain(const VkInstanceCreateInfo *pCreateInfo, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4009 | const VkAllocationCallbacks *pAllocator, |
Jon Ashburn | 373c180 | 2016-01-20 08:08:25 -0700 | [diff] [blame] | 4010 | struct loader_instance *inst, |
Jon Ashburn | 6e0a213 | 2016-02-03 12:37:30 -0700 | [diff] [blame] | 4011 | VkInstance *created_instance) { |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4012 | uint32_t activated_layers = 0; |
| 4013 | VkLayerInstanceCreateInfo chain_info; |
| 4014 | VkLayerInstanceLink *layer_instance_link_info = NULL; |
| 4015 | VkInstanceCreateInfo loader_create_info; |
| 4016 | VkResult res; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 4017 | |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4018 | PFN_vkGetInstanceProcAddr nextGIPA = loader_gpa_instance_internal; |
| 4019 | PFN_vkGetInstanceProcAddr fpGIPA = loader_gpa_instance_internal; |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 4020 | |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4021 | memcpy(&loader_create_info, pCreateInfo, sizeof(VkInstanceCreateInfo)); |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 4022 | |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4023 | if (inst->activated_layer_list.count > 0) { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 4024 | |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4025 | chain_info.u.pLayerInfo = NULL; |
| 4026 | chain_info.pNext = pCreateInfo->pNext; |
| 4027 | chain_info.sType = VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO; |
| 4028 | chain_info.function = VK_LAYER_LINK_INFO; |
| 4029 | loader_create_info.pNext = &chain_info; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 4030 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4031 | layer_instance_link_info = loader_stack_alloc( |
| 4032 | sizeof(VkLayerInstanceLink) * inst->activated_layer_list.count); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4033 | if (!layer_instance_link_info) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4034 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4035 | "loader_create_instance_chain: Failed to alloc Instance" |
| 4036 | " objects for layer"); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4037 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 4038 | } |
| 4039 | |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4040 | /* Create instance chain of enabled layers */ |
| 4041 | for (int32_t i = inst->activated_layer_list.count - 1; i >= 0; i--) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4042 | struct loader_layer_properties *layer_prop = |
| 4043 | &inst->activated_layer_list.list[i]; |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4044 | loader_platform_dl_handle lib_handle; |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 4045 | |
Jon Ashburn | 4dc1d8a | 2016-04-20 13:21:17 -0600 | [diff] [blame] | 4046 | lib_handle = loader_open_layer_lib(inst, "instance", layer_prop); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4047 | if (!lib_handle) |
Courtney Goeltzenleuchter | 524b7e3 | 2016-01-14 16:06:06 -0700 | [diff] [blame] | 4048 | continue; |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4049 | if ((fpGIPA = layer_prop->functions.get_instance_proc_addr) == |
| 4050 | NULL) { |
Jamie Madill | c3d3f07 | 2016-12-14 17:21:43 -0500 | [diff] [blame] | 4051 | if (strlen(layer_prop->functions.str_gipa) == 0) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4052 | fpGIPA = (PFN_vkGetInstanceProcAddr) |
| 4053 | loader_platform_get_proc_address( |
| 4054 | lib_handle, "vkGetInstanceProcAddr"); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4055 | layer_prop->functions.get_instance_proc_addr = fpGIPA; |
| 4056 | } else |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4057 | fpGIPA = (PFN_vkGetInstanceProcAddr) |
| 4058 | loader_platform_get_proc_address( |
| 4059 | lib_handle, layer_prop->functions.str_gipa); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4060 | if (!fpGIPA) { |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4061 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4062 | "loader_create_instance_chain: Failed to find " |
| 4063 | "\'vkGetInstanceProcAddr\' in layer %s", |
| 4064 | layer_prop->lib_name); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4065 | continue; |
| 4066 | } |
| 4067 | } |
| 4068 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4069 | layer_instance_link_info[activated_layers].pNext = |
| 4070 | chain_info.u.pLayerInfo; |
| 4071 | layer_instance_link_info[activated_layers] |
| 4072 | .pfnNextGetInstanceProcAddr = nextGIPA; |
| 4073 | chain_info.u.pLayerInfo = |
| 4074 | &layer_instance_link_info[activated_layers]; |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4075 | nextGIPA = fpGIPA; |
| 4076 | |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 4077 | loader_log(inst, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4078 | "Insert instance layer %s (%s)", |
| 4079 | layer_prop->info.layerName, layer_prop->lib_name); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4080 | |
| 4081 | activated_layers++; |
| 4082 | } |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 4083 | } |
| 4084 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4085 | PFN_vkCreateInstance fpCreateInstance = |
Jon Ashburn | 6e0a213 | 2016-02-03 12:37:30 -0700 | [diff] [blame] | 4086 | (PFN_vkCreateInstance)nextGIPA(*created_instance, "vkCreateInstance"); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4087 | if (fpCreateInstance) { |
Jon Ashburn | c3c5877 | 2016-03-29 11:16:01 -0600 | [diff] [blame] | 4088 | VkLayerInstanceCreateInfo create_info_disp; |
| 4089 | |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 4090 | create_info_disp.sType = VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO; |
Jon Ashburn | ed8f231 | 2016-03-31 10:52:22 -0600 | [diff] [blame] | 4091 | create_info_disp.function = VK_LOADER_DATA_CALLBACK; |
Jon Ashburn | c3c5877 | 2016-03-29 11:16:01 -0600 | [diff] [blame] | 4092 | |
| 4093 | create_info_disp.u.pfnSetInstanceLoaderData = vkSetInstanceDispatch; |
| 4094 | |
| 4095 | create_info_disp.pNext = loader_create_info.pNext; |
| 4096 | loader_create_info.pNext = &create_info_disp; |
Jon Ashburn | f2b4e38 | 2016-02-10 20:50:19 -0700 | [diff] [blame] | 4097 | res = |
| 4098 | fpCreateInstance(&loader_create_info, pAllocator, created_instance); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4099 | } else { |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4100 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4101 | "loader_create_instance_chain: Failed to find " |
| 4102 | "\'vkCreateInstance\'"); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4103 | // Couldn't find CreateInstance function! |
| 4104 | res = VK_ERROR_INITIALIZATION_FAILED; |
| 4105 | } |
| 4106 | |
| 4107 | if (res != VK_SUCCESS) { |
| 4108 | // TODO: Need to clean up here |
| 4109 | } else { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4110 | loader_init_instance_core_dispatch_table(inst->disp, nextGIPA, |
Jon Ashburn | 6e0a213 | 2016-02-03 12:37:30 -0700 | [diff] [blame] | 4111 | *created_instance); |
Jon Ashburn | 4e8c416 | 2016-03-08 15:21:30 -0700 | [diff] [blame] | 4112 | inst->instance = *created_instance; |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4113 | } |
| 4114 | |
| 4115 | return res; |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 4116 | } |
| 4117 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4118 | void loader_activate_instance_layer_extensions(struct loader_instance *inst, |
| 4119 | VkInstance created_inst) { |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 4120 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4121 | loader_init_instance_extension_dispatch_table( |
| 4122 | inst->disp, inst->disp->GetInstanceProcAddr, created_inst); |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 4123 | } |
| 4124 | |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 4125 | VkResult |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 4126 | loader_create_device_chain(const struct loader_physical_device_tramp *pd, |
| 4127 | const VkDeviceCreateInfo *pCreateInfo, |
| 4128 | const VkAllocationCallbacks *pAllocator, |
| 4129 | const struct loader_instance *inst, |
| 4130 | struct loader_device *dev) { |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4131 | uint32_t activated_layers = 0; |
| 4132 | VkLayerDeviceLink *layer_device_link_info; |
| 4133 | VkLayerDeviceCreateInfo chain_info; |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4134 | VkDeviceCreateInfo loader_create_info; |
| 4135 | VkResult res; |
Courtney Goeltzenleuchter | ca173b8 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 4136 | |
Piers Daniell | 295fe40 | 2016-03-29 11:51:11 -0600 | [diff] [blame] | 4137 | PFN_vkGetDeviceProcAddr fpGDPA, nextGDPA = loader_gpa_device_internal; |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4138 | PFN_vkGetInstanceProcAddr fpGIPA, nextGIPA = loader_gpa_instance_internal; |
Courtney Goeltzenleuchter | ca173b8 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 4139 | |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4140 | memcpy(&loader_create_info, pCreateInfo, sizeof(VkDeviceCreateInfo)); |
| 4141 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4142 | layer_device_link_info = loader_stack_alloc( |
| 4143 | sizeof(VkLayerDeviceLink) * dev->activated_layer_list.count); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4144 | if (!layer_device_link_info) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4145 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4146 | "loader_create_device_chain: Failed to alloc Device objects" |
| 4147 | " for layer. Skipping Layer."); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4148 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
David Pinedo | a0a8a24 | 2015-06-24 15:29:18 -0600 | [diff] [blame] | 4149 | } |
Jon Ashburn | 94e7049 | 2015-06-10 10:13:10 -0600 | [diff] [blame] | 4150 | |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4151 | if (dev->activated_layer_list.count > 0) { |
Jon Ashburn | 72690f2 | 2016-03-29 12:52:13 -0600 | [diff] [blame] | 4152 | chain_info.sType = VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO; |
| 4153 | chain_info.function = VK_LAYER_LINK_INFO; |
| 4154 | chain_info.u.pLayerInfo = NULL; |
| 4155 | chain_info.pNext = pCreateInfo->pNext; |
| 4156 | loader_create_info.pNext = &chain_info; |
| 4157 | |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4158 | /* Create instance chain of enabled layers */ |
| 4159 | for (int32_t i = dev->activated_layer_list.count - 1; i >= 0; i--) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4160 | struct loader_layer_properties *layer_prop = |
| 4161 | &dev->activated_layer_list.list[i]; |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4162 | loader_platform_dl_handle lib_handle; |
Courtney Goeltzenleuchter | ca173b8 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 4163 | |
Jon Ashburn | 4dc1d8a | 2016-04-20 13:21:17 -0600 | [diff] [blame] | 4164 | lib_handle = loader_open_layer_lib(inst, "device", layer_prop); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4165 | if (!lib_handle) |
Courtney Goeltzenleuchter | 524b7e3 | 2016-01-14 16:06:06 -0700 | [diff] [blame] | 4166 | continue; |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4167 | if ((fpGIPA = layer_prop->functions.get_instance_proc_addr) == |
| 4168 | NULL) { |
Jamie Madill | c3d3f07 | 2016-12-14 17:21:43 -0500 | [diff] [blame] | 4169 | if (strlen(layer_prop->functions.str_gipa) == 0) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4170 | fpGIPA = (PFN_vkGetInstanceProcAddr) |
| 4171 | loader_platform_get_proc_address( |
| 4172 | lib_handle, "vkGetInstanceProcAddr"); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4173 | layer_prop->functions.get_instance_proc_addr = fpGIPA; |
| 4174 | } else |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4175 | fpGIPA = (PFN_vkGetInstanceProcAddr) |
| 4176 | loader_platform_get_proc_address( |
| 4177 | lib_handle, layer_prop->functions.str_gipa); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4178 | if (!fpGIPA) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4179 | loader_log( |
| 4180 | inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4181 | "loader_create_device_chain: Failed to find " |
| 4182 | "\'vkGetInstanceProcAddr\' in layer %s. Skipping" |
| 4183 | " layer.", |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4184 | layer_prop->lib_name); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4185 | continue; |
| 4186 | } |
Jon Ashburn | 21c21ee | 2015-09-09 11:29:24 -0600 | [diff] [blame] | 4187 | } |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4188 | if ((fpGDPA = layer_prop->functions.get_device_proc_addr) == NULL) { |
Jamie Madill | c3d3f07 | 2016-12-14 17:21:43 -0500 | [diff] [blame] | 4189 | if (strlen(layer_prop->functions.str_gdpa) == 0) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4190 | fpGDPA = (PFN_vkGetDeviceProcAddr) |
| 4191 | loader_platform_get_proc_address(lib_handle, |
| 4192 | "vkGetDeviceProcAddr"); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4193 | layer_prop->functions.get_device_proc_addr = fpGDPA; |
| 4194 | } else |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4195 | fpGDPA = (PFN_vkGetDeviceProcAddr) |
| 4196 | loader_platform_get_proc_address( |
| 4197 | lib_handle, layer_prop->functions.str_gdpa); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4198 | if (!fpGDPA) { |
Jon Ashburn | c0dc07c | 2016-05-16 17:35:43 -0600 | [diff] [blame] | 4199 | loader_log(inst, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4200 | "Failed to find vkGetDeviceProcAddr in layer %s", |
| 4201 | layer_prop->lib_name); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4202 | continue; |
| 4203 | } |
| 4204 | } |
| 4205 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4206 | layer_device_link_info[activated_layers].pNext = |
| 4207 | chain_info.u.pLayerInfo; |
| 4208 | layer_device_link_info[activated_layers] |
| 4209 | .pfnNextGetInstanceProcAddr = nextGIPA; |
| 4210 | layer_device_link_info[activated_layers].pfnNextGetDeviceProcAddr = |
| 4211 | nextGDPA; |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4212 | chain_info.u.pLayerInfo = &layer_device_link_info[activated_layers]; |
| 4213 | nextGIPA = fpGIPA; |
| 4214 | nextGDPA = fpGDPA; |
| 4215 | |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 4216 | loader_log(inst, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4217 | "Insert device layer %s (%s)", |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4218 | layer_prop->info.layerName, layer_prop->lib_name); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4219 | |
| 4220 | activated_layers++; |
Jon Ashburn | 94e7049 | 2015-06-10 10:13:10 -0600 | [diff] [blame] | 4221 | } |
Jon Ashburn | 94e7049 | 2015-06-10 10:13:10 -0600 | [diff] [blame] | 4222 | } |
| 4223 | |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 4224 | VkDevice created_device = (VkDevice)dev; |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4225 | PFN_vkCreateDevice fpCreateDevice = |
Jon Ashburn | 4e8c416 | 2016-03-08 15:21:30 -0700 | [diff] [blame] | 4226 | (PFN_vkCreateDevice)nextGIPA(inst->instance, "vkCreateDevice"); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4227 | if (fpCreateDevice) { |
Jon Ashburn | ed8f231 | 2016-03-31 10:52:22 -0600 | [diff] [blame] | 4228 | VkLayerDeviceCreateInfo create_info_disp; |
| 4229 | |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 4230 | create_info_disp.sType = VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO; |
Jon Ashburn | ed8f231 | 2016-03-31 10:52:22 -0600 | [diff] [blame] | 4231 | create_info_disp.function = VK_LOADER_DATA_CALLBACK; |
| 4232 | |
| 4233 | create_info_disp.u.pfnSetDeviceLoaderData = vkSetDeviceDispatch; |
| 4234 | |
| 4235 | create_info_disp.pNext = loader_create_info.pNext; |
| 4236 | loader_create_info.pNext = &create_info_disp; |
Jon Ashburn | 014438f | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 4237 | res = fpCreateDevice(pd->phys_dev, &loader_create_info, pAllocator, |
Jon Ashburn | 72690f2 | 2016-03-29 12:52:13 -0600 | [diff] [blame] | 4238 | &created_device); |
Piers Daniell | efbbfc1 | 2016-04-05 17:28:06 -0600 | [diff] [blame] | 4239 | if (res != VK_SUCCESS) { |
| 4240 | return res; |
| 4241 | } |
Mark Young | 65cb366 | 2016-11-07 13:27:02 -0700 | [diff] [blame] | 4242 | dev->chain_device = created_device; |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4243 | } else { |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4244 | loader_log( |
| 4245 | inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4246 | "loader_create_device_chain: Failed to find \'vkCreateDevice\' " |
| 4247 | "in layer %s"); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4248 | // Couldn't find CreateDevice function! |
| 4249 | return VK_ERROR_INITIALIZATION_FAILED; |
| 4250 | } |
Jon Ashburn | 94e7049 | 2015-06-10 10:13:10 -0600 | [diff] [blame] | 4251 | |
Mark Young | 65cb366 | 2016-11-07 13:27:02 -0700 | [diff] [blame] | 4252 | // Initialize device dispatch table |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4253 | loader_init_device_dispatch_table(&dev->loader_dispatch, nextGDPA, |
Mark Young | 65cb366 | 2016-11-07 13:27:02 -0700 | [diff] [blame] | 4254 | dev->chain_device); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4255 | |
| 4256 | return res; |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 4257 | } |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 4258 | |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 4259 | VkResult loader_validate_layers(const struct loader_instance *inst, |
| 4260 | const uint32_t layer_count, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4261 | const char *const *ppEnabledLayerNames, |
| 4262 | const struct loader_layer_list *list) { |
Courtney Goeltzenleuchter | 3b8c5ff | 2015-07-06 17:45:08 -0600 | [diff] [blame] | 4263 | struct loader_layer_properties *prop; |
| 4264 | |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 4265 | for (uint32_t i = 0; i < layer_count; i++) { |
Jon Ashburn | f2b4e38 | 2016-02-10 20:50:19 -0700 | [diff] [blame] | 4266 | VkStringErrorFlags result = |
| 4267 | vk_string_validate(MaxLoaderStringLength, ppEnabledLayerNames[i]); |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 4268 | if (result != VK_STRING_ERROR_NONE) { |
| 4269 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4270 | "loader_validate_layers: Device ppEnabledLayerNames " |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 4271 | "contains string that is too long or is badly formed"); |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 4272 | return VK_ERROR_LAYER_NOT_PRESENT; |
| 4273 | } |
| 4274 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4275 | prop = loader_get_layer_property(ppEnabledLayerNames[i], list); |
Courtney Goeltzenleuchter | 3b8c5ff | 2015-07-06 17:45:08 -0600 | [diff] [blame] | 4276 | if (!prop) { |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4277 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4278 | "loader_validate_layers: Layer %d does not exist in " |
| 4279 | "the list of available layers", |
| 4280 | i); |
Courtney Goeltzenleuchter | 55659b7 | 2015-09-14 18:01:17 -0600 | [diff] [blame] | 4281 | return VK_ERROR_LAYER_NOT_PRESENT; |
Courtney Goeltzenleuchter | 3b8c5ff | 2015-07-06 17:45:08 -0600 | [diff] [blame] | 4282 | } |
| 4283 | } |
Courtney Goeltzenleuchter | 3b8c5ff | 2015-07-06 17:45:08 -0600 | [diff] [blame] | 4284 | return VK_SUCCESS; |
| 4285 | } |
| 4286 | |
| 4287 | VkResult loader_validate_instance_extensions( |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 4288 | const struct loader_instance *inst, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4289 | const struct loader_extension_list *icd_exts, |
Michael Jurka | 5c16c00 | 2016-12-19 16:31:43 +0100 | [diff] [blame] | 4290 | const struct loader_layer_list *instance_layers, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4291 | const VkInstanceCreateInfo *pCreateInfo) { |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 4292 | |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 4293 | VkExtensionProperties *extension_prop; |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 4294 | struct loader_layer_properties *layer_prop; |
| 4295 | |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 4296 | for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) { |
Jon Ashburn | f2b4e38 | 2016-02-10 20:50:19 -0700 | [diff] [blame] | 4297 | VkStringErrorFlags result = vk_string_validate( |
| 4298 | MaxLoaderStringLength, pCreateInfo->ppEnabledExtensionNames[i]); |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 4299 | if (result != VK_STRING_ERROR_NONE) { |
| 4300 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4301 | "loader_validate_instance_extensions: Instance " |
| 4302 | "ppEnabledExtensionNames contains " |
Jon Ashburn | f2b4e38 | 2016-02-10 20:50:19 -0700 | [diff] [blame] | 4303 | "string that is too long or is badly formed"); |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 4304 | return VK_ERROR_EXTENSION_NOT_PRESENT; |
| 4305 | } |
| 4306 | |
Lenny Komow | 4053b81 | 2016-12-29 16:27:28 -0700 | [diff] [blame] | 4307 | // See if the extension is in the list of supported extensions |
| 4308 | bool found = false; |
| 4309 | for (uint32_t j = 0; LOADER_INSTANCE_EXTENSIONS[j] != NULL; j++) { |
| 4310 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], |
| 4311 | LOADER_INSTANCE_EXTENSIONS[j]) == 0) { |
| 4312 | found = true; |
| 4313 | break; |
| 4314 | } |
| 4315 | } |
| 4316 | |
| 4317 | // If it isn't in the list, return an error |
| 4318 | if (!found) { |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4319 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4320 | "loader_validate_instance_extensions: Extension %d " |
| 4321 | "not found in list of available extensions.", |
| 4322 | i); |
Lenny Komow | 4053b81 | 2016-12-29 16:27:28 -0700 | [diff] [blame] | 4323 | return VK_ERROR_EXTENSION_NOT_PRESENT; |
| 4324 | } |
| 4325 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4326 | extension_prop = get_extension_property( |
| 4327 | pCreateInfo->ppEnabledExtensionNames[i], icd_exts); |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 4328 | |
| 4329 | if (extension_prop) { |
| 4330 | continue; |
| 4331 | } |
| 4332 | |
| 4333 | extension_prop = NULL; |
| 4334 | |
| 4335 | /* Not in global list, search layer extension lists */ |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 4336 | for (uint32_t j = 0; j < pCreateInfo->enabledLayerCount; j++) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4337 | layer_prop = loader_get_layer_property( |
Michael Jurka | 5c16c00 | 2016-12-19 16:31:43 +0100 | [diff] [blame] | 4338 | pCreateInfo->ppEnabledLayerNames[j], instance_layers); |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 4339 | if (!layer_prop) { |
Courtney Goeltzenleuchter | 6f5b00c | 2015-07-06 20:46:50 -0600 | [diff] [blame] | 4340 | /* Should NOT get here, loader_validate_layers |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 4341 | * should have already filtered this case out. |
| 4342 | */ |
| 4343 | continue; |
| 4344 | } |
| 4345 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4346 | extension_prop = |
| 4347 | get_extension_property(pCreateInfo->ppEnabledExtensionNames[i], |
| 4348 | &layer_prop->instance_extension_list); |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 4349 | if (extension_prop) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4350 | /* Found the extension in one of the layers enabled by the app. |
| 4351 | */ |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 4352 | break; |
| 4353 | } |
| 4354 | } |
| 4355 | |
| 4356 | if (!extension_prop) { |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4357 | // Didn't find extension name in any of the global layers, error out |
| 4358 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4359 | "loader_validate_instance_extensions: Extension %d " |
| 4360 | "not found in enabled layer list extensions.", |
| 4361 | i); |
Courtney Goeltzenleuchter | 55659b7 | 2015-09-14 18:01:17 -0600 | [diff] [blame] | 4362 | return VK_ERROR_EXTENSION_NOT_PRESENT; |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 4363 | } |
| 4364 | } |
| 4365 | return VK_SUCCESS; |
| 4366 | } |
| 4367 | |
| 4368 | VkResult loader_validate_device_extensions( |
Jon Ashburn | 787eb25 | 2016-03-24 15:49:57 -0600 | [diff] [blame] | 4369 | struct loader_physical_device_tramp *phys_dev, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4370 | const struct loader_layer_list *activated_device_layers, |
Jon Ashburn | 014438f | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 4371 | const struct loader_extension_list *icd_exts, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4372 | const VkDeviceCreateInfo *pCreateInfo) { |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 4373 | VkExtensionProperties *extension_prop; |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 4374 | struct loader_layer_properties *layer_prop; |
| 4375 | |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 4376 | for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) { |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 4377 | |
Jon Ashburn | f2b4e38 | 2016-02-10 20:50:19 -0700 | [diff] [blame] | 4378 | VkStringErrorFlags result = vk_string_validate( |
| 4379 | MaxLoaderStringLength, pCreateInfo->ppEnabledExtensionNames[i]); |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 4380 | if (result != VK_STRING_ERROR_NONE) { |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 4381 | loader_log(phys_dev->this_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4382 | 0, "loader_validate_device_extensions: Device " |
| 4383 | "ppEnabledExtensionNames contains " |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 4384 | "string that is too long or is badly formed"); |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 4385 | return VK_ERROR_EXTENSION_NOT_PRESENT; |
| 4386 | } |
| 4387 | |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 4388 | const char *extension_name = pCreateInfo->ppEnabledExtensionNames[i]; |
Jon Ashburn | 014438f | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 4389 | extension_prop = get_extension_property(extension_name, icd_exts); |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 4390 | |
| 4391 | if (extension_prop) { |
| 4392 | continue; |
| 4393 | } |
| 4394 | |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4395 | // Not in global list, search activated layer extension lists |
Jon Ashburn | 471f44c | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 4396 | for (uint32_t j = 0; j < activated_device_layers->count; j++) { |
| 4397 | layer_prop = &activated_device_layers->list[j]; |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 4398 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4399 | extension_prop = get_dev_extension_property( |
| 4400 | extension_name, &layer_prop->device_extension_list); |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 4401 | if (extension_prop) { |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4402 | // Found the extension in one of the layers enabled by the app. |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 4403 | break; |
| 4404 | } |
| 4405 | } |
| 4406 | |
| 4407 | if (!extension_prop) { |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4408 | // Didn't find extension name in any of the device layers, error out |
| 4409 | loader_log(phys_dev->this_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4410 | 0, "loader_validate_device_extensions: Extension %d " |
| 4411 | "not found in enabled layer list extensions.", |
| 4412 | i); |
Courtney Goeltzenleuchter | 55659b7 | 2015-09-14 18:01:17 -0600 | [diff] [blame] | 4413 | return VK_ERROR_EXTENSION_NOT_PRESENT; |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 4414 | } |
| 4415 | } |
Courtney Goeltzenleuchter | 3b8c5ff | 2015-07-06 17:45:08 -0600 | [diff] [blame] | 4416 | return VK_SUCCESS; |
| 4417 | } |
| 4418 | |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4419 | // Terminator functions for the Instance chain |
| 4420 | // All named terminator_<Vulakn API name> |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4421 | VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateInstance( |
| 4422 | const VkInstanceCreateInfo *pCreateInfo, |
| 4423 | const VkAllocationCallbacks *pAllocator, VkInstance *pInstance) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4424 | struct loader_icd_term *icd_term; |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 4425 | VkExtensionProperties *prop; |
Courtney Goeltzenleuchter | 746db73 | 2015-07-06 17:42:01 -0600 | [diff] [blame] | 4426 | char **filtered_extension_names = NULL; |
| 4427 | VkInstanceCreateInfo icd_create_info; |
Courtney Goeltzenleuchter | 40caf0b | 2015-07-06 09:06:34 -0600 | [diff] [blame] | 4428 | VkResult res = VK_SUCCESS; |
Mark Young | 8b4edb5 | 2016-11-11 09:31:55 -0700 | [diff] [blame] | 4429 | bool one_icd_successful = false; |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 4430 | |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 4431 | struct loader_instance *ptr_instance = (struct loader_instance *)*pInstance; |
Tony Barbour | 3c78ff4 | 2015-12-04 13:24:39 -0700 | [diff] [blame] | 4432 | memcpy(&icd_create_info, pCreateInfo, sizeof(icd_create_info)); |
| 4433 | |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 4434 | icd_create_info.enabledLayerCount = 0; |
Courtney Goeltzenleuchter | 746db73 | 2015-07-06 17:42:01 -0600 | [diff] [blame] | 4435 | icd_create_info.ppEnabledLayerNames = NULL; |
Courtney Goeltzenleuchter | 746db73 | 2015-07-06 17:42:01 -0600 | [diff] [blame] | 4436 | |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4437 | // NOTE: Need to filter the extensions to only those supported by the ICD. |
| 4438 | // No ICD will advertise support for layers. An ICD library could |
| 4439 | // support a layer, but it would be independent of the actual ICD, |
| 4440 | // just in the same library. |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4441 | filtered_extension_names = |
| 4442 | loader_stack_alloc(pCreateInfo->enabledExtensionCount * sizeof(char *)); |
Courtney Goeltzenleuchter | 746db73 | 2015-07-06 17:42:01 -0600 | [diff] [blame] | 4443 | if (!filtered_extension_names) { |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4444 | loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4445 | "terminator_CreateInstance: Failed create extension name " |
| 4446 | "array for %d extensions", |
| 4447 | pCreateInfo->enabledExtensionCount); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 4448 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 4449 | goto out; |
Courtney Goeltzenleuchter | 746db73 | 2015-07-06 17:42:01 -0600 | [diff] [blame] | 4450 | } |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4451 | icd_create_info.ppEnabledExtensionNames = |
| 4452 | (const char *const *)filtered_extension_names; |
Courtney Goeltzenleuchter | 746db73 | 2015-07-06 17:42:01 -0600 | [diff] [blame] | 4453 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4454 | for (uint32_t i = 0; i < ptr_instance->icd_tramp_list.count; i++) { |
| 4455 | icd_term = loader_icd_add( |
| 4456 | ptr_instance, &ptr_instance->icd_tramp_list.scanned_list[i]); |
| 4457 | if (NULL == icd_term) { |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 4458 | loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4459 | 0, |
| 4460 | "terminator_CreateInstance: Failed to add ICD %d to ICD " |
| 4461 | "trampoline list.", |
| 4462 | i); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 4463 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 4464 | goto out; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4465 | } |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 4466 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4467 | icd_create_info.enabledExtensionCount = 0; |
| 4468 | struct loader_extension_list icd_exts; |
Courtney Goeltzenleuchter | 746db73 | 2015-07-06 17:42:01 -0600 | [diff] [blame] | 4469 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4470 | loader_log(ptr_instance, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, |
| 4471 | "Build ICD instance extension list"); |
| 4472 | // traverse scanned icd list adding non-duplicate extensions to the |
| 4473 | // list |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 4474 | res = loader_init_generic_list(ptr_instance, |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4475 | (struct loader_generic_list *)&icd_exts, |
| 4476 | sizeof(VkExtensionProperties)); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 4477 | if (VK_ERROR_OUT_OF_HOST_MEMORY == res) { |
| 4478 | // If out of memory, bail immediately. |
| 4479 | goto out; |
| 4480 | } else if (VK_SUCCESS != res) { |
Mark Young | 7e47129 | 2016-09-06 09:53:45 -0600 | [diff] [blame] | 4481 | // Something bad happened with this ICD, so free it and try the |
| 4482 | // next. |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4483 | ptr_instance->icd_terms = icd_term->next; |
| 4484 | icd_term->next = NULL; |
| 4485 | loader_icd_destroy(ptr_instance, icd_term, pAllocator); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 4486 | continue; |
| 4487 | } |
| 4488 | |
| 4489 | res = loader_add_instance_extensions( |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4490 | ptr_instance, |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4491 | icd_term->scanned_icd->EnumerateInstanceExtensionProperties, |
| 4492 | icd_term->scanned_icd->lib_name, &icd_exts); |
Mark Young | db13a2a | 2016-09-06 13:53:03 -0600 | [diff] [blame] | 4493 | if (VK_SUCCESS != res) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4494 | loader_destroy_generic_list( |
| 4495 | ptr_instance, (struct loader_generic_list *)&icd_exts); |
Mark Young | db13a2a | 2016-09-06 13:53:03 -0600 | [diff] [blame] | 4496 | if (VK_ERROR_OUT_OF_HOST_MEMORY == res) { |
| 4497 | // If out of memory, bail immediately. |
| 4498 | goto out; |
| 4499 | } else { |
| 4500 | // Something bad happened with this ICD, so free it and try |
| 4501 | // the next. |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4502 | ptr_instance->icd_terms = icd_term->next; |
| 4503 | icd_term->next = NULL; |
| 4504 | loader_icd_destroy(ptr_instance, icd_term, pAllocator); |
Mark Young | db13a2a | 2016-09-06 13:53:03 -0600 | [diff] [blame] | 4505 | continue; |
| 4506 | } |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 4507 | } |
Courtney Goeltzenleuchter | 36eeb74 | 2015-12-21 16:41:47 -0700 | [diff] [blame] | 4508 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4509 | for (uint32_t j = 0; j < pCreateInfo->enabledExtensionCount; j++) { |
| 4510 | prop = get_extension_property( |
| 4511 | pCreateInfo->ppEnabledExtensionNames[j], &icd_exts); |
| 4512 | if (prop) { |
| 4513 | filtered_extension_names[icd_create_info |
| 4514 | .enabledExtensionCount] = |
| 4515 | (char *)pCreateInfo->ppEnabledExtensionNames[j]; |
| 4516 | icd_create_info.enabledExtensionCount++; |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 4517 | } |
| 4518 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4519 | |
| 4520 | loader_destroy_generic_list(ptr_instance, |
| 4521 | (struct loader_generic_list *)&icd_exts); |
| 4522 | |
Mark Young | 8b4edb5 | 2016-11-11 09:31:55 -0700 | [diff] [blame] | 4523 | VkResult icd_result = |
| 4524 | ptr_instance->icd_tramp_list.scanned_list[i].CreateInstance( |
| 4525 | &icd_create_info, pAllocator, &(icd_term->instance)); |
| 4526 | if (VK_ERROR_OUT_OF_HOST_MEMORY == icd_result) { |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 4527 | // If out of memory, bail immediately. |
Mark Young | 8b4edb5 | 2016-11-11 09:31:55 -0700 | [diff] [blame] | 4528 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 4529 | goto out; |
Mark Young | 8b4edb5 | 2016-11-11 09:31:55 -0700 | [diff] [blame] | 4530 | } else if (VK_SUCCESS != icd_result) { |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 4531 | loader_log(ptr_instance, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4532 | "terminator_CreateInstance: Failed to CreateInstance in " |
| 4533 | "ICD %d. Skipping ICD.", |
| 4534 | i); |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4535 | ptr_instance->icd_terms = icd_term->next; |
| 4536 | icd_term->next = NULL; |
| 4537 | loader_icd_destroy(ptr_instance, icd_term, pAllocator); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 4538 | continue; |
| 4539 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4540 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4541 | if (!loader_icd_init_entrys(icd_term, icd_term->instance, |
| 4542 | ptr_instance->icd_tramp_list.scanned_list[i] |
| 4543 | .GetInstanceProcAddr)) { |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4544 | loader_log( |
| 4545 | ptr_instance, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 4546 | "terminator_CreateInstance: Failed to CreateInstance and find " |
| 4547 | "entrypoints with ICD. Skipping ICD."); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 4548 | continue; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4549 | } |
Mark Young | 8b4edb5 | 2016-11-11 09:31:55 -0700 | [diff] [blame] | 4550 | |
| 4551 | // If we made it this far, at least one ICD was successful |
| 4552 | one_icd_successful = true; |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 4553 | } |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 4554 | |
Mark Young | 8b4edb5 | 2016-11-11 09:31:55 -0700 | [diff] [blame] | 4555 | // If no ICDs were added to instance list and res is unchanged |
| 4556 | // from it's initial value, the loader was unable to find |
| 4557 | // a suitable ICD. |
| 4558 | if (VK_SUCCESS == res && |
| 4559 | (ptr_instance->icd_terms == NULL || !one_icd_successful)) { |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 4560 | res = VK_ERROR_INCOMPATIBLE_DRIVER; |
| 4561 | } |
| 4562 | |
| 4563 | out: |
| 4564 | |
| 4565 | if (VK_SUCCESS != res) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4566 | while (NULL != ptr_instance->icd_terms) { |
| 4567 | icd_term = ptr_instance->icd_terms; |
| 4568 | ptr_instance->icd_terms = icd_term->next; |
| 4569 | if (NULL != icd_term->instance) { |
| 4570 | icd_term->DestroyInstance(icd_term->instance, pAllocator); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 4571 | } |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4572 | loader_icd_destroy(ptr_instance, icd_term, pAllocator); |
Courtney Goeltzenleuchter | 40caf0b | 2015-07-06 09:06:34 -0600 | [diff] [blame] | 4573 | } |
Ian Elliott | eb45076 | 2015-02-05 15:19:15 -0700 | [diff] [blame] | 4574 | } |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 4575 | |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 4576 | return res; |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 4577 | } |
| 4578 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4579 | VKAPI_ATTR void VKAPI_CALL terminator_DestroyInstance( |
| 4580 | VkInstance instance, const VkAllocationCallbacks *pAllocator) { |
Courtney Goeltzenleuchter | deceded | 2015-06-08 15:04:02 -0600 | [diff] [blame] | 4581 | struct loader_instance *ptr_instance = loader_instance(instance); |
Karl Schultz | e2ef9e6 | 2017-01-13 14:01:35 -0700 | [diff] [blame] | 4582 | if (NULL == ptr_instance) { |
| 4583 | return; |
| 4584 | } |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4585 | struct loader_icd_term *icd_terms = ptr_instance->icd_terms; |
| 4586 | struct loader_icd_term *next_icd_term; |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 4587 | |
| 4588 | // Remove this instance from the list of instances: |
| 4589 | struct loader_instance *prev = NULL; |
| 4590 | struct loader_instance *next = loader.instances; |
| 4591 | while (next != NULL) { |
| 4592 | if (next == ptr_instance) { |
| 4593 | // Remove this instance from the list: |
| 4594 | if (prev) |
| 4595 | prev->next = next->next; |
Jon Ashburn | c5c4960 | 2015-02-03 09:26:59 -0700 | [diff] [blame] | 4596 | else |
| 4597 | loader.instances = next->next; |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 4598 | break; |
| 4599 | } |
| 4600 | prev = next; |
| 4601 | next = next->next; |
| 4602 | } |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 4603 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4604 | while (NULL != icd_terms) { |
| 4605 | if (icd_terms->instance) { |
| 4606 | icd_terms->DestroyInstance(icd_terms->instance, pAllocator); |
Tony Barbour | f20f87b | 2015-04-22 09:02:32 -0600 | [diff] [blame] | 4607 | } |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4608 | next_icd_term = icd_terms->next; |
| 4609 | icd_terms->instance = VK_NULL_HANDLE; |
| 4610 | loader_icd_destroy(ptr_instance, icd_terms, pAllocator); |
Jon Ashburn | a6fd261 | 2015-06-16 14:43:19 -0600 | [diff] [blame] | 4611 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4612 | icd_terms = next_icd_term; |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 4613 | } |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 4614 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4615 | loader_delete_layer_properties(ptr_instance, |
| 4616 | &ptr_instance->instance_layer_list); |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4617 | loader_scanned_icd_clear(ptr_instance, &ptr_instance->icd_tramp_list); |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4618 | loader_destroy_generic_list( |
| 4619 | ptr_instance, (struct loader_generic_list *)&ptr_instance->ext_list); |
Lenny Komow | 8a1f8a5 | 2016-12-20 15:35:11 -0700 | [diff] [blame] | 4620 | if (ptr_instance->phys_devs_term) { |
Mark Young | 0193d65 | 2016-12-28 16:10:10 -0700 | [diff] [blame] | 4621 | for (uint32_t i = 0; i < ptr_instance->phys_dev_count_term; i++) { |
Lenny Komow | 8a1f8a5 | 2016-12-20 15:35:11 -0700 | [diff] [blame] | 4622 | loader_instance_heap_free(ptr_instance, |
| 4623 | ptr_instance->phys_devs_term[i]); |
| 4624 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4625 | loader_instance_heap_free(ptr_instance, ptr_instance->phys_devs_term); |
Lenny Komow | 8a1f8a5 | 2016-12-20 15:35:11 -0700 | [diff] [blame] | 4626 | } |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 4627 | loader_free_dev_ext_table(ptr_instance); |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 4628 | } |
| 4629 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4630 | VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateDevice( |
| 4631 | VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo *pCreateInfo, |
| 4632 | const VkAllocationCallbacks *pAllocator, VkDevice *pDevice) { |
| 4633 | VkResult res = VK_SUCCESS; |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4634 | struct loader_physical_device_term *phys_dev_term; |
| 4635 | phys_dev_term = (struct loader_physical_device_term *)physicalDevice; |
| 4636 | struct loader_icd_term *icd_term = phys_dev_term->this_icd_term; |
Jon Ashburn | 24cd4be | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 4637 | |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 4638 | struct loader_device *dev = (struct loader_device *)*pDevice; |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4639 | PFN_vkCreateDevice fpCreateDevice = icd_term->CreateDevice; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4640 | struct loader_extension_list icd_exts; |
| 4641 | |
Mark Young | 65cb366 | 2016-11-07 13:27:02 -0700 | [diff] [blame] | 4642 | dev->phys_dev_term = phys_dev_term; |
| 4643 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4644 | icd_exts.list = NULL; |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 4645 | |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 4646 | if (fpCreateDevice == NULL) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4647 | loader_log(icd_term->this_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4648 | "terminator_CreateDevice: No vkCreateDevice command exposed " |
| 4649 | "by ICD %s", |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4650 | icd_term->scanned_icd->lib_name); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4651 | res = VK_ERROR_INITIALIZATION_FAILED; |
| 4652 | goto out; |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 4653 | } |
| 4654 | |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 4655 | VkDeviceCreateInfo localCreateInfo; |
| 4656 | memcpy(&localCreateInfo, pCreateInfo, sizeof(localCreateInfo)); |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 4657 | |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4658 | // NOTE: Need to filter the extensions to only those supported by the ICD. |
| 4659 | // No ICD will advertise support for layers. An ICD library could |
| 4660 | // support a layer, but it would be independent of the actual ICD, |
| 4661 | // just in the same library. |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 4662 | char **filtered_extension_names = NULL; |
| 4663 | filtered_extension_names = |
| 4664 | loader_stack_alloc(pCreateInfo->enabledExtensionCount * sizeof(char *)); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4665 | if (NULL == filtered_extension_names) { |
| 4666 | loader_log(icd_term->this_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4667 | "terminator_CreateDevice: Failed to create extension name " |
| 4668 | "storage for %d extensions %d", |
| 4669 | pCreateInfo->enabledExtensionCount); |
Jon Ashburn | 24cd4be | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 4670 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 4671 | } |
| 4672 | |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 4673 | localCreateInfo.enabledLayerCount = 0; |
| 4674 | localCreateInfo.ppEnabledLayerNames = NULL; |
| 4675 | |
| 4676 | localCreateInfo.enabledExtensionCount = 0; |
| 4677 | localCreateInfo.ppEnabledExtensionNames = |
| 4678 | (const char *const *)filtered_extension_names; |
| 4679 | |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4680 | // Get the physical device (ICD) extensions |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4681 | res = loader_init_generic_list(icd_term->this_instance, |
| 4682 | (struct loader_generic_list *)&icd_exts, |
| 4683 | sizeof(VkExtensionProperties)); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 4684 | if (VK_SUCCESS != res) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4685 | goto out; |
Jon Ashburn | 014438f | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 4686 | } |
| 4687 | |
| 4688 | res = loader_add_device_extensions( |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4689 | icd_term->this_instance, icd_term->EnumerateDeviceExtensionProperties, |
| 4690 | phys_dev_term->phys_dev, icd_term->scanned_icd->lib_name, &icd_exts); |
Jon Ashburn | 014438f | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 4691 | if (res != VK_SUCCESS) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4692 | goto out; |
Jon Ashburn | 014438f | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 4693 | } |
| 4694 | |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 4695 | for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) { |
| 4696 | const char *extension_name = pCreateInfo->ppEnabledExtensionNames[i]; |
Jon Ashburn | 014438f | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 4697 | VkExtensionProperties *prop = |
| 4698 | get_extension_property(extension_name, &icd_exts); |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 4699 | if (prop) { |
| 4700 | filtered_extension_names[localCreateInfo.enabledExtensionCount] = |
| 4701 | (char *)extension_name; |
| 4702 | localCreateInfo.enabledExtensionCount++; |
Mark Young | 9a3ddd4 | 2016-10-21 16:25:47 -0600 | [diff] [blame] | 4703 | } else { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4704 | loader_log(icd_term->this_instance, VK_DEBUG_REPORT_WARNING_BIT_EXT, |
| 4705 | 0, "vkCreateDevice extension %s not available for " |
| 4706 | "devices associated with ICD %s", |
| 4707 | extension_name, icd_term->scanned_icd->lib_name); |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 4708 | } |
| 4709 | } |
| 4710 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4711 | res = fpCreateDevice(phys_dev_term->phys_dev, &localCreateInfo, pAllocator, |
Mark Young | 65cb366 | 2016-11-07 13:27:02 -0700 | [diff] [blame] | 4712 | &dev->icd_device); |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 4713 | if (res != VK_SUCCESS) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4714 | loader_log(icd_term->this_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4715 | "terminator_CreateDevice: Failed in ICD %s vkCreateDevice" |
| 4716 | "call", |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4717 | icd_term->scanned_icd->lib_name); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4718 | goto out; |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 4719 | } |
| 4720 | |
Mark Young | 65cb366 | 2016-11-07 13:27:02 -0700 | [diff] [blame] | 4721 | *pDevice = dev->icd_device; |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4722 | loader_add_logical_device(icd_term->this_instance, icd_term, dev); |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 4723 | |
| 4724 | /* Init dispatch pointer in new device object */ |
| 4725 | loader_init_dispatch(*pDevice, &dev->loader_dispatch); |
| 4726 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4727 | out: |
| 4728 | if (NULL != icd_exts.list) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4729 | loader_destroy_generic_list(icd_term->this_instance, |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4730 | (struct loader_generic_list *)&icd_exts); |
| 4731 | } |
| 4732 | |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 4733 | return res; |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 4734 | } |
| 4735 | |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 4736 | VkResult setupLoaderTrampPhysDevs(VkInstance instance) { |
Jon Ashburn | 24cd4be | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 4737 | VkResult res = VK_SUCCESS; |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 4738 | VkPhysicalDevice *local_phys_devs = NULL; |
| 4739 | struct loader_instance *inst; |
| 4740 | uint32_t total_count = 0; |
| 4741 | struct loader_physical_device_tramp **new_phys_devs = NULL; |
Jon Ashburn | 4c392fb | 2015-01-28 19:57:09 -0700 | [diff] [blame] | 4742 | |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 4743 | inst = loader_get_instance(instance); |
| 4744 | if (NULL == inst) { |
| 4745 | res = VK_ERROR_INITIALIZATION_FAILED; |
| 4746 | goto out; |
| 4747 | } |
| 4748 | total_count = inst->total_gpu_count; |
| 4749 | |
| 4750 | // Create an array for the new physical devices, which will be stored |
| 4751 | // in the instance for the trampoline code. |
| 4752 | new_phys_devs = |
| 4753 | (struct loader_physical_device_tramp **)loader_instance_heap_alloc( |
| 4754 | inst, |
| 4755 | total_count * sizeof(struct loader_physical_device_tramp *), |
| 4756 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
| 4757 | if (NULL == new_phys_devs) { |
Lenny Komow | 5e4ad10 | 2017-01-12 15:47:53 -0700 | [diff] [blame] | 4758 | loader_log( |
| 4759 | inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 4760 | "setupLoaderTrampPhysDevs: Failed to allocate new physical device" |
| 4761 | " array of size %d", |
Lenny Komow | 5e4ad10 | 2017-01-12 15:47:53 -0700 | [diff] [blame] | 4762 | total_count); |
Mark Young | d8382d7 | 2016-12-23 16:59:58 -0700 | [diff] [blame] | 4763 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 4764 | goto out; |
| 4765 | } |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 4766 | memset(new_phys_devs, 0, |
| 4767 | total_count * sizeof(struct loader_physical_device_tramp *)); |
Jon Ashburn | 014438f | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 4768 | |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 4769 | // Create a temporary array (on the stack) to keep track of the |
| 4770 | // returned VkPhysicalDevice values. |
| 4771 | local_phys_devs = |
| 4772 | loader_stack_alloc(sizeof(VkPhysicalDevice) * total_count); |
| 4773 | if (NULL == local_phys_devs) { |
| 4774 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4775 | "setupLoaderTrampPhysDevs: Failed to allocate local " |
| 4776 | "physical device array of size %d", |
| 4777 | total_count); |
| 4778 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 4779 | goto out; |
| 4780 | } |
| 4781 | memset(local_phys_devs, 0, sizeof(VkPhysicalDevice) * total_count); |
| 4782 | |
| 4783 | res = inst->disp->EnumeratePhysicalDevices(instance, &total_count, |
| 4784 | local_phys_devs); |
| 4785 | if (VK_SUCCESS != res) { |
| 4786 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4787 | "setupLoaderTrampPhysDevs: Failed during dispatch call " |
| 4788 | "of \'vkEnumeratePhysicalDevices\' to lower layers or " |
| 4789 | "loader."); |
| 4790 | goto out; |
| 4791 | } |
| 4792 | |
| 4793 | // Copy or create everything to fill the new array of physical devices |
| 4794 | for (uint32_t new_idx = 0; new_idx < total_count; new_idx++) { |
| 4795 | |
| 4796 | // Check if this physical device is already in the old buffer |
| 4797 | for (uint32_t old_idx = 0; |
| 4798 | old_idx < inst->phys_dev_count_tramp; |
| 4799 | old_idx++) { |
| 4800 | if (local_phys_devs[new_idx] == |
| 4801 | inst->phys_devs_tramp[old_idx]->phys_dev) { |
| 4802 | new_phys_devs[new_idx] = inst->phys_devs_tramp[old_idx]; |
| 4803 | break; |
| 4804 | } |
Mark Young | d8382d7 | 2016-12-23 16:59:58 -0700 | [diff] [blame] | 4805 | } |
| 4806 | |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 4807 | // If this physical device isn't in the old buffer, create it |
| 4808 | if (NULL == new_phys_devs[new_idx]) { |
| 4809 | new_phys_devs[new_idx] = (struct loader_physical_device_tramp *) |
| 4810 | loader_instance_heap_alloc( |
| 4811 | inst, sizeof(struct loader_physical_device_tramp), |
| 4812 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
| 4813 | if (NULL == new_phys_devs[new_idx]) { |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4814 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 4815 | "setupLoaderTrampPhysDevs: Failed to allocate " |
| 4816 | "physical device trampoline object %d", |
| 4817 | new_idx); |
| 4818 | total_count = new_idx; |
Mark Young | d8382d7 | 2016-12-23 16:59:58 -0700 | [diff] [blame] | 4819 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 4820 | goto out; |
| 4821 | } |
| 4822 | |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 4823 | // Initialize the new physicalDevice object |
| 4824 | loader_set_dispatch((void *)new_phys_devs[new_idx], inst->disp); |
| 4825 | new_phys_devs[new_idx]->this_instance = inst; |
| 4826 | new_phys_devs[new_idx]->phys_dev = local_phys_devs[new_idx]; |
Mark Young | 559d750 | 2016-09-26 11:38:46 -0600 | [diff] [blame] | 4827 | } |
Lenny Komow | a5e0112 | 2016-12-22 15:29:43 -0700 | [diff] [blame] | 4828 | } |
Mark Young | 559d750 | 2016-09-26 11:38:46 -0600 | [diff] [blame] | 4829 | |
Lenny Komow | a5e0112 | 2016-12-22 15:29:43 -0700 | [diff] [blame] | 4830 | out: |
Mark Young | d8382d7 | 2016-12-23 16:59:58 -0700 | [diff] [blame] | 4831 | |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 4832 | if (VK_SUCCESS != res) { |
| 4833 | if (NULL != new_phys_devs) { |
| 4834 | for (uint32_t i = 0; i < total_count; i++) { |
| 4835 | loader_instance_heap_free(inst, new_phys_devs[i]); |
Lenny Komow | a5e0112 | 2016-12-22 15:29:43 -0700 | [diff] [blame] | 4836 | } |
| 4837 | loader_instance_heap_free(inst, new_phys_devs); |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 4838 | } |
| 4839 | total_count = 0; |
| 4840 | } else { |
| 4841 | // Free everything that didn't carry over to the new array of |
| 4842 | // physical devices |
| 4843 | if (NULL != inst->phys_devs_tramp) { |
| 4844 | for (uint32_t i = 0; i < inst->phys_dev_count_tramp; i++) { |
| 4845 | bool found = false; |
| 4846 | for (uint32_t j = 0; j < total_count; j++) { |
| 4847 | if (inst->phys_devs_tramp[i] == new_phys_devs[j]) { |
| 4848 | found = true; |
| 4849 | break; |
| 4850 | } |
| 4851 | } |
| 4852 | if (!found) { |
| 4853 | loader_instance_heap_free(inst, |
| 4854 | inst->phys_devs_tramp[i]); |
| 4855 | } |
| 4856 | } |
| 4857 | loader_instance_heap_free(inst, inst->phys_devs_tramp); |
| 4858 | } |
Mark Young | d8382d7 | 2016-12-23 16:59:58 -0700 | [diff] [blame] | 4859 | |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 4860 | // Swap in the new physical device list |
| 4861 | inst->phys_dev_count_tramp = total_count; |
| 4862 | inst->phys_devs_tramp = new_phys_devs; |
| 4863 | } |
| 4864 | |
| 4865 | return res; |
| 4866 | } |
| 4867 | |
| 4868 | VkResult setupLoaderTermPhysDevs(struct loader_instance *inst) { |
| 4869 | VkResult res = VK_SUCCESS; |
| 4870 | struct loader_icd_term *icd_term; |
| 4871 | struct loader_phys_dev_per_icd *icd_phys_dev_array = NULL; |
| 4872 | struct loader_physical_device_term **new_phys_devs = NULL; |
| 4873 | uint32_t i = 0; |
| 4874 | |
| 4875 | inst->total_gpu_count = 0; |
| 4876 | |
| 4877 | // Allocate something to store the physical device characteristics |
| 4878 | // that we read from each ICD. |
| 4879 | icd_phys_dev_array = (struct loader_phys_dev_per_icd *)loader_stack_alloc( |
| 4880 | sizeof(struct loader_phys_dev_per_icd) * inst->total_icd_count); |
| 4881 | if (NULL == icd_phys_dev_array) { |
| 4882 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4883 | "setupLoaderTermPhysDevs: Failed to allocate temporary " |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 4884 | "ICD Physical device info array of size %d", |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 4885 | inst->total_gpu_count); |
| 4886 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 4887 | goto out; |
| 4888 | } |
| 4889 | memset(icd_phys_dev_array, 0, |
| 4890 | sizeof(struct loader_phys_dev_per_icd) * inst->total_icd_count); |
| 4891 | icd_term = inst->icd_terms; |
| 4892 | |
| 4893 | // For each ICD, query the number of physical devices, and then get an |
| 4894 | // internal value for those physical devices. |
| 4895 | while (NULL != icd_term) { |
| 4896 | res = icd_term->EnumeratePhysicalDevices( |
| 4897 | icd_term->instance, &icd_phys_dev_array[i].count, NULL); |
| 4898 | if (VK_SUCCESS != res) { |
| 4899 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4900 | "setupLoaderTermPhysDevs: Call to " |
| 4901 | "ICD %d's \'vkEnumeratePhysicalDevices\' failed with" |
| 4902 | " error 0x%08x", |
| 4903 | i, res); |
| 4904 | goto out; |
| 4905 | } |
| 4906 | |
| 4907 | icd_phys_dev_array[i].phys_devs = |
| 4908 | (VkPhysicalDevice *)loader_stack_alloc(icd_phys_dev_array[i].count * |
| 4909 | sizeof(VkPhysicalDevice)); |
| 4910 | if (NULL == icd_phys_dev_array[i].phys_devs) { |
| 4911 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4912 | "setupLoaderTermPhysDevs: Failed to allocate temporary " |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 4913 | "ICD Physical device array for ICD %d of size %d", |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 4914 | i, inst->total_gpu_count); |
| 4915 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 4916 | goto out; |
| 4917 | } |
| 4918 | |
| 4919 | res = icd_term->EnumeratePhysicalDevices( |
| 4920 | icd_term->instance, &(icd_phys_dev_array[i].count), |
| 4921 | icd_phys_dev_array[i].phys_devs); |
| 4922 | if (VK_SUCCESS != res) { |
| 4923 | goto out; |
| 4924 | } |
| 4925 | inst->total_gpu_count += icd_phys_dev_array[i].count; |
| 4926 | icd_phys_dev_array[i].this_icd_term = icd_term; |
| 4927 | |
| 4928 | icd_term = icd_term->next; |
| 4929 | i++; |
| 4930 | } |
| 4931 | |
| 4932 | if (0 == inst->total_gpu_count) { |
| 4933 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4934 | "setupLoaderTermPhysDevs: Failed to detect any valid" |
| 4935 | " GPUs in the current config"); |
| 4936 | res = VK_ERROR_INITIALIZATION_FAILED; |
| 4937 | goto out; |
| 4938 | } |
| 4939 | |
| 4940 | new_phys_devs = loader_instance_heap_alloc( |
| 4941 | inst, |
| 4942 | sizeof(struct loader_physical_device_term *) * inst->total_gpu_count, |
| 4943 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
| 4944 | if (NULL == new_phys_devs) { |
| 4945 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4946 | "setupLoaderTermPhysDevs: Failed to allocate new physical" |
| 4947 | " device array of size %d", |
| 4948 | inst->total_gpu_count); |
| 4949 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 4950 | goto out; |
| 4951 | } |
| 4952 | memset(new_phys_devs, 0, sizeof(struct loader_physical_device_term *) * |
| 4953 | inst->total_gpu_count); |
| 4954 | |
| 4955 | // Copy or create everything to fill the new array of physical devices |
| 4956 | uint32_t idx = 0; |
| 4957 | for (uint32_t icd_idx = 0; icd_idx < inst->total_icd_count; icd_idx++) { |
| 4958 | for (uint32_t pd_idx = 0; pd_idx < icd_phys_dev_array[icd_idx].count; |
| 4959 | pd_idx++) { |
| 4960 | |
| 4961 | // Check if this physical device is already in the old buffer |
| 4962 | if (NULL != inst->phys_devs_term) { |
| 4963 | for (uint32_t old_idx = 0; |
| 4964 | old_idx < inst->phys_dev_count_term; |
| 4965 | old_idx++) { |
| 4966 | if (icd_phys_dev_array[icd_idx].phys_devs[pd_idx] == |
| 4967 | inst->phys_devs_term[old_idx]->phys_dev) { |
| 4968 | new_phys_devs[idx] = inst->phys_devs_term[old_idx]; |
| 4969 | break; |
| 4970 | } |
| 4971 | } |
| 4972 | } |
| 4973 | // If this physical device isn't in the old buffer, then we |
| 4974 | // need to create it. |
| 4975 | if (NULL == new_phys_devs[idx]) { |
| 4976 | new_phys_devs[idx] = loader_instance_heap_alloc( |
| 4977 | inst, sizeof(struct loader_physical_device_term), |
| 4978 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
| 4979 | if (NULL == new_phys_devs[idx]) { |
| 4980 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4981 | "setupLoaderTermPhysDevs: Failed to allocate " |
| 4982 | "physical device terminator object %d", |
| 4983 | idx); |
| 4984 | inst->total_gpu_count = idx; |
| 4985 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 4986 | goto out; |
| 4987 | } |
| 4988 | |
| 4989 | loader_set_dispatch((void *)new_phys_devs[idx], inst->disp); |
| 4990 | new_phys_devs[idx]->this_icd_term = |
| 4991 | icd_phys_dev_array[icd_idx].this_icd_term; |
| 4992 | new_phys_devs[idx]->icd_index = (uint8_t)(icd_idx); |
| 4993 | new_phys_devs[idx]->phys_dev = |
| 4994 | icd_phys_dev_array[icd_idx].phys_devs[pd_idx]; |
| 4995 | } |
| 4996 | idx++; |
| 4997 | } |
| 4998 | } |
| 4999 | |
| 5000 | out: |
| 5001 | |
| 5002 | if (VK_SUCCESS != res) { |
| 5003 | if (NULL != inst->phys_devs_term) { |
| 5004 | // We've encountered an error, so we should free the |
| 5005 | // new buffers. |
| 5006 | for (uint32_t i = 0; i < inst->total_gpu_count; i++) { |
| 5007 | loader_instance_heap_free(inst, new_phys_devs[i]); |
| 5008 | } |
| 5009 | loader_instance_heap_free(inst, inst->phys_devs_term); |
| 5010 | inst->total_gpu_count = 0; |
| 5011 | } |
| 5012 | } else { |
| 5013 | // Free everything that didn't carry over to the new array of |
| 5014 | // physical devices. Everything else will have been copied over |
| 5015 | // to the new array. |
| 5016 | if (NULL != inst->phys_devs_term) { |
| 5017 | for (uint32_t cur_pd = 0; cur_pd < inst->phys_dev_count_term; |
| 5018 | cur_pd++) { |
| 5019 | bool found = false; |
| 5020 | for (uint32_t new_pd_idx = 0; |
| 5021 | new_pd_idx < inst->total_gpu_count; |
| 5022 | new_pd_idx++) { |
| 5023 | if (inst->phys_devs_term[cur_pd] == |
| 5024 | new_phys_devs[new_pd_idx]) { |
| 5025 | found = true; |
| 5026 | break; |
| 5027 | } |
| 5028 | } |
| 5029 | if (!found) { |
| 5030 | loader_instance_heap_free(inst, |
| 5031 | inst->phys_devs_term[cur_pd]); |
| 5032 | } |
| 5033 | } |
| 5034 | loader_instance_heap_free(inst, inst->phys_devs_term); |
| 5035 | } |
| 5036 | |
| 5037 | // Swap out old and new devices list |
| 5038 | inst->phys_dev_count_term = inst->total_gpu_count; |
| 5039 | inst->phys_devs_term = new_phys_devs; |
| 5040 | } |
| 5041 | |
| 5042 | return res; |
| 5043 | } |
| 5044 | |
| 5045 | VKAPI_ATTR VkResult VKAPI_CALL terminator_EnumeratePhysicalDevices( |
| 5046 | VkInstance instance, uint32_t *pPhysicalDeviceCount, |
| 5047 | VkPhysicalDevice *pPhysicalDevices) { |
| 5048 | struct loader_instance *inst = (struct loader_instance *)instance; |
| 5049 | VkResult res = VK_SUCCESS; |
| 5050 | |
| 5051 | // Only do the setup if we're re-querying the number of devices, or |
| 5052 | // our count is currently 0. |
| 5053 | if (NULL == pPhysicalDevices || 0 == inst->total_gpu_count) { |
| 5054 | res = setupLoaderTermPhysDevs(inst); |
| 5055 | if (VK_SUCCESS != res) { |
| 5056 | goto out; |
| 5057 | } |
| 5058 | } |
| 5059 | |
| 5060 | uint32_t copy_count = inst->total_gpu_count; |
| 5061 | if (NULL != pPhysicalDevices) { |
| 5062 | if (copy_count > *pPhysicalDeviceCount) { |
| 5063 | copy_count = *pPhysicalDeviceCount; |
| 5064 | res = VK_INCOMPLETE; |
| 5065 | } |
| 5066 | |
| 5067 | for (uint32_t i = 0; i < copy_count; i++) { |
| 5068 | pPhysicalDevices[i] = (VkPhysicalDevice)inst->phys_devs_term[i]; |
Jon Ashburn | 014438f | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 5069 | } |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 5070 | } |
Mark Young | 559d750 | 2016-09-26 11:38:46 -0600 | [diff] [blame] | 5071 | |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 5072 | *pPhysicalDeviceCount = copy_count; |
| 5073 | |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5074 | out: |
| 5075 | |
Jon Ashburn | 24cd4be | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 5076 | return res; |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 5077 | } |
| 5078 | |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 5079 | VKAPI_ATTR void VKAPI_CALL terminator_GetPhysicalDeviceProperties( |
| 5080 | VkPhysicalDevice physicalDevice, VkPhysicalDeviceProperties *pProperties) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5081 | struct loader_physical_device_term *phys_dev_term = |
| 5082 | (struct loader_physical_device_term *)physicalDevice; |
| 5083 | struct loader_icd_term *icd_term = phys_dev_term->this_icd_term; |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5084 | if (NULL != icd_term->GetPhysicalDeviceProperties) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5085 | icd_term->GetPhysicalDeviceProperties(phys_dev_term->phys_dev, |
| 5086 | pProperties); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5087 | } |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 5088 | } |
| 5089 | |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 5090 | VKAPI_ATTR void VKAPI_CALL terminator_GetPhysicalDeviceQueueFamilyProperties( |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 5091 | VkPhysicalDevice physicalDevice, uint32_t *pQueueFamilyPropertyCount, |
| 5092 | VkQueueFamilyProperties *pProperties) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5093 | struct loader_physical_device_term *phys_dev_term = |
| 5094 | (struct loader_physical_device_term *)physicalDevice; |
| 5095 | struct loader_icd_term *icd_term = phys_dev_term->this_icd_term; |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5096 | if (NULL != icd_term->GetPhysicalDeviceQueueFamilyProperties) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5097 | icd_term->GetPhysicalDeviceQueueFamilyProperties( |
| 5098 | phys_dev_term->phys_dev, pQueueFamilyPropertyCount, pProperties); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5099 | } |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 5100 | } |
| 5101 | |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 5102 | VKAPI_ATTR void VKAPI_CALL terminator_GetPhysicalDeviceMemoryProperties( |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 5103 | VkPhysicalDevice physicalDevice, |
| 5104 | VkPhysicalDeviceMemoryProperties *pProperties) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5105 | struct loader_physical_device_term *phys_dev_term = |
| 5106 | (struct loader_physical_device_term *)physicalDevice; |
| 5107 | struct loader_icd_term *icd_term = phys_dev_term->this_icd_term; |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5108 | if (NULL != icd_term->GetPhysicalDeviceMemoryProperties) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5109 | icd_term->GetPhysicalDeviceMemoryProperties(phys_dev_term->phys_dev, |
| 5110 | pProperties); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5111 | } |
Jon Ashburn | 3da71f2 | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 5112 | } |
| 5113 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5114 | VKAPI_ATTR void VKAPI_CALL terminator_GetPhysicalDeviceFeatures( |
| 5115 | VkPhysicalDevice physicalDevice, VkPhysicalDeviceFeatures *pFeatures) { |
| 5116 | struct loader_physical_device_term *phys_dev_term = |
| 5117 | (struct loader_physical_device_term *)physicalDevice; |
| 5118 | struct loader_icd_term *icd_term = phys_dev_term->this_icd_term; |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5119 | if (NULL != icd_term->GetPhysicalDeviceFeatures) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5120 | icd_term->GetPhysicalDeviceFeatures(phys_dev_term->phys_dev, pFeatures); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5121 | } |
Chris Forbes | bc0bb77 | 2015-06-21 22:55:02 +1200 | [diff] [blame] | 5122 | } |
| 5123 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5124 | VKAPI_ATTR void VKAPI_CALL terminator_GetPhysicalDeviceFormatProperties( |
| 5125 | VkPhysicalDevice physicalDevice, VkFormat format, |
| 5126 | VkFormatProperties *pFormatInfo) { |
| 5127 | struct loader_physical_device_term *phys_dev_term = |
| 5128 | (struct loader_physical_device_term *)physicalDevice; |
| 5129 | struct loader_icd_term *icd_term = phys_dev_term->this_icd_term; |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5130 | if (NULL != icd_term->GetPhysicalDeviceFormatProperties) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5131 | icd_term->GetPhysicalDeviceFormatProperties(phys_dev_term->phys_dev, |
| 5132 | format, pFormatInfo); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5133 | } |
Chris Forbes | bc0bb77 | 2015-06-21 22:55:02 +1200 | [diff] [blame] | 5134 | } |
| 5135 | |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 5136 | VKAPI_ATTR VkResult VKAPI_CALL |
| 5137 | terminator_GetPhysicalDeviceImageFormatProperties( |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 5138 | VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, |
| 5139 | VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags, |
| 5140 | VkImageFormatProperties *pImageFormatProperties) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5141 | struct loader_physical_device_term *phys_dev_term = |
| 5142 | (struct loader_physical_device_term *)physicalDevice; |
| 5143 | struct loader_icd_term *icd_term = phys_dev_term->this_icd_term; |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5144 | if (NULL == icd_term->GetPhysicalDeviceImageFormatProperties) { |
| 5145 | loader_log(icd_term->this_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 5146 | "Encountered the vkEnumerateDeviceLayerProperties " |
| 5147 | "terminator. This means a layer improperly continued."); |
Chia-I Wu | 1724104 | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 5148 | return VK_ERROR_INITIALIZATION_FAILED; |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5149 | } |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5150 | return icd_term->GetPhysicalDeviceImageFormatProperties( |
| 5151 | phys_dev_term->phys_dev, format, type, tiling, usage, flags, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 5152 | pImageFormatProperties); |
Jon Ashburn | 754864f | 2015-07-23 18:49:07 -0600 | [diff] [blame] | 5153 | } |
| 5154 | |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 5155 | VKAPI_ATTR void VKAPI_CALL |
| 5156 | terminator_GetPhysicalDeviceSparseImageFormatProperties( |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 5157 | VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, |
| 5158 | VkSampleCountFlagBits samples, VkImageUsageFlags usage, |
| 5159 | VkImageTiling tiling, uint32_t *pNumProperties, |
| 5160 | VkSparseImageFormatProperties *pProperties) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5161 | struct loader_physical_device_term *phys_dev_term = |
| 5162 | (struct loader_physical_device_term *)physicalDevice; |
| 5163 | struct loader_icd_term *icd_term = phys_dev_term->this_icd_term; |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5164 | if (NULL != icd_term->GetPhysicalDeviceSparseImageFormatProperties) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5165 | icd_term->GetPhysicalDeviceSparseImageFormatProperties( |
| 5166 | phys_dev_term->phys_dev, format, type, samples, usage, tiling, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 5167 | pNumProperties, pProperties); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5168 | } |
Mark Lobodzinski | 16e8bef | 2015-07-03 15:58:09 -0600 | [diff] [blame] | 5169 | } |
| 5170 | |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 5171 | VKAPI_ATTR VkResult VKAPI_CALL terminator_EnumerateDeviceExtensionProperties( |
| 5172 | VkPhysicalDevice physicalDevice, const char *pLayerName, |
| 5173 | uint32_t *pPropertyCount, VkExtensionProperties *pProperties) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5174 | struct loader_physical_device_term *phys_dev_term; |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 5175 | |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 5176 | struct loader_layer_list implicit_layer_list = {0}; |
| 5177 | struct loader_extension_list all_exts = {0}; |
| 5178 | struct loader_extension_list icd_exts = {0}; |
Jon Ashburn | 471f44c | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 5179 | |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 5180 | assert(pLayerName == NULL || strlen(pLayerName) == 0); |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 5181 | |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 5182 | /* Any layer or trampoline wrapping should be removed at this point in time |
| 5183 | * can just cast to the expected type for VkPhysicalDevice. */ |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5184 | phys_dev_term = (struct loader_physical_device_term *)physicalDevice; |
Jon Ashburn | 471f44c | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 5185 | |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 5186 | /* this case is during the call down the instance chain with pLayerName |
| 5187 | * == NULL*/ |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5188 | struct loader_icd_term *icd_term = phys_dev_term->this_icd_term; |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 5189 | uint32_t icd_ext_count = *pPropertyCount; |
| 5190 | VkResult res; |
Jon Ashburn | 471f44c | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 5191 | |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 5192 | /* get device extensions */ |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5193 | res = icd_term->EnumerateDeviceExtensionProperties( |
| 5194 | phys_dev_term->phys_dev, NULL, &icd_ext_count, pProperties); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 5195 | if (res != VK_SUCCESS) { |
| 5196 | goto out; |
| 5197 | } |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 5198 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5199 | if (!loader_init_layer_list(icd_term->this_instance, |
| 5200 | &implicit_layer_list)) { |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 5201 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 5202 | goto out; |
| 5203 | } |
Jon Ashburn | 471f44c | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 5204 | |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 5205 | loader_add_layer_implicit( |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5206 | icd_term->this_instance, VK_LAYER_TYPE_INSTANCE_IMPLICIT, |
| 5207 | &implicit_layer_list, &icd_term->this_instance->instance_layer_list); |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 5208 | /* we need to determine which implicit layers are active, |
| 5209 | * and then add their extensions. This can't be cached as |
| 5210 | * it depends on results of environment variables (which can change). |
| 5211 | */ |
| 5212 | if (pProperties != NULL) { |
| 5213 | /* initialize dev_extension list within the physicalDevice object */ |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5214 | res = loader_init_device_extensions(icd_term->this_instance, |
| 5215 | phys_dev_term, icd_ext_count, |
| 5216 | pProperties, &icd_exts); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 5217 | if (res != VK_SUCCESS) { |
| 5218 | goto out; |
| 5219 | } |
Jon Ashburn | 471f44c | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 5220 | |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 5221 | /* we need to determine which implicit layers are active, |
| 5222 | * and then add their extensions. This can't be cached as |
| 5223 | * it depends on results of environment variables (which can |
| 5224 | * change). |
| 5225 | */ |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5226 | res = loader_add_to_ext_list(icd_term->this_instance, &all_exts, |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 5227 | icd_exts.count, icd_exts.list); |
| 5228 | if (res != VK_SUCCESS) { |
| 5229 | goto out; |
| 5230 | } |
Jon Ashburn | 471f44c | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 5231 | |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 5232 | loader_add_layer_implicit( |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5233 | icd_term->this_instance, VK_LAYER_TYPE_INSTANCE_IMPLICIT, |
| 5234 | &implicit_layer_list, |
| 5235 | &icd_term->this_instance->instance_layer_list); |
Jon Ashburn | 471f44c | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 5236 | |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 5237 | for (uint32_t i = 0; i < implicit_layer_list.count; i++) { |
| 5238 | for (uint32_t j = 0; |
Jon Ashburn | 014438f | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 5239 | j < implicit_layer_list.list[i].device_extension_list.count; |
| 5240 | j++) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5241 | res = loader_add_to_ext_list(icd_term->this_instance, &all_exts, |
| 5242 | 1, |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 5243 | &implicit_layer_list.list[i] |
| 5244 | .device_extension_list.list[j] |
| 5245 | .props); |
| 5246 | if (res != VK_SUCCESS) { |
| 5247 | goto out; |
| 5248 | } |
Jon Ashburn | 471f44c | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 5249 | } |
Jon Ashburn | 471f44c | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 5250 | } |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 5251 | uint32_t capacity = *pPropertyCount; |
| 5252 | VkExtensionProperties *props = pProperties; |
Jon Ashburn | 471f44c | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 5253 | |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 5254 | for (uint32_t i = 0; i < all_exts.count && i < capacity; i++) { |
| 5255 | props[i] = all_exts.list[i]; |
| 5256 | } |
| 5257 | /* wasn't enough space for the extensions, we did partial copy now |
| 5258 | * return VK_INCOMPLETE */ |
| 5259 | if (capacity < all_exts.count) { |
| 5260 | res = VK_INCOMPLETE; |
| 5261 | } else { |
| 5262 | *pPropertyCount = all_exts.count; |
| 5263 | } |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 5264 | } else { |
| 5265 | /* just return the count; need to add in the count of implicit layer |
| 5266 | * extensions |
| 5267 | * don't worry about duplicates being added in the count */ |
| 5268 | *pPropertyCount = icd_ext_count; |
| 5269 | |
| 5270 | for (uint32_t i = 0; i < implicit_layer_list.count; i++) { |
| 5271 | *pPropertyCount += |
Jon Ashburn | 014438f | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 5272 | implicit_layer_list.list[i].device_extension_list.count; |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 5273 | } |
| 5274 | res = VK_SUCCESS; |
Jon Ashburn | b82c185 | 2015-08-11 14:49:54 -0600 | [diff] [blame] | 5275 | } |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 5276 | |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 5277 | out: |
| 5278 | |
| 5279 | if (NULL != implicit_layer_list.list) { |
| 5280 | loader_destroy_generic_list( |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5281 | icd_term->this_instance, |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 5282 | (struct loader_generic_list *)&implicit_layer_list); |
| 5283 | } |
| 5284 | if (NULL != all_exts.list) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5285 | loader_destroy_generic_list(icd_term->this_instance, |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 5286 | (struct loader_generic_list *)&all_exts); |
| 5287 | } |
| 5288 | if (NULL != icd_exts.list) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5289 | loader_destroy_generic_list(icd_term->this_instance, |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 5290 | (struct loader_generic_list *)&icd_exts); |
| 5291 | } |
| 5292 | |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 5293 | return res; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 5294 | } |
| 5295 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5296 | VKAPI_ATTR VkResult VKAPI_CALL terminator_EnumerateDeviceLayerProperties( |
| 5297 | VkPhysicalDevice physicalDevice, uint32_t *pPropertyCount, |
| 5298 | VkLayerProperties *pProperties) { |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5299 | struct loader_physical_device_term *phys_dev_term = |
| 5300 | (struct loader_physical_device_term *)physicalDevice; |
| 5301 | struct loader_icd_term *icd_term = phys_dev_term->this_icd_term; |
| 5302 | loader_log(icd_term->this_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 5303 | "Encountered the vkEnumerateDeviceLayerProperties " |
| 5304 | "terminator. This means a layer improperly continued."); |
| 5305 | // Should never get here this call isn't dispatched down the chain |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 5306 | return VK_ERROR_INITIALIZATION_FAILED; |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 5307 | } |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 5308 | |
Jon Ashburn | f2b4e38 | 2016-02-10 20:50:19 -0700 | [diff] [blame] | 5309 | VkStringErrorFlags vk_string_validate(const int max_length, const char *utf8) { |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 5310 | VkStringErrorFlags result = VK_STRING_ERROR_NONE; |
Karl Schultz | 2558bd3 | 2016-02-24 14:39:39 -0700 | [diff] [blame] | 5311 | int num_char_bytes = 0; |
Jon Ashburn | f2b4e38 | 2016-02-10 20:50:19 -0700 | [diff] [blame] | 5312 | int i, j; |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 5313 | |
Courtney Goeltzenleuchter | 7a3486d | 2016-12-21 16:24:34 -0700 | [diff] [blame] | 5314 | for (i = 0; i <= max_length; i++) { |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 5315 | if (utf8[i] == 0) { |
| 5316 | break; |
Courtney Goeltzenleuchter | 7a3486d | 2016-12-21 16:24:34 -0700 | [diff] [blame] | 5317 | } else if (i == max_length) { |
| 5318 | result |= VK_STRING_ERROR_LENGTH; |
| 5319 | break; |
Mark Lobodzinski | 36b4de2 | 2016-02-12 11:30:14 -0700 | [diff] [blame] | 5320 | } else if ((utf8[i] >= 0x20) && (utf8[i] < 0x7f)) { |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 5321 | num_char_bytes = 0; |
Jon Ashburn | f2b4e38 | 2016-02-10 20:50:19 -0700 | [diff] [blame] | 5322 | } else if ((utf8[i] & UTF8_ONE_BYTE_MASK) == UTF8_ONE_BYTE_CODE) { |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 5323 | num_char_bytes = 1; |
Jon Ashburn | f2b4e38 | 2016-02-10 20:50:19 -0700 | [diff] [blame] | 5324 | } else if ((utf8[i] & UTF8_TWO_BYTE_MASK) == UTF8_TWO_BYTE_CODE) { |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 5325 | num_char_bytes = 2; |
| 5326 | } else if ((utf8[i] & UTF8_THREE_BYTE_MASK) == UTF8_THREE_BYTE_CODE) { |
| 5327 | num_char_bytes = 3; |
| 5328 | } else { |
| 5329 | result = VK_STRING_ERROR_BAD_DATA; |
| 5330 | } |
| 5331 | |
| 5332 | // Validate the following num_char_bytes of data |
| 5333 | for (j = 0; (j < num_char_bytes) && (i < max_length); j++) { |
| 5334 | if (++i == max_length) { |
| 5335 | result |= VK_STRING_ERROR_LENGTH; |
| 5336 | break; |
| 5337 | } |
| 5338 | if ((utf8[i] & UTF8_DATA_BYTE_MASK) != UTF8_DATA_BYTE_CODE) { |
| 5339 | result |= VK_STRING_ERROR_BAD_DATA; |
| 5340 | } |
| 5341 | } |
| 5342 | } |
| 5343 | return result; |
| 5344 | } |