Crate wgpu

source
Expand description

A cross-platform graphics and compute library based on WebGPU.

To start using the API, create an Instance.

§Feature flags

§Backends

  • dx12 (enabled by default) — Enables the DX12 backend on Windows.
  • metal (enabled by default) — Enables the Metal backend on macOS & iOS.
  • vulkan (enabled by default) — Enables the Vulkan backend on Windows, Linux, and Android.
  • gles (enabled by default) — Enables the OpenGL/GLES backend on Windows, Linux, Android, and Emscripten.
  • webgpu (enabled by default) — Enables the WebGPU backend on WebAssembly.

§Conditional Backends

  • angle — Enables the GLES backend on macOS only for use with ANGLE.

  • vulkan-portability — Enables the Vulkan backend on macOS & iOS only for use with MoltenVK.

  • webgl — Enables the GLES backend on WebAssembly only.

  • noop — Enables the noop backend for testing.

    This backend allows creating resources such as buffers and textures, but performs no computation. Because it lacks basic functionality, it is only actually used if explicitly enabled through NoopBackendOptions.

Note: In the documentation, if you see that an item depends on a backend, it means that the item is only available when that backend is enabled and the backend is supported on the current platform.

§Shading language support

These features enable support for that input language on all platforms. We will translate the input language to whatever the backend requires.

  • spirv — Enable accepting SPIR-V shaders as input.
  • glsl — Enable accepting GLSL shaders as input.
  • wgsl (enabled by default) — Enable accepting WGSL shaders as input.
  • naga-ir — Enable accepting naga IR shaders as input.

§Assertions and Serialization

  • strict_asserts — Apply run-time checks, even in release builds. These are in addition to the validation carried out at public APIs in all builds.
  • serde — Enables serialization via serde on common wgpu types.

§External libraries

The following features facilitate integration with third-party supporting libraries.

  • static-dxc — Enables statically linking DXC.

    Normally, to use the modern DXC shader compiler with WGPU, the final application must be shipped alongside dxcompiler.dll and dxil.dll (which can be downloaded from Microsoft’s GitHub). This feature statically links a version of DXC so that no external binaries are required to compile DX12 shaders.

§Other

  • counters — Internally count resources and events for debugging purposes. If the counters feature is disabled, the counting infrastructure is removed from the build and the exposed counters always return 0.

  • fragile-send-sync-non-atomic-wasm — Implement Send and Sync on Wasm, but only if atomics are not enabled.

    WebGL/WebGPU objects can not be shared between threads. However, it can be useful to artificially mark them as Send and Sync anyways to make it easier to write cross-platform code. This is technically very unsafe in a multithreaded environment, but on a wasm binary compiled without atomics is a definitionally single-threaded environment.

§Feature Aliases

These features aren’t actually features on the crate itself, but a convenient shorthand for complicated cases.

  • wgpu_core — Enabled when there is any non-webgpu backend enabled on the platform.
  • naga –– Enabled when any non-wgsl shader input is enabled.

Re-exports§

  • pub extern crate wgpu_hal as hal;
  • pub extern crate wgpu_core as wgc;
  • pub extern crate wgpu_types as wgt;
  • pub use ::wgc::naga;
    wgpu_core or naga
  • pub use raw_window_handle as rwh;

Modules§

  • api 🔒
    Types and functions which define our public api and their helper functionality.
  • backend 🔒
  • cmp 🔒
    We need to impl PartialEq, Eq, PartialOrd, Ord, and Hash for all handle types in wgpu.
  • dispatch 🔒
    Infrastructure for dispatching calls to the appropriate “backend”. The “backends” are:
  • macros 🔒
    Convenience macros
  • Utility structures and functions that are built on top of the main wgpu API.

Macros§

Structs§

Enums§

Constants§

Traits§

Type Aliases§