Skip to content

WebGPU API Reference

These pages list the WebGPU interfaces used by the tutorials. Each page stays with members that exist in the specification. The complete definitions are in the WebGPU specification.

interface GPU {
requestAdapter(options?: GPURequestAdapterOptions): Promise<GPUAdapter | null>;
getPreferredCanvasFormat(): GPUTextureFormat;
}
interface GPUAdapter {
readonly features: GPUSupportedFeatures;
readonly limits: GPUSupportedLimits;
readonly info: GPUAdapterInfo;
requestDevice(descriptor?: GPUDeviceDescriptor): Promise<GPUDevice>;
}

GPUDevice creates the resources. Common methods:

MethodObject
createBufferGPUBuffer
createTextureGPUTexture
createSamplerGPUSampler
createBindGroupLayout / createBindGroupGPUBindGroup
createPipelineLayoutCombines bind group layouts into a pipeline layout
createShaderModuleCompiles WGSL
createRenderPipelineGPURenderPipeline
createComputePipelineGPUComputePipeline
createCommandEncoderGPUCommandEncoder
pushErrorScope / popErrorScopeCapture validation errors
destroyDestroy the device and resources it created

The device also exposes read-only features, limits, and queue. lost is a promise that resolves when the device is lost. Validation errors that are not captured by an error scope are delivered as uncapturederror events.

getPreferredCanvasFormat() returns only "rgba8unorm" or "bgra8unorm". Use that value for the canvas color attachment and the fragment target format.

  • Vertex and index data are buffers, bound with setVertexBuffer() and setIndexBuffer().
  • Uniforms, storage buffers, textures, and samplers go in a bind group and are bound with setBindGroup().
  • Commands are recorded into a GPUCommandEncoder. finish() returns a GPUCommandBuffer, and GPUQueue.submit() runs it.

Tutorial order:

  1. WGSL basics
  2. Render pipeline
  3. Buffers
  4. Bind groups
  5. Uniform buffers
  6. Textures and samplers
  7. Depth buffer
  8. Compute shaders