GPURenderPipeline: getBindGroupLayout() method

Khả dụng hạn chế

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

Note: This feature is available in Web Workers.

Phương thức getBindGroupLayout() của giao diện GPURenderPipeline trả về đối tượng GPUBindGroupLayout của pipeline với chỉ mục cho trước (tức là được bao gồm trong bố cục pipeline của lệnh gọi GPUDevice.createRenderPipeline() hoặc GPUDevice.createRenderPipelineAsync() gốc).

Nếu GPURenderPipeline được tạo với layout: "auto", phương thức này là cách duy nhất để lấy GPUBindGroupLayout được tạo bởi pipeline.

Cú pháp

js
getBindGroupLayout(index)

Tham số

index

Số đại diện cho chỉ mục của GPUBindGroupLayout cần trả về.

Giá trị trả về

Phiên bản đối tượng GPUBindGroupLayout.

Xác thực

Các tiêu chí sau phải được đáp ứng khi gọi getBindGroupLayout(), nếu không GPUValidationError được tạo ra và đối tượng GPUBindGroupLayout không hợp lệ được trả về:

  • index nhỏ hơn số đối tượng GPUBindGroupLayout được sử dụng trong bố cục pipeline.

Ví dụ

Note: Bạn có thể thấy các ví dụ hoàn chỉnh với getBindGroupLayout() trong các mẫu WebGPU.

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(),
    },
  ],
});

// …

Thông số kỹ thuật

Thông số kỹ thuật
WebGPU
# dom-gpupipelinebase-getbindgrouplayout

Tương thích trình duyệt

Xem thêm