WebGPU の新機能(Chrome 137)

François Beaufort
François Beaufort

公開日: 2025 年 5 月 26 日

externalTexture バインディングにテクスチャビューを使用する

GPUBindGroup の作成時に、GPUExternalTexture バインディングの代わりに、互換性のある GPUTextureView(2D、単一のサブリソース)を使用できるようになりました。

これにより、GPUExternalTexture(ソース動画用)と GPUTextureView(中間処理用)の両方を処理する必要がある動画エフェクト パイプラインのシェーダー ロジックを簡素化できます。また、テクスチャの取得元に応じてシェーダーを動的にコンパイルする必要がなくなります。Intent to Ship: WebGPU: externalTexture バインディング用の GPUTextureView をご覧ください。

const texture = myDevice.createTexture({
  size: [42, 42],
  format: navigator.gpu.getPreferredCanvasFormat(),
  usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.TEXTURE_BINDING,
});

const code = `
@group(0) @binding(0) var texture : texture_external;
@group(0) @binding(1) var<storage, read_write> buffer: vec2u;
    
@compute @workgroup_size(1) fn main() {
  buffer = textureDimensions(texture);
}`;

const pipeline = myDevice.createComputePipeline({
  layout: "auto",
  compute: { module: myDevice.createShaderModule({ code }) },
});

const bindGroup = myDevice.createBindGroup({
  layout: pipeline.getBindGroupLayout(0),
  entries: [
    { binding: 0, resource: texture.createView() }, // Use texture view for an externalTexture binding
    { binding: 1, resource: { buffer: myBuffer } },
  ],
});

オフセットとサイズを指定しない場合のバッファのコピー

新しい GPUCommandEncoder メソッドのオーバーロードにより、copyBufferToBuffer() を使用するときにオフセットとサイズ パラメータを省略して、バッファ全体のコピーを簡素化できます。Intent to Ship: WebGPU: copyBufferToBuffer のオーバーロードをご覧ください。

const size = 42;
const srcBuffer = myDevice.createBuffer({
  size,
  usage: GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_SRC,
});
const dstBuffer = myDevice.createBuffer({
  size,
  usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ,
});

// Copy entire buffer.
myCommandEncoder.copyBufferToBuffer(srcBuffer, dstBuffer);

// This is the same as the following.
// myCommandEncoder.copyBufferToBuffer(srcBuffer, 0, dstBuffer, 0, size);

アトミックへのポインタを使用する WGSL workgroupUniformLoad

デベロッパーの利便性を高めるために、WGSL に新しい workgroupUniformLoad(ptr) オーバーロードが追加されました。ptr が指す値をアトミックに読み込み、ワークグループ内のすべての呼び出しに返します。ここで、ptr はワークグループ変数内のアトミックへのポインタです。問題 408241039 をご覧ください。

@group(0) @binding(0) var<storage, read_write> buffer : array<u32, 1>;

var<workgroup> wgvar : atomic<u32>;

@compute @workgroup_size(1, 1)
fn main(@builtin(local_invocation_index) lid: u32) {
  if (lid == 0) {
    atomicStore(&(wgvar), 42u);
  }
  buffer[lid] = workgroupUniformLoad(&wgvar);
}

GPUAdapterInfo の powerPreference 属性

ユーザーが chrome://flags/#enable-webgpu-developer-features で「WebGPU デベロッパー機能」フラグを有効にしている場合、非標準の powerPreference GPUAdapterInfo 文字列属性を使用できるようになりました。サポートされている場合、powerPreference の値は、GPURequestAdapterOptions で使用された GPUPowerPreference の値に応じて、"low-power" または "high-performance" のいずれかになります。CL 6438860 をご覧ください。

function checkPowerPreferenceForGpuDevice(device) {
  const powerPreference = device.adapterInfo.powerPreference;
  if (powerPreference === "high-performance") {
    // High-performance GPU detected. Enabling enhanced graphics settings.
  } else if (powerPreference === "low-power") {
    // Low-power GPU detected. Optimizing for battery life.
  }
}

GPURequestAdapterOptions の compatibilityMode 属性を削除

試験運用版の GPURequestAdapterOptions compatibilityMode 属性は削除され、Chrome 133 で追加された標準化された featureLevel 属性に置き換えられました。問題 366151404 をご覧ください。

Dawn の更新

デベロッパーは、webgpu.h を使用して WebAssembly と特定のプラットフォームの両方をターゲットにし、C++ などの言語で WebGPU プロジェクトを構築できます。Dawn の最新リリース「emdawnwebgpu」(「Emscripten Dawn WebGPU」)は、ブラウザ API で最新の標準化された webgpu.h を実装します。

Emdawnwebgpu は、Emscripten の(現在はメンテナンス対象外)組み込みバインディング(USE_WEBGPU)の(メンテナンス対象)フォークです。新しい開発はすべて emdawnwebgpu で行われ、デベロッパーが emdawnwebgpu に移行するにつれて、Emscripten の組み込みバインディングは削除されます。Emdawnwebgpu の C ヘッダーは Dawn のヘッダーに非常に近いですが、組み込みバインディングは大幅に古くなっています。

Dawn の GitHub リリースページから emdawnwebgpu をダウンロードし、パッケージの README.md で使用方法を確認します。ソースファイルは Dawn リポジトリにあります。

詳細なガイドについては、更新された WebGPU を使用してアプリを作成するをご覧ください。

以下に、主なハイライトをいくつかご紹介します。コミットの一覧(すべて網羅)をご覧ください。

WebGPU の新機能

WebGPU の新機能シリーズで取り上げられたすべての内容のリスト。

Chrome 138

Chrome 137

Chrome 136

Chrome 135

Chrome 134

Chrome 133

Chrome 132

Chrome 131

Chrome 130

Chrome 129

Chrome 128

Chrome 127

Chrome 126

Chrome 125

Chrome 124

Chrome 123

Chrome 122

Chrome 121

Chrome 120

Chrome 119

Chrome 118

Chrome 117

Chrome 116

Chrome 115

Chrome 114

Chrome 113