wgpu README

The project's README from github.com/gfx-rs/wgpu. As one markdown file: README.md.

wgpu

Build Status codecov.io

wgpu is a cross-platform, safe, pure-Rust graphics API. It runs natively on Vulkan, Metal, D3D12, and OpenGL; and on top of WebGL2 and WebGPU on wasm.

The API is based on the WebGPU standard, but is a fully native Rust library. It serves as the core of the WebGPU integration in Firefox, Servo, and Deno.

Getting Started

See our examples online at https://wgpu.rs/examples/. You can see the Rust sources at examples and run them directly with cargo run --bin wgpu-examples <example>.

Learning wgpu

If you are new to wgpu and graphics programming, we recommend starting with Learn Wgpu.

Additionally, WebGPU Fundamentals is a tutorial for WebGPU which is very similar to our API, minus differences between Rust and Javascript.

Documentation Guides

We ship a set of documentation modules with information on useful architecture patterns, debugging tips, and more getting started information.

Need Help? Want to Contribute?

The wgpu community uses Matrix and Discord to discuss.

Other Languages

To use wgpu in C or dozens of other languages, look at wgpu-native. These are C bindings to wgpu and has an up-to-date list of libraries bringing support to other languages.

Learn WebGPU (for C++) is a good resource for learning how to use wgpu-native from C++.

Docs Examples Changelog
v30 v30 v30
trunk trunk trunk

Contributors are welcome! See CONTRIBUTING.md for more information.

Supported Platforms

API Windows Linux/Android macOS/iOS Web (wasm)
Vulkan ✅ ✅ 🌋
Metal ✅
DX12 ✅
OpenGL 🆗 (GL 3.3+), or 📐 🆗 (GL ES 3.0+) 📐 🆗 (WebGL2)
WebGPU ✅

✅ = First Class Support
🆗 = Downlevel/Best Effort Support
📐 = Requires the ANGLE translation layer (GL ES 3.0 only). On macOS/iOS, use the angle feature. On Windows, gles uses WGL by default; build with cfg(windows_angle) to use ANGLE instead. 🌋 = Requires the MoltenVK translation layer
🛠️ = Unsupported, though open to contributions

Environment Variables

Testing, examples, and ::from_env() methods use a standardized set of environment variables to control wgpu's behavior.

See the documentation for more environment variables.

When running the CTS, use the variables DENO_WEBGPU_ADAPTER_NAME, DENO_WEBGPU_BACKEND, DENO_WEBGPU_POWER_PREFERENCE, DENO_WEBGPU_DX12_COMPILER, and DENO_WEBGPU_STRICT_COMPLIANCE.

Repo Overview

For an overview of all the components in the gfx-rs ecosystem, see the big picture.

MSRV policy

TL;DR: If you're using wgpu, our MSRV is 1.87. If you're running our tests or examples, our MSRV is 1.93.

We will avoid bumping the MSRV of wgpu without good reason, and such a change is considered breaking.

Specific Details

Due to complex dependants, we have three MSRV policies:

  • wgpu's MSRV is 1.87
  • wgpu-core (and hence wgpu-hal, naga, naga-types and wgpu-types)'s MSRV is 1.87.
  • The rest of the workspace has an MSRV of 1.93.

It is enforced on CI (in "/.github/workflows/ci.yml") with the WGPU_MSRV, CORE_MSRV, and REPO_MSRV variables, respectively. This version can only be upgraded in breaking releases, though we release a breaking version every three months.

The following rules apply:

  • The wgpu-core crate should never require an MSRV ahead of Firefox's MSRV for nightly builds, as determined by the value of MINIMUM_RUST_VERSION in python/mozboot/mozboot/util.py.
  • The wgpu crate should never require an MSRV ahead of Servo's MSRV, as determined by the value of their rust-version declaration in Cargo.toml
  • The repository MSRV should never require an MSRV higher than stable - 3. For example, if stable is at 1.97, the repository MSRV should be no higher than 1.94. This is to allow people who are using a decently-updated OS-provided rust to be able to build our repository. Consider cross checking with NixOS, though this is not required.

Testing and Environment Variables

Information about testing, including where tests of various kinds live, and how to run the tests.

Tracking the WebGPU and WGSL draft specifications

The wgpu crate is meant to be an idiomatic Rust translation of the WebGPU API. That specification, along with its shading language, WGSL, are both still in the "Working Draft" phase, and while the general outlines are stable, details change frequently. Until the specification is stabilized, the wgpu crate and the version of WGSL it implements will likely differ from what is specified, as the implementation catches up.

Exactly which WGSL features wgpu supports depends on how you are using it:

wgpu (gfx-rs/wgpu)

graphics-programming
Searching Database…

18.3K ·GitHub
What is this?wgpu is a cross-platform, safe, pure-Rust graphics library based on the WebGPU standard. It runs natively on Vulkan, Metal, D3D12, and OpenGL, and in the browser on top of WebGL2 and WebGPU via WebAssembly.
Is it a Rust library I add to my project, or a separate app I install?It is a fully native Rust library you add as a crate — there is no app to install. Code in C or dozens of other languages can reach it through the wgpu-native C bindings.
How do I get started with it?Add the wgpu crate to your Cargo project. If you are new to graphics programming, the README recommends the Learn Wgpu tutorial, and there are official examples online.
Which Rust version do I need?Rust 1.87 minimum for the library (1.93 to run the repo's tests and examples). MSRV bumps count as breaking changes, and a breaking version ships every three months.
The WebGPU spec and WGSL are still working drafts — is wgpu risky to build on?Somewhat. The outlines are stable but details change frequently, and wgpu's WGSL support can differ from the spec while the implementation catches up.
Is anything real built on it yet?Yes — wgpu serves as the core of the WebGPU integration in Firefox, Servo, and Deno, so it is heavily exercised in production.
Which platforms and graphics backends does it support?First-class: Vulkan (Windows, Linux, Android), Metal (macOS, iOS), and DX12 (Windows). OpenGL is downlevel best-effort, and the web build targets WebGPU or WebGL2 on wasm.
How do my WGSL shaders get compiled for each backend?Natively, wgpu's own Naga compiler translates WGSL into the platform's shader language. In the browser without the webgl feature, WGSL is passed straight to the browser's WebGPU implementation; with webgl enabled, Naga converts it to GLSL.
What's the catch with OpenGL support, especially on macOS and iOS?OpenGL is downlevel, best-effort support: GL 3.3+ on Windows and GL ES 3.0+ on Linux/Android. On macOS and iOS it needs the ANGLE translation layer (the angle feature), and Vulkan there requires MoltenVK.
Can I control which backend or GPU adapter wgpu picks at runtime?Yes, via environment variables: WGPU_BACKEND takes a comma-separated backend list (vulkan, metal, dx12, gl), and WGPU_ADAPTER_NAME matches a case-insensitive name substring, e.g. 1080 selects an NVIDIA GeForce 1080ti.
What are similar projects?filament, bgfx, renderdoc, crosstl, sokol, egui, Vulkan, framefields
Creator
gfx-rs
Size
85.3 MB
Stars
18.3K
Age
8y
Commits · 90 Days