blob: ff7ab112aa578f23959857c758c57aa92971cf00 [file] [log] [blame]
Chia-I Wu19300602014-08-04 08:03:57 +08001/*
Chia-I Wu19300602014-08-04 08:03:57 +08002 *
Jon Ashburn23d36b12016-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 Goeltzenleuchterf821dad2015-12-02 14:53:22 -07006 * Copyright (C) 2015 Google Inc.
Chia-I Wu19300602014-08-04 08:03:57 +08007 *
Jon Ashburn23d36b12016-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 Wu19300602014-08-04 08:03:57 +080014 *
Jon Ashburn23d36b12016-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 Wu19300602014-08-04 08:03:57 +080017 *
Jon Ashburn23d36b12016-02-02 17:47:28 -070018 * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Chia-I Wu19300602014-08-04 08:03:57 +080019 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Jon Ashburn23d36b12016-02-02 17:47:28 -070020 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
Chia-I Wu701f3f62014-09-02 08:32:09 +080021 *
Jon Ashburn23d36b12016-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 Goeltzenleuchter05559522015-10-30 11:14:30 -060029 * Author: Chia-I Wu <olvaffe@gmail.com>
30 * Author: Chia-I Wu <olv@lunarg.com>
Jon Ashburn23d36b12016-02-02 17:47:28 -070031 * Author: Mark Lobodzinski <mark@LunarG.com>
Courtney Goeltzenleuchter05559522015-10-30 11:14:30 -060032 *
Chia-I Wu19300602014-08-04 08:03:57 +080033 */
34
35#ifndef LOADER_H
36#define LOADER_H
37
David Pinedo9316d3b2015-11-06 12:54:48 -070038#include <vulkan/vulkan.h>
Jon Ashburn8a39efc2015-11-06 11:02:40 -070039#include <vk_loader_platform.h>
Ian Elliott1dcd1092015-11-17 17:29:40 -070040
David Pinedo9316d3b2015-11-06 12:54:48 -070041#include <vulkan/vk_layer.h>
42#include <vulkan/vk_icd.h>
Chia-I Wu5291c762015-04-11 15:34:07 +080043#include <assert.h>
44
Chia-I Wu19300602014-08-04 08:03:57 +080045#if defined(__GNUC__) && __GNUC__ >= 4
Jon Ashburn23d36b12016-02-02 17:47:28 -070046#define LOADER_EXPORT __attribute__((visibility("default")))
Chia-I Wu19300602014-08-04 08:03:57 +080047#elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)
Jon Ashburn23d36b12016-02-02 17:47:28 -070048#define LOADER_EXPORT __attribute__((visibility("default")))
Chia-I Wu19300602014-08-04 08:03:57 +080049#else
Jon Ashburn23d36b12016-02-02 17:47:28 -070050#define LOADER_EXPORT
Chia-I Wu19300602014-08-04 08:03:57 +080051#endif
52
Jon Ashburnf73e9212015-08-04 10:22:33 -060053#define MAX_STRING_SIZE 1024
Courtney Goeltzenleuchter110fdf92015-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 Ashburn27cd5842015-05-12 17:26:48 -060057
Jon Ashburn5ef20602015-07-02 09:40:15 -060058enum layer_type {
Jon Ashburn0c26e712015-07-02 16:10:32 -060059 VK_LAYER_TYPE_DEVICE_EXPLICIT = 0x1,
60 VK_LAYER_TYPE_INSTANCE_EXPLICIT = 0x2,
Jon Ashburn86a527a2016-02-10 20:59:26 -070061 VK_LAYER_TYPE_GLOBAL_EXPLICIT = 0x3, // instance and device layer, bitwise
Jon Ashburn0c26e712015-07-02 16:10:32 -060062 VK_LAYER_TYPE_DEVICE_IMPLICIT = 0x4,
63 VK_LAYER_TYPE_INSTANCE_IMPLICIT = 0x8,
Jon Ashburn86a527a2016-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 Ashburn5ef20602015-07-02 09:40:15 -060066};
67
Mark Lobodzinskie9f09ef2016-02-02 18:53:34 -070068typedef enum VkStringErrorFlagBits {
Jon Ashburnf2b4e382016-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 Lobodzinskie9f09ef2016-02-02 18:53:34 -070072} VkStringErrorFlagBits;
73typedef VkFlags VkStringErrorFlags;
74
Jon Ashburnf2b4e382016-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 Lobodzinskie9f09ef2016-02-02 18:53:34 -070084
Jon Ashburn86a527a2016-02-10 20:59:26 -070085static const char std_validation_names[9][VK_MAX_EXTENSION_NAME_SIZE] = {
Jon Ashburn4b8e87d2016-02-18 12:48:24 -070086 "VK_LAYER_GOOGLE_threading", "VK_LAYER_LUNARG_param_checker",
Jon Ashburn86a527a2016-02-10 20:59:26 -070087 "VK_LAYER_LUNARG_device_limits", "VK_LAYER_LUNARG_object_tracker",
88 "VK_LAYER_LUNARG_image", "VK_LAYER_LUNARG_mem_tracker",
89 "VK_LAYER_LUNARG_draw_state", "VK_LAYER_LUNARG_swapchain",
90 "VK_LAYER_GOOGLE_unique_objects"};
91
Jon Ashburn6e6a2162015-12-10 08:51:10 -070092// form of all dynamic lists/arrays
93// only the list element should be changed
94struct loader_generic_list {
95 size_t capacity;
96 uint32_t count;
97 void *list;
98};
99
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600100struct loader_extension_list {
101 size_t capacity;
102 uint32_t count;
Jon Ashburn5c042ea2015-08-04 11:14:18 -0600103 VkExtensionProperties *list;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600104};
105
Jon Ashburn39fbd4e2015-12-10 18:17:34 -0700106struct loader_dev_ext_props {
107 VkExtensionProperties props;
108 uint32_t entrypoint_count;
109 char **entrypoints;
110};
111
112struct loader_device_extension_list {
113 size_t capacity;
114 uint32_t count;
115 struct loader_dev_ext_props *list;
116};
117
Jon Ashburn5ef20602015-07-02 09:40:15 -0600118struct loader_name_value {
Jon Ashburnf73e9212015-08-04 10:22:33 -0600119 char name[MAX_STRING_SIZE];
120 char value[MAX_STRING_SIZE];
Jon Ashburn5ef20602015-07-02 09:40:15 -0600121};
122
123struct loader_lib_info {
Jon Ashburn3d002332015-08-20 16:35:30 -0600124 char lib_name[MAX_STRING_SIZE];
Jon Ashburn5ef20602015-07-02 09:40:15 -0600125 uint32_t ref_count;
126 loader_platform_dl_handle lib_handle;
127};
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600128
Jon Ashburn5ef20602015-07-02 09:40:15 -0600129struct loader_layer_functions {
Jon Ashburnf73e9212015-08-04 10:22:33 -0600130 char str_gipa[MAX_STRING_SIZE];
131 char str_gdpa[MAX_STRING_SIZE];
Jon Ashburn5ef20602015-07-02 09:40:15 -0600132 PFN_vkGetInstanceProcAddr get_instance_proc_addr;
133 PFN_vkGetDeviceProcAddr get_device_proc_addr;
134};
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600135
Jon Ashburn5ef20602015-07-02 09:40:15 -0600136struct loader_layer_properties {
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -0600137 VkLayerProperties info;
Jon Ashburn5ef20602015-07-02 09:40:15 -0600138 enum layer_type type;
Jon Ashburn3d002332015-08-20 16:35:30 -0600139 char lib_name[MAX_STRING_SIZE];
Jon Ashburn5ef20602015-07-02 09:40:15 -0600140 struct loader_layer_functions functions;
141 struct loader_extension_list instance_extension_list;
Jon Ashburn39fbd4e2015-12-10 18:17:34 -0700142 struct loader_device_extension_list device_extension_list;
Jon Ashburn5ef20602015-07-02 09:40:15 -0600143 struct loader_name_value disable_env_var;
144 struct loader_name_value enable_env_var;
145};
146
147struct loader_layer_list {
148 size_t capacity;
149 uint32_t count;
150 struct loader_layer_properties *list;
Jon Ashburn27cd5842015-05-12 17:26:48 -0600151};
152
Courtney Goeltzenleuchter371de702015-07-05 12:53:31 -0600153struct loader_layer_library_list {
154 size_t capacity;
155 uint32_t count;
156 struct loader_lib_info *list;
157};
158
Jon Ashburnfc1031e2015-11-17 15:31:02 -0700159struct loader_dispatch_hash_list {
160 size_t capacity;
161 uint32_t count;
Jon Ashburn23d36b12016-02-02 17:47:28 -0700162 uint32_t *index; // index into the dev_ext dispatch table
Jon Ashburnfc1031e2015-11-17 15:31:02 -0700163};
164
165#define MAX_NUM_DEV_EXTS 250
Jon Ashburn23d36b12016-02-02 17:47:28 -0700166// loader_dispatch_hash_entry and loader_dev_ext_dispatch_table.DevExt have one
167// to one
Jon Ashburnfc1031e2015-11-17 15:31:02 -0700168// correspondence; one loader_dispatch_hash_entry for one DevExt dispatch entry.
169// Also have a one to one correspondence with functions in dev_ext_trampoline.c
170struct loader_dispatch_hash_entry {
171 char *func_name;
Jon Ashburn23d36b12016-02-02 17:47:28 -0700172 struct loader_dispatch_hash_list list; // to handle hashing collisions
Jon Ashburnfc1031e2015-11-17 15:31:02 -0700173};
174
Jon Ashburn23d36b12016-02-02 17:47:28 -0700175typedef void(VKAPI_PTR *PFN_vkDevExt)(VkDevice device);
Jon Ashburnfc1031e2015-11-17 15:31:02 -0700176struct loader_dev_ext_dispatch_table {
177 PFN_vkDevExt DevExt[MAX_NUM_DEV_EXTS];
178};
179
180struct loader_dev_dispatch_table {
181 VkLayerDispatchTable core_dispatch;
182 struct loader_dev_ext_dispatch_table ext_dispatch;
183};
184
Jon Ashburndc6fcad2015-06-10 10:06:06 -0600185/* per CreateDevice structure */
186struct loader_device {
Jon Ashburnfc1031e2015-11-17 15:31:02 -0700187 struct loader_dev_dispatch_table loader_dispatch;
Jon Ashburn23d36b12016-02-02 17:47:28 -0700188 VkDevice device; // device object from the icd
Jon Ashburndc6fcad2015-06-10 10:06:06 -0600189
Jon Ashburn23d36b12016-02-02 17:47:28 -0700190 uint32_t app_extension_count;
Jon Ashburndc6fcad2015-06-10 10:06:06 -0600191 VkExtensionProperties *app_extension_props;
192
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -0600193 struct loader_layer_list activated_layer_list;
Jon Ashburndc6fcad2015-06-10 10:06:06 -0600194
195 struct loader_device *next;
196};
197
Jon Ashburn953bb3c2015-06-10 16:11:42 -0600198/* per ICD structure */
Jon Ashburn95a77ba2015-05-15 15:09:35 -0600199struct loader_icd {
Jon Ashburn3d002332015-08-20 16:35:30 -0600200 // pointers to find other structs
201 const struct loader_scanned_icds *this_icd_lib;
202 const struct loader_instance *this_instance;
Jon Ashburn95a77ba2015-05-15 15:09:35 -0600203
Jon Ashburndc6fcad2015-06-10 10:06:06 -0600204 struct loader_device *logical_device_list;
Jon Ashburn23d36b12016-02-02 17:47:28 -0700205 VkInstance instance; // instance object from the icd
Jon Ashburn8d1b0b52015-05-18 13:20:15 -0600206 PFN_vkGetDeviceProcAddr GetDeviceProcAddr;
Jon Ashburn95a77ba2015-05-15 15:09:35 -0600207 PFN_vkDestroyInstance DestroyInstance;
208 PFN_vkEnumeratePhysicalDevices EnumeratePhysicalDevices;
Chris Forbesbc0bb772015-06-21 22:55:02 +1200209 PFN_vkGetPhysicalDeviceFeatures GetPhysicalDeviceFeatures;
Courtney Goeltzenleuchter2caec862015-07-12 12:52:09 -0600210 PFN_vkGetPhysicalDeviceFormatProperties GetPhysicalDeviceFormatProperties;
Jon Ashburn23d36b12016-02-02 17:47:28 -0700211 PFN_vkGetPhysicalDeviceImageFormatProperties
212 GetPhysicalDeviceImageFormatProperties;
Jon Ashburn95a77ba2015-05-15 15:09:35 -0600213 PFN_vkCreateDevice CreateDevice;
Tony Barbour59a47322015-06-24 16:06:58 -0600214 PFN_vkGetPhysicalDeviceProperties GetPhysicalDeviceProperties;
Jon Ashburn23d36b12016-02-02 17:47:28 -0700215 PFN_vkGetPhysicalDeviceQueueFamilyProperties
216 GetPhysicalDeviceQueueFamilyProperties;
Tony Barbour59a47322015-06-24 16:06:58 -0600217 PFN_vkGetPhysicalDeviceMemoryProperties GetPhysicalDeviceMemoryProperties;
Courtney Goeltzenleuchter35985f62015-09-14 17:22:16 -0600218 PFN_vkEnumerateDeviceExtensionProperties EnumerateDeviceExtensionProperties;
Jon Ashburn23d36b12016-02-02 17:47:28 -0700219 PFN_vkGetPhysicalDeviceSparseImageFormatProperties
220 GetPhysicalDeviceSparseImageFormatProperties;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700221 PFN_vkCreateDebugReportCallbackEXT CreateDebugReportCallbackEXT;
222 PFN_vkDestroyDebugReportCallbackEXT DestroyDebugReportCallbackEXT;
223 PFN_vkDebugReportMessageEXT DebugReportMessageEXT;
Ian Elliott7e40db92015-08-21 15:09:33 -0600224 PFN_vkGetPhysicalDeviceSurfaceSupportKHR GetPhysicalDeviceSurfaceSupportKHR;
Jon Ashburn23d36b12016-02-02 17:47:28 -0700225 PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR
226 GetPhysicalDeviceSurfaceCapabilitiesKHR;
Ian Elliott486c5502015-11-19 16:05:09 -0700227 PFN_vkGetPhysicalDeviceSurfaceFormatsKHR GetPhysicalDeviceSurfaceFormatsKHR;
Jon Ashburn23d36b12016-02-02 17:47:28 -0700228 PFN_vkGetPhysicalDeviceSurfacePresentModesKHR
229 GetPhysicalDeviceSurfacePresentModesKHR;
Ian Elliott919fa302015-11-24 15:39:10 -0700230#ifdef VK_USE_PLATFORM_WIN32_KHR
Jon Ashburn23d36b12016-02-02 17:47:28 -0700231 PFN_vkGetPhysicalDeviceWin32PresentationSupportKHR
232 GetPhysicalDeviceWin32PresentationSupportKHR;
Ian Elliott919fa302015-11-24 15:39:10 -0700233#endif
234#ifdef VK_USE_PLATFORM_MIR_KHR
Jon Ashburn23d36b12016-02-02 17:47:28 -0700235 PFN_vkGetPhysicalDeviceMirPresentationSupportKHR
236 GetPhysicalDeviceMirPresentvationSupportKHR;
Ian Elliott919fa302015-11-24 15:39:10 -0700237#endif
238#ifdef VK_USE_PLATFORM_WAYLAND_KHR
Jon Ashburn23d36b12016-02-02 17:47:28 -0700239 PFN_vkGetPhysicalDeviceWaylandPresentationSupportKHR
240 GetPhysicalDeviceWaylandPresentationSupportKHR;
Ian Elliott919fa302015-11-24 15:39:10 -0700241#endif
242#ifdef VK_USE_PLATFORM_XCB_KHR
Jon Ashburn23d36b12016-02-02 17:47:28 -0700243 PFN_vkGetPhysicalDeviceXcbPresentationSupportKHR
244 GetPhysicalDeviceXcbPresentationSupportKHR;
Ian Elliott919fa302015-11-24 15:39:10 -0700245#endif
246#ifdef VK_USE_PLATFORM_XLIB_KHR
Jon Ashburn23d36b12016-02-02 17:47:28 -0700247 PFN_vkGetPhysicalDeviceXlibPresentationSupportKHR
248 GetPhysicalDeviceXlibPresentationSupportKHR;
Ian Elliott919fa302015-11-24 15:39:10 -0700249#endif
Jon Ashburnc7d3e732016-03-08 09:30:30 -0700250 PFN_vkGetPhysicalDeviceDisplayPropertiesKHR
251 GetPhysicalDeviceDisplayPropertiesKHR;
252 PFN_vkGetPhysicalDeviceDisplayPlanePropertiesKHR
253 GetPhysicalDeviceDisplayPlanePropertiesKHR;
254 PFN_vkGetDisplayPlaneSupportedDisplaysKHR
255 GetDisplayPlaneSupportedDisplaysKHR;
256 PFN_vkGetDisplayModePropertiesKHR
257 GetDisplayModePropertiesKHR;
258 PFN_vkCreateDisplayModeKHR
259 CreateDisplayModeKHR;
260 PFN_vkGetDisplayPlaneCapabilitiesKHR
261 GetDisplayPlaneCapabilitiesKHR;
262 PFN_vkCreateDisplayPlaneSurfaceKHR
263 CreateDisplayPlaneSurfaceKHR;
Jon Ashburndc6fcad2015-06-10 10:06:06 -0600264 struct loader_icd *next;
Jon Ashburn95a77ba2015-05-15 15:09:35 -0600265};
266
Jon Ashburn8810c5f2015-08-18 18:04:47 -0600267/* per ICD library structure */
268struct loader_icd_libs {
269 size_t capacity;
270 uint32_t count;
271 struct loader_scanned_icds *list;
272};
273
Jon Ashburn953bb3c2015-06-10 16:11:42 -0600274/* per instance structure */
Jon Ashburn27cd5842015-05-12 17:26:48 -0600275struct loader_instance {
Jon Ashburn95a77ba2015-05-15 15:09:35 -0600276 VkLayerInstanceDispatchTable *disp; // must be first entry in structure
277
Jon Ashburn014438f2016-03-01 19:51:07 -0700278 uint32_t total_gpu_count; // count of the next two arrays
279 struct loader_physical_device *phys_devs_term;
280 struct loader_physical_device *phys_devs; // tramp wrapped physDev obj list
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600281 uint32_t total_icd_count;
Jon Ashburn27cd5842015-05-12 17:26:48 -0600282 struct loader_icd *icds;
283 struct loader_instance *next;
Jon Ashburn23d36b12016-02-02 17:47:28 -0700284 struct loader_extension_list ext_list; // icds and loaders extensions
Jon Ashburn8810c5f2015-08-18 18:04:47 -0600285 struct loader_icd_libs icd_libs;
Jon Ashburn3d002332015-08-20 16:35:30 -0600286 struct loader_layer_list instance_layer_list;
287 struct loader_layer_list device_layer_list;
Jon Ashburnfc1031e2015-11-17 15:31:02 -0700288 struct loader_dispatch_hash_entry disp_hash[MAX_NUM_DEV_EXTS];
Jon Ashburn3d002332015-08-20 16:35:30 -0600289
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600290 struct loader_msg_callback_map_entry *icd_msg_callback_map;
291
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -0600292 struct loader_layer_list activated_layer_list;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600293
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700294 VkInstance instance;
295
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600296 bool debug_report_enabled;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600297 VkLayerDbgFunctionNode *DbgFunctionHead;
Courtney Goeltzenleuchter7f5aafc2015-07-05 11:28:29 -0600298
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800299 VkAllocationCallbacks alloc_callbacks;
Ian Elliottd3ef02f2015-07-06 14:36:13 -0600300
Ian Elliott954fa342015-10-30 15:28:23 -0600301 bool wsi_surface_enabled;
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -0700302#ifdef VK_USE_PLATFORM_WIN32_KHR
Ian Elliott954fa342015-10-30 15:28:23 -0600303 bool wsi_win32_surface_enabled;
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -0700304#endif
305#ifdef VK_USE_PLATFORM_MIR_KHR
Ian Elliott954fa342015-10-30 15:28:23 -0600306 bool wsi_mir_surface_enabled;
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -0700307#endif
308#ifdef VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott954fa342015-10-30 15:28:23 -0600309 bool wsi_wayland_surface_enabled;
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -0700310#endif
311#ifdef VK_USE_PLATFORM_XCB_KHR
Ian Elliott954fa342015-10-30 15:28:23 -0600312 bool wsi_xcb_surface_enabled;
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -0700313#endif
314#ifdef VK_USE_PLATFORM_XLIB_KHR
Ian Elliott954fa342015-10-30 15:28:23 -0600315 bool wsi_xlib_surface_enabled;
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -0700316#endif
317#ifdef VK_USE_PLATFORM_ANDROID_KHR
318 bool wsi_android_surface_enabled;
319#endif
Jon Ashburnc7d3e732016-03-08 09:30:30 -0700320 bool wsi_display_enabled;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600321};
322
Jon Ashburn014438f2016-03-01 19:51:07 -0700323/* VkPhysicalDevice requires special treatment by loader. Firstly, terminator
324 * code must be able to get the struct loader_icd to call into the proper
325 * driver (multiple ICD/gpu case). This can be accomplished by wrapping the
326 * created VkPhysicalDevice in loader terminate_EnumeratePhysicalDevices().
327 * Secondly, loader must be able to find the instance and icd in trampoline
328 * code.
329 * Thirdly, the loader must be able to handle wrapped by layer VkPhysicalDevice
330 * in trampoline code. This implies, that the loader trampoline code must also
331 * wrap the VkPhysicalDevice object in trampoline code. Thus, loader has to
332 * wrap the VkPhysicalDevice created object twice. In trampoline code it can't
333 * rely on the terminator object wrapping since a layer may also wrap. Since
334 * trampoline code wraps the VkPhysicalDevice this means all loader trampoline
335 * code that passes a VkPhysicalDevice should unwrap it. */
336
337/* per enumerated PhysicalDevice structure, used to wrap in trampoline code and
338 also same structure used to wrap in terminator code */
Jon Ashburn24cd4be2015-11-01 14:04:06 -0700339struct loader_physical_device {
340 VkLayerInstanceDispatchTable *disp; // must be first entry in structure
Jon Ashburn24cd4be2015-11-01 14:04:06 -0700341 struct loader_icd *this_icd;
Jon Ashburn014438f2016-03-01 19:51:07 -0700342 VkPhysicalDevice phys_dev; // object from ICD/layers/loader terminator
Jon Ashburn24cd4be2015-11-01 14:04:06 -0700343};
344
Jon Ashburn27cd5842015-05-12 17:26:48 -0600345struct loader_struct {
346 struct loader_instance *instances;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600347
348 unsigned int loaded_layer_lib_count;
Courtney Goeltzenleuchterdad30df2015-10-07 09:00:34 -0600349 size_t loaded_layer_lib_capacity;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600350 struct loader_lib_info *loaded_layer_lib_list;
Jon Ashburn8810c5f2015-08-18 18:04:47 -0600351 // TODO add ref counting of ICD libraries
Jon Ashburn2d0c4bb2015-07-06 15:40:35 -0600352 // TODO use this struct loader_layer_library_list scanned_layer_libraries;
Jon Ashburn8810c5f2015-08-18 18:04:47 -0600353 // TODO add list of icd libraries for ref counting them for closure
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600354};
355
356struct loader_scanned_icds {
357 char *lib_name;
358 loader_platform_dl_handle handle;
Jon Ashburn005617f2015-11-17 17:35:40 -0700359 uint32_t api_version;
Jon Ashburnc624c882015-07-16 10:17:29 -0600360 PFN_vkGetInstanceProcAddr GetInstanceProcAddr;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600361 PFN_vkCreateInstance CreateInstance;
Jon Ashburn23d36b12016-02-02 17:47:28 -0700362 PFN_vkEnumerateInstanceExtensionProperties
363 EnumerateInstanceExtensionProperties;
Jon Ashburn27cd5842015-05-12 17:26:48 -0600364};
365
Jon Ashburn5ef20602015-07-02 09:40:15 -0600366static inline struct loader_instance *loader_instance(VkInstance instance) {
Jon Ashburn23d36b12016-02-02 17:47:28 -0700367 return (struct loader_instance *)instance;
Jon Ashburn5ef20602015-07-02 09:40:15 -0600368}
369
Jon Ashburn014438f2016-03-01 19:51:07 -0700370static inline VkPhysicalDevice
371loader_unwrap_physical_device(VkPhysicalDevice physicalDevice) {
372 struct loader_physical_device *phys_dev =
373 (struct loader_physical_device *)physicalDevice;
374 return phys_dev->phys_dev;
375}
376
Jon Ashburn23d36b12016-02-02 17:47:28 -0700377static inline void loader_set_dispatch(void *obj, const void *data) {
378 *((const void **)obj) = data;
Chia-I Wu5291c762015-04-11 15:34:07 +0800379}
380
Jon Ashburn23d36b12016-02-02 17:47:28 -0700381static inline VkLayerDispatchTable *loader_get_dispatch(const void *obj) {
382 return *((VkLayerDispatchTable **)obj);
Chia-I Wu5291c762015-04-11 15:34:07 +0800383}
384
Jon Ashburn23d36b12016-02-02 17:47:28 -0700385static inline struct loader_dev_dispatch_table *
386loader_get_dev_dispatch(const void *obj) {
387 return *((struct loader_dev_dispatch_table **)obj);
Jon Ashburnfc1031e2015-11-17 15:31:02 -0700388}
389
Jon Ashburn23d36b12016-02-02 17:47:28 -0700390static inline VkLayerInstanceDispatchTable *
391loader_get_instance_dispatch(const void *obj) {
392 return *((VkLayerInstanceDispatchTable **)obj);
Jon Ashburn27cd5842015-05-12 17:26:48 -0600393}
394
Jon Ashburn23d36b12016-02-02 17:47:28 -0700395static inline void loader_init_dispatch(void *obj, const void *data) {
Jon Ashburn40066642015-04-15 13:34:33 -0600396#ifdef DEBUG
Chia-I Wu5291c762015-04-11 15:34:07 +0800397 assert(valid_loader_magic_value(obj) &&
Jon Ashburn23d36b12016-02-02 17:47:28 -0700398 "Incompatible ICD, first dword must be initialized to "
399 "ICD_LOADER_MAGIC. See loader/README.md for details.");
Jon Ashburn40066642015-04-15 13:34:33 -0600400#endif
Chia-I Wu5291c762015-04-11 15:34:07 +0800401
Jon Ashburn1ed042c2015-05-01 18:00:33 -0600402 loader_set_dispatch(obj, data);
Chia-I Wu5291c762015-04-11 15:34:07 +0800403}
404
Jon Ashburn27cd5842015-05-12 17:26:48 -0600405/* global variables used across files */
406extern struct loader_struct loader;
Jon Ashburn87d6aa92015-08-28 15:19:27 -0600407extern THREAD_LOCAL_DECL struct loader_instance *tls_instance;
Jon Ashburn8810c5f2015-08-18 18:04:47 -0600408extern LOADER_PLATFORM_THREAD_ONCE_DEFINITION(once_init);
Jon Ashburn6301a0f2015-05-29 13:15:39 -0600409extern loader_platform_thread_mutex loader_lock;
Jon Ashburn6461ef22015-09-22 13:11:00 -0600410extern loader_platform_thread_mutex loader_json_lock;
Jon Ashburn6301a0f2015-05-29 13:15:39 -0600411extern const VkLayerInstanceDispatchTable instance_disp;
Jon Ashburn86a527a2016-02-10 20:59:26 -0700412extern const char *std_validation_str;
Jon Ashburnbacb0f52015-04-06 10:58:22 -0600413
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600414struct loader_msg_callback_map_entry {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700415 VkDebugReportCallbackEXT icd_obj;
416 VkDebugReportCallbackEXT loader_obj;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600417};
418
Jon Ashburn1530c342016-02-26 13:14:27 -0700419/* helper function definitions */
420void *loader_heap_alloc(const struct loader_instance *instance, size_t size,
421 VkSystemAllocationScope allocationScope);
422
423void loader_heap_free(const struct loader_instance *instance, void *pMemory);
424
425void *loader_tls_heap_alloc(size_t size);
426
427void loader_tls_heap_free(void *pMemory);
428
Jon Ashburn2e37d752016-02-12 08:20:06 -0700429void loader_log(const struct loader_instance *inst, VkFlags msg_type,
Jon Ashburn1530c342016-02-26 13:14:27 -0700430 int32_t msg_code, const char *format, ...);
Jon Ashburn2e37d752016-02-12 08:20:06 -0700431
Jon Ashburn23d36b12016-02-02 17:47:28 -0700432bool compare_vk_extension_properties(const VkExtensionProperties *op1,
433 const VkExtensionProperties *op2);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600434
Mark Lobodzinskie9f09ef2016-02-02 18:53:34 -0700435VkResult loader_validate_layers(const struct loader_instance *inst,
436 const uint32_t layer_count,
Jon Ashburn23d36b12016-02-02 17:47:28 -0700437 const char *const *ppEnabledLayerNames,
438 const struct loader_layer_list *list);
Courtney Goeltzenleuchter3b8c5ff2015-07-06 17:45:08 -0600439
440VkResult loader_validate_instance_extensions(
Mark Lobodzinskie9f09ef2016-02-02 18:53:34 -0700441 const struct loader_instance *inst,
Jon Ashburn23d36b12016-02-02 17:47:28 -0700442 const struct loader_extension_list *icd_exts,
443 const struct loader_layer_list *instance_layer,
444 const VkInstanceCreateInfo *pCreateInfo);
Courtney Goeltzenleuchter3b8c5ff2015-07-06 17:45:08 -0600445
Jon Ashburn8810c5f2015-08-18 18:04:47 -0600446void loader_initialize(void);
Jon Ashburn23d36b12016-02-02 17:47:28 -0700447bool has_vk_extension_property_array(const VkExtensionProperties *vk_ext_prop,
448 const uint32_t count,
449 const VkExtensionProperties *ext_array);
450bool has_vk_extension_property(const VkExtensionProperties *vk_ext_prop,
451 const struct loader_extension_list *ext_list);
Jon Ashburn27cd5842015-05-12 17:26:48 -0600452
Jon Ashburn23d36b12016-02-02 17:47:28 -0700453VkResult loader_add_to_ext_list(const struct loader_instance *inst,
454 struct loader_extension_list *ext_list,
455 uint32_t prop_list_count,
456 const VkExtensionProperties *props);
Jon Ashburn1530c342016-02-26 13:14:27 -0700457VkResult loader_add_device_extensions(const struct loader_instance *inst,
458 struct loader_icd *icd,
459 VkPhysicalDevice physical_device,
460 const char *lib_name,
461 struct loader_extension_list *ext_list);
462bool loader_init_generic_list(const struct loader_instance *inst,
463 struct loader_generic_list *list_info,
464 size_t element_size);
Jon Ashburn23d36b12016-02-02 17:47:28 -0700465void loader_destroy_generic_list(const struct loader_instance *inst,
466 struct loader_generic_list *list);
Jon Ashburn1530c342016-02-26 13:14:27 -0700467void loader_destroy_layer_list(const struct loader_instance *inst,
468 struct loader_layer_list *layer_list);
Jon Ashburn23d36b12016-02-02 17:47:28 -0700469void loader_delete_layer_properties(const struct loader_instance *inst,
470 struct loader_layer_list *layer_list);
Jon Ashburn86a527a2016-02-10 20:59:26 -0700471void loader_expand_layer_names(
472 const struct loader_instance *inst, const char *key_name,
473 uint32_t expand_count,
474 const char expand_names[][VK_MAX_EXTENSION_NAME_SIZE],
475 uint32_t *layer_count, char ***ppp_layer_names);
Jon Ashburn71483442016-02-11 18:59:43 -0700476void loader_unexpand_dev_layer_names(const struct loader_instance *inst,
477 uint32_t layer_count, char **layer_names,
478 char **layer_ptr,
Jon Ashburn86a527a2016-02-10 20:59:26 -0700479 const VkDeviceCreateInfo *pCreateInfo);
Jon Ashburn71483442016-02-11 18:59:43 -0700480void loader_unexpand_inst_layer_names(const struct loader_instance *inst,
481 uint32_t layer_count, char **layer_names,
482 char **layer_ptr,
Jon Ashburn86a527a2016-02-10 20:59:26 -0700483 const VkInstanceCreateInfo *pCreateInfo);
Jon Ashburn23d36b12016-02-02 17:47:28 -0700484void loader_add_to_layer_list(const struct loader_instance *inst,
485 struct loader_layer_list *list,
486 uint32_t prop_list_count,
487 const struct loader_layer_properties *props);
488void loader_scanned_icd_clear(const struct loader_instance *inst,
489 struct loader_icd_libs *icd_libs);
490void loader_icd_scan(const struct loader_instance *inst,
491 struct loader_icd_libs *icds);
492void loader_layer_scan(const struct loader_instance *inst,
493 struct loader_layer_list *instance_layers,
494 struct loader_layer_list *device_layers);
Jon Ashburn8810c5f2015-08-18 18:04:47 -0600495void loader_get_icd_loader_instance_extensions(
Jon Ashburn23d36b12016-02-02 17:47:28 -0700496 const struct loader_instance *inst, struct loader_icd_libs *icd_libs,
497 struct loader_extension_list *inst_exts);
498struct loader_icd *loader_get_icd_and_device(const VkDevice device,
499 struct loader_device **found_dev);
Jon Ashburn1530c342016-02-26 13:14:27 -0700500void loader_init_dispatch_dev_ext(struct loader_instance *inst,
501 struct loader_device *dev);
Jon Ashburn23d36b12016-02-02 17:47:28 -0700502void *loader_dev_ext_gpa(struct loader_instance *inst, const char *funcName);
503void *loader_get_dev_ext_trampoline(uint32_t index);
504struct loader_instance *loader_get_instance(const VkInstance instance);
Jon Ashburn1530c342016-02-26 13:14:27 -0700505struct loader_device *
506loader_add_logical_device(const struct loader_instance *inst,
507 struct loader_device **device_list);
Jon Ashburn23d36b12016-02-02 17:47:28 -0700508void loader_remove_logical_device(const struct loader_instance *inst,
509 struct loader_icd *icd,
510 struct loader_device *found_dev);
511VkResult
512loader_enable_instance_layers(struct loader_instance *inst,
513 const VkInstanceCreateInfo *pCreateInfo,
514 const struct loader_layer_list *instance_layers);
Jon Ashburndc6fcad2015-06-10 10:06:06 -0600515void loader_deactivate_instance_layers(struct loader_instance *instance);
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700516
Jon Ashburn23d36b12016-02-02 17:47:28 -0700517VkResult loader_create_instance_chain(const VkInstanceCreateInfo *pCreateInfo,
518 const VkAllocationCallbacks *pAllocator,
519 struct loader_instance *inst,
Jon Ashburn6e0a2132016-02-03 12:37:30 -0700520 VkInstance *created_instance);
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700521
Jon Ashburn23d36b12016-02-02 17:47:28 -0700522void loader_activate_instance_layer_extensions(struct loader_instance *inst,
523 VkInstance created_inst);
Jon Ashburn1530c342016-02-26 13:14:27 -0700524VkResult
525loader_enable_device_layers(const struct loader_instance *inst,
526 struct loader_icd *icd,
527 struct loader_layer_list *activated_layer_list,
528 const VkDeviceCreateInfo *pCreateInfo,
529 const struct loader_layer_list *device_layers);
Courtney Goeltzenleuchter7f5aafc2015-07-05 11:28:29 -0600530
Jon Ashburn014438f2016-03-01 19:51:07 -0700531VkResult loader_create_device_chain(const struct loader_physical_device *pd,
Jon Ashburn1530c342016-02-26 13:14:27 -0700532 const VkDeviceCreateInfo *pCreateInfo,
533 const VkAllocationCallbacks *pAllocator,
Jon Ashburn014438f2016-03-01 19:51:07 -0700534 const struct loader_instance *inst,
Jon Ashburn1530c342016-02-26 13:14:27 -0700535 struct loader_icd *icd,
536 struct loader_device *dev);
537VkResult loader_validate_device_extensions(
538 struct loader_physical_device *phys_dev,
539 const struct loader_layer_list *activated_device_layers,
Jon Ashburn014438f2016-03-01 19:51:07 -0700540 const struct loader_extension_list *icd_exts,
Jon Ashburn1530c342016-02-26 13:14:27 -0700541 const VkDeviceCreateInfo *pCreateInfo);
Courtney Goeltzenleuchter7f5aafc2015-07-05 11:28:29 -0600542
Jon Ashburn1530c342016-02-26 13:14:27 -0700543/* instance layer chain termination entrypoint definitions */
544VKAPI_ATTR VkResult VKAPI_CALL
545terminator_CreateInstance(const VkInstanceCreateInfo *pCreateInfo,
546 const VkAllocationCallbacks *pAllocator,
547 VkInstance *pInstance);
Jon Ashburn87d6aa92015-08-28 15:19:27 -0600548
Jon Ashburn1530c342016-02-26 13:14:27 -0700549VKAPI_ATTR void VKAPI_CALL
550terminator_DestroyInstance(VkInstance instance,
551 const VkAllocationCallbacks *pAllocator);
Jon Ashburn87d6aa92015-08-28 15:19:27 -0600552
Jon Ashburn1530c342016-02-26 13:14:27 -0700553VKAPI_ATTR VkResult VKAPI_CALL
554terminator_EnumeratePhysicalDevices(VkInstance instance,
555 uint32_t *pPhysicalDeviceCount,
556 VkPhysicalDevice *pPhysicalDevices);
557
558VKAPI_ATTR void VKAPI_CALL
559terminator_GetPhysicalDeviceFeatures(VkPhysicalDevice physicalDevice,
560 VkPhysicalDeviceFeatures *pFeatures);
561
562VKAPI_ATTR void VKAPI_CALL
563terminator_GetPhysicalDeviceFormatProperties(VkPhysicalDevice physicalDevice,
564 VkFormat format,
565 VkFormatProperties *pFormatInfo);
566
567VKAPI_ATTR VkResult VKAPI_CALL
568terminator_GetPhysicalDeviceImageFormatProperties(
569 VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type,
570 VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags,
571 VkImageFormatProperties *pImageFormatProperties);
572
573VKAPI_ATTR void VKAPI_CALL
574terminator_GetPhysicalDeviceSparseImageFormatProperties(
575 VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type,
576 VkSampleCountFlagBits samples, VkImageUsageFlags usage,
577 VkImageTiling tiling, uint32_t *pNumProperties,
578 VkSparseImageFormatProperties *pProperties);
579
580VKAPI_ATTR void VKAPI_CALL
581terminator_GetPhysicalDeviceProperties(VkPhysicalDevice physicalDevice,
582 VkPhysicalDeviceProperties *pProperties);
583
584VKAPI_ATTR VkResult VKAPI_CALL terminator_EnumerateDeviceExtensionProperties(
585 VkPhysicalDevice physicalDevice, const char *pLayerName, uint32_t *pCount,
586 VkExtensionProperties *pProperties);
587
588VKAPI_ATTR VkResult VKAPI_CALL
589terminator_EnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice,
590 uint32_t *pCount,
591 VkLayerProperties *pProperties);
592
593VKAPI_ATTR void VKAPI_CALL terminator_GetPhysicalDeviceQueueFamilyProperties(
594 VkPhysicalDevice physicalDevice, uint32_t *pCount,
595 VkQueueFamilyProperties *pProperties);
596
597VKAPI_ATTR void VKAPI_CALL terminator_GetPhysicalDeviceMemoryProperties(
598 VkPhysicalDevice physicalDevice,
599 VkPhysicalDeviceMemoryProperties *pProperties);
600
601VKAPI_ATTR VkResult VKAPI_CALL
602terminator_CreateDevice(VkPhysicalDevice gpu,
603 const VkDeviceCreateInfo *pCreateInfo,
604 const VkAllocationCallbacks *pAllocator,
605 VkDevice *pDevice);
Mark Lobodzinskie9f09ef2016-02-02 18:53:34 -0700606
Jon Ashburnf2b4e382016-02-10 20:50:19 -0700607VkStringErrorFlags vk_string_validate(const int max_length,
608 const char *char_array);
Mark Lobodzinskie9f09ef2016-02-02 18:53:34 -0700609
Chia-I Wu19300602014-08-04 08:03:57 +0800610#endif /* LOADER_H */