GPUAdapter はブラウザが選んだ GPU と、利用できる機能・上限を表します。そこから GPUDevice を取得し、GPU で使うデータや描画手順を作成してコマンドを送ります。
// WebGPU の描画先にする Canvas を HTML から探す
const canvas = document.querySelector<HTMLCanvasElement>("#gpu-canvas");
if (!canvas) throw new Error("Canvas が見つかりません");
// ブラウザに、この環境で利用する GPU を選んでもらう
const adapter: GPUAdapter | null = await navigator.gpu.requestAdapter();
if (!adapter) throw new Error("GPU が見つかりません");
// GPU で使うデータや描画手順を作り、命令するための Device を取得する
const device: GPUDevice = await adapter.requestDevice();
// Canvas へ WebGPU で描画するための Context を取得する
const context = canvas.getContext("webgpu");
if (!context) throw new Error("WebGPU context を作成できません");
// この環境の Canvas が効率よく表示できる色形式を選ぶ
const format: GPUTextureFormat = navigator.gpu.getPreferredCanvasFormat();
// 使用する Device と色形式を、Canvas の Context へ設定する
context.configure({ device, format } satisfies GPUCanvasConfiguration);
Adapter選択された GPU と利用可能な機能Deviceリソース作成とコマンド送信ContextCanvas の描画先