WebGPU 的新功能 (Chrome 124)

François Beaufort
François Beaufort

唯讀和讀寫儲存空間紋理

儲存空間紋理繫結類型可讓著色器從儲存空間紋理讀取資料,不必新增 TEXTURE_BINDING 用途,並對特定格式執行混合讀取和寫入作業。如果 navigator.gpu.wgslLanguageFeatures 中有 "readonly_and_readwrite_storage_textures" WGSL 語言擴充功能,您現在可以在建立繫結群組版面配置時,將 GPUStorageTexture 存取權設為 "read-write""read-only"。先前僅限於 "write-only"

接著,WGSL 著色器程式碼就能使用 read_writeread 存取限定符 (適用於儲存空間紋理),textureLoad()textureStore() 內建函式也會相應運作,且您可以使用新的 textureBarrier() 內建函式,在工作群組中同步處理紋理記憶體存取。

建議在 WGSL 著色器程式碼頂端使用 requires 指令,標示 requires readonly_and_readwrite_storage_textures; 可能無法移植。請參閱以下範例和問題 dawn:1972

if (!navigator.gpu.wgslLanguageFeatures.has("readonly_and_readwrite_storage_textures")) {
  throw new Error("Read-only and read-write storage textures are not available");
}

const adapter = await navigator.gpu.requestAdapter();
const device = await adapter.requestDevice();

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

const shaderModule = device.createShaderModule({ code: `
  requires readonly_and_readwrite_storage_textures;

  @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.

支援服務工作人員和共用工作人員

Chrome 中的 WebGPU 將網頁工作人員支援功能提升至全新境界,現在同時支援服務工作人員共用工作人員。您可以使用 Service Worker 強化背景工作和離線功能,並使用 Shared Worker 在指令碼之間有效率地共用資源。請參閱問題 chromium:41494731

請參閱 Chrome 擴充功能範例WebLLM Chrome 擴充功能,瞭解如何在擴充功能服務工作人員中使用 WebGPU。

WebLLM Chrome 擴充功能的螢幕截圖。
WebLLM Chrome 擴充功能。

新的轉接程式資訊屬性

如果使用者在 chrome://flags/#enable-webgpu-developer-features 啟用「WebGPU 開發人員功能」旗標,現在呼叫 requestAdapterInfo() 時,即可取得非標準的 d3dShaderModelvkDriverVersion 配接器資訊屬性。支援的時機:

https://webgpureport.org 的螢幕截圖,顯示配接器資訊中的 vkDriverVersion。
https://webgpureport.org 顯示的介面卡資訊 vkDriverVersion

修正錯誤

使用 layout: "auto" 建立兩個具有相符繫結群組的管道,然後使用第一個管道建立繫結群組,並在第二個管道上使用該繫結群組,現在會引發 GPUValidationError。允許使用是實作錯誤,現在已透過適當的測試修正。請參閱問題 dawn:2402

黎明更新

在 Dawn API 中,GPU 裝置遺失後,系統不會再呼叫使用 wgpuDeviceSetUncapturedErrorCallback 設定的未擷取錯誤回呼。這項修正會讓 Dawn 符合 JavaScript API 規格和 Blink 的實作方式。請參閱問題 dawn:2459

這僅涵蓋部分重點。請參閱完整的提交清單

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