-
Notifications
You must be signed in to change notification settings - Fork 186
Getting Started
This section will show you how to get the necessary dependencies for running the examples included in wgpu-rs.
The project requires
- The rust compiler (installation instructions)
- Drivers for your graphics card. Note that some platforms have multiple possible driver backends (e.g. Dx12 or Vulkan on Windows).
- git (installation instructions)
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
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
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.