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

瀏覽器相容性

另見