Expand description
A cross-platform graphics and compute library based on WebGPU.
To start using the API, create an Instance
.
§Feature flags
§Backends
⚠️ WIP: Not all backends can be manually configured today. On Windows, Linux & Android the Vulkan & GLES backends are always enabled. See #3514 for more details.
-
dx12
(enabled by default) — Enables the DX12 backend on Windows. -
metal
(enabled by default) — Enables the Metal backend on macOS & iOS. -
webgpu
(enabled by default) — Enables the WebGPU backend on Wasm. Disabled when targetingemscripten
. -
angle
— Enables the GLES backend via ANGLE on macOS using. -
vulkan-portability
— Enables the Vulkan backend on macOS & iOS. -
webgl
— Enables the GLES backend on Wasm- ⚠️ WIP: Currently will also enable GLES dependencies on any other targets.
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
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.
§Logging & Tracing
The following features do not have any effect on the WebGPU backend.
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 viaserde
on common wgpu types.replay
— Allow deserializing of trace capture files that were written with thetrace
feature. To replay a trace file use the wgpu player.
§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
— ImplementSend
andSync
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
andSync
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 we know we are definitely not in a multithreaded 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 use ::wgc as core;
wgpu_core
pub use ::hal;
wgpu_core
pub use ::wgc::naga;
wgpu_core
ornaga
pub use raw_window_handle as rwh;
pub use web_sys;
webgl
orwebgpu
Modules§
- Utility structures and functions that are built on top of the main
wgpu
API.
Macros§
- include_
spirv spirv
Macro to load a SPIR-V module statically. - Macro to load raw SPIR-V data statically, for use with
Features::SPIRV_SHADER_PASSTHROUGH
. - Load WGSL source code from a file at compile time.
- Macro to produce an array of
VertexAttribute
.
Structs§
- Handle to a physical graphics and/or compute device.
- Information about an adapter.
- Represents the backends that wgpu will use.
- Handle to a binding group.
- Describes a group of bindings and the resources to be bound.
- An element of a
BindGroupDescriptor
, consisting of a bindable resource and the slot to bind it to. - Handle to a binding group layout.
- Describes a
BindGroupLayout
. - Describes a single binding inside a bind group.
- Describes a blend component of a
BlendState
. - Describe the blend state of a render pipeline, within
ColorTargetState
. - Handle to a GPU-accessible buffer.
- Error occurred when trying to async map a buffer.
- Describes the segment of a buffer to bind.
- A slice of a
Buffer
, to be mapped, used for vertex or index data, or the like. - Different ways that you can use a buffer.
- A read-only view of a mapped buffer’s bytes.
- A write-only view of a mapped buffer’s bytes.
- RGBA double precision color.
- Describes the color state of a render pipeline.
- Color write mask. Disabled color channels will not be written to.
- Handle to a command buffer on the GPU.
- Describes a
CommandBuffer
. - Encodes a series of GPU operations.
- Compilation information for a shader module.
- A single message from the shader compilation process.
- In-progress recording of a compute pass.
- Describes the attachments of a compute pass.
- Describes the timestamp writes of a compute pass.
- Handle to a compute pipeline.
- Describes a compute pipeline.
wgpu-core
’s internal counters.Instance::create_surface()
or a related function failed.- Describes the biasing setting for the depth target.
- Describes the depth/stencil state in a render pipeline.
- Open connection to a graphics and/or compute device.
- Lists various ways the underlying platform does not conform to the WebGPU standard.
- Binary flags listing features that may or may not be present on downlevel adapters.
- Extent of a texture related operation.
- Features that are not guaranteed to be supported.
- Describes the fragment processing in a render pipeline.
wgpu-hal
’s internal counters.- View of a buffer which can be used to copy to/from a texture.
- Image
Copy External Image webgpu
orwebgl
View of an external texture that can be used to copy to a texture. - View of a texture which can be used to copy to/from a buffer/texture.
- View of a texture which can be used to copy to a texture, including color space and alpha premultiplication information.
- Layout of a texture in a buffer’s memory.
- Subresource range within an image
- Context for all other wgpu objects. Instance of wgpu.
- Options for creating an instance.
- Instance debugging flags.
- All internal counters, exposed for debugging purposes.
- Represents the sets of limits an adapter/device supports.
- Describes the multi-sampling state of a render pipeline.
- Pair of load and store operations for an attachment aspect.
- Origin of a copy from a 2D image.
- Origin of a copy to/from a texture.
- Handle to a pipeline cache, which is used to accelerate creating
RenderPipeline
s andComputePipeline
s in subsequent executions - Describes a pipeline cache, which allows reusing compilation work between program runs.
- Advanced options for use when a pipeline is compiled
- Handle to a pipeline layout.
- Describes a
PipelineLayout
. - Flags for which pipeline data should be recorded.
- Nanosecond timestamp used by the presentation engine.
- Describes the state of primitive assembly and rasterization in a render pipeline.
- A range of push constant memory to pass to a shader stage.
- Handle to a query set.
- Handle to a command queue on a device.
- A write-only view into a staging buffer.
- Pre-prepared reusable bundle of GPU operations.
- Describes the depth/stencil attachment for render bundles.
- Encodes a series of GPU operations into a reusable “render bundle”.
- Describes a
RenderBundleEncoder
. - In-progress recording of a render pass: a list of render commands in a
CommandEncoder
. - Describes a color attachment to a
RenderPass
. - Describes a depth/stencil attachment to a
RenderPass
. - Describes the attachments of a render pass.
- Describes the timestamp writes of a render pass.
- Handle to a rendering (graphics) pipeline.
- Describes a render (graphics) pipeline.
- Options for requesting adapter.
- Requesting a device from an
Adapter
failed. - Handle to a sampler.
- Describes a
Sampler
. - Handle to a compiled shader module.
- Descriptor for use with
Device::create_shader_module
. - Descriptor for a shader module given by SPIR-V binary, for use with
Device::create_shader_module_spirv
. - Describes the shader stages that a binding will be visible from.
- A human-readable representation for a span, tailored for text source.
- Describes stencil state in a render pipeline.
- State of the stencil operation (fixed-pipeline stage).
- Identifier for a particular call to
Queue::submit
. Can be used as part of an argument toDevice::poll
to block for a particular submission to finish. - Handle to a presentable surface.
- Defines the capabilities of a given surface and adapter.
- Surface texture that can be rendered to. Result of a successful call to
Surface::get_current_texture
. - Handle to a texture on the GPU.
- Feature flags for a texture format.
- Features supported by a given texture format
- Different ways that you can use a texture.
- Handle to a texture view.
- Describes a
TextureView
. - Vertex inputs (attributes) to shaders.
- Describes how the vertex buffer is interpreted.
- Describes the vertex processing in a render pipeline.
Enums§
- How edges should be handled in texture addressing.
- ASTC block dimensions
- ASTC RGBA channel
- Backends supported by wgpu.
- Resource that can be bound to a pipeline.
- Specific type of a binding.
- Alpha blend factor.
- Alpha blend operation.
- Specific type of a buffer binding.
- Comparison function used for depth and stencil operations.
- The type of a compilation message.
- Specifies how the alpha channel of the textures should be handled during compositing.
- Reason for “lose the device”.
- Supported physical device types.
- Selects which DX12 shader compiler to use.
- Error type
- Filter for error scopes.
- External
Image Source webgpu
orwebgl
Source of an external texture copy. - Face of a vertex.
- Texel mixing mode when sampling between texels.
- Vertex winding order which classifies the “front” face of a triangle.
- Selects which OpenGL ES 3 minor version to request.
- Format of indices used with pipeline.
- Operation to perform to the output attachment at the start of a render pass.
- Passed to
Device::poll
to control how and if it should block. - Result of a maintain operation.
- Type of buffer mapping.
- Hints to the device about the memory allocation strategy.
- Type of drawing mode for polygons
- Power Preference when choosing a physical adapter.
- Color spaces supported on the web.
- Behavior of the presentation engine based on frame rate.
- Primitive type the input mesh is composed of.
- Type of query contained in a QuerySet.
- Specific type of a sampler binding.
- Color variation to use when sampler addressing mode is
AddressMode::ClampToBorder
- Collections of shader features a device supports if they support less than WebGPU normally allows.
- Source of a shader module.
- Operation to perform on the stencil value.
- Specific type of a sample in a texture binding.
- Operation to perform to the output attachment at the end of a render pass.
- Result of an unsuccessful call to
Surface::get_current_texture
. - Status of the received surface image.
- The window/canvas/surface/swap-chain/etc. a surface is attached to, for use with safe surface creation.
- The window/canvas/surface/swap-chain/etc. a surface is attached to, for use with unsafe surface creation.
- Kind of data the texture holds.
- Dimensionality of a texture.
- Underlying texture data format.
- Specific type of a sample in a texture binding.
- Dimensions of a particular texture view.
- Vertex Format for a
VertexAttribute
(input). - Whether a vertex buffer is indexed by vertex or by instance.
Constants§
- Buffer to buffer copy as well as buffer clear offsets and sizes must be aligned to this number.
- Buffer-Texture copies must have
bytes_per_row
aligned to this number. - Size to align mappings.
- Alignment all push constants need
- An offset into the query resolve buffer has to be aligned to this.
- Maximum queries in a query set
- Size of a single piece of query data.
- Vertex buffer strides have to be aligned to this number.
Traits§
- Type for the callback of uncaptured error handler
- Super trait for window handles as used in
SurfaceTarget
.
Type Aliases§
- Integral type used for buffer offsets.
- Describes a
Buffer
. - Integral type used for buffer slice sizes.
- Describes a
CommandEncoder
. - Describes a
Device
. - Integral type used for dynamic bind group offsets.
- Lower level source of the error.
- View of a buffer which can be used to copy to/from a texture.
- View of a texture which can be used to copy to/from a buffer/texture.
- View of a texture which can be used to copy to a texture, including color space and alpha premultiplication information.
- Object debugging label.
- Passed to
Device::poll
to control how and if it should block. - Describes a
QuerySet
. - Describes a
RenderBundle
. - Additional information required when requesting an adapter.
- Integral type used for binding locations in shaders.
- Describes a
Surface
. - Describes a
Texture
.