blob: 4e53ed8cfc81d44672ce85556b53b59c230d0a20 [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
Courtney Goeltzenleuchterc66236e2015-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
Jens Owen8b5ed542014-12-18 14:36:31 -070027##Layer library example code
Jon Ashburn9d290e42014-11-26 13:27:04 -070028
Jon Ashburnde3630c2014-12-18 17:26:52 -070029Note that some layers are code-generated and will therefore exist in the directory (build_dir)/layers
30
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060031-include/vkLayer.h - header file for layer code.
Jens Owen8b5ed542014-12-18 14:36:31 -070032
33### Templates
Tobin Ehlis173d93e2015-10-01 15:26:33 -060034layers/basic.cpp (name=Basic) simple example wrapping a few entrypoints. Shows layer features:
Jens Owen8b5ed542014-12-18 14:36:31 -070035- Multiple dispatch tables for supporting multiple GPUs.
36- Example layer extension function shown.
Jon Ashburneaaaced2015-07-23 10:59:21 -060037- Layer extension advertised by vkGetXXXExtension().
Jens Owen8b5ed542014-12-18 14:36:31 -070038
Tobin Ehlis173d93e2015-10-01 15:26:33 -060039layers/multi.cpp (name=multi1:multi2) simple example showing multiple layers per library
Jens Owen8b5ed542014-12-18 14:36:31 -070040
Courtney Goeltzenleuchterc66236e2015-09-28 15:13:45 -060041(build dir)/layer/generic_layer.cpp (name=Generic) - auto generated example wrapping all VK entrypoints.
Jens Owen8b5ed542014-12-18 14:36:31 -070042
Tobin Ehlis173d93e2015-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 Owen8b5ed542014-12-18 14:36:31 -070046### Print API Calls and Parameter Values
Tobin Ehlis173d93e2015-10-01 15:26:33 -060047(build dir)/layers/api_dump.cpp (name=APIDump) - print out API calls along with parameter values
Jens Owen8b5ed542014-12-18 14:36:31 -070048
49### Print Object Stats
Tobin Ehlis173d93e2015-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 Owen8b5ed542014-12-18 14:36:31 -070051
Tobin Ehlis173d93e2015-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 Owen8b5ed542014-12-18 14:36:31 -070054
55### Track GPU Memory
Tobin Ehlis173d93e2015-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 Ashburn183dfd02014-10-22 18:13:16 -060057
Tobin Ehlis27c2d822014-12-18 10:32:57 -070058### Check parameters
Tobin Ehlis173d93e2015-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 Goeltzenleuchterc66236e2015-09-28 15:13:45 -060060
Tobin Ehlis173d93e2015-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 Ehlis27c2d822014-12-18 10:32:57 -070063
Mike Stroyanb326d2c2015-04-02 11:59:05 -060064### Check threading
Tobin Ehlis173d93e2015-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 Goeltzenleuchterc66236e2015-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 Ehlis173d93e2015-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 Stroyanb326d2c2015-04-02 11:59:05 -060075
Jon Ashburn9d290e42014-11-26 13:27:04 -070076## Using Layers
77
Tobin Ehlis173d93e2015-10-01 15:26:33 -0600781. Build VK loader and i965 icd driver using normal steps (cmake and make)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600792. Place libVKLayer<name>.so in the same directory as your VK test or app:
Jens Owen8b5ed542014-12-18 14:36:31 -070080
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060081 cp build/layer/libVKLayerBasic.so build/layer/libVKLayerGeneric.so build/tests
Jon Ashburnde3630c2014-12-18 17:26:52 -070082
Jon Ashburneaaaced2015-07-23 10:59:21 -060083 This is required for the Loader to be able to scan and enumerate your library.
Courtney Goeltzenleuchterc66236e2015-09-28 15:13:45 -060084 Alternatively, use the VK\_LAYER\_PATH environment variable to specify where the layer libraries reside.
Jens Owen8b5ed542014-12-18 14:36:31 -070085
863. Specify which Layers to activate by using
Jon Ashburneaaaced2015-07-23 10:59:21 -060087vkCreateDevice and/or vkCreateInstance or environment variables.
Jens Owen8b5ed542014-12-18 14:36:31 -070088
Jon Ashburneaaaced2015-07-23 10:59:21 -060089 export VK\_INSTANCE\_LAYERS=Basic:Generic
90 export VK\_DEVICE\_LAYERS=Basic:Generic
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060091 cd build/tests; ./vkinfo
Jon Ashburn183dfd02014-10-22 18:13:16 -060092
Jon Ashburn9d290e42014-11-26 13:27:04 -070093## Tips for writing new layers
Jon Ashburn183dfd02014-10-22 18:13:16 -060094
Jon Ashburneaaaced2015-07-23 10:59:21 -0600951. Must implement vkGetInstanceProcAddr() (aka GIPA) and vkGetDeviceProcAddr() (aka GDPA);
Tobin Ehlis173d93e2015-10-01 15:26:33 -0600962. Must have a local dispatch table to call next layer (see vk_layer.h);
Jon Ashburneaaaced2015-07-23 10:59:21 -0600973. Must have a layer manifest file for each Layer library for Loader to find layer properties (see loader/README.md)
Tobin Ehlis173d93e2015-10-01 15:26:33 -0600984. Next layers GXPA can be found in the wrapped instance or device object;
995. Loader calls a layer's GXPA first so initialization should occur here;
Jon Ashburneaaaced2015-07-23 10:59:21 -06001006. all entrypoints can be wrapped but only will be called after layer is activated
101 via the first vkCreatDevice or vkCreateInstance;
1027. entrypoint names can be any name as specified by the layers vkGetXXXXXProcAddr
103 implementation; exceptions are vkGetXXXXProcAddr,
Jon Ashburn9d290e42014-11-26 13:27:04 -0700104 which must have the correct name since the Loader calls these entrypoints;
Jon Ashburneaaaced2015-07-23 10:59:21 -06001058. entrypoint names must be exported to the OSes dynamic loader with VK\_LAYER\_EXPORT;
1069. Layer naming convention is camel case same name as in library: libVKLayer<name>.so
10710. For multiple layers in one library the manifest file can specify each layer.
Jon Ashburn9d290e42014-11-26 13:27:04 -0700108
109## Status
110
Jon Ashburn183dfd02014-10-22 18:13:16 -0600111
Jon Ashburn9d290e42014-11-26 13:27:04 -0700112### Current known issues
113
Jon Ashburneaaaced2015-07-23 10:59:21 -0600114- Layers with multiple layers per library the manifest file parsing in Loader doesn't yet handle this;
115- multi.cpp Layer needs rewrite to allow manifest file to specify multiple layers
116- multi1 and multi2 layers from multi.cpp: only multi1 layer working
117