blob: 17309396e3c83d847375ba4755b18f7cd40d7282 [file] [log] [blame] [view]
Jens Owen763b76e2014-12-18 14:36:31 -07001# Layer Description and Status
Jon Ashburn6b4d70c2014-10-22 18:13:16 -06002
Jens Owen763b76e2014-12-18 14:36:31 -07003## Overview
Jon Ashburna5817d52014-11-26 13:27:04 -07004
Jon Ashburn6b4d70c2014-10-22 18:13:16 -06005Layer libraries can be written to intercept or hook XGL entrypoints for various
Courtney Goeltzenleuchter4fe05bf2014-11-02 18:50:52 -07006debug and validation purposes. One or more XGL entrypoints can be defined in your Layer
Jon Ashburn6b4d70c2014-10-22 18:13:16 -06007library. Undefined entrypoints in the Layer library will be passed to the next Layer which
8may be the driver. Multiple layer libraries can be chained (actually a hierarchy) together.
Tobin Ehlis5d0a5b22014-10-23 08:44:44 -06009xglEnumerateLayer can be called to list the available layer libraries. xglGetProcAddr is
Jon Ashburn6b4d70c2014-10-22 18:13:16 -060010used internally by the Layers and ICD Loader to initialize dispatch tables. Layers are
11activated at xglCreateDevice time. xglCreateDevice createInfo struct is extended to allow
Jon Ashburn649d8712014-12-18 17:26:52 -070012a list of layers to be activated. Layer libraries can alternatively be LD\_PRELOADed depending
Jon Ashburna5817d52014-11-26 13:27:04 -070013upon how they are implemented.
Jon Ashburn6b4d70c2014-10-22 18:13:16 -060014
Jens Owen763b76e2014-12-18 14:36:31 -070015##Layer library example code
Jon Ashburna5817d52014-11-26 13:27:04 -070016
Jon Ashburn649d8712014-12-18 17:26:52 -070017Note that some layers are code-generated and will therefore exist in the directory (build_dir)/layers
18
19-include/xglLayer.h - header file for layer code.
Jens Owen763b76e2014-12-18 14:36:31 -070020
21### Templates
Jon Ashburna5817d52014-11-26 13:27:04 -070022layer/Basic.cpp (name=Basic) simple example wrapping a few entrypoints. Shows layer features:
Jens Owen763b76e2014-12-18 14:36:31 -070023- Multiple dispatch tables for supporting multiple GPUs.
24- Example layer extension function shown.
25- Layer extension advertised by xglGetExtension().
26- xglEnumerateLayers() supports loader layer name queries and call interception
Jon Ashburn649d8712014-12-18 17:26:52 -070027- Can be LD\_PRELOADed individually
Jens Owen763b76e2014-12-18 14:36:31 -070028
29layer/Multi.cpp (name=multi1:multi2) simple example showing multiple layers per library
30
Jon Ashburn649d8712014-12-18 17:26:52 -070031(build dir)/layer/generic_layer.c (name=Generic) - auto generated example wrapping all XGL entrypoints. Single global dispatch table. Can be LD\_PRELOADed.
Jens Owen763b76e2014-12-18 14:36:31 -070032
33### Print API Calls and Parameter Values
Jon Ashburn649d8712014-12-18 17:26:52 -070034(build dir)/layer/api_dump.c - print out API calls along with parameter values
Jens Owen763b76e2014-12-18 14:36:31 -070035
Jon Ashburn649d8712014-12-18 17:26:52 -070036(build dir)/layer/api\_dump\_file.c - Write API calls along with parameter values to xgl\_apidump.txt file.
Jens Owen763b76e2014-12-18 14:36:31 -070037
Jon Ashburn649d8712014-12-18 17:26:52 -070038(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".
Jens Owen763b76e2014-12-18 14:36:31 -070039
40### Print Object Stats
Jon Ashburn649d8712014-12-18 17:26:52 -070041(build di\r>/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)".
Jens Owen763b76e2014-12-18 14:36:31 -070042
43### Report Draw State
Jon Ashburn649d8712014-12-18 17:26:52 -070044layer/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.
Jens Owen763b76e2014-12-18 14:36:31 -070045
46### Track GPU Memory
Jon Ashburn649d8712014-12-18 17:26:52 -070047layer/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 Ashburn6b4d70c2014-10-22 18:13:16 -060048
Jon Ashburna5817d52014-11-26 13:27:04 -070049## Using Layers
50
Jens Owen763b76e2014-12-18 14:36:31 -0700511. Build XGL loader and i965 icd driver using normal steps (cmake and make)
522. Place libXGLLayer<name>.so in the same directory as your XGL test or app:
53
54 cp build/layer/libXGLLayerBasic.so build/layer/libXGLLayerGeneric.so build/tests
Jon Ashburn649d8712014-12-18 17:26:52 -070055
56 This is required for the Icd loader to be able to scan and enumerate your library. Alternatively, use the LIBXGL\_LAYERS\_PATH environment variable to specify where the layer libraries reside.
Jens Owen763b76e2014-12-18 14:36:31 -070057
583. Specify which Layers to activate by using
Jon Ashburn649d8712014-12-18 17:26:52 -070059xglCreateDevice XGL\_LAYER\_CREATE\_INFO struct or environment variable LIBXGL\_LAYER\_NAMES
Jens Owen763b76e2014-12-18 14:36:31 -070060
Jon Ashburn649d8712014-12-18 17:26:52 -070061 export LIBXGL\_LAYER\_NAMES=Basic:Generic;
Jens Owen763b76e2014-12-18 14:36:31 -070062 cd build/tests; ./xglinfo
Jon Ashburn6b4d70c2014-10-22 18:13:16 -060063
Jon Ashburna5817d52014-11-26 13:27:04 -070064## Tips for writing new layers
Jon Ashburn6b4d70c2014-10-22 18:13:16 -060065
Jens Owen763b76e2014-12-18 14:36:31 -0700661. Must implement xglGetProcAddr() (aka GPA);
672. Must have a local dispatch table to call next layer (see xglLayer.h);
683. Should implement xglEnumerateLayers() returning layer name when gpu == NULL; otherwise layer name is extracted from library filename by the Loader;
694. gpu objects must be unwrapped (gpu->nextObject) when passed to next layer;
705. next layers GPA can be found in the wrapped gpu object;
716. Loader calls a layer's GPA first so initialization should occur here;
727. all entrypoints can be wrapped but only will be called after layer is activated
Jon Ashburna5817d52014-11-26 13:27:04 -070073 via the first xglCreatDevice;
Jens Owen763b76e2014-12-18 14:36:31 -0700748. entrypoint names can be any name as specified by the layers xglGetProcAddr
Jon Ashburna5817d52014-11-26 13:27:04 -070075 implementation; exceptions are xglGetProcAddr and xglEnumerateLayers,
76 which must have the correct name since the Loader calls these entrypoints;
Jon Ashburn649d8712014-12-18 17:26:52 -0700779. entrypoint names must be exported to the dynamic loader with XGL\_LAYER\_EXPORT;
7810. For LD\_PRELOAD support: a)entrypoint names should be offical xgl names and
Jon Ashburna5817d52014-11-26 13:27:04 -070079 b) initialization should occur on any call with a gpu object (Loader type
80 initialization must be done if implementing xglInitAndEnumerateGpus).
Jens Owen763b76e2014-12-18 14:36:31 -07008111. Implement xglGetExtension() if you want to advertise a layer extension
Jon Ashburna5817d52014-11-26 13:27:04 -070082 (only available after the layer is activated);
Jens Owen763b76e2014-12-18 14:36:31 -07008312. Layer naming convention is camel case same name as in library: libXGLLayer<name>.so
8413. For multiple layers in one library should implement a separate GetProcAddr for each
Jon Ashburn79113cc2014-12-01 14:22:40 -070085 layer and export them to dynamic loader; function name is <layerName>GetProcAddr().
86 Main xglGetProcAddr() should also be implemented.
Jon Ashburna5817d52014-11-26 13:27:04 -070087
88## Status
89
90### Current Features
91
Jens Owen763b76e2014-12-18 14:36:31 -070092- scanning of available Layers during xglInitAndEnumerateGpus;
93- layer names retrieved via xglEnumerateLayers();
94- xglEnumerateLayers and xglGetProcAddr supported APIs in xgl.h, ICD loader and i965 driver;
95- multiple layers in a hierarchy supported;
96- layer enumeration supported per GPU;
97- layers activated per gpu and per icd driver: separate dispatch table and layer library list in loader for each gpu or icd driver;
Jon Ashburn649d8712014-12-18 17:26:52 -070098- activation via xglCreateDevice extension struct in CreateInfo or via env var (LIBXGL\_LAYER\_NAMES);
99- layer libraries can be LD\_PRELOADed if implemented correctly;
Jon Ashburn6b4d70c2014-10-22 18:13:16 -0600100
Jon Ashburna5817d52014-11-26 13:27:04 -0700101### Current known issues
102
Jens Owen763b76e2014-12-18 14:36:31 -0700103- layer libraries (except Basic) don't support multiple dispatch tables for multi-gpus;
Jon Ashburn649d8712014-12-18 17:26:52 -0700104- layer libraries not yet include loader init functionality for full LD\_PRELOAD of entire API including xglInitAndEnumerateGpus;
Jens Owen763b76e2014-12-18 14:36:31 -0700105- Since Layers aren't activated until xglCreateDevice, any calls to xglGetExtension() will not report layer extensions unless implemented in the layer;
106- layer extensions do NOT need to be enabled in xglCreateDevice to be available;
107- no support for apps registering layers, must be discovered via initial scan
Jon Ashburn6b4d70c2014-10-22 18:13:16 -0600108