發布日期:2025 年 1 月 8 日
紋理檢視畫面用量
GPU 紋理檢視區塊目前會從來源 GPU 紋理繼承所有使用旗標。這可能會造成問題,因為部分檢視格式不支援特定用途。如要解決這個問題,請使用選用的 usage
成員呼叫 createView()
,明確指定與所選檢視區塊格式相容的來源紋理使用旗標子集。
這項異動可讓您預先驗證,並更精細地控管檢視畫面使用方式。這也與其他繪圖 API 一致,因為使用情形標記是檢視畫面建立作業的常見參數,可提供最佳化機會。
請參閱以下程式碼片段、chromestatus 項目和問題 363903526。
const texture = myDevice.createTexture({
size: [4, 4],
format: "rgba8unorm",
usage:
GPUTextureUsage.RENDER_ATTACHMENT |
GPUTextureUsage.TEXTURE_BINDING |
GPUTextureUsage.STORAGE_BINDING,
viewFormats: ["rgba8unorm-srgb"],
});
const view = texture.createView({
format: 'rgba8unorm-srgb',
usage: GPUTextureUsage.RENDER_ATTACHMENT, // Restrict allowed usage.
});
32 位元浮點紋理混合
32 位元浮點紋理是 HDR 算繪的必要條件,可保留多種顏色值,並避免出現色帶偽影。例如科學視覺化。
新的 "float32-blendable"
GPU 功能可讓格式為 "r32float"
、"rg32float"
和 "rgba32float"
的 GPU 紋理混合。要求使用這項功能的 GPU 裝置時,現在可以建立使用混合的算繪管道,並搭配任何 float32 格式的附件。
請參閱下列程式碼片段、chromestatus 項目和問題 369649348。
const adapter = await navigator.gpu.requestAdapter();
if (!adapter.features.has("float32-blendable")) {
throw new Error("32-bit float textures blending support is not available");
}
// Explicitly request 32-bit float textures blending support.
const device = await adapter.requestDevice({
requiredFeatures: ["float32-blendable"],
});
// ... Creation of shader modules is omitted for readability.
// Create a render pipeline that uses blending for the rgba32float format.
device.createRenderPipeline({
vertex: { module: myVertexShaderModule },
fragment: {
module: myFragmentShaderModule,
targets: [
{
format: "rgba32float",
blend: { color: {}, alpha: {} },
},
],
},
layout: "auto",
});
// Create the GPU texture with rgba32float format and
// send the appropriate commands to the GPU...
GPUDevice adapterInfo
屬性
對於採用使用者提供的 GPUDevice
物件的程式庫而言,存取實體 GPU 的相關資訊非常重要,因為程式庫可能需要根據 GPU 架構進行最佳化或實作解決方法。雖然可以透過 GPUAdapter
物件存取這項資訊,但無法直接從 GPUDevice
取得。這可能會造成不便,因為使用者可能需要一併提供額外資訊和 GPUDevice
。
為解決這個問題,GPUAdapterInfo
現在會透過 GPUDevice
adapterInfo
屬性公開。這些屬性與現有的 GPUAdapter
info
屬性類似。
請參閱以下程式碼片段、chromestatus 項目和問題 376600838。
function optimizeForGpuDevice(device) {
if (device.adapterInfo.vendor === "amd") {
// Use AMD-specific optimizations.
} else if (device.adapterInfo.architecture.includes("turing")) {
// Optimize for NVIDIA Turing architecture.
}
}
以無效格式設定畫布內容時,會擲回 JavaScript 錯誤
先前,使用無效的紋理格式搭配 GPU 畫布內容的 configure()
方法,會導致 GPU 驗證錯誤。這項變更會擲回 JavaScript TypeError
。這樣可避免 getCurrentTexture()
傳回有效的 GPU 紋理,即使 GPU 畫布環境設定錯誤也一樣。詳情請參閱問題 372837859。
對紋理套用取樣器篩選限制
先前可使用 "sint"
、"uint"
和「depth"
格式紋理」搭配篩選範例。現在可正確禁止使用 "sint"
或 "uint"
格式的紋理搭配過濾取樣器。請注意,如果您使用「depth"
紋理搭配篩選取樣器」,目前會發出警告,因為日後將不允許這麼做。請參閱問題 376497143。
這些限制表示使用深度紋理和非篩選取樣器時,需要手動建立繫結群組版面配置。這是因為「自動」產生的繫結群組版面配置目前不支援這種組合。規格問題 4952 包含一項提案,考慮在日後解決這項限制。
擴大子群組實驗
子群組實驗原定在 Chrome 131 結束,現已延長至 Chrome 133,並於 2025 年 4 月 16 日結束。雖然第一個原始碼試用階段著重於效能,但缺少重要的可攜性安全防護措施。現在會新增這些安全措施,可能導致現有程式碼發生錯誤。
提升開發人員體驗
在 Windows 上使用 powerPreference
選項和 requestAdapter()
時,開發人員工具現在會顯示警告。Chrome 瞭解如何使用兩個不同的 GPU,並在兩者之間合成結果後,就會移除這項警告。請參閱問題 369219127。
現在建立過大的 GPU 緩衝區時,錯誤訊息會顯示 GPU 緩衝區的大小。請參閱問題 374167798。
實驗性支援 16 位元標準化紋理格式
16 位元帶正負號正規化和不帶正負號正規化紋理格式,現在分別透過 "chromium-experimental-snorm16-texture-formats"
和 "chromium-experimental-unorm16-texture-formats"
GPU 功能提供實驗性支援,同時討論標準化。
這些功能新增了對 16 位元正規化紋理格式的支援,並提供 COPY_SRC
、COPY_DST
、TEXTURE_BINDING
、RENDER_ATTACHMENT
用途、多重取樣和解析功能。其他格式包括 "r16unorm"
、"rg16unorm"
、"rgba16unorm"
、"r16snorm"
、"rg16snorm"
和 "rgba16snorm"
。
在這些實驗功能標準化之前,請在 chrome://flags/#enable-unsafe-webgpu
啟用「Unsafe WebGPU Support」旗標,以便在 Chrome 中使用這些功能。
請參閱下列程式碼片段和問題 374790898。
const adapter = await navigator.gpu.requestAdapter();
if (!adapter.features.has("chromium-experimental-snorm16-texture-formats")) {
throw new Error("16-bit signed normalized formats support is not available");
}
// Explicitly request 16-bit signed normalized formats support.
const device = await adapter.requestDevice({
requiredFeatures: ["chromium-experimental-snorm16-texture-formats"],
});
// Create a texture with the rgba16snorm format which consists of four
// components, each of which is a 16-bit, normalized, signed integer value.
const texture = device.createTexture({
size: [4, 4],
format: "rgba16snorm",
usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.TEXTURE_BINDING,
});
// Send the appropriate commands to the GPU...
黎明更新
wgpu::Adapter
和 wgpu::Device
中的 EnumerateFeatures(FeatureName * features)
方法已淘汰,並改用 GetFeatures(SupportedFeatures * features)
。請參閱問題 368672123。
webgpu.h C API 已將所有 char const *
變更為 WGPUStringView
結構,用於定義 UTF-8 編碼字串的檢視畫面。它就像是指向字串資料的指標,並搭配長度。這樣一來,您不必複製字串,就能處理字串的某部分。請參閱問題 42241188。
這僅涵蓋部分重點。請參閱完整的提交清單。
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 來源