xref: /aosp_15_r20/external/vulkan-validation-layers/layers/README.md (revision b7893ccf7851cd6a48cc5a1e965257d8a5cdcc70)
1*b7893ccfSSadaf Ebrahimi# Layer Description and Status
2*b7893ccfSSadaf Ebrahimi
3*b7893ccfSSadaf Ebrahimi## Layer Library Interface
4*b7893ccfSSadaf Ebrahimi
5*b7893ccfSSadaf EbrahimiAll layer libraries must support the layer library interface defined in
6*b7893ccfSSadaf Ebrahimi[`LoaderAndLayerInterface.md`][].
7*b7893ccfSSadaf Ebrahimi
8*b7893ccfSSadaf Ebrahimi[`LoaderAndLayerInterface.md`]: ../loader/LoaderAndLayerInterface.md#layer-library-interface
9*b7893ccfSSadaf Ebrahimi
10*b7893ccfSSadaf Ebrahimi## Overview
11*b7893ccfSSadaf Ebrahimi
12*b7893ccfSSadaf EbrahimiLayer libraries can be written to intercept or hook VK entry points for various
13*b7893ccfSSadaf Ebrahimidebug and validation purposes.  One or more VK entry points can be defined in your Layer
14*b7893ccfSSadaf Ebrahimilibrary.  Undefined entrypoints in the Layer library will be passed to the next Layer which
15*b7893ccfSSadaf Ebrahimimay be the driver.  Multiple layer libraries can be chained (actually a hierarchy) together.
16*b7893ccfSSadaf EbrahimivkEnumerateInstanceLayerProperties can be called to list the
17*b7893ccfSSadaf Ebrahimiavailable layers and their properties.  Layers can intercept all Vulkan commands
18*b7893ccfSSadaf Ebrahimithat take a dispatchable object as it's first argument. I.e.  VkInstance, VkPhysicalDevice,
19*b7893ccfSSadaf EbrahimiVkDevice, VkCommandBuffer, and VkQueue.
20*b7893ccfSSadaf EbrahimivkXXXXGetProcAddr is used internally by the Layers and Loader to initialize dispatch tables.
21*b7893ccfSSadaf EbrahimiLayers can also be activated via the VK_INSTANCE_LAYERS environment variable.
22*b7893ccfSSadaf Ebrahimi
23*b7893ccfSSadaf EbrahimiAll validation layers work with the DEBUG_REPORT extension to provide validation feedback.
24*b7893ccfSSadaf EbrahimiWhen a validation layer is enabled, it will look for a vk_layer_settings.txt file (see"Using
25*b7893ccfSSadaf EbrahimiLayers" section below for more details) to define its logging behavior, which can include
26*b7893ccfSSadaf Ebrahimisending output to a file, stdout, or debug output (Windows). Applications can also register
27*b7893ccfSSadaf Ebrahimidebug callback functions via the DEBUG_REPORT extension to receive callbacks when validation
28*b7893ccfSSadaf Ebrahimievents occur. Application callbacks are independent of settings in a vk_layer_settings.txt
29*b7893ccfSSadaf Ebrahimifile which will be carried out separately. If no vk_layer_settings.txt file is present and
30*b7893ccfSSadaf Ebrahimino application callbacks are registered, error messages will be output through default
31*b7893ccfSSadaf Ebrahimilogging callbacks.
32*b7893ccfSSadaf Ebrahimi
33*b7893ccfSSadaf Ebrahimi### Layer library example code
34*b7893ccfSSadaf Ebrahimi
35*b7893ccfSSadaf EbrahimiNote that some layers are code-generated and will therefore exist in the directory `(build_dir)/layers`
36*b7893ccfSSadaf Ebrahimi
37*b7893ccfSSadaf Ebrahimi`include/vkLayer.h` - header file for layer code.
38*b7893ccfSSadaf Ebrahimi
39*b7893ccfSSadaf Ebrahimi### Standard Validation
40*b7893ccfSSadaf EbrahimiNOTE: This meta-layer is being deprecated -- users should load the Khronos validation layer (name = `VK_LAYER_KHRONOS_validation`) in its place.
41*b7893ccfSSadaf EbrahimiThis 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 standard validation layer:  `VK_LAYER_KHRONOS_validation`. Other layers can be specified and the loader will remove duplicates.
42*b7893ccfSSadaf Ebrahimi
43*b7893ccfSSadaf Ebrahimi### The Khronos Validation Layer
44*b7893ccfSSadaf Ebrahimi
45*b7893ccfSSadaf EbrahimiThis layer emcompasses all of the functionality that used to be contained in the following layers: VK_LAYER_GOOGLE_threading, VK_LAYER_LUNARG_parameter_validation, VK_LAYER_LUNARG_object_tracker, VK_LAYER_LUNARG_core_validation, and VK_LAYER_GOOGLE_unique_objects. Each of these functional areas can still disabled individually, and are described below.
46*b7893ccfSSadaf Ebrahimi
47*b7893ccfSSadaf Ebrahimi### Object Validation and Statistics
48*b7893ccfSSadaf EbrahimiThe object lifetime tracking will track object creation, use, and destruction. As objects are created their handles are stored in a data structure. As objects are used the layer verifies they exist in the data structure and output errors for unknown objects. As objects are destroyed they are removed from the data structure. At `vkDestroyDevice()` and `vkDestroyInstance()` times, if any objects have not been destroyed they are reported as leaked objects. If a debug callback function is registered this layer will use callback function(s) for reporting, otherwise it will use stdout.
49*b7893ccfSSadaf Ebrahimi
50*b7893ccfSSadaf Ebrahimi### Validate API State and Shaders
51*b7893ccfSSadaf EbrahimiThe set of core checks 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 debug callback function is registered, this layer will use callback function(s) for reporting, otherwise uses stdout.  This layer also validates correct usage of image- and buffer-related APIs, including image and buffer parameters, formats, and correct use.
52*b7893ccfSSadaf Ebrahimi
53*b7893ccfSSadaf Ebrahimi### Stateless parameter checking
54*b7893ccfSSadaf EbrahimiThe stateless validation checks the input parameters to API calls for validity. If a debug callback function is registered, this layer will use callback function(s) for reporting otherwise uses stdout.
55*b7893ccfSSadaf Ebrahimi
56*b7893ccfSSadaf Ebrahimi### Thread Safety Checking
57*b7893ccfSSadaf EbrahimiThe thread-safety validation will check the 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 debug callback function is registered, this layer will use callback function(s) for reporting, otherwise uses stdout.
58*b7893ccfSSadaf Ebrahimi
59*b7893ccfSSadaf Ebrahimi### Handle Wrapping
60*b7893ccfSSadaf EbrahimiThe khronos layer framework also supports Vulkan handle wrapping.  The Vulkan specification allows objects to have non-unique handles. This makes tracking object lifetimes difficult in that it is unclear which object is being referenced on deletion. When this functionalty is enabled (as it is by default) it will alias all objects with a unique object representation, allowing proper object lifetime tracking. This functionality may interfere with the development of proprietary Vulkan extension development, and is not strictly required for the proper operation of validation. One sign that it is needed is the appearance of errors emitted from the object_tracker layer indicating the use of previously destroyed objects.
61*b7893ccfSSadaf Ebrahimi
62*b7893ccfSSadaf Ebrahimi## Using Layers
63*b7893ccfSSadaf Ebrahimi
64*b7893ccfSSadaf Ebrahimi1. Build VK loader using normal steps (cmake and make)
65*b7893ccfSSadaf Ebrahimi2. Place `libVkLayer_khronos_validation.so` in the same directory as your VK test or app:
66*b7893ccfSSadaf Ebrahimi
67*b7893ccfSSadaf Ebrahimi    `cp build/layer/libVkLayer_khronos_validation.so  build/tests`
68*b7893ccfSSadaf Ebrahimi
69*b7893ccfSSadaf Ebrahimi    This is required for the Loader to be able to scan and enumerate your library.
70*b7893ccfSSadaf Ebrahimi    Alternatively, use the `VK_LAYER_PATH` environment variable to specify where the layer libraries reside.
71*b7893ccfSSadaf Ebrahimi
72*b7893ccfSSadaf Ebrahimi3. To specify how your layers should behave, create a vk_layer_settings.txt file. This file can exist in the same directory as your app or in a directory given by the `VK_LAYER_SETTINGS_PATH` environment variable. Alternatively, you can use any filename you want if you set `VK_LAYER_SETTINGS_PATH` to the full path of the file, rather than the directory that contains it.
73*b7893ccfSSadaf Ebrahimi
74*b7893ccfSSadaf Ebrahimi    Model the file after the following example:  [*vk_layer_settings.txt*](vk_layer_settings.txt)
75*b7893ccfSSadaf Ebrahimi
76*b7893ccfSSadaf Ebrahimi4. Specify which layers to activate using environment variables.
77*b7893ccfSSadaf Ebrahimi
78*b7893ccfSSadaf Ebrahimi    `export VK\_INSTANCE\_LAYERS=VK\_LAYER\_KHRONOS\_validation`
79*b7893ccfSSadaf Ebrahimi    `cd build/tests; ./vkinfo`
80*b7893ccfSSadaf Ebrahimi
81*b7893ccfSSadaf Ebrahimi
82*b7893ccfSSadaf Ebrahimi## Status
83*b7893ccfSSadaf Ebrahimi
84*b7893ccfSSadaf Ebrahimi
85*b7893ccfSSadaf Ebrahimi### Current known issues
86*b7893ccfSSadaf Ebrahimi
87