Jens Owen | 8b5ed54 | 2014-12-18 14:36:31 -0700 | [diff] [blame] | 1 | # Layer Description and Status |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 2 | |
Jens Owen | 8b5ed54 | 2014-12-18 14:36:31 -0700 | [diff] [blame] | 3 | ## Overview |
Jon Ashburn | 9d290e4 | 2014-11-26 13:27:04 -0700 | [diff] [blame] | 4 | |
Jon Ashburn | eaaaced | 2015-07-23 10:59:21 -0600 | [diff] [blame] | 5 | Layer libraries can be written to intercept or hook VK entry points for various |
| 6 | debug and validation purposes. One or more VK entry points can be defined in your Layer |
Jon Ashburn | 183dfd0 | 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. |
Courtney Goeltzenleuchter | 74c4ce9 | 2015-09-14 17:22:16 -0600 | [diff] [blame] | 9 | vkEnumerateInstanceLayerProperties and vkEnumerateDeviceLayerProperties can be called to list the |
Jon Ashburn | eaaaced | 2015-07-23 10:59:21 -0600 | [diff] [blame] | 10 | available layers and their properties. Layers can intercept Vulkan instance level entry points |
| 11 | in which case they are called an Instance Layer. Layers can intercept device entry points |
| 12 | in which case they are called a Device Layer. Instance level entry points are those with VkInstance |
| 13 | or VkPhysicalDevice as first parameter. Device level entry points are those with VkDevice, VkCmdBuffer, |
| 14 | or VkQueue as the first parameter. Layers that want to intercept both instance and device |
| 15 | level entrypoints are called Global Layers. vkXXXXGetProcAddr is used internally by the Layers and |
| 16 | Loader to initialize dispatch tables. Device Layers are activated at vkCreateDevice time. Instance |
| 17 | Layers are activated at vkCreateInstance. Layers can also be activated via environment variables |
| 18 | (VK_INSTANCE_LAYERS or VK_DEVICE_LAYERS). |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 19 | |
Jens Owen | 8b5ed54 | 2014-12-18 14:36:31 -0700 | [diff] [blame] | 20 | ##Layer library example code |
Jon Ashburn | 9d290e4 | 2014-11-26 13:27:04 -0700 | [diff] [blame] | 21 | |
Jon Ashburn | de3630c | 2014-12-18 17:26:52 -0700 | [diff] [blame] | 22 | Note that some layers are code-generated and will therefore exist in the directory (build_dir)/layers |
| 23 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 24 | -include/vkLayer.h - header file for layer code. |
Jens Owen | 8b5ed54 | 2014-12-18 14:36:31 -0700 | [diff] [blame] | 25 | |
| 26 | ### Templates |
Jon Ashburn | 9d290e4 | 2014-11-26 13:27:04 -0700 | [diff] [blame] | 27 | layer/Basic.cpp (name=Basic) simple example wrapping a few entrypoints. Shows layer features: |
Jens Owen | 8b5ed54 | 2014-12-18 14:36:31 -0700 | [diff] [blame] | 28 | - Multiple dispatch tables for supporting multiple GPUs. |
| 29 | - Example layer extension function shown. |
Jon Ashburn | eaaaced | 2015-07-23 10:59:21 -0600 | [diff] [blame] | 30 | - Layer extension advertised by vkGetXXXExtension(). |
Jens Owen | 8b5ed54 | 2014-12-18 14:36:31 -0700 | [diff] [blame] | 31 | |
| 32 | layer/Multi.cpp (name=multi1:multi2) simple example showing multiple layers per library |
| 33 | |
Jon Ashburn | eaaaced | 2015-07-23 10:59:21 -0600 | [diff] [blame] | 34 | (build dir)/layer/generic_layer.c (name=Generic) - auto generated example wrapping all VK entrypoints. |
Jens Owen | 8b5ed54 | 2014-12-18 14:36:31 -0700 | [diff] [blame] | 35 | |
| 36 | ### Print API Calls and Parameter Values |
Jon Ashburn | eaaaced | 2015-07-23 10:59:21 -0600 | [diff] [blame] | 37 | (build dir)/layer/api_dump.cpp (name=APIDump) - print out API calls along with parameter values |
Jens Owen | 8b5ed54 | 2014-12-18 14:36:31 -0700 | [diff] [blame] | 38 | |
| 39 | ### Print Object Stats |
Mark Lobodzinski | 4e5016f | 2015-05-05 15:01:37 -0500 | [diff] [blame] | 40 | (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 Owen | 8b5ed54 | 2014-12-18 14:36:31 -0700 | [diff] [blame] | 41 | |
| 42 | ### Report Draw State |
Tobin Ehlis | a75af3d | 2015-04-06 09:24:42 -0600 | [diff] [blame] | 43 | layer/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 Owen | 8b5ed54 | 2014-12-18 14:36:31 -0700 | [diff] [blame] | 44 | |
| 45 | ### Track GPU Memory |
Tobin Ehlis | a75af3d | 2015-04-06 09:24:42 -0600 | [diff] [blame] | 46 | layer/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 Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 47 | |
Tobin Ehlis | 27c2d82 | 2014-12-18 10:32:57 -0700 | [diff] [blame] | 48 | ### 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 Stroyan | b326d2c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 51 | ### 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 Ashburn | 9d290e4 | 2014-11-26 13:27:04 -0700 | [diff] [blame] | 54 | ## Using Layers |
| 55 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 56 | 1. Build VK loader and i965 icd driver using normal steps (cmake and make) |
| 57 | 2. Place libVKLayer<name>.so in the same directory as your VK test or app: |
Jens Owen | 8b5ed54 | 2014-12-18 14:36:31 -0700 | [diff] [blame] | 58 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 59 | cp build/layer/libVKLayerBasic.so build/layer/libVKLayerGeneric.so build/tests |
Jon Ashburn | de3630c | 2014-12-18 17:26:52 -0700 | [diff] [blame] | 60 | |
Jon Ashburn | eaaaced | 2015-07-23 10:59:21 -0600 | [diff] [blame] | 61 | 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 Owen | 8b5ed54 | 2014-12-18 14:36:31 -0700 | [diff] [blame] | 63 | |
| 64 | 3. Specify which Layers to activate by using |
Jon Ashburn | eaaaced | 2015-07-23 10:59:21 -0600 | [diff] [blame] | 65 | vkCreateDevice and/or vkCreateInstance or environment variables. |
Jens Owen | 8b5ed54 | 2014-12-18 14:36:31 -0700 | [diff] [blame] | 66 | |
Jon Ashburn | eaaaced | 2015-07-23 10:59:21 -0600 | [diff] [blame] | 67 | export VK\_INSTANCE\_LAYERS=Basic:Generic |
| 68 | export VK\_DEVICE\_LAYERS=Basic:Generic |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 69 | cd build/tests; ./vkinfo |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 70 | |
Jon Ashburn | 9d290e4 | 2014-11-26 13:27:04 -0700 | [diff] [blame] | 71 | ## Tips for writing new layers |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 72 | |
Jon Ashburn | eaaaced | 2015-07-23 10:59:21 -0600 | [diff] [blame] | 73 | 1. Must implement vkGetInstanceProcAddr() (aka GIPA) and vkGetDeviceProcAddr() (aka GDPA); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 74 | 2. Must have a local dispatch table to call next layer (see vkLayer.h); |
Jon Ashburn | eaaaced | 2015-07-23 10:59:21 -0600 | [diff] [blame] | 75 | 3. Must have a layer manifest file for each Layer library for Loader to find layer properties (see loader/README.md) |
| 76 | 4. next layers GXPA can be found in the wrapped instance or device object; |
| 77 | 5. Loader calls a layer's GXPA first so initialization should occur here; |
| 78 | 6. all entrypoints can be wrapped but only will be called after layer is activated |
| 79 | via the first vkCreatDevice or vkCreateInstance; |
| 80 | 7. entrypoint names can be any name as specified by the layers vkGetXXXXXProcAddr |
| 81 | implementation; exceptions are vkGetXXXXProcAddr, |
Jon Ashburn | 9d290e4 | 2014-11-26 13:27:04 -0700 | [diff] [blame] | 82 | which must have the correct name since the Loader calls these entrypoints; |
Jon Ashburn | eaaaced | 2015-07-23 10:59:21 -0600 | [diff] [blame] | 83 | 8. entrypoint names must be exported to the OSes dynamic loader with VK\_LAYER\_EXPORT; |
| 84 | 9. Layer naming convention is camel case same name as in library: libVKLayer<name>.so |
| 85 | 10. For multiple layers in one library the manifest file can specify each layer. |
Jon Ashburn | 9d290e4 | 2014-11-26 13:27:04 -0700 | [diff] [blame] | 86 | |
| 87 | ## Status |
| 88 | |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 89 | |
Jon Ashburn | 9d290e4 | 2014-11-26 13:27:04 -0700 | [diff] [blame] | 90 | ### Current known issues |
| 91 | |
Jon Ashburn | eaaaced | 2015-07-23 10:59:21 -0600 | [diff] [blame] | 92 | - 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 Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 96 | |