blob: 19d28e10e0aa75547538626753a578ea3566ae6f [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 Ashburn3ebf1252016-04-19 11:30:31 -06008 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
Chia-I Wu19300602014-08-04 08:03:57 +080011 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -060012 * http://www.apache.org/licenses/LICENSE-2.0
Chia-I Wu19300602014-08-04 08:03:57 +080013 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -060014 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
Jon Ashburn23d36b12016-02-02 17:47:28 -070019 *
20 * Author: Jon Ashburn <jon@lunarg.com>
21 * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
Courtney Goeltzenleuchter05559522015-10-30 11:14:30 -060022 * Author: Chia-I Wu <olvaffe@gmail.com>
23 * Author: Chia-I Wu <olv@lunarg.com>
Jon Ashburn23d36b12016-02-02 17:47:28 -070024 * Author: Mark Lobodzinski <mark@LunarG.com>
Courtney Goeltzenleuchter05559522015-10-30 11:14:30 -060025 *
Chia-I Wu19300602014-08-04 08:03:57 +080026 */
27
28#ifndef LOADER_H
29#define LOADER_H
30
David Pinedo9316d3b2015-11-06 12:54:48 -070031#include <vulkan/vulkan.h>
Aaron Karp848bad42016-03-13 16:41:59 -040032#include "vk_loader_platform.h"
Mark Lobodzinskib87f9022016-05-24 16:04:56 -060033#include "vk_loader_layer.h"
David Pinedo9316d3b2015-11-06 12:54:48 -070034#include <vulkan/vk_layer.h>
Mark Lobodzinskib87f9022016-05-24 16:04:56 -060035
David Pinedo9316d3b2015-11-06 12:54:48 -070036#include <vulkan/vk_icd.h>
Chia-I Wu5291c762015-04-11 15:34:07 +080037#include <assert.h>
38
Chia-I Wu19300602014-08-04 08:03:57 +080039#if defined(__GNUC__) && __GNUC__ >= 4
Jon Ashburn23d36b12016-02-02 17:47:28 -070040#define LOADER_EXPORT __attribute__((visibility("default")))
Chia-I Wu19300602014-08-04 08:03:57 +080041#elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)
Jon Ashburn23d36b12016-02-02 17:47:28 -070042#define LOADER_EXPORT __attribute__((visibility("default")))
Chia-I Wu19300602014-08-04 08:03:57 +080043#else
Jon Ashburn23d36b12016-02-02 17:47:28 -070044#define LOADER_EXPORT
Chia-I Wu19300602014-08-04 08:03:57 +080045#endif
46
Mark Young0ad83132016-06-30 13:02:42 -060047// A debug option to disable allocators at compile time to investigate future issues.
48#define DEBUG_DISABLE_APP_ALLOCATORS 0
49
Jon Ashburnf73e9212015-08-04 10:22:33 -060050#define MAX_STRING_SIZE 1024
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -060051#define VK_MAJOR(version) (version >> 22)
52#define VK_MINOR(version) ((version >> 12) & 0x3ff)
53#define VK_PATCH(version) (version & 0xfff)
Jon Ashburn27cd5842015-05-12 17:26:48 -060054
Jon Ashburn5ef20602015-07-02 09:40:15 -060055enum layer_type {
Jon Ashburn491cd042016-05-16 14:01:18 -060056 VK_LAYER_TYPE_INSTANCE_EXPLICIT = 0x1,
57 VK_LAYER_TYPE_INSTANCE_IMPLICIT = 0x2,
58 VK_LAYER_TYPE_META_EXPLICT = 0x4,
Jon Ashburn5ef20602015-07-02 09:40:15 -060059};
60
Mark Lobodzinskie9f09ef2016-02-02 18:53:34 -070061typedef enum VkStringErrorFlagBits {
Jon Ashburnf2b4e382016-02-10 20:50:19 -070062 VK_STRING_ERROR_NONE = 0x00000000,
63 VK_STRING_ERROR_LENGTH = 0x00000001,
64 VK_STRING_ERROR_BAD_DATA = 0x00000002,
Mark Lobodzinskie9f09ef2016-02-02 18:53:34 -070065} VkStringErrorFlagBits;
66typedef VkFlags VkStringErrorFlags;
67
Jon Ashburnf2b4e382016-02-10 20:50:19 -070068static const int MaxLoaderStringLength = 256;
69static const char UTF8_ONE_BYTE_CODE = 0xC0;
70static const char UTF8_ONE_BYTE_MASK = 0xE0;
71static const char UTF8_TWO_BYTE_CODE = 0xE0;
72static const char UTF8_TWO_BYTE_MASK = 0xF0;
73static const char UTF8_THREE_BYTE_CODE = 0xF0;
74static const char UTF8_THREE_BYTE_MASK = 0xF8;
75static const char UTF8_DATA_BYTE_CODE = 0x80;
76static const char UTF8_DATA_BYTE_MASK = 0xC0;
Mark Lobodzinskie9f09ef2016-02-02 18:53:34 -070077
Mark Lobodzinskied566c32016-06-29 14:18:30 -060078static const char std_validation_names[7][VK_MAX_EXTENSION_NAME_SIZE] = {
79 "VK_LAYER_GOOGLE_threading", "VK_LAYER_LUNARG_parameter_validation",
80 "VK_LAYER_LUNARG_object_tracker", "VK_LAYER_LUNARG_image",
81 "VK_LAYER_LUNARG_core_validation", "VK_LAYER_LUNARG_swapchain",
82 "VK_LAYER_GOOGLE_unique_objects"};
Jon Ashburn86a527a2016-02-10 20:59:26 -070083
Jon Ashburn6e6a2162015-12-10 08:51:10 -070084// form of all dynamic lists/arrays
85// only the list element should be changed
86struct loader_generic_list {
87 size_t capacity;
88 uint32_t count;
89 void *list;
90};
91
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -060092struct loader_extension_list {
93 size_t capacity;
94 uint32_t count;
Jon Ashburn5c042ea2015-08-04 11:14:18 -060095 VkExtensionProperties *list;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -060096};
97
Jon Ashburn39fbd4e2015-12-10 18:17:34 -070098struct loader_dev_ext_props {
99 VkExtensionProperties props;
100 uint32_t entrypoint_count;
101 char **entrypoints;
102};
103
104struct loader_device_extension_list {
105 size_t capacity;
106 uint32_t count;
107 struct loader_dev_ext_props *list;
108};
109
Jon Ashburn5ef20602015-07-02 09:40:15 -0600110struct loader_name_value {
Jon Ashburnf73e9212015-08-04 10:22:33 -0600111 char name[MAX_STRING_SIZE];
112 char value[MAX_STRING_SIZE];
Jon Ashburn5ef20602015-07-02 09:40:15 -0600113};
114
Jon Ashburn5ef20602015-07-02 09:40:15 -0600115struct loader_layer_functions {
Jon Ashburnf73e9212015-08-04 10:22:33 -0600116 char str_gipa[MAX_STRING_SIZE];
117 char str_gdpa[MAX_STRING_SIZE];
Jon Ashburn5ef20602015-07-02 09:40:15 -0600118 PFN_vkGetInstanceProcAddr get_instance_proc_addr;
119 PFN_vkGetDeviceProcAddr get_device_proc_addr;
120};
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600121
Jon Ashburn5ef20602015-07-02 09:40:15 -0600122struct loader_layer_properties {
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -0600123 VkLayerProperties info;
Jon Ashburn5ef20602015-07-02 09:40:15 -0600124 enum layer_type type;
Jon Ashburn3d002332015-08-20 16:35:30 -0600125 char lib_name[MAX_STRING_SIZE];
Jon Ashburn4dc1d8a2016-04-20 13:21:17 -0600126 loader_platform_dl_handle lib_handle;
Jon Ashburn5ef20602015-07-02 09:40:15 -0600127 struct loader_layer_functions functions;
128 struct loader_extension_list instance_extension_list;
Jon Ashburn39fbd4e2015-12-10 18:17:34 -0700129 struct loader_device_extension_list device_extension_list;
Jon Ashburn5ef20602015-07-02 09:40:15 -0600130 struct loader_name_value disable_env_var;
131 struct loader_name_value enable_env_var;
132};
133
134struct loader_layer_list {
135 size_t capacity;
136 uint32_t count;
137 struct loader_layer_properties *list;
Jon Ashburn27cd5842015-05-12 17:26:48 -0600138};
139
Jon Ashburnfc1031e2015-11-17 15:31:02 -0700140struct loader_dispatch_hash_list {
141 size_t capacity;
142 uint32_t count;
Jon Ashburn23d36b12016-02-02 17:47:28 -0700143 uint32_t *index; // index into the dev_ext dispatch table
Jon Ashburnfc1031e2015-11-17 15:31:02 -0700144};
145
146#define MAX_NUM_DEV_EXTS 250
Mark Young8191d9f2016-09-02 11:41:28 -0600147// loader_dispatch_hash_entry and loader_dev_ext_dispatch_table.dev_ext have
148// one to one correspondence; one loader_dispatch_hash_entry for one dev_ext
149// dispatch entry.
Jon Ashburnfc1031e2015-11-17 15:31:02 -0700150// Also have a one to one correspondence with functions in dev_ext_trampoline.c
151struct loader_dispatch_hash_entry {
152 char *func_name;
Jon Ashburn23d36b12016-02-02 17:47:28 -0700153 struct loader_dispatch_hash_list list; // to handle hashing collisions
Jon Ashburnfc1031e2015-11-17 15:31:02 -0700154};
155
Jon Ashburn23d36b12016-02-02 17:47:28 -0700156typedef void(VKAPI_PTR *PFN_vkDevExt)(VkDevice device);
Jon Ashburnfc1031e2015-11-17 15:31:02 -0700157struct loader_dev_ext_dispatch_table {
Mark Young8191d9f2016-09-02 11:41:28 -0600158 PFN_vkDevExt dev_ext[MAX_NUM_DEV_EXTS];
Jon Ashburnfc1031e2015-11-17 15:31:02 -0700159};
160
161struct loader_dev_dispatch_table {
162 VkLayerDispatchTable core_dispatch;
163 struct loader_dev_ext_dispatch_table ext_dispatch;
164};
165
Mark Young35159af2016-09-07 08:50:32 -0600166// per CreateDevice structure
Jon Ashburndc6fcad2015-06-10 10:06:06 -0600167struct loader_device {
Jon Ashburnfc1031e2015-11-17 15:31:02 -0700168 struct loader_dev_dispatch_table loader_dispatch;
Jon Ashburn23d36b12016-02-02 17:47:28 -0700169 VkDevice device; // device object from the icd
Jon Ashburndc6fcad2015-06-10 10:06:06 -0600170
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -0600171 struct loader_layer_list activated_layer_list;
Jon Ashburndc6fcad2015-06-10 10:06:06 -0600172
Mark Young0ad83132016-06-30 13:02:42 -0600173 VkAllocationCallbacks alloc_callbacks;
174
Jon Ashburndc6fcad2015-06-10 10:06:06 -0600175 struct loader_device *next;
176};
177
Jon Ashburn953bb3c2015-06-10 16:11:42 -0600178/* per ICD structure */
Jon Ashburn95a77ba2015-05-15 15:09:35 -0600179struct loader_icd {
Jon Ashburn3d002332015-08-20 16:35:30 -0600180 // pointers to find other structs
181 const struct loader_scanned_icds *this_icd_lib;
182 const struct loader_instance *this_instance;
Jon Ashburndc6fcad2015-06-10 10:06:06 -0600183 struct loader_device *logical_device_list;
Jon Ashburn23d36b12016-02-02 17:47:28 -0700184 VkInstance instance; // instance object from the icd
Jon Ashburn8d1b0b52015-05-18 13:20:15 -0600185 PFN_vkGetDeviceProcAddr GetDeviceProcAddr;
Jon Ashburn95a77ba2015-05-15 15:09:35 -0600186 PFN_vkDestroyInstance DestroyInstance;
187 PFN_vkEnumeratePhysicalDevices EnumeratePhysicalDevices;
Chris Forbesbc0bb772015-06-21 22:55:02 +1200188 PFN_vkGetPhysicalDeviceFeatures GetPhysicalDeviceFeatures;
Courtney Goeltzenleuchter2caec862015-07-12 12:52:09 -0600189 PFN_vkGetPhysicalDeviceFormatProperties GetPhysicalDeviceFormatProperties;
Jon Ashburn23d36b12016-02-02 17:47:28 -0700190 PFN_vkGetPhysicalDeviceImageFormatProperties
191 GetPhysicalDeviceImageFormatProperties;
Jon Ashburn95a77ba2015-05-15 15:09:35 -0600192 PFN_vkCreateDevice CreateDevice;
Tony Barbour59a47322015-06-24 16:06:58 -0600193 PFN_vkGetPhysicalDeviceProperties GetPhysicalDeviceProperties;
Jon Ashburn23d36b12016-02-02 17:47:28 -0700194 PFN_vkGetPhysicalDeviceQueueFamilyProperties
195 GetPhysicalDeviceQueueFamilyProperties;
Tony Barbour59a47322015-06-24 16:06:58 -0600196 PFN_vkGetPhysicalDeviceMemoryProperties GetPhysicalDeviceMemoryProperties;
Courtney Goeltzenleuchter35985f62015-09-14 17:22:16 -0600197 PFN_vkEnumerateDeviceExtensionProperties EnumerateDeviceExtensionProperties;
Jon Ashburn23d36b12016-02-02 17:47:28 -0700198 PFN_vkGetPhysicalDeviceSparseImageFormatProperties
199 GetPhysicalDeviceSparseImageFormatProperties;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700200 PFN_vkCreateDebugReportCallbackEXT CreateDebugReportCallbackEXT;
201 PFN_vkDestroyDebugReportCallbackEXT DestroyDebugReportCallbackEXT;
202 PFN_vkDebugReportMessageEXT DebugReportMessageEXT;
Ian Elliott7e40db92015-08-21 15:09:33 -0600203 PFN_vkGetPhysicalDeviceSurfaceSupportKHR GetPhysicalDeviceSurfaceSupportKHR;
Jon Ashburn23d36b12016-02-02 17:47:28 -0700204 PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR
205 GetPhysicalDeviceSurfaceCapabilitiesKHR;
Ian Elliott486c5502015-11-19 16:05:09 -0700206 PFN_vkGetPhysicalDeviceSurfaceFormatsKHR GetPhysicalDeviceSurfaceFormatsKHR;
Jon Ashburn23d36b12016-02-02 17:47:28 -0700207 PFN_vkGetPhysicalDeviceSurfacePresentModesKHR
208 GetPhysicalDeviceSurfacePresentModesKHR;
Mark Lobodzinski317574e2016-08-29 14:21:14 -0600209 PFN_vkGetPhysicalDeviceExternalImageFormatPropertiesNV
210 GetPhysicalDeviceExternalImageFormatPropertiesNV;
Ian Elliott919fa302015-11-24 15:39:10 -0700211#ifdef VK_USE_PLATFORM_WIN32_KHR
Jon Ashburn23d36b12016-02-02 17:47:28 -0700212 PFN_vkGetPhysicalDeviceWin32PresentationSupportKHR
213 GetPhysicalDeviceWin32PresentationSupportKHR;
Ian Elliott919fa302015-11-24 15:39:10 -0700214#endif
215#ifdef VK_USE_PLATFORM_MIR_KHR
Jon Ashburn23d36b12016-02-02 17:47:28 -0700216 PFN_vkGetPhysicalDeviceMirPresentationSupportKHR
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -0600217 GetPhysicalDeviceMirPresentationSupportKHR;
Ian Elliott919fa302015-11-24 15:39:10 -0700218#endif
219#ifdef VK_USE_PLATFORM_WAYLAND_KHR
Jon Ashburn23d36b12016-02-02 17:47:28 -0700220 PFN_vkGetPhysicalDeviceWaylandPresentationSupportKHR
221 GetPhysicalDeviceWaylandPresentationSupportKHR;
Ian Elliott919fa302015-11-24 15:39:10 -0700222#endif
223#ifdef VK_USE_PLATFORM_XCB_KHR
Jon Ashburn23d36b12016-02-02 17:47:28 -0700224 PFN_vkGetPhysicalDeviceXcbPresentationSupportKHR
225 GetPhysicalDeviceXcbPresentationSupportKHR;
Ian Elliott919fa302015-11-24 15:39:10 -0700226#endif
227#ifdef VK_USE_PLATFORM_XLIB_KHR
Jon Ashburn23d36b12016-02-02 17:47:28 -0700228 PFN_vkGetPhysicalDeviceXlibPresentationSupportKHR
229 GetPhysicalDeviceXlibPresentationSupportKHR;
Ian Elliott919fa302015-11-24 15:39:10 -0700230#endif
Jon Ashburnc7d3e732016-03-08 09:30:30 -0700231 PFN_vkGetPhysicalDeviceDisplayPropertiesKHR
232 GetPhysicalDeviceDisplayPropertiesKHR;
233 PFN_vkGetPhysicalDeviceDisplayPlanePropertiesKHR
234 GetPhysicalDeviceDisplayPlanePropertiesKHR;
235 PFN_vkGetDisplayPlaneSupportedDisplaysKHR
236 GetDisplayPlaneSupportedDisplaysKHR;
Jon Ashburncc407a22016-04-15 09:25:03 -0600237 PFN_vkGetDisplayModePropertiesKHR GetDisplayModePropertiesKHR;
238 PFN_vkCreateDisplayModeKHR CreateDisplayModeKHR;
239 PFN_vkGetDisplayPlaneCapabilitiesKHR GetDisplayPlaneCapabilitiesKHR;
240 PFN_vkCreateDisplayPlaneSurfaceKHR CreateDisplayPlaneSurfaceKHR;
241 PFN_vkDestroySurfaceKHR DestroySurfaceKHR;
Jon Ashburndc6fcad2015-06-10 10:06:06 -0600242 struct loader_icd *next;
Jon Ashburn95a77ba2015-05-15 15:09:35 -0600243};
244
Mark Young35159af2016-09-07 08:50:32 -0600245// per ICD library structure
Jon Ashburn8810c5f2015-08-18 18:04:47 -0600246struct loader_icd_libs {
247 size_t capacity;
248 uint32_t count;
249 struct loader_scanned_icds *list;
250};
251
Mark Young35159af2016-09-07 08:50:32 -0600252union loader_instance_extension_enables {
253 struct {
254 uint8_t ext_debug_report : 1;
255 uint8_t nv_external_memory_capabilities : 1;
256 };
257 uint64_t padding[4];
258};
259
260// per instance structure
Jon Ashburn27cd5842015-05-12 17:26:48 -0600261struct loader_instance {
Jon Ashburn95a77ba2015-05-15 15:09:35 -0600262 VkLayerInstanceDispatchTable *disp; // must be first entry in structure
263
Jon Ashburn014438f2016-03-01 19:51:07 -0700264 uint32_t total_gpu_count; // count of the next two arrays
265 struct loader_physical_device *phys_devs_term;
Jon Ashburncc407a22016-04-15 09:25:03 -0600266 struct loader_physical_device_tramp *
267 phys_devs; // tramp wrapped physDev obj list
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600268 uint32_t total_icd_count;
Jon Ashburn27cd5842015-05-12 17:26:48 -0600269 struct loader_icd *icds;
270 struct loader_instance *next;
Jon Ashburn23d36b12016-02-02 17:47:28 -0700271 struct loader_extension_list ext_list; // icds and loaders extensions
Mark Young35159af2016-09-07 08:50:32 -0600272 union loader_instance_extension_enables enabled_known_extensions;
Jon Ashburn8810c5f2015-08-18 18:04:47 -0600273 struct loader_icd_libs icd_libs;
Jon Ashburn3d002332015-08-20 16:35:30 -0600274 struct loader_layer_list instance_layer_list;
Jon Ashburnfc1031e2015-11-17 15:31:02 -0700275 struct loader_dispatch_hash_entry disp_hash[MAX_NUM_DEV_EXTS];
Jon Ashburn3d002332015-08-20 16:35:30 -0600276
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600277 struct loader_msg_callback_map_entry *icd_msg_callback_map;
278
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -0600279 struct loader_layer_list activated_layer_list;
Jon Ashburn491cd042016-05-16 14:01:18 -0600280 bool activated_layers_are_std_val;
Jon Ashburncc407a22016-04-15 09:25:03 -0600281 VkInstance instance; // layers/ICD instance returned to trampoline
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700282
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600283 VkLayerDbgFunctionNode *DbgFunctionHead;
Ian Elliottad6300f2016-03-31 10:48:19 -0600284 uint32_t num_tmp_callbacks;
285 VkDebugReportCallbackCreateInfoEXT *tmp_dbg_create_infos;
286 VkDebugReportCallbackEXT *tmp_callbacks;
Courtney Goeltzenleuchter7f5aafc2015-07-05 11:28:29 -0600287
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800288 VkAllocationCallbacks alloc_callbacks;
Ian Elliottd3ef02f2015-07-06 14:36:13 -0600289
Ian Elliott954fa342015-10-30 15:28:23 -0600290 bool wsi_surface_enabled;
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -0700291#ifdef VK_USE_PLATFORM_WIN32_KHR
Ian Elliott954fa342015-10-30 15:28:23 -0600292 bool wsi_win32_surface_enabled;
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -0700293#endif
294#ifdef VK_USE_PLATFORM_MIR_KHR
Ian Elliott954fa342015-10-30 15:28:23 -0600295 bool wsi_mir_surface_enabled;
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -0700296#endif
297#ifdef VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott954fa342015-10-30 15:28:23 -0600298 bool wsi_wayland_surface_enabled;
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -0700299#endif
300#ifdef VK_USE_PLATFORM_XCB_KHR
Ian Elliott954fa342015-10-30 15:28:23 -0600301 bool wsi_xcb_surface_enabled;
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -0700302#endif
303#ifdef VK_USE_PLATFORM_XLIB_KHR
Ian Elliott954fa342015-10-30 15:28:23 -0600304 bool wsi_xlib_surface_enabled;
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -0700305#endif
306#ifdef VK_USE_PLATFORM_ANDROID_KHR
307 bool wsi_android_surface_enabled;
308#endif
Jon Ashburnc7d3e732016-03-08 09:30:30 -0700309 bool wsi_display_enabled;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600310};
311
Jon Ashburn014438f2016-03-01 19:51:07 -0700312/* VkPhysicalDevice requires special treatment by loader. Firstly, terminator
313 * code must be able to get the struct loader_icd to call into the proper
314 * driver (multiple ICD/gpu case). This can be accomplished by wrapping the
315 * created VkPhysicalDevice in loader terminate_EnumeratePhysicalDevices().
Piers Daniell295fe402016-03-29 11:51:11 -0600316 * Secondly, the loader must be able to handle wrapped by layer VkPhysicalDevice
Jon Ashburn014438f2016-03-01 19:51:07 -0700317 * in trampoline code. This implies, that the loader trampoline code must also
318 * wrap the VkPhysicalDevice object in trampoline code. Thus, loader has to
319 * wrap the VkPhysicalDevice created object twice. In trampoline code it can't
320 * rely on the terminator object wrapping since a layer may also wrap. Since
321 * trampoline code wraps the VkPhysicalDevice this means all loader trampoline
322 * code that passes a VkPhysicalDevice should unwrap it. */
323
324/* per enumerated PhysicalDevice structure, used to wrap in trampoline code and
325 also same structure used to wrap in terminator code */
Jon Ashburn787eb252016-03-24 15:49:57 -0600326struct loader_physical_device_tramp {
327 VkLayerInstanceDispatchTable *disp; // must be first entry in structure
Piers Daniell295fe402016-03-29 11:51:11 -0600328 struct loader_instance *this_instance;
Jon Ashburncc407a22016-04-15 09:25:03 -0600329 VkPhysicalDevice phys_dev; // object from layers/loader terminator
Jon Ashburn787eb252016-03-24 15:49:57 -0600330};
331
332/* per enumerated PhysicalDevice structure, used to wrap in terminator code */
Jon Ashburn24cd4be2015-11-01 14:04:06 -0700333struct loader_physical_device {
334 VkLayerInstanceDispatchTable *disp; // must be first entry in structure
Jon Ashburn24cd4be2015-11-01 14:04:06 -0700335 struct loader_icd *this_icd;
Jon Ashburn787eb252016-03-24 15:49:57 -0600336 VkPhysicalDevice phys_dev; // object from ICD
Jon Ashburn24cd4be2015-11-01 14:04:06 -0700337};
338
Jon Ashburn27cd5842015-05-12 17:26:48 -0600339struct loader_struct {
340 struct loader_instance *instances;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600341};
342
343struct loader_scanned_icds {
344 char *lib_name;
345 loader_platform_dl_handle handle;
Jon Ashburn005617f2015-11-17 17:35:40 -0700346 uint32_t api_version;
Jon Ashburn17b4c862016-04-25 11:09:37 -0600347 uint32_t interface_version;
Jon Ashburnc624c882015-07-16 10:17:29 -0600348 PFN_vkGetInstanceProcAddr GetInstanceProcAddr;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600349 PFN_vkCreateInstance CreateInstance;
Jon Ashburn23d36b12016-02-02 17:47:28 -0700350 PFN_vkEnumerateInstanceExtensionProperties
351 EnumerateInstanceExtensionProperties;
Jon Ashburn27cd5842015-05-12 17:26:48 -0600352};
353
Jon Ashburn5ef20602015-07-02 09:40:15 -0600354static inline struct loader_instance *loader_instance(VkInstance instance) {
Jon Ashburn23d36b12016-02-02 17:47:28 -0700355 return (struct loader_instance *)instance;
Jon Ashburn5ef20602015-07-02 09:40:15 -0600356}
357
Jon Ashburn014438f2016-03-01 19:51:07 -0700358static inline VkPhysicalDevice
359loader_unwrap_physical_device(VkPhysicalDevice physicalDevice) {
Piers Daniell61e45382016-03-31 14:47:57 -0600360 struct loader_physical_device_tramp *phys_dev =
361 (struct loader_physical_device_tramp *)physicalDevice;
Jon Ashburn014438f2016-03-01 19:51:07 -0700362 return phys_dev->phys_dev;
363}
364
Jon Ashburn23d36b12016-02-02 17:47:28 -0700365static inline void loader_set_dispatch(void *obj, const void *data) {
366 *((const void **)obj) = data;
Chia-I Wu5291c762015-04-11 15:34:07 +0800367}
368
Jon Ashburn23d36b12016-02-02 17:47:28 -0700369static inline VkLayerDispatchTable *loader_get_dispatch(const void *obj) {
370 return *((VkLayerDispatchTable **)obj);
Chia-I Wu5291c762015-04-11 15:34:07 +0800371}
372
Jon Ashburn23d36b12016-02-02 17:47:28 -0700373static inline struct loader_dev_dispatch_table *
374loader_get_dev_dispatch(const void *obj) {
375 return *((struct loader_dev_dispatch_table **)obj);
Jon Ashburnfc1031e2015-11-17 15:31:02 -0700376}
377
Jon Ashburn23d36b12016-02-02 17:47:28 -0700378static inline VkLayerInstanceDispatchTable *
379loader_get_instance_dispatch(const void *obj) {
380 return *((VkLayerInstanceDispatchTable **)obj);
Jon Ashburn27cd5842015-05-12 17:26:48 -0600381}
382
Jon Ashburn23d36b12016-02-02 17:47:28 -0700383static inline void loader_init_dispatch(void *obj, const void *data) {
Jon Ashburn40066642015-04-15 13:34:33 -0600384#ifdef DEBUG
Chia-I Wu5291c762015-04-11 15:34:07 +0800385 assert(valid_loader_magic_value(obj) &&
Jon Ashburn23d36b12016-02-02 17:47:28 -0700386 "Incompatible ICD, first dword must be initialized to "
387 "ICD_LOADER_MAGIC. See loader/README.md for details.");
Jon Ashburn40066642015-04-15 13:34:33 -0600388#endif
Chia-I Wu5291c762015-04-11 15:34:07 +0800389
Jon Ashburn1ed042c2015-05-01 18:00:33 -0600390 loader_set_dispatch(obj, data);
Chia-I Wu5291c762015-04-11 15:34:07 +0800391}
392
Jon Ashburn27cd5842015-05-12 17:26:48 -0600393/* global variables used across files */
394extern struct loader_struct loader;
Jon Ashburn87d6aa92015-08-28 15:19:27 -0600395extern THREAD_LOCAL_DECL struct loader_instance *tls_instance;
Jon Ashburn8810c5f2015-08-18 18:04:47 -0600396extern LOADER_PLATFORM_THREAD_ONCE_DEFINITION(once_init);
Jon Ashburn6301a0f2015-05-29 13:15:39 -0600397extern loader_platform_thread_mutex loader_lock;
Jon Ashburn6461ef22015-09-22 13:11:00 -0600398extern loader_platform_thread_mutex loader_json_lock;
Jon Ashburn6301a0f2015-05-29 13:15:39 -0600399extern const VkLayerInstanceDispatchTable instance_disp;
Jon Ashburn86a527a2016-02-10 20:59:26 -0700400extern const char *std_validation_str;
Jon Ashburnbacb0f52015-04-06 10:58:22 -0600401
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600402struct loader_msg_callback_map_entry {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700403 VkDebugReportCallbackEXT icd_obj;
404 VkDebugReportCallbackEXT loader_obj;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600405};
406
Jon Ashburn1530c342016-02-26 13:14:27 -0700407/* helper function definitions */
Mark Young0ad83132016-06-30 13:02:42 -0600408void *loader_instance_heap_alloc(const struct loader_instance *instance, size_t size, VkSystemAllocationScope allocationScope);
409void loader_instance_heap_free(const struct loader_instance *instance, void *pMemory);
410void *loader_instance_heap_realloc(const struct loader_instance *instance, void *pMemory, size_t orig_size, size_t size, VkSystemAllocationScope alloc_scope);
411void *loader_instance_tls_heap_alloc(size_t size);
412void loader_instance_tls_heap_free(void *pMemory);
413void *loader_device_heap_alloc(const struct loader_device *device, size_t size, VkSystemAllocationScope allocationScope);
414void loader_device_heap_free(const struct loader_device *device, void *pMemory);
415void *loader_device_heap_realloc(const struct loader_device *device, void *pMemory, size_t orig_size, size_t size, VkSystemAllocationScope alloc_scope);
Jon Ashburn1530c342016-02-26 13:14:27 -0700416
Jon Ashburn2e37d752016-02-12 08:20:06 -0700417void loader_log(const struct loader_instance *inst, VkFlags msg_type,
Jon Ashburn1530c342016-02-26 13:14:27 -0700418 int32_t msg_code, const char *format, ...);
Jon Ashburn2e37d752016-02-12 08:20:06 -0700419
Jon Ashburn23d36b12016-02-02 17:47:28 -0700420bool compare_vk_extension_properties(const VkExtensionProperties *op1,
421 const VkExtensionProperties *op2);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600422
Mark Lobodzinskie9f09ef2016-02-02 18:53:34 -0700423VkResult loader_validate_layers(const struct loader_instance *inst,
424 const uint32_t layer_count,
Jon Ashburn23d36b12016-02-02 17:47:28 -0700425 const char *const *ppEnabledLayerNames,
426 const struct loader_layer_list *list);
Courtney Goeltzenleuchter3b8c5ff2015-07-06 17:45:08 -0600427
428VkResult loader_validate_instance_extensions(
Mark Lobodzinskie9f09ef2016-02-02 18:53:34 -0700429 const struct loader_instance *inst,
Jon Ashburn23d36b12016-02-02 17:47:28 -0700430 const struct loader_extension_list *icd_exts,
431 const struct loader_layer_list *instance_layer,
432 const VkInstanceCreateInfo *pCreateInfo);
Courtney Goeltzenleuchter3b8c5ff2015-07-06 17:45:08 -0600433
Jon Ashburn8810c5f2015-08-18 18:04:47 -0600434void loader_initialize(void);
Mark Young0ad83132016-06-30 13:02:42 -0600435VkResult loader_copy_layer_properties(const struct loader_instance *inst,
436 struct loader_layer_properties *dst,
437 struct loader_layer_properties *src);
Jon Ashburn23d36b12016-02-02 17:47:28 -0700438bool has_vk_extension_property_array(const VkExtensionProperties *vk_ext_prop,
439 const uint32_t count,
440 const VkExtensionProperties *ext_array);
441bool has_vk_extension_property(const VkExtensionProperties *vk_ext_prop,
442 const struct loader_extension_list *ext_list);
Jon Ashburn27cd5842015-05-12 17:26:48 -0600443
Jon Ashburn23d36b12016-02-02 17:47:28 -0700444VkResult loader_add_to_ext_list(const struct loader_instance *inst,
445 struct loader_extension_list *ext_list,
446 uint32_t prop_list_count,
447 const VkExtensionProperties *props);
Jon Ashburncc407a22016-04-15 09:25:03 -0600448VkResult
449loader_add_to_dev_ext_list(const struct loader_instance *inst,
450 struct loader_device_extension_list *ext_list,
451 const VkExtensionProperties *props,
452 uint32_t entry_count, char **entrys);
Jon Ashburn1530c342016-02-26 13:14:27 -0700453VkResult loader_add_device_extensions(const struct loader_instance *inst,
Jon Ashburncc407a22016-04-15 09:25:03 -0600454 PFN_vkEnumerateDeviceExtensionProperties
455 fpEnumerateDeviceExtensionProperties,
Jon Ashburn1530c342016-02-26 13:14:27 -0700456 VkPhysicalDevice physical_device,
457 const char *lib_name,
458 struct loader_extension_list *ext_list);
Mark Young3a587792016-08-19 15:25:08 -0600459VkResult loader_init_generic_list(const struct loader_instance *inst,
460 struct loader_generic_list *list_info,
461 size_t element_size);
Jon Ashburn23d36b12016-02-02 17:47:28 -0700462void loader_destroy_generic_list(const struct loader_instance *inst,
463 struct loader_generic_list *list);
Jon Ashburn1530c342016-02-26 13:14:27 -0700464void loader_destroy_layer_list(const struct loader_instance *inst,
Mark Young0ad83132016-06-30 13:02:42 -0600465 struct loader_device *device,
Jon Ashburn1530c342016-02-26 13:14:27 -0700466 struct loader_layer_list *layer_list);
Jon Ashburn23d36b12016-02-02 17:47:28 -0700467void loader_delete_layer_properties(const struct loader_instance *inst,
468 struct loader_layer_list *layer_list);
Jon Ashburn491cd042016-05-16 14:01:18 -0600469bool loader_find_layer_name_array(const char *name, uint32_t layer_count,
470 const char layer_list[][VK_MAX_EXTENSION_NAME_SIZE]);
Mark Young0ad83132016-06-30 13:02:42 -0600471VkResult loader_expand_layer_names(
Jon Ashburn491cd042016-05-16 14:01:18 -0600472 struct loader_instance *inst, const char *key_name,
Jon Ashburn86a527a2016-02-10 20:59:26 -0700473 uint32_t expand_count,
474 const char expand_names[][VK_MAX_EXTENSION_NAME_SIZE],
Jon Ashburncc407a22016-04-15 09:25:03 -0600475 uint32_t *layer_count, char const *const **ppp_layer_names);
Jon Ashburn491cd042016-05-16 14:01:18 -0600476void loader_init_std_validation_props(struct loader_layer_properties *props);
Chris Forbesbd9de052016-04-06 20:49:02 +1200477void loader_delete_shadow_dev_layer_names(const struct loader_instance *inst,
478 const VkDeviceCreateInfo *orig,
479 VkDeviceCreateInfo *ours);
480void loader_delete_shadow_inst_layer_names(const struct loader_instance *inst,
481 const VkInstanceCreateInfo *orig,
482 VkInstanceCreateInfo *ours);
Mark Young0ad83132016-06-30 13:02:42 -0600483VkResult loader_add_to_layer_list(const struct loader_instance *inst,
484 struct loader_layer_list *list,
485 uint32_t prop_list_count,
486 const struct loader_layer_properties *props);
Jon Ashburncc407a22016-04-15 09:25:03 -0600487void loader_find_layer_name_add_list(
488 const struct loader_instance *inst, const char *name,
489 const enum layer_type type, const struct loader_layer_list *search_list,
490 struct loader_layer_list *found_list);
Jon Ashburn23d36b12016-02-02 17:47:28 -0700491void loader_scanned_icd_clear(const struct loader_instance *inst,
492 struct loader_icd_libs *icd_libs);
Mark Young0ad83132016-06-30 13:02:42 -0600493VkResult loader_icd_scan(const struct loader_instance *inst,
Jon Ashburn23d36b12016-02-02 17:47:28 -0700494 struct loader_icd_libs *icds);
495void loader_layer_scan(const struct loader_instance *inst,
Jon Ashburn491cd042016-05-16 14:01:18 -0600496 struct loader_layer_list *instance_layers);
Jeremy Hayes3e2bd5a2016-04-01 11:40:26 -0600497void loader_implicit_layer_scan(const struct loader_instance *inst,
Jon Ashburn491cd042016-05-16 14:01:18 -0600498 struct loader_layer_list *instance_layers);
Mark Young3a587792016-08-19 15:25:08 -0600499VkResult loader_get_icd_loader_instance_extensions(
Jon Ashburn23d36b12016-02-02 17:47:28 -0700500 const struct loader_instance *inst, struct loader_icd_libs *icd_libs,
501 struct loader_extension_list *inst_exts);
502struct loader_icd *loader_get_icd_and_device(const VkDevice device,
503 struct loader_device **found_dev);
Jon Ashburn1530c342016-02-26 13:14:27 -0700504void loader_init_dispatch_dev_ext(struct loader_instance *inst,
505 struct loader_device *dev);
Jon Ashburn23d36b12016-02-02 17:47:28 -0700506void *loader_dev_ext_gpa(struct loader_instance *inst, const char *funcName);
507void *loader_get_dev_ext_trampoline(uint32_t index);
508struct loader_instance *loader_get_instance(const VkInstance instance);
Jon Ashburn4dc1d8a2016-04-20 13:21:17 -0600509void loader_deactivate_layers(const struct loader_instance *instance,
Mark Young0ad83132016-06-30 13:02:42 -0600510 struct loader_device *device,
Jon Ashburn4dc1d8a2016-04-20 13:21:17 -0600511 struct loader_layer_list *list);
Jon Ashburn1530c342016-02-26 13:14:27 -0700512struct loader_device *
Mark Young0ad83132016-06-30 13:02:42 -0600513loader_create_logical_device(const struct loader_instance *inst, const VkAllocationCallbacks *pAllocator);
Piers Daniell295fe402016-03-29 11:51:11 -0600514void loader_add_logical_device(const struct loader_instance *inst,
515 struct loader_icd *icd,
516 struct loader_device *found_dev);
Jon Ashburn23d36b12016-02-02 17:47:28 -0700517void loader_remove_logical_device(const struct loader_instance *inst,
518 struct loader_icd *icd,
Mark Young0ad83132016-06-30 13:02:42 -0600519 struct loader_device *found_dev,
520 const VkAllocationCallbacks *pAllocator);
521// NOTE: Outside of loader, this entry-point is only proivided for error cleanup.
522void loader_destroy_logical_device(const struct loader_instance *inst,
523 struct loader_device *dev,
524 const VkAllocationCallbacks *pAllocator);
525
Jon Ashburn23d36b12016-02-02 17:47:28 -0700526VkResult
527loader_enable_instance_layers(struct loader_instance *inst,
528 const VkInstanceCreateInfo *pCreateInfo,
529 const struct loader_layer_list *instance_layers);
Jon Ashburndc6fcad2015-06-10 10:06:06 -0600530void loader_deactivate_instance_layers(struct loader_instance *instance);
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700531
Jon Ashburn23d36b12016-02-02 17:47:28 -0700532VkResult loader_create_instance_chain(const VkInstanceCreateInfo *pCreateInfo,
533 const VkAllocationCallbacks *pAllocator,
534 struct loader_instance *inst,
Jon Ashburn6e0a2132016-02-03 12:37:30 -0700535 VkInstance *created_instance);
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700536
Jon Ashburn23d36b12016-02-02 17:47:28 -0700537void loader_activate_instance_layer_extensions(struct loader_instance *inst,
538 VkInstance created_inst);
Jon Ashburn1530c342016-02-26 13:14:27 -0700539VkResult
540loader_enable_device_layers(const struct loader_instance *inst,
Jon Ashburn1530c342016-02-26 13:14:27 -0700541 struct loader_layer_list *activated_layer_list,
542 const VkDeviceCreateInfo *pCreateInfo,
543 const struct loader_layer_list *device_layers);
Courtney Goeltzenleuchter7f5aafc2015-07-05 11:28:29 -0600544
Jon Ashburncc407a22016-04-15 09:25:03 -0600545VkResult
546loader_create_device_chain(const struct loader_physical_device_tramp *pd,
547 const VkDeviceCreateInfo *pCreateInfo,
548 const VkAllocationCallbacks *pAllocator,
549 const struct loader_instance *inst,
550 struct loader_device *dev);
Jon Ashburn1530c342016-02-26 13:14:27 -0700551VkResult loader_validate_device_extensions(
Jon Ashburn787eb252016-03-24 15:49:57 -0600552 struct loader_physical_device_tramp *phys_dev,
Jon Ashburn1530c342016-02-26 13:14:27 -0700553 const struct loader_layer_list *activated_device_layers,
Jon Ashburn014438f2016-03-01 19:51:07 -0700554 const struct loader_extension_list *icd_exts,
Jon Ashburn1530c342016-02-26 13:14:27 -0700555 const VkDeviceCreateInfo *pCreateInfo);
Courtney Goeltzenleuchter7f5aafc2015-07-05 11:28:29 -0600556
Jon Ashburn1530c342016-02-26 13:14:27 -0700557/* instance layer chain termination entrypoint definitions */
558VKAPI_ATTR VkResult VKAPI_CALL
559terminator_CreateInstance(const VkInstanceCreateInfo *pCreateInfo,
560 const VkAllocationCallbacks *pAllocator,
561 VkInstance *pInstance);
Jon Ashburn87d6aa92015-08-28 15:19:27 -0600562
Jon Ashburn1530c342016-02-26 13:14:27 -0700563VKAPI_ATTR void VKAPI_CALL
564terminator_DestroyInstance(VkInstance instance,
565 const VkAllocationCallbacks *pAllocator);
Jon Ashburn87d6aa92015-08-28 15:19:27 -0600566
Jon Ashburn1530c342016-02-26 13:14:27 -0700567VKAPI_ATTR VkResult VKAPI_CALL
568terminator_EnumeratePhysicalDevices(VkInstance instance,
569 uint32_t *pPhysicalDeviceCount,
570 VkPhysicalDevice *pPhysicalDevices);
571
572VKAPI_ATTR void VKAPI_CALL
573terminator_GetPhysicalDeviceFeatures(VkPhysicalDevice physicalDevice,
574 VkPhysicalDeviceFeatures *pFeatures);
575
576VKAPI_ATTR void VKAPI_CALL
577terminator_GetPhysicalDeviceFormatProperties(VkPhysicalDevice physicalDevice,
578 VkFormat format,
579 VkFormatProperties *pFormatInfo);
580
581VKAPI_ATTR VkResult VKAPI_CALL
582terminator_GetPhysicalDeviceImageFormatProperties(
583 VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type,
584 VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags,
585 VkImageFormatProperties *pImageFormatProperties);
586
587VKAPI_ATTR void VKAPI_CALL
588terminator_GetPhysicalDeviceSparseImageFormatProperties(
589 VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type,
590 VkSampleCountFlagBits samples, VkImageUsageFlags usage,
591 VkImageTiling tiling, uint32_t *pNumProperties,
592 VkSparseImageFormatProperties *pProperties);
593
594VKAPI_ATTR void VKAPI_CALL
595terminator_GetPhysicalDeviceProperties(VkPhysicalDevice physicalDevice,
596 VkPhysicalDeviceProperties *pProperties);
597
598VKAPI_ATTR VkResult VKAPI_CALL terminator_EnumerateDeviceExtensionProperties(
599 VkPhysicalDevice physicalDevice, const char *pLayerName, uint32_t *pCount,
600 VkExtensionProperties *pProperties);
601
602VKAPI_ATTR VkResult VKAPI_CALL
603terminator_EnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice,
604 uint32_t *pCount,
605 VkLayerProperties *pProperties);
606
607VKAPI_ATTR void VKAPI_CALL terminator_GetPhysicalDeviceQueueFamilyProperties(
608 VkPhysicalDevice physicalDevice, uint32_t *pCount,
609 VkQueueFamilyProperties *pProperties);
610
611VKAPI_ATTR void VKAPI_CALL terminator_GetPhysicalDeviceMemoryProperties(
612 VkPhysicalDevice physicalDevice,
613 VkPhysicalDeviceMemoryProperties *pProperties);
614
615VKAPI_ATTR VkResult VKAPI_CALL
616terminator_CreateDevice(VkPhysicalDevice gpu,
617 const VkDeviceCreateInfo *pCreateInfo,
618 const VkAllocationCallbacks *pAllocator,
619 VkDevice *pDevice);
Mark Lobodzinskie9f09ef2016-02-02 18:53:34 -0700620
Jon Ashburnf2b4e382016-02-10 20:50:19 -0700621VkStringErrorFlags vk_string_validate(const int max_length,
622 const char *char_array);
Mark Lobodzinskie9f09ef2016-02-02 18:53:34 -0700623
Chia-I Wu19300602014-08-04 08:03:57 +0800624#endif /* LOADER_H */