GPUComputePipeline: getBindGroupLayout() 方法
注意:此功能在 Web Workers 中可用。
getBindGroupLayout() 方法是 GPUComputePipeline 介面的一部分,它會返回管道的 GPUBindGroupLayout 物件,其索引與原始的 GPUDevice.createComputePipeline() 或 GPUDevice.createComputePipelineAsync() 呼叫中的管道佈局給出的索引相對應。
如果 GPUComputePipeline 是使用 layout: "auto" 建立的,那麼此方法是檢索由管道生成的 GPUBindGroupLayouts 的唯一途徑。
語法
js
getBindGroupLayout(index)
引數
index-
一個數字,表示要返回的
GPUBindGroupLayout的索引。
返回值
一個 GPUBindGroupLayout 物件例項。
驗證
呼叫 getBindGroupLayout() 時必須滿足以下條件,否則將生成 GPUValidationError 並返回一個無效的 GPUBindGroupLayout 物件。
index小於管道佈局中使用的GPUBindGroupLayout物件的數量。
示例
注意: 在 WebGPU 示例中,您可以看到 getBindGroupLayout() 的完整工作示例。
js
// …
// Create a compute pipeline using layout: "auto" to automatically generate
// appropriate bind group layouts
const computePipeline = device.createComputePipeline({
layout: "auto",
compute: {
module: shaderModule,
entryPoint: "main",
},
});
// Create a bind group with the auto-generated layout from the compute pipeline
const computeBindGroup = device.createBindGroup({
layout: computePipeline.getBindGroupLayout(0),
entries: [
{
binding: 0,
resource: { buffer: storageBuffer },
},
],
});
// …
規範
| 規範 |
|---|
| WebGPU # dom-gpupipelinebase-getbindgrouplayout |
瀏覽器相容性
載入中…