blob: 84cdfde37a00310319c24f17ee63db9c452c206e [file] [log] [blame] [view]
Jon Ashburnbd7d1922015-01-06 10:33:36 -07001# Loader Description
2
3## Overview
Jon Ashburnfd4d09d2016-01-07 09:44:27 -07004The Loader implements the main VK library (e.g. "vulkan-1.dll" on Windows and
Jeremy Hayes22641442016-02-08 12:14:51 -07005"libvulkan.so" on Linux). It handles layer management and driver management. The
Ian Elliott3672c782015-02-13 11:23:05 -07006loader fully supports multi-gpu operation. As part of this, it dispatches API
7calls to the correct driver, and to the correct layers, based on the GPU object
8selected by the application.
Jon Ashburnbd7d1922015-01-06 10:33:36 -07009
Ian Elliott3672c782015-02-13 11:23:05 -070010The loader's driver management includes finding driver libraries and loading
11them. When a driver is initialized, the loader sets up its dispatch tables,
12using a very light-weight "trampoline" mechanism. To do so, it reserves space
13for a pointer in API objects (see below for more information about this).
14
15The loader's layer management includes finding layer libraries and activating
16them as requested. The loader correctly sets up each activated layer, and its
17own dispatch tables in order to support all activated layers. Each active
18layer can intercept a subset of the full API entrypoints. A layer which
19doesn't intercept a given entrypoint will be skipped for that entrypoint. The
20loader supports layers that operate on multiple GPUs.
Jon Ashburnbd7d1922015-01-06 10:33:36 -070021
Jon Ashburn4a511f12015-07-16 10:54:55 -060022## ICD discovery
23See file LinuxICDs.txt and WindowsICDs.txt for description of how the loader
24finds ICD driver libraries.
Jon Ashburnbd7d1922015-01-06 10:33:36 -070025
26## Interface to driver (ICD)
Jon Ashburnfd4d09d2016-01-07 09:44:27 -070027Currently two supported methods of the loader finding ICD entry points are supported:
281) Recommended
29- vk_icdGetInstanceProcAddr exported in the ICD library and returns valid function pointers for all the VK API entrypoints
Jon Ashburn8ceb1f12016-01-11 14:21:31 -070030 both core entry points and any instance or device extension entrypoints
31- ICD supports NULL instance handle for the global Vulkan entrypoints when called from vk_icdGetInstanceProcAddr
Jon Ashburnfd4d09d2016-01-07 09:44:27 -070032- all other Vulkan entrypoints either NOT exported from the ICD library or else will not use the official Vulkan function names
33 if they are exported. (NOTE: this requirement is for ICD libraries that include other functionality (such as OpenGL library)
34 and thus could be loaded prior to when the Vulkan loader library is loaded by the app. Thus the ICD library exported Vulkan symbols must not
35 clash with the loader's exported Vulkan symbols).
36 2) Deprecated
Jon Ashburn8ceb1f12016-01-11 14:21:31 -070037 - vkGetInstanceProcAddr exported in the ICD library and returns valid function pointers for all the VK API entrypoints.
38 - vkCreateInstance exported in the ICD library
39 - vkEnumerateInstanceExtensionProperties exported in the ICD library
Jon Ashburnfd4d09d2016-01-07 09:44:27 -070040
Jon Ashburn7726f4f2015-11-27 17:57:12 -070041- WSI surface extensions (vk_KHR_*surface) handling:
42 1. Loader handles the vkCreate*SurfaceKHR() and vkDestroySurfaceKHR() functions including creating/destroying the VkSurfaceKHR object
43 2. VkSurfaceKHR objects have the underlying structure (VKIcdSurface*) as defined in include/vulkan/vk_icd.h
44 3. ICDs can cast any VkSurfaceKHR object to a pointer to the appropriate VKIcdSurface* structure
45 4. VkIcdSurface* structures include VkIcdSurfaceWin32, VkIcdSurfaceXcb, VkIcdSurfaceXlib, VkIcdSurfaceMir, and VkIcdSurfaceWayland
46- all objects created by an ICD can be cast to (VK\_LAYER\_DISPATCH\_TABLE \*\*)
Jon Ashburnbd7d1922015-01-06 10:33:36 -070047 where the loader will replace the first entry with a pointer to the dispatch table which is
Courtney Goeltzenleuchter64ca9232015-02-10 18:40:14 -070048 owned by the loader. This implies three things for ICD drivers:
Ian Elliott3672c782015-02-13 11:23:05 -070049 1. The ICD must return a pointer for the opaque object handle
50 2. This pointer points to a regular C structure with the first entry being a pointer.
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060051 Note: for any C++ ICD's that implement VK objects directly as C++ classes.
Ian Elliott3672c782015-02-13 11:23:05 -070052 The C++ compiler may put a vtable at offset zero, if your class is virtual.
53 In this case use a regular C structure (see below).
54 3. The reservedForLoader.loaderMagic member must be initialized with ICD\_LOADER\_MAGIC, as follows:
55
Jon Ashburn50a561c2015-02-11 12:40:00 -070056```
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060057 #include "vkIcd.h"
Ian Elliott3672c782015-02-13 11:23:05 -070058
Jon Ashburn50a561c2015-02-11 12:40:00 -070059 struct {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060060 VK_LOADER_DATA reservedForLoader; // Reserve space for pointer to loader's dispatch table
Ian Elliott42258e02015-02-13 16:51:05 -070061 myObjectClass myObj; // Your driver's C++ class
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060062 } vkObj;
Ian Elliott3672c782015-02-13 11:23:05 -070063
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060064 vkObj alloc_icd_obj()
Ian Elliott3672c782015-02-13 11:23:05 -070065 {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060066 vkObj *newObj = alloc_obj();
Ian Elliott3672c782015-02-13 11:23:05 -070067 ...
68 // Initialize pointer to loader's dispatch table with ICD_LOADER_MAGIC
69 set_loader_magic_value(newObj);
70 ...
71 return newObj;
72 }
Jon Ashburn50a561c2015-02-11 12:40:00 -070073```
Ian Elliott3672c782015-02-13 11:23:05 -070074
75Additional Notes:
Jon Ashburnfd4d09d2016-01-07 09:44:27 -070076- loader will filter out extensions requested in vkCreateInstance and vkCreateDevice
77 before calling into the ICD;
78 Filtering will be of extensions advertised by entities (eg layers) different from the ICD in question
79- loader will not call ICD for vkEnumerate*LayerProperties() as layer properties are obtained from
80 the layer libraries and ICD files.
81- loader will not call ICD for vkEnumerate*ExtensionProperties(pLayerName != NULL)
Ian Elliott3672c782015-02-13 11:23:05 -070082- The ICD may or may not implement a dispatch table.
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060083- ICD entrypoints can be named anything including the offcial vk name such as vkCreateDevice(). However, beware of interposing by dynamic OS library loaders if the offical names are used. On Linux, if offical names are used, the ICD library must be linked with -Bsymbolic.
Courtney Goeltzenleuchterc1f86392015-01-07 09:24:45 -070084
Jon Ashburn4a511f12015-07-16 10:54:55 -060085## Layer library discovery
86See file LinuxICDs.txt and WindowsICDs.txt for description of how the loader
87finds layer libraries.
88
89## Interface to layer libraries
90TBD
91