Gfx-rs nuts and bolts

Gfx-rs is a low-level graphics abstraction layer in Rust. This blog supposedly hosts the major milestones, concepts, and recaps of the project.


The Big Picture

16 Nov 2020

gfx-rs community’s goal is to make graphics programming in Rust easy, fast, and reliable. In this post, we are going to provide an overview of the projects we work on, how they are connected, and what the future holds for us:

big picture

Full diagram link.

Legend:

  • parallelogram: Rust node
  • rectangle: C/C++ node
  • hexagon: node in Rust that exposes an external API

Colors correspond roughly to the areas: gfx is blue, wgpu is green, JS stuff is yellow, etc.

Nodes

ash - Vulkan bindings we use in gfx-rs, external to us.

metal-rs - Metal bindings crate we use in gfx-rs, also used outside.

d3d12-rs - simple D3D12 convenience wrapper we use in gfx-rs.

winapi - WinAPI bindings we use in gfx-rs for both DX11 and DX12 (where d3d12-rs has gaps), external to us.

glow - OpenGL (including ES and WebGL) bindings we use in gfx-rs, also used outside.

gfx-rs - our portable graphics API in Rust, tightly following Vulkan.

gfx-portability - a Vulkan Portability API wrapper around gfx-rs. Can be used as a drop-in Vulkan driver on platforms without native Vulkan support.

SPIRV-Cross - shader translation library in C++, taking SPIR-V as an input. It’s developed by a few Khronos members. We currently use it for generating platform-specific shaders in gfx-rs. We are phasing it away, replacing by naga gradually (the striped fill signifies deprecation in the diagram).

naga - our new shader translation library in Rust, it has a number of front-ends (SPIR-V, GLSL, and WGSL so far), various backends (SPIR-V, MSL, GLSL so far), and a solid intermediate representation (IR) in the middle. It’s a young project, and we are slowly rolling it out to replace the C++ blocks around the ecosystem, such as SPIRV-Cross and glsl-to-spirv/shaderc (used by many gfx/wgpu/Vulkan devs).

wgpu - our implementation of WebGPU API in Rust. It’s safe, portable, and fast (in this order).

  • Uses gfx-rs to reach the hardware.
  • Uses naga to parse WGSL shaders, as well as introspect both SPIR-V and WGSL shaders. This allows us to validate the shaders, also to derive the implicit bind group layouts.
  • able to record and replay API traces across platforms.

wgpu-rs - idiomatic Rust bindings to wgpu, meant for Rust end-users. Has many dependent applications and libraries, including Nannou and Bevy.

  • Currently able to target wgpu as well as the WebGPU/WASM (experimental in browsers).
  • Will be able to link to an implementation behind the portable WebGPU C header, such as wgpu-native.

wgpu-native - a wrapper around wgpu that exposes a WebGPU C API conforming to the shared header. The plan is to have it accessible by non-Rust libraries, as a drop-in replacement for Dawn, also accessible via NAPI.

Deno - JS/TS runtime in Rust. There is a mostly complete PR #7977 delivering support for WebGPU via wgpu. It should allow native JS/TS applications (such as TensorFlow.js) using WebGPU to run directly on top of wgpu in the future.

Servo - an experimental browser engine in Rust. It has WebGPU support via wgpu.

Gecko - the browser engine powering Firefox, developed by Mozilla. It also implements WebGPU via wgpu.