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)

Searching Database…

18.3K ·GitHub
这是什么东西?wgpu 是一个基于 WebGPU 标准的跨平台、内存安全、纯 Rust 编写的图形库。它可以在 Vulkan、Metal、D3D12 和 OpenGL 上原生运行,也能通过 WebAssembly 在浏览器里跑在 WebGL2 和 WebGPU 之上。
它是加到我项目里的 Rust 库,还是需要单独安装的应用?它是一个完整的原生 Rust 库,以 crate 的形式加入项目——没有任何需要安装的应用。C 语言以及几十种其他语言的代码可以通过 wgpu-native 这个 C 绑定来调用它。
该怎么上手?把 wgpu crate 添加到你的 Cargo 项目里。如果你是刚接触图形编程,README 推荐 Learn Wgpu 教程,网上还有官方示例可以看。
我需要哪个版本的 Rust?库本身要求 Rust 最低 1.87(要跑仓库里的测试和示例则需要 1.93)。MSRV 的提升会被当作破坏性变更,每三个月发布一个破坏性版本。
WebGPU 规范和 WGSL 还是草案,基于 wgpu 开发有风险吗?多少有一点。整体框架已经稳定,但细节经常变动,而且 wgpu 的 WGSL 支持在实现追上规范之前,可能与规范有所不同。
有没有真实项目在用它?有——Firefox、Servo 和 Deno 里的 WebGPU 集成都是以 wgpu 为核心的,所以它已经在生产环境中被大量使用和检验。
它支持哪些平台和图形后端?一等支持:Vulkan(Windows、Linux、Android)、Metal(macOS、iOS)和 DX12(Windows)。OpenGL 属于较低优先级的尽力支持,Web 版本则在 wasm 上以 WebGPU 或 WebGL2 为目标。
我的 WGSL 着色器是怎么为各个后端编译的?在原生环境下,wgpu 自带的 Naga 编译器会把 WGSL 翻译成对应平台的着色器语言。在浏览器里,如果没有启用 webgl feature,WGSL 会直接交给浏览器的 WebGPU 实现;启用 webgl 后,则由 Naga 把它转换成 GLSL。
OpenGL 支持有什么限制,尤其是在 macOS 和 iOS 上?OpenGL 属于较低优先级的尽力支持:Windows 上要求 GL 3.3+,Linux/Android 上要求 GL ES 3.0+。在 macOS 和 iOS 上需要 ANGLE 转换层(angle feature),在那两个平台上用 Vulkan 则需要 MoltenVK。
我能在运行时控制 wgpu 选择哪个后端或哪块 GPU 吗?可以,通过环境变量:WGPU_BACKEND 接受用逗号分隔的后端列表(vulkan、metal、dx12、gl),WGPU_ADAPTER_NAME 则按不区分大小写的名称子串匹配,比如填 1080 就会选中 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