Building Rust-GPU
Getting started
-
Clone the repository.
git clone --recurse-submodules https://github.com/EmbarkStudios/rust-gpu
-
optional Install SPIRV-Tools and add it to your
PATH
. You can skip this step if you just want to run examples with the defaults. See Using installed SPIRV-Tools if you decide to go with this option. -
Next, look at the examples folder. There are two kinds of targets here: [runners] and [shaders]. The projects inside
shaders
are "GPU crates", i.e. ones that will be compiled to one or more SPIR-V modules. Therunner
projects are normal, CPU crates that use some graphics backend (currently, we have awgpu
runner, a Vulkan runner throughash
, and a barebones pure software CPU runner) to actually run one of the "GPU crate" shaders.Run the example:
cargo run --bin example-runner-wgpu
This will build
rustc_codegen_spirv
, the compiler, then use that compiler to buildsky-shader
into a SPIR-V module, then finally, build awgpu
sample app (modified fromwgpu
's examples) using the built SPIR-V module to display the shader in a window.
Prerequisite linux packages recommended to install before building Rust-GPU
You may need the development version (i.e. headers/etc. included) of some packages in some distributions to be able to
build the examples - specifically, x11 and libxkbcommon, as well as gcc/clang with c++ support. These packages may be
called (fedora) libX11-devel
, libxkbcommon-x11-devel
, and gcc-c++
, or (ubuntu) libxkbcommon-x11-dev
,
libx11-dev
, and gcc
.
Using installed SPIRV-Tools
By default, all of the crates and examples in this repo will compile the spirv-tools-sys
crate, including a lot of C++ code from SPIRV-Tools. If you don't want to build the C++ code because you already have SPIRV-Tools installed, or just don't want to spend more time compiling, you can build/run the crate with the use-installed-tools
feature.
cargo run \
--manifest-path examples/example-runner/Cargo.toml \
--features use-installed-tools \
--no-default-features
You should see warning: use-installed-tools feature on, skipping compilation of C++ code
during the compilation, but otherwise the build will function just the same as if you compiled the C++ code, with the exception that it will fail if you don't have SPIRV-Tools installed correctly.