• Stars
    star
    6,796
  • Rank 5,523 (Top 0.2 %)
  • Language
    Rust
  • License
    Apache License 2.0
  • Created almost 4 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

๐Ÿ‰ Making Rust a first-class language and ecosystem for GPU shaders ๐Ÿšง

๐Ÿ‰ rust-gpu

Rust as a first-class language and ecosystem for GPU graphics & compute shaders

Embark Discord Documentation dependency status Build status

Current Status ๐Ÿšง

Note: This project is still heavily in development and is at an early stage.

Compiling and running simple shaders works, and a significant portion of the core library also compiles.

However, many things aren't implemented yet. That means that while being technically usable, this project is far from being production-ready. Support for specific features in Rust and SPIR-V are tracked on GitHub.

Example

Sky shader

use glam::{Vec3, Vec4, vec2, vec3};

#[spirv(fragment)]
pub fn main(
    #[spirv(frag_coord)] in_frag_coord: &Vec4,
    #[spirv(push_constant)] constants: &ShaderConstants,
    output: &mut Vec4,
) {
    let frag_coord = vec2(in_frag_coord.x, in_frag_coord.y);
    let mut uv = (frag_coord - 0.5 * vec2(constants.width as f32, constants.height as f32))
        / constants.height as f32;
    uv.y = -uv.y;

    let eye_pos = vec3(0.0, 0.0997, 0.2);
    let sun_pos = vec3(0.0, 75.0, -1000.0);
    let dir = get_ray_dir(uv, eye_pos, sun_pos);

    // evaluate Preetham sky model
    let color = sky(dir, sun_pos);

    *output = tonemap(color).extend(1.0)
}

See source for full details.

Our Vision & Community Contributions

rust-gpu is a project that we at Embark think has the potential to change the way GPU programming works in multiple ways. One of the primary things we think it can change is opening the door to leverage the open source culture of sharing and improving each others' code, and our end goal and vision for rust-gpu is to develop it very much in tandem with the community. However, the project is still in quite early stages and has a very small team working on it, so in order to be productive and guide the project to where we ultimately want it to go, as of right now, we need to focus on our own primary use cases for our projects at Embark.

What this means practically is that it is unlikely that we'll be able to accept major changes from community members at this time. If you have a large change you would like to make, please file an issue and/or ask on our Discord in the #rust-gpu channel to see if it is something we'll be able to accept before working on it, as it is not great to have to turn down stuff that community members have poured their time and effort into. As the project matures, we'll in theory be able to accept more input from the community and move closer and closer to the goals outlined above. Thank you so much for your understanding!

Getting started

Check out The rust-gpu Dev Guide for information on how to get started with using it in your projects.

Experiment with rust-gpu shaders in-browser at SHADERed.

Background

Historically in games GPU programming has been done through writing either HLSL, or to a lesser extent GLSL. These are simple programming languages that have evolved along with rendering APIs over the years. However, as game engines have evolved, these languages have failed to provide mechanisms for dealing with large codebases, and have generally stayed behind the curve compared to other programming languages.

In part this is because it's a niche language for a niche market, and in part this has been because the industry as a whole has sunk quite a lot of time and effort into the status quo. While over-all better alternatives to both languages exist, none of them are in a place to replace HLSL or GLSL. Either because they are vendor locked, or because they don't support the traditional graphics pipeline. Examples of this include CUDA and OpenCL. And while attempts have been made to create language in this space, none of them have gained any notable traction in the gamedev community.

Our hope with this project is that we push the industry forward by bringing an existing, low-level, safe, and high performance language to the GPU; namely Rust. And with it come some additional benefits that can't be overlooked: a package/module system that's one of the industry's best, built in safety against race-conditions or out of bounds memory access, a wide range of tools and utilities to improve programmer workflows, and many others!

Why Embark?

At Embark, we've been building our own new game engine from the ground up in Rust. We have previous experience in-house developing the RLSL prototype, and we have a team of excellent rendering engineers that are familiar with the problems in current shading languages both from games, game engines and other industries. So, we believe we are uniquely positioned to attempt solving this problem.

We want to streamline our own internal development with a single great language, build an open source graphics ecosystem and community, facilitate code-sharing between GPU and CPU, and most importantly: to enable our (future) users, and fellow developers, to more rapidly build great looking and engaging experiences.

If we do this project right, one wouldn't necessarily need an entire team of rendering engineers to build a good looking game, instead one would simply use a few of the existing open-source crates that provide the graphical effects needed to create the experience you're after. Instead of sharing and copy'n'pasting snippets of TAA code on forum posts, one could simply find and use the right crates from crates.io.

Project scope

