blob: 463b74e19d7cbb8d259c695ef11352153367bd3f [file] [log] [blame]
Chia-I Wuc1e0f962014-08-04 08:03:57 +08001/*
Chia-I Wuc1e0f962014-08-04 08:03:57 +08002 *
Lenny Komow2a680fb2019-02-25 21:37:33 -07003 * Copyright (c) 2014-2019 The Khronos Group Inc.
4 * Copyright (c) 2014-2019 Valve Corporation
5 * Copyright (c) 2014-2019 LunarG, Inc.
Courtney Goeltzenleuchter8e1b8d92015-12-02 14:53:22 -07006 * Copyright (C) 2015 Google Inc.
Chia-I Wuc1e0f962014-08-04 08:03:57 +08007 *
Jon Ashburn4f80d672016-04-19 11:30:31 -06008 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
Chia-I Wuc1e0f962014-08-04 08:03:57 +080011 *
Jon Ashburn4f80d672016-04-19 11:30:31 -060012 * http://www.apache.org/licenses/LICENSE-2.0
Chia-I Wuc1e0f962014-08-04 08:03:57 +080013 *
Jon Ashburn4f80d672016-04-19 11:30:31 -060014 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
Jon Ashburn1c75aec2016-02-02 17:47:28 -070019 *
20 * Author: Jon Ashburn <jon@lunarg.com>
21 * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
Courtney Goeltzenleuchterb9ce3952015-10-30 11:14:30 -060022 * Author: Chia-I Wu <olvaffe@gmail.com>
23 * Author: Chia-I Wu <olv@lunarg.com>
Jon Ashburn1c75aec2016-02-02 17:47:28 -070024 * Author: Mark Lobodzinski <mark@LunarG.com>
Lenny Komow2a680fb2019-02-25 21:37:33 -070025 * Author: Lenny Komow <lenny@lunarg.com>
Courtney Goeltzenleuchterb9ce3952015-10-30 11:14:30 -060026 *
Chia-I Wuc1e0f962014-08-04 08:03:57 +080027 */
28
29#ifndef LOADER_H
30#define LOADER_H
31
David Pinedoa5036622015-11-06 12:54:48 -070032#include <vulkan/vulkan.h>
Aaron Karp95c5f952016-03-13 16:41:59 -040033#include "vk_loader_platform.h"
Mark Lobodzinski663818f2016-05-24 16:04:56 -060034#include "vk_loader_layer.h"
David Pinedoa5036622015-11-06 12:54:48 -070035#include <vulkan/vk_layer.h>
36#include <vulkan/vk_icd.h>
Chia-I Wufe333ed2015-04-11 15:34:07 +080037#include <assert.h>
Lenny Komow700483f2018-06-25 14:09:51 -060038#include "vk_layer_dispatch_table.h"
Mark Youngd4e5ba42017-02-28 09:58:04 -070039#include "vk_loader_extensions.h"
Chia-I Wufe333ed2015-04-11 15:34:07 +080040
Chia-I Wuc1e0f962014-08-04 08:03:57 +080041#if defined(__GNUC__) && __GNUC__ >= 4
Jon Ashburn1c75aec2016-02-02 17:47:28 -070042#define LOADER_EXPORT __attribute__((visibility("default")))
Chia-I Wuc1e0f962014-08-04 08:03:57 +080043#elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)
Jon Ashburn1c75aec2016-02-02 17:47:28 -070044#define LOADER_EXPORT __attribute__((visibility("default")))
Chia-I Wuc1e0f962014-08-04 08:03:57 +080045#else
Jon Ashburn1c75aec2016-02-02 17:47:28 -070046#define LOADER_EXPORT
Chia-I Wuc1e0f962014-08-04 08:03:57 +080047#endif
48
Mark Young74dd5d12016-06-30 13:02:42 -060049// A debug option to disable allocators at compile time to investigate future issues.
50#define DEBUG_DISABLE_APP_ALLOCATORS 0
51
Jon Ashburnb2379c52015-08-04 10:22:33 -060052#define MAX_STRING_SIZE 1024
Jon Ashburn13482452015-05-12 17:26:48 -060053
Mark Young274e4bc2017-01-19 21:10:49 -070054// This is defined in vk_layer.h, but if there's problems we need to create the define
55// here.
56#ifndef MAX_NUM_UNKNOWN_EXTS
57#define MAX_NUM_UNKNOWN_EXTS 250
58#endif
59
Mark Young74268f72017-05-02 10:49:46 -060060enum layer_type_flags {
61 VK_LAYER_TYPE_FLAG_INSTANCE_LAYER = 0x1, // If not set, indicates Device layer
62 VK_LAYER_TYPE_FLAG_EXPLICIT_LAYER = 0x2, // If not set, indicates Implicit layer
63 VK_LAYER_TYPE_FLAG_META_LAYER = 0x4, // If not set, indicates standard layer
Jon Ashburn399c9162015-07-02 09:40:15 -060064};
65
Mark Lobodzinski8d325802016-02-02 18:53:34 -070066typedef enum VkStringErrorFlagBits {
Jon Ashburnb1cdf2e2016-02-10 20:50:19 -070067 VK_STRING_ERROR_NONE = 0x00000000,
68 VK_STRING_ERROR_LENGTH = 0x00000001,
69 VK_STRING_ERROR_BAD_DATA = 0x00000002,
Charles Giessene8d7d882020-02-03 10:28:04 -070070 VK_STRING_ERROR_NULL_PTR = 0x00000004,
Mark Lobodzinski8d325802016-02-02 18:53:34 -070071} VkStringErrorFlagBits;
72typedef VkFlags VkStringErrorFlags;
73
Jon Ashburnb1cdf2e2016-02-10 20:50:19 -070074static const int MaxLoaderStringLength = 256;
75static const char UTF8_ONE_BYTE_CODE = 0xC0;
76static const char UTF8_ONE_BYTE_MASK = 0xE0;
77static const char UTF8_TWO_BYTE_CODE = 0xE0;
78static const char UTF8_TWO_BYTE_MASK = 0xF0;
79static const char UTF8_THREE_BYTE_CODE = 0xF0;
80static const char UTF8_THREE_BYTE_MASK = 0xF8;
81static const char UTF8_DATA_BYTE_CODE = 0x80;
82static const char UTF8_DATA_BYTE_MASK = 0xC0;
Mark Lobodzinski8d325802016-02-02 18:53:34 -070083
Jon Ashburn6b00b472015-12-10 08:51:10 -070084// form of all dynamic lists/arrays
85// only the list element should be changed
86struct loader_generic_list {
87 size_t capacity;
88 uint32_t count;
89 void *list;
90};
91
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -060092struct loader_extension_list {
93 size_t capacity;
94 uint32_t count;
Jon Ashburnb7d327c2015-08-04 11:14:18 -060095 VkExtensionProperties *list;
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -060096};
97
Jon Ashburn92cdb012015-12-10 18:17:34 -070098struct loader_dev_ext_props {
99 VkExtensionProperties props;
100 uint32_t entrypoint_count;
101 char **entrypoints;
102};
103
104struct loader_device_extension_list {
105 size_t capacity;
106 uint32_t count;
107 struct loader_dev_ext_props *list;
108};
109
Jon Ashburn399c9162015-07-02 09:40:15 -0600110struct loader_name_value {
Jon Ashburnb2379c52015-08-04 10:22:33 -0600111 char name[MAX_STRING_SIZE];
112 char value[MAX_STRING_SIZE];
Jon Ashburn399c9162015-07-02 09:40:15 -0600113};
114
Jon Ashburn399c9162015-07-02 09:40:15 -0600115struct loader_layer_functions {
Jon Ashburnb2379c52015-08-04 10:22:33 -0600116 char str_gipa[MAX_STRING_SIZE];
117 char str_gdpa[MAX_STRING_SIZE];
Mark Young274e4bc2017-01-19 21:10:49 -0700118 char str_negotiate_interface[MAX_STRING_SIZE];
119 PFN_vkNegotiateLoaderLayerInterfaceVersion negotiate_layer_interface;
Jon Ashburn399c9162015-07-02 09:40:15 -0600120 PFN_vkGetInstanceProcAddr get_instance_proc_addr;
121 PFN_vkGetDeviceProcAddr get_device_proc_addr;
Mark Young274e4bc2017-01-19 21:10:49 -0700122 PFN_GetPhysicalDeviceProcAddr get_physical_device_proc_addr;
Jon Ashburn399c9162015-07-02 09:40:15 -0600123};
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600124
Lenny Komow40761b02018-10-03 17:44:02 -0600125struct loader_override_expiration {
126 uint16_t year;
127 uint8_t month;
128 uint8_t day;
129 uint8_t hour;
130 uint8_t minute;
131};
132
Jon Ashburn399c9162015-07-02 09:40:15 -0600133struct loader_layer_properties {
Courtney Goeltzenleuchter44667cc2015-06-29 15:39:26 -0600134 VkLayerProperties info;
Mark Young74268f72017-05-02 10:49:46 -0600135 enum layer_type_flags type_flags;
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -0700136 uint32_t interface_version; // PFN_vkNegotiateLoaderLayerInterfaceVersion
Jon Ashburnb4c24232015-08-20 16:35:30 -0600137 char lib_name[MAX_STRING_SIZE];
Jon Ashburnd3cf9552016-04-20 13:21:17 -0600138 loader_platform_dl_handle lib_handle;
Jon Ashburn399c9162015-07-02 09:40:15 -0600139 struct loader_layer_functions functions;
140 struct loader_extension_list instance_extension_list;
Jon Ashburn92cdb012015-12-10 18:17:34 -0700141 struct loader_device_extension_list device_extension_list;
Jon Ashburn399c9162015-07-02 09:40:15 -0600142 struct loader_name_value disable_env_var;
143 struct loader_name_value enable_env_var;
Mark Young74268f72017-05-02 10:49:46 -0600144 uint32_t num_component_layers;
145 char (*component_layer_names)[MAX_STRING_SIZE];
Lenny Komowe6b54942017-12-19 16:38:37 -0700146 struct {
147 char enumerate_instance_extension_properties[MAX_STRING_SIZE];
148 char enumerate_instance_layer_properties[MAX_STRING_SIZE];
Lenny Komow3b7c7f22018-02-13 15:58:47 -0700149 char enumerate_instance_version[MAX_STRING_SIZE];
Lenny Komowe6b54942017-12-19 16:38:37 -0700150 } pre_instance_functions;
Lenny Komow40761b02018-10-03 17:44:02 -0600151 uint32_t num_override_paths;
152 char (*override_paths)[MAX_STRING_SIZE];
153 bool is_override;
154 bool has_expiration;
155 struct loader_override_expiration expiration;
156 bool keep;
Lenny Komow2a680fb2019-02-25 21:37:33 -0700157 uint32_t num_blacklist_layers;
158 char (*blacklist_layer_names)[MAX_STRING_SIZE];
Jon Ashburn399c9162015-07-02 09:40:15 -0600159};
160
161struct loader_layer_list {
162 size_t capacity;
163 uint32_t count;
164 struct loader_layer_properties *list;
Jon Ashburn13482452015-05-12 17:26:48 -0600165};
166
Jon Ashburn6cb69f42015-11-17 15:31:02 -0700167struct loader_dispatch_hash_list {
168 size_t capacity;
169 uint32_t count;
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -0700170 uint32_t *index; // index into the dev_ext dispatch table
Jon Ashburn6cb69f42015-11-17 15:31:02 -0700171};
172
Mark Youngdd904ae2016-09-02 11:41:28 -0600173// loader_dispatch_hash_entry and loader_dev_ext_dispatch_table.dev_ext have
174// one to one correspondence; one loader_dispatch_hash_entry for one dev_ext
175// dispatch entry.
Jon Ashburn6cb69f42015-11-17 15:31:02 -0700176// Also have a one to one correspondence with functions in dev_ext_trampoline.c
177struct loader_dispatch_hash_entry {
178 char *func_name;
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -0700179 struct loader_dispatch_hash_list list; // to handle hashing collisions
Jon Ashburn6cb69f42015-11-17 15:31:02 -0700180};
181
Lenny Komow2a614252018-05-09 11:09:58 -0600182typedef VkResult(VKAPI_PTR *PFN_vkDevExt)(VkDevice device);
Jon Ashburn6cb69f42015-11-17 15:31:02 -0700183struct loader_dev_ext_dispatch_table {
Mark Young274e4bc2017-01-19 21:10:49 -0700184 PFN_vkDevExt dev_ext[MAX_NUM_UNKNOWN_EXTS];
Jon Ashburn6cb69f42015-11-17 15:31:02 -0700185};
186
187struct loader_dev_dispatch_table {
188 VkLayerDispatchTable core_dispatch;
189 struct loader_dev_ext_dispatch_table ext_dispatch;
190};
191
Mark Young1d645262016-09-07 08:50:32 -0600192// per CreateDevice structure
Jon Ashburn10f4e822015-06-10 10:06:06 -0600193struct loader_device {
Jon Ashburn6cb69f42015-11-17 15:31:02 -0700194 struct loader_dev_dispatch_table loader_dispatch;
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -0700195 VkDevice chain_device; // device object from the dispatch chain
196 VkDevice icd_device; // device object from the icd
Mark Young0f7adeb2016-11-07 13:27:02 -0700197 struct loader_physical_device_term *phys_dev_term;
Jon Ashburn10f4e822015-06-10 10:06:06 -0600198
Mark Young5c875062017-05-04 12:16:35 -0600199 // List of activated layers.
200 // app_ is the version based on exactly what the application asked for.
201 // This is what must be returned to the application on Enumerate calls.
202 // expanded_ is the version based on expanding meta-layers into their
203 // individual component layers. This is what is used internally.
204 struct loader_layer_list app_activated_layer_list;
205 struct loader_layer_list expanded_activated_layer_list;
Jon Ashburn10f4e822015-06-10 10:06:06 -0600206
Mark Young74dd5d12016-06-30 13:02:42 -0600207 VkAllocationCallbacks alloc_callbacks;
208
Lenny Komowbc3d03f2018-03-29 13:25:38 -0600209 // List of activated device extensions that have terminators implemented in the loader
210 struct {
211 bool khr_swapchain_enabled;
212 bool khr_display_swapchain_enabled;
Mike Schuchardt1df2ebd2019-03-16 10:09:25 -0700213 bool khr_device_group_enabled;
Lenny Komowbc3d03f2018-03-29 13:25:38 -0600214 bool ext_debug_marker_enabled;
215 bool ext_debug_utils_enabled;
Mike Schuchardt1df2ebd2019-03-16 10:09:25 -0700216 bool ext_full_screen_exclusive_enabled;
Lenny Komowbc3d03f2018-03-29 13:25:38 -0600217 } extensions;
218
Jon Ashburn10f4e822015-06-10 10:06:06 -0600219 struct loader_device *next;
220};
221
Mark Youngd4e5ba42017-02-28 09:58:04 -0700222// Per ICD information
223
224// Per ICD structure
Mark Young26c19372016-11-03 14:27:13 -0600225struct loader_icd_term {
Jon Ashburnb4c24232015-08-20 16:35:30 -0600226 // pointers to find other structs
Mark Young26c19372016-11-03 14:27:13 -0600227 const struct loader_scanned_icd *scanned_icd;
Jon Ashburnb4c24232015-08-20 16:35:30 -0600228 const struct loader_instance *this_instance;
Jon Ashburn10f4e822015-06-10 10:06:06 -0600229 struct loader_device *logical_device_list;
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -0700230 VkInstance instance; // instance object from the icd
Mark Youngd4e5ba42017-02-28 09:58:04 -0700231 struct loader_icd_term_dispatch dispatch;
Mark Young4ab55c42016-12-12 16:14:55 -0700232
Mark Young26c19372016-11-03 14:27:13 -0600233 struct loader_icd_term *next;
Mark Young274e4bc2017-01-19 21:10:49 -0700234
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700235 PFN_PhysDevExt phys_dev_ext[MAX_NUM_UNKNOWN_EXTS];
Jon Ashburnebfa25e2015-05-15 15:09:35 -0600236};
237
Mark Youngd4e5ba42017-02-28 09:58:04 -0700238// Per ICD library structure
Mark Young26c19372016-11-03 14:27:13 -0600239struct loader_icd_tramp_list {
Jon Ashburne0367472015-08-18 18:04:47 -0600240 size_t capacity;
241 uint32_t count;
Mark Young26c19372016-11-03 14:27:13 -0600242 struct loader_scanned_icd *scanned_list;
Jon Ashburne0367472015-08-18 18:04:47 -0600243};
244
Mark Young274e4bc2017-01-19 21:10:49 -0700245struct loader_instance_dispatch_table {
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -0700246 VkLayerInstanceDispatchTable layer_inst_disp; // must be first entry in structure
Mark Young274e4bc2017-01-19 21:10:49 -0700247
248 // Physical device functions unknown to the loader
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700249 PFN_PhysDevExt phys_dev_ext[MAX_NUM_UNKNOWN_EXTS];
Mark Young274e4bc2017-01-19 21:10:49 -0700250};
251
Mark Youngd4e5ba42017-02-28 09:58:04 -0700252// Per instance structure
Jon Ashburn13482452015-05-12 17:26:48 -0600253struct loader_instance {
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -0700254 struct loader_instance_dispatch_table *disp; // must be first entry in structure
Jon Ashburnebfa25e2015-05-15 15:09:35 -0600255
Lenny Komowde705cc2017-10-25 15:26:15 -0600256 // Vulkan API version the app is intending to use.
257 uint16_t app_api_major_version;
258 uint16_t app_api_minor_version;
259
Mark Young0746fce2017-03-10 17:31:18 -0700260 // We need to manually track physical devices over time. If the user
261 // re-queries the information, we don't want to delete old data or
262 // create new data unless necessary.
Mark Young26c19372016-11-03 14:27:13 -0600263 uint32_t total_gpu_count;
Lenny Komowe93e87f2016-12-20 15:35:11 -0700264 uint32_t phys_dev_count_term;
265 struct loader_physical_device_term **phys_devs_term;
Lenny Komowaaa115c2016-12-19 17:11:40 -0700266 uint32_t phys_dev_count_tramp;
267 struct loader_physical_device_tramp **phys_devs_tramp;
Mark Young26c19372016-11-03 14:27:13 -0600268
Mark Young0746fce2017-03-10 17:31:18 -0700269 // We also need to manually track physical device groups, but we don't need
270 // loader specific structures since we have that content in the physical
271 // device stored internal to the public structures.
272 uint32_t phys_dev_group_count_term;
Lenny Komow31217432017-10-02 15:08:53 -0600273 struct VkPhysicalDeviceGroupProperties **phys_dev_groups_term;
Mark Young0746fce2017-03-10 17:31:18 -0700274 uint32_t phys_dev_group_count_tramp;
Lenny Komow31217432017-10-02 15:08:53 -0600275 struct VkPhysicalDeviceGroupProperties **phys_dev_groups_tramp;
Mark Young0746fce2017-03-10 17:31:18 -0700276
Jon Ashburn13482452015-05-12 17:26:48 -0600277 struct loader_instance *next;
Mark Young26c19372016-11-03 14:27:13 -0600278
279 uint32_t total_icd_count;
280 struct loader_icd_term *icd_terms;
281 struct loader_icd_tramp_list icd_tramp_list;
282
Mark Young274e4bc2017-01-19 21:10:49 -0700283 struct loader_dispatch_hash_entry dev_ext_disp_hash[MAX_NUM_UNKNOWN_EXTS];
284 struct loader_dispatch_hash_entry phys_dev_ext_disp_hash[MAX_NUM_UNKNOWN_EXTS];
Jon Ashburnb4c24232015-08-20 16:35:30 -0600285
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600286 struct loader_msg_callback_map_entry *icd_msg_callback_map;
287
Mark Young26c19372016-11-03 14:27:13 -0600288 struct loader_layer_list instance_layer_list;
Lenny Komow40761b02018-10-03 17:44:02 -0600289 bool override_layer_present;
Mark Young5c875062017-05-04 12:16:35 -0600290
291 // List of activated layers.
292 // app_ is the version based on exactly what the application asked for.
293 // This is what must be returned to the application on Enumerate calls.
294 // expanded_ is the version based on expanding meta-layers into their
295 // individual component layers. This is what is used internally.
296 struct loader_layer_list app_activated_layer_list;
297 struct loader_layer_list expanded_activated_layer_list;
298
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -0700299 VkInstance instance; // layers/ICD instance returned to trampoline
Courtney Goeltzenleuchter0bd705c2016-01-08 12:18:43 -0700300
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -0700301 struct loader_extension_list ext_list; // icds and loaders extensions
Mark Young26c19372016-11-03 14:27:13 -0600302 union loader_instance_extension_enables enabled_known_extensions;
303
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600304 VkLayerDbgFunctionNode *DbgFunctionHead;
Mark Younge3e9b562017-11-09 10:37:04 -0700305 uint32_t num_tmp_report_callbacks;
306 VkDebugReportCallbackCreateInfoEXT *tmp_report_create_infos;
307 VkDebugReportCallbackEXT *tmp_report_callbacks;
308 uint32_t num_tmp_messengers;
309 VkDebugUtilsMessengerCreateInfoEXT *tmp_messenger_create_infos;
310 VkDebugUtilsMessengerEXT *tmp_messengers;
Courtney Goeltzenleuchter71b454b2015-07-05 11:28:29 -0600311
Chia-I Wu227c8b32015-10-27 18:04:07 +0800312 VkAllocationCallbacks alloc_callbacks;
Ian Elliotted33eb72015-07-06 14:36:13 -0600313
Ian Elliott54cea232015-10-30 15:28:23 -0600314 bool wsi_surface_enabled;
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -0700315#ifdef VK_USE_PLATFORM_WIN32_KHR
Ian Elliott54cea232015-10-30 15:28:23 -0600316 bool wsi_win32_surface_enabled;
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -0700317#endif
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -0700318#ifdef VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott54cea232015-10-30 15:28:23 -0600319 bool wsi_wayland_surface_enabled;
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -0700320#endif
321#ifdef VK_USE_PLATFORM_XCB_KHR
Ian Elliott54cea232015-10-30 15:28:23 -0600322 bool wsi_xcb_surface_enabled;
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -0700323#endif
324#ifdef VK_USE_PLATFORM_XLIB_KHR
Ian Elliott54cea232015-10-30 15:28:23 -0600325 bool wsi_xlib_surface_enabled;
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -0700326#endif
327#ifdef VK_USE_PLATFORM_ANDROID_KHR
328 bool wsi_android_surface_enabled;
329#endif
Karl Schultzd81ebfb2017-12-12 10:33:01 -0500330#ifdef VK_USE_PLATFORM_MACOS_MVK
331 bool wsi_macos_surface_enabled;
332#endif
333#ifdef VK_USE_PLATFORM_IOS_MVK
334 bool wsi_ios_surface_enabled;
335#endif
Bryan Law-Smith57305692019-04-01 09:45:55 +0100336 bool wsi_headless_surface_enabled;
Lenny Komowa1b5e442019-09-16 16:14:36 -0600337#if defined(VK_USE_PLATFORM_METAL_EXT)
338 bool wsi_metal_surface_enabled;
339#endif
Jon Ashburncc370d02016-03-08 09:30:30 -0700340 bool wsi_display_enabled;
Lenny Komow61139782018-05-31 11:32:31 -0600341 bool wsi_display_props2_enabled;
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600342};
343
Mark Youngd4e5ba42017-02-28 09:58:04 -0700344// VkPhysicalDevice requires special treatment by loader. Firstly, terminator
345// code must be able to get the struct loader_icd_term to call into the proper
346// driver (multiple ICD/gpu case). This can be accomplished by wrapping the
347// created VkPhysicalDevice in loader terminate_EnumeratePhysicalDevices().
348// Secondly, the loader must be able to handle wrapped by layer VkPhysicalDevice
349// in trampoline code. This implies, that the loader trampoline code must also
350// wrap the VkPhysicalDevice object in trampoline code. Thus, loader has to
351// wrap the VkPhysicalDevice created object twice. In trampoline code it can't
352// rely on the terminator object wrapping since a layer may also wrap. Since
353// trampoline code wraps the VkPhysicalDevice this means all loader trampoline
354// code that passes a VkPhysicalDevice should unwrap it.
Jon Ashburnfd02a0f2016-03-01 19:51:07 -0700355
Mark Youngd4e5ba42017-02-28 09:58:04 -0700356// Per enumerated PhysicalDevice structure, used to wrap in trampoline code and
357// also same structure used to wrap in terminator code
Jon Ashburnc3519e42016-03-24 15:49:57 -0600358struct loader_physical_device_tramp {
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -0700359 struct loader_instance_dispatch_table *disp; // must be first entry in structure
Piers Daniell82107a62016-03-29 11:51:11 -0600360 struct loader_instance *this_instance;
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -0700361 VkPhysicalDevice phys_dev; // object from layers/loader terminator
Jon Ashburnc3519e42016-03-24 15:49:57 -0600362};
363
Mark Youngd4e5ba42017-02-28 09:58:04 -0700364// Per enumerated PhysicalDevice structure, used to wrap in terminator code
Mark Young26c19372016-11-03 14:27:13 -0600365struct loader_physical_device_term {
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -0700366 struct loader_instance_dispatch_table *disp; // must be first entry in structure
Mark Young26c19372016-11-03 14:27:13 -0600367 struct loader_icd_term *this_icd_term;
Mark Young5467d672016-06-28 10:52:43 -0600368 uint8_t icd_index;
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -0700369 VkPhysicalDevice phys_dev; // object from ICD
Jon Ashburn969caa42015-11-01 14:04:06 -0700370};
371
Jon Ashburn13482452015-05-12 17:26:48 -0600372struct loader_struct {
373 struct loader_instance *instances;
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600374};
375
Mark Young26c19372016-11-03 14:27:13 -0600376struct loader_scanned_icd {
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600377 char *lib_name;
378 loader_platform_dl_handle handle;
Jon Ashburn27109e82015-11-17 17:35:40 -0700379 uint32_t api_version;
Jon Ashburn68b06d62016-04-25 11:09:37 -0600380 uint32_t interface_version;
Jon Ashburnc7ca48d2015-07-16 10:17:29 -0600381 PFN_vkGetInstanceProcAddr GetInstanceProcAddr;
Mark Young274e4bc2017-01-19 21:10:49 -0700382 PFN_GetPhysicalDeviceProcAddr GetPhysicalDeviceProcAddr;
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600383 PFN_vkCreateInstance CreateInstance;
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700384 PFN_vkEnumerateInstanceExtensionProperties EnumerateInstanceExtensionProperties;
Jon Ashburn13482452015-05-12 17:26:48 -0600385};
386
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700387static inline struct loader_instance *loader_instance(VkInstance instance) { return (struct loader_instance *)instance; }
Jon Ashburn399c9162015-07-02 09:40:15 -0600388
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700389static inline VkPhysicalDevice loader_unwrap_physical_device(VkPhysicalDevice physicalDevice) {
390 struct loader_physical_device_tramp *phys_dev = (struct loader_physical_device_tramp *)physicalDevice;
Jon Ashburnfd02a0f2016-03-01 19:51:07 -0700391 return phys_dev->phys_dev;
392}
393
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700394static inline void loader_set_dispatch(void *obj, const void *data) { *((const void **)obj) = data; }
Chia-I Wufe333ed2015-04-11 15:34:07 +0800395
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700396static inline VkLayerDispatchTable *loader_get_dispatch(const void *obj) { return *((VkLayerDispatchTable **)obj); }
Chia-I Wufe333ed2015-04-11 15:34:07 +0800397
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700398static inline struct loader_dev_dispatch_table *loader_get_dev_dispatch(const void *obj) {
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700399 return *((struct loader_dev_dispatch_table **)obj);
Jon Ashburn6cb69f42015-11-17 15:31:02 -0700400}
401
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700402static inline VkLayerInstanceDispatchTable *loader_get_instance_layer_dispatch(const void *obj) {
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700403 return *((VkLayerInstanceDispatchTable **)obj);
Jon Ashburn13482452015-05-12 17:26:48 -0600404}
405
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700406static inline struct loader_instance_dispatch_table *loader_get_instance_dispatch(const void *obj) {
Mark Young274e4bc2017-01-19 21:10:49 -0700407 return *((struct loader_instance_dispatch_table **)obj);
408}
409
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700410static inline void loader_init_dispatch(void *obj, const void *data) {
Jon Ashburn167b2b12015-04-15 13:34:33 -0600411#ifdef DEBUG
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -0700412 assert(valid_loader_magic_value(obj) &&
413 "Incompatible ICD, first dword must be initialized to "
414 "ICD_LOADER_MAGIC. See loader/README.md for details.");
Jon Ashburn167b2b12015-04-15 13:34:33 -0600415#endif
Chia-I Wufe333ed2015-04-11 15:34:07 +0800416
Jon Ashburn62a54d12015-05-01 18:00:33 -0600417 loader_set_dispatch(obj, data);
Chia-I Wufe333ed2015-04-11 15:34:07 +0800418}
419
Mark Youngd4e5ba42017-02-28 09:58:04 -0700420// Global variables used across files
Jon Ashburn13482452015-05-12 17:26:48 -0600421extern struct loader_struct loader;
Jon Ashburnb4dee9c2015-08-28 15:19:27 -0600422extern THREAD_LOCAL_DECL struct loader_instance *tls_instance;
Jon Ashburn7e8d8b42015-05-29 13:15:39 -0600423extern loader_platform_thread_mutex loader_lock;
Jon Ashburn7d4d51c2015-09-22 13:11:00 -0600424extern loader_platform_thread_mutex loader_json_lock;
Charles Giessen3e390a12020-05-12 14:25:47 -0600425extern loader_platform_thread_mutex loader_preload_icd_lock;
Jon Ashburn37e7f972015-04-06 10:58:22 -0600426
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600427struct loader_msg_callback_map_entry {
Courtney Goeltzenleuchter725db942015-12-09 15:48:16 -0700428 VkDebugReportCallbackEXT icd_obj;
429 VkDebugReportCallbackEXT loader_obj;
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600430};
431
Mark Youngd4e5ba42017-02-28 09:58:04 -0700432// Helper function definitions
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700433void *loader_instance_heap_alloc(const struct loader_instance *instance, size_t size, VkSystemAllocationScope allocationScope);
434void loader_instance_heap_free(const struct loader_instance *instance, void *pMemory);
435void *loader_instance_heap_realloc(const struct loader_instance *instance, void *pMemory, size_t orig_size, size_t size,
Mark Young26c19372016-11-03 14:27:13 -0600436 VkSystemAllocationScope alloc_scope);
Mark Young74dd5d12016-06-30 13:02:42 -0600437void *loader_instance_tls_heap_alloc(size_t size);
438void loader_instance_tls_heap_free(void *pMemory);
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700439void *loader_device_heap_alloc(const struct loader_device *device, size_t size, VkSystemAllocationScope allocationScope);
Mark Young74dd5d12016-06-30 13:02:42 -0600440void loader_device_heap_free(const struct loader_device *device, void *pMemory);
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700441void *loader_device_heap_realloc(const struct loader_device *device, void *pMemory, size_t orig_size, size_t size,
Mark Young26c19372016-11-03 14:27:13 -0600442 VkSystemAllocationScope alloc_scope);
Jon Ashburnc4e9ae62016-02-26 13:14:27 -0700443
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700444void loader_log(const struct loader_instance *inst, VkFlags msg_type, int32_t msg_code, const char *format, ...);
Jon Ashburn663f8312016-02-12 08:20:06 -0700445
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700446bool compare_vk_extension_properties(const VkExtensionProperties *op1, const VkExtensionProperties *op2);
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600447
Lenny Komow40761b02018-10-03 17:44:02 -0600448VkResult loaderValidateLayers(const struct loader_instance *inst, const uint32_t layer_count,
449 const char *const *ppEnabledLayerNames, const struct loader_layer_list *list);
Courtney Goeltzenleuchter76ece702015-07-06 17:45:08 -0600450
Lenny Komow40761b02018-10-03 17:44:02 -0600451VkResult loader_validate_instance_extensions(struct loader_instance *inst, const struct loader_extension_list *icd_exts,
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700452 const struct loader_layer_list *instance_layer,
453 const VkInstanceCreateInfo *pCreateInfo);
Courtney Goeltzenleuchter76ece702015-07-06 17:45:08 -0600454
Jon Ashburne0367472015-08-18 18:04:47 -0600455void loader_initialize(void);
Charles Giessen95a4ccd2020-03-02 15:04:30 -0700456void loader_preload_icds(void);
457void loader_unload_preloaded_icds(void);
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700458bool has_vk_extension_property_array(const VkExtensionProperties *vk_ext_prop, const uint32_t count,
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700459 const VkExtensionProperties *ext_array);
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700460bool has_vk_extension_property(const VkExtensionProperties *vk_ext_prop, const struct loader_extension_list *ext_list);
Jon Ashburn13482452015-05-12 17:26:48 -0600461
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700462VkResult loader_add_to_ext_list(const struct loader_instance *inst, struct loader_extension_list *ext_list,
463 uint32_t prop_list_count, const VkExtensionProperties *props);
464VkResult loader_add_to_dev_ext_list(const struct loader_instance *inst, struct loader_device_extension_list *ext_list,
465 const VkExtensionProperties *props, uint32_t entry_count, char **entrys);
Jon Ashburnc4e9ae62016-02-26 13:14:27 -0700466VkResult loader_add_device_extensions(const struct loader_instance *inst,
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700467 PFN_vkEnumerateDeviceExtensionProperties fpEnumerateDeviceExtensionProperties,
468 VkPhysicalDevice physical_device, const char *lib_name,
Jon Ashburnc4e9ae62016-02-26 13:14:27 -0700469 struct loader_extension_list *ext_list);
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700470VkResult loader_init_generic_list(const struct loader_instance *inst, struct loader_generic_list *list_info, size_t element_size);
471void loader_destroy_generic_list(const struct loader_instance *inst, struct loader_generic_list *list);
Lenny Komow40761b02018-10-03 17:44:02 -0600472void loaderDestroyLayerList(const struct loader_instance *inst, struct loader_device *device, struct loader_layer_list *layer_list);
473void loaderDeleteLayerListAndProperties(const struct loader_instance *inst, struct loader_layer_list *layer_list);
474void loaderAddLayerNameToList(const struct loader_instance *inst, const char *name, const enum layer_type_flags type_flags,
475 const struct loader_layer_list *source_list, struct loader_layer_list *target_list,
476 struct loader_layer_list *expanded_target_list);
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700477void loader_scanned_icd_clear(const struct loader_instance *inst, struct loader_icd_tramp_list *icd_tramp_list);
478VkResult loader_icd_scan(const struct loader_instance *inst, struct loader_icd_tramp_list *icd_tramp_list);
Lenny Komow40761b02018-10-03 17:44:02 -0600479void loaderScanForLayers(struct loader_instance *inst, struct loader_layer_list *instance_layers);
480void loaderScanForImplicitLayers(struct loader_instance *inst, struct loader_layer_list *instance_layers);
481bool loaderImplicitLayerIsEnabled(const struct loader_instance *inst, const struct loader_layer_properties *prop);
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700482VkResult loader_get_icd_loader_instance_extensions(const struct loader_instance *inst, struct loader_icd_tramp_list *icd_tramp_list,
483 struct loader_extension_list *inst_exts);
Lenny Komowa4f41ae2020-01-31 15:25:46 -0700484struct loader_icd_term *loader_get_icd_and_device(const void *device, struct loader_device **found_dev, uint32_t *icd_index);
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700485void loader_init_dispatch_dev_ext(struct loader_instance *inst, struct loader_device *dev);
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700486void *loader_dev_ext_gpa(struct loader_instance *inst, const char *funcName);
487void *loader_get_dev_ext_trampoline(uint32_t index);
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700488bool loader_phys_dev_ext_gpa(struct loader_instance *inst, const char *funcName, bool perform_checking, void **tramp_addr,
489 void **term_addr);
Mark Young274e4bc2017-01-19 21:10:49 -0700490void *loader_get_phys_dev_ext_tramp(uint32_t index);
491void *loader_get_phys_dev_ext_termin(uint32_t index);
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700492struct loader_instance *loader_get_instance(const VkInstance instance);
Lenny Komow40761b02018-10-03 17:44:02 -0600493void loaderDeactivateLayers(const struct loader_instance *instance, struct loader_device *device, struct loader_layer_list *list);
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700494struct loader_device *loader_create_logical_device(const struct loader_instance *inst, const VkAllocationCallbacks *pAllocator);
495void loader_add_logical_device(const struct loader_instance *inst, struct loader_icd_term *icd_term,
Piers Daniell82107a62016-03-29 11:51:11 -0600496 struct loader_device *found_dev);
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700497void loader_remove_logical_device(const struct loader_instance *inst, struct loader_icd_term *icd_term,
498 struct loader_device *found_dev, const VkAllocationCallbacks *pAllocator);
Mark Young15098392017-03-08 13:38:35 -0700499// NOTE: Outside of loader, this entry-point is only provided for error
Mark Young26c19372016-11-03 14:27:13 -0600500// cleanup.
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700501void loader_destroy_logical_device(const struct loader_instance *inst, struct loader_device *dev,
Mark Young74dd5d12016-06-30 13:02:42 -0600502 const VkAllocationCallbacks *pAllocator);
503
Lenny Komow40761b02018-10-03 17:44:02 -0600504VkResult loaderEnableInstanceLayers(struct loader_instance *inst, const VkInstanceCreateInfo *pCreateInfo,
505 const struct loader_layer_list *instance_layers);
Courtney Goeltzenleuchter0bd705c2016-01-08 12:18:43 -0700506
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700507VkResult loader_create_instance_chain(const VkInstanceCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
508 struct loader_instance *inst, VkInstance *created_instance);
Courtney Goeltzenleuchter0bd705c2016-01-08 12:18:43 -0700509
Lenny Komow40761b02018-10-03 17:44:02 -0600510void loaderActivateInstanceLayerExtensions(struct loader_instance *inst, VkInstance created_inst);
Courtney Goeltzenleuchter71b454b2015-07-05 11:28:29 -0600511
Felix Dörre06794722019-04-26 14:57:59 +0200512VKAPI_ATTR VkResult VKAPI_CALL loader_layer_create_device(VkInstance instance, VkPhysicalDevice physicalDevice,
513 const VkDeviceCreateInfo *pCreateInfo,
514 const VkAllocationCallbacks *pAllocator, VkDevice *pDevice,
515 PFN_vkGetInstanceProcAddr layerGIPA, PFN_vkGetDeviceProcAddr *nextGDPA);
516VKAPI_ATTR void VKAPI_CALL loader_layer_destroy_device(VkDevice device, const VkAllocationCallbacks *pAllocator,
517 PFN_vkDestroyDevice destroyFunction);
Felix Dörreb2223842018-12-11 18:29:38 +0100518
Felix Dörre34c3c5a2018-12-11 18:30:24 +0100519VkResult loader_create_device_chain(const VkPhysicalDevice pd, const VkDeviceCreateInfo *pCreateInfo,
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700520 const VkAllocationCallbacks *pAllocator, const struct loader_instance *inst,
Felix Dörre06794722019-04-26 14:57:59 +0200521 struct loader_device *dev, PFN_vkGetInstanceProcAddr callingLayer,
522 PFN_vkGetDeviceProcAddr *layerNextGDPA);
Mark Young274e4bc2017-01-19 21:10:49 -0700523
Felix Dörre34c3c5a2018-12-11 18:30:24 +0100524VkResult loader_validate_device_extensions(struct loader_instance *this_instance,
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700525 const struct loader_layer_list *activated_device_layers,
526 const struct loader_extension_list *icd_exts, const VkDeviceCreateInfo *pCreateInfo);
Courtney Goeltzenleuchter71b454b2015-07-05 11:28:29 -0600527
Mark Youngd4ff03b2017-01-12 12:27:19 -0700528VkResult setupLoaderTrampPhysDevs(VkInstance instance);
529VkResult setupLoaderTermPhysDevs(struct loader_instance *inst);
530
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700531VkStringErrorFlags vk_string_validate(const int max_length, const char *char_array);
Mark Lobodzinski8d325802016-02-02 18:53:34 -0700532
Mark Young74268f72017-05-02 10:49:46 -0600533#endif // LOADER_H