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