What's WebGPU 新功能 (Chrome 118 以上版本)

François Beaufort
François Beaufort

copyExternalImageToTexture() 中的 HTMLImageElement 和 ImageData 支援

GPUQueuecopyExternalImageToTexture() 方法可讓您將來源圖片、影片或畫布的快照複製到指定的 GPUTexture。您現在可以將 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" 使用。

如要充分利用這項功能,你必須使用 enable chromium_experimental_read_write_storage_texture 在 WGSL 程式碼中明確啟用這項擴充功能。啟用後,您就能針對儲存紋理使用 read_writeread 存取限定詞,textureLoad()textureStore() 內建函式也會據此運作,而新的 textureBarrier() 內建函式可用來同步處理工作群組中的紋理記憶體存取權。請參考以下範例和問題 dawn:1972

這項功能仍在實驗階段,可能會有變動。系統已標準化,但你可在執行 Chrome 時加上 --enable-dawn-features=allow_unsafe_apis 旗標,將此內容提供給使用者。

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.

日出最新消息

webgpu.h C API 將下列欄位重新命名為 requiredFeatureCount,將 requiredFeaturesCount 重新命名為 requiredFeatureCountpipelineStatisticsCount 重新命名為 pipelineStatisticCount,以及將 colorFormatsCount 重新命名為 colorFormatCount。請參閱問題 dawn:146040

全新的 DawnInfo 程式 (類似於 vulkaninfo) 可讓您列出切換鈕、轉接器、轉接器功能和轉接器限制。可在建構黎明 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 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