Jens Owen | 763b76e | 2014-12-18 14:36:31 -0700 | [diff] [blame] | 1 | # Layer Description and Status |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 2 | |
Jens Owen | 763b76e | 2014-12-18 14:36:31 -0700 | [diff] [blame] | 3 | ## Overview |
Jon Ashburn | a5817d5 | 2014-11-26 13:27:04 -0700 | [diff] [blame] | 4 | |
Jon Ashburn | 12afc87 | 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 | 6b4d70c | 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 | 35985f6 | 2015-09-14 17:22:16 -0600 | [diff] [blame] | 9 | vkEnumerateInstanceLayerProperties and vkEnumerateDeviceLayerProperties can be called to list the |
Jon Ashburn | 12afc87 | 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 |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13 | or VkPhysicalDevice as first parameter. Device level entry points are those with VkDevice, VkCommandBuffer, |
Jon Ashburn | 12afc87 | 2015-07-23 10:59:21 -0600 | [diff] [blame] | 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 |
Mark Lobodzinski | 186c493 | 2015-11-30 08:37:47 -0700 | [diff] [blame] | 17 | Layers are activated at vkCreateInstance time. Layers can also be activated via environment variables |
Jon Ashburn | 12afc87 | 2015-07-23 10:59:21 -0600 | [diff] [blame] | 18 | (VK_INSTANCE_LAYERS or VK_DEVICE_LAYERS). |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 19 | |
Courtney Goeltzenleuchter | 0e1c970 | 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 |
Mark Lobodzinski | 186c493 | 2015-11-30 08:37:47 -0700 | [diff] [blame] | 22 | file to determine its behavior. Such as outputing to a file, stdout or debug output (Windows). An |
Courtney Goeltzenleuchter | 0e1c970 | 2015-09-28 15:13:45 -0600 | [diff] [blame] | 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 | |
Cody Northrop | 6dfa279 | 2015-11-23 13:52:26 -0700 | [diff] [blame] | 27 | ### Layer library example code |
Jon Ashburn | a5817d5 | 2014-11-26 13:27:04 -0700 | [diff] [blame] | 28 | |
Jon Ashburn | 649d871 | 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 | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 31 | -include/vkLayer.h - header file for layer code. |
Jens Owen | 763b76e | 2014-12-18 14:36:31 -0700 | [diff] [blame] | 32 | |
| 33 | ### Templates |
Mark Lobodzinski | 0d054fe | 2015-12-30 08:16:12 -0700 | [diff] [blame] | 34 | layers/basic.cpp (name=VK_LAYER_LUNARG_basic) simple example wrapping a few entrypoints. Shows layer features: |
Jens Owen | 763b76e | 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 | 12afc87 | 2015-07-23 10:59:21 -0600 | [diff] [blame] | 37 | - Layer extension advertised by vkGetXXXExtension(). |
Jens Owen | 763b76e | 2014-12-18 14:36:31 -0700 | [diff] [blame] | 38 | |
Mark Lobodzinski | 186c493 | 2015-11-30 08:37:47 -0700 | [diff] [blame] | 39 | layers/multi.cpp (name=VK_LAYER_LUNARG_multi1:VK_LAYER_LUNARG_multi2) simple example showing multiple layers per library |
| 40 | |
Mark Lobodzinski | 0d054fe | 2015-12-30 08:16:12 -0700 | [diff] [blame] | 41 | (build dir)/layer/generic_layer.cpp (name=VK_LAYER_LUNARG_generic) - auto generated example wrapping all VK entrypoints. |
Jens Owen | 763b76e | 2014-12-18 14:36:31 -0700 | [diff] [blame] | 42 | |
Tobin Ehlis | f3fad35 | 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 | 763b76e | 2014-12-18 14:36:31 -0700 | [diff] [blame] | 46 | ### Print API Calls and Parameter Values |
Mark Lobodzinski | 0d054fe | 2015-12-30 08:16:12 -0700 | [diff] [blame] | 47 | (build dir)/layers/api_dump.cpp (name=VK_LAYER_LUNARG_api_dump) - print out API calls along with parameter values |
Jens Owen | 763b76e | 2014-12-18 14:36:31 -0700 | [diff] [blame] | 48 | |
| 49 | ### Print Object Stats |
Mark Lobodzinski | 0d054fe | 2015-12-30 08:16:12 -0700 | [diff] [blame] | 50 | (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 Owen | 763b76e | 2014-12-18 14:36:31 -0700 | [diff] [blame] | 51 | |
Tobin Ehlis | 7e2ad75 | 2015-12-01 09:48:58 -0700 | [diff] [blame] | 52 | ### Validate Draw State and Shaders |
Mark Lobodzinski | 0d054fe | 2015-12-30 08:16:12 -0700 | [diff] [blame] | 53 | layers/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 Owen | 763b76e | 2014-12-18 14:36:31 -0700 | [diff] [blame] | 54 | |
| 55 | ### Track GPU Memory |
Mark Lobodzinski | 0d054fe | 2015-12-30 08:16:12 -0700 | [diff] [blame] | 56 | layers/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 Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 57 | |
Tobin Ehlis | 6e6aa1f | 2014-12-18 10:32:57 -0700 | [diff] [blame] | 58 | ### Check parameters |
Mark Lobodzinski | 0d054fe | 2015-12-30 08:16:12 -0700 | [diff] [blame] | 59 | layers/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 Goeltzenleuchter | 0e1c970 | 2015-09-28 15:13:45 -0600 | [diff] [blame] | 60 | |
Tobin Ehlis | f3fad35 | 2015-10-01 15:26:33 -0600 | [diff] [blame] | 61 | ### Image parameters |
Mark Lobodzinski | 0d054fe | 2015-12-30 08:16:12 -0700 | [diff] [blame] | 62 | layers/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 Ehlis | 6e6aa1f | 2014-12-18 10:32:57 -0700 | [diff] [blame] | 63 | |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 64 | ### Check threading |
Mark Lobodzinski | 0d054fe | 2015-12-30 08:16:12 -0700 | [diff] [blame] | 65 | <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 Goeltzenleuchter | 0e1c970 | 2015-09-28 15:13:45 -0600 | [diff] [blame] | 66 | |
| 67 | ### Swapchain |
Mark Lobodzinski | 0d054fe | 2015-12-30 08:16:12 -0700 | [diff] [blame] | 68 | <build dir>/layer/swapchain.cpp (name=VK_LAYER_LUNARG_swapchain) - Check that WSI extensions are being used correctly. |
Courtney Goeltzenleuchter | 0e1c970 | 2015-09-28 15:13:45 -0600 | [diff] [blame] | 69 | |
Tobin Ehlis | f3fad35 | 2015-10-01 15:26:33 -0600 | [diff] [blame] | 70 | ### Device Limitations |
Mark Lobodzinski | 0d054fe | 2015-12-30 08:16:12 -0700 | [diff] [blame] | 71 | layers/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 Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 72 | |
Jon Ashburn | a5817d5 | 2014-11-26 13:27:04 -0700 | [diff] [blame] | 73 | ## Using Layers |
| 74 | |
Tobin Ehlis | f3fad35 | 2015-10-01 15:26:33 -0600 | [diff] [blame] | 75 | 1. Build VK loader and i965 icd driver using normal steps (cmake and make) |
Mark Lobodzinski | 0d054fe | 2015-12-30 08:16:12 -0700 | [diff] [blame] | 76 | 2. Place libVkLayer_<name>.so in the same directory as your VK test or app: |
Jens Owen | 763b76e | 2014-12-18 14:36:31 -0700 | [diff] [blame] | 77 | |
Mark Lobodzinski | 0d054fe | 2015-12-30 08:16:12 -0700 | [diff] [blame] | 78 | cp build/layer/libVkLayer_basic.so build/layer/libVkLayer_generic.so build/tests |
Jon Ashburn | 649d871 | 2014-12-18 17:26:52 -0700 | [diff] [blame] | 79 | |
Jon Ashburn | 12afc87 | 2015-07-23 10:59:21 -0600 | [diff] [blame] | 80 | This is required for the Loader to be able to scan and enumerate your library. |
Courtney Goeltzenleuchter | 0e1c970 | 2015-09-28 15:13:45 -0600 | [diff] [blame] | 81 | Alternatively, use the VK\_LAYER\_PATH environment variable to specify where the layer libraries reside. |
Jens Owen | 763b76e | 2014-12-18 14:36:31 -0700 | [diff] [blame] | 82 | |
Cody Northrop | 6dfa279 | 2015-11-23 13:52:26 -0700 | [diff] [blame] | 83 | 3. 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 | |
| 87 | 4. Specify which Layers to activate by using |
Jon Ashburn | 12afc87 | 2015-07-23 10:59:21 -0600 | [diff] [blame] | 88 | vkCreateDevice and/or vkCreateInstance or environment variables. |
Jens Owen | 763b76e | 2014-12-18 14:36:31 -0700 | [diff] [blame] | 89 | |
Mark Lobodzinski | 0d054fe | 2015-12-30 08:16:12 -0700 | [diff] [blame] | 90 | 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 Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 92 | cd build/tests; ./vkinfo |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 93 | |
Jon Ashburn | a5817d5 | 2014-11-26 13:27:04 -0700 | [diff] [blame] | 94 | ## Tips for writing new layers |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 95 | |
Jon Ashburn | 12afc87 | 2015-07-23 10:59:21 -0600 | [diff] [blame] | 96 | 1. Must implement vkGetInstanceProcAddr() (aka GIPA) and vkGetDeviceProcAddr() (aka GDPA); |
Tobin Ehlis | f3fad35 | 2015-10-01 15:26:33 -0600 | [diff] [blame] | 97 | 2. Must have a local dispatch table to call next layer (see vk_layer.h); |
Jon Ashburn | 12afc87 | 2015-07-23 10:59:21 -0600 | [diff] [blame] | 98 | 3. Must have a layer manifest file for each Layer library for Loader to find layer properties (see loader/README.md) |
Tobin Ehlis | f3fad35 | 2015-10-01 15:26:33 -0600 | [diff] [blame] | 99 | 4. Next layers GXPA can be found in the wrapped instance or device object; |
| 100 | 5. Loader calls a layer's GXPA first so initialization should occur here; |
Jon Ashburn | 12afc87 | 2015-07-23 10:59:21 -0600 | [diff] [blame] | 101 | 6. all entrypoints can be wrapped but only will be called after layer is activated |
| 102 | via the first vkCreatDevice or vkCreateInstance; |
| 103 | 7. entrypoint names can be any name as specified by the layers vkGetXXXXXProcAddr |
| 104 | implementation; exceptions are vkGetXXXXProcAddr, |
Jon Ashburn | a5817d5 | 2014-11-26 13:27:04 -0700 | [diff] [blame] | 105 | which must have the correct name since the Loader calls these entrypoints; |
Jon Ashburn | 12afc87 | 2015-07-23 10:59:21 -0600 | [diff] [blame] | 106 | 8. entrypoint names must be exported to the OSes dynamic loader with VK\_LAYER\_EXPORT; |
Mark Lobodzinski | 0d054fe | 2015-12-30 08:16:12 -0700 | [diff] [blame] | 107 | 9. Layer naming convention is camel case same name as in library: libVkLayer_<name>.so |
Jon Ashburn | 12afc87 | 2015-07-23 10:59:21 -0600 | [diff] [blame] | 108 | 10. For multiple layers in one library the manifest file can specify each layer. |
Jon Ashburn | a5817d5 | 2014-11-26 13:27:04 -0700 | [diff] [blame] | 109 | |
| 110 | ## Status |
| 111 | |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 112 | |
Jon Ashburn | a5817d5 | 2014-11-26 13:27:04 -0700 | [diff] [blame] | 113 | ### Current known issues |
| 114 | |
Mark Lobodzinski | 186c493 | 2015-11-30 08:37:47 -0700 | [diff] [blame] | 115 | - Layers with multiple layers per library: the manifest file parsing in Loader doesn't yet handle this |
Jon Ashburn | 12afc87 | 2015-07-23 10:59:21 -0600 | [diff] [blame] | 116 | - multi.cpp Layer needs rewrite to allow manifest file to specify multiple layers |
Mark Lobodzinski | 186c493 | 2015-11-30 08:37:47 -0700 | [diff] [blame] | 117 | - multi1 and multi2 layers from multi.cpp: only multi1 layer working |