| Chia-I Wu | 468e3c3 | 2014-08-04 08:03:57 +0800 | [diff] [blame] | 1 | /* |
| Chia-I Wu | 468e3c3 | 2014-08-04 08:03:57 +0800 | [diff] [blame] | 2 | * |
| Courtney Goeltzenleuchter | 8a17da5 | 2015-10-29 13:50:34 -0600 | [diff] [blame] | 3 | * Copyright (C) 2015 Valve Corporation |
| Chia-I Wu | 468e3c3 | 2014-08-04 08:03:57 +0800 | [diff] [blame] | 4 | * |
| 5 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 6 | * copy of this software and associated documentation files (the "Software"), |
| 7 | * to deal in the Software without restriction, including without limitation |
| 8 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 9 | * and/or sell copies of the Software, and to permit persons to whom the |
| 10 | * Software is furnished to do so, subject to the following conditions: |
| 11 | * |
| 12 | * The above copyright notice and this permission notice shall be included |
| 13 | * in all copies or substantial portions of the Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 21 | * DEALINGS IN THE SOFTWARE. |
| Chia-I Wu | 44e4236 | 2014-09-02 08:32:09 +0800 | [diff] [blame] | 22 | * |
| Courtney Goeltzenleuchter | 96cd795 | 2015-10-30 11:14:30 -0600 | [diff] [blame] | 23 | * Author: Chia-I Wu <olvaffe@gmail.com> |
| 24 | * Author: Chia-I Wu <olv@lunarg.com> |
| 25 | * Author: Chris Forbes <chrisf@ijw.co.nz> |
| 26 | * Author: Courtney Goeltzenleuchter <courtney@LunarG.com> |
| 27 | * Author: Jon Ashburn <jon@lunarg.com> |
| 28 | * Author: Tony Barbour <tony@LunarG.com> |
| 29 | * |
| Chia-I Wu | 468e3c3 | 2014-08-04 08:03:57 +0800 | [diff] [blame] | 30 | */ |
| 31 | |
| 32 | #ifndef LOADER_H |
| 33 | #define LOADER_H |
| 34 | |
| David Pinedo | 329ca9e | 2015-11-06 12:54:48 -0700 | [diff] [blame] | 35 | #include <vulkan/vulkan.h> |
| Jon Ashburn | 9945600 | 2015-11-06 11:02:40 -0700 | [diff] [blame] | 36 | #include <vk_loader_platform.h> |
| Ian Elliott | 64070a8 | 2015-11-17 17:29:40 -0700 | [diff] [blame] | 37 | |
| David Pinedo | a31fe0b | 2015-11-24 09:00:24 -0700 | [diff] [blame] | 38 | #include <vulkan/vk_lunarg_debug_report.h> |
| Ian Elliott | e504c01 | 2015-11-18 14:57:08 -0700 | [diff] [blame^] | 39 | |
| David Pinedo | 329ca9e | 2015-11-06 12:54:48 -0700 | [diff] [blame] | 40 | #include <vulkan/vk_layer.h> |
| 41 | #include <vulkan/vk_icd.h> |
| Chia-I Wu | 1d6731b | 2015-04-11 15:34:07 +0800 | [diff] [blame] | 42 | #include <assert.h> |
| 43 | |
| Chia-I Wu | 468e3c3 | 2014-08-04 08:03:57 +0800 | [diff] [blame] | 44 | #if defined(__GNUC__) && __GNUC__ >= 4 |
| 45 | # define LOADER_EXPORT __attribute__((visibility("default"))) |
| 46 | #elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590) |
| 47 | # define LOADER_EXPORT __attribute__((visibility("default"))) |
| 48 | #else |
| 49 | # define LOADER_EXPORT |
| 50 | #endif |
| 51 | |
| Jon Ashburn | 0b72805 | 2015-08-04 10:22:33 -0600 | [diff] [blame] | 52 | #define MAX_STRING_SIZE 1024 |
| Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 53 | #define VK_MAJOR(version) (version >> 22) |
| 54 | #define VK_MINOR(version) ((version >> 12) & 0x3ff) |
| 55 | #define VK_PATCH(version) (version & 0xfff) |
| Jon Ashburn | fce93d9 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 56 | |
| Jon Ashburn | 68a6392 | 2015-07-02 09:40:15 -0600 | [diff] [blame] | 57 | enum layer_type { |
| Jon Ashburn | 535bd00 | 2015-07-02 16:10:32 -0600 | [diff] [blame] | 58 | VK_LAYER_TYPE_DEVICE_EXPLICIT = 0x1, |
| 59 | VK_LAYER_TYPE_INSTANCE_EXPLICIT = 0x2, |
| 60 | VK_LAYER_TYPE_GLOBAL_EXPLICIT = 0x3, // both instance and device layer, bitwise |
| 61 | VK_LAYER_TYPE_DEVICE_IMPLICIT = 0x4, |
| 62 | VK_LAYER_TYPE_INSTANCE_IMPLICIT = 0x8, |
| 63 | VK_LAYER_TYPE_GLOBAL_IMPLICIT = 0xc, // both instance and device layer, bitwise |
| Jon Ashburn | 68a6392 | 2015-07-02 09:40:15 -0600 | [diff] [blame] | 64 | }; |
| 65 | |
| Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 66 | struct loader_extension_list { |
| 67 | size_t capacity; |
| 68 | uint32_t count; |
| Jon Ashburn | c4748dc | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 69 | VkExtensionProperties *list; |
| Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 70 | }; |
| 71 | |
| Jon Ashburn | 68a6392 | 2015-07-02 09:40:15 -0600 | [diff] [blame] | 72 | struct loader_name_value { |
| Jon Ashburn | 0b72805 | 2015-08-04 10:22:33 -0600 | [diff] [blame] | 73 | char name[MAX_STRING_SIZE]; |
| 74 | char value[MAX_STRING_SIZE]; |
| Jon Ashburn | 68a6392 | 2015-07-02 09:40:15 -0600 | [diff] [blame] | 75 | }; |
| 76 | |
| 77 | struct loader_lib_info { |
| Jon Ashburn | e9ca8fa | 2015-08-20 16:35:30 -0600 | [diff] [blame] | 78 | char lib_name[MAX_STRING_SIZE]; |
| Jon Ashburn | 68a6392 | 2015-07-02 09:40:15 -0600 | [diff] [blame] | 79 | uint32_t ref_count; |
| 80 | loader_platform_dl_handle lib_handle; |
| 81 | }; |
| Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 82 | |
| Jon Ashburn | 68a6392 | 2015-07-02 09:40:15 -0600 | [diff] [blame] | 83 | struct loader_layer_functions { |
| Jon Ashburn | 0b72805 | 2015-08-04 10:22:33 -0600 | [diff] [blame] | 84 | char str_gipa[MAX_STRING_SIZE]; |
| 85 | char str_gdpa[MAX_STRING_SIZE]; |
| Jon Ashburn | 68a6392 | 2015-07-02 09:40:15 -0600 | [diff] [blame] | 86 | PFN_vkGetInstanceProcAddr get_instance_proc_addr; |
| 87 | PFN_vkGetDeviceProcAddr get_device_proc_addr; |
| 88 | }; |
| Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 89 | |
| Jon Ashburn | 68a6392 | 2015-07-02 09:40:15 -0600 | [diff] [blame] | 90 | struct loader_layer_properties { |
| Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 91 | VkLayerProperties info; |
| Jon Ashburn | 68a6392 | 2015-07-02 09:40:15 -0600 | [diff] [blame] | 92 | enum layer_type type; |
| Jon Ashburn | e9ca8fa | 2015-08-20 16:35:30 -0600 | [diff] [blame] | 93 | char lib_name[MAX_STRING_SIZE]; |
| Jon Ashburn | 68a6392 | 2015-07-02 09:40:15 -0600 | [diff] [blame] | 94 | struct loader_layer_functions functions; |
| 95 | struct loader_extension_list instance_extension_list; |
| 96 | struct loader_extension_list device_extension_list; |
| 97 | struct loader_name_value disable_env_var; |
| 98 | struct loader_name_value enable_env_var; |
| 99 | }; |
| 100 | |
| 101 | struct loader_layer_list { |
| 102 | size_t capacity; |
| 103 | uint32_t count; |
| 104 | struct loader_layer_properties *list; |
| Jon Ashburn | fce93d9 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 105 | }; |
| 106 | |
| Courtney Goeltzenleuchter | c5cf7d7 | 2015-07-05 12:53:31 -0600 | [diff] [blame] | 107 | struct loader_layer_library_list { |
| 108 | size_t capacity; |
| 109 | uint32_t count; |
| 110 | struct loader_lib_info *list; |
| 111 | }; |
| 112 | |
| Jon Ashburn | 429e19f | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 113 | struct loader_dispatch_hash_list { |
| 114 | size_t capacity; |
| 115 | uint32_t count; |
| 116 | uint32_t *index; // index into the dev_ext dispatch table |
| 117 | }; |
| 118 | |
| 119 | #define MAX_NUM_DEV_EXTS 250 |
| 120 | // loader_dispatch_hash_entry and loader_dev_ext_dispatch_table.DevExt have one to one |
| 121 | // correspondence; one loader_dispatch_hash_entry for one DevExt dispatch entry. |
| 122 | // Also have a one to one correspondence with functions in dev_ext_trampoline.c |
| 123 | struct loader_dispatch_hash_entry { |
| 124 | char *func_name; |
| 125 | struct loader_dispatch_hash_list list; // to handle hashing collisions |
| 126 | }; |
| 127 | |
| 128 | typedef void (VKAPI_PTR *PFN_vkDevExt)(VkDevice device); |
| 129 | struct loader_dev_ext_dispatch_table { |
| 130 | PFN_vkDevExt DevExt[MAX_NUM_DEV_EXTS]; |
| 131 | }; |
| 132 | |
| 133 | struct loader_dev_dispatch_table { |
| 134 | VkLayerDispatchTable core_dispatch; |
| 135 | struct loader_dev_ext_dispatch_table ext_dispatch; |
| 136 | }; |
| 137 | |
| Jon Ashburn | cb5a5ac | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 138 | /* per CreateDevice structure */ |
| 139 | struct loader_device { |
| Jon Ashburn | 429e19f | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 140 | struct loader_dev_dispatch_table loader_dispatch; |
| Jon Ashburn | cb5a5ac | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 141 | VkDevice device; // device object from the icd |
| 142 | |
| 143 | uint32_t app_extension_count; |
| 144 | VkExtensionProperties *app_extension_props; |
| 145 | |
| Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 146 | struct loader_layer_list activated_layer_list; |
| Jon Ashburn | cb5a5ac | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 147 | |
| 148 | struct loader_device *next; |
| 149 | }; |
| 150 | |
| Jon Ashburn | 6069926 | 2015-06-10 16:11:42 -0600 | [diff] [blame] | 151 | /* per ICD structure */ |
| Jon Ashburn | 2666e2f | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 152 | struct loader_icd { |
| Jon Ashburn | e9ca8fa | 2015-08-20 16:35:30 -0600 | [diff] [blame] | 153 | // pointers to find other structs |
| 154 | const struct loader_scanned_icds *this_icd_lib; |
| 155 | const struct loader_instance *this_instance; |
| Jon Ashburn | 2666e2f | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 156 | |
| Jon Ashburn | cb5a5ac | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 157 | struct loader_device *logical_device_list; |
| Jon Ashburn | 2666e2f | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 158 | VkInstance instance; // instance object from the icd |
| Jon Ashburn | 1245cec | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 159 | PFN_vkGetDeviceProcAddr GetDeviceProcAddr; |
| Jon Ashburn | 2666e2f | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 160 | PFN_vkDestroyInstance DestroyInstance; |
| 161 | PFN_vkEnumeratePhysicalDevices EnumeratePhysicalDevices; |
| Chris Forbes | d757630 | 2015-06-21 22:55:02 +1200 | [diff] [blame] | 162 | PFN_vkGetPhysicalDeviceFeatures GetPhysicalDeviceFeatures; |
| Courtney Goeltzenleuchter | 4da96aa | 2015-07-12 12:52:09 -0600 | [diff] [blame] | 163 | PFN_vkGetPhysicalDeviceFormatProperties GetPhysicalDeviceFormatProperties; |
| Jon Ashburn | 4e18956 | 2015-07-23 18:49:07 -0600 | [diff] [blame] | 164 | PFN_vkGetPhysicalDeviceImageFormatProperties GetPhysicalDeviceImageFormatProperties; |
| Jon Ashburn | 2666e2f | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 165 | PFN_vkCreateDevice CreateDevice; |
| Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 166 | PFN_vkGetPhysicalDeviceProperties GetPhysicalDeviceProperties; |
| Cody Northrop | ef72e2a | 2015-08-03 17:04:53 -0600 | [diff] [blame] | 167 | PFN_vkGetPhysicalDeviceQueueFamilyProperties GetPhysicalDeviceQueueFamilyProperties; |
| Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 168 | PFN_vkGetPhysicalDeviceMemoryProperties GetPhysicalDeviceMemoryProperties; |
| Courtney Goeltzenleuchter | 74c4ce9 | 2015-09-14 17:22:16 -0600 | [diff] [blame] | 169 | PFN_vkEnumerateDeviceExtensionProperties EnumerateDeviceExtensionProperties; |
| Mark Lobodzinski | 83d4e6a | 2015-07-03 15:58:09 -0600 | [diff] [blame] | 170 | PFN_vkGetPhysicalDeviceSparseImageFormatProperties GetPhysicalDeviceSparseImageFormatProperties; |
| Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 171 | PFN_vkDbgCreateMsgCallback DbgCreateMsgCallback; |
| 172 | PFN_vkDbgDestroyMsgCallback DbgDestroyMsgCallback; |
| Ian Elliott | 338dedb | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 173 | PFN_vkGetPhysicalDeviceSurfaceSupportKHR GetPhysicalDeviceSurfaceSupportKHR; |
| Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 174 | |
| Jon Ashburn | cb5a5ac | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 175 | struct loader_icd *next; |
| Jon Ashburn | 2666e2f | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 176 | }; |
| 177 | |
| Jon Ashburn | 754f199 | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 178 | /* per ICD library structure */ |
| 179 | struct loader_icd_libs { |
| 180 | size_t capacity; |
| 181 | uint32_t count; |
| 182 | struct loader_scanned_icds *list; |
| 183 | }; |
| 184 | |
| Jon Ashburn | 6069926 | 2015-06-10 16:11:42 -0600 | [diff] [blame] | 185 | /* per instance structure */ |
| Jon Ashburn | fce93d9 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 186 | struct loader_instance { |
| Jon Ashburn | 2666e2f | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 187 | VkLayerInstanceDispatchTable *disp; // must be first entry in structure |
| 188 | |
| Jon Ashburn | fce93d9 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 189 | uint32_t total_gpu_count; |
| Jon Ashburn | 251258f | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 190 | struct loader_physical_device *phys_devs; |
| Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 191 | uint32_t total_icd_count; |
| Jon Ashburn | fce93d9 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 192 | struct loader_icd *icds; |
| 193 | struct loader_instance *next; |
| Jon Ashburn | 85f9807 | 2015-08-14 14:49:22 -0600 | [diff] [blame] | 194 | struct loader_extension_list ext_list; // icds and loaders extensions |
| Jon Ashburn | 754f199 | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 195 | struct loader_icd_libs icd_libs; |
| Jon Ashburn | e9ca8fa | 2015-08-20 16:35:30 -0600 | [diff] [blame] | 196 | struct loader_layer_list instance_layer_list; |
| 197 | struct loader_layer_list device_layer_list; |
| Jon Ashburn | 429e19f | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 198 | struct loader_dispatch_hash_entry disp_hash[MAX_NUM_DEV_EXTS]; |
| Jon Ashburn | e9ca8fa | 2015-08-20 16:35:30 -0600 | [diff] [blame] | 199 | |
| Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 200 | struct loader_msg_callback_map_entry *icd_msg_callback_map; |
| 201 | |
| Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 202 | struct loader_layer_list activated_layer_list; |
| Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 203 | |
| 204 | bool debug_report_enabled; |
| Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 205 | VkLayerDbgFunctionNode *DbgFunctionHead; |
| Courtney Goeltzenleuchter | b620ace | 2015-07-05 11:28:29 -0600 | [diff] [blame] | 206 | |
| Chia-I Wu | 1f85191 | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 207 | VkAllocationCallbacks alloc_callbacks; |
| Ian Elliott | 1d73e66 | 2015-07-06 14:36:13 -0600 | [diff] [blame] | 208 | |
| 209 | bool wsi_swapchain_enabled; |
| Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 210 | }; |
| 211 | |
| Jon Ashburn | 251258f | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 212 | /* per enumerated PhysicalDevice structure */ |
| 213 | struct loader_physical_device { |
| 214 | VkLayerInstanceDispatchTable *disp; // must be first entry in structure |
| 215 | struct loader_instance *this_instance; |
| 216 | struct loader_icd *this_icd; |
| 217 | VkPhysicalDevice phys_dev; // object from ICD |
| 218 | /* |
| 219 | * Fill in the cache of available device extensions from |
| Jon Ashburn | db5a5bc | 2015-11-02 17:40:01 -0700 | [diff] [blame] | 220 | * this physical device. This cache can be used during CreateDevice |
| Jon Ashburn | 251258f | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 221 | */ |
| 222 | struct loader_extension_list device_extension_cache; |
| 223 | }; |
| 224 | |
| Jon Ashburn | fce93d9 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 225 | struct loader_struct { |
| 226 | struct loader_instance *instances; |
| Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 227 | |
| 228 | unsigned int loaded_layer_lib_count; |
| Courtney Goeltzenleuchter | a2f21d0 | 2015-10-07 09:00:34 -0600 | [diff] [blame] | 229 | size_t loaded_layer_lib_capacity; |
| Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 230 | struct loader_lib_info *loaded_layer_lib_list; |
| Jon Ashburn | 754f199 | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 231 | // TODO add ref counting of ICD libraries |
| Jon Ashburn | 1b111de | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 232 | // TODO use this struct loader_layer_library_list scanned_layer_libraries; |
| Jon Ashburn | 754f199 | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 233 | // TODO add list of icd libraries for ref counting them for closure |
| Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 234 | }; |
| 235 | |
| 236 | struct loader_scanned_icds { |
| 237 | char *lib_name; |
| 238 | loader_platform_dl_handle handle; |
| Jon Ashburn | 0083b22 | 2015-11-17 17:35:40 -0700 | [diff] [blame] | 239 | uint32_t api_version; |
| Jon Ashburn | ce7e3d9 | 2015-07-16 10:17:29 -0600 | [diff] [blame] | 240 | PFN_vkGetInstanceProcAddr GetInstanceProcAddr; |
| Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 241 | PFN_vkCreateInstance CreateInstance; |
| Courtney Goeltzenleuchter | 74c4ce9 | 2015-09-14 17:22:16 -0600 | [diff] [blame] | 242 | PFN_vkEnumerateInstanceExtensionProperties EnumerateInstanceExtensionProperties; |
| Jon Ashburn | fce93d9 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 243 | }; |
| 244 | |
| Jon Ashburn | 68a6392 | 2015-07-02 09:40:15 -0600 | [diff] [blame] | 245 | static inline struct loader_instance *loader_instance(VkInstance instance) { |
| 246 | return (struct loader_instance *) instance; |
| 247 | } |
| 248 | |
| Tony Barbour | de4124d | 2015-07-03 10:33:54 -0600 | [diff] [blame] | 249 | static inline void loader_set_dispatch(void* obj, const void *data) |
| Chia-I Wu | 1d6731b | 2015-04-11 15:34:07 +0800 | [diff] [blame] | 250 | { |
| 251 | *((const void **) obj) = data; |
| 252 | } |
| 253 | |
| Tony Barbour | de4124d | 2015-07-03 10:33:54 -0600 | [diff] [blame] | 254 | static inline VkLayerDispatchTable *loader_get_dispatch(const void* obj) |
| Chia-I Wu | 1d6731b | 2015-04-11 15:34:07 +0800 | [diff] [blame] | 255 | { |
| Jon Ashburn | da7c20d | 2015-05-01 18:00:33 -0600 | [diff] [blame] | 256 | return *((VkLayerDispatchTable **) obj); |
| Chia-I Wu | 1d6731b | 2015-04-11 15:34:07 +0800 | [diff] [blame] | 257 | } |
| 258 | |
| Jon Ashburn | 429e19f | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 259 | static inline struct loader_dev_dispatch_table *loader_get_dev_dispatch(const void* obj) |
| 260 | { |
| 261 | return *((struct loader_dev_dispatch_table **) obj); |
| 262 | } |
| 263 | |
| Tony Barbour | de4124d | 2015-07-03 10:33:54 -0600 | [diff] [blame] | 264 | static inline VkLayerInstanceDispatchTable *loader_get_instance_dispatch(const void* obj) |
| Jon Ashburn | fce93d9 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 265 | { |
| 266 | return *((VkLayerInstanceDispatchTable **) obj); |
| 267 | } |
| 268 | |
| Tony Barbour | de4124d | 2015-07-03 10:33:54 -0600 | [diff] [blame] | 269 | static inline void loader_init_dispatch(void* obj, const void *data) |
| Chia-I Wu | 1d6731b | 2015-04-11 15:34:07 +0800 | [diff] [blame] | 270 | { |
| Jon Ashburn | 166641e | 2015-04-15 13:34:33 -0600 | [diff] [blame] | 271 | #ifdef DEBUG |
| Chia-I Wu | 1d6731b | 2015-04-11 15:34:07 +0800 | [diff] [blame] | 272 | assert(valid_loader_magic_value(obj) && |
| 273 | "Incompatible ICD, first dword must be initialized to ICD_LOADER_MAGIC. See loader/README.md for details."); |
| Jon Ashburn | 166641e | 2015-04-15 13:34:33 -0600 | [diff] [blame] | 274 | #endif |
| Chia-I Wu | 1d6731b | 2015-04-11 15:34:07 +0800 | [diff] [blame] | 275 | |
| Jon Ashburn | da7c20d | 2015-05-01 18:00:33 -0600 | [diff] [blame] | 276 | loader_set_dispatch(obj, data); |
| Chia-I Wu | 1d6731b | 2015-04-11 15:34:07 +0800 | [diff] [blame] | 277 | } |
| 278 | |
| Jon Ashburn | fce93d9 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 279 | /* global variables used across files */ |
| 280 | extern struct loader_struct loader; |
| Jon Ashburn | 413d658 | 2015-08-28 15:19:27 -0600 | [diff] [blame] | 281 | extern THREAD_LOCAL_DECL struct loader_instance *tls_instance; |
| Jon Ashburn | 754f199 | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 282 | extern LOADER_PLATFORM_THREAD_ONCE_DEFINITION(once_init); |
| Jon Ashburn | b40f256 | 2015-05-29 13:15:39 -0600 | [diff] [blame] | 283 | extern loader_platform_thread_mutex loader_lock; |
| Jon Ashburn | d02fc2c | 2015-09-22 13:11:00 -0600 | [diff] [blame] | 284 | extern loader_platform_thread_mutex loader_json_lock; |
| Jon Ashburn | b40f256 | 2015-05-29 13:15:39 -0600 | [diff] [blame] | 285 | extern const VkLayerInstanceDispatchTable instance_disp; |
| Jon Ashburn | 301c5f0 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 286 | |
| Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 287 | struct loader_msg_callback_map_entry { |
| 288 | VkDbgMsgCallback icd_obj; |
| 289 | VkDbgMsgCallback loader_obj; |
| 290 | }; |
| 291 | |
| 292 | bool compare_vk_extension_properties( |
| 293 | const VkExtensionProperties* op1, |
| 294 | const VkExtensionProperties* op2); |
| 295 | |
| Jon Ashburn | e9ca8fa | 2015-08-20 16:35:30 -0600 | [diff] [blame] | 296 | VkResult loader_validate_layers( |
| 297 | const uint32_t layer_count, |
| 298 | const char * const *ppEnabledLayerNames, |
| 299 | const struct loader_layer_list *list); |
| Courtney Goeltzenleuchter | 5d9f29b | 2015-07-06 17:45:08 -0600 | [diff] [blame] | 300 | |
| 301 | VkResult loader_validate_instance_extensions( |
| Jon Ashburn | c1d1eb7 | 2015-08-14 11:57:54 -0600 | [diff] [blame] | 302 | const struct loader_extension_list *icd_exts, |
| Jon Ashburn | 182b830 | 2015-08-11 14:49:54 -0600 | [diff] [blame] | 303 | const struct loader_layer_list *instance_layer, |
| Courtney Goeltzenleuchter | 5d9f29b | 2015-07-06 17:45:08 -0600 | [diff] [blame] | 304 | const VkInstanceCreateInfo* pCreateInfo); |
| 305 | |
| Jon Ashburn | fce93d9 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 306 | /* instance layer chain termination entrypoint definitions */ |
| Chia-I Wu | af9e4fd | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 307 | VKAPI_ATTR VkResult VKAPI_CALL loader_CreateInstance( |
| Jon Ashburn | fce93d9 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 308 | const VkInstanceCreateInfo* pCreateInfo, |
| Chia-I Wu | 1f85191 | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 309 | const VkAllocationCallbacks* pAllocator, |
| Jon Ashburn | fce93d9 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 310 | VkInstance* pInstance); |
| Chia-I Wu | 1d6731b | 2015-04-11 15:34:07 +0800 | [diff] [blame] | 311 | |
| Chia-I Wu | af9e4fd | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 312 | VKAPI_ATTR void VKAPI_CALL loader_DestroyInstance( |
| Chia-I Wu | 69f4012 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 313 | VkInstance instance, |
| Chia-I Wu | 1f85191 | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 314 | const VkAllocationCallbacks* pAllocator); |
| Jon Ashburn | fce93d9 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 315 | |
| Chia-I Wu | af9e4fd | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 316 | VKAPI_ATTR VkResult VKAPI_CALL loader_EnumeratePhysicalDevices( |
| Jon Ashburn | fce93d9 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 317 | VkInstance instance, |
| 318 | uint32_t* pPhysicalDeviceCount, |
| 319 | VkPhysicalDevice* pPhysicalDevices); |
| Chris Forbes | d757630 | 2015-06-21 22:55:02 +1200 | [diff] [blame] | 320 | |
| Chia-I Wu | af9e4fd | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 321 | VKAPI_ATTR void VKAPI_CALL loader_GetPhysicalDeviceFeatures( |
| Chris Forbes | d757630 | 2015-06-21 22:55:02 +1200 | [diff] [blame] | 322 | VkPhysicalDevice physicalDevice, |
| 323 | VkPhysicalDeviceFeatures* pFeatures); |
| 324 | |
| Chia-I Wu | af9e4fd | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 325 | VKAPI_ATTR void VKAPI_CALL loader_GetPhysicalDeviceFormatProperties( |
| Chris Forbes | d757630 | 2015-06-21 22:55:02 +1200 | [diff] [blame] | 326 | VkPhysicalDevice physicalDevice, |
| 327 | VkFormat format, |
| 328 | VkFormatProperties* pFormatInfo); |
| 329 | |
| Chia-I Wu | af9e4fd | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 330 | VKAPI_ATTR VkResult VKAPI_CALL loader_GetPhysicalDeviceImageFormatProperties( |
| Chia-I Wu | 5202c54 | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 331 | VkPhysicalDevice physicalDevice, |
| Jon Ashburn | 4e18956 | 2015-07-23 18:49:07 -0600 | [diff] [blame] | 332 | VkFormat format, |
| 333 | VkImageType type, |
| 334 | VkImageTiling tiling, |
| 335 | VkImageUsageFlags usage, |
| Courtney Goeltzenleuchter | 83c95f8 | 2015-09-10 13:44:12 -0600 | [diff] [blame] | 336 | VkImageCreateFlags flags, |
| Jon Ashburn | 4e18956 | 2015-07-23 18:49:07 -0600 | [diff] [blame] | 337 | VkImageFormatProperties* pImageFormatProperties); |
| 338 | |
| Chia-I Wu | af9e4fd | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 339 | VKAPI_ATTR void VKAPI_CALL loader_GetPhysicalDeviceSparseImageFormatProperties( |
| Mark Lobodzinski | 83d4e6a | 2015-07-03 15:58:09 -0600 | [diff] [blame] | 340 | VkPhysicalDevice physicalDevice, |
| 341 | VkFormat format, |
| 342 | VkImageType type, |
| Chia-I Wu | 3138d6a | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 343 | VkSampleCountFlagBits samples, |
| Mark Lobodzinski | 83d4e6a | 2015-07-03 15:58:09 -0600 | [diff] [blame] | 344 | VkImageUsageFlags usage, |
| 345 | VkImageTiling tiling, |
| 346 | uint32_t* pNumProperties, |
| 347 | VkSparseImageFormatProperties* pProperties); |
| Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 348 | |
| Chia-I Wu | af9e4fd | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 349 | VKAPI_ATTR void VKAPI_CALL loader_GetPhysicalDeviceProperties ( |
| Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 350 | VkPhysicalDevice physicalDevice, |
| 351 | VkPhysicalDeviceProperties* pProperties); |
| 352 | |
| Chia-I Wu | af9e4fd | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 353 | VKAPI_ATTR VkResult VKAPI_CALL loader_EnumerateDeviceExtensionProperties (VkPhysicalDevice physicalDevice, |
| Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 354 | const char *pLayerName, uint32_t *pCount, |
| Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 355 | VkExtensionProperties* pProperties); |
| 356 | |
| Chia-I Wu | af9e4fd | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 357 | VKAPI_ATTR VkResult VKAPI_CALL loader_EnumerateDeviceLayerProperties (VkPhysicalDevice physicalDevice, |
| Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 358 | uint32_t *pCount, |
| 359 | VkLayerProperties* pProperties); |
| Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 360 | |
| Chia-I Wu | af9e4fd | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 361 | VKAPI_ATTR void VKAPI_CALL loader_GetPhysicalDeviceQueueFamilyProperties ( |
| Cody Northrop | ef72e2a | 2015-08-03 17:04:53 -0600 | [diff] [blame] | 362 | VkPhysicalDevice physicalDevice, |
| 363 | uint32_t* pCount, |
| 364 | VkQueueFamilyProperties* pProperties); |
| Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 365 | |
| Chia-I Wu | af9e4fd | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 366 | VKAPI_ATTR void VKAPI_CALL loader_GetPhysicalDeviceMemoryProperties ( |
| Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 367 | VkPhysicalDevice physicalDevice, |
| 368 | VkPhysicalDeviceMemoryProperties * pProperties); |
| Jon Ashburn | b40f256 | 2015-05-29 13:15:39 -0600 | [diff] [blame] | 369 | |
| Chia-I Wu | af9e4fd | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 370 | VKAPI_ATTR VkResult VKAPI_CALL loader_CreateDevice( |
| Jon Ashburn | 2666e2f | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 371 | VkPhysicalDevice gpu, |
| 372 | const VkDeviceCreateInfo* pCreateInfo, |
| Chia-I Wu | 1f85191 | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 373 | const VkAllocationCallbacks* pAllocator, |
| Jon Ashburn | 2666e2f | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 374 | VkDevice* pDevice); |
| Jon Ashburn | fce93d9 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 375 | |
| Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 376 | /* helper function definitions */ |
| Jon Ashburn | 754f199 | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 377 | void loader_initialize(void); |
| Jon Ashburn | 6037841 | 2015-07-02 12:59:25 -0600 | [diff] [blame] | 378 | bool has_vk_extension_property_array( |
| 379 | const VkExtensionProperties *vk_ext_prop, |
| 380 | const uint32_t count, |
| 381 | const VkExtensionProperties *ext_array); |
| Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 382 | bool has_vk_extension_property( |
| 383 | const VkExtensionProperties *vk_ext_prop, |
| 384 | const struct loader_extension_list *ext_list); |
| Jon Ashburn | fce93d9 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 385 | |
| Jon Ashburn | 251258f | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 386 | VkResult loader_add_to_ext_list( |
| Jon Ashburn | e58f1a3 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 387 | const struct loader_instance *inst, |
| Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 388 | struct loader_extension_list *ext_list, |
| 389 | uint32_t prop_list_count, |
| Jon Ashburn | c4748dc | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 390 | const VkExtensionProperties *props); |
| Jon Ashburn | e58f1a3 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 391 | void loader_destroy_ext_list( |
| 392 | const struct loader_instance *inst, |
| 393 | struct loader_extension_list *ext_info); |
| 394 | void loader_delete_layer_properties( |
| 395 | const struct loader_instance *inst, |
| 396 | struct loader_layer_list *layer_list); |
| Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 397 | void loader_add_to_layer_list( |
| Jon Ashburn | e58f1a3 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 398 | const struct loader_instance *inst, |
| Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 399 | struct loader_layer_list *list, |
| 400 | uint32_t prop_list_count, |
| 401 | const struct loader_layer_properties *props); |
| Jon Ashburn | e58f1a3 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 402 | void loader_scanned_icd_clear( |
| 403 | const struct loader_instance *inst, |
| 404 | struct loader_icd_libs *icd_libs); |
| 405 | void loader_icd_scan( |
| 406 | const struct loader_instance *inst, |
| 407 | struct loader_icd_libs *icds); |
| Jon Ashburn | 182b830 | 2015-08-11 14:49:54 -0600 | [diff] [blame] | 408 | void loader_layer_scan( |
| Jon Ashburn | e58f1a3 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 409 | const struct loader_instance *inst, |
| Jon Ashburn | 182b830 | 2015-08-11 14:49:54 -0600 | [diff] [blame] | 410 | struct loader_layer_list *instance_layers, |
| 411 | struct loader_layer_list *device_layers); |
| Jon Ashburn | 754f199 | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 412 | void loader_get_icd_loader_instance_extensions( |
| Jon Ashburn | e58f1a3 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 413 | const struct loader_instance *inst, |
| Jon Ashburn | 754f199 | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 414 | struct loader_icd_libs *icd_libs, |
| 415 | struct loader_extension_list *inst_exts); |
| Jon Ashburn | e58f1a3 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 416 | struct loader_icd *loader_get_icd_and_device( |
| 417 | const VkDevice device, |
| 418 | struct loader_device **found_dev); |
| Jon Ashburn | 429e19f | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 419 | void *loader_dev_ext_gpa( |
| 420 | struct loader_instance *inst, |
| 421 | const char *funcName); |
| 422 | void *loader_get_dev_ext_trampoline( |
| 423 | uint32_t index); |
| Jon Ashburn | 0c5eea2 | 2015-09-30 12:56:42 -0600 | [diff] [blame] | 424 | struct loader_instance *loader_get_instance( |
| 425 | const VkInstance instance); |
| Jon Ashburn | e58f1a3 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 426 | void loader_remove_logical_device( |
| 427 | const struct loader_instance *inst, |
| Jon Ashburn | dbf8cee | 2015-11-19 15:43:26 -0700 | [diff] [blame] | 428 | struct loader_icd *icd, |
| 429 | struct loader_device *found_dev); |
| Jon Ashburn | 182b830 | 2015-08-11 14:49:54 -0600 | [diff] [blame] | 430 | VkResult loader_enable_instance_layers( |
| 431 | struct loader_instance *inst, |
| 432 | const VkInstanceCreateInfo *pCreateInfo, |
| 433 | const struct loader_layer_list *instance_layers); |
| Jon Ashburn | cb5a5ac | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 434 | void loader_deactivate_instance_layers(struct loader_instance *instance); |
| Jon Ashburn | fce93d9 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 435 | uint32_t loader_activate_instance_layers(struct loader_instance *inst); |
| Courtney Goeltzenleuchter | 23b5f8d | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 436 | void loader_activate_instance_layer_extensions(struct loader_instance *inst); |
| Courtney Goeltzenleuchter | b620ace | 2015-07-05 11:28:29 -0600 | [diff] [blame] | 437 | |
| 438 | void* loader_heap_alloc( |
| Jon Ashburn | e58f1a3 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 439 | const struct loader_instance *instance, |
| Jon Ashburn | 182b830 | 2015-08-11 14:49:54 -0600 | [diff] [blame] | 440 | size_t size, |
| Chia-I Wu | 1f85191 | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 441 | VkSystemAllocationScope allocationScope); |
| Courtney Goeltzenleuchter | b620ace | 2015-07-05 11:28:29 -0600 | [diff] [blame] | 442 | |
| Courtney Goeltzenleuchter | b620ace | 2015-07-05 11:28:29 -0600 | [diff] [blame] | 443 | void loader_heap_free( |
| Jon Ashburn | e58f1a3 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 444 | const struct loader_instance *instance, |
| Chia-I Wu | 1f85191 | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 445 | void *pMemory); |
| Jon Ashburn | 413d658 | 2015-08-28 15:19:27 -0600 | [diff] [blame] | 446 | |
| 447 | void *loader_tls_heap_alloc(size_t size); |
| 448 | |
| Chia-I Wu | 1f85191 | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 449 | void loader_tls_heap_free(void *pMemory); |
| Chia-I Wu | 468e3c3 | 2014-08-04 08:03:57 +0800 | [diff] [blame] | 450 | #endif /* LOADER_H */ |