RLSL
A Rust to SPIR-V compiler
Maik Klein, Embark Studios
Agenda
Embark Studios
We are a Stockholm-based games studio, on a mission to blur the line between playing and making.
Why Rust?
When we started Embark, we chose Rust as our primary language for the long term future we are building. We love the safety and robustness of the language, the ability to write high performance, safe, and (mostly) bug free code and then fearlessly refactor and change it without common lifetime/ownership, memory safety or race condition problems.
That, combined with the openness and collaborative nature of the quickly growing ecosystem of and around Rust with crates.io and the tens of thousands of open source crates with a best-in-class package system, cargo, truly makes Rust a language for the next 40 years.
We believe that by openly sharing our work, issues, and ideas with the community, we'll create more opportunities for collaboration and discussion to bring us toward a great future for Rust and for the games industry in general.
-- Johan Andersson (@repi), CTO, Embark
Why Rust on the GPU?
All the same reasons why Rust is nice on the CPU.
Unified front end.
You benefit from the Rust ecosystem
crates.io
Central repository for hosting and finding libraries
Cargo
Easily add dependencies to your project
Open community
Hypothetical libraries
What is RLSL?
RLSL => Rust Like Shading Language
RLSL is a subset of Rust
TL;DR: Write your shaders in Rust
Highly experimental (Not ready to be used)
Generating SPIR-V
RUST
MIR
SPIR-V
MIR => Mid Level Intermediate Representation
Building your project
Rlsl Integrates seamlessly with cargo
Showcase
Ray sphere intersection
Scattering
Things you get for free
Mapping SPIR-V types
SPIR-V has built in intrinsic types like OpTypeVector
Those can be mapped with attributes #[spirv(Vec4)]
Can be implemented in user land
Testing
1
2
5
9
1
2
3
1
2
5
9
8
2
3
CPU
GPU
Mismatch
5
3
1
1
9
4
8
Input
Challenges
Structured Control Flow
MIR is fully unstructured
Structured control flow has to be recomputed
Many edge cases that are hard to track down
rspirv-cfg
A blend of spirv-cfg and spirv-dis
This project is independent of RLSL and can be used with any SPIR-V file
Pointers can be tricky
Mapping algebraic data types
No unions in SPIR-V
No arbitrary bit casts in SPIR-V
This results in an inefficient memory layout for enums
SPIR-V
Promising prototype
Many features have been implemented and proven to work
Closing
We at Embark want to invest in a rusty GPU future
We are looking for partners to collaborate with
Feel free to reach out to me or visit embark.rs
Or send us an email opensource@embark-studios.com
Questions?