wgpu/
lib.rs

1//! A cross-platform graphics and compute library based on [WebGPU](https://gpuweb.github.io/gpuweb/).
2//!
3//! To start using the API, create an [`Instance`].
4//!
5//! ## Feature flags
6#![doc = document_features::document_features!()]
7//!
8//! ### Feature Aliases
9//!
10//! These features aren't actually features on the crate itself, but a convenient shorthand for
11//! complicated cases.
12//!
13//! - **`wgpu_core`** --- Enabled when there is any non-webgpu backend enabled on the platform.
14//! - **`naga`** ---- Enabled when any non-wgsl shader input is enabled.
15//!
16
17#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
18#![doc(html_logo_url = "https://raw.githubusercontent.com/gfx-rs/wgpu/trunk/logo.png")]
19#![warn(
20    clippy::allow_attributes,
21    missing_docs,
22    rust_2018_idioms,
23    unsafe_op_in_unsafe_fn
24)]
25#![allow(clippy::arc_with_non_send_sync)]
26#![cfg_attr(not(any(wgpu_core, webgpu)), allow(unused))]
27
28//
29//
30// Modules
31//
32//
33
34mod api;
35mod backend;
36mod cmp;
37mod dispatch;
38mod macros;
39pub mod util;
40
41//
42//
43// Private re-exports
44//
45//
46
47//
48//
49// Public re-exports
50//
51//
52
53pub use api::*;
54pub use wgt::{
55    AdapterInfo, AddressMode, AstcBlock, AstcChannel, Backend, BackendOptions, Backends,
56    BindGroupLayoutEntry, BindingType, BlendComponent, BlendFactor, BlendOperation, BlendState,
57    BufferAddress, BufferBindingType, BufferSize, BufferUsages, Color, ColorTargetState,
58    ColorWrites, CommandBufferDescriptor, CompareFunction, CompositeAlphaMode,
59    CopyExternalImageDestInfo, CoreCounters, DepthBiasState, DepthStencilState, DeviceLostReason,
60    DeviceType, DownlevelCapabilities, DownlevelFlags, Dx12BackendOptions, Dx12Compiler,
61    DynamicOffset, Extent3d, Face, Features, FilterMode, FrontFace, GlBackendOptions,
62    Gles3MinorVersion, HalCounters, ImageSubresourceRange, IndexFormat, InstanceDescriptor,
63    InstanceFlags, InternalCounters, Limits, MaintainResult, MemoryHints, MultisampleState,
64    Origin2d, Origin3d, PipelineStatisticsTypes, PolygonMode, PowerPreference,
65    PredefinedColorSpace, PresentMode, PresentationTimestamp, PrimitiveState, PrimitiveTopology,
66    PushConstantRange, QueryType, RenderBundleDepthStencil, SamplerBindingType, SamplerBorderColor,
67    ShaderLocation, ShaderModel, ShaderRuntimeChecks, ShaderStages, StencilFaceState,
68    StencilOperation, StencilState, StorageTextureAccess, SurfaceCapabilities, SurfaceStatus,
69    TexelCopyBufferLayout, TextureAspect, TextureDimension, TextureFormat,
70    TextureFormatFeatureFlags, TextureFormatFeatures, TextureSampleType, TextureUsages,
71    TextureViewDimension, VertexAttribute, VertexFormat, VertexStepMode, WasmNotSend,
72    WasmNotSendSync, WasmNotSync, COPY_BUFFER_ALIGNMENT, COPY_BYTES_PER_ROW_ALIGNMENT,
73    MAP_ALIGNMENT, PUSH_CONSTANT_ALIGNMENT, QUERY_RESOLVE_BUFFER_ALIGNMENT, QUERY_SET_MAX_QUERIES,
74    QUERY_SIZE, VERTEX_STRIDE_ALIGNMENT,
75};
76#[expect(deprecated)]
77pub use wgt::{ImageCopyBuffer, ImageCopyTexture, ImageCopyTextureTagged, ImageDataLayout};
78// wasm-only types, we try to keep as many types non-platform
79// specific, but these need to depend on web-sys.
80#[cfg(any(webgpu, webgl))]
81#[expect(deprecated)]
82pub use wgt::ImageCopyExternalImage;
83#[cfg(any(webgpu, webgl))]
84pub use wgt::{CopyExternalImageSourceInfo, ExternalImageSource};
85//
86//
87// Re-exports of dependencies
88//
89//
90
91/// Re-export of our `wgpu-core` dependency.
92///
93#[cfg(wgpu_core)]
94pub use ::wgc as core;
95
96/// Re-export of our `wgpu-hal` dependency.
97///
98///
99#[cfg(wgpu_core)]
100pub use ::hal;
101
102/// Re-export of our `naga` dependency.
103///
104#[cfg(wgpu_core)]
105#[cfg_attr(docsrs, doc(cfg(any(wgpu_core, naga))))]
106// We re-export wgpu-core's re-export of naga, as we may not have direct access to it.
107pub use ::wgc::naga;
108/// Re-export of our `naga` dependency.
109///
110#[cfg(all(not(wgpu_core), naga))]
111#[cfg_attr(docsrs, doc(cfg(any(wgpu_core, naga))))]
112// If that's not available, we re-export our own.
113pub use naga;
114
115/// Re-export of our `raw-window-handle` dependency.
116///
117pub use raw_window_handle as rwh;
118
119/// Re-export of our `web-sys` dependency.
120///
121#[cfg(any(webgl, webgpu))]
122pub use web_sys;
123
124/// `web-sys` has a `no_std` mode, and instead refers to the `alloc` crate in its generated code.
125/// Since we vendor the WebGPU bindings we need to explicitly add the `alloc` crate ourselves.
126#[cfg(webgpu)]
127extern crate alloc;