blob: b8840d2c83725c8b12f8ac66416c9f4a8fbe3484 [file] [log] [blame] [view]
Jon Ashburn8c519362015-01-06 10:33:36 -07001# Loader Description
2
3## Overview
Jon Ashburn43c8e0c2015-07-16 10:54:55 -06004The Loader implements the main VK library (e.g. "vulkan.dll" on Windows and
5"libvulkan.so" on Linux). It handles layer management and driver management. The
Ian Elliotteff61a02015-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 Ashburn8c519362015-01-06 10:33:36 -07009
Ian Elliotteff61a02015-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 Ashburn8c519362015-01-06 10:33:36 -070021
Jon Ashburn43c8e0c2015-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 Ashburn8c519362015-01-06 10:33:36 -070025
26## Interface to driver (ICD)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060027- vkCreateInstance exported
Courtney Goeltzenleuchter74c4ce92015-09-14 17:22:16 -060028- vkEnumerateInstanceExtensionProperties exported
Jon Ashburn43c8e0c2015-07-16 10:54:55 -060029- vkGetDeviceProcAddr exported and returns valid function pointers for all the VK API entrypoints
30- vkGetInstanceProcAddr exported and returns valid function pointers for all the VK API entrypoints
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060031- all objects created by ICD can be cast to (VK\_LAYER\_DISPATCH\_TABLE \*\*)
Jon Ashburn8c519362015-01-06 10:33:36 -070032 where the loader will replace the first entry with a pointer to the dispatch table which is
Courtney Goeltzenleuchterba7133b2015-02-10 18:40:14 -070033 owned by the loader. This implies three things for ICD drivers:
Ian Elliotteff61a02015-02-13 11:23:05 -070034 1. The ICD must return a pointer for the opaque object handle
35 2. This pointer points to a regular C structure with the first entry being a pointer.
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060036 Note: for any C++ ICD's that implement VK objects directly as C++ classes.
Ian Elliotteff61a02015-02-13 11:23:05 -070037 The C++ compiler may put a vtable at offset zero, if your class is virtual.
38 In this case use a regular C structure (see below).
39 3. The reservedForLoader.loaderMagic member must be initialized with ICD\_LOADER\_MAGIC, as follows:
40
Jon Ashburn117a0d42015-02-11 12:40:00 -070041```
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060042 #include "vkIcd.h"
Ian Elliotteff61a02015-02-13 11:23:05 -070043
Jon Ashburn117a0d42015-02-11 12:40:00 -070044 struct {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060045 VK_LOADER_DATA reservedForLoader; // Reserve space for pointer to loader's dispatch table
Ian Elliotta12ad3d2015-02-13 16:51:05 -070046 myObjectClass myObj; // Your driver's C++ class
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060047 } vkObj;
Ian Elliotteff61a02015-02-13 11:23:05 -070048
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060049 vkObj alloc_icd_obj()
Ian Elliotteff61a02015-02-13 11:23:05 -070050 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060051 vkObj *newObj = alloc_obj();
Ian Elliotteff61a02015-02-13 11:23:05 -070052 ...
53 // Initialize pointer to loader's dispatch table with ICD_LOADER_MAGIC
54 set_loader_magic_value(newObj);
55 ...
56 return newObj;
57 }
Jon Ashburn117a0d42015-02-11 12:40:00 -070058```
Ian Elliotteff61a02015-02-13 11:23:05 -070059
60Additional Notes:
61
62- The ICD may or may not implement a dispatch table.
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060063- 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 Goeltzenleuchterc507e3d2015-01-07 09:24:45 -070064
Jon Ashburn43c8e0c2015-07-16 10:54:55 -060065## Layer library discovery
66See file LinuxICDs.txt and WindowsICDs.txt for description of how the loader
67finds layer libraries.
68
69## Interface to layer libraries
70TBD
71