blob: fe146890a674046e6f4f990fe99aef0599a467b6 [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>
Jon Ashburn3708e792015-11-06 11:02:40 -070039#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
Jon Ashburnd1eb3322016-02-10 20:59:26 -070085static const char std_validation_names[9][VK_MAX_EXTENSION_NAME_SIZE] = {
Jon Ashburnbcb9e372016-02-18 12:48:24 -070086 "VK_LAYER_GOOGLE_threading", "VK_LAYER_LUNARG_param_checker",
Jon Ashburnd1eb3322016-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 Ashburn6b00b472015-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 Goeltzenleuchter67146d02015-06-10 17:39:03 -0600100struct loader_extension_list {
101 size_t capacity;
102 uint32_t count;
Jon Ashburnb7d327c2015-08-04 11:14:18 -0600103 VkExtensionProperties *list;
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600104};
105
Jon Ashburn92cdb012015-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 Ashburn399c9162015-07-02 09:40:15 -0600118struct loader_name_value {
Jon Ashburnb2379c52015-08-04 10:22:33 -0600119 char name[MAX_STRING_SIZE];
120 char value[MAX_STRING_SIZE];
Jon Ashburn399c9162015-07-02 09:40:15 -0600121};
122
123struct loader_lib_info {
Jon Ashburnb4c24232015-08-20 16:35:30 -0600124 char lib_name[MAX_STRING_SIZE];
Jon Ashburn399c9162015-07-02 09:40:15 -0600125 uint32_t ref_count;
126 loader_platform_dl_handle lib_handle;
127};
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600128
Jon Ashburn399c9162015-07-02 09:40:15 -0600129struct loader_layer_functions {
Jon Ashburnb2379c52015-08-04 10:22:33 -0600130 char str_gipa[MAX_STRING_SIZE];
131 char str_gdpa[MAX_STRING_SIZE];
Jon Ashburn399c9162015-07-02 09:40:15 -0600132 PFN_vkGetInstanceProcAddr get_instance_proc_addr;
133 PFN_vkGetDeviceProcAddr get_device_proc_addr;
134};
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600135
Jon Ashburn399c9162015-07-02 09:40:15 -0600136struct loader_layer_properties {
Courtney Goeltzenleuchter44667cc2015-06-29 15:39:26 -0600137 VkLayerProperties info;
Jon Ashburn399c9162015-07-02 09:40:15 -0600138 enum layer_type type;
Jon Ashburnb4c24232015-08-20 16:35:30 -0600139 char lib_name[MAX_STRING_SIZE];
Jon Ashburn399c9162015-07-02 09:40:15 -0600140 struct loader_layer_functions functions;
141 struct loader_extension_list instance_extension_list;
Jon Ashburn92cdb012015-12-10 18:17:34 -0700142 struct loader_device_extension_list device_extension_list;
Jon Ashburn399c9162015-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 Ashburn13482452015-05-12 17:26:48 -0600151};
152
Courtney Goeltzenleuchter8aff3862015-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 Ashburn6cb69f42015-11-17 15:31:02 -0700159struct loader_dispatch_hash_list {
160 size_t capacity;
161 uint32_t count;
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700162 uint32_t *index; // index into the dev_ext dispatch table
Jon Ashburn6cb69f42015-11-17 15:31:02 -0700163};
164
165#define MAX_NUM_DEV_EXTS 250
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700166// loader_dispatch_hash_entry and loader_dev_ext_dispatch_table.DevExt have one
167// to one
Jon Ashburn6cb69f42015-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 Ashburn1c75aec2016-02-02 17:47:28 -0700172 struct loader_dispatch_hash_list list; // to handle hashing collisions
Jon Ashburn6cb69f42015-11-17 15:31:02 -0700173};
174
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700175typedef void(VKAPI_PTR *PFN_vkDevExt)(VkDevice device);
Jon Ashburn6cb69f42015-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 Ashburn10f4e822015-06-10 10:06:06 -0600185/* per CreateDevice structure */
186struct loader_device {
Jon Ashburn6cb69f42015-11-17 15:31:02 -0700187 struct loader_dev_dispatch_table loader_dispatch;
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700188 VkDevice device; // device object from the icd
Jon Ashburn10f4e822015-06-10 10:06:06 -0600189
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700190 uint32_t app_extension_count;
Jon Ashburn10f4e822015-06-10 10:06:06 -0600191 VkExtensionProperties *app_extension_props;
192
Courtney Goeltzenleuchter44667cc2015-06-29 15:39:26 -0600193 struct loader_layer_list activated_layer_list;
Jon Ashburn10f4e822015-06-10 10:06:06 -0600194
195 struct loader_device *next;
196};
197
Jon Ashburn392c5622015-06-10 16:11:42 -0600198/* per ICD structure */
Jon Ashburnebfa25e2015-05-15 15:09:35 -0600199struct loader_icd {
Jon Ashburnb4c24232015-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 Ashburnebfa25e2015-05-15 15:09:35 -0600203
Jon Ashburn10f4e822015-06-10 10:06:06 -0600204 struct loader_device *logical_device_list;
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700205 VkInstance instance; // instance object from the icd
Jon Ashburnc89dd4a2015-05-18 13:20:15 -0600206 PFN_vkGetDeviceProcAddr GetDeviceProcAddr;
Jon Ashburnebfa25e2015-05-15 15:09:35 -0600207 PFN_vkDestroyInstance DestroyInstance;
208 PFN_vkEnumeratePhysicalDevices EnumeratePhysicalDevices;
Chris Forbes1c946ec2015-06-21 22:55:02 +1200209 PFN_vkGetPhysicalDeviceFeatures GetPhysicalDeviceFeatures;
Courtney Goeltzenleuchter2b6559e2015-07-12 12:52:09 -0600210 PFN_vkGetPhysicalDeviceFormatProperties GetPhysicalDeviceFormatProperties;
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700211 PFN_vkGetPhysicalDeviceImageFormatProperties
212 GetPhysicalDeviceImageFormatProperties;
Jon Ashburnebfa25e2015-05-15 15:09:35 -0600213 PFN_vkCreateDevice CreateDevice;
Tony Barbour4e657ba2015-06-24 16:06:58 -0600214 PFN_vkGetPhysicalDeviceProperties GetPhysicalDeviceProperties;
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700215 PFN_vkGetPhysicalDeviceQueueFamilyProperties
216 GetPhysicalDeviceQueueFamilyProperties;
Tony Barbour4e657ba2015-06-24 16:06:58 -0600217 PFN_vkGetPhysicalDeviceMemoryProperties GetPhysicalDeviceMemoryProperties;
Courtney Goeltzenleuchtere25064c2015-09-14 17:22:16 -0600218 PFN_vkEnumerateDeviceExtensionProperties EnumerateDeviceExtensionProperties;
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700219 PFN_vkGetPhysicalDeviceSparseImageFormatProperties
220 GetPhysicalDeviceSparseImageFormatProperties;
Courtney Goeltzenleuchter725db942015-12-09 15:48:16 -0700221 PFN_vkCreateDebugReportCallbackEXT CreateDebugReportCallbackEXT;
222 PFN_vkDestroyDebugReportCallbackEXT DestroyDebugReportCallbackEXT;
223 PFN_vkDebugReportMessageEXT DebugReportMessageEXT;
Ian Elliottec736342015-08-21 15:09:33 -0600224 PFN_vkGetPhysicalDeviceSurfaceSupportKHR GetPhysicalDeviceSurfaceSupportKHR;
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700225 PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR
226 GetPhysicalDeviceSurfaceCapabilitiesKHR;
Ian Elliottea666b22015-11-19 16:05:09 -0700227 PFN_vkGetPhysicalDeviceSurfaceFormatsKHR GetPhysicalDeviceSurfaceFormatsKHR;
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700228 PFN_vkGetPhysicalDeviceSurfacePresentModesKHR
229 GetPhysicalDeviceSurfacePresentModesKHR;
Ian Elliotte851dd62015-11-24 15:39:10 -0700230#ifdef VK_USE_PLATFORM_WIN32_KHR
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700231 PFN_vkGetPhysicalDeviceWin32PresentationSupportKHR
232 GetPhysicalDeviceWin32PresentationSupportKHR;
Ian Elliotte851dd62015-11-24 15:39:10 -0700233#endif
234#ifdef VK_USE_PLATFORM_MIR_KHR
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700235 PFN_vkGetPhysicalDeviceMirPresentationSupportKHR
236 GetPhysicalDeviceMirPresentvationSupportKHR;
Ian Elliotte851dd62015-11-24 15:39:10 -0700237#endif
238#ifdef VK_USE_PLATFORM_WAYLAND_KHR
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700239 PFN_vkGetPhysicalDeviceWaylandPresentationSupportKHR
240 GetPhysicalDeviceWaylandPresentationSupportKHR;
Ian Elliotte851dd62015-11-24 15:39:10 -0700241#endif
242#ifdef VK_USE_PLATFORM_XCB_KHR
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700243 PFN_vkGetPhysicalDeviceXcbPresentationSupportKHR
244 GetPhysicalDeviceXcbPresentationSupportKHR;
Ian Elliotte851dd62015-11-24 15:39:10 -0700245#endif
246#ifdef VK_USE_PLATFORM_XLIB_KHR
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700247 PFN_vkGetPhysicalDeviceXlibPresentationSupportKHR
248 GetPhysicalDeviceXlibPresentationSupportKHR;
Ian Elliotte851dd62015-11-24 15:39:10 -0700249#endif
Courtney Goeltzenleuchter44667cc2015-06-29 15:39:26 -0600250
Jon Ashburn10f4e822015-06-10 10:06:06 -0600251 struct loader_icd *next;
Jon Ashburnebfa25e2015-05-15 15:09:35 -0600252};
253
Jon Ashburne0367472015-08-18 18:04:47 -0600254/* per ICD library structure */
255struct loader_icd_libs {
256 size_t capacity;
257 uint32_t count;
258 struct loader_scanned_icds *list;
259};
260
Jon Ashburn392c5622015-06-10 16:11:42 -0600261/* per instance structure */
Jon Ashburn13482452015-05-12 17:26:48 -0600262struct loader_instance {
Jon Ashburnebfa25e2015-05-15 15:09:35 -0600263 VkLayerInstanceDispatchTable *disp; // must be first entry in structure
264
Jon Ashburn13482452015-05-12 17:26:48 -0600265 uint32_t total_gpu_count;
Jon Ashburn969caa42015-11-01 14:04:06 -0700266 struct loader_physical_device *phys_devs;
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600267 uint32_t total_icd_count;
Jon Ashburn13482452015-05-12 17:26:48 -0600268 struct loader_icd *icds;
269 struct loader_instance *next;
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700270 struct loader_extension_list ext_list; // icds and loaders extensions
Jon Ashburne0367472015-08-18 18:04:47 -0600271 struct loader_icd_libs icd_libs;
Jon Ashburnb4c24232015-08-20 16:35:30 -0600272 struct loader_layer_list instance_layer_list;
273 struct loader_layer_list device_layer_list;
Jon Ashburn6cb69f42015-11-17 15:31:02 -0700274 struct loader_dispatch_hash_entry disp_hash[MAX_NUM_DEV_EXTS];
Jon Ashburnb4c24232015-08-20 16:35:30 -0600275
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600276 struct loader_msg_callback_map_entry *icd_msg_callback_map;
277
Courtney Goeltzenleuchter44667cc2015-06-29 15:39:26 -0600278 struct loader_layer_list activated_layer_list;
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600279
Courtney Goeltzenleuchter0bd705c2016-01-08 12:18:43 -0700280 VkInstance instance;
281
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600282 bool debug_report_enabled;
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600283 VkLayerDbgFunctionNode *DbgFunctionHead;
Courtney Goeltzenleuchter71b454b2015-07-05 11:28:29 -0600284
Chia-I Wu227c8b32015-10-27 18:04:07 +0800285 VkAllocationCallbacks alloc_callbacks;
Ian Elliotted33eb72015-07-06 14:36:13 -0600286
Ian Elliott54cea232015-10-30 15:28:23 -0600287 bool wsi_surface_enabled;
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -0700288#ifdef VK_USE_PLATFORM_WIN32_KHR
Ian Elliott54cea232015-10-30 15:28:23 -0600289 bool wsi_win32_surface_enabled;
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -0700290#endif
291#ifdef VK_USE_PLATFORM_MIR_KHR
Ian Elliott54cea232015-10-30 15:28:23 -0600292 bool wsi_mir_surface_enabled;
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -0700293#endif
294#ifdef VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott54cea232015-10-30 15:28:23 -0600295 bool wsi_wayland_surface_enabled;
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -0700296#endif
297#ifdef VK_USE_PLATFORM_XCB_KHR
Ian Elliott54cea232015-10-30 15:28:23 -0600298 bool wsi_xcb_surface_enabled;
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -0700299#endif
300#ifdef VK_USE_PLATFORM_XLIB_KHR
Ian Elliott54cea232015-10-30 15:28:23 -0600301 bool wsi_xlib_surface_enabled;
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -0700302#endif
303#ifdef VK_USE_PLATFORM_ANDROID_KHR
304 bool wsi_android_surface_enabled;
305#endif
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600306};
307
Jon Ashburn969caa42015-11-01 14:04:06 -0700308/* per enumerated PhysicalDevice structure */
309struct loader_physical_device {
310 VkLayerInstanceDispatchTable *disp; // must be first entry in structure
311 struct loader_instance *this_instance;
312 struct loader_icd *this_icd;
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700313 VkPhysicalDevice phys_dev; // object from ICD
314 /*
315 * Fill in the cache of available device extensions from
316 * this physical device. This cache can be used during CreateDevice
317 */
Jon Ashburn969caa42015-11-01 14:04:06 -0700318 struct loader_extension_list device_extension_cache;
319};
320
Jon Ashburn13482452015-05-12 17:26:48 -0600321struct loader_struct {
322 struct loader_instance *instances;
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600323
324 unsigned int loaded_layer_lib_count;
Courtney Goeltzenleuchter452303a2015-10-07 09:00:34 -0600325 size_t loaded_layer_lib_capacity;
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600326 struct loader_lib_info *loaded_layer_lib_list;
Jon Ashburne0367472015-08-18 18:04:47 -0600327 // TODO add ref counting of ICD libraries
Jon Ashburn269b5922015-07-06 15:40:35 -0600328 // TODO use this struct loader_layer_library_list scanned_layer_libraries;
Jon Ashburne0367472015-08-18 18:04:47 -0600329 // TODO add list of icd libraries for ref counting them for closure
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600330};
331
332struct loader_scanned_icds {
333 char *lib_name;
334 loader_platform_dl_handle handle;
Jon Ashburn27109e82015-11-17 17:35:40 -0700335 uint32_t api_version;
Jon Ashburnc7ca48d2015-07-16 10:17:29 -0600336 PFN_vkGetInstanceProcAddr GetInstanceProcAddr;
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600337 PFN_vkCreateInstance CreateInstance;
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700338 PFN_vkEnumerateInstanceExtensionProperties
339 EnumerateInstanceExtensionProperties;
Jon Ashburn13482452015-05-12 17:26:48 -0600340};
341
Jon Ashburn399c9162015-07-02 09:40:15 -0600342static inline struct loader_instance *loader_instance(VkInstance instance) {
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700343 return (struct loader_instance *)instance;
Jon Ashburn399c9162015-07-02 09:40:15 -0600344}
345
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700346static inline void loader_set_dispatch(void *obj, const void *data) {
347 *((const void **)obj) = data;
Chia-I Wufe333ed2015-04-11 15:34:07 +0800348}
349
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700350static inline VkLayerDispatchTable *loader_get_dispatch(const void *obj) {
351 return *((VkLayerDispatchTable **)obj);
Chia-I Wufe333ed2015-04-11 15:34:07 +0800352}
353
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700354static inline struct loader_dev_dispatch_table *
355loader_get_dev_dispatch(const void *obj) {
356 return *((struct loader_dev_dispatch_table **)obj);
Jon Ashburn6cb69f42015-11-17 15:31:02 -0700357}
358
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700359static inline VkLayerInstanceDispatchTable *
360loader_get_instance_dispatch(const void *obj) {
361 return *((VkLayerInstanceDispatchTable **)obj);
Jon Ashburn13482452015-05-12 17:26:48 -0600362}
363
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700364static inline void loader_init_dispatch(void *obj, const void *data) {
Jon Ashburn167b2b12015-04-15 13:34:33 -0600365#ifdef DEBUG
Chia-I Wufe333ed2015-04-11 15:34:07 +0800366 assert(valid_loader_magic_value(obj) &&
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700367 "Incompatible ICD, first dword must be initialized to "
368 "ICD_LOADER_MAGIC. See loader/README.md for details.");
Jon Ashburn167b2b12015-04-15 13:34:33 -0600369#endif
Chia-I Wufe333ed2015-04-11 15:34:07 +0800370
Jon Ashburn62a54d12015-05-01 18:00:33 -0600371 loader_set_dispatch(obj, data);
Chia-I Wufe333ed2015-04-11 15:34:07 +0800372}
373
Jon Ashburn13482452015-05-12 17:26:48 -0600374/* global variables used across files */
375extern struct loader_struct loader;
Jon Ashburnb4dee9c2015-08-28 15:19:27 -0600376extern THREAD_LOCAL_DECL struct loader_instance *tls_instance;
Jon Ashburne0367472015-08-18 18:04:47 -0600377extern LOADER_PLATFORM_THREAD_ONCE_DEFINITION(once_init);
Jon Ashburn7e8d8b42015-05-29 13:15:39 -0600378extern loader_platform_thread_mutex loader_lock;
Jon Ashburn7d4d51c2015-09-22 13:11:00 -0600379extern loader_platform_thread_mutex loader_json_lock;
Jon Ashburn7e8d8b42015-05-29 13:15:39 -0600380extern const VkLayerInstanceDispatchTable instance_disp;
Jon Ashburnd1eb3322016-02-10 20:59:26 -0700381extern const char *std_validation_str;
Jon Ashburn37e7f972015-04-06 10:58:22 -0600382
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600383struct loader_msg_callback_map_entry {
Courtney Goeltzenleuchter725db942015-12-09 15:48:16 -0700384 VkDebugReportCallbackEXT icd_obj;
385 VkDebugReportCallbackEXT loader_obj;
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600386};
387
Jon Ashburnc4e9ae62016-02-26 13:14:27 -0700388/* helper function definitions */
389void *loader_heap_alloc(const struct loader_instance *instance, size_t size,
390 VkSystemAllocationScope allocationScope);
391
392void loader_heap_free(const struct loader_instance *instance, void *pMemory);
393
394void *loader_tls_heap_alloc(size_t size);
395
396void loader_tls_heap_free(void *pMemory);
397
Jon Ashburn663f8312016-02-12 08:20:06 -0700398void loader_log(const struct loader_instance *inst, VkFlags msg_type,
Jon Ashburnc4e9ae62016-02-26 13:14:27 -0700399 int32_t msg_code, const char *format, ...);
Jon Ashburn663f8312016-02-12 08:20:06 -0700400
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700401bool compare_vk_extension_properties(const VkExtensionProperties *op1,
402 const VkExtensionProperties *op2);
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600403
Mark Lobodzinski8d325802016-02-02 18:53:34 -0700404VkResult loader_validate_layers(const struct loader_instance *inst,
405 const uint32_t layer_count,
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700406 const char *const *ppEnabledLayerNames,
407 const struct loader_layer_list *list);
Courtney Goeltzenleuchter76ece702015-07-06 17:45:08 -0600408
409VkResult loader_validate_instance_extensions(
Mark Lobodzinski8d325802016-02-02 18:53:34 -0700410 const struct loader_instance *inst,
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700411 const struct loader_extension_list *icd_exts,
412 const struct loader_layer_list *instance_layer,
413 const VkInstanceCreateInfo *pCreateInfo);
Courtney Goeltzenleuchter76ece702015-07-06 17:45:08 -0600414
Jon Ashburne0367472015-08-18 18:04:47 -0600415void loader_initialize(void);
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700416bool has_vk_extension_property_array(const VkExtensionProperties *vk_ext_prop,
417 const uint32_t count,
418 const VkExtensionProperties *ext_array);
419bool has_vk_extension_property(const VkExtensionProperties *vk_ext_prop,
420 const struct loader_extension_list *ext_list);
Jon Ashburn13482452015-05-12 17:26:48 -0600421
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700422VkResult loader_add_to_ext_list(const struct loader_instance *inst,
423 struct loader_extension_list *ext_list,
424 uint32_t prop_list_count,
425 const VkExtensionProperties *props);
Jon Ashburnc4e9ae62016-02-26 13:14:27 -0700426VkResult loader_add_device_extensions(const struct loader_instance *inst,
427 struct loader_icd *icd,
428 VkPhysicalDevice physical_device,
429 const char *lib_name,
430 struct loader_extension_list *ext_list);
431bool loader_init_generic_list(const struct loader_instance *inst,
432 struct loader_generic_list *list_info,
433 size_t element_size);
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700434void loader_destroy_generic_list(const struct loader_instance *inst,
435 struct loader_generic_list *list);
Jon Ashburnc4e9ae62016-02-26 13:14:27 -0700436void loader_destroy_layer_list(const struct loader_instance *inst,
437 struct loader_layer_list *layer_list);
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700438void loader_delete_layer_properties(const struct loader_instance *inst,
439 struct loader_layer_list *layer_list);
Jon Ashburnd1eb3322016-02-10 20:59:26 -0700440void loader_expand_layer_names(
441 const struct loader_instance *inst, const char *key_name,
442 uint32_t expand_count,
443 const char expand_names[][VK_MAX_EXTENSION_NAME_SIZE],
444 uint32_t *layer_count, char ***ppp_layer_names);
Jon Ashburn31efe262016-02-11 18:59:43 -0700445void loader_unexpand_dev_layer_names(const struct loader_instance *inst,
446 uint32_t layer_count, char **layer_names,
447 char **layer_ptr,
Jon Ashburnd1eb3322016-02-10 20:59:26 -0700448 const VkDeviceCreateInfo *pCreateInfo);
Jon Ashburn31efe262016-02-11 18:59:43 -0700449void loader_unexpand_inst_layer_names(const struct loader_instance *inst,
450 uint32_t layer_count, char **layer_names,
451 char **layer_ptr,
Jon Ashburnd1eb3322016-02-10 20:59:26 -0700452 const VkInstanceCreateInfo *pCreateInfo);
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700453void loader_add_to_layer_list(const struct loader_instance *inst,
454 struct loader_layer_list *list,
455 uint32_t prop_list_count,
456 const struct loader_layer_properties *props);
457void loader_scanned_icd_clear(const struct loader_instance *inst,
458 struct loader_icd_libs *icd_libs);
459void loader_icd_scan(const struct loader_instance *inst,
460 struct loader_icd_libs *icds);
461void loader_layer_scan(const struct loader_instance *inst,
462 struct loader_layer_list *instance_layers,
463 struct loader_layer_list *device_layers);
Jon Ashburne0367472015-08-18 18:04:47 -0600464void loader_get_icd_loader_instance_extensions(
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700465 const struct loader_instance *inst, struct loader_icd_libs *icd_libs,
466 struct loader_extension_list *inst_exts);
Jon Ashburnc4e9ae62016-02-26 13:14:27 -0700467struct loader_physical_device *
468loader_get_physical_device(const VkPhysicalDevice physdev);
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700469struct loader_icd *loader_get_icd_and_device(const VkDevice device,
470 struct loader_device **found_dev);
Jon Ashburnc4e9ae62016-02-26 13:14:27 -0700471void loader_init_dispatch_dev_ext(struct loader_instance *inst,
472 struct loader_device *dev);
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700473void *loader_dev_ext_gpa(struct loader_instance *inst, const char *funcName);
474void *loader_get_dev_ext_trampoline(uint32_t index);
475struct loader_instance *loader_get_instance(const VkInstance instance);
Jon Ashburnc4e9ae62016-02-26 13:14:27 -0700476struct loader_device *
477loader_add_logical_device(const struct loader_instance *inst,
478 struct loader_device **device_list);
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700479void loader_remove_logical_device(const struct loader_instance *inst,
480 struct loader_icd *icd,
481 struct loader_device *found_dev);
482VkResult
483loader_enable_instance_layers(struct loader_instance *inst,
484 const VkInstanceCreateInfo *pCreateInfo,
485 const struct loader_layer_list *instance_layers);
Jon Ashburn10f4e822015-06-10 10:06:06 -0600486void loader_deactivate_instance_layers(struct loader_instance *instance);
Courtney Goeltzenleuchter0bd705c2016-01-08 12:18:43 -0700487
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700488VkResult loader_create_instance_chain(const VkInstanceCreateInfo *pCreateInfo,
489 const VkAllocationCallbacks *pAllocator,
490 struct loader_instance *inst,
Jon Ashburnd1205a92016-02-03 12:37:30 -0700491 VkInstance *created_instance);
Courtney Goeltzenleuchter0bd705c2016-01-08 12:18:43 -0700492
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700493void loader_activate_instance_layer_extensions(struct loader_instance *inst,
494 VkInstance created_inst);
Jon Ashburnc4e9ae62016-02-26 13:14:27 -0700495VkResult
496loader_enable_device_layers(const struct loader_instance *inst,
497 struct loader_icd *icd,
498 struct loader_layer_list *activated_layer_list,
499 const VkDeviceCreateInfo *pCreateInfo,
500 const struct loader_layer_list *device_layers);
Courtney Goeltzenleuchter71b454b2015-07-05 11:28:29 -0600501
Jon Ashburnc4e9ae62016-02-26 13:14:27 -0700502VkResult loader_create_device_chain(VkPhysicalDevice physicalDevice,
503 const VkDeviceCreateInfo *pCreateInfo,
504 const VkAllocationCallbacks *pAllocator,
505 struct loader_instance *inst,
506 struct loader_icd *icd,
507 struct loader_device *dev);
508VkResult loader_validate_device_extensions(
509 struct loader_physical_device *phys_dev,
510 const struct loader_layer_list *activated_device_layers,
511 const VkDeviceCreateInfo *pCreateInfo);
Courtney Goeltzenleuchter71b454b2015-07-05 11:28:29 -0600512
Jon Ashburnc4e9ae62016-02-26 13:14:27 -0700513/* instance layer chain termination entrypoint definitions */
514VKAPI_ATTR VkResult VKAPI_CALL
515terminator_CreateInstance(const VkInstanceCreateInfo *pCreateInfo,
516 const VkAllocationCallbacks *pAllocator,
517 VkInstance *pInstance);
Jon Ashburnb4dee9c2015-08-28 15:19:27 -0600518
Jon Ashburnc4e9ae62016-02-26 13:14:27 -0700519VKAPI_ATTR void VKAPI_CALL
520terminator_DestroyInstance(VkInstance instance,
521 const VkAllocationCallbacks *pAllocator);
Jon Ashburnb4dee9c2015-08-28 15:19:27 -0600522
Jon Ashburnc4e9ae62016-02-26 13:14:27 -0700523VKAPI_ATTR VkResult VKAPI_CALL
524terminator_EnumeratePhysicalDevices(VkInstance instance,
525 uint32_t *pPhysicalDeviceCount,
526 VkPhysicalDevice *pPhysicalDevices);
527
528VKAPI_ATTR void VKAPI_CALL
529terminator_GetPhysicalDeviceFeatures(VkPhysicalDevice physicalDevice,
530 VkPhysicalDeviceFeatures *pFeatures);
531
532VKAPI_ATTR void VKAPI_CALL
533terminator_GetPhysicalDeviceFormatProperties(VkPhysicalDevice physicalDevice,
534 VkFormat format,
535 VkFormatProperties *pFormatInfo);
536
537VKAPI_ATTR VkResult VKAPI_CALL
538terminator_GetPhysicalDeviceImageFormatProperties(
539 VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type,
540 VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags,
541 VkImageFormatProperties *pImageFormatProperties);
542
543VKAPI_ATTR void VKAPI_CALL
544terminator_GetPhysicalDeviceSparseImageFormatProperties(
545 VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type,
546 VkSampleCountFlagBits samples, VkImageUsageFlags usage,
547 VkImageTiling tiling, uint32_t *pNumProperties,
548 VkSparseImageFormatProperties *pProperties);
549
550VKAPI_ATTR void VKAPI_CALL
551terminator_GetPhysicalDeviceProperties(VkPhysicalDevice physicalDevice,
552 VkPhysicalDeviceProperties *pProperties);
553
554VKAPI_ATTR VkResult VKAPI_CALL terminator_EnumerateDeviceExtensionProperties(
555 VkPhysicalDevice physicalDevice, const char *pLayerName, uint32_t *pCount,
556 VkExtensionProperties *pProperties);
557
558VKAPI_ATTR VkResult VKAPI_CALL
559terminator_EnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice,
560 uint32_t *pCount,
561 VkLayerProperties *pProperties);
562
563VKAPI_ATTR void VKAPI_CALL terminator_GetPhysicalDeviceQueueFamilyProperties(
564 VkPhysicalDevice physicalDevice, uint32_t *pCount,
565 VkQueueFamilyProperties *pProperties);
566
567VKAPI_ATTR void VKAPI_CALL terminator_GetPhysicalDeviceMemoryProperties(
568 VkPhysicalDevice physicalDevice,
569 VkPhysicalDeviceMemoryProperties *pProperties);
570
571VKAPI_ATTR VkResult VKAPI_CALL
572terminator_CreateDevice(VkPhysicalDevice gpu,
573 const VkDeviceCreateInfo *pCreateInfo,
574 const VkAllocationCallbacks *pAllocator,
575 VkDevice *pDevice);
Mark Lobodzinski8d325802016-02-02 18:53:34 -0700576
Jon Ashburnb1cdf2e2016-02-10 20:50:19 -0700577VkStringErrorFlags vk_string_validate(const int max_length,
578 const char *char_array);
Mark Lobodzinski8d325802016-02-02 18:53:34 -0700579
Chia-I Wuc1e0f962014-08-04 08:03:57 +0800580#endif /* LOADER_H */