blob: cb5f20637f7c2414a3d8226e2295716a15c5ce60 [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
Jon Ashburn23d36b12016-02-02 17:47:28 -0700147// loader_dispatch_hash_entry and loader_dev_ext_dispatch_table.DevExt have one
148// to one
Jon Ashburnfc1031e2015-11-17 15:31:02 -0700149// correspondence; one loader_dispatch_hash_entry for one DevExt dispatch entry.
150// 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 {
158 PFN_vkDevExt DevExt[MAX_NUM_DEV_EXTS];
159};
160
161struct loader_dev_dispatch_table {
162 VkLayerDispatchTable core_dispatch;
163 struct loader_dev_ext_dispatch_table ext_dispatch;
164};
165
Jon Ashburndc6fcad2015-06-10 10:06:06 -0600166/* per CreateDevice structure */
167struct 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
Jon Ashburn23d36b12016-02-02 17:47:28 -0700171 uint32_t app_extension_count;
Jon Ashburndc6fcad2015-06-10 10:06:06 -0600172 VkExtensionProperties *app_extension_props;
173
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -0600174 struct loader_layer_list activated_layer_list;
Jon Ashburndc6fcad2015-06-10 10:06:06 -0600175
Mark Young0ad83132016-06-30 13:02:42 -0600176 VkAllocationCallbacks alloc_callbacks;
177
Jon Ashburndc6fcad2015-06-10 10:06:06 -0600178 struct loader_device *next;
179};
180
Jon Ashburn953bb3c2015-06-10 16:11:42 -0600181/* per ICD structure */
Jon Ashburn95a77ba2015-05-15 15:09:35 -0600182struct loader_icd {
Jon Ashburn3d002332015-08-20 16:35:30 -0600183 // pointers to find other structs
184 const struct loader_scanned_icds *this_icd_lib;
185 const struct loader_instance *this_instance;
Jon Ashburndc6fcad2015-06-10 10:06:06 -0600186 struct loader_device *logical_device_list;
Jon Ashburn23d36b12016-02-02 17:47:28 -0700187 VkInstance instance; // instance object from the icd
Jon Ashburn8d1b0b52015-05-18 13:20:15 -0600188 PFN_vkGetDeviceProcAddr GetDeviceProcAddr;
Jon Ashburn95a77ba2015-05-15 15:09:35 -0600189 PFN_vkDestroyInstance DestroyInstance;
190 PFN_vkEnumeratePhysicalDevices EnumeratePhysicalDevices;
Chris Forbesbc0bb772015-06-21 22:55:02 +1200191 PFN_vkGetPhysicalDeviceFeatures GetPhysicalDeviceFeatures;
Courtney Goeltzenleuchter2caec862015-07-12 12:52:09 -0600192 PFN_vkGetPhysicalDeviceFormatProperties GetPhysicalDeviceFormatProperties;
Jon Ashburn23d36b12016-02-02 17:47:28 -0700193 PFN_vkGetPhysicalDeviceImageFormatProperties
194 GetPhysicalDeviceImageFormatProperties;
Jon Ashburn95a77ba2015-05-15 15:09:35 -0600195 PFN_vkCreateDevice CreateDevice;
Tony Barbour59a47322015-06-24 16:06:58 -0600196 PFN_vkGetPhysicalDeviceProperties GetPhysicalDeviceProperties;
Jon Ashburn23d36b12016-02-02 17:47:28 -0700197 PFN_vkGetPhysicalDeviceQueueFamilyProperties
198 GetPhysicalDeviceQueueFamilyProperties;
Tony Barbour59a47322015-06-24 16:06:58 -0600199 PFN_vkGetPhysicalDeviceMemoryProperties GetPhysicalDeviceMemoryProperties;
Courtney Goeltzenleuchter35985f62015-09-14 17:22:16 -0600200 PFN_vkEnumerateDeviceExtensionProperties EnumerateDeviceExtensionProperties;
Jon Ashburn23d36b12016-02-02 17:47:28 -0700201 PFN_vkGetPhysicalDeviceSparseImageFormatProperties
202 GetPhysicalDeviceSparseImageFormatProperties;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700203 PFN_vkCreateDebugReportCallbackEXT CreateDebugReportCallbackEXT;
204 PFN_vkDestroyDebugReportCallbackEXT DestroyDebugReportCallbackEXT;
205 PFN_vkDebugReportMessageEXT DebugReportMessageEXT;
Ian Elliott7e40db92015-08-21 15:09:33 -0600206 PFN_vkGetPhysicalDeviceSurfaceSupportKHR GetPhysicalDeviceSurfaceSupportKHR;
Jon Ashburn23d36b12016-02-02 17:47:28 -0700207 PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR
208 GetPhysicalDeviceSurfaceCapabilitiesKHR;
Ian Elliott486c5502015-11-19 16:05:09 -0700209 PFN_vkGetPhysicalDeviceSurfaceFormatsKHR GetPhysicalDeviceSurfaceFormatsKHR;
Jon Ashburn23d36b12016-02-02 17:47:28 -0700210 PFN_vkGetPhysicalDeviceSurfacePresentModesKHR
211 GetPhysicalDeviceSurfacePresentModesKHR;
Ian Elliott919fa302015-11-24 15:39:10 -0700212#ifdef VK_USE_PLATFORM_WIN32_KHR
Jon Ashburn23d36b12016-02-02 17:47:28 -0700213 PFN_vkGetPhysicalDeviceWin32PresentationSupportKHR
214 GetPhysicalDeviceWin32PresentationSupportKHR;
Ian Elliott919fa302015-11-24 15:39:10 -0700215#endif
216#ifdef VK_USE_PLATFORM_MIR_KHR
Jon Ashburn23d36b12016-02-02 17:47:28 -0700217 PFN_vkGetPhysicalDeviceMirPresentationSupportKHR
218 GetPhysicalDeviceMirPresentvationSupportKHR;
Ian Elliott919fa302015-11-24 15:39:10 -0700219#endif
220#ifdef VK_USE_PLATFORM_WAYLAND_KHR
Jon Ashburn23d36b12016-02-02 17:47:28 -0700221 PFN_vkGetPhysicalDeviceWaylandPresentationSupportKHR
222 GetPhysicalDeviceWaylandPresentationSupportKHR;
Ian Elliott919fa302015-11-24 15:39:10 -0700223#endif
224#ifdef VK_USE_PLATFORM_XCB_KHR
Jon Ashburn23d36b12016-02-02 17:47:28 -0700225 PFN_vkGetPhysicalDeviceXcbPresentationSupportKHR
226 GetPhysicalDeviceXcbPresentationSupportKHR;
Ian Elliott919fa302015-11-24 15:39:10 -0700227#endif
228#ifdef VK_USE_PLATFORM_XLIB_KHR
Jon Ashburn23d36b12016-02-02 17:47:28 -0700229 PFN_vkGetPhysicalDeviceXlibPresentationSupportKHR
230 GetPhysicalDeviceXlibPresentationSupportKHR;
Ian Elliott919fa302015-11-24 15:39:10 -0700231#endif
Jon Ashburnc7d3e732016-03-08 09:30:30 -0700232 PFN_vkGetPhysicalDeviceDisplayPropertiesKHR
233 GetPhysicalDeviceDisplayPropertiesKHR;
234 PFN_vkGetPhysicalDeviceDisplayPlanePropertiesKHR
235 GetPhysicalDeviceDisplayPlanePropertiesKHR;
236 PFN_vkGetDisplayPlaneSupportedDisplaysKHR
237 GetDisplayPlaneSupportedDisplaysKHR;
Jon Ashburncc407a22016-04-15 09:25:03 -0600238 PFN_vkGetDisplayModePropertiesKHR GetDisplayModePropertiesKHR;
239 PFN_vkCreateDisplayModeKHR CreateDisplayModeKHR;
240 PFN_vkGetDisplayPlaneCapabilitiesKHR GetDisplayPlaneCapabilitiesKHR;
241 PFN_vkCreateDisplayPlaneSurfaceKHR CreateDisplayPlaneSurfaceKHR;
242 PFN_vkDestroySurfaceKHR DestroySurfaceKHR;
Jon Ashburndc6fcad2015-06-10 10:06:06 -0600243 struct loader_icd *next;
Jon Ashburn95a77ba2015-05-15 15:09:35 -0600244};
245
Jon Ashburn8810c5f2015-08-18 18:04:47 -0600246/* per ICD library structure */
247struct loader_icd_libs {
248 size_t capacity;
249 uint32_t count;
250 struct loader_scanned_icds *list;
251};
252
Jon Ashburn953bb3c2015-06-10 16:11:42 -0600253/* per instance structure */
Jon Ashburn27cd5842015-05-12 17:26:48 -0600254struct loader_instance {
Jon Ashburn95a77ba2015-05-15 15:09:35 -0600255 VkLayerInstanceDispatchTable *disp; // must be first entry in structure
256
Jon Ashburn014438f2016-03-01 19:51:07 -0700257 uint32_t total_gpu_count; // count of the next two arrays
258 struct loader_physical_device *phys_devs_term;
Jon Ashburncc407a22016-04-15 09:25:03 -0600259 struct loader_physical_device_tramp *
260 phys_devs; // tramp wrapped physDev obj list
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600261 uint32_t total_icd_count;
Jon Ashburn27cd5842015-05-12 17:26:48 -0600262 struct loader_icd *icds;
263 struct loader_instance *next;
Jon Ashburn23d36b12016-02-02 17:47:28 -0700264 struct loader_extension_list ext_list; // icds and loaders extensions
Jon Ashburn8810c5f2015-08-18 18:04:47 -0600265 struct loader_icd_libs icd_libs;
Jon Ashburn3d002332015-08-20 16:35:30 -0600266 struct loader_layer_list instance_layer_list;
Jon Ashburnfc1031e2015-11-17 15:31:02 -0700267 struct loader_dispatch_hash_entry disp_hash[MAX_NUM_DEV_EXTS];
Jon Ashburn3d002332015-08-20 16:35:30 -0600268
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600269 struct loader_msg_callback_map_entry *icd_msg_callback_map;
270
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -0600271 struct loader_layer_list activated_layer_list;
Jon Ashburn491cd042016-05-16 14:01:18 -0600272 bool activated_layers_are_std_val;
Jon Ashburncc407a22016-04-15 09:25:03 -0600273 VkInstance instance; // layers/ICD instance returned to trampoline
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700274
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600275 bool debug_report_enabled;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600276 VkLayerDbgFunctionNode *DbgFunctionHead;
Ian Elliottad6300f2016-03-31 10:48:19 -0600277 uint32_t num_tmp_callbacks;
278 VkDebugReportCallbackCreateInfoEXT *tmp_dbg_create_infos;
279 VkDebugReportCallbackEXT *tmp_callbacks;
Courtney Goeltzenleuchter7f5aafc2015-07-05 11:28:29 -0600280
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800281 VkAllocationCallbacks alloc_callbacks;
Ian Elliottd3ef02f2015-07-06 14:36:13 -0600282
Ian Elliott954fa342015-10-30 15:28:23 -0600283 bool wsi_surface_enabled;
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -0700284#ifdef VK_USE_PLATFORM_WIN32_KHR
Ian Elliott954fa342015-10-30 15:28:23 -0600285 bool wsi_win32_surface_enabled;
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -0700286#endif
287#ifdef VK_USE_PLATFORM_MIR_KHR
Ian Elliott954fa342015-10-30 15:28:23 -0600288 bool wsi_mir_surface_enabled;
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -0700289#endif
290#ifdef VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott954fa342015-10-30 15:28:23 -0600291 bool wsi_wayland_surface_enabled;
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -0700292#endif
293#ifdef VK_USE_PLATFORM_XCB_KHR
Ian Elliott954fa342015-10-30 15:28:23 -0600294 bool wsi_xcb_surface_enabled;
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -0700295#endif
296#ifdef VK_USE_PLATFORM_XLIB_KHR
Ian Elliott954fa342015-10-30 15:28:23 -0600297 bool wsi_xlib_surface_enabled;
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -0700298#endif
299#ifdef VK_USE_PLATFORM_ANDROID_KHR
300 bool wsi_android_surface_enabled;
301#endif
Jon Ashburnc7d3e732016-03-08 09:30:30 -0700302 bool wsi_display_enabled;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600303};
304
Jon Ashburn014438f2016-03-01 19:51:07 -0700305/* VkPhysicalDevice requires special treatment by loader. Firstly, terminator
306 * code must be able to get the struct loader_icd to call into the proper
307 * driver (multiple ICD/gpu case). This can be accomplished by wrapping the
308 * created VkPhysicalDevice in loader terminate_EnumeratePhysicalDevices().
Piers Daniell295fe402016-03-29 11:51:11 -0600309 * Secondly, the loader must be able to handle wrapped by layer VkPhysicalDevice
Jon Ashburn014438f2016-03-01 19:51:07 -0700310 * in trampoline code. This implies, that the loader trampoline code must also
311 * wrap the VkPhysicalDevice object in trampoline code. Thus, loader has to
312 * wrap the VkPhysicalDevice created object twice. In trampoline code it can't
313 * rely on the terminator object wrapping since a layer may also wrap. Since
314 * trampoline code wraps the VkPhysicalDevice this means all loader trampoline
315 * code that passes a VkPhysicalDevice should unwrap it. */
316
317/* per enumerated PhysicalDevice structure, used to wrap in trampoline code and
318 also same structure used to wrap in terminator code */
Jon Ashburn787eb252016-03-24 15:49:57 -0600319struct loader_physical_device_tramp {
320 VkLayerInstanceDispatchTable *disp; // must be first entry in structure
Piers Daniell295fe402016-03-29 11:51:11 -0600321 struct loader_instance *this_instance;
Jon Ashburncc407a22016-04-15 09:25:03 -0600322 VkPhysicalDevice phys_dev; // object from layers/loader terminator
Jon Ashburn787eb252016-03-24 15:49:57 -0600323};
324
325/* per enumerated PhysicalDevice structure, used to wrap in terminator code */
Jon Ashburn24cd4be2015-11-01 14:04:06 -0700326struct loader_physical_device {
327 VkLayerInstanceDispatchTable *disp; // must be first entry in structure
Jon Ashburn24cd4be2015-11-01 14:04:06 -0700328 struct loader_icd *this_icd;
Jon Ashburn787eb252016-03-24 15:49:57 -0600329 VkPhysicalDevice phys_dev; // object from ICD
Jon Ashburn24cd4be2015-11-01 14:04:06 -0700330};
331
Jon Ashburn27cd5842015-05-12 17:26:48 -0600332struct loader_struct {
333 struct loader_instance *instances;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600334};
335
336struct loader_scanned_icds {
337 char *lib_name;
338 loader_platform_dl_handle handle;
Jon Ashburn005617f2015-11-17 17:35:40 -0700339 uint32_t api_version;
Jon Ashburn17b4c862016-04-25 11:09:37 -0600340 uint32_t interface_version;
Jon Ashburnc624c882015-07-16 10:17:29 -0600341 PFN_vkGetInstanceProcAddr GetInstanceProcAddr;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600342 PFN_vkCreateInstance CreateInstance;
Jon Ashburn23d36b12016-02-02 17:47:28 -0700343 PFN_vkEnumerateInstanceExtensionProperties
344 EnumerateInstanceExtensionProperties;
Jon Ashburn27cd5842015-05-12 17:26:48 -0600345};
346
Jon Ashburn5ef20602015-07-02 09:40:15 -0600347static inline struct loader_instance *loader_instance(VkInstance instance) {
Jon Ashburn23d36b12016-02-02 17:47:28 -0700348 return (struct loader_instance *)instance;
Jon Ashburn5ef20602015-07-02 09:40:15 -0600349}
350
Jon Ashburn014438f2016-03-01 19:51:07 -0700351static inline VkPhysicalDevice
352loader_unwrap_physical_device(VkPhysicalDevice physicalDevice) {
Piers Daniell61e45382016-03-31 14:47:57 -0600353 struct loader_physical_device_tramp *phys_dev =
354 (struct loader_physical_device_tramp *)physicalDevice;
Jon Ashburn014438f2016-03-01 19:51:07 -0700355 return phys_dev->phys_dev;
356}
357
Jon Ashburn23d36b12016-02-02 17:47:28 -0700358static inline void loader_set_dispatch(void *obj, const void *data) {
359 *((const void **)obj) = data;
Chia-I Wu5291c762015-04-11 15:34:07 +0800360}
361
Jon Ashburn23d36b12016-02-02 17:47:28 -0700362static inline VkLayerDispatchTable *loader_get_dispatch(const void *obj) {
363 return *((VkLayerDispatchTable **)obj);
Chia-I Wu5291c762015-04-11 15:34:07 +0800364}
365
Jon Ashburn23d36b12016-02-02 17:47:28 -0700366static inline struct loader_dev_dispatch_table *
367loader_get_dev_dispatch(const void *obj) {
368 return *((struct loader_dev_dispatch_table **)obj);
Jon Ashburnfc1031e2015-11-17 15:31:02 -0700369}
370
Jon Ashburn23d36b12016-02-02 17:47:28 -0700371static inline VkLayerInstanceDispatchTable *
372loader_get_instance_dispatch(const void *obj) {
373 return *((VkLayerInstanceDispatchTable **)obj);
Jon Ashburn27cd5842015-05-12 17:26:48 -0600374}
375
Jon Ashburn23d36b12016-02-02 17:47:28 -0700376static inline void loader_init_dispatch(void *obj, const void *data) {
Jon Ashburn40066642015-04-15 13:34:33 -0600377#ifdef DEBUG
Chia-I Wu5291c762015-04-11 15:34:07 +0800378 assert(valid_loader_magic_value(obj) &&
Jon Ashburn23d36b12016-02-02 17:47:28 -0700379 "Incompatible ICD, first dword must be initialized to "
380 "ICD_LOADER_MAGIC. See loader/README.md for details.");
Jon Ashburn40066642015-04-15 13:34:33 -0600381#endif
Chia-I Wu5291c762015-04-11 15:34:07 +0800382
Jon Ashburn1ed042c2015-05-01 18:00:33 -0600383 loader_set_dispatch(obj, data);
Chia-I Wu5291c762015-04-11 15:34:07 +0800384}
385
Jon Ashburn27cd5842015-05-12 17:26:48 -0600386/* global variables used across files */
387extern struct loader_struct loader;
Jon Ashburn87d6aa92015-08-28 15:19:27 -0600388extern THREAD_LOCAL_DECL struct loader_instance *tls_instance;
Jon Ashburn8810c5f2015-08-18 18:04:47 -0600389extern LOADER_PLATFORM_THREAD_ONCE_DEFINITION(once_init);
Jon Ashburn6301a0f2015-05-29 13:15:39 -0600390extern loader_platform_thread_mutex loader_lock;
Jon Ashburn6461ef22015-09-22 13:11:00 -0600391extern loader_platform_thread_mutex loader_json_lock;
Jon Ashburn6301a0f2015-05-29 13:15:39 -0600392extern const VkLayerInstanceDispatchTable instance_disp;
Jon Ashburn86a527a2016-02-10 20:59:26 -0700393extern const char *std_validation_str;
Jon Ashburnbacb0f52015-04-06 10:58:22 -0600394
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600395struct loader_msg_callback_map_entry {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700396 VkDebugReportCallbackEXT icd_obj;
397 VkDebugReportCallbackEXT loader_obj;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600398};
399
Jon Ashburn1530c342016-02-26 13:14:27 -0700400/* helper function definitions */
Mark Young0ad83132016-06-30 13:02:42 -0600401void *loader_instance_heap_alloc(const struct loader_instance *instance, size_t size, VkSystemAllocationScope allocationScope);
402void loader_instance_heap_free(const struct loader_instance *instance, void *pMemory);
403void *loader_instance_heap_realloc(const struct loader_instance *instance, void *pMemory, size_t orig_size, size_t size, VkSystemAllocationScope alloc_scope);
404void *loader_instance_tls_heap_alloc(size_t size);
405void loader_instance_tls_heap_free(void *pMemory);
406void *loader_device_heap_alloc(const struct loader_device *device, size_t size, VkSystemAllocationScope allocationScope);
407void loader_device_heap_free(const struct loader_device *device, void *pMemory);
408void *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 -0700409
Jon Ashburn2e37d752016-02-12 08:20:06 -0700410void loader_log(const struct loader_instance *inst, VkFlags msg_type,
Jon Ashburn1530c342016-02-26 13:14:27 -0700411 int32_t msg_code, const char *format, ...);
Jon Ashburn2e37d752016-02-12 08:20:06 -0700412
Jon Ashburn23d36b12016-02-02 17:47:28 -0700413bool compare_vk_extension_properties(const VkExtensionProperties *op1,
414 const VkExtensionProperties *op2);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600415
Mark Lobodzinskie9f09ef2016-02-02 18:53:34 -0700416VkResult loader_validate_layers(const struct loader_instance *inst,
417 const uint32_t layer_count,
Jon Ashburn23d36b12016-02-02 17:47:28 -0700418 const char *const *ppEnabledLayerNames,
419 const struct loader_layer_list *list);
Courtney Goeltzenleuchter3b8c5ff2015-07-06 17:45:08 -0600420
421VkResult loader_validate_instance_extensions(
Mark Lobodzinskie9f09ef2016-02-02 18:53:34 -0700422 const struct loader_instance *inst,
Jon Ashburn23d36b12016-02-02 17:47:28 -0700423 const struct loader_extension_list *icd_exts,
424 const struct loader_layer_list *instance_layer,
425 const VkInstanceCreateInfo *pCreateInfo);
Courtney Goeltzenleuchter3b8c5ff2015-07-06 17:45:08 -0600426
Jon Ashburn8810c5f2015-08-18 18:04:47 -0600427void loader_initialize(void);
Mark Young0ad83132016-06-30 13:02:42 -0600428VkResult loader_copy_layer_properties(const struct loader_instance *inst,
429 struct loader_layer_properties *dst,
430 struct loader_layer_properties *src);
Jon Ashburn23d36b12016-02-02 17:47:28 -0700431bool has_vk_extension_property_array(const VkExtensionProperties *vk_ext_prop,
432 const uint32_t count,
433 const VkExtensionProperties *ext_array);
434bool has_vk_extension_property(const VkExtensionProperties *vk_ext_prop,
435 const struct loader_extension_list *ext_list);
Jon Ashburn27cd5842015-05-12 17:26:48 -0600436
Jon Ashburn23d36b12016-02-02 17:47:28 -0700437VkResult loader_add_to_ext_list(const struct loader_instance *inst,
438 struct loader_extension_list *ext_list,
439 uint32_t prop_list_count,
440 const VkExtensionProperties *props);
Jon Ashburncc407a22016-04-15 09:25:03 -0600441VkResult
442loader_add_to_dev_ext_list(const struct loader_instance *inst,
443 struct loader_device_extension_list *ext_list,
444 const VkExtensionProperties *props,
445 uint32_t entry_count, char **entrys);
Jon Ashburn1530c342016-02-26 13:14:27 -0700446VkResult loader_add_device_extensions(const struct loader_instance *inst,
Jon Ashburncc407a22016-04-15 09:25:03 -0600447 PFN_vkEnumerateDeviceExtensionProperties
448 fpEnumerateDeviceExtensionProperties,
Jon Ashburn1530c342016-02-26 13:14:27 -0700449 VkPhysicalDevice physical_device,
450 const char *lib_name,
451 struct loader_extension_list *ext_list);
452bool loader_init_generic_list(const struct loader_instance *inst,
453 struct loader_generic_list *list_info,
454 size_t element_size);
Jon Ashburn23d36b12016-02-02 17:47:28 -0700455void loader_destroy_generic_list(const struct loader_instance *inst,
456 struct loader_generic_list *list);
Jon Ashburn1530c342016-02-26 13:14:27 -0700457void loader_destroy_layer_list(const struct loader_instance *inst,
Mark Young0ad83132016-06-30 13:02:42 -0600458 struct loader_device *device,
Jon Ashburn1530c342016-02-26 13:14:27 -0700459 struct loader_layer_list *layer_list);
Jon Ashburn23d36b12016-02-02 17:47:28 -0700460void loader_delete_layer_properties(const struct loader_instance *inst,
461 struct loader_layer_list *layer_list);
Jon Ashburn491cd042016-05-16 14:01:18 -0600462bool loader_find_layer_name_array(const char *name, uint32_t layer_count,
463 const char layer_list[][VK_MAX_EXTENSION_NAME_SIZE]);
Mark Young0ad83132016-06-30 13:02:42 -0600464VkResult loader_expand_layer_names(
Jon Ashburn491cd042016-05-16 14:01:18 -0600465 struct loader_instance *inst, const char *key_name,
Jon Ashburn86a527a2016-02-10 20:59:26 -0700466 uint32_t expand_count,
467 const char expand_names[][VK_MAX_EXTENSION_NAME_SIZE],
Jon Ashburncc407a22016-04-15 09:25:03 -0600468 uint32_t *layer_count, char const *const **ppp_layer_names);
Jon Ashburn491cd042016-05-16 14:01:18 -0600469void loader_init_std_validation_props(struct loader_layer_properties *props);
Chris Forbesbd9de052016-04-06 20:49:02 +1200470void loader_delete_shadow_dev_layer_names(const struct loader_instance *inst,
471 const VkDeviceCreateInfo *orig,
472 VkDeviceCreateInfo *ours);
473void loader_delete_shadow_inst_layer_names(const struct loader_instance *inst,
474 const VkInstanceCreateInfo *orig,
475 VkInstanceCreateInfo *ours);
Mark Young0ad83132016-06-30 13:02:42 -0600476VkResult loader_add_to_layer_list(const struct loader_instance *inst,
477 struct loader_layer_list *list,
478 uint32_t prop_list_count,
479 const struct loader_layer_properties *props);
Jon Ashburncc407a22016-04-15 09:25:03 -0600480void loader_find_layer_name_add_list(
481 const struct loader_instance *inst, const char *name,
482 const enum layer_type type, const struct loader_layer_list *search_list,
483 struct loader_layer_list *found_list);
Jon Ashburn23d36b12016-02-02 17:47:28 -0700484void loader_scanned_icd_clear(const struct loader_instance *inst,
485 struct loader_icd_libs *icd_libs);
Mark Young0ad83132016-06-30 13:02:42 -0600486VkResult loader_icd_scan(const struct loader_instance *inst,
Jon Ashburn23d36b12016-02-02 17:47:28 -0700487 struct loader_icd_libs *icds);
488void loader_layer_scan(const struct loader_instance *inst,
Jon Ashburn491cd042016-05-16 14:01:18 -0600489 struct loader_layer_list *instance_layers);
Jeremy Hayes3e2bd5a2016-04-01 11:40:26 -0600490void loader_implicit_layer_scan(const struct loader_instance *inst,
Jon Ashburn491cd042016-05-16 14:01:18 -0600491 struct loader_layer_list *instance_layers);
Jon Ashburn8810c5f2015-08-18 18:04:47 -0600492void loader_get_icd_loader_instance_extensions(
Jon Ashburn23d36b12016-02-02 17:47:28 -0700493 const struct loader_instance *inst, struct loader_icd_libs *icd_libs,
494 struct loader_extension_list *inst_exts);
495struct loader_icd *loader_get_icd_and_device(const VkDevice device,
496 struct loader_device **found_dev);
Jon Ashburn1530c342016-02-26 13:14:27 -0700497void loader_init_dispatch_dev_ext(struct loader_instance *inst,
498 struct loader_device *dev);
Jon Ashburn23d36b12016-02-02 17:47:28 -0700499void *loader_dev_ext_gpa(struct loader_instance *inst, const char *funcName);
500void *loader_get_dev_ext_trampoline(uint32_t index);
501struct loader_instance *loader_get_instance(const VkInstance instance);
Jon Ashburn4dc1d8a2016-04-20 13:21:17 -0600502void loader_deactivate_layers(const struct loader_instance *instance,
Mark Young0ad83132016-06-30 13:02:42 -0600503 struct loader_device *device,
Jon Ashburn4dc1d8a2016-04-20 13:21:17 -0600504 struct loader_layer_list *list);
Jon Ashburn1530c342016-02-26 13:14:27 -0700505struct loader_device *
Mark Young0ad83132016-06-30 13:02:42 -0600506loader_create_logical_device(const struct loader_instance *inst, const VkAllocationCallbacks *pAllocator);
Piers Daniell295fe402016-03-29 11:51:11 -0600507void loader_add_logical_device(const struct loader_instance *inst,
508 struct loader_icd *icd,
509 struct loader_device *found_dev);
Jon Ashburn23d36b12016-02-02 17:47:28 -0700510void loader_remove_logical_device(const struct loader_instance *inst,
511 struct loader_icd *icd,
Mark Young0ad83132016-06-30 13:02:42 -0600512 struct loader_device *found_dev,
513 const VkAllocationCallbacks *pAllocator);
514// NOTE: Outside of loader, this entry-point is only proivided for error cleanup.
515void loader_destroy_logical_device(const struct loader_instance *inst,
516 struct loader_device *dev,
517 const VkAllocationCallbacks *pAllocator);
518
Jon Ashburn23d36b12016-02-02 17:47:28 -0700519VkResult
520loader_enable_instance_layers(struct loader_instance *inst,
521 const VkInstanceCreateInfo *pCreateInfo,
522 const struct loader_layer_list *instance_layers);
Jon Ashburndc6fcad2015-06-10 10:06:06 -0600523void loader_deactivate_instance_layers(struct loader_instance *instance);
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700524
Jon Ashburn23d36b12016-02-02 17:47:28 -0700525VkResult loader_create_instance_chain(const VkInstanceCreateInfo *pCreateInfo,
526 const VkAllocationCallbacks *pAllocator,
527 struct loader_instance *inst,
Jon Ashburn6e0a2132016-02-03 12:37:30 -0700528 VkInstance *created_instance);
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700529
Jon Ashburn23d36b12016-02-02 17:47:28 -0700530void loader_activate_instance_layer_extensions(struct loader_instance *inst,
531 VkInstance created_inst);
Jon Ashburn1530c342016-02-26 13:14:27 -0700532VkResult
533loader_enable_device_layers(const struct loader_instance *inst,
Jon Ashburn1530c342016-02-26 13:14:27 -0700534 struct loader_layer_list *activated_layer_list,
535 const VkDeviceCreateInfo *pCreateInfo,
536 const struct loader_layer_list *device_layers);
Courtney Goeltzenleuchter7f5aafc2015-07-05 11:28:29 -0600537
Jon Ashburncc407a22016-04-15 09:25:03 -0600538VkResult
539loader_create_device_chain(const struct loader_physical_device_tramp *pd,
540 const VkDeviceCreateInfo *pCreateInfo,
541 const VkAllocationCallbacks *pAllocator,
542 const struct loader_instance *inst,
543 struct loader_device *dev);
Jon Ashburn1530c342016-02-26 13:14:27 -0700544VkResult loader_validate_device_extensions(
Jon Ashburn787eb252016-03-24 15:49:57 -0600545 struct loader_physical_device_tramp *phys_dev,
Jon Ashburn1530c342016-02-26 13:14:27 -0700546 const struct loader_layer_list *activated_device_layers,
Jon Ashburn014438f2016-03-01 19:51:07 -0700547 const struct loader_extension_list *icd_exts,
Jon Ashburn1530c342016-02-26 13:14:27 -0700548 const VkDeviceCreateInfo *pCreateInfo);
Courtney Goeltzenleuchter7f5aafc2015-07-05 11:28:29 -0600549
Jon Ashburn1530c342016-02-26 13:14:27 -0700550/* instance layer chain termination entrypoint definitions */
551VKAPI_ATTR VkResult VKAPI_CALL
552terminator_CreateInstance(const VkInstanceCreateInfo *pCreateInfo,
553 const VkAllocationCallbacks *pAllocator,
554 VkInstance *pInstance);
Jon Ashburn87d6aa92015-08-28 15:19:27 -0600555
Jon Ashburn1530c342016-02-26 13:14:27 -0700556VKAPI_ATTR void VKAPI_CALL
557terminator_DestroyInstance(VkInstance instance,
558 const VkAllocationCallbacks *pAllocator);
Jon Ashburn87d6aa92015-08-28 15:19:27 -0600559
Jon Ashburn1530c342016-02-26 13:14:27 -0700560VKAPI_ATTR VkResult VKAPI_CALL
561terminator_EnumeratePhysicalDevices(VkInstance instance,
562 uint32_t *pPhysicalDeviceCount,
563 VkPhysicalDevice *pPhysicalDevices);
564
565VKAPI_ATTR void VKAPI_CALL
566terminator_GetPhysicalDeviceFeatures(VkPhysicalDevice physicalDevice,
567 VkPhysicalDeviceFeatures *pFeatures);
568
569VKAPI_ATTR void VKAPI_CALL
570terminator_GetPhysicalDeviceFormatProperties(VkPhysicalDevice physicalDevice,
571 VkFormat format,
572 VkFormatProperties *pFormatInfo);
573
574VKAPI_ATTR VkResult VKAPI_CALL
575terminator_GetPhysicalDeviceImageFormatProperties(
576 VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type,
577 VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags,
578 VkImageFormatProperties *pImageFormatProperties);
579
580VKAPI_ATTR void VKAPI_CALL
581terminator_GetPhysicalDeviceSparseImageFormatProperties(
582 VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type,
583 VkSampleCountFlagBits samples, VkImageUsageFlags usage,
584 VkImageTiling tiling, uint32_t *pNumProperties,
585 VkSparseImageFormatProperties *pProperties);
586
587VKAPI_ATTR void VKAPI_CALL
588terminator_GetPhysicalDeviceProperties(VkPhysicalDevice physicalDevice,
589 VkPhysicalDeviceProperties *pProperties);
590
591VKAPI_ATTR VkResult VKAPI_CALL terminator_EnumerateDeviceExtensionProperties(
592 VkPhysicalDevice physicalDevice, const char *pLayerName, uint32_t *pCount,
593 VkExtensionProperties *pProperties);
594
595VKAPI_ATTR VkResult VKAPI_CALL
596terminator_EnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice,
597 uint32_t *pCount,
598 VkLayerProperties *pProperties);
599
600VKAPI_ATTR void VKAPI_CALL terminator_GetPhysicalDeviceQueueFamilyProperties(
601 VkPhysicalDevice physicalDevice, uint32_t *pCount,
602 VkQueueFamilyProperties *pProperties);
603
604VKAPI_ATTR void VKAPI_CALL terminator_GetPhysicalDeviceMemoryProperties(
605 VkPhysicalDevice physicalDevice,
606 VkPhysicalDeviceMemoryProperties *pProperties);
607
608VKAPI_ATTR VkResult VKAPI_CALL
609terminator_CreateDevice(VkPhysicalDevice gpu,
610 const VkDeviceCreateInfo *pCreateInfo,
611 const VkAllocationCallbacks *pAllocator,
612 VkDevice *pDevice);
Mark Lobodzinskie9f09ef2016-02-02 18:53:34 -0700613
Jon Ashburnf2b4e382016-02-10 20:50:19 -0700614VkStringErrorFlags vk_string_validate(const int max_length,
615 const char *char_array);
Mark Lobodzinskie9f09ef2016-02-02 18:53:34 -0700616
Chia-I Wu19300602014-08-04 08:03:57 +0800617#endif /* LOADER_H */