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/v29/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.87**.
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/v29/docs/render_coordinates.png
36//! [texture_coordinates]: https://raw.githubusercontent.com/gfx-rs/wgpu/refs/heads/v29/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/v29/docs/api-specs/ray_tracing.md).
46//! - 🧪EXPERIMENTAL🧪 [Mesh Shading](https://github.com/gfx-rs/wgpu/blob/v29/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// Workspace CI compiles this crate with `-D warnings` for wasm32. Upstream
98// 29.0.3 leaves HAL doc macros, Deref imports, and BufferMappedRange::len
99// unused on that target; they are not Tilo changes.
100#![cfg_attr(
101 target_arch = "wasm32",
102 allow(unused_macros, unused_imports, dead_code)
103)]
104
105extern crate alloc;
106#[cfg(any(std, test))]
107extern crate std;
108#[cfg(wgpu_core)]
109pub extern crate wgpu_core as wgc;
110#[cfg(wgpu_core)]
111pub extern crate wgpu_hal as hal;
112pub extern crate wgpu_types as wgt;
113
114//
115//
116// Modules
117//
118//
119
120mod api;
121mod backend;
122mod cmp;
123mod dispatch;
124mod macros;
125pub mod util;
126
127//
128//
129// Public re-exports
130//
131//
132
133#[cfg(custom)]
134pub use backend::custom;
135
136pub use api::*;
137pub use wgt::{
138 AdapterInfo, AddressMode, AllocatorReport, AstcBlock, AstcChannel, Backend, BackendOptions,
139 Backends, BindGroupLayoutEntry, BindingType, BlendComponent, BlendFactor, BlendOperation,
140 BlendState, BufferAddress, BufferBindingType, BufferSize, BufferTextureCopyInfo,
141 BufferTransition, BufferUsages, BufferUses, Color, ColorTargetState, ColorWrites,
142 CommandBufferDescriptor, CompareFunction, CompositeAlphaMode, CooperativeMatrixProperties,
143 CooperativeScalarType, CopyExternalImageDestInfo, CoreCounters, DepthBiasState,
144 DepthStencilState, DeviceLostReason, DeviceType, DownlevelCapabilities, DownlevelFlags,
145 DownlevelLimits, Dx12BackendOptions, Dx12Compiler, Dx12SwapchainKind,
146 Dx12UseFrameLatencyWaitableObject, DxcShaderModel, DynamicOffset, ExperimentalFeatures,
147 Extent3d, ExternalTextureFormat, ExternalTextureTransferFunction, Face, Features, FeaturesWGPU,
148 FeaturesWebGPU, FilterMode, ForceShaderModelToken, FrontFace, GlBackendOptions, GlDebugFns,
149 GlFenceBehavior, Gles3MinorVersion, HalCounters, ImageSubresourceRange, IndexFormat,
150 InstanceDescriptor, InstanceFlags, InternalCounters, Limits, LoadOpDontCare,
151 MemoryBudgetThresholds, MemoryHints, MipmapFilterMode, MultisampleState, NoopBackendOptions,
152 Origin2d, Origin3d, PipelineStatisticsTypes, PollError, PollStatus, PolygonMode,
153 PowerPreference, PredefinedColorSpace, PresentMode, PresentationTimestamp, PrimitiveState,
154 PrimitiveTopology, QueryType, RenderBundleDepthStencil, RequestAdapterError,
155 SamplerBindingType, SamplerBorderColor, ShaderLocation, ShaderModel, ShaderRuntimeChecks,
156 ShaderStages, StencilFaceState, StencilOperation, StencilState, StorageTextureAccess,
157 SurfaceCapabilities, SurfaceStatus, TexelCopyBufferLayout, TextureAspect, TextureChannel,
158 TextureDimension, TextureFormat, TextureFormatFeatureFlags, TextureFormatFeatures,
159 TextureSampleType, TextureTransition, TextureUsages, TextureUses, TextureViewDimension, Trace,
160 VertexAttribute, VertexFormat, VertexStepMode, WasmNotSend, WasmNotSendSync, WasmNotSync,
161 WriteOnly, WriteOnlyIter, COPY_BUFFER_ALIGNMENT, COPY_BYTES_PER_ROW_ALIGNMENT,
162 IMMEDIATE_DATA_ALIGNMENT, MAP_ALIGNMENT, MAXIMUM_SUBGROUP_MAX_SIZE, MINIMUM_SUBGROUP_MIN_SIZE,
163 QUERY_RESOLVE_BUFFER_ALIGNMENT, QUERY_SET_MAX_QUERIES, QUERY_SIZE, VERTEX_ALIGNMENT,
164};
165
166#[expect(deprecated)]
167pub use wgt::VERTEX_STRIDE_ALIGNMENT;
168
169// wasm-only types, we try to keep as many types non-platform
170// specific, but these need to depend on web-sys.
171#[cfg(web)]
172pub use wgt::{CopyExternalImageSourceInfo, ExternalImageSource};
173
174/// Re-export of our `naga` dependency.
175///
176#[cfg(wgpu_core)]
177#[cfg_attr(docsrs, doc(cfg(any(wgpu_core, naga))))]
178// We re-export wgpu-core's re-export of naga, as we may not have direct access to it.
179pub use ::wgc::naga;
180/// Re-export of our `naga` dependency.
181///
182#[cfg(all(not(wgpu_core), naga))]
183#[cfg_attr(docsrs, doc(cfg(any(wgpu_core, naga))))]
184// If that's not available, we re-export our own.
185pub use naga;
186
187/// Re-export of our `raw-window-handle` dependency.
188///
189pub use raw_window_handle as rwh;
190
191/// Re-export of our `web-sys` dependency.
192///
193#[cfg(web)]
194pub use web_sys;
195
196#[doc(hidden)]
197pub use macros::helpers as __macro_helpers;