Jon Ashburn | 9d290e4 | 2014-11-26 13:27:04 -0700 | [diff] [blame] | 1 | #Layer Description and Status |
Tobin Ehlis | 3657bce | 2014-11-27 07:01:51 -0700 | [diff] [blame^] | 2 | *27 Nov 2014* |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 3 | |
Jon Ashburn | 9d290e4 | 2014-11-26 13:27:04 -0700 | [diff] [blame] | 4 | ##Overview |
| 5 | |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 6 | Layer libraries can be written to intercept or hook XGL entrypoints for various |
Courtney Goeltzenleuchter | 6be96bb | 2014-11-02 18:50:52 -0700 | [diff] [blame] | 7 | debug and validation purposes. One or more XGL entrypoints can be defined in your Layer |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 8 | library. Undefined entrypoints in the Layer library will be passed to the next Layer which |
| 9 | may be the driver. Multiple layer libraries can be chained (actually a hierarchy) together. |
Tobin Ehlis | 475bebe | 2014-10-23 08:44:44 -0600 | [diff] [blame] | 10 | xglEnumerateLayer can be called to list the available layer libraries. xglGetProcAddr is |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 11 | used internally by the Layers and ICD Loader to initialize dispatch tables. Layers are |
| 12 | activated at xglCreateDevice time. xglCreateDevice createInfo struct is extended to allow |
Jon Ashburn | 9d290e4 | 2014-11-26 13:27:04 -0700 | [diff] [blame] | 13 | a list of layers to be activated. Layer libraries can alternatively be LD_PRELOADed depending |
| 14 | upon how they are implemented. |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 15 | |
Jon Ashburn | 9d290e4 | 2014-11-26 13:27:04 -0700 | [diff] [blame] | 16 | ## Layer library example code |
| 17 | |
Tobin Ehlis | 3657bce | 2014-11-27 07:01:51 -0700 | [diff] [blame^] | 18 | Note that some layers are code-generated and will therefore exist in the <build dir> |
Jon Ashburn | a0b85eb | 2014-10-23 10:59:23 -0600 | [diff] [blame] | 19 | include/xglLayer.h - header file for layer code |
Jon Ashburn | 9d290e4 | 2014-11-26 13:27:04 -0700 | [diff] [blame] | 20 | layer/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 |
| 26 | <build dir>/layer/generic_layer.c (name=Generic) - auto generated example wrapping all XGL entrypoints. |
Jon Ashburn | a0b85eb | 2014-10-23 10:59:23 -0600 | [diff] [blame] | 27 | Single global dispatch table. Can be LD_PRELOADed. |
Tobin Ehlis | 475bebe | 2014-10-23 08:44:44 -0600 | [diff] [blame] | 28 | <build dir>/layer/api_dump.c - print out API calls along with parameter values |
Tobin Ehlis | 3657bce | 2014-11-27 07:01:51 -0700 | [diff] [blame^] | 29 | <build dir>/layer/api_dump_file.c - Write API calls along with parameter values to xgl_apidump.txt file. |
| 30 | <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". |
| 31 | <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)". |
| 32 | layer/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. |
| 33 | layer/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 Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 34 | |
Jon Ashburn | 9d290e4 | 2014-11-26 13:27:04 -0700 | [diff] [blame] | 35 | ## Using Layers |
| 36 | |
Jon Ashburn | a0b85eb | 2014-10-23 10:59:23 -0600 | [diff] [blame] | 37 | 1) Build XGL loader and i965 icd driver using normal steps (cmake and make) |
Jon Ashburn | a0b85eb | 2014-10-23 10:59:23 -0600 | [diff] [blame] | 38 | 2) Place libXGLLayer<name>.so in the same directory as your XGL test or app: |
Jon Ashburn | 9d290e4 | 2014-11-26 13:27:04 -0700 | [diff] [blame] | 39 | cp build/layer/libXGLLayerBasic.so build/layer/libXGLLayerGeneric.so build/tests |
Jon Ashburn | a0b85eb | 2014-10-23 10:59:23 -0600 | [diff] [blame] | 40 | This is required for the Icd loader to be able to scan and enumerate your library. |
Jon Ashburn | 9d290e4 | 2014-11-26 13:27:04 -0700 | [diff] [blame] | 41 | 3) Specify which Layers to activate by using xglCreateDevice XGL_LAYER_CREATE_INFO struct or environment variable LIBXGL_LAYER_NAMES |
| 42 | export LIBXGL_LAYER_NAMES=Basic:Generic; |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 43 | cd build/tests; ./xglinfo |
| 44 | |
Jon Ashburn | 9d290e4 | 2014-11-26 13:27:04 -0700 | [diff] [blame] | 45 | ## Tips for writing new layers |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 46 | |
Jon Ashburn | 9d290e4 | 2014-11-26 13:27:04 -0700 | [diff] [blame] | 47 | 1) Must implement xglGetProcAddr() (aka GPA); |
| 48 | 2) Must have a local dispatch table to call next layer (see xglLayer.h); |
| 49 | 3) Should implement xglEnumerateLayers() returning layer name when gpu == NULL; |
| 50 | otherwise layer name is extracted from library filename by the Loader; |
| 51 | 4) gpu objects must be unwrapped (gpu->nextObject) when passed to next layer; |
| 52 | 5) next layers GPA can be found in the wrapped gpu object; |
| 53 | 6) Loader calls a layer's GPA first so initialization should occur here; |
| 54 | 7) all entrypoints can be wrapped but only will be called after layer is activated |
| 55 | via the first xglCreatDevice; |
| 56 | 8) entrypoint names can be any name as specified by the layers xglGetProcAddr |
| 57 | implementation; exceptions are xglGetProcAddr and xglEnumerateLayers, |
| 58 | which must have the correct name since the Loader calls these entrypoints; |
| 59 | 9) entrypoint names must be exported to the dynamic loader with XGL_LAYER_EXPORT; |
| 60 | 10) For LD_PRELOAD support: a)entrypoint names should be offical xgl names and |
| 61 | b) initialization should occur on any call with a gpu object (Loader type |
| 62 | initialization must be done if implementing xglInitAndEnumerateGpus). |
| 63 | 11) Implement xglGetExtension() if you want to advertise a layer extension |
| 64 | (only available after the layer is activated); |
| 65 | 12) Layer naming convention is camel case same name as in library: libXGLLayer<name>.so |
| 66 | |
| 67 | ## Status |
| 68 | |
| 69 | ### Current Features |
| 70 | |
| 71 | -scanning of available Layers during xglInitAndEnumerateGpus; |
| 72 | -layer names retrieved via xglEnumerateLayers(); |
| 73 | -xglEnumerateLayers and xglGetProcAddr supported APIs in xgl.h, ICD loader and i965 driver; |
| 74 | -multiple layers in a hierarchy supported; |
| 75 | -layer enumeration supported per GPU; |
Jon Ashburn | a0b85eb | 2014-10-23 10:59:23 -0600 | [diff] [blame] | 76 | -layers activated per gpu and per icd driver: separate dispatch table and layer library |
Jon Ashburn | 9d290e4 | 2014-11-26 13:27:04 -0700 | [diff] [blame] | 77 | list in loader for each gpu or icd driver; |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 78 | -activation via xglCreateDevice extension struct in CreateInfo or via env var |
Jon Ashburn | 9d290e4 | 2014-11-26 13:27:04 -0700 | [diff] [blame] | 79 | (LIBXGL_LAYER_NAMES); |
| 80 | -layer libraries can be LD_PRELOADed if implemented correctly; |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 81 | |
Jon Ashburn | 9d290e4 | 2014-11-26 13:27:04 -0700 | [diff] [blame] | 82 | ### Current known issues |
| 83 | |
| 84 | -layer libraries (except Basic) don't support multiple dispatch tables for multi-gpus; |
Tobin Ehlis | 475bebe | 2014-10-23 08:44:44 -0600 | [diff] [blame] | 85 | -layer libraries not yet include loader init functionality for full LD_PRELOAD of |
Jon Ashburn | 9d290e4 | 2014-11-26 13:27:04 -0700 | [diff] [blame] | 86 | entire API including xglInitAndEnumerateGpus; |
| 87 | -Since Layers aren't activated until xglCreateDevice, any calls to xglGetExtension() |
| 88 | will not report layer extensions unless implemented in the layer; |
| 89 | -layer extensions do NOT need to be enabled in xglCreateDevice to be available; |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 90 | -no support for apps registering layers, must be discovered via initial scan |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 91 | |