Layer libraries can be written to intercept or hook XGL entrypoints for various debug and validation purposes. One or more XGL entrypoints can be defined in your Layer library. Undefined entrypoints in the Layer library will be passed to the next Layer which may be the driver. Multiple layer libraries can be chained (actually a hierarchy) together. xglEnumerateLayer can be called to list the available layer libraries. xglGetProcAddr is used internally by the Layers and ICD Loader to initialize dispatch tables. Layers are activated at xglCreateDevice time. xglCreateDevice createInfo struct is extended to allow a list of layers to be activated. Layer libraries can alternatively be LD_PRELOADed depending upon how they are implemented.
##Layer library example code
Note that some layers are code-generated and will therefore exist in the directory (build_dir)/layers
-include/xglLayer.h - header file for layer code.
layer/Basic.cpp (name=Basic) simple example wrapping a few entrypoints. Shows layer features:
layer/Multi.cpp (name=multi1:multi2) simple example showing multiple layers per library
(build dir)/layer/generic_layer.c (name=Generic) - auto generated example wrapping all XGL entrypoints. Single global dispatch table. Can be LD_PRELOADed.
(build dir)/layer/api_dump.c - print out API calls along with parameter values
(build dir)/layer/api_dump_file.c - Write API calls along with parameter values to xgl_apidump.txt file.
(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".
(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)".
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.
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.
/layer/param_checker.c (name=ParamChecker) - Check the input parameters to API calls for validity. Currently this only checks ENUM params directly passed to API calls and ENUMs embedded in struct params. If a Dbg callback function is registered, this layer will use callback function(s) for reporting, otherwise uses stdout.
Build XGL loader and i965 icd driver using normal steps (cmake and make)
Place libXGLLayer.so in the same directory as your XGL test or app:
cp build/layer/libXGLLayerBasic.so build/layer/libXGLLayerGeneric.so build/tests
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.
Specify which Layers to activate by using xglCreateDevice XGL_LAYER_CREATE_INFO struct or environment variable LIBXGL_LAYER_NAMES
export LIBXGL_LAYER_NAMES=Basic:Generic; cd build/tests; ./xglinfo