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