blob: cbd40b9cbe86e9a8799db9e2f640000420abe58e [file] [log] [blame] [view]
Jon Ashburn9d290e42014-11-26 13:27:04 -07001#Layer Description and Status
Tobin Ehlis3657bce2014-11-27 07:01:51 -07002*27 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
Tobin Ehlis3657bce2014-11-27 07:01:51 -070018Note that some layers are code-generated and will therefore exist in the <build dir>
Jon Ashburna0b85eb2014-10-23 10:59:23 -060019include/xglLayer.h - header file for layer code
Jon Ashburn9d290e42014-11-26 13:27:04 -070020layer/Basic.cpp (name=Basic) simple example wrapping a few entrypoints. Shows layer features:
21 - Multiple dispatch tables for supporting multiple GPUs.
22 - Example layer extension function shown.
23 - Layer extension advertised by xglGetExtension().
24 - xglEnumerateLayers() supports loader layer name queries and call interception
25 - Can be LD_PRELOADed individually
Jon Ashburn8d8dad02014-12-01 14:22:40 -070026layer/Multi.cpp (name=multi1:multi2) simple example showing multiple layers per library
Jon Ashburn9d290e42014-11-26 13:27:04 -070027<build dir>/layer/generic_layer.c (name=Generic) - auto generated example wrapping all XGL entrypoints.
Jon Ashburna0b85eb2014-10-23 10:59:23 -060028 Single global dispatch table. Can be LD_PRELOADed.
Tobin Ehlis475bebe2014-10-23 08:44:44 -060029<build dir>/layer/api_dump.c - print out API calls along with parameter values
Tobin Ehlis3657bce2014-11-27 07:01:51 -070030<build dir>/layer/api_dump_file.c - Write API calls along with parameter values to xgl_apidump.txt file.
31<build dir>/layer/api_dump_no_addr.c - print out API calls along with parameter values but replace any variable addresses with the static string "addr".
32<build dir>/layer/object_track.c - Print object CREATE/USE/DESTROY stats. Individually track objects by category. XGL_OBJECT_TYPE enum defined in object_track.h. If a Dbg callback function is registered, this layer will use callback function(s) for reporting, otherwise uses stdout. Provides custom interface to query number of live objects of given type "XGL_UINT64 objTrackGetObjectCount(XGL_OBJECT_TYPE type)" and a secondary call to return an array of those objects "XGL_RESULT objTrackGetObjects(XGL_OBJECT_TYPE type, XGL_UINT64 objCount, OBJTRACK_NODE* pObjNodeArray)".
33layer/draw_state.c - Report the Descriptor Set, Pipeline State, and dynamic state at each Draw call. If a Dbg callback function is registered, this layer will use callback function(s) for reporting, otherwise uses stdout.
34layer/mem_tracker.c - Track GPU Memory and any binding it has to objects and/or Cmd Buffers. Report issues with freeing memory, memory dependencies on Cmd Buffers, and any memory leaks at DestroyDevice time. If a Dbg callback function is registered, this layer will use callback function(s) for reporting, otherwise uses stdout.
Jon Ashburn183dfd02014-10-22 18:13:16 -060035
Jon Ashburn9d290e42014-11-26 13:27:04 -070036## Using Layers
37
Jon Ashburna0b85eb2014-10-23 10:59:23 -0600381) Build XGL loader and i965 icd driver using normal steps (cmake and make)
Jon Ashburna0b85eb2014-10-23 10:59:23 -0600392) Place libXGLLayer<name>.so in the same directory as your XGL test or app:
Jon Ashburn9d290e42014-11-26 13:27:04 -070040 cp build/layer/libXGLLayerBasic.so build/layer/libXGLLayerGeneric.so build/tests
Jon Ashburna0b85eb2014-10-23 10:59:23 -060041This is required for the Icd loader to be able to scan and enumerate your library.
Jon Ashburn9d290e42014-11-26 13:27:04 -0700423) Specify which Layers to activate by using xglCreateDevice XGL_LAYER_CREATE_INFO struct or environment variable LIBXGL_LAYER_NAMES
43 export LIBXGL_LAYER_NAMES=Basic:Generic;
Jon Ashburn183dfd02014-10-22 18:13:16 -060044 cd build/tests; ./xglinfo
45
Jon Ashburn9d290e42014-11-26 13:27:04 -070046## Tips for writing new layers
Jon Ashburn183dfd02014-10-22 18:13:16 -060047
Jon Ashburn9d290e42014-11-26 13:27:04 -0700481) Must implement xglGetProcAddr() (aka GPA);
492) Must have a local dispatch table to call next layer (see xglLayer.h);
503) Should implement xglEnumerateLayers() returning layer name when gpu == NULL;
51 otherwise layer name is extracted from library filename by the Loader;
524) gpu objects must be unwrapped (gpu->nextObject) when passed to next layer;
535) next layers GPA can be found in the wrapped gpu object;
546) Loader calls a layer's GPA first so initialization should occur here;
557) all entrypoints can be wrapped but only will be called after layer is activated
56 via the first xglCreatDevice;
578) entrypoint names can be any name as specified by the layers xglGetProcAddr
58 implementation; exceptions are xglGetProcAddr and xglEnumerateLayers,
59 which must have the correct name since the Loader calls these entrypoints;
609) entrypoint names must be exported to the dynamic loader with XGL_LAYER_EXPORT;
6110) For LD_PRELOAD support: a)entrypoint names should be offical xgl names and
62 b) initialization should occur on any call with a gpu object (Loader type
63 initialization must be done if implementing xglInitAndEnumerateGpus).
6411) Implement xglGetExtension() if you want to advertise a layer extension
65 (only available after the layer is activated);
6612) Layer naming convention is camel case same name as in library: libXGLLayer<name>.so
Jon Ashburn8d8dad02014-12-01 14:22:40 -07006713) For multiple layers in one library should implement a separate GetProcAddr for each
68 layer and export them to dynamic loader; function name is <layerName>GetProcAddr().
69 Main xglGetProcAddr() should also be implemented.
Jon Ashburn9d290e42014-11-26 13:27:04 -070070
71## Status
72
73### Current Features
74
75-scanning of available Layers during xglInitAndEnumerateGpus;
76-layer names retrieved via xglEnumerateLayers();
77-xglEnumerateLayers and xglGetProcAddr supported APIs in xgl.h, ICD loader and i965 driver;
78-multiple layers in a hierarchy supported;
79-layer enumeration supported per GPU;
Jon Ashburna0b85eb2014-10-23 10:59:23 -060080-layers activated per gpu and per icd driver: separate dispatch table and layer library
Jon Ashburn9d290e42014-11-26 13:27:04 -070081 list in loader for each gpu or icd driver;
Jon Ashburn183dfd02014-10-22 18:13:16 -060082-activation via xglCreateDevice extension struct in CreateInfo or via env var
Jon Ashburn9d290e42014-11-26 13:27:04 -070083 (LIBXGL_LAYER_NAMES);
84-layer libraries can be LD_PRELOADed if implemented correctly;
Jon Ashburn183dfd02014-10-22 18:13:16 -060085
Jon Ashburn9d290e42014-11-26 13:27:04 -070086### Current known issues
87
88-layer libraries (except Basic) don't support multiple dispatch tables for multi-gpus;
Tobin Ehlis475bebe2014-10-23 08:44:44 -060089-layer libraries not yet include loader init functionality for full LD_PRELOAD of
Jon Ashburn9d290e42014-11-26 13:27:04 -070090 entire API including xglInitAndEnumerateGpus;
91-Since Layers aren't activated until xglCreateDevice, any calls to xglGetExtension()
92 will not report layer extensions unless implemented in the layer;
93-layer extensions do NOT need to be enabled in xglCreateDevice to be available;
Jon Ashburn183dfd02014-10-22 18:13:16 -060094-no support for apps registering layers, must be discovered via initial scan
Jon Ashburn183dfd02014-10-22 18:13:16 -060095