blob: 2dabf4a72d5253b9aa76116b426896157876fb1d [file] [log] [blame] [view]
Jens Owen8b5ed542014-12-18 14:36:31 -07001# Layer Description and Status
Jon Ashburn183dfd02014-10-22 18:13:16 -06002
Jens Owen8b5ed542014-12-18 14:36:31 -07003## Overview
Jon Ashburn9d290e42014-11-26 13:27:04 -07004
Jon Ashburneaaaced2015-07-23 10:59:21 -06005Layer libraries can be written to intercept or hook VK entry points for various
6debug and validation purposes. One or more VK entry points can be defined in your Layer
Jon Ashburn183dfd02014-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.
Courtney Goeltzenleuchter74c4ce92015-09-14 17:22:16 -06009vkEnumerateInstanceLayerProperties and vkEnumerateDeviceLayerProperties can be called to list the
Jon Ashburneaaaced2015-07-23 10:59:21 -060010available layers and their properties. Layers can intercept Vulkan instance level entry points
11in which case they are called an Instance Layer. Layers can intercept device entry points
12in which case they are called a Device Layer. Instance level entry points are those with VkInstance
13or VkPhysicalDevice as first parameter. Device level entry points are those with VkDevice, VkCmdBuffer,
14or VkQueue as the first parameter. Layers that want to intercept both instance and device
15level entrypoints are called Global Layers. vkXXXXGetProcAddr is used internally by the Layers and
16Loader to initialize dispatch tables. Device Layers are activated at vkCreateDevice time. Instance
17Layers are activated at vkCreateInstance. Layers can also be activated via environment variables
18(VK_INSTANCE_LAYERS or VK_DEVICE_LAYERS).
Jon Ashburn183dfd02014-10-22 18:13:16 -060019
Jens Owen8b5ed542014-12-18 14:36:31 -070020##Layer library example code
Jon Ashburn9d290e42014-11-26 13:27:04 -070021
Jon Ashburnde3630c2014-12-18 17:26:52 -070022Note that some layers are code-generated and will therefore exist in the directory (build_dir)/layers
23
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060024-include/vkLayer.h - header file for layer code.
Jens Owen8b5ed542014-12-18 14:36:31 -070025
26### Templates
Jon Ashburn9d290e42014-11-26 13:27:04 -070027layer/Basic.cpp (name=Basic) simple example wrapping a few entrypoints. Shows layer features:
Jens Owen8b5ed542014-12-18 14:36:31 -070028- Multiple dispatch tables for supporting multiple GPUs.
29- Example layer extension function shown.
Jon Ashburneaaaced2015-07-23 10:59:21 -060030- Layer extension advertised by vkGetXXXExtension().
Jens Owen8b5ed542014-12-18 14:36:31 -070031
32layer/Multi.cpp (name=multi1:multi2) simple example showing multiple layers per library
33
Jon Ashburneaaaced2015-07-23 10:59:21 -060034(build dir)/layer/generic_layer.c (name=Generic) - auto generated example wrapping all VK entrypoints.
Jens Owen8b5ed542014-12-18 14:36:31 -070035
36### Print API Calls and Parameter Values
Jon Ashburneaaaced2015-07-23 10:59:21 -060037(build dir)/layer/api_dump.cpp (name=APIDump) - print out API calls along with parameter values
Jens Owen8b5ed542014-12-18 14:36:31 -070038
39### Print Object Stats
Mark Lobodzinski4e5016f2015-05-05 15:01:37 -050040(build dir>/layer/object_track.c (name=ObjectTracker) - Print object CREATE/USE/DESTROY stats. Individually track objects by category. VkObjectType enum defined in vulkan.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 about the total number of objects or of live objects of given type. To get information on all objects, use "VK\_UINT64 objTrackGetObjectsCount()" and the secondary call to return an array of those objects "VK\_RESULT objTrackGetObjects(VK\_UINT64 objCount, OBJTRACK\_NODE\* pObjNodeArray)". For objects of a specific type, use "VK\_UINT64 objTrackGetObjectsOfTypeCount(VkObjectType type)" and the secondary call to return an array of those objects "VK\_RESULT objTrackGetObjectsOfType(VK\_OBJECT\_TYPE type, VK\_UINT64 objCount, OBJTRACK\_NODE\* pObjNodeArray)".
Jens Owen8b5ed542014-12-18 14:36:31 -070041
42### Report Draw State
Tobin Ehlisa75af3d2015-04-06 09:24:42 -060043layer/draw\_state.c (name=DrawState) - DrawState reports the Descriptor Set, Pipeline State, and dynamic state at each Draw call. DrawState layer performs a number of validation checks on this state. Of primary interest is making sure that the resources bound to Descriptor Sets correctly align with the layout specified for the Set. If a Dbg callback function is registered, this layer will use callback function(s) for reporting, otherwise uses stdout.
Jens Owen8b5ed542014-12-18 14:36:31 -070044
45### Track GPU Memory
Tobin Ehlisa75af3d2015-04-06 09:24:42 -060046layer/mem\_tracker.c (name=MemTracker) - MemTracker functions mostly as a validation layer, attempting to ensure that memory objects are managed correctly by the application. These memory objects are bound to pipelines, objects, and command buffers, and then submitted to the GPU for work. As an example, the layer validates that the correct memory objects have been bound, and that they are specified correctly when the command buffers are submitted. Also, that only existing memory objects are referenced, and that any destroyed memory objects are not referenced. Another type of validation done is that before any memory objects are reused or destroyed, the layer ensures that the application has confirmed that they are no longer in use, and that they have been properly unbound before destruction. 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 -060047
Tobin Ehlis27c2d822014-12-18 10:32:57 -070048### Check parameters
49<build dir>/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.
50
Mike Stroyanb326d2c2015-04-02 11:59:05 -060051### Check threading
52<build dir>/layer/threading.c (name=Threading) - Check multithreading of API calls for validity. Currently this checks that only one thread at a time uses an object in free-threaded API calls. If a Dbg callback function is registered, this layer will use callback function(s) for reporting, otherwise uses stdout.
53
Jon Ashburn9d290e42014-11-26 13:27:04 -070054## Using Layers
55
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600561. Build VK loader and i965 icd driver using normal steps (cmake and make)
572. Place libVKLayer<name>.so in the same directory as your VK test or app:
Jens Owen8b5ed542014-12-18 14:36:31 -070058
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060059 cp build/layer/libVKLayerBasic.so build/layer/libVKLayerGeneric.so build/tests
Jon Ashburnde3630c2014-12-18 17:26:52 -070060
Jon Ashburneaaaced2015-07-23 10:59:21 -060061 This is required for the Loader to be able to scan and enumerate your library.
62 Alternatively, use the VK\_LAYER\_DIRS (VK\_LAYER\_FOLDERS Windows) environment variable to specify where the layer libraries reside.
Jens Owen8b5ed542014-12-18 14:36:31 -070063
643. Specify which Layers to activate by using
Jon Ashburneaaaced2015-07-23 10:59:21 -060065vkCreateDevice and/or vkCreateInstance or environment variables.
Jens Owen8b5ed542014-12-18 14:36:31 -070066
Jon Ashburneaaaced2015-07-23 10:59:21 -060067 export VK\_INSTANCE\_LAYERS=Basic:Generic
68 export VK\_DEVICE\_LAYERS=Basic:Generic
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060069 cd build/tests; ./vkinfo
Jon Ashburn183dfd02014-10-22 18:13:16 -060070
Jon Ashburn9d290e42014-11-26 13:27:04 -070071## Tips for writing new layers
Jon Ashburn183dfd02014-10-22 18:13:16 -060072
Jon Ashburneaaaced2015-07-23 10:59:21 -0600731. Must implement vkGetInstanceProcAddr() (aka GIPA) and vkGetDeviceProcAddr() (aka GDPA);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600742. Must have a local dispatch table to call next layer (see vkLayer.h);
Jon Ashburneaaaced2015-07-23 10:59:21 -0600753. Must have a layer manifest file for each Layer library for Loader to find layer properties (see loader/README.md)
764. next layers GXPA can be found in the wrapped instance or device object;
775. Loader calls a layer's GXPA first so initialization should occur here;
786. all entrypoints can be wrapped but only will be called after layer is activated
79 via the first vkCreatDevice or vkCreateInstance;
807. entrypoint names can be any name as specified by the layers vkGetXXXXXProcAddr
81 implementation; exceptions are vkGetXXXXProcAddr,
Jon Ashburn9d290e42014-11-26 13:27:04 -070082 which must have the correct name since the Loader calls these entrypoints;
Jon Ashburneaaaced2015-07-23 10:59:21 -0600838. entrypoint names must be exported to the OSes dynamic loader with VK\_LAYER\_EXPORT;
849. Layer naming convention is camel case same name as in library: libVKLayer<name>.so
8510. For multiple layers in one library the manifest file can specify each layer.
Jon Ashburn9d290e42014-11-26 13:27:04 -070086
87## Status
88
Jon Ashburn183dfd02014-10-22 18:13:16 -060089
Jon Ashburn9d290e42014-11-26 13:27:04 -070090### Current known issues
91
Jon Ashburneaaaced2015-07-23 10:59:21 -060092- Layers with multiple layers per library the manifest file parsing in Loader doesn't yet handle this;
93- multi.cpp Layer needs rewrite to allow manifest file to specify multiple layers
94- multi1 and multi2 layers from multi.cpp: only multi1 layer working
95
Jon Ashburn183dfd02014-10-22 18:13:16 -060096