WebGPU 的新变化 (Chrome 126)

François Beaufort
François Beaufort

提高 maxTextureArrayLayers 限制

默认情况下,2D 纹理的深度或层数允许的最大值为 256。现在,通过使用 maxTextureArrayLayers 限制(如果支持),最多可以请求 2048 个。请参阅以下示例和问题 42241514

const adapter = await navigator.gpu.requestAdapter();
if (adapter.limits.maxTextureArrayLayers < 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 texture array layers attributes.
const device = await adapter.requestDevice({
  requiredLimits: { maxTextureArrayLayers: 2048 }
});

针对 Vulkan 后端的缓冲区上传优化

现在,在调用 Vulkan 后端 GPUQueue 的 writeBuffer() 方法时可以使用快速路径。数据现在可以直接写入目标缓冲区,无需额外的复制和同步。这项优化可减少将数据上传到 GPU 所需的内存流量。

快速路径优化要求缓冲区的内存处于主机可见状态,并且没有任何待处理的 GPU 操作。请参阅问题 42242084

缩短了着色器编译时间

Chrome 团队正在提升 Tint(WebGPU 着色器语言的编译器)的效率。目前,Tint 在生成机器代码之前会多次修改着色器代码的抽象语法树 (AST),这个过程在某些平台上会占用大量资源。为了优化这一点,我们推出了一个新的中间表示法 (IR),并重新设计了使用该表示法的后端。此变更旨在加快着色器编译速度。

渲染管道创建涉及使用 Tint 编译器将 WGSL 转换为 SPIR-V,然后使用驱动程序编译器将 WGSL 转换为 ISA。
在 ChromeOS 中创建渲染流水线。

这些改进已在 Android 上推出,我们正在逐步将其扩展到支持 WebGPU 及 Vulkan 后端的 ChromeOS 设备。请参阅问题 42250751

提交的命令缓冲区必须是唯一的

使用 submit() 方法提交到 GPUQueue 的每个 GPUCommandBuffer 都必须具有唯一性,否则会产生验证错误。这是一个规范错误。请参阅问题 42241492

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

const commandEncoder = device.createCommandEncoder();
const commandBuffer = commandEncoder.finish();

device.queue.submit([commandBuffer, commandBuffer]);
// ⚠️ Validation fails because command buffers are not unique.

黎明动态

C++ 封装容器 webgpu_cpp.h 现在只有头文件,这不仅简化了其使用,还简化了与替代 C++ 封装容器的集成。请参阅问题 40195122

webgpu.h C API 不再公开 Swapchain 对象的概念。此变更是为了与 JavaScript API 保持一致。内部配置现在通过新 wgpu::Surface 对象的 Configure() 方法完成,但将来可能会有所修改。如需查看示例,请参阅使用 WebGPU 构建应用文档。请参阅问题 42241264

查看详尽的提交内容列表

WebGPU 的新变化

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

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