Crate wgpu

Source
Expand description

A cross-platform graphics and compute library based on WebGPU.

To start using the API, create an Instance.

§Feature flags

§Backends

  • dx12 (enabled by default) — Enables the DX12 backend on Windows.
  • metal (enabled by default) — Enables the Metal backend on macOS & iOS.
  • vulkan (enabled by default) — Enables the Vulkan backend on Windows, Linux, and Android.
  • gles (enabled by default) — Enables the OpenGL/GLES backend on Windows, Linux, Android, and Emscripten.
  • webgpu (enabled by default) — Enables the WebGPU backend on WebAssembly.

§Conditional Backends

  • angle — Enables the GLES backend on macOS only for use with ANGLE.

  • vulkan-portability — Enables the Vulkan backend on macOS & iOS only for use with MoltenVK.

  • webgl — Enables the GLES backend on WebAssembly only.

  • noop — Enables the noop backend for testing.

    This backend allows creating resources such as buffers and textures, but performs no computation. Because it lacks basic functionality, it is only actually used if explicitly enabled through NoopBackendOptions.

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

These features enable support for that input language on all platforms. We will translate the input language to whatever the backend requires.

  • 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.

§Assertions and Serialization

  • 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 via serde on common wgpu types.

§External libraries

The following features facilitate integration with third-party supporting libraries.

  • static-dxc — Enables statically linking DXC.

    Normally, to use the modern DXC shader compiler with WGPU, the final application must be shipped alongside dxcompiler.dll and dxil.dll (which can be downloaded from Microsoft’s GitHub). This feature statically links a version of DXC so that no external binaries are required to compile DX12 shaders.

§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 — Implement Send and Sync 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 and Sync 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 is a definitionally single-threaded 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 extern crate wgpu_hal as hal;
pub extern crate wgpu_core as wgc;
pub extern crate wgpu_types as wgt;
pub use ::wgc::naga;wgpu_core or naga
pub use raw_window_handle as rwh;

Modules§

customcustom
Provides wrappers custom backend implementations
util
Utility structures and functions that are built on top of the main wgpu API.

Macros§

include_spirvspirv
Macro to load a SPIR-V module statically.
include_spirv_raw
Macro to load raw SPIR-V data statically, for use with Features::SPIRV_SHADER_PASSTHROUGH.
include_wgsl
Load WGSL source code from a file at compile time.
vertex_attr_array
Macro to produce an array of VertexAttribute.

Structs§

