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