blob: 84659bbaa5b5e66133832c5baf17628c2e9143a6 [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 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>
Courtney Goeltzenleuchterb9ce3952015-10-30 11:14:30 -060025 *
Chia-I Wuc1e0f962014-08-04 08:03:57 +080026 */
27
28#ifndef LOADER_H
29#define LOADER_H
30
David Pinedoa5036622015-11-06 12:54:48 -070031#include <vulkan/vulkan.h>
Aaron Karp95c5f952016-03-13 16:41:59 -040032#include "vk_loader_platform.h"
Ian Elliottafaf1852015-11-17 17:29:40 -070033
David Pinedoa5036622015-11-06 12:54:48 -070034#include <vulkan/vk_layer.h>
35#include <vulkan/vk_icd.h>
Chia-I Wufe333ed2015-04-11 15:34:07 +080036#include <assert.h>
37
Chia-I Wuc1e0f962014-08-04 08:03:57 +080038#if defined(__GNUC__) && __GNUC__ >= 4
Jon Ashburn1c75aec2016-02-02 17:47:28 -070039#define LOADER_EXPORT __attribute__((visibility("default")))
Chia-I Wuc1e0f962014-08-04 08:03:57 +080040#elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)
Jon Ashburn1c75aec2016-02-02 17:47:28 -070041#define LOADER_EXPORT __attribute__((visibility("default")))
Chia-I Wuc1e0f962014-08-04 08:03:57 +080042#else
Jon Ashburn1c75aec2016-02-02 17:47:28 -070043#define LOADER_EXPORT
Chia-I Wuc1e0f962014-08-04 08:03:57 +080044#endif
45
Jon Ashburnb2379c52015-08-04 10:22:33 -060046#define MAX_STRING_SIZE 1024
Courtney Goeltzenleuchter44667cc2015-06-29 15:39:26 -060047#define VK_MAJOR(version) (version >> 22)
48#define VK_MINOR(version) ((version >> 12) & 0x3ff)
49#define VK_PATCH(version) (version & 0xfff)
Jon Ashburn13482452015-05-12 17:26:48 -060050
Jon Ashburn399c9162015-07-02 09:40:15 -060051enum layer_type {
Jon Ashburn9464e772015-07-02 16:10:32 -060052 VK_LAYER_TYPE_DEVICE_EXPLICIT = 0x1,
53 VK_LAYER_TYPE_INSTANCE_EXPLICIT = 0x2,
Jon Ashburnd1eb3322016-02-10 20:59:26 -070054 VK_LAYER_TYPE_GLOBAL_EXPLICIT = 0x3, // instance and device layer, bitwise
Jon Ashburn9464e772015-07-02 16:10:32 -060055 VK_LAYER_TYPE_DEVICE_IMPLICIT = 0x4,
56 VK_LAYER_TYPE_INSTANCE_IMPLICIT = 0x8,
Jon Ashburnd1eb3322016-02-10 20:59:26 -070057 VK_LAYER_TYPE_GLOBAL_IMPLICIT = 0xc, // instance and device layer, bitwise
58 VK_LAYER_TYPE_META_EXPLICT = 0x10,
Jon Ashburn399c9162015-07-02 09:40:15 -060059};
60
Mark Lobodzinski8d325802016-02-02 18:53:34 -070061typedef enum VkStringErrorFlagBits {
Jon Ashburnb1cdf2e2016-02-10 20:50:19 -070062 VK_STRING_ERROR_NONE = 0x00000000,
63 VK_STRING_ERROR_LENGTH = 0x00000001,
64 VK_STRING_ERROR_BAD_DATA = 0x00000002,
Mark Lobodzinski8d325802016-02-02 18:53:34 -070065} VkStringErrorFlagBits;
66typedef VkFlags VkStringErrorFlags;
67
Jon Ashburnb1cdf2e2016-02-10 20:50:19 -070068static const int MaxLoaderStringLength = 256;
69static const char UTF8_ONE_BYTE_CODE = 0xC0;
70static const char UTF8_ONE_BYTE_MASK = 0xE0;
71static const char UTF8_TWO_BYTE_CODE = 0xE0;
72static const char UTF8_TWO_BYTE_MASK = 0xF0;
73static const char UTF8_THREE_BYTE_CODE = 0xF0;
74static const char UTF8_THREE_BYTE_MASK = 0xF8;
75static const char UTF8_DATA_BYTE_CODE = 0x80;
76static const char UTF8_DATA_BYTE_MASK = 0xC0;
Mark Lobodzinski8d325802016-02-02 18:53:34 -070077
Mark Lobodzinskib0123ea2016-03-15 17:23:12 -060078static const char std_validation_names[8][VK_MAX_EXTENSION_NAME_SIZE] = {
Jon Ashburnc466da52016-04-15 09:25:03 -060079 "VK_LAYER_GOOGLE_threading", "VK_LAYER_LUNARG_parameter_validation",
Jon Ashburnd1eb3322016-02-10 20:59:26 -070080 "VK_LAYER_LUNARG_device_limits", "VK_LAYER_LUNARG_object_tracker",
Jon Ashburnc466da52016-04-15 09:25:03 -060081 "VK_LAYER_LUNARG_image", "VK_LAYER_LUNARG_core_validation",
82 "VK_LAYER_LUNARG_swapchain", "VK_LAYER_GOOGLE_unique_objects"};
Jon Ashburnd1eb3322016-02-10 20:59:26 -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
115struct loader_lib_info {
Jon Ashburnb4c24232015-08-20 16:35:30 -0600116 char lib_name[MAX_STRING_SIZE];
Jon Ashburn399c9162015-07-02 09:40:15 -0600117 uint32_t ref_count;
118 loader_platform_dl_handle lib_handle;
119};
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600120
Jon Ashburn399c9162015-07-02 09:40:15 -0600121struct loader_layer_functions {
Jon Ashburnb2379c52015-08-04 10:22:33 -0600122 char str_gipa[MAX_STRING_SIZE];
123 char str_gdpa[MAX_STRING_SIZE];
Jon Ashburn399c9162015-07-02 09:40:15 -0600124 PFN_vkGetInstanceProcAddr get_instance_proc_addr;
125 PFN_vkGetDeviceProcAddr get_device_proc_addr;
126};
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600127
Jon Ashburn399c9162015-07-02 09:40:15 -0600128struct loader_layer_properties {
Courtney Goeltzenleuchter44667cc2015-06-29 15:39:26 -0600129 VkLayerProperties info;
Jon Ashburn399c9162015-07-02 09:40:15 -0600130 enum layer_type type;
Jon Ashburnb4c24232015-08-20 16:35:30 -0600131 char lib_name[MAX_STRING_SIZE];
Jon Ashburn399c9162015-07-02 09:40:15 -0600132 struct loader_layer_functions functions;
133 struct loader_extension_list instance_extension_list;
Jon Ashburn92cdb012015-12-10 18:17:34 -0700134 struct loader_device_extension_list device_extension_list;
Jon Ashburn399c9162015-07-02 09:40:15 -0600135 struct loader_name_value disable_env_var;
136 struct loader_name_value enable_env_var;
137};
138
139struct loader_layer_list {
140 size_t capacity;
141 uint32_t count;
142 struct loader_layer_properties *list;
Jon Ashburn13482452015-05-12 17:26:48 -0600143};
144
Courtney Goeltzenleuchter8aff3862015-07-05 12:53:31 -0600145struct loader_layer_library_list {
146 size_t capacity;
147 uint32_t count;
148 struct loader_lib_info *list;
149};
150
Jon Ashburn6cb69f42015-11-17 15:31:02 -0700151struct loader_dispatch_hash_list {
152 size_t capacity;
153 uint32_t count;
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700154 uint32_t *index; // index into the dev_ext dispatch table
Jon Ashburn6cb69f42015-11-17 15:31:02 -0700155};
156
157#define MAX_NUM_DEV_EXTS 250
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700158// loader_dispatch_hash_entry and loader_dev_ext_dispatch_table.DevExt have one
159// to one
Jon Ashburn6cb69f42015-11-17 15:31:02 -0700160// correspondence; one loader_dispatch_hash_entry for one DevExt dispatch entry.
161// Also have a one to one correspondence with functions in dev_ext_trampoline.c
162struct loader_dispatch_hash_entry {
163 char *func_name;
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700164 struct loader_dispatch_hash_list list; // to handle hashing collisions
Jon Ashburn6cb69f42015-11-17 15:31:02 -0700165};
166
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700167typedef void(VKAPI_PTR *PFN_vkDevExt)(VkDevice device);
Jon Ashburn6cb69f42015-11-17 15:31:02 -0700168struct loader_dev_ext_dispatch_table {
169 PFN_vkDevExt DevExt[MAX_NUM_DEV_EXTS];
170};
171
172struct loader_dev_dispatch_table {
173 VkLayerDispatchTable core_dispatch;
174 struct loader_dev_ext_dispatch_table ext_dispatch;
175};
176
Jon Ashburn10f4e822015-06-10 10:06:06 -0600177/* per CreateDevice structure */
178struct loader_device {
Jon Ashburn6cb69f42015-11-17 15:31:02 -0700179 struct loader_dev_dispatch_table loader_dispatch;
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700180 VkDevice device; // device object from the icd
Jon Ashburn10f4e822015-06-10 10:06:06 -0600181
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700182 uint32_t app_extension_count;
Jon Ashburn10f4e822015-06-10 10:06:06 -0600183 VkExtensionProperties *app_extension_props;
184
Courtney Goeltzenleuchter44667cc2015-06-29 15:39:26 -0600185 struct loader_layer_list activated_layer_list;
Jon Ashburn10f4e822015-06-10 10:06:06 -0600186
187 struct loader_device *next;
188};
189
Jon Ashburn392c5622015-06-10 16:11:42 -0600190/* per ICD structure */
Jon Ashburnebfa25e2015-05-15 15:09:35 -0600191struct loader_icd {
Jon Ashburnb4c24232015-08-20 16:35:30 -0600192 // pointers to find other structs
193 const struct loader_scanned_icds *this_icd_lib;
194 const struct loader_instance *this_instance;
Jon Ashburn10f4e822015-06-10 10:06:06 -0600195 struct loader_device *logical_device_list;
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700196 VkInstance instance; // instance object from the icd
Jon Ashburnc89dd4a2015-05-18 13:20:15 -0600197 PFN_vkGetDeviceProcAddr GetDeviceProcAddr;
Jon Ashburnebfa25e2015-05-15 15:09:35 -0600198 PFN_vkDestroyInstance DestroyInstance;
199 PFN_vkEnumeratePhysicalDevices EnumeratePhysicalDevices;
Chris Forbes1c946ec2015-06-21 22:55:02 +1200200 PFN_vkGetPhysicalDeviceFeatures GetPhysicalDeviceFeatures;
Courtney Goeltzenleuchter2b6559e2015-07-12 12:52:09 -0600201 PFN_vkGetPhysicalDeviceFormatProperties GetPhysicalDeviceFormatProperties;
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700202 PFN_vkGetPhysicalDeviceImageFormatProperties
203 GetPhysicalDeviceImageFormatProperties;
Jon Ashburnebfa25e2015-05-15 15:09:35 -0600204 PFN_vkCreateDevice CreateDevice;
Tony Barbour4e657ba2015-06-24 16:06:58 -0600205 PFN_vkGetPhysicalDeviceProperties GetPhysicalDeviceProperties;
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700206 PFN_vkGetPhysicalDeviceQueueFamilyProperties
207 GetPhysicalDeviceQueueFamilyProperties;
Tony Barbour4e657ba2015-06-24 16:06:58 -0600208 PFN_vkGetPhysicalDeviceMemoryProperties GetPhysicalDeviceMemoryProperties;
Courtney Goeltzenleuchtere25064c2015-09-14 17:22:16 -0600209 PFN_vkEnumerateDeviceExtensionProperties EnumerateDeviceExtensionProperties;
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700210 PFN_vkGetPhysicalDeviceSparseImageFormatProperties
211 GetPhysicalDeviceSparseImageFormatProperties;
Courtney Goeltzenleuchter725db942015-12-09 15:48:16 -0700212 PFN_vkCreateDebugReportCallbackEXT CreateDebugReportCallbackEXT;
213 PFN_vkDestroyDebugReportCallbackEXT DestroyDebugReportCallbackEXT;
214 PFN_vkDebugReportMessageEXT DebugReportMessageEXT;
Ian Elliottec736342015-08-21 15:09:33 -0600215 PFN_vkGetPhysicalDeviceSurfaceSupportKHR GetPhysicalDeviceSurfaceSupportKHR;
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700216 PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR
217 GetPhysicalDeviceSurfaceCapabilitiesKHR;
Ian Elliottea666b22015-11-19 16:05:09 -0700218 PFN_vkGetPhysicalDeviceSurfaceFormatsKHR GetPhysicalDeviceSurfaceFormatsKHR;
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700219 PFN_vkGetPhysicalDeviceSurfacePresentModesKHR
220 GetPhysicalDeviceSurfacePresentModesKHR;
Ian Elliotte851dd62015-11-24 15:39:10 -0700221#ifdef VK_USE_PLATFORM_WIN32_KHR
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700222 PFN_vkGetPhysicalDeviceWin32PresentationSupportKHR
223 GetPhysicalDeviceWin32PresentationSupportKHR;
Ian Elliotte851dd62015-11-24 15:39:10 -0700224#endif
225#ifdef VK_USE_PLATFORM_MIR_KHR
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700226 PFN_vkGetPhysicalDeviceMirPresentationSupportKHR
227 GetPhysicalDeviceMirPresentvationSupportKHR;
Ian Elliotte851dd62015-11-24 15:39:10 -0700228#endif
229#ifdef VK_USE_PLATFORM_WAYLAND_KHR
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700230 PFN_vkGetPhysicalDeviceWaylandPresentationSupportKHR
231 GetPhysicalDeviceWaylandPresentationSupportKHR;
Ian Elliotte851dd62015-11-24 15:39:10 -0700232#endif
233#ifdef VK_USE_PLATFORM_XCB_KHR
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700234 PFN_vkGetPhysicalDeviceXcbPresentationSupportKHR
235 GetPhysicalDeviceXcbPresentationSupportKHR;
Ian Elliotte851dd62015-11-24 15:39:10 -0700236#endif
237#ifdef VK_USE_PLATFORM_XLIB_KHR
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700238 PFN_vkGetPhysicalDeviceXlibPresentationSupportKHR
239 GetPhysicalDeviceXlibPresentationSupportKHR;
Ian Elliotte851dd62015-11-24 15:39:10 -0700240#endif
Jon Ashburncc370d02016-03-08 09:30:30 -0700241 PFN_vkGetPhysicalDeviceDisplayPropertiesKHR
242 GetPhysicalDeviceDisplayPropertiesKHR;
243 PFN_vkGetPhysicalDeviceDisplayPlanePropertiesKHR
244 GetPhysicalDeviceDisplayPlanePropertiesKHR;
245 PFN_vkGetDisplayPlaneSupportedDisplaysKHR
246 GetDisplayPlaneSupportedDisplaysKHR;
Jon Ashburnc466da52016-04-15 09:25:03 -0600247 PFN_vkGetDisplayModePropertiesKHR GetDisplayModePropertiesKHR;
248 PFN_vkCreateDisplayModeKHR CreateDisplayModeKHR;
249 PFN_vkGetDisplayPlaneCapabilitiesKHR GetDisplayPlaneCapabilitiesKHR;
250 PFN_vkCreateDisplayPlaneSurfaceKHR CreateDisplayPlaneSurfaceKHR;
251 PFN_vkDestroySurfaceKHR DestroySurfaceKHR;
Jon Ashburn10f4e822015-06-10 10:06:06 -0600252 struct loader_icd *next;
Jon Ashburnebfa25e2015-05-15 15:09:35 -0600253};
254
Jon Ashburne0367472015-08-18 18:04:47 -0600255/* per ICD library structure */
256struct loader_icd_libs {
257 size_t capacity;
258 uint32_t count;
259 struct loader_scanned_icds *list;
260};
261
Jon Ashburn392c5622015-06-10 16:11:42 -0600262/* per instance structure */
Jon Ashburn13482452015-05-12 17:26:48 -0600263struct loader_instance {
Jon Ashburnebfa25e2015-05-15 15:09:35 -0600264 VkLayerInstanceDispatchTable *disp; // must be first entry in structure
265
Jon Ashburnfd02a0f2016-03-01 19:51:07 -0700266 uint32_t total_gpu_count; // count of the next two arrays
267 struct loader_physical_device *phys_devs_term;
Jon Ashburnc466da52016-04-15 09:25:03 -0600268 struct loader_physical_device_tramp *
269 phys_devs; // tramp wrapped physDev obj list
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600270 uint32_t total_icd_count;
Jon Ashburn13482452015-05-12 17:26:48 -0600271 struct loader_icd *icds;
272 struct loader_instance *next;
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700273 struct loader_extension_list ext_list; // icds and loaders extensions
Jon Ashburne0367472015-08-18 18:04:47 -0600274 struct loader_icd_libs icd_libs;
Jon Ashburnb4c24232015-08-20 16:35:30 -0600275 struct loader_layer_list instance_layer_list;
276 struct loader_layer_list device_layer_list;
Jon Ashburn6cb69f42015-11-17 15:31:02 -0700277 struct loader_dispatch_hash_entry disp_hash[MAX_NUM_DEV_EXTS];
Jon Ashburnb4c24232015-08-20 16:35:30 -0600278
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600279 struct loader_msg_callback_map_entry *icd_msg_callback_map;
280
Courtney Goeltzenleuchter44667cc2015-06-29 15:39:26 -0600281 struct loader_layer_list activated_layer_list;
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600282
Jon Ashburnc466da52016-04-15 09:25:03 -0600283 VkInstance instance; // layers/ICD instance returned to trampoline
Courtney Goeltzenleuchter0bd705c2016-01-08 12:18:43 -0700284
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600285 bool debug_report_enabled;
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600286 VkLayerDbgFunctionNode *DbgFunctionHead;
Ian Elliottdefd6da2016-03-31 10:48:19 -0600287 uint32_t num_tmp_callbacks;
288 VkDebugReportCallbackCreateInfoEXT *tmp_dbg_create_infos;
289 VkDebugReportCallbackEXT *tmp_callbacks;
Courtney Goeltzenleuchter71b454b2015-07-05 11:28:29 -0600290
Chia-I Wu227c8b32015-10-27 18:04:07 +0800291 VkAllocationCallbacks alloc_callbacks;
Ian Elliotted33eb72015-07-06 14:36:13 -0600292
Ian Elliott54cea232015-10-30 15:28:23 -0600293 bool wsi_surface_enabled;
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -0700294#ifdef VK_USE_PLATFORM_WIN32_KHR
Ian Elliott54cea232015-10-30 15:28:23 -0600295 bool wsi_win32_surface_enabled;
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -0700296#endif
297#ifdef VK_USE_PLATFORM_MIR_KHR
Ian Elliott54cea232015-10-30 15:28:23 -0600298 bool wsi_mir_surface_enabled;
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -0700299#endif
300#ifdef VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott54cea232015-10-30 15:28:23 -0600301 bool wsi_wayland_surface_enabled;
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -0700302#endif
303#ifdef VK_USE_PLATFORM_XCB_KHR
Ian Elliott54cea232015-10-30 15:28:23 -0600304 bool wsi_xcb_surface_enabled;
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -0700305#endif
306#ifdef VK_USE_PLATFORM_XLIB_KHR
Ian Elliott54cea232015-10-30 15:28:23 -0600307 bool wsi_xlib_surface_enabled;
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -0700308#endif
309#ifdef VK_USE_PLATFORM_ANDROID_KHR
310 bool wsi_android_surface_enabled;
311#endif
Jon Ashburncc370d02016-03-08 09:30:30 -0700312 bool wsi_display_enabled;
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600313};
314
Jon Ashburnfd02a0f2016-03-01 19:51:07 -0700315/* VkPhysicalDevice requires special treatment by loader. Firstly, terminator
316 * code must be able to get the struct loader_icd to call into the proper
317 * driver (multiple ICD/gpu case). This can be accomplished by wrapping the
318 * created VkPhysicalDevice in loader terminate_EnumeratePhysicalDevices().
Piers Daniell82107a62016-03-29 11:51:11 -0600319 * Secondly, the loader must be able to handle wrapped by layer VkPhysicalDevice
Jon Ashburnfd02a0f2016-03-01 19:51:07 -0700320 * in trampoline code. This implies, that the loader trampoline code must also
321 * wrap the VkPhysicalDevice object in trampoline code. Thus, loader has to
322 * wrap the VkPhysicalDevice created object twice. In trampoline code it can't
323 * rely on the terminator object wrapping since a layer may also wrap. Since
324 * trampoline code wraps the VkPhysicalDevice this means all loader trampoline
325 * code that passes a VkPhysicalDevice should unwrap it. */
326
327/* per enumerated PhysicalDevice structure, used to wrap in trampoline code and
328 also same structure used to wrap in terminator code */
Jon Ashburnc3519e42016-03-24 15:49:57 -0600329struct loader_physical_device_tramp {
330 VkLayerInstanceDispatchTable *disp; // must be first entry in structure
Piers Daniell82107a62016-03-29 11:51:11 -0600331 struct loader_instance *this_instance;
Jon Ashburnc466da52016-04-15 09:25:03 -0600332 VkPhysicalDevice phys_dev; // object from layers/loader terminator
Jon Ashburnc3519e42016-03-24 15:49:57 -0600333};
334
335/* per enumerated PhysicalDevice structure, used to wrap in terminator code */
Jon Ashburn969caa42015-11-01 14:04:06 -0700336struct loader_physical_device {
337 VkLayerInstanceDispatchTable *disp; // must be first entry in structure
Jon Ashburn969caa42015-11-01 14:04:06 -0700338 struct loader_icd *this_icd;
Jon Ashburnc3519e42016-03-24 15:49:57 -0600339 VkPhysicalDevice phys_dev; // object from ICD
Jon Ashburn969caa42015-11-01 14:04:06 -0700340};
341
Jon Ashburn13482452015-05-12 17:26:48 -0600342struct loader_struct {
343 struct loader_instance *instances;
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600344
345 unsigned int loaded_layer_lib_count;
Courtney Goeltzenleuchter452303a2015-10-07 09:00:34 -0600346 size_t loaded_layer_lib_capacity;
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600347 struct loader_lib_info *loaded_layer_lib_list;
Jon Ashburne0367472015-08-18 18:04:47 -0600348 // TODO add ref counting of ICD libraries
Jon Ashburn269b5922015-07-06 15:40:35 -0600349 // TODO use this struct loader_layer_library_list scanned_layer_libraries;
Jon Ashburne0367472015-08-18 18:04:47 -0600350 // TODO add list of icd libraries for ref counting them for closure
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600351};
352
353struct loader_scanned_icds {
354 char *lib_name;
355 loader_platform_dl_handle handle;
Jon Ashburn27109e82015-11-17 17:35:40 -0700356 uint32_t api_version;
Jon Ashburnc7ca48d2015-07-16 10:17:29 -0600357 PFN_vkGetInstanceProcAddr GetInstanceProcAddr;
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600358 PFN_vkCreateInstance CreateInstance;
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700359 PFN_vkEnumerateInstanceExtensionProperties
360 EnumerateInstanceExtensionProperties;
Jon Ashburn13482452015-05-12 17:26:48 -0600361};
362
Jon Ashburn399c9162015-07-02 09:40:15 -0600363static inline struct loader_instance *loader_instance(VkInstance instance) {
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700364 return (struct loader_instance *)instance;
Jon Ashburn399c9162015-07-02 09:40:15 -0600365}
366
Jon Ashburnfd02a0f2016-03-01 19:51:07 -0700367static inline VkPhysicalDevice
368loader_unwrap_physical_device(VkPhysicalDevice physicalDevice) {
Piers Daniella9ccaed2016-03-31 14:47:57 -0600369 struct loader_physical_device_tramp *phys_dev =
370 (struct loader_physical_device_tramp *)physicalDevice;
Jon Ashburnfd02a0f2016-03-01 19:51:07 -0700371 return phys_dev->phys_dev;
372}
373
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700374static inline void loader_set_dispatch(void *obj, const void *data) {
375 *((const void **)obj) = data;
Chia-I Wufe333ed2015-04-11 15:34:07 +0800376}
377
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700378static inline VkLayerDispatchTable *loader_get_dispatch(const void *obj) {
379 return *((VkLayerDispatchTable **)obj);
Chia-I Wufe333ed2015-04-11 15:34:07 +0800380}
381
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700382static inline struct loader_dev_dispatch_table *
383loader_get_dev_dispatch(const void *obj) {
384 return *((struct loader_dev_dispatch_table **)obj);
Jon Ashburn6cb69f42015-11-17 15:31:02 -0700385}
386
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700387static inline VkLayerInstanceDispatchTable *
388loader_get_instance_dispatch(const void *obj) {
389 return *((VkLayerInstanceDispatchTable **)obj);
Jon Ashburn13482452015-05-12 17:26:48 -0600390}
391
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700392static inline void loader_init_dispatch(void *obj, const void *data) {
Jon Ashburn167b2b12015-04-15 13:34:33 -0600393#ifdef DEBUG
Chia-I Wufe333ed2015-04-11 15:34:07 +0800394 assert(valid_loader_magic_value(obj) &&
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700395 "Incompatible ICD, first dword must be initialized to "
396 "ICD_LOADER_MAGIC. See loader/README.md for details.");
Jon Ashburn167b2b12015-04-15 13:34:33 -0600397#endif
Chia-I Wufe333ed2015-04-11 15:34:07 +0800398
Jon Ashburn62a54d12015-05-01 18:00:33 -0600399 loader_set_dispatch(obj, data);
Chia-I Wufe333ed2015-04-11 15:34:07 +0800400}
401
Jon Ashburn13482452015-05-12 17:26:48 -0600402/* global variables used across files */
403extern struct loader_struct loader;
Jon Ashburnb4dee9c2015-08-28 15:19:27 -0600404extern THREAD_LOCAL_DECL struct loader_instance *tls_instance;
Jon Ashburne0367472015-08-18 18:04:47 -0600405extern LOADER_PLATFORM_THREAD_ONCE_DEFINITION(once_init);
Jon Ashburn7e8d8b42015-05-29 13:15:39 -0600406extern loader_platform_thread_mutex loader_lock;
Jon Ashburn7d4d51c2015-09-22 13:11:00 -0600407extern loader_platform_thread_mutex loader_json_lock;
Jon Ashburn7e8d8b42015-05-29 13:15:39 -0600408extern const VkLayerInstanceDispatchTable instance_disp;
Jon Ashburnd1eb3322016-02-10 20:59:26 -0700409extern const char *std_validation_str;
Jon Ashburn37e7f972015-04-06 10:58:22 -0600410
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600411struct loader_msg_callback_map_entry {
Courtney Goeltzenleuchter725db942015-12-09 15:48:16 -0700412 VkDebugReportCallbackEXT icd_obj;
413 VkDebugReportCallbackEXT loader_obj;
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600414};
415
Jon Ashburnc4e9ae62016-02-26 13:14:27 -0700416/* helper function definitions */
417void *loader_heap_alloc(const struct loader_instance *instance, size_t size,
418 VkSystemAllocationScope allocationScope);
419
420void loader_heap_free(const struct loader_instance *instance, void *pMemory);
421
422void *loader_tls_heap_alloc(size_t size);
423
424void loader_tls_heap_free(void *pMemory);
425
Jon Ashburn663f8312016-02-12 08:20:06 -0700426void loader_log(const struct loader_instance *inst, VkFlags msg_type,
Jon Ashburnc4e9ae62016-02-26 13:14:27 -0700427 int32_t msg_code, const char *format, ...);
Jon Ashburn663f8312016-02-12 08:20:06 -0700428
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700429bool compare_vk_extension_properties(const VkExtensionProperties *op1,
430 const VkExtensionProperties *op2);
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600431
Mark Lobodzinski8d325802016-02-02 18:53:34 -0700432VkResult loader_validate_layers(const struct loader_instance *inst,
433 const uint32_t layer_count,
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700434 const char *const *ppEnabledLayerNames,
435 const struct loader_layer_list *list);
Courtney Goeltzenleuchter76ece702015-07-06 17:45:08 -0600436
437VkResult loader_validate_instance_extensions(
Mark Lobodzinski8d325802016-02-02 18:53:34 -0700438 const struct loader_instance *inst,
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700439 const struct loader_extension_list *icd_exts,
440 const struct loader_layer_list *instance_layer,
441 const VkInstanceCreateInfo *pCreateInfo);
Courtney Goeltzenleuchter76ece702015-07-06 17:45:08 -0600442
Jon Ashburne0367472015-08-18 18:04:47 -0600443void loader_initialize(void);
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700444bool has_vk_extension_property_array(const VkExtensionProperties *vk_ext_prop,
445 const uint32_t count,
446 const VkExtensionProperties *ext_array);
447bool has_vk_extension_property(const VkExtensionProperties *vk_ext_prop,
448 const struct loader_extension_list *ext_list);
Jon Ashburn13482452015-05-12 17:26:48 -0600449
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700450VkResult loader_add_to_ext_list(const struct loader_instance *inst,
451 struct loader_extension_list *ext_list,
452 uint32_t prop_list_count,
453 const VkExtensionProperties *props);
Jon Ashburnc466da52016-04-15 09:25:03 -0600454VkResult
455loader_add_to_dev_ext_list(const struct loader_instance *inst,
456 struct loader_device_extension_list *ext_list,
457 const VkExtensionProperties *props,
458 uint32_t entry_count, char **entrys);
Jon Ashburnc4e9ae62016-02-26 13:14:27 -0700459VkResult loader_add_device_extensions(const struct loader_instance *inst,
Jon Ashburnc466da52016-04-15 09:25:03 -0600460 PFN_vkEnumerateDeviceExtensionProperties
461 fpEnumerateDeviceExtensionProperties,
Jon Ashburnc4e9ae62016-02-26 13:14:27 -0700462 VkPhysicalDevice physical_device,
463 const char *lib_name,
464 struct loader_extension_list *ext_list);
465bool loader_init_generic_list(const struct loader_instance *inst,
466 struct loader_generic_list *list_info,
467 size_t element_size);
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700468void loader_destroy_generic_list(const struct loader_instance *inst,
469 struct loader_generic_list *list);
Jon Ashburnc4e9ae62016-02-26 13:14:27 -0700470void loader_destroy_layer_list(const struct loader_instance *inst,
471 struct loader_layer_list *layer_list);
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700472void loader_delete_layer_properties(const struct loader_instance *inst,
473 struct loader_layer_list *layer_list);
Jon Ashburnd1eb3322016-02-10 20:59:26 -0700474void loader_expand_layer_names(
475 const struct loader_instance *inst, const char *key_name,
476 uint32_t expand_count,
477 const char expand_names[][VK_MAX_EXTENSION_NAME_SIZE],
Jon Ashburnc466da52016-04-15 09:25:03 -0600478 uint32_t *layer_count, char const *const **ppp_layer_names);
Chris Forbes7333fdd2016-04-06 20:49:02 +1200479void loader_delete_shadow_dev_layer_names(const struct loader_instance *inst,
480 const VkDeviceCreateInfo *orig,
481 VkDeviceCreateInfo *ours);
482void loader_delete_shadow_inst_layer_names(const struct loader_instance *inst,
483 const VkInstanceCreateInfo *orig,
484 VkInstanceCreateInfo *ours);
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700485void loader_add_to_layer_list(const struct loader_instance *inst,
486 struct loader_layer_list *list,
487 uint32_t prop_list_count,
488 const struct loader_layer_properties *props);
Jon Ashburnc466da52016-04-15 09:25:03 -0600489void loader_find_layer_name_add_list(
490 const struct loader_instance *inst, const char *name,
491 const enum layer_type type, const struct loader_layer_list *search_list,
492 struct loader_layer_list *found_list);
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700493void loader_scanned_icd_clear(const struct loader_instance *inst,
494 struct loader_icd_libs *icd_libs);
495void loader_icd_scan(const struct loader_instance *inst,
496 struct loader_icd_libs *icds);
497void loader_layer_scan(const struct loader_instance *inst,
498 struct loader_layer_list *instance_layers,
499 struct loader_layer_list *device_layers);
Jeremy Hayes10d78f12016-04-01 11:40:26 -0600500void loader_implicit_layer_scan(const struct loader_instance *inst,
Jon Ashburnc466da52016-04-15 09:25:03 -0600501 struct loader_layer_list *instance_layers,
502 struct loader_layer_list *device_layers);
Jon Ashburne0367472015-08-18 18:04:47 -0600503void loader_get_icd_loader_instance_extensions(
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700504 const struct loader_instance *inst, struct loader_icd_libs *icd_libs,
505 struct loader_extension_list *inst_exts);
506struct loader_icd *loader_get_icd_and_device(const VkDevice device,
507 struct loader_device **found_dev);
Jon Ashburnc4e9ae62016-02-26 13:14:27 -0700508void loader_init_dispatch_dev_ext(struct loader_instance *inst,
509 struct loader_device *dev);
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700510void *loader_dev_ext_gpa(struct loader_instance *inst, const char *funcName);
511void *loader_get_dev_ext_trampoline(uint32_t index);
512struct loader_instance *loader_get_instance(const VkInstance instance);
Jon Ashburnc4e9ae62016-02-26 13:14:27 -0700513struct loader_device *
Piers Daniell82107a62016-03-29 11:51:11 -0600514loader_create_logical_device(const struct loader_instance *inst);
515void loader_add_logical_device(const struct loader_instance *inst,
516 struct loader_icd *icd,
517 struct loader_device *found_dev);
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700518void loader_remove_logical_device(const struct loader_instance *inst,
519 struct loader_icd *icd,
520 struct loader_device *found_dev);
521VkResult
522loader_enable_instance_layers(struct loader_instance *inst,
523 const VkInstanceCreateInfo *pCreateInfo,
524 const struct loader_layer_list *instance_layers);
Jon Ashburn10f4e822015-06-10 10:06:06 -0600525void loader_deactivate_instance_layers(struct loader_instance *instance);
Courtney Goeltzenleuchter0bd705c2016-01-08 12:18:43 -0700526
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700527VkResult loader_create_instance_chain(const VkInstanceCreateInfo *pCreateInfo,
528 const VkAllocationCallbacks *pAllocator,
529 struct loader_instance *inst,
Jon Ashburnd1205a92016-02-03 12:37:30 -0700530 VkInstance *created_instance);
Courtney Goeltzenleuchter0bd705c2016-01-08 12:18:43 -0700531
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700532void loader_activate_instance_layer_extensions(struct loader_instance *inst,
533 VkInstance created_inst);
Jon Ashburnc4e9ae62016-02-26 13:14:27 -0700534VkResult
535loader_enable_device_layers(const struct loader_instance *inst,
Jon Ashburnc4e9ae62016-02-26 13:14:27 -0700536 struct loader_layer_list *activated_layer_list,
537 const VkDeviceCreateInfo *pCreateInfo,
538 const struct loader_layer_list *device_layers);
Courtney Goeltzenleuchter71b454b2015-07-05 11:28:29 -0600539
Jon Ashburnc466da52016-04-15 09:25:03 -0600540VkResult
541loader_create_device_chain(const struct loader_physical_device_tramp *pd,
542 const VkDeviceCreateInfo *pCreateInfo,
543 const VkAllocationCallbacks *pAllocator,
544 const struct loader_instance *inst,
545 struct loader_device *dev);
Jon Ashburnc4e9ae62016-02-26 13:14:27 -0700546VkResult loader_validate_device_extensions(
Jon Ashburnc3519e42016-03-24 15:49:57 -0600547 struct loader_physical_device_tramp *phys_dev,
Jon Ashburnc4e9ae62016-02-26 13:14:27 -0700548 const struct loader_layer_list *activated_device_layers,
Jon Ashburnfd02a0f2016-03-01 19:51:07 -0700549 const struct loader_extension_list *icd_exts,
Jon Ashburnc4e9ae62016-02-26 13:14:27 -0700550 const VkDeviceCreateInfo *pCreateInfo);
Courtney Goeltzenleuchter71b454b2015-07-05 11:28:29 -0600551
Jon Ashburnc4e9ae62016-02-26 13:14:27 -0700552/* instance layer chain termination entrypoint definitions */
553VKAPI_ATTR VkResult VKAPI_CALL
554terminator_CreateInstance(const VkInstanceCreateInfo *pCreateInfo,
555 const VkAllocationCallbacks *pAllocator,
556 VkInstance *pInstance);
Jon Ashburnb4dee9c2015-08-28 15:19:27 -0600557
Jon Ashburnc4e9ae62016-02-26 13:14:27 -0700558VKAPI_ATTR void VKAPI_CALL
559terminator_DestroyInstance(VkInstance instance,
560 const VkAllocationCallbacks *pAllocator);
Jon Ashburnb4dee9c2015-08-28 15:19:27 -0600561
Jon Ashburnc4e9ae62016-02-26 13:14:27 -0700562VKAPI_ATTR VkResult VKAPI_CALL
563terminator_EnumeratePhysicalDevices(VkInstance instance,
564 uint32_t *pPhysicalDeviceCount,
565 VkPhysicalDevice *pPhysicalDevices);
566
567VKAPI_ATTR void VKAPI_CALL
568terminator_GetPhysicalDeviceFeatures(VkPhysicalDevice physicalDevice,
569 VkPhysicalDeviceFeatures *pFeatures);
570
571VKAPI_ATTR void VKAPI_CALL
572terminator_GetPhysicalDeviceFormatProperties(VkPhysicalDevice physicalDevice,
573 VkFormat format,
574 VkFormatProperties *pFormatInfo);
575
576VKAPI_ATTR VkResult VKAPI_CALL
577terminator_GetPhysicalDeviceImageFormatProperties(
578 VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type,
579 VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags,
580 VkImageFormatProperties *pImageFormatProperties);
581
582VKAPI_ATTR void VKAPI_CALL
583terminator_GetPhysicalDeviceSparseImageFormatProperties(
584 VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type,
585 VkSampleCountFlagBits samples, VkImageUsageFlags usage,
586 VkImageTiling tiling, uint32_t *pNumProperties,
587 VkSparseImageFormatProperties *pProperties);
588
589VKAPI_ATTR void VKAPI_CALL
590terminator_GetPhysicalDeviceProperties(VkPhysicalDevice physicalDevice,
591 VkPhysicalDeviceProperties *pProperties);
592
593VKAPI_ATTR VkResult VKAPI_CALL terminator_EnumerateDeviceExtensionProperties(
594 VkPhysicalDevice physicalDevice, const char *pLayerName, uint32_t *pCount,
595 VkExtensionProperties *pProperties);
596
597VKAPI_ATTR VkResult VKAPI_CALL
598terminator_EnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice,
599 uint32_t *pCount,
600 VkLayerProperties *pProperties);
601
602VKAPI_ATTR void VKAPI_CALL terminator_GetPhysicalDeviceQueueFamilyProperties(
603 VkPhysicalDevice physicalDevice, uint32_t *pCount,
604 VkQueueFamilyProperties *pProperties);
605
606VKAPI_ATTR void VKAPI_CALL terminator_GetPhysicalDeviceMemoryProperties(
607 VkPhysicalDevice physicalDevice,
608 VkPhysicalDeviceMemoryProperties *pProperties);
609
610VKAPI_ATTR VkResult VKAPI_CALL
611terminator_CreateDevice(VkPhysicalDevice gpu,
612 const VkDeviceCreateInfo *pCreateInfo,
613 const VkAllocationCallbacks *pAllocator,
614 VkDevice *pDevice);
Mark Lobodzinski8d325802016-02-02 18:53:34 -0700615
Jon Ashburnb1cdf2e2016-02-10 20:50:19 -0700616VkStringErrorFlags vk_string_validate(const int max_length,
617 const char *char_array);
Mark Lobodzinski8d325802016-02-02 18:53:34 -0700618
Chia-I Wuc1e0f962014-08-04 08:03:57 +0800619#endif /* LOADER_H */