Jon Ashburn | 8c51936 | 2015-01-06 10:33:36 -0700 | [diff] [blame] | 1 | # Loader Description |
| 2 | |
| 3 | ## Overview |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 4 | The Loader implements the main VK library (e.g. "VK.dll" on Windows and |
| 5 | "libVK.so" on Linux). It handles layer management and driver management. The |
Ian Elliott | eff61a0 | 2015-02-13 11:23:05 -0700 | [diff] [blame] | 6 | loader fully supports multi-gpu operation. As part of this, it dispatches API |
| 7 | calls to the correct driver, and to the correct layers, based on the GPU object |
| 8 | selected by the application. |
Jon Ashburn | 8c51936 | 2015-01-06 10:33:36 -0700 | [diff] [blame] | 9 | |
Ian Elliott | eff61a0 | 2015-02-13 11:23:05 -0700 | [diff] [blame] | 10 | The loader's driver management includes finding driver libraries and loading |
| 11 | them. When a driver is initialized, the loader sets up its dispatch tables, |
| 12 | using a very light-weight "trampoline" mechanism. To do so, it reserves space |
| 13 | for a pointer in API objects (see below for more information about this). |
| 14 | |
| 15 | The loader's layer management includes finding layer libraries and activating |
| 16 | them as requested. The loader correctly sets up each activated layer, and its |
| 17 | own dispatch tables in order to support all activated layers. Each active |
| 18 | layer can intercept a subset of the full API entrypoints. A layer which |
| 19 | doesn't intercept a given entrypoint will be skipped for that entrypoint. The |
| 20 | loader supports layers that operate on multiple GPUs. |
Jon Ashburn | 8c51936 | 2015-01-06 10:33:36 -0700 | [diff] [blame] | 21 | |
| 22 | ## Environment Variables |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 23 | **LIBVK\_DRIVERS\_PATH** directory for loader to search for ICD driver libraries to open |
Courtney Goeltzenleuchter | c507e3d | 2015-01-07 09:24:45 -0700 | [diff] [blame] | 24 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 25 | **LIBVK\_LAYERS\_PATH** directory for loader to search for layer libraries that may get activated and used at vkCreateDevice() time. |
Courtney Goeltzenleuchter | c507e3d | 2015-01-07 09:24:45 -0700 | [diff] [blame] | 26 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 27 | **LIBVK\_LAYER\_NAMES** colon-separated list of layer names to be activated (e.g., LIBVK\_LAYER\_NAMES=MemTracker:DrawState). |
Ian Elliott | eff61a0 | 2015-02-13 11:23:05 -0700 | [diff] [blame] | 28 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 29 | Note: Both of the LIBVK\_*\_PATH variables may contain more than one directory. Each directory must be separated by one of the following characters, depending on your OS: |
Ian Elliott | eff61a0 | 2015-02-13 11:23:05 -0700 | [diff] [blame] | 30 | |
| 31 | - ";" on Windows |
| 32 | - ":" on Linux |
Jon Ashburn | 8c51936 | 2015-01-06 10:33:36 -0700 | [diff] [blame] | 33 | |
| 34 | ## Interface to driver (ICD) |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 35 | - vkEnumerateGpus exported |
| 36 | - vkCreateInstance exported |
| 37 | - vkDestroyInstance exported |
| 38 | - vkGetProcAddr exported and returns valid function pointers for all the VK API entrypoints |
| 39 | - all objects created by ICD can be cast to (VK\_LAYER\_DISPATCH\_TABLE \*\*) |
Jon Ashburn | 8c51936 | 2015-01-06 10:33:36 -0700 | [diff] [blame] | 40 | where the loader will replace the first entry with a pointer to the dispatch table which is |
Courtney Goeltzenleuchter | ba7133b | 2015-02-10 18:40:14 -0700 | [diff] [blame] | 41 | owned by the loader. This implies three things for ICD drivers: |
Ian Elliott | eff61a0 | 2015-02-13 11:23:05 -0700 | [diff] [blame] | 42 | 1. The ICD must return a pointer for the opaque object handle |
| 43 | 2. This pointer points to a regular C structure with the first entry being a pointer. |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 44 | Note: for any C++ ICD's that implement VK objects directly as C++ classes. |
Ian Elliott | eff61a0 | 2015-02-13 11:23:05 -0700 | [diff] [blame] | 45 | The C++ compiler may put a vtable at offset zero, if your class is virtual. |
| 46 | In this case use a regular C structure (see below). |
| 47 | 3. The reservedForLoader.loaderMagic member must be initialized with ICD\_LOADER\_MAGIC, as follows: |
| 48 | |
Jon Ashburn | 117a0d4 | 2015-02-11 12:40:00 -0700 | [diff] [blame] | 49 | ``` |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 50 | #include "vkIcd.h" |
Ian Elliott | eff61a0 | 2015-02-13 11:23:05 -0700 | [diff] [blame] | 51 | |
Jon Ashburn | 117a0d4 | 2015-02-11 12:40:00 -0700 | [diff] [blame] | 52 | struct { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 53 | VK_LOADER_DATA reservedForLoader; // Reserve space for pointer to loader's dispatch table |
Ian Elliott | a12ad3d | 2015-02-13 16:51:05 -0700 | [diff] [blame] | 54 | myObjectClass myObj; // Your driver's C++ class |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 55 | } vkObj; |
Ian Elliott | eff61a0 | 2015-02-13 11:23:05 -0700 | [diff] [blame] | 56 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 57 | vkObj alloc_icd_obj() |
Ian Elliott | eff61a0 | 2015-02-13 11:23:05 -0700 | [diff] [blame] | 58 | { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 59 | vkObj *newObj = alloc_obj(); |
Ian Elliott | eff61a0 | 2015-02-13 11:23:05 -0700 | [diff] [blame] | 60 | ... |
| 61 | // Initialize pointer to loader's dispatch table with ICD_LOADER_MAGIC |
| 62 | set_loader_magic_value(newObj); |
| 63 | ... |
| 64 | return newObj; |
| 65 | } |
Jon Ashburn | 117a0d4 | 2015-02-11 12:40:00 -0700 | [diff] [blame] | 66 | ``` |
Ian Elliott | eff61a0 | 2015-02-13 11:23:05 -0700 | [diff] [blame] | 67 | |
| 68 | Additional Notes: |
| 69 | |
| 70 | - The ICD may or may not implement a dispatch table. |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 71 | - 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 Goeltzenleuchter | c507e3d | 2015-01-07 09:24:45 -0700 | [diff] [blame] | 72 | |