blob: 20453d38e5931864589043362186890e3966401b [file] [log] [blame]
Chia-I Wuc1e0f962014-08-04 08:03:57 +08001/*
Chia-I Wuc1e0f962014-08-04 08:03:57 +08002 *
Jon Ashburn1c75aec2016-02-02 17:47:28 -07003 * Copyright (c) 2014-2016 The Khronos Group Inc.
4 * Copyright (c) 2014-2016 Valve Corporation
5 * Copyright (c) 2014-2016 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 Ashburn1c75aec2016-02-02 17:47:28 -07008 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and/or associated documentation files (the "Materials"), to
10 * deal in the Materials without restriction, including without limitation the
11 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
12 * sell copies of the Materials, and to permit persons to whom the Materials are
13 * furnished to do so, subject to the following conditions:
Chia-I Wuc1e0f962014-08-04 08:03:57 +080014 *
Jon Ashburn1c75aec2016-02-02 17:47:28 -070015 * The above copyright notice(s) and this permission notice shall be included in
16 * all copies or substantial portions of the Materials.
Chia-I Wuc1e0f962014-08-04 08:03:57 +080017 *
Jon Ashburn1c75aec2016-02-02 17:47:28 -070018 * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Chia-I Wuc1e0f962014-08-04 08:03:57 +080019 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Jon Ashburn1c75aec2016-02-02 17:47:28 -070020 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
Chia-I Wud8ab1e62014-09-02 08:32:09 +080021 *
Jon Ashburn1c75aec2016-02-02 17:47:28 -070022 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
23 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE
25 * USE OR OTHER DEALINGS IN THE MATERIALS.
26 *
27 * Author: Jon Ashburn <jon@lunarg.com>
28 * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
Courtney Goeltzenleuchterb9ce3952015-10-30 11:14:30 -060029 * Author: Chia-I Wu <olvaffe@gmail.com>
30 * Author: Chia-I Wu <olv@lunarg.com>
Jon Ashburn1c75aec2016-02-02 17:47:28 -070031 * Author: Mark Lobodzinski <mark@LunarG.com>
Courtney Goeltzenleuchterb9ce3952015-10-30 11:14:30 -060032 *
Chia-I Wuc1e0f962014-08-04 08:03:57 +080033 */
34
35#ifndef LOADER_H
36#define LOADER_H
37
David Pinedoa5036622015-11-06 12:54:48 -070038#include <vulkan/vulkan.h>
Aaron Karp95c5f952016-03-13 16:41:59 -040039#include "vk_loader_platform.h"
Ian Elliottafaf1852015-11-17 17:29:40 -070040
David Pinedoa5036622015-11-06 12:54:48 -070041#include <vulkan/vk_layer.h>
42#include <vulkan/vk_icd.h>
Chia-I Wufe333ed2015-04-11 15:34:07 +080043#include <assert.h>
44
Chia-I Wuc1e0f962014-08-04 08:03:57 +080045#if defined(__GNUC__) && __GNUC__ >= 4
Jon Ashburn1c75aec2016-02-02 17:47:28 -070046#define LOADER_EXPORT __attribute__((visibility("default")))
Chia-I Wuc1e0f962014-08-04 08:03:57 +080047#elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)
Jon Ashburn1c75aec2016-02-02 17:47:28 -070048#define LOADER_EXPORT __attribute__((visibility("default")))
Chia-I Wuc1e0f962014-08-04 08:03:57 +080049#else
Jon Ashburn1c75aec2016-02-02 17:47:28 -070050#define LOADER_EXPORT
Chia-I Wuc1e0f962014-08-04 08:03:57 +080051#endif
52
Jon Ashburnb2379c52015-08-04 10:22:33 -060053#define MAX_STRING_SIZE 1024
Courtney Goeltzenleuchter44667cc2015-06-29 15:39:26 -060054#define VK_MAJOR(version) (version >> 22)
55#define VK_MINOR(version) ((version >> 12) & 0x3ff)
56#define VK_PATCH(version) (version & 0xfff)
Jon Ashburn13482452015-05-12 17:26:48 -060057
Jon Ashburn399c9162015-07-02 09:40:15 -060058enum layer_type {
Jon Ashburn9464e772015-07-02 16:10:32 -060059 VK_LAYER_TYPE_DEVICE_EXPLICIT = 0x1,
60 VK_LAYER_TYPE_INSTANCE_EXPLICIT = 0x2,
Jon Ashburnd1eb3322016-02-10 20:59:26 -070061 VK_LAYER_TYPE_GLOBAL_EXPLICIT = 0x3, // instance and device layer, bitwise
Jon Ashburn9464e772015-07-02 16:10:32 -060062 VK_LAYER_TYPE_DEVICE_IMPLICIT = 0x4,
63 VK_LAYER_TYPE_INSTANCE_IMPLICIT = 0x8,
Jon Ashburnd1eb3322016-02-10 20:59:26 -070064 VK_LAYER_TYPE_GLOBAL_IMPLICIT = 0xc, // instance and device layer, bitwise
65 VK_LAYER_TYPE_META_EXPLICT = 0x10,
Jon Ashburn399c9162015-07-02 09:40:15 -060066};
67
Mark Lobodzinski8d325802016-02-02 18:53:34 -070068typedef enum VkStringErrorFlagBits {
Jon Ashburnb1cdf2e2016-02-10 20:50:19 -070069 VK_STRING_ERROR_NONE = 0x00000000,
70 VK_STRING_ERROR_LENGTH = 0x00000001,
71 VK_STRING_ERROR_BAD_DATA = 0x00000002,
Mark Lobodzinski8d325802016-02-02 18:53:34 -070072} VkStringErrorFlagBits;
73typedef VkFlags VkStringErrorFlags;
74
Jon Ashburnb1cdf2e2016-02-10 20:50:19 -070075static const int MaxLoaderStringLength = 256;
76static const char UTF8_ONE_BYTE_CODE = 0xC0;
77static const char UTF8_ONE_BYTE_MASK = 0xE0;
78static const char UTF8_TWO_BYTE_CODE = 0xE0;
79static const char UTF8_TWO_BYTE_MASK = 0xF0;
80static const char UTF8_THREE_BYTE_CODE = 0xF0;
81static const char UTF8_THREE_BYTE_MASK = 0xF8;
82static const char UTF8_DATA_BYTE_CODE = 0x80;
83static const char UTF8_DATA_BYTE_MASK = 0xC0;
Mark Lobodzinski8d325802016-02-02 18:53:34 -070084
Mark Lobodzinskib0123ea2016-03-15 17:23:12 -060085static const char std_validation_names[8][VK_MAX_EXTENSION_NAME_SIZE] = {
Mark Lobodzinski842167e2016-03-17 15:08:18 -060086 "VK_LAYER_GOOGLE_threading", "VK_LAYER_LUNARG_parameter_validation",
Jon Ashburnd1eb3322016-02-10 20:59:26 -070087 "VK_LAYER_LUNARG_device_limits", "VK_LAYER_LUNARG_object_tracker",
Mark Lobodzinskib0123ea2016-03-15 17:23:12 -060088 "VK_LAYER_LUNARG_image", "VK_LAYER_LUNARG_core_validation",
89 "VK_LAYER_LUNARG_swapchain", "VK_LAYER_GOOGLE_unique_objects"};
Jon Ashburnd1eb3322016-02-10 20:59:26 -070090
Jon Ashburn6b00b472015-12-10 08:51:10 -070091// form of all dynamic lists/arrays
92// only the list element should be changed
93struct loader_generic_list {
94 size_t capacity;
95 uint32_t count;
96 void *list;
97};
98
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -060099struct loader_extension_list {
100 size_t capacity;
101 uint32_t count;
Jon Ashburnb7d327c2015-08-04 11:14:18 -0600102 VkExtensionProperties *list;
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600103};
104
Jon Ashburn92cdb012015-12-10 18:17:34 -0700105struct loader_dev_ext_props {
106 VkExtensionProperties props;
107 uint32_t entrypoint_count;
108 char **entrypoints;
109};
110
111struct loader_device_extension_list {
112 size_t capacity;
113 uint32_t count;
114 struct loader_dev_ext_props *list;
115};
116
Jon Ashburn399c9162015-07-02 09:40:15 -0600117struct loader_name_value {
Jon Ashburnb2379c52015-08-04 10:22:33 -0600118 char name[MAX_STRING_SIZE];
119 char value[MAX_STRING_SIZE];
Jon Ashburn399c9162015-07-02 09:40:15 -0600120};
121
122struct loader_lib_info {
Jon Ashburnb4c24232015-08-20 16:35:30 -0600123 char lib_name[MAX_STRING_SIZE];
Jon Ashburn399c9162015-07-02 09:40:15 -0600124 uint32_t ref_count;
125 loader_platform_dl_handle lib_handle;
126};
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600127
Jon Ashburn399c9162015-07-02 09:40:15 -0600128struct loader_layer_functions {
Jon Ashburnb2379c52015-08-04 10:22:33 -0600129 char str_gipa[MAX_STRING_SIZE];
130 char str_gdpa[MAX_STRING_SIZE];
Jon Ashburn399c9162015-07-02 09:40:15 -0600131 PFN_vkGetInstanceProcAddr get_instance_proc_addr;
132 PFN_vkGetDeviceProcAddr get_device_proc_addr;
133};
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600134
Jon Ashburn399c9162015-07-02 09:40:15 -0600135struct loader_layer_properties {
Courtney Goeltzenleuchter44667cc2015-06-29 15:39:26 -0600136 VkLayerProperties info;
Jon Ashburn399c9162015-07-02 09:40:15 -0600137 enum layer_type type;
Jon Ashburnb4c24232015-08-20 16:35:30 -0600138 char lib_name[MAX_STRING_SIZE];
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;
144};
145
146struct loader_layer_list {
147 size_t capacity;
148 uint32_t count;
149 struct loader_layer_properties *list;
Jon Ashburn13482452015-05-12 17:26:48 -0600150};
151
Courtney Goeltzenleuchter8aff3862015-07-05 12:53:31 -0600152struct loader_layer_library_list {
153 size_t capacity;
154 uint32_t count;
155 struct loader_lib_info *list;
156};
157
Jon Ashburn6cb69f42015-11-17 15:31:02 -0700158struct loader_dispatch_hash_list {
159 size_t capacity;
160 uint32_t count;
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700161 uint32_t *index; // index into the dev_ext dispatch table
Jon Ashburn6cb69f42015-11-17 15:31:02 -0700162};
163
164#define MAX_NUM_DEV_EXTS 250
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700165// loader_dispatch_hash_entry and loader_dev_ext_dispatch_table.DevExt have one
166// to one
Jon Ashburn6cb69f42015-11-17 15:31:02 -0700167// correspondence; one loader_dispatch_hash_entry for one DevExt dispatch entry.
168// Also have a one to one correspondence with functions in dev_ext_trampoline.c
169struct loader_dispatch_hash_entry {
170 char *func_name;
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700171 struct loader_dispatch_hash_list list; // to handle hashing collisions
Jon Ashburn6cb69f42015-11-17 15:31:02 -0700172};
173
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700174typedef void(VKAPI_PTR *PFN_vkDevExt)(VkDevice device);
Jon Ashburn6cb69f42015-11-17 15:31:02 -0700175struct loader_dev_ext_dispatch_table {
176 PFN_vkDevExt DevExt[MAX_NUM_DEV_EXTS];
177};
178
179struct loader_dev_dispatch_table {
180 VkLayerDispatchTable core_dispatch;
181 struct loader_dev_ext_dispatch_table ext_dispatch;
182};
183
Jon Ashburn10f4e822015-06-10 10:06:06 -0600184/* per CreateDevice structure */
185struct loader_device {
Jon Ashburn6cb69f42015-11-17 15:31:02 -0700186 struct loader_dev_dispatch_table loader_dispatch;
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700187 VkDevice device; // device object from the icd
Jon Ashburn10f4e822015-06-10 10:06:06 -0600188
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700189 uint32_t app_extension_count;
Jon Ashburn10f4e822015-06-10 10:06:06 -0600190 VkExtensionProperties *app_extension_props;
191
Courtney Goeltzenleuchter44667cc2015-06-29 15:39:26 -0600192 struct loader_layer_list activated_layer_list;
Jon Ashburn10f4e822015-06-10 10:06:06 -0600193
194 struct loader_device *next;
195};
196
Jon Ashburn392c5622015-06-10 16:11:42 -0600197/* per ICD structure */
Jon Ashburnebfa25e2015-05-15 15:09:35 -0600198struct loader_icd {
Jon Ashburnb4c24232015-08-20 16:35:30 -0600199 // pointers to find other structs
200 const struct loader_scanned_icds *this_icd_lib;
201 const struct loader_instance *this_instance;
Jon Ashburn10f4e822015-06-10 10:06:06 -0600202 struct loader_device *logical_device_list;
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700203 VkInstance instance; // instance object from the icd
Jon Ashburnc89dd4a2015-05-18 13:20:15 -0600204 PFN_vkGetDeviceProcAddr GetDeviceProcAddr;
Jon Ashburnebfa25e2015-05-15 15:09:35 -0600205 PFN_vkDestroyInstance DestroyInstance;
206 PFN_vkEnumeratePhysicalDevices EnumeratePhysicalDevices;
Chris Forbes1c946ec2015-06-21 22:55:02 +1200207 PFN_vkGetPhysicalDeviceFeatures GetPhysicalDeviceFeatures;
Courtney Goeltzenleuchter2b6559e2015-07-12 12:52:09 -0600208 PFN_vkGetPhysicalDeviceFormatProperties GetPhysicalDeviceFormatProperties;
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700209 PFN_vkGetPhysicalDeviceImageFormatProperties
210 GetPhysicalDeviceImageFormatProperties;
Jon Ashburnebfa25e2015-05-15 15:09:35 -0600211 PFN_vkCreateDevice CreateDevice;
Tony Barbour4e657ba2015-06-24 16:06:58 -0600212 PFN_vkGetPhysicalDeviceProperties GetPhysicalDeviceProperties;
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700213 PFN_vkGetPhysicalDeviceQueueFamilyProperties
214 GetPhysicalDeviceQueueFamilyProperties;
Tony Barbour4e657ba2015-06-24 16:06:58 -0600215 PFN_vkGetPhysicalDeviceMemoryProperties GetPhysicalDeviceMemoryProperties;
Courtney Goeltzenleuchtere25064c2015-09-14 17:22:16 -0600216 PFN_vkEnumerateDeviceExtensionProperties EnumerateDeviceExtensionProperties;
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700217 PFN_vkGetPhysicalDeviceSparseImageFormatProperties
218 GetPhysicalDeviceSparseImageFormatProperties;
Courtney Goeltzenleuchter725db942015-12-09 15:48:16 -0700219 PFN_vkCreateDebugReportCallbackEXT CreateDebugReportCallbackEXT;
220 PFN_vkDestroyDebugReportCallbackEXT DestroyDebugReportCallbackEXT;
221 PFN_vkDebugReportMessageEXT DebugReportMessageEXT;
Ian Elliottec736342015-08-21 15:09:33 -0600222 PFN_vkGetPhysicalDeviceSurfaceSupportKHR GetPhysicalDeviceSurfaceSupportKHR;
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700223 PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR
224 GetPhysicalDeviceSurfaceCapabilitiesKHR;
Ian Elliottea666b22015-11-19 16:05:09 -0700225 PFN_vkGetPhysicalDeviceSurfaceFormatsKHR GetPhysicalDeviceSurfaceFormatsKHR;
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700226 PFN_vkGetPhysicalDeviceSurfacePresentModesKHR
227 GetPhysicalDeviceSurfacePresentModesKHR;
Ian Elliotte851dd62015-11-24 15:39:10 -0700228#ifdef VK_USE_PLATFORM_WIN32_KHR
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700229 PFN_vkGetPhysicalDeviceWin32PresentationSupportKHR
230 GetPhysicalDeviceWin32PresentationSupportKHR;
Ian Elliotte851dd62015-11-24 15:39:10 -0700231#endif
232#ifdef VK_USE_PLATFORM_MIR_KHR
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700233 PFN_vkGetPhysicalDeviceMirPresentationSupportKHR
234 GetPhysicalDeviceMirPresentvationSupportKHR;
Ian Elliotte851dd62015-11-24 15:39:10 -0700235#endif
236#ifdef VK_USE_PLATFORM_WAYLAND_KHR
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700237 PFN_vkGetPhysicalDeviceWaylandPresentationSupportKHR
238 GetPhysicalDeviceWaylandPresentationSupportKHR;
Ian Elliotte851dd62015-11-24 15:39:10 -0700239#endif
240#ifdef VK_USE_PLATFORM_XCB_KHR
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700241 PFN_vkGetPhysicalDeviceXcbPresentationSupportKHR
242 GetPhysicalDeviceXcbPresentationSupportKHR;
Ian Elliotte851dd62015-11-24 15:39:10 -0700243#endif
244#ifdef VK_USE_PLATFORM_XLIB_KHR
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700245 PFN_vkGetPhysicalDeviceXlibPresentationSupportKHR
246 GetPhysicalDeviceXlibPresentationSupportKHR;
Ian Elliotte851dd62015-11-24 15:39:10 -0700247#endif
Jon Ashburncc370d02016-03-08 09:30:30 -0700248 PFN_vkGetPhysicalDeviceDisplayPropertiesKHR
249 GetPhysicalDeviceDisplayPropertiesKHR;
250 PFN_vkGetPhysicalDeviceDisplayPlanePropertiesKHR
251 GetPhysicalDeviceDisplayPlanePropertiesKHR;
252 PFN_vkGetDisplayPlaneSupportedDisplaysKHR
253 GetDisplayPlaneSupportedDisplaysKHR;
254 PFN_vkGetDisplayModePropertiesKHR
255 GetDisplayModePropertiesKHR;
256 PFN_vkCreateDisplayModeKHR
257 CreateDisplayModeKHR;
258 PFN_vkGetDisplayPlaneCapabilitiesKHR
259 GetDisplayPlaneCapabilitiesKHR;
260 PFN_vkCreateDisplayPlaneSurfaceKHR
261 CreateDisplayPlaneSurfaceKHR;
Jon Ashburn10f4e822015-06-10 10:06:06 -0600262 struct loader_icd *next;
Jon Ashburnebfa25e2015-05-15 15:09:35 -0600263};
264
Jon Ashburne0367472015-08-18 18:04:47 -0600265/* per ICD library structure */
266struct loader_icd_libs {
267 size_t capacity;
268 uint32_t count;
269 struct loader_scanned_icds *list;
270};
271
Jon Ashburn392c5622015-06-10 16:11:42 -0600272/* per instance structure */
Jon Ashburn13482452015-05-12 17:26:48 -0600273struct loader_instance {
Jon Ashburnebfa25e2015-05-15 15:09:35 -0600274 VkLayerInstanceDispatchTable *disp; // must be first entry in structure
275
Jon Ashburnfd02a0f2016-03-01 19:51:07 -0700276 uint32_t total_gpu_count; // count of the next two arrays
277 struct loader_physical_device *phys_devs_term;
Jon Ashburnc3519e42016-03-24 15:49:57 -0600278 struct loader_physical_device_tramp *phys_devs; // tramp wrapped physDev obj list
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600279 uint32_t total_icd_count;
Jon Ashburn13482452015-05-12 17:26:48 -0600280 struct loader_icd *icds;
281 struct loader_instance *next;
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700282 struct loader_extension_list ext_list; // icds and loaders extensions
Jon Ashburne0367472015-08-18 18:04:47 -0600283 struct loader_icd_libs icd_libs;
Jon Ashburnb4c24232015-08-20 16:35:30 -0600284 struct loader_layer_list instance_layer_list;
285 struct loader_layer_list device_layer_list;
Jon Ashburn6cb69f42015-11-17 15:31:02 -0700286 struct loader_dispatch_hash_entry disp_hash[MAX_NUM_DEV_EXTS];
Jon Ashburnb4c24232015-08-20 16:35:30 -0600287
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600288 struct loader_msg_callback_map_entry *icd_msg_callback_map;
289
Courtney Goeltzenleuchter44667cc2015-06-29 15:39:26 -0600290 struct loader_layer_list activated_layer_list;
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600291
Jon Ashburnedbe39d2016-03-08 15:21:30 -0700292 VkInstance instance; // layers/ICD instance returned to trampoline
Courtney Goeltzenleuchter0bd705c2016-01-08 12:18:43 -0700293
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600294 bool debug_report_enabled;
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600295 VkLayerDbgFunctionNode *DbgFunctionHead;
Ian Elliottf8bd0e72016-03-25 09:54:04 -0600296 VkDebugReportCallbackCreateInfoEXT debugReportCreateInfo;
Courtney Goeltzenleuchter71b454b2015-07-05 11:28:29 -0600297
Chia-I Wu227c8b32015-10-27 18:04:07 +0800298 VkAllocationCallbacks alloc_callbacks;
Ian Elliotted33eb72015-07-06 14:36:13 -0600299
Ian Elliott54cea232015-10-30 15:28:23 -0600300 bool wsi_surface_enabled;
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -0700301#ifdef VK_USE_PLATFORM_WIN32_KHR
Ian Elliott54cea232015-10-30 15:28:23 -0600302 bool wsi_win32_surface_enabled;
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -0700303#endif
304#ifdef VK_USE_PLATFORM_MIR_KHR
Ian Elliott54cea232015-10-30 15:28:23 -0600305 bool wsi_mir_surface_enabled;
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -0700306#endif
307#ifdef VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott54cea232015-10-30 15:28:23 -0600308 bool wsi_wayland_surface_enabled;
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -0700309#endif
310#ifdef VK_USE_PLATFORM_XCB_KHR
Ian Elliott54cea232015-10-30 15:28:23 -0600311 bool wsi_xcb_surface_enabled;
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -0700312#endif
313#ifdef VK_USE_PLATFORM_XLIB_KHR
Ian Elliott54cea232015-10-30 15:28:23 -0600314 bool wsi_xlib_surface_enabled;
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -0700315#endif
316#ifdef VK_USE_PLATFORM_ANDROID_KHR
317 bool wsi_android_surface_enabled;
318#endif
Jon Ashburncc370d02016-03-08 09:30:30 -0700319 bool wsi_display_enabled;
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600320};
321
Jon Ashburnfd02a0f2016-03-01 19:51:07 -0700322/* VkPhysicalDevice requires special treatment by loader. Firstly, terminator
323 * code must be able to get the struct loader_icd to call into the proper
324 * driver (multiple ICD/gpu case). This can be accomplished by wrapping the
325 * created VkPhysicalDevice in loader terminate_EnumeratePhysicalDevices().
326 * Secondly, loader must be able to find the instance and icd in trampoline
327 * code.
328 * Thirdly, the loader must be able to handle wrapped by layer VkPhysicalDevice
329 * in trampoline code. This implies, that the loader trampoline code must also
330 * wrap the VkPhysicalDevice object in trampoline code. Thus, loader has to
331 * wrap the VkPhysicalDevice created object twice. In trampoline code it can't
332 * rely on the terminator object wrapping since a layer may also wrap. Since
333 * trampoline code wraps the VkPhysicalDevice this means all loader trampoline
334 * code that passes a VkPhysicalDevice should unwrap it. */
335
336/* per enumerated PhysicalDevice structure, used to wrap in trampoline code and
337 also same structure used to wrap in terminator code */
Jon Ashburnc3519e42016-03-24 15:49:57 -0600338struct loader_physical_device_tramp {
339 VkLayerInstanceDispatchTable *disp; // must be first entry in structure
340 struct loader_icd *this_icd;
341 VkPhysicalDevice phys_dev; // object from layers/loader terminator
342 VkPhysicalDevice icd_phys_dev; // object from icd
343};
344
345/* per enumerated PhysicalDevice structure, used to wrap in terminator code */
Jon Ashburn969caa42015-11-01 14:04:06 -0700346struct loader_physical_device {
347 VkLayerInstanceDispatchTable *disp; // must be first entry in structure
Jon Ashburn969caa42015-11-01 14:04:06 -0700348 struct loader_icd *this_icd;
Jon Ashburnc3519e42016-03-24 15:49:57 -0600349 VkPhysicalDevice phys_dev; // object from ICD
Jon Ashburn969caa42015-11-01 14:04:06 -0700350};
351
Jon Ashburn13482452015-05-12 17:26:48 -0600352struct loader_struct {
353 struct loader_instance *instances;
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600354
355 unsigned int loaded_layer_lib_count;
Courtney Goeltzenleuchter452303a2015-10-07 09:00:34 -0600356 size_t loaded_layer_lib_capacity;
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600357 struct loader_lib_info *loaded_layer_lib_list;
Jon Ashburne0367472015-08-18 18:04:47 -0600358 // TODO add ref counting of ICD libraries
Jon Ashburn269b5922015-07-06 15:40:35 -0600359 // TODO use this struct loader_layer_library_list scanned_layer_libraries;
Jon Ashburne0367472015-08-18 18:04:47 -0600360 // TODO add list of icd libraries for ref counting them for closure
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600361};
362
363struct loader_scanned_icds {
364 char *lib_name;
365 loader_platform_dl_handle handle;
Jon Ashburn27109e82015-11-17 17:35:40 -0700366 uint32_t api_version;
Jon Ashburnc7ca48d2015-07-16 10:17:29 -0600367 PFN_vkGetInstanceProcAddr GetInstanceProcAddr;
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600368 PFN_vkCreateInstance CreateInstance;
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700369 PFN_vkEnumerateInstanceExtensionProperties
370 EnumerateInstanceExtensionProperties;
Jon Ashburn13482452015-05-12 17:26:48 -0600371};
372
Jon Ashburn399c9162015-07-02 09:40:15 -0600373static inline struct loader_instance *loader_instance(VkInstance instance) {
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700374 return (struct loader_instance *)instance;
Jon Ashburn399c9162015-07-02 09:40:15 -0600375}
376
Jon Ashburnfd02a0f2016-03-01 19:51:07 -0700377static inline VkPhysicalDevice
378loader_unwrap_physical_device(VkPhysicalDevice physicalDevice) {
379 struct loader_physical_device *phys_dev =
380 (struct loader_physical_device *)physicalDevice;
381 return phys_dev->phys_dev;
382}
383
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700384static inline void loader_set_dispatch(void *obj, const void *data) {
385 *((const void **)obj) = data;
Chia-I Wufe333ed2015-04-11 15:34:07 +0800386}
387
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700388static inline VkLayerDispatchTable *loader_get_dispatch(const void *obj) {
389 return *((VkLayerDispatchTable **)obj);
Chia-I Wufe333ed2015-04-11 15:34:07 +0800390}
391
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700392static inline struct loader_dev_dispatch_table *
393loader_get_dev_dispatch(const void *obj) {
394 return *((struct loader_dev_dispatch_table **)obj);
Jon Ashburn6cb69f42015-11-17 15:31:02 -0700395}
396
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700397static inline VkLayerInstanceDispatchTable *
398loader_get_instance_dispatch(const void *obj) {
399 return *((VkLayerInstanceDispatchTable **)obj);
Jon Ashburn13482452015-05-12 17:26:48 -0600400}
401
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700402static inline void loader_init_dispatch(void *obj, const void *data) {
Jon Ashburn167b2b12015-04-15 13:34:33 -0600403#ifdef DEBUG
Chia-I Wufe333ed2015-04-11 15:34:07 +0800404 assert(valid_loader_magic_value(obj) &&
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700405 "Incompatible ICD, first dword must be initialized to "
406 "ICD_LOADER_MAGIC. See loader/README.md for details.");
Jon Ashburn167b2b12015-04-15 13:34:33 -0600407#endif
Chia-I Wufe333ed2015-04-11 15:34:07 +0800408
Jon Ashburn62a54d12015-05-01 18:00:33 -0600409 loader_set_dispatch(obj, data);
Chia-I Wufe333ed2015-04-11 15:34:07 +0800410}
411
Jon Ashburn13482452015-05-12 17:26:48 -0600412/* global variables used across files */
413extern struct loader_struct loader;
Jon Ashburnb4dee9c2015-08-28 15:19:27 -0600414extern THREAD_LOCAL_DECL struct loader_instance *tls_instance;
Jon Ashburne0367472015-08-18 18:04:47 -0600415extern LOADER_PLATFORM_THREAD_ONCE_DEFINITION(once_init);
Jon Ashburn7e8d8b42015-05-29 13:15:39 -0600416extern loader_platform_thread_mutex loader_lock;
Jon Ashburn7d4d51c2015-09-22 13:11:00 -0600417extern loader_platform_thread_mutex loader_json_lock;
Jon Ashburn7e8d8b42015-05-29 13:15:39 -0600418extern const VkLayerInstanceDispatchTable instance_disp;
Jon Ashburnd1eb3322016-02-10 20:59:26 -0700419extern const char *std_validation_str;
Jon Ashburn37e7f972015-04-06 10:58:22 -0600420
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600421struct loader_msg_callback_map_entry {
Courtney Goeltzenleuchter725db942015-12-09 15:48:16 -0700422 VkDebugReportCallbackEXT icd_obj;
423 VkDebugReportCallbackEXT loader_obj;
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600424};
425
Jon Ashburnc4e9ae62016-02-26 13:14:27 -0700426/* helper function definitions */
427void *loader_heap_alloc(const struct loader_instance *instance, size_t size,
428 VkSystemAllocationScope allocationScope);
429
430void loader_heap_free(const struct loader_instance *instance, void *pMemory);
431
432void *loader_tls_heap_alloc(size_t size);
433
434void loader_tls_heap_free(void *pMemory);
435
Jon Ashburn663f8312016-02-12 08:20:06 -0700436void loader_log(const struct loader_instance *inst, VkFlags msg_type,
Jon Ashburnc4e9ae62016-02-26 13:14:27 -0700437 int32_t msg_code, const char *format, ...);
Jon Ashburn663f8312016-02-12 08:20:06 -0700438
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700439bool compare_vk_extension_properties(const VkExtensionProperties *op1,
440 const VkExtensionProperties *op2);
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600441
Mark Lobodzinski8d325802016-02-02 18:53:34 -0700442VkResult loader_validate_layers(const struct loader_instance *inst,
443 const uint32_t layer_count,
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700444 const char *const *ppEnabledLayerNames,
445 const struct loader_layer_list *list);
Courtney Goeltzenleuchter76ece702015-07-06 17:45:08 -0600446
447VkResult loader_validate_instance_extensions(
Mark Lobodzinski8d325802016-02-02 18:53:34 -0700448 const struct loader_instance *inst,
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700449 const struct loader_extension_list *icd_exts,
450 const struct loader_layer_list *instance_layer,
451 const VkInstanceCreateInfo *pCreateInfo);
Courtney Goeltzenleuchter76ece702015-07-06 17:45:08 -0600452
Jon Ashburne0367472015-08-18 18:04:47 -0600453void loader_initialize(void);
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700454bool has_vk_extension_property_array(const VkExtensionProperties *vk_ext_prop,
455 const uint32_t count,
456 const VkExtensionProperties *ext_array);
457bool has_vk_extension_property(const VkExtensionProperties *vk_ext_prop,
458 const struct loader_extension_list *ext_list);
Jon Ashburn13482452015-05-12 17:26:48 -0600459
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700460VkResult loader_add_to_ext_list(const struct loader_instance *inst,
461 struct loader_extension_list *ext_list,
462 uint32_t prop_list_count,
463 const VkExtensionProperties *props);
Jon Ashburnc4e9ae62016-02-26 13:14:27 -0700464VkResult loader_add_device_extensions(const struct loader_instance *inst,
465 struct loader_icd *icd,
466 VkPhysicalDevice physical_device,
467 const char *lib_name,
468 struct loader_extension_list *ext_list);
469bool loader_init_generic_list(const struct loader_instance *inst,
470 struct loader_generic_list *list_info,
471 size_t element_size);
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700472void loader_destroy_generic_list(const struct loader_instance *inst,
473 struct loader_generic_list *list);
Jon Ashburnc4e9ae62016-02-26 13:14:27 -0700474void loader_destroy_layer_list(const struct loader_instance *inst,
475 struct loader_layer_list *layer_list);
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700476void loader_delete_layer_properties(const struct loader_instance *inst,
477 struct loader_layer_list *layer_list);
Jon Ashburnd1eb3322016-02-10 20:59:26 -0700478void loader_expand_layer_names(
479 const struct loader_instance *inst, const char *key_name,
480 uint32_t expand_count,
481 const char expand_names[][VK_MAX_EXTENSION_NAME_SIZE],
482 uint32_t *layer_count, char ***ppp_layer_names);
Jon Ashburn31efe262016-02-11 18:59:43 -0700483void loader_unexpand_dev_layer_names(const struct loader_instance *inst,
484 uint32_t layer_count, char **layer_names,
485 char **layer_ptr,
Jon Ashburnd1eb3322016-02-10 20:59:26 -0700486 const VkDeviceCreateInfo *pCreateInfo);
Jon Ashburn31efe262016-02-11 18:59:43 -0700487void loader_unexpand_inst_layer_names(const struct loader_instance *inst,
488 uint32_t layer_count, char **layer_names,
489 char **layer_ptr,
Jon Ashburnd1eb3322016-02-10 20:59:26 -0700490 const VkInstanceCreateInfo *pCreateInfo);
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700491void loader_add_to_layer_list(const struct loader_instance *inst,
492 struct loader_layer_list *list,
493 uint32_t prop_list_count,
494 const struct loader_layer_properties *props);
495void loader_scanned_icd_clear(const struct loader_instance *inst,
496 struct loader_icd_libs *icd_libs);
497void loader_icd_scan(const struct loader_instance *inst,
498 struct loader_icd_libs *icds);
499void loader_layer_scan(const struct loader_instance *inst,
500 struct loader_layer_list *instance_layers,
501 struct loader_layer_list *device_layers);
Jon Ashburne0367472015-08-18 18:04:47 -0600502void loader_get_icd_loader_instance_extensions(
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700503 const struct loader_instance *inst, struct loader_icd_libs *icd_libs,
504 struct loader_extension_list *inst_exts);
505struct loader_icd *loader_get_icd_and_device(const VkDevice device,
506 struct loader_device **found_dev);
Jon Ashburnc4e9ae62016-02-26 13:14:27 -0700507void loader_init_dispatch_dev_ext(struct loader_instance *inst,
508 struct loader_device *dev);
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700509void *loader_dev_ext_gpa(struct loader_instance *inst, const char *funcName);
510void *loader_get_dev_ext_trampoline(uint32_t index);
511struct loader_instance *loader_get_instance(const VkInstance instance);
Jon Ashburnc4e9ae62016-02-26 13:14:27 -0700512struct loader_device *
513loader_add_logical_device(const struct loader_instance *inst,
514 struct loader_device **device_list);
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700515void loader_remove_logical_device(const struct loader_instance *inst,
516 struct loader_icd *icd,
517 struct loader_device *found_dev);
518VkResult
519loader_enable_instance_layers(struct loader_instance *inst,
520 const VkInstanceCreateInfo *pCreateInfo,
521 const struct loader_layer_list *instance_layers);
Jon Ashburn10f4e822015-06-10 10:06:06 -0600522void loader_deactivate_instance_layers(struct loader_instance *instance);
Courtney Goeltzenleuchter0bd705c2016-01-08 12:18:43 -0700523
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700524VkResult loader_create_instance_chain(const VkInstanceCreateInfo *pCreateInfo,
525 const VkAllocationCallbacks *pAllocator,
526 struct loader_instance *inst,
Jon Ashburnd1205a92016-02-03 12:37:30 -0700527 VkInstance *created_instance);
Courtney Goeltzenleuchter0bd705c2016-01-08 12:18:43 -0700528
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700529void loader_activate_instance_layer_extensions(struct loader_instance *inst,
530 VkInstance created_inst);
Jon Ashburnc4e9ae62016-02-26 13:14:27 -0700531VkResult
532loader_enable_device_layers(const struct loader_instance *inst,
533 struct loader_icd *icd,
534 struct loader_layer_list *activated_layer_list,
535 const VkDeviceCreateInfo *pCreateInfo,
536 const struct loader_layer_list *device_layers);
Courtney Goeltzenleuchter71b454b2015-07-05 11:28:29 -0600537
Jon Ashburnc3519e42016-03-24 15:49:57 -0600538VkResult loader_create_device_chain(const struct loader_physical_device_tramp *pd,
Jon Ashburnc4e9ae62016-02-26 13:14:27 -0700539 const VkDeviceCreateInfo *pCreateInfo,
540 const VkAllocationCallbacks *pAllocator,
Jon Ashburnfd02a0f2016-03-01 19:51:07 -0700541 const struct loader_instance *inst,
Jon Ashburnc4e9ae62016-02-26 13:14:27 -0700542 struct loader_icd *icd,
543 struct loader_device *dev);
544VkResult loader_validate_device_extensions(
Jon Ashburnc3519e42016-03-24 15:49:57 -0600545 struct loader_physical_device_tramp *phys_dev,
Jon Ashburnc4e9ae62016-02-26 13:14:27 -0700546 const struct loader_layer_list *activated_device_layers,
Jon Ashburnfd02a0f2016-03-01 19:51:07 -0700547 const struct loader_extension_list *icd_exts,
Jon Ashburnc4e9ae62016-02-26 13:14:27 -0700548 const VkDeviceCreateInfo *pCreateInfo);
Courtney Goeltzenleuchter71b454b2015-07-05 11:28:29 -0600549
Jon Ashburnc4e9ae62016-02-26 13:14:27 -0700550/* instance layer chain termination entrypoint definitions */
551VKAPI_ATTR VkResult VKAPI_CALL
552terminator_CreateInstance(const VkInstanceCreateInfo *pCreateInfo,
553 const VkAllocationCallbacks *pAllocator,
554 VkInstance *pInstance);
Jon Ashburnb4dee9c2015-08-28 15:19:27 -0600555
Jon Ashburnc4e9ae62016-02-26 13:14:27 -0700556VKAPI_ATTR void VKAPI_CALL
557terminator_DestroyInstance(VkInstance instance,
558 const VkAllocationCallbacks *pAllocator);
Jon Ashburnb4dee9c2015-08-28 15:19:27 -0600559
Jon Ashburnc4e9ae62016-02-26 13:14:27 -0700560VKAPI_ATTR VkResult VKAPI_CALL
561terminator_EnumeratePhysicalDevices(VkInstance instance,
562 uint32_t *pPhysicalDeviceCount,
563 VkPhysicalDevice *pPhysicalDevices);
564
565VKAPI_ATTR void VKAPI_CALL
566terminator_GetPhysicalDeviceFeatures(VkPhysicalDevice physicalDevice,
567 VkPhysicalDeviceFeatures *pFeatures);
568
569VKAPI_ATTR void VKAPI_CALL
570terminator_GetPhysicalDeviceFormatProperties(VkPhysicalDevice physicalDevice,
571 VkFormat format,
572 VkFormatProperties *pFormatInfo);
573
574VKAPI_ATTR VkResult VKAPI_CALL
575terminator_GetPhysicalDeviceImageFormatProperties(
576 VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type,
577 VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags,
578 VkImageFormatProperties *pImageFormatProperties);
579
580VKAPI_ATTR void VKAPI_CALL
581terminator_GetPhysicalDeviceSparseImageFormatProperties(
582 VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type,
583 VkSampleCountFlagBits samples, VkImageUsageFlags usage,
584 VkImageTiling tiling, uint32_t *pNumProperties,
585 VkSparseImageFormatProperties *pProperties);
586
587VKAPI_ATTR void VKAPI_CALL
588terminator_GetPhysicalDeviceProperties(VkPhysicalDevice physicalDevice,
589 VkPhysicalDeviceProperties *pProperties);
590
591VKAPI_ATTR VkResult VKAPI_CALL terminator_EnumerateDeviceExtensionProperties(
592 VkPhysicalDevice physicalDevice, const char *pLayerName, uint32_t *pCount,
593 VkExtensionProperties *pProperties);
594
595VKAPI_ATTR VkResult VKAPI_CALL
596terminator_EnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice,
597 uint32_t *pCount,
598 VkLayerProperties *pProperties);
599
600VKAPI_ATTR void VKAPI_CALL terminator_GetPhysicalDeviceQueueFamilyProperties(
601 VkPhysicalDevice physicalDevice, uint32_t *pCount,
602 VkQueueFamilyProperties *pProperties);
603
604VKAPI_ATTR void VKAPI_CALL terminator_GetPhysicalDeviceMemoryProperties(
605 VkPhysicalDevice physicalDevice,
606 VkPhysicalDeviceMemoryProperties *pProperties);
607
608VKAPI_ATTR VkResult VKAPI_CALL
609terminator_CreateDevice(VkPhysicalDevice gpu,
610 const VkDeviceCreateInfo *pCreateInfo,
611 const VkAllocationCallbacks *pAllocator,
612 VkDevice *pDevice);
Mark Lobodzinski8d325802016-02-02 18:53:34 -0700613
Jon Ashburnb1cdf2e2016-02-10 20:50:19 -0700614VkStringErrorFlags vk_string_validate(const int max_length,
615 const char *char_array);
Mark Lobodzinski8d325802016-02-02 18:53:34 -0700616
Chia-I Wuc1e0f962014-08-04 08:03:57 +0800617#endif /* LOADER_H */