An example project on how to integrate rust-gpu with vulkano. It based on vulkano's image example but the glsl shaders are replaced with rust-gpu shaders.
This example is currently based on vulkano v0.34 and rust-gpu v0.9.
These are the important bits to take a look at:
- root Cargo.toml contains important configuration for the entire workspace. Most notably
resolver = "2"
for dependency resolution and enabling optimizations for build scripts, so that rust-gpu doesn't take forever to compile shaders. - example's Cargo.toml contains next to the vulkano dependency also a
[build-dependency]
block declaring a dependency on the rust-gpu compilerspirv-builder
. Additionally, we declare two features, to tell the builder to either use your locally installedspirv-tools
, that come with the Vulkan SDK, or to build them itself which may take several minutes. It also contains theuse-glsl-shader
feature by which one can switch between the original glsl and rust-gpu shaders. - example contains the CPU code and as mentioned above is based on the image example of vulkano. Commit e2719349 contains all changes done to the file, notably:
- moved
shader!
macros to a separate mod shaders, where also theshader!
macros for rust-gpu shaders reside. - Instead of searching for the entry point called "main", assume there is just one entry point and use that. Rust-gpu names the entry point after the module declaration of your entry point function.
- added required device feature
vulkan_memory_model
by rust-gpu
- moved
- example's build script invokes rust-gpu to compile the rust shaders to SPIR-V shader binaries (.spv). Feel free to add some codegen here.
- example-shaders's Cargo.toml must contain the
crate-type = ["dylib"]
declaration, otherwise no artifacts may be produced. It also depends on thespirv-std
which version must match that of thespirv-builder
. - the image shader can be found in the source of the
example-shader
project and is a direct port of the glsl shaders used in vulkano's image example. If you are looking for how specific in-builds are named or used, I'd recommend searching though rust-gpu's compile tests for examples.