Adapter
Handle to a physical graphics and/or compute device.
AdapterInfo
Information about an adapter.
AllocatorReport
A report that can be generated for informational purposes using Allocator::generate_report().
BackendOptions
Options that are passed to a given backend.
Backends
Represents the backends that wgpu will use.
BindGroup
Handle to a binding group.
BindGroupDescriptor
Describes a group of bindings and the resources to be bound.
BindGroupEntry
An element of a BindGroupDescriptor, consisting of a bindable resource and the slot to bind it to.
BindGroupLayout
Handle to a binding group layout.
BindGroupLayoutDescriptor
Describes a BindGroupLayout.
BindGroupLayoutEntry
Describes a single binding inside a bind group.
Blas
Bottom Level Acceleration Structure (BLAS).
BlasBuildEntry
Builds the given sets of geometry into the given Blas.
BlasTriangleGeometry
Definition for a triangle geometry for a Bottom Level Acceleration Structure (BLAS).
BlendComponent
Describes a blend component of a BlendState.
BlendState
Describe the blend state of a render pipeline, within ColorTargetState.
Buffer
Handle to a GPU-accessible buffer.
BufferAsyncError
Error occurred when trying to async map a buffer.
BufferBinding
Describes the segment of a buffer to bind.
BufferSlice
A slice of a Buffer, to be mapped, used for vertex or index data, or the like.
BufferTransition
A buffer transition for use with CommandEncoder::transition_resources.
BufferUsages
Different ways that you can use a buffer.
BufferUses
Similar to BufferUsages, but used only for CommandEncoder::transition_resources.
BufferView
A read-only view of a mapped buffer’s bytes.
BufferViewMut
A write-only view of a mapped buffer’s bytes.
Color
RGBA double precision color.
ColorTargetState
Describes the color state of a render pipeline.
ColorWrites
Color write mask. Disabled color channels will not be written to.
CommandBuffer
Handle to a command buffer on the GPU.
CommandBufferDescriptor
Describes a CommandBuffer.
CommandEncoder
Encodes a series of GPU operations.
CompilationInfo
Compilation information for a shader module.
CompilationMessage
A single message from the shader compilation process.
ComputePass
In-progress recording of a compute pass.
ComputePassDescriptor
Describes the attachments of a compute pass.
ComputePassTimestampWrites
Describes the timestamp writes of a compute pass.
ComputePipeline
Handle to a compute pipeline.
ComputePipelineDescriptor
Describes a compute pipeline.
ContextBlasBuildEntry
Context version see BlasBuildEntry.
ContextBlasTriangleGeometry
Context version of BlasTriangleGeometry.
CopyExternalImageDestInfo
View of a texture which can be used to copy to a texture, including color space and alpha premultiplication information.
CoreCounters
wgpu-core’s part of InternalCounters.
CreateSurfaceError
Instance::create_surface() or a related function failed.
DepthBiasState
Describes the biasing setting for the depth target.
DepthStencilState
Describes the depth/stencil state in a render pipeline.
Device
Open connection to a graphics and/or compute device.
DownlevelCapabilities
Lists various ways the underlying platform does not conform to the WebGPU standard.
DownlevelFlags
Binary flags listing features that may or may not be present on downlevel adapters.
DownlevelLimits
Represents the sets of additional limits on an adapter, which take place when running on downlevel backends.
Dx12BackendOptions
Configuration for the DX12 backend.
Extent3d
Extent of a texture related operation.
Features
Features that are not guaranteed to be supported.
FeaturesWGPU
Features that are not guaranteed to be supported.
FeaturesWebGPU
Features that are not guaranteed to be supported.
FragmentState
Describes the fragment processing in a render pipeline.
GlBackendOptions
Configuration for the OpenGL/OpenGLES backend.
HalCounters
wgpu-hal’s part of InternalCounters.
ImageSubresourceRange
Subresource range within an image
Instance
Context for all other wgpu objects. Instance of wgpu.
InstanceDescriptor
Options for creating an instance.
InstanceFlags
Instance debugging flags.
InternalCounters
All internal counters, exposed for debugging purposes.
Limits
Represents the sets of limits an adapter/device supports.
MultisampleState
Describes the multi-sampling state of a render pipeline.
NoopBackendOptions
Configuration for the noop backend.
Operations
Pair of load and store operations for an attachment aspect.
Origin2d
Origin of a copy from a 2D image.
Origin3d
Origin of a copy to/from a texture.
PipelineCache
Handle to a pipeline cache, which is used to accelerate creating RenderPipelines and ComputePipelines in subsequent executions
PipelineCacheDescriptor
Describes a pipeline cache, which allows reusing compilation work between program runs.
PipelineCompilationOptions
Advanced options for use when a pipeline is compiled
PipelineLayout
Handle to a pipeline layout.
PipelineLayoutDescriptor
Describes a PipelineLayout.
PipelineStatisticsTypes
Flags for which pipeline data should be recorded in a query.
PresentationTimestamp
Nanosecond timestamp used by the presentation engine.
PrimitiveState
Describes the state of primitive assembly and rasterization in a render pipeline.
PushConstantRange
A range of push constant memory to pass to a shader stage.
QuerySet
Handle to a query set.
Queue
Handle to a command queue on a device.
QueueWriteBufferView
A write-only view into a staging buffer.
RenderBundle
Pre-prepared reusable bundle of GPU operations.
RenderBundleDepthStencil
Describes the depth/stencil attachment for render bundles.
RenderBundleEncoder
Encodes a series of GPU operations into a reusable “render bundle”.
RenderBundleEncoderDescriptor
Describes a RenderBundleEncoder.
RenderPass
In-progress recording of a render pass: a list of render commands in a CommandEncoder.
RenderPassColorAttachment
Describes a color attachment to a RenderPass.
RenderPassDepthStencilAttachment
Describes a depth/stencil attachment to a RenderPass.
RenderPassDescriptor
Describes the attachments of a render pass.
RenderPassTimestampWrites
Describes the timestamp writes of a render pass.
RenderPipeline
Handle to a rendering (graphics) pipeline.
RenderPipelineDescriptor
Describes a render (graphics) pipeline.
RequestAdapterOptionsBase
Options for requesting adapter.
RequestDeviceError
Requesting a device from an Adapter failed.
Sampler
Handle to a sampler.
ShaderModule
Handle to a compiled shader module.
ShaderModuleDescriptor
Descriptor for use with Device::create_shader_module.
ShaderRuntimeChecks
Describes how shader bound checks should be performed.
ShaderStages
Describes the shader stages that a binding will be visible from.
SourceLocation
A human-readable representation for a span, tailored for text source.
StencilFaceState
Describes stencil state in a render pipeline.
StencilState
State of the stencil operation (fixed-pipeline stage).
SubmissionIndex
Identifier for a particular call to Queue::submit. Can be used as part of an argument to Device::poll to block for a particular submission to finish.
Surface
Handle to a presentable surface.
SurfaceCapabilities
Defines the capabilities of a given surface and adapter.
SurfaceTexture
Surface texture that can be rendered to. Result of a successful call to Surface::get_current_texture.
TexelCopyBufferInfoBase
View of a buffer which can be used to copy to/from a texture.
TexelCopyBufferLayout
Layout of a texture in a buffer’s memory.
TexelCopyTextureInfoBase
View of a texture which can be used to copy to/from a buffer/texture.
Texture
Handle to a texture on the GPU.
TextureFormatFeatureFlags
Feature flags for a texture format.
TextureFormatFeatures
Features supported by a given texture format
TextureTransition
A texture transition for use with CommandEncoder::transition_resources.
TextureUsages
Different ways that you can use a texture.
TextureUses
Similar to TextureUsages, but used only for CommandEncoder::transition_resources.
TextureView
Handle to a texture view.
Tlas
Top Level Acceleration Structure (TLAS).
TlasBuildEntry
Entry for a top level acceleration structure build. Used with raw instance buffers for an unvalidated builds. See TlasPackage for the safe version.
TlasInstance
Safe instance for a Tlas.
TlasPackage
The safe version of TlasBuildEntry, containing TlasInstances instead of a raw buffer.
VertexAttribute
Vertex inputs (attributes) to shaders.
VertexBufferLayout
Specifies an interpretation of the bytes of a vertex buffer as vertex attributes.
VertexState
Describes the vertex processing in a render pipeline.
WgslLanguageFeatures
WGSL language extensions.

