wgpu/documentation/debugging/vulkan_validation_layers.rs
1/*!
2# Enabling Vulkan Validation Layers
3
4When developing an application it is often useful to enable Vulkan's
5validation layers. They can catch errors when you are using the API
6incorrectly or exceeding device limits. You can read more about validation
7layers here: <https://gpuopen.com/using-the-vulkan-validation-layers/>.
8
9Validation layers are a Vulkan-only feature, so they cannot be used with
10other backends. You can restrict which backends `wgpu` uses via
11[`InstanceDescriptor`] and [`Backends`].
12
13## Installation
14
15For validation layers to work you need to install the Vulkan SDK:
16
17### Linux
18
19Visit <https://packages.lunarg.com/> to install the Vulkan SDK along with
20some validation layers. Click the "Latest Supported Release" button (which
21looks like it's just a header, but it is in fact a button) and follow the
22instructions.
23
24### Other operating systems
25
26TODO.
27
28## Enabling validation layers
29
30`wgpu` enables validation layers automatically in most cases when the
31application is compiled in debug mode (that is, if the `--release` flag is
32*not* passed to `cargo`), because [`InstanceFlags::DEBUG`] is set by default
33in development builds. You can also enable them explicitly with
34[`InstanceFlags::VALIDATION`], or by setting the environment variable
35`VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`.
36
37The validation layers use normal Rust logging functionality, which also
38needs to be enabled. The `wgpu` examples use the
39[`env_logger`](https://crates.io/crates/env_logger) crate for logging, which
40means you can enable validation-layer logging by setting an environment
41variable:
42
43```bash
44env RUST_LOG=trace cargo run --bin wgpu-examples cube
45```
46
47There are several logging levels (see <https://docs.rs/log/latest/log/> for
48more info), with `trace` being the highest. If you choose a lower level such
49as `info`, then fewer messages will be logged.
50
51If you want to enable validation layers in your own application, make sure
52it has logging configured. The
53[`env_logger`](https://crates.io/crates/env_logger) crate is one possible
54way to do this.
55*/
56
57use crate::{Backends, InstanceDescriptor, InstanceFlags};