blob: 760443b234535f33e70e45237d664cc19aa766cc [file] [log] [blame] [view]
Jens Owen763b76e2014-12-18 14:36:31 -07001# Layer Description and Status
Jon Ashburn6b4d70c2014-10-22 18:13:16 -06002
Jens Owen763b76e2014-12-18 14:36:31 -07003## Overview
Jon Ashburna5817d52014-11-26 13:27:04 -07004
Jon Ashburn12afc872015-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 Ashburn6b4d70c2014-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 Goeltzenleuchter35985f62015-09-14 17:22:16 -06009vkEnumerateInstanceLayerProperties and vkEnumerateDeviceLayerProperties can be called to list the
Jon Ashburn12afc872015-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
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013or VkPhysicalDevice as first parameter. Device level entry points are those with VkDevice, VkCommandBuffer,
Jon Ashburn12afc872015-07-23 10:59:21 -060014or 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 Ashburn6b4d70c2014-10-22 18:13:16 -060019
Courtney Goeltzenleuchter0e1c9702015-09-28 15:13:45 -060020All validation layers work with the DEBUG_REPORT extension to provide the application or user with
21validation feedback. When a validation layer is enabled, it will look at the vk_layer_settings.txt
22file to determine it's behavior. Such as outputing to a file, stdout or debug output (Windows). An
23application can also register callback functions via the DEBUG_REPORT extension to receive callbacks
24when the requested validation events happen. Application callbacks happen regardless of the
25settings in vk_layer_settings.txt
26
Cody Northrop6dfa2792015-11-23 13:52:26 -070027### Layer library example code
Jon Ashburna5817d52014-11-26 13:27:04 -070028
Jon Ashburn649d8712014-12-18 17:26:52 -070029Note that some layers are code-generated and will therefore exist in the directory (build_dir)/layers
30
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060031-include/vkLayer.h - header file for layer code.
Jens Owen763b76e2014-12-18 14:36:31 -070032
33### Templates
Tobin Ehlisf3fad352015-10-01 15:26:33 -060034layers/basic.cpp (name=Basic) simple example wrapping a few entrypoints. Shows layer features:
Jens Owen763b76e2014-12-18 14:36:31 -070035- Multiple dispatch tables for supporting multiple GPUs.
36- Example layer extension function shown.
Jon Ashburn12afc872015-07-23 10:59:21 -060037- Layer extension advertised by vkGetXXXExtension().
Jens Owen763b76e2014-12-18 14:36:31 -070038
Tobin Ehlisf3fad352015-10-01 15:26:33 -060039layers/multi.cpp (name=multi1:multi2) simple example showing multiple layers per library
Jens Owen763b76e2014-12-18 14:36:31 -070040
Courtney Goeltzenleuchter0e1c9702015-09-28 15:13:45 -060041(build dir)/layer/generic_layer.cpp (name=Generic) - auto generated example wrapping all VK entrypoints.
Jens Owen763b76e2014-12-18 14:36:31 -070042
Tobin Ehlisf3fad352015-10-01 15:26:33 -060043### Layer Details
44For complete details of current validation layers, including all of the validation checks that they perform, please refer to the document layers/vk_validation_layer_details.md. Below is a brief overview of each layer.
45
Jens Owen763b76e2014-12-18 14:36:31 -070046### Print API Calls and Parameter Values
Tobin Ehlisf3fad352015-10-01 15:26:33 -060047(build dir)/layers/api_dump.cpp (name=APIDump) - print out API calls along with parameter values
Jens Owen763b76e2014-12-18 14:36:31 -070048
49### Print Object Stats
Tobin Ehlisf3fad352015-10-01 15:26:33 -060050(build dir)/layers/object_track.cpp (name=ObjectTracker) - Track object creation, use, and destruction. As objects are created, they're stored in a map. As objects are used, the layer verifies they exist in the map, flagging errors for unknown objects. As objects are destroyed, they're removed from the map. At vkDestroyDevice() and vkDestroyInstance() times, if any objects have not been destroyed, they are reported as leaked objects. If a Dbg callback function is registered, this layer will use callback function(s) for reporting, otherwise uses stdout.
Jens Owen763b76e2014-12-18 14:36:31 -070051
Tobin Ehlisf3fad352015-10-01 15:26:33 -060052### Validate Draw State
53layers/draw\_state.cpp (name=DrawState) - DrawState tracks the Descriptor Set, Pipeline State, and dynamic state performing some point validation as states are created and used, and further validation at each Draw call. 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 Owen763b76e2014-12-18 14:36:31 -070054
55### Track GPU Memory
Tobin Ehlisf3fad352015-10-01 15:26:33 -060056layers/mem\_tracker.cpp (name=MemTracker) - The MemTracker layer tracks memory objects and references and validates that they are managed correctly by the application. This includes tracking object bindings, memory hazards, and memory object lifetimes. MemTracker validates several other hazard-related issues related to command buffers, fences, and memory mapping. If a Dbg callback function is registered, this layer will use callback function(s) for reporting, otherwise uses stdout.
Jon Ashburn6b4d70c2014-10-22 18:13:16 -060057
Tobin Ehlis6e6aa1f2014-12-18 10:32:57 -070058### Check parameters
Tobin Ehlisf3fad352015-10-01 15:26:33 -060059layers/param_checker.cpp (name=ParamChecker) - Check the input parameters to API calls for validity. If a Dbg callback function is registered, this layer will use callback function(s) for reporting, otherwise uses stdout.
Courtney Goeltzenleuchter0e1c9702015-09-28 15:13:45 -060060
Tobin Ehlisf3fad352015-10-01 15:26:33 -060061### Image parameters
62layers/image.cpp (name=Image) - The Image layer is intended to validate image parameters, formats, and correct use. Images are a significant enough area that they were given a separate layer. If a Dbg callback function is registered, this layer will use callback function(s) for reporting, otherwise uses stdout.
Tobin Ehlis6e6aa1f2014-12-18 10:32:57 -070063
Mike Stroyan3712d5c2015-04-02 11:59:05 -060064### Check threading
Tobin Ehlisf3fad352015-10-01 15:26:33 -060065<build dir>/layers/threading.cpp (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.
Courtney Goeltzenleuchter0e1c9702015-09-28 15:13:45 -060066
67### Swapchain
68<build dir>/layer/swapchain.cpp (name=Swapchain) - Check that WSI extensions are being used correctly.
69
Tobin Ehlisf3fad352015-10-01 15:26:33 -060070### Validate Shaders
71<build dir>/layers/shader_checker.cpp (name=ShaderChecker) - The ShaderChecker layer inspects the SPIR-V shader images and fixed function pipeline stages at PSO creation time. It flags errors when inconsistencies are found across interfaces between shader stages. The exact behavior of the checks depends on the pair of pipeline stages involved. If a Dbg callback function is registered, this layer will use callback function(s) for reporting, otherwise uses stdout.
72
73### Device Limitations
74layers/device_limits.cpp (name=DeviceLimits) - This layer is intended to capture underlying device features and limitations and then flag errors if an app makes requests for unsupported features or exceeding limitations. This layer is a work in progress and currently only flags some high-level errors without flagging errors on specific feature and limitation. If a Dbg callback function is registered, this layer will use callback function(s) for reporting, otherwise uses stdout.
Mike Stroyan3712d5c2015-04-02 11:59:05 -060075
Jon Ashburna5817d52014-11-26 13:27:04 -070076## Using Layers
77
Tobin Ehlisf3fad352015-10-01 15:26:33 -0600781. Build VK loader and i965 icd driver using normal steps (cmake and make)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600792. Place libVKLayer<name>.so in the same directory as your VK test or app:
Jens Owen763b76e2014-12-18 14:36:31 -070080
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060081 cp build/layer/libVKLayerBasic.so build/layer/libVKLayerGeneric.so build/tests
Jon Ashburn649d8712014-12-18 17:26:52 -070082
Jon Ashburn12afc872015-07-23 10:59:21 -060083 This is required for the Loader to be able to scan and enumerate your library.
Courtney Goeltzenleuchter0e1c9702015-09-28 15:13:45 -060084 Alternatively, use the VK\_LAYER\_PATH environment variable to specify where the layer libraries reside.
Jens Owen763b76e2014-12-18 14:36:31 -070085
Cody Northrop6dfa2792015-11-23 13:52:26 -0700863. Create a vk_layer_settings.txt file in the same directory to specify how your layers should behave.
87
88 Model it after the following example: [*vk_layer_settings.txt*](layers/vk_layer_settings.txt)
89
904. Specify which Layers to activate by using
Jon Ashburn12afc872015-07-23 10:59:21 -060091vkCreateDevice and/or vkCreateInstance or environment variables.
Jens Owen763b76e2014-12-18 14:36:31 -070092
Jon Ashburn12afc872015-07-23 10:59:21 -060093 export VK\_INSTANCE\_LAYERS=Basic:Generic
94 export VK\_DEVICE\_LAYERS=Basic:Generic
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060095 cd build/tests; ./vkinfo
Jon Ashburn6b4d70c2014-10-22 18:13:16 -060096
Jon Ashburna5817d52014-11-26 13:27:04 -070097## Tips for writing new layers
Jon Ashburn6b4d70c2014-10-22 18:13:16 -060098
Jon Ashburn12afc872015-07-23 10:59:21 -0600991. Must implement vkGetInstanceProcAddr() (aka GIPA) and vkGetDeviceProcAddr() (aka GDPA);
Tobin Ehlisf3fad352015-10-01 15:26:33 -06001002. Must have a local dispatch table to call next layer (see vk_layer.h);
Jon Ashburn12afc872015-07-23 10:59:21 -06001013. Must have a layer manifest file for each Layer library for Loader to find layer properties (see loader/README.md)
Tobin Ehlisf3fad352015-10-01 15:26:33 -06001024. Next layers GXPA can be found in the wrapped instance or device object;
1035. Loader calls a layer's GXPA first so initialization should occur here;
Jon Ashburn12afc872015-07-23 10:59:21 -06001046. all entrypoints can be wrapped but only will be called after layer is activated
105 via the first vkCreatDevice or vkCreateInstance;
1067. entrypoint names can be any name as specified by the layers vkGetXXXXXProcAddr
107 implementation; exceptions are vkGetXXXXProcAddr,
Jon Ashburna5817d52014-11-26 13:27:04 -0700108 which must have the correct name since the Loader calls these entrypoints;
Jon Ashburn12afc872015-07-23 10:59:21 -06001098. entrypoint names must be exported to the OSes dynamic loader with VK\_LAYER\_EXPORT;
1109. Layer naming convention is camel case same name as in library: libVKLayer<name>.so
11110. For multiple layers in one library the manifest file can specify each layer.
Jon Ashburna5817d52014-11-26 13:27:04 -0700112
113## Status
114
Jon Ashburn6b4d70c2014-10-22 18:13:16 -0600115
Jon Ashburna5817d52014-11-26 13:27:04 -0700116### Current known issues
117
Jon Ashburn12afc872015-07-23 10:59:21 -0600118- Layers with multiple layers per library the manifest file parsing in Loader doesn't yet handle this;
119- multi.cpp Layer needs rewrite to allow manifest file to specify multiple layers
Cody Northrop6dfa2792015-11-23 13:52:26 -0700120- multi1 and multi2 layers from multi.cpp: only multi1 layer working