Enums§

AddressMode
How edges should be handled in texture addressing.
AstcBlock
ASTC block dimensions
AstcChannel
ASTC RGBA channel
Backend
Backends supported by wgpu.
BindingResource
Resource to be bound by a BindGroup for use with a pipeline.
BindingType
Type of a binding in a bind group layout.
BlasGeometries
Contains the sets of geometry that go into a Blas.
BlendFactor
Alpha blend factor.
BlendOperation
Alpha blend operation.
BufferBindingType
Specific type of a buffer binding.
CompareFunction
Comparison function used for depth and stencil operations.
CompilationMessageType
The type of a compilation message.
CompositeAlphaMode
Specifies how the alpha channel of the textures should be handled during compositing.
ContextBlasGeometries
Context version of BlasGeometries.
DeviceLostReason
Reason for “lose the device”.
DeviceType
Supported physical device types.
Dx12Compiler
Selects which DX12 shader compiler to use.
DxcShaderModel
DXC shader model.
Error
Errors resulting from usage of GPU APIs.
ErrorFilter
Kinds of Errors a Device::push_error_scope() may be configured to catch.
Face
Face of a vertex.
FilterMode
Texel mixing mode when sampling between texels.
FrontFace
Vertex winding order which classifies the “front” face of a triangle.
GlFenceBehavior
Dictate the behavior of fences in OpenGL.
Gles3MinorVersion
Selects which OpenGL ES 3 minor version to request.
IndexFormat
Format of indices used with pipeline.
LoadOp
Operation to perform to the output attachment at the start of a render pass.
MaintainBase
Passed to Device::poll to control how and if it should block.
MapMode
Type of buffer mapping.
MemoryHints
Hints to the device about the memory allocation strategy.
PollError
Error states after a device poll
PollStatus
Status of device poll operation.
PolygonMode
Type of drawing mode for polygons
PowerPreference
Power Preference when choosing a physical adapter.
PredefinedColorSpace
Color spaces supported on the web.
PresentMode
Timing and queueing with which frames are actually displayed to the user.
PrimitiveTopology
Primitive type the input mesh is composed of.
QueryType
Type of query contained in a QuerySet.
RequestAdapterError
Error when Instance::request_adapter() fails.
SamplerBindingType
Specific type of a sampler binding.
SamplerBorderColor
Color variation to use when sampler addressing mode is AddressMode::ClampToBorder
ShaderModel
Collections of shader features a device supports if they support less than WebGPU normally allows.
ShaderSource
Source of a shader module.
StencilOperation
Operation to perform on the stencil value.
StorageTextureAccess
Specific type of a sample in a texture binding.
StoreOp
Operation to perform to the output attachment at the end of a render pass.
SurfaceError
Result of an unsuccessful call to Surface::get_current_texture.
SurfaceStatus
Status of the received surface image.
SurfaceTarget
The window/canvas/surface/swap-chain/etc. a surface is attached to, for use with safe surface creation.
SurfaceTargetUnsafe
The window/canvas/surface/swap-chain/etc. a surface is attached to, for use with unsafe surface creation.
TextureAspect
Selects a subset of the data a Texture holds.
TextureDimension
Dimensionality of a texture.
TextureFormat
Format in which a texture’s texels are stored in GPU memory.
TextureSampleType
Specific type of a sample in a texture binding.
TextureViewDimension
Dimensions of a particular texture view.
Trace
Controls API call tracing and specifies where the trace is written.
VertexFormat
Vertex Format for a VertexAttribute (input).
VertexStepMode
Whether a vertex buffer is indexed by vertex or by instance.

