blob: 43600f9387a921acd7aa1e09761b6d887bf40037 [file] [log] [blame]
Chia-I Wu19300602014-08-04 08:03:57 +08001/*
Chia-I Wu19300602014-08-04 08:03:57 +08002 *
Mark Youngf2079b92017-05-02 10:49:46 -06003 * Copyright (c) 2014-2017 The Khronos Group Inc.
4 * Copyright (c) 2014-2017 Valve Corporation
5 * Copyright (c) 2014-2017 LunarG, Inc.
Courtney Goeltzenleuchterf821dad2015-12-02 14:53:22 -07006 * Copyright (C) 2015 Google Inc.
Chia-I Wu19300602014-08-04 08:03:57 +08007 *
Jon Ashburn3ebf1252016-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 Wu19300602014-08-04 08:03:57 +080011 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -060012 * http://www.apache.org/licenses/LICENSE-2.0
Chia-I Wu19300602014-08-04 08:03:57 +080013 *
Jon Ashburn3ebf1252016-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 Ashburn23d36b12016-02-02 17:47:28 -070019 *
20 * Author: Jon Ashburn <jon@lunarg.com>
21 * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
Courtney Goeltzenleuchter05559522015-10-30 11:14:30 -060022 * Author: Chia-I Wu <olvaffe@gmail.com>
23 * Author: Chia-I Wu <olv@lunarg.com>
Jon Ashburn23d36b12016-02-02 17:47:28 -070024 * Author: Mark Lobodzinski <mark@LunarG.com>
Courtney Goeltzenleuchter05559522015-10-30 11:14:30 -060025 *
Chia-I Wu19300602014-08-04 08:03:57 +080026 */
27
28#ifndef LOADER_H
29#define LOADER_H
30
David Pinedo9316d3b2015-11-06 12:54:48 -070031#include <vulkan/vulkan.h>
Aaron Karp848bad42016-03-13 16:41:59 -040032#include "vk_loader_platform.h"
Mark Lobodzinskib87f9022016-05-24 16:04:56 -060033#include "vk_loader_layer.h"
David Pinedo9316d3b2015-11-06 12:54:48 -070034#include <vulkan/vk_layer.h>
35#include <vulkan/vk_icd.h>
Chia-I Wu5291c762015-04-11 15:34:07 +080036#include <assert.h>
Mark Young0f183a82017-02-28 09:58:04 -070037#include "vk_loader_extensions.h"
Chia-I Wu5291c762015-04-11 15:34:07 +080038
Chia-I Wu19300602014-08-04 08:03:57 +080039#if defined(__GNUC__) && __GNUC__ >= 4
Jon Ashburn23d36b12016-02-02 17:47:28 -070040#define LOADER_EXPORT __attribute__((visibility("default")))
Chia-I Wu19300602014-08-04 08:03:57 +080041#elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)
Jon Ashburn23d36b12016-02-02 17:47:28 -070042#define LOADER_EXPORT __attribute__((visibility("default")))
Chia-I Wu19300602014-08-04 08:03:57 +080043#else
Jon Ashburn23d36b12016-02-02 17:47:28 -070044#define LOADER_EXPORT
Chia-I Wu19300602014-08-04 08:03:57 +080045#endif
46
Mark Young0ad83132016-06-30 13:02:42 -060047// A debug option to disable allocators at compile time to investigate future issues.
48#define DEBUG_DISABLE_APP_ALLOCATORS 0
49
Jon Ashburnf73e9212015-08-04 10:22:33 -060050#define MAX_STRING_SIZE 1024
Jon Ashburn27cd5842015-05-12 17:26:48 -060051
Mark Young39389872017-01-19 21:10:49 -070052// This is defined in vk_layer.h, but if there's problems we need to create the define
53// here.
54#ifndef MAX_NUM_UNKNOWN_EXTS
55#define MAX_NUM_UNKNOWN_EXTS 250
56#endif
57
Mark Youngf2079b92017-05-02 10:49:46 -060058enum layer_type_flags {
59 VK_LAYER_TYPE_FLAG_INSTANCE_LAYER = 0x1, // If not set, indicates Device layer
60 VK_LAYER_TYPE_FLAG_EXPLICIT_LAYER = 0x2, // If not set, indicates Implicit layer
61 VK_LAYER_TYPE_FLAG_META_LAYER = 0x4, // If not set, indicates standard layer
Jon Ashburn5ef20602015-07-02 09:40:15 -060062};
63
Mark Lobodzinskie9f09ef2016-02-02 18:53:34 -070064typedef enum VkStringErrorFlagBits {
Jon Ashburnf2b4e382016-02-10 20:50:19 -070065 VK_STRING_ERROR_NONE = 0x00000000,
66 VK_STRING_ERROR_LENGTH = 0x00000001,
67 VK_STRING_ERROR_BAD_DATA = 0x00000002,
Mark Lobodzinskie9f09ef2016-02-02 18:53:34 -070068} VkStringErrorFlagBits;
69typedef VkFlags VkStringErrorFlags;
70
Jon Ashburnf2b4e382016-02-10 20:50:19 -070071static const int MaxLoaderStringLength = 256;
72static const char UTF8_ONE_BYTE_CODE = 0xC0;
73static const char UTF8_ONE_BYTE_MASK = 0xE0;
74static const char UTF8_TWO_BYTE_CODE = 0xE0;
75static const char UTF8_TWO_BYTE_MASK = 0xF0;
76static const char UTF8_THREE_BYTE_CODE = 0xF0;
77static const char UTF8_THREE_BYTE_MASK = 0xF8;
78static const char UTF8_DATA_BYTE_CODE = 0x80;
79static const char UTF8_DATA_BYTE_MASK = 0xC0;
Mark Lobodzinskie9f09ef2016-02-02 18:53:34 -070080
Mark Young39389872017-01-19 21:10:49 -070081struct VkStructureHeader {
82 VkStructureType sType;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070083 const void *pNext;
Mark Young39389872017-01-19 21:10:49 -070084};
85
Jon Ashburn6e6a2162015-12-10 08:51:10 -070086// form of all dynamic lists/arrays
87// only the list element should be changed
88struct loader_generic_list {
89 size_t capacity;
90 uint32_t count;
91 void *list;
92};
93
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -060094struct loader_extension_list {
95 size_t capacity;
96 uint32_t count;
Jon Ashburn5c042ea2015-08-04 11:14:18 -060097 VkExtensionProperties *list;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -060098};
99
Jon Ashburn39fbd4e2015-12-10 18:17:34 -0700100struct loader_dev_ext_props {
101 VkExtensionProperties props;
102 uint32_t entrypoint_count;
103 char **entrypoints;
104};
105
106struct loader_device_extension_list {
107 size_t capacity;
108 uint32_t count;
109 struct loader_dev_ext_props *list;
110};
111
Jon Ashburn5ef20602015-07-02 09:40:15 -0600112struct loader_name_value {
Jon Ashburnf73e9212015-08-04 10:22:33 -0600113 char name[MAX_STRING_SIZE];
114 char value[MAX_STRING_SIZE];
Jon Ashburn5ef20602015-07-02 09:40:15 -0600115};
116
Jon Ashburn5ef20602015-07-02 09:40:15 -0600117struct loader_layer_functions {
Jon Ashburnf73e9212015-08-04 10:22:33 -0600118 char str_gipa[MAX_STRING_SIZE];
119 char str_gdpa[MAX_STRING_SIZE];
Mark Young39389872017-01-19 21:10:49 -0700120 char str_negotiate_interface[MAX_STRING_SIZE];
121 PFN_vkNegotiateLoaderLayerInterfaceVersion negotiate_layer_interface;
Jon Ashburn5ef20602015-07-02 09:40:15 -0600122 PFN_vkGetInstanceProcAddr get_instance_proc_addr;
123 PFN_vkGetDeviceProcAddr get_device_proc_addr;
Mark Young39389872017-01-19 21:10:49 -0700124 PFN_GetPhysicalDeviceProcAddr get_physical_device_proc_addr;
Jon Ashburn5ef20602015-07-02 09:40:15 -0600125};
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600126
Jon Ashburn5ef20602015-07-02 09:40:15 -0600127struct loader_layer_properties {
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -0600128 VkLayerProperties info;
Mark Youngf2079b92017-05-02 10:49:46 -0600129 enum layer_type_flags type_flags;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700130 uint32_t interface_version; // PFN_vkNegotiateLoaderLayerInterfaceVersion
Jon Ashburn3d002332015-08-20 16:35:30 -0600131 char lib_name[MAX_STRING_SIZE];
Jon Ashburn4dc1d8a2016-04-20 13:21:17 -0600132 loader_platform_dl_handle lib_handle;
Jon Ashburn5ef20602015-07-02 09:40:15 -0600133 struct loader_layer_functions functions;
134 struct loader_extension_list instance_extension_list;
Jon Ashburn39fbd4e2015-12-10 18:17:34 -0700135 struct loader_device_extension_list device_extension_list;
Jon Ashburn5ef20602015-07-02 09:40:15 -0600136 struct loader_name_value disable_env_var;
137 struct loader_name_value enable_env_var;
Mark Youngf2079b92017-05-02 10:49:46 -0600138 uint32_t num_component_layers;
139 char (*component_layer_names)[MAX_STRING_SIZE];
Jon Ashburn5ef20602015-07-02 09:40:15 -0600140};
141
142struct loader_layer_list {
143 size_t capacity;
144 uint32_t count;
145 struct loader_layer_properties *list;
Jon Ashburn27cd5842015-05-12 17:26:48 -0600146};
147
Jon Ashburnfc1031e2015-11-17 15:31:02 -0700148struct loader_dispatch_hash_list {
149 size_t capacity;
150 uint32_t count;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700151 uint32_t *index; // index into the dev_ext dispatch table
Jon Ashburnfc1031e2015-11-17 15:31:02 -0700152};
153
Mark Young8191d9f2016-09-02 11:41:28 -0600154// loader_dispatch_hash_entry and loader_dev_ext_dispatch_table.dev_ext have
155// one to one correspondence; one loader_dispatch_hash_entry for one dev_ext
156// dispatch entry.
Jon Ashburnfc1031e2015-11-17 15:31:02 -0700157// Also have a one to one correspondence with functions in dev_ext_trampoline.c
158struct loader_dispatch_hash_entry {
159 char *func_name;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700160 struct loader_dispatch_hash_list list; // to handle hashing collisions
Jon Ashburnfc1031e2015-11-17 15:31:02 -0700161};
162
Jon Ashburn23d36b12016-02-02 17:47:28 -0700163typedef void(VKAPI_PTR *PFN_vkDevExt)(VkDevice device);
Jon Ashburnfc1031e2015-11-17 15:31:02 -0700164struct loader_dev_ext_dispatch_table {
Mark Young39389872017-01-19 21:10:49 -0700165 PFN_vkDevExt dev_ext[MAX_NUM_UNKNOWN_EXTS];
Jon Ashburnfc1031e2015-11-17 15:31:02 -0700166};
167
168struct loader_dev_dispatch_table {
169 VkLayerDispatchTable core_dispatch;
170 struct loader_dev_ext_dispatch_table ext_dispatch;
171};
172
Mark Young35159af2016-09-07 08:50:32 -0600173// per CreateDevice structure
Jon Ashburndc6fcad2015-06-10 10:06:06 -0600174struct loader_device {
Jon Ashburnfc1031e2015-11-17 15:31:02 -0700175 struct loader_dev_dispatch_table loader_dispatch;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700176 VkDevice chain_device; // device object from the dispatch chain
177 VkDevice icd_device; // device object from the icd
Mark Young65cb3662016-11-07 13:27:02 -0700178 struct loader_physical_device_term *phys_dev_term;
Jon Ashburndc6fcad2015-06-10 10:06:06 -0600179
Mark Young283fe1c2017-05-04 12:16:35 -0600180 // List of activated layers.
181 // app_ is the version based on exactly what the application asked for.
182 // This is what must be returned to the application on Enumerate calls.
183 // expanded_ is the version based on expanding meta-layers into their
184 // individual component layers. This is what is used internally.
185 struct loader_layer_list app_activated_layer_list;
186 struct loader_layer_list expanded_activated_layer_list;
Jon Ashburndc6fcad2015-06-10 10:06:06 -0600187
Mark Young0ad83132016-06-30 13:02:42 -0600188 VkAllocationCallbacks alloc_callbacks;
189
Jon Ashburndc6fcad2015-06-10 10:06:06 -0600190 struct loader_device *next;
191};
192
Mark Young0f183a82017-02-28 09:58:04 -0700193// Per ICD information
194
195// Per ICD structure
Mark Young0153e0b2016-11-03 14:27:13 -0600196struct loader_icd_term {
Jon Ashburn3d002332015-08-20 16:35:30 -0600197 // pointers to find other structs
Mark Young0153e0b2016-11-03 14:27:13 -0600198 const struct loader_scanned_icd *scanned_icd;
Jon Ashburn3d002332015-08-20 16:35:30 -0600199 const struct loader_instance *this_instance;
Jon Ashburndc6fcad2015-06-10 10:06:06 -0600200 struct loader_device *logical_device_list;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700201 VkInstance instance; // instance object from the icd
Mark Young0f183a82017-02-28 09:58:04 -0700202 struct loader_icd_term_dispatch dispatch;
Mark Youngfa552782016-12-12 16:14:55 -0700203
Mark Young0153e0b2016-11-03 14:27:13 -0600204 struct loader_icd_term *next;
Mark Young39389872017-01-19 21:10:49 -0700205
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700206 PFN_PhysDevExt phys_dev_ext[MAX_NUM_UNKNOWN_EXTS];
Jon Ashburn95a77ba2015-05-15 15:09:35 -0600207};
208
Mark Young0f183a82017-02-28 09:58:04 -0700209// Per ICD library structure
Mark Young0153e0b2016-11-03 14:27:13 -0600210struct loader_icd_tramp_list {
Jon Ashburn8810c5f2015-08-18 18:04:47 -0600211 size_t capacity;
212 uint32_t count;
Mark Young0153e0b2016-11-03 14:27:13 -0600213 struct loader_scanned_icd *scanned_list;
Jon Ashburn8810c5f2015-08-18 18:04:47 -0600214};
215
Mark Young39389872017-01-19 21:10:49 -0700216struct loader_instance_dispatch_table {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700217 VkLayerInstanceDispatchTable layer_inst_disp; // must be first entry in structure
Mark Young39389872017-01-19 21:10:49 -0700218
219 // Physical device functions unknown to the loader
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700220 PFN_PhysDevExt phys_dev_ext[MAX_NUM_UNKNOWN_EXTS];
Mark Young39389872017-01-19 21:10:49 -0700221};
222
Mark Young0f183a82017-02-28 09:58:04 -0700223// Per instance structure
Jon Ashburn27cd5842015-05-12 17:26:48 -0600224struct loader_instance {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700225 struct loader_instance_dispatch_table *disp; // must be first entry in structure
Jon Ashburn95a77ba2015-05-15 15:09:35 -0600226
Mark Youngd66edd52017-03-10 17:31:18 -0700227 // We need to manually track physical devices over time. If the user
228 // re-queries the information, we don't want to delete old data or
229 // create new data unless necessary.
Mark Young0153e0b2016-11-03 14:27:13 -0600230 uint32_t total_gpu_count;
Lenny Komow8a1f8a52016-12-20 15:35:11 -0700231 uint32_t phys_dev_count_term;
232 struct loader_physical_device_term **phys_devs_term;
Lenny Komowb9f70c32016-12-19 17:11:40 -0700233 uint32_t phys_dev_count_tramp;
234 struct loader_physical_device_tramp **phys_devs_tramp;
Mark Young0153e0b2016-11-03 14:27:13 -0600235
Mark Youngd66edd52017-03-10 17:31:18 -0700236 // We also need to manually track physical device groups, but we don't need
237 // loader specific structures since we have that content in the physical
238 // device stored internal to the public structures.
239 uint32_t phys_dev_group_count_term;
240 struct VkPhysicalDeviceGroupPropertiesKHX **phys_dev_groups_term;
241 uint32_t phys_dev_group_count_tramp;
242 struct VkPhysicalDeviceGroupPropertiesKHX **phys_dev_groups_tramp;
243
Jon Ashburn27cd5842015-05-12 17:26:48 -0600244 struct loader_instance *next;
Mark Young0153e0b2016-11-03 14:27:13 -0600245
246 uint32_t total_icd_count;
247 struct loader_icd_term *icd_terms;
248 struct loader_icd_tramp_list icd_tramp_list;
249
Mark Young39389872017-01-19 21:10:49 -0700250 struct loader_dispatch_hash_entry dev_ext_disp_hash[MAX_NUM_UNKNOWN_EXTS];
251 struct loader_dispatch_hash_entry phys_dev_ext_disp_hash[MAX_NUM_UNKNOWN_EXTS];
Jon Ashburn3d002332015-08-20 16:35:30 -0600252
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600253 struct loader_msg_callback_map_entry *icd_msg_callback_map;
254
Mark Young0153e0b2016-11-03 14:27:13 -0600255 struct loader_layer_list instance_layer_list;
Mark Young283fe1c2017-05-04 12:16:35 -0600256
257 // List of activated layers.
258 // app_ is the version based on exactly what the application asked for.
259 // This is what must be returned to the application on Enumerate calls.
260 // expanded_ is the version based on expanding meta-layers into their
261 // individual component layers. This is what is used internally.
262 struct loader_layer_list app_activated_layer_list;
263 struct loader_layer_list expanded_activated_layer_list;
264
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700265 VkInstance instance; // layers/ICD instance returned to trampoline
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700266
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700267 struct loader_extension_list ext_list; // icds and loaders extensions
Mark Young0153e0b2016-11-03 14:27:13 -0600268 union loader_instance_extension_enables enabled_known_extensions;
269
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600270 VkLayerDbgFunctionNode *DbgFunctionHead;
Ian Elliottad6300f2016-03-31 10:48:19 -0600271 uint32_t num_tmp_callbacks;
272 VkDebugReportCallbackCreateInfoEXT *tmp_dbg_create_infos;
273 VkDebugReportCallbackEXT *tmp_callbacks;
Courtney Goeltzenleuchter7f5aafc2015-07-05 11:28:29 -0600274
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800275 VkAllocationCallbacks alloc_callbacks;
Ian Elliottd3ef02f2015-07-06 14:36:13 -0600276
Ian Elliott954fa342015-10-30 15:28:23 -0600277 bool wsi_surface_enabled;
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -0700278#ifdef VK_USE_PLATFORM_WIN32_KHR
Ian Elliott954fa342015-10-30 15:28:23 -0600279 bool wsi_win32_surface_enabled;
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -0700280#endif
281#ifdef VK_USE_PLATFORM_MIR_KHR
Ian Elliott954fa342015-10-30 15:28:23 -0600282 bool wsi_mir_surface_enabled;
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -0700283#endif
284#ifdef VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott954fa342015-10-30 15:28:23 -0600285 bool wsi_wayland_surface_enabled;
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -0700286#endif
287#ifdef VK_USE_PLATFORM_XCB_KHR
Ian Elliott954fa342015-10-30 15:28:23 -0600288 bool wsi_xcb_surface_enabled;
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -0700289#endif
290#ifdef VK_USE_PLATFORM_XLIB_KHR
Ian Elliott954fa342015-10-30 15:28:23 -0600291 bool wsi_xlib_surface_enabled;
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -0700292#endif
293#ifdef VK_USE_PLATFORM_ANDROID_KHR
294 bool wsi_android_surface_enabled;
295#endif
Jon Ashburnc7d3e732016-03-08 09:30:30 -0700296 bool wsi_display_enabled;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600297};
298
Mark Young0f183a82017-02-28 09:58:04 -0700299// VkPhysicalDevice requires special treatment by loader. Firstly, terminator
300// code must be able to get the struct loader_icd_term to call into the proper
301// driver (multiple ICD/gpu case). This can be accomplished by wrapping the
302// created VkPhysicalDevice in loader terminate_EnumeratePhysicalDevices().
303// Secondly, the loader must be able to handle wrapped by layer VkPhysicalDevice
304// in trampoline code. This implies, that the loader trampoline code must also
305// wrap the VkPhysicalDevice object in trampoline code. Thus, loader has to
306// wrap the VkPhysicalDevice created object twice. In trampoline code it can't
307// rely on the terminator object wrapping since a layer may also wrap. Since
308// trampoline code wraps the VkPhysicalDevice this means all loader trampoline
309// code that passes a VkPhysicalDevice should unwrap it.
Jon Ashburn014438f2016-03-01 19:51:07 -0700310
Mark Young0f183a82017-02-28 09:58:04 -0700311// Per enumerated PhysicalDevice structure, used to wrap in trampoline code and
312// also same structure used to wrap in terminator code
Jon Ashburn787eb252016-03-24 15:49:57 -0600313struct loader_physical_device_tramp {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700314 struct loader_instance_dispatch_table *disp; // must be first entry in structure
Piers Daniell295fe402016-03-29 11:51:11 -0600315 struct loader_instance *this_instance;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700316 VkPhysicalDevice phys_dev; // object from layers/loader terminator
Jon Ashburn787eb252016-03-24 15:49:57 -0600317};
318
Mark Young0f183a82017-02-28 09:58:04 -0700319// Per enumerated PhysicalDevice structure, used to wrap in terminator code
Mark Young0153e0b2016-11-03 14:27:13 -0600320struct loader_physical_device_term {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700321 struct loader_instance_dispatch_table *disp; // must be first entry in structure
Mark Young0153e0b2016-11-03 14:27:13 -0600322 struct loader_icd_term *this_icd_term;
Mark Young16573c72016-06-28 10:52:43 -0600323 uint8_t icd_index;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700324 VkPhysicalDevice phys_dev; // object from ICD
Jon Ashburn24cd4be2015-11-01 14:04:06 -0700325};
326
Jon Ashburn27cd5842015-05-12 17:26:48 -0600327struct loader_struct {
328 struct loader_instance *instances;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600329};
330
Mark Young0153e0b2016-11-03 14:27:13 -0600331struct loader_scanned_icd {
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600332 char *lib_name;
333 loader_platform_dl_handle handle;
Jon Ashburn005617f2015-11-17 17:35:40 -0700334 uint32_t api_version;
Jon Ashburn17b4c862016-04-25 11:09:37 -0600335 uint32_t interface_version;
Jon Ashburnc624c882015-07-16 10:17:29 -0600336 PFN_vkGetInstanceProcAddr GetInstanceProcAddr;
Mark Young39389872017-01-19 21:10:49 -0700337 PFN_GetPhysicalDeviceProcAddr GetPhysicalDeviceProcAddr;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600338 PFN_vkCreateInstance CreateInstance;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700339 PFN_vkEnumerateInstanceExtensionProperties EnumerateInstanceExtensionProperties;
Jon Ashburn27cd5842015-05-12 17:26:48 -0600340};
341
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700342static inline struct loader_instance *loader_instance(VkInstance instance) { return (struct loader_instance *)instance; }
Jon Ashburn5ef20602015-07-02 09:40:15 -0600343
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700344static inline VkPhysicalDevice loader_unwrap_physical_device(VkPhysicalDevice physicalDevice) {
345 struct loader_physical_device_tramp *phys_dev = (struct loader_physical_device_tramp *)physicalDevice;
Jon Ashburn014438f2016-03-01 19:51:07 -0700346 return phys_dev->phys_dev;
347}
348
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700349static inline void loader_set_dispatch(void *obj, const void *data) { *((const void **)obj) = data; }
Chia-I Wu5291c762015-04-11 15:34:07 +0800350
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700351static inline VkLayerDispatchTable *loader_get_dispatch(const void *obj) { return *((VkLayerDispatchTable **)obj); }
Chia-I Wu5291c762015-04-11 15:34:07 +0800352
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700353static inline struct loader_dev_dispatch_table *loader_get_dev_dispatch(const void *obj) {
Jon Ashburn23d36b12016-02-02 17:47:28 -0700354 return *((struct loader_dev_dispatch_table **)obj);
Jon Ashburnfc1031e2015-11-17 15:31:02 -0700355}
356
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700357static inline VkLayerInstanceDispatchTable *loader_get_instance_layer_dispatch(const void *obj) {
Jon Ashburn23d36b12016-02-02 17:47:28 -0700358 return *((VkLayerInstanceDispatchTable **)obj);
Jon Ashburn27cd5842015-05-12 17:26:48 -0600359}
360
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700361static inline struct loader_instance_dispatch_table *loader_get_instance_dispatch(const void *obj) {
Mark Young39389872017-01-19 21:10:49 -0700362 return *((struct loader_instance_dispatch_table **)obj);
363}
364
Jon Ashburn23d36b12016-02-02 17:47:28 -0700365static inline void loader_init_dispatch(void *obj, const void *data) {
Jon Ashburn40066642015-04-15 13:34:33 -0600366#ifdef DEBUG
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700367 assert(valid_loader_magic_value(obj) &&
368 "Incompatible ICD, first dword must be initialized to "
369 "ICD_LOADER_MAGIC. See loader/README.md for details.");
Jon Ashburn40066642015-04-15 13:34:33 -0600370#endif
Chia-I Wu5291c762015-04-11 15:34:07 +0800371
Jon Ashburn1ed042c2015-05-01 18:00:33 -0600372 loader_set_dispatch(obj, data);
Chia-I Wu5291c762015-04-11 15:34:07 +0800373}
374
Mark Young0f183a82017-02-28 09:58:04 -0700375// Global variables used across files
Jon Ashburn27cd5842015-05-12 17:26:48 -0600376extern struct loader_struct loader;
Jon Ashburn87d6aa92015-08-28 15:19:27 -0600377extern THREAD_LOCAL_DECL struct loader_instance *tls_instance;
Jon Ashburn8810c5f2015-08-18 18:04:47 -0600378extern LOADER_PLATFORM_THREAD_ONCE_DEFINITION(once_init);
Jon Ashburn6301a0f2015-05-29 13:15:39 -0600379extern loader_platform_thread_mutex loader_lock;
Jon Ashburn6461ef22015-09-22 13:11:00 -0600380extern loader_platform_thread_mutex loader_json_lock;
Jon Ashburnbacb0f52015-04-06 10:58:22 -0600381
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600382struct loader_msg_callback_map_entry {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700383 VkDebugReportCallbackEXT icd_obj;
384 VkDebugReportCallbackEXT loader_obj;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600385};
386
Mark Young0f183a82017-02-28 09:58:04 -0700387// Helper function definitions
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700388void *loader_instance_heap_alloc(const struct loader_instance *instance, size_t size, VkSystemAllocationScope allocationScope);
389void loader_instance_heap_free(const struct loader_instance *instance, void *pMemory);
390void *loader_instance_heap_realloc(const struct loader_instance *instance, void *pMemory, size_t orig_size, size_t size,
Mark Young0153e0b2016-11-03 14:27:13 -0600391 VkSystemAllocationScope alloc_scope);
Mark Young0ad83132016-06-30 13:02:42 -0600392void *loader_instance_tls_heap_alloc(size_t size);
393void loader_instance_tls_heap_free(void *pMemory);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700394void *loader_device_heap_alloc(const struct loader_device *device, size_t size, VkSystemAllocationScope allocationScope);
Mark Young0ad83132016-06-30 13:02:42 -0600395void loader_device_heap_free(const struct loader_device *device, void *pMemory);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700396void *loader_device_heap_realloc(const struct loader_device *device, void *pMemory, size_t orig_size, size_t size,
Mark Young0153e0b2016-11-03 14:27:13 -0600397 VkSystemAllocationScope alloc_scope);
Jon Ashburn1530c342016-02-26 13:14:27 -0700398
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700399void loader_log(const struct loader_instance *inst, VkFlags msg_type, int32_t msg_code, const char *format, ...);
Jon Ashburn2e37d752016-02-12 08:20:06 -0700400
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700401bool compare_vk_extension_properties(const VkExtensionProperties *op1, const VkExtensionProperties *op2);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600402
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700403VkResult loader_validate_layers(const struct loader_instance *inst, const uint32_t layer_count,
404 const char *const *ppEnabledLayerNames, const struct loader_layer_list *list);
Courtney Goeltzenleuchter3b8c5ff2015-07-06 17:45:08 -0600405
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700406VkResult loader_validate_instance_extensions(const struct loader_instance *inst, const struct loader_extension_list *icd_exts,
407 const struct loader_layer_list *instance_layer,
408 const VkInstanceCreateInfo *pCreateInfo);
Courtney Goeltzenleuchter3b8c5ff2015-07-06 17:45:08 -0600409
Jon Ashburn8810c5f2015-08-18 18:04:47 -0600410void loader_initialize(void);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700411VkResult loader_copy_layer_properties(const struct loader_instance *inst, struct loader_layer_properties *dst,
Mark Young0ad83132016-06-30 13:02:42 -0600412 struct loader_layer_properties *src);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700413bool has_vk_extension_property_array(const VkExtensionProperties *vk_ext_prop, const uint32_t count,
Jon Ashburn23d36b12016-02-02 17:47:28 -0700414 const VkExtensionProperties *ext_array);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700415bool has_vk_extension_property(const VkExtensionProperties *vk_ext_prop, const struct loader_extension_list *ext_list);
Jon Ashburn27cd5842015-05-12 17:26:48 -0600416
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700417VkResult loader_add_to_ext_list(const struct loader_instance *inst, struct loader_extension_list *ext_list,
418 uint32_t prop_list_count, const VkExtensionProperties *props);
419VkResult loader_add_to_dev_ext_list(const struct loader_instance *inst, struct loader_device_extension_list *ext_list,
420 const VkExtensionProperties *props, uint32_t entry_count, char **entrys);
Jon Ashburn1530c342016-02-26 13:14:27 -0700421VkResult loader_add_device_extensions(const struct loader_instance *inst,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700422 PFN_vkEnumerateDeviceExtensionProperties fpEnumerateDeviceExtensionProperties,
423 VkPhysicalDevice physical_device, const char *lib_name,
Jon Ashburn1530c342016-02-26 13:14:27 -0700424 struct loader_extension_list *ext_list);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700425VkResult loader_init_generic_list(const struct loader_instance *inst, struct loader_generic_list *list_info, size_t element_size);
426void loader_destroy_generic_list(const struct loader_instance *inst, struct loader_generic_list *list);
427void loader_destroy_layer_list(const struct loader_instance *inst, struct loader_device *device,
Jon Ashburn1530c342016-02-26 13:14:27 -0700428 struct loader_layer_list *layer_list);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700429void loader_delete_layer_properties(const struct loader_instance *inst, struct loader_layer_list *layer_list);
430bool loader_find_layer_name_array(const char *name, uint32_t layer_count, const char layer_list[][VK_MAX_EXTENSION_NAME_SIZE]);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700431VkResult loader_add_to_layer_list(const struct loader_instance *inst, struct loader_layer_list *list, uint32_t prop_list_count,
Mark Young0ad83132016-06-30 13:02:42 -0600432 const struct loader_layer_properties *props);
Mark Youngf2079b92017-05-02 10:49:46 -0600433void loader_find_layer_name_add_list(const struct loader_instance *inst, const char *name, const enum layer_type_flags type_flags,
Mark Young283fe1c2017-05-04 12:16:35 -0600434 const struct loader_layer_list *source_list, struct loader_layer_list *target_list,
435 struct loader_layer_list *expanded_target_list);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700436void loader_scanned_icd_clear(const struct loader_instance *inst, struct loader_icd_tramp_list *icd_tramp_list);
437VkResult loader_icd_scan(const struct loader_instance *inst, struct loader_icd_tramp_list *icd_tramp_list);
438void loader_layer_scan(const struct loader_instance *inst, struct loader_layer_list *instance_layers);
439void loader_implicit_layer_scan(const struct loader_instance *inst, struct loader_layer_list *instance_layers);
Jean-Francois Roybd7ceab2017-07-06 14:10:13 -0700440bool loader_is_implicit_layer_enabled(const struct loader_instance *inst, const struct loader_layer_properties *prop);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700441VkResult loader_get_icd_loader_instance_extensions(const struct loader_instance *inst, struct loader_icd_tramp_list *icd_tramp_list,
442 struct loader_extension_list *inst_exts);
443struct loader_icd_term *loader_get_icd_and_device(const VkDevice device, struct loader_device **found_dev, uint32_t *icd_index);
444void loader_init_dispatch_dev_ext(struct loader_instance *inst, struct loader_device *dev);
Jon Ashburn23d36b12016-02-02 17:47:28 -0700445void *loader_dev_ext_gpa(struct loader_instance *inst, const char *funcName);
446void *loader_get_dev_ext_trampoline(uint32_t index);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700447bool loader_phys_dev_ext_gpa(struct loader_instance *inst, const char *funcName, bool perform_checking, void **tramp_addr,
448 void **term_addr);
Mark Young39389872017-01-19 21:10:49 -0700449void *loader_get_phys_dev_ext_tramp(uint32_t index);
450void *loader_get_phys_dev_ext_termin(uint32_t index);
Jon Ashburn23d36b12016-02-02 17:47:28 -0700451struct loader_instance *loader_get_instance(const VkInstance instance);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700452void loader_deactivate_layers(const struct loader_instance *instance, struct loader_device *device, struct loader_layer_list *list);
453struct loader_device *loader_create_logical_device(const struct loader_instance *inst, const VkAllocationCallbacks *pAllocator);
454void loader_add_logical_device(const struct loader_instance *inst, struct loader_icd_term *icd_term,
Piers Daniell295fe402016-03-29 11:51:11 -0600455 struct loader_device *found_dev);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700456void loader_remove_logical_device(const struct loader_instance *inst, struct loader_icd_term *icd_term,
457 struct loader_device *found_dev, const VkAllocationCallbacks *pAllocator);
Mark Youngdee312c2017-03-08 13:38:35 -0700458// NOTE: Outside of loader, this entry-point is only provided for error
Mark Young0153e0b2016-11-03 14:27:13 -0600459// cleanup.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700460void loader_destroy_logical_device(const struct loader_instance *inst, struct loader_device *dev,
Mark Young0ad83132016-06-30 13:02:42 -0600461 const VkAllocationCallbacks *pAllocator);
462
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700463VkResult loader_enable_instance_layers(struct loader_instance *inst, const VkInstanceCreateInfo *pCreateInfo,
464 const struct loader_layer_list *instance_layers);
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700465
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700466VkResult loader_create_instance_chain(const VkInstanceCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
467 struct loader_instance *inst, VkInstance *created_instance);
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700468
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700469void loader_activate_instance_layer_extensions(struct loader_instance *inst, VkInstance created_inst);
Courtney Goeltzenleuchter7f5aafc2015-07-05 11:28:29 -0600470
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700471VkResult loader_create_device_chain(const struct loader_physical_device_tramp *pd, const VkDeviceCreateInfo *pCreateInfo,
472 const VkAllocationCallbacks *pAllocator, const struct loader_instance *inst,
473 struct loader_device *dev);
Mark Young39389872017-01-19 21:10:49 -0700474
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700475VkResult loader_validate_device_extensions(struct loader_physical_device_tramp *phys_dev,
476 const struct loader_layer_list *activated_device_layers,
477 const struct loader_extension_list *icd_exts, const VkDeviceCreateInfo *pCreateInfo);
Courtney Goeltzenleuchter7f5aafc2015-07-05 11:28:29 -0600478
Mark Young6267ae62017-01-12 12:27:19 -0700479VkResult setupLoaderTrampPhysDevs(VkInstance instance);
480VkResult setupLoaderTermPhysDevs(struct loader_instance *inst);
481
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700482VkStringErrorFlags vk_string_validate(const int max_length, const char *char_array);
Mark Lobodzinskie9f09ef2016-02-02 18:53:34 -0700483
Mark Youngf2079b92017-05-02 10:49:46 -0600484#endif // LOADER_H