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.
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>.
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.
We have a wiki which has information on useful architecture patterns, debugging tips, and more getting started information.
The wgpu community uses Matrix to discuss.
- discussion of wgpu's development.
- discussion of using the library and the surrounding ecosystem.
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 |
|---|---|---|
| v27 | v27 | v27 |
trunk |
trunk |
trunk |
Contributors are welcome! See CONTRIBUTING.md for more information.
| API | Windows | Linux/Android | macOS/iOS | Web (wasm) |
|---|---|---|---|---|
| Vulkan | β | β | π | |
| Metal | β | |||
| DX12 | β | |||
| OpenGL | π (GL 3.3+) | π (GL ES 3.0+) | π | π (WebGL2) |
| WebGPU | β |
β
= First Class Support
π = Downlevel/Best Effort Support
π = Requires the ANGLE translation layer (GL ES 3.0 only)
π = Requires the MoltenVK translation layer
π οΈ = Unsupported, though open to contributions
Testing, examples, and ::from_env() methods use a standardized set of environment variables to control wgpu's behavior.
WGPU_BACKENDwith a comma-separated list of the backends you want to use (vulkan,metal,dx12, orgl).WGPU_ADAPTER_NAMEwith a case-insensitive substring of the name of the adapter you want to use (ex.1080will matchNVIDIA GeForce 1080ti).WGPU_DX12_COMPILERwith the DX12 shader compiler you wish to use (dxc,static-dxc, orfxc). Note thatdxcrequiresdxcompiler.dll(min v1.8.2502) to be in the working directory, andstatic-dxcrequires thestatic-dxccrate feature to be enabled. Otherwise, it will fall back tofxc.
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.
For an overview of all the components in the gfx-rs ecosystem, see the big picture.
TL;DR: If you're using wgpu, our MSRV is 1.88.
Specific Details
Due to complex dependants, we have two MSRV policies:
naga,wgpu-core,wgpu-hal, andwgpu-types's MSRV is 1.82.- The rest of the workspace has an MSRV of 1.88.
It is enforced on CI (in "/.github/workflows/ci.yml") with the CORE_MSRV and REPO_MSRV variables.
This version can only be upgraded in breaking releases, though we release a breaking version every three months.
The naga, wgpu-core, wgpu-hal, and wgpu-types crates 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.
Information about testing, including where tests of various kinds live, and how to run the tests.
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:
-
When running as native code,
wgpuuses Naga to translate WGSL code into the shading language of your platform's native GPU API. Naga is working on catching up to the WGSL specification, with bugs tracking various issues, but there is no concise summary of differences from the specification. -
When running in a web browser (by compilation to WebAssembly) without the
"webgl"feature enabled,wgpurelies on the browser's own WebGPU implementation. WGSL shaders are simply passed through to the browser, so that determines which WGSL features you can use. -
When running in a web browser with
wgpu's"webgl"feature enabled,wgpuuses Naga to translate WGSL programs into GLSL. This uses the same version of Naga as if you were runningwgpuas native code.
