blob: b88d98bc04eff0a709dc10bb8bfbecb5cb4e71e3 [file] [log] [blame] [view]
Jon Ashburn8c519362015-01-06 10:33:36 -07001# Loader Description
2
3## Overview
Ian Elliotteff61a02015-02-13 11:23:05 -07004The Loader implements the main XGL library (e.g. "XGL.dll" on Windows and
5"libXGL.so" on Linux). It handles layer management and driver management. The
6loader 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
22## Environment Variables
Ian Elliotteff61a02015-02-13 11:23:05 -070023**LIBXGL\_DRIVERS\_PATH** directory for loader to search for ICD driver libraries to open
Courtney Goeltzenleuchterc507e3d2015-01-07 09:24:45 -070024
Ian Elliotteff61a02015-02-13 11:23:05 -070025**LIBXGL\_LAYERS\_PATH** directory for loader to search for layer libraries that may get activated and used at xglCreateDevice() time.
Courtney Goeltzenleuchterc507e3d2015-01-07 09:24:45 -070026
Ian Elliotteff61a02015-02-13 11:23:05 -070027**LIBXGL\_LAYER\_NAMES** colon-separated list of layer names to be activated (e.g., LIBXGL\_LAYER\_NAMES=MemTracker:DrawState).
28
29Note: Both of the LIBXGL\_*\_PATH variables may contain more than one directory. Each directory must be separated by one of the following characters, depending on your OS:
30
31- ";" on Windows
32- ":" on Linux
Jon Ashburn8c519362015-01-06 10:33:36 -070033
34## Interface to driver (ICD)
Jon Ashburn117a0d42015-02-11 12:40:00 -070035- xglEnumerateGpus exported
36- xglCreateInstance exported
37- xglDestroyInstance exported
Jon Ashburn8c519362015-01-06 10:33:36 -070038- xglGetProcAddr exported and returns valid function pointers for all the XGL API entrypoints
Courtney Goeltzenleuchterba7133b2015-02-10 18:40:14 -070039- all objects created by ICD can be cast to (XGL\_LAYER\_DISPATCH\_TABLE \*\*)
Jon Ashburn8c519362015-01-06 10:33:36 -070040 where the loader will replace the first entry with a pointer to the dispatch table which is
Courtney Goeltzenleuchterba7133b2015-02-10 18:40:14 -070041 owned by the loader. This implies three things for ICD drivers:
Ian Elliotteff61a02015-02-13 11:23:05 -070042 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.
Jon Ashburn117a0d42015-02-11 12:40:00 -070044 Note: for any C++ ICD's that implement XGL objects directly as C++ classes.
Ian Elliotteff61a02015-02-13 11:23:05 -070045 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 Ashburn117a0d42015-02-11 12:40:00 -070049```
Courtney Goeltzenleuchterba7133b2015-02-10 18:40:14 -070050 #include "xglIcd.h"
Ian Elliotteff61a02015-02-13 11:23:05 -070051
Jon Ashburn117a0d42015-02-11 12:40:00 -070052 struct {
Ian Elliotteff61a02015-02-13 11:23:05 -070053 XGL_LOADER_DATA *reservedForLoader; // Reserve space for pointer to loader's dispatch table
54 myObjectClass myObj; // Your driver's C++ class
Jon Ashburn117a0d42015-02-11 12:40:00 -070055 } xglObj;
Ian Elliotteff61a02015-02-13 11:23:05 -070056
57 xglObj alloc_icd_obj()
58 {
59 xglObj *newObj = alloc_obj();
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 Ashburn117a0d42015-02-11 12:40:00 -070066```
Ian Elliotteff61a02015-02-13 11:23:05 -070067
68Additional Notes:
69
70- The ICD may or may not implement a dispatch table.
71- ICD entrypoints can be named anything including the offcial xgl name such as xglCreateDevice(). 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 -070072