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; |
| 415 | struct loader_icd *icd = loader_get_icd_and_device(device, &dev); |
| 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, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1246 | struct loader_device **found_dev) { |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1247 | *found_dev = NULL; |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1248 | for (struct loader_instance *inst = loader.instances; inst; |
| 1249 | inst = inst->next) { |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1250 | for (struct loader_icd *icd = inst->icds; icd; icd = icd->next) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1251 | for (struct loader_device *dev = icd->logical_device_list; dev; |
| 1252 | dev = dev->next) |
| 1253 | /* Value comparison of device prevents object wrapping by layers |
| 1254 | */ |
| 1255 | if (loader_get_dispatch(dev->device) == |
| 1256 | loader_get_dispatch(device)) { |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1257 | *found_dev = dev; |
| 1258 | return icd; |
| 1259 | } |
| 1260 | } |
| 1261 | } |
| 1262 | return NULL; |
| 1263 | } |
| 1264 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1265 | void loader_destroy_logical_device(const struct loader_instance *inst, |
| 1266 | struct loader_device *dev, |
| 1267 | const VkAllocationCallbacks *pAllocator) { |
| 1268 | if (pAllocator) { |
| 1269 | dev->alloc_callbacks = *pAllocator; |
| 1270 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1271 | if (NULL != dev->activated_layer_list.list) { |
| 1272 | loader_deactivate_layers(inst, dev, &dev->activated_layer_list); |
| 1273 | } |
| 1274 | loader_device_heap_free(dev, dev); |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1275 | } |
| 1276 | |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 1277 | struct loader_device * |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1278 | loader_create_logical_device(const struct loader_instance *inst, |
| 1279 | const VkAllocationCallbacks *pAllocator) { |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1280 | struct loader_device *new_dev; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1281 | #if (DEBUG_DISABLE_APP_ALLOCATORS == 1) |
| 1282 | { |
| 1283 | #else |
| 1284 | if (pAllocator) { |
| 1285 | new_dev = (struct loader_device *)pAllocator->pfnAllocation( |
| 1286 | pAllocator->pUserData, sizeof(struct loader_device), sizeof(int *), |
| 1287 | VK_SYSTEM_ALLOCATION_SCOPE_DEVICE); |
| 1288 | } else { |
| 1289 | #endif |
| 1290 | new_dev = (struct loader_device *)malloc(sizeof(struct loader_device)); |
| 1291 | } |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1292 | |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1293 | if (!new_dev) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1294 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1295 | "Failed to alloc struct loader-device"); |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1296 | return NULL; |
| 1297 | } |
| 1298 | |
| 1299 | memset(new_dev, 0, sizeof(struct loader_device)); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1300 | if (pAllocator) { |
| 1301 | new_dev->alloc_callbacks = *pAllocator; |
| 1302 | } |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1303 | |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1304 | return new_dev; |
| 1305 | } |
| 1306 | |
Piers Daniell | 295fe40 | 2016-03-29 11:51:11 -0600 | [diff] [blame] | 1307 | void loader_add_logical_device(const struct loader_instance *inst, |
| 1308 | struct loader_icd *icd, |
| 1309 | struct loader_device *dev) { |
| 1310 | dev->next = icd->logical_device_list; |
| 1311 | icd->logical_device_list = dev; |
| 1312 | } |
| 1313 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1314 | void loader_remove_logical_device(const struct loader_instance *inst, |
| 1315 | struct loader_icd *icd, |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1316 | struct loader_device *found_dev, |
| 1317 | const VkAllocationCallbacks *pAllocator) { |
Jon Ashburn | 781a7ae | 2015-11-19 15:43:26 -0700 | [diff] [blame] | 1318 | struct loader_device *dev, *prev_dev; |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1319 | |
| 1320 | if (!icd || !found_dev) |
| 1321 | return; |
| 1322 | |
| 1323 | prev_dev = NULL; |
| 1324 | dev = icd->logical_device_list; |
| 1325 | while (dev && dev != found_dev) { |
| 1326 | prev_dev = dev; |
| 1327 | dev = dev->next; |
| 1328 | } |
| 1329 | |
| 1330 | if (prev_dev) |
| 1331 | prev_dev->next = found_dev->next; |
| 1332 | else |
| 1333 | icd->logical_device_list = found_dev->next; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1334 | loader_destroy_logical_device(inst, found_dev, pAllocator); |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1335 | } |
| 1336 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1337 | static void loader_icd_destroy(struct loader_instance *ptr_inst, |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1338 | struct loader_icd *icd, |
| 1339 | const VkAllocationCallbacks *pAllocator) { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1340 | ptr_inst->total_icd_count--; |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1341 | for (struct loader_device *dev = icd->logical_device_list; dev;) { |
Courtney Goeltzenleuchter | 1f157ac | 2015-06-14 19:57:15 -0600 | [diff] [blame] | 1342 | struct loader_device *next_dev = dev->next; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1343 | loader_destroy_logical_device(ptr_inst, dev, pAllocator); |
Courtney Goeltzenleuchter | 1f157ac | 2015-06-14 19:57:15 -0600 | [diff] [blame] | 1344 | dev = next_dev; |
| 1345 | } |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1346 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1347 | loader_instance_heap_free(ptr_inst, icd); |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1348 | } |
| 1349 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1350 | static struct loader_icd * |
| 1351 | loader_icd_create(const struct loader_instance *inst) { |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1352 | struct loader_icd *icd; |
| 1353 | |
Mark Young | db13a2a | 2016-09-06 13:53:03 -0600 | [diff] [blame] | 1354 | icd = loader_instance_heap_alloc(inst, sizeof(struct loader_icd), |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1355 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Mark Young | db13a2a | 2016-09-06 13:53:03 -0600 | [diff] [blame] | 1356 | if (!icd) { |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1357 | return NULL; |
Mark Young | db13a2a | 2016-09-06 13:53:03 -0600 | [diff] [blame] | 1358 | } |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1359 | |
Mark Young | db13a2a | 2016-09-06 13:53:03 -0600 | [diff] [blame] | 1360 | memset(icd, 0, sizeof(struct loader_icd)); |
Courtney Goeltzenleuchter | 55001bb | 2014-10-28 10:29:27 -0600 | [diff] [blame] | 1361 | |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1362 | return icd; |
| 1363 | } |
| 1364 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1365 | static struct loader_icd * |
| 1366 | loader_icd_add(struct loader_instance *ptr_inst, |
| 1367 | const struct loader_scanned_icds *icd_lib) { |
Chia-I Wu | 13a61a5 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 1368 | struct loader_icd *icd; |
| 1369 | |
Jon Ashburn | e39a4f8 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 1370 | icd = loader_icd_create(ptr_inst); |
Mark Young | db13a2a | 2016-09-06 13:53:03 -0600 | [diff] [blame] | 1371 | if (!icd) { |
Chia-I Wu | 13a61a5 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 1372 | return NULL; |
Mark Young | db13a2a | 2016-09-06 13:53:03 -0600 | [diff] [blame] | 1373 | } |
Chia-I Wu | 13a61a5 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 1374 | |
Jon Ashburn | 3d00233 | 2015-08-20 16:35:30 -0600 | [diff] [blame] | 1375 | icd->this_icd_lib = icd_lib; |
| 1376 | icd->this_instance = ptr_inst; |
| 1377 | |
Chia-I Wu | 13a61a5 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 1378 | /* prepend to the list */ |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 1379 | icd->next = ptr_inst->icds; |
| 1380 | ptr_inst->icds = icd; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1381 | ptr_inst->total_icd_count++; |
Chia-I Wu | 13a61a5 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 1382 | |
| 1383 | return icd; |
| 1384 | } |
Jon Ashburn | 17b4c86 | 2016-04-25 11:09:37 -0600 | [diff] [blame] | 1385 | /** |
| 1386 | * Determine the ICD interface version to use. |
| 1387 | * @param icd |
| 1388 | * @param pVersion Output parameter indicating which version to use or 0 if |
| 1389 | * the negotiation API is not supported by the ICD |
| 1390 | * @return bool indicating true if the selected interface version is supported |
| 1391 | * by the loader, false indicates the version is not supported |
| 1392 | * version 0 doesn't support vk_icdGetInstanceProcAddr nor |
| 1393 | * vk_icdNegotiateLoaderICDInterfaceVersion |
| 1394 | * version 1 supports vk_icdGetInstanceProcAddr |
| 1395 | * version 2 supports vk_icdNegotiateLoaderICDInterfaceVersion |
| 1396 | */ |
| 1397 | bool loader_get_icd_interface_version( |
| 1398 | PFN_vkNegotiateLoaderICDInterfaceVersion fp_negotiate_icd_version, |
| 1399 | uint32_t *pVersion) { |
| 1400 | |
| 1401 | if (fp_negotiate_icd_version == NULL) { |
| 1402 | // ICD does not support the negotiation API, it supports version 0 or 1 |
| 1403 | // calling code must determine if it is version 0 or 1 |
| 1404 | *pVersion = 0; |
| 1405 | } else { |
| 1406 | // ICD supports the negotiation API, so call it with the loader's |
| 1407 | // latest version supported |
| 1408 | *pVersion = CURRENT_LOADER_ICD_INTERFACE_VERSION; |
| 1409 | VkResult result = fp_negotiate_icd_version(pVersion); |
| 1410 | |
| 1411 | if (result == VK_ERROR_INCOMPATIBLE_DRIVER) { |
| 1412 | // ICD no longer supports the loader's latest interface version so |
| 1413 | // fail loading the ICD |
| 1414 | return false; |
| 1415 | } |
| 1416 | } |
| 1417 | |
| 1418 | #if MIN_SUPPORTED_LOADER_ICD_INTERFACE_VERSION > 0 |
| 1419 | if (*pVersion < MIN_SUPPORTED_LOADER_ICD_INTERFACE_VERSION) { |
| 1420 | // Loader no longer supports the ICD's latest interface version so fail |
| 1421 | // loading the ICD |
| 1422 | return false; |
| 1423 | } |
| 1424 | #endif |
| 1425 | return true; |
| 1426 | } |
Chia-I Wu | 13a61a5 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 1427 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1428 | void loader_scanned_icd_clear(const struct loader_instance *inst, |
| 1429 | struct loader_icd_libs *icd_libs) { |
Jon Ashburn | 8810c5f | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 1430 | if (icd_libs->capacity == 0) |
| 1431 | return; |
| 1432 | for (uint32_t i = 0; i < icd_libs->count; i++) { |
| 1433 | loader_platform_close_library(icd_libs->list[i].handle); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1434 | loader_instance_heap_free(inst, icd_libs->list[i].lib_name); |
Jon Ashburn | 8810c5f | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 1435 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1436 | loader_instance_heap_free(inst, icd_libs->list); |
Jon Ashburn | 8810c5f | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 1437 | icd_libs->capacity = 0; |
| 1438 | icd_libs->count = 0; |
| 1439 | icd_libs->list = NULL; |
| 1440 | } |
| 1441 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1442 | static VkResult loader_scanned_icd_init(const struct loader_instance *inst, |
| 1443 | struct loader_icd_libs *icd_libs) { |
| 1444 | VkResult err = VK_SUCCESS; |
Jon Ashburn | e39a4f8 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 1445 | loader_scanned_icd_clear(inst, icd_libs); |
Jon Ashburn | 8810c5f | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 1446 | icd_libs->capacity = 8 * sizeof(struct loader_scanned_icds); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1447 | icd_libs->list = loader_instance_heap_alloc( |
| 1448 | inst, icd_libs->capacity, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
| 1449 | if (NULL == icd_libs->list) { |
| 1450 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1451 | "realloc failed for layer list when attempting to add new layer"); |
| 1452 | err = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 1453 | } |
| 1454 | return err; |
Jon Ashburn | 8810c5f | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 1455 | } |
| 1456 | |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1457 | static VkResult loader_scanned_icd_add(const struct loader_instance *inst, |
| 1458 | struct loader_icd_libs *icd_libs, |
| 1459 | const char *filename, |
| 1460 | uint32_t api_version) { |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1461 | loader_platform_dl_handle handle; |
Tony Barbour | 1d2cd3f | 2015-07-03 10:33:54 -0600 | [diff] [blame] | 1462 | PFN_vkCreateInstance fp_create_inst; |
Jon Ashburn | fd4d09d | 2016-01-07 09:44:27 -0700 | [diff] [blame] | 1463 | PFN_vkEnumerateInstanceExtensionProperties fp_get_inst_ext_props; |
Jon Ashburn | c624c88 | 2015-07-16 10:17:29 -0600 | [diff] [blame] | 1464 | PFN_vkGetInstanceProcAddr fp_get_proc_addr; |
Jon Ashburn | 17b4c86 | 2016-04-25 11:09:37 -0600 | [diff] [blame] | 1465 | PFN_vkNegotiateLoaderICDInterfaceVersion fp_negotiate_icd_version; |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 1466 | struct loader_scanned_icds *new_node; |
Jon Ashburn | 17b4c86 | 2016-04-25 11:09:37 -0600 | [diff] [blame] | 1467 | uint32_t interface_vers; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1468 | VkResult res = VK_SUCCESS; |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 1469 | |
Jon Ashburn | 4dc1d8a | 2016-04-20 13:21:17 -0600 | [diff] [blame] | 1470 | /* TODO implement smarter opening/closing of libraries. For now this |
| 1471 | * function leaves libraries open and the scanned_icd_clear closes them */ |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1472 | handle = loader_platform_open_library(filename); |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 1473 | if (!handle) { |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 1474 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1475 | loader_platform_open_library_error(filename)); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1476 | goto out; |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 1477 | } |
| 1478 | |
Jon Ashburn | 17b4c86 | 2016-04-25 11:09:37 -0600 | [diff] [blame] | 1479 | // Get and settle on an ICD interface version |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1480 | fp_negotiate_icd_version = loader_platform_get_proc_address( |
| 1481 | handle, "vk_icdNegotiateLoaderICDInterfaceVersion"); |
Jon Ashburn | 17b4c86 | 2016-04-25 11:09:37 -0600 | [diff] [blame] | 1482 | |
| 1483 | if (!loader_get_icd_interface_version(fp_negotiate_icd_version, |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1484 | &interface_vers)) { |
| 1485 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1486 | "ICD (%s) doesn't support interface version compatible" |
| 1487 | "with loader, skip this ICD %s", |
| 1488 | filename); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1489 | goto out; |
Jon Ashburn | 17b4c86 | 2016-04-25 11:09:37 -0600 | [diff] [blame] | 1490 | } |
| 1491 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1492 | fp_get_proc_addr = |
| 1493 | loader_platform_get_proc_address(handle, "vk_icdGetInstanceProcAddr"); |
Jon Ashburn | fd4d09d | 2016-01-07 09:44:27 -0700 | [diff] [blame] | 1494 | if (!fp_get_proc_addr) { |
Jon Ashburn | 17b4c86 | 2016-04-25 11:09:37 -0600 | [diff] [blame] | 1495 | assert(interface_vers == 0); |
| 1496 | // Use deprecated interface from version 0 |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1497 | fp_get_proc_addr = |
| 1498 | loader_platform_get_proc_address(handle, "vkGetInstanceProcAddr"); |
Jon Ashburn | fd4d09d | 2016-01-07 09:44:27 -0700 | [diff] [blame] | 1499 | if (!fp_get_proc_addr) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1500 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1501 | loader_platform_get_proc_address_error( |
| 1502 | "vk_icdGetInstanceProcAddr")); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1503 | goto out; |
Jon Ashburn | fd4d09d | 2016-01-07 09:44:27 -0700 | [diff] [blame] | 1504 | } else { |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 1505 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1506 | "Using deprecated ICD interface of " |
| 1507 | "vkGetInstanceProcAddr instead of " |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1508 | "vk_icdGetInstanceProcAddr for ICD %s", |
| 1509 | filename); |
Jon Ashburn | fd4d09d | 2016-01-07 09:44:27 -0700 | [diff] [blame] | 1510 | } |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1511 | fp_create_inst = |
| 1512 | loader_platform_get_proc_address(handle, "vkCreateInstance"); |
Jon Ashburn | 69a5f7a | 2016-01-11 14:41:35 -0700 | [diff] [blame] | 1513 | if (!fp_create_inst) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1514 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1515 | "Couldn't get vkCreateInstance via dlsym/loadlibrary " |
| 1516 | "for ICD %s", |
| 1517 | filename); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1518 | goto out; |
Jon Ashburn | 69a5f7a | 2016-01-11 14:41:35 -0700 | [diff] [blame] | 1519 | } |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1520 | fp_get_inst_ext_props = loader_platform_get_proc_address( |
| 1521 | handle, "vkEnumerateInstanceExtensionProperties"); |
Jon Ashburn | 69a5f7a | 2016-01-11 14:41:35 -0700 | [diff] [blame] | 1522 | if (!fp_get_inst_ext_props) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1523 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1524 | "Couldn't get vkEnumerateInstanceExtensionProperties " |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1525 | "via dlsym/loadlibrary for ICD %s", |
| 1526 | filename); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1527 | goto out; |
Jon Ashburn | 69a5f7a | 2016-01-11 14:41:35 -0700 | [diff] [blame] | 1528 | } |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1529 | } else { |
Jon Ashburn | 17b4c86 | 2016-04-25 11:09:37 -0600 | [diff] [blame] | 1530 | // Use newer interface version 1 or later |
| 1531 | if (interface_vers == 0) |
| 1532 | interface_vers = 1; |
| 1533 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1534 | fp_create_inst = |
| 1535 | (PFN_vkCreateInstance)fp_get_proc_addr(NULL, "vkCreateInstance"); |
Jon Ashburn | 69a5f7a | 2016-01-11 14:41:35 -0700 | [diff] [blame] | 1536 | if (!fp_create_inst) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1537 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1538 | "Couldn't get vkCreateInstance via " |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1539 | "vk_icdGetInstanceProcAddr for ICD %s", |
| 1540 | filename); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1541 | goto out; |
Jon Ashburn | 69a5f7a | 2016-01-11 14:41:35 -0700 | [diff] [blame] | 1542 | } |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1543 | fp_get_inst_ext_props = |
| 1544 | (PFN_vkEnumerateInstanceExtensionProperties)fp_get_proc_addr( |
| 1545 | NULL, "vkEnumerateInstanceExtensionProperties"); |
Jon Ashburn | 69a5f7a | 2016-01-11 14:41:35 -0700 | [diff] [blame] | 1546 | if (!fp_get_inst_ext_props) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1547 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1548 | "Couldn't get vkEnumerateInstanceExtensionProperties " |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1549 | "via vk_icdGetInstanceProcAddr for ICD %s", |
| 1550 | filename); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1551 | goto out; |
Jon Ashburn | 69a5f7a | 2016-01-11 14:41:35 -0700 | [diff] [blame] | 1552 | } |
Jon Ashburn | fd4d09d | 2016-01-07 09:44:27 -0700 | [diff] [blame] | 1553 | } |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 1554 | |
Jon Ashburn | 8810c5f | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 1555 | // check for enough capacity |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1556 | if ((icd_libs->count * sizeof(struct loader_scanned_icds)) >= |
| 1557 | icd_libs->capacity) { |
Jon Ashburn | e39a4f8 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 1558 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1559 | icd_libs->list = loader_instance_heap_realloc( |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1560 | inst, icd_libs->list, icd_libs->capacity, icd_libs->capacity * 2, |
| 1561 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1562 | if (NULL == icd_libs->list) { |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1563 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1564 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1565 | "realloc failed on icd library list"); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1566 | goto out; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1567 | } |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1568 | // double capacity |
| 1569 | icd_libs->capacity *= 2; |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 1570 | } |
Jon Ashburn | 8810c5f | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 1571 | new_node = &(icd_libs->list[icd_libs->count]); |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 1572 | |
| 1573 | new_node->handle = handle; |
Jon Ashburn | 005617f | 2015-11-17 17:35:40 -0700 | [diff] [blame] | 1574 | new_node->api_version = api_version; |
Jon Ashburn | c624c88 | 2015-07-16 10:17:29 -0600 | [diff] [blame] | 1575 | new_node->GetInstanceProcAddr = fp_get_proc_addr; |
Jon Ashburn | fd4d09d | 2016-01-07 09:44:27 -0700 | [diff] [blame] | 1576 | new_node->EnumerateInstanceExtensionProperties = fp_get_inst_ext_props; |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 1577 | new_node->CreateInstance = fp_create_inst; |
Jon Ashburn | 17b4c86 | 2016-04-25 11:09:37 -0600 | [diff] [blame] | 1578 | new_node->interface_version = interface_vers; |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 1579 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1580 | new_node->lib_name = (char *)loader_instance_heap_alloc( |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1581 | inst, strlen(filename) + 1, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1582 | if (NULL == new_node->lib_name) { |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1583 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 1584 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1585 | "Out of memory can't add icd"); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1586 | goto out; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1587 | } |
| 1588 | strcpy(new_node->lib_name, filename); |
Jon Ashburn | 8810c5f | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 1589 | icd_libs->count++; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1590 | |
| 1591 | out: |
| 1592 | |
| 1593 | return res; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1594 | } |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1595 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1596 | static bool loader_icd_init_entrys(struct loader_icd *icd, VkInstance inst, |
| 1597 | const PFN_vkGetInstanceProcAddr fp_gipa) { |
| 1598 | /* initialize entrypoint function pointers */ |
Jon Ashburn | 3da71f2 | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 1599 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1600 | #define LOOKUP_GIPA(func, required) \ |
| 1601 | do { \ |
| 1602 | icd->func = (PFN_vk##func)fp_gipa(inst, "vk" #func); \ |
| 1603 | if (!icd->func && required) { \ |
| 1604 | loader_log((struct loader_instance *)inst, \ |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 1605 | VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, \ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1606 | loader_platform_get_proc_address_error("vk" #func)); \ |
| 1607 | return false; \ |
| 1608 | } \ |
Jon Ashburn | 3da71f2 | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 1609 | } while (0) |
| 1610 | |
Jon Ashburn | c624c88 | 2015-07-16 10:17:29 -0600 | [diff] [blame] | 1611 | LOOKUP_GIPA(GetDeviceProcAddr, true); |
| 1612 | LOOKUP_GIPA(DestroyInstance, true); |
| 1613 | LOOKUP_GIPA(EnumeratePhysicalDevices, true); |
| 1614 | LOOKUP_GIPA(GetPhysicalDeviceFeatures, true); |
| 1615 | LOOKUP_GIPA(GetPhysicalDeviceFormatProperties, true); |
Jon Ashburn | 754864f | 2015-07-23 18:49:07 -0600 | [diff] [blame] | 1616 | LOOKUP_GIPA(GetPhysicalDeviceImageFormatProperties, true); |
Jon Ashburn | c624c88 | 2015-07-16 10:17:29 -0600 | [diff] [blame] | 1617 | LOOKUP_GIPA(CreateDevice, true); |
| 1618 | LOOKUP_GIPA(GetPhysicalDeviceProperties, true); |
| 1619 | LOOKUP_GIPA(GetPhysicalDeviceMemoryProperties, true); |
Cody Northrop | d080288 | 2015-08-03 17:04:53 -0600 | [diff] [blame] | 1620 | LOOKUP_GIPA(GetPhysicalDeviceQueueFamilyProperties, true); |
Courtney Goeltzenleuchter | 35985f6 | 2015-09-14 17:22:16 -0600 | [diff] [blame] | 1621 | LOOKUP_GIPA(EnumerateDeviceExtensionProperties, true); |
Jon Ashburn | c624c88 | 2015-07-16 10:17:29 -0600 | [diff] [blame] | 1622 | LOOKUP_GIPA(GetPhysicalDeviceSparseImageFormatProperties, true); |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1623 | LOOKUP_GIPA(CreateDebugReportCallbackEXT, false); |
| 1624 | LOOKUP_GIPA(DestroyDebugReportCallbackEXT, false); |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 1625 | LOOKUP_GIPA(GetPhysicalDeviceSurfaceSupportKHR, false); |
Ian Elliott | 486c550 | 2015-11-19 16:05:09 -0700 | [diff] [blame] | 1626 | LOOKUP_GIPA(GetPhysicalDeviceSurfaceCapabilitiesKHR, false); |
| 1627 | LOOKUP_GIPA(GetPhysicalDeviceSurfaceFormatsKHR, false); |
| 1628 | LOOKUP_GIPA(GetPhysicalDeviceSurfacePresentModesKHR, false); |
Petros Bantolas | 25d27fe | 2016-04-14 12:50:42 +0100 | [diff] [blame] | 1629 | LOOKUP_GIPA(GetPhysicalDeviceDisplayPropertiesKHR, false); |
| 1630 | LOOKUP_GIPA(GetDisplayModePropertiesKHR, false); |
| 1631 | LOOKUP_GIPA(CreateDisplayPlaneSurfaceKHR, false); |
| 1632 | LOOKUP_GIPA(GetPhysicalDeviceDisplayPlanePropertiesKHR, false); |
| 1633 | LOOKUP_GIPA(GetDisplayPlaneSupportedDisplaysKHR, false); |
| 1634 | LOOKUP_GIPA(CreateDisplayModeKHR, false); |
| 1635 | LOOKUP_GIPA(GetDisplayPlaneCapabilitiesKHR, false); |
| 1636 | LOOKUP_GIPA(DestroySurfaceKHR, false); |
Ian Elliott | 919fa30 | 2015-11-24 15:39:10 -0700 | [diff] [blame] | 1637 | #ifdef VK_USE_PLATFORM_WIN32_KHR |
| 1638 | LOOKUP_GIPA(GetPhysicalDeviceWin32PresentationSupportKHR, false); |
| 1639 | #endif |
| 1640 | #ifdef VK_USE_PLATFORM_XCB_KHR |
| 1641 | LOOKUP_GIPA(GetPhysicalDeviceXcbPresentationSupportKHR, false); |
| 1642 | #endif |
Karl Schultz | 65d2018 | 2016-03-08 07:55:27 -0700 | [diff] [blame] | 1643 | #ifdef VK_USE_PLATFORM_XLIB_KHR |
| 1644 | LOOKUP_GIPA(GetPhysicalDeviceXlibPresentationSupportKHR, false); |
| 1645 | #endif |
Jason Ekstrand | a5ebe8a | 2016-02-12 17:25:03 -0800 | [diff] [blame] | 1646 | #ifdef VK_USE_PLATFORM_WAYLAND_KHR |
| 1647 | LOOKUP_GIPA(GetPhysicalDeviceWaylandPresentationSupportKHR, false); |
| 1648 | #endif |
James Jones | 389dc0c | 2016-08-18 23:41:19 +0100 | [diff] [blame] | 1649 | LOOKUP_GIPA(GetPhysicalDeviceExternalImageFormatPropertiesNV, false); |
Jon Ashburn | 3da71f2 | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 1650 | |
Jon Ashburn | c624c88 | 2015-07-16 10:17:29 -0600 | [diff] [blame] | 1651 | #undef LOOKUP_GIPA |
Ian Elliott | d3ef02f | 2015-07-06 14:36:13 -0600 | [diff] [blame] | 1652 | |
Jon Ashburn | c624c88 | 2015-07-16 10:17:29 -0600 | [diff] [blame] | 1653 | return true; |
Jon Ashburn | 3da71f2 | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 1654 | } |
| 1655 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1656 | static void loader_debug_init(void) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1657 | char *env, *orig; |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 1658 | |
| 1659 | if (g_loader_debug > 0) |
| 1660 | return; |
| 1661 | |
| 1662 | g_loader_debug = 0; |
| 1663 | |
| 1664 | /* parse comma-separated debug options */ |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1665 | orig = env = loader_getenv("VK_LOADER_DEBUG", NULL); |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 1666 | while (env) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1667 | char *p = strchr(env, ','); |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 1668 | size_t len; |
| 1669 | |
| 1670 | if (p) |
| 1671 | len = p - env; |
| 1672 | else |
| 1673 | len = strlen(env); |
| 1674 | |
| 1675 | if (len > 0) { |
Michael Worcester | 25c73e7 | 2015-12-10 18:06:24 +0000 | [diff] [blame] | 1676 | if (strncmp(env, "all", len) == 0) { |
| 1677 | g_loader_debug = ~0u; |
| 1678 | g_loader_log_msgs = ~0u; |
| 1679 | } else if (strncmp(env, "warn", len) == 0) { |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 1680 | g_loader_debug |= LOADER_WARN_BIT; |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 1681 | g_loader_log_msgs |= VK_DEBUG_REPORT_WARNING_BIT_EXT; |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 1682 | } else if (strncmp(env, "info", len) == 0) { |
| 1683 | g_loader_debug |= LOADER_INFO_BIT; |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 1684 | g_loader_log_msgs |= VK_DEBUG_REPORT_INFORMATION_BIT_EXT; |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 1685 | } else if (strncmp(env, "perf", len) == 0) { |
| 1686 | g_loader_debug |= LOADER_PERF_BIT; |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 1687 | g_loader_log_msgs |= |
| 1688 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT; |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 1689 | } else if (strncmp(env, "error", len) == 0) { |
| 1690 | g_loader_debug |= LOADER_ERROR_BIT; |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1691 | g_loader_log_msgs |= VK_DEBUG_REPORT_ERROR_BIT_EXT; |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 1692 | } else if (strncmp(env, "debug", len) == 0) { |
| 1693 | g_loader_debug |= LOADER_DEBUG_BIT; |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1694 | g_loader_log_msgs |= VK_DEBUG_REPORT_DEBUG_BIT_EXT; |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 1695 | } |
| 1696 | } |
| 1697 | |
| 1698 | if (!p) |
| 1699 | break; |
| 1700 | |
| 1701 | env = p + 1; |
| 1702 | } |
Jon Ashburn | 38a497f | 2016-01-04 14:01:38 -0700 | [diff] [blame] | 1703 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1704 | loader_free_getenv(orig, NULL); |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 1705 | } |
| 1706 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1707 | void loader_initialize(void) { |
Jon Ashburn | 6461ef2 | 2015-09-22 13:11:00 -0600 | [diff] [blame] | 1708 | // initialize mutexs |
Jon Ashburn | 8810c5f | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 1709 | loader_platform_thread_create_mutex(&loader_lock); |
Jon Ashburn | 6461ef2 | 2015-09-22 13:11:00 -0600 | [diff] [blame] | 1710 | loader_platform_thread_create_mutex(&loader_json_lock); |
Jon Ashburn | 8810c5f | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 1711 | |
| 1712 | // initialize logging |
| 1713 | loader_debug_init(); |
Jon Ashburn | 87d6aa9 | 2015-08-28 15:19:27 -0600 | [diff] [blame] | 1714 | |
| 1715 | // initial cJSON to use alloc callbacks |
| 1716 | cJSON_Hooks alloc_fns = { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1717 | .malloc_fn = loader_instance_tls_heap_alloc, |
| 1718 | .free_fn = loader_instance_tls_heap_free, |
Jon Ashburn | 87d6aa9 | 2015-08-28 15:19:27 -0600 | [diff] [blame] | 1719 | }; |
| 1720 | cJSON_InitHooks(&alloc_fns); |
Jon Ashburn | 8810c5f | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 1721 | } |
| 1722 | |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1723 | struct loader_manifest_files { |
| 1724 | uint32_t count; |
| 1725 | char **filename_list; |
| 1726 | }; |
| 1727 | |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 1728 | /** |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1729 | * 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] | 1730 | * |
| 1731 | * \returns |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1732 | * A pointer to first char in the next path. |
| 1733 | * The next path (or NULL) in the list is returned in next_path. |
| 1734 | * Note: input string is modified in some cases. PASS IN A COPY! |
| 1735 | */ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1736 | static char *loader_get_next_path(char *path) { |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1737 | uint32_t len; |
| 1738 | char *next; |
| 1739 | |
| 1740 | if (path == NULL) |
| 1741 | return NULL; |
| 1742 | next = strchr(path, PATH_SEPERATOR); |
| 1743 | if (next == NULL) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1744 | len = (uint32_t)strlen(path); |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1745 | next = path + len; |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1746 | } else { |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1747 | *next = '\0'; |
| 1748 | next++; |
| 1749 | } |
| 1750 | |
| 1751 | return next; |
| 1752 | } |
| 1753 | |
| 1754 | /** |
Daniel Dadap | 00b4aba | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 1755 | * Given a path which is absolute or relative, expand the path if relative or |
| 1756 | * leave the path unmodified if absolute. The base path to prepend to relative |
| 1757 | * paths is given in rel_base. |
Jon Ashburn | 1531517 | 2015-07-07 15:06:25 -0600 | [diff] [blame] | 1758 | * |
| 1759 | * \returns |
| 1760 | * A string in out_fullpath of the full absolute path |
Jon Ashburn | 1531517 | 2015-07-07 15:06:25 -0600 | [diff] [blame] | 1761 | */ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1762 | static void loader_expand_path(const char *path, const char *rel_base, |
| 1763 | size_t out_size, char *out_fullpath) { |
Jon Ashburn | 1531517 | 2015-07-07 15:06:25 -0600 | [diff] [blame] | 1764 | if (loader_platform_is_path_absolute(path)) { |
Daniel Dadap | 00b4aba | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 1765 | // do not prepend a base to an absolute path |
| 1766 | rel_base = ""; |
Jon Ashburn | 1531517 | 2015-07-07 15:06:25 -0600 | [diff] [blame] | 1767 | } |
Daniel Dadap | 00b4aba | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 1768 | |
| 1769 | loader_platform_combine_path(out_fullpath, out_size, rel_base, path, NULL); |
Jon Ashburn | 1531517 | 2015-07-07 15:06:25 -0600 | [diff] [blame] | 1770 | } |
| 1771 | |
| 1772 | /** |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1773 | * Given a filename (file) and a list of paths (dir), try to find an existing |
| 1774 | * file in the paths. If filename already is a path then no |
| 1775 | * searching in the given paths. |
| 1776 | * |
| 1777 | * \returns |
| 1778 | * A string in out_fullpath of either the full path or file. |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1779 | */ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1780 | static void loader_get_fullpath(const char *file, const char *dirs, |
| 1781 | size_t out_size, char *out_fullpath) { |
Daniel Dadap | 00b4aba | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 1782 | if (!loader_platform_is_path(file) && *dirs) { |
| 1783 | char *dirs_copy, *dir, *next_dir; |
| 1784 | |
| 1785 | dirs_copy = loader_stack_alloc(strlen(dirs) + 1); |
| 1786 | strcpy(dirs_copy, dirs); |
| 1787 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1788 | // find if file exists after prepending paths in given list |
| 1789 | for (dir = dirs_copy; *dir && (next_dir = loader_get_next_path(dir)); |
Daniel Dadap | 00b4aba | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 1790 | dir = next_dir) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1791 | loader_platform_combine_path(out_fullpath, out_size, dir, file, |
| 1792 | NULL); |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1793 | if (loader_platform_file_exists(out_fullpath)) { |
| 1794 | return; |
| 1795 | } |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1796 | } |
| 1797 | } |
Daniel Dadap | 00b4aba | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 1798 | |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1799 | snprintf(out_fullpath, out_size, "%s", file); |
| 1800 | } |
| 1801 | |
| 1802 | /** |
| 1803 | * Read a JSON file into a buffer. |
| 1804 | * |
| 1805 | * \returns |
| 1806 | * A pointer to a cJSON object representing the JSON parse tree. |
| 1807 | * This returned buffer should be freed by caller. |
| 1808 | */ |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1809 | static VkResult loader_get_json(const struct loader_instance *inst, |
| 1810 | const char *filename, cJSON **json) { |
| 1811 | FILE *file = NULL; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1812 | char *json_buf; |
Mark Young | 93ecb1d | 2016-01-13 13:47:16 -0700 | [diff] [blame] | 1813 | size_t len; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1814 | VkResult res = VK_SUCCESS; |
| 1815 | |
| 1816 | if (NULL == json) { |
| 1817 | res = VK_ERROR_INITIALIZATION_FAILED; |
| 1818 | goto out; |
| 1819 | } |
| 1820 | |
| 1821 | *json = NULL; |
| 1822 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1823 | file = fopen(filename, "rb"); |
Jon Ashburn | aa4ea47 | 2015-08-27 08:30:50 -0600 | [diff] [blame] | 1824 | if (!file) { |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1825 | res = VK_ERROR_INITIALIZATION_FAILED; |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1826 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1827 | "Couldn't open JSON file %s", filename); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1828 | goto out; |
Jon Ashburn | aa4ea47 | 2015-08-27 08:30:50 -0600 | [diff] [blame] | 1829 | } |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1830 | fseek(file, 0, SEEK_END); |
| 1831 | len = ftell(file); |
| 1832 | fseek(file, 0, SEEK_SET); |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1833 | json_buf = (char *)loader_stack_alloc(len + 1); |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1834 | if (json_buf == NULL) { |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1835 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1836 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1837 | "Out of memory can't get JSON file"); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1838 | goto out; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1839 | } |
| 1840 | if (fread(json_buf, sizeof(char), len, file) != len) { |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1841 | res = VK_ERROR_INITIALIZATION_FAILED; |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1842 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1843 | "fread failed can't get JSON file"); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1844 | goto out; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1845 | } |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1846 | json_buf[len] = '\0'; |
| 1847 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1848 | // parse text from file |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1849 | *json = cJSON_Parse(json_buf); |
| 1850 | if (*json == NULL) { |
| 1851 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1852 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1853 | "Can't parse JSON file %s", filename); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1854 | goto out; |
| 1855 | } |
| 1856 | |
| 1857 | out: |
| 1858 | if (NULL != file) { |
| 1859 | fclose(file); |
| 1860 | } |
| 1861 | |
| 1862 | return res; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1863 | } |
| 1864 | |
| 1865 | /** |
Jon Ashburn | 3d00233 | 2015-08-20 16:35:30 -0600 | [diff] [blame] | 1866 | * Do a deep copy of the loader_layer_properties structure. |
| 1867 | */ |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1868 | VkResult loader_copy_layer_properties(const struct loader_instance *inst, |
| 1869 | struct loader_layer_properties *dst, |
| 1870 | struct loader_layer_properties *src) { |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1871 | uint32_t cnt, i; |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1872 | memcpy(dst, src, sizeof(*src)); |
| 1873 | dst->instance_extension_list.list = |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1874 | loader_instance_heap_alloc(inst, sizeof(VkExtensionProperties) * |
| 1875 | src->instance_extension_list.count, |
| 1876 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
| 1877 | if (NULL == dst->instance_extension_list.list) { |
| 1878 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1879 | "alloc failed for instance extension list"); |
| 1880 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 1881 | } |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1882 | dst->instance_extension_list.capacity = |
| 1883 | sizeof(VkExtensionProperties) * src->instance_extension_list.count; |
Jon Ashburn | e39a4f8 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 1884 | memcpy(dst->instance_extension_list.list, src->instance_extension_list.list, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1885 | dst->instance_extension_list.capacity); |
| 1886 | dst->device_extension_list.list = |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1887 | loader_instance_heap_alloc(inst, sizeof(struct loader_dev_ext_props) * |
| 1888 | src->device_extension_list.count, |
| 1889 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
| 1890 | if (NULL == dst->device_extension_list.list) { |
| 1891 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1892 | "alloc failed for device extension list"); |
| 1893 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 1894 | } |
| 1895 | memset(dst->device_extension_list.list, 0, sizeof(struct loader_dev_ext_props) * |
| 1896 | src->device_extension_list.count); |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1897 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1898 | dst->device_extension_list.capacity = |
| 1899 | sizeof(struct loader_dev_ext_props) * src->device_extension_list.count; |
Jon Ashburn | e39a4f8 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 1900 | memcpy(dst->device_extension_list.list, src->device_extension_list.list, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1901 | dst->device_extension_list.capacity); |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1902 | if (src->device_extension_list.count > 0 && |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1903 | src->device_extension_list.list->entrypoint_count > 0) { |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1904 | cnt = src->device_extension_list.list->entrypoint_count; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1905 | dst->device_extension_list.list->entrypoints = |
| 1906 | loader_instance_heap_alloc(inst, sizeof(char *) * cnt, |
| 1907 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
| 1908 | if (NULL == dst->device_extension_list.list->entrypoints) { |
| 1909 | loader_log( |
| 1910 | inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1911 | "alloc failed for device extension list entrypoint array"); |
| 1912 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 1913 | } |
| 1914 | memset(dst->device_extension_list.list->entrypoints, 0, sizeof(char *) * cnt); |
| 1915 | |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1916 | for (i = 0; i < cnt; i++) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1917 | dst->device_extension_list.list->entrypoints[i] = |
| 1918 | loader_instance_heap_alloc( |
| 1919 | inst, |
| 1920 | strlen(src->device_extension_list.list->entrypoints[i]) + 1, |
| 1921 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
| 1922 | if (NULL == dst->device_extension_list.list->entrypoints[i]) { |
| 1923 | loader_log( |
| 1924 | inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1925 | "alloc failed for device extension list entrypoint %d", i); |
| 1926 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 1927 | } |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1928 | strcpy(dst->device_extension_list.list->entrypoints[i], |
| 1929 | src->device_extension_list.list->entrypoints[i]); |
| 1930 | } |
| 1931 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1932 | |
| 1933 | return VK_SUCCESS; |
Jon Ashburn | 3d00233 | 2015-08-20 16:35:30 -0600 | [diff] [blame] | 1934 | } |
| 1935 | |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 1936 | static bool |
| 1937 | loader_find_layer_name_list(const char *name, |
| 1938 | const struct loader_layer_list *layer_list) { |
| 1939 | if (!layer_list) |
| 1940 | return false; |
| 1941 | for (uint32_t j = 0; j < layer_list->count; j++) |
| 1942 | if (!strcmp(name, layer_list->list[j].info.layerName)) |
| 1943 | return true; |
| 1944 | return false; |
| 1945 | } |
| 1946 | |
| 1947 | static bool loader_find_layer_name(const char *name, uint32_t layer_count, |
| 1948 | const char **layer_list) { |
| 1949 | if (!layer_list) |
| 1950 | return false; |
| 1951 | for (uint32_t j = 0; j < layer_count; j++) |
| 1952 | if (!strcmp(name, layer_list[j])) |
| 1953 | return true; |
| 1954 | return false; |
| 1955 | } |
| 1956 | |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 1957 | bool loader_find_layer_name_array( |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 1958 | const char *name, uint32_t layer_count, |
| 1959 | const char layer_list[][VK_MAX_EXTENSION_NAME_SIZE]) { |
| 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 | |
| 1968 | /** |
| 1969 | * Searches through an array of layer names (ppp_layer_names) looking for a |
| 1970 | * layer key_name. |
| 1971 | * If not found then simply returns updating nothing. |
| 1972 | * Otherwise, it uses expand_count, expand_names adding them to layer names. |
Chris Forbes | 6936647 | 2016-04-07 09:04:49 +1200 | [diff] [blame] | 1973 | * Any duplicate (pre-existing) expand_names in layer names are removed. |
| 1974 | * Order is otherwise preserved, with the layer key_name being replaced by the |
| 1975 | * expand_names. |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 1976 | * @param inst |
| 1977 | * @param layer_count |
| 1978 | * @param ppp_layer_names |
| 1979 | */ |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1980 | VkResult loader_expand_layer_names( |
| 1981 | struct loader_instance *inst, const char *key_name, uint32_t expand_count, |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 1982 | const char expand_names[][VK_MAX_EXTENSION_NAME_SIZE], |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 1983 | uint32_t *layer_count, char const *const **ppp_layer_names) { |
Jon Ashburn | 7148344 | 2016-02-11 18:59:43 -0700 | [diff] [blame] | 1984 | |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 1985 | char const *const *pp_src_layers = *ppp_layer_names; |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 1986 | |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 1987 | if (!loader_find_layer_name(key_name, *layer_count, |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 1988 | (char const **)pp_src_layers)) { |
| 1989 | inst->activated_layers_are_std_val = false; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1990 | return VK_SUCCESS; // didn't find the key_name in the list. |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 1991 | } |
Jon Ashburn | 7148344 | 2016-02-11 18:59:43 -0700 | [diff] [blame] | 1992 | |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 1993 | loader_log(inst, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, |
| 1994 | "Found meta layer %s, replacing with actual layer group", |
| 1995 | key_name); |
Chris Forbes | bd9de05 | 2016-04-06 20:49:02 +1200 | [diff] [blame] | 1996 | |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 1997 | inst->activated_layers_are_std_val = true; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1998 | char const **pp_dst_layers = loader_instance_heap_alloc( |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 1999 | inst, (expand_count + *layer_count - 1) * sizeof(char const *), |
| 2000 | VK_SYSTEM_ALLOCATION_SCOPE_COMMAND); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2001 | if (NULL == pp_dst_layers) { |
| 2002 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 2003 | "alloc failed for dst layer array"); |
| 2004 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 2005 | } |
Chris Forbes | bd9de05 | 2016-04-06 20:49:02 +1200 | [diff] [blame] | 2006 | |
| 2007 | // copy layers from src to dst, stripping key_name and anything in |
| 2008 | // expand_names. |
| 2009 | uint32_t src_index, dst_index = 0; |
| 2010 | for (src_index = 0; src_index < *layer_count; src_index++) { |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 2011 | if (loader_find_layer_name_array(pp_src_layers[src_index], expand_count, |
| 2012 | expand_names)) { |
Chris Forbes | 6936647 | 2016-04-07 09:04:49 +1200 | [diff] [blame] | 2013 | continue; |
| 2014 | } |
| 2015 | |
| 2016 | if (!strcmp(pp_src_layers[src_index], key_name)) { |
| 2017 | // insert all expand_names in place of key_name |
| 2018 | uint32_t expand_index; |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 2019 | for (expand_index = 0; expand_index < expand_count; |
| 2020 | expand_index++) { |
Chris Forbes | 6936647 | 2016-04-07 09:04:49 +1200 | [diff] [blame] | 2021 | pp_dst_layers[dst_index++] = expand_names[expand_index]; |
| 2022 | } |
Chris Forbes | bd9de05 | 2016-04-06 20:49:02 +1200 | [diff] [blame] | 2023 | continue; |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 2024 | } |
Chris Forbes | bd9de05 | 2016-04-06 20:49:02 +1200 | [diff] [blame] | 2025 | |
| 2026 | pp_dst_layers[dst_index++] = pp_src_layers[src_index]; |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 2027 | } |
| 2028 | |
Chris Forbes | bd9de05 | 2016-04-06 20:49:02 +1200 | [diff] [blame] | 2029 | *ppp_layer_names = pp_dst_layers; |
| 2030 | *layer_count = dst_index; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2031 | |
| 2032 | return VK_SUCCESS; |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 2033 | } |
| 2034 | |
Chris Forbes | bd9de05 | 2016-04-06 20:49:02 +1200 | [diff] [blame] | 2035 | void loader_delete_shadow_inst_layer_names(const struct loader_instance *inst, |
| 2036 | const VkInstanceCreateInfo *orig, |
| 2037 | VkInstanceCreateInfo *ours) { |
| 2038 | /* Free the layer names array iff we had to reallocate it */ |
| 2039 | if (orig->ppEnabledLayerNames != ours->ppEnabledLayerNames) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2040 | loader_instance_heap_free(inst, (void *)ours->ppEnabledLayerNames); |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 2041 | } |
| 2042 | } |
| 2043 | |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 2044 | void loader_init_std_validation_props(struct loader_layer_properties *props) { |
| 2045 | memset(props, 0, sizeof(struct loader_layer_properties)); |
| 2046 | props->type = VK_LAYER_TYPE_META_EXPLICT; |
| 2047 | strncpy(props->info.description, "LunarG Standard Validation Layer", |
| 2048 | sizeof (props->info.description)); |
| 2049 | props->info.implementationVersion = 1; |
| 2050 | strncpy(props->info.layerName, std_validation_str, |
| 2051 | sizeof (props->info.layerName)); |
| 2052 | // TODO what about specVersion? for now insert loader's built version |
| 2053 | props->info.specVersion = VK_MAKE_VERSION(1, 0, VK_HEADER_VERSION); |
| 2054 | } |
| 2055 | |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 2056 | /** |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 2057 | * Searches through the existing instance layer lists looking for |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 2058 | * the set of required layer names. If found then it adds a meta property to the |
| 2059 | * layer list. |
| 2060 | * Assumes the required layers are the same for both instance and device lists. |
| 2061 | * @param inst |
| 2062 | * @param layer_count number of layers in layer_names |
| 2063 | * @param layer_names array of required layer names |
| 2064 | * @param layer_instance_list |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 2065 | */ |
| 2066 | static void loader_add_layer_property_meta( |
| 2067 | const struct loader_instance *inst, uint32_t layer_count, |
| 2068 | const char layer_names[][VK_MAX_EXTENSION_NAME_SIZE], |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 2069 | struct loader_layer_list *layer_instance_list) { |
| 2070 | uint32_t i; |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 2071 | bool found; |
| 2072 | struct loader_layer_list *layer_list; |
| 2073 | |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 2074 | if (0 == layer_count || (!layer_instance_list)) |
Jon Ashburn | 888c050 | 2016-02-19 15:22:10 -0700 | [diff] [blame] | 2075 | return; |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 2076 | if (layer_instance_list && (layer_count > layer_instance_list->count)) |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 2077 | return; |
| 2078 | |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 2079 | |
| 2080 | layer_list = layer_instance_list; |
| 2081 | |
| 2082 | found = true; |
| 2083 | if (layer_list == NULL) |
| 2084 | return; |
| 2085 | for (i = 0; i < layer_count; i++) { |
| 2086 | if (loader_find_layer_name_list(layer_names[i], layer_list)) |
Jon Ashburn | 888c050 | 2016-02-19 15:22:10 -0700 | [diff] [blame] | 2087 | continue; |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 2088 | found = false; |
| 2089 | break; |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 2090 | } |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 2091 | |
| 2092 | struct loader_layer_properties *props; |
| 2093 | if (found) { |
| 2094 | props = loader_get_next_layer_property(inst, layer_list); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2095 | if (NULL == props) { |
| 2096 | // Error already triggered in loader_get_next_layer_property. |
| 2097 | return; |
| 2098 | } |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 2099 | loader_init_std_validation_props(props); |
| 2100 | |
| 2101 | } |
| 2102 | |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 2103 | } |
| 2104 | |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2105 | static void loader_read_json_layer( |
| 2106 | const struct loader_instance *inst, |
| 2107 | struct loader_layer_list *layer_instance_list, cJSON *layer_node, |
| 2108 | cJSON *item, cJSON *disable_environment, bool is_implicit, char *filename) { |
| 2109 | char *temp; |
| 2110 | char *name, *type, *library_path, *api_version; |
| 2111 | char *implementation_version, *description; |
| 2112 | cJSON *ext_item; |
| 2113 | VkExtensionProperties ext_prop; |
| 2114 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2115 | /* |
| 2116 | * The following are required in the "layer" object: |
| 2117 | * (required) "name" |
| 2118 | * (required) "type" |
| 2119 | * (required) “library_path” |
| 2120 | * (required) “api_version” |
| 2121 | * (required) “implementation_version” |
| 2122 | * (required) “description” |
| 2123 | * (required for implicit layers) “disable_environment” |
| 2124 | */ |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 2125 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2126 | #define GET_JSON_OBJECT(node, var) \ |
| 2127 | { \ |
| 2128 | var = cJSON_GetObjectItem(node, #var); \ |
| 2129 | if (var == NULL) { \ |
| 2130 | layer_node = layer_node->next; \ |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 2131 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, \ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2132 | "Didn't find required layer object %s in manifest " \ |
| 2133 | "JSON file, skipping this layer", \ |
| 2134 | #var); \ |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2135 | return; \ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2136 | } \ |
| 2137 | } |
| 2138 | #define GET_JSON_ITEM(node, var) \ |
| 2139 | { \ |
| 2140 | item = cJSON_GetObjectItem(node, #var); \ |
| 2141 | if (item == NULL) { \ |
| 2142 | layer_node = layer_node->next; \ |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 2143 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, \ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2144 | "Didn't find required layer value %s in manifest JSON " \ |
| 2145 | "file, skipping this layer", \ |
| 2146 | #var); \ |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2147 | return; \ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2148 | } \ |
| 2149 | temp = cJSON_Print(item); \ |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2150 | if (temp == NULL) { \ |
| 2151 | layer_node = layer_node->next; \ |
| 2152 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, \ |
| 2153 | "Problem accessing layer value %s in manifest JSON " \ |
| 2154 | "file, skipping this layer", \ |
| 2155 | #var); \ |
| 2156 | return; \ |
| 2157 | } \ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2158 | temp[strlen(temp) - 1] = '\0'; \ |
| 2159 | var = loader_stack_alloc(strlen(temp) + 1); \ |
| 2160 | strcpy(var, &temp[1]); \ |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2161 | cJSON_Free(temp); \ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2162 | } |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2163 | GET_JSON_ITEM(layer_node, name) |
| 2164 | GET_JSON_ITEM(layer_node, type) |
| 2165 | GET_JSON_ITEM(layer_node, library_path) |
| 2166 | GET_JSON_ITEM(layer_node, api_version) |
| 2167 | GET_JSON_ITEM(layer_node, implementation_version) |
| 2168 | GET_JSON_ITEM(layer_node, description) |
| 2169 | if (is_implicit) { |
| 2170 | GET_JSON_OBJECT(layer_node, disable_environment) |
| 2171 | } |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 2172 | #undef GET_JSON_ITEM |
| 2173 | #undef GET_JSON_OBJECT |
| 2174 | |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2175 | // add list entry |
| 2176 | struct loader_layer_properties *props = NULL; |
| 2177 | if (!strcmp(type, "DEVICE")) { |
| 2178 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 2179 | "Device layers are deprecated skipping this layer"); |
| 2180 | layer_node = layer_node->next; |
| 2181 | return; |
| 2182 | } |
| 2183 | // Allow either GLOBAL or INSTANCE type interchangeably to handle |
| 2184 | // layers that must work with older loaders |
| 2185 | if (!strcmp(type, "INSTANCE") || !strcmp(type, "GLOBAL")) { |
| 2186 | if (layer_instance_list == NULL) { |
Jon Ashburn | 432d276 | 2015-09-18 12:53:16 -0600 | [diff] [blame] | 2187 | layer_node = layer_node->next; |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2188 | return; |
Jon Ashburn | 432d276 | 2015-09-18 12:53:16 -0600 | [diff] [blame] | 2189 | } |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2190 | props = loader_get_next_layer_property(inst, layer_instance_list); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2191 | if (NULL == props) { |
| 2192 | // Error already triggered in loader_get_next_layer_property. |
| 2193 | return; |
| 2194 | } |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2195 | props->type = (is_implicit) ? VK_LAYER_TYPE_INSTANCE_IMPLICIT |
| 2196 | : VK_LAYER_TYPE_INSTANCE_EXPLICIT; |
| 2197 | } |
Jon Ashburn | 432d276 | 2015-09-18 12:53:16 -0600 | [diff] [blame] | 2198 | |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2199 | if (props == NULL) { |
| 2200 | layer_node = layer_node->next; |
| 2201 | return; |
| 2202 | } |
Jon Ashburn | 1531517 | 2015-07-07 15:06:25 -0600 | [diff] [blame] | 2203 | |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2204 | strncpy(props->info.layerName, name, sizeof(props->info.layerName)); |
| 2205 | props->info.layerName[sizeof(props->info.layerName) - 1] = '\0'; |
| 2206 | |
| 2207 | char *fullpath = props->lib_name; |
| 2208 | char *rel_base; |
| 2209 | if (loader_platform_is_path(library_path)) { |
| 2210 | // a relative or absolute path |
| 2211 | char *name_copy = loader_stack_alloc(strlen(filename) + 1); |
| 2212 | strcpy(name_copy, filename); |
| 2213 | rel_base = loader_platform_dirname(name_copy); |
| 2214 | loader_expand_path(library_path, rel_base, MAX_STRING_SIZE, fullpath); |
| 2215 | } else { |
| 2216 | // a filename which is assumed in a system directory |
| 2217 | loader_get_fullpath(library_path, DEFAULT_VK_LAYERS_PATH, |
| 2218 | MAX_STRING_SIZE, fullpath); |
| 2219 | } |
| 2220 | props->info.specVersion = loader_make_version(api_version); |
| 2221 | props->info.implementationVersion = atoi(implementation_version); |
| 2222 | strncpy((char *)props->info.description, description, |
| 2223 | sizeof(props->info.description)); |
| 2224 | props->info.description[sizeof(props->info.description) - 1] = '\0'; |
| 2225 | if (is_implicit) { |
| 2226 | if (!disable_environment || !disable_environment->child) { |
| 2227 | loader_log( |
| 2228 | inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 2229 | "Didn't find required layer child value disable_environment" |
| 2230 | "in manifest JSON file, skipping this layer"); |
| 2231 | layer_node = layer_node->next; |
| 2232 | return; |
Jon Ashburn | fb8ac01 | 2015-08-12 16:39:32 -0600 | [diff] [blame] | 2233 | } |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2234 | strncpy(props->disable_env_var.name, disable_environment->child->string, |
| 2235 | sizeof(props->disable_env_var.name)); |
| 2236 | props->disable_env_var.name[sizeof(props->disable_env_var.name) - 1] = |
| 2237 | '\0'; |
| 2238 | strncpy(props->disable_env_var.value, |
| 2239 | disable_environment->child->valuestring, |
| 2240 | sizeof(props->disable_env_var.value)); |
| 2241 | props->disable_env_var.value[sizeof(props->disable_env_var.value) - 1] = |
| 2242 | '\0'; |
| 2243 | } |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 2244 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2245 | /** |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2246 | * Now get all optional items and objects and put in list: |
| 2247 | * functions |
| 2248 | * instance_extensions |
| 2249 | * device_extensions |
| 2250 | * enable_environment (implicit layers only) |
| 2251 | */ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2252 | #define GET_JSON_OBJECT(node, var) \ |
| 2253 | { var = cJSON_GetObjectItem(node, #var); } |
| 2254 | #define GET_JSON_ITEM(node, var) \ |
| 2255 | { \ |
| 2256 | item = cJSON_GetObjectItem(node, #var); \ |
| 2257 | if (item != NULL) { \ |
| 2258 | temp = cJSON_Print(item); \ |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2259 | if (temp != NULL) { \ |
| 2260 | temp[strlen(temp) - 1] = '\0'; \ |
| 2261 | var = loader_stack_alloc(strlen(temp) + 1); \ |
| 2262 | strcpy(var, &temp[1]); \ |
| 2263 | cJSON_Free(temp); \ |
| 2264 | } \ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2265 | } \ |
| 2266 | } |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 2267 | |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2268 | cJSON *instance_extensions, *device_extensions, *functions, |
| 2269 | *enable_environment; |
| 2270 | cJSON *entrypoints; |
| 2271 | char *vkGetInstanceProcAddr, *vkGetDeviceProcAddr, *spec_version; |
| 2272 | char **entry_array; |
| 2273 | vkGetInstanceProcAddr = NULL; |
| 2274 | vkGetDeviceProcAddr = NULL; |
| 2275 | spec_version = NULL; |
| 2276 | entrypoints = NULL; |
| 2277 | entry_array = NULL; |
| 2278 | int i, j; |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 2279 | |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2280 | /** |
| 2281 | * functions |
| 2282 | * vkGetInstanceProcAddr |
| 2283 | * vkGetDeviceProcAddr |
| 2284 | */ |
| 2285 | GET_JSON_OBJECT(layer_node, functions) |
| 2286 | if (functions != NULL) { |
| 2287 | GET_JSON_ITEM(functions, vkGetInstanceProcAddr) |
| 2288 | GET_JSON_ITEM(functions, vkGetDeviceProcAddr) |
| 2289 | if (vkGetInstanceProcAddr != NULL) |
| 2290 | strncpy(props->functions.str_gipa, vkGetInstanceProcAddr, |
| 2291 | sizeof(props->functions.str_gipa)); |
| 2292 | props->functions.str_gipa[sizeof(props->functions.str_gipa) - 1] = '\0'; |
| 2293 | if (vkGetDeviceProcAddr != NULL) |
| 2294 | strncpy(props->functions.str_gdpa, vkGetDeviceProcAddr, |
| 2295 | sizeof(props->functions.str_gdpa)); |
| 2296 | props->functions.str_gdpa[sizeof(props->functions.str_gdpa) - 1] = '\0'; |
| 2297 | } |
| 2298 | /** |
| 2299 | * instance_extensions |
| 2300 | * array of |
| 2301 | * name |
| 2302 | * spec_version |
| 2303 | */ |
| 2304 | GET_JSON_OBJECT(layer_node, instance_extensions) |
| 2305 | if (instance_extensions != NULL) { |
| 2306 | int count = cJSON_GetArraySize(instance_extensions); |
| 2307 | for (i = 0; i < count; i++) { |
| 2308 | ext_item = cJSON_GetArrayItem(instance_extensions, i); |
| 2309 | GET_JSON_ITEM(ext_item, name) |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2310 | if (name != NULL) { |
| 2311 | strncpy(ext_prop.extensionName, name, |
| 2312 | sizeof(ext_prop.extensionName)); |
| 2313 | ext_prop.extensionName[sizeof(ext_prop.extensionName) - 1] = |
| 2314 | '\0'; |
| 2315 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2316 | GET_JSON_ITEM(ext_item, spec_version) |
| 2317 | if (NULL != spec_version) { |
| 2318 | ext_prop.specVersion = atoi(spec_version); |
| 2319 | } else { |
| 2320 | ext_prop.specVersion = 0; |
| 2321 | } |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2322 | bool ext_unsupported = |
| 2323 | wsi_unsupported_instance_extension(&ext_prop); |
| 2324 | if (!ext_unsupported) { |
| 2325 | loader_add_to_ext_list(inst, &props->instance_extension_list, 1, |
| 2326 | &ext_prop); |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 2327 | } |
Jon Ashburn | fb8ac01 | 2015-08-12 16:39:32 -0600 | [diff] [blame] | 2328 | } |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2329 | } |
| 2330 | /** |
| 2331 | * device_extensions |
| 2332 | * array of |
| 2333 | * name |
| 2334 | * spec_version |
| 2335 | * entrypoints |
| 2336 | */ |
| 2337 | GET_JSON_OBJECT(layer_node, device_extensions) |
| 2338 | if (device_extensions != NULL) { |
| 2339 | int count = cJSON_GetArraySize(device_extensions); |
| 2340 | for (i = 0; i < count; i++) { |
| 2341 | ext_item = cJSON_GetArrayItem(device_extensions, i); |
| 2342 | GET_JSON_ITEM(ext_item, name) |
| 2343 | GET_JSON_ITEM(ext_item, spec_version) |
| 2344 | if (name != NULL) { |
| 2345 | strncpy(ext_prop.extensionName, name, |
| 2346 | sizeof(ext_prop.extensionName)); |
| 2347 | ext_prop.extensionName[sizeof(ext_prop.extensionName) - 1] = |
| 2348 | '\0'; |
| 2349 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2350 | if (NULL != spec_version) { |
| 2351 | ext_prop.specVersion = atoi(spec_version); |
| 2352 | } else { |
| 2353 | ext_prop.specVersion = 0; |
| 2354 | } |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2355 | // entrypoints = cJSON_GetObjectItem(ext_item, "entrypoints"); |
| 2356 | GET_JSON_OBJECT(ext_item, entrypoints) |
| 2357 | int entry_count; |
| 2358 | if (entrypoints == NULL) { |
| 2359 | loader_add_to_dev_ext_list(inst, &props->device_extension_list, |
| 2360 | &ext_prop, 0, NULL); |
| 2361 | continue; |
| 2362 | } |
| 2363 | entry_count = cJSON_GetArraySize(entrypoints); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2364 | if (entry_count) { |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2365 | entry_array = |
| 2366 | (char **)loader_stack_alloc(sizeof(char *) * entry_count); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2367 | } |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2368 | for (j = 0; j < entry_count; j++) { |
| 2369 | ext_item = cJSON_GetArrayItem(entrypoints, j); |
| 2370 | if (ext_item != NULL) { |
| 2371 | temp = cJSON_Print(ext_item); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2372 | if (NULL == temp) { |
| 2373 | entry_array[j] = NULL; |
| 2374 | continue; |
| 2375 | } |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2376 | temp[strlen(temp) - 1] = '\0'; |
| 2377 | entry_array[j] = loader_stack_alloc(strlen(temp) + 1); |
| 2378 | strcpy(entry_array[j], &temp[1]); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2379 | cJSON_Free(temp); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2380 | } |
| 2381 | } |
| 2382 | loader_add_to_dev_ext_list(inst, &props->device_extension_list, |
| 2383 | &ext_prop, entry_count, entry_array); |
| 2384 | } |
| 2385 | } |
| 2386 | if (is_implicit) { |
| 2387 | GET_JSON_OBJECT(layer_node, enable_environment) |
| 2388 | |
| 2389 | // enable_environment is optional |
| 2390 | if (enable_environment) { |
| 2391 | strncpy(props->enable_env_var.name, |
| 2392 | enable_environment->child->string, |
| 2393 | sizeof(props->enable_env_var.name)); |
| 2394 | props->enable_env_var.name[sizeof(props->enable_env_var.name) - 1] = |
| 2395 | '\0'; |
| 2396 | strncpy(props->enable_env_var.value, |
| 2397 | enable_environment->child->valuestring, |
| 2398 | sizeof(props->enable_env_var.value)); |
| 2399 | props->enable_env_var |
| 2400 | .value[sizeof(props->enable_env_var.value) - 1] = '\0'; |
| 2401 | } |
| 2402 | } |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 2403 | #undef GET_JSON_ITEM |
| 2404 | #undef GET_JSON_OBJECT |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2405 | } |
| 2406 | |
| 2407 | /** |
| 2408 | * Given a cJSON struct (json) of the top level JSON object from layer manifest |
| 2409 | * file, add entry to the layer_list. Fill out the layer_properties in this list |
| 2410 | * entry from the input cJSON object. |
| 2411 | * |
| 2412 | * \returns |
| 2413 | * void |
| 2414 | * layer_list has a new entry and initialized accordingly. |
| 2415 | * If the json input object does not have all the required fields no entry |
| 2416 | * is added to the list. |
| 2417 | */ |
| 2418 | static void |
| 2419 | loader_add_layer_properties(const struct loader_instance *inst, |
| 2420 | struct loader_layer_list *layer_instance_list, |
| 2421 | cJSON *json, bool is_implicit, char *filename) { |
| 2422 | /* Fields in layer manifest file that are required: |
| 2423 | * (required) “file_format_version” |
| 2424 | * |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2425 | * If more than one "layer" object are to be used, use the "layers" array |
| 2426 | * instead. |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2427 | * |
| 2428 | * First get all required items and if any missing abort |
| 2429 | */ |
| 2430 | |
| 2431 | cJSON *item, *layers_node, *layer_node; |
| 2432 | uint16_t file_major_vers = 0; |
| 2433 | uint16_t file_minor_vers = 0; |
| 2434 | uint16_t file_patch_vers = 0; |
| 2435 | char *vers_tok; |
| 2436 | cJSON *disable_environment = NULL; |
| 2437 | item = cJSON_GetObjectItem(json, "file_format_version"); |
| 2438 | if (item == NULL) { |
| 2439 | return; |
| 2440 | } |
| 2441 | char *file_vers = cJSON_PrintUnformatted(item); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2442 | if (NULL == file_vers) { |
| 2443 | return; |
| 2444 | } |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2445 | loader_log(inst, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, |
| 2446 | "Found manifest file %s, version %s", filename, file_vers); |
| 2447 | // Get the major/minor/and patch as integers for easier comparison |
| 2448 | vers_tok = strtok(file_vers, ".\"\n\r"); |
| 2449 | if (NULL != vers_tok) { |
Jamie Madill | 970ebcf | 2016-07-06 11:19:42 -0400 | [diff] [blame] | 2450 | file_major_vers = (uint16_t)atoi(vers_tok); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2451 | vers_tok = strtok(NULL, ".\"\n\r"); |
| 2452 | if (NULL != vers_tok) { |
Jamie Madill | 970ebcf | 2016-07-06 11:19:42 -0400 | [diff] [blame] | 2453 | file_minor_vers = (uint16_t)atoi(vers_tok); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2454 | vers_tok = strtok(NULL, ".\"\n\r"); |
| 2455 | if (NULL != vers_tok) { |
Jamie Madill | 970ebcf | 2016-07-06 11:19:42 -0400 | [diff] [blame] | 2456 | file_patch_vers = (uint16_t)atoi(vers_tok); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2457 | } |
| 2458 | } |
| 2459 | } |
| 2460 | if (file_major_vers != 1 || file_minor_vers != 0 || file_patch_vers > 1) { |
| 2461 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 2462 | "%s Unexpected manifest file version (expected 1.0.0 or " |
| 2463 | "1.0.1), may cause errors", |
| 2464 | filename); |
| 2465 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2466 | cJSON_Free(file_vers); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2467 | // If "layers" is present, read in the array of layer objects |
| 2468 | layers_node = cJSON_GetObjectItem(json, "layers"); |
| 2469 | if (layers_node != NULL) { |
| 2470 | int numItems = cJSON_GetArraySize(layers_node); |
| 2471 | if (file_major_vers == 1 && file_minor_vers == 0 && |
| 2472 | file_patch_vers == 0) { |
| 2473 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 2474 | "\"layers\" tag not officially added until file version " |
| 2475 | "1.0.1, but %s is reporting version %s", |
| 2476 | filename, file_vers); |
| 2477 | } |
| 2478 | for (int curLayer = 0; curLayer < numItems; curLayer++) { |
| 2479 | layer_node = cJSON_GetArrayItem(layers_node, curLayer); |
| 2480 | if (layer_node == NULL) { |
| 2481 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 2482 | "Can't find \"layers\" array element %d object in " |
| 2483 | "manifest JSON file %s, skipping this file", |
| 2484 | curLayer, filename); |
| 2485 | return; |
| 2486 | } |
| 2487 | loader_read_json_layer(inst, layer_instance_list, layer_node, item, |
| 2488 | disable_environment, is_implicit, filename); |
| 2489 | } |
| 2490 | } else { |
| 2491 | // Otherwise, try to read in individual layers |
| 2492 | layer_node = cJSON_GetObjectItem(json, "layer"); |
| 2493 | if (layer_node == NULL) { |
| 2494 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 2495 | "Can't find \"layer\" object in manifest JSON file %s, " |
| 2496 | "skipping this file", |
| 2497 | filename); |
| 2498 | return; |
| 2499 | } |
| 2500 | // Loop through all "layer" objects in the file to get a count of them |
| 2501 | // first. |
| 2502 | uint16_t layer_count = 0; |
| 2503 | cJSON *tempNode = layer_node; |
| 2504 | do { |
| 2505 | tempNode = tempNode->next; |
| 2506 | layer_count++; |
| 2507 | } while (tempNode != NULL); |
| 2508 | /* |
| 2509 | * Throw a warning if we encounter multiple "layer" objects in file |
| 2510 | * versions newer than 1.0.0. Having multiple objects with the same |
| 2511 | * name at the same level is actually a JSON standard violation. |
| 2512 | */ |
| 2513 | if (layer_count > 1 && |
| 2514 | (file_major_vers > 1 || |
| 2515 | !(file_minor_vers == 0 && file_patch_vers == 0))) { |
| 2516 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 2517 | "Multiple \"layer\" nodes are deprecated starting in " |
| 2518 | "file version \"1.0.1\". Please use \"layers\" : [] " |
| 2519 | "array instead in %s.", |
| 2520 | filename); |
| 2521 | } else { |
| 2522 | do { |
| 2523 | loader_read_json_layer(inst, layer_instance_list, layer_node, |
| 2524 | item, disable_environment, is_implicit, |
| 2525 | filename); |
| 2526 | layer_node = layer_node->next; |
| 2527 | } while (layer_node != NULL); |
| 2528 | } |
| 2529 | } |
Jon Ashburn | fb8ac01 | 2015-08-12 16:39:32 -0600 | [diff] [blame] | 2530 | return; |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 2531 | } |
| 2532 | |
| 2533 | /** |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2534 | * Find the Vulkan library manifest files. |
| 2535 | * |
Jon Ashburn | b682221 | 2016-02-16 15:34:16 -0700 | [diff] [blame] | 2536 | * This function scans the "location" or "env_override" directories/files |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2537 | * for a list of JSON manifest files. If env_override is non-NULL |
| 2538 | * and has a valid value. Then the location is ignored. Otherwise |
| 2539 | * location is used to look for manifest files. The location |
| 2540 | * is interpreted as Registry path on Windows and a directory path(s) |
Jon Ashburn | b682221 | 2016-02-16 15:34:16 -0700 | [diff] [blame] | 2541 | * on Linux. "home_location" is an additional directory in the users home |
John Drinkwater | 9ac3f4f | 2016-08-01 17:00:00 +0100 | [diff] [blame] | 2542 | * directory to look at. It is expanded into the dir path |
| 2543 | * $XDG_DATA_HOME/home_location or $HOME/.local/share/home_location depending |
| 2544 | * on environment variables. This "home_location" is only used on Linux. |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2545 | * |
| 2546 | * \returns |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2547 | * VKResult |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2548 | * A string list of manifest files to be opened in out_files param. |
| 2549 | * List has a pointer to string for each manifest filename. |
| 2550 | * When done using the list in out_files, pointers should be freed. |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2551 | * Location or override string lists can be either files or directories as |
| 2552 | *follows: |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2553 | * | location | override |
| 2554 | * -------------------------------- |
| 2555 | * Win ICD | files | files |
| 2556 | * Win Layer | files | dirs |
| 2557 | * Linux ICD | dirs | files |
| 2558 | * Linux Layer| dirs | dirs |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2559 | */ |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2560 | static VkResult loader_get_manifest_files( |
| 2561 | const struct loader_instance *inst, const char *env_override, |
| 2562 | char *source_override, bool is_layer, const char *location, |
| 2563 | const char *home_location, struct loader_manifest_files *out_files) { |
| 2564 | char * override = NULL; |
| 2565 | char *loc, *orig_loc = NULL; |
| 2566 | char *reg = NULL; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2567 | char *file, *next_file, *name; |
| 2568 | size_t alloced_count = 64; |
| 2569 | char full_path[2048]; |
| 2570 | DIR *sysdir = NULL; |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2571 | bool list_is_dirs = false; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2572 | struct dirent *dent; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2573 | VkResult res = VK_SUCCESS; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2574 | |
| 2575 | out_files->count = 0; |
| 2576 | out_files->filename_list = NULL; |
| 2577 | |
Jamie Madill | 00c3c91 | 2016-04-06 18:26:46 -0400 | [diff] [blame] | 2578 | if (source_override != NULL) { |
| 2579 | override = source_override; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2580 | } else if (env_override != NULL && |
| 2581 | (override = loader_getenv(env_override, inst))) { |
Johannes van Waveren | 9bd80501 | 2015-10-28 11:45:00 -0500 | [diff] [blame] | 2582 | #if !defined(_WIN32) |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 2583 | if (geteuid() != getuid() || getegid() != getgid()) { |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2584 | /* Don't allow setuid apps to use the env var: */ |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2585 | loader_free_getenv(override, inst); |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2586 | override = NULL; |
| 2587 | } |
| 2588 | #endif |
| 2589 | } |
| 2590 | |
Jon Ashburn | b682221 | 2016-02-16 15:34:16 -0700 | [diff] [blame] | 2591 | #if !defined(_WIN32) |
| 2592 | if (location == NULL && home_location == NULL) { |
| 2593 | #else |
| 2594 | home_location = NULL; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2595 | if (location == NULL) { |
Jon Ashburn | b682221 | 2016-02-16 15:34:16 -0700 | [diff] [blame] | 2596 | #endif |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2597 | loader_log( |
| 2598 | inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2599 | "Can't get manifest files with NULL location, env_override=%s", |
| 2600 | env_override); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2601 | res = VK_ERROR_INITIALIZATION_FAILED; |
| 2602 | goto out; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2603 | } |
| 2604 | |
Johannes van Waveren | 9bd80501 | 2015-10-28 11:45:00 -0500 | [diff] [blame] | 2605 | #if defined(_WIN32) |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2606 | list_is_dirs = (is_layer && override != NULL) ? true : false; |
Johannes van Waveren | 9bd80501 | 2015-10-28 11:45:00 -0500 | [diff] [blame] | 2607 | #else |
| 2608 | list_is_dirs = (override == NULL || is_layer) ? true : false; |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2609 | #endif |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2610 | // 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] | 2611 | // Also handle getting the location(s) from registry on Windows |
| 2612 | if (override == NULL) { |
Jon Ashburn | 3b78e46 | 2015-07-31 10:11:24 -0600 | [diff] [blame] | 2613 | loc = loader_stack_alloc(strlen(location) + 1); |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2614 | if (loc == NULL) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2615 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 2616 | "Out of memory can't get manifest files"); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2617 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 2618 | goto out; |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2619 | } |
| 2620 | strcpy(loc, location); |
Johannes van Waveren | 9bd80501 | 2015-10-28 11:45:00 -0500 | [diff] [blame] | 2621 | #if defined(_WIN32) |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2622 | reg = loader_get_registry_files(inst, loc); |
| 2623 | if (reg == NULL) { |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 2624 | if (!is_layer) { |
| 2625 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 2626 | "Registry lookup failed can't get ICD manifest " |
| 2627 | "files, do you have a Vulkan driver installed"); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2628 | // This typically only fails when out of memory, which is |
| 2629 | // critical |
| 2630 | // if this is for the loader. |
| 2631 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 2632 | } else { |
| 2633 | // warning only for layers |
| 2634 | loader_log( |
| 2635 | inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 2636 | "Registry lookup failed can't get layer manifest files"); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2637 | // Return success for now since it's not critical for layers |
| 2638 | res = VK_SUCCESS; |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 2639 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2640 | goto out; |
Jon Ashburn | 24265ac | 2015-07-31 09:33:21 -0600 | [diff] [blame] | 2641 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2642 | orig_loc = loc; |
| 2643 | loc = reg; |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2644 | #endif |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2645 | } else { |
Courtney Goeltzenleuchter | 7f5aafc | 2015-07-05 11:28:29 -0600 | [diff] [blame] | 2646 | loc = loader_stack_alloc(strlen(override) + 1); |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2647 | if (loc == NULL) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2648 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 2649 | "Out of memory can't get manifest files"); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2650 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 2651 | goto out; |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2652 | } |
| 2653 | strcpy(loc, override); |
Jamie Madill | 00c3c91 | 2016-04-06 18:26:46 -0400 | [diff] [blame] | 2654 | if (source_override == NULL) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2655 | loader_free_getenv(override, inst); |
Jamie Madill | 00c3c91 | 2016-04-06 18:26:46 -0400 | [diff] [blame] | 2656 | } |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2657 | } |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2658 | |
Liam Middlebrook | 9b14e89 | 2015-07-23 18:32:20 -0700 | [diff] [blame] | 2659 | // Print out the paths being searched if debugging is enabled |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2660 | loader_log(inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, |
| 2661 | "Searching the following paths for manifest files: %s\n", loc); |
Liam Middlebrook | 9b14e89 | 2015-07-23 18:32:20 -0700 | [diff] [blame] | 2662 | |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2663 | file = loc; |
| 2664 | while (*file) { |
| 2665 | next_file = loader_get_next_path(file); |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2666 | if (list_is_dirs) { |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2667 | sysdir = opendir(file); |
| 2668 | name = NULL; |
| 2669 | if (sysdir) { |
| 2670 | dent = readdir(sysdir); |
| 2671 | if (dent == NULL) |
| 2672 | break; |
| 2673 | name = &(dent->d_name[0]); |
| 2674 | loader_get_fullpath(name, file, sizeof(full_path), full_path); |
| 2675 | name = full_path; |
| 2676 | } |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2677 | } else { |
Johannes van Waveren | 9bd80501 | 2015-10-28 11:45:00 -0500 | [diff] [blame] | 2678 | #if defined(_WIN32) |
| 2679 | name = file; |
| 2680 | #else |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2681 | // only Linux has relative paths |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2682 | char *dir; |
| 2683 | // make a copy of location so it isn't modified |
Jason Ekstrand | cc7550e | 2015-10-10 08:33:37 -0700 | [diff] [blame] | 2684 | dir = loader_stack_alloc(strlen(loc) + 1); |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2685 | if (dir == NULL) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2686 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 2687 | "Out of memory can't get manifest files"); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2688 | goto out; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2689 | } |
Jason Ekstrand | cc7550e | 2015-10-10 08:33:37 -0700 | [diff] [blame] | 2690 | strcpy(dir, loc); |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2691 | |
| 2692 | loader_get_fullpath(file, dir, sizeof(full_path), full_path); |
| 2693 | |
| 2694 | name = full_path; |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2695 | #endif |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2696 | } |
| 2697 | while (name) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2698 | /* Look for files ending with ".json" suffix */ |
| 2699 | uint32_t nlen = (uint32_t)strlen(name); |
| 2700 | const char *suf = name + nlen - 5; |
| 2701 | if ((nlen > 5) && !strncmp(suf, ".json", 5)) { |
| 2702 | if (out_files->count == 0) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2703 | out_files->filename_list = loader_instance_heap_alloc( |
| 2704 | inst, alloced_count * sizeof(char *), |
| 2705 | VK_SYSTEM_ALLOCATION_SCOPE_COMMAND); |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2706 | } else if (out_files->count == alloced_count) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2707 | out_files->filename_list = loader_instance_heap_realloc( |
| 2708 | inst, out_files->filename_list, |
| 2709 | alloced_count * sizeof(char *), |
| 2710 | alloced_count * sizeof(char *) * 2, |
| 2711 | VK_SYSTEM_ALLOCATION_SCOPE_COMMAND); |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2712 | alloced_count *= 2; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2713 | } |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2714 | if (out_files->filename_list == NULL) { |
| 2715 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 2716 | "Out of memory can't alloc manifest file list"); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2717 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 2718 | goto out; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2719 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2720 | out_files->filename_list[out_files->count] = |
| 2721 | loader_instance_heap_alloc( |
| 2722 | inst, strlen(name) + 1, |
| 2723 | VK_SYSTEM_ALLOCATION_SCOPE_COMMAND); |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2724 | if (out_files->filename_list[out_files->count] == NULL) { |
| 2725 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 2726 | "Out of memory can't get manifest files"); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2727 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 2728 | goto out; |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2729 | } |
| 2730 | strcpy(out_files->filename_list[out_files->count], name); |
| 2731 | out_files->count++; |
| 2732 | } else if (!list_is_dirs) { |
| 2733 | loader_log( |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 2734 | inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2735 | "Skipping manifest file %s, file name must end in .json", |
| 2736 | name); |
| 2737 | } |
| 2738 | if (list_is_dirs) { |
| 2739 | dent = readdir(sysdir); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2740 | if (dent == NULL) { |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2741 | break; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2742 | } |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2743 | name = &(dent->d_name[0]); |
| 2744 | loader_get_fullpath(name, file, sizeof(full_path), full_path); |
| 2745 | name = full_path; |
| 2746 | } else { |
| 2747 | break; |
| 2748 | } |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2749 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2750 | if (sysdir) { |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2751 | closedir(sysdir); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2752 | sysdir = NULL; |
| 2753 | } |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2754 | file = next_file; |
Jon Ashburn | 67e262e | 2016-02-18 12:45:39 -0700 | [diff] [blame] | 2755 | #if !defined(_WIN32) |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 2756 | if (home_location != NULL && |
| 2757 | (next_file == NULL || *next_file == '\0') && override == NULL) { |
John Drinkwater | 9ac3f4f | 2016-08-01 17:00:00 +0100 | [diff] [blame] | 2758 | char *xdgdatahome = secure_getenv("XDG_DATA_HOME"); |
| 2759 | size_t len; |
| 2760 | if (xdgdatahome != NULL) { |
| 2761 | |
| 2762 | char *home_loc = loader_stack_alloc(strlen(xdgdatahome) + 2 + |
Jon Ashburn | 67e262e | 2016-02-18 12:45:39 -0700 | [diff] [blame] | 2763 | strlen(home_location)); |
| 2764 | if (home_loc == NULL) { |
| 2765 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 2766 | "Out of memory can't get manifest files"); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2767 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 2768 | goto out; |
Jon Ashburn | 67e262e | 2016-02-18 12:45:39 -0700 | [diff] [blame] | 2769 | } |
John Drinkwater | 9ac3f4f | 2016-08-01 17:00:00 +0100 | [diff] [blame] | 2770 | strcpy(home_loc, xdgdatahome); |
Jon Ashburn | 67e262e | 2016-02-18 12:45:39 -0700 | [diff] [blame] | 2771 | // Add directory separator if needed |
| 2772 | if (home_location[0] != DIRECTORY_SYMBOL) { |
| 2773 | len = strlen(home_loc); |
| 2774 | home_loc[len] = DIRECTORY_SYMBOL; |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 2775 | home_loc[len + 1] = '\0'; |
Jon Ashburn | 67e262e | 2016-02-18 12:45:39 -0700 | [diff] [blame] | 2776 | } |
| 2777 | strcat(home_loc, home_location); |
| 2778 | file = home_loc; |
| 2779 | next_file = loader_get_next_path(file); |
| 2780 | home_location = NULL; |
| 2781 | |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 2782 | loader_log( |
| 2783 | inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, |
John Drinkwater | 9ac3f4f | 2016-08-01 17:00:00 +0100 | [diff] [blame] | 2784 | "Searching the following path for manifest files: %s\n", |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 2785 | home_loc); |
Jon Ashburn | 67e262e | 2016-02-18 12:45:39 -0700 | [diff] [blame] | 2786 | list_is_dirs = true; |
John Drinkwater | 9ac3f4f | 2016-08-01 17:00:00 +0100 | [diff] [blame] | 2787 | |
| 2788 | } else { |
| 2789 | |
| 2790 | char *home = secure_getenv("HOME"); |
| 2791 | if (home != NULL) { |
| 2792 | char *home_loc = loader_stack_alloc(strlen(home) + 16 + |
| 2793 | strlen(home_location)); |
| 2794 | if (home_loc == NULL) { |
| 2795 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 2796 | "Out of memory can't get manifest files"); |
| 2797 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 2798 | goto out; |
| 2799 | } |
| 2800 | strcpy(home_loc, home); |
| 2801 | |
| 2802 | len = strlen(home); |
| 2803 | if (home[len] != DIRECTORY_SYMBOL) { |
| 2804 | home_loc[len] = DIRECTORY_SYMBOL; |
| 2805 | home_loc[len + 1] = '\0'; |
| 2806 | } |
| 2807 | strcat(home_loc, ".local/share"); |
| 2808 | |
| 2809 | if (home_location[0] != DIRECTORY_SYMBOL) { |
| 2810 | len = strlen(home_loc); |
| 2811 | home_loc[len] = DIRECTORY_SYMBOL; |
| 2812 | home_loc[len + 1] = '\0'; |
| 2813 | } |
| 2814 | strcat(home_loc, home_location); |
| 2815 | file = home_loc; |
| 2816 | next_file = loader_get_next_path(file); |
| 2817 | home_location = NULL; |
| 2818 | |
| 2819 | loader_log( |
| 2820 | inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, |
| 2821 | "Searching the following path for manifest files: %s\n", |
| 2822 | home_loc); |
| 2823 | list_is_dirs = true; |
| 2824 | } else { |
| 2825 | // without knowing HOME, we just.. give up |
| 2826 | } |
Jon Ashburn | 67e262e | 2016-02-18 12:45:39 -0700 | [diff] [blame] | 2827 | } |
| 2828 | } |
| 2829 | #endif |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2830 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2831 | |
| 2832 | out: |
| 2833 | if (VK_SUCCESS != res && NULL != out_files->filename_list) { |
| 2834 | for (uint32_t remove = 0; remove < out_files->count; remove++) { |
| 2835 | loader_instance_heap_free(inst, out_files->filename_list[remove]); |
| 2836 | } |
| 2837 | loader_instance_heap_free(inst, out_files->filename_list); |
| 2838 | out_files->count = 0; |
| 2839 | out_files->filename_list = NULL; |
| 2840 | } |
| 2841 | |
| 2842 | if (NULL != sysdir) { |
| 2843 | closedir(sysdir); |
| 2844 | } |
| 2845 | |
| 2846 | if (NULL != reg && reg != orig_loc) { |
| 2847 | loader_instance_heap_free(inst, reg); |
| 2848 | } |
| 2849 | return res; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2850 | } |
| 2851 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2852 | void loader_init_icd_lib_list() {} |
Jon Ashburn | 8810c5f | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 2853 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2854 | void loader_destroy_icd_lib_list() {} |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2855 | /** |
| 2856 | * Try to find the Vulkan ICD driver(s). |
| 2857 | * |
| 2858 | * This function scans the default system loader path(s) or path |
| 2859 | * specified by the \c VK_ICD_FILENAMES environment variable in |
| 2860 | * order to find loadable VK ICDs manifest files. From these |
| 2861 | * manifest files it finds the ICD libraries. |
| 2862 | * |
| 2863 | * \returns |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2864 | * Vulkan result |
| 2865 | * (on result == VK_SUCCESS) a list of icds that were discovered |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 2866 | */ |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2867 | VkResult loader_icd_scan(const struct loader_instance *inst, |
| 2868 | struct loader_icd_libs *icds) { |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2869 | char *file_str; |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2870 | uint16_t file_major_vers = 0; |
| 2871 | uint16_t file_minor_vers = 0; |
| 2872 | uint16_t file_patch_vers = 0; |
| 2873 | char *vers_tok; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2874 | struct loader_manifest_files manifest_files; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2875 | VkResult res = VK_SUCCESS; |
| 2876 | bool lockedMutex = false; |
| 2877 | cJSON *json = NULL; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 2878 | uint32_t num_good_icds = 0; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2879 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2880 | memset(&manifest_files, 0, sizeof(struct loader_manifest_files)); |
| 2881 | |
| 2882 | res = loader_scanned_icd_init(inst, icds); |
| 2883 | if (VK_SUCCESS != res) { |
| 2884 | goto out; |
| 2885 | } |
| 2886 | |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2887 | // Get a list of manifest files for ICDs |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2888 | res = loader_get_manifest_files(inst, "VK_ICD_FILENAMES", NULL, false, |
| 2889 | DEFAULT_VK_DRIVERS_INFO, |
| 2890 | HOME_VK_DRIVERS_INFO, &manifest_files); |
| 2891 | if (VK_SUCCESS != res || manifest_files.count == 0) { |
| 2892 | goto out; |
| 2893 | } |
Jon Ashburn | 6461ef2 | 2015-09-22 13:11:00 -0600 | [diff] [blame] | 2894 | loader_platform_thread_lock_mutex(&loader_json_lock); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2895 | lockedMutex = true; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2896 | for (uint32_t i = 0; i < manifest_files.count; i++) { |
| 2897 | file_str = manifest_files.filename_list[i]; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2898 | if (file_str == NULL) { |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2899 | continue; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2900 | } |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2901 | |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 2902 | res = loader_get_json(inst, file_str, &json); |
| 2903 | if (VK_ERROR_OUT_OF_HOST_MEMORY == res) { |
| 2904 | break; |
| 2905 | } else if (VK_SUCCESS != res || NULL == json) { |
Jon Ashburn | aa4ea47 | 2015-08-27 08:30:50 -0600 | [diff] [blame] | 2906 | continue; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2907 | } |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 2908 | |
Jon Ashburn | 005617f | 2015-11-17 17:35:40 -0700 | [diff] [blame] | 2909 | cJSON *item, *itemICD; |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 2910 | item = cJSON_GetObjectItem(json, "file_format_version"); |
Jon Ashburn | 6461ef2 | 2015-09-22 13:11:00 -0600 | [diff] [blame] | 2911 | if (item == NULL) { |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 2912 | if (num_good_icds == 0) { |
| 2913 | res = VK_ERROR_INITIALIZATION_FAILED; |
| 2914 | } |
Derrick Owens | 62e16ef | 2016-09-09 15:49:07 -0400 | [diff] [blame] | 2915 | cJSON_Delete(json); |
| 2916 | json = NULL; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 2917 | continue; |
Jon Ashburn | 6461ef2 | 2015-09-22 13:11:00 -0600 | [diff] [blame] | 2918 | } |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 2919 | char *file_vers = cJSON_Print(item); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2920 | if (NULL == file_vers) { |
| 2921 | // Only reason the print can fail is if there was an allocation |
| 2922 | // issue |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 2923 | if (num_good_icds == 0) { |
| 2924 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 2925 | } |
Derrick Owens | cd92b8b | 2016-09-09 15:45:13 -0400 | [diff] [blame] | 2926 | cJSON_Delete(json); |
| 2927 | json = NULL; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 2928 | continue; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2929 | } |
Mark Young | cbcbf89 | 2016-06-22 15:25:00 -0600 | [diff] [blame] | 2930 | loader_log(inst, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, |
| 2931 | "Found manifest file %s, version %s", file_str, file_vers); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2932 | // Get the major/minor/and patch as integers for easier comparison |
| 2933 | vers_tok = strtok(file_vers, ".\"\n\r"); |
| 2934 | if (NULL != vers_tok) { |
Jamie Madill | 970ebcf | 2016-07-06 11:19:42 -0400 | [diff] [blame] | 2935 | file_major_vers = (uint16_t)atoi(vers_tok); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2936 | vers_tok = strtok(NULL, ".\"\n\r"); |
| 2937 | if (NULL != vers_tok) { |
Jamie Madill | 970ebcf | 2016-07-06 11:19:42 -0400 | [diff] [blame] | 2938 | file_minor_vers = (uint16_t)atoi(vers_tok); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2939 | vers_tok = strtok(NULL, ".\"\n\r"); |
| 2940 | if (NULL != vers_tok) { |
Jamie Madill | 970ebcf | 2016-07-06 11:19:42 -0400 | [diff] [blame] | 2941 | file_patch_vers = (uint16_t)atoi(vers_tok); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2942 | } |
| 2943 | } |
| 2944 | } |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2945 | 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] | 2946 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2947 | "Unexpected manifest file version (expected 1.0.0 or " |
| 2948 | "1.0.1), may " |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2949 | "cause errors"); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2950 | cJSON_Free(file_vers); |
Jon Ashburn | 005617f | 2015-11-17 17:35:40 -0700 | [diff] [blame] | 2951 | itemICD = cJSON_GetObjectItem(json, "ICD"); |
| 2952 | if (itemICD != NULL) { |
| 2953 | item = cJSON_GetObjectItem(itemICD, "library_path"); |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 2954 | if (item != NULL) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2955 | char *temp = cJSON_Print(item); |
Jon Ashburn | 8625130 | 2015-08-25 16:48:24 -0600 | [diff] [blame] | 2956 | if (!temp || strlen(temp) == 0) { |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 2957 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2958 | "Can't find \"library_path\" in ICD JSON file " |
| 2959 | "%s, skipping", |
| 2960 | file_str); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 2961 | if (num_good_icds == 0) { |
| 2962 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 2963 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2964 | cJSON_Free(temp); |
Jon Ashburn | 8625130 | 2015-08-25 16:48:24 -0600 | [diff] [blame] | 2965 | cJSON_Delete(json); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2966 | json = NULL; |
Jon Ashburn | 8625130 | 2015-08-25 16:48:24 -0600 | [diff] [blame] | 2967 | continue; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2968 | } |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2969 | // strip out extra quotes |
Jon Ashburn | 8625130 | 2015-08-25 16:48:24 -0600 | [diff] [blame] | 2970 | temp[strlen(temp) - 1] = '\0'; |
| 2971 | char *library_path = loader_stack_alloc(strlen(temp) + 1); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 2972 | if (NULL == library_path) { |
| 2973 | loader_log( |
| 2974 | inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 2975 | "Can't allocate space for \"library_path\" in ICD " |
| 2976 | "JSON file %s, skipping", |
| 2977 | file_str); |
| 2978 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 2979 | cJSON_Free(temp); |
| 2980 | cJSON_Delete(json); |
| 2981 | json = NULL; |
| 2982 | goto out; |
| 2983 | } |
Jon Ashburn | 8625130 | 2015-08-25 16:48:24 -0600 | [diff] [blame] | 2984 | strcpy(library_path, &temp[1]); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2985 | cJSON_Free(temp); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 2986 | if (strlen(library_path) == 0) { |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 2987 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2988 | "Can't find \"library_path\" in ICD JSON file " |
| 2989 | "%s, skipping", |
| 2990 | file_str); |
Jon Ashburn | 8625130 | 2015-08-25 16:48:24 -0600 | [diff] [blame] | 2991 | cJSON_Delete(json); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2992 | json = NULL; |
Jon Ashburn | 8625130 | 2015-08-25 16:48:24 -0600 | [diff] [blame] | 2993 | continue; |
| 2994 | } |
Jamie Madill | 2fcbd15 | 2016-04-27 16:33:23 -0400 | [diff] [blame] | 2995 | char fullpath[MAX_STRING_SIZE]; |
Jon Ashburn | 8625130 | 2015-08-25 16:48:24 -0600 | [diff] [blame] | 2996 | // Print out the paths being searched if debugging is enabled |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2997 | loader_log( |
| 2998 | inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, |
Jamie Madill | 2fcbd15 | 2016-04-27 16:33:23 -0400 | [diff] [blame] | 2999 | "Searching for ICD drivers named %s default dir %s\n", |
| 3000 | library_path, DEFAULT_VK_DRIVERS_PATH); |
Daniel Dadap | 00b4aba | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 3001 | if (loader_platform_is_path(library_path)) { |
Jon Ashburn | 8625130 | 2015-08-25 16:48:24 -0600 | [diff] [blame] | 3002 | // a relative or absolute path |
Daniel Dadap | 00b4aba | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 3003 | char *name_copy = loader_stack_alloc(strlen(file_str) + 1); |
| 3004 | char *rel_base; |
Jon Ashburn | 8625130 | 2015-08-25 16:48:24 -0600 | [diff] [blame] | 3005 | strcpy(name_copy, file_str); |
| 3006 | rel_base = loader_platform_dirname(name_copy); |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3007 | loader_expand_path(library_path, rel_base, sizeof(fullpath), |
| 3008 | fullpath); |
Daniel Dadap | 00b4aba | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 3009 | } else { |
Jamie Madill | 2fcbd15 | 2016-04-27 16:33:23 -0400 | [diff] [blame] | 3010 | // a filename which is assumed in a system directory |
| 3011 | loader_get_fullpath(library_path, DEFAULT_VK_DRIVERS_PATH, |
| 3012 | sizeof(fullpath), fullpath); |
Jon Ashburn | 8625130 | 2015-08-25 16:48:24 -0600 | [diff] [blame] | 3013 | } |
Jon Ashburn | 005617f | 2015-11-17 17:35:40 -0700 | [diff] [blame] | 3014 | |
| 3015 | uint32_t vers = 0; |
| 3016 | item = cJSON_GetObjectItem(itemICD, "api_version"); |
| 3017 | if (item != NULL) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3018 | temp = cJSON_Print(item); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3019 | if (NULL == temp) { |
| 3020 | // Only reason the print can fail is if there was an |
| 3021 | // allocation issue |
| 3022 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 3023 | goto out; |
| 3024 | } |
Jon Ashburn | 005617f | 2015-11-17 17:35:40 -0700 | [diff] [blame] | 3025 | vers = loader_make_version(temp); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3026 | cJSON_Free(temp); |
Jon Ashburn | 005617f | 2015-11-17 17:35:40 -0700 | [diff] [blame] | 3027 | } |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3028 | res = loader_scanned_icd_add(inst, icds, fullpath, vers); |
| 3029 | if (VK_SUCCESS != res) { |
| 3030 | goto out; |
| 3031 | } |
| 3032 | num_good_icds++; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3033 | } else { |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 3034 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3035 | "Can't find \"library_path\" object in ICD JSON " |
| 3036 | "file %s, skipping", |
| 3037 | file_str); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3038 | } |
| 3039 | } else { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3040 | loader_log( |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 3041 | inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3042 | "Can't find \"ICD\" object in ICD JSON file %s, skipping", |
| 3043 | file_str); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3044 | } |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3045 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3046 | cJSON_Delete(json); |
| 3047 | json = NULL; |
| 3048 | } |
| 3049 | |
| 3050 | out: |
| 3051 | if (NULL != json) { |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3052 | cJSON_Delete(json); |
| 3053 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3054 | if (NULL != manifest_files.filename_list) { |
| 3055 | for (uint32_t i = 0; i < manifest_files.count; i++) { |
| 3056 | if (NULL != manifest_files.filename_list[i]) { |
| 3057 | loader_instance_heap_free(inst, |
| 3058 | manifest_files.filename_list[i]); |
| 3059 | } |
| 3060 | } |
| 3061 | loader_instance_heap_free(inst, manifest_files.filename_list); |
| 3062 | } |
| 3063 | if (lockedMutex) { |
| 3064 | loader_platform_thread_unlock_mutex(&loader_json_lock); |
| 3065 | } |
| 3066 | return res; |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 3067 | } |
| 3068 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3069 | void loader_layer_scan(const struct loader_instance *inst, |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 3070 | struct loader_layer_list *instance_layers) { |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 3071 | char *file_str; |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3072 | struct loader_manifest_files |
| 3073 | manifest_files[2]; // [0] = explicit, [1] = implicit |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 3074 | cJSON *json; |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3075 | uint32_t implicit; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3076 | bool lockedMutex = false; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 3077 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3078 | memset(manifest_files, 0, sizeof(struct loader_manifest_files) * 2); |
| 3079 | |
| 3080 | // Get a list of manifest files for explicit layers |
| 3081 | if (VK_SUCCESS != |
| 3082 | loader_get_manifest_files(inst, LAYERS_PATH_ENV, LAYERS_SOURCE_PATH, |
| 3083 | true, DEFAULT_VK_ELAYERS_INFO, |
| 3084 | HOME_VK_ELAYERS_INFO, &manifest_files[0])) { |
| 3085 | goto out; |
| 3086 | } |
| 3087 | |
| 3088 | // Get a list of manifest files for any implicit layers |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3089 | // Pass NULL for environment variable override - implicit layers are not |
| 3090 | // overridden by LAYERS_PATH_ENV |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3091 | if (VK_SUCCESS != loader_get_manifest_files( |
| 3092 | inst, NULL, NULL, true, DEFAULT_VK_ILAYERS_INFO, |
| 3093 | HOME_VK_ILAYERS_INFO, &manifest_files[1])) { |
| 3094 | goto out; |
| 3095 | } |
Jon Ashburn | 90c6a0e | 2015-06-04 15:30:58 -0600 | [diff] [blame] | 3096 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3097 | // Make sure we have at least one layer, if not, go ahead and return |
| 3098 | if (manifest_files[0].count == 0 && manifest_files[1].count == 0) { |
| 3099 | goto out; |
| 3100 | } |
| 3101 | |
| 3102 | // cleanup any previously scanned libraries |
Jon Ashburn | e39a4f8 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 3103 | loader_delete_layer_properties(inst, instance_layers); |
Jon Ashburn | b2ef137 | 2015-07-16 17:19:31 -0600 | [diff] [blame] | 3104 | |
Jon Ashburn | 6461ef2 | 2015-09-22 13:11:00 -0600 | [diff] [blame] | 3105 | loader_platform_thread_lock_mutex(&loader_json_lock); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3106 | lockedMutex = true; |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3107 | for (implicit = 0; implicit < 2; implicit++) { |
Jamie Madill | 970ebcf | 2016-07-06 11:19:42 -0400 | [diff] [blame] | 3108 | for (uint32_t i = 0; i < manifest_files[implicit].count; i++) { |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3109 | file_str = manifest_files[implicit].filename_list[i]; |
| 3110 | if (file_str == NULL) |
| 3111 | continue; |
Courtney Goeltzenleuchter | a9e4af4 | 2015-06-01 14:49:17 -0600 | [diff] [blame] | 3112 | |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3113 | // parse file into JSON struct |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3114 | VkResult res = loader_get_json(inst, file_str, &json); |
| 3115 | if (VK_ERROR_OUT_OF_HOST_MEMORY == res) { |
| 3116 | break; |
| 3117 | } else if (VK_SUCCESS != res || NULL == json) { |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3118 | continue; |
| 3119 | } |
| 3120 | |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 3121 | loader_add_layer_properties(inst, instance_layers, json, |
| 3122 | (implicit == 1), file_str); |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3123 | cJSON_Delete(json); |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 3124 | } |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 3125 | } |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 3126 | |
| 3127 | // 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] | 3128 | loader_add_layer_property_meta(inst, sizeof(std_validation_names) / |
| 3129 | sizeof(std_validation_names[0]), |
| 3130 | std_validation_names, instance_layers); |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 3131 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3132 | out: |
| 3133 | |
| 3134 | for (uint32_t manFile = 0; manFile < 2; manFile++) { |
| 3135 | if (NULL != manifest_files[manFile].filename_list) { |
| 3136 | for (uint32_t i = 0; i < manifest_files[manFile].count; i++) { |
| 3137 | if (NULL != manifest_files[manFile].filename_list[i]) { |
| 3138 | loader_instance_heap_free( |
| 3139 | inst, manifest_files[manFile].filename_list[i]); |
| 3140 | } |
| 3141 | } |
| 3142 | loader_instance_heap_free(inst, |
| 3143 | manifest_files[manFile].filename_list); |
| 3144 | } |
| 3145 | } |
| 3146 | if (lockedMutex) { |
| 3147 | loader_platform_thread_unlock_mutex(&loader_json_lock); |
| 3148 | } |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 3149 | } |
| 3150 | |
Jeremy Hayes | 3e2bd5a | 2016-04-01 11:40:26 -0600 | [diff] [blame] | 3151 | void loader_implicit_layer_scan(const struct loader_instance *inst, |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 3152 | struct loader_layer_list *instance_layers) { |
Jeremy Hayes | 3e2bd5a | 2016-04-01 11:40:26 -0600 | [diff] [blame] | 3153 | char *file_str; |
| 3154 | struct loader_manifest_files manifest_files; |
| 3155 | cJSON *json; |
| 3156 | uint32_t i; |
| 3157 | |
| 3158 | // Pass NULL for environment variable override - implicit layers are not |
| 3159 | // overridden by LAYERS_PATH_ENV |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3160 | VkResult res = loader_get_manifest_files( |
| 3161 | inst, NULL, NULL, true, DEFAULT_VK_ILAYERS_INFO, HOME_VK_ILAYERS_INFO, |
| 3162 | &manifest_files); |
| 3163 | if (VK_SUCCESS != res || manifest_files.count == 0) { |
Jeremy Hayes | 3e2bd5a | 2016-04-01 11:40:26 -0600 | [diff] [blame] | 3164 | return; |
| 3165 | } |
| 3166 | |
| 3167 | /* cleanup any previously scanned libraries */ |
| 3168 | loader_delete_layer_properties(inst, instance_layers); |
Jeremy Hayes | 3e2bd5a | 2016-04-01 11:40:26 -0600 | [diff] [blame] | 3169 | |
| 3170 | loader_platform_thread_lock_mutex(&loader_json_lock); |
| 3171 | |
| 3172 | for (i = 0; i < manifest_files.count; i++) { |
| 3173 | file_str = manifest_files.filename_list[i]; |
| 3174 | if (file_str == NULL) { |
| 3175 | continue; |
| 3176 | } |
| 3177 | |
| 3178 | // parse file into JSON struct |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3179 | res = loader_get_json(inst, file_str, &json); |
| 3180 | if (VK_ERROR_OUT_OF_HOST_MEMORY == res) { |
| 3181 | break; |
| 3182 | } else if (VK_SUCCESS != res || NULL == json) { |
Jeremy Hayes | 3e2bd5a | 2016-04-01 11:40:26 -0600 | [diff] [blame] | 3183 | continue; |
| 3184 | } |
| 3185 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3186 | loader_add_layer_properties(inst, instance_layers, json, true, |
| 3187 | file_str); |
Jeremy Hayes | 3e2bd5a | 2016-04-01 11:40:26 -0600 | [diff] [blame] | 3188 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3189 | loader_instance_heap_free(inst, file_str); |
Jeremy Hayes | 3e2bd5a | 2016-04-01 11:40:26 -0600 | [diff] [blame] | 3190 | cJSON_Delete(json); |
| 3191 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3192 | loader_instance_heap_free(inst, manifest_files.filename_list); |
Jeremy Hayes | 3e2bd5a | 2016-04-01 11:40:26 -0600 | [diff] [blame] | 3193 | |
| 3194 | // 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] | 3195 | loader_add_layer_property_meta(inst, sizeof(std_validation_names) / |
| 3196 | sizeof(std_validation_names[0]), |
| 3197 | std_validation_names, instance_layers); |
Jeremy Hayes | 3e2bd5a | 2016-04-01 11:40:26 -0600 | [diff] [blame] | 3198 | |
| 3199 | loader_platform_thread_unlock_mutex(&loader_json_lock); |
| 3200 | } |
| 3201 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3202 | static VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL |
| 3203 | loader_gpa_instance_internal(VkInstance inst, const char *pName) { |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3204 | if (!strcmp(pName, "vkGetInstanceProcAddr")) |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3205 | return (void *)loader_gpa_instance_internal; |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3206 | if (!strcmp(pName, "vkCreateInstance")) |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 3207 | return (void *)terminator_CreateInstance; |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3208 | if (!strcmp(pName, "vkCreateDevice")) |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 3209 | return (void *)terminator_CreateDevice; |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3210 | |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 3211 | // inst is not wrapped |
| 3212 | if (inst == VK_NULL_HANDLE) { |
| 3213 | return NULL; |
| 3214 | } |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3215 | VkLayerInstanceDispatchTable *disp_table = |
| 3216 | *(VkLayerInstanceDispatchTable **)inst; |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 3217 | void *addr; |
| 3218 | |
| 3219 | if (disp_table == NULL) |
| 3220 | return NULL; |
| 3221 | |
Jon Ashburn | c7d3e73 | 2016-03-08 09:30:30 -0700 | [diff] [blame] | 3222 | bool found_name; |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 3223 | addr = |
| 3224 | loader_lookup_instance_dispatch_table(disp_table, pName, &found_name); |
Jon Ashburn | c7d3e73 | 2016-03-08 09:30:30 -0700 | [diff] [blame] | 3225 | if (found_name) { |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 3226 | return addr; |
Jon Ashburn | 3d526cb | 2015-04-13 18:10:06 -0600 | [diff] [blame] | 3227 | } |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3228 | |
Jon Ashburn | c7d3e73 | 2016-03-08 09:30:30 -0700 | [diff] [blame] | 3229 | // Don't call down the chain, this would be an infinite loop |
| 3230 | loader_log(NULL, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 3231 | "loader_gpa_instance_internal() unrecognized name %s", pName); |
Jon Ashburn | c7d3e73 | 2016-03-08 09:30:30 -0700 | [diff] [blame] | 3232 | return NULL; |
Jon Ashburn | 3d526cb | 2015-04-13 18:10:06 -0600 | [diff] [blame] | 3233 | } |
| 3234 | |
Piers Daniell | 295fe40 | 2016-03-29 11:51:11 -0600 | [diff] [blame] | 3235 | static VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 3236 | loader_gpa_device_internal(VkDevice device, const char *pName) { |
| 3237 | struct loader_device *dev; |
| 3238 | struct loader_icd *icd = loader_get_icd_and_device(device, &dev); |
Piers Daniell | 295fe40 | 2016-03-29 11:51:11 -0600 | [diff] [blame] | 3239 | return icd->GetDeviceProcAddr(device, pName); |
| 3240 | } |
| 3241 | |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3242 | /** |
| 3243 | * Initialize device_ext dispatch table entry as follows: |
| 3244 | * If dev == NULL find all logical devices created within this instance and |
| 3245 | * init the entry (given by idx) in the ext dispatch table. |
| 3246 | * 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] | 3247 | * The initialization value is gotten by calling down the device chain with |
| 3248 | * GDPA. |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3249 | * If GDPA returns NULL then don't initialize the dispatch table entry. |
| 3250 | */ |
| 3251 | static void loader_init_dispatch_dev_ext_entry(struct loader_instance *inst, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3252 | struct loader_device *dev, |
| 3253 | uint32_t idx, |
| 3254 | const char *funcName) |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3255 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3256 | { |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3257 | void *gdpa_value; |
| 3258 | if (dev != NULL) { |
| 3259 | gdpa_value = dev->loader_dispatch.core_dispatch.GetDeviceProcAddr( |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3260 | dev->device, funcName); |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3261 | if (gdpa_value != NULL) |
Mark Young | 8191d9f | 2016-09-02 11:41:28 -0600 | [diff] [blame] | 3262 | dev->loader_dispatch.ext_dispatch.dev_ext[idx] = |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3263 | (PFN_vkDevExt)gdpa_value; |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3264 | } else { |
| 3265 | for (uint32_t i = 0; i < inst->total_icd_count; i++) { |
| 3266 | struct loader_icd *icd = &inst->icds[i]; |
Karl Schultz | 2558bd3 | 2016-02-24 14:39:39 -0700 | [diff] [blame] | 3267 | struct loader_device *ldev = icd->logical_device_list; |
| 3268 | while (ldev) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3269 | gdpa_value = |
Karl Schultz | 2558bd3 | 2016-02-24 14:39:39 -0700 | [diff] [blame] | 3270 | ldev->loader_dispatch.core_dispatch.GetDeviceProcAddr( |
| 3271 | ldev->device, funcName); |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3272 | if (gdpa_value != NULL) |
Mark Young | 8191d9f | 2016-09-02 11:41:28 -0600 | [diff] [blame] | 3273 | ldev->loader_dispatch.ext_dispatch.dev_ext[idx] = |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3274 | (PFN_vkDevExt)gdpa_value; |
Karl Schultz | 2558bd3 | 2016-02-24 14:39:39 -0700 | [diff] [blame] | 3275 | ldev = ldev->next; |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3276 | } |
| 3277 | } |
| 3278 | } |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3279 | } |
| 3280 | |
| 3281 | /** |
| 3282 | * Find all dev extension in the hash table and initialize the dispatch table |
| 3283 | * for dev for each of those extension entrypoints found in hash table. |
| 3284 | |
| 3285 | */ |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 3286 | void loader_init_dispatch_dev_ext(struct loader_instance *inst, |
| 3287 | struct loader_device *dev) { |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3288 | for (uint32_t i = 0; i < MAX_NUM_DEV_EXTS; i++) { |
| 3289 | if (inst->disp_hash[i].func_name != NULL) |
| 3290 | loader_init_dispatch_dev_ext_entry(inst, dev, i, |
| 3291 | inst->disp_hash[i].func_name); |
| 3292 | } |
| 3293 | } |
| 3294 | |
| 3295 | static bool loader_check_icds_for_address(struct loader_instance *inst, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3296 | const char *funcName) { |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3297 | struct loader_icd *icd; |
| 3298 | icd = inst->icds; |
| 3299 | while (icd) { |
| 3300 | if (icd->this_icd_lib->GetInstanceProcAddr(icd->instance, funcName)) |
| 3301 | // this icd supports funcName |
| 3302 | return true; |
| 3303 | icd = icd->next; |
| 3304 | } |
| 3305 | |
| 3306 | return false; |
| 3307 | } |
| 3308 | |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 3309 | static bool loader_check_layer_list_for_address( |
| 3310 | const struct loader_layer_list *const layers, const char *funcName) { |
Jeremy Hayes | 1eb1f62 | 2016-03-03 16:03:03 -0700 | [diff] [blame] | 3311 | // Iterate over the layers. |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 3312 | for (uint32_t layer = 0; layer < layers->count; ++layer) { |
Jeremy Hayes | 1eb1f62 | 2016-03-03 16:03:03 -0700 | [diff] [blame] | 3313 | // Iterate over the extensions. |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 3314 | const struct loader_device_extension_list *const extensions = |
| 3315 | &(layers->list[layer].device_extension_list); |
| 3316 | for (uint32_t extension = 0; extension < extensions->count; |
| 3317 | ++extension) { |
Jeremy Hayes | 1eb1f62 | 2016-03-03 16:03:03 -0700 | [diff] [blame] | 3318 | // Iterate over the entry points. |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 3319 | const struct loader_dev_ext_props *const property = |
| 3320 | &(extensions->list[extension]); |
| 3321 | for (uint32_t entry = 0; entry < property->entrypoint_count; |
| 3322 | ++entry) { |
| 3323 | if (strcmp(property->entrypoints[entry], funcName) == 0) { |
Jeremy Hayes | 1eb1f62 | 2016-03-03 16:03:03 -0700 | [diff] [blame] | 3324 | return true; |
| 3325 | } |
| 3326 | } |
| 3327 | } |
| 3328 | } |
| 3329 | |
| 3330 | return false; |
| 3331 | } |
| 3332 | |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 3333 | static bool |
| 3334 | loader_check_layers_for_address(const struct loader_instance *const inst, |
| 3335 | const char *funcName) { |
| 3336 | if (loader_check_layer_list_for_address(&inst->instance_layer_list, |
| 3337 | funcName)) { |
Jeremy Hayes | 1eb1f62 | 2016-03-03 16:03:03 -0700 | [diff] [blame] | 3338 | return true; |
| 3339 | } |
| 3340 | |
Jeremy Hayes | 1eb1f62 | 2016-03-03 16:03:03 -0700 | [diff] [blame] | 3341 | return false; |
| 3342 | } |
| 3343 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3344 | static void loader_free_dev_ext_table(struct loader_instance *inst) { |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3345 | for (uint32_t i = 0; i < MAX_NUM_DEV_EXTS; i++) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3346 | loader_instance_heap_free(inst, inst->disp_hash[i].func_name); |
| 3347 | loader_instance_heap_free(inst, inst->disp_hash[i].list.index); |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3348 | } |
| 3349 | memset(inst->disp_hash, 0, sizeof(inst->disp_hash)); |
| 3350 | } |
| 3351 | |
| 3352 | static bool loader_add_dev_ext_table(struct loader_instance *inst, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3353 | uint32_t *ptr_idx, const char *funcName) { |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3354 | uint32_t i; |
| 3355 | uint32_t idx = *ptr_idx; |
| 3356 | struct loader_dispatch_hash_list *list = &inst->disp_hash[idx].list; |
| 3357 | |
| 3358 | if (!inst->disp_hash[idx].func_name) { |
| 3359 | // no entry here at this idx, so use it |
| 3360 | assert(list->capacity == 0); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3361 | inst->disp_hash[idx].func_name = (char *)loader_instance_heap_alloc( |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3362 | inst, strlen(funcName) + 1, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3363 | if (inst->disp_hash[idx].func_name == NULL) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 3364 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3365 | "loader_add_dev_ext_table() can't allocate memory for " |
| 3366 | "func_name"); |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3367 | return false; |
| 3368 | } |
| 3369 | strncpy(inst->disp_hash[idx].func_name, funcName, strlen(funcName) + 1); |
| 3370 | return true; |
| 3371 | } |
| 3372 | |
| 3373 | // check for enough capacity |
| 3374 | if (list->capacity == 0) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3375 | list->index = loader_instance_heap_alloc(inst, 8 * sizeof(*(list->index)), |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3376 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
| 3377 | if (list->index == NULL) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 3378 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3379 | "loader_add_dev_ext_table() can't allocate list memory"); |
| 3380 | return false; |
| 3381 | } |
| 3382 | list->capacity = 8 * sizeof(*(list->index)); |
| 3383 | } else if (list->capacity < (list->count + 1) * sizeof(*(list->index))) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3384 | list->index = loader_instance_heap_realloc(inst, list->index, list->capacity, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3385 | list->capacity * 2, |
| 3386 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3387 | if (list->index == NULL) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3388 | loader_log( |
| 3389 | inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 3390 | "loader_add_dev_ext_table() can't reallocate list memory"); |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3391 | return false; |
| 3392 | } |
| 3393 | list->capacity *= 2; |
| 3394 | } |
| 3395 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3396 | // find an unused index in the hash table and use it |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3397 | i = (idx + 1) % MAX_NUM_DEV_EXTS; |
| 3398 | do { |
| 3399 | if (!inst->disp_hash[i].func_name) { |
| 3400 | assert(inst->disp_hash[i].list.capacity == 0); |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3401 | inst->disp_hash[i].func_name = |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3402 | (char *)loader_instance_heap_alloc(inst, strlen(funcName) + 1, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3403 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3404 | if (inst->disp_hash[i].func_name == NULL) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 3405 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3406 | "loader_add_dev_ext_table() can't rallocate " |
| 3407 | "func_name memory"); |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3408 | return false; |
| 3409 | } |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3410 | strncpy(inst->disp_hash[i].func_name, funcName, |
| 3411 | strlen(funcName) + 1); |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3412 | list->index[list->count] = i; |
| 3413 | list->count++; |
| 3414 | *ptr_idx = i; |
| 3415 | return true; |
| 3416 | } |
| 3417 | i = (i + 1) % MAX_NUM_DEV_EXTS; |
| 3418 | } while (i != idx); |
| 3419 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 3420 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3421 | "loader_add_dev_ext_table() couldn't insert into hash table; is " |
| 3422 | "it full?"); |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3423 | return false; |
| 3424 | } |
| 3425 | |
| 3426 | static bool loader_name_in_dev_ext_table(struct loader_instance *inst, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3427 | uint32_t *idx, const char *funcName) { |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3428 | uint32_t alt_idx; |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3429 | if (inst->disp_hash[*idx].func_name && |
| 3430 | !strcmp(inst->disp_hash[*idx].func_name, funcName)) |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3431 | return true; |
| 3432 | |
| 3433 | // funcName wasn't at the primary spot in the hash table |
| 3434 | // search the list of secondary locations (shallow search, not deep search) |
| 3435 | for (uint32_t i = 0; i < inst->disp_hash[*idx].list.count; i++) { |
| 3436 | alt_idx = inst->disp_hash[*idx].list.index[i]; |
| 3437 | if (!strcmp(inst->disp_hash[*idx].func_name, funcName)) { |
| 3438 | *idx = alt_idx; |
| 3439 | return true; |
| 3440 | } |
| 3441 | } |
| 3442 | |
| 3443 | return false; |
| 3444 | } |
| 3445 | |
| 3446 | /** |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3447 | * This function returns generic trampoline code address for unknown entry |
| 3448 | * points. |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3449 | * Presumably, these unknown entry points (as given by funcName) are device |
| 3450 | * extension entrypoints. A hash table is used to keep a list of unknown entry |
| 3451 | * points and their mapping to the device extension dispatch table |
| 3452 | * (struct loader_dev_ext_dispatch_table). |
| 3453 | * \returns |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3454 | * For a given entry point string (funcName), if an existing mapping is found |
| 3455 | * the |
| 3456 | * trampoline address for that mapping is returned. Otherwise, this unknown |
| 3457 | * entry point |
| 3458 | * has not been seen yet. Next check if a layer or ICD supports it. If so then |
| 3459 | * a |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3460 | * new entry in the hash table is initialized and that trampoline address for |
| 3461 | * the new entry is returned. Null is returned if the hash table is full or |
| 3462 | * if no discovered layer or ICD returns a non-NULL GetProcAddr for it. |
| 3463 | */ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3464 | void *loader_dev_ext_gpa(struct loader_instance *inst, const char *funcName) { |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3465 | uint32_t idx; |
| 3466 | uint32_t seed = 0; |
| 3467 | |
| 3468 | idx = murmurhash(funcName, strlen(funcName), seed) % MAX_NUM_DEV_EXTS; |
| 3469 | |
| 3470 | if (loader_name_in_dev_ext_table(inst, &idx, funcName)) |
| 3471 | // found funcName already in hash |
| 3472 | return loader_get_dev_ext_trampoline(idx); |
| 3473 | |
| 3474 | // Check if funcName is supported in either ICDs or a layer library |
Jeremy Hayes | 1eb1f62 | 2016-03-03 16:03:03 -0700 | [diff] [blame] | 3475 | if (!loader_check_icds_for_address(inst, funcName) && |
| 3476 | !loader_check_layers_for_address(inst, funcName)) { |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3477 | // if support found in layers continue on |
| 3478 | return NULL; |
| 3479 | } |
| 3480 | |
| 3481 | if (loader_add_dev_ext_table(inst, &idx, funcName)) { |
| 3482 | // successfully added new table entry |
| 3483 | // init any dev dispatch table entrys as needed |
| 3484 | loader_init_dispatch_dev_ext_entry(inst, NULL, idx, funcName); |
| 3485 | return loader_get_dev_ext_trampoline(idx); |
| 3486 | } |
| 3487 | |
| 3488 | return NULL; |
| 3489 | } |
| 3490 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3491 | struct loader_instance *loader_get_instance(const VkInstance instance) { |
Jon Ashburn | e0e6457 | 2015-09-30 12:56:42 -0600 | [diff] [blame] | 3492 | /* look up the loader_instance in our list by comparing dispatch tables, as |
| 3493 | * there is no guarantee the instance is still a loader_instance* after any |
| 3494 | * layers which wrap the instance object. |
| 3495 | */ |
| 3496 | const VkLayerInstanceDispatchTable *disp; |
| 3497 | struct loader_instance *ptr_instance = NULL; |
| 3498 | disp = loader_get_instance_dispatch(instance); |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3499 | for (struct loader_instance *inst = loader.instances; inst; |
| 3500 | inst = inst->next) { |
Jon Ashburn | e0e6457 | 2015-09-30 12:56:42 -0600 | [diff] [blame] | 3501 | if (inst->disp == disp) { |
| 3502 | ptr_instance = inst; |
| 3503 | break; |
| 3504 | } |
| 3505 | } |
| 3506 | return ptr_instance; |
| 3507 | } |
| 3508 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3509 | static loader_platform_dl_handle |
Jon Ashburn | 4dc1d8a | 2016-04-20 13:21:17 -0600 | [diff] [blame] | 3510 | loader_open_layer_lib(const struct loader_instance *inst, const char *chain_type, |
| 3511 | struct loader_layer_properties *prop) { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3512 | |
Jon Ashburn | 4dc1d8a | 2016-04-20 13:21:17 -0600 | [diff] [blame] | 3513 | if ((prop->lib_handle = loader_platform_open_library(prop->lib_name)) == |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3514 | NULL) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 3515 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Jon Ashburn | 4dc1d8a | 2016-04-20 13:21:17 -0600 | [diff] [blame] | 3516 | loader_platform_open_library_error(prop->lib_name)); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3517 | } else { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 3518 | loader_log(inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3519 | "Chain: %s: Loading layer library %s", chain_type, |
Jon Ashburn | 4dc1d8a | 2016-04-20 13:21:17 -0600 | [diff] [blame] | 3520 | prop->lib_name); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3521 | } |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3522 | |
Jon Ashburn | 4dc1d8a | 2016-04-20 13:21:17 -0600 | [diff] [blame] | 3523 | return prop->lib_handle; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3524 | } |
| 3525 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3526 | static void |
Jon Ashburn | 4dc1d8a | 2016-04-20 13:21:17 -0600 | [diff] [blame] | 3527 | loader_close_layer_lib(const struct loader_instance *inst, |
| 3528 | struct loader_layer_properties *prop) { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3529 | |
Jon Ashburn | 4dc1d8a | 2016-04-20 13:21:17 -0600 | [diff] [blame] | 3530 | if (prop->lib_handle) { |
| 3531 | loader_platform_close_library(prop->lib_handle); |
| 3532 | loader_log(inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, |
| 3533 | "Unloading layer library %s", prop->lib_name); |
| 3534 | prop->lib_handle = NULL; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 3535 | } |
Jon Ashburn | 4dc1d8a | 2016-04-20 13:21:17 -0600 | [diff] [blame] | 3536 | } |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 3537 | |
Jon Ashburn | 4dc1d8a | 2016-04-20 13:21:17 -0600 | [diff] [blame] | 3538 | void loader_deactivate_layers(const struct loader_instance *instance, |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3539 | struct loader_device *device, |
Jon Ashburn | 4dc1d8a | 2016-04-20 13:21:17 -0600 | [diff] [blame] | 3540 | struct loader_layer_list *list) { |
| 3541 | /* delete instance list of enabled layers and close any layer libraries */ |
| 3542 | for (uint32_t i = 0; i < list->count; i++) { |
| 3543 | struct loader_layer_properties *layer_prop = &list->list[i]; |
Courtney Goeltzenleuchter | 80bfd0e | 2015-12-17 09:51:22 -0700 | [diff] [blame] | 3544 | |
Jon Ashburn | 4dc1d8a | 2016-04-20 13:21:17 -0600 | [diff] [blame] | 3545 | loader_close_layer_lib(instance, layer_prop); |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 3546 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3547 | loader_destroy_layer_list(instance, device, list); |
Jon Ashburn | b835805 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 3548 | } |
| 3549 | |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 3550 | /** |
| 3551 | * Go through the search_list and find any layers which match type. If layer |
| 3552 | * type match is found in then add it to ext_list. |
| 3553 | */ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3554 | static void |
| 3555 | loader_add_layer_implicit(const struct loader_instance *inst, |
| 3556 | const enum layer_type type, |
| 3557 | struct loader_layer_list *list, |
| 3558 | const struct loader_layer_list *search_list) { |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3559 | bool enable; |
| 3560 | char *env_value; |
Jon Ashburn | 0c26e71 | 2015-07-02 16:10:32 -0600 | [diff] [blame] | 3561 | uint32_t i; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 3562 | for (i = 0; i < search_list->count; i++) { |
| 3563 | const struct loader_layer_properties *prop = &search_list->list[i]; |
Jon Ashburn | 0c26e71 | 2015-07-02 16:10:32 -0600 | [diff] [blame] | 3564 | if (prop->type & type) { |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3565 | /* Found an implicit layer, see if it should be enabled */ |
| 3566 | enable = false; |
| 3567 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3568 | // if no enable_environment variable is specified, this implicit |
| 3569 | // layer |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3570 | // should always be enabled. Otherwise check if the variable is set |
| 3571 | if (prop->enable_env_var.name[0] == 0) { |
| 3572 | enable = true; |
| 3573 | } else { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3574 | env_value = loader_getenv(prop->enable_env_var.name, inst); |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3575 | if (env_value && !strcmp(prop->enable_env_var.value, env_value)) |
| 3576 | enable = true; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3577 | loader_free_getenv(env_value, inst); |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3578 | } |
| 3579 | |
| 3580 | // disable_environment has priority, i.e. if both enable and disable |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3581 | // environment variables are set, the layer is disabled. Implicit |
| 3582 | // layers |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3583 | // are required to have a disable_environment variables |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3584 | env_value = loader_getenv(prop->disable_env_var.name, inst); |
| 3585 | if (env_value) { |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3586 | enable = false; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3587 | } |
| 3588 | loader_free_getenv(env_value, inst); |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3589 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3590 | if (enable) { |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3591 | loader_add_to_layer_list(inst, list, 1, prop); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3592 | } |
Jon Ashburn | 0c26e71 | 2015-07-02 16:10:32 -0600 | [diff] [blame] | 3593 | } |
| 3594 | } |
Jon Ashburn | 0c26e71 | 2015-07-02 16:10:32 -0600 | [diff] [blame] | 3595 | } |
| 3596 | |
| 3597 | /** |
| 3598 | * 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] | 3599 | * is found in search_list then add it to layer_list. But only add it to |
| 3600 | * layer_list if type matches. |
Jon Ashburn | 0c26e71 | 2015-07-02 16:10:32 -0600 | [diff] [blame] | 3601 | */ |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 3602 | static void loader_add_layer_env(struct loader_instance *inst, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3603 | const enum layer_type type, |
| 3604 | const char *env_name, |
| 3605 | struct loader_layer_list *layer_list, |
| 3606 | const struct loader_layer_list *search_list) { |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 3607 | char *layerEnv; |
Jon Ashburn | eb6d568 | 2015-07-02 14:10:53 -0600 | [diff] [blame] | 3608 | char *next, *name; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 3609 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3610 | layerEnv = loader_getenv(env_name, inst); |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 3611 | if (layerEnv == NULL) { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3612 | return; |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 3613 | } |
Courtney Goeltzenleuchter | 7f5aafc | 2015-07-05 11:28:29 -0600 | [diff] [blame] | 3614 | name = loader_stack_alloc(strlen(layerEnv) + 1); |
Jon Ashburn | eb6d568 | 2015-07-02 14:10:53 -0600 | [diff] [blame] | 3615 | if (name == NULL) { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3616 | return; |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 3617 | } |
Jon Ashburn | eb6d568 | 2015-07-02 14:10:53 -0600 | [diff] [blame] | 3618 | strcpy(name, layerEnv); |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 3619 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3620 | loader_free_getenv(layerEnv, inst); |
Jon Ashburn | 38a497f | 2016-01-04 14:01:38 -0700 | [diff] [blame] | 3621 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3622 | while (name && *name) { |
Jon Ashburn | eb6d568 | 2015-07-02 14:10:53 -0600 | [diff] [blame] | 3623 | next = loader_get_next_path(name); |
Jon Ashburn | 7148344 | 2016-02-11 18:59:43 -0700 | [diff] [blame] | 3624 | if (!strcmp(std_validation_str, name)) { |
| 3625 | /* add meta list of layers |
| 3626 | don't attempt to remove duplicate layers already added by app or |
| 3627 | env var |
| 3628 | */ |
| 3629 | loader_log(inst, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, |
| 3630 | "Expanding meta layer %s found in environment variable", |
| 3631 | std_validation_str); |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 3632 | if (type == VK_LAYER_TYPE_INSTANCE_EXPLICIT) |
| 3633 | inst->activated_layers_are_std_val = true; |
Jon Ashburn | 7148344 | 2016-02-11 18:59:43 -0700 | [diff] [blame] | 3634 | for (uint32_t i = 0; i < sizeof(std_validation_names) / |
| 3635 | sizeof(std_validation_names[0]); |
| 3636 | i++) { |
| 3637 | loader_find_layer_name_add_list(inst, std_validation_names[i], |
| 3638 | type, search_list, layer_list); |
| 3639 | } |
| 3640 | } else { |
| 3641 | loader_find_layer_name_add_list(inst, name, type, search_list, |
| 3642 | layer_list); |
| 3643 | } |
Jon Ashburn | eb6d568 | 2015-07-02 14:10:53 -0600 | [diff] [blame] | 3644 | name = next; |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 3645 | } |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 3646 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3647 | return; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 3648 | } |
| 3649 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3650 | VkResult |
| 3651 | loader_enable_instance_layers(struct loader_instance *inst, |
| 3652 | const VkInstanceCreateInfo *pCreateInfo, |
| 3653 | const struct loader_layer_list *instance_layers) { |
Courtney Goeltzenleuchter | 40caf0b | 2015-07-06 09:06:34 -0600 | [diff] [blame] | 3654 | VkResult err; |
| 3655 | |
Courtney Goeltzenleuchter | 55659b7 | 2015-09-14 18:01:17 -0600 | [diff] [blame] | 3656 | assert(inst && "Cannot have null instance"); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3657 | |
Jon Ashburn | e39a4f8 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 3658 | if (!loader_init_layer_list(inst, &inst->activated_layer_list)) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3659 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 3660 | "Failed to alloc Instance activated layer list"); |
Courtney Goeltzenleuchter | 40caf0b | 2015-07-06 09:06:34 -0600 | [diff] [blame] | 3661 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Jon Ashburn | bd6c488 | 2015-07-02 12:59:25 -0600 | [diff] [blame] | 3662 | } |
| 3663 | |
Jon Ashburn | 0c26e71 | 2015-07-02 16:10:32 -0600 | [diff] [blame] | 3664 | /* Add any implicit layers first */ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3665 | loader_add_layer_implicit(inst, VK_LAYER_TYPE_INSTANCE_IMPLICIT, |
| 3666 | &inst->activated_layer_list, instance_layers); |
Jon Ashburn | 0c26e71 | 2015-07-02 16:10:32 -0600 | [diff] [blame] | 3667 | |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 3668 | /* Add any layers specified via environment variable next */ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3669 | loader_add_layer_env(inst, VK_LAYER_TYPE_INSTANCE_EXPLICIT, |
| 3670 | "VK_INSTANCE_LAYERS", &inst->activated_layer_list, |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3671 | instance_layers); |
Jon Ashburn | bd6c488 | 2015-07-02 12:59:25 -0600 | [diff] [blame] | 3672 | |
| 3673 | /* Add layers specified by the application */ |
Courtney Goeltzenleuchter | 40caf0b | 2015-07-06 09:06:34 -0600 | [diff] [blame] | 3674 | err = loader_add_layer_names_to_list( |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3675 | inst, &inst->activated_layer_list, pCreateInfo->enabledLayerCount, |
| 3676 | pCreateInfo->ppEnabledLayerNames, instance_layers); |
Courtney Goeltzenleuchter | 40caf0b | 2015-07-06 09:06:34 -0600 | [diff] [blame] | 3677 | |
| 3678 | return err; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3679 | } |
| 3680 | |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3681 | /* |
| 3682 | * Given the list of layers to activate in the loader_instance |
| 3683 | * structure. This function will add a VkLayerInstanceCreateInfo |
| 3684 | * structure to the VkInstanceCreateInfo.pNext pointer. |
| 3685 | * Each activated layer will have it's own VkLayerInstanceLink |
| 3686 | * structure that tells the layer what Get*ProcAddr to call to |
| 3687 | * get function pointers to the next layer down. |
| 3688 | * Once the chain info has been created this function will |
| 3689 | * execute the CreateInstance call chain. Each layer will |
| 3690 | * then have an opportunity in it's CreateInstance function |
| 3691 | * to setup it's dispatch table when the lower layer returns |
| 3692 | * successfully. |
| 3693 | * Each layer can wrap or not-wrap the returned VkInstance object |
| 3694 | * as it sees fit. |
| 3695 | * The instance chain is terminated by a loader function |
| 3696 | * that will call CreateInstance on all available ICD's and |
| 3697 | * cache those VkInstance objects for future use. |
| 3698 | */ |
| 3699 | VkResult loader_create_instance_chain(const VkInstanceCreateInfo *pCreateInfo, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3700 | const VkAllocationCallbacks *pAllocator, |
Jon Ashburn | 373c180 | 2016-01-20 08:08:25 -0700 | [diff] [blame] | 3701 | struct loader_instance *inst, |
Jon Ashburn | 6e0a213 | 2016-02-03 12:37:30 -0700 | [diff] [blame] | 3702 | VkInstance *created_instance) { |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3703 | uint32_t activated_layers = 0; |
| 3704 | VkLayerInstanceCreateInfo chain_info; |
| 3705 | VkLayerInstanceLink *layer_instance_link_info = NULL; |
| 3706 | VkInstanceCreateInfo loader_create_info; |
| 3707 | VkResult res; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3708 | |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3709 | PFN_vkGetInstanceProcAddr nextGIPA = loader_gpa_instance_internal; |
| 3710 | PFN_vkGetInstanceProcAddr fpGIPA = loader_gpa_instance_internal; |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 3711 | |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3712 | memcpy(&loader_create_info, pCreateInfo, sizeof(VkInstanceCreateInfo)); |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 3713 | |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3714 | if (inst->activated_layer_list.count > 0) { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3715 | |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3716 | chain_info.u.pLayerInfo = NULL; |
| 3717 | chain_info.pNext = pCreateInfo->pNext; |
| 3718 | chain_info.sType = VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO; |
| 3719 | chain_info.function = VK_LAYER_LINK_INFO; |
| 3720 | loader_create_info.pNext = &chain_info; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3721 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3722 | layer_instance_link_info = loader_stack_alloc( |
| 3723 | sizeof(VkLayerInstanceLink) * inst->activated_layer_list.count); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3724 | if (!layer_instance_link_info) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3725 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 3726 | "Failed to alloc Instance objects for layer"); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3727 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 3728 | } |
| 3729 | |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3730 | /* Create instance chain of enabled layers */ |
| 3731 | 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] | 3732 | struct loader_layer_properties *layer_prop = |
| 3733 | &inst->activated_layer_list.list[i]; |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3734 | loader_platform_dl_handle lib_handle; |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 3735 | |
Jon Ashburn | 4dc1d8a | 2016-04-20 13:21:17 -0600 | [diff] [blame] | 3736 | lib_handle = loader_open_layer_lib(inst, "instance", layer_prop); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3737 | if (!lib_handle) |
Courtney Goeltzenleuchter | 524b7e3 | 2016-01-14 16:06:06 -0700 | [diff] [blame] | 3738 | continue; |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3739 | if ((fpGIPA = layer_prop->functions.get_instance_proc_addr) == |
| 3740 | NULL) { |
| 3741 | if (layer_prop->functions.str_gipa == NULL || |
| 3742 | strlen(layer_prop->functions.str_gipa) == 0) { |
| 3743 | fpGIPA = (PFN_vkGetInstanceProcAddr) |
| 3744 | loader_platform_get_proc_address( |
| 3745 | lib_handle, "vkGetInstanceProcAddr"); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3746 | layer_prop->functions.get_instance_proc_addr = fpGIPA; |
| 3747 | } else |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3748 | fpGIPA = (PFN_vkGetInstanceProcAddr) |
| 3749 | loader_platform_get_proc_address( |
| 3750 | lib_handle, layer_prop->functions.str_gipa); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3751 | if (!fpGIPA) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3752 | loader_log( |
| 3753 | inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 3754 | "Failed to find vkGetInstanceProcAddr in layer %s", |
| 3755 | layer_prop->lib_name); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3756 | continue; |
| 3757 | } |
| 3758 | } |
| 3759 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3760 | layer_instance_link_info[activated_layers].pNext = |
| 3761 | chain_info.u.pLayerInfo; |
| 3762 | layer_instance_link_info[activated_layers] |
| 3763 | .pfnNextGetInstanceProcAddr = nextGIPA; |
| 3764 | chain_info.u.pLayerInfo = |
| 3765 | &layer_instance_link_info[activated_layers]; |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3766 | nextGIPA = fpGIPA; |
| 3767 | |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 3768 | loader_log(inst, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3769 | "Insert instance layer %s (%s)", |
| 3770 | layer_prop->info.layerName, layer_prop->lib_name); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3771 | |
| 3772 | activated_layers++; |
| 3773 | } |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 3774 | } |
| 3775 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3776 | PFN_vkCreateInstance fpCreateInstance = |
Jon Ashburn | 6e0a213 | 2016-02-03 12:37:30 -0700 | [diff] [blame] | 3777 | (PFN_vkCreateInstance)nextGIPA(*created_instance, "vkCreateInstance"); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3778 | if (fpCreateInstance) { |
Jon Ashburn | c3c5877 | 2016-03-29 11:16:01 -0600 | [diff] [blame] | 3779 | VkLayerInstanceCreateInfo create_info_disp; |
| 3780 | |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 3781 | create_info_disp.sType = VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO; |
Jon Ashburn | ed8f231 | 2016-03-31 10:52:22 -0600 | [diff] [blame] | 3782 | create_info_disp.function = VK_LOADER_DATA_CALLBACK; |
Jon Ashburn | c3c5877 | 2016-03-29 11:16:01 -0600 | [diff] [blame] | 3783 | |
| 3784 | create_info_disp.u.pfnSetInstanceLoaderData = vkSetInstanceDispatch; |
| 3785 | |
| 3786 | create_info_disp.pNext = loader_create_info.pNext; |
| 3787 | loader_create_info.pNext = &create_info_disp; |
Jon Ashburn | f2b4e38 | 2016-02-10 20:50:19 -0700 | [diff] [blame] | 3788 | res = |
| 3789 | fpCreateInstance(&loader_create_info, pAllocator, created_instance); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3790 | } else { |
| 3791 | // Couldn't find CreateInstance function! |
| 3792 | res = VK_ERROR_INITIALIZATION_FAILED; |
| 3793 | } |
| 3794 | |
| 3795 | if (res != VK_SUCCESS) { |
| 3796 | // TODO: Need to clean up here |
| 3797 | } else { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3798 | loader_init_instance_core_dispatch_table(inst->disp, nextGIPA, |
Jon Ashburn | 6e0a213 | 2016-02-03 12:37:30 -0700 | [diff] [blame] | 3799 | *created_instance); |
Jon Ashburn | 4e8c416 | 2016-03-08 15:21:30 -0700 | [diff] [blame] | 3800 | inst->instance = *created_instance; |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3801 | } |
| 3802 | |
| 3803 | return res; |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 3804 | } |
| 3805 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3806 | void loader_activate_instance_layer_extensions(struct loader_instance *inst, |
| 3807 | VkInstance created_inst) { |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 3808 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3809 | loader_init_instance_extension_dispatch_table( |
| 3810 | inst->disp, inst->disp->GetInstanceProcAddr, created_inst); |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 3811 | } |
| 3812 | |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 3813 | VkResult |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 3814 | loader_create_device_chain(const struct loader_physical_device_tramp *pd, |
| 3815 | const VkDeviceCreateInfo *pCreateInfo, |
| 3816 | const VkAllocationCallbacks *pAllocator, |
| 3817 | const struct loader_instance *inst, |
| 3818 | struct loader_device *dev) { |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3819 | uint32_t activated_layers = 0; |
| 3820 | VkLayerDeviceLink *layer_device_link_info; |
| 3821 | VkLayerDeviceCreateInfo chain_info; |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3822 | VkDeviceCreateInfo loader_create_info; |
| 3823 | VkResult res; |
Courtney Goeltzenleuchter | ca173b8 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 3824 | |
Piers Daniell | 295fe40 | 2016-03-29 11:51:11 -0600 | [diff] [blame] | 3825 | PFN_vkGetDeviceProcAddr fpGDPA, nextGDPA = loader_gpa_device_internal; |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3826 | PFN_vkGetInstanceProcAddr fpGIPA, nextGIPA = loader_gpa_instance_internal; |
Courtney Goeltzenleuchter | ca173b8 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 3827 | |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3828 | memcpy(&loader_create_info, pCreateInfo, sizeof(VkDeviceCreateInfo)); |
| 3829 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3830 | layer_device_link_info = loader_stack_alloc( |
| 3831 | sizeof(VkLayerDeviceLink) * dev->activated_layer_list.count); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3832 | if (!layer_device_link_info) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3833 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 3834 | "Failed to alloc Device objects for layer"); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3835 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
David Pinedo | a0a8a24 | 2015-06-24 15:29:18 -0600 | [diff] [blame] | 3836 | } |
Jon Ashburn | 94e7049 | 2015-06-10 10:13:10 -0600 | [diff] [blame] | 3837 | |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3838 | if (dev->activated_layer_list.count > 0) { |
Jon Ashburn | 72690f2 | 2016-03-29 12:52:13 -0600 | [diff] [blame] | 3839 | chain_info.sType = VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO; |
| 3840 | chain_info.function = VK_LAYER_LINK_INFO; |
| 3841 | chain_info.u.pLayerInfo = NULL; |
| 3842 | chain_info.pNext = pCreateInfo->pNext; |
| 3843 | loader_create_info.pNext = &chain_info; |
| 3844 | |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3845 | /* Create instance chain of enabled layers */ |
| 3846 | 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] | 3847 | struct loader_layer_properties *layer_prop = |
| 3848 | &dev->activated_layer_list.list[i]; |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3849 | loader_platform_dl_handle lib_handle; |
Courtney Goeltzenleuchter | ca173b8 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 3850 | |
Jon Ashburn | 4dc1d8a | 2016-04-20 13:21:17 -0600 | [diff] [blame] | 3851 | lib_handle = loader_open_layer_lib(inst, "device", layer_prop); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3852 | if (!lib_handle) |
Courtney Goeltzenleuchter | 524b7e3 | 2016-01-14 16:06:06 -0700 | [diff] [blame] | 3853 | continue; |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3854 | if ((fpGIPA = layer_prop->functions.get_instance_proc_addr) == |
| 3855 | NULL) { |
| 3856 | if (layer_prop->functions.str_gipa == NULL || |
| 3857 | strlen(layer_prop->functions.str_gipa) == 0) { |
| 3858 | fpGIPA = (PFN_vkGetInstanceProcAddr) |
| 3859 | loader_platform_get_proc_address( |
| 3860 | lib_handle, "vkGetInstanceProcAddr"); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3861 | layer_prop->functions.get_instance_proc_addr = fpGIPA; |
| 3862 | } else |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3863 | fpGIPA = (PFN_vkGetInstanceProcAddr) |
| 3864 | loader_platform_get_proc_address( |
| 3865 | lib_handle, layer_prop->functions.str_gipa); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3866 | if (!fpGIPA) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3867 | loader_log( |
| 3868 | inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 3869 | "Failed to find vkGetInstanceProcAddr in layer %s", |
| 3870 | layer_prop->lib_name); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3871 | continue; |
| 3872 | } |
Jon Ashburn | 21c21ee | 2015-09-09 11:29:24 -0600 | [diff] [blame] | 3873 | } |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3874 | if ((fpGDPA = layer_prop->functions.get_device_proc_addr) == NULL) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3875 | if (layer_prop->functions.str_gdpa == NULL || |
| 3876 | strlen(layer_prop->functions.str_gdpa) == 0) { |
| 3877 | fpGDPA = (PFN_vkGetDeviceProcAddr) |
| 3878 | loader_platform_get_proc_address(lib_handle, |
| 3879 | "vkGetDeviceProcAddr"); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3880 | layer_prop->functions.get_device_proc_addr = fpGDPA; |
| 3881 | } else |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3882 | fpGDPA = (PFN_vkGetDeviceProcAddr) |
| 3883 | loader_platform_get_proc_address( |
| 3884 | lib_handle, layer_prop->functions.str_gdpa); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3885 | if (!fpGDPA) { |
Jon Ashburn | c0dc07c | 2016-05-16 17:35:43 -0600 | [diff] [blame] | 3886 | loader_log(inst, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3887 | "Failed to find vkGetDeviceProcAddr in layer %s", |
| 3888 | layer_prop->lib_name); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3889 | continue; |
| 3890 | } |
| 3891 | } |
| 3892 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3893 | layer_device_link_info[activated_layers].pNext = |
| 3894 | chain_info.u.pLayerInfo; |
| 3895 | layer_device_link_info[activated_layers] |
| 3896 | .pfnNextGetInstanceProcAddr = nextGIPA; |
| 3897 | layer_device_link_info[activated_layers].pfnNextGetDeviceProcAddr = |
| 3898 | nextGDPA; |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3899 | chain_info.u.pLayerInfo = &layer_device_link_info[activated_layers]; |
| 3900 | nextGIPA = fpGIPA; |
| 3901 | nextGDPA = fpGDPA; |
| 3902 | |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 3903 | loader_log(inst, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3904 | "Insert device layer %s (%s)", |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3905 | layer_prop->info.layerName, layer_prop->lib_name); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3906 | |
| 3907 | activated_layers++; |
Jon Ashburn | 94e7049 | 2015-06-10 10:13:10 -0600 | [diff] [blame] | 3908 | } |
Jon Ashburn | 94e7049 | 2015-06-10 10:13:10 -0600 | [diff] [blame] | 3909 | } |
| 3910 | |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 3911 | VkDevice created_device = (VkDevice)dev; |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3912 | PFN_vkCreateDevice fpCreateDevice = |
Jon Ashburn | 4e8c416 | 2016-03-08 15:21:30 -0700 | [diff] [blame] | 3913 | (PFN_vkCreateDevice)nextGIPA(inst->instance, "vkCreateDevice"); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3914 | if (fpCreateDevice) { |
Jon Ashburn | ed8f231 | 2016-03-31 10:52:22 -0600 | [diff] [blame] | 3915 | VkLayerDeviceCreateInfo create_info_disp; |
| 3916 | |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 3917 | create_info_disp.sType = VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO; |
Jon Ashburn | ed8f231 | 2016-03-31 10:52:22 -0600 | [diff] [blame] | 3918 | create_info_disp.function = VK_LOADER_DATA_CALLBACK; |
| 3919 | |
| 3920 | create_info_disp.u.pfnSetDeviceLoaderData = vkSetDeviceDispatch; |
| 3921 | |
| 3922 | create_info_disp.pNext = loader_create_info.pNext; |
| 3923 | loader_create_info.pNext = &create_info_disp; |
Jon Ashburn | 014438f | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 3924 | res = fpCreateDevice(pd->phys_dev, &loader_create_info, pAllocator, |
Jon Ashburn | 72690f2 | 2016-03-29 12:52:13 -0600 | [diff] [blame] | 3925 | &created_device); |
Piers Daniell | efbbfc1 | 2016-04-05 17:28:06 -0600 | [diff] [blame] | 3926 | if (res != VK_SUCCESS) { |
| 3927 | return res; |
| 3928 | } |
Jon Ashburn | 72690f2 | 2016-03-29 12:52:13 -0600 | [diff] [blame] | 3929 | dev->device = created_device; |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3930 | } else { |
| 3931 | // Couldn't find CreateDevice function! |
| 3932 | return VK_ERROR_INITIALIZATION_FAILED; |
| 3933 | } |
Jon Ashburn | 94e7049 | 2015-06-10 10:13:10 -0600 | [diff] [blame] | 3934 | |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3935 | /* Initialize device dispatch table */ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3936 | loader_init_device_dispatch_table(&dev->loader_dispatch, nextGDPA, |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3937 | dev->device); |
| 3938 | |
| 3939 | return res; |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 3940 | } |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 3941 | |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 3942 | VkResult loader_validate_layers(const struct loader_instance *inst, |
| 3943 | const uint32_t layer_count, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3944 | const char *const *ppEnabledLayerNames, |
| 3945 | const struct loader_layer_list *list) { |
Courtney Goeltzenleuchter | 3b8c5ff | 2015-07-06 17:45:08 -0600 | [diff] [blame] | 3946 | struct loader_layer_properties *prop; |
| 3947 | |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 3948 | for (uint32_t i = 0; i < layer_count; i++) { |
Jon Ashburn | f2b4e38 | 2016-02-10 20:50:19 -0700 | [diff] [blame] | 3949 | VkStringErrorFlags result = |
| 3950 | vk_string_validate(MaxLoaderStringLength, ppEnabledLayerNames[i]); |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 3951 | if (result != VK_STRING_ERROR_NONE) { |
| 3952 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Jon Ashburn | f2b4e38 | 2016-02-10 20:50:19 -0700 | [diff] [blame] | 3953 | "Loader: Device ppEnabledLayerNames contains string " |
| 3954 | "that is too long or is badly formed"); |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 3955 | return VK_ERROR_LAYER_NOT_PRESENT; |
| 3956 | } |
| 3957 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3958 | prop = loader_get_layer_property(ppEnabledLayerNames[i], list); |
Courtney Goeltzenleuchter | 3b8c5ff | 2015-07-06 17:45:08 -0600 | [diff] [blame] | 3959 | if (!prop) { |
Courtney Goeltzenleuchter | 55659b7 | 2015-09-14 18:01:17 -0600 | [diff] [blame] | 3960 | return VK_ERROR_LAYER_NOT_PRESENT; |
Courtney Goeltzenleuchter | 3b8c5ff | 2015-07-06 17:45:08 -0600 | [diff] [blame] | 3961 | } |
| 3962 | } |
Courtney Goeltzenleuchter | 3b8c5ff | 2015-07-06 17:45:08 -0600 | [diff] [blame] | 3963 | return VK_SUCCESS; |
| 3964 | } |
| 3965 | |
| 3966 | VkResult loader_validate_instance_extensions( |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 3967 | const struct loader_instance *inst, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3968 | const struct loader_extension_list *icd_exts, |
| 3969 | const struct loader_layer_list *instance_layer, |
| 3970 | const VkInstanceCreateInfo *pCreateInfo) { |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 3971 | |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 3972 | VkExtensionProperties *extension_prop; |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 3973 | struct loader_layer_properties *layer_prop; |
| 3974 | |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 3975 | for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) { |
Jon Ashburn | f2b4e38 | 2016-02-10 20:50:19 -0700 | [diff] [blame] | 3976 | VkStringErrorFlags result = vk_string_validate( |
| 3977 | MaxLoaderStringLength, pCreateInfo->ppEnabledExtensionNames[i]); |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 3978 | if (result != VK_STRING_ERROR_NONE) { |
| 3979 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Jon Ashburn | f2b4e38 | 2016-02-10 20:50:19 -0700 | [diff] [blame] | 3980 | "Loader: Instance ppEnabledExtensionNames contains " |
| 3981 | "string that is too long or is badly formed"); |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 3982 | return VK_ERROR_EXTENSION_NOT_PRESENT; |
| 3983 | } |
| 3984 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3985 | extension_prop = get_extension_property( |
| 3986 | pCreateInfo->ppEnabledExtensionNames[i], icd_exts); |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 3987 | |
| 3988 | if (extension_prop) { |
| 3989 | continue; |
| 3990 | } |
| 3991 | |
| 3992 | extension_prop = NULL; |
| 3993 | |
| 3994 | /* Not in global list, search layer extension lists */ |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 3995 | for (uint32_t j = 0; j < pCreateInfo->enabledLayerCount; j++) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3996 | layer_prop = loader_get_layer_property( |
| 3997 | pCreateInfo->ppEnabledLayerNames[i], instance_layer); |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 3998 | if (!layer_prop) { |
Courtney Goeltzenleuchter | 6f5b00c | 2015-07-06 20:46:50 -0600 | [diff] [blame] | 3999 | /* Should NOT get here, loader_validate_layers |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 4000 | * should have already filtered this case out. |
| 4001 | */ |
| 4002 | continue; |
| 4003 | } |
| 4004 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4005 | extension_prop = |
| 4006 | get_extension_property(pCreateInfo->ppEnabledExtensionNames[i], |
| 4007 | &layer_prop->instance_extension_list); |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 4008 | if (extension_prop) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4009 | /* Found the extension in one of the layers enabled by the app. |
| 4010 | */ |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 4011 | break; |
| 4012 | } |
| 4013 | } |
| 4014 | |
| 4015 | if (!extension_prop) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4016 | /* Didn't find extension name in any of the global layers, error out |
| 4017 | */ |
Courtney Goeltzenleuchter | 55659b7 | 2015-09-14 18:01:17 -0600 | [diff] [blame] | 4018 | return VK_ERROR_EXTENSION_NOT_PRESENT; |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 4019 | } |
| 4020 | } |
| 4021 | return VK_SUCCESS; |
| 4022 | } |
| 4023 | |
| 4024 | VkResult loader_validate_device_extensions( |
Jon Ashburn | 787eb25 | 2016-03-24 15:49:57 -0600 | [diff] [blame] | 4025 | struct loader_physical_device_tramp *phys_dev, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4026 | const struct loader_layer_list *activated_device_layers, |
Jon Ashburn | 014438f | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 4027 | const struct loader_extension_list *icd_exts, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4028 | const VkDeviceCreateInfo *pCreateInfo) { |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 4029 | VkExtensionProperties *extension_prop; |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 4030 | struct loader_layer_properties *layer_prop; |
| 4031 | |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 4032 | for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) { |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 4033 | |
Jon Ashburn | f2b4e38 | 2016-02-10 20:50:19 -0700 | [diff] [blame] | 4034 | VkStringErrorFlags result = vk_string_validate( |
| 4035 | MaxLoaderStringLength, pCreateInfo->ppEnabledExtensionNames[i]); |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 4036 | if (result != VK_STRING_ERROR_NONE) { |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 4037 | loader_log(phys_dev->this_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4038 | 0, "Loader: Device ppEnabledExtensionNames contains " |
| 4039 | "string that is too long or is badly formed"); |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 4040 | return VK_ERROR_EXTENSION_NOT_PRESENT; |
| 4041 | } |
| 4042 | |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 4043 | const char *extension_name = pCreateInfo->ppEnabledExtensionNames[i]; |
Jon Ashburn | 014438f | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 4044 | extension_prop = get_extension_property(extension_name, icd_exts); |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 4045 | |
| 4046 | if (extension_prop) { |
| 4047 | continue; |
| 4048 | } |
| 4049 | |
Jon Ashburn | 471f44c | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 4050 | /* Not in global list, search activated layer extension lists */ |
| 4051 | for (uint32_t j = 0; j < activated_device_layers->count; j++) { |
| 4052 | layer_prop = &activated_device_layers->list[j]; |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 4053 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4054 | extension_prop = get_dev_extension_property( |
| 4055 | extension_name, &layer_prop->device_extension_list); |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 4056 | if (extension_prop) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4057 | /* Found the extension in one of the layers enabled by the app. |
| 4058 | */ |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 4059 | break; |
| 4060 | } |
| 4061 | } |
| 4062 | |
| 4063 | if (!extension_prop) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4064 | /* Didn't find extension name in any of the device layers, error out |
| 4065 | */ |
Courtney Goeltzenleuchter | 55659b7 | 2015-09-14 18:01:17 -0600 | [diff] [blame] | 4066 | return VK_ERROR_EXTENSION_NOT_PRESENT; |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 4067 | } |
| 4068 | } |
Courtney Goeltzenleuchter | 3b8c5ff | 2015-07-06 17:45:08 -0600 | [diff] [blame] | 4069 | return VK_SUCCESS; |
| 4070 | } |
| 4071 | |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 4072 | /** |
| 4073 | * Terminator functions for the Instance chain |
| 4074 | * All named terminator_<Vulakn API name> |
| 4075 | */ |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4076 | VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateInstance( |
| 4077 | const VkInstanceCreateInfo *pCreateInfo, |
| 4078 | const VkAllocationCallbacks *pAllocator, VkInstance *pInstance) { |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 4079 | struct loader_icd *icd; |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 4080 | VkExtensionProperties *prop; |
Courtney Goeltzenleuchter | 746db73 | 2015-07-06 17:42:01 -0600 | [diff] [blame] | 4081 | char **filtered_extension_names = NULL; |
| 4082 | VkInstanceCreateInfo icd_create_info; |
Courtney Goeltzenleuchter | 40caf0b | 2015-07-06 09:06:34 -0600 | [diff] [blame] | 4083 | VkResult res = VK_SUCCESS; |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 4084 | |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 4085 | struct loader_instance *ptr_instance = (struct loader_instance *)*pInstance; |
Tony Barbour | 3c78ff4 | 2015-12-04 13:24:39 -0700 | [diff] [blame] | 4086 | memcpy(&icd_create_info, pCreateInfo, sizeof(icd_create_info)); |
| 4087 | |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 4088 | icd_create_info.enabledLayerCount = 0; |
Courtney Goeltzenleuchter | 746db73 | 2015-07-06 17:42:01 -0600 | [diff] [blame] | 4089 | icd_create_info.ppEnabledLayerNames = NULL; |
Courtney Goeltzenleuchter | 746db73 | 2015-07-06 17:42:01 -0600 | [diff] [blame] | 4090 | |
| 4091 | /* |
| 4092 | * NOTE: Need to filter the extensions to only those |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 4093 | * supported by the ICD. |
Courtney Goeltzenleuchter | 746db73 | 2015-07-06 17:42:01 -0600 | [diff] [blame] | 4094 | * No ICD will advertise support for layers. An ICD |
| 4095 | * library could support a layer, but it would be |
| 4096 | * independent of the actual ICD, just in the same library. |
| 4097 | */ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4098 | filtered_extension_names = |
| 4099 | loader_stack_alloc(pCreateInfo->enabledExtensionCount * sizeof(char *)); |
Courtney Goeltzenleuchter | 746db73 | 2015-07-06 17:42:01 -0600 | [diff] [blame] | 4100 | if (!filtered_extension_names) { |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 4101 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 4102 | goto out; |
Courtney Goeltzenleuchter | 746db73 | 2015-07-06 17:42:01 -0600 | [diff] [blame] | 4103 | } |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4104 | icd_create_info.ppEnabledExtensionNames = |
| 4105 | (const char *const *)filtered_extension_names; |
Courtney Goeltzenleuchter | 746db73 | 2015-07-06 17:42:01 -0600 | [diff] [blame] | 4106 | |
Jon Ashburn | 8810c5f | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 4107 | for (uint32_t i = 0; i < ptr_instance->icd_libs.count; i++) { |
| 4108 | icd = loader_icd_add(ptr_instance, &ptr_instance->icd_libs.list[i]); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4109 | if (NULL == icd) { |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 4110 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 4111 | goto out; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4112 | } |
| 4113 | icd_create_info.enabledExtensionCount = 0; |
| 4114 | struct loader_extension_list icd_exts; |
Courtney Goeltzenleuchter | 746db73 | 2015-07-06 17:42:01 -0600 | [diff] [blame] | 4115 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4116 | loader_log(ptr_instance, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, |
| 4117 | "Build ICD instance extension list"); |
| 4118 | // traverse scanned icd list adding non-duplicate extensions to the |
| 4119 | // list |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 4120 | res = loader_init_generic_list(ptr_instance, |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4121 | (struct loader_generic_list *)&icd_exts, |
| 4122 | sizeof(VkExtensionProperties)); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 4123 | if (VK_ERROR_OUT_OF_HOST_MEMORY == res) { |
| 4124 | // If out of memory, bail immediately. |
| 4125 | goto out; |
| 4126 | } else if (VK_SUCCESS != res) { |
Mark Young | 7e47129 | 2016-09-06 09:53:45 -0600 | [diff] [blame] | 4127 | // Something bad happened with this ICD, so free it and try the |
| 4128 | // next. |
| 4129 | ptr_instance->icds = icd->next; |
Mark Young | db13a2a | 2016-09-06 13:53:03 -0600 | [diff] [blame] | 4130 | icd->next = NULL; |
Mark Young | 7e47129 | 2016-09-06 09:53:45 -0600 | [diff] [blame] | 4131 | loader_icd_destroy(ptr_instance, icd, pAllocator); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 4132 | continue; |
| 4133 | } |
| 4134 | |
| 4135 | res = loader_add_instance_extensions( |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4136 | ptr_instance, |
| 4137 | icd->this_icd_lib->EnumerateInstanceExtensionProperties, |
| 4138 | icd->this_icd_lib->lib_name, &icd_exts); |
Mark Young | db13a2a | 2016-09-06 13:53:03 -0600 | [diff] [blame] | 4139 | if (VK_SUCCESS != res) { |
| 4140 | loader_destroy_generic_list(ptr_instance, |
| 4141 | (struct loader_generic_list *)&icd_exts); |
| 4142 | if (VK_ERROR_OUT_OF_HOST_MEMORY == res) { |
| 4143 | // If out of memory, bail immediately. |
| 4144 | goto out; |
| 4145 | } else { |
| 4146 | // Something bad happened with this ICD, so free it and try |
| 4147 | // the next. |
| 4148 | ptr_instance->icds = icd->next; |
| 4149 | icd->next = NULL; |
| 4150 | loader_icd_destroy(ptr_instance, icd, pAllocator); |
| 4151 | continue; |
| 4152 | } |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 4153 | } |
Courtney Goeltzenleuchter | 36eeb74 | 2015-12-21 16:41:47 -0700 | [diff] [blame] | 4154 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4155 | for (uint32_t j = 0; j < pCreateInfo->enabledExtensionCount; j++) { |
| 4156 | prop = get_extension_property( |
| 4157 | pCreateInfo->ppEnabledExtensionNames[j], &icd_exts); |
| 4158 | if (prop) { |
| 4159 | filtered_extension_names[icd_create_info |
| 4160 | .enabledExtensionCount] = |
| 4161 | (char *)pCreateInfo->ppEnabledExtensionNames[j]; |
| 4162 | icd_create_info.enabledExtensionCount++; |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 4163 | } |
| 4164 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4165 | |
| 4166 | loader_destroy_generic_list(ptr_instance, |
| 4167 | (struct loader_generic_list *)&icd_exts); |
| 4168 | |
| 4169 | res = ptr_instance->icd_libs.list[i].CreateInstance( |
| 4170 | &icd_create_info, pAllocator, &(icd->instance)); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 4171 | if (VK_ERROR_OUT_OF_HOST_MEMORY == res) { |
| 4172 | // If out of memory, bail immediately. |
| 4173 | goto out; |
| 4174 | } else if (VK_SUCCESS != res) { |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 4175 | loader_log(ptr_instance, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 4176 | "ICD ignored: failed to CreateInstance in ICD %d", i); |
Mark Young | 7e47129 | 2016-09-06 09:53:45 -0600 | [diff] [blame] | 4177 | ptr_instance->icds = icd->next; |
Mark Young | db13a2a | 2016-09-06 13:53:03 -0600 | [diff] [blame] | 4178 | icd->next = NULL; |
Mark Young | 7e47129 | 2016-09-06 09:53:45 -0600 | [diff] [blame] | 4179 | loader_icd_destroy(ptr_instance, icd, pAllocator); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 4180 | continue; |
| 4181 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4182 | |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 4183 | if (!loader_icd_init_entrys( |
| 4184 | icd, icd->instance, |
| 4185 | ptr_instance->icd_libs.list[i].GetInstanceProcAddr)) { |
| 4186 | loader_log(ptr_instance, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4187 | "ICD ignored: failed to CreateInstance and find " |
| 4188 | "entrypoints with ICD"); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 4189 | continue; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4190 | } |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 4191 | } |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 4192 | |
Courtney Goeltzenleuchter | 40caf0b | 2015-07-06 09:06:34 -0600 | [diff] [blame] | 4193 | /* |
| 4194 | * If no ICDs were added to instance list and res is unchanged |
| 4195 | * from it's initial value, the loader was unable to find |
| 4196 | * a suitable ICD. |
| 4197 | */ |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 4198 | if (VK_SUCCESS == res && ptr_instance->icds == NULL) { |
| 4199 | res = VK_ERROR_INCOMPATIBLE_DRIVER; |
| 4200 | } |
| 4201 | |
| 4202 | out: |
| 4203 | |
| 4204 | if (VK_SUCCESS != res) { |
| 4205 | while (NULL != ptr_instance->icds) { |
| 4206 | icd = ptr_instance->icds; |
| 4207 | ptr_instance->icds = icd->next; |
| 4208 | if (NULL != icd->instance) { |
| 4209 | icd->DestroyInstance(icd->instance, pAllocator); |
| 4210 | } |
| 4211 | loader_icd_destroy(ptr_instance, icd, pAllocator); |
Courtney Goeltzenleuchter | 40caf0b | 2015-07-06 09:06:34 -0600 | [diff] [blame] | 4212 | } |
Ian Elliott | eb45076 | 2015-02-05 15:19:15 -0700 | [diff] [blame] | 4213 | } |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 4214 | |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 4215 | return res; |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 4216 | } |
| 4217 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4218 | VKAPI_ATTR void VKAPI_CALL terminator_DestroyInstance( |
| 4219 | VkInstance instance, const VkAllocationCallbacks *pAllocator) { |
Courtney Goeltzenleuchter | deceded | 2015-06-08 15:04:02 -0600 | [diff] [blame] | 4220 | struct loader_instance *ptr_instance = loader_instance(instance); |
Jon Ashburn | 3da71f2 | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 4221 | struct loader_icd *icds = ptr_instance->icds; |
Jon Ashburn | a6fd261 | 2015-06-16 14:43:19 -0600 | [diff] [blame] | 4222 | struct loader_icd *next_icd; |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 4223 | |
| 4224 | // Remove this instance from the list of instances: |
| 4225 | struct loader_instance *prev = NULL; |
| 4226 | struct loader_instance *next = loader.instances; |
| 4227 | while (next != NULL) { |
| 4228 | if (next == ptr_instance) { |
| 4229 | // Remove this instance from the list: |
| 4230 | if (prev) |
| 4231 | prev->next = next->next; |
Jon Ashburn | c5c4960 | 2015-02-03 09:26:59 -0700 | [diff] [blame] | 4232 | else |
| 4233 | loader.instances = next->next; |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 4234 | break; |
| 4235 | } |
| 4236 | prev = next; |
| 4237 | next = next->next; |
| 4238 | } |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 4239 | |
Jon Ashburn | 3da71f2 | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 4240 | while (icds) { |
| 4241 | if (icds->instance) { |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 4242 | icds->DestroyInstance(icds->instance, pAllocator); |
Tony Barbour | f20f87b | 2015-04-22 09:02:32 -0600 | [diff] [blame] | 4243 | } |
Jon Ashburn | a6fd261 | 2015-06-16 14:43:19 -0600 | [diff] [blame] | 4244 | next_icd = icds->next; |
Jon Ashburn | 3da71f2 | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 4245 | icds->instance = VK_NULL_HANDLE; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4246 | loader_icd_destroy(ptr_instance, icds, pAllocator); |
Jon Ashburn | a6fd261 | 2015-06-16 14:43:19 -0600 | [diff] [blame] | 4247 | |
| 4248 | icds = next_icd; |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 4249 | } |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 4250 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4251 | loader_delete_layer_properties(ptr_instance, |
| 4252 | &ptr_instance->instance_layer_list); |
Jon Ashburn | e39a4f8 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 4253 | loader_scanned_icd_clear(ptr_instance, &ptr_instance->icd_libs); |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4254 | loader_destroy_generic_list( |
| 4255 | ptr_instance, (struct loader_generic_list *)&ptr_instance->ext_list); |
Jon Ashburn | 014438f | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 4256 | if (ptr_instance->phys_devs_term) |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4257 | loader_instance_heap_free(ptr_instance, ptr_instance->phys_devs_term); |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 4258 | loader_free_dev_ext_table(ptr_instance); |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 4259 | } |
| 4260 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4261 | VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateDevice( |
| 4262 | VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo *pCreateInfo, |
| 4263 | const VkAllocationCallbacks *pAllocator, VkDevice *pDevice) { |
| 4264 | VkResult res = VK_SUCCESS; |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 4265 | struct loader_physical_device *phys_dev; |
Jon Ashburn | 014438f | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 4266 | phys_dev = (struct loader_physical_device *)physicalDevice; |
Jon Ashburn | 24cd4be | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 4267 | |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 4268 | struct loader_device *dev = (struct loader_device *)*pDevice; |
Jon Ashburn | 72690f2 | 2016-03-29 12:52:13 -0600 | [diff] [blame] | 4269 | PFN_vkCreateDevice fpCreateDevice = phys_dev->this_icd->CreateDevice; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4270 | struct loader_extension_list icd_exts; |
| 4271 | |
| 4272 | icd_exts.list = NULL; |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 4273 | |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 4274 | if (fpCreateDevice == NULL) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4275 | res = VK_ERROR_INITIALIZATION_FAILED; |
| 4276 | goto out; |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 4277 | } |
| 4278 | |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 4279 | VkDeviceCreateInfo localCreateInfo; |
| 4280 | memcpy(&localCreateInfo, pCreateInfo, sizeof(localCreateInfo)); |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 4281 | |
| 4282 | /* |
| 4283 | * NOTE: Need to filter the extensions to only those |
| 4284 | * supported by the ICD. |
| 4285 | * No ICD will advertise support for layers. An ICD |
| 4286 | * library could support a layer, but it would be |
| 4287 | * independent of the actual ICD, just in the same library. |
| 4288 | */ |
| 4289 | char **filtered_extension_names = NULL; |
| 4290 | filtered_extension_names = |
| 4291 | loader_stack_alloc(pCreateInfo->enabledExtensionCount * sizeof(char *)); |
| 4292 | if (!filtered_extension_names) { |
Jon Ashburn | 24cd4be | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 4293 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 4294 | } |
| 4295 | |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 4296 | localCreateInfo.enabledLayerCount = 0; |
| 4297 | localCreateInfo.ppEnabledLayerNames = NULL; |
| 4298 | |
| 4299 | localCreateInfo.enabledExtensionCount = 0; |
| 4300 | localCreateInfo.ppEnabledExtensionNames = |
| 4301 | (const char *const *)filtered_extension_names; |
| 4302 | |
Jon Ashburn | 014438f | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 4303 | /* Get the physical device (ICD) extensions */ |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 4304 | res = loader_init_generic_list(phys_dev->this_icd->this_instance, |
Jon Ashburn | 014438f | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 4305 | (struct loader_generic_list *)&icd_exts, |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 4306 | sizeof(VkExtensionProperties)); |
| 4307 | if (VK_SUCCESS != res) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4308 | goto out; |
Jon Ashburn | 014438f | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 4309 | } |
| 4310 | |
| 4311 | res = loader_add_device_extensions( |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 4312 | phys_dev->this_icd->this_instance, |
| 4313 | phys_dev->this_icd->EnumerateDeviceExtensionProperties, |
Jon Ashburn | 014438f | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 4314 | phys_dev->phys_dev, phys_dev->this_icd->this_icd_lib->lib_name, |
| 4315 | &icd_exts); |
| 4316 | if (res != VK_SUCCESS) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4317 | goto out; |
Jon Ashburn | 014438f | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 4318 | } |
| 4319 | |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 4320 | for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) { |
| 4321 | const char *extension_name = pCreateInfo->ppEnabledExtensionNames[i]; |
Jon Ashburn | 014438f | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 4322 | VkExtensionProperties *prop = |
| 4323 | get_extension_property(extension_name, &icd_exts); |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 4324 | if (prop) { |
| 4325 | filtered_extension_names[localCreateInfo.enabledExtensionCount] = |
| 4326 | (char *)extension_name; |
| 4327 | localCreateInfo.enabledExtensionCount++; |
| 4328 | } |
| 4329 | } |
| 4330 | |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 4331 | // TODO: Why does fpCreateDevice behave differently than |
| 4332 | // this_icd->CreateDevice? |
| 4333 | // VkResult res = fpCreateDevice(phys_dev->phys_dev, &localCreateInfo, |
| 4334 | // pAllocator, &localDevice); |
Jon Ashburn | 014438f | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 4335 | res = phys_dev->this_icd->CreateDevice(phys_dev->phys_dev, &localCreateInfo, |
Jon Ashburn | 0b8507c | 2016-04-01 11:49:39 -0600 | [diff] [blame] | 4336 | pAllocator, &dev->device); |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 4337 | |
| 4338 | if (res != VK_SUCCESS) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4339 | goto out; |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 4340 | } |
| 4341 | |
Jon Ashburn | 0b8507c | 2016-04-01 11:49:39 -0600 | [diff] [blame] | 4342 | *pDevice = dev->device; |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 4343 | loader_add_logical_device(phys_dev->this_icd->this_instance, |
| 4344 | phys_dev->this_icd, dev); |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 4345 | |
| 4346 | /* Init dispatch pointer in new device object */ |
| 4347 | loader_init_dispatch(*pDevice, &dev->loader_dispatch); |
| 4348 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4349 | out: |
| 4350 | if (NULL != icd_exts.list) { |
| 4351 | loader_destroy_generic_list(phys_dev->this_icd->this_instance, |
| 4352 | (struct loader_generic_list *)&icd_exts); |
| 4353 | } |
| 4354 | |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 4355 | return res; |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 4356 | } |
| 4357 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4358 | VKAPI_ATTR VkResult VKAPI_CALL |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 4359 | terminator_EnumeratePhysicalDevices(VkInstance instance, |
| 4360 | uint32_t *pPhysicalDeviceCount, |
| 4361 | VkPhysicalDevice *pPhysicalDevices) { |
Jon Ashburn | 24cd4be | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 4362 | uint32_t i; |
Jon Ashburn | 014438f | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 4363 | struct loader_instance *inst = (struct loader_instance *)instance; |
Jon Ashburn | 24cd4be | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 4364 | VkResult res = VK_SUCCESS; |
Jon Ashburn | 4c392fb | 2015-01-28 19:57:09 -0700 | [diff] [blame] | 4365 | |
Jon Ashburn | 014438f | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 4366 | struct loader_icd *icd; |
| 4367 | struct loader_phys_dev_per_icd *phys_devs; |
| 4368 | |
| 4369 | inst->total_gpu_count = 0; |
| 4370 | phys_devs = (struct loader_phys_dev_per_icd *)loader_stack_alloc( |
| 4371 | sizeof(struct loader_phys_dev_per_icd) * inst->total_icd_count); |
| 4372 | if (!phys_devs) |
| 4373 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 4374 | |
| 4375 | icd = inst->icds; |
| 4376 | for (i = 0; i < inst->total_icd_count; i++) { |
| 4377 | assert(icd); |
| 4378 | res = icd->EnumeratePhysicalDevices(icd->instance, &phys_devs[i].count, |
| 4379 | NULL); |
| 4380 | if (res != VK_SUCCESS) |
| 4381 | return res; |
| 4382 | icd = icd->next; |
Jon Ashburn | 4c392fb | 2015-01-28 19:57:09 -0700 | [diff] [blame] | 4383 | } |
| 4384 | |
Jon Ashburn | 014438f | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 4385 | icd = inst->icds; |
| 4386 | for (i = 0; i < inst->total_icd_count; i++) { |
| 4387 | assert(icd); |
| 4388 | phys_devs[i].phys_devs = (VkPhysicalDevice *)loader_stack_alloc( |
| 4389 | phys_devs[i].count * sizeof(VkPhysicalDevice)); |
| 4390 | if (!phys_devs[i].phys_devs) { |
| 4391 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 4392 | } |
| 4393 | res = icd->EnumeratePhysicalDevices( |
| 4394 | icd->instance, &(phys_devs[i].count), phys_devs[i].phys_devs); |
| 4395 | if ((res == VK_SUCCESS)) { |
| 4396 | inst->total_gpu_count += phys_devs[i].count; |
| 4397 | } else { |
| 4398 | return res; |
| 4399 | } |
| 4400 | phys_devs[i].this_icd = icd; |
| 4401 | icd = icd->next; |
| 4402 | } |
| 4403 | |
| 4404 | *pPhysicalDeviceCount = inst->total_gpu_count; |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 4405 | if (!pPhysicalDevices) { |
Jon Ashburn | 24cd4be | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 4406 | return res; |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 4407 | } |
Jon Ashburn | 4c392fb | 2015-01-28 19:57:09 -0700 | [diff] [blame] | 4408 | |
Jon Ashburn | 014438f | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 4409 | /* Initialize the output pPhysicalDevices with wrapped loader terminator |
| 4410 | * physicalDevice objects; save this list of wrapped objects in instance |
| 4411 | * struct for later cleanup and use by trampoline code */ |
| 4412 | uint32_t j, idx = 0; |
| 4413 | uint32_t copy_count = 0; |
| 4414 | |
| 4415 | copy_count = (inst->total_gpu_count < *pPhysicalDeviceCount) |
| 4416 | ? inst->total_gpu_count |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4417 | : *pPhysicalDeviceCount; |
Jon Ashburn | 014438f | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 4418 | |
Jon Ashburn | 014438f | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 4419 | if (inst->phys_devs_term) |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4420 | loader_instance_heap_free(inst, inst->phys_devs_term); |
| 4421 | inst->phys_devs_term = loader_instance_heap_alloc( |
Jon Ashburn | 014438f | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 4422 | inst, sizeof(struct loader_physical_device) * copy_count, |
| 4423 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
| 4424 | if (!inst->phys_devs_term) |
| 4425 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 4426 | |
| 4427 | for (i = 0; idx < copy_count && i < inst->total_icd_count; i++) { |
Jon Ashburn | 1a02c2f | 2016-03-11 14:43:57 -0700 | [diff] [blame] | 4428 | |
Jon Ashburn | 014438f | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 4429 | for (j = 0; j < phys_devs[i].count && idx < copy_count; j++) { |
| 4430 | loader_set_dispatch((void *)&inst->phys_devs_term[idx], inst->disp); |
| 4431 | inst->phys_devs_term[idx].this_icd = phys_devs[i].this_icd; |
| 4432 | inst->phys_devs_term[idx].phys_dev = phys_devs[i].phys_devs[j]; |
| 4433 | pPhysicalDevices[idx] = |
| 4434 | (VkPhysicalDevice)&inst->phys_devs_term[idx]; |
| 4435 | idx++; |
| 4436 | } |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 4437 | } |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4438 | *pPhysicalDeviceCount = copy_count; |
| 4439 | |
Piers Daniell | 295fe40 | 2016-03-29 11:51:11 -0600 | [diff] [blame] | 4440 | // TODO: Is phys_devs being leaked? |
| 4441 | |
Jon Ashburn | 014438f | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 4442 | if (copy_count < inst->total_gpu_count) { |
| 4443 | inst->total_gpu_count = copy_count; |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4444 | return VK_INCOMPLETE; |
| 4445 | } |
Jon Ashburn | 24cd4be | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 4446 | return res; |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 4447 | } |
| 4448 | |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 4449 | VKAPI_ATTR void VKAPI_CALL terminator_GetPhysicalDeviceProperties( |
| 4450 | VkPhysicalDevice physicalDevice, VkPhysicalDeviceProperties *pProperties) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4451 | struct loader_physical_device *phys_dev = |
| 4452 | (struct loader_physical_device *)physicalDevice; |
Jon Ashburn | 24cd4be | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 4453 | struct loader_icd *icd = phys_dev->this_icd; |
Jon Ashburn | 3da71f2 | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 4454 | |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 4455 | if (icd->GetPhysicalDeviceProperties) |
Jon Ashburn | 24cd4be | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 4456 | icd->GetPhysicalDeviceProperties(phys_dev->phys_dev, pProperties); |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 4457 | } |
| 4458 | |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 4459 | VKAPI_ATTR void VKAPI_CALL terminator_GetPhysicalDeviceQueueFamilyProperties( |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4460 | VkPhysicalDevice physicalDevice, uint32_t *pQueueFamilyPropertyCount, |
| 4461 | VkQueueFamilyProperties *pProperties) { |
| 4462 | struct loader_physical_device *phys_dev = |
| 4463 | (struct loader_physical_device *)physicalDevice; |
Jon Ashburn | 24cd4be | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 4464 | struct loader_icd *icd = phys_dev->this_icd; |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 4465 | |
Cody Northrop | d080288 | 2015-08-03 17:04:53 -0600 | [diff] [blame] | 4466 | if (icd->GetPhysicalDeviceQueueFamilyProperties) |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4467 | icd->GetPhysicalDeviceQueueFamilyProperties( |
| 4468 | phys_dev->phys_dev, pQueueFamilyPropertyCount, pProperties); |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 4469 | } |
| 4470 | |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 4471 | VKAPI_ATTR void VKAPI_CALL terminator_GetPhysicalDeviceMemoryProperties( |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4472 | VkPhysicalDevice physicalDevice, |
| 4473 | VkPhysicalDeviceMemoryProperties *pProperties) { |
| 4474 | struct loader_physical_device *phys_dev = |
| 4475 | (struct loader_physical_device *)physicalDevice; |
Jon Ashburn | 24cd4be | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 4476 | struct loader_icd *icd = phys_dev->this_icd; |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 4477 | |
| 4478 | if (icd->GetPhysicalDeviceMemoryProperties) |
Jon Ashburn | 24cd4be | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 4479 | icd->GetPhysicalDeviceMemoryProperties(phys_dev->phys_dev, pProperties); |
Jon Ashburn | 3da71f2 | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 4480 | } |
| 4481 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4482 | VKAPI_ATTR void VKAPI_CALL |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 4483 | terminator_GetPhysicalDeviceFeatures(VkPhysicalDevice physicalDevice, |
| 4484 | VkPhysicalDeviceFeatures *pFeatures) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4485 | struct loader_physical_device *phys_dev = |
| 4486 | (struct loader_physical_device *)physicalDevice; |
Jon Ashburn | 24cd4be | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 4487 | struct loader_icd *icd = phys_dev->this_icd; |
Chris Forbes | bc0bb77 | 2015-06-21 22:55:02 +1200 | [diff] [blame] | 4488 | |
| 4489 | if (icd->GetPhysicalDeviceFeatures) |
Jon Ashburn | 24cd4be | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 4490 | icd->GetPhysicalDeviceFeatures(phys_dev->phys_dev, pFeatures); |
Chris Forbes | bc0bb77 | 2015-06-21 22:55:02 +1200 | [diff] [blame] | 4491 | } |
| 4492 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4493 | VKAPI_ATTR void VKAPI_CALL |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 4494 | terminator_GetPhysicalDeviceFormatProperties(VkPhysicalDevice physicalDevice, |
| 4495 | VkFormat format, |
| 4496 | VkFormatProperties *pFormatInfo) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4497 | struct loader_physical_device *phys_dev = |
| 4498 | (struct loader_physical_device *)physicalDevice; |
Jon Ashburn | 24cd4be | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 4499 | struct loader_icd *icd = phys_dev->this_icd; |
Chris Forbes | bc0bb77 | 2015-06-21 22:55:02 +1200 | [diff] [blame] | 4500 | |
Courtney Goeltzenleuchter | 2caec86 | 2015-07-12 12:52:09 -0600 | [diff] [blame] | 4501 | if (icd->GetPhysicalDeviceFormatProperties) |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4502 | icd->GetPhysicalDeviceFormatProperties(phys_dev->phys_dev, format, |
| 4503 | pFormatInfo); |
Chris Forbes | bc0bb77 | 2015-06-21 22:55:02 +1200 | [diff] [blame] | 4504 | } |
| 4505 | |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 4506 | VKAPI_ATTR VkResult VKAPI_CALL |
| 4507 | terminator_GetPhysicalDeviceImageFormatProperties( |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4508 | VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, |
| 4509 | VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags, |
| 4510 | VkImageFormatProperties *pImageFormatProperties) { |
| 4511 | struct loader_physical_device *phys_dev = |
| 4512 | (struct loader_physical_device *)physicalDevice; |
Jon Ashburn | 24cd4be | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 4513 | struct loader_icd *icd = phys_dev->this_icd; |
Jon Ashburn | 754864f | 2015-07-23 18:49:07 -0600 | [diff] [blame] | 4514 | |
Chia-I Wu | 1724104 | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 4515 | if (!icd->GetPhysicalDeviceImageFormatProperties) |
| 4516 | return VK_ERROR_INITIALIZATION_FAILED; |
| 4517 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4518 | return icd->GetPhysicalDeviceImageFormatProperties( |
| 4519 | phys_dev->phys_dev, format, type, tiling, usage, flags, |
| 4520 | pImageFormatProperties); |
Jon Ashburn | 754864f | 2015-07-23 18:49:07 -0600 | [diff] [blame] | 4521 | } |
| 4522 | |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 4523 | VKAPI_ATTR void VKAPI_CALL |
| 4524 | terminator_GetPhysicalDeviceSparseImageFormatProperties( |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4525 | VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, |
| 4526 | VkSampleCountFlagBits samples, VkImageUsageFlags usage, |
| 4527 | VkImageTiling tiling, uint32_t *pNumProperties, |
| 4528 | VkSparseImageFormatProperties *pProperties) { |
| 4529 | struct loader_physical_device *phys_dev = |
| 4530 | (struct loader_physical_device *)physicalDevice; |
Jon Ashburn | 24cd4be | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 4531 | struct loader_icd *icd = phys_dev->this_icd; |
Mark Lobodzinski | 16e8bef | 2015-07-03 15:58:09 -0600 | [diff] [blame] | 4532 | |
| 4533 | if (icd->GetPhysicalDeviceSparseImageFormatProperties) |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4534 | icd->GetPhysicalDeviceSparseImageFormatProperties( |
| 4535 | phys_dev->phys_dev, format, type, samples, usage, tiling, |
| 4536 | pNumProperties, pProperties); |
Mark Lobodzinski | 16e8bef | 2015-07-03 15:58:09 -0600 | [diff] [blame] | 4537 | } |
| 4538 | |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 4539 | VKAPI_ATTR VkResult VKAPI_CALL terminator_EnumerateDeviceExtensionProperties( |
| 4540 | VkPhysicalDevice physicalDevice, const char *pLayerName, |
| 4541 | uint32_t *pPropertyCount, VkExtensionProperties *pProperties) { |
Jon Ashburn | a760a51 | 2015-12-14 08:52:14 -0700 | [diff] [blame] | 4542 | struct loader_physical_device *phys_dev; |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 4543 | |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 4544 | struct loader_layer_list implicit_layer_list = {0}; |
| 4545 | struct loader_extension_list all_exts = {0}; |
| 4546 | struct loader_extension_list icd_exts = {0}; |
Jon Ashburn | 471f44c | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 4547 | |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 4548 | assert(pLayerName == NULL || strlen(pLayerName) == 0); |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 4549 | |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 4550 | /* Any layer or trampoline wrapping should be removed at this point in time |
| 4551 | * can just cast to the expected type for VkPhysicalDevice. */ |
Jon Ashburn | 014438f | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 4552 | phys_dev = (struct loader_physical_device *)physicalDevice; |
Jon Ashburn | 471f44c | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 4553 | |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 4554 | /* this case is during the call down the instance chain with pLayerName |
| 4555 | * == NULL*/ |
| 4556 | struct loader_icd *icd = phys_dev->this_icd; |
| 4557 | uint32_t icd_ext_count = *pPropertyCount; |
| 4558 | VkResult res; |
Jon Ashburn | 471f44c | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 4559 | |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 4560 | /* get device extensions */ |
Jon Ashburn | 014438f | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 4561 | res = icd->EnumerateDeviceExtensionProperties(phys_dev->phys_dev, NULL, |
| 4562 | &icd_ext_count, pProperties); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 4563 | if (res != VK_SUCCESS) { |
| 4564 | goto out; |
| 4565 | } |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4566 | |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 4567 | if (!loader_init_layer_list(icd->this_instance, &implicit_layer_list)) { |
| 4568 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 4569 | goto out; |
| 4570 | } |
Jon Ashburn | 471f44c | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 4571 | |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 4572 | loader_add_layer_implicit( |
Jon Ashburn | 014438f | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 4573 | icd->this_instance, VK_LAYER_TYPE_INSTANCE_IMPLICIT, |
| 4574 | &implicit_layer_list, &icd->this_instance->instance_layer_list); |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 4575 | /* we need to determine which implicit layers are active, |
| 4576 | * and then add their extensions. This can't be cached as |
| 4577 | * it depends on results of environment variables (which can change). |
| 4578 | */ |
| 4579 | if (pProperties != NULL) { |
| 4580 | /* initialize dev_extension list within the physicalDevice object */ |
Jon Ashburn | 014438f | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 4581 | res = loader_init_device_extensions(icd->this_instance, phys_dev, |
| 4582 | icd_ext_count, pProperties, |
| 4583 | &icd_exts); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 4584 | if (res != VK_SUCCESS) { |
| 4585 | goto out; |
| 4586 | } |
Jon Ashburn | 471f44c | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 4587 | |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 4588 | /* we need to determine which implicit layers are active, |
| 4589 | * and then add their extensions. This can't be cached as |
| 4590 | * it depends on results of environment variables (which can |
| 4591 | * change). |
| 4592 | */ |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 4593 | res = loader_add_to_ext_list(icd->this_instance, &all_exts, |
| 4594 | icd_exts.count, icd_exts.list); |
| 4595 | if (res != VK_SUCCESS) { |
| 4596 | goto out; |
| 4597 | } |
Jon Ashburn | 471f44c | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 4598 | |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 4599 | loader_add_layer_implicit( |
Jon Ashburn | 014438f | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 4600 | icd->this_instance, VK_LAYER_TYPE_INSTANCE_IMPLICIT, |
| 4601 | &implicit_layer_list, &icd->this_instance->instance_layer_list); |
Jon Ashburn | 471f44c | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 4602 | |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 4603 | for (uint32_t i = 0; i < implicit_layer_list.count; i++) { |
| 4604 | for (uint32_t j = 0; |
Jon Ashburn | 014438f | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 4605 | j < implicit_layer_list.list[i].device_extension_list.count; |
| 4606 | j++) { |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 4607 | res = loader_add_to_ext_list(icd->this_instance, &all_exts, 1, |
| 4608 | &implicit_layer_list.list[i] |
| 4609 | .device_extension_list.list[j] |
| 4610 | .props); |
| 4611 | if (res != VK_SUCCESS) { |
| 4612 | goto out; |
| 4613 | } |
Jon Ashburn | 471f44c | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 4614 | } |
Jon Ashburn | 471f44c | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 4615 | } |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 4616 | uint32_t capacity = *pPropertyCount; |
| 4617 | VkExtensionProperties *props = pProperties; |
Jon Ashburn | 471f44c | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 4618 | |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 4619 | for (uint32_t i = 0; i < all_exts.count && i < capacity; i++) { |
| 4620 | props[i] = all_exts.list[i]; |
| 4621 | } |
| 4622 | /* wasn't enough space for the extensions, we did partial copy now |
| 4623 | * return VK_INCOMPLETE */ |
| 4624 | if (capacity < all_exts.count) { |
| 4625 | res = VK_INCOMPLETE; |
| 4626 | } else { |
| 4627 | *pPropertyCount = all_exts.count; |
| 4628 | } |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 4629 | } else { |
| 4630 | /* just return the count; need to add in the count of implicit layer |
| 4631 | * extensions |
| 4632 | * don't worry about duplicates being added in the count */ |
| 4633 | *pPropertyCount = icd_ext_count; |
| 4634 | |
| 4635 | for (uint32_t i = 0; i < implicit_layer_list.count; i++) { |
| 4636 | *pPropertyCount += |
Jon Ashburn | 014438f | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 4637 | implicit_layer_list.list[i].device_extension_list.count; |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 4638 | } |
| 4639 | res = VK_SUCCESS; |
Jon Ashburn | b82c185 | 2015-08-11 14:49:54 -0600 | [diff] [blame] | 4640 | } |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 4641 | |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 4642 | out: |
| 4643 | |
| 4644 | if (NULL != implicit_layer_list.list) { |
| 4645 | loader_destroy_generic_list( |
| 4646 | icd->this_instance, |
| 4647 | (struct loader_generic_list *)&implicit_layer_list); |
| 4648 | } |
| 4649 | if (NULL != all_exts.list) { |
| 4650 | loader_destroy_generic_list(icd->this_instance, |
| 4651 | (struct loader_generic_list *)&all_exts); |
| 4652 | } |
| 4653 | if (NULL != icd_exts.list) { |
| 4654 | loader_destroy_generic_list(icd->this_instance, |
| 4655 | (struct loader_generic_list *)&icd_exts); |
| 4656 | } |
| 4657 | |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 4658 | return res; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 4659 | } |
| 4660 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4661 | VKAPI_ATTR VkResult VKAPI_CALL |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 4662 | terminator_EnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice, |
| 4663 | uint32_t *pPropertyCount, |
| 4664 | VkLayerProperties *pProperties) { |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 4665 | |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 4666 | // should never get here this call isn't dispatched down the chain |
| 4667 | return VK_ERROR_INITIALIZATION_FAILED; |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 4668 | } |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 4669 | |
Jon Ashburn | f2b4e38 | 2016-02-10 20:50:19 -0700 | [diff] [blame] | 4670 | VkStringErrorFlags vk_string_validate(const int max_length, const char *utf8) { |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 4671 | VkStringErrorFlags result = VK_STRING_ERROR_NONE; |
Karl Schultz | 2558bd3 | 2016-02-24 14:39:39 -0700 | [diff] [blame] | 4672 | int num_char_bytes = 0; |
Jon Ashburn | f2b4e38 | 2016-02-10 20:50:19 -0700 | [diff] [blame] | 4673 | int i, j; |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 4674 | |
Jon Ashburn | f2b4e38 | 2016-02-10 20:50:19 -0700 | [diff] [blame] | 4675 | for (i = 0; i < max_length; i++) { |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 4676 | if (utf8[i] == 0) { |
| 4677 | break; |
Mark Lobodzinski | 36b4de2 | 2016-02-12 11:30:14 -0700 | [diff] [blame] | 4678 | } else if ((utf8[i] >= 0x20) && (utf8[i] < 0x7f)) { |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 4679 | num_char_bytes = 0; |
Jon Ashburn | f2b4e38 | 2016-02-10 20:50:19 -0700 | [diff] [blame] | 4680 | } else if ((utf8[i] & UTF8_ONE_BYTE_MASK) == UTF8_ONE_BYTE_CODE) { |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 4681 | num_char_bytes = 1; |
Jon Ashburn | f2b4e38 | 2016-02-10 20:50:19 -0700 | [diff] [blame] | 4682 | } else if ((utf8[i] & UTF8_TWO_BYTE_MASK) == UTF8_TWO_BYTE_CODE) { |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 4683 | num_char_bytes = 2; |
| 4684 | } else if ((utf8[i] & UTF8_THREE_BYTE_MASK) == UTF8_THREE_BYTE_CODE) { |
| 4685 | num_char_bytes = 3; |
| 4686 | } else { |
| 4687 | result = VK_STRING_ERROR_BAD_DATA; |
| 4688 | } |
| 4689 | |
| 4690 | // Validate the following num_char_bytes of data |
| 4691 | for (j = 0; (j < num_char_bytes) && (i < max_length); j++) { |
| 4692 | if (++i == max_length) { |
| 4693 | result |= VK_STRING_ERROR_LENGTH; |
| 4694 | break; |
| 4695 | } |
| 4696 | if ((utf8[i] & UTF8_DATA_BYTE_MASK) != UTF8_DATA_BYTE_CODE) { |
| 4697 | result |= VK_STRING_ERROR_BAD_DATA; |
| 4698 | } |
| 4699 | } |
| 4700 | } |
| 4701 | return result; |
| 4702 | } |