WebGPU の新機能(Chrome 137)

François Beaufort
François Beaufort

公開日: 2025 年 5 月 26 日

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

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

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

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 overload をご覧ください。

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 Developer Features」フラグを有効にしている場合、非標準の 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 属性は、標準化された featureLevel 属性(Chrome 133 で追加)に置き換えられました。問題 366151404 をご覧ください。

Dawn のアップデート

デベロッパーは、C++ などの言語で WebGPU プロジェクトを構築し、webgpu.h を使用して WebAssembly と特定のプラットフォームの両方をターゲットにできます。新たにリリースされた 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 140

Chrome 139

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