WebGPU 的新变化 (Chrome 122)

François Beaufort
François Beaufort

WebGPU 功能的数量看起来似乎有点少,但重大的进步近在眼前!后续版本将包括 DP4a、只读和读写存储纹理、单独的模板和深度切面控制、渲染到 3D 纹理切片等功能,以及着色器编译改进。

在此期间,不妨了解如何利用 Headless Chrome 中的 WebGPU 和 WebGL 支持来提升 Web AI 模型测试的效果,以及为什么 WebGPU 在 Chrome 中可能被停用或无法正常运行

利用兼容模式扩大覆盖面(正在开发的功能)

WebGPU 与现代图形 API(Vulkan、Metal 和 D3D12)完美契合,但有些设备缺乏对这类 API 的支持。这限制了 WebGPU 的可访问性,尤其是在 Windows(31% 的 Chrome 用户缺少 D3D11.1+)、Android(23% 缺少 Vulkan 1.1+)和 ChromeOS(Vulkan 采用率正在上升)等平台上。

为了解决这个问题,Chrome 团队正在努力开发 WebGPU 的兼容模式,通过提供适用于 D3D11 和 OpenGL ES 等旧版 API 的 WebGPU 提供略微受限的版本。这将扩展 WebGPU 的潜在用户群。

重要的是,使用兼容模式的应用仍然完全有效的 WebGPU 应用。不支持兼容模式的设备将无缝默认使用核心 WebGPU 适配器,确保广泛的易用性。

WebGPU 兼容模式的示意图。
WebGPU 兼容模式扩大覆盖范围。

如有任何疑问,请查看提案评论

提高 maxVertexAttributes 限制

创建 GPURenderPipeline 时,缓冲区中属性总数的上限为 16 个。现在,使用 maxVertexAttributes 限制(如果支持)可以请求最多 30 个。请参阅以下示例并问题 dawn:2223

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

if (adapter.limits.maxVertexAttributes < 30) {
  // When the desired limit isn't supported, take action to either fall back to
  // a code path that does not require the higher limit or notify the user that
  // their device does not meet minimum requirements.
}

// Request highest limit of max vertext attributes.
const device = await adapter.requestDevice({
  requiredLimits: { maxVertexAttributes: 30 },
});

黎明动态

新增了一个名为“expose_wgsl_experimental_features”的实例切换开关,以使实例仅公开实验性 WGSL 功能,而不公开不安全的功能,这样,您无需启用“allow_unsafe_apis”切换开关即可使用安全的实验性 WGSL 功能。请参阅问题 dawn:2260

适用于 Node.js 的 Dawn 绑定的最新改进包括:

  • 已添加 GPUSupportedFeatures::getSize()
  • 实现了 GPUAdapter 过时。
  • 现在可以正确报告设备的 GPUInternalError
  • 属性现在是可枚举的。

这仅涵盖了部分重要的亮点。查看详尽的提交内容列表

WebGPU 的新变化

WebGPU 的新变化系列中涵盖的所有内容的列表。

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