blob: 49b992b3d74c927afddaa199d691947ee83dfdb6 [file] [log] [blame] [view]
Jon Ashburn9d290e42014-11-26 13:27:04 -07001#Layer Description and Status
2*26 Nov 2014*
Jon Ashburn183dfd02014-10-22 18:13:16 -06003
Jon Ashburn9d290e42014-11-26 13:27:04 -07004##Overview
5
Jon Ashburn183dfd02014-10-22 18:13:16 -06006Layer libraries can be written to intercept or hook XGL entrypoints for various
Courtney Goeltzenleuchter6be96bb2014-11-02 18:50:52 -07007debug and validation purposes. One or more XGL entrypoints can be defined in your Layer
Jon Ashburn183dfd02014-10-22 18:13:16 -06008library. Undefined entrypoints in the Layer library will be passed to the next Layer which
9may be the driver. Multiple layer libraries can be chained (actually a hierarchy) together.
Tobin Ehlis475bebe2014-10-23 08:44:44 -060010xglEnumerateLayer can be called to list the available layer libraries. xglGetProcAddr is
Jon Ashburn183dfd02014-10-22 18:13:16 -060011used internally by the Layers and ICD Loader to initialize dispatch tables. Layers are
12activated at xglCreateDevice time. xglCreateDevice createInfo struct is extended to allow
Jon Ashburn9d290e42014-11-26 13:27:04 -070013a list of layers to be activated. Layer libraries can alternatively be LD_PRELOADed depending
14upon how they are implemented.
Jon Ashburn183dfd02014-10-22 18:13:16 -060015
Jon Ashburn9d290e42014-11-26 13:27:04 -070016## Layer library example code
17
Jon Ashburna0b85eb2014-10-23 10:59:23 -060018include/xglLayer.h - header file for layer code
Jon Ashburn9d290e42014-11-26 13:27:04 -070019layer/Basic.cpp (name=Basic) simple example wrapping a few entrypoints. Shows layer features:
20 - Multiple dispatch tables for supporting multiple GPUs.
21 - Example layer extension function shown.
22 - Layer extension advertised by xglGetExtension().
23 - xglEnumerateLayers() supports loader layer name queries and call interception
24 - Can be LD_PRELOADed individually
25<build dir>/layer/generic_layer.c (name=Generic) - auto generated example wrapping all XGL entrypoints.
Jon Ashburna0b85eb2014-10-23 10:59:23 -060026 Single global dispatch table. Can be LD_PRELOADed.
Tobin Ehlis475bebe2014-10-23 08:44:44 -060027<build dir>/layer/api_dump.c - print out API calls along with parameter values
28<build dir>/layer/object_track.c - Print object CREATE/USE/DESTROY stats
Jon Ashburn183dfd02014-10-22 18:13:16 -060029
Jon Ashburn9d290e42014-11-26 13:27:04 -070030## Using Layers
31
Jon Ashburna0b85eb2014-10-23 10:59:23 -0600321) Build XGL loader and i965 icd driver using normal steps (cmake and make)
Jon Ashburna0b85eb2014-10-23 10:59:23 -0600332) Place libXGLLayer<name>.so in the same directory as your XGL test or app:
Jon Ashburn9d290e42014-11-26 13:27:04 -070034 cp build/layer/libXGLLayerBasic.so build/layer/libXGLLayerGeneric.so build/tests
Jon Ashburna0b85eb2014-10-23 10:59:23 -060035This is required for the Icd loader to be able to scan and enumerate your library.
Jon Ashburn9d290e42014-11-26 13:27:04 -0700363) Specify which Layers to activate by using xglCreateDevice XGL_LAYER_CREATE_INFO struct or environment variable LIBXGL_LAYER_NAMES
37 export LIBXGL_LAYER_NAMES=Basic:Generic;
Jon Ashburn183dfd02014-10-22 18:13:16 -060038 cd build/tests; ./xglinfo
39
Jon Ashburn9d290e42014-11-26 13:27:04 -070040## Tips for writing new layers
Jon Ashburn183dfd02014-10-22 18:13:16 -060041
Jon Ashburn9d290e42014-11-26 13:27:04 -0700421) Must implement xglGetProcAddr() (aka GPA);
432) Must have a local dispatch table to call next layer (see xglLayer.h);
443) Should implement xglEnumerateLayers() returning layer name when gpu == NULL;
45 otherwise layer name is extracted from library filename by the Loader;
464) gpu objects must be unwrapped (gpu->nextObject) when passed to next layer;
475) next layers GPA can be found in the wrapped gpu object;
486) Loader calls a layer's GPA first so initialization should occur here;
497) all entrypoints can be wrapped but only will be called after layer is activated
50 via the first xglCreatDevice;
518) entrypoint names can be any name as specified by the layers xglGetProcAddr
52 implementation; exceptions are xglGetProcAddr and xglEnumerateLayers,
53 which must have the correct name since the Loader calls these entrypoints;
549) entrypoint names must be exported to the dynamic loader with XGL_LAYER_EXPORT;
5510) For LD_PRELOAD support: a)entrypoint names should be offical xgl names and
56 b) initialization should occur on any call with a gpu object (Loader type
57 initialization must be done if implementing xglInitAndEnumerateGpus).
5811) Implement xglGetExtension() if you want to advertise a layer extension
59 (only available after the layer is activated);
6012) Layer naming convention is camel case same name as in library: libXGLLayer<name>.so
61
62## Status
63
64### Current Features
65
66-scanning of available Layers during xglInitAndEnumerateGpus;
67-layer names retrieved via xglEnumerateLayers();
68-xglEnumerateLayers and xglGetProcAddr supported APIs in xgl.h, ICD loader and i965 driver;
69-multiple layers in a hierarchy supported;
70-layer enumeration supported per GPU;
Jon Ashburna0b85eb2014-10-23 10:59:23 -060071-layers activated per gpu and per icd driver: separate dispatch table and layer library
Jon Ashburn9d290e42014-11-26 13:27:04 -070072 list in loader for each gpu or icd driver;
Jon Ashburn183dfd02014-10-22 18:13:16 -060073-activation via xglCreateDevice extension struct in CreateInfo or via env var
Jon Ashburn9d290e42014-11-26 13:27:04 -070074 (LIBXGL_LAYER_NAMES);
75-layer libraries can be LD_PRELOADed if implemented correctly;
Jon Ashburn183dfd02014-10-22 18:13:16 -060076
Jon Ashburn9d290e42014-11-26 13:27:04 -070077### Current known issues
78
79-layer libraries (except Basic) don't support multiple dispatch tables for multi-gpus;
Tobin Ehlis475bebe2014-10-23 08:44:44 -060080-layer libraries not yet include loader init functionality for full LD_PRELOAD of
Jon Ashburn9d290e42014-11-26 13:27:04 -070081 entire API including xglInitAndEnumerateGpus;
82-Since Layers aren't activated until xglCreateDevice, any calls to xglGetExtension()
83 will not report layer extensions unless implemented in the layer;
84-layer extensions do NOT need to be enabled in xglCreateDevice to be available;
Jon Ashburn183dfd02014-10-22 18:13:16 -060085-no support for apps registering layers, must be discovered via initial scan
Jon Ashburn183dfd02014-10-22 18:13:16 -060086