The scope of this overall project is quite broad, but is in multiple stages

  • rustc compiler backend to generate SPIR-V, plugging in via -Z codegen-backend.
  • Focus on Vulkan graphics shaders first, then after Vulkan compute shaders
  • Cargo and crates.io support to develop and publish SPIR-V crates
  • High-level render graph to take advantage of this, make it easy for users to develop and use rendering effects.

Process

We use this repo as a monorepo for everything related to the project: crates, tools, shaders, examples, tests, and design documents. This way, we can use issues and PRs covering everything in the same place, cross-reference stuff within the repo, as well as with other GitHub repos such as rspirv and Rust itself.

We meet weekly over a Discord call to discuss design and triage issues. Each meeting has an issue with agenda, links and minutes.

We have a #rust-gpu Discord channel for fast discussion and collaboration.

Backwards compatibility, breaking changes and deprecation

Right now because the project is in an early state of development, we might introduce temporary changes as stop-gap measures, or implement features or APIs that might not work exactly in a way we end up liking. Therefore it is expected that some (if not most) of the user facing code will change and evolve over time. At the moment this means that we make no guarantees about backwards compatibility and have no formal deprecation model in place. Effectively meaning that currently we only support building from source with the latest main branch in our repository. We appreciate our early adopters and would ask them to evolve their code along with ours.

Structure

There are a few different components to this repo:

  • rfcs for in-depth discussion and specs.
  • rustc_codegen_spirv for the compiler itself.
  • spirv-std for GPU intrinsics, types, and other library items used by GPU crates.
  • spirv-builder for a convenient way of building a GPU crate in a CPU build.rs file.

Related Projects

Historical and other related projects for compiling Rust code to GPUs.

  • 2016: glassful Compiles a subset of Rust to GLSL.
  • 2017: inspirv-rust Experimental Rust to SPIR-V compiler.
  • 2018: nvptx Rust to PTX compiler.
  • 2020: accel GPGPU library for Rust.
  • 2020: rlsl Predeccesor to rust_gpu, Rust to SPIR-V compiler.
  • 2021: Rust CUDA Rust to PTX compiler, similar mechanism to rustc_codegen_spirv.

Contributing

Contributor Covenant

We welcome community contributions to this project.

Please read our Contributor Guide for more information on how to get started.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

More Repositories

1

kajiya

๐Ÿ’ก Experimental real-time global illumination renderer ๐Ÿฆ€
Rust
4,524
star
2

texture-synthesis

๐ŸŽจ Example-based texture synthesis written in Rust ๐Ÿฆ€
Rust
1,717
star
3

wg-ui

WireGuard Web UI for self-serve client configurations, with optional auth.
Go
1,468
star
4

cargo-deny

โŒ Cargo plugin for linting your dependencies ๐Ÿฆ€
Rust
1,254
star
5

puffin

๐Ÿฆ Friendly little instrumentation profiler for Rust ๐Ÿฆ€
Rust
973
star
6

rust-ecosystem

Rust wants & tracking for Embark ๐Ÿฆ€
Rust
843
star
7

physx-rs

๐ŸŽณ Rust binding for NVIDIA PhysX ๐Ÿฆ€
Rust
611
star
8

blender-tools

๐Ÿต Embark Addon for Blender
Python
392
star
9

cargo-about

๐Ÿ“œ Cargo plugin to generate list of all licenses for a crate ๐Ÿฆ€
Rust
320
star
10

tryhard

๐Ÿ’ซ Easily retry futures ๐Ÿฆ€
Rust
182
star
11

presser

A crate to help you copy things into raw buffers without invoking spooky action at a distance (undefined behavior).
Rust
150
star
12

rpmalloc-rs

๐Ÿ rpmalloc global memory allocator for Rust ๐Ÿฆ€
Rust
126
star
13

crash-handling

Collection of crates to deal with crashes
Rust
122
star
14

poll-promise

A Rust promise for games and immediate mode GUIs
Rust
119
star
15

discord-sdk

An open implementation of the Discord Game SDK in Rust
Rust
108
star
16

skyhook

Simple Python communication system for DCC's and Game Engines
Python
104
star
17

spirt

SPIR-๐Ÿ‡น: shader-focused IR to target, transform and translate from ๐Ÿฆ€
Rust
101
star
18

superluminal-perf-rs

๐Ÿ”† Superluminal Performance profiler Rust API ๐Ÿฆ€
Rust
94
star
19

ash-molten

๐ŸŒ‹ Statically linked MoltenVK for Vulkan on Mac using Ash ๐Ÿฆ€
Rust
91
star
20

cargo-deny-action

โŒ GitHub Action for cargo-deny ๐Ÿฆ€
Shell
89
star
21

