blob: c87629a9d2949f3d9701eea088b1694d41b193ab [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
Jon Ashburn9d290e42014-11-26 13:27:04 -070034layer/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
39layer/Multi.cpp (name=multi1:multi2) simple example showing multiple layers per library
40
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
43### Print API Calls and Parameter Values
Jon Ashburneaaaced2015-07-23 10:59:21 -060044(build dir)/layer/api_dump.cpp (name=APIDump) - print out API calls along with parameter values
Jens Owen8b5ed542014-12-18 14:36:31 -070045
46### Print Object Stats
Courtney Goeltzenleuchterc66236e2015-09-28 15:13:45 -060047(build dir)/layer/object_track.cpp (name=ObjectTracker) - Track object CREATE/USE/DESTROY stats. Individually track objects by category. VkObjectType enum defined in vulkan.h.
Jens Owen8b5ed542014-12-18 14:36:31 -070048
49### Report Draw State
Courtney Goeltzenleuchterc66236e2015-09-28 15:13:45 -060050layer/draw\_state.cpp (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.
Jens Owen8b5ed542014-12-18 14:36:31 -070051
52### Track GPU Memory
Courtney Goeltzenleuchterc66236e2015-09-28 15:13:45 -060053layer/mem\_tracker.cpp (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.
54
55### Device Limits
56<build dir>/layer/device_limits.cpp (name=DeviceLimits) - Check that parameters used do not exceed device limits.
Jon Ashburn183dfd02014-10-22 18:13:16 -060057
Tobin Ehlis27c2d822014-12-18 10:32:57 -070058### Check parameters
Courtney Goeltzenleuchterc66236e2015-09-28 15:13:45 -060059<build dir>/layer/param_checker.cpp (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.
60
61### Image Checker
62<build dir>/layer/image.cpp (name=Image) - Verify parameters on Vulkan calls that use VkImage.
Tobin Ehlis27c2d822014-12-18 10:32:57 -070063
Mike Stroyanb326d2c2015-04-02 11:59:05 -060064### Check threading
Courtney Goeltzenleuchterc66236e2015-09-28 15:13:45 -060065<build dir>/layer/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.
66
67### Swapchain
68<build dir>/layer/swapchain.cpp (name=Swapchain) - Check that WSI extensions are being used correctly.
69
70### Shader Checker
71<build dir>/layer/shader_checker.cpp (name=ShaderChecker) - Verify SPIR-V shader layout matches descriptor set.
Mike Stroyanb326d2c2015-04-02 11:59:05 -060072
Jon Ashburn9d290e42014-11-26 13:27:04 -070073## Using Layers
74
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600751. Build VK loader and i965 icd driver using normal steps (cmake and make)
762. Place libVKLayer<name>.so in the same directory as your VK test or app:
Jens Owen8b5ed542014-12-18 14:36:31 -070077
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060078 cp build/layer/libVKLayerBasic.so build/layer/libVKLayerGeneric.so build/tests
Jon Ashburnde3630c2014-12-18 17:26:52 -070079
Jon Ashburneaaaced2015-07-23 10:59:21 -060080 This is required for the Loader to be able to scan and enumerate your library.
Courtney Goeltzenleuchterc66236e2015-09-28 15:13:45 -060081 Alternatively, use the VK\_LAYER\_PATH environment variable to specify where the layer libraries reside.
Jens Owen8b5ed542014-12-18 14:36:31 -070082
833. Specify which Layers to activate by using
Jon Ashburneaaaced2015-07-23 10:59:21 -060084vkCreateDevice and/or vkCreateInstance or environment variables.
Jens Owen8b5ed542014-12-18 14:36:31 -070085
Jon Ashburneaaaced2015-07-23 10:59:21 -060086 export VK\_INSTANCE\_LAYERS=Basic:Generic
87 export VK\_DEVICE\_LAYERS=Basic:Generic
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060088 cd build/tests; ./vkinfo
Jon Ashburn183dfd02014-10-22 18:13:16 -060089
Jon Ashburn9d290e42014-11-26 13:27:04 -070090## Tips for writing new layers
Jon Ashburn183dfd02014-10-22 18:13:16 -060091
Jon Ashburneaaaced2015-07-23 10:59:21 -0600921. Must implement vkGetInstanceProcAddr() (aka GIPA) and vkGetDeviceProcAddr() (aka GDPA);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600932. Must have a local dispatch table to call next layer (see vkLayer.h);
Jon Ashburneaaaced2015-07-23 10:59:21 -0600943. Must have a layer manifest file for each Layer library for Loader to find layer properties (see loader/README.md)
954. next layers GXPA can be found in the wrapped instance or device object;
965. Loader calls a layer's GXPA first so initialization should occur here;
976. all entrypoints can be wrapped but only will be called after layer is activated
98 via the first vkCreatDevice or vkCreateInstance;
997. entrypoint names can be any name as specified by the layers vkGetXXXXXProcAddr
100 implementation; exceptions are vkGetXXXXProcAddr,
Jon Ashburn9d290e42014-11-26 13:27:04 -0700101 which must have the correct name since the Loader calls these entrypoints;
Jon Ashburneaaaced2015-07-23 10:59:21 -06001028. entrypoint names must be exported to the OSes dynamic loader with VK\_LAYER\_EXPORT;
1039. Layer naming convention is camel case same name as in library: libVKLayer<name>.so
10410. For multiple layers in one library the manifest file can specify each layer.
Jon Ashburn9d290e42014-11-26 13:27:04 -0700105
106## Status
107
Jon Ashburn183dfd02014-10-22 18:13:16 -0600108
Jon Ashburn9d290e42014-11-26 13:27:04 -0700109### Current known issues
110
Jon Ashburneaaaced2015-07-23 10:59:21 -0600111- Layers with multiple layers per library the manifest file parsing in Loader doesn't yet handle this;
112- multi.cpp Layer needs rewrite to allow manifest file to specify multiple layers
113- multi1 and multi2 layers from multi.cpp: only multi1 layer working
114
Jon Ashburn183dfd02014-10-22 18:13:16 -0600115