WebGPU の新機能(Chrome 118)

François Beaufort
François Beaufort

copyExternalImageToTexture() での HTMLImageElement と ImageData のサポート

copyExternalImageToTexture() メソッドを使用すると、ソース画像、動画、キャンバスから取得したスナップショットを特定の GPUTexture にコピーできます。GPUQueueソースとして HTMLImageElementImageData オブジェクトを渡せるようになりました。次の例と chromium:1471372 の問題をご覧ください。

// Fetch and decode image.
const source = document.createElement("img");
source.src = "my-image.png";
await source.decode();

// Create destination texture.
const size = [source.width, source.height];
const texture = myDevice.createTexture({
 size,
 format: "rgba8unorm",
 usage:
   GPUTextureUsage.COPY_DST |
   GPUTextureUsage.RENDER_ATTACHMENT |
   GPUTextureUsage.TEXTURE_BINDING,
});

// Copies a snapshot taken from the source image into a texture.
myDevice.queue.copyExternalImageToTexture({ source }, { texture }, size);

読み書き可能なストレージ テクスチャと読み取り専用のストレージ テクスチャの試験運用版のサポート

ストレージ テクスチャ バインディング タイプを使用すると、サンプリングを行わずにテクスチャを読み取り、シェーダー内の任意の場所に保存できます。GPUAdapter"chromium-experimental-read-write-storage-texture" 機能が利用可能になったため、この機能を使用して GPUDevice をリクエストし、バインド グループ レイアウトの作成時に GPUStorageTexture アクセスを "read-write" または "read-only" に設定できるようになりました。以前は "write-only" に制限されていました。

この機能を利用するには、WGSL コードで enable chromium_experimental_read_write_storage_texture を使用して、この拡張機能を明示的に有効にする必要があります。有効にすると、ストレージ テクスチャに read_write アクセス修飾子と read アクセス修飾子を使用できます。textureLoad() 組み込み関数と textureStore() 組み込み関数はそれに応じて動作します。また、新しい textureBarrier() 組み込み関数を使用して、ワークグループ内のテクスチャ メモリ アクセスを同期できます。次の例と dawn:1972 をご覧ください。

この機能はまだ試験運用版であり、変更される可能性があります。標準化されるまでは、--enable-dawn-features=allow_unsafe_apis フラグを指定して Chrome を実行すると、この機能を利用できます。

const feature = "chromium-experimental-read-write-storage-texture";
const adapter = await navigator.gpu.requestAdapter();
if (!adapter.features.has(feature)) {
  throw new Error("Read-write storage texture support is not available");
}
// Explicitly request read-write storage texture support.
const device = await adapter.requestDevice({
  requiredFeatures: [feature],
});

const bindGroupLayout = device.createBindGroupLayout({
  entries: [{
    binding: 0,
    visibility: GPUShaderStage.COMPUTE,
    storageTexture: {
      access: "read-write", // <-- New!
      format: "r32uint",
    },
  }],
});

const shaderModule = device.createShaderModule({ code: `
  enable chromium_experimental_read_write_storage_texture;
  @group(0) @binding(0) var tex : texture_storage_2d<r32uint, read_write>;

  @compute @workgroup_size(1, 1)
  fn main(@builtin(local_invocation_id) local_id: vec3u) {
    var data = textureLoad(tex, vec2i(local_id.xy));
    data.x *= 2;
    textureStore(tex, vec2i(local_id.xy), data);
  }`,
});

// You can now create a compute pipeline with this shader module and
// send the appropriate commands to the GPU.

Dawn の更新

webgpu.h C API では、一貫性を保つために、以下のフィールドの名前を変更しました: requiredFeaturesCountrequiredFeatureCount に、pipelineStatisticsCountpipelineStatisticCount に、colorFormatsCountcolorFormatCount に。issue dawn:146040 をご覧ください。

新しい DawnInfo プログラム(vulkaninfo と同様)を使用すると、切り替え、アダプター、アダプター機能、アダプターの制限を一覧表示できます。dawn samples をビルドすると利用できます。簡潔にするため、出力は大幅に削減されています。変更 dawn:149020 をご覧ください。

./out/Debug/DawnInfo
Toggles
=======
  Name: allow_unsafe_apis
    Suppresses validation errors on API entry points or parameter combinations
    that aren't considered secure yet.
    http://crbug.com/1138528
[…]

Adapter
=======
VendorID: 0x106B
Vendor: apple
Architecture: common-3
DeviceID: 0x0000
Name: Apple M1 Pro
Driver description: Metal driver on macOS Version 13.5.1 (Build 22G90)
Adapter Type: discrete GPU
Backend Type: Metal
Power: <undefined>

  Features
  ========
   * depth_clip_control
      Disable depth clipping of primitives to the clip volume
      https://bugs.chromium.org/p/dawn/issues/detail?id=1178
[…]

  Adapter Limits
  ==============
    maxTextureDimension1D: 16,384
    maxTextureDimension2D: 16,384
[…]

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

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