WebGPU の新機能(Chrome 137)

François Beaufort
François Beaufort

公開日: 2025 年 5 月 26 日

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

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

これにより、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 デベロッパー機能] フラグを有効にすると、非標準の powerPreference GPUAdapterInfo 文字列属性を使用できるようになりました。サポートされている場合、powerPreference の値は、GPUPowerPreference の値に応じて、"low-power" または "high-performance" になります。これは、GPURequestAdapterOptions で使用されました。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 の更新

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

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

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

完全なガイドについては、更新された WebGPU でアプリを構築する ドキュメントをご覧ください。

これは主なハイライトの一部にすぎません。コミットの完全なリストをご覧ください。

WebGPU の新機能

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

Chrome 147 ~ 148

Chrome 146

Chrome 145

Chrome 144

Chrome 143

Chrome 142

Chrome 141

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