rust-gpu v0.6
Rust-gpu hot reloading in action using the rust-gpu plugin for Bevy
Hi there, and welcome to another release of rust-gpu
! Our project aimed at making Rust a first class language and ecosystem for GPU programming. You can read more about why we at Embark started this project in the original announcement.
For this version, the nightly has been updated to nightly-2023-01-21
, so make sure to update your rust-toolchain
file if you want to switch to version 0.6.0
. This nightly includes the Rust language features supported by Rust 1.68 released last week.
Image API
This release also contains the first part of a change to the Image
API, namely the removal of return type inference for the texture fetch functions. In a nutshell, because of the return type inference, the Rust compiler had to know the type where you store the result of a texture fetch. For most use cases, this implied that you had to specifically store the result in an explicitly typed variable before being able to do further computations on it, like so:
// You had to do this in 0.5.0 and before:
let s: Vec3 = texture.sample(uv);
let result = s.xy() * coefficients;
// Rather than this (this works starting from 0.6.0):
let result = texture.sample(uv).xy() * coefficients;
By removing the return type inference, the texture fetch functions, such as sample()
, always return a concrete glam
Vector type (typically a glam::Vec4
for unknown and floating point formats). However, in order to do this, we had to make the API less generic, and therefore remove support for user supplied vector library bindings. This also means that glam
has now become a non-optional dependency of spirv-std
, and you no longer need to add glam
as feature when depending on spirv-std
(in fact, you'll need to remove glam
if specified as feature).
If you were using your own vector library, then unfortunately this is a breaking change. You'll need to either switch to glam
, or manually convert to and from your vector type of choice. We may want to add support for other popular vector libraries in the future.
Code generation
Furthermore, we made the previously experimental shader IR framework SPIR-🇹 the default. Extensive testing has not resulted in any issues or performance degradation, and in fact this may improve the generated SPIR-V code of your shader. If you previously already opted in using --spirt
in the codegen args, you must remove the flag. On the other hand, if this change is causing you issues, you can opt out by specifying --no-spirt
(and please let us know by filing a new issue 🙏). You can do so in the RUSTGPU_CODEGEN_ARGS
environment variable, or using the new extra_arg()
function when invoking the SpirvBuilder
from code.
Community spotlight
A big shoutout to the developers of Bevy, and @Shfty in particular, for adding support for rust-gpu
to Bevy
. The above title image shows hot reloading of shaders written in rust-gpu
in the engine. Awesome work, and much appreciated for fast prototyping of rust-gpu
shaders! 🚀