WebGPU の新機能(Chrome 119)

François Beaufort
François Beaufort

フィルタリング可能な 32 ビット浮動小数点テクスチャ

32 ビットの浮動小数点テクスチャは、HDR 画像や深度マップなどの高精度データの保存に使用されます。特に、ハイエンドのゲームやプロフェッショナル アプリケーションで使用される GPU にとって重要です。

フィルタ可能な 32 ビット浮動小数点テクスチャのサポートは、GPU が 32 ビット浮動小数点テクスチャをフィルタできるかどうかを表します。つまり、GPU は浮動小数点テクスチャの端を滑らかにし、ギザギザに見えないようにすることができます。これは、WebGL の「OES_texture_float_linear」拡張機能に似ています。

すべての GPU がフィルタリング可能な 32 ビット浮動小数点テクスチャをサポートしているわけではありません。GPUAdapter"float32-filterable" 機能が利用可能になった場合、この機能で GPUDevice をリクエストし、「r32float」、「rg32float」、「rgba32float」形式でテクスチャをフィルタできるようになりました。次の例と issue dawn:1664 をご覧ください。

const adapter = await navigator.gpu.requestAdapter();
if (!adapter.features.has("float32-filterable")) {
  throw new Error("Filterable 32-bit float textures support is not available");
}
// Explicitly request filterable 32-bit float textures support.
const device = await adapter.requestDevice({
  requiredFeatures: ["float32-filterable"],
});

// Create a sampler with linear filtering.
const sampler = device.createSampler({
  magFilter: "linear",
});

// Create a texture with rgba32float format.
const texture = device.createTexture({
  size: [100, 100],
  format: "rgba32float",
  usage: GPUTextureUsage.COPY_DST | GPUTextureUsage.TEXTURE_BINDING,
});

// Write data to texture, create a bindgroup with sampler and texture and
// send the appropriate commands to the GPU....

unorm10-10-10-2 頂点形式

WebGPU 仕様に「unorm10-10-10-2」別名「rgb10a2」という新しい頂点形式が追加されました。4 つの正規化された符号なし整数値を含む 1 つのパックされた 32 ビット値で構成され、10 ビット、10 ビット、10 ビット、2 ビットの順に並べられています。次の例と issue dawn:2044 をご覧ください。

// Define the layout of vertex attribute data with unorm10-10-10-2 format.
const buffers = [
  {
    arrayStride: 0,
    attributes: [
      { format: "unorm10-10-10-2", offset: 0, shaderLocation: 0 },
    ],
  },
];

// Describe the vertex shader entry point and its input buffer layouts.
const vertex = {
  module: myVertexShaderModule,
  entryPoint: "main",
  buffers,
};

// Pass vertex to device.createRenderPipeline() and
// use vec4<f32> type in WGSL shader code to manipulate data.

rgb10a2uint テクスチャ形式

WebGPU 仕様に「rgb10a2uint」という新しいテクスチャ形式が追加されました。これは、4 つの符号なし整数コンポーネント(10 ビットの赤、10 ビットの緑、10 ビットの青、2 ビットのアルファ)を含む 32 ビットのパックされたピクセル形式で構成されています。次の例と issue dawn:1936 をご覧ください。

// Create a texture with rgb10a2uint format.
const texture = device.createTexture({
  size: [100, 100],
  format: "rgb10a2uint",
  usage: GPUTextureUsage.COPY_DST | GPUTextureUsage.TEXTURE_BINDING,
});

// Write data to texture, create a bindgroup with texture and
// send the appropriate commands to the GPU....

Dawn のアップデート

タイムスタンプ クエリを使用すると、WebGPU アプリケーションは GPU コマンドの実行にかかる時間をナノ秒単位で正確に測定できます。パスの開始時と終了時にタイムスタンプ クエリをキャプチャする API シェイプが、WebGPU 仕様に合わせて更新されました。次の例と issue dawn:1800 をご覧ください。

// Create a timestamp query set that will store the timestamp values.
wgpu::QuerySetDescriptor querySetDescriptor = {
    .count = 2,
    .type = wgpu::QueryType::Timestamp};
wgpu::QuerySet querySet = device.CreateQuerySet(&querySetDescriptor);

wgpu::RenderPassTimestampWrites timestampWrites = {
    .querySet = querySet,
    .beginningOfPassWriteIndex = 0,
    .endOfPassWriteIndex = 1};
wgpu::ComputePassDescriptor pass{.timestampWrites = &timestampWrites};

// Write the queue timestamp into beginningOfPassWriteIndex and
// endOfPassWriteIndex of myQuerySet respectively before and after the pass
// commands execute.
myEncoder.BeginComputePass(&pass);

ここでは、主なハイライトの一部のみを取り上げます。コミットの一覧をご覧ください。

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