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-gpuis the added ability to infer storage class types. This removes the need to call.load/.storeon the storage class types, and allows you to useDeref/DerefMutto manipulate the inner type directly. This a huge improvementrust-gpuergonomics, as well leading to more efficient code being generated with the removal of unneededOpLoads andOpStores 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
constarguments toasm!. rustc_codegen_spirvwill now remove differentOpNames that target the same ID. This should reduce the size of the generated SPIR-V binaries.rustc_codegen_spirvwill now try to deduplicate generatedOpVariables. This fixes certain issues with compiling rust-gpu SPIR-V on Android platforms.- You can now set
entry_point_namein 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_spirvto annotate all loops inside withUnroll.
spirv-std
- Added a new
archmodule 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::StorageImage2dwhich is an image designed be read/written to without aSampler. - Added the
spirv-std-macroscrate for holding thespirvproc macro which acts as dummy macro to allow to use thespirvattribute on CPU code (has no affect on CPU code). - Added the
gpu_onlyproc 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
discardanddemote_to_helper_invocationfunctions. Which correspond todiscardin GLSL and HLSL respectively. Derivativeis now implemented forglam::{Vec2, Vec3, Vec3A, Vec4}.- Added the
SampledImagetype, which is an image already combined with a sampler.
spirv-builder
- You can now build your shaders in
releasemode with--releaseor withSpirvBuilder::release - If you're using
spirv-builderin your build script, you can add the following to yourCargo.tomlto 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! 🎉
