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]; |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 405 | va_list ap; |
| 406 | int ret; |
| 407 | |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 408 | va_start(ap, format); |
| 409 | ret = vsnprintf(msg, sizeof(msg), format, ap); |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 410 | if ((ret >= (int)sizeof(msg)) || ret < 0) { |
| 411 | msg[sizeof(msg) - 1] = '\0'; |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 412 | } |
| 413 | va_end(ap); |
| 414 | |
Courtney Goeltzenleuchter | 7347739 | 2015-12-03 13:48:01 -0700 | [diff] [blame] | 415 | if (inst) { |
Karl Schultz | 9497129 | 2016-11-19 09:02:27 -0700 | [diff] [blame] | 416 | util_DebugReportMessage( |
| 417 | inst, msg_type, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, |
| 418 | (uint64_t)(uintptr_t)inst, 0, msg_code, "loader", msg); |
Courtney Goeltzenleuchter | 7347739 | 2015-12-03 13:48:01 -0700 | [diff] [blame] | 419 | } |
| 420 | |
| 421 | if (!(msg_type & g_loader_log_msgs)) { |
| 422 | return; |
| 423 | } |
| 424 | |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 425 | #if defined(WIN32) |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 426 | OutputDebugString(msg); |
mschott | b9cdb78 | 2015-07-22 14:11:29 +0200 | [diff] [blame] | 427 | OutputDebugString("\n"); |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 428 | #endif |
| 429 | fputs(msg, stderr); |
| 430 | fputc('\n', stderr); |
| 431 | } |
| 432 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 433 | VKAPI_ATTR VkResult VKAPI_CALL vkSetInstanceDispatch(VkInstance instance, |
| 434 | void *object) { |
Jon Ashburn | c3c5877 | 2016-03-29 11:16:01 -0600 | [diff] [blame] | 435 | |
| 436 | struct loader_instance *inst = loader_get_instance(instance); |
| 437 | if (!inst) { |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 438 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 439 | "vkSetInstanceDispatch: Can not retrieve Instance " |
| 440 | "dispatch table."); |
Jon Ashburn | c3c5877 | 2016-03-29 11:16:01 -0600 | [diff] [blame] | 441 | return VK_ERROR_INITIALIZATION_FAILED; |
| 442 | } |
| 443 | loader_set_dispatch(object, inst->disp); |
| 444 | return VK_SUCCESS; |
| 445 | } |
| 446 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 447 | VKAPI_ATTR VkResult VKAPI_CALL vkSetDeviceDispatch(VkDevice device, |
| 448 | void *object) { |
Jon Ashburn | ed8f231 | 2016-03-31 10:52:22 -0600 | [diff] [blame] | 449 | struct loader_device *dev; |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 450 | struct loader_icd_term *icd_term = |
| 451 | loader_get_icd_and_device(device, &dev, NULL); |
Jon Ashburn | ed8f231 | 2016-03-31 10:52:22 -0600 | [diff] [blame] | 452 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 453 | if (NULL == icd_term) { |
Jon Ashburn | ed8f231 | 2016-03-31 10:52:22 -0600 | [diff] [blame] | 454 | return VK_ERROR_INITIALIZATION_FAILED; |
| 455 | } |
| 456 | loader_set_dispatch(object, &dev->loader_dispatch); |
| 457 | return VK_SUCCESS; |
| 458 | } |
| 459 | |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 460 | #if defined(WIN32) |
Tony Barbour | ea96890 | 2015-07-29 14:26:21 -0600 | [diff] [blame] | 461 | static char *loader_get_next_path(char *path); |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 462 | /** |
| 463 | * Find the list of registry files (names within a key) in key "location". |
| 464 | * |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 465 | * This function looks in the registry (hive = DEFAULT_VK_REGISTRY_HIVE) key as |
| 466 | *given in "location" |
| 467 | * for a list or name/values which are added to a returned list (function return |
| 468 | *value). |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 469 | * The DWORD values within the key must be 0 or they are skipped. |
Jon Ashburn | e39a4f8 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 470 | * Function return is a string with a ';' separated list of filenames. |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 471 | * Function return is NULL if no valid name/value pairs are found in the key, |
| 472 | * or the key is not found. |
| 473 | * |
| 474 | * \returns |
| 475 | * A string list of filenames as pointer. |
| 476 | * When done using the returned string list, pointer should be freed. |
| 477 | */ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 478 | static char *loader_get_registry_files(const struct loader_instance *inst, |
| 479 | char *location) { |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 480 | LONG rtn_value; |
| 481 | HKEY hive, key; |
Piers Daniell | 524ec73 | 2015-11-05 16:58:26 -0700 | [diff] [blame] | 482 | DWORD access_flags; |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 483 | char name[2048]; |
| 484 | char *out = NULL; |
Tony Barbour | ea96890 | 2015-07-29 14:26:21 -0600 | [diff] [blame] | 485 | char *loc = location; |
| 486 | char *next; |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 487 | DWORD idx = 0; |
| 488 | DWORD name_size = sizeof(name); |
| 489 | DWORD value; |
| 490 | DWORD total_size = 4096; |
| 491 | DWORD value_size = sizeof(value); |
Tony Barbour | ea96890 | 2015-07-29 14:26:21 -0600 | [diff] [blame] | 492 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 493 | while (*loc) { |
Tony Barbour | ea96890 | 2015-07-29 14:26:21 -0600 | [diff] [blame] | 494 | next = loader_get_next_path(loc); |
| 495 | hive = DEFAULT_VK_REGISTRY_HIVE; |
Piers Daniell | 524ec73 | 2015-11-05 16:58:26 -0700 | [diff] [blame] | 496 | access_flags = KEY_QUERY_VALUE; |
Tony Barbour | ea96890 | 2015-07-29 14:26:21 -0600 | [diff] [blame] | 497 | rtn_value = RegOpenKeyEx(hive, loc, 0, access_flags, &key); |
| 498 | if (rtn_value != ERROR_SUCCESS) { |
Mark Young | 93ecb1d | 2016-01-13 13:47:16 -0700 | [diff] [blame] | 499 | // We still couldn't find the key, so give up: |
| 500 | loc = next; |
| 501 | continue; |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 502 | } |
Tony Barbour | ea96890 | 2015-07-29 14:26:21 -0600 | [diff] [blame] | 503 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 504 | while ((rtn_value = RegEnumValue(key, idx++, name, &name_size, NULL, |
| 505 | NULL, (LPBYTE)&value, &value_size)) == |
| 506 | ERROR_SUCCESS) { |
Tony Barbour | ea96890 | 2015-07-29 14:26:21 -0600 | [diff] [blame] | 507 | if (value_size == sizeof(value) && value == 0) { |
| 508 | if (out == NULL) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 509 | out = loader_instance_heap_alloc( |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 510 | inst, total_size, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 511 | if (NULL == out) { |
| 512 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 513 | "Out of memory can't alloc space for " |
| 514 | "registry data"); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 515 | return NULL; |
| 516 | } |
Tony Barbour | ea96890 | 2015-07-29 14:26:21 -0600 | [diff] [blame] | 517 | out[0] = '\0'; |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 518 | } else if (strlen(out) + name_size + 1 > total_size) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 519 | out = loader_instance_heap_realloc( |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 520 | inst, out, total_size, total_size * 2, |
| 521 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 522 | if (NULL == out) { |
| 523 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 524 | "Out of memory can't realloc space for " |
| 525 | "registry data"); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 526 | return NULL; |
| 527 | } |
Tony Barbour | ea96890 | 2015-07-29 14:26:21 -0600 | [diff] [blame] | 528 | total_size *= 2; |
| 529 | } |
Tony Barbour | ea96890 | 2015-07-29 14:26:21 -0600 | [diff] [blame] | 530 | if (strlen(out) == 0) |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 531 | snprintf(out, name_size + 1, "%s", name); |
Tony Barbour | ea96890 | 2015-07-29 14:26:21 -0600 | [diff] [blame] | 532 | else |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 533 | snprintf(out + strlen(out), name_size + 2, "%c%s", |
Frank Henigman | 5717310 | 2016-11-24 22:15:20 -0500 | [diff] [blame] | 534 | PATH_SEPARATOR, name); |
Tony Barbour | ea96890 | 2015-07-29 14:26:21 -0600 | [diff] [blame] | 535 | } |
| 536 | name_size = 2048; |
| 537 | } |
| 538 | loc = next; |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 539 | } |
Tony Barbour | ea96890 | 2015-07-29 14:26:21 -0600 | [diff] [blame] | 540 | |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 541 | return out; |
| 542 | } |
| 543 | |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 544 | #endif // WIN32 |
| 545 | |
Jon Ashburn | c7237a7 | 2015-08-03 09:08:46 -0600 | [diff] [blame] | 546 | /** |
Daniel Dadap | 00b4aba | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 547 | * Combine path elements, separating each element with the platform-specific |
| 548 | * directory separator, and save the combined string to a destination buffer, |
| 549 | * not exceeding the given length. Path elements are given as variadic args, |
| 550 | * with a NULL element terminating the list. |
| 551 | * |
| 552 | * \returns the total length of the combined string, not including an ASCII |
| 553 | * NUL termination character. This length may exceed the available storage: |
| 554 | * in this case, the written string will be truncated to avoid a buffer |
| 555 | * overrun, and the return value will greater than or equal to the storage |
| 556 | * size. A NULL argument may be provided as the destination buffer in order |
| 557 | * to determine the required string length without actually writing a string. |
| 558 | */ |
| 559 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 560 | static size_t loader_platform_combine_path(char *dest, size_t len, ...) { |
Courtney Goeltzenleuchter | 0ef13a0 | 2015-12-16 16:19:46 -0700 | [diff] [blame] | 561 | size_t required_len = 0; |
Daniel Dadap | 00b4aba | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 562 | va_list ap; |
| 563 | const char *component; |
| 564 | |
| 565 | va_start(ap, len); |
| 566 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 567 | while ((component = va_arg(ap, const char *))) { |
Daniel Dadap | 00b4aba | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 568 | if (required_len > 0) { |
| 569 | // This path element is not the first non-empty element; prepend |
| 570 | // a directory separator if space allows |
| 571 | if (dest && required_len + 1 < len) { |
| 572 | snprintf(dest + required_len, len - required_len, "%c", |
| 573 | DIRECTORY_SYMBOL); |
| 574 | } |
| 575 | required_len++; |
| 576 | } |
| 577 | |
| 578 | if (dest && required_len < len) { |
| 579 | strncpy(dest + required_len, component, len - required_len); |
| 580 | } |
| 581 | required_len += strlen(component); |
| 582 | } |
| 583 | |
| 584 | va_end(ap); |
| 585 | |
| 586 | // strncpy(3) won't add a NUL terminating byte in the event of truncation. |
| 587 | if (dest && required_len >= len) { |
| 588 | dest[len - 1] = '\0'; |
| 589 | } |
| 590 | |
| 591 | return required_len; |
| 592 | } |
| 593 | |
Daniel Dadap | 00b4aba | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 594 | /** |
Jon Ashburn | c7237a7 | 2015-08-03 09:08:46 -0600 | [diff] [blame] | 595 | * Given string of three part form "maj.min.pat" convert to a vulkan version |
| 596 | * number. |
| 597 | */ |
Mark Young | 60861ac | 2016-09-02 11:39:26 -0600 | [diff] [blame] | 598 | static uint32_t loader_make_version(char *vers_str) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 599 | uint32_t vers = 0, major = 0, minor = 0, patch = 0; |
Mark Young | 60861ac | 2016-09-02 11:39:26 -0600 | [diff] [blame] | 600 | char *vers_tok; |
Jon Ashburn | c7237a7 | 2015-08-03 09:08:46 -0600 | [diff] [blame] | 601 | |
Mark Young | 60861ac | 2016-09-02 11:39:26 -0600 | [diff] [blame] | 602 | if (!vers_str) { |
Jon Ashburn | c7237a7 | 2015-08-03 09:08:46 -0600 | [diff] [blame] | 603 | return vers; |
Jon Ashburn | c7237a7 | 2015-08-03 09:08:46 -0600 | [diff] [blame] | 604 | } |
Mark Young | 60861ac | 2016-09-02 11:39:26 -0600 | [diff] [blame] | 605 | |
| 606 | vers_tok = strtok(vers_str, ".\"\n\r"); |
| 607 | if (NULL != vers_tok) { |
| 608 | major = (uint16_t)atoi(vers_tok); |
| 609 | vers_tok = strtok(NULL, ".\"\n\r"); |
| 610 | if (NULL != vers_tok) { |
| 611 | minor = (uint16_t)atoi(vers_tok); |
| 612 | vers_tok = strtok(NULL, ".\"\n\r"); |
| 613 | if (NULL != vers_tok) { |
| 614 | patch = (uint16_t)atoi(vers_tok); |
| 615 | } |
| 616 | } |
| 617 | } |
Jon Ashburn | c7237a7 | 2015-08-03 09:08:46 -0600 | [diff] [blame] | 618 | |
| 619 | return VK_MAKE_VERSION(major, minor, patch); |
Jon Ashburn | c7237a7 | 2015-08-03 09:08:46 -0600 | [diff] [blame] | 620 | } |
| 621 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 622 | bool compare_vk_extension_properties(const VkExtensionProperties *op1, |
| 623 | const VkExtensionProperties *op2) { |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 624 | return strcmp(op1->extensionName, op2->extensionName) == 0 ? true : false; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 625 | } |
| 626 | |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 627 | /** |
Jon Ashburn | bd6c488 | 2015-07-02 12:59:25 -0600 | [diff] [blame] | 628 | * Search the given ext_array for an extension |
| 629 | * matching the given vk_ext_prop |
| 630 | */ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 631 | bool has_vk_extension_property_array(const VkExtensionProperties *vk_ext_prop, |
| 632 | const uint32_t count, |
| 633 | const VkExtensionProperties *ext_array) { |
Jon Ashburn | bd6c488 | 2015-07-02 12:59:25 -0600 | [diff] [blame] | 634 | for (uint32_t i = 0; i < count; i++) { |
| 635 | if (compare_vk_extension_properties(vk_ext_prop, &ext_array[i])) |
| 636 | return true; |
| 637 | } |
| 638 | return false; |
| 639 | } |
| 640 | |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 641 | /** |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 642 | * Search the given ext_list for an extension |
| 643 | * matching the given vk_ext_prop |
| 644 | */ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 645 | bool has_vk_extension_property(const VkExtensionProperties *vk_ext_prop, |
| 646 | const struct loader_extension_list *ext_list) { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 647 | for (uint32_t i = 0; i < ext_list->count; i++) { |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 648 | if (compare_vk_extension_properties(&ext_list->list[i], vk_ext_prop)) |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 649 | return true; |
| 650 | } |
| 651 | return false; |
| 652 | } |
| 653 | |
Jon Ashburn | b872696 | 2016-04-08 15:03:35 -0600 | [diff] [blame] | 654 | /** |
| 655 | * Search the given ext_list for a device extension matching the given ext_prop |
| 656 | */ |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 657 | bool has_vk_dev_ext_property( |
| 658 | const VkExtensionProperties *ext_prop, |
| 659 | const struct loader_device_extension_list *ext_list) { |
Jon Ashburn | b872696 | 2016-04-08 15:03:35 -0600 | [diff] [blame] | 660 | for (uint32_t i = 0; i < ext_list->count; i++) { |
| 661 | if (compare_vk_extension_properties(&ext_list->list[i].props, ext_prop)) |
| 662 | return true; |
| 663 | } |
| 664 | return false; |
| 665 | } |
| 666 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 667 | /* |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 668 | * 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] | 669 | */ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 670 | static struct loader_layer_properties * |
| 671 | loader_get_layer_property(const char *name, |
| 672 | const struct loader_layer_list *layer_list) { |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 673 | for (uint32_t i = 0; i < layer_list->count; i++) { |
| 674 | const VkLayerProperties *item = &layer_list->list[i].info; |
| 675 | if (strcmp(name, item->layerName) == 0) |
| 676 | return &layer_list->list[i]; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 677 | } |
| 678 | return NULL; |
| 679 | } |
| 680 | |
Jon Ashburn | e13ecc9 | 2015-08-03 17:19:30 -0600 | [diff] [blame] | 681 | /** |
| 682 | * Get the next unused layer property in the list. Init the property to zero. |
| 683 | */ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 684 | static struct loader_layer_properties * |
| 685 | loader_get_next_layer_property(const struct loader_instance *inst, |
| 686 | struct loader_layer_list *layer_list) { |
Jon Ashburn | e13ecc9 | 2015-08-03 17:19:30 -0600 | [diff] [blame] | 687 | if (layer_list->capacity == 0) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 688 | layer_list->list = loader_instance_heap_alloc( |
| 689 | inst, sizeof(struct loader_layer_properties) * 64, |
| 690 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Jon Ashburn | e13ecc9 | 2015-08-03 17:19:30 -0600 | [diff] [blame] | 691 | if (layer_list->list == NULL) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 692 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 693 | "loader_get_next_layer_property: Out of memory can " |
| 694 | "not add any layer properties to list"); |
Jon Ashburn | e13ecc9 | 2015-08-03 17:19:30 -0600 | [diff] [blame] | 695 | return NULL; |
| 696 | } |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 697 | memset(layer_list->list, 0, |
| 698 | sizeof(struct loader_layer_properties) * 64); |
Jon Ashburn | e13ecc9 | 2015-08-03 17:19:30 -0600 | [diff] [blame] | 699 | layer_list->capacity = sizeof(struct loader_layer_properties) * 64; |
| 700 | } |
| 701 | |
| 702 | // ensure enough room to add an entry |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 703 | if ((layer_list->count + 1) * sizeof(struct loader_layer_properties) > |
| 704 | layer_list->capacity) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 705 | layer_list->list = loader_instance_heap_realloc( |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 706 | inst, layer_list->list, layer_list->capacity, |
| 707 | layer_list->capacity * 2, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Jon Ashburn | e13ecc9 | 2015-08-03 17:19:30 -0600 | [diff] [blame] | 708 | if (layer_list->list == NULL) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 709 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 710 | "loader_get_next_layer_property: realloc failed for " |
| 711 | "layer list"); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 712 | return NULL; |
Jon Ashburn | e13ecc9 | 2015-08-03 17:19:30 -0600 | [diff] [blame] | 713 | } |
| 714 | layer_list->capacity *= 2; |
| 715 | } |
| 716 | |
| 717 | layer_list->count++; |
| 718 | return &(layer_list->list[layer_list->count - 1]); |
| 719 | } |
| 720 | |
| 721 | /** |
| 722 | * Remove all layer properties entrys from the list |
| 723 | */ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 724 | void loader_delete_layer_properties(const struct loader_instance *inst, |
| 725 | struct loader_layer_list *layer_list) { |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 726 | uint32_t i, j; |
| 727 | struct loader_device_extension_list *dev_ext_list; |
Jon Ashburn | b82c185 | 2015-08-11 14:49:54 -0600 | [diff] [blame] | 728 | if (!layer_list) |
| 729 | return; |
| 730 | |
Jon Ashburn | e13ecc9 | 2015-08-03 17:19:30 -0600 | [diff] [blame] | 731 | for (i = 0; i < layer_list->count; i++) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 732 | loader_destroy_generic_list( |
| 733 | inst, (struct loader_generic_list *)&layer_list->list[i] |
| 734 | .instance_extension_list); |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 735 | dev_ext_list = &layer_list->list[i].device_extension_list; |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 736 | if (dev_ext_list->capacity > 0 && NULL != dev_ext_list->list && |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 737 | dev_ext_list->list->entrypoint_count > 0) { |
| 738 | for (j = 0; j < dev_ext_list->list->entrypoint_count; j++) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 739 | loader_instance_heap_free(inst, |
| 740 | dev_ext_list->list->entrypoints[j]); |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 741 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 742 | loader_instance_heap_free(inst, dev_ext_list->list->entrypoints); |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 743 | } |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 744 | loader_destroy_generic_list(inst, |
| 745 | (struct loader_generic_list *)dev_ext_list); |
Jon Ashburn | e13ecc9 | 2015-08-03 17:19:30 -0600 | [diff] [blame] | 746 | } |
| 747 | layer_list->count = 0; |
| 748 | |
Jon Ashburn | b82c185 | 2015-08-11 14:49:54 -0600 | [diff] [blame] | 749 | if (layer_list->capacity > 0) { |
| 750 | layer_list->capacity = 0; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 751 | loader_instance_heap_free(inst, layer_list->list); |
Jon Ashburn | b82c185 | 2015-08-11 14:49:54 -0600 | [diff] [blame] | 752 | } |
Jon Ashburn | e13ecc9 | 2015-08-03 17:19:30 -0600 | [diff] [blame] | 753 | } |
| 754 | |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 755 | static VkResult loader_add_instance_extensions( |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 756 | const struct loader_instance *inst, |
| 757 | const PFN_vkEnumerateInstanceExtensionProperties fp_get_props, |
| 758 | const char *lib_name, struct loader_extension_list *ext_list) { |
Courtney Goeltzenleuchter | 36eeb74 | 2015-12-21 16:41:47 -0700 | [diff] [blame] | 759 | uint32_t i, count = 0; |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 760 | VkExtensionProperties *ext_props; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 761 | VkResult res = VK_SUCCESS; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 762 | |
Courtney Goeltzenleuchter | 5c6cf47 | 2015-07-06 22:28:18 -0600 | [diff] [blame] | 763 | if (!fp_get_props) { |
Courtney Goeltzenleuchter | 35985f6 | 2015-09-14 17:22:16 -0600 | [diff] [blame] | 764 | /* No EnumerateInstanceExtensionProperties defined */ |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 765 | goto out; |
Courtney Goeltzenleuchter | 5c6cf47 | 2015-07-06 22:28:18 -0600 | [diff] [blame] | 766 | } |
| 767 | |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 768 | res = fp_get_props(NULL, &count, NULL); |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 769 | if (res != VK_SUCCESS) { |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 770 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 771 | "loader_add_instance_extensions: Error getting Instance " |
| 772 | "extension count from %s", |
| 773 | lib_name); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 774 | goto out; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 775 | } |
Jon Ashburn | 953bb3c | 2015-06-10 16:11:42 -0600 | [diff] [blame] | 776 | |
Courtney Goeltzenleuchter | 5c6cf47 | 2015-07-06 22:28:18 -0600 | [diff] [blame] | 777 | if (count == 0) { |
| 778 | /* No ExtensionProperties to report */ |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 779 | goto out; |
Courtney Goeltzenleuchter | 5c6cf47 | 2015-07-06 22:28:18 -0600 | [diff] [blame] | 780 | } |
| 781 | |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 782 | ext_props = loader_stack_alloc(count * sizeof(VkExtensionProperties)); |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 783 | |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 784 | res = fp_get_props(NULL, &count, ext_props); |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 785 | if (res != VK_SUCCESS) { |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 786 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 787 | "loader_add_instance_extensions: Error getting Instance " |
| 788 | "extensions from %s", |
| 789 | lib_name); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 790 | goto out; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 791 | } |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 792 | |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 793 | for (i = 0; i < count; i++) { |
Courtney Goeltzenleuchter | 5304373 | 2015-07-12 13:20:05 -0600 | [diff] [blame] | 794 | char spec_version[64]; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 795 | |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 796 | bool ext_unsupported = |
| 797 | wsi_unsupported_instance_extension(&ext_props[i]); |
Jon Ashburn | 6fa520f | 2016-03-25 12:49:35 -0600 | [diff] [blame] | 798 | if (!ext_unsupported) { |
| 799 | snprintf(spec_version, sizeof(spec_version), "%d.%d.%d", |
| 800 | VK_MAJOR(ext_props[i].specVersion), |
| 801 | VK_MINOR(ext_props[i].specVersion), |
| 802 | VK_PATCH(ext_props[i].specVersion)); |
| 803 | loader_log(inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, |
| 804 | "Instance Extension: %s (%s) version %s", |
| 805 | ext_props[i].extensionName, lib_name, spec_version); |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame^] | 806 | |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 807 | res = loader_add_to_ext_list(inst, ext_list, 1, &ext_props[i]); |
| 808 | if (res != VK_SUCCESS) { |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 809 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 810 | "loader_add_instance_extensions: Failed to add %s " |
| 811 | "to Instance extension list", |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 812 | lib_name); |
| 813 | goto out; |
| 814 | } |
Jon Ashburn | 6fa520f | 2016-03-25 12:49:35 -0600 | [diff] [blame] | 815 | } |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 816 | } |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame^] | 817 | |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 818 | out: |
| 819 | return res; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 820 | } |
| 821 | |
Jon Ashburn | 00eb6c0 | 2015-11-02 17:40:01 -0700 | [diff] [blame] | 822 | /* |
| 823 | * Initialize ext_list with the physical device extensions. |
| 824 | * The extension properties are passed as inputs in count and ext_props. |
| 825 | */ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 826 | static VkResult |
| 827 | loader_init_device_extensions(const struct loader_instance *inst, |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 828 | struct loader_physical_device_term *phys_dev_term, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 829 | uint32_t count, VkExtensionProperties *ext_props, |
| 830 | struct loader_extension_list *ext_list) { |
Jon Ashburn | 00eb6c0 | 2015-11-02 17:40:01 -0700 | [diff] [blame] | 831 | VkResult res; |
| 832 | uint32_t i; |
| 833 | |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 834 | res = loader_init_generic_list(inst, (struct loader_generic_list *)ext_list, |
| 835 | sizeof(VkExtensionProperties)); |
| 836 | if (VK_SUCCESS != res) { |
| 837 | return res; |
Jon Ashburn | 00eb6c0 | 2015-11-02 17:40:01 -0700 | [diff] [blame] | 838 | } |
| 839 | |
| 840 | for (i = 0; i < count; i++) { |
| 841 | char spec_version[64]; |
| 842 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 843 | snprintf(spec_version, sizeof(spec_version), "%d.%d.%d", |
| 844 | VK_MAJOR(ext_props[i].specVersion), |
| 845 | VK_MINOR(ext_props[i].specVersion), |
| 846 | VK_PATCH(ext_props[i].specVersion)); |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 847 | loader_log( |
| 848 | inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, |
| 849 | "Device Extension: %s (%s) version %s", ext_props[i].extensionName, |
| 850 | phys_dev_term->this_icd_term->scanned_icd->lib_name, spec_version); |
Jon Ashburn | 00eb6c0 | 2015-11-02 17:40:01 -0700 | [diff] [blame] | 851 | res = loader_add_to_ext_list(inst, ext_list, 1, &ext_props[i]); |
| 852 | if (res != VK_SUCCESS) |
| 853 | return res; |
| 854 | } |
| 855 | |
| 856 | return VK_SUCCESS; |
| 857 | } |
| 858 | |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 859 | VkResult loader_add_device_extensions(const struct loader_instance *inst, |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 860 | PFN_vkEnumerateDeviceExtensionProperties |
| 861 | fpEnumerateDeviceExtensionProperties, |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 862 | VkPhysicalDevice physical_device, |
| 863 | const char *lib_name, |
| 864 | struct loader_extension_list *ext_list) { |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 865 | uint32_t i, count; |
| 866 | VkResult res; |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 867 | VkExtensionProperties *ext_props; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 868 | |
Piers Daniell | 295fe40 | 2016-03-29 11:51:11 -0600 | [diff] [blame] | 869 | res = fpEnumerateDeviceExtensionProperties(physical_device, NULL, &count, |
| 870 | NULL); |
Jon Ashburn | 00eb6c0 | 2015-11-02 17:40:01 -0700 | [diff] [blame] | 871 | if (res == VK_SUCCESS && count > 0) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 872 | ext_props = loader_stack_alloc(count * sizeof(VkExtensionProperties)); |
Mark Young | 9a3ddd4 | 2016-10-21 16:25:47 -0600 | [diff] [blame] | 873 | if (!ext_props) { |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 874 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 875 | "loader_add_device_extensions: Failed to allocate space" |
| 876 | " for device extension properties."); |
Jon Ashburn | 00eb6c0 | 2015-11-02 17:40:01 -0700 | [diff] [blame] | 877 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Mark Young | 9a3ddd4 | 2016-10-21 16:25:47 -0600 | [diff] [blame] | 878 | } |
Piers Daniell | 295fe40 | 2016-03-29 11:51:11 -0600 | [diff] [blame] | 879 | res = fpEnumerateDeviceExtensionProperties(physical_device, NULL, |
| 880 | &count, ext_props); |
Mark Young | 9a3ddd4 | 2016-10-21 16:25:47 -0600 | [diff] [blame] | 881 | if (res != VK_SUCCESS) { |
Jon Ashburn | 24cd4be | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 882 | return res; |
Mark Young | 9a3ddd4 | 2016-10-21 16:25:47 -0600 | [diff] [blame] | 883 | } |
Jon Ashburn | 00eb6c0 | 2015-11-02 17:40:01 -0700 | [diff] [blame] | 884 | for (i = 0; i < count; i++) { |
| 885 | char spec_version[64]; |
| 886 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 887 | snprintf(spec_version, sizeof(spec_version), "%d.%d.%d", |
| 888 | VK_MAJOR(ext_props[i].specVersion), |
| 889 | VK_MINOR(ext_props[i].specVersion), |
| 890 | VK_PATCH(ext_props[i].specVersion)); |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 891 | loader_log(inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 892 | "Device Extension: %s (%s) version %s", |
| 893 | ext_props[i].extensionName, lib_name, spec_version); |
Jon Ashburn | 00eb6c0 | 2015-11-02 17:40:01 -0700 | [diff] [blame] | 894 | 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] | 895 | if (res != VK_SUCCESS) { |
Jon Ashburn | 00eb6c0 | 2015-11-02 17:40:01 -0700 | [diff] [blame] | 896 | return res; |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 897 | } |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 898 | } |
Jon Ashburn | 00eb6c0 | 2015-11-02 17:40:01 -0700 | [diff] [blame] | 899 | } else { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 900 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 901 | "loader_add_device_extensions: Error getting physical " |
| 902 | "device extension info count from library %s", |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 903 | lib_name); |
Jon Ashburn | 00eb6c0 | 2015-11-02 17:40:01 -0700 | [diff] [blame] | 904 | return res; |
| 905 | } |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 906 | |
Jon Ashburn | 24cd4be | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 907 | return VK_SUCCESS; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 908 | } |
| 909 | |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 910 | VkResult loader_init_generic_list(const struct loader_instance *inst, |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 911 | struct loader_generic_list *list_info, |
| 912 | size_t element_size) { |
Mark Young | 84ba048 | 2016-09-02 11:45:00 -0600 | [diff] [blame] | 913 | size_t capacity = 32 * element_size; |
| 914 | list_info->count = 0; |
| 915 | list_info->capacity = 0; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 916 | list_info->list = loader_instance_heap_alloc( |
Mark Young | 84ba048 | 2016-09-02 11:45:00 -0600 | [diff] [blame] | 917 | inst, capacity, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Jon Ashburn | 6e6a216 | 2015-12-10 08:51:10 -0700 | [diff] [blame] | 918 | if (list_info->list == NULL) { |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 919 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 920 | "loader_init_generic_list: Failed to allocate space " |
| 921 | "for generic list"); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 922 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 923 | } |
Mark Young | 84ba048 | 2016-09-02 11:45:00 -0600 | [diff] [blame] | 924 | memset(list_info->list, 0, capacity); |
| 925 | list_info->capacity = capacity; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 926 | return VK_SUCCESS; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 927 | } |
| 928 | |
Jon Ashburn | 6e6a216 | 2015-12-10 08:51:10 -0700 | [diff] [blame] | 929 | void loader_destroy_generic_list(const struct loader_instance *inst, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 930 | struct loader_generic_list *list) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 931 | loader_instance_heap_free(inst, list->list); |
Jon Ashburn | 6e6a216 | 2015-12-10 08:51:10 -0700 | [diff] [blame] | 932 | list->count = 0; |
| 933 | list->capacity = 0; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 934 | } |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 935 | |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 936 | /* |
| 937 | * Append non-duplicate extension properties defined in props |
| 938 | * to the given ext_list. |
Jon Ashburn | 24cd4be | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 939 | * Return |
| 940 | * Vk_SUCCESS on success |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 941 | */ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 942 | VkResult loader_add_to_ext_list(const struct loader_instance *inst, |
| 943 | struct loader_extension_list *ext_list, |
| 944 | uint32_t prop_list_count, |
| 945 | const VkExtensionProperties *props) { |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 946 | uint32_t i; |
| 947 | const VkExtensionProperties *cur_ext; |
| 948 | |
| 949 | if (ext_list->list == NULL || ext_list->capacity == 0) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 950 | VkResult res = loader_init_generic_list( |
| 951 | inst, (struct loader_generic_list *)ext_list, |
| 952 | sizeof(VkExtensionProperties)); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 953 | if (VK_SUCCESS != res) { |
| 954 | return res; |
| 955 | } |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 956 | } |
| 957 | |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 958 | for (i = 0; i < prop_list_count; i++) { |
| 959 | cur_ext = &props[i]; |
| 960 | |
| 961 | // look for duplicates |
| 962 | if (has_vk_extension_property(cur_ext, ext_list)) { |
| 963 | continue; |
| 964 | } |
| 965 | |
| 966 | // add to list at end |
| 967 | // check for enough capacity |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 968 | if (ext_list->count * sizeof(VkExtensionProperties) >= |
| 969 | ext_list->capacity) { |
Jon Ashburn | e39a4f8 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 970 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 971 | ext_list->list = loader_instance_heap_realloc( |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 972 | inst, ext_list->list, ext_list->capacity, |
| 973 | ext_list->capacity * 2, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Jon Ashburn | 24cd4be | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 974 | |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 975 | if (ext_list->list == NULL) { |
| 976 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 977 | "loader_add_to_ext_list: Failed to reallocate " |
| 978 | "space for extension list"); |
Jon Ashburn | 24cd4be | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 979 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 980 | } |
Jon Ashburn | 24cd4be | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 981 | |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 982 | // double capacity |
| 983 | ext_list->capacity *= 2; |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 984 | } |
| 985 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 986 | memcpy(&ext_list->list[ext_list->count], cur_ext, |
| 987 | sizeof(VkExtensionProperties)); |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 988 | ext_list->count++; |
| 989 | } |
Jon Ashburn | 24cd4be | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 990 | return VK_SUCCESS; |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 991 | } |
| 992 | |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 993 | /* |
| 994 | * Append one extension property defined in props with entrypoints |
Jon Ashburn | b872696 | 2016-04-08 15:03:35 -0600 | [diff] [blame] | 995 | * 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] | 996 | * Return |
| 997 | * Vk_SUCCESS on success |
| 998 | */ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 999 | VkResult |
| 1000 | loader_add_to_dev_ext_list(const struct loader_instance *inst, |
| 1001 | struct loader_device_extension_list *ext_list, |
| 1002 | const VkExtensionProperties *props, |
| 1003 | uint32_t entry_count, char **entrys) { |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1004 | uint32_t idx; |
| 1005 | if (ext_list->list == NULL || ext_list->capacity == 0) { |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1006 | VkResult res = loader_init_generic_list( |
| 1007 | inst, (struct loader_generic_list *)ext_list, |
| 1008 | sizeof(struct loader_dev_ext_props)); |
| 1009 | if (VK_SUCCESS != res) { |
| 1010 | return res; |
| 1011 | } |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1012 | } |
| 1013 | |
Jon Ashburn | b872696 | 2016-04-08 15:03:35 -0600 | [diff] [blame] | 1014 | // look for duplicates |
| 1015 | if (has_vk_dev_ext_property(props, ext_list)) { |
| 1016 | return VK_SUCCESS; |
| 1017 | } |
| 1018 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1019 | idx = ext_list->count; |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1020 | // add to list at end |
| 1021 | // check for enough capacity |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1022 | if (idx * sizeof(struct loader_dev_ext_props) >= ext_list->capacity) { |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1023 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1024 | ext_list->list = loader_instance_heap_realloc( |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1025 | inst, ext_list->list, ext_list->capacity, ext_list->capacity * 2, |
| 1026 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1027 | |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1028 | if (ext_list->list == NULL) { |
| 1029 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1030 | "loader_add_to_dev_ext_list: Failed to reallocate " |
| 1031 | "space for device extension list"); |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1032 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1033 | } |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1034 | |
| 1035 | // double capacity |
| 1036 | ext_list->capacity *= 2; |
| 1037 | } |
| 1038 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1039 | memcpy(&ext_list->list[idx].props, props, |
| 1040 | sizeof(struct loader_dev_ext_props)); |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1041 | ext_list->list[idx].entrypoint_count = entry_count; |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1042 | ext_list->list[idx].entrypoints = |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1043 | loader_instance_heap_alloc(inst, sizeof(char *) * entry_count, |
| 1044 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
| 1045 | if (ext_list->list[idx].entrypoints == NULL) { |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1046 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1047 | "loader_add_to_dev_ext_list: Failed to allocate space " |
| 1048 | "for device extension entrypoint list in list %d", |
| 1049 | idx); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1050 | ext_list->list[idx].entrypoint_count = 0; |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1051 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1052 | } |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1053 | for (uint32_t i = 0; i < entry_count; i++) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1054 | ext_list->list[idx].entrypoints[i] = loader_instance_heap_alloc( |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1055 | inst, strlen(entrys[i]) + 1, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1056 | if (ext_list->list[idx].entrypoints[i] == NULL) { |
| 1057 | for (uint32_t j = 0; j < i; j++) { |
| 1058 | loader_instance_heap_free(inst, |
| 1059 | ext_list->list[idx].entrypoints[j]); |
| 1060 | } |
| 1061 | loader_instance_heap_free(inst, ext_list->list[idx].entrypoints); |
| 1062 | ext_list->list[idx].entrypoint_count = 0; |
| 1063 | ext_list->list[idx].entrypoints = NULL; |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1064 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1065 | "loader_add_to_dev_ext_list: Failed to allocate space " |
| 1066 | "for device extension entrypoint %d name", |
| 1067 | i); |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1068 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1069 | } |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1070 | strcpy(ext_list->list[idx].entrypoints[i], entrys[i]); |
| 1071 | } |
| 1072 | ext_list->count++; |
| 1073 | |
| 1074 | return VK_SUCCESS; |
| 1075 | } |
| 1076 | |
Jon Ashburn | bd6c488 | 2015-07-02 12:59:25 -0600 | [diff] [blame] | 1077 | /** |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1078 | * Search the given search_list for any layers in the props list. |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1079 | * Add these to the output layer_list. Don't add duplicates to the output |
| 1080 | * layer_list. |
Jon Ashburn | bd6c488 | 2015-07-02 12:59:25 -0600 | [diff] [blame] | 1081 | */ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1082 | static VkResult |
| 1083 | loader_add_layer_names_to_list(const struct loader_instance *inst, |
| 1084 | struct loader_layer_list *output_list, |
| 1085 | uint32_t name_count, const char *const *names, |
| 1086 | const struct loader_layer_list *search_list) { |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1087 | struct loader_layer_properties *layer_prop; |
Courtney Goeltzenleuchter | 40caf0b | 2015-07-06 09:06:34 -0600 | [diff] [blame] | 1088 | VkResult err = VK_SUCCESS; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1089 | |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1090 | for (uint32_t i = 0; i < name_count; i++) { |
| 1091 | const char *search_target = names[i]; |
Jon Ashburn | e13ecc9 | 2015-08-03 17:19:30 -0600 | [diff] [blame] | 1092 | layer_prop = loader_get_layer_property(search_target, search_list); |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1093 | if (!layer_prop) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1094 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1095 | "loader_add_layer_names_to_list: Unable to find layer" |
| 1096 | " %s", |
| 1097 | search_target); |
Courtney Goeltzenleuchter | 55659b7 | 2015-09-14 18:01:17 -0600 | [diff] [blame] | 1098 | err = VK_ERROR_LAYER_NOT_PRESENT; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1099 | continue; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1100 | } |
| 1101 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1102 | err = loader_add_to_layer_list(inst, output_list, 1, layer_prop); |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1103 | } |
Courtney Goeltzenleuchter | 40caf0b | 2015-07-06 09:06:34 -0600 | [diff] [blame] | 1104 | |
| 1105 | return err; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1106 | } |
| 1107 | |
Courtney Goeltzenleuchter | 7f5aafc | 2015-07-05 11:28:29 -0600 | [diff] [blame] | 1108 | /* |
| 1109 | * Manage lists of VkLayerProperties |
| 1110 | */ |
Jon Ashburn | e39a4f8 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 1111 | static bool loader_init_layer_list(const struct loader_instance *inst, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1112 | struct loader_layer_list *list) { |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1113 | list->capacity = 32 * sizeof(struct loader_layer_properties); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1114 | list->list = loader_instance_heap_alloc( |
| 1115 | inst, list->capacity, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1116 | if (list->list == NULL) { |
| 1117 | return false; |
| 1118 | } |
| 1119 | memset(list->list, 0, list->capacity); |
| 1120 | list->count = 0; |
| 1121 | return true; |
| 1122 | } |
| 1123 | |
Jon Ashburn | e39a4f8 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 1124 | void loader_destroy_layer_list(const struct loader_instance *inst, |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1125 | struct loader_device *device, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1126 | struct loader_layer_list *layer_list) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1127 | if (device) { |
| 1128 | loader_device_heap_free(device, layer_list->list); |
| 1129 | } else { |
| 1130 | loader_instance_heap_free(inst, layer_list->list); |
| 1131 | } |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1132 | layer_list->count = 0; |
| 1133 | layer_list->capacity = 0; |
| 1134 | } |
| 1135 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1136 | /* |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1137 | * Search the given layer list for a list |
| 1138 | * matching the given VkLayerProperties |
| 1139 | */ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1140 | bool has_vk_layer_property(const VkLayerProperties *vk_layer_prop, |
| 1141 | const struct loader_layer_list *list) { |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1142 | for (uint32_t i = 0; i < list->count; i++) { |
| 1143 | if (strcmp(vk_layer_prop->layerName, list->list[i].info.layerName) == 0) |
| 1144 | return true; |
| 1145 | } |
| 1146 | return false; |
| 1147 | } |
| 1148 | |
| 1149 | /* |
| 1150 | * Search the given layer list for a layer |
| 1151 | * matching the given name |
| 1152 | */ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1153 | 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] | 1154 | for (uint32_t i = 0; i < list->count; i++) { |
| 1155 | if (strcmp(name, list->list[i].info.layerName) == 0) |
| 1156 | return true; |
| 1157 | } |
| 1158 | return false; |
| 1159 | } |
| 1160 | |
| 1161 | /* |
| 1162 | * Append non-duplicate layer properties defined in prop_list |
| 1163 | * to the given layer_info list |
| 1164 | */ |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1165 | VkResult loader_add_to_layer_list(const struct loader_instance *inst, |
| 1166 | struct loader_layer_list *list, |
| 1167 | uint32_t prop_list_count, |
| 1168 | const struct loader_layer_properties *props) { |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1169 | uint32_t i; |
| 1170 | struct loader_layer_properties *layer; |
| 1171 | |
| 1172 | if (list->list == NULL || list->capacity == 0) { |
Jon Ashburn | e39a4f8 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 1173 | loader_init_layer_list(inst, list); |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1174 | } |
| 1175 | |
| 1176 | if (list->list == NULL) |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1177 | return VK_SUCCESS; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1178 | |
| 1179 | for (i = 0; i < prop_list_count; i++) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1180 | layer = (struct loader_layer_properties *)&props[i]; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1181 | |
| 1182 | // look for duplicates |
| 1183 | if (has_vk_layer_property(&layer->info, list)) { |
| 1184 | continue; |
| 1185 | } |
| 1186 | |
| 1187 | // add to list at end |
| 1188 | // check for enough capacity |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1189 | if (list->count * sizeof(struct loader_layer_properties) >= |
| 1190 | list->capacity) { |
Jon Ashburn | e39a4f8 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 1191 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1192 | list->list = loader_instance_heap_realloc( |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1193 | inst, list->list, list->capacity, list->capacity * 2, |
| 1194 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1195 | if (NULL == list->list) { |
| 1196 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1197 | "loader_add_to_layer_list: Realloc failed for " |
| 1198 | "when attempting to add new layer"); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1199 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 1200 | } |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1201 | // double capacity |
| 1202 | list->capacity *= 2; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1203 | } |
| 1204 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1205 | memcpy(&list->list[list->count], layer, |
| 1206 | sizeof(struct loader_layer_properties)); |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1207 | list->count++; |
| 1208 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1209 | |
| 1210 | return VK_SUCCESS; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1211 | } |
| 1212 | |
Jon Ashburn | bd332cc | 2015-07-07 10:27:45 -0600 | [diff] [blame] | 1213 | /** |
| 1214 | * Search the search_list for any layer with a name |
| 1215 | * 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] | 1216 | * Add all matching layers to the found_list |
Jon Ashburn | bd332cc | 2015-07-07 10:27:45 -0600 | [diff] [blame] | 1217 | * Do not add if found loader_layer_properties is already |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1218 | * on the found_list. |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1219 | */ |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 1220 | void loader_find_layer_name_add_list( |
| 1221 | const struct loader_instance *inst, const char *name, |
| 1222 | const enum layer_type type, const struct loader_layer_list *search_list, |
| 1223 | struct loader_layer_list *found_list) { |
Jon Ashburn | 56151d6 | 2015-10-05 09:03:21 -0600 | [diff] [blame] | 1224 | bool found = false; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1225 | for (uint32_t i = 0; i < search_list->count; i++) { |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1226 | struct loader_layer_properties *layer_prop = &search_list->list[i]; |
Jon Ashburn | bd332cc | 2015-07-07 10:27:45 -0600 | [diff] [blame] | 1227 | if (0 == strcmp(layer_prop->info.layerName, name) && |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1228 | (layer_prop->type & type)) { |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1229 | /* Found a layer with the same name, add to found_list */ |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1230 | if (VK_SUCCESS == |
| 1231 | loader_add_to_layer_list(inst, found_list, 1, layer_prop)) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1232 | found = true; |
| 1233 | } |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1234 | } |
| 1235 | } |
Jon Ashburn | 56151d6 | 2015-10-05 09:03:21 -0600 | [diff] [blame] | 1236 | if (!found) { |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 1237 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1238 | "loader_find_layer_name_add_list: Failed to find layer name " |
| 1239 | "%s to activate", |
| 1240 | name); |
Jon Ashburn | 56151d6 | 2015-10-05 09:03:21 -0600 | [diff] [blame] | 1241 | } |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1242 | } |
| 1243 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1244 | static VkExtensionProperties * |
| 1245 | get_extension_property(const char *name, |
| 1246 | const struct loader_extension_list *list) { |
Courtney Goeltzenleuchter | 746db73 | 2015-07-06 17:42:01 -0600 | [diff] [blame] | 1247 | for (uint32_t i = 0; i < list->count; i++) { |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1248 | if (strcmp(name, list->list[i].extensionName) == 0) |
Courtney Goeltzenleuchter | 746db73 | 2015-07-06 17:42:01 -0600 | [diff] [blame] | 1249 | return &list->list[i]; |
Jon Ashburn | fc2e38c | 2015-04-14 09:15:32 -0600 | [diff] [blame] | 1250 | } |
Courtney Goeltzenleuchter | 746db73 | 2015-07-06 17:42:01 -0600 | [diff] [blame] | 1251 | return NULL; |
Jon Ashburn | fc2e38c | 2015-04-14 09:15:32 -0600 | [diff] [blame] | 1252 | } |
| 1253 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1254 | static VkExtensionProperties * |
| 1255 | get_dev_extension_property(const char *name, |
| 1256 | const struct loader_device_extension_list *list) { |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1257 | for (uint32_t i = 0; i < list->count; i++) { |
| 1258 | if (strcmp(name, list->list[i].props.extensionName) == 0) |
| 1259 | return &list->list[i].props; |
| 1260 | } |
| 1261 | return NULL; |
| 1262 | } |
| 1263 | |
Courtney Goeltzenleuchter | b39ccd5 | 2016-01-15 14:15:00 -0700 | [diff] [blame] | 1264 | /* |
Courtney Goeltzenleuchter | f538ef7 | 2015-12-02 14:00:19 -0700 | [diff] [blame] | 1265 | * For Instance extensions implemented within the loader (i.e. DEBUG_REPORT |
Jon Ashburn | bd6c488 | 2015-07-02 12:59:25 -0600 | [diff] [blame] | 1266 | * the extension must provide two entry points for the loader to use: |
| 1267 | * - "trampoline" entry point - this is the address returned by GetProcAddr |
| 1268 | * and will always do what's necessary to support a global call. |
| 1269 | * - "terminator" function - this function will be put at the end of the |
Jon Ashburn | 232e3af | 2015-11-30 17:21:25 -0700 | [diff] [blame] | 1270 | * instance chain and will contain the necessary logic to call / process |
Jon Ashburn | bd6c488 | 2015-07-02 12:59:25 -0600 | [diff] [blame] | 1271 | * the extension for the appropriate ICDs that are available. |
| 1272 | * There is no generic mechanism for including these functions, the references |
| 1273 | * must be placed into the appropriate loader entry points. |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1274 | * GetInstanceProcAddr: call extension GetInstanceProcAddr to check for |
| 1275 | * GetProcAddr requests |
| 1276 | * loader_coalesce_extensions(void) - add extension records to the list of |
| 1277 | * global |
Jon Ashburn | bd6c488 | 2015-07-02 12:59:25 -0600 | [diff] [blame] | 1278 | * extension available to the app. |
| 1279 | * instance_disp - add function pointer for terminator function to this array. |
| 1280 | * The extension itself should be in a separate file that will be |
| 1281 | * linked directly with the loader. |
| 1282 | */ |
Jon Ashburn | 9a4c6aa | 2015-08-14 11:57:54 -0600 | [diff] [blame] | 1283 | |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1284 | VkResult loader_get_icd_loader_instance_extensions( |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1285 | const struct loader_instance *inst, |
| 1286 | struct loader_icd_tramp_list *icd_tramp_list, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1287 | struct loader_extension_list *inst_exts) { |
Jon Ashburn | 5c6a46f | 2015-08-14 14:49:22 -0600 | [diff] [blame] | 1288 | struct loader_extension_list icd_exts; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1289 | VkResult res = VK_SUCCESS; |
| 1290 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1291 | loader_log(inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, |
| 1292 | "Build ICD instance extension list"); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1293 | |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1294 | // traverse scanned icd list adding non-duplicate extensions to the list |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1295 | for (uint32_t i = 0; i < icd_tramp_list->count; i++) { |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1296 | res = loader_init_generic_list(inst, |
| 1297 | (struct loader_generic_list *)&icd_exts, |
| 1298 | sizeof(VkExtensionProperties)); |
| 1299 | if (VK_SUCCESS != res) { |
| 1300 | goto out; |
| 1301 | } |
| 1302 | res = loader_add_instance_extensions( |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1303 | inst, icd_tramp_list->scanned_list[i] |
| 1304 | .EnumerateInstanceExtensionProperties, |
| 1305 | icd_tramp_list->scanned_list[i].lib_name, &icd_exts); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1306 | if (VK_SUCCESS == res) { |
Lenny Komow | 4053b81 | 2016-12-29 16:27:28 -0700 | [diff] [blame] | 1307 | // Remove any extensions not recognized by the loader |
| 1308 | for (int32_t j = 0; j < (int32_t)icd_exts.count; j++) { |
| 1309 | |
| 1310 | // See if the extension is in the list of supported extensions |
| 1311 | bool found = false; |
| 1312 | for (uint32_t k = 0; LOADER_INSTANCE_EXTENSIONS[k] != NULL; |
| 1313 | k++) { |
| 1314 | if (strcmp(icd_exts.list[j].extensionName, |
| 1315 | LOADER_INSTANCE_EXTENSIONS[k]) == 0) { |
| 1316 | found = true; |
| 1317 | break; |
| 1318 | } |
| 1319 | } |
| 1320 | |
| 1321 | // If it isn't in the list, remove it |
| 1322 | if (!found) { |
| 1323 | for (uint32_t k = j + 1; k < icd_exts.count; k++) { |
| 1324 | icd_exts.list[k - 1] = icd_exts.list[k]; |
| 1325 | } |
| 1326 | --icd_exts.count; |
| 1327 | --j; |
| 1328 | } |
| 1329 | } |
| 1330 | |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1331 | res = loader_add_to_ext_list(inst, inst_exts, icd_exts.count, |
| 1332 | icd_exts.list); |
| 1333 | } |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1334 | loader_destroy_generic_list(inst, |
| 1335 | (struct loader_generic_list *)&icd_exts); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1336 | if (VK_SUCCESS != res) { |
| 1337 | goto out; |
| 1338 | } |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1339 | }; |
| 1340 | |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame^] | 1341 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1342 | // Traverse loader's extensions, adding non-duplicate extensions to the list |
Jon Ashburn | e39a4f8 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 1343 | debug_report_add_instance_extensions(inst, inst_exts); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1344 | |
| 1345 | out: |
| 1346 | return res; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1347 | } |
| 1348 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1349 | struct loader_icd_term * |
| 1350 | loader_get_icd_and_device(const VkDevice device, |
| 1351 | struct loader_device **found_dev, |
| 1352 | uint32_t *icd_index) { |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1353 | *found_dev = NULL; |
Mark Young | 16573c7 | 2016-06-28 10:52:43 -0600 | [diff] [blame] | 1354 | uint32_t index = 0; |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1355 | for (struct loader_instance *inst = loader.instances; inst; |
| 1356 | inst = inst->next) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1357 | for (struct loader_icd_term *icd_term = inst->icd_terms; icd_term; |
| 1358 | icd_term = icd_term->next) { |
| 1359 | for (struct loader_device *dev = icd_term->logical_device_list; dev; |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1360 | dev = dev->next) |
Mark Young | 65cb366 | 2016-11-07 13:27:02 -0700 | [diff] [blame] | 1361 | // Value comparison of device prevents object wrapping by layers |
| 1362 | if (loader_get_dispatch(dev->icd_device) == |
| 1363 | loader_get_dispatch(device) || |
| 1364 | loader_get_dispatch(dev->chain_device) == |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1365 | loader_get_dispatch(device)) { |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1366 | *found_dev = dev; |
Mark Young | 16573c7 | 2016-06-28 10:52:43 -0600 | [diff] [blame] | 1367 | if (NULL != icd_index) { |
| 1368 | *icd_index = index; |
| 1369 | } |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1370 | return icd_term; |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1371 | } |
Mark Young | 16573c7 | 2016-06-28 10:52:43 -0600 | [diff] [blame] | 1372 | index++; |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1373 | } |
| 1374 | } |
| 1375 | return NULL; |
| 1376 | } |
| 1377 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1378 | void loader_destroy_logical_device(const struct loader_instance *inst, |
| 1379 | struct loader_device *dev, |
| 1380 | const VkAllocationCallbacks *pAllocator) { |
| 1381 | if (pAllocator) { |
| 1382 | dev->alloc_callbacks = *pAllocator; |
| 1383 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1384 | if (NULL != dev->activated_layer_list.list) { |
| 1385 | loader_deactivate_layers(inst, dev, &dev->activated_layer_list); |
| 1386 | } |
| 1387 | loader_device_heap_free(dev, dev); |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1388 | } |
| 1389 | |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 1390 | struct loader_device * |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1391 | loader_create_logical_device(const struct loader_instance *inst, |
| 1392 | const VkAllocationCallbacks *pAllocator) { |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1393 | struct loader_device *new_dev; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1394 | #if (DEBUG_DISABLE_APP_ALLOCATORS == 1) |
| 1395 | { |
| 1396 | #else |
| 1397 | if (pAllocator) { |
| 1398 | new_dev = (struct loader_device *)pAllocator->pfnAllocation( |
| 1399 | pAllocator->pUserData, sizeof(struct loader_device), sizeof(int *), |
| 1400 | VK_SYSTEM_ALLOCATION_SCOPE_DEVICE); |
| 1401 | } else { |
| 1402 | #endif |
| 1403 | new_dev = (struct loader_device *)malloc(sizeof(struct loader_device)); |
| 1404 | } |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1405 | |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1406 | if (!new_dev) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1407 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1408 | "loader_create_logical_device: Failed to alloc struct " |
| 1409 | "loader_device"); |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1410 | return NULL; |
| 1411 | } |
| 1412 | |
| 1413 | memset(new_dev, 0, sizeof(struct loader_device)); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1414 | if (pAllocator) { |
| 1415 | new_dev->alloc_callbacks = *pAllocator; |
| 1416 | } |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1417 | |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1418 | return new_dev; |
| 1419 | } |
| 1420 | |
Piers Daniell | 295fe40 | 2016-03-29 11:51:11 -0600 | [diff] [blame] | 1421 | void loader_add_logical_device(const struct loader_instance *inst, |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1422 | struct loader_icd_term *icd_term, |
Piers Daniell | 295fe40 | 2016-03-29 11:51:11 -0600 | [diff] [blame] | 1423 | struct loader_device *dev) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1424 | dev->next = icd_term->logical_device_list; |
| 1425 | icd_term->logical_device_list = dev; |
Piers Daniell | 295fe40 | 2016-03-29 11:51:11 -0600 | [diff] [blame] | 1426 | } |
| 1427 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1428 | void loader_remove_logical_device(const struct loader_instance *inst, |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1429 | struct loader_icd_term *icd_term, |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1430 | struct loader_device *found_dev, |
| 1431 | const VkAllocationCallbacks *pAllocator) { |
Jon Ashburn | 781a7ae | 2015-11-19 15:43:26 -0700 | [diff] [blame] | 1432 | struct loader_device *dev, *prev_dev; |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1433 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1434 | if (!icd_term || !found_dev) |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1435 | return; |
| 1436 | |
| 1437 | prev_dev = NULL; |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1438 | dev = icd_term->logical_device_list; |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1439 | while (dev && dev != found_dev) { |
| 1440 | prev_dev = dev; |
| 1441 | dev = dev->next; |
| 1442 | } |
| 1443 | |
| 1444 | if (prev_dev) |
| 1445 | prev_dev->next = found_dev->next; |
| 1446 | else |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1447 | icd_term->logical_device_list = found_dev->next; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1448 | loader_destroy_logical_device(inst, found_dev, pAllocator); |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1449 | } |
| 1450 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1451 | static void loader_icd_destroy(struct loader_instance *ptr_inst, |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1452 | struct loader_icd_term *icd_term, |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1453 | const VkAllocationCallbacks *pAllocator) { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1454 | ptr_inst->total_icd_count--; |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1455 | for (struct loader_device *dev = icd_term->logical_device_list; dev;) { |
Courtney Goeltzenleuchter | 1f157ac | 2015-06-14 19:57:15 -0600 | [diff] [blame] | 1456 | struct loader_device *next_dev = dev->next; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1457 | loader_destroy_logical_device(ptr_inst, dev, pAllocator); |
Courtney Goeltzenleuchter | 1f157ac | 2015-06-14 19:57:15 -0600 | [diff] [blame] | 1458 | dev = next_dev; |
| 1459 | } |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1460 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1461 | loader_instance_heap_free(ptr_inst, icd_term); |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1462 | } |
| 1463 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1464 | static struct loader_icd_term * |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1465 | loader_icd_create(const struct loader_instance *inst) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1466 | struct loader_icd_term *icd_term; |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1467 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1468 | icd_term = loader_instance_heap_alloc(inst, sizeof(struct loader_icd_term), |
| 1469 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
| 1470 | if (!icd_term) { |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1471 | return NULL; |
Mark Young | db13a2a | 2016-09-06 13:53:03 -0600 | [diff] [blame] | 1472 | } |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1473 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1474 | memset(icd_term, 0, sizeof(struct loader_icd_term)); |
Courtney Goeltzenleuchter | 55001bb | 2014-10-28 10:29:27 -0600 | [diff] [blame] | 1475 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1476 | return icd_term; |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1477 | } |
| 1478 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1479 | static struct loader_icd_term * |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1480 | loader_icd_add(struct loader_instance *ptr_inst, |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1481 | const struct loader_scanned_icd *scanned_icd) { |
| 1482 | struct loader_icd_term *icd_term; |
Chia-I Wu | 13a61a5 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 1483 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1484 | icd_term = loader_icd_create(ptr_inst); |
| 1485 | if (!icd_term) { |
Chia-I Wu | 13a61a5 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 1486 | return NULL; |
Mark Young | db13a2a | 2016-09-06 13:53:03 -0600 | [diff] [blame] | 1487 | } |
Chia-I Wu | 13a61a5 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 1488 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1489 | icd_term->scanned_icd = scanned_icd; |
| 1490 | icd_term->this_instance = ptr_inst; |
Jon Ashburn | 3d00233 | 2015-08-20 16:35:30 -0600 | [diff] [blame] | 1491 | |
Chia-I Wu | 13a61a5 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 1492 | /* prepend to the list */ |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1493 | icd_term->next = ptr_inst->icd_terms; |
| 1494 | ptr_inst->icd_terms = icd_term; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1495 | ptr_inst->total_icd_count++; |
Chia-I Wu | 13a61a5 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 1496 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1497 | return icd_term; |
Chia-I Wu | 13a61a5 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 1498 | } |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1499 | |
Jon Ashburn | 17b4c86 | 2016-04-25 11:09:37 -0600 | [diff] [blame] | 1500 | /** |
| 1501 | * Determine the ICD interface version to use. |
| 1502 | * @param icd |
| 1503 | * @param pVersion Output parameter indicating which version to use or 0 if |
| 1504 | * the negotiation API is not supported by the ICD |
| 1505 | * @return bool indicating true if the selected interface version is supported |
| 1506 | * by the loader, false indicates the version is not supported |
| 1507 | * version 0 doesn't support vk_icdGetInstanceProcAddr nor |
| 1508 | * vk_icdNegotiateLoaderICDInterfaceVersion |
| 1509 | * version 1 supports vk_icdGetInstanceProcAddr |
| 1510 | * version 2 supports vk_icdNegotiateLoaderICDInterfaceVersion |
| 1511 | */ |
| 1512 | bool loader_get_icd_interface_version( |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1513 | PFN_vkNegotiateLoaderICDInterfaceVersion fp_negotiate_icd_version, |
| 1514 | uint32_t *pVersion) { |
Jon Ashburn | 17b4c86 | 2016-04-25 11:09:37 -0600 | [diff] [blame] | 1515 | |
| 1516 | if (fp_negotiate_icd_version == NULL) { |
| 1517 | // ICD does not support the negotiation API, it supports version 0 or 1 |
| 1518 | // calling code must determine if it is version 0 or 1 |
| 1519 | *pVersion = 0; |
| 1520 | } else { |
| 1521 | // ICD supports the negotiation API, so call it with the loader's |
| 1522 | // latest version supported |
| 1523 | *pVersion = CURRENT_LOADER_ICD_INTERFACE_VERSION; |
| 1524 | VkResult result = fp_negotiate_icd_version(pVersion); |
| 1525 | |
| 1526 | if (result == VK_ERROR_INCOMPATIBLE_DRIVER) { |
| 1527 | // ICD no longer supports the loader's latest interface version so |
| 1528 | // fail loading the ICD |
| 1529 | return false; |
| 1530 | } |
| 1531 | } |
| 1532 | |
| 1533 | #if MIN_SUPPORTED_LOADER_ICD_INTERFACE_VERSION > 0 |
| 1534 | if (*pVersion < MIN_SUPPORTED_LOADER_ICD_INTERFACE_VERSION) { |
| 1535 | // Loader no longer supports the ICD's latest interface version so fail |
| 1536 | // loading the ICD |
| 1537 | return false; |
| 1538 | } |
| 1539 | #endif |
| 1540 | return true; |
| 1541 | } |
Chia-I Wu | 13a61a5 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 1542 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1543 | void loader_scanned_icd_clear(const struct loader_instance *inst, |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1544 | struct loader_icd_tramp_list *icd_tramp_list) { |
| 1545 | if (icd_tramp_list->capacity == 0) |
Jon Ashburn | 8810c5f | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 1546 | return; |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1547 | for (uint32_t i = 0; i < icd_tramp_list->count; i++) { |
| 1548 | loader_platform_close_library(icd_tramp_list->scanned_list[i].handle); |
| 1549 | loader_instance_heap_free(inst, |
| 1550 | icd_tramp_list->scanned_list[i].lib_name); |
Jon Ashburn | 8810c5f | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 1551 | } |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1552 | loader_instance_heap_free(inst, icd_tramp_list->scanned_list); |
| 1553 | icd_tramp_list->capacity = 0; |
| 1554 | icd_tramp_list->count = 0; |
| 1555 | icd_tramp_list->scanned_list = NULL; |
Jon Ashburn | 8810c5f | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 1556 | } |
| 1557 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1558 | static VkResult |
| 1559 | loader_scanned_icd_init(const struct loader_instance *inst, |
| 1560 | struct loader_icd_tramp_list *icd_tramp_list) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1561 | VkResult err = VK_SUCCESS; |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1562 | loader_scanned_icd_clear(inst, icd_tramp_list); |
| 1563 | icd_tramp_list->capacity = 8 * sizeof(struct loader_scanned_icd); |
| 1564 | icd_tramp_list->scanned_list = loader_instance_heap_alloc( |
| 1565 | inst, icd_tramp_list->capacity, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
| 1566 | if (NULL == icd_tramp_list->scanned_list) { |
| 1567 | loader_log( |
| 1568 | inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1569 | "loader_scanned_icd_init: Realloc failed for layer list when " |
| 1570 | "attempting to add new layer"); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1571 | err = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 1572 | } |
| 1573 | return err; |
Jon Ashburn | 8810c5f | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 1574 | } |
| 1575 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1576 | static VkResult |
| 1577 | loader_scanned_icd_add(const struct loader_instance *inst, |
| 1578 | struct loader_icd_tramp_list *icd_tramp_list, |
| 1579 | const char *filename, uint32_t api_version) { |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1580 | loader_platform_dl_handle handle; |
Tony Barbour | 1d2cd3f | 2015-07-03 10:33:54 -0600 | [diff] [blame] | 1581 | PFN_vkCreateInstance fp_create_inst; |
Jon Ashburn | fd4d09d | 2016-01-07 09:44:27 -0700 | [diff] [blame] | 1582 | PFN_vkEnumerateInstanceExtensionProperties fp_get_inst_ext_props; |
Jon Ashburn | c624c88 | 2015-07-16 10:17:29 -0600 | [diff] [blame] | 1583 | PFN_vkGetInstanceProcAddr fp_get_proc_addr; |
Jon Ashburn | 17b4c86 | 2016-04-25 11:09:37 -0600 | [diff] [blame] | 1584 | PFN_vkNegotiateLoaderICDInterfaceVersion fp_negotiate_icd_version; |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1585 | struct loader_scanned_icd *new_scanned_icd; |
Jon Ashburn | 17b4c86 | 2016-04-25 11:09:37 -0600 | [diff] [blame] | 1586 | uint32_t interface_vers; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1587 | VkResult res = VK_SUCCESS; |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 1588 | |
Jon Ashburn | 4dc1d8a | 2016-04-20 13:21:17 -0600 | [diff] [blame] | 1589 | /* TODO implement smarter opening/closing of libraries. For now this |
| 1590 | * function leaves libraries open and the scanned_icd_clear closes them */ |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1591 | handle = loader_platform_open_library(filename); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1592 | if (NULL == handle) { |
| 1593 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1594 | loader_platform_open_library_error(filename)); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1595 | goto out; |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 1596 | } |
| 1597 | |
Jon Ashburn | 17b4c86 | 2016-04-25 11:09:37 -0600 | [diff] [blame] | 1598 | // Get and settle on an ICD interface version |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1599 | fp_negotiate_icd_version = loader_platform_get_proc_address( |
| 1600 | handle, "vk_icdNegotiateLoaderICDInterfaceVersion"); |
Jon Ashburn | 17b4c86 | 2016-04-25 11:09:37 -0600 | [diff] [blame] | 1601 | |
| 1602 | if (!loader_get_icd_interface_version(fp_negotiate_icd_version, |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1603 | &interface_vers)) { |
| 1604 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1605 | "loader_scanned_icd_add: ICD %s doesn't support interface" |
| 1606 | " version compatible with loader, skip this ICD.", |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1607 | filename); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1608 | goto out; |
Jon Ashburn | 17b4c86 | 2016-04-25 11:09:37 -0600 | [diff] [blame] | 1609 | } |
| 1610 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1611 | fp_get_proc_addr = |
| 1612 | loader_platform_get_proc_address(handle, "vk_icdGetInstanceProcAddr"); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1613 | if (NULL == fp_get_proc_addr) { |
Jon Ashburn | 17b4c86 | 2016-04-25 11:09:37 -0600 | [diff] [blame] | 1614 | assert(interface_vers == 0); |
| 1615 | // Use deprecated interface from version 0 |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1616 | fp_get_proc_addr = |
| 1617 | loader_platform_get_proc_address(handle, "vkGetInstanceProcAddr"); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1618 | if (NULL == fp_get_proc_addr) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1619 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1620 | "loader_scanned_icd_add: Attempt to retreive either " |
| 1621 | " \'vkGetInstanceProcAddr\' or " |
| 1622 | "\'vk_icdGetInstanceProcAddr\' from ICD %s failed.", |
| 1623 | filename); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1624 | goto out; |
Jon Ashburn | fd4d09d | 2016-01-07 09:44:27 -0700 | [diff] [blame] | 1625 | } else { |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 1626 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1627 | "loader_scanned_icd_add: Using deprecated ICD " |
| 1628 | "interface of \'vkGetInstanceProcAddr\' instead of " |
| 1629 | "\'vk_icdGetInstanceProcAddr\' for ICD %s", |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1630 | filename); |
Jon Ashburn | fd4d09d | 2016-01-07 09:44:27 -0700 | [diff] [blame] | 1631 | } |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1632 | fp_create_inst = |
| 1633 | loader_platform_get_proc_address(handle, "vkCreateInstance"); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1634 | if (NULL == fp_create_inst) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1635 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1636 | "loader_scanned_icd_add: Failed querying " |
| 1637 | "\'vkCreateInstance\' via dlsym/loadlibrary for " |
| 1638 | "ICD %s", |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1639 | filename); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1640 | goto out; |
Jon Ashburn | 69a5f7a | 2016-01-11 14:41:35 -0700 | [diff] [blame] | 1641 | } |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1642 | fp_get_inst_ext_props = loader_platform_get_proc_address( |
| 1643 | handle, "vkEnumerateInstanceExtensionProperties"); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1644 | if (NULL == fp_get_inst_ext_props) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1645 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1646 | "loader_scanned_icd_add: Could not get \'vkEnumerate" |
| 1647 | "InstanceExtensionProperties\' via dlsym/loadlibrary " |
| 1648 | "for ICD %s", |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1649 | filename); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1650 | goto out; |
Jon Ashburn | 69a5f7a | 2016-01-11 14:41:35 -0700 | [diff] [blame] | 1651 | } |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1652 | } else { |
Jon Ashburn | 17b4c86 | 2016-04-25 11:09:37 -0600 | [diff] [blame] | 1653 | // Use newer interface version 1 or later |
| 1654 | if (interface_vers == 0) |
| 1655 | interface_vers = 1; |
| 1656 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1657 | fp_create_inst = |
| 1658 | (PFN_vkCreateInstance)fp_get_proc_addr(NULL, "vkCreateInstance"); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1659 | if (NULL == fp_create_inst) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1660 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1661 | "loader_scanned_icd_add: Could not get " |
| 1662 | "\'vkCreateInstance\' via \'vk_icdGetInstanceProcAddr\'" |
| 1663 | " for ICD %s", |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1664 | filename); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1665 | goto out; |
Jon Ashburn | 69a5f7a | 2016-01-11 14:41:35 -0700 | [diff] [blame] | 1666 | } |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1667 | fp_get_inst_ext_props = |
| 1668 | (PFN_vkEnumerateInstanceExtensionProperties)fp_get_proc_addr( |
| 1669 | NULL, "vkEnumerateInstanceExtensionProperties"); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1670 | if (NULL == fp_get_inst_ext_props) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1671 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1672 | "loader_scanned_icd_add: Could not get \'vkEnumerate" |
| 1673 | "InstanceExtensionProperties\' via " |
| 1674 | "\'vk_icdGetInstanceProcAddr\' for ICD %s", |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1675 | filename); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1676 | goto out; |
Jon Ashburn | 69a5f7a | 2016-01-11 14:41:35 -0700 | [diff] [blame] | 1677 | } |
Jon Ashburn | fd4d09d | 2016-01-07 09:44:27 -0700 | [diff] [blame] | 1678 | } |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 1679 | |
Jon Ashburn | 8810c5f | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 1680 | // check for enough capacity |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1681 | if ((icd_tramp_list->count * sizeof(struct loader_scanned_icd)) >= |
| 1682 | icd_tramp_list->capacity) { |
Jon Ashburn | e39a4f8 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 1683 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1684 | icd_tramp_list->scanned_list = loader_instance_heap_realloc( |
| 1685 | inst, icd_tramp_list->scanned_list, icd_tramp_list->capacity, |
| 1686 | icd_tramp_list->capacity * 2, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
| 1687 | if (NULL == icd_tramp_list->scanned_list) { |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1688 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1689 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1690 | "loader_scanned_icd_add: Realloc failed on icd library" |
| 1691 | " list for ICD %s", |
| 1692 | filename); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1693 | goto out; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1694 | } |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1695 | // double capacity |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1696 | icd_tramp_list->capacity *= 2; |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 1697 | } |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1698 | new_scanned_icd = &(icd_tramp_list->scanned_list[icd_tramp_list->count]); |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 1699 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1700 | new_scanned_icd->handle = handle; |
| 1701 | new_scanned_icd->api_version = api_version; |
| 1702 | new_scanned_icd->GetInstanceProcAddr = fp_get_proc_addr; |
| 1703 | new_scanned_icd->EnumerateInstanceExtensionProperties = |
| 1704 | fp_get_inst_ext_props; |
| 1705 | new_scanned_icd->CreateInstance = fp_create_inst; |
| 1706 | new_scanned_icd->interface_version = interface_vers; |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 1707 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1708 | new_scanned_icd->lib_name = (char *)loader_instance_heap_alloc( |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1709 | inst, strlen(filename) + 1, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1710 | if (NULL == new_scanned_icd->lib_name) { |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1711 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1712 | "loader_scanned_icd_add: Out of memory can't add ICD %s", |
| 1713 | filename); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1714 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1715 | goto out; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1716 | } |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1717 | strcpy(new_scanned_icd->lib_name, filename); |
| 1718 | icd_tramp_list->count++; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1719 | |
| 1720 | out: |
| 1721 | |
| 1722 | return res; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1723 | } |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1724 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1725 | static bool loader_icd_init_entrys(struct loader_icd_term *icd_term, |
| 1726 | VkInstance inst, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1727 | const PFN_vkGetInstanceProcAddr fp_gipa) { |
| 1728 | /* initialize entrypoint function pointers */ |
Jon Ashburn | 3da71f2 | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 1729 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1730 | #define LOOKUP_GIPA(func, required) \ |
| 1731 | do { \ |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1732 | icd_term->func = (PFN_vk##func)fp_gipa(inst, "vk" #func); \ |
| 1733 | if (!icd_term->func && required) { \ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1734 | loader_log((struct loader_instance *)inst, \ |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 1735 | VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, \ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1736 | loader_platform_get_proc_address_error("vk" #func)); \ |
| 1737 | return false; \ |
| 1738 | } \ |
Jon Ashburn | 3da71f2 | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 1739 | } while (0) |
| 1740 | |
Jon Ashburn | c624c88 | 2015-07-16 10:17:29 -0600 | [diff] [blame] | 1741 | LOOKUP_GIPA(GetDeviceProcAddr, true); |
| 1742 | LOOKUP_GIPA(DestroyInstance, true); |
| 1743 | LOOKUP_GIPA(EnumeratePhysicalDevices, true); |
| 1744 | LOOKUP_GIPA(GetPhysicalDeviceFeatures, true); |
| 1745 | LOOKUP_GIPA(GetPhysicalDeviceFormatProperties, true); |
Jon Ashburn | 754864f | 2015-07-23 18:49:07 -0600 | [diff] [blame] | 1746 | LOOKUP_GIPA(GetPhysicalDeviceImageFormatProperties, true); |
Jon Ashburn | c624c88 | 2015-07-16 10:17:29 -0600 | [diff] [blame] | 1747 | LOOKUP_GIPA(CreateDevice, true); |
| 1748 | LOOKUP_GIPA(GetPhysicalDeviceProperties, true); |
| 1749 | LOOKUP_GIPA(GetPhysicalDeviceMemoryProperties, true); |
Cody Northrop | d080288 | 2015-08-03 17:04:53 -0600 | [diff] [blame] | 1750 | LOOKUP_GIPA(GetPhysicalDeviceQueueFamilyProperties, true); |
Courtney Goeltzenleuchter | 35985f6 | 2015-09-14 17:22:16 -0600 | [diff] [blame] | 1751 | LOOKUP_GIPA(EnumerateDeviceExtensionProperties, true); |
Jon Ashburn | c624c88 | 2015-07-16 10:17:29 -0600 | [diff] [blame] | 1752 | LOOKUP_GIPA(GetPhysicalDeviceSparseImageFormatProperties, true); |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1753 | LOOKUP_GIPA(CreateDebugReportCallbackEXT, false); |
| 1754 | LOOKUP_GIPA(DestroyDebugReportCallbackEXT, false); |
Mark Young | 65cb366 | 2016-11-07 13:27:02 -0700 | [diff] [blame] | 1755 | LOOKUP_GIPA(DebugMarkerSetObjectTagEXT, false); |
| 1756 | LOOKUP_GIPA(DebugMarkerSetObjectNameEXT, false); |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 1757 | LOOKUP_GIPA(GetPhysicalDeviceSurfaceSupportKHR, false); |
Ian Elliott | 486c550 | 2015-11-19 16:05:09 -0700 | [diff] [blame] | 1758 | LOOKUP_GIPA(GetPhysicalDeviceSurfaceCapabilitiesKHR, false); |
| 1759 | LOOKUP_GIPA(GetPhysicalDeviceSurfaceFormatsKHR, false); |
| 1760 | LOOKUP_GIPA(GetPhysicalDeviceSurfacePresentModesKHR, false); |
Petros Bantolas | 25d27fe | 2016-04-14 12:50:42 +0100 | [diff] [blame] | 1761 | LOOKUP_GIPA(GetPhysicalDeviceDisplayPropertiesKHR, false); |
| 1762 | LOOKUP_GIPA(GetDisplayModePropertiesKHR, false); |
| 1763 | LOOKUP_GIPA(CreateDisplayPlaneSurfaceKHR, false); |
| 1764 | LOOKUP_GIPA(GetPhysicalDeviceDisplayPlanePropertiesKHR, false); |
| 1765 | LOOKUP_GIPA(GetDisplayPlaneSupportedDisplaysKHR, false); |
| 1766 | LOOKUP_GIPA(CreateDisplayModeKHR, false); |
| 1767 | LOOKUP_GIPA(GetDisplayPlaneCapabilitiesKHR, false); |
| 1768 | LOOKUP_GIPA(DestroySurfaceKHR, false); |
Mark Young | 16573c7 | 2016-06-28 10:52:43 -0600 | [diff] [blame] | 1769 | LOOKUP_GIPA(CreateSwapchainKHR, false); |
Ian Elliott | 919fa30 | 2015-11-24 15:39:10 -0700 | [diff] [blame] | 1770 | #ifdef VK_USE_PLATFORM_WIN32_KHR |
Mark Young | 16573c7 | 2016-06-28 10:52:43 -0600 | [diff] [blame] | 1771 | LOOKUP_GIPA(CreateWin32SurfaceKHR, false); |
Ian Elliott | 919fa30 | 2015-11-24 15:39:10 -0700 | [diff] [blame] | 1772 | LOOKUP_GIPA(GetPhysicalDeviceWin32PresentationSupportKHR, false); |
| 1773 | #endif |
| 1774 | #ifdef VK_USE_PLATFORM_XCB_KHR |
Mark Young | 16573c7 | 2016-06-28 10:52:43 -0600 | [diff] [blame] | 1775 | LOOKUP_GIPA(CreateXcbSurfaceKHR, false); |
Ian Elliott | 919fa30 | 2015-11-24 15:39:10 -0700 | [diff] [blame] | 1776 | LOOKUP_GIPA(GetPhysicalDeviceXcbPresentationSupportKHR, false); |
| 1777 | #endif |
Karl Schultz | 65d2018 | 2016-03-08 07:55:27 -0700 | [diff] [blame] | 1778 | #ifdef VK_USE_PLATFORM_XLIB_KHR |
Mark Young | 16573c7 | 2016-06-28 10:52:43 -0600 | [diff] [blame] | 1779 | LOOKUP_GIPA(CreateXlibSurfaceKHR, false); |
Karl Schultz | 65d2018 | 2016-03-08 07:55:27 -0700 | [diff] [blame] | 1780 | LOOKUP_GIPA(GetPhysicalDeviceXlibPresentationSupportKHR, false); |
| 1781 | #endif |
Mark Young | a7c51fd | 2016-09-16 10:18:42 -0600 | [diff] [blame] | 1782 | #ifdef VK_USE_PLATFORM_MIR_KHR |
| 1783 | LOOKUP_GIPA(CreateMirSurfaceKHR, false); |
| 1784 | LOOKUP_GIPA(GetPhysicalDeviceMirPresentationSupportKHR, false); |
| 1785 | #endif |
Jason Ekstrand | a5ebe8a | 2016-02-12 17:25:03 -0800 | [diff] [blame] | 1786 | #ifdef VK_USE_PLATFORM_WAYLAND_KHR |
Mark Young | 16573c7 | 2016-06-28 10:52:43 -0600 | [diff] [blame] | 1787 | LOOKUP_GIPA(CreateWaylandSurfaceKHR, false); |
Jason Ekstrand | a5ebe8a | 2016-02-12 17:25:03 -0800 | [diff] [blame] | 1788 | LOOKUP_GIPA(GetPhysicalDeviceWaylandPresentationSupportKHR, false); |
| 1789 | #endif |
Mark Young | fa55278 | 2016-12-12 16:14:55 -0700 | [diff] [blame] | 1790 | // NV_external_memory_capabilities |
James Jones | 389dc0c | 2016-08-18 23:41:19 +0100 | [diff] [blame] | 1791 | LOOKUP_GIPA(GetPhysicalDeviceExternalImageFormatPropertiesNV, false); |
Mark Young | fa55278 | 2016-12-12 16:14:55 -0700 | [diff] [blame] | 1792 | // NVX_device_generated_commands |
| 1793 | LOOKUP_GIPA(GetPhysicalDeviceGeneratedCommandsPropertiesNVX, false); |
Jon Ashburn | 3da71f2 | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 1794 | |
Jon Ashburn | c624c88 | 2015-07-16 10:17:29 -0600 | [diff] [blame] | 1795 | #undef LOOKUP_GIPA |
Ian Elliott | d3ef02f | 2015-07-06 14:36:13 -0600 | [diff] [blame] | 1796 | |
Jon Ashburn | c624c88 | 2015-07-16 10:17:29 -0600 | [diff] [blame] | 1797 | return true; |
Jon Ashburn | 3da71f2 | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 1798 | } |
| 1799 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1800 | static void loader_debug_init(void) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1801 | char *env, *orig; |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 1802 | |
| 1803 | if (g_loader_debug > 0) |
| 1804 | return; |
| 1805 | |
| 1806 | g_loader_debug = 0; |
| 1807 | |
| 1808 | /* parse comma-separated debug options */ |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1809 | orig = env = loader_getenv("VK_LOADER_DEBUG", NULL); |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 1810 | while (env) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1811 | char *p = strchr(env, ','); |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 1812 | size_t len; |
| 1813 | |
| 1814 | if (p) |
| 1815 | len = p - env; |
| 1816 | else |
| 1817 | len = strlen(env); |
| 1818 | |
| 1819 | if (len > 0) { |
Michael Worcester | 25c73e7 | 2015-12-10 18:06:24 +0000 | [diff] [blame] | 1820 | if (strncmp(env, "all", len) == 0) { |
| 1821 | g_loader_debug = ~0u; |
| 1822 | g_loader_log_msgs = ~0u; |
| 1823 | } else if (strncmp(env, "warn", len) == 0) { |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 1824 | g_loader_debug |= LOADER_WARN_BIT; |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 1825 | g_loader_log_msgs |= VK_DEBUG_REPORT_WARNING_BIT_EXT; |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 1826 | } else if (strncmp(env, "info", len) == 0) { |
| 1827 | g_loader_debug |= LOADER_INFO_BIT; |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 1828 | g_loader_log_msgs |= VK_DEBUG_REPORT_INFORMATION_BIT_EXT; |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 1829 | } else if (strncmp(env, "perf", len) == 0) { |
| 1830 | g_loader_debug |= LOADER_PERF_BIT; |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 1831 | g_loader_log_msgs |= |
| 1832 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT; |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 1833 | } else if (strncmp(env, "error", len) == 0) { |
| 1834 | g_loader_debug |= LOADER_ERROR_BIT; |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1835 | g_loader_log_msgs |= VK_DEBUG_REPORT_ERROR_BIT_EXT; |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 1836 | } else if (strncmp(env, "debug", len) == 0) { |
| 1837 | g_loader_debug |= LOADER_DEBUG_BIT; |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1838 | g_loader_log_msgs |= VK_DEBUG_REPORT_DEBUG_BIT_EXT; |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 1839 | } |
| 1840 | } |
| 1841 | |
| 1842 | if (!p) |
| 1843 | break; |
| 1844 | |
| 1845 | env = p + 1; |
| 1846 | } |
Jon Ashburn | 38a497f | 2016-01-04 14:01:38 -0700 | [diff] [blame] | 1847 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1848 | loader_free_getenv(orig, NULL); |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 1849 | } |
| 1850 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1851 | void loader_initialize(void) { |
Jon Ashburn | 6461ef2 | 2015-09-22 13:11:00 -0600 | [diff] [blame] | 1852 | // initialize mutexs |
Jon Ashburn | 8810c5f | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 1853 | loader_platform_thread_create_mutex(&loader_lock); |
Jon Ashburn | 6461ef2 | 2015-09-22 13:11:00 -0600 | [diff] [blame] | 1854 | loader_platform_thread_create_mutex(&loader_json_lock); |
Jon Ashburn | 8810c5f | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 1855 | |
| 1856 | // initialize logging |
| 1857 | loader_debug_init(); |
Jon Ashburn | 87d6aa9 | 2015-08-28 15:19:27 -0600 | [diff] [blame] | 1858 | |
| 1859 | // initial cJSON to use alloc callbacks |
| 1860 | cJSON_Hooks alloc_fns = { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1861 | .malloc_fn = loader_instance_tls_heap_alloc, |
| 1862 | .free_fn = loader_instance_tls_heap_free, |
Jon Ashburn | 87d6aa9 | 2015-08-28 15:19:27 -0600 | [diff] [blame] | 1863 | }; |
| 1864 | cJSON_InitHooks(&alloc_fns); |
Jon Ashburn | 8810c5f | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 1865 | } |
| 1866 | |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1867 | struct loader_manifest_files { |
| 1868 | uint32_t count; |
| 1869 | char **filename_list; |
| 1870 | }; |
| 1871 | |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 1872 | /** |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1873 | * 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] | 1874 | * |
| 1875 | * \returns |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1876 | * A pointer to first char in the next path. |
| 1877 | * The next path (or NULL) in the list is returned in next_path. |
| 1878 | * Note: input string is modified in some cases. PASS IN A COPY! |
| 1879 | */ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1880 | static char *loader_get_next_path(char *path) { |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1881 | uint32_t len; |
| 1882 | char *next; |
| 1883 | |
| 1884 | if (path == NULL) |
| 1885 | return NULL; |
Frank Henigman | 5717310 | 2016-11-24 22:15:20 -0500 | [diff] [blame] | 1886 | next = strchr(path, PATH_SEPARATOR); |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1887 | if (next == NULL) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1888 | len = (uint32_t)strlen(path); |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1889 | next = path + len; |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1890 | } else { |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1891 | *next = '\0'; |
| 1892 | next++; |
| 1893 | } |
| 1894 | |
| 1895 | return next; |
| 1896 | } |
| 1897 | |
| 1898 | /** |
Daniel Dadap | 00b4aba | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 1899 | * Given a path which is absolute or relative, expand the path if relative or |
| 1900 | * leave the path unmodified if absolute. The base path to prepend to relative |
| 1901 | * paths is given in rel_base. |
Jon Ashburn | 1531517 | 2015-07-07 15:06:25 -0600 | [diff] [blame] | 1902 | * |
| 1903 | * \returns |
| 1904 | * A string in out_fullpath of the full absolute path |
Jon Ashburn | 1531517 | 2015-07-07 15:06:25 -0600 | [diff] [blame] | 1905 | */ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1906 | static void loader_expand_path(const char *path, const char *rel_base, |
| 1907 | size_t out_size, char *out_fullpath) { |
Jon Ashburn | 1531517 | 2015-07-07 15:06:25 -0600 | [diff] [blame] | 1908 | if (loader_platform_is_path_absolute(path)) { |
Daniel Dadap | 00b4aba | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 1909 | // do not prepend a base to an absolute path |
| 1910 | rel_base = ""; |
Jon Ashburn | 1531517 | 2015-07-07 15:06:25 -0600 | [diff] [blame] | 1911 | } |
Daniel Dadap | 00b4aba | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 1912 | |
| 1913 | loader_platform_combine_path(out_fullpath, out_size, rel_base, path, NULL); |
Jon Ashburn | 1531517 | 2015-07-07 15:06:25 -0600 | [diff] [blame] | 1914 | } |
| 1915 | |
| 1916 | /** |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1917 | * Given a filename (file) and a list of paths (dir), try to find an existing |
| 1918 | * file in the paths. If filename already is a path then no |
| 1919 | * searching in the given paths. |
| 1920 | * |
| 1921 | * \returns |
| 1922 | * A string in out_fullpath of either the full path or file. |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1923 | */ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1924 | static void loader_get_fullpath(const char *file, const char *dirs, |
| 1925 | size_t out_size, char *out_fullpath) { |
Daniel Dadap | 00b4aba | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 1926 | if (!loader_platform_is_path(file) && *dirs) { |
| 1927 | char *dirs_copy, *dir, *next_dir; |
| 1928 | |
| 1929 | dirs_copy = loader_stack_alloc(strlen(dirs) + 1); |
| 1930 | strcpy(dirs_copy, dirs); |
| 1931 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1932 | // find if file exists after prepending paths in given list |
| 1933 | for (dir = dirs_copy; *dir && (next_dir = loader_get_next_path(dir)); |
Daniel Dadap | 00b4aba | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 1934 | dir = next_dir) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1935 | loader_platform_combine_path(out_fullpath, out_size, dir, file, |
| 1936 | NULL); |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1937 | if (loader_platform_file_exists(out_fullpath)) { |
| 1938 | return; |
| 1939 | } |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1940 | } |
| 1941 | } |
Daniel Dadap | 00b4aba | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 1942 | |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1943 | snprintf(out_fullpath, out_size, "%s", file); |
| 1944 | } |
| 1945 | |
| 1946 | /** |
| 1947 | * Read a JSON file into a buffer. |
| 1948 | * |
| 1949 | * \returns |
| 1950 | * A pointer to a cJSON object representing the JSON parse tree. |
| 1951 | * This returned buffer should be freed by caller. |
| 1952 | */ |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1953 | static VkResult loader_get_json(const struct loader_instance *inst, |
| 1954 | const char *filename, cJSON **json) { |
| 1955 | FILE *file = NULL; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1956 | char *json_buf; |
Mark Young | 93ecb1d | 2016-01-13 13:47:16 -0700 | [diff] [blame] | 1957 | size_t len; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1958 | VkResult res = VK_SUCCESS; |
| 1959 | |
| 1960 | if (NULL == json) { |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1961 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1962 | "loader_get_json: Received invalid JSON file"); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1963 | res = VK_ERROR_INITIALIZATION_FAILED; |
| 1964 | goto out; |
| 1965 | } |
| 1966 | |
| 1967 | *json = NULL; |
| 1968 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1969 | file = fopen(filename, "rb"); |
Jon Ashburn | aa4ea47 | 2015-08-27 08:30:50 -0600 | [diff] [blame] | 1970 | if (!file) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1971 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1972 | "loader_get_json: Failed to open JSON file %s", filename); |
| 1973 | res = VK_ERROR_INITIALIZATION_FAILED; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1974 | goto out; |
Jon Ashburn | aa4ea47 | 2015-08-27 08:30:50 -0600 | [diff] [blame] | 1975 | } |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1976 | fseek(file, 0, SEEK_END); |
| 1977 | len = ftell(file); |
| 1978 | fseek(file, 0, SEEK_SET); |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1979 | json_buf = (char *)loader_stack_alloc(len + 1); |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1980 | if (json_buf == NULL) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1981 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1982 | "loader_get_json: Failed to allocate space for " |
| 1983 | " JSON file %s buffer of length %d", |
| 1984 | filename, len); |
| 1985 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1986 | goto out; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1987 | } |
| 1988 | if (fread(json_buf, sizeof(char), len, file) != len) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1989 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1990 | "loader_get_json: Failed to read JSON file %s.", filename); |
| 1991 | res = VK_ERROR_INITIALIZATION_FAILED; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1992 | goto out; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1993 | } |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1994 | json_buf[len] = '\0'; |
| 1995 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1996 | // parse text from file |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1997 | *json = cJSON_Parse(json_buf); |
| 1998 | if (*json == NULL) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1999 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2000 | "loader_get_json: Failed to parse JSON file %s, " |
| 2001 | " this is usually because something ran out of " |
| 2002 | " memory.", |
| 2003 | filename); |
| 2004 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 2005 | goto out; |
| 2006 | } |
| 2007 | |
| 2008 | out: |
| 2009 | if (NULL != file) { |
| 2010 | fclose(file); |
| 2011 | } |
| 2012 | |
| 2013 | return res; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2014 | } |
| 2015 | |
| 2016 | /** |
Jon Ashburn | 3d00233 | 2015-08-20 16:35:30 -0600 | [diff] [blame] | 2017 | * Do a deep copy of the loader_layer_properties structure. |
| 2018 | */ |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2019 | VkResult loader_copy_layer_properties(const struct loader_instance *inst, |
| 2020 | struct loader_layer_properties *dst, |
| 2021 | struct loader_layer_properties *src) { |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 2022 | uint32_t cnt, i; |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2023 | memcpy(dst, src, sizeof(*src)); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2024 | dst->instance_extension_list.list = loader_instance_heap_alloc( |
| 2025 | inst, |
| 2026 | sizeof(VkExtensionProperties) * src->instance_extension_list.count, |
| 2027 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2028 | if (NULL == dst->instance_extension_list.list) { |
| 2029 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2030 | "loader_copy_layer_properties: Failed to allocate space " |
| 2031 | " for instance extension list of size %d.", |
| 2032 | src->instance_extension_list.count); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2033 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 2034 | } |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2035 | dst->instance_extension_list.capacity = |
| 2036 | sizeof(VkExtensionProperties) * src->instance_extension_list.count; |
Jon Ashburn | e39a4f8 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 2037 | memcpy(dst->instance_extension_list.list, src->instance_extension_list.list, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2038 | dst->instance_extension_list.capacity); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2039 | dst->device_extension_list.list = loader_instance_heap_alloc( |
| 2040 | inst, |
| 2041 | sizeof(struct loader_dev_ext_props) * src->device_extension_list.count, |
| 2042 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2043 | if (NULL == dst->device_extension_list.list) { |
| 2044 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2045 | "loader_copy_layer_properties: Failed to allocate space " |
| 2046 | " for device extension list of size %d.", |
| 2047 | src->device_extension_list.count); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2048 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 2049 | } |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 2050 | memset(dst->device_extension_list.list, 0, |
| 2051 | sizeof(struct loader_dev_ext_props) * |
| 2052 | src->device_extension_list.count); |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 2053 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2054 | dst->device_extension_list.capacity = |
| 2055 | sizeof(struct loader_dev_ext_props) * src->device_extension_list.count; |
Jon Ashburn | e39a4f8 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 2056 | memcpy(dst->device_extension_list.list, src->device_extension_list.list, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2057 | dst->device_extension_list.capacity); |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 2058 | if (src->device_extension_list.count > 0 && |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2059 | src->device_extension_list.list->entrypoint_count > 0) { |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 2060 | cnt = src->device_extension_list.list->entrypoint_count; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2061 | dst->device_extension_list.list->entrypoints = |
| 2062 | loader_instance_heap_alloc(inst, sizeof(char *) * cnt, |
| 2063 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
| 2064 | if (NULL == dst->device_extension_list.list->entrypoints) { |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2065 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 2066 | "loader_copy_layer_properties: Failed to allocate space " |
| 2067 | " for device extension entrypoint list of size %d.", |
| 2068 | cnt); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2069 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 2070 | } |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 2071 | memset(dst->device_extension_list.list->entrypoints, 0, |
| 2072 | sizeof(char *) * cnt); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2073 | |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 2074 | for (i = 0; i < cnt; i++) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2075 | dst->device_extension_list.list->entrypoints[i] = |
| 2076 | loader_instance_heap_alloc( |
| 2077 | inst, |
| 2078 | strlen(src->device_extension_list.list->entrypoints[i]) + 1, |
| 2079 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
| 2080 | if (NULL == dst->device_extension_list.list->entrypoints[i]) { |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2081 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 2082 | "loader_copy_layer_properties: Failed to " |
| 2083 | "allocate space for device extension entrypoint " |
| 2084 | "%d name of length", |
| 2085 | i); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2086 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 2087 | } |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 2088 | strcpy(dst->device_extension_list.list->entrypoints[i], |
| 2089 | src->device_extension_list.list->entrypoints[i]); |
| 2090 | } |
| 2091 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2092 | |
| 2093 | return VK_SUCCESS; |
Jon Ashburn | 3d00233 | 2015-08-20 16:35:30 -0600 | [diff] [blame] | 2094 | } |
| 2095 | |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 2096 | static bool |
| 2097 | loader_find_layer_name_list(const char *name, |
| 2098 | const struct loader_layer_list *layer_list) { |
| 2099 | if (!layer_list) |
| 2100 | return false; |
| 2101 | for (uint32_t j = 0; j < layer_list->count; j++) |
| 2102 | if (!strcmp(name, layer_list->list[j].info.layerName)) |
| 2103 | return true; |
| 2104 | return false; |
| 2105 | } |
| 2106 | |
| 2107 | static bool loader_find_layer_name(const char *name, uint32_t layer_count, |
| 2108 | const char **layer_list) { |
| 2109 | if (!layer_list) |
| 2110 | return false; |
| 2111 | for (uint32_t j = 0; j < layer_count; j++) |
| 2112 | if (!strcmp(name, layer_list[j])) |
| 2113 | return true; |
| 2114 | return false; |
| 2115 | } |
| 2116 | |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 2117 | bool loader_find_layer_name_array( |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 2118 | const char *name, uint32_t layer_count, |
| 2119 | const char layer_list[][VK_MAX_EXTENSION_NAME_SIZE]) { |
| 2120 | if (!layer_list) |
| 2121 | return false; |
| 2122 | for (uint32_t j = 0; j < layer_count; j++) |
| 2123 | if (!strcmp(name, layer_list[j])) |
| 2124 | return true; |
| 2125 | return false; |
| 2126 | } |
| 2127 | |
| 2128 | /** |
| 2129 | * Searches through an array of layer names (ppp_layer_names) looking for a |
| 2130 | * layer key_name. |
| 2131 | * If not found then simply returns updating nothing. |
| 2132 | * Otherwise, it uses expand_count, expand_names adding them to layer names. |
Chris Forbes | 6936647 | 2016-04-07 09:04:49 +1200 | [diff] [blame] | 2133 | * Any duplicate (pre-existing) expand_names in layer names are removed. |
| 2134 | * Order is otherwise preserved, with the layer key_name being replaced by the |
| 2135 | * expand_names. |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 2136 | * @param inst |
| 2137 | * @param layer_count |
| 2138 | * @param ppp_layer_names |
| 2139 | */ |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2140 | VkResult loader_expand_layer_names( |
| 2141 | struct loader_instance *inst, const char *key_name, uint32_t expand_count, |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 2142 | const char expand_names[][VK_MAX_EXTENSION_NAME_SIZE], |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 2143 | uint32_t *layer_count, char const *const **ppp_layer_names) { |
Jon Ashburn | 7148344 | 2016-02-11 18:59:43 -0700 | [diff] [blame] | 2144 | |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 2145 | char const *const *pp_src_layers = *ppp_layer_names; |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 2146 | |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 2147 | if (!loader_find_layer_name(key_name, *layer_count, |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 2148 | (char const **)pp_src_layers)) { |
| 2149 | inst->activated_layers_are_std_val = false; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2150 | return VK_SUCCESS; // didn't find the key_name in the list. |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 2151 | } |
Jon Ashburn | 7148344 | 2016-02-11 18:59:43 -0700 | [diff] [blame] | 2152 | |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 2153 | loader_log(inst, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, |
| 2154 | "Found meta layer %s, replacing with actual layer group", |
| 2155 | key_name); |
Chris Forbes | bd9de05 | 2016-04-06 20:49:02 +1200 | [diff] [blame] | 2156 | |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 2157 | inst->activated_layers_are_std_val = true; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2158 | char const **pp_dst_layers = loader_instance_heap_alloc( |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 2159 | inst, (expand_count + *layer_count - 1) * sizeof(char const *), |
| 2160 | VK_SYSTEM_ALLOCATION_SCOPE_COMMAND); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2161 | if (NULL == pp_dst_layers) { |
| 2162 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2163 | "loader_expand_layer_names:: Failed to allocate space for " |
| 2164 | "std_validation layer names in pp_dst_layers."); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2165 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 2166 | } |
Chris Forbes | bd9de05 | 2016-04-06 20:49:02 +1200 | [diff] [blame] | 2167 | |
| 2168 | // copy layers from src to dst, stripping key_name and anything in |
| 2169 | // expand_names. |
| 2170 | uint32_t src_index, dst_index = 0; |
| 2171 | for (src_index = 0; src_index < *layer_count; src_index++) { |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 2172 | if (loader_find_layer_name_array(pp_src_layers[src_index], expand_count, |
| 2173 | expand_names)) { |
Chris Forbes | 6936647 | 2016-04-07 09:04:49 +1200 | [diff] [blame] | 2174 | continue; |
| 2175 | } |
| 2176 | |
| 2177 | if (!strcmp(pp_src_layers[src_index], key_name)) { |
| 2178 | // insert all expand_names in place of key_name |
| 2179 | uint32_t expand_index; |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 2180 | for (expand_index = 0; expand_index < expand_count; |
| 2181 | expand_index++) { |
Chris Forbes | 6936647 | 2016-04-07 09:04:49 +1200 | [diff] [blame] | 2182 | pp_dst_layers[dst_index++] = expand_names[expand_index]; |
| 2183 | } |
Chris Forbes | bd9de05 | 2016-04-06 20:49:02 +1200 | [diff] [blame] | 2184 | continue; |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 2185 | } |
Chris Forbes | bd9de05 | 2016-04-06 20:49:02 +1200 | [diff] [blame] | 2186 | |
| 2187 | pp_dst_layers[dst_index++] = pp_src_layers[src_index]; |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 2188 | } |
| 2189 | |
Chris Forbes | bd9de05 | 2016-04-06 20:49:02 +1200 | [diff] [blame] | 2190 | *ppp_layer_names = pp_dst_layers; |
| 2191 | *layer_count = dst_index; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2192 | |
| 2193 | return VK_SUCCESS; |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 2194 | } |
| 2195 | |
Chris Forbes | bd9de05 | 2016-04-06 20:49:02 +1200 | [diff] [blame] | 2196 | void loader_delete_shadow_inst_layer_names(const struct loader_instance *inst, |
| 2197 | const VkInstanceCreateInfo *orig, |
| 2198 | VkInstanceCreateInfo *ours) { |
| 2199 | /* Free the layer names array iff we had to reallocate it */ |
| 2200 | if (orig->ppEnabledLayerNames != ours->ppEnabledLayerNames) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2201 | loader_instance_heap_free(inst, (void *)ours->ppEnabledLayerNames); |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 2202 | } |
| 2203 | } |
| 2204 | |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 2205 | void loader_init_std_validation_props(struct loader_layer_properties *props) { |
| 2206 | memset(props, 0, sizeof(struct loader_layer_properties)); |
| 2207 | props->type = VK_LAYER_TYPE_META_EXPLICT; |
| 2208 | strncpy(props->info.description, "LunarG Standard Validation Layer", |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 2209 | sizeof(props->info.description)); |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 2210 | props->info.implementationVersion = 1; |
| 2211 | strncpy(props->info.layerName, std_validation_str, |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 2212 | sizeof(props->info.layerName)); |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 2213 | // TODO what about specVersion? for now insert loader's built version |
| 2214 | props->info.specVersion = VK_MAKE_VERSION(1, 0, VK_HEADER_VERSION); |
| 2215 | } |
| 2216 | |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 2217 | /** |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 2218 | * Searches through the existing instance layer lists looking for |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 2219 | * the set of required layer names. If found then it adds a meta property to the |
| 2220 | * layer list. |
| 2221 | * Assumes the required layers are the same for both instance and device lists. |
| 2222 | * @param inst |
| 2223 | * @param layer_count number of layers in layer_names |
| 2224 | * @param layer_names array of required layer names |
| 2225 | * @param layer_instance_list |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 2226 | */ |
| 2227 | static void loader_add_layer_property_meta( |
| 2228 | const struct loader_instance *inst, uint32_t layer_count, |
| 2229 | const char layer_names[][VK_MAX_EXTENSION_NAME_SIZE], |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 2230 | struct loader_layer_list *layer_instance_list) { |
| 2231 | uint32_t i; |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 2232 | bool found; |
| 2233 | struct loader_layer_list *layer_list; |
| 2234 | |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 2235 | if (0 == layer_count || (!layer_instance_list)) |
Jon Ashburn | 888c050 | 2016-02-19 15:22:10 -0700 | [diff] [blame] | 2236 | return; |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 2237 | if (layer_instance_list && (layer_count > layer_instance_list->count)) |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 2238 | return; |
| 2239 | |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 2240 | layer_list = layer_instance_list; |
| 2241 | |
| 2242 | found = true; |
| 2243 | if (layer_list == NULL) |
| 2244 | return; |
| 2245 | for (i = 0; i < layer_count; i++) { |
| 2246 | if (loader_find_layer_name_list(layer_names[i], layer_list)) |
Jon Ashburn | 888c050 | 2016-02-19 15:22:10 -0700 | [diff] [blame] | 2247 | continue; |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 2248 | found = false; |
| 2249 | break; |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 2250 | } |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 2251 | |
| 2252 | struct loader_layer_properties *props; |
| 2253 | if (found) { |
| 2254 | props = loader_get_next_layer_property(inst, layer_list); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2255 | if (NULL == props) { |
| 2256 | // Error already triggered in loader_get_next_layer_property. |
| 2257 | return; |
| 2258 | } |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 2259 | loader_init_std_validation_props(props); |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 2260 | } |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 2261 | } |
| 2262 | |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2263 | static void loader_read_json_layer( |
| 2264 | const struct loader_instance *inst, |
| 2265 | struct loader_layer_list *layer_instance_list, cJSON *layer_node, |
| 2266 | cJSON *item, cJSON *disable_environment, bool is_implicit, char *filename) { |
| 2267 | char *temp; |
| 2268 | char *name, *type, *library_path, *api_version; |
| 2269 | char *implementation_version, *description; |
| 2270 | cJSON *ext_item; |
| 2271 | VkExtensionProperties ext_prop; |
| 2272 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2273 | /* |
| 2274 | * The following are required in the "layer" object: |
| 2275 | * (required) "name" |
| 2276 | * (required) "type" |
| 2277 | * (required) “library_path” |
| 2278 | * (required) “api_version” |
| 2279 | * (required) “implementation_version” |
| 2280 | * (required) “description” |
| 2281 | * (required for implicit layers) “disable_environment” |
| 2282 | */ |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 2283 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2284 | #define GET_JSON_OBJECT(node, var) \ |
| 2285 | { \ |
| 2286 | var = cJSON_GetObjectItem(node, #var); \ |
| 2287 | if (var == NULL) { \ |
| 2288 | layer_node = layer_node->next; \ |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 2289 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, \ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2290 | "Didn't find required layer object %s in manifest " \ |
| 2291 | "JSON file, skipping this layer", \ |
| 2292 | #var); \ |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2293 | return; \ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2294 | } \ |
| 2295 | } |
| 2296 | #define GET_JSON_ITEM(node, var) \ |
| 2297 | { \ |
| 2298 | item = cJSON_GetObjectItem(node, #var); \ |
| 2299 | if (item == NULL) { \ |
| 2300 | layer_node = layer_node->next; \ |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 2301 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, \ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2302 | "Didn't find required layer value %s in manifest JSON " \ |
| 2303 | "file, skipping this layer", \ |
| 2304 | #var); \ |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2305 | return; \ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2306 | } \ |
| 2307 | temp = cJSON_Print(item); \ |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2308 | if (temp == NULL) { \ |
| 2309 | layer_node = layer_node->next; \ |
| 2310 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, \ |
| 2311 | "Problem accessing layer value %s in manifest JSON " \ |
| 2312 | "file, skipping this layer", \ |
| 2313 | #var); \ |
| 2314 | return; \ |
| 2315 | } \ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2316 | temp[strlen(temp) - 1] = '\0'; \ |
| 2317 | var = loader_stack_alloc(strlen(temp) + 1); \ |
| 2318 | strcpy(var, &temp[1]); \ |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2319 | cJSON_Free(temp); \ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2320 | } |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2321 | GET_JSON_ITEM(layer_node, name) |
| 2322 | GET_JSON_ITEM(layer_node, type) |
| 2323 | GET_JSON_ITEM(layer_node, library_path) |
| 2324 | GET_JSON_ITEM(layer_node, api_version) |
| 2325 | GET_JSON_ITEM(layer_node, implementation_version) |
| 2326 | GET_JSON_ITEM(layer_node, description) |
| 2327 | if (is_implicit) { |
| 2328 | GET_JSON_OBJECT(layer_node, disable_environment) |
| 2329 | } |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 2330 | #undef GET_JSON_ITEM |
| 2331 | #undef GET_JSON_OBJECT |
| 2332 | |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2333 | // add list entry |
| 2334 | struct loader_layer_properties *props = NULL; |
| 2335 | if (!strcmp(type, "DEVICE")) { |
| 2336 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 2337 | "Device layers are deprecated skipping this layer"); |
| 2338 | layer_node = layer_node->next; |
| 2339 | return; |
| 2340 | } |
| 2341 | // Allow either GLOBAL or INSTANCE type interchangeably to handle |
| 2342 | // layers that must work with older loaders |
| 2343 | if (!strcmp(type, "INSTANCE") || !strcmp(type, "GLOBAL")) { |
| 2344 | if (layer_instance_list == NULL) { |
Jon Ashburn | 432d276 | 2015-09-18 12:53:16 -0600 | [diff] [blame] | 2345 | layer_node = layer_node->next; |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2346 | return; |
Jon Ashburn | 432d276 | 2015-09-18 12:53:16 -0600 | [diff] [blame] | 2347 | } |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2348 | props = loader_get_next_layer_property(inst, layer_instance_list); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2349 | if (NULL == props) { |
| 2350 | // Error already triggered in loader_get_next_layer_property. |
| 2351 | return; |
| 2352 | } |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2353 | props->type = (is_implicit) ? VK_LAYER_TYPE_INSTANCE_IMPLICIT |
| 2354 | : VK_LAYER_TYPE_INSTANCE_EXPLICIT; |
| 2355 | } |
Jon Ashburn | 432d276 | 2015-09-18 12:53:16 -0600 | [diff] [blame] | 2356 | |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2357 | if (props == NULL) { |
| 2358 | layer_node = layer_node->next; |
| 2359 | return; |
| 2360 | } |
Jon Ashburn | 1531517 | 2015-07-07 15:06:25 -0600 | [diff] [blame] | 2361 | |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2362 | strncpy(props->info.layerName, name, sizeof(props->info.layerName)); |
| 2363 | props->info.layerName[sizeof(props->info.layerName) - 1] = '\0'; |
| 2364 | |
| 2365 | char *fullpath = props->lib_name; |
| 2366 | char *rel_base; |
| 2367 | if (loader_platform_is_path(library_path)) { |
| 2368 | // a relative or absolute path |
| 2369 | char *name_copy = loader_stack_alloc(strlen(filename) + 1); |
| 2370 | strcpy(name_copy, filename); |
| 2371 | rel_base = loader_platform_dirname(name_copy); |
| 2372 | loader_expand_path(library_path, rel_base, MAX_STRING_SIZE, fullpath); |
| 2373 | } else { |
| 2374 | // a filename which is assumed in a system directory |
| 2375 | loader_get_fullpath(library_path, DEFAULT_VK_LAYERS_PATH, |
| 2376 | MAX_STRING_SIZE, fullpath); |
| 2377 | } |
| 2378 | props->info.specVersion = loader_make_version(api_version); |
| 2379 | props->info.implementationVersion = atoi(implementation_version); |
| 2380 | strncpy((char *)props->info.description, description, |
| 2381 | sizeof(props->info.description)); |
| 2382 | props->info.description[sizeof(props->info.description) - 1] = '\0'; |
| 2383 | if (is_implicit) { |
| 2384 | if (!disable_environment || !disable_environment->child) { |
| 2385 | loader_log( |
| 2386 | inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 2387 | "Didn't find required layer child value disable_environment" |
| 2388 | "in manifest JSON file, skipping this layer"); |
| 2389 | layer_node = layer_node->next; |
| 2390 | return; |
Jon Ashburn | fb8ac01 | 2015-08-12 16:39:32 -0600 | [diff] [blame] | 2391 | } |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2392 | strncpy(props->disable_env_var.name, disable_environment->child->string, |
| 2393 | sizeof(props->disable_env_var.name)); |
| 2394 | props->disable_env_var.name[sizeof(props->disable_env_var.name) - 1] = |
| 2395 | '\0'; |
| 2396 | strncpy(props->disable_env_var.value, |
| 2397 | disable_environment->child->valuestring, |
| 2398 | sizeof(props->disable_env_var.value)); |
| 2399 | props->disable_env_var.value[sizeof(props->disable_env_var.value) - 1] = |
| 2400 | '\0'; |
| 2401 | } |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 2402 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2403 | /** |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2404 | * Now get all optional items and objects and put in list: |
| 2405 | * functions |
| 2406 | * instance_extensions |
| 2407 | * device_extensions |
| 2408 | * enable_environment (implicit layers only) |
| 2409 | */ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2410 | #define GET_JSON_OBJECT(node, var) \ |
| 2411 | { var = cJSON_GetObjectItem(node, #var); } |
| 2412 | #define GET_JSON_ITEM(node, var) \ |
| 2413 | { \ |
| 2414 | item = cJSON_GetObjectItem(node, #var); \ |
| 2415 | if (item != NULL) { \ |
| 2416 | temp = cJSON_Print(item); \ |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2417 | if (temp != NULL) { \ |
| 2418 | temp[strlen(temp) - 1] = '\0'; \ |
| 2419 | var = loader_stack_alloc(strlen(temp) + 1); \ |
| 2420 | strcpy(var, &temp[1]); \ |
| 2421 | cJSON_Free(temp); \ |
| 2422 | } \ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2423 | } \ |
| 2424 | } |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 2425 | |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2426 | cJSON *instance_extensions, *device_extensions, *functions, |
| 2427 | *enable_environment; |
| 2428 | cJSON *entrypoints; |
| 2429 | char *vkGetInstanceProcAddr, *vkGetDeviceProcAddr, *spec_version; |
| 2430 | char **entry_array; |
| 2431 | vkGetInstanceProcAddr = NULL; |
| 2432 | vkGetDeviceProcAddr = NULL; |
| 2433 | spec_version = NULL; |
| 2434 | entrypoints = NULL; |
| 2435 | entry_array = NULL; |
| 2436 | int i, j; |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 2437 | |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2438 | /** |
| 2439 | * functions |
| 2440 | * vkGetInstanceProcAddr |
| 2441 | * vkGetDeviceProcAddr |
| 2442 | */ |
| 2443 | GET_JSON_OBJECT(layer_node, functions) |
| 2444 | if (functions != NULL) { |
| 2445 | GET_JSON_ITEM(functions, vkGetInstanceProcAddr) |
| 2446 | GET_JSON_ITEM(functions, vkGetDeviceProcAddr) |
| 2447 | if (vkGetInstanceProcAddr != NULL) |
| 2448 | strncpy(props->functions.str_gipa, vkGetInstanceProcAddr, |
| 2449 | sizeof(props->functions.str_gipa)); |
| 2450 | props->functions.str_gipa[sizeof(props->functions.str_gipa) - 1] = '\0'; |
| 2451 | if (vkGetDeviceProcAddr != NULL) |
| 2452 | strncpy(props->functions.str_gdpa, vkGetDeviceProcAddr, |
| 2453 | sizeof(props->functions.str_gdpa)); |
| 2454 | props->functions.str_gdpa[sizeof(props->functions.str_gdpa) - 1] = '\0'; |
| 2455 | } |
| 2456 | /** |
| 2457 | * instance_extensions |
| 2458 | * array of |
| 2459 | * name |
| 2460 | * spec_version |
| 2461 | */ |
| 2462 | GET_JSON_OBJECT(layer_node, instance_extensions) |
| 2463 | if (instance_extensions != NULL) { |
| 2464 | int count = cJSON_GetArraySize(instance_extensions); |
| 2465 | for (i = 0; i < count; i++) { |
| 2466 | ext_item = cJSON_GetArrayItem(instance_extensions, i); |
| 2467 | GET_JSON_ITEM(ext_item, name) |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2468 | if (name != NULL) { |
| 2469 | strncpy(ext_prop.extensionName, name, |
| 2470 | sizeof(ext_prop.extensionName)); |
| 2471 | ext_prop.extensionName[sizeof(ext_prop.extensionName) - 1] = |
| 2472 | '\0'; |
| 2473 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2474 | GET_JSON_ITEM(ext_item, spec_version) |
| 2475 | if (NULL != spec_version) { |
| 2476 | ext_prop.specVersion = atoi(spec_version); |
| 2477 | } else { |
| 2478 | ext_prop.specVersion = 0; |
| 2479 | } |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2480 | bool ext_unsupported = |
| 2481 | wsi_unsupported_instance_extension(&ext_prop); |
| 2482 | if (!ext_unsupported) { |
| 2483 | loader_add_to_ext_list(inst, &props->instance_extension_list, 1, |
| 2484 | &ext_prop); |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 2485 | } |
Jon Ashburn | fb8ac01 | 2015-08-12 16:39:32 -0600 | [diff] [blame] | 2486 | } |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2487 | } |
| 2488 | /** |
| 2489 | * device_extensions |
| 2490 | * array of |
| 2491 | * name |
| 2492 | * spec_version |
| 2493 | * entrypoints |
| 2494 | */ |
| 2495 | GET_JSON_OBJECT(layer_node, device_extensions) |
| 2496 | if (device_extensions != NULL) { |
| 2497 | int count = cJSON_GetArraySize(device_extensions); |
| 2498 | for (i = 0; i < count; i++) { |
| 2499 | ext_item = cJSON_GetArrayItem(device_extensions, i); |
| 2500 | GET_JSON_ITEM(ext_item, name) |
| 2501 | GET_JSON_ITEM(ext_item, spec_version) |
| 2502 | if (name != NULL) { |
| 2503 | strncpy(ext_prop.extensionName, name, |
| 2504 | sizeof(ext_prop.extensionName)); |
| 2505 | ext_prop.extensionName[sizeof(ext_prop.extensionName) - 1] = |
| 2506 | '\0'; |
| 2507 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2508 | if (NULL != spec_version) { |
| 2509 | ext_prop.specVersion = atoi(spec_version); |
| 2510 | } else { |
| 2511 | ext_prop.specVersion = 0; |
| 2512 | } |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2513 | // entrypoints = cJSON_GetObjectItem(ext_item, "entrypoints"); |
| 2514 | GET_JSON_OBJECT(ext_item, entrypoints) |
| 2515 | int entry_count; |
| 2516 | if (entrypoints == NULL) { |
| 2517 | loader_add_to_dev_ext_list(inst, &props->device_extension_list, |
| 2518 | &ext_prop, 0, NULL); |
| 2519 | continue; |
| 2520 | } |
| 2521 | entry_count = cJSON_GetArraySize(entrypoints); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2522 | if (entry_count) { |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2523 | entry_array = |
| 2524 | (char **)loader_stack_alloc(sizeof(char *) * entry_count); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2525 | } |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2526 | for (j = 0; j < entry_count; j++) { |
| 2527 | ext_item = cJSON_GetArrayItem(entrypoints, j); |
| 2528 | if (ext_item != NULL) { |
| 2529 | temp = cJSON_Print(ext_item); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2530 | if (NULL == temp) { |
| 2531 | entry_array[j] = NULL; |
| 2532 | continue; |
| 2533 | } |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2534 | temp[strlen(temp) - 1] = '\0'; |
| 2535 | entry_array[j] = loader_stack_alloc(strlen(temp) + 1); |
| 2536 | strcpy(entry_array[j], &temp[1]); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2537 | cJSON_Free(temp); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2538 | } |
| 2539 | } |
| 2540 | loader_add_to_dev_ext_list(inst, &props->device_extension_list, |
| 2541 | &ext_prop, entry_count, entry_array); |
| 2542 | } |
| 2543 | } |
| 2544 | if (is_implicit) { |
| 2545 | GET_JSON_OBJECT(layer_node, enable_environment) |
| 2546 | |
| 2547 | // enable_environment is optional |
| 2548 | if (enable_environment) { |
| 2549 | strncpy(props->enable_env_var.name, |
| 2550 | enable_environment->child->string, |
| 2551 | sizeof(props->enable_env_var.name)); |
| 2552 | props->enable_env_var.name[sizeof(props->enable_env_var.name) - 1] = |
| 2553 | '\0'; |
| 2554 | strncpy(props->enable_env_var.value, |
| 2555 | enable_environment->child->valuestring, |
| 2556 | sizeof(props->enable_env_var.value)); |
| 2557 | props->enable_env_var |
| 2558 | .value[sizeof(props->enable_env_var.value) - 1] = '\0'; |
| 2559 | } |
| 2560 | } |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 2561 | #undef GET_JSON_ITEM |
| 2562 | #undef GET_JSON_OBJECT |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2563 | } |
| 2564 | |
| 2565 | /** |
| 2566 | * Given a cJSON struct (json) of the top level JSON object from layer manifest |
| 2567 | * file, add entry to the layer_list. Fill out the layer_properties in this list |
| 2568 | * entry from the input cJSON object. |
| 2569 | * |
| 2570 | * \returns |
| 2571 | * void |
| 2572 | * layer_list has a new entry and initialized accordingly. |
| 2573 | * If the json input object does not have all the required fields no entry |
| 2574 | * is added to the list. |
| 2575 | */ |
| 2576 | static void |
| 2577 | loader_add_layer_properties(const struct loader_instance *inst, |
| 2578 | struct loader_layer_list *layer_instance_list, |
| 2579 | cJSON *json, bool is_implicit, char *filename) { |
| 2580 | /* Fields in layer manifest file that are required: |
| 2581 | * (required) “file_format_version” |
| 2582 | * |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2583 | * If more than one "layer" object are to be used, use the "layers" array |
| 2584 | * instead. |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2585 | * |
| 2586 | * First get all required items and if any missing abort |
| 2587 | */ |
| 2588 | |
| 2589 | cJSON *item, *layers_node, *layer_node; |
| 2590 | uint16_t file_major_vers = 0; |
| 2591 | uint16_t file_minor_vers = 0; |
| 2592 | uint16_t file_patch_vers = 0; |
| 2593 | char *vers_tok; |
| 2594 | cJSON *disable_environment = NULL; |
| 2595 | item = cJSON_GetObjectItem(json, "file_format_version"); |
| 2596 | if (item == NULL) { |
| 2597 | return; |
| 2598 | } |
| 2599 | char *file_vers = cJSON_PrintUnformatted(item); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2600 | if (NULL == file_vers) { |
| 2601 | return; |
| 2602 | } |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2603 | loader_log(inst, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, |
| 2604 | "Found manifest file %s, version %s", filename, file_vers); |
| 2605 | // Get the major/minor/and patch as integers for easier comparison |
| 2606 | vers_tok = strtok(file_vers, ".\"\n\r"); |
| 2607 | if (NULL != vers_tok) { |
Jamie Madill | 970ebcf | 2016-07-06 11:19:42 -0400 | [diff] [blame] | 2608 | file_major_vers = (uint16_t)atoi(vers_tok); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2609 | vers_tok = strtok(NULL, ".\"\n\r"); |
| 2610 | if (NULL != vers_tok) { |
Jamie Madill | 970ebcf | 2016-07-06 11:19:42 -0400 | [diff] [blame] | 2611 | file_minor_vers = (uint16_t)atoi(vers_tok); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2612 | vers_tok = strtok(NULL, ".\"\n\r"); |
| 2613 | if (NULL != vers_tok) { |
Jamie Madill | 970ebcf | 2016-07-06 11:19:42 -0400 | [diff] [blame] | 2614 | file_patch_vers = (uint16_t)atoi(vers_tok); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2615 | } |
| 2616 | } |
| 2617 | } |
| 2618 | if (file_major_vers != 1 || file_minor_vers != 0 || file_patch_vers > 1) { |
| 2619 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2620 | "loader_add_layer_properties: Unexpected manifest file " |
| 2621 | " version (expected 1.0.0 or 1.0.1) in %s, may cause " |
| 2622 | "errors", |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2623 | filename); |
| 2624 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2625 | cJSON_Free(file_vers); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2626 | // If "layers" is present, read in the array of layer objects |
| 2627 | layers_node = cJSON_GetObjectItem(json, "layers"); |
| 2628 | if (layers_node != NULL) { |
| 2629 | int numItems = cJSON_GetArraySize(layers_node); |
| 2630 | if (file_major_vers == 1 && file_minor_vers == 0 && |
| 2631 | file_patch_vers == 0) { |
| 2632 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2633 | "loader_add_layer_properties: \"layers\" tag not " |
| 2634 | "supported until file version 1.0.1, but %s is " |
| 2635 | "reporting version %s", |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2636 | filename, file_vers); |
| 2637 | } |
| 2638 | for (int curLayer = 0; curLayer < numItems; curLayer++) { |
| 2639 | layer_node = cJSON_GetArrayItem(layers_node, curLayer); |
| 2640 | if (layer_node == NULL) { |
| 2641 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2642 | "loader_add_layer_properties: Can not find " |
| 2643 | "\"layers\" array element %d object in manifest " |
| 2644 | "JSON file %s. Skipping this file", |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2645 | curLayer, filename); |
| 2646 | return; |
| 2647 | } |
| 2648 | loader_read_json_layer(inst, layer_instance_list, layer_node, item, |
| 2649 | disable_environment, is_implicit, filename); |
| 2650 | } |
| 2651 | } else { |
| 2652 | // Otherwise, try to read in individual layers |
| 2653 | layer_node = cJSON_GetObjectItem(json, "layer"); |
| 2654 | if (layer_node == NULL) { |
| 2655 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2656 | "loader_add_layer_properties: Can not find \"layer\" " |
| 2657 | "object in manifest JSON file %s. Skipping this file.", |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2658 | filename); |
| 2659 | return; |
| 2660 | } |
| 2661 | // Loop through all "layer" objects in the file to get a count of them |
| 2662 | // first. |
| 2663 | uint16_t layer_count = 0; |
| 2664 | cJSON *tempNode = layer_node; |
| 2665 | do { |
| 2666 | tempNode = tempNode->next; |
| 2667 | layer_count++; |
| 2668 | } while (tempNode != NULL); |
| 2669 | /* |
| 2670 | * Throw a warning if we encounter multiple "layer" objects in file |
| 2671 | * versions newer than 1.0.0. Having multiple objects with the same |
| 2672 | * name at the same level is actually a JSON standard violation. |
| 2673 | */ |
| 2674 | if (layer_count > 1 && |
| 2675 | (file_major_vers > 1 || |
| 2676 | !(file_minor_vers == 0 && file_patch_vers == 0))) { |
| 2677 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2678 | "loader_add_layer_properties: Multiple \"layer\" nodes" |
| 2679 | " are deprecated starting in file version \"1.0.1\". " |
| 2680 | "Please use \"layers\" : [] array instead in %s.", |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2681 | filename); |
| 2682 | } else { |
| 2683 | do { |
| 2684 | loader_read_json_layer(inst, layer_instance_list, layer_node, |
| 2685 | item, disable_environment, is_implicit, |
| 2686 | filename); |
| 2687 | layer_node = layer_node->next; |
| 2688 | } while (layer_node != NULL); |
| 2689 | } |
| 2690 | } |
Jon Ashburn | fb8ac01 | 2015-08-12 16:39:32 -0600 | [diff] [blame] | 2691 | return; |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 2692 | } |
| 2693 | |
| 2694 | /** |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2695 | * Find the Vulkan library manifest files. |
| 2696 | * |
Jon Ashburn | b682221 | 2016-02-16 15:34:16 -0700 | [diff] [blame] | 2697 | * This function scans the "location" or "env_override" directories/files |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2698 | * for a list of JSON manifest files. If env_override is non-NULL |
| 2699 | * and has a valid value. Then the location is ignored. Otherwise |
| 2700 | * location is used to look for manifest files. The location |
| 2701 | * is interpreted as Registry path on Windows and a directory path(s) |
Jon Ashburn | b682221 | 2016-02-16 15:34:16 -0700 | [diff] [blame] | 2702 | * on Linux. "home_location" is an additional directory in the users home |
John Drinkwater | 9ac3f4f | 2016-08-01 17:00:00 +0100 | [diff] [blame] | 2703 | * directory to look at. It is expanded into the dir path |
| 2704 | * $XDG_DATA_HOME/home_location or $HOME/.local/share/home_location depending |
| 2705 | * on environment variables. This "home_location" is only used on Linux. |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2706 | * |
| 2707 | * \returns |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2708 | * VKResult |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2709 | * A string list of manifest files to be opened in out_files param. |
| 2710 | * List has a pointer to string for each manifest filename. |
| 2711 | * When done using the list in out_files, pointers should be freed. |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2712 | * Location or override string lists can be either files or directories as |
| 2713 | *follows: |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2714 | * | location | override |
| 2715 | * -------------------------------- |
| 2716 | * Win ICD | files | files |
| 2717 | * Win Layer | files | dirs |
| 2718 | * Linux ICD | dirs | files |
| 2719 | * Linux Layer| dirs | dirs |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2720 | */ |
Mark Young | f8c2010 | 2016-11-07 16:26:17 -0700 | [diff] [blame] | 2721 | static VkResult |
| 2722 | loader_get_manifest_files(const struct loader_instance *inst, |
Frank Henigman | b1c27cb | 2016-11-24 20:02:09 -0500 | [diff] [blame] | 2723 | const char *env_override, const char *source_override, |
Mark Young | f8c2010 | 2016-11-07 16:26:17 -0700 | [diff] [blame] | 2724 | bool is_layer, bool warn_if_not_present, |
| 2725 | const char *location, const char *home_location, |
| 2726 | struct loader_manifest_files *out_files) { |
Frank Henigman | b1c27cb | 2016-11-24 20:02:09 -0500 | [diff] [blame] | 2727 | const char *override = NULL; |
| 2728 | char *override_getenv = NULL; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2729 | char *loc, *orig_loc = NULL; |
| 2730 | char *reg = NULL; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2731 | char *file, *next_file, *name; |
| 2732 | size_t alloced_count = 64; |
| 2733 | char full_path[2048]; |
| 2734 | DIR *sysdir = NULL; |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2735 | bool list_is_dirs = false; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2736 | struct dirent *dent; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2737 | VkResult res = VK_SUCCESS; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2738 | |
| 2739 | out_files->count = 0; |
| 2740 | out_files->filename_list = NULL; |
| 2741 | |
Jamie Madill | 00c3c91 | 2016-04-06 18:26:46 -0400 | [diff] [blame] | 2742 | if (source_override != NULL) { |
| 2743 | override = source_override; |
Frank Henigman | b1c27cb | 2016-11-24 20:02:09 -0500 | [diff] [blame] | 2744 | } else if (env_override != NULL) { |
Johannes van Waveren | 9bd80501 | 2015-10-28 11:45:00 -0500 | [diff] [blame] | 2745 | #if !defined(_WIN32) |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 2746 | if (geteuid() != getuid() || getegid() != getgid()) { |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2747 | /* Don't allow setuid apps to use the env var: */ |
Frank Henigman | b1c27cb | 2016-11-24 20:02:09 -0500 | [diff] [blame] | 2748 | env_override = NULL; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2749 | } |
| 2750 | #endif |
Frank Henigman | b1c27cb | 2016-11-24 20:02:09 -0500 | [diff] [blame] | 2751 | if (env_override != NULL) { |
| 2752 | override = override_getenv = loader_getenv(env_override, inst); |
| 2753 | } |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2754 | } |
| 2755 | |
Jon Ashburn | b682221 | 2016-02-16 15:34:16 -0700 | [diff] [blame] | 2756 | #if !defined(_WIN32) |
| 2757 | if (location == NULL && home_location == NULL) { |
| 2758 | #else |
| 2759 | home_location = NULL; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2760 | if (location == NULL) { |
Jon Ashburn | b682221 | 2016-02-16 15:34:16 -0700 | [diff] [blame] | 2761 | #endif |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2762 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 2763 | "loader_get_manifest_files: Can not get manifest files with " |
| 2764 | "NULL location, env_override=%s", |
| 2765 | (env_override != NULL) ? env_override : ""); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2766 | res = VK_ERROR_INITIALIZATION_FAILED; |
| 2767 | goto out; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2768 | } |
| 2769 | |
Johannes van Waveren | 9bd80501 | 2015-10-28 11:45:00 -0500 | [diff] [blame] | 2770 | #if defined(_WIN32) |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2771 | list_is_dirs = (is_layer && override != NULL) ? true : false; |
Johannes van Waveren | 9bd80501 | 2015-10-28 11:45:00 -0500 | [diff] [blame] | 2772 | #else |
| 2773 | list_is_dirs = (override == NULL || is_layer) ? true : false; |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2774 | #endif |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2775 | // 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] | 2776 | // Also handle getting the location(s) from registry on Windows |
| 2777 | if (override == NULL) { |
Jon Ashburn | 3b78e46 | 2015-07-31 10:11:24 -0600 | [diff] [blame] | 2778 | loc = loader_stack_alloc(strlen(location) + 1); |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2779 | if (loc == NULL) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2780 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2781 | "loader_get_manifest_files: Failed to allocate " |
| 2782 | " %d bytes for manifest file location.", |
| 2783 | strlen(location)); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2784 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 2785 | goto out; |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2786 | } |
| 2787 | strcpy(loc, location); |
Johannes van Waveren | 9bd80501 | 2015-10-28 11:45:00 -0500 | [diff] [blame] | 2788 | #if defined(_WIN32) |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2789 | reg = loader_get_registry_files(inst, loc); |
| 2790 | if (reg == NULL) { |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 2791 | if (!is_layer) { |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2792 | loader_log( |
| 2793 | inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 2794 | "loader_get_manifest_files: Registry lookup failed " |
| 2795 | " to get ICD manifest files. Possibly missing Vulkan" |
| 2796 | " driver?"); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2797 | // This typically only fails when out of memory, which is |
| 2798 | // critical |
| 2799 | // if this is for the loader. |
| 2800 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 2801 | } else { |
Mark Young | f8c2010 | 2016-11-07 16:26:17 -0700 | [diff] [blame] | 2802 | if (warn_if_not_present) { |
| 2803 | // warning only for layers |
| 2804 | loader_log( |
| 2805 | inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2806 | "loader_get_manifest_files: Registry lookup failed " |
| 2807 | " to get layer manifest files."); |
Mark Young | f8c2010 | 2016-11-07 16:26:17 -0700 | [diff] [blame] | 2808 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2809 | // Return success for now since it's not critical for layers |
| 2810 | res = VK_SUCCESS; |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 2811 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2812 | goto out; |
Jon Ashburn | 24265ac | 2015-07-31 09:33:21 -0600 | [diff] [blame] | 2813 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2814 | orig_loc = loc; |
| 2815 | loc = reg; |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2816 | #endif |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2817 | } else { |
Courtney Goeltzenleuchter | 7f5aafc | 2015-07-05 11:28:29 -0600 | [diff] [blame] | 2818 | loc = loader_stack_alloc(strlen(override) + 1); |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2819 | if (loc == NULL) { |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2820 | loader_log( |
| 2821 | inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 2822 | "loader_get_manifest_files: Failed to allocate space for " |
| 2823 | " override environment variable of length %d", |
| 2824 | strlen(override) + 1); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2825 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 2826 | goto out; |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2827 | } |
| 2828 | strcpy(loc, override); |
| 2829 | } |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2830 | |
Liam Middlebrook | 9b14e89 | 2015-07-23 18:32:20 -0700 | [diff] [blame] | 2831 | // Print out the paths being searched if debugging is enabled |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2832 | loader_log(inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, |
| 2833 | "Searching the following paths for manifest files: %s\n", loc); |
Liam Middlebrook | 9b14e89 | 2015-07-23 18:32:20 -0700 | [diff] [blame] | 2834 | |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2835 | file = loc; |
| 2836 | while (*file) { |
| 2837 | next_file = loader_get_next_path(file); |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2838 | if (list_is_dirs) { |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2839 | sysdir = opendir(file); |
| 2840 | name = NULL; |
| 2841 | if (sysdir) { |
| 2842 | dent = readdir(sysdir); |
| 2843 | if (dent == NULL) |
| 2844 | break; |
| 2845 | name = &(dent->d_name[0]); |
| 2846 | loader_get_fullpath(name, file, sizeof(full_path), full_path); |
| 2847 | name = full_path; |
| 2848 | } |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2849 | } else { |
Johannes van Waveren | 9bd80501 | 2015-10-28 11:45:00 -0500 | [diff] [blame] | 2850 | #if defined(_WIN32) |
| 2851 | name = file; |
| 2852 | #else |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2853 | // only Linux has relative paths |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2854 | char *dir; |
| 2855 | // make a copy of location so it isn't modified |
Jason Ekstrand | cc7550e | 2015-10-10 08:33:37 -0700 | [diff] [blame] | 2856 | dir = loader_stack_alloc(strlen(loc) + 1); |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2857 | if (dir == NULL) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2858 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2859 | "loader_get_manifest_files: Failed to allocate " |
| 2860 | " space for relative location path length %d", |
| 2861 | strlen(loc) + 1); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2862 | goto out; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2863 | } |
Jason Ekstrand | cc7550e | 2015-10-10 08:33:37 -0700 | [diff] [blame] | 2864 | strcpy(dir, loc); |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2865 | |
| 2866 | loader_get_fullpath(file, dir, sizeof(full_path), full_path); |
| 2867 | |
| 2868 | name = full_path; |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2869 | #endif |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2870 | } |
| 2871 | while (name) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2872 | /* Look for files ending with ".json" suffix */ |
| 2873 | uint32_t nlen = (uint32_t)strlen(name); |
| 2874 | const char *suf = name + nlen - 5; |
| 2875 | if ((nlen > 5) && !strncmp(suf, ".json", 5)) { |
| 2876 | if (out_files->count == 0) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2877 | out_files->filename_list = loader_instance_heap_alloc( |
| 2878 | inst, alloced_count * sizeof(char *), |
| 2879 | VK_SYSTEM_ALLOCATION_SCOPE_COMMAND); |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2880 | } else if (out_files->count == alloced_count) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2881 | out_files->filename_list = loader_instance_heap_realloc( |
| 2882 | inst, out_files->filename_list, |
| 2883 | alloced_count * sizeof(char *), |
| 2884 | alloced_count * sizeof(char *) * 2, |
| 2885 | VK_SYSTEM_ALLOCATION_SCOPE_COMMAND); |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2886 | alloced_count *= 2; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2887 | } |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2888 | if (out_files->filename_list == NULL) { |
| 2889 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2890 | "loader_get_manifest_files: Failed to allocate " |
| 2891 | " space for manifest file name list"); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2892 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 2893 | goto out; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2894 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2895 | out_files->filename_list[out_files->count] = |
| 2896 | loader_instance_heap_alloc( |
| 2897 | inst, strlen(name) + 1, |
| 2898 | VK_SYSTEM_ALLOCATION_SCOPE_COMMAND); |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2899 | if (out_files->filename_list[out_files->count] == NULL) { |
| 2900 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2901 | "loader_get_manifest_files: Failed to allocate " |
| 2902 | " space for manifest file %d list", |
| 2903 | out_files->count); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2904 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 2905 | goto out; |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2906 | } |
| 2907 | strcpy(out_files->filename_list[out_files->count], name); |
| 2908 | out_files->count++; |
| 2909 | } else if (!list_is_dirs) { |
| 2910 | loader_log( |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 2911 | inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2912 | "Skipping manifest file %s, file name must end in .json", |
| 2913 | name); |
| 2914 | } |
| 2915 | if (list_is_dirs) { |
| 2916 | dent = readdir(sysdir); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2917 | if (dent == NULL) { |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2918 | break; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2919 | } |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2920 | name = &(dent->d_name[0]); |
| 2921 | loader_get_fullpath(name, file, sizeof(full_path), full_path); |
| 2922 | name = full_path; |
| 2923 | } else { |
| 2924 | break; |
| 2925 | } |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2926 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2927 | if (sysdir) { |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2928 | closedir(sysdir); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2929 | sysdir = NULL; |
| 2930 | } |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2931 | file = next_file; |
Jon Ashburn | 67e262e | 2016-02-18 12:45:39 -0700 | [diff] [blame] | 2932 | #if !defined(_WIN32) |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 2933 | if (home_location != NULL && |
| 2934 | (next_file == NULL || *next_file == '\0') && override == NULL) { |
John Drinkwater | 9ac3f4f | 2016-08-01 17:00:00 +0100 | [diff] [blame] | 2935 | char *xdgdatahome = secure_getenv("XDG_DATA_HOME"); |
| 2936 | size_t len; |
| 2937 | if (xdgdatahome != NULL) { |
| 2938 | |
| 2939 | char *home_loc = loader_stack_alloc(strlen(xdgdatahome) + 2 + |
Jon Ashburn | 67e262e | 2016-02-18 12:45:39 -0700 | [diff] [blame] | 2940 | strlen(home_location)); |
| 2941 | if (home_loc == NULL) { |
| 2942 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2943 | "loader_get_manifest_files: Failed to allocate " |
| 2944 | " space for manifest file XDG Home location"); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2945 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 2946 | goto out; |
Jon Ashburn | 67e262e | 2016-02-18 12:45:39 -0700 | [diff] [blame] | 2947 | } |
John Drinkwater | 9ac3f4f | 2016-08-01 17:00:00 +0100 | [diff] [blame] | 2948 | strcpy(home_loc, xdgdatahome); |
Jon Ashburn | 67e262e | 2016-02-18 12:45:39 -0700 | [diff] [blame] | 2949 | // Add directory separator if needed |
| 2950 | if (home_location[0] != DIRECTORY_SYMBOL) { |
| 2951 | len = strlen(home_loc); |
| 2952 | home_loc[len] = DIRECTORY_SYMBOL; |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 2953 | home_loc[len + 1] = '\0'; |
Jon Ashburn | 67e262e | 2016-02-18 12:45:39 -0700 | [diff] [blame] | 2954 | } |
| 2955 | strcat(home_loc, home_location); |
| 2956 | file = home_loc; |
| 2957 | next_file = loader_get_next_path(file); |
| 2958 | home_location = NULL; |
| 2959 | |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 2960 | loader_log( |
| 2961 | inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, |
John Drinkwater | 9ac3f4f | 2016-08-01 17:00:00 +0100 | [diff] [blame] | 2962 | "Searching the following path for manifest files: %s\n", |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 2963 | home_loc); |
Jon Ashburn | 67e262e | 2016-02-18 12:45:39 -0700 | [diff] [blame] | 2964 | list_is_dirs = true; |
John Drinkwater | 9ac3f4f | 2016-08-01 17:00:00 +0100 | [diff] [blame] | 2965 | |
| 2966 | } else { |
| 2967 | |
| 2968 | char *home = secure_getenv("HOME"); |
| 2969 | if (home != NULL) { |
| 2970 | char *home_loc = loader_stack_alloc(strlen(home) + 16 + |
| 2971 | strlen(home_location)); |
| 2972 | if (home_loc == NULL) { |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2973 | loader_log( |
| 2974 | inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 2975 | "loader_get_manifest_files: Failed to allocate " |
| 2976 | " space for manifest file Home location"); |
John Drinkwater | 9ac3f4f | 2016-08-01 17:00:00 +0100 | [diff] [blame] | 2977 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 2978 | goto out; |
| 2979 | } |
| 2980 | strcpy(home_loc, home); |
| 2981 | |
| 2982 | len = strlen(home); |
| 2983 | if (home[len] != DIRECTORY_SYMBOL) { |
| 2984 | home_loc[len] = DIRECTORY_SYMBOL; |
| 2985 | home_loc[len + 1] = '\0'; |
| 2986 | } |
| 2987 | strcat(home_loc, ".local/share"); |
| 2988 | |
| 2989 | if (home_location[0] != DIRECTORY_SYMBOL) { |
| 2990 | len = strlen(home_loc); |
| 2991 | home_loc[len] = DIRECTORY_SYMBOL; |
| 2992 | home_loc[len + 1] = '\0'; |
| 2993 | } |
| 2994 | strcat(home_loc, home_location); |
| 2995 | file = home_loc; |
| 2996 | next_file = loader_get_next_path(file); |
| 2997 | home_location = NULL; |
| 2998 | |
| 2999 | loader_log( |
| 3000 | inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, |
| 3001 | "Searching the following path for manifest files: %s\n", |
| 3002 | home_loc); |
| 3003 | list_is_dirs = true; |
| 3004 | } else { |
| 3005 | // without knowing HOME, we just.. give up |
| 3006 | } |
Jon Ashburn | 67e262e | 2016-02-18 12:45:39 -0700 | [diff] [blame] | 3007 | } |
| 3008 | } |
| 3009 | #endif |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3010 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3011 | |
| 3012 | out: |
| 3013 | if (VK_SUCCESS != res && NULL != out_files->filename_list) { |
| 3014 | for (uint32_t remove = 0; remove < out_files->count; remove++) { |
| 3015 | loader_instance_heap_free(inst, out_files->filename_list[remove]); |
| 3016 | } |
| 3017 | loader_instance_heap_free(inst, out_files->filename_list); |
| 3018 | out_files->count = 0; |
| 3019 | out_files->filename_list = NULL; |
| 3020 | } |
| 3021 | |
| 3022 | if (NULL != sysdir) { |
| 3023 | closedir(sysdir); |
| 3024 | } |
| 3025 | |
Frank Henigman | b1c27cb | 2016-11-24 20:02:09 -0500 | [diff] [blame] | 3026 | if (override_getenv != NULL) { |
| 3027 | loader_free_getenv(override_getenv, inst); |
| 3028 | } |
| 3029 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3030 | if (NULL != reg && reg != orig_loc) { |
| 3031 | loader_instance_heap_free(inst, reg); |
| 3032 | } |
| 3033 | return res; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3034 | } |
| 3035 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3036 | void loader_init_icd_lib_list() {} |
Jon Ashburn | 8810c5f | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 3037 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3038 | void loader_destroy_icd_lib_list() {} |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3039 | /** |
| 3040 | * Try to find the Vulkan ICD driver(s). |
| 3041 | * |
| 3042 | * This function scans the default system loader path(s) or path |
| 3043 | * specified by the \c VK_ICD_FILENAMES environment variable in |
| 3044 | * order to find loadable VK ICDs manifest files. From these |
| 3045 | * manifest files it finds the ICD libraries. |
| 3046 | * |
| 3047 | * \returns |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3048 | * Vulkan result |
| 3049 | * (on result == VK_SUCCESS) a list of icds that were discovered |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 3050 | */ |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3051 | VkResult loader_icd_scan(const struct loader_instance *inst, |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 3052 | struct loader_icd_tramp_list *icd_tramp_list) { |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3053 | char *file_str; |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 3054 | uint16_t file_major_vers = 0; |
| 3055 | uint16_t file_minor_vers = 0; |
| 3056 | uint16_t file_patch_vers = 0; |
| 3057 | char *vers_tok; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3058 | struct loader_manifest_files manifest_files; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3059 | VkResult res = VK_SUCCESS; |
| 3060 | bool lockedMutex = false; |
| 3061 | cJSON *json = NULL; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3062 | uint32_t num_good_icds = 0; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3063 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3064 | memset(&manifest_files, 0, sizeof(struct loader_manifest_files)); |
| 3065 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 3066 | res = loader_scanned_icd_init(inst, icd_tramp_list); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3067 | if (VK_SUCCESS != res) { |
| 3068 | goto out; |
| 3069 | } |
| 3070 | |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3071 | // Get a list of manifest files for ICDs |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3072 | res = loader_get_manifest_files(inst, "VK_ICD_FILENAMES", NULL, false, |
Mark Young | f8c2010 | 2016-11-07 16:26:17 -0700 | [diff] [blame] | 3073 | true, DEFAULT_VK_DRIVERS_INFO, |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3074 | HOME_VK_DRIVERS_INFO, &manifest_files); |
| 3075 | if (VK_SUCCESS != res || manifest_files.count == 0) { |
| 3076 | goto out; |
| 3077 | } |
Jon Ashburn | 6461ef2 | 2015-09-22 13:11:00 -0600 | [diff] [blame] | 3078 | loader_platform_thread_lock_mutex(&loader_json_lock); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3079 | lockedMutex = true; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3080 | for (uint32_t i = 0; i < manifest_files.count; i++) { |
| 3081 | file_str = manifest_files.filename_list[i]; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3082 | if (file_str == NULL) { |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3083 | continue; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3084 | } |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3085 | |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3086 | res = loader_get_json(inst, file_str, &json); |
| 3087 | if (VK_ERROR_OUT_OF_HOST_MEMORY == res) { |
| 3088 | break; |
| 3089 | } else if (VK_SUCCESS != res || NULL == json) { |
Jon Ashburn | aa4ea47 | 2015-08-27 08:30:50 -0600 | [diff] [blame] | 3090 | continue; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3091 | } |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3092 | |
Jon Ashburn | 005617f | 2015-11-17 17:35:40 -0700 | [diff] [blame] | 3093 | cJSON *item, *itemICD; |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 3094 | item = cJSON_GetObjectItem(json, "file_format_version"); |
Jon Ashburn | 6461ef2 | 2015-09-22 13:11:00 -0600 | [diff] [blame] | 3095 | if (item == NULL) { |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3096 | if (num_good_icds == 0) { |
| 3097 | res = VK_ERROR_INITIALIZATION_FAILED; |
| 3098 | } |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3099 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 3100 | "loader_icd_scan: ICD JSON %s does not have a" |
| 3101 | " \'file_format_version\' field. Skipping ICD JSON.", |
| 3102 | file_str); |
Derrick Owens | 62e16ef | 2016-09-09 15:49:07 -0400 | [diff] [blame] | 3103 | cJSON_Delete(json); |
| 3104 | json = NULL; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3105 | continue; |
Jon Ashburn | 6461ef2 | 2015-09-22 13:11:00 -0600 | [diff] [blame] | 3106 | } |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 3107 | char *file_vers = cJSON_Print(item); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3108 | if (NULL == file_vers) { |
| 3109 | // Only reason the print can fail is if there was an allocation |
| 3110 | // issue |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3111 | if (num_good_icds == 0) { |
| 3112 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 3113 | } |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3114 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 3115 | "loader_icd_scan: Failed retrieving ICD JSON %s" |
| 3116 | " \'file_format_version\' field. Skipping ICD JSON", |
| 3117 | file_str); |
Derrick Owens | cd92b8b | 2016-09-09 15:45:13 -0400 | [diff] [blame] | 3118 | cJSON_Delete(json); |
| 3119 | json = NULL; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3120 | continue; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3121 | } |
Mark Young | cbcbf89 | 2016-06-22 15:25:00 -0600 | [diff] [blame] | 3122 | loader_log(inst, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3123 | "Found ICD manifest file %s, version %s", file_str, |
| 3124 | file_vers); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 3125 | // Get the major/minor/and patch as integers for easier comparison |
| 3126 | vers_tok = strtok(file_vers, ".\"\n\r"); |
| 3127 | if (NULL != vers_tok) { |
Jamie Madill | 970ebcf | 2016-07-06 11:19:42 -0400 | [diff] [blame] | 3128 | file_major_vers = (uint16_t)atoi(vers_tok); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 3129 | vers_tok = strtok(NULL, ".\"\n\r"); |
| 3130 | if (NULL != vers_tok) { |
Jamie Madill | 970ebcf | 2016-07-06 11:19:42 -0400 | [diff] [blame] | 3131 | file_minor_vers = (uint16_t)atoi(vers_tok); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 3132 | vers_tok = strtok(NULL, ".\"\n\r"); |
| 3133 | if (NULL != vers_tok) { |
Jamie Madill | 970ebcf | 2016-07-06 11:19:42 -0400 | [diff] [blame] | 3134 | file_patch_vers = (uint16_t)atoi(vers_tok); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 3135 | } |
| 3136 | } |
| 3137 | } |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 3138 | 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] | 3139 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3140 | "loader_icd_scan: Unexpected manifest file version " |
| 3141 | "(expected 1.0.0 or 1.0.1), may cause errors"); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3142 | cJSON_Free(file_vers); |
Jon Ashburn | 005617f | 2015-11-17 17:35:40 -0700 | [diff] [blame] | 3143 | itemICD = cJSON_GetObjectItem(json, "ICD"); |
| 3144 | if (itemICD != NULL) { |
| 3145 | item = cJSON_GetObjectItem(itemICD, "library_path"); |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 3146 | if (item != NULL) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3147 | char *temp = cJSON_Print(item); |
Jon Ashburn | 8625130 | 2015-08-25 16:48:24 -0600 | [diff] [blame] | 3148 | if (!temp || strlen(temp) == 0) { |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3149 | if (num_good_icds == 0) { |
| 3150 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 3151 | } |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3152 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 3153 | "loader_icd_scan: Failed retrieving ICD JSON %s" |
| 3154 | " \'library_path\' field. Skipping ICD JSON.", |
| 3155 | file_str); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3156 | cJSON_Free(temp); |
Jon Ashburn | 8625130 | 2015-08-25 16:48:24 -0600 | [diff] [blame] | 3157 | cJSON_Delete(json); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3158 | json = NULL; |
Jon Ashburn | 8625130 | 2015-08-25 16:48:24 -0600 | [diff] [blame] | 3159 | continue; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3160 | } |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3161 | // strip out extra quotes |
Jon Ashburn | 8625130 | 2015-08-25 16:48:24 -0600 | [diff] [blame] | 3162 | temp[strlen(temp) - 1] = '\0'; |
| 3163 | char *library_path = loader_stack_alloc(strlen(temp) + 1); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3164 | if (NULL == library_path) { |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3165 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 3166 | "loader_icd_scan: Failed to allocate space for " |
| 3167 | "ICD JSON %s \'library_path\' value. Skipping " |
| 3168 | " ICD JSON.", |
| 3169 | file_str); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3170 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 3171 | cJSON_Free(temp); |
| 3172 | cJSON_Delete(json); |
| 3173 | json = NULL; |
| 3174 | goto out; |
| 3175 | } |
Jon Ashburn | 8625130 | 2015-08-25 16:48:24 -0600 | [diff] [blame] | 3176 | strcpy(library_path, &temp[1]); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3177 | cJSON_Free(temp); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3178 | if (strlen(library_path) == 0) { |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 3179 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3180 | "loader_icd_scan: ICD JSON %s \'library_path\'" |
| 3181 | " field is empty. Skipping ICD JSON.", |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3182 | file_str); |
Jon Ashburn | 8625130 | 2015-08-25 16:48:24 -0600 | [diff] [blame] | 3183 | cJSON_Delete(json); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3184 | json = NULL; |
Jon Ashburn | 8625130 | 2015-08-25 16:48:24 -0600 | [diff] [blame] | 3185 | continue; |
| 3186 | } |
Jamie Madill | 2fcbd15 | 2016-04-27 16:33:23 -0400 | [diff] [blame] | 3187 | char fullpath[MAX_STRING_SIZE]; |
Jon Ashburn | 8625130 | 2015-08-25 16:48:24 -0600 | [diff] [blame] | 3188 | // Print out the paths being searched if debugging is enabled |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3189 | loader_log( |
| 3190 | inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3191 | "Searching for ICD drivers named %s, using default dir %s", |
Jamie Madill | 2fcbd15 | 2016-04-27 16:33:23 -0400 | [diff] [blame] | 3192 | library_path, DEFAULT_VK_DRIVERS_PATH); |
Daniel Dadap | 00b4aba | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 3193 | if (loader_platform_is_path(library_path)) { |
Jon Ashburn | 8625130 | 2015-08-25 16:48:24 -0600 | [diff] [blame] | 3194 | // a relative or absolute path |
Daniel Dadap | 00b4aba | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 3195 | char *name_copy = loader_stack_alloc(strlen(file_str) + 1); |
| 3196 | char *rel_base; |
Jon Ashburn | 8625130 | 2015-08-25 16:48:24 -0600 | [diff] [blame] | 3197 | strcpy(name_copy, file_str); |
| 3198 | rel_base = loader_platform_dirname(name_copy); |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3199 | loader_expand_path(library_path, rel_base, sizeof(fullpath), |
| 3200 | fullpath); |
Daniel Dadap | 00b4aba | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 3201 | } else { |
Jamie Madill | 2fcbd15 | 2016-04-27 16:33:23 -0400 | [diff] [blame] | 3202 | // a filename which is assumed in a system directory |
| 3203 | loader_get_fullpath(library_path, DEFAULT_VK_DRIVERS_PATH, |
| 3204 | sizeof(fullpath), fullpath); |
Jon Ashburn | 8625130 | 2015-08-25 16:48:24 -0600 | [diff] [blame] | 3205 | } |
Jon Ashburn | 005617f | 2015-11-17 17:35:40 -0700 | [diff] [blame] | 3206 | |
| 3207 | uint32_t vers = 0; |
| 3208 | item = cJSON_GetObjectItem(itemICD, "api_version"); |
| 3209 | if (item != NULL) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3210 | temp = cJSON_Print(item); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3211 | if (NULL == temp) { |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3212 | loader_log( |
| 3213 | inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 3214 | "loader_icd_scan: Failed retrieving ICD JSON %s" |
| 3215 | " \'api_version\' field. Skipping ICD JSON.", |
| 3216 | file_str); |
| 3217 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3218 | // Only reason the print can fail is if there was an |
| 3219 | // allocation issue |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3220 | if (num_good_icds == 0) { |
| 3221 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 3222 | } |
| 3223 | |
| 3224 | cJSON_Free(temp); |
| 3225 | cJSON_Delete(json); |
| 3226 | json = NULL; |
| 3227 | continue; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3228 | } |
Jon Ashburn | 005617f | 2015-11-17 17:35:40 -0700 | [diff] [blame] | 3229 | vers = loader_make_version(temp); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3230 | cJSON_Free(temp); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3231 | } else { |
| 3232 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 3233 | "loader_icd_scan: ICD JSON %s does not have an" |
| 3234 | " \'api_version\' field.", |
| 3235 | file_str); |
Jon Ashburn | 005617f | 2015-11-17 17:35:40 -0700 | [diff] [blame] | 3236 | } |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3237 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 3238 | res = loader_scanned_icd_add(inst, icd_tramp_list, fullpath, |
| 3239 | vers); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3240 | if (VK_SUCCESS != res) { |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3241 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 3242 | "loader_icd_scan: Failed to add ICD JSON %s. " |
| 3243 | " Skipping ICD JSON.", |
| 3244 | fullpath); |
| 3245 | cJSON_Free(temp); |
| 3246 | cJSON_Delete(json); |
| 3247 | json = NULL; |
| 3248 | continue; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3249 | } |
| 3250 | num_good_icds++; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3251 | } else { |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 3252 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3253 | "loader_icd_scan: Failed to find \'library_path\' " |
| 3254 | "object in ICD JSON file %s. Skipping ICD JSON.", |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3255 | file_str); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3256 | } |
| 3257 | } else { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3258 | loader_log( |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 3259 | inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3260 | "loader_icd_scan: Can not find \'ICD\' object in ICD JSON " |
| 3261 | "file %s. Skipping ICD JSON", |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3262 | file_str); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3263 | } |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3264 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3265 | cJSON_Delete(json); |
| 3266 | json = NULL; |
| 3267 | } |
| 3268 | |
| 3269 | out: |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3270 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3271 | if (NULL != json) { |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3272 | cJSON_Delete(json); |
| 3273 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3274 | if (NULL != manifest_files.filename_list) { |
| 3275 | for (uint32_t i = 0; i < manifest_files.count; i++) { |
| 3276 | if (NULL != manifest_files.filename_list[i]) { |
| 3277 | loader_instance_heap_free(inst, |
| 3278 | manifest_files.filename_list[i]); |
| 3279 | } |
| 3280 | } |
| 3281 | loader_instance_heap_free(inst, manifest_files.filename_list); |
| 3282 | } |
| 3283 | if (lockedMutex) { |
| 3284 | loader_platform_thread_unlock_mutex(&loader_json_lock); |
| 3285 | } |
| 3286 | return res; |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 3287 | } |
| 3288 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3289 | void loader_layer_scan(const struct loader_instance *inst, |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 3290 | struct loader_layer_list *instance_layers) { |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 3291 | char *file_str; |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3292 | struct loader_manifest_files |
| 3293 | manifest_files[2]; // [0] = explicit, [1] = implicit |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 3294 | cJSON *json; |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3295 | uint32_t implicit; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3296 | bool lockedMutex = false; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 3297 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3298 | memset(manifest_files, 0, sizeof(struct loader_manifest_files) * 2); |
| 3299 | |
| 3300 | // Get a list of manifest files for explicit layers |
| 3301 | if (VK_SUCCESS != |
| 3302 | loader_get_manifest_files(inst, LAYERS_PATH_ENV, LAYERS_SOURCE_PATH, |
Mark Young | f8c2010 | 2016-11-07 16:26:17 -0700 | [diff] [blame] | 3303 | true, true, DEFAULT_VK_ELAYERS_INFO, |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3304 | HOME_VK_ELAYERS_INFO, &manifest_files[0])) { |
| 3305 | goto out; |
| 3306 | } |
| 3307 | |
| 3308 | // Get a list of manifest files for any implicit layers |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3309 | // Pass NULL for environment variable override - implicit layers are not |
| 3310 | // overridden by LAYERS_PATH_ENV |
Mark Young | f8c2010 | 2016-11-07 16:26:17 -0700 | [diff] [blame] | 3311 | if (VK_SUCCESS != loader_get_manifest_files(inst, NULL, NULL, true, false, |
| 3312 | DEFAULT_VK_ILAYERS_INFO, |
| 3313 | HOME_VK_ILAYERS_INFO, |
| 3314 | &manifest_files[1])) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3315 | goto out; |
| 3316 | } |
Jon Ashburn | 90c6a0e | 2015-06-04 15:30:58 -0600 | [diff] [blame] | 3317 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3318 | // Make sure we have at least one layer, if not, go ahead and return |
| 3319 | if (manifest_files[0].count == 0 && manifest_files[1].count == 0) { |
| 3320 | goto out; |
| 3321 | } |
| 3322 | |
| 3323 | // cleanup any previously scanned libraries |
Jon Ashburn | e39a4f8 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 3324 | loader_delete_layer_properties(inst, instance_layers); |
Jon Ashburn | b2ef137 | 2015-07-16 17:19:31 -0600 | [diff] [blame] | 3325 | |
Jon Ashburn | 6461ef2 | 2015-09-22 13:11:00 -0600 | [diff] [blame] | 3326 | loader_platform_thread_lock_mutex(&loader_json_lock); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3327 | lockedMutex = true; |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3328 | for (implicit = 0; implicit < 2; implicit++) { |
Jamie Madill | 970ebcf | 2016-07-06 11:19:42 -0400 | [diff] [blame] | 3329 | for (uint32_t i = 0; i < manifest_files[implicit].count; i++) { |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3330 | file_str = manifest_files[implicit].filename_list[i]; |
| 3331 | if (file_str == NULL) |
| 3332 | continue; |
Courtney Goeltzenleuchter | a9e4af4 | 2015-06-01 14:49:17 -0600 | [diff] [blame] | 3333 | |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3334 | // parse file into JSON struct |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3335 | VkResult res = loader_get_json(inst, file_str, &json); |
| 3336 | if (VK_ERROR_OUT_OF_HOST_MEMORY == res) { |
| 3337 | break; |
| 3338 | } else if (VK_SUCCESS != res || NULL == json) { |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3339 | continue; |
| 3340 | } |
| 3341 | |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 3342 | loader_add_layer_properties(inst, instance_layers, json, |
| 3343 | (implicit == 1), file_str); |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3344 | cJSON_Delete(json); |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 3345 | } |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 3346 | } |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 3347 | |
| 3348 | // 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] | 3349 | loader_add_layer_property_meta(inst, sizeof(std_validation_names) / |
| 3350 | sizeof(std_validation_names[0]), |
| 3351 | std_validation_names, instance_layers); |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 3352 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3353 | out: |
| 3354 | |
| 3355 | for (uint32_t manFile = 0; manFile < 2; manFile++) { |
| 3356 | if (NULL != manifest_files[manFile].filename_list) { |
| 3357 | for (uint32_t i = 0; i < manifest_files[manFile].count; i++) { |
| 3358 | if (NULL != manifest_files[manFile].filename_list[i]) { |
| 3359 | loader_instance_heap_free( |
| 3360 | inst, manifest_files[manFile].filename_list[i]); |
| 3361 | } |
| 3362 | } |
| 3363 | loader_instance_heap_free(inst, |
| 3364 | manifest_files[manFile].filename_list); |
| 3365 | } |
| 3366 | } |
| 3367 | if (lockedMutex) { |
| 3368 | loader_platform_thread_unlock_mutex(&loader_json_lock); |
| 3369 | } |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 3370 | } |
| 3371 | |
Jeremy Hayes | 3e2bd5a | 2016-04-01 11:40:26 -0600 | [diff] [blame] | 3372 | void loader_implicit_layer_scan(const struct loader_instance *inst, |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 3373 | struct loader_layer_list *instance_layers) { |
Jeremy Hayes | 3e2bd5a | 2016-04-01 11:40:26 -0600 | [diff] [blame] | 3374 | char *file_str; |
| 3375 | struct loader_manifest_files manifest_files; |
| 3376 | cJSON *json; |
| 3377 | uint32_t i; |
| 3378 | |
| 3379 | // Pass NULL for environment variable override - implicit layers are not |
| 3380 | // overridden by LAYERS_PATH_ENV |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3381 | VkResult res = loader_get_manifest_files( |
Mark Young | f8c2010 | 2016-11-07 16:26:17 -0700 | [diff] [blame] | 3382 | inst, NULL, NULL, true, false, DEFAULT_VK_ILAYERS_INFO, |
| 3383 | HOME_VK_ILAYERS_INFO, &manifest_files); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3384 | if (VK_SUCCESS != res || manifest_files.count == 0) { |
Jeremy Hayes | 3e2bd5a | 2016-04-01 11:40:26 -0600 | [diff] [blame] | 3385 | return; |
| 3386 | } |
| 3387 | |
| 3388 | /* cleanup any previously scanned libraries */ |
| 3389 | loader_delete_layer_properties(inst, instance_layers); |
Jeremy Hayes | 3e2bd5a | 2016-04-01 11:40:26 -0600 | [diff] [blame] | 3390 | |
| 3391 | loader_platform_thread_lock_mutex(&loader_json_lock); |
| 3392 | |
| 3393 | for (i = 0; i < manifest_files.count; i++) { |
| 3394 | file_str = manifest_files.filename_list[i]; |
| 3395 | if (file_str == NULL) { |
| 3396 | continue; |
| 3397 | } |
| 3398 | |
| 3399 | // parse file into JSON struct |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3400 | res = loader_get_json(inst, file_str, &json); |
| 3401 | if (VK_ERROR_OUT_OF_HOST_MEMORY == res) { |
| 3402 | break; |
| 3403 | } else if (VK_SUCCESS != res || NULL == json) { |
Jeremy Hayes | 3e2bd5a | 2016-04-01 11:40:26 -0600 | [diff] [blame] | 3404 | continue; |
| 3405 | } |
| 3406 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3407 | loader_add_layer_properties(inst, instance_layers, json, true, |
| 3408 | file_str); |
Jeremy Hayes | 3e2bd5a | 2016-04-01 11:40:26 -0600 | [diff] [blame] | 3409 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3410 | loader_instance_heap_free(inst, file_str); |
Jeremy Hayes | 3e2bd5a | 2016-04-01 11:40:26 -0600 | [diff] [blame] | 3411 | cJSON_Delete(json); |
| 3412 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3413 | loader_instance_heap_free(inst, manifest_files.filename_list); |
Jeremy Hayes | 3e2bd5a | 2016-04-01 11:40:26 -0600 | [diff] [blame] | 3414 | |
| 3415 | // 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] | 3416 | loader_add_layer_property_meta(inst, sizeof(std_validation_names) / |
| 3417 | sizeof(std_validation_names[0]), |
| 3418 | std_validation_names, instance_layers); |
Jeremy Hayes | 3e2bd5a | 2016-04-01 11:40:26 -0600 | [diff] [blame] | 3419 | |
| 3420 | loader_platform_thread_unlock_mutex(&loader_json_lock); |
| 3421 | } |
| 3422 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3423 | static VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL |
| 3424 | loader_gpa_instance_internal(VkInstance inst, const char *pName) { |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3425 | if (!strcmp(pName, "vkGetInstanceProcAddr")) |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3426 | return (void *)loader_gpa_instance_internal; |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3427 | if (!strcmp(pName, "vkCreateInstance")) |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 3428 | return (void *)terminator_CreateInstance; |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3429 | if (!strcmp(pName, "vkCreateDevice")) |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 3430 | return (void *)terminator_CreateDevice; |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3431 | |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 3432 | // inst is not wrapped |
| 3433 | if (inst == VK_NULL_HANDLE) { |
| 3434 | return NULL; |
| 3435 | } |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3436 | VkLayerInstanceDispatchTable *disp_table = |
| 3437 | *(VkLayerInstanceDispatchTable **)inst; |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 3438 | void *addr; |
| 3439 | |
| 3440 | if (disp_table == NULL) |
| 3441 | return NULL; |
| 3442 | |
Jon Ashburn | c7d3e73 | 2016-03-08 09:30:30 -0700 | [diff] [blame] | 3443 | bool found_name; |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 3444 | addr = |
| 3445 | loader_lookup_instance_dispatch_table(disp_table, pName, &found_name); |
Jon Ashburn | c7d3e73 | 2016-03-08 09:30:30 -0700 | [diff] [blame] | 3446 | if (found_name) { |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 3447 | return addr; |
Jon Ashburn | 3d526cb | 2015-04-13 18:10:06 -0600 | [diff] [blame] | 3448 | } |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3449 | |
Jon Ashburn | c7d3e73 | 2016-03-08 09:30:30 -0700 | [diff] [blame] | 3450 | // Don't call down the chain, this would be an infinite loop |
| 3451 | loader_log(NULL, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 3452 | "loader_gpa_instance_internal() unrecognized name %s", pName); |
Jon Ashburn | c7d3e73 | 2016-03-08 09:30:30 -0700 | [diff] [blame] | 3453 | return NULL; |
Jon Ashburn | 3d526cb | 2015-04-13 18:10:06 -0600 | [diff] [blame] | 3454 | } |
| 3455 | |
Piers Daniell | f9262be | 2016-09-14 11:24:36 -0600 | [diff] [blame] | 3456 | VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 3457 | loader_gpa_device_internal(VkDevice device, const char *pName) { |
| 3458 | struct loader_device *dev; |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 3459 | struct loader_icd_term *icd_term = |
| 3460 | loader_get_icd_and_device(device, &dev, NULL); |
Mark Young | 16573c7 | 2016-06-28 10:52:43 -0600 | [diff] [blame] | 3461 | |
Mark Young | 65cb366 | 2016-11-07 13:27:02 -0700 | [diff] [blame] | 3462 | // NOTE: Device Funcs needing Trampoline/Terminator. |
| 3463 | // Overrides for device functions needing a trampoline and |
| 3464 | // a terminator because certain device entry-points still need to go |
| 3465 | // through a terminator before hitting the ICD. This could be for |
| 3466 | // several reasons, but the main one is currently unwrapping an |
| 3467 | // object before passing the appropriate info along to the ICD. |
| 3468 | // This is why we also have to override the direct ICD call to |
| 3469 | // vkGetDeviceProcAddr to intercept those calls. |
| 3470 | if (!strcmp(pName, "vkGetDeviceProcAddr")) { |
| 3471 | return (PFN_vkVoidFunction)loader_gpa_device_internal; |
| 3472 | } else if (!strcmp(pName, "vkCreateSwapchainKHR")) { |
Mark Young | 16573c7 | 2016-06-28 10:52:43 -0600 | [diff] [blame] | 3473 | return (PFN_vkVoidFunction)terminator_vkCreateSwapchainKHR; |
Mark Young | 65cb366 | 2016-11-07 13:27:02 -0700 | [diff] [blame] | 3474 | } else if (!strcmp(pName, "vkDebugMarkerSetObjectTagEXT")) { |
| 3475 | return (PFN_vkVoidFunction)terminator_DebugMarkerSetObjectTagEXT; |
| 3476 | } else if (!strcmp(pName, "vkDebugMarkerSetObjectNameEXT")) { |
| 3477 | return (PFN_vkVoidFunction)terminator_DebugMarkerSetObjectNameEXT; |
Mark Young | 16573c7 | 2016-06-28 10:52:43 -0600 | [diff] [blame] | 3478 | } |
| 3479 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 3480 | return icd_term->GetDeviceProcAddr(device, pName); |
Piers Daniell | 295fe40 | 2016-03-29 11:51:11 -0600 | [diff] [blame] | 3481 | } |
| 3482 | |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3483 | /** |
| 3484 | * Initialize device_ext dispatch table entry as follows: |
| 3485 | * If dev == NULL find all logical devices created within this instance and |
| 3486 | * init the entry (given by idx) in the ext dispatch table. |
| 3487 | * 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] | 3488 | * The initialization value is gotten by calling down the device chain with |
| 3489 | * GDPA. |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3490 | * If GDPA returns NULL then don't initialize the dispatch table entry. |
| 3491 | */ |
| 3492 | static void loader_init_dispatch_dev_ext_entry(struct loader_instance *inst, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3493 | struct loader_device *dev, |
| 3494 | uint32_t idx, |
| 3495 | const char *funcName) |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3496 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3497 | { |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3498 | void *gdpa_value; |
| 3499 | if (dev != NULL) { |
| 3500 | gdpa_value = dev->loader_dispatch.core_dispatch.GetDeviceProcAddr( |
Mark Young | 65cb366 | 2016-11-07 13:27:02 -0700 | [diff] [blame] | 3501 | dev->chain_device, funcName); |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3502 | if (gdpa_value != NULL) |
Mark Young | 8191d9f | 2016-09-02 11:41:28 -0600 | [diff] [blame] | 3503 | dev->loader_dispatch.ext_dispatch.dev_ext[idx] = |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3504 | (PFN_vkDevExt)gdpa_value; |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3505 | } else { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 3506 | for (struct loader_icd_term *icd_term = inst->icd_terms; |
| 3507 | icd_term != NULL; icd_term = icd_term->next) { |
| 3508 | struct loader_device *ldev = icd_term->logical_device_list; |
Karl Schultz | 2558bd3 | 2016-02-24 14:39:39 -0700 | [diff] [blame] | 3509 | while (ldev) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3510 | gdpa_value = |
Karl Schultz | 2558bd3 | 2016-02-24 14:39:39 -0700 | [diff] [blame] | 3511 | ldev->loader_dispatch.core_dispatch.GetDeviceProcAddr( |
Mark Young | 65cb366 | 2016-11-07 13:27:02 -0700 | [diff] [blame] | 3512 | ldev->chain_device, funcName); |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3513 | if (gdpa_value != NULL) |
Mark Young | 8191d9f | 2016-09-02 11:41:28 -0600 | [diff] [blame] | 3514 | ldev->loader_dispatch.ext_dispatch.dev_ext[idx] = |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3515 | (PFN_vkDevExt)gdpa_value; |
Karl Schultz | 2558bd3 | 2016-02-24 14:39:39 -0700 | [diff] [blame] | 3516 | ldev = ldev->next; |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3517 | } |
| 3518 | } |
| 3519 | } |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3520 | } |
| 3521 | |
| 3522 | /** |
| 3523 | * Find all dev extension in the hash table and initialize the dispatch table |
| 3524 | * for dev for each of those extension entrypoints found in hash table. |
| 3525 | |
| 3526 | */ |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 3527 | void loader_init_dispatch_dev_ext(struct loader_instance *inst, |
| 3528 | struct loader_device *dev) { |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3529 | for (uint32_t i = 0; i < MAX_NUM_DEV_EXTS; i++) { |
| 3530 | if (inst->disp_hash[i].func_name != NULL) |
| 3531 | loader_init_dispatch_dev_ext_entry(inst, dev, i, |
| 3532 | inst->disp_hash[i].func_name); |
| 3533 | } |
| 3534 | } |
| 3535 | |
| 3536 | static bool loader_check_icds_for_address(struct loader_instance *inst, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3537 | const char *funcName) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 3538 | struct loader_icd_term *icd_term; |
| 3539 | icd_term = inst->icd_terms; |
| 3540 | while (NULL != icd_term) { |
| 3541 | if (icd_term->scanned_icd->GetInstanceProcAddr(icd_term->instance, |
| 3542 | funcName)) |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3543 | // this icd supports funcName |
| 3544 | return true; |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 3545 | icd_term = icd_term->next; |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3546 | } |
| 3547 | |
| 3548 | return false; |
| 3549 | } |
| 3550 | |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 3551 | static bool loader_check_layer_list_for_address( |
| 3552 | const struct loader_layer_list *const layers, const char *funcName) { |
Jeremy Hayes | 1eb1f62 | 2016-03-03 16:03:03 -0700 | [diff] [blame] | 3553 | // Iterate over the layers. |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 3554 | for (uint32_t layer = 0; layer < layers->count; ++layer) { |
Jeremy Hayes | 1eb1f62 | 2016-03-03 16:03:03 -0700 | [diff] [blame] | 3555 | // Iterate over the extensions. |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 3556 | const struct loader_device_extension_list *const extensions = |
| 3557 | &(layers->list[layer].device_extension_list); |
| 3558 | for (uint32_t extension = 0; extension < extensions->count; |
| 3559 | ++extension) { |
Jeremy Hayes | 1eb1f62 | 2016-03-03 16:03:03 -0700 | [diff] [blame] | 3560 | // Iterate over the entry points. |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 3561 | const struct loader_dev_ext_props *const property = |
| 3562 | &(extensions->list[extension]); |
| 3563 | for (uint32_t entry = 0; entry < property->entrypoint_count; |
| 3564 | ++entry) { |
| 3565 | if (strcmp(property->entrypoints[entry], funcName) == 0) { |
Jeremy Hayes | 1eb1f62 | 2016-03-03 16:03:03 -0700 | [diff] [blame] | 3566 | return true; |
| 3567 | } |
| 3568 | } |
| 3569 | } |
| 3570 | } |
| 3571 | |
| 3572 | return false; |
| 3573 | } |
| 3574 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3575 | static void loader_free_dev_ext_table(struct loader_instance *inst) { |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3576 | for (uint32_t i = 0; i < MAX_NUM_DEV_EXTS; i++) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3577 | loader_instance_heap_free(inst, inst->disp_hash[i].func_name); |
| 3578 | loader_instance_heap_free(inst, inst->disp_hash[i].list.index); |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3579 | } |
| 3580 | memset(inst->disp_hash, 0, sizeof(inst->disp_hash)); |
| 3581 | } |
| 3582 | |
| 3583 | static bool loader_add_dev_ext_table(struct loader_instance *inst, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3584 | uint32_t *ptr_idx, const char *funcName) { |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3585 | uint32_t i; |
| 3586 | uint32_t idx = *ptr_idx; |
| 3587 | struct loader_dispatch_hash_list *list = &inst->disp_hash[idx].list; |
| 3588 | |
| 3589 | if (!inst->disp_hash[idx].func_name) { |
| 3590 | // no entry here at this idx, so use it |
| 3591 | assert(list->capacity == 0); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3592 | inst->disp_hash[idx].func_name = (char *)loader_instance_heap_alloc( |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3593 | inst, strlen(funcName) + 1, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3594 | if (inst->disp_hash[idx].func_name == NULL) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 3595 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3596 | "loader_add_dev_ext_table: Failed to allocate memory " |
| 3597 | "for func_name %s", |
| 3598 | funcName); |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3599 | return false; |
| 3600 | } |
| 3601 | strncpy(inst->disp_hash[idx].func_name, funcName, strlen(funcName) + 1); |
| 3602 | return true; |
| 3603 | } |
| 3604 | |
| 3605 | // check for enough capacity |
| 3606 | if (list->capacity == 0) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 3607 | list->index = |
| 3608 | loader_instance_heap_alloc(inst, 8 * sizeof(*(list->index)), |
| 3609 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3610 | if (list->index == NULL) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 3611 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3612 | "loader_add_dev_ext_table: Failed to allocate memory " |
| 3613 | "for list index", |
| 3614 | funcName); |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3615 | return false; |
| 3616 | } |
| 3617 | list->capacity = 8 * sizeof(*(list->index)); |
| 3618 | } else if (list->capacity < (list->count + 1) * sizeof(*(list->index))) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 3619 | list->index = loader_instance_heap_realloc( |
| 3620 | inst, list->index, list->capacity, list->capacity * 2, |
| 3621 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3622 | if (list->index == NULL) { |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3623 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 3624 | "loader_add_dev_ext_table: Failed to reallocate memory " |
| 3625 | "for list index", |
| 3626 | funcName); |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3627 | return false; |
| 3628 | } |
| 3629 | list->capacity *= 2; |
| 3630 | } |
| 3631 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3632 | // find an unused index in the hash table and use it |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3633 | i = (idx + 1) % MAX_NUM_DEV_EXTS; |
| 3634 | do { |
| 3635 | if (!inst->disp_hash[i].func_name) { |
| 3636 | assert(inst->disp_hash[i].list.capacity == 0); |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 3637 | inst->disp_hash[i].func_name = (char *)loader_instance_heap_alloc( |
| 3638 | inst, strlen(funcName) + 1, |
| 3639 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3640 | if (inst->disp_hash[i].func_name == NULL) { |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3641 | loader_log( |
| 3642 | inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 3643 | "loader_add_dev_ext_table: Failed to allocate memory " |
| 3644 | "for func_name %s", |
| 3645 | funcName); |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3646 | return false; |
| 3647 | } |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3648 | strncpy(inst->disp_hash[i].func_name, funcName, |
| 3649 | strlen(funcName) + 1); |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3650 | list->index[list->count] = i; |
| 3651 | list->count++; |
| 3652 | *ptr_idx = i; |
| 3653 | return true; |
| 3654 | } |
| 3655 | i = (i + 1) % MAX_NUM_DEV_EXTS; |
| 3656 | } while (i != idx); |
| 3657 | |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3658 | loader_log( |
| 3659 | inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 3660 | "loader_add_dev_ext_table: Could not insert into hash table; is " |
| 3661 | "it full?"); |
| 3662 | |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3663 | return false; |
| 3664 | } |
| 3665 | |
| 3666 | static bool loader_name_in_dev_ext_table(struct loader_instance *inst, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3667 | uint32_t *idx, const char *funcName) { |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3668 | uint32_t alt_idx; |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3669 | if (inst->disp_hash[*idx].func_name && |
| 3670 | !strcmp(inst->disp_hash[*idx].func_name, funcName)) |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3671 | return true; |
| 3672 | |
| 3673 | // funcName wasn't at the primary spot in the hash table |
| 3674 | // search the list of secondary locations (shallow search, not deep search) |
| 3675 | for (uint32_t i = 0; i < inst->disp_hash[*idx].list.count; i++) { |
| 3676 | alt_idx = inst->disp_hash[*idx].list.index[i]; |
| 3677 | if (!strcmp(inst->disp_hash[*idx].func_name, funcName)) { |
| 3678 | *idx = alt_idx; |
| 3679 | return true; |
| 3680 | } |
| 3681 | } |
| 3682 | |
| 3683 | return false; |
| 3684 | } |
| 3685 | |
| 3686 | /** |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3687 | * This function returns generic trampoline code address for unknown entry |
| 3688 | * points. |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3689 | * Presumably, these unknown entry points (as given by funcName) are device |
| 3690 | * extension entrypoints. A hash table is used to keep a list of unknown entry |
| 3691 | * points and their mapping to the device extension dispatch table |
| 3692 | * (struct loader_dev_ext_dispatch_table). |
| 3693 | * \returns |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3694 | * For a given entry point string (funcName), if an existing mapping is found |
| 3695 | * the |
| 3696 | * trampoline address for that mapping is returned. Otherwise, this unknown |
| 3697 | * entry point |
| 3698 | * has not been seen yet. Next check if a layer or ICD supports it. If so then |
| 3699 | * a |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3700 | * new entry in the hash table is initialized and that trampoline address for |
| 3701 | * the new entry is returned. Null is returned if the hash table is full or |
| 3702 | * if no discovered layer or ICD returns a non-NULL GetProcAddr for it. |
| 3703 | */ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3704 | void *loader_dev_ext_gpa(struct loader_instance *inst, const char *funcName) { |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3705 | uint32_t idx; |
| 3706 | uint32_t seed = 0; |
| 3707 | |
| 3708 | idx = murmurhash(funcName, strlen(funcName), seed) % MAX_NUM_DEV_EXTS; |
| 3709 | |
| 3710 | if (loader_name_in_dev_ext_table(inst, &idx, funcName)) |
| 3711 | // found funcName already in hash |
| 3712 | return loader_get_dev_ext_trampoline(idx); |
| 3713 | |
| 3714 | // Check if funcName is supported in either ICDs or a layer library |
Jeremy Hayes | 1eb1f62 | 2016-03-03 16:03:03 -0700 | [diff] [blame] | 3715 | if (!loader_check_icds_for_address(inst, funcName) && |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 3716 | !loader_check_layer_list_for_address(&inst->instance_layer_list, |
| 3717 | funcName)) { |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3718 | // if support found in layers continue on |
| 3719 | return NULL; |
| 3720 | } |
| 3721 | |
| 3722 | if (loader_add_dev_ext_table(inst, &idx, funcName)) { |
| 3723 | // successfully added new table entry |
| 3724 | // init any dev dispatch table entrys as needed |
| 3725 | loader_init_dispatch_dev_ext_entry(inst, NULL, idx, funcName); |
| 3726 | return loader_get_dev_ext_trampoline(idx); |
| 3727 | } |
| 3728 | |
| 3729 | return NULL; |
| 3730 | } |
| 3731 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3732 | struct loader_instance *loader_get_instance(const VkInstance instance) { |
Jon Ashburn | e0e6457 | 2015-09-30 12:56:42 -0600 | [diff] [blame] | 3733 | /* look up the loader_instance in our list by comparing dispatch tables, as |
| 3734 | * there is no guarantee the instance is still a loader_instance* after any |
| 3735 | * layers which wrap the instance object. |
| 3736 | */ |
| 3737 | const VkLayerInstanceDispatchTable *disp; |
| 3738 | struct loader_instance *ptr_instance = NULL; |
| 3739 | disp = loader_get_instance_dispatch(instance); |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3740 | for (struct loader_instance *inst = loader.instances; inst; |
| 3741 | inst = inst->next) { |
Jon Ashburn | e0e6457 | 2015-09-30 12:56:42 -0600 | [diff] [blame] | 3742 | if (inst->disp == disp) { |
| 3743 | ptr_instance = inst; |
| 3744 | break; |
| 3745 | } |
| 3746 | } |
| 3747 | return ptr_instance; |
| 3748 | } |
| 3749 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3750 | static loader_platform_dl_handle |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 3751 | loader_open_layer_lib(const struct loader_instance *inst, |
| 3752 | const char *chain_type, |
| 3753 | struct loader_layer_properties *prop) { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3754 | |
Jon Ashburn | 4dc1d8a | 2016-04-20 13:21:17 -0600 | [diff] [blame] | 3755 | if ((prop->lib_handle = loader_platform_open_library(prop->lib_name)) == |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3756 | NULL) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 3757 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3758 | "loader_open_layer_lib: Failed to open library %s", |
| 3759 | prop->lib_name); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3760 | } else { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 3761 | loader_log(inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3762 | "Loading layer library %s", prop->lib_name); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3763 | } |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3764 | |
Jon Ashburn | 4dc1d8a | 2016-04-20 13:21:17 -0600 | [diff] [blame] | 3765 | return prop->lib_handle; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3766 | } |
| 3767 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 3768 | static void loader_close_layer_lib(const struct loader_instance *inst, |
| 3769 | struct loader_layer_properties *prop) { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3770 | |
Jon Ashburn | 4dc1d8a | 2016-04-20 13:21:17 -0600 | [diff] [blame] | 3771 | if (prop->lib_handle) { |
| 3772 | loader_platform_close_library(prop->lib_handle); |
| 3773 | loader_log(inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, |
| 3774 | "Unloading layer library %s", prop->lib_name); |
| 3775 | prop->lib_handle = NULL; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 3776 | } |
Jon Ashburn | 4dc1d8a | 2016-04-20 13:21:17 -0600 | [diff] [blame] | 3777 | } |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 3778 | |
Jon Ashburn | 4dc1d8a | 2016-04-20 13:21:17 -0600 | [diff] [blame] | 3779 | void loader_deactivate_layers(const struct loader_instance *instance, |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3780 | struct loader_device *device, |
Jon Ashburn | 4dc1d8a | 2016-04-20 13:21:17 -0600 | [diff] [blame] | 3781 | struct loader_layer_list *list) { |
| 3782 | /* delete instance list of enabled layers and close any layer libraries */ |
| 3783 | for (uint32_t i = 0; i < list->count; i++) { |
| 3784 | struct loader_layer_properties *layer_prop = &list->list[i]; |
Courtney Goeltzenleuchter | 80bfd0e | 2015-12-17 09:51:22 -0700 | [diff] [blame] | 3785 | |
Jon Ashburn | 4dc1d8a | 2016-04-20 13:21:17 -0600 | [diff] [blame] | 3786 | loader_close_layer_lib(instance, layer_prop); |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 3787 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3788 | loader_destroy_layer_list(instance, device, list); |
Jon Ashburn | b835805 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 3789 | } |
| 3790 | |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 3791 | /** |
| 3792 | * Go through the search_list and find any layers which match type. If layer |
| 3793 | * type match is found in then add it to ext_list. |
| 3794 | */ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3795 | static void |
| 3796 | loader_add_layer_implicit(const struct loader_instance *inst, |
| 3797 | const enum layer_type type, |
| 3798 | struct loader_layer_list *list, |
| 3799 | const struct loader_layer_list *search_list) { |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3800 | bool enable; |
| 3801 | char *env_value; |
Jon Ashburn | 0c26e71 | 2015-07-02 16:10:32 -0600 | [diff] [blame] | 3802 | uint32_t i; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 3803 | for (i = 0; i < search_list->count; i++) { |
| 3804 | const struct loader_layer_properties *prop = &search_list->list[i]; |
Jon Ashburn | 0c26e71 | 2015-07-02 16:10:32 -0600 | [diff] [blame] | 3805 | if (prop->type & type) { |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3806 | /* Found an implicit layer, see if it should be enabled */ |
| 3807 | enable = false; |
| 3808 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3809 | // if no enable_environment variable is specified, this implicit |
| 3810 | // layer |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3811 | // should always be enabled. Otherwise check if the variable is set |
| 3812 | if (prop->enable_env_var.name[0] == 0) { |
| 3813 | enable = true; |
| 3814 | } else { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3815 | env_value = loader_getenv(prop->enable_env_var.name, inst); |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3816 | if (env_value && !strcmp(prop->enable_env_var.value, env_value)) |
| 3817 | enable = true; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3818 | loader_free_getenv(env_value, inst); |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3819 | } |
| 3820 | |
| 3821 | // disable_environment has priority, i.e. if both enable and disable |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3822 | // environment variables are set, the layer is disabled. Implicit |
| 3823 | // layers |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3824 | // are required to have a disable_environment variables |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3825 | env_value = loader_getenv(prop->disable_env_var.name, inst); |
| 3826 | if (env_value) { |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3827 | enable = false; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3828 | } |
| 3829 | loader_free_getenv(env_value, inst); |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3830 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3831 | if (enable) { |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3832 | loader_add_to_layer_list(inst, list, 1, prop); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3833 | } |
Jon Ashburn | 0c26e71 | 2015-07-02 16:10:32 -0600 | [diff] [blame] | 3834 | } |
| 3835 | } |
Jon Ashburn | 0c26e71 | 2015-07-02 16:10:32 -0600 | [diff] [blame] | 3836 | } |
| 3837 | |
| 3838 | /** |
| 3839 | * 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] | 3840 | * is found in search_list then add it to layer_list. But only add it to |
| 3841 | * layer_list if type matches. |
Jon Ashburn | 0c26e71 | 2015-07-02 16:10:32 -0600 | [diff] [blame] | 3842 | */ |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 3843 | static void loader_add_layer_env(struct loader_instance *inst, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3844 | const enum layer_type type, |
| 3845 | const char *env_name, |
| 3846 | struct loader_layer_list *layer_list, |
| 3847 | const struct loader_layer_list *search_list) { |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 3848 | char *layerEnv; |
Jon Ashburn | eb6d568 | 2015-07-02 14:10:53 -0600 | [diff] [blame] | 3849 | char *next, *name; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 3850 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3851 | layerEnv = loader_getenv(env_name, inst); |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 3852 | if (layerEnv == NULL) { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3853 | return; |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 3854 | } |
Courtney Goeltzenleuchter | 7f5aafc | 2015-07-05 11:28:29 -0600 | [diff] [blame] | 3855 | name = loader_stack_alloc(strlen(layerEnv) + 1); |
Jon Ashburn | eb6d568 | 2015-07-02 14:10:53 -0600 | [diff] [blame] | 3856 | if (name == NULL) { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3857 | return; |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 3858 | } |
Jon Ashburn | eb6d568 | 2015-07-02 14:10:53 -0600 | [diff] [blame] | 3859 | strcpy(name, layerEnv); |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 3860 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3861 | loader_free_getenv(layerEnv, inst); |
Jon Ashburn | 38a497f | 2016-01-04 14:01:38 -0700 | [diff] [blame] | 3862 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3863 | while (name && *name) { |
Jon Ashburn | eb6d568 | 2015-07-02 14:10:53 -0600 | [diff] [blame] | 3864 | next = loader_get_next_path(name); |
Jon Ashburn | 7148344 | 2016-02-11 18:59:43 -0700 | [diff] [blame] | 3865 | if (!strcmp(std_validation_str, name)) { |
| 3866 | /* add meta list of layers |
| 3867 | don't attempt to remove duplicate layers already added by app or |
| 3868 | env var |
| 3869 | */ |
| 3870 | loader_log(inst, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, |
| 3871 | "Expanding meta layer %s found in environment variable", |
| 3872 | std_validation_str); |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 3873 | if (type == VK_LAYER_TYPE_INSTANCE_EXPLICIT) |
| 3874 | inst->activated_layers_are_std_val = true; |
Jon Ashburn | 7148344 | 2016-02-11 18:59:43 -0700 | [diff] [blame] | 3875 | for (uint32_t i = 0; i < sizeof(std_validation_names) / |
| 3876 | sizeof(std_validation_names[0]); |
| 3877 | i++) { |
| 3878 | loader_find_layer_name_add_list(inst, std_validation_names[i], |
| 3879 | type, search_list, layer_list); |
| 3880 | } |
| 3881 | } else { |
| 3882 | loader_find_layer_name_add_list(inst, name, type, search_list, |
| 3883 | layer_list); |
| 3884 | } |
Jon Ashburn | eb6d568 | 2015-07-02 14:10:53 -0600 | [diff] [blame] | 3885 | name = next; |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 3886 | } |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 3887 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3888 | return; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 3889 | } |
| 3890 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3891 | VkResult |
| 3892 | loader_enable_instance_layers(struct loader_instance *inst, |
| 3893 | const VkInstanceCreateInfo *pCreateInfo, |
| 3894 | const struct loader_layer_list *instance_layers) { |
Courtney Goeltzenleuchter | 40caf0b | 2015-07-06 09:06:34 -0600 | [diff] [blame] | 3895 | VkResult err; |
| 3896 | |
Courtney Goeltzenleuchter | 55659b7 | 2015-09-14 18:01:17 -0600 | [diff] [blame] | 3897 | assert(inst && "Cannot have null instance"); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3898 | |
Jon Ashburn | e39a4f8 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 3899 | if (!loader_init_layer_list(inst, &inst->activated_layer_list)) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3900 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3901 | "loader_enable_instance_layers: Failed to initialize" |
| 3902 | " the layer list"); |
Courtney Goeltzenleuchter | 40caf0b | 2015-07-06 09:06:34 -0600 | [diff] [blame] | 3903 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Jon Ashburn | bd6c488 | 2015-07-02 12:59:25 -0600 | [diff] [blame] | 3904 | } |
| 3905 | |
Jon Ashburn | 0c26e71 | 2015-07-02 16:10:32 -0600 | [diff] [blame] | 3906 | /* Add any implicit layers first */ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3907 | loader_add_layer_implicit(inst, VK_LAYER_TYPE_INSTANCE_IMPLICIT, |
| 3908 | &inst->activated_layer_list, instance_layers); |
Jon Ashburn | 0c26e71 | 2015-07-02 16:10:32 -0600 | [diff] [blame] | 3909 | |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 3910 | /* Add any layers specified via environment variable next */ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3911 | loader_add_layer_env(inst, VK_LAYER_TYPE_INSTANCE_EXPLICIT, |
| 3912 | "VK_INSTANCE_LAYERS", &inst->activated_layer_list, |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3913 | instance_layers); |
Jon Ashburn | bd6c488 | 2015-07-02 12:59:25 -0600 | [diff] [blame] | 3914 | |
| 3915 | /* Add layers specified by the application */ |
Courtney Goeltzenleuchter | 40caf0b | 2015-07-06 09:06:34 -0600 | [diff] [blame] | 3916 | err = loader_add_layer_names_to_list( |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3917 | inst, &inst->activated_layer_list, pCreateInfo->enabledLayerCount, |
| 3918 | pCreateInfo->ppEnabledLayerNames, instance_layers); |
Courtney Goeltzenleuchter | 40caf0b | 2015-07-06 09:06:34 -0600 | [diff] [blame] | 3919 | |
| 3920 | return err; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3921 | } |
| 3922 | |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3923 | /* |
| 3924 | * Given the list of layers to activate in the loader_instance |
| 3925 | * structure. This function will add a VkLayerInstanceCreateInfo |
| 3926 | * structure to the VkInstanceCreateInfo.pNext pointer. |
| 3927 | * Each activated layer will have it's own VkLayerInstanceLink |
| 3928 | * structure that tells the layer what Get*ProcAddr to call to |
| 3929 | * get function pointers to the next layer down. |
| 3930 | * Once the chain info has been created this function will |
| 3931 | * execute the CreateInstance call chain. Each layer will |
| 3932 | * then have an opportunity in it's CreateInstance function |
| 3933 | * to setup it's dispatch table when the lower layer returns |
| 3934 | * successfully. |
| 3935 | * Each layer can wrap or not-wrap the returned VkInstance object |
| 3936 | * as it sees fit. |
| 3937 | * The instance chain is terminated by a loader function |
| 3938 | * that will call CreateInstance on all available ICD's and |
| 3939 | * cache those VkInstance objects for future use. |
| 3940 | */ |
| 3941 | VkResult loader_create_instance_chain(const VkInstanceCreateInfo *pCreateInfo, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3942 | const VkAllocationCallbacks *pAllocator, |
Jon Ashburn | 373c180 | 2016-01-20 08:08:25 -0700 | [diff] [blame] | 3943 | struct loader_instance *inst, |
Jon Ashburn | 6e0a213 | 2016-02-03 12:37:30 -0700 | [diff] [blame] | 3944 | VkInstance *created_instance) { |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3945 | uint32_t activated_layers = 0; |
| 3946 | VkLayerInstanceCreateInfo chain_info; |
| 3947 | VkLayerInstanceLink *layer_instance_link_info = NULL; |
| 3948 | VkInstanceCreateInfo loader_create_info; |
| 3949 | VkResult res; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3950 | |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3951 | PFN_vkGetInstanceProcAddr nextGIPA = loader_gpa_instance_internal; |
| 3952 | PFN_vkGetInstanceProcAddr fpGIPA = loader_gpa_instance_internal; |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 3953 | |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3954 | memcpy(&loader_create_info, pCreateInfo, sizeof(VkInstanceCreateInfo)); |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 3955 | |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3956 | if (inst->activated_layer_list.count > 0) { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3957 | |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3958 | chain_info.u.pLayerInfo = NULL; |
| 3959 | chain_info.pNext = pCreateInfo->pNext; |
| 3960 | chain_info.sType = VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO; |
| 3961 | chain_info.function = VK_LAYER_LINK_INFO; |
| 3962 | loader_create_info.pNext = &chain_info; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3963 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3964 | layer_instance_link_info = loader_stack_alloc( |
| 3965 | sizeof(VkLayerInstanceLink) * inst->activated_layer_list.count); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3966 | if (!layer_instance_link_info) { |
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_create_instance_chain: Failed to alloc Instance" |
| 3969 | " objects for layer"); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3970 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 3971 | } |
| 3972 | |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3973 | /* Create instance chain of enabled layers */ |
| 3974 | 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] | 3975 | struct loader_layer_properties *layer_prop = |
| 3976 | &inst->activated_layer_list.list[i]; |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3977 | loader_platform_dl_handle lib_handle; |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 3978 | |
Jon Ashburn | 4dc1d8a | 2016-04-20 13:21:17 -0600 | [diff] [blame] | 3979 | lib_handle = loader_open_layer_lib(inst, "instance", layer_prop); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3980 | if (!lib_handle) |
Courtney Goeltzenleuchter | 524b7e3 | 2016-01-14 16:06:06 -0700 | [diff] [blame] | 3981 | continue; |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3982 | if ((fpGIPA = layer_prop->functions.get_instance_proc_addr) == |
| 3983 | NULL) { |
Jamie Madill | c3d3f07 | 2016-12-14 17:21:43 -0500 | [diff] [blame] | 3984 | if (strlen(layer_prop->functions.str_gipa) == 0) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3985 | fpGIPA = (PFN_vkGetInstanceProcAddr) |
| 3986 | loader_platform_get_proc_address( |
| 3987 | lib_handle, "vkGetInstanceProcAddr"); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3988 | layer_prop->functions.get_instance_proc_addr = fpGIPA; |
| 3989 | } else |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3990 | fpGIPA = (PFN_vkGetInstanceProcAddr) |
| 3991 | loader_platform_get_proc_address( |
| 3992 | lib_handle, layer_prop->functions.str_gipa); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3993 | if (!fpGIPA) { |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3994 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 3995 | "loader_create_instance_chain: Failed to find " |
| 3996 | "\'vkGetInstanceProcAddr\' in layer %s", |
| 3997 | layer_prop->lib_name); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3998 | continue; |
| 3999 | } |
| 4000 | } |
| 4001 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4002 | layer_instance_link_info[activated_layers].pNext = |
| 4003 | chain_info.u.pLayerInfo; |
| 4004 | layer_instance_link_info[activated_layers] |
| 4005 | .pfnNextGetInstanceProcAddr = nextGIPA; |
| 4006 | chain_info.u.pLayerInfo = |
| 4007 | &layer_instance_link_info[activated_layers]; |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4008 | nextGIPA = fpGIPA; |
| 4009 | |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 4010 | loader_log(inst, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4011 | "Insert instance layer %s (%s)", |
| 4012 | layer_prop->info.layerName, layer_prop->lib_name); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4013 | |
| 4014 | activated_layers++; |
| 4015 | } |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 4016 | } |
| 4017 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4018 | PFN_vkCreateInstance fpCreateInstance = |
Jon Ashburn | 6e0a213 | 2016-02-03 12:37:30 -0700 | [diff] [blame] | 4019 | (PFN_vkCreateInstance)nextGIPA(*created_instance, "vkCreateInstance"); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4020 | if (fpCreateInstance) { |
Jon Ashburn | c3c5877 | 2016-03-29 11:16:01 -0600 | [diff] [blame] | 4021 | VkLayerInstanceCreateInfo create_info_disp; |
| 4022 | |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 4023 | create_info_disp.sType = VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO; |
Jon Ashburn | ed8f231 | 2016-03-31 10:52:22 -0600 | [diff] [blame] | 4024 | create_info_disp.function = VK_LOADER_DATA_CALLBACK; |
Jon Ashburn | c3c5877 | 2016-03-29 11:16:01 -0600 | [diff] [blame] | 4025 | |
| 4026 | create_info_disp.u.pfnSetInstanceLoaderData = vkSetInstanceDispatch; |
| 4027 | |
| 4028 | create_info_disp.pNext = loader_create_info.pNext; |
| 4029 | loader_create_info.pNext = &create_info_disp; |
Jon Ashburn | f2b4e38 | 2016-02-10 20:50:19 -0700 | [diff] [blame] | 4030 | res = |
| 4031 | fpCreateInstance(&loader_create_info, pAllocator, created_instance); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4032 | } else { |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4033 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4034 | "loader_create_instance_chain: Failed to find " |
| 4035 | "\'vkCreateInstance\'"); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4036 | // Couldn't find CreateInstance function! |
| 4037 | res = VK_ERROR_INITIALIZATION_FAILED; |
| 4038 | } |
| 4039 | |
| 4040 | if (res != VK_SUCCESS) { |
| 4041 | // TODO: Need to clean up here |
| 4042 | } else { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4043 | loader_init_instance_core_dispatch_table(inst->disp, nextGIPA, |
Jon Ashburn | 6e0a213 | 2016-02-03 12:37:30 -0700 | [diff] [blame] | 4044 | *created_instance); |
Jon Ashburn | 4e8c416 | 2016-03-08 15:21:30 -0700 | [diff] [blame] | 4045 | inst->instance = *created_instance; |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4046 | } |
| 4047 | |
| 4048 | return res; |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 4049 | } |
| 4050 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4051 | void loader_activate_instance_layer_extensions(struct loader_instance *inst, |
| 4052 | VkInstance created_inst) { |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 4053 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4054 | loader_init_instance_extension_dispatch_table( |
| 4055 | inst->disp, inst->disp->GetInstanceProcAddr, created_inst); |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 4056 | } |
| 4057 | |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 4058 | VkResult |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 4059 | loader_create_device_chain(const struct loader_physical_device_tramp *pd, |
| 4060 | const VkDeviceCreateInfo *pCreateInfo, |
| 4061 | const VkAllocationCallbacks *pAllocator, |
| 4062 | const struct loader_instance *inst, |
| 4063 | struct loader_device *dev) { |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4064 | uint32_t activated_layers = 0; |
| 4065 | VkLayerDeviceLink *layer_device_link_info; |
| 4066 | VkLayerDeviceCreateInfo chain_info; |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4067 | VkDeviceCreateInfo loader_create_info; |
| 4068 | VkResult res; |
Courtney Goeltzenleuchter | ca173b8 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 4069 | |
Piers Daniell | 295fe40 | 2016-03-29 11:51:11 -0600 | [diff] [blame] | 4070 | PFN_vkGetDeviceProcAddr fpGDPA, nextGDPA = loader_gpa_device_internal; |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4071 | PFN_vkGetInstanceProcAddr fpGIPA, nextGIPA = loader_gpa_instance_internal; |
Courtney Goeltzenleuchter | ca173b8 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 4072 | |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4073 | memcpy(&loader_create_info, pCreateInfo, sizeof(VkDeviceCreateInfo)); |
| 4074 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4075 | layer_device_link_info = loader_stack_alloc( |
| 4076 | sizeof(VkLayerDeviceLink) * dev->activated_layer_list.count); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4077 | if (!layer_device_link_info) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4078 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4079 | "loader_create_device_chain: Failed to alloc Device objects" |
| 4080 | " for layer. Skipping Layer."); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4081 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
David Pinedo | a0a8a24 | 2015-06-24 15:29:18 -0600 | [diff] [blame] | 4082 | } |
Jon Ashburn | 94e7049 | 2015-06-10 10:13:10 -0600 | [diff] [blame] | 4083 | |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4084 | if (dev->activated_layer_list.count > 0) { |
Jon Ashburn | 72690f2 | 2016-03-29 12:52:13 -0600 | [diff] [blame] | 4085 | chain_info.sType = VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO; |
| 4086 | chain_info.function = VK_LAYER_LINK_INFO; |
| 4087 | chain_info.u.pLayerInfo = NULL; |
| 4088 | chain_info.pNext = pCreateInfo->pNext; |
| 4089 | loader_create_info.pNext = &chain_info; |
| 4090 | |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4091 | /* Create instance chain of enabled layers */ |
| 4092 | 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] | 4093 | struct loader_layer_properties *layer_prop = |
| 4094 | &dev->activated_layer_list.list[i]; |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4095 | loader_platform_dl_handle lib_handle; |
Courtney Goeltzenleuchter | ca173b8 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 4096 | |
Jon Ashburn | 4dc1d8a | 2016-04-20 13:21:17 -0600 | [diff] [blame] | 4097 | lib_handle = loader_open_layer_lib(inst, "device", layer_prop); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4098 | if (!lib_handle) |
Courtney Goeltzenleuchter | 524b7e3 | 2016-01-14 16:06:06 -0700 | [diff] [blame] | 4099 | continue; |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4100 | if ((fpGIPA = layer_prop->functions.get_instance_proc_addr) == |
| 4101 | NULL) { |
Jamie Madill | c3d3f07 | 2016-12-14 17:21:43 -0500 | [diff] [blame] | 4102 | if (strlen(layer_prop->functions.str_gipa) == 0) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4103 | fpGIPA = (PFN_vkGetInstanceProcAddr) |
| 4104 | loader_platform_get_proc_address( |
| 4105 | lib_handle, "vkGetInstanceProcAddr"); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4106 | layer_prop->functions.get_instance_proc_addr = fpGIPA; |
| 4107 | } else |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4108 | fpGIPA = (PFN_vkGetInstanceProcAddr) |
| 4109 | loader_platform_get_proc_address( |
| 4110 | lib_handle, layer_prop->functions.str_gipa); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4111 | if (!fpGIPA) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4112 | loader_log( |
| 4113 | inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4114 | "loader_create_device_chain: Failed to find " |
| 4115 | "\'vkGetInstanceProcAddr\' in layer %s. Skipping" |
| 4116 | " layer.", |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4117 | layer_prop->lib_name); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4118 | continue; |
| 4119 | } |
Jon Ashburn | 21c21ee | 2015-09-09 11:29:24 -0600 | [diff] [blame] | 4120 | } |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4121 | if ((fpGDPA = layer_prop->functions.get_device_proc_addr) == NULL) { |
Jamie Madill | c3d3f07 | 2016-12-14 17:21:43 -0500 | [diff] [blame] | 4122 | if (strlen(layer_prop->functions.str_gdpa) == 0) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4123 | fpGDPA = (PFN_vkGetDeviceProcAddr) |
| 4124 | loader_platform_get_proc_address(lib_handle, |
| 4125 | "vkGetDeviceProcAddr"); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4126 | layer_prop->functions.get_device_proc_addr = fpGDPA; |
| 4127 | } else |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4128 | fpGDPA = (PFN_vkGetDeviceProcAddr) |
| 4129 | loader_platform_get_proc_address( |
| 4130 | lib_handle, layer_prop->functions.str_gdpa); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4131 | if (!fpGDPA) { |
Jon Ashburn | c0dc07c | 2016-05-16 17:35:43 -0600 | [diff] [blame] | 4132 | loader_log(inst, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4133 | "Failed to find vkGetDeviceProcAddr in layer %s", |
| 4134 | layer_prop->lib_name); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4135 | continue; |
| 4136 | } |
| 4137 | } |
| 4138 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4139 | layer_device_link_info[activated_layers].pNext = |
| 4140 | chain_info.u.pLayerInfo; |
| 4141 | layer_device_link_info[activated_layers] |
| 4142 | .pfnNextGetInstanceProcAddr = nextGIPA; |
| 4143 | layer_device_link_info[activated_layers].pfnNextGetDeviceProcAddr = |
| 4144 | nextGDPA; |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4145 | chain_info.u.pLayerInfo = &layer_device_link_info[activated_layers]; |
| 4146 | nextGIPA = fpGIPA; |
| 4147 | nextGDPA = fpGDPA; |
| 4148 | |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 4149 | loader_log(inst, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4150 | "Insert device layer %s (%s)", |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4151 | layer_prop->info.layerName, layer_prop->lib_name); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4152 | |
| 4153 | activated_layers++; |
Jon Ashburn | 94e7049 | 2015-06-10 10:13:10 -0600 | [diff] [blame] | 4154 | } |
Jon Ashburn | 94e7049 | 2015-06-10 10:13:10 -0600 | [diff] [blame] | 4155 | } |
| 4156 | |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 4157 | VkDevice created_device = (VkDevice)dev; |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4158 | PFN_vkCreateDevice fpCreateDevice = |
Jon Ashburn | 4e8c416 | 2016-03-08 15:21:30 -0700 | [diff] [blame] | 4159 | (PFN_vkCreateDevice)nextGIPA(inst->instance, "vkCreateDevice"); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4160 | if (fpCreateDevice) { |
Jon Ashburn | ed8f231 | 2016-03-31 10:52:22 -0600 | [diff] [blame] | 4161 | VkLayerDeviceCreateInfo create_info_disp; |
| 4162 | |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 4163 | create_info_disp.sType = VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO; |
Jon Ashburn | ed8f231 | 2016-03-31 10:52:22 -0600 | [diff] [blame] | 4164 | create_info_disp.function = VK_LOADER_DATA_CALLBACK; |
| 4165 | |
| 4166 | create_info_disp.u.pfnSetDeviceLoaderData = vkSetDeviceDispatch; |
| 4167 | |
| 4168 | create_info_disp.pNext = loader_create_info.pNext; |
| 4169 | loader_create_info.pNext = &create_info_disp; |
Jon Ashburn | 014438f | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 4170 | res = fpCreateDevice(pd->phys_dev, &loader_create_info, pAllocator, |
Jon Ashburn | 72690f2 | 2016-03-29 12:52:13 -0600 | [diff] [blame] | 4171 | &created_device); |
Piers Daniell | efbbfc1 | 2016-04-05 17:28:06 -0600 | [diff] [blame] | 4172 | if (res != VK_SUCCESS) { |
| 4173 | return res; |
| 4174 | } |
Mark Young | 65cb366 | 2016-11-07 13:27:02 -0700 | [diff] [blame] | 4175 | dev->chain_device = created_device; |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4176 | } else { |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4177 | loader_log( |
| 4178 | inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4179 | "loader_create_device_chain: Failed to find \'vkCreateDevice\' " |
| 4180 | "in layer %s"); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4181 | // Couldn't find CreateDevice function! |
| 4182 | return VK_ERROR_INITIALIZATION_FAILED; |
| 4183 | } |
Jon Ashburn | 94e7049 | 2015-06-10 10:13:10 -0600 | [diff] [blame] | 4184 | |
Mark Young | 65cb366 | 2016-11-07 13:27:02 -0700 | [diff] [blame] | 4185 | // Initialize device dispatch table |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4186 | loader_init_device_dispatch_table(&dev->loader_dispatch, nextGDPA, |
Mark Young | 65cb366 | 2016-11-07 13:27:02 -0700 | [diff] [blame] | 4187 | dev->chain_device); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4188 | |
| 4189 | return res; |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 4190 | } |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 4191 | |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 4192 | VkResult loader_validate_layers(const struct loader_instance *inst, |
| 4193 | const uint32_t layer_count, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4194 | const char *const *ppEnabledLayerNames, |
| 4195 | const struct loader_layer_list *list) { |
Courtney Goeltzenleuchter | 3b8c5ff | 2015-07-06 17:45:08 -0600 | [diff] [blame] | 4196 | struct loader_layer_properties *prop; |
| 4197 | |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 4198 | for (uint32_t i = 0; i < layer_count; i++) { |
Jon Ashburn | f2b4e38 | 2016-02-10 20:50:19 -0700 | [diff] [blame] | 4199 | VkStringErrorFlags result = |
| 4200 | vk_string_validate(MaxLoaderStringLength, ppEnabledLayerNames[i]); |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 4201 | if (result != VK_STRING_ERROR_NONE) { |
| 4202 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4203 | "loader_validate_layers: Device ppEnabledLayerNames " |
| 4204 | " contains string that is too long or is badly formed"); |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 4205 | return VK_ERROR_LAYER_NOT_PRESENT; |
| 4206 | } |
| 4207 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4208 | prop = loader_get_layer_property(ppEnabledLayerNames[i], list); |
Courtney Goeltzenleuchter | 3b8c5ff | 2015-07-06 17:45:08 -0600 | [diff] [blame] | 4209 | if (!prop) { |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4210 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4211 | "loader_validate_layers: Layer %d does not exist in " |
| 4212 | "the list of available layers", |
| 4213 | i); |
Courtney Goeltzenleuchter | 55659b7 | 2015-09-14 18:01:17 -0600 | [diff] [blame] | 4214 | return VK_ERROR_LAYER_NOT_PRESENT; |
Courtney Goeltzenleuchter | 3b8c5ff | 2015-07-06 17:45:08 -0600 | [diff] [blame] | 4215 | } |
| 4216 | } |
Courtney Goeltzenleuchter | 3b8c5ff | 2015-07-06 17:45:08 -0600 | [diff] [blame] | 4217 | return VK_SUCCESS; |
| 4218 | } |
| 4219 | |
| 4220 | VkResult loader_validate_instance_extensions( |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 4221 | const struct loader_instance *inst, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4222 | const struct loader_extension_list *icd_exts, |
Michael Jurka | 5c16c00 | 2016-12-19 16:31:43 +0100 | [diff] [blame] | 4223 | const struct loader_layer_list *instance_layers, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4224 | const VkInstanceCreateInfo *pCreateInfo) { |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 4225 | |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 4226 | VkExtensionProperties *extension_prop; |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 4227 | struct loader_layer_properties *layer_prop; |
| 4228 | |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 4229 | for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) { |
Jon Ashburn | f2b4e38 | 2016-02-10 20:50:19 -0700 | [diff] [blame] | 4230 | VkStringErrorFlags result = vk_string_validate( |
| 4231 | MaxLoaderStringLength, pCreateInfo->ppEnabledExtensionNames[i]); |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 4232 | if (result != VK_STRING_ERROR_NONE) { |
| 4233 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4234 | "loader_validate_instance_extensions: Instance " |
| 4235 | "ppEnabledExtensionNames contains " |
Jon Ashburn | f2b4e38 | 2016-02-10 20:50:19 -0700 | [diff] [blame] | 4236 | "string that is too long or is badly formed"); |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 4237 | return VK_ERROR_EXTENSION_NOT_PRESENT; |
| 4238 | } |
| 4239 | |
Lenny Komow | 4053b81 | 2016-12-29 16:27:28 -0700 | [diff] [blame] | 4240 | // See if the extension is in the list of supported extensions |
| 4241 | bool found = false; |
| 4242 | for (uint32_t j = 0; LOADER_INSTANCE_EXTENSIONS[j] != NULL; j++) { |
| 4243 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], |
| 4244 | LOADER_INSTANCE_EXTENSIONS[j]) == 0) { |
| 4245 | found = true; |
| 4246 | break; |
| 4247 | } |
| 4248 | } |
| 4249 | |
| 4250 | // If it isn't in the list, return an error |
| 4251 | if (!found) { |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4252 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4253 | "loader_validate_instance_extensions: Extension %d " |
| 4254 | "not found in list of available extensions.", |
| 4255 | i); |
Lenny Komow | 4053b81 | 2016-12-29 16:27:28 -0700 | [diff] [blame] | 4256 | return VK_ERROR_EXTENSION_NOT_PRESENT; |
| 4257 | } |
| 4258 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4259 | extension_prop = get_extension_property( |
| 4260 | pCreateInfo->ppEnabledExtensionNames[i], icd_exts); |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 4261 | |
| 4262 | if (extension_prop) { |
| 4263 | continue; |
| 4264 | } |
| 4265 | |
| 4266 | extension_prop = NULL; |
| 4267 | |
| 4268 | /* Not in global list, search layer extension lists */ |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 4269 | for (uint32_t j = 0; j < pCreateInfo->enabledLayerCount; j++) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4270 | layer_prop = loader_get_layer_property( |
Michael Jurka | 5c16c00 | 2016-12-19 16:31:43 +0100 | [diff] [blame] | 4271 | pCreateInfo->ppEnabledLayerNames[j], instance_layers); |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 4272 | if (!layer_prop) { |
Courtney Goeltzenleuchter | 6f5b00c | 2015-07-06 20:46:50 -0600 | [diff] [blame] | 4273 | /* Should NOT get here, loader_validate_layers |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 4274 | * should have already filtered this case out. |
| 4275 | */ |
| 4276 | continue; |
| 4277 | } |
| 4278 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4279 | extension_prop = |
| 4280 | get_extension_property(pCreateInfo->ppEnabledExtensionNames[i], |
| 4281 | &layer_prop->instance_extension_list); |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 4282 | if (extension_prop) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4283 | /* Found the extension in one of the layers enabled by the app. |
| 4284 | */ |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 4285 | break; |
| 4286 | } |
| 4287 | } |
| 4288 | |
| 4289 | if (!extension_prop) { |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4290 | // Didn't find extension name in any of the global layers, error out |
| 4291 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4292 | "loader_validate_instance_extensions: Extension %d " |
| 4293 | "not found in enabled layer list extensions.", |
| 4294 | i); |
Courtney Goeltzenleuchter | 55659b7 | 2015-09-14 18:01:17 -0600 | [diff] [blame] | 4295 | return VK_ERROR_EXTENSION_NOT_PRESENT; |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 4296 | } |
| 4297 | } |
| 4298 | return VK_SUCCESS; |
| 4299 | } |
| 4300 | |
| 4301 | VkResult loader_validate_device_extensions( |
Jon Ashburn | 787eb25 | 2016-03-24 15:49:57 -0600 | [diff] [blame] | 4302 | struct loader_physical_device_tramp *phys_dev, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4303 | const struct loader_layer_list *activated_device_layers, |
Jon Ashburn | 014438f | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 4304 | const struct loader_extension_list *icd_exts, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4305 | const VkDeviceCreateInfo *pCreateInfo) { |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 4306 | VkExtensionProperties *extension_prop; |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 4307 | struct loader_layer_properties *layer_prop; |
| 4308 | |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 4309 | for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) { |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 4310 | |
Jon Ashburn | f2b4e38 | 2016-02-10 20:50:19 -0700 | [diff] [blame] | 4311 | VkStringErrorFlags result = vk_string_validate( |
| 4312 | MaxLoaderStringLength, pCreateInfo->ppEnabledExtensionNames[i]); |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 4313 | if (result != VK_STRING_ERROR_NONE) { |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 4314 | loader_log(phys_dev->this_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4315 | 0, "loader_validate_device_extensions: Device " |
| 4316 | "ppEnabledExtensionNames contains " |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 4317 | "string that is too long or is badly formed"); |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 4318 | return VK_ERROR_EXTENSION_NOT_PRESENT; |
| 4319 | } |
| 4320 | |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 4321 | const char *extension_name = pCreateInfo->ppEnabledExtensionNames[i]; |
Jon Ashburn | 014438f | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 4322 | extension_prop = get_extension_property(extension_name, icd_exts); |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 4323 | |
| 4324 | if (extension_prop) { |
| 4325 | continue; |
| 4326 | } |
| 4327 | |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4328 | // Not in global list, search activated layer extension lists |
Jon Ashburn | 471f44c | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 4329 | for (uint32_t j = 0; j < activated_device_layers->count; j++) { |
| 4330 | layer_prop = &activated_device_layers->list[j]; |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 4331 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4332 | extension_prop = get_dev_extension_property( |
| 4333 | extension_name, &layer_prop->device_extension_list); |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 4334 | if (extension_prop) { |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4335 | // Found the extension in one of the layers enabled by the app. |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 4336 | break; |
| 4337 | } |
| 4338 | } |
| 4339 | |
| 4340 | if (!extension_prop) { |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4341 | // Didn't find extension name in any of the device layers, error out |
| 4342 | loader_log(phys_dev->this_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4343 | 0, "loader_validate_device_extensions: Extension %d " |
| 4344 | "not found in enabled layer list extensions.", |
| 4345 | i); |
Courtney Goeltzenleuchter | 55659b7 | 2015-09-14 18:01:17 -0600 | [diff] [blame] | 4346 | return VK_ERROR_EXTENSION_NOT_PRESENT; |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 4347 | } |
| 4348 | } |
Courtney Goeltzenleuchter | 3b8c5ff | 2015-07-06 17:45:08 -0600 | [diff] [blame] | 4349 | return VK_SUCCESS; |
| 4350 | } |
| 4351 | |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4352 | // Terminator functions for the Instance chain |
| 4353 | // All named terminator_<Vulakn API name> |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4354 | VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateInstance( |
| 4355 | const VkInstanceCreateInfo *pCreateInfo, |
| 4356 | const VkAllocationCallbacks *pAllocator, VkInstance *pInstance) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4357 | struct loader_icd_term *icd_term; |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 4358 | VkExtensionProperties *prop; |
Courtney Goeltzenleuchter | 746db73 | 2015-07-06 17:42:01 -0600 | [diff] [blame] | 4359 | char **filtered_extension_names = NULL; |
| 4360 | VkInstanceCreateInfo icd_create_info; |
Courtney Goeltzenleuchter | 40caf0b | 2015-07-06 09:06:34 -0600 | [diff] [blame] | 4361 | VkResult res = VK_SUCCESS; |
Mark Young | 8b4edb5 | 2016-11-11 09:31:55 -0700 | [diff] [blame] | 4362 | bool one_icd_successful = false; |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 4363 | |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 4364 | struct loader_instance *ptr_instance = (struct loader_instance *)*pInstance; |
Tony Barbour | 3c78ff4 | 2015-12-04 13:24:39 -0700 | [diff] [blame] | 4365 | memcpy(&icd_create_info, pCreateInfo, sizeof(icd_create_info)); |
| 4366 | |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 4367 | icd_create_info.enabledLayerCount = 0; |
Courtney Goeltzenleuchter | 746db73 | 2015-07-06 17:42:01 -0600 | [diff] [blame] | 4368 | icd_create_info.ppEnabledLayerNames = NULL; |
Courtney Goeltzenleuchter | 746db73 | 2015-07-06 17:42:01 -0600 | [diff] [blame] | 4369 | |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4370 | // NOTE: Need to filter the extensions to only those supported by the ICD. |
| 4371 | // No ICD will advertise support for layers. An ICD library could |
| 4372 | // support a layer, but it would be independent of the actual ICD, |
| 4373 | // just in the same library. |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4374 | filtered_extension_names = |
| 4375 | loader_stack_alloc(pCreateInfo->enabledExtensionCount * sizeof(char *)); |
Courtney Goeltzenleuchter | 746db73 | 2015-07-06 17:42:01 -0600 | [diff] [blame] | 4376 | if (!filtered_extension_names) { |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4377 | loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4378 | "terminator_CreateInstance: Failed create extension name " |
| 4379 | "array for %d extensions", |
| 4380 | pCreateInfo->enabledExtensionCount); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 4381 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 4382 | goto out; |
Courtney Goeltzenleuchter | 746db73 | 2015-07-06 17:42:01 -0600 | [diff] [blame] | 4383 | } |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4384 | icd_create_info.ppEnabledExtensionNames = |
| 4385 | (const char *const *)filtered_extension_names; |
Courtney Goeltzenleuchter | 746db73 | 2015-07-06 17:42:01 -0600 | [diff] [blame] | 4386 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4387 | for (uint32_t i = 0; i < ptr_instance->icd_tramp_list.count; i++) { |
| 4388 | icd_term = loader_icd_add( |
| 4389 | ptr_instance, &ptr_instance->icd_tramp_list.scanned_list[i]); |
| 4390 | if (NULL == icd_term) { |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4391 | loader_log(icd_term->this_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4392 | 0, |
| 4393 | "terminator_CreateInstance: Failed to add ICD %d to ICD " |
| 4394 | "trampoline list.", |
| 4395 | i); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 4396 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 4397 | goto out; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4398 | } |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame^] | 4399 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4400 | icd_create_info.enabledExtensionCount = 0; |
| 4401 | struct loader_extension_list icd_exts; |
Courtney Goeltzenleuchter | 746db73 | 2015-07-06 17:42:01 -0600 | [diff] [blame] | 4402 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4403 | loader_log(ptr_instance, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, |
| 4404 | "Build ICD instance extension list"); |
| 4405 | // traverse scanned icd list adding non-duplicate extensions to the |
| 4406 | // list |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 4407 | res = loader_init_generic_list(ptr_instance, |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4408 | (struct loader_generic_list *)&icd_exts, |
| 4409 | sizeof(VkExtensionProperties)); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 4410 | if (VK_ERROR_OUT_OF_HOST_MEMORY == res) { |
| 4411 | // If out of memory, bail immediately. |
| 4412 | goto out; |
| 4413 | } else if (VK_SUCCESS != res) { |
Mark Young | 7e47129 | 2016-09-06 09:53:45 -0600 | [diff] [blame] | 4414 | // Something bad happened with this ICD, so free it and try the |
| 4415 | // next. |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4416 | ptr_instance->icd_terms = icd_term->next; |
| 4417 | icd_term->next = NULL; |
| 4418 | loader_icd_destroy(ptr_instance, icd_term, pAllocator); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 4419 | continue; |
| 4420 | } |
| 4421 | |
| 4422 | res = loader_add_instance_extensions( |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4423 | ptr_instance, |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4424 | icd_term->scanned_icd->EnumerateInstanceExtensionProperties, |
| 4425 | icd_term->scanned_icd->lib_name, &icd_exts); |
Mark Young | db13a2a | 2016-09-06 13:53:03 -0600 | [diff] [blame] | 4426 | if (VK_SUCCESS != res) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4427 | loader_destroy_generic_list( |
| 4428 | ptr_instance, (struct loader_generic_list *)&icd_exts); |
Mark Young | db13a2a | 2016-09-06 13:53:03 -0600 | [diff] [blame] | 4429 | if (VK_ERROR_OUT_OF_HOST_MEMORY == res) { |
| 4430 | // If out of memory, bail immediately. |
| 4431 | goto out; |
| 4432 | } else { |
| 4433 | // Something bad happened with this ICD, so free it and try |
| 4434 | // the next. |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4435 | ptr_instance->icd_terms = icd_term->next; |
| 4436 | icd_term->next = NULL; |
| 4437 | loader_icd_destroy(ptr_instance, icd_term, pAllocator); |
Mark Young | db13a2a | 2016-09-06 13:53:03 -0600 | [diff] [blame] | 4438 | continue; |
| 4439 | } |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 4440 | } |
Courtney Goeltzenleuchter | 36eeb74 | 2015-12-21 16:41:47 -0700 | [diff] [blame] | 4441 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4442 | for (uint32_t j = 0; j < pCreateInfo->enabledExtensionCount; j++) { |
| 4443 | prop = get_extension_property( |
| 4444 | pCreateInfo->ppEnabledExtensionNames[j], &icd_exts); |
| 4445 | if (prop) { |
| 4446 | filtered_extension_names[icd_create_info |
| 4447 | .enabledExtensionCount] = |
| 4448 | (char *)pCreateInfo->ppEnabledExtensionNames[j]; |
| 4449 | icd_create_info.enabledExtensionCount++; |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 4450 | } |
| 4451 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4452 | |
| 4453 | loader_destroy_generic_list(ptr_instance, |
| 4454 | (struct loader_generic_list *)&icd_exts); |
| 4455 | |
Mark Young | 8b4edb5 | 2016-11-11 09:31:55 -0700 | [diff] [blame] | 4456 | VkResult icd_result = |
| 4457 | ptr_instance->icd_tramp_list.scanned_list[i].CreateInstance( |
| 4458 | &icd_create_info, pAllocator, &(icd_term->instance)); |
| 4459 | if (VK_ERROR_OUT_OF_HOST_MEMORY == icd_result) { |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 4460 | // If out of memory, bail immediately. |
Mark Young | 8b4edb5 | 2016-11-11 09:31:55 -0700 | [diff] [blame] | 4461 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 4462 | goto out; |
Mark Young | 8b4edb5 | 2016-11-11 09:31:55 -0700 | [diff] [blame] | 4463 | } else if (VK_SUCCESS != icd_result) { |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 4464 | loader_log(ptr_instance, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4465 | "terminator_CreateInstance: Failed to CreateInstance in " |
| 4466 | "ICD %d. Skipping ICD.", |
| 4467 | i); |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4468 | ptr_instance->icd_terms = icd_term->next; |
| 4469 | icd_term->next = NULL; |
| 4470 | loader_icd_destroy(ptr_instance, icd_term, pAllocator); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 4471 | continue; |
| 4472 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4473 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4474 | if (!loader_icd_init_entrys(icd_term, icd_term->instance, |
| 4475 | ptr_instance->icd_tramp_list.scanned_list[i] |
| 4476 | .GetInstanceProcAddr)) { |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4477 | loader_log( |
| 4478 | ptr_instance, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 4479 | "terminator_CreateInstance: Failed to CreateInstance and find " |
| 4480 | "entrypoints with ICD. Skipping ICD."); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 4481 | continue; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4482 | } |
Mark Young | 8b4edb5 | 2016-11-11 09:31:55 -0700 | [diff] [blame] | 4483 | |
| 4484 | // If we made it this far, at least one ICD was successful |
| 4485 | one_icd_successful = true; |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 4486 | } |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 4487 | |
Mark Young | 8b4edb5 | 2016-11-11 09:31:55 -0700 | [diff] [blame] | 4488 | // If no ICDs were added to instance list and res is unchanged |
| 4489 | // from it's initial value, the loader was unable to find |
| 4490 | // a suitable ICD. |
| 4491 | if (VK_SUCCESS == res && |
| 4492 | (ptr_instance->icd_terms == NULL || !one_icd_successful)) { |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 4493 | res = VK_ERROR_INCOMPATIBLE_DRIVER; |
| 4494 | } |
| 4495 | |
| 4496 | out: |
| 4497 | |
| 4498 | if (VK_SUCCESS != res) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4499 | while (NULL != ptr_instance->icd_terms) { |
| 4500 | icd_term = ptr_instance->icd_terms; |
| 4501 | ptr_instance->icd_terms = icd_term->next; |
| 4502 | if (NULL != icd_term->instance) { |
| 4503 | icd_term->DestroyInstance(icd_term->instance, pAllocator); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 4504 | } |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4505 | loader_icd_destroy(ptr_instance, icd_term, pAllocator); |
Courtney Goeltzenleuchter | 40caf0b | 2015-07-06 09:06:34 -0600 | [diff] [blame] | 4506 | } |
Ian Elliott | eb45076 | 2015-02-05 15:19:15 -0700 | [diff] [blame] | 4507 | } |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 4508 | |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 4509 | return res; |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 4510 | } |
| 4511 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4512 | VKAPI_ATTR void VKAPI_CALL terminator_DestroyInstance( |
| 4513 | VkInstance instance, const VkAllocationCallbacks *pAllocator) { |
Courtney Goeltzenleuchter | deceded | 2015-06-08 15:04:02 -0600 | [diff] [blame] | 4514 | struct loader_instance *ptr_instance = loader_instance(instance); |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4515 | struct loader_icd_term *icd_terms = ptr_instance->icd_terms; |
| 4516 | struct loader_icd_term *next_icd_term; |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 4517 | |
| 4518 | // Remove this instance from the list of instances: |
| 4519 | struct loader_instance *prev = NULL; |
| 4520 | struct loader_instance *next = loader.instances; |
| 4521 | while (next != NULL) { |
| 4522 | if (next == ptr_instance) { |
| 4523 | // Remove this instance from the list: |
| 4524 | if (prev) |
| 4525 | prev->next = next->next; |
Jon Ashburn | c5c4960 | 2015-02-03 09:26:59 -0700 | [diff] [blame] | 4526 | else |
| 4527 | loader.instances = next->next; |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 4528 | break; |
| 4529 | } |
| 4530 | prev = next; |
| 4531 | next = next->next; |
| 4532 | } |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 4533 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4534 | while (NULL != icd_terms) { |
| 4535 | if (icd_terms->instance) { |
| 4536 | icd_terms->DestroyInstance(icd_terms->instance, pAllocator); |
Tony Barbour | f20f87b | 2015-04-22 09:02:32 -0600 | [diff] [blame] | 4537 | } |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4538 | next_icd_term = icd_terms->next; |
| 4539 | icd_terms->instance = VK_NULL_HANDLE; |
| 4540 | loader_icd_destroy(ptr_instance, icd_terms, pAllocator); |
Jon Ashburn | a6fd261 | 2015-06-16 14:43:19 -0600 | [diff] [blame] | 4541 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4542 | icd_terms = next_icd_term; |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 4543 | } |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 4544 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4545 | loader_delete_layer_properties(ptr_instance, |
| 4546 | &ptr_instance->instance_layer_list); |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4547 | loader_scanned_icd_clear(ptr_instance, &ptr_instance->icd_tramp_list); |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4548 | loader_destroy_generic_list( |
| 4549 | ptr_instance, (struct loader_generic_list *)&ptr_instance->ext_list); |
Lenny Komow | 8a1f8a5 | 2016-12-20 15:35:11 -0700 | [diff] [blame] | 4550 | if (ptr_instance->phys_devs_term) { |
Mark Young | 0193d65 | 2016-12-28 16:10:10 -0700 | [diff] [blame] | 4551 | 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] | 4552 | loader_instance_heap_free(ptr_instance, |
| 4553 | ptr_instance->phys_devs_term[i]); |
| 4554 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4555 | loader_instance_heap_free(ptr_instance, ptr_instance->phys_devs_term); |
Lenny Komow | 8a1f8a5 | 2016-12-20 15:35:11 -0700 | [diff] [blame] | 4556 | } |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 4557 | loader_free_dev_ext_table(ptr_instance); |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 4558 | } |
| 4559 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4560 | VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateDevice( |
| 4561 | VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo *pCreateInfo, |
| 4562 | const VkAllocationCallbacks *pAllocator, VkDevice *pDevice) { |
| 4563 | VkResult res = VK_SUCCESS; |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4564 | struct loader_physical_device_term *phys_dev_term; |
| 4565 | phys_dev_term = (struct loader_physical_device_term *)physicalDevice; |
| 4566 | struct loader_icd_term *icd_term = phys_dev_term->this_icd_term; |
Jon Ashburn | 24cd4be | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 4567 | |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 4568 | struct loader_device *dev = (struct loader_device *)*pDevice; |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4569 | PFN_vkCreateDevice fpCreateDevice = icd_term->CreateDevice; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4570 | struct loader_extension_list icd_exts; |
| 4571 | |
Mark Young | 65cb366 | 2016-11-07 13:27:02 -0700 | [diff] [blame] | 4572 | dev->phys_dev_term = phys_dev_term; |
| 4573 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4574 | icd_exts.list = NULL; |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 4575 | |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 4576 | if (fpCreateDevice == NULL) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4577 | 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] | 4578 | "terminator_CreateDevice: No vkCreateDevice command exposed " |
| 4579 | "by ICD %s", |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4580 | icd_term->scanned_icd->lib_name); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4581 | res = VK_ERROR_INITIALIZATION_FAILED; |
| 4582 | goto out; |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 4583 | } |
| 4584 | |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 4585 | VkDeviceCreateInfo localCreateInfo; |
| 4586 | memcpy(&localCreateInfo, pCreateInfo, sizeof(localCreateInfo)); |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 4587 | |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4588 | // NOTE: Need to filter the extensions to only those supported by the ICD. |
| 4589 | // No ICD will advertise support for layers. An ICD library could |
| 4590 | // support a layer, but it would be independent of the actual ICD, |
| 4591 | // just in the same library. |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 4592 | char **filtered_extension_names = NULL; |
| 4593 | filtered_extension_names = |
| 4594 | loader_stack_alloc(pCreateInfo->enabledExtensionCount * sizeof(char *)); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4595 | if (NULL == filtered_extension_names) { |
| 4596 | loader_log(icd_term->this_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4597 | "terminator_CreateDevice: Failed to create extension name " |
| 4598 | "storage for %d extensions %d", |
| 4599 | pCreateInfo->enabledExtensionCount); |
Jon Ashburn | 24cd4be | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 4600 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 4601 | } |
| 4602 | |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 4603 | localCreateInfo.enabledLayerCount = 0; |
| 4604 | localCreateInfo.ppEnabledLayerNames = NULL; |
| 4605 | |
| 4606 | localCreateInfo.enabledExtensionCount = 0; |
| 4607 | localCreateInfo.ppEnabledExtensionNames = |
| 4608 | (const char *const *)filtered_extension_names; |
| 4609 | |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4610 | // Get the physical device (ICD) extensions |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4611 | res = loader_init_generic_list(icd_term->this_instance, |
| 4612 | (struct loader_generic_list *)&icd_exts, |
| 4613 | sizeof(VkExtensionProperties)); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 4614 | if (VK_SUCCESS != res) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4615 | goto out; |
Jon Ashburn | 014438f | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 4616 | } |
| 4617 | |
| 4618 | res = loader_add_device_extensions( |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4619 | icd_term->this_instance, icd_term->EnumerateDeviceExtensionProperties, |
| 4620 | 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] | 4621 | if (res != VK_SUCCESS) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4622 | goto out; |
Jon Ashburn | 014438f | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 4623 | } |
| 4624 | |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 4625 | for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) { |
| 4626 | const char *extension_name = pCreateInfo->ppEnabledExtensionNames[i]; |
Jon Ashburn | 014438f | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 4627 | VkExtensionProperties *prop = |
| 4628 | get_extension_property(extension_name, &icd_exts); |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 4629 | if (prop) { |
| 4630 | filtered_extension_names[localCreateInfo.enabledExtensionCount] = |
| 4631 | (char *)extension_name; |
| 4632 | localCreateInfo.enabledExtensionCount++; |
Mark Young | 9a3ddd4 | 2016-10-21 16:25:47 -0600 | [diff] [blame] | 4633 | } else { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4634 | loader_log(icd_term->this_instance, VK_DEBUG_REPORT_WARNING_BIT_EXT, |
| 4635 | 0, "vkCreateDevice extension %s not available for " |
| 4636 | "devices associated with ICD %s", |
| 4637 | extension_name, icd_term->scanned_icd->lib_name); |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 4638 | } |
| 4639 | } |
| 4640 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4641 | res = fpCreateDevice(phys_dev_term->phys_dev, &localCreateInfo, pAllocator, |
Mark Young | 65cb366 | 2016-11-07 13:27:02 -0700 | [diff] [blame] | 4642 | &dev->icd_device); |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 4643 | if (res != VK_SUCCESS) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4644 | 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] | 4645 | "terminator_CreateDevice: Failed in ICD %s vkCreateDevice" |
| 4646 | "call", |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4647 | icd_term->scanned_icd->lib_name); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4648 | goto out; |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 4649 | } |
| 4650 | |
Mark Young | 65cb366 | 2016-11-07 13:27:02 -0700 | [diff] [blame] | 4651 | *pDevice = dev->icd_device; |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4652 | loader_add_logical_device(icd_term->this_instance, icd_term, dev); |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 4653 | |
| 4654 | /* Init dispatch pointer in new device object */ |
| 4655 | loader_init_dispatch(*pDevice, &dev->loader_dispatch); |
| 4656 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4657 | out: |
| 4658 | if (NULL != icd_exts.list) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4659 | loader_destroy_generic_list(icd_term->this_instance, |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4660 | (struct loader_generic_list *)&icd_exts); |
| 4661 | } |
| 4662 | |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 4663 | return res; |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 4664 | } |
| 4665 | |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame^] | 4666 | VkResult setupLoaderTrampPhysDevs(VkInstance instance) { |
Jon Ashburn | 24cd4be | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 4667 | VkResult res = VK_SUCCESS; |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame^] | 4668 | VkPhysicalDevice *local_phys_devs = NULL; |
| 4669 | struct loader_instance *inst; |
| 4670 | uint32_t total_count = 0; |
| 4671 | struct loader_physical_device_tramp **new_phys_devs = NULL; |
Jon Ashburn | 4c392fb | 2015-01-28 19:57:09 -0700 | [diff] [blame] | 4672 | |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame^] | 4673 | inst = loader_get_instance(instance); |
| 4674 | if (NULL == inst) { |
| 4675 | res = VK_ERROR_INITIALIZATION_FAILED; |
| 4676 | goto out; |
| 4677 | } |
| 4678 | total_count = inst->total_gpu_count; |
| 4679 | |
| 4680 | // Create an array for the new physical devices, which will be stored |
| 4681 | // in the instance for the trampoline code. |
| 4682 | new_phys_devs = |
| 4683 | (struct loader_physical_device_tramp **)loader_instance_heap_alloc( |
| 4684 | inst, |
| 4685 | total_count * sizeof(struct loader_physical_device_tramp *), |
| 4686 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
| 4687 | if (NULL == new_phys_devs) { |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4688 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame^] | 4689 | "setupLoaderTrampPhysDevs: Failed to new physical device " |
| 4690 | "array of size %d", |
| 4691 | total_count); |
Mark Young | d8382d7 | 2016-12-23 16:59:58 -0700 | [diff] [blame] | 4692 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 4693 | goto out; |
| 4694 | } |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame^] | 4695 | memset(new_phys_devs, 0, |
| 4696 | total_count * sizeof(struct loader_physical_device_tramp *)); |
Jon Ashburn | 014438f | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 4697 | |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame^] | 4698 | // Create a temporary array (on the stack) to keep track of the |
| 4699 | // returned VkPhysicalDevice values. |
| 4700 | local_phys_devs = |
| 4701 | loader_stack_alloc(sizeof(VkPhysicalDevice) * total_count); |
| 4702 | if (NULL == local_phys_devs) { |
| 4703 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4704 | "setupLoaderTrampPhysDevs: Failed to allocate local " |
| 4705 | "physical device array of size %d", |
| 4706 | total_count); |
| 4707 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 4708 | goto out; |
| 4709 | } |
| 4710 | memset(local_phys_devs, 0, sizeof(VkPhysicalDevice) * total_count); |
| 4711 | |
| 4712 | res = inst->disp->EnumeratePhysicalDevices(instance, &total_count, |
| 4713 | local_phys_devs); |
| 4714 | if (VK_SUCCESS != res) { |
| 4715 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4716 | "setupLoaderTrampPhysDevs: Failed during dispatch call " |
| 4717 | "of \'vkEnumeratePhysicalDevices\' to lower layers or " |
| 4718 | "loader."); |
| 4719 | goto out; |
| 4720 | } |
| 4721 | |
| 4722 | // Copy or create everything to fill the new array of physical devices |
| 4723 | for (uint32_t new_idx = 0; new_idx < total_count; new_idx++) { |
| 4724 | |
| 4725 | // Check if this physical device is already in the old buffer |
| 4726 | for (uint32_t old_idx = 0; |
| 4727 | old_idx < inst->phys_dev_count_tramp; |
| 4728 | old_idx++) { |
| 4729 | if (local_phys_devs[new_idx] == |
| 4730 | inst->phys_devs_tramp[old_idx]->phys_dev) { |
| 4731 | new_phys_devs[new_idx] = inst->phys_devs_tramp[old_idx]; |
| 4732 | break; |
| 4733 | } |
Mark Young | d8382d7 | 2016-12-23 16:59:58 -0700 | [diff] [blame] | 4734 | } |
| 4735 | |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame^] | 4736 | // If this physical device isn't in the old buffer, create it |
| 4737 | if (NULL == new_phys_devs[new_idx]) { |
| 4738 | new_phys_devs[new_idx] = (struct loader_physical_device_tramp *) |
| 4739 | loader_instance_heap_alloc( |
| 4740 | inst, sizeof(struct loader_physical_device_tramp), |
| 4741 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
| 4742 | if (NULL == new_phys_devs[new_idx]) { |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4743 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame^] | 4744 | "setupLoaderTrampPhysDevs: Failed to allocate " |
| 4745 | "physical device trampoline object %d", |
| 4746 | new_idx); |
| 4747 | total_count = new_idx; |
Mark Young | d8382d7 | 2016-12-23 16:59:58 -0700 | [diff] [blame] | 4748 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 4749 | goto out; |
| 4750 | } |
| 4751 | |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame^] | 4752 | // Initialize the new physicalDevice object |
| 4753 | loader_set_dispatch((void *)new_phys_devs[new_idx], inst->disp); |
| 4754 | new_phys_devs[new_idx]->this_instance = inst; |
| 4755 | new_phys_devs[new_idx]->phys_dev = local_phys_devs[new_idx]; |
Mark Young | 559d750 | 2016-09-26 11:38:46 -0600 | [diff] [blame] | 4756 | } |
Lenny Komow | a5e0112 | 2016-12-22 15:29:43 -0700 | [diff] [blame] | 4757 | } |
Mark Young | 559d750 | 2016-09-26 11:38:46 -0600 | [diff] [blame] | 4758 | |
Lenny Komow | a5e0112 | 2016-12-22 15:29:43 -0700 | [diff] [blame] | 4759 | out: |
Mark Young | d8382d7 | 2016-12-23 16:59:58 -0700 | [diff] [blame] | 4760 | |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame^] | 4761 | if (VK_SUCCESS != res) { |
| 4762 | if (NULL != new_phys_devs) { |
| 4763 | for (uint32_t i = 0; i < total_count; i++) { |
| 4764 | loader_instance_heap_free(inst, new_phys_devs[i]); |
Lenny Komow | a5e0112 | 2016-12-22 15:29:43 -0700 | [diff] [blame] | 4765 | } |
| 4766 | loader_instance_heap_free(inst, new_phys_devs); |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame^] | 4767 | } |
| 4768 | total_count = 0; |
| 4769 | } else { |
| 4770 | // Free everything that didn't carry over to the new array of |
| 4771 | // physical devices |
| 4772 | if (NULL != inst->phys_devs_tramp) { |
| 4773 | for (uint32_t i = 0; i < inst->phys_dev_count_tramp; i++) { |
| 4774 | bool found = false; |
| 4775 | for (uint32_t j = 0; j < total_count; j++) { |
| 4776 | if (inst->phys_devs_tramp[i] == new_phys_devs[j]) { |
| 4777 | found = true; |
| 4778 | break; |
| 4779 | } |
| 4780 | } |
| 4781 | if (!found) { |
| 4782 | loader_instance_heap_free(inst, |
| 4783 | inst->phys_devs_tramp[i]); |
| 4784 | } |
| 4785 | } |
| 4786 | loader_instance_heap_free(inst, inst->phys_devs_tramp); |
| 4787 | } |
Mark Young | d8382d7 | 2016-12-23 16:59:58 -0700 | [diff] [blame] | 4788 | |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame^] | 4789 | // Swap in the new physical device list |
| 4790 | inst->phys_dev_count_tramp = total_count; |
| 4791 | inst->phys_devs_tramp = new_phys_devs; |
| 4792 | } |
| 4793 | |
| 4794 | return res; |
| 4795 | } |
| 4796 | |
| 4797 | VkResult setupLoaderTermPhysDevs(struct loader_instance *inst) { |
| 4798 | VkResult res = VK_SUCCESS; |
| 4799 | struct loader_icd_term *icd_term; |
| 4800 | struct loader_phys_dev_per_icd *icd_phys_dev_array = NULL; |
| 4801 | struct loader_physical_device_term **new_phys_devs = NULL; |
| 4802 | uint32_t i = 0; |
| 4803 | |
| 4804 | inst->total_gpu_count = 0; |
| 4805 | |
| 4806 | // Allocate something to store the physical device characteristics |
| 4807 | // that we read from each ICD. |
| 4808 | icd_phys_dev_array = (struct loader_phys_dev_per_icd *)loader_stack_alloc( |
| 4809 | sizeof(struct loader_phys_dev_per_icd) * inst->total_icd_count); |
| 4810 | if (NULL == icd_phys_dev_array) { |
| 4811 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4812 | "setupLoaderTermPhysDevs: Failed to allocate temporary " |
| 4813 | " ICD Physical device info array of size %d", |
| 4814 | inst->total_gpu_count); |
| 4815 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 4816 | goto out; |
| 4817 | } |
| 4818 | memset(icd_phys_dev_array, 0, |
| 4819 | sizeof(struct loader_phys_dev_per_icd) * inst->total_icd_count); |
| 4820 | icd_term = inst->icd_terms; |
| 4821 | |
| 4822 | // For each ICD, query the number of physical devices, and then get an |
| 4823 | // internal value for those physical devices. |
| 4824 | while (NULL != icd_term) { |
| 4825 | res = icd_term->EnumeratePhysicalDevices( |
| 4826 | icd_term->instance, &icd_phys_dev_array[i].count, NULL); |
| 4827 | if (VK_SUCCESS != res) { |
| 4828 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4829 | "setupLoaderTermPhysDevs: Call to " |
| 4830 | "ICD %d's \'vkEnumeratePhysicalDevices\' failed with" |
| 4831 | " error 0x%08x", |
| 4832 | i, res); |
| 4833 | goto out; |
| 4834 | } |
| 4835 | |
| 4836 | icd_phys_dev_array[i].phys_devs = |
| 4837 | (VkPhysicalDevice *)loader_stack_alloc(icd_phys_dev_array[i].count * |
| 4838 | sizeof(VkPhysicalDevice)); |
| 4839 | if (NULL == icd_phys_dev_array[i].phys_devs) { |
| 4840 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4841 | "setupLoaderTermPhysDevs: Failed to allocate temporary " |
| 4842 | " ICD Physical device array for ICD %d of size %d", |
| 4843 | i, inst->total_gpu_count); |
| 4844 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 4845 | goto out; |
| 4846 | } |
| 4847 | |
| 4848 | res = icd_term->EnumeratePhysicalDevices( |
| 4849 | icd_term->instance, &(icd_phys_dev_array[i].count), |
| 4850 | icd_phys_dev_array[i].phys_devs); |
| 4851 | if (VK_SUCCESS != res) { |
| 4852 | goto out; |
| 4853 | } |
| 4854 | inst->total_gpu_count += icd_phys_dev_array[i].count; |
| 4855 | icd_phys_dev_array[i].this_icd_term = icd_term; |
| 4856 | |
| 4857 | icd_term = icd_term->next; |
| 4858 | i++; |
| 4859 | } |
| 4860 | |
| 4861 | if (0 == inst->total_gpu_count) { |
| 4862 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4863 | "setupLoaderTermPhysDevs: Failed to detect any valid" |
| 4864 | " GPUs in the current config"); |
| 4865 | res = VK_ERROR_INITIALIZATION_FAILED; |
| 4866 | goto out; |
| 4867 | } |
| 4868 | |
| 4869 | new_phys_devs = loader_instance_heap_alloc( |
| 4870 | inst, |
| 4871 | sizeof(struct loader_physical_device_term *) * inst->total_gpu_count, |
| 4872 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
| 4873 | if (NULL == new_phys_devs) { |
| 4874 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4875 | "setupLoaderTermPhysDevs: Failed to allocate new physical" |
| 4876 | " device array of size %d", |
| 4877 | inst->total_gpu_count); |
| 4878 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 4879 | goto out; |
| 4880 | } |
| 4881 | memset(new_phys_devs, 0, sizeof(struct loader_physical_device_term *) * |
| 4882 | inst->total_gpu_count); |
| 4883 | |
| 4884 | // Copy or create everything to fill the new array of physical devices |
| 4885 | uint32_t idx = 0; |
| 4886 | for (uint32_t icd_idx = 0; icd_idx < inst->total_icd_count; icd_idx++) { |
| 4887 | for (uint32_t pd_idx = 0; pd_idx < icd_phys_dev_array[icd_idx].count; |
| 4888 | pd_idx++) { |
| 4889 | |
| 4890 | // Check if this physical device is already in the old buffer |
| 4891 | if (NULL != inst->phys_devs_term) { |
| 4892 | for (uint32_t old_idx = 0; |
| 4893 | old_idx < inst->phys_dev_count_term; |
| 4894 | old_idx++) { |
| 4895 | if (icd_phys_dev_array[icd_idx].phys_devs[pd_idx] == |
| 4896 | inst->phys_devs_term[old_idx]->phys_dev) { |
| 4897 | new_phys_devs[idx] = inst->phys_devs_term[old_idx]; |
| 4898 | break; |
| 4899 | } |
| 4900 | } |
| 4901 | } |
| 4902 | // If this physical device isn't in the old buffer, then we |
| 4903 | // need to create it. |
| 4904 | if (NULL == new_phys_devs[idx]) { |
| 4905 | new_phys_devs[idx] = loader_instance_heap_alloc( |
| 4906 | inst, sizeof(struct loader_physical_device_term), |
| 4907 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
| 4908 | if (NULL == new_phys_devs[idx]) { |
| 4909 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4910 | "setupLoaderTermPhysDevs: Failed to allocate " |
| 4911 | "physical device terminator object %d", |
| 4912 | idx); |
| 4913 | inst->total_gpu_count = idx; |
| 4914 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 4915 | goto out; |
| 4916 | } |
| 4917 | |
| 4918 | loader_set_dispatch((void *)new_phys_devs[idx], inst->disp); |
| 4919 | new_phys_devs[idx]->this_icd_term = |
| 4920 | icd_phys_dev_array[icd_idx].this_icd_term; |
| 4921 | new_phys_devs[idx]->icd_index = (uint8_t)(icd_idx); |
| 4922 | new_phys_devs[idx]->phys_dev = |
| 4923 | icd_phys_dev_array[icd_idx].phys_devs[pd_idx]; |
| 4924 | } |
| 4925 | idx++; |
| 4926 | } |
| 4927 | } |
| 4928 | |
| 4929 | out: |
| 4930 | |
| 4931 | if (VK_SUCCESS != res) { |
| 4932 | if (NULL != inst->phys_devs_term) { |
| 4933 | // We've encountered an error, so we should free the |
| 4934 | // new buffers. |
| 4935 | for (uint32_t i = 0; i < inst->total_gpu_count; i++) { |
| 4936 | loader_instance_heap_free(inst, new_phys_devs[i]); |
| 4937 | } |
| 4938 | loader_instance_heap_free(inst, inst->phys_devs_term); |
| 4939 | inst->total_gpu_count = 0; |
| 4940 | } |
| 4941 | } else { |
| 4942 | // Free everything that didn't carry over to the new array of |
| 4943 | // physical devices. Everything else will have been copied over |
| 4944 | // to the new array. |
| 4945 | if (NULL != inst->phys_devs_term) { |
| 4946 | for (uint32_t cur_pd = 0; cur_pd < inst->phys_dev_count_term; |
| 4947 | cur_pd++) { |
| 4948 | bool found = false; |
| 4949 | for (uint32_t new_pd_idx = 0; |
| 4950 | new_pd_idx < inst->total_gpu_count; |
| 4951 | new_pd_idx++) { |
| 4952 | if (inst->phys_devs_term[cur_pd] == |
| 4953 | new_phys_devs[new_pd_idx]) { |
| 4954 | found = true; |
| 4955 | break; |
| 4956 | } |
| 4957 | } |
| 4958 | if (!found) { |
| 4959 | loader_instance_heap_free(inst, |
| 4960 | inst->phys_devs_term[cur_pd]); |
| 4961 | } |
| 4962 | } |
| 4963 | loader_instance_heap_free(inst, inst->phys_devs_term); |
| 4964 | } |
| 4965 | |
| 4966 | // Swap out old and new devices list |
| 4967 | inst->phys_dev_count_term = inst->total_gpu_count; |
| 4968 | inst->phys_devs_term = new_phys_devs; |
| 4969 | } |
| 4970 | |
| 4971 | return res; |
| 4972 | } |
| 4973 | |
| 4974 | VKAPI_ATTR VkResult VKAPI_CALL terminator_EnumeratePhysicalDevices( |
| 4975 | VkInstance instance, uint32_t *pPhysicalDeviceCount, |
| 4976 | VkPhysicalDevice *pPhysicalDevices) { |
| 4977 | struct loader_instance *inst = (struct loader_instance *)instance; |
| 4978 | VkResult res = VK_SUCCESS; |
| 4979 | |
| 4980 | // Only do the setup if we're re-querying the number of devices, or |
| 4981 | // our count is currently 0. |
| 4982 | if (NULL == pPhysicalDevices || 0 == inst->total_gpu_count) { |
| 4983 | res = setupLoaderTermPhysDevs(inst); |
| 4984 | if (VK_SUCCESS != res) { |
| 4985 | goto out; |
| 4986 | } |
| 4987 | } |
| 4988 | |
| 4989 | uint32_t copy_count = inst->total_gpu_count; |
| 4990 | if (NULL != pPhysicalDevices) { |
| 4991 | if (copy_count > *pPhysicalDeviceCount) { |
| 4992 | copy_count = *pPhysicalDeviceCount; |
| 4993 | res = VK_INCOMPLETE; |
| 4994 | } |
| 4995 | |
| 4996 | for (uint32_t i = 0; i < copy_count; i++) { |
| 4997 | pPhysicalDevices[i] = (VkPhysicalDevice)inst->phys_devs_term[i]; |
Jon Ashburn | 014438f | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 4998 | } |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 4999 | } |
Mark Young | 559d750 | 2016-09-26 11:38:46 -0600 | [diff] [blame] | 5000 | |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 5001 | *pPhysicalDeviceCount = copy_count; |
| 5002 | |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame^] | 5003 | out: |
| 5004 | |
Jon Ashburn | 24cd4be | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 5005 | return res; |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 5006 | } |
| 5007 | |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 5008 | VKAPI_ATTR void VKAPI_CALL terminator_GetPhysicalDeviceProperties( |
| 5009 | VkPhysicalDevice physicalDevice, VkPhysicalDeviceProperties *pProperties) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5010 | struct loader_physical_device_term *phys_dev_term = |
| 5011 | (struct loader_physical_device_term *)physicalDevice; |
| 5012 | struct loader_icd_term *icd_term = phys_dev_term->this_icd_term; |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5013 | if (NULL != icd_term->GetPhysicalDeviceProperties) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5014 | icd_term->GetPhysicalDeviceProperties(phys_dev_term->phys_dev, |
| 5015 | pProperties); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5016 | } |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 5017 | } |
| 5018 | |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 5019 | VKAPI_ATTR void VKAPI_CALL terminator_GetPhysicalDeviceQueueFamilyProperties( |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 5020 | VkPhysicalDevice physicalDevice, uint32_t *pQueueFamilyPropertyCount, |
| 5021 | VkQueueFamilyProperties *pProperties) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5022 | struct loader_physical_device_term *phys_dev_term = |
| 5023 | (struct loader_physical_device_term *)physicalDevice; |
| 5024 | struct loader_icd_term *icd_term = phys_dev_term->this_icd_term; |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5025 | if (NULL != icd_term->GetPhysicalDeviceQueueFamilyProperties) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5026 | icd_term->GetPhysicalDeviceQueueFamilyProperties( |
| 5027 | phys_dev_term->phys_dev, pQueueFamilyPropertyCount, pProperties); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5028 | } |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 5029 | } |
| 5030 | |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 5031 | VKAPI_ATTR void VKAPI_CALL terminator_GetPhysicalDeviceMemoryProperties( |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 5032 | VkPhysicalDevice physicalDevice, |
| 5033 | VkPhysicalDeviceMemoryProperties *pProperties) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5034 | struct loader_physical_device_term *phys_dev_term = |
| 5035 | (struct loader_physical_device_term *)physicalDevice; |
| 5036 | struct loader_icd_term *icd_term = phys_dev_term->this_icd_term; |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5037 | if (NULL != icd_term->GetPhysicalDeviceMemoryProperties) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5038 | icd_term->GetPhysicalDeviceMemoryProperties(phys_dev_term->phys_dev, |
| 5039 | pProperties); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5040 | } |
Jon Ashburn | 3da71f2 | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 5041 | } |
| 5042 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5043 | VKAPI_ATTR void VKAPI_CALL terminator_GetPhysicalDeviceFeatures( |
| 5044 | VkPhysicalDevice physicalDevice, VkPhysicalDeviceFeatures *pFeatures) { |
| 5045 | struct loader_physical_device_term *phys_dev_term = |
| 5046 | (struct loader_physical_device_term *)physicalDevice; |
| 5047 | struct loader_icd_term *icd_term = phys_dev_term->this_icd_term; |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5048 | if (NULL != icd_term->GetPhysicalDeviceFeatures) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5049 | icd_term->GetPhysicalDeviceFeatures(phys_dev_term->phys_dev, pFeatures); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5050 | } |
Chris Forbes | bc0bb77 | 2015-06-21 22:55:02 +1200 | [diff] [blame] | 5051 | } |
| 5052 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5053 | VKAPI_ATTR void VKAPI_CALL terminator_GetPhysicalDeviceFormatProperties( |
| 5054 | VkPhysicalDevice physicalDevice, VkFormat format, |
| 5055 | VkFormatProperties *pFormatInfo) { |
| 5056 | struct loader_physical_device_term *phys_dev_term = |
| 5057 | (struct loader_physical_device_term *)physicalDevice; |
| 5058 | struct loader_icd_term *icd_term = phys_dev_term->this_icd_term; |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5059 | if (NULL != icd_term->GetPhysicalDeviceFormatProperties) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5060 | icd_term->GetPhysicalDeviceFormatProperties(phys_dev_term->phys_dev, |
| 5061 | format, pFormatInfo); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5062 | } |
Chris Forbes | bc0bb77 | 2015-06-21 22:55:02 +1200 | [diff] [blame] | 5063 | } |
| 5064 | |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 5065 | VKAPI_ATTR VkResult VKAPI_CALL |
| 5066 | terminator_GetPhysicalDeviceImageFormatProperties( |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 5067 | VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, |
| 5068 | VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags, |
| 5069 | VkImageFormatProperties *pImageFormatProperties) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5070 | struct loader_physical_device_term *phys_dev_term = |
| 5071 | (struct loader_physical_device_term *)physicalDevice; |
| 5072 | struct loader_icd_term *icd_term = phys_dev_term->this_icd_term; |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5073 | if (NULL == icd_term->GetPhysicalDeviceImageFormatProperties) { |
| 5074 | loader_log(icd_term->this_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 5075 | "Encountered the vkEnumerateDeviceLayerProperties " |
| 5076 | "terminator. This means a layer improperly continued."); |
Chia-I Wu | 1724104 | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 5077 | return VK_ERROR_INITIALIZATION_FAILED; |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5078 | } |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5079 | return icd_term->GetPhysicalDeviceImageFormatProperties( |
| 5080 | phys_dev_term->phys_dev, format, type, tiling, usage, flags, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 5081 | pImageFormatProperties); |
Jon Ashburn | 754864f | 2015-07-23 18:49:07 -0600 | [diff] [blame] | 5082 | } |
| 5083 | |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 5084 | VKAPI_ATTR void VKAPI_CALL |
| 5085 | terminator_GetPhysicalDeviceSparseImageFormatProperties( |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 5086 | VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, |
| 5087 | VkSampleCountFlagBits samples, VkImageUsageFlags usage, |
| 5088 | VkImageTiling tiling, uint32_t *pNumProperties, |
| 5089 | VkSparseImageFormatProperties *pProperties) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5090 | struct loader_physical_device_term *phys_dev_term = |
| 5091 | (struct loader_physical_device_term *)physicalDevice; |
| 5092 | struct loader_icd_term *icd_term = phys_dev_term->this_icd_term; |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5093 | if (NULL != icd_term->GetPhysicalDeviceSparseImageFormatProperties) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5094 | icd_term->GetPhysicalDeviceSparseImageFormatProperties( |
| 5095 | phys_dev_term->phys_dev, format, type, samples, usage, tiling, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 5096 | pNumProperties, pProperties); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5097 | } |
Mark Lobodzinski | 16e8bef | 2015-07-03 15:58:09 -0600 | [diff] [blame] | 5098 | } |
| 5099 | |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 5100 | VKAPI_ATTR VkResult VKAPI_CALL terminator_EnumerateDeviceExtensionProperties( |
| 5101 | VkPhysicalDevice physicalDevice, const char *pLayerName, |
| 5102 | uint32_t *pPropertyCount, VkExtensionProperties *pProperties) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5103 | struct loader_physical_device_term *phys_dev_term; |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 5104 | |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 5105 | struct loader_layer_list implicit_layer_list = {0}; |
| 5106 | struct loader_extension_list all_exts = {0}; |
| 5107 | struct loader_extension_list icd_exts = {0}; |
Jon Ashburn | 471f44c | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 5108 | |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 5109 | assert(pLayerName == NULL || strlen(pLayerName) == 0); |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 5110 | |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 5111 | /* Any layer or trampoline wrapping should be removed at this point in time |
| 5112 | * can just cast to the expected type for VkPhysicalDevice. */ |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5113 | phys_dev_term = (struct loader_physical_device_term *)physicalDevice; |
Jon Ashburn | 471f44c | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 5114 | |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 5115 | /* this case is during the call down the instance chain with pLayerName |
| 5116 | * == NULL*/ |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5117 | struct loader_icd_term *icd_term = phys_dev_term->this_icd_term; |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 5118 | uint32_t icd_ext_count = *pPropertyCount; |
| 5119 | VkResult res; |
Jon Ashburn | 471f44c | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 5120 | |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 5121 | /* get device extensions */ |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5122 | res = icd_term->EnumerateDeviceExtensionProperties( |
| 5123 | phys_dev_term->phys_dev, NULL, &icd_ext_count, pProperties); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 5124 | if (res != VK_SUCCESS) { |
| 5125 | goto out; |
| 5126 | } |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 5127 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5128 | if (!loader_init_layer_list(icd_term->this_instance, |
| 5129 | &implicit_layer_list)) { |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 5130 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 5131 | goto out; |
| 5132 | } |
Jon Ashburn | 471f44c | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 5133 | |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 5134 | loader_add_layer_implicit( |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5135 | icd_term->this_instance, VK_LAYER_TYPE_INSTANCE_IMPLICIT, |
| 5136 | &implicit_layer_list, &icd_term->this_instance->instance_layer_list); |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 5137 | /* we need to determine which implicit layers are active, |
| 5138 | * and then add their extensions. This can't be cached as |
| 5139 | * it depends on results of environment variables (which can change). |
| 5140 | */ |
| 5141 | if (pProperties != NULL) { |
| 5142 | /* initialize dev_extension list within the physicalDevice object */ |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5143 | res = loader_init_device_extensions(icd_term->this_instance, |
| 5144 | phys_dev_term, icd_ext_count, |
| 5145 | pProperties, &icd_exts); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 5146 | if (res != VK_SUCCESS) { |
| 5147 | goto out; |
| 5148 | } |
Jon Ashburn | 471f44c | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 5149 | |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 5150 | /* we need to determine which implicit layers are active, |
| 5151 | * and then add their extensions. This can't be cached as |
| 5152 | * it depends on results of environment variables (which can |
| 5153 | * change). |
| 5154 | */ |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5155 | res = loader_add_to_ext_list(icd_term->this_instance, &all_exts, |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 5156 | icd_exts.count, icd_exts.list); |
| 5157 | if (res != VK_SUCCESS) { |
| 5158 | goto out; |
| 5159 | } |
Jon Ashburn | 471f44c | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 5160 | |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 5161 | loader_add_layer_implicit( |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5162 | icd_term->this_instance, VK_LAYER_TYPE_INSTANCE_IMPLICIT, |
| 5163 | &implicit_layer_list, |
| 5164 | &icd_term->this_instance->instance_layer_list); |
Jon Ashburn | 471f44c | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 5165 | |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 5166 | for (uint32_t i = 0; i < implicit_layer_list.count; i++) { |
| 5167 | for (uint32_t j = 0; |
Jon Ashburn | 014438f | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 5168 | j < implicit_layer_list.list[i].device_extension_list.count; |
| 5169 | j++) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5170 | res = loader_add_to_ext_list(icd_term->this_instance, &all_exts, |
| 5171 | 1, |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 5172 | &implicit_layer_list.list[i] |
| 5173 | .device_extension_list.list[j] |
| 5174 | .props); |
| 5175 | if (res != VK_SUCCESS) { |
| 5176 | goto out; |
| 5177 | } |
Jon Ashburn | 471f44c | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 5178 | } |
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 | uint32_t capacity = *pPropertyCount; |
| 5181 | VkExtensionProperties *props = pProperties; |
Jon Ashburn | 471f44c | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 5182 | |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 5183 | for (uint32_t i = 0; i < all_exts.count && i < capacity; i++) { |
| 5184 | props[i] = all_exts.list[i]; |
| 5185 | } |
| 5186 | /* wasn't enough space for the extensions, we did partial copy now |
| 5187 | * return VK_INCOMPLETE */ |
| 5188 | if (capacity < all_exts.count) { |
| 5189 | res = VK_INCOMPLETE; |
| 5190 | } else { |
| 5191 | *pPropertyCount = all_exts.count; |
| 5192 | } |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 5193 | } else { |
| 5194 | /* just return the count; need to add in the count of implicit layer |
| 5195 | * extensions |
| 5196 | * don't worry about duplicates being added in the count */ |
| 5197 | *pPropertyCount = icd_ext_count; |
| 5198 | |
| 5199 | for (uint32_t i = 0; i < implicit_layer_list.count; i++) { |
| 5200 | *pPropertyCount += |
Jon Ashburn | 014438f | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 5201 | implicit_layer_list.list[i].device_extension_list.count; |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 5202 | } |
| 5203 | res = VK_SUCCESS; |
Jon Ashburn | b82c185 | 2015-08-11 14:49:54 -0600 | [diff] [blame] | 5204 | } |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 5205 | |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 5206 | out: |
| 5207 | |
| 5208 | if (NULL != implicit_layer_list.list) { |
| 5209 | loader_destroy_generic_list( |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5210 | icd_term->this_instance, |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 5211 | (struct loader_generic_list *)&implicit_layer_list); |
| 5212 | } |
| 5213 | if (NULL != all_exts.list) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5214 | loader_destroy_generic_list(icd_term->this_instance, |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 5215 | (struct loader_generic_list *)&all_exts); |
| 5216 | } |
| 5217 | if (NULL != icd_exts.list) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5218 | loader_destroy_generic_list(icd_term->this_instance, |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 5219 | (struct loader_generic_list *)&icd_exts); |
| 5220 | } |
| 5221 | |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 5222 | return res; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 5223 | } |
| 5224 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5225 | VKAPI_ATTR VkResult VKAPI_CALL terminator_EnumerateDeviceLayerProperties( |
| 5226 | VkPhysicalDevice physicalDevice, uint32_t *pPropertyCount, |
| 5227 | VkLayerProperties *pProperties) { |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5228 | struct loader_physical_device_term *phys_dev_term = |
| 5229 | (struct loader_physical_device_term *)physicalDevice; |
| 5230 | struct loader_icd_term *icd_term = phys_dev_term->this_icd_term; |
| 5231 | loader_log(icd_term->this_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 5232 | "Encountered the vkEnumerateDeviceLayerProperties " |
| 5233 | "terminator. This means a layer improperly continued."); |
| 5234 | // Should never get here this call isn't dispatched down the chain |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 5235 | return VK_ERROR_INITIALIZATION_FAILED; |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 5236 | } |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 5237 | |
Jon Ashburn | f2b4e38 | 2016-02-10 20:50:19 -0700 | [diff] [blame] | 5238 | VkStringErrorFlags vk_string_validate(const int max_length, const char *utf8) { |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 5239 | VkStringErrorFlags result = VK_STRING_ERROR_NONE; |
Karl Schultz | 2558bd3 | 2016-02-24 14:39:39 -0700 | [diff] [blame] | 5240 | int num_char_bytes = 0; |
Jon Ashburn | f2b4e38 | 2016-02-10 20:50:19 -0700 | [diff] [blame] | 5241 | int i, j; |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 5242 | |
Courtney Goeltzenleuchter | 7a3486d | 2016-12-21 16:24:34 -0700 | [diff] [blame] | 5243 | for (i = 0; i <= max_length; i++) { |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 5244 | if (utf8[i] == 0) { |
| 5245 | break; |
Courtney Goeltzenleuchter | 7a3486d | 2016-12-21 16:24:34 -0700 | [diff] [blame] | 5246 | } else if (i == max_length) { |
| 5247 | result |= VK_STRING_ERROR_LENGTH; |
| 5248 | break; |
Mark Lobodzinski | 36b4de2 | 2016-02-12 11:30:14 -0700 | [diff] [blame] | 5249 | } else if ((utf8[i] >= 0x20) && (utf8[i] < 0x7f)) { |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 5250 | num_char_bytes = 0; |
Jon Ashburn | f2b4e38 | 2016-02-10 20:50:19 -0700 | [diff] [blame] | 5251 | } else if ((utf8[i] & UTF8_ONE_BYTE_MASK) == UTF8_ONE_BYTE_CODE) { |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 5252 | num_char_bytes = 1; |
Jon Ashburn | f2b4e38 | 2016-02-10 20:50:19 -0700 | [diff] [blame] | 5253 | } else if ((utf8[i] & UTF8_TWO_BYTE_MASK) == UTF8_TWO_BYTE_CODE) { |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 5254 | num_char_bytes = 2; |
| 5255 | } else if ((utf8[i] & UTF8_THREE_BYTE_MASK) == UTF8_THREE_BYTE_CODE) { |
| 5256 | num_char_bytes = 3; |
| 5257 | } else { |
| 5258 | result = VK_STRING_ERROR_BAD_DATA; |
| 5259 | } |
| 5260 | |
| 5261 | // Validate the following num_char_bytes of data |
| 5262 | for (j = 0; (j < num_char_bytes) && (i < max_length); j++) { |
| 5263 | if (++i == max_length) { |
| 5264 | result |= VK_STRING_ERROR_LENGTH; |
| 5265 | break; |
| 5266 | } |
| 5267 | if ((utf8[i] & UTF8_DATA_BYTE_MASK) != UTF8_DATA_BYTE_CODE) { |
| 5268 | result |= VK_STRING_ERROR_BAD_DATA; |
| 5269 | } |
| 5270 | } |
| 5271 | } |
| 5272 | return result; |
| 5273 | } |