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