Firefox Tomorrow

web api interface

GPU

View on MDN ↗

Secure contextAvailable in workers

The GPU interface of the WebGPU API is the starting point for using WebGPU. It can be used to return a GPUAdapter from which you can request devices, configure features and limits, and more.

The GPU object for the current context is accessed via the gpu or gpu properties.

Instance properties

Instance methods

  • requestAdapter()
    • : Returns a Promise that fulfills with a GPUAdapter object instance. From this you can request a GPUDevice, which is the primary interface for using WebGPU functionality.
  • getPreferredCanvasFormat()
    • : Returns the optimal canvas texture format for displaying 8-bit depth, standard dynamic range content on the current system.

Examples

Requesting an adapter and a device

async function init() {
  if (!navigator.gpu) {
    throw Error("WebGPU not supported.");
  }

  const adapter = await navigator.gpu.requestAdapter();
  if (!adapter) {
    throw Error("Couldn't request WebGPU adapter.");
  }

  const device = await adapter.requestDevice();

  // …
}

Configuring a GPUCanvasContext with the optimal texture format

const canvas = document.querySelector("#gpuCanvas");
const context = canvas.getContext("webgpu");

context.configure({
  device,
  format: navigator.gpu.getPreferredCanvasFormat(),
  alphaMode: "premultiplied",
});

Specifications

SpecificationsStandards references are available on the canonical MDN page.

Browser compatibility

Browser compatibilityCompatibility data is available on the canonical MDN page.

See also