發布日期:2025 年 5 月 26 日
使用紋理檢視區塊進行 externalTexture 繫結
建立 GPUBindGroup 時,現在可以使用相容的 GPUTextureView (2D,單一子資源) 取代 GPUExternalTexture 繫結。
這樣一來,在視訊效果管道中,就只需要處理 GPUExternalTexture (適用於來源影片) 和 GPUTextureView (適用於中繼處理),簡化著色器邏輯。此外,這項功能還能減少根據紋理來源動態編譯著色器的需求。請參閱「Intent to Ship: WebGPU: GPUTextureView for externalTexture binding」。
const texture = myDevice.createTexture({
size: [42, 42],
format: navigator.gpu.getPreferredCanvasFormat(),
usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.TEXTURE_BINDING,
});
const code = `
@group(0) @binding(0) var texture : texture_external;
@group(0) @binding(1) var<storage, read_write> buffer: vec2u;
@compute @workgroup_size(1) fn main() {
buffer = textureDimensions(texture);
}`;
const pipeline = myDevice.createComputePipeline({
layout: "auto",
compute: { module: myDevice.createShaderModule({ code }) },
});
const bindGroup = myDevice.createBindGroup({
layout: pipeline.getBindGroupLayout(0),
entries: [
{ binding: 0, resource: texture.createView() }, // Use texture view for an externalTexture binding
{ binding: 1, resource: { buffer: myBuffer } },
],
});
複製緩衝區,但不指定位移和大小
開發人員現在可以使用新的 GPUCommandEncoder 方法多載,在使用 copyBufferToBuffer()
時省略偏移和大小參數,簡化整個緩衝區的副本。請參閱「Intent to Ship: WebGPU: copyBufferToBuffer overload」。
const size = 42;
const srcBuffer = myDevice.createBuffer({
size,
usage: GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_SRC,
});
const dstBuffer = myDevice.createBuffer({
size,
usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ,
});
// Copy entire buffer.
myCommandEncoder.copyBufferToBuffer(srcBuffer, dstBuffer);
// This is the same as the following.
// myCommandEncoder.copyBufferToBuffer(srcBuffer, 0, dstBuffer, 0, size);
使用指標指向原子項目的 WGSL workgroupUniformLoad
為方便開發人員,WGSL 新增了 workgroupUniformLoad(ptr)
超載。這個函式會以原子方式載入 ptr
指向的值,並傳回工作群組中的所有呼叫,其中 ptr
是工作群組變數內的指標至原子。請參閱問題 408241039。
@group(0) @binding(0) var<storage, read_write> buffer : array<u32, 1>;
var<workgroup> wgvar : atomic<u32>;
@compute @workgroup_size(1, 1)
fn main(@builtin(local_invocation_index) lid: u32) {
if (lid == 0) {
atomicStore(&(wgvar), 42u);
}
buffer[lid] = workgroupUniformLoad(&wgvar);
}
GPUAdapterInfo powerPreference 屬性
使用者在 chrome://flags/#enable-webgpu-developer-features
啟用「WebGPU 開發人員功能」標記後,即可使用非標準的 powerPreference
GPUAdapterInfo 字串屬性。如果支援,powerPreference
值可以是 "low-power"
或 "high-performance"
,視 GPURequestAdapterOptions 中使用的 GPUPowerPreference 值而定。請參閱 CL 6438860。
function checkPowerPreferenceForGpuDevice(device) {
const powerPreference = device.adapterInfo.powerPreference;
if (powerPreference === "high-performance") {
// High-performance GPU detected. Enabling enhanced graphics settings.
} else if (powerPreference === "low-power") {
// Low-power GPU detected. Optimizing for battery life.
}
}
移除 GPURequestAdapterOptions compatibilityMode 屬性
實驗性的 GPURequestAdapterOptions compatibilityMode
屬性已移除,改用 Chrome 133 版新增的標準化 featureLevel
屬性。請參閱問題 366151404。
黎明更新
開發人員可以使用 C++ 等語言建構 WebGPU 專案,並透過 webgpu.h 同時指定 WebAssembly 和特定平台。Dawn 最新發布的「emdawnwebgpu」(「Emscripten Dawn WebGPU」) 會透過瀏覽器 API 實作最新的標準化 webgpu.h。
Emdawnwebgpu 是 Emscripten (現已停止維護) 內建繫結 (USE_WEBGPU
) 的 (維護) 分支版本。所有新開發作業都會在 emdawnwebgpu 上進行,而 Emscripten 的內建繫結將會移除,開發人員也會改用 emdawnwebgpu。Emdawnwebgpu 的 C 標頭與 Dawn 的標頭非常接近,但內建繫結已過時。
從 Dawn 的 GitHub 版本頁面下載 emdawnwebgpu,並參閱套件的 README.md,瞭解如何使用。來源檔案位於 Dawn 存放區。
如需完整指南,請參閱更新後的「使用 WebGPU 建構應用程式」說明文件。
這僅涵蓋部分重點。請參閱完整的提交清單。
WebGPU 最新消息
「WebGPU 最新消息」系列涵蓋的所有主題清單。
Chrome 140
- 裝置要求會耗用轉接程式
- 使用紋理檢視畫面時,可使用紋理的簡短形式
- WGSL textureSampleLevel 支援 1D 紋理
- 淘汰 bgra8unorm 唯讀儲存空間紋理用法
- 移除 GPUAdapter isFallbackAdapter 屬性
- Dawn 更新
Chrome 139
Chrome 138
Chrome 137
- 使用紋理檢視區塊進行 externalTexture 繫結
- 複製緩衝區,但不指定位移和大小
- WGSL 工作群組 UniformLoad,使用指標指向原子
- GPUAdapterInfo powerPreference 屬性
- 移除 GPURequestAdapterOptions compatibilityMode 屬性
- Dawn 更新
Chrome 136
Chrome 135
- 允許使用空值繫結群組版面配置建立管道版面配置
- 允許檢視區塊超出算繪目標的邊界
- 在 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()
- 點和線條圖元不得有深度偏差
- 子群組的內建包容性掃描功能
- 實驗性支援多重繪圖間接
- 著色器模組編譯選項「嚴格的數學」
- 移除 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
copyExternalImageToTexture()
支援 HTMLImageElement 和 ImageData- 實驗性支援讀寫和唯讀儲存空間紋理
- Dawn 更新
Chrome 117
Chrome 116
- 整合 WebCodecs
- GPUAdapter
requestDevice()
傳回的遺失裝置 - 如果呼叫
importExternalTexture()
,請確保影片播放流暢 - 規格一致性
- 提升開發人員體驗
- Dawn 更新
Chrome 115
Chrome 114
Chrome 113
- 在
importExternalTexture()
中使用 WebCodecs VideoFrame 來源