MDN self-hosted library · e01.org

GPU: requestAdapter() method

Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.

js
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();

  // …
}
js
const adapter = await navigator.gpu.requestAdapter({
  featureLevel: "compatibility",
});
js
const hasCore = adapter.features.has("core-features-and-limits");
const device = await adapter.requestDevice({
  requiredFeatures: [...(hasCore ? ["core-features-and-limits"] : [])],
});
js
const isCore = device.features.has("core-features-and-limits");