Skip to content

Latest commit

 

History

History
252 lines (194 loc) · 10.6 KB

File metadata and controls

252 lines (194 loc) · 10.6 KB
title Announcing Rust GPU 0.10
slug rust-gpu-0.10
tags
announcement
release
draft true

Announcing Rust GPU 0.10

The Rust GPU maintainers are happy to announce a new version of Rust GPU, 0.10. Rust GPU makes it possible to write and run GPU software in Rust.

This release is our first as a community-owned project. One of our goals is to move releases to a more frequent and rapid pace—the last release was on July 25, 2023!

We're eager to add more users and contributors. To follow along or get involved, check out the rust-gpu repo on GitHub.

What's new in 0.10

Updated Rust requirement to a modern version

Rust GPU includes a compiler backend that compiles regular Rust code into SPIR-V, a low-level format that most GPUs understand. Because of this deep integration with compiler internals, Rust GPU must use a very specific version of the Rust compiler. Rust GPU now supports nightly-2024-11-22 (up from the ancient nightly-2023-05-27). This roughly corresponds to Rust 1.83.

:::tip

Most real-world projects like krnl and renderling compile their GPU code with Rust GPU's specific version of nightly while using stable Rust for the rest of their code. We are in the process of making this workflow much easier.

:::

Updating to a newer nightly version required heroic effort from @eddyb, as significant breaking changes to Rust's internal allocation model and #[repr(simd)] were introduced in rustc. @eddyb was able to vendor in parts of rustc and patch out others, unblocking the update and buying us time to figure out the best way forward.

Rust GPU is an "out-of-tree" compiler backend. This enables fast iteration while we explore the problem space, but also makes us more susceptible to this sort of breakage. One of our long-term goals is to be a supported rustc backend.

Mesh shader support

Rust GPU maintainer @Firestar99 and contributor @BeastLe9enD added support for mesh shaders.

Mesh shaders are a modern GPU feature that replace traditional vertex and geometry shaders. They give GPU developers more control over the entire pipeline by letting them directly process batches of vertices and primitives in compute-like shaders. This allows for more efficient culling, level-of-detail calculations, and custom pipeline logic—all on the GPU.

An example of a Rust GPU mesh shader that outputs a triangle:

use spirv_std::arch::set_mesh_outputs_ext;
use spirv_std::glam::{UVec3, Vec4};
use spirv_std::spirv;

#[spirv(mesh_ext(
    threads(1),
    output_vertices = 3,
    output_primitives_ext = 1,
    output_triangles_ext
))]
pub fn main(
    #[spirv(position)] positions: &mut [Vec4; 3],
    #[spirv(primitive_triangle_indices_ext)] indices: &mut [UVec3; 1],
) {
    unsafe {
        set_mesh_outputs_ext(3, 1);
    }

    positions[0] = Vec4::new(-0.5, 0.5, 0.0, 1.0);
    positions[1] = Vec4::new(0.5, 0.5, 0.0, 1.0);
    positions[2] = Vec4::new(0.0, -0.5, 0.0, 1.0);

    indices[0] = UVec3::new(0, 1, 2);
}

An example of a Rust GPU task shader launching mesh shaders with a dispatch size of [1, 2, 3]:

use spirv_std::arch::emit_mesh_tasks_ext;
use spirv_std::spirv;

#[spirv(task_ext(threads(1)))]
pub fn main() {
    unsafe {
        emit_mesh_tasks_ext(1, 2, 3);
    }
}

Subgroup support

@Firestar99 also added support for subgroups via subgroup intrinsics.

Subgroups allow a group of threads of vendor-defined size to share data and perform synchronized operations more efficiently. For example, using subgroup intrinsics you can:

  • Perform reductions (e.g., sum, min, max) across threads in a subgroup.
  • Share intermediate results without relying on global memory, reducing latency.
  • Implement algorithms like prefix sums or parallel sorting more effectively.

Added TypedBuffer

@eddyb and @Firestar99 introduced TypedBuffer, an explicit way to declare inputs and outputs as buffers. This enables declaring an "array of buffer descriptors containing something" as is common in bindless.

Here is an example of using TypedBuffer in a fragment shader:

use glam::Vec4;
use spirv_std::TypedBuffer;
use spirv_std::spirv;

#[spirv(fragment)]
pub fn main(
    #[spirv(storage_buffer, descriptor_set = 0, binding = 0)] single: &TypedBuffer<Vec4>,
    #[spirv(storage_buffer, descriptor_set = 0, binding = 1)] single_mut: &mut TypedBuffer<Vec4>,
) {
    **single_mut = **single;
}

Read-only buffer support for ByteAddressableBuffer

Thanks to @Firestar99, ByteAddressableBuffer now supports reading from read-only buffers. Previously the buffers needed to be read-write. Using read-only buffers can improve performance for immutable data.

Dependency updates

We updated key GPU dependencies like glam. One of the unique benefits of Rust on the GPU is that we use the exact glam crate from crates.io, so this was a simple Cargo.toml update.

Additionally, examples now use the latest versions of CPU-side crates such as ash and wgpu.

Other related changes

SPIR-V atomics in wgpu

Rust GPU maintainer @schell added SPIR-V atomic support to wgpu. This was part of his work on renderling, a project built with Rust GPU. The change enables Rust GPU programs to use atomics and integrate with CPU-side code managed by wgpu. Funding came from a grant by NLnet.

Rustlantis integration

@FractalFir created rustc_codegen_clr, an experimental Rust compiler backend that converts Rust into .NET assemblies or C source files. He adapted Rustlantis, a MIR fuzzer for generating complex test programs, to support his project.

When Rust GPU maintainers asked if the changes could help Rust GPU, @FractalFir took the extra step of updating his Rustlantis fork to support it as well. This collaboration has already uncovered three issues in Rust GPU. We plan to continue investing in Rustlantis support to improve automated testing and actively hunt for bugs.

Updated Shadertoy shaders

Rust GPU maintainer @LegNeato updated previously ported Shadertoy shaders to work with the latest release. In doing so, he fixed several issues in wgpu and naga.

He wrote a blog post about his experience that was popular on Reddit and Hacker News.

New website

@LegNeato also created a new website for the project using Docusaurus. He created custom Docusaurus plugins and components to better support the project's needs. Finally, he wrote a blog post about optimizing a Rust GPU matmul kernel that was popular on Reddit and Hacker News.

Community

Thank you to the 16 community contributors, most of whom contributed for the first time:

@BeastLe9enD, beef (@fee1-dead), Brice Videau (@Kerilk) Bruce Mitchener (@waywardmonkeys), @FractalFir, @doomdagadiggiedahdah, Fredrik Fornwall (@fornwall), Gray Olson (@fu5ha), Jake Shadle (@Jake-Shadle), Jörg Wollenschläger (@jwollen), Julian Knodt (@JulianKnodt), Léo Gaspard (@Ekleog), Rowan Jones (@ArrEssJay), Marek Bernat (@mbernat), Viktor Zoutman (@VZout), @Zanciks

We're especially grateful that @Zanciks chose Rust GPU for their first ever open source contribution!

Maintainers

As previously announced, Rust GPU has four active maintainers who contributed to this release (in alphabetical order):

  1. Christian Legnitto (@LegNeato)
  2. Eduard-Mihai Burtescu (@eddyb)
  3. @Firestar99
  4. Schell Carl Scivally (@schell)

We're always looking for active contributors to become new maintainers. Join us and make an impact!