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