blob: 55662b73cf658c14dd517845afd6930a96dca20c [file] [log] [blame]
Chia-I Wu19300602014-08-04 08:03:57 +08001/*
Chia-I Wu19300602014-08-04 08:03:57 +08002 *
Courtney Goeltzenleuchterfcbe16f2015-10-29 13:50:34 -06003 * Copyright (C) 2015 Valve Corporation
Courtney Goeltzenleuchterf821dad2015-12-02 14:53:22 -07004 * Copyright (C) 2015 Google Inc.
Chia-I Wu19300602014-08-04 08:03:57 +08005 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
Chia-I Wu701f3f62014-09-02 08:32:09 +080023 *
Courtney Goeltzenleuchter05559522015-10-30 11:14:30 -060024 * Author: Chia-I Wu <olvaffe@gmail.com>
25 * Author: Chia-I Wu <olv@lunarg.com>
26 * Author: Chris Forbes <chrisf@ijw.co.nz>
27 * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
28 * Author: Jon Ashburn <jon@lunarg.com>
29 * Author: Tony Barbour <tony@LunarG.com>
30 *
Chia-I Wu19300602014-08-04 08:03:57 +080031 */
32
33#ifndef LOADER_H
34#define LOADER_H
35
David Pinedo9316d3b2015-11-06 12:54:48 -070036#include <vulkan/vulkan.h>
Jon Ashburn8a39efc2015-11-06 11:02:40 -070037#include <vk_loader_platform.h>
Ian Elliott1dcd1092015-11-17 17:29:40 -070038
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070039#include <vulkan/vk_ext_debug_report.h>
Ian Elliottba042332015-11-18 14:57:08 -070040
David Pinedo9316d3b2015-11-06 12:54:48 -070041#include <vulkan/vk_layer.h>
42#include <vulkan/vk_icd.h>
Chia-I Wu5291c762015-04-11 15:34:07 +080043#include <assert.h>
44
Chia-I Wu19300602014-08-04 08:03:57 +080045#if defined(__GNUC__) && __GNUC__ >= 4
46# define LOADER_EXPORT __attribute__((visibility("default")))
47#elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)
48# define LOADER_EXPORT __attribute__((visibility("default")))
49#else
50# define LOADER_EXPORT
51#endif
52
Jon Ashburnf73e9212015-08-04 10:22:33 -060053#define MAX_STRING_SIZE 1024
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -060054#define VK_MAJOR(version) (version >> 22)
55#define VK_MINOR(version) ((version >> 12) & 0x3ff)
56#define VK_PATCH(version) (version & 0xfff)
Jon Ashburn27cd5842015-05-12 17:26:48 -060057
Jon Ashburn5ef20602015-07-02 09:40:15 -060058enum layer_type {
Jon Ashburn0c26e712015-07-02 16:10:32 -060059 VK_LAYER_TYPE_DEVICE_EXPLICIT = 0x1,
60 VK_LAYER_TYPE_INSTANCE_EXPLICIT = 0x2,
61 VK_LAYER_TYPE_GLOBAL_EXPLICIT = 0x3, // both instance and device layer, bitwise
62 VK_LAYER_TYPE_DEVICE_IMPLICIT = 0x4,
63 VK_LAYER_TYPE_INSTANCE_IMPLICIT = 0x8,
64 VK_LAYER_TYPE_GLOBAL_IMPLICIT = 0xc, // both instance and device layer, bitwise
Jon Ashburn5ef20602015-07-02 09:40:15 -060065};
66
Jon Ashburn6e6a2162015-12-10 08:51:10 -070067// form of all dynamic lists/arrays
68// only the list element should be changed
69struct loader_generic_list {
70 size_t capacity;
71 uint32_t count;
72 void *list;
73};
74
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -060075struct loader_extension_list {
76 size_t capacity;
77 uint32_t count;
Jon Ashburn5c042ea2015-08-04 11:14:18 -060078 VkExtensionProperties *list;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -060079};
80
Jon Ashburn39fbd4e2015-12-10 18:17:34 -070081struct loader_dev_ext_props {
82 VkExtensionProperties props;
83 uint32_t entrypoint_count;
84 char **entrypoints;
85};
86
87struct loader_device_extension_list {
88 size_t capacity;
89 uint32_t count;
90 struct loader_dev_ext_props *list;
91};
92
Jon Ashburn5ef20602015-07-02 09:40:15 -060093struct loader_name_value {
Jon Ashburnf73e9212015-08-04 10:22:33 -060094 char name[MAX_STRING_SIZE];
95 char value[MAX_STRING_SIZE];
Jon Ashburn5ef20602015-07-02 09:40:15 -060096};
97
98struct loader_lib_info {
Jon Ashburn3d002332015-08-20 16:35:30 -060099 char lib_name[MAX_STRING_SIZE];
Jon Ashburn5ef20602015-07-02 09:40:15 -0600100 uint32_t ref_count;
101 loader_platform_dl_handle lib_handle;
102};
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600103
Jon Ashburn5ef20602015-07-02 09:40:15 -0600104struct loader_layer_functions {
Jon Ashburnf73e9212015-08-04 10:22:33 -0600105 char str_gipa[MAX_STRING_SIZE];
106 char str_gdpa[MAX_STRING_SIZE];
Jon Ashburn5ef20602015-07-02 09:40:15 -0600107 PFN_vkGetInstanceProcAddr get_instance_proc_addr;
108 PFN_vkGetDeviceProcAddr get_device_proc_addr;
109};
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600110
Jon Ashburn5ef20602015-07-02 09:40:15 -0600111struct loader_layer_properties {
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -0600112 VkLayerProperties info;
Jon Ashburn5ef20602015-07-02 09:40:15 -0600113 enum layer_type type;
Jon Ashburn3d002332015-08-20 16:35:30 -0600114 char lib_name[MAX_STRING_SIZE];
Jon Ashburn5ef20602015-07-02 09:40:15 -0600115 struct loader_layer_functions functions;
116 struct loader_extension_list instance_extension_list;
Jon Ashburn39fbd4e2015-12-10 18:17:34 -0700117 struct loader_device_extension_list device_extension_list;
Jon Ashburn5ef20602015-07-02 09:40:15 -0600118 struct loader_name_value disable_env_var;
119 struct loader_name_value enable_env_var;
120};
121
122struct loader_layer_list {
123 size_t capacity;
124 uint32_t count;
125 struct loader_layer_properties *list;
Jon Ashburn27cd5842015-05-12 17:26:48 -0600126};
127
Courtney Goeltzenleuchter371de702015-07-05 12:53:31 -0600128struct loader_layer_library_list {
129 size_t capacity;
130 uint32_t count;
131 struct loader_lib_info *list;
132};
133
Jon Ashburnfc1031e2015-11-17 15:31:02 -0700134struct loader_dispatch_hash_list {
135 size_t capacity;
136 uint32_t count;
137 uint32_t *index; // index into the dev_ext dispatch table
138};
139
140#define MAX_NUM_DEV_EXTS 250
141// loader_dispatch_hash_entry and loader_dev_ext_dispatch_table.DevExt have one to one
142// correspondence; one loader_dispatch_hash_entry for one DevExt dispatch entry.
143// Also have a one to one correspondence with functions in dev_ext_trampoline.c
144struct loader_dispatch_hash_entry {
145 char *func_name;
146 struct loader_dispatch_hash_list list; // to handle hashing collisions
147};
148
149typedef void (VKAPI_PTR *PFN_vkDevExt)(VkDevice device);
150struct loader_dev_ext_dispatch_table {
151 PFN_vkDevExt DevExt[MAX_NUM_DEV_EXTS];
152};
153
154struct loader_dev_dispatch_table {
155 VkLayerDispatchTable core_dispatch;
156 struct loader_dev_ext_dispatch_table ext_dispatch;
157};
158
Jon Ashburndc6fcad2015-06-10 10:06:06 -0600159/* per CreateDevice structure */
160struct loader_device {
Jon Ashburnfc1031e2015-11-17 15:31:02 -0700161 struct loader_dev_dispatch_table loader_dispatch;
Jon Ashburndc6fcad2015-06-10 10:06:06 -0600162 VkDevice device; // device object from the icd
163
164 uint32_t app_extension_count;
165 VkExtensionProperties *app_extension_props;
166
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -0600167 struct loader_layer_list activated_layer_list;
Jon Ashburndc6fcad2015-06-10 10:06:06 -0600168
169 struct loader_device *next;
170};
171
Jon Ashburn953bb3c2015-06-10 16:11:42 -0600172/* per ICD structure */
Jon Ashburn95a77ba2015-05-15 15:09:35 -0600173struct loader_icd {
Jon Ashburn3d002332015-08-20 16:35:30 -0600174 // pointers to find other structs
175 const struct loader_scanned_icds *this_icd_lib;
176 const struct loader_instance *this_instance;
Jon Ashburn95a77ba2015-05-15 15:09:35 -0600177
Jon Ashburndc6fcad2015-06-10 10:06:06 -0600178 struct loader_device *logical_device_list;
Jon Ashburn95a77ba2015-05-15 15:09:35 -0600179 VkInstance instance; // instance object from the icd
Jon Ashburn8d1b0b52015-05-18 13:20:15 -0600180 PFN_vkGetDeviceProcAddr GetDeviceProcAddr;
Jon Ashburn95a77ba2015-05-15 15:09:35 -0600181 PFN_vkDestroyInstance DestroyInstance;
182 PFN_vkEnumeratePhysicalDevices EnumeratePhysicalDevices;
Chris Forbesbc0bb772015-06-21 22:55:02 +1200183 PFN_vkGetPhysicalDeviceFeatures GetPhysicalDeviceFeatures;
Courtney Goeltzenleuchter2caec862015-07-12 12:52:09 -0600184 PFN_vkGetPhysicalDeviceFormatProperties GetPhysicalDeviceFormatProperties;
Jon Ashburn754864f2015-07-23 18:49:07 -0600185 PFN_vkGetPhysicalDeviceImageFormatProperties GetPhysicalDeviceImageFormatProperties;
Jon Ashburn95a77ba2015-05-15 15:09:35 -0600186 PFN_vkCreateDevice CreateDevice;
Tony Barbour59a47322015-06-24 16:06:58 -0600187 PFN_vkGetPhysicalDeviceProperties GetPhysicalDeviceProperties;
Cody Northropd0802882015-08-03 17:04:53 -0600188 PFN_vkGetPhysicalDeviceQueueFamilyProperties GetPhysicalDeviceQueueFamilyProperties;
Tony Barbour59a47322015-06-24 16:06:58 -0600189 PFN_vkGetPhysicalDeviceMemoryProperties GetPhysicalDeviceMemoryProperties;
Courtney Goeltzenleuchter35985f62015-09-14 17:22:16 -0600190 PFN_vkEnumerateDeviceExtensionProperties EnumerateDeviceExtensionProperties;
Mark Lobodzinski16e8bef2015-07-03 15:58:09 -0600191 PFN_vkGetPhysicalDeviceSparseImageFormatProperties GetPhysicalDeviceSparseImageFormatProperties;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700192 PFN_vkCreateDebugReportCallbackEXT CreateDebugReportCallbackEXT;
193 PFN_vkDestroyDebugReportCallbackEXT DestroyDebugReportCallbackEXT;
194 PFN_vkDebugReportMessageEXT DebugReportMessageEXT;
Ian Elliott7e40db92015-08-21 15:09:33 -0600195 PFN_vkGetPhysicalDeviceSurfaceSupportKHR GetPhysicalDeviceSurfaceSupportKHR;
Ian Elliott486c5502015-11-19 16:05:09 -0700196 PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR GetPhysicalDeviceSurfaceCapabilitiesKHR;
197 PFN_vkGetPhysicalDeviceSurfaceFormatsKHR GetPhysicalDeviceSurfaceFormatsKHR;
198 PFN_vkGetPhysicalDeviceSurfacePresentModesKHR GetPhysicalDeviceSurfacePresentModesKHR;
Ian Elliott919fa302015-11-24 15:39:10 -0700199#ifdef VK_USE_PLATFORM_WIN32_KHR
200 PFN_vkGetPhysicalDeviceWin32PresentationSupportKHR GetPhysicalDeviceWin32PresentationSupportKHR;
201#endif
202#ifdef VK_USE_PLATFORM_MIR_KHR
203 PFN_vkGetPhysicalDeviceMirPresentationSupportKHR GetPhysicalDeviceMirPresentvationSupportKHR;
204#endif
205#ifdef VK_USE_PLATFORM_WAYLAND_KHR
206 PFN_vkGetPhysicalDeviceWaylandPresentationSupportKHR GetPhysicalDeviceWaylandPresentationSupportKHR;
207#endif
208#ifdef VK_USE_PLATFORM_XCB_KHR
209 PFN_vkGetPhysicalDeviceXcbPresentationSupportKHR GetPhysicalDeviceXcbPresentationSupportKHR;
210#endif
211#ifdef VK_USE_PLATFORM_XLIB_KHR
212 PFN_vkGetPhysicalDeviceXlibPresentationSupportKHR GetPhysicalDeviceXlibPresentationSupportKHR;
213#endif
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -0600214
Jon Ashburndc6fcad2015-06-10 10:06:06 -0600215 struct loader_icd *next;
Jon Ashburn95a77ba2015-05-15 15:09:35 -0600216};
217
Jon Ashburn8810c5f2015-08-18 18:04:47 -0600218/* per ICD library structure */
219struct loader_icd_libs {
220 size_t capacity;
221 uint32_t count;
222 struct loader_scanned_icds *list;
223};
224
Jon Ashburn953bb3c2015-06-10 16:11:42 -0600225/* per instance structure */
Jon Ashburn27cd5842015-05-12 17:26:48 -0600226struct loader_instance {
Jon Ashburn95a77ba2015-05-15 15:09:35 -0600227 VkLayerInstanceDispatchTable *disp; // must be first entry in structure
228
Jon Ashburn27cd5842015-05-12 17:26:48 -0600229 uint32_t total_gpu_count;
Jon Ashburn24cd4be2015-11-01 14:04:06 -0700230 struct loader_physical_device *phys_devs;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600231 uint32_t total_icd_count;
Jon Ashburn27cd5842015-05-12 17:26:48 -0600232 struct loader_icd *icds;
233 struct loader_instance *next;
Jon Ashburn5c6a46f2015-08-14 14:49:22 -0600234 struct loader_extension_list ext_list; // icds and loaders extensions
Jon Ashburn8810c5f2015-08-18 18:04:47 -0600235 struct loader_icd_libs icd_libs;
Jon Ashburn3d002332015-08-20 16:35:30 -0600236 struct loader_layer_list instance_layer_list;
237 struct loader_layer_list device_layer_list;
Jon Ashburnfc1031e2015-11-17 15:31:02 -0700238 struct loader_dispatch_hash_entry disp_hash[MAX_NUM_DEV_EXTS];
Jon Ashburn3d002332015-08-20 16:35:30 -0600239
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600240 struct loader_msg_callback_map_entry *icd_msg_callback_map;
241
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -0600242 struct loader_layer_list activated_layer_list;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600243
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700244 VkInstance instance;
245
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600246 bool debug_report_enabled;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600247 VkLayerDbgFunctionNode *DbgFunctionHead;
Courtney Goeltzenleuchter7f5aafc2015-07-05 11:28:29 -0600248
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800249 VkAllocationCallbacks alloc_callbacks;
Ian Elliottd3ef02f2015-07-06 14:36:13 -0600250
Ian Elliott954fa342015-10-30 15:28:23 -0600251 bool wsi_surface_enabled;
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -0700252#ifdef VK_USE_PLATFORM_WIN32_KHR
Ian Elliott954fa342015-10-30 15:28:23 -0600253 bool wsi_win32_surface_enabled;
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -0700254#endif
255#ifdef VK_USE_PLATFORM_MIR_KHR
Ian Elliott954fa342015-10-30 15:28:23 -0600256 bool wsi_mir_surface_enabled;
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -0700257#endif
258#ifdef VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott954fa342015-10-30 15:28:23 -0600259 bool wsi_wayland_surface_enabled;
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -0700260#endif
261#ifdef VK_USE_PLATFORM_XCB_KHR
Ian Elliott954fa342015-10-30 15:28:23 -0600262 bool wsi_xcb_surface_enabled;
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -0700263#endif
264#ifdef VK_USE_PLATFORM_XLIB_KHR
Ian Elliott954fa342015-10-30 15:28:23 -0600265 bool wsi_xlib_surface_enabled;
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -0700266#endif
267#ifdef VK_USE_PLATFORM_ANDROID_KHR
268 bool wsi_android_surface_enabled;
269#endif
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600270};
271
Jon Ashburn24cd4be2015-11-01 14:04:06 -0700272/* per enumerated PhysicalDevice structure */
273struct loader_physical_device {
274 VkLayerInstanceDispatchTable *disp; // must be first entry in structure
275 struct loader_instance *this_instance;
276 struct loader_icd *this_icd;
277 VkPhysicalDevice phys_dev; // object from ICD
278 /*
279 * Fill in the cache of available device extensions from
Jon Ashburn00eb6c02015-11-02 17:40:01 -0700280 * this physical device. This cache can be used during CreateDevice
Jon Ashburn24cd4be2015-11-01 14:04:06 -0700281 */
282 struct loader_extension_list device_extension_cache;
283};
284
Jon Ashburn27cd5842015-05-12 17:26:48 -0600285struct loader_struct {
286 struct loader_instance *instances;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600287
288 unsigned int loaded_layer_lib_count;
Courtney Goeltzenleuchterdad30df2015-10-07 09:00:34 -0600289 size_t loaded_layer_lib_capacity;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600290 struct loader_lib_info *loaded_layer_lib_list;
Jon Ashburn8810c5f2015-08-18 18:04:47 -0600291 // TODO add ref counting of ICD libraries
Jon Ashburn2d0c4bb2015-07-06 15:40:35 -0600292 // TODO use this struct loader_layer_library_list scanned_layer_libraries;
Jon Ashburn8810c5f2015-08-18 18:04:47 -0600293 // TODO add list of icd libraries for ref counting them for closure
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600294};
295
296struct loader_scanned_icds {
297 char *lib_name;
298 loader_platform_dl_handle handle;
Jon Ashburn005617f2015-11-17 17:35:40 -0700299 uint32_t api_version;
Jon Ashburnc624c882015-07-16 10:17:29 -0600300 PFN_vkGetInstanceProcAddr GetInstanceProcAddr;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600301 PFN_vkCreateInstance CreateInstance;
Courtney Goeltzenleuchter35985f62015-09-14 17:22:16 -0600302 PFN_vkEnumerateInstanceExtensionProperties EnumerateInstanceExtensionProperties;
Jon Ashburn27cd5842015-05-12 17:26:48 -0600303};
304
Jon Ashburn5ef20602015-07-02 09:40:15 -0600305static inline struct loader_instance *loader_instance(VkInstance instance) {
306 return (struct loader_instance *) instance;
307}
308
Tony Barbour1d2cd3f2015-07-03 10:33:54 -0600309static inline void loader_set_dispatch(void* obj, const void *data)
Chia-I Wu5291c762015-04-11 15:34:07 +0800310{
311 *((const void **) obj) = data;
312}
313
Tony Barbour1d2cd3f2015-07-03 10:33:54 -0600314static inline VkLayerDispatchTable *loader_get_dispatch(const void* obj)
Chia-I Wu5291c762015-04-11 15:34:07 +0800315{
Jon Ashburn1ed042c2015-05-01 18:00:33 -0600316 return *((VkLayerDispatchTable **) obj);
Chia-I Wu5291c762015-04-11 15:34:07 +0800317}
318
Jon Ashburnfc1031e2015-11-17 15:31:02 -0700319static inline struct loader_dev_dispatch_table *loader_get_dev_dispatch(const void* obj)
320{
321 return *((struct loader_dev_dispatch_table **) obj);
322}
323
Tony Barbour1d2cd3f2015-07-03 10:33:54 -0600324static inline VkLayerInstanceDispatchTable *loader_get_instance_dispatch(const void* obj)
Jon Ashburn27cd5842015-05-12 17:26:48 -0600325{
326 return *((VkLayerInstanceDispatchTable **) obj);
327}
328
Tony Barbour1d2cd3f2015-07-03 10:33:54 -0600329static inline void loader_init_dispatch(void* obj, const void *data)
Chia-I Wu5291c762015-04-11 15:34:07 +0800330{
Jon Ashburn40066642015-04-15 13:34:33 -0600331#ifdef DEBUG
Chia-I Wu5291c762015-04-11 15:34:07 +0800332 assert(valid_loader_magic_value(obj) &&
333 "Incompatible ICD, first dword must be initialized to ICD_LOADER_MAGIC. See loader/README.md for details.");
Jon Ashburn40066642015-04-15 13:34:33 -0600334#endif
Chia-I Wu5291c762015-04-11 15:34:07 +0800335
Jon Ashburn1ed042c2015-05-01 18:00:33 -0600336 loader_set_dispatch(obj, data);
Chia-I Wu5291c762015-04-11 15:34:07 +0800337}
338
Jon Ashburn27cd5842015-05-12 17:26:48 -0600339/* global variables used across files */
340extern struct loader_struct loader;
Jon Ashburn87d6aa92015-08-28 15:19:27 -0600341extern THREAD_LOCAL_DECL struct loader_instance *tls_instance;
Jon Ashburn8810c5f2015-08-18 18:04:47 -0600342extern LOADER_PLATFORM_THREAD_ONCE_DEFINITION(once_init);
Jon Ashburn6301a0f2015-05-29 13:15:39 -0600343extern loader_platform_thread_mutex loader_lock;
Jon Ashburn6461ef22015-09-22 13:11:00 -0600344extern loader_platform_thread_mutex loader_json_lock;
Jon Ashburn6301a0f2015-05-29 13:15:39 -0600345extern const VkLayerInstanceDispatchTable instance_disp;
Jon Ashburnbacb0f52015-04-06 10:58:22 -0600346
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600347struct loader_msg_callback_map_entry {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700348 VkDebugReportCallbackEXT icd_obj;
349 VkDebugReportCallbackEXT loader_obj;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600350};
351
352bool compare_vk_extension_properties(
353 const VkExtensionProperties* op1,
354 const VkExtensionProperties* op2);
355
Jon Ashburn3d002332015-08-20 16:35:30 -0600356VkResult loader_validate_layers(
357 const uint32_t layer_count,
358 const char * const *ppEnabledLayerNames,
359 const struct loader_layer_list *list);
Courtney Goeltzenleuchter3b8c5ff2015-07-06 17:45:08 -0600360
361VkResult loader_validate_instance_extensions(
Jon Ashburn9a4c6aa2015-08-14 11:57:54 -0600362 const struct loader_extension_list *icd_exts,
Jon Ashburnb82c1852015-08-11 14:49:54 -0600363 const struct loader_layer_list *instance_layer,
Courtney Goeltzenleuchter3b8c5ff2015-07-06 17:45:08 -0600364 const VkInstanceCreateInfo* pCreateInfo);
365
Jon Ashburn27cd5842015-05-12 17:26:48 -0600366/* instance layer chain termination entrypoint definitions */
Chia-I Wu9ab61502015-11-06 06:42:02 +0800367VKAPI_ATTR VkResult VKAPI_CALL loader_CreateInstance(
Jon Ashburn27cd5842015-05-12 17:26:48 -0600368 const VkInstanceCreateInfo* pCreateInfo,
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800369 const VkAllocationCallbacks* pAllocator,
Jon Ashburn27cd5842015-05-12 17:26:48 -0600370 VkInstance* pInstance);
Chia-I Wu5291c762015-04-11 15:34:07 +0800371
Chia-I Wu9ab61502015-11-06 06:42:02 +0800372VKAPI_ATTR void VKAPI_CALL loader_DestroyInstance(
Chia-I Wuf7458c52015-10-26 21:10:41 +0800373 VkInstance instance,
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800374 const VkAllocationCallbacks* pAllocator);
Jon Ashburn27cd5842015-05-12 17:26:48 -0600375
Chia-I Wu9ab61502015-11-06 06:42:02 +0800376VKAPI_ATTR VkResult VKAPI_CALL loader_EnumeratePhysicalDevices(
Jon Ashburn27cd5842015-05-12 17:26:48 -0600377 VkInstance instance,
378 uint32_t* pPhysicalDeviceCount,
379 VkPhysicalDevice* pPhysicalDevices);
Chris Forbesbc0bb772015-06-21 22:55:02 +1200380
Chia-I Wu9ab61502015-11-06 06:42:02 +0800381VKAPI_ATTR void VKAPI_CALL loader_GetPhysicalDeviceFeatures(
Chris Forbesbc0bb772015-06-21 22:55:02 +1200382 VkPhysicalDevice physicalDevice,
383 VkPhysicalDeviceFeatures* pFeatures);
384
Chia-I Wu9ab61502015-11-06 06:42:02 +0800385VKAPI_ATTR void VKAPI_CALL loader_GetPhysicalDeviceFormatProperties(
Chris Forbesbc0bb772015-06-21 22:55:02 +1200386 VkPhysicalDevice physicalDevice,
387 VkFormat format,
388 VkFormatProperties* pFormatInfo);
389
Chia-I Wu9ab61502015-11-06 06:42:02 +0800390VKAPI_ATTR VkResult VKAPI_CALL loader_GetPhysicalDeviceImageFormatProperties(
Chia-I Wu17241042015-10-31 00:31:16 +0800391 VkPhysicalDevice physicalDevice,
Jon Ashburn754864f2015-07-23 18:49:07 -0600392 VkFormat format,
393 VkImageType type,
394 VkImageTiling tiling,
395 VkImageUsageFlags usage,
Courtney Goeltzenleuchtera22097a2015-09-10 13:44:12 -0600396 VkImageCreateFlags flags,
Jon Ashburn754864f2015-07-23 18:49:07 -0600397 VkImageFormatProperties* pImageFormatProperties);
398
Chia-I Wu9ab61502015-11-06 06:42:02 +0800399VKAPI_ATTR void VKAPI_CALL loader_GetPhysicalDeviceSparseImageFormatProperties(
Mark Lobodzinski16e8bef2015-07-03 15:58:09 -0600400 VkPhysicalDevice physicalDevice,
401 VkFormat format,
402 VkImageType type,
Chia-I Wu5c17c962015-10-31 00:31:16 +0800403 VkSampleCountFlagBits samples,
Mark Lobodzinski16e8bef2015-07-03 15:58:09 -0600404 VkImageUsageFlags usage,
405 VkImageTiling tiling,
406 uint32_t* pNumProperties,
407 VkSparseImageFormatProperties* pProperties);
Tony Barbour59a47322015-06-24 16:06:58 -0600408
Chia-I Wu9ab61502015-11-06 06:42:02 +0800409VKAPI_ATTR void VKAPI_CALL loader_GetPhysicalDeviceProperties (
Tony Barbour59a47322015-06-24 16:06:58 -0600410 VkPhysicalDevice physicalDevice,
411 VkPhysicalDeviceProperties* pProperties);
412
Chia-I Wu9ab61502015-11-06 06:42:02 +0800413VKAPI_ATTR VkResult VKAPI_CALL loader_EnumerateDeviceExtensionProperties (VkPhysicalDevice physicalDevice,
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -0600414 const char *pLayerName, uint32_t *pCount,
Tony Barbour59a47322015-06-24 16:06:58 -0600415 VkExtensionProperties* pProperties);
416
Chia-I Wu9ab61502015-11-06 06:42:02 +0800417VKAPI_ATTR VkResult VKAPI_CALL loader_EnumerateDeviceLayerProperties (VkPhysicalDevice physicalDevice,
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -0600418 uint32_t *pCount,
419 VkLayerProperties* pProperties);
Tony Barbour59a47322015-06-24 16:06:58 -0600420
Chia-I Wu9ab61502015-11-06 06:42:02 +0800421VKAPI_ATTR void VKAPI_CALL loader_GetPhysicalDeviceQueueFamilyProperties (
Cody Northropd0802882015-08-03 17:04:53 -0600422 VkPhysicalDevice physicalDevice,
423 uint32_t* pCount,
424 VkQueueFamilyProperties* pProperties);
Tony Barbour59a47322015-06-24 16:06:58 -0600425
Chia-I Wu9ab61502015-11-06 06:42:02 +0800426VKAPI_ATTR void VKAPI_CALL loader_GetPhysicalDeviceMemoryProperties (
Tony Barbour59a47322015-06-24 16:06:58 -0600427 VkPhysicalDevice physicalDevice,
428 VkPhysicalDeviceMemoryProperties * pProperties);
Jon Ashburn6301a0f2015-05-29 13:15:39 -0600429
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700430VkResult loader_create_device_terminator(
431 VkPhysicalDevice physicalDevice,
432 const VkDeviceCreateInfo* pCreateInfo,
433 const VkAllocationCallbacks* pAllocator,
434 VkDevice* pDevice);
435
Chia-I Wu9ab61502015-11-06 06:42:02 +0800436VKAPI_ATTR VkResult VKAPI_CALL loader_CreateDevice(
Jon Ashburn95a77ba2015-05-15 15:09:35 -0600437 VkPhysicalDevice gpu,
438 const VkDeviceCreateInfo* pCreateInfo,
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800439 const VkAllocationCallbacks* pAllocator,
Jon Ashburn95a77ba2015-05-15 15:09:35 -0600440 VkDevice* pDevice);
Jon Ashburn27cd5842015-05-12 17:26:48 -0600441
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600442/* helper function definitions */
Jon Ashburn8810c5f2015-08-18 18:04:47 -0600443void loader_initialize(void);
Jon Ashburnbd6c4882015-07-02 12:59:25 -0600444bool has_vk_extension_property_array(
445 const VkExtensionProperties *vk_ext_prop,
446 const uint32_t count,
447 const VkExtensionProperties *ext_array);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600448bool has_vk_extension_property(
449 const VkExtensionProperties *vk_ext_prop,
450 const struct loader_extension_list *ext_list);
Jon Ashburn27cd5842015-05-12 17:26:48 -0600451
Jon Ashburn24cd4be2015-11-01 14:04:06 -0700452VkResult loader_add_to_ext_list(
Jon Ashburne39a4f82015-08-28 13:38:21 -0600453 const struct loader_instance *inst,
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600454 struct loader_extension_list *ext_list,
455 uint32_t prop_list_count,
Jon Ashburn5c042ea2015-08-04 11:14:18 -0600456 const VkExtensionProperties *props);
Jon Ashburn6e6a2162015-12-10 08:51:10 -0700457void loader_destroy_generic_list(
Jon Ashburne39a4f82015-08-28 13:38:21 -0600458 const struct loader_instance *inst,
Jon Ashburn6e6a2162015-12-10 08:51:10 -0700459 struct loader_generic_list *list);
Jon Ashburne39a4f82015-08-28 13:38:21 -0600460void loader_delete_layer_properties(
461 const struct loader_instance *inst,
462 struct loader_layer_list *layer_list);
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -0600463void loader_add_to_layer_list(
Jon Ashburne39a4f82015-08-28 13:38:21 -0600464 const struct loader_instance *inst,
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -0600465 struct loader_layer_list *list,
466 uint32_t prop_list_count,
467 const struct loader_layer_properties *props);
Jon Ashburne39a4f82015-08-28 13:38:21 -0600468void loader_scanned_icd_clear(
469 const struct loader_instance *inst,
470 struct loader_icd_libs *icd_libs);
471void loader_icd_scan(
472 const struct loader_instance *inst,
473 struct loader_icd_libs *icds);
Jon Ashburnb82c1852015-08-11 14:49:54 -0600474void loader_layer_scan(
Jon Ashburne39a4f82015-08-28 13:38:21 -0600475 const struct loader_instance *inst,
Jon Ashburnb82c1852015-08-11 14:49:54 -0600476 struct loader_layer_list *instance_layers,
477 struct loader_layer_list *device_layers);
Jon Ashburn8810c5f2015-08-18 18:04:47 -0600478void loader_get_icd_loader_instance_extensions(
Jon Ashburne39a4f82015-08-28 13:38:21 -0600479 const struct loader_instance *inst,
Jon Ashburn8810c5f2015-08-18 18:04:47 -0600480 struct loader_icd_libs *icd_libs,
481 struct loader_extension_list *inst_exts);
Jon Ashburne39a4f82015-08-28 13:38:21 -0600482struct loader_icd *loader_get_icd_and_device(
483 const VkDevice device,
484 struct loader_device **found_dev);
Jon Ashburnfc1031e2015-11-17 15:31:02 -0700485void *loader_dev_ext_gpa(
486 struct loader_instance *inst,
487 const char *funcName);
488void *loader_get_dev_ext_trampoline(
489 uint32_t index);
Jon Ashburne0e64572015-09-30 12:56:42 -0600490struct loader_instance *loader_get_instance(
491 const VkInstance instance);
Jon Ashburne39a4f82015-08-28 13:38:21 -0600492void loader_remove_logical_device(
493 const struct loader_instance *inst,
Jon Ashburn781a7ae2015-11-19 15:43:26 -0700494 struct loader_icd *icd,
495 struct loader_device *found_dev);
Jon Ashburnb82c1852015-08-11 14:49:54 -0600496VkResult loader_enable_instance_layers(
497 struct loader_instance *inst,
498 const VkInstanceCreateInfo *pCreateInfo,
499 const struct loader_layer_list *instance_layers);
Jon Ashburndc6fcad2015-06-10 10:06:06 -0600500void loader_deactivate_instance_layers(struct loader_instance *instance);
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700501
502VkResult loader_create_instance_chain(const VkInstanceCreateInfo *pCreateInfo,
503 const VkAllocationCallbacks* pAllocator,
504 struct loader_instance *inst);
505
Jon Ashburn5f556602016-01-12 09:55:14 -0700506void loader_activate_instance_layer_extensions(struct loader_instance *inst, VkInstance created_inst);
Courtney Goeltzenleuchter7f5aafc2015-07-05 11:28:29 -0600507
508void* loader_heap_alloc(
Jon Ashburne39a4f82015-08-28 13:38:21 -0600509 const struct loader_instance *instance,
Jon Ashburnb82c1852015-08-11 14:49:54 -0600510 size_t size,
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800511 VkSystemAllocationScope allocationScope);
Courtney Goeltzenleuchter7f5aafc2015-07-05 11:28:29 -0600512
Courtney Goeltzenleuchter7f5aafc2015-07-05 11:28:29 -0600513void loader_heap_free(
Jon Ashburne39a4f82015-08-28 13:38:21 -0600514 const struct loader_instance *instance,
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800515 void *pMemory);
Jon Ashburn87d6aa92015-08-28 15:19:27 -0600516
517void *loader_tls_heap_alloc(size_t size);
518
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800519void loader_tls_heap_free(void *pMemory);
Chia-I Wu19300602014-08-04 08:03:57 +0800520#endif /* LOADER_H */