wgpu/
lib.rs

1//! `wgpu` is a cross-platform, safe, pure-Rust graphics API. It runs natively on
2//! Vulkan, Metal, D3D12, and OpenGL; and on top of WebGL2 and WebGPU on wasm.
3//!
4//! The API is based on the [WebGPU standard][webgpu], but is a fully native Rust library.
5//! It serves as the core of the WebGPU integration in Firefox, Servo, and Deno.
6//!
7//! [webgpu]: https://gpuweb.github.io/gpuweb/
8//!
9//! ## Getting Started
10//!
11//! The main entry point to the API is the [`Instance`] type, from which you can create [`Adapter`], [`Device`], and [`Surface`].
12//!
13//! If you are new to `wgpu` and graphics programming, we recommend starting with [Learn Wgpu].
14//! <!-- Note, "Learn Wgpu" is using the capitalization style in their header, NOT our styling -->
15//!
16//! Additionally, [WebGPU Fundamentals] is a tutorial for WebGPU which is very similar to our API, minus differences between Rust and Javascript.
17//!
18//! We have a [wiki](https://github.com/gfx-rs/wgpu/wiki) which has information on useful architecture patterns, debugging tips, and more getting started information.
19//!
20//! There are examples for this version [available on GitHub](https://github.com/gfx-rs/wgpu/tree/v28/examples#readme).
21//!
22//! The API is refcounted, so all handles are cloneable, and if you create a resource which references another,
23//! it will automatically keep dependent resources alive.
24//!
25//! `wgpu` uses the coordinate systems of D3D and Metal. Depth ranges from [0, 1].
26//!
27//! | Render                | Texture                |
28//! | --------------------- | ---------------------- |
29//! | ![render_coordinates] | ![texture_coordinates] |
30//!
31//! `wgpu`'s MSRV is **1.92**.
32//!
33//! [Learn Wgpu]: https://sotrh.github.io/learn-wgpu/
34//! [WebGPU Fundamentals]: https://webgpufundamentals.org/
35//! [render_coordinates]: https://raw.githubusercontent.com/gfx-rs/wgpu/refs/heads/v28/docs/render_coordinates.png
36//! [texture_coordinates]: https://raw.githubusercontent.com/gfx-rs/wgpu/refs/heads/v28/docs/texture_coordinates.png
37//!
38//! ## Extension Specifications
39//!
40//! While the core of `wgpu` is based on the WebGPU standard, we also support extensions that allow for features that the standard does not have yet.
41//! For high-level documentation on how to use these extensions, see documentation on [`Features`] or the relevant specification:
42//!
43//! 🧪EXPERIMENTAL🧪 APIs are subject to change and may allow undefined behavior if used incorrectly.
44//!
45//! - 🧪EXPERIMENTAL🧪 [Ray Tracing](https://github.com/gfx-rs/wgpu/blob/v28/docs/api-specs/ray_tracing.md).
46//! - 🧪EXPERIMENTAL🧪 [Mesh Shading](https://github.com/gfx-rs/wgpu/blob/v28/docs/api-specs/mesh_shading.md).
47//!
48//! ## Shader Support
49//!
50//! `wgpu` can consume shaders in [WGSL](https://gpuweb.github.io/gpuweb/wgsl/), SPIR-V, and GLSL.
51//! Both [HLSL](https://github.com/Microsoft/DirectXShaderCompiler) and [GLSL](https://github.com/KhronosGroup/glslang)
52//! have compilers to target SPIR-V. All of these shader languages can be used with any backend as we handle all of the conversions. Additionally, support for these shader inputs is not going away.
53//!
54//! While WebGPU does not support any shading language other than WGSL, we will automatically convert your
55//! non-WGSL shaders if you're running on WebGPU.
56//!
57//! WGSL is always supported by default, but GLSL and SPIR-V need features enabled to compile in support.
58//!
59//! To enable WGSL shaders, enable the `wgsl` feature of `wgpu` (enabled by default).
60//! To enable SPIR-V shaders, enable the `spirv` feature of `wgpu`.
61//! To enable GLSL shaders, enable the `glsl` feature of `wgpu`.
62//!
63//! ## Feature flags
64#![doc = document_features::document_features!()]
65//!
66//! ### Feature Aliases
67//!
68//! These features aren't actually features on the crate itself, but a convenient shorthand for
69//! complicated cases.
70//!
71//! - **`wgpu_core`** --- Enabled when there is any non-webgpu backend enabled on the platform.
72//! - **`naga`** --- Enabled when target `glsl` or `spirv` input is enabled, or when `wgpu_core` is enabled.
73//!
74
75#![no_std]
76#![cfg_attr(docsrs, feature(doc_cfg))]
77#![doc(html_logo_url = "https://raw.githubusercontent.com/gfx-rs/wgpu/trunk/logo.png")]
78#![warn(
79    clippy::alloc_instead_of_core,
80    clippy::allow_attributes,
81    clippy::std_instead_of_alloc,
82    clippy::std_instead_of_core,
83    missing_docs,
84    rust_2018_idioms,
85    unsafe_op_in_unsafe_fn
86)]
87#![allow(
88    // We need to investiagate these.
89    clippy::large_enum_variant,
90    // These degrade readability significantly.
91    clippy::bool_assert_comparison,
92    clippy::bool_comparison,
93)]
94// NOTE: Keep this in sync with `wgpu-core`.
95#![cfg_attr(not(send_sync), allow(clippy::arc_with_non_send_sync))]
96#![cfg_attr(not(any(wgpu_core, webgpu)), allow(unused))]
97
98extern crate alloc;
99#[cfg(std)]
100extern crate std;
101#[cfg(wgpu_core)]
102pub extern crate wgpu_core as wgc;
103#[cfg(wgpu_core)]
104pub extern crate wgpu_hal as hal;
105pub extern crate wgpu_types as wgt;
106
107//
108//
109// Modules
110//
111//
112
113mod api;
114mod backend;
115mod cmp;
116mod dispatch;
117mod macros;
118pub mod util;
119
120//
121//
122// Public re-exports
123//
124//
125
126#[cfg(custom)]
127pub use backend::custom;
128
129pub use api::*;
130pub use wgt::{
131    AdapterInfo, AddressMode, AllocatorReport, AstcBlock, AstcChannel, Backend, BackendOptions,
132    Backends, BindGroupLayoutEntry, BindingType, BlendComponent, BlendFactor, BlendOperation,
133    BlendState, BufferAddress, BufferBindingType, BufferSize, BufferTextureCopyInfo,
134    BufferTransition, BufferUsages, BufferUses, Color, ColorTargetState, ColorWrites,
135    CommandBufferDescriptor, CompareFunction, CompositeAlphaMode, CooperativeMatrixProperties,
136    CooperativeScalarType, CopyExternalImageDestInfo, CoreCounters, DepthBiasState,
137    DepthStencilState, DeviceLostReason, DeviceType, DownlevelCapabilities, DownlevelFlags,
138    DownlevelLimits, Dx12BackendOptions, Dx12Compiler, Dx12SwapchainKind,
139    Dx12UseFrameLatencyWaitableObject, DxcShaderModel, DynamicOffset, ExperimentalFeatures,
140    Extent3d, ExternalTextureFormat, ExternalTextureTransferFunction, Face, Features, FeaturesWGPU,
141    FeaturesWebGPU, FilterMode, FrontFace, GlBackendOptions, GlFenceBehavior, Gles3MinorVersion,
142    HalCounters, ImageSubresourceRange, IndexFormat, InstanceDescriptor, InstanceFlags,
143    InternalCounters, Limits, LoadOpDontCare, MemoryBudgetThresholds, MemoryHints,
144    MipmapFilterMode, MultisampleState, NoopBackendOptions, Origin2d, Origin3d,
145    PipelineStatisticsTypes, PollError, PollStatus, PolygonMode, PowerPreference,
146    PredefinedColorSpace, PresentMode, PresentationTimestamp, PrimitiveState, PrimitiveTopology,
147    QueryType, RenderBundleDepthStencil, RequestAdapterError, SamplerBindingType,
148    SamplerBorderColor, ShaderLocation, ShaderModel, ShaderRuntimeChecks, ShaderStages,
149    StencilFaceState, StencilOperation, StencilState, StorageTextureAccess, SurfaceCapabilities,
150    SurfaceStatus, TexelCopyBufferLayout, TextureAspect, TextureDimension, TextureFormat,
151    TextureFormatFeatureFlags, TextureFormatFeatures, TextureSampleType, TextureTransition,
152    TextureUsages, TextureUses, TextureViewDimension, Trace, VertexAttribute, VertexFormat,
153    VertexStepMode, WasmNotSend, WasmNotSendSync, WasmNotSync, COPY_BUFFER_ALIGNMENT,
154    COPY_BYTES_PER_ROW_ALIGNMENT, IMMEDIATE_DATA_ALIGNMENT, MAP_ALIGNMENT,
155    MAXIMUM_SUBGROUP_MAX_SIZE, MINIMUM_SUBGROUP_MIN_SIZE, QUERY_RESOLVE_BUFFER_ALIGNMENT,
156    QUERY_SET_MAX_QUERIES, QUERY_SIZE, VERTEX_ALIGNMENT,
157};
158
159#[expect(deprecated)]
160pub use wgt::VERTEX_STRIDE_ALIGNMENT;
161
162// wasm-only types, we try to keep as many types non-platform
163// specific, but these need to depend on web-sys.
164#[cfg(web)]
165pub use wgt::{CopyExternalImageSourceInfo, ExternalImageSource};
166
167/// Re-export of our `naga` dependency.
168///
169#[cfg(wgpu_core)]
170#[cfg_attr(docsrs, doc(cfg(any(wgpu_core, naga))))]
171// We re-export wgpu-core's re-export of naga, as we may not have direct access to it.
172pub use ::wgc::naga;
173/// Re-export of our `naga` dependency.
174///
175#[cfg(all(not(wgpu_core), naga))]
176#[cfg_attr(docsrs, doc(cfg(any(wgpu_core, naga))))]
177// If that's not available, we re-export our own.
178pub use naga;
179
180/// Re-export of our `raw-window-handle` dependency.
181///
182pub use raw_window_handle as rwh;
183
184/// Re-export of our `web-sys` dependency.
185///
186#[cfg(web)]
187pub use web_sys;
188
189#[doc(hidden)]
190pub use macros::helpers as __macro_helpers;