WebGPU 中的新变化(Chrome 143)

François Beaufort
François Beaufort

发布时间:2025 年 11 月 19 日

纹理组件混色

现在,当着色器访问纹理的红色、绿色、蓝色和 Alpha 通道时,可以重新排列或替换这些颜色分量。

当 GPUAdapter 中提供 "texture-component-swizzle" 功能时,请求具有此功能的 GPUDevice,并通过调用 createView() 并使用新的 swizzle 选项来创建 GPUTextureView。此值是一个长度为 4 的字符串,每个字符分别对应于视图的红色、绿色、蓝色和 Alpha 分量。每个字符可以是:

  • "r":从纹理的红色通道获取值。
  • "g":从纹理的绿色通道获取其值。
  • "b":从纹理的蓝色通道获取其值。
  • "a":从纹理的 Alpha 通道获取其值。
  • "0":强制将其值设为 0。
  • "1":强制将其值设为 1。

请参阅以下代码段和 chromestatus 条目

const adapter = await navigator.gpu.requestAdapter();
if (!adapter.features.has("texture-component-swizzle")) {
  throw new Error("Texture component swizzle support is not available");
}
// Explicitly request texture component swizzle support.
const device = await adapter.requestDevice({
  requiredFeatures: ["texture-component-swizzle"],
});

// ... Assuming myTexture is a GPUTexture with a single red channel.

// Map the view's red, green, blue components to myTexture's red channel
// and force the view's alpha component to 1 so that the shader sees it as
// a grayscale image.
const view = myTexture.createView({ swizzle: "rrr1" });

// Send the appropriate commands to the GPU...

移除 bgra8unorm 只读存储纹理使用情况

正如之前宣布的那样,现在已移除将 "bgra8unorm" 格式与只读存储纹理搭配使用的功能。WebGPU 规范明确禁止这样做,而 Chrome 之前允许这样做是一个 bug,因为此格式仅用于写入访问,且不可移植。请参阅问题 427681156

“黎明”更新

修复了在 Vulkan 中清除 3D 纹理时引发的验证错误。请参阅问题 443950688

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

WebGPU 的新变化

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

Chrome 143

Chrome 142

Chrome 141

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