blob: ecc945edcb791343006701b7f70e1fdeb20cb2f2 [file] [log] [blame]
Chia-I Wuc1e0f962014-08-04 08:03:57 +08001/*
Chia-I Wuc1e0f962014-08-04 08:03:57 +08002 *
Jon Ashburn1c75aec2016-02-02 17:47:28 -07003 * Copyright (c) 2014-2016 The Khronos Group Inc.
4 * Copyright (c) 2014-2016 Valve Corporation
5 * Copyright (c) 2014-2016 LunarG, Inc.
Courtney Goeltzenleuchter8e1b8d92015-12-02 14:53:22 -07006 * Copyright (C) 2015 Google Inc.
Chia-I Wuc1e0f962014-08-04 08:03:57 +08007 *
Jon Ashburn4f80d672016-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 Wuc1e0f962014-08-04 08:03:57 +080011 *
Jon Ashburn4f80d672016-04-19 11:30:31 -060012 * http://www.apache.org/licenses/LICENSE-2.0
Chia-I Wuc1e0f962014-08-04 08:03:57 +080013 *
Jon Ashburn4f80d672016-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 Ashburn1c75aec2016-02-02 17:47:28 -070019 *
20 * Author: Jon Ashburn <jon@lunarg.com>
21 * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
Courtney Goeltzenleuchterb9ce3952015-10-30 11:14:30 -060022 * Author: Chia-I Wu <olvaffe@gmail.com>
23 * Author: Chia-I Wu <olv@lunarg.com>
Jon Ashburn1c75aec2016-02-02 17:47:28 -070024 * Author: Mark Lobodzinski <mark@LunarG.com>
Courtney Goeltzenleuchterb9ce3952015-10-30 11:14:30 -060025 *
Chia-I Wuc1e0f962014-08-04 08:03:57 +080026 */
27
28#ifndef LOADER_H
29#define LOADER_H
30
David Pinedoa5036622015-11-06 12:54:48 -070031#include <vulkan/vulkan.h>
Aaron Karp95c5f952016-03-13 16:41:59 -040032#include "vk_loader_platform.h"
Mark Lobodzinski663818f2016-05-24 16:04:56 -060033#include "vk_loader_layer.h"
David Pinedoa5036622015-11-06 12:54:48 -070034#include <vulkan/vk_layer.h>
Mark Lobodzinski663818f2016-05-24 16:04:56 -060035
David Pinedoa5036622015-11-06 12:54:48 -070036#include <vulkan/vk_icd.h>
Chia-I Wufe333ed2015-04-11 15:34:07 +080037#include <assert.h>
38
Chia-I Wuc1e0f962014-08-04 08:03:57 +080039#if defined(__GNUC__) && __GNUC__ >= 4
Jon Ashburn1c75aec2016-02-02 17:47:28 -070040#define LOADER_EXPORT __attribute__((visibility("default")))
Chia-I Wuc1e0f962014-08-04 08:03:57 +080041#elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)
Jon Ashburn1c75aec2016-02-02 17:47:28 -070042#define LOADER_EXPORT __attribute__((visibility("default")))
Chia-I Wuc1e0f962014-08-04 08:03:57 +080043#else
Jon Ashburn1c75aec2016-02-02 17:47:28 -070044#define LOADER_EXPORT
Chia-I Wuc1e0f962014-08-04 08:03:57 +080045#endif
46
Jon Ashburnb2379c52015-08-04 10:22:33 -060047#define MAX_STRING_SIZE 1024
Courtney Goeltzenleuchter44667cc2015-06-29 15:39:26 -060048#define VK_MAJOR(version) (version >> 22)
49#define VK_MINOR(version) ((version >> 12) & 0x3ff)
50#define VK_PATCH(version) (version & 0xfff)
Jon Ashburn13482452015-05-12 17:26:48 -060051
Jon Ashburn399c9162015-07-02 09:40:15 -060052enum layer_type {
Jon Ashburnc325bc02016-05-16 14:01:18 -060053 VK_LAYER_TYPE_INSTANCE_EXPLICIT = 0x1,
54 VK_LAYER_TYPE_INSTANCE_IMPLICIT = 0x2,
55 VK_LAYER_TYPE_META_EXPLICT = 0x4,
Jon Ashburn399c9162015-07-02 09:40:15 -060056};
57
Mark Lobodzinski8d325802016-02-02 18:53:34 -070058typedef enum VkStringErrorFlagBits {
Jon Ashburnb1cdf2e2016-02-10 20:50:19 -070059 VK_STRING_ERROR_NONE = 0x00000000,
60 VK_STRING_ERROR_LENGTH = 0x00000001,
61 VK_STRING_ERROR_BAD_DATA = 0x00000002,
Mark Lobodzinski8d325802016-02-02 18:53:34 -070062} VkStringErrorFlagBits;
63typedef VkFlags VkStringErrorFlags;
64
Jon Ashburnb1cdf2e2016-02-10 20:50:19 -070065static const int MaxLoaderStringLength = 256;
66static const char UTF8_ONE_BYTE_CODE = 0xC0;
67static const char UTF8_ONE_BYTE_MASK = 0xE0;
68static const char UTF8_TWO_BYTE_CODE = 0xE0;
69static const char UTF8_TWO_BYTE_MASK = 0xF0;
70static const char UTF8_THREE_BYTE_CODE = 0xF0;
71static const char UTF8_THREE_BYTE_MASK = 0xF8;
72static const char UTF8_DATA_BYTE_CODE = 0x80;
73static const char UTF8_DATA_BYTE_MASK = 0xC0;
Mark Lobodzinski8d325802016-02-02 18:53:34 -070074
Mark Lobodzinskib0123ea2016-03-15 17:23:12 -060075static const char std_validation_names[8][VK_MAX_EXTENSION_NAME_SIZE] = {
Jon Ashburnc466da52016-04-15 09:25:03 -060076 "VK_LAYER_GOOGLE_threading", "VK_LAYER_LUNARG_parameter_validation",
Jon Ashburnd1eb3322016-02-10 20:59:26 -070077 "VK_LAYER_LUNARG_device_limits", "VK_LAYER_LUNARG_object_tracker",
Jon Ashburnc466da52016-04-15 09:25:03 -060078 "VK_LAYER_LUNARG_image", "VK_LAYER_LUNARG_core_validation",
79 "VK_LAYER_LUNARG_swapchain", "VK_LAYER_GOOGLE_unique_objects"};
Jon Ashburnd1eb3322016-02-10 20:59:26 -070080
Jon Ashburn6b00b472015-12-10 08:51:10 -070081// form of all dynamic lists/arrays
82// only the list element should be changed
83struct loader_generic_list {
84 size_t capacity;
85 uint32_t count;
86 void *list;
87};
88
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -060089struct loader_extension_list {
90 size_t capacity;
91 uint32_t count;
Jon Ashburnb7d327c2015-08-04 11:14:18 -060092 VkExtensionProperties *list;
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -060093};
94
Jon Ashburn92cdb012015-12-10 18:17:34 -070095struct loader_dev_ext_props {
96 VkExtensionProperties props;
97 uint32_t entrypoint_count;
98 char **entrypoints;
99};
100
101struct loader_device_extension_list {
102 size_t capacity;
103 uint32_t count;
104 struct loader_dev_ext_props *list;
105};
106
Jon Ashburn399c9162015-07-02 09:40:15 -0600107struct loader_name_value {
Jon Ashburnb2379c52015-08-04 10:22:33 -0600108 char name[MAX_STRING_SIZE];
109 char value[MAX_STRING_SIZE];
Jon Ashburn399c9162015-07-02 09:40:15 -0600110};
111
Jon Ashburn399c9162015-07-02 09:40:15 -0600112struct loader_layer_functions {
Jon Ashburnb2379c52015-08-04 10:22:33 -0600113 char str_gipa[MAX_STRING_SIZE];
114 char str_gdpa[MAX_STRING_SIZE];
Jon Ashburn399c9162015-07-02 09:40:15 -0600115 PFN_vkGetInstanceProcAddr get_instance_proc_addr;
116 PFN_vkGetDeviceProcAddr get_device_proc_addr;
117};
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600118
Jon Ashburn399c9162015-07-02 09:40:15 -0600119struct loader_layer_properties {
Courtney Goeltzenleuchter44667cc2015-06-29 15:39:26 -0600120 VkLayerProperties info;
Jon Ashburn399c9162015-07-02 09:40:15 -0600121 enum layer_type type;
Jon Ashburnb4c24232015-08-20 16:35:30 -0600122 char lib_name[MAX_STRING_SIZE];
Jon Ashburnd3cf9552016-04-20 13:21:17 -0600123 loader_platform_dl_handle lib_handle;
Jon Ashburn399c9162015-07-02 09:40:15 -0600124 struct loader_layer_functions functions;
125 struct loader_extension_list instance_extension_list;
Jon Ashburn92cdb012015-12-10 18:17:34 -0700126 struct loader_device_extension_list device_extension_list;
Jon Ashburn399c9162015-07-02 09:40:15 -0600127 struct loader_name_value disable_env_var;
128 struct loader_name_value enable_env_var;
129};
130
131struct loader_layer_list {
132 size_t capacity;
133 uint32_t count;
134 struct loader_layer_properties *list;
Jon Ashburn13482452015-05-12 17:26:48 -0600135};
136
Jon Ashburn6cb69f42015-11-17 15:31:02 -0700137struct loader_dispatch_hash_list {
138 size_t capacity;
139 uint32_t count;
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700140 uint32_t *index; // index into the dev_ext dispatch table
Jon Ashburn6cb69f42015-11-17 15:31:02 -0700141};
142
143#define MAX_NUM_DEV_EXTS 250
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700144// loader_dispatch_hash_entry and loader_dev_ext_dispatch_table.DevExt have one
145// to one
Jon Ashburn6cb69f42015-11-17 15:31:02 -0700146// correspondence; one loader_dispatch_hash_entry for one DevExt dispatch entry.
147// Also have a one to one correspondence with functions in dev_ext_trampoline.c
148struct loader_dispatch_hash_entry {
149 char *func_name;
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700150 struct loader_dispatch_hash_list list; // to handle hashing collisions
Jon Ashburn6cb69f42015-11-17 15:31:02 -0700151};
152
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700153typedef void(VKAPI_PTR *PFN_vkDevExt)(VkDevice device);
Jon Ashburn6cb69f42015-11-17 15:31:02 -0700154struct loader_dev_ext_dispatch_table {
155 PFN_vkDevExt DevExt[MAX_NUM_DEV_EXTS];
156};
157
158struct loader_dev_dispatch_table {
159 VkLayerDispatchTable core_dispatch;
160 struct loader_dev_ext_dispatch_table ext_dispatch;
161};
162
Jon Ashburn10f4e822015-06-10 10:06:06 -0600163/* per CreateDevice structure */
164struct loader_device {
Jon Ashburn6cb69f42015-11-17 15:31:02 -0700165 struct loader_dev_dispatch_table loader_dispatch;
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700166 VkDevice device; // device object from the icd
Jon Ashburn10f4e822015-06-10 10:06:06 -0600167
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700168 uint32_t app_extension_count;
Jon Ashburn10f4e822015-06-10 10:06:06 -0600169 VkExtensionProperties *app_extension_props;
170
Courtney Goeltzenleuchter44667cc2015-06-29 15:39:26 -0600171 struct loader_layer_list activated_layer_list;
Jon Ashburn10f4e822015-06-10 10:06:06 -0600172
173 struct loader_device *next;
174};
175
Jon Ashburn392c5622015-06-10 16:11:42 -0600176/* per ICD structure */
Jon Ashburnebfa25e2015-05-15 15:09:35 -0600177struct loader_icd {
Jon Ashburnb4c24232015-08-20 16:35:30 -0600178 // pointers to find other structs
179 const struct loader_scanned_icds *this_icd_lib;
180 const struct loader_instance *this_instance;
Jon Ashburn10f4e822015-06-10 10:06:06 -0600181 struct loader_device *logical_device_list;
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700182 VkInstance instance; // instance object from the icd
Jon Ashburnc89dd4a2015-05-18 13:20:15 -0600183 PFN_vkGetDeviceProcAddr GetDeviceProcAddr;
Jon Ashburnebfa25e2015-05-15 15:09:35 -0600184 PFN_vkDestroyInstance DestroyInstance;
185 PFN_vkEnumeratePhysicalDevices EnumeratePhysicalDevices;
Chris Forbes1c946ec2015-06-21 22:55:02 +1200186 PFN_vkGetPhysicalDeviceFeatures GetPhysicalDeviceFeatures;
Courtney Goeltzenleuchter2b6559e2015-07-12 12:52:09 -0600187 PFN_vkGetPhysicalDeviceFormatProperties GetPhysicalDeviceFormatProperties;
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700188 PFN_vkGetPhysicalDeviceImageFormatProperties
189 GetPhysicalDeviceImageFormatProperties;
Jon Ashburnebfa25e2015-05-15 15:09:35 -0600190 PFN_vkCreateDevice CreateDevice;
Tony Barbour4e657ba2015-06-24 16:06:58 -0600191 PFN_vkGetPhysicalDeviceProperties GetPhysicalDeviceProperties;
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700192 PFN_vkGetPhysicalDeviceQueueFamilyProperties
193 GetPhysicalDeviceQueueFamilyProperties;
Tony Barbour4e657ba2015-06-24 16:06:58 -0600194 PFN_vkGetPhysicalDeviceMemoryProperties GetPhysicalDeviceMemoryProperties;
Courtney Goeltzenleuchtere25064c2015-09-14 17:22:16 -0600195 PFN_vkEnumerateDeviceExtensionProperties EnumerateDeviceExtensionProperties;
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700196 PFN_vkGetPhysicalDeviceSparseImageFormatProperties
197 GetPhysicalDeviceSparseImageFormatProperties;
Courtney Goeltzenleuchter725db942015-12-09 15:48:16 -0700198 PFN_vkCreateDebugReportCallbackEXT CreateDebugReportCallbackEXT;
199 PFN_vkDestroyDebugReportCallbackEXT DestroyDebugReportCallbackEXT;
200 PFN_vkDebugReportMessageEXT DebugReportMessageEXT;
Ian Elliottec736342015-08-21 15:09:33 -0600201 PFN_vkGetPhysicalDeviceSurfaceSupportKHR GetPhysicalDeviceSurfaceSupportKHR;
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700202 PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR
203 GetPhysicalDeviceSurfaceCapabilitiesKHR;
Ian Elliottea666b22015-11-19 16:05:09 -0700204 PFN_vkGetPhysicalDeviceSurfaceFormatsKHR GetPhysicalDeviceSurfaceFormatsKHR;
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700205 PFN_vkGetPhysicalDeviceSurfacePresentModesKHR
206 GetPhysicalDeviceSurfacePresentModesKHR;
Ian Elliotte851dd62015-11-24 15:39:10 -0700207#ifdef VK_USE_PLATFORM_WIN32_KHR
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700208 PFN_vkGetPhysicalDeviceWin32PresentationSupportKHR
209 GetPhysicalDeviceWin32PresentationSupportKHR;
Ian Elliotte851dd62015-11-24 15:39:10 -0700210#endif
211#ifdef VK_USE_PLATFORM_MIR_KHR
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700212 PFN_vkGetPhysicalDeviceMirPresentationSupportKHR
213 GetPhysicalDeviceMirPresentvationSupportKHR;
Ian Elliotte851dd62015-11-24 15:39:10 -0700214#endif
215#ifdef VK_USE_PLATFORM_WAYLAND_KHR
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700216 PFN_vkGetPhysicalDeviceWaylandPresentationSupportKHR
217 GetPhysicalDeviceWaylandPresentationSupportKHR;
Ian Elliotte851dd62015-11-24 15:39:10 -0700218#endif
219#ifdef VK_USE_PLATFORM_XCB_KHR
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700220 PFN_vkGetPhysicalDeviceXcbPresentationSupportKHR
221 GetPhysicalDeviceXcbPresentationSupportKHR;
Ian Elliotte851dd62015-11-24 15:39:10 -0700222#endif
223#ifdef VK_USE_PLATFORM_XLIB_KHR
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700224 PFN_vkGetPhysicalDeviceXlibPresentationSupportKHR
225 GetPhysicalDeviceXlibPresentationSupportKHR;
Ian Elliotte851dd62015-11-24 15:39:10 -0700226#endif
Jon Ashburncc370d02016-03-08 09:30:30 -0700227 PFN_vkGetPhysicalDeviceDisplayPropertiesKHR
228 GetPhysicalDeviceDisplayPropertiesKHR;
229 PFN_vkGetPhysicalDeviceDisplayPlanePropertiesKHR
230 GetPhysicalDeviceDisplayPlanePropertiesKHR;
231 PFN_vkGetDisplayPlaneSupportedDisplaysKHR
232 GetDisplayPlaneSupportedDisplaysKHR;
Jon Ashburnc466da52016-04-15 09:25:03 -0600233 PFN_vkGetDisplayModePropertiesKHR GetDisplayModePropertiesKHR;
234 PFN_vkCreateDisplayModeKHR CreateDisplayModeKHR;
235 PFN_vkGetDisplayPlaneCapabilitiesKHR GetDisplayPlaneCapabilitiesKHR;
236 PFN_vkCreateDisplayPlaneSurfaceKHR CreateDisplayPlaneSurfaceKHR;
237 PFN_vkDestroySurfaceKHR DestroySurfaceKHR;
Jon Ashburn10f4e822015-06-10 10:06:06 -0600238 struct loader_icd *next;
Jon Ashburnebfa25e2015-05-15 15:09:35 -0600239};
240
Jon Ashburne0367472015-08-18 18:04:47 -0600241/* per ICD library structure */
242struct loader_icd_libs {
243 size_t capacity;
244 uint32_t count;
245 struct loader_scanned_icds *list;
246};
247
Jon Ashburn392c5622015-06-10 16:11:42 -0600248/* per instance structure */
Jon Ashburn13482452015-05-12 17:26:48 -0600249struct loader_instance {
Jon Ashburnebfa25e2015-05-15 15:09:35 -0600250 VkLayerInstanceDispatchTable *disp; // must be first entry in structure
251
Jon Ashburnfd02a0f2016-03-01 19:51:07 -0700252 uint32_t total_gpu_count; // count of the next two arrays
253 struct loader_physical_device *phys_devs_term;
Jon Ashburnc466da52016-04-15 09:25:03 -0600254 struct loader_physical_device_tramp *
255 phys_devs; // tramp wrapped physDev obj list
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600256 uint32_t total_icd_count;
Jon Ashburn13482452015-05-12 17:26:48 -0600257 struct loader_icd *icds;
258 struct loader_instance *next;
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700259 struct loader_extension_list ext_list; // icds and loaders extensions
Jon Ashburne0367472015-08-18 18:04:47 -0600260 struct loader_icd_libs icd_libs;
Jon Ashburnb4c24232015-08-20 16:35:30 -0600261 struct loader_layer_list instance_layer_list;
Jon Ashburn6cb69f42015-11-17 15:31:02 -0700262 struct loader_dispatch_hash_entry disp_hash[MAX_NUM_DEV_EXTS];
Jon Ashburnb4c24232015-08-20 16:35:30 -0600263
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600264 struct loader_msg_callback_map_entry *icd_msg_callback_map;
265
Courtney Goeltzenleuchter44667cc2015-06-29 15:39:26 -0600266 struct loader_layer_list activated_layer_list;
Jon Ashburnc325bc02016-05-16 14:01:18 -0600267 bool activated_layers_are_std_val;
Jon Ashburnc466da52016-04-15 09:25:03 -0600268 VkInstance instance; // layers/ICD instance returned to trampoline
Courtney Goeltzenleuchter0bd705c2016-01-08 12:18:43 -0700269
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600270 bool debug_report_enabled;
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600271 VkLayerDbgFunctionNode *DbgFunctionHead;
Ian Elliottdefd6da2016-03-31 10:48:19 -0600272 uint32_t num_tmp_callbacks;
273 VkDebugReportCallbackCreateInfoEXT *tmp_dbg_create_infos;
274 VkDebugReportCallbackEXT *tmp_callbacks;
Courtney Goeltzenleuchter71b454b2015-07-05 11:28:29 -0600275
Chia-I Wu227c8b32015-10-27 18:04:07 +0800276 VkAllocationCallbacks alloc_callbacks;
Ian Elliotted33eb72015-07-06 14:36:13 -0600277
Ian Elliott54cea232015-10-30 15:28:23 -0600278 bool wsi_surface_enabled;
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -0700279#ifdef VK_USE_PLATFORM_WIN32_KHR
Ian Elliott54cea232015-10-30 15:28:23 -0600280 bool wsi_win32_surface_enabled;
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -0700281#endif
282#ifdef VK_USE_PLATFORM_MIR_KHR
Ian Elliott54cea232015-10-30 15:28:23 -0600283 bool wsi_mir_surface_enabled;
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -0700284#endif
285#ifdef VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott54cea232015-10-30 15:28:23 -0600286 bool wsi_wayland_surface_enabled;
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -0700287#endif
288#ifdef VK_USE_PLATFORM_XCB_KHR
Ian Elliott54cea232015-10-30 15:28:23 -0600289 bool wsi_xcb_surface_enabled;
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -0700290#endif
291#ifdef VK_USE_PLATFORM_XLIB_KHR
Ian Elliott54cea232015-10-30 15:28:23 -0600292 bool wsi_xlib_surface_enabled;
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -0700293#endif
294#ifdef VK_USE_PLATFORM_ANDROID_KHR
295 bool wsi_android_surface_enabled;
296#endif
Jon Ashburncc370d02016-03-08 09:30:30 -0700297 bool wsi_display_enabled;
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600298};
299
Jon Ashburnfd02a0f2016-03-01 19:51:07 -0700300/* VkPhysicalDevice requires special treatment by loader. Firstly, terminator
301 * code must be able to get the struct loader_icd to call into the proper
302 * driver (multiple ICD/gpu case). This can be accomplished by wrapping the
303 * created VkPhysicalDevice in loader terminate_EnumeratePhysicalDevices().
Piers Daniell82107a62016-03-29 11:51:11 -0600304 * Secondly, the loader must be able to handle wrapped by layer VkPhysicalDevice
Jon Ashburnfd02a0f2016-03-01 19:51:07 -0700305 * in trampoline code. This implies, that the loader trampoline code must also
306 * wrap the VkPhysicalDevice object in trampoline code. Thus, loader has to
307 * wrap the VkPhysicalDevice created object twice. In trampoline code it can't
308 * rely on the terminator object wrapping since a layer may also wrap. Since
309 * trampoline code wraps the VkPhysicalDevice this means all loader trampoline
310 * code that passes a VkPhysicalDevice should unwrap it. */
311
312/* per enumerated PhysicalDevice structure, used to wrap in trampoline code and
313 also same structure used to wrap in terminator code */
Jon Ashburnc3519e42016-03-24 15:49:57 -0600314struct loader_physical_device_tramp {
315 VkLayerInstanceDispatchTable *disp; // must be first entry in structure
Piers Daniell82107a62016-03-29 11:51:11 -0600316 struct loader_instance *this_instance;
Jon Ashburnc466da52016-04-15 09:25:03 -0600317 VkPhysicalDevice phys_dev; // object from layers/loader terminator
Jon Ashburnc3519e42016-03-24 15:49:57 -0600318};
319
320/* per enumerated PhysicalDevice structure, used to wrap in terminator code */
Jon Ashburn969caa42015-11-01 14:04:06 -0700321struct loader_physical_device {
322 VkLayerInstanceDispatchTable *disp; // must be first entry in structure
Jon Ashburn969caa42015-11-01 14:04:06 -0700323 struct loader_icd *this_icd;
Jon Ashburnc3519e42016-03-24 15:49:57 -0600324 VkPhysicalDevice phys_dev; // object from ICD
Jon Ashburn969caa42015-11-01 14:04:06 -0700325};
326
Jon Ashburn13482452015-05-12 17:26:48 -0600327struct loader_struct {
328 struct loader_instance *instances;
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600329};
330
331struct loader_scanned_icds {
332 char *lib_name;
333 loader_platform_dl_handle handle;
Jon Ashburn27109e82015-11-17 17:35:40 -0700334 uint32_t api_version;
Jon Ashburn68b06d62016-04-25 11:09:37 -0600335 uint32_t interface_version;
Jon Ashburnc7ca48d2015-07-16 10:17:29 -0600336 PFN_vkGetInstanceProcAddr GetInstanceProcAddr;
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600337 PFN_vkCreateInstance CreateInstance;
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700338 PFN_vkEnumerateInstanceExtensionProperties
339 EnumerateInstanceExtensionProperties;
Jon Ashburn13482452015-05-12 17:26:48 -0600340};
341
Jon Ashburn399c9162015-07-02 09:40:15 -0600342static inline struct loader_instance *loader_instance(VkInstance instance) {
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700343 return (struct loader_instance *)instance;
Jon Ashburn399c9162015-07-02 09:40:15 -0600344}
345
Jon Ashburnfd02a0f2016-03-01 19:51:07 -0700346static inline VkPhysicalDevice
347loader_unwrap_physical_device(VkPhysicalDevice physicalDevice) {
Piers Daniella9ccaed2016-03-31 14:47:57 -0600348 struct loader_physical_device_tramp *phys_dev =
349 (struct loader_physical_device_tramp *)physicalDevice;
Jon Ashburnfd02a0f2016-03-01 19:51:07 -0700350 return phys_dev->phys_dev;
351}
352
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700353static inline void loader_set_dispatch(void *obj, const void *data) {
354 *((const void **)obj) = data;
Chia-I Wufe333ed2015-04-11 15:34:07 +0800355}
356
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700357static inline VkLayerDispatchTable *loader_get_dispatch(const void *obj) {
358 return *((VkLayerDispatchTable **)obj);
Chia-I Wufe333ed2015-04-11 15:34:07 +0800359}
360
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700361static inline struct loader_dev_dispatch_table *
362loader_get_dev_dispatch(const void *obj) {
363 return *((struct loader_dev_dispatch_table **)obj);
Jon Ashburn6cb69f42015-11-17 15:31:02 -0700364}
365
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700366static inline VkLayerInstanceDispatchTable *
367loader_get_instance_dispatch(const void *obj) {
368 return *((VkLayerInstanceDispatchTable **)obj);
Jon Ashburn13482452015-05-12 17:26:48 -0600369}
370
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700371static inline void loader_init_dispatch(void *obj, const void *data) {
Jon Ashburn167b2b12015-04-15 13:34:33 -0600372#ifdef DEBUG
Chia-I Wufe333ed2015-04-11 15:34:07 +0800373 assert(valid_loader_magic_value(obj) &&
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700374 "Incompatible ICD, first dword must be initialized to "
375 "ICD_LOADER_MAGIC. See loader/README.md for details.");
Jon Ashburn167b2b12015-04-15 13:34:33 -0600376#endif
Chia-I Wufe333ed2015-04-11 15:34:07 +0800377
Jon Ashburn62a54d12015-05-01 18:00:33 -0600378 loader_set_dispatch(obj, data);
Chia-I Wufe333ed2015-04-11 15:34:07 +0800379}
380
Jon Ashburn13482452015-05-12 17:26:48 -0600381/* global variables used across files */
382extern struct loader_struct loader;
Jon Ashburnb4dee9c2015-08-28 15:19:27 -0600383extern THREAD_LOCAL_DECL struct loader_instance *tls_instance;
Jon Ashburne0367472015-08-18 18:04:47 -0600384extern LOADER_PLATFORM_THREAD_ONCE_DEFINITION(once_init);
Jon Ashburn7e8d8b42015-05-29 13:15:39 -0600385extern loader_platform_thread_mutex loader_lock;
Jon Ashburn7d4d51c2015-09-22 13:11:00 -0600386extern loader_platform_thread_mutex loader_json_lock;
Jon Ashburn7e8d8b42015-05-29 13:15:39 -0600387extern const VkLayerInstanceDispatchTable instance_disp;
Jon Ashburnd1eb3322016-02-10 20:59:26 -0700388extern const char *std_validation_str;
Jon Ashburn37e7f972015-04-06 10:58:22 -0600389
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600390struct loader_msg_callback_map_entry {
Courtney Goeltzenleuchter725db942015-12-09 15:48:16 -0700391 VkDebugReportCallbackEXT icd_obj;
392 VkDebugReportCallbackEXT loader_obj;
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600393};
394
Jon Ashburnc4e9ae62016-02-26 13:14:27 -0700395/* helper function definitions */
396void *loader_heap_alloc(const struct loader_instance *instance, size_t size,
397 VkSystemAllocationScope allocationScope);
398
399void loader_heap_free(const struct loader_instance *instance, void *pMemory);
400
401void *loader_tls_heap_alloc(size_t size);
402
403void loader_tls_heap_free(void *pMemory);
404
Jon Ashburn663f8312016-02-12 08:20:06 -0700405void loader_log(const struct loader_instance *inst, VkFlags msg_type,
Jon Ashburnc4e9ae62016-02-26 13:14:27 -0700406 int32_t msg_code, const char *format, ...);
Jon Ashburn663f8312016-02-12 08:20:06 -0700407
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700408bool compare_vk_extension_properties(const VkExtensionProperties *op1,
409 const VkExtensionProperties *op2);
Courtney Goeltzenleuchter67146d02015-06-10 17:39:03 -0600410
Mark Lobodzinski8d325802016-02-02 18:53:34 -0700411VkResult loader_validate_layers(const struct loader_instance *inst,
412 const uint32_t layer_count,
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700413 const char *const *ppEnabledLayerNames,
414 const struct loader_layer_list *list);
Courtney Goeltzenleuchter76ece702015-07-06 17:45:08 -0600415
416VkResult loader_validate_instance_extensions(
Mark Lobodzinski8d325802016-02-02 18:53:34 -0700417 const struct loader_instance *inst,
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700418 const struct loader_extension_list *icd_exts,
419 const struct loader_layer_list *instance_layer,
420 const VkInstanceCreateInfo *pCreateInfo);
Courtney Goeltzenleuchter76ece702015-07-06 17:45:08 -0600421
Jon Ashburne0367472015-08-18 18:04:47 -0600422void loader_initialize(void);
Jon Ashburnc325bc02016-05-16 14:01:18 -0600423void loader_copy_layer_properties(const struct loader_instance *inst,
424 struct loader_layer_properties *dst,
425 struct loader_layer_properties *src);
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700426bool has_vk_extension_property_array(const VkExtensionProperties *vk_ext_prop,
427 const uint32_t count,
428 const VkExtensionProperties *ext_array);
429bool has_vk_extension_property(const VkExtensionProperties *vk_ext_prop,
430 const struct loader_extension_list *ext_list);
Jon Ashburn13482452015-05-12 17:26:48 -0600431
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700432VkResult loader_add_to_ext_list(const struct loader_instance *inst,
433 struct loader_extension_list *ext_list,
434 uint32_t prop_list_count,
435 const VkExtensionProperties *props);
Jon Ashburnc466da52016-04-15 09:25:03 -0600436VkResult
437loader_add_to_dev_ext_list(const struct loader_instance *inst,
438 struct loader_device_extension_list *ext_list,
439 const VkExtensionProperties *props,
440 uint32_t entry_count, char **entrys);
Jon Ashburnc4e9ae62016-02-26 13:14:27 -0700441VkResult loader_add_device_extensions(const struct loader_instance *inst,
Jon Ashburnc466da52016-04-15 09:25:03 -0600442 PFN_vkEnumerateDeviceExtensionProperties
443 fpEnumerateDeviceExtensionProperties,
Jon Ashburnc4e9ae62016-02-26 13:14:27 -0700444 VkPhysicalDevice physical_device,
445 const char *lib_name,
446 struct loader_extension_list *ext_list);
447bool loader_init_generic_list(const struct loader_instance *inst,
448 struct loader_generic_list *list_info,
449 size_t element_size);
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700450void loader_destroy_generic_list(const struct loader_instance *inst,
451 struct loader_generic_list *list);
Jon Ashburnc4e9ae62016-02-26 13:14:27 -0700452void loader_destroy_layer_list(const struct loader_instance *inst,
453 struct loader_layer_list *layer_list);
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700454void loader_delete_layer_properties(const struct loader_instance *inst,
455 struct loader_layer_list *layer_list);
Jon Ashburnc325bc02016-05-16 14:01:18 -0600456bool loader_find_layer_name_array(const char *name, uint32_t layer_count,
457 const char layer_list[][VK_MAX_EXTENSION_NAME_SIZE]);
Jon Ashburnd1eb3322016-02-10 20:59:26 -0700458void loader_expand_layer_names(
Jon Ashburnc325bc02016-05-16 14:01:18 -0600459 struct loader_instance *inst, const char *key_name,
Jon Ashburnd1eb3322016-02-10 20:59:26 -0700460 uint32_t expand_count,
461 const char expand_names[][VK_MAX_EXTENSION_NAME_SIZE],
Jon Ashburnc466da52016-04-15 09:25:03 -0600462 uint32_t *layer_count, char const *const **ppp_layer_names);
Jon Ashburnc325bc02016-05-16 14:01:18 -0600463void loader_init_std_validation_props(struct loader_layer_properties *props);
Chris Forbes7333fdd2016-04-06 20:49:02 +1200464void loader_delete_shadow_dev_layer_names(const struct loader_instance *inst,
465 const VkDeviceCreateInfo *orig,
466 VkDeviceCreateInfo *ours);
467void loader_delete_shadow_inst_layer_names(const struct loader_instance *inst,
468 const VkInstanceCreateInfo *orig,
469 VkInstanceCreateInfo *ours);
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700470void loader_add_to_layer_list(const struct loader_instance *inst,
471 struct loader_layer_list *list,
472 uint32_t prop_list_count,
473 const struct loader_layer_properties *props);
Jon Ashburnc466da52016-04-15 09:25:03 -0600474void loader_find_layer_name_add_list(
475 const struct loader_instance *inst, const char *name,
476 const enum layer_type type, const struct loader_layer_list *search_list,
477 struct loader_layer_list *found_list);
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700478void loader_scanned_icd_clear(const struct loader_instance *inst,
479 struct loader_icd_libs *icd_libs);
480void loader_icd_scan(const struct loader_instance *inst,
481 struct loader_icd_libs *icds);
482void loader_layer_scan(const struct loader_instance *inst,
Jon Ashburnc325bc02016-05-16 14:01:18 -0600483 struct loader_layer_list *instance_layers);
Jeremy Hayes10d78f12016-04-01 11:40:26 -0600484void loader_implicit_layer_scan(const struct loader_instance *inst,
Jon Ashburnc325bc02016-05-16 14:01:18 -0600485 struct loader_layer_list *instance_layers);
Jon Ashburne0367472015-08-18 18:04:47 -0600486void loader_get_icd_loader_instance_extensions(
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700487 const struct loader_instance *inst, struct loader_icd_libs *icd_libs,
488 struct loader_extension_list *inst_exts);
489struct loader_icd *loader_get_icd_and_device(const VkDevice device,
490 struct loader_device **found_dev);
Jon Ashburnc4e9ae62016-02-26 13:14:27 -0700491void loader_init_dispatch_dev_ext(struct loader_instance *inst,
492 struct loader_device *dev);
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700493void *loader_dev_ext_gpa(struct loader_instance *inst, const char *funcName);
494void *loader_get_dev_ext_trampoline(uint32_t index);
495struct loader_instance *loader_get_instance(const VkInstance instance);
Jon Ashburnd3cf9552016-04-20 13:21:17 -0600496void loader_deactivate_layers(const struct loader_instance *instance,
497 struct loader_layer_list *list);
Jon Ashburnc4e9ae62016-02-26 13:14:27 -0700498struct loader_device *
Piers Daniell82107a62016-03-29 11:51:11 -0600499loader_create_logical_device(const struct loader_instance *inst);
500void loader_add_logical_device(const struct loader_instance *inst,
501 struct loader_icd *icd,
502 struct loader_device *found_dev);
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700503void loader_remove_logical_device(const struct loader_instance *inst,
504 struct loader_icd *icd,
505 struct loader_device *found_dev);
506VkResult
507loader_enable_instance_layers(struct loader_instance *inst,
508 const VkInstanceCreateInfo *pCreateInfo,
509 const struct loader_layer_list *instance_layers);
Jon Ashburn10f4e822015-06-10 10:06:06 -0600510void loader_deactivate_instance_layers(struct loader_instance *instance);
Courtney Goeltzenleuchter0bd705c2016-01-08 12:18:43 -0700511
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700512VkResult loader_create_instance_chain(const VkInstanceCreateInfo *pCreateInfo,
513 const VkAllocationCallbacks *pAllocator,
514 struct loader_instance *inst,
Jon Ashburnd1205a92016-02-03 12:37:30 -0700515 VkInstance *created_instance);
Courtney Goeltzenleuchter0bd705c2016-01-08 12:18:43 -0700516
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700517void loader_activate_instance_layer_extensions(struct loader_instance *inst,
518 VkInstance created_inst);
Jon Ashburnc4e9ae62016-02-26 13:14:27 -0700519VkResult
520loader_enable_device_layers(const struct loader_instance *inst,
Jon Ashburnc4e9ae62016-02-26 13:14:27 -0700521 struct loader_layer_list *activated_layer_list,
522 const VkDeviceCreateInfo *pCreateInfo,
523 const struct loader_layer_list *device_layers);
Courtney Goeltzenleuchter71b454b2015-07-05 11:28:29 -0600524
Jon Ashburnc466da52016-04-15 09:25:03 -0600525VkResult
526loader_create_device_chain(const struct loader_physical_device_tramp *pd,
527 const VkDeviceCreateInfo *pCreateInfo,
528 const VkAllocationCallbacks *pAllocator,
529 const struct loader_instance *inst,
530 struct loader_device *dev);
Jon Ashburnc4e9ae62016-02-26 13:14:27 -0700531VkResult loader_validate_device_extensions(
Jon Ashburnc3519e42016-03-24 15:49:57 -0600532 struct loader_physical_device_tramp *phys_dev,
Jon Ashburnc4e9ae62016-02-26 13:14:27 -0700533 const struct loader_layer_list *activated_device_layers,
Jon Ashburnfd02a0f2016-03-01 19:51:07 -0700534 const struct loader_extension_list *icd_exts,
Jon Ashburnc4e9ae62016-02-26 13:14:27 -0700535 const VkDeviceCreateInfo *pCreateInfo);
Courtney Goeltzenleuchter71b454b2015-07-05 11:28:29 -0600536
Jon Ashburnc4e9ae62016-02-26 13:14:27 -0700537/* instance layer chain termination entrypoint definitions */
538VKAPI_ATTR VkResult VKAPI_CALL
539terminator_CreateInstance(const VkInstanceCreateInfo *pCreateInfo,
540 const VkAllocationCallbacks *pAllocator,
541 VkInstance *pInstance);
Jon Ashburnb4dee9c2015-08-28 15:19:27 -0600542
Jon Ashburnc4e9ae62016-02-26 13:14:27 -0700543VKAPI_ATTR void VKAPI_CALL
544terminator_DestroyInstance(VkInstance instance,
545 const VkAllocationCallbacks *pAllocator);
Jon Ashburnb4dee9c2015-08-28 15:19:27 -0600546
Jon Ashburnc4e9ae62016-02-26 13:14:27 -0700547VKAPI_ATTR VkResult VKAPI_CALL
548terminator_EnumeratePhysicalDevices(VkInstance instance,
549 uint32_t *pPhysicalDeviceCount,
550 VkPhysicalDevice *pPhysicalDevices);
551
552VKAPI_ATTR void VKAPI_CALL
553terminator_GetPhysicalDeviceFeatures(VkPhysicalDevice physicalDevice,
554 VkPhysicalDeviceFeatures *pFeatures);
555
556VKAPI_ATTR void VKAPI_CALL
557terminator_GetPhysicalDeviceFormatProperties(VkPhysicalDevice physicalDevice,
558 VkFormat format,
559 VkFormatProperties *pFormatInfo);
560
561VKAPI_ATTR VkResult VKAPI_CALL
562terminator_GetPhysicalDeviceImageFormatProperties(
563 VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type,
564 VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags,
565 VkImageFormatProperties *pImageFormatProperties);
566
567VKAPI_ATTR void VKAPI_CALL
568terminator_GetPhysicalDeviceSparseImageFormatProperties(
569 VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type,
570 VkSampleCountFlagBits samples, VkImageUsageFlags usage,
571 VkImageTiling tiling, uint32_t *pNumProperties,
572 VkSparseImageFormatProperties *pProperties);
573
574VKAPI_ATTR void VKAPI_CALL
575terminator_GetPhysicalDeviceProperties(VkPhysicalDevice physicalDevice,
576 VkPhysicalDeviceProperties *pProperties);
577
578VKAPI_ATTR VkResult VKAPI_CALL terminator_EnumerateDeviceExtensionProperties(
579 VkPhysicalDevice physicalDevice, const char *pLayerName, uint32_t *pCount,
580 VkExtensionProperties *pProperties);
581
582VKAPI_ATTR VkResult VKAPI_CALL
583terminator_EnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice,
584 uint32_t *pCount,
585 VkLayerProperties *pProperties);
586
587VKAPI_ATTR void VKAPI_CALL terminator_GetPhysicalDeviceQueueFamilyProperties(
588 VkPhysicalDevice physicalDevice, uint32_t *pCount,
589 VkQueueFamilyProperties *pProperties);
590
591VKAPI_ATTR void VKAPI_CALL terminator_GetPhysicalDeviceMemoryProperties(
592 VkPhysicalDevice physicalDevice,
593 VkPhysicalDeviceMemoryProperties *pProperties);
594
595VKAPI_ATTR VkResult VKAPI_CALL
596terminator_CreateDevice(VkPhysicalDevice gpu,
597 const VkDeviceCreateInfo *pCreateInfo,
598 const VkAllocationCallbacks *pAllocator,
599 VkDevice *pDevice);
Mark Lobodzinski8d325802016-02-02 18:53:34 -0700600
Jon Ashburnb1cdf2e2016-02-10 20:50:19 -0700601VkStringErrorFlags vk_string_validate(const int max_length,
602 const char *char_array);
Mark Lobodzinski8d325802016-02-02 18:53:34 -0700603
Chia-I Wuc1e0f962014-08-04 08:03:57 +0800604#endif /* LOADER_H */