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 | |
Courtney Goeltzenleuchter | c66236e | 2015-09-28 15:13:45 -0600 | [diff] [blame] | 20 | All validation layers work with the DEBUG_REPORT extension to provide the application or user with |
| 21 | validation feedback. When a validation layer is enabled, it will look at the vk_layer_settings.txt |
| 22 | file to determine it's behavior. Such as outputing to a file, stdout or debug output (Windows). An |
| 23 | application can also register callback functions via the DEBUG_REPORT extension to receive callbacks |
| 24 | when the requested validation events happen. Application callbacks happen regardless of the |
| 25 | settings in vk_layer_settings.txt |
| 26 | |
Jens Owen | 8b5ed54 | 2014-12-18 14:36:31 -0700 | [diff] [blame] | 27 | ##Layer library example code |
Jon Ashburn | 9d290e4 | 2014-11-26 13:27:04 -0700 | [diff] [blame] | 28 | |
Jon Ashburn | de3630c | 2014-12-18 17:26:52 -0700 | [diff] [blame] | 29 | Note that some layers are code-generated and will therefore exist in the directory (build_dir)/layers |
| 30 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 31 | -include/vkLayer.h - header file for layer code. |
Jens Owen | 8b5ed54 | 2014-12-18 14:36:31 -0700 | [diff] [blame] | 32 | |
| 33 | ### Templates |
Tobin Ehlis | 173d93e | 2015-10-01 15:26:33 -0600 | [diff] [blame] | 34 | layers/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] | 35 | - Multiple dispatch tables for supporting multiple GPUs. |
| 36 | - Example layer extension function shown. |
Jon Ashburn | eaaaced | 2015-07-23 10:59:21 -0600 | [diff] [blame] | 37 | - Layer extension advertised by vkGetXXXExtension(). |
Jens Owen | 8b5ed54 | 2014-12-18 14:36:31 -0700 | [diff] [blame] | 38 | |
Tobin Ehlis | 173d93e | 2015-10-01 15:26:33 -0600 | [diff] [blame] | 39 | layers/multi.cpp (name=multi1:multi2) simple example showing multiple layers per library |
Jens Owen | 8b5ed54 | 2014-12-18 14:36:31 -0700 | [diff] [blame] | 40 | |
Courtney Goeltzenleuchter | c66236e | 2015-09-28 15:13:45 -0600 | [diff] [blame] | 41 | (build dir)/layer/generic_layer.cpp (name=Generic) - auto generated example wrapping all VK entrypoints. |
Jens Owen | 8b5ed54 | 2014-12-18 14:36:31 -0700 | [diff] [blame] | 42 | |
Tobin Ehlis | 173d93e | 2015-10-01 15:26:33 -0600 | [diff] [blame] | 43 | ### Layer Details |
| 44 | For 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 Owen | 8b5ed54 | 2014-12-18 14:36:31 -0700 | [diff] [blame] | 46 | ### Print API Calls and Parameter Values |
Tobin Ehlis | 173d93e | 2015-10-01 15:26:33 -0600 | [diff] [blame] | 47 | (build dir)/layers/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] | 48 | |
| 49 | ### Print Object Stats |
Tobin Ehlis | 173d93e | 2015-10-01 15:26:33 -0600 | [diff] [blame] | 50 | (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 Owen | 8b5ed54 | 2014-12-18 14:36:31 -0700 | [diff] [blame] | 51 | |
Tobin Ehlis | 173d93e | 2015-10-01 15:26:33 -0600 | [diff] [blame] | 52 | ### Validate Draw State |
| 53 | layers/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 Owen | 8b5ed54 | 2014-12-18 14:36:31 -0700 | [diff] [blame] | 54 | |
| 55 | ### Track GPU Memory |
Tobin Ehlis | 173d93e | 2015-10-01 15:26:33 -0600 | [diff] [blame] | 56 | layers/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 Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 57 | |
Tobin Ehlis | 27c2d82 | 2014-12-18 10:32:57 -0700 | [diff] [blame] | 58 | ### Check parameters |
Tobin Ehlis | 173d93e | 2015-10-01 15:26:33 -0600 | [diff] [blame] | 59 | layers/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 Goeltzenleuchter | c66236e | 2015-09-28 15:13:45 -0600 | [diff] [blame] | 60 | |
Tobin Ehlis | 173d93e | 2015-10-01 15:26:33 -0600 | [diff] [blame] | 61 | ### Image parameters |
| 62 | layers/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 Ehlis | 27c2d82 | 2014-12-18 10:32:57 -0700 | [diff] [blame] | 63 | |
Mike Stroyan | b326d2c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 64 | ### Check threading |
Tobin Ehlis | 173d93e | 2015-10-01 15:26:33 -0600 | [diff] [blame] | 65 | <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 Goeltzenleuchter | c66236e | 2015-09-28 15:13:45 -0600 | [diff] [blame] | 66 | |
| 67 | ### Swapchain |
| 68 | <build dir>/layer/swapchain.cpp (name=Swapchain) - Check that WSI extensions are being used correctly. |
| 69 | |
Tobin Ehlis | 173d93e | 2015-10-01 15:26:33 -0600 | [diff] [blame] | 70 | ### 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 |
| 74 | layers/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 Stroyan | b326d2c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 75 | |
Jon Ashburn | 9d290e4 | 2014-11-26 13:27:04 -0700 | [diff] [blame] | 76 | ## Using Layers |
| 77 | |
Tobin Ehlis | 173d93e | 2015-10-01 15:26:33 -0600 | [diff] [blame] | 78 | 1. Build VK loader and i965 icd driver using normal steps (cmake and make) |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 79 | 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] | 80 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 81 | cp build/layer/libVKLayerBasic.so build/layer/libVKLayerGeneric.so build/tests |
Jon Ashburn | de3630c | 2014-12-18 17:26:52 -0700 | [diff] [blame] | 82 | |
Jon Ashburn | eaaaced | 2015-07-23 10:59:21 -0600 | [diff] [blame] | 83 | This is required for the Loader to be able to scan and enumerate your library. |
Courtney Goeltzenleuchter | c66236e | 2015-09-28 15:13:45 -0600 | [diff] [blame] | 84 | Alternatively, use the VK\_LAYER\_PATH environment variable to specify where the layer libraries reside. |
Jens Owen | 8b5ed54 | 2014-12-18 14:36:31 -0700 | [diff] [blame] | 85 | |
| 86 | 3. Specify which Layers to activate by using |
Jon Ashburn | eaaaced | 2015-07-23 10:59:21 -0600 | [diff] [blame] | 87 | vkCreateDevice and/or vkCreateInstance or environment variables. |
Jens Owen | 8b5ed54 | 2014-12-18 14:36:31 -0700 | [diff] [blame] | 88 | |
Jon Ashburn | eaaaced | 2015-07-23 10:59:21 -0600 | [diff] [blame] | 89 | export VK\_INSTANCE\_LAYERS=Basic:Generic |
| 90 | export VK\_DEVICE\_LAYERS=Basic:Generic |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 91 | cd build/tests; ./vkinfo |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 92 | |
Jon Ashburn | 9d290e4 | 2014-11-26 13:27:04 -0700 | [diff] [blame] | 93 | ## Tips for writing new layers |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 94 | |
Jon Ashburn | eaaaced | 2015-07-23 10:59:21 -0600 | [diff] [blame] | 95 | 1. Must implement vkGetInstanceProcAddr() (aka GIPA) and vkGetDeviceProcAddr() (aka GDPA); |
Tobin Ehlis | 173d93e | 2015-10-01 15:26:33 -0600 | [diff] [blame] | 96 | 2. Must have a local dispatch table to call next layer (see vk_layer.h); |
Jon Ashburn | eaaaced | 2015-07-23 10:59:21 -0600 | [diff] [blame] | 97 | 3. Must have a layer manifest file for each Layer library for Loader to find layer properties (see loader/README.md) |
Tobin Ehlis | 173d93e | 2015-10-01 15:26:33 -0600 | [diff] [blame] | 98 | 4. Next layers GXPA can be found in the wrapped instance or device object; |
| 99 | 5. Loader calls a layer's GXPA first so initialization should occur here; |
Jon Ashburn | eaaaced | 2015-07-23 10:59:21 -0600 | [diff] [blame] | 100 | 6. all entrypoints can be wrapped but only will be called after layer is activated |
| 101 | via the first vkCreatDevice or vkCreateInstance; |
| 102 | 7. entrypoint names can be any name as specified by the layers vkGetXXXXXProcAddr |
| 103 | implementation; exceptions are vkGetXXXXProcAddr, |
Jon Ashburn | 9d290e4 | 2014-11-26 13:27:04 -0700 | [diff] [blame] | 104 | which must have the correct name since the Loader calls these entrypoints; |
Jon Ashburn | eaaaced | 2015-07-23 10:59:21 -0600 | [diff] [blame] | 105 | 8. entrypoint names must be exported to the OSes dynamic loader with VK\_LAYER\_EXPORT; |
| 106 | 9. Layer naming convention is camel case same name as in library: libVKLayer<name>.so |
| 107 | 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] | 108 | |
| 109 | ## Status |
| 110 | |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 111 | |
Jon Ashburn | 9d290e4 | 2014-11-26 13:27:04 -0700 | [diff] [blame] | 112 | ### Current known issues |
| 113 | |
Jon Ashburn | eaaaced | 2015-07-23 10:59:21 -0600 | [diff] [blame] | 114 | - 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 | |