SuperAPI AI 工具集

webgpu-syntax-render-pipeline

前端与建站

查看项目

更新于 10-15 22:18

技能介绍

用途:创建不可变的 GPURenderPipeline,正确捕获顶点布局、片元目标、混合、图元拓扑与深度模板状态,避免 WebGPU 管线创建校验错误。基线为 WebGPU 1.0-stable:Chrome 113+、Safari 26+、Firefox 141+。

主要能力:device.createRenderPipeline(descriptor) 返回 GPURenderPipeline;createRenderPipelineAsync 返回 Promise 并在内容时间线之外编译。描述符字段包括 label(可选)、layout(必填,GPUPipelineLayout 或 "auto")、vertex(必填)、primitive、depthStencil、multisample、fragment(可选)。vertex 含 module、entryPoint、constants、buffers;fragment 含 module、entryPoint、constants、targets。

必要用法:片元目标格式必须与颜色附件格式一致,画布统一用 navigator.gpu.getPreferredCanvasFormat();顶点属性 offset 与 shaderLocation 必须匹配 WGSL 的 @location,format 分量与类型需对应,arrayStride 为一个顶点的总字节数;有深度附件时必须声明 depthStencil 且 format 与深度纹理格式完全一致;管线只创建一次并逐帧复用,禁止在 requestAnimationFrame 内调用 createRenderPipeline;strip 拓扑配合 drawIndexed 时必须设置 stripIndexFormat 且与索引格式一致;multisample.count 必须等于附件 sampleCount(1 或 4)。

适用场景:全屏三角形、带顶点缓冲的网格、透明混合、深度遮挡、MSAA 等渲染管线配置。

限制与警告:不要硬编码 "bgra8unorm";不要复用 "auto" 布局的绑定组到其他管线;device.queue 是只读属性,不可当函数调用。完整字段表、枚举默认值与示例见 references/methods.md、references/examples.md、references/anti-patterns.md。