-
Notifications
You must be signed in to change notification settings - Fork 931
Enabling validation layers for Vulkan
When developing an application it is often useful to enable Vulkan's validation layers. They can catch errors when you are using the API incorrectly or exceeding device limits. You can read more about validation layers here: https://gpuopen.com/using-the-vulkan-validation-layers/.
Validation layers are a Vulkan only feature, so they cannot be used with other backends. You can specify which backend that wgpu-rs uses in the parameters to the Adapter::request method
For validation layers to work you need to install the Vulkan SDK:
Visit https://packages.lunarg.com/ to install the vulkan sdk along with some validation layers. Click the 'Latest Supported Release' button (which looks like it's just a header, but it is in fact a button) and follow the instructions.
TODO
The wgpu library will enable validation layers automatically if the application is compiled in debug mode (that is if the --release
flag is not passed to cargo
) in most cases. You can also pass the environment variable VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation which will also enable validation layers.
The validation layers use normal rust logging functionality which also needs to be enabled:
The wgpu-rs examples use the env_logger crate for logging. This means you can enable validation layer logging by setting an environment variable.
env RUST_LOG=trace cargo run --example cube
There are several logging levels (see https://docs.rs/log/latest/log/ for more info), with trace
being the highest. If you choose a lower level such as info
then fewer messages will be logged.
If you want to enable validation layers in your own application, make sure that it has logging configured. The env_logger crate is one possible way to do this.