Skip to content
This repository has been archived by the owner on Jun 18, 2021. It is now read-only.

Getting Started

Connor Fitzgerald edited this page Jul 19, 2020 · 1 revision

Running the examples

This section will show you how to get the necessary dependencies for running the examples included in wgpu-rs.

Dependencies

The project requires

Cloning

When you have installed the tools above then you can clone this repository

git clone https://github.com/gfx-rs/wgpu-rs.git
cd wgpu-rs

Running the examples

You can run the examples using the --example flag for cargo.

# Show a list of all examples
cargo run --example

# Run the cube example
cargo run --example cube

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

Installation

For validation layers to work you need to install the Vulkan SDK:

Linux

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.

Other operating systems

TODO

Enabling validation layers

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.