cargo-fetcher

๐ŸŽ cargo plugin for quickly fetching dependencies ๐Ÿฆ€
Rust
83
star
22

relnotes

Automatic GitHub Release Notes
Rust
77
star
23

opensource-template

๐ŸŒป Template for creating new repositories
74
star
24

tame-oauth

๐Ÿ” Small OAuth crate that follows the sans-io approach ๐Ÿฆ€
Rust
68
star
25

mirror-mirror

๐Ÿชž Powerful reflection library for Rust
Rust
68
star
26

tiny-bench

A tiny benchmarking library
Rust
55
star
27

k8s-buildkite-plugin

Run any buildkite build step as a Kubernetes Job
Jsonnet
48
star
28

krates

๐Ÿ“ฆ Creates graphs of crates from cargo metadata ๐Ÿฆ€
Rust
45
star
29

opensource

Open source processes, policies, and info
Rust
42
star
30

tame-gcs

๐Ÿ“‚ A small library with a limited set of Google Cloud Storage operations ๐Ÿฆ€
Rust
37
star
31

cervo

Utility wrappers for tract
Rust
36
star
32

server-framework

Framework for running network services, opinions included
Rust
36
star
33

tracing-logfmt

A logfmt formatter for tracing subscriber logs
Rust
35
star
34

octobors

Rust program for automerging PRs based on a few rules
Rust
35
star
35

nfd2

OS native dialogs for Windows, MacOS, and Linux
Rust
32
star
36

cfg-expr

A parser and evaluator for Rust cfg() expressions. Targets as of Rust 1.58.0 are supported.
Rust
32
star
37

opa-policies

Contains OPA Policies for Dockerfiles, Kubernetes YAMLs, Terraform, etc
Open Policy Agent
29
star
38

gsutil

Minimal gsutil replacement
Rust
27
star
39

spdx

๐Ÿ†” Helper crate for SPDX expressions. ๐Ÿฆ€
Rust
27
star
40

pdm-plugin-torch

A tool for managing torch-variants with PDM.
Python
22
star
41

opensource-website

๐ŸŒ Hub for Embark's open source efforts
HTML
22
star
42

buildkite-jobify

๐Ÿ‘ท Kubekite, but in Rust, using configuration from your repos ๐Ÿฆ€
Rust
21
star
43

spirv-tools-rs

๐Ÿ›  Wrapper crate for SPIRV-Tools ๐Ÿฆ€
C++
20
star
44

tame-index

Small crate for interacting with cargo registry indices
Rust
18
star
45

emote

Reinforcement learning library from Embark Studios
Python
17
star
46

rymder

Unofficial agones client SDK
Rust
17
star
47

fsr-rs

Rust bindings for AMD FidelityFXโ„ข Super Resolution
C
16
star
48

proto-gen

A protobuf generation runner/cli using tonic build
Rust
15
star
49

sentry-contrib-rust

Integrates crashdump reporting with Sentry
Rust
15
star
50

tame-oidc

๐Ÿงฌ Small OAuth crate that follows the sans-io approach ๐Ÿฆ€
Rust
11
star
51

cloud-dns

A wrapper for the Google Cloud DNS API (https://cloud.google.com/dns)
Rust
10
star
52

tame-webpurify

๐Ÿ’ฉ Small HTTP client for the Webpurify API following the sans-io approach ๐Ÿฆ€
Rust
9
star
53

tracing-ext-ffi-subscriber

Simple subscriber for forwarding tracing spans to a C or C++ profiling API.
Rust
4
star
54

server-code-exciser

A program that contains grammars and functionality to remove server only code from code bases.
C#
4
star
55

boh

Rust
4
star
56

gke-accelerated-xorg-example

Example project for running remote rendering on GKE
Dockerfile
3
star
57

helix-oidc

๐Ÿงฌ Helix Perforce OIDC validator
Go
3
star
58

PhysX-5

NVIDIA PhysX SDK
C++
3
star
59

cassini

Topology-aware distributed cache
Go
2
star
60

winit

Window handling library in pure Rust
Rust
2
star
61

minwin

Rust
2
star
62

container-packer-qemu

๐Ÿ“ฆ Dockerized packer with qemu
Dockerfile
1
star
63

rustc-compile-time-regress

Rust
1
star
64

.github

Default community health files for GitHub (https://help.github.com/en/github/building-a-strong-community/creating-a-default-community-health-file-for-your-organization)
1
star
65

missing-symbols

Rust
1
star
66

fd-lock

Advisory cross-platform file locks using file descriptors
Rust
1
star
67

lmdb-rs

Safe Rust bindings for LMDB
Rust
1
star
68

dolly

Composable camera rigs
Rust
1
star