WebGPU 的新变化 (Chrome 122)

François Beaufort
François Beaufort

这次的 WebGPU 功能数量可能看起来有点少,但重大进展即将到来!后续版本将包含 DP4a、只读和读写存储纹理、单独的模板和深度纵横比控制、渲染到 3D 纹理切片以及着色器编译改进等功能。

在此期间,您可以了解如何利用无头 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 vertex attributes.
const device = await adapter.requestDevice({
  requiredLimits: { maxVertexAttributes: 30 },
});

Dawn 更新

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

最近对 Node.js 的 Dawn 绑定进行了改进,包括:

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

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

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