1<!-- markdownlint-disable MD041 -->
2<!-- Copyright 2015-2021 LunarG, Inc. -->
3[![Khronos Vulkan][1]][2]
4
5[1]: https://vulkan.lunarg.com/img/Vulkan_100px_Dec16.png "https://www.khronos.org/vulkan/"
6[2]: https://www.khronos.org/vulkan/
7
8# Best Practices Validation
9
10Best Practices Validation
11
12Best Practices Validation is implemented in the `VK_LAYER_KHRONOS_validation layer`. When enabled, the Best Practices Object is
13intended to highlight potential performance issues, questionable usage patterns, common mistakes, and items not specifically prohibited
14by the Vulkan specification but that may lead to application problems.
15
16Best Practices will ideally be run periodically along with normal validation checks so that issues may be addressed in early stages of development.
17
18Best Practices can easily be enabled and configured using the [Vulkan Configurator](https://vulkan.lunarg.com/doc/sdk/latest/windows/vkconfig.html) included with the Vulkan SDK. Or you can manually enable and configure the Best Practices by following the directions below.
19
20The specific areas covered by this layer are currently tracked in the
21[Best Practices Project](https://github.com/KhronosGroup/Vulkan-ValidationLayers/projects/1).
22Requests for additional checks can be requested by creating a Github issue.
23
24## Enabling Best Practices Validation
25
26Best Practices Validation is disabled by default. To turn on Best Practices validation, add the following to your layer settings file,
27`vk_layer_settings.txt`:
28
29```code
30khronos_validation.enables = VK_VALIDATION_FEATURE_ENABLE_BEST_PRACTICES_EXT
31```
32
33To enable using environment variables, set the following variable:
34
35```code
36VK_LAYER_ENABLES=VK_VALIDATION_FEATURE_ENABLE_BEST_PRACTICES_EXT
37```
38
39To additionally enable the ARM-specific best practices checks, use the following:
40
41```code
42khronos_validation.enables = VK_VALIDATION_FEATURE_ENABLE_BEST_PRACTICES_EXT,VALIDATION_CHECK_ENABLE_VENDOR_SPECIFIC_ARM
43```
44
45 - or the environment variables for Windows
46
47```code
48VK_LAYER_ENABLES=VK_VALIDATION_FEATURE_ENABLE_BEST_PRACTICES_EXT;VALIDATION_CHECK_ENABLE_VENDOR_SPECIFIC_ARM
49```
50
51 - or for Linux -
52
53```code
54VK_LAYER_ENABLES=VK_VALIDATION_FEATURE_ENABLE_BEST_PRACTICES_EXT:VALIDATION_CHECK_ENABLE_VENDOR_SPECIFIC_ARM
55```
56
57Similarly to enable the AMD-specific best pratices checks, use the following:
58
59```code
60khronos_validation.enables = VK_VALIDATION_FEATURE_ENABLE_BEST_PRACTICES_EXT,VALIDATION_CHECK_ENABLE_VENDOR_SPECIFIC_AMD
61```
62
63 - or the environment variables for Windows
64
65```code
66VK_LAYER_ENABLES=VK_VALIDATION_FEATURE_ENABLE_BEST_PRACTICES_EXT;VALIDATION_CHECK_ENABLE_VENDOR_SPECIFIC_AMD
67```
68
69 - or for Linux -
70
71```code
72VK_LAYER_ENABLES=VK_VALIDATION_FEATURE_ENABLE_BEST_PRACTICES_EXT:VALIDATION_CHECK_ENABLE_VENDOR_SPECIFIC_AMD
73```
74
75To enable all vendor-specific checks, use:
76
77```code
78khronos_validation.enables = VK_VALIDATION_FEATURE_ENABLE_BEST_PRACTICES_EXT,VALIDATION_CHECK_ENABLE_VENDOR_SPECIFIC_ALL
79```
80
81 - or the environment variables for Windows
82
83```code
84VK_LAYER_ENABLES=VK_VALIDATION_FEATURE_ENABLE_BEST_PRACTICES_EXT;VALIDATION_CHECK_ENABLE_VENDOR_SPECIFIC_ALL
85```
86
87 - or for Linux -
88
89```code
90VK_LAYER_ENABLES=VK_VALIDATION_FEATURE_ENABLE_BEST_PRACTICES_EXT:VALIDATION_CHECK_ENABLE_VENDOR_SPECIFIC_ALL
91```
92
93Some platforms do not support configuration of the validation layers with this configuration file.
94Programs running on these platforms must then use the programmatic interface.
95
96### Enabling and Specifying Options with the Programmatic Interface
97
98The `VK_EXT_validation_features` extension can be used to enable Best Practices Validation at CreateInstance time.
99
100Here is sample code illustrating how to enable it:
101
102```code
103VkValidationFeatureEnableEXT enables[] = {VK_VALIDATION_FEATURE_ENABLE_BEST_PRACTICES_EXT};
104VkValidationFeaturesEXT features = {};
105features.sType = VK_STRUCTURE_TYPE_VALIDATION_FEATURES_EXT;
106features.enabledValidationFeatureCount = 1;
107features.pEnabledValidationFeatures = enables;
108
109VkInstanceCreateInfo info = {};
110info.pNext = &features;
111```
112