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