在 copyExternalImageToTexture() 中支持 HTMLImageElement 和 ImageData
GPUQueue
上的 copyExternalImageToTexture()
方法可让您将从源图片、视频或画布拍摄的快照复制到给定的 GPUTexture
中。您现在可以传递 HTMLImageElement
和 ImageData
对象作为来源。请参阅以下示例和问题 chromium:1471372。
// Fetch and decode image.
const source = document.createElement("img");
source.src = "my-image.png";
await source.decode();
// Create destination texture.
const size = [source.width, source.height];
const texture = myDevice.createTexture({
size,
format: "rgba8unorm",
usage:
GPUTextureUsage.COPY_DST |
GPUTextureUsage.RENDER_ATTACHMENT |
GPUTextureUsage.TEXTURE_BINDING,
});
// Copies a snapshot taken from the source image into a texture.
myDevice.queue.copyExternalImageToTexture({ source }, { texture }, size);
实验性支持读写和只读存储纹理
存储纹理绑定类型允许您在着色器中执行纹理读取(无需采样)并存储到任意位置。当 "chromium-experimental-read-write-storage-texture"
功能在 GPUAdapter
中可用时,您现在可以请求具有此功能的 GPUDevice
,并在创建绑定组布局时将 GPUStorageTexture
访问权限设置为 "read-write"
或 "read-only"
。之前,此功能仅限于 "write-only"
。
如需利用此功能,您必须在 WGSL 代码中使用 enable chromium_experimental_read_write_storage_texture
明确启用此扩展程序。启用后,您可以将 read_write
和 read
存储访问限定符用于存储纹理,textureLoad()
和 textureStore()
内置函数会相应地运行,并且可以使用新的 textureBarrier()
内置函数来同步工作组中的纹理内存访问。请参阅以下示例并发布 dawn:1972。
此功能仍处于实验阶段,可能会发生变化。虽然该功能正在标准化,但您可以使用 --enable-dawn-features=allow_unsafe_apis
标志运行 Chrome,以使其可用。
const feature = "chromium-experimental-read-write-storage-texture";
const adapter = await navigator.gpu.requestAdapter();
if (!adapter.features.has(feature)) {
throw new Error("Read-write storage texture support is not available");
}
// Explicitly request read-write storage texture support.
const device = await adapter.requestDevice({
requiredFeatures: [feature],
});
const bindGroupLayout = device.createBindGroupLayout({
entries: [{
binding: 0,
visibility: GPUShaderStage.COMPUTE,
storageTexture: {
access: "read-write", // <-- New!
format: "r32uint",
},
}],
});
const shaderModule = device.createShaderModule({ code: `
enable chromium_experimental_read_write_storage_texture;
@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.
Dawn 更新
webgpu.h C API 已重命名以下字段,以保持一致:requiredFeaturesCount
改为 requiredFeatureCount
、pipelineStatisticsCount
改为 pipelineStatisticCount
,以及 colorFormatsCount
改为 colorFormatCount
。请参阅问题 dawn:146040。
借助新的 DawnInfo
程序(类似于 vulkaninfo),您可以列出切换开关、适配器、适配器功能和适配器限制。在构建 Dawn samples
时可用。以下输出经过大幅精简,以求简洁。请参阅更改 dawn:149020。
./out/Debug/DawnInfo
Toggles
=======
Name: allow_unsafe_apis
Suppresses validation errors on API entry points or parameter combinations
that aren't considered secure yet.
http://crbug.com/1138528
[…]
Adapter
=======
VendorID: 0x106B
Vendor: apple
Architecture: common-3
DeviceID: 0x0000
Name: Apple M1 Pro
Driver description: Metal driver on macOS Version 13.5.1 (Build 22G90)
Adapter Type: discrete GPU
Backend Type: Metal
Power: <undefined>
Features
========
* depth_clip_control
Disable depth clipping of primitives to the clip volume
https://bugs.chromium.org/p/dawn/issues/detail?id=1178
[…]
Adapter Limits
==============
maxTextureDimension1D: 16,384
maxTextureDimension2D: 16,384
[…]
这仅涵盖了部分重要亮点。查看详尽的提交列表。
WebGPU 的新变化
WebGPU 新变化系列中涵盖的所有内容的列表。
Chrome 140
- 设备请求消耗适配器
- 使用纹理视图时使用纹理的简写形式
- WGSL textureSampleLevel 支持一维纹理
- 弃用 bgra8unorm 只读存储纹理用法
- 移除了 GPUAdapter isFallbackAdapter 属性
- Dawn 更新
Chrome 139
Chrome 138
Chrome 137
- 使用纹理视图进行 externalTexture 绑定
- 复制缓冲区,但不指定偏移量和大小
- 使用指向原子变量的指针的 WGSL workgroupUniformLoad
- GPUAdapterInfo powerPreference 属性
- 移除 GPURequestAdapterOptions compatibilityMode 属性
- Dawn 更新
Chrome 136
Chrome 135
- 允许创建具有 null bind 组布局的流水线布局
- 允许视口超出渲染目标边界
- 更轻松地访问 Android 上的实验性兼容性模式
- 移除 maxInterStageShaderComponents 限制
- Dawn 更新
Chrome 134
Chrome 133
- 新增了 unorm8x4-bgra 和 1 分量顶点格式
- 允许请求具有未定义值的未知限制
- WGSL 对齐规则变更
- 使用 discard 提高 WGSL 性能
- 针对外部纹理使用 VideoFrame displaySize
- 使用 copyExternalImageToTexture 处理具有非默认方向的图片
- 改善开发者体验
- 启用与 featureLevel 的兼容模式
- 清理实验性子群组功能
- 弃用 maxInterStageShaderComponents 限制
- Dawn 更新
Chrome 132
- 纹理视图使用情况
- 32 位浮点纹理混合
- GPUDevice adapterInfo 属性
- 使用无效格式配置画布上下文时抛出 JavaScript 错误
- 纹理的过滤采样器限制
- 扩展子群组实验
- 改善开发者体验
- 实验性支持 16 位归一化纹理格式
- Dawn 更新
Chrome 131
- 剪裁 WGSL 中的距离
- GPUCanvasContext getConfiguration()
- 点和线图元不得具有深度偏移
- 子群组的包含性扫描内置函数
- 对多重绘制间接调用的实验性支持
- 着色器模块编译选项 strict math
- 移除 GPUAdapter requestAdapterInfo()
- Dawn 更新
Chrome 130
Chrome 129
Chrome 128
Chrome 127
Chrome 126
Chrome 125
Chrome 124
Chrome 123
Chrome 122
Chrome 121
- 在 Android 上支持 WebGPU
- 在 Windows 上使用 DXC 而不是 FXC 进行着色器编译
- 计算和渲染通道中的时间戳查询
- 着色器模块的默认入口点
- 支持将 display-p3 用作 GPUExternalTexture 色彩空间
- 内存堆信息
- Dawn 更新
Chrome 120
Chrome 119
Chrome 118
Chrome 117
Chrome 116
- WebCodecs 集成
- 由 GPUAdapter
requestDevice()
返回的丢失设备 - 如果调用了
importExternalTexture()
,则保持视频播放流畅 - 规范一致性
- 改善开发者体验
- Dawn 更新
Chrome 115
Chrome 114
Chrome 113
- 在
importExternalTexture()
中使用 WebCodecs VideoFrame 来源