Signed distance functions + Rust (CPU & GPU) = ❤️❤️

Overview

sdf-playground

Signed distance functions + Rust (CPU & GPU) = ❤️❤️

Platforms: Windows, Mac & Linux.

About

sdf-playground is a demo showcasing how you can run Rust code on the GPU - it consists of two parts:

  • the application (run on the CPU, inside ./app),
  • the shader (run on the GPU, inside ./shader).

Application is responsible for spawning the window and telling GPU to execute the shader, while shader is the one which generates all the colors.

Shader here implements a ray-marcher for signed distance functions, but in principle it can be anything you want, e.g.:

#[spirv(fragment)]
pub fn main_fs(out_color: &mut Vec4) {
    // out_color.x = R (0..1)
    // out_color.y = G (0..1)
    // out_color.z = B (0..1)
    // out_color.w = alpha (technically 0..1, but actually unused here)

    // Renders a yellow rectangle
    *out_color = vec4(1.0, 1.0, 0.0, 1.0); 
}

Usage

Assuming you've got Rust installed:

$ git clone https://github.com/Patryk27/sdf-playground
$ cargo run --release
# (might take a few minutes the first time, but should be faster then)

Note that the code first builds the application, then starts it, and then builds the shader - so for a few moments (until the shader is ready), the window will be just pitch-black (you should be able to see the shader's compilation progress in the terminal, though).

On the upside, modifying the shader doesn't require restarting the application - simply change shader/src/lib.rs, save it and wait a few seconds for the application to refresh!

Caveat Emptor

rust-gpu (the software that compiles your Rust code into a shader) doesn't support all features of the Rust language:

  • understandably, there's no standard library (no std::fs, no vec![] etc.),
  • there's no support for ADTs (no enum Option<T> { Some(T), None } etc.),
  • stick to bool, u8, u32 and f32 - other types (might) not work,
  • miscompilations are possible, though unlikely.

License

MIT License

Copyright (c) 2023 Patryk Wychowaniec

You might also like...
How to: Run Rust code on your NVIDIA GPU

Status This documentation about an unstable feature is UNMAINTAINED and was written over a year ago. Things may have drastically changed since then; r

🐉 Making Rust a first-class language and ecosystem for GPU shaders 🚧
🐉 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 Current Status 🚧 Note: This project is still heavily in d

A Demo server serving Bert through ONNX with GPU written in Rust with 3

Demo BERT ONNX server written in rust This demo showcase the use of onnxruntime-rs on BERT with a GPU on CUDA 11 served by actix-web and tokenized wit

Wonnx - a GPU-accelerated ONNX inference run-time written 100% in Rust, ready for the web

Wonnx is a GPU-accelerated ONNX inference run-time written 100% in Rust, ready for the web. Supported Platforms (enabled by wgpu) API Windows Linux &

A gpu accelerated (optional) neural network Rust crate.

Intricate A GPU accelerated library that creates/trains/runs neural networks in pure safe Rust code. Architechture overview Intricate has a layout ver

A repo for learning how to parallelize computations in the GPU using Apple's Metal, in Rust.

Metal playground in rust Made for learning how to parallelize computations in the GPU using Apple's Metal, in Rust, via the metal crate. Overview The

LLaMa 7b with CUDA acceleration implemented in rust. Minimal GPU memory needed!

LLaMa 7b in rust This repo contains the popular LLaMa 7b language model, fully implemented in the rust programming language! Uses dfdx tensors and CUD

A fun, hackable, GPU-accelerated, neural network library in Rust, written by an idiot

Tensorken: A Fun, Hackable, GPU-Accelerated, Neural Network library in Rust, Written by an Idiot (work in progress) Understanding deep learning from t

rust-gpu CLI driver

rust-gpu-driver Experiment to make rust-gpu more accessible as a GPU shading language in various projects. DISCLAIMER: This is an unstable experiment

Owner
Patryk Wychowaniec
doing (hopefully useful) computer things
Patryk Wychowaniec
Open Machine Intelligence Framework for Hackers. (GPU/CPU)

Leaf • Introduction Leaf is a open Machine Learning Framework for hackers to build classical, deep or hybrid machine learning applications. It was ins

Autumn 5.5k Jan 1, 2023
Open deep learning compiler stack for cpu, gpu and specialized accelerators

Open Deep Learning Compiler Stack Documentation | Contributors | Community | Release Notes Apache TVM is a compiler stack for deep learning systems. I

The Apache Software Foundation 8.9k Jan 4, 2023
Damavand is a quantum circuit simulator. It can run on laptops or High Performance Computing architectures, such CPU distributed architectures or multi GPU distributed architectures.

Damavand is a code that simulates quantum circuits. In order to learn more about damavand, refer to the documentation. Development status Core feature

prevision.io 6 Mar 29, 2022
Instance Distance is a fast pure-Rust implementation of the Hierarchical Navigable Small Worlds paper

Fast approximate nearest neighbor searching in Rust, based on HNSW index

Instant Domain Search, Inc. 135 Dec 24, 2022
Python package to compute levensthein distance in rust

Contents Introduction Installation Usage License Introduction Rust implementation of levensthein distance (https://en.wikipedia.org/wiki/Levenshtein_d

Thibault Blanc 2 Feb 21, 2022
Adjustment Identification Distance: A gadjid for Causal Structure Learning

Adjustment Identification Distance: A ???????????? for Causal Structure Learning This is an early release of ???????????? ?? and feedback is very welc

CausalDisco 6 Feb 29, 2024
Rust based Cross-GPU Machine Learning

HAL : Hyper Adaptive Learning Rust based Cross-GPU Machine Learning. Why Rust? This project is for those that miss strongly typed compiled languages.

Jason Ramapuram 83 Dec 20, 2022
A real-time implementation of "Ray Tracing in One Weekend" using nannou and rust-gpu.

Real-time Ray Tracing with nannou & rust-gpu An attempt at a real-time implementation of "Ray Tracing in One Weekend" by Peter Shirley. This was a per

null 89 Dec 23, 2022
Ecosystem of libraries and tools for writing and executing extremely fast GPU code fully in Rust.

Ecosystem of libraries and tools for writing and executing extremely fast GPU code fully in Rust.

Riccardo D'Ambrosio 2.1k Jan 5, 2023
Ecosystem of libraries and tools for writing and executing fast GPU code fully in Rust.

The Rust CUDA Project An ecosystem of libraries and tools for writing and executing extremely fast GPU code fully in Rust Guide | Getting Started | Fe

Rust GPU 2.1k Dec 30, 2022