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 | * |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3 | * Copyright (c) 2014-2017 The Khronos Group Inc. |
| 4 | * Copyright (c) 2014-2017 Valve Corporation |
| 5 | * Copyright (c) 2014-2017 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> |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 23 | * Author: Mark Young <marky@lunarg.com> |
Courtney Goeltzenleuchter | 0555952 | 2015-10-30 11:14:30 -0600 | [diff] [blame] | 24 | * |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 25 | */ |
Mark Lobodzinski | faa9081 | 2015-11-25 13:26:15 -0700 | [diff] [blame] | 26 | |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 27 | #define _GNU_SOURCE |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 28 | #include <stdio.h> |
| 29 | #include <stdlib.h> |
| 30 | #include <stdarg.h> |
| 31 | #include <stdbool.h> |
| 32 | #include <string.h> |
Benjamin Saunders | 31a4801 | 2017-01-29 14:49:54 -0800 | [diff] [blame] | 33 | #include <stddef.h> |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 34 | |
Chia-I Wu | 13a61a5 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 35 | #include <sys/types.h> |
Johannes van Waveren | 9bd80501 | 2015-10-28 11:45:00 -0500 | [diff] [blame] | 36 | #if defined(_WIN32) |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 37 | #include "dirent_on_windows.h" |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 38 | #else // _WIN32 |
Chia-I Wu | 13a61a5 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 39 | #include <dirent.h> |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 40 | #endif // _WIN32 |
Tobin Ehlis | b835d1b | 2015-07-03 10:34:49 -0600 | [diff] [blame] | 41 | #include "vk_loader_platform.h" |
Chia-I Wu | 1930060 | 2014-08-04 08:03:57 +0800 | [diff] [blame] | 42 | #include "loader.h" |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 43 | #include "gpa_helper.h" |
| 44 | #include "table_ops.h" |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 45 | #include "debug_report.h" |
Ian Elliott | 954fa34 | 2015-10-30 15:28:23 -0600 | [diff] [blame] | 46 | #include "wsi.h" |
Mark Lobodzinski | 317574e | 2016-08-29 14:21:14 -0600 | [diff] [blame] | 47 | #include "extensions.h" |
David Pinedo | 9316d3b | 2015-11-06 12:54:48 -0700 | [diff] [blame] | 48 | #include "vulkan/vk_icd.h" |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 49 | #include "cJSON.h" |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 50 | #include "murmurhash.h" |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 51 | |
Jon Ashburn | d8ed799 | 2016-04-04 13:52:53 -0600 | [diff] [blame] | 52 | #if defined(__GNUC__) |
Jon Ashburn | 10b3f83 | 2016-05-09 11:31:40 -0600 | [diff] [blame] | 53 | #if (__GLIBC__ < 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ < 17)) |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 54 | #define secure_getenv __secure_getenv |
| 55 | #endif |
Jon Ashburn | d8ed799 | 2016-04-04 13:52:53 -0600 | [diff] [blame] | 56 | #endif |
| 57 | |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 58 | struct loader_struct loader = {0}; |
Jon Ashburn | 87d6aa9 | 2015-08-28 15:19:27 -0600 | [diff] [blame] | 59 | // TLS for instance for alloc/free callbacks |
| 60 | THREAD_LOCAL_DECL struct loader_instance *tls_instance; |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 61 | |
Courtney Goeltzenleuchter | 0ef13a0 | 2015-12-16 16:19:46 -0700 | [diff] [blame] | 62 | static size_t loader_platform_combine_path(char *dest, size_t len, ...); |
Daniel Dadap | 00b4aba | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 63 | |
Jon Ashburn | 24cd4be | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 64 | struct loader_phys_dev_per_icd { |
| 65 | uint32_t count; |
| 66 | VkPhysicalDevice *phys_devs; |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 67 | struct loader_icd_term *this_icd_term; |
Jon Ashburn | 24cd4be | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 68 | }; |
| 69 | |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 70 | enum loader_debug { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 71 | LOADER_INFO_BIT = 0x01, |
| 72 | LOADER_WARN_BIT = 0x02, |
| 73 | LOADER_PERF_BIT = 0x04, |
| 74 | LOADER_ERROR_BIT = 0x08, |
| 75 | LOADER_DEBUG_BIT = 0x10, |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 76 | }; |
| 77 | |
| 78 | uint32_t g_loader_debug = 0; |
| 79 | uint32_t g_loader_log_msgs = 0; |
| 80 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 81 | // thread safety lock for accessing global data structures such as "loader" |
Jon Ashburn | 6301a0f | 2015-05-29 13:15:39 -0600 | [diff] [blame] | 82 | // all entrypoints on the instance chain need to be locked except GPA |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 83 | // additionally CreateDevice and DestroyDevice needs to be locked |
Jon Ashburn | 6301a0f | 2015-05-29 13:15:39 -0600 | [diff] [blame] | 84 | loader_platform_thread_mutex loader_lock; |
Jon Ashburn | 6461ef2 | 2015-09-22 13:11:00 -0600 | [diff] [blame] | 85 | loader_platform_thread_mutex loader_json_lock; |
Jon Ashburn | 6301a0f | 2015-05-29 13:15:39 -0600 | [diff] [blame] | 86 | |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 87 | const char *std_validation_str = "VK_LAYER_LUNARG_standard_validation"; |
| 88 | |
Ian Elliott | d3ef02f | 2015-07-06 14:36:13 -0600 | [diff] [blame] | 89 | // This table contains the loader's instance dispatch table, which contains |
| 90 | // default functions if no instance layers are activated. This contains |
| 91 | // pointers to "terminator functions". |
Jon Ashburn | 6301a0f | 2015-05-29 13:15:39 -0600 | [diff] [blame] | 92 | const VkLayerInstanceDispatchTable instance_disp = { |
Jon Ashburn | 69e9ea2 | 2015-09-28 16:15:00 -0600 | [diff] [blame] | 93 | .GetInstanceProcAddr = vkGetInstanceProcAddr, |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 94 | .DestroyInstance = terminator_DestroyInstance, |
| 95 | .EnumeratePhysicalDevices = terminator_EnumeratePhysicalDevices, |
| 96 | .GetPhysicalDeviceFeatures = terminator_GetPhysicalDeviceFeatures, |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 97 | .GetPhysicalDeviceFormatProperties = terminator_GetPhysicalDeviceFormatProperties, |
| 98 | .GetPhysicalDeviceImageFormatProperties = terminator_GetPhysicalDeviceImageFormatProperties, |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 99 | .GetPhysicalDeviceProperties = terminator_GetPhysicalDeviceProperties, |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 100 | .GetPhysicalDeviceQueueFamilyProperties = terminator_GetPhysicalDeviceQueueFamilyProperties, |
| 101 | .GetPhysicalDeviceMemoryProperties = terminator_GetPhysicalDeviceMemoryProperties, |
| 102 | .EnumerateDeviceExtensionProperties = terminator_EnumerateDeviceExtensionProperties, |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 103 | .EnumerateDeviceLayerProperties = terminator_EnumerateDeviceLayerProperties, |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 104 | .GetPhysicalDeviceSparseImageFormatProperties = terminator_GetPhysicalDeviceSparseImageFormatProperties, |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 105 | .DestroySurfaceKHR = terminator_DestroySurfaceKHR, |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 106 | .GetPhysicalDeviceSurfaceSupportKHR = terminator_GetPhysicalDeviceSurfaceSupportKHR, |
| 107 | .GetPhysicalDeviceSurfaceCapabilitiesKHR = terminator_GetPhysicalDeviceSurfaceCapabilitiesKHR, |
| 108 | .GetPhysicalDeviceSurfaceFormatsKHR = terminator_GetPhysicalDeviceSurfaceFormatsKHR, |
| 109 | .GetPhysicalDeviceSurfacePresentModesKHR = terminator_GetPhysicalDeviceSurfacePresentModesKHR, |
Ian Elliott | db4300a | 2015-11-23 10:17:23 -0700 | [diff] [blame] | 110 | #ifdef VK_USE_PLATFORM_MIR_KHR |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 111 | .CreateMirSurfaceKHR = terminator_CreateMirSurfaceKHR, |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 112 | .GetPhysicalDeviceMirPresentationSupportKHR = terminator_GetPhysicalDeviceMirPresentationSupportKHR, |
Ian Elliott | db4300a | 2015-11-23 10:17:23 -0700 | [diff] [blame] | 113 | #endif |
| 114 | #ifdef VK_USE_PLATFORM_WAYLAND_KHR |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 115 | .CreateWaylandSurfaceKHR = terminator_CreateWaylandSurfaceKHR, |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 116 | .GetPhysicalDeviceWaylandPresentationSupportKHR = terminator_GetPhysicalDeviceWaylandPresentationSupportKHR, |
Ian Elliott | db4300a | 2015-11-23 10:17:23 -0700 | [diff] [blame] | 117 | #endif |
| 118 | #ifdef VK_USE_PLATFORM_WIN32_KHR |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 119 | .CreateWin32SurfaceKHR = terminator_CreateWin32SurfaceKHR, |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 120 | .GetPhysicalDeviceWin32PresentationSupportKHR = terminator_GetPhysicalDeviceWin32PresentationSupportKHR, |
Ian Elliott | db4300a | 2015-11-23 10:17:23 -0700 | [diff] [blame] | 121 | #endif |
| 122 | #ifdef VK_USE_PLATFORM_XCB_KHR |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 123 | .CreateXcbSurfaceKHR = terminator_CreateXcbSurfaceKHR, |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 124 | .GetPhysicalDeviceXcbPresentationSupportKHR = terminator_GetPhysicalDeviceXcbPresentationSupportKHR, |
Ian Elliott | db4300a | 2015-11-23 10:17:23 -0700 | [diff] [blame] | 125 | #endif |
| 126 | #ifdef VK_USE_PLATFORM_XLIB_KHR |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 127 | .CreateXlibSurfaceKHR = terminator_CreateXlibSurfaceKHR, |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 128 | .GetPhysicalDeviceXlibPresentationSupportKHR = terminator_GetPhysicalDeviceXlibPresentationSupportKHR, |
Ian Elliott | db4300a | 2015-11-23 10:17:23 -0700 | [diff] [blame] | 129 | #endif |
Mark Lobodzinski | a8a5f85 | 2015-12-10 16:25:21 -0700 | [diff] [blame] | 130 | #ifdef VK_USE_PLATFORM_ANDROID_KHR |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 131 | .CreateAndroidSurfaceKHR = terminator_CreateAndroidSurfaceKHR, |
Mark Lobodzinski | a8a5f85 | 2015-12-10 16:25:21 -0700 | [diff] [blame] | 132 | #endif |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 133 | .GetPhysicalDeviceDisplayPropertiesKHR = terminator_GetPhysicalDeviceDisplayPropertiesKHR, |
| 134 | .GetPhysicalDeviceDisplayPlanePropertiesKHR = terminator_GetPhysicalDeviceDisplayPlanePropertiesKHR, |
| 135 | .GetDisplayPlaneSupportedDisplaysKHR = terminator_GetDisplayPlaneSupportedDisplaysKHR, |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 136 | .GetDisplayModePropertiesKHR = terminator_GetDisplayModePropertiesKHR, |
| 137 | .CreateDisplayModeKHR = terminator_CreateDisplayModeKHR, |
| 138 | .GetDisplayPlaneCapabilitiesKHR = terminator_GetDisplayPlaneCapabilitiesKHR, |
| 139 | .CreateDisplayPlaneSurfaceKHR = terminator_CreateDisplayPlaneSurfaceKHR, |
Mark Young | fa55278 | 2016-12-12 16:14:55 -0700 | [diff] [blame] | 140 | |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 141 | // KHR_get_physical_device_properties2 |
| 142 | .GetPhysicalDeviceFeatures2KHR = terminator_GetPhysicalDeviceFeatures2KHR, |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 143 | .GetPhysicalDeviceProperties2KHR = terminator_GetPhysicalDeviceProperties2KHR, |
| 144 | .GetPhysicalDeviceFormatProperties2KHR = terminator_GetPhysicalDeviceFormatProperties2KHR, |
| 145 | .GetPhysicalDeviceImageFormatProperties2KHR = terminator_GetPhysicalDeviceImageFormatProperties2KHR, |
| 146 | .GetPhysicalDeviceQueueFamilyProperties2KHR = terminator_GetPhysicalDeviceQueueFamilyProperties2KHR, |
| 147 | .GetPhysicalDeviceMemoryProperties2KHR = terminator_GetPhysicalDeviceMemoryProperties2KHR, |
| 148 | .GetPhysicalDeviceSparseImageFormatProperties2KHR = terminator_GetPhysicalDeviceSparseImageFormatProperties2KHR, |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 149 | |
| 150 | #ifdef VK_USE_PLATFORM_XLIB_XRANDR_EXT |
| 151 | // EXT_acquire_xlib_display |
| 152 | .AcquireXlibDisplayEXT = terminator_AcquireXlibDisplayEXT, |
| 153 | .GetRandROutputDisplayEXT = terminator_GetRandROutputDisplayEXT, |
| 154 | #endif |
| 155 | |
| 156 | // EXT_debug_report |
| 157 | .CreateDebugReportCallbackEXT = terminator_CreateDebugReportCallback, |
| 158 | .DestroyDebugReportCallbackEXT = terminator_DestroyDebugReportCallback, |
| 159 | .DebugReportMessageEXT = terminator_DebugReportMessage, |
| 160 | |
| 161 | // EXT_direct_mode_display |
| 162 | .ReleaseDisplayEXT = terminator_ReleaseDisplayEXT, |
| 163 | |
| 164 | // EXT_display_surface_counter |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 165 | .GetPhysicalDeviceSurfaceCapabilities2EXT = terminator_GetPhysicalDeviceSurfaceCapabilities2EXT, |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 166 | |
| 167 | // NV_external_memory_capabilities |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 168 | .GetPhysicalDeviceExternalImageFormatPropertiesNV = terminator_GetPhysicalDeviceExternalImageFormatPropertiesNV, |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 169 | |
Mark Young | fa55278 | 2016-12-12 16:14:55 -0700 | [diff] [blame] | 170 | // NVX_device_generated_commands |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 171 | .GetPhysicalDeviceGeneratedCommandsPropertiesNVX = terminator_GetPhysicalDeviceGeneratedCommandsPropertiesNVX, |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 172 | }; |
| 173 | |
Lenny Komow | 4053b81 | 2016-12-29 16:27:28 -0700 | [diff] [blame] | 174 | // A null-terminated list of all of the instance extensions supported by the |
| 175 | // loader |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 176 | static const char *const LOADER_INSTANCE_EXTENSIONS[] = {VK_KHR_SURFACE_EXTENSION_NAME, |
| 177 | VK_KHR_DISPLAY_EXTENSION_NAME, |
Lenny Komow | 4053b81 | 2016-12-29 16:27:28 -0700 | [diff] [blame] | 178 | #ifdef VK_USE_PLATFORM_XLIB_KHR |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 179 | VK_KHR_XLIB_SURFACE_EXTENSION_NAME, |
Lenny Komow | 4053b81 | 2016-12-29 16:27:28 -0700 | [diff] [blame] | 180 | #endif |
| 181 | #ifdef VK_USE_PLATFORM_XCB_KHR |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 182 | VK_KHR_XCB_SURFACE_EXTENSION_NAME, |
Lenny Komow | 4053b81 | 2016-12-29 16:27:28 -0700 | [diff] [blame] | 183 | #endif |
| 184 | #ifdef VK_USE_PLATFORM_WAYLAND_KHR |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 185 | VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME, |
Lenny Komow | 4053b81 | 2016-12-29 16:27:28 -0700 | [diff] [blame] | 186 | #endif |
| 187 | #ifdef VK_USE_PLATFORM_MIR_KHR |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 188 | VK_KHR_MIR_SURFACE_EXTENSION_NAME, |
Lenny Komow | 4053b81 | 2016-12-29 16:27:28 -0700 | [diff] [blame] | 189 | #endif |
| 190 | #ifdef VK_USE_PLATFORM_ANDROID_KHR |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 191 | VK_KHR_ANDROID_SURFACE_EXTENSION_NAME, |
Lenny Komow | 4053b81 | 2016-12-29 16:27:28 -0700 | [diff] [blame] | 192 | #endif |
| 193 | #ifdef VK_USE_PLATFORM_WIN32_KHR |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 194 | VK_KHR_WIN32_SURFACE_EXTENSION_NAME, |
Lenny Komow | 4053b81 | 2016-12-29 16:27:28 -0700 | [diff] [blame] | 195 | #endif |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 196 | VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 197 | #ifdef VK_USE_PLATFORM_XLIB_XRANDR_EXT |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 198 | VK_EXT_ACQUIRE_XLIB_DISPLAY_EXTENSION_NAME, |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 199 | #endif |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 200 | VK_EXT_DEBUG_REPORT_EXTENSION_NAME, |
| 201 | VK_EXT_DIRECT_MODE_DISPLAY_EXTENSION_NAME, |
| 202 | VK_EXT_DISPLAY_SURFACE_COUNTER_EXTENSION_NAME, |
| 203 | VK_EXT_VALIDATION_FLAGS_EXTENSION_NAME, |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 204 | #ifdef VK_USE_PLATFORM_VI_NN |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 205 | VK_NN_VI_SURFACE_EXTENSION_NAME, |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 206 | #endif |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 207 | VK_NV_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME, |
| 208 | NULL}; |
Lenny Komow | 4053b81 | 2016-12-29 16:27:28 -0700 | [diff] [blame] | 209 | |
Jon Ashburn | 8810c5f | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 210 | LOADER_PLATFORM_THREAD_ONCE_DECLARATION(once_init); |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 211 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 212 | void *loader_instance_heap_alloc(const struct loader_instance *instance, size_t size, VkSystemAllocationScope alloc_scope) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 213 | void *pMemory = NULL; |
| 214 | #if (DEBUG_DISABLE_APP_ALLOCATORS == 1) |
| 215 | { |
| 216 | #else |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 217 | if (instance && instance->alloc_callbacks.pfnAllocation) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 218 | /* These are internal structures, so it's best to align everything to |
| 219 | * the largest unit size which is the size of a uint64_t. |
| 220 | */ |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 221 | pMemory = instance->alloc_callbacks.pfnAllocation(instance->alloc_callbacks.pUserData, size, sizeof(uint64_t), alloc_scope); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 222 | } else { |
| 223 | #endif |
| 224 | pMemory = malloc(size); |
Courtney Goeltzenleuchter | 7f5aafc | 2015-07-05 11:28:29 -0600 | [diff] [blame] | 225 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 226 | return pMemory; |
Courtney Goeltzenleuchter | 7f5aafc | 2015-07-05 11:28:29 -0600 | [diff] [blame] | 227 | } |
| 228 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 229 | void loader_instance_heap_free(const struct loader_instance *instance, void *pMemory) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 230 | if (pMemory != NULL) { |
| 231 | #if (DEBUG_DISABLE_APP_ALLOCATORS == 1) |
| 232 | { |
| 233 | #else |
| 234 | if (instance && instance->alloc_callbacks.pfnFree) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 235 | instance->alloc_callbacks.pfnFree(instance->alloc_callbacks.pUserData, pMemory); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 236 | } else { |
| 237 | #endif |
| 238 | free(pMemory); |
Mark Young | d077f99 | 2016-06-30 11:03:59 -0600 | [diff] [blame] | 239 | } |
Mark Young | 4b0b922 | 2016-06-29 18:33:53 -0600 | [diff] [blame] | 240 | } |
Mark Young | 4b0b922 | 2016-06-29 18:33:53 -0600 | [diff] [blame] | 241 | } |
| 242 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 243 | void *loader_instance_heap_realloc(const struct loader_instance *instance, void *pMemory, size_t orig_size, size_t size, |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 244 | VkSystemAllocationScope alloc_scope) { |
| 245 | void *pNewMem = NULL; |
| 246 | if (pMemory == NULL || orig_size == 0) { |
| 247 | pNewMem = loader_instance_heap_alloc(instance, size, alloc_scope); |
| 248 | } else if (size == 0) { |
| 249 | loader_instance_heap_free(instance, pMemory); |
| 250 | #if (DEBUG_DISABLE_APP_ALLOCATORS == 1) |
| 251 | #else |
| 252 | } else if (instance && instance->alloc_callbacks.pfnReallocation) { |
| 253 | /* These are internal structures, so it's best to align everything to |
| 254 | * the largest unit size which is the size of a uint64_t. |
| 255 | */ |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 256 | pNewMem = instance->alloc_callbacks.pfnReallocation(instance->alloc_callbacks.pUserData, pMemory, size, sizeof(uint64_t), |
| 257 | alloc_scope); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 258 | #endif |
| 259 | } else { |
| 260 | pNewMem = realloc(pMemory, size); |
| 261 | } |
| 262 | return pNewMem; |
Mark Young | 4b0b922 | 2016-06-29 18:33:53 -0600 | [diff] [blame] | 263 | } |
| 264 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 265 | void *loader_instance_tls_heap_alloc(size_t size) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 266 | return loader_instance_heap_alloc(tls_instance, size, VK_SYSTEM_ALLOCATION_SCOPE_COMMAND); |
Mark Young | 4b0b922 | 2016-06-29 18:33:53 -0600 | [diff] [blame] | 267 | } |
Mark Young | 4b0b922 | 2016-06-29 18:33:53 -0600 | [diff] [blame] | 268 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 269 | void loader_instance_tls_heap_free(void *pMemory) { loader_instance_heap_free(tls_instance, pMemory); } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 270 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 271 | void *loader_device_heap_alloc(const struct loader_device *device, size_t size, VkSystemAllocationScope alloc_scope) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 272 | void *pMemory = NULL; |
| 273 | #if (DEBUG_DISABLE_APP_ALLOCATORS == 1) |
| 274 | { |
| 275 | #else |
| 276 | if (device && device->alloc_callbacks.pfnAllocation) { |
| 277 | /* These are internal structures, so it's best to align everything to |
| 278 | * the largest unit size which is the size of a uint64_t. |
| 279 | */ |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 280 | pMemory = device->alloc_callbacks.pfnAllocation(device->alloc_callbacks.pUserData, size, sizeof(uint64_t), alloc_scope); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 281 | } else { |
| 282 | #endif |
| 283 | pMemory = malloc(size); |
| 284 | } |
| 285 | return pMemory; |
| 286 | } |
| 287 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 288 | void loader_device_heap_free(const struct loader_device *device, void *pMemory) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 289 | if (pMemory != NULL) { |
| 290 | #if (DEBUG_DISABLE_APP_ALLOCATORS == 1) |
| 291 | { |
| 292 | #else |
| 293 | if (device && device->alloc_callbacks.pfnFree) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 294 | device->alloc_callbacks.pfnFree(device->alloc_callbacks.pUserData, pMemory); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 295 | } else { |
| 296 | #endif |
| 297 | free(pMemory); |
| 298 | } |
| 299 | } |
| 300 | } |
| 301 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 302 | void *loader_device_heap_realloc(const struct loader_device *device, void *pMemory, size_t orig_size, size_t size, |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 303 | VkSystemAllocationScope alloc_scope) { |
| 304 | void *pNewMem = NULL; |
| 305 | if (pMemory == NULL || orig_size == 0) { |
| 306 | pNewMem = loader_device_heap_alloc(device, size, alloc_scope); |
| 307 | } else if (size == 0) { |
| 308 | loader_device_heap_free(device, pMemory); |
| 309 | #if (DEBUG_DISABLE_APP_ALLOCATORS == 1) |
| 310 | #else |
| 311 | } else if (device && device->alloc_callbacks.pfnReallocation) { |
| 312 | /* These are internal structures, so it's best to align everything to |
| 313 | * the largest unit size which is the size of a uint64_t. |
| 314 | */ |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 315 | pNewMem = device->alloc_callbacks.pfnReallocation(device->alloc_callbacks.pUserData, pMemory, size, sizeof(uint64_t), |
| 316 | alloc_scope); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 317 | #endif |
| 318 | } else { |
| 319 | pNewMem = realloc(pMemory, size); |
| 320 | } |
| 321 | return pNewMem; |
| 322 | } |
| 323 | |
| 324 | // Environment variables |
| 325 | #if defined(__linux__) |
| 326 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 327 | static inline char *loader_getenv(const char *name, const struct loader_instance *inst) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 328 | // No allocation of memory necessary for Linux, but we should at least touch |
| 329 | // the inst pointer to get rid of compiler warnings. |
| 330 | (void)inst; |
| 331 | return getenv(name); |
| 332 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 333 | static inline void loader_free_getenv(char *val, const struct loader_instance *inst) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 334 | // No freeing of memory necessary for Linux, but we should at least touch |
| 335 | // the val and inst pointers to get rid of compiler warnings. |
| 336 | (void)val; |
| 337 | (void)inst; |
| 338 | } |
| 339 | |
| 340 | #elif defined(WIN32) |
| 341 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 342 | static inline char *loader_getenv(const char *name, const struct loader_instance *inst) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 343 | char *retVal; |
| 344 | DWORD valSize; |
| 345 | |
| 346 | valSize = GetEnvironmentVariableA(name, NULL, 0); |
| 347 | |
| 348 | // valSize DOES include the null terminator, so for any set variable |
| 349 | // will always be at least 1. If it's 0, the variable wasn't set. |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 350 | if (valSize == 0) return NULL; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 351 | |
| 352 | // Allocate the space necessary for the registry entry |
| 353 | if (NULL != inst && NULL != inst->alloc_callbacks.pfnAllocation) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 354 | retVal = (char *)inst->alloc_callbacks.pfnAllocation(inst->alloc_callbacks.pUserData, valSize, sizeof(char *), |
| 355 | VK_SYSTEM_ALLOCATION_SCOPE_COMMAND); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 356 | } else { |
| 357 | retVal = (char *)malloc(valSize); |
| 358 | } |
| 359 | |
| 360 | if (NULL != retVal) { |
| 361 | GetEnvironmentVariableA(name, retVal, valSize); |
| 362 | } |
| 363 | |
| 364 | return retVal; |
| 365 | } |
| 366 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 367 | static inline void loader_free_getenv(char *val, const struct loader_instance *inst) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 368 | if (NULL != inst && NULL != inst->alloc_callbacks.pfnFree) { |
| 369 | inst->alloc_callbacks.pfnFree(inst->alloc_callbacks.pUserData, val); |
| 370 | } else { |
| 371 | free((void *)val); |
| 372 | } |
| 373 | } |
| 374 | |
| 375 | #else |
| 376 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 377 | static inline char *loader_getenv(const char *name, const struct loader_instance *inst) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 378 | // stub func |
| 379 | (void)inst; |
| 380 | (void)name; |
| 381 | return NULL; |
| 382 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 383 | static inline void loader_free_getenv(char *val, const struct loader_instance *inst) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 384 | // stub func |
| 385 | (void)val; |
| 386 | (void)inst; |
| 387 | } |
| 388 | |
| 389 | #endif |
| 390 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 391 | void loader_log(const struct loader_instance *inst, VkFlags msg_type, int32_t msg_code, const char *format, ...) { |
Jon Ashburn | 86723b0 | 2015-07-31 15:47:59 -0600 | [diff] [blame] | 392 | char msg[512]; |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 393 | char cmd_line_msg[512]; |
| 394 | uint16_t cmd_line_size = sizeof(cmd_line_msg); |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 395 | va_list ap; |
| 396 | int ret; |
| 397 | |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 398 | va_start(ap, format); |
| 399 | ret = vsnprintf(msg, sizeof(msg), format, ap); |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 400 | if ((ret >= (int)sizeof(msg)) || ret < 0) { |
| 401 | msg[sizeof(msg) - 1] = '\0'; |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 402 | } |
| 403 | va_end(ap); |
| 404 | |
Courtney Goeltzenleuchter | 7347739 | 2015-12-03 13:48:01 -0700 | [diff] [blame] | 405 | if (inst) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 406 | util_DebugReportMessage(inst, msg_type, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, (uint64_t)(uintptr_t)inst, 0, msg_code, |
| 407 | "loader", msg); |
Courtney Goeltzenleuchter | 7347739 | 2015-12-03 13:48:01 -0700 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | if (!(msg_type & g_loader_log_msgs)) { |
| 411 | return; |
| 412 | } |
| 413 | |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 414 | cmd_line_msg[0] = '\0'; |
| 415 | |
| 416 | va_start(ap, format); |
| 417 | if ((msg_type & LOADER_INFO_BIT) != 0) { |
| 418 | strcat(cmd_line_msg, "INFO"); |
| 419 | cmd_line_size -= 4; |
| 420 | } |
| 421 | if ((msg_type & LOADER_WARN_BIT) != 0) { |
| 422 | if (cmd_line_size != sizeof(cmd_line_msg)) { |
| 423 | strcat(cmd_line_msg, " | "); |
| 424 | cmd_line_size -= 3; |
| 425 | } |
| 426 | strcat(cmd_line_msg, "WARNING"); |
| 427 | cmd_line_size -= 7; |
| 428 | } |
| 429 | if ((msg_type & LOADER_PERF_BIT) != 0) { |
| 430 | if (cmd_line_size != sizeof(cmd_line_msg)) { |
| 431 | strcat(cmd_line_msg, " | "); |
| 432 | cmd_line_size -= 3; |
| 433 | } |
| 434 | strcat(cmd_line_msg, "PERF"); |
| 435 | cmd_line_size -= 4; |
| 436 | } |
| 437 | if ((msg_type & LOADER_ERROR_BIT) != 0) { |
| 438 | if (cmd_line_size != sizeof(cmd_line_msg)) { |
| 439 | strcat(cmd_line_msg, " | "); |
| 440 | cmd_line_size -= 3; |
| 441 | } |
| 442 | strcat(cmd_line_msg, "ERROR"); |
| 443 | cmd_line_size -= 5; |
| 444 | } |
| 445 | if ((msg_type & LOADER_DEBUG_BIT) != 0) { |
| 446 | if (cmd_line_size != sizeof(cmd_line_msg)) { |
| 447 | strcat(cmd_line_msg, " | "); |
| 448 | cmd_line_size -= 3; |
| 449 | } |
| 450 | strcat(cmd_line_msg, "DEBUG"); |
| 451 | cmd_line_size -= 5; |
| 452 | } |
| 453 | if (cmd_line_size != sizeof(cmd_line_msg)) { |
| 454 | strcat(cmd_line_msg, ": "); |
| 455 | cmd_line_size -= 2; |
| 456 | } |
| 457 | strncat(cmd_line_msg, msg, cmd_line_size); |
| 458 | |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 459 | #if defined(WIN32) |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 460 | OutputDebugString(cmd_line_msg); |
mschott | b9cdb78 | 2015-07-22 14:11:29 +0200 | [diff] [blame] | 461 | OutputDebugString("\n"); |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 462 | #endif |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 463 | fputs(cmd_line_msg, stderr); |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 464 | fputc('\n', stderr); |
| 465 | } |
| 466 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 467 | VKAPI_ATTR VkResult VKAPI_CALL vkSetInstanceDispatch(VkInstance instance, void *object) { |
Jon Ashburn | c3c5877 | 2016-03-29 11:16:01 -0600 | [diff] [blame] | 468 | struct loader_instance *inst = loader_get_instance(instance); |
| 469 | if (!inst) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 470 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 471 | "vkSetInstanceDispatch: Can not retrieve Instance " |
| 472 | "dispatch table."); |
Jon Ashburn | c3c5877 | 2016-03-29 11:16:01 -0600 | [diff] [blame] | 473 | return VK_ERROR_INITIALIZATION_FAILED; |
| 474 | } |
| 475 | loader_set_dispatch(object, inst->disp); |
| 476 | return VK_SUCCESS; |
| 477 | } |
| 478 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 479 | VKAPI_ATTR VkResult VKAPI_CALL vkSetDeviceDispatch(VkDevice device, void *object) { |
Jon Ashburn | ed8f231 | 2016-03-31 10:52:22 -0600 | [diff] [blame] | 480 | struct loader_device *dev; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 481 | struct loader_icd_term *icd_term = loader_get_icd_and_device(device, &dev, NULL); |
Jon Ashburn | ed8f231 | 2016-03-31 10:52:22 -0600 | [diff] [blame] | 482 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 483 | if (NULL == icd_term) { |
Jon Ashburn | ed8f231 | 2016-03-31 10:52:22 -0600 | [diff] [blame] | 484 | return VK_ERROR_INITIALIZATION_FAILED; |
| 485 | } |
| 486 | loader_set_dispatch(object, &dev->loader_dispatch); |
| 487 | return VK_SUCCESS; |
| 488 | } |
| 489 | |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 490 | #if defined(WIN32) |
Tony Barbour | ea96890 | 2015-07-29 14:26:21 -0600 | [diff] [blame] | 491 | static char *loader_get_next_path(char *path); |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 492 | |
| 493 | // Find the list of registry files (names within a key) in key "location". |
| 494 | // |
| 495 | // This function looks in the registry (hive = DEFAULT_VK_REGISTRY_HIVE) key as |
| 496 | // given in "location" |
| 497 | // for a list or name/values which are added to a returned list (function return |
| 498 | // value). |
| 499 | // The DWORD values within the key must be 0 or they are skipped. |
| 500 | // Function return is a string with a ';' separated list of filenames. |
| 501 | // Function return is NULL if no valid name/value pairs are found in the key, |
| 502 | // or the key is not found. |
| 503 | // |
| 504 | // *reg_data contains a string list of filenames as pointer. |
| 505 | // When done using the returned string list, the caller should free the pointer. |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 506 | VkResult loaderGetRegistryFiles(const struct loader_instance *inst, char *location, char **reg_data) { |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 507 | LONG rtn_value; |
| 508 | HKEY hive, key; |
Piers Daniell | 524ec73 | 2015-11-05 16:58:26 -0700 | [diff] [blame] | 509 | DWORD access_flags; |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 510 | char name[2048]; |
Tony Barbour | ea96890 | 2015-07-29 14:26:21 -0600 | [diff] [blame] | 511 | char *loc = location; |
| 512 | char *next; |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 513 | DWORD idx = 0; |
| 514 | DWORD name_size = sizeof(name); |
| 515 | DWORD value; |
| 516 | DWORD total_size = 4096; |
| 517 | DWORD value_size = sizeof(value); |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 518 | VkResult result = VK_SUCCESS; |
| 519 | bool found = false; |
| 520 | |
| 521 | if (NULL == reg_data) { |
| 522 | result = VK_ERROR_INITIALIZATION_FAILED; |
| 523 | goto out; |
| 524 | } |
Tony Barbour | ea96890 | 2015-07-29 14:26:21 -0600 | [diff] [blame] | 525 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 526 | while (*loc) { |
Tony Barbour | ea96890 | 2015-07-29 14:26:21 -0600 | [diff] [blame] | 527 | next = loader_get_next_path(loc); |
| 528 | hive = DEFAULT_VK_REGISTRY_HIVE; |
Piers Daniell | 524ec73 | 2015-11-05 16:58:26 -0700 | [diff] [blame] | 529 | access_flags = KEY_QUERY_VALUE; |
Tony Barbour | ea96890 | 2015-07-29 14:26:21 -0600 | [diff] [blame] | 530 | rtn_value = RegOpenKeyEx(hive, loc, 0, access_flags, &key); |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 531 | if (ERROR_SUCCESS != rtn_value) { |
Mark Young | 93ecb1d | 2016-01-13 13:47:16 -0700 | [diff] [blame] | 532 | // We still couldn't find the key, so give up: |
| 533 | loc = next; |
| 534 | continue; |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 535 | } |
Tony Barbour | ea96890 | 2015-07-29 14:26:21 -0600 | [diff] [blame] | 536 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 537 | while ((rtn_value = RegEnumValue(key, idx++, name, &name_size, NULL, NULL, (LPBYTE)&value, &value_size)) == ERROR_SUCCESS) { |
Tony Barbour | ea96890 | 2015-07-29 14:26:21 -0600 | [diff] [blame] | 538 | if (value_size == sizeof(value) && value == 0) { |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 539 | if (NULL == *reg_data) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 540 | *reg_data = loader_instance_heap_alloc(inst, total_size, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 541 | if (NULL == *reg_data) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 542 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 543 | "loaderGetRegistryFiles: Failed to allocate " |
| 544 | "space for registry data for key %s", |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 545 | name); |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 546 | result = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 547 | goto out; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 548 | } |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 549 | *reg_data[0] = '\0'; |
| 550 | } else if (strlen(*reg_data) + name_size + 1 > total_size) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 551 | *reg_data = loader_instance_heap_realloc(inst, *reg_data, total_size, total_size * 2, |
| 552 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 553 | if (NULL == *reg_data) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 554 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 555 | "loaderGetRegistryFiles: Failed to reallocate " |
| 556 | "space for registry value of size %d for key %s", |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 557 | total_size * 2, name); |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 558 | result = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 559 | goto out; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 560 | } |
Tony Barbour | ea96890 | 2015-07-29 14:26:21 -0600 | [diff] [blame] | 561 | total_size *= 2; |
| 562 | } |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 563 | if (strlen(*reg_data) == 0) { |
Karl Schultz | e2ef9e6 | 2017-01-13 14:01:35 -0700 | [diff] [blame] | 564 | (void)snprintf(*reg_data, name_size + 1, "%s", name); |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 565 | } else { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 566 | (void)snprintf(*reg_data + strlen(*reg_data), name_size + 2, "%c%s", PATH_SEPARATOR, name); |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 567 | } |
| 568 | found = true; |
Tony Barbour | ea96890 | 2015-07-29 14:26:21 -0600 | [diff] [blame] | 569 | } |
| 570 | name_size = 2048; |
| 571 | } |
| 572 | loc = next; |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 573 | } |
Tony Barbour | ea96890 | 2015-07-29 14:26:21 -0600 | [diff] [blame] | 574 | |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 575 | if (!found) { |
| 576 | result = VK_ERROR_INITIALIZATION_FAILED; |
| 577 | } |
| 578 | |
| 579 | out: |
| 580 | |
| 581 | return result; |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 582 | } |
| 583 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 584 | #endif // WIN32 |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 585 | |
Jon Ashburn | c7237a7 | 2015-08-03 09:08:46 -0600 | [diff] [blame] | 586 | /** |
Daniel Dadap | 00b4aba | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 587 | * Combine path elements, separating each element with the platform-specific |
| 588 | * directory separator, and save the combined string to a destination buffer, |
| 589 | * not exceeding the given length. Path elements are given as variadic args, |
| 590 | * with a NULL element terminating the list. |
| 591 | * |
| 592 | * \returns the total length of the combined string, not including an ASCII |
| 593 | * NUL termination character. This length may exceed the available storage: |
| 594 | * in this case, the written string will be truncated to avoid a buffer |
| 595 | * overrun, and the return value will greater than or equal to the storage |
| 596 | * size. A NULL argument may be provided as the destination buffer in order |
| 597 | * to determine the required string length without actually writing a string. |
| 598 | */ |
| 599 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 600 | static size_t loader_platform_combine_path(char *dest, size_t len, ...) { |
Courtney Goeltzenleuchter | 0ef13a0 | 2015-12-16 16:19:46 -0700 | [diff] [blame] | 601 | size_t required_len = 0; |
Daniel Dadap | 00b4aba | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 602 | va_list ap; |
| 603 | const char *component; |
| 604 | |
| 605 | va_start(ap, len); |
| 606 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 607 | while ((component = va_arg(ap, const char *))) { |
Daniel Dadap | 00b4aba | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 608 | if (required_len > 0) { |
| 609 | // This path element is not the first non-empty element; prepend |
| 610 | // a directory separator if space allows |
| 611 | if (dest && required_len + 1 < len) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 612 | (void)snprintf(dest + required_len, len - required_len, "%c", DIRECTORY_SYMBOL); |
Daniel Dadap | 00b4aba | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 613 | } |
| 614 | required_len++; |
| 615 | } |
| 616 | |
| 617 | if (dest && required_len < len) { |
| 618 | strncpy(dest + required_len, component, len - required_len); |
| 619 | } |
| 620 | required_len += strlen(component); |
| 621 | } |
| 622 | |
| 623 | va_end(ap); |
| 624 | |
| 625 | // strncpy(3) won't add a NUL terminating byte in the event of truncation. |
| 626 | if (dest && required_len >= len) { |
| 627 | dest[len - 1] = '\0'; |
| 628 | } |
| 629 | |
| 630 | return required_len; |
| 631 | } |
| 632 | |
Daniel Dadap | 00b4aba | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 633 | /** |
Jon Ashburn | c7237a7 | 2015-08-03 09:08:46 -0600 | [diff] [blame] | 634 | * Given string of three part form "maj.min.pat" convert to a vulkan version |
| 635 | * number. |
| 636 | */ |
Mark Young | 60861ac | 2016-09-02 11:39:26 -0600 | [diff] [blame] | 637 | static uint32_t loader_make_version(char *vers_str) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 638 | uint32_t vers = 0, major = 0, minor = 0, patch = 0; |
Mark Young | 60861ac | 2016-09-02 11:39:26 -0600 | [diff] [blame] | 639 | char *vers_tok; |
Jon Ashburn | c7237a7 | 2015-08-03 09:08:46 -0600 | [diff] [blame] | 640 | |
Mark Young | 60861ac | 2016-09-02 11:39:26 -0600 | [diff] [blame] | 641 | if (!vers_str) { |
Jon Ashburn | c7237a7 | 2015-08-03 09:08:46 -0600 | [diff] [blame] | 642 | return vers; |
Jon Ashburn | c7237a7 | 2015-08-03 09:08:46 -0600 | [diff] [blame] | 643 | } |
Mark Young | 60861ac | 2016-09-02 11:39:26 -0600 | [diff] [blame] | 644 | |
| 645 | vers_tok = strtok(vers_str, ".\"\n\r"); |
| 646 | if (NULL != vers_tok) { |
| 647 | major = (uint16_t)atoi(vers_tok); |
| 648 | vers_tok = strtok(NULL, ".\"\n\r"); |
| 649 | if (NULL != vers_tok) { |
| 650 | minor = (uint16_t)atoi(vers_tok); |
| 651 | vers_tok = strtok(NULL, ".\"\n\r"); |
| 652 | if (NULL != vers_tok) { |
| 653 | patch = (uint16_t)atoi(vers_tok); |
| 654 | } |
| 655 | } |
| 656 | } |
Jon Ashburn | c7237a7 | 2015-08-03 09:08:46 -0600 | [diff] [blame] | 657 | |
| 658 | return VK_MAKE_VERSION(major, minor, patch); |
Jon Ashburn | c7237a7 | 2015-08-03 09:08:46 -0600 | [diff] [blame] | 659 | } |
| 660 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 661 | bool compare_vk_extension_properties(const VkExtensionProperties *op1, const VkExtensionProperties *op2) { |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 662 | return strcmp(op1->extensionName, op2->extensionName) == 0 ? true : false; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 663 | } |
| 664 | |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 665 | /** |
Jon Ashburn | bd6c488 | 2015-07-02 12:59:25 -0600 | [diff] [blame] | 666 | * Search the given ext_array for an extension |
| 667 | * matching the given vk_ext_prop |
| 668 | */ |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 669 | bool has_vk_extension_property_array(const VkExtensionProperties *vk_ext_prop, const uint32_t count, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 670 | const VkExtensionProperties *ext_array) { |
Jon Ashburn | bd6c488 | 2015-07-02 12:59:25 -0600 | [diff] [blame] | 671 | for (uint32_t i = 0; i < count; i++) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 672 | if (compare_vk_extension_properties(vk_ext_prop, &ext_array[i])) return true; |
Jon Ashburn | bd6c488 | 2015-07-02 12:59:25 -0600 | [diff] [blame] | 673 | } |
| 674 | return false; |
| 675 | } |
| 676 | |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 677 | /** |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 678 | * Search the given ext_list for an extension |
| 679 | * matching the given vk_ext_prop |
| 680 | */ |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 681 | bool has_vk_extension_property(const VkExtensionProperties *vk_ext_prop, const struct loader_extension_list *ext_list) { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 682 | for (uint32_t i = 0; i < ext_list->count; i++) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 683 | if (compare_vk_extension_properties(&ext_list->list[i], vk_ext_prop)) return true; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 684 | } |
| 685 | return false; |
| 686 | } |
| 687 | |
Jon Ashburn | b872696 | 2016-04-08 15:03:35 -0600 | [diff] [blame] | 688 | /** |
| 689 | * Search the given ext_list for a device extension matching the given ext_prop |
| 690 | */ |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 691 | bool has_vk_dev_ext_property(const VkExtensionProperties *ext_prop, const struct loader_device_extension_list *ext_list) { |
Jon Ashburn | b872696 | 2016-04-08 15:03:35 -0600 | [diff] [blame] | 692 | for (uint32_t i = 0; i < ext_list->count; i++) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 693 | if (compare_vk_extension_properties(&ext_list->list[i].props, ext_prop)) return true; |
Jon Ashburn | b872696 | 2016-04-08 15:03:35 -0600 | [diff] [blame] | 694 | } |
| 695 | return false; |
| 696 | } |
| 697 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 698 | /* |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 699 | * 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] | 700 | */ |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 701 | static struct loader_layer_properties *loader_get_layer_property(const char *name, const struct loader_layer_list *layer_list) { |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 702 | for (uint32_t i = 0; i < layer_list->count; i++) { |
| 703 | const VkLayerProperties *item = &layer_list->list[i].info; |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 704 | if (strcmp(name, item->layerName) == 0) return &layer_list->list[i]; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 705 | } |
| 706 | return NULL; |
| 707 | } |
| 708 | |
Jon Ashburn | e13ecc9 | 2015-08-03 17:19:30 -0600 | [diff] [blame] | 709 | /** |
| 710 | * Get the next unused layer property in the list. Init the property to zero. |
| 711 | */ |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 712 | static struct loader_layer_properties *loader_get_next_layer_property(const struct loader_instance *inst, |
| 713 | struct loader_layer_list *layer_list) { |
Jon Ashburn | e13ecc9 | 2015-08-03 17:19:30 -0600 | [diff] [blame] | 714 | if (layer_list->capacity == 0) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 715 | layer_list->list = |
| 716 | loader_instance_heap_alloc(inst, sizeof(struct loader_layer_properties) * 64, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Jon Ashburn | e13ecc9 | 2015-08-03 17:19:30 -0600 | [diff] [blame] | 717 | if (layer_list->list == NULL) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 718 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 719 | "loader_get_next_layer_property: Out of memory can " |
| 720 | "not add any layer properties to list"); |
Jon Ashburn | e13ecc9 | 2015-08-03 17:19:30 -0600 | [diff] [blame] | 721 | return NULL; |
| 722 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 723 | memset(layer_list->list, 0, sizeof(struct loader_layer_properties) * 64); |
Jon Ashburn | e13ecc9 | 2015-08-03 17:19:30 -0600 | [diff] [blame] | 724 | layer_list->capacity = sizeof(struct loader_layer_properties) * 64; |
| 725 | } |
| 726 | |
| 727 | // ensure enough room to add an entry |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 728 | if ((layer_list->count + 1) * sizeof(struct loader_layer_properties) > layer_list->capacity) { |
| 729 | layer_list->list = loader_instance_heap_realloc(inst, layer_list->list, layer_list->capacity, layer_list->capacity * 2, |
| 730 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Jon Ashburn | e13ecc9 | 2015-08-03 17:19:30 -0600 | [diff] [blame] | 731 | if (layer_list->list == NULL) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 732 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 733 | "loader_get_next_layer_property: realloc failed for " |
| 734 | "layer list"); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 735 | return NULL; |
Jon Ashburn | e13ecc9 | 2015-08-03 17:19:30 -0600 | [diff] [blame] | 736 | } |
| 737 | layer_list->capacity *= 2; |
| 738 | } |
| 739 | |
| 740 | layer_list->count++; |
| 741 | return &(layer_list->list[layer_list->count - 1]); |
| 742 | } |
| 743 | |
| 744 | /** |
| 745 | * Remove all layer properties entrys from the list |
| 746 | */ |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 747 | void loader_delete_layer_properties(const struct loader_instance *inst, struct loader_layer_list *layer_list) { |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 748 | uint32_t i, j; |
| 749 | struct loader_device_extension_list *dev_ext_list; |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 750 | if (!layer_list) return; |
Jon Ashburn | b82c185 | 2015-08-11 14:49:54 -0600 | [diff] [blame] | 751 | |
Jon Ashburn | e13ecc9 | 2015-08-03 17:19:30 -0600 | [diff] [blame] | 752 | for (i = 0; i < layer_list->count; i++) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 753 | loader_destroy_generic_list(inst, (struct loader_generic_list *)&layer_list->list[i].instance_extension_list); |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 754 | dev_ext_list = &layer_list->list[i].device_extension_list; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 755 | if (dev_ext_list->capacity > 0 && NULL != dev_ext_list->list && dev_ext_list->list->entrypoint_count > 0) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 756 | for (j = 0; j < dev_ext_list->list->entrypoint_count; j++) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 757 | loader_instance_heap_free(inst, dev_ext_list->list->entrypoints[j]); |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 758 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 759 | loader_instance_heap_free(inst, dev_ext_list->list->entrypoints); |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 760 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 761 | loader_destroy_generic_list(inst, (struct loader_generic_list *)dev_ext_list); |
Jon Ashburn | e13ecc9 | 2015-08-03 17:19:30 -0600 | [diff] [blame] | 762 | } |
| 763 | layer_list->count = 0; |
| 764 | |
Jon Ashburn | b82c185 | 2015-08-11 14:49:54 -0600 | [diff] [blame] | 765 | if (layer_list->capacity > 0) { |
| 766 | layer_list->capacity = 0; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 767 | loader_instance_heap_free(inst, layer_list->list); |
Jon Ashburn | b82c185 | 2015-08-11 14:49:54 -0600 | [diff] [blame] | 768 | } |
Jon Ashburn | e13ecc9 | 2015-08-03 17:19:30 -0600 | [diff] [blame] | 769 | } |
| 770 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 771 | static VkResult loader_add_instance_extensions(const struct loader_instance *inst, |
| 772 | const PFN_vkEnumerateInstanceExtensionProperties fp_get_props, const char *lib_name, |
| 773 | struct loader_extension_list *ext_list) { |
Courtney Goeltzenleuchter | 36eeb74 | 2015-12-21 16:41:47 -0700 | [diff] [blame] | 774 | uint32_t i, count = 0; |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 775 | VkExtensionProperties *ext_props; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 776 | VkResult res = VK_SUCCESS; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 777 | |
Courtney Goeltzenleuchter | 5c6cf47 | 2015-07-06 22:28:18 -0600 | [diff] [blame] | 778 | if (!fp_get_props) { |
Courtney Goeltzenleuchter | 35985f6 | 2015-09-14 17:22:16 -0600 | [diff] [blame] | 779 | /* No EnumerateInstanceExtensionProperties defined */ |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 780 | goto out; |
Courtney Goeltzenleuchter | 5c6cf47 | 2015-07-06 22:28:18 -0600 | [diff] [blame] | 781 | } |
| 782 | |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 783 | res = fp_get_props(NULL, &count, NULL); |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 784 | if (res != VK_SUCCESS) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 785 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 786 | "loader_add_instance_extensions: Error getting Instance " |
| 787 | "extension count from %s", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 788 | lib_name); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 789 | goto out; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 790 | } |
Jon Ashburn | 953bb3c | 2015-06-10 16:11:42 -0600 | [diff] [blame] | 791 | |
Courtney Goeltzenleuchter | 5c6cf47 | 2015-07-06 22:28:18 -0600 | [diff] [blame] | 792 | if (count == 0) { |
| 793 | /* No ExtensionProperties to report */ |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 794 | goto out; |
Courtney Goeltzenleuchter | 5c6cf47 | 2015-07-06 22:28:18 -0600 | [diff] [blame] | 795 | } |
| 796 | |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 797 | ext_props = loader_stack_alloc(count * sizeof(VkExtensionProperties)); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 798 | if (NULL == ext_props) { |
| 799 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 800 | goto out; |
| 801 | } |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 802 | |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 803 | res = fp_get_props(NULL, &count, ext_props); |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 804 | if (res != VK_SUCCESS) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 805 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 806 | "loader_add_instance_extensions: Error getting Instance " |
| 807 | "extensions from %s", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 808 | lib_name); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 809 | goto out; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 810 | } |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 811 | |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 812 | for (i = 0; i < count; i++) { |
Courtney Goeltzenleuchter | 5304373 | 2015-07-12 13:20:05 -0600 | [diff] [blame] | 813 | char spec_version[64]; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 814 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 815 | bool ext_unsupported = wsi_unsupported_instance_extension(&ext_props[i]); |
Jon Ashburn | 6fa520f | 2016-03-25 12:49:35 -0600 | [diff] [blame] | 816 | if (!ext_unsupported) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 817 | (void)snprintf(spec_version, sizeof(spec_version), "%d.%d.%d", VK_MAJOR(ext_props[i].specVersion), |
| 818 | VK_MINOR(ext_props[i].specVersion), VK_PATCH(ext_props[i].specVersion)); |
| 819 | loader_log(inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, "Instance Extension: %s (%s) version %s", ext_props[i].extensionName, |
| 820 | lib_name, spec_version); |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 821 | |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 822 | res = loader_add_to_ext_list(inst, ext_list, 1, &ext_props[i]); |
| 823 | if (res != VK_SUCCESS) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 824 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 825 | "loader_add_instance_extensions: Failed to add %s " |
| 826 | "to Instance extension list", |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 827 | lib_name); |
| 828 | goto out; |
| 829 | } |
Jon Ashburn | 6fa520f | 2016-03-25 12:49:35 -0600 | [diff] [blame] | 830 | } |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 831 | } |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 832 | |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 833 | out: |
| 834 | return res; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 835 | } |
| 836 | |
Jon Ashburn | 00eb6c0 | 2015-11-02 17:40:01 -0700 | [diff] [blame] | 837 | /* |
| 838 | * Initialize ext_list with the physical device extensions. |
| 839 | * The extension properties are passed as inputs in count and ext_props. |
| 840 | */ |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 841 | static VkResult loader_init_device_extensions(const struct loader_instance *inst, struct loader_physical_device_term *phys_dev_term, |
| 842 | uint32_t count, VkExtensionProperties *ext_props, |
| 843 | struct loader_extension_list *ext_list) { |
Jon Ashburn | 00eb6c0 | 2015-11-02 17:40:01 -0700 | [diff] [blame] | 844 | VkResult res; |
| 845 | uint32_t i; |
| 846 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 847 | res = loader_init_generic_list(inst, (struct loader_generic_list *)ext_list, sizeof(VkExtensionProperties)); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 848 | if (VK_SUCCESS != res) { |
| 849 | return res; |
Jon Ashburn | 00eb6c0 | 2015-11-02 17:40:01 -0700 | [diff] [blame] | 850 | } |
| 851 | |
| 852 | for (i = 0; i < count; i++) { |
| 853 | char spec_version[64]; |
| 854 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 855 | (void)snprintf(spec_version, sizeof(spec_version), "%d.%d.%d", VK_MAJOR(ext_props[i].specVersion), |
| 856 | VK_MINOR(ext_props[i].specVersion), VK_PATCH(ext_props[i].specVersion)); |
| 857 | loader_log(inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, "Device Extension: %s (%s) version %s", ext_props[i].extensionName, |
| 858 | phys_dev_term->this_icd_term->scanned_icd->lib_name, spec_version); |
Jon Ashburn | 00eb6c0 | 2015-11-02 17:40:01 -0700 | [diff] [blame] | 859 | res = loader_add_to_ext_list(inst, ext_list, 1, &ext_props[i]); |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 860 | if (res != VK_SUCCESS) return res; |
Jon Ashburn | 00eb6c0 | 2015-11-02 17:40:01 -0700 | [diff] [blame] | 861 | } |
| 862 | |
| 863 | return VK_SUCCESS; |
| 864 | } |
| 865 | |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 866 | VkResult loader_add_device_extensions(const struct loader_instance *inst, |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 867 | PFN_vkEnumerateDeviceExtensionProperties fpEnumerateDeviceExtensionProperties, |
| 868 | VkPhysicalDevice physical_device, const char *lib_name, |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 869 | struct loader_extension_list *ext_list) { |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 870 | uint32_t i, count; |
| 871 | VkResult res; |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 872 | VkExtensionProperties *ext_props; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 873 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 874 | res = fpEnumerateDeviceExtensionProperties(physical_device, NULL, &count, NULL); |
Jon Ashburn | 00eb6c0 | 2015-11-02 17:40:01 -0700 | [diff] [blame] | 875 | if (res == VK_SUCCESS && count > 0) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 876 | ext_props = loader_stack_alloc(count * sizeof(VkExtensionProperties)); |
Mark Young | 9a3ddd4 | 2016-10-21 16:25:47 -0600 | [diff] [blame] | 877 | if (!ext_props) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 878 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 879 | "loader_add_device_extensions: Failed to allocate space" |
| 880 | " for device extension properties."); |
Jon Ashburn | 00eb6c0 | 2015-11-02 17:40:01 -0700 | [diff] [blame] | 881 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Mark Young | 9a3ddd4 | 2016-10-21 16:25:47 -0600 | [diff] [blame] | 882 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 883 | res = fpEnumerateDeviceExtensionProperties(physical_device, NULL, &count, ext_props); |
Mark Young | 9a3ddd4 | 2016-10-21 16:25:47 -0600 | [diff] [blame] | 884 | if (res != VK_SUCCESS) { |
Jon Ashburn | 24cd4be | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 885 | return res; |
Mark Young | 9a3ddd4 | 2016-10-21 16:25:47 -0600 | [diff] [blame] | 886 | } |
Jon Ashburn | 00eb6c0 | 2015-11-02 17:40:01 -0700 | [diff] [blame] | 887 | for (i = 0; i < count; i++) { |
| 888 | char spec_version[64]; |
| 889 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 890 | (void)snprintf(spec_version, sizeof(spec_version), "%d.%d.%d", VK_MAJOR(ext_props[i].specVersion), |
| 891 | VK_MINOR(ext_props[i].specVersion), VK_PATCH(ext_props[i].specVersion)); |
| 892 | loader_log(inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, "Device Extension: %s (%s) version %s", ext_props[i].extensionName, |
| 893 | lib_name, spec_version); |
Jon Ashburn | 00eb6c0 | 2015-11-02 17:40:01 -0700 | [diff] [blame] | 894 | res = loader_add_to_ext_list(inst, ext_list, 1, &ext_props[i]); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 895 | if (res != VK_SUCCESS) { |
Jon Ashburn | 00eb6c0 | 2015-11-02 17:40:01 -0700 | [diff] [blame] | 896 | return res; |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 897 | } |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 898 | } |
Jon Ashburn | 00eb6c0 | 2015-11-02 17:40:01 -0700 | [diff] [blame] | 899 | } else { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 900 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 901 | "loader_add_device_extensions: Error getting physical " |
| 902 | "device extension info count from library %s", |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 903 | lib_name); |
Jon Ashburn | 00eb6c0 | 2015-11-02 17:40:01 -0700 | [diff] [blame] | 904 | return res; |
| 905 | } |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 906 | |
Jon Ashburn | 24cd4be | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 907 | return VK_SUCCESS; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 908 | } |
| 909 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 910 | VkResult loader_init_generic_list(const struct loader_instance *inst, struct loader_generic_list *list_info, size_t element_size) { |
Mark Young | 84ba048 | 2016-09-02 11:45:00 -0600 | [diff] [blame] | 911 | size_t capacity = 32 * element_size; |
| 912 | list_info->count = 0; |
| 913 | list_info->capacity = 0; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 914 | list_info->list = loader_instance_heap_alloc(inst, capacity, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Jon Ashburn | 6e6a216 | 2015-12-10 08:51:10 -0700 | [diff] [blame] | 915 | if (list_info->list == NULL) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 916 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 917 | "loader_init_generic_list: Failed to allocate space " |
| 918 | "for generic list"); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 919 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 920 | } |
Mark Young | 84ba048 | 2016-09-02 11:45:00 -0600 | [diff] [blame] | 921 | memset(list_info->list, 0, capacity); |
| 922 | list_info->capacity = capacity; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 923 | return VK_SUCCESS; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 924 | } |
| 925 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 926 | void loader_destroy_generic_list(const struct loader_instance *inst, struct loader_generic_list *list) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 927 | loader_instance_heap_free(inst, list->list); |
Jon Ashburn | 6e6a216 | 2015-12-10 08:51:10 -0700 | [diff] [blame] | 928 | list->count = 0; |
| 929 | list->capacity = 0; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 930 | } |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 931 | |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 932 | /* |
| 933 | * Append non-duplicate extension properties defined in props |
| 934 | * to the given ext_list. |
Jon Ashburn | 24cd4be | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 935 | * Return |
| 936 | * Vk_SUCCESS on success |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 937 | */ |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 938 | VkResult loader_add_to_ext_list(const struct loader_instance *inst, struct loader_extension_list *ext_list, |
| 939 | uint32_t prop_list_count, const VkExtensionProperties *props) { |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 940 | uint32_t i; |
| 941 | const VkExtensionProperties *cur_ext; |
| 942 | |
| 943 | if (ext_list->list == NULL || ext_list->capacity == 0) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 944 | VkResult res = loader_init_generic_list(inst, (struct loader_generic_list *)ext_list, sizeof(VkExtensionProperties)); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 945 | if (VK_SUCCESS != res) { |
| 946 | return res; |
| 947 | } |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 948 | } |
| 949 | |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 950 | for (i = 0; i < prop_list_count; i++) { |
| 951 | cur_ext = &props[i]; |
| 952 | |
| 953 | // look for duplicates |
| 954 | if (has_vk_extension_property(cur_ext, ext_list)) { |
| 955 | continue; |
| 956 | } |
| 957 | |
| 958 | // add to list at end |
| 959 | // check for enough capacity |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 960 | if (ext_list->count * sizeof(VkExtensionProperties) >= ext_list->capacity) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 961 | ext_list->list = loader_instance_heap_realloc(inst, ext_list->list, ext_list->capacity, ext_list->capacity * 2, |
| 962 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Jon Ashburn | 24cd4be | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 963 | |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 964 | if (ext_list->list == NULL) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 965 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 966 | "loader_add_to_ext_list: Failed to reallocate " |
| 967 | "space for extension list"); |
Jon Ashburn | 24cd4be | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 968 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 969 | } |
Jon Ashburn | 24cd4be | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 970 | |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 971 | // double capacity |
| 972 | ext_list->capacity *= 2; |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 973 | } |
| 974 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 975 | memcpy(&ext_list->list[ext_list->count], cur_ext, sizeof(VkExtensionProperties)); |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 976 | ext_list->count++; |
| 977 | } |
Jon Ashburn | 24cd4be | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 978 | return VK_SUCCESS; |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 979 | } |
| 980 | |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 981 | /* |
| 982 | * Append one extension property defined in props with entrypoints |
Jon Ashburn | b872696 | 2016-04-08 15:03:35 -0600 | [diff] [blame] | 983 | * 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] | 984 | * Return |
| 985 | * Vk_SUCCESS on success |
| 986 | */ |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 987 | VkResult loader_add_to_dev_ext_list(const struct loader_instance *inst, struct loader_device_extension_list *ext_list, |
| 988 | const VkExtensionProperties *props, uint32_t entry_count, char **entrys) { |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 989 | uint32_t idx; |
| 990 | if (ext_list->list == NULL || ext_list->capacity == 0) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 991 | VkResult res = loader_init_generic_list(inst, (struct loader_generic_list *)ext_list, sizeof(struct loader_dev_ext_props)); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 992 | if (VK_SUCCESS != res) { |
| 993 | return res; |
| 994 | } |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 995 | } |
| 996 | |
Jon Ashburn | b872696 | 2016-04-08 15:03:35 -0600 | [diff] [blame] | 997 | // look for duplicates |
| 998 | if (has_vk_dev_ext_property(props, ext_list)) { |
| 999 | return VK_SUCCESS; |
| 1000 | } |
| 1001 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1002 | idx = ext_list->count; |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1003 | // add to list at end |
| 1004 | // check for enough capacity |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1005 | if (idx * sizeof(struct loader_dev_ext_props) >= ext_list->capacity) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1006 | ext_list->list = loader_instance_heap_realloc(inst, ext_list->list, ext_list->capacity, ext_list->capacity * 2, |
| 1007 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1008 | |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1009 | if (ext_list->list == NULL) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1010 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1011 | "loader_add_to_dev_ext_list: Failed to reallocate " |
| 1012 | "space for device extension list"); |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1013 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1014 | } |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1015 | |
| 1016 | // double capacity |
| 1017 | ext_list->capacity *= 2; |
| 1018 | } |
| 1019 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1020 | memcpy(&ext_list->list[idx].props, props, sizeof(struct loader_dev_ext_props)); |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1021 | ext_list->list[idx].entrypoint_count = entry_count; |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1022 | ext_list->list[idx].entrypoints = |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1023 | loader_instance_heap_alloc(inst, sizeof(char *) * entry_count, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1024 | if (ext_list->list[idx].entrypoints == NULL) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1025 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1026 | "loader_add_to_dev_ext_list: Failed to allocate space " |
| 1027 | "for device extension entrypoint list in list %d", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1028 | idx); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1029 | ext_list->list[idx].entrypoint_count = 0; |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1030 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1031 | } |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1032 | for (uint32_t i = 0; i < entry_count; i++) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1033 | ext_list->list[idx].entrypoints[i] = |
| 1034 | loader_instance_heap_alloc(inst, strlen(entrys[i]) + 1, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1035 | if (ext_list->list[idx].entrypoints[i] == NULL) { |
| 1036 | for (uint32_t j = 0; j < i; j++) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1037 | loader_instance_heap_free(inst, ext_list->list[idx].entrypoints[j]); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1038 | } |
| 1039 | loader_instance_heap_free(inst, ext_list->list[idx].entrypoints); |
| 1040 | ext_list->list[idx].entrypoint_count = 0; |
| 1041 | ext_list->list[idx].entrypoints = NULL; |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1042 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1043 | "loader_add_to_dev_ext_list: Failed to allocate space " |
| 1044 | "for device extension entrypoint %d name", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1045 | i); |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1046 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1047 | } |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1048 | strcpy(ext_list->list[idx].entrypoints[i], entrys[i]); |
| 1049 | } |
| 1050 | ext_list->count++; |
| 1051 | |
| 1052 | return VK_SUCCESS; |
| 1053 | } |
| 1054 | |
Jon Ashburn | bd6c488 | 2015-07-02 12:59:25 -0600 | [diff] [blame] | 1055 | /** |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1056 | * Search the given search_list for any layers in the props list. |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1057 | * Add these to the output layer_list. Don't add duplicates to the output |
| 1058 | * layer_list. |
Jon Ashburn | bd6c488 | 2015-07-02 12:59:25 -0600 | [diff] [blame] | 1059 | */ |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1060 | static VkResult loader_add_layer_names_to_list(const struct loader_instance *inst, struct loader_layer_list *output_list, |
| 1061 | uint32_t name_count, const char *const *names, |
| 1062 | const struct loader_layer_list *search_list) { |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1063 | struct loader_layer_properties *layer_prop; |
Courtney Goeltzenleuchter | 40caf0b | 2015-07-06 09:06:34 -0600 | [diff] [blame] | 1064 | VkResult err = VK_SUCCESS; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1065 | |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1066 | for (uint32_t i = 0; i < name_count; i++) { |
| 1067 | const char *search_target = names[i]; |
Jon Ashburn | e13ecc9 | 2015-08-03 17:19:30 -0600 | [diff] [blame] | 1068 | layer_prop = loader_get_layer_property(search_target, search_list); |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1069 | if (!layer_prop) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1070 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1071 | "loader_add_layer_names_to_list: Unable to find layer" |
| 1072 | " %s", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1073 | search_target); |
Courtney Goeltzenleuchter | 55659b7 | 2015-09-14 18:01:17 -0600 | [diff] [blame] | 1074 | err = VK_ERROR_LAYER_NOT_PRESENT; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1075 | continue; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1076 | } |
| 1077 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1078 | err = loader_add_to_layer_list(inst, output_list, 1, layer_prop); |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1079 | } |
Courtney Goeltzenleuchter | 40caf0b | 2015-07-06 09:06:34 -0600 | [diff] [blame] | 1080 | |
| 1081 | return err; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1082 | } |
| 1083 | |
Courtney Goeltzenleuchter | 7f5aafc | 2015-07-05 11:28:29 -0600 | [diff] [blame] | 1084 | /* |
| 1085 | * Manage lists of VkLayerProperties |
| 1086 | */ |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1087 | static bool loader_init_layer_list(const struct loader_instance *inst, struct loader_layer_list *list) { |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1088 | list->capacity = 32 * sizeof(struct loader_layer_properties); |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1089 | list->list = loader_instance_heap_alloc(inst, list->capacity, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1090 | if (list->list == NULL) { |
| 1091 | return false; |
| 1092 | } |
| 1093 | memset(list->list, 0, list->capacity); |
| 1094 | list->count = 0; |
| 1095 | return true; |
| 1096 | } |
| 1097 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1098 | void loader_destroy_layer_list(const struct loader_instance *inst, struct loader_device *device, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1099 | struct loader_layer_list *layer_list) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1100 | if (device) { |
| 1101 | loader_device_heap_free(device, layer_list->list); |
| 1102 | } else { |
| 1103 | loader_instance_heap_free(inst, layer_list->list); |
| 1104 | } |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1105 | layer_list->count = 0; |
| 1106 | layer_list->capacity = 0; |
| 1107 | } |
| 1108 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1109 | /* |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1110 | * Search the given layer list for a list |
| 1111 | * matching the given VkLayerProperties |
| 1112 | */ |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1113 | bool has_vk_layer_property(const VkLayerProperties *vk_layer_prop, const struct loader_layer_list *list) { |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1114 | for (uint32_t i = 0; i < list->count; i++) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1115 | if (strcmp(vk_layer_prop->layerName, list->list[i].info.layerName) == 0) return true; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1116 | } |
| 1117 | return false; |
| 1118 | } |
| 1119 | |
| 1120 | /* |
| 1121 | * Search the given layer list for a layer |
| 1122 | * matching the given name |
| 1123 | */ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1124 | 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] | 1125 | for (uint32_t i = 0; i < list->count; i++) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1126 | if (strcmp(name, list->list[i].info.layerName) == 0) return true; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1127 | } |
| 1128 | return false; |
| 1129 | } |
| 1130 | |
| 1131 | /* |
| 1132 | * Append non-duplicate layer properties defined in prop_list |
| 1133 | * to the given layer_info list |
| 1134 | */ |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1135 | VkResult loader_add_to_layer_list(const struct loader_instance *inst, struct loader_layer_list *list, uint32_t prop_list_count, |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1136 | const struct loader_layer_properties *props) { |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1137 | uint32_t i; |
| 1138 | struct loader_layer_properties *layer; |
| 1139 | |
| 1140 | if (list->list == NULL || list->capacity == 0) { |
Jon Ashburn | e39a4f8 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 1141 | loader_init_layer_list(inst, list); |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1142 | } |
| 1143 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1144 | if (list->list == NULL) return VK_SUCCESS; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1145 | |
| 1146 | for (i = 0; i < prop_list_count; i++) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1147 | layer = (struct loader_layer_properties *)&props[i]; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1148 | |
| 1149 | // look for duplicates |
| 1150 | if (has_vk_layer_property(&layer->info, list)) { |
| 1151 | continue; |
| 1152 | } |
| 1153 | |
| 1154 | // add to list at end |
| 1155 | // check for enough capacity |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1156 | if (list->count * sizeof(struct loader_layer_properties) >= list->capacity) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1157 | list->list = loader_instance_heap_realloc(inst, list->list, list->capacity, list->capacity * 2, |
| 1158 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1159 | if (NULL == list->list) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1160 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1161 | "loader_add_to_layer_list: Realloc failed for " |
| 1162 | "when attempting to add new layer"); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1163 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 1164 | } |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1165 | // double capacity |
| 1166 | list->capacity *= 2; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1167 | } |
| 1168 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1169 | memcpy(&list->list[list->count], layer, sizeof(struct loader_layer_properties)); |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1170 | list->count++; |
| 1171 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1172 | |
| 1173 | return VK_SUCCESS; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1174 | } |
| 1175 | |
Jon Ashburn | bd332cc | 2015-07-07 10:27:45 -0600 | [diff] [blame] | 1176 | /** |
| 1177 | * Search the search_list for any layer with a name |
| 1178 | * 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] | 1179 | * Add all matching layers to the found_list |
Jon Ashburn | bd332cc | 2015-07-07 10:27:45 -0600 | [diff] [blame] | 1180 | * Do not add if found loader_layer_properties is already |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1181 | * on the found_list. |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1182 | */ |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1183 | void loader_find_layer_name_add_list(const struct loader_instance *inst, const char *name, const enum layer_type type, |
| 1184 | const struct loader_layer_list *search_list, struct loader_layer_list *found_list) { |
Jon Ashburn | 56151d6 | 2015-10-05 09:03:21 -0600 | [diff] [blame] | 1185 | bool found = false; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1186 | for (uint32_t i = 0; i < search_list->count; i++) { |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1187 | struct loader_layer_properties *layer_prop = &search_list->list[i]; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1188 | if (0 == strcmp(layer_prop->info.layerName, name) && (layer_prop->type & type)) { |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1189 | /* Found a layer with the same name, add to found_list */ |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1190 | if (VK_SUCCESS == loader_add_to_layer_list(inst, found_list, 1, layer_prop)) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1191 | found = true; |
| 1192 | } |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1193 | } |
| 1194 | } |
Jon Ashburn | 56151d6 | 2015-10-05 09:03:21 -0600 | [diff] [blame] | 1195 | if (!found) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1196 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 1197 | "loader_find_layer_name_add_list: Failed to find layer name " |
| 1198 | "%s to activate", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1199 | name); |
Jon Ashburn | 56151d6 | 2015-10-05 09:03:21 -0600 | [diff] [blame] | 1200 | } |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1201 | } |
| 1202 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1203 | static VkExtensionProperties *get_extension_property(const char *name, const struct loader_extension_list *list) { |
Courtney Goeltzenleuchter | 746db73 | 2015-07-06 17:42:01 -0600 | [diff] [blame] | 1204 | for (uint32_t i = 0; i < list->count; i++) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1205 | if (strcmp(name, list->list[i].extensionName) == 0) return &list->list[i]; |
Jon Ashburn | fc2e38c | 2015-04-14 09:15:32 -0600 | [diff] [blame] | 1206 | } |
Courtney Goeltzenleuchter | 746db73 | 2015-07-06 17:42:01 -0600 | [diff] [blame] | 1207 | return NULL; |
Jon Ashburn | fc2e38c | 2015-04-14 09:15:32 -0600 | [diff] [blame] | 1208 | } |
| 1209 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1210 | static VkExtensionProperties *get_dev_extension_property(const char *name, const struct loader_device_extension_list *list) { |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1211 | for (uint32_t i = 0; i < list->count; i++) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1212 | if (strcmp(name, list->list[i].props.extensionName) == 0) return &list->list[i].props; |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1213 | } |
| 1214 | return NULL; |
| 1215 | } |
| 1216 | |
Courtney Goeltzenleuchter | b39ccd5 | 2016-01-15 14:15:00 -0700 | [diff] [blame] | 1217 | /* |
Courtney Goeltzenleuchter | f538ef7 | 2015-12-02 14:00:19 -0700 | [diff] [blame] | 1218 | * For Instance extensions implemented within the loader (i.e. DEBUG_REPORT |
Jon Ashburn | bd6c488 | 2015-07-02 12:59:25 -0600 | [diff] [blame] | 1219 | * the extension must provide two entry points for the loader to use: |
| 1220 | * - "trampoline" entry point - this is the address returned by GetProcAddr |
| 1221 | * and will always do what's necessary to support a global call. |
| 1222 | * - "terminator" function - this function will be put at the end of the |
Jon Ashburn | 232e3af | 2015-11-30 17:21:25 -0700 | [diff] [blame] | 1223 | * instance chain and will contain the necessary logic to call / process |
Jon Ashburn | bd6c488 | 2015-07-02 12:59:25 -0600 | [diff] [blame] | 1224 | * the extension for the appropriate ICDs that are available. |
| 1225 | * There is no generic mechanism for including these functions, the references |
| 1226 | * must be placed into the appropriate loader entry points. |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1227 | * GetInstanceProcAddr: call extension GetInstanceProcAddr to check for |
| 1228 | * GetProcAddr requests |
| 1229 | * loader_coalesce_extensions(void) - add extension records to the list of |
| 1230 | * global |
Jon Ashburn | bd6c488 | 2015-07-02 12:59:25 -0600 | [diff] [blame] | 1231 | * extension available to the app. |
| 1232 | * instance_disp - add function pointer for terminator function to this array. |
| 1233 | * The extension itself should be in a separate file that will be |
| 1234 | * linked directly with the loader. |
| 1235 | */ |
Jon Ashburn | 9a4c6aa | 2015-08-14 11:57:54 -0600 | [diff] [blame] | 1236 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1237 | VkResult loader_get_icd_loader_instance_extensions(const struct loader_instance *inst, struct loader_icd_tramp_list *icd_tramp_list, |
| 1238 | struct loader_extension_list *inst_exts) { |
Jon Ashburn | 5c6a46f | 2015-08-14 14:49:22 -0600 | [diff] [blame] | 1239 | struct loader_extension_list icd_exts; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1240 | VkResult res = VK_SUCCESS; |
Mark Young | 2b2ece7 | 2017-02-10 11:19:02 -0700 | [diff] [blame] | 1241 | char *env_value; |
| 1242 | bool filter_extensions = true; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1243 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1244 | loader_log(inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, "Build ICD instance extension list"); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1245 | |
Mark Young | 2b2ece7 | 2017-02-10 11:19:02 -0700 | [diff] [blame] | 1246 | // Check if a user wants to disable the instance extension filtering behavior |
| 1247 | env_value = loader_getenv("VK_LOADER_DISABLE_INST_EXT_FILTER", inst); |
| 1248 | if (NULL != env_value && atoi(env_value) != 0) { |
| 1249 | filter_extensions = false; |
| 1250 | } |
| 1251 | loader_free_getenv(env_value, inst); |
| 1252 | |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1253 | // traverse scanned icd list adding non-duplicate extensions to the list |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1254 | for (uint32_t i = 0; i < icd_tramp_list->count; i++) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1255 | res = loader_init_generic_list(inst, (struct loader_generic_list *)&icd_exts, sizeof(VkExtensionProperties)); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1256 | if (VK_SUCCESS != res) { |
| 1257 | goto out; |
| 1258 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1259 | res = loader_add_instance_extensions(inst, icd_tramp_list->scanned_list[i].EnumerateInstanceExtensionProperties, |
| 1260 | icd_tramp_list->scanned_list[i].lib_name, &icd_exts); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1261 | if (VK_SUCCESS == res) { |
Mark Young | 2b2ece7 | 2017-02-10 11:19:02 -0700 | [diff] [blame] | 1262 | if (filter_extensions) { |
| 1263 | // Remove any extensions not recognized by the loader |
| 1264 | for (int32_t j = 0; j < (int32_t)icd_exts.count; j++) { |
| 1265 | // See if the extension is in the list of supported extensions |
| 1266 | bool found = false; |
| 1267 | for (uint32_t k = 0; LOADER_INSTANCE_EXTENSIONS[k] != NULL; k++) { |
| 1268 | if (strcmp(icd_exts.list[j].extensionName, LOADER_INSTANCE_EXTENSIONS[k]) == 0) { |
| 1269 | found = true; |
| 1270 | break; |
| 1271 | } |
Lenny Komow | 4053b81 | 2016-12-29 16:27:28 -0700 | [diff] [blame] | 1272 | } |
Lenny Komow | 4053b81 | 2016-12-29 16:27:28 -0700 | [diff] [blame] | 1273 | |
Mark Young | 2b2ece7 | 2017-02-10 11:19:02 -0700 | [diff] [blame] | 1274 | // If it isn't in the list, remove it |
| 1275 | if (!found) { |
| 1276 | for (uint32_t k = j + 1; k < icd_exts.count; k++) { |
| 1277 | icd_exts.list[k - 1] = icd_exts.list[k]; |
| 1278 | } |
| 1279 | --icd_exts.count; |
| 1280 | --j; |
Lenny Komow | 4053b81 | 2016-12-29 16:27:28 -0700 | [diff] [blame] | 1281 | } |
Lenny Komow | 4053b81 | 2016-12-29 16:27:28 -0700 | [diff] [blame] | 1282 | } |
| 1283 | } |
| 1284 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1285 | res = loader_add_to_ext_list(inst, inst_exts, icd_exts.count, icd_exts.list); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1286 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1287 | loader_destroy_generic_list(inst, (struct loader_generic_list *)&icd_exts); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1288 | if (VK_SUCCESS != res) { |
| 1289 | goto out; |
| 1290 | } |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1291 | }; |
| 1292 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1293 | // Traverse loader's extensions, adding non-duplicate extensions to the list |
Jon Ashburn | e39a4f8 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 1294 | debug_report_add_instance_extensions(inst, inst_exts); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1295 | |
| 1296 | out: |
| 1297 | return res; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1298 | } |
| 1299 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1300 | struct loader_icd_term *loader_get_icd_and_device(const VkDevice device, struct loader_device **found_dev, uint32_t *icd_index) { |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1301 | *found_dev = NULL; |
Mark Young | 16573c7 | 2016-06-28 10:52:43 -0600 | [diff] [blame] | 1302 | uint32_t index = 0; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1303 | for (struct loader_instance *inst = loader.instances; inst; inst = inst->next) { |
| 1304 | for (struct loader_icd_term *icd_term = inst->icd_terms; icd_term; icd_term = icd_term->next) { |
| 1305 | for (struct loader_device *dev = icd_term->logical_device_list; dev; dev = dev->next) |
Mark Young | 65cb366 | 2016-11-07 13:27:02 -0700 | [diff] [blame] | 1306 | // Value comparison of device prevents object wrapping by layers |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1307 | if (loader_get_dispatch(dev->icd_device) == loader_get_dispatch(device) || |
| 1308 | loader_get_dispatch(dev->chain_device) == loader_get_dispatch(device)) { |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1309 | *found_dev = dev; |
Mark Young | 16573c7 | 2016-06-28 10:52:43 -0600 | [diff] [blame] | 1310 | if (NULL != icd_index) { |
| 1311 | *icd_index = index; |
| 1312 | } |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1313 | return icd_term; |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1314 | } |
Mark Young | 16573c7 | 2016-06-28 10:52:43 -0600 | [diff] [blame] | 1315 | index++; |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1316 | } |
| 1317 | } |
| 1318 | return NULL; |
| 1319 | } |
| 1320 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1321 | void loader_destroy_logical_device(const struct loader_instance *inst, struct loader_device *dev, |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1322 | const VkAllocationCallbacks *pAllocator) { |
| 1323 | if (pAllocator) { |
| 1324 | dev->alloc_callbacks = *pAllocator; |
| 1325 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1326 | if (NULL != dev->activated_layer_list.list) { |
| 1327 | loader_deactivate_layers(inst, dev, &dev->activated_layer_list); |
| 1328 | } |
| 1329 | loader_device_heap_free(dev, dev); |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1330 | } |
| 1331 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1332 | struct loader_device *loader_create_logical_device(const struct loader_instance *inst, const VkAllocationCallbacks *pAllocator) { |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1333 | struct loader_device *new_dev; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1334 | #if (DEBUG_DISABLE_APP_ALLOCATORS == 1) |
| 1335 | { |
| 1336 | #else |
| 1337 | if (pAllocator) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1338 | new_dev = (struct loader_device *)pAllocator->pfnAllocation(pAllocator->pUserData, sizeof(struct loader_device), |
| 1339 | sizeof(int *), VK_SYSTEM_ALLOCATION_SCOPE_DEVICE); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1340 | } else { |
| 1341 | #endif |
| 1342 | new_dev = (struct loader_device *)malloc(sizeof(struct loader_device)); |
| 1343 | } |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1344 | |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1345 | if (!new_dev) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1346 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1347 | "loader_create_logical_device: Failed to alloc struct " |
| 1348 | "loader_device"); |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1349 | return NULL; |
| 1350 | } |
| 1351 | |
| 1352 | memset(new_dev, 0, sizeof(struct loader_device)); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1353 | if (pAllocator) { |
| 1354 | new_dev->alloc_callbacks = *pAllocator; |
| 1355 | } |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1356 | |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1357 | return new_dev; |
| 1358 | } |
| 1359 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1360 | void loader_add_logical_device(const struct loader_instance *inst, struct loader_icd_term *icd_term, struct loader_device *dev) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1361 | dev->next = icd_term->logical_device_list; |
| 1362 | icd_term->logical_device_list = dev; |
Piers Daniell | 295fe40 | 2016-03-29 11:51:11 -0600 | [diff] [blame] | 1363 | } |
| 1364 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1365 | void loader_remove_logical_device(const struct loader_instance *inst, struct loader_icd_term *icd_term, |
| 1366 | struct loader_device *found_dev, const VkAllocationCallbacks *pAllocator) { |
Jon Ashburn | 781a7ae | 2015-11-19 15:43:26 -0700 | [diff] [blame] | 1367 | struct loader_device *dev, *prev_dev; |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1368 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1369 | if (!icd_term || !found_dev) return; |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1370 | |
| 1371 | prev_dev = NULL; |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1372 | dev = icd_term->logical_device_list; |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1373 | while (dev && dev != found_dev) { |
| 1374 | prev_dev = dev; |
| 1375 | dev = dev->next; |
| 1376 | } |
| 1377 | |
| 1378 | if (prev_dev) |
| 1379 | prev_dev->next = found_dev->next; |
| 1380 | else |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1381 | icd_term->logical_device_list = found_dev->next; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1382 | loader_destroy_logical_device(inst, found_dev, pAllocator); |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1383 | } |
| 1384 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1385 | static void loader_icd_destroy(struct loader_instance *ptr_inst, struct loader_icd_term *icd_term, |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1386 | const VkAllocationCallbacks *pAllocator) { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1387 | ptr_inst->total_icd_count--; |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1388 | for (struct loader_device *dev = icd_term->logical_device_list; dev;) { |
Courtney Goeltzenleuchter | 1f157ac | 2015-06-14 19:57:15 -0600 | [diff] [blame] | 1389 | struct loader_device *next_dev = dev->next; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1390 | loader_destroy_logical_device(ptr_inst, dev, pAllocator); |
Courtney Goeltzenleuchter | 1f157ac | 2015-06-14 19:57:15 -0600 | [diff] [blame] | 1391 | dev = next_dev; |
| 1392 | } |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1393 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1394 | loader_instance_heap_free(ptr_inst, icd_term); |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1395 | } |
| 1396 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1397 | static struct loader_icd_term *loader_icd_create(const struct loader_instance *inst) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1398 | struct loader_icd_term *icd_term; |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1399 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1400 | icd_term = loader_instance_heap_alloc(inst, sizeof(struct loader_icd_term), VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1401 | if (!icd_term) { |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1402 | return NULL; |
Mark Young | db13a2a | 2016-09-06 13:53:03 -0600 | [diff] [blame] | 1403 | } |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1404 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1405 | memset(icd_term, 0, sizeof(struct loader_icd_term)); |
Courtney Goeltzenleuchter | 55001bb | 2014-10-28 10:29:27 -0600 | [diff] [blame] | 1406 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1407 | return icd_term; |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1408 | } |
| 1409 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1410 | static struct loader_icd_term *loader_icd_add(struct loader_instance *ptr_inst, const struct loader_scanned_icd *scanned_icd) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1411 | struct loader_icd_term *icd_term; |
Chia-I Wu | 13a61a5 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 1412 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1413 | icd_term = loader_icd_create(ptr_inst); |
| 1414 | if (!icd_term) { |
Chia-I Wu | 13a61a5 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 1415 | return NULL; |
Mark Young | db13a2a | 2016-09-06 13:53:03 -0600 | [diff] [blame] | 1416 | } |
Chia-I Wu | 13a61a5 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 1417 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1418 | icd_term->scanned_icd = scanned_icd; |
| 1419 | icd_term->this_instance = ptr_inst; |
Jon Ashburn | 3d00233 | 2015-08-20 16:35:30 -0600 | [diff] [blame] | 1420 | |
Chia-I Wu | 13a61a5 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 1421 | /* prepend to the list */ |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1422 | icd_term->next = ptr_inst->icd_terms; |
| 1423 | ptr_inst->icd_terms = icd_term; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1424 | ptr_inst->total_icd_count++; |
Chia-I Wu | 13a61a5 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 1425 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1426 | return icd_term; |
Chia-I Wu | 13a61a5 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 1427 | } |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1428 | |
Jon Ashburn | 17b4c86 | 2016-04-25 11:09:37 -0600 | [diff] [blame] | 1429 | /** |
| 1430 | * Determine the ICD interface version to use. |
| 1431 | * @param icd |
| 1432 | * @param pVersion Output parameter indicating which version to use or 0 if |
| 1433 | * the negotiation API is not supported by the ICD |
| 1434 | * @return bool indicating true if the selected interface version is supported |
| 1435 | * by the loader, false indicates the version is not supported |
Jon Ashburn | 17b4c86 | 2016-04-25 11:09:37 -0600 | [diff] [blame] | 1436 | */ |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1437 | bool loader_get_icd_interface_version(PFN_vkNegotiateLoaderICDInterfaceVersion fp_negotiate_icd_version, uint32_t *pVersion) { |
Jon Ashburn | 17b4c86 | 2016-04-25 11:09:37 -0600 | [diff] [blame] | 1438 | if (fp_negotiate_icd_version == NULL) { |
| 1439 | // ICD does not support the negotiation API, it supports version 0 or 1 |
| 1440 | // calling code must determine if it is version 0 or 1 |
| 1441 | *pVersion = 0; |
| 1442 | } else { |
| 1443 | // ICD supports the negotiation API, so call it with the loader's |
| 1444 | // latest version supported |
| 1445 | *pVersion = CURRENT_LOADER_ICD_INTERFACE_VERSION; |
| 1446 | VkResult result = fp_negotiate_icd_version(pVersion); |
| 1447 | |
| 1448 | if (result == VK_ERROR_INCOMPATIBLE_DRIVER) { |
| 1449 | // ICD no longer supports the loader's latest interface version so |
| 1450 | // fail loading the ICD |
| 1451 | return false; |
| 1452 | } |
| 1453 | } |
| 1454 | |
| 1455 | #if MIN_SUPPORTED_LOADER_ICD_INTERFACE_VERSION > 0 |
| 1456 | if (*pVersion < MIN_SUPPORTED_LOADER_ICD_INTERFACE_VERSION) { |
| 1457 | // Loader no longer supports the ICD's latest interface version so fail |
| 1458 | // loading the ICD |
| 1459 | return false; |
| 1460 | } |
| 1461 | #endif |
| 1462 | return true; |
| 1463 | } |
Chia-I Wu | 13a61a5 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 1464 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1465 | void loader_scanned_icd_clear(const struct loader_instance *inst, struct loader_icd_tramp_list *icd_tramp_list) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1466 | if (icd_tramp_list->capacity == 0) return; |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1467 | for (uint32_t i = 0; i < icd_tramp_list->count; i++) { |
| 1468 | loader_platform_close_library(icd_tramp_list->scanned_list[i].handle); |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1469 | loader_instance_heap_free(inst, icd_tramp_list->scanned_list[i].lib_name); |
Jon Ashburn | 8810c5f | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 1470 | } |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1471 | loader_instance_heap_free(inst, icd_tramp_list->scanned_list); |
| 1472 | icd_tramp_list->capacity = 0; |
| 1473 | icd_tramp_list->count = 0; |
| 1474 | icd_tramp_list->scanned_list = NULL; |
Jon Ashburn | 8810c5f | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 1475 | } |
| 1476 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1477 | static VkResult loader_scanned_icd_init(const struct loader_instance *inst, struct loader_icd_tramp_list *icd_tramp_list) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1478 | VkResult err = VK_SUCCESS; |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1479 | loader_scanned_icd_clear(inst, icd_tramp_list); |
| 1480 | icd_tramp_list->capacity = 8 * sizeof(struct loader_scanned_icd); |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1481 | icd_tramp_list->scanned_list = loader_instance_heap_alloc(inst, icd_tramp_list->capacity, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1482 | if (NULL == icd_tramp_list->scanned_list) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1483 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1484 | "loader_scanned_icd_init: Realloc failed for layer list when " |
| 1485 | "attempting to add new layer"); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1486 | err = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 1487 | } |
| 1488 | return err; |
Jon Ashburn | 8810c5f | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 1489 | } |
| 1490 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1491 | static VkResult loader_scanned_icd_add(const struct loader_instance *inst, struct loader_icd_tramp_list *icd_tramp_list, |
| 1492 | const char *filename, uint32_t api_version) { |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1493 | loader_platform_dl_handle handle; |
Tony Barbour | 1d2cd3f | 2015-07-03 10:33:54 -0600 | [diff] [blame] | 1494 | PFN_vkCreateInstance fp_create_inst; |
Jon Ashburn | fd4d09d | 2016-01-07 09:44:27 -0700 | [diff] [blame] | 1495 | PFN_vkEnumerateInstanceExtensionProperties fp_get_inst_ext_props; |
Jon Ashburn | c624c88 | 2015-07-16 10:17:29 -0600 | [diff] [blame] | 1496 | PFN_vkGetInstanceProcAddr fp_get_proc_addr; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 1497 | PFN_GetPhysicalDeviceProcAddr fp_get_phys_dev_proc_addr = NULL; |
Jon Ashburn | 17b4c86 | 2016-04-25 11:09:37 -0600 | [diff] [blame] | 1498 | PFN_vkNegotiateLoaderICDInterfaceVersion fp_negotiate_icd_version; |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1499 | struct loader_scanned_icd *new_scanned_icd; |
Jon Ashburn | 17b4c86 | 2016-04-25 11:09:37 -0600 | [diff] [blame] | 1500 | uint32_t interface_vers; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1501 | VkResult res = VK_SUCCESS; |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 1502 | |
Jon Ashburn | 4dc1d8a | 2016-04-20 13:21:17 -0600 | [diff] [blame] | 1503 | /* TODO implement smarter opening/closing of libraries. For now this |
| 1504 | * function leaves libraries open and the scanned_icd_clear closes them */ |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1505 | handle = loader_platform_open_library(filename); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1506 | if (NULL == handle) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1507 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, loader_platform_open_library_error(filename)); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1508 | goto out; |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 1509 | } |
| 1510 | |
Jon Ashburn | 17b4c86 | 2016-04-25 11:09:37 -0600 | [diff] [blame] | 1511 | // Get and settle on an ICD interface version |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1512 | fp_negotiate_icd_version = loader_platform_get_proc_address(handle, "vk_icdNegotiateLoaderICDInterfaceVersion"); |
Jon Ashburn | 17b4c86 | 2016-04-25 11:09:37 -0600 | [diff] [blame] | 1513 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1514 | if (!loader_get_icd_interface_version(fp_negotiate_icd_version, &interface_vers)) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1515 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1516 | "loader_scanned_icd_add: ICD %s doesn't support interface" |
| 1517 | " version compatible with loader, skip this ICD.", |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1518 | filename); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1519 | goto out; |
Jon Ashburn | 17b4c86 | 2016-04-25 11:09:37 -0600 | [diff] [blame] | 1520 | } |
| 1521 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1522 | fp_get_proc_addr = loader_platform_get_proc_address(handle, "vk_icdGetInstanceProcAddr"); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1523 | if (NULL == fp_get_proc_addr) { |
Jon Ashburn | 17b4c86 | 2016-04-25 11:09:37 -0600 | [diff] [blame] | 1524 | assert(interface_vers == 0); |
| 1525 | // Use deprecated interface from version 0 |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1526 | fp_get_proc_addr = loader_platform_get_proc_address(handle, "vkGetInstanceProcAddr"); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1527 | if (NULL == fp_get_proc_addr) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1528 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1529 | "loader_scanned_icd_add: Attempt to retreive either " |
| 1530 | "\'vkGetInstanceProcAddr\' or " |
| 1531 | "\'vk_icdGetInstanceProcAddr\' from ICD %s failed.", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1532 | filename); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1533 | goto out; |
Jon Ashburn | fd4d09d | 2016-01-07 09:44:27 -0700 | [diff] [blame] | 1534 | } else { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1535 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 1536 | "loader_scanned_icd_add: Using deprecated ICD " |
| 1537 | "interface of \'vkGetInstanceProcAddr\' instead of " |
| 1538 | "\'vk_icdGetInstanceProcAddr\' for ICD %s", |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1539 | filename); |
Jon Ashburn | fd4d09d | 2016-01-07 09:44:27 -0700 | [diff] [blame] | 1540 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1541 | fp_create_inst = loader_platform_get_proc_address(handle, "vkCreateInstance"); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1542 | if (NULL == fp_create_inst) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1543 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1544 | "loader_scanned_icd_add: Failed querying " |
| 1545 | "\'vkCreateInstance\' via dlsym/loadlibrary for " |
| 1546 | "ICD %s", |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1547 | filename); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1548 | goto out; |
Jon Ashburn | 69a5f7a | 2016-01-11 14:41:35 -0700 | [diff] [blame] | 1549 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1550 | fp_get_inst_ext_props = loader_platform_get_proc_address(handle, "vkEnumerateInstanceExtensionProperties"); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1551 | if (NULL == fp_get_inst_ext_props) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1552 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1553 | "loader_scanned_icd_add: Could not get \'vkEnumerate" |
| 1554 | "InstanceExtensionProperties\' via dlsym/loadlibrary " |
| 1555 | "for ICD %s", |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1556 | filename); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1557 | goto out; |
Jon Ashburn | 69a5f7a | 2016-01-11 14:41:35 -0700 | [diff] [blame] | 1558 | } |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1559 | } else { |
Jon Ashburn | 17b4c86 | 2016-04-25 11:09:37 -0600 | [diff] [blame] | 1560 | // Use newer interface version 1 or later |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 1561 | if (interface_vers == 0) { |
Jon Ashburn | 17b4c86 | 2016-04-25 11:09:37 -0600 | [diff] [blame] | 1562 | interface_vers = 1; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 1563 | } |
Jon Ashburn | 17b4c86 | 2016-04-25 11:09:37 -0600 | [diff] [blame] | 1564 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1565 | fp_create_inst = (PFN_vkCreateInstance)fp_get_proc_addr(NULL, "vkCreateInstance"); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1566 | if (NULL == fp_create_inst) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1567 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1568 | "loader_scanned_icd_add: Could not get " |
| 1569 | "\'vkCreateInstance\' via \'vk_icdGetInstanceProcAddr\'" |
| 1570 | " for ICD %s", |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1571 | filename); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1572 | goto out; |
Jon Ashburn | 69a5f7a | 2016-01-11 14:41:35 -0700 | [diff] [blame] | 1573 | } |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1574 | fp_get_inst_ext_props = |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1575 | (PFN_vkEnumerateInstanceExtensionProperties)fp_get_proc_addr(NULL, "vkEnumerateInstanceExtensionProperties"); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1576 | if (NULL == fp_get_inst_ext_props) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1577 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1578 | "loader_scanned_icd_add: Could not get \'vkEnumerate" |
| 1579 | "InstanceExtensionProperties\' via " |
| 1580 | "\'vk_icdGetInstanceProcAddr\' for ICD %s", |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1581 | filename); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1582 | goto out; |
Jon Ashburn | 69a5f7a | 2016-01-11 14:41:35 -0700 | [diff] [blame] | 1583 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1584 | fp_get_phys_dev_proc_addr = loader_platform_get_proc_address(handle, "vk_icdGetPhysicalDeviceProcAddr"); |
Jon Ashburn | fd4d09d | 2016-01-07 09:44:27 -0700 | [diff] [blame] | 1585 | } |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 1586 | |
Jon Ashburn | 8810c5f | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 1587 | // check for enough capacity |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1588 | if ((icd_tramp_list->count * sizeof(struct loader_scanned_icd)) >= icd_tramp_list->capacity) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1589 | icd_tramp_list->scanned_list = |
| 1590 | loader_instance_heap_realloc(inst, icd_tramp_list->scanned_list, icd_tramp_list->capacity, icd_tramp_list->capacity * 2, |
| 1591 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1592 | if (NULL == icd_tramp_list->scanned_list) { |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1593 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1594 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1595 | "loader_scanned_icd_add: Realloc failed on icd library" |
| 1596 | " list for ICD %s", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1597 | filename); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1598 | goto out; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1599 | } |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1600 | // double capacity |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1601 | icd_tramp_list->capacity *= 2; |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 1602 | } |
| 1603 | |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 1604 | new_scanned_icd = &(icd_tramp_list->scanned_list[icd_tramp_list->count]); |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1605 | new_scanned_icd->handle = handle; |
| 1606 | new_scanned_icd->api_version = api_version; |
| 1607 | new_scanned_icd->GetInstanceProcAddr = fp_get_proc_addr; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 1608 | new_scanned_icd->GetPhysicalDeviceProcAddr = fp_get_phys_dev_proc_addr; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1609 | new_scanned_icd->EnumerateInstanceExtensionProperties = fp_get_inst_ext_props; |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1610 | new_scanned_icd->CreateInstance = fp_create_inst; |
| 1611 | new_scanned_icd->interface_version = interface_vers; |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 1612 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1613 | new_scanned_icd->lib_name = (char *)loader_instance_heap_alloc(inst, strlen(filename) + 1, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1614 | if (NULL == new_scanned_icd->lib_name) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1615 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, "loader_scanned_icd_add: Out of memory can't add ICD %s", filename); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1616 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1617 | goto out; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1618 | } |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1619 | strcpy(new_scanned_icd->lib_name, filename); |
| 1620 | icd_tramp_list->count++; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1621 | |
| 1622 | out: |
| 1623 | |
| 1624 | return res; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1625 | } |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1626 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1627 | static bool loader_icd_init_entrys(struct loader_icd_term *icd_term, VkInstance inst, const PFN_vkGetInstanceProcAddr fp_gipa) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1628 | /* initialize entrypoint function pointers */ |
Jon Ashburn | 3da71f2 | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 1629 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1630 | #define LOOKUP_GIPA(func, required) \ |
| 1631 | do { \ |
| 1632 | icd_term->func = (PFN_vk##func)fp_gipa(inst, "vk" #func); \ |
| 1633 | if (!icd_term->func && required) { \ |
| 1634 | loader_log((struct loader_instance *)inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, \ |
| 1635 | loader_platform_get_proc_address_error("vk" #func)); \ |
| 1636 | return false; \ |
| 1637 | } \ |
Jon Ashburn | 3da71f2 | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 1638 | } while (0) |
| 1639 | |
Jon Ashburn | c624c88 | 2015-07-16 10:17:29 -0600 | [diff] [blame] | 1640 | LOOKUP_GIPA(GetDeviceProcAddr, true); |
| 1641 | LOOKUP_GIPA(DestroyInstance, true); |
| 1642 | LOOKUP_GIPA(EnumeratePhysicalDevices, true); |
| 1643 | LOOKUP_GIPA(GetPhysicalDeviceFeatures, true); |
| 1644 | LOOKUP_GIPA(GetPhysicalDeviceFormatProperties, true); |
Jon Ashburn | 754864f | 2015-07-23 18:49:07 -0600 | [diff] [blame] | 1645 | LOOKUP_GIPA(GetPhysicalDeviceImageFormatProperties, true); |
Jon Ashburn | c624c88 | 2015-07-16 10:17:29 -0600 | [diff] [blame] | 1646 | LOOKUP_GIPA(CreateDevice, true); |
| 1647 | LOOKUP_GIPA(GetPhysicalDeviceProperties, true); |
| 1648 | LOOKUP_GIPA(GetPhysicalDeviceMemoryProperties, true); |
Cody Northrop | d080288 | 2015-08-03 17:04:53 -0600 | [diff] [blame] | 1649 | LOOKUP_GIPA(GetPhysicalDeviceQueueFamilyProperties, true); |
Courtney Goeltzenleuchter | 35985f6 | 2015-09-14 17:22:16 -0600 | [diff] [blame] | 1650 | LOOKUP_GIPA(EnumerateDeviceExtensionProperties, true); |
Jon Ashburn | c624c88 | 2015-07-16 10:17:29 -0600 | [diff] [blame] | 1651 | LOOKUP_GIPA(GetPhysicalDeviceSparseImageFormatProperties, true); |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 1652 | LOOKUP_GIPA(GetPhysicalDeviceSurfaceSupportKHR, false); |
Ian Elliott | 486c550 | 2015-11-19 16:05:09 -0700 | [diff] [blame] | 1653 | LOOKUP_GIPA(GetPhysicalDeviceSurfaceCapabilitiesKHR, false); |
| 1654 | LOOKUP_GIPA(GetPhysicalDeviceSurfaceFormatsKHR, false); |
| 1655 | LOOKUP_GIPA(GetPhysicalDeviceSurfacePresentModesKHR, false); |
Petros Bantolas | 25d27fe | 2016-04-14 12:50:42 +0100 | [diff] [blame] | 1656 | LOOKUP_GIPA(GetPhysicalDeviceDisplayPropertiesKHR, false); |
| 1657 | LOOKUP_GIPA(GetDisplayModePropertiesKHR, false); |
| 1658 | LOOKUP_GIPA(CreateDisplayPlaneSurfaceKHR, false); |
| 1659 | LOOKUP_GIPA(GetPhysicalDeviceDisplayPlanePropertiesKHR, false); |
| 1660 | LOOKUP_GIPA(GetDisplayPlaneSupportedDisplaysKHR, false); |
| 1661 | LOOKUP_GIPA(CreateDisplayModeKHR, false); |
| 1662 | LOOKUP_GIPA(GetDisplayPlaneCapabilitiesKHR, false); |
| 1663 | LOOKUP_GIPA(DestroySurfaceKHR, false); |
Mark Young | 16573c7 | 2016-06-28 10:52:43 -0600 | [diff] [blame] | 1664 | LOOKUP_GIPA(CreateSwapchainKHR, false); |
Ian Elliott | 919fa30 | 2015-11-24 15:39:10 -0700 | [diff] [blame] | 1665 | #ifdef VK_USE_PLATFORM_WIN32_KHR |
Mark Young | 16573c7 | 2016-06-28 10:52:43 -0600 | [diff] [blame] | 1666 | LOOKUP_GIPA(CreateWin32SurfaceKHR, false); |
Ian Elliott | 919fa30 | 2015-11-24 15:39:10 -0700 | [diff] [blame] | 1667 | LOOKUP_GIPA(GetPhysicalDeviceWin32PresentationSupportKHR, false); |
| 1668 | #endif |
| 1669 | #ifdef VK_USE_PLATFORM_XCB_KHR |
Mark Young | 16573c7 | 2016-06-28 10:52:43 -0600 | [diff] [blame] | 1670 | LOOKUP_GIPA(CreateXcbSurfaceKHR, false); |
Ian Elliott | 919fa30 | 2015-11-24 15:39:10 -0700 | [diff] [blame] | 1671 | LOOKUP_GIPA(GetPhysicalDeviceXcbPresentationSupportKHR, false); |
| 1672 | #endif |
Karl Schultz | 65d2018 | 2016-03-08 07:55:27 -0700 | [diff] [blame] | 1673 | #ifdef VK_USE_PLATFORM_XLIB_KHR |
Mark Young | 16573c7 | 2016-06-28 10:52:43 -0600 | [diff] [blame] | 1674 | LOOKUP_GIPA(CreateXlibSurfaceKHR, false); |
Karl Schultz | 65d2018 | 2016-03-08 07:55:27 -0700 | [diff] [blame] | 1675 | LOOKUP_GIPA(GetPhysicalDeviceXlibPresentationSupportKHR, false); |
| 1676 | #endif |
Mark Young | a7c51fd | 2016-09-16 10:18:42 -0600 | [diff] [blame] | 1677 | #ifdef VK_USE_PLATFORM_MIR_KHR |
| 1678 | LOOKUP_GIPA(CreateMirSurfaceKHR, false); |
| 1679 | LOOKUP_GIPA(GetPhysicalDeviceMirPresentationSupportKHR, false); |
| 1680 | #endif |
Jason Ekstrand | a5ebe8a | 2016-02-12 17:25:03 -0800 | [diff] [blame] | 1681 | #ifdef VK_USE_PLATFORM_WAYLAND_KHR |
Mark Young | 16573c7 | 2016-06-28 10:52:43 -0600 | [diff] [blame] | 1682 | LOOKUP_GIPA(CreateWaylandSurfaceKHR, false); |
Jason Ekstrand | a5ebe8a | 2016-02-12 17:25:03 -0800 | [diff] [blame] | 1683 | LOOKUP_GIPA(GetPhysicalDeviceWaylandPresentationSupportKHR, false); |
| 1684 | #endif |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 1685 | LOOKUP_GIPA(CreateSharedSwapchainsKHR, false); |
| 1686 | |
| 1687 | // KHR_get_physical_device_properties2 |
| 1688 | LOOKUP_GIPA(GetPhysicalDeviceFeatures2KHR, false); |
| 1689 | LOOKUP_GIPA(GetPhysicalDeviceProperties2KHR, false); |
| 1690 | LOOKUP_GIPA(GetPhysicalDeviceFormatProperties2KHR, false); |
| 1691 | LOOKUP_GIPA(GetPhysicalDeviceImageFormatProperties2KHR, false); |
| 1692 | LOOKUP_GIPA(GetPhysicalDeviceQueueFamilyProperties2KHR, false); |
| 1693 | LOOKUP_GIPA(GetPhysicalDeviceMemoryProperties2KHR, false); |
| 1694 | LOOKUP_GIPA(GetPhysicalDeviceSparseImageFormatProperties2KHR, false); |
| 1695 | // EXT_debug_marker (items needing a trampoline/terminator) |
| 1696 | LOOKUP_GIPA(DebugMarkerSetObjectTagEXT, false); |
| 1697 | LOOKUP_GIPA(DebugMarkerSetObjectNameEXT, false); |
| 1698 | |
| 1699 | #ifdef VK_USE_PLATFORM_XLIB_XRANDR_EXT |
| 1700 | // EXT_acquire_xlib_display |
| 1701 | LOOKUP_GIPA(AcquireXlibDisplayEXT, false); |
| 1702 | LOOKUP_GIPA(GetRandROutputDisplayEXT, false); |
| 1703 | #endif |
| 1704 | |
| 1705 | // EXT_debug_report |
| 1706 | LOOKUP_GIPA(CreateDebugReportCallbackEXT, false); |
| 1707 | LOOKUP_GIPA(DestroyDebugReportCallbackEXT, false); |
| 1708 | LOOKUP_GIPA(DebugReportMessageEXT, false); |
| 1709 | |
| 1710 | // EXT_direct_mode_display |
| 1711 | LOOKUP_GIPA(ReleaseDisplayEXT, false); |
| 1712 | |
| 1713 | // EXT_display_surface_counter |
| 1714 | LOOKUP_GIPA(GetPhysicalDeviceSurfaceCapabilities2EXT, false); |
| 1715 | |
Mark Young | fa55278 | 2016-12-12 16:14:55 -0700 | [diff] [blame] | 1716 | // NV_external_memory_capabilities |
James Jones | 389dc0c | 2016-08-18 23:41:19 +0100 | [diff] [blame] | 1717 | LOOKUP_GIPA(GetPhysicalDeviceExternalImageFormatPropertiesNV, false); |
Mark Young | fa55278 | 2016-12-12 16:14:55 -0700 | [diff] [blame] | 1718 | // NVX_device_generated_commands |
| 1719 | LOOKUP_GIPA(GetPhysicalDeviceGeneratedCommandsPropertiesNVX, false); |
Jon Ashburn | 3da71f2 | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 1720 | |
Jon Ashburn | c624c88 | 2015-07-16 10:17:29 -0600 | [diff] [blame] | 1721 | #undef LOOKUP_GIPA |
Ian Elliott | d3ef02f | 2015-07-06 14:36:13 -0600 | [diff] [blame] | 1722 | |
Jon Ashburn | c624c88 | 2015-07-16 10:17:29 -0600 | [diff] [blame] | 1723 | return true; |
Jon Ashburn | 3da71f2 | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 1724 | } |
| 1725 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1726 | static void loader_debug_init(void) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1727 | char *env, *orig; |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 1728 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1729 | if (g_loader_debug > 0) return; |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 1730 | |
| 1731 | g_loader_debug = 0; |
| 1732 | |
| 1733 | /* parse comma-separated debug options */ |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1734 | orig = env = loader_getenv("VK_LOADER_DEBUG", NULL); |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 1735 | while (env) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1736 | char *p = strchr(env, ','); |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 1737 | size_t len; |
| 1738 | |
| 1739 | if (p) |
| 1740 | len = p - env; |
| 1741 | else |
| 1742 | len = strlen(env); |
| 1743 | |
| 1744 | if (len > 0) { |
Michael Worcester | 25c73e7 | 2015-12-10 18:06:24 +0000 | [diff] [blame] | 1745 | if (strncmp(env, "all", len) == 0) { |
| 1746 | g_loader_debug = ~0u; |
| 1747 | g_loader_log_msgs = ~0u; |
| 1748 | } else if (strncmp(env, "warn", len) == 0) { |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 1749 | g_loader_debug |= LOADER_WARN_BIT; |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 1750 | g_loader_log_msgs |= VK_DEBUG_REPORT_WARNING_BIT_EXT; |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 1751 | } else if (strncmp(env, "info", len) == 0) { |
| 1752 | g_loader_debug |= LOADER_INFO_BIT; |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 1753 | g_loader_log_msgs |= VK_DEBUG_REPORT_INFORMATION_BIT_EXT; |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 1754 | } else if (strncmp(env, "perf", len) == 0) { |
| 1755 | g_loader_debug |= LOADER_PERF_BIT; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1756 | g_loader_log_msgs |= VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT; |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 1757 | } else if (strncmp(env, "error", len) == 0) { |
| 1758 | g_loader_debug |= LOADER_ERROR_BIT; |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1759 | g_loader_log_msgs |= VK_DEBUG_REPORT_ERROR_BIT_EXT; |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 1760 | } else if (strncmp(env, "debug", len) == 0) { |
| 1761 | g_loader_debug |= LOADER_DEBUG_BIT; |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1762 | g_loader_log_msgs |= VK_DEBUG_REPORT_DEBUG_BIT_EXT; |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 1763 | } |
| 1764 | } |
| 1765 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1766 | if (!p) break; |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 1767 | |
| 1768 | env = p + 1; |
| 1769 | } |
Jon Ashburn | 38a497f | 2016-01-04 14:01:38 -0700 | [diff] [blame] | 1770 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1771 | loader_free_getenv(orig, NULL); |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 1772 | } |
| 1773 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1774 | void loader_initialize(void) { |
Jon Ashburn | 6461ef2 | 2015-09-22 13:11:00 -0600 | [diff] [blame] | 1775 | // initialize mutexs |
Jon Ashburn | 8810c5f | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 1776 | loader_platform_thread_create_mutex(&loader_lock); |
Jon Ashburn | 6461ef2 | 2015-09-22 13:11:00 -0600 | [diff] [blame] | 1777 | loader_platform_thread_create_mutex(&loader_json_lock); |
Jon Ashburn | 8810c5f | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 1778 | |
| 1779 | // initialize logging |
| 1780 | loader_debug_init(); |
Jon Ashburn | 87d6aa9 | 2015-08-28 15:19:27 -0600 | [diff] [blame] | 1781 | |
| 1782 | // initial cJSON to use alloc callbacks |
| 1783 | cJSON_Hooks alloc_fns = { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1784 | .malloc_fn = loader_instance_tls_heap_alloc, .free_fn = loader_instance_tls_heap_free, |
Jon Ashburn | 87d6aa9 | 2015-08-28 15:19:27 -0600 | [diff] [blame] | 1785 | }; |
| 1786 | cJSON_InitHooks(&alloc_fns); |
Jon Ashburn | 8810c5f | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 1787 | } |
| 1788 | |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1789 | struct loader_manifest_files { |
| 1790 | uint32_t count; |
| 1791 | char **filename_list; |
| 1792 | }; |
| 1793 | |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 1794 | /** |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1795 | * 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] | 1796 | * |
| 1797 | * \returns |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1798 | * A pointer to first char in the next path. |
| 1799 | * The next path (or NULL) in the list is returned in next_path. |
| 1800 | * Note: input string is modified in some cases. PASS IN A COPY! |
| 1801 | */ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1802 | static char *loader_get_next_path(char *path) { |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1803 | uint32_t len; |
| 1804 | char *next; |
| 1805 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1806 | if (path == NULL) return NULL; |
Frank Henigman | 5717310 | 2016-11-24 22:15:20 -0500 | [diff] [blame] | 1807 | next = strchr(path, PATH_SEPARATOR); |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1808 | if (next == NULL) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1809 | len = (uint32_t)strlen(path); |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1810 | next = path + len; |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1811 | } else { |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1812 | *next = '\0'; |
| 1813 | next++; |
| 1814 | } |
| 1815 | |
| 1816 | return next; |
| 1817 | } |
| 1818 | |
| 1819 | /** |
Daniel Dadap | 00b4aba | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 1820 | * Given a path which is absolute or relative, expand the path if relative or |
| 1821 | * leave the path unmodified if absolute. The base path to prepend to relative |
| 1822 | * paths is given in rel_base. |
Jon Ashburn | 1531517 | 2015-07-07 15:06:25 -0600 | [diff] [blame] | 1823 | * |
| 1824 | * \returns |
| 1825 | * A string in out_fullpath of the full absolute path |
Jon Ashburn | 1531517 | 2015-07-07 15:06:25 -0600 | [diff] [blame] | 1826 | */ |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1827 | static void loader_expand_path(const char *path, const char *rel_base, size_t out_size, char *out_fullpath) { |
Jon Ashburn | 1531517 | 2015-07-07 15:06:25 -0600 | [diff] [blame] | 1828 | if (loader_platform_is_path_absolute(path)) { |
Daniel Dadap | 00b4aba | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 1829 | // do not prepend a base to an absolute path |
| 1830 | rel_base = ""; |
Jon Ashburn | 1531517 | 2015-07-07 15:06:25 -0600 | [diff] [blame] | 1831 | } |
Daniel Dadap | 00b4aba | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 1832 | |
| 1833 | loader_platform_combine_path(out_fullpath, out_size, rel_base, path, NULL); |
Jon Ashburn | 1531517 | 2015-07-07 15:06:25 -0600 | [diff] [blame] | 1834 | } |
| 1835 | |
| 1836 | /** |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1837 | * Given a filename (file) and a list of paths (dir), try to find an existing |
| 1838 | * file in the paths. If filename already is a path then no |
| 1839 | * searching in the given paths. |
| 1840 | * |
| 1841 | * \returns |
| 1842 | * A string in out_fullpath of either the full path or file. |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1843 | */ |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1844 | static void loader_get_fullpath(const char *file, const char *dirs, size_t out_size, char *out_fullpath) { |
Daniel Dadap | 00b4aba | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 1845 | if (!loader_platform_is_path(file) && *dirs) { |
| 1846 | char *dirs_copy, *dir, *next_dir; |
| 1847 | |
| 1848 | dirs_copy = loader_stack_alloc(strlen(dirs) + 1); |
| 1849 | strcpy(dirs_copy, dirs); |
| 1850 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1851 | // find if file exists after prepending paths in given list |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1852 | for (dir = dirs_copy; *dir && (next_dir = loader_get_next_path(dir)); dir = next_dir) { |
| 1853 | loader_platform_combine_path(out_fullpath, out_size, dir, file, NULL); |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1854 | if (loader_platform_file_exists(out_fullpath)) { |
| 1855 | return; |
| 1856 | } |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1857 | } |
| 1858 | } |
Daniel Dadap | 00b4aba | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 1859 | |
Karl Schultz | e2ef9e6 | 2017-01-13 14:01:35 -0700 | [diff] [blame] | 1860 | (void)snprintf(out_fullpath, out_size, "%s", file); |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1861 | } |
| 1862 | |
| 1863 | /** |
| 1864 | * Read a JSON file into a buffer. |
| 1865 | * |
| 1866 | * \returns |
| 1867 | * A pointer to a cJSON object representing the JSON parse tree. |
| 1868 | * This returned buffer should be freed by caller. |
| 1869 | */ |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1870 | static VkResult loader_get_json(const struct loader_instance *inst, const char *filename, cJSON **json) { |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1871 | FILE *file = NULL; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1872 | char *json_buf; |
Mark Young | 93ecb1d | 2016-01-13 13:47:16 -0700 | [diff] [blame] | 1873 | size_t len; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1874 | VkResult res = VK_SUCCESS; |
| 1875 | |
| 1876 | if (NULL == json) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1877 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, "loader_get_json: Received invalid JSON file"); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1878 | res = VK_ERROR_INITIALIZATION_FAILED; |
| 1879 | goto out; |
| 1880 | } |
| 1881 | |
| 1882 | *json = NULL; |
| 1883 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1884 | file = fopen(filename, "rb"); |
Jon Ashburn | aa4ea47 | 2015-08-27 08:30:50 -0600 | [diff] [blame] | 1885 | if (!file) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1886 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, "loader_get_json: Failed to open JSON file %s", filename); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1887 | res = VK_ERROR_INITIALIZATION_FAILED; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1888 | goto out; |
Jon Ashburn | aa4ea47 | 2015-08-27 08:30:50 -0600 | [diff] [blame] | 1889 | } |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1890 | fseek(file, 0, SEEK_END); |
| 1891 | len = ftell(file); |
| 1892 | fseek(file, 0, SEEK_SET); |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1893 | json_buf = (char *)loader_stack_alloc(len + 1); |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1894 | if (json_buf == NULL) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1895 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1896 | "loader_get_json: Failed to allocate space for " |
| 1897 | "JSON file %s buffer of length %d", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1898 | filename, len); |
| 1899 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1900 | goto out; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1901 | } |
| 1902 | if (fread(json_buf, sizeof(char), len, file) != len) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1903 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, "loader_get_json: Failed to read JSON file %s.", filename); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1904 | res = VK_ERROR_INITIALIZATION_FAILED; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1905 | goto out; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1906 | } |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1907 | json_buf[len] = '\0'; |
| 1908 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1909 | // parse text from file |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1910 | *json = cJSON_Parse(json_buf); |
| 1911 | if (*json == NULL) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1912 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1913 | "loader_get_json: Failed to parse JSON file %s, " |
| 1914 | "this is usually because something ran out of " |
| 1915 | "memory.", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1916 | filename); |
| 1917 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1918 | goto out; |
| 1919 | } |
| 1920 | |
| 1921 | out: |
| 1922 | if (NULL != file) { |
| 1923 | fclose(file); |
| 1924 | } |
| 1925 | |
| 1926 | return res; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 1927 | } |
| 1928 | |
| 1929 | /** |
Jon Ashburn | 3d00233 | 2015-08-20 16:35:30 -0600 | [diff] [blame] | 1930 | * Do a deep copy of the loader_layer_properties structure. |
| 1931 | */ |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1932 | VkResult loader_copy_layer_properties(const struct loader_instance *inst, struct loader_layer_properties *dst, |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1933 | struct loader_layer_properties *src) { |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1934 | uint32_t cnt, i; |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1935 | memcpy(dst, src, sizeof(*src)); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1936 | dst->instance_extension_list.list = loader_instance_heap_alloc( |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1937 | inst, sizeof(VkExtensionProperties) * src->instance_extension_list.count, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1938 | if (NULL == dst->instance_extension_list.list) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1939 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1940 | "loader_copy_layer_properties: Failed to allocate space " |
| 1941 | "for instance extension list of size %d.", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1942 | src->instance_extension_list.count); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1943 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 1944 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1945 | dst->instance_extension_list.capacity = sizeof(VkExtensionProperties) * src->instance_extension_list.count; |
| 1946 | memcpy(dst->instance_extension_list.list, src->instance_extension_list.list, dst->instance_extension_list.capacity); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1947 | dst->device_extension_list.list = loader_instance_heap_alloc( |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1948 | inst, sizeof(struct loader_dev_ext_props) * src->device_extension_list.count, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1949 | if (NULL == dst->device_extension_list.list) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1950 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1951 | "loader_copy_layer_properties: Failed to allocate space " |
| 1952 | "for device extension list of size %d.", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1953 | src->device_extension_list.count); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1954 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 1955 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1956 | memset(dst->device_extension_list.list, 0, sizeof(struct loader_dev_ext_props) * src->device_extension_list.count); |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1957 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1958 | dst->device_extension_list.capacity = sizeof(struct loader_dev_ext_props) * src->device_extension_list.count; |
| 1959 | memcpy(dst->device_extension_list.list, src->device_extension_list.list, dst->device_extension_list.capacity); |
| 1960 | if (src->device_extension_list.count > 0 && src->device_extension_list.list->entrypoint_count > 0) { |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1961 | cnt = src->device_extension_list.list->entrypoint_count; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1962 | dst->device_extension_list.list->entrypoints = |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1963 | loader_instance_heap_alloc(inst, sizeof(char *) * cnt, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1964 | if (NULL == dst->device_extension_list.list->entrypoints) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1965 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1966 | "loader_copy_layer_properties: Failed to allocate space " |
| 1967 | "for device extension entrypoint list of size %d.", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1968 | cnt); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1969 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 1970 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1971 | memset(dst->device_extension_list.list->entrypoints, 0, sizeof(char *) * cnt); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1972 | |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1973 | for (i = 0; i < cnt; i++) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1974 | dst->device_extension_list.list->entrypoints[i] = loader_instance_heap_alloc( |
| 1975 | inst, strlen(src->device_extension_list.list->entrypoints[i]) + 1, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1976 | if (NULL == dst->device_extension_list.list->entrypoints[i]) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1977 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1978 | "loader_copy_layer_properties: Failed to " |
| 1979 | "allocate space for device extension entrypoint " |
| 1980 | "%d name of length", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1981 | i); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1982 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 1983 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1984 | strcpy(dst->device_extension_list.list->entrypoints[i], src->device_extension_list.list->entrypoints[i]); |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1985 | } |
| 1986 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1987 | |
| 1988 | return VK_SUCCESS; |
Jon Ashburn | 3d00233 | 2015-08-20 16:35:30 -0600 | [diff] [blame] | 1989 | } |
| 1990 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1991 | static bool loader_find_layer_name_list(const char *name, const struct loader_layer_list *layer_list) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1992 | if (!layer_list) return false; |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 1993 | for (uint32_t j = 0; j < layer_list->count; j++) |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1994 | if (!strcmp(name, layer_list->list[j].info.layerName)) return true; |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 1995 | return false; |
| 1996 | } |
| 1997 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1998 | static bool loader_find_layer_name(const char *name, uint32_t layer_count, const char **layer_list) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1999 | if (!layer_list) return false; |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 2000 | for (uint32_t j = 0; j < layer_count; j++) |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2001 | if (!strcmp(name, layer_list[j])) return true; |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 2002 | return false; |
| 2003 | } |
| 2004 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2005 | bool loader_find_layer_name_array(const char *name, uint32_t layer_count, const char layer_list[][VK_MAX_EXTENSION_NAME_SIZE]) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2006 | if (!layer_list) return false; |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 2007 | for (uint32_t j = 0; j < layer_count; j++) |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2008 | if (!strcmp(name, layer_list[j])) return true; |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 2009 | return false; |
| 2010 | } |
| 2011 | |
| 2012 | /** |
| 2013 | * Searches through an array of layer names (ppp_layer_names) looking for a |
| 2014 | * layer key_name. |
| 2015 | * If not found then simply returns updating nothing. |
| 2016 | * Otherwise, it uses expand_count, expand_names adding them to layer names. |
Chris Forbes | 6936647 | 2016-04-07 09:04:49 +1200 | [diff] [blame] | 2017 | * Any duplicate (pre-existing) expand_names in layer names are removed. |
| 2018 | * Order is otherwise preserved, with the layer key_name being replaced by the |
| 2019 | * expand_names. |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 2020 | * @param inst |
| 2021 | * @param layer_count |
| 2022 | * @param ppp_layer_names |
| 2023 | */ |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2024 | VkResult loader_expand_layer_names(struct loader_instance *inst, const char *key_name, uint32_t expand_count, |
| 2025 | const char expand_names[][VK_MAX_EXTENSION_NAME_SIZE], uint32_t *layer_count, |
| 2026 | char const *const **ppp_layer_names) { |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 2027 | char const *const *pp_src_layers = *ppp_layer_names; |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 2028 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2029 | if (!loader_find_layer_name(key_name, *layer_count, (char const **)pp_src_layers)) { |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 2030 | inst->activated_layers_are_std_val = false; |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2031 | return VK_SUCCESS; // didn't find the key_name in the list. |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 2032 | } |
Jon Ashburn | 7148344 | 2016-02-11 18:59:43 -0700 | [diff] [blame] | 2033 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2034 | loader_log(inst, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, "Found meta layer %s, replacing with actual layer group", key_name); |
Chris Forbes | bd9de05 | 2016-04-06 20:49:02 +1200 | [diff] [blame] | 2035 | |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 2036 | inst->activated_layers_are_std_val = true; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2037 | char const **pp_dst_layers = loader_instance_heap_alloc(inst, (expand_count + *layer_count - 1) * sizeof(char const *), |
| 2038 | VK_SYSTEM_ALLOCATION_SCOPE_COMMAND); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2039 | if (NULL == pp_dst_layers) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2040 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 2041 | "loader_expand_layer_names:: Failed to allocate space for " |
| 2042 | "std_validation layer names in pp_dst_layers."); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2043 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 2044 | } |
Chris Forbes | bd9de05 | 2016-04-06 20:49:02 +1200 | [diff] [blame] | 2045 | |
| 2046 | // copy layers from src to dst, stripping key_name and anything in |
| 2047 | // expand_names. |
| 2048 | uint32_t src_index, dst_index = 0; |
| 2049 | for (src_index = 0; src_index < *layer_count; src_index++) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2050 | if (loader_find_layer_name_array(pp_src_layers[src_index], expand_count, expand_names)) { |
Chris Forbes | 6936647 | 2016-04-07 09:04:49 +1200 | [diff] [blame] | 2051 | continue; |
| 2052 | } |
| 2053 | |
| 2054 | if (!strcmp(pp_src_layers[src_index], key_name)) { |
| 2055 | // insert all expand_names in place of key_name |
| 2056 | uint32_t expand_index; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2057 | for (expand_index = 0; expand_index < expand_count; expand_index++) { |
Chris Forbes | 6936647 | 2016-04-07 09:04:49 +1200 | [diff] [blame] | 2058 | pp_dst_layers[dst_index++] = expand_names[expand_index]; |
| 2059 | } |
Chris Forbes | bd9de05 | 2016-04-06 20:49:02 +1200 | [diff] [blame] | 2060 | continue; |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 2061 | } |
Chris Forbes | bd9de05 | 2016-04-06 20:49:02 +1200 | [diff] [blame] | 2062 | |
| 2063 | pp_dst_layers[dst_index++] = pp_src_layers[src_index]; |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 2064 | } |
| 2065 | |
Chris Forbes | bd9de05 | 2016-04-06 20:49:02 +1200 | [diff] [blame] | 2066 | *ppp_layer_names = pp_dst_layers; |
| 2067 | *layer_count = dst_index; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2068 | |
| 2069 | return VK_SUCCESS; |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 2070 | } |
| 2071 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2072 | void loader_delete_shadow_inst_layer_names(const struct loader_instance *inst, const VkInstanceCreateInfo *orig, |
Chris Forbes | bd9de05 | 2016-04-06 20:49:02 +1200 | [diff] [blame] | 2073 | VkInstanceCreateInfo *ours) { |
| 2074 | /* Free the layer names array iff we had to reallocate it */ |
| 2075 | if (orig->ppEnabledLayerNames != ours->ppEnabledLayerNames) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2076 | loader_instance_heap_free(inst, (void *)ours->ppEnabledLayerNames); |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 2077 | } |
| 2078 | } |
| 2079 | |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 2080 | void loader_init_std_validation_props(struct loader_layer_properties *props) { |
| 2081 | memset(props, 0, sizeof(struct loader_layer_properties)); |
| 2082 | props->type = VK_LAYER_TYPE_META_EXPLICT; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2083 | strncpy(props->info.description, "LunarG Standard Validation Layer", sizeof(props->info.description)); |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 2084 | props->info.implementationVersion = 1; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2085 | strncpy(props->info.layerName, std_validation_str, sizeof(props->info.layerName)); |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 2086 | // TODO what about specVersion? for now insert loader's built version |
| 2087 | props->info.specVersion = VK_MAKE_VERSION(1, 0, VK_HEADER_VERSION); |
| 2088 | } |
| 2089 | |
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 | * Searches through the existing instance layer lists looking for |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 2092 | * the set of required layer names. If found then it adds a meta property to the |
| 2093 | * layer list. |
| 2094 | * Assumes the required layers are the same for both instance and device lists. |
| 2095 | * @param inst |
| 2096 | * @param layer_count number of layers in layer_names |
| 2097 | * @param layer_names array of required layer names |
| 2098 | * @param layer_instance_list |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 2099 | */ |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2100 | static void loader_add_layer_property_meta(const struct loader_instance *inst, uint32_t layer_count, |
| 2101 | const char layer_names[][VK_MAX_EXTENSION_NAME_SIZE], |
| 2102 | struct loader_layer_list *layer_instance_list) { |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 2103 | uint32_t i; |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 2104 | bool found; |
| 2105 | struct loader_layer_list *layer_list; |
| 2106 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2107 | if (0 == layer_count || (!layer_instance_list)) return; |
| 2108 | if (layer_instance_list && (layer_count > layer_instance_list->count)) return; |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 2109 | |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 2110 | layer_list = layer_instance_list; |
| 2111 | |
| 2112 | found = true; |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2113 | if (layer_list == NULL) return; |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 2114 | for (i = 0; i < layer_count; i++) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2115 | if (loader_find_layer_name_list(layer_names[i], layer_list)) continue; |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 2116 | found = false; |
| 2117 | break; |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 2118 | } |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 2119 | |
| 2120 | struct loader_layer_properties *props; |
| 2121 | if (found) { |
| 2122 | props = loader_get_next_layer_property(inst, layer_list); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2123 | if (NULL == props) { |
| 2124 | // Error already triggered in loader_get_next_layer_property. |
| 2125 | return; |
| 2126 | } |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 2127 | loader_init_std_validation_props(props); |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 2128 | } |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 2129 | } |
| 2130 | |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2131 | // This structure is used to store the json file version |
| 2132 | // in a more managable way. |
| 2133 | typedef struct { |
| 2134 | uint16_t major; |
| 2135 | uint16_t minor; |
| 2136 | uint16_t patch; |
| 2137 | } layer_json_version; |
| 2138 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2139 | static void loader_read_json_layer(const struct loader_instance *inst, struct loader_layer_list *layer_instance_list, |
| 2140 | cJSON *layer_node, layer_json_version version, cJSON *item, cJSON *disable_environment, |
| 2141 | bool is_implicit, char *filename) { |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2142 | char *temp; |
| 2143 | char *name, *type, *library_path, *api_version; |
| 2144 | char *implementation_version, *description; |
| 2145 | cJSON *ext_item; |
| 2146 | VkExtensionProperties ext_prop; |
| 2147 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2148 | /* |
| 2149 | * The following are required in the "layer" object: |
| 2150 | * (required) "name" |
| 2151 | * (required) "type" |
| 2152 | * (required) “library_path” |
| 2153 | * (required) “api_version” |
| 2154 | * (required) “implementation_version” |
| 2155 | * (required) “description” |
| 2156 | * (required for implicit layers) “disable_environment” |
| 2157 | */ |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 2158 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2159 | #define GET_JSON_OBJECT(node, var) \ |
| 2160 | { \ |
| 2161 | var = cJSON_GetObjectItem(node, #var); \ |
| 2162 | if (var == NULL) { \ |
| 2163 | layer_node = layer_node->next; \ |
| 2164 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, \ |
| 2165 | "Didn't find required layer object %s in manifest " \ |
| 2166 | "JSON file, skipping this layer", \ |
| 2167 | #var); \ |
| 2168 | return; \ |
| 2169 | } \ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2170 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2171 | #define GET_JSON_ITEM(node, var) \ |
| 2172 | { \ |
| 2173 | item = cJSON_GetObjectItem(node, #var); \ |
| 2174 | if (item == NULL) { \ |
| 2175 | layer_node = layer_node->next; \ |
| 2176 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, \ |
| 2177 | "Didn't find required layer value %s in manifest JSON " \ |
| 2178 | "file, skipping this layer", \ |
| 2179 | #var); \ |
| 2180 | return; \ |
| 2181 | } \ |
| 2182 | temp = cJSON_Print(item); \ |
| 2183 | if (temp == NULL) { \ |
| 2184 | layer_node = layer_node->next; \ |
| 2185 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, \ |
| 2186 | "Problem accessing layer value %s in manifest JSON " \ |
| 2187 | "file, skipping this layer", \ |
| 2188 | #var); \ |
| 2189 | return; \ |
| 2190 | } \ |
| 2191 | temp[strlen(temp) - 1] = '\0'; \ |
| 2192 | var = loader_stack_alloc(strlen(temp) + 1); \ |
| 2193 | strcpy(var, &temp[1]); \ |
| 2194 | cJSON_Free(temp); \ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2195 | } |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2196 | GET_JSON_ITEM(layer_node, name) |
| 2197 | GET_JSON_ITEM(layer_node, type) |
| 2198 | GET_JSON_ITEM(layer_node, library_path) |
| 2199 | GET_JSON_ITEM(layer_node, api_version) |
| 2200 | GET_JSON_ITEM(layer_node, implementation_version) |
| 2201 | GET_JSON_ITEM(layer_node, description) |
| 2202 | if (is_implicit) { |
| 2203 | GET_JSON_OBJECT(layer_node, disable_environment) |
| 2204 | } |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 2205 | #undef GET_JSON_ITEM |
| 2206 | #undef GET_JSON_OBJECT |
| 2207 | |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2208 | // Add list entry |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2209 | struct loader_layer_properties *props = NULL; |
| 2210 | if (!strcmp(type, "DEVICE")) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2211 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, "Device layers are deprecated skipping this layer"); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2212 | layer_node = layer_node->next; |
| 2213 | return; |
| 2214 | } |
| 2215 | // Allow either GLOBAL or INSTANCE type interchangeably to handle |
| 2216 | // layers that must work with older loaders |
| 2217 | if (!strcmp(type, "INSTANCE") || !strcmp(type, "GLOBAL")) { |
| 2218 | if (layer_instance_list == NULL) { |
Jon Ashburn | 432d276 | 2015-09-18 12:53:16 -0600 | [diff] [blame] | 2219 | layer_node = layer_node->next; |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2220 | return; |
Jon Ashburn | 432d276 | 2015-09-18 12:53:16 -0600 | [diff] [blame] | 2221 | } |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2222 | props = loader_get_next_layer_property(inst, layer_instance_list); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2223 | if (NULL == props) { |
| 2224 | // Error already triggered in loader_get_next_layer_property. |
| 2225 | return; |
| 2226 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2227 | props->type = (is_implicit) ? VK_LAYER_TYPE_INSTANCE_IMPLICIT : VK_LAYER_TYPE_INSTANCE_EXPLICIT; |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2228 | } |
Jon Ashburn | 432d276 | 2015-09-18 12:53:16 -0600 | [diff] [blame] | 2229 | |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2230 | if (props == NULL) { |
| 2231 | layer_node = layer_node->next; |
| 2232 | return; |
| 2233 | } |
Jon Ashburn | 1531517 | 2015-07-07 15:06:25 -0600 | [diff] [blame] | 2234 | |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2235 | strncpy(props->info.layerName, name, sizeof(props->info.layerName)); |
| 2236 | props->info.layerName[sizeof(props->info.layerName) - 1] = '\0'; |
| 2237 | |
| 2238 | char *fullpath = props->lib_name; |
| 2239 | char *rel_base; |
| 2240 | if (loader_platform_is_path(library_path)) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2241 | // A relative or absolute path |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2242 | char *name_copy = loader_stack_alloc(strlen(filename) + 1); |
| 2243 | strcpy(name_copy, filename); |
| 2244 | rel_base = loader_platform_dirname(name_copy); |
| 2245 | loader_expand_path(library_path, rel_base, MAX_STRING_SIZE, fullpath); |
| 2246 | } else { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2247 | // A filename which is assumed in a system directory |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2248 | loader_get_fullpath(library_path, DEFAULT_VK_LAYERS_PATH, MAX_STRING_SIZE, fullpath); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2249 | } |
| 2250 | props->info.specVersion = loader_make_version(api_version); |
| 2251 | props->info.implementationVersion = atoi(implementation_version); |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2252 | strncpy((char *)props->info.description, description, sizeof(props->info.description)); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2253 | props->info.description[sizeof(props->info.description) - 1] = '\0'; |
| 2254 | if (is_implicit) { |
| 2255 | if (!disable_environment || !disable_environment->child) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2256 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 2257 | "Didn't find required layer child value disable_environment" |
| 2258 | "in manifest JSON file, skipping this layer"); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2259 | layer_node = layer_node->next; |
| 2260 | return; |
Jon Ashburn | fb8ac01 | 2015-08-12 16:39:32 -0600 | [diff] [blame] | 2261 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2262 | strncpy(props->disable_env_var.name, disable_environment->child->string, sizeof(props->disable_env_var.name)); |
| 2263 | props->disable_env_var.name[sizeof(props->disable_env_var.name) - 1] = '\0'; |
| 2264 | strncpy(props->disable_env_var.value, disable_environment->child->valuestring, sizeof(props->disable_env_var.value)); |
| 2265 | props->disable_env_var.value[sizeof(props->disable_env_var.value) - 1] = '\0'; |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2266 | } |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 2267 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2268 | /** |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2269 | * Now get all optional items and objects and put in list: |
| 2270 | * functions |
| 2271 | * instance_extensions |
| 2272 | * device_extensions |
| 2273 | * enable_environment (implicit layers only) |
| 2274 | */ |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2275 | #define GET_JSON_OBJECT(node, var) \ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2276 | { var = cJSON_GetObjectItem(node, #var); } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2277 | #define GET_JSON_ITEM(node, var) \ |
| 2278 | { \ |
| 2279 | item = cJSON_GetObjectItem(node, #var); \ |
| 2280 | if (item != NULL) { \ |
| 2281 | temp = cJSON_Print(item); \ |
| 2282 | if (temp != NULL) { \ |
| 2283 | temp[strlen(temp) - 1] = '\0'; \ |
| 2284 | var = loader_stack_alloc(strlen(temp) + 1); \ |
| 2285 | strcpy(var, &temp[1]); \ |
| 2286 | cJSON_Free(temp); \ |
| 2287 | } \ |
| 2288 | } \ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2289 | } |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 2290 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2291 | cJSON *instance_extensions, *device_extensions, *functions, *enable_environment; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2292 | cJSON *entrypoints = NULL; |
| 2293 | char *vkGetInstanceProcAddr = NULL; |
| 2294 | char *vkGetDeviceProcAddr = NULL; |
| 2295 | char *vkNegotiateLoaderLayerInterfaceVersion = NULL; |
| 2296 | char *spec_version = NULL; |
| 2297 | char **entry_array = NULL; |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2298 | entrypoints = NULL; |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2299 | int i, j; |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 2300 | |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2301 | // Layer interface functions |
| 2302 | // vkGetInstanceProcAddr |
| 2303 | // vkGetDeviceProcAddr |
| 2304 | // vkNegotiateLoaderLayerInterfaceVersion (starting with JSON file 1.1.0) |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2305 | GET_JSON_OBJECT(layer_node, functions) |
| 2306 | if (functions != NULL) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2307 | if (version.major > 1 || version.minor >= 1) { |
| 2308 | GET_JSON_ITEM(functions, vkNegotiateLoaderLayerInterfaceVersion) |
| 2309 | if (vkNegotiateLoaderLayerInterfaceVersion != NULL) |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2310 | strncpy(props->functions.str_negotiate_interface, vkNegotiateLoaderLayerInterfaceVersion, |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2311 | sizeof(props->functions.str_negotiate_interface)); |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2312 | props->functions.str_negotiate_interface[sizeof(props->functions.str_negotiate_interface) - 1] = '\0'; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2313 | } else { |
| 2314 | props->functions.str_negotiate_interface[0] = '\0'; |
| 2315 | } |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2316 | GET_JSON_ITEM(functions, vkGetInstanceProcAddr) |
| 2317 | GET_JSON_ITEM(functions, vkGetDeviceProcAddr) |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2318 | if (vkGetInstanceProcAddr != NULL) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2319 | strncpy(props->functions.str_gipa, vkGetInstanceProcAddr, sizeof(props->functions.str_gipa)); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2320 | if (version.major > 1 || version.minor >= 1) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2321 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 2322 | "Indicating layer-specific vkGetInstanceProcAddr " |
| 2323 | "function is deprecated starting with JSON file " |
| 2324 | "version 1.1.0. Instead, use the new " |
| 2325 | "vkNegotiateLayerInterfaceVersion function to " |
| 2326 | "return the GetInstanceProcAddr function for this" |
| 2327 | "layer"); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2328 | } |
| 2329 | } |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2330 | props->functions.str_gipa[sizeof(props->functions.str_gipa) - 1] = '\0'; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2331 | if (vkGetDeviceProcAddr != NULL) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2332 | strncpy(props->functions.str_gdpa, vkGetDeviceProcAddr, sizeof(props->functions.str_gdpa)); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2333 | if (version.major > 1 || version.minor >= 1) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2334 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 2335 | "Indicating layer-specific vkGetDeviceProcAddr " |
| 2336 | "function is deprecated starting with JSON file " |
| 2337 | "version 1.1.0. Instead, use the new " |
| 2338 | "vkNegotiateLayerInterfaceVersion function to " |
| 2339 | "return the GetDeviceProcAddr function for this" |
| 2340 | "layer"); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2341 | } |
| 2342 | } |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2343 | props->functions.str_gdpa[sizeof(props->functions.str_gdpa) - 1] = '\0'; |
| 2344 | } |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2345 | |
| 2346 | // instance_extensions |
| 2347 | // array of { |
| 2348 | // name |
| 2349 | // spec_version |
| 2350 | // } |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2351 | GET_JSON_OBJECT(layer_node, instance_extensions) |
| 2352 | if (instance_extensions != NULL) { |
| 2353 | int count = cJSON_GetArraySize(instance_extensions); |
| 2354 | for (i = 0; i < count; i++) { |
| 2355 | ext_item = cJSON_GetArrayItem(instance_extensions, i); |
| 2356 | GET_JSON_ITEM(ext_item, name) |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2357 | if (name != NULL) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2358 | strncpy(ext_prop.extensionName, name, sizeof(ext_prop.extensionName)); |
| 2359 | ext_prop.extensionName[sizeof(ext_prop.extensionName) - 1] = '\0'; |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2360 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2361 | GET_JSON_ITEM(ext_item, spec_version) |
| 2362 | if (NULL != spec_version) { |
| 2363 | ext_prop.specVersion = atoi(spec_version); |
| 2364 | } else { |
| 2365 | ext_prop.specVersion = 0; |
| 2366 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2367 | bool ext_unsupported = wsi_unsupported_instance_extension(&ext_prop); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2368 | if (!ext_unsupported) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2369 | loader_add_to_ext_list(inst, &props->instance_extension_list, 1, &ext_prop); |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 2370 | } |
Jon Ashburn | fb8ac01 | 2015-08-12 16:39:32 -0600 | [diff] [blame] | 2371 | } |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2372 | } |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2373 | |
| 2374 | // device_extensions |
| 2375 | // array of { |
| 2376 | // name |
| 2377 | // spec_version |
| 2378 | // entrypoints |
| 2379 | // } |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2380 | GET_JSON_OBJECT(layer_node, device_extensions) |
| 2381 | if (device_extensions != NULL) { |
| 2382 | int count = cJSON_GetArraySize(device_extensions); |
| 2383 | for (i = 0; i < count; i++) { |
| 2384 | ext_item = cJSON_GetArrayItem(device_extensions, i); |
| 2385 | GET_JSON_ITEM(ext_item, name) |
| 2386 | GET_JSON_ITEM(ext_item, spec_version) |
| 2387 | if (name != NULL) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2388 | strncpy(ext_prop.extensionName, name, sizeof(ext_prop.extensionName)); |
| 2389 | ext_prop.extensionName[sizeof(ext_prop.extensionName) - 1] = '\0'; |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2390 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2391 | if (NULL != spec_version) { |
| 2392 | ext_prop.specVersion = atoi(spec_version); |
| 2393 | } else { |
| 2394 | ext_prop.specVersion = 0; |
| 2395 | } |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2396 | // entrypoints = cJSON_GetObjectItem(ext_item, "entrypoints"); |
| 2397 | GET_JSON_OBJECT(ext_item, entrypoints) |
| 2398 | int entry_count; |
| 2399 | if (entrypoints == NULL) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2400 | loader_add_to_dev_ext_list(inst, &props->device_extension_list, &ext_prop, 0, NULL); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2401 | continue; |
| 2402 | } |
| 2403 | entry_count = cJSON_GetArraySize(entrypoints); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2404 | if (entry_count) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2405 | entry_array = (char **)loader_stack_alloc(sizeof(char *) * entry_count); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2406 | } |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2407 | for (j = 0; j < entry_count; j++) { |
| 2408 | ext_item = cJSON_GetArrayItem(entrypoints, j); |
| 2409 | if (ext_item != NULL) { |
| 2410 | temp = cJSON_Print(ext_item); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2411 | if (NULL == temp) { |
| 2412 | entry_array[j] = NULL; |
| 2413 | continue; |
| 2414 | } |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2415 | temp[strlen(temp) - 1] = '\0'; |
| 2416 | entry_array[j] = loader_stack_alloc(strlen(temp) + 1); |
| 2417 | strcpy(entry_array[j], &temp[1]); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2418 | cJSON_Free(temp); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2419 | } |
| 2420 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2421 | loader_add_to_dev_ext_list(inst, &props->device_extension_list, &ext_prop, entry_count, entry_array); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2422 | } |
| 2423 | } |
| 2424 | if (is_implicit) { |
| 2425 | GET_JSON_OBJECT(layer_node, enable_environment) |
| 2426 | |
| 2427 | // enable_environment is optional |
| 2428 | if (enable_environment) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2429 | strncpy(props->enable_env_var.name, enable_environment->child->string, sizeof(props->enable_env_var.name)); |
| 2430 | props->enable_env_var.name[sizeof(props->enable_env_var.name) - 1] = '\0'; |
| 2431 | strncpy(props->enable_env_var.value, enable_environment->child->valuestring, sizeof(props->enable_env_var.value)); |
| 2432 | props->enable_env_var.value[sizeof(props->enable_env_var.value) - 1] = '\0'; |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2433 | } |
| 2434 | } |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 2435 | #undef GET_JSON_ITEM |
| 2436 | #undef GET_JSON_OBJECT |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2437 | } |
| 2438 | |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2439 | static inline bool is_valid_layer_json_version(const layer_json_version *layer_json) { |
| 2440 | // Supported versions are: 1.0.0, 1.0.1, and 1.1.0. |
| 2441 | if ((layer_json->major == 1 && layer_json->minor == 1 && layer_json->patch == 0) || |
| 2442 | (layer_json->major == 1 && layer_json->minor == 0 && layer_json->patch < 2)) { |
| 2443 | return true; |
| 2444 | } |
| 2445 | return false; |
| 2446 | } |
| 2447 | |
| 2448 | static inline bool layer_json_supports_layers_tag(const layer_json_version *layer_json) { |
| 2449 | // Supported versions started in 1.0.1, so anything newer |
| 2450 | if ((layer_json->major > 1 || layer_json->minor > 0 || layer_json->patch > 1)) { |
| 2451 | return true; |
| 2452 | } |
| 2453 | return false; |
| 2454 | } |
| 2455 | |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2456 | /** |
| 2457 | * Given a cJSON struct (json) of the top level JSON object from layer manifest |
| 2458 | * file, add entry to the layer_list. Fill out the layer_properties in this list |
| 2459 | * entry from the input cJSON object. |
| 2460 | * |
| 2461 | * \returns |
| 2462 | * void |
| 2463 | * layer_list has a new entry and initialized accordingly. |
| 2464 | * If the json input object does not have all the required fields no entry |
| 2465 | * is added to the list. |
| 2466 | */ |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2467 | static void loader_add_layer_properties(const struct loader_instance *inst, struct loader_layer_list *layer_instance_list, |
| 2468 | cJSON *json, bool is_implicit, char *filename) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2469 | // The following Fields in layer manifest file that are required: |
| 2470 | // - “file_format_version” |
| 2471 | // - If more than one "layer" object are used, then the "layers" array is |
| 2472 | // requred |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2473 | |
| 2474 | cJSON *item, *layers_node, *layer_node; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2475 | layer_json_version json_version; |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2476 | char *vers_tok; |
| 2477 | cJSON *disable_environment = NULL; |
| 2478 | item = cJSON_GetObjectItem(json, "file_format_version"); |
| 2479 | if (item == NULL) { |
| 2480 | return; |
| 2481 | } |
| 2482 | char *file_vers = cJSON_PrintUnformatted(item); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2483 | if (NULL == file_vers) { |
| 2484 | return; |
| 2485 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2486 | loader_log(inst, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, "Found manifest file %s, version %s", filename, file_vers); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2487 | // Get the major/minor/and patch as integers for easier comparison |
| 2488 | vers_tok = strtok(file_vers, ".\"\n\r"); |
| 2489 | if (NULL != vers_tok) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2490 | json_version.major = (uint16_t)atoi(vers_tok); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2491 | vers_tok = strtok(NULL, ".\"\n\r"); |
| 2492 | if (NULL != vers_tok) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2493 | json_version.minor = (uint16_t)atoi(vers_tok); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2494 | vers_tok = strtok(NULL, ".\"\n\r"); |
| 2495 | if (NULL != vers_tok) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2496 | json_version.patch = (uint16_t)atoi(vers_tok); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2497 | } |
| 2498 | } |
| 2499 | } |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2500 | |
| 2501 | if (!is_valid_layer_json_version(&json_version)) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2502 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 2503 | "loader_add_layer_properties: %s invalid layer " |
| 2504 | " manifest file version %d.%d.%d. May cause errors.", |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2505 | filename, json_version.major, json_version.minor, json_version.patch); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2506 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2507 | cJSON_Free(file_vers); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2508 | |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2509 | // If "layers" is present, read in the array of layer objects |
| 2510 | layers_node = cJSON_GetObjectItem(json, "layers"); |
| 2511 | if (layers_node != NULL) { |
| 2512 | int numItems = cJSON_GetArraySize(layers_node); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2513 | if (!layer_json_supports_layers_tag(&json_version)) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2514 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 2515 | "loader_add_layer_properties: \'layers\' tag not " |
| 2516 | "supported until file version 1.0.1, but %s is " |
| 2517 | "reporting version %s", |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2518 | filename, file_vers); |
| 2519 | } |
| 2520 | for (int curLayer = 0; curLayer < numItems; curLayer++) { |
| 2521 | layer_node = cJSON_GetArrayItem(layers_node, curLayer); |
| 2522 | if (layer_node == NULL) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2523 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 2524 | "loader_add_layer_properties: Can not find " |
| 2525 | "\'layers\' array element %d object in manifest " |
| 2526 | "JSON file %s. Skipping this file", |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2527 | curLayer, filename); |
| 2528 | return; |
| 2529 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2530 | loader_read_json_layer(inst, layer_instance_list, layer_node, json_version, item, disable_environment, is_implicit, |
| 2531 | filename); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2532 | } |
| 2533 | } else { |
| 2534 | // Otherwise, try to read in individual layers |
| 2535 | layer_node = cJSON_GetObjectItem(json, "layer"); |
| 2536 | if (layer_node == NULL) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2537 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 2538 | "loader_add_layer_properties: Can not find \'layer\' " |
| 2539 | "object in manifest JSON file %s. Skipping this file.", |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2540 | filename); |
| 2541 | return; |
| 2542 | } |
| 2543 | // Loop through all "layer" objects in the file to get a count of them |
| 2544 | // first. |
| 2545 | uint16_t layer_count = 0; |
| 2546 | cJSON *tempNode = layer_node; |
| 2547 | do { |
| 2548 | tempNode = tempNode->next; |
| 2549 | layer_count++; |
| 2550 | } while (tempNode != NULL); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2551 | |
| 2552 | // Throw a warning if we encounter multiple "layer" objects in file |
| 2553 | // versions newer than 1.0.0. Having multiple objects with the same |
| 2554 | // name at the same level is actually a JSON standard violation. |
| 2555 | if (layer_count > 1 && layer_json_supports_layers_tag(&json_version)) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2556 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 2557 | "loader_add_layer_properties: Multiple \'layer\' nodes" |
| 2558 | " are deprecated starting in file version \"1.0.1\". " |
| 2559 | "Please use \'layers\' : [] array instead in %s.", |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2560 | filename); |
| 2561 | } else { |
| 2562 | do { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2563 | loader_read_json_layer(inst, layer_instance_list, layer_node, json_version, item, disable_environment, is_implicit, |
| 2564 | filename); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2565 | layer_node = layer_node->next; |
| 2566 | } while (layer_node != NULL); |
| 2567 | } |
| 2568 | } |
Jon Ashburn | fb8ac01 | 2015-08-12 16:39:32 -0600 | [diff] [blame] | 2569 | return; |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 2570 | } |
| 2571 | |
| 2572 | /** |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2573 | * Find the Vulkan library manifest files. |
| 2574 | * |
Jon Ashburn | b682221 | 2016-02-16 15:34:16 -0700 | [diff] [blame] | 2575 | * This function scans the "location" or "env_override" directories/files |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2576 | * for a list of JSON manifest files. If env_override is non-NULL |
| 2577 | * and has a valid value. Then the location is ignored. Otherwise |
| 2578 | * location is used to look for manifest files. The location |
| 2579 | * is interpreted as Registry path on Windows and a directory path(s) |
Jon Ashburn | b682221 | 2016-02-16 15:34:16 -0700 | [diff] [blame] | 2580 | * on Linux. "home_location" is an additional directory in the users home |
John Drinkwater | 9ac3f4f | 2016-08-01 17:00:00 +0100 | [diff] [blame] | 2581 | * directory to look at. It is expanded into the dir path |
| 2582 | * $XDG_DATA_HOME/home_location or $HOME/.local/share/home_location depending |
| 2583 | * on environment variables. This "home_location" is only used on Linux. |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2584 | * |
| 2585 | * \returns |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2586 | * VKResult |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2587 | * A string list of manifest files to be opened in out_files param. |
| 2588 | * List has a pointer to string for each manifest filename. |
| 2589 | * When done using the list in out_files, pointers should be freed. |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2590 | * Location or override string lists can be either files or directories as |
| 2591 | *follows: |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2592 | * | location | override |
| 2593 | * -------------------------------- |
| 2594 | * Win ICD | files | files |
| 2595 | * Win Layer | files | dirs |
| 2596 | * Linux ICD | dirs | files |
| 2597 | * Linux Layer| dirs | dirs |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2598 | */ |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2599 | static VkResult loader_get_manifest_files(const struct loader_instance *inst, const char *env_override, const char *source_override, |
Benjamin Saunders | 31a4801 | 2017-01-29 14:49:54 -0800 | [diff] [blame] | 2600 | bool is_layer, bool warn_if_not_present, const char *location, const char *relative_location, |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2601 | struct loader_manifest_files *out_files) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2602 | const char * override = NULL; |
Frank Henigman | b1c27cb | 2016-11-24 20:02:09 -0500 | [diff] [blame] | 2603 | char *override_getenv = NULL; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2604 | char *loc, *orig_loc = NULL; |
| 2605 | char *reg = NULL; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2606 | char *file, *next_file, *name; |
| 2607 | size_t alloced_count = 64; |
| 2608 | char full_path[2048]; |
| 2609 | DIR *sysdir = NULL; |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2610 | bool list_is_dirs = false; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2611 | struct dirent *dent; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2612 | VkResult res = VK_SUCCESS; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2613 | |
| 2614 | out_files->count = 0; |
| 2615 | out_files->filename_list = NULL; |
| 2616 | |
Jamie Madill | 00c3c91 | 2016-04-06 18:26:46 -0400 | [diff] [blame] | 2617 | if (source_override != NULL) { |
| 2618 | override = source_override; |
Frank Henigman | b1c27cb | 2016-11-24 20:02:09 -0500 | [diff] [blame] | 2619 | } else if (env_override != NULL) { |
Johannes van Waveren | 9bd80501 | 2015-10-28 11:45:00 -0500 | [diff] [blame] | 2620 | #if !defined(_WIN32) |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 2621 | if (geteuid() != getuid() || getegid() != getgid()) { |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2622 | /* Don't allow setuid apps to use the env var: */ |
Frank Henigman | b1c27cb | 2016-11-24 20:02:09 -0500 | [diff] [blame] | 2623 | env_override = NULL; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2624 | } |
| 2625 | #endif |
Frank Henigman | b1c27cb | 2016-11-24 20:02:09 -0500 | [diff] [blame] | 2626 | if (env_override != NULL) { |
| 2627 | override = override_getenv = loader_getenv(env_override, inst); |
| 2628 | } |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2629 | } |
| 2630 | |
Jon Ashburn | b682221 | 2016-02-16 15:34:16 -0700 | [diff] [blame] | 2631 | #if !defined(_WIN32) |
Benjamin Saunders | 31a4801 | 2017-01-29 14:49:54 -0800 | [diff] [blame] | 2632 | if (relative_location == NULL) { |
Jon Ashburn | b682221 | 2016-02-16 15:34:16 -0700 | [diff] [blame] | 2633 | #else |
Benjamin Saunders | 31a4801 | 2017-01-29 14:49:54 -0800 | [diff] [blame] | 2634 | relative_location = NULL; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2635 | if (location == NULL) { |
Jon Ashburn | b682221 | 2016-02-16 15:34:16 -0700 | [diff] [blame] | 2636 | #endif |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2637 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 2638 | "loader_get_manifest_files: Can not get manifest files with " |
| 2639 | "NULL location, env_override=%s", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2640 | (env_override != NULL) ? env_override : ""); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2641 | res = VK_ERROR_INITIALIZATION_FAILED; |
| 2642 | goto out; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2643 | } |
| 2644 | |
Johannes van Waveren | 9bd80501 | 2015-10-28 11:45:00 -0500 | [diff] [blame] | 2645 | #if defined(_WIN32) |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2646 | list_is_dirs = (is_layer && override != NULL) ? true : false; |
Johannes van Waveren | 9bd80501 | 2015-10-28 11:45:00 -0500 | [diff] [blame] | 2647 | #else |
| 2648 | list_is_dirs = (override == NULL || is_layer) ? true : false; |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2649 | #endif |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2650 | // 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] | 2651 | // Also handle getting the location(s) from registry on Windows |
| 2652 | if (override == NULL) { |
Benjamin Saunders | 31a4801 | 2017-01-29 14:49:54 -0800 | [diff] [blame] | 2653 | size_t loc_size = 0; |
| 2654 | #if !defined(_WIN32) |
| 2655 | const char *xdgconfdirs = secure_getenv("XDG_CONFIG_DIRS"); |
| 2656 | const char *xdgdatadirs = secure_getenv("XDG_DATA_DIRS"); |
| 2657 | if (xdgconfdirs == NULL || xdgconfdirs[0] == '\0') |
| 2658 | xdgconfdirs = "/etc/xdg"; |
| 2659 | if (xdgdatadirs == NULL || xdgdatadirs[0] == '\0') |
| 2660 | xdgdatadirs = "/usr/local/share:/usr/share"; |
| 2661 | const size_t rel_size = strlen(relative_location); |
| 2662 | // Leave space for trailing separators |
| 2663 | loc_size += strlen(xdgconfdirs) + strlen(xdgdatadirs) + 2*rel_size + 2; |
| 2664 | for (const char *x = xdgconfdirs; *x; ++x) |
| 2665 | if (*x == PATH_SEPARATOR) loc_size += rel_size; |
| 2666 | for (const char *x = xdgdatadirs; *x; ++x) |
| 2667 | if (*x == PATH_SEPARATOR) loc_size += rel_size; |
| 2668 | loc_size += strlen(SYSCONFDIR) + rel_size + 1; |
| 2669 | #if defined(EXTRASYSCONFDIR) |
| 2670 | loc_size += strlen(EXTRASYSCONFDIR) + rel_size + 1; |
| 2671 | #endif |
| 2672 | #else |
| 2673 | loc_size += strlen(location) + 1; |
| 2674 | #endif |
| 2675 | loc = loader_stack_alloc(loc_size); |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2676 | if (loc == NULL) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2677 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 2678 | "loader_get_manifest_files: Failed to allocate " |
| 2679 | "%d bytes for manifest file location.", |
Benjamin Saunders | 31a4801 | 2017-01-29 14:49:54 -0800 | [diff] [blame] | 2680 | loc_size); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2681 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 2682 | goto out; |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2683 | } |
Benjamin Saunders | 31a4801 | 2017-01-29 14:49:54 -0800 | [diff] [blame] | 2684 | char *loc_write = loc; |
| 2685 | #if !defined(_WIN32) |
| 2686 | const char *loc_read; |
Karl Schultz | 52f5daa | 2017-02-12 12:34:03 -0700 | [diff] [blame^] | 2687 | size_t start, stop; |
Benjamin Saunders | 31a4801 | 2017-01-29 14:49:54 -0800 | [diff] [blame] | 2688 | |
| 2689 | loc_read = &xdgconfdirs[0]; |
Karl Schultz | 52f5daa | 2017-02-12 12:34:03 -0700 | [diff] [blame^] | 2690 | start = 0; |
| 2691 | while (loc_read[start] != '\0') { |
| 2692 | while (loc_read[start] == PATH_SEPARATOR) { |
| 2693 | start++; |
| 2694 | } |
| 2695 | stop = start; |
| 2696 | while (loc_read[stop] != PATH_SEPARATOR && loc_read[stop] != '\0') { |
| 2697 | stop++; |
| 2698 | } |
| 2699 | const size_t s = stop - start; |
| 2700 | if (s) { |
| 2701 | memcpy(loc_write, &loc_read[start], s); |
Benjamin Saunders | 31a4801 | 2017-01-29 14:49:54 -0800 | [diff] [blame] | 2702 | loc_write += s; |
| 2703 | memcpy(loc_write, relative_location, rel_size); |
| 2704 | loc_write += rel_size; |
| 2705 | *loc_write++ = PATH_SEPARATOR; |
Karl Schultz | 52f5daa | 2017-02-12 12:34:03 -0700 | [diff] [blame^] | 2706 | start = stop; |
Benjamin Saunders | 31a4801 | 2017-01-29 14:49:54 -0800 | [diff] [blame] | 2707 | } |
| 2708 | } |
| 2709 | |
| 2710 | memcpy(loc_write, SYSCONFDIR, strlen(SYSCONFDIR)); |
| 2711 | loc_write += strlen(SYSCONFDIR); |
| 2712 | memcpy(loc_write, relative_location, rel_size); |
| 2713 | loc_write += rel_size; |
| 2714 | *loc_write++ = PATH_SEPARATOR; |
| 2715 | |
| 2716 | #if defined(EXTRASYSCONFDIR) |
| 2717 | memcpy(loc_write, EXTRASYSCONFDIR, strlen(EXTRASYSCONFDIR)); |
| 2718 | loc_write += strlen(EXTRASYSCONFDIR); |
| 2719 | memcpy(loc_write, relative_location, rel_size); |
| 2720 | loc_write += rel_size; |
| 2721 | *loc_write++ = PATH_SEPARATOR; |
| 2722 | #endif |
| 2723 | |
| 2724 | loc_read = &xdgdatadirs[0]; |
Karl Schultz | 52f5daa | 2017-02-12 12:34:03 -0700 | [diff] [blame^] | 2725 | start = 0; |
| 2726 | while (loc_read[start] != '\0') { |
| 2727 | while (loc_read[start] == PATH_SEPARATOR) { |
| 2728 | start++; |
| 2729 | } |
| 2730 | stop = start; |
| 2731 | while (loc_read[stop] != PATH_SEPARATOR && loc_read[stop] != '\0') { |
| 2732 | stop++; |
| 2733 | } |
| 2734 | const size_t s = stop - start; |
| 2735 | if (s) { |
| 2736 | memcpy(loc_write, &loc_read[start], s); |
Benjamin Saunders | 31a4801 | 2017-01-29 14:49:54 -0800 | [diff] [blame] | 2737 | loc_write += s; |
| 2738 | memcpy(loc_write, relative_location, rel_size); |
| 2739 | loc_write += rel_size; |
| 2740 | *loc_write++ = PATH_SEPARATOR; |
Karl Schultz | 52f5daa | 2017-02-12 12:34:03 -0700 | [diff] [blame^] | 2741 | start = stop; |
Benjamin Saunders | 31a4801 | 2017-01-29 14:49:54 -0800 | [diff] [blame] | 2742 | } |
| 2743 | } |
Karl Schultz | 52f5daa | 2017-02-12 12:34:03 -0700 | [diff] [blame^] | 2744 | |
Benjamin Saunders | 31a4801 | 2017-01-29 14:49:54 -0800 | [diff] [blame] | 2745 | --loc_write; |
| 2746 | #else |
| 2747 | memcpy(loc_write, location, strlen(location)); |
| 2748 | loc_write += strlen(location); |
| 2749 | #endif |
| 2750 | assert(loc_write - loc < (ptrdiff_t)loc_size); |
| 2751 | *loc_write = '\0'; |
| 2752 | |
Johannes van Waveren | 9bd80501 | 2015-10-28 11:45:00 -0500 | [diff] [blame] | 2753 | #if defined(_WIN32) |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 2754 | VkResult reg_result = loaderGetRegistryFiles(inst, loc, ®); |
| 2755 | if (VK_SUCCESS != reg_result || NULL == reg) { |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 2756 | if (!is_layer) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2757 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 2758 | "loader_get_manifest_files: Registry lookup failed " |
| 2759 | "to get ICD manifest files. Possibly missing Vulkan" |
| 2760 | " driver?"); |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2761 | if (VK_SUCCESS == reg_result || VK_ERROR_OUT_OF_HOST_MEMORY == reg_result) { |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 2762 | res = reg_result; |
| 2763 | } else { |
| 2764 | res = VK_ERROR_INCOMPATIBLE_DRIVER; |
| 2765 | } |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 2766 | } else { |
Mark Young | f8c2010 | 2016-11-07 16:26:17 -0700 | [diff] [blame] | 2767 | if (warn_if_not_present) { |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 2768 | // This is only a warning for layers |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2769 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 2770 | "loader_get_manifest_files: Registry lookup failed " |
| 2771 | "to get layer manifest files."); |
Mark Young | f8c2010 | 2016-11-07 16:26:17 -0700 | [diff] [blame] | 2772 | } |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 2773 | if (reg_result == VK_ERROR_OUT_OF_HOST_MEMORY) { |
| 2774 | res = reg_result; |
| 2775 | } else { |
| 2776 | // Return success for now since it's not critical for layers |
| 2777 | res = VK_SUCCESS; |
| 2778 | } |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 2779 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2780 | goto out; |
Jon Ashburn | 24265ac | 2015-07-31 09:33:21 -0600 | [diff] [blame] | 2781 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2782 | orig_loc = loc; |
| 2783 | loc = reg; |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2784 | #endif |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2785 | } else { |
Courtney Goeltzenleuchter | 7f5aafc | 2015-07-05 11:28:29 -0600 | [diff] [blame] | 2786 | loc = loader_stack_alloc(strlen(override) + 1); |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2787 | if (loc == NULL) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2788 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 2789 | "loader_get_manifest_files: Failed to allocate space for " |
| 2790 | "override environment variable of length %d", |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2791 | strlen(override) + 1); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2792 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 2793 | goto out; |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2794 | } |
| 2795 | strcpy(loc, override); |
| 2796 | } |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2797 | |
Liam Middlebrook | 9b14e89 | 2015-07-23 18:32:20 -0700 | [diff] [blame] | 2798 | // Print out the paths being searched if debugging is enabled |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2799 | loader_log(inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, "Searching the following paths for manifest files: %s\n", loc); |
Liam Middlebrook | 9b14e89 | 2015-07-23 18:32:20 -0700 | [diff] [blame] | 2800 | |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2801 | file = loc; |
| 2802 | while (*file) { |
| 2803 | next_file = loader_get_next_path(file); |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2804 | if (list_is_dirs) { |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2805 | sysdir = opendir(file); |
| 2806 | name = NULL; |
| 2807 | if (sysdir) { |
| 2808 | dent = readdir(sysdir); |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2809 | if (dent == NULL) break; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2810 | name = &(dent->d_name[0]); |
| 2811 | loader_get_fullpath(name, file, sizeof(full_path), full_path); |
| 2812 | name = full_path; |
| 2813 | } |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2814 | } else { |
Johannes van Waveren | 9bd80501 | 2015-10-28 11:45:00 -0500 | [diff] [blame] | 2815 | #if defined(_WIN32) |
| 2816 | name = file; |
| 2817 | #else |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2818 | // only Linux has relative paths |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2819 | char *dir; |
| 2820 | // make a copy of location so it isn't modified |
Jason Ekstrand | cc7550e | 2015-10-10 08:33:37 -0700 | [diff] [blame] | 2821 | dir = loader_stack_alloc(strlen(loc) + 1); |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2822 | if (dir == NULL) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2823 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 2824 | "loader_get_manifest_files: Failed to allocate " |
| 2825 | "space for relative location path length %d", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2826 | strlen(loc) + 1); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2827 | goto out; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2828 | } |
Jason Ekstrand | cc7550e | 2015-10-10 08:33:37 -0700 | [diff] [blame] | 2829 | strcpy(dir, loc); |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2830 | |
| 2831 | loader_get_fullpath(file, dir, sizeof(full_path), full_path); |
| 2832 | |
| 2833 | name = full_path; |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 2834 | #endif |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2835 | } |
| 2836 | while (name) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2837 | /* Look for files ending with ".json" suffix */ |
| 2838 | uint32_t nlen = (uint32_t)strlen(name); |
| 2839 | const char *suf = name + nlen - 5; |
| 2840 | if ((nlen > 5) && !strncmp(suf, ".json", 5)) { |
| 2841 | if (out_files->count == 0) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2842 | out_files->filename_list = |
| 2843 | loader_instance_heap_alloc(inst, alloced_count * sizeof(char *), VK_SYSTEM_ALLOCATION_SCOPE_COMMAND); |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2844 | } else if (out_files->count == alloced_count) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2845 | out_files->filename_list = |
| 2846 | loader_instance_heap_realloc(inst, out_files->filename_list, alloced_count * sizeof(char *), |
| 2847 | alloced_count * sizeof(char *) * 2, VK_SYSTEM_ALLOCATION_SCOPE_COMMAND); |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2848 | alloced_count *= 2; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2849 | } |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2850 | if (out_files->filename_list == NULL) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2851 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 2852 | "loader_get_manifest_files: Failed to allocate " |
| 2853 | "space for manifest file name list"); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2854 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 2855 | goto out; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2856 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2857 | out_files->filename_list[out_files->count] = |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2858 | loader_instance_heap_alloc(inst, strlen(name) + 1, VK_SYSTEM_ALLOCATION_SCOPE_COMMAND); |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2859 | if (out_files->filename_list[out_files->count] == NULL) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2860 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 2861 | "loader_get_manifest_files: Failed to allocate " |
| 2862 | "space for manifest file %d list", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2863 | out_files->count); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2864 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 2865 | goto out; |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2866 | } |
| 2867 | strcpy(out_files->filename_list[out_files->count], name); |
| 2868 | out_files->count++; |
| 2869 | } else if (!list_is_dirs) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2870 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, "Skipping manifest file %s, file name must end in .json", |
| 2871 | name); |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2872 | } |
| 2873 | if (list_is_dirs) { |
| 2874 | dent = readdir(sysdir); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2875 | if (dent == NULL) { |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2876 | break; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2877 | } |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2878 | name = &(dent->d_name[0]); |
| 2879 | loader_get_fullpath(name, file, sizeof(full_path), full_path); |
| 2880 | name = full_path; |
| 2881 | } else { |
| 2882 | break; |
| 2883 | } |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2884 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2885 | if (sysdir) { |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2886 | closedir(sysdir); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2887 | sysdir = NULL; |
| 2888 | } |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2889 | file = next_file; |
Jon Ashburn | 67e262e | 2016-02-18 12:45:39 -0700 | [diff] [blame] | 2890 | #if !defined(_WIN32) |
Benjamin Saunders | 31a4801 | 2017-01-29 14:49:54 -0800 | [diff] [blame] | 2891 | if (relative_location != NULL && (next_file == NULL || *next_file == '\0') && override == NULL) { |
John Drinkwater | 9ac3f4f | 2016-08-01 17:00:00 +0100 | [diff] [blame] | 2892 | char *xdgdatahome = secure_getenv("XDG_DATA_HOME"); |
| 2893 | size_t len; |
| 2894 | if (xdgdatahome != NULL) { |
Benjamin Saunders | 31a4801 | 2017-01-29 14:49:54 -0800 | [diff] [blame] | 2895 | char *home_loc = loader_stack_alloc(strlen(xdgdatahome) + 2 + strlen(relative_location)); |
Jon Ashburn | 67e262e | 2016-02-18 12:45:39 -0700 | [diff] [blame] | 2896 | if (home_loc == NULL) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2897 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 2898 | "loader_get_manifest_files: Failed to allocate " |
| 2899 | "space for manifest file XDG Home location"); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2900 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 2901 | goto out; |
Jon Ashburn | 67e262e | 2016-02-18 12:45:39 -0700 | [diff] [blame] | 2902 | } |
John Drinkwater | 9ac3f4f | 2016-08-01 17:00:00 +0100 | [diff] [blame] | 2903 | strcpy(home_loc, xdgdatahome); |
Jon Ashburn | 67e262e | 2016-02-18 12:45:39 -0700 | [diff] [blame] | 2904 | // Add directory separator if needed |
Benjamin Saunders | 31a4801 | 2017-01-29 14:49:54 -0800 | [diff] [blame] | 2905 | if (relative_location[0] != DIRECTORY_SYMBOL) { |
Jon Ashburn | 67e262e | 2016-02-18 12:45:39 -0700 | [diff] [blame] | 2906 | len = strlen(home_loc); |
| 2907 | home_loc[len] = DIRECTORY_SYMBOL; |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 2908 | home_loc[len + 1] = '\0'; |
Jon Ashburn | 67e262e | 2016-02-18 12:45:39 -0700 | [diff] [blame] | 2909 | } |
Benjamin Saunders | 31a4801 | 2017-01-29 14:49:54 -0800 | [diff] [blame] | 2910 | strcat(home_loc, relative_location); |
Jon Ashburn | 67e262e | 2016-02-18 12:45:39 -0700 | [diff] [blame] | 2911 | file = home_loc; |
| 2912 | next_file = loader_get_next_path(file); |
Benjamin Saunders | 31a4801 | 2017-01-29 14:49:54 -0800 | [diff] [blame] | 2913 | relative_location = NULL; |
Jon Ashburn | 67e262e | 2016-02-18 12:45:39 -0700 | [diff] [blame] | 2914 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2915 | loader_log(inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, "Searching the following path for manifest files: %s\n", |
| 2916 | home_loc); |
Jon Ashburn | 67e262e | 2016-02-18 12:45:39 -0700 | [diff] [blame] | 2917 | list_is_dirs = true; |
John Drinkwater | 9ac3f4f | 2016-08-01 17:00:00 +0100 | [diff] [blame] | 2918 | |
| 2919 | } else { |
John Drinkwater | 9ac3f4f | 2016-08-01 17:00:00 +0100 | [diff] [blame] | 2920 | char *home = secure_getenv("HOME"); |
| 2921 | if (home != NULL) { |
Benjamin Saunders | 31a4801 | 2017-01-29 14:49:54 -0800 | [diff] [blame] | 2922 | char *home_loc = loader_stack_alloc(strlen(home) + 16 + strlen(relative_location)); |
John Drinkwater | 9ac3f4f | 2016-08-01 17:00:00 +0100 | [diff] [blame] | 2923 | if (home_loc == NULL) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2924 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 2925 | "loader_get_manifest_files: Failed to allocate " |
| 2926 | "space for manifest file Home location"); |
John Drinkwater | 9ac3f4f | 2016-08-01 17:00:00 +0100 | [diff] [blame] | 2927 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 2928 | goto out; |
| 2929 | } |
| 2930 | strcpy(home_loc, home); |
| 2931 | |
| 2932 | len = strlen(home); |
| 2933 | if (home[len] != DIRECTORY_SYMBOL) { |
| 2934 | home_loc[len] = DIRECTORY_SYMBOL; |
| 2935 | home_loc[len + 1] = '\0'; |
| 2936 | } |
| 2937 | strcat(home_loc, ".local/share"); |
| 2938 | |
Benjamin Saunders | 31a4801 | 2017-01-29 14:49:54 -0800 | [diff] [blame] | 2939 | if (relative_location[0] != DIRECTORY_SYMBOL) { |
John Drinkwater | 9ac3f4f | 2016-08-01 17:00:00 +0100 | [diff] [blame] | 2940 | len = strlen(home_loc); |
| 2941 | home_loc[len] = DIRECTORY_SYMBOL; |
| 2942 | home_loc[len + 1] = '\0'; |
| 2943 | } |
Benjamin Saunders | 31a4801 | 2017-01-29 14:49:54 -0800 | [diff] [blame] | 2944 | strcat(home_loc, relative_location); |
John Drinkwater | 9ac3f4f | 2016-08-01 17:00:00 +0100 | [diff] [blame] | 2945 | file = home_loc; |
| 2946 | next_file = loader_get_next_path(file); |
Benjamin Saunders | 31a4801 | 2017-01-29 14:49:54 -0800 | [diff] [blame] | 2947 | relative_location = NULL; |
John Drinkwater | 9ac3f4f | 2016-08-01 17:00:00 +0100 | [diff] [blame] | 2948 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2949 | loader_log(inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, "Searching the following path for manifest files: %s\n", |
| 2950 | home_loc); |
John Drinkwater | 9ac3f4f | 2016-08-01 17:00:00 +0100 | [diff] [blame] | 2951 | list_is_dirs = true; |
| 2952 | } else { |
| 2953 | // without knowing HOME, we just.. give up |
| 2954 | } |
Jon Ashburn | 67e262e | 2016-02-18 12:45:39 -0700 | [diff] [blame] | 2955 | } |
| 2956 | } |
| 2957 | #endif |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2958 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2959 | |
| 2960 | out: |
| 2961 | if (VK_SUCCESS != res && NULL != out_files->filename_list) { |
| 2962 | for (uint32_t remove = 0; remove < out_files->count; remove++) { |
| 2963 | loader_instance_heap_free(inst, out_files->filename_list[remove]); |
| 2964 | } |
| 2965 | loader_instance_heap_free(inst, out_files->filename_list); |
| 2966 | out_files->count = 0; |
| 2967 | out_files->filename_list = NULL; |
| 2968 | } |
| 2969 | |
| 2970 | if (NULL != sysdir) { |
| 2971 | closedir(sysdir); |
| 2972 | } |
| 2973 | |
Frank Henigman | b1c27cb | 2016-11-24 20:02:09 -0500 | [diff] [blame] | 2974 | if (override_getenv != NULL) { |
| 2975 | loader_free_getenv(override_getenv, inst); |
| 2976 | } |
| 2977 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2978 | if (NULL != reg && reg != orig_loc) { |
| 2979 | loader_instance_heap_free(inst, reg); |
| 2980 | } |
| 2981 | return res; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2982 | } |
| 2983 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2984 | void loader_init_icd_lib_list() {} |
Jon Ashburn | 8810c5f | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 2985 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2986 | void loader_destroy_icd_lib_list() {} |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2987 | /** |
| 2988 | * Try to find the Vulkan ICD driver(s). |
| 2989 | * |
| 2990 | * This function scans the default system loader path(s) or path |
| 2991 | * specified by the \c VK_ICD_FILENAMES environment variable in |
| 2992 | * order to find loadable VK ICDs manifest files. From these |
| 2993 | * manifest files it finds the ICD libraries. |
| 2994 | * |
| 2995 | * \returns |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2996 | * Vulkan result |
| 2997 | * (on result == VK_SUCCESS) a list of icds that were discovered |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 2998 | */ |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2999 | VkResult loader_icd_scan(const struct loader_instance *inst, struct loader_icd_tramp_list *icd_tramp_list) { |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3000 | char *file_str; |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 3001 | uint16_t file_major_vers = 0; |
| 3002 | uint16_t file_minor_vers = 0; |
| 3003 | uint16_t file_patch_vers = 0; |
| 3004 | char *vers_tok; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3005 | struct loader_manifest_files manifest_files; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3006 | VkResult res = VK_SUCCESS; |
| 3007 | bool lockedMutex = false; |
| 3008 | cJSON *json = NULL; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3009 | uint32_t num_good_icds = 0; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3010 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3011 | memset(&manifest_files, 0, sizeof(struct loader_manifest_files)); |
| 3012 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 3013 | res = loader_scanned_icd_init(inst, icd_tramp_list); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3014 | if (VK_SUCCESS != res) { |
| 3015 | goto out; |
| 3016 | } |
| 3017 | |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3018 | // Get a list of manifest files for ICDs |
Benjamin Saunders | 31a4801 | 2017-01-29 14:49:54 -0800 | [diff] [blame] | 3019 | res = loader_get_manifest_files(inst, "VK_ICD_FILENAMES", NULL, false, true, DEFAULT_VK_DRIVERS_INFO, RELATIVE_VK_DRIVERS_INFO, |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3020 | &manifest_files); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3021 | if (VK_SUCCESS != res || manifest_files.count == 0) { |
| 3022 | goto out; |
| 3023 | } |
Jon Ashburn | 6461ef2 | 2015-09-22 13:11:00 -0600 | [diff] [blame] | 3024 | loader_platform_thread_lock_mutex(&loader_json_lock); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3025 | lockedMutex = true; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3026 | for (uint32_t i = 0; i < manifest_files.count; i++) { |
| 3027 | file_str = manifest_files.filename_list[i]; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3028 | if (file_str == NULL) { |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3029 | continue; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3030 | } |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3031 | |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3032 | res = loader_get_json(inst, file_str, &json); |
| 3033 | if (VK_ERROR_OUT_OF_HOST_MEMORY == res) { |
| 3034 | break; |
| 3035 | } else if (VK_SUCCESS != res || NULL == json) { |
Jon Ashburn | aa4ea47 | 2015-08-27 08:30:50 -0600 | [diff] [blame] | 3036 | continue; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3037 | } |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3038 | |
Jon Ashburn | 005617f | 2015-11-17 17:35:40 -0700 | [diff] [blame] | 3039 | cJSON *item, *itemICD; |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 3040 | item = cJSON_GetObjectItem(json, "file_format_version"); |
Jon Ashburn | 6461ef2 | 2015-09-22 13:11:00 -0600 | [diff] [blame] | 3041 | if (item == NULL) { |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3042 | if (num_good_icds == 0) { |
| 3043 | res = VK_ERROR_INITIALIZATION_FAILED; |
| 3044 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3045 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 3046 | "loader_icd_scan: ICD JSON %s does not have a" |
| 3047 | " \'file_format_version\' field. Skipping ICD JSON.", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3048 | file_str); |
Derrick Owens | 62e16ef | 2016-09-09 15:49:07 -0400 | [diff] [blame] | 3049 | cJSON_Delete(json); |
| 3050 | json = NULL; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3051 | continue; |
Jon Ashburn | 6461ef2 | 2015-09-22 13:11:00 -0600 | [diff] [blame] | 3052 | } |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 3053 | char *file_vers = cJSON_Print(item); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3054 | if (NULL == file_vers) { |
| 3055 | // Only reason the print can fail is if there was an allocation |
| 3056 | // issue |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3057 | if (num_good_icds == 0) { |
| 3058 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 3059 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3060 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 3061 | "loader_icd_scan: Failed retrieving ICD JSON %s" |
| 3062 | " \'file_format_version\' field. Skipping ICD JSON", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3063 | file_str); |
Derrick Owens | cd92b8b | 2016-09-09 15:45:13 -0400 | [diff] [blame] | 3064 | cJSON_Delete(json); |
| 3065 | json = NULL; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3066 | continue; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3067 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3068 | loader_log(inst, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, "Found ICD manifest file %s, version %s", file_str, file_vers); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 3069 | // Get the major/minor/and patch as integers for easier comparison |
| 3070 | vers_tok = strtok(file_vers, ".\"\n\r"); |
| 3071 | if (NULL != vers_tok) { |
Jamie Madill | 970ebcf | 2016-07-06 11:19:42 -0400 | [diff] [blame] | 3072 | file_major_vers = (uint16_t)atoi(vers_tok); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 3073 | vers_tok = strtok(NULL, ".\"\n\r"); |
| 3074 | if (NULL != vers_tok) { |
Jamie Madill | 970ebcf | 2016-07-06 11:19:42 -0400 | [diff] [blame] | 3075 | file_minor_vers = (uint16_t)atoi(vers_tok); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 3076 | vers_tok = strtok(NULL, ".\"\n\r"); |
| 3077 | if (NULL != vers_tok) { |
Jamie Madill | 970ebcf | 2016-07-06 11:19:42 -0400 | [diff] [blame] | 3078 | file_patch_vers = (uint16_t)atoi(vers_tok); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 3079 | } |
| 3080 | } |
| 3081 | } |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 3082 | if (file_major_vers != 1 || file_minor_vers != 0 || file_patch_vers > 1) |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3083 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 3084 | "loader_icd_scan: Unexpected manifest file version " |
| 3085 | "(expected 1.0.0 or 1.0.1), may cause errors"); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3086 | cJSON_Free(file_vers); |
Jon Ashburn | 005617f | 2015-11-17 17:35:40 -0700 | [diff] [blame] | 3087 | itemICD = cJSON_GetObjectItem(json, "ICD"); |
| 3088 | if (itemICD != NULL) { |
| 3089 | item = cJSON_GetObjectItem(itemICD, "library_path"); |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 3090 | if (item != NULL) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3091 | char *temp = cJSON_Print(item); |
Jon Ashburn | 8625130 | 2015-08-25 16:48:24 -0600 | [diff] [blame] | 3092 | if (!temp || strlen(temp) == 0) { |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3093 | if (num_good_icds == 0) { |
| 3094 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 3095 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3096 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 3097 | "loader_icd_scan: Failed retrieving ICD JSON %s" |
| 3098 | " \'library_path\' field. Skipping ICD JSON.", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3099 | file_str); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3100 | cJSON_Free(temp); |
Jon Ashburn | 8625130 | 2015-08-25 16:48:24 -0600 | [diff] [blame] | 3101 | cJSON_Delete(json); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3102 | json = NULL; |
Jon Ashburn | 8625130 | 2015-08-25 16:48:24 -0600 | [diff] [blame] | 3103 | continue; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3104 | } |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3105 | // strip out extra quotes |
Jon Ashburn | 8625130 | 2015-08-25 16:48:24 -0600 | [diff] [blame] | 3106 | temp[strlen(temp) - 1] = '\0'; |
| 3107 | char *library_path = loader_stack_alloc(strlen(temp) + 1); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3108 | if (NULL == library_path) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3109 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 3110 | "loader_icd_scan: Failed to allocate space for " |
| 3111 | "ICD JSON %s \'library_path\' value. Skipping " |
| 3112 | "ICD JSON.", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3113 | file_str); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3114 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 3115 | cJSON_Free(temp); |
| 3116 | cJSON_Delete(json); |
| 3117 | json = NULL; |
| 3118 | goto out; |
| 3119 | } |
Jon Ashburn | 8625130 | 2015-08-25 16:48:24 -0600 | [diff] [blame] | 3120 | strcpy(library_path, &temp[1]); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3121 | cJSON_Free(temp); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3122 | if (strlen(library_path) == 0) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3123 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 3124 | "loader_icd_scan: ICD JSON %s \'library_path\'" |
| 3125 | " field is empty. Skipping ICD JSON.", |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3126 | file_str); |
Jon Ashburn | 8625130 | 2015-08-25 16:48:24 -0600 | [diff] [blame] | 3127 | cJSON_Delete(json); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3128 | json = NULL; |
Jon Ashburn | 8625130 | 2015-08-25 16:48:24 -0600 | [diff] [blame] | 3129 | continue; |
| 3130 | } |
Jamie Madill | 2fcbd15 | 2016-04-27 16:33:23 -0400 | [diff] [blame] | 3131 | char fullpath[MAX_STRING_SIZE]; |
Jon Ashburn | 8625130 | 2015-08-25 16:48:24 -0600 | [diff] [blame] | 3132 | // Print out the paths being searched if debugging is enabled |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3133 | loader_log(inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, "Searching for ICD drivers named %s, using default dir %s", |
| 3134 | library_path, DEFAULT_VK_DRIVERS_PATH); |
Daniel Dadap | 00b4aba | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 3135 | if (loader_platform_is_path(library_path)) { |
Jon Ashburn | 8625130 | 2015-08-25 16:48:24 -0600 | [diff] [blame] | 3136 | // a relative or absolute path |
Daniel Dadap | 00b4aba | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 3137 | char *name_copy = loader_stack_alloc(strlen(file_str) + 1); |
| 3138 | char *rel_base; |
Jon Ashburn | 8625130 | 2015-08-25 16:48:24 -0600 | [diff] [blame] | 3139 | strcpy(name_copy, file_str); |
| 3140 | rel_base = loader_platform_dirname(name_copy); |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3141 | loader_expand_path(library_path, rel_base, sizeof(fullpath), fullpath); |
Daniel Dadap | 00b4aba | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 3142 | } else { |
Jamie Madill | 2fcbd15 | 2016-04-27 16:33:23 -0400 | [diff] [blame] | 3143 | // a filename which is assumed in a system directory |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3144 | loader_get_fullpath(library_path, DEFAULT_VK_DRIVERS_PATH, sizeof(fullpath), fullpath); |
Jon Ashburn | 8625130 | 2015-08-25 16:48:24 -0600 | [diff] [blame] | 3145 | } |
Jon Ashburn | 005617f | 2015-11-17 17:35:40 -0700 | [diff] [blame] | 3146 | |
| 3147 | uint32_t vers = 0; |
| 3148 | item = cJSON_GetObjectItem(itemICD, "api_version"); |
| 3149 | if (item != NULL) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3150 | temp = cJSON_Print(item); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3151 | if (NULL == temp) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3152 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 3153 | "loader_icd_scan: Failed retrieving ICD JSON %s" |
| 3154 | " \'api_version\' field. Skipping ICD JSON.", |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3155 | file_str); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3156 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3157 | // Only reason the print can fail is if there was an |
| 3158 | // allocation issue |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3159 | if (num_good_icds == 0) { |
| 3160 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 3161 | } |
| 3162 | |
| 3163 | cJSON_Free(temp); |
| 3164 | cJSON_Delete(json); |
| 3165 | json = NULL; |
| 3166 | continue; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3167 | } |
Jon Ashburn | 005617f | 2015-11-17 17:35:40 -0700 | [diff] [blame] | 3168 | vers = loader_make_version(temp); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3169 | cJSON_Free(temp); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3170 | } else { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3171 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 3172 | "loader_icd_scan: ICD JSON %s does not have an" |
| 3173 | " \'api_version\' field.", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3174 | file_str); |
Jon Ashburn | 005617f | 2015-11-17 17:35:40 -0700 | [diff] [blame] | 3175 | } |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3176 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3177 | res = loader_scanned_icd_add(inst, icd_tramp_list, fullpath, vers); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3178 | if (VK_SUCCESS != res) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3179 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 3180 | "loader_icd_scan: Failed to add ICD JSON %s. " |
| 3181 | " Skipping ICD JSON.", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3182 | fullpath); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3183 | continue; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3184 | } |
| 3185 | num_good_icds++; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3186 | } else { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3187 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 3188 | "loader_icd_scan: Failed to find \'library_path\' " |
| 3189 | "object in ICD JSON file %s. Skipping ICD JSON.", |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3190 | file_str); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3191 | } |
| 3192 | } else { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3193 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 3194 | "loader_icd_scan: Can not find \'ICD\' object in ICD JSON " |
| 3195 | "file %s. Skipping ICD JSON", |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3196 | file_str); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3197 | } |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3198 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3199 | cJSON_Delete(json); |
| 3200 | json = NULL; |
| 3201 | } |
| 3202 | |
| 3203 | out: |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3204 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3205 | if (NULL != json) { |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3206 | cJSON_Delete(json); |
| 3207 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3208 | if (NULL != manifest_files.filename_list) { |
| 3209 | for (uint32_t i = 0; i < manifest_files.count; i++) { |
| 3210 | if (NULL != manifest_files.filename_list[i]) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3211 | loader_instance_heap_free(inst, manifest_files.filename_list[i]); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3212 | } |
| 3213 | } |
| 3214 | loader_instance_heap_free(inst, manifest_files.filename_list); |
| 3215 | } |
| 3216 | if (lockedMutex) { |
| 3217 | loader_platform_thread_unlock_mutex(&loader_json_lock); |
| 3218 | } |
| 3219 | return res; |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 3220 | } |
| 3221 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3222 | void loader_layer_scan(const struct loader_instance *inst, struct loader_layer_list *instance_layers) { |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 3223 | char *file_str; |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3224 | struct loader_manifest_files manifest_files[2]; // [0] = explicit, [1] = implicit |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 3225 | cJSON *json; |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3226 | uint32_t implicit; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3227 | bool lockedMutex = false; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 3228 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3229 | memset(manifest_files, 0, sizeof(struct loader_manifest_files) * 2); |
| 3230 | |
| 3231 | // Get a list of manifest files for explicit layers |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3232 | if (VK_SUCCESS != loader_get_manifest_files(inst, LAYERS_PATH_ENV, LAYERS_SOURCE_PATH, true, true, DEFAULT_VK_ELAYERS_INFO, |
Benjamin Saunders | 31a4801 | 2017-01-29 14:49:54 -0800 | [diff] [blame] | 3233 | RELATIVE_VK_ELAYERS_INFO, &manifest_files[0])) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3234 | goto out; |
| 3235 | } |
| 3236 | |
| 3237 | // Get a list of manifest files for any implicit layers |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3238 | // Pass NULL for environment variable override - implicit layers are not |
| 3239 | // overridden by LAYERS_PATH_ENV |
Benjamin Saunders | 31a4801 | 2017-01-29 14:49:54 -0800 | [diff] [blame] | 3240 | if (VK_SUCCESS != loader_get_manifest_files(inst, NULL, NULL, true, false, DEFAULT_VK_ILAYERS_INFO, RELATIVE_VK_ILAYERS_INFO, |
Mark Young | f8c2010 | 2016-11-07 16:26:17 -0700 | [diff] [blame] | 3241 | &manifest_files[1])) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3242 | goto out; |
| 3243 | } |
Jon Ashburn | 90c6a0e | 2015-06-04 15:30:58 -0600 | [diff] [blame] | 3244 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3245 | // Make sure we have at least one layer, if not, go ahead and return |
| 3246 | if (manifest_files[0].count == 0 && manifest_files[1].count == 0) { |
| 3247 | goto out; |
| 3248 | } |
| 3249 | |
| 3250 | // cleanup any previously scanned libraries |
Jon Ashburn | e39a4f8 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 3251 | loader_delete_layer_properties(inst, instance_layers); |
Jon Ashburn | b2ef137 | 2015-07-16 17:19:31 -0600 | [diff] [blame] | 3252 | |
Jon Ashburn | 6461ef2 | 2015-09-22 13:11:00 -0600 | [diff] [blame] | 3253 | loader_platform_thread_lock_mutex(&loader_json_lock); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3254 | lockedMutex = true; |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3255 | for (implicit = 0; implicit < 2; implicit++) { |
Jamie Madill | 970ebcf | 2016-07-06 11:19:42 -0400 | [diff] [blame] | 3256 | for (uint32_t i = 0; i < manifest_files[implicit].count; i++) { |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3257 | file_str = manifest_files[implicit].filename_list[i]; |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3258 | if (file_str == NULL) continue; |
Courtney Goeltzenleuchter | a9e4af4 | 2015-06-01 14:49:17 -0600 | [diff] [blame] | 3259 | |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3260 | // parse file into JSON struct |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3261 | VkResult res = loader_get_json(inst, file_str, &json); |
| 3262 | if (VK_ERROR_OUT_OF_HOST_MEMORY == res) { |
| 3263 | break; |
| 3264 | } else if (VK_SUCCESS != res || NULL == json) { |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3265 | continue; |
| 3266 | } |
| 3267 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3268 | loader_add_layer_properties(inst, instance_layers, json, (implicit == 1), file_str); |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3269 | cJSON_Delete(json); |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 3270 | } |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 3271 | } |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 3272 | |
| 3273 | // add a meta layer for validation if the validation layers are all present |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3274 | loader_add_layer_property_meta(inst, sizeof(std_validation_names) / sizeof(std_validation_names[0]), std_validation_names, |
| 3275 | instance_layers); |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 3276 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3277 | out: |
| 3278 | |
| 3279 | for (uint32_t manFile = 0; manFile < 2; manFile++) { |
| 3280 | if (NULL != manifest_files[manFile].filename_list) { |
| 3281 | for (uint32_t i = 0; i < manifest_files[manFile].count; i++) { |
| 3282 | if (NULL != manifest_files[manFile].filename_list[i]) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3283 | loader_instance_heap_free(inst, manifest_files[manFile].filename_list[i]); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3284 | } |
| 3285 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3286 | loader_instance_heap_free(inst, manifest_files[manFile].filename_list); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3287 | } |
| 3288 | } |
| 3289 | if (lockedMutex) { |
| 3290 | loader_platform_thread_unlock_mutex(&loader_json_lock); |
| 3291 | } |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 3292 | } |
| 3293 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3294 | void loader_implicit_layer_scan(const struct loader_instance *inst, struct loader_layer_list *instance_layers) { |
Jeremy Hayes | 3e2bd5a | 2016-04-01 11:40:26 -0600 | [diff] [blame] | 3295 | char *file_str; |
| 3296 | struct loader_manifest_files manifest_files; |
| 3297 | cJSON *json; |
| 3298 | uint32_t i; |
| 3299 | |
| 3300 | // Pass NULL for environment variable override - implicit layers are not |
| 3301 | // overridden by LAYERS_PATH_ENV |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3302 | VkResult res = |
Benjamin Saunders | 31a4801 | 2017-01-29 14:49:54 -0800 | [diff] [blame] | 3303 | loader_get_manifest_files(inst, NULL, NULL, true, false, DEFAULT_VK_ILAYERS_INFO, RELATIVE_VK_ILAYERS_INFO, &manifest_files); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3304 | if (VK_SUCCESS != res || manifest_files.count == 0) { |
Jeremy Hayes | 3e2bd5a | 2016-04-01 11:40:26 -0600 | [diff] [blame] | 3305 | return; |
| 3306 | } |
| 3307 | |
| 3308 | /* cleanup any previously scanned libraries */ |
| 3309 | loader_delete_layer_properties(inst, instance_layers); |
Jeremy Hayes | 3e2bd5a | 2016-04-01 11:40:26 -0600 | [diff] [blame] | 3310 | |
| 3311 | loader_platform_thread_lock_mutex(&loader_json_lock); |
| 3312 | |
| 3313 | for (i = 0; i < manifest_files.count; i++) { |
| 3314 | file_str = manifest_files.filename_list[i]; |
| 3315 | if (file_str == NULL) { |
| 3316 | continue; |
| 3317 | } |
| 3318 | |
| 3319 | // parse file into JSON struct |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3320 | res = loader_get_json(inst, file_str, &json); |
| 3321 | if (VK_ERROR_OUT_OF_HOST_MEMORY == res) { |
| 3322 | break; |
| 3323 | } else if (VK_SUCCESS != res || NULL == json) { |
Jeremy Hayes | 3e2bd5a | 2016-04-01 11:40:26 -0600 | [diff] [blame] | 3324 | continue; |
| 3325 | } |
| 3326 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3327 | loader_add_layer_properties(inst, instance_layers, json, true, file_str); |
Jeremy Hayes | 3e2bd5a | 2016-04-01 11:40:26 -0600 | [diff] [blame] | 3328 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3329 | loader_instance_heap_free(inst, file_str); |
Jeremy Hayes | 3e2bd5a | 2016-04-01 11:40:26 -0600 | [diff] [blame] | 3330 | cJSON_Delete(json); |
| 3331 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3332 | loader_instance_heap_free(inst, manifest_files.filename_list); |
Jeremy Hayes | 3e2bd5a | 2016-04-01 11:40:26 -0600 | [diff] [blame] | 3333 | |
| 3334 | // add a meta layer for validation if the validation layers are all present |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3335 | loader_add_layer_property_meta(inst, sizeof(std_validation_names) / sizeof(std_validation_names[0]), std_validation_names, |
| 3336 | instance_layers); |
Jeremy Hayes | 3e2bd5a | 2016-04-01 11:40:26 -0600 | [diff] [blame] | 3337 | |
| 3338 | loader_platform_thread_unlock_mutex(&loader_json_lock); |
| 3339 | } |
| 3340 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3341 | static VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL loader_gpdpa_instance_internal(VkInstance inst, const char *pName) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3342 | // inst is not wrapped |
| 3343 | if (inst == VK_NULL_HANDLE) { |
| 3344 | return NULL; |
| 3345 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3346 | VkLayerInstanceDispatchTable *disp_table = *(VkLayerInstanceDispatchTable **)inst; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3347 | void *addr; |
| 3348 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3349 | if (disp_table == NULL) return NULL; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3350 | |
| 3351 | bool found_name; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3352 | addr = loader_lookup_instance_dispatch_table(disp_table, pName, &found_name); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3353 | if (found_name) { |
| 3354 | return addr; |
| 3355 | } |
| 3356 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3357 | if (loader_phys_dev_ext_gpa(loader_get_instance(inst), pName, true, NULL, &addr)) return addr; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3358 | |
| 3359 | // Don't call down the chain, this would be an infinite loop |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3360 | loader_log(NULL, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, "loader_gpdpa_instance_internal() unrecognized name %s", pName); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3361 | return NULL; |
| 3362 | } |
| 3363 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3364 | static VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL loader_gpdpa_instance_terminator(VkInstance inst, const char *pName) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3365 | // inst is not wrapped |
| 3366 | if (inst == VK_NULL_HANDLE) { |
| 3367 | return NULL; |
| 3368 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3369 | VkLayerInstanceDispatchTable *disp_table = *(VkLayerInstanceDispatchTable **)inst; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3370 | void *addr; |
| 3371 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3372 | if (disp_table == NULL) return NULL; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3373 | |
| 3374 | bool found_name; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3375 | addr = loader_lookup_instance_dispatch_table(disp_table, pName, &found_name); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3376 | if (found_name) { |
| 3377 | return addr; |
| 3378 | } |
| 3379 | |
| 3380 | // Get the terminator, but don't perform checking since it should already |
| 3381 | // have been setup if we get here. |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3382 | if (loader_phys_dev_ext_gpa(loader_get_instance(inst), pName, false, NULL, &addr)) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3383 | return addr; |
| 3384 | } |
| 3385 | |
| 3386 | // Don't call down the chain, this would be an infinite loop |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3387 | loader_log(NULL, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, "loader_gpdpa_instance_terminator() unrecognized name %s", pName); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3388 | return NULL; |
| 3389 | } |
| 3390 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3391 | static VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL loader_gpa_instance_internal(VkInstance inst, const char *pName) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3392 | if (!strcmp(pName, "vkGetInstanceProcAddr")) { |
| 3393 | return (PFN_vkVoidFunction)loader_gpa_instance_internal; |
| 3394 | } |
| 3395 | if (!strcmp(pName, "vk_layerGetPhysicalDeviceProcAddr")) { |
| 3396 | return (PFN_vkVoidFunction)loader_gpdpa_instance_terminator; |
| 3397 | } |
| 3398 | if (!strcmp(pName, "vkCreateInstance")) { |
| 3399 | return (PFN_vkVoidFunction)terminator_CreateInstance; |
| 3400 | } |
| 3401 | if (!strcmp(pName, "vkCreateDevice")) { |
| 3402 | return (PFN_vkVoidFunction)terminator_CreateDevice; |
| 3403 | } |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3404 | |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 3405 | // inst is not wrapped |
| 3406 | if (inst == VK_NULL_HANDLE) { |
| 3407 | return NULL; |
| 3408 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3409 | VkLayerInstanceDispatchTable *disp_table = *(VkLayerInstanceDispatchTable **)inst; |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 3410 | void *addr; |
| 3411 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3412 | if (disp_table == NULL) return NULL; |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 3413 | |
Jon Ashburn | c7d3e73 | 2016-03-08 09:30:30 -0700 | [diff] [blame] | 3414 | bool found_name; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3415 | addr = loader_lookup_instance_dispatch_table(disp_table, pName, &found_name); |
Jon Ashburn | c7d3e73 | 2016-03-08 09:30:30 -0700 | [diff] [blame] | 3416 | if (found_name) { |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 3417 | return addr; |
Jon Ashburn | 3d526cb | 2015-04-13 18:10:06 -0600 | [diff] [blame] | 3418 | } |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3419 | |
Jon Ashburn | c7d3e73 | 2016-03-08 09:30:30 -0700 | [diff] [blame] | 3420 | // Don't call down the chain, this would be an infinite loop |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3421 | loader_log(NULL, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, "loader_gpa_instance_internal() unrecognized name %s", pName); |
Jon Ashburn | c7d3e73 | 2016-03-08 09:30:30 -0700 | [diff] [blame] | 3422 | return NULL; |
Jon Ashburn | 3d526cb | 2015-04-13 18:10:06 -0600 | [diff] [blame] | 3423 | } |
| 3424 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3425 | VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL loader_gpa_device_internal(VkDevice device, const char *pName) { |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 3426 | struct loader_device *dev; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3427 | struct loader_icd_term *icd_term = loader_get_icd_and_device(device, &dev, NULL); |
Mark Young | 16573c7 | 2016-06-28 10:52:43 -0600 | [diff] [blame] | 3428 | |
Mark Young | 65cb366 | 2016-11-07 13:27:02 -0700 | [diff] [blame] | 3429 | // NOTE: Device Funcs needing Trampoline/Terminator. |
| 3430 | // Overrides for device functions needing a trampoline and |
| 3431 | // a terminator because certain device entry-points still need to go |
| 3432 | // through a terminator before hitting the ICD. This could be for |
| 3433 | // several reasons, but the main one is currently unwrapping an |
| 3434 | // object before passing the appropriate info along to the ICD. |
| 3435 | // This is why we also have to override the direct ICD call to |
| 3436 | // vkGetDeviceProcAddr to intercept those calls. |
| 3437 | if (!strcmp(pName, "vkGetDeviceProcAddr")) { |
| 3438 | return (PFN_vkVoidFunction)loader_gpa_device_internal; |
| 3439 | } else if (!strcmp(pName, "vkCreateSwapchainKHR")) { |
Mark Young | 16573c7 | 2016-06-28 10:52:43 -0600 | [diff] [blame] | 3440 | return (PFN_vkVoidFunction)terminator_vkCreateSwapchainKHR; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3441 | } else if (!strcmp(pName, "vkCreateSharedSwapchainsKHR")) { |
| 3442 | return (PFN_vkVoidFunction)terminator_vkCreateSharedSwapchainsKHR; |
Mark Young | 65cb366 | 2016-11-07 13:27:02 -0700 | [diff] [blame] | 3443 | } else if (!strcmp(pName, "vkDebugMarkerSetObjectTagEXT")) { |
| 3444 | return (PFN_vkVoidFunction)terminator_DebugMarkerSetObjectTagEXT; |
| 3445 | } else if (!strcmp(pName, "vkDebugMarkerSetObjectNameEXT")) { |
| 3446 | return (PFN_vkVoidFunction)terminator_DebugMarkerSetObjectNameEXT; |
Mark Young | 16573c7 | 2016-06-28 10:52:43 -0600 | [diff] [blame] | 3447 | } |
| 3448 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 3449 | return icd_term->GetDeviceProcAddr(device, pName); |
Piers Daniell | 295fe40 | 2016-03-29 11:51:11 -0600 | [diff] [blame] | 3450 | } |
| 3451 | |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3452 | /** |
| 3453 | * Initialize device_ext dispatch table entry as follows: |
| 3454 | * If dev == NULL find all logical devices created within this instance and |
| 3455 | * init the entry (given by idx) in the ext dispatch table. |
| 3456 | * 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] | 3457 | * The initialization value is gotten by calling down the device chain with |
| 3458 | * GDPA. |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3459 | * If GDPA returns NULL then don't initialize the dispatch table entry. |
| 3460 | */ |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3461 | static void loader_init_dispatch_dev_ext_entry(struct loader_instance *inst, struct loader_device *dev, uint32_t idx, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3462 | const char *funcName) |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3463 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3464 | { |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3465 | void *gdpa_value; |
| 3466 | if (dev != NULL) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3467 | gdpa_value = dev->loader_dispatch.core_dispatch.GetDeviceProcAddr(dev->chain_device, funcName); |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3468 | if (gdpa_value != NULL) dev->loader_dispatch.ext_dispatch.dev_ext[idx] = (PFN_vkDevExt)gdpa_value; |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3469 | } else { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3470 | for (struct loader_icd_term *icd_term = inst->icd_terms; icd_term != NULL; icd_term = icd_term->next) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 3471 | struct loader_device *ldev = icd_term->logical_device_list; |
Karl Schultz | 2558bd3 | 2016-02-24 14:39:39 -0700 | [diff] [blame] | 3472 | while (ldev) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3473 | gdpa_value = ldev->loader_dispatch.core_dispatch.GetDeviceProcAddr(ldev->chain_device, funcName); |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3474 | if (gdpa_value != NULL) ldev->loader_dispatch.ext_dispatch.dev_ext[idx] = (PFN_vkDevExt)gdpa_value; |
Karl Schultz | 2558bd3 | 2016-02-24 14:39:39 -0700 | [diff] [blame] | 3475 | ldev = ldev->next; |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3476 | } |
| 3477 | } |
| 3478 | } |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3479 | } |
| 3480 | |
| 3481 | /** |
| 3482 | * Find all dev extension in the hash table and initialize the dispatch table |
| 3483 | * for dev for each of those extension entrypoints found in hash table. |
| 3484 | |
| 3485 | */ |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3486 | void loader_init_dispatch_dev_ext(struct loader_instance *inst, struct loader_device *dev) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3487 | for (uint32_t i = 0; i < MAX_NUM_UNKNOWN_EXTS; i++) { |
| 3488 | if (inst->dev_ext_disp_hash[i].func_name != NULL) |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3489 | loader_init_dispatch_dev_ext_entry(inst, dev, i, inst->dev_ext_disp_hash[i].func_name); |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3490 | } |
| 3491 | } |
| 3492 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3493 | static bool loader_check_icds_for_dev_ext_address(struct loader_instance *inst, const char *funcName) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 3494 | struct loader_icd_term *icd_term; |
| 3495 | icd_term = inst->icd_terms; |
| 3496 | while (NULL != icd_term) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3497 | if (icd_term->scanned_icd->GetInstanceProcAddr(icd_term->instance, funcName)) |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3498 | // this icd supports funcName |
| 3499 | return true; |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 3500 | icd_term = icd_term->next; |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3501 | } |
| 3502 | |
| 3503 | return false; |
| 3504 | } |
| 3505 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3506 | static bool loader_check_layer_list_for_dev_ext_address(const struct loader_layer_list *const layers, const char *funcName) { |
Jeremy Hayes | 1eb1f62 | 2016-03-03 16:03:03 -0700 | [diff] [blame] | 3507 | // Iterate over the layers. |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 3508 | for (uint32_t layer = 0; layer < layers->count; ++layer) { |
Jeremy Hayes | 1eb1f62 | 2016-03-03 16:03:03 -0700 | [diff] [blame] | 3509 | // Iterate over the extensions. |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3510 | const struct loader_device_extension_list *const extensions = &(layers->list[layer].device_extension_list); |
| 3511 | for (uint32_t extension = 0; extension < extensions->count; ++extension) { |
Jeremy Hayes | 1eb1f62 | 2016-03-03 16:03:03 -0700 | [diff] [blame] | 3512 | // Iterate over the entry points. |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3513 | const struct loader_dev_ext_props *const property = &(extensions->list[extension]); |
| 3514 | for (uint32_t entry = 0; entry < property->entrypoint_count; ++entry) { |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 3515 | if (strcmp(property->entrypoints[entry], funcName) == 0) { |
Jeremy Hayes | 1eb1f62 | 2016-03-03 16:03:03 -0700 | [diff] [blame] | 3516 | return true; |
| 3517 | } |
| 3518 | } |
| 3519 | } |
| 3520 | } |
| 3521 | |
| 3522 | return false; |
| 3523 | } |
| 3524 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3525 | static void loader_free_dev_ext_table(struct loader_instance *inst) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3526 | for (uint32_t i = 0; i < MAX_NUM_UNKNOWN_EXTS; i++) { |
| 3527 | loader_instance_heap_free(inst, inst->dev_ext_disp_hash[i].func_name); |
| 3528 | loader_instance_heap_free(inst, inst->dev_ext_disp_hash[i].list.index); |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3529 | } |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3530 | memset(inst->dev_ext_disp_hash, 0, sizeof(inst->dev_ext_disp_hash)); |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3531 | } |
| 3532 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3533 | static bool loader_add_dev_ext_table(struct loader_instance *inst, uint32_t *ptr_idx, const char *funcName) { |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3534 | uint32_t i; |
| 3535 | uint32_t idx = *ptr_idx; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3536 | struct loader_dispatch_hash_list *list = &inst->dev_ext_disp_hash[idx].list; |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3537 | |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3538 | if (!inst->dev_ext_disp_hash[idx].func_name) { |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3539 | // no entry here at this idx, so use it |
| 3540 | assert(list->capacity == 0); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3541 | inst->dev_ext_disp_hash[idx].func_name = |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3542 | (char *)loader_instance_heap_alloc(inst, strlen(funcName) + 1, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3543 | if (inst->dev_ext_disp_hash[idx].func_name == NULL) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3544 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 3545 | "loader_add_dev_ext_table: Failed to allocate memory " |
| 3546 | "for func_name %s", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3547 | funcName); |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3548 | return false; |
| 3549 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3550 | strncpy(inst->dev_ext_disp_hash[idx].func_name, funcName, strlen(funcName) + 1); |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3551 | return true; |
| 3552 | } |
| 3553 | |
| 3554 | // check for enough capacity |
| 3555 | if (list->capacity == 0) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3556 | list->index = loader_instance_heap_alloc(inst, 8 * sizeof(*(list->index)), VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3557 | if (list->index == NULL) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3558 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 3559 | "loader_add_dev_ext_table: Failed to allocate memory " |
| 3560 | "for list index", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3561 | funcName); |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3562 | return false; |
| 3563 | } |
| 3564 | list->capacity = 8 * sizeof(*(list->index)); |
| 3565 | } else if (list->capacity < (list->count + 1) * sizeof(*(list->index))) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3566 | list->index = loader_instance_heap_realloc(inst, list->index, list->capacity, list->capacity * 2, |
| 3567 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3568 | if (list->index == NULL) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3569 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 3570 | "loader_add_dev_ext_table: Failed to reallocate memory " |
| 3571 | "for list index", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3572 | funcName); |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3573 | return false; |
| 3574 | } |
| 3575 | list->capacity *= 2; |
| 3576 | } |
| 3577 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3578 | // find an unused index in the hash table and use it |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3579 | i = (idx + 1) % MAX_NUM_UNKNOWN_EXTS; |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3580 | do { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3581 | if (!inst->dev_ext_disp_hash[i].func_name) { |
| 3582 | assert(inst->dev_ext_disp_hash[i].list.capacity == 0); |
| 3583 | inst->dev_ext_disp_hash[i].func_name = |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3584 | (char *)loader_instance_heap_alloc(inst, strlen(funcName) + 1, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3585 | if (inst->dev_ext_disp_hash[i].func_name == NULL) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3586 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 3587 | "loader_add_dev_ext_table: Failed to allocate memory " |
| 3588 | "for func_name %s", |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3589 | funcName); |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3590 | return false; |
| 3591 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3592 | strncpy(inst->dev_ext_disp_hash[i].func_name, funcName, strlen(funcName) + 1); |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3593 | list->index[list->count] = i; |
| 3594 | list->count++; |
| 3595 | *ptr_idx = i; |
| 3596 | return true; |
| 3597 | } |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3598 | i = (i + 1) % MAX_NUM_UNKNOWN_EXTS; |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3599 | } while (i != idx); |
| 3600 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3601 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 3602 | "loader_add_dev_ext_table: Could not insert into hash table; is " |
| 3603 | "it full?"); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3604 | |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3605 | return false; |
| 3606 | } |
| 3607 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3608 | static bool loader_name_in_dev_ext_table(struct loader_instance *inst, uint32_t *idx, const char *funcName) { |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3609 | uint32_t alt_idx; |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3610 | if (inst->dev_ext_disp_hash[*idx].func_name && !strcmp(inst->dev_ext_disp_hash[*idx].func_name, funcName)) return true; |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3611 | |
| 3612 | // funcName wasn't at the primary spot in the hash table |
| 3613 | // search the list of secondary locations (shallow search, not deep search) |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3614 | for (uint32_t i = 0; i < inst->dev_ext_disp_hash[*idx].list.count; i++) { |
| 3615 | alt_idx = inst->dev_ext_disp_hash[*idx].list.index[i]; |
| 3616 | if (!strcmp(inst->dev_ext_disp_hash[*idx].func_name, funcName)) { |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3617 | *idx = alt_idx; |
| 3618 | return true; |
| 3619 | } |
| 3620 | } |
| 3621 | |
| 3622 | return false; |
| 3623 | } |
| 3624 | |
| 3625 | /** |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3626 | * This function returns generic trampoline code address for unknown entry |
| 3627 | * points. |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3628 | * Presumably, these unknown entry points (as given by funcName) are device |
| 3629 | * extension entrypoints. A hash table is used to keep a list of unknown entry |
| 3630 | * points and their mapping to the device extension dispatch table |
| 3631 | * (struct loader_dev_ext_dispatch_table). |
| 3632 | * \returns |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3633 | * For a given entry point string (funcName), if an existing mapping is found |
| 3634 | * the |
| 3635 | * trampoline address for that mapping is returned. Otherwise, this unknown |
| 3636 | * entry point |
| 3637 | * has not been seen yet. Next check if a layer or ICD supports it. If so then |
| 3638 | * a |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3639 | * new entry in the hash table is initialized and that trampoline address for |
| 3640 | * the new entry is returned. Null is returned if the hash table is full or |
| 3641 | * if no discovered layer or ICD returns a non-NULL GetProcAddr for it. |
| 3642 | */ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3643 | void *loader_dev_ext_gpa(struct loader_instance *inst, const char *funcName) { |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3644 | uint32_t idx; |
| 3645 | uint32_t seed = 0; |
| 3646 | |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3647 | idx = murmurhash(funcName, strlen(funcName), seed) % MAX_NUM_UNKNOWN_EXTS; |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3648 | |
| 3649 | if (loader_name_in_dev_ext_table(inst, &idx, funcName)) |
| 3650 | // found funcName already in hash |
| 3651 | return loader_get_dev_ext_trampoline(idx); |
| 3652 | |
| 3653 | // Check if funcName is supported in either ICDs or a layer library |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3654 | if (!loader_check_icds_for_dev_ext_address(inst, funcName) && |
| 3655 | !loader_check_layer_list_for_dev_ext_address(&inst->instance_layer_list, funcName)) { |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 3656 | // if support found in layers continue on |
| 3657 | return NULL; |
| 3658 | } |
| 3659 | |
| 3660 | if (loader_add_dev_ext_table(inst, &idx, funcName)) { |
| 3661 | // successfully added new table entry |
| 3662 | // init any dev dispatch table entrys as needed |
| 3663 | loader_init_dispatch_dev_ext_entry(inst, NULL, idx, funcName); |
| 3664 | return loader_get_dev_ext_trampoline(idx); |
| 3665 | } |
| 3666 | |
| 3667 | return NULL; |
| 3668 | } |
| 3669 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3670 | static bool loader_check_icds_for_phys_dev_ext_address(struct loader_instance *inst, const char *funcName) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3671 | struct loader_icd_term *icd_term; |
| 3672 | icd_term = inst->icd_terms; |
| 3673 | while (NULL != icd_term) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3674 | if (icd_term->scanned_icd->interface_version >= MIN_PHYS_DEV_EXTENSION_ICD_INTERFACE_VERSION && |
| 3675 | icd_term->scanned_icd->GetPhysicalDeviceProcAddr(icd_term->instance, funcName)) |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3676 | // this icd supports funcName |
| 3677 | return true; |
| 3678 | icd_term = icd_term->next; |
| 3679 | } |
| 3680 | |
| 3681 | return false; |
| 3682 | } |
| 3683 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3684 | static bool loader_check_layer_list_for_phys_dev_ext_address(struct loader_instance *inst, const char *funcName) { |
| 3685 | struct loader_layer_properties *layer_prop_list = inst->activated_layer_list.list; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3686 | for (uint32_t layer = 0; layer < inst->activated_layer_list.count; ++layer) { |
| 3687 | // If this layer supports the vk_layerGetPhysicalDeviceProcAddr, then call |
| 3688 | // it and see if it returns a valid pointer for this function name. |
| 3689 | if (layer_prop_list[layer].interface_version > 1) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3690 | const struct loader_layer_functions *const functions = &(layer_prop_list[layer].functions); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3691 | if (NULL != functions->get_physical_device_proc_addr && |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3692 | NULL != functions->get_physical_device_proc_addr((VkInstance)inst, funcName)) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3693 | return true; |
| 3694 | } |
| 3695 | } |
| 3696 | } |
| 3697 | |
| 3698 | return false; |
| 3699 | } |
| 3700 | |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3701 | static void loader_free_phys_dev_ext_table(struct loader_instance *inst) { |
| 3702 | for (uint32_t i = 0; i < MAX_NUM_UNKNOWN_EXTS; i++) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3703 | loader_instance_heap_free(inst, inst->phys_dev_ext_disp_hash[i].func_name); |
| 3704 | loader_instance_heap_free(inst, inst->phys_dev_ext_disp_hash[i].list.index); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3705 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3706 | memset(inst->phys_dev_ext_disp_hash, 0, sizeof(inst->phys_dev_ext_disp_hash)); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3707 | } |
| 3708 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3709 | static bool loader_add_phys_dev_ext_table(struct loader_instance *inst, uint32_t *ptr_idx, const char *funcName) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3710 | uint32_t i; |
| 3711 | uint32_t idx = *ptr_idx; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3712 | struct loader_dispatch_hash_list *list = &inst->phys_dev_ext_disp_hash[idx].list; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3713 | |
| 3714 | if (!inst->phys_dev_ext_disp_hash[idx].func_name) { |
| 3715 | // no entry here at this idx, so use it |
| 3716 | assert(list->capacity == 0); |
| 3717 | inst->phys_dev_ext_disp_hash[idx].func_name = |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3718 | (char *)loader_instance_heap_alloc(inst, strlen(funcName) + 1, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3719 | if (inst->phys_dev_ext_disp_hash[idx].func_name == NULL) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3720 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 3721 | "loader_add_phys_dev_ext_table() can't allocate memory for " |
| 3722 | "func_name"); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3723 | return false; |
| 3724 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3725 | strncpy(inst->phys_dev_ext_disp_hash[idx].func_name, funcName, strlen(funcName) + 1); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3726 | return true; |
| 3727 | } |
| 3728 | |
| 3729 | // check for enough capacity |
| 3730 | if (list->capacity == 0) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3731 | list->index = loader_instance_heap_alloc(inst, 8 * sizeof(*(list->index)), VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3732 | if (list->index == NULL) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3733 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, "loader_add_phys_dev_ext_table() can't allocate list memory"); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3734 | return false; |
| 3735 | } |
| 3736 | list->capacity = 8 * sizeof(*(list->index)); |
| 3737 | } else if (list->capacity < (list->count + 1) * sizeof(*(list->index))) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3738 | list->index = loader_instance_heap_realloc(inst, list->index, list->capacity, list->capacity * 2, |
| 3739 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3740 | if (list->index == NULL) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3741 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, "loader_add_phys_dev_ext_table() can't reallocate list memory"); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3742 | return false; |
| 3743 | } |
| 3744 | list->capacity *= 2; |
| 3745 | } |
| 3746 | |
| 3747 | // find an unused index in the hash table and use it |
| 3748 | i = (idx + 1) % MAX_NUM_UNKNOWN_EXTS; |
| 3749 | do { |
| 3750 | if (!inst->phys_dev_ext_disp_hash[i].func_name) { |
| 3751 | assert(inst->phys_dev_ext_disp_hash[i].list.capacity == 0); |
| 3752 | inst->phys_dev_ext_disp_hash[i].func_name = |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3753 | (char *)loader_instance_heap_alloc(inst, strlen(funcName) + 1, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3754 | if (inst->phys_dev_ext_disp_hash[i].func_name == NULL) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3755 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 3756 | "loader_add_dev_ext_table() can't rallocate " |
| 3757 | "func_name memory"); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3758 | return false; |
| 3759 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3760 | strncpy(inst->phys_dev_ext_disp_hash[i].func_name, funcName, strlen(funcName) + 1); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3761 | list->index[list->count] = i; |
| 3762 | list->count++; |
| 3763 | *ptr_idx = i; |
| 3764 | return true; |
| 3765 | } |
| 3766 | i = (i + 1) % MAX_NUM_UNKNOWN_EXTS; |
| 3767 | } while (i != idx); |
| 3768 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3769 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 3770 | "loader_add_phys_dev_ext_table() couldn't insert into hash table; is " |
| 3771 | "it full?"); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3772 | return false; |
| 3773 | } |
| 3774 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3775 | static bool loader_name_in_phys_dev_ext_table(struct loader_instance *inst, uint32_t *idx, const char *funcName) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3776 | uint32_t alt_idx; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3777 | if (inst->phys_dev_ext_disp_hash[*idx].func_name && !strcmp(inst->phys_dev_ext_disp_hash[*idx].func_name, funcName)) |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3778 | return true; |
| 3779 | |
| 3780 | // funcName wasn't at the primary spot in the hash table |
| 3781 | // search the list of secondary locations (shallow search, not deep search) |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3782 | for (uint32_t i = 0; i < inst->phys_dev_ext_disp_hash[*idx].list.count; i++) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3783 | alt_idx = inst->phys_dev_ext_disp_hash[*idx].list.index[i]; |
| 3784 | if (!strcmp(inst->phys_dev_ext_disp_hash[*idx].func_name, funcName)) { |
| 3785 | *idx = alt_idx; |
| 3786 | return true; |
| 3787 | } |
| 3788 | } |
| 3789 | |
| 3790 | return false; |
| 3791 | } |
| 3792 | |
| 3793 | // This function returns a generic trampoline and/or terminator function |
| 3794 | // address for any unknown physical device extension commands. A hash |
| 3795 | // table is used to keep a list of unknown entry points and their |
| 3796 | // mapping to the physical device extension dispatch table (struct |
| 3797 | // loader_phys_dev_ext_dispatch_table). |
| 3798 | // For a given entry point string (funcName), if an existing mapping is |
| 3799 | // found, then the trampoline address for that mapping is returned in |
| 3800 | // tramp_addr (if it is not NULL) and the terminator address for that |
| 3801 | // mapping is returned in term_addr (if it is not NULL). Otherwise, |
| 3802 | // this unknown entry point has not been seen yet. |
| 3803 | // If it has not been seen before, and perform_checking is 'true', |
| 3804 | // check if a layer or and ICD supports it. If so then a new entry in |
| 3805 | // the hash table is initialized and the trampoline and/or terminator |
| 3806 | // addresses are returned. |
| 3807 | // Null is returned if the hash table is full or if no discovered layer or |
| 3808 | // ICD returns a non-NULL GetProcAddr for it. |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3809 | bool loader_phys_dev_ext_gpa(struct loader_instance *inst, const char *funcName, bool perform_checking, void **tramp_addr, |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3810 | void **term_addr) { |
| 3811 | uint32_t idx; |
| 3812 | uint32_t seed = 0; |
| 3813 | bool success = false; |
| 3814 | |
| 3815 | if (inst == NULL) { |
| 3816 | goto out; |
| 3817 | } |
| 3818 | |
| 3819 | if (NULL != tramp_addr) { |
| 3820 | *tramp_addr = NULL; |
| 3821 | } |
| 3822 | if (NULL != term_addr) { |
| 3823 | *term_addr = NULL; |
| 3824 | } |
| 3825 | |
| 3826 | // We should always check to see if any ICD supports it. |
| 3827 | if (!loader_check_icds_for_phys_dev_ext_address(inst, funcName)) { |
| 3828 | // If we're not checking layers, or we are and it's not in a layer, just |
| 3829 | // return |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3830 | if (!perform_checking || !loader_check_layer_list_for_phys_dev_ext_address(inst, funcName)) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3831 | goto out; |
| 3832 | } |
| 3833 | } |
| 3834 | |
| 3835 | idx = murmurhash(funcName, strlen(funcName), seed) % MAX_NUM_UNKNOWN_EXTS; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3836 | if (perform_checking && !loader_name_in_phys_dev_ext_table(inst, &idx, funcName)) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3837 | uint32_t i; |
| 3838 | bool added = false; |
| 3839 | |
| 3840 | // Only need to add first one to get index in Instance. Others will use |
| 3841 | // the same index. |
| 3842 | if (!added && loader_add_phys_dev_ext_table(inst, &idx, funcName)) { |
| 3843 | added = true; |
| 3844 | } |
| 3845 | |
| 3846 | // Setup the ICD function pointers |
| 3847 | struct loader_icd_term *icd_term = inst->icd_terms; |
| 3848 | while (NULL != icd_term) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3849 | if (MIN_PHYS_DEV_EXTENSION_ICD_INTERFACE_VERSION <= icd_term->scanned_icd->interface_version && |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3850 | NULL != icd_term->scanned_icd->GetPhysicalDeviceProcAddr) { |
| 3851 | icd_term->phys_dev_ext[idx] = |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3852 | (PFN_PhysDevExt)icd_term->scanned_icd->GetPhysicalDeviceProcAddr(icd_term->instance, funcName); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3853 | |
| 3854 | // Make sure we set the instance dispatch to point to the |
| 3855 | // loader's terminator now since we can at least handle it |
| 3856 | // in one ICD. |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3857 | inst->disp->phys_dev_ext[idx] = loader_get_phys_dev_ext_termin(idx); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3858 | } else { |
| 3859 | icd_term->phys_dev_ext[idx] = NULL; |
| 3860 | } |
| 3861 | |
| 3862 | icd_term = icd_term->next; |
| 3863 | } |
| 3864 | |
| 3865 | // Now, search for the first layer attached and query using it to get |
| 3866 | // the first entry point. |
| 3867 | for (i = 0; i < inst->activated_layer_list.count; i++) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3868 | struct loader_layer_properties *layer_prop = &inst->activated_layer_list.list[i]; |
| 3869 | if (layer_prop->interface_version > 1 && NULL != layer_prop->functions.get_physical_device_proc_addr) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3870 | inst->disp->phys_dev_ext[idx] = |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3871 | (PFN_PhysDevExt)layer_prop->functions.get_physical_device_proc_addr((VkInstance)inst, funcName); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3872 | if (NULL != inst->disp->phys_dev_ext[idx]) { |
| 3873 | break; |
| 3874 | } |
| 3875 | } |
| 3876 | } |
| 3877 | } |
| 3878 | |
| 3879 | if (NULL != tramp_addr) { |
| 3880 | *tramp_addr = loader_get_phys_dev_ext_tramp(idx); |
| 3881 | } |
| 3882 | |
| 3883 | if (NULL != term_addr) { |
| 3884 | *term_addr = loader_get_phys_dev_ext_termin(idx); |
| 3885 | } |
| 3886 | |
| 3887 | success = true; |
| 3888 | |
| 3889 | out: |
| 3890 | return success; |
| 3891 | } |
| 3892 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3893 | struct loader_instance *loader_get_instance(const VkInstance instance) { |
Jon Ashburn | e0e6457 | 2015-09-30 12:56:42 -0600 | [diff] [blame] | 3894 | /* look up the loader_instance in our list by comparing dispatch tables, as |
| 3895 | * there is no guarantee the instance is still a loader_instance* after any |
| 3896 | * layers which wrap the instance object. |
| 3897 | */ |
| 3898 | const VkLayerInstanceDispatchTable *disp; |
| 3899 | struct loader_instance *ptr_instance = NULL; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3900 | disp = loader_get_instance_layer_dispatch(instance); |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3901 | for (struct loader_instance *inst = loader.instances; inst; inst = inst->next) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3902 | if (&inst->disp->layer_inst_disp == disp) { |
Jon Ashburn | e0e6457 | 2015-09-30 12:56:42 -0600 | [diff] [blame] | 3903 | ptr_instance = inst; |
| 3904 | break; |
| 3905 | } |
| 3906 | } |
| 3907 | return ptr_instance; |
| 3908 | } |
| 3909 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3910 | static loader_platform_dl_handle loader_open_layer_lib(const struct loader_instance *inst, const char *chain_type, |
| 3911 | struct loader_layer_properties *prop) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3912 | if ((prop->lib_handle = loader_platform_open_library(prop->lib_name)) == NULL) { |
| 3913 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, "loader_open_layer_lib: Failed to open library %s", prop->lib_name); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3914 | } else { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3915 | loader_log(inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, "Loading layer library %s", prop->lib_name); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3916 | } |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3917 | |
Jon Ashburn | 4dc1d8a | 2016-04-20 13:21:17 -0600 | [diff] [blame] | 3918 | return prop->lib_handle; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3919 | } |
| 3920 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3921 | static void loader_close_layer_lib(const struct loader_instance *inst, struct loader_layer_properties *prop) { |
Jon Ashburn | 4dc1d8a | 2016-04-20 13:21:17 -0600 | [diff] [blame] | 3922 | if (prop->lib_handle) { |
| 3923 | loader_platform_close_library(prop->lib_handle); |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3924 | loader_log(inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, "Unloading layer library %s", prop->lib_name); |
Jon Ashburn | 4dc1d8a | 2016-04-20 13:21:17 -0600 | [diff] [blame] | 3925 | prop->lib_handle = NULL; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 3926 | } |
Jon Ashburn | 4dc1d8a | 2016-04-20 13:21:17 -0600 | [diff] [blame] | 3927 | } |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 3928 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3929 | void loader_deactivate_layers(const struct loader_instance *instance, struct loader_device *device, |
Jon Ashburn | 4dc1d8a | 2016-04-20 13:21:17 -0600 | [diff] [blame] | 3930 | struct loader_layer_list *list) { |
| 3931 | /* delete instance list of enabled layers and close any layer libraries */ |
| 3932 | for (uint32_t i = 0; i < list->count; i++) { |
| 3933 | struct loader_layer_properties *layer_prop = &list->list[i]; |
Courtney Goeltzenleuchter | 80bfd0e | 2015-12-17 09:51:22 -0700 | [diff] [blame] | 3934 | |
Jon Ashburn | 4dc1d8a | 2016-04-20 13:21:17 -0600 | [diff] [blame] | 3935 | loader_close_layer_lib(instance, layer_prop); |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 3936 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3937 | loader_destroy_layer_list(instance, device, list); |
Jon Ashburn | b835805 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 3938 | } |
| 3939 | |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 3940 | /** |
| 3941 | * Go through the search_list and find any layers which match type. If layer |
| 3942 | * type match is found in then add it to ext_list. |
| 3943 | */ |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3944 | static void loader_add_layer_implicit(const struct loader_instance *inst, const enum layer_type type, |
| 3945 | struct loader_layer_list *list, const struct loader_layer_list *search_list) { |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3946 | bool enable; |
| 3947 | char *env_value; |
Jon Ashburn | 0c26e71 | 2015-07-02 16:10:32 -0600 | [diff] [blame] | 3948 | uint32_t i; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 3949 | for (i = 0; i < search_list->count; i++) { |
| 3950 | const struct loader_layer_properties *prop = &search_list->list[i]; |
Jon Ashburn | 0c26e71 | 2015-07-02 16:10:32 -0600 | [diff] [blame] | 3951 | if (prop->type & type) { |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3952 | /* Found an implicit layer, see if it should be enabled */ |
| 3953 | enable = false; |
| 3954 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3955 | // if no enable_environment variable is specified, this implicit |
| 3956 | // layer |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3957 | // should always be enabled. Otherwise check if the variable is set |
| 3958 | if (prop->enable_env_var.name[0] == 0) { |
| 3959 | enable = true; |
| 3960 | } else { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3961 | env_value = loader_getenv(prop->enable_env_var.name, inst); |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3962 | if (env_value && !strcmp(prop->enable_env_var.value, env_value)) enable = true; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3963 | loader_free_getenv(env_value, inst); |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3964 | } |
| 3965 | |
| 3966 | // disable_environment has priority, i.e. if both enable and disable |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3967 | // environment variables are set, the layer is disabled. Implicit |
| 3968 | // layers |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3969 | // are required to have a disable_environment variables |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3970 | env_value = loader_getenv(prop->disable_env_var.name, inst); |
| 3971 | if (env_value) { |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3972 | enable = false; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3973 | } |
| 3974 | loader_free_getenv(env_value, inst); |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3975 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3976 | if (enable) { |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3977 | loader_add_to_layer_list(inst, list, 1, prop); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3978 | } |
Jon Ashburn | 0c26e71 | 2015-07-02 16:10:32 -0600 | [diff] [blame] | 3979 | } |
| 3980 | } |
Jon Ashburn | 0c26e71 | 2015-07-02 16:10:32 -0600 | [diff] [blame] | 3981 | } |
| 3982 | |
| 3983 | /** |
| 3984 | * 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] | 3985 | * is found in search_list then add it to layer_list. But only add it to |
| 3986 | * layer_list if type matches. |
Jon Ashburn | 0c26e71 | 2015-07-02 16:10:32 -0600 | [diff] [blame] | 3987 | */ |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3988 | static void loader_add_layer_env(struct loader_instance *inst, const enum layer_type type, const char *env_name, |
| 3989 | struct loader_layer_list *layer_list, const struct loader_layer_list *search_list) { |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 3990 | char *layerEnv; |
Jon Ashburn | eb6d568 | 2015-07-02 14:10:53 -0600 | [diff] [blame] | 3991 | char *next, *name; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 3992 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3993 | layerEnv = loader_getenv(env_name, inst); |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 3994 | if (layerEnv == NULL) { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3995 | return; |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 3996 | } |
Courtney Goeltzenleuchter | 7f5aafc | 2015-07-05 11:28:29 -0600 | [diff] [blame] | 3997 | name = loader_stack_alloc(strlen(layerEnv) + 1); |
Jon Ashburn | eb6d568 | 2015-07-02 14:10:53 -0600 | [diff] [blame] | 3998 | if (name == NULL) { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3999 | return; |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 4000 | } |
Jon Ashburn | eb6d568 | 2015-07-02 14:10:53 -0600 | [diff] [blame] | 4001 | strcpy(name, layerEnv); |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 4002 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4003 | loader_free_getenv(layerEnv, inst); |
Jon Ashburn | 38a497f | 2016-01-04 14:01:38 -0700 | [diff] [blame] | 4004 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4005 | while (name && *name) { |
Jon Ashburn | eb6d568 | 2015-07-02 14:10:53 -0600 | [diff] [blame] | 4006 | next = loader_get_next_path(name); |
Jon Ashburn | 7148344 | 2016-02-11 18:59:43 -0700 | [diff] [blame] | 4007 | if (!strcmp(std_validation_str, name)) { |
| 4008 | /* add meta list of layers |
| 4009 | don't attempt to remove duplicate layers already added by app or |
| 4010 | env var |
| 4011 | */ |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4012 | loader_log(inst, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, "Expanding meta layer %s found in environment variable", |
Jon Ashburn | 7148344 | 2016-02-11 18:59:43 -0700 | [diff] [blame] | 4013 | std_validation_str); |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 4014 | if (type == VK_LAYER_TYPE_INSTANCE_EXPLICIT) inst->activated_layers_are_std_val = true; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4015 | for (uint32_t i = 0; i < sizeof(std_validation_names) / sizeof(std_validation_names[0]); i++) { |
| 4016 | loader_find_layer_name_add_list(inst, std_validation_names[i], type, search_list, layer_list); |
Jon Ashburn | 7148344 | 2016-02-11 18:59:43 -0700 | [diff] [blame] | 4017 | } |
| 4018 | } else { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4019 | loader_find_layer_name_add_list(inst, name, type, search_list, layer_list); |
Jon Ashburn | 7148344 | 2016-02-11 18:59:43 -0700 | [diff] [blame] | 4020 | } |
Jon Ashburn | eb6d568 | 2015-07-02 14:10:53 -0600 | [diff] [blame] | 4021 | name = next; |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 4022 | } |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 4023 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 4024 | return; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 4025 | } |
| 4026 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4027 | VkResult loader_enable_instance_layers(struct loader_instance *inst, const VkInstanceCreateInfo *pCreateInfo, |
| 4028 | const struct loader_layer_list *instance_layers) { |
Courtney Goeltzenleuchter | 40caf0b | 2015-07-06 09:06:34 -0600 | [diff] [blame] | 4029 | VkResult err; |
| 4030 | |
Courtney Goeltzenleuchter | 55659b7 | 2015-09-14 18:01:17 -0600 | [diff] [blame] | 4031 | assert(inst && "Cannot have null instance"); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 4032 | |
Jon Ashburn | e39a4f8 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 4033 | if (!loader_init_layer_list(inst, &inst->activated_layer_list)) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 4034 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4035 | "loader_enable_instance_layers: Failed to initialize" |
| 4036 | " the layer list"); |
Courtney Goeltzenleuchter | 40caf0b | 2015-07-06 09:06:34 -0600 | [diff] [blame] | 4037 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Jon Ashburn | bd6c488 | 2015-07-02 12:59:25 -0600 | [diff] [blame] | 4038 | } |
| 4039 | |
Jon Ashburn | 0c26e71 | 2015-07-02 16:10:32 -0600 | [diff] [blame] | 4040 | /* Add any implicit layers first */ |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4041 | loader_add_layer_implicit(inst, VK_LAYER_TYPE_INSTANCE_IMPLICIT, &inst->activated_layer_list, instance_layers); |
Jon Ashburn | 0c26e71 | 2015-07-02 16:10:32 -0600 | [diff] [blame] | 4042 | |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 4043 | /* Add any layers specified via environment variable next */ |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4044 | loader_add_layer_env(inst, VK_LAYER_TYPE_INSTANCE_EXPLICIT, "VK_INSTANCE_LAYERS", &inst->activated_layer_list, instance_layers); |
Jon Ashburn | bd6c488 | 2015-07-02 12:59:25 -0600 | [diff] [blame] | 4045 | |
| 4046 | /* Add layers specified by the application */ |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4047 | err = loader_add_layer_names_to_list(inst, &inst->activated_layer_list, pCreateInfo->enabledLayerCount, |
| 4048 | pCreateInfo->ppEnabledLayerNames, instance_layers); |
Courtney Goeltzenleuchter | 40caf0b | 2015-07-06 09:06:34 -0600 | [diff] [blame] | 4049 | |
| 4050 | return err; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 4051 | } |
| 4052 | |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4053 | // Determine the layer interface version to use. |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4054 | bool loader_get_layer_interface_version(PFN_vkNegotiateLoaderLayerInterfaceVersion fp_negotiate_layer_version, |
| 4055 | VkNegotiateLayerInterface *interface_struct) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4056 | memset(interface_struct, 0, sizeof(VkNegotiateLayerInterface)); |
| 4057 | |
| 4058 | // Base assumption is that all layers are version 1 at least. |
| 4059 | interface_struct->loaderLayerInterfaceVersion = 1; |
| 4060 | |
| 4061 | if (fp_negotiate_layer_version != NULL) { |
| 4062 | // Layer supports the negotiation API, so call it with the loader's |
| 4063 | // latest version supported |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4064 | interface_struct->loaderLayerInterfaceVersion = CURRENT_LOADER_LAYER_INTERFACE_VERSION; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4065 | VkResult result = fp_negotiate_layer_version(interface_struct); |
| 4066 | |
| 4067 | if (result != VK_SUCCESS) { |
| 4068 | // Layer no longer supports the loader's latest interface version so |
| 4069 | // fail loading the Layer |
| 4070 | return false; |
| 4071 | } |
| 4072 | } |
| 4073 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4074 | if (interface_struct->loaderLayerInterfaceVersion < MIN_SUPPORTED_LOADER_LAYER_INTERFACE_VERSION) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4075 | // Loader no longer supports the layer's latest interface version so |
| 4076 | // fail loading the layer |
| 4077 | return false; |
| 4078 | } |
| 4079 | |
| 4080 | return true; |
| 4081 | } |
| 4082 | |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4083 | /* |
| 4084 | * Given the list of layers to activate in the loader_instance |
| 4085 | * structure. This function will add a VkLayerInstanceCreateInfo |
| 4086 | * structure to the VkInstanceCreateInfo.pNext pointer. |
| 4087 | * Each activated layer will have it's own VkLayerInstanceLink |
| 4088 | * structure that tells the layer what Get*ProcAddr to call to |
| 4089 | * get function pointers to the next layer down. |
| 4090 | * Once the chain info has been created this function will |
| 4091 | * execute the CreateInstance call chain. Each layer will |
| 4092 | * then have an opportunity in it's CreateInstance function |
| 4093 | * to setup it's dispatch table when the lower layer returns |
| 4094 | * successfully. |
| 4095 | * Each layer can wrap or not-wrap the returned VkInstance object |
| 4096 | * as it sees fit. |
| 4097 | * The instance chain is terminated by a loader function |
| 4098 | * that will call CreateInstance on all available ICD's and |
| 4099 | * cache those VkInstance objects for future use. |
| 4100 | */ |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4101 | VkResult loader_create_instance_chain(const VkInstanceCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator, |
| 4102 | struct loader_instance *inst, VkInstance *created_instance) { |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4103 | uint32_t activated_layers = 0; |
| 4104 | VkLayerInstanceCreateInfo chain_info; |
| 4105 | VkLayerInstanceLink *layer_instance_link_info = NULL; |
| 4106 | VkInstanceCreateInfo loader_create_info; |
| 4107 | VkResult res; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 4108 | |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4109 | PFN_vkGetInstanceProcAddr next_gipa = loader_gpa_instance_internal; |
| 4110 | PFN_vkGetInstanceProcAddr cur_gipa = loader_gpa_instance_internal; |
| 4111 | PFN_GetPhysicalDeviceProcAddr next_gpdpa = loader_gpdpa_instance_internal; |
| 4112 | PFN_GetPhysicalDeviceProcAddr cur_gpdpa = loader_gpdpa_instance_internal; |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 4113 | |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4114 | memcpy(&loader_create_info, pCreateInfo, sizeof(VkInstanceCreateInfo)); |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 4115 | |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4116 | if (inst->activated_layer_list.count > 0) { |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4117 | chain_info.u.pLayerInfo = NULL; |
| 4118 | chain_info.pNext = pCreateInfo->pNext; |
| 4119 | chain_info.sType = VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO; |
| 4120 | chain_info.function = VK_LAYER_LINK_INFO; |
| 4121 | loader_create_info.pNext = &chain_info; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 4122 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4123 | layer_instance_link_info = loader_stack_alloc(sizeof(VkLayerInstanceLink) * inst->activated_layer_list.count); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4124 | if (!layer_instance_link_info) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 4125 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4126 | "loader_create_instance_chain: Failed to alloc Instance" |
| 4127 | " objects for layer"); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4128 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 4129 | } |
| 4130 | |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4131 | // Create instance chain of enabled layers |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4132 | for (int32_t i = inst->activated_layer_list.count - 1; i >= 0; i--) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4133 | struct loader_layer_properties *layer_prop = &inst->activated_layer_list.list[i]; |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4134 | loader_platform_dl_handle lib_handle; |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 4135 | |
Jon Ashburn | 4dc1d8a | 2016-04-20 13:21:17 -0600 | [diff] [blame] | 4136 | lib_handle = loader_open_layer_lib(inst, "instance", layer_prop); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4137 | if (!lib_handle) { |
Courtney Goeltzenleuchter | 524b7e3 | 2016-01-14 16:06:06 -0700 | [diff] [blame] | 4138 | continue; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4139 | } |
| 4140 | |
| 4141 | if (NULL == layer_prop->functions.negotiate_layer_interface) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4142 | PFN_vkNegotiateLoaderLayerInterfaceVersion negotiate_interface = NULL; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4143 | bool functions_in_interface = false; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4144 | if (strlen(layer_prop->functions.str_negotiate_interface) == 0) { |
| 4145 | negotiate_interface = (PFN_vkNegotiateLoaderLayerInterfaceVersion)loader_platform_get_proc_address( |
| 4146 | lib_handle, "vkNegotiateLoaderLayerInterfaceVersion"); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4147 | } else { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4148 | negotiate_interface = (PFN_vkNegotiateLoaderLayerInterfaceVersion)loader_platform_get_proc_address( |
| 4149 | lib_handle, layer_prop->functions.str_negotiate_interface); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4150 | } |
| 4151 | |
| 4152 | // If we can negotiate an interface version, then we can also |
| 4153 | // get everything we need from the one function call, so try |
| 4154 | // that first, and see if we can get all the function pointers |
| 4155 | // necessary from that one call. |
| 4156 | if (NULL != negotiate_interface) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4157 | layer_prop->functions.negotiate_layer_interface = negotiate_interface; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4158 | |
| 4159 | VkNegotiateLayerInterface interface_struct; |
| 4160 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4161 | if (loader_get_layer_interface_version(negotiate_interface, &interface_struct)) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4162 | // Go ahead and set the properites version to the |
| 4163 | // correct value. |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4164 | layer_prop->interface_version = interface_struct.loaderLayerInterfaceVersion; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4165 | |
| 4166 | // If the interface is 2 or newer, we have access to the |
| 4167 | // new GetPhysicalDeviceProcAddr function, so grab it, |
| 4168 | // and the other necessary functions, from the |
| 4169 | // structure. |
| 4170 | if (interface_struct.loaderLayerInterfaceVersion > 1) { |
| 4171 | cur_gipa = interface_struct.pfnGetInstanceProcAddr; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4172 | cur_gpdpa = interface_struct.pfnGetPhysicalDeviceProcAddr; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4173 | if (cur_gipa != NULL) { |
| 4174 | // We've set the functions, so make sure we |
| 4175 | // don't do the unnecessary calls later. |
| 4176 | functions_in_interface = true; |
| 4177 | } |
| 4178 | } |
| 4179 | } |
| 4180 | } |
| 4181 | |
| 4182 | if (!functions_in_interface) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4183 | if ((cur_gipa = layer_prop->functions.get_instance_proc_addr) == NULL) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4184 | if (strlen(layer_prop->functions.str_gipa) == 0) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4185 | cur_gipa = |
| 4186 | (PFN_vkGetInstanceProcAddr)loader_platform_get_proc_address(lib_handle, "vkGetInstanceProcAddr"); |
| 4187 | layer_prop->functions.get_instance_proc_addr = cur_gipa; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4188 | } else { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4189 | cur_gipa = (PFN_vkGetInstanceProcAddr)loader_platform_get_proc_address(lib_handle, |
| 4190 | layer_prop->functions.str_gipa); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4191 | } |
| 4192 | |
| 4193 | if (NULL == cur_gipa) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 4194 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4195 | "loader_create_instance_chain: Failed to" |
| 4196 | " find \'vkGetInstanceProcAddr\' in " |
| 4197 | "layer %s", |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4198 | layer_prop->lib_name); |
| 4199 | continue; |
| 4200 | } |
| 4201 | } |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4202 | } |
| 4203 | } |
| 4204 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4205 | layer_instance_link_info[activated_layers].pNext = chain_info.u.pLayerInfo; |
| 4206 | layer_instance_link_info[activated_layers].pfnNextGetInstanceProcAddr = next_gipa; |
| 4207 | layer_instance_link_info[activated_layers].pfnNextGetPhysicalDeviceProcAddr = next_gpdpa; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4208 | next_gipa = cur_gipa; |
| 4209 | if (layer_prop->interface_version > 1 && cur_gpdpa != NULL) { |
| 4210 | layer_prop->functions.get_physical_device_proc_addr = cur_gpdpa; |
| 4211 | next_gpdpa = cur_gpdpa; |
| 4212 | } |
| 4213 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4214 | chain_info.u.pLayerInfo = &layer_instance_link_info[activated_layers]; |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4215 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4216 | loader_log(inst, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, "Insert instance layer %s (%s)", layer_prop->info.layerName, |
| 4217 | layer_prop->lib_name); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4218 | |
| 4219 | activated_layers++; |
| 4220 | } |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 4221 | } |
| 4222 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4223 | PFN_vkCreateInstance fpCreateInstance = (PFN_vkCreateInstance)next_gipa(*created_instance, "vkCreateInstance"); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4224 | if (fpCreateInstance) { |
Jon Ashburn | c3c5877 | 2016-03-29 11:16:01 -0600 | [diff] [blame] | 4225 | VkLayerInstanceCreateInfo create_info_disp; |
| 4226 | |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 4227 | create_info_disp.sType = VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO; |
Jon Ashburn | ed8f231 | 2016-03-31 10:52:22 -0600 | [diff] [blame] | 4228 | create_info_disp.function = VK_LOADER_DATA_CALLBACK; |
Jon Ashburn | c3c5877 | 2016-03-29 11:16:01 -0600 | [diff] [blame] | 4229 | |
| 4230 | create_info_disp.u.pfnSetInstanceLoaderData = vkSetInstanceDispatch; |
| 4231 | |
| 4232 | create_info_disp.pNext = loader_create_info.pNext; |
| 4233 | loader_create_info.pNext = &create_info_disp; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4234 | res = fpCreateInstance(&loader_create_info, pAllocator, created_instance); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4235 | } else { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 4236 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4237 | "loader_create_instance_chain: Failed to find " |
| 4238 | "\'vkCreateInstance\'"); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4239 | // Couldn't find CreateInstance function! |
| 4240 | res = VK_ERROR_INITIALIZATION_FAILED; |
| 4241 | } |
| 4242 | |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4243 | if (res == VK_SUCCESS) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4244 | loader_init_instance_core_dispatch_table(&inst->disp->layer_inst_disp, next_gipa, *created_instance); |
Jon Ashburn | 4e8c416 | 2016-03-08 15:21:30 -0700 | [diff] [blame] | 4245 | inst->instance = *created_instance; |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4246 | } |
| 4247 | |
| 4248 | return res; |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 4249 | } |
| 4250 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4251 | void loader_activate_instance_layer_extensions(struct loader_instance *inst, VkInstance created_inst) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4252 | loader_init_instance_extension_dispatch_table(&inst->disp->layer_inst_disp, inst->disp->layer_inst_disp.GetInstanceProcAddr, |
| 4253 | created_inst); |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 4254 | } |
| 4255 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4256 | VkResult loader_create_device_chain(const struct loader_physical_device_tramp *pd, const VkDeviceCreateInfo *pCreateInfo, |
| 4257 | const VkAllocationCallbacks *pAllocator, const struct loader_instance *inst, |
| 4258 | struct loader_device *dev) { |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4259 | uint32_t activated_layers = 0; |
| 4260 | VkLayerDeviceLink *layer_device_link_info; |
| 4261 | VkLayerDeviceCreateInfo chain_info; |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4262 | VkDeviceCreateInfo loader_create_info; |
| 4263 | VkResult res; |
Courtney Goeltzenleuchter | ca173b8 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 4264 | |
Piers Daniell | 295fe40 | 2016-03-29 11:51:11 -0600 | [diff] [blame] | 4265 | PFN_vkGetDeviceProcAddr fpGDPA, nextGDPA = loader_gpa_device_internal; |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4266 | PFN_vkGetInstanceProcAddr fpGIPA, nextGIPA = loader_gpa_instance_internal; |
Courtney Goeltzenleuchter | ca173b8 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 4267 | |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4268 | memcpy(&loader_create_info, pCreateInfo, sizeof(VkDeviceCreateInfo)); |
| 4269 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4270 | layer_device_link_info = loader_stack_alloc(sizeof(VkLayerDeviceLink) * dev->activated_layer_list.count); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4271 | if (!layer_device_link_info) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 4272 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4273 | "loader_create_device_chain: Failed to alloc Device objects" |
| 4274 | " for layer. Skipping Layer."); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4275 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
David Pinedo | a0a8a24 | 2015-06-24 15:29:18 -0600 | [diff] [blame] | 4276 | } |
Jon Ashburn | 94e7049 | 2015-06-10 10:13:10 -0600 | [diff] [blame] | 4277 | |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4278 | if (dev->activated_layer_list.count > 0) { |
Jon Ashburn | 72690f2 | 2016-03-29 12:52:13 -0600 | [diff] [blame] | 4279 | chain_info.sType = VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO; |
| 4280 | chain_info.function = VK_LAYER_LINK_INFO; |
| 4281 | chain_info.u.pLayerInfo = NULL; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4282 | chain_info.pNext = loader_create_info.pNext; |
Jon Ashburn | 72690f2 | 2016-03-29 12:52:13 -0600 | [diff] [blame] | 4283 | loader_create_info.pNext = &chain_info; |
| 4284 | |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4285 | // Create instance chain of enabled layers |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4286 | for (int32_t i = dev->activated_layer_list.count - 1; i >= 0; i--) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4287 | struct loader_layer_properties *layer_prop = &dev->activated_layer_list.list[i]; |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4288 | loader_platform_dl_handle lib_handle; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4289 | bool functions_in_interface = false; |
Courtney Goeltzenleuchter | ca173b8 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 4290 | |
Jon Ashburn | 4dc1d8a | 2016-04-20 13:21:17 -0600 | [diff] [blame] | 4291 | lib_handle = loader_open_layer_lib(inst, "device", layer_prop); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4292 | if (!lib_handle) { |
Courtney Goeltzenleuchter | 524b7e3 | 2016-01-14 16:06:06 -0700 | [diff] [blame] | 4293 | continue; |
Jon Ashburn | 21c21ee | 2015-09-09 11:29:24 -0600 | [diff] [blame] | 4294 | } |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4295 | |
| 4296 | // If we can negotiate an interface version, then we can also |
| 4297 | // get everything we need from the one function call, so try |
| 4298 | // that first, and see if we can get all the function pointers |
| 4299 | // necessary from that one call. |
| 4300 | if (NULL == layer_prop->functions.negotiate_layer_interface) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4301 | PFN_vkNegotiateLoaderLayerInterfaceVersion negotiate_interface = NULL; |
| 4302 | if (strlen(layer_prop->functions.str_negotiate_interface) == 0) { |
| 4303 | negotiate_interface = (PFN_vkNegotiateLoaderLayerInterfaceVersion)loader_platform_get_proc_address( |
| 4304 | lib_handle, "vkNegotiateLoaderLayerInterfaceVersion"); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4305 | } else { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4306 | negotiate_interface = (PFN_vkNegotiateLoaderLayerInterfaceVersion)loader_platform_get_proc_address( |
| 4307 | lib_handle, layer_prop->functions.str_negotiate_interface); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4308 | } |
| 4309 | |
| 4310 | if (NULL != negotiate_interface) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4311 | layer_prop->functions.negotiate_layer_interface = negotiate_interface; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4312 | |
| 4313 | VkNegotiateLayerInterface interface_struct; |
| 4314 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4315 | if (loader_get_layer_interface_version(negotiate_interface, &interface_struct)) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4316 | // Go ahead and set the properites version to the |
| 4317 | // correct value. |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4318 | layer_prop->interface_version = interface_struct.loaderLayerInterfaceVersion; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4319 | |
| 4320 | // If the interface is 2 or newer, we have access to the |
| 4321 | // new GetPhysicalDeviceProcAddr function, so grab it, |
| 4322 | // and the other necessary functions, from the structure. |
| 4323 | if (interface_struct.loaderLayerInterfaceVersion > 1) { |
| 4324 | fpGIPA = interface_struct.pfnGetInstanceProcAddr; |
| 4325 | fpGDPA = interface_struct.pfnGetDeviceProcAddr; |
| 4326 | if (fpGIPA != NULL && fpGDPA) { |
| 4327 | // We've set the functions, so make sure we |
| 4328 | // don't do the unnecessary calls later. |
| 4329 | functions_in_interface = true; |
| 4330 | } |
| 4331 | } |
| 4332 | } |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4333 | } |
| 4334 | } |
| 4335 | |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4336 | if (!functions_in_interface) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4337 | if ((fpGIPA = layer_prop->functions.get_instance_proc_addr) == NULL) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4338 | if (strlen(layer_prop->functions.str_gipa) == 0) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4339 | fpGIPA = (PFN_vkGetInstanceProcAddr)loader_platform_get_proc_address(lib_handle, "vkGetInstanceProcAddr"); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4340 | layer_prop->functions.get_instance_proc_addr = fpGIPA; |
| 4341 | } else |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4342 | fpGIPA = |
| 4343 | (PFN_vkGetInstanceProcAddr)loader_platform_get_proc_address(lib_handle, layer_prop->functions.str_gipa); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4344 | if (!fpGIPA) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 4345 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4346 | "loader_create_device_chain: Failed to find " |
| 4347 | "\'vkGetInstanceProcAddr\' in layer %s. Skipping" |
| 4348 | " layer.", |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4349 | layer_prop->lib_name); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4350 | continue; |
| 4351 | } |
| 4352 | } |
| 4353 | if ((fpGDPA = layer_prop->functions.get_device_proc_addr) == NULL) { |
| 4354 | if (strlen(layer_prop->functions.str_gdpa) == 0) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4355 | fpGDPA = (PFN_vkGetDeviceProcAddr)loader_platform_get_proc_address(lib_handle, "vkGetDeviceProcAddr"); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4356 | layer_prop->functions.get_device_proc_addr = fpGDPA; |
| 4357 | } else |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4358 | fpGDPA = |
| 4359 | (PFN_vkGetDeviceProcAddr)loader_platform_get_proc_address(lib_handle, layer_prop->functions.str_gdpa); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4360 | if (!fpGDPA) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4361 | loader_log(inst, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, "Failed to find vkGetDeviceProcAddr in layer %s", |
| 4362 | layer_prop->lib_name); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4363 | continue; |
| 4364 | } |
| 4365 | } |
| 4366 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4367 | layer_device_link_info[activated_layers].pNext = chain_info.u.pLayerInfo; |
| 4368 | layer_device_link_info[activated_layers].pfnNextGetInstanceProcAddr = nextGIPA; |
| 4369 | layer_device_link_info[activated_layers].pfnNextGetDeviceProcAddr = nextGDPA; |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4370 | chain_info.u.pLayerInfo = &layer_device_link_info[activated_layers]; |
| 4371 | nextGIPA = fpGIPA; |
| 4372 | nextGDPA = fpGDPA; |
| 4373 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4374 | loader_log(inst, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, "Insert device layer %s (%s)", layer_prop->info.layerName, |
| 4375 | layer_prop->lib_name); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4376 | |
| 4377 | activated_layers++; |
Jon Ashburn | 94e7049 | 2015-06-10 10:13:10 -0600 | [diff] [blame] | 4378 | } |
Jon Ashburn | 94e7049 | 2015-06-10 10:13:10 -0600 | [diff] [blame] | 4379 | } |
| 4380 | |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 4381 | VkDevice created_device = (VkDevice)dev; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4382 | PFN_vkCreateDevice fpCreateDevice = (PFN_vkCreateDevice)nextGIPA(inst->instance, "vkCreateDevice"); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4383 | if (fpCreateDevice) { |
Jon Ashburn | ed8f231 | 2016-03-31 10:52:22 -0600 | [diff] [blame] | 4384 | VkLayerDeviceCreateInfo create_info_disp; |
| 4385 | |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 4386 | create_info_disp.sType = VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO; |
Jon Ashburn | ed8f231 | 2016-03-31 10:52:22 -0600 | [diff] [blame] | 4387 | create_info_disp.function = VK_LOADER_DATA_CALLBACK; |
| 4388 | |
| 4389 | create_info_disp.u.pfnSetDeviceLoaderData = vkSetDeviceDispatch; |
| 4390 | |
| 4391 | create_info_disp.pNext = loader_create_info.pNext; |
| 4392 | loader_create_info.pNext = &create_info_disp; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4393 | res = fpCreateDevice(pd->phys_dev, &loader_create_info, pAllocator, &created_device); |
Piers Daniell | efbbfc1 | 2016-04-05 17:28:06 -0600 | [diff] [blame] | 4394 | if (res != VK_SUCCESS) { |
| 4395 | return res; |
| 4396 | } |
Mark Young | 65cb366 | 2016-11-07 13:27:02 -0700 | [diff] [blame] | 4397 | dev->chain_device = created_device; |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4398 | } else { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 4399 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4400 | "loader_create_device_chain: Failed to find \'vkCreateDevice\' " |
| 4401 | "in layer %s"); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4402 | // Couldn't find CreateDevice function! |
| 4403 | return VK_ERROR_INITIALIZATION_FAILED; |
| 4404 | } |
Jon Ashburn | 94e7049 | 2015-06-10 10:13:10 -0600 | [diff] [blame] | 4405 | |
Mark Young | 65cb366 | 2016-11-07 13:27:02 -0700 | [diff] [blame] | 4406 | // Initialize device dispatch table |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4407 | loader_init_device_dispatch_table(&dev->loader_dispatch, nextGDPA, dev->chain_device); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4408 | |
| 4409 | return res; |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 4410 | } |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 4411 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4412 | VkResult loader_validate_layers(const struct loader_instance *inst, const uint32_t layer_count, |
| 4413 | const char *const *ppEnabledLayerNames, const struct loader_layer_list *list) { |
Courtney Goeltzenleuchter | 3b8c5ff | 2015-07-06 17:45:08 -0600 | [diff] [blame] | 4414 | struct loader_layer_properties *prop; |
| 4415 | |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 4416 | for (uint32_t i = 0; i < layer_count; i++) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4417 | VkStringErrorFlags result = vk_string_validate(MaxLoaderStringLength, ppEnabledLayerNames[i]); |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 4418 | if (result != VK_STRING_ERROR_NONE) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 4419 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4420 | "loader_validate_layers: Device ppEnabledLayerNames " |
| 4421 | "contains string that is too long or is badly formed"); |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 4422 | return VK_ERROR_LAYER_NOT_PRESENT; |
| 4423 | } |
| 4424 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4425 | prop = loader_get_layer_property(ppEnabledLayerNames[i], list); |
Courtney Goeltzenleuchter | 3b8c5ff | 2015-07-06 17:45:08 -0600 | [diff] [blame] | 4426 | if (!prop) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 4427 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4428 | "loader_validate_layers: Layer %d does not exist in " |
| 4429 | "the list of available layers", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4430 | i); |
Courtney Goeltzenleuchter | 55659b7 | 2015-09-14 18:01:17 -0600 | [diff] [blame] | 4431 | return VK_ERROR_LAYER_NOT_PRESENT; |
Courtney Goeltzenleuchter | 3b8c5ff | 2015-07-06 17:45:08 -0600 | [diff] [blame] | 4432 | } |
| 4433 | } |
Courtney Goeltzenleuchter | 3b8c5ff | 2015-07-06 17:45:08 -0600 | [diff] [blame] | 4434 | return VK_SUCCESS; |
| 4435 | } |
| 4436 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4437 | VkResult loader_validate_instance_extensions(const struct loader_instance *inst, const struct loader_extension_list *icd_exts, |
| 4438 | const struct loader_layer_list *instance_layers, |
| 4439 | const VkInstanceCreateInfo *pCreateInfo) { |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 4440 | VkExtensionProperties *extension_prop; |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 4441 | struct loader_layer_properties *layer_prop; |
| 4442 | |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 4443 | for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4444 | VkStringErrorFlags result = vk_string_validate(MaxLoaderStringLength, pCreateInfo->ppEnabledExtensionNames[i]); |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 4445 | if (result != VK_STRING_ERROR_NONE) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 4446 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4447 | "loader_validate_instance_extensions: Instance " |
| 4448 | "ppEnabledExtensionNames contains " |
| 4449 | "string that is too long or is badly formed"); |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 4450 | return VK_ERROR_EXTENSION_NOT_PRESENT; |
| 4451 | } |
| 4452 | |
Lenny Komow | 4053b81 | 2016-12-29 16:27:28 -0700 | [diff] [blame] | 4453 | // See if the extension is in the list of supported extensions |
| 4454 | bool found = false; |
| 4455 | for (uint32_t j = 0; LOADER_INSTANCE_EXTENSIONS[j] != NULL; j++) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4456 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], LOADER_INSTANCE_EXTENSIONS[j]) == 0) { |
Lenny Komow | 4053b81 | 2016-12-29 16:27:28 -0700 | [diff] [blame] | 4457 | found = true; |
| 4458 | break; |
| 4459 | } |
| 4460 | } |
| 4461 | |
| 4462 | // If it isn't in the list, return an error |
| 4463 | if (!found) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 4464 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4465 | "loader_validate_instance_extensions: Extension %d " |
| 4466 | "not found in list of available extensions.", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4467 | i); |
Lenny Komow | 4053b81 | 2016-12-29 16:27:28 -0700 | [diff] [blame] | 4468 | return VK_ERROR_EXTENSION_NOT_PRESENT; |
| 4469 | } |
| 4470 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4471 | extension_prop = get_extension_property(pCreateInfo->ppEnabledExtensionNames[i], icd_exts); |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 4472 | |
| 4473 | if (extension_prop) { |
| 4474 | continue; |
| 4475 | } |
| 4476 | |
| 4477 | extension_prop = NULL; |
| 4478 | |
| 4479 | /* Not in global list, search layer extension lists */ |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 4480 | for (uint32_t j = 0; j < pCreateInfo->enabledLayerCount; j++) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4481 | layer_prop = loader_get_layer_property(pCreateInfo->ppEnabledLayerNames[j], instance_layers); |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 4482 | if (!layer_prop) { |
Courtney Goeltzenleuchter | 6f5b00c | 2015-07-06 20:46:50 -0600 | [diff] [blame] | 4483 | /* Should NOT get here, loader_validate_layers |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 4484 | * should have already filtered this case out. |
| 4485 | */ |
| 4486 | continue; |
| 4487 | } |
| 4488 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4489 | extension_prop = get_extension_property(pCreateInfo->ppEnabledExtensionNames[i], &layer_prop->instance_extension_list); |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 4490 | if (extension_prop) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4491 | /* Found the extension in one of the layers enabled by the app. |
| 4492 | */ |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 4493 | break; |
| 4494 | } |
| 4495 | } |
| 4496 | |
| 4497 | if (!extension_prop) { |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4498 | // Didn't find extension name in any of the global layers, error out |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 4499 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4500 | "loader_validate_instance_extensions: Extension %d " |
| 4501 | "not found in enabled layer list extensions.", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4502 | i); |
Courtney Goeltzenleuchter | 55659b7 | 2015-09-14 18:01:17 -0600 | [diff] [blame] | 4503 | return VK_ERROR_EXTENSION_NOT_PRESENT; |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 4504 | } |
| 4505 | } |
| 4506 | return VK_SUCCESS; |
| 4507 | } |
| 4508 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4509 | VkResult loader_validate_device_extensions(struct loader_physical_device_tramp *phys_dev, |
| 4510 | const struct loader_layer_list *activated_device_layers, |
| 4511 | const struct loader_extension_list *icd_exts, const VkDeviceCreateInfo *pCreateInfo) { |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 4512 | VkExtensionProperties *extension_prop; |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 4513 | struct loader_layer_properties *layer_prop; |
| 4514 | |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 4515 | for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4516 | VkStringErrorFlags result = vk_string_validate(MaxLoaderStringLength, pCreateInfo->ppEnabledExtensionNames[i]); |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 4517 | if (result != VK_STRING_ERROR_NONE) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 4518 | loader_log(phys_dev->this_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4519 | "loader_validate_device_extensions: Device " |
| 4520 | "ppEnabledExtensionNames contains " |
| 4521 | "string that is too long or is badly formed"); |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 4522 | return VK_ERROR_EXTENSION_NOT_PRESENT; |
| 4523 | } |
| 4524 | |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 4525 | const char *extension_name = pCreateInfo->ppEnabledExtensionNames[i]; |
Jon Ashburn | 014438f | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 4526 | extension_prop = get_extension_property(extension_name, icd_exts); |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 4527 | |
| 4528 | if (extension_prop) { |
| 4529 | continue; |
| 4530 | } |
| 4531 | |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4532 | // Not in global list, search activated layer extension lists |
Jon Ashburn | 471f44c | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 4533 | for (uint32_t j = 0; j < activated_device_layers->count; j++) { |
| 4534 | layer_prop = &activated_device_layers->list[j]; |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 4535 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4536 | extension_prop = get_dev_extension_property(extension_name, &layer_prop->device_extension_list); |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 4537 | if (extension_prop) { |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4538 | // Found the extension in one of the layers enabled by the app. |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 4539 | break; |
| 4540 | } |
| 4541 | } |
| 4542 | |
| 4543 | if (!extension_prop) { |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4544 | // Didn't find extension name in any of the device layers, error out |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 4545 | loader_log(phys_dev->this_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4546 | "loader_validate_device_extensions: Extension %d " |
| 4547 | "not found in enabled layer list extensions.", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4548 | i); |
Courtney Goeltzenleuchter | 55659b7 | 2015-09-14 18:01:17 -0600 | [diff] [blame] | 4549 | return VK_ERROR_EXTENSION_NOT_PRESENT; |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 4550 | } |
| 4551 | } |
Courtney Goeltzenleuchter | 3b8c5ff | 2015-07-06 17:45:08 -0600 | [diff] [blame] | 4552 | return VK_SUCCESS; |
| 4553 | } |
| 4554 | |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4555 | // Terminator functions for the Instance chain |
| 4556 | // All named terminator_<Vulakn API name> |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4557 | VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateInstance(const VkInstanceCreateInfo *pCreateInfo, |
| 4558 | const VkAllocationCallbacks *pAllocator, VkInstance *pInstance) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4559 | struct loader_icd_term *icd_term; |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 4560 | VkExtensionProperties *prop; |
Courtney Goeltzenleuchter | 746db73 | 2015-07-06 17:42:01 -0600 | [diff] [blame] | 4561 | char **filtered_extension_names = NULL; |
| 4562 | VkInstanceCreateInfo icd_create_info; |
Courtney Goeltzenleuchter | 40caf0b | 2015-07-06 09:06:34 -0600 | [diff] [blame] | 4563 | VkResult res = VK_SUCCESS; |
Mark Young | 8b4edb5 | 2016-11-11 09:31:55 -0700 | [diff] [blame] | 4564 | bool one_icd_successful = false; |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 4565 | |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 4566 | struct loader_instance *ptr_instance = (struct loader_instance *)*pInstance; |
Tony Barbour | 3c78ff4 | 2015-12-04 13:24:39 -0700 | [diff] [blame] | 4567 | memcpy(&icd_create_info, pCreateInfo, sizeof(icd_create_info)); |
| 4568 | |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 4569 | icd_create_info.enabledLayerCount = 0; |
Courtney Goeltzenleuchter | 746db73 | 2015-07-06 17:42:01 -0600 | [diff] [blame] | 4570 | icd_create_info.ppEnabledLayerNames = NULL; |
Courtney Goeltzenleuchter | 746db73 | 2015-07-06 17:42:01 -0600 | [diff] [blame] | 4571 | |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4572 | // NOTE: Need to filter the extensions to only those supported by the ICD. |
| 4573 | // No ICD will advertise support for layers. An ICD library could |
| 4574 | // support a layer, but it would be independent of the actual ICD, |
| 4575 | // just in the same library. |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4576 | filtered_extension_names = loader_stack_alloc(pCreateInfo->enabledExtensionCount * sizeof(char *)); |
Courtney Goeltzenleuchter | 746db73 | 2015-07-06 17:42:01 -0600 | [diff] [blame] | 4577 | if (!filtered_extension_names) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 4578 | loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4579 | "terminator_CreateInstance: Failed create extension name " |
| 4580 | "array for %d extensions", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4581 | pCreateInfo->enabledExtensionCount); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 4582 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 4583 | goto out; |
Courtney Goeltzenleuchter | 746db73 | 2015-07-06 17:42:01 -0600 | [diff] [blame] | 4584 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4585 | icd_create_info.ppEnabledExtensionNames = (const char *const *)filtered_extension_names; |
Courtney Goeltzenleuchter | 746db73 | 2015-07-06 17:42:01 -0600 | [diff] [blame] | 4586 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4587 | for (uint32_t i = 0; i < ptr_instance->icd_tramp_list.count; i++) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4588 | icd_term = loader_icd_add(ptr_instance, &ptr_instance->icd_tramp_list.scanned_list[i]); |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4589 | if (NULL == icd_term) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 4590 | loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4591 | "terminator_CreateInstance: Failed to add ICD %d to ICD " |
| 4592 | "trampoline list.", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4593 | i); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 4594 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 4595 | goto out; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4596 | } |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 4597 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4598 | icd_create_info.enabledExtensionCount = 0; |
| 4599 | struct loader_extension_list icd_exts; |
Courtney Goeltzenleuchter | 746db73 | 2015-07-06 17:42:01 -0600 | [diff] [blame] | 4600 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4601 | loader_log(ptr_instance, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, "Build ICD instance extension list"); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4602 | // traverse scanned icd list adding non-duplicate extensions to the |
| 4603 | // list |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4604 | res = loader_init_generic_list(ptr_instance, (struct loader_generic_list *)&icd_exts, sizeof(VkExtensionProperties)); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 4605 | if (VK_ERROR_OUT_OF_HOST_MEMORY == res) { |
| 4606 | // If out of memory, bail immediately. |
| 4607 | goto out; |
| 4608 | } else if (VK_SUCCESS != res) { |
Mark Young | 7e47129 | 2016-09-06 09:53:45 -0600 | [diff] [blame] | 4609 | // Something bad happened with this ICD, so free it and try the |
| 4610 | // next. |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4611 | ptr_instance->icd_terms = icd_term->next; |
| 4612 | icd_term->next = NULL; |
| 4613 | loader_icd_destroy(ptr_instance, icd_term, pAllocator); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 4614 | continue; |
| 4615 | } |
| 4616 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4617 | res = loader_add_instance_extensions(ptr_instance, icd_term->scanned_icd->EnumerateInstanceExtensionProperties, |
| 4618 | icd_term->scanned_icd->lib_name, &icd_exts); |
Mark Young | db13a2a | 2016-09-06 13:53:03 -0600 | [diff] [blame] | 4619 | if (VK_SUCCESS != res) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4620 | loader_destroy_generic_list(ptr_instance, (struct loader_generic_list *)&icd_exts); |
Mark Young | db13a2a | 2016-09-06 13:53:03 -0600 | [diff] [blame] | 4621 | if (VK_ERROR_OUT_OF_HOST_MEMORY == res) { |
| 4622 | // If out of memory, bail immediately. |
| 4623 | goto out; |
| 4624 | } else { |
| 4625 | // Something bad happened with this ICD, so free it and try |
| 4626 | // the next. |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4627 | ptr_instance->icd_terms = icd_term->next; |
| 4628 | icd_term->next = NULL; |
| 4629 | loader_icd_destroy(ptr_instance, icd_term, pAllocator); |
Mark Young | db13a2a | 2016-09-06 13:53:03 -0600 | [diff] [blame] | 4630 | continue; |
| 4631 | } |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 4632 | } |
Courtney Goeltzenleuchter | 36eeb74 | 2015-12-21 16:41:47 -0700 | [diff] [blame] | 4633 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4634 | for (uint32_t j = 0; j < pCreateInfo->enabledExtensionCount; j++) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4635 | prop = get_extension_property(pCreateInfo->ppEnabledExtensionNames[j], &icd_exts); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4636 | if (prop) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4637 | filtered_extension_names[icd_create_info.enabledExtensionCount] = (char *)pCreateInfo->ppEnabledExtensionNames[j]; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4638 | icd_create_info.enabledExtensionCount++; |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 4639 | } |
| 4640 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4641 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4642 | loader_destroy_generic_list(ptr_instance, (struct loader_generic_list *)&icd_exts); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4643 | |
Mark Young | 8b4edb5 | 2016-11-11 09:31:55 -0700 | [diff] [blame] | 4644 | VkResult icd_result = |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4645 | ptr_instance->icd_tramp_list.scanned_list[i].CreateInstance(&icd_create_info, pAllocator, &(icd_term->instance)); |
Mark Young | 8b4edb5 | 2016-11-11 09:31:55 -0700 | [diff] [blame] | 4646 | if (VK_ERROR_OUT_OF_HOST_MEMORY == icd_result) { |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 4647 | // If out of memory, bail immediately. |
Mark Young | 8b4edb5 | 2016-11-11 09:31:55 -0700 | [diff] [blame] | 4648 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 4649 | goto out; |
Mark Young | 8b4edb5 | 2016-11-11 09:31:55 -0700 | [diff] [blame] | 4650 | } else if (VK_SUCCESS != icd_result) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 4651 | loader_log(ptr_instance, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 4652 | "terminator_CreateInstance: Failed to CreateInstance in " |
| 4653 | "ICD %d. Skipping ICD.", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4654 | i); |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4655 | ptr_instance->icd_terms = icd_term->next; |
| 4656 | icd_term->next = NULL; |
| 4657 | loader_icd_destroy(ptr_instance, icd_term, pAllocator); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 4658 | continue; |
| 4659 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4660 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4661 | if (!loader_icd_init_entrys(icd_term, icd_term->instance, |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4662 | ptr_instance->icd_tramp_list.scanned_list[i].GetInstanceProcAddr)) { |
| 4663 | loader_log(ptr_instance, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 4664 | "terminator_CreateInstance: Failed to CreateInstance and find " |
| 4665 | "entrypoints with ICD. Skipping ICD."); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 4666 | continue; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4667 | } |
Mark Young | 8b4edb5 | 2016-11-11 09:31:55 -0700 | [diff] [blame] | 4668 | |
| 4669 | // If we made it this far, at least one ICD was successful |
| 4670 | one_icd_successful = true; |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 4671 | } |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 4672 | |
Mark Young | 8b4edb5 | 2016-11-11 09:31:55 -0700 | [diff] [blame] | 4673 | // If no ICDs were added to instance list and res is unchanged |
| 4674 | // from it's initial value, the loader was unable to find |
| 4675 | // a suitable ICD. |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4676 | if (VK_SUCCESS == res && (ptr_instance->icd_terms == NULL || !one_icd_successful)) { |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 4677 | res = VK_ERROR_INCOMPATIBLE_DRIVER; |
| 4678 | } |
| 4679 | |
| 4680 | out: |
| 4681 | |
| 4682 | if (VK_SUCCESS != res) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4683 | while (NULL != ptr_instance->icd_terms) { |
| 4684 | icd_term = ptr_instance->icd_terms; |
| 4685 | ptr_instance->icd_terms = icd_term->next; |
| 4686 | if (NULL != icd_term->instance) { |
| 4687 | icd_term->DestroyInstance(icd_term->instance, pAllocator); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 4688 | } |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4689 | loader_icd_destroy(ptr_instance, icd_term, pAllocator); |
Courtney Goeltzenleuchter | 40caf0b | 2015-07-06 09:06:34 -0600 | [diff] [blame] | 4690 | } |
Ian Elliott | eb45076 | 2015-02-05 15:19:15 -0700 | [diff] [blame] | 4691 | } |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 4692 | |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 4693 | return res; |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 4694 | } |
| 4695 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4696 | VKAPI_ATTR void VKAPI_CALL terminator_DestroyInstance(VkInstance instance, const VkAllocationCallbacks *pAllocator) { |
Courtney Goeltzenleuchter | deceded | 2015-06-08 15:04:02 -0600 | [diff] [blame] | 4697 | struct loader_instance *ptr_instance = loader_instance(instance); |
Karl Schultz | e2ef9e6 | 2017-01-13 14:01:35 -0700 | [diff] [blame] | 4698 | if (NULL == ptr_instance) { |
| 4699 | return; |
| 4700 | } |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4701 | struct loader_icd_term *icd_terms = ptr_instance->icd_terms; |
| 4702 | struct loader_icd_term *next_icd_term; |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 4703 | |
| 4704 | // Remove this instance from the list of instances: |
| 4705 | struct loader_instance *prev = NULL; |
| 4706 | struct loader_instance *next = loader.instances; |
| 4707 | while (next != NULL) { |
| 4708 | if (next == ptr_instance) { |
| 4709 | // Remove this instance from the list: |
| 4710 | if (prev) |
| 4711 | prev->next = next->next; |
Jon Ashburn | c5c4960 | 2015-02-03 09:26:59 -0700 | [diff] [blame] | 4712 | else |
| 4713 | loader.instances = next->next; |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 4714 | break; |
| 4715 | } |
| 4716 | prev = next; |
| 4717 | next = next->next; |
| 4718 | } |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 4719 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4720 | while (NULL != icd_terms) { |
| 4721 | if (icd_terms->instance) { |
| 4722 | icd_terms->DestroyInstance(icd_terms->instance, pAllocator); |
Tony Barbour | f20f87b | 2015-04-22 09:02:32 -0600 | [diff] [blame] | 4723 | } |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4724 | next_icd_term = icd_terms->next; |
| 4725 | icd_terms->instance = VK_NULL_HANDLE; |
| 4726 | loader_icd_destroy(ptr_instance, icd_terms, pAllocator); |
Jon Ashburn | a6fd261 | 2015-06-16 14:43:19 -0600 | [diff] [blame] | 4727 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4728 | icd_terms = next_icd_term; |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 4729 | } |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 4730 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4731 | loader_delete_layer_properties(ptr_instance, &ptr_instance->instance_layer_list); |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4732 | loader_scanned_icd_clear(ptr_instance, &ptr_instance->icd_tramp_list); |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4733 | loader_destroy_generic_list(ptr_instance, (struct loader_generic_list *)&ptr_instance->ext_list); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4734 | if (NULL != ptr_instance->phys_devs_term) { |
Mark Young | 0193d65 | 2016-12-28 16:10:10 -0700 | [diff] [blame] | 4735 | for (uint32_t i = 0; i < ptr_instance->phys_dev_count_term; i++) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4736 | loader_instance_heap_free(ptr_instance, ptr_instance->phys_devs_term[i]); |
Lenny Komow | 8a1f8a5 | 2016-12-20 15:35:11 -0700 | [diff] [blame] | 4737 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4738 | loader_instance_heap_free(ptr_instance, ptr_instance->phys_devs_term); |
Lenny Komow | 8a1f8a5 | 2016-12-20 15:35:11 -0700 | [diff] [blame] | 4739 | } |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 4740 | loader_free_dev_ext_table(ptr_instance); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4741 | loader_free_phys_dev_ext_table(ptr_instance); |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 4742 | } |
| 4743 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4744 | VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo *pCreateInfo, |
| 4745 | const VkAllocationCallbacks *pAllocator, VkDevice *pDevice) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4746 | VkResult res = VK_SUCCESS; |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4747 | struct loader_physical_device_term *phys_dev_term; |
| 4748 | phys_dev_term = (struct loader_physical_device_term *)physicalDevice; |
| 4749 | struct loader_icd_term *icd_term = phys_dev_term->this_icd_term; |
Jon Ashburn | 24cd4be | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 4750 | |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 4751 | struct loader_device *dev = (struct loader_device *)*pDevice; |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4752 | PFN_vkCreateDevice fpCreateDevice = icd_term->CreateDevice; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4753 | struct loader_extension_list icd_exts; |
| 4754 | |
Mark Young | 65cb366 | 2016-11-07 13:27:02 -0700 | [diff] [blame] | 4755 | dev->phys_dev_term = phys_dev_term; |
| 4756 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4757 | icd_exts.list = NULL; |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 4758 | |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 4759 | if (fpCreateDevice == NULL) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4760 | loader_log(icd_term->this_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4761 | "terminator_CreateDevice: No vkCreateDevice command exposed " |
| 4762 | "by ICD %s", |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4763 | icd_term->scanned_icd->lib_name); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4764 | res = VK_ERROR_INITIALIZATION_FAILED; |
| 4765 | goto out; |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 4766 | } |
| 4767 | |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 4768 | VkDeviceCreateInfo localCreateInfo; |
| 4769 | memcpy(&localCreateInfo, pCreateInfo, sizeof(localCreateInfo)); |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 4770 | |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4771 | // NOTE: Need to filter the extensions to only those supported by the ICD. |
| 4772 | // No ICD will advertise support for layers. An ICD library could |
| 4773 | // support a layer, but it would be independent of the actual ICD, |
| 4774 | // just in the same library. |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 4775 | char **filtered_extension_names = NULL; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4776 | filtered_extension_names = loader_stack_alloc(pCreateInfo->enabledExtensionCount * sizeof(char *)); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4777 | if (NULL == filtered_extension_names) { |
| 4778 | loader_log(icd_term->this_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4779 | "terminator_CreateDevice: Failed to create extension name " |
| 4780 | "storage for %d extensions %d", |
| 4781 | pCreateInfo->enabledExtensionCount); |
Jon Ashburn | 24cd4be | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 4782 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 4783 | } |
| 4784 | |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 4785 | localCreateInfo.enabledLayerCount = 0; |
| 4786 | localCreateInfo.ppEnabledLayerNames = NULL; |
| 4787 | |
| 4788 | localCreateInfo.enabledExtensionCount = 0; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4789 | localCreateInfo.ppEnabledExtensionNames = (const char *const *)filtered_extension_names; |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 4790 | |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4791 | // Get the physical device (ICD) extensions |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4792 | res = loader_init_generic_list(icd_term->this_instance, (struct loader_generic_list *)&icd_exts, sizeof(VkExtensionProperties)); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 4793 | if (VK_SUCCESS != res) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4794 | goto out; |
Jon Ashburn | 014438f | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 4795 | } |
| 4796 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4797 | res = loader_add_device_extensions(icd_term->this_instance, icd_term->EnumerateDeviceExtensionProperties, |
| 4798 | phys_dev_term->phys_dev, icd_term->scanned_icd->lib_name, &icd_exts); |
Jon Ashburn | 014438f | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 4799 | if (res != VK_SUCCESS) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4800 | goto out; |
Jon Ashburn | 014438f | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 4801 | } |
| 4802 | |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 4803 | for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) { |
| 4804 | const char *extension_name = pCreateInfo->ppEnabledExtensionNames[i]; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4805 | VkExtensionProperties *prop = get_extension_property(extension_name, &icd_exts); |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 4806 | if (prop) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4807 | filtered_extension_names[localCreateInfo.enabledExtensionCount] = (char *)extension_name; |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 4808 | localCreateInfo.enabledExtensionCount++; |
Mark Young | 9a3ddd4 | 2016-10-21 16:25:47 -0600 | [diff] [blame] | 4809 | } else { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 4810 | loader_log(icd_term->this_instance, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 4811 | "vkCreateDevice extension %s not available for " |
| 4812 | "devices associated with ICD %s", |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4813 | extension_name, icd_term->scanned_icd->lib_name); |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 4814 | } |
| 4815 | } |
| 4816 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4817 | res = fpCreateDevice(phys_dev_term->phys_dev, &localCreateInfo, pAllocator, &dev->icd_device); |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 4818 | if (res != VK_SUCCESS) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4819 | loader_log(icd_term->this_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4820 | "terminator_CreateDevice: Failed in ICD %s vkCreateDevice" |
| 4821 | "call", |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4822 | icd_term->scanned_icd->lib_name); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4823 | goto out; |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 4824 | } |
| 4825 | |
Mark Young | 65cb366 | 2016-11-07 13:27:02 -0700 | [diff] [blame] | 4826 | *pDevice = dev->icd_device; |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4827 | loader_add_logical_device(icd_term->this_instance, icd_term, dev); |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 4828 | |
| 4829 | /* Init dispatch pointer in new device object */ |
| 4830 | loader_init_dispatch(*pDevice, &dev->loader_dispatch); |
| 4831 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4832 | out: |
| 4833 | if (NULL != icd_exts.list) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4834 | loader_destroy_generic_list(icd_term->this_instance, (struct loader_generic_list *)&icd_exts); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4835 | } |
| 4836 | |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 4837 | return res; |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 4838 | } |
| 4839 | |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 4840 | VkResult setupLoaderTrampPhysDevs(VkInstance instance) { |
Jon Ashburn | 24cd4be | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 4841 | VkResult res = VK_SUCCESS; |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 4842 | VkPhysicalDevice *local_phys_devs = NULL; |
| 4843 | struct loader_instance *inst; |
| 4844 | uint32_t total_count = 0; |
| 4845 | struct loader_physical_device_tramp **new_phys_devs = NULL; |
Jon Ashburn | 4c392fb | 2015-01-28 19:57:09 -0700 | [diff] [blame] | 4846 | |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 4847 | inst = loader_get_instance(instance); |
| 4848 | if (NULL == inst) { |
| 4849 | res = VK_ERROR_INITIALIZATION_FAILED; |
| 4850 | goto out; |
| 4851 | } |
| 4852 | total_count = inst->total_gpu_count; |
| 4853 | |
| 4854 | // Create an array for the new physical devices, which will be stored |
| 4855 | // in the instance for the trampoline code. |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4856 | new_phys_devs = (struct loader_physical_device_tramp **)loader_instance_heap_alloc( |
| 4857 | inst, total_count * sizeof(struct loader_physical_device_tramp *), VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 4858 | if (NULL == new_phys_devs) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 4859 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4860 | "setupLoaderTrampPhysDevs: Failed to allocate new physical device" |
| 4861 | " array of size %d", |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4862 | total_count); |
Mark Young | d8382d7 | 2016-12-23 16:59:58 -0700 | [diff] [blame] | 4863 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 4864 | goto out; |
| 4865 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4866 | memset(new_phys_devs, 0, total_count * sizeof(struct loader_physical_device_tramp *)); |
Jon Ashburn | 014438f | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 4867 | |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 4868 | // Create a temporary array (on the stack) to keep track of the |
| 4869 | // returned VkPhysicalDevice values. |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4870 | local_phys_devs = loader_stack_alloc(sizeof(VkPhysicalDevice) * total_count); |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 4871 | if (NULL == local_phys_devs) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 4872 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4873 | "setupLoaderTrampPhysDevs: Failed to allocate local " |
| 4874 | "physical device array of size %d", |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 4875 | total_count); |
| 4876 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 4877 | goto out; |
| 4878 | } |
| 4879 | memset(local_phys_devs, 0, sizeof(VkPhysicalDevice) * total_count); |
| 4880 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4881 | res = inst->disp->layer_inst_disp.EnumeratePhysicalDevices(instance, &total_count, local_phys_devs); |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 4882 | if (VK_SUCCESS != res) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 4883 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4884 | "setupLoaderTrampPhysDevs: Failed during dispatch call " |
| 4885 | "of \'vkEnumeratePhysicalDevices\' to lower layers or " |
| 4886 | "loader."); |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 4887 | goto out; |
| 4888 | } |
| 4889 | |
| 4890 | // Copy or create everything to fill the new array of physical devices |
| 4891 | for (uint32_t new_idx = 0; new_idx < total_count; new_idx++) { |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 4892 | // Check if this physical device is already in the old buffer |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4893 | for (uint32_t old_idx = 0; old_idx < inst->phys_dev_count_tramp; old_idx++) { |
| 4894 | if (local_phys_devs[new_idx] == inst->phys_devs_tramp[old_idx]->phys_dev) { |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 4895 | new_phys_devs[new_idx] = inst->phys_devs_tramp[old_idx]; |
| 4896 | break; |
| 4897 | } |
Mark Young | d8382d7 | 2016-12-23 16:59:58 -0700 | [diff] [blame] | 4898 | } |
| 4899 | |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 4900 | // If this physical device isn't in the old buffer, create it |
| 4901 | if (NULL == new_phys_devs[new_idx]) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4902 | new_phys_devs[new_idx] = (struct loader_physical_device_tramp *)loader_instance_heap_alloc( |
| 4903 | inst, sizeof(struct loader_physical_device_tramp), VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 4904 | if (NULL == new_phys_devs[new_idx]) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 4905 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4906 | "setupLoaderTrampPhysDevs: Failed to allocate " |
| 4907 | "physical device trampoline object %d", |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 4908 | new_idx); |
| 4909 | total_count = new_idx; |
Mark Young | d8382d7 | 2016-12-23 16:59:58 -0700 | [diff] [blame] | 4910 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 4911 | goto out; |
| 4912 | } |
| 4913 | |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 4914 | // Initialize the new physicalDevice object |
| 4915 | loader_set_dispatch((void *)new_phys_devs[new_idx], inst->disp); |
| 4916 | new_phys_devs[new_idx]->this_instance = inst; |
| 4917 | new_phys_devs[new_idx]->phys_dev = local_phys_devs[new_idx]; |
Mark Young | 559d750 | 2016-09-26 11:38:46 -0600 | [diff] [blame] | 4918 | } |
Lenny Komow | a5e0112 | 2016-12-22 15:29:43 -0700 | [diff] [blame] | 4919 | } |
Mark Young | 559d750 | 2016-09-26 11:38:46 -0600 | [diff] [blame] | 4920 | |
Lenny Komow | a5e0112 | 2016-12-22 15:29:43 -0700 | [diff] [blame] | 4921 | out: |
Mark Young | d8382d7 | 2016-12-23 16:59:58 -0700 | [diff] [blame] | 4922 | |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 4923 | if (VK_SUCCESS != res) { |
| 4924 | if (NULL != new_phys_devs) { |
| 4925 | for (uint32_t i = 0; i < total_count; i++) { |
| 4926 | loader_instance_heap_free(inst, new_phys_devs[i]); |
Lenny Komow | a5e0112 | 2016-12-22 15:29:43 -0700 | [diff] [blame] | 4927 | } |
| 4928 | loader_instance_heap_free(inst, new_phys_devs); |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 4929 | } |
| 4930 | total_count = 0; |
| 4931 | } else { |
| 4932 | // Free everything that didn't carry over to the new array of |
| 4933 | // physical devices |
| 4934 | if (NULL != inst->phys_devs_tramp) { |
| 4935 | for (uint32_t i = 0; i < inst->phys_dev_count_tramp; i++) { |
| 4936 | bool found = false; |
| 4937 | for (uint32_t j = 0; j < total_count; j++) { |
| 4938 | if (inst->phys_devs_tramp[i] == new_phys_devs[j]) { |
| 4939 | found = true; |
| 4940 | break; |
| 4941 | } |
| 4942 | } |
| 4943 | if (!found) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4944 | loader_instance_heap_free(inst, inst->phys_devs_tramp[i]); |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 4945 | } |
| 4946 | } |
| 4947 | loader_instance_heap_free(inst, inst->phys_devs_tramp); |
| 4948 | } |
Mark Young | d8382d7 | 2016-12-23 16:59:58 -0700 | [diff] [blame] | 4949 | |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 4950 | // Swap in the new physical device list |
| 4951 | inst->phys_dev_count_tramp = total_count; |
| 4952 | inst->phys_devs_tramp = new_phys_devs; |
| 4953 | } |
| 4954 | |
| 4955 | return res; |
| 4956 | } |
| 4957 | |
| 4958 | VkResult setupLoaderTermPhysDevs(struct loader_instance *inst) { |
| 4959 | VkResult res = VK_SUCCESS; |
| 4960 | struct loader_icd_term *icd_term; |
| 4961 | struct loader_phys_dev_per_icd *icd_phys_dev_array = NULL; |
| 4962 | struct loader_physical_device_term **new_phys_devs = NULL; |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 4963 | |
| 4964 | inst->total_gpu_count = 0; |
| 4965 | |
| 4966 | // Allocate something to store the physical device characteristics |
| 4967 | // that we read from each ICD. |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4968 | icd_phys_dev_array = |
| 4969 | (struct loader_phys_dev_per_icd *)loader_stack_alloc(sizeof(struct loader_phys_dev_per_icd) * inst->total_icd_count); |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 4970 | if (NULL == icd_phys_dev_array) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 4971 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4972 | "setupLoaderTermPhysDevs: Failed to allocate temporary " |
| 4973 | "ICD Physical device info array of size %d", |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 4974 | inst->total_gpu_count); |
| 4975 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 4976 | goto out; |
| 4977 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4978 | memset(icd_phys_dev_array, 0, sizeof(struct loader_phys_dev_per_icd) * inst->total_icd_count); |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 4979 | icd_term = inst->icd_terms; |
| 4980 | |
| 4981 | // For each ICD, query the number of physical devices, and then get an |
| 4982 | // internal value for those physical devices. |
Karl Schultz | 47dd59d | 2017-01-20 13:19:20 -0700 | [diff] [blame] | 4983 | for (uint32_t icd_idx = 0; NULL != icd_term; icd_term = icd_term->next, icd_idx++) { |
| 4984 | res = icd_term->EnumeratePhysicalDevices(icd_term->instance, &icd_phys_dev_array[icd_idx].count, NULL); |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 4985 | if (VK_SUCCESS != res) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 4986 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4987 | "setupLoaderTermPhysDevs: Call to " |
| 4988 | "ICD %d's \'vkEnumeratePhysicalDevices\' failed with" |
| 4989 | " error 0x%08x", |
Karl Schultz | 47dd59d | 2017-01-20 13:19:20 -0700 | [diff] [blame] | 4990 | icd_idx, res); |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 4991 | goto out; |
| 4992 | } |
| 4993 | |
Karl Schultz | 47dd59d | 2017-01-20 13:19:20 -0700 | [diff] [blame] | 4994 | icd_phys_dev_array[icd_idx].phys_devs = |
| 4995 | (VkPhysicalDevice *)loader_stack_alloc(icd_phys_dev_array[icd_idx].count * sizeof(VkPhysicalDevice)); |
| 4996 | if (NULL == icd_phys_dev_array[icd_idx].phys_devs) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 4997 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4998 | "setupLoaderTermPhysDevs: Failed to allocate temporary " |
| 4999 | "ICD Physical device array for ICD %d of size %d", |
Karl Schultz | 47dd59d | 2017-01-20 13:19:20 -0700 | [diff] [blame] | 5000 | icd_idx, inst->total_gpu_count); |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5001 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 5002 | goto out; |
| 5003 | } |
| 5004 | |
Karl Schultz | 47dd59d | 2017-01-20 13:19:20 -0700 | [diff] [blame] | 5005 | res = icd_term->EnumeratePhysicalDevices(icd_term->instance, &(icd_phys_dev_array[icd_idx].count), |
| 5006 | icd_phys_dev_array[icd_idx].phys_devs); |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5007 | if (VK_SUCCESS != res) { |
| 5008 | goto out; |
| 5009 | } |
Karl Schultz | 47dd59d | 2017-01-20 13:19:20 -0700 | [diff] [blame] | 5010 | inst->total_gpu_count += icd_phys_dev_array[icd_idx].count; |
| 5011 | icd_phys_dev_array[icd_idx].this_icd_term = icd_term; |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5012 | } |
| 5013 | |
| 5014 | if (0 == inst->total_gpu_count) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 5015 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 5016 | "setupLoaderTermPhysDevs: Failed to detect any valid" |
| 5017 | " GPUs in the current config"); |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5018 | res = VK_ERROR_INITIALIZATION_FAILED; |
| 5019 | goto out; |
| 5020 | } |
| 5021 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5022 | new_phys_devs = loader_instance_heap_alloc(inst, sizeof(struct loader_physical_device_term *) * inst->total_gpu_count, |
| 5023 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5024 | if (NULL == new_phys_devs) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 5025 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 5026 | "setupLoaderTermPhysDevs: Failed to allocate new physical" |
| 5027 | " device array of size %d", |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5028 | inst->total_gpu_count); |
| 5029 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 5030 | goto out; |
| 5031 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5032 | memset(new_phys_devs, 0, sizeof(struct loader_physical_device_term *) * inst->total_gpu_count); |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5033 | |
| 5034 | // Copy or create everything to fill the new array of physical devices |
| 5035 | uint32_t idx = 0; |
| 5036 | for (uint32_t icd_idx = 0; icd_idx < inst->total_icd_count; icd_idx++) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5037 | for (uint32_t pd_idx = 0; pd_idx < icd_phys_dev_array[icd_idx].count; pd_idx++) { |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5038 | // Check if this physical device is already in the old buffer |
| 5039 | if (NULL != inst->phys_devs_term) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5040 | for (uint32_t old_idx = 0; old_idx < inst->phys_dev_count_term; old_idx++) { |
| 5041 | if (icd_phys_dev_array[icd_idx].phys_devs[pd_idx] == inst->phys_devs_term[old_idx]->phys_dev) { |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5042 | new_phys_devs[idx] = inst->phys_devs_term[old_idx]; |
| 5043 | break; |
| 5044 | } |
| 5045 | } |
| 5046 | } |
| 5047 | // If this physical device isn't in the old buffer, then we |
| 5048 | // need to create it. |
| 5049 | if (NULL == new_phys_devs[idx]) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5050 | new_phys_devs[idx] = loader_instance_heap_alloc(inst, sizeof(struct loader_physical_device_term), |
| 5051 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5052 | if (NULL == new_phys_devs[idx]) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 5053 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 5054 | "setupLoaderTermPhysDevs: Failed to allocate " |
| 5055 | "physical device terminator object %d", |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5056 | idx); |
| 5057 | inst->total_gpu_count = idx; |
| 5058 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 5059 | goto out; |
| 5060 | } |
| 5061 | |
| 5062 | loader_set_dispatch((void *)new_phys_devs[idx], inst->disp); |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5063 | new_phys_devs[idx]->this_icd_term = icd_phys_dev_array[icd_idx].this_icd_term; |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5064 | new_phys_devs[idx]->icd_index = (uint8_t)(icd_idx); |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5065 | new_phys_devs[idx]->phys_dev = icd_phys_dev_array[icd_idx].phys_devs[pd_idx]; |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5066 | } |
| 5067 | idx++; |
| 5068 | } |
| 5069 | } |
| 5070 | |
| 5071 | out: |
| 5072 | |
| 5073 | if (VK_SUCCESS != res) { |
Mark Young | 156e855 | 2017-02-03 16:27:42 -0700 | [diff] [blame] | 5074 | if (NULL != new_phys_devs) { |
| 5075 | // We've encountered an error, so we should free the new buffers. |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5076 | for (uint32_t i = 0; i < inst->total_gpu_count; i++) { |
| 5077 | loader_instance_heap_free(inst, new_phys_devs[i]); |
| 5078 | } |
Mark Young | 156e855 | 2017-02-03 16:27:42 -0700 | [diff] [blame] | 5079 | loader_instance_heap_free(inst, new_phys_devs); |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5080 | } |
Mark Young | 156e855 | 2017-02-03 16:27:42 -0700 | [diff] [blame] | 5081 | if (NULL != inst->phys_devs_term) { |
| 5082 | loader_instance_heap_free(inst, inst->phys_devs_term); |
| 5083 | } |
| 5084 | inst->total_gpu_count = 0; |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5085 | } else { |
| 5086 | // Free everything that didn't carry over to the new array of |
| 5087 | // physical devices. Everything else will have been copied over |
| 5088 | // to the new array. |
| 5089 | if (NULL != inst->phys_devs_term) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5090 | for (uint32_t cur_pd = 0; cur_pd < inst->phys_dev_count_term; cur_pd++) { |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5091 | bool found = false; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5092 | for (uint32_t new_pd_idx = 0; new_pd_idx < inst->total_gpu_count; new_pd_idx++) { |
| 5093 | if (inst->phys_devs_term[cur_pd] == new_phys_devs[new_pd_idx]) { |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5094 | found = true; |
| 5095 | break; |
| 5096 | } |
| 5097 | } |
| 5098 | if (!found) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5099 | loader_instance_heap_free(inst, inst->phys_devs_term[cur_pd]); |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5100 | } |
| 5101 | } |
| 5102 | loader_instance_heap_free(inst, inst->phys_devs_term); |
| 5103 | } |
| 5104 | |
| 5105 | // Swap out old and new devices list |
| 5106 | inst->phys_dev_count_term = inst->total_gpu_count; |
| 5107 | inst->phys_devs_term = new_phys_devs; |
| 5108 | } |
| 5109 | |
| 5110 | return res; |
| 5111 | } |
| 5112 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5113 | VKAPI_ATTR VkResult VKAPI_CALL terminator_EnumeratePhysicalDevices(VkInstance instance, uint32_t *pPhysicalDeviceCount, |
| 5114 | VkPhysicalDevice *pPhysicalDevices) { |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5115 | struct loader_instance *inst = (struct loader_instance *)instance; |
| 5116 | VkResult res = VK_SUCCESS; |
| 5117 | |
| 5118 | // Only do the setup if we're re-querying the number of devices, or |
| 5119 | // our count is currently 0. |
| 5120 | if (NULL == pPhysicalDevices || 0 == inst->total_gpu_count) { |
| 5121 | res = setupLoaderTermPhysDevs(inst); |
| 5122 | if (VK_SUCCESS != res) { |
| 5123 | goto out; |
| 5124 | } |
| 5125 | } |
| 5126 | |
| 5127 | uint32_t copy_count = inst->total_gpu_count; |
| 5128 | if (NULL != pPhysicalDevices) { |
| 5129 | if (copy_count > *pPhysicalDeviceCount) { |
| 5130 | copy_count = *pPhysicalDeviceCount; |
| 5131 | res = VK_INCOMPLETE; |
| 5132 | } |
| 5133 | |
| 5134 | for (uint32_t i = 0; i < copy_count; i++) { |
| 5135 | pPhysicalDevices[i] = (VkPhysicalDevice)inst->phys_devs_term[i]; |
Jon Ashburn | 014438f | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 5136 | } |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 5137 | } |
Mark Young | 559d750 | 2016-09-26 11:38:46 -0600 | [diff] [blame] | 5138 | |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 5139 | *pPhysicalDeviceCount = copy_count; |
| 5140 | |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5141 | out: |
| 5142 | |
Jon Ashburn | 24cd4be | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 5143 | return res; |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 5144 | } |
| 5145 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5146 | VKAPI_ATTR void VKAPI_CALL terminator_GetPhysicalDeviceProperties(VkPhysicalDevice physicalDevice, |
| 5147 | VkPhysicalDeviceProperties *pProperties) { |
| 5148 | struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice; |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5149 | struct loader_icd_term *icd_term = phys_dev_term->this_icd_term; |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5150 | if (NULL != icd_term->GetPhysicalDeviceProperties) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5151 | icd_term->GetPhysicalDeviceProperties(phys_dev_term->phys_dev, pProperties); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5152 | } |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 5153 | } |
| 5154 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5155 | VKAPI_ATTR void VKAPI_CALL terminator_GetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice, |
| 5156 | uint32_t *pQueueFamilyPropertyCount, |
| 5157 | VkQueueFamilyProperties *pProperties) { |
| 5158 | struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice; |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5159 | struct loader_icd_term *icd_term = phys_dev_term->this_icd_term; |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5160 | if (NULL != icd_term->GetPhysicalDeviceQueueFamilyProperties) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5161 | icd_term->GetPhysicalDeviceQueueFamilyProperties(phys_dev_term->phys_dev, pQueueFamilyPropertyCount, pProperties); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5162 | } |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 5163 | } |
| 5164 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5165 | VKAPI_ATTR void VKAPI_CALL terminator_GetPhysicalDeviceMemoryProperties(VkPhysicalDevice physicalDevice, |
| 5166 | VkPhysicalDeviceMemoryProperties *pProperties) { |
| 5167 | struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice; |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5168 | struct loader_icd_term *icd_term = phys_dev_term->this_icd_term; |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5169 | if (NULL != icd_term->GetPhysicalDeviceMemoryProperties) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5170 | icd_term->GetPhysicalDeviceMemoryProperties(phys_dev_term->phys_dev, pProperties); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5171 | } |
Jon Ashburn | 3da71f2 | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 5172 | } |
| 5173 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5174 | VKAPI_ATTR void VKAPI_CALL terminator_GetPhysicalDeviceFeatures(VkPhysicalDevice physicalDevice, |
| 5175 | VkPhysicalDeviceFeatures *pFeatures) { |
| 5176 | struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice; |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5177 | struct loader_icd_term *icd_term = phys_dev_term->this_icd_term; |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5178 | if (NULL != icd_term->GetPhysicalDeviceFeatures) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5179 | icd_term->GetPhysicalDeviceFeatures(phys_dev_term->phys_dev, pFeatures); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5180 | } |
Chris Forbes | bc0bb77 | 2015-06-21 22:55:02 +1200 | [diff] [blame] | 5181 | } |
| 5182 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5183 | VKAPI_ATTR void VKAPI_CALL terminator_GetPhysicalDeviceFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, |
| 5184 | VkFormatProperties *pFormatInfo) { |
| 5185 | struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice; |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5186 | struct loader_icd_term *icd_term = phys_dev_term->this_icd_term; |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5187 | if (NULL != icd_term->GetPhysicalDeviceFormatProperties) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5188 | icd_term->GetPhysicalDeviceFormatProperties(phys_dev_term->phys_dev, format, pFormatInfo); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5189 | } |
Chris Forbes | bc0bb77 | 2015-06-21 22:55:02 +1200 | [diff] [blame] | 5190 | } |
| 5191 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5192 | VKAPI_ATTR VkResult VKAPI_CALL terminator_GetPhysicalDeviceImageFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, |
| 5193 | VkImageType type, VkImageTiling tiling, |
| 5194 | VkImageUsageFlags usage, VkImageCreateFlags flags, |
| 5195 | VkImageFormatProperties *pImageFormatProperties) { |
| 5196 | struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice; |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5197 | struct loader_icd_term *icd_term = phys_dev_term->this_icd_term; |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5198 | if (NULL == icd_term->GetPhysicalDeviceImageFormatProperties) { |
| 5199 | loader_log(icd_term->this_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 5200 | "Encountered the vkEnumerateDeviceLayerProperties " |
| 5201 | "terminator. This means a layer improperly continued."); |
Chia-I Wu | 1724104 | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 5202 | return VK_ERROR_INITIALIZATION_FAILED; |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5203 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5204 | return icd_term->GetPhysicalDeviceImageFormatProperties(phys_dev_term->phys_dev, format, type, tiling, usage, flags, |
| 5205 | pImageFormatProperties); |
Jon Ashburn | 754864f | 2015-07-23 18:49:07 -0600 | [diff] [blame] | 5206 | } |
| 5207 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5208 | VKAPI_ATTR void VKAPI_CALL terminator_GetPhysicalDeviceSparseImageFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, |
| 5209 | VkImageType type, VkSampleCountFlagBits samples, |
| 5210 | VkImageUsageFlags usage, VkImageTiling tiling, |
| 5211 | uint32_t *pNumProperties, |
| 5212 | VkSparseImageFormatProperties *pProperties) { |
| 5213 | struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice; |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5214 | struct loader_icd_term *icd_term = phys_dev_term->this_icd_term; |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5215 | if (NULL != icd_term->GetPhysicalDeviceSparseImageFormatProperties) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5216 | icd_term->GetPhysicalDeviceSparseImageFormatProperties(phys_dev_term->phys_dev, format, type, samples, usage, tiling, |
| 5217 | pNumProperties, pProperties); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5218 | } |
Mark Lobodzinski | 16e8bef | 2015-07-03 15:58:09 -0600 | [diff] [blame] | 5219 | } |
| 5220 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5221 | VKAPI_ATTR VkResult VKAPI_CALL terminator_EnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice, |
| 5222 | const char *pLayerName, uint32_t *pPropertyCount, |
| 5223 | VkExtensionProperties *pProperties) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5224 | struct loader_physical_device_term *phys_dev_term; |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 5225 | |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 5226 | struct loader_layer_list implicit_layer_list = {0}; |
| 5227 | struct loader_extension_list all_exts = {0}; |
| 5228 | struct loader_extension_list icd_exts = {0}; |
Jon Ashburn | 471f44c | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 5229 | |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 5230 | assert(pLayerName == NULL || strlen(pLayerName) == 0); |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 5231 | |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 5232 | /* Any layer or trampoline wrapping should be removed at this point in time |
| 5233 | * can just cast to the expected type for VkPhysicalDevice. */ |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5234 | phys_dev_term = (struct loader_physical_device_term *)physicalDevice; |
Jon Ashburn | 471f44c | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 5235 | |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 5236 | /* this case is during the call down the instance chain with pLayerName |
| 5237 | * == NULL*/ |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5238 | struct loader_icd_term *icd_term = phys_dev_term->this_icd_term; |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 5239 | uint32_t icd_ext_count = *pPropertyCount; |
| 5240 | VkResult res; |
Jon Ashburn | 471f44c | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 5241 | |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 5242 | /* get device extensions */ |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5243 | res = icd_term->EnumerateDeviceExtensionProperties(phys_dev_term->phys_dev, NULL, &icd_ext_count, pProperties); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 5244 | if (res != VK_SUCCESS) { |
| 5245 | goto out; |
| 5246 | } |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 5247 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5248 | if (!loader_init_layer_list(icd_term->this_instance, &implicit_layer_list)) { |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 5249 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 5250 | goto out; |
| 5251 | } |
Jon Ashburn | 471f44c | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 5252 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5253 | loader_add_layer_implicit(icd_term->this_instance, VK_LAYER_TYPE_INSTANCE_IMPLICIT, &implicit_layer_list, |
| 5254 | &icd_term->this_instance->instance_layer_list); |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 5255 | /* we need to determine which implicit layers are active, |
| 5256 | * and then add their extensions. This can't be cached as |
| 5257 | * it depends on results of environment variables (which can change). |
| 5258 | */ |
| 5259 | if (pProperties != NULL) { |
| 5260 | /* initialize dev_extension list within the physicalDevice object */ |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5261 | res = loader_init_device_extensions(icd_term->this_instance, phys_dev_term, icd_ext_count, pProperties, &icd_exts); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 5262 | if (res != VK_SUCCESS) { |
| 5263 | goto out; |
| 5264 | } |
Jon Ashburn | 471f44c | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 5265 | |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 5266 | /* we need to determine which implicit layers are active, |
| 5267 | * and then add their extensions. This can't be cached as |
| 5268 | * it depends on results of environment variables (which can |
| 5269 | * change). |
| 5270 | */ |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5271 | res = loader_add_to_ext_list(icd_term->this_instance, &all_exts, icd_exts.count, icd_exts.list); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 5272 | if (res != VK_SUCCESS) { |
| 5273 | goto out; |
| 5274 | } |
Jon Ashburn | 471f44c | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 5275 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5276 | loader_add_layer_implicit(icd_term->this_instance, VK_LAYER_TYPE_INSTANCE_IMPLICIT, &implicit_layer_list, |
| 5277 | &icd_term->this_instance->instance_layer_list); |
Jon Ashburn | 471f44c | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 5278 | |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 5279 | for (uint32_t i = 0; i < implicit_layer_list.count; i++) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5280 | for (uint32_t j = 0; j < implicit_layer_list.list[i].device_extension_list.count; j++) { |
| 5281 | res = loader_add_to_ext_list(icd_term->this_instance, &all_exts, 1, |
| 5282 | &implicit_layer_list.list[i].device_extension_list.list[j].props); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 5283 | if (res != VK_SUCCESS) { |
| 5284 | goto out; |
| 5285 | } |
Jon Ashburn | 471f44c | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 5286 | } |
Jon Ashburn | 471f44c | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 5287 | } |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 5288 | uint32_t capacity = *pPropertyCount; |
| 5289 | VkExtensionProperties *props = pProperties; |
Jon Ashburn | 471f44c | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 5290 | |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 5291 | for (uint32_t i = 0; i < all_exts.count && i < capacity; i++) { |
| 5292 | props[i] = all_exts.list[i]; |
| 5293 | } |
| 5294 | /* wasn't enough space for the extensions, we did partial copy now |
| 5295 | * return VK_INCOMPLETE */ |
| 5296 | if (capacity < all_exts.count) { |
| 5297 | res = VK_INCOMPLETE; |
| 5298 | } else { |
| 5299 | *pPropertyCount = all_exts.count; |
| 5300 | } |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 5301 | } else { |
| 5302 | /* just return the count; need to add in the count of implicit layer |
| 5303 | * extensions |
| 5304 | * don't worry about duplicates being added in the count */ |
| 5305 | *pPropertyCount = icd_ext_count; |
| 5306 | |
| 5307 | for (uint32_t i = 0; i < implicit_layer_list.count; i++) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5308 | *pPropertyCount += implicit_layer_list.list[i].device_extension_list.count; |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 5309 | } |
| 5310 | res = VK_SUCCESS; |
Jon Ashburn | b82c185 | 2015-08-11 14:49:54 -0600 | [diff] [blame] | 5311 | } |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 5312 | |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 5313 | out: |
| 5314 | |
| 5315 | if (NULL != implicit_layer_list.list) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5316 | loader_destroy_generic_list(icd_term->this_instance, (struct loader_generic_list *)&implicit_layer_list); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 5317 | } |
| 5318 | if (NULL != all_exts.list) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5319 | loader_destroy_generic_list(icd_term->this_instance, (struct loader_generic_list *)&all_exts); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 5320 | } |
| 5321 | if (NULL != icd_exts.list) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5322 | loader_destroy_generic_list(icd_term->this_instance, (struct loader_generic_list *)&icd_exts); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 5323 | } |
| 5324 | |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 5325 | return res; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 5326 | } |
| 5327 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5328 | VKAPI_ATTR VkResult VKAPI_CALL terminator_EnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice, uint32_t *pPropertyCount, |
| 5329 | VkLayerProperties *pProperties) { |
| 5330 | struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice; |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5331 | struct loader_icd_term *icd_term = phys_dev_term->this_icd_term; |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 5332 | loader_log(icd_term->this_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 5333 | "Encountered the vkEnumerateDeviceLayerProperties " |
| 5334 | "terminator. This means a layer improperly continued."); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5335 | // Should never get here this call isn't dispatched down the chain |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 5336 | return VK_ERROR_INITIALIZATION_FAILED; |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 5337 | } |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 5338 | |
Jon Ashburn | f2b4e38 | 2016-02-10 20:50:19 -0700 | [diff] [blame] | 5339 | VkStringErrorFlags vk_string_validate(const int max_length, const char *utf8) { |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 5340 | VkStringErrorFlags result = VK_STRING_ERROR_NONE; |
Karl Schultz | 2558bd3 | 2016-02-24 14:39:39 -0700 | [diff] [blame] | 5341 | int num_char_bytes = 0; |
Jon Ashburn | f2b4e38 | 2016-02-10 20:50:19 -0700 | [diff] [blame] | 5342 | int i, j; |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 5343 | |
Courtney Goeltzenleuchter | 7a3486d | 2016-12-21 16:24:34 -0700 | [diff] [blame] | 5344 | for (i = 0; i <= max_length; i++) { |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 5345 | if (utf8[i] == 0) { |
| 5346 | break; |
Courtney Goeltzenleuchter | 7a3486d | 2016-12-21 16:24:34 -0700 | [diff] [blame] | 5347 | } else if (i == max_length) { |
| 5348 | result |= VK_STRING_ERROR_LENGTH; |
| 5349 | break; |
Mark Lobodzinski | 36b4de2 | 2016-02-12 11:30:14 -0700 | [diff] [blame] | 5350 | } else if ((utf8[i] >= 0x20) && (utf8[i] < 0x7f)) { |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 5351 | num_char_bytes = 0; |
Jon Ashburn | f2b4e38 | 2016-02-10 20:50:19 -0700 | [diff] [blame] | 5352 | } else if ((utf8[i] & UTF8_ONE_BYTE_MASK) == UTF8_ONE_BYTE_CODE) { |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 5353 | num_char_bytes = 1; |
Jon Ashburn | f2b4e38 | 2016-02-10 20:50:19 -0700 | [diff] [blame] | 5354 | } else if ((utf8[i] & UTF8_TWO_BYTE_MASK) == UTF8_TWO_BYTE_CODE) { |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 5355 | num_char_bytes = 2; |
| 5356 | } else if ((utf8[i] & UTF8_THREE_BYTE_MASK) == UTF8_THREE_BYTE_CODE) { |
| 5357 | num_char_bytes = 3; |
| 5358 | } else { |
| 5359 | result = VK_STRING_ERROR_BAD_DATA; |
| 5360 | } |
| 5361 | |
| 5362 | // Validate the following num_char_bytes of data |
| 5363 | for (j = 0; (j < num_char_bytes) && (i < max_length); j++) { |
| 5364 | if (++i == max_length) { |
| 5365 | result |= VK_STRING_ERROR_LENGTH; |
| 5366 | break; |
| 5367 | } |
| 5368 | if ((utf8[i] & UTF8_DATA_BYTE_MASK) != UTF8_DATA_BYTE_CODE) { |
| 5369 | result |= VK_STRING_ERROR_BAD_DATA; |
| 5370 | } |
| 5371 | } |
| 5372 | } |
| 5373 | return result; |
| 5374 | } |