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