GPURenderPipeline: getBindGroupLayout() 方法

可用性有限

此特性不是基线特性,因为它在一些最广泛使用的浏览器中不起作用。

安全上下文: 此功能仅在安全上下文(HTTPS)中可用,且支持此功能的浏览器数量有限。

注意:此功能在 Web Workers 中可用。

getBindGroupLayout() 方法是 GPURenderPipeline 接口的一部分,用于返回具有给定索引的管道的 GPUBindGroupLayout 对象(即,包含在原始的 GPUDevice.createRenderPipeline()GPUDevice.createRenderPipelineAsync() 调用中的管道布局)。

如果 GPURenderPipeline 是使用 layout: "auto" 创建的,那么此方法是检索由管道生成的 GPUBindGroupLayouts 的唯一方法。

语法

js
getBindGroupLayout(index)

参数

index

一个数字,表示要返回的 GPUBindGroupLayout 的索引。

返回值

一个 GPUBindGroupLayout 对象实例。

验证

调用 getBindGroupLayout() 时必须满足以下条件,否则将生成 GPUValidationError 并返回一个无效的 GPUBindGroupLayout 对象。

示例

注意:您可以在 WebGPU 示例 中查看 getBindGroupLayout() 的完整工作示例。

js
// …

// Create a render pipeline using layout: "auto" to automatically generate
// appropriate bind group layouts
const fullscreenQuadPipeline = device.createRenderPipeline({
  layout: "auto",
  vertex: {
    module: device.createShaderModule({
      code: fullscreenTexturedQuadWGSL,
    }),
    entryPoint: "vert_main",
  },
  fragment: {
    module: device.createShaderModule({
      code: fullscreenTexturedQuadWGSL,
    }),
    entryPoint: "frag_main",
    targets: [
      {
        format: presentationFormat,
      },
    ],
  },
  primitive: {
    topology: "triangle-list",
  },
});

// …

// Create a bind group with the auto-generated layout from the render pipeline
const showResultBindGroup = device.createBindGroup({
  layout: fullscreenQuadPipeline.getBindGroupLayout(0),
  entries: [
    {
      binding: 0,
      resource: sampler,
    },
    {
      binding: 1,
      resource: textures[1].createView(),
    },
  ],
});

// …

规范

规范
WebGPU
# dom-gpupipelinebase-getbindgrouplayout

浏览器兼容性

另见