Rust-GPU/rust-gpu
🐉 Making Rust a first-class language and ecosystem for GPU shaders 🚧
What it is
Rust‑GPU is an open‑source project that lets you write GPU shaders in the Rust programming language. It provides a Rust compiler backend that translates Rust code into SPIR‑V, the binary format used by modern graphics APIs such as Vulkan (and potentially DirectX or WebGPU in the future). In practice you write normal Rust functions, annotate them with #[spirv(...)], and the toolchain compiles them into GPU‑executable shader modules that can be loaded from a Rust host application.
Why it matters
- Safety & ergonomics – Rust’s strong type system, ownership model and crate ecosystem give you compile‑time guarantees against out‑of‑bounds memory access, data races and many other bugs that are common in traditional shader languages (GLSL/HLSL).
- Code reuse – Because the same language is used on CPU and GPU, you can share math libraries, data structures and even logic between the two sides, reducing duplication and maintenance effort.
- Tooling – You get the full Rust toolchain (Cargo, Clippy, rust‑fmt, IDE support) for shader development, making debugging, testing and refactoring far easier than with ad‑hoc shader languages.
- Future‑proofing – The project is built as a Rust compiler backend, so it can evolve alongside the main Rust compiler and potentially target other GPU IRs (DXIL, WGSL) later on.
Who’s behind it
The effort started at Embark Studios, a game‑development studio that needed a better way to write GPU code. Embark contributed the initial implementation and now maintains the project in the open‑source community. Contributions are welcomed from anyone; the repo follows the Contributor Covenant and provides a guide for new contributors.
How to get started
- Read the book – The official “GPU guide” (linked in the README) walks you through installing the toolchain, setting up Cargo, and writing your first shader.
- Write a shader – Use normal Rust syntax and the
#[spirv(...)]attribute to mark entry points. The README shows a tiny fragment shader that renders a sky using the Preetham model. - Compile – The
rustc_codegen_spirvbackend is invoked viacargo(or directly withrustc -Z codegen-backend=rustc_codegen_spirv). It produces a.spvfile you can load with Vulkan. - Run examples – The repo includes a set of example shaders and a small host program to demonstrate usage.
Current maturity
The project is early‑stage. Simple shaders compile and run, and a large part of Rust’s core library is already supported, but many language features and standard library APIs are still missing. There is no formal stability guarantee yet; the main branch is the only supported version and breaking changes are expected.
Where to go next
- Follow the discussion – GitHub Discussions and the Discord server are the primary places for help and roadmap talk.
- Contribute – Fix a missing API, improve documentation, or help with testing new back‑ends.
- Watch the ecosystem – As the compiler backend matures, more crates (e.g., math libraries like
glam) will become fully usable inside shaders, expanding what you can build on the GPU.
Rust‑GPU turns GPU shader development into a first‑class Rust experience, bringing safety, modern tooling, and code‑sharing to graphics and compute programming.
Related
- Project
- Project
- Project
- Dispatch
- Project