Chia-I Wu | 1930060 | 2014-08-04 08:03:57 +0800 | [diff] [blame] | 1 | /* |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 2 | * Vulkan |
Chia-I Wu | 1930060 | 2014-08-04 08:03:57 +0800 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2014 LunarG, Inc. |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 7 | * copy of this software and associated documentation files (the "Software"), |
| 8 | * to deal in the Software without restriction, including without limitation |
| 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 10 | * and/or sell copies of the Software, and to permit persons to whom the |
| 11 | * Software is furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included |
| 14 | * in all copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 22 | * DEALINGS IN THE SOFTWARE. |
Chia-I Wu | 701f3f6 | 2014-09-02 08:32:09 +0800 | [diff] [blame] | 23 | * |
| 24 | * Authors: |
| 25 | * Chia-I Wu <olv@lunarg.com> |
Chia-I Wu | 1930060 | 2014-08-04 08:03:57 +0800 | [diff] [blame] | 26 | */ |
| 27 | |
| 28 | #ifndef LOADER_H |
| 29 | #define LOADER_H |
| 30 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 31 | #include <vulkan.h> |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 32 | #include <vk_debug_report_lunarg.h> |
Ian Elliott | d3ef02f | 2015-07-06 14:36:13 -0600 | [diff] [blame] | 33 | #include <vk_wsi_swapchain.h> |
Tobin Ehlis | 0c6f9ee | 2015-07-03 09:42:57 -0600 | [diff] [blame] | 34 | #include <vk_layer.h> |
| 35 | #include <vk_icd.h> |
Chia-I Wu | 5291c76 | 2015-04-11 15:34:07 +0800 | [diff] [blame] | 36 | #include <assert.h> |
| 37 | |
Chia-I Wu | 1930060 | 2014-08-04 08:03:57 +0800 | [diff] [blame] | 38 | #if defined(__GNUC__) && __GNUC__ >= 4 |
| 39 | # define LOADER_EXPORT __attribute__((visibility("default"))) |
| 40 | #elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590) |
| 41 | # define LOADER_EXPORT __attribute__((visibility("default"))) |
| 42 | #else |
| 43 | # define LOADER_EXPORT |
| 44 | #endif |
| 45 | |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 46 | #define MAX_EXTENSION_NAME_SIZE (VK_MAX_EXTENSION_NAME-1) |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 47 | #define MAX_GPUS_PER_ICD 16 |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 48 | |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 49 | #define VK_MAJOR(version) (version >> 22) |
| 50 | #define VK_MINOR(version) ((version >> 12) & 0x3ff) |
| 51 | #define VK_PATCH(version) (version & 0xfff) |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 52 | enum extension_origin { |
| 53 | VK_EXTENSION_ORIGIN_ICD, |
| 54 | VK_EXTENSION_ORIGIN_LAYER, |
| 55 | VK_EXTENSION_ORIGIN_LOADER |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 56 | }; |
| 57 | |
Jon Ashburn | 5ef2060 | 2015-07-02 09:40:15 -0600 | [diff] [blame] | 58 | enum layer_type { |
Jon Ashburn | 0c26e71 | 2015-07-02 16:10:32 -0600 | [diff] [blame] | 59 | VK_LAYER_TYPE_DEVICE_EXPLICIT = 0x1, |
| 60 | VK_LAYER_TYPE_INSTANCE_EXPLICIT = 0x2, |
| 61 | VK_LAYER_TYPE_GLOBAL_EXPLICIT = 0x3, // both instance and device layer, bitwise |
| 62 | VK_LAYER_TYPE_DEVICE_IMPLICIT = 0x4, |
| 63 | VK_LAYER_TYPE_INSTANCE_IMPLICIT = 0x8, |
| 64 | VK_LAYER_TYPE_GLOBAL_IMPLICIT = 0xc, // both instance and device layer, bitwise |
Jon Ashburn | 5ef2060 | 2015-07-02 09:40:15 -0600 | [diff] [blame] | 65 | }; |
| 66 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 67 | struct loader_extension_property { |
| 68 | VkExtensionProperties info; |
| 69 | const char *lib_name; |
| 70 | enum extension_origin origin; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 71 | }; |
| 72 | |
| 73 | struct loader_extension_list { |
| 74 | size_t capacity; |
| 75 | uint32_t count; |
| 76 | struct loader_extension_property *list; |
| 77 | }; |
| 78 | |
Jon Ashburn | 5ef2060 | 2015-07-02 09:40:15 -0600 | [diff] [blame] | 79 | struct loader_name_value { |
| 80 | char *name; |
| 81 | char *value; |
| 82 | }; |
| 83 | |
| 84 | struct loader_lib_info { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 85 | char *lib_name; |
Jon Ashburn | 5ef2060 | 2015-07-02 09:40:15 -0600 | [diff] [blame] | 86 | uint32_t ref_count; |
| 87 | loader_platform_dl_handle lib_handle; |
| 88 | }; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 89 | |
Jon Ashburn | 5ef2060 | 2015-07-02 09:40:15 -0600 | [diff] [blame] | 90 | struct loader_layer_functions { |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 91 | char *str_gipa; |
| 92 | char *str_gdpa; |
Jon Ashburn | 5ef2060 | 2015-07-02 09:40:15 -0600 | [diff] [blame] | 93 | PFN_vkGetInstanceProcAddr get_instance_proc_addr; |
| 94 | PFN_vkGetDeviceProcAddr get_device_proc_addr; |
| 95 | }; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 96 | |
Jon Ashburn | 5ef2060 | 2015-07-02 09:40:15 -0600 | [diff] [blame] | 97 | struct loader_layer_properties { |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 98 | VkLayerProperties info; |
Jon Ashburn | 5ef2060 | 2015-07-02 09:40:15 -0600 | [diff] [blame] | 99 | enum layer_type type; |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 100 | char *abi_version; |
| 101 | char *impl_version; |
Jon Ashburn | 5ef2060 | 2015-07-02 09:40:15 -0600 | [diff] [blame] | 102 | struct loader_lib_info lib_info; |
Jon Ashburn | 5ef2060 | 2015-07-02 09:40:15 -0600 | [diff] [blame] | 103 | struct loader_layer_functions functions; |
| 104 | struct loader_extension_list instance_extension_list; |
| 105 | struct loader_extension_list device_extension_list; |
| 106 | struct loader_name_value disable_env_var; |
| 107 | struct loader_name_value enable_env_var; |
| 108 | }; |
| 109 | |
| 110 | struct loader_layer_list { |
| 111 | size_t capacity; |
| 112 | uint32_t count; |
| 113 | struct loader_layer_properties *list; |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 114 | }; |
| 115 | |
Courtney Goeltzenleuchter | 371de70 | 2015-07-05 12:53:31 -0600 | [diff] [blame] | 116 | struct loader_layer_library_list { |
| 117 | size_t capacity; |
| 118 | uint32_t count; |
| 119 | struct loader_lib_info *list; |
| 120 | }; |
| 121 | |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 122 | /* per CreateDevice structure */ |
| 123 | struct loader_device { |
| 124 | VkLayerDispatchTable loader_dispatch; |
| 125 | VkDevice device; // device object from the icd |
| 126 | |
| 127 | uint32_t app_extension_count; |
| 128 | VkExtensionProperties *app_extension_props; |
| 129 | |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 130 | struct loader_layer_list activated_layer_list; |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 131 | |
| 132 | struct loader_device *next; |
| 133 | }; |
| 134 | |
Jon Ashburn | 953bb3c | 2015-06-10 16:11:42 -0600 | [diff] [blame] | 135 | /* per ICD structure */ |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 136 | struct loader_icd { |
| 137 | const struct loader_scanned_icds *scanned_icds; |
| 138 | |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 139 | struct loader_device *logical_device_list; |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 140 | uint32_t gpu_count; |
Jon Ashburn | 953bb3c | 2015-06-10 16:11:42 -0600 | [diff] [blame] | 141 | VkPhysicalDevice *gpus; // enumerated PhysicalDevices |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 142 | VkInstance instance; // instance object from the icd |
Jon Ashburn | 8d1b0b5 | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 143 | PFN_vkGetDeviceProcAddr GetDeviceProcAddr; |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 144 | PFN_vkDestroyInstance DestroyInstance; |
| 145 | PFN_vkEnumeratePhysicalDevices EnumeratePhysicalDevices; |
Chris Forbes | bc0bb77 | 2015-06-21 22:55:02 +1200 | [diff] [blame] | 146 | PFN_vkGetPhysicalDeviceFeatures GetPhysicalDeviceFeatures; |
Courtney Goeltzenleuchter | 2caec86 | 2015-07-12 12:52:09 -0600 | [diff] [blame] | 147 | PFN_vkGetPhysicalDeviceFormatProperties GetPhysicalDeviceFormatProperties; |
Jon Ashburn | 754864f | 2015-07-23 18:49:07 -0600 | [diff] [blame] | 148 | PFN_vkGetPhysicalDeviceImageFormatProperties GetPhysicalDeviceImageFormatProperties; |
Chris Forbes | bc0bb77 | 2015-06-21 22:55:02 +1200 | [diff] [blame] | 149 | PFN_vkGetPhysicalDeviceLimits GetPhysicalDeviceLimits; |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 150 | PFN_vkCreateDevice CreateDevice; |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 151 | PFN_vkGetPhysicalDeviceProperties GetPhysicalDeviceProperties; |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 152 | PFN_vkGetPhysicalDeviceQueueCount GetPhysicalDeviceQueueCount; |
| 153 | PFN_vkGetPhysicalDeviceQueueProperties GetPhysicalDeviceQueueProperties; |
| 154 | PFN_vkGetPhysicalDeviceMemoryProperties GetPhysicalDeviceMemoryProperties; |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 155 | PFN_vkGetPhysicalDeviceExtensionProperties GetPhysicalDeviceExtensionProperties; |
Mark Lobodzinski | 16e8bef | 2015-07-03 15:58:09 -0600 | [diff] [blame] | 156 | PFN_vkGetPhysicalDeviceSparseImageFormatProperties GetPhysicalDeviceSparseImageFormatProperties; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 157 | PFN_vkDbgCreateMsgCallback DbgCreateMsgCallback; |
| 158 | PFN_vkDbgDestroyMsgCallback DbgDestroyMsgCallback; |
Jon Ashburn | c624c88 | 2015-07-16 10:17:29 -0600 | [diff] [blame] | 159 | PFN_vkGetPhysicalDeviceSurfaceSupportWSI GetPhysicalDeviceSurfaceSupportWSI; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 160 | |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 161 | /* |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 162 | * Fill in the cache of available global extensions that operate |
| 163 | * with this physical device. This cache will be used to satisfy |
| 164 | * calls to GetPhysicalDeviceExtensionProperties |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 165 | */ |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 166 | struct loader_extension_list device_extension_cache[MAX_GPUS_PER_ICD]; |
| 167 | struct loader_icd *next; |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 168 | }; |
| 169 | |
Jon Ashburn | 953bb3c | 2015-06-10 16:11:42 -0600 | [diff] [blame] | 170 | /* per instance structure */ |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 171 | struct loader_instance { |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 172 | VkLayerInstanceDispatchTable *disp; // must be first entry in structure |
| 173 | |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 174 | uint32_t total_gpu_count; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 175 | uint32_t total_icd_count; |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 176 | struct loader_icd *icds; |
| 177 | struct loader_instance *next; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 178 | |
| 179 | /* TODO: Should keep track of application provided allocation functions */ |
| 180 | |
| 181 | /* |
| 182 | * CreateMsgCallback is global and needs to be |
| 183 | * applied to all layers and ICDs. |
| 184 | * What happens if a layer is enabled on both the instance chain |
| 185 | * as well as the device chain and a call to CreateMsgCallback is made? |
| 186 | * Do we need to make sure that each layer / driver only gets called once? |
| 187 | * Should a layer implementing support for CreateMsgCallback only be allowed (?) |
| 188 | * to live on one chain? Or maybe make it the application's responsibility. |
| 189 | * If the app enables DRAW_STATE on at both CreateInstance time and CreateDevice |
| 190 | * time, CreateMsgCallback will call the DRAW_STATE layer twice. Once via |
| 191 | * the instance chain and once via the device chain. |
| 192 | * The loader should only return the DEBUG_REPORT extension as supported |
| 193 | * for the GetGlobalExtensionSupport call. That should help eliminate one |
| 194 | * duplication. |
| 195 | * Since the instance chain requires us iterating over the available ICDs |
| 196 | * and each ICD will have it's own unique MsgCallback object we need to |
| 197 | * track those objects to give back the right one. |
| 198 | * This also implies that the loader has to intercept vkDestroyObject and |
| 199 | * if the extension is enabled and the object type is a MsgCallback then |
| 200 | * we must translate the object into the proper ICD specific ones. |
| 201 | * DestroyObject works on a device chain. Should not be what's destroying |
| 202 | * the MsgCallback object. That needs to be an instance thing. So, since |
| 203 | * we used an instance to create it, we need a custom Destroy that also |
| 204 | * takes an instance. That way we can iterate over the ICDs properly. |
| 205 | * Example use: |
| 206 | * CreateInstance: DEBUG_REPORT |
| 207 | * Loader will create instance chain with enabled extensions. |
| 208 | * TODO: Should validation layers be enabled here? If not, they will not be in the instance chain. |
| 209 | * fn = GetProcAddr(INSTANCE, "vkCreateMsgCallback") -> point to loader's vkCreateMsgCallback |
| 210 | * App creates a callback object: fn(..., &MsgCallbackObject1) |
| 211 | * Have only established the instance chain so far. Loader will call the instance chain. |
| 212 | * Each layer in the instance chain will call down to the next layer, terminating with |
| 213 | * the CreateMsgCallback loader terminator function that creates the actual MsgCallbackObject1 object. |
| 214 | * The loader CreateMsgCallback terminator will iterate over the ICDs. |
| 215 | * Calling each ICD that supports vkCreateMsgCallback and collect answers in icd_msg_callback_map here. |
| 216 | * As result is sent back up the chain each layer has opportunity to record the callback operation and |
| 217 | * appropriate MsgCallback object. |
| 218 | * ... |
| 219 | * Any reports matching the flags set in MsgCallbackObject1 will generate the defined callback behavior |
| 220 | * in the layer / ICD that initiated that report. |
| 221 | * ... |
| 222 | * CreateDevice: MemTracker:... |
| 223 | * App does not include DEBUG_REPORT as that is a global extension. |
| 224 | * TODO: GetExtensionSupport must not report DEBUG_REPORT when using instance. |
| 225 | * App MUST include any desired validation layers or they will not participate in the device call chain. |
| 226 | * App creates a callback object: fn(..., &MsgCallbackObject2) |
| 227 | * Loader's vkCreateMsgCallback is called. |
| 228 | * Loader sends call down instance chain - this is a global extension - any validation layer that was |
| 229 | * enabled at CreateInstance will be able to register the callback. Loader will iterate over the ICDs and |
| 230 | * will record the ICD's version of the MsgCallback2 object here. |
| 231 | * ... |
| 232 | * Any report will go to the layer's report function and it will check the flags for MsgCallbackObject1 |
| 233 | * and MsgCallbackObject2 and take the appropriate action as indicated by the app. |
| 234 | * ... |
| 235 | * App calls vkDestroyMsgCallback( MsgCallbackObject1 ) |
| 236 | * Loader's DestroyMsgCallback is where call starts. DestroyMsgCallback will be sent down instance chain |
| 237 | * ending in the loader's DestroyMsgCallback terminator which will iterate over the ICD's destroying each |
| 238 | * ICD version of that MsgCallback object and then destroy the loader's version of the object. |
| 239 | * Any reports generated after this will only have MsgCallbackObject2 available. |
| 240 | */ |
| 241 | struct loader_msg_callback_map_entry *icd_msg_callback_map; |
| 242 | |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 243 | struct loader_layer_list activated_layer_list; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 244 | |
| 245 | bool debug_report_enabled; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 246 | VkLayerDbgFunctionNode *DbgFunctionHead; |
Courtney Goeltzenleuchter | 7f5aafc | 2015-07-05 11:28:29 -0600 | [diff] [blame] | 247 | |
| 248 | VkAllocCallbacks alloc_callbacks; |
Ian Elliott | d3ef02f | 2015-07-06 14:36:13 -0600 | [diff] [blame] | 249 | |
| 250 | bool wsi_swapchain_enabled; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 251 | }; |
| 252 | |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 253 | struct loader_struct { |
| 254 | struct loader_instance *instances; |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 255 | struct loader_scanned_icds *scanned_icd_list; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 256 | |
| 257 | unsigned int loaded_layer_lib_count; |
| 258 | struct loader_lib_info *loaded_layer_lib_list; |
| 259 | |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 260 | char *layer_dirs; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 261 | |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 262 | // TODO use this struct loader_layer_library_list scanned_layer_libraries; |
Jon Ashburn | b2ef137 | 2015-07-16 17:19:31 -0600 | [diff] [blame] | 263 | struct loader_layer_list scanned_instance_layers; |
| 264 | struct loader_layer_list scanned_device_layers; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 265 | |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 266 | /* Keep track of all the extensions available via GetGlobalExtensionProperties */ |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 267 | struct loader_extension_list global_extensions; |
| 268 | }; |
| 269 | |
| 270 | struct loader_scanned_icds { |
| 271 | char *lib_name; |
| 272 | loader_platform_dl_handle handle; |
| 273 | |
Jon Ashburn | c624c88 | 2015-07-16 10:17:29 -0600 | [diff] [blame] | 274 | PFN_vkGetInstanceProcAddr GetInstanceProcAddr; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 275 | PFN_vkCreateInstance CreateInstance; |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 276 | PFN_vkGetGlobalExtensionProperties GetGlobalExtensionProperties; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 277 | VkInstance instance; |
| 278 | struct loader_scanned_icds *next; |
| 279 | |
| 280 | /* cache of global extensions for specific ICD */ |
| 281 | struct loader_extension_list global_extension_list; |
| 282 | |
| 283 | /* |
| 284 | * cache of device extensions for specific ICD, |
| 285 | * filled in at CreateInstance time |
| 286 | */ |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 287 | struct loader_extension_list device_extension_list; |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 288 | }; |
| 289 | |
Jon Ashburn | 5ef2060 | 2015-07-02 09:40:15 -0600 | [diff] [blame] | 290 | static inline struct loader_instance *loader_instance(VkInstance instance) { |
| 291 | return (struct loader_instance *) instance; |
| 292 | } |
| 293 | |
Tony Barbour | 1d2cd3f | 2015-07-03 10:33:54 -0600 | [diff] [blame] | 294 | static inline void loader_set_dispatch(void* obj, const void *data) |
Chia-I Wu | 5291c76 | 2015-04-11 15:34:07 +0800 | [diff] [blame] | 295 | { |
| 296 | *((const void **) obj) = data; |
| 297 | } |
| 298 | |
Tony Barbour | 1d2cd3f | 2015-07-03 10:33:54 -0600 | [diff] [blame] | 299 | static inline VkLayerDispatchTable *loader_get_dispatch(const void* obj) |
Chia-I Wu | 5291c76 | 2015-04-11 15:34:07 +0800 | [diff] [blame] | 300 | { |
Jon Ashburn | 1ed042c | 2015-05-01 18:00:33 -0600 | [diff] [blame] | 301 | return *((VkLayerDispatchTable **) obj); |
Chia-I Wu | 5291c76 | 2015-04-11 15:34:07 +0800 | [diff] [blame] | 302 | } |
| 303 | |
Tony Barbour | 1d2cd3f | 2015-07-03 10:33:54 -0600 | [diff] [blame] | 304 | static inline VkLayerInstanceDispatchTable *loader_get_instance_dispatch(const void* obj) |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 305 | { |
| 306 | return *((VkLayerInstanceDispatchTable **) obj); |
| 307 | } |
| 308 | |
Tony Barbour | 1d2cd3f | 2015-07-03 10:33:54 -0600 | [diff] [blame] | 309 | static inline void loader_init_dispatch(void* obj, const void *data) |
Chia-I Wu | 5291c76 | 2015-04-11 15:34:07 +0800 | [diff] [blame] | 310 | { |
Jon Ashburn | 4006664 | 2015-04-15 13:34:33 -0600 | [diff] [blame] | 311 | #ifdef DEBUG |
Chia-I Wu | 5291c76 | 2015-04-11 15:34:07 +0800 | [diff] [blame] | 312 | assert(valid_loader_magic_value(obj) && |
| 313 | "Incompatible ICD, first dword must be initialized to ICD_LOADER_MAGIC. See loader/README.md for details."); |
Jon Ashburn | 4006664 | 2015-04-15 13:34:33 -0600 | [diff] [blame] | 314 | #endif |
Chia-I Wu | 5291c76 | 2015-04-11 15:34:07 +0800 | [diff] [blame] | 315 | |
Jon Ashburn | 1ed042c | 2015-05-01 18:00:33 -0600 | [diff] [blame] | 316 | loader_set_dispatch(obj, data); |
Chia-I Wu | 5291c76 | 2015-04-11 15:34:07 +0800 | [diff] [blame] | 317 | } |
| 318 | |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 319 | /* global variables used across files */ |
| 320 | extern struct loader_struct loader; |
| 321 | extern LOADER_PLATFORM_THREAD_ONCE_DEFINITION(once_icd); |
| 322 | extern LOADER_PLATFORM_THREAD_ONCE_DEFINITION(once_layer); |
| 323 | extern LOADER_PLATFORM_THREAD_ONCE_DEFINITION(once_exts); |
Jon Ashburn | 6301a0f | 2015-05-29 13:15:39 -0600 | [diff] [blame] | 324 | extern loader_platform_thread_mutex loader_lock; |
| 325 | extern const VkLayerInstanceDispatchTable instance_disp; |
Jon Ashburn | bacb0f5 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 326 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 327 | struct loader_msg_callback_map_entry { |
| 328 | VkDbgMsgCallback icd_obj; |
| 329 | VkDbgMsgCallback loader_obj; |
| 330 | }; |
| 331 | |
| 332 | bool compare_vk_extension_properties( |
| 333 | const VkExtensionProperties* op1, |
| 334 | const VkExtensionProperties* op2); |
| 335 | |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 336 | VkResult loader_validate_layers(const uint32_t layer_count, const char * const *ppEnabledLayerNames, struct loader_layer_list *list); |
Courtney Goeltzenleuchter | 3b8c5ff | 2015-07-06 17:45:08 -0600 | [diff] [blame] | 337 | |
| 338 | VkResult loader_validate_instance_extensions( |
| 339 | const VkInstanceCreateInfo* pCreateInfo); |
| 340 | |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 341 | /* instance layer chain termination entrypoint definitions */ |
Dan Ginsburg | 78556e8 | 2015-07-23 13:15:00 -0400 | [diff] [blame] | 342 | VkResult VKAPI loader_CreateInstance( |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 343 | const VkInstanceCreateInfo* pCreateInfo, |
| 344 | VkInstance* pInstance); |
Chia-I Wu | 5291c76 | 2015-04-11 15:34:07 +0800 | [diff] [blame] | 345 | |
Dan Ginsburg | 78556e8 | 2015-07-23 13:15:00 -0400 | [diff] [blame] | 346 | VkResult VKAPI loader_DestroyInstance( |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 347 | VkInstance instance); |
| 348 | |
Dan Ginsburg | 78556e8 | 2015-07-23 13:15:00 -0400 | [diff] [blame] | 349 | VkResult VKAPI loader_EnumeratePhysicalDevices( |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 350 | VkInstance instance, |
| 351 | uint32_t* pPhysicalDeviceCount, |
| 352 | VkPhysicalDevice* pPhysicalDevices); |
Chris Forbes | bc0bb77 | 2015-06-21 22:55:02 +1200 | [diff] [blame] | 353 | |
Dan Ginsburg | 78556e8 | 2015-07-23 13:15:00 -0400 | [diff] [blame] | 354 | VkResult VKAPI loader_GetPhysicalDeviceFeatures( |
Chris Forbes | bc0bb77 | 2015-06-21 22:55:02 +1200 | [diff] [blame] | 355 | VkPhysicalDevice physicalDevice, |
| 356 | VkPhysicalDeviceFeatures* pFeatures); |
| 357 | |
Dan Ginsburg | 78556e8 | 2015-07-23 13:15:00 -0400 | [diff] [blame] | 358 | VkResult VKAPI loader_GetPhysicalDeviceFormatProperties( |
Chris Forbes | bc0bb77 | 2015-06-21 22:55:02 +1200 | [diff] [blame] | 359 | VkPhysicalDevice physicalDevice, |
| 360 | VkFormat format, |
| 361 | VkFormatProperties* pFormatInfo); |
| 362 | |
Jon Ashburn | 754864f | 2015-07-23 18:49:07 -0600 | [diff] [blame] | 363 | VkResult VKAPI loader_GetPhysicalDeviceImageFormatProperties( |
| 364 | VkPhysicalDevice physicalDevice, |
| 365 | VkFormat format, |
| 366 | VkImageType type, |
| 367 | VkImageTiling tiling, |
| 368 | VkImageUsageFlags usage, |
| 369 | VkImageFormatProperties* pImageFormatProperties); |
| 370 | |
Dan Ginsburg | 78556e8 | 2015-07-23 13:15:00 -0400 | [diff] [blame] | 371 | VkResult VKAPI loader_GetPhysicalDeviceLimits( |
Chris Forbes | bc0bb77 | 2015-06-21 22:55:02 +1200 | [diff] [blame] | 372 | VkPhysicalDevice physicalDevice, |
| 373 | VkPhysicalDeviceLimits* pLimits); |
| 374 | |
Dan Ginsburg | 78556e8 | 2015-07-23 13:15:00 -0400 | [diff] [blame] | 375 | VkResult VKAPI loader_GetPhysicalDeviceSparseImageFormatProperties( |
Mark Lobodzinski | 16e8bef | 2015-07-03 15:58:09 -0600 | [diff] [blame] | 376 | VkPhysicalDevice physicalDevice, |
| 377 | VkFormat format, |
| 378 | VkImageType type, |
| 379 | uint32_t samples, |
| 380 | VkImageUsageFlags usage, |
| 381 | VkImageTiling tiling, |
| 382 | uint32_t* pNumProperties, |
| 383 | VkSparseImageFormatProperties* pProperties); |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 384 | |
Dan Ginsburg | 78556e8 | 2015-07-23 13:15:00 -0400 | [diff] [blame] | 385 | VkResult VKAPI loader_GetPhysicalDeviceProperties ( |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 386 | VkPhysicalDevice physicalDevice, |
| 387 | VkPhysicalDeviceProperties* pProperties); |
| 388 | |
Dan Ginsburg | 78556e8 | 2015-07-23 13:15:00 -0400 | [diff] [blame] | 389 | VkResult VKAPI loader_GetPhysicalDeviceExtensionProperties (VkPhysicalDevice physicalDevice, |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 390 | const char *pLayerName, uint32_t *pCount, |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 391 | VkExtensionProperties* pProperties); |
| 392 | |
Dan Ginsburg | 78556e8 | 2015-07-23 13:15:00 -0400 | [diff] [blame] | 393 | VkResult VKAPI loader_GetPhysicalDeviceLayerProperties (VkPhysicalDevice physicalDevice, |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 394 | uint32_t *pCount, |
| 395 | VkLayerProperties* pProperties); |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 396 | |
Dan Ginsburg | 78556e8 | 2015-07-23 13:15:00 -0400 | [diff] [blame] | 397 | VkResult VKAPI loader_GetPhysicalDeviceQueueCount ( |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 398 | VkPhysicalDevice physicalDevice, |
| 399 | uint32_t* pCount); |
| 400 | |
Dan Ginsburg | 78556e8 | 2015-07-23 13:15:00 -0400 | [diff] [blame] | 401 | VkResult VKAPI loader_GetPhysicalDeviceQueueProperties ( |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 402 | VkPhysicalDevice physicalDevice, |
| 403 | uint32_t count, |
| 404 | VkPhysicalDeviceQueueProperties * pProperties); |
| 405 | |
Dan Ginsburg | 78556e8 | 2015-07-23 13:15:00 -0400 | [diff] [blame] | 406 | VkResult VKAPI loader_GetPhysicalDeviceMemoryProperties ( |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 407 | VkPhysicalDevice physicalDevice, |
| 408 | VkPhysicalDeviceMemoryProperties * pProperties); |
Jon Ashburn | 6301a0f | 2015-05-29 13:15:39 -0600 | [diff] [blame] | 409 | |
Dan Ginsburg | 78556e8 | 2015-07-23 13:15:00 -0400 | [diff] [blame] | 410 | VkResult VKAPI loader_CreateDevice( |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 411 | VkPhysicalDevice gpu, |
| 412 | const VkDeviceCreateInfo* pCreateInfo, |
| 413 | VkDevice* pDevice); |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 414 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 415 | /* helper function definitions */ |
Jon Ashburn | bd6c488 | 2015-07-02 12:59:25 -0600 | [diff] [blame] | 416 | bool has_vk_extension_property_array( |
| 417 | const VkExtensionProperties *vk_ext_prop, |
| 418 | const uint32_t count, |
| 419 | const VkExtensionProperties *ext_array); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 420 | bool has_vk_extension_property( |
| 421 | const VkExtensionProperties *vk_ext_prop, |
| 422 | const struct loader_extension_list *ext_list); |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 423 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 424 | void loader_add_to_ext_list( |
| 425 | struct loader_extension_list *ext_list, |
| 426 | uint32_t prop_list_count, |
| 427 | const struct loader_extension_property *props); |
Courtney Goeltzenleuchter | 7d0023c | 2015-06-08 15:09:22 -0600 | [diff] [blame] | 428 | void loader_destroy_ext_list(struct loader_extension_list *ext_info); |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 429 | |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 430 | void loader_add_to_layer_list( |
| 431 | struct loader_layer_list *list, |
| 432 | uint32_t prop_list_count, |
| 433 | const struct loader_layer_properties *props); |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 434 | void loader_icd_scan(void); |
Jon Ashburn | 5ef2060 | 2015-07-02 09:40:15 -0600 | [diff] [blame] | 435 | void loader_layer_scan(void); |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 436 | void loader_coalesce_extensions(void); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 437 | |
Jon Ashburn | 128f942 | 2015-05-28 19:16:58 -0600 | [diff] [blame] | 438 | struct loader_icd * loader_get_icd(const VkPhysicalDevice gpu, |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 439 | uint32_t *gpu_index); |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 440 | void loader_remove_logical_device(VkDevice device); |
Courtney Goeltzenleuchter | 40caf0b | 2015-07-06 09:06:34 -0600 | [diff] [blame] | 441 | VkResult loader_enable_instance_layers(struct loader_instance *inst, const VkInstanceCreateInfo *pCreateInfo); |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 442 | void loader_deactivate_instance_layers(struct loader_instance *instance); |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 443 | uint32_t loader_activate_instance_layers(struct loader_instance *inst); |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 444 | void loader_activate_instance_layer_extensions(struct loader_instance *inst); |
Courtney Goeltzenleuchter | 7f5aafc | 2015-07-05 11:28:29 -0600 | [diff] [blame] | 445 | |
| 446 | void* loader_heap_alloc( |
| 447 | struct loader_instance *instance, |
| 448 | size_t size, |
| 449 | VkSystemAllocType allocType); |
| 450 | |
| 451 | void* loader_aligned_heap_alloc( |
| 452 | struct loader_instance *instance, |
| 453 | size_t size, |
| 454 | size_t alignment, |
| 455 | VkSystemAllocType allocType); |
| 456 | |
| 457 | void loader_heap_free( |
| 458 | struct loader_instance *instance, |
| 459 | void *pMem); |
Chia-I Wu | 1930060 | 2014-08-04 08:03:57 +0800 | [diff] [blame] | 460 | #endif /* LOADER_H */ |