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