blob: 2c8946041ddc9f8b1cb24fc0a58224bc5339db04 [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 Confidential Information as defined by the Khronos
19 * Membership Agreement until designated non-confidential by Khronos, at which
20 * point this condition clause shall be removed.
21 *
22 * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Chia-I Wuc1e0f962014-08-04 08:03:57 +080023 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Jon Ashburn1c75aec2016-02-02 17:47:28 -070024 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
Chia-I Wud8ab1e62014-09-02 08:32:09 +080025 *
Jon Ashburn1c75aec2016-02-02 17:47:28 -070026 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
27 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
28 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE
29 * USE OR OTHER DEALINGS IN THE MATERIALS.
30 *
31 * Author: Jon Ashburn <jon@lunarg.com>
32 * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
Courtney Goeltzenleuchterb9ce3952015-10-30 11:14:30 -060033 * Author: Chia-I Wu <olvaffe@gmail.com>
34 * Author: Chia-I Wu <olv@lunarg.com>
Jon Ashburn1c75aec2016-02-02 17:47:28 -070035 * Author: Mark Lobodzinski <mark@LunarG.com>
Courtney Goeltzenleuchterb9ce3952015-10-30 11:14:30 -060036 *
Chia-I Wuc1e0f962014-08-04 08:03:57 +080037 */
38
39#ifndef LOADER_H
40#define LOADER_H
41
David Pinedoa5036622015-11-06 12:54:48 -070042#include <vulkan/vulkan.h>
Jon Ashburn3708e792015-11-06 11:02:40 -070043#include <vk_loader_platform.h>
Ian Elliottafaf1852015-11-17 17:29:40 -070044
Courtney Goeltzenleuchter725db942015-12-09 15:48:16 -070045#include <vulkan/vk_ext_debug_report.h>
Ian Elliotta77fed72015-11-18 14:57:08 -070046
David Pinedoa5036622015-11-06 12:54:48 -070047#include <vulkan/vk_layer.h>
48#include <vulkan/vk_icd.h>
Chia-I Wufe333ed2015-04-11 15:34:07 +080049#include <assert.h>
50
Chia-I Wuc1e0f962014-08-04 08:03:57 +080051#if defined(__GNUC__) && __GNUC__ >= 4
Jon Ashburn1c75aec2016-02-02 17:47:28 -070052#define LOADER_EXPORT __attribute__((visibility("default")))
Chia-I Wuc1e0f962014-08-04 08:03:57 +080053#elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)
Jon Ashburn1c75aec2016-02-02 17:47:28 -070054#define LOADER_EXPORT __attribute__((visibility("default")))
Chia-I Wuc1e0f962014-08-04 08:03:57 +080055#else
Jon Ashburn1c75aec2016-02-02 17:47:28 -070056#define LOADER_EXPORT
Chia-I Wuc1e0f962014-08-04 08:03:57 +080057#endif
58
Jon Ashburnb2379c52015-08-04 10:22:33 -060059#define MAX_STRING_SIZE 1024
Courtney Goeltzenleuchter44667cc2015-06-29 15:39:26 -060060#define VK_MAJOR(version) (version >> 22)
61#define VK_MINOR(version) ((version >> 12) & 0x3ff)
62#define VK_PATCH(version) (version & 0xfff)
Jon Ashburn13482452015-05-12 17:26:48 -060063
Jon Ashburn399c9162015-07-02 09:40:15 -060064enum layer_type {
Jon Ashburn9464e772015-07-02 16:10:32 -060065 VK_LAYER_TYPE_DEVICE_EXPLICIT = 0x1,
66 VK_LAYER_TYPE_INSTANCE_EXPLICIT = 0x2,
Jon Ashburn1c75aec2016-02-02 17:47:28 -070067 VK_LAYER_TYPE_GLOBAL_EXPLICIT =
68 0x3, // both instance and device layer, bitwise
Jon Ashburn9464e772015-07-02 16:10:32 -060069 VK_LAYER_TYPE_DEVICE_IMPLICIT = 0x4,
70 VK_LAYER_TYPE_INSTANCE_IMPLICIT = 0x8,
Jon Ashburn1c75aec2016-02-02 17:47:28 -070071 VK_LAYER_TYPE_GLOBAL_IMPLICIT =
72 0xc, // both instance and device layer, bitwise
Jon Ashburn399c9162015-07-02 09:40:15 -060073};
74
Mark Lobodzinski8d325802016-02-02 18:53:34 -070075
76typedef enum VkStringErrorFlagBits {
77 VK_STRING_ERROR_NONE = 0x00000000,
78 VK_STRING_ERROR_LENGTH = 0x00000001,
79 VK_STRING_ERROR_BAD_DATA = 0x00000002,
80} VkStringErrorFlagBits;
81typedef VkFlags VkStringErrorFlags;
82
83static const int MaxLoaderStringLength = 256;
84static const char UTF8_ONE_BYTE_CODE = 0xC0;
85static const char UTF8_ONE_BYTE_MASK = 0xE0;
86static const char UTF8_TWO_BYTE_CODE = 0xE0;
87static const char UTF8_TWO_BYTE_MASK = 0xF0;
88static const char UTF8_THREE_BYTE_CODE = 0xF0;
89static const char UTF8_THREE_BYTE_MASK = 0xF8;
90static const char UTF8_DATA_BYTE_CODE = 0x80;
91static const char UTF8_DATA_BYTE_MASK = 0xC0;
92
Jon Ashburn6b00b472015-12-10 08:51:10 -070093// form of all dynamic lists/arrays
94// only the list element should be changed
95struct loader_generic_list {
96 size_t capacity;
97 uint32_t count;
98 void *list;
99};
100
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600101struct loader_extension_list {
102 size_t capacity;
103 uint32_t count;
Jon Ashburnb7d327c2015-08-04 11:14:18 -0600104 VkExtensionProperties *list;
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600105};
106
Jon Ashburn92cdb012015-12-10 18:17:34 -0700107struct loader_dev_ext_props {
108 VkExtensionProperties props;
109 uint32_t entrypoint_count;
110 char **entrypoints;
111};
112
113struct loader_device_extension_list {
114 size_t capacity;
115 uint32_t count;
116 struct loader_dev_ext_props *list;
117};
118
Jon Ashburn399c9162015-07-02 09:40:15 -0600119struct loader_name_value {
Jon Ashburnb2379c52015-08-04 10:22:33 -0600120 char name[MAX_STRING_SIZE];
121 char value[MAX_STRING_SIZE];
Jon Ashburn399c9162015-07-02 09:40:15 -0600122};
123
124struct loader_lib_info {
Jon Ashburnb4c24232015-08-20 16:35:30 -0600125 char lib_name[MAX_STRING_SIZE];
Jon Ashburn399c9162015-07-02 09:40:15 -0600126 uint32_t ref_count;
127 loader_platform_dl_handle lib_handle;
128};
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600129
Jon Ashburn399c9162015-07-02 09:40:15 -0600130struct loader_layer_functions {
Jon Ashburnb2379c52015-08-04 10:22:33 -0600131 char str_gipa[MAX_STRING_SIZE];
132 char str_gdpa[MAX_STRING_SIZE];
Jon Ashburn399c9162015-07-02 09:40:15 -0600133 PFN_vkGetInstanceProcAddr get_instance_proc_addr;
134 PFN_vkGetDeviceProcAddr get_device_proc_addr;
135};
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600136
Jon Ashburn399c9162015-07-02 09:40:15 -0600137struct loader_layer_properties {
Courtney Goeltzenleuchter44667cc2015-06-29 15:39:26 -0600138 VkLayerProperties info;
Jon Ashburn399c9162015-07-02 09:40:15 -0600139 enum layer_type type;
Jon Ashburnb4c24232015-08-20 16:35:30 -0600140 char lib_name[MAX_STRING_SIZE];
Jon Ashburn399c9162015-07-02 09:40:15 -0600141 struct loader_layer_functions functions;
142 struct loader_extension_list instance_extension_list;
Jon Ashburn92cdb012015-12-10 18:17:34 -0700143 struct loader_device_extension_list device_extension_list;
Jon Ashburn399c9162015-07-02 09:40:15 -0600144 struct loader_name_value disable_env_var;
145 struct loader_name_value enable_env_var;
146};
147
148struct loader_layer_list {
149 size_t capacity;
150 uint32_t count;
151 struct loader_layer_properties *list;
Jon Ashburn13482452015-05-12 17:26:48 -0600152};
153
Courtney Goeltzenleuchter8aff3862015-07-05 12:53:31 -0600154struct loader_layer_library_list {
155 size_t capacity;
156 uint32_t count;
157 struct loader_lib_info *list;
158};
159
Jon Ashburn6cb69f42015-11-17 15:31:02 -0700160struct loader_dispatch_hash_list {
161 size_t capacity;
162 uint32_t count;
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700163 uint32_t *index; // index into the dev_ext dispatch table
Jon Ashburn6cb69f42015-11-17 15:31:02 -0700164};
165
166#define MAX_NUM_DEV_EXTS 250
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700167// loader_dispatch_hash_entry and loader_dev_ext_dispatch_table.DevExt have one
168// to one
Jon Ashburn6cb69f42015-11-17 15:31:02 -0700169// correspondence; one loader_dispatch_hash_entry for one DevExt dispatch entry.
170// Also have a one to one correspondence with functions in dev_ext_trampoline.c
171struct loader_dispatch_hash_entry {
172 char *func_name;
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700173 struct loader_dispatch_hash_list list; // to handle hashing collisions
Jon Ashburn6cb69f42015-11-17 15:31:02 -0700174};
175
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700176typedef void(VKAPI_PTR *PFN_vkDevExt)(VkDevice device);
Jon Ashburn6cb69f42015-11-17 15:31:02 -0700177struct loader_dev_ext_dispatch_table {
178 PFN_vkDevExt DevExt[MAX_NUM_DEV_EXTS];
179};
180
181struct loader_dev_dispatch_table {
182 VkLayerDispatchTable core_dispatch;
183 struct loader_dev_ext_dispatch_table ext_dispatch;
184};
185
Jon Ashburn10f4e822015-06-10 10:06:06 -0600186/* per CreateDevice structure */
187struct loader_device {
Jon Ashburn6cb69f42015-11-17 15:31:02 -0700188 struct loader_dev_dispatch_table loader_dispatch;
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700189 VkDevice device; // device object from the icd
Jon Ashburn10f4e822015-06-10 10:06:06 -0600190
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700191 uint32_t app_extension_count;
Jon Ashburn10f4e822015-06-10 10:06:06 -0600192 VkExtensionProperties *app_extension_props;
193
Courtney Goeltzenleuchter44667cc2015-06-29 15:39:26 -0600194 struct loader_layer_list activated_layer_list;
Jon Ashburn10f4e822015-06-10 10:06:06 -0600195
196 struct loader_device *next;
197};
198
Jon Ashburn392c5622015-06-10 16:11:42 -0600199/* per ICD structure */
Jon Ashburnebfa25e2015-05-15 15:09:35 -0600200struct loader_icd {
Jon Ashburnb4c24232015-08-20 16:35:30 -0600201 // pointers to find other structs
202 const struct loader_scanned_icds *this_icd_lib;
203 const struct loader_instance *this_instance;
Jon Ashburnebfa25e2015-05-15 15:09:35 -0600204
Jon Ashburn10f4e822015-06-10 10:06:06 -0600205 struct loader_device *logical_device_list;
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700206 VkInstance instance; // instance object from the icd
Jon Ashburnc89dd4a2015-05-18 13:20:15 -0600207 PFN_vkGetDeviceProcAddr GetDeviceProcAddr;
Jon Ashburnebfa25e2015-05-15 15:09:35 -0600208 PFN_vkDestroyInstance DestroyInstance;
209 PFN_vkEnumeratePhysicalDevices EnumeratePhysicalDevices;
Chris Forbes1c946ec2015-06-21 22:55:02 +1200210 PFN_vkGetPhysicalDeviceFeatures GetPhysicalDeviceFeatures;
Courtney Goeltzenleuchter2b6559e2015-07-12 12:52:09 -0600211 PFN_vkGetPhysicalDeviceFormatProperties GetPhysicalDeviceFormatProperties;
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700212 PFN_vkGetPhysicalDeviceImageFormatProperties
213 GetPhysicalDeviceImageFormatProperties;
Jon Ashburnebfa25e2015-05-15 15:09:35 -0600214 PFN_vkCreateDevice CreateDevice;
Tony Barbour4e657ba2015-06-24 16:06:58 -0600215 PFN_vkGetPhysicalDeviceProperties GetPhysicalDeviceProperties;
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700216 PFN_vkGetPhysicalDeviceQueueFamilyProperties
217 GetPhysicalDeviceQueueFamilyProperties;
Tony Barbour4e657ba2015-06-24 16:06:58 -0600218 PFN_vkGetPhysicalDeviceMemoryProperties GetPhysicalDeviceMemoryProperties;
Courtney Goeltzenleuchtere25064c2015-09-14 17:22:16 -0600219 PFN_vkEnumerateDeviceExtensionProperties EnumerateDeviceExtensionProperties;
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700220 PFN_vkGetPhysicalDeviceSparseImageFormatProperties
221 GetPhysicalDeviceSparseImageFormatProperties;
Courtney Goeltzenleuchter725db942015-12-09 15:48:16 -0700222 PFN_vkCreateDebugReportCallbackEXT CreateDebugReportCallbackEXT;
223 PFN_vkDestroyDebugReportCallbackEXT DestroyDebugReportCallbackEXT;
224 PFN_vkDebugReportMessageEXT DebugReportMessageEXT;
Ian Elliottec736342015-08-21 15:09:33 -0600225 PFN_vkGetPhysicalDeviceSurfaceSupportKHR GetPhysicalDeviceSurfaceSupportKHR;
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700226 PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR
227 GetPhysicalDeviceSurfaceCapabilitiesKHR;
Ian Elliottea666b22015-11-19 16:05:09 -0700228 PFN_vkGetPhysicalDeviceSurfaceFormatsKHR GetPhysicalDeviceSurfaceFormatsKHR;
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700229 PFN_vkGetPhysicalDeviceSurfacePresentModesKHR
230 GetPhysicalDeviceSurfacePresentModesKHR;
Ian Elliotte851dd62015-11-24 15:39:10 -0700231#ifdef VK_USE_PLATFORM_WIN32_KHR
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700232 PFN_vkGetPhysicalDeviceWin32PresentationSupportKHR
233 GetPhysicalDeviceWin32PresentationSupportKHR;
Ian Elliotte851dd62015-11-24 15:39:10 -0700234#endif
235#ifdef VK_USE_PLATFORM_MIR_KHR
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700236 PFN_vkGetPhysicalDeviceMirPresentationSupportKHR
237 GetPhysicalDeviceMirPresentvationSupportKHR;
Ian Elliotte851dd62015-11-24 15:39:10 -0700238#endif
239#ifdef VK_USE_PLATFORM_WAYLAND_KHR
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700240 PFN_vkGetPhysicalDeviceWaylandPresentationSupportKHR
241 GetPhysicalDeviceWaylandPresentationSupportKHR;
Ian Elliotte851dd62015-11-24 15:39:10 -0700242#endif
243#ifdef VK_USE_PLATFORM_XCB_KHR
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700244 PFN_vkGetPhysicalDeviceXcbPresentationSupportKHR
245 GetPhysicalDeviceXcbPresentationSupportKHR;
Ian Elliotte851dd62015-11-24 15:39:10 -0700246#endif
247#ifdef VK_USE_PLATFORM_XLIB_KHR
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700248 PFN_vkGetPhysicalDeviceXlibPresentationSupportKHR
249 GetPhysicalDeviceXlibPresentationSupportKHR;
Ian Elliotte851dd62015-11-24 15:39:10 -0700250#endif
Courtney Goeltzenleuchter44667cc2015-06-29 15:39:26 -0600251
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 Ashburn13482452015-05-12 17:26:48 -0600266 uint32_t total_gpu_count;
Jon Ashburn969caa42015-11-01 14:04:06 -0700267 struct loader_physical_device *phys_devs;
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600268 uint32_t total_icd_count;
Jon Ashburn13482452015-05-12 17:26:48 -0600269 struct loader_icd *icds;
270 struct loader_instance *next;
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700271 struct loader_extension_list ext_list; // icds and loaders extensions
Jon Ashburne0367472015-08-18 18:04:47 -0600272 struct loader_icd_libs icd_libs;
Jon Ashburnb4c24232015-08-20 16:35:30 -0600273 struct loader_layer_list instance_layer_list;
274 struct loader_layer_list device_layer_list;
Jon Ashburn6cb69f42015-11-17 15:31:02 -0700275 struct loader_dispatch_hash_entry disp_hash[MAX_NUM_DEV_EXTS];
Jon Ashburnb4c24232015-08-20 16:35:30 -0600276
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600277 struct loader_msg_callback_map_entry *icd_msg_callback_map;
278
Courtney Goeltzenleuchter44667cc2015-06-29 15:39:26 -0600279 struct loader_layer_list activated_layer_list;
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600280
Courtney Goeltzenleuchter0bd705c2016-01-08 12:18:43 -0700281 VkInstance instance;
282
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600283 bool debug_report_enabled;
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600284 VkLayerDbgFunctionNode *DbgFunctionHead;
Courtney Goeltzenleuchter71b454b2015-07-05 11:28:29 -0600285
Chia-I Wu227c8b32015-10-27 18:04:07 +0800286 VkAllocationCallbacks alloc_callbacks;
Ian Elliotted33eb72015-07-06 14:36:13 -0600287
Ian Elliott54cea232015-10-30 15:28:23 -0600288 bool wsi_surface_enabled;
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -0700289#ifdef VK_USE_PLATFORM_WIN32_KHR
Ian Elliott54cea232015-10-30 15:28:23 -0600290 bool wsi_win32_surface_enabled;
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -0700291#endif
292#ifdef VK_USE_PLATFORM_MIR_KHR
Ian Elliott54cea232015-10-30 15:28:23 -0600293 bool wsi_mir_surface_enabled;
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -0700294#endif
295#ifdef VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott54cea232015-10-30 15:28:23 -0600296 bool wsi_wayland_surface_enabled;
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -0700297#endif
298#ifdef VK_USE_PLATFORM_XCB_KHR
Ian Elliott54cea232015-10-30 15:28:23 -0600299 bool wsi_xcb_surface_enabled;
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -0700300#endif
301#ifdef VK_USE_PLATFORM_XLIB_KHR
Ian Elliott54cea232015-10-30 15:28:23 -0600302 bool wsi_xlib_surface_enabled;
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -0700303#endif
304#ifdef VK_USE_PLATFORM_ANDROID_KHR
305 bool wsi_android_surface_enabled;
306#endif
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600307};
308
Jon Ashburn969caa42015-11-01 14:04:06 -0700309/* per enumerated PhysicalDevice structure */
310struct loader_physical_device {
311 VkLayerInstanceDispatchTable *disp; // must be first entry in structure
312 struct loader_instance *this_instance;
313 struct loader_icd *this_icd;
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700314 VkPhysicalDevice phys_dev; // object from ICD
315 /*
316 * Fill in the cache of available device extensions from
317 * this physical device. This cache can be used during CreateDevice
318 */
Jon Ashburn969caa42015-11-01 14:04:06 -0700319 struct loader_extension_list device_extension_cache;
320};
321
Jon Ashburn13482452015-05-12 17:26:48 -0600322struct loader_struct {
323 struct loader_instance *instances;
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600324
325 unsigned int loaded_layer_lib_count;
Courtney Goeltzenleuchter452303a2015-10-07 09:00:34 -0600326 size_t loaded_layer_lib_capacity;
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600327 struct loader_lib_info *loaded_layer_lib_list;
Jon Ashburne0367472015-08-18 18:04:47 -0600328 // TODO add ref counting of ICD libraries
Jon Ashburn269b5922015-07-06 15:40:35 -0600329 // TODO use this struct loader_layer_library_list scanned_layer_libraries;
Jon Ashburne0367472015-08-18 18:04:47 -0600330 // TODO add list of icd libraries for ref counting them for closure
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600331};
332
333struct loader_scanned_icds {
334 char *lib_name;
335 loader_platform_dl_handle handle;
Jon Ashburn27109e82015-11-17 17:35:40 -0700336 uint32_t api_version;
Jon Ashburnc7ca48d2015-07-16 10:17:29 -0600337 PFN_vkGetInstanceProcAddr GetInstanceProcAddr;
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600338 PFN_vkCreateInstance CreateInstance;
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700339 PFN_vkEnumerateInstanceExtensionProperties
340 EnumerateInstanceExtensionProperties;
Jon Ashburn13482452015-05-12 17:26:48 -0600341};
342
Jon Ashburn399c9162015-07-02 09:40:15 -0600343static inline struct loader_instance *loader_instance(VkInstance instance) {
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700344 return (struct loader_instance *)instance;
Jon Ashburn399c9162015-07-02 09:40:15 -0600345}
346
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700347static inline void loader_set_dispatch(void *obj, const void *data) {
348 *((const void **)obj) = data;
Chia-I Wufe333ed2015-04-11 15:34:07 +0800349}
350
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700351static inline VkLayerDispatchTable *loader_get_dispatch(const void *obj) {
352 return *((VkLayerDispatchTable **)obj);
Chia-I Wufe333ed2015-04-11 15:34:07 +0800353}
354
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700355static inline struct loader_dev_dispatch_table *
356loader_get_dev_dispatch(const void *obj) {
357 return *((struct loader_dev_dispatch_table **)obj);
Jon Ashburn6cb69f42015-11-17 15:31:02 -0700358}
359
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700360static inline VkLayerInstanceDispatchTable *
361loader_get_instance_dispatch(const void *obj) {
362 return *((VkLayerInstanceDispatchTable **)obj);
Jon Ashburn13482452015-05-12 17:26:48 -0600363}
364
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700365static inline void loader_init_dispatch(void *obj, const void *data) {
Jon Ashburn167b2b12015-04-15 13:34:33 -0600366#ifdef DEBUG
Chia-I Wufe333ed2015-04-11 15:34:07 +0800367 assert(valid_loader_magic_value(obj) &&
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700368 "Incompatible ICD, first dword must be initialized to "
369 "ICD_LOADER_MAGIC. See loader/README.md for details.");
Jon Ashburn167b2b12015-04-15 13:34:33 -0600370#endif
Chia-I Wufe333ed2015-04-11 15:34:07 +0800371
Jon Ashburn62a54d12015-05-01 18:00:33 -0600372 loader_set_dispatch(obj, data);
Chia-I Wufe333ed2015-04-11 15:34:07 +0800373}
374
Jon Ashburn13482452015-05-12 17:26:48 -0600375/* global variables used across files */
376extern struct loader_struct loader;
Jon Ashburnb4dee9c2015-08-28 15:19:27 -0600377extern THREAD_LOCAL_DECL struct loader_instance *tls_instance;
Jon Ashburne0367472015-08-18 18:04:47 -0600378extern LOADER_PLATFORM_THREAD_ONCE_DEFINITION(once_init);
Jon Ashburn7e8d8b42015-05-29 13:15:39 -0600379extern loader_platform_thread_mutex loader_lock;
Jon Ashburn7d4d51c2015-09-22 13:11:00 -0600380extern loader_platform_thread_mutex loader_json_lock;
Jon Ashburn7e8d8b42015-05-29 13:15:39 -0600381extern const VkLayerInstanceDispatchTable instance_disp;
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 Ashburn1c75aec2016-02-02 17:47:28 -0700388bool compare_vk_extension_properties(const VkExtensionProperties *op1,
389 const VkExtensionProperties *op2);
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600390
Mark Lobodzinski8d325802016-02-02 18:53:34 -0700391VkResult loader_validate_layers(const struct loader_instance *inst,
392 const uint32_t layer_count,
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700393 const char *const *ppEnabledLayerNames,
394 const struct loader_layer_list *list);
Courtney Goeltzenleuchter76ece702015-07-06 17:45:08 -0600395
396VkResult loader_validate_instance_extensions(
Mark Lobodzinski8d325802016-02-02 18:53:34 -0700397 const struct loader_instance *inst,
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700398 const struct loader_extension_list *icd_exts,
399 const struct loader_layer_list *instance_layer,
400 const VkInstanceCreateInfo *pCreateInfo);
Courtney Goeltzenleuchter76ece702015-07-06 17:45:08 -0600401
Jon Ashburn13482452015-05-12 17:26:48 -0600402/* instance layer chain termination entrypoint definitions */
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700403VKAPI_ATTR VkResult VKAPI_CALL
404loader_CreateInstance(const VkInstanceCreateInfo *pCreateInfo,
405 const VkAllocationCallbacks *pAllocator,
406 VkInstance *pInstance);
Chia-I Wufe333ed2015-04-11 15:34:07 +0800407
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700408VKAPI_ATTR void VKAPI_CALL
409loader_DestroyInstance(VkInstance instance,
410 const VkAllocationCallbacks *pAllocator);
Jon Ashburn13482452015-05-12 17:26:48 -0600411
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700412VKAPI_ATTR VkResult VKAPI_CALL
413loader_EnumeratePhysicalDevices(VkInstance instance,
414 uint32_t *pPhysicalDeviceCount,
415 VkPhysicalDevice *pPhysicalDevices);
Chris Forbes1c946ec2015-06-21 22:55:02 +1200416
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700417VKAPI_ATTR void VKAPI_CALL
418loader_GetPhysicalDeviceFeatures(VkPhysicalDevice physicalDevice,
419 VkPhysicalDeviceFeatures *pFeatures);
Chris Forbes1c946ec2015-06-21 22:55:02 +1200420
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700421VKAPI_ATTR void VKAPI_CALL
422loader_GetPhysicalDeviceFormatProperties(VkPhysicalDevice physicalDevice,
423 VkFormat format,
424 VkFormatProperties *pFormatInfo);
Chris Forbes1c946ec2015-06-21 22:55:02 +1200425
Chia-I Wu2c56bb92015-11-06 06:42:02 +0800426VKAPI_ATTR VkResult VKAPI_CALL loader_GetPhysicalDeviceImageFormatProperties(
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700427 VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type,
428 VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags,
429 VkImageFormatProperties *pImageFormatProperties);
Jon Ashburn25c11452015-07-23 18:49:07 -0600430
Chia-I Wu2c56bb92015-11-06 06:42:02 +0800431VKAPI_ATTR void VKAPI_CALL loader_GetPhysicalDeviceSparseImageFormatProperties(
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700432 VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type,
433 VkSampleCountFlagBits samples, VkImageUsageFlags usage,
434 VkImageTiling tiling, uint32_t *pNumProperties,
435 VkSparseImageFormatProperties *pProperties);
Tony Barbour4e657ba2015-06-24 16:06:58 -0600436
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700437VKAPI_ATTR void VKAPI_CALL
438loader_GetPhysicalDeviceProperties(VkPhysicalDevice physicalDevice,
439 VkPhysicalDeviceProperties *pProperties);
Tony Barbour4e657ba2015-06-24 16:06:58 -0600440
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700441VKAPI_ATTR VkResult VKAPI_CALL
442loader_EnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice,
443 const char *pLayerName,
444 uint32_t *pCount,
445 VkExtensionProperties *pProperties);
Tony Barbour4e657ba2015-06-24 16:06:58 -0600446
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700447VKAPI_ATTR VkResult VKAPI_CALL
448loader_EnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice,
449 uint32_t *pCount,
450 VkLayerProperties *pProperties);
Tony Barbour4e657ba2015-06-24 16:06:58 -0600451
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700452VKAPI_ATTR void VKAPI_CALL loader_GetPhysicalDeviceQueueFamilyProperties(
453 VkPhysicalDevice physicalDevice, uint32_t *pCount,
454 VkQueueFamilyProperties *pProperties);
Tony Barbour4e657ba2015-06-24 16:06:58 -0600455
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700456VKAPI_ATTR void VKAPI_CALL loader_GetPhysicalDeviceMemoryProperties(
457 VkPhysicalDevice physicalDevice,
458 VkPhysicalDeviceMemoryProperties *pProperties);
Jon Ashburn7e8d8b42015-05-29 13:15:39 -0600459
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700460VKAPI_ATTR VkResult VKAPI_CALL
461loader_create_device_terminator(VkPhysicalDevice physicalDevice,
462 const VkDeviceCreateInfo *pCreateInfo,
463 const VkAllocationCallbacks *pAllocator,
464 VkDevice *pDevice);
Courtney Goeltzenleuchter0bd705c2016-01-08 12:18:43 -0700465
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700466VKAPI_ATTR VkResult VKAPI_CALL
467loader_CreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo *pCreateInfo,
468 const VkAllocationCallbacks *pAllocator, VkDevice *pDevice);
Jon Ashburn13482452015-05-12 17:26:48 -0600469
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600470/* helper function definitions */
Jon Ashburne0367472015-08-18 18:04:47 -0600471void loader_initialize(void);
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700472bool has_vk_extension_property_array(const VkExtensionProperties *vk_ext_prop,
473 const uint32_t count,
474 const VkExtensionProperties *ext_array);
475bool has_vk_extension_property(const VkExtensionProperties *vk_ext_prop,
476 const struct loader_extension_list *ext_list);
Jon Ashburn13482452015-05-12 17:26:48 -0600477
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700478VkResult loader_add_to_ext_list(const struct loader_instance *inst,
479 struct loader_extension_list *ext_list,
480 uint32_t prop_list_count,
481 const VkExtensionProperties *props);
482void loader_destroy_generic_list(const struct loader_instance *inst,
483 struct loader_generic_list *list);
484void loader_delete_layer_properties(const struct loader_instance *inst,
485 struct loader_layer_list *layer_list);
486void loader_add_to_layer_list(const struct loader_instance *inst,
487 struct loader_layer_list *list,
488 uint32_t prop_list_count,
489 const struct loader_layer_properties *props);
490void loader_scanned_icd_clear(const struct loader_instance *inst,
491 struct loader_icd_libs *icd_libs);
492void loader_icd_scan(const struct loader_instance *inst,
493 struct loader_icd_libs *icds);
494void loader_layer_scan(const struct loader_instance *inst,
495 struct loader_layer_list *instance_layers,
496 struct loader_layer_list *device_layers);
Jon Ashburne0367472015-08-18 18:04:47 -0600497void loader_get_icd_loader_instance_extensions(
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700498 const struct loader_instance *inst, struct loader_icd_libs *icd_libs,
499 struct loader_extension_list *inst_exts);
500struct loader_icd *loader_get_icd_and_device(const VkDevice device,
501 struct loader_device **found_dev);
502void *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);
505void loader_remove_logical_device(const struct loader_instance *inst,
506 struct loader_icd *icd,
507 struct loader_device *found_dev);
508VkResult
509loader_enable_instance_layers(struct loader_instance *inst,
510 const VkInstanceCreateInfo *pCreateInfo,
511 const struct loader_layer_list *instance_layers);
Jon Ashburn10f4e822015-06-10 10:06:06 -0600512void loader_deactivate_instance_layers(struct loader_instance *instance);
Courtney Goeltzenleuchter0bd705c2016-01-08 12:18:43 -0700513
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700514VkResult loader_create_instance_chain(const VkInstanceCreateInfo *pCreateInfo,
515 const VkAllocationCallbacks *pAllocator,
516 struct loader_instance *inst,
Jon Ashburnd1205a92016-02-03 12:37:30 -0700517 VkInstance *created_instance);
Courtney Goeltzenleuchter0bd705c2016-01-08 12:18:43 -0700518
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700519void loader_activate_instance_layer_extensions(struct loader_instance *inst,
520 VkInstance created_inst);
Courtney Goeltzenleuchter71b454b2015-07-05 11:28:29 -0600521
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700522void *loader_heap_alloc(const struct loader_instance *instance, size_t size,
523 VkSystemAllocationScope allocationScope);
Courtney Goeltzenleuchter71b454b2015-07-05 11:28:29 -0600524
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700525void loader_heap_free(const struct loader_instance *instance, void *pMemory);
Jon Ashburnb4dee9c2015-08-28 15:19:27 -0600526
527void *loader_tls_heap_alloc(size_t size);
528
Chia-I Wu227c8b32015-10-27 18:04:07 +0800529void loader_tls_heap_free(void *pMemory);
Mark Lobodzinski8d325802016-02-02 18:53:34 -0700530
531VkStringErrorFlags vk_string_validate(const int max_length, const char *char_array);
532
Chia-I Wuc1e0f962014-08-04 08:03:57 +0800533#endif /* LOADER_H */