layers: Update docs for shared utils DLL
[platform/upstream/Vulkan-Tools.git] / layers / README.md
1 # Layer Description and Status
2
3 ## Layer Library Interface
4
5 All layer libraries must support the layer library interface defined in
6 [`LoaderAndLayerInterface.md`][].
7
8 [`LoaderAndLayerInterface.md`]: ../loader/LoaderAndLayerInterface.md#layer-library-interface
9
10 ## Overview
11
12 Layer libraries can be written to intercept or hook VK entry points for various
13 debug and validation purposes.  One or more VK entry points can be defined in your Layer
14 library.  Undefined entrypoints in the Layer library will be passed to the next Layer which
15 may be the driver.  Multiple layer libraries can be chained (actually a hierarchy) together.
16 vkEnumerateInstanceLayerProperties can be called to list the
17 available layers and their properties.  Layers can intercept all Vulkan commands
18 that take a dispatchable object as it's first argument. I.e.  VkInstance, VkPhysicalDevice,
19 VkDevice, VkCommandBuffer, and VkQueue.
20 vkXXXXGetProcAddr is used internally by the Layers and Loader to initialize dispatch tables.
21 Layers can also be activated via the VK_INSTANCE_LAYERS environment variable.
22
23 All validation layers work with the DEBUG_REPORT extension to provide validation feedback.
24 When a validation layer is enabled, it will look for a vk_layer_settings.txt file to define
25 its loggin behavior, which can include sending output to a file, stdout, or debug output (Windows).
26 Applications can also register debug callback functions via the DEBUG_REPORT extension to receive
27 callbacks when validation events occur. Application callbacks are independent of settings in a
28 vk_layer_settings.txt file which will be carried out separately. If no vk_layer_settings.txt
29 file is present and no application callbacks are registered, error messages will be output
30 through default logging callbacks.
31
32 ### Layer library example code
33
34 Note that some layers are code-generated and will therefore exist in the directory `(build_dir)/layers`
35
36 `include/vkLayer.h` - header file for layer code.
37
38 ### Layer Details
39 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.
40
41 ### Standard Validation
42 This is a meta-layer managed by the loader. (name = `VK_LAYER_LUNARG_standard_validation`) - specifying this layer name will cause the loader to load the all of the standard validation layers (listed below) in the following optimal order:  `VK_LAYER_GOOGLE_threading`, `VK_LAYER_LUNARG_parameter_validation`, `VK_LAYER_LUNARG_device_limits`, `VK_LAYER_LUNARG_object_tracker`, `VK_LAYER_LUNARG_image`, `VK_LAYER_LUNARG_core_validation`,` VK_LAYER_LUNARG_swapchain`, and `VK_LAYER_GOOGLE_unique_objects`. Other layers can be specified and the loader will remove duplicates.
43
44 ### Object Validation and Statistics
45 (build dir)/layers/object_tracker.cpp (name=`VK_LAYER_LUNARG_object_tracker`) - Track object creation, use, and destruction. As objects are created they are 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 are 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 it will use stdout.
46
47 ### Validate API State and Shaders
48 layers/core\_validation.cpp (name=`VK_LAYER_LUNARG_core_validation`) - The core\_validation layer does the bulk of the API validation that requires storing state. Some of the state it tracks includes the Descriptor Set, Pipeline State, Shaders, and dynamic state, and memory objects and bindings. It performs some point validation as states are created and used, and further validation Draw call and QueueSubmit time. Of primary interest is making sure that the resources bound to Descriptor Sets correctly align with the layout specified for the Set. Also, all of the image and buffer layouts are validated to make sure explicit layout transitions are properly managed. Related to memory, core\_validation includes tracking object bindings, memory hazards, and memory object lifetimes. It also validates several other hazard-related issues related to command buffers, fences, and memory mapping. Additionally core\_validation include shader validation (formerly separate shader\_checker 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.
49
50 ### Check parameters
51 layers/parameter_validation.cpp (name=`VK_LAYER_LUNARG_parameter_validation`) - 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.
52
53 ### Image Validity
54 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.
55
56 ### Check threading
57 layers/threading.cpp (name=`VK_LAYER_GOOGLE_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.
58
59 ### Swapchain
60 layers/swapchain.cpp (name=`VK_LAYER_LUNARG_swapchain`) - Check that WSI extensions are being used correctly.
61
62 ### Device Limitations
63 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.
64
65 ### Unique Objects
66 (build dir)/layers/unique_objects.cpp (name=`VK_LAYER_GOOGLE_unique_objects`) - The Vulkan specification allows objects that have non-unique handles. This makes tracking object lifetimes difficult in that it is unclear which object is being referenced on deletion. The unique_objects layer was created to address this problem. If loaded in the correct position (last, which is closest to the display driver) it will alias all objects with a unique object representation, allowing proper object lifetime tracking. This layer does no validation on its own and may not be required for the proper operation of all layers or all platforms. One sign that it is needed is the appearance of errors emitted from the object_tracker layer indicating the use of previously destroyed objects.
67
68 ## Using Layers
69
70 1. Build VK loader using normal steps (cmake and make)
71 2. Place `libVkLayer_<name>.so` or `VkLayer_<name>.dll` in the same directory as your VK test or app:
72
73     `cp build/layers/libVkLayer_threading.so  build/tests`    -or-
74     `copy build\layers/VkLayer_threading.dll build\tests`
75
76     This is required for the Loader to be able to scan and enumerate your library.
77     Alternatively, use the `VK_LAYER_PATH` environment variable to specify where the layer libraries reside.
78
79     [Windows Only] The VkLayer_utils.dll will also need to be copied into your app directory or to your
80                    system library directory (typically \Windows\System32).
81
82 3. Create a vk_layer_settings.txt file in the same directory to specify how your layers should behave.
83
84     Model it after the following example:  [*vk_layer_settings.txt*](vk_layer_settings.txt)
85
86 4. Specify which layers to activate using environment variables.
87
88     `export VK\_INSTANCE\_LAYERS=VK\_LAYER\_LUNARG\_parameter\_validation:VK\_LAYER\_LUNARG\_core\_validation`
89     `cd build/tests; ./vkinfo`
90
91
92 ## Status
93
94
95 ### Current known issues
96