Constants§

COPY_BUFFER_ALIGNMENT
Buffer to buffer copy as well as buffer clear offsets and sizes must be aligned to this number.
COPY_BYTES_PER_ROW_ALIGNMENT
Buffer-to-texture copies must have bytes_per_row aligned to this number.
MAP_ALIGNMENT
Minimum alignment of buffer mappings.
PUSH_CONSTANT_ALIGNMENT
Ranges of writes to push constant storage must be at least this aligned.
QUERY_RESOLVE_BUFFER_ALIGNMENT
An offset into the query resolve buffer has to be aligned to this.
QUERY_SET_MAX_QUERIES
Maximum queries in a QuerySetDescriptor.
QUERY_SIZE
Size in bytes of a single piece of query data.
VERTEX_STRIDE_ALIGNMENT
Vertex buffer strides have to be a multiple of this number.

Traits§

UncapturedErrorHandler
Type for the callback of uncaptured error handler
WasmNotSend
WasmNotSendSync
WasmNotSync
WindowHandle
Super trait for window handles as used in SurfaceTarget.

Type Aliases§

AccelerationStructureFlags
Flags for an acceleration structure.
AccelerationStructureGeometryFlags
Flags for a geometry inside a bottom level acceleration structure.
AccelerationStructureUpdateMode
Update mode for acceleration structure builds.
BlasGeometrySizeDescriptors
Descriptor for the size defining attributes, for a bottom level acceleration structure.
BlasTriangleGeometrySizeDescriptor
Descriptor for the size defining attributes of a triangle geometry, for a bottom level acceleration structure.
BufferAddress
Integral type used for Buffer offsets and sizes.
BufferDescriptor
Describes a Buffer.
BufferSize
Integral type used for BufferSlice sizes.
CommandEncoderDescriptor
Describes a CommandEncoder.
CreateBlasDescriptor
Descriptor to create bottom level acceleration structures.
CreateTlasDescriptor
Descriptor to create top level acceleration structures.
DeviceDescriptor
Describes a Device.
DynamicOffset
Integral type used for dynamic bind group offsets.
ErrorSource
Lower level source of the error.
ImageCopyBufferDeprecated
Old name for a TexelCopyBufferInfo.
ImageCopyTextureDeprecated
Old name for a TexelCopyTextureInfo.
ImageCopyTextureTaggedDeprecated
Old name for a CopyExternalImageDestInfo.
ImageDataLayoutDeprecated
Old name for a TexelCopyBufferLayout.
Label
Object debugging label.
PollType
Passed to Device::poll to control how and if it should block.
QuerySetDescriptor
Describes a QuerySet.
RenderBundleDescriptor
Describes a RenderBundle.
RequestAdapterOptions
Additional information required when requesting an adapter.
SamplerDescriptor
Describes a Sampler.
ShaderLocation
Integral type used for binding locations in shaders.
ShaderModuleDescriptorMsl
Descriptor for a shader module given by Metal MSL source.
ShaderModuleDescriptorPassthrough
Descriptor for a shader module that will bypass wgpu’s shader tooling, for use with Device::create_shader_module_passthrough.
ShaderModuleDescriptorSpirV
Descriptor for a shader module given by SPIR-V binary.
SurfaceConfiguration
Describes a Surface.
TexelCopyBufferInfo
View of a buffer which can be used to copy to/from a texture.
TexelCopyTextureInfo
View of a texture which can be used to copy to/from a buffer/texture.
TextureDescriptor
Describes a Texture.
TextureViewDescriptor
Describes a TextureView.