blob: 8c7411ad9cb5b5da0fb158b10a79c2ad940c4515 [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
Mark Lobodzinski186c4932015-11-30 08:37:47 -070017Layers are activated at vkCreateInstance time. Layers can also be activated via environment variables
Jon Ashburn12afc872015-07-23 10:59:21 -060018(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
Mark Lobodzinski186c4932015-11-30 08:37:47 -070022file to determine its behavior. Such as outputing to a file, stdout or debug output (Windows). An
Courtney Goeltzenleuchter0e1c9702015-09-28 15:13:45 -060023application 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
Mark Lobodzinski0d054fe2015-12-30 08:16:12 -070034layers/basic.cpp (name=VK_LAYER_LUNARG_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
Mark Lobodzinski186c4932015-11-30 08:37:47 -070039layers/multi.cpp (name=VK_LAYER_LUNARG_multi1:VK_LAYER_LUNARG_multi2) simple example showing multiple layers per library
40
Mark Lobodzinski0d054fe2015-12-30 08:16:12 -070041(build dir)/layer/generic_layer.cpp (name=VK_LAYER_LUNARG_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
Mark Lobodzinski0d054fe2015-12-30 08:16:12 -070047(build dir)/layers/api_dump.cpp (name=VK_LAYER_LUNARG_api_dump) - print out API calls along with parameter values
Jens Owen763b76e2014-12-18 14:36:31 -070048
49### Print Object Stats
Mark Lobodzinski0d054fe2015-12-30 08:16:12 -070050(build dir)/layers/object_tracker.cpp (name=VK_LAYER_LUNARG_object_tracker) - 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 Ehlis7e2ad752015-12-01 09:48:58 -070052### Validate Draw State and Shaders
Mark Lobodzinski0d054fe2015-12-30 08:16:12 -070053layers/draw\_state.cpp (name=VK_LAYER_LUNARG_draw_state) - DrawState tracks the Descriptor Set, Pipeline State, Shaders, 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. Additionally DrawState include sharder validation (formerly separate ShaderChecker layer) that 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.
Jens Owen763b76e2014-12-18 14:36:31 -070054
55### Track GPU Memory
Mark Lobodzinski0d054fe2015-12-30 08:16:12 -070056layers/mem\_tracker.cpp (name=VK_LAYER_LUNARG_mem_tracker) - 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
Mark Lobodzinski0d054fe2015-12-30 08:16:12 -070059layers/param_checker.cpp (name=VK_LAYER_LUNARG_param_checker) - 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
Mark Lobodzinski0d054fe2015-12-30 08:16:12 -070062layers/image.cpp (name=VK_LAYER_LUNARG_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
Mark Lobodzinski0d054fe2015-12-30 08:16:12 -070065<build dir>/layers/threading.cpp (name=VK_LAYER_LUNARG_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
Mark Lobodzinski0d054fe2015-12-30 08:16:12 -070068<build dir>/layer/swapchain.cpp (name=VK_LAYER_LUNARG_swapchain) - Check that WSI extensions are being used correctly.
Courtney Goeltzenleuchter0e1c9702015-09-28 15:13:45 -060069
Tobin Ehlisf3fad352015-10-01 15:26:33 -060070### Device Limitations
Mark Lobodzinski0d054fe2015-12-30 08:16:12 -070071layers/device_limits.cpp (name=VK_LAYER_LUNARG_device_limits) - 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 -060072
Jon Ashburna5817d52014-11-26 13:27:04 -070073## Using Layers
74
Tobin Ehlisf3fad352015-10-01 15:26:33 -0600751. Build VK loader and i965 icd driver using normal steps (cmake and make)
Mark Lobodzinski0d054fe2015-12-30 08:16:12 -0700762. Place libVkLayer_<name>.so in the same directory as your VK test or app:
Jens Owen763b76e2014-12-18 14:36:31 -070077
Mark Lobodzinski0d054fe2015-12-30 08:16:12 -070078 cp build/layer/libVkLayer_basic.so build/layer/libVkLayer_generic.so build/tests
Jon Ashburn649d8712014-12-18 17:26:52 -070079
Jon Ashburn12afc872015-07-23 10:59:21 -060080 This is required for the Loader to be able to scan and enumerate your library.
Courtney Goeltzenleuchter0e1c9702015-09-28 15:13:45 -060081 Alternatively, use the VK\_LAYER\_PATH environment variable to specify where the layer libraries reside.
Jens Owen763b76e2014-12-18 14:36:31 -070082
Cody Northrop6dfa2792015-11-23 13:52:26 -0700833. Create a vk_layer_settings.txt file in the same directory to specify how your layers should behave.
84
85 Model it after the following example: [*vk_layer_settings.txt*](layers/vk_layer_settings.txt)
86
874. Specify which Layers to activate by using
Jon Ashburn12afc872015-07-23 10:59:21 -060088vkCreateDevice and/or vkCreateInstance or environment variables.
Jens Owen763b76e2014-12-18 14:36:31 -070089
Mark Lobodzinski0d054fe2015-12-30 08:16:12 -070090 export VK\_INSTANCE\_LAYERS=VK_LAYER_LUNARG_basic:VK_LAYER_LUNARG_generic
91 export VK\_DEVICE\_LAYERS=VK_LAYER_LUNARG_basic:VK_LAYER_LUNARG_generic
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060092 cd build/tests; ./vkinfo
Jon Ashburn6b4d70c2014-10-22 18:13:16 -060093
Jon Ashburna5817d52014-11-26 13:27:04 -070094## Tips for writing new layers
Jon Ashburn6b4d70c2014-10-22 18:13:16 -060095
Jon Ashburn12afc872015-07-23 10:59:21 -0600961. Must implement vkGetInstanceProcAddr() (aka GIPA) and vkGetDeviceProcAddr() (aka GDPA);
Tobin Ehlisf3fad352015-10-01 15:26:33 -0600972. Must have a local dispatch table to call next layer (see vk_layer.h);
Jon Ashburn12afc872015-07-23 10:59:21 -0600983. 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 -0600994. Next layers GXPA can be found in the wrapped instance or device object;
1005. Loader calls a layer's GXPA first so initialization should occur here;
Jon Ashburn12afc872015-07-23 10:59:21 -06001016. all entrypoints can be wrapped but only will be called after layer is activated
102 via the first vkCreatDevice or vkCreateInstance;
1037. entrypoint names can be any name as specified by the layers vkGetXXXXXProcAddr
104 implementation; exceptions are vkGetXXXXProcAddr,
Jon Ashburna5817d52014-11-26 13:27:04 -0700105 which must have the correct name since the Loader calls these entrypoints;
Jon Ashburn12afc872015-07-23 10:59:21 -06001068. entrypoint names must be exported to the OSes dynamic loader with VK\_LAYER\_EXPORT;
Mark Lobodzinski0d054fe2015-12-30 08:16:12 -07001079. Layer naming convention is camel case same name as in library: libVkLayer_<name>.so
Jon Ashburn12afc872015-07-23 10:59:21 -060010810. For multiple layers in one library the manifest file can specify each layer.
Jon Ashburna5817d52014-11-26 13:27:04 -0700109
110## Status
111
Jon Ashburn6b4d70c2014-10-22 18:13:16 -0600112
Jon Ashburna5817d52014-11-26 13:27:04 -0700113### Current known issues
114
Mark Lobodzinski186c4932015-11-30 08:37:47 -0700115- Layers with multiple layers per library: the manifest file parsing in Loader doesn't yet handle this
Jon Ashburn12afc872015-07-23 10:59:21 -0600116- multi.cpp Layer needs rewrite to allow manifest file to specify multiple layers
Mark Lobodzinski186c4932015-11-30 08:37:47 -0700117- multi1 and multi2 layers from multi.cpp: only multi1 layer working