rust-gpu v0.3
The Khronos Sci-Fi helmet model. glTF model viewer created by @msiglreith using rust-gpu
(Source)
Hello everyone, and welcome to the third 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.
We're still not publishing releases to crates.io or distributing artefacts for rust-gpu
, but we still wanted to highlight some of the changes that have been happening over the past couple of months. For more information on how to get started with using rust-gpu
in your projects, be sure to check out the Rust-GPU Dev Guide! You can always add a git dependency in cargo to access spirv-builder
.
[build-dependencies]
spirv-builder = { git = "https://github.com/EmbarkStudios/rust-gpu.git", branch = "main" }
While not a user facing feature, we are also proud to announce that we've also reached an important internal milestone in rust-gpu
. We've now completely rewritten our GLSL shaders in our internal Ark project with Rust thanks to the improvements in this release! 🎉
rustc_codegen_spirv
- The biggest change to
rust-gpu
is the added ability to infer storage class types. This removes the need to call.load/.store
on the storage class types, and allows you to useDeref/DerefMut
to manipulate the inner type directly. This a huge improvementrust-gpu
ergonomics, as well leading to more efficient code being generated with the removal of unneededOpLoad
s andOpStore
s when using large types.use spirv_std::{glam::{Vec4, vec2}, storage_class::{Input, Output}}; #[spirv(fragment)] pub fn main_fs( #[spirv(frag_coord)] in_frag_coord: Input<Vec4>, mut output: Output<Vec4>, ) { // Before let frag_coord = frag_coord.load(); output.store(black_box(vec2(frag_coord.x, frag_coord.y))); // Now *output = black_box(vec2(in_frag_coord.x, in_frag_coord.y)); }
- Initial support for Algebraic Data Type enums (e.g.
Option<T>
) has been added. This support is initially only provided for enums which have all scalar values in each variants (integers, floats, booleans). So for exampleOption<u32>
works, butOption<Struct>
doesn't work at the moment. - You no longer need add
#[allow(unused_attributes)]
in front of#[spirv]
attributes to remove warnings. - You can now provide
const
arguments toasm!
. rustc_codegen_spirv
will now remove differentOpName
s that target the same ID. This should reduce the size of the generated SPIR-V binaries.rustc_codegen_spirv
will now try to deduplicate generatedOpVariable
s. This fixes certain issues with compiling rust-gpu SPIR-V on Android platforms.- You can now set
entry_point_name
in entry point attributes to change the final name of an entry point. E.g.#[spirv(vertex(entry_point_name = "foo_bar"))]
- You can now add the
#[spirv(unroll_loops)]
attribute to functions, which tellsrustc_codegen_spirv
to annotate all loops inside withUnroll
.
spirv-std
- Added a new
arch
module which provides an abstraction some basic SPIR-V instructions as free functions. The first iteration includes two functions.vector_extract_dynamic
(OpVectorExtractDynamic
)vector_insert_dynamic
(OpVectorInsertDynamic
)
- Added
textures::StorageImage2d
which is an image designed be read/written to without aSampler
. - Added the
spirv-std-macros
crate for holding thespirv
proc macro which acts as dummy macro to allow to use thespirv
attribute on CPU code (has no affect on CPU code). - Added the
gpu_only
proc macro, which allows you to mark a function as only runnable on GPU, it will still generate a callable function on the CPU side, but it will cause a panic when called. - Added
discard
anddemote_to_helper_invocation
functions. Which correspond todiscard
in GLSL and HLSL respectively. Derivative
is now implemented forglam::{Vec2, Vec3, Vec3A, Vec4}
.- Added the
SampledImage
type, which is an image already combined with a sampler.
spirv-builder
- You can now build your shaders in
release
mode with--release
or withSpirvBuilder::release
- If you're using
spirv-builder
in your build script, you can add the following to yourCargo.toml
to improve build times.[profile.dev.build-override] opt-level = 3 [profile.release.build-override] opt-level = 3
Contributors
Thank you to all the contributors who helped make this release possible! 🎉