SuperAPI AI 工具集

webgpu-syntax-textures

设计与创作

查看项目

更新于 10-16 09:56

技能介绍

用途:在创建 WebGPU 纹理、纹理视图或采样器,选择纹理格式,或把视频帧导入为外部纹理时使用,避免格式、usage 标志与绑定类型不匹配导致的验证错误。目标为 WebGPU 1.0-stable(Chrome 113+、Safari 26+、Firefox 141+)。

主要能力:

  1. createTexture 描述符:size 支持 [w, h, depthOrArrayLayers];mipLevelCount 默认 1;sampleCount 仅 1 或 4;dimension 可为 1d/2d/3d;format 必填;usage 必填;viewFormats 可选。
  2. 常用 GPUTextureFormat:8 位色 rgba8unorm、rgba8unorm-srgb、bgra8unorm、bgra8unorm-srgb;16 位浮点 r16float、rgba16float;32 位浮点 r32float、rgba32float(过滤需 float32-filterable);深度模板 depth16unorm、depth24plus、depth24plus-stencil8、depth32float 等。画布格式始终取 navigator.gpu.getPreferredCanvasFormat()。
  3. GPUTextureUsage 标志:COPY_SRC、COPY_DST、TEXTURE_BINDING、STORAGE_BINDING、RENDER_ATTACHMENT。纹理用作渲染目标又作采样输入时需同时带上对应标志,缺失会在绑定组或渲染通道阶段报错。
  4. createSampler:可设 addressModeU/V/W、magFilter、minFilter、mipmapFilter、lodMinClamp、lodMaxClamp、maxAnisotropy 及 compare。绑定类型须匹配:仅 linear 过滤用 filtering,全 nearest 用 non-filtering,设了 compare 用 comparison。
  5. 决策树覆盖纹理用途、格式选择、视图维度(2d、2d-array、cube、3d)与采样器选择(平滑、像素风、mipmap、阴影比较)。

必要用法与限制:视图用 texture.createView(descriptor?) 从所属纹理新建;MSAA 时纹理与管线 sampleCount 都须为 4,多采样纹理须带 RENDER_ATTACHMENT、禁止 STORAGE_BINDING 且 mipLevelCount 为 1;HTMLVideoElement 来源的 GPUExternalTexture 单帧有效,每帧重新 importExternalTexture 并重建绑定组;依赖特性的格式需先用 adapter.features 确认,再在 requestDevice 中申请;sampleCount 只能是 1 或 4,maxAnisotropy 大于 1 时三个过滤器都须为 linear;WebGPU 不会自动生成 mipmap,mipLevelCount 大于 1 须自行填充。

限制:资料未提供除上述之外的收费、价格或平台信息。参考文件 references/methods.md、references/examples.md、references/anti-patterns.md 提供了完整描述符、格式列表、示例与反模式分析。