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// `-Znext-solver` requires deeper recursion limits (at least for now) to prove Send/Sync
77#![recursion_limit = "256"]
78#![cfg_attr(docsrs, feature(doc_cfg))]
79#![doc(html_logo_url = "https://raw.githubusercontent.com/gfx-rs/wgpu/trunk/logo.png")]
80#![warn(
81 clippy::alloc_instead_of_core,
82 clippy::allow_attributes,
83 clippy::std_instead_of_alloc,
84 clippy::std_instead_of_core,
85 missing_docs,
86 rust_2018_idioms,
87 unsafe_op_in_unsafe_fn
88)]
89#![allow(
90 // We need to investiagate these.
91 clippy::large_enum_variant,
92 // These degrade readability significantly.
93 clippy::bool_assert_comparison,
94 clippy::bool_comparison,
95)]
96// NOTE: Keep this in sync with `wgpu-core`.
97#![cfg_attr(not(send_sync), allow(clippy::arc_with_non_send_sync))]
98#![cfg_attr(not(any(wgpu_core, webgpu)), allow(unused))]
99
100extern crate alloc;
101#[cfg(any(std, test))]
102extern crate std;
103#[cfg(wgpu_core)]
104pub extern crate wgpu_core as wgc;
105#[cfg(wgpu_core)]
106pub extern crate wgpu_hal as hal;
107pub extern crate wgpu_types as wgt;
108
109//
110//
111// Modules
112//
113//
114
115mod api;
116mod backend;
117mod cmp;
118mod dispatch;
119mod macros;
120pub mod util;
121
122//
123//
124// Public re-exports
125//
126//
127
128#[cfg(custom)]
129pub use backend::custom;
130
131pub use api::*;
132pub use wgt::{
133 AdapterInfo, AddressMode, AllocatorReport, AstcBlock, AstcChannel, Backend, BackendOptions,
134 Backends, BindGroupLayoutEntry, BindingType, BlendComponent, BlendFactor, BlendOperation,
135 BlendState, BufferAddress, BufferBindingType, BufferSize, BufferTextureCopyInfo,
136 BufferTransition, BufferUsages, BufferUses, Color, ColorTargetState, ColorWrites,
137 CommandBufferDescriptor, CompareFunction, CompositeAlphaMode, CooperativeMatrixProperties,
138 CooperativeScalarType, CopyExternalImageDestInfo, CoreCounters, DepthBiasState,
139 DepthStencilState, DeviceLostReason, DeviceType, DownlevelCapabilities, DownlevelFlags,
140 DownlevelLimits, Dx12BackendOptions, Dx12Compiler, Dx12SwapchainKind,
141 Dx12UseFrameLatencyWaitableObject, DxcShaderModel, DynamicOffset, ExperimentalFeatures,
142 Extent3d, ExternalTextureFormat, ExternalTextureTransferFunction, Face, Features, FeaturesWGPU,
143 FeaturesWebGPU, FilterMode, ForceShaderModelToken, FrontFace, GlBackendOptions, GlDebugFns,
144 GlFenceBehavior, Gles3MinorVersion, HalCounters, ImageSubresourceRange, IndexFormat,
145 InstanceDescriptor, InstanceFlags, InternalCounters, Limits, LoadOpDontCare,
146 MemoryBudgetThresholds, MemoryHints, MipmapFilterMode, MultisampleState, NoopBackendOptions,
147 Origin2d, Origin3d, PassthroughShaderEntryPoint, PipelineStatisticsTypes, PollError,
148 PollStatus, PolygonMode, PowerPreference, PredefinedColorSpace, PresentMode,
149 PresentationTimestamp, PrimitiveState, PrimitiveTopology, QueryType, RenderBundleDepthStencil,
150 RequestAdapterError, SamplerBindingType, SamplerBorderColor, ShaderLocation, ShaderModel,
151 ShaderRuntimeChecks, ShaderStages, StencilFaceState, StencilOperation, StencilState,
152 StorageTextureAccess, SurfaceCapabilities, SurfaceStatus, TexelCopyBufferLayout, TextureAspect,
153 TextureChannel, TextureDimension, TextureFormat, TextureFormatFeatureFlags,
154 TextureFormatFeatures, TextureSampleType, TextureTransition, TextureUsages, TextureUses,
155 TextureViewDimension, Trace, VertexAttribute, VertexFormat, VertexStepMode, WasmNotSend,
156 WasmNotSendSync, WasmNotSync, WriteOnly, WriteOnlyIter, COPY_BUFFER_ALIGNMENT,
157 COPY_BYTES_PER_ROW_ALIGNMENT, IMMEDIATE_DATA_ALIGNMENT, MAP_ALIGNMENT,
158 MAXIMUM_SUBGROUP_MAX_SIZE, MINIMUM_SUBGROUP_MIN_SIZE, QUERY_RESOLVE_BUFFER_ALIGNMENT,
159 QUERY_SET_MAX_QUERIES, QUERY_SIZE, VERTEX_ALIGNMENT,
160};
161
162#[expect(deprecated)]
163pub use wgt::VERTEX_STRIDE_ALIGNMENT;
164
165// wasm-only types, we try to keep as many types non-platform
166// specific, but these need to depend on web-sys.
167#[cfg(web)]
168pub use wgt::{CopyExternalImageSourceInfo, ExternalImageSource};
169
170/// Re-export of our `naga` dependency.
171///
172#[cfg(wgpu_core)]
173#[cfg_attr(docsrs, doc(cfg(any(wgpu_core, naga))))]
174// We re-export wgpu-core's re-export of naga, as we may not have direct access to it.
175pub use ::wgc::naga;
176/// Re-export of our `naga` dependency.
177///
178#[cfg(all(not(wgpu_core), naga))]
179#[cfg_attr(docsrs, doc(cfg(any(wgpu_core, naga))))]
180// If that's not available, we re-export our own.
181pub use naga;
182
183/// Re-export of our `raw-window-handle` dependency.
184///
185pub use raw_window_handle as rwh;
186
187/// Re-export of our `web-sys` dependency.
188///
189#[cfg(web)]
190pub use web_sys;
191
192#[doc(hidden)]
193pub use macros::helpers as __macro_helpers;