blob: 72639eb0cc2dd79512f3c37f06aff1fa88029191 [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
Ian Elliottba042332015-11-18 14:57:08 -070041
David Pinedo9316d3b2015-11-06 12:54:48 -070042#include <vulkan/vk_layer.h>
43#include <vulkan/vk_icd.h>
Chia-I Wu5291c762015-04-11 15:34:07 +080044#include <assert.h>
45
Chia-I Wu19300602014-08-04 08:03:57 +080046#if defined(__GNUC__) && __GNUC__ >= 4
Jon Ashburn23d36b12016-02-02 17:47:28 -070047#define LOADER_EXPORT __attribute__((visibility("default")))
Chia-I Wu19300602014-08-04 08:03:57 +080048#elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)
Jon Ashburn23d36b12016-02-02 17:47:28 -070049#define LOADER_EXPORT __attribute__((visibility("default")))
Chia-I Wu19300602014-08-04 08:03:57 +080050#else
Jon Ashburn23d36b12016-02-02 17:47:28 -070051#define LOADER_EXPORT
Chia-I Wu19300602014-08-04 08:03:57 +080052#endif
53
Jon Ashburnf73e9212015-08-04 10:22:33 -060054#define MAX_STRING_SIZE 1024
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -060055#define VK_MAJOR(version) (version >> 22)
56#define VK_MINOR(version) ((version >> 12) & 0x3ff)
57#define VK_PATCH(version) (version & 0xfff)
Jon Ashburn27cd5842015-05-12 17:26:48 -060058
Jon Ashburn5ef20602015-07-02 09:40:15 -060059enum layer_type {
Jon Ashburn0c26e712015-07-02 16:10:32 -060060 VK_LAYER_TYPE_DEVICE_EXPLICIT = 0x1,
61 VK_LAYER_TYPE_INSTANCE_EXPLICIT = 0x2,
Jon Ashburn23d36b12016-02-02 17:47:28 -070062 VK_LAYER_TYPE_GLOBAL_EXPLICIT =
63 0x3, // both instance and device layer, bitwise
Jon Ashburn0c26e712015-07-02 16:10:32 -060064 VK_LAYER_TYPE_DEVICE_IMPLICIT = 0x4,
65 VK_LAYER_TYPE_INSTANCE_IMPLICIT = 0x8,
Jon Ashburn23d36b12016-02-02 17:47:28 -070066 VK_LAYER_TYPE_GLOBAL_IMPLICIT =
67 0xc, // both instance and device layer, bitwise
Jon Ashburn5ef20602015-07-02 09:40:15 -060068};
69
Mark Lobodzinskie9f09ef2016-02-02 18:53:34 -070070typedef enum VkStringErrorFlagBits {
Jon Ashburnf2b4e382016-02-10 20:50:19 -070071 VK_STRING_ERROR_NONE = 0x00000000,
72 VK_STRING_ERROR_LENGTH = 0x00000001,
73 VK_STRING_ERROR_BAD_DATA = 0x00000002,
Mark Lobodzinskie9f09ef2016-02-02 18:53:34 -070074} VkStringErrorFlagBits;
75typedef VkFlags VkStringErrorFlags;
76
Jon Ashburnf2b4e382016-02-10 20:50:19 -070077static const int MaxLoaderStringLength = 256;
78static const char UTF8_ONE_BYTE_CODE = 0xC0;
79static const char UTF8_ONE_BYTE_MASK = 0xE0;
80static const char UTF8_TWO_BYTE_CODE = 0xE0;
81static const char UTF8_TWO_BYTE_MASK = 0xF0;
82static const char UTF8_THREE_BYTE_CODE = 0xF0;
83static const char UTF8_THREE_BYTE_MASK = 0xF8;
84static const char UTF8_DATA_BYTE_CODE = 0x80;
85static const char UTF8_DATA_BYTE_MASK = 0xC0;
Mark Lobodzinskie9f09ef2016-02-02 18:53:34 -070086
Jon Ashburn6e6a2162015-12-10 08:51:10 -070087// form of all dynamic lists/arrays
88// only the list element should be changed
89struct loader_generic_list {
90 size_t capacity;
91 uint32_t count;
92 void *list;
93};
94
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -060095struct loader_extension_list {
96 size_t capacity;
97 uint32_t count;
Jon Ashburn5c042ea2015-08-04 11:14:18 -060098 VkExtensionProperties *list;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -060099};
100
Jon Ashburn39fbd4e2015-12-10 18:17:34 -0700101struct loader_dev_ext_props {
102 VkExtensionProperties props;
103 uint32_t entrypoint_count;
104 char **entrypoints;
105};
106
107struct loader_device_extension_list {
108 size_t capacity;
109 uint32_t count;
110 struct loader_dev_ext_props *list;
111};
112
Jon Ashburn5ef20602015-07-02 09:40:15 -0600113struct loader_name_value {
Jon Ashburnf73e9212015-08-04 10:22:33 -0600114 char name[MAX_STRING_SIZE];
115 char value[MAX_STRING_SIZE];
Jon Ashburn5ef20602015-07-02 09:40:15 -0600116};
117
118struct loader_lib_info {
Jon Ashburn3d002332015-08-20 16:35:30 -0600119 char lib_name[MAX_STRING_SIZE];
Jon Ashburn5ef20602015-07-02 09:40:15 -0600120 uint32_t ref_count;
121 loader_platform_dl_handle lib_handle;
122};
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600123
Jon Ashburn5ef20602015-07-02 09:40:15 -0600124struct loader_layer_functions {
Jon Ashburnf73e9212015-08-04 10:22:33 -0600125 char str_gipa[MAX_STRING_SIZE];
126 char str_gdpa[MAX_STRING_SIZE];
Jon Ashburn5ef20602015-07-02 09:40:15 -0600127 PFN_vkGetInstanceProcAddr get_instance_proc_addr;
128 PFN_vkGetDeviceProcAddr get_device_proc_addr;
129};
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600130
Jon Ashburn5ef20602015-07-02 09:40:15 -0600131struct loader_layer_properties {
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -0600132 VkLayerProperties info;
Jon Ashburn5ef20602015-07-02 09:40:15 -0600133 enum layer_type type;
Jon Ashburn3d002332015-08-20 16:35:30 -0600134 char lib_name[MAX_STRING_SIZE];
Jon Ashburn5ef20602015-07-02 09:40:15 -0600135 struct loader_layer_functions functions;
136 struct loader_extension_list instance_extension_list;
Jon Ashburn39fbd4e2015-12-10 18:17:34 -0700137 struct loader_device_extension_list device_extension_list;
Jon Ashburn5ef20602015-07-02 09:40:15 -0600138 struct loader_name_value disable_env_var;
139 struct loader_name_value enable_env_var;
140};
141
142struct loader_layer_list {
143 size_t capacity;
144 uint32_t count;
145 struct loader_layer_properties *list;
Jon Ashburn27cd5842015-05-12 17:26:48 -0600146};
147
Courtney Goeltzenleuchter371de702015-07-05 12:53:31 -0600148struct loader_layer_library_list {
149 size_t capacity;
150 uint32_t count;
151 struct loader_lib_info *list;
152};
153
Jon Ashburnfc1031e2015-11-17 15:31:02 -0700154struct loader_dispatch_hash_list {
155 size_t capacity;
156 uint32_t count;
Jon Ashburn23d36b12016-02-02 17:47:28 -0700157 uint32_t *index; // index into the dev_ext dispatch table
Jon Ashburnfc1031e2015-11-17 15:31:02 -0700158};
159
160#define MAX_NUM_DEV_EXTS 250
Jon Ashburn23d36b12016-02-02 17:47:28 -0700161// loader_dispatch_hash_entry and loader_dev_ext_dispatch_table.DevExt have one
162// to one
Jon Ashburnfc1031e2015-11-17 15:31:02 -0700163// correspondence; one loader_dispatch_hash_entry for one DevExt dispatch entry.
164// Also have a one to one correspondence with functions in dev_ext_trampoline.c
165struct loader_dispatch_hash_entry {
166 char *func_name;
Jon Ashburn23d36b12016-02-02 17:47:28 -0700167 struct loader_dispatch_hash_list list; // to handle hashing collisions
Jon Ashburnfc1031e2015-11-17 15:31:02 -0700168};
169
Jon Ashburn23d36b12016-02-02 17:47:28 -0700170typedef void(VKAPI_PTR *PFN_vkDevExt)(VkDevice device);
Jon Ashburnfc1031e2015-11-17 15:31:02 -0700171struct loader_dev_ext_dispatch_table {
172 PFN_vkDevExt DevExt[MAX_NUM_DEV_EXTS];
173};
174
175struct loader_dev_dispatch_table {
176 VkLayerDispatchTable core_dispatch;
177 struct loader_dev_ext_dispatch_table ext_dispatch;
178};
179
Jon Ashburndc6fcad2015-06-10 10:06:06 -0600180/* per CreateDevice structure */
181struct loader_device {
Jon Ashburnfc1031e2015-11-17 15:31:02 -0700182 struct loader_dev_dispatch_table loader_dispatch;
Jon Ashburn23d36b12016-02-02 17:47:28 -0700183 VkDevice device; // device object from the icd
Jon Ashburndc6fcad2015-06-10 10:06:06 -0600184
Jon Ashburn23d36b12016-02-02 17:47:28 -0700185 uint32_t app_extension_count;
Jon Ashburndc6fcad2015-06-10 10:06:06 -0600186 VkExtensionProperties *app_extension_props;
187
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -0600188 struct loader_layer_list activated_layer_list;
Jon Ashburndc6fcad2015-06-10 10:06:06 -0600189
190 struct loader_device *next;
191};
192
Jon Ashburn953bb3c2015-06-10 16:11:42 -0600193/* per ICD structure */
Jon Ashburn95a77ba2015-05-15 15:09:35 -0600194struct loader_icd {
Jon Ashburn3d002332015-08-20 16:35:30 -0600195 // pointers to find other structs
196 const struct loader_scanned_icds *this_icd_lib;
197 const struct loader_instance *this_instance;
Jon Ashburn95a77ba2015-05-15 15:09:35 -0600198
Jon Ashburndc6fcad2015-06-10 10:06:06 -0600199 struct loader_device *logical_device_list;
Jon Ashburn23d36b12016-02-02 17:47:28 -0700200 VkInstance instance; // instance object from the icd
Jon Ashburn8d1b0b52015-05-18 13:20:15 -0600201 PFN_vkGetDeviceProcAddr GetDeviceProcAddr;
Jon Ashburn95a77ba2015-05-15 15:09:35 -0600202 PFN_vkDestroyInstance DestroyInstance;
203 PFN_vkEnumeratePhysicalDevices EnumeratePhysicalDevices;
Chris Forbesbc0bb772015-06-21 22:55:02 +1200204 PFN_vkGetPhysicalDeviceFeatures GetPhysicalDeviceFeatures;
Courtney Goeltzenleuchter2caec862015-07-12 12:52:09 -0600205 PFN_vkGetPhysicalDeviceFormatProperties GetPhysicalDeviceFormatProperties;
Jon Ashburn23d36b12016-02-02 17:47:28 -0700206 PFN_vkGetPhysicalDeviceImageFormatProperties
207 GetPhysicalDeviceImageFormatProperties;
Jon Ashburn95a77ba2015-05-15 15:09:35 -0600208 PFN_vkCreateDevice CreateDevice;
Tony Barbour59a47322015-06-24 16:06:58 -0600209 PFN_vkGetPhysicalDeviceProperties GetPhysicalDeviceProperties;
Jon Ashburn23d36b12016-02-02 17:47:28 -0700210 PFN_vkGetPhysicalDeviceQueueFamilyProperties
211 GetPhysicalDeviceQueueFamilyProperties;
Tony Barbour59a47322015-06-24 16:06:58 -0600212 PFN_vkGetPhysicalDeviceMemoryProperties GetPhysicalDeviceMemoryProperties;
Courtney Goeltzenleuchter35985f62015-09-14 17:22:16 -0600213 PFN_vkEnumerateDeviceExtensionProperties EnumerateDeviceExtensionProperties;
Jon Ashburn23d36b12016-02-02 17:47:28 -0700214 PFN_vkGetPhysicalDeviceSparseImageFormatProperties
215 GetPhysicalDeviceSparseImageFormatProperties;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700216 PFN_vkCreateDebugReportCallbackEXT CreateDebugReportCallbackEXT;
217 PFN_vkDestroyDebugReportCallbackEXT DestroyDebugReportCallbackEXT;
218 PFN_vkDebugReportMessageEXT DebugReportMessageEXT;
Ian Elliott7e40db92015-08-21 15:09:33 -0600219 PFN_vkGetPhysicalDeviceSurfaceSupportKHR GetPhysicalDeviceSurfaceSupportKHR;
Jon Ashburn23d36b12016-02-02 17:47:28 -0700220 PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR
221 GetPhysicalDeviceSurfaceCapabilitiesKHR;
Ian Elliott486c5502015-11-19 16:05:09 -0700222 PFN_vkGetPhysicalDeviceSurfaceFormatsKHR GetPhysicalDeviceSurfaceFormatsKHR;
Jon Ashburn23d36b12016-02-02 17:47:28 -0700223 PFN_vkGetPhysicalDeviceSurfacePresentModesKHR
224 GetPhysicalDeviceSurfacePresentModesKHR;
Ian Elliott919fa302015-11-24 15:39:10 -0700225#ifdef VK_USE_PLATFORM_WIN32_KHR
Jon Ashburn23d36b12016-02-02 17:47:28 -0700226 PFN_vkGetPhysicalDeviceWin32PresentationSupportKHR
227 GetPhysicalDeviceWin32PresentationSupportKHR;
Ian Elliott919fa302015-11-24 15:39:10 -0700228#endif
229#ifdef VK_USE_PLATFORM_MIR_KHR
Jon Ashburn23d36b12016-02-02 17:47:28 -0700230 PFN_vkGetPhysicalDeviceMirPresentationSupportKHR
231 GetPhysicalDeviceMirPresentvationSupportKHR;
Ian Elliott919fa302015-11-24 15:39:10 -0700232#endif
233#ifdef VK_USE_PLATFORM_WAYLAND_KHR
Jon Ashburn23d36b12016-02-02 17:47:28 -0700234 PFN_vkGetPhysicalDeviceWaylandPresentationSupportKHR
235 GetPhysicalDeviceWaylandPresentationSupportKHR;
Ian Elliott919fa302015-11-24 15:39:10 -0700236#endif
237#ifdef VK_USE_PLATFORM_XCB_KHR
Jon Ashburn23d36b12016-02-02 17:47:28 -0700238 PFN_vkGetPhysicalDeviceXcbPresentationSupportKHR
239 GetPhysicalDeviceXcbPresentationSupportKHR;
Ian Elliott919fa302015-11-24 15:39:10 -0700240#endif
241#ifdef VK_USE_PLATFORM_XLIB_KHR
Jon Ashburn23d36b12016-02-02 17:47:28 -0700242 PFN_vkGetPhysicalDeviceXlibPresentationSupportKHR
243 GetPhysicalDeviceXlibPresentationSupportKHR;
Ian Elliott919fa302015-11-24 15:39:10 -0700244#endif
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -0600245
Jon Ashburndc6fcad2015-06-10 10:06:06 -0600246 struct loader_icd *next;
Jon Ashburn95a77ba2015-05-15 15:09:35 -0600247};
248
Jon Ashburn8810c5f2015-08-18 18:04:47 -0600249/* per ICD library structure */
250struct loader_icd_libs {
251 size_t capacity;
252 uint32_t count;
253 struct loader_scanned_icds *list;
254};
255
Jon Ashburn953bb3c2015-06-10 16:11:42 -0600256/* per instance structure */
Jon Ashburn27cd5842015-05-12 17:26:48 -0600257struct loader_instance {
Jon Ashburn95a77ba2015-05-15 15:09:35 -0600258 VkLayerInstanceDispatchTable *disp; // must be first entry in structure
259
Jon Ashburn27cd5842015-05-12 17:26:48 -0600260 uint32_t total_gpu_count;
Jon Ashburn24cd4be2015-11-01 14:04:06 -0700261 struct loader_physical_device *phys_devs;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600262 uint32_t total_icd_count;
Jon Ashburn27cd5842015-05-12 17:26:48 -0600263 struct loader_icd *icds;
264 struct loader_instance *next;
Jon Ashburn23d36b12016-02-02 17:47:28 -0700265 struct loader_extension_list ext_list; // icds and loaders extensions
Jon Ashburn8810c5f2015-08-18 18:04:47 -0600266 struct loader_icd_libs icd_libs;
Jon Ashburn3d002332015-08-20 16:35:30 -0600267 struct loader_layer_list instance_layer_list;
268 struct loader_layer_list device_layer_list;
Jon Ashburnfc1031e2015-11-17 15:31:02 -0700269 struct loader_dispatch_hash_entry disp_hash[MAX_NUM_DEV_EXTS];
Jon Ashburn3d002332015-08-20 16:35:30 -0600270
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600271 struct loader_msg_callback_map_entry *icd_msg_callback_map;
272
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -0600273 struct loader_layer_list activated_layer_list;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600274
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700275 VkInstance instance;
276
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600277 bool debug_report_enabled;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600278 VkLayerDbgFunctionNode *DbgFunctionHead;
Courtney Goeltzenleuchter7f5aafc2015-07-05 11:28:29 -0600279
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800280 VkAllocationCallbacks alloc_callbacks;
Ian Elliottd3ef02f2015-07-06 14:36:13 -0600281
Ian Elliott954fa342015-10-30 15:28:23 -0600282 bool wsi_surface_enabled;
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -0700283#ifdef VK_USE_PLATFORM_WIN32_KHR
Ian Elliott954fa342015-10-30 15:28:23 -0600284 bool wsi_win32_surface_enabled;
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -0700285#endif
286#ifdef VK_USE_PLATFORM_MIR_KHR
Ian Elliott954fa342015-10-30 15:28:23 -0600287 bool wsi_mir_surface_enabled;
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -0700288#endif
289#ifdef VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott954fa342015-10-30 15:28:23 -0600290 bool wsi_wayland_surface_enabled;
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -0700291#endif
292#ifdef VK_USE_PLATFORM_XCB_KHR
Ian Elliott954fa342015-10-30 15:28:23 -0600293 bool wsi_xcb_surface_enabled;
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -0700294#endif
295#ifdef VK_USE_PLATFORM_XLIB_KHR
Ian Elliott954fa342015-10-30 15:28:23 -0600296 bool wsi_xlib_surface_enabled;
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -0700297#endif
298#ifdef VK_USE_PLATFORM_ANDROID_KHR
299 bool wsi_android_surface_enabled;
300#endif
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600301};
302
Jon Ashburn24cd4be2015-11-01 14:04:06 -0700303/* per enumerated PhysicalDevice structure */
304struct loader_physical_device {
305 VkLayerInstanceDispatchTable *disp; // must be first entry in structure
306 struct loader_instance *this_instance;
307 struct loader_icd *this_icd;
Jon Ashburn23d36b12016-02-02 17:47:28 -0700308 VkPhysicalDevice phys_dev; // object from ICD
309 /*
310 * Fill in the cache of available device extensions from
311 * this physical device. This cache can be used during CreateDevice
312 */
Jon Ashburn24cd4be2015-11-01 14:04:06 -0700313 struct loader_extension_list device_extension_cache;
314};
315
Jon Ashburn27cd5842015-05-12 17:26:48 -0600316struct loader_struct {
317 struct loader_instance *instances;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600318
319 unsigned int loaded_layer_lib_count;
Courtney Goeltzenleuchterdad30df2015-10-07 09:00:34 -0600320 size_t loaded_layer_lib_capacity;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600321 struct loader_lib_info *loaded_layer_lib_list;
Jon Ashburn8810c5f2015-08-18 18:04:47 -0600322 // TODO add ref counting of ICD libraries
Jon Ashburn2d0c4bb2015-07-06 15:40:35 -0600323 // TODO use this struct loader_layer_library_list scanned_layer_libraries;
Jon Ashburn8810c5f2015-08-18 18:04:47 -0600324 // TODO add list of icd libraries for ref counting them for closure
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600325};
326
327struct loader_scanned_icds {
328 char *lib_name;
329 loader_platform_dl_handle handle;
Jon Ashburn005617f2015-11-17 17:35:40 -0700330 uint32_t api_version;
Jon Ashburnc624c882015-07-16 10:17:29 -0600331 PFN_vkGetInstanceProcAddr GetInstanceProcAddr;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600332 PFN_vkCreateInstance CreateInstance;
Jon Ashburn23d36b12016-02-02 17:47:28 -0700333 PFN_vkEnumerateInstanceExtensionProperties
334 EnumerateInstanceExtensionProperties;
Jon Ashburn27cd5842015-05-12 17:26:48 -0600335};
336
Jon Ashburn5ef20602015-07-02 09:40:15 -0600337static inline struct loader_instance *loader_instance(VkInstance instance) {
Jon Ashburn23d36b12016-02-02 17:47:28 -0700338 return (struct loader_instance *)instance;
Jon Ashburn5ef20602015-07-02 09:40:15 -0600339}
340
Jon Ashburn23d36b12016-02-02 17:47:28 -0700341static inline void loader_set_dispatch(void *obj, const void *data) {
342 *((const void **)obj) = data;
Chia-I Wu5291c762015-04-11 15:34:07 +0800343}
344
Jon Ashburn23d36b12016-02-02 17:47:28 -0700345static inline VkLayerDispatchTable *loader_get_dispatch(const void *obj) {
346 return *((VkLayerDispatchTable **)obj);
Chia-I Wu5291c762015-04-11 15:34:07 +0800347}
348
Jon Ashburn23d36b12016-02-02 17:47:28 -0700349static inline struct loader_dev_dispatch_table *
350loader_get_dev_dispatch(const void *obj) {
351 return *((struct loader_dev_dispatch_table **)obj);
Jon Ashburnfc1031e2015-11-17 15:31:02 -0700352}
353
Jon Ashburn23d36b12016-02-02 17:47:28 -0700354static inline VkLayerInstanceDispatchTable *
355loader_get_instance_dispatch(const void *obj) {
356 return *((VkLayerInstanceDispatchTable **)obj);
Jon Ashburn27cd5842015-05-12 17:26:48 -0600357}
358
Jon Ashburn23d36b12016-02-02 17:47:28 -0700359static inline void loader_init_dispatch(void *obj, const void *data) {
Jon Ashburn40066642015-04-15 13:34:33 -0600360#ifdef DEBUG
Chia-I Wu5291c762015-04-11 15:34:07 +0800361 assert(valid_loader_magic_value(obj) &&
Jon Ashburn23d36b12016-02-02 17:47:28 -0700362 "Incompatible ICD, first dword must be initialized to "
363 "ICD_LOADER_MAGIC. See loader/README.md for details.");
Jon Ashburn40066642015-04-15 13:34:33 -0600364#endif
Chia-I Wu5291c762015-04-11 15:34:07 +0800365
Jon Ashburn1ed042c2015-05-01 18:00:33 -0600366 loader_set_dispatch(obj, data);
Chia-I Wu5291c762015-04-11 15:34:07 +0800367}
368
Jon Ashburn27cd5842015-05-12 17:26:48 -0600369/* global variables used across files */
370extern struct loader_struct loader;
Jon Ashburn87d6aa92015-08-28 15:19:27 -0600371extern THREAD_LOCAL_DECL struct loader_instance *tls_instance;
Jon Ashburn8810c5f2015-08-18 18:04:47 -0600372extern LOADER_PLATFORM_THREAD_ONCE_DEFINITION(once_init);
Jon Ashburn6301a0f2015-05-29 13:15:39 -0600373extern loader_platform_thread_mutex loader_lock;
Jon Ashburn6461ef22015-09-22 13:11:00 -0600374extern loader_platform_thread_mutex loader_json_lock;
Jon Ashburn6301a0f2015-05-29 13:15:39 -0600375extern const VkLayerInstanceDispatchTable instance_disp;
Jon Ashburnbacb0f52015-04-06 10:58:22 -0600376
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600377struct loader_msg_callback_map_entry {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700378 VkDebugReportCallbackEXT icd_obj;
379 VkDebugReportCallbackEXT loader_obj;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600380};
381
Jon Ashburn23d36b12016-02-02 17:47:28 -0700382bool compare_vk_extension_properties(const VkExtensionProperties *op1,
383 const VkExtensionProperties *op2);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600384
Mark Lobodzinskie9f09ef2016-02-02 18:53:34 -0700385VkResult loader_validate_layers(const struct loader_instance *inst,
386 const uint32_t layer_count,
Jon Ashburn23d36b12016-02-02 17:47:28 -0700387 const char *const *ppEnabledLayerNames,
388 const struct loader_layer_list *list);
Courtney Goeltzenleuchter3b8c5ff2015-07-06 17:45:08 -0600389
390VkResult loader_validate_instance_extensions(
Mark Lobodzinskie9f09ef2016-02-02 18:53:34 -0700391 const struct loader_instance *inst,
Jon Ashburn23d36b12016-02-02 17:47:28 -0700392 const struct loader_extension_list *icd_exts,
393 const struct loader_layer_list *instance_layer,
394 const VkInstanceCreateInfo *pCreateInfo);
Courtney Goeltzenleuchter3b8c5ff2015-07-06 17:45:08 -0600395
Jon Ashburn27cd5842015-05-12 17:26:48 -0600396/* instance layer chain termination entrypoint definitions */
Jon Ashburn23d36b12016-02-02 17:47:28 -0700397VKAPI_ATTR VkResult VKAPI_CALL
398loader_CreateInstance(const VkInstanceCreateInfo *pCreateInfo,
399 const VkAllocationCallbacks *pAllocator,
400 VkInstance *pInstance);
Chia-I Wu5291c762015-04-11 15:34:07 +0800401
Jon Ashburn23d36b12016-02-02 17:47:28 -0700402VKAPI_ATTR void VKAPI_CALL
403loader_DestroyInstance(VkInstance instance,
404 const VkAllocationCallbacks *pAllocator);
Jon Ashburn27cd5842015-05-12 17:26:48 -0600405
Jon Ashburn23d36b12016-02-02 17:47:28 -0700406VKAPI_ATTR VkResult VKAPI_CALL
407loader_EnumeratePhysicalDevices(VkInstance instance,
408 uint32_t *pPhysicalDeviceCount,
409 VkPhysicalDevice *pPhysicalDevices);
Chris Forbesbc0bb772015-06-21 22:55:02 +1200410
Jon Ashburn23d36b12016-02-02 17:47:28 -0700411VKAPI_ATTR void VKAPI_CALL
412loader_GetPhysicalDeviceFeatures(VkPhysicalDevice physicalDevice,
413 VkPhysicalDeviceFeatures *pFeatures);
Chris Forbesbc0bb772015-06-21 22:55:02 +1200414
Jon Ashburn23d36b12016-02-02 17:47:28 -0700415VKAPI_ATTR void VKAPI_CALL
416loader_GetPhysicalDeviceFormatProperties(VkPhysicalDevice physicalDevice,
417 VkFormat format,
418 VkFormatProperties *pFormatInfo);
Chris Forbesbc0bb772015-06-21 22:55:02 +1200419
Chia-I Wu9ab61502015-11-06 06:42:02 +0800420VKAPI_ATTR VkResult VKAPI_CALL loader_GetPhysicalDeviceImageFormatProperties(
Jon Ashburn23d36b12016-02-02 17:47:28 -0700421 VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type,
422 VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags,
423 VkImageFormatProperties *pImageFormatProperties);
Jon Ashburn754864f2015-07-23 18:49:07 -0600424
Chia-I Wu9ab61502015-11-06 06:42:02 +0800425VKAPI_ATTR void VKAPI_CALL loader_GetPhysicalDeviceSparseImageFormatProperties(
Jon Ashburn23d36b12016-02-02 17:47:28 -0700426 VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type,
427 VkSampleCountFlagBits samples, VkImageUsageFlags usage,
428 VkImageTiling tiling, uint32_t *pNumProperties,
429 VkSparseImageFormatProperties *pProperties);
Tony Barbour59a47322015-06-24 16:06:58 -0600430
Jon Ashburn23d36b12016-02-02 17:47:28 -0700431VKAPI_ATTR void VKAPI_CALL
432loader_GetPhysicalDeviceProperties(VkPhysicalDevice physicalDevice,
433 VkPhysicalDeviceProperties *pProperties);
Tony Barbour59a47322015-06-24 16:06:58 -0600434
Jon Ashburn23d36b12016-02-02 17:47:28 -0700435VKAPI_ATTR VkResult VKAPI_CALL
436loader_EnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice,
437 const char *pLayerName,
438 uint32_t *pCount,
439 VkExtensionProperties *pProperties);
Tony Barbour59a47322015-06-24 16:06:58 -0600440
Jon Ashburn23d36b12016-02-02 17:47:28 -0700441VKAPI_ATTR VkResult VKAPI_CALL
442loader_EnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice,
443 uint32_t *pCount,
444 VkLayerProperties *pProperties);
Tony Barbour59a47322015-06-24 16:06:58 -0600445
Jon Ashburn23d36b12016-02-02 17:47:28 -0700446VKAPI_ATTR void VKAPI_CALL loader_GetPhysicalDeviceQueueFamilyProperties(
447 VkPhysicalDevice physicalDevice, uint32_t *pCount,
448 VkQueueFamilyProperties *pProperties);
Tony Barbour59a47322015-06-24 16:06:58 -0600449
Jon Ashburn23d36b12016-02-02 17:47:28 -0700450VKAPI_ATTR void VKAPI_CALL loader_GetPhysicalDeviceMemoryProperties(
451 VkPhysicalDevice physicalDevice,
452 VkPhysicalDeviceMemoryProperties *pProperties);
Jon Ashburn6301a0f2015-05-29 13:15:39 -0600453
Jon Ashburn23d36b12016-02-02 17:47:28 -0700454VKAPI_ATTR VkResult VKAPI_CALL
455loader_create_device_terminator(VkPhysicalDevice physicalDevice,
456 const VkDeviceCreateInfo *pCreateInfo,
457 const VkAllocationCallbacks *pAllocator,
458 VkDevice *pDevice);
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700459
Jon Ashburn23d36b12016-02-02 17:47:28 -0700460VKAPI_ATTR VkResult VKAPI_CALL
461loader_CreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo *pCreateInfo,
462 const VkAllocationCallbacks *pAllocator, VkDevice *pDevice);
Jon Ashburn27cd5842015-05-12 17:26:48 -0600463
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600464/* helper function definitions */
Jon Ashburn8810c5f2015-08-18 18:04:47 -0600465void loader_initialize(void);
Jon Ashburn23d36b12016-02-02 17:47:28 -0700466bool has_vk_extension_property_array(const VkExtensionProperties *vk_ext_prop,
467 const uint32_t count,
468 const VkExtensionProperties *ext_array);
469bool has_vk_extension_property(const VkExtensionProperties *vk_ext_prop,
470 const struct loader_extension_list *ext_list);
Jon Ashburn27cd5842015-05-12 17:26:48 -0600471
Jon Ashburn23d36b12016-02-02 17:47:28 -0700472VkResult loader_add_to_ext_list(const struct loader_instance *inst,
473 struct loader_extension_list *ext_list,
474 uint32_t prop_list_count,
475 const VkExtensionProperties *props);
476void loader_destroy_generic_list(const struct loader_instance *inst,
477 struct loader_generic_list *list);
478void loader_delete_layer_properties(const struct loader_instance *inst,
479 struct loader_layer_list *layer_list);
480void loader_add_to_layer_list(const struct loader_instance *inst,
481 struct loader_layer_list *list,
482 uint32_t prop_list_count,
483 const struct loader_layer_properties *props);
484void loader_scanned_icd_clear(const struct loader_instance *inst,
485 struct loader_icd_libs *icd_libs);
486void loader_icd_scan(const struct loader_instance *inst,
487 struct loader_icd_libs *icds);
488void loader_layer_scan(const struct loader_instance *inst,
489 struct loader_layer_list *instance_layers,
490 struct loader_layer_list *device_layers);
Jon Ashburn8810c5f2015-08-18 18:04:47 -0600491void loader_get_icd_loader_instance_extensions(
Jon Ashburn23d36b12016-02-02 17:47:28 -0700492 const struct loader_instance *inst, struct loader_icd_libs *icd_libs,
493 struct loader_extension_list *inst_exts);
494struct loader_icd *loader_get_icd_and_device(const VkDevice device,
495 struct loader_device **found_dev);
496void *loader_dev_ext_gpa(struct loader_instance *inst, const char *funcName);
497void *loader_get_dev_ext_trampoline(uint32_t index);
498struct loader_instance *loader_get_instance(const VkInstance instance);
499void loader_remove_logical_device(const struct loader_instance *inst,
500 struct loader_icd *icd,
501 struct loader_device *found_dev);
502VkResult
503loader_enable_instance_layers(struct loader_instance *inst,
504 const VkInstanceCreateInfo *pCreateInfo,
505 const struct loader_layer_list *instance_layers);
Jon Ashburndc6fcad2015-06-10 10:06:06 -0600506void loader_deactivate_instance_layers(struct loader_instance *instance);
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700507
Jon Ashburn23d36b12016-02-02 17:47:28 -0700508VkResult loader_create_instance_chain(const VkInstanceCreateInfo *pCreateInfo,
509 const VkAllocationCallbacks *pAllocator,
510 struct loader_instance *inst,
Jon Ashburn6e0a2132016-02-03 12:37:30 -0700511 VkInstance *created_instance);
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700512
Jon Ashburn23d36b12016-02-02 17:47:28 -0700513void loader_activate_instance_layer_extensions(struct loader_instance *inst,
514 VkInstance created_inst);
Courtney Goeltzenleuchter7f5aafc2015-07-05 11:28:29 -0600515
Jon Ashburn23d36b12016-02-02 17:47:28 -0700516void *loader_heap_alloc(const struct loader_instance *instance, size_t size,
517 VkSystemAllocationScope allocationScope);
Courtney Goeltzenleuchter7f5aafc2015-07-05 11:28:29 -0600518
Jon Ashburn23d36b12016-02-02 17:47:28 -0700519void loader_heap_free(const struct loader_instance *instance, void *pMemory);
Jon Ashburn87d6aa92015-08-28 15:19:27 -0600520
521void *loader_tls_heap_alloc(size_t size);
522
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800523void loader_tls_heap_free(void *pMemory);
Mark Lobodzinskie9f09ef2016-02-02 18:53:34 -0700524
Jon Ashburnf2b4e382016-02-10 20:50:19 -0700525VkStringErrorFlags vk_string_validate(const int max_length,
526 const char *char_array);
Mark Lobodzinskie9f09ef2016-02-02 18:53:34 -0700527
Chia-I Wu19300602014-08-04 08:03:57 +0800528#endif /* LOADER_H */